Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency @effect/schema to ^0.70.0 #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Mar 13, 2024

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@effect/schema (source) ^0.63.0 -> ^0.70.0 age adoption passing confidence

Release Notes

Effect-TS/effect (@​effect/schema)

v0.70.0

Compare Source

Patch Changes

v0.69.3

Compare Source

Patch Changes
  • #​3359 7c0da50 Thanks @​gcanti! - Add Context field to Schema interface, closes #​3356

  • #​3363 2fc0ff4 Thanks @​gcanti! - export isPropertySignature guard

  • #​3357 f262665 Thanks @​gcanti! - Improve annotation retrieval from Class APIs, closes #​3348.

    Previously, accessing annotations such as identifier and title required explicit casting of the ast field to AST.Transformation.
    This update refines the type definitions to reflect that ast is always an AST.Transformation, eliminating the need for casting and simplifying client code.

    import { AST, Schema } from "@​effect/schema";
    
    class Person extends Schema.Class<Person>("Person")(
      {
        name: Schema.String,
        age: Schema.Number,
      },
      { description: "my description" },
    ) {}
    
    console.log(AST.getDescriptionAnnotation(Person.ast.to));
    // { _id: 'Option', _tag: 'Some', value: 'my description' }
  • #​3343 9bbe7a6 Thanks @​gcanti! - - add NonEmptyTrimmedString

    Example

    import { Schema } from "@&#8203;effect/schema";
    
    console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("")); // Option.none()
    console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)(" a ")); // Option.none()
    console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("a")); // Option.some("a")
    • add OptionFromNonEmptyTrimmedString, closes #​3335

      Example

      import { Schema } from "@&#8203;effect/schema";
      
      console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")); // Option.none()
      console.log(
        Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a "),
      ); // Option.some("a")
      console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")); // Option.some("a")
  • Updated dependencies [6359644, 7f41e42, f566fd1]:

    • effect@3.5.9

v0.69.2

Compare Source

Patch Changes

v0.69.1

Compare Source

Patch Changes

v0.69.0

Compare Source

Minor Changes
  • #​3227 20807a4 Thanks @​gcanti! - ## Codemod

    For some of the breking changes, a code-mod has been released to make migration as easy as possible.

    You can run it by executing:

    npx @&#8203;effect/codemod schema-0.69 src/**/*

    It might not be perfect - if you encounter issues, let us know! Also make sure you commit any changes before running it, in case you need to revert anything.

v0.68.27

Compare Source

Patch Changes

v0.68.26

Compare Source

Patch Changes
  • #​3287 f0285d3 Thanks @​gcanti! - JSON Schema: change default behavior for property signatures containing undefined

    Changed the default behavior when encountering a required property signature whose type contains undefined. Instead of raising an exception, undefined is now pruned and the field is set as optional.

    Before

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Struct({
      a: Schema.NullishOr(Schema.Number),
    });
    
    const jsonSchema = JSONSchema.make(schema);
    console.log(JSON.stringify(jsonSchema, null, 2));
    /*
    throws
    Error: Missing annotation
    at path: ["a"]
    details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation
    schema (UndefinedKeyword): undefined
    */

    Now

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Struct({
      a: Schema.NullishOr(Schema.Number),
    });
    
    const jsonSchema = JSONSchema.make(schema);
    console.log(JSON.stringify(jsonSchema, null, 2));
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [], // <=== empty
      "properties": {
        "a": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "$ref": "#/$defs/null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "$defs": {
        "null": {
          "const": null
        }
      }
    }
    */
  • #​3291 8ec4955 Thanks @​gcanti! - remove type-level error message from optional signature, closes #​3290

    This fix eliminates the type-level error message from the optional function signature, which was causing issues in generic contexts.

  • #​3284 3ac2d76 Thanks @​gcanti! - Fix: Correct Handling of JSON Schema Annotations in Refinements

    Fixes an issue where the JSON schema annotation set by a refinement after a transformation was mistakenly interpreted as an override annotation. This caused the output to be incorrect, as the annotations were not applied as intended.

    Before

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Trim.pipe(Schema.nonEmpty());
    
    const jsonSchema = JSONSchema.make(schema);
    console.log(JSON.stringify(jsonSchema, null, 2));
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "minLength": 1
    }
    */

    Now

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Trim.pipe(Schema.nonEmpty());
    
    const jsonSchema = JSONSchema.make(schema);
    console.log(JSON.stringify(jsonSchema, null, 2));
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "string"
    }
    */
  • Updated dependencies [cc327a1, 4bfe4fb, 2b14d18]:

    • effect@3.5.6

