Skip to content

Commit

Permalink
chore(deps): update effect schema 0.69.0
Browse files Browse the repository at this point in the history
- [#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]>
  • Loading branch information
suddenlyGiovanni committed Sep 3, 2024
1 parent 1d92ed4 commit b1b20ce
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-swans-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suddenlygiovanni/resume": patch
---

update `@effect/schema` package to v0.69.0
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
},
"license": "UNLICENSED",
"peerDependencies": {
"@effect/schema": "~0.68.27"
"@effect/schema": "~0.69.0"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@changesets/cli": "2.27.7",
"@effect/schema": "0.68.27",
"@effect/schema": "0.69.0",
"@std/yaml": "npm:@jsr/[email protected]",
"@tsconfig/node21": "21.0.3",
"@tsconfig/strictest": "2.0.5",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/schema-primitive/iso-date-string/iso-date-string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from '@effect/schema'

export const ISODateString = Schema.compose(Schema.Trim, Schema.NonEmpty)
export const ISODateString = Schema.compose(Schema.Trim, Schema.NonEmptyString)
.pipe(
Schema.pattern(
/^[0-9]{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(02)-(0[1-9]|[12][0-9]))T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])\.[0-9]{3}Z$/,
Expand Down
2 changes: 1 addition & 1 deletion src/schema-primitive/non-empty-string/non-empty-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const nonEmptyString = (annotations?: Schema.Annotations.Schema<string>):
description: 'a non empty string',
examples: ["' test string '", "'test string'"],
},
).pipe(Schema.compose(Schema.Trim), Schema.nonEmpty())
).pipe(Schema.compose(Schema.Trim), Schema.nonEmptyString())
8 changes: 4 additions & 4 deletions src/schema-resume/award/award.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { StringDate, TrimmedNonEmpty } from '../../schema-primitive/index.js'

