@fncts/schema 0.0.24 → 0.0.25
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/LICENSE +26 -0
- package/_cjs/AST.cjs +1093 -1226
- package/_cjs/AST.cjs.map +1 -1
- package/_cjs/ASTAnnotation.cjs +114 -85
- package/_cjs/ASTAnnotation.cjs.map +1 -1
- package/_cjs/ASTAnnotationMap.cjs +43 -41
- package/_cjs/ASTAnnotationMap.cjs.map +1 -1
- package/_cjs/Eq.cjs +113 -145
- package/_cjs/Eq.cjs.map +1 -1
- package/_cjs/Gen.cjs +131 -167
- package/_cjs/Gen.cjs.map +1 -1
- package/_cjs/Guard.cjs +167 -267
- package/_cjs/Guard.cjs.map +1 -1
- package/_cjs/InvalidInterpretationError.cjs +9 -10
- package/_cjs/InvalidInterpretationError.cjs.map +1 -1
- package/_cjs/ParseError/ParseError.cjs +283 -284
- package/_cjs/ParseError/ParseError.cjs.map +1 -1
- package/_cjs/ParseError/ParseErrorFormatter.cjs +0 -2
- package/_cjs/ParseError/PathFormatter.cjs +55 -87
- package/_cjs/ParseError/PathFormatter.cjs.map +1 -1
- package/_cjs/ParseError/TreeFormatter.cjs +70 -102
- package/_cjs/ParseError/TreeFormatter.cjs.map +1 -1
- package/_cjs/ParseError.cjs +35 -50
- package/_cjs/ParseResult.cjs +15 -15
- package/_cjs/ParseResult.cjs.map +1 -1
- package/_cjs/Parser/api.cjs +54 -50
- package/_cjs/Parser/api.cjs.map +1 -1
- package/_cjs/Parser/definition.cjs +17 -16
- package/_cjs/Parser/definition.cjs.map +1 -1
- package/_cjs/Parser/interpreter.cjs +276 -358
- package/_cjs/Parser/interpreter.cjs.map +1 -1
- package/_cjs/Parser.cjs +12 -39
- package/_cjs/Schema/api/conc.cjs +64 -59
- package/_cjs/Schema/api/conc.cjs.map +1 -1
- package/_cjs/Schema/api/either.cjs +73 -72
- package/_cjs/Schema/api/either.cjs.map +1 -1
- package/_cjs/Schema/api/hashMap.cjs +85 -85
- package/_cjs/Schema/api/hashMap.cjs.map +1 -1
- package/_cjs/Schema/api/hashSet.cjs +75 -69
- package/_cjs/Schema/api/hashSet.cjs.map +1 -1
- package/_cjs/Schema/api/list.cjs +74 -66
- package/_cjs/Schema/api/list.cjs.map +1 -1
- package/_cjs/Schema/api/map.cjs +81 -83
- package/_cjs/Schema/api/map.cjs.map +1 -1
- package/_cjs/Schema/api/maybe.cjs +56 -49
- package/_cjs/Schema/api/maybe.cjs.map +1 -1
- package/_cjs/Schema/api/set.cjs +68 -61
- package/_cjs/Schema/api/set.cjs.map +1 -1
- package/_cjs/Schema/api.cjs +332 -350
- package/_cjs/Schema/api.cjs.map +1 -1
- package/_cjs/Schema/definition.cjs +28 -26
- package/_cjs/Schema/definition.cjs.map +1 -1
- package/_cjs/Schema/derivations.cjs +85 -100
- package/_cjs/Schema/derivations.cjs.map +1 -1
- package/_cjs/Schema.cjs +95 -127
- package/_cjs/Show.cjs +91 -151
- package/_cjs/Show.cjs.map +1 -1
- package/_cjs/chunk.cjs +28 -0
- package/_cjs/global.cjs +0 -2
- package/_cjs/index.cjs +0 -2
- package/_cjs/utils.cjs +41 -46
- package/_cjs/utils.cjs.map +1 -1
- package/_mjs/AST.mjs +996 -1161
- package/_mjs/AST.mjs.map +1 -1
- package/_mjs/ASTAnnotation.mjs +77 -73
- package/_mjs/ASTAnnotation.mjs.map +1 -1
- package/_mjs/ASTAnnotationMap.mjs +31 -29
- package/_mjs/ASTAnnotationMap.mjs.map +1 -1
- package/_mjs/Eq.mjs +101 -134
- package/_mjs/Eq.mjs.map +1 -1
- package/_mjs/Gen.mjs +117 -157
- package/_mjs/Gen.mjs.map +1 -1
- package/_mjs/Guard.mjs +154 -257
- package/_mjs/Guard.mjs.map +1 -1
- package/_mjs/InvalidInterpretationError.mjs +8 -4
- package/_mjs/InvalidInterpretationError.mjs.map +1 -1
- package/_mjs/ParseError/ParseError.mjs +266 -262
- package/_mjs/ParseError/ParseError.mjs.map +1 -1
- package/_mjs/ParseError/ParseErrorFormatter.mjs +0 -2
- package/_mjs/ParseError/PathFormatter.mjs +51 -80
- package/_mjs/ParseError/PathFormatter.mjs.map +1 -1
- package/_mjs/ParseError/TreeFormatter.mjs +62 -94
- package/_mjs/ParseError/TreeFormatter.mjs.map +1 -1
- package/_mjs/ParseError.mjs +5 -6
- package/_mjs/ParseResult.mjs +13 -9
- package/_mjs/ParseResult.mjs.map +1 -1
- package/_mjs/Parser/api.mjs +43 -39
- package/_mjs/Parser/api.mjs.map +1 -1
- package/_mjs/Parser/definition.mjs +12 -8
- package/_mjs/Parser/definition.mjs.map +1 -1
- package/_mjs/Parser/interpreter.mjs +262 -348
- package/_mjs/Parser/interpreter.mjs.map +1 -1
- package/_mjs/Parser.mjs +4 -5
- package/_mjs/Schema/api/conc.mjs +41 -45
- package/_mjs/Schema/api/conc.mjs.map +1 -1
- package/_mjs/Schema/api/either.mjs +55 -61
- package/_mjs/Schema/api/either.mjs.map +1 -1
- package/_mjs/Schema/api/hashMap.mjs +61 -71
- package/_mjs/Schema/api/hashMap.mjs.map +1 -1
- package/_mjs/Schema/api/hashSet.mjs +53 -56
- package/_mjs/Schema/api/hashSet.mjs.map +1 -1
- package/_mjs/Schema/api/list.mjs +50 -53
- package/_mjs/Schema/api/list.mjs.map +1 -1
- package/_mjs/Schema/api/map.mjs +59 -69
- package/_mjs/Schema/api/map.mjs.map +1 -1
- package/_mjs/Schema/api/maybe.mjs +34 -36
- package/_mjs/Schema/api/maybe.mjs.map +1 -1
- package/_mjs/Schema/api/set.mjs +47 -48
- package/_mjs/Schema/api/set.mjs.map +1 -1
- package/_mjs/Schema/api.mjs +304 -346
- package/_mjs/Schema/api.mjs.map +1 -1
- package/_mjs/Schema/definition.mjs +21 -17
- package/_mjs/Schema/definition.mjs.map +1 -1
- package/_mjs/Schema/derivations.mjs +71 -90
- package/_mjs/Schema/derivations.mjs.map +1 -1
- package/_mjs/Schema.mjs +12 -15
- package/_mjs/Show.mjs +79 -139
- package/_mjs/Show.mjs.map +1 -1
- package/_mjs/global.mjs +0 -2
- package/_mjs/index.mjs +0 -2
- package/_mjs/utils.mjs +35 -37
- package/_mjs/utils.mjs.map +1 -1
- package/package.json +7 -3
- package/_cjs/ParseError/ParseErrorFormatter.cjs.map +0 -1
- package/_cjs/ParseError.cjs.map +0 -1
- package/_cjs/Parser.cjs.map +0 -1
- package/_cjs/Schema.cjs.map +0 -1
- package/_cjs/global.cjs.map +0 -1
- package/_cjs/index.cjs.map +0 -1
- package/_mjs/ParseError/ParseErrorFormatter.mjs.map +0 -1
- package/_mjs/ParseError.mjs.map +0 -1
- package/_mjs/Parser.mjs.map +0 -1
- package/_mjs/Schema.mjs.map +0 -1
- package/_mjs/global.mjs.map +0 -1
- package/_mjs/index.mjs.map +0 -1
package/_mjs/Schema/api.mjs
CHANGED
|
@@ -1,402 +1,360 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { ownKeys } from "../utils.mjs";
|
|
2
|
+
import { TemplateLiteralSpan, getParameter } from "../AST.mjs";
|
|
3
3
|
import * as tsplus_module_2 from "@fncts/base/collection/immutable/Vector/api";
|
|
4
4
|
import * as tsplus_module_3 from "@fncts/schema/AST";
|
|
5
|
+
import { show } from "@fncts/base/data/Showable";
|
|
6
|
+
import * as tsplus_module_7 from "@fncts/base/data/Maybe/api";
|
|
7
|
+
import * as tsplus_module_9 from "@fncts/base/data/Maybe/constructors";
|
|
8
|
+
import * as tsplus_module_1 from "@fncts/schema/Schema/definition";
|
|
5
9
|
import * as tsplus_module_4 from "@fncts/schema/ASTAnnotation";
|
|
6
10
|
import * as tsplus_module_5 from "@fncts/schema/ParseResult";
|
|
7
11
|
import * as tsplus_module_6 from "@fncts/schema/Parser/api";
|
|
8
|
-
import * as tsplus_module_7 from "@fncts/base/data/Maybe/api";
|
|
9
12
|
import * as tsplus_module_8 from "@fncts/schema/Schema/api/maybe";
|
|
10
|
-
import * as tsplus_module_9 from "@fncts/base/data/Maybe/constructors";
|
|
11
13
|
import * as tsplus_module_10 from "@fncts/base/data/Maybe/definition";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @tsplus static fncts.schema.SchemaOps fromAST
|
|
28
|
-
*/
|
|
14
|
+
//#region build/esm/Schema/api.js
|
|
15
|
+
const fileName_1 = "(@fncts/schema) src/Schema/api.ts";
|
|
16
|
+
const make = make_1;
|
|
17
|
+
const annotate = annotate_1;
|
|
18
|
+
const filter = filter_1;
|
|
19
|
+
const union = union_1;
|
|
20
|
+
const isOptional = isOptional_1;
|
|
21
|
+
const isParseOptional = isParseOptional_1;
|
|
22
|
+
const enum_ = enum_1;
|
|
23
|
+
const instanceOf = instanceOf_1;
|
|
24
|
+
const transformOrFail = transformOrFail_1;
|
|
25
|
+
const transform = transform_1;
|
|
26
|
+
/**
|
|
27
|
+
* @tsplus static fncts.schema.SchemaOps fromAST
|
|
28
|
+
*/
|
|
29
29
|
function make_1(ast) {
|
|
30
|
-
|
|
30
|
+
return new tsplus_module_1.Schema(ast);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
* @tsplus pipeable fncts.schema.Schema annotate
|
|
34
|
+
*/
|
|
35
35
|
function annotate_1(annotation, value) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}));
|
|
40
|
-
};
|
|
36
|
+
return (self) => {
|
|
37
|
+
return make_1(self.ast.clone({ annotations: self.ast.annotations.annotate(annotation, value) }));
|
|
38
|
+
};
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
* @tsplus static fncts.schema.SchemaOps declaration
|
|
42
|
+
*/
|
|
43
|
+
function declaration(typeParameters, decode, encode, annotations) {
|
|
44
|
+
return make_1(tsplus_module_3.createDeclaration(tsplus_module_2.map((tp) => tp.ast)(typeParameters), (...typeParameters) => decode(...typeParameters.map(make_1)), (...typeParameters) => encode(...typeParameters.map(make_1)), annotations));
|
|
47
45
|
}
|
|
48
46
|
function filter_1(predicate) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
47
|
+
return (self) => {
|
|
48
|
+
return make_1(tsplus_module_3.createRefinement(self.ast, predicate));
|
|
49
|
+
};
|
|
53
50
|
}
|
|
54
51
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
52
|
+
* @tsplus pipeable fncts.schema.Schema brand
|
|
53
|
+
*/
|
|
54
|
+
function brand(validation) {
|
|
55
|
+
return (self) => {
|
|
56
|
+
return make_1(tsplus_module_3.createRefinement(self.ast, validation.validate, self.ast.annotations.annotate(tsplus_module_4.Brand, tsplus_module_2.vector(validation))));
|
|
57
|
+
};
|
|
62
58
|
}
|
|
63
59
|
function makeLiteral(value) {
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const unknown_1 =
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const _undefined_1 =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
}, input => tsplus_module_5.succeed(input))(unknown_1);
|
|
154
|
-
/**
|
|
155
|
-
* @tsplus derive fncts.schema.Schema<|> 30
|
|
156
|
-
* @tsplus static fncts.schema.SchemaOps union
|
|
157
|
-
*/
|
|
60
|
+
return make_1(tsplus_module_3.createLiteral(value));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @tsplus static fncts.schema.SchemaOps literal
|
|
64
|
+
*/
|
|
65
|
+
function literal(...literals) {
|
|
66
|
+
return union_1(...literals.map(makeLiteral));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @tsplus static fncts.schema.SchemaOps never
|
|
70
|
+
* @tsplus implicit
|
|
71
|
+
*/
|
|
72
|
+
const never = make_1(tsplus_module_3.neverKeyword);
|
|
73
|
+
/**
|
|
74
|
+
* @tsplus static fncts.schema.SchemaOps unknown
|
|
75
|
+
* @tsplus implicit
|
|
76
|
+
*/
|
|
77
|
+
const unknown_1 = make_1(tsplus_module_3.unknownKeyword);
|
|
78
|
+
const unknown = unknown_1;
|
|
79
|
+
/**
|
|
80
|
+
* @tsplus static fncts.schema.SchemaOps any
|
|
81
|
+
*/
|
|
82
|
+
const any = make_1(tsplus_module_3.anyKeyword);
|
|
83
|
+
/**
|
|
84
|
+
* @tsplus static fncts.schema.SchemaOps undefined
|
|
85
|
+
* @tsplus implicit
|
|
86
|
+
*/
|
|
87
|
+
const _undefined_1 = make_1(tsplus_module_3.undefinedKeyword);
|
|
88
|
+
const _undefined = _undefined_1;
|
|
89
|
+
/**
|
|
90
|
+
* @tsplus static fncts.schema.SchemaOps null
|
|
91
|
+
* @tsplus implicit
|
|
92
|
+
*/
|
|
93
|
+
const _null_1 = make_1(tsplus_module_3.createLiteral(null));
|
|
94
|
+
const _null = _null_1;
|
|
95
|
+
/**
|
|
96
|
+
* @tsplus static fncts.schema.SchemaOps void
|
|
97
|
+
* @tsplus implicit
|
|
98
|
+
*/
|
|
99
|
+
const _void_1 = make_1(tsplus_module_3.voidKeyword);
|
|
100
|
+
const _void = _void_1;
|
|
101
|
+
/**
|
|
102
|
+
* @tsplus static fncts.schema.SchemaOps string
|
|
103
|
+
* @tsplus implicit
|
|
104
|
+
*/
|
|
105
|
+
const string = make_1(tsplus_module_3.stringKeyword);
|
|
106
|
+
/**
|
|
107
|
+
* @tsplus static fncts.schema.SchemaOps number
|
|
108
|
+
* @tsplus implicit
|
|
109
|
+
*/
|
|
110
|
+
const number = make_1(tsplus_module_3.numberKeyword);
|
|
111
|
+
/**
|
|
112
|
+
* @tsplus static fncts.schema.SchemaOps boolean
|
|
113
|
+
* @tsplus implicit
|
|
114
|
+
*/
|
|
115
|
+
const boolean = make_1(tsplus_module_3.booleanKeyword);
|
|
116
|
+
/**
|
|
117
|
+
* @tsplus static fncts.schema.SchemaOps bigint
|
|
118
|
+
* @tsplus implicit
|
|
119
|
+
*/
|
|
120
|
+
const bigint = make_1(tsplus_module_3.bigIntKeyword);
|
|
121
|
+
/**
|
|
122
|
+
* @tsplus static fncts.schema.SchemaOps symbol
|
|
123
|
+
* @tsplus implicit
|
|
124
|
+
*/
|
|
125
|
+
const symbol = make_1(tsplus_module_3.symbolKeyword);
|
|
126
|
+
/**
|
|
127
|
+
* @tsplus static fncts.schema.SchemaOps object
|
|
128
|
+
* @tsplus implicit
|
|
129
|
+
*/
|
|
130
|
+
const object_1 = make_1(tsplus_module_3.objectKeyword);
|
|
131
|
+
const object = object_1;
|
|
132
|
+
/**
|
|
133
|
+
* @tsplus static fncts.schema.SchemaOps date
|
|
134
|
+
*/
|
|
135
|
+
const date_1 = instanceOf_1(Date)(object_1);
|
|
136
|
+
const date = date_1;
|
|
137
|
+
/**
|
|
138
|
+
* @tsplus implicit
|
|
139
|
+
*/
|
|
140
|
+
const implicitDate = transformOrFail_1(date_1, (input, options) => {
|
|
141
|
+
if (typeof input === "string" || typeof input === "number") return tsplus_module_5.succeed(new Date(input));
|
|
142
|
+
else return tsplus_module_6.decode(date_1)(input, options);
|
|
143
|
+
}, (input) => tsplus_module_5.succeed(input))(unknown_1);
|
|
144
|
+
/**
|
|
145
|
+
* @tsplus derive fncts.schema.Schema<|> 30
|
|
146
|
+
* @tsplus static fncts.schema.SchemaOps union
|
|
147
|
+
*/
|
|
158
148
|
function union_1(...members) {
|
|
159
|
-
|
|
149
|
+
return make_1(tsplus_module_3.createUnion(tsplus_module_2.from(members.map((m) => m.ast))));
|
|
160
150
|
}
|
|
161
151
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
* @tsplus getter fncts.schema.Schema nullable
|
|
153
|
+
*/
|
|
154
|
+
function nullable(self) {
|
|
155
|
+
return union_1(_null_1, self);
|
|
166
156
|
}
|
|
167
157
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
* @tsplus static fncts.schema.SchemaOps uniqueSymbol
|
|
159
|
+
*/
|
|
160
|
+
function uniqueSymbol(symbol, annotations) {
|
|
161
|
+
return make_1(tsplus_module_3.createUniqueSymbol(symbol, annotations));
|
|
172
162
|
}
|
|
173
163
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
annotations: self.ast.annotations.annotate(tsplus_module_4.Optional, true)
|
|
179
|
-
}));
|
|
164
|
+
* @tsplus getter fncts.schema.Schema optional
|
|
165
|
+
*/
|
|
166
|
+
function optional(self) {
|
|
167
|
+
return make_1(self.ast.clone({ annotations: self.ast.annotations.annotate(tsplus_module_4.Optional, true) }));
|
|
180
168
|
}
|
|
181
169
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
170
|
+
* @tsplus fluent fncts.schema.Schema isOptional
|
|
171
|
+
*/
|
|
184
172
|
function isOptional_1(self) {
|
|
185
|
-
|
|
173
|
+
return tsplus_module_7.getOrElse(() => false)(self.ast.annotations.get(tsplus_module_4.Optional));
|
|
186
174
|
}
|
|
187
175
|
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
annotations: self.ast.annotations.annotate(tsplus_module_4.ParseOptional, true)
|
|
193
|
-
}));
|
|
176
|
+
* @tsplus getter fncts.schema.Schema parseOptional
|
|
177
|
+
*/
|
|
178
|
+
function parseOptional(self) {
|
|
179
|
+
return make_1(self.ast.clone({ annotations: self.ast.annotations.annotate(tsplus_module_4.ParseOptional, true) }));
|
|
194
180
|
}
|
|
195
181
|
/**
|
|
196
|
-
|
|
197
|
-
|
|
182
|
+
* @tsplus fluent fncts.schema.Schema isParseOptional
|
|
183
|
+
*/
|
|
198
184
|
function isParseOptional_1(self) {
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return make_1(tsplus_module_3.createTuple(tsplus_module_2.empty(), tsplus_module_9.just(tsplus_module_2.vector(item.ast), fileName_1 + ":357:61"), false));
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* @tsplus static fncts.schema.SchemaOps record
|
|
272
|
-
*/
|
|
273
|
-
export function record(key, value) {
|
|
274
|
-
return make_1(tsplus_module_3.createRecord(key.ast, value.ast, true));
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* @tsplus static fncts.schema.SchemaOps enum
|
|
278
|
-
*/
|
|
185
|
+
return tsplus_module_7.getOrElse(() => false)(self.ast.annotations.get(tsplus_module_4.ParseOptional));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @tsplus static fncts.schema.SchemaOps struct
|
|
189
|
+
*/
|
|
190
|
+
function struct(fields) {
|
|
191
|
+
const parseOptionalKeys = tsplus_module_2.filter((key) => isParseOptional_1(fields[key]))(ownKeys(fields));
|
|
192
|
+
const struct = make_1(tsplus_module_3.createTypeLiteral(tsplus_module_2.map((key) => tsplus_module_3.createPropertySignature(key, fields[key].ast, isOptional_1(fields[key]), true))(ownKeys(fields)), tsplus_module_2.empty()));
|
|
193
|
+
if (tsplus_module_2.isEmpty(parseOptionalKeys)) return struct;
|
|
194
|
+
const propertySignatures = struct.ast.propertySignatures;
|
|
195
|
+
const from = make_1(tsplus_module_3.createTypeLiteral(tsplus_module_2.map((p) => tsplus_module_2.includes(p.name)(parseOptionalKeys) ? tsplus_module_3.createPropertySignature(p.name, tsplus_module_3.createUnion(tsplus_module_2.vector(tsplus_module_3.undefinedKeyword, tsplus_module_3.createLiteral(null), p.type)), true, p.isReadonly) : p)(propertySignatures), tsplus_module_2.empty()));
|
|
196
|
+
return transform_1(make_1(tsplus_module_3.createTypeLiteral(tsplus_module_2.map((p) => {
|
|
197
|
+
if (tsplus_module_2.includes(p.name)(parseOptionalKeys)) {
|
|
198
|
+
if (tsplus_module_3.isLazy(fields[p.name].ast)) return tsplus_module_3.createPropertySignature(p.name, tsplus_module_3.createLazy(() => tsplus_module_8.maybe(fields[p.name]).ast), true, p.isReadonly);
|
|
199
|
+
return tsplus_module_3.createPropertySignature(p.name, tsplus_module_8.maybe(fields[p.name]).ast, true, p.isReadonly);
|
|
200
|
+
}
|
|
201
|
+
return p;
|
|
202
|
+
})(propertySignatures), tsplus_module_2.empty())), (input) => {
|
|
203
|
+
const output = { ...input };
|
|
204
|
+
for (const key of parseOptionalKeys) output[key] = tsplus_module_9.fromNullable(input[key]);
|
|
205
|
+
return output;
|
|
206
|
+
}, (input) => {
|
|
207
|
+
const output = { ...input };
|
|
208
|
+
for (const key of parseOptionalKeys) {
|
|
209
|
+
const value = input[key];
|
|
210
|
+
if (tsplus_module_10.isNothing(value)) {
|
|
211
|
+
delete output[key];
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
output[key] = tsplus_module_7.toUndefined(value);
|
|
215
|
+
}
|
|
216
|
+
return output;
|
|
217
|
+
})(from);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @tsplus static fncts.schema.SchemaOps tuple
|
|
221
|
+
*/
|
|
222
|
+
function tuple(...elements) {
|
|
223
|
+
return make_1(tsplus_module_3.createTuple(tsplus_module_2.from(elements.map((schema) => tsplus_module_3.createElement(schema.ast, false))), tsplus_module_9.nothing(fileName_1 + ":333:105"), true));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* @tsplus static fncts.schema.SchemaOps lazy
|
|
227
|
+
*/
|
|
228
|
+
function lazy(f, annotations) {
|
|
229
|
+
return make_1(tsplus_module_3.createLazy(() => f().ast, annotations));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @tsplus static fncts.schema.SchemaOps array
|
|
233
|
+
* @tsplus getter fncts.schema.Schema array
|
|
234
|
+
*/
|
|
235
|
+
function array(item) {
|
|
236
|
+
return make_1(tsplus_module_3.createTuple(tsplus_module_2.empty(), tsplus_module_9.just(tsplus_module_2.vector(item.ast), fileName_1 + ":349:61"), true));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @tsplus static fncts.schema.SchemaOps mutableArray
|
|
240
|
+
* @tsplus getter fncts.schema.Schema mutableArray
|
|
241
|
+
*/
|
|
242
|
+
function mutableArray(item) {
|
|
243
|
+
return make_1(tsplus_module_3.createTuple(tsplus_module_2.empty(), tsplus_module_9.just(tsplus_module_2.vector(item.ast), fileName_1 + ":357:61"), false));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @tsplus static fncts.schema.SchemaOps record
|
|
247
|
+
*/
|
|
248
|
+
function record(key, value) {
|
|
249
|
+
return make_1(tsplus_module_3.createRecord(key.ast, value.ast, true));
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @tsplus static fncts.schema.SchemaOps enum
|
|
253
|
+
*/
|
|
279
254
|
function enum_1(enums) {
|
|
280
|
-
|
|
255
|
+
return make_1(tsplus_module_3.createEnum(tsplus_module_2.from(Object.keys(enums).filter((key) => typeof enums[enums[key]] !== "number").map((key) => [key, enums[key]]))));
|
|
281
256
|
}
|
|
282
|
-
export { enum_1 as enum };
|
|
283
257
|
function getTemplateLiterals(ast) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
case 18 /* ASTTag.Union */:
|
|
292
|
-
return tsplus_module_2.flatMap(getTemplateLiterals)(ast.types);
|
|
293
|
-
default:
|
|
294
|
-
throw new Error(`Unsupported template literal span ${show(ast)}`);
|
|
295
|
-
}
|
|
258
|
+
switch (ast._tag) {
|
|
259
|
+
case 1: return tsplus_module_2.vector(ast);
|
|
260
|
+
case 9:
|
|
261
|
+
case 8: return tsplus_module_2.vector(tsplus_module_3.createTemplateLiteral("", tsplus_module_2.vector(new TemplateLiteralSpan(ast, ""))));
|
|
262
|
+
case 18: return tsplus_module_2.flatMap(getTemplateLiterals)(ast.types);
|
|
263
|
+
default: throw new Error(`Unsupported template literal span ${show(ast)}`);
|
|
264
|
+
}
|
|
296
265
|
}
|
|
297
266
|
function combineTemplateLiterals(a, b) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return make_1(tsplus_module_3.createUnion(types));
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* @tsplus static fncts.schema.SchemaOps keyof
|
|
326
|
-
* @tsplus getter fncts.schema.Schema keyof
|
|
327
|
-
*/
|
|
328
|
-
export function keyof(self) {
|
|
329
|
-
return make_1(tsplus_module_3.keyof(self.ast));
|
|
267
|
+
if (tsplus_module_3.isLiteral(a)) return tsplus_module_3.isLiteral(b) ? tsplus_module_3.createLiteral(String(a.literal) + String(b.literal)) : tsplus_module_3.createTemplateLiteral(String(a.literal) + b.head, b.spans);
|
|
268
|
+
if (tsplus_module_3.isLiteral(b)) {
|
|
269
|
+
if (!tsplus_module_2.isNonEmpty(a.spans)) throw new Error("Invalid template literal");
|
|
270
|
+
const last = tsplus_module_2.unsafeLast(a.spans);
|
|
271
|
+
return tsplus_module_3.createTemplateLiteral(a.head, tsplus_module_2.append(new TemplateLiteralSpan(last.type, last.literal + String(b.literal)))(tsplus_module_2.slice(0, -1)(a.spans)));
|
|
272
|
+
}
|
|
273
|
+
if (!tsplus_module_2.isNonEmpty(a.spans)) throw new Error("Invalid template literal");
|
|
274
|
+
const last = tsplus_module_2.unsafeLast(a.spans);
|
|
275
|
+
return tsplus_module_3.createTemplateLiteral(a.head, tsplus_module_2.concat(b.spans)(tsplus_module_2.append(new TemplateLiteralSpan(last.type, last.literal + String(b.head)))(tsplus_module_2.slice(0, -1)(a.spans))));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @tsplus static fncts.schema.SchemaOps templateLiteral
|
|
279
|
+
*/
|
|
280
|
+
function templateLiteral(...[head, ...tail]) {
|
|
281
|
+
let types = getTemplateLiterals(head.ast);
|
|
282
|
+
for (const span of tail) types = tsplus_module_2.flatMap((a) => tsplus_module_2.map((b) => combineTemplateLiterals(a, b))(getTemplateLiterals(span.ast)))(types);
|
|
283
|
+
return make_1(tsplus_module_3.createUnion(types));
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* @tsplus static fncts.schema.SchemaOps keyof
|
|
287
|
+
* @tsplus getter fncts.schema.Schema keyof
|
|
288
|
+
*/
|
|
289
|
+
function keyof(self) {
|
|
290
|
+
return make_1(tsplus_module_3.keyof(self.ast));
|
|
330
291
|
}
|
|
331
292
|
function isOverlappingPropertySignatures(x, y) {
|
|
332
|
-
|
|
293
|
+
return tsplus_module_2.some((px) => tsplus_module_2.some((py) => px.name === py.name)(y.propertySignatures))(x.propertySignatures);
|
|
333
294
|
}
|
|
334
295
|
function isOverlappingIndexSignatures(x, y) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
throw new Error("`extend can only handle type literals or unions of type literals`");
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* @tsplus pipeable fncts.schema.Schema instanceOf
|
|
364
|
-
*/
|
|
296
|
+
return tsplus_module_2.some((ix) => tsplus_module_2.some((iy) => {
|
|
297
|
+
const bx = getParameter(ix.parameter);
|
|
298
|
+
const by = getParameter(iy.parameter);
|
|
299
|
+
return tsplus_module_3.isStringKeyword(bx) && tsplus_module_3.isStringKeyword(by) || tsplus_module_3.isSymbolKeyword(bx) && tsplus_module_3.isSymbolKeyword(by);
|
|
300
|
+
})(y.indexSignatures))(x.indexSignatures);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @tsplus pipeable fncts.schema.Schema extend
|
|
304
|
+
*/
|
|
305
|
+
function extend(that) {
|
|
306
|
+
return (self) => {
|
|
307
|
+
const selfTypes = tsplus_module_3.isUnion(self.ast) ? self.ast.types : tsplus_module_2.vector(self.ast);
|
|
308
|
+
const thatTypes = tsplus_module_3.isUnion(that.ast) ? that.ast.types : tsplus_module_2.vector(that.ast);
|
|
309
|
+
if (tsplus_module_2.every(tsplus_module_3.isTypeLiteral)(selfTypes) && tsplus_module_2.every(tsplus_module_3.isTypeLiteral)(thatTypes)) return make_1(tsplus_module_3.createUnion(tsplus_module_2.flatMap((x) => tsplus_module_2.map((y) => {
|
|
310
|
+
if (isOverlappingPropertySignatures(x, y)) throw new Error("`extend` cannot handle overlapping property signatures");
|
|
311
|
+
if (isOverlappingIndexSignatures(x, y)) throw new Error("`extend` cannot handle overlapping index signatures");
|
|
312
|
+
return tsplus_module_3.createTypeLiteral(tsplus_module_2.concat(y.propertySignatures)(x.propertySignatures), tsplus_module_2.concat(y.indexSignatures)(x.indexSignatures));
|
|
313
|
+
})(thatTypes))(selfTypes)));
|
|
314
|
+
throw new Error("`extend can only handle type literals or unions of type literals`");
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @tsplus pipeable fncts.schema.Schema instanceOf
|
|
319
|
+
*/
|
|
365
320
|
function instanceOf_1(constructor) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
321
|
+
return (self) => {
|
|
322
|
+
return annotate_1(tsplus_module_4.Description, `an instance of ${constructor.name}`)(filter_1((value) => value instanceof constructor)(self));
|
|
323
|
+
};
|
|
369
324
|
}
|
|
370
325
|
/**
|
|
371
|
-
|
|
372
|
-
|
|
326
|
+
* @tsplus pipeable fncts.schema.Schema transformOrFail
|
|
327
|
+
*/
|
|
373
328
|
function transformOrFail_1(to, decode, encode) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
329
|
+
return (from) => {
|
|
330
|
+
return make_1(tsplus_module_3.createTransform(from.ast, to.ast, decode, encode));
|
|
331
|
+
};
|
|
377
332
|
}
|
|
378
333
|
/**
|
|
379
|
-
|
|
380
|
-
|
|
334
|
+
* @tsplus pipeable fncts.schema.Schema transform
|
|
335
|
+
*/
|
|
381
336
|
function transform_1(to, decode, encode) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
337
|
+
return (from) => {
|
|
338
|
+
return transformOrFail_1(to, (input, options) => tsplus_module_5.succeed(decode(input, options)), (input, options) => tsplus_module_5.succeed(encode(input, options)))(from);
|
|
339
|
+
};
|
|
385
340
|
}
|
|
386
341
|
/**
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
342
|
+
* @tsplus pipeable fncts.schema.Schema pick
|
|
343
|
+
*/
|
|
344
|
+
function pick(...keys) {
|
|
345
|
+
return (self) => {
|
|
346
|
+
return make_1(tsplus_module_3.pick(tsplus_module_2.from(keys))(self.ast));
|
|
347
|
+
};
|
|
393
348
|
}
|
|
394
349
|
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
350
|
+
* @tsplus pipeable fncts.schema.Schema omit
|
|
351
|
+
*/
|
|
352
|
+
function omit(...keys) {
|
|
353
|
+
return (self) => {
|
|
354
|
+
return make_1(tsplus_module_3.omit(tsplus_module_2.from(keys))(self.ast));
|
|
355
|
+
};
|
|
401
356
|
}
|
|
357
|
+
//#endregion
|
|
358
|
+
export { _null, _undefined, _void, annotate, any, array, bigint, boolean, brand, date, declaration, enum_1 as enum, enum_, extend, filter, implicitDate, instanceOf, isOptional, isParseOptional, keyof, lazy, literal, make, mutableArray, never, _null_1 as null, nullable, number, object, omit, optional, parseOptional, pick, record, string, struct, symbol, templateLiteral, transform, transformOrFail, tuple, _undefined_1 as undefined, union, uniqueSymbol, unknown, _void_1 as void };
|
|
359
|
+
|
|
402
360
|
//# sourceMappingURL=api.mjs.map
|