@sinclair/typebox 0.34.12 → 0.34.14
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/cjs/compiler/compiler.js +1 -1
- package/build/cjs/type/ref/ref.d.ts +19 -6
- package/build/cjs/type/type/json.d.ts +19 -6
- package/build/cjs/value/convert/convert.js +1 -1
- package/build/cjs/value/guard/guard.js +8 -8
- package/build/esm/compiler/compiler.mjs +1 -1
- package/build/esm/type/ref/ref.d.mts +19 -6
- package/build/esm/type/type/json.d.mts +19 -6
- package/build/esm/value/convert/convert.mjs +1 -1
- package/build/esm/value/guard/guard.mjs +8 -8
- package/license +1 -1
- package/package.json +1 -1
|
@@ -376,7 +376,7 @@ var TypeCompiler;
|
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
function* FromPromise(schema, references, value) {
|
|
379
|
-
yield
|
|
379
|
+
yield `${value} instanceof Promise`;
|
|
380
380
|
}
|
|
381
381
|
function* FromRecord(schema, references, value) {
|
|
382
382
|
yield Policy.IsRecordLike(value);
|
|
@@ -11,18 +11,31 @@ export type TRefUnsafe<Type extends TSchema> = TUnsafe<Static<Type>>;
|
|
|
11
11
|
/** `[Json]` Creates a Ref type.*/
|
|
12
12
|
export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
13
13
|
/**
|
|
14
|
-
* @deprecated `[Json]` Creates a Ref type.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
|
|
15
|
+
* a `string` value for the reference (and not a schema).
|
|
16
|
+
*
|
|
17
|
+
* To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
|
|
18
18
|
*
|
|
19
19
|
* ```typescript
|
|
20
|
+
* // pre-0.34.0
|
|
21
|
+
*
|
|
22
|
+
* const T = Type.String({ $id: 'T' })
|
|
23
|
+
*
|
|
20
24
|
* const R = Type.Ref(T)
|
|
21
25
|
* ```
|
|
22
|
-
* to
|
|
26
|
+
* should be changed to the following
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // post-0.34.0
|
|
30
|
+
*
|
|
31
|
+
* const T = Type.String({ $id: 'T' })
|
|
32
|
+
*
|
|
33
|
+
* const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
|
|
34
|
+
* ```
|
|
35
|
+
* You can also create a generic function to replicate the pre-0.34.0 signature if required
|
|
23
36
|
*
|
|
24
37
|
* ```typescript
|
|
25
|
-
* const
|
|
38
|
+
* const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
|
|
26
39
|
* ```
|
|
27
40
|
*/
|
|
28
41
|
export declare function Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
|
|
@@ -151,18 +151,31 @@ export declare class JsonTypeBuilder {
|
|
|
151
151
|
/** `[Json]` Creates a Ref type.*/
|
|
152
152
|
Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
153
153
|
/**
|
|
154
|
-
* @deprecated `[Json]` Creates a Ref type.
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
154
|
+
* @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
|
|
155
|
+
* a `string` value for the reference (and not a schema).
|
|
156
|
+
*
|
|
157
|
+
* To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
|
|
158
158
|
*
|
|
159
159
|
* ```typescript
|
|
160
|
+
* // pre-0.34.0
|
|
161
|
+
*
|
|
162
|
+
* const T = Type.String({ $id: 'T' })
|
|
163
|
+
*
|
|
160
164
|
* const R = Type.Ref(T)
|
|
161
165
|
* ```
|
|
162
|
-
* to
|
|
166
|
+
* should be changed to the following
|
|
167
|
+
*
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // post-0.34.0
|
|
170
|
+
*
|
|
171
|
+
* const T = Type.String({ $id: 'T' })
|
|
172
|
+
*
|
|
173
|
+
* const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
|
|
174
|
+
* ```
|
|
175
|
+
* You can also create a generic function to replicate the pre-0.34.0 signature if required
|
|
163
176
|
*
|
|
164
177
|
* ```typescript
|
|
165
|
-
* const
|
|
178
|
+
* const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
|
|
166
179
|
* ```
|
|
167
180
|
*/
|
|
168
181
|
Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
|
|
@@ -70,7 +70,7 @@ function TryConvertBigInt(value) {
|
|
|
70
70
|
return IsStringNumeric(value) ? BigInt(truncateInteger(value)) : (0, index_5.IsNumber)(value) ? BigInt(Math.trunc(value)) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
|
|
71
71
|
}
|
|
72
72
|
function TryConvertString(value) {
|
|
73
|
-
return
|
|
73
|
+
return (0, index_5.IsSymbol)(value) && value.description !== undefined ? value.description.toString() : IsValueToString(value) ? value.toString() : value;
|
|
74
74
|
}
|
|
75
75
|
function TryConvertNumber(value) {
|
|
76
76
|
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
@@ -40,18 +40,18 @@ exports.IsValueType = IsValueType;
|
|
|
40
40
|
// --------------------------------------------------------------------------
|
|
41
41
|
/** Returns true if this value is an async iterator */
|
|
42
42
|
function IsAsyncIterator(value) {
|
|
43
|
-
return IsObject(value) && Symbol.asyncIterator in value;
|
|
43
|
+
return IsObject(value) && globalThis.Symbol.asyncIterator in value;
|
|
44
44
|
}
|
|
45
45
|
/** Returns true if this value is an iterator */
|
|
46
46
|
function IsIterator(value) {
|
|
47
|
-
return IsObject(value) && Symbol.iterator in value;
|
|
47
|
+
return IsObject(value) && globalThis.Symbol.iterator in value;
|
|
48
48
|
}
|
|
49
49
|
// --------------------------------------------------------------------------
|
|
50
50
|
// Object Instances
|
|
51
51
|
// --------------------------------------------------------------------------
|
|
52
52
|
/** Returns true if this value is not an instance of a class */
|
|
53
53
|
function IsStandardObject(value) {
|
|
54
|
-
return IsObject(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
54
|
+
return IsObject(value) && (globalThis.Object.getPrototypeOf(value) === Object.prototype || globalThis.Object.getPrototypeOf(value) === null);
|
|
55
55
|
}
|
|
56
56
|
/** Returns true if this value is an instance of a class */
|
|
57
57
|
function IsInstanceObject(value) {
|
|
@@ -62,11 +62,11 @@ function IsInstanceObject(value) {
|
|
|
62
62
|
// --------------------------------------------------------------------------
|
|
63
63
|
/** Returns true if this value is a Promise */
|
|
64
64
|
function IsPromise(value) {
|
|
65
|
-
return value instanceof Promise;
|
|
65
|
+
return value instanceof globalThis.Promise;
|
|
66
66
|
}
|
|
67
67
|
/** Returns true if this value is a Date */
|
|
68
68
|
function IsDate(value) {
|
|
69
|
-
return value instanceof Date && Number.isFinite(value.getTime());
|
|
69
|
+
return value instanceof Date && globalThis.Number.isFinite(value.getTime());
|
|
70
70
|
}
|
|
71
71
|
/** Returns true if this value is an instance of Map<K, T> */
|
|
72
72
|
function IsMap(value) {
|
|
@@ -82,7 +82,7 @@ function IsRegExp(value) {
|
|
|
82
82
|
}
|
|
83
83
|
/** Returns true if this value is a typed array */
|
|
84
84
|
function IsTypedArray(value) {
|
|
85
|
-
return ArrayBuffer.isView(value);
|
|
85
|
+
return globalThis.ArrayBuffer.isView(value);
|
|
86
86
|
}
|
|
87
87
|
/** Returns true if the value is a Int8Array */
|
|
88
88
|
function IsInt8Array(value) {
|
|
@@ -144,7 +144,7 @@ function IsObject(value) {
|
|
|
144
144
|
}
|
|
145
145
|
/** Returns true if this value is an array, but not a typed array */
|
|
146
146
|
function IsArray(value) {
|
|
147
|
-
return Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
147
|
+
return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
|
|
148
148
|
}
|
|
149
149
|
/** Returns true if this value is an undefined */
|
|
150
150
|
function IsUndefined(value) {
|
|
@@ -164,7 +164,7 @@ function IsNumber(value) {
|
|
|
164
164
|
}
|
|
165
165
|
/** Returns true if this value is an integer */
|
|
166
166
|
function IsInteger(value) {
|
|
167
|
-
return Number.isInteger(value);
|
|
167
|
+
return globalThis.Number.isInteger(value);
|
|
168
168
|
}
|
|
169
169
|
/** Returns true if this value is bigint */
|
|
170
170
|
function IsBigInt(value) {
|
|
@@ -369,7 +369,7 @@ export var TypeCompiler;
|
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
function* FromPromise(schema, references, value) {
|
|
372
|
-
yield
|
|
372
|
+
yield `${value} instanceof Promise`;
|
|
373
373
|
}
|
|
374
374
|
function* FromRecord(schema, references, value) {
|
|
375
375
|
yield Policy.IsRecordLike(value);
|
|
@@ -11,18 +11,31 @@ export type TRefUnsafe<Type extends TSchema> = TUnsafe<Static<Type>>;
|
|
|
11
11
|
/** `[Json]` Creates a Ref type.*/
|
|
12
12
|
export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
13
13
|
/**
|
|
14
|
-
* @deprecated `[Json]` Creates a Ref type.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
|
|
15
|
+
* a `string` value for the reference (and not a schema).
|
|
16
|
+
*
|
|
17
|
+
* To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
|
|
18
18
|
*
|
|
19
19
|
* ```typescript
|
|
20
|
+
* // pre-0.34.0
|
|
21
|
+
*
|
|
22
|
+
* const T = Type.String({ $id: 'T' })
|
|
23
|
+
*
|
|
20
24
|
* const R = Type.Ref(T)
|
|
21
25
|
* ```
|
|
22
|
-
* to
|
|
26
|
+
* should be changed to the following
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // post-0.34.0
|
|
30
|
+
*
|
|
31
|
+
* const T = Type.String({ $id: 'T' })
|
|
32
|
+
*
|
|
33
|
+
* const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
|
|
34
|
+
* ```
|
|
35
|
+
* You can also create a generic function to replicate the pre-0.34.0 signature if required
|
|
23
36
|
*
|
|
24
37
|
* ```typescript
|
|
25
|
-
* const
|
|
38
|
+
* const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
|
|
26
39
|
* ```
|
|
27
40
|
*/
|
|
28
41
|
export declare function Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
|
|
@@ -151,18 +151,31 @@ export declare class JsonTypeBuilder {
|
|
|
151
151
|
/** `[Json]` Creates a Ref type.*/
|
|
152
152
|
Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
153
153
|
/**
|
|
154
|
-
* @deprecated `[Json]` Creates a Ref type.
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
154
|
+
* @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
|
|
155
|
+
* a `string` value for the reference (and not a schema).
|
|
156
|
+
*
|
|
157
|
+
* To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
|
|
158
158
|
*
|
|
159
159
|
* ```typescript
|
|
160
|
+
* // pre-0.34.0
|
|
161
|
+
*
|
|
162
|
+
* const T = Type.String({ $id: 'T' })
|
|
163
|
+
*
|
|
160
164
|
* const R = Type.Ref(T)
|
|
161
165
|
* ```
|
|
162
|
-
* to
|
|
166
|
+
* should be changed to the following
|
|
167
|
+
*
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // post-0.34.0
|
|
170
|
+
*
|
|
171
|
+
* const T = Type.String({ $id: 'T' })
|
|
172
|
+
*
|
|
173
|
+
* const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
|
|
174
|
+
* ```
|
|
175
|
+
* You can also create a generic function to replicate the pre-0.34.0 signature if required
|
|
163
176
|
*
|
|
164
177
|
* ```typescript
|
|
165
|
-
* const
|
|
178
|
+
* const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
|
|
166
179
|
* ```
|
|
167
180
|
*/
|
|
168
181
|
Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
|
|
@@ -66,7 +66,7 @@ function TryConvertBigInt(value) {
|
|
|
66
66
|
return IsStringNumeric(value) ? BigInt(truncateInteger(value)) : IsNumber(value) ? BigInt(Math.trunc(value)) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
|
|
67
67
|
}
|
|
68
68
|
function TryConvertString(value) {
|
|
69
|
-
return
|
|
69
|
+
return IsSymbol(value) && value.description !== undefined ? value.description.toString() : IsValueToString(value) ? value.toString() : value;
|
|
70
70
|
}
|
|
71
71
|
function TryConvertNumber(value) {
|
|
72
72
|
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
// --------------------------------------------------------------------------
|
|
4
4
|
/** Returns true if this value is an async iterator */
|
|
5
5
|
export function IsAsyncIterator(value) {
|
|
6
|
-
return IsObject(value) && Symbol.asyncIterator in value;
|
|
6
|
+
return IsObject(value) && globalThis.Symbol.asyncIterator in value;
|
|
7
7
|
}
|
|
8
8
|
/** Returns true if this value is an iterator */
|
|
9
9
|
export function IsIterator(value) {
|
|
10
|
-
return IsObject(value) && Symbol.iterator in value;
|
|
10
|
+
return IsObject(value) && globalThis.Symbol.iterator in value;
|
|
11
11
|
}
|
|
12
12
|
// --------------------------------------------------------------------------
|
|
13
13
|
// Object Instances
|
|
14
14
|
// --------------------------------------------------------------------------
|
|
15
15
|
/** Returns true if this value is not an instance of a class */
|
|
16
16
|
export function IsStandardObject(value) {
|
|
17
|
-
return IsObject(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
17
|
+
return IsObject(value) && (globalThis.Object.getPrototypeOf(value) === Object.prototype || globalThis.Object.getPrototypeOf(value) === null);
|
|
18
18
|
}
|
|
19
19
|
/** Returns true if this value is an instance of a class */
|
|
20
20
|
export function IsInstanceObject(value) {
|
|
@@ -25,11 +25,11 @@ export function IsInstanceObject(value) {
|
|
|
25
25
|
// --------------------------------------------------------------------------
|
|
26
26
|
/** Returns true if this value is a Promise */
|
|
27
27
|
export function IsPromise(value) {
|
|
28
|
-
return value instanceof Promise;
|
|
28
|
+
return value instanceof globalThis.Promise;
|
|
29
29
|
}
|
|
30
30
|
/** Returns true if this value is a Date */
|
|
31
31
|
export function IsDate(value) {
|
|
32
|
-
return value instanceof Date && Number.isFinite(value.getTime());
|
|
32
|
+
return value instanceof Date && globalThis.Number.isFinite(value.getTime());
|
|
33
33
|
}
|
|
34
34
|
/** Returns true if this value is an instance of Map<K, T> */
|
|
35
35
|
export function IsMap(value) {
|
|
@@ -45,7 +45,7 @@ export function IsRegExp(value) {
|
|
|
45
45
|
}
|
|
46
46
|
/** Returns true if this value is a typed array */
|
|
47
47
|
export function IsTypedArray(value) {
|
|
48
|
-
return ArrayBuffer.isView(value);
|
|
48
|
+
return globalThis.ArrayBuffer.isView(value);
|
|
49
49
|
}
|
|
50
50
|
/** Returns true if the value is a Int8Array */
|
|
51
51
|
export function IsInt8Array(value) {
|
|
@@ -107,7 +107,7 @@ export function IsObject(value) {
|
|
|
107
107
|
}
|
|
108
108
|
/** Returns true if this value is an array, but not a typed array */
|
|
109
109
|
export function IsArray(value) {
|
|
110
|
-
return Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
110
|
+
return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
|
|
111
111
|
}
|
|
112
112
|
/** Returns true if this value is an undefined */
|
|
113
113
|
export function IsUndefined(value) {
|
|
@@ -127,7 +127,7 @@ export function IsNumber(value) {
|
|
|
127
127
|
}
|
|
128
128
|
/** Returns true if this value is an integer */
|
|
129
129
|
export function IsInteger(value) {
|
|
130
|
-
return Number.isInteger(value);
|
|
130
|
+
return globalThis.Number.isInteger(value);
|
|
131
131
|
}
|
|
132
132
|
/** Returns true if this value is bigint */
|
|
133
133
|
export function IsBigInt(value) {
|
package/license
CHANGED
|
@@ -4,7 +4,7 @@ Json Schema Type Builder with Static Type Resolution for TypeScript
|
|
|
4
4
|
|
|
5
5
|
The MIT License (MIT)
|
|
6
6
|
|
|
7
|
-
Copyright (c) 2017-
|
|
7
|
+
Copyright (c) 2017-2025 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
8
8
|
|
|
9
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
10
|
of this software and associated documentation files (the "Software"), to deal
|