@sinclair/typebox 0.24.7 → 0.24.10
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 +6 -5
- package/compiler/compiler.js +108 -101
- package/compiler/index.d.ts +1 -1
- package/compiler/index.js +0 -1
- package/package.json +1 -1
- package/readme.md +32 -19
- package/typebox.d.ts +1 -3
- package/typebox.js +1 -1
- package/value/cast.d.ts +5 -0
- package/value/cast.js +249 -0
- package/value/check.d.ts +2 -3
- package/value/check.js +181 -119
- package/value/create.d.ts +3 -4
- package/value/create.js +91 -101
- package/value/errors.d.ts +10 -0
- package/{compiler → value}/errors.js +77 -92
- package/value/index.d.ts +1 -0
- package/value/value.d.ts +17 -13
- package/value/value.js +20 -32
- package/compiler/errors.d.ts +0 -10
- package/value/clone.d.ts +0 -3
- package/value/clone.js +0 -94
- package/value/delta.d.ts +0 -13
- package/value/delta.js +0 -191
- package/value/pointer.d.ts +0 -12
- package/value/pointer.js +0 -110
- package/value/reflect.d.ts +0 -2
- package/value/reflect.js +0 -42
- package/value/upcast.d.ts +0 -4
- package/value/upcast.js +0 -247
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*--------------------------------------------------------------------------
|
|
3
3
|
|
|
4
|
-
@sinclair/typebox/
|
|
4
|
+
@sinclair/typebox/value
|
|
5
5
|
|
|
6
6
|
The MIT License (MIT)
|
|
7
7
|
|
|
@@ -27,33 +27,33 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
30
|
+
exports.ValueErrors = void 0;
|
|
31
31
|
const Types = require("../typebox");
|
|
32
|
-
var
|
|
33
|
-
(function (
|
|
34
|
-
function* Any(schema, path, value) { }
|
|
35
|
-
function* Array(schema, path, value) {
|
|
32
|
+
var ValueErrors;
|
|
33
|
+
(function (ValueErrors) {
|
|
34
|
+
function* Any(schema, references, path, value) { }
|
|
35
|
+
function* Array(schema, references, path, value) {
|
|
36
36
|
if (!globalThis.Array.isArray(value)) {
|
|
37
37
|
return yield { schema, path, value, message: `Expected array` };
|
|
38
38
|
}
|
|
39
39
|
for (let i = 0; i < value.length; i++) {
|
|
40
|
-
yield* Visit(schema.items, `${path}/${i}`, value[i]);
|
|
40
|
+
yield* Visit(schema.items, references, `${path}/${i}`, value[i]);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function* Boolean(schema, path, value) {
|
|
43
|
+
function* Boolean(schema, references, path, value) {
|
|
44
44
|
if (!(typeof value === 'boolean')) {
|
|
45
45
|
return yield { schema, path, value, message: `Expected boolean` };
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function* Constructor(schema, path, value) {
|
|
49
|
-
yield* Visit(schema.
|
|
48
|
+
function* Constructor(schema, references, path, value) {
|
|
49
|
+
yield* Visit(schema.returns, references, path, value);
|
|
50
50
|
}
|
|
51
|
-
function* Function(schema, path, value) {
|
|
51
|
+
function* Function(schema, references, path, value) {
|
|
52
52
|
if (!(typeof value === 'function')) {
|
|
53
53
|
return yield { schema, path, value, message: `Expected function` };
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function* Integer(schema, path, value) {
|
|
56
|
+
function* Integer(schema, references, path, value) {
|
|
57
57
|
if (!(typeof value === 'number')) {
|
|
58
58
|
return yield { schema, path, value, message: `Expected number` };
|
|
59
59
|
}
|
|
@@ -76,18 +76,18 @@ var TypeErrors;
|
|
|
76
76
|
yield { schema, path, value, message: `Expected number to be less or equal to ${schema.maximum}` };
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
function* Literal(schema, path, value) {
|
|
79
|
+
function* Literal(schema, references, path, value) {
|
|
80
80
|
if (!(value === schema.const)) {
|
|
81
81
|
const error = typeof schema.const === 'string' ? `'${schema.const}'` : schema.const;
|
|
82
82
|
return yield { schema, path, value, message: `Expected ${error}` };
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
function* Null(schema, path, value) {
|
|
85
|
+
function* Null(schema, references, path, value) {
|
|
86
86
|
if (!(value === null)) {
|
|
87
87
|
return yield { schema, path, value, message: `Expected null` };
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
function* Number(schema, path, value) {
|
|
90
|
+
function* Number(schema, references, path, value) {
|
|
91
91
|
if (!(typeof value === 'number')) {
|
|
92
92
|
return yield { schema, path, value, message: `Expected number` };
|
|
93
93
|
}
|
|
@@ -107,7 +107,7 @@ var TypeErrors;
|
|
|
107
107
|
yield { schema, path, value, message: `Expected number to be less or equal to ${schema.maximum}` };
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function* Object(schema, path, value) {
|
|
110
|
+
function* Object(schema, references, path, value) {
|
|
111
111
|
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
112
112
|
return yield { schema, path, value, message: `Expected object` };
|
|
113
113
|
}
|
|
@@ -119,37 +119,30 @@ var TypeErrors;
|
|
|
119
119
|
}
|
|
120
120
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
121
121
|
if (schema.additionalProperties === false) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// will occur in subsequent property tests.
|
|
126
|
-
if (schema.required && schema.required.length === propertyKeys.length && !(globalThis.Object.keys(value).length === propertyKeys.length)) {
|
|
127
|
-
yield { schema, path, value, message: 'Expected object must not have additional properties' };
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
if (!globalThis.Object.keys(value).every((key) => propertyKeys.includes(key))) {
|
|
131
|
-
yield { schema, path, value, message: 'Expected object must not have additional properties' };
|
|
122
|
+
for (const propKey of globalThis.Object.keys(value)) {
|
|
123
|
+
if (!propertyKeys.includes(propKey)) {
|
|
124
|
+
yield { schema, path: `${path}/${propKey}`, value: value[propKey], message: 'Unexpected property' };
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
128
|
for (const propertyKey of propertyKeys) {
|
|
136
129
|
const propertySchema = schema.properties[propertyKey];
|
|
137
130
|
if (schema.required && schema.required.includes(propertyKey)) {
|
|
138
|
-
yield* Visit(propertySchema, `${path}/${propertyKey}`, value[propertyKey]);
|
|
131
|
+
yield* Visit(propertySchema, references, `${path}/${propertyKey}`, value[propertyKey]);
|
|
139
132
|
}
|
|
140
133
|
else {
|
|
141
134
|
if (value[propertyKey] !== undefined) {
|
|
142
|
-
yield* Visit(propertySchema, `${path}/${propertyKey}`, value[propertyKey]);
|
|
135
|
+
yield* Visit(propertySchema, references, `${path}/${propertyKey}`, value[propertyKey]);
|
|
143
136
|
}
|
|
144
137
|
}
|
|
145
138
|
}
|
|
146
139
|
}
|
|
147
|
-
function* Promise(schema, path, value) {
|
|
140
|
+
function* Promise(schema, references, path, value) {
|
|
148
141
|
if (!(typeof value === 'object' && typeof value.then === 'function')) {
|
|
149
142
|
yield { schema, path, value, message: `Expected Promise` };
|
|
150
143
|
}
|
|
151
144
|
}
|
|
152
|
-
function* Record(schema, path, value) {
|
|
145
|
+
function* Record(schema, references, path, value) {
|
|
153
146
|
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
154
147
|
return yield { schema, path, value, message: `Expected object` };
|
|
155
148
|
}
|
|
@@ -160,27 +153,31 @@ var TypeErrors;
|
|
|
160
153
|
return yield { schema, path, value, message };
|
|
161
154
|
}
|
|
162
155
|
for (const [propKey, propValue] of globalThis.Object.entries(value)) {
|
|
163
|
-
yield* Visit(valueSchema, `${path}/${propKey}`, propValue);
|
|
156
|
+
yield* Visit(valueSchema, references, `${path}/${propKey}`, propValue);
|
|
164
157
|
}
|
|
165
158
|
}
|
|
166
|
-
function* Ref(schema, path, value) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
yield* Visit(referencedSchema, path, value);
|
|
159
|
+
function* Ref(schema, references, path, value) {
|
|
160
|
+
const reference = references.find((reference) => reference.$id === schema.$ref);
|
|
161
|
+
if (reference === undefined)
|
|
162
|
+
throw new Error(`ValueErrors.Ref: Cannot find schema with $id '${schema.$ref}'.`);
|
|
163
|
+
yield* Visit(reference, references, path, value);
|
|
172
164
|
}
|
|
173
|
-
function* Self(schema, path, value) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
yield* Visit(referencedSchema, path, value);
|
|
165
|
+
function* Self(schema, references, path, value) {
|
|
166
|
+
const reference = references.find((reference) => reference.$id === schema.$ref);
|
|
167
|
+
if (reference === undefined)
|
|
168
|
+
throw new Error(`ValueErrors.Self: Cannot find schema with $id '${schema.$ref}'.`);
|
|
169
|
+
yield* Visit(reference, references, path, value);
|
|
179
170
|
}
|
|
180
|
-
function* String(schema, path, value) {
|
|
171
|
+
function* String(schema, references, path, value) {
|
|
181
172
|
if (!(typeof value === 'string')) {
|
|
182
173
|
return yield { schema, path, value, message: 'Expected string' };
|
|
183
174
|
}
|
|
175
|
+
if (schema.minLength !== undefined && !(value.length >= schema.minLength)) {
|
|
176
|
+
yield { schema, path, value, message: `Expected string length greater or equal to ${schema.minLength}` };
|
|
177
|
+
}
|
|
178
|
+
if (schema.maxLength !== undefined && !(value.length <= schema.maxLength)) {
|
|
179
|
+
yield { schema, path, value, message: `Expected string length less or equal to ${schema.maxLength}` };
|
|
180
|
+
}
|
|
184
181
|
if (schema.pattern !== undefined) {
|
|
185
182
|
const regex = new RegExp(schema.pattern);
|
|
186
183
|
if (!regex.test(value)) {
|
|
@@ -188,7 +185,7 @@ var TypeErrors;
|
|
|
188
185
|
}
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
|
-
function* Tuple(schema, path, value) {
|
|
188
|
+
function* Tuple(schema, references, path, value) {
|
|
192
189
|
if (!global.Array.isArray(value)) {
|
|
193
190
|
return yield { schema, path, value, message: 'Expected Array' };
|
|
194
191
|
}
|
|
@@ -202,18 +199,18 @@ var TypeErrors;
|
|
|
202
199
|
return;
|
|
203
200
|
}
|
|
204
201
|
for (let i = 0; i < schema.items.length; i++) {
|
|
205
|
-
yield* Visit(schema.items[i], `${path}/${i}`, value[i]);
|
|
202
|
+
yield* Visit(schema.items[i], references, `${path}/${i}`, value[i]);
|
|
206
203
|
}
|
|
207
204
|
}
|
|
208
|
-
function* Undefined(schema, path, value) {
|
|
205
|
+
function* Undefined(schema, references, path, value) {
|
|
209
206
|
if (!(value === undefined)) {
|
|
210
207
|
yield { schema, path, value, message: `Expected undefined` };
|
|
211
208
|
}
|
|
212
209
|
}
|
|
213
|
-
function* Union(schema, path, value) {
|
|
210
|
+
function* Union(schema, references, path, value) {
|
|
214
211
|
const errors = [];
|
|
215
212
|
for (const inner of schema.anyOf) {
|
|
216
|
-
const variantErrors = [...Visit(inner, path, value)];
|
|
213
|
+
const variantErrors = [...Visit(inner, references, path, value)];
|
|
217
214
|
if (variantErrors.length === 0)
|
|
218
215
|
return;
|
|
219
216
|
errors.push(...variantErrors);
|
|
@@ -225,7 +222,7 @@ var TypeErrors;
|
|
|
225
222
|
yield { schema, path, value, message: 'Expected value of union' };
|
|
226
223
|
}
|
|
227
224
|
}
|
|
228
|
-
function* Uint8Array(schema, path, value) {
|
|
225
|
+
function* Uint8Array(schema, references, path, value) {
|
|
229
226
|
if (!(value instanceof globalThis.Uint8Array)) {
|
|
230
227
|
return yield { schema, path, value, message: `Expected Uint8Array` };
|
|
231
228
|
}
|
|
@@ -236,76 +233,64 @@ var TypeErrors;
|
|
|
236
233
|
yield { schema, path, value, message: `Expected Uint8Array to have a byte length greater or equal to ${schema.maxByteLength}` };
|
|
237
234
|
}
|
|
238
235
|
}
|
|
239
|
-
function* Unknown(schema, path, value) { }
|
|
240
|
-
function* Void(schema, path, value) {
|
|
236
|
+
function* Unknown(schema, references, path, value) { }
|
|
237
|
+
function* Void(schema, references, path, value) {
|
|
241
238
|
if (!(value === null)) {
|
|
242
239
|
return yield { schema, path, value, message: `Expected null` };
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
|
-
function* Visit(schema, path, value) {
|
|
246
|
-
|
|
247
|
-
referenceMap.set(schema.$id, schema);
|
|
248
|
-
}
|
|
242
|
+
function* Visit(schema, references, path, value) {
|
|
243
|
+
const anyReferences = schema.$id === undefined ? references : [schema, ...references];
|
|
249
244
|
const anySchema = schema;
|
|
250
245
|
switch (anySchema[Types.Kind]) {
|
|
251
246
|
case 'Any':
|
|
252
|
-
return yield* Any(anySchema, path, value);
|
|
247
|
+
return yield* Any(anySchema, anyReferences, path, value);
|
|
253
248
|
case 'Array':
|
|
254
|
-
return yield* Array(anySchema, path, value);
|
|
249
|
+
return yield* Array(anySchema, anyReferences, path, value);
|
|
255
250
|
case 'Boolean':
|
|
256
|
-
return yield* Boolean(anySchema, path, value);
|
|
251
|
+
return yield* Boolean(anySchema, anyReferences, path, value);
|
|
257
252
|
case 'Constructor':
|
|
258
|
-
return yield* Constructor(anySchema, path, value);
|
|
253
|
+
return yield* Constructor(anySchema, anyReferences, path, value);
|
|
259
254
|
case 'Function':
|
|
260
|
-
return yield* Function(anySchema, path, value);
|
|
255
|
+
return yield* Function(anySchema, anyReferences, path, value);
|
|
261
256
|
case 'Integer':
|
|
262
|
-
return yield* Integer(anySchema, path, value);
|
|
257
|
+
return yield* Integer(anySchema, anyReferences, path, value);
|
|
263
258
|
case 'Literal':
|
|
264
|
-
return yield* Literal(anySchema, path, value);
|
|
259
|
+
return yield* Literal(anySchema, anyReferences, path, value);
|
|
265
260
|
case 'Null':
|
|
266
|
-
return yield* Null(anySchema, path, value);
|
|
261
|
+
return yield* Null(anySchema, anyReferences, path, value);
|
|
267
262
|
case 'Number':
|
|
268
|
-
return yield* Number(anySchema, path, value);
|
|
263
|
+
return yield* Number(anySchema, anyReferences, path, value);
|
|
269
264
|
case 'Object':
|
|
270
|
-
return yield* Object(anySchema, path, value);
|
|
265
|
+
return yield* Object(anySchema, anyReferences, path, value);
|
|
271
266
|
case 'Promise':
|
|
272
|
-
return yield* Promise(anySchema, path, value);
|
|
267
|
+
return yield* Promise(anySchema, anyReferences, path, value);
|
|
273
268
|
case 'Record':
|
|
274
|
-
return yield* Record(anySchema, path, value);
|
|
269
|
+
return yield* Record(anySchema, anyReferences, path, value);
|
|
275
270
|
case 'Ref':
|
|
276
|
-
return yield* Ref(anySchema, path, value);
|
|
271
|
+
return yield* Ref(anySchema, anyReferences, path, value);
|
|
277
272
|
case 'Self':
|
|
278
|
-
return yield* Self(anySchema, path, value);
|
|
273
|
+
return yield* Self(anySchema, anyReferences, path, value);
|
|
279
274
|
case 'String':
|
|
280
|
-
return yield* String(anySchema, path, value);
|
|
275
|
+
return yield* String(anySchema, anyReferences, path, value);
|
|
281
276
|
case 'Tuple':
|
|
282
|
-
return yield* Tuple(anySchema, path, value);
|
|
277
|
+
return yield* Tuple(anySchema, anyReferences, path, value);
|
|
283
278
|
case 'Undefined':
|
|
284
|
-
return yield* Undefined(anySchema, path, value);
|
|
279
|
+
return yield* Undefined(anySchema, anyReferences, path, value);
|
|
285
280
|
case 'Union':
|
|
286
|
-
return yield* Union(anySchema, path, value);
|
|
281
|
+
return yield* Union(anySchema, anyReferences, path, value);
|
|
287
282
|
case 'Uint8Array':
|
|
288
|
-
return yield* Uint8Array(anySchema, path, value);
|
|
283
|
+
return yield* Uint8Array(anySchema, anyReferences, path, value);
|
|
289
284
|
case 'Unknown':
|
|
290
|
-
return yield* Unknown(anySchema, path, value);
|
|
285
|
+
return yield* Unknown(anySchema, anyReferences, path, value);
|
|
291
286
|
case 'Void':
|
|
292
|
-
return yield* Void(anySchema, path, value);
|
|
287
|
+
return yield* Void(anySchema, anyReferences, path, value);
|
|
293
288
|
default:
|
|
294
|
-
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const referenceMap = new Map();
|
|
298
|
-
function SetAdditional(additional = []) {
|
|
299
|
-
referenceMap.clear();
|
|
300
|
-
for (const schema of additional) {
|
|
301
|
-
if (!schema.$id)
|
|
302
|
-
throw Error('TypeErrors: Referenced additional schemas must have an $id');
|
|
303
|
-
referenceMap.set(schema.$id, schema);
|
|
289
|
+
throw new Error(`ValueErrors: Unknown schema kind '${schema[Types.Kind]}'`);
|
|
304
290
|
}
|
|
305
291
|
}
|
|
306
|
-
function* Errors(schema,
|
|
307
|
-
|
|
308
|
-
yield* Visit(schema, '', value);
|
|
292
|
+
function* Errors(schema, references, value) {
|
|
293
|
+
yield* Visit(schema, references, '', value);
|
|
309
294
|
}
|
|
310
|
-
|
|
311
|
-
})(
|
|
295
|
+
ValueErrors.Errors = Errors;
|
|
296
|
+
})(ValueErrors = exports.ValueErrors || (exports.ValueErrors = {}));
|
package/value/index.d.ts
CHANGED
package/value/value.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import * as Types from '../typebox';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ValueError } from './errors';
|
|
3
|
+
/** Creates Values from TypeBox Types */
|
|
4
4
|
export declare namespace Value {
|
|
5
|
-
/**
|
|
6
|
-
function
|
|
7
|
-
/**
|
|
8
|
-
function Clone<T>(value: T): T;
|
|
9
|
-
/** Creates a value from the given schema type */
|
|
5
|
+
/** Creates a value from the given type */
|
|
6
|
+
function Create<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R]): Types.Static<T>;
|
|
7
|
+
/** Creates a value from the given type */
|
|
10
8
|
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
11
|
-
/**
|
|
12
|
-
function
|
|
13
|
-
/**
|
|
14
|
-
function
|
|
15
|
-
/**
|
|
16
|
-
function
|
|
9
|
+
/** Checks a value matches the given type */
|
|
10
|
+
function Check<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): value is Types.Static<T>;
|
|
11
|
+
/** Checks a value matches the given type */
|
|
12
|
+
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
13
|
+
/** Casts a value into a structure matching the given type. The result will be a new value that retains as much information of the original value as possible. */
|
|
14
|
+
function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): Types.Static<T>;
|
|
15
|
+
/** Casts a value into a structure matching the given type. The result will be a new value that retains as much information of the original value as possible. */
|
|
16
|
+
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
17
|
+
/** Returns an iterator for each error in this value. */
|
|
18
|
+
function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): IterableIterator<ValueError>;
|
|
19
|
+
/** Returns an iterator for each error in this value. */
|
|
20
|
+
function Errors<T extends Types.TSchema>(schema: T, value: unknown): IterableIterator<ValueError>;
|
|
17
21
|
}
|
package/value/value.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*--------------------------------------------------------------------------
|
|
3
3
|
|
|
4
|
-
@sinclair/typebox
|
|
4
|
+
@sinclair/typebox/value
|
|
5
5
|
|
|
6
6
|
The MIT License (MIT)
|
|
7
7
|
|
|
@@ -27,44 +27,32 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Value =
|
|
30
|
+
exports.Value = void 0;
|
|
31
|
+
const errors_1 = require("./errors");
|
|
32
|
+
const cast_1 = require("./cast");
|
|
31
33
|
const create_1 = require("./create");
|
|
32
34
|
const check_1 = require("./check");
|
|
33
|
-
|
|
34
|
-
const delta_1 = require("./delta");
|
|
35
|
-
const upcast_1 = require("./upcast");
|
|
36
|
-
var delta_2 = require("./delta");
|
|
37
|
-
Object.defineProperty(exports, "EditType", { enumerable: true, get: function () { return delta_2.EditType; } });
|
|
35
|
+
/** Creates Values from TypeBox Types */
|
|
38
36
|
var Value;
|
|
39
37
|
(function (Value) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
Value.Check = Check;
|
|
45
|
-
/** Returns a deep clone of the given value */
|
|
46
|
-
function Clone(value) {
|
|
47
|
-
return clone_1.CloneValue.Create(value);
|
|
48
|
-
}
|
|
49
|
-
Value.Clone = Clone;
|
|
50
|
-
/** Creates a value from the given schema type */
|
|
51
|
-
function Create(schema) {
|
|
52
|
-
return create_1.CreateValue.Create(schema);
|
|
38
|
+
function Create(...args) {
|
|
39
|
+
const [schema, references] = args.length === 2 ? [args[0], args[1]] : [args[0], []];
|
|
40
|
+
return create_1.ValueCreate.Create(schema, references);
|
|
53
41
|
}
|
|
54
42
|
Value.Create = Create;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
43
|
+
function Check(...args) {
|
|
44
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
45
|
+
return check_1.ValueCheck.Check(schema, references, value);
|
|
58
46
|
}
|
|
59
|
-
Value.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
47
|
+
Value.Check = Check;
|
|
48
|
+
function Cast(...args) {
|
|
49
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
50
|
+
return cast_1.ValueCast.Cast(schema, references, value);
|
|
63
51
|
}
|
|
64
|
-
Value.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
Value.Cast = Cast;
|
|
53
|
+
function* Errors(...args) {
|
|
54
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
55
|
+
yield* errors_1.ValueErrors.Errors(schema, references, value);
|
|
68
56
|
}
|
|
69
|
-
Value.
|
|
57
|
+
Value.Errors = Errors;
|
|
70
58
|
})(Value = exports.Value || (exports.Value = {}));
|
package/compiler/errors.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as Types from '../typebox';
|
|
2
|
-
export interface TypeError {
|
|
3
|
-
schema: Types.TSchema;
|
|
4
|
-
path: string;
|
|
5
|
-
value: unknown;
|
|
6
|
-
message: string;
|
|
7
|
-
}
|
|
8
|
-
export declare namespace TypeErrors {
|
|
9
|
-
function Errors<T extends Types.TSchema>(schema: T, additional: Types.TSchema[], value: any): Generator<TypeError>;
|
|
10
|
-
}
|
package/value/clone.d.ts
DELETED
package/value/clone.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
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.CloneValue = void 0;
|
|
31
|
-
const reflect_1 = require("./reflect");
|
|
32
|
-
var CloneValue;
|
|
33
|
-
(function (CloneValue) {
|
|
34
|
-
function Undefined(_value) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
function Null(_value) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
function Function(value) {
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
function Object(value) {
|
|
44
|
-
return globalThis.Object.entries(value).reduce((acc, [key, value]) => {
|
|
45
|
-
return { ...acc, [key]: Create(value) };
|
|
46
|
-
}, {});
|
|
47
|
-
}
|
|
48
|
-
function Array(value) {
|
|
49
|
-
return value.map((element) => Create(element));
|
|
50
|
-
}
|
|
51
|
-
function BigInt(value) {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
function Symbol(value) {
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
function String(value) {
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
function Boolean(value) {
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
function Number(value) {
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
function Create(value) {
|
|
67
|
-
const typeName = (0, reflect_1.Reflect)(value);
|
|
68
|
-
switch (typeName) {
|
|
69
|
-
case 'array':
|
|
70
|
-
return Array(value);
|
|
71
|
-
case 'bigint':
|
|
72
|
-
return BigInt(value);
|
|
73
|
-
case 'boolean':
|
|
74
|
-
return Boolean(value);
|
|
75
|
-
case 'function':
|
|
76
|
-
return Function(value);
|
|
77
|
-
case 'null':
|
|
78
|
-
return Null(value);
|
|
79
|
-
case 'number':
|
|
80
|
-
return Number(value);
|
|
81
|
-
case 'object':
|
|
82
|
-
return Object(value);
|
|
83
|
-
case 'string':
|
|
84
|
-
return String(value);
|
|
85
|
-
case 'symbol':
|
|
86
|
-
return Symbol(value);
|
|
87
|
-
case 'undefined':
|
|
88
|
-
return Undefined(value);
|
|
89
|
-
default:
|
|
90
|
-
throw new Error(`Cannot clone from unknown typename ${typeName}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
CloneValue.Create = Create;
|
|
94
|
-
})(CloneValue = exports.CloneValue || (exports.CloneValue = {}));
|
package/value/delta.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare enum EditType {
|
|
2
|
-
Delete = 0,
|
|
3
|
-
Update = 1,
|
|
4
|
-
Insert = 2
|
|
5
|
-
}
|
|
6
|
-
export declare type Edit = Insert | Update | Delete;
|
|
7
|
-
export declare type Update = [EditType.Update, string, any];
|
|
8
|
-
export declare type Insert = [EditType.Insert, string, any];
|
|
9
|
-
export declare type Delete = [EditType.Delete, string];
|
|
10
|
-
export declare namespace DeltaValue {
|
|
11
|
-
function Diff(valueA: any, valueB: any): Edit[];
|
|
12
|
-
function Edit(valueA: any, operations: Edit[]): any;
|
|
13
|
-
}
|