@sinclair/typebox 0.25.23 → 0.26.0-dev

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.
Files changed (44) hide show
  1. package/compiler/compiler.d.ts +9 -4
  2. package/compiler/compiler.js +160 -119
  3. package/errors/errors.d.ts +56 -46
  4. package/errors/errors.js +234 -149
  5. package/package.json +1 -6
  6. package/readme.md +395 -396
  7. package/system/system.d.ts +9 -6
  8. package/system/system.js +17 -17
  9. package/typebox.d.ts +386 -162
  10. package/typebox.js +1710 -229
  11. package/value/cast.d.ts +2 -2
  12. package/value/cast.js +120 -192
  13. package/value/check.d.ts +1 -1
  14. package/value/check.js +162 -107
  15. package/value/convert.d.ts +13 -0
  16. package/value/convert.js +345 -0
  17. package/value/create.d.ts +6 -2
  18. package/value/create.js +149 -107
  19. package/{hash → value}/hash.js +39 -14
  20. package/value/index.d.ts +1 -0
  21. package/value/index.js +3 -1
  22. package/value/value.d.ts +2 -8
  23. package/value/value.js +20 -14
  24. package/conditional/conditional.d.ts +0 -17
  25. package/conditional/conditional.js +0 -91
  26. package/conditional/index.d.ts +0 -2
  27. package/conditional/index.js +0 -45
  28. package/conditional/structural.d.ts +0 -11
  29. package/conditional/structural.js +0 -685
  30. package/custom/custom.d.ts +0 -12
  31. package/custom/custom.js +0 -55
  32. package/custom/index.d.ts +0 -1
  33. package/custom/index.js +0 -44
  34. package/format/format.d.ts +0 -12
  35. package/format/format.js +0 -55
  36. package/format/index.d.ts +0 -1
  37. package/format/index.js +0 -44
  38. package/guard/guard.d.ts +0 -60
  39. package/guard/guard.js +0 -440
  40. package/guard/index.d.ts +0 -1
  41. package/guard/index.js +0 -44
  42. package/hash/index.d.ts +0 -1
  43. package/hash/index.js +0 -44
  44. /package/{hash → value}/hash.d.ts +0 -0
package/value/create.js CHANGED
@@ -27,9 +27,12 @@ THE SOFTWARE.
27
27
 
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.ValueCreate = exports.ValueCreateNeverTypeError = exports.ValueCreateUnknownTypeError = void 0;
30
+ exports.ValueCreate = exports.ValueCreateIntersectTypeError = exports.ValueCreateNeverTypeError = exports.ValueCreateUnknownTypeError = void 0;
31
31
  const Types = require("../typebox");
