Skip to content

v10.0.0-rc.0

Choose a tag to compare

@DZakh DZakh released this 21 Apr 11:50
· 201 commits to main since this release
d4dc08b

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.classify is removed as not needed. Removed literal type and Literal module, since it's now a part of the schema type variant as const field. Removed Dict and Tuple variants as well as unknownKeys in favor of additionalItems for object and array types. Removed Option and Null variants in favor of union type, so there are no overlapping types anymore (besides json).
    • For TypeScript users you can now access the internal fields of the schema directly.
  • Every schema now implements StandardSchema interface. The S.standard function is removed as not needed.
  • S.dict/S.record now 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-schema package directly into sury.
    • Added JSONSchema.res module for ReScript users
    • Added JSONSchema7 type for TypeScript users
    • Added S.toJSONSchema and S.extendJSONSchema
    • Added examples as a part of new S.meta API
  • Allow to set S.tuple to strip mode (still strict by default)

Rebranding

With the version ReScript Schema is now called Sury.

  • Remove rescript-schema mention from the code and use sury or generic Schema instead
  • Renamed RescriptSchemaError class to SuryError
  • (rescript) Renamed S.Raised exception to S.Error
  • (rescript) Removed Error module. You can access message and reason directly on error type. Also, added the ErrorClass module to replace Error.class for advanced use-cases.
  • (rescript) Removed RescriptSchema namespace. Namespace was causing many issues with IDE autocompletion and discoverability, so now S is exposed directly without a namespace.
  • Improve thrown error display in Node.js console #106

API changes

  • Removed deprecated S.to in favor of S.shape & Renamed S.coerce to S.to. Sorry for the mess 😅

  • Enhanced S.to to support more cases:

    • From any literal to another literal S.schema(1).with(S.to, S.schema(true))
    • S.union, S.option and S.null as target types are now supported
    • S.to can now be used on unknown schemas. It'll apply the target schema validation to the unknown schema output.
    • S.to can be targeted to unknown schema.
  • Removed S.preprocess in favor of S.to and S.transform.

  • (rescript) Renamed S.nullable to S.nullish to match js/ts api

  • (rescript) Added S.nullAsUnit

  • (js/ts) Removed S.undefined in favor of S.schema(undefined)

  • (js/ts) Allow to pass default value to S.nullable

  • (js/ts) Stopped transforming null to undefined for S.nullish

  • Fixed multiple TS type issues:

    • Default the Input generic to unknown instead of Output
      - export type Schema<Output, Input = Output>
      + export type Schema<Output, Input = unknown>
    • Fixed S.to TS type (previously S.coerce)
    • Fixed infered type of S.merge call (#107)
    • Correctly infer optional fields when using S.schema (#87)
  • Changed S.removeTypeValidation to S.noValidation. It doesn't affect union discriminated optimisation anymore.

  • Introduced S.meta to allow to set all the metadata fields on a schema:

    • Removed S.describe in favor of S.meta({description: "..."})
    • Removed S.description in favor of the description field on schema
    • Removed S.deprecate in favor of S.meta({deprecated: true})
    • Removed S.deprecated in favor of the deprecated field on schema
    • Removed S.setName in favor of S.meta({name: "..."})
    • Also, it's possible to set examples using S.meta
    • Renamed S.name to S.toExpression. Also, it's now possible to get the name itself from the name property on schema.
  • (js/ts) Introduced .with method on every schema to allow to chain methods easily: S.string.with(S.meta, {examples: ["Hello", "World"]}) which is the same as S.meta(S.string, {examples: ["Hello", "World"]})

  • (rescript) Removed S.inline because of maintanability issues. I'll reintroduce it in the future.

  • Renamed S.stringMinLength to S.min

  • Renamed S.stringMaxLength to S.max

  • Renamed S.stringLength to S.length

  • Renamed S.intMin to S.min

  • Renamed S.intMax to S.max

  • Renamed S.numberMin to S.min

  • Renamed S.numberMax to S.max

  • Renamed S.arrayMinLength to S.min

  • Renamed S.arrayMaxLength to S.max

  • Renamed S.arrayLength to S.length

PPX changes

  • Error when using unsupported attributes. eg @s.deprecated will error, but @s.meta will work.
  • Added support for @s.meta, @s.noValidation, @s.strict, @s.strip, @s.deepStrict and @s.deepStrip
  • Removed @s.nullable in favor of Nullable.t type support.

Full Changelog: v9.3.0...v10.0.0-rc.0