@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,318 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { HttpMessage, HttpMessageHost } from './http-message.host.js';
|
|
5
|
+
import type { HttpRequestMessage } from './http-request-message.js';
|
|
6
|
+
import { CookieOptions } from './interfaces/cookie-options.interface.js';
|
|
7
|
+
export interface HttpResponseMessage extends HttpMessage {
|
|
8
|
+
method?: string | undefined;
|
|
9
|
+
url?: string | undefined;
|
|
10
|
+
body?: any;
|
|
11
|
+
statusCode?: number;
|
|
12
|
+
statusMessage?: string;
|
|
13
|
+
readonly upgrade?: any;
|
|
14
|
+
/**
|
|
15
|
+
* Return request header.
|
|
16
|
+
*
|
|
17
|
+
* The `Referrer` header field is special-cased,
|
|
18
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
19
|
+
*
|
|
20
|
+
* Examples:
|
|
21
|
+
*
|
|
22
|
+
* req.get('Content-Type');
|
|
23
|
+
* // => "text/plain"
|
|
24
|
+
*
|
|
25
|
+
* req.get('content-type');
|
|
26
|
+
* // => "text/plain"
|
|
27
|
+
*
|
|
28
|
+
* req.get('Something');
|
|
29
|
+
* // => undefined
|
|
30
|
+
*
|
|
31
|
+
* Aliased as `req.header()`.
|
|
32
|
+
*/
|
|
33
|
+
get(field: string): string | undefined;
|
|
34
|
+
getHeader(name: string): number | string | string[] | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Set header `field` to `val`,
|
|
37
|
+
* or pass an object of header fields.
|
|
38
|
+
*
|
|
39
|
+
* Examples:
|
|
40
|
+
*
|
|
41
|
+
* msg.setHeader('Foo', ['bar', 'baz']);
|
|
42
|
+
* msg.setHeader('Accept', 'application/json');
|
|
43
|
+
* msg.setHeader({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
47
|
+
/**
|
|
48
|
+
* Set status `code`.
|
|
49
|
+
*/
|
|
50
|
+
status(code: number): this;
|
|
51
|
+
/**
|
|
52
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
53
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
54
|
+
*
|
|
55
|
+
* Examples:
|
|
56
|
+
*
|
|
57
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
58
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
59
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
60
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
61
|
+
*/
|
|
62
|
+
sendStatus(code: number): this;
|
|
63
|
+
/**
|
|
64
|
+
* Set Link header field with the given `links`.
|
|
65
|
+
*
|
|
66
|
+
* Examples:
|
|
67
|
+
*
|
|
68
|
+
* res.links({
|
|
69
|
+
* next: 'http://api.example.com/users?page=2',
|
|
70
|
+
* last: 'http://api.example.com/users?page=5'
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
links(links: any): this;
|
|
74
|
+
/**
|
|
75
|
+
* Send JSON response.
|
|
76
|
+
*
|
|
77
|
+
* Examples:
|
|
78
|
+
*
|
|
79
|
+
* res.json(null);
|
|
80
|
+
* res.json({ user: 'tj' });
|
|
81
|
+
* res.status(500).json('oh noes!');
|
|
82
|
+
* res.status(404).json('I dont have that');
|
|
83
|
+
*/
|
|
84
|
+
json(body: any): this;
|
|
85
|
+
/**
|
|
86
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
87
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
88
|
+
*
|
|
89
|
+
* Examples:
|
|
90
|
+
*
|
|
91
|
+
* res.type('.html');
|
|
92
|
+
* res.type('html');
|
|
93
|
+
* res.type('json');
|
|
94
|
+
* res.type('application/json');
|
|
95
|
+
* res.type('png');
|
|
96
|
+
*/
|
|
97
|
+
contentType(type: string): this;
|
|
98
|
+
/**
|
|
99
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
100
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
101
|
+
*
|
|
102
|
+
* Examples:
|
|
103
|
+
*
|
|
104
|
+
* res.type('.html');
|
|
105
|
+
* res.type('html');
|
|
106
|
+
* res.type('json');
|
|
107
|
+
* res.type('application/json');
|
|
108
|
+
* res.type('png');
|
|
109
|
+
*/
|
|
110
|
+
type(type: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
113
|
+
*/
|
|
114
|
+
attachment(filename?: string): this;
|
|
115
|
+
/**
|
|
116
|
+
* Set header `field` to `val`, or pass
|
|
117
|
+
* an object of header fields.
|
|
118
|
+
*
|
|
119
|
+
* Examples:
|
|
120
|
+
*
|
|
121
|
+
* res.set('Foo', ['bar', 'baz']);
|
|
122
|
+
* res.set('Accept', 'application/json');
|
|
123
|
+
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
124
|
+
*
|
|
125
|
+
* Aliased as `res.header()`.
|
|
126
|
+
*/
|
|
127
|
+
set(field: any): this;
|
|
128
|
+
set(field: string, value?: string | string[]): this;
|
|
129
|
+
header(field: any): this;
|
|
130
|
+
header(field: string, value?: string | string[]): this;
|
|
131
|
+
append(field: string, value?: string | string[]): this;
|
|
132
|
+
/** Clear cookie `name`. */
|
|
133
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
134
|
+
/**
|
|
135
|
+
* Set cookie `name` to `val`, with the given `options`.
|
|
136
|
+
*
|
|
137
|
+
* Options:
|
|
138
|
+
*
|
|
139
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
140
|
+
* - `signed` sign the cookie
|
|
141
|
+
* - `path` defaults to "/"
|
|
142
|
+
*
|
|
143
|
+
* Examples:
|
|
144
|
+
*
|
|
145
|
+
* // "Remember Me" for 15 minutes
|
|
146
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
147
|
+
*
|
|
148
|
+
* // save as above
|
|
149
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
150
|
+
*/
|
|
151
|
+
cookie(name: string, val: string, options: CookieOptions): this;
|
|
152
|
+
cookie(name: string, val: any, options: CookieOptions): this;
|
|
153
|
+
cookie(name: string, val: any): this;
|
|
154
|
+
/**
|
|
155
|
+
* Set the location header to `url`.
|
|
156
|
+
*
|
|
157
|
+
* The given `url` can also be the name of a mapped url, for
|
|
158
|
+
* example by default express supports "back" which redirects
|
|
159
|
+
* to the _Referrer_ or _Referer_ headers or "/".
|
|
160
|
+
*
|
|
161
|
+
* Examples:
|
|
162
|
+
*
|
|
163
|
+
* res.location('/foo/bar').;
|
|
164
|
+
* res.location('http://example.com');
|
|
165
|
+
* res.location('../login'); // /blog/post/1 -> /blog/login
|
|
166
|
+
*
|
|
167
|
+
* Mounting:
|
|
168
|
+
*
|
|
169
|
+
* When an application is mounted and `res.location()`
|
|
170
|
+
* is given a path that does _not_ lead with "/" it becomes
|
|
171
|
+
* relative to the mount-point. For example if the application
|
|
172
|
+
* is mounted at "/blog", the following would become "/blog/login".
|
|
173
|
+
*
|
|
174
|
+
* res.location('login');
|
|
175
|
+
*
|
|
176
|
+
* While the leading slash would result in a location of "/login":
|
|
177
|
+
*
|
|
178
|
+
* res.location('/login');
|
|
179
|
+
*/
|
|
180
|
+
location(url: string): this;
|
|
181
|
+
/**
|
|
182
|
+
* Redirect to the given `url` with optional response `status`
|
|
183
|
+
* defaulting to 302.
|
|
184
|
+
*
|
|
185
|
+
* The resulting `url` is determined by `res.location()`, so
|
|
186
|
+
* it will play nicely with mounted apps, relative paths,
|
|
187
|
+
* `"back"` etc.
|
|
188
|
+
*
|
|
189
|
+
* Examples:
|
|
190
|
+
*
|
|
191
|
+
* res.redirect('back');
|
|
192
|
+
* res.redirect('/foo/bar');
|
|
193
|
+
* res.redirect('http://example.com');
|
|
194
|
+
* res.redirect(301, 'http://example.com');
|
|
195
|
+
* res.redirect('http://example.com', 301);
|
|
196
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
197
|
+
*/
|
|
198
|
+
redirect(url: string): void;
|
|
199
|
+
redirect(status: number, url: string): void;
|
|
200
|
+
/** @deprecated use res.redirect(status, url) instead */
|
|
201
|
+
redirect(url: string, status: number): void;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* @namespace HttpResponseMessage
|
|
205
|
+
*/
|
|
206
|
+
export declare namespace HttpResponseMessage {
|
|
207
|
+
interface Initiator extends HttpMessage.Initiator {
|
|
208
|
+
statusCode?: number;
|
|
209
|
+
statusMessage?: string;
|
|
210
|
+
req?: HttpRequestMessage;
|
|
211
|
+
chunkedEncoding?: boolean;
|
|
212
|
+
}
|
|
213
|
+
function create(init: Initiator): HttpResponseMessage;
|
|
214
|
+
function fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
|
|
215
|
+
function fromStream(readable: Readable): Promise<HttpResponseMessage>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @class HttpResponseMessageHost
|
|
219
|
+
*/
|
|
220
|
+
export declare class HttpResponseMessageHost extends HttpMessageHost implements HttpResponseMessage {
|
|
221
|
+
chunkedEncoding?: boolean;
|
|
222
|
+
req?: HttpRequestMessage;
|
|
223
|
+
statusCode?: number;
|
|
224
|
+
statusMessage?: string;
|
|
225
|
+
constructor();
|
|
226
|
+
header(name: 'set-cookie' | 'Set-Cookie', value: string | string[]): this;
|
|
227
|
+
header(name: string, value: number | string): this;
|
|
228
|
+
header(headers: Record<string, number | string | string[]>): this;
|
|
229
|
+
append(name: string, value: string | string[]): this;
|
|
230
|
+
/**
|
|
231
|
+
* Set "Content-Disposition" header to "attachment" with optional `filename`.
|
|
232
|
+
*/
|
|
233
|
+
attachment(filename?: string): this;
|
|
234
|
+
/**
|
|
235
|
+
* Alias for msg.type()
|
|
236
|
+
*/
|
|
237
|
+
contentType(type: string): this;
|
|
238
|
+
/**
|
|
239
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
240
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
241
|
+
*
|
|
242
|
+
* Examples:
|
|
243
|
+
*
|
|
244
|
+
* res.type('.html');
|
|
245
|
+
* res.type('html');
|
|
246
|
+
* res.type('json');
|
|
247
|
+
* res.type('application/json');
|
|
248
|
+
* res.type('png');
|
|
249
|
+
*/
|
|
250
|
+
type(type: string): this;
|
|
251
|
+
/**
|
|
252
|
+
* Set cookie `name` to `value`, with the given `options`.
|
|
253
|
+
*
|
|
254
|
+
* Options:
|
|
255
|
+
*
|
|
256
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
257
|
+
* - `signed` sign the cookie
|
|
258
|
+
* - `path` defaults to "/"
|
|
259
|
+
*
|
|
260
|
+
* Examples:
|
|
261
|
+
*
|
|
262
|
+
* // "Remember Me" for 15 minutes
|
|
263
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
264
|
+
*
|
|
265
|
+
* // same as above
|
|
266
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
267
|
+
*
|
|
268
|
+
*/
|
|
269
|
+
cookie(name: string, value: string, options?: CookieOptions): this;
|
|
270
|
+
/**
|
|
271
|
+
* Clear cookie `name`.
|
|
272
|
+
*/
|
|
273
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
274
|
+
/**
|
|
275
|
+
* Set Link header field with the given `links`.
|
|
276
|
+
*
|
|
277
|
+
* Examples:
|
|
278
|
+
*
|
|
279
|
+
* res.links({
|
|
280
|
+
* next: 'http://api.example.com/users?page=2',
|
|
281
|
+
* last: 'http://api.example.com/users?page=5'
|
|
282
|
+
* });
|
|
283
|
+
*
|
|
284
|
+
*/
|
|
285
|
+
links(links: Record<string, string>): this;
|
|
286
|
+
redirect(url: string): any;
|
|
287
|
+
redirect(status: number, url: string): any;
|
|
288
|
+
/**
|
|
289
|
+
* Send JSON response.
|
|
290
|
+
*
|
|
291
|
+
* Examples:
|
|
292
|
+
*
|
|
293
|
+
* res.json(null);
|
|
294
|
+
* res.json({ user: 'tj' });
|
|
295
|
+
*/
|
|
296
|
+
json(obj: any): this;
|
|
297
|
+
location(url: string): this;
|
|
298
|
+
/**
|
|
299
|
+
* Set status `code`.
|
|
300
|
+
*/
|
|
301
|
+
status(code: number): this;
|
|
302
|
+
/**
|
|
303
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
304
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
305
|
+
*
|
|
306
|
+
* Examples:
|
|
307
|
+
*
|
|
308
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
309
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
310
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
311
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
312
|
+
*/
|
|
313
|
+
sendStatus(statusCode: number): this;
|
|
314
|
+
protected _init(init: HttpResponseMessage.Initiator): void;
|
|
315
|
+
static create(init: HttpResponseMessage.Initiator): HttpResponseMessage;
|
|
316
|
+
static fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
|
|
317
|
+
static fromStream(readable: Readable): Promise<HttpResponseMessage>;
|
|
318
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import contentDisposition from 'content-disposition';
|
|
2
|
+
import cookie from 'cookie';
|
|
3
|
+
import cookieSignature from 'cookie-signature';
|
|
4
|
+
import encodeUrl from 'encodeurl';
|
|
5
|
+
import { HTTPParser } from 'http-parser-js';
|
|
6
|
+
import mime from 'mime-types';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { HttpStatusMessages } from './enums/http-status-messages.js';
|
|
9
|
+
import { HttpMessageHost } from './http-message.host.js';
|
|
10
|
+
/**
|
|
11
|
+
* @namespace HttpResponseMessage
|
|
12
|
+
*/
|
|
13
|
+
export var HttpResponseMessage;
|
|
14
|
+
(function (HttpResponseMessage) {
|
|
15
|
+
function create(init) {
|
|
16
|
+
return HttpResponseMessageHost.create(init);
|
|
17
|
+
}
|
|
18
|
+
HttpResponseMessage.create = create;
|
|
19
|
+
function fromBuffer(buffer) {
|
|
20
|
+
return HttpResponseMessageHost.fromBuffer(buffer);
|
|
21
|
+
}
|
|
22
|
+
HttpResponseMessage.fromBuffer = fromBuffer;
|
|
23
|
+
async function fromStream(readable) {
|
|
24
|
+
return HttpResponseMessageHost.fromStream(readable);
|
|
25
|
+
}
|
|
26
|
+
HttpResponseMessage.fromStream = fromStream;
|
|
27
|
+
})(HttpResponseMessage || (HttpResponseMessage = {}));
|
|
28
|
+
/**
|
|
29
|
+
* @class HttpResponseMessageHost
|
|
30
|
+
*/
|
|
31
|
+
export class HttpResponseMessageHost extends HttpMessageHost {
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
}
|
|
35
|
+
header(arg0, arg1) {
|
|
36
|
+
return this.set(arg0, arg1);
|
|
37
|
+
}
|
|
38
|
+
append(name, value) {
|
|
39
|
+
this[HttpMessageHost.kHeaders].append(name, value);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set "Content-Disposition" header to "attachment" with optional `filename`.
|
|
44
|
+
*/
|
|
45
|
+
attachment(filename) {
|
|
46
|
+
if (filename)
|
|
47
|
+
this.type(path.extname(filename));
|
|
48
|
+
this.set('Content-Disposition', contentDisposition(filename));
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Alias for msg.type()
|
|
53
|
+
*/
|
|
54
|
+
contentType(type) {
|
|
55
|
+
return this.type(type);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
59
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
60
|
+
*
|
|
61
|
+
* Examples:
|
|
62
|
+
*
|
|
63
|
+
* res.type('.html');
|
|
64
|
+
* res.type('html');
|
|
65
|
+
* res.type('json');
|
|
66
|
+
* res.type('application/json');
|
|
67
|
+
* res.type('png');
|
|
68
|
+
*/
|
|
69
|
+
type(type) {
|
|
70
|
+
const ct = type.indexOf('/') === -1
|
|
71
|
+
? mime.lookup(type)
|
|
72
|
+
: type;
|
|
73
|
+
if (ct)
|
|
74
|
+
this.set('Content-Type', ct);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Set cookie `name` to `value`, with the given `options`.
|
|
79
|
+
*
|
|
80
|
+
* Options:
|
|
81
|
+
*
|
|
82
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
83
|
+
* - `signed` sign the cookie
|
|
84
|
+
* - `path` defaults to "/"
|
|
85
|
+
*
|
|
86
|
+
* Examples:
|
|
87
|
+
*
|
|
88
|
+
* // "Remember Me" for 15 minutes
|
|
89
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
90
|
+
*
|
|
91
|
+
* // same as above
|
|
92
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
cookie(name, value, options) {
|
|
96
|
+
const opts = { ...options };
|
|
97
|
+
const secret = this.req?.secret;
|
|
98
|
+
const signed = opts.signed;
|
|
99
|
+
if (signed && !secret) {
|
|
100
|
+
throw new Error('cookieParser("secret") required for signed cookies');
|
|
101
|
+
}
|
|
102
|
+
let val = typeof value === 'object'
|
|
103
|
+
? 'j:' + JSON.stringify(value)
|
|
104
|
+
: String(value);
|
|
105
|
+
if (signed)
|
|
106
|
+
val = 's:' + cookieSignature.sign(val, secret);
|
|
107
|
+
if (opts.maxAge != null) {
|
|
108
|
+
const maxAge = opts.maxAge - 0;
|
|
109
|
+
if (!isNaN(maxAge)) {
|
|
110
|
+
opts.expires = new Date(Date.now() + maxAge);
|
|
111
|
+
opts.maxAge = Math.floor(maxAge / 1000);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (opts.path == null)
|
|
115
|
+
opts.path = '/';
|
|
116
|
+
// Remove old cookie
|
|
117
|
+
let a = this.get('Set-Cookie');
|
|
118
|
+
if (a && Array.isArray(a)) {
|
|
119
|
+
a = a.filter(x => !x.startsWith(name + '='));
|
|
120
|
+
this.set('Set-Cookie', a);
|
|
121
|
+
}
|
|
122
|
+
this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Clear cookie `name`.
|
|
127
|
+
*/
|
|
128
|
+
clearCookie(name, options) {
|
|
129
|
+
return this.cookie(name, '', { expires: new Date(1), path: '/', ...options });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Set Link header field with the given `links`.
|
|
133
|
+
*
|
|
134
|
+
* Examples:
|
|
135
|
+
*
|
|
136
|
+
* res.links({
|
|
137
|
+
* next: 'http://api.example.com/users?page=2',
|
|
138
|
+
* last: 'http://api.example.com/users?page=5'
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
links(links) {
|
|
143
|
+
let link = this.get('Link') || '';
|
|
144
|
+
if (link)
|
|
145
|
+
link += ', ';
|
|
146
|
+
return this.set('Link', link + Object.keys(links).map(rel => '<' + links[rel] + '>; rel="' + rel + '"').join(', '));
|
|
147
|
+
}
|
|
148
|
+
redirect(arg0, url) {
|
|
149
|
+
let status = 302;
|
|
150
|
+
// allow status / url
|
|
151
|
+
if (typeof arg0 === 'number') {
|
|
152
|
+
status = arg0;
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
url = arg0 || '';
|
|
156
|
+
// Set location header
|
|
157
|
+
this.location(url || '/');
|
|
158
|
+
// Respond
|
|
159
|
+
this.statusCode = status;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Send JSON response.
|
|
163
|
+
*
|
|
164
|
+
* Examples:
|
|
165
|
+
*
|
|
166
|
+
* res.json(null);
|
|
167
|
+
* res.json({ user: 'tj' });
|
|
168
|
+
*/
|
|
169
|
+
json(obj) {
|
|
170
|
+
if (!this.get('Content-Type'))
|
|
171
|
+
this.set('Content-Type', 'application/json');
|
|
172
|
+
const body = JSON.stringify(obj);
|
|
173
|
+
return this.send(body);
|
|
174
|
+
}
|
|
175
|
+
location(url) {
|
|
176
|
+
let loc = url;
|
|
177
|
+
// "back" is an alias for the referrer
|
|
178
|
+
if (url === 'back')
|
|
179
|
+
loc = this.req?.get('Referrer') || '/';
|
|
180
|
+
// set location
|
|
181
|
+
return this.set('Location', encodeUrl(loc));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Set status `code`.
|
|
185
|
+
*/
|
|
186
|
+
status(code) {
|
|
187
|
+
this.statusCode = code;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
192
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
193
|
+
*
|
|
194
|
+
* Examples:
|
|
195
|
+
*
|
|
196
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
197
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
198
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
199
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
200
|
+
*/
|
|
201
|
+
sendStatus(statusCode) {
|
|
202
|
+
const body = HttpStatusMessages[statusCode] || String(statusCode);
|
|
203
|
+
this.statusCode = statusCode;
|
|
204
|
+
this.type('txt');
|
|
205
|
+
return this.send(body);
|
|
206
|
+
}
|
|
207
|
+
_init(init) {
|
|
208
|
+
super._init(init);
|
|
209
|
+
this.statusCode = init?.statusCode;
|
|
210
|
+
this.statusMessage = init?.statusMessage;
|
|
211
|
+
this.req = init?.req;
|
|
212
|
+
this.chunkedEncoding = init?.chunkedEncoding;
|
|
213
|
+
}
|
|
214
|
+
[HttpMessageHost.kOnHeaderReceived](info) {
|
|
215
|
+
super[HttpMessageHost.kOnHeaderReceived](info);
|
|
216
|
+
this.statusCode = info.statusCode;
|
|
217
|
+
this.statusMessage = info.statusMessage;
|
|
218
|
+
}
|
|
219
|
+
static create(init) {
|
|
220
|
+
const msg = new HttpResponseMessageHost();
|
|
221
|
+
msg._init(init);
|
|
222
|
+
return msg;
|
|
223
|
+
}
|
|
224
|
+
static fromBuffer(buffer) {
|
|
225
|
+
const msg = new HttpResponseMessageHost();
|
|
226
|
+
msg._parseBuffer(buffer, HTTPParser.RESPONSE);
|
|
227
|
+
return msg;
|
|
228
|
+
}
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
230
|
+
static async fromStream(readable) {
|
|
231
|
+
throw new Error('fromStream is not implemented yet');
|
|
232
|
+
}
|
|
233
|
+
}
|
package/esm/http/index.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
export * from './http-request-node.js';
|
|
2
1
|
export * from './http-headers.js';
|
|
3
|
-
export * from './http-request.js';
|
|
4
|
-
export * from './http-response.js';
|
|
5
2
|
export * from './http-params.js';
|
|
6
|
-
export * from './http-
|
|
3
|
+
export * from './http-response-message.js';
|
|
4
|
+
export * from './http-request-message.js';
|
|
7
5
|
export * from './enums/http-headers-codes.enum.js';
|
|
8
6
|
export * from './enums/http-status-codes.enum.js';
|
|
9
7
|
export * from './interfaces/client-http-headers.interface.js';
|
|
10
8
|
export * from './interfaces/server-http-headers.interface.js';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './utils/normalize-headers.js';
|
|
9
|
+
export * from './codecs/date-codec.js';
|
|
10
|
+
export * from './codecs/boolean-codec.js';
|
|
11
|
+
export * from './codecs/filter-codec.js';
|
|
12
|
+
export * from './codecs/integer-codec.js';
|
|
13
|
+
export * from './codecs/number-codec.js';
|
|
14
|
+
export * from './codecs/string-codec.js';
|
package/esm/http/index.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
export * from './http-request-node.js';
|
|
2
1
|
export * from './http-headers.js';
|
|
3
|
-
export * from './http-request.js';
|
|
4
|
-
export * from './http-response.js';
|
|
5
2
|
export * from './http-params.js';
|
|
6
|
-
export * from './http-
|
|
3
|
+
export * from './http-response-message.js';
|
|
4
|
+
export * from './http-request-message.js';
|
|
7
5
|
export * from './enums/http-headers-codes.enum.js';
|
|
8
6
|
export * from './enums/http-status-codes.enum.js';
|
|
9
7
|
export * from './interfaces/client-http-headers.interface.js';
|
|
10
8
|
export * from './interfaces/server-http-headers.interface.js';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './utils/normalize-headers.js';
|
|
9
|
+
export * from './codecs/date-codec.js';
|
|
10
|
+
export * from './codecs/boolean-codec.js';
|
|
11
|
+
export * from './codecs/filter-codec.js';
|
|
12
|
+
export * from './codecs/integer-codec.js';
|
|
13
|
+
export * from './codecs/number-codec.js';
|
|
14
|
+
export * from './codecs/string-codec.js';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { Readable } from 'stream';
|
|
5
|
-
import { HttpRequestContent, IHttpRequestContent } from './http-request-content.js';
|
|
6
|
-
import { HttpResponseContent, IHttpResponseContent } from './http-response-content.js';
|
|
7
|
-
type Part = {
|
|
8
|
-
headers: Record<string, string | string[]>;
|
|
9
|
-
contentId?: string;
|
|
10
|
-
content: HttpRequestContent | HttpResponseContent | BatchMultipart;
|
|
11
|
-
};
|
|
12
|
-
export declare class BatchMultipart {
|
|
13
|
-
protected _parts: Part[];
|
|
14
|
-
readonly boundary: string;
|
|
15
|
-
constructor();
|
|
16
|
-
addRequestPart(content: IHttpRequestContent, part?: {
|
|
17
|
-
contentId?: string;
|
|
18
|
-
headers?: Record<string, string | string[]>;
|
|
19
|
-
}): this;
|
|
20
|
-
addHttpResponse(content: IHttpResponseContent, part?: {
|
|
21
|
-
contentId?: string;
|
|
22
|
-
headers?: Record<string, string | string[]>;
|
|
23
|
-
}): this;
|
|
24
|
-
addBatch(batch: BatchMultipart, part?: {
|
|
25
|
-
contentId?: string;
|
|
26
|
-
headers?: Record<string, string | string[]>;
|
|
27
|
-
}): this;
|
|
28
|
-
stream(): NodeJS.ReadableStream;
|
|
29
|
-
protected _build(target: (Buffer | Readable)[]): void;
|
|
30
|
-
}
|
|
31
|
-
export {};
|