github Effect-TS/effect @effect/schema@0.62.7

latest releases: @effect/vitest@0.10.5, @effect/sql-sqlite-wasm@0.13.0, @effect/sql-sqlite-react-native@0.16.0...
7 months ago

Patch Changes

  • #2141 dbff62c Thanks @gcanti! - add { exact: true } optional argument to the partial API, mirroring the implementation in the optional API, closes #2140

    The partial operation allows you to make all properties within a schema optional.

    By default, the partial operation adds a union with undefined to the types. If you wish to avoid this, you can opt-out by passing a { exact: true } argument to the partial operation.

    Example

    import * as S from "@effect/schema/Schema";
    
    /*
    const schema: S.Schema<{
        readonly a?: string | undefined;
    }, {
        readonly a?: string | undefined;
    }, never>
    */
    const schema = S.partial(S.struct({ a: S.string }));
    
    S.decodeUnknownSync(schema)({ a: "a" }); // ok
    S.decodeUnknownSync(schema)({ a: undefined }); // ok
    
    /*
    const exact: S.Schema<{
        readonly a?: string;
    }, {
        readonly a?: string;
    }, never>
    */
    const exactSchema = S.partial(S.struct({ a: S.string }), { exact: true });
    
    S.decodeUnknownSync(exactSchema)({ a: "a" }); // ok
    S.decodeUnknownSync(exactSchema)({ a: undefined });
    /*
    throws:
    Error: { a?: string }
    └─ ["a"]
       └─ Expected a string, actual undefined
    */
  • #2128 e572b07 Thanks @tim-smart! - allow passing structs when encoding schema classes

    The following will no longer throw an error:

    import * as S from "@effect/schema/Schema";
    
    class C extends S.Class<C>()({
      n: S.NumberFromString,
    }) {
      get b() {
        return 1;
      }
    }
    class D extends S.Class<D>()({
      n: S.NumberFromString,
      b: S.number,
    }) {}
    
    console.log(S.encodeSync(D)(new C({ n: 1 })));
    // Output: { b: 1, n: '1' }
  • #2123 e787a57 Thanks @gcanti! - Refactor the declare signature to ensure that the decoding and encoding functions do not utilize context.

    As a result, we can relax the signature of the following functions to accept R !== never:

    • Parser.validateSync
    • Parser.validateOption
    • Parser.validateEither
    • Parser.is
    • Parser.asserts
    • Schema.validateSync
    • Schema.validateOption
    • Schema.validateEither
    • Schema.is
    • Schema.asserts

    Additionally, the Class API no longer requires the optional argument disableValidation to be true when R !== never.

  • Updated dependencies [b1163b2, b46b869, de1b226, a663390, ff88f80, 11be07b, c568645, 88835e5, b415577, ff8046f]:

    • effect@2.3.6

Don't miss a new effect release

NewReleases is sending notifications on new releases.