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