@opra/common 0.13.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,29 @@
|
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import type { ApiDocument } from '../api-document.js';
|
|
4
|
+
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
5
|
+
export declare namespace Resource {
|
|
6
|
+
interface InitArguments extends StrictOmit<OpraSchema.ResourceBase, 'kind'> {
|
|
7
|
+
name: string;
|
|
8
|
+
controller?: object | Type;
|
|
9
|
+
}
|
|
10
|
+
interface DecoratorOptions extends Partial<Pick<InitArguments, 'name' | 'description'>> {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export interface Resource {
|
|
14
|
+
readonly document: ApiDocument;
|
|
15
|
+
readonly kind: OpraSchema.Resource.Kind;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
readonly controller?: object | Type;
|
|
19
|
+
exportSchema(): OpraSchema.ResourceBase;
|
|
20
|
+
toString(): string;
|
|
21
|
+
[nodeInspectCustom](): string;
|
|
22
|
+
_construct(init: Resource.InitArguments): void;
|
|
23
|
+
}
|
|
24
|
+
export interface ResourceConstructor {
|
|
25
|
+
readonly prototype: Resource;
|
|
26
|
+
new (document: ApiDocument, init: Resource.InitArguments): Resource;
|
|
27
|
+
(...args: any[]): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const Resource: ResourceConstructor;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { omitUndefined } from '../../helpers/object-utils.js';
|
|
2
|
+
import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
|
|
3
|
+
export const Resource = function (document, init) {
|
|
4
|
+
if (!(this instanceof Resource)) {
|
|
5
|
+
throw new TypeError(`Class constructor must be called with "new" keyword`);
|
|
6
|
+
// noinspection UnreachableCodeJS
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const _this = this;
|
|
10
|
+
_this.document = document;
|
|
11
|
+
_this.name = init.name;
|
|
12
|
+
_this.description = init.description;
|
|
13
|
+
_this.controller = init.controller;
|
|
14
|
+
_this._construct(init);
|
|
15
|
+
};
|
|
16
|
+
const proto = {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
_construct(init) {
|
|
19
|
+
// Do nothing
|
|
20
|
+
},
|
|
21
|
+
exportSchema() {
|
|
22
|
+
return omitUndefined({
|
|
23
|
+
kind: this.kind,
|
|
24
|
+
description: this.description
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
toString() {
|
|
28
|
+
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || '#anonymous'}]`;
|
|
29
|
+
},
|
|
30
|
+
[nodeInspectCustom]() {
|
|
31
|
+
return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset}` +
|
|
32
|
+
` ${colorFgMagenta + this.name + colorReset}]`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
Object.assign(Resource.prototype, proto);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import type { TypeThunkAsync } from '../../types.js';
|
|
4
|
+
import type { ApiDocument } from '../api-document.js';
|
|
5
|
+
import { ComplexType } from '../data-type/complex-type.js';
|
|
6
|
+
import { Resource } from './resource.js';
|
|
7
|
+
export declare namespace Singleton {
|
|
8
|
+
export interface InitArguments extends Resource.InitArguments, Pick<OpraSchema.Singleton, 'operations'> {
|
|
9
|
+
type: ComplexType;
|
|
10
|
+
}
|
|
11
|
+
export interface DecoratorOptions extends Resource.DecoratorOptions {
|
|
12
|
+
}
|
|
13
|
+
export interface Metadata extends StrictOmit<OpraSchema.Singleton, 'type'> {
|
|
14
|
+
name: string;
|
|
15
|
+
type: TypeThunkAsync | string;
|
|
16
|
+
}
|
|
17
|
+
interface Operation {
|
|
18
|
+
handlerName?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Operations {
|
|
21
|
+
create?: OpraSchema.Singleton.CreateOperation & Operation;
|
|
22
|
+
delete?: OpraSchema.Singleton.DeleteOperation & Operation;
|
|
23
|
+
get?: OpraSchema.Singleton.GetOperation & Operation;
|
|
24
|
+
update?: OpraSchema.Singleton.UpdateOperation & Operation;
|
|
25
|
+
}
|
|
26
|
+
export type CreateOperationOptions = StrictOmit<OpraSchema.Singleton.CreateOperation, 'handler'>;
|
|
27
|
+
export type DeleteOperationOptions = StrictOmit<OpraSchema.Singleton.DeleteOperation, 'handler'>;
|
|
28
|
+
export type GetOperationOptions = StrictOmit<OpraSchema.Singleton.GetOperation, 'handler'>;
|
|
29
|
+
export type UpdateOperationOptions = StrictOmit<OpraSchema.Singleton.UpdateOperation, 'handler'>;
|
|
30
|
+
export {};
|
|
31
|
+
}
|
|
32
|
+
export interface Singleton extends StrictOmit<Resource, 'exportSchema' | '_construct'> {
|
|
33
|
+
readonly type: ComplexType;
|
|
34
|
+
readonly operations: Singleton.Operations;
|
|
35
|
+
readonly controller?: object | Type;
|
|
36
|
+
exportSchema(): OpraSchema.Singleton;
|
|
37
|
+
normalizeFieldNames(fields: string[]): string[] | undefined;
|
|
38
|
+
_construct(init: Singleton.InitArguments): void;
|
|
39
|
+
}
|
|
40
|
+
export interface SingletonConstructor {
|
|
41
|
+
prototype: Singleton;
|
|
42
|
+
new (document: ApiDocument, init: Singleton.InitArguments): Singleton;
|
|
43
|
+
(type: TypeThunkAsync | string, options?: Singleton.DecoratorOptions): ClassDecorator;
|
|
44
|
+
CreateOperation: (options?: Singleton.CreateOperationOptions) => PropertyDecorator;
|
|
45
|
+
GetOperation: (options?: Singleton.GetOperationOptions) => PropertyDecorator;
|
|
46
|
+
DeleteOperation: (options?: Singleton.DeleteOperationOptions) => PropertyDecorator;
|
|
47
|
+
UpdateOperation: (options?: Singleton.UpdateOperationOptions) => PropertyDecorator;
|
|
48
|
+
}
|
|
49
|
+
export declare const Singleton: SingletonConstructor;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import omit from 'lodash.omit';
|
|
2
|
+
import { omitUndefined } from '../../helpers/index.js';
|
|
3
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
4
|
+
import { METADATA_KEY } from '../constants.js';
|
|
5
|
+
import { Resource } from './resource.js';
|
|
6
|
+
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
7
|
+
const NAME_PATTERN = /^(.*)(Resource|Singleton)$/;
|
|
8
|
+
export const Singleton = function (...args) {
|
|
9
|
+
// ClassDecorator
|
|
10
|
+
if (!this) {
|
|
11
|
+
const [type, options] = args;
|
|
12
|
+
return function (target) {
|
|
13
|
+
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
14
|
+
const metadata = Reflect.getOwnMetadata(METADATA_KEY, target) || {};
|
|
15
|
+
metadata.kind = OpraSchema.Singleton.Kind;
|
|
16
|
+
metadata.name = name;
|
|
17
|
+
metadata.type = type;
|
|
18
|
+
// Merge with previous metadata object
|
|
19
|
+
const m = Reflect.getMetadata(METADATA_KEY, target);
|
|
20
|
+
if (m && metadata !== m)
|
|
21
|
+
Object.assign(metadata, omit(m), Object.keys(metadata));
|
|
22
|
+
// Merge options
|
|
23
|
+
if (options)
|
|
24
|
+
Object.assign(metadata, omit(options, ['kind', 'name', 'type', 'controller']));
|
|
25
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target);
|
|
26
|
+
/* Define Injectable metadata for NestJS support*/
|
|
27
|
+
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Constructor
|
|
31
|
+
const [document, init] = args;
|
|
32
|
+
// call super()
|
|
33
|
+
Resource.apply(this, [document, init]);
|
|
34
|
+
};
|
|
35
|
+
const proto = {
|
|
36
|
+
_construct(init) {
|
|
37
|
+
// call super()
|
|
38
|
+
Resource.prototype._construct.call(this, init);
|
|
39
|
+
const _this = this;
|
|
40
|
+
_this.kind = OpraSchema.Singleton.Kind;
|
|
41
|
+
_this.controller = init.controller;
|
|
42
|
+
const operations = _this.operations = init.operations || {};
|
|
43
|
+
_this.type = init.type;
|
|
44
|
+
if (_this.controller) {
|
|
45
|
+
const instance = typeof _this.controller == 'function'
|
|
46
|
+
? new _this.controller()
|
|
47
|
+
: _this.controller;
|
|
48
|
+
for (const operation of Object.values(operations)) {
|
|
49
|
+
if (!operation.handler && operation.handlerName) {
|
|
50
|
+
const fn = instance[operation.handlerName];
|
|
51
|
+
if (!fn)
|
|
52
|
+
throw new TypeError(`No such operation handler (${operation.handlerName}) found`);
|
|
53
|
+
operation.handler = fn.bind(instance);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
exportSchema() {
|
|
59
|
+
const out = Resource.prototype.exportSchema.call(this);
|
|
60
|
+
Object.assign(out, omitUndefined({
|
|
61
|
+
type: this.type.name,
|
|
62
|
+
operations: this.operations
|
|
63
|
+
}));
|
|
64
|
+
return out;
|
|
65
|
+
},
|
|
66
|
+
normalizeFieldNames(fields) {
|
|
67
|
+
return this.type.normalizeFieldNames(fields);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
Object.assign(Singleton.prototype, proto);
|
|
71
|
+
Object.setPrototypeOf(Singleton.prototype, Resource.prototype);
|
|
72
|
+
function createOperationDecorator(operation) {
|
|
73
|
+
return (options) => ((target, propertyKey) => {
|
|
74
|
+
const metadata = {
|
|
75
|
+
...options,
|
|
76
|
+
handlerName: propertyKey
|
|
77
|
+
};
|
|
78
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
79
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
80
|
+
resourceMetadata.operations[operation] = metadata;
|
|
81
|
+
Reflect.defineMetadata(METADATA_KEY, resourceMetadata, target.constructor);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
Singleton.CreateOperation = createOperationDecorator('create');
|
|
85
|
+
Singleton.GetOperation = createOperationDecorator('get');
|
|
86
|
+
Singleton.DeleteOperation = createOperationDecorator('delete');
|
|
87
|
+
Singleton.UpdateOperation = createOperationDecorator('update');
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { OpraException } from '../opra-exception.js';
|
|
2
|
+
/**
|
|
3
|
+
* The server cannot find the requested resource.
|
|
4
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
5
|
+
*/
|
|
2
6
|
export declare class ResourceNotFoundError extends OpraException {
|
|
3
7
|
constructor(resource: string, keyValue?: any, cause?: Error);
|
|
4
8
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { translate } from '../../i18n/index.js';
|
|
2
2
|
import { OpraException } from '../opra-exception.js';
|
|
3
|
+
/**
|
|
4
|
+
* The server cannot find the requested resource.
|
|
5
|
+
* This can also mean that the endpoint is valid but the resource itself does not exist.
|
|
6
|
+
*/
|
|
3
7
|
export class ResourceNotFoundError extends OpraException {
|
|
4
8
|
constructor(resource, keyValue, cause) {
|
|
5
9
|
super({
|
package/esm/filter/parse.js
CHANGED
|
@@ -23,7 +23,9 @@ export function parseFilter(text, visitor) {
|
|
|
23
23
|
const errMsgs = [];
|
|
24
24
|
for (const err of errors) {
|
|
25
25
|
errMsgs.push(err.message +
|
|
26
|
-
|
|
26
|
+
(text.includes('\n')
|
|
27
|
+
? (' at ' + 'line: ' + err.line + ' column: ' + err.column)
|
|
28
|
+
: (' at ' + ' column: ' + err.column)));
|
|
27
29
|
}
|
|
28
30
|
const e = new SyntaxError(errMsgs.join('\n'));
|
|
29
31
|
e.errors = errors;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import promisify from 'putil-promisify';
|
|
2
|
+
import { isConstructor } from './type-guards.js';
|
|
3
|
+
export async function resolveThunk(thunk) {
|
|
4
|
+
thunk = promisify.isPromise(thunk) ? await thunk : thunk;
|
|
5
|
+
if (typeof thunk === 'function') {
|
|
6
|
+
if (isConstructor(thunk))
|
|
7
|
+
return thunk;
|
|
8
|
+
return resolveClass(thunk());
|
|
9
|
+
}
|
|
10
|
+
return thunk;
|
|
11
|
+
}
|
|
12
|
+
export async function resolveClass(thunk) {
|
|
13
|
+
thunk = promisify.isPromise(thunk) ? await thunk : thunk;
|
|
14
|
+
if (typeof thunk !== 'function')
|
|
15
|
+
throw new Error(`No Class type resolved`);
|
|
16
|
+
if (isConstructor(thunk))
|
|
17
|
+
return thunk;
|
|
18
|
+
return resolveClass(thunk());
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getStackFileName(position?: number): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const PATH_PATTERN = /^(?:file:\/\/)?(.+)$/;
|
|
2
|
+
export function getStackFileName(position = 1) {
|
|
3
|
+
if (position >= Error.stackTraceLimit) {
|
|
4
|
+
throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' +
|
|
5
|
+
position + '` and Error.stackTraceLimit was: `' + Error.stackTraceLimit + '`');
|
|
6
|
+
}
|
|
7
|
+
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
8
|
+
Error.prepareStackTrace = (_, stack) => stack;
|
|
9
|
+
const stack = new Error().stack;
|
|
10
|
+
Error.prepareStackTrace = oldPrepareStackTrace;
|
|
11
|
+
if (stack !== null && typeof stack === 'object') {
|
|
12
|
+
// stack[0] holds this file
|
|
13
|
+
// stack[1] holds where this function was called
|
|
14
|
+
const s = stack[position] ?
|
|
15
|
+
stack[position].getFileName() : undefined;
|
|
16
|
+
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
17
|
+
return m ? m[1] : '';
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
}
|
package/esm/helpers/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
export * from './function-utils.js';
|
|
2
|
+
export * from './get-stack-filename.js';
|
|
3
|
+
export * from './is-url.js';
|
|
4
|
+
export * from './mixin-utils.js';
|
|
5
|
+
export * from './object-utils.js';
|
|
6
|
+
export * from './path-to-object-tree.js';
|
|
1
7
|
export * from './responsive-map.js';
|
|
8
|
+
export * from './type-guards.js';
|
package/esm/helpers/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
export * from './function-utils.js';
|
|
2
|
+
export * from './get-stack-filename.js';
|
|
3
|
+
export * from './is-url.js';
|
|
4
|
+
export * from './mixin-utils.js';
|
|
5
|
+
export * from './object-utils.js';
|
|
6
|
+
export * from './path-to-object-tree.js';
|
|
1
7
|
export * from './responsive-map.js';
|
|
8
|
+
export * from './type-guards.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isUrl(url: string): boolean;
|
|
@@ -12,3 +12,14 @@ export function cloneObject(obj, jsonOnly) {
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
export function omitUndefined(obj) {
|
|
16
|
+
if (!(obj && typeof obj === 'object'))
|
|
17
|
+
return obj;
|
|
18
|
+
for (const k of Object.keys(obj)) {
|
|
19
|
+
if (obj[k] === undefined)
|
|
20
|
+
delete obj[k];
|
|
21
|
+
else if (typeof obj[k] === 'object')
|
|
22
|
+
omitUndefined(obj[k]);
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const
|
|
2
|
-
export function
|
|
3
|
-
if (!arr.length)
|
|
1
|
+
const DOT_PATTERN = /^([^.]+)\.(.*)$/;
|
|
2
|
+
export function pathToObjectTree(arr, lowerCaseKeys) {
|
|
3
|
+
if (!(arr && arr.length))
|
|
4
4
|
return;
|
|
5
|
-
return
|
|
5
|
+
return _pathToObjectTree(arr, {}, lowerCaseKeys);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _pathToObjectTree(arr, target, lowerCaseKeys) {
|
|
8
8
|
for (let k of arr) {
|
|
9
9
|
if (lowerCaseKeys)
|
|
10
10
|
k = k.toLowerCase();
|
|
11
|
-
const m =
|
|
11
|
+
const m = DOT_PATTERN.exec(k);
|
|
12
12
|
if (m) {
|
|
13
13
|
const key = m[1];
|
|
14
14
|
if (target[key] === true)
|
|
15
15
|
continue;
|
|
16
16
|
const sub = target[key] = typeof target[key] === 'object' ? target[key] : {};
|
|
17
|
-
|
|
17
|
+
_pathToObjectTree([m[2]], sub);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
target[k] = true;
|
|
@@ -2,7 +2,7 @@ export interface ResponsiveMapOptions {
|
|
|
2
2
|
wellKnownKeys?: string[];
|
|
3
3
|
caseSensitive?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export type ResponsiveMapInit<
|
|
5
|
+
export type ResponsiveMapInit<V> = ResponsiveMap<V> | Map<string, V> | Record<any, V>;
|
|
6
6
|
declare const kKeyMap: unique symbol;
|
|
7
7
|
declare const kKeyOrder: unique symbol;
|
|
8
8
|
declare const kWellKnownKeys: unique symbol;
|
|
@@ -10,23 +10,25 @@ declare const kOptions: unique symbol;
|
|
|
10
10
|
/**
|
|
11
11
|
* A Map implementation that supports case-insensitivity and ordered keys
|
|
12
12
|
*/
|
|
13
|
-
export declare class ResponsiveMap<
|
|
13
|
+
export declare class ResponsiveMap<V> extends Map<string, V> {
|
|
14
14
|
private [kKeyMap];
|
|
15
15
|
private [kKeyOrder];
|
|
16
16
|
private [kWellKnownKeys];
|
|
17
17
|
private [kOptions];
|
|
18
|
-
constructor(init?: ResponsiveMapInit<
|
|
18
|
+
constructor(init?: ResponsiveMapInit<V> | null, options?: ResponsiveMapOptions);
|
|
19
19
|
clear(): void;
|
|
20
|
-
get(key:
|
|
21
|
-
has(key:
|
|
22
|
-
set(key:
|
|
23
|
-
|
|
20
|
+
get(key: string): V | undefined;
|
|
21
|
+
has(key: string): boolean;
|
|
22
|
+
set(key: string, value: V): this;
|
|
23
|
+
setAll(source: ResponsiveMapInit<V>): this;
|
|
24
|
+
keys(): IterableIterator<string>;
|
|
24
25
|
values(): IterableIterator<V>;
|
|
25
|
-
entries(): IterableIterator<[
|
|
26
|
-
delete(key:
|
|
27
|
-
sort(compareFn?: (a:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
protected
|
|
26
|
+
entries(): IterableIterator<[string, V]>;
|
|
27
|
+
delete(key: string): boolean;
|
|
28
|
+
sort(compareFn?: (a: string, b: string) => number): this;
|
|
29
|
+
getProxy(handler?: ProxyHandler<Record<string, V>>): Record<string, V>;
|
|
30
|
+
[Symbol.iterator](): IterableIterator<[string, V]>;
|
|
31
|
+
protected _getOriginalKey(key: string): string;
|
|
32
|
+
protected _getStoringKey(key: string): string;
|
|
31
33
|
}
|
|
32
34
|
export {};
|
|
@@ -19,11 +19,8 @@ export class ResponsiveMap extends Map {
|
|
|
19
19
|
this[kOptions].caseSensitive = !!options?.caseSensitive;
|
|
20
20
|
if (options?.wellKnownKeys)
|
|
21
21
|
options.wellKnownKeys.forEach(k => this[kWellKnownKeys].set(k.toLowerCase(), k));
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
else if (init && typeof init === 'object')
|
|
26
|
-
Object.keys(init).forEach(k => this.set(k, init[k]));
|
|
22
|
+
if (init)
|
|
23
|
+
this.setAll(init);
|
|
27
24
|
}
|
|
28
25
|
clear() {
|
|
29
26
|
super.clear();
|
|
@@ -44,8 +41,15 @@ export class ResponsiveMap extends Map {
|
|
|
44
41
|
this[kKeyOrder].push(key);
|
|
45
42
|
return super.set(key, value);
|
|
46
43
|
}
|
|
44
|
+
setAll(source) {
|
|
45
|
+
if (isMap(source))
|
|
46
|
+
source.forEach((v, k) => this.set(k, v));
|
|
47
|
+
else
|
|
48
|
+
Object.keys(source).forEach(k => this.set(k, source[k]));
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
47
51
|
keys() {
|
|
48
|
-
return this[kKeyOrder].
|
|
52
|
+
return this[kKeyOrder][Symbol.iterator]();
|
|
49
53
|
}
|
|
50
54
|
values() {
|
|
51
55
|
let i = -1;
|
|
@@ -94,22 +98,66 @@ export class ResponsiveMap extends Map {
|
|
|
94
98
|
this[kKeyOrder].sort(compareFn);
|
|
95
99
|
return this;
|
|
96
100
|
}
|
|
101
|
+
getProxy(handler) {
|
|
102
|
+
const _this = this;
|
|
103
|
+
const finalHandler = {
|
|
104
|
+
get(target, p, receiver) {
|
|
105
|
+
if (typeof p === 'string')
|
|
106
|
+
return _this.get(p);
|
|
107
|
+
return Reflect.get(target, p, receiver);
|
|
108
|
+
},
|
|
109
|
+
set(target, p, newValue, receiver) {
|
|
110
|
+
if (typeof p === 'string') {
|
|
111
|
+
_this.set(p, newValue);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return Reflect.set(target, p, newValue, receiver);
|
|
115
|
+
},
|
|
116
|
+
has(target, p) {
|
|
117
|
+
if (typeof p === 'string')
|
|
118
|
+
return _this.has(p);
|
|
119
|
+
return Reflect.has(target, p);
|
|
120
|
+
},
|
|
121
|
+
ownKeys() {
|
|
122
|
+
return Array.from(_this.keys()).map(x => x.toLowerCase());
|
|
123
|
+
},
|
|
124
|
+
getPrototypeOf() {
|
|
125
|
+
return Object.prototype;
|
|
126
|
+
},
|
|
127
|
+
defineProperty(target, property, attributes) {
|
|
128
|
+
if (typeof property === 'string') {
|
|
129
|
+
_this.set(property, attributes.value);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
},
|
|
134
|
+
deleteProperty(target, p) {
|
|
135
|
+
if (typeof p === 'string')
|
|
136
|
+
return _this.delete(p);
|
|
137
|
+
return false;
|
|
138
|
+
},
|
|
139
|
+
getOwnPropertyDescriptor(target, key) {
|
|
140
|
+
if (typeof key === 'string') {
|
|
141
|
+
const value = finalHandler.get(target, key);
|
|
142
|
+
return { configurable: true, enumerable: true, writable: true, value };
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
...handler
|
|
146
|
+
};
|
|
147
|
+
return new Proxy({}, finalHandler);
|
|
148
|
+
}
|
|
97
149
|
[(_a = kKeyMap, _b = kKeyOrder, _c = kWellKnownKeys, _d = kOptions, Symbol.iterator)]() {
|
|
98
150
|
return this.entries();
|
|
99
151
|
}
|
|
100
152
|
_getOriginalKey(key) {
|
|
101
|
-
if (this[kOptions].caseSensitive)
|
|
153
|
+
if (!key || this[kOptions].caseSensitive)
|
|
102
154
|
return key;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(this[kWellKnownKeys].get(key.toLowerCase()) ?? key);
|
|
106
|
-
return key;
|
|
155
|
+
return this[kKeyMap].get(key.toLowerCase()) ??
|
|
156
|
+
(this[kWellKnownKeys].get(key.toLowerCase()) ?? key);
|
|
107
157
|
}
|
|
108
158
|
_getStoringKey(key) {
|
|
109
159
|
if (this[kOptions].caseSensitive)
|
|
110
160
|
return key;
|
|
111
|
-
|
|
112
|
-
return key.toLowerCase();
|
|
113
|
-
return key;
|
|
161
|
+
return key.toLowerCase();
|
|
114
162
|
}
|
|
115
163
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference lib="dom" />
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
|
-
|
|
4
|
+
import { Type } from 'ts-gems';
|
|
5
|
+
export declare function isConstructor(fn: any): fn is Type;
|
|
6
|
+
export declare function isStream(stream: any): boolean;
|
|
5
7
|
export declare function isReadable(x: any): x is Readable;
|
|
6
8
|
export declare function isReadableStream(x: any): x is ReadableStream;
|
|
7
9
|
export declare function isBlob(x: any): x is Blob;
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function isConstructor(fn) {
|
|
2
|
+
return typeof fn === 'function' && fn.prototype &&
|
|
3
|
+
fn.prototype.constructor === fn &&
|
|
4
|
+
fn.prototype.constructor.name !== 'Function' &&
|
|
5
|
+
fn.prototype.constructor.name !== 'anonymous';
|
|
6
|
+
}
|
|
7
|
+
export function isStream(stream) {
|
|
2
8
|
return stream !== null
|
|
3
9
|
&& typeof stream === 'object'
|
|
4
10
|
&& typeof stream.pipe === 'function';
|
|
5
11
|
}
|
|
6
12
|
export function isReadable(x) {
|
|
7
|
-
return
|
|
13
|
+
return isStream(x)
|
|
8
14
|
&& x.readable !== false
|
|
9
15
|
&& typeof x._read === 'function'
|
|
10
16
|
&& typeof x._readableState === 'object';
|
|
11
17
|
}
|
|
12
18
|
export function isReadableStream(x) {
|
|
13
|
-
return
|
|
19
|
+
return isStream(x)
|
|
14
20
|
&& x.readable !== false
|
|
15
21
|
&& typeof x.getReader === 'function'
|
|
16
22
|
&& typeof x.pipeThrough === 'function'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { HttpParamCodec } from '../http-param-codec.js';
|
|
2
1
|
const trueValues = ['true', 't', 'yes', 'y', '1'];
|
|
3
2
|
const falseValues = ['false', 'f', 'no', 'n', '0'];
|
|
4
|
-
export class BooleanCodec
|
|
3
|
+
export class BooleanCodec {
|
|
5
4
|
decode(value) {
|
|
6
5
|
if (value === '')
|
|
7
6
|
return true;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HttpParams } from '../http-params.js';
|
|
2
2
|
export interface DateCodecOptions {
|
|
3
3
|
time?: boolean;
|
|
4
4
|
timeZone?: boolean;
|
|
5
5
|
min?: string;
|
|
6
6
|
max?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare class DateCodec
|
|
8
|
+
export declare class DateCodec implements HttpParams.Codec {
|
|
9
9
|
time: boolean;
|
|
10
10
|
timeZone: boolean;
|
|
11
11
|
min?: string;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import { HttpParamCodec } from '../http-param-codec.js';
|
|
3
1
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
2
|
const DATE_FORMAT_PATTERN = /^(\d{4})(?:-?(0[1-9]|1[012])(?:-?([123]0|[012][1-9]|31))?)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
|
|
5
|
-
export class DateCodec
|
|
3
|
+
export class DateCodec {
|
|
6
4
|
constructor(options) {
|
|
7
|
-
super();
|
|
8
5
|
this.max = options?.max ? coerceToDateString(options.max) : undefined;
|
|
9
6
|
this.min = options?.min ? coerceToDateString(options.min) : undefined;
|
|
10
7
|
this.time = options?.time ?? true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ast, Expression } from '../../filter/ast/index.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare class FilterCodec
|
|
2
|
+
import type { HttpParams } from '../http-params.js';
|
|
3
|
+
export declare class FilterCodec implements HttpParams.Codec {
|
|
4
4
|
decode(value: string | Expression): object;
|
|
5
5
|
encode(value: Ast): string;
|
|
6
6
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Expression } from '../../filter/ast/index.js';
|
|
2
2
|
import { parseFilter } from '../../filter/parse.js';
|
|
3
|
-
|
|
4
|
-
export class FilterCodec extends HttpParamCodec {
|
|
3
|
+
export class FilterCodec {
|
|
5
4
|
decode(value) {
|
|
6
5
|
if (value instanceof Expression)
|
|
7
6
|
return value;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NumberCodec } from './number-codec.js';
|
|
2
|
+
export declare namespace IntegerCodec {
|
|
3
|
+
interface Options extends NumberCodec.Options {
|
|
4
|
+
enum?: number[];
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare class IntegerCodec extends NumberCodec {
|
|
8
|
+
enum?: number[];
|
|
9
|
+
constructor(options?: IntegerCodec.Options);
|
|
10
|
+
decode(value: string): number;
|
|
11
|
+
}
|