@wovin/core 0.0.7 → 0.0.8

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.
Files changed (68) hide show
  1. package/dist/applog/applog-helpers.d.ts +5 -6
  2. package/dist/applog/applog-helpers.d.ts.map +1 -1
  3. package/dist/applog/applog-utils.d.ts +2 -1
  4. package/dist/applog/applog-utils.d.ts.map +1 -1
  5. package/dist/applog/datom-types.d.ts +34 -2
  6. package/dist/applog/datom-types.d.ts.map +1 -1
  7. package/dist/applog.min.js +90 -1
  8. package/dist/chunk-2J7BWXZ3.min.js +4373 -0
  9. package/dist/{chunk-G3GOAFHU.min.js.map → chunk-2J7BWXZ3.min.js.map} +1 -1
  10. package/dist/chunk-5MMGBK2U.min.js +1 -0
  11. package/dist/chunk-5MMGBK2U.min.js.map +1 -0
  12. package/dist/chunk-6BFNER6K.min.js +120 -0
  13. package/dist/chunk-6BFNER6K.min.js.map +1 -0
  14. package/dist/chunk-KRQZ6V4Y.min.js +36 -0
  15. package/dist/chunk-KRQZ6V4Y.min.js.map +1 -0
  16. package/dist/chunk-N4QMZPZF.min.js +10844 -0
  17. package/dist/chunk-N4QMZPZF.min.js.map +1 -0
  18. package/dist/chunk-ORHJN4G2.min.js +1425 -0
  19. package/dist/chunk-ORHJN4G2.min.js.map +1 -0
  20. package/dist/chunk-PTGUFZ3Q.min.js +1555 -0
  21. package/dist/chunk-PTGUFZ3Q.min.js.map +1 -0
  22. package/dist/chunk-YOCP7FGE.min.js +66 -0
  23. package/dist/chunk-YOCP7FGE.min.js.map +1 -0
  24. package/dist/index.d.ts +0 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.min.js +252 -1
  27. package/dist/index.min.js.map +1 -1
  28. package/dist/ipfs/car.d.ts +2 -0
  29. package/dist/ipfs/car.d.ts.map +1 -1
  30. package/dist/ipfs.min.js +32 -1
  31. package/dist/mobx/mobx-utils.d.ts +7 -6
  32. package/dist/mobx/mobx-utils.d.ts.map +1 -1
  33. package/dist/pubsub.min.js +21 -1
  34. package/dist/query/basic.d.ts +11 -28
  35. package/dist/query/basic.d.ts.map +1 -1
  36. package/dist/query/divergences.d.ts +2 -2
  37. package/dist/query/divergences.d.ts.map +1 -1
  38. package/dist/query/query-steps.d.ts +4 -0
  39. package/dist/query/query-steps.d.ts.map +1 -0
  40. package/dist/query/types.d.ts +29 -0
  41. package/dist/query/types.d.ts.map +1 -0
  42. package/dist/query.d.ts +1 -0
  43. package/dist/query.d.ts.map +1 -1
  44. package/dist/query.min.js +71 -1
  45. package/dist/thread/basic.d.ts +12 -6
  46. package/dist/thread/basic.d.ts.map +1 -1
  47. package/dist/thread/filters.d.ts +7 -5
  48. package/dist/thread/filters.d.ts.map +1 -1
  49. package/dist/thread/mapped.d.ts +3 -4
  50. package/dist/thread/mapped.d.ts.map +1 -1
  51. package/dist/thread/writeable.d.ts +3 -2
  52. package/dist/thread/writeable.d.ts.map +1 -1
  53. package/dist/thread.min.js +37 -1
  54. package/dist/types/typescript-utils.d.ts +6 -2
  55. package/dist/types/typescript-utils.d.ts.map +1 -1
  56. package/dist/types.min.js +30 -1
  57. package/package.json +2 -2
  58. package/dist/chunk-5O6HLH5H.min.js +0 -2
  59. package/dist/chunk-5O6HLH5H.min.js.map +0 -1
  60. package/dist/chunk-6WLDICQ6.min.js +0 -2
  61. package/dist/chunk-6WLDICQ6.min.js.map +0 -1
  62. package/dist/chunk-G3GOAFHU.min.js +0 -8
  63. package/dist/chunk-J5PGGKKW.min.js +0 -2
  64. package/dist/chunk-J5PGGKKW.min.js.map +0 -1
  65. package/dist/chunk-O7KDPKK2.min.js +0 -2
  66. package/dist/chunk-O7KDPKK2.min.js.map +0 -1
  67. package/dist/chunk-XQUJRFOK.min.js +0 -45
  68. package/dist/chunk-XQUJRFOK.min.js.map +0 -1
