@sinclair/typebox 0.23.4 → 0.24.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/compiler/compiler.d.ts +25 -0
- package/compiler/compiler.js +347 -0
- package/compiler/index.d.ts +1 -0
- package/compiler/index.js +40 -0
- package/license +1 -1
- package/package.json +6 -6
- package/readme.md +377 -361
- package/typebox.d.ts +306 -296
- package/typebox.js +247 -260
- package/value/check.d.ts +5 -0
- package/value/check.js +232 -0
- package/value/clone.d.ts +3 -0
- package/value/clone.js +94 -0
- package/value/create.d.ts +7 -0
- package/value/create.js +337 -0
- package/value/delta.d.ts +13 -0
- package/value/delta.js +191 -0
- package/value/index.d.ts +1 -0
- package/value/index.js +40 -0
- package/value/pointer.d.ts +12 -0
- package/value/pointer.js +110 -0
- package/value/reflect.d.ts +2 -0
- package/value/reflect.js +42 -0
- package/value/upcast.d.ts +4 -0
- package/value/upcast.js +247 -0
- package/value/value.d.ts +17 -0
- package/value/value.js +70 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Types from '../typebox';
|
|
2
|
+
export declare type CheckFunction = (value: unknown) => boolean;
|
|
3
|
+
export declare class TypeCheckAssertError extends Error {
|
|
4
|
+
readonly schema: Types.TSchema;
|
|
5
|
+
readonly value: unknown;
|
|
6
|
+
constructor(schema: Types.TSchema, value: unknown);
|
|
7
|
+
}
|
|
8
|
+
export declare class TypeCheck<T extends Types.TSchema> {
|
|
9
|
+
private readonly schema;
|
|
10
|
+
private readonly checkFunc;
|
|
11
|
+
constructor(schema: T, checkFunc: CheckFunction);
|
|
12
|
+
/** Returns true if the value is valid. */
|
|
13
|
+
Check(value: unknown): value is Types.Static<T>;
|
|
14
|
+
/** Asserts the given value and throws a TypeCheckAssertError if invalid. */
|
|
15
|
+
Assert(value: unknown): void;
|
|
16
|
+
}
|
|
17
|
+
export declare namespace TypeCompiler {
|
|
18
|
+
interface Condition {
|
|
19
|
+
schema: Types.TSchema;
|
|
20
|
+
expr: string;
|
|
21
|
+
path: string;
|
|
22
|
+
}
|
|
23
|
+
/** Compiles a type into validation function */
|
|
24
|
+
function Compile<T extends Types.TSchema>(schema: T, additional?: Types.TSchema[]): TypeCheck<T>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
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.TypeCompiler = exports.TypeCheck = exports.TypeCheckAssertError = void 0;
|
|
31
|
+
const Types = require("../typebox");
|
|
32
|
+
// -------------------------------------------------------------------
|
|
33
|
+
// TypeCheck
|
|
34
|
+
// -------------------------------------------------------------------
|
|
35
|
+
class TypeCheckAssertError extends Error {
|
|
36
|
+
schema;
|
|
37
|
+
value;
|
|
38
|
+
constructor(schema, value) {
|
|
39
|
+
super(`TypeCheckAssertError`);
|
|
40
|
+
this.schema = Types.Type.Strict(schema);
|
|
41
|
+
this.value = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.TypeCheckAssertError = TypeCheckAssertError;
|
|
45
|
+
class TypeCheck {
|
|
46
|
+
schema;
|
|
47
|
+
checkFunc;
|
|
48
|
+
constructor(schema, checkFunc) {
|
|
49
|
+
this.schema = schema;
|
|
50
|
+
this.checkFunc = checkFunc;
|
|
51
|
+
}
|
|
52
|
+
/** Returns true if the value is valid. */
|
|
53
|
+
Check(value) {
|
|
54
|
+
return this.checkFunc(value);
|
|
55
|
+
}
|
|
56
|
+
/** Asserts the given value and throws a TypeCheckAssertError if invalid. */
|
|
57
|
+
Assert(value) {
|
|
58
|
+
// The return type for this function should be 'asserts value is Static<T>' but due
|
|
59
|
+
// to a limitation in TypeScript, this currently isn't possible. See issue below.
|
|
60
|
+
// https://github.com/microsoft/TypeScript/issues/36931
|
|
61
|
+
if (!this.checkFunc(value))
|
|
62
|
+
throw new TypeCheckAssertError(this.schema, value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.TypeCheck = TypeCheck;
|
|
66
|
+
// -------------------------------------------------------------------
|
|
67
|
+
// TypeCompiler
|
|
68
|
+
// -------------------------------------------------------------------
|
|
69
|
+
var TypeCompiler;
|
|
70
|
+
(function (TypeCompiler) {
|
|
71
|
+
// -------------------------------------------------------------------
|
|
72
|
+
// Condition
|
|
73
|
+
// -------------------------------------------------------------------
|
|
74
|
+
function CreateCondition(schema, path, expr) {
|
|
75
|
+
return { schema, path, expr };
|
|
76
|
+
}
|
|
77
|
+
// -------------------------------------------------------------------
|
|
78
|
+
// Schemas
|
|
79
|
+
// -------------------------------------------------------------------
|
|
80
|
+
function* Any(schema, path) {
|
|
81
|
+
yield CreateCondition(schema, path, '(true)');
|
|
82
|
+
}
|
|
83
|
+
function* Array(schema, path) {
|
|
84
|
+
const expr = [...Visit(schema.items, `value`)].map((condition) => condition.expr).join(' && ');
|
|
85
|
+
yield CreateCondition(schema, path, `(Array.isArray(${path}) && ${path}.every(value => ${expr}))`);
|
|
86
|
+
}
|
|
87
|
+
function* Boolean(schema, path) {
|
|
88
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'boolean')`);
|
|
89
|
+
}
|
|
90
|
+
function* Constructor(schema, path) {
|
|
91
|
+
yield* Visit(schema.yields, path);
|
|
92
|
+
}
|
|
93
|
+
function* Function(schema, path) {
|
|
94
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'function')`);
|
|
95
|
+
}
|
|
96
|
+
function* Integer(schema, path) {
|
|
97
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'number' && Number.isInteger(${path}))`);
|
|
98
|
+
if (schema.multipleOf)
|
|
99
|
+
yield CreateCondition(schema, path, `(${path} % ${schema.multipleOf} === 0)`);
|
|
100
|
+
if (schema.exclusiveMinimum)
|
|
101
|
+
yield CreateCondition(schema, path, `(${path} < ${schema.exclusiveMinimum})`);
|
|
102
|
+
if (schema.exclusiveMaximum)
|
|
103
|
+
yield CreateCondition(schema, path, `(${path} < ${schema.exclusiveMaximum})`);
|
|
104
|
+
if (schema.minimum)
|
|
105
|
+
yield CreateCondition(schema, path, `(${path} >= ${schema.minimum})`);
|
|
106
|
+
if (schema.maximum)
|
|
107
|
+
yield CreateCondition(schema, path, `(${path} <= ${schema.maximum})`);
|
|
108
|
+
}
|
|
109
|
+
function* Literal(schema, path) {
|
|
110
|
+
if (typeof schema.const === 'string') {
|
|
111
|
+
yield CreateCondition(schema, path, `(${path} === '${schema.const}')`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
yield CreateCondition(schema, path, `(${path} === ${schema.const})`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function* Null(schema, path) {
|
|
118
|
+
yield CreateCondition(schema, path, `(${path} === null)`);
|
|
119
|
+
}
|
|
120
|
+
function* Number(schema, path) {
|
|
121
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'number')`);
|
|
122
|
+
if (schema.multipleOf)
|
|
123
|
+
yield CreateCondition(schema, path, `(${path} % ${schema.multipleOf} === 0)`);
|
|
124
|
+
if (schema.exclusiveMinimum)
|
|
125
|
+
yield CreateCondition(schema, path, `(${path} < ${schema.exclusiveMinimum})`);
|
|
126
|
+
if (schema.exclusiveMaximum)
|
|
127
|
+
yield CreateCondition(schema, path, `(${path} < ${schema.exclusiveMaximum})`);
|
|
128
|
+
if (schema.minimum)
|
|
129
|
+
yield CreateCondition(schema, path, `(${path} >= ${schema.minimum})`);
|
|
130
|
+
if (schema.maximum)
|
|
131
|
+
yield CreateCondition(schema, path, `(${path} <= ${schema.maximum})`);
|
|
132
|
+
}
|
|
133
|
+
function* Object(schema, path) {
|
|
134
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'object' && ${path} !== null && !Array.isArray(${path}))`);
|
|
135
|
+
if (schema.minProperties !== undefined)
|
|
136
|
+
yield CreateCondition(schema, path, `(Object.keys(${path}).length >= ${schema.minProperties})`);
|
|
137
|
+
if (schema.maxProperties !== undefined)
|
|
138
|
+
yield CreateCondition(schema, path, `(Object.keys(${path}).length <= ${schema.maxProperties})`);
|
|
139
|
+
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
140
|
+
if (schema.additionalProperties === false) {
|
|
141
|
+
// optimization: If the property key length matches the required keys length
|
|
142
|
+
// then we only need check that the values property key length matches that
|
|
143
|
+
// of the property key length. This is because exhaustive testing for values
|
|
144
|
+
// will occur in subsequent property tests.
|
|
145
|
+
if (schema.required && schema.required.length === propertyKeys.length) {
|
|
146
|
+
yield CreateCondition(schema, path, `(Object.keys(${path}).length === ${propertyKeys.length})`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const keys = `[${propertyKeys.map((key) => `'${key}'`).join(', ')}]`;
|
|
150
|
+
yield CreateCondition(schema, path, `(Object.keys(${path}).every(key => ${keys}.includes(key)))`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const propertyKey of propertyKeys) {
|
|
154
|
+
const propertySchema = schema.properties[propertyKey];
|
|
155
|
+
if (schema.required && schema.required.includes(propertyKey)) {
|
|
156
|
+
yield* Visit(propertySchema, `${path}.${propertyKey}`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const expr = [...Visit(propertySchema, `${path}.${propertyKey}`)].map((condition) => condition.expr).join(' && ');
|
|
160
|
+
yield CreateCondition(schema, `${path}.${propertyKey}`, `(${path}.${propertyKey} === undefined ? true : (${expr}))`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function* Promise(schema, path) {
|
|
165
|
+
yield CreateCondition(schema, path, `(typeof value === 'object' && typeof ${path}.then === 'function')`);
|
|
166
|
+
}
|
|
167
|
+
function* Record(schema, path) {
|
|
168
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'object' && ${path} !== null && !Array.isArray(${path}))`);
|
|
169
|
+
const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
|
|
170
|
+
const local = PushLocal(`const local = new RegExp(/${keyPattern}/)`);
|
|
171
|
+
yield CreateCondition(schema, path, `(Object.keys(${path}).every(key => ${local}.test(key)))`);
|
|
172
|
+
const expr = [...Visit(valueSchema, 'value')].map((cond) => cond.expr).join(' && ');
|
|
173
|
+
yield CreateCondition(schema, path, `(Object.values(${path}).every(value => ${expr}))`);
|
|
174
|
+
}
|
|
175
|
+
function* Ref(schema, path) {
|
|
176
|
+
// reference: referenced schemas can originate from either additional
|
|
177
|
+
// schemas or inline in the schema itself. Ideally the recursive
|
|
178
|
+
// path should align to reference path. Consider for review.
|
|
179
|
+
if (!functionNames.has(schema.$ref)) {
|
|
180
|
+
const reference = referenceMap.get(schema.$ref);
|
|
181
|
+
functionNames.add(schema.$ref);
|
|
182
|
+
const conditions = [...Visit(reference, 'value')];
|
|
183
|
+
const name = CreateFunctionName(schema.$ref);
|
|
184
|
+
const body = CreateFunction(name, conditions);
|
|
185
|
+
PushLocal(body);
|
|
186
|
+
}
|
|
187
|
+
const func = CreateFunctionName(schema.$ref);
|
|
188
|
+
yield CreateCondition(schema, path, `(${func}(${path}))`);
|
|
189
|
+
}
|
|
190
|
+
function* Self(schema, path) {
|
|
191
|
+
const func = CreateFunctionName(schema.$ref);
|
|
192
|
+
yield CreateCondition(schema, path, `(${func}(${path}))`);
|
|
193
|
+
}
|
|
194
|
+
function* String(schema, path) {
|
|
195
|
+
yield CreateCondition(schema, path, `(typeof ${path} === 'string')`);
|
|
196
|
+
if (schema.pattern !== undefined) {
|
|
197
|
+
const local = PushLocal(`const local = new RegExp('${schema.pattern}');`);
|
|
198
|
+
yield CreateCondition(schema, path, `(${local}.test(${path}))`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function* Tuple(schema, path) {
|
|
202
|
+
yield CreateCondition(schema, path, `(Array.isArray(${path}))`);
|
|
203
|
+
if (schema.items === undefined)
|
|
204
|
+
return yield CreateCondition(schema, path, `(${path}.length === 0)`);
|
|
205
|
+
yield CreateCondition(schema, path, `(${path}.length === ${schema.maxItems})`);
|
|
206
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
207
|
+
const expr = [...Visit(schema.items[i], `${path}[${i}]`)].map((condition) => condition.expr).join(' && ');
|
|
208
|
+
yield CreateCondition(schema, path, `(${expr})`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function* Undefined(schema, path) {
|
|
212
|
+
yield CreateCondition(schema, path, `${path} === undefined`);
|
|
213
|
+
}
|
|
214
|
+
function* Union(schema, path) {
|
|
215
|
+
const exprs = schema.anyOf.map((schema) => [...Visit(schema, path)].map((cond) => cond.expr).join(' && '));
|
|
216
|
+
yield CreateCondition(schema, path, `(${exprs.join(' || ')})`);
|
|
217
|
+
}
|
|
218
|
+
function* Uint8Array(schema, path) {
|
|
219
|
+
yield CreateCondition(schema, path, `(${path} instanceof Uint8Array)`);
|
|
220
|
+
if (schema.maxByteLength)
|
|
221
|
+
yield CreateCondition(schema, path, `(${path}.length <= ${schema.maxByteLength})`);
|
|
222
|
+
if (schema.minByteLength)
|
|
223
|
+
yield CreateCondition(schema, path, `(${path}.length >= ${schema.minByteLength})`);
|
|
224
|
+
}
|
|
225
|
+
function* Unknown(schema, path) {
|
|
226
|
+
yield CreateCondition(schema, path, '(true)');
|
|
227
|
+
}
|
|
228
|
+
function* Void(schema, path) {
|
|
229
|
+
yield CreateCondition(schema, path, `(${path} === null)`);
|
|
230
|
+
}
|
|
231
|
+
function* Visit(schema, path) {
|
|
232
|
+
// reference: referenced schemas can originate from either additional
|
|
233
|
+
// schemas or inline in the schema itself. Ideally the recursive
|
|
234
|
+
// path should align to reference path. Consider for review.
|
|
235
|
+
if (schema.$id && !functionNames.has(schema.$id)) {
|
|
236
|
+
functionNames.add(schema.$id);
|
|
237
|
+
const conditions = [...Visit(schema, 'value')];
|
|
238
|
+
const name = CreateFunctionName(schema.$id);
|
|
239
|
+
const body = CreateFunction(name, conditions);
|
|
240
|
+
PushLocal(body);
|
|
241
|
+
yield CreateCondition(schema, path, `(${name}(${path}))`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const anySchema = schema;
|
|
245
|
+
switch (anySchema[Types.Kind]) {
|
|
246
|
+
case 'Any':
|
|
247
|
+
return yield* Any(anySchema, path);
|
|
248
|
+
case 'Array':
|
|
249
|
+
return yield* Array(anySchema, path);
|
|
250
|
+
case 'Boolean':
|
|
251
|
+
return yield* Boolean(anySchema, path);
|
|
252
|
+
case 'Constructor':
|
|
253
|
+
return yield* Constructor(anySchema, path);
|
|
254
|
+
case 'Function':
|
|
255
|
+
return yield* Function(anySchema, path);
|
|
256
|
+
case 'Integer':
|
|
257
|
+
return yield* Integer(anySchema, path);
|
|
258
|
+
case 'Literal':
|
|
259
|
+
return yield* Literal(anySchema, path);
|
|
260
|
+
case 'Null':
|
|
261
|
+
return yield* Null(anySchema, path);
|
|
262
|
+
case 'Number':
|
|
263
|
+
return yield* Number(anySchema, path);
|
|
264
|
+
case 'Object':
|
|
265
|
+
return yield* Object(anySchema, path);
|
|
266
|
+
case 'Promise':
|
|
267
|
+
return yield* Promise(anySchema, path);
|
|
268
|
+
case 'Record':
|
|
269
|
+
return yield* Record(anySchema, path);
|
|
270
|
+
case 'Ref':
|
|
271
|
+
return yield* Ref(anySchema, path);
|
|
272
|
+
case 'Self':
|
|
273
|
+
return yield* Self(anySchema, path);
|
|
274
|
+
case 'String':
|
|
275
|
+
return yield* String(anySchema, path);
|
|
276
|
+
case 'Tuple':
|
|
277
|
+
return yield* Tuple(anySchema, path);
|
|
278
|
+
case 'Undefined':
|
|
279
|
+
return yield* Undefined(anySchema, path);
|
|
280
|
+
case 'Union':
|
|
281
|
+
return yield* Union(anySchema, path);
|
|
282
|
+
case 'Uint8Array':
|
|
283
|
+
return yield* Uint8Array(anySchema, path);
|
|
284
|
+
case 'Unknown':
|
|
285
|
+
return yield* Unknown(anySchema, path);
|
|
286
|
+
case 'Void':
|
|
287
|
+
return yield* Void(anySchema, path);
|
|
288
|
+
default:
|
|
289
|
+
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// -------------------------------------------------------------------
|
|
293
|
+
// Locals
|
|
294
|
+
// -------------------------------------------------------------------
|
|
295
|
+
const referenceMap = new Map();
|
|
296
|
+
const functionLocals = new Set();
|
|
297
|
+
const functionNames = new Set();
|
|
298
|
+
function ClearLocals() {
|
|
299
|
+
functionLocals.clear();
|
|
300
|
+
functionNames.clear();
|
|
301
|
+
referenceMap.clear();
|
|
302
|
+
}
|
|
303
|
+
function PushReferences(schemas = []) {
|
|
304
|
+
for (const schema of schemas) {
|
|
305
|
+
if (!schema.$id)
|
|
306
|
+
throw Error(`Referenced schemas must specify an $id. Failed for '${JSON.stringify(schema)}'`);
|
|
307
|
+
if (referenceMap.has(schema.$id))
|
|
308
|
+
throw Error(`Duplicate schema $id detected for '${schema.$id}'`);
|
|
309
|
+
referenceMap.set(schema.$id, schema);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function PushLocal(code) {
|
|
313
|
+
const name = `local${functionLocals.size}`;
|
|
314
|
+
functionLocals.add(code.replace('local', name));
|
|
315
|
+
return name;
|
|
316
|
+
}
|
|
317
|
+
function GetLocals() {
|
|
318
|
+
return [...functionLocals.values()];
|
|
319
|
+
}
|
|
320
|
+
// -------------------------------------------------------------------
|
|
321
|
+
// Functions
|
|
322
|
+
// -------------------------------------------------------------------
|
|
323
|
+
function CreateFunctionName($id) {
|
|
324
|
+
return `check_${$id.replace(/-/g, '_')}`;
|
|
325
|
+
}
|
|
326
|
+
function CreateFunction(name, conditions) {
|
|
327
|
+
const statements = conditions.map((condition, index) => ` if(!${condition.expr}) { return false }`);
|
|
328
|
+
return `function ${name}(value) {\n${statements.join('\n')}\n return true\n}`;
|
|
329
|
+
}
|
|
330
|
+
// -------------------------------------------------------------------
|
|
331
|
+
// Compiler
|
|
332
|
+
// -------------------------------------------------------------------
|
|
333
|
+
function Build(schema, additional = []) {
|
|
334
|
+
ClearLocals();
|
|
335
|
+
PushReferences(additional);
|
|
336
|
+
const conditions = [...Visit(schema, 'value')]; // locals populated during yield
|
|
337
|
+
const locals = GetLocals();
|
|
338
|
+
return `${locals.join('\n')}\nreturn ${CreateFunction('check', conditions)}`;
|
|
339
|
+
}
|
|
340
|
+
/** Compiles a type into validation function */
|
|
341
|
+
function Compile(schema, additional = []) {
|
|
342
|
+
const code = Build(schema, additional);
|
|
343
|
+
const func = globalThis.Function(code);
|
|
344
|
+
return new TypeCheck(schema, func());
|
|
345
|
+
}
|
|
346
|
+
TypeCompiler.Compile = Compile;
|
|
347
|
+
})(TypeCompiler = exports.TypeCompiler || (exports.TypeCompiler = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compiler';
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
32
|
+
}) : (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
o[k2] = m[k];
|
|
35
|
+
}));
|
|
36
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
37
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
__exportStar(require("./compiler"), exports);
|
package/license
CHANGED
|
@@ -2,7 +2,7 @@ TypeBox: JSON Schema Type Builder with Static Type Resolution for TypeScript
|
|
|
2
2
|
|
|
3
3
|
The MIT License (MIT)
|
|
4
4
|
|
|
5
|
-
Copyright (c)
|
|
5
|
+
Copyright (c) 2022 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json-schema",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"clean": "hammer task clean",
|
|
21
|
+
"format": "hammer task format",
|
|
22
|
+
"start": "hammer task start",
|
|
23
|
+
"test": "hammer task test",
|
|
21
24
|
"build": "hammer task build",
|
|
22
|
-
"
|
|
23
|
-
"spec": "hammer task spec",
|
|
24
|
-
"spec:types": "hammer task spec_types",
|
|
25
|
-
"spec:schemas": "hammer task spec_schemas",
|
|
26
|
-
"test": "npm run spec"
|
|
25
|
+
"publish": "hammer task publish"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@sinclair/hammer": "^0.16.3",
|
|
@@ -34,6 +33,7 @@
|
|
|
34
33
|
"ajv-formats": "^2.1.1",
|
|
35
34
|
"chai": "^4.3.5",
|
|
36
35
|
"mocha": "^9.2.0",
|
|
36
|
+
"prettier": "^2.7.1",
|
|
37
37
|
"tsd": "^0.19.1",
|
|
38
38
|
"typescript": "^4.5.5"
|
|
39
39
|
}
|