export class Award extends Schema.Class<Award>('Award')({
awarder: Schema.optional(
awarder: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'awarder',
description: 'The name of the award given',
Expand All @@ -12,15 +12,15 @@ export class Award extends Schema.Class<Award>('Award')({
{ exact: true },
),

date: Schema.optional(
date: Schema.optionalWith(
StringDate.annotations({
title: 'date',
description: 'Date of the award',
}),
{ exact: true },
),

summary: Schema.optional(
summary: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'summary',
description: 'A brief summary of the award',
Expand All @@ -29,7 +29,7 @@ export class Award extends Schema.Class<Award>('Award')({
{ exact: true },
),

title: Schema.optional(
title: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'title',
description: 'Title of the award',
Expand Down
6 changes: 3 additions & 3 deletions src/schema-resume/basics/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Profile } from '../profile/profile.js'
export class Basics extends Schema.Class<Basics>('Basics')({
email: Email,

image: Schema.optional(
image: Schema.optionalWith(
UrlString.annotations({
title: 'image',
description: 'URL to a image in JPEG or PNG format (as per RFC 3986)',
Expand All @@ -29,7 +29,7 @@ export class Basics extends Schema.Class<Basics>('Basics')({
examples: ['Thomas Anderson'],
}),

phone: Schema.optional(
phone: Schema.optionalWith(
Phone.annotations({
title: 'phone',
description:
Expand All @@ -50,7 +50,7 @@ export class Basics extends Schema.Class<Basics>('Basics')({
examples: ['Web Developer with a passion for web-based applications'],
}),

url: Schema.optional(
url: Schema.optionalWith(
UrlString.annotations({
title: 'url',
description: 'URL (as per RFC 3986) to your website, e.g. personal homepage',
Expand Down
8 changes: 4 additions & 4 deletions src/schema-resume/certificates/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { StringDate, TrimmedNonEmpty, UrlString } from '../../schema-primitive/index.js'

export class Certificate extends Schema.Class<Certificate>('Certificate')({
name: Schema.optional(
name: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'Name',
description: 'name of the certificate',
Expand All @@ -12,14 +12,14 @@ export class Certificate extends Schema.Class<Certificate>('Certificate')({
{ exact: true },
),

date: Schema.optional(
date: Schema.optionalWith(
StringDate.annotations({
title: 'date',
}),
{ exact: true },
),

url: Schema.optional(
url: Schema.optionalWith(
UrlString.annotations({
title: 'url',
description: 'the url of the certificate',
Expand All @@ -28,7 +28,7 @@ export class Certificate extends Schema.Class<Certificate>('Certificate')({
{ exact: true },
),

issuer: Schema.optional(
issuer: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'issuer',
description: 'issuer of the certificate',
Expand Down
10 changes: 5 additions & 5 deletions src/schema-resume/education/education.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Education extends Schema.Class<Education>('Education')({
examples: ['Arts', 'Computer Science'],
}),

courses: Schema.optional(
courses: Schema.optionalWith(
Schema.Array(
TrimmedNonEmpty.annotations({
title: 'course',
Expand All @@ -23,7 +23,7 @@ export class Education extends Schema.Class<Education>('Education')({
{ exact: true },
),

endDate: Schema.optional(
endDate: Schema.optionalWith(
StringDate.annotations({
title: 'endDate',
description: 'end date of education',
Expand All @@ -32,7 +32,7 @@ export class Education extends Schema.Class<Education>('Education')({
{ exact: true },
),

score: Schema.optional(
score: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'score',
description: 'grade point average, e.g. 3.67/4.0',
Expand All @@ -49,7 +49,7 @@ export class Education extends Schema.Class<Education>('Education')({
examples: ['Massachusetts Institute of Technology'],
}),

location: Schema.optional(TrimmedNonEmpty, { exact: true }),
location: Schema.optionalWith(TrimmedNonEmpty, { exact: true }),

startDate: StringDate.annotations({
title: 'startDate',
Expand All @@ -63,7 +63,7 @@ export class Education extends Schema.Class<Education>('Education')({
examples: ['Bachelor', 'Master', 'Doctorate'],
}),

url: Schema.optional(
url: Schema.optionalWith(
UrlString.annotations({
title: 'url',
description: 'URL (as per RFC 3986) of the institution',
Expand Down
4 changes: 2 additions & 2 deletions src/schema-resume/interest/interest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { TrimmedNonEmpty } from '../../schema-primitive/index.js'

export class Interest extends Schema.Class<Interest>('Interest')({
keywords: Schema.optional(
keywords: Schema.optionalWith(
Schema.Array(
TrimmedNonEmpty.annotations({
title: 'keyword',
Expand All @@ -17,7 +17,7 @@ export class Interest extends Schema.Class<Interest>('Interest')({
{ exact: true },
),

name: Schema.optional(
name: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'name',
description: 'Interest name',
Expand Down
4 changes: 2 additions & 2 deletions src/schema-resume/language/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { TrimmedNonEmpty } from '../../schema-primitive/index.js'

export class Language extends Schema.Class<Language>('Language')({
fluency: Schema.optional(
fluency: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'fluency',
description: 'e.g. Fluent, Beginner',
Expand All @@ -12,7 +12,7 @@ export class Language extends Schema.Class<Language>('Language')({
{ exact: true },
),

language: Schema.optional(
language: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'language',
description: 'e.g. English, Spanish',
Expand Down
6 changes: 3 additions & 3 deletions src/schema-resume/location/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const countryCode =
}

export class Location extends Schema.Class<Location>('Location')({
address: Schema.optional(
address: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'address',
description: 'To add multiple address lines, use "\\n".',
Expand All @@ -55,7 +55,7 @@ export class Location extends Schema.Class<Location>('Location')({
}),
),

postalCode: Schema.optional(
postalCode: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'postalCode',
description: 'European postal code',
Expand All @@ -66,7 +66,7 @@ export class Location extends Schema.Class<Location>('Location')({
},
),

region: Schema.optional(
region: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'region',
description: 'The general region where you live. Can be a US state, or a province',
Expand Down
20 changes: 10 additions & 10 deletions src/schema-resume/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { StringDate, TrimmedNonEmpty, UrlString } from '../../schema-primitive/index.js'

export class Project extends Schema.Class<Project>('Project')({
description: Schema.optional(
description: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'description',
description: 'Short summary of project',
Expand All @@ -12,9 +12,9 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

endDate: Schema.optional(StringDate, { exact: true }),
endDate: Schema.optionalWith(StringDate, { exact: true }),

entity: Schema.optional(
entity: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'entity',
description: 'Specify the relevant company/entity affiliations',
Expand All @@ -23,7 +23,7 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

highlights: Schema.optional(
highlights: Schema.optionalWith(
Schema.Array(
TrimmedNonEmpty.annotations({
title: 'highlight',
Expand All @@ -37,7 +37,7 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

keywords: Schema.optional(
keywords: Schema.optionalWith(
Schema.Array(
TrimmedNonEmpty.annotations({
title: 'keyword',
Expand All @@ -50,7 +50,7 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

name: Schema.optional(
name: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'name',
description: 'Name of the project',
Expand All @@ -59,7 +59,7 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

roles: Schema.optional(
roles: Schema.optionalWith(
Schema.Array(
TrimmedNonEmpty.annotations({
title: 'role',
Expand All @@ -72,9 +72,9 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

startDate: Schema.optional(StringDate, { exact: true }),
startDate: Schema.optionalWith(StringDate, { exact: true }),

type: Schema.optional(
type: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'type',
description: 'Type of project',
Expand All @@ -83,7 +83,7 @@ export class Project extends Schema.Class<Project>('Project')({
{ exact: true },
),

url: Schema.optional(
url: Schema.optionalWith(
UrlString.annotations({
title: 'url',
description: 'URL (as per RFC 3986) to the project page',
Expand Down
10 changes: 5 additions & 5 deletions src/schema-resume/publication/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Schema } from '@effect/schema'
import { StringDate, TrimmedNonEmpty, UrlString } from '../../schema-primitive/index.js'

export class Publication extends Schema.Class<Publication>('Publication')({
name: Schema.optional(
name: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'name',
description: 'The name of the publication',
Expand All @@ -12,7 +12,7 @@ export class Publication extends Schema.Class<Publication>('Publication')({
{ exact: true },
),

publisher: Schema.optional(
publisher: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'publisher',
description: 'The publisher of the publication',
Expand All @@ -21,9 +21,9 @@ export class Publication extends Schema.Class<Publication>('Publication')({
{ exact: true },
),

releaseDate: Schema.optional(StringDate, { exact: true }),
releaseDate: Schema.optionalWith(StringDate, { exact: true }),

summary: Schema.optional(
summary: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'summary',
description: 'Short summary of publication',
Expand All @@ -32,7 +32,7 @@ export class Publication extends Schema.Class<Publication>('Publication')({
{ exact: true },
),

url: Schema.optional(
url: Schema.optionalWith(
UrlString.annotations({
title: 'url',
description: 'URL (as per RFC 3986) to the publication',
Expand Down
2 changes: 1 addition & 1 deletion src/schema-resume/reference/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Reference extends Schema.Class<Reference>('Reference')({
examples: ['Timothy Cook'],
}),

reference: Schema.optional(
reference: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'reference',
description: 'The reference text',
Expand Down
Loading

0 comments on commit b1b20ce

Please sign in to comment.