@tstdl/base 0.71.88 → 0.78.0-beta2
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/.eslintrc.js +2 -4
- package/api/client/client.js +2 -12
- package/api/client/client.js.map +1 -1
- package/api/default-error-handlers.d.ts +0 -4
- package/api/default-error-handlers.js +1 -6
- package/api/default-error-handlers.js.map +1 -1
- package/api/server/gateway.js +12 -18
- package/api/server/gateway.js.map +1 -1
- package/api/server/module.d.ts +0 -4
- package/api/server/module.js +1 -12
- package/api/server/module.js.map +1 -1
- package/api/types.d.ts +8 -32
- package/api/types.js.map +1 -1
- package/container/container.js +2 -2
- package/container/container.js.map +1 -1
- package/data-structures/index.d.ts +1 -0
- package/data-structures/index.js +1 -0
- package/data-structures/index.js.map +1 -1
- package/data-structures/iterable-weak-map.d.ts +29 -0
- package/data-structures/iterable-weak-map.js +128 -0
- package/data-structures/iterable-weak-map.js.map +1 -0
- package/data-structures/multi-key-map.d.ts +12 -1
- package/data-structures/multi-key-map.js +22 -11
- package/data-structures/multi-key-map.js.map +1 -1
- package/error/custom.error.d.ts +3 -1
- package/error/custom.error.js +16 -7
- package/error/custom.error.js.map +1 -1
- package/examples/api/basic-overview.js +16 -8
- package/examples/api/basic-overview.js.map +1 -1
- package/image-service/image-service.d.ts +32 -65
- package/image-service/image-service.js +73 -15
- package/image-service/image-service.js.map +1 -1
- package/json-path/json-path.d.ts +8 -3
- package/json-path/json-path.js +24 -7
- package/json-path/json-path.js.map +1 -1
- package/module/modules/index.d.ts +0 -1
- package/module/modules/index.js +0 -1
- package/module/modules/index.js.map +1 -1
- package/openid-connect/oidc-configuration.service.js +7 -7
- package/openid-connect/oidc-configuration.service.js.map +1 -1
- package/openid-connect/oidc.service.js +7 -7
- package/openid-connect/oidc.service.js.map +1 -1
- package/package.json +3 -4
- package/process-shutdown.js +3 -2
- package/process-shutdown.js.map +1 -1
- package/reflection/decorators.js +1 -0
- package/reflection/decorators.js.map +1 -1
- package/reflection/reflection-data-map.d.ts +10 -0
- package/reflection/reflection-data-map.js +40 -0
- package/reflection/reflection-data-map.js.map +1 -0
- package/reflection/registry.d.ts +7 -7
- package/reflection/registry.js +7 -6
- package/reflection/registry.js.map +1 -1
- package/reflection/types.d.ts +1 -0
- package/reflection/utils.d.ts +6 -3
- package/reflection/utils.js +9 -35
- package/reflection/utils.js.map +1 -1
- package/schema/array-constraints/index.d.ts +2 -0
- package/{old-api/validation/validators → schema/array-constraints}/index.js +2 -1
- package/schema/array-constraints/index.js.map +1 -0
- package/schema/array-constraints/maximum-length.d.ts +11 -0
- package/schema/array-constraints/maximum-length.js +26 -0
- package/schema/array-constraints/maximum-length.js.map +1 -0
- package/schema/array-constraints/minimum-length.d.ts +11 -0
- package/schema/array-constraints/minimum-length.js +26 -0
- package/schema/array-constraints/minimum-length.js.map +1 -0
- package/schema/coercers/boolean.coercer.d.ts +9 -0
- package/schema/coercers/boolean.coercer.js +35 -0
- package/schema/coercers/boolean.coercer.js.map +1 -0
- package/schema/coercers/date.coercer.d.ts +9 -0
- package/schema/coercers/date.coercer.js +24 -0
- package/schema/coercers/date.coercer.js.map +1 -0
- package/schema/coercers/default-value.coercer.d.ts +9 -0
- package/schema/coercers/default-value.coercer.js +16 -0
- package/schema/coercers/default-value.coercer.js.map +1 -0
- package/schema/coercers/index.d.ts +7 -0
- package/schema/coercers/index.js +24 -0
- package/schema/coercers/index.js.map +1 -0
- package/schema/coercers/number.coercer.d.ts +9 -0
- package/schema/coercers/number.coercer.js +22 -0
- package/schema/coercers/number.coercer.js.map +1 -0
- package/schema/coercers/regexp.coercer.d.ts +11 -0
- package/schema/coercers/regexp.coercer.js +24 -0
- package/schema/coercers/regexp.coercer.js.map +1 -0
- package/schema/coercers/string.coercer.d.ts +9 -0
- package/schema/coercers/string.coercer.js +22 -0
- package/schema/coercers/string.coercer.js.map +1 -0
- package/schema/coercers/uint8-array.coercer.d.ts +9 -0
- package/schema/coercers/uint8-array.coercer.js +31 -0
- package/schema/coercers/uint8-array.coercer.js.map +1 -0
- package/schema/constraints/enumeration.d.ts +13 -0
- package/schema/constraints/enumeration.js +29 -0
- package/schema/constraints/enumeration.js.map +1 -0
- package/schema/constraints/generic.d.ts +22 -0
- package/schema/constraints/generic.js +32 -0
- package/schema/constraints/generic.js.map +1 -0
- package/schema/constraints/index.d.ts +12 -0
- package/schema/constraints/index.js +29 -0
- package/schema/constraints/index.js.map +1 -0
- package/schema/constraints/integer.d.ts +12 -0
- package/schema/constraints/integer.js +27 -0
- package/schema/constraints/integer.js.map +1 -0
- package/schema/constraints/length.d.ts +6 -0
- package/schema/constraints/length.js +20 -0
- package/schema/constraints/length.js.map +1 -0
- package/schema/constraints/literal.d.ts +10 -0
- package/schema/constraints/literal.js +26 -0
- package/schema/constraints/literal.js.map +1 -0
- package/schema/constraints/maximum-date.d.ts +12 -0
- package/schema/constraints/maximum-date.js +29 -0
- package/schema/constraints/maximum-date.js.map +1 -0
- package/schema/constraints/maximum-length.d.ts +12 -0
- package/schema/constraints/maximum-length.js +29 -0
- package/schema/constraints/maximum-length.js.map +1 -0
- package/schema/constraints/maximum.d.ts +12 -0
- package/schema/constraints/maximum.js +27 -0
- package/schema/constraints/maximum.js.map +1 -0
- package/schema/constraints/minimum-date.d.ts +12 -0
- package/schema/constraints/minimum-date.js +29 -0
- package/schema/constraints/minimum-date.js.map +1 -0
- package/schema/constraints/minimum-length.d.ts +12 -0
- package/schema/constraints/minimum-length.js +29 -0
- package/schema/constraints/minimum-length.js.map +1 -0
- package/schema/constraints/minimum.d.ts +12 -0
- package/schema/constraints/minimum.js +27 -0
- package/schema/constraints/minimum.js.map +1 -0
- package/schema/constraints/pattern.d.ts +13 -0
- package/schema/constraints/pattern.js +28 -0
- package/schema/constraints/pattern.js.map +1 -0
- package/schema/decorators/array.d.ts +4 -0
- package/schema/decorators/array.js +11 -0
- package/schema/decorators/array.js.map +1 -0
- package/schema/decorators/coerce.d.ts +2 -0
- package/schema/decorators/coerce.js +10 -0
- package/schema/decorators/coerce.js.map +1 -0
- package/schema/decorators/defaulted.d.ts +3 -0
- package/schema/decorators/defaulted.js +11 -0
- package/schema/decorators/defaulted.js.map +1 -0
- package/schema/decorators/index.d.ts +8 -0
- package/{old-api → schema/decorators}/index.js +8 -3
- package/schema/decorators/index.js.map +1 -0
- package/schema/decorators/nullable.d.ts +2 -0
- package/schema/decorators/nullable.js +10 -0
- package/schema/decorators/nullable.js.map +1 -0
- package/schema/decorators/optional.d.ts +2 -0
- package/schema/decorators/optional.js +10 -0
- package/schema/decorators/optional.js.map +1 -0
- package/schema/decorators/property.d.ts +6 -0
- package/schema/decorators/property.js +19 -0
- package/schema/decorators/property.js.map +1 -0
- package/schema/decorators/type.d.ts +3 -0
- package/schema/decorators/type.js +10 -0
- package/schema/decorators/type.js.map +1 -0
- package/schema/decorators/types.d.ts +18 -0
- package/schema/decorators/types.js +3 -0
- package/schema/decorators/types.js.map +1 -0
- package/schema/decorators/utils.d.ts +10 -0
- package/schema/decorators/utils.js +59 -0
- package/schema/decorators/utils.js.map +1 -0
- package/schema/index.d.ts +7 -1
- package/schema/index.js +7 -1
- package/schema/index.js.map +1 -1
- package/schema/schema.d.ts +19 -0
- package/schema/schema.error.d.ts +13 -7
- package/schema/schema.error.js +45 -13
- package/schema/schema.error.js.map +1 -1
- package/schema/schema.js +286 -0
- package/schema/schema.js.map +1 -0
- package/schema/schemas/any.d.ts +4 -8
- package/schema/schemas/any.js +9 -14
- package/schema/schemas/any.js.map +1 -1
- package/schema/schemas/array.d.ts +7 -13
- package/schema/schemas/array.js +14 -43
- package/schema/schemas/array.js.map +1 -1
- package/schema/schemas/assign.d.ts +8 -0
- package/schema/schemas/assign.js +28 -0
- package/schema/schemas/assign.js.map +1 -0
- package/schema/schemas/boolean.d.ts +5 -9
- package/schema/schemas/boolean.js +11 -38
- package/schema/schemas/boolean.js.map +1 -1
- package/schema/schemas/constraint.d.ts +4 -0
- package/schema/schemas/constraint.js +14 -0
- package/schema/schemas/constraint.js.map +1 -0
- package/schema/schemas/date.d.ts +7 -11
- package/schema/schemas/date.js +18 -53
- package/schema/schemas/date.js.map +1 -1
- package/schema/schemas/defaulted.d.ts +2 -15
- package/schema/schemas/defaulted.js +7 -23
- package/schema/schemas/defaulted.js.map +1 -1
- package/schema/schemas/enumeration.d.ts +6 -18
- package/schema/schemas/enumeration.js +13 -50
- package/schema/schemas/enumeration.js.map +1 -1
- package/schema/schemas/exclude.d.ts +4 -0
- package/schema/schemas/exclude.js +17 -0
- package/schema/schemas/exclude.js.map +1 -0
- package/schema/schemas/index.d.ts +5 -6
- package/schema/schemas/index.js +5 -6
- package/schema/schemas/index.js.map +1 -1
- package/schema/schemas/instance.d.ts +2 -12
- package/schema/schemas/instance.js +4 -20
- package/schema/schemas/instance.js.map +1 -1
- package/schema/schemas/literal.d.ts +4 -11
- package/schema/schemas/literal.js +13 -18
- package/schema/schemas/literal.js.map +1 -1
- package/schema/schemas/nullable.d.ts +3 -13
- package/schema/schemas/nullable.js +3 -26
- package/schema/schemas/nullable.js.map +1 -1
- package/schema/schemas/number.d.ts +7 -14
- package/schema/schemas/number.js +23 -44
- package/schema/schemas/number.js.map +1 -1
- package/schema/schemas/object.d.ts +6 -34
- package/schema/schemas/object.js +8 -112
- package/schema/schemas/object.js.map +1 -1
- package/schema/schemas/optional.d.ts +3 -13
- package/schema/schemas/optional.js +3 -26
- package/schema/schemas/optional.js.map +1 -1
- package/schema/schemas/pick.d.ts +4 -0
- package/schema/schemas/pick.js +17 -0
- package/schema/schemas/pick.js.map +1 -0
- package/schema/schemas/readable-stream.d.ts +4 -9
- package/schema/schemas/readable-stream.js +9 -15
- package/schema/schemas/readable-stream.js.map +1 -1
- package/schema/schemas/record.d.ts +4 -0
- package/schema/schemas/record.js +14 -0
- package/schema/schemas/record.js.map +1 -0
- package/schema/schemas/regexp.d.ts +6 -9
- package/schema/schemas/regexp.js +10 -27
- package/schema/schemas/regexp.js.map +1 -1
- package/schema/schemas/string.d.ts +9 -13
- package/schema/schemas/string.js +34 -46
- package/schema/schemas/string.js.map +1 -1
- package/schema/schemas/transform.d.ts +4 -16
- package/schema/schemas/transform.js +7 -36
- package/schema/schemas/transform.js.map +1 -1
- package/schema/schemas/uint8-array.d.ts +8 -11
- package/schema/schemas/uint8-array.js +20 -32
- package/schema/schemas/uint8-array.js.map +1 -1
- package/schema/schemas/union.d.ts +5 -17
- package/schema/schemas/union.js +9 -35
- package/schema/schemas/union.js.map +1 -1
- package/schema/schemas/unknown.d.ts +4 -8
- package/schema/schemas/unknown.js +9 -14
- package/schema/schemas/unknown.js.map +1 -1
- package/schema/transformers/generic.d.ts +13 -0
- package/schema/transformers/generic.js +28 -0
- package/schema/transformers/generic.js.map +1 -0
- package/schema/transformers/index.d.ts +3 -0
- package/{old-api/endpoints → schema/transformers}/index.js +3 -1
- package/schema/transformers/index.js.map +1 -0
- package/schema/transformers/lowercase.d.ts +9 -0
- package/schema/transformers/lowercase.js +22 -0
- package/schema/transformers/lowercase.js.map +1 -0
- package/schema/transformers/trim.d.ts +9 -0
- package/schema/transformers/trim.js +22 -0
- package/schema/transformers/trim.js.map +1 -0
- package/schema/transformers/uppercase.d.ts +9 -0
- package/schema/transformers/uppercase.js +22 -0
- package/schema/transformers/uppercase.js.map +1 -0
- package/schema/types.d.ts +135 -15
- package/schema/types.js +39 -3
- package/schema/types.js.map +1 -1
- package/schema/utils/index.d.ts +2 -0
- package/{old-api/validation → schema/utils}/index.js +2 -1
- package/schema/utils/index.js.map +1 -0
- package/schema/utils/schema.d.ts +12 -0
- package/schema/utils/schema.js +78 -0
- package/schema/utils/schema.js.map +1 -0
- package/schema/utils/value-type.d.ts +4 -0
- package/schema/utils/value-type.js +35 -0
- package/schema/utils/value-type.js.map +1 -0
- package/templates/providers/file-template.provider.base.d.ts +1 -1
- package/templates/providers/file-template.provider.base.js +3 -2
- package/templates/providers/file-template.provider.base.js.map +1 -1
- package/types.d.ts +6 -3
- package/utils/enum.d.ts +1 -1
- package/utils/function/memoize.d.ts +6 -2
- package/utils/function/memoize.js +28 -20
- package/utils/function/memoize.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +1 -1
- package/utils/merge.d.ts +5 -0
- package/utils/merge.js +32 -0
- package/utils/merge.js.map +1 -0
- package/utils/object/dereference.js.map +1 -1
- package/utils/object/object.d.ts +4 -0
- package/utils/object/object.js +9 -2
- package/utils/object/object.js.map +1 -1
- package/utils/patterns.d.ts +1 -1
- package/utils/patterns.js +3 -3
- package/utils/patterns.js.map +1 -1
- package/utils/timing.d.ts +0 -8
- package/utils/timing.js.map +1 -1
- package/utils/type-guards.d.ts +6 -0
- package/utils/type-guards.js +16 -4
- package/utils/type-guards.js.map +1 -1
- package/instance-provider.d.ts +0 -17
- package/instance-provider.js +0 -55
- package/instance-provider.js.map +0 -1
- package/module/modules/old-web-server.module.d.ts +0 -22
- package/module/modules/old-web-server.module.js +0 -37
- package/module/modules/old-web-server.module.js.map +0 -1
- package/old-api/endpoint.d.ts +0 -5
- package/old-api/endpoint.js +0 -20
- package/old-api/endpoint.js.map +0 -1
- package/old-api/endpoints/echo.endpoint.d.ts +0 -2
- package/old-api/endpoints/echo.endpoint.js +0 -6
- package/old-api/endpoints/echo.endpoint.js.map +0 -1
- package/old-api/endpoints/index.d.ts +0 -1
- package/old-api/endpoints/index.js.map +0 -1
- package/old-api/http-api.d.ts +0 -63
- package/old-api/http-api.js +0 -269
- package/old-api/http-api.js.map +0 -1
- package/old-api/index.d.ts +0 -3
- package/old-api/index.js.map +0 -1
- package/old-api/validation/index.d.ts +0 -1
- package/old-api/validation/index.js.map +0 -1
- package/old-api/validation/types.d.ts +0 -6
- package/old-api/validation/types.js +0 -6
- package/old-api/validation/types.js.map +0 -1
- package/old-api/validation/validators/index.d.ts +0 -1
- package/old-api/validation/validators/index.js.map +0 -1
- package/old-api/validation/validators/noop.d.ts +0 -2
- package/old-api/validation/validators/noop.js +0 -8
- package/old-api/validation/validators/noop.js.map +0 -1
- package/old-api/validation/validators/superstruct.d.ts +0 -14
- package/old-api/validation/validators/superstruct.js +0 -66
- package/old-api/validation/validators/superstruct.js.map +0 -1
- package/old-api/validation/validators/yup.d.ts +0 -7
- package/old-api/validation/validators/yup.js +0 -60
- package/old-api/validation/validators/yup.js.map +0 -1
- package/schema/schema.validator.d.ts +0 -40
- package/schema/schema.validator.js +0 -75
- package/schema/schema.validator.js.map +0 -1
- package/schema/schemas/async-iterable.d.ts +0 -13
- package/schema/schemas/async-iterable.js +0 -40
- package/schema/schemas/async-iterable.js.map +0 -1
- package/schema/schemas/iterable.d.ts +0 -13
- package/schema/schemas/iterable.js +0 -40
- package/schema/schemas/iterable.js.map +0 -1
- package/schema/schemas/never.d.ts +0 -9
- package/schema/schemas/never.js +0 -22
- package/schema/schemas/never.js.map +0 -1
- package/schema/schemas/preprocess.d.ts +0 -16
- package/schema/schemas/preprocess.js +0 -35
- package/schema/schemas/preprocess.js.map +0 -1
- package/schema/schemas/refine.d.ts +0 -24
- package/schema/schemas/refine.js +0 -52
- package/schema/schemas/refine.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/schema/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,0CAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/schema/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,yCAAuB;AACvB,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,yCAAuB;AACvB,oDAAkC;AAClC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B"}
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { DefinedValidationOptions, ValidationTestResult } from '../schema.validator';
|
|
4
|
-
import { SchemaValidator, test } from '../schema.validator';
|
|
5
|
-
import type { SchemaDefinition, SchemaOptions, SchemaOutput } from '../types';
|
|
6
|
-
export declare type InstanceSchemaDefinition<T = unknown> = SchemaDefinition<'instance', T, T> & {
|
|
7
|
-
constructor: Type<T>;
|
|
8
|
-
};
|
|
9
|
-
export declare class InstanceSchemaValidator<T> extends SchemaValidator<InstanceSchemaDefinition<T>> {
|
|
10
|
-
[test](value: unknown, _options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<InstanceSchemaDefinition<T>>>;
|
|
11
|
-
}
|
|
12
|
-
export declare function instance<T>(constructor: Type<T>, options?: SchemaOptions<InstanceSchemaDefinition<T>, 'constructor'>): InstanceSchemaValidator<T>;
|
|
1
|
+
import type { ValueSchema, ValueType } from '../types';
|
|
2
|
+
export declare function instance<T>(type: Extract<ValueType<T>, Function>): ValueSchema<T>;
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instance =
|
|
4
|
-
const type_of_1 = require("../../utils/type-of");
|
|
5
|
-
const schema_error_1 = require("../schema.error");
|
|
6
|
-
const schema_validator_1 = require("../schema.validator");
|
|
4
|
+
exports.instance = void 0;
|
|
7
5
|
const types_1 = require("../types");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (value instanceof this.schema.constructor) {
|
|
11
|
-
return { valid: true, value: value };
|
|
12
|
-
}
|
|
13
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(`instance of ${this.schema.constructor.name}`, (0, type_of_1.typeOf)(value), path) };
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.InstanceSchemaValidator = InstanceSchemaValidator;
|
|
17
|
-
function instance(constructor, options) {
|
|
18
|
-
const schema = (0, types_1.schemaHelper)({
|
|
19
|
-
type: 'instance',
|
|
20
|
-
constructor,
|
|
21
|
-
...options
|
|
22
|
-
});
|
|
23
|
-
return new InstanceSchemaValidator(schema);
|
|
6
|
+
function instance(type) {
|
|
7
|
+
return (0, types_1.valueSchema)({ type });
|
|
24
8
|
}
|
|
25
9
|
exports.instance = instance;
|
|
26
10
|
//# sourceMappingURL=instance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../source/schema/schemas/instance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../source/schema/schemas/instance.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAGjD,oCAAuC;AAEvC,SAAgB,QAAQ,CAAI,IAAqC;IAC/D,OAAO,IAAA,mBAAW,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/B,CAAC;AAFD,4BAEC"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare type LiteralSchemaDefinition<T> = SchemaDefinition<'literal', T, T> & {
|
|
6
|
-
value: T;
|
|
7
|
-
};
|
|
8
|
-
export declare class LiteralSchemaValidator<T> extends SchemaValidator<LiteralSchemaDefinition<T>> {
|
|
9
|
-
[test](value: unknown, _options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<LiteralSchemaDefinition<T>>>;
|
|
10
|
-
}
|
|
11
|
-
export declare function literal<T>(value: T, options?: SchemaOptions<LiteralSchemaDefinition<T>, 'value'>): LiteralSchemaValidator<T>;
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { ValueSchema } from '../types';
|
|
3
|
+
export declare function literal<T>(value: T): ValueSchema<T>;
|
|
4
|
+
export declare function Literal(value: any): Decorator<'property' | 'accessor'>;
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
exports.Literal = exports.literal = void 0;
|
|
5
|
+
const constraints_1 = require("../constraints");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
6
7
|
const types_1 = require("../types");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(String(this.schema.value), String(value), path) };
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.LiteralSchemaValidator = LiteralSchemaValidator;
|
|
16
|
-
function literal(value, options) {
|
|
17
|
-
const schema = (0, types_1.schemaHelper)({
|
|
18
|
-
type: 'literal',
|
|
19
|
-
value,
|
|
20
|
-
...options
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
function literal(value) {
|
|
10
|
+
return (0, types_1.valueSchema)({
|
|
11
|
+
type: (0, utils_1.getValueType)(value),
|
|
12
|
+
valueConstraints: new constraints_1.LiteralConstraint(value)
|
|
21
13
|
});
|
|
22
|
-
return new LiteralSchemaValidator(schema);
|
|
23
14
|
}
|
|
24
15
|
exports.literal = literal;
|
|
16
|
+
function Literal(value) {
|
|
17
|
+
return (0, decorators_1.createSchemaPropertyDecoratorFromValueType)(literal(value));
|
|
18
|
+
}
|
|
19
|
+
exports.Literal = Literal;
|
|
25
20
|
//# sourceMappingURL=literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../source/schema/schemas/literal.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../source/schema/schemas/literal.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,gDAAmD;AACnD,8CAA2E;AAE3E,oCAAuC;AACvC,oCAAwC;AAExC,SAAgB,OAAO,CAAI,KAAQ;IACjC,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,IAAA,oBAAY,EAAC,KAAK,CAAC;QACzB,gBAAgB,EAAE,IAAI,+BAAiB,CAAC,KAAK,CAAC;KAC/C,CAAC,CAAC;AACL,CAAC;AALD,0BAKC;AAED,SAAgB,OAAO,CAAC,KAAU;IAChC,OAAO,IAAA,uDAA0C,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,CAAC;AAFD,0BAEC"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import type { Coercible, SchemaDefinition, SchemaInput, SchemaOptions, SchemaOutput } from '../types';
|
|
5
|
-
export declare type NullableSchemaDefinition<T extends SchemaDefinition = SchemaDefinition> = SchemaDefinition<'nullable', SchemaInput<T> | null, SchemaOutput<T> | null> & Coercible & {
|
|
6
|
-
schema: T;
|
|
7
|
-
};
|
|
8
|
-
export declare class NullableSchemaValidator<T extends SchemaDefinition> extends SchemaValidator<NullableSchemaDefinition<T>> {
|
|
9
|
-
private readonly innerValidator;
|
|
10
|
-
constructor(innerValidator: SchemaValidator<T>, schema: NullableSchemaDefinition<T>);
|
|
11
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<NullableSchemaDefinition<T>>>;
|
|
12
|
-
}
|
|
13
|
-
export declare function nullable<T extends SchemaDefinition>(innerValidator: SchemaValidator<T>, options?: SchemaOptions<NullableSchemaDefinition<T>, 'schema'>): NullableSchemaValidator<T>;
|
|
1
|
+
import type { Schema } from '../schema';
|
|
2
|
+
import type { ValueSchema } from '../types';
|
|
3
|
+
export declare function nullable<T>(schema: Schema<T>): ValueSchema<T | null>;
|
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nullable =
|
|
4
|
-
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
-
const schema_validator_1 = require("../schema.validator");
|
|
3
|
+
exports.nullable = void 0;
|
|
6
4
|
const types_1 = require("../types");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
super(schema);
|
|
10
|
-
this.innerValidator = innerValidator;
|
|
11
|
-
}
|
|
12
|
-
[schema_validator_1.test](value, options, path) {
|
|
13
|
-
if ((0, type_guards_1.isNull)(value)) {
|
|
14
|
-
return { valid: true, value };
|
|
15
|
-
}
|
|
16
|
-
if ((this.schema.coerce ?? options.coerce) && (0, type_guards_1.isUndefined)(value)) {
|
|
17
|
-
return { valid: true, value: null };
|
|
18
|
-
}
|
|
19
|
-
return this.innerValidator[schema_validator_1.test](value, options, path);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.NullableSchemaValidator = NullableSchemaValidator;
|
|
23
|
-
function nullable(innerValidator, options) {
|
|
24
|
-
const schema = (0, types_1.schemaHelper)({
|
|
25
|
-
type: 'nullable',
|
|
26
|
-
schema: innerValidator.schema,
|
|
27
|
-
...options
|
|
28
|
-
});
|
|
29
|
-
return new NullableSchemaValidator(innerValidator, schema);
|
|
5
|
+
function nullable(schema) {
|
|
6
|
+
return (0, types_1.valueSchema)({ type: schema, nullable: true });
|
|
30
7
|
}
|
|
31
8
|
exports.nullable = nullable;
|
|
32
9
|
//# sourceMappingURL=nullable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../source/schema/schemas/nullable.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../source/schema/schemas/nullable.ts"],"names":[],"mappings":";;;AAEA,oCAAuC;AAEvC,SAAgB,QAAQ,CAAI,MAAiB;IAC3C,OAAO,IAAA,mBAAW,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC;AAFD,4BAEC"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** integer */
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { Coercible, ValueSchema } from '../types';
|
|
3
|
+
export declare type NumberOptions = Coercible & {
|
|
4
|
+
minimum?: number;
|
|
5
|
+
maximum?: number;
|
|
7
6
|
integer?: boolean;
|
|
8
|
-
/** min */
|
|
9
|
-
min?: number;
|
|
10
|
-
/** max */
|
|
11
|
-
max?: number;
|
|
12
7
|
};
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export declare function number(options?: SchemaOptions<NumberSchemaDefinition>): NumberSchemaValidator;
|
|
8
|
+
export declare function number(options?: NumberOptions): ValueSchema<number>;
|
|
9
|
+
export declare function Number(options?: NumberOptions): Decorator<'property' | 'accessor'>;
|
package/schema/schemas/number.js
CHANGED
|
@@ -1,54 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const patterns_1 = require("../../utils/patterns");
|
|
4
|
+
exports.Number = exports.number = void 0;
|
|
5
5
|
const type_guards_1 = require("../../utils/type-guards");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const integer_1 = require("../constraints/integer");
|
|
7
|
+
const maximum_1 = require("../constraints/maximum");
|
|
8
|
+
const minimum_1 = require("../constraints/minimum");
|
|
9
|
+
const decorators_1 = require("../decorators");
|
|
8
10
|
const types_1 = require("../types");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!isNumberString || Number.isNaN(numberValue)) {
|
|
14
|
-
return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid format', path) };
|
|
15
|
-
}
|
|
16
|
-
return { valid: true, value: numberValue };
|
|
17
|
-
},
|
|
18
|
-
boolean: (boolean) => ({ valid: true, value: Number(boolean) }),
|
|
19
|
-
bigint: (bigint, path) => {
|
|
20
|
-
const numberValue = Number(bigint);
|
|
21
|
-
if (!Number.isFinite(numberValue)) {
|
|
22
|
-
return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'bigint', 'value out of bounds', path) };
|
|
23
|
-
}
|
|
24
|
-
return { valid: true, value: numberValue };
|
|
11
|
+
function number(options = {}) {
|
|
12
|
+
const constraints = [];
|
|
13
|
+
if ((0, type_guards_1.isDefined)(options.minimum)) {
|
|
14
|
+
constraints.push(new minimum_1.MinimumConstraint(options.minimum));
|
|
25
15
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
[schema_validator_1.test](value, options, path) {
|
|
29
|
-
const result = super.ensureType('number', value, path, { coerce: this.schema.coerce ?? options.coerce }, coercerMap);
|
|
30
|
-
if (!result.valid) {
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
if ((this.schema.integer == true) && !Number.isInteger(result.value)) {
|
|
34
|
-
return { valid: false, error: (0, schema_error_1.schemaError)('expected integer', path) };
|
|
35
|
-
}
|
|
36
|
-
if ((0, type_guards_1.isDefined)(this.schema.min) && (result.value < this.schema.min)) {
|
|
37
|
-
return { valid: false, error: (0, schema_error_1.schemaError)(`minimum valid value is ${this.schema.min}`, path) };
|
|
38
|
-
}
|
|
39
|
-
if ((0, type_guards_1.isDefined)(this.schema.max) && (result.value > this.schema.max)) {
|
|
40
|
-
return { valid: false, error: (0, schema_error_1.schemaError)(`maximum valid value is ${this.schema.max}`, path) };
|
|
41
|
-
}
|
|
42
|
-
return { valid: true, value: result.value };
|
|
16
|
+
if ((0, type_guards_1.isDefined)(options.maximum)) {
|
|
17
|
+
constraints.push(new maximum_1.MaximumConstraint(options.maximum));
|
|
43
18
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
type:
|
|
49
|
-
|
|
19
|
+
if (options.integer == true) {
|
|
20
|
+
constraints.push(integer_1.integerConstraint);
|
|
21
|
+
}
|
|
22
|
+
return (0, types_1.valueSchema)({
|
|
23
|
+
type: globalThis.Number,
|
|
24
|
+
coerce: options.coerce,
|
|
25
|
+
valueConstraints: constraints
|
|
50
26
|
});
|
|
51
|
-
return new NumberSchemaValidator(schema);
|
|
52
27
|
}
|
|
53
28
|
exports.number = number;
|
|
29
|
+
function Number(options) {
|
|
30
|
+
return (0, decorators_1.createSchemaPropertyDecoratorFromValueType)(number(options));
|
|
31
|
+
}
|
|
32
|
+
exports.Number = Number;
|
|
54
33
|
//# sourceMappingURL=number.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../source/schema/schemas/number.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../source/schema/schemas/number.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,yDAAgD;AAChD,oDAA2D;AAC3D,oDAA2D;AAC3D,oDAA2D;AAC3D,8CAA2E;AAE3E,oCAAuC;AAQvC,SAAgB,MAAM,CAAC,UAAyB,EAAE;IAChD,MAAM,WAAW,GAA4B,EAAE,CAAC;IAEhD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,2BAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC1D;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,2BAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC1D;IAED,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,EAAE;QAC3B,WAAW,CAAC,IAAI,CAAC,2BAAiB,CAAC,CAAC;KACrC;IAED,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,UAAU,CAAC,MAAM;QACvB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AApBD,wBAoBC;AAED,SAAgB,MAAM,CAAC,OAAuB;IAC5C,OAAO,IAAA,uDAA0C,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC;AAFD,wBAEC"}
|
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare type ObjectOutputType<T extends StringMap<SchemaDefinition>> = Simplify<Optionalize<{
|
|
8
|
-
[P in keyof T]: SchemaOutput<T[P]>;
|
|
9
|
-
}>>;
|
|
10
|
-
export declare type ObjectSchemaValidatorEntries<T extends StringMap<SchemaDefinition>> = {
|
|
11
|
-
[P in keyof T]: SchemaValidator<T[P]>;
|
|
12
|
-
};
|
|
13
|
-
export declare type ObjectSchemaDefinition<T extends StringMap<SchemaDefinition> = StringMap<SchemaDefinition>> = SchemaDefinition<'object', unknown, ObjectOutputType<T>> & Maskable & {
|
|
14
|
-
entries: T;
|
|
15
|
-
/** Keep unknown properties instead of raising an error. This overwrites mask. */
|
|
16
|
-
keepUnknown?: boolean;
|
|
17
|
-
};
|
|
18
|
-
export declare type ObjectAssign<A extends StringMap<SchemaDefinition>, B extends StringMap<SchemaDefinition>> = SimplifyObject<B & Omit<A, keyof B>>;
|
|
19
|
-
export declare type ObjectPick<T extends StringMap<SchemaDefinition>, K extends keyof T> = SimplifyObject<Pick<T, K>>;
|
|
20
|
-
export declare type ObjectExclude<T extends StringMap<SchemaDefinition>, K extends keyof T> = SimplifyObject<Omit<T, K>>;
|
|
21
|
-
export declare class ObjectSchemaValidator<T extends StringMap<SchemaDefinition>> extends SchemaValidator<ObjectSchemaDefinition<T>> {
|
|
22
|
-
private readonly validatorEntries;
|
|
23
|
-
constructor(validators: ObjectSchemaValidatorEntries<T>, schema: ObjectSchemaDefinition<T>);
|
|
24
|
-
static assign<A extends StringMap<SchemaDefinition>, B extends StringMap<SchemaDefinition>>(a: ObjectSchemaValidator<A>, b: ObjectSchemaValidator<B>): ObjectSchemaValidator<ObjectAssign<A, B>>;
|
|
25
|
-
static pick<T extends StringMap<SchemaDefinition>, K extends keyof T>(objectSchema: ObjectSchemaValidator<T>, keys: OneOrMany<K>): ObjectSchemaValidator<ObjectPick<T, K>>;
|
|
26
|
-
static exclude<T extends StringMap<SchemaDefinition>, K extends keyof T>(objectSchema: ObjectSchemaValidator<T>, keys: OneOrMany<K>): ObjectSchemaValidator<ObjectExclude<T, K>>;
|
|
27
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<ObjectOutputType<T>>;
|
|
28
|
-
[testAsync](value: unknown, options: DefinedValidationOptions, path: JsonPath): Promise<ValidationTestResult<ObjectOutputType<T>>>;
|
|
29
|
-
private _testBase;
|
|
30
|
-
}
|
|
31
|
-
export declare function object<T extends StringMap<SchemaDefinition>>(entries: ObjectSchemaValidatorEntries<T>, options?: SchemaOptions<ObjectSchemaDefinition<T>, 'entries'>): ObjectSchemaValidator<T>;
|
|
32
|
-
export declare function assign<A extends StringMap<SchemaDefinition>, B extends StringMap<SchemaDefinition>>(a: ObjectSchemaValidator<A>, b: ObjectSchemaValidator<B>): ObjectSchemaValidator<ObjectAssign<A, B>>;
|
|
33
|
-
export declare function pick<T extends StringMap<SchemaDefinition>, K extends keyof T>(objectSchema: ObjectSchemaValidator<T>, keys: OneOrMany<K>): ObjectSchemaValidator<ObjectPick<T, K>>;
|
|
34
|
-
export declare function exclude<T extends StringMap<SchemaDefinition>, K extends keyof T>(objectSchema: ObjectSchemaValidator<T>, keys: OneOrMany<K>): ObjectSchemaValidator<ObjectExclude<T, K>>;
|
|
1
|
+
import type { Record, TypedOmit } from "../../types";
|
|
2
|
+
import type { PartialOnUndefinedDeep } from 'type-fest';
|
|
3
|
+
import type { ObjectSchema, ObjectSchemaProperties } from '../types';
|
|
4
|
+
export declare type ObjectOptions<T extends Record = Record> = TypedOmit<ObjectSchema<T>, 'properties'>;
|
|
5
|
+
export declare function explicitObject<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T>): ObjectSchema<T>;
|
|
6
|
+
export declare function object<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T>): ObjectSchema<PartialOnUndefinedDeep<T>>;
|
package/schema/schemas/object.js
CHANGED
|
@@ -1,121 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const array_1 = require("../../utils/array/array");
|
|
5
|
-
const map_1 = require("../../utils/map");
|
|
6
|
-
const object_1 = require("../../utils/object/object");
|
|
7
|
-
const type_guards_1 = require("../../utils/type-guards");
|
|
8
|
-
const schema_error_1 = require("../schema.error");
|
|
9
|
-
const schema_validator_1 = require("../schema.validator");
|
|
4
|
+
exports.object = exports.explicitObject = void 0;
|
|
10
5
|
const types_1 = require("../types");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
super(schema);
|
|
14
|
-
this.validatorEntries = new Map((0, object_1.objectEntries)(validators));
|
|
15
|
-
}
|
|
16
|
-
static assign(a, b) {
|
|
17
|
-
const validatorEntries = Object.fromEntries([...a.validatorEntries, ...b.validatorEntries]);
|
|
18
|
-
const schema = {
|
|
19
|
-
type: 'object',
|
|
20
|
-
entries: { ...a.schema.entries, ...b.schema.entries }
|
|
21
|
-
};
|
|
22
|
-
return new ObjectSchemaValidator(validatorEntries, schema);
|
|
23
|
-
}
|
|
24
|
-
static pick(objectSchema, keys) {
|
|
25
|
-
const keysArray = (0, array_1.toArray)(keys);
|
|
26
|
-
const validatorEntries = Object.fromEntries([...objectSchema.validatorEntries].filter(([key]) => keysArray.includes(key)));
|
|
27
|
-
const schema = {
|
|
28
|
-
type: 'object',
|
|
29
|
-
entries: Object.fromEntries([...Object.entries(objectSchema.schema.entries)].filter(([key]) => keysArray.includes(key)))
|
|
30
|
-
};
|
|
31
|
-
return new ObjectSchemaValidator(validatorEntries, schema);
|
|
32
|
-
}
|
|
33
|
-
static exclude(objectSchema, keys) {
|
|
34
|
-
const keysArray = (0, array_1.toArray)(keys);
|
|
35
|
-
const validatorEntries = Object.fromEntries([...objectSchema.validatorEntries].filter(([key]) => !keysArray.includes(key)));
|
|
36
|
-
const schema = {
|
|
37
|
-
type: 'object',
|
|
38
|
-
entries: Object.fromEntries([...Object.entries(objectSchema.schema.entries)].filter(([key]) => !keysArray.includes(key)))
|
|
39
|
-
};
|
|
40
|
-
return new ObjectSchemaValidator(validatorEntries, schema);
|
|
41
|
-
}
|
|
42
|
-
[schema_validator_1.test](value, options, path) {
|
|
43
|
-
const testBaseResult = this._testBase(value, options, path);
|
|
44
|
-
if (!testBaseResult.valid) {
|
|
45
|
-
return testBaseResult;
|
|
46
|
-
}
|
|
47
|
-
let resultObject = {};
|
|
48
|
-
for (const [key, validator] of this.validatorEntries) {
|
|
49
|
-
const innerValue = testBaseResult.value.get(key);
|
|
50
|
-
const innerValueValidationTestResult = validator[schema_validator_1.test](innerValue, options, path.add(key));
|
|
51
|
-
if (!innerValueValidationTestResult.valid) {
|
|
52
|
-
return innerValueValidationTestResult;
|
|
53
|
-
}
|
|
54
|
-
resultObject[key] = innerValueValidationTestResult.value;
|
|
55
|
-
}
|
|
56
|
-
if (this.schema.keepUnknown == true) {
|
|
57
|
-
resultObject = { ...value, ...resultObject };
|
|
58
|
-
}
|
|
59
|
-
return { valid: true, value: resultObject };
|
|
60
|
-
}
|
|
61
|
-
async [schema_validator_1.testAsync](value, options, path) {
|
|
62
|
-
const testBaseResult = this._testBase(value, options, path);
|
|
63
|
-
if (!testBaseResult.valid) {
|
|
64
|
-
return testBaseResult;
|
|
65
|
-
}
|
|
66
|
-
let resultObject = {};
|
|
67
|
-
for (const [key, validator] of this.validatorEntries) {
|
|
68
|
-
const innerValue = testBaseResult.value.get(key);
|
|
69
|
-
const innerValueValidationTestResult = await validator[schema_validator_1.testAsync](innerValue, options, path.add(key));
|
|
70
|
-
if (!innerValueValidationTestResult.valid) {
|
|
71
|
-
return innerValueValidationTestResult;
|
|
72
|
-
}
|
|
73
|
-
resultObject[key] = innerValueValidationTestResult.value;
|
|
74
|
-
}
|
|
75
|
-
if (this.schema.keepUnknown == true) {
|
|
76
|
-
resultObject = { ...value, ...resultObject };
|
|
77
|
-
}
|
|
78
|
-
return { valid: true, value: resultObject };
|
|
79
|
-
}
|
|
80
|
-
_testBase(value, options, path) {
|
|
81
|
-
const typeResult = this.ensureType('object', value, path);
|
|
82
|
-
if (!typeResult.valid) {
|
|
83
|
-
return typeResult;
|
|
84
|
-
}
|
|
85
|
-
else if (value === null) {
|
|
86
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot('object', 'null', path) };
|
|
87
|
-
}
|
|
88
|
-
const valueEntries = new Map((0, object_1.objectEntries)(value));
|
|
89
|
-
const unknownKeys = (0, map_1.differenceMaps)(valueEntries, this.validatorEntries);
|
|
90
|
-
if ((unknownKeys.length > 0) && (this.schema.mask != true) && ((0, type_guards_1.isBoolean)(this.schema.mask) || !options.mask) && (this.schema.keepUnknown != true)) {
|
|
91
|
-
const keys = unknownKeys.map((entry) => entry[0]).join(', ');
|
|
92
|
-
return { valid: false, error: (0, schema_error_1.schemaError)(`unexpected keys in object: ${keys}`, path) };
|
|
93
|
-
}
|
|
94
|
-
return { valid: true, value: valueEntries };
|
|
95
|
-
}
|
|
6
|
+
function explicitObject(properties, options) {
|
|
7
|
+
return object(properties, options);
|
|
96
8
|
}
|
|
97
|
-
exports.
|
|
98
|
-
function object(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const schema = (0, types_1.schemaHelper)({
|
|
102
|
-
type: 'object',
|
|
103
|
-
entries: Object.fromEntries(mappedValidatorEntries),
|
|
9
|
+
exports.explicitObject = explicitObject;
|
|
10
|
+
function object(properties, options) {
|
|
11
|
+
return (0, types_1.objectSchema)({
|
|
12
|
+
properties,
|
|
104
13
|
...options
|
|
105
14
|
});
|
|
106
|
-
return new ObjectSchemaValidator(entries, schema);
|
|
107
15
|
}
|
|
108
16
|
exports.object = object;
|
|
109
|
-
function assign(a, b) {
|
|
110
|
-
return ObjectSchemaValidator.assign(a, b);
|
|
111
|
-
}
|
|
112
|
-
exports.assign = assign;
|
|
113
|
-
function pick(objectSchema, keys) {
|
|
114
|
-
return ObjectSchemaValidator.pick(objectSchema, keys);
|
|
115
|
-
}
|
|
116
|
-
exports.pick = pick;
|
|
117
|
-
function exclude(objectSchema, keys) {
|
|
118
|
-
return ObjectSchemaValidator.exclude(objectSchema, keys);
|
|
119
|
-
}
|
|
120
|
-
exports.exclude = exclude;
|
|
121
17
|
//# sourceMappingURL=object.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../source/schema/schemas/object.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../source/schema/schemas/object.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAKzD,oCAAwC;AAIxC,SAAgB,cAAc,CAAmB,UAAqC,EAAE,OAA0B;IAChH,OAAO,MAAM,CAAC,UAAU,EAAE,OAAO,CAA2B,CAAC;AAC/D,CAAC;AAFD,wCAEC;AAED,SAAgB,MAAM,CAAmB,UAAqC,EAAE,OAA0B;IACxG,OAAO,IAAA,oBAAY,EAAC;QAClB,UAAU;QACV,GAAG,OAAO;KACX,CAA4C,CAAC;AAChD,CAAC;AALD,wBAKC"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import type { Coercible, SchemaDefinition, SchemaInput, SchemaOptions, SchemaOutput } from '../types';
|
|
5
|
-
export declare type OptionalSchemaDefinition<T extends SchemaDefinition = SchemaDefinition> = SchemaDefinition<'optional', SchemaInput<T> | undefined, SchemaOutput<T> | undefined> & Coercible & {
|
|
6
|
-
schema: T;
|
|
7
|
-
};
|
|
8
|
-
export declare class OptionalSchemaValidator<T extends SchemaDefinition> extends SchemaValidator<OptionalSchemaDefinition<T>> {
|
|
9
|
-
private readonly innerValidator;
|
|
10
|
-
constructor(innerValidator: SchemaValidator<T>, schema: OptionalSchemaDefinition<T>);
|
|
11
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<OptionalSchemaDefinition<T>>>;
|
|
12
|
-
}
|
|
13
|
-
export declare function optional<T extends SchemaDefinition>(innerValidator: SchemaValidator<T>, options?: SchemaOptions<OptionalSchemaDefinition<T>, 'schema'>): OptionalSchemaValidator<T>;
|
|
1
|
+
import type { Schema } from '../schema';
|
|
2
|
+
import type { ValueSchema } from '../types';
|
|
3
|
+
export declare function optional<T>(schema: Schema<T>): ValueSchema<T | undefined>;
|
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optional =
|
|
4
|
-
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
-
const schema_validator_1 = require("../schema.validator");
|
|
3
|
+
exports.optional = void 0;
|
|
6
4
|
const types_1 = require("../types");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
super(schema);
|
|
10
|
-
this.innerValidator = innerValidator;
|
|
11
|
-
}
|
|
12
|
-
[schema_validator_1.test](value, options, path) {
|
|
13
|
-
if ((0, type_guards_1.isUndefined)(value)) {
|
|
14
|
-
return { valid: true, value };
|
|
15
|
-
}
|
|
16
|
-
if ((this.schema.coerce ?? options.coerce) && (0, type_guards_1.isNull)(value)) {
|
|
17
|
-
return { valid: true, value: undefined };
|
|
18
|
-
}
|
|
19
|
-
return this.innerValidator[schema_validator_1.test](value, options, path);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.OptionalSchemaValidator = OptionalSchemaValidator;
|
|
23
|
-
function optional(innerValidator, options) {
|
|
24
|
-
const schema = (0, types_1.schemaHelper)({
|
|
25
|
-
type: 'optional',
|
|
26
|
-
schema: innerValidator.schema,
|
|
27
|
-
...options
|
|
28
|
-
});
|
|
29
|
-
return new OptionalSchemaValidator(innerValidator, schema);
|
|
5
|
+
function optional(schema) {
|
|
6
|
+
return (0, types_1.valueSchema)({ type: schema, optional: true });
|
|
30
7
|
}
|
|
31
8
|
exports.optional = optional;
|
|
32
9
|
//# sourceMappingURL=optional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/schemas/optional.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/schemas/optional.ts"],"names":[],"mappings":";;;AAEA,oCAAuC;AAEvC,SAAgB,QAAQ,CAAI,MAAiB;IAC3C,OAAO,IAAA,mBAAW,EAAC,EAAE,IAAI,EAAE,MAA+B,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAChF,CAAC;AAFD,4BAEC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OneOrMany, Record } from "../../types";
|
|
2
|
+
import type { Simplify } from 'type-fest';
|
|
3
|
+
import type { ObjectSchema } from '../types';
|
|
4
|
+
export declare function pick<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, key: OneOrMany<K>): ObjectSchema<Simplify<Pick<T, K>>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pick = void 0;
|
|
4
|
+
const array_1 = require("../../utils/array/array");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
function pick(schema, key) {
|
|
7
|
+
const keys = (0, array_1.toArray)(key);
|
|
8
|
+
const entries = Object.entries(schema.properties);
|
|
9
|
+
const pickedEntries = entries.filter(([propertyKey]) => keys.includes(propertyKey));
|
|
10
|
+
const pickedSchema = (0, types_1.objectSchema)({
|
|
11
|
+
...schema,
|
|
12
|
+
properties: Object.fromEntries(pickedEntries)
|
|
13
|
+
});
|
|
14
|
+
return pickedSchema;
|
|
15
|
+
}
|
|
16
|
+
exports.pick = pick;
|
|
17
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../source/schema/schemas/pick.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAG9C,oCAAwC;AAExC,SAAgB,IAAI,CAAsC,MAAuB,EAAE,GAAiB;IAClG,MAAM,IAAI,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;IAE1B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAgB,CAAC,CAAC,CAAC;IAEzF,MAAM,YAAY,GAAG,IAAA,oBAAY,EAAC;QAChC,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAAe;KAC5D,CAAC,CAAC;IAEH,OAAO,YAAwC,CAAC;AAClD,CAAC;AAZD,oBAYC"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare type ReadableStreamSchemaDefinition = SchemaDefinition<'readableStream', unknown, ReadableStream>;
|
|
6
|
-
export declare class ReadableStreamSchemaValidator extends SchemaValidator<ReadableStreamSchemaDefinition> {
|
|
7
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<ReadableStreamSchemaDefinition>>;
|
|
8
|
-
}
|
|
9
|
-
export declare function readableStream(options?: SchemaOptions<ReadableStreamSchemaDefinition>): ReadableStreamSchemaValidator;
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { ValueSchema } from '../types';
|
|
3
|
+
export declare function readableStream(): ValueSchema<globalThis.ReadableStream>;
|
|
4
|
+
export declare function ReadableStream(): Decorator<'property' | 'accessor'>;
|