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

latest releases: @effect/sql-sqlite-wasm@0.21.1, @effect/sql-sqlite-bun@0.21.8, @effect/sql-libsql@0.9.8...
8 months ago

Minor Changes

  • #2172 5d47ee0 Thanks @gcanti! - # Breaking Changes

    • The Format module has been removed

    AST module

    • Tuple has been refactored to TupleType, and its _tag has consequently been renamed. The type of its rest property has changed from Option.Option<ReadonlyArray.NonEmptyReadonlyArray<AST>> to ReadonlyArray<AST>.

    • Transform has been refactored to Transformation, and its _tag property has consequently been renamed. Its property transformation has now the type TransformationKind = FinalTransformation | ComposeTransformation | TypeLiteralTransformation.

    • createRecord has been removed

    • AST.to has been renamed to AST.typeAST

    • AST.from has been renamed to AST.encodedAST

    • ExamplesAnnotation and DefaultAnnotation now accept a type parameter

    • format has been removed:
      Before

      AST.format(ast, verbose?)

      Now

      ast.toString(verbose?)
    • setAnnotation has been removed (use annotations instead)

    • mergeAnnotations has been renamed to annotations

    • move defaultParseOption from Parser.ts to AST.ts

    ParseResult module

    • The ParseResult module now uses classes and custom constructors have been removed:
      Before

      import * as ParseResult from "@effect/schema/ParseResult";
      
      ParseResult.type(ast, actual);

      Now

      import * as ParseResult from "@effect/schema/ParseResult";
      
      new ParseResult.Type(ast, actual);
    • Transform has been refactored to Transformation, and its kind property now accepts "Encoded", "Transformation", or "Type" as values

    Schema module

    • uniqueSymbol has been renamed to uniqueSymbolFromSelf

    • Schema.Schema.To has been renamed to Schema.Schema.Type, and Schema.to to Schema.typeSchema

    • Schema.Schema.From has been renamed to Schema.Schema.Encoded, and Schema.from to Schema.encodedSchema

    • The type parameters of TaggedRequest have been swapped

    • The signature of PropertySignature has been changed from PropertySignature<From, FromOptional, To, ToOptional> to PropertySignature<ToToken extends Token, To, Key extends PropertyKey, FromToken extends Token, From, R>

    • Class APIs

      • Class APIs now expose fields and require an identifier
        -class A extends S.Class<A>()({ a: S.string }) {}
        +class A extends S.Class<A>("A")({ a: S.string }) {}
    • element and rest have been removed in favor of array and tuple:

      Before

      import * as S from "@effect/schema/Schema";
      
      const schema1 = S.tuple().pipe(S.rest(S.number), S.element(S.boolean));
      
      const schema2 = S.tuple(S.string).pipe(
        S.rest(S.number),
        S.element(S.boolean),
      );

      Now

      import * as S from "@effect/schema/Schema";
      
      const schema1 = S.array(S.number, S.boolean);
      
      const schema2 = S.tuple([S.string], S.number, S.boolean);
    • optionalElement has been refactored:

      Before

      import * as S from "@effect/schema/Schema";
      
      const schema = S.tuple(S.string).pipe(S.optionalElement(S.number));

      Now

      import * as S from "@effect/schema/Schema";
      
      const schema = S.tuple(S.string, S.optionalElement(S.number));
    • use TreeFormatter in BrandSchemas

    • Schema annotations interfaces have been refactored into a namespace Annotations

    • the annotations option of the optional constructor has been replaced by the annotations method
      Before

      S.optional(S.string, {
        exact: true,
        annotations: { description: "description" },
      });

      Now

      S.optional(S.string, { exact: true }).annotations({
        description: "description",
      });
    • Updated the pluck function to return Schema<A[K], { readonly [key]: I[K] }> instead of Schema<A[K], I>. Removed the { transformation: false } option in favor of selecting the specific field from the fields exposed by a struct.

    • Removed propertySignatureAnnotations, use propertySignature(schema).annotations().

    • Updated the function name headOr to headOrElse to align with the standard naming convention.

    Serializable module

    • The type parameters of SerializableWithResult and WithResult have been swapped

Patch Changes

  • #2172 5d47ee0 Thanks @gcanti! - ## AST module

    • expose the getTemplateLiteralRegExp API

    Schema module

    • enhance the struct API to allow records:

      const schema1 = S.struct(
        { a: S.number },
        { key: S.string, value: S.number },
      );
      // or
      const schema2 = S.struct({ a: S.number }, S.record(S.string, S.number));
    • enhance the extend API to allow nested (non-overlapping) fields:

      const A = S.struct({ a: S.struct({ b: S.string }) });
      const B = S.struct({ a: S.struct({ c: S.number }) });
      const schema = S.extend(A, B);
      /*
      same as:
      const schema = S.struct({
        a: S.struct({
          b: S.string,
          c: S.number
        })
      })
      */
    • add Annotable interface

    • add asSchema

    • add add Schema.Any, Schema.All, Schema.AnyNoContext helpers

    • refactor annotations API to be a method within the Schema interface

    • add support for AST.keyof, AST.getPropertySignatures, Parser.getSearchTree to Classes

    • fix BrandAnnotation type and add getBrandAnnotation

    • add annotations? parameter to Class constructors:

      import * as AST from "@effect/schema/AST";
      import * as S from "@effect/schema/Schema";
      
      class A extends S.Class<A>()(
        {
          a: S.string,
        },
        { description: "some description..." }, // <= annotations
      ) {}
      
      console.log(AST.getDescriptionAnnotation((A.ast as AST.Transform).to));
      // => { _id: 'Option', _tag: 'Some', value: 'some description...' }
  • Updated dependencies [5d47ee0, 817a04c, d90a99d, dd05faa, dd05faa, 802674b]:

    • effect@2.4.4

Don't miss a new effect release

NewReleases is sending notifications on new releases.