@sinclair/typebox 0.32.14 → 0.32.16
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/system/system.d.mts +1 -1
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +3 -1
- package/build/import/type/template-literal/parse.mjs +24 -5
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/value/cast/cast.mjs +2 -2
- package/build/import/value/clone/clone.mjs +2 -2
- package/build/import/value/convert/convert.mjs +2 -15
- package/build/import/value/delta/delta.d.mts +22 -22
- 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.d.mts +3 -1
- package/build/import/value/transform/decode.mjs +62 -56
- package/build/import/value/transform/encode.d.mts +3 -1
- package/build/import/value/transform/encode.mjs +60 -54
- package/build/import/value/value/value.mjs +1 -1
- 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/system/system.d.ts +1 -1
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +3 -1
- package/build/require/type/template-literal/parse.js +24 -5
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/value/cast/cast.js +1 -1
- package/build/require/value/clone/clone.js +1 -1
- package/build/require/value/convert/convert.js +33 -46
- package/build/require/value/delta/delta.d.ts +22 -22
- 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.d.ts +3 -1
- package/build/require/value/transform/decode.js +59 -55
- package/build/require/value/transform/encode.d.ts +3 -1
- package/build/require/value/transform/encode.js +57 -53
- package/build/require/value/value/value.js +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
|
@@ -9,23 +9,42 @@ const index_1 = require("../error/index");
|
|
|
9
9
|
class TemplateLiteralParserError extends index_1.TypeBoxError {
|
|
10
10
|
}
|
|
11
11
|
exports.TemplateLiteralParserError = TemplateLiteralParserError;
|
|
12
|
+
// -------------------------------------------------------------------
|
|
13
|
+
// Unescape
|
|
14
|
+
//
|
|
15
|
+
// Unescape for these control characters specifically. Note that this
|
|
16
|
+
// function is only called on non union group content, and where we
|
|
17
|
+
// still want to allow the user to embed control characters in that
|
|
18
|
+
// content. For review.
|
|
19
|
+
// -------------------------------------------------------------------
|
|
12
20
|
// prettier-ignore
|
|
21
|
+
function Unescape(pattern) {
|
|
22
|
+
return pattern
|
|
23
|
+
.replace(/\\\$/g, '$')
|
|
24
|
+
.replace(/\\\*/g, '*')
|
|
25
|
+
.replace(/\\\^/g, '^')
|
|
26
|
+
.replace(/\\\|/g, '|')
|
|
27
|
+
.replace(/\\\(/g, '(')
|
|
28
|
+
.replace(/\\\)/g, ')');
|
|
29
|
+
}
|
|
30
|
+
// -------------------------------------------------------------------
|
|
31
|
+
// Control Characters
|
|
32
|
+
// -------------------------------------------------------------------
|
|
13
33
|
function IsNonEscaped(pattern, index, char) {
|
|
14
34
|
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
15
35
|
}
|
|
16
|
-
// prettier-ignore
|
|
17
36
|
function IsOpenParen(pattern, index) {
|
|
18
37
|
return IsNonEscaped(pattern, index, '(');
|
|
19
38
|
}
|
|
20
|
-
// prettier-ignore
|
|
21
39
|
function IsCloseParen(pattern, index) {
|
|
22
40
|
return IsNonEscaped(pattern, index, ')');
|
|
23
41
|
}
|
|
24
|
-
// prettier-ignore
|
|
25
42
|
function IsSeparator(pattern, index) {
|
|
26
43
|
return IsNonEscaped(pattern, index, '|');
|
|
27
44
|
}
|
|
28
|
-
//
|
|
45
|
+
// -------------------------------------------------------------------
|
|
46
|
+
// Control Groups
|
|
47
|
+
// -------------------------------------------------------------------
|
|
29
48
|
function IsGroup(pattern) {
|
|
30
49
|
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
31
50
|
return false;
|
|
@@ -142,7 +161,7 @@ function TemplateLiteralParse(pattern) {
|
|
|
142
161
|
return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
|
|
143
162
|
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
144
163
|
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
145
|
-
{ type: 'const', const: pattern });
|
|
164
|
+
{ type: 'const', const: Unescape(pattern) });
|
|
146
165
|
}
|
|
147
166
|
exports.TemplateLiteralParse = TemplateLiteralParse;
|
|
148
167
|
// ------------------------------------------------------------------
|
|
@@ -12,7 +12,7 @@ type FromUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [T
|
|
|
12
12
|
];
|
|
13
13
|
type FromUnion<T extends string> = TUnionEvaluated<FromUnionLiteral<T>>;
|
|
14
14
|
type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
|
|
15
|
-
type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}
|
|
15
|
+
type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$\{${infer R1}\}${infer R2}` ? [TLiteral<L>, ...FromString<`{${R1}}`>, ...FromString<R2>] : T extends `${infer L}$\{${infer R1}\}` ? [TLiteral<L>, ...FromString<`{${R1}}`>] : T extends `${infer L}` ? [TLiteral<L>] : [
|
|
16
16
|
];
|
|
17
17
|
export type TTemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
|
|
18
18
|
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
|
|
@@ -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);
|
|
@@ -3,44 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Convert = void 0;
|
|
5
5
|
const index_1 = require("../clone/index");
|
|
6
|
-
const index_2 = require("../
|
|
7
|
-
const index_3 = require("
|
|
8
|
-
const type_1 = require("../../type/guard/type");
|
|
9
|
-
const index_4 = require("../../type/symbols/index");
|
|
10
|
-
const index_5 = require("../../type/composite/index");
|
|
6
|
+
const index_2 = require("../deref/index");
|
|
7
|
+
const index_3 = require("../../type/symbols/index");
|
|
11
8
|
// ------------------------------------------------------------------
|
|
12
9
|
// ValueGuard
|
|
13
10
|
// ------------------------------------------------------------------
|
|
14
|
-
const
|
|
11
|
+
const index_4 = require("../guard/index");
|
|
15
12
|
// ------------------------------------------------------------------
|
|
16
13
|
// Conversions
|
|
17
14
|
// ------------------------------------------------------------------
|
|
18
15
|
function IsStringNumeric(value) {
|
|
19
|
-
return (0,
|
|
16
|
+
return (0, index_4.IsString)(value) && !isNaN(value) && !isNaN(parseFloat(value));
|
|
20
17
|
}
|
|
21
18
|
function IsValueToString(value) {
|
|
22
|
-
return (0,
|
|
19
|
+
return (0, index_4.IsBigInt)(value) || (0, index_4.IsBoolean)(value) || (0, index_4.IsNumber)(value);
|
|
23
20
|
}
|
|
24
21
|
function IsValueTrue(value) {
|
|
25
|
-
return value === true || ((0,
|
|
22
|
+
return value === true || ((0, index_4.IsNumber)(value) && value === 1) || ((0, index_4.IsBigInt)(value) && value === BigInt('1')) || ((0, index_4.IsString)(value) && (value.toLowerCase() === 'true' || value === '1'));
|
|
26
23
|
}
|
|
27
24
|
function IsValueFalse(value) {
|
|
28
|
-
return value === false || ((0,
|
|
25
|
+
return value === false || ((0, index_4.IsNumber)(value) && (value === 0 || Object.is(value, -0))) || ((0, index_4.IsBigInt)(value) && value === BigInt('0')) || ((0, index_4.IsString)(value) && (value.toLowerCase() === 'false' || value === '0' || value === '-0'));
|
|
29
26
|
}
|
|
30
27
|
function IsTimeStringWithTimeZone(value) {
|
|
31
|
-
return (0,
|
|
28
|
+
return (0, index_4.IsString)(value) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value);
|
|
32
29
|
}
|
|
33
30
|
function IsTimeStringWithoutTimeZone(value) {
|
|
34
|
-
return (0,
|
|
31
|
+
return (0, index_4.IsString)(value) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value);
|
|
35
32
|
}
|
|
36
33
|
function IsDateTimeStringWithTimeZone(value) {
|
|
37
|
-
return (0,
|
|
34
|
+
return (0, index_4.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value);
|
|
38
35
|
}
|
|
39
36
|
function IsDateTimeStringWithoutTimeZone(value) {
|
|
40
|
-
return (0,
|
|
37
|
+
return (0, index_4.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value);
|
|
41
38
|
}
|
|
42
39
|
function IsDateString(value) {
|
|
43
|
-
return (0,
|
|
40
|
+
return (0, index_4.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\d$/i.test(value);
|
|
44
41
|
}
|
|
45
42
|
// ------------------------------------------------------------------
|
|
46
43
|
// Convert
|
|
@@ -59,31 +56,31 @@ function TryConvertLiteralBoolean(value, target) {
|
|
|
59
56
|
}
|
|
60
57
|
// prettier-ignore
|
|
61
58
|
function TryConvertLiteral(schema, value) {
|
|
62
|
-
return ((0,
|
|
63
|
-
(0,
|
|
64
|
-
(0,
|
|
59
|
+
return ((0, index_4.IsString)(schema.const) ? TryConvertLiteralString(value, schema.const) :
|
|
60
|
+
(0, index_4.IsNumber)(schema.const) ? TryConvertLiteralNumber(value, schema.const) :
|
|
61
|
+
(0, index_4.IsBoolean)(schema.const) ? TryConvertLiteralBoolean(value, schema.const) :
|
|
65
62
|
(0, index_1.Clone)(value));
|
|
66
63
|
}
|
|
67
64
|
function TryConvertBoolean(value) {
|
|
68
65
|
return IsValueTrue(value) ? true : IsValueFalse(value) ? false : value;
|
|
69
66
|
}
|
|
70
67
|
function TryConvertBigInt(value) {
|
|
71
|
-
return IsStringNumeric(value) ? BigInt(parseInt(value)) : (0,
|
|
68
|
+
return IsStringNumeric(value) ? BigInt(parseInt(value)) : (0, index_4.IsNumber)(value) ? BigInt(value | 0) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
|
|
72
69
|
}
|
|
73
70
|
function TryConvertString(value) {
|
|
74
|
-
return IsValueToString(value) ? value.toString() : (0,
|
|
71
|
+
return IsValueToString(value) ? value.toString() : (0, index_4.IsSymbol)(value) && value.description !== undefined ? value.description.toString() : value;
|
|
75
72
|
}
|
|
76
73
|
function TryConvertNumber(value) {
|
|
77
74
|
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
78
75
|
}
|
|
79
76
|
function TryConvertInteger(value) {
|
|
80
|
-
return IsStringNumeric(value) ? parseInt(value) : (0,
|
|
77
|
+
return IsStringNumeric(value) ? parseInt(value) : (0, index_4.IsNumber)(value) ? value | 0 : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
81
78
|
}
|
|
82
79
|
function TryConvertNull(value) {
|
|
83
|
-
return (0,
|
|
80
|
+
return (0, index_4.IsString)(value) && value.toLowerCase() === 'null' ? null : value;
|
|
84
81
|
}
|
|
85
82
|
function TryConvertUndefined(value) {
|
|
86
|
-
return (0,
|
|
83
|
+
return (0, index_4.IsString)(value) && value === 'undefined' ? undefined : value;
|
|
87
84
|
}
|
|
88
85
|
// ------------------------------------------------------------------
|
|
89
86
|
// note: this function may return an invalid dates for the regex
|
|
@@ -94,8 +91,8 @@ function TryConvertUndefined(value) {
|
|
|
94
91
|
// ------------------------------------------------------------------
|
|
95
92
|
// prettier-ignore
|
|
96
93
|
function TryConvertDate(value) {
|
|
97
|
-
return ((0,
|
|
98
|
-
(0,
|
|
94
|
+
return ((0, index_4.IsDate)(value) ? value :
|
|
95
|
+
(0, index_4.IsNumber)(value) ? new Date(value) :
|
|
99
96
|
IsValueTrue(value) ? new Date(1) :
|
|
100
97
|
IsValueFalse(value) ? new Date(0) :
|
|
101
98
|
IsStringNumeric(value) ? new Date(parseInt(value)) :
|
|
@@ -116,7 +113,7 @@ function Default(value) {
|
|
|
116
113
|
// Convert
|
|
117
114
|
// ------------------------------------------------------------------
|
|
118
115
|
function FromArray(schema, references, value) {
|
|
119
|
-
if ((0,
|
|
116
|
+
if ((0, index_4.IsArray)(value)) {
|
|
120
117
|
return value.map((value) => Visit(schema.items, references, value));
|
|
121
118
|
}
|
|
122
119
|
return value;
|
|
@@ -133,12 +130,8 @@ function FromDate(schema, references, value) {
|
|
|
133
130
|
function FromInteger(schema, references, value) {
|
|
134
131
|
return TryConvertInteger(value);
|
|
135
132
|
}
|
|
136
|
-
// prettier-ignore
|
|
137
133
|
function FromIntersect(schema, references, value) {
|
|
138
|
-
|
|
139
|
-
if (allObjects)
|
|
140
|
-
return Visit((0, index_5.Composite)(schema.allOf), references, value);
|
|
141
|
-
return Visit(schema.allOf[0], references, value); // todo: fix this
|
|
134
|
+
return schema.allOf.reduce((value, schema) => Visit(schema, references, value), value);
|
|
142
135
|
}
|
|
143
136
|
function FromLiteral(schema, references, value) {
|
|
144
137
|
return TryConvertLiteral(schema, value);
|
|
@@ -151,11 +144,11 @@ function FromNumber(schema, references, value) {
|
|
|
151
144
|
}
|
|
152
145
|
// prettier-ignore
|
|
153
146
|
function FromObject(schema, references, value) {
|
|
154
|
-
const isConvertable = (0,
|
|
147
|
+
const isConvertable = (0, index_4.IsObject)(value);
|
|
155
148
|
if (!isConvertable)
|
|
156
149
|
return value;
|
|
157
150
|
return Object.getOwnPropertyNames(schema.properties).reduce((value, key) => {
|
|
158
|
-
return !(0,
|
|
151
|
+
return !(0, index_4.IsUndefined)(value[key])
|
|
159
152
|
? ({ ...value, [key]: Visit(schema.properties[key], references, value[key]) })
|
|
160
153
|
: ({ ...value });
|
|
161
154
|
}, value);
|
|
@@ -170,20 +163,20 @@ function FromRecord(schema, references, value) {
|
|
|
170
163
|
return result;
|
|
171
164
|
}
|
|
172
165
|
function FromRef(schema, references, value) {
|
|
173
|
-
return Visit((0,
|
|
166
|
+
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
174
167
|
}
|
|
175
168
|
function FromString(schema, references, value) {
|
|
176
169
|
return TryConvertString(value);
|
|
177
170
|
}
|
|
178
171
|
function FromSymbol(schema, references, value) {
|
|
179
|
-
return (0,
|
|
172
|
+
return (0, index_4.IsString)(value) || (0, index_4.IsNumber)(value) ? Symbol(value) : value;
|
|
180
173
|
}
|
|
181
174
|
function FromThis(schema, references, value) {
|
|
182
|
-
return Visit((0,
|
|
175
|
+
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
183
176
|
}
|
|
184
177
|
// prettier-ignore
|
|
185
178
|
function FromTuple(schema, references, value) {
|
|
186
|
-
const isConvertable = (0,
|
|
179
|
+
const isConvertable = (0, index_4.IsArray)(value) && !(0, index_4.IsUndefined)(schema.items);
|
|
187
180
|
if (!isConvertable)
|
|
188
181
|
return value;
|
|
189
182
|
return value.map((value, index) => {
|
|
@@ -196,18 +189,12 @@ function FromUndefined(schema, references, value) {
|
|
|
196
189
|
return TryConvertUndefined(value);
|
|
197
190
|
}
|
|
198
191
|
function FromUnion(schema, references, value) {
|
|
199
|
-
|
|
200
|
-
const converted = Visit(subschema, references, value);
|
|
201
|
-
if ((0, index_2.Check)(subschema, references, converted)) {
|
|
202
|
-
return converted;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return value;
|
|
192
|
+
return schema.anyOf.reduce((value, schema) => Visit(schema, references, value), value);
|
|
206
193
|
}
|
|
207
194
|
function Visit(schema, references, value) {
|
|
208
|
-
const references_ = (0,
|
|
195
|
+
const references_ = (0, index_4.IsString)(schema.$id) ? [...references, schema] : references;
|
|
209
196
|
const schema_ = schema;
|
|
210
|
-
switch (schema[
|
|
197
|
+
switch (schema[index_3.Kind]) {
|
|
211
198
|
case 'Array':
|
|
212
199
|
return FromArray(schema_, references_, value);
|
|
213
200
|
case 'BigInt':
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import type { Static } from '../../type/static/index';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index';
|
|
3
3
|
export type Insert = Static<typeof Insert>;
|
|
4
|
-
export declare const Insert: import("
|
|
5
|
-
type: import("
|
|
6
|
-
path: import("
|
|
7
|
-
value: import("
|
|
4
|
+
export declare const Insert: import("src/type/object/object").TObject<{
|
|
5
|
+
type: import("src/type/literal/literal").TLiteral<"insert">;
|
|
6
|
+
path: import("src/type/string/string").TString;
|
|
7
|
+
value: import("src/type/unknown/unknown").TUnknown;
|
|
8
8
|
}>;
|
|
9
9
|
export type Update = Static<typeof Update>;
|
|
10
|
-
export declare const Update: import("
|
|
11
|
-
type: import("
|
|
12
|
-
path: import("
|
|
13
|
-
value: import("
|
|
10
|
+
export declare const Update: import("src/type/object/object").TObject<{
|
|
11
|
+
type: import("src/type/literal/literal").TLiteral<"update">;
|
|
12
|
+
path: import("src/type/string/string").TString;
|
|
13
|
+
value: import("src/type/unknown/unknown").TUnknown;
|
|
14
14
|
}>;
|
|
15
15
|
export type Delete = Static<typeof Delete>;
|
|
16
|
-
export declare const Delete: import("
|
|
17
|
-
type: import("
|
|
18
|
-
path: import("
|
|
16
|
+
export declare const Delete: import("src/type/object/object").TObject<{
|
|
17
|
+
type: import("src/type/literal/literal").TLiteral<"delete">;
|
|
18
|
+
path: import("src/type/string/string").TString;
|
|
19
19
|
}>;
|
|
20
20
|
export type Edit = Static<typeof Edit>;
|
|
21
|
-
export declare const Edit: import("
|
|
22
|
-
type: import("
|
|
23
|
-
path: import("
|
|
24
|
-
value: import("
|
|
25
|
-
}>, import("
|
|
26
|
-
type: import("
|
|
27
|
-
path: import("
|
|
28
|
-
value: import("
|
|
29
|
-
}>, import("
|
|
30
|
-
type: import("
|
|
31
|
-
path: import("
|
|
21
|
+
export declare const Edit: import("src/type/union/union-type").TUnion<[import("src/type/object/object").TObject<{
|
|
22
|
+
type: import("src/type/literal/literal").TLiteral<"insert">;
|
|
23
|
+
path: import("src/type/string/string").TString;
|
|
24
|
+
value: import("src/type/unknown/unknown").TUnknown;
|
|
25
|
+
}>, import("src/type/object/object").TObject<{
|
|
26
|
+
type: import("src/type/literal/literal").TLiteral<"update">;
|
|
27
|
+
path: import("src/type/string/string").TString;
|
|
28
|
+
value: import("src/type/unknown/unknown").TUnknown;
|
|
29
|
+
}>, import("src/type/object/object").TObject<{
|
|
30
|
+
type: import("src/type/literal/literal").TLiteral<"delete">;
|
|
31
|
+
path: import("src/type/string/string").TString;
|
|
32
32
|
}>]>;
|
|
33
33
|
export declare class ValueDeltaError extends TypeBoxError {
|
|
34
34
|
readonly value: unknown;
|
|
@@ -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';
|