Skip to content

Releases: DZakh/rescript-schema

v8.4.0

17 Oct 07:22
Compare
Choose a tag to compare

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 anymore
  • s.flatten stopped working with S.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

27 Sep 09:08
Compare
Choose a tag to compare

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 of S.isAsync
  • Deprecated S.assertOrRaiseWith in favor of S.assertAnyWith
  • Deprecated S.parseOrRaiseWith, S.parseAnyOrRaiseWith, S.serializeOrRaiseWith, S.serializeToUnknownOrRaiseWith, S.serializeToJsonStringOrRaiseWith. Use safe versions instead, together with the new S.unwrap helper. If you care about performance, I recommend using S.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

10 Sep 18:00
Compare
Choose a tag to compare

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

29 Aug 16:54
Compare
Choose a tag to compare

🆕 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

15 Aug 17:22
Compare
Choose a tag to compare
  • Fix TS type for assert
  • Fix TS type for s.fail
  • Update regular expressions used for email and uuid validations. It adds support for uuidv7 validation.

Full Changelog: v8.0.2...v8.0.3

v8.0.2

28 Jul 17:05
Compare
Choose a tag to compare
  • Added S.recursive support for JS/TS API

Full Changelog: v8.0.1...v8.0.2

v8.0.1

22 Jul 17:32
Compare
Choose a tag to compare

Fixes S.refine incorrect behaviour for some schemas #79

Full Changelog: v8.0.0...v8.0.1

v8.0.0

15 Jul 08:40
Compare
Choose a tag to compare

Big clean up release

  • Added S.assertOrRaiseWith or schema.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 from Strip to Strict
    • Disable NaN check for numbers
  • 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 and S.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
  • 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 of InvalidType
    • Changed default name of S.literal schema (Literal(<value>) -> <value>)
    • Renamed InvalidJsonStruct error to InvalidJsonSchema, since after rescript-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

12 Jul 21:25
Compare
Choose a tag to compare
  • 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

17 Jun 13:38
Compare
Choose a tag to compare

Fix regression with transformed object serializing in unions.

Full Changelog: v7.0.0...v7.0.1