2.0 #278
jacob-alford
announced in
Announcements
2.0
#278
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thank you for supporting schemata-ts! Feel welcome to open PRs, submit issues, or discussions; get yourself on the contributor's list!
Feature Upgrades
No longer depends on io-ts
Schemata 2.0 is built from the ground up with its own extensible version of Schemable hand-crafted for all supported derivations.
(New) Transcoder and TranscoderPar
Schemata-ts 1.0 was built on top of io-ts 'experimental' and had derivations for Decoder, and Encoder. Later, schemata added its own version of Codec which for io-ts meant a combined decoder and encoder, but for schemata meant encoding, decoding, and serialization. Though novel, this prevented serializers from being composable with other schemas. This is because encoding was infallible and thus prevented instances that permitted fallible operations such as serialization and deserialization. Furthermore, io-ts experimental errors used a binary tree
FreeSemigroup
as its error grouping which made working with decode errors cumbersome.Schemata-ts 2.0 comes with its own iteration of Codec: Transcoder. Transcoder has two methods: encode and decode. Both methods are fallible and come with the requirement that encoding and decoding are idempotent, which means that for all inner transcoder types, two consecutive encodes/decodes will round trip up to an isomorphism.
Because Transcoder is now circularly fallible, parser schemas are now possible. Schemata-ts comes with two printer/parser schemas out of the box:
ParseJsonString
which refocuses the input type to valid json-strings, andParseBase64Json
which is the same asParseJsonString
but has an extra step of encoding / decoding the string to and from URI-encoded/decoded base 64.Schemata-ts 2.0 also comes with its own
TranscodeError
which is more ergonomic using ReadonlyNonEmptyArray as its concatenating structure and comes with helpers to reduce its tree structure into common semigroups.TranscoderPar is the same as Transcoder and the successor to TaskDecoder. The difference is that both methods return
TaskEither
s, and operate in parallel for operations where that applies, such as traversing arrays, records, or structs.Json Schema
Now JsonSchema can now be projected into specific versions: Draft-07, 2019-09, and 2020-12. Additionally, JsonSchemas can now be annotated with
reference
for lazy schemas,readOnly
, anddeprecated
. Additionally, theOptional
schema can be supplied a fallback parameter which will lend its JsonSchema adefault
value.(New) Type String
Schemata-ts has consolidated the
expected
error for transcoders largely in part due to the new Type String derivation. Type String is just a tuple of two strings: one input, the other output. Both describe the input/output types for a schema providing pseudo-TypeScript for debugging and typing information. In a pinch, it can be used in documentation or error messages as a quick overview of what's expected.(New) MergeSemigroup
MergeSemigroup is a data type with a method
semigroup
which accepts an argument of either: "first," "last," or an object with semigroups that apply to particular primitives. Calling this method will return a semigroup that merges mergeable data types (like arrays, or records) and uses the supplied parameter for others.And more
Optional
schema will display a?
for input struct properties in type signaturesOptional
now accepts a fallback input valueStruct
now accepts an optional index signature as an additional way to handle unexpected propertiesStrict
schema for raising errors on unexpected keysCamelCaseString
for converting strings into a camelcaseCamelCaseRecord
for converting the keys of a record to all be camelcaseUnion
- a proper union type that first sorts elements by complexity to mitigate non-mutually exclusive union elementsParse
build your own string parser schemasParseEncodedJson
apply a fallible string mapping function to serialized JSONFloat
andInt
branded with their configured min/max valuesString
is now configurable with min/max lengthDate
andDateString
are now configurable withbeforeDate
andafterDate
Array
is now configurable withminLength
andmaxLength
newtype
is now simpler with its ownNewtypeIso
data typebrand
now usestype-fest > Opaque
for compatibility with other systemsSchema
now has stronger type-checking with two new methods: input/output which can be used as constructor functionsEq
module and instancesBreaking Changes
getFoo
interpreters are now calledderiveFoo
in the spirit of Haskell and PurescriptIntersect
is now binary instead of curriedbrand
now usestype-fest
'sOpaque
technique for branding which is incompatible with io-ts's brandingString
now has optional parametersSum
is replaced byUnion
Printer
,JsonSerializer
, andJsonDeserializer
, are now replaced by parser schemasmake
,interpret
,memoize
are no longer exported from a primary module, use pre-constructed schemas insteadType
has been removediso
has been removedstruct
has now been incorporated into the primaryStruct
schema2.0 Roadmap
Error Collation
Transcoders now produce a
Left
which is tagged with the type that produced that particular failure. This means that error reporters can be constructed for specific types. In a future release expect error reporters such as:More Validators
Schemata-ts already has a ton of validators, but expect more in the near future!
Something else?
Schemata-ts welcomes all contributions and ideas, don’t be afraid to open up a ticket, PR, or start a discussion!
This discussion was created from the release 2.0.
Beta Was this translation helpful? Give feedback.
All reactions