@opra/common 0.5.0 → 0.7.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/constants.js +1 -0
- package/cjs/exception/enums/issue-severity.enum.js +23 -0
- package/cjs/{types.js → exception/error-issue.js} +0 -0
- package/cjs/exception/http-errors/bad-request.error.js +22 -0
- package/cjs/exception/http-errors/failed-dependency.error.js +21 -0
- package/cjs/exception/http-errors/forbidden.error.js +23 -0
- package/cjs/exception/http-errors/internal-server.error.js +21 -0
- package/cjs/exception/http-errors/method-not-allowed.error.js +22 -0
- package/cjs/exception/http-errors/not-acceptable.error.js +22 -0
- package/cjs/exception/http-errors/not-found.error.js +25 -0
- package/cjs/exception/http-errors/unauthorized.error.js +22 -0
- package/cjs/exception/http-errors/unprocessable-entity.error.js +21 -0
- package/cjs/exception/index.js +18 -0
- package/cjs/exception/opra-exception.js +56 -0
- package/cjs/exception/resource-errors/resource-conflict.error.js +20 -0
- package/cjs/exception/resource-errors/resource-not-found.error.js +20 -0
- package/cjs/exception/wrap-exception.js +42 -0
- package/cjs/filter/antlr/OpraFilterLexer.js +386 -0
- package/cjs/filter/antlr/OpraFilterParser.js +2070 -0
- package/cjs/filter/antlr/OpraFilterVisitor.js +3 -0
- package/cjs/filter/ast/abstract/ast.js +10 -0
- package/cjs/filter/ast/abstract/expression.js +7 -0
- package/cjs/filter/ast/abstract/literal.js +14 -0
- package/cjs/filter/ast/abstract/term.js +7 -0
- package/cjs/filter/ast/expressions/arithmetic-expression.js +29 -0
- package/cjs/filter/ast/expressions/array-expression.js +15 -0
- package/cjs/filter/ast/expressions/comparison-expression.js +18 -0
- package/cjs/filter/ast/expressions/logical-expression.js +18 -0
- package/cjs/filter/ast/expressions/parentheses-expression.js +15 -0
- package/cjs/filter/ast/index.js +19 -0
- package/cjs/filter/ast/terms/boolean-literal.js +10 -0
- package/cjs/filter/ast/terms/date-literal.js +28 -0
- package/cjs/filter/ast/terms/external-constant.js +13 -0
- package/cjs/filter/ast/terms/null-literal.js +11 -0
- package/cjs/filter/ast/terms/number-literal.js +40 -0
- package/cjs/filter/ast/terms/qualified-identifier.js +10 -0
- package/cjs/filter/ast/terms/string-literal.js +14 -0
- package/cjs/filter/ast/terms/time-literal.js +33 -0
- package/cjs/filter/build.js +129 -0
- package/cjs/filter/error-listener.js +14 -0
- package/cjs/filter/errors.js +21 -0
- package/cjs/filter/filter-tree-visitor.js +113 -0
- package/cjs/filter/index.js +8 -0
- package/cjs/filter/parse.js +37 -0
- package/cjs/filter/utils.js +26 -0
- package/cjs/helpers/index.js +4 -0
- package/cjs/{classes → helpers}/responsive-map.js +1 -1
- package/cjs/{enums → http/enums}/http-headers.enum.js +9 -0
- package/cjs/{enums → http/enums}/http-status.enum.js +0 -0
- package/cjs/http/http-request.js +118 -0
- package/cjs/http/index.js +9 -0
- package/cjs/http/interfaces/client-http-headers.interface.js +2 -0
- package/cjs/http/interfaces/server-http-headers.interface.js +2 -0
- package/cjs/http/multipart/batch-multipart.js +155 -0
- package/cjs/http/multipart/http-request-content.js +16 -0
- package/cjs/http/multipart/http-response-content.js +14 -0
- package/cjs/http/multipart/index.js +4 -0
- package/cjs/http/utils/normalize-headers.js +28 -0
- package/cjs/i18n/i18n.js +175 -0
- package/cjs/i18n/index.js +10 -0
- package/cjs/i18n/string-utils.js +13 -0
- package/cjs/i18n/translate.js +15 -0
- package/cjs/index.js +12 -5
- package/cjs/schema/constants.js +11 -0
- package/cjs/schema/decorators/opr-collection-resource.decorator.js +23 -0
- package/cjs/schema/decorators/opr-complex-type.decorator.js +27 -0
- package/cjs/schema/decorators/opr-field.decorator.js +28 -0
- package/cjs/schema/decorators/opr-resolver.decorator.js +81 -0
- package/cjs/schema/decorators/opr-simple-type.decorator.js +18 -0
- package/cjs/schema/decorators/opr-singleton-resource.decorator.js +23 -0
- package/cjs/schema/implementation/data-type/builtin/any.type.js +9 -0
- package/cjs/schema/implementation/data-type/builtin/base64-binary.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/bigint.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/boolean.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/date-string.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/date.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/guid.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/integer.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/number.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/object.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin/string.type.js +15 -0
- package/cjs/schema/implementation/data-type/builtin-data-types.js +37 -0
- package/cjs/schema/implementation/data-type/complex-type.js +111 -0
- package/cjs/schema/implementation/data-type/data-type.js +36 -0
- package/cjs/schema/implementation/data-type/simple-type.js +21 -0
- package/cjs/schema/implementation/data-type/union-type.js +25 -0
- package/cjs/schema/implementation/document-builder.js +140 -0
- package/cjs/schema/implementation/opra-document.js +181 -0
- package/cjs/schema/implementation/query/collection-count-query.js +19 -0
- package/cjs/schema/implementation/query/collection-create-query.js +28 -0
- package/cjs/schema/implementation/query/collection-delete-many-query.js +19 -0
- package/cjs/schema/implementation/query/collection-delete-query.js +27 -0
- package/cjs/schema/implementation/query/collection-get-query.js +38 -0
- package/cjs/schema/implementation/query/collection-search-query.js +55 -0
- package/cjs/schema/implementation/query/collection-update-many-query.js +21 -0
- package/cjs/schema/implementation/query/collection-update-query.js +39 -0
- package/cjs/schema/implementation/query/field-get-query.js +45 -0
- package/cjs/schema/implementation/query/index.js +22 -0
- package/cjs/schema/implementation/query/singleton-get-query.js +27 -0
- package/cjs/schema/implementation/resource/collection-resource-info.js +58 -0
- package/cjs/schema/implementation/resource/container-resource-info.js +30 -0
- package/cjs/schema/implementation/resource/resource-info.js +39 -0
- package/cjs/schema/implementation/resource/singleton-resource-info.js +37 -0
- package/cjs/schema/implementation/schema-builder/extract-resource-metadata.util.js +84 -0
- package/cjs/schema/implementation/schema-builder/extract-type-metadata.util.js +94 -0
- package/cjs/schema/index.js +28 -0
- package/cjs/schema/interfaces/child-field-query.interface.js +2 -0
- package/cjs/schema/interfaces/data-type.metadata.js +2 -0
- package/cjs/schema/interfaces/resource-container.interface.js +2 -0
- package/cjs/schema/interfaces/resource.metadata.js +2 -0
- package/cjs/schema/opra-schema.definition.js +49 -0
- package/cjs/schema/type-helpers/extend-type.helper.js +65 -0
- package/cjs/schema/type-helpers/mixin-type.helper.js +46 -0
- package/cjs/schema/type-helpers/mixin.utils.js +32 -0
- package/cjs/schema/types.js +2 -0
- package/cjs/schema/utils/class.utils.js +8 -0
- package/cjs/schema/utils/clone-object.util.js +19 -0
- package/cjs/schema/utils/inspect.util.js +7 -0
- package/cjs/schema/utils/normalize-field-array.util.js +44 -0
- package/cjs/schema/utils/path-to-tree.util.js +26 -0
- package/cjs/schema/utils/string-compare.util.js +11 -0
- package/cjs/url/formats/boolean-format.js +25 -0
- package/cjs/url/formats/date-format.js +48 -0
- package/cjs/url/formats/filter-format.js +18 -0
- package/cjs/url/formats/format.js +6 -0
- package/cjs/url/formats/integer-format.js +20 -0
- package/cjs/url/formats/number-format.js +28 -0
- package/cjs/url/formats/string-format.js +28 -0
- package/cjs/url/index.js +8 -0
- package/cjs/url/opra-url-path-component.js +33 -0
- package/cjs/url/opra-url-path.js +128 -0
- package/cjs/url/opra-url-search-params.js +247 -0
- package/cjs/url/opra-url.js +299 -0
- package/cjs/url/utils/path-utils.js +86 -0
- package/cjs/utils/index.js +6 -0
- package/cjs/utils/is-url.js +8 -0
- package/cjs/utils/path-to-tree.js +28 -0
- package/cjs/utils/type-guards.js +46 -0
- package/esm/constants.d.ts +0 -0
- package/esm/constants.js +1 -0
- package/esm/exception/enums/issue-severity.enum.d.ts +13 -0
- package/esm/exception/enums/issue-severity.enum.js +20 -0
- package/esm/exception/error-issue.d.ts +9 -0
- package/esm/{types.js → exception/error-issue.js} +0 -0
- package/esm/exception/http-errors/bad-request.error.d.ts +10 -0
- package/esm/exception/http-errors/bad-request.error.js +18 -0
- package/esm/exception/http-errors/failed-dependency.error.d.ts +9 -0
- package/esm/exception/http-errors/failed-dependency.error.js +17 -0
- package/esm/exception/http-errors/forbidden.error.d.ts +11 -0
- package/esm/exception/http-errors/forbidden.error.js +19 -0
- package/esm/exception/http-errors/internal-server.error.d.ts +9 -0
- package/esm/exception/http-errors/internal-server.error.js +17 -0
- package/esm/exception/http-errors/method-not-allowed.error.d.ts +10 -0
- package/esm/exception/http-errors/method-not-allowed.error.js +18 -0
- package/esm/exception/http-errors/not-acceptable.error.d.ts +10 -0
- package/esm/exception/http-errors/not-acceptable.error.js +18 -0
- package/esm/exception/http-errors/not-found.error.d.ts +13 -0
- package/esm/exception/http-errors/not-found.error.js +21 -0
- package/esm/exception/http-errors/unauthorized.error.d.ts +10 -0
- package/esm/exception/http-errors/unauthorized.error.js +18 -0
- package/esm/exception/http-errors/unprocessable-entity.error.d.ts +9 -0
- package/esm/exception/http-errors/unprocessable-entity.error.js +17 -0
- package/esm/exception/index.d.ts +15 -0
- package/esm/exception/index.js +15 -0
- package/esm/exception/opra-exception.d.ts +15 -0
- package/esm/exception/opra-exception.js +52 -0
- package/esm/exception/resource-errors/resource-conflict.error.d.ts +5 -0
- package/esm/exception/resource-errors/resource-conflict.error.js +16 -0
- package/esm/exception/resource-errors/resource-not-found.error.d.ts +4 -0
- package/esm/exception/resource-errors/resource-not-found.error.js +16 -0
- package/esm/exception/wrap-exception.d.ts +2 -0
- package/esm/exception/wrap-exception.js +38 -0
- package/esm/filter/antlr/OpraFilterLexer.d.ts +78 -0
- package/esm/filter/antlr/OpraFilterLexer.js +381 -0
- package/esm/filter/antlr/OpraFilterParser.d.ts +365 -0
- package/esm/filter/antlr/OpraFilterParser.js +2022 -0
- package/esm/filter/antlr/OpraFilterVisitor.d.ts +290 -0
- package/esm/filter/antlr/OpraFilterVisitor.js +2 -0
- package/esm/filter/ast/abstract/ast.d.ts +5 -0
- package/esm/filter/ast/abstract/ast.js +6 -0
- package/esm/filter/ast/abstract/expression.d.ts +3 -0
- package/esm/filter/ast/abstract/expression.js +3 -0
- package/esm/filter/ast/abstract/literal.d.ts +6 -0
- package/esm/filter/ast/abstract/literal.js +10 -0
- package/esm/filter/ast/abstract/term.d.ts +3 -0
- package/esm/filter/ast/abstract/term.js +3 -0
- package/esm/filter/ast/expressions/arithmetic-expression.d.ts +13 -0
- package/esm/filter/ast/expressions/arithmetic-expression.js +24 -0
- package/esm/filter/ast/expressions/array-expression.d.ts +7 -0
- package/esm/filter/ast/expressions/array-expression.js +11 -0
- package/esm/filter/ast/expressions/comparison-expression.d.ts +10 -0
- package/esm/filter/ast/expressions/comparison-expression.js +14 -0
- package/esm/filter/ast/expressions/logical-expression.d.ts +8 -0
- package/esm/filter/ast/expressions/logical-expression.js +14 -0
- package/esm/filter/ast/expressions/parentheses-expression.d.ts +6 -0
- package/esm/filter/ast/expressions/parentheses-expression.js +11 -0
- package/esm/filter/ast/index.d.ts +16 -0
- package/esm/filter/ast/index.js +16 -0
- package/esm/filter/ast/terms/boolean-literal.d.ts +5 -0
- package/esm/filter/ast/terms/boolean-literal.js +6 -0
- package/esm/filter/ast/terms/date-literal.d.ts +6 -0
- package/esm/filter/ast/terms/date-literal.js +24 -0
- package/esm/filter/ast/terms/external-constant.d.ts +5 -0
- package/esm/filter/ast/terms/external-constant.js +9 -0
- package/esm/filter/ast/terms/null-literal.d.ts +5 -0
- package/esm/filter/ast/terms/null-literal.js +7 -0
- package/esm/filter/ast/terms/number-literal.d.ts +6 -0
- package/esm/filter/ast/terms/number-literal.js +36 -0
- package/esm/filter/ast/terms/qualified-identifier.d.ts +4 -0
- package/esm/filter/ast/terms/qualified-identifier.js +6 -0
- package/esm/filter/ast/terms/string-literal.d.ts +5 -0
- package/esm/filter/ast/terms/string-literal.js +10 -0
- package/esm/filter/ast/terms/time-literal.d.ts +6 -0
- package/esm/filter/ast/terms/time-literal.js +29 -0
- package/esm/filter/build.d.ts +31 -0
- package/esm/filter/build.js +105 -0
- package/esm/filter/error-listener.d.ts +8 -0
- package/esm/filter/error-listener.js +10 -0
- package/esm/filter/errors.d.ts +20 -0
- package/esm/filter/errors.js +15 -0
- package/esm/filter/filter-tree-visitor.d.ts +30 -0
- package/esm/filter/filter-tree-visitor.js +109 -0
- package/esm/filter/index.d.ts +5 -0
- package/esm/filter/index.js +5 -0
- package/esm/filter/parse.d.ts +2 -0
- package/esm/filter/parse.js +33 -0
- package/esm/filter/utils.d.ts +2 -0
- package/esm/filter/utils.js +21 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/{classes → helpers}/responsive-map.d.ts +0 -0
- package/esm/{classes → helpers}/responsive-map.js +1 -1
- package/esm/{enums → http/enums}/http-headers.enum.d.ts +9 -0
- package/esm/{enums → http/enums}/http-headers.enum.js +9 -0
- package/esm/{enums → http/enums}/http-status.enum.d.ts +0 -0
- package/esm/{enums → http/enums}/http-status.enum.js +0 -0
- package/esm/http/http-request.d.ts +34 -0
- package/esm/http/http-request.js +114 -0
- package/esm/http/index.d.ts +6 -0
- package/esm/http/index.js +6 -0
- package/esm/http/interfaces/client-http-headers.interface.d.ts +65 -0
- package/esm/http/interfaces/client-http-headers.interface.js +1 -0
- package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -0
- package/esm/http/interfaces/server-http-headers.interface.js +1 -0
- package/esm/http/multipart/batch-multipart.d.ts +30 -0
- package/esm/http/multipart/batch-multipart.js +150 -0
- package/esm/http/multipart/http-request-content.d.ts +8 -0
- package/esm/http/multipart/http-request-content.js +12 -0
- package/esm/http/multipart/http-response-content.d.ts +7 -0
- package/esm/http/multipart/http-response-content.js +10 -0
- package/esm/http/multipart/index.d.ts +1 -0
- package/esm/http/multipart/index.js +1 -0
- package/esm/http/utils/normalize-headers.d.ts +1 -0
- package/esm/http/utils/normalize-headers.js +24 -0
- package/esm/i18n/i18n.d.ts +28 -0
- package/esm/i18n/i18n.js +170 -0
- package/esm/i18n/index.d.ts +5 -0
- package/esm/i18n/index.js +6 -0
- package/esm/i18n/string-utils.d.ts +2 -0
- package/esm/i18n/string-utils.js +8 -0
- package/esm/i18n/translate.d.ts +4 -0
- package/esm/i18n/translate.js +11 -0
- package/esm/index.d.ts +10 -5
- package/esm/index.js +10 -5
- package/esm/schema/constants.d.ts +8 -0
- package/esm/schema/constants.js +8 -0
- package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +8 -0
- package/esm/schema/decorators/opr-collection-resource.decorator.js +19 -0
- package/esm/schema/decorators/opr-complex-type.decorator.d.ts +6 -0
- package/esm/schema/decorators/opr-complex-type.decorator.js +23 -0
- package/esm/schema/decorators/opr-field.decorator.d.ts +3 -0
- package/esm/schema/decorators/opr-field.decorator.js +24 -0
- package/esm/schema/decorators/opr-resolver.decorator.d.ts +8 -0
- package/esm/schema/decorators/opr-resolver.decorator.js +71 -0
- package/esm/schema/decorators/opr-simple-type.decorator.d.ts +6 -0
- package/esm/schema/decorators/opr-simple-type.decorator.js +14 -0
- package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +8 -0
- package/esm/schema/decorators/opr-singleton-resource.decorator.js +19 -0
- package/esm/schema/implementation/data-type/builtin/any.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/any.type.js +6 -0
- package/esm/schema/implementation/data-type/builtin/base64-binary.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/base64-binary.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/bigint.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/bigint.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/boolean.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/boolean.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/date-string.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/date-string.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/date.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/date.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/guid.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/guid.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/integer.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/integer.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/number.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/number.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/object.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/object.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin/string.type.d.ts +2 -0
- package/esm/schema/implementation/data-type/builtin/string.type.js +12 -0
- package/esm/schema/implementation/data-type/builtin-data-types.d.ts +4 -0
- package/esm/schema/implementation/data-type/builtin-data-types.js +34 -0
- package/esm/schema/implementation/data-type/complex-type.d.ts +29 -0
- package/esm/schema/implementation/data-type/complex-type.js +107 -0
- package/esm/schema/implementation/data-type/data-type.d.ts +16 -0
- package/esm/schema/implementation/data-type/data-type.js +32 -0
- package/esm/schema/implementation/data-type/simple-type.d.ts +12 -0
- package/esm/schema/implementation/data-type/simple-type.js +17 -0
- package/esm/schema/implementation/data-type/union-type.d.ts +16 -0
- package/esm/schema/implementation/data-type/union-type.js +21 -0
- package/esm/schema/implementation/document-builder.d.ts +16 -0
- package/esm/schema/implementation/document-builder.js +135 -0
- package/esm/schema/implementation/opra-document.d.ts +44 -0
- package/esm/schema/implementation/opra-document.js +177 -0
- package/esm/schema/implementation/query/collection-count-query.d.ts +14 -0
- package/esm/schema/implementation/query/collection-count-query.js +15 -0
- package/esm/schema/implementation/query/collection-create-query.d.ts +18 -0
- package/esm/schema/implementation/query/collection-create-query.js +24 -0
- package/esm/schema/implementation/query/collection-delete-many-query.d.ts +14 -0
- package/esm/schema/implementation/query/collection-delete-many-query.js +15 -0
- package/esm/schema/implementation/query/collection-delete-query.d.ts +10 -0
- package/esm/schema/implementation/query/collection-delete-query.js +23 -0
- package/esm/schema/implementation/query/collection-get-query.d.ts +21 -0
- package/esm/schema/implementation/query/collection-get-query.js +34 -0
- package/esm/schema/implementation/query/collection-search-query.d.ts +30 -0
- package/esm/schema/implementation/query/collection-search-query.js +51 -0
- package/esm/schema/implementation/query/collection-update-many-query.d.ts +15 -0
- package/esm/schema/implementation/query/collection-update-many-query.js +17 -0
- package/esm/schema/implementation/query/collection-update-query.d.ts +19 -0
- package/esm/schema/implementation/query/collection-update-query.js +35 -0
- package/esm/schema/implementation/query/field-get-query.d.ts +30 -0
- package/esm/schema/implementation/query/field-get-query.js +41 -0
- package/esm/schema/implementation/query/index.d.ts +27 -0
- package/esm/schema/implementation/query/index.js +17 -0
- package/esm/schema/implementation/query/singleton-get-query.d.ts +20 -0
- package/esm/schema/implementation/query/singleton-get-query.js +23 -0
- package/esm/schema/implementation/resource/collection-resource-info.d.ts +19 -0
- package/esm/schema/implementation/resource/collection-resource-info.js +54 -0
- package/esm/schema/implementation/resource/container-resource-info.d.ts +13 -0
- package/esm/schema/implementation/resource/container-resource-info.js +26 -0
- package/esm/schema/implementation/resource/resource-info.d.ts +17 -0
- package/esm/schema/implementation/resource/resource-info.js +35 -0
- package/esm/schema/implementation/resource/singleton-resource-info.d.ts +14 -0
- package/esm/schema/implementation/resource/singleton-resource-info.js +33 -0
- package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.d.ts +3 -0
- package/esm/schema/implementation/schema-builder/extract-resource-metadata.util.js +80 -0
- package/esm/schema/implementation/schema-builder/extract-type-metadata.util.d.ts +4 -0
- package/esm/schema/implementation/schema-builder/extract-type-metadata.util.js +89 -0
- package/esm/schema/index.d.ts +25 -0
- package/esm/schema/index.js +25 -0
- package/esm/schema/interfaces/child-field-query.interface.d.ts +4 -0
- package/esm/schema/interfaces/child-field-query.interface.js +1 -0
- package/esm/schema/interfaces/data-type.metadata.d.ts +18 -0
- package/esm/schema/interfaces/data-type.metadata.js +1 -0
- package/esm/schema/interfaces/resource-container.interface.d.ts +8 -0
- package/esm/schema/interfaces/resource-container.interface.js +1 -0
- package/esm/schema/interfaces/resource.metadata.d.ts +18 -0
- package/esm/schema/interfaces/resource.metadata.js +1 -0
- package/esm/schema/opra-schema.definition.d.ts +178 -0
- package/esm/schema/opra-schema.definition.js +46 -0
- package/esm/schema/type-helpers/extend-type.helper.d.ts +3 -0
- package/esm/schema/type-helpers/extend-type.helper.js +59 -0
- package/esm/schema/type-helpers/mixin-type.helper.d.ts +2 -0
- package/esm/schema/type-helpers/mixin-type.helper.js +41 -0
- package/esm/schema/type-helpers/mixin.utils.d.ts +3 -0
- package/esm/schema/type-helpers/mixin.utils.js +27 -0
- package/esm/{types.d.ts → schema/types.d.ts} +8 -1
- package/esm/schema/types.js +1 -0
- package/esm/schema/utils/class.utils.d.ts +2 -0
- package/esm/schema/utils/class.utils.js +4 -0
- package/esm/schema/utils/clone-object.util.d.ts +1 -0
- package/esm/schema/utils/clone-object.util.js +14 -0
- package/esm/schema/utils/inspect.util.d.ts +4 -0
- package/esm/schema/utils/inspect.util.js +4 -0
- package/esm/schema/utils/normalize-field-array.util.d.ts +3 -0
- package/esm/schema/utils/normalize-field-array.util.js +40 -0
- package/esm/schema/utils/path-to-tree.util.d.ts +4 -0
- package/esm/schema/utils/path-to-tree.util.js +22 -0
- package/esm/schema/utils/string-compare.util.d.ts +1 -0
- package/esm/schema/utils/string-compare.util.js +7 -0
- package/esm/url/formats/boolean-format.d.ts +5 -0
- package/esm/url/formats/boolean-format.js +21 -0
- package/esm/url/formats/date-format.d.ts +16 -0
- package/esm/url/formats/date-format.js +44 -0
- package/esm/url/formats/filter-format.d.ts +6 -0
- package/esm/url/formats/filter-format.js +14 -0
- package/esm/url/formats/format.d.ts +4 -0
- package/esm/url/formats/format.js +2 -0
- package/esm/url/formats/integer-format.d.ts +9 -0
- package/esm/url/formats/integer-format.js +16 -0
- package/esm/url/formats/number-format.d.ts +12 -0
- package/esm/url/formats/number-format.js +24 -0
- package/esm/url/formats/string-format.d.ts +14 -0
- package/esm/url/formats/string-format.js +24 -0
- package/esm/url/index.d.ts +5 -0
- package/esm/url/index.js +5 -0
- package/esm/url/opra-url-path-component.d.ts +15 -0
- package/esm/url/opra-url-path-component.js +29 -0
- package/esm/url/opra-url-path.d.ts +30 -0
- package/esm/url/opra-url-path.js +124 -0
- package/esm/url/opra-url-search-params.d.ts +46 -0
- package/esm/url/opra-url-search-params.js +243 -0
- package/esm/url/opra-url.d.ts +79 -0
- package/esm/url/opra-url.js +295 -0
- package/esm/url/utils/path-utils.d.ts +8 -0
- package/esm/url/utils/path-utils.js +78 -0
- package/esm/utils/index.d.ts +3 -0
- package/esm/utils/index.js +3 -0
- package/esm/utils/is-url.d.ts +1 -0
- package/esm/utils/is-url.js +4 -0
- package/esm/utils/path-to-tree.d.ts +4 -0
- package/esm/utils/path-to-tree.js +24 -0
- package/esm/utils/type-guards.d.ts +9 -0
- package/esm/utils/type-guards.js +37 -0
- package/package.json +30 -10
- package/umd/opra-common.umd.min.js +1 -0
- package/cjs/classes/headers-map.js +0 -18
- package/esm/classes/headers-map.d.ts +0 -5
- package/esm/classes/headers-map.js +0 -14
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unquoteFilterString = exports.quoteFilterString = void 0;
|
|
4
|
+
const quotesRegEx = /'/g;
|
|
5
|
+
const escapeRegEx = /(\\)/g;
|
|
6
|
+
const unescapeRegEx = /\\(.)/g;
|
|
7
|
+
function escapeString(s) {
|
|
8
|
+
return s.replace(escapeRegEx, '\\\\');
|
|
9
|
+
}
|
|
10
|
+
function unescapeString(s) {
|
|
11
|
+
return s.replace(unescapeRegEx, '$1');
|
|
12
|
+
}
|
|
13
|
+
function quoteFilterString(s) {
|
|
14
|
+
return "'" +
|
|
15
|
+
escapeString(s).replace(quotesRegEx, '\\\'') +
|
|
16
|
+
"'";
|
|
17
|
+
}
|
|
18
|
+
exports.quoteFilterString = quoteFilterString;
|
|
19
|
+
function unquoteFilterString(s) {
|
|
20
|
+
if (s && (s.startsWith("'") || s.startsWith('"')) && s.endsWith(s.charAt(0))) {
|
|
21
|
+
return unescapeString(s.substring(1, s.length - 1));
|
|
22
|
+
}
|
|
23
|
+
/* istanbul ignore next */
|
|
24
|
+
return s;
|
|
25
|
+
}
|
|
26
|
+
exports.unquoteFilterString = unquoteFilterString;
|
|
@@ -9,7 +9,7 @@ class ResponsiveMap extends Map {
|
|
|
9
9
|
super();
|
|
10
10
|
if (wellKnownKeys)
|
|
11
11
|
wellKnownKeys.forEach(k => this._wellKnownKeyMap.set(k.toLowerCase(), k));
|
|
12
|
-
if (data
|
|
12
|
+
if (typeof data?.forEach === 'function') {
|
|
13
13
|
data.forEach((v, k) => this.set(k, v));
|
|
14
14
|
}
|
|
15
15
|
else if (data && typeof data === 'object')
|
|
@@ -180,6 +180,10 @@ var HttpHeaders;
|
|
|
180
180
|
*/
|
|
181
181
|
HttpHeaders["Content_Disposition"] = "Content-Disposition";
|
|
182
182
|
/* *** Message body information *** */
|
|
183
|
+
/**
|
|
184
|
+
* Indicates to uniquely identifies MIME entities in several contexts.
|
|
185
|
+
*/
|
|
186
|
+
HttpHeaders["Content_ID"] = "Content-ID";
|
|
183
187
|
/**
|
|
184
188
|
* The size of the resource, in decimal number of bytes.
|
|
185
189
|
*/
|
|
@@ -188,6 +192,11 @@ var HttpHeaders;
|
|
|
188
192
|
* Indicates the media type of the resource.
|
|
189
193
|
*/
|
|
190
194
|
HttpHeaders["Content_Type"] = "Content-Type";
|
|
195
|
+
/**
|
|
196
|
+
* Indicates to specify how a MIME message or body part has been encoded,
|
|
197
|
+
* so that it can be decoded by its recipient.
|
|
198
|
+
*/
|
|
199
|
+
HttpHeaders["Content_Transfer_Encoding"] = "Content-Transfer-Encoding";
|
|
191
200
|
/**
|
|
192
201
|
* Used to specify the compression algorithm.
|
|
193
202
|
*/
|
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRequest = void 0;
|
|
4
|
+
const http_parser_js_1 = require("http-parser-js");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
const crlfBuffer = Buffer.from('\r\n');
|
|
7
|
+
const kHeaders = Symbol('kHeaders');
|
|
8
|
+
const kHeadersCount = Symbol('kHeadersCount');
|
|
9
|
+
const kTrailers = Symbol('kTrailers');
|
|
10
|
+
const kTrailersCount = Symbol('kTrailersCount');
|
|
11
|
+
class HttpRequest extends stream_1.Readable {
|
|
12
|
+
httpVersionMajor;
|
|
13
|
+
httpVersionMinor;
|
|
14
|
+
httpVersion;
|
|
15
|
+
complete;
|
|
16
|
+
rawHeaders;
|
|
17
|
+
rawTrailers;
|
|
18
|
+
aborted = false;
|
|
19
|
+
upgrade;
|
|
20
|
+
url;
|
|
21
|
+
originalUrl;
|
|
22
|
+
method;
|
|
23
|
+
shouldKeepAlive;
|
|
24
|
+
data;
|
|
25
|
+
body;
|
|
26
|
+
[kHeaders];
|
|
27
|
+
[kHeadersCount];
|
|
28
|
+
[kTrailers];
|
|
29
|
+
[kTrailersCount];
|
|
30
|
+
get headers() {
|
|
31
|
+
if (!this[kHeaders])
|
|
32
|
+
this[kHeaders] = arrayToHeaders(this.rawHeaders);
|
|
33
|
+
return this[kHeaders];
|
|
34
|
+
}
|
|
35
|
+
get headersCount() {
|
|
36
|
+
return this[kHeadersCount];
|
|
37
|
+
}
|
|
38
|
+
get trailers() {
|
|
39
|
+
if (!this[kTrailers])
|
|
40
|
+
this[kTrailers] = arrayToHeaders(this.rawTrailers);
|
|
41
|
+
return this[kTrailers];
|
|
42
|
+
}
|
|
43
|
+
get trailersCount() {
|
|
44
|
+
return this[kTrailersCount];
|
|
45
|
+
}
|
|
46
|
+
_read() {
|
|
47
|
+
if (this.data) {
|
|
48
|
+
this.push(this.data);
|
|
49
|
+
}
|
|
50
|
+
this.push(null);
|
|
51
|
+
}
|
|
52
|
+
static parse(input) {
|
|
53
|
+
const parser = new http_parser_js_1.HTTPParser(http_parser_js_1.HTTPParser.REQUEST);
|
|
54
|
+
const out = new HttpRequest();
|
|
55
|
+
const bodyChunks = [];
|
|
56
|
+
parser[http_parser_js_1.HTTPParser.kOnHeadersComplete] = function (req) {
|
|
57
|
+
out.shouldKeepAlive = req.shouldKeepAlive;
|
|
58
|
+
out.upgrade = req.upgrade;
|
|
59
|
+
out.method = http_parser_js_1.HTTPParser.methods[req.method];
|
|
60
|
+
out.url = req.url;
|
|
61
|
+
out.originalUrl = req.url;
|
|
62
|
+
out.httpVersionMajor = req.versionMajor;
|
|
63
|
+
out.httpVersionMinor = req.versionMinor;
|
|
64
|
+
out.httpVersion = req.versionMajor + '.' + req.versionMinor;
|
|
65
|
+
out.rawHeaders = req.headers;
|
|
66
|
+
out[kHeadersCount] = Math.ceil(req.headers.length / 2);
|
|
67
|
+
out[kTrailersCount] = 0;
|
|
68
|
+
};
|
|
69
|
+
parser[http_parser_js_1.HTTPParser.kOnBody] = function (chunk, offset, length) {
|
|
70
|
+
bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
71
|
+
};
|
|
72
|
+
// This is actually the event for trailers, go figure.
|
|
73
|
+
parser[http_parser_js_1.HTTPParser.kOnHeaders] = function (t) {
|
|
74
|
+
out.rawTrailers = t;
|
|
75
|
+
out[kTrailersCount] = Math.ceil(t.length / 2);
|
|
76
|
+
};
|
|
77
|
+
parser[http_parser_js_1.HTTPParser.kOnMessageComplete] = function () {
|
|
78
|
+
out.complete = true;
|
|
79
|
+
};
|
|
80
|
+
// Since we are sending the entire Buffer at once here all callbacks above happen synchronously.
|
|
81
|
+
// The parser does not do _anything_ asynchronous.
|
|
82
|
+
// However, you can of course call execute() multiple times with multiple chunks, e.g. from a stream.
|
|
83
|
+
// But then you have to refactor the entire logic to be async (e.g. resolve a Promise in kOnMessageComplete and add timeout logic).
|
|
84
|
+
parser.execute(input);
|
|
85
|
+
if (!out.complete)
|
|
86
|
+
parser.execute(crlfBuffer);
|
|
87
|
+
parser.finish();
|
|
88
|
+
if (!out.complete) {
|
|
89
|
+
throw new Error('Could not parse request');
|
|
90
|
+
}
|
|
91
|
+
out.rawTrailers = out.rawTrailers || [];
|
|
92
|
+
if (bodyChunks.length)
|
|
93
|
+
out.data = Buffer.concat(bodyChunks);
|
|
94
|
+
out.resume();
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.HttpRequest = HttpRequest;
|
|
99
|
+
function arrayToHeaders(arr) {
|
|
100
|
+
const headers = {};
|
|
101
|
+
for (let i = 0; i < arr.length; i++) {
|
|
102
|
+
const k = arr[i].toLowerCase();
|
|
103
|
+
const v = arr[++i];
|
|
104
|
+
const trgV = headers[k];
|
|
105
|
+
// Array header -- only Set-Cookie at the moment
|
|
106
|
+
if (trgV && k === 'set-cookie') {
|
|
107
|
+
const a = Array.isArray(trgV) ? trgV : [trgV];
|
|
108
|
+
a.push(v);
|
|
109
|
+
headers[k] = a;
|
|
110
|
+
}
|
|
111
|
+
else if (typeof trgV === 'string') {
|
|
112
|
+
headers[k] += (k === 'cookie' ? '; ' : ', ') + v;
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
headers[k] = v;
|
|
116
|
+
}
|
|
117
|
+
return headers;
|
|
118
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./http-request.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./enums/http-headers.enum.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./enums/http-status.enum.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./interfaces/client-http-headers.interface.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./interfaces/server-http-headers.interface.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./utils/normalize-headers.js"), exports);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BatchMultipart = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const highland_1 = tslib_1.__importDefault(require("highland"));
|
|
6
|
+
const uid_1 = require("uid");
|
|
7
|
+
const type_guards_js_1 = require("../../utils/type-guards.js");
|
|
8
|
+
const http_headers_enum_js_1 = require("../enums/http-headers.enum.js");
|
|
9
|
+
const http_status_enum_js_1 = require("../enums/http-status.enum.js");
|
|
10
|
+
const normalize_headers_js_1 = require("../utils/normalize-headers.js");
|
|
11
|
+
const http_request_content_js_1 = require("./http-request-content.js");
|
|
12
|
+
const http_response_content_js_1 = require("./http-response-content.js");
|
|
13
|
+
const CRLF = '\r\n';
|
|
14
|
+
const CHARSET_PATTERN = / *charset=./i;
|
|
15
|
+
class BatchMultipart {
|
|
16
|
+
_parts = [];
|
|
17
|
+
boundary;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.boundary = 'batch_' + (0, uid_1.uid)(12);
|
|
20
|
+
}
|
|
21
|
+
addRequestPart(content, part) {
|
|
22
|
+
const headers = {
|
|
23
|
+
...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
|
|
24
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
|
|
25
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
|
|
26
|
+
};
|
|
27
|
+
if (part?.contentId)
|
|
28
|
+
headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
|
|
29
|
+
this._parts.push({
|
|
30
|
+
headers,
|
|
31
|
+
contentId: part?.contentId,
|
|
32
|
+
content: new http_request_content_js_1.HttpRequestContent(content)
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
addHttpResponse(content, part) {
|
|
37
|
+
const headers = {
|
|
38
|
+
...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
|
|
39
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
|
|
40
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
|
|
41
|
+
};
|
|
42
|
+
if (part?.contentId)
|
|
43
|
+
headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
|
|
44
|
+
this._parts.push({
|
|
45
|
+
headers,
|
|
46
|
+
contentId: part?.contentId,
|
|
47
|
+
content: new http_response_content_js_1.HttpResponseContent(content)
|
|
48
|
+
});
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
addBatch(batch, part) {
|
|
52
|
+
const headers = {
|
|
53
|
+
...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
|
|
54
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
|
|
55
|
+
[http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
|
|
56
|
+
};
|
|
57
|
+
if (part?.contentId)
|
|
58
|
+
headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
|
|
59
|
+
this._parts.push({
|
|
60
|
+
headers,
|
|
61
|
+
contentId: part?.contentId,
|
|
62
|
+
content: batch
|
|
63
|
+
});
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
stream() {
|
|
67
|
+
const chunks = [];
|
|
68
|
+
this._build(chunks);
|
|
69
|
+
return (0, highland_1.default)(chunks).flatten();
|
|
70
|
+
}
|
|
71
|
+
_build(target) {
|
|
72
|
+
for (const part of this._parts) {
|
|
73
|
+
if (part.content instanceof http_request_content_js_1.HttpRequestContent || part.content instanceof http_response_content_js_1.HttpResponseContent) {
|
|
74
|
+
let contentBody = part.content.data;
|
|
75
|
+
let contentLength = 0;
|
|
76
|
+
const contentHeaders = (0, normalize_headers_js_1.normalizeHeaders)(part.content.headers);
|
|
77
|
+
if (contentBody) {
|
|
78
|
+
const contentType = String(contentHeaders['content-type'] || '').split(/\s*;\s*/);
|
|
79
|
+
let charset = '';
|
|
80
|
+
if ((0, type_guards_js_1.isReadable)(contentBody)) {
|
|
81
|
+
contentLength = parseInt(String(contentHeaders['content-length']), 10) || 0;
|
|
82
|
+
// const l = parseInt(String(contentHeaders['content-length']), 10);
|
|
83
|
+
// if (isNaN(l))
|
|
84
|
+
// throw new TypeError('"content-length" header required for streamed responses');
|
|
85
|
+
}
|
|
86
|
+
else if (typeof contentBody === 'object') {
|
|
87
|
+
if (typeof contentBody.stream === 'function') { // File and Blob
|
|
88
|
+
contentType[0] = contentBody.type || 'binary';
|
|
89
|
+
contentLength = contentBody.size;
|
|
90
|
+
contentBody = contentBody.stream();
|
|
91
|
+
}
|
|
92
|
+
else if (Buffer.isBuffer(contentBody)) {
|
|
93
|
+
contentHeaders['content-length'] = String(contentBody.length);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
contentType[0] = contentType[0] || 'application/json';
|
|
97
|
+
charset = 'utf-8';
|
|
98
|
+
contentBody = Buffer.from(JSON.stringify(contentBody), 'utf-8');
|
|
99
|
+
contentLength = contentBody.length;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
contentType[0] = contentType[0] || 'text/plain';
|
|
104
|
+
charset = 'utf-8';
|
|
105
|
+
contentBody = Buffer.from(String(contentBody), 'utf-8');
|
|
106
|
+
contentLength = contentBody.length;
|
|
107
|
+
}
|
|
108
|
+
if (contentType[0]) {
|
|
109
|
+
if (charset) {
|
|
110
|
+
const i = contentType.findIndex(x => CHARSET_PATTERN.test(String(x)));
|
|
111
|
+
if (i > 0)
|
|
112
|
+
contentType[i] = 'charset=' + charset;
|
|
113
|
+
else
|
|
114
|
+
contentType.join('charset=' + charset);
|
|
115
|
+
}
|
|
116
|
+
contentHeaders['content-type'] = contentType.join(';');
|
|
117
|
+
}
|
|
118
|
+
if (contentLength)
|
|
119
|
+
contentHeaders['content-length'] = String(contentLength);
|
|
120
|
+
}
|
|
121
|
+
let s = '--' + this.boundary + CRLF;
|
|
122
|
+
for (const [k, v] of Object.entries(part.headers)) {
|
|
123
|
+
if (!(v === '' || v == null))
|
|
124
|
+
s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
125
|
+
}
|
|
126
|
+
s += CRLF;
|
|
127
|
+
if (part.content instanceof http_request_content_js_1.HttpRequestContent)
|
|
128
|
+
s += (part.content.method || 'GET').toUpperCase() + ' ' + part.content.url + ' HTTP/1.1' + CRLF;
|
|
129
|
+
else
|
|
130
|
+
s += 'HTTP/1.1 ' + part.content.status + (http_status_enum_js_1.HttpStatus[part.content.status] || 'Unknown') + CRLF;
|
|
131
|
+
if (part.content.headers) {
|
|
132
|
+
for (const [k, v] of Object.entries(part.content.headers)) {
|
|
133
|
+
if (v === '' || v == null)
|
|
134
|
+
continue;
|
|
135
|
+
if (k === 'set-cookie' && Array.isArray(v)) {
|
|
136
|
+
v.forEach(x => s += k + ': ' + x);
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
s += CRLF;
|
|
143
|
+
target.push(Buffer.from(s, 'utf-8'));
|
|
144
|
+
if (contentBody) {
|
|
145
|
+
target.push(contentBody);
|
|
146
|
+
target.push(Buffer.from(CRLF + CRLF));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
throw new Error('Not implemented yet');
|
|
151
|
+
}
|
|
152
|
+
target.push(Buffer.from('--' + this.boundary + '--' + CRLF, 'utf-8'));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.BatchMultipart = BatchMultipart;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRequestContent = void 0;
|
|
4
|
+
class HttpRequestContent {
|
|
5
|
+
method;
|
|
6
|
+
url;
|
|
7
|
+
headers;
|
|
8
|
+
data;
|
|
9
|
+
constructor(init) {
|
|
10
|
+
this.method = init.method;
|
|
11
|
+
this.url = encodeURI(decodeURI(init.url));
|
|
12
|
+
this.headers = init.headers;
|
|
13
|
+
this.data = init.data;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.HttpRequestContent = HttpRequestContent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpResponseContent = void 0;
|
|
4
|
+
class HttpResponseContent {
|
|
5
|
+
status;
|
|
6
|
+
headers;
|
|
7
|
+
data;
|
|
8
|
+
constructor(init) {
|
|
9
|
+
this.status = init.status;
|
|
10
|
+
this.headers = init.headers;
|
|
11
|
+
this.data = init.data;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.HttpResponseContent = HttpResponseContent;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeHeaders = void 0;
|
|
4
|
+
const http_headers_enum_js_1 = require("../enums/http-headers.enum.js");
|
|
5
|
+
const knownKeys = Object.keys(http_headers_enum_js_1.HttpHeaders);
|
|
6
|
+
const knownKeysLower = knownKeys.map(x => x.toLowerCase());
|
|
7
|
+
function normalizeHeaders(headers, normalCase) {
|
|
8
|
+
if (!headers)
|
|
9
|
+
return {};
|
|
10
|
+
return Object.keys(headers).reduce((o, k) => {
|
|
11
|
+
const v = headers[k];
|
|
12
|
+
const key = normalCase
|
|
13
|
+
? knownKeys[knownKeysLower.indexOf(k.toLowerCase())] || camelize(k) :
|
|
14
|
+
k.toLowerCase();
|
|
15
|
+
if (k.toLowerCase() === 'set-cookie')
|
|
16
|
+
o[key] = Array.isArray(v) ? v : [v];
|
|
17
|
+
else {
|
|
18
|
+
o[key] = Array.isArray(v) ? v.join(';') : v;
|
|
19
|
+
}
|
|
20
|
+
return o;
|
|
21
|
+
}, {}) || {};
|
|
22
|
+
}
|
|
23
|
+
exports.normalizeHeaders = normalizeHeaders;
|
|
24
|
+
function camelize(str) {
|
|
25
|
+
return str.replace(/(^\w|[A-Z]|\b\w)/g, function (word) {
|
|
26
|
+
return word.toUpperCase();
|
|
27
|
+
});
|
|
28
|
+
}
|
package/cjs/i18n/i18n.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.I18n = exports.BaseI18n = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
6
|
+
const i18next_1 = tslib_1.__importDefault(require("i18next"));
|
|
7
|
+
const index_js_1 = require("../utils/index.js");
|
|
8
|
+
const string_utils_js_1 = require("./string-utils.js");
|
|
9
|
+
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default).constructor;
|
|
10
|
+
const globalLocaleDirs = [];
|
|
11
|
+
class I18n extends exports.BaseI18n {
|
|
12
|
+
async init(arg0, arg1) {
|
|
13
|
+
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
14
|
+
const callback = typeof arg0 === 'function' ? arg0 : arg1;
|
|
15
|
+
try {
|
|
16
|
+
const t = await super.init(options);
|
|
17
|
+
// Add formatters
|
|
18
|
+
const formatter = this.services.formatter;
|
|
19
|
+
formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
|
|
20
|
+
formatter.add('uppercase', (value, lng) => value.toLocaleUpperCase(lng));
|
|
21
|
+
formatter.add('upperFirst', (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
|
|
22
|
+
// Load globally registered resources
|
|
23
|
+
if (globalLocaleDirs.length)
|
|
24
|
+
await this.loadResourceDir(globalLocaleDirs, false, true);
|
|
25
|
+
// Load resource dirs and overwrite existing
|
|
26
|
+
if (options?.resourceDirs?.length) {
|
|
27
|
+
await this.loadResourceDir(options.resourceDirs, false, true);
|
|
28
|
+
}
|
|
29
|
+
// overwrite existing resources with options.resources
|
|
30
|
+
if (options?.resources) {
|
|
31
|
+
for (const lang of Object.keys(options.resources)) {
|
|
32
|
+
const langObj = options.resources[lang];
|
|
33
|
+
for (const ns of Object.keys(langObj)) {
|
|
34
|
+
this.addResourceBundle(lang, ns, langObj[ns], false, true);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (callback)
|
|
39
|
+
callback(null, t);
|
|
40
|
+
return t;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (callback)
|
|
44
|
+
callback(err, this.t);
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
deep(input, options) {
|
|
49
|
+
if (input == null)
|
|
50
|
+
return input;
|
|
51
|
+
const objectStack = new WeakMap();
|
|
52
|
+
return this._deepTranslate(input, objectStack, options);
|
|
53
|
+
}
|
|
54
|
+
registerLocaleDir(...dirname) {
|
|
55
|
+
globalLocaleDirs.push(...dirname);
|
|
56
|
+
}
|
|
57
|
+
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
58
|
+
let obj;
|
|
59
|
+
if ((0, index_js_1.isUrl)(filePath)) {
|
|
60
|
+
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const fs = await Promise.resolve().then(() => tslib_1.__importStar(require('fs/promises')));
|
|
64
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
65
|
+
obj = JSON.parse(content);
|
|
66
|
+
}
|
|
67
|
+
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
68
|
+
}
|
|
69
|
+
async loadResourceDir(dirnames, deep, overwrite) {
|
|
70
|
+
const fs = await Promise.resolve().then(() => tslib_1.__importStar(require('fs/promises')));
|
|
71
|
+
const path = await Promise.resolve().then(() => tslib_1.__importStar(require('path')));
|
|
72
|
+
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
73
|
+
/* istanbul ignore next */
|
|
74
|
+
if (!(await fs.stat(dirname)).isDirectory()) {
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
76
|
+
console.warn(`Locale directory does not exists. (${dirname})`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const languageDirs = await fs.readdir(dirname);
|
|
80
|
+
for (const lang of languageDirs) {
|
|
81
|
+
const langDir = path.join(dirname, lang);
|
|
82
|
+
if ((await fs.stat(langDir)).isDirectory()) {
|
|
83
|
+
const nsDirs = await fs.readdir(langDir);
|
|
84
|
+
for (const nsfile of nsDirs) {
|
|
85
|
+
const nsFilePath = path.join(langDir, nsfile);
|
|
86
|
+
const ext = path.extname(nsfile);
|
|
87
|
+
if (ext === '.json' && (await fs.stat(nsFilePath)).isFile()) {
|
|
88
|
+
const ns = path.basename(nsfile, ext);
|
|
89
|
+
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
createInstance(options = {}, callback) {
|
|
97
|
+
return new I18n(options, callback);
|
|
98
|
+
}
|
|
99
|
+
static createInstance(options, callback) {
|
|
100
|
+
return new I18n(options, callback);
|
|
101
|
+
}
|
|
102
|
+
_deepTranslate(input, objectStack, options) {
|
|
103
|
+
if (input == null)
|
|
104
|
+
return input;
|
|
105
|
+
if (options?.ignore && options.ignore(input, this))
|
|
106
|
+
return input;
|
|
107
|
+
if (typeof input === 'object' && objectStack.has(input))
|
|
108
|
+
return objectStack.get(input);
|
|
109
|
+
if (typeof input === 'string') {
|
|
110
|
+
let s = '';
|
|
111
|
+
for (let token of (0, fast_tokenizer_1.tokenize)(input, {
|
|
112
|
+
brackets: { '$t(': ')' },
|
|
113
|
+
quotes: true,
|
|
114
|
+
keepQuotes: true,
|
|
115
|
+
keepBrackets: true,
|
|
116
|
+
keepDelimiters: true,
|
|
117
|
+
})) {
|
|
118
|
+
if (token.startsWith('$t(') && token.endsWith(')')) {
|
|
119
|
+
token = token.substring(3, token.length - 1);
|
|
120
|
+
const a = (0, fast_tokenizer_1.splitString)(token, { delimiters: '?', quotes: true, brackets: { '{': '}' } });
|
|
121
|
+
const fallback = (0, string_utils_js_1.unescapeString)(token.substring((a[0] || '').length + 1));
|
|
122
|
+
token = a[0] || '';
|
|
123
|
+
const keys = [];
|
|
124
|
+
let opts = null;
|
|
125
|
+
for (const token2 of (0, fast_tokenizer_1.tokenize)(token, { delimiters: ',', quotes: true, brackets: { '{': '}' } })) {
|
|
126
|
+
if (token2.startsWith('{')) {
|
|
127
|
+
opts = JSON.parse(token2);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
keys.push(token2);
|
|
131
|
+
}
|
|
132
|
+
const k = keys.length > 1 ? '$t(' + keys.join(',') + ')' : keys[0];
|
|
133
|
+
s += fallback
|
|
134
|
+
? this.t(k, fallback, { ...options, ...opts })
|
|
135
|
+
: this.t(k, { ...options, ...opts });
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
s += token;
|
|
139
|
+
}
|
|
140
|
+
return s;
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(input)) {
|
|
143
|
+
const out = Array(input.length);
|
|
144
|
+
objectStack.set(input, out);
|
|
145
|
+
for (let i = 0, l = input.length; i < l; i++) {
|
|
146
|
+
out[i] = this._deepTranslate(input[i], objectStack, options);
|
|
147
|
+
}
|
|
148
|
+
objectStack.delete(input);
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
if (typeof input === 'object') {
|
|
152
|
+
if (Buffer.isBuffer(input))
|
|
153
|
+
return input;
|
|
154
|
+
if (Buffer.isBuffer(input) || input instanceof Symbol ||
|
|
155
|
+
input instanceof RegExp || input instanceof Map || input instanceof Set ||
|
|
156
|
+
input instanceof WeakMap || input instanceof WeakSet)
|
|
157
|
+
return input;
|
|
158
|
+
const out = {};
|
|
159
|
+
objectStack.set(input, out);
|
|
160
|
+
const keys = Object.keys(input);
|
|
161
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
162
|
+
const k = keys[i];
|
|
163
|
+
out[k] = this._deepTranslate(input[k], objectStack, options);
|
|
164
|
+
}
|
|
165
|
+
objectStack.delete(input);
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
return input;
|
|
169
|
+
}
|
|
170
|
+
static get defaultInstance() {
|
|
171
|
+
return defaultInstance;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.I18n = I18n;
|
|
175
|
+
const defaultInstance = I18n.createInstance();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const i18n_js_1 = require("./i18n.js");
|
|
6
|
+
tslib_1.__exportStar(require("./i18n.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./translate.js"), exports);
|
|
8
|
+
const i18n = i18n_js_1.I18n.createInstance();
|
|
9
|
+
exports.i18n = i18n;
|
|
10
|
+
i18n.init().catch(() => void 0);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unescapeString = exports.escapeString = void 0;
|
|
4
|
+
const unescapeRegEx = /\\(.)/g;
|
|
5
|
+
const escapeRegEx = /(\\)/g;
|
|
6
|
+
function escapeString(s) {
|
|
7
|
+
return s.replace(escapeRegEx, '\\\\');
|
|
8
|
+
}
|
|
9
|
+
exports.escapeString = escapeString;
|
|
10
|
+
function unescapeString(s) {
|
|
11
|
+
return s.replace(unescapeRegEx, '$1');
|
|
12
|
+
}
|
|
13
|
+
exports.unescapeString = unescapeString;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translate = void 0;
|
|
4
|
+
const string_utils_js_1 = require("./string-utils.js");
|
|
5
|
+
const bracketRegEx = /(\))/g;
|
|
6
|
+
function translate(key, arg0, arg1) {
|
|
7
|
+
const options = arg0 && typeof arg0 === 'object' ? arg0 : undefined;
|
|
8
|
+
const fallback = typeof arg0 === 'string' ? arg0 : arg1;
|
|
9
|
+
return '$t(' +
|
|
10
|
+
key +
|
|
11
|
+
(options ? ',' + JSON.stringify(options) : '') +
|
|
12
|
+
(fallback ? '?' + (0, string_utils_js_1.escapeString)(fallback).replace(bracketRegEx, '\\$1') : '') +
|
|
13
|
+
')';
|
|
14
|
+
}
|
|
15
|
+
exports.translate = translate;
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uid = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
5
|
-
tslib_1.__exportStar(require("./
|
|
6
|
-
tslib_1.__exportStar(require("./
|
|
7
|
-
tslib_1.__exportStar(require("./
|
|
8
|
-
tslib_1.__exportStar(require("./
|
|
5
|
+
tslib_1.__exportStar(require("./exception/index.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./i18n/index.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./filter/index.js"), exports); // todo. review
|
|
8
|
+
tslib_1.__exportStar(require("./http/multipart/index.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./schema/index.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./url/index.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./http/index.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./helpers/index.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./utils/index.js"), exports);
|
|
14
|
+
var uid_1 = require("uid");
|
|
15
|
+
Object.defineProperty(exports, "uid", { enumerable: true, get: function () { return uid_1.uid; } });
|