@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
package/schema/schemas/array.js
CHANGED
|
@@ -1,53 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.array =
|
|
4
|
+
exports.array = void 0;
|
|
4
5
|
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
-
const
|
|
6
|
-
const schema_error_1 = require("../schema.error");
|
|
7
|
-
const schema_validator_1 = require("../schema.validator");
|
|
6
|
+
const array_constraints_1 = require("../array-constraints");
|
|
8
7
|
const types_1 = require("../types");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
function array(innerValues, options = {}) {
|
|
9
|
+
const arrayConstraints = [];
|
|
10
|
+
if ((0, type_guards_1.isDefined)(options.minimumLength)) {
|
|
11
|
+
arrayConstraints.push(new array_constraints_1.ArrayMaximumLengthConstraint(options.minimumLength));
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot('array', (0, type_of_1.typeOf)(value), path) };
|
|
17
|
-
}
|
|
18
|
-
const validatedArray = [];
|
|
19
|
-
for (let i = 0; i < value.length; i++) {
|
|
20
|
-
const innerTestResult = this.innerValidator[schema_validator_1.test](value[i], options, path.add(i));
|
|
21
|
-
if (!innerTestResult.valid) {
|
|
22
|
-
return innerTestResult;
|
|
23
|
-
}
|
|
24
|
-
validatedArray.push(innerTestResult.value);
|
|
25
|
-
}
|
|
26
|
-
return { valid: true, value: validatedArray };
|
|
13
|
+
if ((0, type_guards_1.isDefined)(options.maximumLength)) {
|
|
14
|
+
arrayConstraints.push(new array_constraints_1.ArrayMaximumLengthConstraint(options.maximumLength));
|
|
27
15
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (let i = 0; i < value.length; i++) {
|
|
34
|
-
const innerTestResult = await this.innerValidator[schema_validator_1.testAsync](value[i], options, path.add(i));
|
|
35
|
-
if (!innerTestResult.valid) {
|
|
36
|
-
return innerTestResult;
|
|
37
|
-
}
|
|
38
|
-
validatedArray.push(innerTestResult.value);
|
|
39
|
-
}
|
|
40
|
-
return { valid: true, value: validatedArray };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ArraySchemaValidator = ArraySchemaValidator;
|
|
44
|
-
function array(innerValidator, options) {
|
|
45
|
-
const schema = (0, types_1.schemaHelper)({
|
|
46
|
-
type: 'array',
|
|
47
|
-
schema: innerValidator.schema,
|
|
48
|
-
...options
|
|
16
|
+
return (0, types_1.valueSchema)({
|
|
17
|
+
type: innerValues,
|
|
18
|
+
array: true,
|
|
19
|
+
coerce: options.coerce,
|
|
20
|
+
arrayConstraints
|
|
49
21
|
});
|
|
50
|
-
return new ArraySchemaValidator(innerValidator, schema);
|
|
51
22
|
}
|
|
52
23
|
exports.array = array;
|
|
53
24
|
//# sourceMappingURL=array.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../source/schema/schemas/array.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../source/schema/schemas/array.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAEzD,yDAAgD;AAChD,4DAAoE;AAEpE,oCAAuC;AAUvC,SAAgB,KAAK,CAAI,WAAuC,EAAE,UAAwB,EAAE;IAC1F,MAAM,gBAAgB,GAA4B,EAAE,CAAC;IAErD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,gBAAgB,CAAC,IAAI,CAAC,IAAI,gDAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KAChF;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,gBAAgB,CAAC,IAAI,CAAC,IAAI,gDAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KAChF;IAED,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAjBD,sBAiBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Record } from "../../types";
|
|
2
|
+
import type { Merge } from 'type-fest';
|
|
3
|
+
import type { ObjectSchema } from '../types';
|
|
4
|
+
export declare function assign<A extends Record, B extends Record>(schema1: ObjectSchema<A>, schema2: ObjectSchema<B>): ObjectSchema<Merge<A, B>>;
|
|
5
|
+
export declare function assign<A extends Record, B extends Record, C extends Record>(schema1: ObjectSchema<A>, schema2: ObjectSchema<B>, schema3: ObjectSchema<C>): ObjectSchema<Merge<Merge<A, B>, C>>;
|
|
6
|
+
export declare function assign<A extends Record, B extends Record, C extends Record, D extends Record>(schema1: ObjectSchema<A>, schema2: ObjectSchema<B>, schema3: ObjectSchema<C>, schema4: ObjectSchema<D>): ObjectSchema<Merge<Merge<Merge<A, B>, C>, D>>;
|
|
7
|
+
export declare function assign<A extends Record, B extends Record, C extends Record, D extends Record, E extends Record>(schema1: ObjectSchema<A>, schema2: ObjectSchema<B>, schema3: ObjectSchema<C>, schema4: ObjectSchema<D>, schema5: ObjectSchema<E>): ObjectSchema<Merge<Merge<Merge<Merge<A, B>, C>, D>, E>>;
|
|
8
|
+
export declare function assign<A extends Record, B extends Record, C extends Record, D extends Record, E extends Record, F extends Record>(schema1: ObjectSchema<A>, schema2: ObjectSchema<B>, schema3: ObjectSchema<C>, schema4: ObjectSchema<D>, schema5: ObjectSchema<E>, schema6: ObjectSchema<F>): ObjectSchema<Merge<Merge<Merge<Merge<Merge<A, B>, C>, D>, E>, F>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assign = void 0;
|
|
4
|
+
const array_1 = require("../../utils/array/array");
|
|
5
|
+
const type_guards_1 = require("../../utils/type-guards");
|
|
6
|
+
function assign(...schemas) {
|
|
7
|
+
(0, type_guards_1.assert)(schemas.length >= 2, 'Assign requires at least 2 schemas.');
|
|
8
|
+
let result = schemas[0];
|
|
9
|
+
const hasDeferredValueType = schemas.flatMap((schema) => (0, array_1.toArray)(schema.allowUnknownProperties));
|
|
10
|
+
for (let i = 1; i < schemas.length; i++) {
|
|
11
|
+
result = {
|
|
12
|
+
...result,
|
|
13
|
+
...schemas[i],
|
|
14
|
+
properties: {
|
|
15
|
+
...result.properties,
|
|
16
|
+
...schemas[i].properties
|
|
17
|
+
},
|
|
18
|
+
allowUnknownProperties: [...(0, array_1.toArray)(result.allowUnknownProperties ?? []), ...(0, array_1.toArray)(schemas[i].allowUnknownProperties ?? [])]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (result.allowUnknownProperties.length == 0) {
|
|
22
|
+
const { allowUnknownProperties: _, ...rest } = result;
|
|
23
|
+
result = rest;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
exports.assign = assign;
|
|
28
|
+
//# sourceMappingURL=assign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assign.js","sourceRoot":"","sources":["../../../source/schema/schemas/assign.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAC9C,yDAA6C;AAoB7C,SAAgB,MAAM,CAAC,GAAG,OAAuB;IAC/C,IAAA,oBAAM,EAAC,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;IAEnE,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;IACzB,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,eAAO,EAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAEjG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,GAAG;YACP,GAAG,MAAM;YACT,GAAG,OAAO,CAAC,CAAC,CAAE;YACd,UAAU,EAAE;gBACV,GAAG,MAAM,CAAC,UAAU;gBACpB,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,UAAU;aAC1B;YACD,sBAAsB,EAAE,CAAC,GAAG,IAAA,eAAO,EAAC,MAAM,CAAC,sBAAsB,IAAI,EAAE,CAAC,EAAE,GAAG,IAAA,eAAO,EAAC,OAAO,CAAC,CAAC,CAAE,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;SAChI,CAAC;KACH;IAED,IAAK,MAAM,CAAC,sBAAgC,CAAC,MAAM,IAAI,CAAC,EAAE;QACxD,MAAM,EAAE,sBAAsB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QACtD,MAAM,GAAG,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAxBD,wBAwBC"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
export declare class BooleanSchemaValidator extends SchemaValidator<BooleanSchemaDefinition> {
|
|
7
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<boolean>;
|
|
8
|
-
}
|
|
9
|
-
export declare function boolean(options?: SchemaOptions<BooleanSchemaDefinition>): BooleanSchemaValidator;
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { Coercible, ValueSchema } from '../types';
|
|
3
|
+
export declare type BooleanOptions = Coercible;
|
|
4
|
+
export declare function boolean(options?: BooleanOptions): ValueSchema<boolean>;
|
|
5
|
+
export declare function Boolean(options?: BooleanOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -1,45 +1,18 @@
|
|
|
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 schema_validator_1 = require("../schema.validator");
|
|
4
|
+
exports.Boolean = exports.boolean = void 0;
|
|
5
|
+
const decorators_1 = require("../decorators");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
case 'true':
|
|
12
|
-
case '1':
|
|
13
|
-
case 'yes':
|
|
14
|
-
return { valid: true, value: true };
|
|
15
|
-
case 'false':
|
|
16
|
-
case '0':
|
|
17
|
-
case 'no':
|
|
18
|
-
return { valid: true, value: false };
|
|
19
|
-
default:
|
|
20
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot('boolean', 'string', path) };
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
number: (number, path) => ((number == 1) ? { valid: true, value: true }
|
|
24
|
-
: (number == 0) ? { valid: true, value: false }
|
|
25
|
-
: { valid: false, error: schema_error_1.SchemaError.expectedButGot('boolean', 'number', path) })
|
|
26
|
-
};
|
|
27
|
-
class BooleanSchemaValidator extends schema_validator_1.SchemaValidator {
|
|
28
|
-
[schema_validator_1.test](value, options, path) {
|
|
29
|
-
const result = super.ensureType('boolean', value, path, { coerce: this.schema.coerce ?? options.coerce }, coercerMap);
|
|
30
|
-
if (!result.valid) {
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
return { valid: true, value: result.value };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.BooleanSchemaValidator = BooleanSchemaValidator;
|
|
37
|
-
function boolean(options) {
|
|
38
|
-
const schema = (0, types_1.schemaHelper)({
|
|
39
|
-
type: 'boolean',
|
|
40
|
-
...options
|
|
7
|
+
function boolean(options = {}) {
|
|
8
|
+
return (0, types_1.valueSchema)({
|
|
9
|
+
type: globalThis.Boolean,
|
|
10
|
+
coerce: options.coerce
|
|
41
11
|
});
|
|
42
|
-
return new BooleanSchemaValidator(schema);
|
|
43
12
|
}
|
|
44
13
|
exports.boolean = boolean;
|
|
14
|
+
function Boolean(options) {
|
|
15
|
+
return (0, decorators_1.createSchemaPropertyDecoratorFromValueType)(boolean(options));
|
|
16
|
+
}
|
|
17
|
+
exports.Boolean = Boolean;
|
|
45
18
|
//# sourceMappingURL=boolean.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../source/schema/schemas/boolean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../source/schema/schemas/boolean.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAA2E;AAE3E,oCAAuC;AAIvC,SAAgB,OAAO,CAAC,UAA0B,EAAE;IAClD,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,UAAU,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AALD,0BAKC;AAED,SAAgB,OAAO,CAAC,OAAwB;IAC9C,OAAO,IAAA,uDAA0C,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC;AAFD,0BAEC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OneOrMany } from "../../types";
|
|
2
|
+
import type { GenericConstraintFunction } from '../constraints/generic';
|
|
3
|
+
import type { Schema } from '../schema';
|
|
4
|
+
export declare function constraint<T>(schema: Schema<T>, constraintFunction: GenericConstraintFunction<T>, expects?: OneOrMany<string>): Schema<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constraint = void 0;
|
|
4
|
+
const generic_1 = require("../constraints/generic");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
function constraint(schema, constraintFunction, expects) {
|
|
7
|
+
return (0, types_1.valueSchema)({
|
|
8
|
+
type: schema,
|
|
9
|
+
valueConstraints: new generic_1.GenericConstraint(constraintFunction, expects)
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.constraint = constraint;
|
|
13
|
+
/* decorator is in file of GenericConstraint */
|
|
14
|
+
//# sourceMappingURL=constraint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint.js","sourceRoot":"","sources":["../../../source/schema/schemas/constraint.ts"],"names":[],"mappings":";;;AAEA,oDAA2D;AAE3D,oCAAuC;AAEvC,SAAgB,UAAU,CAAI,MAAiB,EAAE,kBAAgD,EAAE,OAA2B;IAC5H,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,MAAM;QACZ,gBAAgB,EAAE,IAAI,2BAAiB,CAAC,kBAAkB,EAAE,OAAO,CAAC;KACrE,CAAC,CAAC;AACL,CAAC;AALD,gCAKC;AAED,+CAA+C"}
|
package/schema/schemas/date.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
min?: Date;
|
|
7
|
-
max?: Date;
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { Coercible, ValueSchema } from '../types';
|
|
3
|
+
export declare type DateOptions = Coercible & {
|
|
4
|
+
minimum?: Date | number;
|
|
5
|
+
maximum?: Date | number;
|
|
8
6
|
};
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export declare function date(options?: SchemaOptions<DateSchemaDefinition>): DateSchemaValidator;
|
|
7
|
+
export declare function date(options?: DateOptions): ValueSchema<Date>;
|
|
8
|
+
export declare function Date(options?: DateOptions): Decorator<'property' | 'accessor'>;
|
package/schema/schemas/date.js
CHANGED
|
@@ -1,63 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
+
exports.Date = exports.date = void 0;
|
|
4
5
|
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const constraints_1 = require("../constraints");
|
|
7
|
+
const decorators_1 = require("../decorators");
|
|
7
8
|
const types_1 = require("../types");
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const dateValue = new Date(string);
|
|
13
|
-
if (Number.isNaN(dateValue.getTime())) {
|
|
14
|
-
return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid format', path) };
|
|
15
|
-
}
|
|
16
|
-
return { valid: true, value: dateValue };
|
|
17
|
-
},
|
|
18
|
-
number: (number, path) => {
|
|
19
|
-
const dateValue = new Date(number);
|
|
20
|
-
if (Number.isNaN(dateValue.getTime())) {
|
|
21
|
-
return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid timestamp', path) };
|
|
22
|
-
}
|
|
23
|
-
return { valid: true, value: dateValue };
|
|
24
|
-
},
|
|
25
|
-
bigint: (bigint, path) => {
|
|
26
|
-
const numberValue = Number(bigint);
|
|
27
|
-
const dateValue = new Date(numberValue);
|
|
28
|
-
if (Number.isNaN(dateValue.getTime())) {
|
|
29
|
-
return { valid: false, error: schema_error_1.SchemaError.couldNotCoerce('number', 'string', 'invalid timestamp', path) };
|
|
30
|
-
}
|
|
31
|
-
return { valid: true, value: dateValue };
|
|
9
|
+
function date(options = {}) {
|
|
10
|
+
const constraints = [];
|
|
11
|
+
if ((0, type_guards_1.isDefined)(options.minimum)) {
|
|
12
|
+
constraints.push(new constraints_1.MinimumDateConstraint(options.minimum));
|
|
32
13
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[schema_validator_1.test](value, options, path) {
|
|
36
|
-
const result = super.ensureInstance(Date, value, path, { coerce: this.schema.coerce ?? options.coerce }, coercerMap);
|
|
37
|
-
if (!result.valid) {
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
const instanceTestResult = dateInstanceSchema[schema_validator_1.test](result.value, options, path);
|
|
41
|
-
if (!instanceTestResult.valid) {
|
|
42
|
-
return instanceTestResult;
|
|
43
|
-
}
|
|
44
|
-
const dateValue = instanceTestResult.value;
|
|
45
|
-
if ((0, type_guards_1.isDefined)(this.schema.min) && (dateValue < this.schema.min)) {
|
|
46
|
-
return { valid: false, error: (0, schema_error_1.schemaError)(`minimum date is ${this.schema.min.toISOString()}`, path) };
|
|
47
|
-
}
|
|
48
|
-
if ((0, type_guards_1.isDefined)(this.schema.max) && (dateValue > this.schema.max)) {
|
|
49
|
-
return { valid: false, error: (0, schema_error_1.schemaError)(`maximum date is ${this.schema.max.toISOString()}`, path) };
|
|
50
|
-
}
|
|
51
|
-
return { valid: true, value: dateValue };
|
|
14
|
+
if ((0, type_guards_1.isDefined)(options.maximum)) {
|
|
15
|
+
constraints.push(new constraints_1.MaximumDateConstraint(options.maximum));
|
|
52
16
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type: 'uint8-array',
|
|
58
|
-
...options
|
|
17
|
+
return (0, types_1.valueSchema)({
|
|
18
|
+
type: globalThis.Date,
|
|
19
|
+
coerce: options.coerce,
|
|
20
|
+
valueConstraints: constraints
|
|
59
21
|
});
|
|
60
|
-
return new DateSchemaValidator(schema);
|
|
61
22
|
}
|
|
62
23
|
exports.date = date;
|
|
24
|
+
function Date(options) {
|
|
25
|
+
return (0, decorators_1.createSchemaPropertyDecoratorFromValueType)(date(options));
|
|
26
|
+
}
|
|
27
|
+
exports.Date = Date;
|
|
63
28
|
//# sourceMappingURL=date.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../source/schema/schemas/date.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../source/schema/schemas/date.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,yDAAgD;AAChD,gDAA8E;AAC9E,8CAA2E;AAE3E,oCAAuC;AAOvC,SAAgB,IAAI,CAAC,UAAuB,EAAE;IAC5C,MAAM,WAAW,GAA4B,EAAE,CAAC;IAEhD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,mCAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC9D;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,WAAW,CAAC,IAAI,CAAC,IAAI,mCAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;KAC9D;IAED,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AAhBD,oBAgBC;AAED,SAAgB,IAAI,CAAC,OAAqB;IACxC,OAAO,IAAA,uDAA0C,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC;AAFD,oBAEC"}
|
|
@@ -1,15 +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, SchemaInput, SchemaOptions, SchemaOutput } from '../types';
|
|
6
|
-
export declare type DefaultedSchemaDefinition<T extends SchemaDefinition = SchemaDefinition, U = unknown> = SchemaDefinition<'defaulted', SchemaInput<T> | undefined | null, NonNullOrUndefinable<SchemaOutput<T>> | U> & {
|
|
7
|
-
schema: T;
|
|
8
|
-
defaultValue: U;
|
|
9
|
-
};
|
|
10
|
-
export declare class DefaultedSchemaValidator<T extends SchemaDefinition, U> extends SchemaValidator<DefaultedSchemaDefinition<T, U>> {
|
|
11
|
-
private readonly innerValidator;
|
|
12
|
-
constructor(innerValidator: SchemaValidator<T>, schema: DefaultedSchemaDefinition<T, U>);
|
|
13
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<DefaultedSchemaDefinition<T, U>>>;
|
|
14
|
-
}
|
|
15
|
-
export declare function defaulted<T extends SchemaDefinition, U>(innerValidator: SchemaValidator<T>, defaultValue: U, options?: SchemaOptions<DefaultedSchemaDefinition<T, U>, 'schema' | 'defaultValue'>): DefaultedSchemaValidator<T, U>;
|
|
1
|
+
import type { MaybeDeferredValueTypes, ValueSchema } from '../types';
|
|
2
|
+
export declare function defaulted<T>(type: MaybeDeferredValueTypes, defaultValue: T): ValueSchema<Date | T>;
|
|
@@ -1,30 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaulted =
|
|
4
|
-
const
|
|
5
|
-
const schema_validator_1 = require("../schema.validator");
|
|
4
|
+
exports.defaulted = void 0;
|
|
5
|
+
const coercers_1 = require("../coercers");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
[schema_validator_1.test](value, options, path) {
|
|
13
|
-
if ((0, type_guards_1.isNullOrUndefined)(value)) {
|
|
14
|
-
return { valid: true, value: this.schema.defaultValue };
|
|
15
|
-
}
|
|
16
|
-
return this.innerValidator[schema_validator_1.test](value, options, path);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.DefaultedSchemaValidator = DefaultedSchemaValidator;
|
|
20
|
-
function defaulted(innerValidator, defaultValue, options) {
|
|
21
|
-
const schema = (0, types_1.schemaHelper)({
|
|
22
|
-
type: 'defaulted',
|
|
23
|
-
schema: innerValidator.schema,
|
|
24
|
-
defaultValue,
|
|
25
|
-
...options
|
|
7
|
+
function defaulted(type, defaultValue) {
|
|
8
|
+
return (0, types_1.valueSchema)({
|
|
9
|
+
type,
|
|
10
|
+
coercers: new coercers_1.DefaultValueCoercer(defaultValue)
|
|
26
11
|
});
|
|
27
|
-
return new DefaultedSchemaValidator(innerValidator, schema);
|
|
28
12
|
}
|
|
29
13
|
exports.defaulted = defaulted;
|
|
30
14
|
//# sourceMappingURL=defaulted.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaulted.js","sourceRoot":"","sources":["../../../source/schema/schemas/defaulted.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaulted.js","sourceRoot":"","sources":["../../../source/schema/schemas/defaulted.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAEzD,0CAAkD;AAElD,oCAAuC;AAEvC,SAAgB,SAAS,CAAI,IAA6B,EAAE,YAAe;IACzE,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI;QACJ,QAAQ,EAAE,IAAI,8BAAmB,CAAC,YAAY,CAAC;KAChD,CAAC,CAAC;AACL,CAAC;AALD,8BAKC"}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Enumeration,
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare type EnumerationSchemaOutput<T extends Enumeration> = T extends EnumerationArray ? T[number] : EnumValue<T>;
|
|
8
|
-
export declare type EnumerationSchemaDefinition<T extends Enumeration = Enumeration> = SchemaDefinition<'enumeration', unknown, EnumerationSchemaOutput<T>> & Coercible & {
|
|
9
|
-
values: T;
|
|
10
|
-
};
|
|
11
|
-
export declare class EnumerationSchemaValidator<T extends Enumeration> extends SchemaValidator<EnumerationSchemaDefinition<T>> {
|
|
12
|
-
private readonly values;
|
|
13
|
-
private readonly valuesSet;
|
|
14
|
-
readonly valuesCommaSeparated: string;
|
|
15
|
-
constructor(valuesOrEnum: T, schema: EnumerationSchemaDefinition<T>);
|
|
16
|
-
[test](value: unknown, options: DefinedValidationOptions, path: JsonPath): ValidationTestResult<SchemaOutput<EnumerationSchemaDefinition<T>>>;
|
|
17
|
-
}
|
|
18
|
-
export declare function enumeration<T extends Enumeration>(values: T, options?: SchemaOptions<EnumerationSchemaDefinition, 'values'>): EnumerationSchemaValidator<T>;
|
|
1
|
+
import type { Decorator } from "../../reflection";
|
|
2
|
+
import type { Enumeration as EnumerationType, EnumerationValue } from "../../types";
|
|
3
|
+
import type { Coercible, ValueSchema } from '../types';
|
|
4
|
+
export declare type EnumerationOptions = Coercible;
|
|
5
|
+
export declare function enumeration<T extends EnumerationType>(enumerationValue: T, options?: EnumerationOptions): ValueSchema<EnumerationValue<T>>;
|
|
6
|
+
export declare function Enumeration(enumerationValue: EnumerationType, options?: EnumerationOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -1,58 +1,21 @@
|
|
|
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
|
|
6
|
-
const patterns_1 = require("../../utils/patterns");
|
|
7
|
-
const type_guards_1 = require("../../utils/type-guards");
|
|
8
|
-
const type_of_1 = require("../../utils/type-of");
|
|
9
|
-
const schema_error_1 = require("../schema.error");
|
|
10
|
-
const schema_validator_1 = require("../schema.validator");
|
|
4
|
+
exports.Enumeration = exports.enumeration = void 0;
|
|
5
|
+
const constraints_1 = require("../constraints");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
11
7
|
const types_1 = require("../types");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
[schema_validator_1.test](value, options, path) {
|
|
20
|
-
if (this.valuesSet.has(value)) {
|
|
21
|
-
return { valid: true, value: value };
|
|
22
|
-
}
|
|
23
|
-
if (this.schema.coerce ?? options.coerce) {
|
|
24
|
-
let coercedValue;
|
|
25
|
-
switch (typeof value) {
|
|
26
|
-
case 'number':
|
|
27
|
-
coercedValue = value.toString();
|
|
28
|
-
break;
|
|
29
|
-
case 'string':
|
|
30
|
-
coercedValue = patterns_1.numberPattern.test(value) ? Number(value) : undefined;
|
|
31
|
-
break;
|
|
32
|
-
default:
|
|
33
|
-
coercedValue = undefined;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
if (this.valuesSet.has(coercedValue)) {
|
|
37
|
-
return { valid: true, value: coercedValue };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(`one of [${this.valuesCommaSeparated}]`, stringifyEnumerationValue(value), path) };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.EnumerationSchemaValidator = EnumerationSchemaValidator;
|
|
44
|
-
function enumeration(values, options) {
|
|
45
|
-
const schema = (0, types_1.schemaHelper)({
|
|
46
|
-
type: 'enumeration',
|
|
47
|
-
values,
|
|
48
|
-
...options
|
|
8
|
+
function enumeration(enumerationValue, options = {}) {
|
|
9
|
+
const enumerationConstraint = new constraints_1.EnumerationConstraint(enumerationValue);
|
|
10
|
+
return (0, types_1.valueSchema)({
|
|
11
|
+
type: enumerationConstraint.suitableTypes,
|
|
12
|
+
coerce: options.coerce,
|
|
13
|
+
valueConstraints: enumerationConstraint
|
|
49
14
|
});
|
|
50
|
-
return new EnumerationSchemaValidator(values, schema);
|
|
51
15
|
}
|
|
52
16
|
exports.enumeration = enumeration;
|
|
53
|
-
function
|
|
54
|
-
return (0,
|
|
55
|
-
: (0, type_guards_1.isNumber)(value) ? value.toString()
|
|
56
|
-
: (0, type_of_1.typeOf)(value);
|
|
17
|
+
function Enumeration(enumerationValue, options = {}) {
|
|
18
|
+
return (0, decorators_1.createSchemaPropertyDecoratorFromValueType)(enumeration(enumerationValue, options));
|
|
57
19
|
}
|
|
20
|
+
exports.Enumeration = Enumeration;
|
|
58
21
|
//# sourceMappingURL=enumeration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enumeration.js","sourceRoot":"","sources":["../../../source/schema/schemas/enumeration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enumeration.js","sourceRoot":"","sources":["../../../source/schema/schemas/enumeration.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,gDAAuD;AACvD,8CAA2E;AAE3E,oCAAuC;AAIvC,SAAgB,WAAW,CAA4B,gBAAmB,EAAE,UAA8B,EAAE;IAC1G,MAAM,qBAAqB,GAAG,IAAI,mCAAqB,CAAC,gBAAgB,CAAC,CAAC;IAE1E,OAAO,IAAA,mBAAW,EAAC;QACjB,IAAI,EAAE,qBAAqB,CAAC,aAAa;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,qBAAqB;KACxC,CAAC,CAAC;AACL,CAAC;AARD,kCAQC;AAED,SAAgB,WAAW,CAAC,gBAAiC,EAAE,UAA8B,EAAE;IAC7F,OAAO,IAAA,uDAA0C,EAAC,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5F,CAAC;AAFD,kCAEC"}
|
|
@@ -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 exclude<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, key: OneOrMany<K>): ObjectSchema<Simplify<Omit<T, K>>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exclude = void 0;
|
|
4
|
+
const array_1 = require("../../utils/array/array");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
function exclude(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.exclude = exclude;
|
|
17
|
+
//# sourceMappingURL=exclude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exclude.js","sourceRoot":"","sources":["../../../source/schema/schemas/exclude.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAG9C,oCAAwC;AAExC,SAAgB,OAAO,CAAsC,MAAuB,EAAE,GAAiB;IACrG,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,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAgB,CAAC,CAAC,CAAC;IAE1F,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,0BAYC"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
export * from './any';
|
|
2
2
|
export * from './array';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './assign';
|
|
4
4
|
export * from './boolean';
|
|
5
|
+
export * from './constraint';
|
|
5
6
|
export * from './date';
|
|
6
|
-
export * from './defaulted';
|
|
7
7
|
export * from './enumeration';
|
|
8
|
+
export * from './exclude';
|
|
8
9
|
export * from './instance';
|
|
9
|
-
export * from './iterable';
|
|
10
10
|
export * from './literal';
|
|
11
|
-
export * from './never';
|
|
12
11
|
export * from './nullable';
|
|
13
12
|
export * from './number';
|
|
14
13
|
export * from './object';
|
|
15
14
|
export * from './optional';
|
|
16
|
-
export * from './
|
|
15
|
+
export * from './pick';
|
|
17
16
|
export * from './readable-stream';
|
|
18
|
-
export * from './
|
|
17
|
+
export * from './record';
|
|
19
18
|
export * from './regexp';
|
|
20
19
|
export * from './string';
|
|
21
20
|
export * from './transform';
|
package/schema/schemas/index.js
CHANGED
|
@@ -16,22 +16,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./any"), exports);
|
|
18
18
|
__exportStar(require("./array"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./assign"), exports);
|
|
20
20
|
__exportStar(require("./boolean"), exports);
|
|
21
|
+
__exportStar(require("./constraint"), exports);
|
|
21
22
|
__exportStar(require("./date"), exports);
|
|
22
|
-
__exportStar(require("./defaulted"), exports);
|
|
23
23
|
__exportStar(require("./enumeration"), exports);
|
|
24
|
+
__exportStar(require("./exclude"), exports);
|
|
24
25
|
__exportStar(require("./instance"), exports);
|
|
25
|
-
__exportStar(require("./iterable"), exports);
|
|
26
26
|
__exportStar(require("./literal"), exports);
|
|
27
|
-
__exportStar(require("./never"), exports);
|
|
28
27
|
__exportStar(require("./nullable"), exports);
|
|
29
28
|
__exportStar(require("./number"), exports);
|
|
30
29
|
__exportStar(require("./object"), exports);
|
|
31
30
|
__exportStar(require("./optional"), exports);
|
|
32
|
-
__exportStar(require("./
|
|
31
|
+
__exportStar(require("./pick"), exports);
|
|
33
32
|
__exportStar(require("./readable-stream"), exports);
|
|
34
|
-
__exportStar(require("./
|
|
33
|
+
__exportStar(require("./record"), exports);
|
|
35
34
|
__exportStar(require("./regexp"), exports);
|
|
36
35
|
__exportStar(require("./string"), exports);
|
|
37
36
|
__exportStar(require("./transform"), exports);
|