@fncts/base 0.0.33 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_cjs/collection/immutable/Conc/api.cjs +1 -4
- package/_cjs/collection/immutable/Conc/api.cjs.map +1 -1
- package/_cjs/collection/immutable/HashMap/api.cjs +4 -7
- package/_cjs/collection/immutable/HashMap/api.cjs.map +1 -1
- package/_cjs/collection/immutable/HashSet/api.cjs +4 -7
- package/_cjs/collection/immutable/HashSet/api.cjs.map +1 -1
- package/_cjs/collection/immutable/ImmutableArray/api.cjs +6 -9
- package/_cjs/collection/immutable/ImmutableArray/api.cjs.map +1 -1
- package/_cjs/collection/immutable/ImmutableArray/instances.cjs.map +1 -1
- package/_cjs/control/Pure/api.cjs +8 -20
- package/_cjs/control/Pure/api.cjs.map +1 -1
- package/_cjs/data/Cause/api.cjs +2 -8
- package/_cjs/data/Cause/api.cjs.map +1 -1
- package/_cjs/data/Data.cjs +121 -0
- package/_cjs/data/Data.cjs.map +1 -0
- package/_cjs/data/Datum/api.cjs +2 -8
- package/_cjs/data/Datum/api.cjs.map +1 -1
- package/_cjs/data/DatumEither/api.cjs +2 -8
- package/_cjs/data/DatumEither/api.cjs.map +1 -1
- package/_cjs/data/Either/api.cjs +6 -24
- package/_cjs/data/Either/api.cjs.map +1 -1
- package/_cjs/data/Either/definition.cjs +1 -0
- package/_cjs/data/Either/definition.cjs.map +1 -1
- package/_cjs/data/Either/destructors.cjs +3 -3
- package/_cjs/data/Either/destructors.cjs.map +1 -1
- package/_cjs/data/Either/instances.cjs +7 -27
- package/_cjs/data/Either/instances.cjs.map +1 -1
- package/_cjs/data/EitherT/api.cjs +2 -8
- package/_cjs/data/EitherT/api.cjs.map +1 -1
- package/_cjs/data/Exit/api.cjs +3 -3
- package/_cjs/data/Exit/api.cjs.map +1 -1
- package/_cjs/data/Exit/constructors.cjs +1 -4
- package/_cjs/data/Exit/constructors.cjs.map +1 -1
- package/_cjs/data/Exit/definition.cjs +2 -0
- package/_cjs/data/Exit/definition.cjs.map +1 -1
- package/_cjs/data/Guard/api.cjs +4 -2
- package/_cjs/data/Guard/api.cjs.map +1 -1
- package/_cjs/data/Maybe/api.cjs +1 -4
- package/_cjs/data/Maybe/api.cjs.map +1 -1
- package/_cjs/data/Maybe/definition.cjs +1 -0
- package/_cjs/data/Maybe/definition.cjs.map +1 -1
- package/_cjs/data/Maybe/instances.cjs +13 -46
- package/_cjs/data/Maybe/instances.cjs.map +1 -1
- package/_cjs/data/Showable/show.cjs.map +1 -1
- package/_cjs/data/Tag/definition.cjs +8 -0
- package/_cjs/data/Tag/definition.cjs.map +1 -1
- package/_cjs/data/These/instances.cjs +0 -11
- package/_cjs/data/These/instances.cjs.map +1 -1
- package/_cjs/json/EitherJson.cjs +0 -18
- package/_cjs/json/EitherJson.cjs.map +1 -1
- package/_cjs/json/MaybeJson.cjs +0 -16
- package/_cjs/json/MaybeJson.cjs.map +1 -1
- package/_cjs/json/TheseJson.cjs +0 -22
- package/_cjs/json/TheseJson.cjs.map +1 -1
- package/_cjs/optics/Optional/definition.cjs +1 -4
- package/_cjs/optics/Optional/definition.cjs.map +1 -1
- package/_cjs/optics/Prism/definition.cjs +1 -4
- package/_cjs/optics/Prism/definition.cjs.map +1 -1
- package/_cjs/typeclass/MonadExcept.cjs +1 -4
- package/_cjs/typeclass/MonadExcept.cjs.map +1 -1
- package/_mjs/collection/immutable/Conc/api.mjs +1 -4
- package/_mjs/collection/immutable/Conc/api.mjs.map +1 -1
- package/_mjs/collection/immutable/HashMap/api.mjs +4 -7
- package/_mjs/collection/immutable/HashMap/api.mjs.map +1 -1
- package/_mjs/collection/immutable/HashSet/api.mjs +4 -7
- package/_mjs/collection/immutable/HashSet/api.mjs.map +1 -1
- package/_mjs/collection/immutable/ImmutableArray/api.mjs +6 -9
- package/_mjs/collection/immutable/ImmutableArray/api.mjs.map +1 -1
- package/_mjs/collection/immutable/ImmutableArray/instances.mjs.map +1 -1
- package/_mjs/control/Pure/api.mjs +8 -20
- package/_mjs/control/Pure/api.mjs.map +1 -1
- package/_mjs/data/Cause/api.mjs +2 -8
- package/_mjs/data/Cause/api.mjs.map +1 -1
- package/_mjs/data/Data.mjs +110 -0
- package/_mjs/data/Data.mjs.map +1 -0
- package/_mjs/data/Datum/api.mjs +2 -8
- package/_mjs/data/Datum/api.mjs.map +1 -1
- package/_mjs/data/DatumEither/api.mjs +2 -8
- package/_mjs/data/DatumEither/api.mjs.map +1 -1
- package/_mjs/data/Either/api.mjs +6 -24
- package/_mjs/data/Either/api.mjs.map +1 -1
- package/_mjs/data/Either/definition.mjs +1 -0
- package/_mjs/data/Either/definition.mjs.map +1 -1
- package/_mjs/data/Either/destructors.mjs +3 -3
- package/_mjs/data/Either/destructors.mjs.map +1 -1
- package/_mjs/data/Either/instances.mjs +6 -25
- package/_mjs/data/Either/instances.mjs.map +1 -1
- package/_mjs/data/EitherT/api.mjs +2 -8
- package/_mjs/data/EitherT/api.mjs.map +1 -1
- package/_mjs/data/Exit/api.mjs +2 -2
- package/_mjs/data/Exit/api.mjs.map +1 -1
- package/_mjs/data/Exit/constructors.mjs +1 -4
- package/_mjs/data/Exit/constructors.mjs.map +1 -1
- package/_mjs/data/Exit/definition.mjs +2 -0
- package/_mjs/data/Exit/definition.mjs.map +1 -1
- package/_mjs/data/Guard/api.mjs +5 -3
- package/_mjs/data/Guard/api.mjs.map +1 -1
- package/_mjs/data/Maybe/api.mjs +1 -4
- package/_mjs/data/Maybe/api.mjs.map +1 -1
- package/_mjs/data/Maybe/definition.mjs +1 -0
- package/_mjs/data/Maybe/definition.mjs.map +1 -1
- package/_mjs/data/Maybe/instances.mjs +0 -31
- package/_mjs/data/Maybe/instances.mjs.map +1 -1
- package/_mjs/data/Showable/show.mjs.map +1 -1
- package/_mjs/data/Tag/definition.mjs +7 -0
- package/_mjs/data/Tag/definition.mjs.map +1 -1
- package/_mjs/data/These/instances.mjs +0 -10
- package/_mjs/data/These/instances.mjs.map +1 -1
- package/_mjs/json/EitherJson.mjs +0 -15
- package/_mjs/json/EitherJson.mjs.map +1 -1
- package/_mjs/json/MaybeJson.mjs +0 -13
- package/_mjs/json/MaybeJson.mjs.map +1 -1
- package/_mjs/json/TheseJson.mjs +0 -19
- package/_mjs/json/TheseJson.mjs.map +1 -1
- package/_mjs/optics/Optional/definition.mjs +1 -4
- package/_mjs/optics/Optional/definition.mjs.map +1 -1
- package/_mjs/optics/Prism/definition.mjs +1 -4
- package/_mjs/optics/Prism/definition.mjs.map +1 -1
- package/_mjs/typeclass/MonadExcept.mjs +1 -4
- package/_mjs/typeclass/MonadExcept.mjs.map +1 -1
- package/_src/collection/immutable/Conc/api.ts +4 -4
- package/_src/collection/immutable/HashMap/api.ts +4 -4
- package/_src/collection/immutable/HashSet/api.ts +4 -4
- package/_src/collection/immutable/ImmutableArray/api.ts +4 -4
- package/_src/collection/immutable/ImmutableArray/instances.ts +0 -2
- package/_src/control/Pure/api.ts +4 -7
- package/_src/control.ts +0 -2
- package/_src/data/Cause/api.ts +8 -8
- package/_src/data/Data.ts +144 -0
- package/_src/data/Datum/api.ts +8 -8
- package/_src/data/DatumEither/api.ts +8 -8
- package/_src/data/Either/api.ts +18 -18
- package/_src/data/Either/definition.ts +2 -1
- package/_src/data/Either/destructors.ts +3 -3
- package/_src/data/Either/instances.ts +12 -31
- package/_src/data/EitherT/api.ts +8 -8
- package/_src/data/Exit/api.ts +2 -2
- package/_src/data/Exit/constructors.ts +1 -1
- package/_src/data/Exit/definition.ts +2 -0
- package/_src/data/Guard/api.ts +6 -3
- package/_src/data/Maybe/api.ts +4 -4
- package/_src/data/Maybe/definition.ts +1 -0
- package/_src/data/Maybe/instances.ts +0 -39
- package/_src/data/Showable/show.ts +1 -1
- package/_src/data/Tag/definition.ts +8 -0
- package/_src/data/These/instances.ts +0 -22
- package/_src/data.ts +1 -0
- package/_src/global.ts +0 -8
- package/_src/json/EitherJson.ts +0 -7
- package/_src/json/MaybeJson.ts +0 -7
- package/_src/json/TheseJson.ts +0 -7
- package/_src/optics/Optional/definition.ts +4 -4
- package/_src/optics/Prism/definition.ts +1 -1
- package/_src/typeclass/MonadExcept.ts +1 -1
- package/control.d.ts +0 -2
- package/data/Data.d.ts +31 -0
- package/data/Either/definition.d.ts +2 -1
- package/data/Either/destructors.d.ts +1 -4
- package/data/Either/instances.d.ts +0 -6
- package/data/Exit/api.d.ts +2 -2
- package/data/Exit/definition.d.ts +2 -0
- package/data/Guard/api.d.ts +1 -2
- package/data/Maybe/definition.d.ts +1 -0
- package/data/Maybe/instances.d.ts +0 -12
- package/data/Showable/show.d.ts +1 -1
- package/data/Tag/definition.d.ts +5 -0
- package/data/These/instances.d.ts +0 -6
- package/data.d.ts +1 -0
- package/global.d.ts +0 -8
- package/json/EitherJson.d.ts +0 -6
- package/json/MaybeJson.d.ts +0 -6
- package/json/TheseJson.d.ts +0 -6
- package/package.json +2 -2
- package/_cjs/control/CompletablePromise.cjs +0 -21
- package/_cjs/control/CompletablePromise.cjs.map +0 -1
- package/_cjs/control/InterruptiblePromise.cjs +0 -23
- package/_cjs/control/InterruptiblePromise.cjs.map +0 -1
- package/_cjs/data/DecodeError/definition.cjs +0 -240
- package/_cjs/data/DecodeError/definition.cjs.map +0 -1
- package/_cjs/data/DecodeError/instances.cjs +0 -6
- package/_cjs/data/DecodeError/instances.cjs.map +0 -1
- package/_cjs/data/DecodeError.cjs +0 -28
- package/_cjs/data/DecodeError.cjs.map +0 -1
- package/_cjs/data/Decoder/api.cjs +0 -572
- package/_cjs/data/Decoder/api.cjs.map +0 -1
- package/_cjs/data/Decoder/definition.cjs +0 -30
- package/_cjs/data/Decoder/definition.cjs.map +0 -1
- package/_cjs/data/Decoder.cjs +0 -28
- package/_cjs/data/Decoder.cjs.map +0 -1
- package/_cjs/data/Encoder/api.cjs +0 -315
- package/_cjs/data/Encoder/api.cjs.map +0 -1
- package/_cjs/data/Encoder/definition.cjs +0 -22
- package/_cjs/data/Encoder/definition.cjs.map +0 -1
- package/_cjs/data/Encoder.cjs +0 -28
- package/_cjs/data/Encoder.cjs.map +0 -1
- package/_mjs/control/CompletablePromise.mjs +0 -15
- package/_mjs/control/CompletablePromise.mjs.map +0 -1
- package/_mjs/control/InterruptiblePromise.mjs +0 -15
- package/_mjs/control/InterruptiblePromise.mjs.map +0 -1
- package/_mjs/data/DecodeError/definition.mjs +0 -209
- package/_mjs/data/DecodeError/definition.mjs.map +0 -1
- package/_mjs/data/DecodeError/instances.mjs +0 -2
- package/_mjs/data/DecodeError/instances.mjs.map +0 -1
- package/_mjs/data/DecodeError.mjs +0 -5
- package/_mjs/data/DecodeError.mjs.map +0 -1
- package/_mjs/data/Decoder/api.mjs +0 -542
- package/_mjs/data/Decoder/api.mjs.map +0 -1
- package/_mjs/data/Decoder/definition.mjs +0 -22
- package/_mjs/data/Decoder/definition.mjs.map +0 -1
- package/_mjs/data/Decoder.mjs +0 -5
- package/_mjs/data/Decoder.mjs.map +0 -1
- package/_mjs/data/Encoder/api.mjs +0 -279
- package/_mjs/data/Encoder/api.mjs.map +0 -1
- package/_mjs/data/Encoder/definition.mjs +0 -15
- package/_mjs/data/Encoder/definition.mjs.map +0 -1
- package/_mjs/data/Encoder.mjs +0 -5
- package/_mjs/data/Encoder.mjs.map +0 -1
- package/_src/control/CompletablePromise.ts +0 -23
- package/_src/control/InterruptiblePromise.ts +0 -23
- package/_src/data/DecodeError/definition.ts +0 -267
- package/_src/data/DecodeError/instances.ts +0 -0
- package/_src/data/DecodeError.ts +0 -5
- package/_src/data/Decoder/api.ts +0 -696
- package/_src/data/Decoder/definition.ts +0 -31
- package/_src/data/Decoder.ts +0 -5
- package/_src/data/Encoder/api.ts +0 -381
- package/_src/data/Encoder/definition.ts +0 -16
- package/_src/data/Encoder.ts +0 -5
- package/control/CompletablePromise.d.ts +0 -13
- package/control/InterruptiblePromise.d.ts +0 -12
- package/data/DecodeError/definition.d.ts +0 -148
- package/data/DecodeError/instances.d.ts +0 -1
- package/data/DecodeError.d.ts +0 -2
- package/data/Decoder/api.d.ts +0 -214
- package/data/Decoder/definition.d.ts +0 -27
- package/data/Decoder.d.ts +0 -2
- package/data/Encoder/api.d.ts +0 -214
- package/data/Encoder/definition.d.ts +0 -16
- package/data/Encoder.d.ts +0 -2
@@ -1,31 +0,0 @@
|
|
1
|
-
import type { DecodeError } from "@fncts/base/data/DecodeError";
|
2
|
-
|
3
|
-
export const DecoderTypeId = Symbol.for("fncts.Decoder");
|
4
|
-
export type DecoderTypeId = typeof DecoderTypeId;
|
5
|
-
|
6
|
-
export interface DecoderF extends HKT {
|
7
|
-
type: Decoder<this["A"]>;
|
8
|
-
variance: {
|
9
|
-
A: "+";
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
/**
|
14
|
-
* @tsplus type fncts.Decoder
|
15
|
-
* @tsplus companion fncts.DecoderOps
|
16
|
-
* @tsplus derive nominal
|
17
|
-
*/
|
18
|
-
export class Decoder<in out A> {
|
19
|
-
readonly [DecoderTypeId]: DecoderTypeId = DecoderTypeId;
|
20
|
-
constructor(
|
21
|
-
readonly decode: (input: unknown) => These<DecodeError, A>,
|
22
|
-
readonly label: string,
|
23
|
-
) {}
|
24
|
-
}
|
25
|
-
|
26
|
-
/**
|
27
|
-
* @tsplus static fncts.DecoderOps __call
|
28
|
-
*/
|
29
|
-
export function makeDecoder<A>(decode: (input: unknown) => These<DecodeError, A>, label: string): Decoder<A> {
|
30
|
-
return new Decoder(decode, label);
|
31
|
-
}
|
package/_src/data/Decoder.ts
DELETED
package/_src/data/Encoder/api.ts
DELETED
@@ -1,381 +0,0 @@
|
|
1
|
-
import type { Brand, Validation } from "../Branded.js";
|
2
|
-
import type { Check } from "@fncts/typelevel";
|
3
|
-
import type { Literal } from "@fncts/typelevel/Any";
|
4
|
-
import type { OptionalKeys, RequiredKeys } from "@fncts/typelevel/Object";
|
5
|
-
|
6
|
-
import { Encoder } from "./definition.js";
|
7
|
-
|
8
|
-
/**
|
9
|
-
* @tsplus static fncts.EncoderOps __call
|
10
|
-
*/
|
11
|
-
export function makeEncoder<A>(encode: (inp: A) => unknown): Encoder<A> {
|
12
|
-
return new Encoder(encode);
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* @tsplus static fncts.EncoderOps unknown
|
17
|
-
*/
|
18
|
-
export const unknown: Encoder<unknown> = Encoder(Function.identity);
|
19
|
-
|
20
|
-
/**
|
21
|
-
* @tsplus implicit
|
22
|
-
* @tsplus static fncts.EncoderOps boolean
|
23
|
-
*/
|
24
|
-
export const boolean: Encoder<boolean> = Encoder(Function.identity);
|
25
|
-
|
26
|
-
/**
|
27
|
-
* @tsplus implicit
|
28
|
-
* @tsplus static fncts.EncoderOps number
|
29
|
-
*/
|
30
|
-
export const number: Encoder<number> = Encoder(Function.identity);
|
31
|
-
|
32
|
-
/**
|
33
|
-
* @tsplus implicit
|
34
|
-
* @tsplus static fncts.EncoderOps string
|
35
|
-
*/
|
36
|
-
export const string: Encoder<string> = Encoder(Function.identity);
|
37
|
-
|
38
|
-
/**
|
39
|
-
* @tsplus implicit
|
40
|
-
* @tsplus static fncts.EncoderOps bigint
|
41
|
-
*/
|
42
|
-
export const bigint: Encoder<bigint> = Encoder((n) => n.toString(10));
|
43
|
-
|
44
|
-
/**
|
45
|
-
* @tsplus implicit
|
46
|
-
* @tsplus static fncts.EncoderOps null
|
47
|
-
*/
|
48
|
-
export const _null: Encoder<null> = Encoder(Function.identity);
|
49
|
-
|
50
|
-
/**
|
51
|
-
* @tsplus implicit
|
52
|
-
* @tsplus static fncts.EncoderOps undefined
|
53
|
-
*/
|
54
|
-
export const _undefined: Encoder<undefined> = Encoder(Function.identity);
|
55
|
-
|
56
|
-
/**
|
57
|
-
* @tsplus implicit
|
58
|
-
* @tsplus static fncts.EncoderOps date
|
59
|
-
*/
|
60
|
-
export const date: Encoder<Date> = Encoder((d) => d.toISOString());
|
61
|
-
|
62
|
-
/**
|
63
|
-
* @tsplus derive fncts.Encoder lazy
|
64
|
-
* @tsplus static fncts.EncoderOps lazy
|
65
|
-
*/
|
66
|
-
export function deriveLazy<A>(fn: (_: Encoder<A>) => Encoder<A>): Encoder<A> {
|
67
|
-
let cached: Encoder<A> | undefined;
|
68
|
-
const encoder: Encoder<A> = Encoder((a) => {
|
69
|
-
if (!cached) {
|
70
|
-
cached = fn(encoder);
|
71
|
-
}
|
72
|
-
return cached.encode(a);
|
73
|
-
});
|
74
|
-
return encoder;
|
75
|
-
}
|
76
|
-
|
77
|
-
export function deriveLiteral<A extends string | number | boolean>(
|
78
|
-
...[value]: Check<Check.IsLiteral<A> & Check.Not<Check.IsUnion<A>>> extends Check.True ? [value: A] : never
|
79
|
-
): Encoder<A> {
|
80
|
-
return Encoder(Function.identity);
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* @tsplus static fncts.EncoderOps literal
|
85
|
-
*/
|
86
|
-
export function literal<A extends Literal>(value: A): Encoder<A> {
|
87
|
-
return Encoder(Function.identity);
|
88
|
-
}
|
89
|
-
|
90
|
-
/**
|
91
|
-
* @tsplus static fncts.EncoderOps nullable
|
92
|
-
*/
|
93
|
-
export function nullable<A>(/** @tsplus implicit local */ base: Encoder<A>): Encoder<A | null | undefined> {
|
94
|
-
return Encoder((inp) => (inp == null ? inp : base.encode(inp)));
|
95
|
-
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* @tsplus derive fncts.Encoder<_> 20
|
99
|
-
*/
|
100
|
-
export function deriveStruct<A extends Record<string, any>>(
|
101
|
-
...[requiredFields, optionalFields]: Check<Check.IsStruct<A>> extends Check.True
|
102
|
-
? [
|
103
|
-
...[
|
104
|
-
requiredFields: {
|
105
|
-
[K in RequiredKeys<A>]: Encoder<A[K]>;
|
106
|
-
},
|
107
|
-
],
|
108
|
-
...([OptionalKeys<A>] extends [never]
|
109
|
-
? []
|
110
|
-
: [
|
111
|
-
optionalFields: {
|
112
|
-
[K in OptionalKeys<A>]: Encoder<NonNullable<A[K]>>;
|
113
|
-
},
|
114
|
-
]),
|
115
|
-
]
|
116
|
-
: never
|
117
|
-
): Encoder<A> {
|
118
|
-
return Encoder((inp) => {
|
119
|
-
const encoded = {};
|
120
|
-
for (const field of Object.keys(requiredFields)) {
|
121
|
-
// @ts-expect-error
|
122
|
-
encoded[field] = (requiredFields[field] as Encoder<unknown>).encode(inp[field]);
|
123
|
-
}
|
124
|
-
if (optionalFields) {
|
125
|
-
for (const field of Object.keys(optionalFields)) {
|
126
|
-
if (field in inp && typeof inp[field] !== undefined) {
|
127
|
-
// @ts-expect-error
|
128
|
-
encoded[field] = (optionalFields[field] as Encoder<unknown>).encode(inp[field]);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}
|
132
|
-
return encoded;
|
133
|
-
});
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* @tsplus static fncts.EncoderOps struct
|
138
|
-
*/
|
139
|
-
export function struct<A extends Record<string, any>>(fields: {
|
140
|
-
[K in keyof A]: Encoder<A[K]>;
|
141
|
-
}): Encoder<A> {
|
142
|
-
return Encoder((inp) => {
|
143
|
-
const encoded = {};
|
144
|
-
for (const field of Object.keys(fields)) {
|
145
|
-
// @ts-expect-error
|
146
|
-
encoded[field] = fields[field]!.encode(inp[field]);
|
147
|
-
}
|
148
|
-
return encoded;
|
149
|
-
});
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
* @tsplus static fncts.EncoderOps partial
|
154
|
-
*/
|
155
|
-
export function partial<A extends Record<string, any>>(fields: {
|
156
|
-
[K in keyof A]: Encoder<A[K]>;
|
157
|
-
}): Encoder<Partial<A>> {
|
158
|
-
return Encoder((inp) => {
|
159
|
-
const encoded = {};
|
160
|
-
for (const field of Object.keys(fields)) {
|
161
|
-
if (field in inp && typeof inp[field] !== undefined) {
|
162
|
-
// @ts-expect-error
|
163
|
-
encoded[field] = fields[field]!.encode(inp[field]!);
|
164
|
-
}
|
165
|
-
}
|
166
|
-
return encoded;
|
167
|
-
});
|
168
|
-
}
|
169
|
-
|
170
|
-
/**
|
171
|
-
* @tsplus derive fncts.Encoder<|> 30
|
172
|
-
*/
|
173
|
-
export function deriveUnion<A extends Array<unknown>>(
|
174
|
-
...elements: {
|
175
|
-
[K in keyof A]: [Guard<A[K]>, Encoder<A[K]>];
|
176
|
-
}
|
177
|
-
): Encoder<A[number]> {
|
178
|
-
return Encoder((inp) => {
|
179
|
-
for (const [guard, encoder] of elements) {
|
180
|
-
if (guard.is(inp)) {
|
181
|
-
return encoder.encode(inp);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
});
|
185
|
-
}
|
186
|
-
|
187
|
-
/**
|
188
|
-
* @tsplus derive fncts.Encoder<_> 10
|
189
|
-
*/
|
190
|
-
export function deriveEmptyRecord<A extends {}>(
|
191
|
-
..._: Check<Check.IsEqual<A, {}>> extends Check.True ? [] : never
|
192
|
-
): Encoder<A> {
|
193
|
-
return Encoder(Function.identity);
|
194
|
-
}
|
195
|
-
|
196
|
-
/**
|
197
|
-
* @tsplus derive fncts.Encoder[fncts.Array]<_> 10
|
198
|
-
*/
|
199
|
-
export function deriveArray<A extends Array<any>>(
|
200
|
-
...[element]: [A] extends [Array<infer _A>]
|
201
|
-
? Check<Check.IsEqual<A, Array<_A>>> extends Check.True
|
202
|
-
? [element: Encoder<_A>]
|
203
|
-
: never
|
204
|
-
: never
|
205
|
-
): Encoder<A> {
|
206
|
-
return Encoder((inp) => inp.map((a) => element.encode(a)));
|
207
|
-
}
|
208
|
-
|
209
|
-
/**
|
210
|
-
* @tsplus static fncts.EncoderOps array
|
211
|
-
*/
|
212
|
-
export function array<A>(/** @tsplus implicit local */ base: Encoder<A>): Encoder<Array<A>> {
|
213
|
-
return Derive();
|
214
|
-
}
|
215
|
-
|
216
|
-
/**
|
217
|
-
* @tsplus derive fncts.Encoder[fncts.ReadonlyArray]<_> 10
|
218
|
-
*/
|
219
|
-
export function deriveReadonlyArray<A extends ReadonlyArray<any>>(
|
220
|
-
...[element]: [A] extends [ReadonlyArray<infer _A>]
|
221
|
-
? Check<Check.IsEqual<A, ReadonlyArray<_A>>> extends Check.True
|
222
|
-
? [element: Encoder<_A>]
|
223
|
-
: never
|
224
|
-
: never
|
225
|
-
): Encoder<A> {
|
226
|
-
return Encoder((inp) => inp.map((a) => element.encode(a)));
|
227
|
-
}
|
228
|
-
|
229
|
-
/**
|
230
|
-
* @tsplus static fncts.EncoderOps readonlyArray
|
231
|
-
*/
|
232
|
-
export function readonlyArray<A>(/** @tsplus implicit local */ base: Encoder<A>): Encoder<ReadonlyArray<A>> {
|
233
|
-
return Derive();
|
234
|
-
}
|
235
|
-
|
236
|
-
/**
|
237
|
-
* @tsplus derive fncts.Encoder<_> 15
|
238
|
-
*/
|
239
|
-
export function deriveDictionary<A extends Record<string, any>>(
|
240
|
-
...[value]: Check<Check.IsDictionary<A>> extends Check.True ? [value: Encoder<A[keyof A]>] : never
|
241
|
-
): Encoder<A> {
|
242
|
-
return Encoder((inp) => {
|
243
|
-
const encoded = {};
|
244
|
-
for (const k of Object.keys(inp)) {
|
245
|
-
// @ts-expect-error
|
246
|
-
encoded[k] = value.encode(inp[k]);
|
247
|
-
}
|
248
|
-
return encoded;
|
249
|
-
});
|
250
|
-
}
|
251
|
-
|
252
|
-
/**
|
253
|
-
* @tsplus derive fncts.Encoder<_> 15
|
254
|
-
*/
|
255
|
-
export function deriveRecord<A extends Record<string, any>>(
|
256
|
-
...[value, requiredKeys]: Check<Check.IsRecord<A>> extends Check.True
|
257
|
-
? [
|
258
|
-
value: Encoder<A[keyof A]>,
|
259
|
-
requiredKeys: {
|
260
|
-
[K in keyof A]: 0;
|
261
|
-
},
|
262
|
-
]
|
263
|
-
: never
|
264
|
-
): Encoder<A> {
|
265
|
-
return Encoder((inp) => {
|
266
|
-
const encoded = {};
|
267
|
-
for (const k of Object.keys(requiredKeys)) {
|
268
|
-
// @ts-expect-error
|
269
|
-
encoded[k] = value.encode(inp[k]);
|
270
|
-
}
|
271
|
-
return encoded;
|
272
|
-
});
|
273
|
-
}
|
274
|
-
|
275
|
-
/**
|
276
|
-
* @tsplus static fncts.EncoderOps record
|
277
|
-
*/
|
278
|
-
export function record<A>(codomain: Encoder<A>): Encoder<Record<string, A>> {
|
279
|
-
return Derive();
|
280
|
-
}
|
281
|
-
|
282
|
-
/**
|
283
|
-
* @tsplus derive fncts.Encoder[fncts.ImmutableArray]<_> 10
|
284
|
-
*/
|
285
|
-
export function deriveImmutableArray<A extends ImmutableArray<any>>(
|
286
|
-
...[element]: [A] extends [ImmutableArray<infer _A>]
|
287
|
-
? Check<Check.IsEqual<A, ImmutableArray<_A>>> extends Check.True
|
288
|
-
? [element: Encoder<_A>]
|
289
|
-
: never
|
290
|
-
: never
|
291
|
-
): Encoder<A> {
|
292
|
-
return Encoder((inp) => inp._array.map((a) => element.encode(a)));
|
293
|
-
}
|
294
|
-
|
295
|
-
/**
|
296
|
-
* @tsplus static fncts.EncoderOps immutableArray
|
297
|
-
*/
|
298
|
-
export function immutableArray<A>(base: Encoder<A>): Encoder<ImmutableArray<A>> {
|
299
|
-
return Derive();
|
300
|
-
}
|
301
|
-
|
302
|
-
/**
|
303
|
-
* @tsplus derive fncts.Encoder[fncts.ImmutableNonEmptyArray]<_> 10
|
304
|
-
*/
|
305
|
-
export function deriveImmutableNonEmptyArray<A extends ImmutableNonEmptyArray<any>>(
|
306
|
-
...[element]: [A] extends [ImmutableNonEmptyArray<infer _A>]
|
307
|
-
? Check<Check.IsEqual<A, ImmutableNonEmptyArray<_A>>> extends Check.True
|
308
|
-
? [element: Encoder<_A>]
|
309
|
-
: never
|
310
|
-
: never
|
311
|
-
): Encoder<A> {
|
312
|
-
return Encoder((inp) => inp._array.map((a) => element.encode(a)));
|
313
|
-
}
|
314
|
-
|
315
|
-
/**
|
316
|
-
* @tsplus static fncts.EncoderOps immutableNonEmptyArray
|
317
|
-
*/
|
318
|
-
export function immutableNonEmptyArray<A>(base: Encoder<A>): Encoder<ImmutableNonEmptyArray<A>> {
|
319
|
-
return Derive();
|
320
|
-
}
|
321
|
-
|
322
|
-
/**
|
323
|
-
* @tsplus derive fncts.Encoder[fncts.Conc]<_> 10
|
324
|
-
*/
|
325
|
-
export function deriveConc<A extends Conc<any>>(
|
326
|
-
...[element]: [A] extends [Conc<infer _A>]
|
327
|
-
? Check<Check.IsEqual<A, Conc<_A>>> extends Check.True
|
328
|
-
? [element: Encoder<_A>]
|
329
|
-
: never
|
330
|
-
: never
|
331
|
-
): Encoder<A> {
|
332
|
-
return Encoder((inp) => Array.from(inp).map((a) => element.encode(a)));
|
333
|
-
}
|
334
|
-
|
335
|
-
/**
|
336
|
-
* @tsplus static fncts.EncoderOps conc
|
337
|
-
*/
|
338
|
-
export function conc<A>(base: Encoder<A>): Encoder<Conc<A>> {
|
339
|
-
return Derive();
|
340
|
-
}
|
341
|
-
|
342
|
-
/**
|
343
|
-
* @tsplus derive fncts.Encoder<_> 10
|
344
|
-
*/
|
345
|
-
export function deriveValidation<A extends Brand.Valid<any, any>>(
|
346
|
-
...[base]: Check<Brand.IsValidated<A>> extends Check.True ? [base: Encoder<Brand.Unbranded<A>>] : never
|
347
|
-
): Encoder<A> {
|
348
|
-
return Encoder((inp) => base.encode(inp.unsafeCoerce()));
|
349
|
-
}
|
350
|
-
|
351
|
-
/**
|
352
|
-
* @tsplus static fncts.EncoderOps validation
|
353
|
-
*/
|
354
|
-
export function validation<A, B extends ReadonlyArray<Validation<A, any>>>(..._validations: B) {
|
355
|
-
return (
|
356
|
-
base: Encoder<A>,
|
357
|
-
): Encoder<A & { [K in keyof B]: B[K] extends Validation<any, infer S> ? Brand.Valid<A, S> : never }[number]> =>
|
358
|
-
Encoder(base.encode.unsafeCoerce());
|
359
|
-
}
|
360
|
-
|
361
|
-
/**
|
362
|
-
* @tsplus derive fncts.Encoder<_> 10
|
363
|
-
*/
|
364
|
-
export function deriveTuple<A extends ReadonlyArray<unknown>>(
|
365
|
-
...[components]: Check<Check.IsTuple<A>> extends Check.True ? [components: { [K in keyof A]: Encoder<A[K]> }] : never
|
366
|
-
): Encoder<A> {
|
367
|
-
return Encoder((inp) => {
|
368
|
-
const out = Array(inp.length);
|
369
|
-
for (let i = 0; i < inp.length; i++) {
|
370
|
-
out[i] = components[i]!.encode(inp[i]);
|
371
|
-
}
|
372
|
-
return out;
|
373
|
-
});
|
374
|
-
}
|
375
|
-
|
376
|
-
/**
|
377
|
-
* @tsplus static fncts.EncoderOps tuple
|
378
|
-
*/
|
379
|
-
export function tuple<A extends ReadonlyArray<unknown>>(...components: { [K in keyof A]: Encoder<A[K]> }): Encoder<A> {
|
380
|
-
return deriveTuple(components as [never]).unsafeCoerce();
|
381
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
export const EncoderTypeId = Symbol.for("fncts.Encoder");
|
2
|
-
export type EncoderTypeId = typeof EncoderTypeId;
|
3
|
-
|
4
|
-
/**
|
5
|
-
* @tsplus type fncts.Encoder
|
6
|
-
* @tsplus companion fncts.EncoderOps
|
7
|
-
* @tsplus derive nominal
|
8
|
-
*/
|
9
|
-
export class Encoder<in out A> {
|
10
|
-
readonly [EncoderTypeId]: EncoderTypeId = EncoderTypeId;
|
11
|
-
constructor(readonly encode: (inp: A) => unknown) {}
|
12
|
-
}
|
13
|
-
|
14
|
-
export interface EncoderF extends HKT {
|
15
|
-
readonly type: Encoder<this["A"]>;
|
16
|
-
}
|
package/_src/data/Encoder.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @tsplus type fncts.CompletablePromise
|
3
|
-
* @tsplus companion fncts.CompletablePromiseOps
|
4
|
-
*/
|
5
|
-
export interface CompletablePromise<A> extends Promise<A> {
|
6
|
-
resolve: (a: A) => void;
|
7
|
-
reject: (reason: unknown) => void;
|
8
|
-
}
|
9
|
-
/**
|
10
|
-
* @tsplus static fncts.CompletablePromiseOps __call
|
11
|
-
* @tsplus location "@fncts/base/control/CompletablePromise"
|
12
|
-
*/
|
13
|
-
export declare function make<A>(): CompletablePromise<A>;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @tsplus type fncts.InterruptiblePromise
|
3
|
-
* @tsplus companion fncts.InterruptiblePromiseOps
|
4
|
-
*/
|
5
|
-
export interface InterruptiblePromise<A> extends Promise<A> {
|
6
|
-
interrupt: () => void;
|
7
|
-
}
|
8
|
-
/**
|
9
|
-
* @tsplus static fncts.InterruptiblePromiseOps __call
|
10
|
-
* @tsplus location "@fncts/base/control/InterruptiblePromise"
|
11
|
-
*/
|
12
|
-
export declare function make<A>(executor: (resolve: (value: A | PromiseLike<A>) => void, reject: (reason?: unknown) => void) => (() => void) | void): InterruptiblePromise<A>;
|
@@ -1,148 +0,0 @@
|
|
1
|
-
import { Eval } from "@fncts/base/control/Eval/definition";
|
2
|
-
import { RoseTree } from "@fncts/base/collection/immutable/RoseTree";
|
3
|
-
import { Vector } from "@fncts/base/collection/immutable/Vector";
|
4
|
-
import type { Literal } from "@fncts/typelevel/Any";
|
5
|
-
export declare const DecodeErrorTypeId: unique symbol;
|
6
|
-
export type DecodeErrorTypeId = typeof DecodeErrorTypeId;
|
7
|
-
export declare abstract class DecodeError {
|
8
|
-
readonly [DecodeErrorTypeId]: DecodeErrorTypeId;
|
9
|
-
abstract render: Eval<RoseTree<string>>;
|
10
|
-
}
|
11
|
-
export declare class RequiredKeyError extends DecodeError {
|
12
|
-
readonly key: string;
|
13
|
-
readonly error: DecodeError;
|
14
|
-
readonly _tag = "RequiredKey";
|
15
|
-
constructor(key: string, error: DecodeError);
|
16
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
17
|
-
}
|
18
|
-
export declare class OptionalKeyError extends DecodeError {
|
19
|
-
readonly key: PropertyKey;
|
20
|
-
readonly error: DecodeError;
|
21
|
-
readonly _tag = "OptionalKey";
|
22
|
-
constructor(key: PropertyKey, error: DecodeError);
|
23
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
24
|
-
}
|
25
|
-
export declare class RequiredIndexError<I, E extends DecodeError> extends DecodeError {
|
26
|
-
readonly index: I;
|
27
|
-
readonly error: E;
|
28
|
-
readonly _tag = "RequiredIndex";
|
29
|
-
constructor(index: I, error: E);
|
30
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
31
|
-
}
|
32
|
-
export declare class OptionalIndexError<I, E extends DecodeError> extends DecodeError {
|
33
|
-
readonly index: I;
|
34
|
-
readonly error: E;
|
35
|
-
readonly _tag = "RequiredIndex";
|
36
|
-
constructor(index: I, error: E);
|
37
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
38
|
-
}
|
39
|
-
export declare class LazyError<E extends DecodeError> extends DecodeError {
|
40
|
-
readonly error: E;
|
41
|
-
readonly _tag = "Lazy";
|
42
|
-
constructor(error: E);
|
43
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
44
|
-
}
|
45
|
-
export declare class MemberError extends DecodeError {
|
46
|
-
readonly label: string;
|
47
|
-
readonly error: DecodeError;
|
48
|
-
readonly _tag = "Member";
|
49
|
-
constructor(label: string, error: DecodeError);
|
50
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
51
|
-
}
|
52
|
-
export declare class CompoundError<E extends DecodeError> extends DecodeError {
|
53
|
-
readonly name: string;
|
54
|
-
readonly errors: Vector<E>;
|
55
|
-
readonly _tag = "Compound";
|
56
|
-
constructor(name: string, errors: Vector<E>);
|
57
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
58
|
-
}
|
59
|
-
export declare class CompositionError<E extends DecodeError> extends DecodeError {
|
60
|
-
readonly errors: Vector<E>;
|
61
|
-
readonly _tag = "Composition";
|
62
|
-
constructor(errors: Vector<E>);
|
63
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
64
|
-
}
|
65
|
-
export declare class StringError extends DecodeError {
|
66
|
-
readonly actual: unknown;
|
67
|
-
readonly _tag = "String";
|
68
|
-
constructor(actual: unknown);
|
69
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
70
|
-
}
|
71
|
-
export declare class NumberError extends DecodeError {
|
72
|
-
readonly actual: unknown;
|
73
|
-
readonly _tag = "Number";
|
74
|
-
constructor(actual: unknown);
|
75
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
76
|
-
}
|
77
|
-
export declare class NaNError extends DecodeError {
|
78
|
-
readonly _tag = "NaN";
|
79
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
80
|
-
}
|
81
|
-
export declare class InfinityError extends DecodeError {
|
82
|
-
readonly _tag = "Infinity";
|
83
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
84
|
-
}
|
85
|
-
export declare class BooleanError extends DecodeError {
|
86
|
-
readonly actual: unknown;
|
87
|
-
readonly _tag = "Boolean";
|
88
|
-
constructor(actual: unknown);
|
89
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
90
|
-
}
|
91
|
-
export declare class PrimitiveError extends DecodeError {
|
92
|
-
readonly actual: unknown;
|
93
|
-
readonly name: string;
|
94
|
-
readonly _tag = "Primitive";
|
95
|
-
constructor(actual: unknown, name: string);
|
96
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
97
|
-
}
|
98
|
-
export declare class LiteralError<A extends Literal> extends DecodeError {
|
99
|
-
readonly actual: unknown;
|
100
|
-
readonly literals: Vector<A>;
|
101
|
-
readonly _tag = "Literal";
|
102
|
-
constructor(actual: unknown, literals: Vector<A>);
|
103
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
104
|
-
}
|
105
|
-
export declare class UnexpectedKeysError extends DecodeError {
|
106
|
-
readonly keys: Vector<string>;
|
107
|
-
readonly _tag = "UnexpectedKeys";
|
108
|
-
constructor(keys: Vector<string>);
|
109
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
110
|
-
}
|
111
|
-
export declare class UnexpectedIndicesError extends DecodeError {
|
112
|
-
readonly indices: Vector<number>;
|
113
|
-
readonly _tag = "UnexpectedIndices";
|
114
|
-
constructor(indices: Vector<number>);
|
115
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
116
|
-
}
|
117
|
-
export declare class MissingKeyError extends DecodeError {
|
118
|
-
readonly key: PropertyKey;
|
119
|
-
readonly _tag = "MissingKeys";
|
120
|
-
constructor(key: PropertyKey);
|
121
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
122
|
-
}
|
123
|
-
export declare class MissingIndicesError extends DecodeError {
|
124
|
-
readonly keys: Vector<PropertyKey>;
|
125
|
-
readonly _tag = "MissingIndices";
|
126
|
-
constructor(keys: Vector<PropertyKey>);
|
127
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
128
|
-
}
|
129
|
-
export declare class BrandedError extends DecodeError {
|
130
|
-
readonly name: string;
|
131
|
-
readonly brands: Vector<string>;
|
132
|
-
readonly _tag = "BrandedError";
|
133
|
-
constructor(name: string, brands: Vector<string>);
|
134
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
135
|
-
}
|
136
|
-
export declare class UnionError extends DecodeError {
|
137
|
-
readonly label: string;
|
138
|
-
readonly errors: Vector<DecodeError>;
|
139
|
-
readonly _tag = "UnionError";
|
140
|
-
constructor(label: string, errors: Vector<DecodeError>);
|
141
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
142
|
-
}
|
143
|
-
export declare class EmptyError extends DecodeError {
|
144
|
-
readonly actual: unknown;
|
145
|
-
readonly _tag = "EmptyError";
|
146
|
-
constructor(actual: unknown);
|
147
|
-
render: import("../../control/Eval").Eval<import("../../collection/immutable/RoseTree").RoseTree<string>>;
|
148
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/data/DecodeError.d.ts
DELETED