Minor Changes
-
#2172
5d47ee0
Thanks @gcanti! - # Breaking Changes- The
Format
module has been removed
AST
module-
Tuple
has been refactored toTupleType
, and its_tag
has consequently been renamed. The type of itsrest
property has changed fromOption.Option<ReadonlyArray.NonEmptyReadonlyArray<AST>>
toReadonlyArray<AST>
. -
Transform
has been refactored toTransformation
, and its_tag
property has consequently been renamed. Its propertytransformation
has now the typeTransformationKind = FinalTransformation | ComposeTransformation | TypeLiteralTransformation
. -
createRecord
has been removed -
AST.to
has been renamed toAST.typeAST
-
AST.from
has been renamed toAST.encodedAST
-
ExamplesAnnotation
andDefaultAnnotation
now accept a type parameter -
format
has been removed:
BeforeAST.format(ast, verbose?)
Now
ast.toString(verbose?)
-
setAnnotation
has been removed (useannotations
instead) -
mergeAnnotations
has been renamed toannotations
-
move
defaultParseOption
fromParser.ts
toAST.ts
ParseResult
module-
The
ParseResult
module now uses classes and custom constructors have been removed:
Beforeimport * as ParseResult from "@effect/schema/ParseResult"; ParseResult.type(ast, actual);
Now
import * as ParseResult from "@effect/schema/ParseResult"; new ParseResult.Type(ast, actual);
-
Transform
has been refactored toTransformation
, and itskind
property now accepts"Encoded"
,"Transformation"
, or"Type"
as values
Schema
module-
uniqueSymbol
has been renamed touniqueSymbolFromSelf
-
Schema.Schema.To
has been renamed toSchema.Schema.Type
, andSchema.to
toSchema.typeSchema
-
Schema.Schema.From
has been renamed toSchema.Schema.Encoded
, andSchema.from
toSchema.encodedSchema
-
The type parameters of
TaggedRequest
have been swapped -
The signature of
PropertySignature
has been changed fromPropertySignature<From, FromOptional, To, ToOptional>
toPropertySignature<ToToken extends Token, To, Key extends PropertyKey, FromToken extends Token, From, R>
-
Class APIs
- Class APIs now expose
fields
and require an identifier-class A extends S.Class<A>()({ a: S.string }) {} +class A extends S.Class<A>("A")({ a: S.string }) {}
- Class APIs now expose
-
element
andrest
have been removed in favor ofarray
andtuple
:Before
import * as S from "@effect/schema/Schema"; const schema1 = S.tuple().pipe(S.rest(S.number), S.element(S.boolean)); const schema2 = S.tuple(S.string).pipe( S.rest(S.number), S.element(S.boolean), );
Now
import * as S from "@effect/schema/Schema"; const schema1 = S.array(S.number, S.boolean); const schema2 = S.tuple([S.string], S.number, S.boolean);
-
optionalElement
has been refactored:Before
import * as S from "@effect/schema/Schema"; const schema = S.tuple(S.string).pipe(S.optionalElement(S.number));
Now
import * as S from "@effect/schema/Schema"; const schema = S.tuple(S.string, S.optionalElement(S.number));
-
use
TreeFormatter
inBrandSchema
s -
Schema annotations interfaces have been refactored into a namespace
Annotations
-
the
annotations
option of theoptional
constructor has been replaced by theannotations
method
BeforeS.optional(S.string, { exact: true, annotations: { description: "description" }, });
Now
S.optional(S.string, { exact: true }).annotations({ description: "description", });
-
Updated the
pluck
function to returnSchema<A[K], { readonly [key]: I[K] }>
instead ofSchema<A[K], I>
. Removed the{ transformation: false }
option in favor of selecting the specific field from thefields
exposed by a struct. -
Removed
propertySignatureAnnotations
, usepropertySignature(schema).annotations()
. -
Updated the function name
headOr
toheadOrElse
to align with the standard naming convention.
Serializable
module- The type parameters of
SerializableWithResult
andWithResult
have been swapped
- The
Patch Changes
-
#2172
5d47ee0
Thanks @gcanti! - ##AST
module- expose the
getTemplateLiteralRegExp
API
Schema
module-
enhance the
struct
API to allow records:const schema1 = S.struct( { a: S.number }, { key: S.string, value: S.number }, ); // or const schema2 = S.struct({ a: S.number }, S.record(S.string, S.number));
-
enhance the
extend
API to allow nested (non-overlapping) fields:const A = S.struct({ a: S.struct({ b: S.string }) }); const B = S.struct({ a: S.struct({ c: S.number }) }); const schema = S.extend(A, B); /* same as: const schema = S.struct({ a: S.struct({ b: S.string, c: S.number }) }) */
-
add
Annotable
interface -
add
asSchema
-
add add
Schema.Any
,Schema.All
,Schema.AnyNoContext
helpers -
refactor
annotations
API to be a method within theSchema
interface -
add support for
AST.keyof
,AST.getPropertySignatures
,Parser.getSearchTree
to Classes -
fix
BrandAnnotation
type and addgetBrandAnnotation
-
add
annotations?
parameter to Class constructors:import * as AST from "@effect/schema/AST"; import * as S from "@effect/schema/Schema"; class A extends S.Class<A>()( { a: S.string, }, { description: "some description..." }, // <= annotations ) {} console.log(AST.getDescriptionAnnotation((A.ast as AST.Transform).to)); // => { _id: 'Option', _tag: 'Some', value: 'some description...' }
- expose the
-
Updated dependencies [
5d47ee0
,817a04c
,d90a99d
,dd05faa
,dd05faa
,802674b
]:- effect@2.4.4