@sinclair/typebox 0.32.14 → 0.32.15
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/build/import/compiler/index.d.mts +1 -1
- package/build/import/compiler/index.mjs +1 -1
- package/build/import/errors/index.d.mts +2 -2
- package/build/import/errors/index.mjs +2 -2
- package/build/import/system/index.d.mts +2 -2
- package/build/import/system/index.mjs +2 -2
- package/build/import/value/cast/cast.mjs +2 -2
- package/build/import/value/clone/clone.mjs +2 -2
- package/build/import/value/delta/delta.mjs +3 -3
- package/build/import/value/equal/equal.mjs +3 -3
- package/build/import/value/guard/guard.d.mts +34 -6
- package/build/import/value/guard/guard.mjs +71 -12
- package/build/import/value/hash/hash.mjs +2 -2
- package/build/import/value/index.d.mts +14 -14
- package/build/import/value/index.mjs +18 -18
- package/build/import/value/mutate/mutate.mjs +5 -5
- package/build/import/value/transform/decode.mjs +4 -4
- package/build/import/value/transform/encode.mjs +4 -4
- package/build/require/compiler/index.d.ts +1 -1
- package/build/require/compiler/index.js +16 -6
- package/build/require/errors/index.d.ts +2 -2
- package/build/require/errors/index.js +16 -10
- package/build/require/system/index.d.ts +2 -2
- package/build/require/system/index.js +16 -7
- package/build/require/value/cast/cast.js +1 -1
- package/build/require/value/clone/clone.js +1 -1
- package/build/require/value/delta/delta.js +2 -2
- package/build/require/value/equal/equal.js +2 -2
- package/build/require/value/guard/guard.d.ts +34 -6
- package/build/require/value/guard/guard.js +89 -16
- package/build/require/value/hash/hash.js +1 -1
- package/build/require/value/index.d.ts +14 -14
- package/build/require/value/index.js +35 -71
- package/build/require/value/mutate/mutate.js +4 -4
- package/build/require/value/transform/decode.js +3 -3
- package/build/require/value/transform/encode.js +3 -3
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
2
|
-
export
|
|
2
|
+
export * from './compiler.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
2
|
-
export
|
|
2
|
+
export * from './compiler.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './errors.mjs';
|
|
2
|
+
export * from './function.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './errors.mjs';
|
|
2
|
+
export * from './function.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './policy.mjs';
|
|
2
|
+
export * from './system.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './policy.mjs';
|
|
2
|
+
export * from './system.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsStandardObject, IsArray, IsString, IsNumber, IsNull } from '../guard/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
3
3
|
import { Kind } from '../../type/symbols/index.mjs';
|
|
4
4
|
import { Create } from '../create/index.mjs';
|
|
@@ -100,7 +100,7 @@ function FromConstructor(schema, references, value) {
|
|
|
100
100
|
}
|
|
101
101
|
function FromIntersect(schema, references, value) {
|
|
102
102
|
const created = Create(schema, references);
|
|
103
|
-
const mapped =
|
|
103
|
+
const mapped = IsStandardObject(created) && IsStandardObject(value) ? { ...created, ...value } : value;
|
|
104
104
|
return Check(schema, references, mapped) ? mapped : Create(schema, references);
|
|
105
105
|
}
|
|
106
106
|
function FromNever(schema, references, value) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ------------------------------------------------------------------
|
|
2
2
|
// ValueGuard
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
|
-
import { IsArray, IsDate,
|
|
4
|
+
import { IsArray, IsDate, IsStandardObject, IsTypedArray, IsValueType } from '../guard/index.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// Clonable
|
|
7
7
|
// ------------------------------------------------------------------
|
|
@@ -30,7 +30,7 @@ export function Clone(value) {
|
|
|
30
30
|
return ArrayType(value);
|
|
31
31
|
if (IsDate(value))
|
|
32
32
|
return DateType(value);
|
|
33
|
-
if (
|
|
33
|
+
if (IsStandardObject(value))
|
|
34
34
|
return ObjectType(value);
|
|
35
35
|
if (IsTypedArray(value))
|
|
36
36
|
return TypedArrayType(value);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsStandardObject, IsArray, IsTypedArray, IsValueType, IsSymbol, IsUndefined } from '../guard/index.mjs';
|
|
2
2
|
import { ValuePointer } from '../pointer/index.mjs';
|
|
3
3
|
import { Clone } from '../clone/index.mjs';
|
|
4
4
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
@@ -55,7 +55,7 @@ function CreateDelete(path) {
|
|
|
55
55
|
// Diffing Generators
|
|
56
56
|
// ------------------------------------------------------------------
|
|
57
57
|
function* ObjectType(path, current, next) {
|
|
58
|
-
if (!
|
|
58
|
+
if (!IsStandardObject(next))
|
|
59
59
|
return yield CreateUpdate(path, next);
|
|
60
60
|
const currentKeys = [...globalThis.Object.keys(current), ...globalThis.Object.getOwnPropertySymbols(current)];
|
|
61
61
|
const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
|
|
@@ -115,7 +115,7 @@ function* ValueType(path, current, next) {
|
|
|
115
115
|
yield CreateUpdate(path, next);
|
|
116
116
|
}
|
|
117
117
|
function* Visit(path, current, next) {
|
|
118
|
-
if (
|
|
118
|
+
if (IsStandardObject(current))
|
|
119
119
|
return yield* ObjectType(path, current, next);
|
|
120
120
|
if (IsArray(current))
|
|
121
121
|
return yield* ArrayType(path, current, next);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsStandardObject, IsDate, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
|
|
2
2
|
// ------------------------------------------------------------------
|
|
3
3
|
// Equality Checks
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
function ObjectType(left, right) {
|
|
6
|
-
if (!
|
|
6
|
+
if (!IsStandardObject(right))
|
|
7
7
|
return false;
|
|
8
8
|
const leftKeys = [...Object.keys(left), ...Object.getOwnPropertySymbols(left)];
|
|
9
9
|
const rightKeys = [...Object.keys(right), ...Object.getOwnPropertySymbols(right)];
|
|
@@ -32,7 +32,7 @@ function ValueType(left, right) {
|
|
|
32
32
|
// ------------------------------------------------------------------
|
|
33
33
|
/** Returns true if the left value deep-equals the right */
|
|
34
34
|
export function Equal(left, right) {
|
|
35
|
-
if (
|
|
35
|
+
if (IsStandardObject(left))
|
|
36
36
|
return ObjectType(left, right);
|
|
37
37
|
if (IsDate(left))
|
|
38
38
|
return DateType(left, right);
|
|
@@ -6,18 +6,46 @@ export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16A
|
|
|
6
6
|
export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<any>;
|
|
7
7
|
/** Returns true if this value is an iterator */
|
|
8
8
|
export declare function IsIterator(value: unknown): value is IterableIterator<any>;
|
|
9
|
-
/** Returns true if this value is a
|
|
10
|
-
export declare function
|
|
9
|
+
/** Returns true if this value is not an instance of a class */
|
|
10
|
+
export declare function IsStandardObject(value: unknown): value is ObjectType;
|
|
11
|
+
/** Returns true if this value is an instance of a class */
|
|
12
|
+
export declare function IsInstanceObject(value: unknown): value is ObjectType;
|
|
11
13
|
/** Returns true if this value is a Promise */
|
|
12
14
|
export declare function IsPromise(value: unknown): value is Promise<unknown>;
|
|
13
|
-
/** Returns true if the value is a Uint8Array */
|
|
14
|
-
export declare function IsUint8Array(value: unknown): value is Uint8Array;
|
|
15
15
|
/** Returns true if this value is a Date */
|
|
16
16
|
export declare function IsDate(value: unknown): value is Date;
|
|
17
|
+
/** Returns true if this value is an instance of Map<K, T> */
|
|
18
|
+
export declare function IsMap(value: unknown): value is Map<unknown, unknown>;
|
|
19
|
+
/** Returns true if this value is an instance of Set<T> */
|
|
20
|
+
export declare function IsSet(value: unknown): value is Set<unknown>;
|
|
21
|
+
/** Returns true if this value is RegExp */
|
|
22
|
+
export declare function IsRegExp(value: unknown): value is RegExp;
|
|
23
|
+
/** Returns true if this value is a typed array */
|
|
24
|
+
export declare function IsTypedArray(value: unknown): value is TypedArrayType;
|
|
25
|
+
/** Returns true if the value is a Int8Array */
|
|
26
|
+
export declare function IsInt8Array(value: unknown): value is Int8Array;
|
|
27
|
+
/** Returns true if the value is a Uint8Array */
|
|
28
|
+
export declare function IsUint8Array(value: unknown): value is Uint8Array;
|
|
29
|
+
/** Returns true if the value is a Uint8ClampedArray */
|
|
30
|
+
export declare function IsUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
|
|
31
|
+
/** Returns true if the value is a Int16Array */
|
|
32
|
+
export declare function IsInt16Array(value: unknown): value is Int16Array;
|
|
33
|
+
/** Returns true if the value is a Uint16Array */
|
|
34
|
+
export declare function IsUint16Array(value: unknown): value is Uint16Array;
|
|
35
|
+
/** Returns true if the value is a Int32Array */
|
|
36
|
+
export declare function IsInt32Array(value: unknown): value is Int32Array;
|
|
37
|
+
/** Returns true if the value is a Uint32Array */
|
|
38
|
+
export declare function IsUint32Array(value: unknown): value is Uint32Array;
|
|
39
|
+
/** Returns true if the value is a Float32Array */
|
|
40
|
+
export declare function IsFloat32Array(value: unknown): value is Float32Array;
|
|
41
|
+
/** Returns true if the value is a Float64Array */
|
|
42
|
+
export declare function IsFloat64Array(value: unknown): value is Float64Array;
|
|
43
|
+
/** Returns true if the value is a BigInt64Array */
|
|
44
|
+
export declare function IsBigInt64Array(value: unknown): value is BigInt64Array;
|
|
45
|
+
/** Returns true if the value is a BigUint64Array */
|
|
46
|
+
export declare function IsBigUint64Array(value: unknown): value is BigUint64Array;
|
|
17
47
|
/** Returns true if this value has this property key */
|
|
18
48
|
export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is ObjectType & Record<K, unknown>;
|
|
19
|
-
/** Returns true if this object is not an instance of any other type */
|
|
20
|
-
export declare function IsPlainObject(value: unknown): value is ObjectType;
|
|
21
49
|
/** Returns true of this value is an object type */
|
|
22
50
|
export declare function IsObject(value: unknown): value is ObjectType;
|
|
23
51
|
/** Returns true if this value is an array, but not a typed array */
|
|
@@ -10,24 +10,87 @@ export function IsIterator(value) {
|
|
|
10
10
|
return IsObject(value) && Symbol.iterator in value;
|
|
11
11
|
}
|
|
12
12
|
// --------------------------------------------------------------------------
|
|
13
|
-
//
|
|
13
|
+
// Object Instances
|
|
14
14
|
// --------------------------------------------------------------------------
|
|
15
|
-
/** Returns true if this value is a
|
|
16
|
-
export function
|
|
17
|
-
return
|
|
15
|
+
/** Returns true if this value is not an instance of a class */
|
|
16
|
+
export function IsStandardObject(value) {
|
|
17
|
+
return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
|
|
18
|
+
}
|
|
19
|
+
/** Returns true if this value is an instance of a class */
|
|
20
|
+
export function IsInstanceObject(value) {
|
|
21
|
+
return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name !== 'Object';
|
|
18
22
|
}
|
|
23
|
+
// --------------------------------------------------------------------------
|
|
24
|
+
// JavaScript
|
|
25
|
+
// --------------------------------------------------------------------------
|
|
19
26
|
/** Returns true if this value is a Promise */
|
|
20
27
|
export function IsPromise(value) {
|
|
21
28
|
return value instanceof Promise;
|
|
22
29
|
}
|
|
23
|
-
/** Returns true if the value is a Uint8Array */
|
|
24
|
-
export function IsUint8Array(value) {
|
|
25
|
-
return value instanceof Uint8Array;
|
|
26
|
-
}
|
|
27
30
|
/** Returns true if this value is a Date */
|
|
28
31
|
export function IsDate(value) {
|
|
29
32
|
return value instanceof Date && Number.isFinite(value.getTime());
|
|
30
33
|
}
|
|
34
|
+
/** Returns true if this value is an instance of Map<K, T> */
|
|
35
|
+
export function IsMap(value) {
|
|
36
|
+
return value instanceof globalThis.Map;
|
|
37
|
+
}
|
|
38
|
+
/** Returns true if this value is an instance of Set<T> */
|
|
39
|
+
export function IsSet(value) {
|
|
40
|
+
return value instanceof globalThis.Set;
|
|
41
|
+
}
|
|
42
|
+
/** Returns true if this value is RegExp */
|
|
43
|
+
export function IsRegExp(value) {
|
|
44
|
+
return value instanceof globalThis.RegExp;
|
|
45
|
+
}
|
|
46
|
+
/** Returns true if this value is a typed array */
|
|
47
|
+
export function IsTypedArray(value) {
|
|
48
|
+
return ArrayBuffer.isView(value);
|
|
49
|
+
}
|
|
50
|
+
/** Returns true if the value is a Int8Array */
|
|
51
|
+
export function IsInt8Array(value) {
|
|
52
|
+
return value instanceof globalThis.Int8Array;
|
|
53
|
+
}
|
|
54
|
+
/** Returns true if the value is a Uint8Array */
|
|
55
|
+
export function IsUint8Array(value) {
|
|
56
|
+
return value instanceof globalThis.Uint8Array;
|
|
57
|
+
}
|
|
58
|
+
/** Returns true if the value is a Uint8ClampedArray */
|
|
59
|
+
export function IsUint8ClampedArray(value) {
|
|
60
|
+
return value instanceof globalThis.Uint8ClampedArray;
|
|
61
|
+
}
|
|
62
|
+
/** Returns true if the value is a Int16Array */
|
|
63
|
+
export function IsInt16Array(value) {
|
|
64
|
+
return value instanceof globalThis.Int16Array;
|
|
65
|
+
}
|
|
66
|
+
/** Returns true if the value is a Uint16Array */
|
|
67
|
+
export function IsUint16Array(value) {
|
|
68
|
+
return value instanceof globalThis.Uint16Array;
|
|
69
|
+
}
|
|
70
|
+
/** Returns true if the value is a Int32Array */
|
|
71
|
+
export function IsInt32Array(value) {
|
|
72
|
+
return value instanceof globalThis.Int32Array;
|
|
73
|
+
}
|
|
74
|
+
/** Returns true if the value is a Uint32Array */
|
|
75
|
+
export function IsUint32Array(value) {
|
|
76
|
+
return value instanceof globalThis.Uint32Array;
|
|
77
|
+
}
|
|
78
|
+
/** Returns true if the value is a Float32Array */
|
|
79
|
+
export function IsFloat32Array(value) {
|
|
80
|
+
return value instanceof globalThis.Float32Array;
|
|
81
|
+
}
|
|
82
|
+
/** Returns true if the value is a Float64Array */
|
|
83
|
+
export function IsFloat64Array(value) {
|
|
84
|
+
return value instanceof globalThis.Float64Array;
|
|
85
|
+
}
|
|
86
|
+
/** Returns true if the value is a BigInt64Array */
|
|
87
|
+
export function IsBigInt64Array(value) {
|
|
88
|
+
return value instanceof globalThis.BigInt64Array;
|
|
89
|
+
}
|
|
90
|
+
/** Returns true if the value is a BigUint64Array */
|
|
91
|
+
export function IsBigUint64Array(value) {
|
|
92
|
+
return value instanceof globalThis.BigUint64Array;
|
|
93
|
+
}
|
|
31
94
|
// --------------------------------------------------------------------------
|
|
32
95
|
// Standard
|
|
33
96
|
// --------------------------------------------------------------------------
|
|
@@ -35,10 +98,6 @@ export function IsDate(value) {
|
|
|
35
98
|
export function HasPropertyKey(value, key) {
|
|
36
99
|
return key in value;
|
|
37
100
|
}
|
|
38
|
-
/** Returns true if this object is not an instance of any other type */
|
|
39
|
-
export function IsPlainObject(value) {
|
|
40
|
-
return IsObject(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
|
|
41
|
-
}
|
|
42
101
|
/** Returns true of this value is an object type */
|
|
43
102
|
export function IsObject(value) {
|
|
44
103
|
return value !== null && typeof value === 'object';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsArray, IsBoolean, IsBigInt, IsDate, IsNull, IsNumber,
|
|
1
|
+
import { IsArray, IsBoolean, IsBigInt, IsDate, IsNull, IsNumber, IsStandardObject, IsString, IsSymbol, IsUint8Array, IsUndefined } from '../guard/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// Errors
|
|
@@ -120,7 +120,7 @@ function Visit(value) {
|
|
|
120
120
|
return NullType(value);
|
|
121
121
|
if (IsNumber(value))
|
|
122
122
|
return NumberType(value);
|
|
123
|
-
if (
|
|
123
|
+
if (IsStandardObject(value))
|
|
124
124
|
return ObjectType(value);
|
|
125
125
|
if (IsString(value))
|
|
126
126
|
return StringType(value);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
2
|
+
export * from './guard/index.mjs';
|
|
3
|
+
export * from './cast/index.mjs';
|
|
4
|
+
export * from './check/index.mjs';
|
|
5
|
+
export * from './clean/index.mjs';
|
|
6
|
+
export * from './clone/index.mjs';
|
|
7
|
+
export * from './convert/index.mjs';
|
|
8
|
+
export * from './create/index.mjs';
|
|
9
|
+
export * from './default/index.mjs';
|
|
10
|
+
export * from './delta/index.mjs';
|
|
11
|
+
export * from './equal/index.mjs';
|
|
12
|
+
export * from './hash/index.mjs';
|
|
13
|
+
export * from './mutate/index.mjs';
|
|
14
|
+
export * from './pointer/index.mjs';
|
|
15
|
+
export * from './transform/index.mjs';
|
|
16
16
|
export { Value } from './value/index.mjs';
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
// ------------------------------------------------------------------
|
|
2
|
-
//
|
|
2
|
+
// Errors (re-export)
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
//
|
|
6
|
+
// Guards
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
export
|
|
9
|
-
export { Check } from './check/index.mjs';
|
|
10
|
-
export { Clean } from './clean/index.mjs';
|
|
11
|
-
export { Clone } from './clone/index.mjs';
|
|
12
|
-
export { Convert } from './convert/index.mjs';
|
|
13
|
-
export { Create, ValueCreateError } from './create/index.mjs';
|
|
14
|
-
export { Default } from './default/index.mjs';
|
|
15
|
-
export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index.mjs';
|
|
16
|
-
export { Equal } from './equal/index.mjs';
|
|
17
|
-
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
18
|
-
export { Mutate, ValueMutateError } from './mutate/index.mjs';
|
|
19
|
-
export { ValuePointer } from './pointer/index.mjs';
|
|
20
|
-
export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
8
|
+
export * from './guard/index.mjs';
|
|
21
9
|
// ------------------------------------------------------------------
|
|
22
|
-
//
|
|
10
|
+
// Operators
|
|
23
11
|
// ------------------------------------------------------------------
|
|
24
|
-
export
|
|
12
|
+
export * from './cast/index.mjs';
|
|
13
|
+
export * from './check/index.mjs';
|
|
14
|
+
export * from './clean/index.mjs';
|
|
15
|
+
export * from './clone/index.mjs';
|
|
16
|
+
export * from './convert/index.mjs';
|
|
17
|
+
export * from './create/index.mjs';
|
|
18
|
+
export * from './default/index.mjs';
|
|
19
|
+
export * from './delta/index.mjs';
|
|
20
|
+
export * from './equal/index.mjs';
|
|
21
|
+
export * from './hash/index.mjs';
|
|
22
|
+
export * from './mutate/index.mjs';
|
|
23
|
+
export * from './pointer/index.mjs';
|
|
24
|
+
export * from './transform/index.mjs';
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
|
-
//
|
|
26
|
+
// Namespace
|
|
27
27
|
// ------------------------------------------------------------------
|
|
28
28
|
export { Value } from './value/index.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsStandardObject, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
|
|
2
2
|
import { ValuePointer } from '../pointer/index.mjs';
|
|
3
3
|
import { Clone } from '../clone/index.mjs';
|
|
4
4
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
@@ -11,7 +11,7 @@ export class ValueMutateError extends TypeBoxError {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
function ObjectType(root, path, current, next) {
|
|
14
|
-
if (!
|
|
14
|
+
if (!IsStandardObject(current)) {
|
|
15
15
|
ValuePointer.Set(root, path, Clone(next));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
@@ -63,7 +63,7 @@ function Visit(root, path, current, next) {
|
|
|
63
63
|
return ArrayType(root, path, current, next);
|
|
64
64
|
if (IsTypedArray(next))
|
|
65
65
|
return TypedArrayType(root, path, current, next);
|
|
66
|
-
if (
|
|
66
|
+
if (IsStandardObject(next))
|
|
67
67
|
return ObjectType(root, path, current, next);
|
|
68
68
|
if (IsValueType(next))
|
|
69
69
|
return ValueType(root, path, current, next);
|
|
@@ -76,8 +76,8 @@ function IsNonMutableValue(value) {
|
|
|
76
76
|
}
|
|
77
77
|
function IsMismatchedValue(current, next) {
|
|
78
78
|
// prettier-ignore
|
|
79
|
-
return ((
|
|
80
|
-
(IsArray(current) &&
|
|
79
|
+
return ((IsStandardObject(current) && IsArray(next)) ||
|
|
80
|
+
(IsArray(current) && IsStandardObject(next)));
|
|
81
81
|
}
|
|
82
82
|
// ------------------------------------------------------------------
|
|
83
83
|
// Mutate
|
|
@@ -7,7 +7,7 @@ import { Check } from '../check/index.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// ValueGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
import {
|
|
10
|
+
import { IsStandardObject, IsArray, IsValueType } from '../guard/index.mjs';
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// TypeGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
@@ -56,7 +56,7 @@ function FromArray(schema, references, value) {
|
|
|
56
56
|
}
|
|
57
57
|
// prettier-ignore
|
|
58
58
|
function FromIntersect(schema, references, value) {
|
|
59
|
-
if (!
|
|
59
|
+
if (!IsStandardObject(value) || IsValueType(value))
|
|
60
60
|
return Default(schema, value);
|
|
61
61
|
const knownKeys = KeyOfPropertyKeys(schema);
|
|
62
62
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -81,7 +81,7 @@ function FromNot(schema, references, value) {
|
|
|
81
81
|
}
|
|
82
82
|
// prettier-ignore
|
|
83
83
|
function FromObject(schema, references, value) {
|
|
84
|
-
if (!
|
|
84
|
+
if (!IsStandardObject(value))
|
|
85
85
|
return Default(schema, value);
|
|
86
86
|
const knownKeys = KeyOfPropertyKeys(schema);
|
|
87
87
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -103,7 +103,7 @@ function FromObject(schema, references, value) {
|
|
|
103
103
|
}
|
|
104
104
|
// prettier-ignore
|
|
105
105
|
function FromRecord(schema, references, value) {
|
|
106
|
-
if (!
|
|
106
|
+
if (!IsStandardObject(value))
|
|
107
107
|
return Default(schema, value);
|
|
108
108
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
109
109
|
const knownKeys = new RegExp(pattern);
|
|
@@ -7,7 +7,7 @@ import { Check } from '../check/index.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// ValueGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
import {
|
|
10
|
+
import { IsStandardObject, IsArray, IsValueType } from '../guard/index.mjs';
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// TypeGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
@@ -57,7 +57,7 @@ function FromArray(schema, references, value) {
|
|
|
57
57
|
// prettier-ignore
|
|
58
58
|
function FromIntersect(schema, references, value) {
|
|
59
59
|
const defaulted = Default(schema, value);
|
|
60
|
-
if (!
|
|
60
|
+
if (!IsStandardObject(value) || IsValueType(value))
|
|
61
61
|
return defaulted;
|
|
62
62
|
const knownKeys = KeyOfPropertyKeys(schema);
|
|
63
63
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -83,7 +83,7 @@ function FromNot(schema, references, value) {
|
|
|
83
83
|
// prettier-ignore
|
|
84
84
|
function FromObject(schema, references, value) {
|
|
85
85
|
const defaulted = Default(schema, value);
|
|
86
|
-
if (!
|
|
86
|
+
if (!IsStandardObject(value))
|
|
87
87
|
return defaulted;
|
|
88
88
|
const knownKeys = KeyOfPropertyKeys(schema);
|
|
89
89
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -105,7 +105,7 @@ function FromObject(schema, references, value) {
|
|
|
105
105
|
// prettier-ignore
|
|
106
106
|
function FromRecord(schema, references, value) {
|
|
107
107
|
const defaulted = Default(schema, value);
|
|
108
|
-
if (!
|
|
108
|
+
if (!IsStandardObject(value))
|
|
109
109
|
return defaulted;
|
|
110
110
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
111
111
|
const knownKeys = new RegExp(pattern);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index';
|
|
2
|
-
export
|
|
2
|
+
export * from './compiler';
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
3
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
18
|
+
exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
5
19
|
var index_1 = require("../errors/index");
|
|
6
20
|
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
7
21
|
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return index_1.ValueErrorIterator; } });
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "TypeCompiler", { enumerable: true, get: function () { return compiler_1.TypeCompiler; } });
|
|
10
|
-
Object.defineProperty(exports, "TypeCheck", { enumerable: true, get: function () { return compiler_1.TypeCheck; } });
|
|
11
|
-
Object.defineProperty(exports, "TypeCompilerTypeGuardError", { enumerable: true, get: function () { return compiler_1.TypeCompilerTypeGuardError; } });
|
|
12
|
-
Object.defineProperty(exports, "TypeCompilerUnknownTypeError", { enumerable: true, get: function () { return compiler_1.TypeCompilerUnknownTypeError; } });
|
|
22
|
+
__exportStar(require("./compiler"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './errors';
|
|
2
|
+
export * from './function';
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
3
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return errors_1.Errors; } });
|
|
7
|
-
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return errors_1.ValueErrorIterator; } });
|
|
8
|
-
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return errors_1.ValueErrorType; } });
|
|
9
|
-
Object.defineProperty(exports, "ValueErrorsUnknownTypeError", { enumerable: true, get: function () { return errors_1.ValueErrorsUnknownTypeError; } });
|
|
10
|
-
var function_1 = require("./function");
|
|
11
|
-
Object.defineProperty(exports, "DefaultErrorFunction", { enumerable: true, get: function () { return function_1.DefaultErrorFunction; } });
|
|
12
|
-
Object.defineProperty(exports, "GetErrorFunction", { enumerable: true, get: function () { return function_1.GetErrorFunction; } });
|
|
13
|
-
Object.defineProperty(exports, "SetErrorFunction", { enumerable: true, get: function () { return function_1.SetErrorFunction; } });
|
|
18
|
+
__exportStar(require("./errors"), exports);
|
|
19
|
+
__exportStar(require("./function"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './policy';
|
|
2
|
+
export * from './system';
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
3
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "TypeSystemPolicy", { enumerable: true, get: function () { return policy_1.TypeSystemPolicy; } });
|
|
7
|
-
var system_1 = require("./system");
|
|
8
|
-
Object.defineProperty(exports, "TypeSystem", { enumerable: true, get: function () { return system_1.TypeSystem; } });
|
|
9
|
-
Object.defineProperty(exports, "TypeSystemDuplicateFormat", { enumerable: true, get: function () { return system_1.TypeSystemDuplicateFormat; } });
|
|
10
|
-
Object.defineProperty(exports, "TypeSystemDuplicateTypeKind", { enumerable: true, get: function () { return system_1.TypeSystemDuplicateTypeKind; } });
|
|
18
|
+
__exportStar(require("./policy"), exports);
|
|
19
|
+
__exportStar(require("./system"), exports);
|
|
@@ -104,7 +104,7 @@ function FromConstructor(schema, references, value) {
|
|
|
104
104
|
}
|
|
105
105
|
function FromIntersect(schema, references, value) {
|
|
106
106
|
const created = (0, index_4.Create)(schema, references);
|
|
107
|
-
const mapped = (0, index_1.
|
|
107
|
+
const mapped = (0, index_1.IsStandardObject)(created) && (0, index_1.IsStandardObject)(value) ? { ...created, ...value } : value;
|
|
108
108
|
return (0, index_5.Check)(schema, references, mapped) ? mapped : (0, index_4.Create)(schema, references);
|
|
109
109
|
}
|
|
110
110
|
function FromNever(schema, references, value) {
|
|
@@ -34,7 +34,7 @@ function Clone(value) {
|
|
|
34
34
|
return ArrayType(value);
|
|
35
35
|
if ((0, index_1.IsDate)(value))
|
|
36
36
|
return DateType(value);
|
|
37
|
-
if ((0, index_1.
|
|
37
|
+
if ((0, index_1.IsStandardObject)(value))
|
|
38
38
|
return ObjectType(value);
|
|
39
39
|
if ((0, index_1.IsTypedArray)(value))
|
|
40
40
|
return TypedArrayType(value);
|
|
@@ -59,7 +59,7 @@ function CreateDelete(path) {
|
|
|
59
59
|
// Diffing Generators
|
|
60
60
|
// ------------------------------------------------------------------
|
|
61
61
|
function* ObjectType(path, current, next) {
|
|
62
|
-
if (!(0, index_1.
|
|
62
|
+
if (!(0, index_1.IsStandardObject)(next))
|
|
63
63
|
return yield CreateUpdate(path, next);
|
|
64
64
|
const currentKeys = [...globalThis.Object.keys(current), ...globalThis.Object.getOwnPropertySymbols(current)];
|
|
65
65
|
const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
|
|
@@ -119,7 +119,7 @@ function* ValueType(path, current, next) {
|
|
|
119
119
|
yield CreateUpdate(path, next);
|
|
120
120
|
}
|
|
121
121
|
function* Visit(path, current, next) {
|
|
122
|
-
if ((0, index_1.
|
|
122
|
+
if ((0, index_1.IsStandardObject)(current))
|
|
123
123
|
return yield* ObjectType(path, current, next);
|
|
124
124
|
if ((0, index_1.IsArray)(current))
|
|
125
125
|
return yield* ArrayType(path, current, next);
|
|
@@ -7,7 +7,7 @@ const index_1 = require("../guard/index");
|
|
|
7
7
|
// Equality Checks
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
function ObjectType(left, right) {
|
|
10
|
-
if (!(0, index_1.
|
|
10
|
+
if (!(0, index_1.IsStandardObject)(right))
|
|
11
11
|
return false;
|
|
12
12
|
const leftKeys = [...Object.keys(left), ...Object.getOwnPropertySymbols(left)];
|
|
13
13
|
const rightKeys = [...Object.keys(right), ...Object.getOwnPropertySymbols(right)];
|
|
@@ -36,7 +36,7 @@ function ValueType(left, right) {
|
|
|
36
36
|
// ------------------------------------------------------------------
|
|
37
37
|
/** Returns true if the left value deep-equals the right */
|
|
38
38
|
function Equal(left, right) {
|
|
39
|
-
if ((0, index_1.
|
|
39
|
+
if ((0, index_1.IsStandardObject)(left))
|
|
40
40
|
return ObjectType(left, right);
|
|
41
41
|
if ((0, index_1.IsDate)(left))
|
|
42
42
|
return DateType(left, right);
|
|
@@ -6,18 +6,46 @@ export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16A
|
|
|
6
6
|
export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<any>;
|
|
7
7
|
/** Returns true if this value is an iterator */
|
|
8
8
|
export declare function IsIterator(value: unknown): value is IterableIterator<any>;
|
|
9
|
-
/** Returns true if this value is a
|
|
10
|
-
export declare function
|
|
9
|
+
/** Returns true if this value is not an instance of a class */
|
|
10
|
+
export declare function IsStandardObject(value: unknown): value is ObjectType;
|
|
11
|
+
/** Returns true if this value is an instance of a class */
|
|
12
|
+
export declare function IsInstanceObject(value: unknown): value is ObjectType;
|
|
11
13
|
/** Returns true if this value is a Promise */
|
|
12
14
|
export declare function IsPromise(value: unknown): value is Promise<unknown>;
|
|
13
|
-
/** Returns true if the value is a Uint8Array */
|
|
14
|
-
export declare function IsUint8Array(value: unknown): value is Uint8Array;
|
|
15
15
|
/** Returns true if this value is a Date */
|
|
16
16
|
export declare function IsDate(value: unknown): value is Date;
|
|
17
|
+
/** Returns true if this value is an instance of Map<K, T> */
|
|
18
|
+
export declare function IsMap(value: unknown): value is Map<unknown, unknown>;
|
|
19
|
+
/** Returns true if this value is an instance of Set<T> */
|
|
20
|
+
export declare function IsSet(value: unknown): value is Set<unknown>;
|
|
21
|
+
/** Returns true if this value is RegExp */
|
|
22
|
+
export declare function IsRegExp(value: unknown): value is RegExp;
|
|
23
|
+
/** Returns true if this value is a typed array */
|
|
24
|
+
export declare function IsTypedArray(value: unknown): value is TypedArrayType;
|
|
25
|
+
/** Returns true if the value is a Int8Array */
|
|
26
|
+
export declare function IsInt8Array(value: unknown): value is Int8Array;
|
|
27
|
+
/** Returns true if the value is a Uint8Array */
|
|
28
|
+
export declare function IsUint8Array(value: unknown): value is Uint8Array;
|
|
29
|
+
/** Returns true if the value is a Uint8ClampedArray */
|
|
30
|
+
export declare function IsUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
|
|
31
|
+
/** Returns true if the value is a Int16Array */
|
|
32
|
+
export declare function IsInt16Array(value: unknown): value is Int16Array;
|
|
33
|
+
/** Returns true if the value is a Uint16Array */
|
|
34
|
+
export declare function IsUint16Array(value: unknown): value is Uint16Array;
|
|
35
|
+
/** Returns true if the value is a Int32Array */
|
|
36
|
+
export declare function IsInt32Array(value: unknown): value is Int32Array;
|
|
37
|
+
/** Returns true if the value is a Uint32Array */
|
|
38
|
+
export declare function IsUint32Array(value: unknown): value is Uint32Array;
|
|
39
|
+
/** Returns true if the value is a Float32Array */
|
|
40
|
+
export declare function IsFloat32Array(value: unknown): value is Float32Array;
|
|
41
|
+
/** Returns true if the value is a Float64Array */
|
|
42
|
+
export declare function IsFloat64Array(value: unknown): value is Float64Array;
|
|
43
|
+
/** Returns true if the value is a BigInt64Array */
|
|
44
|
+
export declare function IsBigInt64Array(value: unknown): value is BigInt64Array;
|
|
45
|
+
/** Returns true if the value is a BigUint64Array */
|
|
46
|
+
export declare function IsBigUint64Array(value: unknown): value is BigUint64Array;
|
|
17
47
|
/** Returns true if this value has this property key */
|
|
18
48
|
export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is ObjectType & Record<K, unknown>;
|
|
19
|
-
/** Returns true if this object is not an instance of any other type */
|
|
20
|
-
export declare function IsPlainObject(value: unknown): value is ObjectType;
|
|
21
49
|
/** Returns true of this value is an object type */
|
|
22
50
|
export declare function IsObject(value: unknown): value is ObjectType;
|
|
23
51
|
/** Returns true if this value is an array, but not a typed array */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.IsValueType = exports.IsSymbol = exports.IsFunction = exports.IsString = exports.IsBigInt = exports.IsInteger = exports.IsNumber = exports.IsBoolean = exports.IsNull = exports.IsUndefined = exports.IsArray = exports.IsObject = exports.
|
|
4
|
+
exports.IsValueType = exports.IsSymbol = exports.IsFunction = exports.IsString = exports.IsBigInt = exports.IsInteger = exports.IsNumber = exports.IsBoolean = exports.IsNull = exports.IsUndefined = exports.IsArray = exports.IsObject = exports.HasPropertyKey = exports.IsBigUint64Array = exports.IsBigInt64Array = exports.IsFloat64Array = exports.IsFloat32Array = exports.IsUint32Array = exports.IsInt32Array = exports.IsUint16Array = exports.IsInt16Array = exports.IsUint8ClampedArray = exports.IsUint8Array = exports.IsInt8Array = exports.IsTypedArray = exports.IsRegExp = exports.IsSet = exports.IsMap = exports.IsDate = exports.IsPromise = exports.IsInstanceObject = exports.IsStandardObject = exports.IsIterator = exports.IsAsyncIterator = void 0;
|
|
5
5
|
// --------------------------------------------------------------------------
|
|
6
6
|
// Iterators
|
|
7
7
|
// --------------------------------------------------------------------------
|
|
@@ -16,28 +16,106 @@ function IsIterator(value) {
|
|
|
16
16
|
}
|
|
17
17
|
exports.IsIterator = IsIterator;
|
|
18
18
|
// --------------------------------------------------------------------------
|
|
19
|
-
//
|
|
19
|
+
// Object Instances
|
|
20
20
|
// --------------------------------------------------------------------------
|
|
21
|
-
/** Returns true if this value is a
|
|
22
|
-
function
|
|
23
|
-
return
|
|
21
|
+
/** Returns true if this value is not an instance of a class */
|
|
22
|
+
function IsStandardObject(value) {
|
|
23
|
+
return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
|
|
24
24
|
}
|
|
25
|
-
exports.
|
|
25
|
+
exports.IsStandardObject = IsStandardObject;
|
|
26
|
+
/** Returns true if this value is an instance of a class */
|
|
27
|
+
function IsInstanceObject(value) {
|
|
28
|
+
return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name !== 'Object';
|
|
29
|
+
}
|
|
30
|
+
exports.IsInstanceObject = IsInstanceObject;
|
|
31
|
+
// --------------------------------------------------------------------------
|
|
32
|
+
// JavaScript
|
|
33
|
+
// --------------------------------------------------------------------------
|
|
26
34
|
/** Returns true if this value is a Promise */
|
|
27
35
|
function IsPromise(value) {
|
|
28
36
|
return value instanceof Promise;
|
|
29
37
|
}
|
|
30
38
|
exports.IsPromise = IsPromise;
|
|
31
|
-
/** Returns true if the value is a Uint8Array */
|
|
32
|
-
function IsUint8Array(value) {
|
|
33
|
-
return value instanceof Uint8Array;
|
|
34
|
-
}
|
|
35
|
-
exports.IsUint8Array = IsUint8Array;
|
|
36
39
|
/** Returns true if this value is a Date */
|
|
37
40
|
function IsDate(value) {
|
|
38
41
|
return value instanceof Date && Number.isFinite(value.getTime());
|
|
39
42
|
}
|
|
40
43
|
exports.IsDate = IsDate;
|
|
44
|
+
/** Returns true if this value is an instance of Map<K, T> */
|
|
45
|
+
function IsMap(value) {
|
|
46
|
+
return value instanceof globalThis.Map;
|
|
47
|
+
}
|
|
48
|
+
exports.IsMap = IsMap;
|
|
49
|
+
/** Returns true if this value is an instance of Set<T> */
|
|
50
|
+
function IsSet(value) {
|
|
51
|
+
return value instanceof globalThis.Set;
|
|
52
|
+
}
|
|
53
|
+
exports.IsSet = IsSet;
|
|
54
|
+
/** Returns true if this value is RegExp */
|
|
55
|
+
function IsRegExp(value) {
|
|
56
|
+
return value instanceof globalThis.RegExp;
|
|
57
|
+
}
|
|
58
|
+
exports.IsRegExp = IsRegExp;
|
|
59
|
+
/** Returns true if this value is a typed array */
|
|
60
|
+
function IsTypedArray(value) {
|
|
61
|
+
return ArrayBuffer.isView(value);
|
|
62
|
+
}
|
|
63
|
+
exports.IsTypedArray = IsTypedArray;
|
|
64
|
+
/** Returns true if the value is a Int8Array */
|
|
65
|
+
function IsInt8Array(value) {
|
|
66
|
+
return value instanceof globalThis.Int8Array;
|
|
67
|
+
}
|
|
68
|
+
exports.IsInt8Array = IsInt8Array;
|
|
69
|
+
/** Returns true if the value is a Uint8Array */
|
|
70
|
+
function IsUint8Array(value) {
|
|
71
|
+
return value instanceof globalThis.Uint8Array;
|
|
72
|
+
}
|
|
73
|
+
exports.IsUint8Array = IsUint8Array;
|
|
74
|
+
/** Returns true if the value is a Uint8ClampedArray */
|
|
75
|
+
function IsUint8ClampedArray(value) {
|
|
76
|
+
return value instanceof globalThis.Uint8ClampedArray;
|
|
77
|
+
}
|
|
78
|
+
exports.IsUint8ClampedArray = IsUint8ClampedArray;
|
|
79
|
+
/** Returns true if the value is a Int16Array */
|
|
80
|
+
function IsInt16Array(value) {
|
|
81
|
+
return value instanceof globalThis.Int16Array;
|
|
82
|
+
}
|
|
83
|
+
exports.IsInt16Array = IsInt16Array;
|
|
84
|
+
/** Returns true if the value is a Uint16Array */
|
|
85
|
+
function IsUint16Array(value) {
|
|
86
|
+
return value instanceof globalThis.Uint16Array;
|
|
87
|
+
}
|
|
88
|
+
exports.IsUint16Array = IsUint16Array;
|
|
89
|
+
/** Returns true if the value is a Int32Array */
|
|
90
|
+
function IsInt32Array(value) {
|
|
91
|
+
return value instanceof globalThis.Int32Array;
|
|
92
|
+
}
|
|
93
|
+
exports.IsInt32Array = IsInt32Array;
|
|
94
|
+
/** Returns true if the value is a Uint32Array */
|
|
95
|
+
function IsUint32Array(value) {
|
|
96
|
+
return value instanceof globalThis.Uint32Array;
|
|
97
|
+
}
|
|
98
|
+
exports.IsUint32Array = IsUint32Array;
|
|
99
|
+
/** Returns true if the value is a Float32Array */
|
|
100
|
+
function IsFloat32Array(value) {
|
|
101
|
+
return value instanceof globalThis.Float32Array;
|
|
102
|
+
}
|
|
103
|
+
exports.IsFloat32Array = IsFloat32Array;
|
|
104
|
+
/** Returns true if the value is a Float64Array */
|
|
105
|
+
function IsFloat64Array(value) {
|
|
106
|
+
return value instanceof globalThis.Float64Array;
|
|
107
|
+
}
|
|
108
|
+
exports.IsFloat64Array = IsFloat64Array;
|
|
109
|
+
/** Returns true if the value is a BigInt64Array */
|
|
110
|
+
function IsBigInt64Array(value) {
|
|
111
|
+
return value instanceof globalThis.BigInt64Array;
|
|
112
|
+
}
|
|
113
|
+
exports.IsBigInt64Array = IsBigInt64Array;
|
|
114
|
+
/** Returns true if the value is a BigUint64Array */
|
|
115
|
+
function IsBigUint64Array(value) {
|
|
116
|
+
return value instanceof globalThis.BigUint64Array;
|
|
117
|
+
}
|
|
118
|
+
exports.IsBigUint64Array = IsBigUint64Array;
|
|
41
119
|
// --------------------------------------------------------------------------
|
|
42
120
|
// Standard
|
|
43
121
|
// --------------------------------------------------------------------------
|
|
@@ -46,11 +124,6 @@ function HasPropertyKey(value, key) {
|
|
|
46
124
|
return key in value;
|
|
47
125
|
}
|
|
48
126
|
exports.HasPropertyKey = HasPropertyKey;
|
|
49
|
-
/** Returns true if this object is not an instance of any other type */
|
|
50
|
-
function IsPlainObject(value) {
|
|
51
|
-
return IsObject(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
|
|
52
|
-
}
|
|
53
|
-
exports.IsPlainObject = IsPlainObject;
|
|
54
127
|
/** Returns true of this value is an object type */
|
|
55
128
|
function IsObject(value) {
|
|
56
129
|
return value !== null && typeof value === 'object';
|
|
@@ -124,7 +124,7 @@ function Visit(value) {
|
|
|
124
124
|
return NullType(value);
|
|
125
125
|
if ((0, index_1.IsNumber)(value))
|
|
126
126
|
return NumberType(value);
|
|
127
|
-
if ((0, index_1.
|
|
127
|
+
if ((0, index_1.IsStandardObject)(value))
|
|
128
128
|
return ObjectType(value);
|
|
129
129
|
if ((0, index_1.IsString)(value))
|
|
130
130
|
return StringType(value);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
2
|
+
export * from './guard/index';
|
|
3
|
+
export * from './cast/index';
|
|
4
|
+
export * from './check/index';
|
|
5
|
+
export * from './clean/index';
|
|
6
|
+
export * from './clone/index';
|
|
7
|
+
export * from './convert/index';
|
|
8
|
+
export * from './create/index';
|
|
9
|
+
export * from './default/index';
|
|
10
|
+
export * from './delta/index';
|
|
11
|
+
export * from './equal/index';
|
|
12
|
+
export * from './hash/index';
|
|
13
|
+
export * from './mutate/index';
|
|
14
|
+
export * from './pointer/index';
|
|
15
|
+
export * from './transform/index';
|
|
16
16
|
export { Value } from './value/index';
|
|
@@ -1,85 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
3
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.Value = exports.IsValueType = void 0;
|
|
18
|
+
exports.Value = exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
6
19
|
// ------------------------------------------------------------------
|
|
7
|
-
//
|
|
20
|
+
// Errors (re-export)
|
|
8
21
|
// ------------------------------------------------------------------
|
|
9
22
|
var index_1 = require("../errors/index");
|
|
10
23
|
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
11
24
|
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return index_1.ValueErrorIterator; } });
|
|
12
25
|
// ------------------------------------------------------------------
|
|
13
|
-
//
|
|
26
|
+
// Guards
|
|
14
27
|
// ------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(exports, "Cast", { enumerable: true, get: function () { return index_2.Cast; } });
|
|
17
|
-
Object.defineProperty(exports, "ValueCastError", { enumerable: true, get: function () { return index_2.ValueCastError; } });
|
|
18
|
-
var index_3 = require("./check/index");
|
|
19
|
-
Object.defineProperty(exports, "Check", { enumerable: true, get: function () { return index_3.Check; } });
|
|
20
|
-
var index_4 = require("./clean/index");
|
|
21
|
-
Object.defineProperty(exports, "Clean", { enumerable: true, get: function () { return index_4.Clean; } });
|
|
22
|
-
var index_5 = require("./clone/index");
|
|
23
|
-
Object.defineProperty(exports, "Clone", { enumerable: true, get: function () { return index_5.Clone; } });
|
|
24
|
-
var index_6 = require("./convert/index");
|
|
25
|
-
Object.defineProperty(exports, "Convert", { enumerable: true, get: function () { return index_6.Convert; } });
|
|
26
|
-
var index_7 = require("./create/index");
|
|
27
|
-
Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return index_7.Create; } });
|
|
28
|
-
Object.defineProperty(exports, "ValueCreateError", { enumerable: true, get: function () { return index_7.ValueCreateError; } });
|
|
29
|
-
var index_8 = require("./default/index");
|
|
30
|
-
Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return index_8.Default; } });
|
|
31
|
-
var index_9 = require("./delta/index");
|
|
32
|
-
Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return index_9.Diff; } });
|
|
33
|
-
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return index_9.Patch; } });
|
|
34
|
-
Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return index_9.Edit; } });
|
|
35
|
-
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return index_9.Delete; } });
|
|
36
|
-
Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return index_9.Insert; } });
|
|
37
|
-
Object.defineProperty(exports, "Update", { enumerable: true, get: function () { return index_9.Update; } });
|
|
38
|
-
Object.defineProperty(exports, "ValueDeltaError", { enumerable: true, get: function () { return index_9.ValueDeltaError; } });
|
|
39
|
-
var index_10 = require("./equal/index");
|
|
40
|
-
Object.defineProperty(exports, "Equal", { enumerable: true, get: function () { return index_10.Equal; } });
|
|
41
|
-
var index_11 = require("./hash/index");
|
|
42
|
-
Object.defineProperty(exports, "Hash", { enumerable: true, get: function () { return index_11.Hash; } });
|
|
43
|
-
Object.defineProperty(exports, "ValueHashError", { enumerable: true, get: function () { return index_11.ValueHashError; } });
|
|
44
|
-
var index_12 = require("./mutate/index");
|
|
45
|
-
Object.defineProperty(exports, "Mutate", { enumerable: true, get: function () { return index_12.Mutate; } });
|
|
46
|
-
Object.defineProperty(exports, "ValueMutateError", { enumerable: true, get: function () { return index_12.ValueMutateError; } });
|
|
47
|
-
var index_13 = require("./pointer/index");
|
|
48
|
-
Object.defineProperty(exports, "ValuePointer", { enumerable: true, get: function () { return index_13.ValuePointer; } });
|
|
49
|
-
var index_14 = require("./transform/index");
|
|
50
|
-
Object.defineProperty(exports, "TransformDecode", { enumerable: true, get: function () { return index_14.TransformDecode; } });
|
|
51
|
-
Object.defineProperty(exports, "TransformEncode", { enumerable: true, get: function () { return index_14.TransformEncode; } });
|
|
52
|
-
Object.defineProperty(exports, "HasTransform", { enumerable: true, get: function () { return index_14.HasTransform; } });
|
|
53
|
-
Object.defineProperty(exports, "TransformDecodeCheckError", { enumerable: true, get: function () { return index_14.TransformDecodeCheckError; } });
|
|
54
|
-
Object.defineProperty(exports, "TransformDecodeError", { enumerable: true, get: function () { return index_14.TransformDecodeError; } });
|
|
55
|
-
Object.defineProperty(exports, "TransformEncodeCheckError", { enumerable: true, get: function () { return index_14.TransformEncodeCheckError; } });
|
|
56
|
-
Object.defineProperty(exports, "TransformEncodeError", { enumerable: true, get: function () { return index_14.TransformEncodeError; } });
|
|
28
|
+
__exportStar(require("./guard/index"), exports);
|
|
57
29
|
// ------------------------------------------------------------------
|
|
58
|
-
//
|
|
30
|
+
// Operators
|
|
59
31
|
// ------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Object.defineProperty(exports, "IsPlainObject", { enumerable: true, get: function () { return index_15.IsPlainObject; } });
|
|
74
|
-
Object.defineProperty(exports, "IsPromise", { enumerable: true, get: function () { return index_15.IsPromise; } });
|
|
75
|
-
Object.defineProperty(exports, "IsString", { enumerable: true, get: function () { return index_15.IsString; } });
|
|
76
|
-
Object.defineProperty(exports, "IsSymbol", { enumerable: true, get: function () { return index_15.IsSymbol; } });
|
|
77
|
-
Object.defineProperty(exports, "IsTypedArray", { enumerable: true, get: function () { return index_15.IsTypedArray; } });
|
|
78
|
-
Object.defineProperty(exports, "IsUint8Array", { enumerable: true, get: function () { return index_15.IsUint8Array; } });
|
|
79
|
-
Object.defineProperty(exports, "IsUndefined", { enumerable: true, get: function () { return index_15.IsUndefined; } });
|
|
80
|
-
Object.defineProperty(exports, "IsValueType", { enumerable: true, get: function () { return index_15.IsValueType; } });
|
|
32
|
+
__exportStar(require("./cast/index"), exports);
|
|
33
|
+
__exportStar(require("./check/index"), exports);
|
|
34
|
+
__exportStar(require("./clean/index"), exports);
|
|
35
|
+
__exportStar(require("./clone/index"), exports);
|
|
36
|
+
__exportStar(require("./convert/index"), exports);
|
|
37
|
+
__exportStar(require("./create/index"), exports);
|
|
38
|
+
__exportStar(require("./default/index"), exports);
|
|
39
|
+
__exportStar(require("./delta/index"), exports);
|
|
40
|
+
__exportStar(require("./equal/index"), exports);
|
|
41
|
+
__exportStar(require("./hash/index"), exports);
|
|
42
|
+
__exportStar(require("./mutate/index"), exports);
|
|
43
|
+
__exportStar(require("./pointer/index"), exports);
|
|
44
|
+
__exportStar(require("./transform/index"), exports);
|
|
81
45
|
// ------------------------------------------------------------------
|
|
82
|
-
//
|
|
46
|
+
// Namespace
|
|
83
47
|
// ------------------------------------------------------------------
|
|
84
|
-
var
|
|
85
|
-
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return
|
|
48
|
+
var index_2 = require("./value/index");
|
|
49
|
+
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return index_2.Value; } });
|
|
@@ -16,7 +16,7 @@ class ValueMutateError extends index_4.TypeBoxError {
|
|
|
16
16
|
}
|
|
17
17
|
exports.ValueMutateError = ValueMutateError;
|
|
18
18
|
function ObjectType(root, path, current, next) {
|
|
19
|
-
if (!(0, index_1.
|
|
19
|
+
if (!(0, index_1.IsStandardObject)(current)) {
|
|
20
20
|
index_2.ValuePointer.Set(root, path, (0, index_3.Clone)(next));
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
@@ -68,7 +68,7 @@ function Visit(root, path, current, next) {
|
|
|
68
68
|
return ArrayType(root, path, current, next);
|
|
69
69
|
if ((0, index_1.IsTypedArray)(next))
|
|
70
70
|
return TypedArrayType(root, path, current, next);
|
|
71
|
-
if ((0, index_1.
|
|
71
|
+
if ((0, index_1.IsStandardObject)(next))
|
|
72
72
|
return ObjectType(root, path, current, next);
|
|
73
73
|
if ((0, index_1.IsValueType)(next))
|
|
74
74
|
return ValueType(root, path, current, next);
|
|
@@ -81,8 +81,8 @@ function IsNonMutableValue(value) {
|
|
|
81
81
|
}
|
|
82
82
|
function IsMismatchedValue(current, next) {
|
|
83
83
|
// prettier-ignore
|
|
84
|
-
return (((0, index_1.
|
|
85
|
-
((0, index_1.IsArray)(current) && (0, index_1.
|
|
84
|
+
return (((0, index_1.IsStandardObject)(current) && (0, index_1.IsArray)(next)) ||
|
|
85
|
+
((0, index_1.IsArray)(current) && (0, index_1.IsStandardObject)(next)));
|
|
86
86
|
}
|
|
87
87
|
// ------------------------------------------------------------------
|
|
88
88
|
// Mutate
|
|
@@ -57,7 +57,7 @@ function FromArray(schema, references, value) {
|
|
|
57
57
|
}
|
|
58
58
|
// prettier-ignore
|
|
59
59
|
function FromIntersect(schema, references, value) {
|
|
60
|
-
if (!(0, index_7.
|
|
60
|
+
if (!(0, index_7.IsStandardObject)(value) || (0, index_7.IsValueType)(value))
|
|
61
61
|
return Default(schema, value);
|
|
62
62
|
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
63
63
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -82,7 +82,7 @@ function FromNot(schema, references, value) {
|
|
|
82
82
|
}
|
|
83
83
|
// prettier-ignore
|
|
84
84
|
function FromObject(schema, references, value) {
|
|
85
|
-
if (!(0, index_7.
|
|
85
|
+
if (!(0, index_7.IsStandardObject)(value))
|
|
86
86
|
return Default(schema, value);
|
|
87
87
|
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
88
88
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -104,7 +104,7 @@ function FromObject(schema, references, value) {
|
|
|
104
104
|
}
|
|
105
105
|
// prettier-ignore
|
|
106
106
|
function FromRecord(schema, references, value) {
|
|
107
|
-
if (!(0, index_7.
|
|
107
|
+
if (!(0, index_7.IsStandardObject)(value))
|
|
108
108
|
return Default(schema, value);
|
|
109
109
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
110
110
|
const knownKeys = new RegExp(pattern);
|
|
@@ -58,7 +58,7 @@ function FromArray(schema, references, value) {
|
|
|
58
58
|
// prettier-ignore
|
|
59
59
|
function FromIntersect(schema, references, value) {
|
|
60
60
|
const defaulted = Default(schema, value);
|
|
61
|
-
if (!(0, index_7.
|
|
61
|
+
if (!(0, index_7.IsStandardObject)(value) || (0, index_7.IsValueType)(value))
|
|
62
62
|
return defaulted;
|
|
63
63
|
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
64
64
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -84,7 +84,7 @@ function FromNot(schema, references, value) {
|
|
|
84
84
|
// prettier-ignore
|
|
85
85
|
function FromObject(schema, references, value) {
|
|
86
86
|
const defaulted = Default(schema, value);
|
|
87
|
-
if (!(0, index_7.
|
|
87
|
+
if (!(0, index_7.IsStandardObject)(value))
|
|
88
88
|
return defaulted;
|
|
89
89
|
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
90
90
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
@@ -106,7 +106,7 @@ function FromObject(schema, references, value) {
|
|
|
106
106
|
// prettier-ignore
|
|
107
107
|
function FromRecord(schema, references, value) {
|
|
108
108
|
const defaulted = Default(schema, value);
|
|
109
|
-
if (!(0, index_7.
|
|
109
|
+
if (!(0, index_7.IsStandardObject)(value))
|
|
110
110
|
return defaulted;
|
|
111
111
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
112
112
|
const knownKeys = new RegExp(pattern);
|