@anvailabs/agentbrowser-mcp 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +2922 -415
- package/dist/index.js +2755 -254
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +53 -31
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -10,236 +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
|
-
/** TD-BROWSER-8: execute a batched action plan; returns per-step results. */
|
|
97
|
-
async plan(sessionId, pageId, actions) {
|
|
98
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/plan`, {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
...this.headers
|
|
103
|
-
},
|
|
104
|
-
body: JSON.stringify({ actions })
|
|
105
|
-
});
|
|
106
|
-
return this.handleResponse(response);
|
|
107
|
-
}
|
|
108
|
-
/** TD-BROWSER-8: self-contained snapshot payload for one-shot LLM reasoning. */
|
|
109
|
-
async snapshot(sessionId, pageId) {
|
|
110
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/snapshot`, { headers: this.headers });
|
|
111
|
-
return this.handleResponse(response);
|
|
112
|
-
}
|
|
113
|
-
async navigate(sessionId, pageId, request) {
|
|
114
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/navigate`, {
|
|
115
|
-
method: "POST",
|
|
116
|
-
headers: {
|
|
117
|
-
"Content-Type": "application/json",
|
|
118
|
-
...this.headers
|
|
119
|
-
},
|
|
120
|
-
body: JSON.stringify(request)
|
|
121
|
-
});
|
|
122
|
-
return this.handleResponse(response);
|
|
123
|
-
}
|
|
124
|
-
async observe(sessionId, pageId, request = {}) {
|
|
125
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/observe`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
headers: {
|
|
128
|
-
"Content-Type": "application/json",
|
|
129
|
-
...this.headers
|
|
130
|
-
},
|
|
131
|
-
body: JSON.stringify(request)
|
|
132
|
-
});
|
|
133
|
-
return this.handleResponse(response);
|
|
134
|
-
}
|
|
135
|
-
async executeAction(sessionId, pageId, request) {
|
|
136
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/act`, {
|
|
137
|
-
method: "POST",
|
|
138
|
-
headers: {
|
|
139
|
-
"Content-Type": "application/json",
|
|
140
|
-
...this.headers
|
|
141
|
-
},
|
|
142
|
-
body: JSON.stringify(request)
|
|
143
|
-
});
|
|
144
|
-
return this.handleResponse(response);
|
|
145
|
-
}
|
|
146
|
-
async screenshot(sessionId, pageId, request = {}) {
|
|
147
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/screenshot`, {
|
|
148
|
-
method: "POST",
|
|
149
|
-
headers: {
|
|
150
|
-
"Content-Type": "application/json",
|
|
151
|
-
...this.headers
|
|
152
|
-
},
|
|
153
|
-
body: JSON.stringify(request)
|
|
154
|
-
});
|
|
155
|
-
return this.handleResponse(response);
|
|
156
|
-
}
|
|
157
|
-
async extract(sessionId, pageId, request) {
|
|
158
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/extract`, {
|
|
159
|
-
method: "POST",
|
|
160
|
-
headers: {
|
|
161
|
-
"Content-Type": "application/json",
|
|
162
|
-
...this.headers
|
|
163
|
-
},
|
|
164
|
-
body: JSON.stringify(request)
|
|
165
|
-
});
|
|
166
|
-
return this.handleResponse(response);
|
|
167
|
-
}
|
|
168
|
-
async pdf(sessionId, pageId, request = {}) {
|
|
169
|
-
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/pdf`, {
|
|
170
|
-
method: "POST",
|
|
171
|
-
headers: {
|
|
172
|
-
"Content-Type": "application/json",
|
|
173
|
-
...this.headers
|
|
174
|
-
},
|
|
175
|
-
body: JSON.stringify(request)
|
|
176
|
-
});
|
|
177
|
-
return this.handleResponse(response);
|
|
178
|
-
}
|
|
179
|
-
async handleResponse(response) {
|
|
180
|
-
if (!response.ok) {
|
|
181
|
-
let error2;
|
|
182
|
-
try {
|
|
183
|
-
const data = await response.json();
|
|
184
|
-
error2 = data.error || {
|
|
185
|
-
code: "UNKNOWN_ERROR",
|
|
186
|
-
message: "Unknown error",
|
|
187
|
-
retryable: false
|
|
188
|
-
};
|
|
189
|
-
} catch {
|
|
190
|
-
error2 = {
|
|
191
|
-
code: "UNKNOWN_ERROR",
|
|
192
|
-
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
193
|
-
retryable: false
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
throw new AgentBrowserError(error2.code, error2.message, error2.retryable);
|
|
197
|
-
}
|
|
198
|
-
return response.json();
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var AgentBrowserClient = class {
|
|
202
|
-
baseUrl;
|
|
203
|
-
timeout;
|
|
204
|
-
sessions;
|
|
205
|
-
customHeaders;
|
|
206
|
-
constructor(options = {}) {
|
|
207
|
-
this.baseUrl = options.baseUrl || "http://localhost:3000";
|
|
208
|
-
this.timeout = options.timeout || 3e4;
|
|
209
|
-
this.customHeaders = {
|
|
210
|
-
...options.apiKey !== void 0 ? { Authorization: `Bearer ${options.apiKey}` } : {},
|
|
211
|
-
...options.headers
|
|
212
|
-
};
|
|
213
|
-
this.sessions = new SessionsClient(this.baseUrl, this.timeout, this.customHeaders, this.request.bind(this));
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Set default headers for all requests
|
|
217
|
-
*/
|
|
218
|
-
setHeaders(headers) {
|
|
219
|
-
Object.assign(this.customHeaders, headers);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Make an HTTP request with timeout
|
|
223
|
-
*/
|
|
224
|
-
async request(url, options = {}) {
|
|
225
|
-
const controller = new AbortController();
|
|
226
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
227
|
-
try {
|
|
228
|
-
const response = await fetch(url, {
|
|
229
|
-
...options,
|
|
230
|
-
signal: controller.signal
|
|
231
|
-
});
|
|
232
|
-
clearTimeout(timeoutId);
|
|
233
|
-
return response;
|
|
234
|
-
} catch (error2) {
|
|
235
|
-
clearTimeout(timeoutId);
|
|
236
|
-
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
237
|
-
throw new AgentBrowserError("TIMEOUT", "Request timeout", false);
|
|
238
|
-
}
|
|
239
|
-
throw error2;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
13
|
var value_exports = {};
|
|
244
14
|
__export(value_exports, {
|
|
245
15
|
HasPropertyKey: () => HasPropertyKey,
|
|
@@ -338,6 +108,24 @@ function Clone(value) {
|
|
|
338
108
|
function CloneType(schema, options) {
|
|
339
109
|
return options === void 0 ? Clone(schema) : Clone({ ...options, ...schema });
|
|
340
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
|
+
}
|
|
341
129
|
function IsObject2(value) {
|
|
342
130
|
return value !== null && typeof value === "object";
|
|
343
131
|
}
|
|
@@ -347,18 +135,42 @@ function IsArray2(value) {
|
|
|
347
135
|
function IsUndefined2(value) {
|
|
348
136
|
return value === void 0;
|
|
349
137
|
}
|
|
138
|
+
function IsNull2(value) {
|
|
139
|
+
return value === null;
|
|
140
|
+
}
|
|
141
|
+
function IsBoolean2(value) {
|
|
142
|
+
return typeof value === "boolean";
|
|
143
|
+
}
|
|
350
144
|
function IsNumber2(value) {
|
|
351
145
|
return typeof value === "number";
|
|
352
146
|
}
|
|
353
|
-
|
|
354
|
-
(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
+
}
|
|
165
|
+
var TypeSystemPolicy;
|
|
166
|
+
(function(TypeSystemPolicy2) {
|
|
167
|
+
TypeSystemPolicy2.InstanceMode = "default";
|
|
168
|
+
TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
|
|
169
|
+
TypeSystemPolicy2.AllowArrayObject = false;
|
|
170
|
+
TypeSystemPolicy2.AllowNaN = false;
|
|
171
|
+
TypeSystemPolicy2.AllowNullVoid = false;
|
|
172
|
+
function IsExactOptionalProperty(value, key) {
|
|
173
|
+
return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
|
|
362
174
|
}
|
|
363
175
|
TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
|
|
364
176
|
function IsObjectLike(value) {
|
|
@@ -441,13 +253,13 @@ function IsArgument(value) {
|
|
|
441
253
|
function IsArray3(value) {
|
|
442
254
|
return IsKindOf(value, "Array");
|
|
443
255
|
}
|
|
444
|
-
function
|
|
256
|
+
function IsAsyncIterator3(value) {
|
|
445
257
|
return IsKindOf(value, "AsyncIterator");
|
|
446
258
|
}
|
|
447
|
-
function
|
|
259
|
+
function IsBigInt3(value) {
|
|
448
260
|
return IsKindOf(value, "BigInt");
|
|
449
261
|
}
|
|
450
|
-
function
|
|
262
|
+
function IsBoolean3(value) {
|
|
451
263
|
return IsKindOf(value, "Boolean");
|
|
452
264
|
}
|
|
453
265
|
function IsComputed(value) {
|
|
@@ -456,19 +268,19 @@ function IsComputed(value) {
|
|
|
456
268
|
function IsConstructor(value) {
|
|
457
269
|
return IsKindOf(value, "Constructor");
|
|
458
270
|
}
|
|
459
|
-
function
|
|
271
|
+
function IsDate3(value) {
|
|
460
272
|
return IsKindOf(value, "Date");
|
|
461
273
|
}
|
|
462
|
-
function
|
|
274
|
+
function IsFunction3(value) {
|
|
463
275
|
return IsKindOf(value, "Function");
|
|
464
276
|
}
|
|
465
|
-
function
|
|
277
|
+
function IsInteger2(value) {
|
|
466
278
|
return IsKindOf(value, "Integer");
|
|
467
279
|
}
|
|
468
280
|
function IsIntersect(value) {
|
|
469
281
|
return IsKindOf(value, "Intersect");
|
|
470
282
|
}
|
|
471
|
-
function
|
|
283
|
+
function IsIterator3(value) {
|
|
472
284
|
return IsKindOf(value, "Iterator");
|
|
473
285
|
}
|
|
474
286
|
function IsKindOf(value, kind) {
|
|
@@ -492,7 +304,7 @@ function IsNever(value) {
|
|
|
492
304
|
function IsNot(value) {
|
|
493
305
|
return IsKindOf(value, "Not");
|
|
494
306
|
}
|
|
495
|
-
function
|
|
307
|
+
function IsNull3(value) {
|
|
496
308
|
return IsKindOf(value, "Null");
|
|
497
309
|
}
|
|
498
310
|
function IsNumber3(value) {
|
|
@@ -501,7 +313,7 @@ function IsNumber3(value) {
|
|
|
501
313
|
function IsObject3(value) {
|
|
502
314
|
return IsKindOf(value, "Object");
|
|
503
315
|
}
|
|
504
|
-
function
|
|
316
|
+
function IsPromise2(value) {
|
|
505
317
|
return IsKindOf(value, "Promise");
|
|
506
318
|
}
|
|
507
319
|
function IsRecord(value) {
|
|
@@ -513,10 +325,10 @@ function IsRef(value) {
|
|
|
513
325
|
function IsRegExp2(value) {
|
|
514
326
|
return IsKindOf(value, "RegExp");
|
|
515
327
|
}
|
|
516
|
-
function
|
|
328
|
+
function IsString3(value) {
|
|
517
329
|
return IsKindOf(value, "String");
|
|
518
330
|
}
|
|
519
|
-
function
|
|
331
|
+
function IsSymbol3(value) {
|
|
520
332
|
return IsKindOf(value, "Symbol");
|
|
521
333
|
}
|
|
522
334
|
function IsTemplateLiteral(value) {
|
|
@@ -537,7 +349,7 @@ function IsUndefined3(value) {
|
|
|
537
349
|
function IsUnion(value) {
|
|
538
350
|
return IsKindOf(value, "Union");
|
|
539
351
|
}
|
|
540
|
-
function
|
|
352
|
+
function IsUint8Array3(value) {
|
|
541
353
|
return IsKindOf(value, "Uint8Array");
|
|
542
354
|
}
|
|
543
355
|
function IsUnknown(value) {
|
|
@@ -553,24 +365,24 @@ function IsKind(value) {
|
|
|
553
365
|
return IsObject(value) && Kind in value && IsString(value[Kind]);
|
|
554
366
|
}
|
|
555
367
|
function IsSchema(value) {
|
|
556
|
-
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);
|
|
557
369
|
}
|
|
558
370
|
var type_exports = {};
|
|
559
371
|
__export(type_exports, {
|
|
560
372
|
IsAny: () => IsAny2,
|
|
561
373
|
IsArgument: () => IsArgument2,
|
|
562
374
|
IsArray: () => IsArray4,
|
|
563
|
-
IsAsyncIterator: () =>
|
|
564
|
-
IsBigInt: () =>
|
|
565
|
-
IsBoolean: () =>
|
|
375
|
+
IsAsyncIterator: () => IsAsyncIterator4,
|
|
376
|
+
IsBigInt: () => IsBigInt4,
|
|
377
|
+
IsBoolean: () => IsBoolean4,
|
|
566
378
|
IsComputed: () => IsComputed2,
|
|
567
379
|
IsConstructor: () => IsConstructor2,
|
|
568
|
-
IsDate: () =>
|
|
569
|
-
IsFunction: () =>
|
|
380
|
+
IsDate: () => IsDate4,
|
|
381
|
+
IsFunction: () => IsFunction4,
|
|
570
382
|
IsImport: () => IsImport,
|
|
571
|
-
IsInteger: () =>
|
|
383
|
+
IsInteger: () => IsInteger3,
|
|
572
384
|
IsIntersect: () => IsIntersect2,
|
|
573
|
-
IsIterator: () =>
|
|
385
|
+
IsIterator: () => IsIterator4,
|
|
574
386
|
IsKind: () => IsKind2,
|
|
575
387
|
IsKindOf: () => IsKindOf2,
|
|
576
388
|
IsLiteral: () => IsLiteral2,
|
|
@@ -582,11 +394,11 @@ __export(type_exports, {
|
|
|
582
394
|
IsMappedResult: () => IsMappedResult2,
|
|
583
395
|
IsNever: () => IsNever2,
|
|
584
396
|
IsNot: () => IsNot2,
|
|
585
|
-
IsNull: () =>
|
|
397
|
+
IsNull: () => IsNull4,
|
|
586
398
|
IsNumber: () => IsNumber4,
|
|
587
399
|
IsObject: () => IsObject4,
|
|
588
400
|
IsOptional: () => IsOptional2,
|
|
589
|
-
IsPromise: () =>
|
|
401
|
+
IsPromise: () => IsPromise3,
|
|
590
402
|
IsProperties: () => IsProperties,
|
|
591
403
|
IsReadonly: () => IsReadonly2,
|
|
592
404
|
IsRecord: () => IsRecord2,
|
|
@@ -594,13 +406,13 @@ __export(type_exports, {
|
|
|
594
406
|
IsRef: () => IsRef2,
|
|
595
407
|
IsRegExp: () => IsRegExp3,
|
|
596
408
|
IsSchema: () => IsSchema2,
|
|
597
|
-
IsString: () =>
|
|
598
|
-
IsSymbol: () =>
|
|
409
|
+
IsString: () => IsString4,
|
|
410
|
+
IsSymbol: () => IsSymbol4,
|
|
599
411
|
IsTemplateLiteral: () => IsTemplateLiteral2,
|
|
600
412
|
IsThis: () => IsThis2,
|
|
601
413
|
IsTransform: () => IsTransform2,
|
|
602
414
|
IsTuple: () => IsTuple2,
|
|
603
|
-
IsUint8Array: () =>
|
|
415
|
+
IsUint8Array: () => IsUint8Array4,
|
|
604
416
|
IsUndefined: () => IsUndefined4,
|
|
605
417
|
IsUnion: () => IsUnion2,
|
|
606
418
|
IsUnionLiteral: () => IsUnionLiteral,
|
|
@@ -706,13 +518,13 @@ function IsArgument2(value) {
|
|
|
706
518
|
function IsArray4(value) {
|
|
707
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);
|
|
708
520
|
}
|
|
709
|
-
function
|
|
521
|
+
function IsAsyncIterator4(value) {
|
|
710
522
|
return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
711
523
|
}
|
|
712
|
-
function
|
|
524
|
+
function IsBigInt4(value) {
|
|
713
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);
|
|
714
526
|
}
|
|
715
|
-
function
|
|
527
|
+
function IsBoolean4(value) {
|
|
716
528
|
return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
|
|
717
529
|
}
|
|
718
530
|
function IsComputed2(value) {
|
|
@@ -721,16 +533,16 @@ function IsComputed2(value) {
|
|
|
721
533
|
function IsConstructor2(value) {
|
|
722
534
|
return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
723
535
|
}
|
|
724
|
-
function
|
|
536
|
+
function IsDate4(value) {
|
|
725
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);
|
|
726
538
|
}
|
|
727
|
-
function
|
|
539
|
+
function IsFunction4(value) {
|
|
728
540
|
return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
729
541
|
}
|
|
730
542
|
function IsImport(value) {
|
|
731
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;
|
|
732
544
|
}
|
|
733
|
-
function
|
|
545
|
+
function IsInteger3(value) {
|
|
734
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);
|
|
735
547
|
}
|
|
736
548
|
function IsProperties(value) {
|
|
@@ -739,7 +551,7 @@ function IsProperties(value) {
|
|
|
739
551
|
function IsIntersect2(value) {
|
|
740
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);
|
|
741
553
|
}
|
|
742
|
-
function
|
|
554
|
+
function IsIterator4(value) {
|
|
743
555
|
return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
744
556
|
}
|
|
745
557
|
function IsKindOf2(value, kind) {
|
|
@@ -772,7 +584,7 @@ function IsNever2(value) {
|
|
|
772
584
|
function IsNot2(value) {
|
|
773
585
|
return IsKindOf2(value, "Not") && IsSchema2(value.not);
|
|
774
586
|
}
|
|
775
|
-
function
|
|
587
|
+
function IsNull4(value) {
|
|
776
588
|
return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
|
|
777
589
|
}
|
|
778
590
|
function IsNumber4(value) {
|
|
@@ -781,7 +593,7 @@ function IsNumber4(value) {
|
|
|
781
593
|
function IsObject4(value) {
|
|
782
594
|
return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
|
|
783
595
|
}
|
|
784
|
-
function
|
|
596
|
+
function IsPromise3(value) {
|
|
785
597
|
return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
|
|
786
598
|
}
|
|
787
599
|
function IsRecord2(value) {
|
|
@@ -799,10 +611,10 @@ function IsRef2(value) {
|
|
|
799
611
|
function IsRegExp3(value) {
|
|
800
612
|
return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
|
|
801
613
|
}
|
|
802
|
-
function
|
|
614
|
+
function IsString4(value) {
|
|
803
615
|
return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
|
|
804
616
|
}
|
|
805
|
-
function
|
|
617
|
+
function IsSymbol4(value) {
|
|
806
618
|
return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
|
|
807
619
|
}
|
|
808
620
|
function IsTemplateLiteral2(value) {
|
|
@@ -827,7 +639,7 @@ function IsUnionLiteral(value) {
|
|
|
827
639
|
function IsUnion2(value) {
|
|
828
640
|
return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
|
|
829
641
|
}
|
|
830
|
-
function
|
|
642
|
+
function IsUint8Array4(value) {
|
|
831
643
|
return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
|
|
832
644
|
}
|
|
833
645
|
function IsUnknown2(value) {
|
|
@@ -843,7 +655,7 @@ function IsKind2(value) {
|
|
|
843
655
|
return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
844
656
|
}
|
|
845
657
|
function IsSchema2(value) {
|
|
846
|
-
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));
|
|
847
659
|
}
|
|
848
660
|
var PatternBoolean = "(true|false)";
|
|
849
661
|
var PatternNumber = "(0|[1-9][0-9]*)";
|
|
@@ -853,6 +665,62 @@ var PatternBooleanExact = `^${PatternBoolean}$`;
|
|
|
853
665
|
var PatternNumberExact = `^${PatternNumber}$`;
|
|
854
666
|
var PatternStringExact = `^${PatternString}$`;
|
|
855
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
|
+
}
|
|
856
724
|
function SetIncludes(T, S) {
|
|
857
725
|
return T.includes(S);
|
|
858
726
|
}
|
|
@@ -1117,7 +985,7 @@ function Literal(value, options) {
|
|
|
1117
985
|
function Boolean2(options) {
|
|
1118
986
|
return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
|
|
1119
987
|
}
|
|
1120
|
-
function
|
|
988
|
+
function BigInt2(options) {
|
|
1121
989
|
return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
|
|
1122
990
|
}
|
|
1123
991
|
function Number2(options) {
|
|
@@ -1128,7 +996,7 @@ function String2(options) {
|
|
|
1128
996
|
}
|
|
1129
997
|
function* FromUnion(syntax) {
|
|
1130
998
|
const trim = syntax.trim().replace(/"|'/g, "");
|
|
1131
|
-
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 (() => {
|
|
1132
1000
|
const literals = trim.split("|").map((literal) => Literal(literal.trim()));
|
|
1133
1001
|
return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
|
|
1134
1002
|
})();
|
|
@@ -1167,7 +1035,7 @@ function Escape(value) {
|
|
|
1167
1035
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1168
1036
|
}
|
|
1169
1037
|
function Visit2(schema, acc) {
|
|
1170
|
-
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}` : (() => {
|
|
1171
1039
|
throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
|
|
1172
1040
|
})();
|
|
1173
1041
|
}
|
|
@@ -1197,7 +1065,7 @@ function FromLiteral(literalValue) {
|
|
|
1197
1065
|
return [literalValue.toString()];
|
|
1198
1066
|
}
|
|
1199
1067
|
function IndexPropertyKeys(type) {
|
|
1200
|
-
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]"] : [])];
|
|
1201
1069
|
}
|
|
1202
1070
|
function FromProperties(type, properties, options) {
|
|
1203
1071
|
const result = {};
|
|
@@ -1354,7 +1222,7 @@ function FromSchemaType(K, T) {
|
|
|
1354
1222
|
// unevaluated mapped types
|
|
1355
1223
|
IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
|
|
1356
1224
|
// unevaluated types
|
|
1357
|
-
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
|
|
1358
1226
|
)
|
|
1359
1227
|
)
|
|
1360
1228
|
);
|
|
@@ -1365,9 +1233,9 @@ function MappedFunctionReturnType(K, T) {
|
|
|
1365
1233
|
Acc[L] = FromSchemaType(L, T);
|
|
1366
1234
|
return Acc;
|
|
1367
1235
|
}
|
|
1368
|
-
function Mapped(key,
|
|
1236
|
+
function Mapped(key, map3, options) {
|
|
1369
1237
|
const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
1370
|
-
const RT =
|
|
1238
|
+
const RT = map3({ [Kind]: "MappedKey", keys: K });
|
|
1371
1239
|
const R = MappedFunctionReturnType(K, RT);
|
|
1372
1240
|
return Object2(R, options);
|
|
1373
1241
|
}
|
|
@@ -1457,7 +1325,7 @@ function FromRest3(types) {
|
|
|
1457
1325
|
return types.map((type) => Awaited(type));
|
|
1458
1326
|
}
|
|
1459
1327
|
function Awaited(type, options) {
|
|
1460
|
-
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);
|
|
1461
1329
|
}
|
|
1462
1330
|
function FromRest4(types) {
|
|
1463
1331
|
const result = [];
|
|
@@ -1496,6 +1364,13 @@ function KeyOfPropertyKeys(type) {
|
|
|
1496
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) : [];
|
|
1497
1365
|
}
|
|
1498
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
|
+
}
|
|
1499
1374
|
function FromComputed2(target, parameters) {
|
|
1500
1375
|
return Computed("KeyOf", [Computed(target, parameters)]);
|
|
1501
1376
|
}
|
|
@@ -1527,6 +1402,11 @@ function KeyOfFromMappedResult(mappedResult, options) {
|
|
|
1527
1402
|
const properties = FromMappedResult5(mappedResult, options);
|
|
1528
1403
|
return MappedResult(properties);
|
|
1529
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
|
+
}
|
|
1530
1410
|
function CompositeKeys(T) {
|
|
1531
1411
|
const Acc = [];
|
|
1532
1412
|
for (const L of T)
|
|
@@ -1586,7 +1466,7 @@ function ConditionalReadonly(T, root) {
|
|
|
1586
1466
|
return root === true ? T : Readonly(T);
|
|
1587
1467
|
}
|
|
1588
1468
|
function FromValue(value, root) {
|
|
1589
|
-
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({});
|
|
1590
1470
|
}
|
|
1591
1471
|
function Const(T, options) {
|
|
1592
1472
|
return CreateType(FromValue(T, true), options);
|
|
@@ -1888,6 +1768,18 @@ function ExtendsFromMappedKey(T, U, L, R, options) {
|
|
|
1888
1768
|
const P = FromMappedKey2(T, U, L, R, options);
|
|
1889
1769
|
return MappedResult(P);
|
|
1890
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
|
+
}
|
|
1891
1783
|
function ExcludeFromTemplateLiteral(L, R) {
|
|
1892
1784
|
return Exclude(TemplateLiteralToUnion(L), R);
|
|
1893
1785
|
}
|
|
@@ -1989,7 +1881,7 @@ function FromNumberKey(_, type, options) {
|
|
|
1989
1881
|
return RecordCreateFromPattern(PatternNumberExact, type, options);
|
|
1990
1882
|
}
|
|
1991
1883
|
function Record(key, type, options = {}) {
|
|
1992
|
-
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);
|
|
1993
1885
|
}
|
|
1994
1886
|
function RecordPattern(record) {
|
|
1995
1887
|
return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
|
|
@@ -2069,7 +1961,7 @@ function FromTypes(args, types) {
|
|
|
2069
1961
|
return types.map((type) => FromType(args, type));
|
|
2070
1962
|
}
|
|
2071
1963
|
function FromType(args, type) {
|
|
2072
|
-
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;
|
|
2073
1965
|
}
|
|
2074
1966
|
function Instantiate(type, args) {
|
|
2075
1967
|
return FromType(args, CloneType(type));
|
|
@@ -2297,7 +2189,7 @@ function PartialResolve(type) {
|
|
|
2297
2189
|
// Mappable
|
|
2298
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) : (
|
|
2299
2191
|
// Intrinsic
|
|
2300
|
-
|
|
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 : (
|
|
2301
2193
|
// Passthrough
|
|
2302
2194
|
Object2({})
|
|
2303
2195
|
)
|
|
@@ -2349,7 +2241,7 @@ function RequiredResolve(type) {
|
|
|
2349
2241
|
// Mappable
|
|
2350
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) : (
|
|
2351
2243
|
// Intrinsic
|
|
2352
|
-
|
|
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 : (
|
|
2353
2245
|
// Passthrough
|
|
2354
2246
|
Object2({})
|
|
2355
2247
|
)
|
|
@@ -2457,7 +2349,7 @@ function FromType2(moduleProperties, type) {
|
|
|
2457
2349
|
// Transform
|
|
2458
2350
|
IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
|
|
2459
2351
|
// Types
|
|
2460
|
-
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
|
|
2461
2353
|
)
|
|
2462
2354
|
)
|
|
2463
2355
|
);
|
|
@@ -2491,11 +2383,11 @@ var TModule = class {
|
|
|
2491
2383
|
function Module(properties) {
|
|
2492
2384
|
return new TModule(properties);
|
|
2493
2385
|
}
|
|
2494
|
-
function
|
|
2386
|
+
function Not2(type, options) {
|
|
2495
2387
|
return CreateType({ [Kind]: "Not", not: type }, options);
|
|
2496
2388
|
}
|
|
2497
2389
|
function Parameters(schema, options) {
|
|
2498
|
-
return
|
|
2390
|
+
return IsFunction3(schema) ? Tuple(schema.parameters, options) : Never();
|
|
2499
2391
|
}
|
|
2500
2392
|
var Ordinal = 0;
|
|
2501
2393
|
function Recursive(callback, options = {}) {
|
|
@@ -2516,116 +2408,1836 @@ function Rest(T) {
|
|
|
2516
2408
|
return RestResolve(T);
|
|
2517
2409
|
}
|
|
2518
2410
|
function ReturnType(schema, options) {
|
|
2519
|
-
return
|
|
2411
|
+
return IsFunction3(schema) ? CreateType(schema.returns, options) : Never(options);
|
|
2520
2412
|
}
|
|
2521
2413
|
var TransformDecodeBuilder = class {
|
|
2522
2414
|
constructor(schema) {
|
|
2523
2415
|
this.schema = schema;
|
|
2524
|
-
}
|
|
2525
|
-
Decode(decode) {
|
|
2526
|
-
return new TransformEncodeBuilder(this.schema, decode);
|
|
2416
|
+
}
|
|
2417
|
+
Decode(decode) {
|
|
2418
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
var TransformEncodeBuilder = class {
|
|
2422
|
+
constructor(schema, decode) {
|
|
2423
|
+
this.schema = schema;
|
|
2424
|
+
this.decode = decode;
|
|
2425
|
+
}
|
|
2426
|
+
EncodeTransform(encode, schema) {
|
|
2427
|
+
const Encode = (value) => schema[TransformKind].Encode(encode(value));
|
|
2428
|
+
const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
|
|
2429
|
+
const Codec = { Encode, Decode };
|
|
2430
|
+
return { ...schema, [TransformKind]: Codec };
|
|
2431
|
+
}
|
|
2432
|
+
EncodeSchema(encode, schema) {
|
|
2433
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
2434
|
+
return { ...schema, [TransformKind]: Codec };
|
|
2435
|
+
}
|
|
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;
|
|
2527
3954
|
}
|
|
2528
3955
|
};
|
|
2529
|
-
var
|
|
2530
|
-
constructor(schema,
|
|
3956
|
+
var TransformEncodeError = class extends TypeBoxError {
|
|
3957
|
+
constructor(schema, path, value, error2) {
|
|
3958
|
+
super(`${error2 instanceof Error ? error2.message : "Unknown error"}`);
|
|
2531
3959
|
this.schema = schema;
|
|
2532
|
-
this.
|
|
3960
|
+
this.path = path;
|
|
3961
|
+
this.value = value;
|
|
3962
|
+
this.error = error2;
|
|
2533
3963
|
}
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
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);
|
|
2539
3970
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
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;
|
|
2543
3995
|
}
|
|
2544
|
-
|
|
2545
|
-
|
|
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);
|
|
2546
4111
|
}
|
|
2547
|
-
};
|
|
2548
|
-
function Transform(schema) {
|
|
2549
|
-
return new TransformDecodeBuilder(schema);
|
|
2550
4112
|
}
|
|
2551
|
-
function
|
|
2552
|
-
return
|
|
4113
|
+
function TransformEncode(schema, references, value) {
|
|
4114
|
+
return Visit8(schema, references, "", value);
|
|
2553
4115
|
}
|
|
2554
|
-
function
|
|
2555
|
-
return
|
|
4116
|
+
function FromArray11(schema, references) {
|
|
4117
|
+
return IsTransform(schema) || Visit9(schema.items, references);
|
|
2556
4118
|
}
|
|
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
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
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
|
+
];
|
|
2623
4226
|
var DELIVERED_ACTION_TYPES = [
|
|
2624
4227
|
"click",
|
|
4228
|
+
"dblclick",
|
|
4229
|
+
"hover",
|
|
2625
4230
|
"fill",
|
|
4231
|
+
"clear",
|
|
4232
|
+
"check",
|
|
4233
|
+
"uncheck",
|
|
2626
4234
|
"select",
|
|
2627
4235
|
"scroll",
|
|
2628
4236
|
"press",
|
|
4237
|
+
"wait",
|
|
4238
|
+
"goBack",
|
|
4239
|
+
"goForward",
|
|
4240
|
+
"reload",
|
|
2629
4241
|
"acceptDialog",
|
|
2630
4242
|
"dismissDialog"
|
|
2631
4243
|
];
|
|
@@ -2683,13 +4295,28 @@ var SessionPolicySchema = Type.Object({
|
|
|
2683
4295
|
maxDownloadBytes: Type.Optional(Type.Number({ minimum: 0 })),
|
|
2684
4296
|
approval: Type.Optional(ApprovalPolicySchema)
|
|
2685
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
|
+
});
|
|
2686
4308
|
var SessionRequestSchema = Type.Object({
|
|
2687
|
-
|
|
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 })])),
|
|
2688
4313
|
ttlMs: Type.Optional(Type.Number({ minimum: 1e3, maximum: 864e5 })),
|
|
2689
4314
|
idleTimeoutMs: Type.Optional(Type.Number({ minimum: 1e3, maximum: 36e5 })),
|
|
2690
4315
|
viewport: Type.Optional(ViewportSchema),
|
|
2691
4316
|
locale: Type.Optional(Type.String({ pattern: "^[a-z]{2}-[A-Z]{2}$" })),
|
|
2692
4317
|
timezoneId: Type.Optional(Type.String()),
|
|
4318
|
+
headless: Type.Optional(Type.Boolean()),
|
|
4319
|
+
cookies: Type.Optional(Type.Array(SessionCookieSchema)),
|
|
2693
4320
|
policy: Type.Optional(SessionPolicySchema)
|
|
2694
4321
|
});
|
|
2695
4322
|
var ObservationModeSchema = Type.Union([
|
|
@@ -2702,6 +4329,7 @@ var ObservationModeSchema = Type.Union([
|
|
|
2702
4329
|
var ACTION_TYPE_LITERALS = [
|
|
2703
4330
|
"navigate",
|
|
2704
4331
|
"click",
|
|
4332
|
+
"dblclick",
|
|
2705
4333
|
"hover",
|
|
2706
4334
|
"fill",
|
|
2707
4335
|
"type",
|
|
@@ -2761,7 +4389,7 @@ var PageStatusSchema = Type.Union([
|
|
|
2761
4389
|
Type.Literal("complete")
|
|
2762
4390
|
]);
|
|
2763
4391
|
var PageElementSchema = Type.Object({
|
|
2764
|
-
ref: Type.String({ pattern:
|
|
4392
|
+
ref: Type.String({ pattern: REF_PATTERN.source }),
|
|
2765
4393
|
role: Type.String(),
|
|
2766
4394
|
name: Type.Optional(Type.String()),
|
|
2767
4395
|
value: Type.Optional(Type.String()),
|
|
@@ -2800,7 +4428,7 @@ var PageStateSchema = Type.Object({
|
|
|
2800
4428
|
continuation: Type.Optional(ContinuationCursorSchema)
|
|
2801
4429
|
});
|
|
2802
4430
|
var ElementTargetSchema = Type.Object({
|
|
2803
|
-
ref: Type.String({ pattern:
|
|
4431
|
+
ref: Type.String({ pattern: REF_PATTERN.source })
|
|
2804
4432
|
});
|
|
2805
4433
|
var NavigateActionSchema = Type.Object({
|
|
2806
4434
|
type: Type.Literal("navigate"),
|
|
@@ -2870,14 +4498,60 @@ var WaitActionSchema = Type.Object({
|
|
|
2870
4498
|
type: Type.Literal("wait"),
|
|
2871
4499
|
condition: WaitConditionSchema
|
|
2872
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
|
+
});
|
|
2873
4537
|
var ActionSchema = Type.Union([
|
|
2874
4538
|
NavigateActionSchema,
|
|
2875
4539
|
ClickActionSchema,
|
|
4540
|
+
DblClickActionSchema,
|
|
4541
|
+
HoverActionSchema,
|
|
2876
4542
|
FillActionSchema,
|
|
4543
|
+
ClearActionSchema,
|
|
4544
|
+
CheckActionSchema,
|
|
4545
|
+
UncheckActionSchema,
|
|
2877
4546
|
SelectActionSchema,
|
|
2878
4547
|
ScrollActionSchema,
|
|
2879
4548
|
PressActionSchema,
|
|
2880
|
-
WaitActionSchema
|
|
4549
|
+
WaitActionSchema,
|
|
4550
|
+
GoBackActionSchema,
|
|
4551
|
+
GoForwardActionSchema,
|
|
4552
|
+
ReloadActionSchema,
|
|
4553
|
+
AcceptDialogActionSchema,
|
|
4554
|
+
DismissDialogActionSchema
|
|
2881
4555
|
]);
|
|
2882
4556
|
var ObservationRequestSchema = Type.Object({
|
|
2883
4557
|
mode: Type.Optional(ObservationModeSchema),
|
|
@@ -2945,6 +4619,569 @@ var ActionResultSchema = Type.Object({
|
|
|
2945
4619
|
artifacts: Type.Optional(Type.Array(ArtifactRefSchema)),
|
|
2946
4620
|
error: Type.Optional(ApiErrorDetailSchema)
|
|
2947
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);
|
|
2948
5185
|
var ErrorCode;
|
|
2949
5186
|
(function(ErrorCode2) {
|
|
2950
5187
|
ErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
@@ -2970,8 +5207,264 @@ var ErrorCode;
|
|
|
2970
5207
|
ErrorCode2["OUTPUT_TRUNCATED"] = "OUTPUT_TRUNCATED";
|
|
2971
5208
|
ErrorCode2["INTERNAL"] = "INTERNAL";
|
|
2972
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, bounds) {
|
|
5328
|
+
const query = new URLSearchParams();
|
|
5329
|
+
if (bounds?.maxElements !== void 0)
|
|
5330
|
+
query.set("maxElements", String(bounds.maxElements));
|
|
5331
|
+
if (bounds?.maxBytes !== void 0)
|
|
5332
|
+
query.set("maxBytes", String(bounds.maxBytes));
|
|
5333
|
+
const qs = query.toString();
|
|
5334
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/snapshot${qs ? `?${qs}` : ""}`, { headers: this.headers });
|
|
5335
|
+
return this.handleResponse(response);
|
|
5336
|
+
}
|
|
5337
|
+
async navigate(sessionId, pageId, request) {
|
|
5338
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/navigate`, {
|
|
5339
|
+
method: "POST",
|
|
5340
|
+
headers: {
|
|
5341
|
+
"Content-Type": "application/json",
|
|
5342
|
+
...this.headers
|
|
5343
|
+
},
|
|
5344
|
+
body: JSON.stringify(request)
|
|
5345
|
+
});
|
|
5346
|
+
return this.handleResponse(response);
|
|
5347
|
+
}
|
|
5348
|
+
async observe(sessionId, pageId, request = {}) {
|
|
5349
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/observe`, {
|
|
5350
|
+
method: "POST",
|
|
5351
|
+
headers: {
|
|
5352
|
+
"Content-Type": "application/json",
|
|
5353
|
+
...this.headers
|
|
5354
|
+
},
|
|
5355
|
+
body: JSON.stringify(request)
|
|
5356
|
+
});
|
|
5357
|
+
return this.handleResponse(response);
|
|
5358
|
+
}
|
|
5359
|
+
async executeAction(sessionId, pageId, request) {
|
|
5360
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/act`, {
|
|
5361
|
+
method: "POST",
|
|
5362
|
+
headers: {
|
|
5363
|
+
"Content-Type": "application/json",
|
|
5364
|
+
...this.headers
|
|
5365
|
+
},
|
|
5366
|
+
body: JSON.stringify(request)
|
|
5367
|
+
});
|
|
5368
|
+
return this.handleResponse(response);
|
|
5369
|
+
}
|
|
5370
|
+
async screenshot(sessionId, pageId, request = {}) {
|
|
5371
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/screenshot`, {
|
|
5372
|
+
method: "POST",
|
|
5373
|
+
headers: {
|
|
5374
|
+
"Content-Type": "application/json",
|
|
5375
|
+
...this.headers
|
|
5376
|
+
},
|
|
5377
|
+
body: JSON.stringify(request)
|
|
5378
|
+
});
|
|
5379
|
+
return this.handleResponse(response);
|
|
5380
|
+
}
|
|
5381
|
+
async extract(sessionId, pageId, request) {
|
|
5382
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/extract`, {
|
|
5383
|
+
method: "POST",
|
|
5384
|
+
headers: {
|
|
5385
|
+
"Content-Type": "application/json",
|
|
5386
|
+
...this.headers
|
|
5387
|
+
},
|
|
5388
|
+
body: JSON.stringify(request)
|
|
5389
|
+
});
|
|
5390
|
+
return this.handleResponse(response);
|
|
5391
|
+
}
|
|
5392
|
+
async pdf(sessionId, pageId, request = {}) {
|
|
5393
|
+
const response = await this.requestFn(`${this.baseUrl}/v1/sessions/${sessionId}/pages/${pageId}/pdf`, {
|
|
5394
|
+
method: "POST",
|
|
5395
|
+
headers: {
|
|
5396
|
+
"Content-Type": "application/json",
|
|
5397
|
+
...this.headers
|
|
5398
|
+
},
|
|
5399
|
+
body: JSON.stringify(request)
|
|
5400
|
+
});
|
|
5401
|
+
return this.handleResponse(response);
|
|
5402
|
+
}
|
|
5403
|
+
async handleResponse(response) {
|
|
5404
|
+
if (!response.ok) {
|
|
5405
|
+
let error2;
|
|
5406
|
+
try {
|
|
5407
|
+
const data = await response.json();
|
|
5408
|
+
error2 = data.error || {
|
|
5409
|
+
code: "UNKNOWN_ERROR",
|
|
5410
|
+
message: "Unknown error",
|
|
5411
|
+
retryable: false
|
|
5412
|
+
};
|
|
5413
|
+
} catch {
|
|
5414
|
+
error2 = {
|
|
5415
|
+
code: "UNKNOWN_ERROR",
|
|
5416
|
+
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
5417
|
+
retryable: false
|
|
5418
|
+
};
|
|
5419
|
+
}
|
|
5420
|
+
throw new AgentBrowserError(error2.code, error2.message, error2.retryable);
|
|
5421
|
+
}
|
|
5422
|
+
return response.json();
|
|
5423
|
+
}
|
|
5424
|
+
};
|
|
5425
|
+
var AgentBrowserClient = class {
|
|
5426
|
+
baseUrl;
|
|
5427
|
+
timeout;
|
|
5428
|
+
sessions;
|
|
5429
|
+
customHeaders;
|
|
5430
|
+
constructor(options = {}) {
|
|
5431
|
+
this.baseUrl = options.baseUrl || "http://localhost:3000";
|
|
5432
|
+
this.timeout = options.timeout || 3e4;
|
|
5433
|
+
this.customHeaders = {
|
|
5434
|
+
...options.apiKey !== void 0 ? { Authorization: `Bearer ${options.apiKey}` } : {},
|
|
5435
|
+
...options.headers
|
|
5436
|
+
};
|
|
5437
|
+
this.sessions = new SessionsClient(this.baseUrl, this.timeout, this.customHeaders, this.request.bind(this));
|
|
5438
|
+
}
|
|
5439
|
+
/**
|
|
5440
|
+
* Set default headers for all requests
|
|
5441
|
+
*/
|
|
5442
|
+
setHeaders(headers) {
|
|
5443
|
+
Object.assign(this.customHeaders, headers);
|
|
5444
|
+
}
|
|
5445
|
+
/**
|
|
5446
|
+
* Make an HTTP request with timeout
|
|
5447
|
+
*/
|
|
5448
|
+
async request(url, options = {}) {
|
|
5449
|
+
const controller = new AbortController();
|
|
5450
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
5451
|
+
try {
|
|
5452
|
+
const response = await fetch(url, {
|
|
5453
|
+
...options,
|
|
5454
|
+
signal: controller.signal
|
|
5455
|
+
});
|
|
5456
|
+
clearTimeout(timeoutId);
|
|
5457
|
+
return response;
|
|
5458
|
+
} catch (error2) {
|
|
5459
|
+
clearTimeout(timeoutId);
|
|
5460
|
+
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
5461
|
+
throw new AgentBrowserError("TIMEOUT", "Request timeout", false);
|
|
5462
|
+
}
|
|
5463
|
+
throw error2;
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
};
|
|
2973
5467
|
var PROTOCOL_VERSION = "2024-11-05";
|
|
2974
|
-
var REF_PATTERN = "^e\\d+_\\d+$";
|
|
2975
5468
|
function buildMcpServer(deps) {
|
|
2976
5469
|
const client = deps.createClient({ baseUrl: deps.baseUrl ?? "http://localhost:3000" });
|
|
2977
5470
|
const serverInfo = deps.serverInfo ?? { name: "agentbrowser", version: "1.0.0" };
|
|
@@ -3068,7 +5561,7 @@ function buildMcpServer(deps) {
|
|
|
3068
5561
|
},
|
|
3069
5562
|
{
|
|
3070
5563
|
name: "browser_plan",
|
|
3071
|
-
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.",
|
|
5564
|
+
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. A step for a field that only appears after a prior step (Phase 2) may declare `waitForLabel` (substring match on the element name) instead of `target` - the executor waits for it to appear (bounded by `waitMs`, default 5000) and resolves the ref itself; a miss aborts the plan with a typed PLAN_WAIT_TIMEOUT.",
|
|
3072
5565
|
inputSchema: {
|
|
3073
5566
|
type: "object",
|
|
3074
5567
|
properties: {
|
|
@@ -3076,7 +5569,7 @@ function buildMcpServer(deps) {
|
|
|
3076
5569
|
pageId: { type: "string" },
|
|
3077
5570
|
actions: {
|
|
3078
5571
|
type: "array",
|
|
3079
|
-
description: "Ordered plan steps: {action, target?: {ref}, value?, key?}",
|
|
5572
|
+
description: "Ordered plan steps: {action, target?: {ref}, value?, key?, waitForLabel?, waitMs?}",
|
|
3080
5573
|
items: { type: "object" }
|
|
3081
5574
|
}
|
|
3082
5575
|
},
|
|
@@ -3170,7 +5663,7 @@ function buildMcpServer(deps) {
|
|
|
3170
5663
|
},
|
|
3171
5664
|
{
|
|
3172
5665
|
name: "browser_act",
|
|
3173
|
-
description: "Perform an action on an element by ref: click, fill, select, scroll or
|
|
5666
|
+
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.",
|
|
3174
5667
|
inputSchema: {
|
|
3175
5668
|
type: "object",
|
|
3176
5669
|
properties: {
|
|
@@ -3185,7 +5678,7 @@ function buildMcpServer(deps) {
|
|
|
3185
5678
|
properties: {
|
|
3186
5679
|
ref: {
|
|
3187
5680
|
type: "string",
|
|
3188
|
-
pattern: REF_PATTERN,
|
|
5681
|
+
pattern: REF_PATTERN.source,
|
|
3189
5682
|
description: "Element ref from browser_observe, e.g. e1_0."
|
|
3190
5683
|
}
|
|
3191
5684
|
},
|
|
@@ -3194,16 +5687,35 @@ function buildMcpServer(deps) {
|
|
|
3194
5687
|
value: { type: "string", description: "Value for fill/select." },
|
|
3195
5688
|
key: { type: "string", description: "Key for press." },
|
|
3196
5689
|
direction: { type: "string", enum: ["up", "down", "left", "right"] },
|
|
3197
|
-
amount: { type: "number" }
|
|
5690
|
+
amount: { type: "number" },
|
|
5691
|
+
condition: {
|
|
5692
|
+
type: "object",
|
|
5693
|
+
description: 'Wait-action condition (action: "wait" only).',
|
|
5694
|
+
properties: {
|
|
5695
|
+
until: {
|
|
5696
|
+
type: "string",
|
|
5697
|
+
enum: ["settled", "domcontentloaded", "load", "networkidle"]
|
|
5698
|
+
},
|
|
5699
|
+
timeoutMs: { type: "number" }
|
|
5700
|
+
},
|
|
5701
|
+
required: ["until"]
|
|
5702
|
+
}
|
|
3198
5703
|
},
|
|
3199
5704
|
required: ["sessionId", "pageId", "action"]
|
|
3200
5705
|
},
|
|
3201
5706
|
handler: async (args) => {
|
|
3202
5707
|
const [sessionId, pageId] = sessionAndPage(args);
|
|
3203
5708
|
const target = args.target ?? {};
|
|
3204
|
-
const
|
|
5709
|
+
const UNTARGETED_ACTIONS = /* @__PURE__ */ new Set([
|
|
5710
|
+
"acceptDialog",
|
|
5711
|
+
"dismissDialog",
|
|
5712
|
+
"wait",
|
|
5713
|
+
"goBack",
|
|
5714
|
+
"goForward",
|
|
5715
|
+
"reload"
|
|
5716
|
+
]);
|
|
3205
5717
|
const ref = target.ref;
|
|
3206
|
-
if (!
|
|
5718
|
+
if (!UNTARGETED_ACTIONS.has(String(args.action)) && (typeof ref !== "string" || !REF_PATTERN.test(ref))) {
|
|
3207
5719
|
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.`);
|
|
3208
5720
|
}
|
|
3209
5721
|
const request = {
|
|
@@ -3218,6 +5730,9 @@ function buildMcpServer(deps) {
|
|
|
3218
5730
|
request.direction = args.direction;
|
|
3219
5731
|
if (typeof args.amount === "number")
|
|
3220
5732
|
request.amount = args.amount;
|
|
5733
|
+
if (args.condition !== void 0 && typeof args.condition === "object") {
|
|
5734
|
+
request.condition = args.condition;
|
|
5735
|
+
}
|
|
3221
5736
|
return await client.sessions.executeAction(sessionId, pageId, request);
|
|
3222
5737
|
}
|
|
3223
5738
|
},
|
|
@@ -3231,8 +5746,12 @@ function buildMcpServer(deps) {
|
|
|
3231
5746
|
pageId: { type: "string" },
|
|
3232
5747
|
format: {
|
|
3233
5748
|
type: "string",
|
|
3234
|
-
enum: [
|
|
5749
|
+
enum: [...DELIVERED_EXTRACT_FORMATS],
|
|
3235
5750
|
description: "What to extract (default: text)."
|
|
5751
|
+
},
|
|
5752
|
+
schema: {
|
|
5753
|
+
type: "object",
|
|
5754
|
+
description: 'JSON Schema constraining the extraction (format: "schema" only): properties to pick, with type/description/enum constraints.'
|
|
3236
5755
|
}
|
|
3237
5756
|
},
|
|
3238
5757
|
required: ["sessionId", "pageId", "format"]
|
|
@@ -3240,13 +5759,15 @@ function buildMcpServer(deps) {
|
|
|
3240
5759
|
handler: async (args) => {
|
|
3241
5760
|
const [sessionId, pageId] = sessionAndPage(args);
|
|
3242
5761
|
const format = args.format;
|
|
3243
|
-
const supported =
|
|
5762
|
+
const supported = DELIVERED_EXTRACT_FORMATS;
|
|
3244
5763
|
if (typeof format !== "string" || !supported.includes(format)) {
|
|
3245
5764
|
throw new UsageError(`Unknown extraction format '${String(format)}'. Supported: ${supported.join(", ")}.`);
|
|
3246
5765
|
}
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
5766
|
+
const request = { format };
|
|
5767
|
+
if (args.schema !== void 0 && typeof args.schema === "object") {
|
|
5768
|
+
request.schema = args.schema;
|
|
5769
|
+
}
|
|
5770
|
+
return await client.sessions.extract(sessionId, pageId, request);
|
|
3250
5771
|
}
|
|
3251
5772
|
},
|
|
3252
5773
|
{
|
|
@@ -3350,8 +5871,6 @@ function buildMcpServer(deps) {
|
|
|
3350
5871
|
}
|
|
3351
5872
|
};
|
|
3352
5873
|
}
|
|
3353
|
-
var UsageError = class extends Error {
|
|
3354
|
-
};
|
|
3355
5874
|
function requireHttpUrl(value) {
|
|
3356
5875
|
const url = typeof value === "string" ? value : "";
|
|
3357
5876
|
if (!/^https?:\/\//.test(url)) {
|
|
@@ -3371,19 +5890,7 @@ function errorResult(message) {
|
|
|
3371
5890
|
};
|
|
3372
5891
|
}
|
|
3373
5892
|
function formatToolError(error2) {
|
|
3374
|
-
|
|
3375
|
-
return error2.message;
|
|
3376
|
-
}
|
|
3377
|
-
if (error2 instanceof Error) {
|
|
3378
|
-
const code = error2.code;
|
|
3379
|
-
if (code === "STALE_TARGET") {
|
|
3380
|
-
return `${error2.message}
|
|
3381
|
-
|
|
3382
|
-
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.`;
|
|
3383
|
-
}
|
|
3384
|
-
return code && !error2.message.startsWith(code) ? `${code}: ${error2.message}` : error2.message;
|
|
3385
|
-
}
|
|
3386
|
-
return String(error2);
|
|
5893
|
+
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.");
|
|
3387
5894
|
}
|
|
3388
5895
|
function ok(id, result) {
|
|
3389
5896
|
return JSON.stringify({ jsonrpc: "2.0", id, result });
|