v0.68.25

Compare Source

Patch Changes
  • Updated dependencies [a9d7800]:
    • effect@3.5.5

v0.68.24

Compare Source

Patch Changes

v0.68.23

Compare Source

Patch Changes

v0.68.22

Compare Source

Patch Changes

v0.68.21

Compare Source

Patch Changes
  • Updated dependencies [55fdd76]:
    • effect@3.5.1

v0.68.20

Compare Source

Patch Changes

v0.68.19

Compare Source

Patch Changes

v0.68.18

Compare Source

Patch Changes
  • #​3192 5d5cc6c Thanks @​KhraksMamtsov! - Support Capitalize Uncapitalize filters and schemas

  • #​3148 359ff8a Thanks @​gcanti! - add Serializable.Serializable.Type and Serializable.Serializable.Encoded

  • #​3198 f7534b9 Thanks @​gcanti! - Add toString to AST.PropertySignature and AST.IndexSignature and fix type display for IndexSignature.

    Before the Change

    Previously, when a type mismatch occurred in Schema.decodeUnknownSync, the error message displayed for IndexSignature was not accurately representing the type used. For example:

    import { Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Record(Schema.Char, Schema.String);
    
    Schema.decodeUnknownSync(schema)({ a: 1 });
    /*
    throws
    ParseError: { readonly [x: string]: string }
    └─ ["a"]
       └─ Expected string, actual 1
    */

    This output incorrectly indicated [x: string] when the actual index type was Char.

    After the Change

    The toString implementation now correctly reflects the type used in IndexSignature, providing more accurate and informative error messages:

    import { Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Record(Schema.Char, Schema.String);
    
    Schema.decodeUnknownSync(schema)({ a: 1 });
    /*
    throws
    ParseError: { readonly [x: Char]: string }
    └─ ["a"]
       └─ Expected string, actual 1
    */

    The updated output now correctly displays { readonly [x: Char]: string }, aligning the error messages with the actual data types used in the schema.

  • Updated dependencies [a435e0f, b5554db, a9c4fb3]:

    • effect@3.4.8

v0.68.17

Compare Source

Patch Changes
  • #​3166 15967cf Thanks @​gcanti! - Add filterEffect API, closes #​3165

    The filterEffect function enhances the filter functionality by allowing the integration of effects, thus enabling asynchronous or dynamic validation scenarios. This is particularly useful when validations need to perform operations that require side effects, such as network requests or database queries.

    Example: Validating Usernames Asynchronously

    import { Schema } from "@&#8203;effect/schema";
    import { Effect } from "effect";
    
    async function validateUsername(username: string) {
      return Promise.resolve(username === "gcanti");
    }
    
    const ValidUsername = Schema.String.pipe(
      Schema.filterEffect((username) =>
        Effect.promise(() =>
          validateUsername(username).then((valid) => valid || "Invalid username"),
        ),
      ),
    ).annotations({ identifier: "ValidUsername" });
    
    Effect.runPromise(Schema.decodeUnknown(ValidUsername)("xxx")).then(
      console.log,
    );
    /*
    ParseError: ValidUsername
    └─ Transformation process failure
       └─ Invalid username
    */
  • #​3163 2328e17 Thanks @​gcanti! - Add pick and omit static functions to Struct interface, closes #​3152.

    pick

    The pick static function available in each struct schema can be used to create a new Struct by selecting particular properties from an existing Struct.

    import { Schema } from "@&#8203;effect/schema";
    
    const MyStruct = Schema.Struct({
      a: Schema.String,
      b: Schema.Number,
      c: Schema.Boolean,
    });
    
    // Schema.Struct<{ a: typeof Schema.String; c: typeof Schema.Boolean; }>
    const PickedSchema = MyStruct.pick("a", "c");

    omit

    The omit static function available in each struct schema can be used to create a new Struct by excluding particular properties from an existing Struct.

    import { Schema } from "@&#8203;effect/schema";
    
    const MyStruct = Schema.Struct({
      a: Schema.String,
      b: Schema.Number,
      c: Schema.Boolean,
    });
    
    // Schema.Struct<{ a: typeof Schema.String; c: typeof Schema.Boolean; }>
    const PickedSchema = MyStruct.omit("b");
  • Updated dependencies [a5737d6]:

    • effect@3.4.7

v0.68.16

Compare Source

Patch Changes
  • #​3143 d006cec Thanks @​gcanti! - Enhance JSON Schema Support for Refinements in Record Parameters.

    Enhanced JSONSchema.make to properly support refinements as record parameters. Previously, using refinements with Schema.Record resulted in errors when generating JSON schemas.

    Before

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Record(
      Schema.String.pipe(Schema.minLength(1)),
      Schema.Number,
    );
    
    console.log(JSONSchema.make(schema));
    /*
    throws
    Error: Unsupported index signature parameter
    schema (Refinement): a string at least 1 character(s) long
    */

    Now

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Record(
      Schema.String.pipe(Schema.minLength(1)),
      Schema.Number,
    );
    
    console.log(JSONSchema.make(schema));
    /*
    Output:
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [],
      properties: {},
      patternProperties: { '': { type: 'number' } },
      propertyNames: {
        type: 'string',
        description: 'a string at least 1 character(s) long',
        minLength: 1
      }
    }
    */
  • #​3149 cb22726 Thanks @​tim-smart! - add Serializable.WithResult.Success/Error inference helpers

  • #​3139 e911cfd Thanks @​gcanti! - Optimize JSON Schema output for homogeneous tuples (such as non empty arrays).

    This change corrects the JSON Schema generation for S.NonEmptyArray to eliminate redundant schema definitions. Previously, the element schema was unnecessarily duplicated under both items and additionalItems.

v0.68.15

Compare Source

Patch Changes
  • #​3130 34faeb6 Thanks @​gcanti! - Add ReadonlyMapFromRecord and MapFromRecord, closes #​3119

    • decoding
      • { readonly [x: string]: VI } -> ReadonlyMap<KA, VA>
    • encoding
      • ReadonlyMap<KA, VA> -> { readonly [x: string]: VI }
    import { Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.ReadonlyMapFromRecord({
      key: Schema.BigInt,
      value: Schema.NumberFromString,
    });
    
    const decode = Schema.decodeUnknownSync(schema);
    const encode = Schema.encodeSync(schema);
    
    console.log(
      decode({
        "1": "4",
        "2": "5",
        "3": "6",
      }),
    ); // Map(3) { 1n => 4, 2n => 5, 3n => 6 }
    console.log(
      encode(
        new Map([
          [1n, 4],
          [2n, 5],
          [3n, 6],
        ]),
      ),
    ); // { '1': '4', '2': '5', '3': '6' }
  • Updated dependencies [5c0ceb0, 5c0ceb0, 33735b1, 5c0ceb0, 139d4b3]:

    • effect@3.4.6

v0.68.14

Compare Source

Patch Changes

v0.68.13

Compare Source

Patch Changes
  • #​3117 cb76bcb Thanks @​gcanti! - Modified JSONSchema.make to selectively ignore the title and description fields in schema types such as Schema.String, Schema.Number, and Schema.Boolean, closes #​3116

    Before

    import { JSONSchema, Schema as S } from "@&#8203;effect/schema";
    
    const schema = S.Struct({
      foo: S.String,
      bar: S.Number,
    });
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [ 'foo', 'bar' ],
      properties: {
        foo: { type: 'string', description: 'a string', title: 'string' },
        bar: { type: 'number', description: 'a number', title: 'number' }
      },
      additionalProperties: false
    }
    */

    Now

    import { JSONSchema, Schema as S } from "@&#8203;effect/schema";
    
    const schema = S.Struct({
      foo: S.String,
      bar: S.Number,
    });
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [ 'foo', 'bar' ],
      properties: { foo: { type: 'string' }, bar: { type: 'number' } },
      additionalProperties: false
    }
    */

v0.68.12

Compare Source

Patch Changes
  • #​3101 d990544 Thanks @​gcanti! - Generate JSON Schemas correctly for a schema created by extending two refinements using the extend API, ensuring their JSON Schema annotations are preserved.

    Example

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    const schema = Schema.Struct({
      a: Schema.String,
    })
      .pipe(Schema.filter(() => true, { jsonSchema: { a: 1 } }))
      .pipe(
        Schema.extend(
          Schema.Struct({
            b: Schema.Number,
          }).pipe(Schema.filter(() => true, { jsonSchema: { b: 2 } })),
        ),
      );
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [ 'a', 'b' ],
      properties: {
        a: { type: 'string', description: 'a string', title: 'string' },
        b: { type: 'number', description: 'a number', title: 'number' }
      },
      additionalProperties: false,
      b: 2,
      a: 1
    }
    */
  • Updated dependencies [a047af9]:

    • effect@3.4.5

