@tstdl/base 0.90.91 → 0.91.0-beta1
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 +21 -22
- 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/dom/observation/intersection-observer.js +2 -2
- 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 +3 -3
- 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 +83 -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 +6 -4
- 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 +3 -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 +10 -12
- package/schema/schemas/array.js +27 -19
- package/schema/schemas/bigint.d.ts +8 -0
- package/schema/schemas/bigint.js +19 -0
- package/schema/schemas/boolean.d.ts +15 -5
- package/schema/schemas/boolean.js +47 -6
- package/schema/schemas/date.d.ts +9 -7
- package/schema/schemas/date.js +25 -19
- 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/index.d.ts +4 -6
- package/schema/schemas/index.js +4 -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 +10 -6
- package/schema/schemas/nullable.js +24 -7
- package/schema/schemas/number.d.ts +13 -7
- package/schema/schemas/number.js +34 -23
- package/schema/schemas/object.d.ts +75 -7
- package/schema/schemas/object.js +171 -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 +10 -7
- package/schema/schemas/optional.js +21 -3
- package/schema/schemas/readable-stream.d.ts +8 -6
- package/schema/schemas/readable-stream.js +11 -6
- package/schema/schemas/regexp.d.ts +8 -6
- package/schema/schemas/regexp.js +25 -7
- package/schema/schemas/simple.d.ts +27 -0
- package/schema/schemas/simple.js +57 -0
- package/schema/schemas/string.d.ts +13 -21
- package/schema/schemas/string.js +26 -34
- package/schema/schemas/symbol.d.ts +12 -0
- package/schema/schemas/symbol.js +25 -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 +30 -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
|
@@ -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
|
}
|
|
@@ -1,25 +1,23 @@
|
|
|
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';
|
|
9
8
|
export * from './instance.js';
|
|
10
9
|
export * from './literal.js';
|
|
10
|
+
export * from './never.js';
|
|
11
11
|
export * from './nullable.js';
|
|
12
12
|
export * from './number.js';
|
|
13
13
|
export * from './object.js';
|
|
14
|
-
export * from './omit.js';
|
|
15
14
|
export * from './one-or-many.js';
|
|
16
15
|
export * from './optional.js';
|
|
17
|
-
export * from './partial.js';
|
|
18
|
-
export * from './pick.js';
|
|
19
16
|
export * from './readable-stream.js';
|
|
20
|
-
export * from './record.js';
|
|
21
17
|
export * from './regexp.js';
|
|
18
|
+
export * from './simple.js';
|
|
22
19
|
export * from './string.js';
|
|
20
|
+
export * from './symbol.js';
|
|
23
21
|
export * from './transform.js';
|
|
24
22
|
export * from './uint8-array.js';
|
|
25
23
|
export * from './union.js';
|
package/schema/schemas/index.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
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';
|
|
9
8
|
export * from './instance.js';
|
|
10
9
|
export * from './literal.js';
|
|
10
|
+
export * from './never.js';
|
|
11
11
|
export * from './nullable.js';
|
|
12
12
|
export * from './number.js';
|
|
13
13
|
export * from './object.js';
|
|
14
|
-
export * from './omit.js';
|
|
15
14
|
export * from './one-or-many.js';
|
|
16
15
|
export * from './optional.js';
|
|
17
|
-
export * from './partial.js';
|
|
18
|
-
export * from './pick.js';
|
|
19
16
|
export * from './readable-stream.js';
|
|
20
|
-
export * from './record.js';
|
|
21
17
|
export * from './regexp.js';
|
|
18
|
+
export * from './simple.js';
|
|
22
19
|
export * from './string.js';
|
|
20
|
+
export * from './symbol.js';
|
|
23
21
|
export * from './transform.js';
|
|
24
22
|
export * from './uint8-array.js';
|
|
25
23
|
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,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecorator } from '../decorators/index.js';
|
|
3
|
+
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export declare class NullableSchema<T> extends Schema<T | null> {
|
|
5
|
+
readonly schema: Schema<T>;
|
|
6
|
+
constructor(schema: SchemaTestable<T>);
|
|
7
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
|
|
8
|
+
}
|
|
9
|
+
export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
|
|
10
|
+
export declare function 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() {
|
|
25
|
+
return createSchemaPropertyDecorator({ nullable: true });
|
|
9
26
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
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 Number(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use {@link Number()} instead
|
|
14
|
+
*/
|
|
15
|
+
export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/number.js
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
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
|
-
if (isDefined(options.maximum)) {
|
|
15
|
-
valueConstraints.push(new MaximumConstraint(options.maximum));
|
|
16
|
-
}
|
|
17
|
-
if (options.integer == true) {
|
|
18
|
-
valueConstraints.push(integerConstraint);
|
|
19
|
-
}
|
|
20
|
-
return valueSchema(Number, {
|
|
21
|
-
...options,
|
|
22
|
-
valueConstraints
|
|
23
|
-
});
|
|
24
23
|
}
|
|
24
|
+
export function number(options) {
|
|
25
|
+
return new NumberSchema(options);
|
|
26
|
+
}
|
|
27
|
+
export function Number(options) {
|
|
28
|
+
return Property(number(options), options);
|
|
29
|
+
}
|
|
30
|
+
export function Integer(options) {
|
|
31
|
+
return Property(number({ ...options, integer: true }), options);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated use {@link Number()} instead
|
|
35
|
+
*/
|
|
25
36
|
export function NumberProperty(options) {
|
|
26
|
-
return
|
|
37
|
+
return Number(options);
|
|
27
38
|
}
|
|
@@ -1,7 +1,75 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
|
|
1
|
+
import type { EmptyObject, Merge } from 'type-fest';
|
|
2
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
3
|
+
import type { AbstractConstructor, OneOrMany, PartialProperty, Record, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
4
|
+
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
6
|
+
export type ObjectSchemaFactory<T> = {
|
|
7
|
+
type: Type<T>;
|
|
8
|
+
} | ObjectSchemaFactoryFunction<T>;
|
|
9
|
+
export type ObjectSchemaProperties<T extends Record = Record> = {
|
|
10
|
+
[P in keyof T]-?: SchemaTestable<T[P]>;
|
|
11
|
+
};
|
|
12
|
+
export type NormalizedObjectSchemaProperties<T extends Record> = {
|
|
13
|
+
[P in keyof T]-?: Schema<T[P]>;
|
|
14
|
+
};
|
|
15
|
+
export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey = PropertyKey, V = unknown> = {
|
|
16
|
+
mask?: boolean | null;
|
|
17
|
+
unknownProperties?: SchemaTestable<V> | null;
|
|
18
|
+
unknownPropertiesKey?: SchemaTestable<K> | null;
|
|
19
|
+
factory?: ObjectSchemaFactory<T> | null;
|
|
20
|
+
};
|
|
21
|
+
export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
|
|
22
|
+
export declare const tryGetSchemaFromReflection: typeof _tryGetSchemaFromReflection;
|
|
23
|
+
export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
|
|
24
|
+
private readonly propertyKeys;
|
|
25
|
+
private readonly allowUnknownProperties;
|
|
26
|
+
readonly properties: NormalizedObjectSchemaProperties<T>;
|
|
27
|
+
readonly mask: boolean | null;
|
|
28
|
+
readonly unknownProperties: Schema | null;
|
|
29
|
+
readonly unknownPropertiesKey: Schema<PropertyKey> | null;
|
|
30
|
+
readonly factory: ObjectSchemaFactory<T> | null;
|
|
31
|
+
constructor(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>);
|
|
32
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
33
|
+
}
|
|
34
|
+
export declare function object<K extends PropertyKey, V>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, V>> & {
|
|
35
|
+
unknownProperties: SchemaTestable<V>;
|
|
36
|
+
unknownPropertiesKey: SchemaTestable<K>;
|
|
37
|
+
}): ObjectSchema<Record<K, V>>;
|
|
38
|
+
export declare function object<K extends PropertyKey>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, unknown>> & {
|
|
39
|
+
unknownProperties?: undefined;
|
|
40
|
+
unknownPropertiesKey: SchemaTestable<K>;
|
|
41
|
+
}): ObjectSchema<Record<K, unknown>>;
|
|
42
|
+
export declare function object<V>(properties: Record<never>, options: ObjectSchemaOptions<Record<PropertyKey, V>> & {
|
|
43
|
+
unknownProperties: SchemaTestable<V>;
|
|
44
|
+
unknownPropertiesKey?: undefined;
|
|
45
|
+
}): ObjectSchema<Record<PropertyKey, V>>;
|
|
46
|
+
export declare function object<T extends Record, K extends PropertyKey, V>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<K, V>> & {
|
|
47
|
+
unknownProperties: SchemaTestable<V>;
|
|
48
|
+
unknownPropertiesKey: SchemaTestable<K>;
|
|
49
|
+
}): ObjectSchema<SimplifyObject<T & Record<K, V>>>;
|
|
50
|
+
export declare function object<T extends Record, K extends PropertyKey>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<K, unknown>> & {
|
|
51
|
+
unknownPropertiesKey: SchemaTestable<K>;
|
|
52
|
+
}): ObjectSchema<SimplifyObject<T & Record<K, unknown>>>;
|
|
53
|
+
export declare function object<T extends Record, V>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<PropertyKey, V>> & {
|
|
54
|
+
unknownProperties: SchemaTestable<V>;
|
|
55
|
+
}): ObjectSchema<SimplifyObject<T & Record<PropertyKey, V>>>;
|
|
56
|
+
export declare function object<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T> & {
|
|
57
|
+
unknownProperties?: undefined;
|
|
58
|
+
unknownPropertiesKey?: undefined;
|
|
59
|
+
}): ObjectSchema<T>;
|
|
60
|
+
export declare function object<T extends Record, K extends PropertyKey, V>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T, K, V>): ObjectSchema<SimplifyObject<T & Record<K, V>>>;
|
|
61
|
+
export declare function explicitObject<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>): ObjectSchema<T>;
|
|
62
|
+
export declare function record<K extends PropertyKey, V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
|
|
63
|
+
export declare function assign<T1 extends Record, T2 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>): ObjectSchema<Merge<T1, T2>>;
|
|
64
|
+
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>): ObjectSchema<Merge<Merge<T1, T2>, T3>>;
|
|
65
|
+
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>>;
|
|
66
|
+
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>): ObjectSchema<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>>;
|
|
67
|
+
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record, T6 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>, f: ObjectSchemaOrType<T6>): ObjectSchema<Merge<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>, T6>>;
|
|
68
|
+
export declare function partial<T extends Record>(schema: ObjectSchema<T>): ObjectSchema<Partial<T>>;
|
|
69
|
+
export declare function partial<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<PartialProperty<T, K>>;
|
|
70
|
+
export declare function pick<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
71
|
+
export declare function omit<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
72
|
+
export declare function getSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T>;
|
|
73
|
+
declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | null;
|
|
74
|
+
export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
|
|
75
|
+
export {};
|