From eeb04335710bbf72af98077a841a8bd638a816b9 Mon Sep 17 00:00:00 2001 From: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:21:51 +0200 Subject: [PATCH] chore(deps): update effect schema 0.70.1 ## 0.70.1 ### Patch Changes - [#3347](https://github.com/Effect-TS/effect/pull/3347) [`3dce357`](https://github.com/Effect-TS/effect/commit/3dce357efe4a4451d7d29859d08ac11713999b1a) - Enhanced Parsing with `TemplateLiteralParser`, closes #3307 In this update we've introduced a sophisticated API for more refined string parsing: `TemplateLiteralParser`. This enhancement stems from recognizing limitations in the `Schema.TemplateLiteral` and `Schema.pattern` functionalities, which effectively validate string formats without extracting structured data. **Overview of Existing Limitations** The `Schema.TemplateLiteral` function, while useful as a simple validator, only verifies that an input conforms to a specific string pattern by converting template literal definitions into regular expressions. Similarly, `Schema.pattern` employs regular expressions directly for the same purpose. Post-validation, both methods require additional manual parsing to convert the validated string into a usable data format. **Introducing TemplateLiteralParser** To address these limitations and eliminate the need for manual post-validation parsing, the new `TemplateLiteralParser` API has been developed. It not only validates the input format but also automatically parses it into a more structured and type-safe output, specifically into a **tuple** format. This new approach enhances developer productivity by reducing boilerplate code and simplifying the process of working with complex string inputs. **Example** (string based schemas) ```ts import { Schema } from "@effect/schema" // const schema: Schema.Schema const schema = Schema.TemplateLiteralParser( Schema.NumberFromString, "a", Schema.NonEmptyString ) console.log(Schema.decodeEither(schema)("100ab")) // { _id: 'Either', _tag: 'Right', right: [ 100, 'a', 'b' ] } console.log(Schema.encode(schema)([100, "a", "b"])) // { _id: 'Either', _tag: 'Right', right: '100ab' } ``` **Example** (number based schemas) ```ts import { Schema } from "@effect/schema" // const schema: Schema.Schema const schema = Schema.TemplateLiteralParser(Schema.Int, "a") console.log(Schema.decodeEither(schema)("1a")) // { _id: 'Either', _tag: 'Right', right: [ 1, 'a' ] } console.log(Schema.encode(schema)([1, "a"])) // { _id: 'Either', _tag: 'Right', right: '1a' } ``` - [#3346](https://github.com/Effect-TS/effect/pull/3346) [`657fc48`](https://github.com/Effect-TS/effect/commit/657fc48bb32daf2dc09c9335b3cbc3152bcbdd3b) - Implement `DecodingFallbackAnnotation` to manage decoding errors. ```ts export type DecodingFallbackAnnotation = ( issue: ParseIssue ) => Effect ``` This update introduces a `decodingFallback` annotation, enabling custom handling of decoding failures in schemas. This feature allows developers to specify fallback behaviors when decoding operations encounter issues. **Example** ```ts import { Schema } from "@effect/schema" import { Effect, Either } from "effect" // Basic Fallback const schema = Schema.String.annotations({ decodingFallback: () => Either.right("") }) console.log(Schema.decodeUnknownSync(schema)("valid input")) // Output: valid input console.log(Schema.decodeUnknownSync(schema)(null)) // Output: // Advanced Fallback with Logging const schemaWithLog = Schema.String.annotations({ decodingFallback: (issue) => Effect.gen(function* () { yield* Effect.log(issue._tag) yield* Effect.sleep(10) return yield* Effect.succeed("") }) }) Effect.runPromise(Schema.decodeUnknown(schemaWithLog)(null)).then(console.log) /* Output: timestamp=2024-07-25T13:22:37.706Z level=INFO fiber=#0 message=Type */ ``` Signed-off-by: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com> --- .changeset/sweet-months-train.md | 5 +++++ package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/sweet-months-train.md diff --git a/.changeset/sweet-months-train.md b/.changeset/sweet-months-train.md new file mode 100644 index 0000000..b4fa76f --- /dev/null +++ b/.changeset/sweet-months-train.md @@ -0,0 +1,5 @@ +--- +"@suddenlygiovanni/resume": patch +--- + +update `@effect/schema` package to v0.70.1 diff --git a/package.json b/package.json index 3301f55..1493443 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,12 @@ }, "license": "UNLICENSED", "peerDependencies": { - "@effect/schema": "~0.70.0" + "@effect/schema": "~0.70.1" }, "devDependencies": { "@biomejs/biome": "1.8.3", "@changesets/cli": "2.27.7", - "@effect/schema": "0.70.0", + "@effect/schema": "0.70.1", "@std/yaml": "npm:@jsr/std__yaml@1.0.4", "@tsconfig/node21": "21.0.3", "@tsconfig/strictest": "2.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 94105a7..f89da06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: 2.27.7 version: 2.27.7 '@effect/schema': - specifier: 0.70.0 - version: 0.70.0(effect@3.6.0) + specifier: 0.70.1 + version: 0.70.1(effect@3.6.0) '@std/yaml': specifier: npm:@jsr/std__yaml@1.0.4 version: '@jsr/std__yaml@1.0.4' @@ -189,8 +189,8 @@ packages: '@changesets/write@0.3.1': resolution: {integrity: sha512-SyGtMXzH3qFqlHKcvFY2eX+6b0NGiFcNav8AFsYwy5l8hejOeoeTDemu5Yjmke2V5jpzY+pBvM0vCCQ3gdZpfw==} - '@effect/schema@0.70.0': - resolution: {integrity: sha512-3ndFEr9J/F79Fn925XhScGO5i5qxkYXGLy1VgKjjYgXaDhSxxwxqqcyQgSGBaZzM88G7IR4DZaJM1ColnHgj3g==} + '@effect/schema@0.70.1': + resolution: {integrity: sha512-pxHAmOxWXUs7ZcHBTJUHcMg3ici65bOepxWV7cs//ujv1n9cLQJDQE8phUIzbxtROPcEbZwukGgJy7/HlBjx+w==} peerDependencies: effect: ^3.6.0 @@ -1512,7 +1512,7 @@ snapshots: human-id: 1.0.2 prettier: 2.8.8 - '@effect/schema@0.70.0(effect@3.6.0)': + '@effect/schema@0.70.1(effect@3.6.0)': dependencies: effect: 3.6.0 fast-check: 3.22.0