v0.68.11

Compare Source

Patch Changes
  • #​3087 d71c192 Thanks @​gcanti! - Special case S.parseJson to generate JSON Schemas by targeting the "to" side of transformations, closes #​3086

    Resolved an issue where JSONSchema.make improperly generated JSON Schemas for schemas defined with S.parseJson(<real schema>). Previously, invoking JSONSchema.make on these transformed schemas produced a JSON Schema corresponding to a string type rather than the underlying real schema.

    Before

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    // Define a schema that parses a JSON string into a structured object
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.parseJson(Schema.NumberFromString), // Nested parsing from JSON string to number
      }),
    );
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      '$ref': '#/$defs/JsonString',
      '$defs': {
        JsonString: {
          type: 'string',
          description: 'a JSON string',
          title: 'JsonString'
        }
      }
    }
    */

    Now

    import { JSONSchema, Schema } from "@&#8203;effect/schema";
    
    // Define a schema that parses a JSON string into a structured object
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.parseJson(Schema.NumberFromString), // Nested parsing from JSON string to number
      }),
    );
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [ 'a' ],
      properties: { a: { type: 'string', description: 'a string', title: 'string' } },
      additionalProperties: false
    }
    */
  • Updated dependencies [72638e3, d7dde2b, 9b2fc3b]:

    • effect@3.4.4