@@ -0,0 +1,1555 @@
1
+ import {
2
+ __commonJS,
3
+ __toESM
4
+ } from "./chunk-KRQZ6V4Y.min.js";
5
+
6
+ // ../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js
7
+ var require_typebox = __commonJS({
8
+ "../../../node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js"(exports) {
9
+ "use strict";
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ 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;
12
+ exports.Transform = Symbol.for("TypeBox.Transform");
13
+ exports.Readonly = Symbol.for("TypeBox.Readonly");
14
+ exports.Optional = Symbol.for("TypeBox.Optional");
15
+ exports.Hint = Symbol.for("TypeBox.Hint");
16
+ exports.Kind = Symbol.for("TypeBox.Kind");
17
+ exports.PatternBoolean = "(true|false)";
18
+ exports.PatternNumber = "(0|[1-9][0-9]*)";
19
+ exports.PatternString = "(.*)";
20
+ exports.PatternBooleanExact = `^${exports.PatternBoolean}$`;
21
+ exports.PatternNumberExact = `^${exports.PatternNumber}$`;
22
+ exports.PatternStringExact = `^${exports.PatternString}$`;
23
+ var TypeRegistry;
24
+ (function(TypeRegistry2) {
25
+ const map = /* @__PURE__ */ new Map();
26
+ function Entries() {
27
+ return new Map(map);
28
+ }
29
+ TypeRegistry2.Entries = Entries;
30
+ function Clear() {
31
+ return map.clear();
32
+ }
33
+ TypeRegistry2.Clear = Clear;
34
+ function Delete(kind) {
35
+ return map.delete(kind);
36
+ }
37
+ TypeRegistry2.Delete = Delete;
38
+ function Has(kind) {
39
+ return map.has(kind);
40
+ }
41
+ TypeRegistry2.Has = Has;
42
+ function Set2(kind, func) {
43
+ map.set(kind, func);
44
+ }
45
+ TypeRegistry2.Set = Set2;
46
+ function Get(kind) {
47
+ return map.get(kind);
48
+ }
49
+ TypeRegistry2.Get = Get;
50
+ })(TypeRegistry || (exports.TypeRegistry = TypeRegistry = {}));
51
+ var TypeBoxError = class extends Error {
52
+ constructor(message) {
53
+ super(message);
54
+ }
55
+ };
56
+ exports.TypeBoxError = TypeBoxError;
57
+ var FormatRegistry;
58
+ (function(FormatRegistry2) {
59
+ const map = /* @__PURE__ */ new Map();
60
+ function Entries() {
61
+ return new Map(map);
62
+ }
63
+ FormatRegistry2.Entries = Entries;
64
+ function Clear() {
65
+ return map.clear();
66
+ }
67
+ FormatRegistry2.Clear = Clear;
68
+ function Delete(format) {
69
+ return map.delete(format);
70
+ }
71
+ FormatRegistry2.Delete = Delete;
72
+ function Has(format) {
73
+ return map.has(format);
74
+ }
75
+ FormatRegistry2.Has = Has;
76
+ function Set2(format, func) {
77
+ map.set(format, func);
78
+ }
79
+ FormatRegistry2.Set = Set2;
80
+ function Get(format) {
81
+ return map.get(format);
82
+ }
83
+ FormatRegistry2.Get = Get;
84
+ })(FormatRegistry || (exports.FormatRegistry = FormatRegistry = {}));
85
+ var ValueGuard;
86
+ (function(ValueGuard2) {
87
+ function IsArray(value) {
88
+ return Array.isArray(value);
89
+ }
90
+ ValueGuard2.IsArray = IsArray;
91
+ function IsBigInt(value) {
92
+ return typeof value === "bigint";
93
+ }
94
+ ValueGuard2.IsBigInt = IsBigInt;
95
+ function IsBoolean(value) {
96
+ return typeof value === "boolean";
97
+ }
98
+ ValueGuard2.IsBoolean = IsBoolean;
99
+ function IsDate(value) {
100
+ return value instanceof globalThis.Date;
101
+ }
102
+ ValueGuard2.IsDate = IsDate;
103
+ function IsNull(value) {
104
+ return value === null;
105
+ }
106
+ ValueGuard2.IsNull = IsNull;
107
+ function IsNumber(value) {
108
+ return typeof value === "number";
109
+ }
110
+ ValueGuard2.IsNumber = IsNumber;
111
+ function IsObject(value) {
112
+ return typeof value === "object" && value !== null;
113
+ }
114
+ ValueGuard2.IsObject = IsObject;
115
+ function IsString(value) {
116
+ return typeof value === "string";
117
+ }
118
+ ValueGuard2.IsString = IsString;
119
+ function IsUint8Array(value) {
120
+ return value instanceof globalThis.Uint8Array;
121
+ }
122
+ ValueGuard2.IsUint8Array = IsUint8Array;
123
+ function IsUndefined(value) {
124
+ return value === void 0;
125
+ }
126
+ ValueGuard2.IsUndefined = IsUndefined;
127
+ })(ValueGuard || (exports.ValueGuard = ValueGuard = {}));
128
+ var TypeGuardUnknownTypeError = class extends TypeBoxError {
129
+ };
130
+ exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
131
+ var TypeGuard;
132
+ (function(TypeGuard2) {
133
+ function IsPattern(value) {
134
+ try {
135
+ new RegExp(value);
136
+ return true;
137
+ } catch {
138
+ return false;
139
+ }
140
+ }
141
+ function IsControlCharacterFree(value) {
142
+ if (!ValueGuard.IsString(value))
143
+ return false;
144
+ for (let i = 0; i < value.length; i++) {
145
+ const code = value.charCodeAt(i);
146
+ if (code >= 7 && code <= 13 || code === 27 || code === 127) {
147
+ return false;
148
+ }
149
+ }
150
+ return true;
151
+ }
152
+ function IsAdditionalProperties(value) {
153
+ return IsOptionalBoolean(value) || TSchema(value);
154
+ }
155
+ function IsOptionalBigInt(value) {
156
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
157
+ }
158
+ function IsOptionalNumber(value) {
159
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsNumber(value);
160
+ }
161
+ function IsOptionalBoolean(value) {
162
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsBoolean(value);
163
+ }
164
+ function IsOptionalString(value) {
165
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value);
166
+ }
167
+ function IsOptionalPattern(value) {
168
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
169
+ }
170
+ function IsOptionalFormat(value) {
171
+ return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value);
172
+ }
173
+ function IsOptionalSchema(value) {
174
+ return ValueGuard.IsUndefined(value) || TSchema(value);
175
+ }
176
+ function TAny(schema) {
177
+ return TKindOf(schema, "Any") && IsOptionalString(schema.$id);
178
+ }
179
+ TypeGuard2.TAny = TAny;
180
+ function TArray(schema) {
181
+ return TKindOf(schema, "Array") && schema.type === "array" && IsOptionalString(schema.$id) && TSchema(schema.items) && IsOptionalNumber(schema.minItems) && IsOptionalNumber(schema.maxItems) && IsOptionalBoolean(schema.uniqueItems) && IsOptionalSchema(schema.contains) && IsOptionalNumber(schema.minContains) && IsOptionalNumber(schema.maxContains);
182
+ }
183
+ TypeGuard2.TArray = TArray;
184
+ function TAsyncIterator(schema) {
185
+ return TKindOf(schema, "AsyncIterator") && schema.type === "AsyncIterator" && IsOptionalString(schema.$id) && TSchema(schema.items);
186
+ }
187
+ TypeGuard2.TAsyncIterator = TAsyncIterator;
188
+ function TBigInt(schema) {
189
+ 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);
190
+ }
191
+ TypeGuard2.TBigInt = TBigInt;
192
+ function TBoolean(schema) {
193
+ return TKindOf(schema, "Boolean") && schema.type === "boolean" && IsOptionalString(schema.$id);
194
+ }
195
+ TypeGuard2.TBoolean = TBoolean;
196
+ function TConstructor(schema) {
197
+ return TKindOf(schema, "Constructor") && schema.type === "Constructor" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema(schema2)) && TSchema(schema.returns);
198
+ }
199
+ TypeGuard2.TConstructor = TConstructor;
200
+ function TDate(schema) {
201
+ 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);
202
+ }
203
+ TypeGuard2.TDate = TDate;
204
+ function TFunction(schema) {
205
+ return TKindOf(schema, "Function") && schema.type === "Function" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema(schema2)) && TSchema(schema.returns);
206
+ }
207
+ TypeGuard2.TFunction = TFunction;
208
+ function TInteger(schema) {
209
+ 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);
210
+ }
211
+ TypeGuard2.TInteger = TInteger;
212
+ function TIntersect(schema) {
213
+ return TKindOf(schema, "Intersect") && (ValueGuard.IsString(schema.type) && schema.type !== "object" ? false : true) && ValueGuard.IsArray(schema.allOf) && schema.allOf.every((schema2) => TSchema(schema2) && !TTransform(schema2)) && IsOptionalString(schema.type) && (IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) && IsOptionalString(schema.$id);
214
+ }
215
+ TypeGuard2.TIntersect = TIntersect;
216
+ function TIterator(schema) {
217
+ return TKindOf(schema, "Iterator") && schema.type === "Iterator" && IsOptionalString(schema.$id) && TSchema(schema.items);
218
+ }
219
+ TypeGuard2.TIterator = TIterator;
220
+ function TKindOf(schema, kind) {
221
+ return TKind(schema) && schema[exports.Kind] === kind;
222
+ }
223
+ TypeGuard2.TKindOf = TKindOf;
224
+ function TKind(schema) {
225
+ return ValueGuard.IsObject(schema) && exports.Kind in schema && ValueGuard.IsString(schema[exports.Kind]);
226
+ }
227
+ TypeGuard2.TKind = TKind;
228
+ function TLiteralString(schema) {
229
+ return TLiteral(schema) && ValueGuard.IsString(schema.const);
230
+ }
231
+ TypeGuard2.TLiteralString = TLiteralString;
232
+ function TLiteralNumber(schema) {
233
+ return TLiteral(schema) && ValueGuard.IsNumber(schema.const);
234
+ }
235
+ TypeGuard2.TLiteralNumber = TLiteralNumber;
236
+ function TLiteralBoolean(schema) {
237
+ return TLiteral(schema) && ValueGuard.IsBoolean(schema.const);
238
+ }
239
+ TypeGuard2.TLiteralBoolean = TLiteralBoolean;
240
+ function TLiteral(schema) {
241
+ return TKindOf(schema, "Literal") && IsOptionalString(schema.$id) && (ValueGuard.IsBoolean(schema.const) || ValueGuard.IsNumber(schema.const) || ValueGuard.IsString(schema.const));
242
+ }
243
+ TypeGuard2.TLiteral = TLiteral;
244
+ function TNever(schema) {
245
+ return TKindOf(schema, "Never") && ValueGuard.IsObject(schema.not) && Object.getOwnPropertyNames(schema.not).length === 0;
246
+ }
247
+ TypeGuard2.TNever = TNever;
248
+ function TNot(schema) {
249
+ return TKindOf(schema, "Not") && TSchema(schema.not);
250
+ }
251
+ TypeGuard2.TNot = TNot;
252
+ function TNull(schema) {
253
+ return TKindOf(schema, "Null") && schema.type === "null" && IsOptionalString(schema.$id);
254
+ }
255
+ TypeGuard2.TNull = TNull;
256
+ function TNumber(schema) {
257
+ 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);
258
+ }
259
+ TypeGuard2.TNumber = TNumber;
260
+ function TObject(schema) {
261
+ 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) && TSchema(schema2));
262
+ }
263
+ TypeGuard2.TObject = TObject;
264
+ function TPromise(schema) {
265
+ return TKindOf(schema, "Promise") && schema.type === "Promise" && IsOptionalString(schema.$id) && TSchema(schema.item);
266
+ }
267
+ TypeGuard2.TPromise = TPromise;
268
+ function TRecord(schema) {
269
+ return TKindOf(schema, "Record") && schema.type === "object" && IsOptionalString(schema.$id) && IsAdditionalProperties(schema.additionalProperties) && ValueGuard.IsObject(schema.patternProperties) && ((schema2) => {
270
+ const keys = Object.getOwnPropertyNames(schema2.patternProperties);
271
+ return keys.length === 1 && IsPattern(keys[0]) && ValueGuard.IsObject(schema2.patternProperties) && TSchema(schema2.patternProperties[keys[0]]);
272
+ })(schema);
273
+ }
274
+ TypeGuard2.TRecord = TRecord;
275
+ function TRecursive(schema) {
276
+ return ValueGuard.IsObject(schema) && exports.Hint in schema && schema[exports.Hint] === "Recursive";
277
+ }
278
+ TypeGuard2.TRecursive = TRecursive;
279
+ function TRef(schema) {
280
+ return TKindOf(schema, "Ref") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
281
+ }
282
+ TypeGuard2.TRef = TRef;
283
+ function TString(schema) {
284
+ return TKindOf(schema, "String") && schema.type === "string" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minLength) && IsOptionalNumber(schema.maxLength) && IsOptionalPattern(schema.pattern) && IsOptionalFormat(schema.format);
285
+ }
286
+ TypeGuard2.TString = TString;
287
+ function TSymbol(schema) {
288
+ return TKindOf(schema, "Symbol") && schema.type === "symbol" && IsOptionalString(schema.$id);
289
+ }
290
+ TypeGuard2.TSymbol = TSymbol;
291
+ function TTemplateLiteral(schema) {
292
+ return TKindOf(schema, "TemplateLiteral") && schema.type === "string" && ValueGuard.IsString(schema.pattern) && schema.pattern[0] === "^" && schema.pattern[schema.pattern.length - 1] === "$";
293
+ }
294
+ TypeGuard2.TTemplateLiteral = TTemplateLiteral;
295
+ function TThis(schema) {
296
+ return TKindOf(schema, "This") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
297
+ }
298
+ TypeGuard2.TThis = TThis;
299
+ function TTransform(schema) {
300
+ return ValueGuard.IsObject(schema) && exports.Transform in schema;
301
+ }
302
+ TypeGuard2.TTransform = TTransform;
303
+ function TTuple(schema) {
304
+ return TKindOf(schema, "Tuple") && schema.type === "array" && IsOptionalString(schema.$id) && ValueGuard.IsNumber(schema.minItems) && ValueGuard.IsNumber(schema.maxItems) && schema.minItems === schema.maxItems && // empty
305
+ (ValueGuard.IsUndefined(schema.items) && ValueGuard.IsUndefined(schema.additionalItems) && schema.minItems === 0 || ValueGuard.IsArray(schema.items) && schema.items.every((schema2) => TSchema(schema2)));
306
+ }
307
+ TypeGuard2.TTuple = TTuple;
308
+ function TUndefined(schema) {
309
+ return TKindOf(schema, "Undefined") && schema.type === "undefined" && IsOptionalString(schema.$id);
310
+ }
311
+ TypeGuard2.TUndefined = TUndefined;
312
+ function TUnionLiteral(schema) {
313
+ return TUnion(schema) && schema.anyOf.every((schema2) => TLiteralString(schema2) || TLiteralNumber(schema2));
314
+ }
315
+ TypeGuard2.TUnionLiteral = TUnionLiteral;
316
+ function TUnion(schema) {
317
+ return TKindOf(schema, "Union") && IsOptionalString(schema.$id) && ValueGuard.IsObject(schema) && ValueGuard.IsArray(schema.anyOf) && schema.anyOf.every((schema2) => TSchema(schema2));
318
+ }
319
+ TypeGuard2.TUnion = TUnion;
320
+ function TUint8Array(schema) {
321
+ return TKindOf(schema, "Uint8Array") && schema.type === "Uint8Array" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minByteLength) && IsOptionalNumber(schema.maxByteLength);
322
+ }
323
+ TypeGuard2.TUint8Array = TUint8Array;
324
+ function TUnknown(schema) {
325
+ return TKindOf(schema, "Unknown") && IsOptionalString(schema.$id);
326
+ }
327
+ TypeGuard2.TUnknown = TUnknown;
328
+ function TUnsafe(schema) {
329
+ return TKindOf(schema, "Unsafe");
330
+ }
331
+ TypeGuard2.TUnsafe = TUnsafe;
332
+ function TVoid(schema) {
333
+ return TKindOf(schema, "Void") && schema.type === "void" && IsOptionalString(schema.$id);
334
+ }
335
+ TypeGuard2.TVoid = TVoid;
336
+ function TReadonly(schema) {
337
+ return ValueGuard.IsObject(schema) && schema[exports.Readonly] === "Readonly";
338
+ }
339
+ TypeGuard2.TReadonly = TReadonly;
340
+ function TOptional(schema) {
341
+ return ValueGuard.IsObject(schema) && schema[exports.Optional] === "Optional";
342
+ }
343
+ TypeGuard2.TOptional = TOptional;
344
+ function TSchema(schema) {
345
+ 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]));
346
+ }
347
+ TypeGuard2.TSchema = TSchema;
348
+ })(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
349
+ var ExtendsUndefined;
350
+ (function(ExtendsUndefined2) {
351
+ function Check(schema) {
352
+ 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;
353
+ }
354
+ ExtendsUndefined2.Check = Check;
355
+ })(ExtendsUndefined || (exports.ExtendsUndefined = ExtendsUndefined = {}));
356
+ var TypeExtendsError = class extends TypeBoxError {
357
+ };
358
+ exports.TypeExtendsError = TypeExtendsError;
359
+ var TypeExtendsResult;
360
+ (function(TypeExtendsResult2) {
361
+ TypeExtendsResult2[TypeExtendsResult2["Union"] = 0] = "Union";
362
+ TypeExtendsResult2[TypeExtendsResult2["True"] = 1] = "True";
363
+ TypeExtendsResult2[TypeExtendsResult2["False"] = 2] = "False";
364
+ })(TypeExtendsResult || (exports.TypeExtendsResult = TypeExtendsResult = {}));
365
+ var TypeExtends;
366
+ (function(TypeExtends2) {
367
+ function IntoBooleanResult(result) {
368
+ return result === TypeExtendsResult.False ? result : TypeExtendsResult.True;
369
+ }
370
+ function Throw(message) {
371
+ throw new TypeExtendsError(message);
372
+ }
373
+ function IsStructuralRight(right) {
374
+ return TypeGuard.TNever(right) || TypeGuard.TIntersect(right) || TypeGuard.TUnion(right) || TypeGuard.TUnknown(right) || TypeGuard.TAny(right);
375
+ }
376
+ function StructuralRight(left, right) {
377
+ 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");
378
+ }
379
+ function TAnyRight(left, right) {
380
+ return TypeExtendsResult.True;
381
+ }
382
+ function TAny(left, right) {
383
+ 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;
384
+ }
385
+ function TArrayRight(left, right) {
386
+ return TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
387
+ }
388
+ function TArray(left, right) {
389
+ return TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TArray(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
390
+ }
391
+ function TAsyncIterator(left, right) {
392
+ return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TAsyncIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
393
+ }
394
+ function TBigInt(left, right) {
395
+ 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;
396
+ }
397
+ function TBooleanRight(left, right) {
398
+ return TypeGuard.TLiteral(left) && ValueGuard.IsBoolean(left.const) ? TypeExtendsResult.True : TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
399
+ }
400
+ function TBoolean(left, right) {
401
+ 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;
402
+ }
403
+ function TConstructor(left, right) {
404
+ 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));
405
+ }
406
+ function TDate(left, right) {
407
+ 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;
408
+ }
409
+ function TFunction(left, right) {
410
+ 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));
411
+ }
412
+ function TIntegerRight(left, right) {
413
+ return TypeGuard.TLiteral(left) && ValueGuard.IsNumber(left.const) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
414
+ }
415
+ function TInteger(left, right) {
416
+ 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;
417
+ }
418
+ function TIntersectRight(left, right) {
419
+ return right.allOf.every((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
420
+ }
421
+ function TIntersect(left, right) {
422
+ return left.allOf.some((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
423
+ }
424
+ function TIterator(left, right) {
425
+ return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
426
+ }
427
+ function TLiteral(left, right) {
428
+ 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;
429
+ }
430
+ function TNeverRight(left, right) {
431
+ return TypeExtendsResult.False;
432
+ }
433
+ function TNever(left, right) {
434
+ return TypeExtendsResult.True;
435
+ }
436
+ function UnwrapTNot(schema) {
437
+ let [current, depth] = [schema, 0];
438
+ while (true) {
439
+ if (!TypeGuard.TNot(current))
440
+ break;
441
+ current = current.not;
442
+ depth += 1;
443
+ }
444
+ return depth % 2 === 0 ? current : exports.Type.Unknown();
445
+ }
446
+ function TNot(left, right) {
447
+ return TypeGuard.TNot(left) ? Visit(UnwrapTNot(left), right) : TypeGuard.TNot(right) ? Visit(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
448
+ }
449
+ function TNull(left, right) {
450
+ 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;
451
+ }
452
+ function TNumberRight(left, right) {
453
+ return TypeGuard.TLiteralNumber(left) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
454
+ }
455
+ function TNumber(left, right) {
456
+ 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;
457
+ }
458
+ function IsObjectPropertyCount(schema, count) {
459
+ return Object.getOwnPropertyNames(schema.properties).length === count;
460
+ }
461
+ function IsObjectStringLike(schema) {
462
+ return IsObjectArrayLike(schema);
463
+ }
464
+ function IsObjectSymbolLike(schema) {
465
+ 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]));
466
+ }
467
+ function IsObjectNumberLike(schema) {
468
+ return IsObjectPropertyCount(schema, 0);
469
+ }
470
+ function IsObjectBooleanLike(schema) {
471
+ return IsObjectPropertyCount(schema, 0);
472
+ }
473
+ function IsObjectBigIntLike(schema) {
474
+ return IsObjectPropertyCount(schema, 0);
475
+ }
476
+ function IsObjectDateLike(schema) {
477
+ return IsObjectPropertyCount(schema, 0);
478
+ }
479
+ function IsObjectUint8ArrayLike(schema) {
480
+ return IsObjectArrayLike(schema);
481
+ }
482
+ function IsObjectFunctionLike(schema) {
483
+ const length = exports.Type.Number();
484
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
485
+ }
486
+ function IsObjectConstructorLike(schema) {
487
+ return IsObjectPropertyCount(schema, 0);
488
+ }
489
+ function IsObjectArrayLike(schema) {
490
+ const length = exports.Type.Number();
491
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
492
+ }
493
+ function IsObjectPromiseLike(schema) {
494
+ const then = exports.Type.Function([exports.Type.Any()], exports.Type.Any());
495
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit(schema.properties["then"], then)) === TypeExtendsResult.True;
496
+ }
497
+ function Property(left, right) {
498
+ return Visit(left, right) === TypeExtendsResult.False ? TypeExtendsResult.False : TypeGuard.TOptional(left) && !TypeGuard.TOptional(right) ? TypeExtendsResult.False : TypeExtendsResult.True;
499
+ }
500
+ function TObjectRight(left, right) {
501
+ 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)) ? (() => {
502
+ return right[exports.Hint] === "Record" ? TypeExtendsResult.True : TypeExtendsResult.False;
503
+ })() : TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left)) ? (() => {
504
+ return IsObjectPropertyCount(right, 0) ? TypeExtendsResult.True : TypeExtendsResult.False;
505
+ })() : TypeExtendsResult.False;
506
+ }
507
+ function TObject(left, right) {
508
+ return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : !TypeGuard.TObject(right) ? TypeExtendsResult.False : (() => {
509
+ for (const key of Object.getOwnPropertyNames(right.properties)) {
510
+ if (!(key in left.properties) && !TypeGuard.TOptional(right.properties[key])) {
511
+ return TypeExtendsResult.False;
512
+ }
513
+ if (TypeGuard.TOptional(right.properties[key])) {
514
+ return TypeExtendsResult.True;
515
+ }
516
+ if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
517
+ return TypeExtendsResult.False;
518
+ }
519
+ }
520
+ return TypeExtendsResult.True;
521
+ })();
522
+ }
523
+ function TPromise(left, right) {
524
+ return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) && IsObjectPromiseLike(right) ? TypeExtendsResult.True : !TypeGuard.TPromise(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.item, right.item));
525
+ }
526
+ function RecordKey(schema) {
527
+ return exports.PatternNumberExact in schema.patternProperties ? exports.Type.Number() : exports.PatternStringExact in schema.patternProperties ? exports.Type.String() : Throw("Unknown record key pattern");
528
+ }
529
+ function RecordValue(schema) {
530
+ 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");
531
+ }
532
+ function TRecordRight(left, right) {
533
+ const [Key, Value] = [RecordKey(right), RecordValue(right)];
534
+ 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) ? (() => {
535
+ for (const key of Object.getOwnPropertyNames(left.properties)) {
536
+ if (Property(Value, left.properties[key]) === TypeExtendsResult.False) {
537
+ return TypeExtendsResult.False;
538
+ }
539
+ }
540
+ return TypeExtendsResult.True;
541
+ })() : TypeExtendsResult.False;
542
+ }
543
+ function TRecord(left, right) {
544
+ return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TRecord(right) ? TypeExtendsResult.False : Visit(RecordValue(left), RecordValue(right));
545
+ }
546
+ function TStringRight(left, right) {
547
+ return TypeGuard.TLiteral(left) && ValueGuard.IsString(left.const) ? TypeExtendsResult.True : TypeGuard.TString(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
548
+ }
549
+ function TString(left, right) {
550
+ 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;
551
+ }
552
+ function TSymbol(left, right) {
553
+ 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;
554
+ }
555
+ function TTemplateLiteral(left, right) {
556
+ return TypeGuard.TTemplateLiteral(left) ? Visit(TemplateLiteralResolver.Resolve(left), right) : TypeGuard.TTemplateLiteral(right) ? Visit(left, TemplateLiteralResolver.Resolve(right)) : Throw("Invalid fallthrough for TemplateLiteral");
557
+ }
558
+ function IsArrayOfTuple(left, right) {
559
+ return TypeGuard.TArray(right) && left.items !== void 0 && left.items.every((schema) => Visit(schema, right.items) === TypeExtendsResult.True);
560
+ }
561
+ function TTupleRight(left, right) {
562
+ return TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeExtendsResult.False;
563
+ }
564
+ function TTuple(left, right) {
565
+ 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;
566
+ }
567
+ function TUint8Array(left, right) {
568
+ 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;
569
+ }
570
+ function TUndefined(left, right) {
571
+ 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;
572
+ }
573
+ function TUnionRight(left, right) {
574
+ return right.anyOf.some((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
575
+ }
576
+ function TUnion(left, right) {
577
+ return left.anyOf.every((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
578
+ }
579
+ function TUnknownRight(left, right) {
580
+ return TypeExtendsResult.True;
581
+ }
582
+ function TUnknown(left, right) {
583
+ 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;
584
+ }
585
+ function VoidRight(left, right) {
586
+ return TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
587
+ }
588
+ function TVoid(left, right) {
589
+ 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;
590
+ }
591
+ function Visit(left, right) {
592
+ return (
593
+ // resolvable
594
+ TypeGuard.TTemplateLiteral(left) || TypeGuard.TTemplateLiteral(right) ? TTemplateLiteral(left, right) : TypeGuard.TNot(left) || TypeGuard.TNot(right) ? TNot(left, right) : (
595
+ // standard
596
+ 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]}'`)
597
+ )
598
+ );
599
+ }
600
+ function Extends(left, right) {
601
+ return Visit(left, right);
602
+ }
603
+ TypeExtends2.Extends = Extends;
604
+ })(TypeExtends || (exports.TypeExtends = TypeExtends = {}));
605
+ var TypeClone;
606
+ (function(TypeClone2) {
607
+ function ArrayType(value) {
608
+ return value.map((value2) => Visit(value2));
609
+ }
610
+ function DateType(value) {
611
+ return new Date(value.getTime());
612
+ }
613
+ function Uint8ArrayType(value) {
614
+ return new Uint8Array(value);
615
+ }
616
+ function ObjectType(value) {
617
+ const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
618
+ const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
619
+ return { ...clonedProperties, ...clonedSymbols };
620
+ }
621
+ function Visit(value) {
622
+ return ValueGuard.IsArray(value) ? ArrayType(value) : ValueGuard.IsDate(value) ? DateType(value) : ValueGuard.IsUint8Array(value) ? Uint8ArrayType(value) : ValueGuard.IsObject(value) ? ObjectType(value) : value;
623
+ }
624
+ function Rest(schemas) {
625
+ return schemas.map((schema) => Type(schema));
626
+ }
627
+ TypeClone2.Rest = Rest;
628
+ function Type(schema, options = {}) {
629
+ return { ...Visit(schema), ...options };
630
+ }
631
+ TypeClone2.Type = Type;
632
+ })(TypeClone || (exports.TypeClone = TypeClone = {}));
633
+ var IndexedAccessor;
634
+ (function(IndexedAccessor2) {
635
+ function OptionalUnwrap(schema) {
636
+ return schema.map((schema2) => {
637
+ const { [exports.Optional]: _, ...clone } = TypeClone.Type(schema2);
638
+ return clone;
639
+ });
640
+ }
641
+ function IsIntersectOptional(schema) {
642
+ return schema.every((schema2) => TypeGuard.TOptional(schema2));
643
+ }
644
+ function IsUnionOptional(schema) {
645
+ return schema.some((schema2) => TypeGuard.TOptional(schema2));
646
+ }
647
+ function ResolveIntersect(schema) {
648
+ return IsIntersectOptional(schema.allOf) ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
649
+ }
650
+ function ResolveUnion(schema) {
651
+ return IsUnionOptional(schema.anyOf) ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
652
+ }
653
+ function ResolveOptional(schema) {
654
+ return schema[exports.Kind] === "Intersect" ? ResolveIntersect(schema) : schema[exports.Kind] === "Union" ? ResolveUnion(schema) : schema;
655
+ }
656
+ function TIntersect(schema, key) {
657
+ const resolved = schema.allOf.reduce((acc, schema2) => {
658
+ const indexed = Visit(schema2, key);
659
+ return indexed[exports.Kind] === "Never" ? acc : [...acc, indexed];
660
+ }, []);
661
+ return ResolveOptional(exports.Type.Intersect(resolved));
662
+ }
663
+ function TUnion(schema, key) {
664
+ const resolved = schema.anyOf.map((schema2) => Visit(schema2, key));
665
+ return ResolveOptional(exports.Type.Union(resolved));
666
+ }
667
+ function TObject(schema, key) {
668
+ const property = schema.properties[key];
669
+ return ValueGuard.IsUndefined(property) ? exports.Type.Never() : exports.Type.Union([property]);
670
+ }
671
+ function TTuple(schema, key) {
672
+ const items = schema.items;
673
+ if (ValueGuard.IsUndefined(items))
674
+ return exports.Type.Never();
675
+ const element = items[key];
676
+ if (ValueGuard.IsUndefined(element))
677
+ return exports.Type.Never();
678
+ return element;
679
+ }
680
+ function Visit(schema, key) {
681
+ 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();
682
+ }
683
+ function Resolve(schema, keys, options = {}) {
684
+ const resolved = keys.map((key) => Visit(schema, key.toString()));
685
+ return ResolveOptional(exports.Type.Union(resolved, options));
686
+ }
687
+ IndexedAccessor2.Resolve = Resolve;
688
+ })(IndexedAccessor || (exports.IndexedAccessor = IndexedAccessor = {}));
689
+ var Intrinsic;
690
+ (function(Intrinsic2) {
691
+ function Uncapitalize(value) {
692
+ const [first, rest] = [value.slice(0, 1), value.slice(1)];
693
+ return `${first.toLowerCase()}${rest}`;
694
+ }
695
+ function Capitalize(value) {
696
+ const [first, rest] = [value.slice(0, 1), value.slice(1)];
697
+ return `${first.toUpperCase()}${rest}`;
698
+ }
699
+ function Uppercase(value) {
700
+ return value.toUpperCase();
701
+ }
702
+ function Lowercase(value) {
703
+ return value.toLowerCase();
704
+ }
705
+ function IntrinsicTemplateLiteral(schema, mode) {
706
+ const expression = TemplateLiteralParser.ParseExact(schema.pattern);
707
+ const finite = TemplateLiteralFinite.Check(expression);
708
+ if (!finite)
709
+ return { ...schema, pattern: IntrinsicLiteral(schema.pattern, mode) };
710
+ const strings = [...TemplateLiteralGenerator.Generate(expression)];
711
+ const literals = strings.map((value) => exports.Type.Literal(value));
712
+ const mapped = IntrinsicRest(literals, mode);
713
+ const union = exports.Type.Union(mapped);
714
+ return exports.Type.TemplateLiteral([union]);
715
+ }
716
+ function IntrinsicLiteral(value, mode) {
717
+ return typeof value === "string" ? mode === "Uncapitalize" ? Uncapitalize(value) : mode === "Capitalize" ? Capitalize(value) : mode === "Uppercase" ? Uppercase(value) : mode === "Lowercase" ? Lowercase(value) : value : value.toString();
718
+ }
719
+ function IntrinsicRest(schema, mode) {
720
+ if (schema.length === 0)
721
+ return [];
722
+ const [L, ...R] = schema;
723
+ return [Map2(L, mode), ...IntrinsicRest(R, mode)];
724
+ }
725
+ function Visit(schema, mode) {
726
+ 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;
727
+ }
728
+ function Map2(schema, mode) {
729
+ return Visit(schema, mode);
730
+ }
731
+ Intrinsic2.Map = Map2;
732
+ })(Intrinsic || (exports.Intrinsic = Intrinsic = {}));
733
+ var ObjectMap;
734
+ (function(ObjectMap2) {
735
+ function TIntersect(schema, callback) {
736
+ return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
737
+ }
738
+ function TUnion(schema, callback) {
739
+ return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
740
+ }
741
+ function TObject(schema, callback) {
742
+ return callback(schema);
743
+ }
744
+ function Visit(schema, callback) {
745
+ return schema[exports.Kind] === "Intersect" ? TIntersect(schema, callback) : schema[exports.Kind] === "Union" ? TUnion(schema, callback) : schema[exports.Kind] === "Object" ? TObject(schema, callback) : schema;
746
+ }
747
+ function Map2(schema, callback, options) {
748
+ return { ...Visit(TypeClone.Type(schema), callback), ...options };
749
+ }
750
+ ObjectMap2.Map = Map2;
751
+ })(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
752
+ var KeyResolver;
753
+ (function(KeyResolver2) {
754
+ function UnwrapPattern(key) {
755
+ return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
756
+ }
757
+ function TIntersect(schema, options) {
758
+ return schema.allOf.reduce((acc, schema2) => [...acc, ...Visit(schema2, options)], []);
759
+ }
760
+ function TUnion(schema, options) {
761
+ const sets = schema.anyOf.map((inner) => Visit(inner, options));
762
+ return [...sets.reduce((set, outer) => outer.map((key) => sets.every((inner) => inner.includes(key)) ? set.add(key) : set)[0], /* @__PURE__ */ new Set())];
763
+ }
764
+ function TObject(schema, options) {
765
+ return Object.getOwnPropertyNames(schema.properties);
766
+ }
767
+ function TRecord(schema, options) {
768
+ return options.includePatterns ? Object.getOwnPropertyNames(schema.patternProperties) : [];
769
+ }
770
+ function Visit(schema, options) {
771
+ 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) : [];
772
+ }
773
+ function ResolveKeys(schema, options) {
774
+ return [...new Set(Visit(schema, options))];
775
+ }
776
+ KeyResolver2.ResolveKeys = ResolveKeys;
777
+ function ResolvePattern(schema) {
778
+ const keys = ResolveKeys(schema, { includePatterns: true });
779
+ const pattern = keys.map((key) => `(${UnwrapPattern(key)})`);
780
+ return `^(${pattern.join("|")})$`;
781
+ }
782
+ KeyResolver2.ResolvePattern = ResolvePattern;
783
+ })(KeyResolver || (exports.KeyResolver = KeyResolver = {}));
784
+ var KeyArrayResolverError = class extends TypeBoxError {
785
+ };
786
+ exports.KeyArrayResolverError = KeyArrayResolverError;
787
+ var KeyArrayResolver;
788
+ (function(KeyArrayResolver2) {
789
+ function Resolve(schema) {
790
+ return Array.isArray(schema) ? schema : TypeGuard.TUnionLiteral(schema) ? schema.anyOf.map((schema2) => schema2.const.toString()) : TypeGuard.TLiteral(schema) ? [schema.const] : TypeGuard.TTemplateLiteral(schema) ? (() => {
791
+ const expression = TemplateLiteralParser.ParseExact(schema.pattern);
792
+ if (!TemplateLiteralFinite.Check(expression))
793
+ throw new KeyArrayResolverError("Cannot resolve keys from infinite template expression");
794
+ return [...TemplateLiteralGenerator.Generate(expression)];
795
+ })() : [];
796
+ }
797
+ KeyArrayResolver2.Resolve = Resolve;
798
+ })(KeyArrayResolver || (exports.KeyArrayResolver = KeyArrayResolver = {}));
799
+ var UnionResolver;
800
+ (function(UnionResolver2) {
801
+ function* TUnion(union) {
802
+ for (const schema of union.anyOf) {
803
+ if (schema[exports.Kind] === "Union") {
804
+ yield* TUnion(schema);
805
+ } else {
806
+ yield schema;
807
+ }
808
+ }
809
+ }
810
+ function Resolve(union) {
811
+ return exports.Type.Union([...TUnion(union)], { ...union });
812
+ }
813
+ UnionResolver2.Resolve = Resolve;
814
+ })(UnionResolver || (exports.UnionResolver = UnionResolver = {}));
815
+ var TemplateLiteralPatternError = class extends TypeBoxError {
816
+ };
817
+ exports.TemplateLiteralPatternError = TemplateLiteralPatternError;
818
+ var TemplateLiteralPattern;
819
+ (function(TemplateLiteralPattern2) {
820
+ function Throw(message) {
821
+ throw new TemplateLiteralPatternError(message);
822
+ }
823
+ function Escape(value) {
824
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
825
+ }
826
+ function Visit(schema, acc) {
827
+ 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]}'`);
828
+ }
829
+ function Create(kinds) {
830
+ return `^${kinds.map((schema) => Visit(schema, "")).join("")}$`;
831
+ }
832
+ TemplateLiteralPattern2.Create = Create;
833
+ })(TemplateLiteralPattern || (exports.TemplateLiteralPattern = TemplateLiteralPattern = {}));
834
+ var TemplateLiteralResolver;
835
+ (function(TemplateLiteralResolver2) {
836
+ function Resolve(template) {
837
+ const expression = TemplateLiteralParser.ParseExact(template.pattern);
838
+ if (!TemplateLiteralFinite.Check(expression))
839
+ return exports.Type.String();
840
+ const literals = [...TemplateLiteralGenerator.Generate(expression)].map((value) => exports.Type.Literal(value));
841
+ return exports.Type.Union(literals);
842
+ }
843
+ TemplateLiteralResolver2.Resolve = Resolve;
844
+ })(TemplateLiteralResolver || (exports.TemplateLiteralResolver = TemplateLiteralResolver = {}));
845
+ var TemplateLiteralParserError = class extends TypeBoxError {
846
+ };
847
+ exports.TemplateLiteralParserError = TemplateLiteralParserError;
848
+ var TemplateLiteralParser;
849
+ (function(TemplateLiteralParser2) {
850
+ function IsNonEscaped(pattern, index, char) {
851
+ return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
852
+ }
853
+ function IsOpenParen(pattern, index) {
854
+ return IsNonEscaped(pattern, index, "(");
855
+ }
856
+ function IsCloseParen(pattern, index) {
857
+ return IsNonEscaped(pattern, index, ")");
858
+ }
859
+ function IsSeparator(pattern, index) {
860
+ return IsNonEscaped(pattern, index, "|");
861
+ }
862
+ function IsGroup(pattern) {
863
+ if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
864
+ return false;
865
+ let count = 0;
866
+ for (let index = 0; index < pattern.length; index++) {
867
+ if (IsOpenParen(pattern, index))
868
+ count += 1;
869
+ if (IsCloseParen(pattern, index))
870
+ count -= 1;
871
+ if (count === 0 && index !== pattern.length - 1)
872
+ return false;
873
+ }
874
+ return true;
875
+ }
876
+ function InGroup(pattern) {
877
+ return pattern.slice(1, pattern.length - 1);
878
+ }
879
+ function IsPrecedenceOr(pattern) {
880
+ let count = 0;
881
+ for (let index = 0; index < pattern.length; index++) {
882
+ if (IsOpenParen(pattern, index))
883
+ count += 1;
884
+ if (IsCloseParen(pattern, index))
885
+ count -= 1;
886
+ if (IsSeparator(pattern, index) && count === 0)
887
+ return true;
888
+ }
889
+ return false;
890
+ }
891
+ function IsPrecedenceAnd(pattern) {
892
+ for (let index = 0; index < pattern.length; index++) {
893
+ if (IsOpenParen(pattern, index))
894
+ return true;
895
+ }
896
+ return false;
897
+ }
898
+ function Or(pattern) {
899
+ let [count, start] = [0, 0];
900
+ const expressions = [];
901
+ for (let index = 0; index < pattern.length; index++) {
902
+ if (IsOpenParen(pattern, index))
903
+ count += 1;
904
+ if (IsCloseParen(pattern, index))
905
+ count -= 1;
906
+ if (IsSeparator(pattern, index) && count === 0) {
907
+ const range2 = pattern.slice(start, index);
908
+ if (range2.length > 0)
909
+ expressions.push(Parse(range2));
910
+ start = index + 1;
911
+ }
912
+ }
913
+ const range = pattern.slice(start);
914
+ if (range.length > 0)
915
+ expressions.push(Parse(range));
916
+ if (expressions.length === 0)
917
+ return { type: "const", const: "" };
918
+ if (expressions.length === 1)
919
+ return expressions[0];
920
+ return { type: "or", expr: expressions };
921
+ }
922
+ function And(pattern) {
923
+ function Group(value, index) {
924
+ if (!IsOpenParen(value, index))
925
+ throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
926
+ let count = 0;
927
+ for (let scan = index; scan < value.length; scan++) {
928
+ if (IsOpenParen(value, scan))
929
+ count += 1;
930
+ if (IsCloseParen(value, scan))
931
+ count -= 1;
932
+ if (count === 0)
933
+ return [index, scan];
934
+ }
935
+ throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
936
+ }
937
+ function Range(pattern2, index) {
938
+ for (let scan = index; scan < pattern2.length; scan++) {
939
+ if (IsOpenParen(pattern2, scan))
940
+ return [index, scan];
941
+ }
942
+ return [index, pattern2.length];
943
+ }
944
+ const expressions = [];
945
+ for (let index = 0; index < pattern.length; index++) {
946
+ if (IsOpenParen(pattern, index)) {
947
+ const [start, end] = Group(pattern, index);
948
+ const range = pattern.slice(start, end + 1);
949
+ expressions.push(Parse(range));
950
+ index = end;
951
+ } else {
952
+ const [start, end] = Range(pattern, index);
953
+ const range = pattern.slice(start, end);
954
+ if (range.length > 0)
955
+ expressions.push(Parse(range));
956
+ index = end - 1;
957
+ }
958
+ }
959
+ return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
960
+ }
961
+ function Parse(pattern) {
962
+ return IsGroup(pattern) ? Parse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: pattern };
963
+ }
964
+ TemplateLiteralParser2.Parse = Parse;
965
+ function ParseExact(pattern) {
966
+ return Parse(pattern.slice(1, pattern.length - 1));
967
+ }
968
+ TemplateLiteralParser2.ParseExact = ParseExact;
969
+ })(TemplateLiteralParser || (exports.TemplateLiteralParser = TemplateLiteralParser = {}));
970
+ var TemplateLiteralFiniteError = class extends TypeBoxError {
971
+ };
972
+ exports.TemplateLiteralFiniteError = TemplateLiteralFiniteError;
973
+ var TemplateLiteralFinite;
974
+ (function(TemplateLiteralFinite2) {
975
+ function Throw(message) {
976
+ throw new TemplateLiteralFiniteError(message);
977
+ }
978
+ function IsNumber(expression) {
979
+ 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]*";
980
+ }
981
+ function IsBoolean(expression) {
982
+ 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";
983
+ }
984
+ function IsString(expression) {
985
+ return expression.type === "const" && expression.const === ".*";
986
+ }
987
+ function Check(expression) {
988
+ 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`);
989
+ }
990
+ TemplateLiteralFinite2.Check = Check;
991
+ })(TemplateLiteralFinite || (exports.TemplateLiteralFinite = TemplateLiteralFinite = {}));
992
+ var TemplateLiteralGeneratorError = class extends TypeBoxError {
993
+ };
994
+ exports.TemplateLiteralGeneratorError = TemplateLiteralGeneratorError;
995
+ var TemplateLiteralGenerator;
996
+ (function(TemplateLiteralGenerator2) {
997
+ function* Reduce(buffer) {
998
+ if (buffer.length === 1)
999
+ return yield* buffer[0];
1000
+ for (const left of buffer[0]) {
1001
+ for (const right of Reduce(buffer.slice(1))) {
1002
+ yield `${left}${right}`;
1003
+ }
1004
+ }
1005
+ }
1006
+ function* And(expression) {
1007
+ return yield* Reduce(expression.expr.map((expr) => [...Generate(expr)]));
1008
+ }
1009
+ function* Or(expression) {
1010
+ for (const expr of expression.expr)
1011
+ yield* Generate(expr);
1012
+ }
1013
+ function* Const(expression) {
1014
+ return yield expression.const;
1015
+ }
1016
+ function* Generate(expression) {
1017
+ return expression.type === "and" ? yield* And(expression) : expression.type === "or" ? yield* Or(expression) : expression.type === "const" ? yield* Const(expression) : (() => {
1018
+ throw new TemplateLiteralGeneratorError("Unknown expression");
1019
+ })();
1020
+ }
1021
+ TemplateLiteralGenerator2.Generate = Generate;
1022
+ })(TemplateLiteralGenerator || (exports.TemplateLiteralGenerator = TemplateLiteralGenerator = {}));
1023
+ var TemplateLiteralDslParser;
1024
+ (function(TemplateLiteralDslParser2) {
1025
+ function* ParseUnion(template) {
1026
+ const trim = template.trim().replace(/"|'/g, "");
1027
+ 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 (() => {
1028
+ const literals = trim.split("|").map((literal) => exports.Type.Literal(literal.trim()));
1029
+ return literals.length === 0 ? exports.Type.Never() : literals.length === 1 ? literals[0] : exports.Type.Union(literals);
1030
+ })();
1031
+ }
1032
+ function* ParseTerminal(template) {
1033
+ if (template[1] !== "{") {
1034
+ const L = exports.Type.Literal("$");
1035
+ const R = ParseLiteral(template.slice(1));
1036
+ return yield* [L, ...R];
1037
+ }
1038
+ for (let i = 2; i < template.length; i++) {
1039
+ if (template[i] === "}") {
1040
+ const L = ParseUnion(template.slice(2, i));
1041
+ const R = ParseLiteral(template.slice(i + 1));
1042
+ return yield* [...L, ...R];
1043
+ }
1044
+ }
1045
+ yield exports.Type.Literal(template);
1046
+ }
1047
+ function* ParseLiteral(template) {
1048
+ for (let i = 0; i < template.length; i++) {
1049
+ if (template[i] === "$") {
1050
+ const L = exports.Type.Literal(template.slice(0, i));
1051
+ const R = ParseTerminal(template.slice(i));
1052
+ return yield* [L, ...R];
1053
+ }
1054
+ }
1055
+ yield exports.Type.Literal(template);
1056
+ }
1057
+ function Parse(template_dsl) {
1058
+ return [...ParseLiteral(template_dsl)];
1059
+ }
1060
+ TemplateLiteralDslParser2.Parse = Parse;
1061
+ })(TemplateLiteralDslParser || (exports.TemplateLiteralDslParser = TemplateLiteralDslParser = {}));
1062
+ var TransformDecodeBuilder = class {
1063
+ constructor(schema) {
1064
+ this.schema = schema;
1065
+ }
1066
+ Decode(decode) {
1067
+ return new TransformEncodeBuilder(this.schema, decode);
1068
+ }
1069
+ };
1070
+ exports.TransformDecodeBuilder = TransformDecodeBuilder;
1071
+ var TransformEncodeBuilder = class {
1072
+ constructor(schema, decode) {
1073
+ this.schema = schema;
1074
+ this.decode = decode;
1075
+ }
1076
+ Encode(encode) {
1077
+ const schema = TypeClone.Type(this.schema);
1078
+ return TypeGuard.TTransform(schema) ? (() => {
1079
+ const Encode = (value) => schema[exports.Transform].Encode(encode(value));
1080
+ const Decode = (value) => this.decode(schema[exports.Transform].Decode(value));
1081
+ const Codec = { Encode, Decode };
1082
+ return { ...schema, [exports.Transform]: Codec };
1083
+ })() : (() => {
1084
+ const Codec = { Decode: this.decode, Encode: encode };
1085
+ return { ...schema, [exports.Transform]: Codec };
1086
+ })();
1087
+ }
1088
+ };
1089
+ exports.TransformEncodeBuilder = TransformEncodeBuilder;
1090
+ var TypeOrdinal = 0;
1091
+ var TypeBuilderError = class extends TypeBoxError {
1092
+ };
1093
+ exports.TypeBuilderError = TypeBuilderError;
1094
+ var TypeBuilder = class {
1095
+ /** `[Internal]` Creates a schema without `static` and `params` types */
1096
+ Create(schema) {
1097
+ return schema;
1098
+ }
1099
+ /** `[Internal]` Throws a TypeBuilder error with the given message */
1100
+ Throw(message) {
1101
+ throw new TypeBuilderError(message);
1102
+ }
1103
+ /** `[Internal]` Discards property keys from the given record type */
1104
+ Discard(record, keys) {
1105
+ return keys.reduce((acc, key) => {
1106
+ const { [key]: _, ...rest } = acc;
1107
+ return rest;
1108
+ }, record);
1109
+ }
1110
+ /** `[Json]` Omits compositing symbols from this schema */
1111
+ Strict(schema) {
1112
+ return JSON.parse(JSON.stringify(schema));
1113
+ }
1114
+ };
1115
+ exports.TypeBuilder = TypeBuilder;
1116
+ var JsonTypeBuilder = class extends TypeBuilder {
1117
+ // ------------------------------------------------------------------------
1118
+ // Modifiers
1119
+ // ------------------------------------------------------------------------
1120
+ /** `[Json]` Creates a Readonly and Optional property */
1121
+ ReadonlyOptional(schema) {
1122
+ return this.Readonly(this.Optional(schema));
1123
+ }
1124
+ /** `[Json]` Creates a Readonly property */
1125
+ Readonly(schema) {
1126
+ return { ...TypeClone.Type(schema), [exports.Readonly]: "Readonly" };
1127
+ }
1128
+ /** `[Json]` Creates an Optional property */
1129
+ Optional(schema) {
1130
+ return { ...TypeClone.Type(schema), [exports.Optional]: "Optional" };
1131
+ }
1132
+ // ------------------------------------------------------------------------
1133
+ // Types
1134
+ // ------------------------------------------------------------------------
1135
+ /** `[Json]` Creates an Any type */
1136
+ Any(options = {}) {
1137
+ return this.Create({ ...options, [exports.Kind]: "Any" });
1138
+ }
1139
+ /** `[Json]` Creates an Array type */
1140
+ Array(schema, options = {}) {
1141
+ return this.Create({ ...options, [exports.Kind]: "Array", type: "array", items: TypeClone.Type(schema) });
1142
+ }
1143
+ /** `[Json]` Creates a Boolean type */
1144
+ Boolean(options = {}) {
1145
+ return this.Create({ ...options, [exports.Kind]: "Boolean", type: "boolean" });
1146
+ }
1147
+ /** `[Json]` Intrinsic function to Capitalize LiteralString types */
1148
+ Capitalize(schema, options = {}) {
1149
+ return { ...Intrinsic.Map(TypeClone.Type(schema), "Capitalize"), ...options };
1150
+ }
1151
+ /** `[Json]` Creates a Composite object type */
1152
+ Composite(objects, options) {
1153
+ const intersect = exports.Type.Intersect(objects, {});
1154
+ const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
1155
+ const properties = keys.reduce((acc, key) => ({ ...acc, [key]: exports.Type.Index(intersect, [key]) }), {});
1156
+ return exports.Type.Object(properties, options);
1157
+ }
1158
+ /** `[Json]` Creates a Enum type */
1159
+ Enum(item, options = {}) {
1160
+ if (ValueGuard.IsUndefined(item))
1161
+ return this.Throw("Enum undefined or empty");
1162
+ const values1 = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
1163
+ const values2 = [...new Set(values1)];
1164
+ const anyOf = values2.map((value) => exports.Type.Literal(value));
1165
+ return this.Union(anyOf, { ...options, [exports.Hint]: "Enum" });
1166
+ }
1167
+ /** `[Json]` Creates a Conditional type */
1168
+ Extends(left, right, trueType, falseType, options = {}) {
1169
+ switch (TypeExtends.Extends(left, right)) {
1170
+ case TypeExtendsResult.Union:
1171
+ return this.Union([TypeClone.Type(trueType, options), TypeClone.Type(falseType, options)]);
1172
+ case TypeExtendsResult.True:
1173
+ return TypeClone.Type(trueType, options);
1174
+ case TypeExtendsResult.False:
1175
+ return TypeClone.Type(falseType, options);
1176
+ }
1177
+ }
1178
+ /** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
1179
+ Exclude(unionType, excludedMembers, options = {}) {
1180
+ return TypeGuard.TTemplateLiteral(unionType) ? this.Exclude(TemplateLiteralResolver.Resolve(unionType), excludedMembers, options) : TypeGuard.TTemplateLiteral(excludedMembers) ? this.Exclude(unionType, TemplateLiteralResolver.Resolve(excludedMembers), options) : TypeGuard.TUnion(unionType) ? (() => {
1181
+ const narrowed = unionType.anyOf.filter((inner) => TypeExtends.Extends(inner, excludedMembers) === TypeExtendsResult.False);
1182
+ return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
1183
+ })() : TypeExtends.Extends(unionType, excludedMembers) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Type(unionType, options);
1184
+ }
1185
+ /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
1186
+ Extract(type, union, options = {}) {
1187
+ return TypeGuard.TTemplateLiteral(type) ? this.Extract(TemplateLiteralResolver.Resolve(type), union, options) : TypeGuard.TTemplateLiteral(union) ? this.Extract(type, TemplateLiteralResolver.Resolve(union), options) : TypeGuard.TUnion(type) ? (() => {
1188
+ const narrowed = type.anyOf.filter((inner) => TypeExtends.Extends(inner, union) !== TypeExtendsResult.False);
1189
+ return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
1190
+ })() : TypeExtends.Extends(type, union) !== TypeExtendsResult.False ? TypeClone.Type(type, options) : this.Never(options);
1191
+ }
1192
+ /** `[Json]` Returns an Indexed property type for the given keys */
1193
+ Index(schema, unresolved, options = {}) {
1194
+ return TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved) ? (() => {
1195
+ return TypeClone.Type(schema.items, options);
1196
+ })() : TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved) ? (() => {
1197
+ const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
1198
+ const cloned = items.map((schema2) => TypeClone.Type(schema2));
1199
+ return this.Union(cloned, options);
1200
+ })() : (() => {
1201
+ const keys = KeyArrayResolver.Resolve(unresolved);
1202
+ const clone = TypeClone.Type(schema);
1203
+ return IndexedAccessor.Resolve(clone, keys, options);
1204
+ })();
1205
+ }
1206
+ /** `[Json]` Creates an Integer type */
1207
+ Integer(options = {}) {
1208
+ return this.Create({ ...options, [exports.Kind]: "Integer", type: "integer" });
1209
+ }
1210
+ /** `[Json]` Creates an Intersect type */
1211
+ Intersect(allOf, options = {}) {
1212
+ if (allOf.length === 0)
1213
+ return exports.Type.Never();
1214
+ if (allOf.length === 1)
1215
+ return TypeClone.Type(allOf[0], options);
1216
+ if (allOf.some((schema) => TypeGuard.TTransform(schema)))
1217
+ this.Throw("Cannot intersect transform types");
1218
+ const objects = allOf.every((schema) => TypeGuard.TObject(schema));
1219
+ const cloned = TypeClone.Rest(allOf);
1220
+ const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Type(options.unevaluatedProperties) } : {};
1221
+ 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 });
1222
+ }
1223
+ /** `[Json]` Creates a KeyOf type */
1224
+ KeyOf(schema, options = {}) {
1225
+ return TypeGuard.TRecord(schema) ? (() => {
1226
+ const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
1227
+ return pattern === exports.PatternNumberExact ? this.Number(options) : pattern === exports.PatternStringExact ? this.String(options) : this.Throw("Unable to resolve key type from Record key pattern");
1228
+ })() : TypeGuard.TTuple(schema) ? (() => {
1229
+ const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
1230
+ const literals = items.map((_, index) => exports.Type.Literal(index.toString()));
1231
+ return this.Union(literals, options);
1232
+ })() : TypeGuard.TArray(schema) ? (() => {
1233
+ return this.Number(options);
1234
+ })() : (() => {
1235
+ const keys = KeyResolver.ResolveKeys(schema, { includePatterns: false });
1236
+ if (keys.length === 0)
1237
+ return this.Never(options);
1238
+ const literals = keys.map((key) => this.Literal(key));
1239
+ return this.Union(literals, options);
1240
+ })();
1241
+ }
1242
+ /** `[Json]` Creates a Literal type */
1243
+ Literal(value, options = {}) {
1244
+ return this.Create({ ...options, [exports.Kind]: "Literal", const: value, type: typeof value });
1245
+ }
1246
+ /** `[Json]` Intrinsic function to Lowercase LiteralString types */
1247
+ Lowercase(schema, options = {}) {
1248
+ return { ...Intrinsic.Map(TypeClone.Type(schema), "Lowercase"), ...options };
1249
+ }
1250
+ /** `[Json]` Creates a Never type */
1251
+ Never(options = {}) {
1252
+ return this.Create({ ...options, [exports.Kind]: "Never", not: {} });
1253
+ }
1254
+ /** `[Json]` Creates a Not type */
1255
+ Not(schema, options) {
1256
+ return this.Create({ ...options, [exports.Kind]: "Not", not: TypeClone.Type(schema) });
1257
+ }
1258
+ /** `[Json]` Creates a Null type */
1259
+ Null(options = {}) {
1260
+ return this.Create({ ...options, [exports.Kind]: "Null", type: "null" });
1261
+ }
1262
+ /** `[Json]` Creates a Number type */
1263
+ Number(options = {}) {
1264
+ return this.Create({ ...options, [exports.Kind]: "Number", type: "number" });
1265
+ }
1266
+ /** `[Json]` Creates an Object type */
1267
+ Object(properties, options = {}) {
1268
+ const propertyKeys = Object.getOwnPropertyNames(properties);
1269
+ const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
1270
+ const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
1271
+ const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Type(options.additionalProperties) } : {};
1272
+ const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Type(properties[key]) }), {});
1273
+ 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 });
1274
+ }
1275
+ /** `[Json]` Constructs a type whose keys are omitted from the given type */
1276
+ Omit(schema, unresolved, options = {}) {
1277
+ const keys = KeyArrayResolver.Resolve(unresolved);
1278
+ return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
1279
+ if (ValueGuard.IsArray(object.required)) {
1280
+ object.required = object.required.filter((key) => !keys.includes(key));
1281
+ if (object.required.length === 0)
1282
+ delete object.required;
1283
+ }
1284
+ for (const key of Object.getOwnPropertyNames(object.properties)) {
1285
+ if (keys.includes(key))
1286
+ delete object.properties[key];
1287
+ }
1288
+ return this.Create(object);
1289
+ }, options);
1290
+ }
1291
+ /** `[Json]` Constructs a type where all properties are optional */
1292
+ Partial(schema, options = {}) {
1293
+ return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
1294
+ const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
1295
+ return { ...acc, [key]: this.Optional(object.properties[key]) };
1296
+ }, {});
1297
+ return this.Object(
1298
+ properties,
1299
+ this.Discard(object, ["required"])
1300
+ /* object used as options to retain other constraints */
1301
+ );
1302
+ }, options);
1303
+ }
1304
+ /** `[Json]` Constructs a type whose keys are picked from the given type */
1305
+ Pick(schema, unresolved, options = {}) {
1306
+ const keys = KeyArrayResolver.Resolve(unresolved);
1307
+ return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
1308
+ if (ValueGuard.IsArray(object.required)) {
1309
+ object.required = object.required.filter((key) => keys.includes(key));
1310
+ if (object.required.length === 0)
1311
+ delete object.required;
1312
+ }
1313
+ for (const key of Object.getOwnPropertyNames(object.properties)) {
1314
+ if (!keys.includes(key))
1315
+ delete object.properties[key];
1316
+ }
1317
+ return this.Create(object);
1318
+ }, options);
1319
+ }
1320
+ /** `[Json]` Creates a Record type */
1321
+ Record(key, schema, options = {}) {
1322
+ return TypeGuard.TTemplateLiteral(key) ? (() => {
1323
+ const expression = TemplateLiteralParser.ParseExact(key.pattern);
1324
+ 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) } });
1325
+ })() : TypeGuard.TUnion(key) ? (() => {
1326
+ const union = UnionResolver.Resolve(key);
1327
+ if (TypeGuard.TUnionLiteral(union)) {
1328
+ const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Type(schema) }), {});
1329
+ return this.Object(properties, { ...options, [exports.Hint]: "Record" });
1330
+ } else
1331
+ this.Throw("Record key of type union contains non-literal types");
1332
+ })() : TypeGuard.TLiteral(key) ? (() => {
1333
+ 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");
1334
+ })() : TypeGuard.TInteger(key) || TypeGuard.TNumber(key) ? (() => {
1335
+ return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [exports.PatternNumberExact]: TypeClone.Type(schema) } });
1336
+ })() : TypeGuard.TString(key) ? (() => {
1337
+ const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
1338
+ return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [pattern]: TypeClone.Type(schema) } });
1339
+ })() : this.Never();
1340
+ }
1341
+ /** `[Json]` Creates a Recursive type */
1342
+ Recursive(callback, options = {}) {
1343
+ if (ValueGuard.IsUndefined(options.$id))
1344
+ options.$id = `T${TypeOrdinal++}`;
1345
+ const thisType = callback({ [exports.Kind]: "This", $ref: `${options.$id}` });
1346
+ thisType.$id = options.$id;
1347
+ return this.Create({ ...options, [exports.Hint]: "Recursive", ...thisType });
1348
+ }
1349
+ /** `[Json]` Creates a Ref type. */
1350
+ Ref(unresolved, options = {}) {
1351
+ if (ValueGuard.IsString(unresolved))
1352
+ return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved });
1353
+ if (ValueGuard.IsUndefined(unresolved.$id))
1354
+ this.Throw("Reference target type must specify an $id");
1355
+ return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved.$id });
1356
+ }
1357
+ /** `[Json]` Constructs a type where all properties are required */
1358
+ Required(schema, options = {}) {
1359
+ return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
1360
+ const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
1361
+ return { ...acc, [key]: this.Discard(object.properties[key], [exports.Optional]) };
1362
+ }, {});
1363
+ return this.Object(
1364
+ properties,
1365
+ object
1366
+ /* object used as options to retain other constraints */
1367
+ );
1368
+ }, options);
1369
+ }
1370
+ /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
1371
+ Rest(schema) {
1372
+ 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) : [];
1373
+ }
1374
+ /** `[Json]` Creates a String type */
1375
+ String(options = {}) {
1376
+ return this.Create({ ...options, [exports.Kind]: "String", type: "string" });
1377
+ }
1378
+ /** `[Json]` Creates a TemplateLiteral type */
1379
+ TemplateLiteral(unresolved, options = {}) {
1380
+ const pattern = ValueGuard.IsString(unresolved) ? TemplateLiteralPattern.Create(TemplateLiteralDslParser.Parse(unresolved)) : TemplateLiteralPattern.Create(unresolved);
1381
+ return this.Create({ ...options, [exports.Kind]: "TemplateLiteral", type: "string", pattern });
1382
+ }
1383
+ /** `[Json]` Creates a Transform type */
1384
+ Transform(schema) {
1385
+ return new TransformDecodeBuilder(schema);
1386
+ }
1387
+ /** `[Json]` Creates a Tuple type */
1388
+ Tuple(items, options = {}) {
1389
+ const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
1390
+ const clonedItems = TypeClone.Rest(items);
1391
+ const schema = items.length > 0 ? { ...options, [exports.Kind]: "Tuple", type: "array", items: clonedItems, additionalItems, minItems, maxItems } : { ...options, [exports.Kind]: "Tuple", type: "array", minItems, maxItems };
1392
+ return this.Create(schema);
1393
+ }
1394
+ /** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
1395
+ Uncapitalize(schema, options = {}) {
1396
+ return { ...Intrinsic.Map(TypeClone.Type(schema), "Uncapitalize"), ...options };
1397
+ }
1398
+ /** `[Json]` Creates a Union type */
1399
+ Union(union, options = {}) {
1400
+ return TypeGuard.TTemplateLiteral(union) ? TemplateLiteralResolver.Resolve(union) : (() => {
1401
+ const anyOf = union;
1402
+ if (anyOf.length === 0)
1403
+ return this.Never(options);
1404
+ if (anyOf.length === 1)
1405
+ return this.Create(TypeClone.Type(anyOf[0], options));
1406
+ const clonedAnyOf = TypeClone.Rest(anyOf);
1407
+ return this.Create({ ...options, [exports.Kind]: "Union", anyOf: clonedAnyOf });
1408
+ })();
1409
+ }
1410
+ /** `[Json]` Creates an Unknown type */
1411
+ Unknown(options = {}) {
1412
+ return this.Create({ ...options, [exports.Kind]: "Unknown" });
1413
+ }
1414
+ /** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
1415
+ Unsafe(options = {}) {
1416
+ return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || "Unsafe" });
1417
+ }
1418
+ /** `[Json]` Intrinsic function to Uppercase LiteralString types */
1419
+ Uppercase(schema, options = {}) {
1420
+ return { ...Intrinsic.Map(TypeClone.Type(schema), "Uppercase"), ...options };
1421
+ }
1422
+ };
1423
+ exports.JsonTypeBuilder = JsonTypeBuilder;
1424
+ var JavaScriptTypeBuilder = class extends JsonTypeBuilder {
1425
+ /** `[JavaScript]` Creates a AsyncIterator type */
1426
+ AsyncIterator(items, options = {}) {
1427
+ return this.Create({ ...options, [exports.Kind]: "AsyncIterator", type: "AsyncIterator", items: TypeClone.Type(items) });
1428
+ }
1429
+ /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
1430
+ Awaited(schema, options = {}) {
1431
+ const Unwrap = (rest) => rest.length > 0 ? (() => {
1432
+ const [L, ...R] = rest;
1433
+ return [this.Awaited(L), ...Unwrap(R)];
1434
+ })() : rest;
1435
+ 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);
1436
+ }
1437
+ /** `[JavaScript]` Creates a BigInt type */
1438
+ BigInt(options = {}) {
1439
+ return this.Create({ ...options, [exports.Kind]: "BigInt", type: "bigint" });
1440
+ }
1441
+ /** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
1442
+ ConstructorParameters(schema, options = {}) {
1443
+ return this.Tuple([...schema.parameters], { ...options });
1444
+ }
1445
+ /** `[JavaScript]` Creates a Constructor type */
1446
+ Constructor(parameters, returns, options) {
1447
+ const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
1448
+ return this.Create({ ...options, [exports.Kind]: "Constructor", type: "Constructor", parameters: clonedParameters, returns: clonedReturns });
1449
+ }
1450
+ /** `[JavaScript]` Creates a Date type */
1451
+ Date(options = {}) {
1452
+ return this.Create({ ...options, [exports.Kind]: "Date", type: "Date" });
1453
+ }
1454
+ /** `[JavaScript]` Creates a Function type */
1455
+ Function(parameters, returns, options) {
1456
+ const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
1457
+ return this.Create({ ...options, [exports.Kind]: "Function", type: "Function", parameters: clonedParameters, returns: clonedReturns });
1458
+ }
1459
+ /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
1460
+ InstanceType(schema, options = {}) {
1461
+ return TypeClone.Type(schema.returns, options);
1462
+ }
1463
+ /** `[JavaScript]` Creates an Iterator type */
1464
+ Iterator(items, options = {}) {
1465
+ return this.Create({ ...options, [exports.Kind]: "Iterator", type: "Iterator", items: TypeClone.Type(items) });
1466
+ }
1467
+ /** `[JavaScript]` Extracts the Parameters from the given Function type */
1468
+ Parameters(schema, options = {}) {
1469
+ return this.Tuple(schema.parameters, { ...options });
1470
+ }
1471
+ /** `[JavaScript]` Creates a Promise type */
1472
+ Promise(item, options = {}) {
1473
+ return this.Create({ ...options, [exports.Kind]: "Promise", type: "Promise", item: TypeClone.Type(item) });
1474
+ }
1475
+ /** `[Extended]` Creates a String type */
1476
+ RegExp(unresolved, options = {}) {
1477
+ const pattern = ValueGuard.IsString(unresolved) ? unresolved : unresolved.source;
1478
+ return this.Create({ ...options, [exports.Kind]: "String", type: "string", pattern });
1479
+ }
1480
+ /**
1481
+ * @deprecated Use `Type.RegExp`
1482
+ */
1483
+ RegEx(regex, options = {}) {
1484
+ return this.RegExp(regex, options);
1485
+ }
1486
+ /** `[JavaScript]` Extracts the ReturnType from the given Function type */
1487
+ ReturnType(schema, options = {}) {
1488
+ return TypeClone.Type(schema.returns, options);
1489
+ }
1490
+ /** `[JavaScript]` Creates a Symbol type */
1491
+ Symbol(options) {
1492
+ return this.Create({ ...options, [exports.Kind]: "Symbol", type: "symbol" });
1493
+ }
1494
+ /** `[JavaScript]` Creates a Undefined type */
1495
+ Undefined(options = {}) {
1496
+ return this.Create({ ...options, [exports.Kind]: "Undefined", type: "undefined" });
1497
+ }
1498
+ /** `[JavaScript]` Creates a Uint8Array type */
1499
+ Uint8Array(options = {}) {
1500
+ return this.Create({ ...options, [exports.Kind]: "Uint8Array", type: "Uint8Array" });
1501
+ }
1502
+ /** `[JavaScript]` Creates a Void type */
1503
+ Void(options = {}) {
1504
+ return this.Create({ ...options, [exports.Kind]: "Void", type: "void" });
1505
+ }
1506
+ };
1507
+ exports.JavaScriptTypeBuilder = JavaScriptTypeBuilder;
1508
+ exports.JsonType = new JsonTypeBuilder();
1509
+ exports.Type = new JavaScriptTypeBuilder();
1510
+ }
1511
+ });
1512
+
1513
+ // src/types/typescript-utils.ts
1514
+ var import_typebox = __toESM(require_typebox(), 1);
1515
+ var { String: StringTB, Optional: OptionalTB, Boolean: BooleanTB, Object: ObjectTB, Number: NumberTB } = import_typebox.Type;
1516
+ var Str = StringTB.bind(import_typebox.Type);
1517
+ var Num = NumberTB.bind(import_typebox.Type);
1518
+ var Obj = ObjectTB.bind(import_typebox.Type);
1519
+ var Opt = OptionalTB.bind(import_typebox.Type);
1520
+ var Bool = BooleanTB.bind(import_typebox.Type);
1521
+ var STR = Str();
1522
+ var NUM = Num();
1523
+ var BOOL = Bool();
1524
+ var DefaultTrue = true;
1525
+ var DefaultFalse = false;
1526
+ function checkParityTB() {
1527
+ const s1 = Str();
1528
+ const s2 = Str();
1529
+ const n1 = Num();
1530
+ const n2 = Num();
1531
+ console.log({ s1, s2, n1, n2 });
1532
+ }
1533
+ function arrayIfSingle(arrOrSingle) {
1534
+ if (Array.isArray(arrOrSingle))
1535
+ return arrOrSingle;
1536
+ else
1537
+ return [arrOrSingle];
1538
+ }
1539
+
1540
+ export {
1541
+ require_typebox,
1542
+ Str,
1543
+ Num,
1544
+ Obj,
1545
+ Opt,
1546
+ Bool,
1547
+ STR,
1548
+ NUM,
1549
+ BOOL,
1550
+ DefaultTrue,
1551
+ DefaultFalse,
1552
+ checkParityTB,
1553
+ arrayIfSingle
1554
+ };
1555
+ //# sourceMappingURL=chunk-PTGUFZ3Q.min.js.map