@opra/common 0.14.0 → 0.16.0
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/cjs/document/api-document.js +211 -0
- package/cjs/document/constants.js +6 -0
- package/cjs/document/data-type/api-field.js +82 -0
- package/cjs/document/data-type/builtin/any.type.js +14 -0
- package/cjs/document/data-type/builtin/base64.type.js +38 -0
- package/cjs/document/data-type/builtin/bigint.type.js +33 -0
- package/cjs/document/data-type/builtin/boolean.type.js +28 -0
- package/cjs/document/data-type/builtin/date.type.js +18 -0
- package/cjs/document/data-type/builtin/guid.type.js +35 -0
- package/cjs/document/data-type/builtin/index.js +13 -0
- package/cjs/document/data-type/builtin/integer.type.js +28 -0
- package/cjs/document/data-type/builtin/number.type.js +33 -0
- package/cjs/document/data-type/builtin/object.type.js +20 -0
- package/cjs/document/data-type/builtin/string.type.js +24 -0
- package/cjs/document/data-type/builtin/time.type.js +32 -0
- package/cjs/document/data-type/builtin/timestamp.type.js +29 -0
- package/cjs/document/data-type/complex-type.js +154 -0
- package/cjs/document/data-type/data-type.js +46 -0
- package/cjs/document/data-type/enum-type.js +62 -0
- package/cjs/document/data-type/mapped-type.js +96 -0
- package/cjs/document/data-type/simple-type.js +61 -0
- package/cjs/document/data-type/union-type.js +81 -0
- package/cjs/document/factory/add-references.js +20 -0
- package/cjs/document/factory/create-document.js +81 -0
- package/cjs/document/factory/factory.js +62 -0
- package/cjs/document/factory/import-resource-class.js +54 -0
- package/cjs/document/factory/import-type-class.js +137 -0
- package/cjs/document/factory/index.js +4 -0
- package/cjs/document/factory/process-resources.js +55 -0
- package/cjs/document/factory/process-types.js +191 -0
- package/cjs/document/index.js +17 -0
- package/cjs/document/resource/collection.js +185 -0
- package/cjs/document/resource/resource.js +38 -0
- package/cjs/document/resource/singleton.js +91 -0
- package/cjs/exception/opra-exception.js +2 -0
- package/cjs/exception/resource-errors/resource-not-found.error.js +4 -0
- package/cjs/filter/parse.js +3 -1
- package/cjs/helpers/function-utils.js +25 -0
- package/cjs/helpers/get-stack-filename.js +24 -0
- package/cjs/helpers/index.js +7 -0
- package/cjs/{utils → helpers}/is-url.js +2 -2
- package/cjs/{schema/utils/clone-object.util.js → helpers/object-utils.js} +13 -1
- package/cjs/{utils/path-to-tree.js → helpers/path-to-object-tree.js} +9 -9
- package/cjs/helpers/responsive-map.js +62 -14
- package/cjs/{utils → helpers}/type-guards.js +12 -5
- package/cjs/http/{param-codec → codecs}/boolean-codec.js +1 -2
- package/{esm/http/param-codec → cjs/http/codecs}/date-codec.js +5 -4
- package/cjs/http/{param-codec → codecs}/filter-codec.js +1 -2
- package/cjs/http/{param-codec → codecs}/number-codec.js +1 -3
- package/cjs/http/{param-codec → codecs}/string-codec.js +1 -3
- package/cjs/http/enums/http-headers-codes.enum.js +13 -4
- package/cjs/http/enums/http-status-messages.js +68 -0
- package/cjs/http/http-headers.js +138 -124
- package/cjs/http/http-message.host.js +251 -0
- package/cjs/http/http-params.js +78 -45
- package/cjs/http/http-request-message.js +152 -0
- package/cjs/http/http-response-message.js +238 -0
- package/cjs/http/index.js +8 -11
- package/cjs/http/multipart/batch-multipart.js +169 -153
- package/cjs/http/multipart/http-request-content.js +16 -11
- package/cjs/http/multipart/http-response-content.js +13 -10
- package/cjs/http/multipart/index.js +1 -3
- package/cjs/i18n/i18n.js +1 -1
- package/cjs/index.js +6 -5
- package/cjs/schema/constants.js +2 -9
- package/cjs/schema/data-type/complex-type.interface.js +7 -0
- package/cjs/schema/data-type/enum-type.interface.js +7 -0
- package/cjs/schema/data-type/mapped-type.interface.js +7 -0
- package/cjs/schema/data-type/simple-type.interface.js +7 -0
- package/cjs/schema/data-type/union-type.interface.js +7 -0
- package/cjs/schema/index.js +42 -26
- package/cjs/schema/resource/collection.interface.js +7 -0
- package/cjs/schema/resource/container.interface.js +7 -0
- package/cjs/schema/resource/resource.interface.js +2 -0
- package/cjs/schema/resource/singleton.interface.js +7 -0
- package/cjs/schema/type-guards.js +59 -0
- package/cjs/types.js +2 -0
- package/cjs/url/index.js +2 -2
- package/cjs/url/opra-url-path-component.js +2 -2
- package/cjs/url/opra-url-path.js +7 -4
- package/cjs/url/opra-url.js +86 -117
- package/cjs/url/utils/{path-utils.js → decode-path-component.js} +1 -46
- package/cjs/url/utils/encode-path-component.js +27 -0
- package/cjs/utils/path-utils.js +24 -0
- package/esm/document/api-document.js +211 -0
- package/esm/document/constants.js +6 -0
- package/esm/document/data-type/api-field.js +82 -0
- package/esm/document/data-type/builtin/any.type.js +14 -0
- package/esm/document/data-type/builtin/base64.type.js +38 -0
- package/esm/document/data-type/builtin/bigint.type.js +33 -0
- package/esm/document/data-type/builtin/boolean.type.js +28 -0
- package/esm/document/data-type/builtin/date.type.js +18 -0
- package/esm/document/data-type/builtin/guid.type.js +35 -0
- package/esm/document/data-type/builtin/index.js +13 -0
- package/esm/document/data-type/builtin/integer.type.js +28 -0
- package/esm/document/data-type/builtin/number.type.js +33 -0
- package/esm/document/data-type/builtin/object.type.js +20 -0
- package/esm/document/data-type/builtin/string.type.js +24 -0
- package/esm/document/data-type/builtin/time.type.js +32 -0
- package/esm/document/data-type/builtin/timestamp.type.js +29 -0
- package/esm/document/data-type/complex-type.js +154 -0
- package/esm/document/data-type/data-type.js +46 -0
- package/esm/document/data-type/enum-type.js +62 -0
- package/esm/document/data-type/mapped-type.js +96 -0
- package/esm/document/data-type/simple-type.js +61 -0
- package/esm/document/data-type/union-type.js +81 -0
- package/esm/document/factory/add-references.js +20 -0
- package/esm/document/factory/create-document.js +81 -0
- package/esm/document/factory/factory.js +62 -0
- package/esm/document/factory/import-resource-class.js +54 -0
- package/esm/document/factory/import-type-class.js +137 -0
- package/esm/document/factory/index.js +4 -0
- package/esm/document/factory/process-resources.js +55 -0
- package/esm/document/factory/process-types.js +191 -0
- package/esm/document/index.js +17 -0
- package/esm/document/resource/collection.js +185 -0
- package/esm/document/resource/resource.js +38 -0
- package/esm/document/resource/singleton.js +91 -0
- package/esm/document/utils/inspect.util.js +7 -0
- package/esm/document/utils/string-compare.util.js +11 -0
- package/esm/exception/enums/issue-severity.enum.js +5 -2
- package/esm/exception/error-issue.js +2 -1
- package/esm/exception/http-errors/bad-request.error.js +8 -4
- package/esm/exception/http-errors/failed-dependency.error.js +8 -4
- package/esm/exception/http-errors/forbidden.error.js +8 -4
- package/esm/exception/http-errors/internal-server.error.js +8 -4
- package/esm/exception/http-errors/method-not-allowed.error.js +8 -4
- package/esm/exception/http-errors/not-acceptable.error.js +8 -4
- package/esm/exception/http-errors/not-found.error.js +8 -4
- package/esm/exception/http-errors/unauthorized.error.js +8 -4
- package/esm/exception/http-errors/unprocessable-entity.error.js +8 -4
- package/esm/exception/index.js +18 -15
- package/esm/exception/opra-exception.js +9 -3
- package/esm/exception/resource-errors/resource-conflict.error.js +8 -4
- package/esm/exception/resource-errors/resource-not-found.error.js +12 -4
- package/esm/exception/wrap-exception.js +24 -20
- package/esm/filter/antlr/OpraFilterLexer.js +9 -6
- package/esm/filter/antlr/OpraFilterListener.js +5 -2
- package/esm/filter/antlr/OpraFilterParser.js +126 -79
- package/esm/filter/antlr/OpraFilterVisitor.js +5 -2
- package/esm/filter/ast/abstract/ast.js +5 -1
- package/esm/filter/ast/abstract/expression.js +6 -2
- package/esm/filter/ast/abstract/literal.js +6 -2
- package/esm/filter/ast/abstract/term.js +6 -2
- package/esm/filter/ast/expressions/arithmetic-expression.js +8 -3
- package/esm/filter/ast/expressions/array-expression.js +6 -2
- package/esm/filter/ast/expressions/comparison-expression.js +6 -2
- package/esm/filter/ast/expressions/logical-expression.js +6 -2
- package/esm/filter/ast/expressions/parentheses-expression.js +6 -2
- package/esm/filter/ast/index.js +19 -16
- package/esm/filter/ast/terms/boolean-literal.js +6 -2
- package/esm/filter/ast/terms/date-literal.js +12 -8
- package/esm/filter/ast/terms/external-constant.js +6 -2
- package/esm/filter/ast/terms/null-literal.js +6 -2
- package/esm/filter/ast/terms/number-literal.js +8 -4
- package/esm/filter/ast/terms/qualified-identifier.js +6 -2
- package/esm/filter/ast/terms/string-literal.js +8 -4
- package/esm/filter/ast/terms/time-literal.js +10 -6
- package/esm/filter/build.js +69 -45
- package/esm/filter/errors.js +9 -3
- package/esm/filter/filter-tree-visitor.js +31 -26
- package/esm/filter/index.js +8 -5
- package/esm/filter/opra-error-listener.js +8 -4
- package/esm/filter/parse.js +22 -15
- package/esm/filter/utils.js +7 -2
- package/esm/helpers/function-utils.js +25 -0
- package/esm/helpers/get-stack-filename.js +24 -0
- package/esm/helpers/index.js +11 -1
- package/esm/helpers/is-url.js +8 -0
- package/esm/{schema/type-helpers/mixin.utils.js → helpers/mixin-utils.js} +7 -2
- package/esm/helpers/object-utils.js +31 -0
- package/esm/helpers/path-to-object-tree.js +28 -0
- package/esm/helpers/responsive-map.js +67 -15
- package/esm/{utils → helpers}/type-guards.js +24 -8
- package/esm/http/{param-codec → codecs}/boolean-codec.js +5 -2
- package/{cjs/http/param-codec → esm/http/codecs}/date-codec.js +1 -4
- package/{cjs/url/formats/filter-format.js → esm/http/codecs/filter-codec.js} +5 -6
- package/{cjs/url/formats/integer-format.js → esm/http/codecs/integer-codec.js} +6 -6
- package/esm/http/{param-codec → codecs}/number-codec.js +5 -3
- package/esm/http/{param-codec → codecs}/string-codec.js +5 -3
- package/esm/http/enums/http-headers-codes.enum.js +18 -6
- package/esm/http/enums/http-status-codes.enum.js +5 -2
- package/esm/http/enums/http-status-messages.js +68 -0
- package/esm/http/http-headers.js +144 -126
- package/esm/http/http-message.host.js +251 -0
- package/esm/http/http-params.js +86 -49
- package/esm/http/http-request-message.js +152 -0
- package/esm/http/http-response-message.js +238 -0
- package/esm/http/index.js +17 -17
- package/esm/http/interfaces/client-http-headers.interface.js +2 -1
- package/esm/http/interfaces/cookie-options.interface.js +2 -0
- package/esm/http/interfaces/server-http-headers.interface.js +2 -1
- package/esm/http/multipart/batch-multipart.js +170 -149
- package/esm/http/multipart/http-request-content.js +17 -8
- package/esm/http/multipart/http-response-content.js +14 -7
- package/esm/http/multipart/index.js +2 -1
- package/esm/i18n/i18n.js +28 -23
- package/esm/i18n/index.js +9 -5
- package/esm/i18n/string-utils.js +7 -2
- package/esm/i18n/translate.js +7 -3
- package/esm/index.js +16 -10
- package/esm/schema/constants.js +4 -8
- package/esm/schema/data-type/complex-type.interface.js +7 -0
- package/esm/schema/data-type/data-type.interface.js +2 -0
- package/esm/schema/data-type/enum-type.interface.js +7 -0
- package/esm/schema/data-type/field.interface.js +2 -0
- package/esm/schema/data-type/mapped-type.interface.js +7 -0
- package/esm/schema/data-type/simple-type.interface.js +7 -0
- package/esm/schema/data-type/union-type.interface.js +7 -0
- package/esm/schema/document.interface.js +2 -0
- package/esm/schema/index.js +44 -25
- package/esm/schema/resource/collection.interface.js +7 -0
- package/esm/schema/resource/container.interface.js +7 -0
- package/esm/schema/resource/endpoint.interface.js +2 -0
- package/esm/schema/resource/resource.interface.js +2 -0
- package/esm/schema/resource/singleton.interface.js +7 -0
- package/esm/schema/type-guards.js +59 -0
- package/esm/types.js +2 -0
- package/esm/url/index.js +8 -5
- package/esm/url/opra-url-path-component.js +7 -3
- package/esm/url/opra-url-path.js +19 -12
- package/esm/url/opra-url.js +100 -127
- package/esm/url/utils/decode-path-component.js +41 -0
- package/esm/url/utils/encode-path-component.js +27 -0
- package/esm/utils/path-utils.js +24 -0
- package/package.json +23 -7
- package/types/document/api-document.d.ts +102 -0
- package/types/document/constants.d.ts +3 -0
- package/types/document/data-type/api-field.d.ts +41 -0
- package/types/document/data-type/builtin/any.type.d.ts +2 -0
- package/types/document/data-type/builtin/base64.type.d.ts +6 -0
- package/types/document/data-type/builtin/bigint.type.d.ts +6 -0
- package/types/document/data-type/builtin/boolean.type.d.ts +5 -0
- package/types/document/data-type/builtin/date.type.d.ts +4 -0
- package/types/document/data-type/builtin/guid.type.d.ts +7 -0
- package/types/document/data-type/builtin/index.d.ts +10 -0
- package/types/document/data-type/builtin/integer.type.d.ts +6 -0
- package/types/document/data-type/builtin/number.type.d.ts +6 -0
- package/types/document/data-type/builtin/object.type.d.ts +3 -0
- package/types/document/data-type/builtin/string.type.d.ts +5 -0
- package/types/document/data-type/builtin/time.type.d.ts +7 -0
- package/types/document/data-type/builtin/timestamp.type.d.ts +5 -0
- package/types/document/data-type/complex-type.d.ts +50 -0
- package/types/document/data-type/data-type.d.ts +33 -0
- package/types/document/data-type/enum-type.d.ts +32 -0
- package/types/document/data-type/mapped-type.d.ts +53 -0
- package/types/document/data-type/simple-type.d.ts +33 -0
- package/types/document/data-type/union-type.d.ts +42 -0
- package/types/document/factory/add-references.d.ts +4 -0
- package/types/document/factory/create-document.d.ts +12 -0
- package/types/document/factory/factory.d.ts +61 -0
- package/types/document/factory/import-resource-class.d.ts +10 -0
- package/types/document/factory/import-type-class.d.ts +17 -0
- package/types/document/factory/index.d.ts +1 -0
- package/types/document/factory/process-resources.d.ts +7 -0
- package/types/document/factory/process-types.d.ts +6 -0
- package/types/document/index.d.ts +14 -0
- package/types/document/resource/collection.d.ts +67 -0
- package/types/document/resource/resource.d.ts +29 -0
- package/types/document/resource/singleton.d.ts +49 -0
- package/{esm → types}/exception/resource-errors/resource-not-found.error.d.ts +4 -0
- package/types/helpers/function-utils.d.ts +4 -0
- package/types/helpers/get-stack-filename.d.ts +1 -0
- package/types/helpers/index.d.ts +8 -0
- package/types/helpers/is-url.d.ts +1 -0
- package/{esm/schema/utils/clone-object.util.d.ts → types/helpers/object-utils.d.ts} +1 -0
- package/types/helpers/path-to-object-tree.d.ts +4 -0
- package/types/helpers/responsive-map.d.ts +34 -0
- package/{esm/utils → types/helpers}/type-guards.d.ts +3 -1
- package/types/http/codecs/boolean-codec.d.ts +5 -0
- package/{esm/http/param-codec → types/http/codecs}/date-codec.d.ts +2 -2
- package/{esm/http/param-codec → types/http/codecs}/filter-codec.d.ts +2 -2
- package/types/http/codecs/integer-codec.d.ts +11 -0
- package/types/http/codecs/number-codec.d.ts +14 -0
- package/types/http/codecs/string-codec.d.ts +16 -0
- package/{esm → types}/http/enums/http-headers-codes.enum.d.ts +13 -4
- package/types/http/enums/http-status-messages.d.ts +65 -0
- package/types/http/http-headers.d.ts +86 -0
- package/types/http/http-message.host.d.ts +122 -0
- package/{esm → types}/http/http-params.d.ts +43 -29
- package/types/http/http-request-message.d.ts +213 -0
- package/types/http/http-response-message.d.ts +318 -0
- package/types/http/index.d.ts +14 -0
- package/types/http/interfaces/cookie-options.interface.d.ts +4 -0
- package/types/http/multipart/http-request-content.d.ts +0 -0
- package/types/http/multipart/http-response-content.d.ts +0 -0
- package/types/http/multipart/index.d.ts +0 -0
- package/{esm → types}/index.d.ts +6 -5
- package/types/schema/constants.d.ts +2 -0
- package/types/schema/data-type/complex-type.interface.d.ts +16 -0
- package/types/schema/data-type/data-type.interface.d.ts +14 -0
- package/types/schema/data-type/enum-type.interface.d.ts +15 -0
- package/types/schema/data-type/field.interface.d.ts +21 -0
- package/types/schema/data-type/mapped-type.interface.d.ts +11 -0
- package/types/schema/data-type/simple-type.interface.d.ts +18 -0
- package/types/schema/data-type/union-type.interface.d.ts +10 -0
- package/types/schema/document.interface.d.ts +34 -0
- package/types/schema/index.d.ts +51 -0
- package/types/schema/resource/collection.interface.d.ts +33 -0
- package/types/schema/resource/container.interface.d.ts +9 -0
- package/types/schema/resource/endpoint.interface.d.ts +29 -0
- package/types/schema/resource/resource.interface.d.ts +12 -0
- package/types/schema/resource/singleton.interface.d.ts +22 -0
- package/types/schema/type-guards.d.ts +20 -0
- package/{esm/schema → types}/types.d.ts +0 -3
- package/{esm → types}/url/index.d.ts +2 -2
- package/{esm → types}/url/opra-url.d.ts +10 -29
- package/types/url/utils/decode-path-component.d.ts +5 -0
- package/types/url/utils/encode-path-component.d.ts +1 -0
- package/types/utils/path-utils.d.ts +2 -0
- package/cjs/constants.js +0 -1
- package/cjs/http/http-param-codec.js +0 -6
- package/cjs/http/http-request-node.js +0 -105
- package/cjs/http/http-request.js +0 -89
- package/cjs/http/http-response.js +0 -23
- package/cjs/http/utils/encodeURIParam.js +0 -21
- package/cjs/http/utils/normalize-headers.js +0 -28
- package/cjs/schema/decorators/opr-collection-resource.decorator.js +0 -24
- package/cjs/schema/decorators/opr-complex-type.decorator.js +0 -28
- package/cjs/schema/decorators/opr-field.decorator.js +0 -29
- package/cjs/schema/decorators/opr-resolver.decorator.js +0 -81
- package/cjs/schema/decorators/opr-simple-type.decorator.js +0 -19
- package/cjs/schema/decorators/opr-singleton-resource.decorator.js +0 -24
- package/cjs/schema/implementation/data-type/builtin/any.type.js +0 -9
- package/cjs/schema/implementation/data-type/builtin/base64-binary.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/bigint.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/boolean.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/date-string.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/date.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/guid.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/integer.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/number.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/object.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin/string.type.js +0 -15
- package/cjs/schema/implementation/data-type/builtin-data-types.js +0 -37
- package/cjs/schema/implementation/data-type/complex-type.js +0 -110
- package/cjs/schema/implementation/data-type/data-type.js +0 -37
- package/cjs/schema/implementation/data-type/simple-type.js +0 -21
- package/cjs/schema/implementation/data-type/union-type.js +0 -24
- package/cjs/schema/implementation/document-builder.js +0 -140
- package/cjs/schema/implementation/opra-document.js +0 -183
- package/cjs/schema/implementation/query/collection-count-query.js +0 -17
- package/cjs/schema/implementation/query/collection-create-query.js +0 -23
- package/cjs/schema/implementation/query/collection-delete-many-query.js +0 -17
- package/cjs/schema/implementation/query/collection-delete-query.js +0 -25
- package/cjs/schema/implementation/query/collection-get-query.js +0 -32
- package/cjs/schema/implementation/query/collection-search-query.js +0 -45
- package/cjs/schema/implementation/query/collection-update-many-query.js +0 -18
- package/cjs/schema/implementation/query/collection-update-query.js +0 -33
- package/cjs/schema/implementation/query/field-get-query.js +0 -34
- package/cjs/schema/implementation/query/index.js +0 -22
- package/cjs/schema/implementation/query/singleton-get-query.js +0 -22
- package/cjs/schema/implementation/resource/collection-resource-info.js +0 -72
- package/cjs/schema/implementation/resource/container-resource-info.js +0 -30
- package/cjs/schema/implementation/resource/resource-info.js +0 -35
- package/cjs/schema/implementation/resource/singleton-resource-info.js +0 -44
- package/cjs/schema/implementation/schema-builder/extract-resource-metadata.util.js +0 -84
- package/cjs/schema/implementation/schema-builder/extract-type-metadata.util.js +0 -94
- package/cjs/schema/opra-schema.definition.js +0 -49
- package/cjs/schema/type-helpers/extend-type.helper.js +0 -65
- package/cjs/schema/type-helpers/mixin-type.helper.js +0 -46
- package/cjs/schema/utils/class.utils.js +0 -8
- package/cjs/schema/utils/normalize-field-array.util.js +0 -44
- package/cjs/schema/utils/path-to-tree.util.js +0 -26
- package/cjs/url/formats/boolean-format.js +0 -25
- package/cjs/url/formats/date-format.js +0 -44
- package/cjs/url/formats/format.js +0 -6
- package/cjs/url/formats/number-format.js +0 -26
- package/cjs/url/formats/string-format.js +0 -25
- package/cjs/url/opra-url-search-params.js +0 -28
- package/cjs/utils/index.js +0 -6
- package/esm/constants.js +0 -1
- package/esm/helpers/index.d.ts +0 -1
- package/esm/helpers/responsive-map.d.ts +0 -32
- package/esm/http/http-headers.d.ts +0 -70
- package/esm/http/http-param-codec.d.ts +0 -4
- package/esm/http/http-param-codec.js +0 -2
- package/esm/http/http-request-node.d.ts +0 -34
- package/esm/http/http-request-node.js +0 -101
- package/esm/http/http-request.d.ts +0 -76
- package/esm/http/http-request.js +0 -85
- package/esm/http/http-response.d.ts +0 -41
- package/esm/http/http-response.js +0 -19
- package/esm/http/index.d.ts +0 -17
- package/esm/http/multipart/batch-multipart.d.ts +0 -31
- package/esm/http/multipart/http-request-content.d.ts +0 -8
- package/esm/http/multipart/http-response-content.d.ts +0 -7
- package/esm/http/multipart/index.d.ts +0 -1
- package/esm/http/param-codec/boolean-codec.d.ts +0 -5
- package/esm/http/param-codec/filter-codec.js +0 -14
- package/esm/http/param-codec/integer-codec.d.ts +0 -9
- package/esm/http/param-codec/integer-codec.js +0 -15
- package/esm/http/param-codec/number-codec.d.ts +0 -12
- package/esm/http/param-codec/string-codec.d.ts +0 -14
- package/esm/http/utils/encodeURIParam.d.ts +0 -1
- package/esm/http/utils/encodeURIParam.js +0 -17
- package/esm/http/utils/normalize-headers.d.ts +0 -1
- package/esm/http/utils/normalize-headers.js +0 -24
- package/esm/schema/constants.d.ts +0 -8
- package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +0 -8
- package/esm/schema/decorators/opr-collection-resource.decorator.js +0 -19
- package/esm/schema/decorators/opr-complex-type.decorator.d.ts +0 -6
- package/esm/schema/decorators/opr-complex-type.decorator.js +0 -23
- package/esm/schema/decorators/opr-field.decorator.d.ts +0 -3
- package/esm/schema/decorators/opr-field.decorator.js +0 -24
- package/esm/schema/decorators/opr-resolver.decorator.d.ts +0 -8
- package/esm/schema/decorators/opr-resolver.decorator.js +0 -71
- package/esm/schema/decorators/opr-simple-type.decorator.d.ts +0 -6
- package/esm/schema/decorators/opr-simple-type.decorator.js +0 -14
- package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +0 -8
- package/esm/schema/decorators/opr-singleton-resource.decorator.js +0 -19
- package/esm/schema/implementation/data-type/builtin/any.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/any.type.js +0 -6
- package/esm/schema/implementation/data-type/builtin/base64-binary.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/base64-binary.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/bigint.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/bigint.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/boolean.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/boolean.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/date-string.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/date-string.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/date.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/date.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/guid.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/guid.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/integer.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/integer.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/number.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/number.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/object.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/object.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin/string.type.d.ts +0 -2
- package/esm/schema/implementation/data-type/builtin/string.type.js +0 -12
- package/esm/schema/implementation/data-type/builtin-data-types.d.ts +0 -4
- package/esm/schema/implementation/data-type/builtin-data-types.js +0 -34
- package/esm/schema/implementation/data-type/complex-type.d.ts +0 -29
- package/esm/schema/implementation/data-type/complex-type.js +0 -106
- package/esm/schema/implementation/data-type/data-type.d.ts +0 -17
- package/esm/schema/implementation/data-type/data-type.js +0 -33
- package/esm/schema/implementation/data-type/simple-type.d.ts +0 -12
- package/esm/schema/implementation/data-type/simple-type.js +0 -17
- package/esm/schema/implementation/data-type/union-type.d.ts +0 -16
- package/esm/schema/implementation/data-type/union-type.js +0 -19
- package/esm/schema/implementation/document-builder.d.ts +0 -16
- package/esm/schema/implementation/document-builder.js +0 -135
- package/esm/schema/implementation/opra-document.d.ts +0 -44
- package/esm/schema/implementation/opra-document.js +0 -178
- package/esm/schema/implementation/query/collection-count-query.d.ts +0 -14
- package/esm/schema/implementation/query/collection-count-query.js +0 -13
- package/esm/schema/implementation/query/collection-create-query.d.ts +0 -18
- package/esm/schema/implementation/query/collection-create-query.js +0 -19
- package/esm/schema/implementation/query/collection-delete-many-query.d.ts +0 -14
- package/esm/schema/implementation/query/collection-delete-many-query.js +0 -13
- package/esm/schema/implementation/query/collection-delete-query.d.ts +0 -10
- package/esm/schema/implementation/query/collection-delete-query.js +0 -21
- package/esm/schema/implementation/query/collection-get-query.d.ts +0 -21
- package/esm/schema/implementation/query/collection-get-query.js +0 -28
- package/esm/schema/implementation/query/collection-search-query.d.ts +0 -30
- package/esm/schema/implementation/query/collection-search-query.js +0 -41
- package/esm/schema/implementation/query/collection-update-many-query.d.ts +0 -15
- package/esm/schema/implementation/query/collection-update-many-query.js +0 -14
- package/esm/schema/implementation/query/collection-update-query.d.ts +0 -19
- package/esm/schema/implementation/query/collection-update-query.js +0 -29
- package/esm/schema/implementation/query/field-get-query.d.ts +0 -30
- package/esm/schema/implementation/query/field-get-query.js +0 -30
- package/esm/schema/implementation/query/index.d.ts +0 -27
- package/esm/schema/implementation/query/index.js +0 -17
- package/esm/schema/implementation/query/singleton-get-query.d.ts +0 -20
- package/esm/schema/implementation/query/singleton-get-query.js +0 -18
- package/esm/schema/implementation/resource/collection-resource-info.d.ts +0 -22
- package/esm/schema/implementation/resource/collection-resource-info.js +0 -68
- package/esm/schema/implementation/resource/container-resource-info.d.ts +0 -13
- package/esm/schema/implementation/resource/container-resource-info.js +0 -26
- package/esm/schema/implementation/resource/resource-info.d.ts +0 -17
- package/esm/schema/implementation/resource/resource-info.js +0 -31
- package/esm/schema/implementation/resource/singleton-resource-info.d.ts +0 -15
- package/esm/schema/implementation/resource/singleton-resource-info.js +0 -40
- package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.d.ts +0 -3
- package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.js +0 -80
- package/esm/schema/implementation/schema-builder/extract-type-metadata.util.d.ts +0 -4
- package/esm/schema/implementation/schema-builder/extract-type-metadata.util.js +0 -90
- package/esm/schema/index.d.ts +0 -25
- package/esm/schema/interfaces/child-field-query.interface.d.ts +0 -4
- package/esm/schema/interfaces/child-field-query.interface.js +0 -1
- package/esm/schema/interfaces/data-type.metadata.d.ts +0 -18
- package/esm/schema/interfaces/data-type.metadata.js +0 -1
- package/esm/schema/interfaces/resource-container.interface.d.ts +0 -8
- package/esm/schema/interfaces/resource-container.interface.js +0 -1
- package/esm/schema/interfaces/resource.metadata.d.ts +0 -18
- package/esm/schema/interfaces/resource.metadata.js +0 -1
- package/esm/schema/opra-schema.definition.d.ts +0 -178
- package/esm/schema/opra-schema.definition.js +0 -46
- package/esm/schema/type-helpers/extend-type.helper.d.ts +0 -3
- package/esm/schema/type-helpers/extend-type.helper.js +0 -60
- package/esm/schema/type-helpers/mixin-type.helper.d.ts +0 -2
- package/esm/schema/type-helpers/mixin-type.helper.js +0 -42
- package/esm/schema/types.js +0 -1
- package/esm/schema/utils/class.utils.d.ts +0 -2
- package/esm/schema/utils/class.utils.js +0 -4
- package/esm/schema/utils/clone-object.util.js +0 -14
- package/esm/schema/utils/inspect.util.js +0 -4
- package/esm/schema/utils/normalize-field-array.util.d.ts +0 -3
- package/esm/schema/utils/normalize-field-array.util.js +0 -40
- package/esm/schema/utils/path-to-tree.util.d.ts +0 -4
- package/esm/schema/utils/path-to-tree.util.js +0 -22
- package/esm/schema/utils/string-compare.util.js +0 -7
- package/esm/url/formats/boolean-format.d.ts +0 -5
- package/esm/url/formats/boolean-format.js +0 -21
- package/esm/url/formats/date-format.d.ts +0 -16
- package/esm/url/formats/date-format.js +0 -40
- package/esm/url/formats/filter-format.d.ts +0 -6
- package/esm/url/formats/filter-format.js +0 -14
- package/esm/url/formats/format.d.ts +0 -4
- package/esm/url/formats/format.js +0 -2
- package/esm/url/formats/integer-format.d.ts +0 -9
- package/esm/url/formats/integer-format.js +0 -15
- package/esm/url/formats/number-format.d.ts +0 -12
- package/esm/url/formats/number-format.js +0 -22
- package/esm/url/formats/string-format.d.ts +0 -14
- package/esm/url/formats/string-format.js +0 -21
- package/esm/url/opra-url-search-params.d.ts +0 -5
- package/esm/url/opra-url-search-params.js +0 -24
- package/esm/url/utils/path-utils.d.ts +0 -8
- package/esm/url/utils/path-utils.js +0 -78
- package/esm/utils/index.d.ts +0 -3
- package/esm/utils/index.js +0 -3
- package/esm/utils/is-url.d.ts +0 -1
- package/esm/utils/is-url.js +0 -4
- package/esm/utils/path-to-tree.d.ts +0 -4
- package/esm/utils/path-to-tree.js +0 -24
- /package/cjs/{schema → document}/utils/inspect.util.js +0 -0
- /package/cjs/{schema → document}/utils/string-compare.util.js +0 -0
- /package/cjs/{schema/type-helpers/mixin.utils.js → helpers/mixin-utils.js} +0 -0
- /package/cjs/http/{param-codec → codecs}/integer-codec.js +0 -0
- /package/cjs/{schema/interfaces/child-field-query.interface.js → http/interfaces/cookie-options.interface.js} +0 -0
- /package/cjs/schema/{interfaces/data-type.metadata.js → data-type/data-type.interface.js} +0 -0
- /package/cjs/schema/{interfaces/resource-container.interface.js → data-type/field.interface.js} +0 -0
- /package/cjs/schema/{interfaces/resource.metadata.js → document.interface.js} +0 -0
- /package/cjs/schema/{types.js → resource/endpoint.interface.js} +0 -0
- /package/{esm/schema → types/document}/utils/inspect.util.d.ts +0 -0
- /package/{esm/schema → types/document}/utils/string-compare.util.d.ts +0 -0
- /package/{esm → types}/exception/enums/issue-severity.enum.d.ts +0 -0
- /package/{esm → types}/exception/error-issue.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/bad-request.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/failed-dependency.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/forbidden.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/internal-server.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/method-not-allowed.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/not-acceptable.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/not-found.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/unauthorized.error.d.ts +0 -0
- /package/{esm → types}/exception/http-errors/unprocessable-entity.error.d.ts +0 -0
- /package/{esm → types}/exception/index.d.ts +0 -0
- /package/{esm → types}/exception/opra-exception.d.ts +0 -0
- /package/{esm → types}/exception/resource-errors/resource-conflict.error.d.ts +0 -0
- /package/{esm → types}/exception/wrap-exception.d.ts +0 -0
- /package/{esm → types}/filter/antlr/OpraFilterLexer.d.ts +0 -0
- /package/{esm → types}/filter/antlr/OpraFilterListener.d.ts +0 -0
- /package/{esm → types}/filter/antlr/OpraFilterParser.d.ts +0 -0
- /package/{esm → types}/filter/antlr/OpraFilterVisitor.d.ts +0 -0
- /package/{esm → types}/filter/ast/abstract/ast.d.ts +0 -0
- /package/{esm → types}/filter/ast/abstract/expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/abstract/literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/abstract/term.d.ts +0 -0
- /package/{esm → types}/filter/ast/expressions/arithmetic-expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/expressions/array-expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/expressions/comparison-expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/expressions/logical-expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/expressions/parentheses-expression.d.ts +0 -0
- /package/{esm → types}/filter/ast/index.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/boolean-literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/date-literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/external-constant.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/null-literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/number-literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/qualified-identifier.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/string-literal.d.ts +0 -0
- /package/{esm → types}/filter/ast/terms/time-literal.d.ts +0 -0
- /package/{esm → types}/filter/build.d.ts +0 -0
- /package/{esm → types}/filter/errors.d.ts +0 -0
- /package/{esm → types}/filter/filter-tree-visitor.d.ts +0 -0
- /package/{esm → types}/filter/index.d.ts +0 -0
- /package/{esm → types}/filter/opra-error-listener.d.ts +0 -0
- /package/{esm → types}/filter/parse.d.ts +0 -0
- /package/{esm → types}/filter/utils.d.ts +0 -0
- /package/{esm/schema/type-helpers/mixin.utils.d.ts → types/helpers/mixin-utils.d.ts} +0 -0
- /package/{esm → types}/http/enums/http-status-codes.enum.d.ts +0 -0
- /package/{esm → types}/http/interfaces/client-http-headers.interface.d.ts +0 -0
- /package/{esm → types}/http/interfaces/server-http-headers.interface.d.ts +0 -0
- /package/{esm/constants.d.ts → types/http/multipart/batch-multipart.d.ts} +0 -0
- /package/{esm → types}/i18n/i18n.d.ts +0 -0
- /package/{esm → types}/i18n/index.d.ts +0 -0
- /package/{esm → types}/i18n/string-utils.d.ts +0 -0
- /package/{esm → types}/i18n/translate.d.ts +0 -0
- /package/{esm → types}/url/opra-url-path-component.d.ts +0 -0
- /package/{esm → types}/url/opra-url-path.d.ts +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCollectionSchema = exports.extractSingletonSchema = exports.importResourceClass = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
6
|
+
const index_js_2 = require("../../schema/index.js");
|
|
7
|
+
const constants_js_1 = require("../constants.js");
|
|
8
|
+
async function importResourceClass(thunk) {
|
|
9
|
+
const { document, resourceQueue, cache } = this;
|
|
10
|
+
const controller = await (0, index_js_1.resolveThunk)(thunk);
|
|
11
|
+
const cached = cache.get(controller);
|
|
12
|
+
if (cached)
|
|
13
|
+
return cached;
|
|
14
|
+
const ctor = typeof thunk === 'function' ? thunk : Object.getPrototypeOf(thunk).constructor;
|
|
15
|
+
let metadata = Reflect.getMetadata(constants_js_1.METADATA_KEY, ctor);
|
|
16
|
+
if (!metadata && index_js_2.OpraSchema.isResource(metadata))
|
|
17
|
+
throw new TypeError(`Class "${ctor.name}" doesn't have a valid Resource metadata`);
|
|
18
|
+
// const controller = typeof thunk === 'function' ? new ctor() : thunk;
|
|
19
|
+
// Clone metadata to prevent changing its contents
|
|
20
|
+
metadata = (0, index_js_1.cloneObject)(metadata);
|
|
21
|
+
const schema = (0, index_js_1.cloneObject)(metadata);
|
|
22
|
+
schema.controller = controller;
|
|
23
|
+
cache.set(thunk, schema);
|
|
24
|
+
if (index_js_2.OpraSchema.isSingleton(schema) || index_js_2.OpraSchema.isCollection(schema)) {
|
|
25
|
+
if (!document.getDataType(metadata.type, true) && (typeof metadata.type === 'function')) {
|
|
26
|
+
await this.importTypeClass(metadata.type);
|
|
27
|
+
await this.processTypes();
|
|
28
|
+
const dataTypeCtor = await (0, index_js_1.resolveClass)(metadata.type);
|
|
29
|
+
const dataType = document.getComplexType(dataTypeCtor);
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
+
schema.type = dataType.name;
|
|
32
|
+
}
|
|
33
|
+
// Check if data type exists
|
|
34
|
+
document.getComplexType(schema.type);
|
|
35
|
+
}
|
|
36
|
+
if (index_js_2.OpraSchema.isSingleton(schema))
|
|
37
|
+
await this.extractSingletonSchema(schema, ctor, metadata, controller);
|
|
38
|
+
if (index_js_2.OpraSchema.isCollection(schema))
|
|
39
|
+
await this.extractCollectionSchema(schema, ctor, metadata, controller);
|
|
40
|
+
resourceQueue.set(metadata.name, schema);
|
|
41
|
+
}
|
|
42
|
+
exports.importResourceClass = importResourceClass;
|
|
43
|
+
async function extractSingletonSchema(
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
target, ctor, metadata, controller) {
|
|
46
|
+
// Do nothing. This method is used by external modules for extending the factory
|
|
47
|
+
}
|
|
48
|
+
exports.extractSingletonSchema = extractSingletonSchema;
|
|
49
|
+
async function extractCollectionSchema(
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
target, ctor, metadata, controller) {
|
|
52
|
+
// Do nothing. This method is used by external modules for extending the factory
|
|
53
|
+
}
|
|
54
|
+
exports.extractCollectionSchema = extractCollectionSchema;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFieldSchema = exports.extractEnumTypeSchema = exports.extractUnionTypeSchema = exports.extractMappedTypeSchema = exports.extractComplexTypeSchema = exports.extractSimpleTypeSchema = exports.importTypeClass = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const index_js_2 = require("../../schema/index.js");
|
|
6
|
+
const constants_js_1 = require("../constants.js");
|
|
7
|
+
async function importTypeClass(typeThunk) {
|
|
8
|
+
const { document, typeQueue, cache } = this;
|
|
9
|
+
const thunk = await (0, index_js_1.resolveThunk)(typeThunk);
|
|
10
|
+
const cached = cache.get(thunk);
|
|
11
|
+
if (cached)
|
|
12
|
+
return cached;
|
|
13
|
+
const dt = document.getDataType(thunk, true);
|
|
14
|
+
if (dt && dt.name)
|
|
15
|
+
return dt.name;
|
|
16
|
+
const metadata = Reflect.getMetadata(constants_js_1.METADATA_KEY, thunk);
|
|
17
|
+
if (!(metadata && index_js_2.OpraSchema.isDataType(metadata))) {
|
|
18
|
+
// If thunk is a Type class
|
|
19
|
+
if ((0, index_js_1.isConstructor)(thunk))
|
|
20
|
+
throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
|
|
21
|
+
// If thunk is an Enum object
|
|
22
|
+
throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
|
|
23
|
+
}
|
|
24
|
+
// Clone metadata to prevent changing its contents
|
|
25
|
+
const name = metadata.name;
|
|
26
|
+
const schema = (0, index_js_1.cloneObject)(metadata);
|
|
27
|
+
const result = name || schema;
|
|
28
|
+
if (name) {
|
|
29
|
+
if (this.document.types.has(name) || typeQueue.has(name))
|
|
30
|
+
throw new TypeError(`Type "${name}" already imported`);
|
|
31
|
+
cache.set(thunk, result);
|
|
32
|
+
typeQueue.set(name, schema);
|
|
33
|
+
}
|
|
34
|
+
// If thunk is a DataType class
|
|
35
|
+
if ((0, index_js_1.isConstructor)(thunk)) {
|
|
36
|
+
const ctor = thunk;
|
|
37
|
+
if (index_js_2.OpraSchema.isSimpleType(schema))
|
|
38
|
+
await this.extractSimpleTypeSchema(schema, ctor, metadata);
|
|
39
|
+
else if (index_js_2.OpraSchema.isComplexType(schema))
|
|
40
|
+
await this.extractComplexTypeSchema(schema, ctor, metadata);
|
|
41
|
+
else if (index_js_2.OpraSchema.isMappedType(schema))
|
|
42
|
+
await this.extractMappedTypeSchema(schema, ctor, metadata);
|
|
43
|
+
else if (index_js_2.OpraSchema.isUnionType(schema))
|
|
44
|
+
await this.extractUnionTypeSchema(schema, ctor, metadata);
|
|
45
|
+
else
|
|
46
|
+
throw new TypeError(`Class "${ctor.name}" doesn't have a valid DataType metadata`);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
// If thunk is a EnumType object
|
|
50
|
+
const enumObject = thunk;
|
|
51
|
+
if (index_js_2.OpraSchema.isEnumType(schema)) {
|
|
52
|
+
let baseType;
|
|
53
|
+
if (metadata.base && Reflect.hasMetadata(constants_js_1.METADATA_KEY, metadata.base)) {
|
|
54
|
+
baseType = await this.importTypeClass(metadata.base);
|
|
55
|
+
}
|
|
56
|
+
schema.base = baseType;
|
|
57
|
+
await this.extractEnumTypeSchema(schema, enumObject, metadata);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(enumObject).substring(0, 20)}...`);
|
|
61
|
+
}
|
|
62
|
+
exports.importTypeClass = importTypeClass;
|
|
63
|
+
// noinspection JSUnusedLocalSymbols
|
|
64
|
+
async function extractSimpleTypeSchema(target, ctor,
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
+
metadata) {
|
|
67
|
+
const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
|
|
68
|
+
if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
|
|
69
|
+
target.base = await this.importTypeClass(baseClass);
|
|
70
|
+
target.codec = Object.create(ctor.prototype);
|
|
71
|
+
}
|
|
72
|
+
exports.extractSimpleTypeSchema = extractSimpleTypeSchema;
|
|
73
|
+
async function extractComplexTypeSchema(target, ctor, metadata) {
|
|
74
|
+
const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
|
|
75
|
+
if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
|
|
76
|
+
target.base = await this.importTypeClass(baseClass);
|
|
77
|
+
target.ctor = ctor;
|
|
78
|
+
// Fields
|
|
79
|
+
if (metadata.fields) {
|
|
80
|
+
const fields = target.fields = {};
|
|
81
|
+
for (const [elemName, elemMeta] of Object.entries(metadata.fields)) {
|
|
82
|
+
try {
|
|
83
|
+
const t = await elemMeta.type;
|
|
84
|
+
const type = typeof t === 'function'
|
|
85
|
+
? await this.importTypeClass(t)
|
|
86
|
+
: (t || '');
|
|
87
|
+
const elemSchema = fields[elemName] = {
|
|
88
|
+
...elemMeta,
|
|
89
|
+
type
|
|
90
|
+
};
|
|
91
|
+
if (elemMeta.enum)
|
|
92
|
+
elemSchema.type = await this.importTypeClass(elemMeta.enum);
|
|
93
|
+
if (!elemSchema.type && elemMeta.designType)
|
|
94
|
+
elemSchema.type = await this.importTypeClass(elemMeta.designType);
|
|
95
|
+
await this.extractFieldSchema(elemSchema, ctor, elemMeta, elemName);
|
|
96
|
+
// Check enum again. External packages may modify enum value
|
|
97
|
+
if (elemMeta.enum)
|
|
98
|
+
elemSchema.type = await this.importTypeClass(elemMeta.enum);
|
|
99
|
+
if (typeof elemSchema.type === 'function')
|
|
100
|
+
elemSchema.type = await this.importTypeClass(elemSchema.type);
|
|
101
|
+
if (elemSchema.isArray && !elemSchema.type)
|
|
102
|
+
throw new TypeError(`"type" must be defined explicitly for array properties`);
|
|
103
|
+
elemSchema.type = elemSchema.type || 'any';
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
e.message = `Error in class "${ctor.name}.${elemName}". ` + e.message;
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.extractComplexTypeSchema = extractComplexTypeSchema;
|
|
113
|
+
async function extractMappedTypeSchema(target, ctor, metadata) {
|
|
114
|
+
target.type = await this.importTypeClass(metadata.type);
|
|
115
|
+
}
|
|
116
|
+
exports.extractMappedTypeSchema = extractMappedTypeSchema;
|
|
117
|
+
async function extractUnionTypeSchema(target, ctor, metadata) {
|
|
118
|
+
const oldTypes = metadata.types;
|
|
119
|
+
target.types = [];
|
|
120
|
+
for (const type of oldTypes)
|
|
121
|
+
target.types.push(await this.importTypeClass(type));
|
|
122
|
+
}
|
|
123
|
+
exports.extractUnionTypeSchema = extractUnionTypeSchema;
|
|
124
|
+
// noinspection JSUnusedLocalSymbols
|
|
125
|
+
async function extractEnumTypeSchema(
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
127
|
+
target, enumObject, metadata) {
|
|
128
|
+
// Do nothing. This method is used by external modules for extending the factory
|
|
129
|
+
}
|
|
130
|
+
exports.extractEnumTypeSchema = extractEnumTypeSchema;
|
|
131
|
+
// noinspection JSUnusedLocalSymbols
|
|
132
|
+
async function extractFieldSchema(
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
134
|
+
target, ctor, metadata, name) {
|
|
135
|
+
// Do nothing. This method is used by external modules for extending the factory
|
|
136
|
+
}
|
|
137
|
+
exports.extractFieldSchema = extractFieldSchema;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSingleton = exports.createCollection = exports.processResourceQueue = void 0;
|
|
4
|
+
const index_js_1 = require("../../schema/index.js");
|
|
5
|
+
const collection_js_1 = require("../resource/collection.js");
|
|
6
|
+
const singleton_js_1 = require("../resource/singleton.js");
|
|
7
|
+
async function processResourceQueue() {
|
|
8
|
+
const { document, resourceQueue } = this;
|
|
9
|
+
const resourceNames = Array.from(resourceQueue.keys());
|
|
10
|
+
for (const name of resourceNames) {
|
|
11
|
+
const schema = resourceQueue.get(name);
|
|
12
|
+
if (!schema)
|
|
13
|
+
continue;
|
|
14
|
+
try {
|
|
15
|
+
if (index_js_1.OpraSchema.isCollection(schema)) {
|
|
16
|
+
const resource = await this.createCollection(name, schema);
|
|
17
|
+
document.resources.set(name, resource);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (index_js_1.OpraSchema.isSingleton(schema)) {
|
|
21
|
+
const resource = await this.createSingleton(name, schema);
|
|
22
|
+
document.resources.set(name, resource);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
e.message = `Error in Resource schema (${name}): ` + e.message;
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
throw new TypeError(`Invalid Resource schema: ${JSON.stringify(schema).substring(0, 20)}...`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.processResourceQueue = processResourceQueue;
|
|
34
|
+
async function createCollection(name, schema) {
|
|
35
|
+
const { document } = this;
|
|
36
|
+
const dataType = document.getComplexType(schema.type);
|
|
37
|
+
const initArgs = {
|
|
38
|
+
...schema,
|
|
39
|
+
name,
|
|
40
|
+
type: dataType
|
|
41
|
+
};
|
|
42
|
+
return new collection_js_1.Collection(document, initArgs);
|
|
43
|
+
}
|
|
44
|
+
exports.createCollection = createCollection;
|
|
45
|
+
async function createSingleton(name, schema) {
|
|
46
|
+
const { document } = this;
|
|
47
|
+
const dataType = document.getComplexType(schema.type);
|
|
48
|
+
const initArgs = {
|
|
49
|
+
...schema,
|
|
50
|
+
name,
|
|
51
|
+
type: dataType
|
|
52
|
+
};
|
|
53
|
+
return new singleton_js_1.Singleton(document, initArgs);
|
|
54
|
+
}
|
|
55
|
+
exports.createSingleton = createSingleton;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addDataType = exports.createDataTypeInstance = exports.processTypes = void 0;
|
|
4
|
+
const index_js_1 = require("../../schema/index.js");
|
|
5
|
+
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
6
|
+
const enum_type_js_1 = require("../data-type/enum-type.js");
|
|
7
|
+
const mapped_type_js_1 = require("../data-type/mapped-type.js");
|
|
8
|
+
const simple_type_js_1 = require("../data-type/simple-type.js");
|
|
9
|
+
const union_type_js_1 = require("../data-type/union-type.js");
|
|
10
|
+
async function processTypes() {
|
|
11
|
+
const { document, typeQueue } = this;
|
|
12
|
+
// Create DataType instances
|
|
13
|
+
for (const [name, schema] of typeQueue.entries()) {
|
|
14
|
+
const dataType = this.createDataTypeInstance(schema.kind, name);
|
|
15
|
+
document.types.set(name, dataType);
|
|
16
|
+
}
|
|
17
|
+
// Process schemas
|
|
18
|
+
const typeNames = Array.from(typeQueue.keys());
|
|
19
|
+
for (const name of typeNames) {
|
|
20
|
+
if (!typeQueue.has(name))
|
|
21
|
+
continue;
|
|
22
|
+
this.addDataType(name);
|
|
23
|
+
}
|
|
24
|
+
document.invalidate();
|
|
25
|
+
}
|
|
26
|
+
exports.processTypes = processTypes;
|
|
27
|
+
function createDataTypeInstance(kind, name) {
|
|
28
|
+
const dataType = {
|
|
29
|
+
document: this.document,
|
|
30
|
+
kind,
|
|
31
|
+
name
|
|
32
|
+
};
|
|
33
|
+
switch (kind) {
|
|
34
|
+
case index_js_1.OpraSchema.ComplexType.Kind:
|
|
35
|
+
Object.setPrototypeOf(dataType, complex_type_js_1.ComplexType.prototype);
|
|
36
|
+
break;
|
|
37
|
+
case index_js_1.OpraSchema.EnumType.Kind:
|
|
38
|
+
Object.setPrototypeOf(dataType, enum_type_js_1.EnumType.prototype);
|
|
39
|
+
break;
|
|
40
|
+
case index_js_1.OpraSchema.MappedType.Kind:
|
|
41
|
+
Object.setPrototypeOf(dataType, mapped_type_js_1.MappedType.prototype);
|
|
42
|
+
break;
|
|
43
|
+
case index_js_1.OpraSchema.SimpleType.Kind:
|
|
44
|
+
Object.setPrototypeOf(dataType, simple_type_js_1.SimpleType.prototype);
|
|
45
|
+
break;
|
|
46
|
+
case index_js_1.OpraSchema.UnionType.Kind:
|
|
47
|
+
Object.setPrototypeOf(dataType, union_type_js_1.UnionType.prototype);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new TypeError(`Unknown DataType kind (${kind})`);
|
|
51
|
+
}
|
|
52
|
+
return dataType;
|
|
53
|
+
}
|
|
54
|
+
exports.createDataTypeInstance = createDataTypeInstance;
|
|
55
|
+
function addDataType(schemaOrName) {
|
|
56
|
+
const { document, typeQueue, circularRefs, curPath } = this;
|
|
57
|
+
const name = typeof schemaOrName === 'string' ? schemaOrName : undefined;
|
|
58
|
+
let schema;
|
|
59
|
+
let dataType;
|
|
60
|
+
if (name) {
|
|
61
|
+
// Check if data type exists in document
|
|
62
|
+
dataType = document.getDataType(name);
|
|
63
|
+
// Get schema from stack, it is already done if not exist
|
|
64
|
+
schema = typeQueue.get(name);
|
|
65
|
+
if (!schema)
|
|
66
|
+
return dataType;
|
|
67
|
+
// Detect circular refs
|
|
68
|
+
if (circularRefs.has(name))
|
|
69
|
+
throw new TypeError(`Circular reference detected. ${[...Array.from(circularRefs.keys()), name].join('>')}`);
|
|
70
|
+
circularRefs.set(name, 1);
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
schema = schemaOrName;
|
|
74
|
+
try {
|
|
75
|
+
// Init base
|
|
76
|
+
let base;
|
|
77
|
+
if ((index_js_1.OpraSchema.isSimpleType(schema) || index_js_1.OpraSchema.isComplexType(schema) || index_js_1.OpraSchema.isEnumType(schema)) && schema.base) {
|
|
78
|
+
curPath.push(typeof schema.base === 'string' ? schema.base : '[base]');
|
|
79
|
+
base = this.addDataType(schema.base);
|
|
80
|
+
curPath.pop();
|
|
81
|
+
}
|
|
82
|
+
// **** Init SimpleType ****
|
|
83
|
+
if (index_js_1.OpraSchema.isSimpleType(schema)) {
|
|
84
|
+
const initArgs = {
|
|
85
|
+
...schema,
|
|
86
|
+
name,
|
|
87
|
+
base
|
|
88
|
+
};
|
|
89
|
+
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
90
|
+
if (name)
|
|
91
|
+
curPath.push(name);
|
|
92
|
+
simple_type_js_1.SimpleType.apply(dataType, [document, initArgs]);
|
|
93
|
+
if (name)
|
|
94
|
+
curPath.pop();
|
|
95
|
+
return dataType;
|
|
96
|
+
}
|
|
97
|
+
// **** Init ComplexType ****
|
|
98
|
+
if (index_js_1.OpraSchema.isComplexType(schema)) {
|
|
99
|
+
const initArgs = {
|
|
100
|
+
...schema,
|
|
101
|
+
name,
|
|
102
|
+
base
|
|
103
|
+
};
|
|
104
|
+
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
105
|
+
if (name)
|
|
106
|
+
curPath.push(name);
|
|
107
|
+
complex_type_js_1.ComplexType.apply(dataType, [document, initArgs]);
|
|
108
|
+
if (name)
|
|
109
|
+
typeQueue.delete(name);
|
|
110
|
+
// process fields
|
|
111
|
+
if (schema.fields) {
|
|
112
|
+
for (const [elemName, v] of Object.entries(schema.fields)) {
|
|
113
|
+
const elemSchema = typeof v === 'object' ? v : { type: v };
|
|
114
|
+
curPath.push(`${name}.${elemName}[type]`);
|
|
115
|
+
const elemType = this.addDataType(elemSchema.type);
|
|
116
|
+
dataType.addField({
|
|
117
|
+
...elemSchema,
|
|
118
|
+
name: elemName,
|
|
119
|
+
type: elemType
|
|
120
|
+
});
|
|
121
|
+
curPath.pop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (name)
|
|
125
|
+
curPath.pop();
|
|
126
|
+
return dataType;
|
|
127
|
+
}
|
|
128
|
+
// **** Init EnumType ****
|
|
129
|
+
if (index_js_1.OpraSchema.isEnumType(schema)) {
|
|
130
|
+
const initArgs = {
|
|
131
|
+
...schema,
|
|
132
|
+
name,
|
|
133
|
+
base
|
|
134
|
+
};
|
|
135
|
+
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
136
|
+
if (name)
|
|
137
|
+
curPath.push(name);
|
|
138
|
+
enum_type_js_1.EnumType.apply(dataType, [document, initArgs]);
|
|
139
|
+
if (name)
|
|
140
|
+
curPath.pop();
|
|
141
|
+
return dataType;
|
|
142
|
+
}
|
|
143
|
+
// **** Init UnionType ****
|
|
144
|
+
if (index_js_1.OpraSchema.isUnionType(schema)) {
|
|
145
|
+
const unionTypes = schema.types.map(t => this.addDataType(t));
|
|
146
|
+
const initArgs = {
|
|
147
|
+
...schema,
|
|
148
|
+
name,
|
|
149
|
+
types: unionTypes
|
|
150
|
+
};
|
|
151
|
+
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
152
|
+
if (name)
|
|
153
|
+
curPath.push(name);
|
|
154
|
+
union_type_js_1.UnionType.apply(dataType, [document, initArgs]);
|
|
155
|
+
if (name)
|
|
156
|
+
curPath.pop();
|
|
157
|
+
return dataType;
|
|
158
|
+
}
|
|
159
|
+
// **** Init MappedType ****
|
|
160
|
+
if (index_js_1.OpraSchema.isMappedType(schema)) {
|
|
161
|
+
const dt = this.addDataType(schema.type);
|
|
162
|
+
if (!(dt instanceof complex_type_js_1.ComplexType))
|
|
163
|
+
throw new TypeError(`MappedType requires a ComplexType`);
|
|
164
|
+
const initArgs = {
|
|
165
|
+
...schema,
|
|
166
|
+
name,
|
|
167
|
+
type: dt
|
|
168
|
+
};
|
|
169
|
+
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
170
|
+
if (name)
|
|
171
|
+
curPath.push(name);
|
|
172
|
+
mapped_type_js_1.MappedType.apply(dataType, [document, initArgs]);
|
|
173
|
+
if (name)
|
|
174
|
+
curPath.pop();
|
|
175
|
+
return dataType;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
if (curPath.length)
|
|
180
|
+
e.message = `Error at ${curPath.join('/')}: ` + e.message;
|
|
181
|
+
throw e;
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
if (name) {
|
|
185
|
+
circularRefs.delete(name);
|
|
186
|
+
typeQueue.delete(name);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
throw new TypeError(`Invalid DataType schema: ${JSON.stringify(schema).substring(0, 20)}...`);
|
|
190
|
+
}
|
|
191
|
+
exports.addDataType = addDataType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./api-document.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./factory/index.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./data-type/data-type.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./data-type/complex-type.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./data-type/api-field.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./data-type/mapped-type.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./data-type/union-type.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./resource/resource.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./resource/collection.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./resource/singleton.js"), exports);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collection = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
+
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
|
+
const index_js_1 = require("../../exception/index.js");
|
|
8
|
+
const index_js_2 = require("../../filter/index.js");
|
|
9
|
+
const index_js_3 = require("../../helpers/index.js");
|
|
10
|
+
const index_js_4 = require("../../i18n/index.js");
|
|
11
|
+
const index_js_5 = require("../../schema/index.js");
|
|
12
|
+
const constants_js_1 = require("../constants.js");
|
|
13
|
+
const simple_type_js_1 = require("../data-type/simple-type.js");
|
|
14
|
+
const resource_js_1 = require("./resource.js");
|
|
15
|
+
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
16
|
+
const NAME_PATTERN = /^(.*)(Resource|Collection)$/;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
exports.Collection = function (...args) {
|
|
21
|
+
// ClassDecorator
|
|
22
|
+
if (!this) {
|
|
23
|
+
const [type, options] = args;
|
|
24
|
+
return function (target) {
|
|
25
|
+
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
26
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
|
|
27
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, Object.getPrototypeOf(target));
|
|
28
|
+
if (baseMetadata) {
|
|
29
|
+
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
30
|
+
}
|
|
31
|
+
metadata.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
32
|
+
metadata.name = name;
|
|
33
|
+
metadata.type = type;
|
|
34
|
+
// Merge with previous metadata object
|
|
35
|
+
const m = Reflect.getMetadata(constants_js_1.METADATA_KEY, target);
|
|
36
|
+
if (m && metadata !== m)
|
|
37
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
38
|
+
// Merge options
|
|
39
|
+
if (options)
|
|
40
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
41
|
+
Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
|
|
42
|
+
/* Define Injectable metadata for NestJS support*/
|
|
43
|
+
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Constructor
|
|
47
|
+
const [document, init] = args;
|
|
48
|
+
// call super()
|
|
49
|
+
resource_js_1.Resource.apply(this, [document, init]);
|
|
50
|
+
};
|
|
51
|
+
const proto = {
|
|
52
|
+
_construct(init) {
|
|
53
|
+
// call super()
|
|
54
|
+
resource_js_1.Resource.prototype._construct.call(this, init);
|
|
55
|
+
const _this = this;
|
|
56
|
+
_this.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
57
|
+
_this.controller = init.controller;
|
|
58
|
+
const operations = _this.operations = init.operations || {};
|
|
59
|
+
const dataType = _this.type = init.type;
|
|
60
|
+
// Validate key fields
|
|
61
|
+
_this.primaryKey = init.primaryKey
|
|
62
|
+
? (Array.isArray(init.primaryKey) ? init.primaryKey : [init.primaryKey])
|
|
63
|
+
: [];
|
|
64
|
+
if (!_this.primaryKey.length)
|
|
65
|
+
throw new TypeError(`You must provide primaryKey for Collection resource ("${_this.name}")`);
|
|
66
|
+
_this.primaryKey.forEach(f => {
|
|
67
|
+
const el = dataType.getField(f);
|
|
68
|
+
if (!(el.type instanceof simple_type_js_1.SimpleType))
|
|
69
|
+
throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${el.type.kind}`);
|
|
70
|
+
});
|
|
71
|
+
if (_this.controller) {
|
|
72
|
+
const instance = typeof _this.controller == 'function'
|
|
73
|
+
? new _this.controller()
|
|
74
|
+
: _this.controller;
|
|
75
|
+
for (const operation of Object.values(operations)) {
|
|
76
|
+
if (!operation.handler && operation.handlerName) {
|
|
77
|
+
const fn = instance[operation.handlerName];
|
|
78
|
+
if (!fn)
|
|
79
|
+
throw new TypeError(`No such operation handler (${operation.handlerName}) found`);
|
|
80
|
+
operation.handler = fn.bind(instance);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
exportSchema() {
|
|
86
|
+
const out = resource_js_1.Resource.prototype.exportSchema.call(this);
|
|
87
|
+
Object.assign(out, (0, index_js_3.omitUndefined)({
|
|
88
|
+
type: this.type.name,
|
|
89
|
+
operations: this.operations,
|
|
90
|
+
primaryKey: this.primaryKey
|
|
91
|
+
}));
|
|
92
|
+
return out;
|
|
93
|
+
},
|
|
94
|
+
parseKeyValue(value) {
|
|
95
|
+
if (!this.primaryKey?.length)
|
|
96
|
+
return;
|
|
97
|
+
const dataType = this.type;
|
|
98
|
+
if (this.primaryKey.length > 1) {
|
|
99
|
+
// Build primary key/value mapped object
|
|
100
|
+
const obj = Array.isArray(value)
|
|
101
|
+
? this.primaryKey.reduce((o, k, i) => {
|
|
102
|
+
o[k] = value[i];
|
|
103
|
+
return obj;
|
|
104
|
+
}, {})
|
|
105
|
+
: value;
|
|
106
|
+
// decode values
|
|
107
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
108
|
+
const el = dataType.getField(k);
|
|
109
|
+
obj[k] = el.type.decode(v);
|
|
110
|
+
if (obj[k] == null)
|
|
111
|
+
throw new TypeError(`You must provide value of primary field(s) (${k})`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const primaryKey = this.primaryKey[0];
|
|
116
|
+
if (typeof value === 'object')
|
|
117
|
+
value = value[primaryKey];
|
|
118
|
+
const el = dataType.getField(primaryKey);
|
|
119
|
+
const result = el.type.decode(value);
|
|
120
|
+
if (result == null)
|
|
121
|
+
throw new TypeError(`You must provide value of primary field(s) (${primaryKey})`);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
normalizeFieldNames(fields) {
|
|
126
|
+
return this.type.normalizeFieldNames(fields);
|
|
127
|
+
},
|
|
128
|
+
normalizeSortFields(fields) {
|
|
129
|
+
const normalized = this.normalizeFieldNames(fields);
|
|
130
|
+
if (!normalized)
|
|
131
|
+
return;
|
|
132
|
+
const findManyEndpoint = this.operations.findMany;
|
|
133
|
+
const sortFields = findManyEndpoint && findManyEndpoint.sortFields;
|
|
134
|
+
normalized.forEach(field => {
|
|
135
|
+
if (!sortFields?.find(x => x === field))
|
|
136
|
+
throw new index_js_1.BadRequestError({
|
|
137
|
+
message: (0, index_js_4.translate)('error:UNACCEPTED_SORT_FIELD', { field }, `Field '${field}' is not available for sort operation`),
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
return normalized;
|
|
141
|
+
},
|
|
142
|
+
normalizeFilterFields(ast) {
|
|
143
|
+
if (ast instanceof index_js_2.ComparisonExpression) {
|
|
144
|
+
this.normalizeFilterFields(ast.left);
|
|
145
|
+
}
|
|
146
|
+
else if (ast instanceof index_js_2.LogicalExpression) {
|
|
147
|
+
ast.items.forEach(item => this.normalizeFilterFields(item));
|
|
148
|
+
}
|
|
149
|
+
else if (ast instanceof index_js_2.ArithmeticExpression) {
|
|
150
|
+
ast.items.forEach(item => this.normalizeFilterFields(item.expression));
|
|
151
|
+
}
|
|
152
|
+
else if (ast instanceof index_js_2.ArrayExpression) {
|
|
153
|
+
ast.items.forEach(item => this.normalizeFilterFields(item));
|
|
154
|
+
}
|
|
155
|
+
else if (ast instanceof index_js_2.ParenthesesExpression) {
|
|
156
|
+
this.normalizeFilterFields(ast.expression);
|
|
157
|
+
}
|
|
158
|
+
else if (ast instanceof index_js_2.QualifiedIdentifier) {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
160
|
+
ast.value = this.normalizeFieldNames([ast.value])[0];
|
|
161
|
+
}
|
|
162
|
+
return ast;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
Object.assign(exports.Collection.prototype, proto);
|
|
166
|
+
Object.setPrototypeOf(exports.Collection.prototype, resource_js_1.Resource.prototype);
|
|
167
|
+
function createOperationDecorator(operation) {
|
|
168
|
+
return (options) => ((target, propertyKey) => {
|
|
169
|
+
const metadata = {
|
|
170
|
+
...options,
|
|
171
|
+
handlerName: propertyKey
|
|
172
|
+
};
|
|
173
|
+
const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target.constructor) || {});
|
|
174
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
175
|
+
resourceMetadata.operations[operation] = metadata;
|
|
176
|
+
Reflect.defineMetadata(constants_js_1.METADATA_KEY, resourceMetadata, target.constructor);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
exports.Collection.Create = createOperationDecorator('create');
|
|
180
|
+
exports.Collection.Delete = createOperationDecorator('delete');
|
|
181
|
+
exports.Collection.DeleteMany = createOperationDecorator('deleteMany');
|
|
182
|
+
exports.Collection.Get = createOperationDecorator('get');
|
|
183
|
+
exports.Collection.FindMany = createOperationDecorator('findMany');
|
|
184
|
+
exports.Collection.Update = createOperationDecorator('update');
|
|
185
|
+
exports.Collection.UpdateMany = createOperationDecorator('updateMany');
|