v0.68.10

Patch Changes

v0.68.9

Patch Changes

v0.68.8

Compare Source

Patch Changes
  • #​3070 192261b Thanks @​gcanti! - Add refineTypeId unique symbol to the refine interface to ensure correct inference of Fields in the Class APIs, closes #​3063

  • Updated dependencies [3da1497]:

    • effect@3.4.2

v0.68.7

Compare Source

Patch Changes
  • Updated dependencies [66a1910]:
    • effect@3.4.1

v0.68.6

Compare Source

Patch Changes
  • #​3046 530fa9e Thanks @​gcanti! - Fix error message display for composite errors when overwrite = false

    This commit resolves an issue where the custom message for a struct (or tuple or union) was displayed regardless of whether the validation error was related to the entire struct or just a specific part of it. Previously, users would see the custom error message even when the error only concerned a particular field within the struct and the flag overwrite was not set to true.

    import { Schema, TreeFormatter } from "@&#8203;effect/schema";
    import { Either } from "effect";
    
    const schema = Schema.Struct({
      a: Schema.String,
    }).annotations({ message: () => "custom message" });
    
    const res = Schema.decodeUnknownEither(schema)({ a: null });
    if (Either.isLeft(res)) {
      console.log(TreeFormatter.formatErrorSync(res.left));
      // before: custom message
      // now: { readonly a: string }
      //      └─ ["a"]
      //         └─ Expected string, actual null
    }