32
- const index_1 = require("../custom/index");
32
+ const check_1 = require("./check");
33
+ // --------------------------------------------------------------------------
34
+ // Errors
35
+ // --------------------------------------------------------------------------
33
36
  class ValueCreateUnknownTypeError extends Error {
34
37
  constructor(schema) {
35
38
  super('ValueCreate: Unknown type');
@@ -44,46 +47,64 @@ class ValueCreateNeverTypeError extends Error {
44
47
  }
45
48
  }
46
49
  exports.ValueCreateNeverTypeError = ValueCreateNeverTypeError;
50
+ class ValueCreateIntersectTypeError extends Error {
51
+ constructor(schema) {
52
+ super('ValueCreate: Can only create values for intersected objects and non-varying primitive types. Consider using a default value.');
53
+ this.schema = schema;
54
+ }
55
+ }
56
+ exports.ValueCreateIntersectTypeError = ValueCreateIntersectTypeError;
57
+ // --------------------------------------------------------------------------
58
+ // ValueCreate
59
+ // --------------------------------------------------------------------------
47
60
  var ValueCreate;
48
61
  (function (ValueCreate) {
49
- function Any(schema, references) {
50
- if (schema.default !== undefined) {
62
+ function Any(schema) {
63
+ if ('default' in schema) {
51
64
  return schema.default;
52
65
  }
53
66
  else {
54
67
  return {};
55
68
  }
56
69
  }
57
- function Array(schema, references) {
70
+ function Array(schema) {
58
71
  if (schema.uniqueItems === true && schema.default === undefined) {
59
72
  throw new Error('ValueCreate.Array: Arrays with uniqueItems require a default value');
60
73
  }
61
- else if (schema.default !== undefined) {
74
+ else if ('default' in schema) {
62
75
  return schema.default;
63
76
  }
64
77
  else if (schema.minItems !== undefined) {
65
78
  return globalThis.Array.from({ length: schema.minItems }).map((item) => {
66
- return ValueCreate.Create(schema.items, references);
79
+ return ValueCreate.Create(schema.items);
67
80
  });
68
81
  }
69
82
  else {
70
83
  return [];
71
84
  }
72
85
  }
73
- function Boolean(schema, references) {
74
- if (schema.default !== undefined) {
86
+ function BigInt(schema) {
87
+ if ('default' in schema) {
88
+ return schema.default;
89
+ }
90
+ else {
91
+ return globalThis.BigInt(0);
92
+ }
93
+ }
94
+ function Boolean(schema) {
95
+ if ('default' in schema) {
75
96
  return schema.default;
76
97
  }
77
98
  else {
78
99
  return false;
79
100
  }
80
101
  }
81
- function Constructor(schema, references) {
82
- if (schema.default !== undefined) {
102
+ function Constructor(schema) {
103
+ if ('default' in schema) {
83
104
  return schema.default;
84
105
  }
85
106
  else {
86
- const value = ValueCreate.Create(schema.returns, references);
107
+ const value = ValueCreate.Create(schema.returns);
87
108
  if (typeof value === 'object' && !globalThis.Array.isArray(value)) {
88
109
  return class {
89
110
  constructor() {
@@ -100,8 +121,8 @@ var ValueCreate;
100
121
  }
101
122
  }
102
123
  }
103
- function Date(schema, references) {
104
- if (schema.default !== undefined) {
124
+ function Date(schema) {
125
+ if ('default' in schema) {
105
126
  return schema.default;
106
127
  }
107
128
  else if (schema.minimumTimestamp !== undefined) {
@@ -111,16 +132,16 @@ var ValueCreate;
111
132
  return new globalThis.Date(0);
112
133
  }
113
134
  }
114
- function Function(schema, references) {
115
- if (schema.default !== undefined) {
135
+ function Function(schema) {
136
+ if ('default' in schema) {
116
137
  return schema.default;
117
138
  }
118
139
  else {
119
- return () => ValueCreate.Create(schema.returns, references);
140
+ return () => ValueCreate.Create(schema.returns);
120
141
  }
121
142
  }
122
- function Integer(schema, references) {
123
- if (schema.default !== undefined) {
143
+ function Integer(schema) {
144
+ if ('default' in schema) {
124
145
  return schema.default;
125
146
  }
126
147
  else if (schema.minimum !== undefined) {
@@ -130,27 +151,46 @@ var ValueCreate;
130
151
  return 0;
131
152
  }
132
153
  }
133
- function Literal(schema, references) {
134
- if (schema.default !== undefined) {
154
+ function Intersect(schema) {
155
+ if ('default' in schema) {
156
+ return schema.default;
157
+ }
158
+ else {
159
+ const value = schema.type === 'object' ? schema.allOf.reduce((acc, schema) => ({ ...acc, ...Visit(schema) }), {}) : schema.allOf.reduce((_, schema) => Visit(schema), undefined);
160
+ if (!check_1.ValueCheck.Check(schema, value))
161
+ throw new ValueCreateIntersectTypeError(schema);
162
+ return value;
163
+ }
164
+ }
165
+ function Literal(schema) {
166
+ if ('default' in schema) {
135
167
  return schema.default;
136
168
  }
137
169
  else {
138
170
  return schema.const;
139
171
  }
140
172
  }
141
- function Never(schema, references) {
173
+ function Never(schema) {
142
174
  throw new ValueCreateNeverTypeError(schema);
143
175
  }
144
- function Null(schema, references) {
145
- if (schema.default !== undefined) {
176
+ function Not(schema) {
177
+ if ('default' in schema) {
178
+ return schema.default;
179
+ }
180
+ else {
181
+ return Visit(schema.allOf[1]);
182
+ }
183
+ }
184
+ function Null(schema) {
185
+ if ('default' in schema) {
146
186
  return schema.default;
147
187
  }
148
188
  else {
149
189
  return null;
150
190
  }
151
191
  }
152
- function Number(schema, references) {
153
- if (schema.default !== undefined) {
192
+ function Number(schema) {
193
+ if ('default' in schema) {
154
194
  return schema.default;
155
195
  }
156
196
  else if (schema.minimum !== undefined) {
@@ -160,74 +200,60 @@ var ValueCreate;
160
200
  return 0;
161
201
  }
162
202
  }
163
- function Object(schema, references) {
164
- if (schema.default !== undefined) {
203
+ function Object(schema) {
204
+ if ('default' in schema) {
165
205
  return schema.default;
166
206
  }
167
207
  else {
168
208
  const required = new Set(schema.required);
169
209
  return (schema.default ||
170
210
  globalThis.Object.entries(schema.properties).reduce((acc, [key, schema]) => {
171
- return required.has(key) ? { ...acc, [key]: ValueCreate.Create(schema, references) } : { ...acc };
211
+ return required.has(key) ? { ...acc, [key]: ValueCreate.Create(schema) } : { ...acc };
172
212
  }, {}));
173
213
  }
174
214
  }
175
- function Promise(schema, references) {
176
- if (schema.default !== undefined) {
215
+ function Promise(schema) {
216
+ if ('default' in schema) {
177
217
  return schema.default;
178
218
  }
179
219
  else {
180
- return globalThis.Promise.resolve(ValueCreate.Create(schema.item, references));
220
+ return globalThis.Promise.resolve(ValueCreate.Create(schema.item));
181
221
  }
182
222
  }
183
- function Record(schema, references) {
223
+ function Record(schema) {
184
224
  const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
185
- if (schema.default !== undefined) {
225
+ if ('default' in schema) {
186
226
  return schema.default;
187
227
  }
188
228
  else if (!(keyPattern === '^.*$' || keyPattern === '^(0|[1-9][0-9]*)$')) {
189
229
  const propertyKeys = keyPattern.slice(1, keyPattern.length - 1).split('|');
190
230
  return propertyKeys.reduce((acc, key) => {
191
- return { ...acc, [key]: Create(valueSchema, references) };
231
+ return { ...acc, [key]: Create(valueSchema) };
192
232
  }, {});
193
233
  }
194
234
  else {
195
235
  return {};
196
236
  }
197
237
  }
198
- function Recursive(schema, references) {
199
- if (schema.default !== undefined) {
200
- return schema.default;
201
- }
202
- else {
203
- throw new Error('ValueCreate.Recursive: Recursive types require a default value');
204
- }
205
- }
206
- function Ref(schema, references) {
207
- if (schema.default !== undefined) {
238
+ function Ref(schema) {
239
+ if ('default' in schema) {
208
240
  return schema.default;
209
241
  }
210
242
  else {
211
- const reference = references.find((reference) => reference.$id === schema.$ref);
212
- if (reference === undefined)
213
- throw new Error(`ValueCreate.Ref: Cannot find schema with $id '${schema.$ref}'.`);
214
- return Visit(reference, references);
243
+ return Visit(Types.ReferenceRegistry.DerefOne(schema));
215
244
  }
216
245
  }
217
- function Self(schema, references) {
218
- if (schema.default !== undefined) {
246
+ function Self(schema) {
247
+ if ('default' in schema) {
219
248
  return schema.default;
220
249
  }
221
250
  else {
222
- const reference = references.find((reference) => reference.$id === schema.$ref);
223
- if (reference === undefined)
224
- throw new Error(`ValueCreate.Self: Cannot locate schema with $id '${schema.$ref}'`);
225
- return Visit(reference, references);
251
+ return Visit(Types.ReferenceRegistry.DerefOne(schema));
226
252
  }
227
253
  }
228
- function String(schema, references) {
254
+ function String(schema) {
229
255
  if (schema.pattern !== undefined) {
230
- if (schema.default === undefined) {
256
+ if (!('default' in schema)) {
231
257
  throw new Error('ValueCreate.String: String types with patterns must specify a default value');
232
258
  }
233
259
  else {
@@ -235,7 +261,7 @@ var ValueCreate;
235
261
  }
236
262
  }
237
263
  else if (schema.format !== undefined) {
238
- if (schema.default === undefined) {
264
+ if (!('default' in schema)) {
239
265
  throw new Error('ValueCreate.String: String types with formats must specify a default value');
240
266
  }
241
267
  else {
@@ -243,7 +269,7 @@ var ValueCreate;
243
269
  }
244
270
  }
245
271
  else {
246
- if (schema.default !== undefined) {
272
+ if ('default' in schema) {
247
273
  return schema.default;
248
274
  }
249
275
  else if (schema.minLength !== undefined) {
@@ -256,38 +282,49 @@ var ValueCreate;
256
282
  }
257
283
  }
258
284
  }
259
- function Tuple(schema, references) {
260
- if (schema.default !== undefined) {
285
+ function Symbol(schema) {
286
+ if ('default' in schema) {
287
+ return schema.default;
288
+ }
289
+ else if ('value' in schema) {
290
+ return globalThis.Symbol.for(schema.value);
291
+ }
292
+ else {
293
+ return globalThis.Symbol();
294
+ }
295
+ }
296
+ function Tuple(schema) {
297
+ if ('default' in schema) {
261
298
  return schema.default;
262
299
  }
263
300
  if (schema.items === undefined) {
264
301
  return [];
265
302
  }
266
303
  else {
267
- return globalThis.Array.from({ length: schema.minItems }).map((_, index) => ValueCreate.Create(schema.items[index], references));
304
+ return globalThis.Array.from({ length: schema.minItems }).map((_, index) => ValueCreate.Create(schema.items[index]));
268
305
  }
269
306
  }
270
- function Undefined(schema, references) {
271
- if (schema.default !== undefined) {
307
+ function Undefined(schema) {
308
+ if ('default' in schema) {
272
309
  return schema.default;
273
310
  }
274
311
  else {
275
312
  return undefined;
276
313
  }
277
314
  }
278
- function Union(schema, references) {
279
- if (schema.default !== undefined) {
315
+ function Union(schema) {
316
+ if ('default' in schema) {
280
317
  return schema.default;
281
318
  }
282
319
  else if (schema.anyOf.length === 0) {
283
320
  throw new Error('ValueCreate.Union: Cannot create Union with zero variants');
284
321
  }
285
322
  else {
286
- return ValueCreate.Create(schema.anyOf[0], references);
323
+ return ValueCreate.Create(schema.anyOf[0]);
287
324
  }
288
325
  }
289
- function Uint8Array(schema, references) {
290
- if (schema.default !== undefined) {
326
+ function Uint8Array(schema) {
327
+ if ('default' in schema) {
291
328
  return schema.default;
292
329
  }
293
330
  else if (schema.minByteLength !== undefined) {
@@ -297,24 +334,24 @@ var ValueCreate;
297
334
  return new globalThis.Uint8Array(0);
298
335
  }
299
336
  }
300
- function Unknown(schema, references) {
301
- if (schema.default !== undefined) {
337
+ function Unknown(schema) {
338
+ if ('default' in schema) {
302
339
  return schema.default;
303
340
  }
304
341
  else {
305
342
  return {};
306
343
  }
307
344
  }
308
- function Void(schema, references) {
309
- if (schema.default !== undefined) {
345
+ function Void(schema) {
346
+ if ('default' in schema) {
310
347
  return schema.default;
311
348
  }
312
349
  else {
313
- return null;
350
+ return void 0;
314
351
  }
315
352
  }
316
- function UserDefined(schema, references) {
317
- if (schema.default !== undefined) {
353
+ function UserDefined(schema) {
354
+ if ('default' in schema) {
318
355
  return schema.default;
319
356
  }
320
357
  else {
@@ -322,67 +359,72 @@ var ValueCreate;
322
359
  }
323
360
  }
324
361
  /** Creates a value from the given schema. If the schema specifies a default value, then that value is returned. */
325
- function Visit(schema, references) {
326
- const anyReferences = schema.$id === undefined ? references : [schema, ...references];
362
+ function Visit(schema) {
327
363
  const anySchema = schema;
328
364
  switch (anySchema[Types.Kind]) {
329
365
  case 'Any':
330
- return Any(anySchema, anyReferences);
366
+ return Any(anySchema);
331
367
  case 'Array':
332
- return Array(anySchema, anyReferences);
368
+ return Array(anySchema);
369
+ case 'BigInt':
370
+ return BigInt(anySchema);
333
371
  case 'Boolean':
334
- return Boolean(anySchema, anyReferences);
372
+ return Boolean(anySchema);
335
373
  case 'Constructor':
336
- return Constructor(anySchema, anyReferences);
374
+ return Constructor(anySchema);
337
375
  case 'Date':
338
- return Date(anySchema, anyReferences);
376
+ return Date(anySchema);
339
377
  case 'Function':
340
- return Function(anySchema, anyReferences);
378
+ return Function(anySchema);
341
379
  case 'Integer':
342
- return Integer(anySchema, anyReferences);
380
+ return Integer(anySchema);
381
+ case 'Intersect':
382
+ return Intersect(anySchema);
343
383
  case 'Literal':
344
- return Literal(anySchema, anyReferences);
384
+ return Literal(anySchema);
345
385
  case 'Never':
346
- return Never(anySchema, anyReferences);
386
+ return Never(anySchema);
387
+ case 'Not':
388
+ return Not(anySchema);
347
389
  case 'Null':
348
- return Null(anySchema, anyReferences);
390
+ return Null(anySchema);
349
391
  case 'Number':
350
- return Number(anySchema, anyReferences);
392
+ return Number(anySchema);
351
393
  case 'Object':
352
- return Object(anySchema, anyReferences);
394
+ return Object(anySchema);
353
395
  case 'Promise':
354
- return Promise(anySchema, anyReferences);
396
+ return Promise(anySchema);
355
397
  case 'Record':
356
- return Record(anySchema, anyReferences);
357
- case 'Rec':
358
- return Recursive(anySchema, anyReferences);
398
+ return Record(anySchema);
359
399
  case 'Ref':
360
- return Ref(anySchema, anyReferences);
400
+ return Ref(anySchema);
361
401
  case 'Self':
362
- return Self(anySchema, anyReferences);
402
+ return Self(anySchema);
363
403
  case 'String':
364
- return String(anySchema, anyReferences);
404
+ return String(anySchema);
405
+ case 'Symbol':
406
+ return Symbol(anySchema);
365
407
  case 'Tuple':
366
- return Tuple(anySchema, anyReferences);
408
+ return Tuple(anySchema);
367
409
  case 'Undefined':
368
- return Undefined(anySchema, anyReferences);
410
+ return Undefined(anySchema);
369
411
  case 'Union':
370
- return Union(anySchema, anyReferences);
412
+ return Union(anySchema);
371
413
  case 'Uint8Array':
372
- return Uint8Array(anySchema, anyReferences);
414
+ return Uint8Array(anySchema);
373
415
  case 'Unknown':
374
- return Unknown(anySchema, anyReferences);
416
+ return Unknown(anySchema);
375
417
  case 'Void':
376
- return Void(anySchema, anyReferences);
418
+ return Void(anySchema);
377
419
  default:
378
- if (!index_1.Custom.Has(anySchema[Types.Kind]))
420
+ if (!Types.TypeRegistry.Has(anySchema[Types.Kind]))
379
421
  throw new ValueCreateUnknownTypeError(anySchema);
380
- return UserDefined(anySchema, anyReferences);
422
+ return UserDefined(anySchema);
381
423
  }
382
424
  }
383
425
  ValueCreate.Visit = Visit;
384
- function Create(schema, references) {
385
- return Visit(schema, references);
426
+ function Create(schema) {
427
+ return Visit(schema);
386
428
  }
387
429
  ValueCreate.Create = Create;
388
430
  })(ValueCreate = exports.ValueCreate || (exports.ValueCreate = {}));
@@ -48,6 +48,8 @@ var ValueHash;
48
48
  ByteMarker[ByteMarker["Array"] = 6] = "Array";
49
49
  ByteMarker[ByteMarker["Date"] = 7] = "Date";
50
50
  ByteMarker[ByteMarker["Uint8Array"] = 8] = "Uint8Array";
51
+ ByteMarker[ByteMarker["Symbol"] = 9] = "Symbol";
52
+ ByteMarker[ByteMarker["BigInt"] = 10] = "BigInt";
51
53
  })(ByteMarker || (ByteMarker = {}));
52
54
  // ----------------------------------------------------
53
55
  // State
@@ -79,6 +81,12 @@ var ValueHash;
79
81
  function IsNumber(value) {
80
82
  return typeof value === 'number';
81
83
  }
84
+ function IsSymbol(value) {
85
+ return typeof value === 'symbol';
86
+ }
87
+ function IsBigInt(value) {
88
+ return typeof value === 'bigint';
89
+ }
82
90
  function IsObject(value) {
83
91
  return typeof value === 'object' && value !== null && !IsArray(value) && !IsDate(value) && !IsUint8Array(value);
84
92
  }
@@ -92,50 +100,61 @@ var ValueHash;
92
100
  // Encoding
93
101
  // ----------------------------------------------------
94
102
  function Array(value) {
95
- Fnv1A64(ByteMarker.Array);
103
+ FNV1A64(ByteMarker.Array);
96
104
  for (const item of value) {
97
105
  Visit(item);
98
106
  }
99
107
  }
100
108
  function Boolean(value) {
101
- Fnv1A64(ByteMarker.Boolean);
102
- Fnv1A64(value ? 1 : 0);
109
+ FNV1A64(ByteMarker.Boolean);
110
+ FNV1A64(value ? 1 : 0);
111
+ }
112
+ function BigInt(value) {
113
+ FNV1A64(ByteMarker.BigInt);
114
+ F64In.setBigInt64(0, value);
115
+ for (const byte of F64Out) {
116
+ FNV1A64(byte);
117
+ }
103
118
  }
104
119
  function Date(value) {
105
- Fnv1A64(ByteMarker.Date);
120
+ FNV1A64(ByteMarker.Date);
106
121
  Visit(value.getTime());
107
122
  }
108
123
  function Null(value) {
109
- Fnv1A64(ByteMarker.Null);
124
+ FNV1A64(ByteMarker.Null);
110
125
  }
111
126
  function Number(value) {
112
- Fnv1A64(ByteMarker.Number);
127
+ FNV1A64(ByteMarker.Number);
113
128
  F64In.setFloat64(0, value);
114
129
  for (const byte of F64Out) {
115
- Fnv1A64(byte);
130
+ FNV1A64(byte);
116
131
  }
117
132
  }
118
133
  function Object(value) {
119
- Fnv1A64(ByteMarker.Object);
134
+ FNV1A64(ByteMarker.Object);
120
135
  for (const key of globalThis.Object.keys(value).sort()) {
121
136
  Visit(key);
122
137
  Visit(value[key]);
123
138
  }
124
139
  }
125
140
  function String(value) {
126
- Fnv1A64(ByteMarker.String);
141
+ FNV1A64(ByteMarker.String);
127
142
  for (let i = 0; i < value.length; i++) {
128
- Fnv1A64(value.charCodeAt(i));
143
+ FNV1A64(value.charCodeAt(i));
129
144
  }
130
145
  }
146
+ function Symbol(value) {
147
+ FNV1A64(ByteMarker.Symbol);
148
+ Visit(value.description);
149
+ }
131
150
  function Uint8Array(value) {
132
- Fnv1A64(ByteMarker.Uint8Array);
151
+ FNV1A64(ByteMarker.Uint8Array);
133
152
  for (let i = 0; i < value.length; i++) {
134
- Fnv1A64(value[i]);
153
+ FNV1A64(value[i]);
135
154
  }
136
155
  }
137
156
  function Undefined(value) {
138
- return Fnv1A64(ByteMarker.Undefined);
157
+ return FNV1A64(ByteMarker.Undefined);
139
158
  }
140
159
  function Visit(value) {
141
160
  if (IsArray(value)) {
@@ -144,6 +163,9 @@ var ValueHash;
144
163
  else if (IsBoolean(value)) {
145
164
  Boolean(value);
146
165
  }
166
+ else if (IsBigInt(value)) {
167
+ BigInt(value);
168
+ }
147
169
  else if (IsDate(value)) {
148
170
  Date(value);
149
171
  }
@@ -159,6 +181,9 @@ var ValueHash;
159
181
  else if (IsString(value)) {
160
182
  String(value);
161
183
  }
184
+ else if (IsSymbol(value)) {
185
+ Symbol(value);
186
+ }
162
187
  else if (IsUint8Array(value)) {
163
188
  Uint8Array(value);
164
189
  }
@@ -169,7 +194,7 @@ var ValueHash;
169
194
  throw new ValueHashError(value);
170
195
  }
171
196
  }
172
- function Fnv1A64(byte) {
197
+ function FNV1A64(byte) {
173
198
  Hash = Hash ^ Bytes[byte];
174
199
  Hash = (Hash * Prime) % Size;
175
200
  }
package/value/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ValueError, ValueErrorType } from '../errors/index';
2
+ export { ValueHash } from './hash';
2
3
  export { Edit, Insert, Update, Delete } from './delta';
3
4
  export * from './pointer';
4
5
  export * from './value';
package/value/index.js CHANGED
@@ -41,9 +41,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
41
41
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
42
42
  };
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.Delete = exports.Update = exports.Insert = exports.Edit = exports.ValueErrorType = void 0;
44
+ exports.Delete = exports.Update = exports.Insert = exports.Edit = exports.ValueHash = exports.ValueErrorType = void 0;
45
45
  var index_1 = require("../errors/index");
46
46
  Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
47
+ var hash_1 = require("./hash");
48
+ Object.defineProperty(exports, "ValueHash", { enumerable: true, get: function () { return hash_1.ValueHash; } });
47
49
  var delta_1 = require("./delta");
48
50
  Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return delta_1.Edit; } });
49
51
  Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return delta_1.Insert; } });
package/value/value.d.ts CHANGED
@@ -3,23 +3,17 @@ import { ValueError } from '../errors/index';
3
3
  import { Edit } from './delta';
4
4
  /** Provides functions to perform structural updates to JavaScript values */
5
5
  export declare namespace Value {
6
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
7
- function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): Types.Static<T>;
8
6
  /** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
9
7
  function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
10
8
  /** Creates a value from the given type */
11
- function Create<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R]): Types.Static<T>;
12
- /** Creates a value from the given type */
13
9
  function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
14
10
  /** Returns true if the value matches the given type. */
15
- function Check<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): value is Types.Static<T>;
16
- /** Returns true if the value matches the given type. */
17
11
  function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
12
+ /** Converts any type mismatched values to their target type if a conversion is possible. */
13
+ function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
18
14
  /** Returns a structural clone of the given value */
19
15
  function Clone<T>(value: T): T;
20
16
  /** Returns an iterator for each error in this value. */
21
- function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): IterableIterator<ValueError>;
22
- /** Returns an iterator for each error in this value. */
23
17
  function Errors<T extends Types.TSchema>(schema: T, value: unknown): IterableIterator<ValueError>;
24
18
  /** Returns true if left and right values are structurally equal */
25
19
  function Equal<T>(left: T, right: unknown): right is T;