@tstdl/base 0.90.92 → 0.91.0-beta10
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/api/types.d.ts +1 -1
- package/authentication/authentication.api.d.ts +56 -57
- package/authentication/authentication.api.js +1 -6
- package/authentication/client/api.client.d.ts +4 -5
- package/authentication/client/api.client.js +1 -2
- package/authentication/client/http-client.middleware.d.ts +1 -1
- package/browser/pdf-options.js +8 -9
- package/errors/custom.error.d.ts +5 -5
- package/examples/api/basic-overview.js +4 -4
- package/http/client/http-client-request.d.ts +1 -2
- package/http/client/module.d.ts +1 -1
- package/image-service/image-service.js +4 -7
- package/mail/mail.client.d.ts +2 -2
- package/mail/mail.client.js +3 -5
- package/orm/decorators.d.ts +1 -0
- package/orm/decorators.js +4 -0
- package/orm/entity.js +1 -1
- package/orm/index.d.ts +4 -0
- package/orm/index.js +4 -0
- package/orm/repository.d.ts +6 -8
- package/orm/repository.js +7 -0
- package/orm/schema-converter.d.ts +99 -0
- package/orm/schema-converter.js +74 -0
- package/orm/schema.d.ts +3 -0
- package/orm/schema.js +1 -0
- package/orm/types.d.ts +8 -0
- package/orm/types.js +6 -0
- package/package.json +7 -5
- package/reflection/registry.d.ts +1 -1
- package/reflection/utils.d.ts +2 -2
- package/schema/decorators/class.d.ts +1 -1
- package/schema/decorators/index.d.ts +0 -2
- package/schema/decorators/index.js +0 -2
- package/schema/decorators/property.d.ts +6 -5
- package/schema/decorators/property.js +10 -14
- package/schema/decorators/types.d.ts +7 -12
- package/schema/decorators/utils.d.ts +2 -15
- package/schema/decorators/utils.js +4 -43
- package/schema/index.d.ts +1 -6
- package/schema/index.js +15 -6
- package/schema/schema.d.ts +89 -14
- package/schema/schema.error.d.ts +4 -6
- package/schema/schema.error.js +6 -10
- package/schema/schema.js +74 -276
- package/schema/schemas/any.d.ts +7 -5
- package/schema/schemas/any.js +10 -6
- package/schema/schemas/array.d.ts +11 -12
- package/schema/schemas/array.js +29 -19
- package/schema/schemas/bigint.d.ts +9 -0
- package/schema/schemas/bigint.js +19 -0
- package/schema/schemas/boolean.d.ts +11 -5
- package/schema/schemas/boolean.js +41 -6
- package/schema/schemas/date.d.ts +9 -7
- package/schema/schemas/date.js +24 -18
- package/schema/schemas/defaulted.d.ts +11 -6
- package/schema/schemas/defaulted.js +23 -8
- package/schema/schemas/enumeration.d.ts +10 -5
- package/schema/schemas/enumeration.js +25 -15
- package/schema/schemas/function.d.ts +8 -0
- package/schema/schemas/function.js +14 -0
- package/schema/schemas/index.d.ts +5 -6
- package/schema/schemas/index.js +5 -6
- package/schema/schemas/instance.d.ts +11 -3
- package/schema/schemas/instance.js +25 -4
- package/schema/schemas/literal.d.ts +10 -5
- package/schema/schemas/literal.js +25 -15
- package/schema/schemas/never.d.ts +6 -0
- package/schema/schemas/never.js +11 -0
- package/schema/schemas/nullable.d.ts +11 -6
- package/schema/schemas/nullable.js +24 -7
- package/schema/schemas/number.d.ts +9 -7
- package/schema/schemas/number.js +28 -23
- package/schema/schemas/object.d.ts +84 -7
- package/schema/schemas/object.js +180 -6
- package/schema/schemas/one-or-many.d.ts +10 -7
- package/schema/schemas/one-or-many.js +18 -11
- package/schema/schemas/optional.d.ts +11 -7
- package/schema/schemas/optional.js +24 -6
- package/schema/schemas/readable-stream.d.ts +8 -6
- package/schema/schemas/readable-stream.js +10 -5
- package/schema/schemas/regexp.d.ts +8 -6
- package/schema/schemas/regexp.js +24 -6
- package/schema/schemas/simple.d.ts +27 -0
- package/schema/schemas/simple.js +57 -0
- package/schema/schemas/string.d.ts +9 -21
- package/schema/schemas/string.js +20 -34
- package/schema/schemas/symbol.d.ts +8 -0
- package/schema/schemas/symbol.js +19 -0
- package/schema/schemas/transform.d.ts +9 -5
- package/schema/schemas/transform.js +19 -6
- package/schema/schemas/uint8-array.d.ts +9 -5
- package/schema/schemas/uint8-array.js +17 -26
- package/schema/schemas/union.d.ts +14 -7
- package/schema/schemas/union.js +30 -11
- package/schema/schemas/unknown.d.ts +7 -5
- package/schema/schemas/unknown.js +11 -7
- package/schema/testable.d.ts +3 -0
- package/schema/testable.js +33 -0
- package/schema/types.d.ts +31 -0
- package/schema/types.js +1 -0
- package/schema-old/decorators/class.d.ts +3 -0
- package/schema-old/decorators/class.js +5 -0
- package/schema-old/decorators/index.d.ts +6 -0
- package/schema-old/decorators/index.js +6 -0
- package/schema-old/decorators/property.d.ts +6 -0
- package/schema-old/decorators/property.js +17 -0
- package/schema-old/decorators/types.d.ts +19 -0
- package/schema-old/decorators/types.js +1 -0
- package/schema-old/decorators/utils.d.ts +15 -0
- package/schema-old/decorators/utils.js +48 -0
- package/schema-old/index.d.ts +10 -0
- package/schema-old/index.js +10 -0
- package/schema-old/schema.d.ts +15 -0
- package/schema-old/schema.error.d.ts +26 -0
- package/schema-old/schema.error.js +64 -0
- package/schema-old/schema.js +283 -0
- package/schema-old/schemas/any.d.ts +5 -0
- package/schema-old/schemas/any.js +9 -0
- package/schema-old/schemas/array.d.ts +12 -0
- package/schema-old/schemas/array.js +23 -0
- package/schema-old/schemas/boolean.d.ts +5 -0
- package/schema-old/schemas/boolean.js +9 -0
- package/schema-old/schemas/date.d.ts +8 -0
- package/schema-old/schemas/date.js +22 -0
- package/schema-old/schemas/defaulted.d.ts +6 -0
- package/schema-old/schemas/defaulted.js +10 -0
- package/schema-old/schemas/enumeration.d.ts +6 -0
- package/schema-old/schemas/enumeration.js +17 -0
- package/schema-old/schemas/index.d.ts +26 -0
- package/schema-old/schemas/index.js +26 -0
- package/schema-old/schemas/instance.d.ts +3 -0
- package/schema-old/schemas/instance.js +5 -0
- package/schema-old/schemas/literal.d.ts +5 -0
- package/schema-old/schemas/literal.js +17 -0
- package/schema-old/schemas/nullable.d.ts +6 -0
- package/schema-old/schemas/nullable.js +9 -0
- package/schema-old/schemas/number.d.ts +9 -0
- package/schema-old/schemas/number.js +27 -0
- package/schema-old/schemas/object.d.ts +7 -0
- package/schema-old/schemas/object.js +12 -0
- package/schema-old/schemas/one-or-many.d.ts +9 -0
- package/schema-old/schemas/one-or-many.js +15 -0
- package/schema-old/schemas/optional.d.ts +7 -0
- package/schema-old/schemas/optional.js +8 -0
- package/schema-old/schemas/readable-stream.d.ts +6 -0
- package/schema-old/schemas/readable-stream.js +9 -0
- package/schema-old/schemas/regexp.d.ts +6 -0
- package/schema-old/schemas/regexp.js +9 -0
- package/schema-old/schemas/string.d.ts +22 -0
- package/schema-old/schemas/string.js +38 -0
- package/schema-old/schemas/transform.d.ts +5 -0
- package/schema-old/schemas/transform.js +7 -0
- package/schema-old/schemas/uint8-array.d.ts +10 -0
- package/schema-old/schemas/uint8-array.js +29 -0
- package/schema-old/schemas/union.d.ts +7 -0
- package/schema-old/schemas/union.js +13 -0
- package/schema-old/schemas/unknown.d.ts +5 -0
- package/schema-old/schemas/unknown.js +9 -0
- package/templates/resolvers/string.template-resolver.d.ts +0 -1
- package/templates/resolvers/string.template-resolver.js +1 -5
- package/templates/template.model.js +1 -1
- package/types.d.ts +2 -0
- package/utils/type-guards.js +1 -1
- /package/{schema → schema-old}/array-constraints/index.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/index.js +0 -0
- /package/{schema → schema-old}/array-constraints/maximum-length.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/maximum-length.js +0 -0
- /package/{schema → schema-old}/array-constraints/minimum-length.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/minimum-length.js +0 -0
- /package/{schema → schema-old}/coercers/boolean.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/boolean.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/date.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/date.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/index.d.ts +0 -0
- /package/{schema → schema-old}/coercers/index.js +0 -0
- /package/{schema → schema-old}/coercers/number.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/number.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/regexp.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/regexp.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/string.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/string.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/uint8-array.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/uint8-array.coercer.js +0 -0
- /package/{schema → schema-old}/constraints/enumeration.d.ts +0 -0
- /package/{schema → schema-old}/constraints/enumeration.js +0 -0
- /package/{schema → schema-old}/constraints/generic.d.ts +0 -0
- /package/{schema → schema-old}/constraints/generic.js +0 -0
- /package/{schema → schema-old}/constraints/index.d.ts +0 -0
- /package/{schema → schema-old}/constraints/index.js +0 -0
- /package/{schema → schema-old}/constraints/integer.d.ts +0 -0
- /package/{schema → schema-old}/constraints/integer.js +0 -0
- /package/{schema → schema-old}/constraints/length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/length.js +0 -0
- /package/{schema → schema-old}/constraints/literal.d.ts +0 -0
- /package/{schema → schema-old}/constraints/literal.js +0 -0
- /package/{schema → schema-old}/constraints/maximum-date.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum-date.js +0 -0
- /package/{schema → schema-old}/constraints/maximum-length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum-length.js +0 -0
- /package/{schema → schema-old}/constraints/maximum.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum.js +0 -0
- /package/{schema → schema-old}/constraints/minimum-date.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum-date.js +0 -0
- /package/{schema → schema-old}/constraints/minimum-length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum-length.js +0 -0
- /package/{schema → schema-old}/constraints/minimum.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum.js +0 -0
- /package/{schema → schema-old}/constraints/pattern.d.ts +0 -0
- /package/{schema → schema-old}/constraints/pattern.js +0 -0
- /package/{schema → schema-old}/decorators/coerce.d.ts +0 -0
- /package/{schema → schema-old}/decorators/coerce.js +0 -0
- /package/{schema → schema-old}/decorators/constraint.d.ts +0 -0
- /package/{schema → schema-old}/decorators/constraint.js +0 -0
- /package/{schema → schema-old}/schemas/assign.d.ts +0 -0
- /package/{schema → schema-old}/schemas/assign.js +0 -0
- /package/{schema → schema-old}/schemas/constraint.d.ts +0 -0
- /package/{schema → schema-old}/schemas/constraint.js +0 -0
- /package/{schema → schema-old}/schemas/omit.d.ts +0 -0
- /package/{schema → schema-old}/schemas/omit.js +0 -0
- /package/{schema → schema-old}/schemas/partial.d.ts +0 -0
- /package/{schema → schema-old}/schemas/partial.js +0 -0
- /package/{schema → schema-old}/schemas/pick.d.ts +0 -0
- /package/{schema → schema-old}/schemas/pick.js +0 -0
- /package/{schema → schema-old}/schemas/record.d.ts +0 -0
- /package/{schema → schema-old}/schemas/record.js +0 -0
- /package/{schema → schema-old}/transformers/generic.d.ts +0 -0
- /package/{schema → schema-old}/transformers/generic.js +0 -0
- /package/{schema → schema-old}/transformers/index.d.ts +0 -0
- /package/{schema → schema-old}/transformers/index.js +0 -0
- /package/{schema → schema-old}/transformers/lowercase.d.ts +0 -0
- /package/{schema → schema-old}/transformers/lowercase.js +0 -0
- /package/{schema → schema-old}/transformers/trim.d.ts +0 -0
- /package/{schema → schema-old}/transformers/trim.js +0 -0
- /package/{schema → schema-old}/transformers/uppercase.d.ts +0 -0
- /package/{schema → schema-old}/transformers/uppercase.js +0 -0
- /package/{schema → schema-old}/types/index.d.ts +0 -0
- /package/{schema → schema-old}/types/index.js +0 -0
- /package/{schema → schema-old}/types/schema-array-constraint.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-array-constraint.js +0 -0
- /package/{schema → schema-old}/types/schema-value-coercer.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-coercer.js +0 -0
- /package/{schema → schema-old}/types/schema-value-constraint.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-constraint.js +0 -0
- /package/{schema → schema-old}/types/schema-value-transformer.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-transformer.js +0 -0
- /package/{schema → schema-old}/types/types.d.ts +0 -0
- /package/{schema → schema-old}/types/types.js +0 -0
- /package/{schema → schema-old}/utils/index.d.ts +0 -0
- /package/{schema → schema-old}/utils/index.js +0 -0
- /package/{schema → schema-old}/utils/schema.d.ts +0 -0
- /package/{schema → schema-old}/utils/schema.js +0 -0
- /package/{schema → schema-old}/utils/value-type.d.ts +0 -0
- /package/{schema → schema-old}/utils/value-type.js +0 -0
package/schema/schemas/date.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
maximum?: Date | number;
|
|
1
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
+
export type DateSchemaOptions = SimpleSchemaOptions & {
|
|
4
|
+
integer?: boolean;
|
|
6
5
|
};
|
|
7
|
-
export declare
|
|
8
|
-
|
|
6
|
+
export declare class DateSchema extends SimpleSchema<globalThis.Date> {
|
|
7
|
+
constructor(options?: DateSchemaOptions);
|
|
8
|
+
}
|
|
9
|
+
export declare function date(options?: DateSchemaOptions): DateSchema;
|
|
10
|
+
export declare function DateProperty(options?: SchemaPropertyDecoratorOptions & DateSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/date.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { isValidDate } from '../../utils/type-guards.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { SchemaError } from '../schema.error.js';
|
|
4
|
+
import { SimpleSchema } from './simple.js';
|
|
5
|
+
export class DateSchema extends SimpleSchema {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super('date', isValidDate, options, {
|
|
8
|
+
coercers: {
|
|
9
|
+
string: (value, path, options) => {
|
|
10
|
+
const result = new globalThis.Date(value);
|
|
11
|
+
return globalThis.Number.isNaN(result.getTime())
|
|
12
|
+
? { success: false, error: SchemaError.couldNotCoerce('date', 'string', path, { fast: options.fastErrors }) }
|
|
13
|
+
: { success: true, value: result, valid: true };
|
|
14
|
+
},
|
|
15
|
+
number: (value) => ({ success: true, value: new globalThis.Date(value), valid: false })
|
|
16
|
+
},
|
|
17
|
+
constraints: [
|
|
18
|
+
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'value is not an integer.' }) : null
|
|
19
|
+
]
|
|
20
|
+
});
|
|
11
21
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return valueSchema(Date, {
|
|
16
|
-
...options,
|
|
17
|
-
valueConstraints: constraints
|
|
18
|
-
});
|
|
22
|
+
}
|
|
23
|
+
export function date(options) {
|
|
24
|
+
return new DateSchema(options);
|
|
19
25
|
}
|
|
20
26
|
export function DateProperty(options) {
|
|
21
|
-
return
|
|
27
|
+
return Property(date(options), options);
|
|
22
28
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
+
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export declare class DefaultSchema<T, D> extends Schema<T | D> {
|
|
5
|
+
readonly schema: Schema<T>;
|
|
6
|
+
readonly defaultValue: D;
|
|
7
|
+
constructor(schema: SchemaTestable<T>, defaultValue: D);
|
|
8
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | D>;
|
|
9
|
+
}
|
|
10
|
+
export declare function defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D): DefaultSchema<T, D>;
|
|
11
|
+
export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
|
|
1
|
+
import { isNullOrUndefined } from '../../utils/type-guards.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
import { schemaTestableToSchema } from '../testable.js';
|
|
5
|
+
export class DefaultSchema extends Schema {
|
|
6
|
+
schema;
|
|
7
|
+
defaultValue;
|
|
8
|
+
constructor(schema, defaultValue) {
|
|
9
|
+
super();
|
|
10
|
+
this.schema = schemaTestableToSchema(schema);
|
|
11
|
+
this.defaultValue = defaultValue;
|
|
12
|
+
}
|
|
13
|
+
_test(value, path, options) {
|
|
14
|
+
if (isNullOrUndefined(value)) {
|
|
15
|
+
return { valid: true, value: this.defaultValue };
|
|
16
|
+
}
|
|
17
|
+
return this.schema._test(value, path, options);
|
|
18
|
+
}
|
|
7
19
|
}
|
|
8
|
-
export function
|
|
9
|
-
return
|
|
20
|
+
export function defaulted(schema, defaultValue) {
|
|
21
|
+
return new DefaultSchema(schema, defaultValue);
|
|
22
|
+
}
|
|
23
|
+
export function Defaulted(schema, defaultValue, options) {
|
|
24
|
+
return Property(defaulted(schema, defaultValue), options);
|
|
10
25
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
2
1
|
import type { Enumeration as EnumerationType, EnumerationValue } from '../../types.js';
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export declare
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
4
|
+
export type EnumerationSchemaOptions = SimpleSchemaOptions;
|
|
5
|
+
export declare class EnumerationSchema<T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
|
|
6
|
+
#private;
|
|
7
|
+
readonly enumeration: EnumerationType;
|
|
8
|
+
constructor(enumeration: T, options?: EnumerationSchemaOptions);
|
|
9
|
+
}
|
|
10
|
+
export declare function enumeration<T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions): EnumerationSchema<T>;
|
|
11
|
+
export declare function Enumeration(enumeration: EnumerationType, options?: EnumerationSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { enumValues } from '../../utils/enum.js';
|
|
2
|
+
import { isArray, isString } from '../../utils/type-guards.js';
|
|
3
|
+
import { Property } from '../decorators/index.js';
|
|
4
|
+
import { SimpleSchema } from './simple.js';
|
|
5
|
+
export class EnumerationSchema extends SimpleSchema {
|
|
6
|
+
#allowedValuesSet;
|
|
7
|
+
enumeration;
|
|
8
|
+
constructor(enumeration, options) {
|
|
9
|
+
const allowedValues = isArray(enumeration) ? enumeration : enumValues(enumeration);
|
|
10
|
+
const allowedValuesString = allowedValues.map((value) => (isString(value) ? `"${value}"` : String(value))).join(', ');
|
|
11
|
+
super(`one of [${allowedValuesString}]`, (value) => this.#allowedValuesSet.has(value), options, {
|
|
12
|
+
coercers: {
|
|
13
|
+
string: (value) => ({ success: true, value: Number(value), valid: false }),
|
|
14
|
+
number: (value) => ({ success: true, value: String(value), valid: false })
|
|
15
|
+
},
|
|
16
|
+
gotValueFormatter: (value) => isString(value) ? `"${value}"` : String(value)
|
|
17
|
+
});
|
|
18
|
+
this.enumeration = enumeration;
|
|
19
|
+
this.#allowedValuesSet = new Set(allowedValues);
|
|
20
|
+
}
|
|
14
21
|
}
|
|
15
|
-
export function
|
|
16
|
-
return
|
|
22
|
+
export function enumeration(enumeration, options) {
|
|
23
|
+
return new EnumerationSchema(enumeration, options);
|
|
24
|
+
}
|
|
25
|
+
export function Enumeration(enums, options) {
|
|
26
|
+
return Property(enumeration(enums, options), options);
|
|
17
27
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
+
export type FunctionSchemaOptions = SimpleSchemaOptions;
|
|
4
|
+
export declare class FunctionSchema extends SimpleSchema<Function> {
|
|
5
|
+
constructor(options?: FunctionSchemaOptions);
|
|
6
|
+
}
|
|
7
|
+
export declare function func(): FunctionSchema;
|
|
8
|
+
export declare function FunctionProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isFunction } from '../../utils/type-guards.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { SimpleSchema } from './simple.js';
|
|
4
|
+
export class FunctionSchema extends SimpleSchema {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super('function', isFunction, options);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function func() {
|
|
10
|
+
return new FunctionSchema();
|
|
11
|
+
}
|
|
12
|
+
export function FunctionProperty(options) {
|
|
13
|
+
return Property(func(), options);
|
|
14
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
export * from './any.js';
|
|
2
2
|
export * from './array.js';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './bigint.js';
|
|
4
4
|
export * from './boolean.js';
|
|
5
|
-
export * from './constraint.js';
|
|
6
5
|
export * from './date.js';
|
|
7
6
|
export * from './defaulted.js';
|
|
8
7
|
export * from './enumeration.js';
|
|
8
|
+
export * from './function.js';
|
|
9
9
|
export * from './instance.js';
|
|
10
10
|
export * from './literal.js';
|
|
11
|
+
export * from './never.js';
|
|
11
12
|
export * from './nullable.js';
|
|
12
13
|
export * from './number.js';
|
|
13
14
|
export * from './object.js';
|
|
14
|
-
export * from './omit.js';
|
|
15
15
|
export * from './one-or-many.js';
|
|
16
16
|
export * from './optional.js';
|
|
17
|
-
export * from './partial.js';
|
|
18
|
-
export * from './pick.js';
|
|
19
17
|
export * from './readable-stream.js';
|
|
20
|
-
export * from './record.js';
|
|
21
18
|
export * from './regexp.js';
|
|
19
|
+
export * from './simple.js';
|
|
22
20
|
export * from './string.js';
|
|
21
|
+
export * from './symbol.js';
|
|
23
22
|
export * from './transform.js';
|
|
24
23
|
export * from './uint8-array.js';
|
|
25
24
|
export * from './union.js';
|
package/schema/schemas/index.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
export * from './any.js';
|
|
2
2
|
export * from './array.js';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './bigint.js';
|
|
4
4
|
export * from './boolean.js';
|
|
5
|
-
export * from './constraint.js';
|
|
6
5
|
export * from './date.js';
|
|
7
6
|
export * from './defaulted.js';
|
|
8
7
|
export * from './enumeration.js';
|
|
8
|
+
export * from './function.js';
|
|
9
9
|
export * from './instance.js';
|
|
10
10
|
export * from './literal.js';
|
|
11
|
+
export * from './never.js';
|
|
11
12
|
export * from './nullable.js';
|
|
12
13
|
export * from './number.js';
|
|
13
14
|
export * from './object.js';
|
|
14
|
-
export * from './omit.js';
|
|
15
15
|
export * from './one-or-many.js';
|
|
16
16
|
export * from './optional.js';
|
|
17
|
-
export * from './partial.js';
|
|
18
|
-
export * from './pick.js';
|
|
19
17
|
export * from './readable-stream.js';
|
|
20
|
-
export * from './record.js';
|
|
21
18
|
export * from './regexp.js';
|
|
19
|
+
export * from './simple.js';
|
|
22
20
|
export * from './string.js';
|
|
21
|
+
export * from './symbol.js';
|
|
23
22
|
export * from './transform.js';
|
|
24
23
|
export * from './uint8-array.js';
|
|
25
24
|
export * from './union.js';
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import type { AbstractConstructor } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
+
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
export declare class InstanceSchema<T extends AbstractConstructor> extends Schema<InstanceType<T>> {
|
|
6
|
+
readonly type: T;
|
|
7
|
+
constructor(type: T);
|
|
8
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<InstanceType<T>>;
|
|
9
|
+
}
|
|
10
|
+
export declare function instance<T extends AbstractConstructor>(type: T): InstanceSchema<T>;
|
|
11
|
+
export declare function Instance(type: AbstractConstructor, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { typeOf } from '../../utils/type-of.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { SchemaError } from '../schema.error.js';
|
|
4
|
+
import { Schema } from '../schema.js';
|
|
5
|
+
export class InstanceSchema extends Schema {
|
|
6
|
+
type;
|
|
7
|
+
constructor(type) {
|
|
8
|
+
super();
|
|
9
|
+
this.type = type;
|
|
10
|
+
}
|
|
11
|
+
_test(value, path, options) {
|
|
12
|
+
if (value instanceof this.type) {
|
|
13
|
+
return { valid: true, value };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
valid: false,
|
|
17
|
+
error: SchemaError.expectedButGot(typeOf(this.type), typeOf(value), path, { fast: options.fastErrors })
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function instance(type) {
|
|
22
|
+
return new InstanceSchema(type);
|
|
23
|
+
}
|
|
24
|
+
export function Instance(type, options) {
|
|
25
|
+
return Property(instance(type), options);
|
|
5
26
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare
|
|
5
|
-
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
+
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export declare class LiteralSchema<const T> extends Schema<T> {
|
|
5
|
+
readonly value: T;
|
|
6
|
+
constructor(value: T);
|
|
7
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
8
|
+
}
|
|
9
|
+
export declare function literal<const T>(value: T): LiteralSchema<T>;
|
|
10
|
+
export declare function Literal(value: any, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { isPrimitive } from '../../utils/type-guards.js';
|
|
2
|
+
import { typeOf } from '../../utils/type-of.js';
|
|
3
|
+
import { Property } from '../decorators/index.js';
|
|
4
|
+
import { SchemaError } from '../schema.error.js';
|
|
5
|
+
import { Schema } from '../schema.js';
|
|
6
|
+
export class LiteralSchema extends Schema {
|
|
7
|
+
value;
|
|
8
|
+
constructor(value) {
|
|
9
|
+
super();
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
_test(value, path, options) {
|
|
13
|
+
if (value === this.value) {
|
|
14
|
+
return { valid: true, value };
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
valid: false,
|
|
18
|
+
error: SchemaError.expectedButGot(isPrimitive(this.value) ? String(this.value) : typeOf(this.value), isPrimitive(value) ? String(value) : typeOf(value), path, { fast: options.fastErrors })
|
|
19
|
+
};
|
|
20
|
+
}
|
|
14
21
|
}
|
|
15
|
-
export function
|
|
16
|
-
return
|
|
22
|
+
export function literal(value) {
|
|
23
|
+
return new LiteralSchema(value);
|
|
24
|
+
}
|
|
25
|
+
export function Literal(value, options) {
|
|
26
|
+
return Property(literal(value), options);
|
|
17
27
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
export declare class NeverSchema extends Schema<never> {
|
|
4
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<never>;
|
|
5
|
+
}
|
|
6
|
+
export declare function never(): NeverSchema;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaError } from '../../schema/schema.error.js';
|
|
2
|
+
import { typeOf } from '../../utils/type-of.js';
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
export class NeverSchema extends Schema {
|
|
5
|
+
_test(value, path, options) {
|
|
6
|
+
return { valid: false, error: SchemaError.expectedButGot('never', typeOf(value), path, { fast: options.fastErrors }) };
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function never() {
|
|
10
|
+
return new NeverSchema();
|
|
11
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
+
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
export declare class NullableSchema<T> extends Schema<T | null> {
|
|
6
|
+
readonly schema: Schema<T>;
|
|
7
|
+
constructor(schema: SchemaTestable<T>);
|
|
8
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
|
|
9
|
+
}
|
|
10
|
+
export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
|
|
11
|
+
export declare function Nullable(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isNull } from '../../utils/type-guards.js';
|
|
2
|
+
import { createSchemaPropertyDecorator } from '../decorators/index.js';
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
import { schemaTestableToSchema } from '../testable.js';
|
|
5
|
+
export class NullableSchema extends Schema {
|
|
6
|
+
schema;
|
|
7
|
+
constructor(schema) {
|
|
8
|
+
if ((schema instanceof NullableSchema) && (schema == schema.schema)) {
|
|
9
|
+
return schema; // eslint-disable-line no-constructor-return
|
|
10
|
+
}
|
|
11
|
+
super();
|
|
12
|
+
this.schema = schemaTestableToSchema(schema);
|
|
13
|
+
}
|
|
14
|
+
_test(value, path, options) {
|
|
15
|
+
if (isNull(value)) {
|
|
16
|
+
return { valid: true, value };
|
|
17
|
+
}
|
|
18
|
+
return this.schema._test(value, path, options);
|
|
19
|
+
}
|
|
5
20
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
export function nullable(schema) {
|
|
22
|
+
return new NullableSchema(schema);
|
|
23
|
+
}
|
|
24
|
+
export function Nullable(schema, options) {
|
|
25
|
+
return createSchemaPropertyDecorator({ schema, ...options, nullable: true });
|
|
9
26
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
export type
|
|
4
|
-
minimum?: number;
|
|
5
|
-
maximum?: number;
|
|
1
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
+
export type NumberSchemaOptions = SimpleSchemaOptions & {
|
|
6
4
|
integer?: boolean;
|
|
7
5
|
};
|
|
8
|
-
export declare
|
|
9
|
-
|
|
6
|
+
export declare class NumberSchema extends SimpleSchema<number> {
|
|
7
|
+
constructor(options?: NumberSchemaOptions);
|
|
8
|
+
}
|
|
9
|
+
export declare function number(options?: NumberSchemaOptions): NumberSchema;
|
|
10
|
+
export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/number.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { isNumber } from '../../utils/type-guards.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { SchemaError } from '../schema.error.js';
|
|
4
|
+
import { SimpleSchema } from './simple.js';
|
|
5
|
+
export class NumberSchema extends SimpleSchema {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super('number', isNumber, options, {
|
|
8
|
+
coercers: {
|
|
9
|
+
string: (value, path, options) => {
|
|
10
|
+
const result = globalThis.Number(value);
|
|
11
|
+
return globalThis.Number.isNaN(result)
|
|
12
|
+
? { success: false, error: SchemaError.couldNotCoerce('number', 'string', path, { fast: options.fastErrors }) }
|
|
13
|
+
: { success: true, value: result, valid: true };
|
|
14
|
+
},
|
|
15
|
+
boolean: (value) => ({ success: true, value: globalThis.Number(value), valid: true }),
|
|
16
|
+
bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false })
|
|
17
|
+
},
|
|
18
|
+
constraints: [
|
|
19
|
+
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'value is not an integer.' }) : null
|
|
20
|
+
]
|
|
21
|
+
});
|
|
13
22
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (options.integer == true) {
|
|
18
|
-
valueConstraints.push(integerConstraint);
|
|
19
|
-
}
|
|
20
|
-
return valueSchema(Number, {
|
|
21
|
-
...options,
|
|
22
|
-
valueConstraints
|
|
23
|
-
});
|
|
23
|
+
}
|
|
24
|
+
export function number(options) {
|
|
25
|
+
return new NumberSchema(options);
|
|
24
26
|
}
|
|
25
27
|
export function NumberProperty(options) {
|
|
26
|
-
return
|
|
28
|
+
return Property(number(options), options);
|
|
29
|
+
}
|
|
30
|
+
export function Integer(options) {
|
|
31
|
+
return Property(number({ ...options, integer: true }), options);
|
|
27
32
|
}
|