v0.68.5

Compare Source

Patch Changes
  • #​3043 1d62815 Thanks @​gcanti! - Add make constructor to Class-based APIs, closes #​3042

    Introduced a make constructor to class-based APIs to facilitate easier instantiation of classes. This method allows developers to create instances of a class without directly using the new keyword.

    Example

    import { Schema } from "@&#8203;effect/schema";
    
    class MyClass extends Schema.Class<MyClass>("MyClass")({
      someField: Schema.String,
    }) {
      someMethod() {
        return this.someField + "bar";
      }
    }
    
    // Create an instance of MyClass using the make constructor
    const instance = MyClass.make({ someField: "foo" }); // same as new MyClass({ someField: "foo" })
    
    // Outputs to console to demonstrate that the instance is correctly created
    console.log(instance instanceof MyClass); // true
    console.log(instance.someField); // "foo"
    console.log(instance.someMethod()); // "foobar"

v0.68.4

Compare Source

Patch Changes

v0.68.3

Compare Source

Patch Changes
  • #​3028 d473800 Thanks @​gcanti! - Introducing Customizable Parsing Behavior at the Schema Level, closes #​3027

    With this latest update, developers can now set specific parse options for each schema using the parseOptions annotation. This flexibility allows for precise parsing behaviors across different levels of your schema hierarchy, giving you the ability to override settings in parent schemas and propagate settings to nested schemas as needed.

    Here's how you can leverage this new feature:

    import { Schema } from "@&#8203;effect/schema";
    import { Either } from "effect";
    
    const schema = Schema.Struct({
      a: Schema.Struct({
        b: Schema.String,
        c: Schema.String,
      }).annotations({
        title: "first error only",
        parseOptions: { errors: "first" }, // Only the first error in this sub-schema is reported
      }),
      d: Schema.String,
    }).annotations({
      title: "all errors",
      parseOptions: { errors: "all" }, // All errors in the main schema are reported
    });
    
    const result = Schema.decodeUnknownEither(schema)(
      { a: {} },
      { errors: "first" },
    );
    if (Either.isLeft(result)) {
      console.log(result.left.message);
    }
    /*
    all errors
    ├─ ["d"]
    │  └─ is missing
    └─ ["a"]
       └─ first error only
          └─ ["b"]
             └─ is missing
    */

    Detailed Output Explanation:

    In this example:

    • The main schema is configured to display all errors. Hence, you will see errors related to both the d field (since it's missing) and any errors from the a subschema.
    • The subschema (a) is set to display only the first error. Although both b and c fields are missing, only the first missing field (b) is reported.

v0.68.2

Compare Source

Patch Changes

v0.68.1

Compare Source

Patch Changes

v0.68.0

Compare Source

Minor Changes
  • #​2906 f6c7977 Thanks @​gcanti! - ## Refactoring of the ParseIssue Model

    The ParseIssue model in the @effect/schema/ParseResult module has undergone a comprehensive redesign and simplification that enhances its expressiveness without compromising functionality. This section explores the motivation and details of this refactoring.

Enhanced Schema.filter API

The Schema.filter API has been improved to support more complex filtering that can involve multiple properties of a struct. This is especially useful for validations that compare two fields, such as ensuring that a password field matches a confirm_password field, a common requirement in form validations.

Previous Limitations:

Previously, while it was possible to implement a filter that compared two fields, there was no straightforward way to attach validation messages to a specific field. This posed challenges, especially in form validations where precise error reporting is crucial.

Example of Previous Implementation:

import { ArrayFormatter, Schema } from "@&#8203;effect/schema";
import { Either } from "effect";

const Password = Schema.Trim.pipe(Schema.minLength(1));

const MyForm = Schema.Struct({
  password: Password,
  confirm_password: Password,
}).pipe(
  Schema.filter((input) => {
    if (input.password !== input.confirm_password) {
      return "Passwords do not match";
    }
  }),
);

console.log(
  "%o",
  Schema.decodeUnknownEither(MyForm)({
    password: "abc",
    confirm_password: "d",
  }).pipe(Either.mapLeft((error) => ArrayFormatter.formatErrorSync(error))),
);
/*
{
  _id: 'Either',
  _tag: 'Left',
  left: [
    {
      _tag: 'Type',
      path: [],
      message: 'Passwords do not match'
    }
  ]
}
*/

In this scenario, while the filter functionally works, the lack of a specific error path (path: []) means errors are not as descriptive or helpful as they could be.

Specifying Error Paths

With the new improvements, it's now possible to specify an error path along with the message, which enhances error specificity and is particularly beneficial for integration with tools like react-hook-form.

Updated Implementation Example:

import { ArrayFormatter, Schema } from "@&#8203;effect/schema";
import { Either } from "effect";

const Password = Schema.Trim.pipe(Schema.minLength(1));

const MyForm = Schema.Struct({
  password: Password,
  confirm_password: Password,
}).pipe(
  Schema.filter((input) => {
    if (input.password !== input.confirm_password) {
      return {
        path: ["confirm_password"],
        message: "Passwords do not match",
      };
    }
  }),
);

console.log(
  "%o",
  Schema.decodeUnknownEither(MyForm)({
    password: "abc",
    confirm_password: "d",
  }).pipe(Either.mapLeft((error) => ArrayFormatter.formatErrorSync(error))),
);
/*
{
  _id: 'Either',
  _tag: 'Left',
  left: [
    {
      _tag: 'Type',
      path: [ 'confirm_password' ],
      message: 'Passwords do not match'
    }
  ]
}
*/

This modification allows the error to be directly associated with the confirm_password field, improving clarity for the end-user.

Multiple Error Reporting

The refactored API also supports reporting multiple issues at once, which is useful in forms where several validation checks might fail simultaneously.

Example of Multiple Issues Reporting:

import { ArrayFormatter, Schema } from "@&#8203;effect/schema";
import { Either } from "effect";

const Password = Schema.Trim.pipe(Schema.minLength(1));
const OptionalString = Schema.optional(Schema.String);

const MyForm = Schema.Struct({
  password: Password,
  confirm_password: Password,
  name: OptionalString,
  surname: OptionalString,
}).pipe(
  Schema.filter((input) => {
    const issues: Array<Schema.FilterIssue> = [];
    // passwords must match
    if (input.password !== input.confirm_password) {
      issues.push({
        path: ["confirm_password"],
        message: "Passwords do not match",
      });
    }
    // either name or surname must be present
    if (!input.name && !input.surname) {
      issues.push({
        path: ["surname"],
        message: "Surname must be present if name is not present",
      });
    }
    return issues;
  }),
);

console.log(
  "%o",
  Schema.decodeUnknownEither(MyForm)({
    password: "abc",
    confirm_password: "d",
  }).pipe(Either.mapLeft((error) => ArrayFormatter.formatErrorSync(error))),
);
/*
{
  _id: 'Either',
  _tag: 'Left',
  left: [
    {
      _tag: 'Type',
      path: [ 'confirm_password' ],
      message: 'Passwords do not match'
    },
    {
      _tag: 'Type',
      path: [ 'surname' ],
      message: 'Surname must be present if name is not present'
    }
  ]
}
*/
The new ParseIssue Model

The ParseIssue type has undergone a significant restructuring to improve its expressiveness and simplicity. This new model categorizes issues into leaf and composite types, enhancing clarity and making error handling more systematic.

Structure of ParseIsssue Type:

export type ParseIssue =
  // leaf
  | Type
  | Missing
  | Unexpected
  | Forbidden
  // composite
  | Pointer
  | Refinement
  | Transformation
  | Composite;

Key Changes in the Model:

  1. New Members:

    • Composite: A new class that aggregates multiple ParseIssue instances.
    • Missing: Identifies when a required element or value is absent.
    • Unexpected: Flags unexpected elements or values in the input.
    • Pointer: Points to the part of the data structure where an issue occurs.
  2. Removed Members:

    • Previous categories like Declaration, TupleType, TypeLiteral, Union, Member, Key, and Index have been consolidated under the Composite type for a more streamlined approach.

Definition of Composite:

interface Composite {
  readonly _tag: "Composite";
  readonly ast: AST.Annotated;
  readonly actual: unknown;
  readonly issues: ParseIssue | NonEmptyReadonlyArray<ParseIssue>;
  readonly output?: unknown;
}

v0.67.24

Compare Source

Patch Changes
  • #​2997 3b15e1b Thanks @​gcanti! - Improve error handling (type-level) for improper usage of optional, closes #​2995

    This commit addresses concerns raised by users about the confusing behavior when 'optional' is misused in a schema definition. Previously, users experienced unexpected results, such as a schema returning 'Schema.All' when 'optional' was used incorrectly, without clear guidance on the correct usage or error messages.

    Changes:

    • Enhanced the 'optional' method to return a descriptive type-level error when used incorrectly, helping users identify and correct their schema definitions.
    • Updated the Schema.optional() implementation to check its context within a pipeline and ensure it is being used correctly.
    • Added unit tests to verify that the new error handling works as expected and to ensure that correct usage does not affect existing functionality.
  • #​2994 3a750b2 Thanks @​gcanti! - Expose exact option for strict decoding on missing properties, closes #​2993

    This commit addresses an issue where users encountered unexpected decoding behaviors, specifically regarding how undefined values and missing properties are handled. The default behavior of the @effect/schema library treats missing properties as undefined during decoding, which can lead to confusion when stricter validation is expected.

    Changes:

    • Exposed an internal configuration option exțact (default: false), which when set to true, enforces strict decoding that will error on missing properties instead of treating them as undefined.
    • Updated documentation to clearly outline the default and strict decoding behaviors, providing users with guidance on how to enable strict validation.
  • Updated dependencies [06ede85, 7204ca5]:

    • effect@3.3.3

v0.67.23

Compare Source

Patch Changes

v0.67.22

Compare Source

Patch Changes

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch 3 times, most recently from 7adb76c to 3560ed7 Compare March 15, 2024 00:12
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch 2 times, most recently from f62131d to 71971c5 Compare March 23, 2024 00:08
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from 71971c5 to 683e544 Compare April 15, 2024 15:41
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.64.0 fix(deps): update dependency @effect/schema to ^0.65.0 Apr 15, 2024
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from 683e544 to 8aa5115 Compare April 16, 2024 15:57
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.65.0 fix(deps): update dependency @effect/schema to ^0.66.0 Apr 16, 2024
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from 8aa5115 to 31dd1d9 Compare May 10, 2024 16:54
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.66.0 fix(deps): update dependency @effect/schema to ^0.67.0 May 10, 2024
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from 31dd1d9 to ee46a59 Compare June 17, 2024 16:28
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.67.0 fix(deps): update dependency @effect/schema to ^0.68.0 Jun 17, 2024
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from ee46a59 to 7e1bda3 Compare July 23, 2024 14:08
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.68.0 fix(deps): update dependency @effect/schema to ^0.69.0 Jul 23, 2024
@renovate renovate bot force-pushed the renovate/effect-schema-0.x branch from 7e1bda3 to 737952f Compare July 30, 2024 06:57
@renovate renovate bot changed the title fix(deps): update dependency @effect/schema to ^0.69.0 fix(deps): update dependency @effect/schema to ^0.70.0 Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants