@sinclair/typebox 0.25.4 → 0.25.6
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/conditional/conditional.d.ts +1 -1
- package/conditional/conditional.js +1 -1
- package/errors/errors.d.ts +1 -0
- package/errors/errors.js +26 -22
- package/format/format.d.ts +1 -1
- package/format/format.js +1 -1
- package/guard/guard.d.ts +1 -1
- package/guard/guard.js +1 -1
- package/package.json +1 -1
- package/value/pointer.d.ts +1 -1
- package/value/pointer.js +1 -1
- package/value/value.d.ts +2 -2
- package/value/value.js +7 -2
|
@@ -6,7 +6,7 @@ export interface TExclude<T extends Types.TUnion, U extends Types.TUnion> extend
|
|
|
6
6
|
export interface TExtract<T extends Types.TSchema, U extends Types.TUnion> extends Types.TUnion<any[]> {
|
|
7
7
|
static: Extract<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
|
|
8
8
|
}
|
|
9
|
-
/** Conditional
|
|
9
|
+
/** Conditional type mapping for TypeBox types */
|
|
10
10
|
export declare namespace Conditional {
|
|
11
11
|
/** (Experimental) Creates a conditional expression type */
|
|
12
12
|
function Extends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema>(left: L, right: R, ok: T, fail: U): TExtends<L, R, T, U>;
|
|
@@ -31,7 +31,7 @@ exports.Conditional = void 0;
|
|
|
31
31
|
const Types = require("../typebox");
|
|
32
32
|
const structural_1 = require("./structural");
|
|
33
33
|
const index_1 = require("../guard/index");
|
|
34
|
-
/** Conditional
|
|
34
|
+
/** Conditional type mapping for TypeBox types */
|
|
35
35
|
var Conditional;
|
|
36
36
|
(function (Conditional) {
|
|
37
37
|
/** (Experimental) Creates a conditional expression type */
|
package/errors/errors.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare class ValueErrorsUnknownTypeError extends Error {
|
|
|
60
60
|
readonly schema: Types.TSchema;
|
|
61
61
|
constructor(schema: Types.TSchema);
|
|
62
62
|
}
|
|
63
|
+
/** Provides functionality to generate a sequence of errors against a TypeBox type. */
|
|
63
64
|
export declare namespace ValueErrors {
|
|
64
65
|
function Errors<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: any): IterableIterator<ValueError>;
|
|
65
66
|
}
|
package/errors/errors.js
CHANGED
|
@@ -94,17 +94,21 @@ class ValueErrorsUnknownTypeError extends Error {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
97
|
+
/** Provides functionality to generate a sequence of errors against a TypeBox type. */
|
|
97
98
|
var ValueErrors;
|
|
98
99
|
(function (ValueErrors) {
|
|
100
|
+
function IsNumber(value) {
|
|
101
|
+
return typeof value === 'number';
|
|
102
|
+
}
|
|
99
103
|
function* Any(schema, references, path, value) { }
|
|
100
104
|
function* Array(schema, references, path, value) {
|
|
101
105
|
if (!globalThis.Array.isArray(value)) {
|
|
102
106
|
return yield { type: ValueErrorType.Array, schema, path, value, message: `Expected array` };
|
|
103
107
|
}
|
|
104
|
-
if (schema.minItems
|
|
108
|
+
if (IsNumber(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
105
109
|
yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be greater or equal to ${schema.minItems}` };
|
|
106
110
|
}
|
|
107
|
-
if (schema.maxItems
|
|
111
|
+
if (IsNumber(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
108
112
|
yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be less or equal to ${schema.maxItems}` };
|
|
109
113
|
}
|
|
110
114
|
if (schema.uniqueItems === true && !(new Set(value).size === value.length)) {
|
|
@@ -126,16 +130,16 @@ var ValueErrors;
|
|
|
126
130
|
if (!(value instanceof globalThis.Date)) {
|
|
127
131
|
return yield { type: ValueErrorType.Date, schema, path, value, message: `Expected Date object` };
|
|
128
132
|
}
|
|
129
|
-
if (schema.exclusiveMinimumTimestamp && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
133
|
+
if (IsNumber(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
130
134
|
yield { type: ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater than ${schema.exclusiveMinimum}` };
|
|
131
135
|
}
|
|
132
|
-
if (schema.exclusiveMaximumTimestamp && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
136
|
+
if (IsNumber(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
133
137
|
yield { type: ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less than ${schema.exclusiveMaximum}` };
|
|
134
138
|
}
|
|
135
|
-
if (schema.minimumTimestamp && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
139
|
+
if (IsNumber(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
136
140
|
yield { type: ValueErrorType.DateMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater or equal to ${schema.minimum}` };
|
|
137
141
|
}
|
|
138
|
-
if (schema.maximumTimestamp && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
142
|
+
if (IsNumber(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
139
143
|
yield { type: ValueErrorType.DateMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less or equal to ${schema.maximum}` };
|
|
140
144
|
}
|
|
141
145
|
}
|
|
@@ -151,19 +155,19 @@ var ValueErrors;
|
|
|
151
155
|
if (!globalThis.Number.isInteger(value)) {
|
|
152
156
|
yield { type: ValueErrorType.Integer, schema, path, value, message: `Expected integer` };
|
|
153
157
|
}
|
|
154
|
-
if (schema.multipleOf && !(value % schema.multipleOf === 0)) {
|
|
158
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
155
159
|
yield { type: ValueErrorType.IntegerMultipleOf, schema, path, value, message: `Expected integer to be a multiple of ${schema.multipleOf}` };
|
|
156
160
|
}
|
|
157
|
-
if (schema.exclusiveMinimum && !(value > schema.exclusiveMinimum)) {
|
|
161
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
158
162
|
yield { type: ValueErrorType.IntegerExclusiveMinimum, schema, path, value, message: `Expected integer to be greater than ${schema.exclusiveMinimum}` };
|
|
159
163
|
}
|
|
160
|
-
if (schema.exclusiveMaximum && !(value < schema.exclusiveMaximum)) {
|
|
164
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
161
165
|
yield { type: ValueErrorType.IntegerExclusiveMaximum, schema, path, value, message: `Expected integer to be less than ${schema.exclusiveMaximum}` };
|
|
162
166
|
}
|
|
163
|
-
if (schema.minimum && !(value >= schema.minimum)) {
|
|
167
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
164
168
|
yield { type: ValueErrorType.IntegerMinimum, schema, path, value, message: `Expected integer to be greater or equal to ${schema.minimum}` };
|
|
165
169
|
}
|
|
166
|
-
if (schema.maximum && !(value <= schema.maximum)) {
|
|
170
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
167
171
|
yield { type: ValueErrorType.IntegerMaximum, schema, path, value, message: `Expected integer to be less or equal to ${schema.maximum}` };
|
|
168
172
|
}
|
|
169
173
|
}
|
|
@@ -185,19 +189,19 @@ var ValueErrors;
|
|
|
185
189
|
if (!(typeof value === 'number')) {
|
|
186
190
|
return yield { type: ValueErrorType.Number, schema, path, value, message: `Expected number` };
|
|
187
191
|
}
|
|
188
|
-
if (schema.multipleOf && !(value % schema.multipleOf === 0)) {
|
|
192
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
189
193
|
yield { type: ValueErrorType.NumberMultipleOf, schema, path, value, message: `Expected number to be a multiple of ${schema.multipleOf}` };
|
|
190
194
|
}
|
|
191
|
-
if (schema.exclusiveMinimum && !(value > schema.exclusiveMinimum)) {
|
|
195
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
192
196
|
yield { type: ValueErrorType.NumberExclusiveMinimum, schema, path, value, message: `Expected number to be greater than ${schema.exclusiveMinimum}` };
|
|
193
197
|
}
|
|
194
|
-
if (schema.exclusiveMaximum && !(value < schema.exclusiveMaximum)) {
|
|
198
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
195
199
|
yield { type: ValueErrorType.NumberExclusiveMaximum, schema, path, value, message: `Expected number to be less than ${schema.exclusiveMaximum}` };
|
|
196
200
|
}
|
|
197
|
-
if (schema.minimum && !(value >= schema.minimum)) {
|
|
201
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
198
202
|
yield { type: ValueErrorType.NumberMaximum, schema, path, value, message: `Expected number to be greater or equal to ${schema.minimum}` };
|
|
199
203
|
}
|
|
200
|
-
if (schema.maximum && !(value <= schema.maximum)) {
|
|
204
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
201
205
|
yield { type: ValueErrorType.NumberMinumum, schema, path, value, message: `Expected number to be less or equal to ${schema.maximum}` };
|
|
202
206
|
}
|
|
203
207
|
}
|
|
@@ -205,10 +209,10 @@ var ValueErrors;
|
|
|
205
209
|
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
206
210
|
return yield { type: ValueErrorType.Object, schema, path, value, message: `Expected object` };
|
|
207
211
|
}
|
|
208
|
-
if (schema.minProperties
|
|
212
|
+
if (IsNumber(schema.minProperties) && !(globalThis.Object.keys(value).length >= schema.minProperties)) {
|
|
209
213
|
yield { type: ValueErrorType.ObjectMinProperties, schema, path, value, message: `Expected object to have at least ${schema.minProperties} properties` };
|
|
210
214
|
}
|
|
211
|
-
if (schema.maxProperties
|
|
215
|
+
if (IsNumber(schema.maxProperties) && !(globalThis.Object.keys(value).length <= schema.maxProperties)) {
|
|
212
216
|
yield { type: ValueErrorType.ObjectMaxProperties, schema, path, value, message: `Expected object to have less than ${schema.minProperties} properties` };
|
|
213
217
|
}
|
|
214
218
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
@@ -283,10 +287,10 @@ var ValueErrors;
|
|
|
283
287
|
if (!(typeof value === 'string')) {
|
|
284
288
|
return yield { type: ValueErrorType.String, schema, path, value, message: 'Expected string' };
|
|
285
289
|
}
|
|
286
|
-
if (schema.minLength
|
|
290
|
+
if (IsNumber(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
287
291
|
yield { type: ValueErrorType.StringMinLength, schema, path, value, message: `Expected string length greater or equal to ${schema.minLength}` };
|
|
288
292
|
}
|
|
289
|
-
if (schema.maxLength
|
|
293
|
+
if (IsNumber(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
290
294
|
yield { type: ValueErrorType.StringMaxLength, schema, path, value, message: `Expected string length less or equal to ${schema.maxLength}` };
|
|
291
295
|
}
|
|
292
296
|
if (schema.pattern !== undefined) {
|
|
@@ -348,10 +352,10 @@ var ValueErrors;
|
|
|
348
352
|
if (!(value instanceof globalThis.Uint8Array)) {
|
|
349
353
|
return yield { type: ValueErrorType.Uint8Array, schema, path, value, message: `Expected Uint8Array` };
|
|
350
354
|
}
|
|
351
|
-
if (schema.maxByteLength && !(value.length <= schema.maxByteLength)) {
|
|
355
|
+
if (IsNumber(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
352
356
|
yield { type: ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length less or equal to ${schema.maxByteLength}` };
|
|
353
357
|
}
|
|
354
|
-
if (schema.minByteLength && !(value.length >= schema.minByteLength)) {
|
|
358
|
+
if (IsNumber(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
355
359
|
yield { type: ValueErrorType.Uint8ArrayMinByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length greater or equal to ${schema.maxByteLength}` };
|
|
356
360
|
}
|
|
357
361
|
}
|
package/format/format.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type FormatValidationFunction = (value: string) => boolean;
|
|
2
|
-
/**
|
|
2
|
+
/** Provides functions to create custom string formats */
|
|
3
3
|
export declare namespace Format {
|
|
4
4
|
/** Clears all formats */
|
|
5
5
|
function Clear(): void;
|
package/format/format.js
CHANGED
|
@@ -28,7 +28,7 @@ THE SOFTWARE.
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.Format = void 0;
|
|
31
|
-
/**
|
|
31
|
+
/** Provides functions to create custom string formats */
|
|
32
32
|
var Format;
|
|
33
33
|
(function (Format) {
|
|
34
34
|
const formats = new Map();
|
package/guard/guard.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare class TypeGuardInvalidTypeError extends Error {
|
|
|
3
3
|
readonly schema: unknown;
|
|
4
4
|
constructor(schema: unknown);
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/** Provides functionality to test if values are TypeBox types */
|
|
7
7
|
export declare namespace TypeGuard {
|
|
8
8
|
/** Returns true if the given schema is TAny */
|
|
9
9
|
function TAny(schema: unknown): schema is Types.TAny;
|
package/guard/guard.js
CHANGED
|
@@ -36,7 +36,7 @@ class TypeGuardInvalidTypeError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.TypeGuardInvalidTypeError = TypeGuardInvalidTypeError;
|
|
39
|
-
/**
|
|
39
|
+
/** Provides functionality to test if values are TypeBox types */
|
|
40
40
|
var TypeGuard;
|
|
41
41
|
(function (TypeGuard) {
|
|
42
42
|
function IsObject(value) {
|
package/package.json
CHANGED
package/value/pointer.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class ValuePointerRootDeleteError extends Error {
|
|
|
9
9
|
readonly path: string;
|
|
10
10
|
constructor(value: unknown, path: string);
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/** Provides functionality to update values through RFC6901 string pointers */
|
|
13
13
|
export declare namespace ValuePointer {
|
|
14
14
|
/** Formats the given pointer into navigable key components */
|
|
15
15
|
function Format(pointer: string): IterableIterator<string>;
|
package/value/pointer.js
CHANGED
|
@@ -45,7 +45,7 @@ class ValuePointerRootDeleteError extends Error {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.ValuePointerRootDeleteError = ValuePointerRootDeleteError;
|
|
48
|
-
/**
|
|
48
|
+
/** Provides functionality to update values through RFC6901 string pointers */
|
|
49
49
|
var ValuePointer;
|
|
50
50
|
(function (ValuePointer) {
|
|
51
51
|
function Escape(component) {
|
package/value/value.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Types from '../typebox';
|
|
2
2
|
import { ValueError } from '../errors/index';
|
|
3
3
|
import { Edit } from './delta';
|
|
4
|
-
export
|
|
5
|
-
/**
|
|
4
|
+
export { Edit, Insert, Update, Delete } from './delta';
|
|
5
|
+
/** Provides functions to perform structural updates to JavaScript values */
|
|
6
6
|
export declare namespace Value {
|
|
7
7
|
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number and boolean values if a reasonable conversion is possible. */
|
|
8
8
|
function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): Types.Static<T>;
|
package/value/value.js
CHANGED
|
@@ -27,7 +27,7 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Value = void 0;
|
|
30
|
+
exports.Value = exports.Delete = exports.Update = exports.Insert = exports.Edit = void 0;
|
|
31
31
|
const index_1 = require("../errors/index");
|
|
32
32
|
const equal_1 = require("./equal");
|
|
33
33
|
const cast_1 = require("./cast");
|
|
@@ -35,7 +35,12 @@ const clone_1 = require("./clone");
|
|
|
35
35
|
const create_1 = require("./create");
|
|
36
36
|
const check_1 = require("./check");
|
|
37
37
|
const delta_1 = require("./delta");
|
|
38
|
-
|
|
38
|
+
var delta_2 = require("./delta");
|
|
39
|
+
Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return delta_2.Edit; } });
|
|
40
|
+
Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return delta_2.Insert; } });
|
|
41
|
+
Object.defineProperty(exports, "Update", { enumerable: true, get: function () { return delta_2.Update; } });
|
|
42
|
+
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return delta_2.Delete; } });
|
|
43
|
+
/** Provides functions to perform structural updates to JavaScript values */
|
|
39
44
|
var Value;
|
|
40
45
|
(function (Value) {
|
|
41
46
|
function Cast(...args) {
|