@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
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { ResponsiveMap } from '../helpers/
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { ResponsiveMap } from '../helpers/index.js';
|
|
3
|
+
import { BooleanCodec } from './codecs/boolean-codec.js';
|
|
4
|
+
import { DateCodec } from './codecs/date-codec.js';
|
|
5
|
+
import { FilterCodec } from './codecs/filter-codec.js';
|
|
6
|
+
import { IntegerCodec } from './codecs/integer-codec.js';
|
|
7
|
+
import { NumberCodec } from './codecs/number-codec.js';
|
|
8
|
+
import { StringCodec } from './codecs/string-codec.js';
|
|
9
|
+
export declare namespace HttpParams {
|
|
10
|
+
type Initiator = string | URLSearchParams | HttpParams | Map<string, any> | Record<string, any>;
|
|
11
|
+
interface Options {
|
|
12
|
+
onChange?: () => void;
|
|
13
|
+
params?: Record<string, ParamDefinition>;
|
|
14
|
+
}
|
|
15
|
+
type ParamDefinition = StrictOmit<HttpParamMetadata, 'codec'> & {
|
|
16
|
+
codec?: Codec | string;
|
|
17
|
+
};
|
|
18
|
+
interface Codec {
|
|
19
|
+
decode(value: string): any;
|
|
20
|
+
encode(value: any): string;
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
|
-
interface
|
|
16
|
-
codec:
|
|
23
|
+
interface HttpParamMetadata {
|
|
24
|
+
codec: HttpParams.Codec;
|
|
17
25
|
array?: boolean | 'strict';
|
|
18
26
|
arrayDelimiter?: string;
|
|
19
27
|
minArrayItems?: number;
|
|
20
28
|
maxArrayItems?: number;
|
|
21
29
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
onChange?: () => void;
|
|
27
|
-
params?: Record<string, HttpParamDefinition>;
|
|
28
|
-
}
|
|
30
|
+
declare const kEntries: unique symbol;
|
|
31
|
+
declare const kSize: unique symbol;
|
|
32
|
+
declare const kParamDefs: unique symbol;
|
|
33
|
+
declare const kOptions: unique symbol;
|
|
29
34
|
export declare class HttpParams {
|
|
30
35
|
protected static kEntries: symbol;
|
|
31
36
|
protected static kSize: symbol;
|
|
32
37
|
protected static kParamDefs: symbol;
|
|
33
38
|
protected static kOptions: symbol;
|
|
34
|
-
protected [kEntries]: ResponsiveMap<
|
|
39
|
+
protected [kEntries]: ResponsiveMap<any[]>;
|
|
35
40
|
protected [kSize]: number;
|
|
36
|
-
protected [kOptions]:
|
|
37
|
-
protected [kParamDefs]: Map<string,
|
|
38
|
-
constructor(init?:
|
|
41
|
+
protected [kOptions]: HttpParams.Options;
|
|
42
|
+
protected [kParamDefs]: Map<string, HttpParamMetadata>;
|
|
43
|
+
constructor(init?: HttpParams.Initiator, options?: HttpParams.Options);
|
|
39
44
|
get size(): number;
|
|
40
45
|
/**
|
|
41
46
|
* Appends a new value to the existing set of values for a parameter
|
|
42
47
|
* and returns this instance
|
|
43
48
|
*/
|
|
44
49
|
append(name: string, value?: any): this;
|
|
45
|
-
appendAll(input:
|
|
50
|
+
appendAll(input: HttpParams.Initiator): this;
|
|
46
51
|
changed(): void;
|
|
47
52
|
clear(): void;
|
|
48
53
|
/**
|
|
@@ -85,9 +90,9 @@ export declare class HttpParams {
|
|
|
85
90
|
* separated by `&`s.
|
|
86
91
|
*/
|
|
87
92
|
toString(): string;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
getProxy(): Record<string, any>;
|
|
94
|
+
define(params: Record<string, HttpParams.ParamDefinition>): this;
|
|
95
|
+
define(name: string, options: HttpParams.ParamDefinition): this;
|
|
91
96
|
encodeValue(value: any, key: string): string;
|
|
92
97
|
decodeValue(value: string, key: string): any;
|
|
93
98
|
protected _append(name: string, value?: any): void;
|
|
@@ -95,5 +100,14 @@ export declare class HttpParams {
|
|
|
95
100
|
protected _set(name: string, value: any, index?: number): void;
|
|
96
101
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
97
102
|
get [Symbol.toStringTag](): string;
|
|
103
|
+
static codecs: {
|
|
104
|
+
boolean: BooleanCodec;
|
|
105
|
+
date: DateCodec;
|
|
106
|
+
filter: FilterCodec;
|
|
107
|
+
integer: IntegerCodec;
|
|
108
|
+
number: NumberCodec;
|
|
109
|
+
string: StringCodec;
|
|
110
|
+
};
|
|
98
111
|
}
|
|
112
|
+
export declare function encodeURIParam(v: string): string;
|
|
99
113
|
export {};
|
package/esm/http/http-params.js
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
var _a, _b, _c;
|
|
2
2
|
import { splitString, tokenize } from 'fast-tokenizer';
|
|
3
|
-
import { ResponsiveMap } from '../helpers/
|
|
4
|
-
import { BooleanCodec } from './
|
|
5
|
-
import { DateCodec } from './
|
|
6
|
-
import { FilterCodec } from './
|
|
7
|
-
import { IntegerCodec } from './
|
|
8
|
-
import { NumberCodec } from './
|
|
9
|
-
import { StringCodec } from './
|
|
10
|
-
import { encodeURIParam } from './utils/encodeURIParam.js';
|
|
3
|
+
import { ResponsiveMap } from '../helpers/index.js';
|
|
4
|
+
import { BooleanCodec } from './codecs/boolean-codec.js';
|
|
5
|
+
import { DateCodec } from './codecs/date-codec.js';
|
|
6
|
+
import { FilterCodec } from './codecs/filter-codec.js';
|
|
7
|
+
import { IntegerCodec } from './codecs/integer-codec.js';
|
|
8
|
+
import { NumberCodec } from './codecs/number-codec.js';
|
|
9
|
+
import { StringCodec } from './codecs/string-codec.js';
|
|
11
10
|
const kEntries = Symbol('kEntries');
|
|
12
11
|
const kSize = Symbol('kSize');
|
|
13
12
|
const kParamDefs = Symbol('kParamDefs');
|
|
14
13
|
const kOptions = Symbol('kOptions');
|
|
15
|
-
const defaultKeyDecoder = (s) => decodeURIComponent(s);
|
|
16
|
-
const defaultValueDecoder = (s) => decodeURIComponent(s);
|
|
17
|
-
const defaultKeyEncoder = (s) => encodeURIParam(s);
|
|
18
|
-
const defaultValueEncoder = (s) => encodeURIParam(s);
|
|
19
|
-
const internalCodecs = {
|
|
20
|
-
'boolean': new BooleanCodec(),
|
|
21
|
-
'date': new DateCodec(),
|
|
22
|
-
'filter': new FilterCodec(),
|
|
23
|
-
'integer': new IntegerCodec(),
|
|
24
|
-
'number': new NumberCodec(),
|
|
25
|
-
'string': new StringCodec()
|
|
26
|
-
};
|
|
27
14
|
export class HttpParams {
|
|
28
15
|
constructor(init, options) {
|
|
29
16
|
this[_a] = new ResponsiveMap();
|
|
@@ -64,7 +51,7 @@ export class HttpParams {
|
|
|
64
51
|
quotes: true,
|
|
65
52
|
brackets: true
|
|
66
53
|
});
|
|
67
|
-
const k =
|
|
54
|
+
const k = decodeURIComponent(itemTokenizer.next() || '');
|
|
68
55
|
const v = this.decodeValue(itemTokenizer.join('='), k);
|
|
69
56
|
this._append(k, v);
|
|
70
57
|
}
|
|
@@ -139,7 +126,7 @@ export class HttpParams {
|
|
|
139
126
|
* Retrieves value of a given parameter at given index
|
|
140
127
|
*/
|
|
141
128
|
get(name, index = 0) {
|
|
142
|
-
const values = this[kEntries].get(name
|
|
129
|
+
const values = this[kEntries].get(name);
|
|
143
130
|
return values && values.length > index ? values[index] : null;
|
|
144
131
|
}
|
|
145
132
|
/**
|
|
@@ -190,46 +177,66 @@ export class HttpParams {
|
|
|
190
177
|
toString() {
|
|
191
178
|
const out = [];
|
|
192
179
|
this.forEach((v, k) => {
|
|
193
|
-
out.push(
|
|
180
|
+
out.push(encodeURIParam(k) +
|
|
194
181
|
(v ? '=' + this.encodeValue(v, k) : ''));
|
|
195
182
|
});
|
|
196
183
|
return out.join('&');
|
|
197
184
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
185
|
+
getProxy() {
|
|
186
|
+
const _this = this;
|
|
187
|
+
return this[kEntries].getProxy({
|
|
188
|
+
get(target, p, receiver) {
|
|
189
|
+
if (typeof p === 'string') {
|
|
190
|
+
const v = _this[kEntries].get(p);
|
|
191
|
+
return v ? (v.length > 1 ? v : v[0]) : undefined;
|
|
192
|
+
}
|
|
193
|
+
return Reflect.get(target, p, receiver);
|
|
194
|
+
},
|
|
195
|
+
set(target, p, newValue, receiver) {
|
|
196
|
+
if (typeof p === 'string') {
|
|
197
|
+
_this.set(p, newValue);
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return Reflect.set(target, p, newValue, receiver);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
define(arg0, options) {
|
|
205
|
+
if (typeof arg0 === 'object') {
|
|
206
|
+
for (const [name, def] of Object.entries(arg0))
|
|
207
|
+
this.define(name, def);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
if (!arg0)
|
|
211
|
+
throw new Error('"name" argument required');
|
|
212
|
+
if (!options)
|
|
213
|
+
throw new Error('"options" argument required');
|
|
214
|
+
if (typeof options.codec === 'string' && !HttpParams.codecs[options.codec])
|
|
202
215
|
throw new Error(`Unknown url parameter format name "${options.codec}"`);
|
|
203
216
|
const codec = (typeof options?.codec === 'string'
|
|
204
|
-
?
|
|
205
|
-
: options?.codec) ||
|
|
217
|
+
? HttpParams.codecs[options.codec]
|
|
218
|
+
: options?.codec) || HttpParams.codecs.string;
|
|
206
219
|
const meta = {
|
|
207
220
|
...options,
|
|
208
221
|
codec
|
|
209
222
|
};
|
|
210
|
-
this[kParamDefs].set(
|
|
223
|
+
this[kParamDefs].set(arg0, meta);
|
|
211
224
|
return this;
|
|
212
225
|
}
|
|
213
|
-
encodeKey(key) {
|
|
214
|
-
return (this[kOptions].encodeKey || defaultKeyEncoder)(key);
|
|
215
|
-
}
|
|
216
|
-
decodeKey(key) {
|
|
217
|
-
return (this[kOptions].decodeKey || defaultKeyDecoder)(key);
|
|
218
|
-
}
|
|
219
226
|
encodeValue(value, key) {
|
|
220
227
|
const prmDef = this[kParamDefs].get(key);
|
|
221
228
|
if (prmDef) {
|
|
222
229
|
const delimReplace = '%' + (prmDef.arrayDelimiter || ',').charCodeAt(0).toString(16).toUpperCase();
|
|
223
|
-
const fn = (x) => encodeURIParam(prmDef.codec.encode(x))
|
|
230
|
+
const fn = (x) => encodeURIParam(prmDef.codec.encode(x))
|
|
231
|
+
.replace(/,/g, delimReplace);
|
|
224
232
|
return Array.isArray(value)
|
|
225
233
|
? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
|
|
226
234
|
: fn(value);
|
|
227
235
|
}
|
|
228
|
-
return (
|
|
236
|
+
return encodeURIParam(value);
|
|
229
237
|
}
|
|
230
238
|
decodeValue(value, key) {
|
|
231
239
|
const prmDef = this[kParamDefs].get(key);
|
|
232
|
-
const valueDecoder = (this[kOptions].decodeValue || defaultValueDecoder);
|
|
233
240
|
let val = value;
|
|
234
241
|
if (prmDef) {
|
|
235
242
|
if (prmDef.array) {
|
|
@@ -238,11 +245,11 @@ export class HttpParams {
|
|
|
238
245
|
brackets: true,
|
|
239
246
|
quotes: true,
|
|
240
247
|
keepQuotes: false
|
|
241
|
-
}).map((x) =>
|
|
248
|
+
}).map((x) => decodeURIComponent(x));
|
|
242
249
|
}
|
|
243
250
|
else
|
|
244
|
-
val =
|
|
245
|
-
const fn = (x) => prmDef.codec.decode(
|
|
251
|
+
val = decodeURIComponent(val);
|
|
252
|
+
const fn = (x) => prmDef.codec.decode(decodeURIComponent(x));
|
|
246
253
|
val = Array.isArray(val) ? val.map(fn) : fn(val);
|
|
247
254
|
if (prmDef.array === 'strict')
|
|
248
255
|
val = Array.isArray(val) ? val : [val];
|
|
@@ -256,7 +263,7 @@ export class HttpParams {
|
|
|
256
263
|
}
|
|
257
264
|
return val;
|
|
258
265
|
}
|
|
259
|
-
return
|
|
266
|
+
return decodeURIComponent(value);
|
|
260
267
|
}
|
|
261
268
|
_append(name, value) {
|
|
262
269
|
let values = this[kEntries].get(name);
|
|
@@ -315,3 +322,28 @@ HttpParams.kEntries = kEntries;
|
|
|
315
322
|
HttpParams.kSize = kSize;
|
|
316
323
|
HttpParams.kParamDefs = kParamDefs;
|
|
317
324
|
HttpParams.kOptions = kOptions;
|
|
325
|
+
HttpParams.codecs = {
|
|
326
|
+
'boolean': new BooleanCodec(),
|
|
327
|
+
'date': new DateCodec(),
|
|
328
|
+
'filter': new FilterCodec(),
|
|
329
|
+
'integer': new IntegerCodec(),
|
|
330
|
+
'number': new NumberCodec(),
|
|
331
|
+
'string': new StringCodec()
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Encode input string with standard encodeURIComponent and then un-encode specific characters.
|
|
335
|
+
*/
|
|
336
|
+
const ENCODING_REGEX = /%(\d[a-f0-9])/gi;
|
|
337
|
+
const ENCODING_REPLACEMENTS = {
|
|
338
|
+
'2C': ',',
|
|
339
|
+
'2F': '/',
|
|
340
|
+
'24': '$',
|
|
341
|
+
'3A': ':',
|
|
342
|
+
'3B': ';',
|
|
343
|
+
'3D': '=',
|
|
344
|
+
'3F': '?',
|
|
345
|
+
'40': '@'
|
|
346
|
+
};
|
|
347
|
+
export function encodeURIParam(v) {
|
|
348
|
+
return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
|
|
349
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import { Readable } from 'stream';
|
|
7
|
+
import { HttpMessage } from './http-message.host.js';
|
|
8
|
+
export interface HttpRequestMessage extends HttpMessage {
|
|
9
|
+
/**
|
|
10
|
+
* In case of server request, the HTTP version sent by the client. In the case of
|
|
11
|
+
* client response, the HTTP version of the connected-to server.
|
|
12
|
+
* Probably either `'1.1'` or `'1.0'`.
|
|
13
|
+
*
|
|
14
|
+
* Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
|
|
15
|
+
* @since v0.1.1
|
|
16
|
+
*/
|
|
17
|
+
httpVersion: string;
|
|
18
|
+
httpVersionMajor: number;
|
|
19
|
+
httpVersionMinor: number;
|
|
20
|
+
/**
|
|
21
|
+
* The request/response headers object.
|
|
22
|
+
*
|
|
23
|
+
* Key-value pairs of header names and values. Header names are lower-cased.
|
|
24
|
+
*/
|
|
25
|
+
readonly headers: IncomingHttpHeaders;
|
|
26
|
+
/**
|
|
27
|
+
* The raw request/response headers list exactly as they were received.
|
|
28
|
+
*/
|
|
29
|
+
rawHeaders: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The request/response trailers object.
|
|
32
|
+
*/
|
|
33
|
+
readonly trailers: NodeJS.Dict<string>;
|
|
34
|
+
/**
|
|
35
|
+
* The raw request/response trailer keys and values exactly as they were received.
|
|
36
|
+
*/
|
|
37
|
+
rawTrailers: string[];
|
|
38
|
+
readonly complete: boolean;
|
|
39
|
+
readonly upgrade?: any;
|
|
40
|
+
/**
|
|
41
|
+
* Return the protocol string "http" or "https"
|
|
42
|
+
* when requested with TLS. When the "trust proxy"
|
|
43
|
+
* setting is enabled the "X-Forwarded-Proto" header
|
|
44
|
+
* field will be trusted. If you're running behind
|
|
45
|
+
* a reverse proxy that supplies https for you this
|
|
46
|
+
* may be enabled.
|
|
47
|
+
*/
|
|
48
|
+
protocol: string;
|
|
49
|
+
/**
|
|
50
|
+
* Short-hand for:
|
|
51
|
+
*
|
|
52
|
+
* req.protocol == 'https'
|
|
53
|
+
*/
|
|
54
|
+
secure: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Return the remote address, or when
|
|
57
|
+
* "trust proxy" is `true` return
|
|
58
|
+
* the upstream addr.
|
|
59
|
+
*/
|
|
60
|
+
ip: string;
|
|
61
|
+
/**
|
|
62
|
+
* When "trust proxy" is `true`, parse
|
|
63
|
+
* the "X-Forwarded-For" ip address list.
|
|
64
|
+
*
|
|
65
|
+
* For example if the value were "client, proxy1, proxy2"
|
|
66
|
+
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
67
|
+
* where "proxy2" is the furthest down-stream.
|
|
68
|
+
*/
|
|
69
|
+
ips: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Parse the "Host" header field hostname.
|
|
72
|
+
*/
|
|
73
|
+
hostname: string;
|
|
74
|
+
method: string;
|
|
75
|
+
url: string;
|
|
76
|
+
baseUrl: string;
|
|
77
|
+
query: Record<string, any>;
|
|
78
|
+
/**
|
|
79
|
+
* Return request header.
|
|
80
|
+
*
|
|
81
|
+
* The `Referrer` header field is special-cased,
|
|
82
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
83
|
+
*
|
|
84
|
+
* Examples:
|
|
85
|
+
*
|
|
86
|
+
* req.get('Content-Type');
|
|
87
|
+
* // => "text/plain"
|
|
88
|
+
*
|
|
89
|
+
* req.get('content-type');
|
|
90
|
+
* // => "text/plain"
|
|
91
|
+
*
|
|
92
|
+
* req.get('Something');
|
|
93
|
+
* // => undefined
|
|
94
|
+
*
|
|
95
|
+
* Aliased as `req.header()`.
|
|
96
|
+
*/
|
|
97
|
+
get(name: 'set-cookie'): string[] | undefined;
|
|
98
|
+
get(name: string): string | undefined;
|
|
99
|
+
header(name: 'set-cookie'): string[] | undefined;
|
|
100
|
+
header(name: string): string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if the given `type(s)` is acceptable, returning
|
|
103
|
+
* the best match when true, otherwise `undefined`, in which
|
|
104
|
+
* case you should respond with 406 "Not Acceptable".
|
|
105
|
+
*
|
|
106
|
+
* The `type` value may be a single mime type string
|
|
107
|
+
* such as "application/json", the extension name
|
|
108
|
+
* such as "json", a comma-delimted list such as "json, html, text/plain",
|
|
109
|
+
* or an array `["json", "html", "text/plain"]`. When a list
|
|
110
|
+
* or array is given the _best_ match, if any is returned.
|
|
111
|
+
*
|
|
112
|
+
* Examples:
|
|
113
|
+
*
|
|
114
|
+
* // Accept: text/html
|
|
115
|
+
* req.accepts('html');
|
|
116
|
+
* // => "html"
|
|
117
|
+
*
|
|
118
|
+
* // Accept: text/*, application/json
|
|
119
|
+
* req.accepts('html');
|
|
120
|
+
* // => "html"
|
|
121
|
+
* req.accepts('text/html');
|
|
122
|
+
* // => "text/html"
|
|
123
|
+
* req.accepts('json, text');
|
|
124
|
+
* // => "json"
|
|
125
|
+
* req.accepts('application/json');
|
|
126
|
+
* // => "application/json"
|
|
127
|
+
*
|
|
128
|
+
* // Accept: text/*, application/json
|
|
129
|
+
* req.accepts('image/png');
|
|
130
|
+
* req.accepts('png');
|
|
131
|
+
* // => undefined
|
|
132
|
+
*
|
|
133
|
+
* // Accept: text/*;q=.5, application/json
|
|
134
|
+
* req.accepts(['html', 'json']);
|
|
135
|
+
* req.accepts('html, json');
|
|
136
|
+
* // => "json"
|
|
137
|
+
*/
|
|
138
|
+
accepts(): string[];
|
|
139
|
+
accepts(type: string): string | false;
|
|
140
|
+
accepts(type: string[]): string | false;
|
|
141
|
+
accepts(...type: string[]): string | false;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the first accepted charset of the specified character sets,
|
|
144
|
+
* based on the request's Accept-Charset HTTP header field.
|
|
145
|
+
* If none of the specified charsets is accepted, returns false.
|
|
146
|
+
*
|
|
147
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
148
|
+
*/
|
|
149
|
+
acceptsCharsets(): string[];
|
|
150
|
+
acceptsCharsets(charset: string): string | false;
|
|
151
|
+
acceptsCharsets(charset: string[]): string | false;
|
|
152
|
+
acceptsCharsets(...charset: string[]): string | false;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the first accepted encoding of the specified encodings,
|
|
155
|
+
* based on the request's Accept-Encoding HTTP header field.
|
|
156
|
+
* If none of the specified encodings is accepted, returns false.
|
|
157
|
+
*
|
|
158
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
159
|
+
*/
|
|
160
|
+
acceptsEncodings(): string[];
|
|
161
|
+
acceptsEncodings(encoding: string): string | false;
|
|
162
|
+
acceptsEncodings(encoding: string[]): string | false;
|
|
163
|
+
acceptsEncodings(...encoding: string[]): string | false;
|
|
164
|
+
/**
|
|
165
|
+
* Returns the first accepted language of the specified languages,
|
|
166
|
+
* based on the request's Accept-Language HTTP header field.
|
|
167
|
+
* If none of the specified languages is accepted, returns false.
|
|
168
|
+
*
|
|
169
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
170
|
+
*/
|
|
171
|
+
acceptsLanguages(): string[];
|
|
172
|
+
acceptsLanguages(lang: string): string | false;
|
|
173
|
+
acceptsLanguages(lang: string[]): string | false;
|
|
174
|
+
acceptsLanguages(...lang: string[]): string | false;
|
|
175
|
+
/**
|
|
176
|
+
* Check if the incoming request contains the "Content-Type"
|
|
177
|
+
* header field, and it contains the give mime `type`.
|
|
178
|
+
*
|
|
179
|
+
* Examples:
|
|
180
|
+
*
|
|
181
|
+
* // With Content-Type: text/html; charset=utf-8
|
|
182
|
+
* req.is('html');
|
|
183
|
+
* req.is('text/html');
|
|
184
|
+
* req.is('text/*');
|
|
185
|
+
* // => true
|
|
186
|
+
*
|
|
187
|
+
* // When Content-Type is application/json
|
|
188
|
+
* req.is('json');
|
|
189
|
+
* req.is('application/json');
|
|
190
|
+
* req.is('application/*');
|
|
191
|
+
* // => true
|
|
192
|
+
*
|
|
193
|
+
* req.is('html');
|
|
194
|
+
* // => false
|
|
195
|
+
*/
|
|
196
|
+
is(type: string | string[]): string | false | null;
|
|
197
|
+
is(...types: string[]): string | false | null;
|
|
198
|
+
}
|
|
199
|
+
export declare namespace HttpRequestMessage {
|
|
200
|
+
interface Initiator extends HttpMessage.Initiator {
|
|
201
|
+
httpVersionMajor?: number;
|
|
202
|
+
httpVersionMinor?: number;
|
|
203
|
+
method: string;
|
|
204
|
+
url: string;
|
|
205
|
+
protocol?: string;
|
|
206
|
+
baseUrl?: string;
|
|
207
|
+
ip?: string;
|
|
208
|
+
ips?: [];
|
|
209
|
+
}
|
|
210
|
+
function create(init: Initiator): HttpRequestMessage;
|
|
211
|
+
function fromBuffer(buffer: Buffer | ArrayBuffer): HttpRequestMessage;
|
|
212
|
+
function fromStream(readable: Readable): Promise<HttpRequestMessage>;
|
|
213
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import accepts from 'accepts';
|
|
2
|
+
import { HTTPParser } from 'http-parser-js';
|
|
3
|
+
import typeIs from 'type-is';
|
|
4
|
+
import { HttpMessageHost } from './http-message.host.js';
|
|
5
|
+
import { HttpParams } from './http-params.js';
|
|
6
|
+
const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
|
|
7
|
+
export var HttpRequestMessage;
|
|
8
|
+
(function (HttpRequestMessage) {
|
|
9
|
+
function create(init) {
|
|
10
|
+
return HttpRequestMessageHost.create(init);
|
|
11
|
+
}
|
|
12
|
+
HttpRequestMessage.create = create;
|
|
13
|
+
function fromBuffer(buffer) {
|
|
14
|
+
return HttpRequestMessageHost.fromBuffer(buffer);
|
|
15
|
+
}
|
|
16
|
+
HttpRequestMessage.fromBuffer = fromBuffer;
|
|
17
|
+
async function fromStream(readable) {
|
|
18
|
+
return HttpRequestMessageHost.fromStream(readable);
|
|
19
|
+
}
|
|
20
|
+
HttpRequestMessage.fromStream = fromStream;
|
|
21
|
+
})(HttpRequestMessage || (HttpRequestMessage = {}));
|
|
22
|
+
const kQuery = Symbol('kQuery');
|
|
23
|
+
const kQueryProxy = Symbol('kQueryProxy');
|
|
24
|
+
const kProtocol = Symbol('kProtocol');
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
class HttpRequestMessageHost extends HttpMessageHost {
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.httpVersionMajor = 1;
|
|
32
|
+
this.httpVersionMinor = 0;
|
|
33
|
+
this[kQuery] = new HttpParams();
|
|
34
|
+
this[kQueryProxy] = this[kQuery].getProxy();
|
|
35
|
+
}
|
|
36
|
+
get httpVersion() {
|
|
37
|
+
return this.httpVersionMajor + '.' + this.httpVersionMinor;
|
|
38
|
+
}
|
|
39
|
+
set httpVersion(value) {
|
|
40
|
+
const m = HTTP_VERSION_PATTERN.exec(value);
|
|
41
|
+
if (!m)
|
|
42
|
+
throw new TypeError(`Invalid http version string (${value})`);
|
|
43
|
+
this.httpVersionMajor = parseInt(m[1], 10);
|
|
44
|
+
this.httpVersionMinor = parseInt(m[2], 10);
|
|
45
|
+
}
|
|
46
|
+
get hostname() {
|
|
47
|
+
let host = this.get('X-Forwarded-Host') || this.get('Host');
|
|
48
|
+
if (host && host.indexOf(',') !== -1) {
|
|
49
|
+
// Note: X-Forwarded-Host is normally only ever a single value, but this is to be safe.
|
|
50
|
+
host = host.substring(0, host.indexOf(',')).trimEnd();
|
|
51
|
+
}
|
|
52
|
+
if (!host)
|
|
53
|
+
return '';
|
|
54
|
+
// IPv6 literal support
|
|
55
|
+
const offset = host[0] === '['
|
|
56
|
+
? host.indexOf(']') + 1
|
|
57
|
+
: 0;
|
|
58
|
+
const index = host.indexOf(':', offset);
|
|
59
|
+
return index !== -1
|
|
60
|
+
? host.substring(0, index)
|
|
61
|
+
: host;
|
|
62
|
+
}
|
|
63
|
+
get protocol() {
|
|
64
|
+
if (this[kProtocol])
|
|
65
|
+
return this[kProtocol];
|
|
66
|
+
// Note: X-Forwarded-Proto is normally only ever a
|
|
67
|
+
// single value, but this is to be safe.
|
|
68
|
+
const header = this.get('X-Forwarded-Proto');
|
|
69
|
+
if (header) {
|
|
70
|
+
const index = header.indexOf(',');
|
|
71
|
+
return index !== -1
|
|
72
|
+
? header.substring(0, index).trim()
|
|
73
|
+
: header.trim();
|
|
74
|
+
}
|
|
75
|
+
return 'http';
|
|
76
|
+
}
|
|
77
|
+
set protocol(v) {
|
|
78
|
+
this[kProtocol] = v;
|
|
79
|
+
}
|
|
80
|
+
get secure() {
|
|
81
|
+
return this.protocol === 'https';
|
|
82
|
+
}
|
|
83
|
+
get query() {
|
|
84
|
+
return this[kQueryProxy];
|
|
85
|
+
}
|
|
86
|
+
set query(value) {
|
|
87
|
+
this[kQuery].clear();
|
|
88
|
+
this[kQuery].appendAll(value);
|
|
89
|
+
}
|
|
90
|
+
header(name) {
|
|
91
|
+
return this.getHeader(name);
|
|
92
|
+
}
|
|
93
|
+
accepts(...type) {
|
|
94
|
+
const accept = accepts(this);
|
|
95
|
+
// eslint-disable-next-line prefer-spread
|
|
96
|
+
return accept.types.apply(accept, type);
|
|
97
|
+
}
|
|
98
|
+
acceptsCharsets(...charset) {
|
|
99
|
+
const accept = accepts(this);
|
|
100
|
+
// eslint-disable-next-line prefer-spread
|
|
101
|
+
return accept.charsets.apply(accept, charset);
|
|
102
|
+
}
|
|
103
|
+
acceptsEncodings(...encoding) {
|
|
104
|
+
const accept = accepts(this);
|
|
105
|
+
// eslint-disable-next-line prefer-spread
|
|
106
|
+
return accept.encodings.apply(accept, encoding);
|
|
107
|
+
}
|
|
108
|
+
acceptsLanguages(...lang) {
|
|
109
|
+
const accept = accepts(this);
|
|
110
|
+
// eslint-disable-next-line prefer-spread
|
|
111
|
+
return accept.languages.apply(accept, lang);
|
|
112
|
+
}
|
|
113
|
+
is(type, ...otherTypes) {
|
|
114
|
+
const types = Array.isArray(type) ? type : [type];
|
|
115
|
+
if (otherTypes.length)
|
|
116
|
+
types.push(...otherTypes);
|
|
117
|
+
const contentType = this.getHeader('content-type');
|
|
118
|
+
return contentType ? typeIs.is(contentType, types) : null;
|
|
119
|
+
}
|
|
120
|
+
_init(init) {
|
|
121
|
+
super._init(init);
|
|
122
|
+
this.method = init.method.toUpperCase();
|
|
123
|
+
this.url = init.url;
|
|
124
|
+
this.baseUrl = init.baseUrl || this.url;
|
|
125
|
+
this.protocol = init.protocol;
|
|
126
|
+
}
|
|
127
|
+
[HttpMessageHost.kOnHeaderReceived](info) {
|
|
128
|
+
super[HttpMessageHost.kOnHeaderReceived](info);
|
|
129
|
+
this.method = HTTPParser.methods[info.method];
|
|
130
|
+
this.url = info.url;
|
|
131
|
+
this.baseUrl = info.url;
|
|
132
|
+
}
|
|
133
|
+
static create(init) {
|
|
134
|
+
const msg = new HttpRequestMessageHost();
|
|
135
|
+
msg._init(init);
|
|
136
|
+
return msg;
|
|
137
|
+
}
|
|
138
|
+
static fromBuffer(buffer) {
|
|
139
|
+
const msg = new HttpRequestMessageHost();
|
|
140
|
+
msg._parseBuffer(buffer, HTTPParser.REQUEST);
|
|
141
|
+
return msg;
|
|
142
|
+
}
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
144
|
+
static async fromStream(readable) {
|
|
145
|
+
throw new Error('fromStream is not implemented yet');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
HttpRequestMessageHost.kQuery = kQuery;
|