@wovin/core 0.0.1-RC20 → 0.0.1-RC21
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/dist/applog.js +5 -4
- package/dist/chunk-3VDDRHGD.js +9854 -0
- package/dist/chunk-3VDDRHGD.js.map +1 -0
- package/dist/{chunk-RBXGBMA7.js → chunk-5FO6VRGW.js} +16 -5
- package/dist/chunk-5FO6VRGW.js.map +1 -0
- package/dist/chunk-AWVTEBES.js +7 -0
- package/dist/chunk-AWVTEBES.js.map +1 -0
- package/dist/chunk-JHX2WWYS.js +78766 -0
- package/dist/chunk-JHX2WWYS.js.map +1 -0
- package/dist/{chunk-XJPITJRE.js → chunk-JI36NHJX.js} +18 -6
- package/dist/chunk-JI36NHJX.js.map +1 -0
- package/dist/chunk-MTQJBBHB.js +4586 -0
- package/dist/chunk-MTQJBBHB.js.map +1 -0
- package/dist/chunk-TIIA4ZAI.js +56 -0
- package/dist/chunk-TIIA4ZAI.js.map +1 -0
- package/dist/chunk-TYUDGJVU.js +7 -0
- package/dist/chunk-TYUDGJVU.js.map +1 -0
- package/dist/chunk-YJXKRB2D.js +7651 -0
- package/dist/chunk-YJXKRB2D.js.map +1 -0
- package/dist/chunk-YNB6ALUV.js +56 -0
- package/dist/chunk-YNB6ALUV.js.map +1 -0
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/dist/ipfs.js +4 -3
- package/dist/pubsub.js +5 -4
- package/dist/query.js +5 -4
- package/dist/stream.js +4 -3
- package/dist/types.js +5 -4
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6ZDPEEFN.js +0 -67
- package/dist/chunk-6ZDPEEFN.js.map +0 -1
- package/dist/chunk-DBACGNVR.js +0 -1
- package/dist/chunk-DBACGNVR.js.map +0 -1
- package/dist/chunk-I5PELB4T.js +0 -770
- package/dist/chunk-I5PELB4T.js.map +0 -1
- package/dist/chunk-K2JRTCRC.js +0 -44
- package/dist/chunk-K2JRTCRC.js.map +0 -1
- package/dist/chunk-RBXGBMA7.js.map +0 -1
- package/dist/chunk-TR5AJKIN.js +0 -1
- package/dist/chunk-TR5AJKIN.js.map +0 -1
- package/dist/chunk-VKQDEGWA.js +0 -561
- package/dist/chunk-VKQDEGWA.js.map +0 -1
- package/dist/chunk-X23XAGRU.js +0 -60
- package/dist/chunk-X23XAGRU.js.map +0 -1
- package/dist/chunk-XJPITJRE.js.map +0 -1
|
@@ -0,0 +1,4586 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApplogStream,
|
|
3
|
+
MappedApplogStream,
|
|
4
|
+
action,
|
|
5
|
+
applogStreamComparer,
|
|
6
|
+
autorun,
|
|
7
|
+
comparer,
|
|
8
|
+
computed,
|
|
9
|
+
computedFnDeepCompare,
|
|
10
|
+
computedStructuralComparer,
|
|
11
|
+
createDebugName,
|
|
12
|
+
dateNowIso,
|
|
13
|
+
isInitEvent,
|
|
14
|
+
isTsBefore,
|
|
15
|
+
makeObservable,
|
|
16
|
+
observable,
|
|
17
|
+
observableArrayMap,
|
|
18
|
+
onBecomeObserved,
|
|
19
|
+
queryNodesComparer,
|
|
20
|
+
removeDuplicateAppLogs,
|
|
21
|
+
resolveOrRemoveVariables,
|
|
22
|
+
rollingFilter,
|
|
23
|
+
rollingMapper,
|
|
24
|
+
sortApplogsByTs,
|
|
25
|
+
toJS,
|
|
26
|
+
untracked,
|
|
27
|
+
wrapper_default
|
|
28
|
+
} from "./chunk-YJXKRB2D.js";
|
|
29
|
+
import {
|
|
30
|
+
Logger,
|
|
31
|
+
encodeApplogAndGetCid
|
|
32
|
+
} from "./chunk-JHX2WWYS.js";
|
|
33
|
+
import {
|
|
34
|
+
__commonJS,
|
|
35
|
+
__toESM,
|
|
36
|
+
init_dirname
|
|
37
|
+
} from "./chunk-TIIA4ZAI.js";
|
|
38
|
+
|
|
39
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js
|
|
40
|
+
var require_typebox = __commonJS({
|
|
41
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js"(exports) {
|
|
42
|
+
"use strict";
|
|
43
|
+
init_dirname();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.Type = exports.JsonType = exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.TypeBuilder = exports.TypeBuilderError = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.TemplateLiteralDslParser = exports.TemplateLiteralGenerator = exports.TemplateLiteralGeneratorError = exports.TemplateLiteralFinite = exports.TemplateLiteralFiniteError = exports.TemplateLiteralParser = exports.TemplateLiteralParserError = exports.TemplateLiteralResolver = exports.TemplateLiteralPattern = exports.TemplateLiteralPatternError = exports.UnionResolver = exports.KeyArrayResolver = exports.KeyArrayResolverError = exports.KeyResolver = exports.ObjectMap = exports.Intrinsic = exports.IndexedAccessor = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.TypeExtendsError = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.ValueGuard = exports.FormatRegistry = exports.TypeBoxError = exports.TypeRegistry = exports.PatternStringExact = exports.PatternNumberExact = exports.PatternBooleanExact = exports.PatternString = exports.PatternNumber = exports.PatternBoolean = exports.Kind = exports.Hint = exports.Optional = exports.Readonly = exports.Transform = void 0;
|
|
46
|
+
exports.Transform = Symbol.for("TypeBox.Transform");
|
|
47
|
+
exports.Readonly = Symbol.for("TypeBox.Readonly");
|
|
48
|
+
exports.Optional = Symbol.for("TypeBox.Optional");
|
|
49
|
+
exports.Hint = Symbol.for("TypeBox.Hint");
|
|
50
|
+
exports.Kind = Symbol.for("TypeBox.Kind");
|
|
51
|
+
exports.PatternBoolean = "(true|false)";
|
|
52
|
+
exports.PatternNumber = "(0|[1-9][0-9]*)";
|
|
53
|
+
exports.PatternString = "(.*)";
|
|
54
|
+
exports.PatternBooleanExact = `^${exports.PatternBoolean}$`;
|
|
55
|
+
exports.PatternNumberExact = `^${exports.PatternNumber}$`;
|
|
56
|
+
exports.PatternStringExact = `^${exports.PatternString}$`;
|
|
57
|
+
var TypeRegistry;
|
|
58
|
+
(function(TypeRegistry2) {
|
|
59
|
+
const map = /* @__PURE__ */ new Map();
|
|
60
|
+
function Entries() {
|
|
61
|
+
return new Map(map);
|
|
62
|
+
}
|
|
63
|
+
TypeRegistry2.Entries = Entries;
|
|
64
|
+
function Clear() {
|
|
65
|
+
return map.clear();
|
|
66
|
+
}
|
|
67
|
+
TypeRegistry2.Clear = Clear;
|
|
68
|
+
function Delete(kind) {
|
|
69
|
+
return map.delete(kind);
|
|
70
|
+
}
|
|
71
|
+
TypeRegistry2.Delete = Delete;
|
|
72
|
+
function Has(kind) {
|
|
73
|
+
return map.has(kind);
|
|
74
|
+
}
|
|
75
|
+
TypeRegistry2.Has = Has;
|
|
76
|
+
function Set2(kind, func) {
|
|
77
|
+
map.set(kind, func);
|
|
78
|
+
}
|
|
79
|
+
TypeRegistry2.Set = Set2;
|
|
80
|
+
function Get(kind) {
|
|
81
|
+
return map.get(kind);
|
|
82
|
+
}
|
|
83
|
+
TypeRegistry2.Get = Get;
|
|
84
|
+
})(TypeRegistry || (exports.TypeRegistry = TypeRegistry = {}));
|
|
85
|
+
var TypeBoxError = class extends Error {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super(message);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.TypeBoxError = TypeBoxError;
|
|
91
|
+
var FormatRegistry2;
|
|
92
|
+
(function(FormatRegistry3) {
|
|
93
|
+
const map = /* @__PURE__ */ new Map();
|
|
94
|
+
function Entries() {
|
|
95
|
+
return new Map(map);
|
|
96
|
+
}
|
|
97
|
+
FormatRegistry3.Entries = Entries;
|
|
98
|
+
function Clear() {
|
|
99
|
+
return map.clear();
|
|
100
|
+
}
|
|
101
|
+
FormatRegistry3.Clear = Clear;
|
|
102
|
+
function Delete(format) {
|
|
103
|
+
return map.delete(format);
|
|
104
|
+
}
|
|
105
|
+
FormatRegistry3.Delete = Delete;
|
|
106
|
+
function Has(format) {
|
|
107
|
+
return map.has(format);
|
|
108
|
+
}
|
|
109
|
+
FormatRegistry3.Has = Has;
|
|
110
|
+
function Set2(format, func) {
|
|
111
|
+
map.set(format, func);
|
|
112
|
+
}
|
|
113
|
+
FormatRegistry3.Set = Set2;
|
|
114
|
+
function Get(format) {
|
|
115
|
+
return map.get(format);
|
|
116
|
+
}
|
|
117
|
+
FormatRegistry3.Get = Get;
|
|
118
|
+
})(FormatRegistry2 || (exports.FormatRegistry = FormatRegistry2 = {}));
|
|
119
|
+
var ValueGuard;
|
|
120
|
+
(function(ValueGuard2) {
|
|
121
|
+
function IsArray(value) {
|
|
122
|
+
return Array.isArray(value);
|
|
123
|
+
}
|
|
124
|
+
ValueGuard2.IsArray = IsArray;
|
|
125
|
+
function IsBigInt(value) {
|
|
126
|
+
return typeof value === "bigint";
|
|
127
|
+
}
|
|
128
|
+
ValueGuard2.IsBigInt = IsBigInt;
|
|
129
|
+
function IsBoolean(value) {
|
|
130
|
+
return typeof value === "boolean";
|
|
131
|
+
}
|
|
132
|
+
ValueGuard2.IsBoolean = IsBoolean;
|
|
133
|
+
function IsDate(value) {
|
|
134
|
+
return value instanceof globalThis.Date;
|
|
135
|
+
}
|
|
136
|
+
ValueGuard2.IsDate = IsDate;
|
|
137
|
+
function IsNull(value) {
|
|
138
|
+
return value === null;
|
|
139
|
+
}
|
|
140
|
+
ValueGuard2.IsNull = IsNull;
|
|
141
|
+
function IsNumber(value) {
|
|
142
|
+
return typeof value === "number";
|
|
143
|
+
}
|
|
144
|
+
ValueGuard2.IsNumber = IsNumber;
|
|
145
|
+
function IsObject(value) {
|
|
146
|
+
return typeof value === "object" && value !== null;
|
|
147
|
+
}
|
|
148
|
+
ValueGuard2.IsObject = IsObject;
|
|
149
|
+
function IsString(value) {
|
|
150
|
+
return typeof value === "string";
|
|
151
|
+
}
|
|
152
|
+
ValueGuard2.IsString = IsString;
|
|
153
|
+
function IsUint8Array(value) {
|
|
154
|
+
return value instanceof globalThis.Uint8Array;
|
|
155
|
+
}
|
|
156
|
+
ValueGuard2.IsUint8Array = IsUint8Array;
|
|
157
|
+
function IsUndefined(value) {
|
|
158
|
+
return value === void 0;
|
|
159
|
+
}
|
|
160
|
+
ValueGuard2.IsUndefined = IsUndefined;
|
|
161
|
+
})(ValueGuard || (exports.ValueGuard = ValueGuard = {}));
|
|
162
|
+
var TypeGuardUnknownTypeError = class extends TypeBoxError {
|
|
163
|
+
};
|
|
164
|
+
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
165
|
+
var TypeGuard;
|
|
166
|
+
(function(TypeGuard2) {
|
|
167
|
+
function IsPattern(value) {
|
|
168
|
+
try {
|
|
169
|
+
new RegExp(value);
|
|
170
|
+
return true;
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function IsControlCharacterFree(value) {
|
|
176
|
+
if (!ValueGuard.IsString(value))
|
|
177
|
+
return false;
|
|
178
|
+
for (let i = 0; i < value.length; i++) {
|
|
179
|
+
const code = value.charCodeAt(i);
|
|
180
|
+
if (code >= 7 && code <= 13 || code === 27 || code === 127) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
function IsAdditionalProperties(value) {
|
|
187
|
+
return IsOptionalBoolean(value) || TSchema2(value);
|
|
188
|
+
}
|
|
189
|
+
function IsOptionalBigInt(value) {
|
|
190
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
|
|
191
|
+
}
|
|
192
|
+
function IsOptionalNumber(value) {
|
|
193
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsNumber(value);
|
|
194
|
+
}
|
|
195
|
+
function IsOptionalBoolean(value) {
|
|
196
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBoolean(value);
|
|
197
|
+
}
|
|
198
|
+
function IsOptionalString(value) {
|
|
199
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value);
|
|
200
|
+
}
|
|
201
|
+
function IsOptionalPattern(value) {
|
|
202
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
|
|
203
|
+
}
|
|
204
|
+
function IsOptionalFormat(value) {
|
|
205
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value);
|
|
206
|
+
}
|
|
207
|
+
function IsOptionalSchema(value) {
|
|
208
|
+
return ValueGuard.IsUndefined(value) || TSchema2(value);
|
|
209
|
+
}
|
|
210
|
+
function TAny(schema) {
|
|
211
|
+
return TKindOf(schema, "Any") && IsOptionalString(schema.$id);
|
|
212
|
+
}
|
|
213
|
+
TypeGuard2.TAny = TAny;
|
|
214
|
+
function TArray(schema) {
|
|
215
|
+
return TKindOf(schema, "Array") && schema.type === "array" && IsOptionalString(schema.$id) && TSchema2(schema.items) && IsOptionalNumber(schema.minItems) && IsOptionalNumber(schema.maxItems) && IsOptionalBoolean(schema.uniqueItems) && IsOptionalSchema(schema.contains) && IsOptionalNumber(schema.minContains) && IsOptionalNumber(schema.maxContains);
|
|
216
|
+
}
|
|
217
|
+
TypeGuard2.TArray = TArray;
|
|
218
|
+
function TAsyncIterator(schema) {
|
|
219
|
+
return TKindOf(schema, "AsyncIterator") && schema.type === "AsyncIterator" && IsOptionalString(schema.$id) && TSchema2(schema.items);
|
|
220
|
+
}
|
|
221
|
+
TypeGuard2.TAsyncIterator = TAsyncIterator;
|
|
222
|
+
function TBigInt(schema) {
|
|
223
|
+
return TKindOf(schema, "BigInt") && schema.type === "bigint" && IsOptionalString(schema.$id) && IsOptionalBigInt(schema.exclusiveMaximum) && IsOptionalBigInt(schema.exclusiveMinimum) && IsOptionalBigInt(schema.maximum) && IsOptionalBigInt(schema.minimum) && IsOptionalBigInt(schema.multipleOf);
|
|
224
|
+
}
|
|
225
|
+
TypeGuard2.TBigInt = TBigInt;
|
|
226
|
+
function TBoolean(schema) {
|
|
227
|
+
return TKindOf(schema, "Boolean") && schema.type === "boolean" && IsOptionalString(schema.$id);
|
|
228
|
+
}
|
|
229
|
+
TypeGuard2.TBoolean = TBoolean;
|
|
230
|
+
function TConstructor(schema) {
|
|
231
|
+
return TKindOf(schema, "Constructor") && schema.type === "Constructor" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema2(schema2)) && TSchema2(schema.returns);
|
|
232
|
+
}
|
|
233
|
+
TypeGuard2.TConstructor = TConstructor;
|
|
234
|
+
function TDate(schema) {
|
|
235
|
+
return TKindOf(schema, "Date") && schema.type === "Date" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximumTimestamp) && IsOptionalNumber(schema.exclusiveMinimumTimestamp) && IsOptionalNumber(schema.maximumTimestamp) && IsOptionalNumber(schema.minimumTimestamp) && IsOptionalNumber(schema.multipleOfTimestamp);
|
|
236
|
+
}
|
|
237
|
+
TypeGuard2.TDate = TDate;
|
|
238
|
+
function TFunction(schema) {
|
|
239
|
+
return TKindOf(schema, "Function") && schema.type === "Function" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema2(schema2)) && TSchema2(schema.returns);
|
|
240
|
+
}
|
|
241
|
+
TypeGuard2.TFunction = TFunction;
|
|
242
|
+
function TInteger(schema) {
|
|
243
|
+
return TKindOf(schema, "Integer") && schema.type === "integer" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximum) && IsOptionalNumber(schema.exclusiveMinimum) && IsOptionalNumber(schema.maximum) && IsOptionalNumber(schema.minimum) && IsOptionalNumber(schema.multipleOf);
|
|
244
|
+
}
|
|
245
|
+
TypeGuard2.TInteger = TInteger;
|
|
246
|
+
function TIntersect(schema) {
|
|
247
|
+
return TKindOf(schema, "Intersect") && (ValueGuard.IsString(schema.type) && schema.type !== "object" ? false : true) && ValueGuard.IsArray(schema.allOf) && schema.allOf.every((schema2) => TSchema2(schema2) && !TTransform(schema2)) && IsOptionalString(schema.type) && (IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) && IsOptionalString(schema.$id);
|
|
248
|
+
}
|
|
249
|
+
TypeGuard2.TIntersect = TIntersect;
|
|
250
|
+
function TIterator(schema) {
|
|
251
|
+
return TKindOf(schema, "Iterator") && schema.type === "Iterator" && IsOptionalString(schema.$id) && TSchema2(schema.items);
|
|
252
|
+
}
|
|
253
|
+
TypeGuard2.TIterator = TIterator;
|
|
254
|
+
function TKindOf(schema, kind) {
|
|
255
|
+
return TKind(schema) && schema[exports.Kind] === kind;
|
|
256
|
+
}
|
|
257
|
+
TypeGuard2.TKindOf = TKindOf;
|
|
258
|
+
function TKind(schema) {
|
|
259
|
+
return ValueGuard.IsObject(schema) && exports.Kind in schema && ValueGuard.IsString(schema[exports.Kind]);
|
|
260
|
+
}
|
|
261
|
+
TypeGuard2.TKind = TKind;
|
|
262
|
+
function TLiteralString(schema) {
|
|
263
|
+
return TLiteral(schema) && ValueGuard.IsString(schema.const);
|
|
264
|
+
}
|
|
265
|
+
TypeGuard2.TLiteralString = TLiteralString;
|
|
266
|
+
function TLiteralNumber(schema) {
|
|
267
|
+
return TLiteral(schema) && ValueGuard.IsNumber(schema.const);
|
|
268
|
+
}
|
|
269
|
+
TypeGuard2.TLiteralNumber = TLiteralNumber;
|
|
270
|
+
function TLiteralBoolean(schema) {
|
|
271
|
+
return TLiteral(schema) && ValueGuard.IsBoolean(schema.const);
|
|
272
|
+
}
|
|
273
|
+
TypeGuard2.TLiteralBoolean = TLiteralBoolean;
|
|
274
|
+
function TLiteral(schema) {
|
|
275
|
+
return TKindOf(schema, "Literal") && IsOptionalString(schema.$id) && (ValueGuard.IsBoolean(schema.const) || ValueGuard.IsNumber(schema.const) || ValueGuard.IsString(schema.const));
|
|
276
|
+
}
|
|
277
|
+
TypeGuard2.TLiteral = TLiteral;
|
|
278
|
+
function TNever(schema) {
|
|
279
|
+
return TKindOf(schema, "Never") && ValueGuard.IsObject(schema.not) && Object.getOwnPropertyNames(schema.not).length === 0;
|
|
280
|
+
}
|
|
281
|
+
TypeGuard2.TNever = TNever;
|
|
282
|
+
function TNot(schema) {
|
|
283
|
+
return TKindOf(schema, "Not") && TSchema2(schema.not);
|
|
284
|
+
}
|
|
285
|
+
TypeGuard2.TNot = TNot;
|
|
286
|
+
function TNull(schema) {
|
|
287
|
+
return TKindOf(schema, "Null") && schema.type === "null" && IsOptionalString(schema.$id);
|
|
288
|
+
}
|
|
289
|
+
TypeGuard2.TNull = TNull;
|
|
290
|
+
function TNumber(schema) {
|
|
291
|
+
return TKindOf(schema, "Number") && schema.type === "number" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximum) && IsOptionalNumber(schema.exclusiveMinimum) && IsOptionalNumber(schema.maximum) && IsOptionalNumber(schema.minimum) && IsOptionalNumber(schema.multipleOf);
|
|
292
|
+
}
|
|
293
|
+
TypeGuard2.TNumber = TNumber;
|
|
294
|
+
function TObject(schema) {
|
|
295
|
+
return TKindOf(schema, "Object") && schema.type === "object" && IsOptionalString(schema.$id) && ValueGuard.IsObject(schema.properties) && IsAdditionalProperties(schema.additionalProperties) && IsOptionalNumber(schema.minProperties) && IsOptionalNumber(schema.maxProperties) && Object.entries(schema.properties).every(([key, schema2]) => IsControlCharacterFree(key) && TSchema2(schema2));
|
|
296
|
+
}
|
|
297
|
+
TypeGuard2.TObject = TObject;
|
|
298
|
+
function TPromise(schema) {
|
|
299
|
+
return TKindOf(schema, "Promise") && schema.type === "Promise" && IsOptionalString(schema.$id) && TSchema2(schema.item);
|
|
300
|
+
}
|
|
301
|
+
TypeGuard2.TPromise = TPromise;
|
|
302
|
+
function TRecord(schema) {
|
|
303
|
+
return TKindOf(schema, "Record") && schema.type === "object" && IsOptionalString(schema.$id) && IsAdditionalProperties(schema.additionalProperties) && ValueGuard.IsObject(schema.patternProperties) && ((schema2) => {
|
|
304
|
+
const keys = Object.getOwnPropertyNames(schema2.patternProperties);
|
|
305
|
+
return keys.length === 1 && IsPattern(keys[0]) && ValueGuard.IsObject(schema2.patternProperties) && TSchema2(schema2.patternProperties[keys[0]]);
|
|
306
|
+
})(schema);
|
|
307
|
+
}
|
|
308
|
+
TypeGuard2.TRecord = TRecord;
|
|
309
|
+
function TRecursive(schema) {
|
|
310
|
+
return ValueGuard.IsObject(schema) && exports.Hint in schema && schema[exports.Hint] === "Recursive";
|
|
311
|
+
}
|
|
312
|
+
TypeGuard2.TRecursive = TRecursive;
|
|
313
|
+
function TRef(schema) {
|
|
314
|
+
return TKindOf(schema, "Ref") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
|
|
315
|
+
}
|
|
316
|
+
TypeGuard2.TRef = TRef;
|
|
317
|
+
function TString(schema) {
|
|
318
|
+
return TKindOf(schema, "String") && schema.type === "string" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minLength) && IsOptionalNumber(schema.maxLength) && IsOptionalPattern(schema.pattern) && IsOptionalFormat(schema.format);
|
|
319
|
+
}
|
|
320
|
+
TypeGuard2.TString = TString;
|
|
321
|
+
function TSymbol(schema) {
|
|
322
|
+
return TKindOf(schema, "Symbol") && schema.type === "symbol" && IsOptionalString(schema.$id);
|
|
323
|
+
}
|
|
324
|
+
TypeGuard2.TSymbol = TSymbol;
|
|
325
|
+
function TTemplateLiteral(schema) {
|
|
326
|
+
return TKindOf(schema, "TemplateLiteral") && schema.type === "string" && ValueGuard.IsString(schema.pattern) && schema.pattern[0] === "^" && schema.pattern[schema.pattern.length - 1] === "$";
|
|
327
|
+
}
|
|
328
|
+
TypeGuard2.TTemplateLiteral = TTemplateLiteral;
|
|
329
|
+
function TThis(schema) {
|
|
330
|
+
return TKindOf(schema, "This") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
|
|
331
|
+
}
|
|
332
|
+
TypeGuard2.TThis = TThis;
|
|
333
|
+
function TTransform(schema) {
|
|
334
|
+
return ValueGuard.IsObject(schema) && exports.Transform in schema;
|
|
335
|
+
}
|
|
336
|
+
TypeGuard2.TTransform = TTransform;
|
|
337
|
+
function TTuple(schema) {
|
|
338
|
+
return TKindOf(schema, "Tuple") && schema.type === "array" && IsOptionalString(schema.$id) && ValueGuard.IsNumber(schema.minItems) && ValueGuard.IsNumber(schema.maxItems) && schema.minItems === schema.maxItems && // empty
|
|
339
|
+
(ValueGuard.IsUndefined(schema.items) && ValueGuard.IsUndefined(schema.additionalItems) && schema.minItems === 0 || ValueGuard.IsArray(schema.items) && schema.items.every((schema2) => TSchema2(schema2)));
|
|
340
|
+
}
|
|
341
|
+
TypeGuard2.TTuple = TTuple;
|
|
342
|
+
function TUndefined(schema) {
|
|
343
|
+
return TKindOf(schema, "Undefined") && schema.type === "undefined" && IsOptionalString(schema.$id);
|
|
344
|
+
}
|
|
345
|
+
TypeGuard2.TUndefined = TUndefined;
|
|
346
|
+
function TUnionLiteral(schema) {
|
|
347
|
+
return TUnion(schema) && schema.anyOf.every((schema2) => TLiteralString(schema2) || TLiteralNumber(schema2));
|
|
348
|
+
}
|
|
349
|
+
TypeGuard2.TUnionLiteral = TUnionLiteral;
|
|
350
|
+
function TUnion(schema) {
|
|
351
|
+
return TKindOf(schema, "Union") && IsOptionalString(schema.$id) && ValueGuard.IsObject(schema) && ValueGuard.IsArray(schema.anyOf) && schema.anyOf.every((schema2) => TSchema2(schema2));
|
|
352
|
+
}
|
|
353
|
+
TypeGuard2.TUnion = TUnion;
|
|
354
|
+
function TUint8Array(schema) {
|
|
355
|
+
return TKindOf(schema, "Uint8Array") && schema.type === "Uint8Array" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minByteLength) && IsOptionalNumber(schema.maxByteLength);
|
|
356
|
+
}
|
|
357
|
+
TypeGuard2.TUint8Array = TUint8Array;
|
|
358
|
+
function TUnknown(schema) {
|
|
359
|
+
return TKindOf(schema, "Unknown") && IsOptionalString(schema.$id);
|
|
360
|
+
}
|
|
361
|
+
TypeGuard2.TUnknown = TUnknown;
|
|
362
|
+
function TUnsafe(schema) {
|
|
363
|
+
return TKindOf(schema, "Unsafe");
|
|
364
|
+
}
|
|
365
|
+
TypeGuard2.TUnsafe = TUnsafe;
|
|
366
|
+
function TVoid(schema) {
|
|
367
|
+
return TKindOf(schema, "Void") && schema.type === "void" && IsOptionalString(schema.$id);
|
|
368
|
+
}
|
|
369
|
+
TypeGuard2.TVoid = TVoid;
|
|
370
|
+
function TReadonly(schema) {
|
|
371
|
+
return ValueGuard.IsObject(schema) && schema[exports.Readonly] === "Readonly";
|
|
372
|
+
}
|
|
373
|
+
TypeGuard2.TReadonly = TReadonly;
|
|
374
|
+
function TOptional(schema) {
|
|
375
|
+
return ValueGuard.IsObject(schema) && schema[exports.Optional] === "Optional";
|
|
376
|
+
}
|
|
377
|
+
TypeGuard2.TOptional = TOptional;
|
|
378
|
+
function TSchema2(schema) {
|
|
379
|
+
return ValueGuard.IsObject(schema) && (TAny(schema) || TArray(schema) || TBoolean(schema) || TBigInt(schema) || TAsyncIterator(schema) || TConstructor(schema) || TDate(schema) || TFunction(schema) || TInteger(schema) || TIntersect(schema) || TIterator(schema) || TLiteral(schema) || TNever(schema) || TNot(schema) || TNull(schema) || TNumber(schema) || TObject(schema) || TPromise(schema) || TRecord(schema) || TRef(schema) || TString(schema) || TSymbol(schema) || TTemplateLiteral(schema) || TThis(schema) || TTuple(schema) || TUndefined(schema) || TUnion(schema) || TUint8Array(schema) || TUnknown(schema) || TUnsafe(schema) || TVoid(schema) || TKind(schema) && TypeRegistry.Has(schema[exports.Kind]));
|
|
380
|
+
}
|
|
381
|
+
TypeGuard2.TSchema = TSchema2;
|
|
382
|
+
})(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
|
|
383
|
+
var ExtendsUndefined;
|
|
384
|
+
(function(ExtendsUndefined2) {
|
|
385
|
+
function Check(schema) {
|
|
386
|
+
return schema[exports.Kind] === "Intersect" ? schema.allOf.every((schema2) => Check(schema2)) : schema[exports.Kind] === "Union" ? schema.anyOf.some((schema2) => Check(schema2)) : schema[exports.Kind] === "Undefined" ? true : schema[exports.Kind] === "Not" ? !Check(schema.not) : false;
|
|
387
|
+
}
|
|
388
|
+
ExtendsUndefined2.Check = Check;
|
|
389
|
+
})(ExtendsUndefined || (exports.ExtendsUndefined = ExtendsUndefined = {}));
|
|
390
|
+
var TypeExtendsError = class extends TypeBoxError {
|
|
391
|
+
};
|
|
392
|
+
exports.TypeExtendsError = TypeExtendsError;
|
|
393
|
+
var TypeExtendsResult;
|
|
394
|
+
(function(TypeExtendsResult2) {
|
|
395
|
+
TypeExtendsResult2[TypeExtendsResult2["Union"] = 0] = "Union";
|
|
396
|
+
TypeExtendsResult2[TypeExtendsResult2["True"] = 1] = "True";
|
|
397
|
+
TypeExtendsResult2[TypeExtendsResult2["False"] = 2] = "False";
|
|
398
|
+
})(TypeExtendsResult || (exports.TypeExtendsResult = TypeExtendsResult = {}));
|
|
399
|
+
var TypeExtends;
|
|
400
|
+
(function(TypeExtends2) {
|
|
401
|
+
function IntoBooleanResult(result) {
|
|
402
|
+
return result === TypeExtendsResult.False ? result : TypeExtendsResult.True;
|
|
403
|
+
}
|
|
404
|
+
function Throw(message) {
|
|
405
|
+
throw new TypeExtendsError(message);
|
|
406
|
+
}
|
|
407
|
+
function IsStructuralRight(right) {
|
|
408
|
+
return TypeGuard.TNever(right) || TypeGuard.TIntersect(right) || TypeGuard.TUnion(right) || TypeGuard.TUnknown(right) || TypeGuard.TAny(right);
|
|
409
|
+
}
|
|
410
|
+
function StructuralRight(left, right) {
|
|
411
|
+
return TypeGuard.TNever(right) ? TNeverRight(left, right) : TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TUnknown(right) ? TUnknownRight(left, right) : TypeGuard.TAny(right) ? TAnyRight(left, right) : Throw("StructuralRight");
|
|
412
|
+
}
|
|
413
|
+
function TAnyRight(left, right) {
|
|
414
|
+
return TypeExtendsResult.True;
|
|
415
|
+
}
|
|
416
|
+
function TAny(left, right) {
|
|
417
|
+
return TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) && right.anyOf.some((schema) => TypeGuard.TAny(schema) || TypeGuard.TUnknown(schema)) ? TypeExtendsResult.True : TypeGuard.TUnion(right) ? TypeExtendsResult.Union : TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeGuard.TAny(right) ? TypeExtendsResult.True : TypeExtendsResult.Union;
|
|
418
|
+
}
|
|
419
|
+
function TArrayRight(left, right) {
|
|
420
|
+
return TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
421
|
+
}
|
|
422
|
+
function TArray(left, right) {
|
|
423
|
+
return TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TArray(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
424
|
+
}
|
|
425
|
+
function TAsyncIterator(left, right) {
|
|
426
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TAsyncIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
427
|
+
}
|
|
428
|
+
function TBigInt(left, right) {
|
|
429
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TBigInt(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
430
|
+
}
|
|
431
|
+
function TBooleanRight(left, right) {
|
|
432
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsBoolean(left.const) ? TypeExtendsResult.True : TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
433
|
+
}
|
|
434
|
+
function TBoolean(left, right) {
|
|
435
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TBoolean(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
436
|
+
}
|
|
437
|
+
function TConstructor(left, right) {
|
|
438
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TConstructor(right) ? TypeExtendsResult.False : left.parameters.length > right.parameters.length ? TypeExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.returns, right.returns));
|
|
439
|
+
}
|
|
440
|
+
function TDate(left, right) {
|
|
441
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TDate(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
442
|
+
}
|
|
443
|
+
function TFunction(left, right) {
|
|
444
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TFunction(right) ? TypeExtendsResult.False : left.parameters.length > right.parameters.length ? TypeExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.returns, right.returns));
|
|
445
|
+
}
|
|
446
|
+
function TIntegerRight(left, right) {
|
|
447
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsNumber(left.const) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
448
|
+
}
|
|
449
|
+
function TInteger(left, right) {
|
|
450
|
+
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeExtendsResult.False;
|
|
451
|
+
}
|
|
452
|
+
function TIntersectRight(left, right) {
|
|
453
|
+
return right.allOf.every((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
454
|
+
}
|
|
455
|
+
function TIntersect(left, right) {
|
|
456
|
+
return left.allOf.some((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
457
|
+
}
|
|
458
|
+
function TIterator(left, right) {
|
|
459
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
460
|
+
}
|
|
461
|
+
function TLiteral(left, right) {
|
|
462
|
+
return TypeGuard.TLiteral(right) && right.const === left.const ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TString(right) ? TStringRight(left, right) : TypeGuard.TNumber(right) ? TNumberRight(left, right) : TypeGuard.TInteger(right) ? TIntegerRight(left, right) : TypeGuard.TBoolean(right) ? TBooleanRight(left, right) : TypeExtendsResult.False;
|
|
463
|
+
}
|
|
464
|
+
function TNeverRight(left, right) {
|
|
465
|
+
return TypeExtendsResult.False;
|
|
466
|
+
}
|
|
467
|
+
function TNever(left, right) {
|
|
468
|
+
return TypeExtendsResult.True;
|
|
469
|
+
}
|
|
470
|
+
function UnwrapTNot(schema) {
|
|
471
|
+
let [current, depth] = [schema, 0];
|
|
472
|
+
while (true) {
|
|
473
|
+
if (!TypeGuard.TNot(current))
|
|
474
|
+
break;
|
|
475
|
+
current = current.not;
|
|
476
|
+
depth += 1;
|
|
477
|
+
}
|
|
478
|
+
return depth % 2 === 0 ? current : exports.Type.Unknown();
|
|
479
|
+
}
|
|
480
|
+
function TNot(left, right) {
|
|
481
|
+
return TypeGuard.TNot(left) ? Visit(UnwrapTNot(left), right) : TypeGuard.TNot(right) ? Visit(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
|
|
482
|
+
}
|
|
483
|
+
function TNull(left, right) {
|
|
484
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TNull(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
485
|
+
}
|
|
486
|
+
function TNumberRight(left, right) {
|
|
487
|
+
return TypeGuard.TLiteralNumber(left) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
488
|
+
}
|
|
489
|
+
function TNumber(left, right) {
|
|
490
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
491
|
+
}
|
|
492
|
+
function IsObjectPropertyCount(schema, count) {
|
|
493
|
+
return Object.getOwnPropertyNames(schema.properties).length === count;
|
|
494
|
+
}
|
|
495
|
+
function IsObjectStringLike(schema) {
|
|
496
|
+
return IsObjectArrayLike(schema);
|
|
497
|
+
}
|
|
498
|
+
function IsObjectSymbolLike(schema) {
|
|
499
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && TypeGuard.TUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (TypeGuard.TString(schema.properties.description.anyOf[0]) && TypeGuard.TUndefined(schema.properties.description.anyOf[1]) || TypeGuard.TString(schema.properties.description.anyOf[1]) && TypeGuard.TUndefined(schema.properties.description.anyOf[0]));
|
|
500
|
+
}
|
|
501
|
+
function IsObjectNumberLike(schema) {
|
|
502
|
+
return IsObjectPropertyCount(schema, 0);
|
|
503
|
+
}
|
|
504
|
+
function IsObjectBooleanLike(schema) {
|
|
505
|
+
return IsObjectPropertyCount(schema, 0);
|
|
506
|
+
}
|
|
507
|
+
function IsObjectBigIntLike(schema) {
|
|
508
|
+
return IsObjectPropertyCount(schema, 0);
|
|
509
|
+
}
|
|
510
|
+
function IsObjectDateLike(schema) {
|
|
511
|
+
return IsObjectPropertyCount(schema, 0);
|
|
512
|
+
}
|
|
513
|
+
function IsObjectUint8ArrayLike(schema) {
|
|
514
|
+
return IsObjectArrayLike(schema);
|
|
515
|
+
}
|
|
516
|
+
function IsObjectFunctionLike(schema) {
|
|
517
|
+
const length = exports.Type.Number();
|
|
518
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
|
|
519
|
+
}
|
|
520
|
+
function IsObjectConstructorLike(schema) {
|
|
521
|
+
return IsObjectPropertyCount(schema, 0);
|
|
522
|
+
}
|
|
523
|
+
function IsObjectArrayLike(schema) {
|
|
524
|
+
const length = exports.Type.Number();
|
|
525
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
|
|
526
|
+
}
|
|
527
|
+
function IsObjectPromiseLike(schema) {
|
|
528
|
+
const then = exports.Type.Function([exports.Type.Any()], exports.Type.Any());
|
|
529
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit(schema.properties["then"], then)) === TypeExtendsResult.True;
|
|
530
|
+
}
|
|
531
|
+
function Property(left, right) {
|
|
532
|
+
return Visit(left, right) === TypeExtendsResult.False ? TypeExtendsResult.False : TypeGuard.TOptional(left) && !TypeGuard.TOptional(right) ? TypeExtendsResult.False : TypeExtendsResult.True;
|
|
533
|
+
}
|
|
534
|
+
function TObjectRight(left, right) {
|
|
535
|
+
return TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeGuard.TNever(left) || TypeGuard.TLiteralString(left) && IsObjectStringLike(right) || TypeGuard.TLiteralNumber(left) && IsObjectNumberLike(right) || TypeGuard.TLiteralBoolean(left) && IsObjectBooleanLike(right) || TypeGuard.TSymbol(left) && IsObjectSymbolLike(right) || TypeGuard.TBigInt(left) && IsObjectBigIntLike(right) || TypeGuard.TString(left) && IsObjectStringLike(right) || TypeGuard.TSymbol(left) && IsObjectSymbolLike(right) || TypeGuard.TNumber(left) && IsObjectNumberLike(right) || TypeGuard.TInteger(left) && IsObjectNumberLike(right) || TypeGuard.TBoolean(left) && IsObjectBooleanLike(right) || TypeGuard.TUint8Array(left) && IsObjectUint8ArrayLike(right) || TypeGuard.TDate(left) && IsObjectDateLike(right) || TypeGuard.TConstructor(left) && IsObjectConstructorLike(right) || TypeGuard.TFunction(left) && IsObjectFunctionLike(right) ? TypeExtendsResult.True : TypeGuard.TRecord(left) && TypeGuard.TString(RecordKey(left)) ? (() => {
|
|
536
|
+
return right[exports.Hint] === "Record" ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
537
|
+
})() : TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left)) ? (() => {
|
|
538
|
+
return IsObjectPropertyCount(right, 0) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
539
|
+
})() : TypeExtendsResult.False;
|
|
540
|
+
}
|
|
541
|
+
function TObject(left, right) {
|
|
542
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : !TypeGuard.TObject(right) ? TypeExtendsResult.False : (() => {
|
|
543
|
+
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
544
|
+
if (!(key in left.properties) && !TypeGuard.TOptional(right.properties[key])) {
|
|
545
|
+
return TypeExtendsResult.False;
|
|
546
|
+
}
|
|
547
|
+
if (TypeGuard.TOptional(right.properties[key])) {
|
|
548
|
+
return TypeExtendsResult.True;
|
|
549
|
+
}
|
|
550
|
+
if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
|
|
551
|
+
return TypeExtendsResult.False;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return TypeExtendsResult.True;
|
|
555
|
+
})();
|
|
556
|
+
}
|
|
557
|
+
function TPromise(left, right) {
|
|
558
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) && IsObjectPromiseLike(right) ? TypeExtendsResult.True : !TypeGuard.TPromise(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.item, right.item));
|
|
559
|
+
}
|
|
560
|
+
function RecordKey(schema) {
|
|
561
|
+
return exports.PatternNumberExact in schema.patternProperties ? exports.Type.Number() : exports.PatternStringExact in schema.patternProperties ? exports.Type.String() : Throw("Unknown record key pattern");
|
|
562
|
+
}
|
|
563
|
+
function RecordValue(schema) {
|
|
564
|
+
return exports.PatternNumberExact in schema.patternProperties ? schema.patternProperties[exports.PatternNumberExact] : exports.PatternStringExact in schema.patternProperties ? schema.patternProperties[exports.PatternStringExact] : Throw("Unable to get record value schema");
|
|
565
|
+
}
|
|
566
|
+
function TRecordRight(left, right) {
|
|
567
|
+
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
568
|
+
return TypeGuard.TLiteralString(left) && TypeGuard.TNumber(Key) && IntoBooleanResult(Visit(left, Value)) === TypeExtendsResult.True ? TypeExtendsResult.True : TypeGuard.TUint8Array(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TString(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TArray(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TObject(left) ? (() => {
|
|
569
|
+
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
570
|
+
if (Property(Value, left.properties[key]) === TypeExtendsResult.False) {
|
|
571
|
+
return TypeExtendsResult.False;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return TypeExtendsResult.True;
|
|
575
|
+
})() : TypeExtendsResult.False;
|
|
576
|
+
}
|
|
577
|
+
function TRecord(left, right) {
|
|
578
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TRecord(right) ? TypeExtendsResult.False : Visit(RecordValue(left), RecordValue(right));
|
|
579
|
+
}
|
|
580
|
+
function TStringRight(left, right) {
|
|
581
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsString(left.const) ? TypeExtendsResult.True : TypeGuard.TString(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
582
|
+
}
|
|
583
|
+
function TString(left, right) {
|
|
584
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TString(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
585
|
+
}
|
|
586
|
+
function TSymbol(left, right) {
|
|
587
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TSymbol(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
588
|
+
}
|
|
589
|
+
function TTemplateLiteral(left, right) {
|
|
590
|
+
return TypeGuard.TTemplateLiteral(left) ? Visit(TemplateLiteralResolver.Resolve(left), right) : TypeGuard.TTemplateLiteral(right) ? Visit(left, TemplateLiteralResolver.Resolve(right)) : Throw("Invalid fallthrough for TemplateLiteral");
|
|
591
|
+
}
|
|
592
|
+
function IsArrayOfTuple(left, right) {
|
|
593
|
+
return TypeGuard.TArray(right) && left.items !== void 0 && left.items.every((schema) => Visit(schema, right.items) === TypeExtendsResult.True);
|
|
594
|
+
}
|
|
595
|
+
function TTupleRight(left, right) {
|
|
596
|
+
return TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeExtendsResult.False;
|
|
597
|
+
}
|
|
598
|
+
function TTuple(left, right) {
|
|
599
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True : TypeGuard.TArray(right) && IsArrayOfTuple(left, right) ? TypeExtendsResult.True : !TypeGuard.TTuple(right) ? TypeExtendsResult.False : ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items) || !ValueGuard.IsUndefined(left.items) && ValueGuard.IsUndefined(right.items) ? TypeExtendsResult.False : ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items) ? TypeExtendsResult.True : left.items.every((schema, index) => Visit(schema, right.items[index]) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
600
|
+
}
|
|
601
|
+
function TUint8Array(left, right) {
|
|
602
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TUint8Array(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
603
|
+
}
|
|
604
|
+
function TUndefined(left, right) {
|
|
605
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TVoid(right) ? VoidRight(left, right) : TypeGuard.TUndefined(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
606
|
+
}
|
|
607
|
+
function TUnionRight(left, right) {
|
|
608
|
+
return right.anyOf.some((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
609
|
+
}
|
|
610
|
+
function TUnion(left, right) {
|
|
611
|
+
return left.anyOf.every((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
612
|
+
}
|
|
613
|
+
function TUnknownRight(left, right) {
|
|
614
|
+
return TypeExtendsResult.True;
|
|
615
|
+
}
|
|
616
|
+
function TUnknown(left, right) {
|
|
617
|
+
return TypeGuard.TNever(right) ? TNeverRight(left, right) : TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TAny(right) ? TAnyRight(left, right) : TypeGuard.TString(right) ? TStringRight(left, right) : TypeGuard.TNumber(right) ? TNumberRight(left, right) : TypeGuard.TInteger(right) ? TIntegerRight(left, right) : TypeGuard.TBoolean(right) ? TBooleanRight(left, right) : TypeGuard.TArray(right) ? TArrayRight(left, right) : TypeGuard.TTuple(right) ? TTupleRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
618
|
+
}
|
|
619
|
+
function VoidRight(left, right) {
|
|
620
|
+
return TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
621
|
+
}
|
|
622
|
+
function TVoid(left, right) {
|
|
623
|
+
return TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TUnknown(right) ? TUnknownRight(left, right) : TypeGuard.TAny(right) ? TAnyRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
624
|
+
}
|
|
625
|
+
function Visit(left, right) {
|
|
626
|
+
return (
|
|
627
|
+
// resolvable
|
|
628
|
+
TypeGuard.TTemplateLiteral(left) || TypeGuard.TTemplateLiteral(right) ? TTemplateLiteral(left, right) : TypeGuard.TNot(left) || TypeGuard.TNot(right) ? TNot(left, right) : (
|
|
629
|
+
// standard
|
|
630
|
+
TypeGuard.TAny(left) ? TAny(left, right) : TypeGuard.TArray(left) ? TArray(left, right) : TypeGuard.TBigInt(left) ? TBigInt(left, right) : TypeGuard.TBoolean(left) ? TBoolean(left, right) : TypeGuard.TAsyncIterator(left) ? TAsyncIterator(left, right) : TypeGuard.TConstructor(left) ? TConstructor(left, right) : TypeGuard.TDate(left) ? TDate(left, right) : TypeGuard.TFunction(left) ? TFunction(left, right) : TypeGuard.TInteger(left) ? TInteger(left, right) : TypeGuard.TIntersect(left) ? TIntersect(left, right) : TypeGuard.TIterator(left) ? TIterator(left, right) : TypeGuard.TLiteral(left) ? TLiteral(left, right) : TypeGuard.TNever(left) ? TNever(left, right) : TypeGuard.TNull(left) ? TNull(left, right) : TypeGuard.TNumber(left) ? TNumber(left, right) : TypeGuard.TObject(left) ? TObject(left, right) : TypeGuard.TRecord(left) ? TRecord(left, right) : TypeGuard.TString(left) ? TString(left, right) : TypeGuard.TSymbol(left) ? TSymbol(left, right) : TypeGuard.TTuple(left) ? TTuple(left, right) : TypeGuard.TPromise(left) ? TPromise(left, right) : TypeGuard.TUint8Array(left) ? TUint8Array(left, right) : TypeGuard.TUndefined(left) ? TUndefined(left, right) : TypeGuard.TUnion(left) ? TUnion(left, right) : TypeGuard.TUnknown(left) ? TUnknown(left, right) : TypeGuard.TVoid(left) ? TVoid(left, right) : Throw(`Unknown left type operand '${left[exports.Kind]}'`)
|
|
631
|
+
)
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
function Extends(left, right) {
|
|
635
|
+
return Visit(left, right);
|
|
636
|
+
}
|
|
637
|
+
TypeExtends2.Extends = Extends;
|
|
638
|
+
})(TypeExtends || (exports.TypeExtends = TypeExtends = {}));
|
|
639
|
+
var TypeClone;
|
|
640
|
+
(function(TypeClone2) {
|
|
641
|
+
function ArrayType(value) {
|
|
642
|
+
return value.map((value2) => Visit(value2));
|
|
643
|
+
}
|
|
644
|
+
function DateType(value) {
|
|
645
|
+
return new Date(value.getTime());
|
|
646
|
+
}
|
|
647
|
+
function Uint8ArrayType(value) {
|
|
648
|
+
return new Uint8Array(value);
|
|
649
|
+
}
|
|
650
|
+
function ObjectType(value) {
|
|
651
|
+
const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
652
|
+
const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
653
|
+
return { ...clonedProperties, ...clonedSymbols };
|
|
654
|
+
}
|
|
655
|
+
function Visit(value) {
|
|
656
|
+
return ValueGuard.IsArray(value) ? ArrayType(value) : ValueGuard.IsDate(value) ? DateType(value) : ValueGuard.IsUint8Array(value) ? Uint8ArrayType(value) : ValueGuard.IsObject(value) ? ObjectType(value) : value;
|
|
657
|
+
}
|
|
658
|
+
function Rest(schemas) {
|
|
659
|
+
return schemas.map((schema) => Type2(schema));
|
|
660
|
+
}
|
|
661
|
+
TypeClone2.Rest = Rest;
|
|
662
|
+
function Type2(schema, options = {}) {
|
|
663
|
+
return { ...Visit(schema), ...options };
|
|
664
|
+
}
|
|
665
|
+
TypeClone2.Type = Type2;
|
|
666
|
+
})(TypeClone || (exports.TypeClone = TypeClone = {}));
|
|
667
|
+
var IndexedAccessor;
|
|
668
|
+
(function(IndexedAccessor2) {
|
|
669
|
+
function OptionalUnwrap(schema) {
|
|
670
|
+
return schema.map((schema2) => {
|
|
671
|
+
const { [exports.Optional]: _, ...clone } = TypeClone.Type(schema2);
|
|
672
|
+
return clone;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
function IsIntersectOptional(schema) {
|
|
676
|
+
return schema.every((schema2) => TypeGuard.TOptional(schema2));
|
|
677
|
+
}
|
|
678
|
+
function IsUnionOptional(schema) {
|
|
679
|
+
return schema.some((schema2) => TypeGuard.TOptional(schema2));
|
|
680
|
+
}
|
|
681
|
+
function ResolveIntersect(schema) {
|
|
682
|
+
return IsIntersectOptional(schema.allOf) ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
|
|
683
|
+
}
|
|
684
|
+
function ResolveUnion(schema) {
|
|
685
|
+
return IsUnionOptional(schema.anyOf) ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
|
|
686
|
+
}
|
|
687
|
+
function ResolveOptional(schema) {
|
|
688
|
+
return schema[exports.Kind] === "Intersect" ? ResolveIntersect(schema) : schema[exports.Kind] === "Union" ? ResolveUnion(schema) : schema;
|
|
689
|
+
}
|
|
690
|
+
function TIntersect(schema, key) {
|
|
691
|
+
const resolved = schema.allOf.reduce((acc, schema2) => {
|
|
692
|
+
const indexed = Visit(schema2, key);
|
|
693
|
+
return indexed[exports.Kind] === "Never" ? acc : [...acc, indexed];
|
|
694
|
+
}, []);
|
|
695
|
+
return ResolveOptional(exports.Type.Intersect(resolved));
|
|
696
|
+
}
|
|
697
|
+
function TUnion(schema, key) {
|
|
698
|
+
const resolved = schema.anyOf.map((schema2) => Visit(schema2, key));
|
|
699
|
+
return ResolveOptional(exports.Type.Union(resolved));
|
|
700
|
+
}
|
|
701
|
+
function TObject(schema, key) {
|
|
702
|
+
const property = schema.properties[key];
|
|
703
|
+
return ValueGuard.IsUndefined(property) ? exports.Type.Never() : exports.Type.Union([property]);
|
|
704
|
+
}
|
|
705
|
+
function TTuple(schema, key) {
|
|
706
|
+
const items = schema.items;
|
|
707
|
+
if (ValueGuard.IsUndefined(items))
|
|
708
|
+
return exports.Type.Never();
|
|
709
|
+
const element = items[key];
|
|
710
|
+
if (ValueGuard.IsUndefined(element))
|
|
711
|
+
return exports.Type.Never();
|
|
712
|
+
return element;
|
|
713
|
+
}
|
|
714
|
+
function Visit(schema, key) {
|
|
715
|
+
return schema[exports.Kind] === "Intersect" ? TIntersect(schema, key) : schema[exports.Kind] === "Union" ? TUnion(schema, key) : schema[exports.Kind] === "Object" ? TObject(schema, key) : schema[exports.Kind] === "Tuple" ? TTuple(schema, key) : exports.Type.Never();
|
|
716
|
+
}
|
|
717
|
+
function Resolve(schema, keys, options = {}) {
|
|
718
|
+
const resolved = keys.map((key) => Visit(schema, key.toString()));
|
|
719
|
+
return ResolveOptional(exports.Type.Union(resolved, options));
|
|
720
|
+
}
|
|
721
|
+
IndexedAccessor2.Resolve = Resolve;
|
|
722
|
+
})(IndexedAccessor || (exports.IndexedAccessor = IndexedAccessor = {}));
|
|
723
|
+
var Intrinsic;
|
|
724
|
+
(function(Intrinsic2) {
|
|
725
|
+
function Uncapitalize(value) {
|
|
726
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
727
|
+
return `${first.toLowerCase()}${rest}`;
|
|
728
|
+
}
|
|
729
|
+
function Capitalize(value) {
|
|
730
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
731
|
+
return `${first.toUpperCase()}${rest}`;
|
|
732
|
+
}
|
|
733
|
+
function Uppercase(value) {
|
|
734
|
+
return value.toUpperCase();
|
|
735
|
+
}
|
|
736
|
+
function Lowercase(value) {
|
|
737
|
+
return value.toLowerCase();
|
|
738
|
+
}
|
|
739
|
+
function IntrinsicTemplateLiteral(schema, mode) {
|
|
740
|
+
const expression = TemplateLiteralParser.ParseExact(schema.pattern);
|
|
741
|
+
const finite = TemplateLiteralFinite.Check(expression);
|
|
742
|
+
if (!finite)
|
|
743
|
+
return { ...schema, pattern: IntrinsicLiteral(schema.pattern, mode) };
|
|
744
|
+
const strings = [...TemplateLiteralGenerator.Generate(expression)];
|
|
745
|
+
const literals = strings.map((value) => exports.Type.Literal(value));
|
|
746
|
+
const mapped = IntrinsicRest(literals, mode);
|
|
747
|
+
const union = exports.Type.Union(mapped);
|
|
748
|
+
return exports.Type.TemplateLiteral([union]);
|
|
749
|
+
}
|
|
750
|
+
function IntrinsicLiteral(value, mode) {
|
|
751
|
+
return typeof value === "string" ? mode === "Uncapitalize" ? Uncapitalize(value) : mode === "Capitalize" ? Capitalize(value) : mode === "Uppercase" ? Uppercase(value) : mode === "Lowercase" ? Lowercase(value) : value : value.toString();
|
|
752
|
+
}
|
|
753
|
+
function IntrinsicRest(schema, mode) {
|
|
754
|
+
if (schema.length === 0)
|
|
755
|
+
return [];
|
|
756
|
+
const [L, ...R] = schema;
|
|
757
|
+
return [Map2(L, mode), ...IntrinsicRest(R, mode)];
|
|
758
|
+
}
|
|
759
|
+
function Visit(schema, mode) {
|
|
760
|
+
return TypeGuard.TTemplateLiteral(schema) ? IntrinsicTemplateLiteral(schema, mode) : TypeGuard.TUnion(schema) ? exports.Type.Union(IntrinsicRest(schema.anyOf, mode)) : TypeGuard.TLiteral(schema) ? exports.Type.Literal(IntrinsicLiteral(schema.const, mode)) : schema;
|
|
761
|
+
}
|
|
762
|
+
function Map2(schema, mode) {
|
|
763
|
+
return Visit(schema, mode);
|
|
764
|
+
}
|
|
765
|
+
Intrinsic2.Map = Map2;
|
|
766
|
+
})(Intrinsic || (exports.Intrinsic = Intrinsic = {}));
|
|
767
|
+
var ObjectMap;
|
|
768
|
+
(function(ObjectMap2) {
|
|
769
|
+
function TIntersect(schema, callback) {
|
|
770
|
+
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
771
|
+
}
|
|
772
|
+
function TUnion(schema, callback) {
|
|
773
|
+
return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
774
|
+
}
|
|
775
|
+
function TObject(schema, callback) {
|
|
776
|
+
return callback(schema);
|
|
777
|
+
}
|
|
778
|
+
function Visit(schema, callback) {
|
|
779
|
+
return schema[exports.Kind] === "Intersect" ? TIntersect(schema, callback) : schema[exports.Kind] === "Union" ? TUnion(schema, callback) : schema[exports.Kind] === "Object" ? TObject(schema, callback) : schema;
|
|
780
|
+
}
|
|
781
|
+
function Map2(schema, callback, options) {
|
|
782
|
+
return { ...Visit(TypeClone.Type(schema), callback), ...options };
|
|
783
|
+
}
|
|
784
|
+
ObjectMap2.Map = Map2;
|
|
785
|
+
})(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
|
|
786
|
+
var KeyResolver;
|
|
787
|
+
(function(KeyResolver2) {
|
|
788
|
+
function UnwrapPattern(key) {
|
|
789
|
+
return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
|
|
790
|
+
}
|
|
791
|
+
function TIntersect(schema, options) {
|
|
792
|
+
return schema.allOf.reduce((acc, schema2) => [...acc, ...Visit(schema2, options)], []);
|
|
793
|
+
}
|
|
794
|
+
function TUnion(schema, options) {
|
|
795
|
+
const sets = schema.anyOf.map((inner) => Visit(inner, options));
|
|
796
|
+
return [...sets.reduce((set, outer) => outer.map((key) => sets.every((inner) => inner.includes(key)) ? set.add(key) : set)[0], /* @__PURE__ */ new Set())];
|
|
797
|
+
}
|
|
798
|
+
function TObject(schema, options) {
|
|
799
|
+
return Object.getOwnPropertyNames(schema.properties);
|
|
800
|
+
}
|
|
801
|
+
function TRecord(schema, options) {
|
|
802
|
+
return options.includePatterns ? Object.getOwnPropertyNames(schema.patternProperties) : [];
|
|
803
|
+
}
|
|
804
|
+
function Visit(schema, options) {
|
|
805
|
+
return TypeGuard.TIntersect(schema) ? TIntersect(schema, options) : TypeGuard.TUnion(schema) ? TUnion(schema, options) : TypeGuard.TObject(schema) ? TObject(schema, options) : TypeGuard.TRecord(schema) ? TRecord(schema, options) : [];
|
|
806
|
+
}
|
|
807
|
+
function ResolveKeys(schema, options) {
|
|
808
|
+
return [...new Set(Visit(schema, options))];
|
|
809
|
+
}
|
|
810
|
+
KeyResolver2.ResolveKeys = ResolveKeys;
|
|
811
|
+
function ResolvePattern(schema) {
|
|
812
|
+
const keys = ResolveKeys(schema, { includePatterns: true });
|
|
813
|
+
const pattern = keys.map((key) => `(${UnwrapPattern(key)})`);
|
|
814
|
+
return `^(${pattern.join("|")})$`;
|
|
815
|
+
}
|
|
816
|
+
KeyResolver2.ResolvePattern = ResolvePattern;
|
|
817
|
+
})(KeyResolver || (exports.KeyResolver = KeyResolver = {}));
|
|
818
|
+
var KeyArrayResolverError = class extends TypeBoxError {
|
|
819
|
+
};
|
|
820
|
+
exports.KeyArrayResolverError = KeyArrayResolverError;
|
|
821
|
+
var KeyArrayResolver;
|
|
822
|
+
(function(KeyArrayResolver2) {
|
|
823
|
+
function Resolve(schema) {
|
|
824
|
+
return Array.isArray(schema) ? schema : TypeGuard.TUnionLiteral(schema) ? schema.anyOf.map((schema2) => schema2.const.toString()) : TypeGuard.TLiteral(schema) ? [schema.const] : TypeGuard.TTemplateLiteral(schema) ? (() => {
|
|
825
|
+
const expression = TemplateLiteralParser.ParseExact(schema.pattern);
|
|
826
|
+
if (!TemplateLiteralFinite.Check(expression))
|
|
827
|
+
throw new KeyArrayResolverError("Cannot resolve keys from infinite template expression");
|
|
828
|
+
return [...TemplateLiteralGenerator.Generate(expression)];
|
|
829
|
+
})() : [];
|
|
830
|
+
}
|
|
831
|
+
KeyArrayResolver2.Resolve = Resolve;
|
|
832
|
+
})(KeyArrayResolver || (exports.KeyArrayResolver = KeyArrayResolver = {}));
|
|
833
|
+
var UnionResolver;
|
|
834
|
+
(function(UnionResolver2) {
|
|
835
|
+
function* TUnion(union) {
|
|
836
|
+
for (const schema of union.anyOf) {
|
|
837
|
+
if (schema[exports.Kind] === "Union") {
|
|
838
|
+
yield* TUnion(schema);
|
|
839
|
+
} else {
|
|
840
|
+
yield schema;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
function Resolve(union) {
|
|
845
|
+
return exports.Type.Union([...TUnion(union)], { ...union });
|
|
846
|
+
}
|
|
847
|
+
UnionResolver2.Resolve = Resolve;
|
|
848
|
+
})(UnionResolver || (exports.UnionResolver = UnionResolver = {}));
|
|
849
|
+
var TemplateLiteralPatternError = class extends TypeBoxError {
|
|
850
|
+
};
|
|
851
|
+
exports.TemplateLiteralPatternError = TemplateLiteralPatternError;
|
|
852
|
+
var TemplateLiteralPattern;
|
|
853
|
+
(function(TemplateLiteralPattern2) {
|
|
854
|
+
function Throw(message) {
|
|
855
|
+
throw new TemplateLiteralPatternError(message);
|
|
856
|
+
}
|
|
857
|
+
function Escape(value) {
|
|
858
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
859
|
+
}
|
|
860
|
+
function Visit(schema, acc) {
|
|
861
|
+
return TypeGuard.TTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : TypeGuard.TUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit(schema2, acc)).join("|")})` : TypeGuard.TNumber(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TInteger(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TBigInt(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TString(schema) ? `${acc}${exports.PatternString}` : TypeGuard.TLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : TypeGuard.TBoolean(schema) ? `${acc}${exports.PatternBoolean}` : Throw(`Unexpected Kind '${schema[exports.Kind]}'`);
|
|
862
|
+
}
|
|
863
|
+
function Create(kinds) {
|
|
864
|
+
return `^${kinds.map((schema) => Visit(schema, "")).join("")}$`;
|
|
865
|
+
}
|
|
866
|
+
TemplateLiteralPattern2.Create = Create;
|
|
867
|
+
})(TemplateLiteralPattern || (exports.TemplateLiteralPattern = TemplateLiteralPattern = {}));
|
|
868
|
+
var TemplateLiteralResolver;
|
|
869
|
+
(function(TemplateLiteralResolver2) {
|
|
870
|
+
function Resolve(template) {
|
|
871
|
+
const expression = TemplateLiteralParser.ParseExact(template.pattern);
|
|
872
|
+
if (!TemplateLiteralFinite.Check(expression))
|
|
873
|
+
return exports.Type.String();
|
|
874
|
+
const literals = [...TemplateLiteralGenerator.Generate(expression)].map((value) => exports.Type.Literal(value));
|
|
875
|
+
return exports.Type.Union(literals);
|
|
876
|
+
}
|
|
877
|
+
TemplateLiteralResolver2.Resolve = Resolve;
|
|
878
|
+
})(TemplateLiteralResolver || (exports.TemplateLiteralResolver = TemplateLiteralResolver = {}));
|
|
879
|
+
var TemplateLiteralParserError = class extends TypeBoxError {
|
|
880
|
+
};
|
|
881
|
+
exports.TemplateLiteralParserError = TemplateLiteralParserError;
|
|
882
|
+
var TemplateLiteralParser;
|
|
883
|
+
(function(TemplateLiteralParser2) {
|
|
884
|
+
function IsNonEscaped(pattern, index, char) {
|
|
885
|
+
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
886
|
+
}
|
|
887
|
+
function IsOpenParen(pattern, index) {
|
|
888
|
+
return IsNonEscaped(pattern, index, "(");
|
|
889
|
+
}
|
|
890
|
+
function IsCloseParen(pattern, index) {
|
|
891
|
+
return IsNonEscaped(pattern, index, ")");
|
|
892
|
+
}
|
|
893
|
+
function IsSeparator(pattern, index) {
|
|
894
|
+
return IsNonEscaped(pattern, index, "|");
|
|
895
|
+
}
|
|
896
|
+
function IsGroup(pattern) {
|
|
897
|
+
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
898
|
+
return false;
|
|
899
|
+
let count = 0;
|
|
900
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
901
|
+
if (IsOpenParen(pattern, index))
|
|
902
|
+
count += 1;
|
|
903
|
+
if (IsCloseParen(pattern, index))
|
|
904
|
+
count -= 1;
|
|
905
|
+
if (count === 0 && index !== pattern.length - 1)
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
return true;
|
|
909
|
+
}
|
|
910
|
+
function InGroup(pattern) {
|
|
911
|
+
return pattern.slice(1, pattern.length - 1);
|
|
912
|
+
}
|
|
913
|
+
function IsPrecedenceOr(pattern) {
|
|
914
|
+
let count = 0;
|
|
915
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
916
|
+
if (IsOpenParen(pattern, index))
|
|
917
|
+
count += 1;
|
|
918
|
+
if (IsCloseParen(pattern, index))
|
|
919
|
+
count -= 1;
|
|
920
|
+
if (IsSeparator(pattern, index) && count === 0)
|
|
921
|
+
return true;
|
|
922
|
+
}
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
function IsPrecedenceAnd(pattern) {
|
|
926
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
927
|
+
if (IsOpenParen(pattern, index))
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
function Or(pattern) {
|
|
933
|
+
let [count, start] = [0, 0];
|
|
934
|
+
const expressions = [];
|
|
935
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
936
|
+
if (IsOpenParen(pattern, index))
|
|
937
|
+
count += 1;
|
|
938
|
+
if (IsCloseParen(pattern, index))
|
|
939
|
+
count -= 1;
|
|
940
|
+
if (IsSeparator(pattern, index) && count === 0) {
|
|
941
|
+
const range2 = pattern.slice(start, index);
|
|
942
|
+
if (range2.length > 0)
|
|
943
|
+
expressions.push(Parse(range2));
|
|
944
|
+
start = index + 1;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const range = pattern.slice(start);
|
|
948
|
+
if (range.length > 0)
|
|
949
|
+
expressions.push(Parse(range));
|
|
950
|
+
if (expressions.length === 0)
|
|
951
|
+
return { type: "const", const: "" };
|
|
952
|
+
if (expressions.length === 1)
|
|
953
|
+
return expressions[0];
|
|
954
|
+
return { type: "or", expr: expressions };
|
|
955
|
+
}
|
|
956
|
+
function And(pattern) {
|
|
957
|
+
function Group(value, index) {
|
|
958
|
+
if (!IsOpenParen(value, index))
|
|
959
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
|
|
960
|
+
let count = 0;
|
|
961
|
+
for (let scan = index; scan < value.length; scan++) {
|
|
962
|
+
if (IsOpenParen(value, scan))
|
|
963
|
+
count += 1;
|
|
964
|
+
if (IsCloseParen(value, scan))
|
|
965
|
+
count -= 1;
|
|
966
|
+
if (count === 0)
|
|
967
|
+
return [index, scan];
|
|
968
|
+
}
|
|
969
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
|
|
970
|
+
}
|
|
971
|
+
function Range(pattern2, index) {
|
|
972
|
+
for (let scan = index; scan < pattern2.length; scan++) {
|
|
973
|
+
if (IsOpenParen(pattern2, scan))
|
|
974
|
+
return [index, scan];
|
|
975
|
+
}
|
|
976
|
+
return [index, pattern2.length];
|
|
977
|
+
}
|
|
978
|
+
const expressions = [];
|
|
979
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
980
|
+
if (IsOpenParen(pattern, index)) {
|
|
981
|
+
const [start, end] = Group(pattern, index);
|
|
982
|
+
const range = pattern.slice(start, end + 1);
|
|
983
|
+
expressions.push(Parse(range));
|
|
984
|
+
index = end;
|
|
985
|
+
} else {
|
|
986
|
+
const [start, end] = Range(pattern, index);
|
|
987
|
+
const range = pattern.slice(start, end);
|
|
988
|
+
if (range.length > 0)
|
|
989
|
+
expressions.push(Parse(range));
|
|
990
|
+
index = end - 1;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
|
|
994
|
+
}
|
|
995
|
+
function Parse(pattern) {
|
|
996
|
+
return IsGroup(pattern) ? Parse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: pattern };
|
|
997
|
+
}
|
|
998
|
+
TemplateLiteralParser2.Parse = Parse;
|
|
999
|
+
function ParseExact(pattern) {
|
|
1000
|
+
return Parse(pattern.slice(1, pattern.length - 1));
|
|
1001
|
+
}
|
|
1002
|
+
TemplateLiteralParser2.ParseExact = ParseExact;
|
|
1003
|
+
})(TemplateLiteralParser || (exports.TemplateLiteralParser = TemplateLiteralParser = {}));
|
|
1004
|
+
var TemplateLiteralFiniteError = class extends TypeBoxError {
|
|
1005
|
+
};
|
|
1006
|
+
exports.TemplateLiteralFiniteError = TemplateLiteralFiniteError;
|
|
1007
|
+
var TemplateLiteralFinite;
|
|
1008
|
+
(function(TemplateLiteralFinite2) {
|
|
1009
|
+
function Throw(message) {
|
|
1010
|
+
throw new TemplateLiteralFiniteError(message);
|
|
1011
|
+
}
|
|
1012
|
+
function IsNumber(expression) {
|
|
1013
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*";
|
|
1014
|
+
}
|
|
1015
|
+
function IsBoolean(expression) {
|
|
1016
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false";
|
|
1017
|
+
}
|
|
1018
|
+
function IsString(expression) {
|
|
1019
|
+
return expression.type === "const" && expression.const === ".*";
|
|
1020
|
+
}
|
|
1021
|
+
function Check(expression) {
|
|
1022
|
+
return IsBoolean(expression) ? true : IsNumber(expression) || IsString(expression) ? false : expression.type === "and" ? expression.expr.every((expr) => Check(expr)) : expression.type === "or" ? expression.expr.every((expr) => Check(expr)) : expression.type === "const" ? true : Throw(`Unknown expression type`);
|
|
1023
|
+
}
|
|
1024
|
+
TemplateLiteralFinite2.Check = Check;
|
|
1025
|
+
})(TemplateLiteralFinite || (exports.TemplateLiteralFinite = TemplateLiteralFinite = {}));
|
|
1026
|
+
var TemplateLiteralGeneratorError = class extends TypeBoxError {
|
|
1027
|
+
};
|
|
1028
|
+
exports.TemplateLiteralGeneratorError = TemplateLiteralGeneratorError;
|
|
1029
|
+
var TemplateLiteralGenerator;
|
|
1030
|
+
(function(TemplateLiteralGenerator2) {
|
|
1031
|
+
function* Reduce(buffer) {
|
|
1032
|
+
if (buffer.length === 1)
|
|
1033
|
+
return yield* buffer[0];
|
|
1034
|
+
for (const left of buffer[0]) {
|
|
1035
|
+
for (const right of Reduce(buffer.slice(1))) {
|
|
1036
|
+
yield `${left}${right}`;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function* And(expression) {
|
|
1041
|
+
return yield* Reduce(expression.expr.map((expr) => [...Generate(expr)]));
|
|
1042
|
+
}
|
|
1043
|
+
function* Or(expression) {
|
|
1044
|
+
for (const expr of expression.expr)
|
|
1045
|
+
yield* Generate(expr);
|
|
1046
|
+
}
|
|
1047
|
+
function* Const(expression) {
|
|
1048
|
+
return yield expression.const;
|
|
1049
|
+
}
|
|
1050
|
+
function* Generate(expression) {
|
|
1051
|
+
return expression.type === "and" ? yield* And(expression) : expression.type === "or" ? yield* Or(expression) : expression.type === "const" ? yield* Const(expression) : (() => {
|
|
1052
|
+
throw new TemplateLiteralGeneratorError("Unknown expression");
|
|
1053
|
+
})();
|
|
1054
|
+
}
|
|
1055
|
+
TemplateLiteralGenerator2.Generate = Generate;
|
|
1056
|
+
})(TemplateLiteralGenerator || (exports.TemplateLiteralGenerator = TemplateLiteralGenerator = {}));
|
|
1057
|
+
var TemplateLiteralDslParser;
|
|
1058
|
+
(function(TemplateLiteralDslParser2) {
|
|
1059
|
+
function* ParseUnion(template) {
|
|
1060
|
+
const trim = template.trim().replace(/"|'/g, "");
|
|
1061
|
+
return trim === "boolean" ? yield exports.Type.Boolean() : trim === "number" ? yield exports.Type.Number() : trim === "bigint" ? yield exports.Type.BigInt() : trim === "string" ? yield exports.Type.String() : yield (() => {
|
|
1062
|
+
const literals = trim.split("|").map((literal) => exports.Type.Literal(literal.trim()));
|
|
1063
|
+
return literals.length === 0 ? exports.Type.Never() : literals.length === 1 ? literals[0] : exports.Type.Union(literals);
|
|
1064
|
+
})();
|
|
1065
|
+
}
|
|
1066
|
+
function* ParseTerminal(template) {
|
|
1067
|
+
if (template[1] !== "{") {
|
|
1068
|
+
const L = exports.Type.Literal("$");
|
|
1069
|
+
const R = ParseLiteral(template.slice(1));
|
|
1070
|
+
return yield* [L, ...R];
|
|
1071
|
+
}
|
|
1072
|
+
for (let i = 2; i < template.length; i++) {
|
|
1073
|
+
if (template[i] === "}") {
|
|
1074
|
+
const L = ParseUnion(template.slice(2, i));
|
|
1075
|
+
const R = ParseLiteral(template.slice(i + 1));
|
|
1076
|
+
return yield* [...L, ...R];
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
yield exports.Type.Literal(template);
|
|
1080
|
+
}
|
|
1081
|
+
function* ParseLiteral(template) {
|
|
1082
|
+
for (let i = 0; i < template.length; i++) {
|
|
1083
|
+
if (template[i] === "$") {
|
|
1084
|
+
const L = exports.Type.Literal(template.slice(0, i));
|
|
1085
|
+
const R = ParseTerminal(template.slice(i));
|
|
1086
|
+
return yield* [L, ...R];
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
yield exports.Type.Literal(template);
|
|
1090
|
+
}
|
|
1091
|
+
function Parse(template_dsl) {
|
|
1092
|
+
return [...ParseLiteral(template_dsl)];
|
|
1093
|
+
}
|
|
1094
|
+
TemplateLiteralDslParser2.Parse = Parse;
|
|
1095
|
+
})(TemplateLiteralDslParser || (exports.TemplateLiteralDslParser = TemplateLiteralDslParser = {}));
|
|
1096
|
+
var TransformDecodeBuilder = class {
|
|
1097
|
+
constructor(schema) {
|
|
1098
|
+
this.schema = schema;
|
|
1099
|
+
}
|
|
1100
|
+
Decode(decode) {
|
|
1101
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
exports.TransformDecodeBuilder = TransformDecodeBuilder;
|
|
1105
|
+
var TransformEncodeBuilder = class {
|
|
1106
|
+
constructor(schema, decode) {
|
|
1107
|
+
this.schema = schema;
|
|
1108
|
+
this.decode = decode;
|
|
1109
|
+
}
|
|
1110
|
+
Encode(encode) {
|
|
1111
|
+
const schema = TypeClone.Type(this.schema);
|
|
1112
|
+
return TypeGuard.TTransform(schema) ? (() => {
|
|
1113
|
+
const Encode = (value) => schema[exports.Transform].Encode(encode(value));
|
|
1114
|
+
const Decode = (value) => this.decode(schema[exports.Transform].Decode(value));
|
|
1115
|
+
const Codec = { Encode, Decode };
|
|
1116
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1117
|
+
})() : (() => {
|
|
1118
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
1119
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1120
|
+
})();
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
exports.TransformEncodeBuilder = TransformEncodeBuilder;
|
|
1124
|
+
var TypeOrdinal = 0;
|
|
1125
|
+
var TypeBuilderError = class extends TypeBoxError {
|
|
1126
|
+
};
|
|
1127
|
+
exports.TypeBuilderError = TypeBuilderError;
|
|
1128
|
+
var TypeBuilder = class {
|
|
1129
|
+
/** `[Internal]` Creates a schema without `static` and `params` types */
|
|
1130
|
+
Create(schema) {
|
|
1131
|
+
return schema;
|
|
1132
|
+
}
|
|
1133
|
+
/** `[Internal]` Throws a TypeBuilder error with the given message */
|
|
1134
|
+
Throw(message) {
|
|
1135
|
+
throw new TypeBuilderError(message);
|
|
1136
|
+
}
|
|
1137
|
+
/** `[Internal]` Discards property keys from the given record type */
|
|
1138
|
+
Discard(record, keys) {
|
|
1139
|
+
return keys.reduce((acc, key) => {
|
|
1140
|
+
const { [key]: _, ...rest } = acc;
|
|
1141
|
+
return rest;
|
|
1142
|
+
}, record);
|
|
1143
|
+
}
|
|
1144
|
+
/** `[Json]` Omits compositing symbols from this schema */
|
|
1145
|
+
Strict(schema) {
|
|
1146
|
+
return JSON.parse(JSON.stringify(schema));
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
exports.TypeBuilder = TypeBuilder;
|
|
1150
|
+
var JsonTypeBuilder = class extends TypeBuilder {
|
|
1151
|
+
// ------------------------------------------------------------------------
|
|
1152
|
+
// Modifiers
|
|
1153
|
+
// ------------------------------------------------------------------------
|
|
1154
|
+
/** `[Json]` Creates a Readonly and Optional property */
|
|
1155
|
+
ReadonlyOptional(schema) {
|
|
1156
|
+
return this.Readonly(this.Optional(schema));
|
|
1157
|
+
}
|
|
1158
|
+
/** `[Json]` Creates a Readonly property */
|
|
1159
|
+
Readonly(schema) {
|
|
1160
|
+
return { ...TypeClone.Type(schema), [exports.Readonly]: "Readonly" };
|
|
1161
|
+
}
|
|
1162
|
+
/** `[Json]` Creates an Optional property */
|
|
1163
|
+
Optional(schema) {
|
|
1164
|
+
return { ...TypeClone.Type(schema), [exports.Optional]: "Optional" };
|
|
1165
|
+
}
|
|
1166
|
+
// ------------------------------------------------------------------------
|
|
1167
|
+
// Types
|
|
1168
|
+
// ------------------------------------------------------------------------
|
|
1169
|
+
/** `[Json]` Creates an Any type */
|
|
1170
|
+
Any(options = {}) {
|
|
1171
|
+
return this.Create({ ...options, [exports.Kind]: "Any" });
|
|
1172
|
+
}
|
|
1173
|
+
/** `[Json]` Creates an Array type */
|
|
1174
|
+
Array(schema, options = {}) {
|
|
1175
|
+
return this.Create({ ...options, [exports.Kind]: "Array", type: "array", items: TypeClone.Type(schema) });
|
|
1176
|
+
}
|
|
1177
|
+
/** `[Json]` Creates a Boolean type */
|
|
1178
|
+
Boolean(options = {}) {
|
|
1179
|
+
return this.Create({ ...options, [exports.Kind]: "Boolean", type: "boolean" });
|
|
1180
|
+
}
|
|
1181
|
+
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
1182
|
+
Capitalize(schema, options = {}) {
|
|
1183
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Capitalize"), ...options };
|
|
1184
|
+
}
|
|
1185
|
+
/** `[Json]` Creates a Composite object type */
|
|
1186
|
+
Composite(objects, options) {
|
|
1187
|
+
const intersect = exports.Type.Intersect(objects, {});
|
|
1188
|
+
const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
|
|
1189
|
+
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: exports.Type.Index(intersect, [key]) }), {});
|
|
1190
|
+
return exports.Type.Object(properties, options);
|
|
1191
|
+
}
|
|
1192
|
+
/** `[Json]` Creates a Enum type */
|
|
1193
|
+
Enum(item, options = {}) {
|
|
1194
|
+
if (ValueGuard.IsUndefined(item))
|
|
1195
|
+
return this.Throw("Enum undefined or empty");
|
|
1196
|
+
const values1 = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1197
|
+
const values2 = [...new Set(values1)];
|
|
1198
|
+
const anyOf = values2.map((value) => exports.Type.Literal(value));
|
|
1199
|
+
return this.Union(anyOf, { ...options, [exports.Hint]: "Enum" });
|
|
1200
|
+
}
|
|
1201
|
+
/** `[Json]` Creates a Conditional type */
|
|
1202
|
+
Extends(left, right, trueType, falseType, options = {}) {
|
|
1203
|
+
switch (TypeExtends.Extends(left, right)) {
|
|
1204
|
+
case TypeExtendsResult.Union:
|
|
1205
|
+
return this.Union([TypeClone.Type(trueType, options), TypeClone.Type(falseType, options)]);
|
|
1206
|
+
case TypeExtendsResult.True:
|
|
1207
|
+
return TypeClone.Type(trueType, options);
|
|
1208
|
+
case TypeExtendsResult.False:
|
|
1209
|
+
return TypeClone.Type(falseType, options);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
1213
|
+
Exclude(unionType, excludedMembers, options = {}) {
|
|
1214
|
+
return TypeGuard.TTemplateLiteral(unionType) ? this.Exclude(TemplateLiteralResolver.Resolve(unionType), excludedMembers, options) : TypeGuard.TTemplateLiteral(excludedMembers) ? this.Exclude(unionType, TemplateLiteralResolver.Resolve(excludedMembers), options) : TypeGuard.TUnion(unionType) ? (() => {
|
|
1215
|
+
const narrowed = unionType.anyOf.filter((inner) => TypeExtends.Extends(inner, excludedMembers) === TypeExtendsResult.False);
|
|
1216
|
+
return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
|
|
1217
|
+
})() : TypeExtends.Extends(unionType, excludedMembers) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Type(unionType, options);
|
|
1218
|
+
}
|
|
1219
|
+
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
1220
|
+
Extract(type, union, options = {}) {
|
|
1221
|
+
return TypeGuard.TTemplateLiteral(type) ? this.Extract(TemplateLiteralResolver.Resolve(type), union, options) : TypeGuard.TTemplateLiteral(union) ? this.Extract(type, TemplateLiteralResolver.Resolve(union), options) : TypeGuard.TUnion(type) ? (() => {
|
|
1222
|
+
const narrowed = type.anyOf.filter((inner) => TypeExtends.Extends(inner, union) !== TypeExtendsResult.False);
|
|
1223
|
+
return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
|
|
1224
|
+
})() : TypeExtends.Extends(type, union) !== TypeExtendsResult.False ? TypeClone.Type(type, options) : this.Never(options);
|
|
1225
|
+
}
|
|
1226
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
1227
|
+
Index(schema, unresolved, options = {}) {
|
|
1228
|
+
return TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1229
|
+
return TypeClone.Type(schema.items, options);
|
|
1230
|
+
})() : TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1231
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
1232
|
+
const cloned = items.map((schema2) => TypeClone.Type(schema2));
|
|
1233
|
+
return this.Union(cloned, options);
|
|
1234
|
+
})() : (() => {
|
|
1235
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1236
|
+
const clone = TypeClone.Type(schema);
|
|
1237
|
+
return IndexedAccessor.Resolve(clone, keys, options);
|
|
1238
|
+
})();
|
|
1239
|
+
}
|
|
1240
|
+
/** `[Json]` Creates an Integer type */
|
|
1241
|
+
Integer(options = {}) {
|
|
1242
|
+
return this.Create({ ...options, [exports.Kind]: "Integer", type: "integer" });
|
|
1243
|
+
}
|
|
1244
|
+
/** `[Json]` Creates an Intersect type */
|
|
1245
|
+
Intersect(allOf, options = {}) {
|
|
1246
|
+
if (allOf.length === 0)
|
|
1247
|
+
return exports.Type.Never();
|
|
1248
|
+
if (allOf.length === 1)
|
|
1249
|
+
return TypeClone.Type(allOf[0], options);
|
|
1250
|
+
if (allOf.some((schema) => TypeGuard.TTransform(schema)))
|
|
1251
|
+
this.Throw("Cannot intersect transform types");
|
|
1252
|
+
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
1253
|
+
const cloned = TypeClone.Rest(allOf);
|
|
1254
|
+
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Type(options.unevaluatedProperties) } : {};
|
|
1255
|
+
return options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects ? this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: "Intersect", type: "object", allOf: cloned }) : this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: "Intersect", allOf: cloned });
|
|
1256
|
+
}
|
|
1257
|
+
/** `[Json]` Creates a KeyOf type */
|
|
1258
|
+
KeyOf(schema, options = {}) {
|
|
1259
|
+
return TypeGuard.TRecord(schema) ? (() => {
|
|
1260
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
1261
|
+
return pattern === exports.PatternNumberExact ? this.Number(options) : pattern === exports.PatternStringExact ? this.String(options) : this.Throw("Unable to resolve key type from Record key pattern");
|
|
1262
|
+
})() : TypeGuard.TTuple(schema) ? (() => {
|
|
1263
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
1264
|
+
const literals = items.map((_, index) => exports.Type.Literal(index.toString()));
|
|
1265
|
+
return this.Union(literals, options);
|
|
1266
|
+
})() : TypeGuard.TArray(schema) ? (() => {
|
|
1267
|
+
return this.Number(options);
|
|
1268
|
+
})() : (() => {
|
|
1269
|
+
const keys = KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
1270
|
+
if (keys.length === 0)
|
|
1271
|
+
return this.Never(options);
|
|
1272
|
+
const literals = keys.map((key) => this.Literal(key));
|
|
1273
|
+
return this.Union(literals, options);
|
|
1274
|
+
})();
|
|
1275
|
+
}
|
|
1276
|
+
/** `[Json]` Creates a Literal type */
|
|
1277
|
+
Literal(value, options = {}) {
|
|
1278
|
+
return this.Create({ ...options, [exports.Kind]: "Literal", const: value, type: typeof value });
|
|
1279
|
+
}
|
|
1280
|
+
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
1281
|
+
Lowercase(schema, options = {}) {
|
|
1282
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Lowercase"), ...options };
|
|
1283
|
+
}
|
|
1284
|
+
/** `[Json]` Creates a Never type */
|
|
1285
|
+
Never(options = {}) {
|
|
1286
|
+
return this.Create({ ...options, [exports.Kind]: "Never", not: {} });
|
|
1287
|
+
}
|
|
1288
|
+
/** `[Json]` Creates a Not type */
|
|
1289
|
+
Not(schema, options) {
|
|
1290
|
+
return this.Create({ ...options, [exports.Kind]: "Not", not: TypeClone.Type(schema) });
|
|
1291
|
+
}
|
|
1292
|
+
/** `[Json]` Creates a Null type */
|
|
1293
|
+
Null(options = {}) {
|
|
1294
|
+
return this.Create({ ...options, [exports.Kind]: "Null", type: "null" });
|
|
1295
|
+
}
|
|
1296
|
+
/** `[Json]` Creates a Number type */
|
|
1297
|
+
Number(options = {}) {
|
|
1298
|
+
return this.Create({ ...options, [exports.Kind]: "Number", type: "number" });
|
|
1299
|
+
}
|
|
1300
|
+
/** `[Json]` Creates an Object type */
|
|
1301
|
+
Object(properties, options = {}) {
|
|
1302
|
+
const propertyKeys = Object.getOwnPropertyNames(properties);
|
|
1303
|
+
const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
|
|
1304
|
+
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
1305
|
+
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Type(options.additionalProperties) } : {};
|
|
1306
|
+
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Type(properties[key]) }), {});
|
|
1307
|
+
return requiredKeys.length > 0 ? this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: "Object", type: "object", properties: clonedProperties, required: requiredKeys }) : this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: "Object", type: "object", properties: clonedProperties });
|
|
1308
|
+
}
|
|
1309
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
1310
|
+
Omit(schema, unresolved, options = {}) {
|
|
1311
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1312
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1313
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
1314
|
+
object.required = object.required.filter((key) => !keys.includes(key));
|
|
1315
|
+
if (object.required.length === 0)
|
|
1316
|
+
delete object.required;
|
|
1317
|
+
}
|
|
1318
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
1319
|
+
if (keys.includes(key))
|
|
1320
|
+
delete object.properties[key];
|
|
1321
|
+
}
|
|
1322
|
+
return this.Create(object);
|
|
1323
|
+
}, options);
|
|
1324
|
+
}
|
|
1325
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
1326
|
+
Partial(schema, options = {}) {
|
|
1327
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1328
|
+
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
1329
|
+
return { ...acc, [key]: this.Optional(object.properties[key]) };
|
|
1330
|
+
}, {});
|
|
1331
|
+
return this.Object(
|
|
1332
|
+
properties,
|
|
1333
|
+
this.Discard(object, ["required"])
|
|
1334
|
+
/* object used as options to retain other constraints */
|
|
1335
|
+
);
|
|
1336
|
+
}, options);
|
|
1337
|
+
}
|
|
1338
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
1339
|
+
Pick(schema, unresolved, options = {}) {
|
|
1340
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1341
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1342
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
1343
|
+
object.required = object.required.filter((key) => keys.includes(key));
|
|
1344
|
+
if (object.required.length === 0)
|
|
1345
|
+
delete object.required;
|
|
1346
|
+
}
|
|
1347
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
1348
|
+
if (!keys.includes(key))
|
|
1349
|
+
delete object.properties[key];
|
|
1350
|
+
}
|
|
1351
|
+
return this.Create(object);
|
|
1352
|
+
}, options);
|
|
1353
|
+
}
|
|
1354
|
+
/** `[Json]` Creates a Record type */
|
|
1355
|
+
Record(key, schema, options = {}) {
|
|
1356
|
+
return TypeGuard.TTemplateLiteral(key) ? (() => {
|
|
1357
|
+
const expression = TemplateLiteralParser.ParseExact(key.pattern);
|
|
1358
|
+
return TemplateLiteralFinite.Check(expression) ? this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key2) => ({ ...acc, [key2]: TypeClone.Type(schema) }), {}), options) : this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [key.pattern]: TypeClone.Type(schema) } });
|
|
1359
|
+
})() : TypeGuard.TUnion(key) ? (() => {
|
|
1360
|
+
const union = UnionResolver.Resolve(key);
|
|
1361
|
+
if (TypeGuard.TUnionLiteral(union)) {
|
|
1362
|
+
const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Type(schema) }), {});
|
|
1363
|
+
return this.Object(properties, { ...options, [exports.Hint]: "Record" });
|
|
1364
|
+
} else
|
|
1365
|
+
this.Throw("Record key of type union contains non-literal types");
|
|
1366
|
+
})() : TypeGuard.TLiteral(key) ? (() => {
|
|
1367
|
+
return ValueGuard.IsString(key.const) || ValueGuard.IsNumber(key.const) ? this.Object({ [key.const]: TypeClone.Type(schema) }, options) : this.Throw("Record key of type literal is not of type string or number");
|
|
1368
|
+
})() : TypeGuard.TInteger(key) || TypeGuard.TNumber(key) ? (() => {
|
|
1369
|
+
return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [exports.PatternNumberExact]: TypeClone.Type(schema) } });
|
|
1370
|
+
})() : TypeGuard.TString(key) ? (() => {
|
|
1371
|
+
const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
|
|
1372
|
+
return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [pattern]: TypeClone.Type(schema) } });
|
|
1373
|
+
})() : this.Never();
|
|
1374
|
+
}
|
|
1375
|
+
/** `[Json]` Creates a Recursive type */
|
|
1376
|
+
Recursive(callback, options = {}) {
|
|
1377
|
+
if (ValueGuard.IsUndefined(options.$id))
|
|
1378
|
+
options.$id = `T${TypeOrdinal++}`;
|
|
1379
|
+
const thisType = callback({ [exports.Kind]: "This", $ref: `${options.$id}` });
|
|
1380
|
+
thisType.$id = options.$id;
|
|
1381
|
+
return this.Create({ ...options, [exports.Hint]: "Recursive", ...thisType });
|
|
1382
|
+
}
|
|
1383
|
+
/** `[Json]` Creates a Ref type. */
|
|
1384
|
+
Ref(unresolved, options = {}) {
|
|
1385
|
+
if (ValueGuard.IsString(unresolved))
|
|
1386
|
+
return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved });
|
|
1387
|
+
if (ValueGuard.IsUndefined(unresolved.$id))
|
|
1388
|
+
this.Throw("Reference target type must specify an $id");
|
|
1389
|
+
return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved.$id });
|
|
1390
|
+
}
|
|
1391
|
+
/** `[Json]` Constructs a type where all properties are required */
|
|
1392
|
+
Required(schema, options = {}) {
|
|
1393
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1394
|
+
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
1395
|
+
return { ...acc, [key]: this.Discard(object.properties[key], [exports.Optional]) };
|
|
1396
|
+
}, {});
|
|
1397
|
+
return this.Object(
|
|
1398
|
+
properties,
|
|
1399
|
+
object
|
|
1400
|
+
/* object used as options to retain other constraints */
|
|
1401
|
+
);
|
|
1402
|
+
}, options);
|
|
1403
|
+
}
|
|
1404
|
+
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
1405
|
+
Rest(schema) {
|
|
1406
|
+
return TypeGuard.TTuple(schema) && !ValueGuard.IsUndefined(schema.items) ? TypeClone.Rest(schema.items) : TypeGuard.TIntersect(schema) ? TypeClone.Rest(schema.allOf) : TypeGuard.TUnion(schema) ? TypeClone.Rest(schema.anyOf) : [];
|
|
1407
|
+
}
|
|
1408
|
+
/** `[Json]` Creates a String type */
|
|
1409
|
+
String(options = {}) {
|
|
1410
|
+
return this.Create({ ...options, [exports.Kind]: "String", type: "string" });
|
|
1411
|
+
}
|
|
1412
|
+
/** `[Json]` Creates a TemplateLiteral type */
|
|
1413
|
+
TemplateLiteral(unresolved, options = {}) {
|
|
1414
|
+
const pattern = ValueGuard.IsString(unresolved) ? TemplateLiteralPattern.Create(TemplateLiteralDslParser.Parse(unresolved)) : TemplateLiteralPattern.Create(unresolved);
|
|
1415
|
+
return this.Create({ ...options, [exports.Kind]: "TemplateLiteral", type: "string", pattern });
|
|
1416
|
+
}
|
|
1417
|
+
/** `[Json]` Creates a Transform type */
|
|
1418
|
+
Transform(schema) {
|
|
1419
|
+
return new TransformDecodeBuilder(schema);
|
|
1420
|
+
}
|
|
1421
|
+
/** `[Json]` Creates a Tuple type */
|
|
1422
|
+
Tuple(items, options = {}) {
|
|
1423
|
+
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
1424
|
+
const clonedItems = TypeClone.Rest(items);
|
|
1425
|
+
const schema = items.length > 0 ? { ...options, [exports.Kind]: "Tuple", type: "array", items: clonedItems, additionalItems, minItems, maxItems } : { ...options, [exports.Kind]: "Tuple", type: "array", minItems, maxItems };
|
|
1426
|
+
return this.Create(schema);
|
|
1427
|
+
}
|
|
1428
|
+
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
1429
|
+
Uncapitalize(schema, options = {}) {
|
|
1430
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Uncapitalize"), ...options };
|
|
1431
|
+
}
|
|
1432
|
+
/** `[Json]` Creates a Union type */
|
|
1433
|
+
Union(union, options = {}) {
|
|
1434
|
+
return TypeGuard.TTemplateLiteral(union) ? TemplateLiteralResolver.Resolve(union) : (() => {
|
|
1435
|
+
const anyOf = union;
|
|
1436
|
+
if (anyOf.length === 0)
|
|
1437
|
+
return this.Never(options);
|
|
1438
|
+
if (anyOf.length === 1)
|
|
1439
|
+
return this.Create(TypeClone.Type(anyOf[0], options));
|
|
1440
|
+
const clonedAnyOf = TypeClone.Rest(anyOf);
|
|
1441
|
+
return this.Create({ ...options, [exports.Kind]: "Union", anyOf: clonedAnyOf });
|
|
1442
|
+
})();
|
|
1443
|
+
}
|
|
1444
|
+
/** `[Json]` Creates an Unknown type */
|
|
1445
|
+
Unknown(options = {}) {
|
|
1446
|
+
return this.Create({ ...options, [exports.Kind]: "Unknown" });
|
|
1447
|
+
}
|
|
1448
|
+
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
1449
|
+
Unsafe(options = {}) {
|
|
1450
|
+
return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || "Unsafe" });
|
|
1451
|
+
}
|
|
1452
|
+
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
1453
|
+
Uppercase(schema, options = {}) {
|
|
1454
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Uppercase"), ...options };
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
exports.JsonTypeBuilder = JsonTypeBuilder;
|
|
1458
|
+
var JavaScriptTypeBuilder = class extends JsonTypeBuilder {
|
|
1459
|
+
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
1460
|
+
AsyncIterator(items, options = {}) {
|
|
1461
|
+
return this.Create({ ...options, [exports.Kind]: "AsyncIterator", type: "AsyncIterator", items: TypeClone.Type(items) });
|
|
1462
|
+
}
|
|
1463
|
+
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
1464
|
+
Awaited(schema, options = {}) {
|
|
1465
|
+
const Unwrap = (rest) => rest.length > 0 ? (() => {
|
|
1466
|
+
const [L, ...R] = rest;
|
|
1467
|
+
return [this.Awaited(L), ...Unwrap(R)];
|
|
1468
|
+
})() : rest;
|
|
1469
|
+
return TypeGuard.TIntersect(schema) ? exports.Type.Intersect(Unwrap(schema.allOf)) : TypeGuard.TUnion(schema) ? exports.Type.Union(Unwrap(schema.anyOf)) : TypeGuard.TPromise(schema) ? this.Awaited(schema.item) : TypeClone.Type(schema, options);
|
|
1470
|
+
}
|
|
1471
|
+
/** `[JavaScript]` Creates a BigInt type */
|
|
1472
|
+
BigInt(options = {}) {
|
|
1473
|
+
return this.Create({ ...options, [exports.Kind]: "BigInt", type: "bigint" });
|
|
1474
|
+
}
|
|
1475
|
+
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
1476
|
+
ConstructorParameters(schema, options = {}) {
|
|
1477
|
+
return this.Tuple([...schema.parameters], { ...options });
|
|
1478
|
+
}
|
|
1479
|
+
/** `[JavaScript]` Creates a Constructor type */
|
|
1480
|
+
Constructor(parameters, returns, options) {
|
|
1481
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
1482
|
+
return this.Create({ ...options, [exports.Kind]: "Constructor", type: "Constructor", parameters: clonedParameters, returns: clonedReturns });
|
|
1483
|
+
}
|
|
1484
|
+
/** `[JavaScript]` Creates a Date type */
|
|
1485
|
+
Date(options = {}) {
|
|
1486
|
+
return this.Create({ ...options, [exports.Kind]: "Date", type: "Date" });
|
|
1487
|
+
}
|
|
1488
|
+
/** `[JavaScript]` Creates a Function type */
|
|
1489
|
+
Function(parameters, returns, options) {
|
|
1490
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
1491
|
+
return this.Create({ ...options, [exports.Kind]: "Function", type: "Function", parameters: clonedParameters, returns: clonedReturns });
|
|
1492
|
+
}
|
|
1493
|
+
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
1494
|
+
InstanceType(schema, options = {}) {
|
|
1495
|
+
return TypeClone.Type(schema.returns, options);
|
|
1496
|
+
}
|
|
1497
|
+
/** `[JavaScript]` Creates an Iterator type */
|
|
1498
|
+
Iterator(items, options = {}) {
|
|
1499
|
+
return this.Create({ ...options, [exports.Kind]: "Iterator", type: "Iterator", items: TypeClone.Type(items) });
|
|
1500
|
+
}
|
|
1501
|
+
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
1502
|
+
Parameters(schema, options = {}) {
|
|
1503
|
+
return this.Tuple(schema.parameters, { ...options });
|
|
1504
|
+
}
|
|
1505
|
+
/** `[JavaScript]` Creates a Promise type */
|
|
1506
|
+
Promise(item, options = {}) {
|
|
1507
|
+
return this.Create({ ...options, [exports.Kind]: "Promise", type: "Promise", item: TypeClone.Type(item) });
|
|
1508
|
+
}
|
|
1509
|
+
/** `[Extended]` Creates a String type */
|
|
1510
|
+
RegExp(unresolved, options = {}) {
|
|
1511
|
+
const pattern = ValueGuard.IsString(unresolved) ? unresolved : unresolved.source;
|
|
1512
|
+
return this.Create({ ...options, [exports.Kind]: "String", type: "string", pattern });
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* @deprecated Use `Type.RegExp`
|
|
1516
|
+
*/
|
|
1517
|
+
RegEx(regex, options = {}) {
|
|
1518
|
+
return this.RegExp(regex, options);
|
|
1519
|
+
}
|
|
1520
|
+
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
1521
|
+
ReturnType(schema, options = {}) {
|
|
1522
|
+
return TypeClone.Type(schema.returns, options);
|
|
1523
|
+
}
|
|
1524
|
+
/** `[JavaScript]` Creates a Symbol type */
|
|
1525
|
+
Symbol(options) {
|
|
1526
|
+
return this.Create({ ...options, [exports.Kind]: "Symbol", type: "symbol" });
|
|
1527
|
+
}
|
|
1528
|
+
/** `[JavaScript]` Creates a Undefined type */
|
|
1529
|
+
Undefined(options = {}) {
|
|
1530
|
+
return this.Create({ ...options, [exports.Kind]: "Undefined", type: "undefined" });
|
|
1531
|
+
}
|
|
1532
|
+
/** `[JavaScript]` Creates a Uint8Array type */
|
|
1533
|
+
Uint8Array(options = {}) {
|
|
1534
|
+
return this.Create({ ...options, [exports.Kind]: "Uint8Array", type: "Uint8Array" });
|
|
1535
|
+
}
|
|
1536
|
+
/** `[JavaScript]` Creates a Void type */
|
|
1537
|
+
Void(options = {}) {
|
|
1538
|
+
return this.Create({ ...options, [exports.Kind]: "Void", type: "void" });
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
exports.JavaScriptTypeBuilder = JavaScriptTypeBuilder;
|
|
1542
|
+
exports.JsonType = new JsonTypeBuilder();
|
|
1543
|
+
exports.Type = new JavaScriptTypeBuilder();
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1547
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/guard.js
|
|
1548
|
+
var require_guard = __commonJS({
|
|
1549
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/guard.js"(exports) {
|
|
1550
|
+
"use strict";
|
|
1551
|
+
init_dirname();
|
|
1552
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1553
|
+
exports.IsValueType = exports.IsSymbol = exports.IsFunction = exports.IsString = exports.IsBigInt = exports.IsInteger = exports.IsNumber = exports.IsBoolean = exports.IsNull = exports.IsUndefined = exports.IsArray = exports.IsObject = exports.IsPlainObject = exports.HasPropertyKey = exports.IsDate = exports.IsUint8Array = exports.IsPromise = exports.IsTypedArray = exports.IsIterator = exports.IsAsyncIterator = void 0;
|
|
1554
|
+
function IsAsyncIterator(value) {
|
|
1555
|
+
return IsObject(value) && Symbol.asyncIterator in value;
|
|
1556
|
+
}
|
|
1557
|
+
exports.IsAsyncIterator = IsAsyncIterator;
|
|
1558
|
+
function IsIterator(value) {
|
|
1559
|
+
return IsObject(value) && Symbol.iterator in value;
|
|
1560
|
+
}
|
|
1561
|
+
exports.IsIterator = IsIterator;
|
|
1562
|
+
function IsTypedArray(value) {
|
|
1563
|
+
return ArrayBuffer.isView(value);
|
|
1564
|
+
}
|
|
1565
|
+
exports.IsTypedArray = IsTypedArray;
|
|
1566
|
+
function IsPromise(value) {
|
|
1567
|
+
return value instanceof Promise;
|
|
1568
|
+
}
|
|
1569
|
+
exports.IsPromise = IsPromise;
|
|
1570
|
+
function IsUint8Array(value) {
|
|
1571
|
+
return value instanceof Uint8Array;
|
|
1572
|
+
}
|
|
1573
|
+
exports.IsUint8Array = IsUint8Array;
|
|
1574
|
+
function IsDate(value) {
|
|
1575
|
+
return value instanceof Date && Number.isFinite(value.getTime());
|
|
1576
|
+
}
|
|
1577
|
+
exports.IsDate = IsDate;
|
|
1578
|
+
function HasPropertyKey(value, key) {
|
|
1579
|
+
return key in value;
|
|
1580
|
+
}
|
|
1581
|
+
exports.HasPropertyKey = HasPropertyKey;
|
|
1582
|
+
function IsPlainObject(value) {
|
|
1583
|
+
return IsObject(value) && IsFunction(value.constructor) && value.constructor.name === "Object";
|
|
1584
|
+
}
|
|
1585
|
+
exports.IsPlainObject = IsPlainObject;
|
|
1586
|
+
function IsObject(value) {
|
|
1587
|
+
return value !== null && typeof value === "object";
|
|
1588
|
+
}
|
|
1589
|
+
exports.IsObject = IsObject;
|
|
1590
|
+
function IsArray(value) {
|
|
1591
|
+
return Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
1592
|
+
}
|
|
1593
|
+
exports.IsArray = IsArray;
|
|
1594
|
+
function IsUndefined(value) {
|
|
1595
|
+
return value === void 0;
|
|
1596
|
+
}
|
|
1597
|
+
exports.IsUndefined = IsUndefined;
|
|
1598
|
+
function IsNull(value) {
|
|
1599
|
+
return value === null;
|
|
1600
|
+
}
|
|
1601
|
+
exports.IsNull = IsNull;
|
|
1602
|
+
function IsBoolean(value) {
|
|
1603
|
+
return typeof value === "boolean";
|
|
1604
|
+
}
|
|
1605
|
+
exports.IsBoolean = IsBoolean;
|
|
1606
|
+
function IsNumber(value) {
|
|
1607
|
+
return typeof value === "number";
|
|
1608
|
+
}
|
|
1609
|
+
exports.IsNumber = IsNumber;
|
|
1610
|
+
function IsInteger(value) {
|
|
1611
|
+
return IsNumber(value) && Number.isInteger(value);
|
|
1612
|
+
}
|
|
1613
|
+
exports.IsInteger = IsInteger;
|
|
1614
|
+
function IsBigInt(value) {
|
|
1615
|
+
return typeof value === "bigint";
|
|
1616
|
+
}
|
|
1617
|
+
exports.IsBigInt = IsBigInt;
|
|
1618
|
+
function IsString(value) {
|
|
1619
|
+
return typeof value === "string";
|
|
1620
|
+
}
|
|
1621
|
+
exports.IsString = IsString;
|
|
1622
|
+
function IsFunction(value) {
|
|
1623
|
+
return typeof value === "function";
|
|
1624
|
+
}
|
|
1625
|
+
exports.IsFunction = IsFunction;
|
|
1626
|
+
function IsSymbol(value) {
|
|
1627
|
+
return typeof value === "symbol";
|
|
1628
|
+
}
|
|
1629
|
+
exports.IsSymbol = IsSymbol;
|
|
1630
|
+
function IsValueType(value) {
|
|
1631
|
+
return IsBigInt(value) || IsBoolean(value) || IsNull(value) || IsNumber(value) || IsString(value) || IsSymbol(value) || IsUndefined(value);
|
|
1632
|
+
}
|
|
1633
|
+
exports.IsValueType = IsValueType;
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/system/system.js
|
|
1638
|
+
var require_system = __commonJS({
|
|
1639
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/system/system.js"(exports) {
|
|
1640
|
+
"use strict";
|
|
1641
|
+
init_dirname();
|
|
1642
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1643
|
+
exports.DefaultErrorFunction = exports.TypeSystemPolicy = exports.TypeSystemErrorFunction = exports.TypeSystem = exports.TypeSystemDuplicateFormat = exports.TypeSystemDuplicateTypeKind = void 0;
|
|
1644
|
+
var guard_1 = require_guard();
|
|
1645
|
+
var errors_1 = require_errors();
|
|
1646
|
+
var Types = require_typebox();
|
|
1647
|
+
var TypeSystemDuplicateTypeKind = class extends Types.TypeBoxError {
|
|
1648
|
+
constructor(kind) {
|
|
1649
|
+
super(`Duplicate type kind '${kind}' detected`);
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
exports.TypeSystemDuplicateTypeKind = TypeSystemDuplicateTypeKind;
|
|
1653
|
+
var TypeSystemDuplicateFormat = class extends Types.TypeBoxError {
|
|
1654
|
+
constructor(kind) {
|
|
1655
|
+
super(`Duplicate string format '${kind}' detected`);
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
exports.TypeSystemDuplicateFormat = TypeSystemDuplicateFormat;
|
|
1659
|
+
var TypeSystem;
|
|
1660
|
+
(function(TypeSystem2) {
|
|
1661
|
+
function Type2(kind, check) {
|
|
1662
|
+
if (Types.TypeRegistry.Has(kind))
|
|
1663
|
+
throw new TypeSystemDuplicateTypeKind(kind);
|
|
1664
|
+
Types.TypeRegistry.Set(kind, check);
|
|
1665
|
+
return (options = {}) => Types.Type.Unsafe({ ...options, [Types.Kind]: kind });
|
|
1666
|
+
}
|
|
1667
|
+
TypeSystem2.Type = Type2;
|
|
1668
|
+
function Format(format, check) {
|
|
1669
|
+
if (Types.FormatRegistry.Has(format))
|
|
1670
|
+
throw new TypeSystemDuplicateFormat(format);
|
|
1671
|
+
Types.FormatRegistry.Set(format, check);
|
|
1672
|
+
return format;
|
|
1673
|
+
}
|
|
1674
|
+
TypeSystem2.Format = Format;
|
|
1675
|
+
})(TypeSystem || (exports.TypeSystem = TypeSystem = {}));
|
|
1676
|
+
var TypeSystemErrorFunction;
|
|
1677
|
+
(function(TypeSystemErrorFunction2) {
|
|
1678
|
+
let errorMessageFunction = DefaultErrorFunction;
|
|
1679
|
+
function Reset() {
|
|
1680
|
+
errorMessageFunction = DefaultErrorFunction;
|
|
1681
|
+
}
|
|
1682
|
+
TypeSystemErrorFunction2.Reset = Reset;
|
|
1683
|
+
function Set2(callback) {
|
|
1684
|
+
errorMessageFunction = callback;
|
|
1685
|
+
}
|
|
1686
|
+
TypeSystemErrorFunction2.Set = Set2;
|
|
1687
|
+
function Get() {
|
|
1688
|
+
return errorMessageFunction;
|
|
1689
|
+
}
|
|
1690
|
+
TypeSystemErrorFunction2.Get = Get;
|
|
1691
|
+
})(TypeSystemErrorFunction || (exports.TypeSystemErrorFunction = TypeSystemErrorFunction = {}));
|
|
1692
|
+
var TypeSystemPolicy;
|
|
1693
|
+
(function(TypeSystemPolicy2) {
|
|
1694
|
+
TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
|
|
1695
|
+
TypeSystemPolicy2.AllowArrayObject = false;
|
|
1696
|
+
TypeSystemPolicy2.AllowNaN = false;
|
|
1697
|
+
TypeSystemPolicy2.AllowNullVoid = false;
|
|
1698
|
+
function IsExactOptionalProperty(value, key) {
|
|
1699
|
+
return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
|
|
1700
|
+
}
|
|
1701
|
+
TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
|
|
1702
|
+
function IsObjectLike(value) {
|
|
1703
|
+
const isObject = (0, guard_1.IsObject)(value);
|
|
1704
|
+
return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !(0, guard_1.IsArray)(value);
|
|
1705
|
+
}
|
|
1706
|
+
TypeSystemPolicy2.IsObjectLike = IsObjectLike;
|
|
1707
|
+
function IsRecordLike(value) {
|
|
1708
|
+
return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
|
|
1709
|
+
}
|
|
1710
|
+
TypeSystemPolicy2.IsRecordLike = IsRecordLike;
|
|
1711
|
+
function IsNumberLike(value) {
|
|
1712
|
+
const isNumber = (0, guard_1.IsNumber)(value);
|
|
1713
|
+
return TypeSystemPolicy2.AllowNaN ? isNumber : isNumber && Number.isFinite(value);
|
|
1714
|
+
}
|
|
1715
|
+
TypeSystemPolicy2.IsNumberLike = IsNumberLike;
|
|
1716
|
+
function IsVoidLike(value) {
|
|
1717
|
+
const isUndefined = (0, guard_1.IsUndefined)(value);
|
|
1718
|
+
return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined;
|
|
1719
|
+
}
|
|
1720
|
+
TypeSystemPolicy2.IsVoidLike = IsVoidLike;
|
|
1721
|
+
})(TypeSystemPolicy || (exports.TypeSystemPolicy = TypeSystemPolicy = {}));
|
|
1722
|
+
function DefaultErrorFunction(schema, errorType) {
|
|
1723
|
+
switch (errorType) {
|
|
1724
|
+
case errors_1.ValueErrorType.ArrayContains:
|
|
1725
|
+
return "Expected array to contain at least one matching value";
|
|
1726
|
+
case errors_1.ValueErrorType.ArrayMaxContains:
|
|
1727
|
+
return `Expected array to contain no more than ${schema.maxContains} matching values`;
|
|
1728
|
+
case errors_1.ValueErrorType.ArrayMinContains:
|
|
1729
|
+
return `Expected array to contain at least ${schema.minContains} matching values`;
|
|
1730
|
+
case errors_1.ValueErrorType.ArrayMaxItems:
|
|
1731
|
+
return `Expected array length to be less or equal to ${schema.maxItems}`;
|
|
1732
|
+
case errors_1.ValueErrorType.ArrayMinItems:
|
|
1733
|
+
return `Expected array length to be greater or equal to ${schema.minItems}`;
|
|
1734
|
+
case errors_1.ValueErrorType.ArrayUniqueItems:
|
|
1735
|
+
return "Expected array elements to be unique";
|
|
1736
|
+
case errors_1.ValueErrorType.Array:
|
|
1737
|
+
return "Expected array";
|
|
1738
|
+
case errors_1.ValueErrorType.AsyncIterator:
|
|
1739
|
+
return "Expected AsyncIterator";
|
|
1740
|
+
case errors_1.ValueErrorType.BigIntExclusiveMaximum:
|
|
1741
|
+
return `Expected bigint to be less than ${schema.exclusiveMaximum}`;
|
|
1742
|
+
case errors_1.ValueErrorType.BigIntExclusiveMinimum:
|
|
1743
|
+
return `Expected bigint to be greater than ${schema.exclusiveMinimum}`;
|
|
1744
|
+
case errors_1.ValueErrorType.BigIntMaximum:
|
|
1745
|
+
return `Expected bigint to be less or equal to ${schema.maximum}`;
|
|
1746
|
+
case errors_1.ValueErrorType.BigIntMinimum:
|
|
1747
|
+
return `Expected bigint to be greater or equal to ${schema.minimum}`;
|
|
1748
|
+
case errors_1.ValueErrorType.BigIntMultipleOf:
|
|
1749
|
+
return `Expected bigint to be a multiple of ${schema.multipleOf}`;
|
|
1750
|
+
case errors_1.ValueErrorType.BigInt:
|
|
1751
|
+
return "Expected bigint";
|
|
1752
|
+
case errors_1.ValueErrorType.Boolean:
|
|
1753
|
+
return "Expected boolean";
|
|
1754
|
+
case errors_1.ValueErrorType.DateExclusiveMinimumTimestamp:
|
|
1755
|
+
return `Expected Date timestamp to be greater than ${schema.exclusiveMinimumTimestamp}`;
|
|
1756
|
+
case errors_1.ValueErrorType.DateExclusiveMaximumTimestamp:
|
|
1757
|
+
return `Expected Date timestamp to be less than ${schema.exclusiveMaximumTimestamp}`;
|
|
1758
|
+
case errors_1.ValueErrorType.DateMinimumTimestamp:
|
|
1759
|
+
return `Expected Date timestamp to be greater or equal to ${schema.minimumTimestamp}`;
|
|
1760
|
+
case errors_1.ValueErrorType.DateMaximumTimestamp:
|
|
1761
|
+
return `Expected Date timestamp to be less or equal to ${schema.maximumTimestamp}`;
|
|
1762
|
+
case errors_1.ValueErrorType.DateMultipleOfTimestamp:
|
|
1763
|
+
return `Expected Date timestamp to be a multiple of ${schema.multipleOfTimestamp}`;
|
|
1764
|
+
case errors_1.ValueErrorType.Date:
|
|
1765
|
+
return "Expected Date";
|
|
1766
|
+
case errors_1.ValueErrorType.Function:
|
|
1767
|
+
return "Expected function";
|
|
1768
|
+
case errors_1.ValueErrorType.IntegerExclusiveMaximum:
|
|
1769
|
+
return `Expected integer to be less than ${schema.exclusiveMaximum}`;
|
|
1770
|
+
case errors_1.ValueErrorType.IntegerExclusiveMinimum:
|
|
1771
|
+
return `Expected integer to be greater than ${schema.exclusiveMinimum}`;
|
|
1772
|
+
case errors_1.ValueErrorType.IntegerMaximum:
|
|
1773
|
+
return `Expected integer to be less or equal to ${schema.maximum}`;
|
|
1774
|
+
case errors_1.ValueErrorType.IntegerMinimum:
|
|
1775
|
+
return `Expected integer to be greater or equal to ${schema.minimum}`;
|
|
1776
|
+
case errors_1.ValueErrorType.IntegerMultipleOf:
|
|
1777
|
+
return `Expected integer to be a multiple of ${schema.multipleOf}`;
|
|
1778
|
+
case errors_1.ValueErrorType.Integer:
|
|
1779
|
+
return "Expected integer";
|
|
1780
|
+
case errors_1.ValueErrorType.IntersectUnevaluatedProperties:
|
|
1781
|
+
return "Unexpected property";
|
|
1782
|
+
case errors_1.ValueErrorType.Intersect:
|
|
1783
|
+
return "Expected all values to match";
|
|
1784
|
+
case errors_1.ValueErrorType.Iterator:
|
|
1785
|
+
return "Expected Iterator";
|
|
1786
|
+
case errors_1.ValueErrorType.Literal:
|
|
1787
|
+
return `Expected ${typeof schema.const === "string" ? `'${schema.const}'` : schema.const}`;
|
|
1788
|
+
case errors_1.ValueErrorType.Never:
|
|
1789
|
+
return "Never";
|
|
1790
|
+
case errors_1.ValueErrorType.Not:
|
|
1791
|
+
return "Value should not match";
|
|
1792
|
+
case errors_1.ValueErrorType.Null:
|
|
1793
|
+
return "Expected null";
|
|
1794
|
+
case errors_1.ValueErrorType.NumberExclusiveMaximum:
|
|
1795
|
+
return `Expected number to be less than ${schema.exclusiveMaximum}`;
|
|
1796
|
+
case errors_1.ValueErrorType.NumberExclusiveMinimum:
|
|
1797
|
+
return `Expected number to be greater than ${schema.exclusiveMinimum}`;
|
|
1798
|
+
case errors_1.ValueErrorType.NumberMaximum:
|
|
1799
|
+
return `Expected number to be less or equal to ${schema.maximum}`;
|
|
1800
|
+
case errors_1.ValueErrorType.NumberMinimum:
|
|
1801
|
+
return `Expected number to be greater or equal to ${schema.minimum}`;
|
|
1802
|
+
case errors_1.ValueErrorType.NumberMultipleOf:
|
|
1803
|
+
return `Expected number to be a multiple of ${schema.multipleOf}`;
|
|
1804
|
+
case errors_1.ValueErrorType.Number:
|
|
1805
|
+
return "Expected number";
|
|
1806
|
+
case errors_1.ValueErrorType.Object:
|
|
1807
|
+
return "Expected object";
|
|
1808
|
+
case errors_1.ValueErrorType.ObjectAdditionalProperties:
|
|
1809
|
+
return "Unexpected property";
|
|
1810
|
+
case errors_1.ValueErrorType.ObjectMaxProperties:
|
|
1811
|
+
return `Expected object to have no more than ${schema.maxProperties} properties`;
|
|
1812
|
+
case errors_1.ValueErrorType.ObjectMinProperties:
|
|
1813
|
+
return `Expected object to have at least ${schema.minProperties} properties`;
|
|
1814
|
+
case errors_1.ValueErrorType.ObjectRequiredProperty:
|
|
1815
|
+
return "Required property";
|
|
1816
|
+
case errors_1.ValueErrorType.Promise:
|
|
1817
|
+
return "Expected Promise";
|
|
1818
|
+
case errors_1.ValueErrorType.StringFormatUnknown:
|
|
1819
|
+
return `Unknown format '${schema.format}'`;
|
|
1820
|
+
case errors_1.ValueErrorType.StringFormat:
|
|
1821
|
+
return `Expected string to match '${schema.format}' format`;
|
|
1822
|
+
case errors_1.ValueErrorType.StringMaxLength:
|
|
1823
|
+
return `Expected string length less or equal to ${schema.maxLength}`;
|
|
1824
|
+
case errors_1.ValueErrorType.StringMinLength:
|
|
1825
|
+
return `Expected string length greater or equal to ${schema.minLength}`;
|
|
1826
|
+
case errors_1.ValueErrorType.StringPattern:
|
|
1827
|
+
return `Expected string to match '${schema.pattern}'`;
|
|
1828
|
+
case errors_1.ValueErrorType.String:
|
|
1829
|
+
return "Expected string";
|
|
1830
|
+
case errors_1.ValueErrorType.Symbol:
|
|
1831
|
+
return "Expected symbol";
|
|
1832
|
+
case errors_1.ValueErrorType.TupleLength:
|
|
1833
|
+
return `Expected tuple to have ${schema.maxItems || 0} elements`;
|
|
1834
|
+
case errors_1.ValueErrorType.Tuple:
|
|
1835
|
+
return "Expected tuple";
|
|
1836
|
+
case errors_1.ValueErrorType.Uint8ArrayMaxByteLength:
|
|
1837
|
+
return `Expected byte length less or equal to ${schema.maxByteLength}`;
|
|
1838
|
+
case errors_1.ValueErrorType.Uint8ArrayMinByteLength:
|
|
1839
|
+
return `Expected byte length greater or equal to ${schema.minByteLength}`;
|
|
1840
|
+
case errors_1.ValueErrorType.Uint8Array:
|
|
1841
|
+
return "Expected Uint8Array";
|
|
1842
|
+
case errors_1.ValueErrorType.Undefined:
|
|
1843
|
+
return "Expected undefined";
|
|
1844
|
+
case errors_1.ValueErrorType.Union:
|
|
1845
|
+
return "Expected union value";
|
|
1846
|
+
case errors_1.ValueErrorType.Void:
|
|
1847
|
+
return "Expected void";
|
|
1848
|
+
case errors_1.ValueErrorType.Kind:
|
|
1849
|
+
return `Expected kind '${schema[Types.Kind]}'`;
|
|
1850
|
+
default:
|
|
1851
|
+
return "Unknown error type";
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
exports.DefaultErrorFunction = DefaultErrorFunction;
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1857
|
+
|
|
1858
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/deref.js
|
|
1859
|
+
var require_deref = __commonJS({
|
|
1860
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/deref.js"(exports) {
|
|
1861
|
+
"use strict";
|
|
1862
|
+
init_dirname();
|
|
1863
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1864
|
+
exports.Deref = exports.TypeDereferenceError = void 0;
|
|
1865
|
+
var typebox_1 = require_typebox();
|
|
1866
|
+
var TypeDereferenceError = class extends typebox_1.TypeBoxError {
|
|
1867
|
+
constructor(schema) {
|
|
1868
|
+
super(`Unable to dereference schema with $id '${schema.$id}'`);
|
|
1869
|
+
this.schema = schema;
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
exports.TypeDereferenceError = TypeDereferenceError;
|
|
1873
|
+
function Deref(schema, references) {
|
|
1874
|
+
const index = references.findIndex((target) => target.$id === schema.$ref);
|
|
1875
|
+
if (index === -1)
|
|
1876
|
+
throw new TypeDereferenceError(schema);
|
|
1877
|
+
return references[index];
|
|
1878
|
+
}
|
|
1879
|
+
exports.Deref = Deref;
|
|
1880
|
+
}
|
|
1881
|
+
});
|
|
1882
|
+
|
|
1883
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/hash.js
|
|
1884
|
+
var require_hash = __commonJS({
|
|
1885
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/hash.js"(exports) {
|
|
1886
|
+
"use strict";
|
|
1887
|
+
init_dirname();
|
|
1888
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1889
|
+
exports.Hash = exports.ByteMarker = exports.ValueHashError = void 0;
|
|
1890
|
+
var guard_1 = require_guard();
|
|
1891
|
+
var ValueHashError = class extends Error {
|
|
1892
|
+
constructor(value) {
|
|
1893
|
+
super(`Unable to hash value`);
|
|
1894
|
+
this.value = value;
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
exports.ValueHashError = ValueHashError;
|
|
1898
|
+
var ByteMarker;
|
|
1899
|
+
(function(ByteMarker2) {
|
|
1900
|
+
ByteMarker2[ByteMarker2["Undefined"] = 0] = "Undefined";
|
|
1901
|
+
ByteMarker2[ByteMarker2["Null"] = 1] = "Null";
|
|
1902
|
+
ByteMarker2[ByteMarker2["Boolean"] = 2] = "Boolean";
|
|
1903
|
+
ByteMarker2[ByteMarker2["Number"] = 3] = "Number";
|
|
1904
|
+
ByteMarker2[ByteMarker2["String"] = 4] = "String";
|
|
1905
|
+
ByteMarker2[ByteMarker2["Object"] = 5] = "Object";
|
|
1906
|
+
ByteMarker2[ByteMarker2["Array"] = 6] = "Array";
|
|
1907
|
+
ByteMarker2[ByteMarker2["Date"] = 7] = "Date";
|
|
1908
|
+
ByteMarker2[ByteMarker2["Uint8Array"] = 8] = "Uint8Array";
|
|
1909
|
+
ByteMarker2[ByteMarker2["Symbol"] = 9] = "Symbol";
|
|
1910
|
+
ByteMarker2[ByteMarker2["BigInt"] = 10] = "BigInt";
|
|
1911
|
+
})(ByteMarker || (exports.ByteMarker = ByteMarker = {}));
|
|
1912
|
+
var Accumulator = BigInt("14695981039346656037");
|
|
1913
|
+
var [Prime, Size] = [BigInt("1099511628211"), BigInt("2") ** BigInt("64")];
|
|
1914
|
+
var Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i));
|
|
1915
|
+
var F64 = new Float64Array(1);
|
|
1916
|
+
var F64In = new DataView(F64.buffer);
|
|
1917
|
+
var F64Out = new Uint8Array(F64.buffer);
|
|
1918
|
+
function* NumberToBytes(value) {
|
|
1919
|
+
const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8);
|
|
1920
|
+
for (let i = 0; i < byteCount; i++) {
|
|
1921
|
+
yield value >> 8 * (byteCount - 1 - i) & 255;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
function ArrayType(value) {
|
|
1925
|
+
FNV1A64(ByteMarker.Array);
|
|
1926
|
+
for (const item of value) {
|
|
1927
|
+
Visit(item);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
function BooleanType(value) {
|
|
1931
|
+
FNV1A64(ByteMarker.Boolean);
|
|
1932
|
+
FNV1A64(value ? 1 : 0);
|
|
1933
|
+
}
|
|
1934
|
+
function BigIntType(value) {
|
|
1935
|
+
FNV1A64(ByteMarker.BigInt);
|
|
1936
|
+
F64In.setBigInt64(0, value);
|
|
1937
|
+
for (const byte of F64Out) {
|
|
1938
|
+
FNV1A64(byte);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
function DateType(value) {
|
|
1942
|
+
FNV1A64(ByteMarker.Date);
|
|
1943
|
+
Visit(value.getTime());
|
|
1944
|
+
}
|
|
1945
|
+
function NullType(value) {
|
|
1946
|
+
FNV1A64(ByteMarker.Null);
|
|
1947
|
+
}
|
|
1948
|
+
function NumberType(value) {
|
|
1949
|
+
FNV1A64(ByteMarker.Number);
|
|
1950
|
+
F64In.setFloat64(0, value);
|
|
1951
|
+
for (const byte of F64Out) {
|
|
1952
|
+
FNV1A64(byte);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
function ObjectType(value) {
|
|
1956
|
+
FNV1A64(ByteMarker.Object);
|
|
1957
|
+
for (const key of globalThis.Object.keys(value).sort()) {
|
|
1958
|
+
Visit(key);
|
|
1959
|
+
Visit(value[key]);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
function StringType(value) {
|
|
1963
|
+
FNV1A64(ByteMarker.String);
|
|
1964
|
+
for (let i = 0; i < value.length; i++) {
|
|
1965
|
+
for (const byte of NumberToBytes(value.charCodeAt(i))) {
|
|
1966
|
+
FNV1A64(byte);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
function SymbolType(value) {
|
|
1971
|
+
FNV1A64(ByteMarker.Symbol);
|
|
1972
|
+
Visit(value.description);
|
|
1973
|
+
}
|
|
1974
|
+
function Uint8ArrayType(value) {
|
|
1975
|
+
FNV1A64(ByteMarker.Uint8Array);
|
|
1976
|
+
for (let i = 0; i < value.length; i++) {
|
|
1977
|
+
FNV1A64(value[i]);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
function UndefinedType(value) {
|
|
1981
|
+
return FNV1A64(ByteMarker.Undefined);
|
|
1982
|
+
}
|
|
1983
|
+
function Visit(value) {
|
|
1984
|
+
if ((0, guard_1.IsArray)(value))
|
|
1985
|
+
return ArrayType(value);
|
|
1986
|
+
if ((0, guard_1.IsBoolean)(value))
|
|
1987
|
+
return BooleanType(value);
|
|
1988
|
+
if ((0, guard_1.IsBigInt)(value))
|
|
1989
|
+
return BigIntType(value);
|
|
1990
|
+
if ((0, guard_1.IsDate)(value))
|
|
1991
|
+
return DateType(value);
|
|
1992
|
+
if ((0, guard_1.IsNull)(value))
|
|
1993
|
+
return NullType(value);
|
|
1994
|
+
if ((0, guard_1.IsNumber)(value))
|
|
1995
|
+
return NumberType(value);
|
|
1996
|
+
if ((0, guard_1.IsPlainObject)(value))
|
|
1997
|
+
return ObjectType(value);
|
|
1998
|
+
if ((0, guard_1.IsString)(value))
|
|
1999
|
+
return StringType(value);
|
|
2000
|
+
if ((0, guard_1.IsSymbol)(value))
|
|
2001
|
+
return SymbolType(value);
|
|
2002
|
+
if ((0, guard_1.IsUint8Array)(value))
|
|
2003
|
+
return Uint8ArrayType(value);
|
|
2004
|
+
if ((0, guard_1.IsUndefined)(value))
|
|
2005
|
+
return UndefinedType(value);
|
|
2006
|
+
throw new ValueHashError(value);
|
|
2007
|
+
}
|
|
2008
|
+
function FNV1A64(byte) {
|
|
2009
|
+
Accumulator = Accumulator ^ Bytes[byte];
|
|
2010
|
+
Accumulator = Accumulator * Prime % Size;
|
|
2011
|
+
}
|
|
2012
|
+
function Hash(value) {
|
|
2013
|
+
Accumulator = BigInt("14695981039346656037");
|
|
2014
|
+
Visit(value);
|
|
2015
|
+
return Accumulator;
|
|
2016
|
+
}
|
|
2017
|
+
exports.Hash = Hash;
|
|
2018
|
+
}
|
|
2019
|
+
});
|
|
2020
|
+
|
|
2021
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/errors/errors.js
|
|
2022
|
+
var require_errors = __commonJS({
|
|
2023
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/errors/errors.js"(exports) {
|
|
2024
|
+
"use strict";
|
|
2025
|
+
init_dirname();
|
|
2026
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2027
|
+
exports.Errors = exports.ValueErrorIterator = exports.EscapeKey = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
|
|
2028
|
+
var guard_1 = require_guard();
|
|
2029
|
+
var system_1 = require_system();
|
|
2030
|
+
var deref_1 = require_deref();
|
|
2031
|
+
var hash_1 = require_hash();
|
|
2032
|
+
var Types = require_typebox();
|
|
2033
|
+
var ValueErrorType;
|
|
2034
|
+
(function(ValueErrorType2) {
|
|
2035
|
+
ValueErrorType2[ValueErrorType2["ArrayContains"] = 0] = "ArrayContains";
|
|
2036
|
+
ValueErrorType2[ValueErrorType2["ArrayMaxContains"] = 1] = "ArrayMaxContains";
|
|
2037
|
+
ValueErrorType2[ValueErrorType2["ArrayMaxItems"] = 2] = "ArrayMaxItems";
|
|
2038
|
+
ValueErrorType2[ValueErrorType2["ArrayMinContains"] = 3] = "ArrayMinContains";
|
|
2039
|
+
ValueErrorType2[ValueErrorType2["ArrayMinItems"] = 4] = "ArrayMinItems";
|
|
2040
|
+
ValueErrorType2[ValueErrorType2["ArrayUniqueItems"] = 5] = "ArrayUniqueItems";
|
|
2041
|
+
ValueErrorType2[ValueErrorType2["Array"] = 6] = "Array";
|
|
2042
|
+
ValueErrorType2[ValueErrorType2["AsyncIterator"] = 7] = "AsyncIterator";
|
|
2043
|
+
ValueErrorType2[ValueErrorType2["BigIntExclusiveMaximum"] = 8] = "BigIntExclusiveMaximum";
|
|
2044
|
+
ValueErrorType2[ValueErrorType2["BigIntExclusiveMinimum"] = 9] = "BigIntExclusiveMinimum";
|
|
2045
|
+
ValueErrorType2[ValueErrorType2["BigIntMaximum"] = 10] = "BigIntMaximum";
|
|
2046
|
+
ValueErrorType2[ValueErrorType2["BigIntMinimum"] = 11] = "BigIntMinimum";
|
|
2047
|
+
ValueErrorType2[ValueErrorType2["BigIntMultipleOf"] = 12] = "BigIntMultipleOf";
|
|
2048
|
+
ValueErrorType2[ValueErrorType2["BigInt"] = 13] = "BigInt";
|
|
2049
|
+
ValueErrorType2[ValueErrorType2["Boolean"] = 14] = "Boolean";
|
|
2050
|
+
ValueErrorType2[ValueErrorType2["DateExclusiveMaximumTimestamp"] = 15] = "DateExclusiveMaximumTimestamp";
|
|
2051
|
+
ValueErrorType2[ValueErrorType2["DateExclusiveMinimumTimestamp"] = 16] = "DateExclusiveMinimumTimestamp";
|
|
2052
|
+
ValueErrorType2[ValueErrorType2["DateMaximumTimestamp"] = 17] = "DateMaximumTimestamp";
|
|
2053
|
+
ValueErrorType2[ValueErrorType2["DateMinimumTimestamp"] = 18] = "DateMinimumTimestamp";
|
|
2054
|
+
ValueErrorType2[ValueErrorType2["DateMultipleOfTimestamp"] = 19] = "DateMultipleOfTimestamp";
|
|
2055
|
+
ValueErrorType2[ValueErrorType2["Date"] = 20] = "Date";
|
|
2056
|
+
ValueErrorType2[ValueErrorType2["Function"] = 21] = "Function";
|
|
2057
|
+
ValueErrorType2[ValueErrorType2["IntegerExclusiveMaximum"] = 22] = "IntegerExclusiveMaximum";
|
|
2058
|
+
ValueErrorType2[ValueErrorType2["IntegerExclusiveMinimum"] = 23] = "IntegerExclusiveMinimum";
|
|
2059
|
+
ValueErrorType2[ValueErrorType2["IntegerMaximum"] = 24] = "IntegerMaximum";
|
|
2060
|
+
ValueErrorType2[ValueErrorType2["IntegerMinimum"] = 25] = "IntegerMinimum";
|
|
2061
|
+
ValueErrorType2[ValueErrorType2["IntegerMultipleOf"] = 26] = "IntegerMultipleOf";
|
|
2062
|
+
ValueErrorType2[ValueErrorType2["Integer"] = 27] = "Integer";
|
|
2063
|
+
ValueErrorType2[ValueErrorType2["IntersectUnevaluatedProperties"] = 28] = "IntersectUnevaluatedProperties";
|
|
2064
|
+
ValueErrorType2[ValueErrorType2["Intersect"] = 29] = "Intersect";
|
|
2065
|
+
ValueErrorType2[ValueErrorType2["Iterator"] = 30] = "Iterator";
|
|
2066
|
+
ValueErrorType2[ValueErrorType2["Kind"] = 31] = "Kind";
|
|
2067
|
+
ValueErrorType2[ValueErrorType2["Literal"] = 32] = "Literal";
|
|
2068
|
+
ValueErrorType2[ValueErrorType2["Never"] = 33] = "Never";
|
|
2069
|
+
ValueErrorType2[ValueErrorType2["Not"] = 34] = "Not";
|
|
2070
|
+
ValueErrorType2[ValueErrorType2["Null"] = 35] = "Null";
|
|
2071
|
+
ValueErrorType2[ValueErrorType2["NumberExclusiveMaximum"] = 36] = "NumberExclusiveMaximum";
|
|
2072
|
+
ValueErrorType2[ValueErrorType2["NumberExclusiveMinimum"] = 37] = "NumberExclusiveMinimum";
|
|
2073
|
+
ValueErrorType2[ValueErrorType2["NumberMaximum"] = 38] = "NumberMaximum";
|
|
2074
|
+
ValueErrorType2[ValueErrorType2["NumberMinimum"] = 39] = "NumberMinimum";
|
|
2075
|
+
ValueErrorType2[ValueErrorType2["NumberMultipleOf"] = 40] = "NumberMultipleOf";
|
|
2076
|
+
ValueErrorType2[ValueErrorType2["Number"] = 41] = "Number";
|
|
2077
|
+
ValueErrorType2[ValueErrorType2["ObjectAdditionalProperties"] = 42] = "ObjectAdditionalProperties";
|
|
2078
|
+
ValueErrorType2[ValueErrorType2["ObjectMaxProperties"] = 43] = "ObjectMaxProperties";
|
|
2079
|
+
ValueErrorType2[ValueErrorType2["ObjectMinProperties"] = 44] = "ObjectMinProperties";
|
|
2080
|
+
ValueErrorType2[ValueErrorType2["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty";
|
|
2081
|
+
ValueErrorType2[ValueErrorType2["Object"] = 46] = "Object";
|
|
2082
|
+
ValueErrorType2[ValueErrorType2["Promise"] = 47] = "Promise";
|
|
2083
|
+
ValueErrorType2[ValueErrorType2["StringFormatUnknown"] = 48] = "StringFormatUnknown";
|
|
2084
|
+
ValueErrorType2[ValueErrorType2["StringFormat"] = 49] = "StringFormat";
|
|
2085
|
+
ValueErrorType2[ValueErrorType2["StringMaxLength"] = 50] = "StringMaxLength";
|
|
2086
|
+
ValueErrorType2[ValueErrorType2["StringMinLength"] = 51] = "StringMinLength";
|
|
2087
|
+
ValueErrorType2[ValueErrorType2["StringPattern"] = 52] = "StringPattern";
|
|
2088
|
+
ValueErrorType2[ValueErrorType2["String"] = 53] = "String";
|
|
2089
|
+
ValueErrorType2[ValueErrorType2["Symbol"] = 54] = "Symbol";
|
|
2090
|
+
ValueErrorType2[ValueErrorType2["TupleLength"] = 55] = "TupleLength";
|
|
2091
|
+
ValueErrorType2[ValueErrorType2["Tuple"] = 56] = "Tuple";
|
|
2092
|
+
ValueErrorType2[ValueErrorType2["Uint8ArrayMaxByteLength"] = 57] = "Uint8ArrayMaxByteLength";
|
|
2093
|
+
ValueErrorType2[ValueErrorType2["Uint8ArrayMinByteLength"] = 58] = "Uint8ArrayMinByteLength";
|
|
2094
|
+
ValueErrorType2[ValueErrorType2["Uint8Array"] = 59] = "Uint8Array";
|
|
2095
|
+
ValueErrorType2[ValueErrorType2["Undefined"] = 60] = "Undefined";
|
|
2096
|
+
ValueErrorType2[ValueErrorType2["Union"] = 61] = "Union";
|
|
2097
|
+
ValueErrorType2[ValueErrorType2["Void"] = 62] = "Void";
|
|
2098
|
+
})(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
|
|
2099
|
+
var ValueErrorsUnknownTypeError = class extends Types.TypeBoxError {
|
|
2100
|
+
constructor(schema) {
|
|
2101
|
+
super("Unknown type");
|
|
2102
|
+
this.schema = schema;
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
2106
|
+
function EscapeKey(key) {
|
|
2107
|
+
return key.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
2108
|
+
}
|
|
2109
|
+
exports.EscapeKey = EscapeKey;
|
|
2110
|
+
function IsDefined(value) {
|
|
2111
|
+
return value !== void 0;
|
|
2112
|
+
}
|
|
2113
|
+
var ValueErrorIterator = class {
|
|
2114
|
+
constructor(iterator) {
|
|
2115
|
+
this.iterator = iterator;
|
|
2116
|
+
}
|
|
2117
|
+
[Symbol.iterator]() {
|
|
2118
|
+
return this.iterator;
|
|
2119
|
+
}
|
|
2120
|
+
/** Returns the first value error or undefined if no errors */
|
|
2121
|
+
First() {
|
|
2122
|
+
const next = this.iterator.next();
|
|
2123
|
+
return next.done ? void 0 : next.value;
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
exports.ValueErrorIterator = ValueErrorIterator;
|
|
2127
|
+
function Create(type, schema, path, value) {
|
|
2128
|
+
return { type, schema, path, value, message: system_1.TypeSystemErrorFunction.Get()(schema, type) };
|
|
2129
|
+
}
|
|
2130
|
+
function* TAny(schema, references, path, value) {
|
|
2131
|
+
}
|
|
2132
|
+
function* TArray(schema, references, path, value) {
|
|
2133
|
+
if (!(0, guard_1.IsArray)(value)) {
|
|
2134
|
+
return yield Create(ValueErrorType.Array, schema, path, value);
|
|
2135
|
+
}
|
|
2136
|
+
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
2137
|
+
yield Create(ValueErrorType.ArrayMinItems, schema, path, value);
|
|
2138
|
+
}
|
|
2139
|
+
if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
2140
|
+
yield Create(ValueErrorType.ArrayMaxItems, schema, path, value);
|
|
2141
|
+
}
|
|
2142
|
+
for (let i = 0; i < value.length; i++) {
|
|
2143
|
+
yield* Visit(schema.items, references, `${path}/${i}`, value[i]);
|
|
2144
|
+
}
|
|
2145
|
+
if (schema.uniqueItems === true && !function() {
|
|
2146
|
+
const set = /* @__PURE__ */ new Set();
|
|
2147
|
+
for (const element of value) {
|
|
2148
|
+
const hashed = (0, hash_1.Hash)(element);
|
|
2149
|
+
if (set.has(hashed)) {
|
|
2150
|
+
return false;
|
|
2151
|
+
} else {
|
|
2152
|
+
set.add(hashed);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return true;
|
|
2156
|
+
}()) {
|
|
2157
|
+
yield Create(ValueErrorType.ArrayUniqueItems, schema, path, value);
|
|
2158
|
+
}
|
|
2159
|
+
if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : Types.Type.Never();
|
|
2163
|
+
const containsCount = value.reduce((acc, value2, index) => Visit(containsSchema, references, `${path}${index}`, value2).next().done === true ? acc + 1 : acc, 0);
|
|
2164
|
+
if (containsCount === 0) {
|
|
2165
|
+
yield Create(ValueErrorType.ArrayContains, schema, path, value);
|
|
2166
|
+
}
|
|
2167
|
+
if ((0, guard_1.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
2168
|
+
yield Create(ValueErrorType.ArrayMinContains, schema, path, value);
|
|
2169
|
+
}
|
|
2170
|
+
if ((0, guard_1.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
2171
|
+
yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
function* TAsyncIterator(schema, references, path, value) {
|
|
2175
|
+
if (!(0, guard_1.IsAsyncIterator)(value))
|
|
2176
|
+
yield Create(ValueErrorType.AsyncIterator, schema, path, value);
|
|
2177
|
+
}
|
|
2178
|
+
function* TBigInt(schema, references, path, value) {
|
|
2179
|
+
if (!(0, guard_1.IsBigInt)(value))
|
|
2180
|
+
return yield Create(ValueErrorType.BigInt, schema, path, value);
|
|
2181
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2182
|
+
yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value);
|
|
2183
|
+
}
|
|
2184
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2185
|
+
yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path, value);
|
|
2186
|
+
}
|
|
2187
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2188
|
+
yield Create(ValueErrorType.BigIntMaximum, schema, path, value);
|
|
2189
|
+
}
|
|
2190
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2191
|
+
yield Create(ValueErrorType.BigIntMinimum, schema, path, value);
|
|
2192
|
+
}
|
|
2193
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
|
|
2194
|
+
yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value);
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
function* TBoolean(schema, references, path, value) {
|
|
2198
|
+
if (!(0, guard_1.IsBoolean)(value))
|
|
2199
|
+
yield Create(ValueErrorType.Boolean, schema, path, value);
|
|
2200
|
+
}
|
|
2201
|
+
function* TConstructor(schema, references, path, value) {
|
|
2202
|
+
yield* Visit(schema.returns, references, path, value.prototype);
|
|
2203
|
+
}
|
|
2204
|
+
function* TDate(schema, references, path, value) {
|
|
2205
|
+
if (!(0, guard_1.IsDate)(value))
|
|
2206
|
+
return yield Create(ValueErrorType.Date, schema, path, value);
|
|
2207
|
+
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
2208
|
+
yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value);
|
|
2209
|
+
}
|
|
2210
|
+
if (IsDefined(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
2211
|
+
yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value);
|
|
2212
|
+
}
|
|
2213
|
+
if (IsDefined(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
2214
|
+
yield Create(ValueErrorType.DateMaximumTimestamp, schema, path, value);
|
|
2215
|
+
}
|
|
2216
|
+
if (IsDefined(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
2217
|
+
yield Create(ValueErrorType.DateMinimumTimestamp, schema, path, value);
|
|
2218
|
+
}
|
|
2219
|
+
if (IsDefined(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
|
|
2220
|
+
yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
function* TFunction(schema, references, path, value) {
|
|
2224
|
+
if (!(0, guard_1.IsFunction)(value))
|
|
2225
|
+
yield Create(ValueErrorType.Function, schema, path, value);
|
|
2226
|
+
}
|
|
2227
|
+
function* TInteger(schema, references, path, value) {
|
|
2228
|
+
if (!(0, guard_1.IsInteger)(value))
|
|
2229
|
+
return yield Create(ValueErrorType.Integer, schema, path, value);
|
|
2230
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2231
|
+
yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value);
|
|
2232
|
+
}
|
|
2233
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2234
|
+
yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path, value);
|
|
2235
|
+
}
|
|
2236
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2237
|
+
yield Create(ValueErrorType.IntegerMaximum, schema, path, value);
|
|
2238
|
+
}
|
|
2239
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2240
|
+
yield Create(ValueErrorType.IntegerMinimum, schema, path, value);
|
|
2241
|
+
}
|
|
2242
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2243
|
+
yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
function* TIntersect(schema, references, path, value) {
|
|
2247
|
+
for (const inner of schema.allOf) {
|
|
2248
|
+
const next = Visit(inner, references, path, value).next();
|
|
2249
|
+
if (!next.done) {
|
|
2250
|
+
yield Create(ValueErrorType.Intersect, schema, path, value);
|
|
2251
|
+
yield next.value;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
if (schema.unevaluatedProperties === false) {
|
|
2255
|
+
const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
|
|
2256
|
+
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
2257
|
+
if (!keyCheck.test(valueKey)) {
|
|
2258
|
+
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
if (typeof schema.unevaluatedProperties === "object") {
|
|
2263
|
+
const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
|
|
2264
|
+
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
2265
|
+
if (!keyCheck.test(valueKey)) {
|
|
2266
|
+
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
|
2267
|
+
if (!next.done)
|
|
2268
|
+
yield next.value;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
function* TIterator(schema, references, path, value) {
|
|
2274
|
+
if (!(0, guard_1.IsIterator)(value))
|
|
2275
|
+
yield Create(ValueErrorType.Iterator, schema, path, value);
|
|
2276
|
+
}
|
|
2277
|
+
function* TLiteral(schema, references, path, value) {
|
|
2278
|
+
if (!(value === schema.const))
|
|
2279
|
+
yield Create(ValueErrorType.Literal, schema, path, value);
|
|
2280
|
+
}
|
|
2281
|
+
function* TNever(schema, references, path, value) {
|
|
2282
|
+
yield Create(ValueErrorType.Never, schema, path, value);
|
|
2283
|
+
}
|
|
2284
|
+
function* TNot(schema, references, path, value) {
|
|
2285
|
+
if (Visit(schema.not, references, path, value).next().done === true)
|
|
2286
|
+
yield Create(ValueErrorType.Not, schema, path, value);
|
|
2287
|
+
}
|
|
2288
|
+
function* TNull(schema, references, path, value) {
|
|
2289
|
+
if (!(0, guard_1.IsNull)(value))
|
|
2290
|
+
yield Create(ValueErrorType.Null, schema, path, value);
|
|
2291
|
+
}
|
|
2292
|
+
function* TNumber(schema, references, path, value) {
|
|
2293
|
+
if (!system_1.TypeSystemPolicy.IsNumberLike(value))
|
|
2294
|
+
return yield Create(ValueErrorType.Number, schema, path, value);
|
|
2295
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2296
|
+
yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path, value);
|
|
2297
|
+
}
|
|
2298
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2299
|
+
yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path, value);
|
|
2300
|
+
}
|
|
2301
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2302
|
+
yield Create(ValueErrorType.NumberMaximum, schema, path, value);
|
|
2303
|
+
}
|
|
2304
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2305
|
+
yield Create(ValueErrorType.NumberMinimum, schema, path, value);
|
|
2306
|
+
}
|
|
2307
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2308
|
+
yield Create(ValueErrorType.NumberMultipleOf, schema, path, value);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
function* TObject(schema, references, path, value) {
|
|
2312
|
+
if (!system_1.TypeSystemPolicy.IsObjectLike(value))
|
|
2313
|
+
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
2314
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
2315
|
+
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
2316
|
+
}
|
|
2317
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
2318
|
+
yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
|
|
2319
|
+
}
|
|
2320
|
+
const requiredKeys = Array.isArray(schema.required) ? schema.required : [];
|
|
2321
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
2322
|
+
const unknownKeys = Object.getOwnPropertyNames(value);
|
|
2323
|
+
for (const requiredKey of requiredKeys) {
|
|
2324
|
+
if (unknownKeys.includes(requiredKey))
|
|
2325
|
+
continue;
|
|
2326
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${EscapeKey(requiredKey)}`, void 0);
|
|
2327
|
+
}
|
|
2328
|
+
if (schema.additionalProperties === false) {
|
|
2329
|
+
for (const valueKey of unknownKeys) {
|
|
2330
|
+
if (!knownKeys.includes(valueKey)) {
|
|
2331
|
+
yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
if (typeof schema.additionalProperties === "object") {
|
|
2336
|
+
for (const valueKey of unknownKeys) {
|
|
2337
|
+
if (knownKeys.includes(valueKey))
|
|
2338
|
+
continue;
|
|
2339
|
+
yield* Visit(schema.additionalProperties, references, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
for (const knownKey of knownKeys) {
|
|
2343
|
+
const property = schema.properties[knownKey];
|
|
2344
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
2345
|
+
yield* Visit(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
2346
|
+
if (Types.ExtendsUndefined.Check(schema) && !(knownKey in value)) {
|
|
2347
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${EscapeKey(knownKey)}`, void 0);
|
|
2348
|
+
}
|
|
2349
|
+
} else {
|
|
2350
|
+
if (system_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
|
|
2351
|
+
yield* Visit(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
function* TPromise(schema, references, path, value) {
|
|
2357
|
+
if (!(0, guard_1.IsPromise)(value))
|
|
2358
|
+
yield Create(ValueErrorType.Promise, schema, path, value);
|
|
2359
|
+
}
|
|
2360
|
+
function* TRecord(schema, references, path, value) {
|
|
2361
|
+
if (!system_1.TypeSystemPolicy.IsRecordLike(value))
|
|
2362
|
+
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
2363
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
2364
|
+
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
2365
|
+
}
|
|
2366
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
2367
|
+
yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
|
|
2368
|
+
}
|
|
2369
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
2370
|
+
const regex = new RegExp(patternKey);
|
|
2371
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
2372
|
+
if (regex.test(propertyKey))
|
|
2373
|
+
yield* Visit(patternSchema, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
2374
|
+
}
|
|
2375
|
+
if (typeof schema.additionalProperties === "object") {
|
|
2376
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
2377
|
+
if (!regex.test(propertyKey))
|
|
2378
|
+
yield* Visit(schema.additionalProperties, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
if (schema.additionalProperties === false) {
|
|
2382
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
2383
|
+
if (regex.test(propertyKey))
|
|
2384
|
+
continue;
|
|
2385
|
+
return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
function* TRef(schema, references, path, value) {
|
|
2390
|
+
yield* Visit((0, deref_1.Deref)(schema, references), references, path, value);
|
|
2391
|
+
}
|
|
2392
|
+
function* TString(schema, references, path, value) {
|
|
2393
|
+
if (!(0, guard_1.IsString)(value))
|
|
2394
|
+
return yield Create(ValueErrorType.String, schema, path, value);
|
|
2395
|
+
if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
2396
|
+
yield Create(ValueErrorType.StringMinLength, schema, path, value);
|
|
2397
|
+
}
|
|
2398
|
+
if (IsDefined(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
2399
|
+
yield Create(ValueErrorType.StringMaxLength, schema, path, value);
|
|
2400
|
+
}
|
|
2401
|
+
if ((0, guard_1.IsString)(schema.pattern)) {
|
|
2402
|
+
const regex = new RegExp(schema.pattern);
|
|
2403
|
+
if (!regex.test(value)) {
|
|
2404
|
+
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
if ((0, guard_1.IsString)(schema.format)) {
|
|
2408
|
+
if (!Types.FormatRegistry.Has(schema.format)) {
|
|
2409
|
+
yield Create(ValueErrorType.StringFormatUnknown, schema, path, value);
|
|
2410
|
+
} else {
|
|
2411
|
+
const format = Types.FormatRegistry.Get(schema.format);
|
|
2412
|
+
if (!format(value)) {
|
|
2413
|
+
yield Create(ValueErrorType.StringFormat, schema, path, value);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
function* TSymbol(schema, references, path, value) {
|
|
2419
|
+
if (!(0, guard_1.IsSymbol)(value))
|
|
2420
|
+
yield Create(ValueErrorType.Symbol, schema, path, value);
|
|
2421
|
+
}
|
|
2422
|
+
function* TTemplateLiteral(schema, references, path, value) {
|
|
2423
|
+
if (!(0, guard_1.IsString)(value))
|
|
2424
|
+
return yield Create(ValueErrorType.String, schema, path, value);
|
|
2425
|
+
const regex = new RegExp(schema.pattern);
|
|
2426
|
+
if (!regex.test(value)) {
|
|
2427
|
+
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
function* TThis(schema, references, path, value) {
|
|
2431
|
+
yield* Visit((0, deref_1.Deref)(schema, references), references, path, value);
|
|
2432
|
+
}
|
|
2433
|
+
function* TTuple(schema, references, path, value) {
|
|
2434
|
+
if (!(0, guard_1.IsArray)(value))
|
|
2435
|
+
return yield Create(ValueErrorType.Tuple, schema, path, value);
|
|
2436
|
+
if (schema.items === void 0 && !(value.length === 0)) {
|
|
2437
|
+
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
2438
|
+
}
|
|
2439
|
+
if (!(value.length === schema.maxItems)) {
|
|
2440
|
+
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
2441
|
+
}
|
|
2442
|
+
if (!schema.items) {
|
|
2443
|
+
return;
|
|
2444
|
+
}
|
|
2445
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
2446
|
+
yield* Visit(schema.items[i], references, `${path}/${i}`, value[i]);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
function* TUndefined(schema, references, path, value) {
|
|
2450
|
+
if (!(0, guard_1.IsUndefined)(value))
|
|
2451
|
+
yield Create(ValueErrorType.Undefined, schema, path, value);
|
|
2452
|
+
}
|
|
2453
|
+
function* TUnion(schema, references, path, value) {
|
|
2454
|
+
let count = 0;
|
|
2455
|
+
for (const subschema of schema.anyOf) {
|
|
2456
|
+
const errors = [...Visit(subschema, references, path, value)];
|
|
2457
|
+
if (errors.length === 0)
|
|
2458
|
+
return;
|
|
2459
|
+
count += errors.length;
|
|
2460
|
+
}
|
|
2461
|
+
if (count > 0) {
|
|
2462
|
+
yield Create(ValueErrorType.Union, schema, path, value);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
function* TUint8Array(schema, references, path, value) {
|
|
2466
|
+
if (!(0, guard_1.IsUint8Array)(value))
|
|
2467
|
+
return yield Create(ValueErrorType.Uint8Array, schema, path, value);
|
|
2468
|
+
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
2469
|
+
yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value);
|
|
2470
|
+
}
|
|
2471
|
+
if (IsDefined(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
2472
|
+
yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
function* TUnknown(schema, references, path, value) {
|
|
2476
|
+
}
|
|
2477
|
+
function* TVoid(schema, references, path, value) {
|
|
2478
|
+
if (!system_1.TypeSystemPolicy.IsVoidLike(value))
|
|
2479
|
+
yield Create(ValueErrorType.Void, schema, path, value);
|
|
2480
|
+
}
|
|
2481
|
+
function* TKind(schema, references, path, value) {
|
|
2482
|
+
const check = Types.TypeRegistry.Get(schema[Types.Kind]);
|
|
2483
|
+
if (!check(schema, value))
|
|
2484
|
+
yield Create(ValueErrorType.Kind, schema, path, value);
|
|
2485
|
+
}
|
|
2486
|
+
function* Visit(schema, references, path, value) {
|
|
2487
|
+
const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
|
|
2488
|
+
const schema_ = schema;
|
|
2489
|
+
switch (schema_[Types.Kind]) {
|
|
2490
|
+
case "Any":
|
|
2491
|
+
return yield* TAny(schema_, references_, path, value);
|
|
2492
|
+
case "Array":
|
|
2493
|
+
return yield* TArray(schema_, references_, path, value);
|
|
2494
|
+
case "AsyncIterator":
|
|
2495
|
+
return yield* TAsyncIterator(schema_, references_, path, value);
|
|
2496
|
+
case "BigInt":
|
|
2497
|
+
return yield* TBigInt(schema_, references_, path, value);
|
|
2498
|
+
case "Boolean":
|
|
2499
|
+
return yield* TBoolean(schema_, references_, path, value);
|
|
2500
|
+
case "Constructor":
|
|
2501
|
+
return yield* TConstructor(schema_, references_, path, value);
|
|
2502
|
+
case "Date":
|
|
2503
|
+
return yield* TDate(schema_, references_, path, value);
|
|
2504
|
+
case "Function":
|
|
2505
|
+
return yield* TFunction(schema_, references_, path, value);
|
|
2506
|
+
case "Integer":
|
|
2507
|
+
return yield* TInteger(schema_, references_, path, value);
|
|
2508
|
+
case "Intersect":
|
|
2509
|
+
return yield* TIntersect(schema_, references_, path, value);
|
|
2510
|
+
case "Iterator":
|
|
2511
|
+
return yield* TIterator(schema_, references_, path, value);
|
|
2512
|
+
case "Literal":
|
|
2513
|
+
return yield* TLiteral(schema_, references_, path, value);
|
|
2514
|
+
case "Never":
|
|
2515
|
+
return yield* TNever(schema_, references_, path, value);
|
|
2516
|
+
case "Not":
|
|
2517
|
+
return yield* TNot(schema_, references_, path, value);
|
|
2518
|
+
case "Null":
|
|
2519
|
+
return yield* TNull(schema_, references_, path, value);
|
|
2520
|
+
case "Number":
|
|
2521
|
+
return yield* TNumber(schema_, references_, path, value);
|
|
2522
|
+
case "Object":
|
|
2523
|
+
return yield* TObject(schema_, references_, path, value);
|
|
2524
|
+
case "Promise":
|
|
2525
|
+
return yield* TPromise(schema_, references_, path, value);
|
|
2526
|
+
case "Record":
|
|
2527
|
+
return yield* TRecord(schema_, references_, path, value);
|
|
2528
|
+
case "Ref":
|
|
2529
|
+
return yield* TRef(schema_, references_, path, value);
|
|
2530
|
+
case "String":
|
|
2531
|
+
return yield* TString(schema_, references_, path, value);
|
|
2532
|
+
case "Symbol":
|
|
2533
|
+
return yield* TSymbol(schema_, references_, path, value);
|
|
2534
|
+
case "TemplateLiteral":
|
|
2535
|
+
return yield* TTemplateLiteral(schema_, references_, path, value);
|
|
2536
|
+
case "This":
|
|
2537
|
+
return yield* TThis(schema_, references_, path, value);
|
|
2538
|
+
case "Tuple":
|
|
2539
|
+
return yield* TTuple(schema_, references_, path, value);
|
|
2540
|
+
case "Undefined":
|
|
2541
|
+
return yield* TUndefined(schema_, references_, path, value);
|
|
2542
|
+
case "Union":
|
|
2543
|
+
return yield* TUnion(schema_, references_, path, value);
|
|
2544
|
+
case "Uint8Array":
|
|
2545
|
+
return yield* TUint8Array(schema_, references_, path, value);
|
|
2546
|
+
case "Unknown":
|
|
2547
|
+
return yield* TUnknown(schema_, references_, path, value);
|
|
2548
|
+
case "Void":
|
|
2549
|
+
return yield* TVoid(schema_, references_, path, value);
|
|
2550
|
+
default:
|
|
2551
|
+
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
2552
|
+
throw new ValueErrorsUnknownTypeError(schema);
|
|
2553
|
+
return yield* TKind(schema_, references_, path, value);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
function Errors(...args) {
|
|
2557
|
+
const iterator = args.length === 3 ? Visit(args[0], args[1], "", args[2]) : Visit(args[0], [], "", args[1]);
|
|
2558
|
+
return new ValueErrorIterator(iterator);
|
|
2559
|
+
}
|
|
2560
|
+
exports.Errors = Errors;
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/errors/index.js
|
|
2565
|
+
var require_errors2 = __commonJS({
|
|
2566
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/errors/index.js"(exports) {
|
|
2567
|
+
"use strict";
|
|
2568
|
+
init_dirname();
|
|
2569
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
2570
|
+
if (k2 === void 0)
|
|
2571
|
+
k2 = k;
|
|
2572
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2573
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2574
|
+
desc = { enumerable: true, get: function() {
|
|
2575
|
+
return m[k];
|
|
2576
|
+
} };
|
|
2577
|
+
}
|
|
2578
|
+
Object.defineProperty(o, k2, desc);
|
|
2579
|
+
} : function(o, m, k, k2) {
|
|
2580
|
+
if (k2 === void 0)
|
|
2581
|
+
k2 = k;
|
|
2582
|
+
o[k2] = m[k];
|
|
2583
|
+
});
|
|
2584
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
2585
|
+
for (var p in m)
|
|
2586
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
2587
|
+
__createBinding(exports2, m, p);
|
|
2588
|
+
};
|
|
2589
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2590
|
+
__exportStar(require_errors(), exports);
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
|
|
2594
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/system/index.js
|
|
2595
|
+
var require_system2 = __commonJS({
|
|
2596
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/system/index.js"(exports) {
|
|
2597
|
+
"use strict";
|
|
2598
|
+
init_dirname();
|
|
2599
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
2600
|
+
if (k2 === void 0)
|
|
2601
|
+
k2 = k;
|
|
2602
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2603
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2604
|
+
desc = { enumerable: true, get: function() {
|
|
2605
|
+
return m[k];
|
|
2606
|
+
} };
|
|
2607
|
+
}
|
|
2608
|
+
Object.defineProperty(o, k2, desc);
|
|
2609
|
+
} : function(o, m, k, k2) {
|
|
2610
|
+
if (k2 === void 0)
|
|
2611
|
+
k2 = k;
|
|
2612
|
+
o[k2] = m[k];
|
|
2613
|
+
});
|
|
2614
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
2615
|
+
for (var p in m)
|
|
2616
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
2617
|
+
__createBinding(exports2, m, p);
|
|
2618
|
+
};
|
|
2619
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2620
|
+
exports.ValueErrorType = void 0;
|
|
2621
|
+
var errors_1 = require_errors();
|
|
2622
|
+
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function() {
|
|
2623
|
+
return errors_1.ValueErrorType;
|
|
2624
|
+
} });
|
|
2625
|
+
__exportStar(require_system(), exports);
|
|
2626
|
+
}
|
|
2627
|
+
});
|
|
2628
|
+
|
|
2629
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/check.js
|
|
2630
|
+
var require_check = __commonJS({
|
|
2631
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/check.js"(exports) {
|
|
2632
|
+
"use strict";
|
|
2633
|
+
init_dirname();
|
|
2634
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2635
|
+
exports.Check = exports.ValueCheckUnknownTypeError = void 0;
|
|
2636
|
+
var guard_1 = require_guard();
|
|
2637
|
+
var index_1 = require_system2();
|
|
2638
|
+
var deref_1 = require_deref();
|
|
2639
|
+
var hash_1 = require_hash();
|
|
2640
|
+
var Types = require_typebox();
|
|
2641
|
+
var ValueCheckUnknownTypeError = class extends Types.TypeBoxError {
|
|
2642
|
+
constructor(schema) {
|
|
2643
|
+
super(`Unknown type`);
|
|
2644
|
+
this.schema = schema;
|
|
2645
|
+
}
|
|
2646
|
+
};
|
|
2647
|
+
exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
|
|
2648
|
+
function IsAnyOrUnknown(schema) {
|
|
2649
|
+
return schema[Types.Kind] === "Any" || schema[Types.Kind] === "Unknown";
|
|
2650
|
+
}
|
|
2651
|
+
function IsDefined(value) {
|
|
2652
|
+
return value !== void 0;
|
|
2653
|
+
}
|
|
2654
|
+
function TAny(schema, references, value) {
|
|
2655
|
+
return true;
|
|
2656
|
+
}
|
|
2657
|
+
function TArray(schema, references, value) {
|
|
2658
|
+
if (!(0, guard_1.IsArray)(value))
|
|
2659
|
+
return false;
|
|
2660
|
+
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
2661
|
+
return false;
|
|
2662
|
+
}
|
|
2663
|
+
if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
2664
|
+
return false;
|
|
2665
|
+
}
|
|
2666
|
+
if (!value.every((value2) => Visit(schema.items, references, value2))) {
|
|
2667
|
+
return false;
|
|
2668
|
+
}
|
|
2669
|
+
if (schema.uniqueItems === true && !function() {
|
|
2670
|
+
const set = /* @__PURE__ */ new Set();
|
|
2671
|
+
for (const element of value) {
|
|
2672
|
+
const hashed = (0, hash_1.Hash)(element);
|
|
2673
|
+
if (set.has(hashed)) {
|
|
2674
|
+
return false;
|
|
2675
|
+
} else {
|
|
2676
|
+
set.add(hashed);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
return true;
|
|
2680
|
+
}()) {
|
|
2681
|
+
return false;
|
|
2682
|
+
}
|
|
2683
|
+
if (!(IsDefined(schema.contains) || (0, guard_1.IsNumber)(schema.minContains) || (0, guard_1.IsNumber)(schema.maxContains))) {
|
|
2684
|
+
return true;
|
|
2685
|
+
}
|
|
2686
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : Types.Type.Never();
|
|
2687
|
+
const containsCount = value.reduce((acc, value2) => Visit(containsSchema, references, value2) ? acc + 1 : acc, 0);
|
|
2688
|
+
if (containsCount === 0) {
|
|
2689
|
+
return false;
|
|
2690
|
+
}
|
|
2691
|
+
if ((0, guard_1.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
2692
|
+
return false;
|
|
2693
|
+
}
|
|
2694
|
+
if ((0, guard_1.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
2695
|
+
return false;
|
|
2696
|
+
}
|
|
2697
|
+
return true;
|
|
2698
|
+
}
|
|
2699
|
+
function TAsyncIterator(schema, references, value) {
|
|
2700
|
+
return (0, guard_1.IsAsyncIterator)(value);
|
|
2701
|
+
}
|
|
2702
|
+
function TBigInt(schema, references, value) {
|
|
2703
|
+
if (!(0, guard_1.IsBigInt)(value))
|
|
2704
|
+
return false;
|
|
2705
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2706
|
+
return false;
|
|
2707
|
+
}
|
|
2708
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2709
|
+
return false;
|
|
2710
|
+
}
|
|
2711
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2712
|
+
return false;
|
|
2713
|
+
}
|
|
2714
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2715
|
+
return false;
|
|
2716
|
+
}
|
|
2717
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
|
|
2718
|
+
return false;
|
|
2719
|
+
}
|
|
2720
|
+
return true;
|
|
2721
|
+
}
|
|
2722
|
+
function TBoolean(schema, references, value) {
|
|
2723
|
+
return (0, guard_1.IsBoolean)(value);
|
|
2724
|
+
}
|
|
2725
|
+
function TConstructor(schema, references, value) {
|
|
2726
|
+
return Visit(schema.returns, references, value.prototype);
|
|
2727
|
+
}
|
|
2728
|
+
function TDate(schema, references, value) {
|
|
2729
|
+
if (!(0, guard_1.IsDate)(value))
|
|
2730
|
+
return false;
|
|
2731
|
+
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
2732
|
+
return false;
|
|
2733
|
+
}
|
|
2734
|
+
if (IsDefined(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
2735
|
+
return false;
|
|
2736
|
+
}
|
|
2737
|
+
if (IsDefined(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
2738
|
+
return false;
|
|
2739
|
+
}
|
|
2740
|
+
if (IsDefined(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
2741
|
+
return false;
|
|
2742
|
+
}
|
|
2743
|
+
if (IsDefined(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
|
|
2744
|
+
return false;
|
|
2745
|
+
}
|
|
2746
|
+
return true;
|
|
2747
|
+
}
|
|
2748
|
+
function TFunction(schema, references, value) {
|
|
2749
|
+
return (0, guard_1.IsFunction)(value);
|
|
2750
|
+
}
|
|
2751
|
+
function TInteger(schema, references, value) {
|
|
2752
|
+
if (!(0, guard_1.IsInteger)(value)) {
|
|
2753
|
+
return false;
|
|
2754
|
+
}
|
|
2755
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2756
|
+
return false;
|
|
2757
|
+
}
|
|
2758
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2759
|
+
return false;
|
|
2760
|
+
}
|
|
2761
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2762
|
+
return false;
|
|
2763
|
+
}
|
|
2764
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2765
|
+
return false;
|
|
2766
|
+
}
|
|
2767
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2768
|
+
return false;
|
|
2769
|
+
}
|
|
2770
|
+
return true;
|
|
2771
|
+
}
|
|
2772
|
+
function TIntersect(schema, references, value) {
|
|
2773
|
+
const check1 = schema.allOf.every((schema2) => Visit(schema2, references, value));
|
|
2774
|
+
if (schema.unevaluatedProperties === false) {
|
|
2775
|
+
const keyPattern = new RegExp(Types.KeyResolver.ResolvePattern(schema));
|
|
2776
|
+
const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
|
|
2777
|
+
return check1 && check2;
|
|
2778
|
+
} else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
|
|
2779
|
+
const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
|
|
2780
|
+
const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
|
|
2781
|
+
return check1 && check2;
|
|
2782
|
+
} else {
|
|
2783
|
+
return check1;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
function TIterator(schema, references, value) {
|
|
2787
|
+
return (0, guard_1.IsIterator)(value);
|
|
2788
|
+
}
|
|
2789
|
+
function TLiteral(schema, references, value) {
|
|
2790
|
+
return value === schema.const;
|
|
2791
|
+
}
|
|
2792
|
+
function TNever(schema, references, value) {
|
|
2793
|
+
return false;
|
|
2794
|
+
}
|
|
2795
|
+
function TNot(schema, references, value) {
|
|
2796
|
+
return !Visit(schema.not, references, value);
|
|
2797
|
+
}
|
|
2798
|
+
function TNull(schema, references, value) {
|
|
2799
|
+
return (0, guard_1.IsNull)(value);
|
|
2800
|
+
}
|
|
2801
|
+
function TNumber(schema, references, value) {
|
|
2802
|
+
if (!index_1.TypeSystemPolicy.IsNumberLike(value))
|
|
2803
|
+
return false;
|
|
2804
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2805
|
+
return false;
|
|
2806
|
+
}
|
|
2807
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2808
|
+
return false;
|
|
2809
|
+
}
|
|
2810
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2811
|
+
return false;
|
|
2812
|
+
}
|
|
2813
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2814
|
+
return false;
|
|
2815
|
+
}
|
|
2816
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
return true;
|
|
2820
|
+
}
|
|
2821
|
+
function TObject(schema, references, value) {
|
|
2822
|
+
if (!index_1.TypeSystemPolicy.IsObjectLike(value))
|
|
2823
|
+
return false;
|
|
2824
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
2825
|
+
return false;
|
|
2826
|
+
}
|
|
2827
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
2831
|
+
for (const knownKey of knownKeys) {
|
|
2832
|
+
const property = schema.properties[knownKey];
|
|
2833
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
2834
|
+
if (!Visit(property, references, value[knownKey])) {
|
|
2835
|
+
return false;
|
|
2836
|
+
}
|
|
2837
|
+
if ((Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property)) && !(knownKey in value)) {
|
|
2838
|
+
return false;
|
|
2839
|
+
}
|
|
2840
|
+
} else {
|
|
2841
|
+
if (index_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey) && !Visit(property, references, value[knownKey])) {
|
|
2842
|
+
return false;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
if (schema.additionalProperties === false) {
|
|
2847
|
+
const valueKeys = Object.getOwnPropertyNames(value);
|
|
2848
|
+
if (schema.required && schema.required.length === knownKeys.length && valueKeys.length === knownKeys.length) {
|
|
2849
|
+
return true;
|
|
2850
|
+
} else {
|
|
2851
|
+
return valueKeys.every((valueKey) => knownKeys.includes(valueKey));
|
|
2852
|
+
}
|
|
2853
|
+
} else if (typeof schema.additionalProperties === "object") {
|
|
2854
|
+
const valueKeys = Object.getOwnPropertyNames(value);
|
|
2855
|
+
return valueKeys.every((key) => knownKeys.includes(key) || Visit(schema.additionalProperties, references, value[key]));
|
|
2856
|
+
} else {
|
|
2857
|
+
return true;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
function TPromise(schema, references, value) {
|
|
2861
|
+
return (0, guard_1.IsPromise)(value);
|
|
2862
|
+
}
|
|
2863
|
+
function TRecord(schema, references, value) {
|
|
2864
|
+
if (!index_1.TypeSystemPolicy.IsRecordLike(value)) {
|
|
2865
|
+
return false;
|
|
2866
|
+
}
|
|
2867
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
2868
|
+
return false;
|
|
2869
|
+
}
|
|
2870
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
2871
|
+
return false;
|
|
2872
|
+
}
|
|
2873
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
2874
|
+
const regex = new RegExp(patternKey);
|
|
2875
|
+
const check1 = Object.entries(value).every(([key, value2]) => {
|
|
2876
|
+
return regex.test(key) ? Visit(patternSchema, references, value2) : true;
|
|
2877
|
+
});
|
|
2878
|
+
const check2 = typeof schema.additionalProperties === "object" ? Object.entries(value).every(([key, value2]) => {
|
|
2879
|
+
return !regex.test(key) ? Visit(schema.additionalProperties, references, value2) : true;
|
|
2880
|
+
}) : true;
|
|
2881
|
+
const check3 = schema.additionalProperties === false ? Object.getOwnPropertyNames(value).every((key) => {
|
|
2882
|
+
return regex.test(key);
|
|
2883
|
+
}) : true;
|
|
2884
|
+
return check1 && check2 && check3;
|
|
2885
|
+
}
|
|
2886
|
+
function TRef(schema, references, value) {
|
|
2887
|
+
return Visit((0, deref_1.Deref)(schema, references), references, value);
|
|
2888
|
+
}
|
|
2889
|
+
function TString(schema, references, value) {
|
|
2890
|
+
if (!(0, guard_1.IsString)(value)) {
|
|
2891
|
+
return false;
|
|
2892
|
+
}
|
|
2893
|
+
if (IsDefined(schema.minLength)) {
|
|
2894
|
+
if (!(value.length >= schema.minLength))
|
|
2895
|
+
return false;
|
|
2896
|
+
}
|
|
2897
|
+
if (IsDefined(schema.maxLength)) {
|
|
2898
|
+
if (!(value.length <= schema.maxLength))
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (IsDefined(schema.pattern)) {
|
|
2902
|
+
const regex = new RegExp(schema.pattern);
|
|
2903
|
+
if (!regex.test(value))
|
|
2904
|
+
return false;
|
|
2905
|
+
}
|
|
2906
|
+
if (IsDefined(schema.format)) {
|
|
2907
|
+
if (!Types.FormatRegistry.Has(schema.format))
|
|
2908
|
+
return false;
|
|
2909
|
+
const func = Types.FormatRegistry.Get(schema.format);
|
|
2910
|
+
return func(value);
|
|
2911
|
+
}
|
|
2912
|
+
return true;
|
|
2913
|
+
}
|
|
2914
|
+
function TSymbol(schema, references, value) {
|
|
2915
|
+
return (0, guard_1.IsSymbol)(value);
|
|
2916
|
+
}
|
|
2917
|
+
function TTemplateLiteral(schema, references, value) {
|
|
2918
|
+
return (0, guard_1.IsString)(value) && new RegExp(schema.pattern).test(value);
|
|
2919
|
+
}
|
|
2920
|
+
function TThis(schema, references, value) {
|
|
2921
|
+
return Visit((0, deref_1.Deref)(schema, references), references, value);
|
|
2922
|
+
}
|
|
2923
|
+
function TTuple(schema, references, value) {
|
|
2924
|
+
if (!(0, guard_1.IsArray)(value)) {
|
|
2925
|
+
return false;
|
|
2926
|
+
}
|
|
2927
|
+
if (schema.items === void 0 && !(value.length === 0)) {
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2930
|
+
if (!(value.length === schema.maxItems)) {
|
|
2931
|
+
return false;
|
|
2932
|
+
}
|
|
2933
|
+
if (!schema.items) {
|
|
2934
|
+
return true;
|
|
2935
|
+
}
|
|
2936
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
2937
|
+
if (!Visit(schema.items[i], references, value[i]))
|
|
2938
|
+
return false;
|
|
2939
|
+
}
|
|
2940
|
+
return true;
|
|
2941
|
+
}
|
|
2942
|
+
function TUndefined(schema, references, value) {
|
|
2943
|
+
return (0, guard_1.IsUndefined)(value);
|
|
2944
|
+
}
|
|
2945
|
+
function TUnion(schema, references, value) {
|
|
2946
|
+
return schema.anyOf.some((inner) => Visit(inner, references, value));
|
|
2947
|
+
}
|
|
2948
|
+
function TUint8Array(schema, references, value) {
|
|
2949
|
+
if (!(0, guard_1.IsUint8Array)(value)) {
|
|
2950
|
+
return false;
|
|
2951
|
+
}
|
|
2952
|
+
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
2953
|
+
return false;
|
|
2954
|
+
}
|
|
2955
|
+
if (IsDefined(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
2956
|
+
return false;
|
|
2957
|
+
}
|
|
2958
|
+
return true;
|
|
2959
|
+
}
|
|
2960
|
+
function TUnknown(schema, references, value) {
|
|
2961
|
+
return true;
|
|
2962
|
+
}
|
|
2963
|
+
function TVoid(schema, references, value) {
|
|
2964
|
+
return index_1.TypeSystemPolicy.IsVoidLike(value);
|
|
2965
|
+
}
|
|
2966
|
+
function TKind(schema, references, value) {
|
|
2967
|
+
if (!Types.TypeRegistry.Has(schema[Types.Kind]))
|
|
2968
|
+
return false;
|
|
2969
|
+
const func = Types.TypeRegistry.Get(schema[Types.Kind]);
|
|
2970
|
+
return func(schema, value);
|
|
2971
|
+
}
|
|
2972
|
+
function Visit(schema, references, value) {
|
|
2973
|
+
const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
|
|
2974
|
+
const schema_ = schema;
|
|
2975
|
+
switch (schema_[Types.Kind]) {
|
|
2976
|
+
case "Any":
|
|
2977
|
+
return TAny(schema_, references_, value);
|
|
2978
|
+
case "Array":
|
|
2979
|
+
return TArray(schema_, references_, value);
|
|
2980
|
+
case "AsyncIterator":
|
|
2981
|
+
return TAsyncIterator(schema_, references_, value);
|
|
2982
|
+
case "BigInt":
|
|
2983
|
+
return TBigInt(schema_, references_, value);
|
|
2984
|
+
case "Boolean":
|
|
2985
|
+
return TBoolean(schema_, references_, value);
|
|
2986
|
+
case "Constructor":
|
|
2987
|
+
return TConstructor(schema_, references_, value);
|
|
2988
|
+
case "Date":
|
|
2989
|
+
return TDate(schema_, references_, value);
|
|
2990
|
+
case "Function":
|
|
2991
|
+
return TFunction(schema_, references_, value);
|
|
2992
|
+
case "Integer":
|
|
2993
|
+
return TInteger(schema_, references_, value);
|
|
2994
|
+
case "Intersect":
|
|
2995
|
+
return TIntersect(schema_, references_, value);
|
|
2996
|
+
case "Iterator":
|
|
2997
|
+
return TIterator(schema_, references_, value);
|
|
2998
|
+
case "Literal":
|
|
2999
|
+
return TLiteral(schema_, references_, value);
|
|
3000
|
+
case "Never":
|
|
3001
|
+
return TNever(schema_, references_, value);
|
|
3002
|
+
case "Not":
|
|
3003
|
+
return TNot(schema_, references_, value);
|
|
3004
|
+
case "Null":
|
|
3005
|
+
return TNull(schema_, references_, value);
|
|
3006
|
+
case "Number":
|
|
3007
|
+
return TNumber(schema_, references_, value);
|
|
3008
|
+
case "Object":
|
|
3009
|
+
return TObject(schema_, references_, value);
|
|
3010
|
+
case "Promise":
|
|
3011
|
+
return TPromise(schema_, references_, value);
|
|
3012
|
+
case "Record":
|
|
3013
|
+
return TRecord(schema_, references_, value);
|
|
3014
|
+
case "Ref":
|
|
3015
|
+
return TRef(schema_, references_, value);
|
|
3016
|
+
case "String":
|
|
3017
|
+
return TString(schema_, references_, value);
|
|
3018
|
+
case "Symbol":
|
|
3019
|
+
return TSymbol(schema_, references_, value);
|
|
3020
|
+
case "TemplateLiteral":
|
|
3021
|
+
return TTemplateLiteral(schema_, references_, value);
|
|
3022
|
+
case "This":
|
|
3023
|
+
return TThis(schema_, references_, value);
|
|
3024
|
+
case "Tuple":
|
|
3025
|
+
return TTuple(schema_, references_, value);
|
|
3026
|
+
case "Undefined":
|
|
3027
|
+
return TUndefined(schema_, references_, value);
|
|
3028
|
+
case "Union":
|
|
3029
|
+
return TUnion(schema_, references_, value);
|
|
3030
|
+
case "Uint8Array":
|
|
3031
|
+
return TUint8Array(schema_, references_, value);
|
|
3032
|
+
case "Unknown":
|
|
3033
|
+
return TUnknown(schema_, references_, value);
|
|
3034
|
+
case "Void":
|
|
3035
|
+
return TVoid(schema_, references_, value);
|
|
3036
|
+
default:
|
|
3037
|
+
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
3038
|
+
throw new ValueCheckUnknownTypeError(schema_);
|
|
3039
|
+
return TKind(schema_, references_, value);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
function Check(...args) {
|
|
3043
|
+
return args.length === 3 ? Visit(args[0], args[1], args[2]) : Visit(args[0], [], args[1]);
|
|
3044
|
+
}
|
|
3045
|
+
exports.Check = Check;
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
|
|
3049
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/transform.js
|
|
3050
|
+
var require_transform = __commonJS({
|
|
3051
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/value/transform.js"(exports) {
|
|
3052
|
+
"use strict";
|
|
3053
|
+
init_dirname();
|
|
3054
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3055
|
+
exports.EncodeTransform = exports.DecodeTransform = exports.HasTransform = exports.TransformEncodeError = exports.TransformDecodeError = exports.TransformEncodeCheckError = exports.TransformDecodeCheckError = void 0;
|
|
3056
|
+
var guard_1 = require_guard();
|
|
3057
|
+
var deref_1 = require_deref();
|
|
3058
|
+
var check_1 = require_check();
|
|
3059
|
+
var Types = require_typebox();
|
|
3060
|
+
var TransformDecodeCheckError = class extends Types.TypeBoxError {
|
|
3061
|
+
constructor(schema, value, error) {
|
|
3062
|
+
super(`Unable to decode due to invalid value`);
|
|
3063
|
+
this.schema = schema;
|
|
3064
|
+
this.value = value;
|
|
3065
|
+
this.error = error;
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
exports.TransformDecodeCheckError = TransformDecodeCheckError;
|
|
3069
|
+
var TransformEncodeCheckError = class extends Types.TypeBoxError {
|
|
3070
|
+
constructor(schema, value, error) {
|
|
3071
|
+
super(`Unable to encode due to invalid value`);
|
|
3072
|
+
this.schema = schema;
|
|
3073
|
+
this.value = value;
|
|
3074
|
+
this.error = error;
|
|
3075
|
+
}
|
|
3076
|
+
};
|
|
3077
|
+
exports.TransformEncodeCheckError = TransformEncodeCheckError;
|
|
3078
|
+
var TransformDecodeError = class extends Types.TypeBoxError {
|
|
3079
|
+
constructor(schema, value, error) {
|
|
3080
|
+
super(`${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3081
|
+
this.schema = schema;
|
|
3082
|
+
this.value = value;
|
|
3083
|
+
}
|
|
3084
|
+
};
|
|
3085
|
+
exports.TransformDecodeError = TransformDecodeError;
|
|
3086
|
+
var TransformEncodeError = class extends Types.TypeBoxError {
|
|
3087
|
+
constructor(schema, value, error) {
|
|
3088
|
+
super(`${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3089
|
+
this.schema = schema;
|
|
3090
|
+
this.value = value;
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
exports.TransformEncodeError = TransformEncodeError;
|
|
3094
|
+
var HasTransform;
|
|
3095
|
+
(function(HasTransform2) {
|
|
3096
|
+
function TArray(schema, references) {
|
|
3097
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
3098
|
+
}
|
|
3099
|
+
function TAsyncIterator(schema, references) {
|
|
3100
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
3101
|
+
}
|
|
3102
|
+
function TConstructor(schema, references) {
|
|
3103
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema2) => Visit(schema2, references));
|
|
3104
|
+
}
|
|
3105
|
+
function TFunction(schema, references) {
|
|
3106
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema2) => Visit(schema2, references));
|
|
3107
|
+
}
|
|
3108
|
+
function TIntersect(schema, references) {
|
|
3109
|
+
return Types.TypeGuard.TTransform(schema) || Types.TypeGuard.TTransform(schema.unevaluatedProperties) || schema.allOf.some((schema2) => Visit(schema2, references));
|
|
3110
|
+
}
|
|
3111
|
+
function TIterator(schema, references) {
|
|
3112
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
3113
|
+
}
|
|
3114
|
+
function TNot(schema, references) {
|
|
3115
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.not, references);
|
|
3116
|
+
}
|
|
3117
|
+
function TObject(schema, references) {
|
|
3118
|
+
return Types.TypeGuard.TTransform(schema) || Object.values(schema.properties).some((schema2) => Visit(schema2, references)) || Types.TypeGuard.TSchema(schema.additionalProperties) && Visit(schema.additionalProperties, references);
|
|
3119
|
+
}
|
|
3120
|
+
function TPromise(schema, references) {
|
|
3121
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.item, references);
|
|
3122
|
+
}
|
|
3123
|
+
function TRecord(schema, references) {
|
|
3124
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
3125
|
+
const property = schema.patternProperties[pattern];
|
|
3126
|
+
return Types.TypeGuard.TTransform(schema) || Visit(property, references) || Types.TypeGuard.TSchema(schema.additionalProperties) && Types.TypeGuard.TTransform(schema.additionalProperties);
|
|
3127
|
+
}
|
|
3128
|
+
function TRef(schema, references) {
|
|
3129
|
+
if (Types.TypeGuard.TTransform(schema))
|
|
3130
|
+
return true;
|
|
3131
|
+
return Visit((0, deref_1.Deref)(schema, references), references);
|
|
3132
|
+
}
|
|
3133
|
+
function TThis(schema, references) {
|
|
3134
|
+
if (Types.TypeGuard.TTransform(schema))
|
|
3135
|
+
return true;
|
|
3136
|
+
return Visit((0, deref_1.Deref)(schema, references), references);
|
|
3137
|
+
}
|
|
3138
|
+
function TTuple(schema, references) {
|
|
3139
|
+
return Types.TypeGuard.TTransform(schema) || !(0, guard_1.IsUndefined)(schema.items) && schema.items.some((schema2) => Visit(schema2, references));
|
|
3140
|
+
}
|
|
3141
|
+
function TUnion(schema, references) {
|
|
3142
|
+
return Types.TypeGuard.TTransform(schema) || schema.anyOf.some((schema2) => Visit(schema2, references));
|
|
3143
|
+
}
|
|
3144
|
+
function Visit(schema, references) {
|
|
3145
|
+
const references_ = (0, guard_1.IsString)(schema.$id) ? [...references, schema] : references;
|
|
3146
|
+
const schema_ = schema;
|
|
3147
|
+
if (schema.$id && visited.has(schema.$id))
|
|
3148
|
+
return false;
|
|
3149
|
+
if (schema.$id)
|
|
3150
|
+
visited.add(schema.$id);
|
|
3151
|
+
switch (schema[Types.Kind]) {
|
|
3152
|
+
case "Array":
|
|
3153
|
+
return TArray(schema_, references_);
|
|
3154
|
+
case "AsyncIterator":
|
|
3155
|
+
return TAsyncIterator(schema_, references_);
|
|
3156
|
+
case "Constructor":
|
|
3157
|
+
return TConstructor(schema_, references_);
|
|
3158
|
+
case "Function":
|
|
3159
|
+
return TFunction(schema_, references_);
|
|
3160
|
+
case "Intersect":
|
|
3161
|
+
return TIntersect(schema_, references_);
|
|
3162
|
+
case "Iterator":
|
|
3163
|
+
return TIterator(schema_, references_);
|
|
3164
|
+
case "Not":
|
|
3165
|
+
return TNot(schema_, references_);
|
|
3166
|
+
case "Object":
|
|
3167
|
+
return TObject(schema_, references_);
|
|
3168
|
+
case "Promise":
|
|
3169
|
+
return TPromise(schema_, references_);
|
|
3170
|
+
case "Record":
|
|
3171
|
+
return TRecord(schema_, references_);
|
|
3172
|
+
case "Ref":
|
|
3173
|
+
return TRef(schema_, references_);
|
|
3174
|
+
case "This":
|
|
3175
|
+
return TThis(schema_, references_);
|
|
3176
|
+
case "Tuple":
|
|
3177
|
+
return TTuple(schema_, references_);
|
|
3178
|
+
case "Union":
|
|
3179
|
+
return TUnion(schema_, references_);
|
|
3180
|
+
default:
|
|
3181
|
+
return Types.TypeGuard.TTransform(schema);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3185
|
+
function Has(schema, references) {
|
|
3186
|
+
visited.clear();
|
|
3187
|
+
return Visit(schema, references);
|
|
3188
|
+
}
|
|
3189
|
+
HasTransform2.Has = Has;
|
|
3190
|
+
})(HasTransform || (exports.HasTransform = HasTransform = {}));
|
|
3191
|
+
var DecodeTransform;
|
|
3192
|
+
(function(DecodeTransform2) {
|
|
3193
|
+
function Default(schema, value) {
|
|
3194
|
+
try {
|
|
3195
|
+
return Types.TypeGuard.TTransform(schema) ? schema[Types.Transform].Decode(value) : value;
|
|
3196
|
+
} catch (error) {
|
|
3197
|
+
throw new TransformDecodeError(schema, value, error);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
function TArray(schema, references, value) {
|
|
3201
|
+
return (0, guard_1.IsArray)(value) ? Default(schema, value.map((value2) => Visit(schema.items, references, value2))) : Default(schema, value);
|
|
3202
|
+
}
|
|
3203
|
+
function TIntersect(schema, references, value) {
|
|
3204
|
+
if (!(0, guard_1.IsPlainObject)(value) || (0, guard_1.IsValueType)(value))
|
|
3205
|
+
return Default(schema, value);
|
|
3206
|
+
const knownKeys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
3207
|
+
const knownProperties = knownKeys.reduce((value2, key) => {
|
|
3208
|
+
return key in value2 ? { ...value2, [key]: Visit(Types.IndexedAccessor.Resolve(schema, [key]), references, value2[key]) } : value2;
|
|
3209
|
+
}, value);
|
|
3210
|
+
if (!Types.TypeGuard.TTransform(schema.unevaluatedProperties)) {
|
|
3211
|
+
return Default(schema, knownProperties);
|
|
3212
|
+
}
|
|
3213
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3214
|
+
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
3215
|
+
const unknownProperties = unknownKeys.reduce((value2, key) => {
|
|
3216
|
+
return !knownKeys.includes(key) ? { ...value2, [key]: Default(unevaluatedProperties, value2[key]) } : value2;
|
|
3217
|
+
}, knownProperties);
|
|
3218
|
+
return Default(schema, unknownProperties);
|
|
3219
|
+
}
|
|
3220
|
+
function TNot(schema, references, value) {
|
|
3221
|
+
return Default(schema, Visit(schema.not, references, value));
|
|
3222
|
+
}
|
|
3223
|
+
function TObject(schema, references, value) {
|
|
3224
|
+
if (!(0, guard_1.IsPlainObject)(value))
|
|
3225
|
+
return Default(schema, value);
|
|
3226
|
+
const knownKeys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
3227
|
+
const knownProperties = knownKeys.reduce((value2, key) => {
|
|
3228
|
+
return key in value2 ? { ...value2, [key]: Visit(schema.properties[key], references, value2[key]) } : value2;
|
|
3229
|
+
}, value);
|
|
3230
|
+
if (!Types.TypeGuard.TSchema(schema.additionalProperties)) {
|
|
3231
|
+
return Default(schema, knownProperties);
|
|
3232
|
+
}
|
|
3233
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3234
|
+
const additionalProperties = schema.additionalProperties;
|
|
3235
|
+
const unknownProperties = unknownKeys.reduce((value2, key) => {
|
|
3236
|
+
return !knownKeys.includes(key) ? { ...value2, [key]: Default(additionalProperties, value2[key]) } : value2;
|
|
3237
|
+
}, knownProperties);
|
|
3238
|
+
return Default(schema, unknownProperties);
|
|
3239
|
+
}
|
|
3240
|
+
function TRecord(schema, references, value) {
|
|
3241
|
+
if (!(0, guard_1.IsPlainObject)(value))
|
|
3242
|
+
return Default(schema, value);
|
|
3243
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
3244
|
+
const knownKeys = new RegExp(pattern);
|
|
3245
|
+
const knownProperties = Object.getOwnPropertyNames(value).reduce((value2, key) => {
|
|
3246
|
+
return knownKeys.test(key) ? { ...value2, [key]: Visit(schema.patternProperties[pattern], references, value2[key]) } : value2;
|
|
3247
|
+
}, value);
|
|
3248
|
+
if (!Types.TypeGuard.TSchema(schema.additionalProperties)) {
|
|
3249
|
+
return Default(schema, knownProperties);
|
|
3250
|
+
}
|
|
3251
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3252
|
+
const additionalProperties = schema.additionalProperties;
|
|
3253
|
+
const unknownProperties = unknownKeys.reduce((value2, key) => {
|
|
3254
|
+
return !knownKeys.test(key) ? { ...value2, [key]: Default(additionalProperties, value2[key]) } : value2;
|
|
3255
|
+
}, knownProperties);
|
|
3256
|
+
return Default(schema, unknownProperties);
|
|
3257
|
+
}
|
|
3258
|
+
function TRef(schema, references, value) {
|
|
3259
|
+
const target = (0, deref_1.Deref)(schema, references);
|
|
3260
|
+
return Default(schema, Visit(target, references, value));
|
|
3261
|
+
}
|
|
3262
|
+
function TThis(schema, references, value) {
|
|
3263
|
+
const target = (0, deref_1.Deref)(schema, references);
|
|
3264
|
+
return Default(schema, Visit(target, references, value));
|
|
3265
|
+
}
|
|
3266
|
+
function TTuple(schema, references, value) {
|
|
3267
|
+
return (0, guard_1.IsArray)(value) && (0, guard_1.IsArray)(schema.items) ? Default(schema, schema.items.map((schema2, index) => Visit(schema2, references, value[index]))) : Default(schema, value);
|
|
3268
|
+
}
|
|
3269
|
+
function TUnion(schema, references, value) {
|
|
3270
|
+
const defaulted = Default(schema, value);
|
|
3271
|
+
for (const subschema of schema.anyOf) {
|
|
3272
|
+
if (!(0, check_1.Check)(subschema, references, defaulted))
|
|
3273
|
+
continue;
|
|
3274
|
+
return Visit(subschema, references, defaulted);
|
|
3275
|
+
}
|
|
3276
|
+
return defaulted;
|
|
3277
|
+
}
|
|
3278
|
+
function Visit(schema, references, value) {
|
|
3279
|
+
const references_ = typeof schema.$id === "string" ? [...references, schema] : references;
|
|
3280
|
+
const schema_ = schema;
|
|
3281
|
+
switch (schema[Types.Kind]) {
|
|
3282
|
+
case "Array":
|
|
3283
|
+
return TArray(schema_, references_, value);
|
|
3284
|
+
case "Intersect":
|
|
3285
|
+
return TIntersect(schema_, references_, value);
|
|
3286
|
+
case "Not":
|
|
3287
|
+
return TNot(schema_, references_, value);
|
|
3288
|
+
case "Object":
|
|
3289
|
+
return TObject(schema_, references_, value);
|
|
3290
|
+
case "Record":
|
|
3291
|
+
return TRecord(schema_, references_, value);
|
|
3292
|
+
case "Ref":
|
|
3293
|
+
return TRef(schema_, references_, value);
|
|
3294
|
+
case "Symbol":
|
|
3295
|
+
return Default(schema_, value);
|
|
3296
|
+
case "This":
|
|
3297
|
+
return TThis(schema_, references_, value);
|
|
3298
|
+
case "Tuple":
|
|
3299
|
+
return TTuple(schema_, references_, value);
|
|
3300
|
+
case "Union":
|
|
3301
|
+
return TUnion(schema_, references_, value);
|
|
3302
|
+
default:
|
|
3303
|
+
return Default(schema_, value);
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
function Decode(schema, references, value) {
|
|
3307
|
+
return Visit(schema, references, value);
|
|
3308
|
+
}
|
|
3309
|
+
DecodeTransform2.Decode = Decode;
|
|
3310
|
+
})(DecodeTransform || (exports.DecodeTransform = DecodeTransform = {}));
|
|
3311
|
+
var EncodeTransform;
|
|
3312
|
+
(function(EncodeTransform2) {
|
|
3313
|
+
function Default(schema, value) {
|
|
3314
|
+
try {
|
|
3315
|
+
return Types.TypeGuard.TTransform(schema) ? schema[Types.Transform].Encode(value) : value;
|
|
3316
|
+
} catch (error) {
|
|
3317
|
+
throw new TransformEncodeError(schema, value, error);
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
function TArray(schema, references, value) {
|
|
3321
|
+
const defaulted = Default(schema, value);
|
|
3322
|
+
return (0, guard_1.IsArray)(defaulted) ? defaulted.map((value2) => Visit(schema.items, references, value2)) : defaulted;
|
|
3323
|
+
}
|
|
3324
|
+
function TIntersect(schema, references, value) {
|
|
3325
|
+
const defaulted = Default(schema, value);
|
|
3326
|
+
if (!(0, guard_1.IsPlainObject)(value) || (0, guard_1.IsValueType)(value))
|
|
3327
|
+
return defaulted;
|
|
3328
|
+
const knownKeys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
3329
|
+
const knownProperties = knownKeys.reduce((value2, key) => {
|
|
3330
|
+
return key in defaulted ? { ...value2, [key]: Visit(Types.IndexedAccessor.Resolve(schema, [key]), references, value2[key]) } : value2;
|
|
3331
|
+
}, defaulted);
|
|
3332
|
+
if (!Types.TypeGuard.TTransform(schema.unevaluatedProperties)) {
|
|
3333
|
+
return Default(schema, knownProperties);
|
|
3334
|
+
}
|
|
3335
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3336
|
+
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
3337
|
+
return unknownKeys.reduce((value2, key) => {
|
|
3338
|
+
return !knownKeys.includes(key) ? { ...value2, [key]: Default(unevaluatedProperties, value2[key]) } : value2;
|
|
3339
|
+
}, knownProperties);
|
|
3340
|
+
}
|
|
3341
|
+
function TNot(schema, references, value) {
|
|
3342
|
+
return Default(schema.not, Default(schema, value));
|
|
3343
|
+
}
|
|
3344
|
+
function TObject(schema, references, value) {
|
|
3345
|
+
const defaulted = Default(schema, value);
|
|
3346
|
+
if (!(0, guard_1.IsPlainObject)(value))
|
|
3347
|
+
return defaulted;
|
|
3348
|
+
const knownKeys = Types.KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
3349
|
+
const knownProperties = knownKeys.reduce((value2, key) => {
|
|
3350
|
+
return key in value2 ? { ...value2, [key]: Visit(schema.properties[key], references, value2[key]) } : value2;
|
|
3351
|
+
}, defaulted);
|
|
3352
|
+
if (!Types.TypeGuard.TSchema(schema.additionalProperties)) {
|
|
3353
|
+
return knownProperties;
|
|
3354
|
+
}
|
|
3355
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3356
|
+
const additionalProperties = schema.additionalProperties;
|
|
3357
|
+
return unknownKeys.reduce((value2, key) => {
|
|
3358
|
+
return !knownKeys.includes(key) ? { ...value2, [key]: Default(additionalProperties, value2[key]) } : value2;
|
|
3359
|
+
}, knownProperties);
|
|
3360
|
+
}
|
|
3361
|
+
function TRecord(schema, references, value) {
|
|
3362
|
+
const defaulted = Default(schema, value);
|
|
3363
|
+
if (!(0, guard_1.IsPlainObject)(value))
|
|
3364
|
+
return defaulted;
|
|
3365
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
3366
|
+
const knownKeys = new RegExp(pattern);
|
|
3367
|
+
const knownProperties = Object.getOwnPropertyNames(value).reduce((value2, key) => {
|
|
3368
|
+
return knownKeys.test(key) ? { ...value2, [key]: Visit(schema.patternProperties[pattern], references, value2[key]) } : value2;
|
|
3369
|
+
}, defaulted);
|
|
3370
|
+
if (!Types.TypeGuard.TSchema(schema.additionalProperties)) {
|
|
3371
|
+
return Default(schema, knownProperties);
|
|
3372
|
+
}
|
|
3373
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3374
|
+
const additionalProperties = schema.additionalProperties;
|
|
3375
|
+
return unknownKeys.reduce((value2, key) => {
|
|
3376
|
+
return !knownKeys.test(key) ? { ...value2, [key]: Default(additionalProperties, value2[key]) } : value2;
|
|
3377
|
+
}, knownProperties);
|
|
3378
|
+
}
|
|
3379
|
+
function TRef(schema, references, value) {
|
|
3380
|
+
const target = (0, deref_1.Deref)(schema, references);
|
|
3381
|
+
const resolved = Visit(target, references, value);
|
|
3382
|
+
return Default(schema, resolved);
|
|
3383
|
+
}
|
|
3384
|
+
function TThis(schema, references, value) {
|
|
3385
|
+
const target = (0, deref_1.Deref)(schema, references);
|
|
3386
|
+
const resolved = Visit(target, references, value);
|
|
3387
|
+
return Default(schema, resolved);
|
|
3388
|
+
}
|
|
3389
|
+
function TTuple(schema, references, value) {
|
|
3390
|
+
const value1 = Default(schema, value);
|
|
3391
|
+
return (0, guard_1.IsArray)(schema.items) ? schema.items.map((schema2, index) => Visit(schema2, references, value1[index])) : [];
|
|
3392
|
+
}
|
|
3393
|
+
function TUnion(schema, references, value) {
|
|
3394
|
+
for (const subschema of schema.anyOf) {
|
|
3395
|
+
if (!(0, check_1.Check)(subschema, references, value))
|
|
3396
|
+
continue;
|
|
3397
|
+
const value1 = Visit(subschema, references, value);
|
|
3398
|
+
return Default(schema, value1);
|
|
3399
|
+
}
|
|
3400
|
+
for (const subschema of schema.anyOf) {
|
|
3401
|
+
const value1 = Visit(subschema, references, value);
|
|
3402
|
+
if (!(0, check_1.Check)(schema, references, value1))
|
|
3403
|
+
continue;
|
|
3404
|
+
return Default(schema, value1);
|
|
3405
|
+
}
|
|
3406
|
+
return Default(schema, value);
|
|
3407
|
+
}
|
|
3408
|
+
function Visit(schema, references, value) {
|
|
3409
|
+
const references_ = typeof schema.$id === "string" ? [...references, schema] : references;
|
|
3410
|
+
const schema_ = schema;
|
|
3411
|
+
switch (schema[Types.Kind]) {
|
|
3412
|
+
case "Array":
|
|
3413
|
+
return TArray(schema_, references_, value);
|
|
3414
|
+
case "Intersect":
|
|
3415
|
+
return TIntersect(schema_, references_, value);
|
|
3416
|
+
case "Not":
|
|
3417
|
+
return TNot(schema_, references_, value);
|
|
3418
|
+
case "Object":
|
|
3419
|
+
return TObject(schema_, references_, value);
|
|
3420
|
+
case "Record":
|
|
3421
|
+
return TRecord(schema_, references_, value);
|
|
3422
|
+
case "Ref":
|
|
3423
|
+
return TRef(schema_, references_, value);
|
|
3424
|
+
case "This":
|
|
3425
|
+
return TThis(schema_, references_, value);
|
|
3426
|
+
case "Tuple":
|
|
3427
|
+
return TTuple(schema_, references_, value);
|
|
3428
|
+
case "Union":
|
|
3429
|
+
return TUnion(schema_, references_, value);
|
|
3430
|
+
default:
|
|
3431
|
+
return Default(schema_, value);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
function Encode(schema, references, value) {
|
|
3435
|
+
return Visit(schema, references, value);
|
|
3436
|
+
}
|
|
3437
|
+
EncodeTransform2.Encode = Encode;
|
|
3438
|
+
})(EncodeTransform || (exports.EncodeTransform = EncodeTransform = {}));
|
|
3439
|
+
}
|
|
3440
|
+
});
|
|
3441
|
+
|
|
3442
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/compiler/compiler.js
|
|
3443
|
+
var require_compiler = __commonJS({
|
|
3444
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/compiler/compiler.js"(exports) {
|
|
3445
|
+
"use strict";
|
|
3446
|
+
init_dirname();
|
|
3447
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3448
|
+
exports.TypeCompiler = exports.Policy = exports.TypeCompilerTypeGuardError = exports.TypeCompilerUnknownTypeError = exports.TypeCheck = void 0;
|
|
3449
|
+
var transform_1 = require_transform();
|
|
3450
|
+
var guard_1 = require_guard();
|
|
3451
|
+
var errors_1 = require_errors();
|
|
3452
|
+
var index_1 = require_system2();
|
|
3453
|
+
var deref_1 = require_deref();
|
|
3454
|
+
var hash_1 = require_hash();
|
|
3455
|
+
var Types = require_typebox();
|
|
3456
|
+
var TypeCheck = class {
|
|
3457
|
+
constructor(schema, references, checkFunc, code) {
|
|
3458
|
+
this.schema = schema;
|
|
3459
|
+
this.references = references;
|
|
3460
|
+
this.checkFunc = checkFunc;
|
|
3461
|
+
this.code = code;
|
|
3462
|
+
this.hasTransform = transform_1.HasTransform.Has(schema, references);
|
|
3463
|
+
}
|
|
3464
|
+
/** Returns the generated assertion code used to validate this type. */
|
|
3465
|
+
Code() {
|
|
3466
|
+
return this.code;
|
|
3467
|
+
}
|
|
3468
|
+
/** Returns an iterator for each error in this value. */
|
|
3469
|
+
Errors(value) {
|
|
3470
|
+
return (0, errors_1.Errors)(this.schema, this.references, value);
|
|
3471
|
+
}
|
|
3472
|
+
/** Returns true if the value matches the compiled type. */
|
|
3473
|
+
Check(value) {
|
|
3474
|
+
return this.checkFunc(value);
|
|
3475
|
+
}
|
|
3476
|
+
/** Decodes a value or throws if error */
|
|
3477
|
+
Decode(value) {
|
|
3478
|
+
if (!this.checkFunc(value))
|
|
3479
|
+
throw new transform_1.TransformDecodeCheckError(this.schema, value, this.Errors(value).First());
|
|
3480
|
+
return this.hasTransform ? transform_1.DecodeTransform.Decode(this.schema, this.references, value) : value;
|
|
3481
|
+
}
|
|
3482
|
+
/** Encodes a value or throws if error */
|
|
3483
|
+
Encode(value) {
|
|
3484
|
+
const encoded = this.hasTransform ? transform_1.EncodeTransform.Encode(this.schema, this.references, value) : value;
|
|
3485
|
+
if (!this.checkFunc(encoded))
|
|
3486
|
+
throw new transform_1.TransformEncodeCheckError(this.schema, value, this.Errors(value).First());
|
|
3487
|
+
return encoded;
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3490
|
+
exports.TypeCheck = TypeCheck;
|
|
3491
|
+
var Character;
|
|
3492
|
+
(function(Character2) {
|
|
3493
|
+
function DollarSign(code) {
|
|
3494
|
+
return code === 36;
|
|
3495
|
+
}
|
|
3496
|
+
Character2.DollarSign = DollarSign;
|
|
3497
|
+
function IsUnderscore(code) {
|
|
3498
|
+
return code === 95;
|
|
3499
|
+
}
|
|
3500
|
+
Character2.IsUnderscore = IsUnderscore;
|
|
3501
|
+
function IsAlpha(code) {
|
|
3502
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
3503
|
+
}
|
|
3504
|
+
Character2.IsAlpha = IsAlpha;
|
|
3505
|
+
function IsNumeric(code) {
|
|
3506
|
+
return code >= 48 && code <= 57;
|
|
3507
|
+
}
|
|
3508
|
+
Character2.IsNumeric = IsNumeric;
|
|
3509
|
+
})(Character || (Character = {}));
|
|
3510
|
+
var MemberExpression;
|
|
3511
|
+
(function(MemberExpression2) {
|
|
3512
|
+
function IsFirstCharacterNumeric(value) {
|
|
3513
|
+
if (value.length === 0)
|
|
3514
|
+
return false;
|
|
3515
|
+
return Character.IsNumeric(value.charCodeAt(0));
|
|
3516
|
+
}
|
|
3517
|
+
function IsAccessor(value) {
|
|
3518
|
+
if (IsFirstCharacterNumeric(value))
|
|
3519
|
+
return false;
|
|
3520
|
+
for (let i = 0; i < value.length; i++) {
|
|
3521
|
+
const code = value.charCodeAt(i);
|
|
3522
|
+
const check = Character.IsAlpha(code) || Character.IsNumeric(code) || Character.DollarSign(code) || Character.IsUnderscore(code);
|
|
3523
|
+
if (!check)
|
|
3524
|
+
return false;
|
|
3525
|
+
}
|
|
3526
|
+
return true;
|
|
3527
|
+
}
|
|
3528
|
+
function EscapeHyphen(key) {
|
|
3529
|
+
return key.replace(/'/g, "\\'");
|
|
3530
|
+
}
|
|
3531
|
+
function Encode(object, key) {
|
|
3532
|
+
return IsAccessor(key) ? `${object}.${key}` : `${object}['${EscapeHyphen(key)}']`;
|
|
3533
|
+
}
|
|
3534
|
+
MemberExpression2.Encode = Encode;
|
|
3535
|
+
})(MemberExpression || (MemberExpression = {}));
|
|
3536
|
+
var Identifier;
|
|
3537
|
+
(function(Identifier2) {
|
|
3538
|
+
function Encode($id) {
|
|
3539
|
+
const buffer = [];
|
|
3540
|
+
for (let i = 0; i < $id.length; i++) {
|
|
3541
|
+
const code = $id.charCodeAt(i);
|
|
3542
|
+
if (Character.IsNumeric(code) || Character.IsAlpha(code)) {
|
|
3543
|
+
buffer.push($id.charAt(i));
|
|
3544
|
+
} else {
|
|
3545
|
+
buffer.push(`_${code}_`);
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
return buffer.join("").replace(/__/g, "_");
|
|
3549
|
+
}
|
|
3550
|
+
Identifier2.Encode = Encode;
|
|
3551
|
+
})(Identifier || (Identifier = {}));
|
|
3552
|
+
var LiteralString;
|
|
3553
|
+
(function(LiteralString2) {
|
|
3554
|
+
function Escape(content) {
|
|
3555
|
+
return content.replace(/'/g, "\\'");
|
|
3556
|
+
}
|
|
3557
|
+
LiteralString2.Escape = Escape;
|
|
3558
|
+
})(LiteralString || (LiteralString = {}));
|
|
3559
|
+
var TypeCompilerUnknownTypeError = class extends Types.TypeBoxError {
|
|
3560
|
+
constructor(schema) {
|
|
3561
|
+
super("Unknown type");
|
|
3562
|
+
this.schema = schema;
|
|
3563
|
+
}
|
|
3564
|
+
};
|
|
3565
|
+
exports.TypeCompilerUnknownTypeError = TypeCompilerUnknownTypeError;
|
|
3566
|
+
var TypeCompilerTypeGuardError = class extends Types.TypeBoxError {
|
|
3567
|
+
constructor(schema) {
|
|
3568
|
+
super("Preflight validation check failed to guard for the given schema");
|
|
3569
|
+
this.schema = schema;
|
|
3570
|
+
}
|
|
3571
|
+
};
|
|
3572
|
+
exports.TypeCompilerTypeGuardError = TypeCompilerTypeGuardError;
|
|
3573
|
+
var Policy;
|
|
3574
|
+
(function(Policy2) {
|
|
3575
|
+
function IsExactOptionalProperty(value, key, expression) {
|
|
3576
|
+
return index_1.TypeSystemPolicy.ExactOptionalPropertyTypes ? `('${key}' in ${value} ? ${expression} : true)` : `(${MemberExpression.Encode(value, key)} !== undefined ? ${expression} : true)`;
|
|
3577
|
+
}
|
|
3578
|
+
Policy2.IsExactOptionalProperty = IsExactOptionalProperty;
|
|
3579
|
+
function IsObjectLike(value) {
|
|
3580
|
+
return !index_1.TypeSystemPolicy.AllowArrayObject ? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))` : `(typeof ${value} === 'object' && ${value} !== null)`;
|
|
3581
|
+
}
|
|
3582
|
+
Policy2.IsObjectLike = IsObjectLike;
|
|
3583
|
+
function IsRecordLike(value) {
|
|
3584
|
+
return !index_1.TypeSystemPolicy.AllowArrayObject ? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}) && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))` : `(typeof ${value} === 'object' && ${value} !== null && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))`;
|
|
3585
|
+
}
|
|
3586
|
+
Policy2.IsRecordLike = IsRecordLike;
|
|
3587
|
+
function IsNumberLike(value) {
|
|
3588
|
+
return !index_1.TypeSystemPolicy.AllowNaN ? `(typeof ${value} === 'number' && Number.isFinite(${value}))` : `typeof ${value} === 'number'`;
|
|
3589
|
+
}
|
|
3590
|
+
Policy2.IsNumberLike = IsNumberLike;
|
|
3591
|
+
function IsVoidLike(value) {
|
|
3592
|
+
return index_1.TypeSystemPolicy.AllowNullVoid ? `(${value} === undefined || ${value} === null)` : `${value} === undefined`;
|
|
3593
|
+
}
|
|
3594
|
+
Policy2.IsVoidLike = IsVoidLike;
|
|
3595
|
+
})(Policy || (exports.Policy = Policy = {}));
|
|
3596
|
+
var TypeCompiler2;
|
|
3597
|
+
(function(TypeCompiler3) {
|
|
3598
|
+
function IsAnyOrUnknown(schema) {
|
|
3599
|
+
return schema[Types.Kind] === "Any" || schema[Types.Kind] === "Unknown";
|
|
3600
|
+
}
|
|
3601
|
+
function* TAny(schema, references, value) {
|
|
3602
|
+
yield "true";
|
|
3603
|
+
}
|
|
3604
|
+
function* TArray(schema, references, value) {
|
|
3605
|
+
yield `Array.isArray(${value})`;
|
|
3606
|
+
const [parameter, accumulator] = [CreateParameter("value", "any"), CreateParameter("acc", "number")];
|
|
3607
|
+
if ((0, guard_1.IsNumber)(schema.maxItems))
|
|
3608
|
+
yield `${value}.length <= ${schema.maxItems}`;
|
|
3609
|
+
if ((0, guard_1.IsNumber)(schema.minItems))
|
|
3610
|
+
yield `${value}.length >= ${schema.minItems}`;
|
|
3611
|
+
const elementExpression = CreateExpression(schema.items, references, "value");
|
|
3612
|
+
yield `${value}.every((${parameter}) => ${elementExpression})`;
|
|
3613
|
+
if (Types.TypeGuard.TSchema(schema.contains) || (0, guard_1.IsNumber)(schema.minContains) || (0, guard_1.IsNumber)(schema.maxContains)) {
|
|
3614
|
+
const containsSchema = Types.TypeGuard.TSchema(schema.contains) ? schema.contains : Types.Type.Never();
|
|
3615
|
+
const checkExpression = CreateExpression(containsSchema, references, "value");
|
|
3616
|
+
const checkMinContains = (0, guard_1.IsNumber)(schema.minContains) ? [`(count >= ${schema.minContains})`] : [];
|
|
3617
|
+
const checkMaxContains = (0, guard_1.IsNumber)(schema.maxContains) ? [`(count <= ${schema.maxContains})`] : [];
|
|
3618
|
+
const checkCount = `const count = value.reduce((${accumulator}, ${parameter}) => ${checkExpression} ? acc + 1 : acc, 0)`;
|
|
3619
|
+
const check = [`(count > 0)`, ...checkMinContains, ...checkMaxContains].join(" && ");
|
|
3620
|
+
yield `((${parameter}) => { ${checkCount}; return ${check}})(${value})`;
|
|
3621
|
+
}
|
|
3622
|
+
if (schema.uniqueItems === true) {
|
|
3623
|
+
const check = `const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true`;
|
|
3624
|
+
const block = `const set = new Set(); for(const element of value) { ${check} }`;
|
|
3625
|
+
yield `((${parameter}) => { ${block} )(${value})`;
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
function* TAsyncIterator(schema, references, value) {
|
|
3629
|
+
yield `(typeof value === 'object' && Symbol.asyncIterator in ${value})`;
|
|
3630
|
+
}
|
|
3631
|
+
function* TBigInt(schema, references, value) {
|
|
3632
|
+
yield `(typeof ${value} === 'bigint')`;
|
|
3633
|
+
if ((0, guard_1.IsBigInt)(schema.exclusiveMaximum))
|
|
3634
|
+
yield `${value} < BigInt(${schema.exclusiveMaximum})`;
|
|
3635
|
+
if ((0, guard_1.IsBigInt)(schema.exclusiveMinimum))
|
|
3636
|
+
yield `${value} > BigInt(${schema.exclusiveMinimum})`;
|
|
3637
|
+
if ((0, guard_1.IsBigInt)(schema.maximum))
|
|
3638
|
+
yield `${value} <= BigInt(${schema.maximum})`;
|
|
3639
|
+
if ((0, guard_1.IsBigInt)(schema.minimum))
|
|
3640
|
+
yield `${value} >= BigInt(${schema.minimum})`;
|
|
3641
|
+
if ((0, guard_1.IsBigInt)(schema.multipleOf))
|
|
3642
|
+
yield `(${value} % BigInt(${schema.multipleOf})) === 0`;
|
|
3643
|
+
}
|
|
3644
|
+
function* TBoolean(schema, references, value) {
|
|
3645
|
+
yield `(typeof ${value} === 'boolean')`;
|
|
3646
|
+
}
|
|
3647
|
+
function* TConstructor(schema, references, value) {
|
|
3648
|
+
yield* Visit(schema.returns, references, `${value}.prototype`);
|
|
3649
|
+
}
|
|
3650
|
+
function* TDate(schema, references, value) {
|
|
3651
|
+
yield `(${value} instanceof Date) && Number.isFinite(${value}.getTime())`;
|
|
3652
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMaximumTimestamp))
|
|
3653
|
+
yield `${value}.getTime() < ${schema.exclusiveMaximumTimestamp}`;
|
|
3654
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMinimumTimestamp))
|
|
3655
|
+
yield `${value}.getTime() > ${schema.exclusiveMinimumTimestamp}`;
|
|
3656
|
+
if ((0, guard_1.IsNumber)(schema.maximumTimestamp))
|
|
3657
|
+
yield `${value}.getTime() <= ${schema.maximumTimestamp}`;
|
|
3658
|
+
if ((0, guard_1.IsNumber)(schema.minimumTimestamp))
|
|
3659
|
+
yield `${value}.getTime() >= ${schema.minimumTimestamp}`;
|
|
3660
|
+
if ((0, guard_1.IsNumber)(schema.multipleOfTimestamp))
|
|
3661
|
+
yield `(${value}.getTime() % ${schema.multipleOfTimestamp}) === 0`;
|
|
3662
|
+
}
|
|
3663
|
+
function* TFunction(schema, references, value) {
|
|
3664
|
+
yield `(typeof ${value} === 'function')`;
|
|
3665
|
+
}
|
|
3666
|
+
function* TInteger(schema, references, value) {
|
|
3667
|
+
yield `(typeof ${value} === 'number' && Number.isInteger(${value}))`;
|
|
3668
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMaximum))
|
|
3669
|
+
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
3670
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMinimum))
|
|
3671
|
+
yield `${value} > ${schema.exclusiveMinimum}`;
|
|
3672
|
+
if ((0, guard_1.IsNumber)(schema.maximum))
|
|
3673
|
+
yield `${value} <= ${schema.maximum}`;
|
|
3674
|
+
if ((0, guard_1.IsNumber)(schema.minimum))
|
|
3675
|
+
yield `${value} >= ${schema.minimum}`;
|
|
3676
|
+
if ((0, guard_1.IsNumber)(schema.multipleOf))
|
|
3677
|
+
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
3678
|
+
}
|
|
3679
|
+
function* TIntersect(schema, references, value) {
|
|
3680
|
+
const check1 = schema.allOf.map((schema2) => CreateExpression(schema2, references, value)).join(" && ");
|
|
3681
|
+
if (schema.unevaluatedProperties === false) {
|
|
3682
|
+
const keyCheck = CreateVariable(`${new RegExp(Types.KeyResolver.ResolvePattern(schema))};`);
|
|
3683
|
+
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key))`;
|
|
3684
|
+
yield `(${check1} && ${check2})`;
|
|
3685
|
+
} else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
|
|
3686
|
+
const keyCheck = CreateVariable(`${new RegExp(Types.KeyResolver.ResolvePattern(schema))};`);
|
|
3687
|
+
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
|
|
3688
|
+
yield `(${check1} && ${check2})`;
|
|
3689
|
+
} else {
|
|
3690
|
+
yield `(${check1})`;
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
function* TIterator(schema, references, value) {
|
|
3694
|
+
yield `(typeof value === 'object' && Symbol.iterator in ${value})`;
|
|
3695
|
+
}
|
|
3696
|
+
function* TLiteral(schema, references, value) {
|
|
3697
|
+
if (typeof schema.const === "number" || typeof schema.const === "boolean") {
|
|
3698
|
+
yield `(${value} === ${schema.const})`;
|
|
3699
|
+
} else {
|
|
3700
|
+
yield `(${value} === '${LiteralString.Escape(schema.const)}')`;
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
function* TNever(schema, references, value) {
|
|
3704
|
+
yield `false`;
|
|
3705
|
+
}
|
|
3706
|
+
function* TNot(schema, references, value) {
|
|
3707
|
+
const expression = CreateExpression(schema.not, references, value);
|
|
3708
|
+
yield `(!${expression})`;
|
|
3709
|
+
}
|
|
3710
|
+
function* TNull(schema, references, value) {
|
|
3711
|
+
yield `(${value} === null)`;
|
|
3712
|
+
}
|
|
3713
|
+
function* TNumber(schema, references, value) {
|
|
3714
|
+
yield Policy.IsNumberLike(value);
|
|
3715
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMaximum))
|
|
3716
|
+
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
3717
|
+
if ((0, guard_1.IsNumber)(schema.exclusiveMinimum))
|
|
3718
|
+
yield `${value} > ${schema.exclusiveMinimum}`;
|
|
3719
|
+
if ((0, guard_1.IsNumber)(schema.maximum))
|
|
3720
|
+
yield `${value} <= ${schema.maximum}`;
|
|
3721
|
+
if ((0, guard_1.IsNumber)(schema.minimum))
|
|
3722
|
+
yield `${value} >= ${schema.minimum}`;
|
|
3723
|
+
if ((0, guard_1.IsNumber)(schema.multipleOf))
|
|
3724
|
+
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
3725
|
+
}
|
|
3726
|
+
function* TObject(schema, references, value) {
|
|
3727
|
+
yield Policy.IsObjectLike(value);
|
|
3728
|
+
if ((0, guard_1.IsNumber)(schema.minProperties))
|
|
3729
|
+
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
3730
|
+
if ((0, guard_1.IsNumber)(schema.maxProperties))
|
|
3731
|
+
yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
|
|
3732
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
3733
|
+
for (const knownKey of knownKeys) {
|
|
3734
|
+
const memberExpression = MemberExpression.Encode(value, knownKey);
|
|
3735
|
+
const property = schema.properties[knownKey];
|
|
3736
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
3737
|
+
yield* Visit(property, references, memberExpression);
|
|
3738
|
+
if (Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property))
|
|
3739
|
+
yield `('${knownKey}' in ${value})`;
|
|
3740
|
+
} else {
|
|
3741
|
+
const expression = CreateExpression(property, references, memberExpression);
|
|
3742
|
+
yield Policy.IsExactOptionalProperty(value, knownKey, expression);
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
if (schema.additionalProperties === false) {
|
|
3746
|
+
if (schema.required && schema.required.length === knownKeys.length) {
|
|
3747
|
+
yield `Object.getOwnPropertyNames(${value}).length === ${knownKeys.length}`;
|
|
3748
|
+
} else {
|
|
3749
|
+
const keys = `[${knownKeys.map((key) => `'${key}'`).join(", ")}]`;
|
|
3750
|
+
yield `Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key))`;
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
if (typeof schema.additionalProperties === "object") {
|
|
3754
|
+
const expression = CreateExpression(schema.additionalProperties, references, `${value}[key]`);
|
|
3755
|
+
const keys = `[${knownKeys.map((key) => `'${key}'`).join(", ")}]`;
|
|
3756
|
+
yield `(Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key) || ${expression}))`;
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
function* TPromise(schema, references, value) {
|
|
3760
|
+
yield `(typeof value === 'object' && typeof ${value}.then === 'function')`;
|
|
3761
|
+
}
|
|
3762
|
+
function* TRecord(schema, references, value) {
|
|
3763
|
+
yield Policy.IsRecordLike(value);
|
|
3764
|
+
if ((0, guard_1.IsNumber)(schema.minProperties))
|
|
3765
|
+
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
3766
|
+
if ((0, guard_1.IsNumber)(schema.maxProperties))
|
|
3767
|
+
yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
|
|
3768
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
3769
|
+
const variable = CreateVariable(`${new RegExp(patternKey)}`);
|
|
3770
|
+
const check1 = CreateExpression(patternSchema, references, "value");
|
|
3771
|
+
const check2 = Types.TypeGuard.TSchema(schema.additionalProperties) ? CreateExpression(schema.additionalProperties, references, value) : schema.additionalProperties === false ? "false" : "true";
|
|
3772
|
+
const expression = `(${variable}.test(key) ? ${check1} : ${check2})`;
|
|
3773
|
+
yield `(Object.entries(${value}).every(([key, value]) => ${expression}))`;
|
|
3774
|
+
}
|
|
3775
|
+
function* TRef(schema, references, value) {
|
|
3776
|
+
const target = (0, deref_1.Deref)(schema, references);
|
|
3777
|
+
if (state.functions.has(schema.$ref))
|
|
3778
|
+
return yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
3779
|
+
yield* Visit(target, references, value);
|
|
3780
|
+
}
|
|
3781
|
+
function* TString(schema, references, value) {
|
|
3782
|
+
yield `(typeof ${value} === 'string')`;
|
|
3783
|
+
if ((0, guard_1.IsNumber)(schema.maxLength))
|
|
3784
|
+
yield `${value}.length <= ${schema.maxLength}`;
|
|
3785
|
+
if ((0, guard_1.IsNumber)(schema.minLength))
|
|
3786
|
+
yield `${value}.length >= ${schema.minLength}`;
|
|
3787
|
+
if (schema.pattern !== void 0) {
|
|
3788
|
+
const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
|
|
3789
|
+
yield `${variable}.test(${value})`;
|
|
3790
|
+
}
|
|
3791
|
+
if (schema.format !== void 0) {
|
|
3792
|
+
yield `format('${schema.format}', ${value})`;
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
function* TSymbol(schema, references, value) {
|
|
3796
|
+
yield `(typeof ${value} === 'symbol')`;
|
|
3797
|
+
}
|
|
3798
|
+
function* TTemplateLiteral(schema, references, value) {
|
|
3799
|
+
yield `(typeof ${value} === 'string')`;
|
|
3800
|
+
const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
|
|
3801
|
+
yield `${variable}.test(${value})`;
|
|
3802
|
+
}
|
|
3803
|
+
function* TThis(schema, references, value) {
|
|
3804
|
+
yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
3805
|
+
}
|
|
3806
|
+
function* TTuple(schema, references, value) {
|
|
3807
|
+
yield `Array.isArray(${value})`;
|
|
3808
|
+
if (schema.items === void 0)
|
|
3809
|
+
return yield `${value}.length === 0`;
|
|
3810
|
+
yield `(${value}.length === ${schema.maxItems})`;
|
|
3811
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
3812
|
+
const expression = CreateExpression(schema.items[i], references, `${value}[${i}]`);
|
|
3813
|
+
yield `${expression}`;
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
function* TUndefined(schema, references, value) {
|
|
3817
|
+
yield `${value} === undefined`;
|
|
3818
|
+
}
|
|
3819
|
+
function* TUnion(schema, references, value) {
|
|
3820
|
+
const expressions = schema.anyOf.map((schema2) => CreateExpression(schema2, references, value));
|
|
3821
|
+
yield `(${expressions.join(" || ")})`;
|
|
3822
|
+
}
|
|
3823
|
+
function* TUint8Array(schema, references, value) {
|
|
3824
|
+
yield `${value} instanceof Uint8Array`;
|
|
3825
|
+
if ((0, guard_1.IsNumber)(schema.maxByteLength))
|
|
3826
|
+
yield `(${value}.length <= ${schema.maxByteLength})`;
|
|
3827
|
+
if ((0, guard_1.IsNumber)(schema.minByteLength))
|
|
3828
|
+
yield `(${value}.length >= ${schema.minByteLength})`;
|
|
3829
|
+
}
|
|
3830
|
+
function* TUnknown(schema, references, value) {
|
|
3831
|
+
yield "true";
|
|
3832
|
+
}
|
|
3833
|
+
function* TVoid(schema, references, value) {
|
|
3834
|
+
yield Policy.IsVoidLike(value);
|
|
3835
|
+
}
|
|
3836
|
+
function* TKind(schema, references, value) {
|
|
3837
|
+
const instance = state.instances.size;
|
|
3838
|
+
state.instances.set(instance, schema);
|
|
3839
|
+
yield `kind('${schema[Types.Kind]}', ${instance}, ${value})`;
|
|
3840
|
+
}
|
|
3841
|
+
function* Visit(schema, references, value, useHoisting = true) {
|
|
3842
|
+
const references_ = (0, guard_1.IsString)(schema.$id) ? [...references, schema] : references;
|
|
3843
|
+
const schema_ = schema;
|
|
3844
|
+
if (useHoisting && (0, guard_1.IsString)(schema.$id)) {
|
|
3845
|
+
const functionName = CreateFunctionName(schema.$id);
|
|
3846
|
+
if (state.functions.has(functionName)) {
|
|
3847
|
+
return yield `${functionName}(${value})`;
|
|
3848
|
+
} else {
|
|
3849
|
+
const functionCode = CreateFunction(functionName, schema, references, "value", false);
|
|
3850
|
+
state.functions.set(functionName, functionCode);
|
|
3851
|
+
return yield `${functionName}(${value})`;
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
switch (schema_[Types.Kind]) {
|
|
3855
|
+
case "Any":
|
|
3856
|
+
return yield* TAny(schema_, references_, value);
|
|
3857
|
+
case "Array":
|
|
3858
|
+
return yield* TArray(schema_, references_, value);
|
|
3859
|
+
case "AsyncIterator":
|
|
3860
|
+
return yield* TAsyncIterator(schema_, references_, value);
|
|
3861
|
+
case "BigInt":
|
|
3862
|
+
return yield* TBigInt(schema_, references_, value);
|
|
3863
|
+
case "Boolean":
|
|
3864
|
+
return yield* TBoolean(schema_, references_, value);
|
|
3865
|
+
case "Constructor":
|
|
3866
|
+
return yield* TConstructor(schema_, references_, value);
|
|
3867
|
+
case "Date":
|
|
3868
|
+
return yield* TDate(schema_, references_, value);
|
|
3869
|
+
case "Function":
|
|
3870
|
+
return yield* TFunction(schema_, references_, value);
|
|
3871
|
+
case "Integer":
|
|
3872
|
+
return yield* TInteger(schema_, references_, value);
|
|
3873
|
+
case "Intersect":
|
|
3874
|
+
return yield* TIntersect(schema_, references_, value);
|
|
3875
|
+
case "Iterator":
|
|
3876
|
+
return yield* TIterator(schema_, references_, value);
|
|
3877
|
+
case "Literal":
|
|
3878
|
+
return yield* TLiteral(schema_, references_, value);
|
|
3879
|
+
case "Never":
|
|
3880
|
+
return yield* TNever(schema_, references_, value);
|
|
3881
|
+
case "Not":
|
|
3882
|
+
return yield* TNot(schema_, references_, value);
|
|
3883
|
+
case "Null":
|
|
3884
|
+
return yield* TNull(schema_, references_, value);
|
|
3885
|
+
case "Number":
|
|
3886
|
+
return yield* TNumber(schema_, references_, value);
|
|
3887
|
+
case "Object":
|
|
3888
|
+
return yield* TObject(schema_, references_, value);
|
|
3889
|
+
case "Promise":
|
|
3890
|
+
return yield* TPromise(schema_, references_, value);
|
|
3891
|
+
case "Record":
|
|
3892
|
+
return yield* TRecord(schema_, references_, value);
|
|
3893
|
+
case "Ref":
|
|
3894
|
+
return yield* TRef(schema_, references_, value);
|
|
3895
|
+
case "String":
|
|
3896
|
+
return yield* TString(schema_, references_, value);
|
|
3897
|
+
case "Symbol":
|
|
3898
|
+
return yield* TSymbol(schema_, references_, value);
|
|
3899
|
+
case "TemplateLiteral":
|
|
3900
|
+
return yield* TTemplateLiteral(schema_, references_, value);
|
|
3901
|
+
case "This":
|
|
3902
|
+
return yield* TThis(schema_, references_, value);
|
|
3903
|
+
case "Tuple":
|
|
3904
|
+
return yield* TTuple(schema_, references_, value);
|
|
3905
|
+
case "Undefined":
|
|
3906
|
+
return yield* TUndefined(schema_, references_, value);
|
|
3907
|
+
case "Union":
|
|
3908
|
+
return yield* TUnion(schema_, references_, value);
|
|
3909
|
+
case "Uint8Array":
|
|
3910
|
+
return yield* TUint8Array(schema_, references_, value);
|
|
3911
|
+
case "Unknown":
|
|
3912
|
+
return yield* TUnknown(schema_, references_, value);
|
|
3913
|
+
case "Void":
|
|
3914
|
+
return yield* TVoid(schema_, references_, value);
|
|
3915
|
+
default:
|
|
3916
|
+
if (!Types.TypeRegistry.Has(schema_[Types.Kind]))
|
|
3917
|
+
throw new TypeCompilerUnknownTypeError(schema);
|
|
3918
|
+
return yield* TKind(schema_, references_, value);
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
const state = {
|
|
3922
|
+
language: "javascript",
|
|
3923
|
+
functions: /* @__PURE__ */ new Map(),
|
|
3924
|
+
variables: /* @__PURE__ */ new Map(),
|
|
3925
|
+
instances: /* @__PURE__ */ new Map()
|
|
3926
|
+
// exterior kind instances
|
|
3927
|
+
};
|
|
3928
|
+
function CreateExpression(schema, references, value, useHoisting = true) {
|
|
3929
|
+
return `(${[...Visit(schema, references, value, useHoisting)].join(" && ")})`;
|
|
3930
|
+
}
|
|
3931
|
+
function CreateFunctionName($id) {
|
|
3932
|
+
return `check_${Identifier.Encode($id)}`;
|
|
3933
|
+
}
|
|
3934
|
+
function CreateVariable(expression) {
|
|
3935
|
+
const variableName = `local_${state.variables.size}`;
|
|
3936
|
+
state.variables.set(variableName, `const ${variableName} = ${expression}`);
|
|
3937
|
+
return variableName;
|
|
3938
|
+
}
|
|
3939
|
+
function CreateFunction(name, schema, references, value, useHoisting = true) {
|
|
3940
|
+
const [newline, pad] = ["\n", (length) => "".padStart(length, " ")];
|
|
3941
|
+
const parameter = CreateParameter("value", "any");
|
|
3942
|
+
const returns = CreateReturns("boolean");
|
|
3943
|
+
const expression = [...Visit(schema, references, value, useHoisting)].map((expression2) => `${pad(4)}${expression2}`).join(` &&${newline}`);
|
|
3944
|
+
return `function ${name}(${parameter})${returns} {${newline}${pad(2)}return (${newline}${expression}${newline}${pad(2)})
|
|
3945
|
+
}`;
|
|
3946
|
+
}
|
|
3947
|
+
function CreateParameter(name, type) {
|
|
3948
|
+
const annotation = state.language === "typescript" ? `: ${type}` : "";
|
|
3949
|
+
return `${name}${annotation}`;
|
|
3950
|
+
}
|
|
3951
|
+
function CreateReturns(type) {
|
|
3952
|
+
return state.language === "typescript" ? `: ${type}` : "";
|
|
3953
|
+
}
|
|
3954
|
+
function Build(schema, references, options) {
|
|
3955
|
+
const functionCode = CreateFunction("check", schema, references, "value");
|
|
3956
|
+
const parameter = CreateParameter("value", "any");
|
|
3957
|
+
const returns = CreateReturns("boolean");
|
|
3958
|
+
const functions = [...state.functions.values()];
|
|
3959
|
+
const variables = [...state.variables.values()];
|
|
3960
|
+
const checkFunction = (0, guard_1.IsString)(schema.$id) ? `return function check(${parameter})${returns} {
|
|
3961
|
+
return ${CreateFunctionName(schema.$id)}(value)
|
|
3962
|
+
}` : `return ${functionCode}`;
|
|
3963
|
+
return [...variables, ...functions, checkFunction].join("\n");
|
|
3964
|
+
}
|
|
3965
|
+
function Code(...args) {
|
|
3966
|
+
const defaults = { language: "javascript" };
|
|
3967
|
+
const [schema, references, options] = args.length === 2 && (0, guard_1.IsArray)(args[1]) ? [args[0], args[1], defaults] : args.length === 2 && !(0, guard_1.IsArray)(args[1]) ? [args[0], [], args[1]] : args.length === 3 ? [args[0], args[1], args[2]] : args.length === 1 ? [args[0], [], defaults] : [null, [], defaults];
|
|
3968
|
+
state.language = options.language;
|
|
3969
|
+
state.variables.clear();
|
|
3970
|
+
state.functions.clear();
|
|
3971
|
+
state.instances.clear();
|
|
3972
|
+
if (!Types.TypeGuard.TSchema(schema))
|
|
3973
|
+
throw new TypeCompilerTypeGuardError(schema);
|
|
3974
|
+
for (const schema2 of references)
|
|
3975
|
+
if (!Types.TypeGuard.TSchema(schema2))
|
|
3976
|
+
throw new TypeCompilerTypeGuardError(schema2);
|
|
3977
|
+
return Build(schema, references, options);
|
|
3978
|
+
}
|
|
3979
|
+
TypeCompiler3.Code = Code;
|
|
3980
|
+
function Compile(schema, references = []) {
|
|
3981
|
+
const generatedCode = Code(schema, references, { language: "javascript" });
|
|
3982
|
+
const compiledFunction = globalThis.Function("kind", "format", "hash", generatedCode);
|
|
3983
|
+
const instances = new Map(state.instances);
|
|
3984
|
+
function typeRegistryFunction(kind, instance, value) {
|
|
3985
|
+
if (!Types.TypeRegistry.Has(kind) || !instances.has(instance))
|
|
3986
|
+
return false;
|
|
3987
|
+
const checkFunc = Types.TypeRegistry.Get(kind);
|
|
3988
|
+
const schema2 = instances.get(instance);
|
|
3989
|
+
return checkFunc(schema2, value);
|
|
3990
|
+
}
|
|
3991
|
+
function formatRegistryFunction(format, value) {
|
|
3992
|
+
if (!Types.FormatRegistry.Has(format))
|
|
3993
|
+
return false;
|
|
3994
|
+
const checkFunc = Types.FormatRegistry.Get(format);
|
|
3995
|
+
return checkFunc(value);
|
|
3996
|
+
}
|
|
3997
|
+
function hashFunction(value) {
|
|
3998
|
+
return (0, hash_1.Hash)(value);
|
|
3999
|
+
}
|
|
4000
|
+
const checkFunction = compiledFunction(typeRegistryFunction, formatRegistryFunction, hashFunction);
|
|
4001
|
+
return new TypeCheck(schema, references, checkFunction, generatedCode);
|
|
4002
|
+
}
|
|
4003
|
+
TypeCompiler3.Compile = Compile;
|
|
4004
|
+
})(TypeCompiler2 || (exports.TypeCompiler = TypeCompiler2 = {}));
|
|
4005
|
+
}
|
|
4006
|
+
});
|
|
4007
|
+
|
|
4008
|
+
// ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/compiler/index.js
|
|
4009
|
+
var require_compiler2 = __commonJS({
|
|
4010
|
+
"../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/compiler/index.js"(exports) {
|
|
4011
|
+
"use strict";
|
|
4012
|
+
init_dirname();
|
|
4013
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4014
|
+
if (k2 === void 0)
|
|
4015
|
+
k2 = k;
|
|
4016
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4017
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4018
|
+
desc = { enumerable: true, get: function() {
|
|
4019
|
+
return m[k];
|
|
4020
|
+
} };
|
|
4021
|
+
}
|
|
4022
|
+
Object.defineProperty(o, k2, desc);
|
|
4023
|
+
} : function(o, m, k, k2) {
|
|
4024
|
+
if (k2 === void 0)
|
|
4025
|
+
k2 = k;
|
|
4026
|
+
o[k2] = m[k];
|
|
4027
|
+
});
|
|
4028
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
4029
|
+
for (var p in m)
|
|
4030
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
4031
|
+
__createBinding(exports2, m, p);
|
|
4032
|
+
};
|
|
4033
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4034
|
+
exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
4035
|
+
var index_1 = require_errors2();
|
|
4036
|
+
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function() {
|
|
4037
|
+
return index_1.ValueErrorType;
|
|
4038
|
+
} });
|
|
4039
|
+
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function() {
|
|
4040
|
+
return index_1.ValueErrorIterator;
|
|
4041
|
+
} });
|
|
4042
|
+
__exportStar(require_compiler(), exports);
|
|
4043
|
+
}
|
|
4044
|
+
});
|
|
4045
|
+
|
|
4046
|
+
// src/stream.ts
|
|
4047
|
+
init_dirname();
|
|
4048
|
+
|
|
4049
|
+
// src/stream/writeable.ts
|
|
4050
|
+
init_dirname();
|
|
4051
|
+
|
|
4052
|
+
// src/applog/applog-helpers.ts
|
|
4053
|
+
init_dirname();
|
|
4054
|
+
|
|
4055
|
+
// src/query/basic.ts
|
|
4056
|
+
init_dirname();
|
|
4057
|
+
var { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO, { prefix: "[q]" });
|
|
4058
|
+
var QueryNode = class {
|
|
4059
|
+
constructor(logsOfThisNode, variables, prev = null) {
|
|
4060
|
+
this.logsOfThisNode = logsOfThisNode;
|
|
4061
|
+
this.variables = variables;
|
|
4062
|
+
this.prev = prev;
|
|
4063
|
+
makeObservable(this, {
|
|
4064
|
+
allApplogs: computed
|
|
4065
|
+
// ? intuitively only put the ones here that felt expensive to compute (join)
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
get record() {
|
|
4069
|
+
return this.variables;
|
|
4070
|
+
}
|
|
4071
|
+
get allApplogs() {
|
|
4072
|
+
if (!this.prev)
|
|
4073
|
+
return this.logsOfThisNode;
|
|
4074
|
+
return joinStreams([
|
|
4075
|
+
this.logsOfThisNode,
|
|
4076
|
+
this.prev.allApplogs
|
|
4077
|
+
]);
|
|
4078
|
+
}
|
|
4079
|
+
};
|
|
4080
|
+
var QueryNodes = class {
|
|
4081
|
+
constructor(nodes) {
|
|
4082
|
+
this.nodes = nodes;
|
|
4083
|
+
makeObservable(this, {
|
|
4084
|
+
allApplogs: computed,
|
|
4085
|
+
// ? intuitively only put the ones here that felt expensive to compute (join)
|
|
4086
|
+
size: computed,
|
|
4087
|
+
// ... or cheap to cache
|
|
4088
|
+
isEmpty: computed
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
get size() {
|
|
4092
|
+
return this.records.length;
|
|
4093
|
+
}
|
|
4094
|
+
get isEmpty() {
|
|
4095
|
+
return this.records.length === 0;
|
|
4096
|
+
}
|
|
4097
|
+
get untrackedSize() {
|
|
4098
|
+
return untracked(() => this.records.length);
|
|
4099
|
+
}
|
|
4100
|
+
get records() {
|
|
4101
|
+
return this.nodes.map(({ variables }) => variables);
|
|
4102
|
+
}
|
|
4103
|
+
get applogSets() {
|
|
4104
|
+
return this.nodes.map(({ logsOfThisNode: stream }) => stream.applogs);
|
|
4105
|
+
}
|
|
4106
|
+
get applogStreams() {
|
|
4107
|
+
return this.nodes.map(({ logsOfThisNode: stream }) => stream);
|
|
4108
|
+
}
|
|
4109
|
+
get allApplogs() {
|
|
4110
|
+
return joinStreams(this.nodes.map((node) => node.allApplogs));
|
|
4111
|
+
}
|
|
4112
|
+
};
|
|
4113
|
+
var withoutHistory = computedFnDeepCompare(function withoutHistory2(stream, { inverseToOnlyReturnFirstLogs, tolerateAlreadyFiltered } = {}) {
|
|
4114
|
+
VERBOSE(`withoutHistory${inverseToOnlyReturnFirstLogs ? ".inversed" : ""} < ${stream.nameAndSizeUntracked} > initializing`);
|
|
4115
|
+
if (stream.filters.includes("withoutHistory")) {
|
|
4116
|
+
if (tolerateAlreadyFiltered) {
|
|
4117
|
+
DEBUG(`[withoutHistory] already filtered, but tolerateAlreadyFiltered=true, so returning`);
|
|
4118
|
+
return stream;
|
|
4119
|
+
}
|
|
4120
|
+
throw ERROR(`stream already filtered withoutHistory:`, stream.filters, { name: stream.name });
|
|
4121
|
+
}
|
|
4122
|
+
let rollingMap;
|
|
4123
|
+
const mappedStream = rollingMapper(stream, function(event, sourceStream) {
|
|
4124
|
+
const isInitial = isInitEvent(event);
|
|
4125
|
+
let newLogs;
|
|
4126
|
+
const toAdd = [];
|
|
4127
|
+
const toRemove = isInitial ? null : [];
|
|
4128
|
+
if (isInitial) {
|
|
4129
|
+
rollingMap = /* @__PURE__ */ new Map();
|
|
4130
|
+
newLogs = event.init;
|
|
4131
|
+
} else {
|
|
4132
|
+
newLogs = event.added;
|
|
4133
|
+
}
|
|
4134
|
+
let tsCheck;
|
|
4135
|
+
for (let i = inverseToOnlyReturnFirstLogs ? 0 : newLogs.length - 1; inverseToOnlyReturnFirstLogs ? i < newLogs.length : i >= 0; inverseToOnlyReturnFirstLogs ? i++ : i--) {
|
|
4136
|
+
const log = newLogs[i];
|
|
4137
|
+
const key = wrapper_default([log.en, log.at]);
|
|
4138
|
+
if (tsCheck && (inverseToOnlyReturnFirstLogs ? tsCheck > log.ts : tsCheck < log.ts)) {
|
|
4139
|
+
throw ERROR(`withoutHistory.mapper logs not sorted:`, tsCheck, inverseToOnlyReturnFirstLogs ? ">" : "<", log.ts, {
|
|
4140
|
+
log,
|
|
4141
|
+
i,
|
|
4142
|
+
newLogs,
|
|
4143
|
+
inverseToOnlyReturnFirstLogs
|
|
4144
|
+
});
|
|
4145
|
+
}
|
|
4146
|
+
tsCheck = log.ts;
|
|
4147
|
+
const existing = rollingMap.get(key);
|
|
4148
|
+
if (!existing || (inverseToOnlyReturnFirstLogs ? existing.ts > log.ts : existing.ts < log.ts)) {
|
|
4149
|
+
if (existing && !isInitial)
|
|
4150
|
+
toRemove.push(existing);
|
|
4151
|
+
toAdd.push(log);
|
|
4152
|
+
rollingMap.set(key, log);
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
sortApplogsByTs(toAdd);
|
|
4156
|
+
VERBOSE.isDisabled || VERBOSE(
|
|
4157
|
+
`withoutHistory${inverseToOnlyReturnFirstLogs ? ".inversed" : ""}<${stream.nameAndSizeUntracked}> mapped event`,
|
|
4158
|
+
isInitial ? { ...Object.fromEntries(Object.entries(event).map(([k, v]) => [k, v?.length])), toAdd: toAdd.length, toRemove } : { ...event, toAdd, toRemove }
|
|
4159
|
+
);
|
|
4160
|
+
return isInitial ? { init: toAdd } : { added: toAdd, removed: toRemove };
|
|
4161
|
+
}, { name: `withoutHistory${inverseToOnlyReturnFirstLogs ? ".inversed" : ""}`, extraFilterName: "withoutHistory" });
|
|
4162
|
+
VERBOSE.isDisabled || autorun(() => {
|
|
4163
|
+
VERBOSE(`withoutHistory<${stream.nameAndSizeUntracked}> filtered down to`, mappedStream.applogs.length);
|
|
4164
|
+
});
|
|
4165
|
+
return mappedStream;
|
|
4166
|
+
}, { equals: applogStreamComparer });
|
|
4167
|
+
var withoutDeleted = computedFnDeepCompare(function withoutDeleted2(stream) {
|
|
4168
|
+
VERBOSE(`withoutDeleted<${stream.nameAndSizeUntracked}>`);
|
|
4169
|
+
if (stream.filters.includes("withoutDeleted")) {
|
|
4170
|
+
throw ERROR(`stream already filtered withoutDeleted:`, stream.filters, { name: stream.name });
|
|
4171
|
+
}
|
|
4172
|
+
const deletionLogs = rollingFilter(
|
|
4173
|
+
stream,
|
|
4174
|
+
// TODO: handle un-delection
|
|
4175
|
+
{ at: ["isDeleted", "relation/isDeleted", "block/isDeleted"], vl: true },
|
|
4176
|
+
{ name: "isDeleted" }
|
|
4177
|
+
);
|
|
4178
|
+
VERBOSE(`withoutDeleted<${stream.nameAndSizeUntracked}> deletionLogs:`, untracked(() => [...deletionLogs.applogs]));
|
|
4179
|
+
const obsArrMapName = createDebugName({ caller: "allDeletedEntities", stream });
|
|
4180
|
+
const deleted = observableArrayMap(() => deletionLogs.map((log) => log.en), { name: obsArrMapName });
|
|
4181
|
+
VERBOSE.isDisabled || autorun(() => {
|
|
4182
|
+
VERBOSE(`withoutDeleted<${stream.nameAndSizeUntracked}> deleted:`, [...deleted]);
|
|
4183
|
+
});
|
|
4184
|
+
return rollingFilter(stream, { "!en": deleted }, { name: `withoutDeleted`, extraFilterName: "withoutDeleted" });
|
|
4185
|
+
}, { equals: applogStreamComparer });
|
|
4186
|
+
var query = computedFnDeepCompare(function query2(stream, patternOrPatterns, startVariables = {}, opts = {}) {
|
|
4187
|
+
DEBUG(`query<${stream.nameAndSizeUntracked}>:`, patternOrPatterns);
|
|
4188
|
+
const patterns = Array.isArray(patternOrPatterns) ? patternOrPatterns : [patternOrPatterns];
|
|
4189
|
+
let nodes;
|
|
4190
|
+
if (patterns.length === 1) {
|
|
4191
|
+
nodes = null;
|
|
4192
|
+
} else {
|
|
4193
|
+
const pattersExceptLast = patterns.slice(0, -1);
|
|
4194
|
+
nodes = query2(stream, pattersExceptLast, startVariables, opts);
|
|
4195
|
+
}
|
|
4196
|
+
const lastPattern = patterns[patterns.length - 1];
|
|
4197
|
+
const stepResult = queryStep(stream, nodes, lastPattern, opts);
|
|
4198
|
+
VERBOSE.isDisabled || autorun(() => VERBOSE(`query result:`, toJS(stepResult)));
|
|
4199
|
+
return stepResult;
|
|
4200
|
+
}, { equals: queryNodesComparer });
|
|
4201
|
+
var queryStep = computedFnDeepCompare(function queryStep2(stream, nodeSet, pattern, opts = {}) {
|
|
4202
|
+
DEBUG(`queryStep<${stream.nameAndSizeUntracked}> with`, nodeSet?.untrackedSize ?? "all", "nodes, pattern:", pattern);
|
|
4203
|
+
if (!Object.entries(pattern).length)
|
|
4204
|
+
throw new Error(`Pattern is empty`);
|
|
4205
|
+
const observableResultNodes = observableArrayMap(
|
|
4206
|
+
() => {
|
|
4207
|
+
function doQuery(node) {
|
|
4208
|
+
const [patternWithResolvedVars, variablesToFill] = resolveOrRemoveVariables(pattern, node?.variables ?? {});
|
|
4209
|
+
VERBOSE(`[queryStep] patternWithoutVars: `, patternWithResolvedVars);
|
|
4210
|
+
const applogsMatchingStatic = rollingFilter(stream, patternWithResolvedVars);
|
|
4211
|
+
const varMapper = mapTo(variablesToFill);
|
|
4212
|
+
const newVarsAndTheirLog = applogsMatchingStatic.map((log) => ({ log, vars: varMapper(log) }));
|
|
4213
|
+
VERBOSE.isDisabled || VERBOSE(
|
|
4214
|
+
`[queryStep] step node:`,
|
|
4215
|
+
node?.variables,
|
|
4216
|
+
" =>",
|
|
4217
|
+
newVarsAndTheirLog,
|
|
4218
|
+
"from:",
|
|
4219
|
+
untracked(() => applogsMatchingStatic.applogs)
|
|
4220
|
+
);
|
|
4221
|
+
const resultNodes = newVarsAndTheirLog.map(({ log, vars }) => {
|
|
4222
|
+
const nodeVars = Object.assign({}, node?.variables, vars);
|
|
4223
|
+
return new QueryNode(
|
|
4224
|
+
new ApplogStreamInMemory(
|
|
4225
|
+
[log],
|
|
4226
|
+
stream.filters,
|
|
4227
|
+
createDebugName({
|
|
4228
|
+
caller: "QueryNode",
|
|
4229
|
+
stream: applogsMatchingStatic,
|
|
4230
|
+
pattern: `${wrapper_default(nodeVars)}@${wrapper_default(patternWithResolvedVars)}`
|
|
4231
|
+
}),
|
|
4232
|
+
true,
|
|
4233
|
+
applogsMatchingStatic
|
|
4234
|
+
),
|
|
4235
|
+
nodeVars,
|
|
4236
|
+
node
|
|
4237
|
+
);
|
|
4238
|
+
});
|
|
4239
|
+
if (opts.debug) {
|
|
4240
|
+
LOG(
|
|
4241
|
+
`[queryStep] step result:`,
|
|
4242
|
+
untracked(
|
|
4243
|
+
() => resultNodes.map(({ variables, logsOfThisNode: stream2 }) => ({
|
|
4244
|
+
variables,
|
|
4245
|
+
stream: (
|
|
4246
|
+
/* util.inspect( */
|
|
4247
|
+
stream2.applogs
|
|
4248
|
+
)
|
|
4249
|
+
/* , { showHidden: false, depth: null }) */
|
|
4250
|
+
}))
|
|
4251
|
+
)
|
|
4252
|
+
);
|
|
4253
|
+
}
|
|
4254
|
+
return resultNodes;
|
|
4255
|
+
}
|
|
4256
|
+
if (nodeSet) {
|
|
4257
|
+
return nodeSet.nodes.flatMap(doQuery);
|
|
4258
|
+
} else {
|
|
4259
|
+
return doQuery(null);
|
|
4260
|
+
}
|
|
4261
|
+
},
|
|
4262
|
+
{ name: createDebugName({ caller: "queryStep", stream, pattern }) }
|
|
4263
|
+
);
|
|
4264
|
+
VERBOSE(`queryStep result:`, observableResultNodes);
|
|
4265
|
+
return new QueryNodes(observableResultNodes);
|
|
4266
|
+
}, { equals: queryNodesComparer });
|
|
4267
|
+
var queryNot = computedFnDeepCompare(function queryNot2(stream, startNodes, patternOrPatterns, opts = {}) {
|
|
4268
|
+
let nodes = startNodes.nodes;
|
|
4269
|
+
DEBUG(`queryNot<${stream.nameAndSizeUntracked}> from: ${nodes.length} nodes`);
|
|
4270
|
+
const patterns = Array.isArray(patternOrPatterns) ? patternOrPatterns : [patternOrPatterns];
|
|
4271
|
+
for (const pattern of patterns) {
|
|
4272
|
+
if (!Object.entries(patternOrPatterns).length)
|
|
4273
|
+
throw new Error(`Pattern is empty`);
|
|
4274
|
+
nodes = nodes.filter(({
|
|
4275
|
+
/* applogs, */
|
|
4276
|
+
variables
|
|
4277
|
+
}) => {
|
|
4278
|
+
const [patternWithResolvedVars, _variablesToFill] = resolveOrRemoveVariables(pattern, variables ?? {});
|
|
4279
|
+
VERBOSE(`[queryNot] patternWithoutVars: `, patternWithResolvedVars);
|
|
4280
|
+
const newApplogs = rollingFilter(stream, patternWithResolvedVars);
|
|
4281
|
+
VERBOSE(`[queryNot] step node:`, variables, " =>", newApplogs.size, "applogs");
|
|
4282
|
+
VERBOSE.isDisabled || VERBOSE(`[queryNot] step node:`, variables, " => empty?", untracked(() => newApplogs.applogs));
|
|
4283
|
+
if (opts.debug)
|
|
4284
|
+
LOG(`[queryNot] node result:`, variables, "=>", newApplogs.applogs);
|
|
4285
|
+
return newApplogs.isEmpty;
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4288
|
+
return new QueryNodes(nodes);
|
|
4289
|
+
}, { equals: queryNodesComparer });
|
|
4290
|
+
var filterAndMap = computedFnDeepCompare(function filterAndMap2(stream, pattern, mapper) {
|
|
4291
|
+
DEBUG(`filterAndMap<${stream.nameAndSizeUntracked}>`, pattern);
|
|
4292
|
+
const filtered = rollingFilter(stream, pattern);
|
|
4293
|
+
VERBOSE(`[filterAndMap] filtered:`, filtered.untrackedSize);
|
|
4294
|
+
VERBOSE.isDisabled || autorun(() => VERBOSE(`[filterAndMap] filtered:`, filtered.applogs));
|
|
4295
|
+
const mapperFX = function filterAndMapGetterFx() {
|
|
4296
|
+
if (typeof mapper === "function") {
|
|
4297
|
+
return filtered.map(mapper);
|
|
4298
|
+
} else if (typeof mapper === "string") {
|
|
4299
|
+
return filtered.map((log) => log[mapper]);
|
|
4300
|
+
} else {
|
|
4301
|
+
return filtered.map(mapTo(mapper));
|
|
4302
|
+
}
|
|
4303
|
+
};
|
|
4304
|
+
const name = createDebugName({ stream, pattern, caller: "filterAndMap" });
|
|
4305
|
+
const mapped = observableArrayMap(mapperFX, { name });
|
|
4306
|
+
VERBOSE.isDisabled || autorun(() => VERBOSE(`[filterAndMap] mapped:`, mapped));
|
|
4307
|
+
return mapped;
|
|
4308
|
+
}, { equals: comparer.structural });
|
|
4309
|
+
var queryAndMap = computedFnDeepCompare(function queryAndMap2(stream, patternOrPatterns, map, variables = {}) {
|
|
4310
|
+
DEBUG(`queryAndMap<${stream.nameAndSizeUntracked}>`, { patternOrPatterns, variables, map });
|
|
4311
|
+
const debugName = createDebugName({ stream, caller: "queryAndMap" });
|
|
4312
|
+
const filtered = query(stream, patternOrPatterns);
|
|
4313
|
+
VERBOSE(`[queryAndMap] filtered count:`, filtered.untrackedSize);
|
|
4314
|
+
const mapped = observableArrayMap(
|
|
4315
|
+
() => {
|
|
4316
|
+
if (typeof map === "function") {
|
|
4317
|
+
return filtered.records.map(map);
|
|
4318
|
+
} else if (typeof map === "string") {
|
|
4319
|
+
return filtered.records.map((log) => log[map]);
|
|
4320
|
+
} else {
|
|
4321
|
+
throw new Error("what's this map param about?");
|
|
4322
|
+
}
|
|
4323
|
+
},
|
|
4324
|
+
{ name: debugName }
|
|
4325
|
+
);
|
|
4326
|
+
VERBOSE.isDisabled || autorun(() => VERBOSE(`[queryAndMap] result:`, toJS(mapped)));
|
|
4327
|
+
return mapped;
|
|
4328
|
+
}, { equals: comparer.structural });
|
|
4329
|
+
var queryEntity = computedFnDeepCompare(function queryEntity2(stream, name, entityID, attributes) {
|
|
4330
|
+
DEBUG(`queryEntity<${stream.nameAndSizeUntracked}>`, entityID, name);
|
|
4331
|
+
const filtered = rollingFilter(stream, { en: entityID, at: prefixAttrs(name, attributes) });
|
|
4332
|
+
VERBOSE(`queryEntity applogs:`, filtered.applogs);
|
|
4333
|
+
return computed(
|
|
4334
|
+
() => filtered.isEmpty ? null : Object.fromEntries(
|
|
4335
|
+
filtered.map(({ at, vl }) => [at.slice(name.length + 1), vl])
|
|
4336
|
+
)
|
|
4337
|
+
);
|
|
4338
|
+
}, { equals: computedStructuralComparer });
|
|
4339
|
+
var agentsOfStream = computedFnDeepCompare(function agentsOfStream2(stream) {
|
|
4340
|
+
LOG(`agentsOfStream<${stream.nameAndSizeUntracked}>`);
|
|
4341
|
+
const mapped = observable.map();
|
|
4342
|
+
function onEvent(event) {
|
|
4343
|
+
for (const log of isInitEvent(event) ? event.init : event.added) {
|
|
4344
|
+
const prev = mapped.get(log.ag) ?? 0;
|
|
4345
|
+
mapped.set(log.ag, prev + 1);
|
|
4346
|
+
}
|
|
4347
|
+
for (const log of !isInitEvent(event) && event.removed || []) {
|
|
4348
|
+
const prev = mapped.get(log.ag);
|
|
4349
|
+
if (!prev || prev < 1)
|
|
4350
|
+
throw ERROR(`[agentsOfStream] number is now negative`, { log, event, mapped, prev });
|
|
4351
|
+
mapped.set(log.ag, prev - 1);
|
|
4352
|
+
}
|
|
4353
|
+
LOG(`agentsOfStream<${stream.nameAndSizeUntracked}> processed event`, { event, mapped });
|
|
4354
|
+
}
|
|
4355
|
+
untracked(() => onEvent({ init: stream.applogs }));
|
|
4356
|
+
stream.subscribe(onEvent);
|
|
4357
|
+
onBecomeObserved(mapped, () => stream.unsubscribe(onEvent));
|
|
4358
|
+
return mapped;
|
|
4359
|
+
});
|
|
4360
|
+
var entityOverlap = computedFnDeepCompare(function entityOverlapCount(streamA, streamB) {
|
|
4361
|
+
LOG(`entityOverlap<${streamA.nameAndSizeUntracked}, ${streamB.nameAndSizeUntracked}>`);
|
|
4362
|
+
return computed(() => {
|
|
4363
|
+
const entitiesA = new Set(streamA.map((log) => log.en));
|
|
4364
|
+
const entitiesB = new Set(streamB.map((log) => log.en));
|
|
4365
|
+
return [...entitiesA].filter((en) => entitiesB.has(en));
|
|
4366
|
+
});
|
|
4367
|
+
});
|
|
4368
|
+
var entityOverlapCount2 = computedFnDeepCompare(function entityOverlapCount3(streamA, streamB) {
|
|
4369
|
+
return computed(() => entityOverlap(streamA, streamB).get().length);
|
|
4370
|
+
});
|
|
4371
|
+
function mapTo(applogFieldMap) {
|
|
4372
|
+
return (applog) => {
|
|
4373
|
+
return Object.entries(applogFieldMap).reduce((acc, [key, value]) => {
|
|
4374
|
+
acc[value] = applog[key];
|
|
4375
|
+
return acc;
|
|
4376
|
+
}, {});
|
|
4377
|
+
};
|
|
4378
|
+
}
|
|
4379
|
+
function startsWith(str) {
|
|
4380
|
+
return (value) => value.startsWith(str);
|
|
4381
|
+
}
|
|
4382
|
+
function prefixAttrs(prefix, attrs) {
|
|
4383
|
+
return attrs.map((at) => prefixAt(prefix, at));
|
|
4384
|
+
}
|
|
4385
|
+
function prefixAt(prefix, attr) {
|
|
4386
|
+
return `${prefix}/${attr}`;
|
|
4387
|
+
}
|
|
4388
|
+
|
|
4389
|
+
// src/applog/applog-helpers.ts
|
|
4390
|
+
var { WARN: WARN2, LOG: LOG2, DEBUG: DEBUG2, VERBOSE: VERBOSE2, ERROR: ERROR2 } = Logger.setup(Logger.INFO);
|
|
4391
|
+
function hasAg(log) {
|
|
4392
|
+
return !!log.ag;
|
|
4393
|
+
}
|
|
4394
|
+
function hasTs(log) {
|
|
4395
|
+
return !!log.ts;
|
|
4396
|
+
}
|
|
4397
|
+
function hasPv(log) {
|
|
4398
|
+
return !!log.pv;
|
|
4399
|
+
}
|
|
4400
|
+
function withTs(log, ts) {
|
|
4401
|
+
return hasTs(log) ? log : { ...log, ts };
|
|
4402
|
+
}
|
|
4403
|
+
function withPv(log, ds) {
|
|
4404
|
+
const { en, at } = log;
|
|
4405
|
+
const pvs = filterAndMap(withoutHistory(ds), { en, at }, "cid");
|
|
4406
|
+
if (pvs.length > 1)
|
|
4407
|
+
WARN2(`[withPv] unexpected result count:`, pvs.length);
|
|
4408
|
+
let pv = pvs.length ? pvs[0] : null;
|
|
4409
|
+
const isMatchingPv = !!(pv === log.pv);
|
|
4410
|
+
if (log.pv && !isMatchingPv)
|
|
4411
|
+
WARN2(`[withPv] different than pre-set pv:`, { queriedPv: pv, logPv: log.pv });
|
|
4412
|
+
pv = log.pv ?? pv;
|
|
4413
|
+
return { ...log, pv: pv ?? null };
|
|
4414
|
+
}
|
|
4415
|
+
function joinStreams(streams) {
|
|
4416
|
+
if (streams.length === 0)
|
|
4417
|
+
throw ERROR2(`joinStreams called with empty array`);
|
|
4418
|
+
if (streams.length === 1)
|
|
4419
|
+
return streams[0];
|
|
4420
|
+
const fullJoin = () => sortApplogsByTs(
|
|
4421
|
+
removeDuplicateAppLogs(streams.flatMap((s) => {
|
|
4422
|
+
const logs = s.applogs;
|
|
4423
|
+
if (!logs) {
|
|
4424
|
+
ERROR2(`falsy applogs of stream`, s);
|
|
4425
|
+
throw new Error(`falsy applogs of stream`);
|
|
4426
|
+
}
|
|
4427
|
+
return logs;
|
|
4428
|
+
}))
|
|
4429
|
+
);
|
|
4430
|
+
const initialMergeResult = untracked(() => fullJoin());
|
|
4431
|
+
const eventMapper = action(function(event, sourceStream) {
|
|
4432
|
+
if (isInitEvent(event)) {
|
|
4433
|
+
return { init: untracked(() => fullJoin()) };
|
|
4434
|
+
} else {
|
|
4435
|
+
return {
|
|
4436
|
+
// TODO: test this stuff
|
|
4437
|
+
added: event.added.filter((addedLog) => !this.hasApplog(addedLog, true)),
|
|
4438
|
+
removed: event.added.filter(
|
|
4439
|
+
(addedLog) => !this.parents.some((parent) => {
|
|
4440
|
+
if (parent === sourceStream)
|
|
4441
|
+
return false;
|
|
4442
|
+
return parent.hasApplog(addedLog, true);
|
|
4443
|
+
})
|
|
4444
|
+
)
|
|
4445
|
+
};
|
|
4446
|
+
}
|
|
4447
|
+
});
|
|
4448
|
+
return new MappedApplogStream(streams, ["?"], initialMergeResult, eventMapper, `join(${streams.map((s) => s.name).join(", ")})`);
|
|
4449
|
+
}
|
|
4450
|
+
|
|
4451
|
+
// src/applog/datom-types.ts
|
|
4452
|
+
init_dirname();
|
|
4453
|
+
var import_typebox = __toESM(require_typebox(), 1);
|
|
4454
|
+
var import_compiler = __toESM(require_compiler2(), 1);
|
|
4455
|
+
var Nullable = (schema) => import_typebox.Type.Union([schema, import_typebox.Type.Null()]);
|
|
4456
|
+
var EntityID_LENGTH = 7;
|
|
4457
|
+
var isCID = /^(k51qz|baguq)[0-9a-z]{56,57}$/;
|
|
4458
|
+
var isShortHash = /^[0-9A-Fa-f]{7,8}$/g;
|
|
4459
|
+
import_typebox.FormatRegistry.Set("EntityID", (value) => !!value.match(isShortHash) || !!value.match(isCID));
|
|
4460
|
+
var EntityID = import_typebox.Type.String();
|
|
4461
|
+
import_typebox.FormatRegistry.Set("CID", (value) => !!value.match(isCID));
|
|
4462
|
+
var CIDTB = import_typebox.Type.String({ format: "EntityID" });
|
|
4463
|
+
var isURL = /^http([s]?):\/\/.*\..*/;
|
|
4464
|
+
import_typebox.FormatRegistry.Set("URL", (value) => !!value.match(isURL));
|
|
4465
|
+
var URL = import_typebox.Type.String({ format: "URL" });
|
|
4466
|
+
var AppLogTB = import_typebox.Type.Object({
|
|
4467
|
+
en: EntityID,
|
|
4468
|
+
// EntityID
|
|
4469
|
+
at: import_typebox.Type.String(),
|
|
4470
|
+
// Attribute
|
|
4471
|
+
vl: Nullable(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Boolean(), import_typebox.Type.Number()])),
|
|
4472
|
+
// TODO refactor to semantic typesafe ApplogValue
|
|
4473
|
+
ts: import_typebox.Type.String(),
|
|
4474
|
+
// Timestamp
|
|
4475
|
+
ag: import_typebox.Type.String()
|
|
4476
|
+
// AgentHash
|
|
4477
|
+
});
|
|
4478
|
+
var AppLogTBC = import_compiler.TypeCompiler.Compile(AppLogTB);
|
|
4479
|
+
var getApplogTypeErrors = (obj) => Array.from(AppLogTBC.Errors(obj));
|
|
4480
|
+
var isValidApplog = AppLogTBC.Check.bind(AppLogTBC);
|
|
4481
|
+
|
|
4482
|
+
// src/stream/writeable.ts
|
|
4483
|
+
var { WARN: WARN3, LOG: LOG3, DEBUG: DEBUG3, VERBOSE: VERBOSE3, ERROR: ERROR3 } = Logger.setup(Logger.INFO);
|
|
4484
|
+
var WriteableApplogStream = class extends ApplogStream {
|
|
4485
|
+
constructor(parents, filters, applogs = [], name) {
|
|
4486
|
+
super(parents, filters, applogs, name);
|
|
4487
|
+
makeObservable(this, {
|
|
4488
|
+
insert: action
|
|
4489
|
+
// ? is there an advantage to do this here instead of wrapping the fx in action below?
|
|
4490
|
+
});
|
|
4491
|
+
}
|
|
4492
|
+
insert(appLogsToInsert) {
|
|
4493
|
+
const ts = dateNowIso();
|
|
4494
|
+
const mapped = appLogsToInsert.map((log) => {
|
|
4495
|
+
const logWithTs = withTs(log, ts);
|
|
4496
|
+
if (!isValidApplog(logWithTs)) {
|
|
4497
|
+
throw ERROR3(`Bogus Applog ${JSON.stringify(logWithTs)}`, getApplogTypeErrors(logWithTs));
|
|
4498
|
+
}
|
|
4499
|
+
const logWithPv = withPv(logWithTs, this);
|
|
4500
|
+
const cid = encodeApplogAndGetCid(logWithPv).toString();
|
|
4501
|
+
const logWithCid = { ...logWithPv, cid };
|
|
4502
|
+
return Object.freeze(logWithCid);
|
|
4503
|
+
});
|
|
4504
|
+
const mappedLogs = removeDuplicateAppLogs(mapped);
|
|
4505
|
+
if (appLogsToInsert.length !== mappedLogs.length) {
|
|
4506
|
+
WARN3("request to insert duplicate log, inserting mappedLogs:", { appLogsToInsert, mappedLogs });
|
|
4507
|
+
} else if (!appLogsToInsert.length) {
|
|
4508
|
+
WARN3("request to insert empty logs array");
|
|
4509
|
+
} else {
|
|
4510
|
+
LOG3("Inserting:", mappedLogs.length === 1 ? mappedLogs[0] : mappedLogs, { ds: this });
|
|
4511
|
+
}
|
|
4512
|
+
if (!mappedLogs.length)
|
|
4513
|
+
return [];
|
|
4514
|
+
sortApplogsByTs(mappedLogs);
|
|
4515
|
+
const sortNeeded = this._applogs.length && isTsBefore(mappedLogs[0], this._applogs[this._applogs.length - 1]);
|
|
4516
|
+
this._applogs.push(...mappedLogs);
|
|
4517
|
+
if (sortNeeded) {
|
|
4518
|
+
sortApplogsByTs(this._applogs);
|
|
4519
|
+
}
|
|
4520
|
+
this.notifySubscribers({ added: mappedLogs, removed: null });
|
|
4521
|
+
void this.persist(mappedLogs);
|
|
4522
|
+
return mappedLogs;
|
|
4523
|
+
}
|
|
4524
|
+
get readOnly() {
|
|
4525
|
+
return false;
|
|
4526
|
+
}
|
|
4527
|
+
};
|
|
4528
|
+
var ApplogStreamInMemory = class extends WriteableApplogStream {
|
|
4529
|
+
constructor(applogs, filters, name, _readOnly, parents = null) {
|
|
4530
|
+
super(parents, filters, applogs, name);
|
|
4531
|
+
this._readOnly = _readOnly;
|
|
4532
|
+
makeObservable(this, {
|
|
4533
|
+
// @ts-expect-error bc it's private
|
|
4534
|
+
_applogs: observable.shallow
|
|
4535
|
+
});
|
|
4536
|
+
}
|
|
4537
|
+
get readOnly() {
|
|
4538
|
+
return this._readOnly;
|
|
4539
|
+
}
|
|
4540
|
+
persist(logs) {
|
|
4541
|
+
VERBOSE3(`[InMem.persist] no persist for`, logs);
|
|
4542
|
+
if (this.readOnly) {
|
|
4543
|
+
throw ERROR3(`[persist] called for readOnly stream`);
|
|
4544
|
+
}
|
|
4545
|
+
}
|
|
4546
|
+
};
|
|
4547
|
+
|
|
4548
|
+
export {
|
|
4549
|
+
require_typebox,
|
|
4550
|
+
require_system2 as require_system,
|
|
4551
|
+
Nullable,
|
|
4552
|
+
EntityID_LENGTH,
|
|
4553
|
+
EntityID,
|
|
4554
|
+
CIDTB,
|
|
4555
|
+
URL,
|
|
4556
|
+
AppLogTB,
|
|
4557
|
+
AppLogTBC,
|
|
4558
|
+
getApplogTypeErrors,
|
|
4559
|
+
isValidApplog,
|
|
4560
|
+
WriteableApplogStream,
|
|
4561
|
+
ApplogStreamInMemory,
|
|
4562
|
+
QueryNode,
|
|
4563
|
+
QueryNodes,
|
|
4564
|
+
withoutHistory,
|
|
4565
|
+
withoutDeleted,
|
|
4566
|
+
query,
|
|
4567
|
+
queryStep,
|
|
4568
|
+
queryNot,
|
|
4569
|
+
filterAndMap,
|
|
4570
|
+
queryAndMap,
|
|
4571
|
+
queryEntity,
|
|
4572
|
+
agentsOfStream,
|
|
4573
|
+
entityOverlap,
|
|
4574
|
+
entityOverlapCount2 as entityOverlapCount,
|
|
4575
|
+
mapTo,
|
|
4576
|
+
startsWith,
|
|
4577
|
+
prefixAttrs,
|
|
4578
|
+
prefixAt,
|
|
4579
|
+
hasAg,
|
|
4580
|
+
hasTs,
|
|
4581
|
+
hasPv,
|
|
4582
|
+
withTs,
|
|
4583
|
+
withPv,
|
|
4584
|
+
joinStreams
|
|
4585
|
+
};
|
|
4586
|
+
//# sourceMappingURL=chunk-MTQJBBHB.js.map
|