Releases: DZakh/rescript-schema
v8.4.0
TS API Features
Shorthand syntax for S.schema
const loginSchema = S.schema({
email: S.email(S.string),
password: S.stringMinLength(S.string, 8),
});
It's going to replace S.object
in V9.
Shorthand syntax for S.union
const shapeSchema = S.union([
{
kind: "circle" as const,
radius: S.number,
},
{
kind: "square" as const,
x: S.number,
},
{
kind: "triangle" as const,
x: S.number,
y: S.number,
},
]);
Added function-based operation instead of method-based
- parseWith
- parseAsyncWith
- convertWith
- convertToJsonStringWith
- assertWith
They throw exceptions by default. You can use the S.safe
and S.safeAsync
to turn them into result objects.
Deprecations in favor of a new name
S.variant
->S.to
S.assertAnyWith
->S.assertWith
Temporary Regressions/Breaking changes
S.to
/S.variant
doesn't allow to destructure tuples anymores.flatten
stopped working withS.schema
Reverse conversion (serializing) improvement
Now, it's possible to convert back to object schemas where a single field is used multiple times.
Bug Fix
Fix parsing of a tuple nested inside of an object schema.
Full Changelog: v8.3.0...v8.4.0
v8.3.0
What's Changed
- Added
S.bigint
,S.unwrap
,S.compile
,S.removeTypeValidation
,S.convertAnyWith
,S.convertAnyToJsonWith
,S.convertAnyToJsonStringWith
,S.convertAnyAsyncWith
. See the docs for more info. - Deprecated
S.isAsyncParse
in favor ofS.isAsync
- Deprecated
S.assertOrRaiseWith
in favor ofS.assertAnyWith
- Deprecated
S.parseOrRaiseWith
,S.parseAnyOrRaiseWith
,S.serializeOrRaiseWith
,S.serializeToUnknownOrRaiseWith
,S.serializeToJsonStringOrRaiseWith
. Use safe versions instead, together with the newS.unwrap
helper. If you care about performance, I recommend usingS.compile
in this case.
New Contributors
- @WhyThat made their first contribution in #90 by adding PPX support for macOS x64
- @cknitt made their first contribution in #93 by improving compatibility with ReScript v12
Full Changelog: v8.2.0...v8.3.0
v8.2.0
What's Changed
- Add
S.enum
helper - Improve serializing by using experimental reverse schema under the hood by @DZakh in #89
Note: The S.union serializing logic changed in the release. Schemas are not guaranteed to be validated in the order they are passed to S.union. They are grouped by the input data type to optimise performance and improve error message. Schemas with unknown data typed validated the last.
Full Changelog: v8.1.0...v8.2.0
v8.1.0
🆕 Tag shorthand for Js/Ts api object schema
Besides passing schemas for values in S.object
, you can also pass any Js value.
const meSchema = S.object({
id: S.number,
name: "Dmitry Zakharov",
age: 23,
kind: "human" as const,
metadata: {
description: "What?? Even an object with NaN works! Yes 🔥",
money: NaN,
},
});
This is a shorthand for the advanced s.tag
and useful for discriminated unions.
// TypeScript type for reference:
// type Shape =
// | { kind: "circle"; radius: number }
// | { kind: "square"; x: number }
// | { kind: "triangle"; x: number; y: number };
const shapeSchema = S.union([
S.object({
kind: "circle" as const,
radius: S.number,
}),
S.object({
kind: "square" as const,
x: S.number,
}),
S.object({
kind: "triangle" as const,
x: S.number,
y: S.number,
}),
]);
Full Changelog: v8.0.3...v8.1.0
v8.0.3
- Fix TS type for
assert
- Fix TS type for
s.fail
- Update regular expressions used for
email
anduuid
validations. It adds support for uuidv7 validation.
Full Changelog: v8.0.2...v8.0.3
v8.0.2
- Added
S.recursive
support for JS/TS API
Full Changelog: v8.0.1...v8.0.2
v8.0.1
v8.0.0
Big clean up release
-
Added
S.assertOrRaiseWith
orschema.assert
for JS/TS users. It doesn't return parsed value, which makes the operation 2-3 times faster for some schemas. -
Added
S.setGlobalConfig
. Now it's possible to customize the global behavior of the library:- Change the default
unknownKeys
strategy for Object fromStrip
toStrict
- Disable NaN check for numbers
- Change the default
-
S.union
refactoring- Drastically improved parsing performance (1x-1000x times faster depending on the case)
- Returned back async support
- More specific error messages
- When serializing to JSON or JSON string the
S.union
now tries to serialize other items when encounters a non-jsonable schema. Before it used to fail the whole union.
-
Parse Async refactoring
- Performance improvements
- Made it more maintainable and less error-prone
- Hidden bug fixes
- Removed
S.parseAsyncInStepsWith
andS.parseAnyAsyncInStepsWith
to reduce internal library complexity. Create an issue if you need it.
-
S.recursive
refactoring- Performance improvements
- Made it more maintainable and less error-prone
- Fixed bug with serializing to JSON or JSON string
-
For JS/TS users
- Move operations from functions to
Schema
methods - Add
serializeToJsonOrThrow
- Improve TS types and make them compatible with generated types from
genType
- Move operations from functions to
-
Other improvements
S.jsonString
doesn't fail on getting non-jsonable schema anymore. It will fail on the first serialization run instead- Removed
InvalidLiteral
error in favor ofInvalidType
- Changed default
name
ofS.literal
schema (Literal(<value>)
-><value>
) - Renamed
InvalidJsonStruct
error toInvalidJsonSchema
, since afterrescript-struct
->rescript-schema
it became misleading - Update
operation
type to be more detailed and feature it in the error message.
Full Changelog: v7.0.2...v8.0.0
v7.0.2
- Fixed critical error with infinite cycle when getting error message of InvalidType error thrown by recursive schema.
Full Changelog: v7.0.1...v7.0.2
v7.0.1
Fix regression with transformed object serializing in unions.
Full Changelog: v7.0.0...v7.0.1