-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore(deps): update effect schema 0.69 #96
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- [#3227](Effect-TS/effect#3227) [`20807a4`](Effect-TS/effect@20807a4) - ## 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: ```bash npx @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. ## Breaking Changes ### Schema - We've improved the `TaggedRequest` API to make it more intuitive by grouping parameters into a single object (**codmod**), closes #3144 Before Update ```ts class Sample extends Schema.TaggedRequest<Sample>()( "Sample", Schema.String, // Failure Schema Schema.Number, // Success Schema { id: Schema.String, foo: Schema.Number } // Payload Schema ) {} ``` After Update ```ts class Sample extends Schema.TaggedRequest<Sample>()("Sample", { payload: { id: Schema.String, foo: Schema.Number }, success: Schema.Number, failure: Schema.String }) {} ``` - change `TaggedRequestClass` type parameters order (swap `Success` with `Failure`) - simplify `TaggedRequest.Any`, use `TaggedRequest.All` instead - To improve clarity, we have renamed `nonEmpty` filter to `nonEmptyString` and `NonEmpty` schema to `NonEmptyString` (**codmod**), closes #3115 - The `Record` constructor now consistently accepts an object argument, aligning it with similar constructors such as `Map` and `HashMap` (**codmod**), closes #2793 Before Update ```ts import { Schema } from "@effect/schema" const schema = Schema.Record(Schema.String, Schema.Number) ``` After Update ```ts import { Schema } from "@effect/schema" const schema = Schema.Record({ key: Schema.String, value: Schema.Number }) ``` - rename `Base64` to `Uint8ArrayFromBase64` (**codmod**) - rename `Base64Url` to `Uint8ArrayFromBase64Url` (**codmod**) - rename `Hex` to `Uint8ArrayFromHex` (**codmod**) - make `defect` schema required in `ExitFromSelf`, `Exit`, `CauseFromSelf`, `CauseFromSelf` (**codmod**) This is for two reasons: 1. The optionality of `defect` caused inference issues when the schema was declared within a Struct. In such cases, the `R` type of the schema was erroneously inferred as `unknown` instead of `never`. 2. In general, schema definitions such as `Schema.ExitFromSelf` or `Schema.Exit` shouldn't have a default. The user should actively choose them to avoid hidden behaviors. - rename `CauseDefectUnknown` to `Defect` (**codmod**) - fix `Schema.Void` behavior: now accepts any value instead of only validating `undefined`, closes #3297 - rename `optionalWithOptions` interface to `optionalWith` - We've refined the `optional` and `partial` APIs by splitting them into two distinct methods: one without options (`optional` and `partial`) and another with options (`optionalWith` and `partialWith`). This change resolves issues with previous implementations when used with the `pipe` method: ```ts Schema.String.pipe(Schema.optional) ``` ### ParseResult - `Missing`: change `ast` field from `AST.Annotated` to `AST.Type` - `Composite`: change `ast` field from `AST.Annotated` to `AST.AST` - `Type`: change `ast` field from `AST.Annotated` to `AST.AST` - `Forbidden`: change `ast` field from `AST.Annotated` to `AST.AST` ### AST - pass the input of the transformation to `transform` and `transformOrFail` APIs - fix `TemplateLiteralSpan.toString` implementation by returning both its type and its literal Before ```ts import { AST } from "@effect/schema" console.log(String(new AST.TemplateLiteralSpan(AST.stringKeyword, "a"))) // ${string} ``` Now ```ts import { AST } from "@effect/schema" console.log(String(new AST.TemplateLiteralSpan(AST.stringKeyword, "a"))) // ${string}a ``` ### Serializable - change `WithResult` fields to standard lowercase (`Success` -> `success`, `Failure` -> `failure`) - rename `WithResult.Error` to `WithResult.Failure` ## New Features ### Schema - add `StringFromBase64` transformation - add `StringFromBase64Url` transformation - add `StringFromHex` transformation - add `TaggedRequest.All` - Support for extending `Schema.String`, `Schema.Number`, and `Schema.Boolean` with refinements has been added: ```ts import { Schema } from "@effect/schema" const Integer = Schema.Int.pipe(Schema.brand("Int")) const Positive = Schema.Positive.pipe(Schema.brand("Positive")) // Schema.Schema<number & Brand<"Positive"> & Brand<"Int">, number, never> const PositiveInteger = Schema.asSchema(Schema.extend(Positive, Integer)) Schema.decodeUnknownSync(PositiveInteger)(-1) /* throws ParseError: Int & Brand<"Int"> └─ From side refinement failure └─ Positive & Brand<"Positive"> └─ Predicate refinement failure └─ Expected Positive & Brand<"Positive">, actual -1 */ Schema.decodeUnknownSync(PositiveInteger)(1.1) /* throws ParseError: Int & Brand<"Int"> └─ Predicate refinement failure └─ Expected Int & Brand<"Int">, actual 1.1 */ ``` ### Serializable - add `WithResult.SuccessEncoded` - add `WithResult.FailureEncoded` - add `WithResult.Any` - add `WithResult.All` - add `asWithResult` - add `Serializable.Any` - add `Serializable.All` - add `asSerializable` - add `SerializableWithResult.Any` - add `SerializableWithResult.All` - add `asSerializableWithResult` Signed-off-by: Giovanni Ravalico <[email protected]>
🦋 Changeset detectedLatest commit: 6735636 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
- [#3333](Effect-TS/effect#3333) [`f241154`](Effect-TS/effect@f241154) - Expose success and failure schemas on `TaggedRequestClass` interface, closes #3331 Signed-off-by: Giovanni Ravalico <[email protected]>
- Updated dependencies [[`1ba640c`](Effect-TS/effect@1ba640c), [`c8c71bd`](Effect-TS/effect@c8c71bd), [`a26ce58`](Effect-TS/effect@a26ce58)]: - [email protected] Signed-off-by: Giovanni Ravalico <[email protected]>
- [#3359](Effect-TS/effect#3359) [`7c0da50`](Effect-TS/effect@7c0da50) - Add `Context` field to `Schema` interface, closes #3356 - [#3363](Effect-TS/effect#3363) [`2fc0ff4`](Effect-TS/effect@2fc0ff4) - export `isPropertySignature` guard - [#3357](Effect-TS/effect#3357) [`f262665`](Effect-TS/effect@f262665) - 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. ```ts 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](Effect-TS/effect#3343) [`9bbe7a6`](Effect-TS/effect@9bbe7a6) - add `NonEmptyTrimmedString` **Example** ```ts import { Schema } from "@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** ```ts import { Schema } from "@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`](Effect-TS/effect@6359644), [`7f41e42`](Effect-TS/effect@7f41e42), [`f566fd1`](Effect-TS/effect@f566fd1)]: Signed-off-by: Giovanni Ravalico <[email protected]>
suddenlyGiovanni
force-pushed
the
renovate/effect-schema-0_69
branch
from
September 3, 2024 22:08
3d163d4
to
6735636
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.