@anvailabs/agentbrowser-mcp 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/dist/bin.js +2952 -380
- package/dist/index.js +2814 -259
- package/dist/mcp-server.d.ts +13 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +118 -36
- package/dist/mcp-server.js.map +1 -1
- package/package.json +17 -16
- package/LICENSE +0 -201
package/dist/bin.js
CHANGED
|
@@ -10,219 +10,6 @@ var __export = (target, all) => {
|
|
|
10
10
|
for (var name in all)
|
|
11
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
12
|
};
|
|
13
|
-
var AgentBrowserError = class extends Error {
|
|
14
|
-
code;
|
|
15
|
-
retryable;
|
|
16
|
-
constructor(code, message, retryable = false) {
|
|
17
|
-
super(`${code}: ${message}`);
|
|
18
|
-
this.code = code;
|
|
19
|
-
this.retryable = retryable;
|
|
20
|
-
this.name = "AgentBrowserError";
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var SessionsClient = class {
|
|
24
|
-
baseUrl;
|
|
25
|
-
timeout;
|
|
26
|
-
headers;
|
|
27
|
-
requestFn;
|
|
28
|
-
constructor(baseUrl, timeout, headers, requestFn) {
|
|
29
|
-
this.baseUrl = baseUrl;
|
|
30
|
-
this.timeout = timeout;
|
|
31
|
-
this.headers = headers;
|
|
32
|
-
this.requestFn = requestFn;
|
|
33
|
-
}
|
|
34
|
-
async create(request) {
|
|
35
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions`, {
|
|
36
|
-
method: "POST",
|
|
37
|
-
headers: {
|
|
38
|
-
"Content-Type": "application/json",
|
|
39
|
-
...this.headers
|
|
40
|
-
},
|
|
41
|
-
body: JSON.stringify(request)
|
|
42
|
-
});
|
|
43
|
-
return this.handleResponse(response);
|
|
44
|
-
}
|
|
45
|
-
async get(sessionId) {
|
|
46
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
47
|
-
method: "GET",
|
|
48
|
-
headers: this.headers
|
|
49
|
-
});
|
|
50
|
-
return this.handleResponse(response);
|
|
51
|
-
}
|
|
52
|
-
async list() {
|
|
53
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions`, {
|
|
54
|
-
method: "GET",
|
|
55
|
-
headers: this.headers
|
|
56
|
-
});
|
|
57
|
-
const data = await this.handleResponse(response);
|
|
58
|
-
return data.sessions;
|
|
59
|
-
}
|
|
60
|
-
async close(sessionId) {
|
|
61
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
62
|
-
method: "DELETE",
|
|
63
|
-
headers: this.headers
|
|
64
|
-
});
|
|
65
|
-
await this.handleResponse(response);
|
|
66
|
-
}
|
|
67
|
-
async createPage(sessionId) {
|
|
68
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages`, {
|
|
69
|
-
method: "POST",
|
|
70
|
-
headers: this.headers
|
|
71
|
-
});
|
|
72
|
-
return this.handleResponse(response);
|
|
73
|
-
}
|
|
74
|
-
async getPage(sessionId, pageId) {
|
|
75
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}`, {
|
|
76
|
-
method: "GET",
|
|
77
|
-
headers: this.headers
|
|
78
|
-
});
|
|
79
|
-
return this.handleResponse(response);
|
|
80
|
-
}
|
|
81
|
-
async closePage(sessionId, pageId) {
|
|
82
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}`, {
|
|
83
|
-
method: "DELETE",
|
|
84
|
-
headers: this.headers
|
|
85
|
-
});
|
|
86
|
-
await this.handleResponse(response);
|
|
87
|
-
}
|
|
88
|
-
/** TD-BROWSER-6: scoped cookie export — the read half of the credential handoff loop. */
|
|
89
|
-
async cookies(sessionId) {
|
|
90
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/cookies`, {
|
|
91
|
-
headers: this.headers
|
|
92
|
-
});
|
|
93
|
-
const body = await this.handleResponse(response);
|
|
94
|
-
return body.cookies;
|
|
95
|
-
}
|
|
96
|
-
async navigate(sessionId, pageId, request) {
|
|
97
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/navigate`, {
|
|
98
|
-
method: "POST",
|
|
99
|
-
headers: {
|
|
100
|
-
"Content-Type": "application/json",
|
|
101
|
-
...this.headers
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify(request)
|
|
104
|
-
});
|
|
105
|
-
return this.handleResponse(response);
|
|
106
|
-
}
|
|
107
|
-
async observe(sessionId, pageId, request = {}) {
|
|
108
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/observe`, {
|
|
109
|
-
method: "POST",
|
|
110
|
-
headers: {
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
...this.headers
|
|
113
|
-
},
|
|
114
|
-
body: JSON.stringify(request)
|
|
115
|
-
});
|
|
116
|
-
return this.handleResponse(response);
|
|
117
|
-
}
|
|
118
|
-
async executeAction(sessionId, pageId, request) {
|
|
119
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/act`, {
|
|
120
|
-
method: "POST",
|
|
121
|
-
headers: {
|
|
122
|
-
"Content-Type": "application/json",
|
|
123
|
-
...this.headers
|
|
124
|
-
},
|
|
125
|
-
body: JSON.stringify(request)
|
|
126
|
-
});
|
|
127
|
-
return this.handleResponse(response);
|
|
128
|
-
}
|
|
129
|
-
async screenshot(sessionId, pageId, request = {}) {
|
|
130
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/screenshot`, {
|
|
131
|
-
method: "POST",
|
|
132
|
-
headers: {
|
|
133
|
-
"Content-Type": "application/json",
|
|
134
|
-
...this.headers
|
|
135
|
-
},
|
|
136
|
-
body: JSON.stringify(request)
|
|
137
|
-
});
|
|
138
|
-
return this.handleResponse(response);
|
|
139
|
-
}
|
|
140
|
-
async extract(sessionId, pageId, request) {
|
|
141
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/extract`, {
|
|
142
|
-
method: "POST",
|
|
143
|
-
headers: {
|
|
144
|
-
"Content-Type": "application/json",
|
|
145
|
-
...this.headers
|
|
146
|
-
},
|
|
147
|
-
body: JSON.stringify(request)
|
|
148
|
-
});
|
|
149
|
-
return this.handleResponse(response);
|
|
150
|
-
}
|
|
151
|
-
async pdf(sessionId, pageId, request = {}) {
|
|
152
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/pdf`, {
|
|
153
|
-
method: "POST",
|
|
154
|
-
headers: {
|
|
155
|
-
"Content-Type": "application/json",
|
|
156
|
-
...this.headers
|
|
157
|
-
},
|
|
158
|
-
body: JSON.stringify(request)
|
|
159
|
-
});
|
|
160
|
-
return this.handleResponse(response);
|
|
161
|
-
}
|
|
162
|
-
async handleResponse(response) {
|
|
163
|
-
if (!response.ok) {
|
|
164
|
-
let error2;
|
|
165
|
-
try {
|
|
166
|
-
const data = await response.json();
|
|
167
|
-
error2 = data.error || {
|
|
168
|
-
code: "UNKNOWN_ERROR",
|
|
169
|
-
message: "Unknown error",
|
|
170
|
-
retryable: false
|
|
171
|
-
};
|
|
172
|
-
} catch {
|
|
173
|
-
error2 = {
|
|
174
|
-
code: "UNKNOWN_ERROR",
|
|
175
|
-
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
176
|
-
retryable: false
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
throw new AgentBrowserError(error2.code, error2.message, error2.retryable);
|
|
180
|
-
}
|
|
181
|
-
return response.json();
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var AgentBrowserClient = class {
|
|
185
|
-
baseUrl;
|
|
186
|
-
timeout;
|
|
187
|
-
sessions;
|
|
188
|
-
customHeaders;
|
|
189
|
-
constructor(options = {}) {
|
|
190
|
-
this.baseUrl = options.baseUrl || "http://localhost:3000";
|
|
191
|
-
this.timeout = options.timeout || 3e4;
|
|
192
|
-
this.customHeaders = {
|
|
193
|
-
...options.apiKey !== void 0 ? { Authorization: `Bearer ${options.apiKey}` } : {},
|
|
194
|
-
...options.headers
|
|
195
|
-
};
|
|
196
|
-
this.sessions = new SessionsClient(this.baseUrl, this.timeout, this.customHeaders, this.request.bind(this));
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Set default headers for all requests
|
|
200
|
-
*/
|
|
201
|
-
setHeaders(headers) {
|
|
202
|
-
Object.assign(this.customHeaders, headers);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Make an HTTP request with timeout
|
|
206
|
-
*/
|
|
207
|
-
async request(url, options = {}) {
|
|
208
|
-
const controller = new AbortController();
|
|
209
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
210
|
-
try {
|
|
211
|
-
const response = await fetch(url, {
|
|
212
|
-
...options,
|
|
213
|
-
signal: controller.signal
|
|
214
|
-
});
|
|
215
|
-
clearTimeout(timeoutId);
|
|
216
|
-
return response;
|
|
217
|
-
} catch (error2) {
|
|
218
|
-
clearTimeout(timeoutId);
|
|
219
|
-
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
220
|
-
throw new AgentBrowserError("TIMEOUT", "Request timeout", false);
|
|
221
|
-
}
|
|
222
|
-
throw error2;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
13
|
var value_exports = {};
|
|
227
14
|
__export(value_exports, {
|
|
228
15
|
HasPropertyKey: () => HasPropertyKey,
|
|
@@ -321,6 +108,24 @@ function Clone(value) {
|
|
|
321
108
|
function CloneType(schema, options) {
|
|
322
109
|
return options === void 0 ? Clone(schema) : Clone({ ...options, ...schema });
|
|
323
110
|
}
|
|
111
|
+
function IsAsyncIterator2(value) {
|
|
112
|
+
return IsObject2(value) && globalThis.Symbol.asyncIterator in value;
|
|
113
|
+
}
|
|
114
|
+
function IsIterator2(value) {
|
|
115
|
+
return IsObject2(value) && globalThis.Symbol.iterator in value;
|
|
116
|
+
}
|
|
117
|
+
function IsPromise(value) {
|
|
118
|
+
return value instanceof globalThis.Promise;
|
|
119
|
+
}
|
|
120
|
+
function IsDate2(value) {
|
|
121
|
+
return value instanceof Date && globalThis.Number.isFinite(value.getTime());
|
|
122
|
+
}
|
|
123
|
+
function IsUint8Array2(value) {
|
|
124
|
+
return value instanceof globalThis.Uint8Array;
|
|
125
|
+
}
|
|
126
|
+
function HasPropertyKey2(value, key) {
|
|
127
|
+
return key in value;
|
|
128
|
+
}
|
|
324
129
|
function IsObject2(value) {
|
|
325
130
|
return value !== null && typeof value === "object";
|
|
326
131
|
}
|
|
@@ -330,9 +135,33 @@ function IsArray2(value) {
|
|
|
330
135
|
function IsUndefined2(value) {
|
|
331
136
|
return value === void 0;
|
|
332
137
|
}
|
|
138
|
+
function IsNull2(value) {
|
|
139
|
+
return value === null;
|
|
140
|
+
}
|
|
141
|
+
function IsBoolean2(value) {
|
|
142
|
+
return typeof value === "boolean";
|
|
143
|
+
}
|
|
333
144
|
function IsNumber2(value) {
|
|
334
145
|
return typeof value === "number";
|
|
335
146
|
}
|
|
147
|
+
function IsInteger(value) {
|
|
148
|
+
return globalThis.Number.isInteger(value);
|
|
149
|
+
}
|
|
150
|
+
function IsBigInt2(value) {
|
|
151
|
+
return typeof value === "bigint";
|
|
152
|
+
}
|
|
153
|
+
function IsString2(value) {
|
|
154
|
+
return typeof value === "string";
|
|
155
|
+
}
|
|
156
|
+
function IsFunction2(value) {
|
|
157
|
+
return typeof value === "function";
|
|
158
|
+
}
|
|
159
|
+
function IsSymbol2(value) {
|
|
160
|
+
return typeof value === "symbol";
|
|
161
|
+
}
|
|
162
|
+
function IsValueType(value) {
|
|
163
|
+
return IsBigInt2(value) || IsBoolean2(value) || IsNull2(value) || IsNumber2(value) || IsString2(value) || IsSymbol2(value) || IsUndefined2(value);
|
|
164
|
+
}
|
|
336
165
|
var TypeSystemPolicy;
|
|
337
166
|
(function(TypeSystemPolicy2) {
|
|
338
167
|
TypeSystemPolicy2.InstanceMode = "default";
|
|
@@ -424,13 +253,13 @@ function IsArgument(value) {
|
|
|
424
253
|
function IsArray3(value) {
|
|
425
254
|
return IsKindOf(value, "Array");
|
|
426
255
|
}
|
|
427
|
-
function
|
|
256
|
+
function IsAsyncIterator3(value) {
|
|
428
257
|
return IsKindOf(value, "AsyncIterator");
|
|
429
258
|
}
|
|
430
|
-
function
|
|
259
|
+
function IsBigInt3(value) {
|
|
431
260
|
return IsKindOf(value, "BigInt");
|
|
432
261
|
}
|
|
433
|
-
function
|
|
262
|
+
function IsBoolean3(value) {
|
|
434
263
|
return IsKindOf(value, "Boolean");
|
|
435
264
|
}
|
|
436
265
|
function IsComputed(value) {
|
|
@@ -439,19 +268,19 @@ function IsComputed(value) {
|
|
|
439
268
|
function IsConstructor(value) {
|
|
440
269
|
return IsKindOf(value, "Constructor");
|
|
441
270
|
}
|
|
442
|
-
function
|
|
271
|
+
function IsDate3(value) {
|
|
443
272
|
return IsKindOf(value, "Date");
|
|
444
273
|
}
|
|
445
|
-
function
|
|
274
|
+
function IsFunction3(value) {
|
|
446
275
|
return IsKindOf(value, "Function");
|
|
447
276
|
}
|
|
448
|
-
function
|
|
277
|
+
function IsInteger2(value) {
|
|
449
278
|
return IsKindOf(value, "Integer");
|
|
450
279
|
}
|
|
451
280
|
function IsIntersect(value) {
|
|
452
281
|
return IsKindOf(value, "Intersect");
|
|
453
282
|
}
|
|
454
|
-
function
|
|
283
|
+
function IsIterator3(value) {
|
|
455
284
|
return IsKindOf(value, "Iterator");
|
|
456
285
|
}
|
|
457
286
|
function IsKindOf(value, kind) {
|
|
@@ -475,7 +304,7 @@ function IsNever(value) {
|
|
|
475
304
|
function IsNot(value) {
|
|
476
305
|
return IsKindOf(value, "Not");
|
|
477
306
|
}
|
|
478
|
-
function
|
|
307
|
+
function IsNull3(value) {
|
|
479
308
|
return IsKindOf(value, "Null");
|
|
480
309
|
}
|
|
481
310
|
function IsNumber3(value) {
|
|
@@ -484,7 +313,7 @@ function IsNumber3(value) {
|
|
|
484
313
|
function IsObject3(value) {
|
|
485
314
|
return IsKindOf(value, "Object");
|
|
486
315
|
}
|
|
487
|
-
function
|
|
316
|
+
function IsPromise2(value) {
|
|
488
317
|
return IsKindOf(value, "Promise");
|
|
489
318
|
}
|
|
490
319
|
function IsRecord(value) {
|
|
@@ -496,10 +325,10 @@ function IsRef(value) {
|
|
|
496
325
|
function IsRegExp2(value) {
|
|
497
326
|
return IsKindOf(value, "RegExp");
|
|
498
327
|
}
|
|
499
|
-
function
|
|
328
|
+
function IsString3(value) {
|
|
500
329
|
return IsKindOf(value, "String");
|
|
501
330
|
}
|
|
502
|
-
function
|
|
331
|
+
function IsSymbol3(value) {
|
|
503
332
|
return IsKindOf(value, "Symbol");
|
|
504
333
|
}
|
|
505
334
|
function IsTemplateLiteral(value) {
|
|
@@ -520,7 +349,7 @@ function IsUndefined3(value) {
|
|
|
520
349
|
function IsUnion(value) {
|
|
521
350
|
return IsKindOf(value, "Union");
|
|
522
351
|
}
|
|
523
|
-
function
|
|
352
|
+
function IsUint8Array3(value) {
|
|
524
353
|
return IsKindOf(value, "Uint8Array");
|
|
525
354
|
}
|
|
526
355
|
function IsUnknown(value) {
|
|
@@ -536,24 +365,24 @@ function IsKind(value) {
|
|
|
536
365
|
return IsObject(value) && Kind in value && IsString(value[Kind]);
|
|
537
366
|
}
|
|
538
367
|
function IsSchema(value) {
|
|
539
|
-
return IsAny(value) || IsArgument(value) || IsArray3(value) ||
|
|
368
|
+
return IsAny(value) || IsArgument(value) || IsArray3(value) || IsBoolean3(value) || IsBigInt3(value) || IsAsyncIterator3(value) || IsComputed(value) || IsConstructor(value) || IsDate3(value) || IsFunction3(value) || IsInteger2(value) || IsIntersect(value) || IsIterator3(value) || IsLiteral(value) || IsMappedKey(value) || IsMappedResult(value) || IsNever(value) || IsNot(value) || IsNull3(value) || IsNumber3(value) || IsObject3(value) || IsPromise2(value) || IsRecord(value) || IsRef(value) || IsRegExp2(value) || IsString3(value) || IsSymbol3(value) || IsTemplateLiteral(value) || IsThis(value) || IsTuple(value) || IsUndefined3(value) || IsUnion(value) || IsUint8Array3(value) || IsUnknown(value) || IsUnsafe(value) || IsVoid(value) || IsKind(value);
|
|
540
369
|
}
|
|
541
370
|
var type_exports = {};
|
|
542
371
|
__export(type_exports, {
|
|
543
372
|
IsAny: () => IsAny2,
|
|
544
373
|
IsArgument: () => IsArgument2,
|
|
545
374
|
IsArray: () => IsArray4,
|
|
546
|
-
IsAsyncIterator: () =>
|
|
547
|
-
IsBigInt: () =>
|
|
548
|
-
IsBoolean: () =>
|
|
375
|
+
IsAsyncIterator: () => IsAsyncIterator4,
|
|
376
|
+
IsBigInt: () => IsBigInt4,
|
|
377
|
+
IsBoolean: () => IsBoolean4,
|
|
549
378
|
IsComputed: () => IsComputed2,
|
|
550
379
|
IsConstructor: () => IsConstructor2,
|
|
551
|
-
IsDate: () =>
|
|
552
|
-
IsFunction: () =>
|
|
380
|
+
IsDate: () => IsDate4,
|
|
381
|
+
IsFunction: () => IsFunction4,
|
|
553
382
|
IsImport: () => IsImport,
|
|
554
|
-
IsInteger: () =>
|
|
383
|
+
IsInteger: () => IsInteger3,
|
|
555
384
|
IsIntersect: () => IsIntersect2,
|
|
556
|
-
IsIterator: () =>
|
|
385
|
+
IsIterator: () => IsIterator4,
|
|
557
386
|
IsKind: () => IsKind2,
|
|
558
387
|
IsKindOf: () => IsKindOf2,
|
|
559
388
|
IsLiteral: () => IsLiteral2,
|
|
@@ -565,11 +394,11 @@ __export(type_exports, {
|
|
|
565
394
|
IsMappedResult: () => IsMappedResult2,
|
|
566
395
|
IsNever: () => IsNever2,
|
|
567
396
|
IsNot: () => IsNot2,
|
|
568
|
-
IsNull: () =>
|
|
397
|
+
IsNull: () => IsNull4,
|
|
569
398
|
IsNumber: () => IsNumber4,
|
|
570
399
|
IsObject: () => IsObject4,
|
|
571
400
|
IsOptional: () => IsOptional2,
|
|
572
|
-
IsPromise: () =>
|
|
401
|
+
IsPromise: () => IsPromise3,
|
|
573
402
|
IsProperties: () => IsProperties,
|
|
574
403
|
IsReadonly: () => IsReadonly2,
|
|
575
404
|
IsRecord: () => IsRecord2,
|
|
@@ -577,13 +406,13 @@ __export(type_exports, {
|
|
|
577
406
|
IsRef: () => IsRef2,
|
|
578
407
|
IsRegExp: () => IsRegExp3,
|
|
579
408
|
IsSchema: () => IsSchema2,
|
|
580
|
-
IsString: () =>
|
|
581
|
-
IsSymbol: () =>
|
|
409
|
+
IsString: () => IsString4,
|
|
410
|
+
IsSymbol: () => IsSymbol4,
|
|
582
411
|
IsTemplateLiteral: () => IsTemplateLiteral2,
|
|
583
412
|
IsThis: () => IsThis2,
|
|
584
413
|
IsTransform: () => IsTransform2,
|
|
585
414
|
IsTuple: () => IsTuple2,
|
|
586
|
-
IsUint8Array: () =>
|
|
415
|
+
IsUint8Array: () => IsUint8Array4,
|
|
587
416
|
IsUndefined: () => IsUndefined4,
|
|
588
417
|
IsUnion: () => IsUnion2,
|
|
589
418
|
IsUnionLiteral: () => IsUnionLiteral,
|
|
@@ -689,13 +518,13 @@ function IsArgument2(value) {
|
|
|
689
518
|
function IsArray4(value) {
|
|
690
519
|
return IsKindOf2(value, "Array") && value.type === "array" && IsOptionalString(value.$id) && IsSchema2(value.items) && IsOptionalNumber(value.minItems) && IsOptionalNumber(value.maxItems) && IsOptionalBoolean(value.uniqueItems) && IsOptionalSchema(value.contains) && IsOptionalNumber(value.minContains) && IsOptionalNumber(value.maxContains);
|
|
691
520
|
}
|
|
692
|
-
function
|
|
521
|
+
function IsAsyncIterator4(value) {
|
|
693
522
|
return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
694
523
|
}
|
|
695
|
-
function
|
|
524
|
+
function IsBigInt4(value) {
|
|
696
525
|
return IsKindOf2(value, "BigInt") && value.type === "bigint" && IsOptionalString(value.$id) && IsOptionalBigInt(value.exclusiveMaximum) && IsOptionalBigInt(value.exclusiveMinimum) && IsOptionalBigInt(value.maximum) && IsOptionalBigInt(value.minimum) && IsOptionalBigInt(value.multipleOf);
|
|
697
526
|
}
|
|
698
|
-
function
|
|
527
|
+
function IsBoolean4(value) {
|
|
699
528
|
return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
|
|
700
529
|
}
|
|
701
530
|
function IsComputed2(value) {
|
|
@@ -704,16 +533,16 @@ function IsComputed2(value) {
|
|
|
704
533
|
function IsConstructor2(value) {
|
|
705
534
|
return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
706
535
|
}
|
|
707
|
-
function
|
|
536
|
+
function IsDate4(value) {
|
|
708
537
|
return IsKindOf2(value, "Date") && value.type === "Date" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximumTimestamp) && IsOptionalNumber(value.exclusiveMinimumTimestamp) && IsOptionalNumber(value.maximumTimestamp) && IsOptionalNumber(value.minimumTimestamp) && IsOptionalNumber(value.multipleOfTimestamp);
|
|
709
538
|
}
|
|
710
|
-
function
|
|
539
|
+
function IsFunction4(value) {
|
|
711
540
|
return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
712
541
|
}
|
|
713
542
|
function IsImport(value) {
|
|
714
543
|
return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs;
|
|
715
544
|
}
|
|
716
|
-
function
|
|
545
|
+
function IsInteger3(value) {
|
|
717
546
|
return IsKindOf2(value, "Integer") && value.type === "integer" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
|
|
718
547
|
}
|
|
719
548
|
function IsProperties(value) {
|
|
@@ -722,7 +551,7 @@ function IsProperties(value) {
|
|
|
722
551
|
function IsIntersect2(value) {
|
|
723
552
|
return IsKindOf2(value, "Intersect") && (IsString(value.type) && value.type !== "object" ? false : true) && IsArray(value.allOf) && value.allOf.every((schema) => IsSchema2(schema) && !IsTransform2(schema)) && IsOptionalString(value.type) && (IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) && IsOptionalString(value.$id);
|
|
724
553
|
}
|
|
725
|
-
function
|
|
554
|
+
function IsIterator4(value) {
|
|
726
555
|
return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
727
556
|
}
|
|
728
557
|
function IsKindOf2(value, kind) {
|
|
@@ -755,7 +584,7 @@ function IsNever2(value) {
|
|
|
755
584
|
function IsNot2(value) {
|
|
756
585
|
return IsKindOf2(value, "Not") && IsSchema2(value.not);
|
|
757
586
|
}
|
|
758
|
-
function
|
|
587
|
+
function IsNull4(value) {
|
|
759
588
|
return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
|
|
760
589
|
}
|
|
761
590
|
function IsNumber4(value) {
|
|
@@ -764,7 +593,7 @@ function IsNumber4(value) {
|
|
|
764
593
|
function IsObject4(value) {
|
|
765
594
|
return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
|
|
766
595
|
}
|
|
767
|
-
function
|
|
596
|
+
function IsPromise3(value) {
|
|
768
597
|
return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
|
|
769
598
|
}
|
|
770
599
|
function IsRecord2(value) {
|
|
@@ -782,10 +611,10 @@ function IsRef2(value) {
|
|
|
782
611
|
function IsRegExp3(value) {
|
|
783
612
|
return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
|
|
784
613
|
}
|
|
785
|
-
function
|
|
614
|
+
function IsString4(value) {
|
|
786
615
|
return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
|
|
787
616
|
}
|
|
788
|
-
function
|
|
617
|
+
function IsSymbol4(value) {
|
|
789
618
|
return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
|
|
790
619
|
}
|
|
791
620
|
function IsTemplateLiteral2(value) {
|
|
@@ -810,7 +639,7 @@ function IsUnionLiteral(value) {
|
|
|
810
639
|
function IsUnion2(value) {
|
|
811
640
|
return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
|
|
812
641
|
}
|
|
813
|
-
function
|
|
642
|
+
function IsUint8Array4(value) {
|
|
814
643
|
return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
|
|
815
644
|
}
|
|
816
645
|
function IsUnknown2(value) {
|
|
@@ -826,7 +655,7 @@ function IsKind2(value) {
|
|
|
826
655
|
return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
827
656
|
}
|
|
828
657
|
function IsSchema2(value) {
|
|
829
|
-
return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) ||
|
|
658
|
+
return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) || IsBoolean4(value) || IsBigInt4(value) || IsAsyncIterator4(value) || IsComputed2(value) || IsConstructor2(value) || IsDate4(value) || IsFunction4(value) || IsInteger3(value) || IsIntersect2(value) || IsIterator4(value) || IsLiteral2(value) || IsMappedKey2(value) || IsMappedResult2(value) || IsNever2(value) || IsNot2(value) || IsNull4(value) || IsNumber4(value) || IsObject4(value) || IsPromise3(value) || IsRecord2(value) || IsRef2(value) || IsRegExp3(value) || IsString4(value) || IsSymbol4(value) || IsTemplateLiteral2(value) || IsThis2(value) || IsTuple2(value) || IsUndefined4(value) || IsUnion2(value) || IsUint8Array4(value) || IsUnknown2(value) || IsUnsafe2(value) || IsVoid2(value) || IsKind2(value));
|
|
830
659
|
}
|
|
831
660
|
var PatternBoolean = "(true|false)";
|
|
832
661
|
var PatternNumber = "(0|[1-9][0-9]*)";
|
|
@@ -836,6 +665,62 @@ var PatternBooleanExact = `^${PatternBoolean}$`;
|
|
|
836
665
|
var PatternNumberExact = `^${PatternNumber}$`;
|
|
837
666
|
var PatternStringExact = `^${PatternString}$`;
|
|
838
667
|
var PatternNeverExact = `^${PatternNever}$`;
|
|
668
|
+
var format_exports = {};
|
|
669
|
+
__export(format_exports, {
|
|
670
|
+
Clear: () => Clear,
|
|
671
|
+
Delete: () => Delete,
|
|
672
|
+
Entries: () => Entries,
|
|
673
|
+
Get: () => Get,
|
|
674
|
+
Has: () => Has,
|
|
675
|
+
Set: () => Set2
|
|
676
|
+
});
|
|
677
|
+
var map = /* @__PURE__ */ new Map();
|
|
678
|
+
function Entries() {
|
|
679
|
+
return new Map(map);
|
|
680
|
+
}
|
|
681
|
+
function Clear() {
|
|
682
|
+
return map.clear();
|
|
683
|
+
}
|
|
684
|
+
function Delete(format) {
|
|
685
|
+
return map.delete(format);
|
|
686
|
+
}
|
|
687
|
+
function Has(format) {
|
|
688
|
+
return map.has(format);
|
|
689
|
+
}
|
|
690
|
+
function Set2(format, func) {
|
|
691
|
+
map.set(format, func);
|
|
692
|
+
}
|
|
693
|
+
function Get(format) {
|
|
694
|
+
return map.get(format);
|
|
695
|
+
}
|
|
696
|
+
var type_exports2 = {};
|
|
697
|
+
__export(type_exports2, {
|
|
698
|
+
Clear: () => Clear2,
|
|
699
|
+
Delete: () => Delete2,
|
|
700
|
+
Entries: () => Entries2,
|
|
701
|
+
Get: () => Get2,
|
|
702
|
+
Has: () => Has2,
|
|
703
|
+
Set: () => Set3
|
|
704
|
+
});
|
|
705
|
+
var map2 = /* @__PURE__ */ new Map();
|
|
706
|
+
function Entries2() {
|
|
707
|
+
return new Map(map2);
|
|
708
|
+
}
|
|
709
|
+
function Clear2() {
|
|
710
|
+
return map2.clear();
|
|
711
|
+
}
|
|
712
|
+
function Delete2(kind) {
|
|
713
|
+
return map2.delete(kind);
|
|
714
|
+
}
|
|
715
|
+
function Has2(kind) {
|
|
716
|
+
return map2.has(kind);
|
|
717
|
+
}
|
|
718
|
+
function Set3(kind, func) {
|
|
719
|
+
map2.set(kind, func);
|
|
720
|
+
}
|
|
721
|
+
function Get2(kind) {
|
|
722
|
+
return map2.get(kind);
|
|
723
|
+
}
|
|
839
724
|
function SetIncludes(T, S) {
|
|
840
725
|
return T.includes(S);
|
|
841
726
|
}
|
|
@@ -1100,7 +985,7 @@ function Literal(value, options) {
|
|
|
1100
985
|
function Boolean2(options) {
|
|
1101
986
|
return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
|
|
1102
987
|
}
|
|
1103
|
-
function
|
|
988
|
+
function BigInt2(options) {
|
|
1104
989
|
return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
|
|
1105
990
|
}
|
|
1106
991
|
function Number2(options) {
|
|
@@ -1111,7 +996,7 @@ function String2(options) {
|
|
|
1111
996
|
}
|
|
1112
997
|
function* FromUnion(syntax) {
|
|
1113
998
|
const trim = syntax.trim().replace(/"|'/g, "");
|
|
1114
|
-
return trim === "boolean" ? yield Boolean2() : trim === "number" ? yield Number2() : trim === "bigint" ? yield
|
|
999
|
+
return trim === "boolean" ? yield Boolean2() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt2() : trim === "string" ? yield String2() : yield (() => {
|
|
1115
1000
|
const literals = trim.split("|").map((literal) => Literal(literal.trim()));
|
|
1116
1001
|
return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
|
|
1117
1002
|
})();
|
|
@@ -1150,7 +1035,7 @@ function Escape(value) {
|
|
|
1150
1035
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1151
1036
|
}
|
|
1152
1037
|
function Visit2(schema, acc) {
|
|
1153
|
-
return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` :
|
|
1038
|
+
return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` : IsInteger2(schema) ? `${acc}${PatternNumber}` : IsBigInt3(schema) ? `${acc}${PatternNumber}` : IsString3(schema) ? `${acc}${PatternString}` : IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : IsBoolean3(schema) ? `${acc}${PatternBoolean}` : (() => {
|
|
1154
1039
|
throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
|
|
1155
1040
|
})();
|
|
1156
1041
|
}
|
|
@@ -1180,7 +1065,7 @@ function FromLiteral(literalValue) {
|
|
|
1180
1065
|
return [literalValue.toString()];
|
|
1181
1066
|
}
|
|
1182
1067
|
function IndexPropertyKeys(type) {
|
|
1183
|
-
return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] :
|
|
1068
|
+
return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] : IsInteger2(type) ? ["[number]"] : [])];
|
|
1184
1069
|
}
|
|
1185
1070
|
function FromProperties(type, properties, options) {
|
|
1186
1071
|
const result = {};
|
|
@@ -1337,7 +1222,7 @@ function FromSchemaType(K, T) {
|
|
|
1337
1222
|
// unevaluated mapped types
|
|
1338
1223
|
IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
|
|
1339
1224
|
// unevaluated types
|
|
1340
|
-
IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) :
|
|
1225
|
+
IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsFunction3(T) ? Function(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsAsyncIterator3(T) ? AsyncIterator(FromSchemaType(K, T.items), options) : IsIterator3(T) ? Iterator(FromSchemaType(K, T.items), options) : IsIntersect(T) ? Intersect(FromRest2(K, T.allOf), options) : IsUnion(T) ? Union(FromRest2(K, T.anyOf), options) : IsTuple(T) ? Tuple(FromRest2(K, T.items ?? []), options) : IsObject3(T) ? Object2(FromProperties3(K, T.properties), options) : IsArray3(T) ? Array2(FromSchemaType(K, T.items), options) : IsPromise2(T) ? Promise2(FromSchemaType(K, T.item), options) : T
|
|
1341
1226
|
)
|
|
1342
1227
|
)
|
|
1343
1228
|
);
|
|
@@ -1348,9 +1233,9 @@ function MappedFunctionReturnType(K, T) {
|
|
|
1348
1233
|
Acc[L] = FromSchemaType(L, T);
|
|
1349
1234
|
return Acc;
|
|
1350
1235
|
}
|
|
1351
|
-
function Mapped(key,
|
|
1236
|
+
function Mapped(key, map3, options) {
|
|
1352
1237
|
const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
1353
|
-
const RT =
|
|
1238
|
+
const RT = map3({ [Kind]: "MappedKey", keys: K });
|
|
1354
1239
|
const R = MappedFunctionReturnType(K, RT);
|
|
1355
1240
|
return Object2(R, options);
|
|
1356
1241
|
}
|
|
@@ -1440,7 +1325,7 @@ function FromRest3(types) {
|
|
|
1440
1325
|
return types.map((type) => Awaited(type));
|
|
1441
1326
|
}
|
|
1442
1327
|
function Awaited(type, options) {
|
|
1443
|
-
return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect2(type.allOf) : IsUnion(type) ? FromUnion4(type.anyOf) :
|
|
1328
|
+
return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect2(type.allOf) : IsUnion(type) ? FromUnion4(type.anyOf) : IsPromise2(type) ? FromPromise(type.item) : IsRef(type) ? FromRef(type.$ref) : type, options);
|
|
1444
1329
|
}
|
|
1445
1330
|
function FromRest4(types) {
|
|
1446
1331
|
const result = [];
|
|
@@ -1479,6 +1364,13 @@ function KeyOfPropertyKeys(type) {
|
|
|
1479
1364
|
return IsIntersect(type) ? FromIntersect3(type.allOf) : IsUnion(type) ? FromUnion5(type.anyOf) : IsTuple(type) ? FromTuple2(type.items ?? []) : IsArray3(type) ? FromArray2(type.items) : IsObject3(type) ? FromProperties5(type.properties) : IsRecord(type) ? FromPatternProperties(type.patternProperties) : [];
|
|
1480
1365
|
}
|
|
1481
1366
|
var includePatternProperties = false;
|
|
1367
|
+
function KeyOfPattern(schema) {
|
|
1368
|
+
includePatternProperties = true;
|
|
1369
|
+
const keys = KeyOfPropertyKeys(schema);
|
|
1370
|
+
includePatternProperties = false;
|
|
1371
|
+
const pattern = keys.map((key) => `(${key})`);
|
|
1372
|
+
return `^(${pattern.join("|")})$`;
|
|
1373
|
+
}
|
|
1482
1374
|
function FromComputed2(target, parameters) {
|
|
1483
1375
|
return Computed("KeyOf", [Computed(target, parameters)]);
|
|
1484
1376
|
}
|
|
@@ -1510,6 +1402,11 @@ function KeyOfFromMappedResult(mappedResult, options) {
|
|
|
1510
1402
|
const properties = FromMappedResult5(mappedResult, options);
|
|
1511
1403
|
return MappedResult(properties);
|
|
1512
1404
|
}
|
|
1405
|
+
function KeyOfPropertyEntries(schema) {
|
|
1406
|
+
const keys = KeyOfPropertyKeys(schema);
|
|
1407
|
+
const schemas = IndexFromPropertyKeys(schema, keys);
|
|
1408
|
+
return keys.map((_, index) => [keys[index], schemas[index]]);
|
|
1409
|
+
}
|
|
1513
1410
|
function CompositeKeys(T) {
|
|
1514
1411
|
const Acc = [];
|
|
1515
1412
|
for (const L of T)
|
|
@@ -1569,7 +1466,7 @@ function ConditionalReadonly(T, root) {
|
|
|
1569
1466
|
return root === true ? T : Readonly(T);
|
|
1570
1467
|
}
|
|
1571
1468
|
function FromValue(value, root) {
|
|
1572
|
-
return IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) : IsIterator(value) ? ConditionalReadonly(Any(), root) : IsArray(value) ? Readonly(Tuple(FromArray3(value))) : IsUint8Array(value) ? Uint8Array2() : IsDate(value) ? Date2() : IsObject(value) ? ConditionalReadonly(Object2(FromProperties7(value)), root) : IsFunction(value) ? ConditionalReadonly(Function([], Unknown()), root) : IsUndefined(value) ? Undefined() : IsNull(value) ? Null() : IsSymbol(value) ? Symbol2() : IsBigInt(value) ?
|
|
1469
|
+
return IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) : IsIterator(value) ? ConditionalReadonly(Any(), root) : IsArray(value) ? Readonly(Tuple(FromArray3(value))) : IsUint8Array(value) ? Uint8Array2() : IsDate(value) ? Date2() : IsObject(value) ? ConditionalReadonly(Object2(FromProperties7(value)), root) : IsFunction(value) ? ConditionalReadonly(Function([], Unknown()), root) : IsUndefined(value) ? Undefined() : IsNull(value) ? Null() : IsSymbol(value) ? Symbol2() : IsBigInt(value) ? BigInt2() : IsNumber(value) ? Literal(value) : IsBoolean(value) ? Literal(value) : IsString(value) ? Literal(value) : Object2({});
|
|
1573
1470
|
}
|
|
1574
1471
|
function Const(T, options) {
|
|
1575
1472
|
return CreateType(FromValue(T, true), options);
|
|
@@ -1871,6 +1768,18 @@ function ExtendsFromMappedKey(T, U, L, R, options) {
|
|
|
1871
1768
|
const P = FromMappedKey2(T, U, L, R, options);
|
|
1872
1769
|
return MappedResult(P);
|
|
1873
1770
|
}
|
|
1771
|
+
function Intersect2(schema) {
|
|
1772
|
+
return schema.allOf.every((schema2) => ExtendsUndefinedCheck(schema2));
|
|
1773
|
+
}
|
|
1774
|
+
function Union2(schema) {
|
|
1775
|
+
return schema.anyOf.some((schema2) => ExtendsUndefinedCheck(schema2));
|
|
1776
|
+
}
|
|
1777
|
+
function Not(schema) {
|
|
1778
|
+
return !ExtendsUndefinedCheck(schema.not);
|
|
1779
|
+
}
|
|
1780
|
+
function ExtendsUndefinedCheck(schema) {
|
|
1781
|
+
return schema[Kind] === "Intersect" ? Intersect2(schema) : schema[Kind] === "Union" ? Union2(schema) : schema[Kind] === "Not" ? Not(schema) : schema[Kind] === "Undefined" ? true : false;
|
|
1782
|
+
}
|
|
1874
1783
|
function ExcludeFromTemplateLiteral(L, R) {
|
|
1875
1784
|
return Exclude(TemplateLiteralToUnion(L), R);
|
|
1876
1785
|
}
|
|
@@ -1972,7 +1881,7 @@ function FromNumberKey(_, type, options) {
|
|
|
1972
1881
|
return RecordCreateFromPattern(PatternNumberExact, type, options);
|
|
1973
1882
|
}
|
|
1974
1883
|
function Record(key, type, options = {}) {
|
|
1975
|
-
return IsUnion(key) ? FromUnionKey(key.anyOf, type, options) : IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) : IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
|
|
1884
|
+
return IsUnion(key) ? FromUnionKey(key.anyOf, type, options) : IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) : IsLiteral(key) ? FromLiteralKey(key.const, type, options) : IsBoolean3(key) ? FromBooleanKey(key, type, options) : IsInteger2(key) ? FromIntegerKey(key, type, options) : IsNumber3(key) ? FromNumberKey(key, type, options) : IsRegExp2(key) ? FromRegExpKey(key, type, options) : IsString3(key) ? FromStringKey(key, type, options) : IsAny(key) ? FromAnyKey(key, type, options) : IsNever(key) ? FromNeverKey(key, type, options) : Never(options);
|
|
1976
1885
|
}
|
|
1977
1886
|
function RecordPattern(record) {
|
|
1978
1887
|
return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
|
|
@@ -2052,7 +1961,7 @@ function FromTypes(args, types) {
|
|
|
2052
1961
|
return types.map((type) => FromType(args, type));
|
|
2053
1962
|
}
|
|
2054
1963
|
function FromType(args, type) {
|
|
2055
|
-
return IsConstructor(type) ? FromConstructor2(args, type) :
|
|
1964
|
+
return IsConstructor(type) ? FromConstructor2(args, type) : IsFunction3(type) ? FromFunction2(args, type) : IsIntersect(type) ? FromIntersect5(args, type) : IsUnion(type) ? FromUnion7(args, type) : IsTuple(type) ? FromTuple4(args, type) : IsArray3(type) ? FromArray5(args, type) : IsAsyncIterator3(type) ? FromAsyncIterator2(args, type) : IsIterator3(type) ? FromIterator2(args, type) : IsPromise2(type) ? FromPromise3(args, type) : IsObject3(type) ? FromObject2(args, type) : IsRecord(type) ? FromRecord2(args, type) : IsArgument(type) ? FromArgument(args, type) : type;
|
|
2056
1965
|
}
|
|
2057
1966
|
function Instantiate(type, args) {
|
|
2058
1967
|
return FromType(args, CloneType(type));
|
|
@@ -2280,7 +2189,7 @@ function PartialResolve(type) {
|
|
|
2280
2189
|
// Mappable
|
|
2281
2190
|
IsComputed(type) ? FromComputed3(type.target, type.parameters) : IsRef(type) ? FromRef3(type.$ref) : IsIntersect(type) ? Intersect(FromRest6(type.allOf)) : IsUnion(type) ? Union(FromRest6(type.anyOf)) : IsObject3(type) ? FromObject5(type, type.properties) : (
|
|
2282
2191
|
// Intrinsic
|
|
2283
|
-
|
|
2192
|
+
IsBigInt3(type) ? type : IsBoolean3(type) ? type : IsInteger2(type) ? type : IsLiteral(type) ? type : IsNull3(type) ? type : IsNumber3(type) ? type : IsString3(type) ? type : IsSymbol3(type) ? type : IsUndefined3(type) ? type : (
|
|
2284
2193
|
// Passthrough
|
|
2285
2194
|
Object2({})
|
|
2286
2195
|
)
|
|
@@ -2332,7 +2241,7 @@ function RequiredResolve(type) {
|
|
|
2332
2241
|
// Mappable
|
|
2333
2242
|
IsComputed(type) ? FromComputed4(type.target, type.parameters) : IsRef(type) ? FromRef4(type.$ref) : IsIntersect(type) ? Intersect(FromRest7(type.allOf)) : IsUnion(type) ? Union(FromRest7(type.anyOf)) : IsObject3(type) ? FromObject6(type, type.properties) : (
|
|
2334
2243
|
// Intrinsic
|
|
2335
|
-
|
|
2244
|
+
IsBigInt3(type) ? type : IsBoolean3(type) ? type : IsInteger2(type) ? type : IsLiteral(type) ? type : IsNull3(type) ? type : IsNumber3(type) ? type : IsString3(type) ? type : IsSymbol3(type) ? type : IsUndefined3(type) ? type : (
|
|
2336
2245
|
// Passthrough
|
|
2337
2246
|
Object2({})
|
|
2338
2247
|
)
|
|
@@ -2440,7 +2349,7 @@ function FromType2(moduleProperties, type) {
|
|
|
2440
2349
|
// Transform
|
|
2441
2350
|
IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
|
|
2442
2351
|
// Types
|
|
2443
|
-
IsArray3(type) ? CreateType(FromArray6(moduleProperties, type.items), type) :
|
|
2352
|
+
IsArray3(type) ? CreateType(FromArray6(moduleProperties, type.items), type) : IsAsyncIterator3(type) ? CreateType(FromAsyncIterator3(moduleProperties, type.items), type) : IsComputed(type) ? CreateType(FromComputed5(moduleProperties, type.target, type.parameters)) : IsConstructor(type) ? CreateType(FromConstructor3(moduleProperties, type.parameters, type.returns), type) : IsFunction3(type) ? CreateType(FromFunction3(moduleProperties, type.parameters, type.returns), type) : IsIntersect(type) ? CreateType(FromIntersect8(moduleProperties, type.allOf), type) : IsIterator3(type) ? CreateType(FromIterator3(moduleProperties, type.items), type) : IsObject3(type) ? CreateType(FromObject7(moduleProperties, type.properties), type) : IsRecord(type) ? CreateType(FromRecord3(moduleProperties, type)) : IsTuple(type) ? CreateType(FromTuple5(moduleProperties, type.items || []), type) : IsUnion(type) ? CreateType(FromUnion10(moduleProperties, type.anyOf), type) : type
|
|
2444
2353
|
)
|
|
2445
2354
|
)
|
|
2446
2355
|
);
|
|
@@ -2474,11 +2383,11 @@ var TModule = class {
|
|
|
2474
2383
|
function Module(properties) {
|
|
2475
2384
|
return new TModule(properties);
|
|
2476
2385
|
}
|
|
2477
|
-
function
|
|
2386
|
+
function Not2(type, options) {
|
|
2478
2387
|
return CreateType({ [Kind]: "Not", not: type }, options);
|
|
2479
2388
|
}
|
|
2480
2389
|
function Parameters(schema, options) {
|
|
2481
|
-
return
|
|
2390
|
+
return IsFunction3(schema) ? Tuple(schema.parameters, options) : Never();
|
|
2482
2391
|
}
|
|
2483
2392
|
var Ordinal = 0;
|
|
2484
2393
|
function Recursive(callback, options = {}) {
|
|
@@ -2499,7 +2408,7 @@ function Rest(T) {
|
|
|
2499
2408
|
return RestResolve(T);
|
|
2500
2409
|
}
|
|
2501
2410
|
function ReturnType(schema, options) {
|
|
2502
|
-
return
|
|
2411
|
+
return IsFunction3(schema) ? CreateType(schema.returns, options) : Never(options);
|
|
2503
2412
|
}
|
|
2504
2413
|
var TransformDecodeBuilder = class {
|
|
2505
2414
|
constructor(schema) {
|
|
@@ -2524,91 +2433,1811 @@ var TransformEncodeBuilder = class {
|
|
|
2524
2433
|
const Codec = { Decode: this.decode, Encode: encode };
|
|
2525
2434
|
return { ...schema, [TransformKind]: Codec };
|
|
2526
2435
|
}
|
|
2527
|
-
Encode(encode) {
|
|
2528
|
-
return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
|
|
2436
|
+
Encode(encode) {
|
|
2437
|
+
return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
function Transform(schema) {
|
|
2441
|
+
return new TransformDecodeBuilder(schema);
|
|
2442
|
+
}
|
|
2443
|
+
function Unsafe(options = {}) {
|
|
2444
|
+
return CreateType({ [Kind]: options[Kind] ?? "Unsafe" }, options);
|
|
2445
|
+
}
|
|
2446
|
+
function Void(options) {
|
|
2447
|
+
return CreateType({ [Kind]: "Void", type: "void" }, options);
|
|
2448
|
+
}
|
|
2449
|
+
var type_exports3 = {};
|
|
2450
|
+
__export(type_exports3, {
|
|
2451
|
+
Any: () => Any,
|
|
2452
|
+
Argument: () => Argument,
|
|
2453
|
+
Array: () => Array2,
|
|
2454
|
+
AsyncIterator: () => AsyncIterator,
|
|
2455
|
+
Awaited: () => Awaited,
|
|
2456
|
+
BigInt: () => BigInt2,
|
|
2457
|
+
Boolean: () => Boolean2,
|
|
2458
|
+
Capitalize: () => Capitalize,
|
|
2459
|
+
Composite: () => Composite,
|
|
2460
|
+
Const: () => Const,
|
|
2461
|
+
Constructor: () => Constructor,
|
|
2462
|
+
ConstructorParameters: () => ConstructorParameters,
|
|
2463
|
+
Date: () => Date2,
|
|
2464
|
+
Enum: () => Enum,
|
|
2465
|
+
Exclude: () => Exclude,
|
|
2466
|
+
Extends: () => Extends,
|
|
2467
|
+
Extract: () => Extract,
|
|
2468
|
+
Function: () => Function,
|
|
2469
|
+
Index: () => Index,
|
|
2470
|
+
InstanceType: () => InstanceType,
|
|
2471
|
+
Instantiate: () => Instantiate,
|
|
2472
|
+
Integer: () => Integer,
|
|
2473
|
+
Intersect: () => Intersect,
|
|
2474
|
+
Iterator: () => Iterator,
|
|
2475
|
+
KeyOf: () => KeyOf,
|
|
2476
|
+
Literal: () => Literal,
|
|
2477
|
+
Lowercase: () => Lowercase,
|
|
2478
|
+
Mapped: () => Mapped,
|
|
2479
|
+
Module: () => Module,
|
|
2480
|
+
Never: () => Never,
|
|
2481
|
+
Not: () => Not2,
|
|
2482
|
+
Null: () => Null,
|
|
2483
|
+
Number: () => Number2,
|
|
2484
|
+
Object: () => Object2,
|
|
2485
|
+
Omit: () => Omit,
|
|
2486
|
+
Optional: () => Optional,
|
|
2487
|
+
Parameters: () => Parameters,
|
|
2488
|
+
Partial: () => Partial,
|
|
2489
|
+
Pick: () => Pick,
|
|
2490
|
+
Promise: () => Promise2,
|
|
2491
|
+
Readonly: () => Readonly,
|
|
2492
|
+
ReadonlyOptional: () => ReadonlyOptional,
|
|
2493
|
+
Record: () => Record,
|
|
2494
|
+
Recursive: () => Recursive,
|
|
2495
|
+
Ref: () => Ref,
|
|
2496
|
+
RegExp: () => RegExp2,
|
|
2497
|
+
Required: () => Required,
|
|
2498
|
+
Rest: () => Rest,
|
|
2499
|
+
ReturnType: () => ReturnType,
|
|
2500
|
+
String: () => String2,
|
|
2501
|
+
Symbol: () => Symbol2,
|
|
2502
|
+
TemplateLiteral: () => TemplateLiteral,
|
|
2503
|
+
Transform: () => Transform,
|
|
2504
|
+
Tuple: () => Tuple,
|
|
2505
|
+
Uint8Array: () => Uint8Array2,
|
|
2506
|
+
Uncapitalize: () => Uncapitalize,
|
|
2507
|
+
Undefined: () => Undefined,
|
|
2508
|
+
Union: () => Union,
|
|
2509
|
+
Unknown: () => Unknown,
|
|
2510
|
+
Unsafe: () => Unsafe,
|
|
2511
|
+
Uppercase: () => Uppercase,
|
|
2512
|
+
Void: () => Void
|
|
2513
|
+
});
|
|
2514
|
+
var Type = type_exports3;
|
|
2515
|
+
function Evaluate(...args) {
|
|
2516
|
+
return new globalThis.Function(...args);
|
|
2517
|
+
}
|
|
2518
|
+
function DefaultErrorFunction(error2) {
|
|
2519
|
+
switch (error2.errorType) {
|
|
2520
|
+
case ValueErrorType.ArrayContains:
|
|
2521
|
+
return "Expected array to contain at least one matching value";
|
|
2522
|
+
case ValueErrorType.ArrayMaxContains:
|
|
2523
|
+
return `Expected array to contain no more than ${error2.schema.maxContains} matching values`;
|
|
2524
|
+
case ValueErrorType.ArrayMinContains:
|
|
2525
|
+
return `Expected array to contain at least ${error2.schema.minContains} matching values`;
|
|
2526
|
+
case ValueErrorType.ArrayMaxItems:
|
|
2527
|
+
return `Expected array length to be less or equal to ${error2.schema.maxItems}`;
|
|
2528
|
+
case ValueErrorType.ArrayMinItems:
|
|
2529
|
+
return `Expected array length to be greater or equal to ${error2.schema.minItems}`;
|
|
2530
|
+
case ValueErrorType.ArrayUniqueItems:
|
|
2531
|
+
return "Expected array elements to be unique";
|
|
2532
|
+
case ValueErrorType.Array:
|
|
2533
|
+
return "Expected array";
|
|
2534
|
+
case ValueErrorType.AsyncIterator:
|
|
2535
|
+
return "Expected AsyncIterator";
|
|
2536
|
+
case ValueErrorType.BigIntExclusiveMaximum:
|
|
2537
|
+
return `Expected bigint to be less than ${error2.schema.exclusiveMaximum}`;
|
|
2538
|
+
case ValueErrorType.BigIntExclusiveMinimum:
|
|
2539
|
+
return `Expected bigint to be greater than ${error2.schema.exclusiveMinimum}`;
|
|
2540
|
+
case ValueErrorType.BigIntMaximum:
|
|
2541
|
+
return `Expected bigint to be less or equal to ${error2.schema.maximum}`;
|
|
2542
|
+
case ValueErrorType.BigIntMinimum:
|
|
2543
|
+
return `Expected bigint to be greater or equal to ${error2.schema.minimum}`;
|
|
2544
|
+
case ValueErrorType.BigIntMultipleOf:
|
|
2545
|
+
return `Expected bigint to be a multiple of ${error2.schema.multipleOf}`;
|
|
2546
|
+
case ValueErrorType.BigInt:
|
|
2547
|
+
return "Expected bigint";
|
|
2548
|
+
case ValueErrorType.Boolean:
|
|
2549
|
+
return "Expected boolean";
|
|
2550
|
+
case ValueErrorType.DateExclusiveMinimumTimestamp:
|
|
2551
|
+
return `Expected Date timestamp to be greater than ${error2.schema.exclusiveMinimumTimestamp}`;
|
|
2552
|
+
case ValueErrorType.DateExclusiveMaximumTimestamp:
|
|
2553
|
+
return `Expected Date timestamp to be less than ${error2.schema.exclusiveMaximumTimestamp}`;
|
|
2554
|
+
case ValueErrorType.DateMinimumTimestamp:
|
|
2555
|
+
return `Expected Date timestamp to be greater or equal to ${error2.schema.minimumTimestamp}`;
|
|
2556
|
+
case ValueErrorType.DateMaximumTimestamp:
|
|
2557
|
+
return `Expected Date timestamp to be less or equal to ${error2.schema.maximumTimestamp}`;
|
|
2558
|
+
case ValueErrorType.DateMultipleOfTimestamp:
|
|
2559
|
+
return `Expected Date timestamp to be a multiple of ${error2.schema.multipleOfTimestamp}`;
|
|
2560
|
+
case ValueErrorType.Date:
|
|
2561
|
+
return "Expected Date";
|
|
2562
|
+
case ValueErrorType.Function:
|
|
2563
|
+
return "Expected function";
|
|
2564
|
+
case ValueErrorType.IntegerExclusiveMaximum:
|
|
2565
|
+
return `Expected integer to be less than ${error2.schema.exclusiveMaximum}`;
|
|
2566
|
+
case ValueErrorType.IntegerExclusiveMinimum:
|
|
2567
|
+
return `Expected integer to be greater than ${error2.schema.exclusiveMinimum}`;
|
|
2568
|
+
case ValueErrorType.IntegerMaximum:
|
|
2569
|
+
return `Expected integer to be less or equal to ${error2.schema.maximum}`;
|
|
2570
|
+
case ValueErrorType.IntegerMinimum:
|
|
2571
|
+
return `Expected integer to be greater or equal to ${error2.schema.minimum}`;
|
|
2572
|
+
case ValueErrorType.IntegerMultipleOf:
|
|
2573
|
+
return `Expected integer to be a multiple of ${error2.schema.multipleOf}`;
|
|
2574
|
+
case ValueErrorType.Integer:
|
|
2575
|
+
return "Expected integer";
|
|
2576
|
+
case ValueErrorType.IntersectUnevaluatedProperties:
|
|
2577
|
+
return "Unexpected property";
|
|
2578
|
+
case ValueErrorType.Intersect:
|
|
2579
|
+
return "Expected all values to match";
|
|
2580
|
+
case ValueErrorType.Iterator:
|
|
2581
|
+
return "Expected Iterator";
|
|
2582
|
+
case ValueErrorType.Literal:
|
|
2583
|
+
return `Expected ${typeof error2.schema.const === "string" ? `'${error2.schema.const}'` : error2.schema.const}`;
|
|
2584
|
+
case ValueErrorType.Never:
|
|
2585
|
+
return "Never";
|
|
2586
|
+
case ValueErrorType.Not:
|
|
2587
|
+
return "Value should not match";
|
|
2588
|
+
case ValueErrorType.Null:
|
|
2589
|
+
return "Expected null";
|
|
2590
|
+
case ValueErrorType.NumberExclusiveMaximum:
|
|
2591
|
+
return `Expected number to be less than ${error2.schema.exclusiveMaximum}`;
|
|
2592
|
+
case ValueErrorType.NumberExclusiveMinimum:
|
|
2593
|
+
return `Expected number to be greater than ${error2.schema.exclusiveMinimum}`;
|
|
2594
|
+
case ValueErrorType.NumberMaximum:
|
|
2595
|
+
return `Expected number to be less or equal to ${error2.schema.maximum}`;
|
|
2596
|
+
case ValueErrorType.NumberMinimum:
|
|
2597
|
+
return `Expected number to be greater or equal to ${error2.schema.minimum}`;
|
|
2598
|
+
case ValueErrorType.NumberMultipleOf:
|
|
2599
|
+
return `Expected number to be a multiple of ${error2.schema.multipleOf}`;
|
|
2600
|
+
case ValueErrorType.Number:
|
|
2601
|
+
return "Expected number";
|
|
2602
|
+
case ValueErrorType.Object:
|
|
2603
|
+
return "Expected object";
|
|
2604
|
+
case ValueErrorType.ObjectAdditionalProperties:
|
|
2605
|
+
return "Unexpected property";
|
|
2606
|
+
case ValueErrorType.ObjectMaxProperties:
|
|
2607
|
+
return `Expected object to have no more than ${error2.schema.maxProperties} properties`;
|
|
2608
|
+
case ValueErrorType.ObjectMinProperties:
|
|
2609
|
+
return `Expected object to have at least ${error2.schema.minProperties} properties`;
|
|
2610
|
+
case ValueErrorType.ObjectRequiredProperty:
|
|
2611
|
+
return "Expected required property";
|
|
2612
|
+
case ValueErrorType.Promise:
|
|
2613
|
+
return "Expected Promise";
|
|
2614
|
+
case ValueErrorType.RegExp:
|
|
2615
|
+
return "Expected string to match regular expression";
|
|
2616
|
+
case ValueErrorType.StringFormatUnknown:
|
|
2617
|
+
return `Unknown format '${error2.schema.format}'`;
|
|
2618
|
+
case ValueErrorType.StringFormat:
|
|
2619
|
+
return `Expected string to match '${error2.schema.format}' format`;
|
|
2620
|
+
case ValueErrorType.StringMaxLength:
|
|
2621
|
+
return `Expected string length less or equal to ${error2.schema.maxLength}`;
|
|
2622
|
+
case ValueErrorType.StringMinLength:
|
|
2623
|
+
return `Expected string length greater or equal to ${error2.schema.minLength}`;
|
|
2624
|
+
case ValueErrorType.StringPattern:
|
|
2625
|
+
return `Expected string to match '${error2.schema.pattern}'`;
|
|
2626
|
+
case ValueErrorType.String:
|
|
2627
|
+
return "Expected string";
|
|
2628
|
+
case ValueErrorType.Symbol:
|
|
2629
|
+
return "Expected symbol";
|
|
2630
|
+
case ValueErrorType.TupleLength:
|
|
2631
|
+
return `Expected tuple to have ${error2.schema.maxItems || 0} elements`;
|
|
2632
|
+
case ValueErrorType.Tuple:
|
|
2633
|
+
return "Expected tuple";
|
|
2634
|
+
case ValueErrorType.Uint8ArrayMaxByteLength:
|
|
2635
|
+
return `Expected byte length less or equal to ${error2.schema.maxByteLength}`;
|
|
2636
|
+
case ValueErrorType.Uint8ArrayMinByteLength:
|
|
2637
|
+
return `Expected byte length greater or equal to ${error2.schema.minByteLength}`;
|
|
2638
|
+
case ValueErrorType.Uint8Array:
|
|
2639
|
+
return "Expected Uint8Array";
|
|
2640
|
+
case ValueErrorType.Undefined:
|
|
2641
|
+
return "Expected undefined";
|
|
2642
|
+
case ValueErrorType.Union:
|
|
2643
|
+
return "Expected union value";
|
|
2644
|
+
case ValueErrorType.Void:
|
|
2645
|
+
return "Expected void";
|
|
2646
|
+
case ValueErrorType.Kind:
|
|
2647
|
+
return `Expected kind '${error2.schema[Kind]}'`;
|
|
2648
|
+
default:
|
|
2649
|
+
return "Unknown error type";
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
var errorFunction = DefaultErrorFunction;
|
|
2653
|
+
function GetErrorFunction() {
|
|
2654
|
+
return errorFunction;
|
|
2655
|
+
}
|
|
2656
|
+
var TypeDereferenceError = class extends TypeBoxError {
|
|
2657
|
+
constructor(schema) {
|
|
2658
|
+
super(`Unable to dereference schema with $id '${schema.$ref}'`);
|
|
2659
|
+
this.schema = schema;
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
function Resolve(schema, references) {
|
|
2663
|
+
const target = references.find((target2) => target2.$id === schema.$ref);
|
|
2664
|
+
if (target === void 0)
|
|
2665
|
+
throw new TypeDereferenceError(schema);
|
|
2666
|
+
return Deref(target, references);
|
|
2667
|
+
}
|
|
2668
|
+
function Pushref(schema, references) {
|
|
2669
|
+
if (!IsString2(schema.$id) || references.some((target) => target.$id === schema.$id))
|
|
2670
|
+
return references;
|
|
2671
|
+
references.push(schema);
|
|
2672
|
+
return references;
|
|
2673
|
+
}
|
|
2674
|
+
function Deref(schema, references) {
|
|
2675
|
+
return schema[Kind] === "This" || schema[Kind] === "Ref" ? Resolve(schema, references) : schema;
|
|
2676
|
+
}
|
|
2677
|
+
var ValueHashError = class extends TypeBoxError {
|
|
2678
|
+
constructor(value) {
|
|
2679
|
+
super(`Unable to hash value`);
|
|
2680
|
+
this.value = value;
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
var ByteMarker;
|
|
2684
|
+
(function(ByteMarker2) {
|
|
2685
|
+
ByteMarker2[ByteMarker2["Undefined"] = 0] = "Undefined";
|
|
2686
|
+
ByteMarker2[ByteMarker2["Null"] = 1] = "Null";
|
|
2687
|
+
ByteMarker2[ByteMarker2["Boolean"] = 2] = "Boolean";
|
|
2688
|
+
ByteMarker2[ByteMarker2["Number"] = 3] = "Number";
|
|
2689
|
+
ByteMarker2[ByteMarker2["String"] = 4] = "String";
|
|
2690
|
+
ByteMarker2[ByteMarker2["Object"] = 5] = "Object";
|
|
2691
|
+
ByteMarker2[ByteMarker2["Array"] = 6] = "Array";
|
|
2692
|
+
ByteMarker2[ByteMarker2["Date"] = 7] = "Date";
|
|
2693
|
+
ByteMarker2[ByteMarker2["Uint8Array"] = 8] = "Uint8Array";
|
|
2694
|
+
ByteMarker2[ByteMarker2["Symbol"] = 9] = "Symbol";
|
|
2695
|
+
ByteMarker2[ByteMarker2["BigInt"] = 10] = "BigInt";
|
|
2696
|
+
})(ByteMarker || (ByteMarker = {}));
|
|
2697
|
+
var Accumulator = BigInt("14695981039346656037");
|
|
2698
|
+
var [Prime, Size] = [BigInt("1099511628211"), BigInt(
|
|
2699
|
+
"18446744073709551616"
|
|
2700
|
+
/* 2 ^ 64 */
|
|
2701
|
+
)];
|
|
2702
|
+
var Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i));
|
|
2703
|
+
var F64 = new Float64Array(1);
|
|
2704
|
+
var F64In = new DataView(F64.buffer);
|
|
2705
|
+
var F64Out = new Uint8Array(F64.buffer);
|
|
2706
|
+
function* NumberToBytes(value) {
|
|
2707
|
+
const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8);
|
|
2708
|
+
for (let i = 0; i < byteCount; i++) {
|
|
2709
|
+
yield value >> 8 * (byteCount - 1 - i) & 255;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
function ArrayType2(value) {
|
|
2713
|
+
FNV1A64(ByteMarker.Array);
|
|
2714
|
+
for (const item of value) {
|
|
2715
|
+
Visit4(item);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
function BooleanType(value) {
|
|
2719
|
+
FNV1A64(ByteMarker.Boolean);
|
|
2720
|
+
FNV1A64(value ? 1 : 0);
|
|
2721
|
+
}
|
|
2722
|
+
function BigIntType(value) {
|
|
2723
|
+
FNV1A64(ByteMarker.BigInt);
|
|
2724
|
+
F64In.setBigInt64(0, value);
|
|
2725
|
+
for (const byte of F64Out) {
|
|
2726
|
+
FNV1A64(byte);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
function DateType2(value) {
|
|
2730
|
+
FNV1A64(ByteMarker.Date);
|
|
2731
|
+
Visit4(value.getTime());
|
|
2732
|
+
}
|
|
2733
|
+
function NullType(value) {
|
|
2734
|
+
FNV1A64(ByteMarker.Null);
|
|
2735
|
+
}
|
|
2736
|
+
function NumberType(value) {
|
|
2737
|
+
FNV1A64(ByteMarker.Number);
|
|
2738
|
+
F64In.setFloat64(0, value);
|
|
2739
|
+
for (const byte of F64Out) {
|
|
2740
|
+
FNV1A64(byte);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
function ObjectType2(value) {
|
|
2744
|
+
FNV1A64(ByteMarker.Object);
|
|
2745
|
+
for (const key of globalThis.Object.getOwnPropertyNames(value).sort()) {
|
|
2746
|
+
Visit4(key);
|
|
2747
|
+
Visit4(value[key]);
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
function StringType(value) {
|
|
2751
|
+
FNV1A64(ByteMarker.String);
|
|
2752
|
+
for (let i = 0; i < value.length; i++) {
|
|
2753
|
+
for (const byte of NumberToBytes(value.charCodeAt(i))) {
|
|
2754
|
+
FNV1A64(byte);
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
function SymbolType(value) {
|
|
2759
|
+
FNV1A64(ByteMarker.Symbol);
|
|
2760
|
+
Visit4(value.description);
|
|
2761
|
+
}
|
|
2762
|
+
function Uint8ArrayType2(value) {
|
|
2763
|
+
FNV1A64(ByteMarker.Uint8Array);
|
|
2764
|
+
for (let i = 0; i < value.length; i++) {
|
|
2765
|
+
FNV1A64(value[i]);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
function UndefinedType(value) {
|
|
2769
|
+
return FNV1A64(ByteMarker.Undefined);
|
|
2770
|
+
}
|
|
2771
|
+
function Visit4(value) {
|
|
2772
|
+
if (IsArray2(value))
|
|
2773
|
+
return ArrayType2(value);
|
|
2774
|
+
if (IsBoolean2(value))
|
|
2775
|
+
return BooleanType(value);
|
|
2776
|
+
if (IsBigInt2(value))
|
|
2777
|
+
return BigIntType(value);
|
|
2778
|
+
if (IsDate2(value))
|
|
2779
|
+
return DateType2(value);
|
|
2780
|
+
if (IsNull2(value))
|
|
2781
|
+
return NullType(value);
|
|
2782
|
+
if (IsNumber2(value))
|
|
2783
|
+
return NumberType(value);
|
|
2784
|
+
if (IsObject2(value))
|
|
2785
|
+
return ObjectType2(value);
|
|
2786
|
+
if (IsString2(value))
|
|
2787
|
+
return StringType(value);
|
|
2788
|
+
if (IsSymbol2(value))
|
|
2789
|
+
return SymbolType(value);
|
|
2790
|
+
if (IsUint8Array2(value))
|
|
2791
|
+
return Uint8ArrayType2(value);
|
|
2792
|
+
if (IsUndefined2(value))
|
|
2793
|
+
return UndefinedType(value);
|
|
2794
|
+
throw new ValueHashError(value);
|
|
2795
|
+
}
|
|
2796
|
+
function FNV1A64(byte) {
|
|
2797
|
+
Accumulator = Accumulator ^ Bytes[byte];
|
|
2798
|
+
Accumulator = Accumulator * Prime % Size;
|
|
2799
|
+
}
|
|
2800
|
+
function Hash(value) {
|
|
2801
|
+
Accumulator = BigInt("14695981039346656037");
|
|
2802
|
+
Visit4(value);
|
|
2803
|
+
return Accumulator;
|
|
2804
|
+
}
|
|
2805
|
+
var ValueCheckUnknownTypeError = class extends TypeBoxError {
|
|
2806
|
+
constructor(schema) {
|
|
2807
|
+
super(`Unknown type`);
|
|
2808
|
+
this.schema = schema;
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
function IsAnyOrUnknown(schema) {
|
|
2812
|
+
return schema[Kind] === "Any" || schema[Kind] === "Unknown";
|
|
2813
|
+
}
|
|
2814
|
+
function IsDefined(value) {
|
|
2815
|
+
return value !== void 0;
|
|
2816
|
+
}
|
|
2817
|
+
function FromAny2(schema, references, value) {
|
|
2818
|
+
return true;
|
|
2819
|
+
}
|
|
2820
|
+
function FromArgument2(schema, references, value) {
|
|
2821
|
+
return true;
|
|
2822
|
+
}
|
|
2823
|
+
function FromArray7(schema, references, value) {
|
|
2824
|
+
if (!IsArray2(value))
|
|
2825
|
+
return false;
|
|
2826
|
+
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
2827
|
+
return false;
|
|
2828
|
+
}
|
|
2829
|
+
if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
2830
|
+
return false;
|
|
2831
|
+
}
|
|
2832
|
+
for (const element of value) {
|
|
2833
|
+
if (!Visit5(schema.items, references, element))
|
|
2834
|
+
return false;
|
|
2835
|
+
}
|
|
2836
|
+
if (schema.uniqueItems === true && !(function() {
|
|
2837
|
+
const set = /* @__PURE__ */ new Set();
|
|
2838
|
+
for (const element of value) {
|
|
2839
|
+
const hashed = Hash(element);
|
|
2840
|
+
if (set.has(hashed)) {
|
|
2841
|
+
return false;
|
|
2842
|
+
} else {
|
|
2843
|
+
set.add(hashed);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
return true;
|
|
2847
|
+
})()) {
|
|
2848
|
+
return false;
|
|
2849
|
+
}
|
|
2850
|
+
if (!(IsDefined(schema.contains) || IsNumber2(schema.minContains) || IsNumber2(schema.maxContains))) {
|
|
2851
|
+
return true;
|
|
2852
|
+
}
|
|
2853
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : Never();
|
|
2854
|
+
const containsCount = value.reduce((acc, value2) => Visit5(containsSchema, references, value2) ? acc + 1 : acc, 0);
|
|
2855
|
+
if (containsCount === 0) {
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
if (IsNumber2(schema.minContains) && containsCount < schema.minContains) {
|
|
2859
|
+
return false;
|
|
2860
|
+
}
|
|
2861
|
+
if (IsNumber2(schema.maxContains) && containsCount > schema.maxContains) {
|
|
2862
|
+
return false;
|
|
2863
|
+
}
|
|
2864
|
+
return true;
|
|
2865
|
+
}
|
|
2866
|
+
function FromAsyncIterator4(schema, references, value) {
|
|
2867
|
+
return IsAsyncIterator2(value);
|
|
2868
|
+
}
|
|
2869
|
+
function FromBigInt2(schema, references, value) {
|
|
2870
|
+
if (!IsBigInt2(value))
|
|
2871
|
+
return false;
|
|
2872
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2873
|
+
return false;
|
|
2874
|
+
}
|
|
2875
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2876
|
+
return false;
|
|
2877
|
+
}
|
|
2878
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2879
|
+
return false;
|
|
2880
|
+
}
|
|
2881
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2882
|
+
return false;
|
|
2883
|
+
}
|
|
2884
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
|
|
2885
|
+
return false;
|
|
2886
|
+
}
|
|
2887
|
+
return true;
|
|
2888
|
+
}
|
|
2889
|
+
function FromBoolean2(schema, references, value) {
|
|
2890
|
+
return IsBoolean2(value);
|
|
2891
|
+
}
|
|
2892
|
+
function FromConstructor4(schema, references, value) {
|
|
2893
|
+
return Visit5(schema.returns, references, value.prototype);
|
|
2894
|
+
}
|
|
2895
|
+
function FromDate2(schema, references, value) {
|
|
2896
|
+
if (!IsDate2(value))
|
|
2897
|
+
return false;
|
|
2898
|
+
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (IsDefined(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
if (IsDefined(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
2905
|
+
return false;
|
|
2906
|
+
}
|
|
2907
|
+
if (IsDefined(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
2908
|
+
return false;
|
|
2909
|
+
}
|
|
2910
|
+
if (IsDefined(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
|
|
2911
|
+
return false;
|
|
2912
|
+
}
|
|
2913
|
+
return true;
|
|
2914
|
+
}
|
|
2915
|
+
function FromFunction4(schema, references, value) {
|
|
2916
|
+
return IsFunction2(value);
|
|
2917
|
+
}
|
|
2918
|
+
function FromImport(schema, references, value) {
|
|
2919
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
2920
|
+
const target = schema.$defs[schema.$ref];
|
|
2921
|
+
return Visit5(target, [...references, ...definitions], value);
|
|
2922
|
+
}
|
|
2923
|
+
function FromInteger2(schema, references, value) {
|
|
2924
|
+
if (!IsInteger(value)) {
|
|
2925
|
+
return false;
|
|
2926
|
+
}
|
|
2927
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2930
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2931
|
+
return false;
|
|
2932
|
+
}
|
|
2933
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2934
|
+
return false;
|
|
2935
|
+
}
|
|
2936
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2937
|
+
return false;
|
|
2938
|
+
}
|
|
2939
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2940
|
+
return false;
|
|
2941
|
+
}
|
|
2942
|
+
return true;
|
|
2943
|
+
}
|
|
2944
|
+
function FromIntersect9(schema, references, value) {
|
|
2945
|
+
const check1 = schema.allOf.every((schema2) => Visit5(schema2, references, value));
|
|
2946
|
+
if (schema.unevaluatedProperties === false) {
|
|
2947
|
+
const keyPattern = new RegExp(KeyOfPattern(schema));
|
|
2948
|
+
const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
|
|
2949
|
+
return check1 && check2;
|
|
2950
|
+
} else if (IsSchema(schema.unevaluatedProperties)) {
|
|
2951
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
2952
|
+
const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit5(schema.unevaluatedProperties, references, value[key]));
|
|
2953
|
+
return check1 && check2;
|
|
2954
|
+
} else {
|
|
2955
|
+
return check1;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
function FromIterator4(schema, references, value) {
|
|
2959
|
+
return IsIterator2(value);
|
|
2960
|
+
}
|
|
2961
|
+
function FromLiteral3(schema, references, value) {
|
|
2962
|
+
return value === schema.const;
|
|
2963
|
+
}
|
|
2964
|
+
function FromNever2(schema, references, value) {
|
|
2965
|
+
return false;
|
|
2966
|
+
}
|
|
2967
|
+
function FromNot2(schema, references, value) {
|
|
2968
|
+
return !Visit5(schema.not, references, value);
|
|
2969
|
+
}
|
|
2970
|
+
function FromNull2(schema, references, value) {
|
|
2971
|
+
return IsNull2(value);
|
|
2972
|
+
}
|
|
2973
|
+
function FromNumber2(schema, references, value) {
|
|
2974
|
+
if (!TypeSystemPolicy.IsNumberLike(value))
|
|
2975
|
+
return false;
|
|
2976
|
+
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
2977
|
+
return false;
|
|
2978
|
+
}
|
|
2979
|
+
if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
2980
|
+
return false;
|
|
2981
|
+
}
|
|
2982
|
+
if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
|
|
2983
|
+
return false;
|
|
2984
|
+
}
|
|
2985
|
+
if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
|
|
2986
|
+
return false;
|
|
2987
|
+
}
|
|
2988
|
+
if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
2989
|
+
return false;
|
|
2990
|
+
}
|
|
2991
|
+
return true;
|
|
2992
|
+
}
|
|
2993
|
+
function FromObject8(schema, references, value) {
|
|
2994
|
+
if (!TypeSystemPolicy.IsObjectLike(value))
|
|
2995
|
+
return false;
|
|
2996
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
2997
|
+
return false;
|
|
2998
|
+
}
|
|
2999
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
3000
|
+
return false;
|
|
3001
|
+
}
|
|
3002
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
3003
|
+
for (const knownKey of knownKeys) {
|
|
3004
|
+
const property = schema.properties[knownKey];
|
|
3005
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
3006
|
+
if (!Visit5(property, references, value[knownKey])) {
|
|
3007
|
+
return false;
|
|
3008
|
+
}
|
|
3009
|
+
if ((ExtendsUndefinedCheck(property) || IsAnyOrUnknown(property)) && !(knownKey in value)) {
|
|
3010
|
+
return false;
|
|
3011
|
+
}
|
|
3012
|
+
} else {
|
|
3013
|
+
if (TypeSystemPolicy.IsExactOptionalProperty(value, knownKey) && !Visit5(property, references, value[knownKey])) {
|
|
3014
|
+
return false;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
if (schema.additionalProperties === false) {
|
|
3019
|
+
const valueKeys = Object.getOwnPropertyNames(value);
|
|
3020
|
+
if (schema.required && schema.required.length === knownKeys.length && valueKeys.length === knownKeys.length) {
|
|
3021
|
+
return true;
|
|
3022
|
+
} else {
|
|
3023
|
+
return valueKeys.every((valueKey) => knownKeys.includes(valueKey));
|
|
3024
|
+
}
|
|
3025
|
+
} else if (typeof schema.additionalProperties === "object") {
|
|
3026
|
+
const valueKeys = Object.getOwnPropertyNames(value);
|
|
3027
|
+
return valueKeys.every((key) => knownKeys.includes(key) || Visit5(schema.additionalProperties, references, value[key]));
|
|
3028
|
+
} else {
|
|
3029
|
+
return true;
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
function FromPromise4(schema, references, value) {
|
|
3033
|
+
return IsPromise(value);
|
|
3034
|
+
}
|
|
3035
|
+
function FromRecord4(schema, references, value) {
|
|
3036
|
+
if (!TypeSystemPolicy.IsRecordLike(value)) {
|
|
3037
|
+
return false;
|
|
3038
|
+
}
|
|
3039
|
+
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
3040
|
+
return false;
|
|
3041
|
+
}
|
|
3042
|
+
if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
3043
|
+
return false;
|
|
3044
|
+
}
|
|
3045
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
3046
|
+
const regex = new RegExp(patternKey);
|
|
3047
|
+
const check1 = Object.entries(value).every(([key, value2]) => {
|
|
3048
|
+
return regex.test(key) ? Visit5(patternSchema, references, value2) : true;
|
|
3049
|
+
});
|
|
3050
|
+
const check2 = typeof schema.additionalProperties === "object" ? Object.entries(value).every(([key, value2]) => {
|
|
3051
|
+
return !regex.test(key) ? Visit5(schema.additionalProperties, references, value2) : true;
|
|
3052
|
+
}) : true;
|
|
3053
|
+
const check3 = schema.additionalProperties === false ? Object.getOwnPropertyNames(value).every((key) => {
|
|
3054
|
+
return regex.test(key);
|
|
3055
|
+
}) : true;
|
|
3056
|
+
return check1 && check2 && check3;
|
|
3057
|
+
}
|
|
3058
|
+
function FromRef5(schema, references, value) {
|
|
3059
|
+
return Visit5(Deref(schema, references), references, value);
|
|
3060
|
+
}
|
|
3061
|
+
function FromRegExp2(schema, references, value) {
|
|
3062
|
+
const regex = new RegExp(schema.source, schema.flags);
|
|
3063
|
+
if (IsDefined(schema.minLength)) {
|
|
3064
|
+
if (!(value.length >= schema.minLength))
|
|
3065
|
+
return false;
|
|
3066
|
+
}
|
|
3067
|
+
if (IsDefined(schema.maxLength)) {
|
|
3068
|
+
if (!(value.length <= schema.maxLength))
|
|
3069
|
+
return false;
|
|
3070
|
+
}
|
|
3071
|
+
return regex.test(value);
|
|
3072
|
+
}
|
|
3073
|
+
function FromString2(schema, references, value) {
|
|
3074
|
+
if (!IsString2(value)) {
|
|
3075
|
+
return false;
|
|
3076
|
+
}
|
|
3077
|
+
if (IsDefined(schema.minLength)) {
|
|
3078
|
+
if (!(value.length >= schema.minLength))
|
|
3079
|
+
return false;
|
|
3080
|
+
}
|
|
3081
|
+
if (IsDefined(schema.maxLength)) {
|
|
3082
|
+
if (!(value.length <= schema.maxLength))
|
|
3083
|
+
return false;
|
|
3084
|
+
}
|
|
3085
|
+
if (IsDefined(schema.pattern)) {
|
|
3086
|
+
const regex = new RegExp(schema.pattern);
|
|
3087
|
+
if (!regex.test(value))
|
|
3088
|
+
return false;
|
|
3089
|
+
}
|
|
3090
|
+
if (IsDefined(schema.format)) {
|
|
3091
|
+
if (!format_exports.Has(schema.format))
|
|
3092
|
+
return false;
|
|
3093
|
+
const func = format_exports.Get(schema.format);
|
|
3094
|
+
return func(value);
|
|
3095
|
+
}
|
|
3096
|
+
return true;
|
|
3097
|
+
}
|
|
3098
|
+
function FromSymbol2(schema, references, value) {
|
|
3099
|
+
return IsSymbol2(value);
|
|
3100
|
+
}
|
|
3101
|
+
function FromTemplateLiteral4(schema, references, value) {
|
|
3102
|
+
return IsString2(value) && new RegExp(schema.pattern).test(value);
|
|
3103
|
+
}
|
|
3104
|
+
function FromThis(schema, references, value) {
|
|
3105
|
+
return Visit5(Deref(schema, references), references, value);
|
|
3106
|
+
}
|
|
3107
|
+
function FromTuple6(schema, references, value) {
|
|
3108
|
+
if (!IsArray2(value)) {
|
|
3109
|
+
return false;
|
|
3110
|
+
}
|
|
3111
|
+
if (schema.items === void 0 && !(value.length === 0)) {
|
|
3112
|
+
return false;
|
|
3113
|
+
}
|
|
3114
|
+
if (!(value.length === schema.maxItems)) {
|
|
3115
|
+
return false;
|
|
3116
|
+
}
|
|
3117
|
+
if (!schema.items) {
|
|
3118
|
+
return true;
|
|
3119
|
+
}
|
|
3120
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
3121
|
+
if (!Visit5(schema.items[i], references, value[i]))
|
|
3122
|
+
return false;
|
|
3123
|
+
}
|
|
3124
|
+
return true;
|
|
3125
|
+
}
|
|
3126
|
+
function FromUndefined2(schema, references, value) {
|
|
3127
|
+
return IsUndefined2(value);
|
|
3128
|
+
}
|
|
3129
|
+
function FromUnion11(schema, references, value) {
|
|
3130
|
+
return schema.anyOf.some((inner) => Visit5(inner, references, value));
|
|
3131
|
+
}
|
|
3132
|
+
function FromUint8Array2(schema, references, value) {
|
|
3133
|
+
if (!IsUint8Array2(value)) {
|
|
3134
|
+
return false;
|
|
3135
|
+
}
|
|
3136
|
+
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
3137
|
+
return false;
|
|
3138
|
+
}
|
|
3139
|
+
if (IsDefined(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
3140
|
+
return false;
|
|
3141
|
+
}
|
|
3142
|
+
return true;
|
|
3143
|
+
}
|
|
3144
|
+
function FromUnknown2(schema, references, value) {
|
|
3145
|
+
return true;
|
|
3146
|
+
}
|
|
3147
|
+
function FromVoid2(schema, references, value) {
|
|
3148
|
+
return TypeSystemPolicy.IsVoidLike(value);
|
|
3149
|
+
}
|
|
3150
|
+
function FromKind(schema, references, value) {
|
|
3151
|
+
if (!type_exports2.Has(schema[Kind]))
|
|
3152
|
+
return false;
|
|
3153
|
+
const func = type_exports2.Get(schema[Kind]);
|
|
3154
|
+
return func(schema, value);
|
|
3155
|
+
}
|
|
3156
|
+
function Visit5(schema, references, value) {
|
|
3157
|
+
const references_ = IsDefined(schema.$id) ? Pushref(schema, references) : references;
|
|
3158
|
+
const schema_ = schema;
|
|
3159
|
+
switch (schema_[Kind]) {
|
|
3160
|
+
case "Any":
|
|
3161
|
+
return FromAny2(schema_, references_, value);
|
|
3162
|
+
case "Argument":
|
|
3163
|
+
return FromArgument2(schema_, references_, value);
|
|
3164
|
+
case "Array":
|
|
3165
|
+
return FromArray7(schema_, references_, value);
|
|
3166
|
+
case "AsyncIterator":
|
|
3167
|
+
return FromAsyncIterator4(schema_, references_, value);
|
|
3168
|
+
case "BigInt":
|
|
3169
|
+
return FromBigInt2(schema_, references_, value);
|
|
3170
|
+
case "Boolean":
|
|
3171
|
+
return FromBoolean2(schema_, references_, value);
|
|
3172
|
+
case "Constructor":
|
|
3173
|
+
return FromConstructor4(schema_, references_, value);
|
|
3174
|
+
case "Date":
|
|
3175
|
+
return FromDate2(schema_, references_, value);
|
|
3176
|
+
case "Function":
|
|
3177
|
+
return FromFunction4(schema_, references_, value);
|
|
3178
|
+
case "Import":
|
|
3179
|
+
return FromImport(schema_, references_, value);
|
|
3180
|
+
case "Integer":
|
|
3181
|
+
return FromInteger2(schema_, references_, value);
|
|
3182
|
+
case "Intersect":
|
|
3183
|
+
return FromIntersect9(schema_, references_, value);
|
|
3184
|
+
case "Iterator":
|
|
3185
|
+
return FromIterator4(schema_, references_, value);
|
|
3186
|
+
case "Literal":
|
|
3187
|
+
return FromLiteral3(schema_, references_, value);
|
|
3188
|
+
case "Never":
|
|
3189
|
+
return FromNever2(schema_, references_, value);
|
|
3190
|
+
case "Not":
|
|
3191
|
+
return FromNot2(schema_, references_, value);
|
|
3192
|
+
case "Null":
|
|
3193
|
+
return FromNull2(schema_, references_, value);
|
|
3194
|
+
case "Number":
|
|
3195
|
+
return FromNumber2(schema_, references_, value);
|
|
3196
|
+
case "Object":
|
|
3197
|
+
return FromObject8(schema_, references_, value);
|
|
3198
|
+
case "Promise":
|
|
3199
|
+
return FromPromise4(schema_, references_, value);
|
|
3200
|
+
case "Record":
|
|
3201
|
+
return FromRecord4(schema_, references_, value);
|
|
3202
|
+
case "Ref":
|
|
3203
|
+
return FromRef5(schema_, references_, value);
|
|
3204
|
+
case "RegExp":
|
|
3205
|
+
return FromRegExp2(schema_, references_, value);
|
|
3206
|
+
case "String":
|
|
3207
|
+
return FromString2(schema_, references_, value);
|
|
3208
|
+
case "Symbol":
|
|
3209
|
+
return FromSymbol2(schema_, references_, value);
|
|
3210
|
+
case "TemplateLiteral":
|
|
3211
|
+
return FromTemplateLiteral4(schema_, references_, value);
|
|
3212
|
+
case "This":
|
|
3213
|
+
return FromThis(schema_, references_, value);
|
|
3214
|
+
case "Tuple":
|
|
3215
|
+
return FromTuple6(schema_, references_, value);
|
|
3216
|
+
case "Undefined":
|
|
3217
|
+
return FromUndefined2(schema_, references_, value);
|
|
3218
|
+
case "Union":
|
|
3219
|
+
return FromUnion11(schema_, references_, value);
|
|
3220
|
+
case "Uint8Array":
|
|
3221
|
+
return FromUint8Array2(schema_, references_, value);
|
|
3222
|
+
case "Unknown":
|
|
3223
|
+
return FromUnknown2(schema_, references_, value);
|
|
3224
|
+
case "Void":
|
|
3225
|
+
return FromVoid2(schema_, references_, value);
|
|
3226
|
+
default:
|
|
3227
|
+
if (!type_exports2.Has(schema_[Kind]))
|
|
3228
|
+
throw new ValueCheckUnknownTypeError(schema_);
|
|
3229
|
+
return FromKind(schema_, references_, value);
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
function Check(...args) {
|
|
3233
|
+
return args.length === 3 ? Visit5(args[0], args[1], args[2]) : Visit5(args[0], [], args[1]);
|
|
3234
|
+
}
|
|
3235
|
+
var ValueErrorType;
|
|
3236
|
+
(function(ValueErrorType2) {
|
|
3237
|
+
ValueErrorType2[ValueErrorType2["ArrayContains"] = 0] = "ArrayContains";
|
|
3238
|
+
ValueErrorType2[ValueErrorType2["ArrayMaxContains"] = 1] = "ArrayMaxContains";
|
|
3239
|
+
ValueErrorType2[ValueErrorType2["ArrayMaxItems"] = 2] = "ArrayMaxItems";
|
|
3240
|
+
ValueErrorType2[ValueErrorType2["ArrayMinContains"] = 3] = "ArrayMinContains";
|
|
3241
|
+
ValueErrorType2[ValueErrorType2["ArrayMinItems"] = 4] = "ArrayMinItems";
|
|
3242
|
+
ValueErrorType2[ValueErrorType2["ArrayUniqueItems"] = 5] = "ArrayUniqueItems";
|
|
3243
|
+
ValueErrorType2[ValueErrorType2["Array"] = 6] = "Array";
|
|
3244
|
+
ValueErrorType2[ValueErrorType2["AsyncIterator"] = 7] = "AsyncIterator";
|
|
3245
|
+
ValueErrorType2[ValueErrorType2["BigIntExclusiveMaximum"] = 8] = "BigIntExclusiveMaximum";
|
|
3246
|
+
ValueErrorType2[ValueErrorType2["BigIntExclusiveMinimum"] = 9] = "BigIntExclusiveMinimum";
|
|
3247
|
+
ValueErrorType2[ValueErrorType2["BigIntMaximum"] = 10] = "BigIntMaximum";
|
|
3248
|
+
ValueErrorType2[ValueErrorType2["BigIntMinimum"] = 11] = "BigIntMinimum";
|
|
3249
|
+
ValueErrorType2[ValueErrorType2["BigIntMultipleOf"] = 12] = "BigIntMultipleOf";
|
|
3250
|
+
ValueErrorType2[ValueErrorType2["BigInt"] = 13] = "BigInt";
|
|
3251
|
+
ValueErrorType2[ValueErrorType2["Boolean"] = 14] = "Boolean";
|
|
3252
|
+
ValueErrorType2[ValueErrorType2["DateExclusiveMaximumTimestamp"] = 15] = "DateExclusiveMaximumTimestamp";
|
|
3253
|
+
ValueErrorType2[ValueErrorType2["DateExclusiveMinimumTimestamp"] = 16] = "DateExclusiveMinimumTimestamp";
|
|
3254
|
+
ValueErrorType2[ValueErrorType2["DateMaximumTimestamp"] = 17] = "DateMaximumTimestamp";
|
|
3255
|
+
ValueErrorType2[ValueErrorType2["DateMinimumTimestamp"] = 18] = "DateMinimumTimestamp";
|
|
3256
|
+
ValueErrorType2[ValueErrorType2["DateMultipleOfTimestamp"] = 19] = "DateMultipleOfTimestamp";
|
|
3257
|
+
ValueErrorType2[ValueErrorType2["Date"] = 20] = "Date";
|
|
3258
|
+
ValueErrorType2[ValueErrorType2["Function"] = 21] = "Function";
|
|
3259
|
+
ValueErrorType2[ValueErrorType2["IntegerExclusiveMaximum"] = 22] = "IntegerExclusiveMaximum";
|
|
3260
|
+
ValueErrorType2[ValueErrorType2["IntegerExclusiveMinimum"] = 23] = "IntegerExclusiveMinimum";
|
|
3261
|
+
ValueErrorType2[ValueErrorType2["IntegerMaximum"] = 24] = "IntegerMaximum";
|
|
3262
|
+
ValueErrorType2[ValueErrorType2["IntegerMinimum"] = 25] = "IntegerMinimum";
|
|
3263
|
+
ValueErrorType2[ValueErrorType2["IntegerMultipleOf"] = 26] = "IntegerMultipleOf";
|
|
3264
|
+
ValueErrorType2[ValueErrorType2["Integer"] = 27] = "Integer";
|
|
3265
|
+
ValueErrorType2[ValueErrorType2["IntersectUnevaluatedProperties"] = 28] = "IntersectUnevaluatedProperties";
|
|
3266
|
+
ValueErrorType2[ValueErrorType2["Intersect"] = 29] = "Intersect";
|
|
3267
|
+
ValueErrorType2[ValueErrorType2["Iterator"] = 30] = "Iterator";
|
|
3268
|
+
ValueErrorType2[ValueErrorType2["Kind"] = 31] = "Kind";
|
|
3269
|
+
ValueErrorType2[ValueErrorType2["Literal"] = 32] = "Literal";
|
|
3270
|
+
ValueErrorType2[ValueErrorType2["Never"] = 33] = "Never";
|
|
3271
|
+
ValueErrorType2[ValueErrorType2["Not"] = 34] = "Not";
|
|
3272
|
+
ValueErrorType2[ValueErrorType2["Null"] = 35] = "Null";
|
|
3273
|
+
ValueErrorType2[ValueErrorType2["NumberExclusiveMaximum"] = 36] = "NumberExclusiveMaximum";
|
|
3274
|
+
ValueErrorType2[ValueErrorType2["NumberExclusiveMinimum"] = 37] = "NumberExclusiveMinimum";
|
|
3275
|
+
ValueErrorType2[ValueErrorType2["NumberMaximum"] = 38] = "NumberMaximum";
|
|
3276
|
+
ValueErrorType2[ValueErrorType2["NumberMinimum"] = 39] = "NumberMinimum";
|
|
3277
|
+
ValueErrorType2[ValueErrorType2["NumberMultipleOf"] = 40] = "NumberMultipleOf";
|
|
3278
|
+
ValueErrorType2[ValueErrorType2["Number"] = 41] = "Number";
|
|
3279
|
+
ValueErrorType2[ValueErrorType2["ObjectAdditionalProperties"] = 42] = "ObjectAdditionalProperties";
|
|
3280
|
+
ValueErrorType2[ValueErrorType2["ObjectMaxProperties"] = 43] = "ObjectMaxProperties";
|
|
3281
|
+
ValueErrorType2[ValueErrorType2["ObjectMinProperties"] = 44] = "ObjectMinProperties";
|
|
3282
|
+
ValueErrorType2[ValueErrorType2["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty";
|
|
3283
|
+
ValueErrorType2[ValueErrorType2["Object"] = 46] = "Object";
|
|
3284
|
+
ValueErrorType2[ValueErrorType2["Promise"] = 47] = "Promise";
|
|
3285
|
+
ValueErrorType2[ValueErrorType2["RegExp"] = 48] = "RegExp";
|
|
3286
|
+
ValueErrorType2[ValueErrorType2["StringFormatUnknown"] = 49] = "StringFormatUnknown";
|
|
3287
|
+
ValueErrorType2[ValueErrorType2["StringFormat"] = 50] = "StringFormat";
|
|
3288
|
+
ValueErrorType2[ValueErrorType2["StringMaxLength"] = 51] = "StringMaxLength";
|
|
3289
|
+
ValueErrorType2[ValueErrorType2["StringMinLength"] = 52] = "StringMinLength";
|
|
3290
|
+
ValueErrorType2[ValueErrorType2["StringPattern"] = 53] = "StringPattern";
|
|
3291
|
+
ValueErrorType2[ValueErrorType2["String"] = 54] = "String";
|
|
3292
|
+
ValueErrorType2[ValueErrorType2["Symbol"] = 55] = "Symbol";
|
|
3293
|
+
ValueErrorType2[ValueErrorType2["TupleLength"] = 56] = "TupleLength";
|
|
3294
|
+
ValueErrorType2[ValueErrorType2["Tuple"] = 57] = "Tuple";
|
|
3295
|
+
ValueErrorType2[ValueErrorType2["Uint8ArrayMaxByteLength"] = 58] = "Uint8ArrayMaxByteLength";
|
|
3296
|
+
ValueErrorType2[ValueErrorType2["Uint8ArrayMinByteLength"] = 59] = "Uint8ArrayMinByteLength";
|
|
3297
|
+
ValueErrorType2[ValueErrorType2["Uint8Array"] = 60] = "Uint8Array";
|
|
3298
|
+
ValueErrorType2[ValueErrorType2["Undefined"] = 61] = "Undefined";
|
|
3299
|
+
ValueErrorType2[ValueErrorType2["Union"] = 62] = "Union";
|
|
3300
|
+
ValueErrorType2[ValueErrorType2["Void"] = 63] = "Void";
|
|
3301
|
+
})(ValueErrorType || (ValueErrorType = {}));
|
|
3302
|
+
var ValueErrorsUnknownTypeError = class extends TypeBoxError {
|
|
3303
|
+
constructor(schema) {
|
|
3304
|
+
super("Unknown type");
|
|
3305
|
+
this.schema = schema;
|
|
3306
|
+
}
|
|
3307
|
+
};
|
|
3308
|
+
function EscapeKey(key) {
|
|
3309
|
+
return key.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
3310
|
+
}
|
|
3311
|
+
function IsDefined2(value) {
|
|
3312
|
+
return value !== void 0;
|
|
3313
|
+
}
|
|
3314
|
+
var ValueErrorIterator = class {
|
|
3315
|
+
constructor(iterator) {
|
|
3316
|
+
this.iterator = iterator;
|
|
3317
|
+
}
|
|
3318
|
+
[Symbol.iterator]() {
|
|
3319
|
+
return this.iterator;
|
|
3320
|
+
}
|
|
3321
|
+
/** Returns the first value error or undefined if no errors */
|
|
3322
|
+
First() {
|
|
3323
|
+
const next = this.iterator.next();
|
|
3324
|
+
return next.done ? void 0 : next.value;
|
|
3325
|
+
}
|
|
3326
|
+
};
|
|
3327
|
+
function Create(errorType, schema, path, value, errors = []) {
|
|
3328
|
+
return {
|
|
3329
|
+
type: errorType,
|
|
3330
|
+
schema,
|
|
3331
|
+
path,
|
|
3332
|
+
value,
|
|
3333
|
+
message: GetErrorFunction()({ errorType, path, schema, value, errors }),
|
|
3334
|
+
errors
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
function* FromAny3(schema, references, path, value) {
|
|
3338
|
+
}
|
|
3339
|
+
function* FromArgument3(schema, references, path, value) {
|
|
3340
|
+
}
|
|
3341
|
+
function* FromArray8(schema, references, path, value) {
|
|
3342
|
+
if (!IsArray2(value)) {
|
|
3343
|
+
return yield Create(ValueErrorType.Array, schema, path, value);
|
|
3344
|
+
}
|
|
3345
|
+
if (IsDefined2(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
3346
|
+
yield Create(ValueErrorType.ArrayMinItems, schema, path, value);
|
|
3347
|
+
}
|
|
3348
|
+
if (IsDefined2(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
3349
|
+
yield Create(ValueErrorType.ArrayMaxItems, schema, path, value);
|
|
3350
|
+
}
|
|
3351
|
+
for (let i = 0; i < value.length; i++) {
|
|
3352
|
+
yield* Visit6(schema.items, references, `${path}/${i}`, value[i]);
|
|
3353
|
+
}
|
|
3354
|
+
if (schema.uniqueItems === true && !(function() {
|
|
3355
|
+
const set = /* @__PURE__ */ new Set();
|
|
3356
|
+
for (const element of value) {
|
|
3357
|
+
const hashed = Hash(element);
|
|
3358
|
+
if (set.has(hashed)) {
|
|
3359
|
+
return false;
|
|
3360
|
+
} else {
|
|
3361
|
+
set.add(hashed);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
return true;
|
|
3365
|
+
})()) {
|
|
3366
|
+
yield Create(ValueErrorType.ArrayUniqueItems, schema, path, value);
|
|
3367
|
+
}
|
|
3368
|
+
if (!(IsDefined2(schema.contains) || IsDefined2(schema.minContains) || IsDefined2(schema.maxContains))) {
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
const containsSchema = IsDefined2(schema.contains) ? schema.contains : Never();
|
|
3372
|
+
const containsCount = value.reduce((acc, value2, index) => Visit6(containsSchema, references, `${path}${index}`, value2).next().done === true ? acc + 1 : acc, 0);
|
|
3373
|
+
if (containsCount === 0) {
|
|
3374
|
+
yield Create(ValueErrorType.ArrayContains, schema, path, value);
|
|
3375
|
+
}
|
|
3376
|
+
if (IsNumber2(schema.minContains) && containsCount < schema.minContains) {
|
|
3377
|
+
yield Create(ValueErrorType.ArrayMinContains, schema, path, value);
|
|
3378
|
+
}
|
|
3379
|
+
if (IsNumber2(schema.maxContains) && containsCount > schema.maxContains) {
|
|
3380
|
+
yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
function* FromAsyncIterator5(schema, references, path, value) {
|
|
3384
|
+
if (!IsAsyncIterator2(value))
|
|
3385
|
+
yield Create(ValueErrorType.AsyncIterator, schema, path, value);
|
|
3386
|
+
}
|
|
3387
|
+
function* FromBigInt3(schema, references, path, value) {
|
|
3388
|
+
if (!IsBigInt2(value))
|
|
3389
|
+
return yield Create(ValueErrorType.BigInt, schema, path, value);
|
|
3390
|
+
if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
3391
|
+
yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value);
|
|
3392
|
+
}
|
|
3393
|
+
if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
3394
|
+
yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path, value);
|
|
3395
|
+
}
|
|
3396
|
+
if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
|
|
3397
|
+
yield Create(ValueErrorType.BigIntMaximum, schema, path, value);
|
|
3398
|
+
}
|
|
3399
|
+
if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
|
|
3400
|
+
yield Create(ValueErrorType.BigIntMinimum, schema, path, value);
|
|
3401
|
+
}
|
|
3402
|
+
if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
|
|
3403
|
+
yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value);
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
function* FromBoolean3(schema, references, path, value) {
|
|
3407
|
+
if (!IsBoolean2(value))
|
|
3408
|
+
yield Create(ValueErrorType.Boolean, schema, path, value);
|
|
3409
|
+
}
|
|
3410
|
+
function* FromConstructor5(schema, references, path, value) {
|
|
3411
|
+
yield* Visit6(schema.returns, references, path, value.prototype);
|
|
3412
|
+
}
|
|
3413
|
+
function* FromDate3(schema, references, path, value) {
|
|
3414
|
+
if (!IsDate2(value))
|
|
3415
|
+
return yield Create(ValueErrorType.Date, schema, path, value);
|
|
3416
|
+
if (IsDefined2(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
3417
|
+
yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value);
|
|
3418
|
+
}
|
|
3419
|
+
if (IsDefined2(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
3420
|
+
yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value);
|
|
3421
|
+
}
|
|
3422
|
+
if (IsDefined2(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
3423
|
+
yield Create(ValueErrorType.DateMaximumTimestamp, schema, path, value);
|
|
3424
|
+
}
|
|
3425
|
+
if (IsDefined2(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
3426
|
+
yield Create(ValueErrorType.DateMinimumTimestamp, schema, path, value);
|
|
3427
|
+
}
|
|
3428
|
+
if (IsDefined2(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
|
|
3429
|
+
yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value);
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
function* FromFunction5(schema, references, path, value) {
|
|
3433
|
+
if (!IsFunction2(value))
|
|
3434
|
+
yield Create(ValueErrorType.Function, schema, path, value);
|
|
3435
|
+
}
|
|
3436
|
+
function* FromImport2(schema, references, path, value) {
|
|
3437
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
3438
|
+
const target = schema.$defs[schema.$ref];
|
|
3439
|
+
yield* Visit6(target, [...references, ...definitions], path, value);
|
|
3440
|
+
}
|
|
3441
|
+
function* FromInteger3(schema, references, path, value) {
|
|
3442
|
+
if (!IsInteger(value))
|
|
3443
|
+
return yield Create(ValueErrorType.Integer, schema, path, value);
|
|
3444
|
+
if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
3445
|
+
yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value);
|
|
3446
|
+
}
|
|
3447
|
+
if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
3448
|
+
yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path, value);
|
|
3449
|
+
}
|
|
3450
|
+
if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
|
|
3451
|
+
yield Create(ValueErrorType.IntegerMaximum, schema, path, value);
|
|
3452
|
+
}
|
|
3453
|
+
if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
|
|
3454
|
+
yield Create(ValueErrorType.IntegerMinimum, schema, path, value);
|
|
3455
|
+
}
|
|
3456
|
+
if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
3457
|
+
yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value);
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
function* FromIntersect10(schema, references, path, value) {
|
|
3461
|
+
let hasError = false;
|
|
3462
|
+
for (const inner of schema.allOf) {
|
|
3463
|
+
for (const error2 of Visit6(inner, references, path, value)) {
|
|
3464
|
+
hasError = true;
|
|
3465
|
+
yield error2;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
if (hasError) {
|
|
3469
|
+
return yield Create(ValueErrorType.Intersect, schema, path, value);
|
|
3470
|
+
}
|
|
3471
|
+
if (schema.unevaluatedProperties === false) {
|
|
3472
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
3473
|
+
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
3474
|
+
if (!keyCheck.test(valueKey)) {
|
|
3475
|
+
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
if (typeof schema.unevaluatedProperties === "object") {
|
|
3480
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
3481
|
+
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
3482
|
+
if (!keyCheck.test(valueKey)) {
|
|
3483
|
+
const next = Visit6(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
|
3484
|
+
if (!next.done)
|
|
3485
|
+
yield next.value;
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
function* FromIterator5(schema, references, path, value) {
|
|
3491
|
+
if (!IsIterator2(value))
|
|
3492
|
+
yield Create(ValueErrorType.Iterator, schema, path, value);
|
|
3493
|
+
}
|
|
3494
|
+
function* FromLiteral4(schema, references, path, value) {
|
|
3495
|
+
if (!(value === schema.const))
|
|
3496
|
+
yield Create(ValueErrorType.Literal, schema, path, value);
|
|
3497
|
+
}
|
|
3498
|
+
function* FromNever3(schema, references, path, value) {
|
|
3499
|
+
yield Create(ValueErrorType.Never, schema, path, value);
|
|
3500
|
+
}
|
|
3501
|
+
function* FromNot3(schema, references, path, value) {
|
|
3502
|
+
if (Visit6(schema.not, references, path, value).next().done === true)
|
|
3503
|
+
yield Create(ValueErrorType.Not, schema, path, value);
|
|
3504
|
+
}
|
|
3505
|
+
function* FromNull3(schema, references, path, value) {
|
|
3506
|
+
if (!IsNull2(value))
|
|
3507
|
+
yield Create(ValueErrorType.Null, schema, path, value);
|
|
3508
|
+
}
|
|
3509
|
+
function* FromNumber3(schema, references, path, value) {
|
|
3510
|
+
if (!TypeSystemPolicy.IsNumberLike(value))
|
|
3511
|
+
return yield Create(ValueErrorType.Number, schema, path, value);
|
|
3512
|
+
if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
3513
|
+
yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path, value);
|
|
3514
|
+
}
|
|
3515
|
+
if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
3516
|
+
yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path, value);
|
|
3517
|
+
}
|
|
3518
|
+
if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
|
|
3519
|
+
yield Create(ValueErrorType.NumberMaximum, schema, path, value);
|
|
3520
|
+
}
|
|
3521
|
+
if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
|
|
3522
|
+
yield Create(ValueErrorType.NumberMinimum, schema, path, value);
|
|
3523
|
+
}
|
|
3524
|
+
if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
3525
|
+
yield Create(ValueErrorType.NumberMultipleOf, schema, path, value);
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
function* FromObject9(schema, references, path, value) {
|
|
3529
|
+
if (!TypeSystemPolicy.IsObjectLike(value))
|
|
3530
|
+
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
3531
|
+
if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
3532
|
+
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
3533
|
+
}
|
|
3534
|
+
if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
3535
|
+
yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
|
|
3536
|
+
}
|
|
3537
|
+
const requiredKeys = Array.isArray(schema.required) ? schema.required : [];
|
|
3538
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
3539
|
+
const unknownKeys = Object.getOwnPropertyNames(value);
|
|
3540
|
+
for (const requiredKey of requiredKeys) {
|
|
3541
|
+
if (unknownKeys.includes(requiredKey))
|
|
3542
|
+
continue;
|
|
3543
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${EscapeKey(requiredKey)}`, void 0);
|
|
3544
|
+
}
|
|
3545
|
+
if (schema.additionalProperties === false) {
|
|
3546
|
+
for (const valueKey of unknownKeys) {
|
|
3547
|
+
if (!knownKeys.includes(valueKey)) {
|
|
3548
|
+
yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
if (typeof schema.additionalProperties === "object") {
|
|
3553
|
+
for (const valueKey of unknownKeys) {
|
|
3554
|
+
if (knownKeys.includes(valueKey))
|
|
3555
|
+
continue;
|
|
3556
|
+
yield* Visit6(schema.additionalProperties, references, `${path}/${EscapeKey(valueKey)}`, value[valueKey]);
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
for (const knownKey of knownKeys) {
|
|
3560
|
+
const property = schema.properties[knownKey];
|
|
3561
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
3562
|
+
yield* Visit6(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
3563
|
+
if (ExtendsUndefinedCheck(schema) && !(knownKey in value)) {
|
|
3564
|
+
yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${EscapeKey(knownKey)}`, void 0);
|
|
3565
|
+
}
|
|
3566
|
+
} else {
|
|
3567
|
+
if (TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
|
|
3568
|
+
yield* Visit6(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
function* FromPromise5(schema, references, path, value) {
|
|
3574
|
+
if (!IsPromise(value))
|
|
3575
|
+
yield Create(ValueErrorType.Promise, schema, path, value);
|
|
3576
|
+
}
|
|
3577
|
+
function* FromRecord5(schema, references, path, value) {
|
|
3578
|
+
if (!TypeSystemPolicy.IsRecordLike(value))
|
|
3579
|
+
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
3580
|
+
if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
3581
|
+
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
3582
|
+
}
|
|
3583
|
+
if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
3584
|
+
yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
|
|
3585
|
+
}
|
|
3586
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
3587
|
+
const regex = new RegExp(patternKey);
|
|
3588
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
3589
|
+
if (regex.test(propertyKey))
|
|
3590
|
+
yield* Visit6(patternSchema, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
3591
|
+
}
|
|
3592
|
+
if (typeof schema.additionalProperties === "object") {
|
|
3593
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
3594
|
+
if (!regex.test(propertyKey))
|
|
3595
|
+
yield* Visit6(schema.additionalProperties, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
if (schema.additionalProperties === false) {
|
|
3599
|
+
for (const [propertyKey, propertyValue] of Object.entries(value)) {
|
|
3600
|
+
if (regex.test(propertyKey))
|
|
3601
|
+
continue;
|
|
3602
|
+
return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(propertyKey)}`, propertyValue);
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
function* FromRef6(schema, references, path, value) {
|
|
3607
|
+
yield* Visit6(Deref(schema, references), references, path, value);
|
|
3608
|
+
}
|
|
3609
|
+
function* FromRegExp3(schema, references, path, value) {
|
|
3610
|
+
if (!IsString2(value))
|
|
3611
|
+
return yield Create(ValueErrorType.String, schema, path, value);
|
|
3612
|
+
if (IsDefined2(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
3613
|
+
yield Create(ValueErrorType.StringMinLength, schema, path, value);
|
|
3614
|
+
}
|
|
3615
|
+
if (IsDefined2(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
3616
|
+
yield Create(ValueErrorType.StringMaxLength, schema, path, value);
|
|
3617
|
+
}
|
|
3618
|
+
const regex = new RegExp(schema.source, schema.flags);
|
|
3619
|
+
if (!regex.test(value)) {
|
|
3620
|
+
return yield Create(ValueErrorType.RegExp, schema, path, value);
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
function* FromString3(schema, references, path, value) {
|
|
3624
|
+
if (!IsString2(value))
|
|
3625
|
+
return yield Create(ValueErrorType.String, schema, path, value);
|
|
3626
|
+
if (IsDefined2(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
3627
|
+
yield Create(ValueErrorType.StringMinLength, schema, path, value);
|
|
3628
|
+
}
|
|
3629
|
+
if (IsDefined2(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
3630
|
+
yield Create(ValueErrorType.StringMaxLength, schema, path, value);
|
|
3631
|
+
}
|
|
3632
|
+
if (IsString2(schema.pattern)) {
|
|
3633
|
+
const regex = new RegExp(schema.pattern);
|
|
3634
|
+
if (!regex.test(value)) {
|
|
3635
|
+
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
if (IsString2(schema.format)) {
|
|
3639
|
+
if (!format_exports.Has(schema.format)) {
|
|
3640
|
+
yield Create(ValueErrorType.StringFormatUnknown, schema, path, value);
|
|
3641
|
+
} else {
|
|
3642
|
+
const format = format_exports.Get(schema.format);
|
|
3643
|
+
if (!format(value)) {
|
|
3644
|
+
yield Create(ValueErrorType.StringFormat, schema, path, value);
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
function* FromSymbol3(schema, references, path, value) {
|
|
3650
|
+
if (!IsSymbol2(value))
|
|
3651
|
+
yield Create(ValueErrorType.Symbol, schema, path, value);
|
|
3652
|
+
}
|
|
3653
|
+
function* FromTemplateLiteral5(schema, references, path, value) {
|
|
3654
|
+
if (!IsString2(value))
|
|
3655
|
+
return yield Create(ValueErrorType.String, schema, path, value);
|
|
3656
|
+
const regex = new RegExp(schema.pattern);
|
|
3657
|
+
if (!regex.test(value)) {
|
|
3658
|
+
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
function* FromThis2(schema, references, path, value) {
|
|
3662
|
+
yield* Visit6(Deref(schema, references), references, path, value);
|
|
3663
|
+
}
|
|
3664
|
+
function* FromTuple7(schema, references, path, value) {
|
|
3665
|
+
if (!IsArray2(value))
|
|
3666
|
+
return yield Create(ValueErrorType.Tuple, schema, path, value);
|
|
3667
|
+
if (schema.items === void 0 && !(value.length === 0)) {
|
|
3668
|
+
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
3669
|
+
}
|
|
3670
|
+
if (!(value.length === schema.maxItems)) {
|
|
3671
|
+
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
3672
|
+
}
|
|
3673
|
+
if (!schema.items) {
|
|
3674
|
+
return;
|
|
3675
|
+
}
|
|
3676
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
3677
|
+
yield* Visit6(schema.items[i], references, `${path}/${i}`, value[i]);
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
function* FromUndefined3(schema, references, path, value) {
|
|
3681
|
+
if (!IsUndefined2(value))
|
|
3682
|
+
yield Create(ValueErrorType.Undefined, schema, path, value);
|
|
3683
|
+
}
|
|
3684
|
+
function* FromUnion12(schema, references, path, value) {
|
|
3685
|
+
if (Check(schema, references, value))
|
|
3686
|
+
return;
|
|
3687
|
+
const errors = schema.anyOf.map((variant) => new ValueErrorIterator(Visit6(variant, references, path, value)));
|
|
3688
|
+
yield Create(ValueErrorType.Union, schema, path, value, errors);
|
|
3689
|
+
}
|
|
3690
|
+
function* FromUint8Array3(schema, references, path, value) {
|
|
3691
|
+
if (!IsUint8Array2(value))
|
|
3692
|
+
return yield Create(ValueErrorType.Uint8Array, schema, path, value);
|
|
3693
|
+
if (IsDefined2(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
3694
|
+
yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value);
|
|
3695
|
+
}
|
|
3696
|
+
if (IsDefined2(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
3697
|
+
yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
function* FromUnknown3(schema, references, path, value) {
|
|
3701
|
+
}
|
|
3702
|
+
function* FromVoid3(schema, references, path, value) {
|
|
3703
|
+
if (!TypeSystemPolicy.IsVoidLike(value))
|
|
3704
|
+
yield Create(ValueErrorType.Void, schema, path, value);
|
|
3705
|
+
}
|
|
3706
|
+
function* FromKind2(schema, references, path, value) {
|
|
3707
|
+
const check = type_exports2.Get(schema[Kind]);
|
|
3708
|
+
if (!check(schema, value))
|
|
3709
|
+
yield Create(ValueErrorType.Kind, schema, path, value);
|
|
3710
|
+
}
|
|
3711
|
+
function* Visit6(schema, references, path, value) {
|
|
3712
|
+
const references_ = IsDefined2(schema.$id) ? [...references, schema] : references;
|
|
3713
|
+
const schema_ = schema;
|
|
3714
|
+
switch (schema_[Kind]) {
|
|
3715
|
+
case "Any":
|
|
3716
|
+
return yield* FromAny3(schema_, references_, path, value);
|
|
3717
|
+
case "Argument":
|
|
3718
|
+
return yield* FromArgument3(schema_, references_, path, value);
|
|
3719
|
+
case "Array":
|
|
3720
|
+
return yield* FromArray8(schema_, references_, path, value);
|
|
3721
|
+
case "AsyncIterator":
|
|
3722
|
+
return yield* FromAsyncIterator5(schema_, references_, path, value);
|
|
3723
|
+
case "BigInt":
|
|
3724
|
+
return yield* FromBigInt3(schema_, references_, path, value);
|
|
3725
|
+
case "Boolean":
|
|
3726
|
+
return yield* FromBoolean3(schema_, references_, path, value);
|
|
3727
|
+
case "Constructor":
|
|
3728
|
+
return yield* FromConstructor5(schema_, references_, path, value);
|
|
3729
|
+
case "Date":
|
|
3730
|
+
return yield* FromDate3(schema_, references_, path, value);
|
|
3731
|
+
case "Function":
|
|
3732
|
+
return yield* FromFunction5(schema_, references_, path, value);
|
|
3733
|
+
case "Import":
|
|
3734
|
+
return yield* FromImport2(schema_, references_, path, value);
|
|
3735
|
+
case "Integer":
|
|
3736
|
+
return yield* FromInteger3(schema_, references_, path, value);
|
|
3737
|
+
case "Intersect":
|
|
3738
|
+
return yield* FromIntersect10(schema_, references_, path, value);
|
|
3739
|
+
case "Iterator":
|
|
3740
|
+
return yield* FromIterator5(schema_, references_, path, value);
|
|
3741
|
+
case "Literal":
|
|
3742
|
+
return yield* FromLiteral4(schema_, references_, path, value);
|
|
3743
|
+
case "Never":
|
|
3744
|
+
return yield* FromNever3(schema_, references_, path, value);
|
|
3745
|
+
case "Not":
|
|
3746
|
+
return yield* FromNot3(schema_, references_, path, value);
|
|
3747
|
+
case "Null":
|
|
3748
|
+
return yield* FromNull3(schema_, references_, path, value);
|
|
3749
|
+
case "Number":
|
|
3750
|
+
return yield* FromNumber3(schema_, references_, path, value);
|
|
3751
|
+
case "Object":
|
|
3752
|
+
return yield* FromObject9(schema_, references_, path, value);
|
|
3753
|
+
case "Promise":
|
|
3754
|
+
return yield* FromPromise5(schema_, references_, path, value);
|
|
3755
|
+
case "Record":
|
|
3756
|
+
return yield* FromRecord5(schema_, references_, path, value);
|
|
3757
|
+
case "Ref":
|
|
3758
|
+
return yield* FromRef6(schema_, references_, path, value);
|
|
3759
|
+
case "RegExp":
|
|
3760
|
+
return yield* FromRegExp3(schema_, references_, path, value);
|
|
3761
|
+
case "String":
|
|
3762
|
+
return yield* FromString3(schema_, references_, path, value);
|
|
3763
|
+
case "Symbol":
|
|
3764
|
+
return yield* FromSymbol3(schema_, references_, path, value);
|
|
3765
|
+
case "TemplateLiteral":
|
|
3766
|
+
return yield* FromTemplateLiteral5(schema_, references_, path, value);
|
|
3767
|
+
case "This":
|
|
3768
|
+
return yield* FromThis2(schema_, references_, path, value);
|
|
3769
|
+
case "Tuple":
|
|
3770
|
+
return yield* FromTuple7(schema_, references_, path, value);
|
|
3771
|
+
case "Undefined":
|
|
3772
|
+
return yield* FromUndefined3(schema_, references_, path, value);
|
|
3773
|
+
case "Union":
|
|
3774
|
+
return yield* FromUnion12(schema_, references_, path, value);
|
|
3775
|
+
case "Uint8Array":
|
|
3776
|
+
return yield* FromUint8Array3(schema_, references_, path, value);
|
|
3777
|
+
case "Unknown":
|
|
3778
|
+
return yield* FromUnknown3(schema_, references_, path, value);
|
|
3779
|
+
case "Void":
|
|
3780
|
+
return yield* FromVoid3(schema_, references_, path, value);
|
|
3781
|
+
default:
|
|
3782
|
+
if (!type_exports2.Has(schema_[Kind]))
|
|
3783
|
+
throw new ValueErrorsUnknownTypeError(schema);
|
|
3784
|
+
return yield* FromKind2(schema_, references_, path, value);
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
function Errors(...args) {
|
|
3788
|
+
const iterator = args.length === 3 ? Visit6(args[0], args[1], "", args[2]) : Visit6(args[0], [], "", args[1]);
|
|
3789
|
+
return new ValueErrorIterator(iterator);
|
|
3790
|
+
}
|
|
3791
|
+
var TransformDecodeCheckError = class extends TypeBoxError {
|
|
3792
|
+
constructor(schema, value, error2) {
|
|
3793
|
+
super(`Unable to decode value as it does not match the expected schema`);
|
|
3794
|
+
this.schema = schema;
|
|
3795
|
+
this.value = value;
|
|
3796
|
+
this.error = error2;
|
|
3797
|
+
}
|
|
3798
|
+
};
|
|
3799
|
+
var TransformDecodeError = class extends TypeBoxError {
|
|
3800
|
+
constructor(schema, path, value, error2) {
|
|
3801
|
+
super(error2 instanceof Error ? error2.message : "Unknown error");
|
|
3802
|
+
this.schema = schema;
|
|
3803
|
+
this.path = path;
|
|
3804
|
+
this.value = value;
|
|
3805
|
+
this.error = error2;
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
function Default(schema, path, value) {
|
|
3809
|
+
try {
|
|
3810
|
+
return IsTransform(schema) ? schema[TransformKind].Decode(value) : value;
|
|
3811
|
+
} catch (error2) {
|
|
3812
|
+
throw new TransformDecodeError(schema, path, value, error2);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
function FromArray9(schema, references, path, value) {
|
|
3816
|
+
return IsArray2(value) ? Default(schema, path, value.map((value2, index) => Visit7(schema.items, references, `${path}/${index}`, value2))) : Default(schema, path, value);
|
|
3817
|
+
}
|
|
3818
|
+
function FromIntersect11(schema, references, path, value) {
|
|
3819
|
+
if (!IsObject2(value) || IsValueType(value))
|
|
3820
|
+
return Default(schema, path, value);
|
|
3821
|
+
const knownEntries = KeyOfPropertyEntries(schema);
|
|
3822
|
+
const knownKeys = knownEntries.map((entry) => entry[0]);
|
|
3823
|
+
const knownProperties = { ...value };
|
|
3824
|
+
for (const [knownKey, knownSchema] of knownEntries)
|
|
3825
|
+
if (knownKey in knownProperties) {
|
|
3826
|
+
knownProperties[knownKey] = Visit7(knownSchema, references, `${path}/${knownKey}`, knownProperties[knownKey]);
|
|
3827
|
+
}
|
|
3828
|
+
if (!IsTransform(schema.unevaluatedProperties)) {
|
|
3829
|
+
return Default(schema, path, knownProperties);
|
|
3830
|
+
}
|
|
3831
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3832
|
+
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
3833
|
+
const unknownProperties = { ...knownProperties };
|
|
3834
|
+
for (const key of unknownKeys)
|
|
3835
|
+
if (!knownKeys.includes(key)) {
|
|
3836
|
+
unknownProperties[key] = Default(unevaluatedProperties, `${path}/${key}`, unknownProperties[key]);
|
|
3837
|
+
}
|
|
3838
|
+
return Default(schema, path, unknownProperties);
|
|
3839
|
+
}
|
|
3840
|
+
function FromImport3(schema, references, path, value) {
|
|
3841
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
3842
|
+
const target = schema.$defs[schema.$ref];
|
|
3843
|
+
const result = Visit7(target, [...references, ...additional], path, value);
|
|
3844
|
+
return Default(schema, path, result);
|
|
3845
|
+
}
|
|
3846
|
+
function FromNot4(schema, references, path, value) {
|
|
3847
|
+
return Default(schema, path, Visit7(schema.not, references, path, value));
|
|
3848
|
+
}
|
|
3849
|
+
function FromObject10(schema, references, path, value) {
|
|
3850
|
+
if (!IsObject2(value))
|
|
3851
|
+
return Default(schema, path, value);
|
|
3852
|
+
const knownKeys = KeyOfPropertyKeys(schema);
|
|
3853
|
+
const knownProperties = { ...value };
|
|
3854
|
+
for (const key of knownKeys) {
|
|
3855
|
+
if (!HasPropertyKey2(knownProperties, key))
|
|
3856
|
+
continue;
|
|
3857
|
+
if (IsUndefined2(knownProperties[key]) && (!IsUndefined3(schema.properties[key]) || TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
|
|
3858
|
+
continue;
|
|
3859
|
+
knownProperties[key] = Visit7(schema.properties[key], references, `${path}/${key}`, knownProperties[key]);
|
|
3860
|
+
}
|
|
3861
|
+
if (!IsSchema(schema.additionalProperties)) {
|
|
3862
|
+
return Default(schema, path, knownProperties);
|
|
3863
|
+
}
|
|
3864
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3865
|
+
const additionalProperties = schema.additionalProperties;
|
|
3866
|
+
const unknownProperties = { ...knownProperties };
|
|
3867
|
+
for (const key of unknownKeys)
|
|
3868
|
+
if (!knownKeys.includes(key)) {
|
|
3869
|
+
unknownProperties[key] = Default(additionalProperties, `${path}/${key}`, unknownProperties[key]);
|
|
3870
|
+
}
|
|
3871
|
+
return Default(schema, path, unknownProperties);
|
|
3872
|
+
}
|
|
3873
|
+
function FromRecord6(schema, references, path, value) {
|
|
3874
|
+
if (!IsObject2(value))
|
|
3875
|
+
return Default(schema, path, value);
|
|
3876
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
3877
|
+
const knownKeys = new RegExp(pattern);
|
|
3878
|
+
const knownProperties = { ...value };
|
|
3879
|
+
for (const key of Object.getOwnPropertyNames(value))
|
|
3880
|
+
if (knownKeys.test(key)) {
|
|
3881
|
+
knownProperties[key] = Visit7(schema.patternProperties[pattern], references, `${path}/${key}`, knownProperties[key]);
|
|
3882
|
+
}
|
|
3883
|
+
if (!IsSchema(schema.additionalProperties)) {
|
|
3884
|
+
return Default(schema, path, knownProperties);
|
|
3885
|
+
}
|
|
3886
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3887
|
+
const additionalProperties = schema.additionalProperties;
|
|
3888
|
+
const unknownProperties = { ...knownProperties };
|
|
3889
|
+
for (const key of unknownKeys)
|
|
3890
|
+
if (!knownKeys.test(key)) {
|
|
3891
|
+
unknownProperties[key] = Default(additionalProperties, `${path}/${key}`, unknownProperties[key]);
|
|
3892
|
+
}
|
|
3893
|
+
return Default(schema, path, unknownProperties);
|
|
3894
|
+
}
|
|
3895
|
+
function FromRef7(schema, references, path, value) {
|
|
3896
|
+
const target = Deref(schema, references);
|
|
3897
|
+
return Default(schema, path, Visit7(target, references, path, value));
|
|
3898
|
+
}
|
|
3899
|
+
function FromThis3(schema, references, path, value) {
|
|
3900
|
+
const target = Deref(schema, references);
|
|
3901
|
+
return Default(schema, path, Visit7(target, references, path, value));
|
|
3902
|
+
}
|
|
3903
|
+
function FromTuple8(schema, references, path, value) {
|
|
3904
|
+
return IsArray2(value) && IsArray2(schema.items) ? Default(schema, path, schema.items.map((schema2, index) => Visit7(schema2, references, `${path}/${index}`, value[index]))) : Default(schema, path, value);
|
|
3905
|
+
}
|
|
3906
|
+
function FromUnion13(schema, references, path, value) {
|
|
3907
|
+
for (const subschema of schema.anyOf) {
|
|
3908
|
+
if (!Check(subschema, references, value))
|
|
3909
|
+
continue;
|
|
3910
|
+
const decoded = Visit7(subschema, references, path, value);
|
|
3911
|
+
return Default(schema, path, decoded);
|
|
3912
|
+
}
|
|
3913
|
+
return Default(schema, path, value);
|
|
3914
|
+
}
|
|
3915
|
+
function Visit7(schema, references, path, value) {
|
|
3916
|
+
const references_ = Pushref(schema, references);
|
|
3917
|
+
const schema_ = schema;
|
|
3918
|
+
switch (schema[Kind]) {
|
|
3919
|
+
case "Array":
|
|
3920
|
+
return FromArray9(schema_, references_, path, value);
|
|
3921
|
+
case "Import":
|
|
3922
|
+
return FromImport3(schema_, references_, path, value);
|
|
3923
|
+
case "Intersect":
|
|
3924
|
+
return FromIntersect11(schema_, references_, path, value);
|
|
3925
|
+
case "Not":
|
|
3926
|
+
return FromNot4(schema_, references_, path, value);
|
|
3927
|
+
case "Object":
|
|
3928
|
+
return FromObject10(schema_, references_, path, value);
|
|
3929
|
+
case "Record":
|
|
3930
|
+
return FromRecord6(schema_, references_, path, value);
|
|
3931
|
+
case "Ref":
|
|
3932
|
+
return FromRef7(schema_, references_, path, value);
|
|
3933
|
+
case "Symbol":
|
|
3934
|
+
return Default(schema_, path, value);
|
|
3935
|
+
case "This":
|
|
3936
|
+
return FromThis3(schema_, references_, path, value);
|
|
3937
|
+
case "Tuple":
|
|
3938
|
+
return FromTuple8(schema_, references_, path, value);
|
|
3939
|
+
case "Union":
|
|
3940
|
+
return FromUnion13(schema_, references_, path, value);
|
|
3941
|
+
default:
|
|
3942
|
+
return Default(schema_, path, value);
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
function TransformDecode(schema, references, value) {
|
|
3946
|
+
return Visit7(schema, references, "", value);
|
|
3947
|
+
}
|
|
3948
|
+
var TransformEncodeCheckError = class extends TypeBoxError {
|
|
3949
|
+
constructor(schema, value, error2) {
|
|
3950
|
+
super(`The encoded value does not match the expected schema`);
|
|
3951
|
+
this.schema = schema;
|
|
3952
|
+
this.value = value;
|
|
3953
|
+
this.error = error2;
|
|
3954
|
+
}
|
|
3955
|
+
};
|
|
3956
|
+
var TransformEncodeError = class extends TypeBoxError {
|
|
3957
|
+
constructor(schema, path, value, error2) {
|
|
3958
|
+
super(`${error2 instanceof Error ? error2.message : "Unknown error"}`);
|
|
3959
|
+
this.schema = schema;
|
|
3960
|
+
this.path = path;
|
|
3961
|
+
this.value = value;
|
|
3962
|
+
this.error = error2;
|
|
3963
|
+
}
|
|
3964
|
+
};
|
|
3965
|
+
function Default2(schema, path, value) {
|
|
3966
|
+
try {
|
|
3967
|
+
return IsTransform(schema) ? schema[TransformKind].Encode(value) : value;
|
|
3968
|
+
} catch (error2) {
|
|
3969
|
+
throw new TransformEncodeError(schema, path, value, error2);
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
function FromArray10(schema, references, path, value) {
|
|
3973
|
+
const defaulted = Default2(schema, path, value);
|
|
3974
|
+
return IsArray2(defaulted) ? defaulted.map((value2, index) => Visit8(schema.items, references, `${path}/${index}`, value2)) : defaulted;
|
|
3975
|
+
}
|
|
3976
|
+
function FromImport4(schema, references, path, value) {
|
|
3977
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
3978
|
+
const target = schema.$defs[schema.$ref];
|
|
3979
|
+
const result = Default2(schema, path, value);
|
|
3980
|
+
return Visit8(target, [...references, ...additional], path, result);
|
|
3981
|
+
}
|
|
3982
|
+
function FromIntersect12(schema, references, path, value) {
|
|
3983
|
+
const defaulted = Default2(schema, path, value);
|
|
3984
|
+
if (!IsObject2(value) || IsValueType(value))
|
|
3985
|
+
return defaulted;
|
|
3986
|
+
const knownEntries = KeyOfPropertyEntries(schema);
|
|
3987
|
+
const knownKeys = knownEntries.map((entry) => entry[0]);
|
|
3988
|
+
const knownProperties = { ...defaulted };
|
|
3989
|
+
for (const [knownKey, knownSchema] of knownEntries)
|
|
3990
|
+
if (knownKey in knownProperties) {
|
|
3991
|
+
knownProperties[knownKey] = Visit8(knownSchema, references, `${path}/${knownKey}`, knownProperties[knownKey]);
|
|
3992
|
+
}
|
|
3993
|
+
if (!IsTransform(schema.unevaluatedProperties)) {
|
|
3994
|
+
return knownProperties;
|
|
3995
|
+
}
|
|
3996
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
3997
|
+
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
3998
|
+
const properties = { ...knownProperties };
|
|
3999
|
+
for (const key of unknownKeys)
|
|
4000
|
+
if (!knownKeys.includes(key)) {
|
|
4001
|
+
properties[key] = Default2(unevaluatedProperties, `${path}/${key}`, properties[key]);
|
|
4002
|
+
}
|
|
4003
|
+
return properties;
|
|
4004
|
+
}
|
|
4005
|
+
function FromNot5(schema, references, path, value) {
|
|
4006
|
+
return Default2(schema.not, path, Default2(schema, path, value));
|
|
4007
|
+
}
|
|
4008
|
+
function FromObject11(schema, references, path, value) {
|
|
4009
|
+
const defaulted = Default2(schema, path, value);
|
|
4010
|
+
if (!IsObject2(defaulted))
|
|
4011
|
+
return defaulted;
|
|
4012
|
+
const knownKeys = KeyOfPropertyKeys(schema);
|
|
4013
|
+
const knownProperties = { ...defaulted };
|
|
4014
|
+
for (const key of knownKeys) {
|
|
4015
|
+
if (!HasPropertyKey2(knownProperties, key))
|
|
4016
|
+
continue;
|
|
4017
|
+
if (IsUndefined2(knownProperties[key]) && (!IsUndefined3(schema.properties[key]) || TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
|
|
4018
|
+
continue;
|
|
4019
|
+
knownProperties[key] = Visit8(schema.properties[key], references, `${path}/${key}`, knownProperties[key]);
|
|
4020
|
+
}
|
|
4021
|
+
if (!IsSchema(schema.additionalProperties)) {
|
|
4022
|
+
return knownProperties;
|
|
4023
|
+
}
|
|
4024
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
4025
|
+
const additionalProperties = schema.additionalProperties;
|
|
4026
|
+
const properties = { ...knownProperties };
|
|
4027
|
+
for (const key of unknownKeys)
|
|
4028
|
+
if (!knownKeys.includes(key)) {
|
|
4029
|
+
properties[key] = Default2(additionalProperties, `${path}/${key}`, properties[key]);
|
|
4030
|
+
}
|
|
4031
|
+
return properties;
|
|
4032
|
+
}
|
|
4033
|
+
function FromRecord7(schema, references, path, value) {
|
|
4034
|
+
const defaulted = Default2(schema, path, value);
|
|
4035
|
+
if (!IsObject2(value))
|
|
4036
|
+
return defaulted;
|
|
4037
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
4038
|
+
const knownKeys = new RegExp(pattern);
|
|
4039
|
+
const knownProperties = { ...defaulted };
|
|
4040
|
+
for (const key of Object.getOwnPropertyNames(value))
|
|
4041
|
+
if (knownKeys.test(key)) {
|
|
4042
|
+
knownProperties[key] = Visit8(schema.patternProperties[pattern], references, `${path}/${key}`, knownProperties[key]);
|
|
4043
|
+
}
|
|
4044
|
+
if (!IsSchema(schema.additionalProperties)) {
|
|
4045
|
+
return knownProperties;
|
|
4046
|
+
}
|
|
4047
|
+
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
4048
|
+
const additionalProperties = schema.additionalProperties;
|
|
4049
|
+
const properties = { ...knownProperties };
|
|
4050
|
+
for (const key of unknownKeys)
|
|
4051
|
+
if (!knownKeys.test(key)) {
|
|
4052
|
+
properties[key] = Default2(additionalProperties, `${path}/${key}`, properties[key]);
|
|
4053
|
+
}
|
|
4054
|
+
return properties;
|
|
4055
|
+
}
|
|
4056
|
+
function FromRef8(schema, references, path, value) {
|
|
4057
|
+
const target = Deref(schema, references);
|
|
4058
|
+
const resolved = Visit8(target, references, path, value);
|
|
4059
|
+
return Default2(schema, path, resolved);
|
|
4060
|
+
}
|
|
4061
|
+
function FromThis4(schema, references, path, value) {
|
|
4062
|
+
const target = Deref(schema, references);
|
|
4063
|
+
const resolved = Visit8(target, references, path, value);
|
|
4064
|
+
return Default2(schema, path, resolved);
|
|
4065
|
+
}
|
|
4066
|
+
function FromTuple9(schema, references, path, value) {
|
|
4067
|
+
const value1 = Default2(schema, path, value);
|
|
4068
|
+
return IsArray2(schema.items) ? schema.items.map((schema2, index) => Visit8(schema2, references, `${path}/${index}`, value1[index])) : [];
|
|
4069
|
+
}
|
|
4070
|
+
function FromUnion14(schema, references, path, value) {
|
|
4071
|
+
for (const subschema of schema.anyOf) {
|
|
4072
|
+
if (!Check(subschema, references, value))
|
|
4073
|
+
continue;
|
|
4074
|
+
const value1 = Visit8(subschema, references, path, value);
|
|
4075
|
+
return Default2(schema, path, value1);
|
|
4076
|
+
}
|
|
4077
|
+
for (const subschema of schema.anyOf) {
|
|
4078
|
+
const value1 = Visit8(subschema, references, path, value);
|
|
4079
|
+
if (!Check(schema, references, value1))
|
|
4080
|
+
continue;
|
|
4081
|
+
return Default2(schema, path, value1);
|
|
4082
|
+
}
|
|
4083
|
+
return Default2(schema, path, value);
|
|
4084
|
+
}
|
|
4085
|
+
function Visit8(schema, references, path, value) {
|
|
4086
|
+
const references_ = Pushref(schema, references);
|
|
4087
|
+
const schema_ = schema;
|
|
4088
|
+
switch (schema[Kind]) {
|
|
4089
|
+
case "Array":
|
|
4090
|
+
return FromArray10(schema_, references_, path, value);
|
|
4091
|
+
case "Import":
|
|
4092
|
+
return FromImport4(schema_, references_, path, value);
|
|
4093
|
+
case "Intersect":
|
|
4094
|
+
return FromIntersect12(schema_, references_, path, value);
|
|
4095
|
+
case "Not":
|
|
4096
|
+
return FromNot5(schema_, references_, path, value);
|
|
4097
|
+
case "Object":
|
|
4098
|
+
return FromObject11(schema_, references_, path, value);
|
|
4099
|
+
case "Record":
|
|
4100
|
+
return FromRecord7(schema_, references_, path, value);
|
|
4101
|
+
case "Ref":
|
|
4102
|
+
return FromRef8(schema_, references_, path, value);
|
|
4103
|
+
case "This":
|
|
4104
|
+
return FromThis4(schema_, references_, path, value);
|
|
4105
|
+
case "Tuple":
|
|
4106
|
+
return FromTuple9(schema_, references_, path, value);
|
|
4107
|
+
case "Union":
|
|
4108
|
+
return FromUnion14(schema_, references_, path, value);
|
|
4109
|
+
default:
|
|
4110
|
+
return Default2(schema_, path, value);
|
|
2529
4111
|
}
|
|
2530
|
-
};
|
|
2531
|
-
function Transform(schema) {
|
|
2532
|
-
return new TransformDecodeBuilder(schema);
|
|
2533
4112
|
}
|
|
2534
|
-
function
|
|
2535
|
-
return
|
|
4113
|
+
function TransformEncode(schema, references, value) {
|
|
4114
|
+
return Visit8(schema, references, "", value);
|
|
2536
4115
|
}
|
|
2537
|
-
function
|
|
2538
|
-
return
|
|
4116
|
+
function FromArray11(schema, references) {
|
|
4117
|
+
return IsTransform(schema) || Visit9(schema.items, references);
|
|
2539
4118
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
4119
|
+
function FromAsyncIterator6(schema, references) {
|
|
4120
|
+
return IsTransform(schema) || Visit9(schema.items, references);
|
|
4121
|
+
}
|
|
4122
|
+
function FromConstructor6(schema, references) {
|
|
4123
|
+
return IsTransform(schema) || Visit9(schema.returns, references) || schema.parameters.some((schema2) => Visit9(schema2, references));
|
|
4124
|
+
}
|
|
4125
|
+
function FromFunction6(schema, references) {
|
|
4126
|
+
return IsTransform(schema) || Visit9(schema.returns, references) || schema.parameters.some((schema2) => Visit9(schema2, references));
|
|
4127
|
+
}
|
|
4128
|
+
function FromIntersect13(schema, references) {
|
|
4129
|
+
return IsTransform(schema) || IsTransform(schema.unevaluatedProperties) || schema.allOf.some((schema2) => Visit9(schema2, references));
|
|
4130
|
+
}
|
|
4131
|
+
function FromImport5(schema, references) {
|
|
4132
|
+
const additional = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => [...result, schema.$defs[key]], []);
|
|
4133
|
+
const target = schema.$defs[schema.$ref];
|
|
4134
|
+
return IsTransform(schema) || Visit9(target, [...additional, ...references]);
|
|
4135
|
+
}
|
|
4136
|
+
function FromIterator6(schema, references) {
|
|
4137
|
+
return IsTransform(schema) || Visit9(schema.items, references);
|
|
4138
|
+
}
|
|
4139
|
+
function FromNot6(schema, references) {
|
|
4140
|
+
return IsTransform(schema) || Visit9(schema.not, references);
|
|
4141
|
+
}
|
|
4142
|
+
function FromObject12(schema, references) {
|
|
4143
|
+
return IsTransform(schema) || Object.values(schema.properties).some((schema2) => Visit9(schema2, references)) || IsSchema(schema.additionalProperties) && Visit9(schema.additionalProperties, references);
|
|
4144
|
+
}
|
|
4145
|
+
function FromPromise6(schema, references) {
|
|
4146
|
+
return IsTransform(schema) || Visit9(schema.item, references);
|
|
4147
|
+
}
|
|
4148
|
+
function FromRecord8(schema, references) {
|
|
4149
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
4150
|
+
const property = schema.patternProperties[pattern];
|
|
4151
|
+
return IsTransform(schema) || Visit9(property, references) || IsSchema(schema.additionalProperties) && IsTransform(schema.additionalProperties);
|
|
4152
|
+
}
|
|
4153
|
+
function FromRef9(schema, references) {
|
|
4154
|
+
if (IsTransform(schema))
|
|
4155
|
+
return true;
|
|
4156
|
+
return Visit9(Deref(schema, references), references);
|
|
4157
|
+
}
|
|
4158
|
+
function FromThis5(schema, references) {
|
|
4159
|
+
if (IsTransform(schema))
|
|
4160
|
+
return true;
|
|
4161
|
+
return Visit9(Deref(schema, references), references);
|
|
4162
|
+
}
|
|
4163
|
+
function FromTuple10(schema, references) {
|
|
4164
|
+
return IsTransform(schema) || !IsUndefined2(schema.items) && schema.items.some((schema2) => Visit9(schema2, references));
|
|
4165
|
+
}
|
|
4166
|
+
function FromUnion15(schema, references) {
|
|
4167
|
+
return IsTransform(schema) || schema.anyOf.some((schema2) => Visit9(schema2, references));
|
|
4168
|
+
}
|
|
4169
|
+
function Visit9(schema, references) {
|
|
4170
|
+
const references_ = Pushref(schema, references);
|
|
4171
|
+
const schema_ = schema;
|
|
4172
|
+
if (schema.$id && visited.has(schema.$id))
|
|
4173
|
+
return false;
|
|
4174
|
+
if (schema.$id)
|
|
4175
|
+
visited.add(schema.$id);
|
|
4176
|
+
switch (schema[Kind]) {
|
|
4177
|
+
case "Array":
|
|
4178
|
+
return FromArray11(schema_, references_);
|
|
4179
|
+
case "AsyncIterator":
|
|
4180
|
+
return FromAsyncIterator6(schema_, references_);
|
|
4181
|
+
case "Constructor":
|
|
4182
|
+
return FromConstructor6(schema_, references_);
|
|
4183
|
+
case "Function":
|
|
4184
|
+
return FromFunction6(schema_, references_);
|
|
4185
|
+
case "Import":
|
|
4186
|
+
return FromImport5(schema_, references_);
|
|
4187
|
+
case "Intersect":
|
|
4188
|
+
return FromIntersect13(schema_, references_);
|
|
4189
|
+
case "Iterator":
|
|
4190
|
+
return FromIterator6(schema_, references_);
|
|
4191
|
+
case "Not":
|
|
4192
|
+
return FromNot6(schema_, references_);
|
|
4193
|
+
case "Object":
|
|
4194
|
+
return FromObject12(schema_, references_);
|
|
4195
|
+
case "Promise":
|
|
4196
|
+
return FromPromise6(schema_, references_);
|
|
4197
|
+
case "Record":
|
|
4198
|
+
return FromRecord8(schema_, references_);
|
|
4199
|
+
case "Ref":
|
|
4200
|
+
return FromRef9(schema_, references_);
|
|
4201
|
+
case "This":
|
|
4202
|
+
return FromThis5(schema_, references_);
|
|
4203
|
+
case "Tuple":
|
|
4204
|
+
return FromTuple10(schema_, references_);
|
|
4205
|
+
case "Union":
|
|
4206
|
+
return FromUnion15(schema_, references_);
|
|
4207
|
+
default:
|
|
4208
|
+
return IsTransform(schema);
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
var visited = /* @__PURE__ */ new Set();
|
|
4212
|
+
function HasTransform(schema, references) {
|
|
4213
|
+
visited.clear();
|
|
4214
|
+
return Visit9(schema, references);
|
|
4215
|
+
}
|
|
4216
|
+
var REF_PATTERN = /^e\d+_\d+$/;
|
|
4217
|
+
var DELIVERED_EXTRACT_FORMATS = [
|
|
4218
|
+
"text",
|
|
4219
|
+
"markdown",
|
|
4220
|
+
"links",
|
|
4221
|
+
"tables",
|
|
4222
|
+
"forms",
|
|
4223
|
+
"jsonld",
|
|
4224
|
+
"schema"
|
|
4225
|
+
];
|
|
2606
4226
|
var DELIVERED_ACTION_TYPES = [
|
|
2607
4227
|
"click",
|
|
4228
|
+
"dblclick",
|
|
4229
|
+
"hover",
|
|
2608
4230
|
"fill",
|
|
4231
|
+
"clear",
|
|
4232
|
+
"check",
|
|
4233
|
+
"uncheck",
|
|
2609
4234
|
"select",
|
|
2610
4235
|
"scroll",
|
|
2611
4236
|
"press",
|
|
4237
|
+
"wait",
|
|
4238
|
+
"goBack",
|
|
4239
|
+
"goForward",
|
|
4240
|
+
"reload",
|
|
2612
4241
|
"acceptDialog",
|
|
2613
4242
|
"dismissDialog"
|
|
2614
4243
|
];
|
|
@@ -2666,13 +4295,28 @@ var SessionPolicySchema = Type.Object({
|
|
|
2666
4295
|
maxDownloadBytes: Type.Optional(Type.Number({ minimum: 0 })),
|
|
2667
4296
|
approval: Type.Optional(ApprovalPolicySchema)
|
|
2668
4297
|
});
|
|
4298
|
+
var SessionCookieSchema = Type.Object({
|
|
4299
|
+
name: Type.String({ minLength: 1 }),
|
|
4300
|
+
value: Type.String(),
|
|
4301
|
+
domain: Type.String({ minLength: 1 }),
|
|
4302
|
+
path: Type.String(),
|
|
4303
|
+
expires: Type.Optional(Type.Number()),
|
|
4304
|
+
httpOnly: Type.Optional(Type.Boolean()),
|
|
4305
|
+
secure: Type.Optional(Type.Boolean()),
|
|
4306
|
+
sameSite: Type.Optional(Type.Union([Type.Literal("Strict"), Type.Literal("Lax"), Type.Literal("None")]))
|
|
4307
|
+
});
|
|
2669
4308
|
var SessionRequestSchema = Type.Object({
|
|
2670
|
-
|
|
4309
|
+
tenantId: Type.Optional(Type.String({ minLength: 1 })),
|
|
4310
|
+
// Known engine names plus any registered engine name (TD-BROWSER-7
|
|
4311
|
+
// registry routes arbitrary names; unknown names fail at the service).
|
|
4312
|
+
engine: Type.Optional(Type.Union([EngineTypeSchema, Type.String({ minLength: 1 })])),
|
|
2671
4313
|
ttlMs: Type.Optional(Type.Number({ minimum: 1e3, maximum: 864e5 })),
|
|
2672
4314
|
idleTimeoutMs: Type.Optional(Type.Number({ minimum: 1e3, maximum: 36e5 })),
|
|
2673
4315
|
viewport: Type.Optional(ViewportSchema),
|
|
2674
4316
|
locale: Type.Optional(Type.String({ pattern: "^[a-z]{2}-[A-Z]{2}$" })),
|
|
2675
4317
|
timezoneId: Type.Optional(Type.String()),
|
|
4318
|
+
headless: Type.Optional(Type.Boolean()),
|
|
4319
|
+
cookies: Type.Optional(Type.Array(SessionCookieSchema)),
|
|
2676
4320
|
policy: Type.Optional(SessionPolicySchema)
|
|
2677
4321
|
});
|
|
2678
4322
|
var ObservationModeSchema = Type.Union([
|
|
@@ -2685,6 +4329,7 @@ var ObservationModeSchema = Type.Union([
|
|
|
2685
4329
|
var ACTION_TYPE_LITERALS = [
|
|
2686
4330
|
"navigate",
|
|
2687
4331
|
"click",
|
|
4332
|
+
"dblclick",
|
|
2688
4333
|
"hover",
|
|
2689
4334
|
"fill",
|
|
2690
4335
|
"type",
|
|
@@ -2744,7 +4389,7 @@ var PageStatusSchema = Type.Union([
|
|
|
2744
4389
|
Type.Literal("complete")
|
|
2745
4390
|
]);
|
|
2746
4391
|
var PageElementSchema = Type.Object({
|
|
2747
|
-
ref: Type.String({ pattern:
|
|
4392
|
+
ref: Type.String({ pattern: REF_PATTERN.source }),
|
|
2748
4393
|
role: Type.String(),
|
|
2749
4394
|
name: Type.Optional(Type.String()),
|
|
2750
4395
|
value: Type.Optional(Type.String()),
|
|
@@ -2783,7 +4428,7 @@ var PageStateSchema = Type.Object({
|
|
|
2783
4428
|
continuation: Type.Optional(ContinuationCursorSchema)
|
|
2784
4429
|
});
|
|
2785
4430
|
var ElementTargetSchema = Type.Object({
|
|
2786
|
-
ref: Type.String({ pattern:
|
|
4431
|
+
ref: Type.String({ pattern: REF_PATTERN.source })
|
|
2787
4432
|
});
|
|
2788
4433
|
var NavigateActionSchema = Type.Object({
|
|
2789
4434
|
type: Type.Literal("navigate"),
|
|
@@ -2853,14 +4498,60 @@ var WaitActionSchema = Type.Object({
|
|
|
2853
4498
|
type: Type.Literal("wait"),
|
|
2854
4499
|
condition: WaitConditionSchema
|
|
2855
4500
|
});
|
|
4501
|
+
var HoverActionSchema = Type.Object({
|
|
4502
|
+
type: Type.Literal("hover"),
|
|
4503
|
+
target: ElementTargetSchema
|
|
4504
|
+
});
|
|
4505
|
+
var DblClickActionSchema = Type.Object({
|
|
4506
|
+
type: Type.Literal("dblclick"),
|
|
4507
|
+
target: ElementTargetSchema
|
|
4508
|
+
});
|
|
4509
|
+
var ClearActionSchema = Type.Object({
|
|
4510
|
+
type: Type.Literal("clear"),
|
|
4511
|
+
target: ElementTargetSchema
|
|
4512
|
+
});
|
|
4513
|
+
var CheckActionSchema = Type.Object({
|
|
4514
|
+
type: Type.Literal("check"),
|
|
4515
|
+
target: ElementTargetSchema
|
|
4516
|
+
});
|
|
4517
|
+
var UncheckActionSchema = Type.Object({
|
|
4518
|
+
type: Type.Literal("uncheck"),
|
|
4519
|
+
target: ElementTargetSchema
|
|
4520
|
+
});
|
|
4521
|
+
var GoBackActionSchema = Type.Object({
|
|
4522
|
+
type: Type.Literal("goBack")
|
|
4523
|
+
});
|
|
4524
|
+
var GoForwardActionSchema = Type.Object({
|
|
4525
|
+
type: Type.Literal("goForward")
|
|
4526
|
+
});
|
|
4527
|
+
var ReloadActionSchema = Type.Object({
|
|
4528
|
+
type: Type.Literal("reload")
|
|
4529
|
+
});
|
|
4530
|
+
var AcceptDialogActionSchema = Type.Object({
|
|
4531
|
+
type: Type.Literal("acceptDialog"),
|
|
4532
|
+
promptText: Type.Optional(Type.String())
|
|
4533
|
+
});
|
|
4534
|
+
var DismissDialogActionSchema = Type.Object({
|
|
4535
|
+
type: Type.Literal("dismissDialog")
|
|
4536
|
+
});
|
|
2856
4537
|
var ActionSchema = Type.Union([
|
|
2857
4538
|
NavigateActionSchema,
|
|
2858
4539
|
ClickActionSchema,
|
|
4540
|
+
DblClickActionSchema,
|
|
4541
|
+
HoverActionSchema,
|
|
2859
4542
|
FillActionSchema,
|
|
4543
|
+
ClearActionSchema,
|
|
4544
|
+
CheckActionSchema,
|
|
4545
|
+
UncheckActionSchema,
|
|
2860
4546
|
SelectActionSchema,
|
|
2861
4547
|
ScrollActionSchema,
|
|
2862
4548
|
PressActionSchema,
|
|
2863
|
-
WaitActionSchema
|
|
4549
|
+
WaitActionSchema,
|
|
4550
|
+
GoBackActionSchema,
|
|
4551
|
+
GoForwardActionSchema,
|
|
4552
|
+
ReloadActionSchema,
|
|
4553
|
+
AcceptDialogActionSchema,
|
|
4554
|
+
DismissDialogActionSchema
|
|
2864
4555
|
]);
|
|
2865
4556
|
var ObservationRequestSchema = Type.Object({
|
|
2866
4557
|
mode: Type.Optional(ObservationModeSchema),
|
|
@@ -2928,6 +4619,569 @@ var ActionResultSchema = Type.Object({
|
|
|
2928
4619
|
artifacts: Type.Optional(Type.Array(ArtifactRefSchema)),
|
|
2929
4620
|
error: Type.Optional(ApiErrorDetailSchema)
|
|
2930
4621
|
});
|
|
4622
|
+
var TypeCheck = class {
|
|
4623
|
+
constructor(schema, references, checkFunc, code) {
|
|
4624
|
+
this.schema = schema;
|
|
4625
|
+
this.references = references;
|
|
4626
|
+
this.checkFunc = checkFunc;
|
|
4627
|
+
this.code = code;
|
|
4628
|
+
this.hasTransform = HasTransform(schema, references);
|
|
4629
|
+
}
|
|
4630
|
+
/** Returns the generated assertion code used to validate this type. */
|
|
4631
|
+
Code() {
|
|
4632
|
+
return this.code;
|
|
4633
|
+
}
|
|
4634
|
+
/** Returns the schema type used to validate */
|
|
4635
|
+
Schema() {
|
|
4636
|
+
return this.schema;
|
|
4637
|
+
}
|
|
4638
|
+
/** Returns reference types used to validate */
|
|
4639
|
+
References() {
|
|
4640
|
+
return this.references;
|
|
4641
|
+
}
|
|
4642
|
+
/** Returns an iterator for each error in this value. */
|
|
4643
|
+
Errors(value) {
|
|
4644
|
+
return Errors(this.schema, this.references, value);
|
|
4645
|
+
}
|
|
4646
|
+
/** Returns true if the value matches the compiled type. */
|
|
4647
|
+
Check(value) {
|
|
4648
|
+
return this.checkFunc(value);
|
|
4649
|
+
}
|
|
4650
|
+
/** Decodes a value or throws if error */
|
|
4651
|
+
Decode(value) {
|
|
4652
|
+
if (!this.checkFunc(value))
|
|
4653
|
+
throw new TransformDecodeCheckError(this.schema, value, this.Errors(value).First());
|
|
4654
|
+
return this.hasTransform ? TransformDecode(this.schema, this.references, value) : value;
|
|
4655
|
+
}
|
|
4656
|
+
/** Encodes a value or throws if error */
|
|
4657
|
+
Encode(value) {
|
|
4658
|
+
const encoded = this.hasTransform ? TransformEncode(this.schema, this.references, value) : value;
|
|
4659
|
+
if (!this.checkFunc(encoded))
|
|
4660
|
+
throw new TransformEncodeCheckError(this.schema, value, this.Errors(value).First());
|
|
4661
|
+
return encoded;
|
|
4662
|
+
}
|
|
4663
|
+
};
|
|
4664
|
+
var Character;
|
|
4665
|
+
(function(Character2) {
|
|
4666
|
+
function DollarSign(code) {
|
|
4667
|
+
return code === 36;
|
|
4668
|
+
}
|
|
4669
|
+
Character2.DollarSign = DollarSign;
|
|
4670
|
+
function IsUnderscore(code) {
|
|
4671
|
+
return code === 95;
|
|
4672
|
+
}
|
|
4673
|
+
Character2.IsUnderscore = IsUnderscore;
|
|
4674
|
+
function IsAlpha(code) {
|
|
4675
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
4676
|
+
}
|
|
4677
|
+
Character2.IsAlpha = IsAlpha;
|
|
4678
|
+
function IsNumeric(code) {
|
|
4679
|
+
return code >= 48 && code <= 57;
|
|
4680
|
+
}
|
|
4681
|
+
Character2.IsNumeric = IsNumeric;
|
|
4682
|
+
})(Character || (Character = {}));
|
|
4683
|
+
var Identifier;
|
|
4684
|
+
(function(Identifier2) {
|
|
4685
|
+
function Encode($id) {
|
|
4686
|
+
const buffer = [];
|
|
4687
|
+
for (let i = 0; i < $id.length; i++) {
|
|
4688
|
+
const code = $id.charCodeAt(i);
|
|
4689
|
+
if (Character.IsNumeric(code) || Character.IsAlpha(code)) {
|
|
4690
|
+
buffer.push($id.charAt(i));
|
|
4691
|
+
} else {
|
|
4692
|
+
buffer.push(`_${code}_`);
|
|
4693
|
+
}
|
|
4694
|
+
}
|
|
4695
|
+
return buffer.join("").replace(/__/g, "_");
|
|
4696
|
+
}
|
|
4697
|
+
Identifier2.Encode = Encode;
|
|
4698
|
+
})(Identifier || (Identifier = {}));
|
|
4699
|
+
function StringConstant(value) {
|
|
4700
|
+
if (!IsString2(value))
|
|
4701
|
+
throw Error("ConstantString: Not a String");
|
|
4702
|
+
const canonical = JSON.stringify(value).slice(1, -1);
|
|
4703
|
+
const escaped = canonical.replace(/'/g, "\\'");
|
|
4704
|
+
return `'${escaped}'`;
|
|
4705
|
+
}
|
|
4706
|
+
function MemberExpression(value, key) {
|
|
4707
|
+
return `${value}[${StringConstant(key)}]`;
|
|
4708
|
+
}
|
|
4709
|
+
var TypeCompilerUnknownTypeError = class extends TypeBoxError {
|
|
4710
|
+
constructor(schema) {
|
|
4711
|
+
super("Unknown type");
|
|
4712
|
+
this.schema = schema;
|
|
4713
|
+
}
|
|
4714
|
+
};
|
|
4715
|
+
var TypeCompilerTypeGuardError = class extends TypeBoxError {
|
|
4716
|
+
constructor(schema) {
|
|
4717
|
+
super("Preflight validation check failed to guard for the given schema");
|
|
4718
|
+
this.schema = schema;
|
|
4719
|
+
}
|
|
4720
|
+
};
|
|
4721
|
+
var Policy;
|
|
4722
|
+
(function(Policy2) {
|
|
4723
|
+
function IsExactOptionalProperty(value, key, expression) {
|
|
4724
|
+
return TypeSystemPolicy.ExactOptionalPropertyTypes ? `(${StringConstant(key)} in ${value} ? ${expression} : true)` : `(${MemberExpression(value, key)} !== undefined ? ${expression} : true)`;
|
|
4725
|
+
}
|
|
4726
|
+
Policy2.IsExactOptionalProperty = IsExactOptionalProperty;
|
|
4727
|
+
function IsObjectLike(value) {
|
|
4728
|
+
return !TypeSystemPolicy.AllowArrayObject ? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))` : `(typeof ${value} === 'object' && ${value} !== null)`;
|
|
4729
|
+
}
|
|
4730
|
+
Policy2.IsObjectLike = IsObjectLike;
|
|
4731
|
+
function IsRecordLike(value) {
|
|
4732
|
+
return !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))`;
|
|
4733
|
+
}
|
|
4734
|
+
Policy2.IsRecordLike = IsRecordLike;
|
|
4735
|
+
function IsNumberLike(value) {
|
|
4736
|
+
return TypeSystemPolicy.AllowNaN ? `typeof ${value} === 'number'` : `Number.isFinite(${value})`;
|
|
4737
|
+
}
|
|
4738
|
+
Policy2.IsNumberLike = IsNumberLike;
|
|
4739
|
+
function IsVoidLike(value) {
|
|
4740
|
+
return TypeSystemPolicy.AllowNullVoid ? `(${value} === undefined || ${value} === null)` : `${value} === undefined`;
|
|
4741
|
+
}
|
|
4742
|
+
Policy2.IsVoidLike = IsVoidLike;
|
|
4743
|
+
})(Policy || (Policy = {}));
|
|
4744
|
+
var TypeCompiler;
|
|
4745
|
+
(function(TypeCompiler2) {
|
|
4746
|
+
function IsAnyOrUnknown2(schema) {
|
|
4747
|
+
return schema[Kind] === "Any" || schema[Kind] === "Unknown";
|
|
4748
|
+
}
|
|
4749
|
+
function* FromAny4(schema, references, value) {
|
|
4750
|
+
yield "true";
|
|
4751
|
+
}
|
|
4752
|
+
function* FromArgument4(schema, references, value) {
|
|
4753
|
+
yield "true";
|
|
4754
|
+
}
|
|
4755
|
+
function* FromArray12(schema, references, value) {
|
|
4756
|
+
yield `Array.isArray(${value})`;
|
|
4757
|
+
const [parameter, accumulator] = [CreateParameter("value", "any"), CreateParameter("acc", "number")];
|
|
4758
|
+
if (IsNumber2(schema.maxItems))
|
|
4759
|
+
yield `${value}.length <= ${schema.maxItems}`;
|
|
4760
|
+
if (IsNumber2(schema.minItems))
|
|
4761
|
+
yield `${value}.length >= ${schema.minItems}`;
|
|
4762
|
+
const elementExpression = CreateExpression(schema.items, references, "value");
|
|
4763
|
+
yield `((array) => { for(const ${parameter} of array) if(!(${elementExpression})) { return false }; return true; })(${value})`;
|
|
4764
|
+
if (IsSchema2(schema.contains) || IsNumber2(schema.minContains) || IsNumber2(schema.maxContains)) {
|
|
4765
|
+
const containsSchema = IsSchema2(schema.contains) ? schema.contains : Never();
|
|
4766
|
+
const checkExpression = CreateExpression(containsSchema, references, "value");
|
|
4767
|
+
const checkMinContains = IsNumber2(schema.minContains) ? [`(count >= ${schema.minContains})`] : [];
|
|
4768
|
+
const checkMaxContains = IsNumber2(schema.maxContains) ? [`(count <= ${schema.maxContains})`] : [];
|
|
4769
|
+
const checkCount = `const count = value.reduce((${accumulator}, ${parameter}) => ${checkExpression} ? acc + 1 : acc, 0)`;
|
|
4770
|
+
const check = [`(count > 0)`, ...checkMinContains, ...checkMaxContains].join(" && ");
|
|
4771
|
+
yield `((${parameter}) => { ${checkCount}; return ${check}})(${value})`;
|
|
4772
|
+
}
|
|
4773
|
+
if (schema.uniqueItems === true) {
|
|
4774
|
+
const check = `const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true`;
|
|
4775
|
+
const block = `const set = new Set(); for(const element of value) { ${check} }`;
|
|
4776
|
+
yield `((${parameter}) => { ${block} )(${value})`;
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
function* FromAsyncIterator7(schema, references, value) {
|
|
4780
|
+
yield `(typeof value === 'object' && Symbol.asyncIterator in ${value})`;
|
|
4781
|
+
}
|
|
4782
|
+
function* FromBigInt4(schema, references, value) {
|
|
4783
|
+
yield `(typeof ${value} === 'bigint')`;
|
|
4784
|
+
if (IsBigInt2(schema.exclusiveMaximum))
|
|
4785
|
+
yield `${value} < BigInt(${schema.exclusiveMaximum})`;
|
|
4786
|
+
if (IsBigInt2(schema.exclusiveMinimum))
|
|
4787
|
+
yield `${value} > BigInt(${schema.exclusiveMinimum})`;
|
|
4788
|
+
if (IsBigInt2(schema.maximum))
|
|
4789
|
+
yield `${value} <= BigInt(${schema.maximum})`;
|
|
4790
|
+
if (IsBigInt2(schema.minimum))
|
|
4791
|
+
yield `${value} >= BigInt(${schema.minimum})`;
|
|
4792
|
+
if (IsBigInt2(schema.multipleOf))
|
|
4793
|
+
yield `(${value} % BigInt(${schema.multipleOf})) === 0`;
|
|
4794
|
+
}
|
|
4795
|
+
function* FromBoolean4(schema, references, value) {
|
|
4796
|
+
yield `(typeof ${value} === 'boolean')`;
|
|
4797
|
+
}
|
|
4798
|
+
function* FromConstructor7(schema, references, value) {
|
|
4799
|
+
yield* Visit10(schema.returns, references, `${value}.prototype`);
|
|
4800
|
+
}
|
|
4801
|
+
function* FromDate4(schema, references, value) {
|
|
4802
|
+
yield `(${value} instanceof Date) && Number.isFinite(${value}.getTime())`;
|
|
4803
|
+
if (IsNumber2(schema.exclusiveMaximumTimestamp))
|
|
4804
|
+
yield `${value}.getTime() < ${schema.exclusiveMaximumTimestamp}`;
|
|
4805
|
+
if (IsNumber2(schema.exclusiveMinimumTimestamp))
|
|
4806
|
+
yield `${value}.getTime() > ${schema.exclusiveMinimumTimestamp}`;
|
|
4807
|
+
if (IsNumber2(schema.maximumTimestamp))
|
|
4808
|
+
yield `${value}.getTime() <= ${schema.maximumTimestamp}`;
|
|
4809
|
+
if (IsNumber2(schema.minimumTimestamp))
|
|
4810
|
+
yield `${value}.getTime() >= ${schema.minimumTimestamp}`;
|
|
4811
|
+
if (IsNumber2(schema.multipleOfTimestamp))
|
|
4812
|
+
yield `(${value}.getTime() % ${schema.multipleOfTimestamp}) === 0`;
|
|
4813
|
+
}
|
|
4814
|
+
function* FromFunction7(schema, references, value) {
|
|
4815
|
+
yield `(typeof ${value} === 'function')`;
|
|
4816
|
+
}
|
|
4817
|
+
function* FromImport6(schema, references, value) {
|
|
4818
|
+
const members = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => {
|
|
4819
|
+
return [...result, schema.$defs[key]];
|
|
4820
|
+
}, []);
|
|
4821
|
+
yield* Visit10(Ref(schema.$ref), [...references, ...members], value);
|
|
4822
|
+
}
|
|
4823
|
+
function* FromInteger4(schema, references, value) {
|
|
4824
|
+
yield `Number.isInteger(${value})`;
|
|
4825
|
+
if (IsNumber2(schema.exclusiveMaximum))
|
|
4826
|
+
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
4827
|
+
if (IsNumber2(schema.exclusiveMinimum))
|
|
4828
|
+
yield `${value} > ${schema.exclusiveMinimum}`;
|
|
4829
|
+
if (IsNumber2(schema.maximum))
|
|
4830
|
+
yield `${value} <= ${schema.maximum}`;
|
|
4831
|
+
if (IsNumber2(schema.minimum))
|
|
4832
|
+
yield `${value} >= ${schema.minimum}`;
|
|
4833
|
+
if (IsNumber2(schema.multipleOf))
|
|
4834
|
+
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
4835
|
+
}
|
|
4836
|
+
function* FromIntersect14(schema, references, value) {
|
|
4837
|
+
const check1 = schema.allOf.map((schema2) => CreateExpression(schema2, references, value)).join(" && ");
|
|
4838
|
+
if (schema.unevaluatedProperties === false) {
|
|
4839
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
4840
|
+
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key))`;
|
|
4841
|
+
yield `(${check1} && ${check2})`;
|
|
4842
|
+
} else if (IsSchema2(schema.unevaluatedProperties)) {
|
|
4843
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
4844
|
+
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
|
|
4845
|
+
yield `(${check1} && ${check2})`;
|
|
4846
|
+
} else {
|
|
4847
|
+
yield `(${check1})`;
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
function* FromIterator7(schema, references, value) {
|
|
4851
|
+
yield `(typeof value === 'object' && Symbol.iterator in ${value})`;
|
|
4852
|
+
}
|
|
4853
|
+
function* FromLiteral5(schema, references, value) {
|
|
4854
|
+
if (typeof schema.const === "number" || typeof schema.const === "boolean") {
|
|
4855
|
+
yield `(${value} === ${schema.const})`;
|
|
4856
|
+
} else if (typeof schema.const === "string") {
|
|
4857
|
+
yield `(${value} === ${StringConstant(schema.const)})`;
|
|
4858
|
+
} else {
|
|
4859
|
+
throw Error("Invalid Literal Value");
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
function* FromNever4(schema, references, value) {
|
|
4863
|
+
yield `false`;
|
|
4864
|
+
}
|
|
4865
|
+
function* FromNot7(schema, references, value) {
|
|
4866
|
+
const expression = CreateExpression(schema.not, references, value);
|
|
4867
|
+
yield `(!${expression})`;
|
|
4868
|
+
}
|
|
4869
|
+
function* FromNull4(schema, references, value) {
|
|
4870
|
+
yield `(${value} === null)`;
|
|
4871
|
+
}
|
|
4872
|
+
function* FromNumber4(schema, references, value) {
|
|
4873
|
+
yield Policy.IsNumberLike(value);
|
|
4874
|
+
if (IsNumber2(schema.exclusiveMaximum))
|
|
4875
|
+
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
4876
|
+
if (IsNumber2(schema.exclusiveMinimum))
|
|
4877
|
+
yield `${value} > ${schema.exclusiveMinimum}`;
|
|
4878
|
+
if (IsNumber2(schema.maximum))
|
|
4879
|
+
yield `${value} <= ${schema.maximum}`;
|
|
4880
|
+
if (IsNumber2(schema.minimum))
|
|
4881
|
+
yield `${value} >= ${schema.minimum}`;
|
|
4882
|
+
if (IsNumber2(schema.multipleOf))
|
|
4883
|
+
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
4884
|
+
}
|
|
4885
|
+
function* FromObject13(schema, references, value) {
|
|
4886
|
+
yield Policy.IsObjectLike(value);
|
|
4887
|
+
if (IsNumber2(schema.minProperties))
|
|
4888
|
+
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
4889
|
+
if (IsNumber2(schema.maxProperties))
|
|
4890
|
+
yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
|
|
4891
|
+
const knownKeys = Object.getOwnPropertyNames(schema.properties);
|
|
4892
|
+
for (const knownKey of knownKeys) {
|
|
4893
|
+
const memberExpression = MemberExpression(value, knownKey);
|
|
4894
|
+
const property = schema.properties[knownKey];
|
|
4895
|
+
if (schema.required && schema.required.includes(knownKey)) {
|
|
4896
|
+
yield* Visit10(property, references, memberExpression);
|
|
4897
|
+
if (ExtendsUndefinedCheck(property) || IsAnyOrUnknown2(property))
|
|
4898
|
+
yield `(${StringConstant(knownKey)} in ${value})`;
|
|
4899
|
+
} else {
|
|
4900
|
+
const expression = CreateExpression(property, references, memberExpression);
|
|
4901
|
+
yield Policy.IsExactOptionalProperty(value, knownKey, expression);
|
|
4902
|
+
}
|
|
4903
|
+
}
|
|
4904
|
+
if (schema.additionalProperties === false) {
|
|
4905
|
+
if (schema.required && schema.required.length === knownKeys.length) {
|
|
4906
|
+
yield `Object.getOwnPropertyNames(${value}).length === ${knownKeys.length}`;
|
|
4907
|
+
} else {
|
|
4908
|
+
const keys = `[${knownKeys.map((key) => `${StringConstant(key)}`).join(", ")}]`;
|
|
4909
|
+
yield `Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key))`;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
if (typeof schema.additionalProperties === "object") {
|
|
4913
|
+
const expression = CreateExpression(schema.additionalProperties, references, `${value}[key]`);
|
|
4914
|
+
const keys = `[${knownKeys.map((key) => `${StringConstant(key)}`).join(", ")}]`;
|
|
4915
|
+
yield `(Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key) || ${expression}))`;
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
function* FromPromise7(schema, references, value) {
|
|
4919
|
+
yield `${value} instanceof Promise`;
|
|
4920
|
+
}
|
|
4921
|
+
function* FromRecord9(schema, references, value) {
|
|
4922
|
+
yield Policy.IsRecordLike(value);
|
|
4923
|
+
if (IsNumber2(schema.minProperties))
|
|
4924
|
+
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
4925
|
+
if (IsNumber2(schema.maxProperties))
|
|
4926
|
+
yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
|
|
4927
|
+
const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
|
|
4928
|
+
const variable = CreateVariable(`${new RegExp(patternKey)}`);
|
|
4929
|
+
const check1 = CreateExpression(patternSchema, references, "value");
|
|
4930
|
+
const check2 = IsSchema2(schema.additionalProperties) ? CreateExpression(schema.additionalProperties, references, value) : schema.additionalProperties === false ? "false" : "true";
|
|
4931
|
+
const expression = `(${variable}.test(key) ? ${check1} : ${check2})`;
|
|
4932
|
+
yield `(Object.entries(${value}).every(([key, value]) => ${expression}))`;
|
|
4933
|
+
}
|
|
4934
|
+
function* FromRef10(schema, references, value) {
|
|
4935
|
+
const target = Deref(schema, references);
|
|
4936
|
+
if (state.functions.has(schema.$ref))
|
|
4937
|
+
return yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
4938
|
+
yield* Visit10(target, references, value);
|
|
4939
|
+
}
|
|
4940
|
+
function* FromRegExp4(schema, references, value) {
|
|
4941
|
+
const variable = CreateVariable(`${new RegExp(schema.source, schema.flags)};`);
|
|
4942
|
+
yield `(typeof ${value} === 'string')`;
|
|
4943
|
+
if (IsNumber2(schema.maxLength))
|
|
4944
|
+
yield `${value}.length <= ${schema.maxLength}`;
|
|
4945
|
+
if (IsNumber2(schema.minLength))
|
|
4946
|
+
yield `${value}.length >= ${schema.minLength}`;
|
|
4947
|
+
yield `${variable}.test(${value})`;
|
|
4948
|
+
}
|
|
4949
|
+
function* FromString4(schema, references, value) {
|
|
4950
|
+
yield `(typeof ${value} === 'string')`;
|
|
4951
|
+
if (IsNumber2(schema.maxLength))
|
|
4952
|
+
yield `${value}.length <= ${schema.maxLength}`;
|
|
4953
|
+
if (IsNumber2(schema.minLength))
|
|
4954
|
+
yield `${value}.length >= ${schema.minLength}`;
|
|
4955
|
+
if (schema.pattern !== void 0) {
|
|
4956
|
+
const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
|
|
4957
|
+
yield `${variable}.test(${value})`;
|
|
4958
|
+
}
|
|
4959
|
+
if (schema.format !== void 0) {
|
|
4960
|
+
yield `format(${StringConstant(schema.format)}, ${value})`;
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
function* FromSymbol4(schema, references, value) {
|
|
4964
|
+
yield `(typeof ${value} === 'symbol')`;
|
|
4965
|
+
}
|
|
4966
|
+
function* FromTemplateLiteral6(schema, references, value) {
|
|
4967
|
+
yield `(typeof ${value} === 'string')`;
|
|
4968
|
+
const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
|
|
4969
|
+
yield `${variable}.test(${value})`;
|
|
4970
|
+
}
|
|
4971
|
+
function* FromThis6(schema, references, value) {
|
|
4972
|
+
yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
4973
|
+
}
|
|
4974
|
+
function* FromTuple11(schema, references, value) {
|
|
4975
|
+
yield `Array.isArray(${value})`;
|
|
4976
|
+
if (schema.items === void 0)
|
|
4977
|
+
return yield `${value}.length === 0`;
|
|
4978
|
+
yield `(${value}.length === ${schema.maxItems})`;
|
|
4979
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
4980
|
+
const expression = CreateExpression(schema.items[i], references, `${value}[${i}]`);
|
|
4981
|
+
yield `${expression}`;
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
function* FromUndefined4(schema, references, value) {
|
|
4985
|
+
yield `${value} === undefined`;
|
|
4986
|
+
}
|
|
4987
|
+
function* FromUnion16(schema, references, value) {
|
|
4988
|
+
const expressions = schema.anyOf.map((schema2) => CreateExpression(schema2, references, value));
|
|
4989
|
+
yield `(${expressions.join(" || ")})`;
|
|
4990
|
+
}
|
|
4991
|
+
function* FromUint8Array4(schema, references, value) {
|
|
4992
|
+
yield `${value} instanceof Uint8Array`;
|
|
4993
|
+
if (IsNumber2(schema.maxByteLength))
|
|
4994
|
+
yield `(${value}.length <= ${schema.maxByteLength})`;
|
|
4995
|
+
if (IsNumber2(schema.minByteLength))
|
|
4996
|
+
yield `(${value}.length >= ${schema.minByteLength})`;
|
|
4997
|
+
}
|
|
4998
|
+
function* FromUnknown4(schema, references, value) {
|
|
4999
|
+
yield "true";
|
|
5000
|
+
}
|
|
5001
|
+
function* FromVoid4(schema, references, value) {
|
|
5002
|
+
yield Policy.IsVoidLike(value);
|
|
5003
|
+
}
|
|
5004
|
+
function* FromKind3(schema, references, value) {
|
|
5005
|
+
const instance = state.instances.size;
|
|
5006
|
+
state.instances.set(instance, schema);
|
|
5007
|
+
yield `kind(${StringConstant(schema[Kind])}, ${instance}, ${value})`;
|
|
5008
|
+
}
|
|
5009
|
+
function* Visit10(schema, references, value, useHoisting = true) {
|
|
5010
|
+
const references_ = IsString2(schema.$id) ? [...references, schema] : references;
|
|
5011
|
+
const schema_ = schema;
|
|
5012
|
+
if (useHoisting && IsString2(schema.$id)) {
|
|
5013
|
+
const functionName = CreateFunctionName(schema.$id);
|
|
5014
|
+
if (state.functions.has(functionName)) {
|
|
5015
|
+
return yield `${functionName}(${value})`;
|
|
5016
|
+
} else {
|
|
5017
|
+
state.functions.set(functionName, "<deferred>");
|
|
5018
|
+
const functionCode = CreateFunction(functionName, schema, references, "value", false);
|
|
5019
|
+
state.functions.set(functionName, functionCode);
|
|
5020
|
+
return yield `${functionName}(${value})`;
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
switch (schema_[Kind]) {
|
|
5024
|
+
case "Any":
|
|
5025
|
+
return yield* FromAny4(schema_, references_, value);
|
|
5026
|
+
case "Argument":
|
|
5027
|
+
return yield* FromArgument4(schema_, references_, value);
|
|
5028
|
+
case "Array":
|
|
5029
|
+
return yield* FromArray12(schema_, references_, value);
|
|
5030
|
+
case "AsyncIterator":
|
|
5031
|
+
return yield* FromAsyncIterator7(schema_, references_, value);
|
|
5032
|
+
case "BigInt":
|
|
5033
|
+
return yield* FromBigInt4(schema_, references_, value);
|
|
5034
|
+
case "Boolean":
|
|
5035
|
+
return yield* FromBoolean4(schema_, references_, value);
|
|
5036
|
+
case "Constructor":
|
|
5037
|
+
return yield* FromConstructor7(schema_, references_, value);
|
|
5038
|
+
case "Date":
|
|
5039
|
+
return yield* FromDate4(schema_, references_, value);
|
|
5040
|
+
case "Function":
|
|
5041
|
+
return yield* FromFunction7(schema_, references_, value);
|
|
5042
|
+
case "Import":
|
|
5043
|
+
return yield* FromImport6(schema_, references_, value);
|
|
5044
|
+
case "Integer":
|
|
5045
|
+
return yield* FromInteger4(schema_, references_, value);
|
|
5046
|
+
case "Intersect":
|
|
5047
|
+
return yield* FromIntersect14(schema_, references_, value);
|
|
5048
|
+
case "Iterator":
|
|
5049
|
+
return yield* FromIterator7(schema_, references_, value);
|
|
5050
|
+
case "Literal":
|
|
5051
|
+
return yield* FromLiteral5(schema_, references_, value);
|
|
5052
|
+
case "Never":
|
|
5053
|
+
return yield* FromNever4(schema_, references_, value);
|
|
5054
|
+
case "Not":
|
|
5055
|
+
return yield* FromNot7(schema_, references_, value);
|
|
5056
|
+
case "Null":
|
|
5057
|
+
return yield* FromNull4(schema_, references_, value);
|
|
5058
|
+
case "Number":
|
|
5059
|
+
return yield* FromNumber4(schema_, references_, value);
|
|
5060
|
+
case "Object":
|
|
5061
|
+
return yield* FromObject13(schema_, references_, value);
|
|
5062
|
+
case "Promise":
|
|
5063
|
+
return yield* FromPromise7(schema_, references_, value);
|
|
5064
|
+
case "Record":
|
|
5065
|
+
return yield* FromRecord9(schema_, references_, value);
|
|
5066
|
+
case "Ref":
|
|
5067
|
+
return yield* FromRef10(schema_, references_, value);
|
|
5068
|
+
case "RegExp":
|
|
5069
|
+
return yield* FromRegExp4(schema_, references_, value);
|
|
5070
|
+
case "String":
|
|
5071
|
+
return yield* FromString4(schema_, references_, value);
|
|
5072
|
+
case "Symbol":
|
|
5073
|
+
return yield* FromSymbol4(schema_, references_, value);
|
|
5074
|
+
case "TemplateLiteral":
|
|
5075
|
+
return yield* FromTemplateLiteral6(schema_, references_, value);
|
|
5076
|
+
case "This":
|
|
5077
|
+
return yield* FromThis6(schema_, references_, value);
|
|
5078
|
+
case "Tuple":
|
|
5079
|
+
return yield* FromTuple11(schema_, references_, value);
|
|
5080
|
+
case "Undefined":
|
|
5081
|
+
return yield* FromUndefined4(schema_, references_, value);
|
|
5082
|
+
case "Union":
|
|
5083
|
+
return yield* FromUnion16(schema_, references_, value);
|
|
5084
|
+
case "Uint8Array":
|
|
5085
|
+
return yield* FromUint8Array4(schema_, references_, value);
|
|
5086
|
+
case "Unknown":
|
|
5087
|
+
return yield* FromUnknown4(schema_, references_, value);
|
|
5088
|
+
case "Void":
|
|
5089
|
+
return yield* FromVoid4(schema_, references_, value);
|
|
5090
|
+
default:
|
|
5091
|
+
if (!type_exports2.Has(schema_[Kind]))
|
|
5092
|
+
throw new TypeCompilerUnknownTypeError(schema);
|
|
5093
|
+
return yield* FromKind3(schema_, references_, value);
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
const state = {
|
|
5097
|
+
language: "javascript",
|
|
5098
|
+
// target language
|
|
5099
|
+
functions: /* @__PURE__ */ new Map(),
|
|
5100
|
+
// local functions
|
|
5101
|
+
variables: /* @__PURE__ */ new Map(),
|
|
5102
|
+
// local variables
|
|
5103
|
+
instances: /* @__PURE__ */ new Map()
|
|
5104
|
+
// exterior kind instances
|
|
5105
|
+
};
|
|
5106
|
+
function CreateExpression(schema, references, value, useHoisting = true) {
|
|
5107
|
+
return `(${[...Visit10(schema, references, value, useHoisting)].join(" && ")})`;
|
|
5108
|
+
}
|
|
5109
|
+
function CreateFunctionName($id) {
|
|
5110
|
+
return `check_${Identifier.Encode($id)}`;
|
|
5111
|
+
}
|
|
5112
|
+
function CreateVariable(expression) {
|
|
5113
|
+
const variableName = `local_${state.variables.size}`;
|
|
5114
|
+
state.variables.set(variableName, `const ${variableName} = ${expression}`);
|
|
5115
|
+
return variableName;
|
|
5116
|
+
}
|
|
5117
|
+
function CreateFunction(name, schema, references, value, useHoisting = true) {
|
|
5118
|
+
const [newline, pad] = ["\n", (length) => "".padStart(length, " ")];
|
|
5119
|
+
const parameter = CreateParameter("value", "any");
|
|
5120
|
+
const returns = CreateReturns("boolean");
|
|
5121
|
+
const expression = [...Visit10(schema, references, value, useHoisting)].map((expression2) => `${pad(4)}${expression2}`).join(` &&${newline}`);
|
|
5122
|
+
return `function ${name}(${parameter})${returns} {${newline}${pad(2)}return (${newline}${expression}${newline}${pad(2)})
|
|
5123
|
+
}`;
|
|
5124
|
+
}
|
|
5125
|
+
function CreateParameter(name, type) {
|
|
5126
|
+
const annotation = state.language === "typescript" ? `: ${type}` : "";
|
|
5127
|
+
return `${name}${annotation}`;
|
|
5128
|
+
}
|
|
5129
|
+
function CreateReturns(type) {
|
|
5130
|
+
return state.language === "typescript" ? `: ${type}` : "";
|
|
5131
|
+
}
|
|
5132
|
+
function Build(schema, references, options) {
|
|
5133
|
+
const functionCode = CreateFunction("check", schema, references, "value");
|
|
5134
|
+
const parameter = CreateParameter("value", "any");
|
|
5135
|
+
const returns = CreateReturns("boolean");
|
|
5136
|
+
const functions = [...state.functions.values()];
|
|
5137
|
+
const variables = [...state.variables.values()];
|
|
5138
|
+
const checkFunction = IsString2(schema.$id) ? `return function check(${parameter})${returns} {
|
|
5139
|
+
return ${CreateFunctionName(schema.$id)}(value)
|
|
5140
|
+
}` : `return ${functionCode}`;
|
|
5141
|
+
return [...variables, ...functions, checkFunction].join("\n");
|
|
5142
|
+
}
|
|
5143
|
+
function Code(...args) {
|
|
5144
|
+
const defaults = { language: "javascript" };
|
|
5145
|
+
const [schema, references, options] = args.length === 2 && IsArray2(args[1]) ? [args[0], args[1], defaults] : args.length === 2 && !IsArray2(args[1]) ? [args[0], [], args[1]] : args.length === 3 ? [args[0], args[1], args[2]] : args.length === 1 ? [args[0], [], defaults] : [null, [], defaults];
|
|
5146
|
+
state.language = options.language;
|
|
5147
|
+
state.variables.clear();
|
|
5148
|
+
state.functions.clear();
|
|
5149
|
+
state.instances.clear();
|
|
5150
|
+
if (!IsSchema2(schema))
|
|
5151
|
+
throw new TypeCompilerTypeGuardError(schema);
|
|
5152
|
+
for (const schema2 of references)
|
|
5153
|
+
if (!IsSchema2(schema2))
|
|
5154
|
+
throw new TypeCompilerTypeGuardError(schema2);
|
|
5155
|
+
return Build(schema, references, options);
|
|
5156
|
+
}
|
|
5157
|
+
TypeCompiler2.Code = Code;
|
|
5158
|
+
function Compile(schema, references = []) {
|
|
5159
|
+
const generatedCode = Code(schema, references, { language: "javascript" });
|
|
5160
|
+
const compiledFunction = Evaluate("kind", "format", "hash", generatedCode);
|
|
5161
|
+
const instances = new Map(state.instances);
|
|
5162
|
+
function typeRegistryFunction(kind, instance, value) {
|
|
5163
|
+
if (!type_exports2.Has(kind) || !instances.has(instance))
|
|
5164
|
+
return false;
|
|
5165
|
+
const checkFunc = type_exports2.Get(kind);
|
|
5166
|
+
const schema2 = instances.get(instance);
|
|
5167
|
+
return checkFunc(schema2, value);
|
|
5168
|
+
}
|
|
5169
|
+
function formatRegistryFunction(format, value) {
|
|
5170
|
+
if (!format_exports.Has(format))
|
|
5171
|
+
return false;
|
|
5172
|
+
const checkFunc = format_exports.Get(format);
|
|
5173
|
+
return checkFunc(value);
|
|
5174
|
+
}
|
|
5175
|
+
function hashFunction(value) {
|
|
5176
|
+
return Hash(value);
|
|
5177
|
+
}
|
|
5178
|
+
const checkFunction = compiledFunction(typeRegistryFunction, formatRegistryFunction, hashFunction);
|
|
5179
|
+
return new TypeCheck(schema, references, checkFunction, generatedCode);
|
|
5180
|
+
}
|
|
5181
|
+
TypeCompiler2.Compile = Compile;
|
|
5182
|
+
})(TypeCompiler || (TypeCompiler = {}));
|
|
5183
|
+
var sessionRequest = TypeCompiler.Compile(SessionRequestSchema);
|
|
5184
|
+
var action = TypeCompiler.Compile(ActionSchema);
|
|
2931
5185
|
var ErrorCode;
|
|
2932
5186
|
(function(ErrorCode2) {
|
|
2933
5187
|
ErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
@@ -2953,13 +5207,269 @@ var ErrorCode;
|
|
|
2953
5207
|
ErrorCode2["OUTPUT_TRUNCATED"] = "OUTPUT_TRUNCATED";
|
|
2954
5208
|
ErrorCode2["INTERNAL"] = "INTERNAL";
|
|
2955
5209
|
})(ErrorCode || (ErrorCode = {}));
|
|
5210
|
+
var UsageError = class extends Error {
|
|
5211
|
+
constructor(message) {
|
|
5212
|
+
super(message);
|
|
5213
|
+
this.name = "UsageError";
|
|
5214
|
+
}
|
|
5215
|
+
};
|
|
5216
|
+
function formatErrorForUser(error2, staleHint) {
|
|
5217
|
+
if (error2 instanceof UsageError) {
|
|
5218
|
+
return error2.message;
|
|
5219
|
+
}
|
|
5220
|
+
if (error2 instanceof Error) {
|
|
5221
|
+
const code = error2.code;
|
|
5222
|
+
if (code === "STALE_TARGET" && staleHint) {
|
|
5223
|
+
return `${error2.message}
|
|
5224
|
+
|
|
5225
|
+
${staleHint}`;
|
|
5226
|
+
}
|
|
5227
|
+
return code && !error2.message.startsWith(code) ? `${code}: ${error2.message}` : error2.message;
|
|
5228
|
+
}
|
|
5229
|
+
return String(error2);
|
|
5230
|
+
}
|
|
5231
|
+
var AgentBrowserError = class extends Error {
|
|
5232
|
+
code;
|
|
5233
|
+
retryable;
|
|
5234
|
+
constructor(code, message, retryable = false) {
|
|
5235
|
+
super(`${code}: ${message}`);
|
|
5236
|
+
this.code = code;
|
|
5237
|
+
this.retryable = retryable;
|
|
5238
|
+
this.name = "AgentBrowserError";
|
|
5239
|
+
}
|
|
5240
|
+
};
|
|
5241
|
+
var SessionsClient = class {
|
|
5242
|
+
baseUrl;
|
|
5243
|
+
timeout;
|
|
5244
|
+
headers;
|
|
5245
|
+
requestFn;
|
|
5246
|
+
constructor(baseUrl, timeout, headers, requestFn) {
|
|
5247
|
+
this.baseUrl = baseUrl;
|
|
5248
|
+
this.timeout = timeout;
|
|
5249
|
+
this.headers = headers;
|
|
5250
|
+
this.requestFn = requestFn;
|
|
5251
|
+
}
|
|
5252
|
+
async create(request) {
|
|
5253
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions`, {
|
|
5254
|
+
method: "POST",
|
|
5255
|
+
headers: {
|
|
5256
|
+
"Content-Type": "application/json",
|
|
5257
|
+
...this.headers
|
|
5258
|
+
},
|
|
5259
|
+
body: JSON.stringify(request)
|
|
5260
|
+
});
|
|
5261
|
+
return this.handleResponse(response);
|
|
5262
|
+
}
|
|
5263
|
+
async get(sessionId) {
|
|
5264
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
5265
|
+
method: "GET",
|
|
5266
|
+
headers: this.headers
|
|
5267
|
+
});
|
|
5268
|
+
return this.handleResponse(response);
|
|
5269
|
+
}
|
|
5270
|
+
async list() {
|
|
5271
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions`, {
|
|
5272
|
+
method: "GET",
|
|
5273
|
+
headers: this.headers
|
|
5274
|
+
});
|
|
5275
|
+
const data = await this.handleResponse(response);
|
|
5276
|
+
return data.sessions;
|
|
5277
|
+
}
|
|
5278
|
+
async close(sessionId) {
|
|
5279
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
5280
|
+
method: "DELETE",
|
|
5281
|
+
headers: this.headers
|
|
5282
|
+
});
|
|
5283
|
+
await this.handleResponse(response);
|
|
5284
|
+
}
|
|
5285
|
+
async createPage(sessionId) {
|
|
5286
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages`, {
|
|
5287
|
+
method: "POST",
|
|
5288
|
+
headers: this.headers
|
|
5289
|
+
});
|
|
5290
|
+
return this.handleResponse(response);
|
|
5291
|
+
}
|
|
5292
|
+
async getPage(sessionId, pageId) {
|
|
5293
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}`, {
|
|
5294
|
+
method: "GET",
|
|
5295
|
+
headers: this.headers
|
|
5296
|
+
});
|
|
5297
|
+
return this.handleResponse(response);
|
|
5298
|
+
}
|
|
5299
|
+
async closePage(sessionId, pageId) {
|
|
5300
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}`, {
|
|
5301
|
+
method: "DELETE",
|
|
5302
|
+
headers: this.headers
|
|
5303
|
+
});
|
|
5304
|
+
await this.handleResponse(response);
|
|
5305
|
+
}
|
|
5306
|
+
/** TD-BROWSER-6: scoped cookie export — the read half of the credential handoff loop. */
|
|
5307
|
+
async cookies(sessionId) {
|
|
5308
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/cookies`, {
|
|
5309
|
+
headers: this.headers
|
|
5310
|
+
});
|
|
5311
|
+
const body = await this.handleResponse(response);
|
|
5312
|
+
return body.cookies;
|
|
5313
|
+
}
|
|
5314
|
+
/** TD-BROWSER-8: execute a batched action plan; returns per-step results. */
|
|
5315
|
+
async plan(sessionId, pageId, actions) {
|
|
5316
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/plan`, {
|
|
5317
|
+
method: "POST",
|
|
5318
|
+
headers: {
|
|
5319
|
+
"Content-Type": "application/json",
|
|
5320
|
+
...this.headers
|
|
5321
|
+
},
|
|
5322
|
+
body: JSON.stringify({ actions })
|
|
5323
|
+
});
|
|
5324
|
+
return this.handleResponse(response);
|
|
5325
|
+
}
|
|
5326
|
+
/** TD-BROWSER-8: self-contained snapshot payload for one-shot LLM reasoning. */
|
|
5327
|
+
async snapshot(sessionId, pageId) {
|
|
5328
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/snapshot`, { headers: this.headers });
|
|
5329
|
+
return this.handleResponse(response);
|
|
5330
|
+
}
|
|
5331
|
+
async navigate(sessionId, pageId, request) {
|
|
5332
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/navigate`, {
|
|
5333
|
+
method: "POST",
|
|
5334
|
+
headers: {
|
|
5335
|
+
"Content-Type": "application/json",
|
|
5336
|
+
...this.headers
|
|
5337
|
+
},
|
|
5338
|
+
body: JSON.stringify(request)
|
|
5339
|
+
});
|
|
5340
|
+
return this.handleResponse(response);
|
|
5341
|
+
}
|
|
5342
|
+
async observe(sessionId, pageId, request = {}) {
|
|
5343
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/observe`, {
|
|
5344
|
+
method: "POST",
|
|
5345
|
+
headers: {
|
|
5346
|
+
"Content-Type": "application/json",
|
|
5347
|
+
...this.headers
|
|
5348
|
+
},
|
|
5349
|
+
body: JSON.stringify(request)
|
|
5350
|
+
});
|
|
5351
|
+
return this.handleResponse(response);
|
|
5352
|
+
}
|
|
5353
|
+
async executeAction(sessionId, pageId, request) {
|
|
5354
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/act`, {
|
|
5355
|
+
method: "POST",
|
|
5356
|
+
headers: {
|
|
5357
|
+
"Content-Type": "application/json",
|
|
5358
|
+
...this.headers
|
|
5359
|
+
},
|
|
5360
|
+
body: JSON.stringify(request)
|
|
5361
|
+
});
|
|
5362
|
+
return this.handleResponse(response);
|
|
5363
|
+
}
|
|
5364
|
+
async screenshot(sessionId, pageId, request = {}) {
|
|
5365
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/screenshot`, {
|
|
5366
|
+
method: "POST",
|
|
5367
|
+
headers: {
|
|
5368
|
+
"Content-Type": "application/json",
|
|
5369
|
+
...this.headers
|
|
5370
|
+
},
|
|
5371
|
+
body: JSON.stringify(request)
|
|
5372
|
+
});
|
|
5373
|
+
return this.handleResponse(response);
|
|
5374
|
+
}
|
|
5375
|
+
async extract(sessionId, pageId, request) {
|
|
5376
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/extract`, {
|
|
5377
|
+
method: "POST",
|
|
5378
|
+
headers: {
|
|
5379
|
+
"Content-Type": "application/json",
|
|
5380
|
+
...this.headers
|
|
5381
|
+
},
|
|
5382
|
+
body: JSON.stringify(request)
|
|
5383
|
+
});
|
|
5384
|
+
return this.handleResponse(response);
|
|
5385
|
+
}
|
|
5386
|
+
async pdf(sessionId, pageId, request = {}) {
|
|
5387
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/pdf`, {
|
|
5388
|
+
method: "POST",
|
|
5389
|
+
headers: {
|
|
5390
|
+
"Content-Type": "application/json",
|
|
5391
|
+
...this.headers
|
|
5392
|
+
},
|
|
5393
|
+
body: JSON.stringify(request)
|
|
5394
|
+
});
|
|
5395
|
+
return this.handleResponse(response);
|
|
5396
|
+
}
|
|
5397
|
+
async handleResponse(response) {
|
|
5398
|
+
if (!response.ok) {
|
|
5399
|
+
let error2;
|
|
5400
|
+
try {
|
|
5401
|
+
const data = await response.json();
|
|
5402
|
+
error2 = data.error || {
|
|
5403
|
+
code: "UNKNOWN_ERROR",
|
|
5404
|
+
message: "Unknown error",
|
|
5405
|
+
retryable: false
|
|
5406
|
+
};
|
|
5407
|
+
} catch {
|
|
5408
|
+
error2 = {
|
|
5409
|
+
code: "UNKNOWN_ERROR",
|
|
5410
|
+
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
5411
|
+
retryable: false
|
|
5412
|
+
};
|
|
5413
|
+
}
|
|
5414
|
+
throw new AgentBrowserError(error2.code, error2.message, error2.retryable);
|
|
5415
|
+
}
|
|
5416
|
+
return response.json();
|
|
5417
|
+
}
|
|
5418
|
+
};
|
|
5419
|
+
var AgentBrowserClient = class {
|
|
5420
|
+
baseUrl;
|
|
5421
|
+
timeout;
|
|
5422
|
+
sessions;
|
|
5423
|
+
customHeaders;
|
|
5424
|
+
constructor(options = {}) {
|
|
5425
|
+
this.baseUrl = options.baseUrl || "http://localhost:3000";
|
|
5426
|
+
this.timeout = options.timeout || 3e4;
|
|
5427
|
+
this.customHeaders = {
|
|
5428
|
+
...options.apiKey !== void 0 ? { Authorization: `Bearer ${options.apiKey}` } : {},
|
|
5429
|
+
...options.headers
|
|
5430
|
+
};
|
|
5431
|
+
this.sessions = new SessionsClient(this.baseUrl, this.timeout, this.customHeaders, this.request.bind(this));
|
|
5432
|
+
}
|
|
5433
|
+
/**
|
|
5434
|
+
* Set default headers for all requests
|
|
5435
|
+
*/
|
|
5436
|
+
setHeaders(headers) {
|
|
5437
|
+
Object.assign(this.customHeaders, headers);
|
|
5438
|
+
}
|
|
5439
|
+
/**
|
|
5440
|
+
* Make an HTTP request with timeout
|
|
5441
|
+
*/
|
|
5442
|
+
async request(url, options = {}) {
|
|
5443
|
+
const controller = new AbortController();
|
|
5444
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
5445
|
+
try {
|
|
5446
|
+
const response = await fetch(url, {
|
|
5447
|
+
...options,
|
|
5448
|
+
signal: controller.signal
|
|
5449
|
+
});
|
|
5450
|
+
clearTimeout(timeoutId);
|
|
5451
|
+
return response;
|
|
5452
|
+
} catch (error2) {
|
|
5453
|
+
clearTimeout(timeoutId);
|
|
5454
|
+
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
5455
|
+
throw new AgentBrowserError("TIMEOUT", "Request timeout", false);
|
|
5456
|
+
}
|
|
5457
|
+
throw error2;
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
};
|
|
2956
5461
|
var PROTOCOL_VERSION = "2024-11-05";
|
|
2957
|
-
var REF_PATTERN = "^e\\d+_\\d+$";
|
|
2958
5462
|
function buildMcpServer(deps) {
|
|
2959
5463
|
const client = deps.createClient({ baseUrl: deps.baseUrl ?? "http://localhost:3000" });
|
|
2960
5464
|
const serverInfo = deps.serverInfo ?? { name: "agentbrowser", version: "1.0.0" };
|
|
2961
5465
|
const sessionAndPage = (args) => {
|
|
2962
|
-
|
|
5466
|
+
if (typeof args.sessionId !== "string" || args.sessionId.length === 0) {
|
|
5467
|
+
throw new UsageError("sessionId is required and must be a non-empty string.");
|
|
5468
|
+
}
|
|
5469
|
+
if (typeof args.pageId !== "string" || args.pageId.length === 0) {
|
|
5470
|
+
throw new UsageError("pageId is required and must be a non-empty string.");
|
|
5471
|
+
}
|
|
5472
|
+
return [args.sessionId, args.pageId];
|
|
2963
5473
|
};
|
|
2964
5474
|
const tools = [
|
|
2965
5475
|
{
|
|
@@ -2994,7 +5504,10 @@ function buildMcpServer(deps) {
|
|
|
2994
5504
|
required: ["tenantId"]
|
|
2995
5505
|
},
|
|
2996
5506
|
handler: async (args) => {
|
|
2997
|
-
|
|
5507
|
+
if (typeof args.tenantId !== "string" || args.tenantId.length === 0) {
|
|
5508
|
+
throw new UsageError("tenantId is required and must be a non-empty string.");
|
|
5509
|
+
}
|
|
5510
|
+
const request = { tenantId: args.tenantId };
|
|
2998
5511
|
if (typeof args.engine === "string")
|
|
2999
5512
|
request.engine = args.engine;
|
|
3000
5513
|
if (typeof args.headless === "boolean")
|
|
@@ -3017,9 +5530,51 @@ function buildMcpServer(deps) {
|
|
|
3017
5530
|
required: ["sessionId"]
|
|
3018
5531
|
},
|
|
3019
5532
|
handler: async (args) => {
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
5533
|
+
if (typeof args.sessionId !== "string" || args.sessionId.length === 0) {
|
|
5534
|
+
throw new UsageError("sessionId is required and must be a non-empty string.");
|
|
5535
|
+
}
|
|
5536
|
+
const cookies = await client.sessions.cookies(args.sessionId);
|
|
5537
|
+
return { sessionId: args.sessionId, cookies };
|
|
5538
|
+
}
|
|
5539
|
+
},
|
|
5540
|
+
{
|
|
5541
|
+
name: "browser_snapshot",
|
|
5542
|
+
description: "Get a self-contained page snapshot for one-shot plan construction (TD-BROWSER-8): url, title, revision, an adaptive `mode` (stable|verified - verified means recent ref churn was detected and browser_plan will require a stricter role+label match before self-healing a stale ref), and fields ({ref, role, label}) to address in a browser_plan call. Prefer browser_snapshot + browser_plan over repeated browser_observe/browser_act round-trips when filling multi-field forms.",
|
|
5543
|
+
inputSchema: {
|
|
5544
|
+
type: "object",
|
|
5545
|
+
properties: {
|
|
5546
|
+
sessionId: { type: "string" },
|
|
5547
|
+
pageId: { type: "string" }
|
|
5548
|
+
},
|
|
5549
|
+
required: ["sessionId", "pageId"]
|
|
5550
|
+
},
|
|
5551
|
+
handler: async (args) => {
|
|
5552
|
+
const [sessionId, pageId] = sessionAndPage(args);
|
|
5553
|
+
return await client.sessions.snapshot(sessionId, pageId);
|
|
5554
|
+
}
|
|
5555
|
+
},
|
|
5556
|
+
{
|
|
5557
|
+
name: "browser_plan",
|
|
5558
|
+
description: "Execute a batched action plan in one call (TD-BROWSER-8). Each action: {action: fill|click|press|scroll, target?: {ref}, value?, key?}. Steps run sequentially; the first hard failure aborts with per-step results. Best paired with browser_snapshot: address refs from its `fields` in one round trip.",
|
|
5559
|
+
inputSchema: {
|
|
5560
|
+
type: "object",
|
|
5561
|
+
properties: {
|
|
5562
|
+
sessionId: { type: "string" },
|
|
5563
|
+
pageId: { type: "string" },
|
|
5564
|
+
actions: {
|
|
5565
|
+
type: "array",
|
|
5566
|
+
description: "Ordered plan steps: {action, target?: {ref}, value?, key?}",
|
|
5567
|
+
items: { type: "object" }
|
|
5568
|
+
}
|
|
5569
|
+
},
|
|
5570
|
+
required: ["sessionId", "pageId", "actions"]
|
|
5571
|
+
},
|
|
5572
|
+
handler: async (args) => {
|
|
5573
|
+
const [sessionId, pageId] = sessionAndPage(args);
|
|
5574
|
+
if (!Array.isArray(args.actions)) {
|
|
5575
|
+
throw new UsageError("actions is required and must be an array of plan steps.");
|
|
5576
|
+
}
|
|
5577
|
+
return await client.sessions.plan(sessionId, pageId, args.actions);
|
|
3023
5578
|
}
|
|
3024
5579
|
},
|
|
3025
5580
|
{
|
|
@@ -3031,8 +5586,11 @@ function buildMcpServer(deps) {
|
|
|
3031
5586
|
required: ["sessionId"]
|
|
3032
5587
|
},
|
|
3033
5588
|
handler: async (args) => {
|
|
3034
|
-
|
|
3035
|
-
|
|
5589
|
+
if (typeof args.sessionId !== "string" || args.sessionId.length === 0) {
|
|
5590
|
+
throw new UsageError("sessionId is required and must be a non-empty string.");
|
|
5591
|
+
}
|
|
5592
|
+
await client.sessions.close(args.sessionId);
|
|
5593
|
+
return { sessionId: args.sessionId, closed: true };
|
|
3036
5594
|
}
|
|
3037
5595
|
},
|
|
3038
5596
|
{
|
|
@@ -3099,7 +5657,7 @@ function buildMcpServer(deps) {
|
|
|
3099
5657
|
},
|
|
3100
5658
|
{
|
|
3101
5659
|
name: "browser_act",
|
|
3102
|
-
description: "Perform an action on an element by ref: click, fill, select, scroll or
|
|
5660
|
+
description: "Perform an action on an element by ref: click, dblclick, hover, fill, clear, check, uncheck, select, scroll, press, wait, goBack, goForward, reload, or handle a dialog. Elements are addressed by the ref from browser_observe, never by CSS selector or XPath. If the page changed since the observation, the action fails with STALE_TARGET: call browser_observe again and use the new refs; do not retry the old one.",
|
|
3103
5661
|
inputSchema: {
|
|
3104
5662
|
type: "object",
|
|
3105
5663
|
properties: {
|
|
@@ -3114,7 +5672,7 @@ function buildMcpServer(deps) {
|
|
|
3114
5672
|
properties: {
|
|
3115
5673
|
ref: {
|
|
3116
5674
|
type: "string",
|
|
3117
|
-
pattern: REF_PATTERN,
|
|
5675
|
+
pattern: REF_PATTERN.source,
|
|
3118
5676
|
description: "Element ref from browser_observe, e.g. e1_0."
|
|
3119
5677
|
}
|
|
3120
5678
|
},
|
|
@@ -3123,16 +5681,35 @@ function buildMcpServer(deps) {
|
|
|
3123
5681
|
value: { type: "string", description: "Value for fill/select." },
|
|
3124
5682
|
key: { type: "string", description: "Key for press." },
|
|
3125
5683
|
direction: { type: "string", enum: ["up", "down", "left", "right"] },
|
|
3126
|
-
amount: { type: "number" }
|
|
5684
|
+
amount: { type: "number" },
|
|
5685
|
+
condition: {
|
|
5686
|
+
type: "object",
|
|
5687
|
+
description: 'Wait-action condition (action: "wait" only).',
|
|
5688
|
+
properties: {
|
|
5689
|
+
until: {
|
|
5690
|
+
type: "string",
|
|
5691
|
+
enum: ["settled", "domcontentloaded", "load", "networkidle"]
|
|
5692
|
+
},
|
|
5693
|
+
timeoutMs: { type: "number" }
|
|
5694
|
+
},
|
|
5695
|
+
required: ["until"]
|
|
5696
|
+
}
|
|
3127
5697
|
},
|
|
3128
5698
|
required: ["sessionId", "pageId", "action"]
|
|
3129
5699
|
},
|
|
3130
5700
|
handler: async (args) => {
|
|
3131
5701
|
const [sessionId, pageId] = sessionAndPage(args);
|
|
3132
5702
|
const target = args.target ?? {};
|
|
3133
|
-
const
|
|
5703
|
+
const UNTARGETED_ACTIONS = /* @__PURE__ */ new Set([
|
|
5704
|
+
"acceptDialog",
|
|
5705
|
+
"dismissDialog",
|
|
5706
|
+
"wait",
|
|
5707
|
+
"goBack",
|
|
5708
|
+
"goForward",
|
|
5709
|
+
"reload"
|
|
5710
|
+
]);
|
|
3134
5711
|
const ref = target.ref;
|
|
3135
|
-
if (!
|
|
5712
|
+
if (!UNTARGETED_ACTIONS.has(String(args.action)) && (typeof ref !== "string" || !REF_PATTERN.test(ref))) {
|
|
3136
5713
|
throw new UsageError(`Invalid element reference '${String(ref)}'. Expected a ref of the form e<revision>_<ordinal>, such as e1_0. Call browser_observe to list current refs.`);
|
|
3137
5714
|
}
|
|
3138
5715
|
const request = {
|
|
@@ -3147,6 +5724,9 @@ function buildMcpServer(deps) {
|
|
|
3147
5724
|
request.direction = args.direction;
|
|
3148
5725
|
if (typeof args.amount === "number")
|
|
3149
5726
|
request.amount = args.amount;
|
|
5727
|
+
if (args.condition !== void 0 && typeof args.condition === "object") {
|
|
5728
|
+
request.condition = args.condition;
|
|
5729
|
+
}
|
|
3150
5730
|
return await client.sessions.executeAction(sessionId, pageId, request);
|
|
3151
5731
|
}
|
|
3152
5732
|
},
|
|
@@ -3160,8 +5740,12 @@ function buildMcpServer(deps) {
|
|
|
3160
5740
|
pageId: { type: "string" },
|
|
3161
5741
|
format: {
|
|
3162
5742
|
type: "string",
|
|
3163
|
-
enum: [
|
|
5743
|
+
enum: [...DELIVERED_EXTRACT_FORMATS],
|
|
3164
5744
|
description: "What to extract (default: text)."
|
|
5745
|
+
},
|
|
5746
|
+
schema: {
|
|
5747
|
+
type: "object",
|
|
5748
|
+
description: 'JSON Schema constraining the extraction (format: "schema" only): properties to pick, with type/description/enum constraints.'
|
|
3165
5749
|
}
|
|
3166
5750
|
},
|
|
3167
5751
|
required: ["sessionId", "pageId", "format"]
|
|
@@ -3169,13 +5753,15 @@ function buildMcpServer(deps) {
|
|
|
3169
5753
|
handler: async (args) => {
|
|
3170
5754
|
const [sessionId, pageId] = sessionAndPage(args);
|
|
3171
5755
|
const format = args.format;
|
|
3172
|
-
const supported =
|
|
5756
|
+
const supported = DELIVERED_EXTRACT_FORMATS;
|
|
3173
5757
|
if (typeof format !== "string" || !supported.includes(format)) {
|
|
3174
5758
|
throw new UsageError(`Unknown extraction format '${String(format)}'. Supported: ${supported.join(", ")}.`);
|
|
3175
5759
|
}
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
5760
|
+
const request = { format };
|
|
5761
|
+
if (args.schema !== void 0 && typeof args.schema === "object") {
|
|
5762
|
+
request.schema = args.schema;
|
|
5763
|
+
}
|
|
5764
|
+
return await client.sessions.extract(sessionId, pageId, request);
|
|
3179
5765
|
}
|
|
3180
5766
|
},
|
|
3181
5767
|
{
|
|
@@ -3279,8 +5865,6 @@ function buildMcpServer(deps) {
|
|
|
3279
5865
|
}
|
|
3280
5866
|
};
|
|
3281
5867
|
}
|
|
3282
|
-
var UsageError = class extends Error {
|
|
3283
|
-
};
|
|
3284
5868
|
function requireHttpUrl(value) {
|
|
3285
5869
|
const url = typeof value === "string" ? value : "";
|
|
3286
5870
|
if (!/^https?:\/\//.test(url)) {
|
|
@@ -3300,19 +5884,7 @@ function errorResult(message) {
|
|
|
3300
5884
|
};
|
|
3301
5885
|
}
|
|
3302
5886
|
function formatToolError(error2) {
|
|
3303
|
-
|
|
3304
|
-
return error2.message;
|
|
3305
|
-
}
|
|
3306
|
-
if (error2 instanceof Error) {
|
|
3307
|
-
const code = error2.code;
|
|
3308
|
-
if (code === "STALE_TARGET") {
|
|
3309
|
-
return `${error2.message}
|
|
3310
|
-
|
|
3311
|
-
The element ref is stale. Call browser_observe to get fresh refs at the current revision, then act on the new ref. Do not retry the old one.`;
|
|
3312
|
-
}
|
|
3313
|
-
return code && !error2.message.startsWith(code) ? `${code}: ${error2.message}` : error2.message;
|
|
3314
|
-
}
|
|
3315
|
-
return String(error2);
|
|
5887
|
+
return formatErrorForUser(error2, "The element ref is stale. Call browser_observe to get fresh refs at the current revision, then act on the new ref. Do not retry the old one.");
|
|
3316
5888
|
}
|
|
3317
5889
|
function ok(id, result) {
|
|
3318
5890
|
return JSON.stringify({ jsonrpc: "2.0", id, result });
|