@peninsula-med/beisen-ehr-plugin 1.0.6 → 1.1.1
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/README.md +79 -141
- package/dist/index.cjs.js +3704 -66
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -11
- package/dist/index.esm.js +3703 -64
- package/dist/index.esm.js.map +1 -1
- package/openclaw.plugin.json +36 -43
- package/package.json +3 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,3453 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Returns true if this value is an async iterator */
|
|
2
|
+
function IsAsyncIterator$2(value) {
|
|
3
|
+
return IsObject$2(value) && !IsArray$2(value) && !IsUint8Array$2(value) && Symbol.asyncIterator in value;
|
|
4
|
+
}
|
|
5
|
+
/** Returns true if this value is an array */
|
|
6
|
+
function IsArray$2(value) {
|
|
7
|
+
return Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
/** Returns true if this value is bigint */
|
|
10
|
+
function IsBigInt$2(value) {
|
|
11
|
+
return typeof value === 'bigint';
|
|
12
|
+
}
|
|
13
|
+
/** Returns true if this value is a boolean */
|
|
14
|
+
function IsBoolean$2(value) {
|
|
15
|
+
return typeof value === 'boolean';
|
|
16
|
+
}
|
|
17
|
+
/** Returns true if this value is a Date object */
|
|
18
|
+
function IsDate$2(value) {
|
|
19
|
+
return value instanceof globalThis.Date;
|
|
20
|
+
}
|
|
21
|
+
/** Returns true if this value is a function */
|
|
22
|
+
function IsFunction$2(value) {
|
|
23
|
+
return typeof value === 'function';
|
|
24
|
+
}
|
|
25
|
+
/** Returns true if this value is an iterator */
|
|
26
|
+
function IsIterator$2(value) {
|
|
27
|
+
return IsObject$2(value) && !IsArray$2(value) && !IsUint8Array$2(value) && Symbol.iterator in value;
|
|
28
|
+
}
|
|
29
|
+
/** Returns true if this value is null */
|
|
30
|
+
function IsNull$2(value) {
|
|
31
|
+
return value === null;
|
|
32
|
+
}
|
|
33
|
+
/** Returns true if this value is number */
|
|
34
|
+
function IsNumber$2(value) {
|
|
35
|
+
return typeof value === 'number';
|
|
36
|
+
}
|
|
37
|
+
/** Returns true if this value is an object */
|
|
38
|
+
function IsObject$2(value) {
|
|
39
|
+
return typeof value === 'object' && value !== null;
|
|
40
|
+
}
|
|
41
|
+
/** Returns true if this value is RegExp */
|
|
42
|
+
function IsRegExp$2(value) {
|
|
43
|
+
return value instanceof globalThis.RegExp;
|
|
44
|
+
}
|
|
45
|
+
/** Returns true if this value is string */
|
|
46
|
+
function IsString$2(value) {
|
|
47
|
+
return typeof value === 'string';
|
|
48
|
+
}
|
|
49
|
+
/** Returns true if this value is symbol */
|
|
50
|
+
function IsSymbol$2(value) {
|
|
51
|
+
return typeof value === 'symbol';
|
|
52
|
+
}
|
|
53
|
+
/** Returns true if this value is a Uint8Array */
|
|
54
|
+
function IsUint8Array$2(value) {
|
|
55
|
+
return value instanceof globalThis.Uint8Array;
|
|
56
|
+
}
|
|
57
|
+
/** Returns true if this value is undefined */
|
|
58
|
+
function IsUndefined$2(value) {
|
|
59
|
+
return value === undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function ArrayType(value) {
|
|
63
|
+
return value.map((value) => Visit$2(value));
|
|
64
|
+
}
|
|
65
|
+
function DateType(value) {
|
|
66
|
+
return new Date(value.getTime());
|
|
67
|
+
}
|
|
68
|
+
function Uint8ArrayType(value) {
|
|
69
|
+
return new Uint8Array(value);
|
|
70
|
+
}
|
|
71
|
+
function RegExpType(value) {
|
|
72
|
+
return new RegExp(value.source, value.flags);
|
|
73
|
+
}
|
|
74
|
+
function ObjectType(value) {
|
|
75
|
+
const result = {};
|
|
76
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
77
|
+
result[key] = Visit$2(value[key]);
|
|
78
|
+
}
|
|
79
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
80
|
+
result[key] = Visit$2(value[key]);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
// prettier-ignore
|
|
85
|
+
function Visit$2(value) {
|
|
86
|
+
return (IsArray$2(value) ? ArrayType(value) :
|
|
87
|
+
IsDate$2(value) ? DateType(value) :
|
|
88
|
+
IsUint8Array$2(value) ? Uint8ArrayType(value) :
|
|
89
|
+
IsRegExp$2(value) ? RegExpType(value) :
|
|
90
|
+
IsObject$2(value) ? ObjectType(value) :
|
|
91
|
+
value);
|
|
92
|
+
}
|
|
93
|
+
/** Clones a value */
|
|
94
|
+
function Clone(value) {
|
|
95
|
+
return Visit$2(value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Clones a Rest */
|
|
99
|
+
function CloneRest(schemas) {
|
|
100
|
+
return schemas.map((schema) => CloneType(schema));
|
|
101
|
+
}
|
|
102
|
+
/** Clones a Type */
|
|
103
|
+
function CloneType(schema, options = {}) {
|
|
104
|
+
return { ...Clone(schema), ...options };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The base Error type thrown for all TypeBox exceptions */
|
|
108
|
+
class TypeBoxError extends Error {
|
|
109
|
+
constructor(message) {
|
|
110
|
+
super(message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Symbol key applied to transform types */
|
|
115
|
+
const TransformKind = Symbol.for('TypeBox.Transform');
|
|
116
|
+
/** Symbol key applied to readonly types */
|
|
117
|
+
const ReadonlyKind = Symbol.for('TypeBox.Readonly');
|
|
118
|
+
/** Symbol key applied to optional types */
|
|
119
|
+
const OptionalKind = Symbol.for('TypeBox.Optional');
|
|
120
|
+
/** Symbol key applied to types */
|
|
121
|
+
const Hint = Symbol.for('TypeBox.Hint');
|
|
122
|
+
/** Symbol key applied to types */
|
|
123
|
+
const Kind = Symbol.for('TypeBox.Kind');
|
|
124
|
+
|
|
125
|
+
/** `[Kind-Only]` Returns true if this value has a Readonly symbol */
|
|
126
|
+
function IsReadonly(value) {
|
|
127
|
+
return IsObject$2(value) && value[ReadonlyKind] === 'Readonly';
|
|
128
|
+
}
|
|
129
|
+
/** `[Kind-Only]` Returns true if this value has a Optional symbol */
|
|
130
|
+
function IsOptional$1(value) {
|
|
131
|
+
return IsObject$2(value) && value[OptionalKind] === 'Optional';
|
|
132
|
+
}
|
|
133
|
+
/** `[Kind-Only]` Returns true if the given value is TAny */
|
|
134
|
+
function IsAny$1(value) {
|
|
135
|
+
return IsKindOf$1(value, 'Any');
|
|
136
|
+
}
|
|
137
|
+
/** `[Kind-Only]` Returns true if the given value is TArray */
|
|
138
|
+
function IsArray$1(value) {
|
|
139
|
+
return IsKindOf$1(value, 'Array');
|
|
140
|
+
}
|
|
141
|
+
/** `[Kind-Only]` Returns true if the given value is TAsyncIterator */
|
|
142
|
+
function IsAsyncIterator$1(value) {
|
|
143
|
+
return IsKindOf$1(value, 'AsyncIterator');
|
|
144
|
+
}
|
|
145
|
+
/** `[Kind-Only]` Returns true if the given value is TBigInt */
|
|
146
|
+
function IsBigInt$1(value) {
|
|
147
|
+
return IsKindOf$1(value, 'BigInt');
|
|
148
|
+
}
|
|
149
|
+
/** `[Kind-Only]` Returns true if the given value is TBoolean */
|
|
150
|
+
function IsBoolean$1(value) {
|
|
151
|
+
return IsKindOf$1(value, 'Boolean');
|
|
152
|
+
}
|
|
153
|
+
/** `[Kind-Only]` Returns true if the given value is TConstructor */
|
|
154
|
+
function IsConstructor$1(value) {
|
|
155
|
+
return IsKindOf$1(value, 'Constructor');
|
|
156
|
+
}
|
|
157
|
+
/** `[Kind-Only]` Returns true if the given value is TDate */
|
|
158
|
+
function IsDate$1(value) {
|
|
159
|
+
return IsKindOf$1(value, 'Date');
|
|
160
|
+
}
|
|
161
|
+
/** `[Kind-Only]` Returns true if the given value is TFunction */
|
|
162
|
+
function IsFunction$1(value) {
|
|
163
|
+
return IsKindOf$1(value, 'Function');
|
|
164
|
+
}
|
|
165
|
+
/** `[Kind-Only]` Returns true if the given value is TInteger */
|
|
166
|
+
function IsInteger$1(value) {
|
|
167
|
+
return IsKindOf$1(value, 'Integer');
|
|
168
|
+
}
|
|
169
|
+
/** `[Kind-Only]` Returns true if the given value is TIntersect */
|
|
170
|
+
function IsIntersect$1(value) {
|
|
171
|
+
return IsKindOf$1(value, 'Intersect');
|
|
172
|
+
}
|
|
173
|
+
/** `[Kind-Only]` Returns true if the given value is TIterator */
|
|
174
|
+
function IsIterator$1(value) {
|
|
175
|
+
return IsKindOf$1(value, 'Iterator');
|
|
176
|
+
}
|
|
177
|
+
/** `[Kind-Only]` Returns true if the given value is a TKind with the given name. */
|
|
178
|
+
function IsKindOf$1(value, kind) {
|
|
179
|
+
return IsObject$2(value) && Kind in value && value[Kind] === kind;
|
|
180
|
+
}
|
|
181
|
+
/** `[Kind-Only]` Returns true if the given value is TLiteral */
|
|
182
|
+
function IsLiteral$1(value) {
|
|
183
|
+
return IsKindOf$1(value, 'Literal');
|
|
184
|
+
}
|
|
185
|
+
/** `[Kind-Only]` Returns true if the given value is a TMappedKey */
|
|
186
|
+
function IsMappedKey$1(value) {
|
|
187
|
+
return IsKindOf$1(value, 'MappedKey');
|
|
188
|
+
}
|
|
189
|
+
/** `[Kind-Only]` Returns true if the given value is TMappedResult */
|
|
190
|
+
function IsMappedResult$1(value) {
|
|
191
|
+
return IsKindOf$1(value, 'MappedResult');
|
|
192
|
+
}
|
|
193
|
+
/** `[Kind-Only]` Returns true if the given value is TNever */
|
|
194
|
+
function IsNever$1(value) {
|
|
195
|
+
return IsKindOf$1(value, 'Never');
|
|
196
|
+
}
|
|
197
|
+
/** `[Kind-Only]` Returns true if the given value is TNot */
|
|
198
|
+
function IsNot$1(value) {
|
|
199
|
+
return IsKindOf$1(value, 'Not');
|
|
200
|
+
}
|
|
201
|
+
/** `[Kind-Only]` Returns true if the given value is TNull */
|
|
202
|
+
function IsNull$1(value) {
|
|
203
|
+
return IsKindOf$1(value, 'Null');
|
|
204
|
+
}
|
|
205
|
+
/** `[Kind-Only]` Returns true if the given value is TNumber */
|
|
206
|
+
function IsNumber$1(value) {
|
|
207
|
+
return IsKindOf$1(value, 'Number');
|
|
208
|
+
}
|
|
209
|
+
/** `[Kind-Only]` Returns true if the given value is TObject */
|
|
210
|
+
function IsObject$1(value) {
|
|
211
|
+
return IsKindOf$1(value, 'Object');
|
|
212
|
+
}
|
|
213
|
+
/** `[Kind-Only]` Returns true if the given value is TPromise */
|
|
214
|
+
function IsPromise$1(value) {
|
|
215
|
+
return IsKindOf$1(value, 'Promise');
|
|
216
|
+
}
|
|
217
|
+
/** `[Kind-Only]` Returns true if the given value is TRecord */
|
|
218
|
+
function IsRecord$1(value) {
|
|
219
|
+
return IsKindOf$1(value, 'Record');
|
|
220
|
+
}
|
|
221
|
+
/** `[Kind-Only]` Returns true if the given value is TRef */
|
|
222
|
+
function IsRef$1(value) {
|
|
223
|
+
return IsKindOf$1(value, 'Ref');
|
|
224
|
+
}
|
|
225
|
+
/** `[Kind-Only]` Returns true if the given value is TRegExp */
|
|
226
|
+
function IsRegExp$1(value) {
|
|
227
|
+
return IsKindOf$1(value, 'RegExp');
|
|
228
|
+
}
|
|
229
|
+
/** `[Kind-Only]` Returns true if the given value is TString */
|
|
230
|
+
function IsString$1(value) {
|
|
231
|
+
return IsKindOf$1(value, 'String');
|
|
232
|
+
}
|
|
233
|
+
/** `[Kind-Only]` Returns true if the given value is TSymbol */
|
|
234
|
+
function IsSymbol$1(value) {
|
|
235
|
+
return IsKindOf$1(value, 'Symbol');
|
|
236
|
+
}
|
|
237
|
+
/** `[Kind-Only]` Returns true if the given value is TTemplateLiteral */
|
|
238
|
+
function IsTemplateLiteral$1(value) {
|
|
239
|
+
return IsKindOf$1(value, 'TemplateLiteral');
|
|
240
|
+
}
|
|
241
|
+
/** `[Kind-Only]` Returns true if the given value is TThis */
|
|
242
|
+
function IsThis$1(value) {
|
|
243
|
+
return IsKindOf$1(value, 'This');
|
|
244
|
+
}
|
|
245
|
+
/** `[Kind-Only]` Returns true of this value is TTransform */
|
|
246
|
+
function IsTransform$1(value) {
|
|
247
|
+
return IsObject$2(value) && TransformKind in value;
|
|
248
|
+
}
|
|
249
|
+
/** `[Kind-Only]` Returns true if the given value is TTuple */
|
|
250
|
+
function IsTuple$1(value) {
|
|
251
|
+
return IsKindOf$1(value, 'Tuple');
|
|
252
|
+
}
|
|
253
|
+
/** `[Kind-Only]` Returns true if the given value is TUndefined */
|
|
254
|
+
function IsUndefined$1(value) {
|
|
255
|
+
return IsKindOf$1(value, 'Undefined');
|
|
256
|
+
}
|
|
257
|
+
/** `[Kind-Only]` Returns true if the given value is TUnion */
|
|
258
|
+
function IsUnion$1(value) {
|
|
259
|
+
return IsKindOf$1(value, 'Union');
|
|
260
|
+
}
|
|
261
|
+
/** `[Kind-Only]` Returns true if the given value is TUint8Array */
|
|
262
|
+
function IsUint8Array$1(value) {
|
|
263
|
+
return IsKindOf$1(value, 'Uint8Array');
|
|
264
|
+
}
|
|
265
|
+
/** `[Kind-Only]` Returns true if the given value is TUnknown */
|
|
266
|
+
function IsUnknown$1(value) {
|
|
267
|
+
return IsKindOf$1(value, 'Unknown');
|
|
268
|
+
}
|
|
269
|
+
/** `[Kind-Only]` Returns true if the given value is a raw TUnsafe */
|
|
270
|
+
function IsUnsafe$1(value) {
|
|
271
|
+
return IsKindOf$1(value, 'Unsafe');
|
|
272
|
+
}
|
|
273
|
+
/** `[Kind-Only]` Returns true if the given value is TVoid */
|
|
274
|
+
function IsVoid$1(value) {
|
|
275
|
+
return IsKindOf$1(value, 'Void');
|
|
276
|
+
}
|
|
277
|
+
/** `[Kind-Only]` Returns true if the given value is TKind */
|
|
278
|
+
function IsKind$1(value) {
|
|
279
|
+
return IsObject$2(value) && Kind in value && IsString$2(value[Kind]);
|
|
280
|
+
}
|
|
281
|
+
/** `[Kind-Only]` Returns true if the given value is TSchema */
|
|
282
|
+
function IsSchema$1(value) {
|
|
283
|
+
// prettier-ignore
|
|
284
|
+
return (IsAny$1(value) ||
|
|
285
|
+
IsArray$1(value) ||
|
|
286
|
+
IsBoolean$1(value) ||
|
|
287
|
+
IsBigInt$1(value) ||
|
|
288
|
+
IsAsyncIterator$1(value) ||
|
|
289
|
+
IsConstructor$1(value) ||
|
|
290
|
+
IsDate$1(value) ||
|
|
291
|
+
IsFunction$1(value) ||
|
|
292
|
+
IsInteger$1(value) ||
|
|
293
|
+
IsIntersect$1(value) ||
|
|
294
|
+
IsIterator$1(value) ||
|
|
295
|
+
IsLiteral$1(value) ||
|
|
296
|
+
IsMappedKey$1(value) ||
|
|
297
|
+
IsMappedResult$1(value) ||
|
|
298
|
+
IsNever$1(value) ||
|
|
299
|
+
IsNot$1(value) ||
|
|
300
|
+
IsNull$1(value) ||
|
|
301
|
+
IsNumber$1(value) ||
|
|
302
|
+
IsObject$1(value) ||
|
|
303
|
+
IsPromise$1(value) ||
|
|
304
|
+
IsRecord$1(value) ||
|
|
305
|
+
IsRef$1(value) ||
|
|
306
|
+
IsRegExp$1(value) ||
|
|
307
|
+
IsString$1(value) ||
|
|
308
|
+
IsSymbol$1(value) ||
|
|
309
|
+
IsTemplateLiteral$1(value) ||
|
|
310
|
+
IsThis$1(value) ||
|
|
311
|
+
IsTuple$1(value) ||
|
|
312
|
+
IsUndefined$1(value) ||
|
|
313
|
+
IsUnion$1(value) ||
|
|
314
|
+
IsUint8Array$1(value) ||
|
|
315
|
+
IsUnknown$1(value) ||
|
|
316
|
+
IsUnsafe$1(value) ||
|
|
317
|
+
IsVoid$1(value) ||
|
|
318
|
+
IsKind$1(value));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const KnownTypes = [
|
|
322
|
+
'Any',
|
|
323
|
+
'Array',
|
|
324
|
+
'AsyncIterator',
|
|
325
|
+
'BigInt',
|
|
326
|
+
'Boolean',
|
|
327
|
+
'Constructor',
|
|
328
|
+
'Date',
|
|
329
|
+
'Enum',
|
|
330
|
+
'Function',
|
|
331
|
+
'Integer',
|
|
332
|
+
'Intersect',
|
|
333
|
+
'Iterator',
|
|
334
|
+
'Literal',
|
|
335
|
+
'MappedKey',
|
|
336
|
+
'MappedResult',
|
|
337
|
+
'Not',
|
|
338
|
+
'Null',
|
|
339
|
+
'Number',
|
|
340
|
+
'Object',
|
|
341
|
+
'Promise',
|
|
342
|
+
'Record',
|
|
343
|
+
'Ref',
|
|
344
|
+
'RegExp',
|
|
345
|
+
'String',
|
|
346
|
+
'Symbol',
|
|
347
|
+
'TemplateLiteral',
|
|
348
|
+
'This',
|
|
349
|
+
'Tuple',
|
|
350
|
+
'Undefined',
|
|
351
|
+
'Union',
|
|
352
|
+
'Uint8Array',
|
|
353
|
+
'Unknown',
|
|
354
|
+
'Void',
|
|
355
|
+
];
|
|
356
|
+
function IsPattern(value) {
|
|
357
|
+
try {
|
|
358
|
+
new RegExp(value);
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function IsControlCharacterFree(value) {
|
|
366
|
+
if (!IsString$2(value))
|
|
367
|
+
return false;
|
|
368
|
+
for (let i = 0; i < value.length; i++) {
|
|
369
|
+
const code = value.charCodeAt(i);
|
|
370
|
+
if ((code >= 7 && code <= 13) || code === 27 || code === 127) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
function IsAdditionalProperties(value) {
|
|
377
|
+
return IsOptionalBoolean(value) || IsSchema(value);
|
|
378
|
+
}
|
|
379
|
+
function IsOptionalBigInt(value) {
|
|
380
|
+
return IsUndefined$2(value) || IsBigInt$2(value);
|
|
381
|
+
}
|
|
382
|
+
function IsOptionalNumber(value) {
|
|
383
|
+
return IsUndefined$2(value) || IsNumber$2(value);
|
|
384
|
+
}
|
|
385
|
+
function IsOptionalBoolean(value) {
|
|
386
|
+
return IsUndefined$2(value) || IsBoolean$2(value);
|
|
387
|
+
}
|
|
388
|
+
function IsOptionalString(value) {
|
|
389
|
+
return IsUndefined$2(value) || IsString$2(value);
|
|
390
|
+
}
|
|
391
|
+
function IsOptionalPattern(value) {
|
|
392
|
+
return IsUndefined$2(value) || (IsString$2(value) && IsControlCharacterFree(value) && IsPattern(value));
|
|
393
|
+
}
|
|
394
|
+
function IsOptionalFormat(value) {
|
|
395
|
+
return IsUndefined$2(value) || (IsString$2(value) && IsControlCharacterFree(value));
|
|
396
|
+
}
|
|
397
|
+
function IsOptionalSchema(value) {
|
|
398
|
+
return IsUndefined$2(value) || IsSchema(value);
|
|
399
|
+
}
|
|
400
|
+
/** Returns true if this value has a Optional symbol */
|
|
401
|
+
function IsOptional(value) {
|
|
402
|
+
return IsObject$2(value) && value[OptionalKind] === 'Optional';
|
|
403
|
+
}
|
|
404
|
+
// ------------------------------------------------------------------
|
|
405
|
+
// Types
|
|
406
|
+
// ------------------------------------------------------------------
|
|
407
|
+
/** Returns true if the given value is TAny */
|
|
408
|
+
function IsAny(value) {
|
|
409
|
+
// prettier-ignore
|
|
410
|
+
return (IsKindOf(value, 'Any') &&
|
|
411
|
+
IsOptionalString(value.$id));
|
|
412
|
+
}
|
|
413
|
+
/** Returns true if the given value is TArray */
|
|
414
|
+
function IsArray(value) {
|
|
415
|
+
return (IsKindOf(value, 'Array') &&
|
|
416
|
+
value.type === 'array' &&
|
|
417
|
+
IsOptionalString(value.$id) &&
|
|
418
|
+
IsSchema(value.items) &&
|
|
419
|
+
IsOptionalNumber(value.minItems) &&
|
|
420
|
+
IsOptionalNumber(value.maxItems) &&
|
|
421
|
+
IsOptionalBoolean(value.uniqueItems) &&
|
|
422
|
+
IsOptionalSchema(value.contains) &&
|
|
423
|
+
IsOptionalNumber(value.minContains) &&
|
|
424
|
+
IsOptionalNumber(value.maxContains));
|
|
425
|
+
}
|
|
426
|
+
/** Returns true if the given value is TAsyncIterator */
|
|
427
|
+
function IsAsyncIterator(value) {
|
|
428
|
+
// prettier-ignore
|
|
429
|
+
return (IsKindOf(value, 'AsyncIterator') &&
|
|
430
|
+
value.type === 'AsyncIterator' &&
|
|
431
|
+
IsOptionalString(value.$id) &&
|
|
432
|
+
IsSchema(value.items));
|
|
433
|
+
}
|
|
434
|
+
/** Returns true if the given value is TBigInt */
|
|
435
|
+
function IsBigInt(value) {
|
|
436
|
+
// prettier-ignore
|
|
437
|
+
return (IsKindOf(value, 'BigInt') &&
|
|
438
|
+
value.type === 'bigint' &&
|
|
439
|
+
IsOptionalString(value.$id) &&
|
|
440
|
+
IsOptionalBigInt(value.exclusiveMaximum) &&
|
|
441
|
+
IsOptionalBigInt(value.exclusiveMinimum) &&
|
|
442
|
+
IsOptionalBigInt(value.maximum) &&
|
|
443
|
+
IsOptionalBigInt(value.minimum) &&
|
|
444
|
+
IsOptionalBigInt(value.multipleOf));
|
|
445
|
+
}
|
|
446
|
+
/** Returns true if the given value is TBoolean */
|
|
447
|
+
function IsBoolean(value) {
|
|
448
|
+
// prettier-ignore
|
|
449
|
+
return (IsKindOf(value, 'Boolean') &&
|
|
450
|
+
value.type === 'boolean' &&
|
|
451
|
+
IsOptionalString(value.$id));
|
|
452
|
+
}
|
|
453
|
+
/** Returns true if the given value is TConstructor */
|
|
454
|
+
function IsConstructor(value) {
|
|
455
|
+
// prettier-ignore
|
|
456
|
+
return (IsKindOf(value, 'Constructor') &&
|
|
457
|
+
value.type === 'Constructor' &&
|
|
458
|
+
IsOptionalString(value.$id) &&
|
|
459
|
+
IsArray$2(value.parameters) &&
|
|
460
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
461
|
+
IsSchema(value.returns));
|
|
462
|
+
}
|
|
463
|
+
/** Returns true if the given value is TDate */
|
|
464
|
+
function IsDate(value) {
|
|
465
|
+
return (IsKindOf(value, 'Date') &&
|
|
466
|
+
value.type === 'Date' &&
|
|
467
|
+
IsOptionalString(value.$id) &&
|
|
468
|
+
IsOptionalNumber(value.exclusiveMaximumTimestamp) &&
|
|
469
|
+
IsOptionalNumber(value.exclusiveMinimumTimestamp) &&
|
|
470
|
+
IsOptionalNumber(value.maximumTimestamp) &&
|
|
471
|
+
IsOptionalNumber(value.minimumTimestamp) &&
|
|
472
|
+
IsOptionalNumber(value.multipleOfTimestamp));
|
|
473
|
+
}
|
|
474
|
+
/** Returns true if the given value is TFunction */
|
|
475
|
+
function IsFunction(value) {
|
|
476
|
+
// prettier-ignore
|
|
477
|
+
return (IsKindOf(value, 'Function') &&
|
|
478
|
+
value.type === 'Function' &&
|
|
479
|
+
IsOptionalString(value.$id) &&
|
|
480
|
+
IsArray$2(value.parameters) &&
|
|
481
|
+
value.parameters.every(schema => IsSchema(schema)) &&
|
|
482
|
+
IsSchema(value.returns));
|
|
483
|
+
}
|
|
484
|
+
/** Returns true if the given value is TInteger */
|
|
485
|
+
function IsInteger(value) {
|
|
486
|
+
return (IsKindOf(value, 'Integer') &&
|
|
487
|
+
value.type === 'integer' &&
|
|
488
|
+
IsOptionalString(value.$id) &&
|
|
489
|
+
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
490
|
+
IsOptionalNumber(value.exclusiveMinimum) &&
|
|
491
|
+
IsOptionalNumber(value.maximum) &&
|
|
492
|
+
IsOptionalNumber(value.minimum) &&
|
|
493
|
+
IsOptionalNumber(value.multipleOf));
|
|
494
|
+
}
|
|
495
|
+
/** Returns true if the given schema is TProperties */
|
|
496
|
+
function IsProperties(value) {
|
|
497
|
+
// prettier-ignore
|
|
498
|
+
return (IsObject$2(value) &&
|
|
499
|
+
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema(schema)));
|
|
500
|
+
}
|
|
501
|
+
/** Returns true if the given value is TIntersect */
|
|
502
|
+
function IsIntersect(value) {
|
|
503
|
+
// prettier-ignore
|
|
504
|
+
return (IsKindOf(value, 'Intersect') &&
|
|
505
|
+
(IsString$2(value.type) && value.type !== 'object' ? false : true) &&
|
|
506
|
+
IsArray$2(value.allOf) &&
|
|
507
|
+
value.allOf.every(schema => IsSchema(schema) && !IsTransform(schema)) &&
|
|
508
|
+
IsOptionalString(value.type) &&
|
|
509
|
+
(IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) &&
|
|
510
|
+
IsOptionalString(value.$id));
|
|
511
|
+
}
|
|
512
|
+
/** Returns true if the given value is TIterator */
|
|
513
|
+
function IsIterator(value) {
|
|
514
|
+
// prettier-ignore
|
|
515
|
+
return (IsKindOf(value, 'Iterator') &&
|
|
516
|
+
value.type === 'Iterator' &&
|
|
517
|
+
IsOptionalString(value.$id) &&
|
|
518
|
+
IsSchema(value.items));
|
|
519
|
+
}
|
|
520
|
+
/** Returns true if the given value is a TKind with the given name. */
|
|
521
|
+
function IsKindOf(value, kind) {
|
|
522
|
+
return IsObject$2(value) && Kind in value && value[Kind] === kind;
|
|
523
|
+
}
|
|
524
|
+
/** Returns true if the given value is TLiteral<string> */
|
|
525
|
+
function IsLiteralString(value) {
|
|
526
|
+
return IsLiteral(value) && IsString$2(value.const);
|
|
527
|
+
}
|
|
528
|
+
/** Returns true if the given value is TLiteral<number> */
|
|
529
|
+
function IsLiteralNumber(value) {
|
|
530
|
+
return IsLiteral(value) && IsNumber$2(value.const);
|
|
531
|
+
}
|
|
532
|
+
/** Returns true if the given value is TLiteral<boolean> */
|
|
533
|
+
function IsLiteralBoolean(value) {
|
|
534
|
+
return IsLiteral(value) && IsBoolean$2(value.const);
|
|
535
|
+
}
|
|
536
|
+
/** Returns true if the given value is TLiteral */
|
|
537
|
+
function IsLiteral(value) {
|
|
538
|
+
// prettier-ignore
|
|
539
|
+
return (IsKindOf(value, 'Literal') &&
|
|
540
|
+
IsOptionalString(value.$id) && IsLiteralValue(value.const));
|
|
541
|
+
}
|
|
542
|
+
/** Returns true if the given value is a TLiteralValue */
|
|
543
|
+
function IsLiteralValue(value) {
|
|
544
|
+
return IsBoolean$2(value) || IsNumber$2(value) || IsString$2(value);
|
|
545
|
+
}
|
|
546
|
+
/** Returns true if the given value is a TMappedKey */
|
|
547
|
+
function IsMappedKey(value) {
|
|
548
|
+
// prettier-ignore
|
|
549
|
+
return (IsKindOf(value, 'MappedKey') &&
|
|
550
|
+
IsArray$2(value.keys) &&
|
|
551
|
+
value.keys.every(key => IsNumber$2(key) || IsString$2(key)));
|
|
552
|
+
}
|
|
553
|
+
/** Returns true if the given value is TMappedResult */
|
|
554
|
+
function IsMappedResult(value) {
|
|
555
|
+
// prettier-ignore
|
|
556
|
+
return (IsKindOf(value, 'MappedResult') &&
|
|
557
|
+
IsProperties(value.properties));
|
|
558
|
+
}
|
|
559
|
+
/** Returns true if the given value is TNever */
|
|
560
|
+
function IsNever(value) {
|
|
561
|
+
// prettier-ignore
|
|
562
|
+
return (IsKindOf(value, 'Never') &&
|
|
563
|
+
IsObject$2(value.not) &&
|
|
564
|
+
Object.getOwnPropertyNames(value.not).length === 0);
|
|
565
|
+
}
|
|
566
|
+
/** Returns true if the given value is TNot */
|
|
567
|
+
function IsNot(value) {
|
|
568
|
+
// prettier-ignore
|
|
569
|
+
return (IsKindOf(value, 'Not') &&
|
|
570
|
+
IsSchema(value.not));
|
|
571
|
+
}
|
|
572
|
+
/** Returns true if the given value is TNull */
|
|
573
|
+
function IsNull(value) {
|
|
574
|
+
// prettier-ignore
|
|
575
|
+
return (IsKindOf(value, 'Null') &&
|
|
576
|
+
value.type === 'null' &&
|
|
577
|
+
IsOptionalString(value.$id));
|
|
578
|
+
}
|
|
579
|
+
/** Returns true if the given value is TNumber */
|
|
580
|
+
function IsNumber(value) {
|
|
581
|
+
return (IsKindOf(value, 'Number') &&
|
|
582
|
+
value.type === 'number' &&
|
|
583
|
+
IsOptionalString(value.$id) &&
|
|
584
|
+
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
585
|
+
IsOptionalNumber(value.exclusiveMinimum) &&
|
|
586
|
+
IsOptionalNumber(value.maximum) &&
|
|
587
|
+
IsOptionalNumber(value.minimum) &&
|
|
588
|
+
IsOptionalNumber(value.multipleOf));
|
|
589
|
+
}
|
|
590
|
+
/** Returns true if the given value is TObject */
|
|
591
|
+
function IsObject(value) {
|
|
592
|
+
// prettier-ignore
|
|
593
|
+
return (IsKindOf(value, 'Object') &&
|
|
594
|
+
value.type === 'object' &&
|
|
595
|
+
IsOptionalString(value.$id) &&
|
|
596
|
+
IsProperties(value.properties) &&
|
|
597
|
+
IsAdditionalProperties(value.additionalProperties) &&
|
|
598
|
+
IsOptionalNumber(value.minProperties) &&
|
|
599
|
+
IsOptionalNumber(value.maxProperties));
|
|
600
|
+
}
|
|
601
|
+
/** Returns true if the given value is TPromise */
|
|
602
|
+
function IsPromise(value) {
|
|
603
|
+
// prettier-ignore
|
|
604
|
+
return (IsKindOf(value, 'Promise') &&
|
|
605
|
+
value.type === 'Promise' &&
|
|
606
|
+
IsOptionalString(value.$id) &&
|
|
607
|
+
IsSchema(value.item));
|
|
608
|
+
}
|
|
609
|
+
/** Returns true if the given value is TRecord */
|
|
610
|
+
function IsRecord(value) {
|
|
611
|
+
// prettier-ignore
|
|
612
|
+
return (IsKindOf(value, 'Record') &&
|
|
613
|
+
value.type === 'object' &&
|
|
614
|
+
IsOptionalString(value.$id) &&
|
|
615
|
+
IsAdditionalProperties(value.additionalProperties) &&
|
|
616
|
+
IsObject$2(value.patternProperties) &&
|
|
617
|
+
((schema) => {
|
|
618
|
+
const keys = Object.getOwnPropertyNames(schema.patternProperties);
|
|
619
|
+
return (keys.length === 1 &&
|
|
620
|
+
IsPattern(keys[0]) &&
|
|
621
|
+
IsObject$2(schema.patternProperties) &&
|
|
622
|
+
IsSchema(schema.patternProperties[keys[0]]));
|
|
623
|
+
})(value));
|
|
624
|
+
}
|
|
625
|
+
/** Returns true if the given value is TRef */
|
|
626
|
+
function IsRef(value) {
|
|
627
|
+
// prettier-ignore
|
|
628
|
+
return (IsKindOf(value, 'Ref') &&
|
|
629
|
+
IsOptionalString(value.$id) &&
|
|
630
|
+
IsString$2(value.$ref));
|
|
631
|
+
}
|
|
632
|
+
/** Returns true if the given value is TRegExp */
|
|
633
|
+
function IsRegExp(value) {
|
|
634
|
+
// prettier-ignore
|
|
635
|
+
return (IsKindOf(value, 'RegExp') &&
|
|
636
|
+
IsOptionalString(value.$id) &&
|
|
637
|
+
IsString$2(value.source) &&
|
|
638
|
+
IsString$2(value.flags) &&
|
|
639
|
+
IsOptionalNumber(value.maxLength) &&
|
|
640
|
+
IsOptionalNumber(value.minLength));
|
|
641
|
+
}
|
|
642
|
+
/** Returns true if the given value is TString */
|
|
643
|
+
function IsString(value) {
|
|
644
|
+
// prettier-ignore
|
|
645
|
+
return (IsKindOf(value, 'String') &&
|
|
646
|
+
value.type === 'string' &&
|
|
647
|
+
IsOptionalString(value.$id) &&
|
|
648
|
+
IsOptionalNumber(value.minLength) &&
|
|
649
|
+
IsOptionalNumber(value.maxLength) &&
|
|
650
|
+
IsOptionalPattern(value.pattern) &&
|
|
651
|
+
IsOptionalFormat(value.format));
|
|
652
|
+
}
|
|
653
|
+
/** Returns true if the given value is TSymbol */
|
|
654
|
+
function IsSymbol(value) {
|
|
655
|
+
// prettier-ignore
|
|
656
|
+
return (IsKindOf(value, 'Symbol') &&
|
|
657
|
+
value.type === 'symbol' &&
|
|
658
|
+
IsOptionalString(value.$id));
|
|
659
|
+
}
|
|
660
|
+
/** Returns true if the given value is TTemplateLiteral */
|
|
661
|
+
function IsTemplateLiteral(value) {
|
|
662
|
+
// prettier-ignore
|
|
663
|
+
return (IsKindOf(value, 'TemplateLiteral') &&
|
|
664
|
+
value.type === 'string' &&
|
|
665
|
+
IsString$2(value.pattern) &&
|
|
666
|
+
value.pattern[0] === '^' &&
|
|
667
|
+
value.pattern[value.pattern.length - 1] === '$');
|
|
668
|
+
}
|
|
669
|
+
/** Returns true if the given value is TThis */
|
|
670
|
+
function IsThis(value) {
|
|
671
|
+
// prettier-ignore
|
|
672
|
+
return (IsKindOf(value, 'This') &&
|
|
673
|
+
IsOptionalString(value.$id) &&
|
|
674
|
+
IsString$2(value.$ref));
|
|
675
|
+
}
|
|
676
|
+
/** Returns true of this value is TTransform */
|
|
677
|
+
function IsTransform(value) {
|
|
678
|
+
return IsObject$2(value) && TransformKind in value;
|
|
679
|
+
}
|
|
680
|
+
/** Returns true if the given value is TTuple */
|
|
681
|
+
function IsTuple(value) {
|
|
682
|
+
// prettier-ignore
|
|
683
|
+
return (IsKindOf(value, 'Tuple') &&
|
|
684
|
+
value.type === 'array' &&
|
|
685
|
+
IsOptionalString(value.$id) &&
|
|
686
|
+
IsNumber$2(value.minItems) &&
|
|
687
|
+
IsNumber$2(value.maxItems) &&
|
|
688
|
+
value.minItems === value.maxItems &&
|
|
689
|
+
(( // empty
|
|
690
|
+
IsUndefined$2(value.items) &&
|
|
691
|
+
IsUndefined$2(value.additionalItems) &&
|
|
692
|
+
value.minItems === 0) || (IsArray$2(value.items) &&
|
|
693
|
+
value.items.every(schema => IsSchema(schema)))));
|
|
694
|
+
}
|
|
695
|
+
/** Returns true if the given value is TUndefined */
|
|
696
|
+
function IsUndefined(value) {
|
|
697
|
+
// prettier-ignore
|
|
698
|
+
return (IsKindOf(value, 'Undefined') &&
|
|
699
|
+
value.type === 'undefined' &&
|
|
700
|
+
IsOptionalString(value.$id));
|
|
701
|
+
}
|
|
702
|
+
/** Returns true if the given value is TUnion */
|
|
703
|
+
function IsUnion(value) {
|
|
704
|
+
// prettier-ignore
|
|
705
|
+
return (IsKindOf(value, 'Union') &&
|
|
706
|
+
IsOptionalString(value.$id) &&
|
|
707
|
+
IsObject$2(value) &&
|
|
708
|
+
IsArray$2(value.anyOf) &&
|
|
709
|
+
value.anyOf.every(schema => IsSchema(schema)));
|
|
710
|
+
}
|
|
711
|
+
/** Returns true if the given value is TUint8Array */
|
|
712
|
+
function IsUint8Array(value) {
|
|
713
|
+
// prettier-ignore
|
|
714
|
+
return (IsKindOf(value, 'Uint8Array') &&
|
|
715
|
+
value.type === 'Uint8Array' &&
|
|
716
|
+
IsOptionalString(value.$id) &&
|
|
717
|
+
IsOptionalNumber(value.minByteLength) &&
|
|
718
|
+
IsOptionalNumber(value.maxByteLength));
|
|
719
|
+
}
|
|
720
|
+
/** Returns true if the given value is TUnknown */
|
|
721
|
+
function IsUnknown(value) {
|
|
722
|
+
// prettier-ignore
|
|
723
|
+
return (IsKindOf(value, 'Unknown') &&
|
|
724
|
+
IsOptionalString(value.$id));
|
|
725
|
+
}
|
|
726
|
+
/** Returns true if the given value is a raw TUnsafe */
|
|
727
|
+
function IsUnsafe(value) {
|
|
728
|
+
return IsKindOf(value, 'Unsafe');
|
|
729
|
+
}
|
|
730
|
+
/** Returns true if the given value is TVoid */
|
|
731
|
+
function IsVoid(value) {
|
|
732
|
+
// prettier-ignore
|
|
733
|
+
return (IsKindOf(value, 'Void') &&
|
|
734
|
+
value.type === 'void' &&
|
|
735
|
+
IsOptionalString(value.$id));
|
|
736
|
+
}
|
|
737
|
+
/** Returns true if the given value is TKind */
|
|
738
|
+
function IsKind(value) {
|
|
739
|
+
return IsObject$2(value) && Kind in value && IsString$2(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
740
|
+
}
|
|
741
|
+
/** Returns true if the given value is TSchema */
|
|
742
|
+
function IsSchema(value) {
|
|
743
|
+
// prettier-ignore
|
|
744
|
+
return (IsObject$2(value)) && (IsAny(value) ||
|
|
745
|
+
IsArray(value) ||
|
|
746
|
+
IsBoolean(value) ||
|
|
747
|
+
IsBigInt(value) ||
|
|
748
|
+
IsAsyncIterator(value) ||
|
|
749
|
+
IsConstructor(value) ||
|
|
750
|
+
IsDate(value) ||
|
|
751
|
+
IsFunction(value) ||
|
|
752
|
+
IsInteger(value) ||
|
|
753
|
+
IsIntersect(value) ||
|
|
754
|
+
IsIterator(value) ||
|
|
755
|
+
IsLiteral(value) ||
|
|
756
|
+
IsMappedKey(value) ||
|
|
757
|
+
IsMappedResult(value) ||
|
|
758
|
+
IsNever(value) ||
|
|
759
|
+
IsNot(value) ||
|
|
760
|
+
IsNull(value) ||
|
|
761
|
+
IsNumber(value) ||
|
|
762
|
+
IsObject(value) ||
|
|
763
|
+
IsPromise(value) ||
|
|
764
|
+
IsRecord(value) ||
|
|
765
|
+
IsRef(value) ||
|
|
766
|
+
IsRegExp(value) ||
|
|
767
|
+
IsString(value) ||
|
|
768
|
+
IsSymbol(value) ||
|
|
769
|
+
IsTemplateLiteral(value) ||
|
|
770
|
+
IsThis(value) ||
|
|
771
|
+
IsTuple(value) ||
|
|
772
|
+
IsUndefined(value) ||
|
|
773
|
+
IsUnion(value) ||
|
|
774
|
+
IsUint8Array(value) ||
|
|
775
|
+
IsUnknown(value) ||
|
|
776
|
+
IsUnsafe(value) ||
|
|
777
|
+
IsVoid(value) ||
|
|
778
|
+
IsKind(value));
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const PatternBoolean = '(true|false)';
|
|
782
|
+
const PatternNumber = '(0|[1-9][0-9]*)';
|
|
783
|
+
const PatternString = '(.*)';
|
|
784
|
+
const PatternNever = '(?!.*)';
|
|
785
|
+
const PatternNumberExact = `^${PatternNumber}$`;
|
|
786
|
+
const PatternStringExact = `^${PatternString}$`;
|
|
787
|
+
const PatternNeverExact = `^${PatternNever}$`;
|
|
788
|
+
|
|
789
|
+
/** Returns true if element right is in the set of left */
|
|
790
|
+
// prettier-ignore
|
|
791
|
+
function SetIncludes(T, S) {
|
|
792
|
+
return T.includes(S);
|
|
793
|
+
}
|
|
794
|
+
/** Returns a distinct set of elements */
|
|
795
|
+
function SetDistinct(T) {
|
|
796
|
+
return [...new Set(T)];
|
|
797
|
+
}
|
|
798
|
+
/** Returns the Intersect of the given sets */
|
|
799
|
+
function SetIntersect(T, S) {
|
|
800
|
+
return T.filter((L) => S.includes(L));
|
|
801
|
+
}
|
|
802
|
+
// prettier-ignore
|
|
803
|
+
function SetIntersectManyResolve(T, Init) {
|
|
804
|
+
return T.reduce((Acc, L) => {
|
|
805
|
+
return SetIntersect(Acc, L);
|
|
806
|
+
}, Init);
|
|
807
|
+
}
|
|
808
|
+
// prettier-ignore
|
|
809
|
+
function SetIntersectMany(T) {
|
|
810
|
+
return (T.length === 1
|
|
811
|
+
? T[0]
|
|
812
|
+
// Use left to initialize the accumulator for resolve
|
|
813
|
+
: T.length > 1
|
|
814
|
+
? SetIntersectManyResolve(T.slice(1), T[0])
|
|
815
|
+
: []);
|
|
816
|
+
}
|
|
817
|
+
/** Returns the Union of multiple sets */
|
|
818
|
+
function SetUnionMany(T) {
|
|
819
|
+
const Acc = [];
|
|
820
|
+
for (const L of T)
|
|
821
|
+
Acc.push(...L);
|
|
822
|
+
return Acc;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/** `[Json]` Creates an Any type */
|
|
826
|
+
function Any(options = {}) {
|
|
827
|
+
return { ...options, [Kind]: 'Any' };
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/** `[Json]` Creates an Array type */
|
|
831
|
+
function Array$1(schema, options = {}) {
|
|
832
|
+
return {
|
|
833
|
+
...options,
|
|
834
|
+
[Kind]: 'Array',
|
|
835
|
+
type: 'array',
|
|
836
|
+
items: CloneType(schema),
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
841
|
+
function AsyncIterator(items, options = {}) {
|
|
842
|
+
return {
|
|
843
|
+
...options,
|
|
844
|
+
[Kind]: 'AsyncIterator',
|
|
845
|
+
type: 'AsyncIterator',
|
|
846
|
+
items: CloneType(items),
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function DiscardKey(value, key) {
|
|
851
|
+
const { [key]: _, ...rest } = value;
|
|
852
|
+
return rest;
|
|
853
|
+
}
|
|
854
|
+
function Discard(value, keys) {
|
|
855
|
+
return keys.reduce((acc, key) => DiscardKey(acc, key), value);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/** `[Json]` Creates a Never type */
|
|
859
|
+
function Never(options = {}) {
|
|
860
|
+
return {
|
|
861
|
+
...options,
|
|
862
|
+
[Kind]: 'Never',
|
|
863
|
+
not: {},
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// prettier-ignore
|
|
868
|
+
function MappedResult(properties) {
|
|
869
|
+
return {
|
|
870
|
+
[Kind]: 'MappedResult',
|
|
871
|
+
properties
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** `[JavaScript]` Creates a Constructor type */
|
|
876
|
+
function Constructor(parameters, returns, options) {
|
|
877
|
+
return {
|
|
878
|
+
...options,
|
|
879
|
+
[Kind]: 'Constructor',
|
|
880
|
+
type: 'Constructor',
|
|
881
|
+
parameters: CloneRest(parameters),
|
|
882
|
+
returns: CloneType(returns),
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** `[JavaScript]` Creates a Function type */
|
|
887
|
+
function Function(parameters, returns, options) {
|
|
888
|
+
return {
|
|
889
|
+
...options,
|
|
890
|
+
[Kind]: 'Function',
|
|
891
|
+
type: 'Function',
|
|
892
|
+
parameters: CloneRest(parameters),
|
|
893
|
+
returns: CloneType(returns),
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function UnionCreate(T, options) {
|
|
898
|
+
return { ...options, [Kind]: 'Union', anyOf: CloneRest(T) };
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// prettier-ignore
|
|
902
|
+
function IsUnionOptional(T) {
|
|
903
|
+
return T.some(L => IsOptional$1(L));
|
|
904
|
+
}
|
|
905
|
+
// prettier-ignore
|
|
906
|
+
function RemoveOptionalFromRest$1(T) {
|
|
907
|
+
return T.map(L => IsOptional$1(L) ? RemoveOptionalFromType$1(L) : L);
|
|
908
|
+
}
|
|
909
|
+
// prettier-ignore
|
|
910
|
+
function RemoveOptionalFromType$1(T) {
|
|
911
|
+
return (Discard(T, [OptionalKind]));
|
|
912
|
+
}
|
|
913
|
+
// prettier-ignore
|
|
914
|
+
function ResolveUnion(T, options) {
|
|
915
|
+
return (IsUnionOptional(T)
|
|
916
|
+
? Optional(UnionCreate(RemoveOptionalFromRest$1(T), options))
|
|
917
|
+
: UnionCreate(RemoveOptionalFromRest$1(T), options));
|
|
918
|
+
}
|
|
919
|
+
/** `[Json]` Creates an evaluated Union type */
|
|
920
|
+
function UnionEvaluated(T, options = {}) {
|
|
921
|
+
// prettier-ignore
|
|
922
|
+
return (T.length === 0 ? Never(options) :
|
|
923
|
+
T.length === 1 ? CloneType(T[0], options) :
|
|
924
|
+
ResolveUnion(T, options));
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** `[Json]` Creates a Union type */
|
|
928
|
+
function Union(T, options = {}) {
|
|
929
|
+
// prettier-ignore
|
|
930
|
+
return (T.length === 0 ? Never(options) :
|
|
931
|
+
T.length === 1 ? CloneType(T[0], options) :
|
|
932
|
+
UnionCreate(T, options));
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// ------------------------------------------------------------------
|
|
936
|
+
// TemplateLiteralParserError
|
|
937
|
+
// ------------------------------------------------------------------
|
|
938
|
+
class TemplateLiteralParserError extends TypeBoxError {
|
|
939
|
+
}
|
|
940
|
+
// -------------------------------------------------------------------
|
|
941
|
+
// Unescape
|
|
942
|
+
//
|
|
943
|
+
// Unescape for these control characters specifically. Note that this
|
|
944
|
+
// function is only called on non union group content, and where we
|
|
945
|
+
// still want to allow the user to embed control characters in that
|
|
946
|
+
// content. For review.
|
|
947
|
+
// -------------------------------------------------------------------
|
|
948
|
+
// prettier-ignore
|
|
949
|
+
function Unescape(pattern) {
|
|
950
|
+
return pattern
|
|
951
|
+
.replace(/\\\$/g, '$')
|
|
952
|
+
.replace(/\\\*/g, '*')
|
|
953
|
+
.replace(/\\\^/g, '^')
|
|
954
|
+
.replace(/\\\|/g, '|')
|
|
955
|
+
.replace(/\\\(/g, '(')
|
|
956
|
+
.replace(/\\\)/g, ')');
|
|
957
|
+
}
|
|
958
|
+
// -------------------------------------------------------------------
|
|
959
|
+
// Control Characters
|
|
960
|
+
// -------------------------------------------------------------------
|
|
961
|
+
function IsNonEscaped(pattern, index, char) {
|
|
962
|
+
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
963
|
+
}
|
|
964
|
+
function IsOpenParen(pattern, index) {
|
|
965
|
+
return IsNonEscaped(pattern, index, '(');
|
|
966
|
+
}
|
|
967
|
+
function IsCloseParen(pattern, index) {
|
|
968
|
+
return IsNonEscaped(pattern, index, ')');
|
|
969
|
+
}
|
|
970
|
+
function IsSeparator(pattern, index) {
|
|
971
|
+
return IsNonEscaped(pattern, index, '|');
|
|
972
|
+
}
|
|
973
|
+
// -------------------------------------------------------------------
|
|
974
|
+
// Control Groups
|
|
975
|
+
// -------------------------------------------------------------------
|
|
976
|
+
function IsGroup(pattern) {
|
|
977
|
+
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
978
|
+
return false;
|
|
979
|
+
let count = 0;
|
|
980
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
981
|
+
if (IsOpenParen(pattern, index))
|
|
982
|
+
count += 1;
|
|
983
|
+
if (IsCloseParen(pattern, index))
|
|
984
|
+
count -= 1;
|
|
985
|
+
if (count === 0 && index !== pattern.length - 1)
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
// prettier-ignore
|
|
991
|
+
function InGroup(pattern) {
|
|
992
|
+
return pattern.slice(1, pattern.length - 1);
|
|
993
|
+
}
|
|
994
|
+
// prettier-ignore
|
|
995
|
+
function IsPrecedenceOr(pattern) {
|
|
996
|
+
let count = 0;
|
|
997
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
998
|
+
if (IsOpenParen(pattern, index))
|
|
999
|
+
count += 1;
|
|
1000
|
+
if (IsCloseParen(pattern, index))
|
|
1001
|
+
count -= 1;
|
|
1002
|
+
if (IsSeparator(pattern, index) && count === 0)
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
// prettier-ignore
|
|
1008
|
+
function IsPrecedenceAnd(pattern) {
|
|
1009
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1010
|
+
if (IsOpenParen(pattern, index))
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
// prettier-ignore
|
|
1016
|
+
function Or(pattern) {
|
|
1017
|
+
let [count, start] = [0, 0];
|
|
1018
|
+
const expressions = [];
|
|
1019
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1020
|
+
if (IsOpenParen(pattern, index))
|
|
1021
|
+
count += 1;
|
|
1022
|
+
if (IsCloseParen(pattern, index))
|
|
1023
|
+
count -= 1;
|
|
1024
|
+
if (IsSeparator(pattern, index) && count === 0) {
|
|
1025
|
+
const range = pattern.slice(start, index);
|
|
1026
|
+
if (range.length > 0)
|
|
1027
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1028
|
+
start = index + 1;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
const range = pattern.slice(start);
|
|
1032
|
+
if (range.length > 0)
|
|
1033
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1034
|
+
if (expressions.length === 0)
|
|
1035
|
+
return { type: 'const', const: '' };
|
|
1036
|
+
if (expressions.length === 1)
|
|
1037
|
+
return expressions[0];
|
|
1038
|
+
return { type: 'or', expr: expressions };
|
|
1039
|
+
}
|
|
1040
|
+
// prettier-ignore
|
|
1041
|
+
function And(pattern) {
|
|
1042
|
+
function Group(value, index) {
|
|
1043
|
+
if (!IsOpenParen(value, index))
|
|
1044
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
|
|
1045
|
+
let count = 0;
|
|
1046
|
+
for (let scan = index; scan < value.length; scan++) {
|
|
1047
|
+
if (IsOpenParen(value, scan))
|
|
1048
|
+
count += 1;
|
|
1049
|
+
if (IsCloseParen(value, scan))
|
|
1050
|
+
count -= 1;
|
|
1051
|
+
if (count === 0)
|
|
1052
|
+
return [index, scan];
|
|
1053
|
+
}
|
|
1054
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
|
|
1055
|
+
}
|
|
1056
|
+
function Range(pattern, index) {
|
|
1057
|
+
for (let scan = index; scan < pattern.length; scan++) {
|
|
1058
|
+
if (IsOpenParen(pattern, scan))
|
|
1059
|
+
return [index, scan];
|
|
1060
|
+
}
|
|
1061
|
+
return [index, pattern.length];
|
|
1062
|
+
}
|
|
1063
|
+
const expressions = [];
|
|
1064
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1065
|
+
if (IsOpenParen(pattern, index)) {
|
|
1066
|
+
const [start, end] = Group(pattern, index);
|
|
1067
|
+
const range = pattern.slice(start, end + 1);
|
|
1068
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1069
|
+
index = end;
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
const [start, end] = Range(pattern, index);
|
|
1073
|
+
const range = pattern.slice(start, end);
|
|
1074
|
+
if (range.length > 0)
|
|
1075
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1076
|
+
index = end - 1;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return ((expressions.length === 0) ? { type: 'const', const: '' } :
|
|
1080
|
+
(expressions.length === 1) ? expressions[0] :
|
|
1081
|
+
{ type: 'and', expr: expressions });
|
|
1082
|
+
}
|
|
1083
|
+
// ------------------------------------------------------------------
|
|
1084
|
+
// TemplateLiteralParse
|
|
1085
|
+
// ------------------------------------------------------------------
|
|
1086
|
+
/** Parses a pattern and returns an expression tree */
|
|
1087
|
+
function TemplateLiteralParse(pattern) {
|
|
1088
|
+
// prettier-ignore
|
|
1089
|
+
return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
|
|
1090
|
+
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
1091
|
+
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
1092
|
+
{ type: 'const', const: Unescape(pattern) });
|
|
1093
|
+
}
|
|
1094
|
+
// ------------------------------------------------------------------
|
|
1095
|
+
// TemplateLiteralParseExact
|
|
1096
|
+
// ------------------------------------------------------------------
|
|
1097
|
+
/** Parses a pattern and strips forward and trailing ^ and $ */
|
|
1098
|
+
function TemplateLiteralParseExact(pattern) {
|
|
1099
|
+
return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// ------------------------------------------------------------------
|
|
1103
|
+
// TemplateLiteralFiniteError
|
|
1104
|
+
// ------------------------------------------------------------------
|
|
1105
|
+
class TemplateLiteralFiniteError extends TypeBoxError {
|
|
1106
|
+
}
|
|
1107
|
+
// ------------------------------------------------------------------
|
|
1108
|
+
// IsTemplateLiteralFiniteCheck
|
|
1109
|
+
// ------------------------------------------------------------------
|
|
1110
|
+
// prettier-ignore
|
|
1111
|
+
function IsNumberExpression(expression) {
|
|
1112
|
+
return (expression.type === 'or' &&
|
|
1113
|
+
expression.expr.length === 2 &&
|
|
1114
|
+
expression.expr[0].type === 'const' &&
|
|
1115
|
+
expression.expr[0].const === '0' &&
|
|
1116
|
+
expression.expr[1].type === 'const' &&
|
|
1117
|
+
expression.expr[1].const === '[1-9][0-9]*');
|
|
1118
|
+
}
|
|
1119
|
+
// prettier-ignore
|
|
1120
|
+
function IsBooleanExpression(expression) {
|
|
1121
|
+
return (expression.type === 'or' &&
|
|
1122
|
+
expression.expr.length === 2 &&
|
|
1123
|
+
expression.expr[0].type === 'const' &&
|
|
1124
|
+
expression.expr[0].const === 'true' &&
|
|
1125
|
+
expression.expr[1].type === 'const' &&
|
|
1126
|
+
expression.expr[1].const === 'false');
|
|
1127
|
+
}
|
|
1128
|
+
// prettier-ignore
|
|
1129
|
+
function IsStringExpression(expression) {
|
|
1130
|
+
return expression.type === 'const' && expression.const === '.*';
|
|
1131
|
+
}
|
|
1132
|
+
// ------------------------------------------------------------------
|
|
1133
|
+
// IsTemplateLiteralExpressionFinite
|
|
1134
|
+
// ------------------------------------------------------------------
|
|
1135
|
+
// prettier-ignore
|
|
1136
|
+
function IsTemplateLiteralExpressionFinite(expression) {
|
|
1137
|
+
return (IsNumberExpression(expression) || IsStringExpression(expression) ? false :
|
|
1138
|
+
IsBooleanExpression(expression) ? true :
|
|
1139
|
+
(expression.type === 'and') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
1140
|
+
(expression.type === 'or') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
1141
|
+
(expression.type === 'const') ? true :
|
|
1142
|
+
(() => { throw new TemplateLiteralFiniteError(`Unknown expression type`); })());
|
|
1143
|
+
}
|
|
1144
|
+
/** Returns true if this TemplateLiteral resolves to a finite set of values */
|
|
1145
|
+
function IsTemplateLiteralFinite(schema) {
|
|
1146
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
1147
|
+
return IsTemplateLiteralExpressionFinite(expression);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// ------------------------------------------------------------------
|
|
1151
|
+
// TemplateLiteralGenerateError
|
|
1152
|
+
// ------------------------------------------------------------------
|
|
1153
|
+
class TemplateLiteralGenerateError extends TypeBoxError {
|
|
1154
|
+
}
|
|
1155
|
+
// ------------------------------------------------------------------
|
|
1156
|
+
// TemplateLiteralExpressionGenerate
|
|
1157
|
+
// ------------------------------------------------------------------
|
|
1158
|
+
// prettier-ignore
|
|
1159
|
+
function* GenerateReduce(buffer) {
|
|
1160
|
+
if (buffer.length === 1)
|
|
1161
|
+
return yield* buffer[0];
|
|
1162
|
+
for (const left of buffer[0]) {
|
|
1163
|
+
for (const right of GenerateReduce(buffer.slice(1))) {
|
|
1164
|
+
yield `${left}${right}`;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
// prettier-ignore
|
|
1169
|
+
function* GenerateAnd(expression) {
|
|
1170
|
+
return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
|
|
1171
|
+
}
|
|
1172
|
+
// prettier-ignore
|
|
1173
|
+
function* GenerateOr(expression) {
|
|
1174
|
+
for (const expr of expression.expr)
|
|
1175
|
+
yield* TemplateLiteralExpressionGenerate(expr);
|
|
1176
|
+
}
|
|
1177
|
+
// prettier-ignore
|
|
1178
|
+
function* GenerateConst(expression) {
|
|
1179
|
+
return yield expression.const;
|
|
1180
|
+
}
|
|
1181
|
+
function* TemplateLiteralExpressionGenerate(expression) {
|
|
1182
|
+
return expression.type === 'and'
|
|
1183
|
+
? yield* GenerateAnd(expression)
|
|
1184
|
+
: expression.type === 'or'
|
|
1185
|
+
? yield* GenerateOr(expression)
|
|
1186
|
+
: expression.type === 'const'
|
|
1187
|
+
? yield* GenerateConst(expression)
|
|
1188
|
+
: (() => {
|
|
1189
|
+
throw new TemplateLiteralGenerateError('Unknown expression');
|
|
1190
|
+
})();
|
|
1191
|
+
}
|
|
1192
|
+
/** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
|
|
1193
|
+
function TemplateLiteralGenerate(schema) {
|
|
1194
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
1195
|
+
// prettier-ignore
|
|
1196
|
+
return (IsTemplateLiteralExpressionFinite(expression)
|
|
1197
|
+
? [...TemplateLiteralExpressionGenerate(expression)]
|
|
1198
|
+
: []);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/** `[Json]` Creates a Literal type */
|
|
1202
|
+
function Literal(value, options = {}) {
|
|
1203
|
+
return {
|
|
1204
|
+
...options,
|
|
1205
|
+
[Kind]: 'Literal',
|
|
1206
|
+
const: value,
|
|
1207
|
+
type: typeof value,
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/** `[Json]` Creates a Boolean type */
|
|
1212
|
+
function Boolean(options = {}) {
|
|
1213
|
+
return {
|
|
1214
|
+
...options,
|
|
1215
|
+
[Kind]: 'Boolean',
|
|
1216
|
+
type: 'boolean',
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/** `[JavaScript]` Creates a BigInt type */
|
|
1221
|
+
function BigInt(options = {}) {
|
|
1222
|
+
return {
|
|
1223
|
+
...options,
|
|
1224
|
+
[Kind]: 'BigInt',
|
|
1225
|
+
type: 'bigint',
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/** `[Json]` Creates a Number type */
|
|
1230
|
+
function Number(options = {}) {
|
|
1231
|
+
return {
|
|
1232
|
+
...options,
|
|
1233
|
+
[Kind]: 'Number',
|
|
1234
|
+
type: 'number',
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/** `[Json]` Creates a String type */
|
|
1239
|
+
function String(options = {}) {
|
|
1240
|
+
return { ...options, [Kind]: 'String', type: 'string' };
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// ------------------------------------------------------------------
|
|
1244
|
+
// SyntaxParsers
|
|
1245
|
+
// ------------------------------------------------------------------
|
|
1246
|
+
// prettier-ignore
|
|
1247
|
+
function* FromUnion$8(syntax) {
|
|
1248
|
+
const trim = syntax.trim().replace(/"|'/g, '');
|
|
1249
|
+
return (trim === 'boolean' ? yield Boolean() :
|
|
1250
|
+
trim === 'number' ? yield Number() :
|
|
1251
|
+
trim === 'bigint' ? yield BigInt() :
|
|
1252
|
+
trim === 'string' ? yield String() :
|
|
1253
|
+
yield (() => {
|
|
1254
|
+
const literals = trim.split('|').map((literal) => Literal(literal.trim()));
|
|
1255
|
+
return (literals.length === 0 ? Never() :
|
|
1256
|
+
literals.length === 1 ? literals[0] :
|
|
1257
|
+
UnionEvaluated(literals));
|
|
1258
|
+
})());
|
|
1259
|
+
}
|
|
1260
|
+
// prettier-ignore
|
|
1261
|
+
function* FromTerminal(syntax) {
|
|
1262
|
+
if (syntax[1] !== '{') {
|
|
1263
|
+
const L = Literal('$');
|
|
1264
|
+
const R = FromSyntax(syntax.slice(1));
|
|
1265
|
+
return yield* [L, ...R];
|
|
1266
|
+
}
|
|
1267
|
+
for (let i = 2; i < syntax.length; i++) {
|
|
1268
|
+
if (syntax[i] === '}') {
|
|
1269
|
+
const L = FromUnion$8(syntax.slice(2, i));
|
|
1270
|
+
const R = FromSyntax(syntax.slice(i + 1));
|
|
1271
|
+
return yield* [...L, ...R];
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
yield Literal(syntax);
|
|
1275
|
+
}
|
|
1276
|
+
// prettier-ignore
|
|
1277
|
+
function* FromSyntax(syntax) {
|
|
1278
|
+
for (let i = 0; i < syntax.length; i++) {
|
|
1279
|
+
if (syntax[i] === '$') {
|
|
1280
|
+
const L = Literal(syntax.slice(0, i));
|
|
1281
|
+
const R = FromTerminal(syntax.slice(i));
|
|
1282
|
+
return yield* [L, ...R];
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
yield Literal(syntax);
|
|
1286
|
+
}
|
|
1287
|
+
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
|
|
1288
|
+
function TemplateLiteralSyntax(syntax) {
|
|
1289
|
+
return [...FromSyntax(syntax)];
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// ------------------------------------------------------------------
|
|
1293
|
+
// TemplateLiteralPatternError
|
|
1294
|
+
// ------------------------------------------------------------------
|
|
1295
|
+
class TemplateLiteralPatternError extends TypeBoxError {
|
|
1296
|
+
}
|
|
1297
|
+
// ------------------------------------------------------------------
|
|
1298
|
+
// TemplateLiteralPattern
|
|
1299
|
+
// ------------------------------------------------------------------
|
|
1300
|
+
function Escape(value) {
|
|
1301
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1302
|
+
}
|
|
1303
|
+
// prettier-ignore
|
|
1304
|
+
function Visit$1(schema, acc) {
|
|
1305
|
+
return (IsTemplateLiteral$1(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
|
|
1306
|
+
IsUnion$1(schema) ? `(${schema.anyOf.map((schema) => Visit$1(schema, acc)).join('|')})` :
|
|
1307
|
+
IsNumber$1(schema) ? `${acc}${PatternNumber}` :
|
|
1308
|
+
IsInteger$1(schema) ? `${acc}${PatternNumber}` :
|
|
1309
|
+
IsBigInt$1(schema) ? `${acc}${PatternNumber}` :
|
|
1310
|
+
IsString$1(schema) ? `${acc}${PatternString}` :
|
|
1311
|
+
IsLiteral$1(schema) ? `${acc}${Escape(schema.const.toString())}` :
|
|
1312
|
+
IsBoolean$1(schema) ? `${acc}${PatternBoolean}` :
|
|
1313
|
+
(() => { throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`); })());
|
|
1314
|
+
}
|
|
1315
|
+
function TemplateLiteralPattern(kinds) {
|
|
1316
|
+
return `^${kinds.map((schema) => Visit$1(schema, '')).join('')}\$`;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/** Returns a Union from the given TemplateLiteral */
|
|
1320
|
+
function TemplateLiteralToUnion(schema) {
|
|
1321
|
+
const R = TemplateLiteralGenerate(schema);
|
|
1322
|
+
const L = R.map((S) => Literal(S));
|
|
1323
|
+
return UnionEvaluated(L);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/** `[Json]` Creates a TemplateLiteral type */
|
|
1327
|
+
// prettier-ignore
|
|
1328
|
+
function TemplateLiteral(unresolved, options = {}) {
|
|
1329
|
+
const pattern = IsString$2(unresolved)
|
|
1330
|
+
? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved))
|
|
1331
|
+
: TemplateLiteralPattern(unresolved);
|
|
1332
|
+
return { ...options, [Kind]: 'TemplateLiteral', type: 'string', pattern };
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// prettier-ignore
|
|
1336
|
+
function FromTemplateLiteral$2(T) {
|
|
1337
|
+
const R = TemplateLiteralGenerate(T);
|
|
1338
|
+
return R.map(S => S.toString());
|
|
1339
|
+
}
|
|
1340
|
+
// prettier-ignore
|
|
1341
|
+
function FromUnion$7(T) {
|
|
1342
|
+
const Acc = [];
|
|
1343
|
+
for (const L of T)
|
|
1344
|
+
Acc.push(...IndexPropertyKeys(L));
|
|
1345
|
+
return Acc;
|
|
1346
|
+
}
|
|
1347
|
+
// prettier-ignore
|
|
1348
|
+
function FromLiteral$1(T) {
|
|
1349
|
+
return ([T.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
/** Returns a tuple of PropertyKeys derived from the given TSchema */
|
|
1353
|
+
// prettier-ignore
|
|
1354
|
+
function IndexPropertyKeys(T) {
|
|
1355
|
+
return [...new Set((IsTemplateLiteral$1(T) ? FromTemplateLiteral$2(T) :
|
|
1356
|
+
IsUnion$1(T) ? FromUnion$7(T.anyOf) :
|
|
1357
|
+
IsLiteral$1(T) ? FromLiteral$1(T.const) :
|
|
1358
|
+
IsNumber$1(T) ? ['[number]'] :
|
|
1359
|
+
IsInteger$1(T) ? ['[number]'] :
|
|
1360
|
+
[]))];
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// prettier-ignore
|
|
1364
|
+
function FromProperties$i(T, P, options) {
|
|
1365
|
+
const Acc = {};
|
|
1366
|
+
for (const K2 of Object.getOwnPropertyNames(P)) {
|
|
1367
|
+
Acc[K2] = Index(T, IndexPropertyKeys(P[K2]), options);
|
|
1368
|
+
}
|
|
1369
|
+
return Acc;
|
|
1370
|
+
}
|
|
1371
|
+
// prettier-ignore
|
|
1372
|
+
function FromMappedResult$b(T, R, options) {
|
|
1373
|
+
return FromProperties$i(T, R.properties, options);
|
|
1374
|
+
}
|
|
1375
|
+
// prettier-ignore
|
|
1376
|
+
function IndexFromMappedResult(T, R, options) {
|
|
1377
|
+
const P = FromMappedResult$b(T, R, options);
|
|
1378
|
+
return MappedResult(P);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// prettier-ignore
|
|
1382
|
+
function FromRest$7(T, K) {
|
|
1383
|
+
return T.map(L => IndexFromPropertyKey(L, K));
|
|
1384
|
+
}
|
|
1385
|
+
// prettier-ignore
|
|
1386
|
+
function FromIntersectRest(T) {
|
|
1387
|
+
return T.filter(L => !IsNever$1(L));
|
|
1388
|
+
}
|
|
1389
|
+
// prettier-ignore
|
|
1390
|
+
function FromIntersect$6(T, K) {
|
|
1391
|
+
return (IntersectEvaluated(FromIntersectRest(FromRest$7(T, K))));
|
|
1392
|
+
}
|
|
1393
|
+
// prettier-ignore
|
|
1394
|
+
function FromUnionRest(T) {
|
|
1395
|
+
return (T.some(L => IsNever$1(L))
|
|
1396
|
+
? []
|
|
1397
|
+
: T);
|
|
1398
|
+
}
|
|
1399
|
+
// prettier-ignore
|
|
1400
|
+
function FromUnion$6(T, K) {
|
|
1401
|
+
return (UnionEvaluated(FromUnionRest(FromRest$7(T, K))));
|
|
1402
|
+
}
|
|
1403
|
+
// prettier-ignore
|
|
1404
|
+
function FromTuple$3(T, K) {
|
|
1405
|
+
return (K in T ? T[K] :
|
|
1406
|
+
K === '[number]' ? UnionEvaluated(T) :
|
|
1407
|
+
Never());
|
|
1408
|
+
}
|
|
1409
|
+
// prettier-ignore
|
|
1410
|
+
function FromArray$4(T, K) {
|
|
1411
|
+
return (K === '[number]'
|
|
1412
|
+
? T
|
|
1413
|
+
: Never());
|
|
1414
|
+
}
|
|
1415
|
+
// prettier-ignore
|
|
1416
|
+
function FromProperty$1(T, K) {
|
|
1417
|
+
return (K in T ? T[K] : Never());
|
|
1418
|
+
}
|
|
1419
|
+
// prettier-ignore
|
|
1420
|
+
function IndexFromPropertyKey(T, K) {
|
|
1421
|
+
return (IsIntersect$1(T) ? FromIntersect$6(T.allOf, K) :
|
|
1422
|
+
IsUnion$1(T) ? FromUnion$6(T.anyOf, K) :
|
|
1423
|
+
IsTuple$1(T) ? FromTuple$3(T.items ?? [], K) :
|
|
1424
|
+
IsArray$1(T) ? FromArray$4(T.items, K) :
|
|
1425
|
+
IsObject$1(T) ? FromProperty$1(T.properties, K) :
|
|
1426
|
+
Never());
|
|
1427
|
+
}
|
|
1428
|
+
// prettier-ignore
|
|
1429
|
+
function IndexFromPropertyKeys(T, K) {
|
|
1430
|
+
return K.map(L => IndexFromPropertyKey(T, L));
|
|
1431
|
+
}
|
|
1432
|
+
// prettier-ignore
|
|
1433
|
+
function FromSchema(T, K) {
|
|
1434
|
+
return (UnionEvaluated(IndexFromPropertyKeys(T, K)));
|
|
1435
|
+
}
|
|
1436
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
1437
|
+
function Index(T, K, options = {}) {
|
|
1438
|
+
// prettier-ignore
|
|
1439
|
+
return (IsMappedResult$1(K) ? CloneType(IndexFromMappedResult(T, K, options)) :
|
|
1440
|
+
IsMappedKey$1(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
|
|
1441
|
+
IsSchema$1(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) :
|
|
1442
|
+
CloneType(FromSchema(T, K), options));
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// prettier-ignore
|
|
1446
|
+
function MappedIndexPropertyKey(T, K, options) {
|
|
1447
|
+
return { [K]: Index(T, [K], options) };
|
|
1448
|
+
}
|
|
1449
|
+
// prettier-ignore
|
|
1450
|
+
function MappedIndexPropertyKeys(T, K, options) {
|
|
1451
|
+
return K.reduce((Acc, L) => {
|
|
1452
|
+
return { ...Acc, ...MappedIndexPropertyKey(T, L, options) };
|
|
1453
|
+
}, {});
|
|
1454
|
+
}
|
|
1455
|
+
// prettier-ignore
|
|
1456
|
+
function MappedIndexProperties(T, K, options) {
|
|
1457
|
+
return MappedIndexPropertyKeys(T, K.keys, options);
|
|
1458
|
+
}
|
|
1459
|
+
// prettier-ignore
|
|
1460
|
+
function IndexFromMappedKey(T, K, options) {
|
|
1461
|
+
const P = MappedIndexProperties(T, K, options);
|
|
1462
|
+
return MappedResult(P);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
/** `[JavaScript]` Creates an Iterator type */
|
|
1466
|
+
function Iterator(items, options = {}) {
|
|
1467
|
+
return {
|
|
1468
|
+
...options,
|
|
1469
|
+
[Kind]: 'Iterator',
|
|
1470
|
+
type: 'Iterator',
|
|
1471
|
+
items: CloneType(items),
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
/** `[Json]` Creates an Object type */
|
|
1476
|
+
function _Object(properties, options = {}) {
|
|
1477
|
+
const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
|
|
1478
|
+
const optionalKeys = propertyKeys.filter((key) => IsOptional$1(properties[key]));
|
|
1479
|
+
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
1480
|
+
const clonedAdditionalProperties = IsSchema$1(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
|
|
1481
|
+
const clonedProperties = {};
|
|
1482
|
+
for (const key of propertyKeys)
|
|
1483
|
+
clonedProperties[key] = CloneType(properties[key]);
|
|
1484
|
+
return (requiredKeys.length > 0
|
|
1485
|
+
? { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
|
|
1486
|
+
: { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
1487
|
+
}
|
|
1488
|
+
/** `[Json]` Creates an Object type */
|
|
1489
|
+
const Object$1 = _Object;
|
|
1490
|
+
|
|
1491
|
+
/** `[JavaScript]` Creates a Promise type */
|
|
1492
|
+
function Promise$1(item, options = {}) {
|
|
1493
|
+
return {
|
|
1494
|
+
...options,
|
|
1495
|
+
[Kind]: 'Promise',
|
|
1496
|
+
type: 'Promise',
|
|
1497
|
+
item: CloneType(item),
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
function RemoveReadonly(schema) {
|
|
1502
|
+
return Discard(CloneType(schema), [ReadonlyKind]);
|
|
1503
|
+
}
|
|
1504
|
+
function AddReadonly(schema) {
|
|
1505
|
+
return { ...CloneType(schema), [ReadonlyKind]: 'Readonly' };
|
|
1506
|
+
}
|
|
1507
|
+
// prettier-ignore
|
|
1508
|
+
function ReadonlyWithFlag(schema, F) {
|
|
1509
|
+
return (F === false
|
|
1510
|
+
? RemoveReadonly(schema)
|
|
1511
|
+
: AddReadonly(schema));
|
|
1512
|
+
}
|
|
1513
|
+
/** `[Json]` Creates a Readonly property */
|
|
1514
|
+
function Readonly(schema, enable) {
|
|
1515
|
+
const F = enable ?? true;
|
|
1516
|
+
return IsMappedResult$1(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F);
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
// prettier-ignore
|
|
1520
|
+
function FromProperties$h(K, F) {
|
|
1521
|
+
const Acc = {};
|
|
1522
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
1523
|
+
Acc[K2] = Readonly(K[K2], F);
|
|
1524
|
+
return Acc;
|
|
1525
|
+
}
|
|
1526
|
+
// prettier-ignore
|
|
1527
|
+
function FromMappedResult$a(R, F) {
|
|
1528
|
+
return FromProperties$h(R.properties, F);
|
|
1529
|
+
}
|
|
1530
|
+
// prettier-ignore
|
|
1531
|
+
function ReadonlyFromMappedResult(R, F) {
|
|
1532
|
+
const P = FromMappedResult$a(R, F);
|
|
1533
|
+
return MappedResult(P);
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
/** `[Json]` Creates a Tuple type */
|
|
1537
|
+
function Tuple(items, options = {}) {
|
|
1538
|
+
// return TupleResolver.Resolve(T)
|
|
1539
|
+
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
1540
|
+
// prettier-ignore
|
|
1541
|
+
return (items.length > 0 ?
|
|
1542
|
+
{ ...options, [Kind]: 'Tuple', type: 'array', items: CloneRest(items), additionalItems, minItems, maxItems } :
|
|
1543
|
+
{ ...options, [Kind]: 'Tuple', type: 'array', minItems, maxItems });
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// prettier-ignore
|
|
1547
|
+
function FromMappedResult$9(K, P) {
|
|
1548
|
+
return (K in P
|
|
1549
|
+
? FromSchemaType(K, P[K])
|
|
1550
|
+
: MappedResult(P));
|
|
1551
|
+
}
|
|
1552
|
+
// prettier-ignore
|
|
1553
|
+
function MappedKeyToKnownMappedResultProperties(K) {
|
|
1554
|
+
return { [K]: Literal(K) };
|
|
1555
|
+
}
|
|
1556
|
+
// prettier-ignore
|
|
1557
|
+
function MappedKeyToUnknownMappedResultProperties(P) {
|
|
1558
|
+
const Acc = {};
|
|
1559
|
+
for (const L of P)
|
|
1560
|
+
Acc[L] = Literal(L);
|
|
1561
|
+
return Acc;
|
|
1562
|
+
}
|
|
1563
|
+
// prettier-ignore
|
|
1564
|
+
function MappedKeyToMappedResultProperties(K, P) {
|
|
1565
|
+
return (SetIncludes(P, K)
|
|
1566
|
+
? MappedKeyToKnownMappedResultProperties(K)
|
|
1567
|
+
: MappedKeyToUnknownMappedResultProperties(P));
|
|
1568
|
+
}
|
|
1569
|
+
// prettier-ignore
|
|
1570
|
+
function FromMappedKey$3(K, P) {
|
|
1571
|
+
const R = MappedKeyToMappedResultProperties(K, P);
|
|
1572
|
+
return FromMappedResult$9(K, R);
|
|
1573
|
+
}
|
|
1574
|
+
// prettier-ignore
|
|
1575
|
+
function FromRest$6(K, T) {
|
|
1576
|
+
return T.map(L => FromSchemaType(K, L));
|
|
1577
|
+
}
|
|
1578
|
+
// prettier-ignore
|
|
1579
|
+
function FromProperties$g(K, T) {
|
|
1580
|
+
const Acc = {};
|
|
1581
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(T))
|
|
1582
|
+
Acc[K2] = FromSchemaType(K, T[K2]);
|
|
1583
|
+
return Acc;
|
|
1584
|
+
}
|
|
1585
|
+
// prettier-ignore
|
|
1586
|
+
function FromSchemaType(K, T) {
|
|
1587
|
+
return (
|
|
1588
|
+
// unevaluated modifier types
|
|
1589
|
+
IsOptional$1(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) :
|
|
1590
|
+
IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) :
|
|
1591
|
+
// unevaluated mapped types
|
|
1592
|
+
IsMappedResult$1(T) ? FromMappedResult$9(K, T.properties) :
|
|
1593
|
+
IsMappedKey$1(T) ? FromMappedKey$3(K, T.keys) :
|
|
1594
|
+
// unevaluated types
|
|
1595
|
+
IsConstructor$1(T) ? Constructor(FromRest$6(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
1596
|
+
IsFunction$1(T) ? Function(FromRest$6(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
1597
|
+
IsAsyncIterator$1(T) ? AsyncIterator(FromSchemaType(K, T.items)) :
|
|
1598
|
+
IsIterator$1(T) ? Iterator(FromSchemaType(K, T.items)) :
|
|
1599
|
+
IsIntersect$1(T) ? Intersect(FromRest$6(K, T.allOf)) :
|
|
1600
|
+
IsUnion$1(T) ? Union(FromRest$6(K, T.anyOf)) :
|
|
1601
|
+
IsTuple$1(T) ? Tuple(FromRest$6(K, T.items ?? [])) :
|
|
1602
|
+
IsObject$1(T) ? Object$1(FromProperties$g(K, T.properties)) :
|
|
1603
|
+
IsArray$1(T) ? Array$1(FromSchemaType(K, T.items)) :
|
|
1604
|
+
IsPromise$1(T) ? Promise$1(FromSchemaType(K, T.item)) :
|
|
1605
|
+
T);
|
|
1606
|
+
}
|
|
1607
|
+
// prettier-ignore
|
|
1608
|
+
function MappedFunctionReturnType(K, T) {
|
|
1609
|
+
const Acc = {};
|
|
1610
|
+
for (const L of K)
|
|
1611
|
+
Acc[L] = FromSchemaType(L, T);
|
|
1612
|
+
return Acc;
|
|
1613
|
+
}
|
|
1614
|
+
/** `[Json]` Creates a Mapped object type */
|
|
1615
|
+
function Mapped(key, map, options = {}) {
|
|
1616
|
+
const K = IsSchema$1(key) ? IndexPropertyKeys(key) : key;
|
|
1617
|
+
const RT = map({ [Kind]: 'MappedKey', keys: K });
|
|
1618
|
+
const R = MappedFunctionReturnType(K, RT);
|
|
1619
|
+
return CloneType(Object$1(R), options);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
function RemoveOptional(schema) {
|
|
1623
|
+
return Discard(CloneType(schema), [OptionalKind]);
|
|
1624
|
+
}
|
|
1625
|
+
function AddOptional(schema) {
|
|
1626
|
+
return { ...CloneType(schema), [OptionalKind]: 'Optional' };
|
|
1627
|
+
}
|
|
1628
|
+
// prettier-ignore
|
|
1629
|
+
function OptionalWithFlag(schema, F) {
|
|
1630
|
+
return (F === false
|
|
1631
|
+
? RemoveOptional(schema)
|
|
1632
|
+
: AddOptional(schema));
|
|
1633
|
+
}
|
|
1634
|
+
/** `[Json]` Creates a Optional property */
|
|
1635
|
+
function Optional(schema, enable) {
|
|
1636
|
+
const F = enable ?? true;
|
|
1637
|
+
return IsMappedResult$1(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F);
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// prettier-ignore
|
|
1641
|
+
function FromProperties$f(P, F) {
|
|
1642
|
+
const Acc = {};
|
|
1643
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
1644
|
+
Acc[K2] = Optional(P[K2], F);
|
|
1645
|
+
return Acc;
|
|
1646
|
+
}
|
|
1647
|
+
// prettier-ignore
|
|
1648
|
+
function FromMappedResult$8(R, F) {
|
|
1649
|
+
return FromProperties$f(R.properties, F);
|
|
1650
|
+
}
|
|
1651
|
+
// prettier-ignore
|
|
1652
|
+
function OptionalFromMappedResult(R, F) {
|
|
1653
|
+
const P = FromMappedResult$8(R, F);
|
|
1654
|
+
return MappedResult(P);
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// ------------------------------------------------------------------
|
|
1658
|
+
// IntersectCreate
|
|
1659
|
+
// ------------------------------------------------------------------
|
|
1660
|
+
// prettier-ignore
|
|
1661
|
+
function IntersectCreate(T, options) {
|
|
1662
|
+
const allObjects = T.every((schema) => IsObject$1(schema));
|
|
1663
|
+
const clonedUnevaluatedProperties = IsSchema$1(options.unevaluatedProperties)
|
|
1664
|
+
? { unevaluatedProperties: CloneType(options.unevaluatedProperties) }
|
|
1665
|
+
: {};
|
|
1666
|
+
return ((options.unevaluatedProperties === false || IsSchema$1(options.unevaluatedProperties) || allObjects
|
|
1667
|
+
? { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', type: 'object', allOf: CloneRest(T) }
|
|
1668
|
+
: { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', allOf: CloneRest(T) }));
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// prettier-ignore
|
|
1672
|
+
function IsIntersectOptional(T) {
|
|
1673
|
+
return T.every(L => IsOptional$1(L));
|
|
1674
|
+
}
|
|
1675
|
+
// prettier-ignore
|
|
1676
|
+
function RemoveOptionalFromType(T) {
|
|
1677
|
+
return (Discard(T, [OptionalKind]));
|
|
1678
|
+
}
|
|
1679
|
+
// prettier-ignore
|
|
1680
|
+
function RemoveOptionalFromRest(T) {
|
|
1681
|
+
return T.map(L => IsOptional$1(L) ? RemoveOptionalFromType(L) : L);
|
|
1682
|
+
}
|
|
1683
|
+
// prettier-ignore
|
|
1684
|
+
function ResolveIntersect(T, options) {
|
|
1685
|
+
return (IsIntersectOptional(T)
|
|
1686
|
+
? Optional(IntersectCreate(RemoveOptionalFromRest(T), options))
|
|
1687
|
+
: IntersectCreate(RemoveOptionalFromRest(T), options));
|
|
1688
|
+
}
|
|
1689
|
+
/** `[Json]` Creates an evaluated Intersect type */
|
|
1690
|
+
function IntersectEvaluated(T, options = {}) {
|
|
1691
|
+
if (T.length === 0)
|
|
1692
|
+
return Never(options);
|
|
1693
|
+
if (T.length === 1)
|
|
1694
|
+
return CloneType(T[0], options);
|
|
1695
|
+
if (T.some((schema) => IsTransform$1(schema)))
|
|
1696
|
+
throw new Error('Cannot intersect transform types');
|
|
1697
|
+
return ResolveIntersect(T, options);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
/** `[Json]` Creates an evaluated Intersect type */
|
|
1701
|
+
function Intersect(T, options = {}) {
|
|
1702
|
+
if (T.length === 0)
|
|
1703
|
+
return Never(options);
|
|
1704
|
+
if (T.length === 1)
|
|
1705
|
+
return CloneType(T[0], options);
|
|
1706
|
+
if (T.some((schema) => IsTransform$1(schema)))
|
|
1707
|
+
throw new Error('Cannot intersect transform types');
|
|
1708
|
+
return IntersectCreate(T, options);
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
// prettier-ignore
|
|
1712
|
+
function FromRest$5(T) {
|
|
1713
|
+
return T.map(L => AwaitedResolve(L));
|
|
1714
|
+
}
|
|
1715
|
+
// prettier-ignore
|
|
1716
|
+
function FromIntersect$5(T) {
|
|
1717
|
+
return Intersect(FromRest$5(T));
|
|
1718
|
+
}
|
|
1719
|
+
// prettier-ignore
|
|
1720
|
+
function FromUnion$5(T) {
|
|
1721
|
+
return Union(FromRest$5(T));
|
|
1722
|
+
}
|
|
1723
|
+
// prettier-ignore
|
|
1724
|
+
function FromPromise$2(T) {
|
|
1725
|
+
return AwaitedResolve(T);
|
|
1726
|
+
}
|
|
1727
|
+
// ----------------------------------------------------------------
|
|
1728
|
+
// AwaitedResolve
|
|
1729
|
+
// ----------------------------------------------------------------
|
|
1730
|
+
// prettier-ignore
|
|
1731
|
+
function AwaitedResolve(T) {
|
|
1732
|
+
return (IsIntersect$1(T) ? FromIntersect$5(T.allOf) :
|
|
1733
|
+
IsUnion$1(T) ? FromUnion$5(T.anyOf) :
|
|
1734
|
+
IsPromise$1(T) ? FromPromise$2(T.item) :
|
|
1735
|
+
T);
|
|
1736
|
+
}
|
|
1737
|
+
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
1738
|
+
function Awaited(T, options = {}) {
|
|
1739
|
+
return CloneType(AwaitedResolve(T), options);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
// prettier-ignore
|
|
1743
|
+
function FromRest$4(T) {
|
|
1744
|
+
const Acc = [];
|
|
1745
|
+
for (const L of T)
|
|
1746
|
+
Acc.push(KeyOfPropertyKeys(L));
|
|
1747
|
+
return Acc;
|
|
1748
|
+
}
|
|
1749
|
+
// prettier-ignore
|
|
1750
|
+
function FromIntersect$4(T) {
|
|
1751
|
+
const C = FromRest$4(T);
|
|
1752
|
+
const R = SetUnionMany(C);
|
|
1753
|
+
return R;
|
|
1754
|
+
}
|
|
1755
|
+
// prettier-ignore
|
|
1756
|
+
function FromUnion$4(T) {
|
|
1757
|
+
const C = FromRest$4(T);
|
|
1758
|
+
const R = SetIntersectMany(C);
|
|
1759
|
+
return R;
|
|
1760
|
+
}
|
|
1761
|
+
// prettier-ignore
|
|
1762
|
+
function FromTuple$2(T) {
|
|
1763
|
+
return T.map((_, I) => I.toString());
|
|
1764
|
+
}
|
|
1765
|
+
// prettier-ignore
|
|
1766
|
+
function FromArray$3(_) {
|
|
1767
|
+
return (['[number]']);
|
|
1768
|
+
}
|
|
1769
|
+
// prettier-ignore
|
|
1770
|
+
function FromProperties$e(T) {
|
|
1771
|
+
return (globalThis.Object.getOwnPropertyNames(T));
|
|
1772
|
+
}
|
|
1773
|
+
// ------------------------------------------------------------------
|
|
1774
|
+
// FromPatternProperties
|
|
1775
|
+
// ------------------------------------------------------------------
|
|
1776
|
+
// prettier-ignore
|
|
1777
|
+
function FromPatternProperties(patternProperties) {
|
|
1778
|
+
return [];
|
|
1779
|
+
}
|
|
1780
|
+
/** Returns a tuple of PropertyKeys derived from the given TSchema. */
|
|
1781
|
+
// prettier-ignore
|
|
1782
|
+
function KeyOfPropertyKeys(T) {
|
|
1783
|
+
return (IsIntersect$1(T) ? FromIntersect$4(T.allOf) :
|
|
1784
|
+
IsUnion$1(T) ? FromUnion$4(T.anyOf) :
|
|
1785
|
+
IsTuple$1(T) ? FromTuple$2(T.items ?? []) :
|
|
1786
|
+
IsArray$1(T) ? FromArray$3(T.items) :
|
|
1787
|
+
IsObject$1(T) ? FromProperties$e(T.properties) :
|
|
1788
|
+
IsRecord$1(T) ? FromPatternProperties(T.patternProperties) :
|
|
1789
|
+
[]);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
// prettier-ignore
|
|
1793
|
+
function KeyOfPropertyKeysToRest(T) {
|
|
1794
|
+
return T.map(L => L === '[number]' ? Number() : Literal(L));
|
|
1795
|
+
}
|
|
1796
|
+
/** `[Json]` Creates a KeyOf type */
|
|
1797
|
+
function KeyOf(T, options = {}) {
|
|
1798
|
+
if (IsMappedResult$1(T)) {
|
|
1799
|
+
return KeyOfFromMappedResult(T, options);
|
|
1800
|
+
}
|
|
1801
|
+
else {
|
|
1802
|
+
const K = KeyOfPropertyKeys(T);
|
|
1803
|
+
const S = KeyOfPropertyKeysToRest(K);
|
|
1804
|
+
const U = UnionEvaluated(S);
|
|
1805
|
+
return CloneType(U, options);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
// prettier-ignore
|
|
1810
|
+
function FromProperties$d(K, options) {
|
|
1811
|
+
const Acc = {};
|
|
1812
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
1813
|
+
Acc[K2] = KeyOf(K[K2], options);
|
|
1814
|
+
return Acc;
|
|
1815
|
+
}
|
|
1816
|
+
// prettier-ignore
|
|
1817
|
+
function FromMappedResult$7(R, options) {
|
|
1818
|
+
return FromProperties$d(R.properties, options);
|
|
1819
|
+
}
|
|
1820
|
+
// prettier-ignore
|
|
1821
|
+
function KeyOfFromMappedResult(R, options) {
|
|
1822
|
+
const P = FromMappedResult$7(R, options);
|
|
1823
|
+
return MappedResult(P);
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// prettier-ignore
|
|
1827
|
+
function CompositeKeys(T) {
|
|
1828
|
+
const Acc = [];
|
|
1829
|
+
for (const L of T)
|
|
1830
|
+
Acc.push(...KeyOfPropertyKeys(L));
|
|
1831
|
+
return SetDistinct(Acc);
|
|
1832
|
+
}
|
|
1833
|
+
// prettier-ignore
|
|
1834
|
+
function FilterNever(T) {
|
|
1835
|
+
return T.filter(L => !IsNever$1(L));
|
|
1836
|
+
}
|
|
1837
|
+
// prettier-ignore
|
|
1838
|
+
function CompositeProperty(T, K) {
|
|
1839
|
+
const Acc = [];
|
|
1840
|
+
for (const L of T)
|
|
1841
|
+
Acc.push(...IndexFromPropertyKeys(L, [K]));
|
|
1842
|
+
return FilterNever(Acc);
|
|
1843
|
+
}
|
|
1844
|
+
// prettier-ignore
|
|
1845
|
+
function CompositeProperties(T, K) {
|
|
1846
|
+
const Acc = {};
|
|
1847
|
+
for (const L of K) {
|
|
1848
|
+
Acc[L] = IntersectEvaluated(CompositeProperty(T, L));
|
|
1849
|
+
}
|
|
1850
|
+
return Acc;
|
|
1851
|
+
}
|
|
1852
|
+
// prettier-ignore
|
|
1853
|
+
function Composite(T, options = {}) {
|
|
1854
|
+
const K = CompositeKeys(T);
|
|
1855
|
+
const P = CompositeProperties(T, K);
|
|
1856
|
+
const R = Object$1(P, options);
|
|
1857
|
+
return R;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
/** `[JavaScript]` Creates a Date type */
|
|
1861
|
+
function Date$1(options = {}) {
|
|
1862
|
+
return {
|
|
1863
|
+
...options,
|
|
1864
|
+
[Kind]: 'Date',
|
|
1865
|
+
type: 'Date',
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
/** `[Json]` Creates a Null type */
|
|
1870
|
+
function Null(options = {}) {
|
|
1871
|
+
return {
|
|
1872
|
+
...options,
|
|
1873
|
+
[Kind]: 'Null',
|
|
1874
|
+
type: 'null',
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
/** `[JavaScript]` Creates a Symbol type */
|
|
1879
|
+
function Symbol$1(options) {
|
|
1880
|
+
return { ...options, [Kind]: 'Symbol', type: 'symbol' };
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
/** `[JavaScript]` Creates a Undefined type */
|
|
1884
|
+
function Undefined(options = {}) {
|
|
1885
|
+
return { ...options, [Kind]: 'Undefined', type: 'undefined' };
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
/** `[JavaScript]` Creates a Uint8Array type */
|
|
1889
|
+
function Uint8Array$1(options = {}) {
|
|
1890
|
+
return { ...options, [Kind]: 'Uint8Array', type: 'Uint8Array' };
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
/** `[Json]` Creates an Unknown type */
|
|
1894
|
+
function Unknown(options = {}) {
|
|
1895
|
+
return {
|
|
1896
|
+
...options,
|
|
1897
|
+
[Kind]: 'Unknown',
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// prettier-ignore
|
|
1902
|
+
function FromArray$2(T) {
|
|
1903
|
+
return T.map(L => FromValue(L, false));
|
|
1904
|
+
}
|
|
1905
|
+
// prettier-ignore
|
|
1906
|
+
function FromProperties$c(value) {
|
|
1907
|
+
const Acc = {};
|
|
1908
|
+
for (const K of globalThis.Object.getOwnPropertyNames(value))
|
|
1909
|
+
Acc[K] = Readonly(FromValue(value[K], false));
|
|
1910
|
+
return Acc;
|
|
1911
|
+
}
|
|
1912
|
+
function ConditionalReadonly(T, root) {
|
|
1913
|
+
return (root === true ? T : Readonly(T));
|
|
1914
|
+
}
|
|
1915
|
+
// prettier-ignore
|
|
1916
|
+
function FromValue(value, root) {
|
|
1917
|
+
return (IsAsyncIterator$2(value) ? ConditionalReadonly(Any(), root) :
|
|
1918
|
+
IsIterator$2(value) ? ConditionalReadonly(Any(), root) :
|
|
1919
|
+
IsArray$2(value) ? Readonly(Tuple(FromArray$2(value))) :
|
|
1920
|
+
IsUint8Array$2(value) ? Uint8Array$1() :
|
|
1921
|
+
IsDate$2(value) ? Date$1() :
|
|
1922
|
+
IsObject$2(value) ? ConditionalReadonly(Object$1(FromProperties$c(value)), root) :
|
|
1923
|
+
IsFunction$2(value) ? ConditionalReadonly(Function([], Unknown()), root) :
|
|
1924
|
+
IsUndefined$2(value) ? Undefined() :
|
|
1925
|
+
IsNull$2(value) ? Null() :
|
|
1926
|
+
IsSymbol$2(value) ? Symbol$1() :
|
|
1927
|
+
IsBigInt$2(value) ? BigInt() :
|
|
1928
|
+
IsNumber$2(value) ? Literal(value) :
|
|
1929
|
+
IsBoolean$2(value) ? Literal(value) :
|
|
1930
|
+
IsString$2(value) ? Literal(value) :
|
|
1931
|
+
Object$1({}));
|
|
1932
|
+
}
|
|
1933
|
+
/** `[JavaScript]` Creates a readonly const type from the given value. */
|
|
1934
|
+
function Const(T, options = {}) {
|
|
1935
|
+
return CloneType(FromValue(T, true), options);
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
1939
|
+
function ConstructorParameters(schema, options = {}) {
|
|
1940
|
+
return Tuple(CloneRest(schema.parameters), { ...options });
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
function FromRest$3(schema, references) {
|
|
1944
|
+
return schema.map((schema) => Deref(schema, references));
|
|
1945
|
+
}
|
|
1946
|
+
// prettier-ignore
|
|
1947
|
+
function FromProperties$b(properties, references) {
|
|
1948
|
+
const Acc = {};
|
|
1949
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties)) {
|
|
1950
|
+
Acc[K] = Deref(properties[K], references);
|
|
1951
|
+
}
|
|
1952
|
+
return Acc;
|
|
1953
|
+
}
|
|
1954
|
+
// prettier-ignore
|
|
1955
|
+
function FromConstructor$1(schema, references) {
|
|
1956
|
+
schema.parameters = FromRest$3(schema.parameters, references);
|
|
1957
|
+
schema.returns = Deref(schema.returns, references);
|
|
1958
|
+
return schema;
|
|
1959
|
+
}
|
|
1960
|
+
// prettier-ignore
|
|
1961
|
+
function FromFunction$1(schema, references) {
|
|
1962
|
+
schema.parameters = FromRest$3(schema.parameters, references);
|
|
1963
|
+
schema.returns = Deref(schema.returns, references);
|
|
1964
|
+
return schema;
|
|
1965
|
+
}
|
|
1966
|
+
// prettier-ignore
|
|
1967
|
+
function FromIntersect$3(schema, references) {
|
|
1968
|
+
schema.allOf = FromRest$3(schema.allOf, references);
|
|
1969
|
+
return schema;
|
|
1970
|
+
}
|
|
1971
|
+
// prettier-ignore
|
|
1972
|
+
function FromUnion$3(schema, references) {
|
|
1973
|
+
schema.anyOf = FromRest$3(schema.anyOf, references);
|
|
1974
|
+
return schema;
|
|
1975
|
+
}
|
|
1976
|
+
// prettier-ignore
|
|
1977
|
+
function FromTuple$1(schema, references) {
|
|
1978
|
+
if (IsUndefined$2(schema.items))
|
|
1979
|
+
return schema;
|
|
1980
|
+
schema.items = FromRest$3(schema.items, references);
|
|
1981
|
+
return schema;
|
|
1982
|
+
}
|
|
1983
|
+
// prettier-ignore
|
|
1984
|
+
function FromArray$1(schema, references) {
|
|
1985
|
+
schema.items = Deref(schema.items, references);
|
|
1986
|
+
return schema;
|
|
1987
|
+
}
|
|
1988
|
+
// prettier-ignore
|
|
1989
|
+
function FromObject$1(schema, references) {
|
|
1990
|
+
schema.properties = FromProperties$b(schema.properties, references);
|
|
1991
|
+
return schema;
|
|
1992
|
+
}
|
|
1993
|
+
// prettier-ignore
|
|
1994
|
+
function FromPromise$1(schema, references) {
|
|
1995
|
+
schema.item = Deref(schema.item, references);
|
|
1996
|
+
return schema;
|
|
1997
|
+
}
|
|
1998
|
+
// prettier-ignore
|
|
1999
|
+
function FromAsyncIterator$1(schema, references) {
|
|
2000
|
+
schema.items = Deref(schema.items, references);
|
|
2001
|
+
return schema;
|
|
2002
|
+
}
|
|
2003
|
+
// prettier-ignore
|
|
2004
|
+
function FromIterator$1(schema, references) {
|
|
2005
|
+
schema.items = Deref(schema.items, references);
|
|
2006
|
+
return schema;
|
|
2007
|
+
}
|
|
2008
|
+
// prettier-ignore
|
|
2009
|
+
function FromRef(schema, references) {
|
|
2010
|
+
const target = references.find(remote => remote.$id === schema.$ref);
|
|
2011
|
+
if (target === undefined)
|
|
2012
|
+
throw Error(`Unable to dereference schema with $id ${schema.$ref}`);
|
|
2013
|
+
const discard = Discard(target, ['$id']);
|
|
2014
|
+
return Deref(discard, references);
|
|
2015
|
+
}
|
|
2016
|
+
// prettier-ignore
|
|
2017
|
+
function DerefResolve(schema, references) {
|
|
2018
|
+
return (IsConstructor$1(schema) ? FromConstructor$1(schema, references) :
|
|
2019
|
+
IsFunction$1(schema) ? FromFunction$1(schema, references) :
|
|
2020
|
+
IsIntersect$1(schema) ? FromIntersect$3(schema, references) :
|
|
2021
|
+
IsUnion$1(schema) ? FromUnion$3(schema, references) :
|
|
2022
|
+
IsTuple$1(schema) ? FromTuple$1(schema, references) :
|
|
2023
|
+
IsArray$1(schema) ? FromArray$1(schema, references) :
|
|
2024
|
+
IsObject$1(schema) ? FromObject$1(schema, references) :
|
|
2025
|
+
IsPromise$1(schema) ? FromPromise$1(schema, references) :
|
|
2026
|
+
IsAsyncIterator$1(schema) ? FromAsyncIterator$1(schema, references) :
|
|
2027
|
+
IsIterator$1(schema) ? FromIterator$1(schema, references) :
|
|
2028
|
+
IsRef$1(schema) ? FromRef(schema, references) :
|
|
2029
|
+
schema);
|
|
2030
|
+
}
|
|
2031
|
+
// ------------------------------------------------------------------
|
|
2032
|
+
// TDeref
|
|
2033
|
+
// ------------------------------------------------------------------
|
|
2034
|
+
/** `[Json]` Creates a dereferenced type */
|
|
2035
|
+
function Deref(schema, references) {
|
|
2036
|
+
return DerefResolve(CloneType(schema), CloneRest(references));
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
/** `[Json]` Creates a Enum type */
|
|
2040
|
+
function Enum(item, options = {}) {
|
|
2041
|
+
if (IsUndefined$2(item))
|
|
2042
|
+
throw new Error('Enum undefined or empty');
|
|
2043
|
+
const values1 = globalThis.Object.getOwnPropertyNames(item)
|
|
2044
|
+
.filter((key) => isNaN(key))
|
|
2045
|
+
.map((key) => item[key]);
|
|
2046
|
+
const values2 = [...new Set(values1)];
|
|
2047
|
+
const anyOf = values2.map((value) => Literal(value));
|
|
2048
|
+
return Union(anyOf, { ...options, [Hint]: 'Enum' });
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
class ExtendsResolverError extends TypeBoxError {
|
|
2052
|
+
}
|
|
2053
|
+
var ExtendsResult;
|
|
2054
|
+
(function (ExtendsResult) {
|
|
2055
|
+
ExtendsResult[ExtendsResult["Union"] = 0] = "Union";
|
|
2056
|
+
ExtendsResult[ExtendsResult["True"] = 1] = "True";
|
|
2057
|
+
ExtendsResult[ExtendsResult["False"] = 2] = "False";
|
|
2058
|
+
})(ExtendsResult || (ExtendsResult = {}));
|
|
2059
|
+
// ------------------------------------------------------------------
|
|
2060
|
+
// IntoBooleanResult
|
|
2061
|
+
// ------------------------------------------------------------------
|
|
2062
|
+
// prettier-ignore
|
|
2063
|
+
function IntoBooleanResult(result) {
|
|
2064
|
+
return result === ExtendsResult.False ? result : ExtendsResult.True;
|
|
2065
|
+
}
|
|
2066
|
+
// ------------------------------------------------------------------
|
|
2067
|
+
// Throw
|
|
2068
|
+
// ------------------------------------------------------------------
|
|
2069
|
+
// prettier-ignore
|
|
2070
|
+
function Throw(message) {
|
|
2071
|
+
throw new ExtendsResolverError(message);
|
|
2072
|
+
}
|
|
2073
|
+
// ------------------------------------------------------------------
|
|
2074
|
+
// StructuralRight
|
|
2075
|
+
// ------------------------------------------------------------------
|
|
2076
|
+
// prettier-ignore
|
|
2077
|
+
function IsStructuralRight(right) {
|
|
2078
|
+
return (IsNever(right) ||
|
|
2079
|
+
IsIntersect(right) ||
|
|
2080
|
+
IsUnion(right) ||
|
|
2081
|
+
IsUnknown(right) ||
|
|
2082
|
+
IsAny(right));
|
|
2083
|
+
}
|
|
2084
|
+
// prettier-ignore
|
|
2085
|
+
function StructuralRight(left, right) {
|
|
2086
|
+
return (IsNever(right) ? FromNeverRight() :
|
|
2087
|
+
IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
2088
|
+
IsUnion(right) ? FromUnionRight(left, right) :
|
|
2089
|
+
IsUnknown(right) ? FromUnknownRight() :
|
|
2090
|
+
IsAny(right) ? FromAnyRight() :
|
|
2091
|
+
Throw('StructuralRight'));
|
|
2092
|
+
}
|
|
2093
|
+
// ------------------------------------------------------------------
|
|
2094
|
+
// Any
|
|
2095
|
+
// ------------------------------------------------------------------
|
|
2096
|
+
// prettier-ignore
|
|
2097
|
+
function FromAnyRight(left, right) {
|
|
2098
|
+
return ExtendsResult.True;
|
|
2099
|
+
}
|
|
2100
|
+
// prettier-ignore
|
|
2101
|
+
function FromAny(left, right) {
|
|
2102
|
+
return (IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
2103
|
+
(IsUnion(right) && right.anyOf.some((schema) => IsAny(schema) || IsUnknown(schema))) ? ExtendsResult.True :
|
|
2104
|
+
IsUnion(right) ? ExtendsResult.Union :
|
|
2105
|
+
IsUnknown(right) ? ExtendsResult.True :
|
|
2106
|
+
IsAny(right) ? ExtendsResult.True :
|
|
2107
|
+
ExtendsResult.Union);
|
|
2108
|
+
}
|
|
2109
|
+
// ------------------------------------------------------------------
|
|
2110
|
+
// Array
|
|
2111
|
+
// ------------------------------------------------------------------
|
|
2112
|
+
// prettier-ignore
|
|
2113
|
+
function FromArrayRight(left, right) {
|
|
2114
|
+
return (IsUnknown(left) ? ExtendsResult.False :
|
|
2115
|
+
IsAny(left) ? ExtendsResult.Union :
|
|
2116
|
+
IsNever(left) ? ExtendsResult.True :
|
|
2117
|
+
ExtendsResult.False);
|
|
2118
|
+
}
|
|
2119
|
+
// prettier-ignore
|
|
2120
|
+
function FromArray(left, right) {
|
|
2121
|
+
return (IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
2122
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2123
|
+
!IsArray(right) ? ExtendsResult.False :
|
|
2124
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
2125
|
+
}
|
|
2126
|
+
// ------------------------------------------------------------------
|
|
2127
|
+
// AsyncIterator
|
|
2128
|
+
// ------------------------------------------------------------------
|
|
2129
|
+
// prettier-ignore
|
|
2130
|
+
function FromAsyncIterator(left, right) {
|
|
2131
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2132
|
+
!IsAsyncIterator(right) ? ExtendsResult.False :
|
|
2133
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
2134
|
+
}
|
|
2135
|
+
// ------------------------------------------------------------------
|
|
2136
|
+
// BigInt
|
|
2137
|
+
// ------------------------------------------------------------------
|
|
2138
|
+
// prettier-ignore
|
|
2139
|
+
function FromBigInt(left, right) {
|
|
2140
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2141
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2142
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2143
|
+
IsBigInt(right) ? ExtendsResult.True :
|
|
2144
|
+
ExtendsResult.False);
|
|
2145
|
+
}
|
|
2146
|
+
// ------------------------------------------------------------------
|
|
2147
|
+
// Boolean
|
|
2148
|
+
// ------------------------------------------------------------------
|
|
2149
|
+
// prettier-ignore
|
|
2150
|
+
function FromBooleanRight(left, right) {
|
|
2151
|
+
return (IsLiteralBoolean(left) ? ExtendsResult.True :
|
|
2152
|
+
IsBoolean(left) ? ExtendsResult.True :
|
|
2153
|
+
ExtendsResult.False);
|
|
2154
|
+
}
|
|
2155
|
+
// prettier-ignore
|
|
2156
|
+
function FromBoolean(left, right) {
|
|
2157
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2158
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2159
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2160
|
+
IsBoolean(right) ? ExtendsResult.True :
|
|
2161
|
+
ExtendsResult.False);
|
|
2162
|
+
}
|
|
2163
|
+
// ------------------------------------------------------------------
|
|
2164
|
+
// Constructor
|
|
2165
|
+
// ------------------------------------------------------------------
|
|
2166
|
+
// prettier-ignore
|
|
2167
|
+
function FromConstructor(left, right) {
|
|
2168
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2169
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2170
|
+
!IsConstructor(right) ? ExtendsResult.False :
|
|
2171
|
+
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
2172
|
+
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
2173
|
+
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
2174
|
+
}
|
|
2175
|
+
// ------------------------------------------------------------------
|
|
2176
|
+
// Date
|
|
2177
|
+
// ------------------------------------------------------------------
|
|
2178
|
+
// prettier-ignore
|
|
2179
|
+
function FromDate(left, right) {
|
|
2180
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2181
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2182
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2183
|
+
IsDate(right) ? ExtendsResult.True :
|
|
2184
|
+
ExtendsResult.False);
|
|
2185
|
+
}
|
|
2186
|
+
// ------------------------------------------------------------------
|
|
2187
|
+
// Function
|
|
2188
|
+
// ------------------------------------------------------------------
|
|
2189
|
+
// prettier-ignore
|
|
2190
|
+
function FromFunction(left, right) {
|
|
2191
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2192
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2193
|
+
!IsFunction(right) ? ExtendsResult.False :
|
|
2194
|
+
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
2195
|
+
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
2196
|
+
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
2197
|
+
}
|
|
2198
|
+
// ------------------------------------------------------------------
|
|
2199
|
+
// Integer
|
|
2200
|
+
// ------------------------------------------------------------------
|
|
2201
|
+
// prettier-ignore
|
|
2202
|
+
function FromIntegerRight(left, right) {
|
|
2203
|
+
return (IsLiteral(left) && IsNumber$2(left.const) ? ExtendsResult.True :
|
|
2204
|
+
IsNumber(left) || IsInteger(left) ? ExtendsResult.True :
|
|
2205
|
+
ExtendsResult.False);
|
|
2206
|
+
}
|
|
2207
|
+
// prettier-ignore
|
|
2208
|
+
function FromInteger(left, right) {
|
|
2209
|
+
return (IsInteger(right) || IsNumber(right) ? ExtendsResult.True :
|
|
2210
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2211
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2212
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2213
|
+
ExtendsResult.False);
|
|
2214
|
+
}
|
|
2215
|
+
// ------------------------------------------------------------------
|
|
2216
|
+
// Intersect
|
|
2217
|
+
// ------------------------------------------------------------------
|
|
2218
|
+
// prettier-ignore
|
|
2219
|
+
function FromIntersectRight(left, right) {
|
|
2220
|
+
return right.allOf.every((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
2221
|
+
? ExtendsResult.True
|
|
2222
|
+
: ExtendsResult.False;
|
|
2223
|
+
}
|
|
2224
|
+
// prettier-ignore
|
|
2225
|
+
function FromIntersect$2(left, right) {
|
|
2226
|
+
return left.allOf.some((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
2227
|
+
? ExtendsResult.True
|
|
2228
|
+
: ExtendsResult.False;
|
|
2229
|
+
}
|
|
2230
|
+
// ------------------------------------------------------------------
|
|
2231
|
+
// Iterator
|
|
2232
|
+
// ------------------------------------------------------------------
|
|
2233
|
+
// prettier-ignore
|
|
2234
|
+
function FromIterator(left, right) {
|
|
2235
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2236
|
+
!IsIterator(right) ? ExtendsResult.False :
|
|
2237
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
2238
|
+
}
|
|
2239
|
+
// ------------------------------------------------------------------
|
|
2240
|
+
// Literal
|
|
2241
|
+
// ------------------------------------------------------------------
|
|
2242
|
+
// prettier-ignore
|
|
2243
|
+
function FromLiteral(left, right) {
|
|
2244
|
+
return (IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
|
|
2245
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2246
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2247
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2248
|
+
IsString(right) ? FromStringRight(left) :
|
|
2249
|
+
IsNumber(right) ? FromNumberRight(left) :
|
|
2250
|
+
IsInteger(right) ? FromIntegerRight(left) :
|
|
2251
|
+
IsBoolean(right) ? FromBooleanRight(left) :
|
|
2252
|
+
ExtendsResult.False);
|
|
2253
|
+
}
|
|
2254
|
+
// ------------------------------------------------------------------
|
|
2255
|
+
// Never
|
|
2256
|
+
// ------------------------------------------------------------------
|
|
2257
|
+
// prettier-ignore
|
|
2258
|
+
function FromNeverRight(left, right) {
|
|
2259
|
+
return ExtendsResult.False;
|
|
2260
|
+
}
|
|
2261
|
+
// prettier-ignore
|
|
2262
|
+
function FromNever(left, right) {
|
|
2263
|
+
return ExtendsResult.True;
|
|
2264
|
+
}
|
|
2265
|
+
// ------------------------------------------------------------------
|
|
2266
|
+
// Not
|
|
2267
|
+
// ------------------------------------------------------------------
|
|
2268
|
+
// prettier-ignore
|
|
2269
|
+
function UnwrapTNot(schema) {
|
|
2270
|
+
let [current, depth] = [schema, 0];
|
|
2271
|
+
while (true) {
|
|
2272
|
+
if (!IsNot(current))
|
|
2273
|
+
break;
|
|
2274
|
+
current = current.not;
|
|
2275
|
+
depth += 1;
|
|
2276
|
+
}
|
|
2277
|
+
return depth % 2 === 0 ? current : Unknown();
|
|
2278
|
+
}
|
|
2279
|
+
// prettier-ignore
|
|
2280
|
+
function FromNot(left, right) {
|
|
2281
|
+
// TypeScript has no concept of negated types, and attempts to correctly check the negated
|
|
2282
|
+
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
2283
|
+
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
2284
|
+
// prettier-ignore
|
|
2285
|
+
return (IsNot(left) ? Visit(UnwrapTNot(left), right) :
|
|
2286
|
+
IsNot(right) ? Visit(left, UnwrapTNot(right)) :
|
|
2287
|
+
Throw('Invalid fallthrough for Not'));
|
|
2288
|
+
}
|
|
2289
|
+
// ------------------------------------------------------------------
|
|
2290
|
+
// Null
|
|
2291
|
+
// ------------------------------------------------------------------
|
|
2292
|
+
// prettier-ignore
|
|
2293
|
+
function FromNull(left, right) {
|
|
2294
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2295
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2296
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2297
|
+
IsNull(right) ? ExtendsResult.True :
|
|
2298
|
+
ExtendsResult.False);
|
|
2299
|
+
}
|
|
2300
|
+
// ------------------------------------------------------------------
|
|
2301
|
+
// Number
|
|
2302
|
+
// ------------------------------------------------------------------
|
|
2303
|
+
// prettier-ignore
|
|
2304
|
+
function FromNumberRight(left, right) {
|
|
2305
|
+
return (IsLiteralNumber(left) ? ExtendsResult.True :
|
|
2306
|
+
IsNumber(left) || IsInteger(left) ? ExtendsResult.True :
|
|
2307
|
+
ExtendsResult.False);
|
|
2308
|
+
}
|
|
2309
|
+
// prettier-ignore
|
|
2310
|
+
function FromNumber(left, right) {
|
|
2311
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2312
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2313
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2314
|
+
IsInteger(right) || IsNumber(right) ? ExtendsResult.True :
|
|
2315
|
+
ExtendsResult.False);
|
|
2316
|
+
}
|
|
2317
|
+
// ------------------------------------------------------------------
|
|
2318
|
+
// Object
|
|
2319
|
+
// ------------------------------------------------------------------
|
|
2320
|
+
// prettier-ignore
|
|
2321
|
+
function IsObjectPropertyCount(schema, count) {
|
|
2322
|
+
return Object.getOwnPropertyNames(schema.properties).length === count;
|
|
2323
|
+
}
|
|
2324
|
+
// prettier-ignore
|
|
2325
|
+
function IsObjectStringLike(schema) {
|
|
2326
|
+
return IsObjectArrayLike(schema);
|
|
2327
|
+
}
|
|
2328
|
+
// prettier-ignore
|
|
2329
|
+
function IsObjectSymbolLike(schema) {
|
|
2330
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties && IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && ((IsString(schema.properties.description.anyOf[0]) &&
|
|
2331
|
+
IsUndefined(schema.properties.description.anyOf[1])) || (IsString(schema.properties.description.anyOf[1]) &&
|
|
2332
|
+
IsUndefined(schema.properties.description.anyOf[0]))));
|
|
2333
|
+
}
|
|
2334
|
+
// prettier-ignore
|
|
2335
|
+
function IsObjectNumberLike(schema) {
|
|
2336
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2337
|
+
}
|
|
2338
|
+
// prettier-ignore
|
|
2339
|
+
function IsObjectBooleanLike(schema) {
|
|
2340
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2341
|
+
}
|
|
2342
|
+
// prettier-ignore
|
|
2343
|
+
function IsObjectBigIntLike(schema) {
|
|
2344
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2345
|
+
}
|
|
2346
|
+
// prettier-ignore
|
|
2347
|
+
function IsObjectDateLike(schema) {
|
|
2348
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2349
|
+
}
|
|
2350
|
+
// prettier-ignore
|
|
2351
|
+
function IsObjectUint8ArrayLike(schema) {
|
|
2352
|
+
return IsObjectArrayLike(schema);
|
|
2353
|
+
}
|
|
2354
|
+
// prettier-ignore
|
|
2355
|
+
function IsObjectFunctionLike(schema) {
|
|
2356
|
+
const length = Number();
|
|
2357
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'length' in schema.properties && IntoBooleanResult(Visit(schema.properties['length'], length)) === ExtendsResult.True);
|
|
2358
|
+
}
|
|
2359
|
+
// prettier-ignore
|
|
2360
|
+
function IsObjectConstructorLike(schema) {
|
|
2361
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2362
|
+
}
|
|
2363
|
+
// prettier-ignore
|
|
2364
|
+
function IsObjectArrayLike(schema) {
|
|
2365
|
+
const length = Number();
|
|
2366
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'length' in schema.properties && IntoBooleanResult(Visit(schema.properties['length'], length)) === ExtendsResult.True);
|
|
2367
|
+
}
|
|
2368
|
+
// prettier-ignore
|
|
2369
|
+
function IsObjectPromiseLike(schema) {
|
|
2370
|
+
const then = Function([Any()], Any());
|
|
2371
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'then' in schema.properties && IntoBooleanResult(Visit(schema.properties['then'], then)) === ExtendsResult.True);
|
|
2372
|
+
}
|
|
2373
|
+
// ------------------------------------------------------------------
|
|
2374
|
+
// Property
|
|
2375
|
+
// ------------------------------------------------------------------
|
|
2376
|
+
// prettier-ignore
|
|
2377
|
+
function Property(left, right) {
|
|
2378
|
+
return (Visit(left, right) === ExtendsResult.False ? ExtendsResult.False :
|
|
2379
|
+
IsOptional(left) && !IsOptional(right) ? ExtendsResult.False :
|
|
2380
|
+
ExtendsResult.True);
|
|
2381
|
+
}
|
|
2382
|
+
// prettier-ignore
|
|
2383
|
+
function FromObjectRight(left, right) {
|
|
2384
|
+
return (IsUnknown(left) ? ExtendsResult.False :
|
|
2385
|
+
IsAny(left) ? ExtendsResult.Union : (IsNever(left) ||
|
|
2386
|
+
(IsLiteralString(left) && IsObjectStringLike(right)) ||
|
|
2387
|
+
(IsLiteralNumber(left) && IsObjectNumberLike(right)) ||
|
|
2388
|
+
(IsLiteralBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
2389
|
+
(IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
2390
|
+
(IsBigInt(left) && IsObjectBigIntLike(right)) ||
|
|
2391
|
+
(IsString(left) && IsObjectStringLike(right)) ||
|
|
2392
|
+
(IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
2393
|
+
(IsNumber(left) && IsObjectNumberLike(right)) ||
|
|
2394
|
+
(IsInteger(left) && IsObjectNumberLike(right)) ||
|
|
2395
|
+
(IsBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
2396
|
+
(IsUint8Array(left) && IsObjectUint8ArrayLike(right)) ||
|
|
2397
|
+
(IsDate(left) && IsObjectDateLike(right)) ||
|
|
2398
|
+
(IsConstructor(left) && IsObjectConstructorLike(right)) ||
|
|
2399
|
+
(IsFunction(left) && IsObjectFunctionLike(right))) ? ExtendsResult.True :
|
|
2400
|
+
(IsRecord(left) && IsString(RecordKey(left))) ? (() => {
|
|
2401
|
+
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
2402
|
+
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
2403
|
+
return right[Hint] === 'Record' ? ExtendsResult.True : ExtendsResult.False;
|
|
2404
|
+
})() :
|
|
2405
|
+
(IsRecord(left) && IsNumber(RecordKey(left))) ? (() => {
|
|
2406
|
+
return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
|
|
2407
|
+
})() :
|
|
2408
|
+
ExtendsResult.False);
|
|
2409
|
+
}
|
|
2410
|
+
// prettier-ignore
|
|
2411
|
+
function FromObject(left, right) {
|
|
2412
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2413
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2414
|
+
!IsObject(right) ? ExtendsResult.False :
|
|
2415
|
+
(() => {
|
|
2416
|
+
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
2417
|
+
if (!(key in left.properties) && !IsOptional(right.properties[key])) {
|
|
2418
|
+
return ExtendsResult.False;
|
|
2419
|
+
}
|
|
2420
|
+
if (IsOptional(right.properties[key])) {
|
|
2421
|
+
return ExtendsResult.True;
|
|
2422
|
+
}
|
|
2423
|
+
if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
|
|
2424
|
+
return ExtendsResult.False;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
return ExtendsResult.True;
|
|
2428
|
+
})());
|
|
2429
|
+
}
|
|
2430
|
+
// ------------------------------------------------------------------
|
|
2431
|
+
// Promise
|
|
2432
|
+
// ------------------------------------------------------------------
|
|
2433
|
+
// prettier-ignore
|
|
2434
|
+
function FromPromise(left, right) {
|
|
2435
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2436
|
+
IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
|
|
2437
|
+
!IsPromise(right) ? ExtendsResult.False :
|
|
2438
|
+
IntoBooleanResult(Visit(left.item, right.item)));
|
|
2439
|
+
}
|
|
2440
|
+
// ------------------------------------------------------------------
|
|
2441
|
+
// Record
|
|
2442
|
+
// ------------------------------------------------------------------
|
|
2443
|
+
// prettier-ignore
|
|
2444
|
+
function RecordKey(schema) {
|
|
2445
|
+
return (PatternNumberExact in schema.patternProperties ? Number() :
|
|
2446
|
+
PatternStringExact in schema.patternProperties ? String() :
|
|
2447
|
+
Throw('Unknown record key pattern'));
|
|
2448
|
+
}
|
|
2449
|
+
// prettier-ignore
|
|
2450
|
+
function RecordValue(schema) {
|
|
2451
|
+
return (PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] :
|
|
2452
|
+
PatternStringExact in schema.patternProperties ? schema.patternProperties[PatternStringExact] :
|
|
2453
|
+
Throw('Unable to get record value schema'));
|
|
2454
|
+
}
|
|
2455
|
+
// prettier-ignore
|
|
2456
|
+
function FromRecordRight(left, right) {
|
|
2457
|
+
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
2458
|
+
return ((IsLiteralString(left) && IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
|
|
2459
|
+
IsUint8Array(left) && IsNumber(Key) ? Visit(left, Value) :
|
|
2460
|
+
IsString(left) && IsNumber(Key) ? Visit(left, Value) :
|
|
2461
|
+
IsArray(left) && IsNumber(Key) ? Visit(left, Value) :
|
|
2462
|
+
IsObject(left) ? (() => {
|
|
2463
|
+
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
2464
|
+
if (Property(Value, left.properties[key]) === ExtendsResult.False) {
|
|
2465
|
+
return ExtendsResult.False;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
return ExtendsResult.True;
|
|
2469
|
+
})() :
|
|
2470
|
+
ExtendsResult.False);
|
|
2471
|
+
}
|
|
2472
|
+
// prettier-ignore
|
|
2473
|
+
function FromRecord(left, right) {
|
|
2474
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2475
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2476
|
+
!IsRecord(right) ? ExtendsResult.False :
|
|
2477
|
+
Visit(RecordValue(left), RecordValue(right)));
|
|
2478
|
+
}
|
|
2479
|
+
// ------------------------------------------------------------------
|
|
2480
|
+
// RegExp
|
|
2481
|
+
// ------------------------------------------------------------------
|
|
2482
|
+
// prettier-ignore
|
|
2483
|
+
function FromRegExp(left, right) {
|
|
2484
|
+
// Note: RegExp types evaluate as strings, not RegExp objects.
|
|
2485
|
+
// Here we remap either into string and continue evaluating.
|
|
2486
|
+
const L = IsRegExp(left) ? String() : left;
|
|
2487
|
+
const R = IsRegExp(right) ? String() : right;
|
|
2488
|
+
return Visit(L, R);
|
|
2489
|
+
}
|
|
2490
|
+
// ------------------------------------------------------------------
|
|
2491
|
+
// String
|
|
2492
|
+
// ------------------------------------------------------------------
|
|
2493
|
+
// prettier-ignore
|
|
2494
|
+
function FromStringRight(left, right) {
|
|
2495
|
+
return (IsLiteral(left) && IsString$2(left.const) ? ExtendsResult.True :
|
|
2496
|
+
IsString(left) ? ExtendsResult.True :
|
|
2497
|
+
ExtendsResult.False);
|
|
2498
|
+
}
|
|
2499
|
+
// prettier-ignore
|
|
2500
|
+
function FromString(left, right) {
|
|
2501
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2502
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2503
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2504
|
+
IsString(right) ? ExtendsResult.True :
|
|
2505
|
+
ExtendsResult.False);
|
|
2506
|
+
}
|
|
2507
|
+
// ------------------------------------------------------------------
|
|
2508
|
+
// Symbol
|
|
2509
|
+
// ------------------------------------------------------------------
|
|
2510
|
+
// prettier-ignore
|
|
2511
|
+
function FromSymbol(left, right) {
|
|
2512
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2513
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2514
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2515
|
+
IsSymbol(right) ? ExtendsResult.True :
|
|
2516
|
+
ExtendsResult.False);
|
|
2517
|
+
}
|
|
2518
|
+
// ------------------------------------------------------------------
|
|
2519
|
+
// TemplateLiteral
|
|
2520
|
+
// ------------------------------------------------------------------
|
|
2521
|
+
// prettier-ignore
|
|
2522
|
+
function FromTemplateLiteral$1(left, right) {
|
|
2523
|
+
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
2524
|
+
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
2525
|
+
// either type and continue evaluating.
|
|
2526
|
+
return (IsTemplateLiteral(left) ? Visit(TemplateLiteralToUnion(left), right) :
|
|
2527
|
+
IsTemplateLiteral(right) ? Visit(left, TemplateLiteralToUnion(right)) :
|
|
2528
|
+
Throw('Invalid fallthrough for TemplateLiteral'));
|
|
2529
|
+
}
|
|
2530
|
+
// ------------------------------------------------------------------
|
|
2531
|
+
// Tuple
|
|
2532
|
+
// ------------------------------------------------------------------
|
|
2533
|
+
// prettier-ignore
|
|
2534
|
+
function IsArrayOfTuple(left, right) {
|
|
2535
|
+
return (IsArray(right) &&
|
|
2536
|
+
left.items !== undefined &&
|
|
2537
|
+
left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
|
|
2538
|
+
}
|
|
2539
|
+
// prettier-ignore
|
|
2540
|
+
function FromTupleRight(left, right) {
|
|
2541
|
+
return (IsNever(left) ? ExtendsResult.True :
|
|
2542
|
+
IsUnknown(left) ? ExtendsResult.False :
|
|
2543
|
+
IsAny(left) ? ExtendsResult.Union :
|
|
2544
|
+
ExtendsResult.False);
|
|
2545
|
+
}
|
|
2546
|
+
// prettier-ignore
|
|
2547
|
+
function FromTuple(left, right) {
|
|
2548
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2549
|
+
IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
2550
|
+
IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
|
|
2551
|
+
!IsTuple(right) ? ExtendsResult.False :
|
|
2552
|
+
(IsUndefined$2(left.items) && !IsUndefined$2(right.items)) || (!IsUndefined$2(left.items) && IsUndefined$2(right.items)) ? ExtendsResult.False :
|
|
2553
|
+
(IsUndefined$2(left.items) && !IsUndefined$2(right.items)) ? ExtendsResult.True :
|
|
2554
|
+
left.items.every((schema, index) => Visit(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True :
|
|
2555
|
+
ExtendsResult.False);
|
|
2556
|
+
}
|
|
2557
|
+
// ------------------------------------------------------------------
|
|
2558
|
+
// Uint8Array
|
|
2559
|
+
// ------------------------------------------------------------------
|
|
2560
|
+
// prettier-ignore
|
|
2561
|
+
function FromUint8Array(left, right) {
|
|
2562
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2563
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2564
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2565
|
+
IsUint8Array(right) ? ExtendsResult.True :
|
|
2566
|
+
ExtendsResult.False);
|
|
2567
|
+
}
|
|
2568
|
+
// ------------------------------------------------------------------
|
|
2569
|
+
// Undefined
|
|
2570
|
+
// ------------------------------------------------------------------
|
|
2571
|
+
// prettier-ignore
|
|
2572
|
+
function FromUndefined(left, right) {
|
|
2573
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
2574
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2575
|
+
IsRecord(right) ? FromRecordRight(left, right) :
|
|
2576
|
+
IsVoid(right) ? FromVoidRight(left) :
|
|
2577
|
+
IsUndefined(right) ? ExtendsResult.True :
|
|
2578
|
+
ExtendsResult.False);
|
|
2579
|
+
}
|
|
2580
|
+
// ------------------------------------------------------------------
|
|
2581
|
+
// Union
|
|
2582
|
+
// ------------------------------------------------------------------
|
|
2583
|
+
// prettier-ignore
|
|
2584
|
+
function FromUnionRight(left, right) {
|
|
2585
|
+
return right.anyOf.some((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
2586
|
+
? ExtendsResult.True
|
|
2587
|
+
: ExtendsResult.False;
|
|
2588
|
+
}
|
|
2589
|
+
// prettier-ignore
|
|
2590
|
+
function FromUnion$2(left, right) {
|
|
2591
|
+
return left.anyOf.every((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
2592
|
+
? ExtendsResult.True
|
|
2593
|
+
: ExtendsResult.False;
|
|
2594
|
+
}
|
|
2595
|
+
// ------------------------------------------------------------------
|
|
2596
|
+
// Unknown
|
|
2597
|
+
// ------------------------------------------------------------------
|
|
2598
|
+
// prettier-ignore
|
|
2599
|
+
function FromUnknownRight(left, right) {
|
|
2600
|
+
return ExtendsResult.True;
|
|
2601
|
+
}
|
|
2602
|
+
// prettier-ignore
|
|
2603
|
+
function FromUnknown(left, right) {
|
|
2604
|
+
return (IsNever(right) ? FromNeverRight() :
|
|
2605
|
+
IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
2606
|
+
IsUnion(right) ? FromUnionRight(left, right) :
|
|
2607
|
+
IsAny(right) ? FromAnyRight() :
|
|
2608
|
+
IsString(right) ? FromStringRight(left) :
|
|
2609
|
+
IsNumber(right) ? FromNumberRight(left) :
|
|
2610
|
+
IsInteger(right) ? FromIntegerRight(left) :
|
|
2611
|
+
IsBoolean(right) ? FromBooleanRight(left) :
|
|
2612
|
+
IsArray(right) ? FromArrayRight(left) :
|
|
2613
|
+
IsTuple(right) ? FromTupleRight(left) :
|
|
2614
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2615
|
+
IsUnknown(right) ? ExtendsResult.True :
|
|
2616
|
+
ExtendsResult.False);
|
|
2617
|
+
}
|
|
2618
|
+
// ------------------------------------------------------------------
|
|
2619
|
+
// Void
|
|
2620
|
+
// ------------------------------------------------------------------
|
|
2621
|
+
// prettier-ignore
|
|
2622
|
+
function FromVoidRight(left, right) {
|
|
2623
|
+
return (IsUndefined(left) ? ExtendsResult.True :
|
|
2624
|
+
IsUndefined(left) ? ExtendsResult.True :
|
|
2625
|
+
ExtendsResult.False);
|
|
2626
|
+
}
|
|
2627
|
+
// prettier-ignore
|
|
2628
|
+
function FromVoid(left, right) {
|
|
2629
|
+
return (IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
2630
|
+
IsUnion(right) ? FromUnionRight(left, right) :
|
|
2631
|
+
IsUnknown(right) ? FromUnknownRight() :
|
|
2632
|
+
IsAny(right) ? FromAnyRight() :
|
|
2633
|
+
IsObject(right) ? FromObjectRight(left, right) :
|
|
2634
|
+
IsVoid(right) ? ExtendsResult.True :
|
|
2635
|
+
ExtendsResult.False);
|
|
2636
|
+
}
|
|
2637
|
+
// prettier-ignore
|
|
2638
|
+
function Visit(left, right) {
|
|
2639
|
+
return (
|
|
2640
|
+
// resolvable
|
|
2641
|
+
(IsTemplateLiteral(left) || IsTemplateLiteral(right)) ? FromTemplateLiteral$1(left, right) :
|
|
2642
|
+
(IsRegExp(left) || IsRegExp(right)) ? FromRegExp(left, right) :
|
|
2643
|
+
(IsNot(left) || IsNot(right)) ? FromNot(left, right) :
|
|
2644
|
+
// standard
|
|
2645
|
+
IsAny(left) ? FromAny(left, right) :
|
|
2646
|
+
IsArray(left) ? FromArray(left, right) :
|
|
2647
|
+
IsBigInt(left) ? FromBigInt(left, right) :
|
|
2648
|
+
IsBoolean(left) ? FromBoolean(left, right) :
|
|
2649
|
+
IsAsyncIterator(left) ? FromAsyncIterator(left, right) :
|
|
2650
|
+
IsConstructor(left) ? FromConstructor(left, right) :
|
|
2651
|
+
IsDate(left) ? FromDate(left, right) :
|
|
2652
|
+
IsFunction(left) ? FromFunction(left, right) :
|
|
2653
|
+
IsInteger(left) ? FromInteger(left, right) :
|
|
2654
|
+
IsIntersect(left) ? FromIntersect$2(left, right) :
|
|
2655
|
+
IsIterator(left) ? FromIterator(left, right) :
|
|
2656
|
+
IsLiteral(left) ? FromLiteral(left, right) :
|
|
2657
|
+
IsNever(left) ? FromNever() :
|
|
2658
|
+
IsNull(left) ? FromNull(left, right) :
|
|
2659
|
+
IsNumber(left) ? FromNumber(left, right) :
|
|
2660
|
+
IsObject(left) ? FromObject(left, right) :
|
|
2661
|
+
IsRecord(left) ? FromRecord(left, right) :
|
|
2662
|
+
IsString(left) ? FromString(left, right) :
|
|
2663
|
+
IsSymbol(left) ? FromSymbol(left, right) :
|
|
2664
|
+
IsTuple(left) ? FromTuple(left, right) :
|
|
2665
|
+
IsPromise(left) ? FromPromise(left, right) :
|
|
2666
|
+
IsUint8Array(left) ? FromUint8Array(left, right) :
|
|
2667
|
+
IsUndefined(left) ? FromUndefined(left, right) :
|
|
2668
|
+
IsUnion(left) ? FromUnion$2(left, right) :
|
|
2669
|
+
IsUnknown(left) ? FromUnknown(left, right) :
|
|
2670
|
+
IsVoid(left) ? FromVoid(left, right) :
|
|
2671
|
+
Throw(`Unknown left type operand '${left[Kind]}'`));
|
|
2672
|
+
}
|
|
2673
|
+
function ExtendsCheck(left, right) {
|
|
2674
|
+
return Visit(left, right);
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
// prettier-ignore
|
|
2678
|
+
function FromProperties$a(P, Right, True, False, options) {
|
|
2679
|
+
const Acc = {};
|
|
2680
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2681
|
+
Acc[K2] = Extends(P[K2], Right, True, False, options);
|
|
2682
|
+
return Acc;
|
|
2683
|
+
}
|
|
2684
|
+
// prettier-ignore
|
|
2685
|
+
function FromMappedResult$6(Left, Right, True, False, options) {
|
|
2686
|
+
return FromProperties$a(Left.properties, Right, True, False, options);
|
|
2687
|
+
}
|
|
2688
|
+
// prettier-ignore
|
|
2689
|
+
function ExtendsFromMappedResult(Left, Right, True, False, options) {
|
|
2690
|
+
const P = FromMappedResult$6(Left, Right, True, False, options);
|
|
2691
|
+
return MappedResult(P);
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
// prettier-ignore
|
|
2695
|
+
function ExtendsResolve(left, right, trueType, falseType) {
|
|
2696
|
+
const R = ExtendsCheck(left, right);
|
|
2697
|
+
return (R === ExtendsResult.Union ? Union([trueType, falseType]) :
|
|
2698
|
+
R === ExtendsResult.True ? trueType :
|
|
2699
|
+
falseType);
|
|
2700
|
+
}
|
|
2701
|
+
/** `[Json]` Creates a Conditional type */
|
|
2702
|
+
function Extends(L, R, T, F, options = {}) {
|
|
2703
|
+
// prettier-ignore
|
|
2704
|
+
return (IsMappedResult$1(L) ? ExtendsFromMappedResult(L, R, T, F, options) :
|
|
2705
|
+
IsMappedKey$1(L) ? CloneType(ExtendsFromMappedKey(L, R, T, F, options)) :
|
|
2706
|
+
CloneType(ExtendsResolve(L, R, T, F), options));
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
// prettier-ignore
|
|
2710
|
+
function FromPropertyKey$2(K, U, L, R, options) {
|
|
2711
|
+
return {
|
|
2712
|
+
[K]: Extends(Literal(K), U, L, R, options)
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
// prettier-ignore
|
|
2716
|
+
function FromPropertyKeys$2(K, U, L, R, options) {
|
|
2717
|
+
return K.reduce((Acc, LK) => {
|
|
2718
|
+
return { ...Acc, ...FromPropertyKey$2(LK, U, L, R, options) };
|
|
2719
|
+
}, {});
|
|
2720
|
+
}
|
|
2721
|
+
// prettier-ignore
|
|
2722
|
+
function FromMappedKey$2(K, U, L, R, options) {
|
|
2723
|
+
return FromPropertyKeys$2(K.keys, U, L, R, options);
|
|
2724
|
+
}
|
|
2725
|
+
// prettier-ignore
|
|
2726
|
+
function ExtendsFromMappedKey(T, U, L, R, options) {
|
|
2727
|
+
const P = FromMappedKey$2(T, U, L, R, options);
|
|
2728
|
+
return MappedResult(P);
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
function ExcludeFromTemplateLiteral(L, R) {
|
|
2732
|
+
return Exclude(TemplateLiteralToUnion(L), R);
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
function ExcludeRest(L, R) {
|
|
2736
|
+
const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
|
|
2737
|
+
return excluded.length === 1 ? excluded[0] : Union(excluded);
|
|
2738
|
+
}
|
|
2739
|
+
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
2740
|
+
function Exclude(L, R, options = {}) {
|
|
2741
|
+
// overloads
|
|
2742
|
+
if (IsTemplateLiteral$1(L))
|
|
2743
|
+
return CloneType(ExcludeFromTemplateLiteral(L, R), options);
|
|
2744
|
+
if (IsMappedResult$1(L))
|
|
2745
|
+
return CloneType(ExcludeFromMappedResult(L, R), options);
|
|
2746
|
+
// prettier-ignore
|
|
2747
|
+
return CloneType(IsUnion$1(L) ? ExcludeRest(L.anyOf, R) :
|
|
2748
|
+
ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
// prettier-ignore
|
|
2752
|
+
function FromProperties$9(P, U) {
|
|
2753
|
+
const Acc = {};
|
|
2754
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2755
|
+
Acc[K2] = Exclude(P[K2], U);
|
|
2756
|
+
return Acc;
|
|
2757
|
+
}
|
|
2758
|
+
// prettier-ignore
|
|
2759
|
+
function FromMappedResult$5(R, T) {
|
|
2760
|
+
return FromProperties$9(R.properties, T);
|
|
2761
|
+
}
|
|
2762
|
+
// prettier-ignore
|
|
2763
|
+
function ExcludeFromMappedResult(R, T) {
|
|
2764
|
+
const P = FromMappedResult$5(R, T);
|
|
2765
|
+
return MappedResult(P);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
function ExtractFromTemplateLiteral(L, R) {
|
|
2769
|
+
return Extract(TemplateLiteralToUnion(L), R);
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
function ExtractRest(L, R) {
|
|
2773
|
+
const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
|
|
2774
|
+
return extracted.length === 1 ? extracted[0] : Union(extracted);
|
|
2775
|
+
}
|
|
2776
|
+
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
2777
|
+
function Extract(L, R, options = {}) {
|
|
2778
|
+
// overloads
|
|
2779
|
+
if (IsTemplateLiteral$1(L))
|
|
2780
|
+
return CloneType(ExtractFromTemplateLiteral(L, R), options);
|
|
2781
|
+
if (IsMappedResult$1(L))
|
|
2782
|
+
return CloneType(ExtractFromMappedResult(L, R), options);
|
|
2783
|
+
// prettier-ignore
|
|
2784
|
+
return CloneType(IsUnion$1(L) ? ExtractRest(L.anyOf, R) :
|
|
2785
|
+
ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
// prettier-ignore
|
|
2789
|
+
function FromProperties$8(P, T) {
|
|
2790
|
+
const Acc = {};
|
|
2791
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2792
|
+
Acc[K2] = Extract(P[K2], T);
|
|
2793
|
+
return Acc;
|
|
2794
|
+
}
|
|
2795
|
+
// prettier-ignore
|
|
2796
|
+
function FromMappedResult$4(R, T) {
|
|
2797
|
+
return FromProperties$8(R.properties, T);
|
|
2798
|
+
}
|
|
2799
|
+
// prettier-ignore
|
|
2800
|
+
function ExtractFromMappedResult(R, T) {
|
|
2801
|
+
const P = FromMappedResult$4(R, T);
|
|
2802
|
+
return MappedResult(P);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
2806
|
+
function InstanceType(schema, options = {}) {
|
|
2807
|
+
return CloneType(schema.returns, options);
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
/** `[Json]` Creates an Integer type */
|
|
2811
|
+
function Integer(options = {}) {
|
|
2812
|
+
return {
|
|
2813
|
+
...options,
|
|
2814
|
+
[Kind]: 'Integer',
|
|
2815
|
+
type: 'integer',
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
// prettier-ignore
|
|
2820
|
+
function MappedIntrinsicPropertyKey(K, M, options) {
|
|
2821
|
+
return {
|
|
2822
|
+
[K]: Intrinsic(Literal(K), M, options)
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
// prettier-ignore
|
|
2826
|
+
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
2827
|
+
return K.reduce((Acc, L) => {
|
|
2828
|
+
return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
|
|
2829
|
+
}, {});
|
|
2830
|
+
}
|
|
2831
|
+
// prettier-ignore
|
|
2832
|
+
function MappedIntrinsicProperties(T, M, options) {
|
|
2833
|
+
return MappedIntrinsicPropertyKeys(T['keys'], M, options);
|
|
2834
|
+
}
|
|
2835
|
+
// prettier-ignore
|
|
2836
|
+
function IntrinsicFromMappedKey(T, M, options) {
|
|
2837
|
+
const P = MappedIntrinsicProperties(T, M, options);
|
|
2838
|
+
return MappedResult(P);
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
// ------------------------------------------------------------------
|
|
2842
|
+
// Apply
|
|
2843
|
+
// ------------------------------------------------------------------
|
|
2844
|
+
function ApplyUncapitalize(value) {
|
|
2845
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
2846
|
+
return [first.toLowerCase(), rest].join('');
|
|
2847
|
+
}
|
|
2848
|
+
function ApplyCapitalize(value) {
|
|
2849
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
2850
|
+
return [first.toUpperCase(), rest].join('');
|
|
2851
|
+
}
|
|
2852
|
+
function ApplyUppercase(value) {
|
|
2853
|
+
return value.toUpperCase();
|
|
2854
|
+
}
|
|
2855
|
+
function ApplyLowercase(value) {
|
|
2856
|
+
return value.toLowerCase();
|
|
2857
|
+
}
|
|
2858
|
+
function FromTemplateLiteral(schema, mode, options) {
|
|
2859
|
+
// note: template literals require special runtime handling as they are encoded in string patterns.
|
|
2860
|
+
// This diverges from the mapped type which would otherwise map on the template literal kind.
|
|
2861
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
2862
|
+
const finite = IsTemplateLiteralExpressionFinite(expression);
|
|
2863
|
+
if (!finite)
|
|
2864
|
+
return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
|
|
2865
|
+
const strings = [...TemplateLiteralExpressionGenerate(expression)];
|
|
2866
|
+
const literals = strings.map((value) => Literal(value));
|
|
2867
|
+
const mapped = FromRest$2(literals, mode);
|
|
2868
|
+
const union = Union(mapped);
|
|
2869
|
+
return TemplateLiteral([union], options);
|
|
2870
|
+
}
|
|
2871
|
+
// prettier-ignore
|
|
2872
|
+
function FromLiteralValue(value, mode) {
|
|
2873
|
+
return (typeof value === 'string' ? (mode === 'Uncapitalize' ? ApplyUncapitalize(value) :
|
|
2874
|
+
mode === 'Capitalize' ? ApplyCapitalize(value) :
|
|
2875
|
+
mode === 'Uppercase' ? ApplyUppercase(value) :
|
|
2876
|
+
mode === 'Lowercase' ? ApplyLowercase(value) :
|
|
2877
|
+
value) : value.toString());
|
|
2878
|
+
}
|
|
2879
|
+
// prettier-ignore
|
|
2880
|
+
function FromRest$2(T, M) {
|
|
2881
|
+
return T.map(L => Intrinsic(L, M));
|
|
2882
|
+
}
|
|
2883
|
+
/** Applies an intrinsic string manipulation to the given type. */
|
|
2884
|
+
function Intrinsic(schema, mode, options = {}) {
|
|
2885
|
+
// prettier-ignore
|
|
2886
|
+
return (
|
|
2887
|
+
// Intrinsic-Mapped-Inference
|
|
2888
|
+
IsMappedKey$1(schema) ? IntrinsicFromMappedKey(schema, mode, options) :
|
|
2889
|
+
// Standard-Inference
|
|
2890
|
+
IsTemplateLiteral$1(schema) ? FromTemplateLiteral(schema, mode, schema) :
|
|
2891
|
+
IsUnion$1(schema) ? Union(FromRest$2(schema.anyOf, mode), options) :
|
|
2892
|
+
IsLiteral$1(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
|
|
2893
|
+
schema);
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
2897
|
+
function Capitalize(T, options = {}) {
|
|
2898
|
+
return Intrinsic(T, 'Capitalize', options);
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
2902
|
+
function Lowercase(T, options = {}) {
|
|
2903
|
+
return Intrinsic(T, 'Lowercase', options);
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
2907
|
+
function Uncapitalize(T, options = {}) {
|
|
2908
|
+
return Intrinsic(T, 'Uncapitalize', options);
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
2912
|
+
function Uppercase(T, options = {}) {
|
|
2913
|
+
return Intrinsic(T, 'Uppercase', options);
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
/** `[Json]` Creates a Not type */
|
|
2917
|
+
function Not(schema, options) {
|
|
2918
|
+
return {
|
|
2919
|
+
...options,
|
|
2920
|
+
[Kind]: 'Not',
|
|
2921
|
+
not: CloneType(schema),
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
// prettier-ignore
|
|
2926
|
+
function FromProperties$7(P, K, options) {
|
|
2927
|
+
const Acc = {};
|
|
2928
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2929
|
+
Acc[K2] = Omit(P[K2], K, options);
|
|
2930
|
+
return Acc;
|
|
2931
|
+
}
|
|
2932
|
+
// prettier-ignore
|
|
2933
|
+
function FromMappedResult$3(R, K, options) {
|
|
2934
|
+
return FromProperties$7(R.properties, K, options);
|
|
2935
|
+
}
|
|
2936
|
+
// prettier-ignore
|
|
2937
|
+
function OmitFromMappedResult(R, K, options) {
|
|
2938
|
+
const P = FromMappedResult$3(R, K, options);
|
|
2939
|
+
return MappedResult(P);
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
// prettier-ignore
|
|
2943
|
+
function FromIntersect$1(T, K) {
|
|
2944
|
+
return T.map((T) => OmitResolve(T, K));
|
|
2945
|
+
}
|
|
2946
|
+
// prettier-ignore
|
|
2947
|
+
function FromUnion$1(T, K) {
|
|
2948
|
+
return T.map((T) => OmitResolve(T, K));
|
|
2949
|
+
}
|
|
2950
|
+
// ------------------------------------------------------------------
|
|
2951
|
+
// FromProperty
|
|
2952
|
+
// ------------------------------------------------------------------
|
|
2953
|
+
// prettier-ignore
|
|
2954
|
+
function FromProperty(T, K) {
|
|
2955
|
+
const { [K]: _, ...R } = T;
|
|
2956
|
+
return R;
|
|
2957
|
+
}
|
|
2958
|
+
// prettier-ignore
|
|
2959
|
+
function FromProperties$6(T, K) {
|
|
2960
|
+
return K.reduce((T, K2) => FromProperty(T, K2), T);
|
|
2961
|
+
}
|
|
2962
|
+
// ------------------------------------------------------------------
|
|
2963
|
+
// OmitResolve
|
|
2964
|
+
// ------------------------------------------------------------------
|
|
2965
|
+
// prettier-ignore
|
|
2966
|
+
function OmitResolve(T, K) {
|
|
2967
|
+
return (IsIntersect$1(T) ? Intersect(FromIntersect$1(T.allOf, K)) :
|
|
2968
|
+
IsUnion$1(T) ? Union(FromUnion$1(T.anyOf, K)) :
|
|
2969
|
+
IsObject$1(T) ? Object$1(FromProperties$6(T.properties, K)) :
|
|
2970
|
+
Object$1({}));
|
|
2971
|
+
}
|
|
2972
|
+
function Omit(T, K, options = {}) {
|
|
2973
|
+
// mapped
|
|
2974
|
+
if (IsMappedKey$1(K))
|
|
2975
|
+
return OmitFromMappedKey(T, K, options);
|
|
2976
|
+
if (IsMappedResult$1(T))
|
|
2977
|
+
return OmitFromMappedResult(T, K, options);
|
|
2978
|
+
// non-mapped
|
|
2979
|
+
const I = IsSchema$1(K) ? IndexPropertyKeys(K) : K;
|
|
2980
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
2981
|
+
const R = CloneType(OmitResolve(T, I), options);
|
|
2982
|
+
return { ...D, ...R };
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
// prettier-ignore
|
|
2986
|
+
function FromPropertyKey$1(T, K, options) {
|
|
2987
|
+
return {
|
|
2988
|
+
[K]: Omit(T, [K], options)
|
|
2989
|
+
};
|
|
2990
|
+
}
|
|
2991
|
+
// prettier-ignore
|
|
2992
|
+
function FromPropertyKeys$1(T, K, options) {
|
|
2993
|
+
return K.reduce((Acc, LK) => {
|
|
2994
|
+
return { ...Acc, ...FromPropertyKey$1(T, LK, options) };
|
|
2995
|
+
}, {});
|
|
2996
|
+
}
|
|
2997
|
+
// prettier-ignore
|
|
2998
|
+
function FromMappedKey$1(T, K, options) {
|
|
2999
|
+
return FromPropertyKeys$1(T, K.keys, options);
|
|
3000
|
+
}
|
|
3001
|
+
// prettier-ignore
|
|
3002
|
+
function OmitFromMappedKey(T, K, options) {
|
|
3003
|
+
const P = FromMappedKey$1(T, K, options);
|
|
3004
|
+
return MappedResult(P);
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
3008
|
+
function Parameters(schema, options = {}) {
|
|
3009
|
+
return Tuple(CloneRest(schema.parameters), { ...options });
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// prettier-ignore
|
|
3013
|
+
function FromRest$1(T) {
|
|
3014
|
+
return T.map(L => PartialResolve(L));
|
|
3015
|
+
}
|
|
3016
|
+
// prettier-ignore
|
|
3017
|
+
function FromProperties$5(T) {
|
|
3018
|
+
const Acc = {};
|
|
3019
|
+
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
3020
|
+
Acc[K] = Optional(T[K]);
|
|
3021
|
+
return Acc;
|
|
3022
|
+
}
|
|
3023
|
+
// ------------------------------------------------------------------
|
|
3024
|
+
// PartialResolve
|
|
3025
|
+
// ------------------------------------------------------------------
|
|
3026
|
+
// prettier-ignore
|
|
3027
|
+
function PartialResolve(T) {
|
|
3028
|
+
return (IsIntersect$1(T) ? Intersect(FromRest$1(T.allOf)) :
|
|
3029
|
+
IsUnion$1(T) ? Union(FromRest$1(T.anyOf)) :
|
|
3030
|
+
IsObject$1(T) ? Object$1(FromProperties$5(T.properties)) :
|
|
3031
|
+
Object$1({}));
|
|
3032
|
+
}
|
|
3033
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
3034
|
+
function Partial(T, options = {}) {
|
|
3035
|
+
if (IsMappedResult$1(T))
|
|
3036
|
+
return PartialFromMappedResult(T, options);
|
|
3037
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
3038
|
+
const R = CloneType(PartialResolve(T), options);
|
|
3039
|
+
return { ...D, ...R };
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
// prettier-ignore
|
|
3043
|
+
function FromProperties$4(K, options) {
|
|
3044
|
+
const Acc = {};
|
|
3045
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
3046
|
+
Acc[K2] = Partial(K[K2], options);
|
|
3047
|
+
return Acc;
|
|
3048
|
+
}
|
|
3049
|
+
// prettier-ignore
|
|
3050
|
+
function FromMappedResult$2(R, options) {
|
|
3051
|
+
return FromProperties$4(R.properties, options);
|
|
3052
|
+
}
|
|
3053
|
+
// prettier-ignore
|
|
3054
|
+
function PartialFromMappedResult(R, options) {
|
|
3055
|
+
const P = FromMappedResult$2(R, options);
|
|
3056
|
+
return MappedResult(P);
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
// prettier-ignore
|
|
3060
|
+
function FromProperties$3(P, K, options) {
|
|
3061
|
+
const Acc = {};
|
|
3062
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
3063
|
+
Acc[K2] = Pick(P[K2], K, options);
|
|
3064
|
+
return Acc;
|
|
3065
|
+
}
|
|
3066
|
+
// prettier-ignore
|
|
3067
|
+
function FromMappedResult$1(R, K, options) {
|
|
3068
|
+
return FromProperties$3(R.properties, K, options);
|
|
3069
|
+
}
|
|
3070
|
+
// prettier-ignore
|
|
3071
|
+
function PickFromMappedResult(R, K, options) {
|
|
3072
|
+
const P = FromMappedResult$1(R, K, options);
|
|
3073
|
+
return MappedResult(P);
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
function FromIntersect(T, K) {
|
|
3077
|
+
return T.map((T) => PickResolve(T, K));
|
|
3078
|
+
}
|
|
3079
|
+
// prettier-ignore
|
|
3080
|
+
function FromUnion(T, K) {
|
|
3081
|
+
return T.map((T) => PickResolve(T, K));
|
|
3082
|
+
}
|
|
3083
|
+
// prettier-ignore
|
|
3084
|
+
function FromProperties$2(T, K) {
|
|
3085
|
+
const Acc = {};
|
|
3086
|
+
for (const K2 of K)
|
|
3087
|
+
if (K2 in T)
|
|
3088
|
+
Acc[K2] = T[K2];
|
|
3089
|
+
return Acc;
|
|
3090
|
+
}
|
|
3091
|
+
// ------------------------------------------------------------------
|
|
3092
|
+
// PickResolve
|
|
3093
|
+
// ------------------------------------------------------------------
|
|
3094
|
+
// prettier-ignore
|
|
3095
|
+
function PickResolve(T, K) {
|
|
3096
|
+
return (IsIntersect$1(T) ? Intersect(FromIntersect(T.allOf, K)) :
|
|
3097
|
+
IsUnion$1(T) ? Union(FromUnion(T.anyOf, K)) :
|
|
3098
|
+
IsObject$1(T) ? Object$1(FromProperties$2(T.properties, K)) :
|
|
3099
|
+
Object$1({}));
|
|
3100
|
+
}
|
|
3101
|
+
function Pick(T, K, options = {}) {
|
|
3102
|
+
// mapped
|
|
3103
|
+
if (IsMappedKey$1(K))
|
|
3104
|
+
return PickFromMappedKey(T, K, options);
|
|
3105
|
+
if (IsMappedResult$1(T))
|
|
3106
|
+
return PickFromMappedResult(T, K, options);
|
|
3107
|
+
// non-mapped
|
|
3108
|
+
const I = IsSchema$1(K) ? IndexPropertyKeys(K) : K;
|
|
3109
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
3110
|
+
const R = CloneType(PickResolve(T, I), options);
|
|
3111
|
+
return { ...D, ...R };
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
// prettier-ignore
|
|
3115
|
+
function FromPropertyKey(T, K, options) {
|
|
3116
|
+
return {
|
|
3117
|
+
[K]: Pick(T, [K], options)
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
// prettier-ignore
|
|
3121
|
+
function FromPropertyKeys(T, K, options) {
|
|
3122
|
+
return K.reduce((Acc, LK) => {
|
|
3123
|
+
return { ...Acc, ...FromPropertyKey(T, LK, options) };
|
|
3124
|
+
}, {});
|
|
3125
|
+
}
|
|
3126
|
+
// prettier-ignore
|
|
3127
|
+
function FromMappedKey(T, K, options) {
|
|
3128
|
+
return FromPropertyKeys(T, K.keys, options);
|
|
3129
|
+
}
|
|
3130
|
+
// prettier-ignore
|
|
3131
|
+
function PickFromMappedKey(T, K, options) {
|
|
3132
|
+
const P = FromMappedKey(T, K, options);
|
|
3133
|
+
return MappedResult(P);
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
/** `[Json]` Creates a Readonly and Optional property */
|
|
3137
|
+
function ReadonlyOptional(schema) {
|
|
3138
|
+
return Readonly(Optional(schema));
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
// ------------------------------------------------------------------
|
|
3142
|
+
// RecordCreateFromPattern
|
|
3143
|
+
// ------------------------------------------------------------------
|
|
3144
|
+
// prettier-ignore
|
|
3145
|
+
function RecordCreateFromPattern(pattern, T, options) {
|
|
3146
|
+
return {
|
|
3147
|
+
...options,
|
|
3148
|
+
[Kind]: 'Record',
|
|
3149
|
+
type: 'object',
|
|
3150
|
+
patternProperties: { [pattern]: CloneType(T) }
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
// ------------------------------------------------------------------
|
|
3154
|
+
// RecordCreateFromKeys
|
|
3155
|
+
// ------------------------------------------------------------------
|
|
3156
|
+
// prettier-ignore
|
|
3157
|
+
function RecordCreateFromKeys(K, T, options) {
|
|
3158
|
+
const Acc = {};
|
|
3159
|
+
for (const K2 of K)
|
|
3160
|
+
Acc[K2] = CloneType(T);
|
|
3161
|
+
return Object$1(Acc, { ...options, [Hint]: 'Record' });
|
|
3162
|
+
}
|
|
3163
|
+
// prettier-ignore
|
|
3164
|
+
function FromTemplateLiteralKey(K, T, options) {
|
|
3165
|
+
return (IsTemplateLiteralFinite(K)
|
|
3166
|
+
? RecordCreateFromKeys(IndexPropertyKeys(K), T, options)
|
|
3167
|
+
: RecordCreateFromPattern(K.pattern, T, options));
|
|
3168
|
+
}
|
|
3169
|
+
// prettier-ignore
|
|
3170
|
+
function FromUnionKey(K, T, options) {
|
|
3171
|
+
return RecordCreateFromKeys(IndexPropertyKeys(Union(K)), T, options);
|
|
3172
|
+
}
|
|
3173
|
+
// prettier-ignore
|
|
3174
|
+
function FromLiteralKey(K, T, options) {
|
|
3175
|
+
return RecordCreateFromKeys([K.toString()], T, options);
|
|
3176
|
+
}
|
|
3177
|
+
// prettier-ignore
|
|
3178
|
+
function FromRegExpKey(K, T, options) {
|
|
3179
|
+
return RecordCreateFromPattern(K.source, T, options);
|
|
3180
|
+
}
|
|
3181
|
+
// prettier-ignore
|
|
3182
|
+
function FromStringKey(K, T, options) {
|
|
3183
|
+
const pattern = IsUndefined$2(K.pattern) ? PatternStringExact : K.pattern;
|
|
3184
|
+
return RecordCreateFromPattern(pattern, T, options);
|
|
3185
|
+
}
|
|
3186
|
+
// prettier-ignore
|
|
3187
|
+
function FromAnyKey(K, T, options) {
|
|
3188
|
+
return RecordCreateFromPattern(PatternStringExact, T, options);
|
|
3189
|
+
}
|
|
3190
|
+
// prettier-ignore
|
|
3191
|
+
function FromNeverKey(K, T, options) {
|
|
3192
|
+
return RecordCreateFromPattern(PatternNeverExact, T, options);
|
|
3193
|
+
}
|
|
3194
|
+
// prettier-ignore
|
|
3195
|
+
function FromIntegerKey(_, T, options) {
|
|
3196
|
+
return RecordCreateFromPattern(PatternNumberExact, T, options);
|
|
3197
|
+
}
|
|
3198
|
+
// prettier-ignore
|
|
3199
|
+
function FromNumberKey(_, T, options) {
|
|
3200
|
+
return RecordCreateFromPattern(PatternNumberExact, T, options);
|
|
3201
|
+
}
|
|
3202
|
+
// ------------------------------------------------------------------
|
|
3203
|
+
// TRecordOrObject
|
|
3204
|
+
// ------------------------------------------------------------------
|
|
3205
|
+
/** `[Json]` Creates a Record type */
|
|
3206
|
+
function Record(K, T, options = {}) {
|
|
3207
|
+
// prettier-ignore
|
|
3208
|
+
return (IsUnion$1(K) ? FromUnionKey(K.anyOf, T, options) :
|
|
3209
|
+
IsTemplateLiteral$1(K) ? FromTemplateLiteralKey(K, T, options) :
|
|
3210
|
+
IsLiteral$1(K) ? FromLiteralKey(K.const, T, options) :
|
|
3211
|
+
IsInteger$1(K) ? FromIntegerKey(K, T, options) :
|
|
3212
|
+
IsNumber$1(K) ? FromNumberKey(K, T, options) :
|
|
3213
|
+
IsRegExp$1(K) ? FromRegExpKey(K, T, options) :
|
|
3214
|
+
IsString$1(K) ? FromStringKey(K, T, options) :
|
|
3215
|
+
IsAny$1(K) ? FromAnyKey(K, T, options) :
|
|
3216
|
+
IsNever$1(K) ? FromNeverKey(K, T, options) :
|
|
3217
|
+
Never(options));
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
// Auto Tracked For Recursive Types without ID's
|
|
3221
|
+
let Ordinal = 0;
|
|
3222
|
+
/** `[Json]` Creates a Recursive type */
|
|
3223
|
+
function Recursive(callback, options = {}) {
|
|
3224
|
+
if (IsUndefined$2(options.$id))
|
|
3225
|
+
options.$id = `T${Ordinal++}`;
|
|
3226
|
+
const thisType = callback({ [Kind]: 'This', $ref: `${options.$id}` });
|
|
3227
|
+
thisType.$id = options.$id;
|
|
3228
|
+
// prettier-ignore
|
|
3229
|
+
return CloneType({ ...options, [Hint]: 'Recursive', ...thisType });
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
/** `[Json]` Creates a Ref type. */
|
|
3233
|
+
function Ref(unresolved, options = {}) {
|
|
3234
|
+
if (IsString$2(unresolved))
|
|
3235
|
+
return { ...options, [Kind]: 'Ref', $ref: unresolved };
|
|
3236
|
+
if (IsUndefined$2(unresolved.$id))
|
|
3237
|
+
throw new Error('Reference target type must specify an $id');
|
|
3238
|
+
return {
|
|
3239
|
+
...options,
|
|
3240
|
+
[Kind]: 'Ref',
|
|
3241
|
+
$ref: unresolved.$id,
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
3246
|
+
function RegExp$1(unresolved, options = {}) {
|
|
3247
|
+
const expr = IsString$2(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
|
|
3248
|
+
return { ...options, [Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags };
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
// prettier-ignore
|
|
3252
|
+
function FromRest(T) {
|
|
3253
|
+
return T.map(L => RequiredResolve(L));
|
|
3254
|
+
}
|
|
3255
|
+
// prettier-ignore
|
|
3256
|
+
function FromProperties$1(T) {
|
|
3257
|
+
const Acc = {};
|
|
3258
|
+
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
3259
|
+
Acc[K] = Discard(T[K], [OptionalKind]);
|
|
3260
|
+
return Acc;
|
|
3261
|
+
}
|
|
3262
|
+
// ------------------------------------------------------------------
|
|
3263
|
+
// RequiredResolve
|
|
3264
|
+
// ------------------------------------------------------------------
|
|
3265
|
+
// prettier-ignore
|
|
3266
|
+
function RequiredResolve(T) {
|
|
3267
|
+
return (IsIntersect$1(T) ? Intersect(FromRest(T.allOf)) :
|
|
3268
|
+
IsUnion$1(T) ? Union(FromRest(T.anyOf)) :
|
|
3269
|
+
IsObject$1(T) ? Object$1(FromProperties$1(T.properties)) :
|
|
3270
|
+
Object$1({}));
|
|
3271
|
+
}
|
|
3272
|
+
/** `[Json]` Constructs a type where all properties are required */
|
|
3273
|
+
function Required(T, options = {}) {
|
|
3274
|
+
if (IsMappedResult$1(T)) {
|
|
3275
|
+
return RequiredFromMappedResult(T, options);
|
|
3276
|
+
}
|
|
3277
|
+
else {
|
|
3278
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
3279
|
+
const R = CloneType(RequiredResolve(T), options);
|
|
3280
|
+
return { ...D, ...R };
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
// prettier-ignore
|
|
3285
|
+
function FromProperties(P, options) {
|
|
3286
|
+
const Acc = {};
|
|
3287
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
3288
|
+
Acc[K2] = Required(P[K2], options);
|
|
3289
|
+
return Acc;
|
|
3290
|
+
}
|
|
3291
|
+
// prettier-ignore
|
|
3292
|
+
function FromMappedResult(R, options) {
|
|
3293
|
+
return FromProperties(R.properties, options);
|
|
3294
|
+
}
|
|
3295
|
+
// prettier-ignore
|
|
3296
|
+
function RequiredFromMappedResult(R, options) {
|
|
3297
|
+
const P = FromMappedResult(R, options);
|
|
3298
|
+
return MappedResult(P);
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
// prettier-ignore
|
|
3302
|
+
function RestResolve(T) {
|
|
3303
|
+
return (IsIntersect$1(T) ? CloneRest(T.allOf) :
|
|
3304
|
+
IsUnion$1(T) ? CloneRest(T.anyOf) :
|
|
3305
|
+
IsTuple$1(T) ? CloneRest(T.items ?? []) :
|
|
3306
|
+
[]);
|
|
3307
|
+
}
|
|
3308
|
+
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
3309
|
+
function Rest(T) {
|
|
3310
|
+
return CloneRest(RestResolve(T));
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
3314
|
+
function ReturnType(schema, options = {}) {
|
|
3315
|
+
return CloneType(schema.returns, options);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
/** `[Json]` Omits compositing symbols from this schema. */
|
|
3319
|
+
function Strict(schema) {
|
|
3320
|
+
return JSON.parse(JSON.stringify(schema));
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
// ------------------------------------------------------------------
|
|
3324
|
+
// TransformBuilders
|
|
3325
|
+
// ------------------------------------------------------------------
|
|
3326
|
+
class TransformDecodeBuilder {
|
|
3327
|
+
constructor(schema) {
|
|
3328
|
+
this.schema = schema;
|
|
3329
|
+
}
|
|
3330
|
+
Decode(decode) {
|
|
3331
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
// prettier-ignore
|
|
3335
|
+
class TransformEncodeBuilder {
|
|
3336
|
+
constructor(schema, decode) {
|
|
3337
|
+
this.schema = schema;
|
|
3338
|
+
this.decode = decode;
|
|
3339
|
+
}
|
|
3340
|
+
EncodeTransform(encode, schema) {
|
|
3341
|
+
const Encode = (value) => schema[TransformKind].Encode(encode(value));
|
|
3342
|
+
const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
|
|
3343
|
+
const Codec = { Encode: Encode, Decode: Decode };
|
|
3344
|
+
return { ...schema, [TransformKind]: Codec };
|
|
3345
|
+
}
|
|
3346
|
+
EncodeSchema(encode, schema) {
|
|
3347
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
3348
|
+
return { ...schema, [TransformKind]: Codec };
|
|
3349
|
+
}
|
|
3350
|
+
Encode(encode) {
|
|
3351
|
+
const schema = CloneType(this.schema);
|
|
3352
|
+
return (IsTransform$1(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
/** `[Json]` Creates a Transform type */
|
|
3356
|
+
function Transform(schema) {
|
|
3357
|
+
return new TransformDecodeBuilder(schema);
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
3361
|
+
function Unsafe(options = {}) {
|
|
3362
|
+
return {
|
|
3363
|
+
...options,
|
|
3364
|
+
[Kind]: options[Kind] ?? 'Unsafe',
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
/** `[JavaScript]` Creates a Void type */
|
|
3369
|
+
function Void(options = {}) {
|
|
3370
|
+
return {
|
|
3371
|
+
...options,
|
|
3372
|
+
[Kind]: 'Void',
|
|
3373
|
+
type: 'void',
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
// ------------------------------------------------------------------
|
|
3378
|
+
// Type: Module
|
|
3379
|
+
// ------------------------------------------------------------------
|
|
3380
|
+
|
|
3381
|
+
var TypeBuilder = /*#__PURE__*/Object.freeze({
|
|
3382
|
+
__proto__: null,
|
|
3383
|
+
Any: Any,
|
|
3384
|
+
Array: Array$1,
|
|
3385
|
+
AsyncIterator: AsyncIterator,
|
|
3386
|
+
Awaited: Awaited,
|
|
3387
|
+
BigInt: BigInt,
|
|
3388
|
+
Boolean: Boolean,
|
|
3389
|
+
Capitalize: Capitalize,
|
|
3390
|
+
Composite: Composite,
|
|
3391
|
+
Const: Const,
|
|
3392
|
+
Constructor: Constructor,
|
|
3393
|
+
ConstructorParameters: ConstructorParameters,
|
|
3394
|
+
Date: Date$1,
|
|
3395
|
+
Deref: Deref,
|
|
3396
|
+
Enum: Enum,
|
|
3397
|
+
Exclude: Exclude,
|
|
3398
|
+
Extends: Extends,
|
|
3399
|
+
Extract: Extract,
|
|
3400
|
+
Function: Function,
|
|
3401
|
+
Index: Index,
|
|
3402
|
+
InstanceType: InstanceType,
|
|
3403
|
+
Integer: Integer,
|
|
3404
|
+
Intersect: Intersect,
|
|
3405
|
+
Iterator: Iterator,
|
|
3406
|
+
KeyOf: KeyOf,
|
|
3407
|
+
Literal: Literal,
|
|
3408
|
+
Lowercase: Lowercase,
|
|
3409
|
+
Mapped: Mapped,
|
|
3410
|
+
Never: Never,
|
|
3411
|
+
Not: Not,
|
|
3412
|
+
Null: Null,
|
|
3413
|
+
Number: Number,
|
|
3414
|
+
Object: Object$1,
|
|
3415
|
+
Omit: Omit,
|
|
3416
|
+
Optional: Optional,
|
|
3417
|
+
Parameters: Parameters,
|
|
3418
|
+
Partial: Partial,
|
|
3419
|
+
Pick: Pick,
|
|
3420
|
+
Promise: Promise$1,
|
|
3421
|
+
Readonly: Readonly,
|
|
3422
|
+
ReadonlyOptional: ReadonlyOptional,
|
|
3423
|
+
Record: Record,
|
|
3424
|
+
Recursive: Recursive,
|
|
3425
|
+
Ref: Ref,
|
|
3426
|
+
RegExp: RegExp$1,
|
|
3427
|
+
Required: Required,
|
|
3428
|
+
Rest: Rest,
|
|
3429
|
+
ReturnType: ReturnType,
|
|
3430
|
+
Strict: Strict,
|
|
3431
|
+
String: String,
|
|
3432
|
+
Symbol: Symbol$1,
|
|
3433
|
+
TemplateLiteral: TemplateLiteral,
|
|
3434
|
+
Transform: Transform,
|
|
3435
|
+
Tuple: Tuple,
|
|
3436
|
+
Uint8Array: Uint8Array$1,
|
|
3437
|
+
Uncapitalize: Uncapitalize,
|
|
3438
|
+
Undefined: Undefined,
|
|
3439
|
+
Union: Union,
|
|
3440
|
+
Unknown: Unknown,
|
|
3441
|
+
Unsafe: Unsafe,
|
|
3442
|
+
Uppercase: Uppercase,
|
|
3443
|
+
Void: Void
|
|
3444
|
+
});
|
|
3445
|
+
|
|
3446
|
+
// ------------------------------------------------------------------
|
|
3447
|
+
// JsonTypeBuilder
|
|
3448
|
+
// ------------------------------------------------------------------
|
|
3449
|
+
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
3450
|
+
const Type = TypeBuilder;
|
|
4
3451
|
|
|
5
3452
|
/**
|
|
6
3453
|
* 北森 EHR OpenClaw Plugin
|
|
@@ -10,65 +3457,138 @@ import os from 'os';
|
|
|
10
3457
|
*/
|
|
11
3458
|
// 插件元数据
|
|
12
3459
|
const pluginId = 'beisen-ehr-plugin';
|
|
13
|
-
const pluginVersion = '1.
|
|
3460
|
+
const pluginVersion = '1.1.0';
|
|
14
3461
|
/**
|
|
15
3462
|
* 默认配置
|
|
16
3463
|
*/
|
|
17
3464
|
const defaultConfig = {
|
|
18
3465
|
apiUrl: 'https://openapi.italent.cn',
|
|
19
3466
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3467
|
+
// ============ Token 管理 ============
|
|
3468
|
+
let cachedToken = null;
|
|
3469
|
+
let tokenExpiry = 0;
|
|
3470
|
+
async function getAccessToken(config) {
|
|
3471
|
+
// 如果已有有效 Token,直接返回
|
|
3472
|
+
if (cachedToken && Date.now() < tokenExpiry) {
|
|
3473
|
+
return cachedToken;
|
|
3474
|
+
}
|
|
3475
|
+
// 使用 AppKey + AppSecret 获取新 Token(北森官方格式)
|
|
3476
|
+
const tokenUrl = `${config.apiUrl || defaultConfig.apiUrl}/token`;
|
|
3477
|
+
const response = await fetch(tokenUrl, {
|
|
3478
|
+
method: "POST",
|
|
3479
|
+
headers: {
|
|
3480
|
+
"Content-Type": "application/json",
|
|
3481
|
+
},
|
|
3482
|
+
body: JSON.stringify({
|
|
3483
|
+
grant_type: "client_credentials",
|
|
3484
|
+
app_key: config.appKey,
|
|
3485
|
+
app_secret: config.appSecret,
|
|
3486
|
+
}),
|
|
3487
|
+
});
|
|
3488
|
+
if (!response.ok) {
|
|
3489
|
+
const errorText = await response.text();
|
|
3490
|
+
throw new Error(`获取 Token 失败:${response.status} - ${errorText}`);
|
|
3491
|
+
}
|
|
3492
|
+
const data = await response.json();
|
|
3493
|
+
cachedToken = data.accessToken || data.access_token;
|
|
3494
|
+
// Token 有效期通常 2 小时,提前 5 分钟刷新
|
|
3495
|
+
tokenExpiry = Date.now() + (data.expiresIn || data.expires_in || 7200) * 1000 - 5 * 60 * 1000;
|
|
3496
|
+
console.error(`🔑 已获取新 Token,有效期至:${new Date(tokenExpiry).toISOString()}`);
|
|
3497
|
+
return cachedToken;
|
|
3498
|
+
}
|
|
3499
|
+
// ============ 北森 API 客户端 ============
|
|
3500
|
+
class BeisenClient {
|
|
3501
|
+
constructor(config) {
|
|
3502
|
+
this.config = config;
|
|
3503
|
+
}
|
|
3504
|
+
async request(endpoint, options = {}) {
|
|
3505
|
+
const url = `${this.config.apiUrl || defaultConfig.apiUrl}${endpoint}`;
|
|
3506
|
+
const token = await getAccessToken(this.config);
|
|
3507
|
+
const headers = {
|
|
3508
|
+
"Content-Type": "application/json",
|
|
3509
|
+
"Authorization": `Bearer ${token}`,
|
|
3510
|
+
...(this.config.tenantId && { "tenantId": this.config.tenantId }),
|
|
3511
|
+
...(options.headers || {}),
|
|
3512
|
+
};
|
|
3513
|
+
console.error(`📡 请求:${options.method || 'GET'} ${url}`);
|
|
3514
|
+
console.error(`🏢 TenantId: ${this.config.tenantId}`);
|
|
3515
|
+
const response = await fetch(url, {
|
|
3516
|
+
...options,
|
|
3517
|
+
headers,
|
|
3518
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
3519
|
+
});
|
|
3520
|
+
if (!response.ok) {
|
|
3521
|
+
const errorText = await response.text();
|
|
3522
|
+
throw new Error(`北森 API 错误:${response.status} - ${errorText}`);
|
|
29
3523
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
3524
|
+
return response.json();
|
|
3525
|
+
}
|
|
3526
|
+
// 提交加班申请(推送至北森系统并发起审批)
|
|
3527
|
+
async submitOvertime(data) {
|
|
3528
|
+
const overtimeData = {
|
|
3529
|
+
staffId: data.staffId,
|
|
3530
|
+
email: data.email,
|
|
3531
|
+
startDate: data.startDate,
|
|
3532
|
+
stopDate: data.stopDate,
|
|
3533
|
+
compensationType: data.compensationType !== undefined ? data.compensationType : 0,
|
|
3534
|
+
};
|
|
3535
|
+
if (data.properties) {
|
|
3536
|
+
overtimeData.properties = typeof data.properties === 'string' ? data.properties : JSON.stringify(data.properties);
|
|
37
3537
|
}
|
|
38
|
-
|
|
3538
|
+
const payload = {
|
|
3539
|
+
attendance_overTime: overtimeData,
|
|
3540
|
+
};
|
|
3541
|
+
return this.request("/AttendanceOpen/api/v1/AttendanceOvertime/PostOverTimeWithApproval", {
|
|
3542
|
+
method: "POST",
|
|
3543
|
+
body: payload,
|
|
3544
|
+
});
|
|
39
3545
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
3546
|
+
// 查询假期余额
|
|
3547
|
+
async getLeaveBalance(staffId, email) {
|
|
3548
|
+
return this.request("/AttendanceOpen/api/v1/LeaveBalance/QueryLeaveBalance", {
|
|
3549
|
+
method: "POST",
|
|
3550
|
+
body: { staffId, email },
|
|
3551
|
+
});
|
|
3552
|
+
}
|
|
3553
|
+
// 查询考勤记录
|
|
3554
|
+
async getAttendanceRecords(startDate, endDate, employeeId) {
|
|
3555
|
+
return this.request("/api/v1/attendance/records", {
|
|
3556
|
+
method: "POST",
|
|
3557
|
+
body: { startDate, endDate, employeeId },
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
// 查询审批状态
|
|
3561
|
+
async getApprovalStatus(applicationId) {
|
|
3562
|
+
return this.request(`/api/v1/approval/${applicationId}/status`);
|
|
43
3563
|
}
|
|
44
3564
|
}
|
|
45
3565
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* 当插件被激活时,自动配置 MCP 服务器
|
|
3566
|
+
* 插件注册函数
|
|
49
3567
|
*/
|
|
50
|
-
async function
|
|
51
|
-
console.error(`🏢 北森 EHR
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
config = loadConfig();
|
|
55
|
-
}
|
|
56
|
-
// 处理空配置情况
|
|
3568
|
+
async function register(api) {
|
|
3569
|
+
console.error(`🏢 北森 EHR 插件已加载 v${pluginVersion}`);
|
|
3570
|
+
// 获取插件配置
|
|
3571
|
+
const config = api.config?.plugins?.entries?.['beisen-ehr-plugin']?.config;
|
|
57
3572
|
if (!config) {
|
|
58
3573
|
console.error('⚠️ 插件已安装,但未配置凭证');
|
|
59
3574
|
console.error('');
|
|
60
|
-
console.error('📝
|
|
61
|
-
console.error('');
|
|
62
|
-
console.error(' npx @peninsula-med/beisen-ehr-configure');
|
|
3575
|
+
console.error('📝 请在 OpenClaw 配置中添加:');
|
|
63
3576
|
console.error('');
|
|
64
|
-
console.error('
|
|
3577
|
+
console.error(' plugins: {');
|
|
3578
|
+
console.error(' entries: {');
|
|
3579
|
+
console.error(' "beisen-ehr-plugin": {');
|
|
3580
|
+
console.error(' enabled: true,');
|
|
3581
|
+
console.error(' config: {');
|
|
3582
|
+
console.error(' appKey: "your-app-key",');
|
|
3583
|
+
console.error(' appSecret: "your-app-secret",');
|
|
3584
|
+
console.error(' staffId: "your-staff-id",');
|
|
3585
|
+
console.error(' tenantId: "your-tenant-id",');
|
|
3586
|
+
console.error(' email: "your-email@company.com"');
|
|
3587
|
+
console.error(' }');
|
|
3588
|
+
console.error(' }');
|
|
3589
|
+
console.error(' }');
|
|
3590
|
+
console.error(' }');
|
|
65
3591
|
console.error('');
|
|
66
|
-
console.error('需要凭证?联系北森管理员获取:');
|
|
67
|
-
console.error(' • App Key');
|
|
68
|
-
console.error(' • App Secret');
|
|
69
|
-
console.error(' • Tenant ID');
|
|
70
|
-
console.error(' • Staff ID');
|
|
71
|
-
console.error(' • 企业邮箱');
|
|
72
3592
|
return;
|
|
73
3593
|
}
|
|
74
3594
|
// 验证必要配置
|
|
@@ -76,42 +3596,161 @@ async function activate(runtime, config) {
|
|
|
76
3596
|
const missingFields = requiredFields.filter(field => !config[field]);
|
|
77
3597
|
if (missingFields.length > 0) {
|
|
78
3598
|
console.error(`❌ 缺少必要配置:${missingFields.join(', ')}`);
|
|
79
|
-
console.error('');
|
|
80
|
-
console.error('📝 请运行配置向导完成配置:');
|
|
81
|
-
console.error('');
|
|
82
|
-
console.error(' npx @peninsula-med/beisen-ehr-configure');
|
|
83
|
-
console.error('');
|
|
84
|
-
console.error('按提示输入北森凭证即可!');
|
|
3599
|
+
console.error('请补充完整配置后重启 Gateway');
|
|
85
3600
|
return;
|
|
86
3601
|
}
|
|
87
|
-
// MCP 服务器配置会自动从 openclaw.plugin.json 加载
|
|
88
|
-
// 这里只需要验证配置即可
|
|
89
3602
|
console.error('✅ 北森 EHR 配置验证通过');
|
|
90
3603
|
console.error(`📡 API: ${config.apiUrl || defaultConfig.apiUrl}`);
|
|
91
3604
|
console.error(`👤 员工:${config.staffId}`);
|
|
92
3605
|
console.error(`🏢 企业:${config.tenantId}`);
|
|
3606
|
+
// 创建 API 客户端
|
|
3607
|
+
const client = new BeisenClient(config);
|
|
3608
|
+
// ============ 注册工具 ============
|
|
3609
|
+
// 工具 1: 提交加班申请
|
|
3610
|
+
api.registerTool({
|
|
3611
|
+
name: 'beisen_submit_overtime',
|
|
3612
|
+
description: '提交加班申请到北森 EHR(推送数据并发起审批)',
|
|
3613
|
+
parameters: Type.Object({
|
|
3614
|
+
startDate: Type.String({ description: '开始时间 (YYYY-MM-DD HH:mm:ss),如:2020-07-17 22:00:00' }),
|
|
3615
|
+
stopDate: Type.String({ description: '结束时间 (YYYY-MM-DD HH:mm:ss),如:2020-07-17 23:00:00' }),
|
|
3616
|
+
compensationType: Type.Optional(Type.Number({ description: '补偿类型:0=调休假,1=加班费(默认 0)' })),
|
|
3617
|
+
properties: Type.Optional(Type.String({ description: '自定义字段 JSON 字符串' })),
|
|
3618
|
+
}),
|
|
3619
|
+
async execute(_id, params) {
|
|
3620
|
+
try {
|
|
3621
|
+
const result = await client.submitOvertime({
|
|
3622
|
+
staffId: config.staffId,
|
|
3623
|
+
email: config.email,
|
|
3624
|
+
startDate: params.startDate,
|
|
3625
|
+
stopDate: params.stopDate,
|
|
3626
|
+
compensationType: params.compensationType,
|
|
3627
|
+
properties: params.properties,
|
|
3628
|
+
});
|
|
3629
|
+
if (result.code === "200" || result.code === 200) {
|
|
3630
|
+
const compTypeText = params.compensationType === 1 ? "加班费" : "调休假";
|
|
3631
|
+
return {
|
|
3632
|
+
content: [
|
|
3633
|
+
{
|
|
3634
|
+
type: "text",
|
|
3635
|
+
text: `✅ 加班申请已提交!\n\n申请详情:\n- 员工 ID: ${config.staffId}\n- 邮箱:${config.email}\n- 开始:${params.startDate}\n- 结束:${params.stopDate}\n- 补偿类型:${compTypeText}\n- 申请 ID: ${result.data || "待返回"}`,
|
|
3636
|
+
},
|
|
3637
|
+
],
|
|
3638
|
+
};
|
|
3639
|
+
}
|
|
3640
|
+
else {
|
|
3641
|
+
throw new Error(result.message || `API 返回错误:${result.code}`);
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3644
|
+
catch (error) {
|
|
3645
|
+
return {
|
|
3646
|
+
content: [{ type: "text", text: `❌ 提交失败:${error.message}` }],
|
|
3647
|
+
isError: true,
|
|
3648
|
+
};
|
|
3649
|
+
}
|
|
3650
|
+
},
|
|
3651
|
+
});
|
|
3652
|
+
// 工具 2: 查询假期余额
|
|
3653
|
+
api.registerTool({
|
|
3654
|
+
name: 'beisen_get_leave_balance',
|
|
3655
|
+
description: '查询假期余额(年假、调休假等)',
|
|
3656
|
+
parameters: Type.Object({}),
|
|
3657
|
+
async execute(_id, _params) {
|
|
3658
|
+
try {
|
|
3659
|
+
const result = await client.getLeaveBalance(config.staffId, config.email);
|
|
3660
|
+
let balanceText = `📊 假期余额查询\n\n员工:${config.email}\n\n`;
|
|
3661
|
+
if (result.data && Array.isArray(result.data)) {
|
|
3662
|
+
result.data.forEach((item) => {
|
|
3663
|
+
balanceText += `• ${item.leaveTypeName || item.typeName || '未知假期'}: ${item.balanceDays || item.balance || 0} 天\n`;
|
|
3664
|
+
});
|
|
3665
|
+
}
|
|
3666
|
+
else if (result.data) {
|
|
3667
|
+
balanceText += JSON.stringify(result.data, null, 2);
|
|
3668
|
+
}
|
|
3669
|
+
else {
|
|
3670
|
+
balanceText += "暂无假期数据";
|
|
3671
|
+
}
|
|
3672
|
+
return {
|
|
3673
|
+
content: [{ type: "text", text: balanceText }],
|
|
3674
|
+
};
|
|
3675
|
+
}
|
|
3676
|
+
catch (error) {
|
|
3677
|
+
return {
|
|
3678
|
+
content: [{ type: "text", text: `❌ 查询失败:${error.message}` }],
|
|
3679
|
+
isError: true,
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
},
|
|
3683
|
+
});
|
|
3684
|
+
// 工具 3: 查询考勤记录
|
|
3685
|
+
api.registerTool({
|
|
3686
|
+
name: 'beisen_query_attendance',
|
|
3687
|
+
description: '查询员工考勤记录',
|
|
3688
|
+
parameters: Type.Object({
|
|
3689
|
+
startDate: Type.String({ description: '开始日期 (YYYY-MM-DD)' }),
|
|
3690
|
+
endDate: Type.String({ description: '结束日期 (YYYY-MM-DD)' }),
|
|
3691
|
+
}),
|
|
3692
|
+
async execute(_id, params) {
|
|
3693
|
+
try {
|
|
3694
|
+
const records = await client.getAttendanceRecords(params.startDate, params.endDate, config.staffId);
|
|
3695
|
+
return {
|
|
3696
|
+
content: [
|
|
3697
|
+
{
|
|
3698
|
+
type: "text",
|
|
3699
|
+
text: `📅 考勤记录 (${params.startDate} ~ ${params.endDate})\n\n${JSON.stringify(records, null, 2)}`,
|
|
3700
|
+
},
|
|
3701
|
+
],
|
|
3702
|
+
};
|
|
3703
|
+
}
|
|
3704
|
+
catch (error) {
|
|
3705
|
+
return {
|
|
3706
|
+
content: [{ type: "text", text: `❌ 查询失败:${error.message}` }],
|
|
3707
|
+
isError: true,
|
|
3708
|
+
};
|
|
3709
|
+
}
|
|
3710
|
+
},
|
|
3711
|
+
});
|
|
3712
|
+
// 工具 4: 查询审批状态
|
|
3713
|
+
api.registerTool({
|
|
3714
|
+
name: 'beisen_get_approval_status',
|
|
3715
|
+
description: '查询审批状态',
|
|
3716
|
+
parameters: Type.Object({
|
|
3717
|
+
applicationId: Type.String({ description: '申请 ID' }),
|
|
3718
|
+
}),
|
|
3719
|
+
async execute(_id, params) {
|
|
3720
|
+
try {
|
|
3721
|
+
const status = await client.getApprovalStatus(params.applicationId);
|
|
3722
|
+
return {
|
|
3723
|
+
content: [
|
|
3724
|
+
{
|
|
3725
|
+
type: "text",
|
|
3726
|
+
text: `📋 审批状态\n\n申请 ID: ${params.applicationId}\n状态:${status.status || "未知"}\n审批人:${status.approver || "待分配"}\n备注:${status.remark || "无"}`,
|
|
3727
|
+
},
|
|
3728
|
+
],
|
|
3729
|
+
};
|
|
3730
|
+
}
|
|
3731
|
+
catch (error) {
|
|
3732
|
+
return {
|
|
3733
|
+
content: [{ type: "text", text: `❌ 查询失败:${error.message}` }],
|
|
3734
|
+
isError: true,
|
|
3735
|
+
};
|
|
3736
|
+
}
|
|
3737
|
+
},
|
|
3738
|
+
});
|
|
3739
|
+
console.error('✅ 已注册 4 个工具:beisen_submit_overtime, beisen_get_leave_balance, beisen_query_attendance, beisen_get_approval_status');
|
|
93
3740
|
}
|
|
94
3741
|
/**
|
|
95
3742
|
* 插件停用函数
|
|
96
3743
|
*/
|
|
97
|
-
async function
|
|
3744
|
+
async function unregister() {
|
|
98
3745
|
console.error('🏢 北森 EHR 插件已停用');
|
|
99
3746
|
}
|
|
100
|
-
/**
|
|
101
|
-
* 配置变更回调
|
|
102
|
-
*/
|
|
103
|
-
async function onConfigChange(config) {
|
|
104
|
-
console.error('🔄 北森 EHR 配置已更新');
|
|
105
|
-
await activate(undefined, config);
|
|
106
|
-
}
|
|
107
3747
|
// 导出插件入口
|
|
108
3748
|
const plugin = {
|
|
109
3749
|
id: pluginId,
|
|
110
3750
|
version: pluginVersion,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
onConfigChange,
|
|
3751
|
+
register,
|
|
3752
|
+
unregister,
|
|
114
3753
|
};
|
|
115
3754
|
|
|
116
|
-
export {
|
|
3755
|
+
export { plugin as default, defaultConfig, pluginId, pluginVersion, register, unregister };
|
|
117
3756
|
//# sourceMappingURL=index.esm.js.map
|