@tstdl/base 0.78.0-beta4 → 0.78.0-beta40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/client/client.d.ts +2 -1
- package/api/client/client.js +6 -13
- package/api/client/client.js.map +1 -1
- package/api/response.js.map +1 -1
- package/api/server/gateway.js +7 -5
- package/api/server/gateway.js.map +1 -1
- package/api/types.d.ts +22 -9
- package/api/types.js +1 -2
- package/api/types.js.map +1 -1
- package/api/utils.d.ts +9 -0
- package/api/utils.js +15 -0
- package/api/utils.js.map +1 -0
- package/application/application.js.map +1 -1
- package/container/container.js.map +1 -1
- package/container/decorators.d.ts +1 -1
- package/container/decorators.js.map +1 -1
- package/css/theme/theme.service.js.map +1 -1
- package/data-structures/iterable-weak-map.js +1 -1
- package/data-structures/iterable-weak-map.js.map +1 -1
- package/data-structures/linked-list.js.map +1 -1
- package/data-structures/sorted-array-list.js.map +1 -1
- package/database/mongo/classes.js.map +1 -1
- package/database/mongo/mongo-entity-repository.js +2 -2
- package/database/mongo/mongo-entity-repository.js.map +1 -1
- package/distributed-loop/distributed-loop.js.map +1 -1
- package/distributed-loop/provider.js.map +1 -1
- package/enumerable/async-enumerable.d.ts +2 -1
- package/enumerable/async-enumerable.js +3 -0
- package/enumerable/async-enumerable.js.map +1 -1
- package/enumerable/enumerable-methods.d.ts +1 -0
- package/enumerable/enumerable.d.ts +1 -0
- package/enumerable/enumerable.js +12 -18
- package/enumerable/enumerable.js.map +1 -1
- package/error/custom.error.d.ts +1 -1
- package/error/custom.error.js +8 -6
- package/error/custom.error.js.map +1 -1
- package/examples/api/basic-overview.js +0 -1
- package/examples/api/basic-overview.js.map +1 -1
- package/examples/mail/basic.js +12 -7
- package/examples/mail/basic.js.map +1 -1
- package/examples/mail/templates/hello-name.d.ts +2 -0
- package/examples/mail/templates/hello-name.js +11 -0
- package/examples/mail/templates/hello-name.js.map +1 -0
- package/examples/pdf/basic.js +6 -3
- package/examples/pdf/basic.js.map +1 -1
- package/examples/pdf/templates/hello-name.d.ts +1 -4
- package/examples/pdf/templates/hello-name.js +16 -4
- package/examples/pdf/templates/hello-name.js.map +1 -1
- package/examples/reflection/basic.js +1 -1
- package/examples/reflection/basic.js.map +1 -1
- package/http/client/adapters/got-http-client.adapter.js.map +1 -1
- package/http/client/adapters/undici-http-client.adapter.js.map +1 -1
- package/http/client/adapters/utils.js +20 -8
- package/http/client/adapters/utils.js.map +1 -1
- package/http/client/http-client-request.d.ts +13 -3
- package/http/client/http-client-request.js +4 -0
- package/http/client/http-client-request.js.map +1 -1
- package/http/client/http-client.js +29 -12
- package/http/client/http-client.js.map +1 -1
- package/http/http-headers.d.ts +2 -0
- package/http/http-headers.js +6 -0
- package/http/http-headers.js.map +1 -1
- package/http/server/node/node-http-server.js.map +1 -1
- package/image-service/image-service.js.map +1 -1
- package/image-service/imgproxy/imgproxy-image-service.js.map +1 -1
- package/key-value-store/mongo/mongo-key-value-store.provider.js.map +1 -1
- package/key-value-store/mongo/mongo-key-value.repository.js.map +1 -1
- package/key-value-store/mongo/mongo-key-value.store.js.map +1 -1
- package/lock/mongo/lock.js.map +1 -1
- package/lock/mongo/mongo-lock-repository.js.map +1 -1
- package/lock/mongo/provider.js.map +1 -1
- package/logger/console/logger.js.map +1 -1
- package/mail/clients/nodemailer.mail-client.js.map +1 -1
- package/mail/index.d.ts +0 -3
- package/mail/index.js +0 -3
- package/mail/index.js.map +1 -1
- package/mail/mail.service.d.ts +3 -5
- package/mail/mail.service.js +8 -14
- package/mail/mail.service.js.map +1 -1
- package/mail/models/mail-template.model.d.ts +11 -10
- package/mail/models/mail-template.model.js +7 -0
- package/mail/models/mail-template.model.js.map +1 -1
- package/mail/module.d.ts +1 -5
- package/mail/module.js +2 -11
- package/mail/module.js.map +1 -1
- package/mail/repositories/mongo-mail-log.repository.js.map +1 -1
- package/mail/tokens.d.ts +0 -3
- package/mail/tokens.js +1 -2
- package/mail/tokens.js.map +1 -1
- package/message-bus/local/local-message-bus-provider.js.map +1 -1
- package/message-bus/local/local-message-bus.js.map +1 -1
- package/migration/migrator.js.map +1 -1
- package/migration/mongo/migration-state-repository.js.map +1 -1
- package/module/modules/web-server.module.js.map +1 -1
- package/object-storage/s3/s3.object-storage-provider.js.map +1 -1
- package/object-storage/s3/s3.object-storage.js.map +1 -1
- package/openid-connect/cached-oidc-configuration.service.js.map +1 -1
- package/openid-connect/mongo-oidc-state.repository.js.map +1 -1
- package/openid-connect/oidc-configuration.service.d.ts +2 -1
- package/openid-connect/oidc-configuration.service.js +5 -3
- package/openid-connect/oidc-configuration.service.js.map +1 -1
- package/openid-connect/oidc.service-model.d.ts +11 -3
- package/openid-connect/oidc.service.d.ts +4 -3
- package/openid-connect/oidc.service.js +66 -21
- package/openid-connect/oidc.service.js.map +1 -1
- package/package.json +7 -8
- package/pdf/pdf.service.d.ts +48 -10
- package/pdf/pdf.service.js +114 -4
- package/pdf/pdf.service.js.map +1 -1
- package/promise/deferred-promise.d.ts +2 -15
- package/promise/deferred-promise.js +5 -10
- package/promise/deferred-promise.js.map +1 -1
- package/promise/index.d.ts +1 -0
- package/promise/index.js +1 -0
- package/promise/index.js.map +1 -1
- package/promise/lazy-promise.d.ts +11 -0
- package/promise/lazy-promise.js +31 -0
- package/promise/lazy-promise.js.map +1 -0
- package/queue/mongo/mongo-job.repository.js.map +1 -1
- package/queue/mongo/queue.js.map +1 -1
- package/queue/mongo/queue.provider.js.map +1 -1
- package/reflection/decorator-data.js +1 -1
- package/reflection/decorator-data.js.map +1 -1
- package/reflection/decorators.d.ts +2 -2
- package/reflection/decorators.js +7 -7
- package/reflection/decorators.js.map +1 -1
- package/reflection/registry.d.ts +8 -8
- package/reflection/registry.js +1 -1
- package/reflection/registry.js.map +1 -1
- package/reflection/types.d.ts +3 -2
- package/reflection/utils.d.ts +7 -2
- package/reflection/utils.js +38 -12
- package/reflection/utils.js.map +1 -1
- package/schema/array-constraints/maximum-length.js +2 -2
- package/schema/array-constraints/maximum-length.js.map +1 -1
- package/schema/array-constraints/minimum-length.js +2 -2
- package/schema/array-constraints/minimum-length.js.map +1 -1
- package/schema/coercers/default-value.coercer.d.ts +1 -1
- package/schema/coercers/default-value.coercer.js +1 -1
- package/schema/coercers/default-value.coercer.js.map +1 -1
- package/schema/coercers/uint8-array.coercer.js +4 -3
- package/schema/coercers/uint8-array.coercer.js.map +1 -1
- package/schema/constraints/enumeration.js +2 -2
- package/schema/constraints/enumeration.js.map +1 -1
- package/schema/constraints/generic.js +2 -2
- package/schema/constraints/generic.js.map +1 -1
- package/schema/constraints/integer.js +3 -3
- package/schema/constraints/integer.js.map +1 -1
- package/schema/constraints/literal.js +2 -2
- package/schema/constraints/literal.js.map +1 -1
- package/schema/constraints/maximum-date.js +3 -3
- package/schema/constraints/maximum-date.js.map +1 -1
- package/schema/constraints/maximum-length.js +2 -2
- package/schema/constraints/maximum-length.js.map +1 -1
- package/schema/constraints/maximum.js +3 -3
- package/schema/constraints/maximum.js.map +1 -1
- package/schema/constraints/minimum-date.js +3 -3
- package/schema/constraints/minimum-date.js.map +1 -1
- package/schema/constraints/minimum-length.js +2 -2
- package/schema/constraints/minimum-length.js.map +1 -1
- package/schema/constraints/minimum.js +3 -3
- package/schema/constraints/minimum.js.map +1 -1
- package/schema/constraints/pattern.js +3 -3
- package/schema/constraints/pattern.js.map +1 -1
- package/schema/decorators/array.d.ts +2 -2
- package/schema/decorators/array.js +1 -1
- package/schema/decorators/array.js.map +1 -1
- package/schema/decorators/defaulted.d.ts +2 -2
- package/schema/decorators/defaulted.js +1 -1
- package/schema/decorators/defaulted.js.map +1 -1
- package/schema/decorators/optional.d.ts +3 -1
- package/schema/decorators/optional.js +2 -2
- package/schema/decorators/optional.js.map +1 -1
- package/schema/decorators/property.d.ts +1 -1
- package/schema/decorators/property.js +3 -1
- package/schema/decorators/property.js.map +1 -1
- package/schema/decorators/types.d.ts +4 -4
- package/schema/decorators/utils.d.ts +3 -2
- package/schema/decorators/utils.js +4 -8
- package/schema/decorators/utils.js.map +1 -1
- package/schema/schema.d.ts +8 -10
- package/schema/schema.error.d.ts +1 -0
- package/schema/schema.error.js +1 -1
- package/schema/schema.error.js.map +1 -1
- package/schema/schema.js +131 -164
- package/schema/schema.js.map +1 -1
- package/schema/schemas/any.d.ts +2 -2
- package/schema/schemas/any.js +2 -2
- package/schema/schemas/any.js.map +1 -1
- package/schema/schemas/array.d.ts +2 -1
- package/schema/schemas/array.js +1 -1
- package/schema/schemas/array.js.map +1 -1
- package/schema/schemas/assign.d.ts +5 -5
- package/schema/schemas/boolean.js +2 -2
- package/schema/schemas/boolean.js.map +1 -1
- package/schema/schemas/date.js +2 -2
- package/schema/schemas/date.js.map +1 -1
- package/schema/schemas/defaulted.d.ts +3 -2
- package/schema/schemas/defaulted.js.map +1 -1
- package/schema/schemas/enumeration.js +2 -2
- package/schema/schemas/enumeration.js.map +1 -1
- package/schema/schemas/exclude.d.ts +4 -1
- package/schema/schemas/exclude.js +6 -11
- package/schema/schemas/exclude.js.map +1 -1
- package/schema/schemas/index.d.ts +2 -0
- package/schema/schemas/index.js +2 -0
- package/schema/schemas/index.js.map +1 -1
- package/schema/schemas/instance.d.ts +2 -2
- package/schema/schemas/instance.js +1 -1
- package/schema/schemas/instance.js.map +1 -1
- package/schema/schemas/literal.js +2 -2
- package/schema/schemas/literal.js.map +1 -1
- package/schema/schemas/nullable.d.ts +3 -2
- package/schema/schemas/nullable.js.map +1 -1
- package/schema/schemas/number.d.ts +1 -1
- package/schema/schemas/number.js +2 -2
- package/schema/schemas/number.js.map +1 -1
- package/schema/schemas/object.d.ts +2 -3
- package/schema/schemas/object.js.map +1 -1
- package/schema/schemas/omit.d.ts +4 -0
- package/schema/schemas/omit.js +17 -0
- package/schema/schemas/omit.js.map +1 -0
- package/schema/schemas/readable-stream.d.ts +2 -2
- package/schema/schemas/readable-stream.js +2 -2
- package/schema/schemas/readable-stream.js.map +1 -1
- package/schema/schemas/record.d.ts +3 -2
- package/schema/schemas/record.js.map +1 -1
- package/schema/schemas/regexp.js +2 -2
- package/schema/schemas/regexp.js.map +1 -1
- package/schema/schemas/string.js +2 -2
- package/schema/schemas/string.js.map +1 -1
- package/schema/schemas/transform.d.ts +3 -2
- package/schema/schemas/transform.js.map +1 -1
- package/schema/schemas/uint8-array.d.ts +2 -3
- package/schema/schemas/uint8-array.js +3 -3
- package/schema/schemas/uint8-array.js.map +1 -1
- package/schema/schemas/union.d.ts +9 -8
- package/schema/schemas/union.js +1 -1
- package/schema/schemas/union.js.map +1 -1
- package/schema/schemas/unknown.d.ts +2 -2
- package/schema/schemas/unknown.js +2 -2
- package/schema/schemas/unknown.js.map +1 -1
- package/schema/transformers/generic.d.ts +4 -4
- package/schema/transformers/generic.js.map +1 -1
- package/schema/transformers/lowercase.js +1 -1
- package/schema/transformers/lowercase.js.map +1 -1
- package/schema/transformers/trim.js +1 -1
- package/schema/transformers/trim.js.map +1 -1
- package/schema/transformers/uppercase.js +1 -1
- package/schema/transformers/uppercase.js.map +1 -1
- package/schema/types.d.ts +53 -39
- package/schema/types.js +49 -34
- package/schema/types.js.map +1 -1
- package/schema/utils/schema.d.ts +13 -5
- package/schema/utils/schema.js +86 -26
- package/schema/utils/schema.js.map +1 -1
- package/schema/utils/value-type.d.ts +3 -1
- package/schema/utils/value-type.js +32 -2
- package/schema/utils/value-type.js.map +1 -1
- package/search-index/elastic/config.js.map +1 -1
- package/search-index/elastic/model/index-mapping.d.ts +2 -1
- package/search-index/elastic/model/index-mapping.js.map +1 -1
- package/search-index/elastic/search-index.js +1 -1
- package/search-index/elastic/search-index.js.map +1 -1
- package/serializer/serializable.d.ts +4 -4
- package/serializer/serializable.js.map +1 -1
- package/templates/index.d.ts +2 -0
- package/templates/index.js +2 -0
- package/templates/index.js.map +1 -1
- package/templates/module.d.ts +3 -1
- package/templates/module.js +31 -8
- package/templates/module.js.map +1 -1
- package/templates/providers/file.provider-template.d.ts +16 -0
- package/templates/providers/{file-template.provider.js → file.provider-template.js} +22 -15
- package/templates/providers/file.provider-template.js.map +1 -0
- package/templates/providers/memory.template-provider.d.ts +8 -0
- package/templates/providers/{memory-template.provider.base.js → memory.template-provider.js} +8 -6
- package/templates/providers/memory.template-provider.js.map +1 -0
- package/templates/renderers/handlebars.template-renderer.d.ts +38 -6
- package/templates/renderers/handlebars.template-renderer.js +47 -3
- package/templates/renderers/handlebars.template-renderer.js.map +1 -1
- package/templates/renderers/mjml.template-renderer.d.ts +6 -6
- package/templates/renderers/mjml.template-renderer.js +8 -9
- package/templates/renderers/mjml.template-renderer.js.map +1 -1
- package/templates/renderers/string.template-renderer.d.ts +8 -0
- package/{mail/template-providers/memory-mail-template.provider.js → templates/renderers/string.template-renderer.js} +13 -7
- package/templates/renderers/string.template-renderer.js.map +1 -0
- package/templates/resolvers/file.template-resolver.d.ts +23 -0
- package/templates/resolvers/file.template-resolver.js +63 -0
- package/templates/resolvers/file.template-resolver.js.map +1 -0
- package/templates/resolvers/string.template-resolver.d.ts +13 -0
- package/templates/resolvers/string.template-resolver.js +44 -0
- package/templates/resolvers/string.template-resolver.js.map +1 -0
- package/templates/template-renderer.provider.js +7 -19
- package/templates/template-renderer.provider.js.map +1 -1
- package/templates/template-resolver.provider.d.ts +8 -0
- package/templates/template-resolver.provider.js +48 -0
- package/templates/template-resolver.provider.js.map +1 -0
- package/templates/template.model.d.ts +14 -4
- package/templates/template.model.js +42 -0
- package/templates/template.model.js.map +1 -1
- package/templates/template.renderer.d.ts +14 -3
- package/templates/template.renderer.js +3 -0
- package/templates/template.renderer.js.map +1 -1
- package/templates/template.resolver.d.ts +5 -0
- package/templates/template.resolver.js +7 -0
- package/templates/template.resolver.js.map +1 -0
- package/templates/template.service.d.ts +10 -4
- package/templates/template.service.js +19 -6
- package/templates/template.service.js.map +1 -1
- package/templates/tokens.d.ts +3 -2
- package/templates/tokens.js +2 -1
- package/templates/tokens.js.map +1 -1
- package/types.d.ts +6 -4
- package/utils/array/array.d.ts +1 -2
- package/utils/array/array.js.map +1 -1
- package/utils/async-iterable-helpers/includes.d.ts +2 -0
- package/utils/async-iterable-helpers/includes.js +13 -0
- package/utils/async-iterable-helpers/includes.js.map +1 -0
- package/utils/async-iterable-helpers/index.d.ts +1 -0
- package/utils/async-iterable-helpers/index.js +1 -0
- package/utils/async-iterable-helpers/index.js.map +1 -1
- package/utils/clone.js +4 -0
- package/utils/clone.js.map +1 -1
- package/utils/compression.d.ts +13 -13
- package/utils/compression.js +10 -9
- package/utils/compression.js.map +1 -1
- package/utils/encoding.js +1 -1
- package/utils/encoding.js.map +1 -1
- package/utils/enum.js +3 -3
- package/utils/enum.js.map +1 -1
- package/utils/function/memoize.d.ts +1 -0
- package/utils/function/memoize.js +7 -4
- package/utils/function/memoize.js.map +1 -1
- package/utils/helpers.d.ts +0 -2
- package/utils/helpers.js +1 -12
- package/utils/helpers.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/iterable-helpers/includes.d.ts +1 -0
- package/utils/iterable-helpers/includes.js +9 -0
- package/utils/iterable-helpers/includes.js.map +1 -0
- package/utils/iterable-helpers/index.d.ts +1 -0
- package/utils/iterable-helpers/index.js +1 -0
- package/utils/iterable-helpers/index.js.map +1 -1
- package/utils/object/property-name.d.ts +2 -2
- package/utils/throw.d.ts +2 -0
- package/utils/throw.js +15 -0
- package/utils/throw.js.map +1 -0
- package/utils/type-guards.d.ts +13 -1
- package/utils/type-guards.js +29 -5
- package/utils/type-guards.js.map +1 -1
- package/web-types.d.ts +28 -0
- package/web-types.js +3 -0
- package/web-types.js.map +1 -0
- package/mail/mail-template-renderer.provider.d.ts +0 -8
- package/mail/mail-template-renderer.provider.js +0 -60
- package/mail/mail-template-renderer.provider.js.map +0 -1
- package/mail/mail-template.provider.d.ts +0 -4
- package/mail/mail-template.provider.js +0 -7
- package/mail/mail-template.provider.js.map +0 -1
- package/mail/mail-template.renderer.d.ts +0 -10
- package/mail/mail-template.renderer.js +0 -7
- package/mail/mail-template.renderer.js.map +0 -1
- package/mail/template-providers/file-mail-template.provider.d.ts +0 -24
- package/mail/template-providers/file-mail-template.provider.js +0 -51
- package/mail/template-providers/file-mail-template.provider.js.map +0 -1
- package/mail/template-providers/memory-mail-template.provider.d.ts +0 -6
- package/mail/template-providers/memory-mail-template.provider.js.map +0 -1
- package/mail/template-renderers/handlebars.mail-template-renderer.d.ts +0 -13
- package/mail/template-renderers/handlebars.mail-template-renderer.js +0 -49
- package/mail/template-renderers/handlebars.mail-template-renderer.js.map +0 -1
- package/mail/template-renderers/mjml.mail-template-renderer.d.ts +0 -14
- package/mail/template-renderers/mjml.mail-template-renderer.js +0 -63
- package/mail/template-renderers/mjml.mail-template-renderer.js.map +0 -1
- package/templates/providers/file-template.provider.base.d.ts +0 -12
- package/templates/providers/file-template.provider.base.js +0 -50
- package/templates/providers/file-template.provider.base.js.map +0 -1
- package/templates/providers/file-template.provider.d.ts +0 -22
- package/templates/providers/file-template.provider.js.map +0 -1
- package/templates/providers/memory-template.provider.base.d.ts +0 -9
- package/templates/providers/memory-template.provider.base.js.map +0 -1
- package/templates/providers/memory-template.provider.d.ts +0 -4
- package/templates/providers/memory-template.provider.js +0 -18
- package/templates/providers/memory-template.provider.js.map +0 -1
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
|
-
|
|
2
|
+
import type { OneOrMany } from "../../types";
|
|
3
|
+
import type { SchemaTestable } from '../schema';
|
|
4
|
+
export declare function Optional(schema?: OneOrMany<SchemaTestable>): Decorator<'property' | 'accessor'>;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Optional = void 0;
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
function Optional() {
|
|
7
|
-
return (0, utils_1.createSchemaPropertyDecorator)({ optional: true });
|
|
6
|
+
function Optional(schema) {
|
|
7
|
+
return (0, utils_1.createSchemaPropertyDecorator)({ schema, optional: true });
|
|
8
8
|
}
|
|
9
9
|
exports.Optional = Optional;
|
|
10
10
|
//# sourceMappingURL=optional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/decorators/optional.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../source/schema/decorators/optional.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAKzD,mCAAwD;AAExD,SAAgB,QAAQ,CAAC,MAAkC;IACzD,OAAO,IAAA,qCAA6B,EAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC;AAFD,4BAEC"}
|
|
@@ -3,4 +3,4 @@ import type { OneOrMany, TypedOmit } from "../../types";
|
|
|
3
3
|
import type { ValueType } from '../types';
|
|
4
4
|
import type { PropertyOptions } from './types';
|
|
5
5
|
export declare function Property(options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
6
|
-
export declare function Property(
|
|
6
|
+
export declare function Property(schema?: OneOrMany<ValueType>, options?: TypedOmit<PropertyOptions, 'schema'>): Decorator<'property' | 'accessor'>;
|
|
@@ -7,8 +7,10 @@ const type_guards_1 = require("../../utils/type-guards");
|
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
function Property(optionsOrTypes = {}, optionsOrNothing) {
|
|
10
|
-
const
|
|
10
|
+
const schema = ((0, type_guards_1.isFunction)(optionsOrTypes) || (0, type_guards_1.isString)(optionsOrTypes)) ? (0, types_1.typeSchema)(optionsOrTypes) : undefined;
|
|
11
|
+
const options = (0, type_guards_1.isUndefined)(schema) ? optionsOrTypes : optionsOrNothing ?? {};
|
|
11
12
|
return (0, utils_1.createSchemaPropertyDecorator)({
|
|
13
|
+
schema,
|
|
12
14
|
...options,
|
|
13
15
|
coercers: (0, type_guards_1.isDefined)(options.coercers) ? (0, array_1.toArray)(options.coercers) : undefined,
|
|
14
16
|
transformers: (0, type_guards_1.isDefined)(options.transformers) ? (0, array_1.toArray)(options.transformers) : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../source/schema/decorators/property.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,mDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../source/schema/decorators/property.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,mDAA8C;AAC9C,yDAAmF;AAEnF,oCAAsC;AAEtC,mCAAwD;AAIxD,SAAgB,QAAQ,CAAC,iBAAyD,EAAE,EAAE,gBAAkC;IACtH,MAAM,MAAM,GAAG,CAAC,IAAA,wBAAU,EAAC,cAAc,CAAC,IAAI,IAAA,sBAAQ,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAU,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjH,MAAM,OAAO,GAAG,IAAA,yBAAW,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,cAAkC,CAAC,CAAC,CAAC,gBAAgB,IAAK,EAAsB,CAAC;IAExH,OAAO,IAAA,qCAA6B,EAAC;QACnC,MAAM;QACN,GAAG,OAAO;QACV,QAAQ,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QAC7E,YAAY,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;QACzF,gBAAgB,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS;QACrG,gBAAgB,EAAE,IAAA,uBAAS,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS;KACtG,CAAC,CAAC;AACL,CAAC;AAZD,4BAYC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { OneOrMany } from "../../types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SchemaTestable } from '../schema';
|
|
3
|
+
import type { ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, ValueSchema } from '../types';
|
|
3
4
|
export declare type SchemaTypeReflectionData = Partial<Pick<ObjectSchema, 'mask' | 'allowUnknownProperties'>> & {
|
|
4
5
|
factory?: SchemaFactoryFunction<any>;
|
|
5
6
|
};
|
|
6
|
-
export declare type TypesProvider = () => OneOrMany<ValueType>;
|
|
7
7
|
export declare type SchemaPropertyReflectionData = {
|
|
8
|
-
|
|
8
|
+
schema?: OneOrMany<SchemaTestable>;
|
|
9
9
|
array?: boolean;
|
|
10
10
|
optional?: boolean;
|
|
11
11
|
nullable?: boolean;
|
|
@@ -15,4 +15,4 @@ export declare type SchemaPropertyReflectionData = {
|
|
|
15
15
|
arrayConstraints?: readonly SchemaArrayConstraint[];
|
|
16
16
|
valueConstraints?: readonly SchemaValueConstraint[];
|
|
17
17
|
};
|
|
18
|
-
export declare type PropertyOptions = Partial<ValueSchema
|
|
18
|
+
export declare type PropertyOptions = Partial<ValueSchema<any>>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
2
|
import type { OneOrMany } from "../../types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Schema } from '../schema';
|
|
4
|
+
import type { SchemaArrayConstraint, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer } from '../types';
|
|
4
5
|
import type { PropertyOptions } from './types';
|
|
5
6
|
export declare function createSchemaPropertyDecorator(options: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
6
|
-
export declare function
|
|
7
|
+
export declare function createSchemaPropertyDecoratorFromSchema(schema: Schema): Decorator<'property' | 'accessor'>;
|
|
7
8
|
export declare function createSchemaValueCoercerDecorator(coercer: SchemaValueCoercer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
8
9
|
export declare function createSchemaValueTransformerDecorator(transformer: SchemaValueTransformer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
9
10
|
export declare function createSchemaArrayConstraintDecorator(constraint: SchemaArrayConstraint, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createSchemaValueConstraintDecorator = exports.createSchemaArrayConstraintDecorator = exports.createSchemaValueTransformerDecorator = exports.createSchemaValueCoercerDecorator = exports.
|
|
4
|
+
exports.createSchemaValueConstraintDecorator = exports.createSchemaArrayConstraintDecorator = exports.createSchemaValueTransformerDecorator = exports.createSchemaValueCoercerDecorator = exports.createSchemaPropertyDecoratorFromSchema = exports.createSchemaPropertyDecorator = void 0;
|
|
5
5
|
const reflection_1 = require("../../reflection");
|
|
6
6
|
const array_1 = require("../../utils/array/array");
|
|
7
7
|
const merge_1 = require("../../utils/merge");
|
|
@@ -24,14 +24,10 @@ function createSchemaPropertyDecorator(options) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
exports.createSchemaPropertyDecorator = createSchemaPropertyDecorator;
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
return createSchemaPropertyDecorator({
|
|
30
|
-
...schema,
|
|
31
|
-
type: schema.type
|
|
32
|
-
});
|
|
27
|
+
function createSchemaPropertyDecoratorFromSchema(schema) {
|
|
28
|
+
return createSchemaPropertyDecorator((0, types_1.isValueSchema)(schema) ? schema : (0, types_1.valueSchema)(schema));
|
|
33
29
|
}
|
|
34
|
-
exports.
|
|
30
|
+
exports.createSchemaPropertyDecoratorFromSchema = createSchemaPropertyDecoratorFromSchema;
|
|
35
31
|
function createSchemaValueCoercerDecorator(coercer, options) {
|
|
36
32
|
return createSchemaPropertyDecorator({ ...options, coercers: coercer });
|
|
37
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../source/schema/decorators/utils.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,iDAAiE;AAEjE,mDAA8C;AAC9C,6CAAsC;AACtC,+CAA8C;AAC9C,yDAAsE;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../source/schema/decorators/utils.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,iDAAiE;AAEjE,mDAA8C;AAC9C,6CAAsC;AACtC,+CAA8C;AAC9C,yDAAsE;AAGtE,oCAAsD;AAGtD,SAAgB,6BAA6B,CAAC,OAAwB;IACpE,OAAO,IAAA,8CAAiC,EAAC;QACvC,OAAO,CAAC,CAAC,EAAE,QAAQ;YACjB,MAAM,UAAU,GAAG,+BAA+B,CAAC,QAAQ,CAAC,CAAC;YAE7D,MAAM,aAAa,GAAiC;gBAClD,GAAG,OAAO;gBACV,QAAQ,EAAE,CAAC,IAAA,uBAAS,EAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAA,qBAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,aAAK,EAAC,IAAA,eAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC1K,YAAY,EAAE,CAAC,IAAA,u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ypeSchema, ValueSchema } from './types';
|
|
3
|
-
export declare type Schema<T = any, O = T> = ObjectSchema<T, O> | ValueSchema<T, O>;
|
|
4
|
-
export declare
|
|
5
|
-
export declare type
|
|
2
|
+
import type { NormalizedObjectSchema, NormalizedTypeSchema, NormalizedValueSchema, ObjectSchema, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, TypeSchema, ValueSchema, ValueType } from './types';
|
|
3
|
+
export declare type Schema<T = any, O = T> = ObjectSchema<T, O> | ValueSchema<T, O> | TypeSchema<O>;
|
|
4
|
+
export declare type SchemaTestable<T = any, O = T> = Schema<T, O> | ValueType<O>;
|
|
5
|
+
export declare type NormalizedSchema<T = any, O = T> = NormalizedObjectSchema<T, O> | NormalizedValueSchema<T, O> | NormalizedTypeSchema<O>;
|
|
6
6
|
export declare const Schema: {
|
|
7
7
|
registerDefaultCoercer(coercer: SchemaValueCoercer): void;
|
|
8
|
-
test<T, O>(
|
|
9
|
-
validate<T_1, O_1 = T_1>(
|
|
10
|
-
parse<T_2, O_2 = T_2>(
|
|
8
|
+
test<T, O>(schemaOrValueType: SchemaTestable<T, O>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O>;
|
|
9
|
+
validate<T_1, O_1 = T_1>(schemaOrValueType: SchemaTestable<T_1, O_1>, value: unknown, options?: SchemaTestOptions): boolean;
|
|
10
|
+
parse<T_2, O_2 = T_2>(schemaOrValueType: SchemaTestable<T_2, O_2>, value: unknown, options?: SchemaTestOptions): O_2;
|
|
11
11
|
/**
|
|
12
12
|
* disables stack traces for errors
|
|
13
13
|
* @deprecated for internal use only
|
|
14
14
|
*/
|
|
15
|
-
testWithFastError<T_3, O_3 = T_3>(schema:
|
|
15
|
+
testWithFastError<T_3, O_3 = T_3>(schema: Schema<T_3, O_3>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<O_3>;
|
|
16
16
|
};
|
|
17
|
-
declare function _getObjectSchemaFromReflection<T, O>(type: TypeSchema<T, O>): ObjectSchema<T> | null;
|
|
18
|
-
export {};
|
package/schema/schema.error.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare type SchemaErrorOptions = Pick<CustomErrorOptions, 'fast'> & {
|
|
|
8
8
|
path: string | JsonPath;
|
|
9
9
|
inner?: OneOrMany<SchemaError>;
|
|
10
10
|
details?: UndefinableJson;
|
|
11
|
+
cause?: any;
|
|
11
12
|
};
|
|
12
13
|
export declare class SchemaError extends CustomError implements ErrorExtraInfo {
|
|
13
14
|
static readonly errorName = "SchemaError";
|
package/schema/schema.error.js
CHANGED
|
@@ -7,7 +7,7 @@ const type_guards_1 = require("../utils/type-guards");
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
class SchemaError extends error_1.CustomError {
|
|
9
9
|
constructor(message, options, cause) {
|
|
10
|
-
super({ message, cause, fast: options.fast ?? true });
|
|
10
|
+
super({ message, cause: cause ?? options.cause, fast: options.fast ?? true });
|
|
11
11
|
this.path = (0, type_guards_1.isString)(options.path) ? options.path : options.path.path;
|
|
12
12
|
if ((0, type_guards_1.isDefined)(options.inner)) {
|
|
13
13
|
const errors = (0, array_1.toArray)(options.inner);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAGtC,gDAA8C;AAE9C,sDAAgF;AAEhF,mCAA2C;
|
|
1
|
+
{"version":3,"file":"schema.error.js","sourceRoot":"","sources":["../../source/schema/schema.error.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAGtC,gDAA8C;AAE9C,sDAAgF;AAEhF,mCAA2C;AAS3C,MAAa,WAAY,SAAQ,mBAAW;IAO1C,YAAY,OAAe,EAAE,OAA2B,EAAE,KAAW;QACnE,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,EA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AAC,GAAG,IAAI,CAAC,OAAO,CAAC;SAC/B;QAED,IAAI,IAAA,uBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;YACpD,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;SACpE;QAED,IAAI,IAAA,kCAAoB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACtC,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;SAC/B;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAtEH,kCAuEC;AAtEiB,qBAAS,GAAG,aAAa,CAAC"}
|
package/schema/schema.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Schema =
|
|
3
|
+
exports.Schema = void 0;
|
|
4
4
|
const json_path_1 = require("../json-path");
|
|
5
|
-
const reflection_1 = require("../reflection");
|
|
6
5
|
const array_1 = require("../utils/array/array");
|
|
7
|
-
const function_1 = require("../utils/function");
|
|
8
6
|
const noop_1 = require("../utils/noop");
|
|
9
7
|
const object_1 = require("../utils/object/object");
|
|
10
8
|
const set_1 = require("../utils/set");
|
|
@@ -18,7 +16,6 @@ const uint8_array_coercer_1 = require("./coercers/uint8-array.coercer");
|
|
|
18
16
|
const schema_error_1 = require("./schema.error");
|
|
19
17
|
const types_1 = require("./types");
|
|
20
18
|
const utils_1 = require("./utils");
|
|
21
|
-
exports.getSchemaFromReflection = (0, function_1.memoizeSingle)(_getObjectSchemaFromReflection);
|
|
22
19
|
const defaultCoercers = new Map();
|
|
23
20
|
let initialize = () => {
|
|
24
21
|
exports.Schema.registerDefaultCoercer(number_coercer_1.numberCoercer);
|
|
@@ -39,20 +36,23 @@ exports.Schema = {
|
|
|
39
36
|
defaultCoercers.get(sourceType).push(coercer);
|
|
40
37
|
}
|
|
41
38
|
},
|
|
42
|
-
test(
|
|
39
|
+
test(schemaOrValueType, value, options, path = json_path_1.JsonPath.ROOT) {
|
|
40
|
+
const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
|
|
43
41
|
const result = this.testWithFastError(schema, value, options, path);
|
|
44
|
-
if (result.
|
|
42
|
+
if (result.valid) {
|
|
45
43
|
return result;
|
|
46
44
|
}
|
|
47
|
-
return {
|
|
45
|
+
return { valid: false, error: new schema_error_1.SchemaError(result.error.message, { ...result.error, fast: false }) };
|
|
48
46
|
},
|
|
49
|
-
validate(
|
|
47
|
+
validate(schemaOrValueType, value, options) {
|
|
48
|
+
const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
|
|
50
49
|
const result = this.test(schema, value, options);
|
|
51
|
-
return result.
|
|
50
|
+
return result.valid;
|
|
52
51
|
},
|
|
53
|
-
parse(
|
|
52
|
+
parse(schemaOrValueType, value, options) {
|
|
53
|
+
const schema = (0, types_1.valueTypeOrSchemaToSchema)(schemaOrValueType);
|
|
54
54
|
const result = this.test(schema, value, options);
|
|
55
|
-
if (result.
|
|
55
|
+
if (result.valid) {
|
|
56
56
|
return result.value;
|
|
57
57
|
}
|
|
58
58
|
throw result.error;
|
|
@@ -66,222 +66,189 @@ exports.Schema = {
|
|
|
66
66
|
if ((0, types_1.isValueSchema)(schema)) {
|
|
67
67
|
return testValue(schema, value, options, path);
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
if ((0, types_1.isTypeSchema)(schema)) {
|
|
70
|
+
return testType(schema, value, options, path);
|
|
71
|
+
}
|
|
72
|
+
if ((0, types_1.isObjectSchema)(schema)) {
|
|
73
|
+
return testObject(schema, value, options, path);
|
|
74
|
+
}
|
|
75
|
+
throw new Error('Unsupported schema');
|
|
70
76
|
}
|
|
71
77
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
return {
|
|
78
|
+
function testType(schema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
|
|
79
|
+
const resolvedValueType = (0, types_1.resolveValueType)(schema.type);
|
|
80
|
+
if (resolvedValueType == 'any') {
|
|
81
|
+
return { valid: true, value: value };
|
|
82
|
+
}
|
|
83
|
+
else if ((0, type_guards_1.isFunction)(resolvedValueType)) {
|
|
84
|
+
if ((value instanceof resolvedValueType) || ((0, utils_1.getValueType)(value) == resolvedValueType)) {
|
|
85
|
+
return { valid: true, value: value };
|
|
86
|
+
}
|
|
87
|
+
const objectSchema = (0, utils_1.getSchemaFromReflection)(resolvedValueType);
|
|
88
|
+
if ((0, type_guards_1.isNotNull)(objectSchema)) {
|
|
89
|
+
return testObject(objectSchema, value, options, path);
|
|
90
|
+
}
|
|
76
91
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
return { success: false, error: schema_error_1.SchemaError.expectedButGot(expected, (0, utils_1.getValueType)(value), path) };
|
|
92
|
+
else if ((resolvedValueType == 'null' && (0, type_guards_1.isNull)(value)) || (resolvedValueType == 'undefined' && (0, type_guards_1.isUndefined)(value)) || (resolvedValueType == 'any')) {
|
|
93
|
+
return { valid: true, value: value };
|
|
80
94
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(resolvedValueType, (0, utils_1.getValueType)(value), path) };
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line complexity
|
|
98
|
+
function testObject(objectSchema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
|
|
99
|
+
if (!(value instanceof Object)) {
|
|
100
|
+
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(objectSchema.sourceType ?? 'object', (0, utils_1.getValueType)(value), path) };
|
|
84
101
|
}
|
|
85
|
-
const schema = (0, utils_1.
|
|
102
|
+
const schema = (0, utils_1.normalizeObjectSchema)(objectSchema);
|
|
86
103
|
const mask = schema.mask ?? options.mask ?? false;
|
|
87
104
|
const resultValue = (0, type_guards_1.isDefined)(schema.factory?.type) ? new schema.factory.type() : {};
|
|
88
105
|
const schemaPropertyKeys = (0, object_1.objectKeys)(schema.properties);
|
|
89
106
|
const valuePropertyKeys = (0, object_1.objectKeys)(value);
|
|
90
107
|
const unknownValuePropertyKeys = (0, set_1.differenceSets)(new Set(valuePropertyKeys), new Set(schemaPropertyKeys));
|
|
91
108
|
if ((unknownValuePropertyKeys.length > 0) && !(mask || (schema.allowUnknownProperties.size > 0))) {
|
|
92
|
-
return {
|
|
109
|
+
return { valid: false, error: new schema_error_1.SchemaError('Unknown property', { path: path.add(unknownValuePropertyKeys[0]) }) };
|
|
93
110
|
}
|
|
94
111
|
for (const key of schemaPropertyKeys) {
|
|
95
112
|
const propertyResult = exports.Schema.testWithFastError(schema.properties[key], value[key], options, path.add(key));
|
|
96
|
-
if (!propertyResult.
|
|
113
|
+
if (!propertyResult.valid) {
|
|
97
114
|
return propertyResult;
|
|
98
115
|
}
|
|
99
116
|
resultValue[key] = propertyResult.value;
|
|
100
117
|
}
|
|
101
118
|
if (schema.allowUnknownProperties.size > 0) {
|
|
102
119
|
for (const key of unknownValuePropertyKeys) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!propertyResult.success && !mask) {
|
|
107
|
-
errors.push(propertyResult.error);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
resultValue[key] = propertyResult.value;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
if (errors.length > 0) {
|
|
114
|
-
return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match any allowed schemas.', { inner: errors, path }) };
|
|
120
|
+
const propertyResult = exports.Schema.testWithFastError((0, types_1.valueSchema)([...schema.allowUnknownProperties]), value[key], options, path.add(key));
|
|
121
|
+
if (!propertyResult.valid && !mask) {
|
|
122
|
+
return propertyResult;
|
|
115
123
|
}
|
|
124
|
+
resultValue[key] = propertyResult.value;
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
const testResultValue = (0, type_guards_1.isUndefined)(schema.factory) ? resultValue : (0, type_guards_1.isDefined)(schema.factory.type) ? resultValue : schema.factory.builder(resultValue);
|
|
119
|
-
return {
|
|
128
|
+
return { valid: true, value: testResultValue };
|
|
120
129
|
}
|
|
121
130
|
// eslint-disable-next-line max-lines-per-function, max-statements, complexity
|
|
122
131
|
function testValue(schema, value, options = {}, path = json_path_1.JsonPath.ROOT) {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
return {
|
|
132
|
+
const normalizedValueSchema = (0, utils_1.normalizeValueSchema)(schema);
|
|
133
|
+
if (normalizedValueSchema.optional && (0, type_guards_1.isUndefined)(value)) {
|
|
134
|
+
return { valid: true, value: value };
|
|
126
135
|
}
|
|
127
|
-
if (
|
|
128
|
-
return {
|
|
136
|
+
if (normalizedValueSchema.nullable && (0, type_guards_1.isNull)(value)) {
|
|
137
|
+
return { valid: true, value: value };
|
|
129
138
|
}
|
|
130
139
|
const context = {
|
|
131
|
-
schema:
|
|
140
|
+
schema: normalizedValueSchema,
|
|
132
141
|
options
|
|
133
142
|
};
|
|
134
143
|
/** handle arrays */
|
|
135
|
-
if (
|
|
144
|
+
if (normalizedValueSchema.array) {
|
|
136
145
|
if (!(0, type_guards_1.isArray)(value)) {
|
|
137
146
|
throw schema_error_1.SchemaError.expectedButGot(Array, (0, utils_1.getValueType)(value), path);
|
|
138
147
|
}
|
|
139
|
-
for (const arrayConstraint of
|
|
148
|
+
for (const arrayConstraint of normalizedValueSchema.arrayConstraints) {
|
|
140
149
|
const result = arrayConstraint.validate(value, path, context);
|
|
141
|
-
if (!result.
|
|
142
|
-
return {
|
|
150
|
+
if (!result.valid) {
|
|
151
|
+
return { valid: false, error: result.error };
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
const itemSchema = (0, utils_1.getArrayItemSchema)(schema);
|
|
146
155
|
const validatedItems = [];
|
|
147
156
|
for (let i = 0; i < value.length; i++) {
|
|
148
157
|
const result = testValue(itemSchema, value[i], options, path.add(i));
|
|
149
|
-
if (!result.
|
|
158
|
+
if (!result.valid) {
|
|
150
159
|
return result;
|
|
151
160
|
}
|
|
152
161
|
validatedItems.push(result.value);
|
|
153
162
|
}
|
|
154
|
-
return {
|
|
155
|
-
}
|
|
156
|
-
let valueType
|
|
157
|
-
let
|
|
158
|
-
let resultValue
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
valueType = (0, utils_1.getValueType)(resultValue);
|
|
172
|
-
validType = isValidType(valueSchema, valueType);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
if ((errors.length > 0)) {
|
|
176
|
-
return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/** try to coerce with default coercers if enabled */
|
|
181
|
-
if (!validType && (valueSchema.coerce || options.coerce == true)) {
|
|
182
|
-
const coercers = defaultCoercers.get(valueType);
|
|
183
|
-
if ((0, type_guards_1.isDefined)(coercers)) {
|
|
184
|
-
const errors = [];
|
|
185
|
-
for (const coercer of coercers) {
|
|
186
|
-
const coerceResult = coercer.coerce(resultValue, path, context);
|
|
187
|
-
if (!coerceResult.success) {
|
|
188
|
-
errors.push(coerceResult.error);
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
resultValue = coerceResult.value;
|
|
192
|
-
valueType = (0, utils_1.getValueType)(resultValue);
|
|
193
|
-
validType = isValidType(valueSchema, valueType);
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
if ((errors.length > 0)) {
|
|
197
|
-
return { success: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/** check for sub-schemas */
|
|
202
|
-
if (!validType) {
|
|
163
|
+
return { valid: true, value: validatedItems };
|
|
164
|
+
}
|
|
165
|
+
let valueType;
|
|
166
|
+
let valueTestResult;
|
|
167
|
+
let resultValue;
|
|
168
|
+
function updateCurrentState(newValue) {
|
|
169
|
+
resultValue = newValue;
|
|
170
|
+
valueType = (0, utils_1.getValueType)(newValue);
|
|
171
|
+
valueTestResult = isValidValue(normalizedValueSchema.schema, newValue, options, path);
|
|
172
|
+
}
|
|
173
|
+
updateCurrentState(value);
|
|
174
|
+
/** try to coerce */
|
|
175
|
+
if (!valueTestResult.valid) {
|
|
176
|
+
const coercers = [
|
|
177
|
+
...(normalizedValueSchema.coercers.get(valueType) ?? []),
|
|
178
|
+
...((normalizedValueSchema.coerce || options.coerce == true) ? (defaultCoercers.get(valueType) ?? []) : [])
|
|
179
|
+
];
|
|
203
180
|
const errors = [];
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const result = exports.Schema.testWithFastError(typeSchema, resultValue, options, path);
|
|
210
|
-
if (!result.success) {
|
|
211
|
-
errors.push(result.error);
|
|
181
|
+
let success = false;
|
|
182
|
+
for (const coercer of coercers) {
|
|
183
|
+
const coerceResult = coercer.coerce(resultValue, path, context);
|
|
184
|
+
if (!coerceResult.success) {
|
|
185
|
+
errors.push(coerceResult.error);
|
|
212
186
|
continue;
|
|
213
187
|
}
|
|
214
|
-
|
|
215
|
-
|
|
188
|
+
success = true;
|
|
189
|
+
updateCurrentState(coerceResult.value);
|
|
216
190
|
break;
|
|
217
191
|
}
|
|
218
|
-
if (!
|
|
219
|
-
return {
|
|
192
|
+
if (!success && (errors.length > 0)) {
|
|
193
|
+
return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value could not be coerced.', { inner: errors, path }) };
|
|
220
194
|
}
|
|
221
195
|
}
|
|
222
|
-
if (!
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
? expectedNames[0]
|
|
226
|
-
: `[${expectedNames.join(', ')}]`;
|
|
227
|
-
const expects = valueSchema.valueConstraints.map((constraint) => constraint.expects);
|
|
228
|
-
const expectsString = expects.length > 0 ? ` (${expects.join(', ')})` : '';
|
|
229
|
-
return { success: false, error: schema_error_1.SchemaError.expectedButGot(`${expectedTypeString}${expectsString}`, (0, utils_1.getValueType)(resultValue), path) };
|
|
196
|
+
if (!valueTestResult.valid) {
|
|
197
|
+
const expectsString = getExpectString(schema);
|
|
198
|
+
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(expectsString, valueType, path) };
|
|
230
199
|
}
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
200
|
+
if (normalizedValueSchema.transformers.length > 0) {
|
|
201
|
+
let transformedValue = resultValue;
|
|
202
|
+
for (const transformer of normalizedValueSchema.transformers) {
|
|
203
|
+
const transformResult = transformer.transform(transformedValue, path, context);
|
|
204
|
+
if (!transformResult.success) {
|
|
205
|
+
return { valid: false, error: transformResult.error };
|
|
206
|
+
}
|
|
207
|
+
transformedValue = transformResult.value;
|
|
234
208
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const typeString = (0, type_guards_1.isFunction)(valueType) ? valueType.name : valueType;
|
|
209
|
+
updateCurrentState(transformedValue);
|
|
210
|
+
if (!valueTestResult.valid) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
211
|
+
const typeString = (0, utils_1.getValueTypeName)(valueType);
|
|
239
212
|
throw new Error(`Transformers resulted in invalid type (${typeString}).`);
|
|
240
213
|
}
|
|
241
214
|
}
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
215
|
+
{
|
|
216
|
+
const errors = [];
|
|
217
|
+
for (const constraint of normalizedValueSchema.valueConstraints) {
|
|
218
|
+
const result = constraint.validate(resultValue, path, context);
|
|
219
|
+
if (!result.valid) {
|
|
220
|
+
errors.push(result.error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (errors.length > 0) {
|
|
224
|
+
return { valid: false, error: (errors.length == 1) ? errors[0] : new schema_error_1.SchemaError('Value did not match schema.', { path, fast: true, inner: errors }) };
|
|
246
225
|
}
|
|
247
226
|
}
|
|
248
|
-
return {
|
|
227
|
+
return { valid: true, value: resultValue };
|
|
249
228
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
const typeData = metadata.data.tryGet('schema');
|
|
259
|
-
const properties = {};
|
|
260
|
-
for (const [key, propertyMetadata] of metadata.properties) {
|
|
261
|
-
const reflectionData = propertyMetadata.data.tryGet('schema');
|
|
262
|
-
const itemType = (0, type_guards_1.isDefined)(reflectionData?.type) ? (0, types_1.deferrableValueTypesToValueTypes)(reflectionData.type) : undefined;
|
|
263
|
-
const array = ((propertyMetadata.type == Array) && (itemType != Array)) || (reflectionData?.array == true);
|
|
264
|
-
if (array && ((0, type_guards_1.isUndefined)(itemType) || ((0, type_guards_1.isArray)(itemType) && (itemType.length == 0)))) {
|
|
265
|
-
throw new Error(`Item type missing on type ${type.name} at property "${String(key)}"`);
|
|
229
|
+
function isValidValue(validSchemas, value, options, path) {
|
|
230
|
+
const errors = [];
|
|
231
|
+
for (const schema of validSchemas) {
|
|
232
|
+
const result = exports.Schema.testWithFastError(schema, value, options, path);
|
|
233
|
+
if (result.valid) {
|
|
234
|
+
return result;
|
|
266
235
|
}
|
|
267
|
-
|
|
268
|
-
type: (itemType ?? propertyMetadata.type),
|
|
269
|
-
array,
|
|
270
|
-
optional: reflectionData?.optional,
|
|
271
|
-
nullable: reflectionData?.nullable,
|
|
272
|
-
coerce: reflectionData?.coerce,
|
|
273
|
-
coercers: reflectionData?.coercers,
|
|
274
|
-
transformers: reflectionData?.transformers,
|
|
275
|
-
arrayConstraints: reflectionData?.arrayConstraints,
|
|
276
|
-
valueConstraints: reflectionData?.valueConstraints
|
|
277
|
-
};
|
|
236
|
+
errors.push(result.error);
|
|
278
237
|
}
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
};
|
|
285
|
-
|
|
238
|
+
const expectStrings = [];
|
|
239
|
+
for (const schema of validSchemas) {
|
|
240
|
+
getExpectString(schema);
|
|
241
|
+
}
|
|
242
|
+
const expectString = expectStrings.join('\n');
|
|
243
|
+
return { valid: false, error: schema_error_1.SchemaError.expectedButGot(expectString, (0, utils_1.getValueType)(value), path) };
|
|
244
|
+
}
|
|
245
|
+
function getExpectString(schema) {
|
|
246
|
+
const expectedNames = (0, utils_1.getSchemaTypeNames)(schema);
|
|
247
|
+
const expectedTypeString = (expectedNames.length == 1)
|
|
248
|
+
? expectedNames[0]
|
|
249
|
+
: `[${expectedNames.join(', ')}]`;
|
|
250
|
+
const expects = (0, types_1.isValueSchema)(schema) ? (0, array_1.toArray)(schema.valueConstraints ?? []).map((constraint) => constraint.expects) : [];
|
|
251
|
+
const expectsString = (expects.length > 0) ? ` (${expects.join(', ')})` : '';
|
|
252
|
+
return `${expectedTypeString}${expectsString}`;
|
|
286
253
|
}
|
|
287
254
|
//# sourceMappingURL=schema.js.map
|