@dzeio/schema 0.7.0 → 0.9.0
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/dist/Schema.d.mts +25 -2
- package/dist/Schema.d.ts +25 -2
- package/dist/Schema.js +28 -5
- package/dist/Schema.mjs +28 -5
- package/package.json +1 -1
package/dist/Schema.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
3
3
|
declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
|
|
4
4
|
readonly _output: Output;
|
|
5
5
|
readonly _input: Input;
|
|
6
|
+
static id: string;
|
|
6
7
|
'~standard': StandardSchemaV1.Props<Input, Output>;
|
|
7
8
|
/**
|
|
8
9
|
* Function calls saved for serialization
|
|
@@ -163,11 +164,13 @@ type ModelInfer$1<M extends Model> = {
|
|
|
163
164
|
type Literal = string | number | bigint | boolean | null | undefined
|
|
164
165
|
|
|
165
166
|
declare class SchemaAny extends SchemaItem {
|
|
167
|
+
static id: string;
|
|
166
168
|
isOfType(_input: unknown): _input is any;
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
|
|
170
172
|
declare class SchemaDate extends SchemaItem<Date> {
|
|
173
|
+
static id: string;
|
|
171
174
|
parseString(format?: DateFormat): this;
|
|
172
175
|
isOfType(input: unknown): input is Date;
|
|
173
176
|
}
|
|
@@ -175,6 +178,7 @@ declare class SchemaDate extends SchemaItem<Date> {
|
|
|
175
178
|
declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
|
|
176
179
|
private readonly keys;
|
|
177
180
|
private readonly values;
|
|
181
|
+
static id: string;
|
|
178
182
|
constructor(keys: Keys, values: Values);
|
|
179
183
|
isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
|
|
180
184
|
protected parseSubItems(input: unknown, options?: ValidationOptions): {
|
|
@@ -185,6 +189,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
|
|
|
185
189
|
|
|
186
190
|
declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
|
|
187
191
|
readonly values: Child;
|
|
192
|
+
static id: string;
|
|
188
193
|
constructor(values: Child);
|
|
189
194
|
/**
|
|
190
195
|
* transform the array so it only contains one of each elements
|
|
@@ -206,6 +211,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
|
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
declare class SchemaBoolean extends SchemaItem<boolean> {
|
|
214
|
+
static id: string;
|
|
209
215
|
/**
|
|
210
216
|
* @param [trueValue='true'] the truhty value (default to `'true'`)
|
|
211
217
|
* @param [falseValue='false'] the falthy value (default to `'false'`)
|
|
@@ -220,12 +226,14 @@ interface EnumLike {
|
|
|
220
226
|
}
|
|
221
227
|
declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
|
|
222
228
|
private readonly templateEnum;
|
|
229
|
+
static id: string;
|
|
223
230
|
private readonly type;
|
|
224
231
|
constructor(templateEnum: E);
|
|
225
232
|
isOfType(input: unknown): input is E[keyof E];
|
|
226
233
|
}
|
|
227
234
|
|
|
228
235
|
declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
|
|
236
|
+
static id: string;
|
|
229
237
|
private readonly values;
|
|
230
238
|
constructor(...values: Types);
|
|
231
239
|
isOfType(input: unknown): input is Types[number];
|
|
@@ -233,6 +241,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
|
|
|
233
241
|
|
|
234
242
|
declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
|
|
235
243
|
private readonly child;
|
|
244
|
+
static id: string;
|
|
236
245
|
constructor(child: Child);
|
|
237
246
|
falsyAsNull(): this;
|
|
238
247
|
emptyAsNull(): this;
|
|
@@ -251,6 +260,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
|
|
|
251
260
|
}
|
|
252
261
|
|
|
253
262
|
declare class SchemaNumber extends SchemaItem<number> {
|
|
263
|
+
static id: string;
|
|
254
264
|
/**
|
|
255
265
|
* validate that the number is less or equal than {@link value}
|
|
256
266
|
* @param value the maxumum value (inclusive)
|
|
@@ -289,7 +299,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
|
|
|
289
299
|
};
|
|
290
300
|
declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
|
|
291
301
|
readonly model: T;
|
|
292
|
-
id: string;
|
|
302
|
+
static id: string;
|
|
293
303
|
constructor(model: T);
|
|
294
304
|
isOfType(input: unknown): input is ModelInfer<T>;
|
|
295
305
|
protected getSubInputs(input: unknown): Array<{
|
|
@@ -300,6 +310,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
|
|
|
300
310
|
}
|
|
301
311
|
|
|
302
312
|
declare class SchemaString extends SchemaItem<string> {
|
|
313
|
+
static id: string;
|
|
303
314
|
/**
|
|
304
315
|
* force the input text to be a minimum of `value` size
|
|
305
316
|
* @param value the minimum length of the text
|
|
@@ -340,6 +351,7 @@ declare class SchemaString extends SchemaItem<string> {
|
|
|
340
351
|
}
|
|
341
352
|
|
|
342
353
|
declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
|
|
354
|
+
static id: string;
|
|
343
355
|
private readonly schemas;
|
|
344
356
|
constructor(...schemas: Children);
|
|
345
357
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -354,6 +366,7 @@ type Prettify<T> = T extends unknown ? {
|
|
|
354
366
|
} : never;
|
|
355
367
|
type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
356
368
|
declare class SchemaIntersection<Children extends Array<SchemaItem>, Outputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>, Inputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>> extends SchemaItem<Outputs, Inputs> {
|
|
369
|
+
static id: string;
|
|
357
370
|
private readonly schemas;
|
|
358
371
|
constructor(...schemas: Children);
|
|
359
372
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -367,6 +380,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
|
|
|
367
380
|
private readonly child;
|
|
368
381
|
private readonly defaultVal;
|
|
369
382
|
private readonly strict;
|
|
383
|
+
static id: string;
|
|
370
384
|
constructor(child: Child, defaultVal: Output, strict?: boolean);
|
|
371
385
|
unwrap(): Child;
|
|
372
386
|
isOfType(input: unknown): input is Output;
|
|
@@ -378,6 +392,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
|
|
|
378
392
|
}
|
|
379
393
|
|
|
380
394
|
declare class SchemaFile extends SchemaItem<File> {
|
|
395
|
+
static id: string;
|
|
381
396
|
constructor();
|
|
382
397
|
extension(ext: string, error?: string): this;
|
|
383
398
|
maxSize(size: number, error?: string): this;
|
|
@@ -387,6 +402,7 @@ declare class SchemaFile extends SchemaItem<File> {
|
|
|
387
402
|
type TupleToOutputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToOutputs<Tuple, [...Result, SchemaInfer<Tuple[Result['length']]>]>;
|
|
388
403
|
type TupleToInputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInputInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToInputs<Tuple, [...Result, SchemaInputInfer<Tuple[Result['length']]>]>;
|
|
389
404
|
declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
|
|
405
|
+
static id: string;
|
|
390
406
|
private readonly children;
|
|
391
407
|
constructor(...children: Children);
|
|
392
408
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -398,18 +414,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
|
|
|
398
414
|
}
|
|
399
415
|
|
|
400
416
|
declare class SchemaUndefined extends SchemaItem<undefined> {
|
|
417
|
+
static id: string;
|
|
401
418
|
isOfType(input: unknown): input is undefined;
|
|
402
419
|
}
|
|
403
420
|
declare class SchemaNull extends SchemaItem<null> {
|
|
421
|
+
static id: string;
|
|
404
422
|
isOfType(input: unknown): input is null;
|
|
405
423
|
}
|
|
406
424
|
declare class SchemaVoid extends SchemaItem<void> {
|
|
425
|
+
static id: string;
|
|
407
426
|
isOfType(input: unknown): input is void;
|
|
408
427
|
}
|
|
409
428
|
declare class SchemaNullish extends SchemaItem<null | undefined> {
|
|
429
|
+
static id: string;
|
|
410
430
|
isOfType(input: unknown): input is null | undefined;
|
|
411
431
|
}
|
|
412
432
|
declare class SchemaNever extends SchemaItem<never> {
|
|
433
|
+
static id: string;
|
|
413
434
|
isOfType(_input: unknown): _input is never;
|
|
414
435
|
}
|
|
415
436
|
|
|
@@ -425,7 +446,9 @@ declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement
|
|
|
425
446
|
* Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
|
|
426
447
|
*/
|
|
427
448
|
declare function parsable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
|
|
428
|
-
type SchemaItemStatic = new (...args: Array<any>) => SchemaItem
|
|
449
|
+
type SchemaItemStatic = (new (...args: Array<any>) => SchemaItem) & {
|
|
450
|
+
id: string;
|
|
451
|
+
};
|
|
429
452
|
declare class Schema<T extends Record<string, SchemaItem> = Record<string, SchemaItem>> extends SchemaObject<T> {
|
|
430
453
|
private static readonly registeredModules;
|
|
431
454
|
static register(module: SchemaItemStatic): void;
|
package/dist/Schema.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
3
3
|
declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
|
|
4
4
|
readonly _output: Output;
|
|
5
5
|
readonly _input: Input;
|
|
6
|
+
static id: string;
|
|
6
7
|
'~standard': StandardSchemaV1.Props<Input, Output>;
|
|
7
8
|
/**
|
|
8
9
|
* Function calls saved for serialization
|
|
@@ -163,11 +164,13 @@ type ModelInfer$1<M extends Model> = {
|
|
|
163
164
|
type Literal = string | number | bigint | boolean | null | undefined
|
|
164
165
|
|
|
165
166
|
declare class SchemaAny extends SchemaItem {
|
|
167
|
+
static id: string;
|
|
166
168
|
isOfType(_input: unknown): _input is any;
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
|
|
170
172
|
declare class SchemaDate extends SchemaItem<Date> {
|
|
173
|
+
static id: string;
|
|
171
174
|
parseString(format?: DateFormat): this;
|
|
172
175
|
isOfType(input: unknown): input is Date;
|
|
173
176
|
}
|
|
@@ -175,6 +178,7 @@ declare class SchemaDate extends SchemaItem<Date> {
|
|
|
175
178
|
declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
|
|
176
179
|
private readonly keys;
|
|
177
180
|
private readonly values;
|
|
181
|
+
static id: string;
|
|
178
182
|
constructor(keys: Keys, values: Values);
|
|
179
183
|
isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
|
|
180
184
|
protected parseSubItems(input: unknown, options?: ValidationOptions): {
|
|
@@ -185,6 +189,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
|
|
|
185
189
|
|
|
186
190
|
declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
|
|
187
191
|
readonly values: Child;
|
|
192
|
+
static id: string;
|
|
188
193
|
constructor(values: Child);
|
|
189
194
|
/**
|
|
190
195
|
* transform the array so it only contains one of each elements
|
|
@@ -206,6 +211,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
|
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
declare class SchemaBoolean extends SchemaItem<boolean> {
|
|
214
|
+
static id: string;
|
|
209
215
|
/**
|
|
210
216
|
* @param [trueValue='true'] the truhty value (default to `'true'`)
|
|
211
217
|
* @param [falseValue='false'] the falthy value (default to `'false'`)
|
|
@@ -220,12 +226,14 @@ interface EnumLike {
|
|
|
220
226
|
}
|
|
221
227
|
declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
|
|
222
228
|
private readonly templateEnum;
|
|
229
|
+
static id: string;
|
|
223
230
|
private readonly type;
|
|
224
231
|
constructor(templateEnum: E);
|
|
225
232
|
isOfType(input: unknown): input is E[keyof E];
|
|
226
233
|
}
|
|
227
234
|
|
|
228
235
|
declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
|
|
236
|
+
static id: string;
|
|
229
237
|
private readonly values;
|
|
230
238
|
constructor(...values: Types);
|
|
231
239
|
isOfType(input: unknown): input is Types[number];
|
|
@@ -233,6 +241,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
|
|
|
233
241
|
|
|
234
242
|
declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
|
|
235
243
|
private readonly child;
|
|
244
|
+
static id: string;
|
|
236
245
|
constructor(child: Child);
|
|
237
246
|
falsyAsNull(): this;
|
|
238
247
|
emptyAsNull(): this;
|
|
@@ -251,6 +260,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
|
|
|
251
260
|
}
|
|
252
261
|
|
|
253
262
|
declare class SchemaNumber extends SchemaItem<number> {
|
|
263
|
+
static id: string;
|
|
254
264
|
/**
|
|
255
265
|
* validate that the number is less or equal than {@link value}
|
|
256
266
|
* @param value the maxumum value (inclusive)
|
|
@@ -289,7 +299,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
|
|
|
289
299
|
};
|
|
290
300
|
declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
|
|
291
301
|
readonly model: T;
|
|
292
|
-
id: string;
|
|
302
|
+
static id: string;
|
|
293
303
|
constructor(model: T);
|
|
294
304
|
isOfType(input: unknown): input is ModelInfer<T>;
|
|
295
305
|
protected getSubInputs(input: unknown): Array<{
|
|
@@ -300,6 +310,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
|
|
|
300
310
|
}
|
|
301
311
|
|
|
302
312
|
declare class SchemaString extends SchemaItem<string> {
|
|
313
|
+
static id: string;
|
|
303
314
|
/**
|
|
304
315
|
* force the input text to be a minimum of `value` size
|
|
305
316
|
* @param value the minimum length of the text
|
|
@@ -340,6 +351,7 @@ declare class SchemaString extends SchemaItem<string> {
|
|
|
340
351
|
}
|
|
341
352
|
|
|
342
353
|
declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
|
|
354
|
+
static id: string;
|
|
343
355
|
private readonly schemas;
|
|
344
356
|
constructor(...schemas: Children);
|
|
345
357
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -354,6 +366,7 @@ type Prettify<T> = T extends unknown ? {
|
|
|
354
366
|
} : never;
|
|
355
367
|
type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
356
368
|
declare class SchemaIntersection<Children extends Array<SchemaItem>, Outputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>, Inputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>> extends SchemaItem<Outputs, Inputs> {
|
|
369
|
+
static id: string;
|
|
357
370
|
private readonly schemas;
|
|
358
371
|
constructor(...schemas: Children);
|
|
359
372
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -367,6 +380,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
|
|
|
367
380
|
private readonly child;
|
|
368
381
|
private readonly defaultVal;
|
|
369
382
|
private readonly strict;
|
|
383
|
+
static id: string;
|
|
370
384
|
constructor(child: Child, defaultVal: Output, strict?: boolean);
|
|
371
385
|
unwrap(): Child;
|
|
372
386
|
isOfType(input: unknown): input is Output;
|
|
@@ -378,6 +392,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
|
|
|
378
392
|
}
|
|
379
393
|
|
|
380
394
|
declare class SchemaFile extends SchemaItem<File> {
|
|
395
|
+
static id: string;
|
|
381
396
|
constructor();
|
|
382
397
|
extension(ext: string, error?: string): this;
|
|
383
398
|
maxSize(size: number, error?: string): this;
|
|
@@ -387,6 +402,7 @@ declare class SchemaFile extends SchemaItem<File> {
|
|
|
387
402
|
type TupleToOutputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToOutputs<Tuple, [...Result, SchemaInfer<Tuple[Result['length']]>]>;
|
|
388
403
|
type TupleToInputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInputInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToInputs<Tuple, [...Result, SchemaInputInfer<Tuple[Result['length']]>]>;
|
|
389
404
|
declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
|
|
405
|
+
static id: string;
|
|
390
406
|
private readonly children;
|
|
391
407
|
constructor(...children: Children);
|
|
392
408
|
isOfType(input: unknown): input is Outputs;
|
|
@@ -398,18 +414,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
|
|
|
398
414
|
}
|
|
399
415
|
|
|
400
416
|
declare class SchemaUndefined extends SchemaItem<undefined> {
|
|
417
|
+
static id: string;
|
|
401
418
|
isOfType(input: unknown): input is undefined;
|
|
402
419
|
}
|
|
403
420
|
declare class SchemaNull extends SchemaItem<null> {
|
|
421
|
+
static id: string;
|
|
404
422
|
isOfType(input: unknown): input is null;
|
|
405
423
|
}
|
|
406
424
|
declare class SchemaVoid extends SchemaItem<void> {
|
|
425
|
+
static id: string;
|
|
407
426
|
isOfType(input: unknown): input is void;
|
|
408
427
|
}
|
|
409
428
|
declare class SchemaNullish extends SchemaItem<null | undefined> {
|
|
429
|
+
static id: string;
|
|
410
430
|
isOfType(input: unknown): input is null | undefined;
|
|
411
431
|
}
|
|
412
432
|
declare class SchemaNever extends SchemaItem<never> {
|
|
433
|
+
static id: string;
|
|
413
434
|
isOfType(_input: unknown): _input is never;
|
|
414
435
|
}
|
|
415
436
|
|
|
@@ -425,7 +446,9 @@ declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement
|
|
|
425
446
|
* Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
|
|
426
447
|
*/
|
|
427
448
|
declare function parsable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
|
|
428
|
-
type SchemaItemStatic = new (...args: Array<any>) => SchemaItem
|
|
449
|
+
type SchemaItemStatic = (new (...args: Array<any>) => SchemaItem) & {
|
|
450
|
+
id: string;
|
|
451
|
+
};
|
|
429
452
|
declare class Schema<T extends Record<string, SchemaItem> = Record<string, SchemaItem>> extends SchemaObject<T> {
|
|
430
453
|
private static readonly registeredModules;
|
|
431
454
|
static register(module: SchemaItemStatic): void;
|
package/dist/Schema.js
CHANGED
|
@@ -211,7 +211,7 @@ var _SchemaItem = class _SchemaItem {
|
|
|
211
211
|
toJSON() {
|
|
212
212
|
var _a;
|
|
213
213
|
const res = {
|
|
214
|
-
_i: this.constructor.
|
|
214
|
+
_i: this.constructor.id,
|
|
215
215
|
a: this.attributes.length > 0 ? this.attributes : void 0,
|
|
216
216
|
c: (_a = this.items) == null ? void 0 : _a.map((it) => this.deepSerializeItem(it)),
|
|
217
217
|
f: this.savedCalls.map((it) => it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })
|
|
@@ -280,6 +280,9 @@ __decorateClass([
|
|
|
280
280
|
__decorateClass([
|
|
281
281
|
parsable()
|
|
282
282
|
], _SchemaItem.prototype, "in", 1);
|
|
283
|
+
__decorateClass([
|
|
284
|
+
parsable()
|
|
285
|
+
], _SchemaItem.prototype, "setInvalidError", 1);
|
|
283
286
|
var SchemaItem = _SchemaItem;
|
|
284
287
|
|
|
285
288
|
// src/items/array.ts
|
|
@@ -310,6 +313,7 @@ var SchemaArray = class extends SchemaItem {
|
|
|
310
313
|
return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
|
|
311
314
|
}
|
|
312
315
|
};
|
|
316
|
+
SchemaArray.id = "array";
|
|
313
317
|
__decorateClass([
|
|
314
318
|
parsable()
|
|
315
319
|
], SchemaArray.prototype, "unique", 1);
|
|
@@ -341,6 +345,7 @@ var SchemaBoolean = class extends SchemaItem {
|
|
|
341
345
|
return typeof input === "boolean";
|
|
342
346
|
}
|
|
343
347
|
};
|
|
348
|
+
SchemaBoolean.id = "boolean";
|
|
344
349
|
__decorateClass([
|
|
345
350
|
parsable()
|
|
346
351
|
], SchemaBoolean.prototype, "parseString", 1);
|
|
@@ -379,6 +384,7 @@ var SchemaNullable = class extends SchemaItem {
|
|
|
379
384
|
return super.parseSubItems(input, options);
|
|
380
385
|
}
|
|
381
386
|
};
|
|
387
|
+
SchemaNullable.id = "nullable";
|
|
382
388
|
__decorateClass([
|
|
383
389
|
parsable()
|
|
384
390
|
], SchemaNullable.prototype, "falsyAsNull", 1);
|
|
@@ -395,7 +401,6 @@ var SchemaObject = class extends SchemaItem {
|
|
|
395
401
|
constructor(model) {
|
|
396
402
|
super([model]);
|
|
397
403
|
this.model = model;
|
|
398
|
-
this.id = "object";
|
|
399
404
|
}
|
|
400
405
|
isOfType(input) {
|
|
401
406
|
return (0, import_object_util2.isObject)(input) && !(0, import_object_util2.objectFind)(this.model, (item, key) => !item.isOfType(input[key]));
|
|
@@ -404,6 +409,7 @@ var SchemaObject = class extends SchemaItem {
|
|
|
404
409
|
return (0, import_object_util2.isObject)(input) ? (0, import_object_util2.objectMap)(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
|
|
405
410
|
}
|
|
406
411
|
};
|
|
412
|
+
SchemaObject.id = "object";
|
|
407
413
|
|
|
408
414
|
// src/helpers.ts
|
|
409
415
|
function isNull(value) {
|
|
@@ -443,8 +449,8 @@ function parseFormData(schema, data, opts) {
|
|
|
443
449
|
if (value instanceof SchemaObject) {
|
|
444
450
|
handleSchemaForBoolean(value.model, keys);
|
|
445
451
|
}
|
|
446
|
-
if (value instanceof SchemaBoolean) {
|
|
447
|
-
(0, import_object_util3.objectSet)(record, keys,
|
|
452
|
+
if (value instanceof SchemaBoolean && typeof (0, import_object_util3.objectGet)(record, keys) === "undefined") {
|
|
453
|
+
(0, import_object_util3.objectSet)(record, keys, false);
|
|
448
454
|
}
|
|
449
455
|
};
|
|
450
456
|
const handleSchemaForBoolean = (model, keys = []) => {
|
|
@@ -488,6 +494,7 @@ var SchemaAny = class extends SchemaItem {
|
|
|
488
494
|
return true;
|
|
489
495
|
}
|
|
490
496
|
};
|
|
497
|
+
SchemaAny.id = "any";
|
|
491
498
|
|
|
492
499
|
// src/items/date.ts
|
|
493
500
|
var SchemaDate = class extends SchemaItem {
|
|
@@ -531,6 +538,7 @@ var SchemaDate = class extends SchemaItem {
|
|
|
531
538
|
return input instanceof Date;
|
|
532
539
|
}
|
|
533
540
|
};
|
|
541
|
+
SchemaDate.id = "date";
|
|
534
542
|
__decorateClass([
|
|
535
543
|
parsable()
|
|
536
544
|
], SchemaDate.prototype, "parseString", 1);
|
|
@@ -569,6 +577,7 @@ var SchemaRecord = class extends SchemaItem {
|
|
|
569
577
|
return result;
|
|
570
578
|
}
|
|
571
579
|
};
|
|
580
|
+
SchemaRecord.id = "record";
|
|
572
581
|
|
|
573
582
|
// src/items/enum.ts
|
|
574
583
|
var SchemaEnum = class extends SchemaItem {
|
|
@@ -589,6 +598,7 @@ var SchemaEnum = class extends SchemaItem {
|
|
|
589
598
|
return typeof input === this.type;
|
|
590
599
|
}
|
|
591
600
|
};
|
|
601
|
+
SchemaEnum.id = "enum";
|
|
592
602
|
|
|
593
603
|
// src/items/literal.ts
|
|
594
604
|
var SchemaLiteral = class extends SchemaItem {
|
|
@@ -601,6 +611,7 @@ var SchemaLiteral = class extends SchemaItem {
|
|
|
601
611
|
return this.values.some((it) => typeof input === typeof it);
|
|
602
612
|
}
|
|
603
613
|
};
|
|
614
|
+
SchemaLiteral.id = "literal";
|
|
604
615
|
|
|
605
616
|
// src/items/number.ts
|
|
606
617
|
var SchemaNumber = class extends SchemaItem {
|
|
@@ -654,6 +665,7 @@ var SchemaNumber = class extends SchemaItem {
|
|
|
654
665
|
return this.lte(...params);
|
|
655
666
|
}
|
|
656
667
|
};
|
|
668
|
+
SchemaNumber.id = "number";
|
|
657
669
|
__decorateClass([
|
|
658
670
|
parsable()
|
|
659
671
|
], SchemaNumber.prototype, "lte", 1);
|
|
@@ -732,6 +744,7 @@ var SchemaString = class extends SchemaItem {
|
|
|
732
744
|
return typeof input === "string";
|
|
733
745
|
}
|
|
734
746
|
};
|
|
747
|
+
SchemaString.id = "string";
|
|
735
748
|
__decorateClass([
|
|
736
749
|
parsable()
|
|
737
750
|
], SchemaString.prototype, "min", 1);
|
|
@@ -773,6 +786,7 @@ var SchemaUnion = class extends SchemaItem {
|
|
|
773
786
|
return result;
|
|
774
787
|
}
|
|
775
788
|
};
|
|
789
|
+
SchemaUnion.id = "union";
|
|
776
790
|
|
|
777
791
|
// src/items/intersection.ts
|
|
778
792
|
var import_object_util5 = require("@dzeio/object-util");
|
|
@@ -801,6 +815,7 @@ var SchemaIntersection = class extends SchemaItem {
|
|
|
801
815
|
return result;
|
|
802
816
|
}
|
|
803
817
|
};
|
|
818
|
+
SchemaIntersection.id = "intersection";
|
|
804
819
|
|
|
805
820
|
// src/items/default.ts
|
|
806
821
|
var SchemaDefault = class extends SchemaItem {
|
|
@@ -820,6 +835,7 @@ var SchemaDefault = class extends SchemaItem {
|
|
|
820
835
|
return [{ item: this.child, value: isNull(input) || !this.strict && !input ? this.defaultVal : input, path: void 0 }];
|
|
821
836
|
}
|
|
822
837
|
};
|
|
838
|
+
SchemaDefault.id = "default";
|
|
823
839
|
|
|
824
840
|
// src/items/file.ts
|
|
825
841
|
var SchemaFile = class extends SchemaItem {
|
|
@@ -839,6 +855,7 @@ var SchemaFile = class extends SchemaItem {
|
|
|
839
855
|
return input instanceof File;
|
|
840
856
|
}
|
|
841
857
|
};
|
|
858
|
+
SchemaFile.id = "file";
|
|
842
859
|
__decorateClass([
|
|
843
860
|
parsable()
|
|
844
861
|
], SchemaFile.prototype, "extension", 1);
|
|
@@ -867,6 +884,7 @@ var SchemaTuple = class extends SchemaItem {
|
|
|
867
884
|
return Array.isArray(input) ? this.children.map((entry, index) => ({ value: input[index], item: entry, path: index.toString() })) : [];
|
|
868
885
|
}
|
|
869
886
|
};
|
|
887
|
+
SchemaTuple.id = "tuple";
|
|
870
888
|
|
|
871
889
|
// src/items/nullish.ts
|
|
872
890
|
var SchemaUndefined = class extends SchemaItem {
|
|
@@ -874,26 +892,31 @@ var SchemaUndefined = class extends SchemaItem {
|
|
|
874
892
|
return typeof input === "undefined";
|
|
875
893
|
}
|
|
876
894
|
};
|
|
895
|
+
SchemaUndefined.id = "undefined";
|
|
877
896
|
var SchemaNull = class extends SchemaItem {
|
|
878
897
|
isOfType(input) {
|
|
879
898
|
return input === null;
|
|
880
899
|
}
|
|
881
900
|
};
|
|
901
|
+
SchemaNull.id = "null";
|
|
882
902
|
var SchemaVoid = class extends SchemaItem {
|
|
883
903
|
isOfType(input) {
|
|
884
904
|
return typeof input === "undefined";
|
|
885
905
|
}
|
|
886
906
|
};
|
|
907
|
+
SchemaVoid.id = "void";
|
|
887
908
|
var SchemaNullish = class extends SchemaItem {
|
|
888
909
|
isOfType(input) {
|
|
889
910
|
return isNull(input);
|
|
890
911
|
}
|
|
891
912
|
};
|
|
913
|
+
SchemaNullish.id = "nullish";
|
|
892
914
|
var SchemaNever = class extends SchemaItem {
|
|
893
915
|
isOfType(_input) {
|
|
894
916
|
return false;
|
|
895
917
|
}
|
|
896
918
|
};
|
|
919
|
+
SchemaNever.id = "never";
|
|
897
920
|
|
|
898
921
|
// src/Schema.ts
|
|
899
922
|
var import_object_util6 = require("@dzeio/object-util");
|
|
@@ -916,7 +939,7 @@ var _Schema = class _Schema extends SchemaObject {
|
|
|
916
939
|
this.registeredModules.push(module2);
|
|
917
940
|
}
|
|
918
941
|
static getModule(name) {
|
|
919
|
-
const module2 = this.registeredModules.find((it) => it.
|
|
942
|
+
const module2 = this.registeredModules.find((it) => it.id === name);
|
|
920
943
|
if (!module2) {
|
|
921
944
|
console.log("Couldn't find module", name);
|
|
922
945
|
}
|
package/dist/Schema.mjs
CHANGED
|
@@ -161,7 +161,7 @@ var _SchemaItem = class _SchemaItem {
|
|
|
161
161
|
toJSON() {
|
|
162
162
|
var _a;
|
|
163
163
|
const res = {
|
|
164
|
-
_i: this.constructor.
|
|
164
|
+
_i: this.constructor.id,
|
|
165
165
|
a: this.attributes.length > 0 ? this.attributes : void 0,
|
|
166
166
|
c: (_a = this.items) == null ? void 0 : _a.map((it) => this.deepSerializeItem(it)),
|
|
167
167
|
f: this.savedCalls.map((it) => it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })
|
|
@@ -230,6 +230,9 @@ __decorateClass([
|
|
|
230
230
|
__decorateClass([
|
|
231
231
|
parsable()
|
|
232
232
|
], _SchemaItem.prototype, "in", 1);
|
|
233
|
+
__decorateClass([
|
|
234
|
+
parsable()
|
|
235
|
+
], _SchemaItem.prototype, "setInvalidError", 1);
|
|
233
236
|
var SchemaItem = _SchemaItem;
|
|
234
237
|
|
|
235
238
|
// src/items/array.ts
|
|
@@ -260,6 +263,7 @@ var SchemaArray = class extends SchemaItem {
|
|
|
260
263
|
return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
|
|
261
264
|
}
|
|
262
265
|
};
|
|
266
|
+
SchemaArray.id = "array";
|
|
263
267
|
__decorateClass([
|
|
264
268
|
parsable()
|
|
265
269
|
], SchemaArray.prototype, "unique", 1);
|
|
@@ -291,6 +295,7 @@ var SchemaBoolean = class extends SchemaItem {
|
|
|
291
295
|
return typeof input === "boolean";
|
|
292
296
|
}
|
|
293
297
|
};
|
|
298
|
+
SchemaBoolean.id = "boolean";
|
|
294
299
|
__decorateClass([
|
|
295
300
|
parsable()
|
|
296
301
|
], SchemaBoolean.prototype, "parseString", 1);
|
|
@@ -329,6 +334,7 @@ var SchemaNullable = class extends SchemaItem {
|
|
|
329
334
|
return super.parseSubItems(input, options);
|
|
330
335
|
}
|
|
331
336
|
};
|
|
337
|
+
SchemaNullable.id = "nullable";
|
|
332
338
|
__decorateClass([
|
|
333
339
|
parsable()
|
|
334
340
|
], SchemaNullable.prototype, "falsyAsNull", 1);
|
|
@@ -345,7 +351,6 @@ var SchemaObject = class extends SchemaItem {
|
|
|
345
351
|
constructor(model) {
|
|
346
352
|
super([model]);
|
|
347
353
|
this.model = model;
|
|
348
|
-
this.id = "object";
|
|
349
354
|
}
|
|
350
355
|
isOfType(input) {
|
|
351
356
|
return isObject2(input) && !objectFind(this.model, (item, key) => !item.isOfType(input[key]));
|
|
@@ -354,6 +359,7 @@ var SchemaObject = class extends SchemaItem {
|
|
|
354
359
|
return isObject2(input) ? objectMap(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
|
|
355
360
|
}
|
|
356
361
|
};
|
|
362
|
+
SchemaObject.id = "object";
|
|
357
363
|
|
|
358
364
|
// src/helpers.ts
|
|
359
365
|
function isNull(value) {
|
|
@@ -393,8 +399,8 @@ function parseFormData(schema, data, opts) {
|
|
|
393
399
|
if (value instanceof SchemaObject) {
|
|
394
400
|
handleSchemaForBoolean(value.model, keys);
|
|
395
401
|
}
|
|
396
|
-
if (value instanceof SchemaBoolean) {
|
|
397
|
-
objectSet2(record, keys,
|
|
402
|
+
if (value instanceof SchemaBoolean && typeof objectGet(record, keys) === "undefined") {
|
|
403
|
+
objectSet2(record, keys, false);
|
|
398
404
|
}
|
|
399
405
|
};
|
|
400
406
|
const handleSchemaForBoolean = (model, keys = []) => {
|
|
@@ -438,6 +444,7 @@ var SchemaAny = class extends SchemaItem {
|
|
|
438
444
|
return true;
|
|
439
445
|
}
|
|
440
446
|
};
|
|
447
|
+
SchemaAny.id = "any";
|
|
441
448
|
|
|
442
449
|
// src/items/date.ts
|
|
443
450
|
var SchemaDate = class extends SchemaItem {
|
|
@@ -481,6 +488,7 @@ var SchemaDate = class extends SchemaItem {
|
|
|
481
488
|
return input instanceof Date;
|
|
482
489
|
}
|
|
483
490
|
};
|
|
491
|
+
SchemaDate.id = "date";
|
|
484
492
|
__decorateClass([
|
|
485
493
|
parsable()
|
|
486
494
|
], SchemaDate.prototype, "parseString", 1);
|
|
@@ -519,6 +527,7 @@ var SchemaRecord = class extends SchemaItem {
|
|
|
519
527
|
return result;
|
|
520
528
|
}
|
|
521
529
|
};
|
|
530
|
+
SchemaRecord.id = "record";
|
|
522
531
|
|
|
523
532
|
// src/items/enum.ts
|
|
524
533
|
var SchemaEnum = class extends SchemaItem {
|
|
@@ -539,6 +548,7 @@ var SchemaEnum = class extends SchemaItem {
|
|
|
539
548
|
return typeof input === this.type;
|
|
540
549
|
}
|
|
541
550
|
};
|
|
551
|
+
SchemaEnum.id = "enum";
|
|
542
552
|
|
|
543
553
|
// src/items/literal.ts
|
|
544
554
|
var SchemaLiteral = class extends SchemaItem {
|
|
@@ -551,6 +561,7 @@ var SchemaLiteral = class extends SchemaItem {
|
|
|
551
561
|
return this.values.some((it) => typeof input === typeof it);
|
|
552
562
|
}
|
|
553
563
|
};
|
|
564
|
+
SchemaLiteral.id = "literal";
|
|
554
565
|
|
|
555
566
|
// src/items/number.ts
|
|
556
567
|
var SchemaNumber = class extends SchemaItem {
|
|
@@ -604,6 +615,7 @@ var SchemaNumber = class extends SchemaItem {
|
|
|
604
615
|
return this.lte(...params);
|
|
605
616
|
}
|
|
606
617
|
};
|
|
618
|
+
SchemaNumber.id = "number";
|
|
607
619
|
__decorateClass([
|
|
608
620
|
parsable()
|
|
609
621
|
], SchemaNumber.prototype, "lte", 1);
|
|
@@ -682,6 +694,7 @@ var SchemaString = class extends SchemaItem {
|
|
|
682
694
|
return typeof input === "string";
|
|
683
695
|
}
|
|
684
696
|
};
|
|
697
|
+
SchemaString.id = "string";
|
|
685
698
|
__decorateClass([
|
|
686
699
|
parsable()
|
|
687
700
|
], SchemaString.prototype, "min", 1);
|
|
@@ -723,6 +736,7 @@ var SchemaUnion = class extends SchemaItem {
|
|
|
723
736
|
return result;
|
|
724
737
|
}
|
|
725
738
|
};
|
|
739
|
+
SchemaUnion.id = "union";
|
|
726
740
|
|
|
727
741
|
// src/items/intersection.ts
|
|
728
742
|
import { isObject as isObject4 } from "@dzeio/object-util";
|
|
@@ -751,6 +765,7 @@ var SchemaIntersection = class extends SchemaItem {
|
|
|
751
765
|
return result;
|
|
752
766
|
}
|
|
753
767
|
};
|
|
768
|
+
SchemaIntersection.id = "intersection";
|
|
754
769
|
|
|
755
770
|
// src/items/default.ts
|
|
756
771
|
var SchemaDefault = class extends SchemaItem {
|
|
@@ -770,6 +785,7 @@ var SchemaDefault = class extends SchemaItem {
|
|
|
770
785
|
return [{ item: this.child, value: isNull(input) || !this.strict && !input ? this.defaultVal : input, path: void 0 }];
|
|
771
786
|
}
|
|
772
787
|
};
|
|
788
|
+
SchemaDefault.id = "default";
|
|
773
789
|
|
|
774
790
|
// src/items/file.ts
|
|
775
791
|
var SchemaFile = class extends SchemaItem {
|
|
@@ -789,6 +805,7 @@ var SchemaFile = class extends SchemaItem {
|
|
|
789
805
|
return input instanceof File;
|
|
790
806
|
}
|
|
791
807
|
};
|
|
808
|
+
SchemaFile.id = "file";
|
|
792
809
|
__decorateClass([
|
|
793
810
|
parsable()
|
|
794
811
|
], SchemaFile.prototype, "extension", 1);
|
|
@@ -817,6 +834,7 @@ var SchemaTuple = class extends SchemaItem {
|
|
|
817
834
|
return Array.isArray(input) ? this.children.map((entry, index) => ({ value: input[index], item: entry, path: index.toString() })) : [];
|
|
818
835
|
}
|
|
819
836
|
};
|
|
837
|
+
SchemaTuple.id = "tuple";
|
|
820
838
|
|
|
821
839
|
// src/items/nullish.ts
|
|
822
840
|
var SchemaUndefined = class extends SchemaItem {
|
|
@@ -824,26 +842,31 @@ var SchemaUndefined = class extends SchemaItem {
|
|
|
824
842
|
return typeof input === "undefined";
|
|
825
843
|
}
|
|
826
844
|
};
|
|
845
|
+
SchemaUndefined.id = "undefined";
|
|
827
846
|
var SchemaNull = class extends SchemaItem {
|
|
828
847
|
isOfType(input) {
|
|
829
848
|
return input === null;
|
|
830
849
|
}
|
|
831
850
|
};
|
|
851
|
+
SchemaNull.id = "null";
|
|
832
852
|
var SchemaVoid = class extends SchemaItem {
|
|
833
853
|
isOfType(input) {
|
|
834
854
|
return typeof input === "undefined";
|
|
835
855
|
}
|
|
836
856
|
};
|
|
857
|
+
SchemaVoid.id = "void";
|
|
837
858
|
var SchemaNullish = class extends SchemaItem {
|
|
838
859
|
isOfType(input) {
|
|
839
860
|
return isNull(input);
|
|
840
861
|
}
|
|
841
862
|
};
|
|
863
|
+
SchemaNullish.id = "nullish";
|
|
842
864
|
var SchemaNever = class extends SchemaItem {
|
|
843
865
|
isOfType(_input) {
|
|
844
866
|
return false;
|
|
845
867
|
}
|
|
846
868
|
};
|
|
869
|
+
SchemaNever.id = "never";
|
|
847
870
|
|
|
848
871
|
// src/Schema.ts
|
|
849
872
|
import { isObject as isObject5, objectRemap as objectRemap2 } from "@dzeio/object-util";
|
|
@@ -866,7 +889,7 @@ var _Schema = class _Schema extends SchemaObject {
|
|
|
866
889
|
this.registeredModules.push(module);
|
|
867
890
|
}
|
|
868
891
|
static getModule(name) {
|
|
869
|
-
const module = this.registeredModules.find((it) => it.
|
|
892
|
+
const module = this.registeredModules.find((it) => it.id === name);
|
|
870
893
|
if (!module) {
|
|
871
894
|
console.log("Couldn't find module", name);
|
|
872
895
|
}
|