@sinclair/typebox 0.24.19 → 0.24.22
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/compiler/compiler.js +49 -54
- package/compiler/property.d.ts +4 -0
- package/compiler/property.js +64 -0
- package/package.json +4 -4
- package/readme.md +55 -55
- package/value/check.js +1 -1
- package/value/errors.js +1 -1
package/compiler/compiler.js
CHANGED
|
@@ -29,6 +29,7 @@ THE SOFTWARE.
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.TypeCompiler = exports.TypeCheck = void 0;
|
|
31
31
|
const errors_1 = require("../value/errors");
|
|
32
|
+
const property_1 = require("./property");
|
|
32
33
|
const Types = require("../typebox");
|
|
33
34
|
// -------------------------------------------------------------------
|
|
34
35
|
// TypeCheck
|
|
@@ -61,13 +62,13 @@ exports.TypeCheck = TypeCheck;
|
|
|
61
62
|
var TypeCompiler;
|
|
62
63
|
(function (TypeCompiler) {
|
|
63
64
|
// -------------------------------------------------------------------
|
|
64
|
-
//
|
|
65
|
+
// Types
|
|
65
66
|
// -------------------------------------------------------------------
|
|
66
67
|
function* Any(schema, value) {
|
|
67
68
|
yield '(true)';
|
|
68
69
|
}
|
|
69
70
|
function* Array(schema, value) {
|
|
70
|
-
const expression =
|
|
71
|
+
const expression = CreateExpression(schema.items, 'value');
|
|
71
72
|
if (schema.minItems !== undefined)
|
|
72
73
|
yield `(${value}.length >= ${schema.minItems})`;
|
|
73
74
|
if (schema.maxItems !== undefined)
|
|
@@ -143,13 +144,14 @@ var TypeCompiler;
|
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
for (const propertyKey of propertyKeys) {
|
|
147
|
+
const memberExpression = property_1.Property.Check(propertyKey) ? `${value}.${propertyKey}` : `${value}['${propertyKey}']`;
|
|
146
148
|
const propertySchema = schema.properties[propertyKey];
|
|
147
149
|
if (schema.required && schema.required.includes(propertyKey)) {
|
|
148
|
-
yield* Visit(propertySchema,
|
|
150
|
+
yield* Visit(propertySchema, memberExpression);
|
|
149
151
|
}
|
|
150
152
|
else {
|
|
151
|
-
const
|
|
152
|
-
yield `(${
|
|
153
|
+
const expression = CreateExpression(propertySchema, memberExpression);
|
|
154
|
+
yield `(${memberExpression} === undefined ? true : (${expression}))`;
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
}
|
|
@@ -159,25 +161,16 @@ var TypeCompiler;
|
|
|
159
161
|
function* Record(schema, value) {
|
|
160
162
|
yield `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))`;
|
|
161
163
|
const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
|
|
162
|
-
const local = PushLocal(`
|
|
164
|
+
const local = PushLocal(`new RegExp(/${keyPattern}/)`);
|
|
163
165
|
yield `(Object.keys(${value}).every(key => ${local}.test(key)))`;
|
|
164
|
-
const
|
|
165
|
-
yield `(Object.values(${value}).every(value => ${
|
|
166
|
+
const expression = CreateExpression(valueSchema, 'value');
|
|
167
|
+
yield `(Object.values(${value}).every(value => ${expression}))`;
|
|
166
168
|
}
|
|
167
169
|
function* Ref(schema, value) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const reference = referenceMap.get(schema.$ref);
|
|
173
|
-
functionNames.add(schema.$ref);
|
|
174
|
-
const conditions = [...Visit(reference, 'value')];
|
|
175
|
-
const name = CreateFunctionName(schema.$ref);
|
|
176
|
-
const body = CreateFunction(name, conditions);
|
|
177
|
-
PushLocal(body);
|
|
178
|
-
}
|
|
179
|
-
const func = CreateFunctionName(schema.$ref);
|
|
180
|
-
yield `(${func}(${value}))`;
|
|
170
|
+
if (!referenceMap.has(schema.$ref))
|
|
171
|
+
throw Error(`TypeCompiler.Ref: Cannot de-reference schema with $id '${schema.$ref}'`);
|
|
172
|
+
const reference = referenceMap.get(schema.$ref);
|
|
173
|
+
yield* Visit(reference, value);
|
|
181
174
|
}
|
|
182
175
|
function* Self(schema, value) {
|
|
183
176
|
const func = CreateFunctionName(schema.$ref);
|
|
@@ -192,7 +185,7 @@ var TypeCompiler;
|
|
|
192
185
|
yield `(${value}.length <= ${schema.maxLength})`;
|
|
193
186
|
}
|
|
194
187
|
if (schema.pattern !== undefined) {
|
|
195
|
-
const local = PushLocal(`
|
|
188
|
+
const local = PushLocal(`new RegExp(/${schema.pattern}/);`);
|
|
196
189
|
yield `(${local}.test(${value}))`;
|
|
197
190
|
}
|
|
198
191
|
}
|
|
@@ -202,16 +195,16 @@ var TypeCompiler;
|
|
|
202
195
|
return yield `(${value}.length === 0)`;
|
|
203
196
|
yield `(${value}.length === ${schema.maxItems})`;
|
|
204
197
|
for (let i = 0; i < schema.items.length; i++) {
|
|
205
|
-
const
|
|
206
|
-
yield `(${
|
|
198
|
+
const expression = CreateExpression(schema.items[i], `${value}[${i}]`);
|
|
199
|
+
yield `(${expression})`;
|
|
207
200
|
}
|
|
208
201
|
}
|
|
209
202
|
function* Undefined(schema, value) {
|
|
210
203
|
yield `(${value} === undefined)`;
|
|
211
204
|
}
|
|
212
205
|
function* Union(schema, value) {
|
|
213
|
-
const
|
|
214
|
-
yield `(${
|
|
206
|
+
const expressions = schema.anyOf.map((schema) => CreateExpression(schema, value));
|
|
207
|
+
yield `(${expressions.join(' || ')})`;
|
|
215
208
|
}
|
|
216
209
|
function* Uint8Array(schema, value) {
|
|
217
210
|
yield `(${value} instanceof Uint8Array)`;
|
|
@@ -230,12 +223,11 @@ var TypeCompiler;
|
|
|
230
223
|
// reference: referenced schemas can originate from either additional
|
|
231
224
|
// schemas or inline in the schema itself. Ideally the recursive
|
|
232
225
|
// path should align to reference path. Consider for review.
|
|
233
|
-
if (schema.$id && !
|
|
234
|
-
|
|
235
|
-
const conditions = [...Visit(schema, 'value')];
|
|
226
|
+
if (schema.$id && !names.has(schema.$id)) {
|
|
227
|
+
names.add(schema.$id);
|
|
236
228
|
const name = CreateFunctionName(schema.$id);
|
|
237
|
-
const body = CreateFunction(name,
|
|
238
|
-
|
|
229
|
+
const body = CreateFunction(name, schema, 'value');
|
|
230
|
+
PushFunction(body);
|
|
239
231
|
yield `(${name}(${value}))`;
|
|
240
232
|
return;
|
|
241
233
|
}
|
|
@@ -288,17 +280,17 @@ var TypeCompiler;
|
|
|
288
280
|
}
|
|
289
281
|
}
|
|
290
282
|
// -------------------------------------------------------------------
|
|
291
|
-
//
|
|
283
|
+
// Compile State
|
|
292
284
|
// -------------------------------------------------------------------
|
|
293
285
|
const referenceMap = new Map();
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
function
|
|
297
|
-
functionLocals.clear();
|
|
298
|
-
functionNames.clear();
|
|
286
|
+
const locals = new Set(); // local variables and functions
|
|
287
|
+
const names = new Set(); // cache of local functions
|
|
288
|
+
function ResetCompiler() {
|
|
299
289
|
referenceMap.clear();
|
|
290
|
+
locals.clear();
|
|
291
|
+
names.clear();
|
|
300
292
|
}
|
|
301
|
-
function
|
|
293
|
+
function AddReferences(schemas = []) {
|
|
302
294
|
for (const schema of schemas) {
|
|
303
295
|
if (!schema.$id)
|
|
304
296
|
throw new Error(`TypeCompiler: Referenced schemas must specify an $id.`);
|
|
@@ -307,33 +299,36 @@ var TypeCompiler;
|
|
|
307
299
|
referenceMap.set(schema.$id, schema);
|
|
308
300
|
}
|
|
309
301
|
}
|
|
310
|
-
function
|
|
311
|
-
|
|
312
|
-
functionLocals.add(code.replace('local', name));
|
|
313
|
-
return name;
|
|
314
|
-
}
|
|
315
|
-
function GetLocals() {
|
|
316
|
-
return [...functionLocals.values()];
|
|
302
|
+
function CreateExpression(schema, value) {
|
|
303
|
+
return [...Visit(schema, value)].join(' && ');
|
|
317
304
|
}
|
|
318
|
-
// -------------------------------------------------------------------
|
|
319
|
-
// Functions
|
|
320
|
-
// -------------------------------------------------------------------
|
|
321
305
|
function CreateFunctionName($id) {
|
|
322
306
|
return `check_${$id.replace(/-/g, '_')}`;
|
|
323
307
|
}
|
|
324
|
-
function CreateFunction(name,
|
|
325
|
-
const expression =
|
|
308
|
+
function CreateFunction(name, schema, value) {
|
|
309
|
+
const expression = [...Visit(schema, value)].map((condition) => ` ${condition}`).join(' &&\n');
|
|
326
310
|
return `function ${name}(value) {\n return (\n${expression}\n )\n}`;
|
|
327
311
|
}
|
|
312
|
+
function PushFunction(functionBody) {
|
|
313
|
+
locals.add(functionBody);
|
|
314
|
+
}
|
|
315
|
+
function PushLocal(expression) {
|
|
316
|
+
const local = `local_${locals.size}`;
|
|
317
|
+
locals.add(`const ${local} = ${expression}`);
|
|
318
|
+
return local;
|
|
319
|
+
}
|
|
320
|
+
function GetLocals() {
|
|
321
|
+
return [...locals.values()];
|
|
322
|
+
}
|
|
328
323
|
// -------------------------------------------------------------------
|
|
329
324
|
// Compile
|
|
330
325
|
// -------------------------------------------------------------------
|
|
331
326
|
function Build(schema, references = []) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const
|
|
327
|
+
ResetCompiler();
|
|
328
|
+
AddReferences(references);
|
|
329
|
+
const check = CreateFunction('check', schema, 'value');
|
|
335
330
|
const locals = GetLocals();
|
|
336
|
-
return `${locals.join('\n')}\nreturn ${
|
|
331
|
+
return `${locals.join('\n')}\nreturn ${check}`;
|
|
337
332
|
}
|
|
338
333
|
/** Compiles the given type for runtime type checking. This compiler only accepts known TypeBox types non-inclusive of unsafe types. */
|
|
339
334
|
function Compile(schema, references = []) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/compiler
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2022 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Property = void 0;
|
|
31
|
+
var Property;
|
|
32
|
+
(function (Property) {
|
|
33
|
+
function DollarSign(char) {
|
|
34
|
+
return char === 36;
|
|
35
|
+
}
|
|
36
|
+
function Underscore(char) {
|
|
37
|
+
return char === 95;
|
|
38
|
+
}
|
|
39
|
+
function Numeric(char) {
|
|
40
|
+
return char >= 48 && char <= 57;
|
|
41
|
+
}
|
|
42
|
+
function Alpha(char) {
|
|
43
|
+
return (char >= 65 && char <= 90) || (char >= 97 && char <= 122);
|
|
44
|
+
}
|
|
45
|
+
/** Tests if this property name can be used in a member expression */
|
|
46
|
+
function Check(propertyName) {
|
|
47
|
+
if (propertyName.length === 0)
|
|
48
|
+
return false;
|
|
49
|
+
{
|
|
50
|
+
const code = propertyName.charCodeAt(0);
|
|
51
|
+
if (!(DollarSign(code) || Underscore(code) || Alpha(code))) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (let i = 1; i < propertyName.length; i++) {
|
|
56
|
+
const code = propertyName.charCodeAt(i);
|
|
57
|
+
if (!(DollarSign(code) || Underscore(code) || Alpha(code) || Numeric(code))) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
Property.Check = Check;
|
|
64
|
+
})(Property = exports.Property || (exports.Property = {}));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.22",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"json-schema",
|
|
7
6
|
"typescript",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"json-schema",
|
|
8
|
+
"validate",
|
|
9
|
+
"typecheck"
|
|
10
10
|
],
|
|
11
11
|
"author": "sinclairzx81",
|
|
12
12
|
"license": "MIT",
|
package/readme.md
CHANGED
|
@@ -114,9 +114,9 @@ const T = Type.Object({ // const T = {
|
|
|
114
114
|
// }
|
|
115
115
|
// },
|
|
116
116
|
// required: [
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
117
|
+
// 'id',
|
|
118
|
+
// 'name',
|
|
119
|
+
// 'timestamp'
|
|
120
120
|
// ]
|
|
121
121
|
// }
|
|
122
122
|
|
|
@@ -528,7 +528,7 @@ function test(node: Node) {
|
|
|
528
528
|
|
|
529
529
|
## Generic Types
|
|
530
530
|
|
|
531
|
-
|
|
531
|
+
Use functions to create generic types. The following creates a generic `Nullable<T>` type.
|
|
532
532
|
|
|
533
533
|
```typescript
|
|
534
534
|
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
@@ -594,12 +594,12 @@ type T = Static<typeof T> // type T = string | null
|
|
|
594
594
|
|
|
595
595
|
//--------------------------------------------------------------------------------------------
|
|
596
596
|
//
|
|
597
|
-
//
|
|
597
|
+
// StringEnum<string[]>
|
|
598
598
|
//
|
|
599
599
|
//--------------------------------------------------------------------------------------------
|
|
600
600
|
|
|
601
601
|
function StringEnum<T extends string[]>(values: [...T]) {
|
|
602
|
-
return Type.Unsafe<T[number]>({ enum: values })
|
|
602
|
+
return Type.Unsafe<T[number]>({ type: 'string', enum: values })
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
const T = StringEnum(['A', 'B', 'C']) // const T = {
|
|
@@ -876,7 +876,7 @@ console.log(C.Code()) // return function check(va
|
|
|
876
876
|
|
|
877
877
|
## Benchmark
|
|
878
878
|
|
|
879
|
-
This project maintains benchmarks that measure Ajv and TypeCompiler
|
|
879
|
+
This project maintains benchmarks that measure Ajv and TypeCompiler validate and compile performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. Results show against Ajv version 8.11.0.
|
|
880
880
|
|
|
881
881
|
### Validate
|
|
882
882
|
|
|
@@ -886,31 +886,31 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
886
886
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
887
887
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
888
888
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
889
|
-
│ Number │
|
|
890
|
-
│ String │
|
|
891
|
-
│ Boolean │
|
|
892
|
-
│ Null │
|
|
893
|
-
│ RegEx │
|
|
894
|
-
│ ObjectA │
|
|
895
|
-
│ ObjectB │
|
|
896
|
-
│ Tuple │
|
|
897
|
-
│ Union │
|
|
898
|
-
│ Recursive │
|
|
899
|
-
│ Vector4 │
|
|
900
|
-
│ Matrix4 │
|
|
901
|
-
│ Literal_String │
|
|
902
|
-
│ Literal_Number │
|
|
903
|
-
│ Literal_Boolean │
|
|
904
|
-
│ Array_Number │
|
|
905
|
-
│ Array_String │
|
|
906
|
-
│ Array_Boolean │
|
|
907
|
-
│ Array_ObjectA │
|
|
908
|
-
│ Array_ObjectB │
|
|
909
|
-
│ Array_Tuple │
|
|
910
|
-
│ Array_Union │
|
|
911
|
-
│ Array_Recursive │
|
|
912
|
-
│ Array_Vector4 │
|
|
913
|
-
│ Array_Matrix4 │
|
|
889
|
+
│ Number │ 4000000 │ ' 17 ms' │ ' 16 ms' │ ' 1.06 x' │
|
|
890
|
+
│ String │ 4000000 │ ' 74 ms' │ ' 37 ms' │ ' 2.00 x' │
|
|
891
|
+
│ Boolean │ 4000000 │ ' 68 ms' │ ' 36 ms' │ ' 1.89 x' │
|
|
892
|
+
│ Null │ 4000000 │ ' 68 ms' │ ' 36 ms' │ ' 1.89 x' │
|
|
893
|
+
│ RegEx │ 4000000 │ ' 170 ms' │ ' 143 ms' │ ' 1.19 x' │
|
|
894
|
+
│ ObjectA │ 4000000 │ ' 122 ms' │ ' 84 ms' │ ' 1.45 x' │
|
|
895
|
+
│ ObjectB │ 4000000 │ ' 182 ms' │ ' 137 ms' │ ' 1.33 x' │
|
|
896
|
+
│ Tuple │ 4000000 │ ' 82 ms' │ ' 48 ms' │ ' 1.71 x' │
|
|
897
|
+
│ Union │ 4000000 │ ' 84 ms' │ ' 52 ms' │ ' 1.62 x' │
|
|
898
|
+
│ Recursive │ 4000000 │ ' 1526 ms' │ ' 631 ms' │ ' 2.42 x' │
|
|
899
|
+
│ Vector4 │ 4000000 │ ' 80 ms' │ ' 42 ms' │ ' 1.90 x' │
|
|
900
|
+
│ Matrix4 │ 4000000 │ ' 157 ms' │ ' 113 ms' │ ' 1.39 x' │
|
|
901
|
+
│ Literal_String │ 4000000 │ ' 69 ms' │ ' 36 ms' │ ' 1.92 x' │
|
|
902
|
+
│ Literal_Number │ 4000000 │ ' 69 ms' │ ' 35 ms' │ ' 1.97 x' │
|
|
903
|
+
│ Literal_Boolean │ 4000000 │ ' 68 ms' │ ' 35 ms' │ ' 1.94 x' │
|
|
904
|
+
│ Array_Number │ 4000000 │ ' 119 ms' │ ' 60 ms' │ ' 1.98 x' │
|
|
905
|
+
│ Array_String │ 4000000 │ ' 119 ms' │ ' 76 ms' │ ' 1.57 x' │
|
|
906
|
+
│ Array_Boolean │ 4000000 │ ' 131 ms' │ ' 88 ms' │ ' 1.49 x' │
|
|
907
|
+
│ Array_ObjectA │ 4000000 │ ' 10615 ms' │ ' 7053 ms' │ ' 1.51 x' │
|
|
908
|
+
│ Array_ObjectB │ 4000000 │ ' 11305 ms' │ ' 8128 ms' │ ' 1.39 x' │
|
|
909
|
+
│ Array_Tuple │ 4000000 │ ' 355 ms' │ ' 271 ms' │ ' 1.31 x' │
|
|
910
|
+
│ Array_Union │ 4000000 │ ' 910 ms' │ ' 340 ms' │ ' 2.68 x' │
|
|
911
|
+
│ Array_Recursive │ 4000000 │ ' 29101 ms' │ ' 10837 ms' │ ' 2.69 x' │
|
|
912
|
+
│ Array_Vector4 │ 4000000 │ ' 381 ms' │ ' 212 ms' │ ' 1.80 x' │
|
|
913
|
+
│ Array_Matrix4 │ 4000000 │ ' 1534 ms' │ ' 1344 ms' │ ' 1.14 x' │
|
|
914
914
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
915
915
|
```
|
|
916
916
|
|
|
@@ -922,29 +922,29 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
922
922
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
923
923
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
924
924
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
925
|
-
│ Number │ 2000 │ '
|
|
926
|
-
│ String │ 2000 │ '
|
|
927
|
-
│ Boolean │ 2000 │ '
|
|
928
|
-
│ Null │ 2000 │ '
|
|
929
|
-
│ RegEx │ 2000 │ '
|
|
930
|
-
│ ObjectA │ 2000 │ '
|
|
931
|
-
│ ObjectB │ 2000 │ '
|
|
932
|
-
│ Tuple │ 2000 │ '
|
|
933
|
-
│ Union │ 2000 │ '
|
|
934
|
-
│ Vector4 │ 2000 │ '
|
|
935
|
-
│ Matrix4 │ 2000 │ '
|
|
936
|
-
│ Literal_String │ 2000 │ '
|
|
937
|
-
│ Literal_Number │ 2000 │ '
|
|
938
|
-
│ Literal_Boolean │ 2000 │ '
|
|
939
|
-
│ Array_Number │ 2000 │ '
|
|
940
|
-
│ Array_String │ 2000 │ '
|
|
941
|
-
│ Array_Boolean │ 2000 │ '
|
|
942
|
-
│ Array_ObjectA │ 2000 │ '
|
|
943
|
-
│ Array_ObjectB │ 2000 │ '
|
|
944
|
-
│ Array_Tuple │ 2000 │ '
|
|
945
|
-
│ Array_Union │ 2000 │ '
|
|
946
|
-
│ Array_Vector4 │ 2000 │ '
|
|
947
|
-
│ Array_Matrix4 │ 2000 │ '
|
|
925
|
+
│ Number │ 2000 │ ' 384 ms' │ ' 7 ms' │ ' 54.86 x' │
|
|
926
|
+
│ String │ 2000 │ ' 311 ms' │ ' 6 ms' │ ' 51.83 x' │
|
|
927
|
+
│ Boolean │ 2000 │ ' 304 ms' │ ' 5 ms' │ ' 60.80 x' │
|
|
928
|
+
│ Null │ 2000 │ ' 252 ms' │ ' 5 ms' │ ' 50.40 x' │
|
|
929
|
+
│ RegEx │ 2000 │ ' 480 ms' │ ' 7 ms' │ ' 68.57 x' │
|
|
930
|
+
│ ObjectA │ 2000 │ ' 2786 ms' │ ' 27 ms' │ ' 103.19 x' │
|
|
931
|
+
│ ObjectB │ 2000 │ ' 2946 ms' │ ' 22 ms' │ ' 133.91 x' │
|
|
932
|
+
│ Tuple │ 2000 │ ' 1277 ms' │ ' 16 ms' │ ' 79.81 x' │
|
|
933
|
+
│ Union │ 2000 │ ' 1288 ms' │ ' 16 ms' │ ' 80.50 x' │
|
|
934
|
+
│ Vector4 │ 2000 │ ' 1628 ms' │ ' 12 ms' │ ' 135.67 x' │
|
|
935
|
+
│ Matrix4 │ 2000 │ ' 912 ms' │ ' 7 ms' │ ' 130.29 x' │
|
|
936
|
+
│ Literal_String │ 2000 │ ' 344 ms' │ ' 5 ms' │ ' 68.80 x' │
|
|
937
|
+
│ Literal_Number │ 2000 │ ' 432 ms' │ ' 5 ms' │ ' 86.40 x' │
|
|
938
|
+
│ Literal_Boolean │ 2000 │ ' 407 ms' │ ' 4 ms' │ ' 101.75 x' │
|
|
939
|
+
│ Array_Number │ 2000 │ ' 788 ms' │ ' 9 ms' │ ' 87.56 x' │
|
|
940
|
+
│ Array_String │ 2000 │ ' 823 ms' │ ' 7 ms' │ ' 117.57 x' │
|
|
941
|
+
│ Array_Boolean │ 2000 │ ' 816 ms' │ ' 5 ms' │ ' 163.20 x' │
|
|
942
|
+
│ Array_ObjectA │ 2000 │ ' 4270 ms' │ ' 24 ms' │ ' 177.92 x' │
|
|
943
|
+
│ Array_ObjectB │ 2000 │ ' 4008 ms' │ ' 28 ms' │ ' 143.14 x' │
|
|
944
|
+
│ Array_Tuple │ 2000 │ ' 2243 ms' │ ' 13 ms' │ ' 172.54 x' │
|
|
945
|
+
│ Array_Union │ 2000 │ ' 1734 ms' │ ' 16 ms' │ ' 108.38 x' │
|
|
946
|
+
│ Array_Vector4 │ 2000 │ ' 2348 ms' │ ' 14 ms' │ ' 167.71 x' │
|
|
947
|
+
│ Array_Matrix4 │ 2000 │ ' 1608 ms' │ ' 11 ms' │ ' 146.18 x' │
|
|
948
948
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
949
949
|
```
|
|
950
950
|
|
package/value/check.js
CHANGED
|
@@ -201,7 +201,7 @@ var ValueCheck;
|
|
|
201
201
|
return true;
|
|
202
202
|
}
|
|
203
203
|
function Tuple(schema, references, value) {
|
|
204
|
-
if (!
|
|
204
|
+
if (!globalThis.Array.isArray(value)) {
|
|
205
205
|
return false;
|
|
206
206
|
}
|
|
207
207
|
if (schema.items === undefined && !(value.length === 0)) {
|
package/value/errors.js
CHANGED
|
@@ -195,7 +195,7 @@ var ValueErrors;
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
function* Tuple(schema, references, path, value) {
|
|
198
|
-
if (!
|
|
198
|
+
if (!globalThis.Array.isArray(value)) {
|
|
199
199
|
return yield { schema, path, value, message: 'Expected Array' };
|
|
200
200
|
}
|
|
201
201
|
if (schema.items === undefined && !(value.length === 0)) {
|