jar 1.3.0
jar: ^1.3.0 copied to clipboard
Elegant Schema Validation for Flutter and Dart
Changelog #
All notable changes to the JAR validation library will be documented in this file.
1.3.0 [2026-06-29] #
Added #
- Output channel —
JarResult.valueexposes the transformed/coerced/defaulted value, propagated through nested objects, arrays, and records (yup.cast()/ zod.parse()style). - Collect-all validation —
validateAll()returns every issue (vs. abort-earlyvalidate());JarResult.issuesis a typedList<JarIssue>of{ path, code, message }with fully-qualified paths (a.b.0.c). - Error codes — every built-in validator tags its issue with a semantic
code(required,too_small,invalid_type, ...), enabling i18n and programmatic handling. .test()refinement — runs even onnull(unlike.custom()), receives{ parent, root, path }context, and can emit multiple issues viactx.addIssue(message, {path, code}).defaultTo(value)andcatchValue(value)for default/fallback values.- Coercion —
.coerce()on number, date, boolean, and string. record—Jar.record(valueSchema, [keySchema])for dynamic-key maps with per-entry paths.enum/literal—Jar.enumValue(values)andJar.literal(value)..whenupgrade —whenFn(field, (value, schema) => ...)andwhenFields([...], (values, schema) => ...).union/discriminatedUnion—Jar.union([...])andJar.discriminatedUnion(key, {...}).- Async —
validateAsync()and.testAsync(). - i18n —
JarLocale.setLocale({code: message})for centralized messages keyed by code. - Metadata —
.label(),.meta(),.describe()for schema introspection. tuple,intersection, andlazy(recursive schemas).- Per-type methods: string
url/uuid/length/nonempty; numberlessThan/moreThan/multipleOf/finite; arraynonempty/compact/ensure.
Fixed #
.whenno longer pollutes the schema instance. Condition builders mutatedself, leaking validators across reused/shared schema instances (notably array items) — aChefitem could make a siblingWaiteritem's field wrongly required. Validation now snapshots and restores the base rules around each branch.- Coercible types (
number/date/boolean) return aninvalid_typeissue for incompatible input instead of throwing.
Changed #
validategained optional positionalpathandrootarguments:validate(value, [allValues, path, root]). Backward compatible for callers; code that overridesvalidatemust widen its signature to match..testvalidators are now kept in a dedicatedtestslist (still applied during validation).
1.2.0 [2025-03-25] #
Added #
- Cross-field validation with access to all form values
- Enhanced
custom()method to optionally acceptallValuesparameter for all schema types - Added context-aware validation for dependent fields
- Improved propagation of values to nested schemas
- Enhanced
- Comprehensive test suite for cross-field validation scenarios
- Simple field dependency tests
- Multi-level field dependency tests
- Password confirmation validation tests
- Conditional required fields tests
- Added object-level validation for complex field relationships
Changed #
- Updated documentation to include cross-field validation examples
- Improved error propagation in nested schemas
1.1.1 [2025-03-15] #
Fixed #
- Improved type validation for arrays
- Enhanced type checking for array elements
- Fixed edge cases in array type validation
- Added more robust type inference for mixed-type arrays
1.1.0 [2025-03-15] #
Added #
- Custom validation support with
.custom()method for all schema types- Added to string, number, boolean, date, array, object, and mixed schemas
- Allows for complex, context-aware validation rules
- Returns dynamic error messages based on validation conditions
- Comprehensive test suite for custom validation scenarios
- Basic validation tests for each schema type
- Advanced validation tests for real-world scenarios
- Complex conditional validation tests
Changed #
- Updated documentation to include custom validation examples
- Improved error handling for validation functions
1.0.0 [2025-03-04] #
Added #
- Initial release of JAR validation library
- Core schema types:
- String validation with email, pattern matching, and transformations
- Number validation with min/max, positive/negative, and integer checks
- Boolean validation with true/false assertions
- Date validation with past/future and min/max date ranges
- Array validation with length constraints and element validation
- Object validation with nested schemas and field requirements
- Mixed type validation for flexible data structures
- Conditional validation with
.when()method - Schema composition with
.merge()for multi-step forms - Field transformation capabilities
- Comprehensive test suite