@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,279 +0,0 @@
|
|
1
|
-
import * as tsplus_module_1 from "@fncts/base/data/function/api";
|
2
|
-
export const makeEncoder = makeEncoder_1;
|
3
|
-
export const deriveArray = deriveArray_1;
|
4
|
-
export const deriveReadonlyArray = deriveReadonlyArray_1;
|
5
|
-
export const deriveDictionary = deriveDictionary_1;
|
6
|
-
export const deriveImmutableArray = deriveImmutableArray_1;
|
7
|
-
export const deriveImmutableNonEmptyArray = deriveImmutableNonEmptyArray_1;
|
8
|
-
export const deriveConc = deriveConc_1;
|
9
|
-
import { Encoder } from "./definition.mjs";
|
10
|
-
/**
|
11
|
-
* @tsplus static fncts.EncoderOps __call
|
12
|
-
*/
|
13
|
-
function makeEncoder_1(encode) {
|
14
|
-
return new Encoder(encode);
|
15
|
-
}
|
16
|
-
/**
|
17
|
-
* @tsplus static fncts.EncoderOps unknown
|
18
|
-
*/
|
19
|
-
export const unknown = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
20
|
-
/**
|
21
|
-
* @tsplus implicit
|
22
|
-
* @tsplus static fncts.EncoderOps boolean
|
23
|
-
*/
|
24
|
-
export const boolean = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
25
|
-
/**
|
26
|
-
* @tsplus implicit
|
27
|
-
* @tsplus static fncts.EncoderOps number
|
28
|
-
*/
|
29
|
-
export const number = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
30
|
-
/**
|
31
|
-
* @tsplus implicit
|
32
|
-
* @tsplus static fncts.EncoderOps string
|
33
|
-
*/
|
34
|
-
export const string = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
35
|
-
/**
|
36
|
-
* @tsplus implicit
|
37
|
-
* @tsplus static fncts.EncoderOps bigint
|
38
|
-
*/
|
39
|
-
export const bigint = /*#__PURE__*/makeEncoder_1(n => n.toString(10));
|
40
|
-
/**
|
41
|
-
* @tsplus implicit
|
42
|
-
* @tsplus static fncts.EncoderOps null
|
43
|
-
*/
|
44
|
-
export const _null = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
45
|
-
/**
|
46
|
-
* @tsplus implicit
|
47
|
-
* @tsplus static fncts.EncoderOps undefined
|
48
|
-
*/
|
49
|
-
export const _undefined = /*#__PURE__*/makeEncoder_1(tsplus_module_1.identity);
|
50
|
-
/**
|
51
|
-
* @tsplus implicit
|
52
|
-
* @tsplus static fncts.EncoderOps date
|
53
|
-
*/
|
54
|
-
export const date = /*#__PURE__*/makeEncoder_1(d => d.toISOString());
|
55
|
-
/**
|
56
|
-
* @tsplus derive fncts.Encoder lazy
|
57
|
-
* @tsplus static fncts.EncoderOps lazy
|
58
|
-
*/
|
59
|
-
export function deriveLazy(fn) {
|
60
|
-
let cached;
|
61
|
-
const encoder = makeEncoder_1(a => {
|
62
|
-
if (!cached) {
|
63
|
-
cached = fn(encoder);
|
64
|
-
}
|
65
|
-
return cached.encode(a);
|
66
|
-
});
|
67
|
-
return encoder;
|
68
|
-
}
|
69
|
-
export function deriveLiteral(...[value]) {
|
70
|
-
return makeEncoder_1(tsplus_module_1.identity);
|
71
|
-
}
|
72
|
-
/**
|
73
|
-
* @tsplus static fncts.EncoderOps literal
|
74
|
-
*/
|
75
|
-
export function literal(value) {
|
76
|
-
return makeEncoder_1(tsplus_module_1.identity);
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* @tsplus static fncts.EncoderOps nullable
|
80
|
-
*/
|
81
|
-
export function nullable( /** @tsplus implicit local */base) {
|
82
|
-
return makeEncoder_1(inp => inp == null ? inp : base.encode(inp));
|
83
|
-
}
|
84
|
-
/**
|
85
|
-
* @tsplus derive fncts.Encoder<_> 20
|
86
|
-
*/
|
87
|
-
export function deriveStruct(...[requiredFields, optionalFields]) {
|
88
|
-
return makeEncoder_1(inp => {
|
89
|
-
const encoded = {};
|
90
|
-
for (const field of Object.keys(requiredFields)) {
|
91
|
-
// @ts-expect-error
|
92
|
-
encoded[field] = requiredFields[field].encode(inp[field]);
|
93
|
-
}
|
94
|
-
if (optionalFields) {
|
95
|
-
for (const field of Object.keys(optionalFields)) {
|
96
|
-
if (field in inp && typeof inp[field] !== undefined) {
|
97
|
-
// @ts-expect-error
|
98
|
-
encoded[field] = optionalFields[field].encode(inp[field]);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
return encoded;
|
103
|
-
});
|
104
|
-
}
|
105
|
-
/**
|
106
|
-
* @tsplus static fncts.EncoderOps struct
|
107
|
-
*/
|
108
|
-
export function struct(fields) {
|
109
|
-
return makeEncoder_1(inp => {
|
110
|
-
const encoded = {};
|
111
|
-
for (const field of Object.keys(fields)) {
|
112
|
-
// @ts-expect-error
|
113
|
-
encoded[field] = fields[field].encode(inp[field]);
|
114
|
-
}
|
115
|
-
return encoded;
|
116
|
-
});
|
117
|
-
}
|
118
|
-
/**
|
119
|
-
* @tsplus static fncts.EncoderOps partial
|
120
|
-
*/
|
121
|
-
export function partial(fields) {
|
122
|
-
return makeEncoder_1(inp => {
|
123
|
-
const encoded = {};
|
124
|
-
for (const field of Object.keys(fields)) {
|
125
|
-
if (field in inp && typeof inp[field] !== undefined) {
|
126
|
-
// @ts-expect-error
|
127
|
-
encoded[field] = fields[field].encode(inp[field]);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
return encoded;
|
131
|
-
});
|
132
|
-
}
|
133
|
-
/**
|
134
|
-
* @tsplus derive fncts.Encoder<|> 30
|
135
|
-
*/
|
136
|
-
export function deriveUnion(...elements) {
|
137
|
-
return makeEncoder_1(inp => {
|
138
|
-
for (const [guard, encoder] of elements) {
|
139
|
-
if (guard.is(inp)) {
|
140
|
-
return encoder.encode(inp);
|
141
|
-
}
|
142
|
-
}
|
143
|
-
});
|
144
|
-
}
|
145
|
-
/**
|
146
|
-
* @tsplus derive fncts.Encoder<_> 10
|
147
|
-
*/
|
148
|
-
export function deriveEmptyRecord(..._) {
|
149
|
-
return makeEncoder_1(tsplus_module_1.identity);
|
150
|
-
}
|
151
|
-
/**
|
152
|
-
* @tsplus derive fncts.Encoder[fncts.Array]<_> 10
|
153
|
-
*/
|
154
|
-
function deriveArray_1(...[element]) {
|
155
|
-
return makeEncoder_1(inp => inp.map(a => element.encode(a)));
|
156
|
-
}
|
157
|
-
/**
|
158
|
-
* @tsplus static fncts.EncoderOps array
|
159
|
-
*/
|
160
|
-
export function array( /** @tsplus implicit local */base) {
|
161
|
-
const base_1 = base;
|
162
|
-
return deriveArray_1(base_1);
|
163
|
-
}
|
164
|
-
/**
|
165
|
-
* @tsplus derive fncts.Encoder[fncts.ReadonlyArray]<_> 10
|
166
|
-
*/
|
167
|
-
function deriveReadonlyArray_1(...[element]) {
|
168
|
-
return makeEncoder_1(inp => inp.map(a => element.encode(a)));
|
169
|
-
}
|
170
|
-
/**
|
171
|
-
* @tsplus static fncts.EncoderOps readonlyArray
|
172
|
-
*/
|
173
|
-
export function readonlyArray( /** @tsplus implicit local */base) {
|
174
|
-
const base_2 = base;
|
175
|
-
return deriveReadonlyArray_1(base_2);
|
176
|
-
}
|
177
|
-
/**
|
178
|
-
* @tsplus derive fncts.Encoder<_> 15
|
179
|
-
*/
|
180
|
-
function deriveDictionary_1(...[value]) {
|
181
|
-
return makeEncoder_1(inp => {
|
182
|
-
const encoded = {};
|
183
|
-
for (const k of Object.keys(inp)) {
|
184
|
-
// @ts-expect-error
|
185
|
-
encoded[k] = value.encode(inp[k]);
|
186
|
-
}
|
187
|
-
return encoded;
|
188
|
-
});
|
189
|
-
}
|
190
|
-
/**
|
191
|
-
* @tsplus derive fncts.Encoder<_> 15
|
192
|
-
*/
|
193
|
-
export function deriveRecord(...[value, requiredKeys]) {
|
194
|
-
return makeEncoder_1(inp => {
|
195
|
-
const encoded = {};
|
196
|
-
for (const k of Object.keys(requiredKeys)) {
|
197
|
-
// @ts-expect-error
|
198
|
-
encoded[k] = value.encode(inp[k]);
|
199
|
-
}
|
200
|
-
return encoded;
|
201
|
-
});
|
202
|
-
}
|
203
|
-
/**
|
204
|
-
* @tsplus static fncts.EncoderOps record
|
205
|
-
*/
|
206
|
-
export function record(codomain) {
|
207
|
-
const codomain_1 = codomain;
|
208
|
-
return deriveDictionary_1(codomain_1);
|
209
|
-
}
|
210
|
-
/**
|
211
|
-
* @tsplus derive fncts.Encoder[fncts.ImmutableArray]<_> 10
|
212
|
-
*/
|
213
|
-
function deriveImmutableArray_1(...[element]) {
|
214
|
-
return makeEncoder_1(inp => inp._array.map(a => element.encode(a)));
|
215
|
-
}
|
216
|
-
/**
|
217
|
-
* @tsplus static fncts.EncoderOps immutableArray
|
218
|
-
*/
|
219
|
-
export function immutableArray(base) {
|
220
|
-
const base_3 = base;
|
221
|
-
return deriveImmutableArray_1(base_3);
|
222
|
-
}
|
223
|
-
/**
|
224
|
-
* @tsplus derive fncts.Encoder[fncts.ImmutableNonEmptyArray]<_> 10
|
225
|
-
*/
|
226
|
-
function deriveImmutableNonEmptyArray_1(...[element]) {
|
227
|
-
return makeEncoder_1(inp => inp._array.map(a => element.encode(a)));
|
228
|
-
}
|
229
|
-
/**
|
230
|
-
* @tsplus static fncts.EncoderOps immutableNonEmptyArray
|
231
|
-
*/
|
232
|
-
export function immutableNonEmptyArray(base) {
|
233
|
-
const base_4 = base;
|
234
|
-
return deriveImmutableNonEmptyArray_1(base_4);
|
235
|
-
}
|
236
|
-
/**
|
237
|
-
* @tsplus derive fncts.Encoder[fncts.Conc]<_> 10
|
238
|
-
*/
|
239
|
-
function deriveConc_1(...[element]) {
|
240
|
-
return makeEncoder_1(inp => Array.from(inp).map(a => element.encode(a)));
|
241
|
-
}
|
242
|
-
/**
|
243
|
-
* @tsplus static fncts.EncoderOps conc
|
244
|
-
*/
|
245
|
-
export function conc(base) {
|
246
|
-
const base_5 = base;
|
247
|
-
return deriveConc_1(base_5);
|
248
|
-
}
|
249
|
-
/**
|
250
|
-
* @tsplus derive fncts.Encoder<_> 10
|
251
|
-
*/
|
252
|
-
export function deriveValidation(...[base]) {
|
253
|
-
return makeEncoder_1(inp => base.encode(inp.unsafeCoerce()));
|
254
|
-
}
|
255
|
-
/**
|
256
|
-
* @tsplus static fncts.EncoderOps validation
|
257
|
-
*/
|
258
|
-
export function validation(..._validations) {
|
259
|
-
return base => makeEncoder_1(base.encode.unsafeCoerce());
|
260
|
-
}
|
261
|
-
/**
|
262
|
-
* @tsplus derive fncts.Encoder<_> 10
|
263
|
-
*/
|
264
|
-
export function deriveTuple(...[components]) {
|
265
|
-
return makeEncoder_1(inp => {
|
266
|
-
const out = Array(inp.length);
|
267
|
-
for (let i = 0; i < inp.length; i++) {
|
268
|
-
out[i] = components[i].encode(inp[i]);
|
269
|
-
}
|
270
|
-
return out;
|
271
|
-
});
|
272
|
-
}
|
273
|
-
/**
|
274
|
-
* @tsplus static fncts.EncoderOps tuple
|
275
|
-
*/
|
276
|
-
export function tuple(...components) {
|
277
|
-
return deriveTuple(components).unsafeCoerce();
|
278
|
-
}
|
279
|
-
//# sourceMappingURL=api.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"api.mjs","names":["makeEncoder","makeEncoder_1","deriveArray","deriveArray_1","deriveReadonlyArray","deriveReadonlyArray_1","deriveDictionary","deriveDictionary_1","deriveImmutableArray","deriveImmutableArray_1","deriveImmutableNonEmptyArray","deriveImmutableNonEmptyArray_1","deriveConc","deriveConc_1","Encoder","encode","unknown","tsplus_module_1","identity","boolean","number","string","bigint","n","toString","_null","_undefined","date","d","toISOString","deriveLazy","fn","cached","encoder","a","deriveLiteral","value","literal","nullable","base","inp","deriveStruct","requiredFields","optionalFields","encoded","field","Object","keys","undefined","struct","fields","partial","deriveUnion","elements","guard","is","deriveEmptyRecord","_","element","map","array","base_1","readonlyArray","base_2","k","deriveRecord","requiredKeys","record","codomain","codomain_1","_array","immutableArray","base_3","immutableNonEmptyArray","base_4","Array","from","conc","base_5","deriveValidation","unsafeCoerce","validation","_validations","deriveTuple","components","out","length","i","tuple"],"sources":["../../../_src/data/Encoder/api.ts"],"sourcesContent":[null],"mappings":";aAUgBA,WAAW,GAAAC,aAAA;aA4LXC,WAAW,GAAAC,aAAA;aAoBXC,mBAAmB,GAAAC,qBAAA;aAoBnBC,gBAAgB,GAAAC,kBAAA;aA8ChBC,oBAAoB,GAAAC,sBAAA;aAoBpBC,4BAA4B,GAAAC,8BAAA;aAoB5BC,UAAU,GAAAC,YAAA;AA/T1B,SAASC,OAAO,QAAQ,kBAAiB;AAEzC;;;AAGA,SAAAb,cAA+Bc,MAA2B;EACxD,OAAO,IAAID,OAAO,CAACC,MAAM,CAAC;AAC5B;AAEA;;;AAGA,OAAO,MAAMC,OAAO,gBAAqBf,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAEnE;;;;AAIA,OAAO,MAAMC,OAAO,gBAAqBlB,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAEnE;;;;AAIA,OAAO,MAAME,MAAM,gBAAoBnB,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAEjE;;;;AAIA,OAAO,MAAMG,MAAM,gBAAoBpB,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAEjE;;;;AAIA,OAAO,MAAMI,MAAM,gBAAoBrB,aAAA,CAASsB,CAAC,IAAKA,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAErE;;;;AAIA,OAAO,MAAMC,KAAK,gBAAkBxB,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAE9D;;;;AAIA,OAAO,MAAMQ,UAAU,gBAAuBzB,aAAA,CAAAgB,eAAA,CAAAC,QAAA,CAA0B;AAExE;;;;AAIA,OAAO,MAAMS,IAAI,gBAAkB1B,aAAA,CAAS2B,CAAC,IAAKA,CAAC,CAACC,WAAW,EAAE,CAAC;AAElE;;;;AAIA,OAA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ncts.EncoderOps
|
6
|
-
* @tsplus derive nominal
|
7
|
-
*/
|
8
|
-
export class Encoder {
|
9
|
-
constructor(encode) {
|
10
|
-
this.encode = encode;
|
11
|
-
this[_a] = EncoderTypeId;
|
12
|
-
}
|
13
|
-
}
|
14
|
-
_a = EncoderTypeId;
|
15
|
-
//# sourceMappingURL=definition.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"definition.mjs","names":["EncoderTypeId","Symbol","for","Encoder","constructor","encode","_a"],"sources":["../../../_src/data/Encoder/definition.ts"],"sourcesContent":[null],"mappings":";AAAA,OAAO,MAAMA,aAAa,gBAAGC,MAAM,CAACC,GAAG,CAAC,eAAe,CAAC;AAGxD;;;;;AAKA,OAAM,MAAOC,OAAO;EAElBC,YAAqBC,MAA2B;IAA3B,KAAAA,MAAM,GAANA,MAAM;IADlB,KAAAC,EAAA,CAAe,GAAkBN,aAAa;EACJ;;KADzCA,aAAa"}
|
package/_mjs/data/Encoder.mjs
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Encoder.mjs","names":[],"sources":["../../_src/data/Encoder.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA;AACA,cAAc,0BAAyB;AACvC,cAAc,mBAAkB"}
|
@@ -1,23 +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
|
-
/**
|
11
|
-
* @tsplus static fncts.CompletablePromiseOps __call
|
12
|
-
*/
|
13
|
-
export function make<A>(): CompletablePromise<A> {
|
14
|
-
let outerResolve: (a: A) => void = () => {};
|
15
|
-
let outerReject: (reason: unknown) => void = () => {};
|
16
|
-
const promise: CompletablePromise<A> = new Promise((resolve, reject) => {
|
17
|
-
outerResolve = resolve;
|
18
|
-
outerReject = reject;
|
19
|
-
}) as any;
|
20
|
-
promise.resolve = outerResolve;
|
21
|
-
promise.reject = outerReject;
|
22
|
-
return promise;
|
23
|
-
}
|
@@ -1,23 +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
|
-
/**
|
10
|
-
* @tsplus static fncts.InterruptiblePromiseOps __call
|
11
|
-
*/
|
12
|
-
export function make<A>(
|
13
|
-
executor: (resolve: (value: A | PromiseLike<A>) => void, reject: (reason?: unknown) => void) => (() => void) | void,
|
14
|
-
): InterruptiblePromise<A> {
|
15
|
-
const promise: InterruptiblePromise<A> = new Promise((resolve, reject) => {
|
16
|
-
const canceller = executor(resolve, reject);
|
17
|
-
promise.interrupt = () => {
|
18
|
-
canceller?.();
|
19
|
-
reject(new InterruptedException());
|
20
|
-
};
|
21
|
-
}) as InterruptiblePromise<A>;
|
22
|
-
return promise;
|
23
|
-
}
|
@@ -1,267 +0,0 @@
|
|
1
|
-
import type { Literal } from "@fncts/typelevel/Any";
|
2
|
-
|
3
|
-
import { show } from "@fncts/base/data/Showable";
|
4
|
-
|
5
|
-
export const DecodeErrorTypeId = Symbol.for("fncts.DecodeError");
|
6
|
-
export type DecodeErrorTypeId = typeof DecodeErrorTypeId;
|
7
|
-
|
8
|
-
export abstract class DecodeError {
|
9
|
-
readonly [DecodeErrorTypeId]: DecodeErrorTypeId = DecodeErrorTypeId;
|
10
|
-
abstract render: Eval<RoseTree<string>>;
|
11
|
-
}
|
12
|
-
|
13
|
-
export class RequiredKeyError extends DecodeError {
|
14
|
-
readonly _tag = "RequiredKey";
|
15
|
-
constructor(
|
16
|
-
readonly key: string,
|
17
|
-
readonly error: DecodeError,
|
18
|
-
) {
|
19
|
-
super();
|
20
|
-
}
|
21
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree(`on required key ${this.key}`, Vector(error))));
|
22
|
-
}
|
23
|
-
|
24
|
-
export class OptionalKeyError extends DecodeError {
|
25
|
-
readonly _tag = "OptionalKey";
|
26
|
-
constructor(
|
27
|
-
readonly key: PropertyKey,
|
28
|
-
readonly error: DecodeError,
|
29
|
-
) {
|
30
|
-
super();
|
31
|
-
}
|
32
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree(`on optional key ${show(this.key)}`, Vector(error))));
|
33
|
-
}
|
34
|
-
|
35
|
-
export class RequiredIndexError<I, E extends DecodeError> extends DecodeError {
|
36
|
-
readonly _tag = "RequiredIndex";
|
37
|
-
constructor(
|
38
|
-
readonly index: I,
|
39
|
-
readonly error: E,
|
40
|
-
) {
|
41
|
-
super();
|
42
|
-
}
|
43
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree(`on required index ${this.index}`, Vector(error))));
|
44
|
-
}
|
45
|
-
|
46
|
-
export class OptionalIndexError<I, E extends DecodeError> extends DecodeError {
|
47
|
-
readonly _tag = "RequiredIndex";
|
48
|
-
constructor(
|
49
|
-
readonly index: I,
|
50
|
-
readonly error: E,
|
51
|
-
) {
|
52
|
-
super();
|
53
|
-
}
|
54
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree(`on optional index ${this.index}`, Vector(error))));
|
55
|
-
}
|
56
|
-
|
57
|
-
export class LazyError<E extends DecodeError> extends DecodeError {
|
58
|
-
readonly _tag = "Lazy";
|
59
|
-
constructor(readonly error: E) {
|
60
|
-
super();
|
61
|
-
}
|
62
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree("while decoding a lazy decoder", Vector(error))));
|
63
|
-
}
|
64
|
-
|
65
|
-
export class MemberError extends DecodeError {
|
66
|
-
readonly _tag = "Member";
|
67
|
-
constructor(
|
68
|
-
readonly label: string,
|
69
|
-
readonly error: DecodeError,
|
70
|
-
) {
|
71
|
-
super();
|
72
|
-
}
|
73
|
-
render = Eval.defer(this.error.render.map((error) => RoseTree(`on member ${this.label}`, Vector(error))));
|
74
|
-
}
|
75
|
-
|
76
|
-
const vowels = ["a", "e", "i", "o", "u", "y"];
|
77
|
-
|
78
|
-
function startsWithVowel(s: string): boolean {
|
79
|
-
for (let i = 0; i < vowels.length; i++) {
|
80
|
-
if (s.startsWith(vowels[i]!)) return true;
|
81
|
-
}
|
82
|
-
return false;
|
83
|
-
}
|
84
|
-
|
85
|
-
export class CompoundError<E extends DecodeError> extends DecodeError {
|
86
|
-
readonly _tag = "Compound";
|
87
|
-
constructor(
|
88
|
-
readonly name: string,
|
89
|
-
readonly errors: Vector<E>,
|
90
|
-
) {
|
91
|
-
super();
|
92
|
-
}
|
93
|
-
render = Eval.defer(
|
94
|
-
this.errors
|
95
|
-
.traverse(Eval.Applicative)((error) => error.render)
|
96
|
-
.map((errors) =>
|
97
|
-
RoseTree(
|
98
|
-
`${this.errors.length} error(s) found while decoding ${startsWithVowel(this.name) ? "an" : "a"} ${this.name}`,
|
99
|
-
errors,
|
100
|
-
),
|
101
|
-
),
|
102
|
-
);
|
103
|
-
}
|
104
|
-
|
105
|
-
export class CompositionError<E extends DecodeError> extends DecodeError {
|
106
|
-
readonly _tag = "Composition";
|
107
|
-
constructor(readonly errors: Vector<E>) {
|
108
|
-
super();
|
109
|
-
}
|
110
|
-
render = Eval.defer(
|
111
|
-
this.errors
|
112
|
-
.traverse(Eval.Applicative)((error) => error.render)
|
113
|
-
.map((errors) =>
|
114
|
-
errors.length === 1
|
115
|
-
? errors.unsafeGet(1)!
|
116
|
-
: RoseTree(`${errors.length} errors found while decoding a composition`, errors),
|
117
|
-
),
|
118
|
-
);
|
119
|
-
}
|
120
|
-
|
121
|
-
export class StringError extends DecodeError {
|
122
|
-
readonly _tag = "String";
|
123
|
-
constructor(readonly actual: unknown) {
|
124
|
-
super();
|
125
|
-
}
|
126
|
-
render = Eval(RoseTree(cannotDecode(this.actual, "a string")));
|
127
|
-
}
|
128
|
-
|
129
|
-
export class NumberError extends DecodeError {
|
130
|
-
readonly _tag = "Number";
|
131
|
-
constructor(readonly actual: unknown) {
|
132
|
-
super();
|
133
|
-
}
|
134
|
-
render = Eval(RoseTree(cannotDecode(this.actual, "a number")));
|
135
|
-
}
|
136
|
-
|
137
|
-
export class NaNError extends DecodeError {
|
138
|
-
readonly _tag = "NaN";
|
139
|
-
render = Eval.now(RoseTree("value is NaN"));
|
140
|
-
}
|
141
|
-
|
142
|
-
export class InfinityError extends DecodeError {
|
143
|
-
readonly _tag = "Infinity";
|
144
|
-
render = Eval(RoseTree("value is Infinity"));
|
145
|
-
}
|
146
|
-
|
147
|
-
export class BooleanError extends DecodeError {
|
148
|
-
readonly _tag = "Boolean";
|
149
|
-
constructor(readonly actual: unknown) {
|
150
|
-
super();
|
151
|
-
}
|
152
|
-
render = Eval(RoseTree(cannotDecode(this.actual, "a boolean")));
|
153
|
-
}
|
154
|
-
|
155
|
-
export class PrimitiveError extends DecodeError {
|
156
|
-
readonly _tag = "Primitive";
|
157
|
-
constructor(
|
158
|
-
readonly actual: unknown,
|
159
|
-
readonly name: string,
|
160
|
-
) {
|
161
|
-
super();
|
162
|
-
}
|
163
|
-
render = Eval(RoseTree(cannotDecode(this.actual, this.name)));
|
164
|
-
}
|
165
|
-
|
166
|
-
export class LiteralError<A extends Literal> extends DecodeError {
|
167
|
-
readonly _tag = "Literal";
|
168
|
-
constructor(
|
169
|
-
readonly actual: unknown,
|
170
|
-
readonly literals: Vector<A>,
|
171
|
-
) {
|
172
|
-
super();
|
173
|
-
}
|
174
|
-
render = Eval(
|
175
|
-
RoseTree(cannotDecode(this.actual, `one of ${this.literals.map((literal) => show(literal)).join(", ")}`)),
|
176
|
-
);
|
177
|
-
}
|
178
|
-
|
179
|
-
export class UnexpectedKeysError extends DecodeError {
|
180
|
-
readonly _tag = "UnexpectedKeys";
|
181
|
-
constructor(readonly keys: Vector<string>) {
|
182
|
-
super();
|
183
|
-
}
|
184
|
-
render = Eval(
|
185
|
-
RoseTree(
|
186
|
-
`${this.keys.length} error(s) found while checking keys`,
|
187
|
-
this.keys.map((key) => RoseTree(`unexpected key ${show(key)}`)),
|
188
|
-
),
|
189
|
-
);
|
190
|
-
}
|
191
|
-
|
192
|
-
export class UnexpectedIndicesError extends DecodeError {
|
193
|
-
readonly _tag = "UnexpectedIndices";
|
194
|
-
constructor(readonly indices: Vector<number>) {
|
195
|
-
super();
|
196
|
-
}
|
197
|
-
render = Eval(
|
198
|
-
RoseTree(
|
199
|
-
`${this.indices.length} error(s) found while checking indices`,
|
200
|
-
this.indices.map((index) => RoseTree(`unexpected index ${show(index)}`)),
|
201
|
-
),
|
202
|
-
);
|
203
|
-
}
|
204
|
-
|
205
|
-
export class MissingKeyError extends DecodeError {
|
206
|
-
readonly _tag = "MissingKeys";
|
207
|
-
constructor(readonly key: PropertyKey) {
|
208
|
-
super();
|
209
|
-
}
|
210
|
-
render = Eval(RoseTree(`missing required key ${show(this.key)}`));
|
211
|
-
}
|
212
|
-
|
213
|
-
export class MissingIndicesError extends DecodeError {
|
214
|
-
readonly _tag = "MissingIndices";
|
215
|
-
constructor(readonly keys: Vector<PropertyKey>) {
|
216
|
-
super();
|
217
|
-
}
|
218
|
-
render = Eval(
|
219
|
-
RoseTree(
|
220
|
-
`${this.keys.length} error(s) found while checking indices`,
|
221
|
-
this.keys.map((key) => RoseTree(`missing required index ${show(key)}`)),
|
222
|
-
),
|
223
|
-
);
|
224
|
-
}
|
225
|
-
|
226
|
-
function cannotDecode(u: unknown, expected: string): string {
|
227
|
-
return `cannot decode ${show(u)}, expected ${expected}`;
|
228
|
-
}
|
229
|
-
|
230
|
-
export class BrandedError extends DecodeError {
|
231
|
-
readonly _tag = "BrandedError";
|
232
|
-
constructor(
|
233
|
-
readonly name: string,
|
234
|
-
readonly brands: Vector<string>,
|
235
|
-
) {
|
236
|
-
super();
|
237
|
-
}
|
238
|
-
render = Eval(
|
239
|
-
RoseTree(
|
240
|
-
`${this.brands.length} brand(s) failed to be validated while decoding ${this.name}`,
|
241
|
-
this.brands.map((brand) => RoseTree(brand)),
|
242
|
-
),
|
243
|
-
);
|
244
|
-
}
|
245
|
-
|
246
|
-
export class UnionError extends DecodeError {
|
247
|
-
readonly _tag = "UnionError";
|
248
|
-
constructor(
|
249
|
-
readonly label: string,
|
250
|
-
readonly errors: Vector<DecodeError>,
|
251
|
-
) {
|
252
|
-
super();
|
253
|
-
}
|
254
|
-
render = Eval.defer(
|
255
|
-
this.errors
|
256
|
-
.traverse(Eval.Applicative)((error) => error.render)
|
257
|
-
.map((errors) => RoseTree(`${this.errors.length} error(s) found while decoding ${this.label}`, errors)),
|
258
|
-
);
|
259
|
-
}
|
260
|
-
|
261
|
-
export class EmptyError extends DecodeError {
|
262
|
-
readonly _tag = "EmptyError";
|
263
|
-
constructor(readonly actual: unknown) {
|
264
|
-
super();
|
265
|
-
}
|
266
|
-
render = Eval(RoseTree(cannotDecode(this.actual, "a collection containing at least one element")));
|
267
|
-
}
|
File without changes
|