Minor Changes
-
#3227
20807a4
Thanks @gcanti! - ## CodemodFor 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 @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 #3144Before Update
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
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 (swapSuccess
withFailure
) -
simplify
TaggedRequest.Any
, useTaggedRequest.All
instead -
To improve clarity, we have renamed
nonEmpty
filter tononEmptyString
andNonEmpty
schema toNonEmptyString
(codmod), closes #3115 -
The
Record
constructor now consistently accepts an object argument, aligning it with similar constructors such asMap
andHashMap
(codmod), closes #2793Before Update
import { Schema } from "@effect/schema"; const schema = Schema.Record(Schema.String, Schema.Number);
After Update
import { Schema } from "@effect/schema"; const schema = Schema.Record({ key: Schema.String, value: Schema.Number });
-
rename
Base64
toUint8ArrayFromBase64
(codmod) -
rename
Base64Url
toUint8ArrayFromBase64Url
(codmod) -
rename
Hex
toUint8ArrayFromHex
(codmod) -
make
defect
schema required inExitFromSelf
,Exit
,CauseFromSelf
,CauseFromSelf
(codmod)
This is for two reasons:- The optionality of
defect
caused inference issues when the schema was declared within a Struct. In such cases, theR
type of the schema was erroneously inferred asunknown
instead ofnever
. - In general, schema definitions such as
Schema.ExitFromSelf
orSchema.Exit
shouldn't have a default. The user should actively choose them to avoid hidden behaviors.
- The optionality of
-
rename
CauseDefectUnknown
toDefect
(codmod) -
fix
Schema.Void
behavior: now accepts any value instead of only validatingundefined
, closes #3297 -
rename
optionalWithOptions
interface tooptionalWith
-
We've refined the
optional
andpartial
APIs by splitting them into two distinct methods: one without options (optional
andpartial
) and another with options (optionalWith
andpartialWith
). This change resolves issues with previous implementations when used with thepipe
method:Schema.String.pipe(Schema.optional);
ParseResult
Missing
: changeast
field fromAST.Annotated
toAST.Type
Composite
: changeast
field fromAST.Annotated
toAST.AST
Type
: changeast
field fromAST.Annotated
toAST.AST
Forbidden
: changeast
field fromAST.Annotated
toAST.AST
AST
-
pass the input of the transformation to
transform
andtransformOrFail
APIs -
fix
TemplateLiteralSpan.toString
implementation by returning both its type and its literalBefore
import { AST } from "@effect/schema"; console.log(String(new AST.TemplateLiteralSpan(AST.stringKeyword, "a"))); // ${string}
Now
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
toWithResult.Failure
New Features
Schema
-
add
StringFromBase64
transformation -
add
StringFromBase64Url
transformation -
add
StringFromHex
transformation -
add
TaggedRequest.All
-
Support for extending
Schema.String
,Schema.Number
, andSchema.Boolean
with refinements has been added: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
-