@@ -24,7 +24,9 @@ export const Decoder: DecoderOps = {}
2424/**
2525 * @tsplus static Decoder/Ops __call
2626 */
27- export function make < A > ( decodeResult : ( u : unknown ) => Result < Decoder . Error , Decoder . Error , A > ) : Decoder < A > {
27+ export function make < A > (
28+ decodeResult : ( u : unknown ) => Result < Decoder . Error , Decoder . Error , A >
29+ ) : Decoder < A > {
2830 return {
2931 decodeResult
3032 }
@@ -82,7 +84,10 @@ export class DecoderErrorPrimitive implements Decoder.Error {
8284 readonly expectedType : string
8385 ) { }
8486 render = ( ) => {
85- return Tree ( `Expected a value of type "${ this . expectedType } " but received one of type "${ typeof this . value } "` )
87+ return Tree (
88+ `Expected a value of type "${ this . expectedType } " but received one of type "${ typeof this
89+ . value } "`
90+ )
8691 }
8792}
8893
@@ -100,7 +105,10 @@ export class DecoderErrorIsoDateMalformed implements Decoder.Error {
100105 readonly value : unknown
101106 ) { }
102107 render = ( ) => {
103- return Tree ( `Expected a Date represented as an iso string instead received one of type "${ typeof this . value } "` )
108+ return Tree (
109+ `Expected a Date represented as an iso string instead received one of type "${ typeof this
110+ . value } "`
111+ )
104112 }
105113}
106114
@@ -116,7 +124,9 @@ export class DecoderErrorLiteral implements Decoder.Error {
116124 ` of type "${ typeof this . expected } "` :
117125 ""
118126 } instead received ${
119- typeof this . value === typeof this . expected ? `"${ this . value } "` : `one of type "${ typeof this . value } "`
127+ typeof this . value === typeof this . expected ?
128+ `"${ this . value } "` :
129+ `one of type "${ typeof this . value } "`
120130 } `
121131 )
122132 }
@@ -138,18 +148,24 @@ export class DecoderErrorStruct implements Decoder.Error {
138148 constructor (
139149 readonly fields : Chunk < DecoderErrorStructFieldError >
140150 ) { }
141- render = ( ) => Tree ( `Encountered while parsing an object structure` , this . fields . map ( ( d ) => d . render ( ) ) )
151+ render = ( ) =>
152+ Tree ( `Encountered while parsing an object structure` , this . fields . map ( ( d ) => d . render ( ) ) )
142153}
143154
144155export class DecoderErrorTaggedMalformed implements Decoder . Error {
145156 constructor ( readonly keys : string [ ] ) { }
146157 render = ( ) =>
147- Tree ( `Expected a tagged object of the form "{ _tag: ${ this . keys . sort ( ) . map ( k => `"${ k } "` ) . join ( " | " ) } }"` )
158+ Tree (
159+ `Expected a tagged object of the form "{ _tag: ${
160+ this . keys . sort ( ) . map ( k => `"${ k } "` ) . join ( " | " )
161+ } }"`
162+ )
148163}
149164
150165export class DecoderErrorTaggedInner implements Decoder . Error {
151166 constructor ( readonly tag : string , readonly error : Decoder . Error ) { }
152- render = ( ) => Tree ( `Encountered while processing tagged object "${ this . tag } "` , Chunk ( this . error . render ( ) ) )
167+ render = ( ) =>
168+ Tree ( `Encountered while processing tagged object "${ this . tag } "` , Chunk ( this . error . render ( ) ) )
153169}
154170
155171export class DecoderErrorUnionMember implements Decoder . Error {
@@ -171,7 +187,9 @@ export class DecoderErrorArray implements Decoder.Error {
171187 render = ( ) =>
172188 Tree (
173189 `Encountered while processing an Array of elements` ,
174- this . errors . map ( ( [ n , err ] ) => Tree ( `Encountered while processing element "${ n } "` , Chunk ( err . render ( ) ) ) )
190+ this . errors . map ( ( [ n , err ] ) =>
191+ Tree ( `Encountered while processing element "${ n } "` , Chunk ( err . render ( ) ) )
192+ )
175193 )
176194}
177195
@@ -191,35 +209,45 @@ export class DecoderErrorValidation implements Decoder.Error {
191209 * @tsplus implicit
192210 */
193211export const _true : Decoder < true > = Decoder ( ( u ) =>
194- Derive < Guard < true > > ( ) . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "true" ) )
212+ Derive < Guard < true > > ( ) . is ( u ) ?
213+ Result . success ( u ) :
214+ Result . fail ( new DecoderErrorPrimitive ( u , "true" ) )
195215)
196216
197217/**
198218 * @tsplus implicit
199219 */
200220export const _false : Decoder < false > = Decoder ( ( u ) =>
201- Derive < Guard < false > > ( ) . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "false" ) )
221+ Derive < Guard < false > > ( ) . is ( u ) ?
222+ Result . success ( u ) :
223+ Result . fail ( new DecoderErrorPrimitive ( u , "false" ) )
202224)
203225
204226/**
205227 * @tsplus implicit
206228 */
207229export const boolean : Decoder < boolean > = Decoder ( ( u ) =>
208- Derive < Guard < boolean > > ( ) . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "boolean" ) )
230+ Derive < Guard < boolean > > ( ) . is ( u ) ?
231+ Result . success ( u ) :
232+ Result . fail ( new DecoderErrorPrimitive ( u , "boolean" ) )
209233)
210234
211235/**
212236 * @tsplus implicit
213237 */
214238export const string : Decoder < string > = Decoder ( ( u ) =>
215- Derive < Guard < string > > ( ) . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "string" ) )
239+ Derive < Guard < string > > ( ) . is ( u ) ?
240+ Result . success ( u ) :
241+ Result . fail ( new DecoderErrorPrimitive ( u , "string" ) )
216242)
217243
218244/**
219245 * @tsplus implicit
220246 */
221247export const number : Decoder < number > = Decoder ( ( u ) =>
222- Derive < Guard < number > > ( ) . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "number" ) )
248+ Derive < Guard < number > > ( ) . is ( u ) ?
249+ Result . success ( u ) :
250+ Result . fail ( new DecoderErrorPrimitive ( u , "number" ) )
223251)
224252
225253/**
@@ -374,27 +402,37 @@ export function deriveArray<A extends Array<any>>(
374402 if ( hasFailed ) {
375403 return Result . fail ( new DecoderErrorArray ( errors ) )
376404 }
377- return Result . success ( out as A , errors . isEmpty ? Maybe . none : Maybe . some ( new DecoderErrorArray ( errors ) ) )
405+ return Result . success (
406+ out as A ,
407+ errors . isEmpty ? Maybe . none : Maybe . some ( new DecoderErrorArray ( errors ) )
408+ )
378409 }
379410 return Result . fail ( new DecoderErrorPrimitive ( u , "Array" ) )
380411 } )
381412}
382413
383414type EitherStructural < E , A > = { _tag : "Left" ; left : E } | { _tag : "Right" ; right : A }
384415
385- function deriveEitherInternal < E , A > ( left : Decoder < E > , right : Decoder < A > ) : Decoder < EitherStructural < E , A > > {
416+ function deriveEitherInternal < E , A > (
417+ left : Decoder < E > ,
418+ right : Decoder < A >
419+ ) : Decoder < EitherStructural < E , A > > {
386420 return Derive ( )
387421}
388422
389423/**
390424 * @tsplus derive Decoder[Either]<_> 10
391425 */
392426export function deriveEither < A extends Either < any , any > > (
393- ...[ left , right ] : [ A ] extends [ Either < infer _E , infer _A > ] ? [ left : Decoder < _E > , right : Decoder < _A > ] : never
427+ ...[ left , right ] : [ A ] extends [ Either < infer _E , infer _A > ]
428+ ? [ left : Decoder < _E > , right : Decoder < _A > ]
429+ : never
394430) : Decoder < A > {
395431 const structural = deriveEitherInternal ( left , right )
396432 return Decoder ( ( u ) =>
397- structural . decodeResult ( u ) . map ( ( e ) => e . _tag === "Left" ? Either . left ( e . left ) as A : Either . right ( e . right ) as A )
433+ structural . decodeResult ( u ) . map ( ( e ) =>
434+ e . _tag === "Left" ? Either . left ( e . left ) as A : Either . right ( e . right ) as A
435+ )
398436 )
399437}
400438
@@ -415,7 +453,9 @@ export function deriveMaybe<A extends Maybe<any>>(
415453) : Decoder < A > {
416454 const structural = deriveMaybeInternal ( value )
417455 return Decoder ( ( u ) =>
418- structural . decodeResult ( u ) . map ( ( e ) => e . _tag === "Some" ? Maybe . some ( e . value ) as A : Maybe . none as A )
456+ structural . decodeResult ( u ) . map ( ( e ) =>
457+ e . _tag === "Some" ? Maybe . some ( e . value ) as A : Maybe . none as A
458+ )
419459 )
420460}
421461
@@ -424,14 +464,16 @@ export class DecoderErrorRecordValue implements Decoder.Error {
424464 readonly key : string ,
425465 readonly error : Decoder . Error
426466 ) { }
427- render = ( ) => Tree ( `Encountered while parsing a record value at "${ this . key } "` , Chunk ( this . error . render ( ) ) )
467+ render = ( ) =>
468+ Tree ( `Encountered while parsing a record value at "${ this . key } "` , Chunk ( this . error . render ( ) ) )
428469}
429470
430471export class DecoderErrorRecordFields implements Decoder . Error {
431472 constructor (
432473 readonly fields : Chunk < Decoder . Error >
433474 ) { }
434- render = ( ) => Tree ( `Encountered while parsing a record structure` , this . fields . map ( ( d ) => d . render ( ) ) )
475+ render = ( ) =>
476+ Tree ( `Encountered while parsing a record structure` , this . fields . map ( ( d ) => d . render ( ) ) )
435477}
436478
437479export class DecoderErrorRecordMissingKeys implements Decoder . Error {
@@ -440,7 +482,9 @@ export class DecoderErrorRecordMissingKeys implements Decoder.Error {
440482 ) { }
441483 render = ( ) =>
442484 Tree (
443- `Encountered while parsing a record structure, missing keys: ${ this . missing . map ( ( k ) => `"${ k } "` ) . join ( ", " ) } `
485+ `Encountered while parsing a record structure, missing keys: ${
486+ this . missing . map ( ( k ) => `"${ k } "` ) . join ( ", " )
487+ } `
444488 )
445489}
446490
@@ -452,7 +496,9 @@ export function deriveEmptyRecord<A extends {}>(
452496) : Decoder < A > {
453497 const record = Derive < Guard < { } > > ( )
454498 // @ts -expect-error
455- return Decoder ( ( u ) => record . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "{}" ) ) )
499+ return Decoder ( ( u ) =>
500+ record . is ( u ) ? Result . success ( u ) : Result . fail ( new DecoderErrorPrimitive ( u , "{}" ) )
501+ )
456502}
457503
458504/**
@@ -553,9 +599,13 @@ export function deriveRecord<A extends Record<string, any>>(
553599 * @tsplus derive Decoder<_> 20
554600 */
555601export function deriveLiteral < A extends string | number > (
556- ...[ value ] : Check < Check . IsLiteral < A > & Check . Not < Check . IsUnion < A > > > extends Check . True ? [ value : A ] : never
602+ ...[ value ] : Check < Check . IsLiteral < A > & Check . Not < Check . IsUnion < A > > > extends Check . True
603+ ? [ value : A ]
604+ : never
557605) : Decoder < A > {
558- return Decoder ( ( u ) => u === value ? Result . success ( u as A ) : Result . fail ( new DecoderErrorLiteral ( value , u ) ) )
606+ return Decoder ( ( u ) =>
607+ u === value ? Result . success ( u as A ) : Result . fail ( new DecoderErrorLiteral ( value , u ) )
608+ )
559609}
560610
561611/**
0 commit comments