@fncts/schema 0.0.14 → 0.0.16
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/AST.d.ts +29 -12
- package/Guard.d.ts +9 -0
- package/ParseError.d.ts +40 -3
- package/Parser/api.d.ts +0 -6
- package/Parser/interpreter.d.ts +1 -2
- package/Schema/api.d.ts +1 -1
- package/Schema/derivations.d.ts +1 -1
- package/Show.d.ts +1 -1
- package/_cjs/AST.cjs +115 -65
- package/_cjs/AST.cjs.map +1 -1
- package/_cjs/Guard.cjs +278 -0
- package/_cjs/Guard.cjs.map +1 -0
- package/_cjs/ParseError.cjs +77 -3
- package/_cjs/ParseError.cjs.map +1 -1
- package/_cjs/Parser/api.cjs +11 -23
- package/_cjs/Parser/api.cjs.map +1 -1
- package/_cjs/Parser/interpreter.cjs +93 -141
- package/_cjs/Parser/interpreter.cjs.map +1 -1
- package/_cjs/Schema/api.cjs +28 -29
- package/_cjs/Schema/api.cjs.map +1 -1
- package/_cjs/Show.cjs +23 -12
- package/_cjs/Show.cjs.map +1 -1
- package/_mjs/AST.mjs +107 -61
- package/_mjs/AST.mjs.map +1 -1
- package/_mjs/Guard.mjs +269 -0
- package/_mjs/Guard.mjs.map +1 -0
- package/_mjs/ParseError.mjs +72 -2
- package/_mjs/ParseError.mjs.map +1 -1
- package/_mjs/Parser/api.mjs +10 -21
- package/_mjs/Parser/api.mjs.map +1 -1
- package/_mjs/Parser/interpreter.mjs +94 -142
- package/_mjs/Parser/interpreter.mjs.map +1 -1
- package/_mjs/Schema/api.mjs +28 -29
- package/_mjs/Schema/api.mjs.map +1 -1
- package/_mjs/Show.mjs +23 -12
- package/_mjs/Show.mjs.map +1 -1
- package/_src/AST.ts +96 -47
- package/_src/Guard.ts +268 -0
- package/_src/ParseError.ts +88 -4
- package/_src/Parser/api.ts +8 -21
- package/_src/Parser/interpreter.ts +87 -121
- package/_src/Schema/api.ts +4 -11
- package/_src/Schema/derivations.ts +1 -1
- package/_src/Show.ts +28 -15
- package/package.json +3 -3
package/_mjs/Guard.mjs
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@fncts/base/data/Guard/definition";
|
|
2
|
+
import * as tsplus_module_2 from "@fncts/base/data/Either/destructors";
|
|
3
|
+
import * as tsplus_module_3 from "@fncts/base/data/number/instances";
|
|
4
|
+
import * as tsplus_module_4 from "@fncts/base/data/boolean/instances";
|
|
5
|
+
import * as tsplus_module_5 from "@fncts/base/data/Guard/api";
|
|
6
|
+
import * as tsplus_module_6 from "@fncts/base/data/bigint/instances";
|
|
7
|
+
import * as tsplus_module_7 from "@fncts/base/util/predicates";
|
|
8
|
+
import * as tsplus_module_8 from "@fncts/base/collection/immutable/Vector/api";
|
|
9
|
+
import * as tsplus_module_9 from "@fncts/base/data/Maybe/destructors";
|
|
10
|
+
import { globalValue } from "@fncts/base/data/Global";
|
|
11
|
+
import { isRecord } from "@fncts/base/util/predicates";
|
|
12
|
+
import { getKeysForIndexSignature, memoize } from "@fncts/schema/utils";
|
|
13
|
+
import { getSearchTree } from "./AST.mjs";
|
|
14
|
+
import { parserFor } from "./Parser.mjs";
|
|
15
|
+
/**
|
|
16
|
+
* @tsplus getter fncts.schema.Schema is
|
|
17
|
+
*/
|
|
18
|
+
export function is(schema) {
|
|
19
|
+
return input => {
|
|
20
|
+
return guardFor(schema).is(input);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function guardFor(schema) {
|
|
24
|
+
return goMemo(schema.ast);
|
|
25
|
+
}
|
|
26
|
+
const guardStrict = value => tsplus_module_1.makeGuard(inp => inp === value);
|
|
27
|
+
const guardMemoMap = /*#__PURE__*/globalValue( /*#__PURE__*/Symbol.for("fncts.schema.Guard.guardMemoMap"), () => new WeakMap());
|
|
28
|
+
function goMemo(ast) {
|
|
29
|
+
const memo = guardMemoMap.get(ast);
|
|
30
|
+
if (memo) {
|
|
31
|
+
return memo;
|
|
32
|
+
}
|
|
33
|
+
const guard = go(ast);
|
|
34
|
+
guardMemoMap.set(ast, guard);
|
|
35
|
+
return guard;
|
|
36
|
+
}
|
|
37
|
+
function go(ast) {
|
|
38
|
+
void 0;
|
|
39
|
+
switch (ast._tag) {
|
|
40
|
+
case 0 /* ASTTag.Declaration */:
|
|
41
|
+
{
|
|
42
|
+
const parser = parserFor(ast, true);
|
|
43
|
+
return tsplus_module_1.makeGuard(inp => tsplus_module_2.match(() => false, () => true)(parser(inp)));
|
|
44
|
+
}
|
|
45
|
+
case 1 /* ASTTag.Literal */:
|
|
46
|
+
{
|
|
47
|
+
return tsplus_module_1.makeGuard(inp => inp === ast.literal);
|
|
48
|
+
}
|
|
49
|
+
case 2 /* ASTTag.UniqueSymbol */:
|
|
50
|
+
{
|
|
51
|
+
return guardStrict(ast.symbol);
|
|
52
|
+
}
|
|
53
|
+
case 4 /* ASTTag.VoidKeyword */:
|
|
54
|
+
case 3 /* ASTTag.UndefinedKeyword */:
|
|
55
|
+
{
|
|
56
|
+
return guardStrict(undefined);
|
|
57
|
+
}
|
|
58
|
+
case 5 /* ASTTag.NeverKeyword */:
|
|
59
|
+
{
|
|
60
|
+
return tsplus_module_1.makeGuard(inp => false);
|
|
61
|
+
}
|
|
62
|
+
case 6 /* ASTTag.UnknownKeyword */:
|
|
63
|
+
case 7 /* ASTTag.AnyKeyword */:
|
|
64
|
+
{
|
|
65
|
+
return tsplus_module_1.makeGuard(inp => true);
|
|
66
|
+
}
|
|
67
|
+
case 9 /* ASTTag.NumberKeyword */:
|
|
68
|
+
{
|
|
69
|
+
return tsplus_module_3.Guard;
|
|
70
|
+
}
|
|
71
|
+
case 10 /* ASTTag.BooleanKeyword */:
|
|
72
|
+
{
|
|
73
|
+
return tsplus_module_4.Guard;
|
|
74
|
+
}
|
|
75
|
+
case 8 /* ASTTag.StringKeyword */:
|
|
76
|
+
{
|
|
77
|
+
return tsplus_module_5.string;
|
|
78
|
+
}
|
|
79
|
+
case 11 /* ASTTag.BigIntKeyword */:
|
|
80
|
+
{
|
|
81
|
+
return tsplus_module_6.Guard;
|
|
82
|
+
}
|
|
83
|
+
case 12 /* ASTTag.SymbolKeyword */:
|
|
84
|
+
{
|
|
85
|
+
return tsplus_module_1.makeGuard(inp => typeof inp === "symbol");
|
|
86
|
+
}
|
|
87
|
+
case 13 /* ASTTag.ObjectKeyword */:
|
|
88
|
+
{
|
|
89
|
+
return tsplus_module_1.makeGuard(tsplus_module_7.isObject);
|
|
90
|
+
}
|
|
91
|
+
case 15 /* ASTTag.TemplateLiteral */:
|
|
92
|
+
{
|
|
93
|
+
const parser = parserFor(ast, true);
|
|
94
|
+
return tsplus_module_1.makeGuard(inp => tsplus_module_2.match(() => false, () => true)(parser(inp)));
|
|
95
|
+
}
|
|
96
|
+
case 16 /* ASTTag.Tuple */:
|
|
97
|
+
{
|
|
98
|
+
const elements = tsplus_module_8.map(element => goMemo(element.type))(ast.elements);
|
|
99
|
+
const restElements = tsplus_module_9.match(() => tsplus_module_8.empty(), rest => tsplus_module_8.map(goMemo)(rest))(ast.rest);
|
|
100
|
+
return tsplus_module_1.makeGuard(input => {
|
|
101
|
+
if (!Array.isArray(input)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
let i = 0;
|
|
105
|
+
for (; i < elements.length; i++) {
|
|
106
|
+
if (input.length < i + 1) {
|
|
107
|
+
if (!tsplus_module_8.unsafeGet(i)(ast.elements).isOptional) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
const guard = tsplus_module_8.unsafeGet(i)(elements);
|
|
112
|
+
if (!guard.is(input[i])) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (restElements.length > 0) {
|
|
118
|
+
const head = tsplus_module_8.unsafeHead(restElements);
|
|
119
|
+
const tail = tsplus_module_8.tail(restElements);
|
|
120
|
+
for (; i < input.length - tail.length; i++) {
|
|
121
|
+
if (!head.is(input[i])) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (let j = 0; j < tail.length; j++) {
|
|
126
|
+
i += j;
|
|
127
|
+
if (input.length < i + 1) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const guard = tsplus_module_8.unsafeGet(j)(tail);
|
|
131
|
+
if (!guard.is(input[i])) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
case 17 /* ASTTag.TypeLiteral */:
|
|
140
|
+
{
|
|
141
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
|
|
142
|
+
return tsplus_module_1.makeGuard(input => input !== null);
|
|
143
|
+
}
|
|
144
|
+
const propertySignatureTypes = tsplus_module_8.map(ps => goMemo(ps.type))(ast.propertySignatures);
|
|
145
|
+
const indexSignatures = tsplus_module_8.map(is => [goMemo(is.parameter), goMemo(is.type)])(ast.indexSignatures);
|
|
146
|
+
return tsplus_module_1.makeGuard(input => {
|
|
147
|
+
if (!isRecord(input)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const expectedKeys = {};
|
|
151
|
+
console.log(ast.propertySignatures);
|
|
152
|
+
for (let i = 0; i < propertySignatureTypes.length; i++) {
|
|
153
|
+
const ps = tsplus_module_8.unsafeGet(i)(ast.propertySignatures);
|
|
154
|
+
const guard = tsplus_module_8.unsafeGet(i)(propertySignatureTypes);
|
|
155
|
+
const name = ps.name;
|
|
156
|
+
expectedKeys[name] = null;
|
|
157
|
+
if (!Object.prototype.hasOwnProperty.call(input, name)) {
|
|
158
|
+
if (!ps.isOptional) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
if (!tsplus_module_5.is(input[name])(guard)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (indexSignatures.length > 0) {
|
|
168
|
+
for (let i = 0; i < indexSignatures.length; i++) {
|
|
169
|
+
const [parameter, type] = tsplus_module_8.unsafeGet(i)(indexSignatures);
|
|
170
|
+
const keys = getKeysForIndexSignature(input, tsplus_module_8.unsafeGet(i)(ast.indexSignatures).parameter);
|
|
171
|
+
for (const key of keys) {
|
|
172
|
+
if (Object.prototype.hasOwnProperty.call(expectedKeys, key)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!tsplus_module_5.is(key)(parameter)) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (!tsplus_module_5.is(input[key])(type)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
case 18 /* ASTTag.Union */:
|
|
188
|
+
{
|
|
189
|
+
const searchTree = getSearchTree(ast.types, true);
|
|
190
|
+
const ownKeys = Reflect.ownKeys(searchTree.keys);
|
|
191
|
+
const len = ownKeys.length;
|
|
192
|
+
const otherwise = searchTree.otherwise;
|
|
193
|
+
const map = new Map();
|
|
194
|
+
tsplus_module_8.forEach(ast => {
|
|
195
|
+
map.set(ast, goMemo(ast));
|
|
196
|
+
})(ast.types);
|
|
197
|
+
return tsplus_module_1.makeGuard(input => {
|
|
198
|
+
if (len > 0) {
|
|
199
|
+
if (isRecord(input)) {
|
|
200
|
+
for (let i = 0; i < len; i++) {
|
|
201
|
+
const name = ownKeys[i];
|
|
202
|
+
const buckets = searchTree.keys[name].buckets;
|
|
203
|
+
if (Object.prototype.hasOwnProperty.call(input, name)) {
|
|
204
|
+
const literal = String(input[name]);
|
|
205
|
+
if (Object.prototype.hasOwnProperty.call(buckets, literal)) {
|
|
206
|
+
const bucket = buckets[literal];
|
|
207
|
+
for (let i = 0; i < bucket.length; i++) {
|
|
208
|
+
if (tsplus_module_5.is(input)(map.get(bucket[i]))) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
for (let i = 0; i < otherwise.length; i++) {
|
|
218
|
+
if (tsplus_module_5.is(input)(map.get(otherwise[i]))) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
case 19 /* ASTTag.Lazy */:
|
|
226
|
+
{
|
|
227
|
+
const f = () => goMemo(ast.getAST());
|
|
228
|
+
const get = memoize(f);
|
|
229
|
+
return tsplus_module_1.makeGuard(input => tsplus_module_5.is(input)(get()));
|
|
230
|
+
}
|
|
231
|
+
case 14 /* ASTTag.Enum */:
|
|
232
|
+
{
|
|
233
|
+
return tsplus_module_1.makeGuard(input => tsplus_module_8.some(([_, value]) => value === input)(ast.enums));
|
|
234
|
+
}
|
|
235
|
+
case 20 /* ASTTag.Refinement */:
|
|
236
|
+
{
|
|
237
|
+
const from = goMemo(ast.from);
|
|
238
|
+
return tsplus_module_1.makeGuard(input => {
|
|
239
|
+
if (!tsplus_module_5.is(input)(from)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
if (!ast.predicate(input)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
case 21 /* ASTTag.Transform */:
|
|
249
|
+
{
|
|
250
|
+
return goMemo(ast.to);
|
|
251
|
+
}
|
|
252
|
+
case 22 /* ASTTag.Validation */:
|
|
253
|
+
{
|
|
254
|
+
const from = goMemo(ast.from);
|
|
255
|
+
return tsplus_module_1.makeGuard(input => {
|
|
256
|
+
if (!tsplus_module_5.is(input)(from)) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
for (const validation of ast.validation) {
|
|
260
|
+
if (!validation.validate(input)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=Guard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Guard.mjs","names":["globalValue","isRecord","getKeysForIndexSignature","memoize","getSearchTree","parserFor","is","schema","input","guardFor","goMemo","ast","guardStrict","value","tsplus_module_1","makeGuard","inp","guardMemoMap","Symbol","for","WeakMap","memo","get","guard","go","set","_tag","parser","tsplus_module_2","match","literal","symbol","undefined","tsplus_module_3","Guard","tsplus_module_4","tsplus_module_5","string","tsplus_module_6","tsplus_module_7","isObject","elements","tsplus_module_8","map","element","type","restElements","tsplus_module_9","empty","rest","Array","isArray","i","length","unsafeGet","isOptional","head","unsafeHead","tail","j","propertySignatures","indexSignatures","propertySignatureTypes","ps","parameter","expectedKeys","console","log","name","Object","prototype","hasOwnProperty","call","keys","key","searchTree","types","ownKeys","Reflect","len","otherwise","Map","forEach","buckets","String","bucket","f","getAST","some","_","enums","from","predicate","to","validation","validate"],"sources":["../_src/Guard.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;AAAA,SAASA,WAAW,QAAQ,yBAAyB;AACrD,SAASC,QAAQ,QAAQ,6BAA6B;AACtD,SAASC,wBAAwB,EAAEC,OAAO,QAAQ,qBAAqB;AAEvE,SAAiBC,aAAa,QAAQ,WAAU;AAChD,SAASC,SAAS,QAAQ,cAAa;AAEvC;;;AAGA,OAAM,SAAUC,EAAEA,CAAIC,MAAiB;EACrC,OAAQC,KAAc,IAAgB;IACpC,OAAOC,QAAQ,CAACF,MAAM,CAAC,CAACD,EAAE,CAACE,KAAK,CAAC;EACnC,CAAC;AACH;AAEA,OAAM,SAAUC,QAAQA,CAAIF,MAAiB;EAC3C,OAAOG,MAAM,CAACH,MAAM,CAACI,GAAG,CAAC;AAC3B;AAEA,MAAMC,WA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B,OAAOE,MAAM,CAACC,GAAG,CAACkF,EAAE,CAAC;MACvB;IACA;MAAwB;QACtB,MAAMF,IAAI,GAAGjF,MAAM,CAACC,GAAG,CAACgF,IAAI,CAAC;QAC7B,OAAO7E,eAAA,CAAAC,SAAA,CAAOP,KAAK,IAAkB;UACnC,IAAI,CAAC4B,eAAA,CAAA9B,EAAA,CAAKE,KAAK,EAAVmF,IAAI,CAAO,EAAE;YAChB,OAAO,KAAK;UACd;UACA,KAAK,MAAMG,UAAU,IAAInF,GAAG,CAACmF,UAAU,EAAE;YACvC,IAAI,CAACA,UAAU,CAACC,QAAQ,CAACvF,KAAK,CAAC,EAAE;cAC/B,OAAO,KAAK;YACd;UACF;UACA,OAAO,IAAI;QACb,CAAC,CAAC;MACJ;EACF;AACF"}
|
package/_mjs/ParseError.mjs
CHANGED
|
@@ -53,7 +53,7 @@ export class KeyError {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* @tsplus static fncts.schema.ParseError.
|
|
56
|
+
* @tsplus static fncts.schema.ParseError.KeyError __call
|
|
57
57
|
* @tsplus static fncts.schema.ParseErrorOps KeyError
|
|
58
58
|
*/
|
|
59
59
|
export function keyError(keyAST, key, errors) {
|
|
@@ -103,6 +103,44 @@ export class UnionMemberError {
|
|
|
103
103
|
export function unionMemberError(errors) {
|
|
104
104
|
return new UnionMemberError(errors);
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @tsplus companion fncts.schema.ParseError.RefinementError
|
|
108
|
+
*/
|
|
109
|
+
export class RefinementError {
|
|
110
|
+
constructor(ast, actual, kind, errors) {
|
|
111
|
+
this.ast = ast;
|
|
112
|
+
this.actual = actual;
|
|
113
|
+
this.kind = kind;
|
|
114
|
+
this.errors = errors;
|
|
115
|
+
this._tag = 6 /* ParseErrorTag.Refinement */;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @tsplus static fncts.schema.ParseError.RefinementError __call
|
|
120
|
+
* @tsplus static fncts.schema.ParseErrorOps RefinementError
|
|
121
|
+
*/
|
|
122
|
+
export function refinementError(ast, actual, kind, errors) {
|
|
123
|
+
return new RefinementError(ast, actual, kind, errors);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @tsplus companion fncts.schema.ParseError.TransformationError
|
|
127
|
+
*/
|
|
128
|
+
export class TransformationError {
|
|
129
|
+
constructor(ast, actual, kind, errors) {
|
|
130
|
+
this.ast = ast;
|
|
131
|
+
this.actual = actual;
|
|
132
|
+
this.kind = kind;
|
|
133
|
+
this.errors = errors;
|
|
134
|
+
this._tag = 7 /* ParseErrorTag.Transformation */;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @tsplus static fncts.schema.ParseError.TransformationError __call
|
|
139
|
+
* @tsplus static fncts.schema.ParseErrorOps TransformationError
|
|
140
|
+
*/
|
|
141
|
+
export function transformationError(ast, actual, kind, errors) {
|
|
142
|
+
return new TransformationError(ast, actual, kind, errors);
|
|
143
|
+
}
|
|
106
144
|
/**
|
|
107
145
|
* @tsplus static fncts.schema.ParseErrorOps format
|
|
108
146
|
*/
|
|
@@ -125,8 +163,36 @@ function formatTemplateLiteralSpan(span) {
|
|
|
125
163
|
function formatTemplateLiteral(ast) {
|
|
126
164
|
return ast.head + tsplus_module_1.join("")(tsplus_module_1.map(span => formatTemplateLiteralSpan(span) + span.literal)(ast.spans));
|
|
127
165
|
}
|
|
166
|
+
function formatRefinementKind(error) {
|
|
167
|
+
switch (error.kind) {
|
|
168
|
+
case "From":
|
|
169
|
+
{
|
|
170
|
+
return "From side refinement failure";
|
|
171
|
+
}
|
|
172
|
+
case "Predicate":
|
|
173
|
+
{
|
|
174
|
+
return "Predicate refinement failure";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function formatTransformationKind(error) {
|
|
179
|
+
switch (error.kind) {
|
|
180
|
+
case "Encoded":
|
|
181
|
+
{
|
|
182
|
+
return "Encoded side transformation failure";
|
|
183
|
+
}
|
|
184
|
+
case "Transformation":
|
|
185
|
+
{
|
|
186
|
+
return "Transformation process failure";
|
|
187
|
+
}
|
|
188
|
+
case "Type":
|
|
189
|
+
{
|
|
190
|
+
return "Type side transformation failure";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
128
194
|
function getExpected(ast) {
|
|
129
|
-
return tsplus_module_6.flatMap(title => tsplus_module_5.match(() => tsplus_module_3.just(title, fileName_1 + ":
|
|
195
|
+
return tsplus_module_6.flatMap(title => tsplus_module_5.match(() => tsplus_module_3.just(title, fileName_1 + ":242:19"), description => tsplus_module_3.just(`${title} (${description})`, fileName_1 + ":243:30"))(ast.annotations.get(tsplus_module_4.Description)))(tsplus_module_6.orElse(() => ast.annotations.get(tsplus_module_4.Title))(ast.annotations.get(tsplus_module_4.Identifier)));
|
|
130
196
|
}
|
|
131
197
|
function getMissedBrands(ast) {
|
|
132
198
|
return tsplus_module_1.join(" & ")(tsplus_module_1.map(validation => validation.name)(ast.validation));
|
|
@@ -196,6 +262,10 @@ function go(error) {
|
|
|
196
262
|
return tsplus_module_2.make("is missing");
|
|
197
263
|
case 5 /* ParseErrorTag.UnionMember */:
|
|
198
264
|
return tsplus_module_2.make("union member", tsplus_module_1.map(go)(error.errors));
|
|
265
|
+
case 6 /* ParseErrorTag.Refinement */:
|
|
266
|
+
return tsplus_module_2.make(formatRefinementKind(error), tsplus_module_1.map(go)(error.errors));
|
|
267
|
+
case 7 /* ParseErrorTag.Transformation */:
|
|
268
|
+
return tsplus_module_2.make(formatTransformationKind(error), tsplus_module_1.map(go)(error.errors));
|
|
199
269
|
}
|
|
200
270
|
}
|
|
201
271
|
//# sourceMappingURL=ParseError.mjs.map
|
package/_mjs/ParseError.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseError.mjs","names":["showWithOptions","concrete","TypeError","constructor","expected","actual","_tag","typeError","IndexError","index","errors","indexError","KeyError","keyAST","key","keyError","MissingError","missingError","UnexpectedError","unexpectedError","UnionMemberError","unionMemberError","format","tsplus_module_2","draw","make","length","tsplus_module_1","map","go","formatActual","colors","formatTemplateLiteralSpan","span","type","formatTemplateLiteral","
|
|
1
|
+
{"version":3,"file":"ParseError.mjs","names":["showWithOptions","concrete","TypeError","constructor","expected","actual","_tag","typeError","IndexError","index","errors","indexError","KeyError","keyAST","key","keyError","MissingError","missingError","UnexpectedError","unexpectedError","UnionMemberError","unionMemberError","RefinementError","ast","kind","refinementError","TransformationError","transformationError","format","tsplus_module_2","draw","make","length","tsplus_module_1","map","go","formatActual","colors","formatTemplateLiteralSpan","span","type","formatTemplateLiteral","head","join","literal","spans","formatRefinementKind","error","formatTransformationKind","getExpected","tsplus_module_6","flatMap","title","tsplus_module_5","match","tsplus_module_3","just","fileName_1","description","annotations","get","tsplus_module_4","Description","orElse","Title","Identifier","getMissedBrands","validation","name","formatExpected","getOrElse","symbol","types","_","value","JSON","stringify","enums","from","to","f","Message"],"sources":["../_src/ParseError.ts"],"sourcesContent":[null],"mappings":";;;;;;;AAEA,SAASA,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,QAAQ,QAAQ,mBAAmB;AA6B5C;;;AAGA,OAAM,MAAOC,SAAS;EAEpBC,YACWC,QAAa,EACbC,MAAe;IADf,KAAAD,QAAQ,GAARA,QAAQ;IACR,KAAAC,MAAM,GAANA,MAAM;IAHR,KAAAC,IAAI;EAIV;;AAGL;;;;AAIA,OAAM,SAAUC,SAASA,CAACH,QAAa,EAAEC,MAAe;EACtD,OAAO,IAAIH,SAAS,CAACE,QAAQ,EAAEC,MAAM,CAAC;AACxC;AAEA;;;AAGA,OAAM,MAAOG,UAAU;EAErBL,YACWM,KAAa,EACbC,MAA0B;IAD1B,KAAAD,KAAK,GAALA,KAAK;IACL,KAAAC,MAAM,GAANA,MAAM;IAHR,KAAAJ,IAAI;EAIV;;AAGL;;;;AAIA,OAAM,SAAUK,UAAUA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rC,MAAM,CAAQ,CAAC;IACzE;MACE,OAAOmB,eAAA,CAAAE,IAAA,CAAS,YAAY,CAAC;IAC/B;MACE,OAAOF,eAAA,CAAAE,IAAA,CAAS,cAAc,EAAEE,eAAA,CAAAC,GAAA,CAAiBC,EAAE,EAAnBY,KAAK,CAACrC,MAAM,CAAQ,CAAC;IACvD;MACE,OAAOmB,eAAA,CAAAE,IAAA,CAASe,oBAAoB,CAACC,KAAK,CAAC,EAAEd,eAAA,CAAAC,GAAA,CAAiBC,EAAE,EAAnBY,KAAK,CAACrC,MAAM,CAAQ,CAAC;IACpE;MACE,OAAOmB,eAAA,CAAAE,IAAA,CAASiB,wBAAwB,CAACD,KAAK,CAAC,EAAEd,eAAA,CAAAC,GAAA,CAAiBC,EAAE,EAAnBY,KAAK,CAACrC,MAAM,CAAQ,CAAC;EAC1E;AACF"}
|
package/_mjs/Parser/api.mjs
CHANGED
|
@@ -3,13 +3,14 @@ import * as tsplus_module_2 from "@fncts/base/data/Either/api";
|
|
|
3
3
|
import * as tsplus_module_3 from "@fncts/schema/ParseError";
|
|
4
4
|
import * as tsplus_module_4 from "@fncts/base/data/function/api";
|
|
5
5
|
import * as tsplus_module_5 from "@fncts/base/data/Either/destructors";
|
|
6
|
+
export const encode = encode_1;
|
|
6
7
|
import { parserFor } from "./interpreter.mjs";
|
|
7
8
|
/**
|
|
8
9
|
* @tsplus getter fncts.schema.Schema decode
|
|
9
10
|
* @tsplus getter fncts.schema.Parser decode
|
|
10
11
|
*/
|
|
11
12
|
export function decode(schema) {
|
|
12
|
-
return parserFor(schema.ast);
|
|
13
|
+
return parserFor(schema.ast, true);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* @tsplus getter fncts.schema.Schema decodeMaybe
|
|
@@ -22,40 +23,28 @@ export function decodeMaybe(schema) {
|
|
|
22
23
|
* @tsplus getter fncts.schema.Schema encode
|
|
23
24
|
* @tsplus getter fncts.schema.Parser encode
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
-
return parserFor(
|
|
26
|
+
function encode_1(schema) {
|
|
27
|
+
return parserFor(schema.ast, false);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* @tsplus getter fncts.schema.Schema encodeMaybe
|
|
30
31
|
* @tsplus getter fncts.schema.Parser encodeMaybe
|
|
31
32
|
*/
|
|
32
33
|
export function encodeMaybe(schema) {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @tsplus getter fncts.schema.Schema is
|
|
37
|
-
* @tsplus getter fncts.schema.Parser is
|
|
38
|
-
*/
|
|
39
|
-
export function is(schema) {
|
|
40
|
-
return (input, options) => {
|
|
41
|
-
return tsplus_module_2.isRight(parserFor(schema.ast)(input, options));
|
|
42
|
-
};
|
|
34
|
+
return (input, options) => tsplus_module_2.toMaybe(encode_1(schema)(input, options));
|
|
43
35
|
}
|
|
44
36
|
function parseMaybe(ast) {
|
|
45
|
-
const parse = parserFor(ast);
|
|
37
|
+
const parse = parserFor(ast, true);
|
|
46
38
|
return (input, options) => {
|
|
47
39
|
return tsplus_module_2.toMaybe(parse(input, options));
|
|
48
40
|
};
|
|
49
41
|
}
|
|
50
42
|
function parseOrThrow(ast) {
|
|
51
|
-
const parser = parserFor(ast);
|
|
43
|
+
const parser = parserFor(ast, true);
|
|
52
44
|
return (input, options) => {
|
|
53
|
-
return tsplus_module_5.match({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
Right: tsplus_module_4.identity
|
|
58
|
-
})(parser(input, options));
|
|
45
|
+
return tsplus_module_5.match(failure => {
|
|
46
|
+
throw new Error(tsplus_module_3.format(failure.errors));
|
|
47
|
+
}, tsplus_module_4.identity)(parser(input, options));
|
|
59
48
|
};
|
|
60
49
|
}
|
|
61
50
|
/**
|
package/_mjs/Parser/api.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.mjs","names":["parserFor","decode","schema","ast","decodeMaybe","parseMaybe","tsplus_module_1","getTo","
|
|
1
|
+
{"version":3,"file":"api.mjs","names":["encode","encode_1","parserFor","decode","schema","ast","decodeMaybe","parseMaybe","tsplus_module_1","getTo","encodeMaybe","input","options","tsplus_module_2","toMaybe","parse","parseOrThrow","parser","tsplus_module_5","match","failure","Error","tsplus_module_3","format","errors","tsplus_module_4","identity","asserts"],"sources":["../../_src/Parser/api.ts"],"sourcesContent":[null],"mappings":";;;;;aAwBgBA,MAAM,GAAAC,QAAA;AAtBtB,SAASC,SAAS,QAAQ,mBAAkB;AAE5C;;;;AAIA,OAAM,SAAUC,MAAMA,CAAIC,MAAiB;EACzC,OAAOF,SAAS,CAACE,MAAM,CAACC,GAAG,EAAE,IAAI,CAAC;AACpC;AAEA;;;;AAIA,OAAM,SAAUC,WAAWA,CAAIF,MAAiB;EAC9C,OAAOG,UAAU,CAAAC,eAAA,CAAAC,KAAA,CAACL,MAAM,CAACC,GAAG,EAAO;AACrC;AAEA;;;;AAIA,SAAAJ,SAA0BG,MAAiB;EACzC,OAAOF,SAAS,CAACE,MAAM,CAACC,GAAG,EAAE,KAAK,CAAC;AACrC;AAEA;;;;AAIA,OAAM,SAAUK,WAAWA,CAAIN,MAAiB;EAC9C,OAAO,CAACO,KAAK,EAAEC,OAAO,KAAIC,eAAA,CAAAC,OAAA,CAACb,QAAA,CAAOG,MAAM,CAAC,CAACO,KAAK,EAAEC,OAAO,CAAC,CAAQ;AACnE;AAEA,SAASL,UAAUA,CAACF,GAAQ;EAC1B,MAAMU,KAAK,GAAGb,SAAS,CAACG,GAAG,EAAE,IAAI,CAAC;EAClC,OAAO,CAACM,KAAc,EAAEC,OAAsB,KAAgB;IAC5D,OAAAC,eAAA,CAAAC,OAAA,CAAOC,KAAK,CAACJ,KAAK,EAAEC,OAAO,CAAC;EAC9B,CAAC;AACH;AAEA,SAASI,YAAYA,CAACX,GAAQ;EAC5B,MAAMY,MAAM,GAAGf,SAAS,CAACG,GAAG,EAAE,IAAI,CAAC;EACnC,O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