v10.0.0-rc.0
Sury 10 is a major release coming with a big cleanup and some new features.
Internal changes
- Schema changed the internal representation to be more similar to JSON Schema with a few of internal fields.
- For ReScript users this means that you can pattern match on the schema type directly.
S.classifyis removed as not needed. Removedliteraltype andLiteralmodule, since it's now a part of the schema type variant asconstfield. RemovedDictandTuplevariants as well asunknownKeysin favor ofadditionalItemsforobjectandarraytypes. RemovedOptionandNullvariants in favor ofuniontype, so there are no overlapping types anymore (besidesjson). - For TypeScript users you can now access the internal fields of the schema directly.
- For ReScript users this means that you can pattern match on the schema type directly.
- Every schema now implements
StandardSchemainterface. TheS.standardfunction is removed as not needed. S.dict/S.recordnow performs!Array.isArray(${inputVar})check- Updated error massage to be shorter and cleaner. Improved error messages for union and recursive schemas.
- Improved union parsing logic to better discriminate between union cases.
- Integrated
rescript-json-schemapackage directly intosury.- Added
JSONSchema.resmodule for ReScript users - Added
JSONSchema7type for TypeScript users - Added
S.toJSONSchemaandS.extendJSONSchema - Added
examplesas a part of newS.metaAPI
- Added
- Allow to set
S.tupletostripmode (still strict by default)
Rebranding
With the version ReScript Schema is now called Sury.
- Remove
rescript-schemamention from the code and usesuryor genericSchemainstead - Renamed
RescriptSchemaErrorclass toSuryError - (rescript) Renamed
S.Raisedexception toS.Error - (rescript) Removed
Errormodule. You can accessmessageandreasondirectly onerrortype. Also, added theErrorClassmodule to replaceError.classfor advanced use-cases. - (rescript) Removed
RescriptSchemanamespace. Namespace was causing many issues with IDE autocompletion and discoverability, so nowSis exposed directly without a namespace. - Improve thrown error display in Node.js console #106
API changes
-
Removed deprecated
S.toin favor ofS.shape& RenamedS.coercetoS.to. Sorry for the mess 😅 -
Enhanced
S.toto support more cases:- From any literal to another literal
S.schema(1).with(S.to, S.schema(true)) S.union,S.optionandS.nullas target types are now supportedS.tocan now be used onunknownschemas. It'll apply the target schema validation to theunknownschema output.S.tocan be targeted tounknownschema.
- From any literal to another literal
-
Removed
S.preprocessin favor ofS.toandS.transform. -
(rescript) Renamed
S.nullabletoS.nullishto match js/ts api -
(rescript) Added
S.nullAsUnit -
(js/ts) Removed
S.undefinedin favor ofS.schema(undefined) -
(js/ts) Allow to pass default value to
S.nullable -
(js/ts) Stopped transforming
nulltoundefinedforS.nullish -
Fixed multiple TS type issues:
-
Changed
S.removeTypeValidationtoS.noValidation. It doesn't affect union discriminated optimisation anymore. -
Introduced
S.metato allow to set all the metadata fields on a schema:- Removed
S.describein favor ofS.meta({description: "..."}) - Removed
S.descriptionin favor of thedescriptionfield on schema - Removed
S.deprecatein favor ofS.meta({deprecated: true}) - Removed
S.deprecatedin favor of thedeprecatedfield on schema - Removed
S.setNamein favor ofS.meta({name: "..."}) - Also, it's possible to set
examplesusingS.meta - Renamed
S.nametoS.toExpression. Also, it's now possible to get the name itself from thenameproperty on schema.
- Removed
-
(js/ts) Introduced
.withmethod on every schema to allow to chain methods easily:S.string.with(S.meta, {examples: ["Hello", "World"]})which is the same asS.meta(S.string, {examples: ["Hello", "World"]}) -
(rescript) Removed
S.inlinebecause of maintanability issues. I'll reintroduce it in the future. -
Renamed
S.stringMinLengthtoS.min -
Renamed
S.stringMaxLengthtoS.max -
Renamed
S.stringLengthtoS.length -
Renamed
S.intMintoS.min -
Renamed
S.intMaxtoS.max -
Renamed
S.numberMintoS.min -
Renamed
S.numberMaxtoS.max -
Renamed
S.arrayMinLengthtoS.min -
Renamed
S.arrayMaxLengthtoS.max -
Renamed
S.arrayLengthtoS.length
PPX changes
- Error when using unsupported attributes. eg
@s.deprecatedwill error, but@s.metawill work. - Added support for
@s.meta,@s.noValidation,@s.strict,@s.strip,@s.deepStrictand@s.deepStrip - Removed
@s.nullablein favor ofNullable.ttype support.
Full Changelog: v9.3.0...v10.0.0-rc.0