@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
|
@@ -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';
|
|
@@ -8,7 +8,7 @@ export declare class TypeSystemDuplicateFormat extends TypeBoxError {
|
|
|
8
8
|
/** Creates user defined types and formats and provides overrides for value checking behaviours */
|
|
9
9
|
export declare namespace TypeSystem {
|
|
10
10
|
/** Creates a new type */
|
|
11
|
-
function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("
|
|
11
|
+
function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("src/type/unsafe/unsafe.mjs").TUnsafe<Type>;
|
|
12
12
|
/** Creates a new string format */
|
|
13
13
|
function Format<F extends string>(format: F, check: (value: string) => boolean): F;
|
|
14
14
|
}
|
|
@@ -16,7 +16,7 @@ import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
|
16
16
|
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Acc);
|
|
17
17
|
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
18
18
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
19
|
-
type TFromUnionRest<T extends TSchema[]> = T;
|
|
19
|
+
type TFromUnionRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [] : TFromUnionRest<R, [L, ...Acc]> : Acc;
|
|
20
20
|
type TFromUnion<T extends TSchema[], K extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<T, K>>>);
|
|
21
21
|
type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? TUnionEvaluated<T> : TNever);
|
|
22
22
|
type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
@@ -4,23 +4,42 @@ import { TypeBoxError } from '../error/index.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
export class TemplateLiteralParserError extends TypeBoxError {
|
|
6
6
|
}
|
|
7
|
+
// -------------------------------------------------------------------
|
|
8
|
+
// Unescape
|
|
9
|
+
//
|
|
10
|
+
// Unescape for these control characters specifically. Note that this
|
|
11
|
+
// function is only called on non union group content, and where we
|
|
12
|
+
// still want to allow the user to embed control characters in that
|
|
13
|
+
// content. For review.
|
|
14
|
+
// -------------------------------------------------------------------
|
|
7
15
|
// prettier-ignore
|
|
16
|
+
function Unescape(pattern) {
|
|
17
|
+
return pattern
|
|
18
|
+
.replace(/\\\$/g, '$')
|
|
19
|
+
.replace(/\\\*/g, '*')
|
|
20
|
+
.replace(/\\\^/g, '^')
|
|
21
|
+
.replace(/\\\|/g, '|')
|
|
22
|
+
.replace(/\\\(/g, '(')
|
|
23
|
+
.replace(/\\\)/g, ')');
|
|
24
|
+
}
|
|
25
|
+
// -------------------------------------------------------------------
|
|
26
|
+
// Control Characters
|
|
27
|
+
// -------------------------------------------------------------------
|
|
8
28
|
function IsNonEscaped(pattern, index, char) {
|
|
9
29
|
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
10
30
|
}
|
|
11
|
-
// prettier-ignore
|
|
12
31
|
function IsOpenParen(pattern, index) {
|
|
13
32
|
return IsNonEscaped(pattern, index, '(');
|
|
14
33
|
}
|
|
15
|
-
// prettier-ignore
|
|
16
34
|
function IsCloseParen(pattern, index) {
|
|
17
35
|
return IsNonEscaped(pattern, index, ')');
|
|
18
36
|
}
|
|
19
|
-
// prettier-ignore
|
|
20
37
|
function IsSeparator(pattern, index) {
|
|
21
38
|
return IsNonEscaped(pattern, index, '|');
|
|
22
39
|
}
|
|
23
|
-
//
|
|
40
|
+
// -------------------------------------------------------------------
|
|
41
|
+
// Control Groups
|
|
42
|
+
// -------------------------------------------------------------------
|
|
24
43
|
function IsGroup(pattern) {
|
|
25
44
|
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
26
45
|
return false;
|
|
@@ -137,7 +156,7 @@ export function TemplateLiteralParse(pattern) {
|
|
|
137
156
|
return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
|
|
138
157
|
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
139
158
|
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
140
|
-
{ type: 'const', const: pattern });
|
|
159
|
+
{ type: 'const', const: Unescape(pattern) });
|
|
141
160
|
}
|
|
142
161
|
// ------------------------------------------------------------------
|
|
143
162
|
// TemplateLiteralParseExact
|
|
@@ -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 */
|
|
@@ -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,9 +1,6 @@
|
|
|
1
1
|
import { Clone } from '../clone/index.mjs';
|
|
2
|
-
import { Check } from '../check/index.mjs';
|
|
3
2
|
import { Deref } from '../deref/index.mjs';
|
|
4
|
-
import { IsObject as IsObjectType } from '../../type/guard/type.mjs';
|
|
5
3
|
import { Kind } from '../../type/symbols/index.mjs';
|
|
6
|
-
import { Composite } from '../../type/composite/index.mjs';
|
|
7
4
|
// ------------------------------------------------------------------
|
|
8
5
|
// ValueGuard
|
|
9
6
|
// ------------------------------------------------------------------
|
|
@@ -129,12 +126,8 @@ function FromDate(schema, references, value) {
|
|
|
129
126
|
function FromInteger(schema, references, value) {
|
|
130
127
|
return TryConvertInteger(value);
|
|
131
128
|
}
|
|
132
|
-
// prettier-ignore
|
|
133
129
|
function FromIntersect(schema, references, value) {
|
|
134
|
-
|
|
135
|
-
if (allObjects)
|
|
136
|
-
return Visit(Composite(schema.allOf), references, value);
|
|
137
|
-
return Visit(schema.allOf[0], references, value); // todo: fix this
|
|
130
|
+
return schema.allOf.reduce((value, schema) => Visit(schema, references, value), value);
|
|
138
131
|
}
|
|
139
132
|
function FromLiteral(schema, references, value) {
|
|
140
133
|
return TryConvertLiteral(schema, value);
|
|
@@ -192,13 +185,7 @@ function FromUndefined(schema, references, value) {
|
|
|
192
185
|
return TryConvertUndefined(value);
|
|
193
186
|
}
|
|
194
187
|
function FromUnion(schema, references, value) {
|
|
195
|
-
|
|
196
|
-
const converted = Visit(subschema, references, value);
|
|
197
|
-
if (Check(subschema, references, converted)) {
|
|
198
|
-
return converted;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return value;
|
|
188
|
+
return schema.anyOf.reduce((value, schema) => Visit(schema, references, value), value);
|
|
202
189
|
}
|
|
203
190
|
function Visit(schema, references, value) {
|
|
204
191
|
const references_ = IsString(schema.$id) ? [...references, schema] : references;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import type { Static } from '../../type/static/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
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.mjs").TObject<{
|
|
5
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"insert">;
|
|
6
|
+
path: import("src/type/string/string.mjs").TString;
|
|
7
|
+
value: import("src/type/unknown/unknown.mjs").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.mjs").TObject<{
|
|
11
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"update">;
|
|
12
|
+
path: import("src/type/string/string.mjs").TString;
|
|
13
|
+
value: import("src/type/unknown/unknown.mjs").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.mjs").TObject<{
|
|
17
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"delete">;
|
|
18
|
+
path: import("src/type/string/string.mjs").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.mjs").TUnion<[import("src/type/object/object.mjs").TObject<{
|
|
22
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"insert">;
|
|
23
|
+
path: import("src/type/string/string.mjs").TString;
|
|
24
|
+
value: import("src/type/unknown/unknown.mjs").TUnknown;
|
|
25
|
+
}>, import("src/type/object/object.mjs").TObject<{
|
|
26
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"update">;
|
|
27
|
+
path: import("src/type/string/string.mjs").TString;
|
|
28
|
+
value: import("src/type/unknown/unknown.mjs").TUnknown;
|
|
29
|
+
}>, import("src/type/object/object.mjs").TObject<{
|
|
30
|
+
type: import("src/type/literal/literal.mjs").TLiteral<"delete">;
|
|
31
|
+
path: import("src/type/string/string.mjs").TString;
|
|
32
32
|
}>]>;
|
|
33
33
|
export declare class ValueDeltaError extends TypeBoxError {
|
|
34
34
|
readonly value: unknown;
|
|
@@ -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
|
|
@@ -9,8 +9,10 @@ export declare class TransformDecodeCheckError extends TypeBoxError {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class TransformDecodeError extends TypeBoxError {
|
|
11
11
|
readonly schema: TSchema;
|
|
12
|
+
readonly path: string;
|
|
12
13
|
readonly value: unknown;
|
|
13
|
-
|
|
14
|
+
readonly error: Error;
|
|
15
|
+
constructor(schema: TSchema, path: string, value: unknown, error: Error);
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* `[Internal]` Decodes the value and returns the result. This function requires that
|