@opra/common 0.4.0 → 0.6.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/{responsive-map.js → helpers/responsive-map.js} +1 -1
- package/cjs/http/enums/http-headers.enum.js +404 -0
- package/cjs/http/enums/http-status.enum.js +300 -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 -2
- 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/{responsive-map.d.ts → helpers/responsive-map.d.ts} +0 -0
- package/esm/{responsive-map.js → helpers/responsive-map.js} +1 -1
- package/esm/http/enums/http-headers.enum.d.ts +379 -0
- package/esm/http/enums/http-headers.enum.js +401 -0
- package/esm/http/enums/http-status.enum.d.ts +290 -0
- package/esm/http/enums/http-status.enum.js +297 -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 -2
- package/esm/index.js +10 -2
- 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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './opra-schema.definition.js';
|
|
5
|
+
export * from './decorators/opr-complex-type.decorator.js';
|
|
6
|
+
export * from './decorators/opr-field.decorator.js';
|
|
7
|
+
export * from './decorators/opr-collection-resource.decorator.js';
|
|
8
|
+
export * from './decorators/opr-singleton-resource.decorator.js';
|
|
9
|
+
export * from './decorators/opr-resolver.decorator.js';
|
|
10
|
+
export * from './interfaces/resource-container.interface.js';
|
|
11
|
+
export * from './implementation/document-builder.js';
|
|
12
|
+
export * from './implementation/opra-document.js';
|
|
13
|
+
export * from './implementation/data-type/data-type.js';
|
|
14
|
+
export * from './implementation/data-type/complex-type.js';
|
|
15
|
+
export * from './implementation/data-type/simple-type.js';
|
|
16
|
+
export * from './implementation/data-type/union-type.js';
|
|
17
|
+
export * from './implementation/resource/resource-info.js';
|
|
18
|
+
export * from './implementation/resource/container-resource-info.js';
|
|
19
|
+
export * from './implementation/resource/collection-resource-info.js';
|
|
20
|
+
export * from './implementation/resource/singleton-resource-info.js';
|
|
21
|
+
export * from './implementation/query/index.js';
|
|
22
|
+
export * from './type-helpers/mixin-type.helper.js';
|
|
23
|
+
export * from './type-helpers/extend-type.helper.js';
|
|
24
|
+
export * from './implementation/schema-builder/extract-type-metadata.util.js';
|
|
25
|
+
export * from './implementation/schema-builder/extract-resource-metadata.util.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './opra-schema.definition.js';
|
|
5
|
+
export * from './decorators/opr-complex-type.decorator.js';
|
|
6
|
+
export * from './decorators/opr-field.decorator.js';
|
|
7
|
+
export * from './decorators/opr-collection-resource.decorator.js';
|
|
8
|
+
export * from './decorators/opr-singleton-resource.decorator.js';
|
|
9
|
+
export * from './decorators/opr-resolver.decorator.js';
|
|
10
|
+
export * from './interfaces/resource-container.interface.js';
|
|
11
|
+
export * from './implementation/document-builder.js';
|
|
12
|
+
export * from './implementation/opra-document.js';
|
|
13
|
+
export * from './implementation/data-type/data-type.js';
|
|
14
|
+
export * from './implementation/data-type/complex-type.js';
|
|
15
|
+
export * from './implementation/data-type/simple-type.js';
|
|
16
|
+
export * from './implementation/data-type/union-type.js';
|
|
17
|
+
export * from './implementation/resource/resource-info.js';
|
|
18
|
+
export * from './implementation/resource/container-resource-info.js';
|
|
19
|
+
export * from './implementation/resource/collection-resource-info.js';
|
|
20
|
+
export * from './implementation/resource/singleton-resource-info.js';
|
|
21
|
+
export * from './implementation/query/index.js';
|
|
22
|
+
export * from './type-helpers/mixin-type.helper.js';
|
|
23
|
+
export * from './type-helpers/extend-type.helper.js';
|
|
24
|
+
export * from './implementation/schema-builder/extract-type-metadata.util.js';
|
|
25
|
+
export * from './implementation/schema-builder/extract-resource-metadata.util.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../opra-schema.definition.js';
|
|
3
|
+
import { TypeThunkAsync } from '../types.js';
|
|
4
|
+
export declare type SimpleTypeMetadata = OpraSchema.SimpleType & {
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type ComplexTypeMetadata = StrictOmit<OpraSchema.ComplexType, 'fields' | 'extends'> & {
|
|
8
|
+
name: string;
|
|
9
|
+
extends?: ComplexTypeExtendingMetadata[];
|
|
10
|
+
fields?: Record<string, FieldMetadata>;
|
|
11
|
+
};
|
|
12
|
+
export declare type FieldMetadata = StrictOmit<OpraSchema.Field, 'type'> & {
|
|
13
|
+
type?: string | TypeThunkAsync | (string | TypeThunkAsync)[];
|
|
14
|
+
};
|
|
15
|
+
declare type ComplexTypeExtendingMetadata = StrictOmit<OpraSchema.ComplexTypeExtendingInfo, 'type'> & {
|
|
16
|
+
type: string | Type;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CollectionResourceInfo } from '../implementation/resource/collection-resource-info.js';
|
|
2
|
+
import { ResourceInfo } from '../implementation/resource/resource-info.js';
|
|
3
|
+
import { SingletonResourceInfo } from '../implementation/resource/singleton-resource-info.js';
|
|
4
|
+
export interface IResourceContainer {
|
|
5
|
+
getResource<T extends ResourceInfo>(name: string): T;
|
|
6
|
+
getCollectionResource(name: string): CollectionResourceInfo;
|
|
7
|
+
getSingletonResource(name: string): SingletonResourceInfo;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PartialSome, StrictOmit } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../opra-schema.definition.js';
|
|
3
|
+
import { TypeThunkAsync } from '../types.js';
|
|
4
|
+
export declare type CollectionResourceMetadata = PartialSome<StrictOmit<OpraSchema.CollectionResource, 'type'>, 'keyFields'> & {
|
|
5
|
+
type: TypeThunkAsync | string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type SingletonResourceMetadata = StrictOmit<OpraSchema.SingletonResource, 'type'> & {
|
|
9
|
+
type: TypeThunkAsync | string;
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type ICreateResolverMetadata = StrictOmit<OpraSchema.CreateMethodResolver, 'handler'>;
|
|
13
|
+
export declare type IDeleteResolverMetadata = StrictOmit<OpraSchema.DeleteMethodResolver, 'handler'>;
|
|
14
|
+
export declare type IDeleteManyResolverMetadata = StrictOmit<OpraSchema.DeleteManyMethodResolver, 'handler'>;
|
|
15
|
+
export declare type IGetResolverMetadata = StrictOmit<OpraSchema.GetMethodResolver, 'handler'>;
|
|
16
|
+
export declare type IUpdateResolverMetadata = StrictOmit<OpraSchema.UpdateMethodResolver, 'handler'>;
|
|
17
|
+
export declare type IUpdateManyResolverMetadata = StrictOmit<OpraSchema.UpdateManyMethodResolver, 'handler'>;
|
|
18
|
+
export declare type ISearchResolverMetadata = StrictOmit<OpraSchema.SearchMethodResolver, 'handler'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Type } from 'ts-gems';
|
|
2
|
+
import { ComparisonOperator } from '../filter/index.js';
|
|
3
|
+
export declare namespace OpraSchema {
|
|
4
|
+
/**
|
|
5
|
+
* *** === Constants === ***
|
|
6
|
+
*/
|
|
7
|
+
export const Version = "1.0";
|
|
8
|
+
/**
|
|
9
|
+
* *** === Type definitions === ***
|
|
10
|
+
*/
|
|
11
|
+
export type Extensible<T = any> = {
|
|
12
|
+
[key: `$${string}`]: T;
|
|
13
|
+
};
|
|
14
|
+
export type ResourceKind = 'ContainerResource' | 'CollectionResource' | 'SingletonResource';
|
|
15
|
+
export type DataTypeKind = 'SimpleType' | 'ComplexType' | 'UnionType';
|
|
16
|
+
export type SingletonMethod = 'get' | 'create' | 'update' | 'delete';
|
|
17
|
+
export type CollectionMethod = SingletonMethod | 'search' | 'count' | 'updateMany' | 'deleteMany';
|
|
18
|
+
/**
|
|
19
|
+
* *** === Document related === ***
|
|
20
|
+
*/
|
|
21
|
+
export interface Document {
|
|
22
|
+
version: string;
|
|
23
|
+
info: DocumentInfo;
|
|
24
|
+
references?: Record<string, Reference>;
|
|
25
|
+
types?: Record<string, DataType>;
|
|
26
|
+
resources?: Record<string, Resource>;
|
|
27
|
+
servers?: ServerInfo[];
|
|
28
|
+
}
|
|
29
|
+
export type ServerInfo = Extensible & {
|
|
30
|
+
url: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
};
|
|
33
|
+
export type Reference = Extensible & {
|
|
34
|
+
url?: string;
|
|
35
|
+
document?: Document;
|
|
36
|
+
};
|
|
37
|
+
export type DocumentInfo = Extensible & {
|
|
38
|
+
title: string;
|
|
39
|
+
version: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
termsOfService?: string;
|
|
42
|
+
contact?: ContactPerson[];
|
|
43
|
+
license?: LicenseInfo;
|
|
44
|
+
};
|
|
45
|
+
export type ContactPerson = Extensible & {
|
|
46
|
+
name?: string;
|
|
47
|
+
email?: string;
|
|
48
|
+
url?: string;
|
|
49
|
+
};
|
|
50
|
+
export type LicenseInfo = Extensible & {
|
|
51
|
+
name: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
content?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* *** === Data Type related === ***
|
|
57
|
+
*/
|
|
58
|
+
export type DataType = ComplexType | SimpleType | UnionType;
|
|
59
|
+
export type BaseDataType = {
|
|
60
|
+
kind: DataTypeKind;
|
|
61
|
+
description?: string;
|
|
62
|
+
ctor?: Type;
|
|
63
|
+
parse?: (v: any) => any;
|
|
64
|
+
serialize?: (v: any) => any;
|
|
65
|
+
};
|
|
66
|
+
export interface SimpleType extends BaseDataType {
|
|
67
|
+
kind: 'SimpleType';
|
|
68
|
+
}
|
|
69
|
+
export interface UnionType extends BaseDataType {
|
|
70
|
+
kind: 'UnionType';
|
|
71
|
+
types: DataType[];
|
|
72
|
+
}
|
|
73
|
+
export interface ComplexType extends BaseDataType {
|
|
74
|
+
kind: 'ComplexType';
|
|
75
|
+
description?: string;
|
|
76
|
+
abstract?: boolean;
|
|
77
|
+
extends?: ComplexTypeExtendingInfo[];
|
|
78
|
+
fields?: Record<string, Field>;
|
|
79
|
+
additionalFields?: boolean | string | Pick<Field, 'type' | 'format' | 'isArray' | 'enum'>;
|
|
80
|
+
}
|
|
81
|
+
export interface ComplexTypeExtendingInfo {
|
|
82
|
+
type: string;
|
|
83
|
+
pick?: string[];
|
|
84
|
+
omit?: string[];
|
|
85
|
+
}
|
|
86
|
+
export type Field = Extensible & {
|
|
87
|
+
type: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
required?: boolean;
|
|
90
|
+
isArray?: boolean;
|
|
91
|
+
format?: string;
|
|
92
|
+
default?: any;
|
|
93
|
+
fixed?: string | number;
|
|
94
|
+
enum?: string | string[] | Record<string, string>;
|
|
95
|
+
enumName?: string;
|
|
96
|
+
examples?: any[] | Record<string, any>;
|
|
97
|
+
deprecated?: boolean | string;
|
|
98
|
+
/**
|
|
99
|
+
* If true, this property will not be included in results by default.
|
|
100
|
+
* The client side should include the property name in the "include" query parameter.
|
|
101
|
+
*/
|
|
102
|
+
exclusive?: boolean;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* *** === Resource related === ***
|
|
106
|
+
*/
|
|
107
|
+
export type Resource = ContainerResource | CollectionResource | SingletonResource;
|
|
108
|
+
export interface BaseResource {
|
|
109
|
+
kind: ResourceKind;
|
|
110
|
+
description?: string;
|
|
111
|
+
instance?: {};
|
|
112
|
+
}
|
|
113
|
+
export interface CollectionResource extends BaseResource {
|
|
114
|
+
kind: 'CollectionResource';
|
|
115
|
+
type: string;
|
|
116
|
+
keyFields: string | string[];
|
|
117
|
+
create?: CreateMethodResolver;
|
|
118
|
+
count?: CountMethodResolver;
|
|
119
|
+
delete?: DeleteMethodResolver;
|
|
120
|
+
deleteMany?: DeleteManyMethodResolver;
|
|
121
|
+
get?: GetMethodResolver;
|
|
122
|
+
update?: UpdateMethodResolver;
|
|
123
|
+
updateMany?: UpdateManyMethodResolver;
|
|
124
|
+
search?: SearchMethodResolver;
|
|
125
|
+
}
|
|
126
|
+
export interface SingletonResource extends BaseResource {
|
|
127
|
+
kind: 'SingletonResource';
|
|
128
|
+
type: string;
|
|
129
|
+
create?: CreateMethodResolver;
|
|
130
|
+
get?: GetMethodResolver;
|
|
131
|
+
update?: UpdateMethodResolver;
|
|
132
|
+
delete?: DeleteMethodResolver;
|
|
133
|
+
}
|
|
134
|
+
export interface ContainerResource extends BaseResource {
|
|
135
|
+
kind: 'ContainerResource';
|
|
136
|
+
resources: Resource[];
|
|
137
|
+
}
|
|
138
|
+
export type MethodResolver = {
|
|
139
|
+
handler?: Function;
|
|
140
|
+
};
|
|
141
|
+
type MethodResolverInputOptions = {
|
|
142
|
+
inputPick?: string[];
|
|
143
|
+
inputOmit?: string[];
|
|
144
|
+
};
|
|
145
|
+
type MethodResolverOutputOptions = {
|
|
146
|
+
outputPick?: string[];
|
|
147
|
+
outputOmit?: string[];
|
|
148
|
+
};
|
|
149
|
+
type MethodResolverFilterOptions = {
|
|
150
|
+
filters?: {
|
|
151
|
+
field: string;
|
|
152
|
+
operators?: ComparisonOperator[];
|
|
153
|
+
}[];
|
|
154
|
+
};
|
|
155
|
+
export type CreateMethodResolver = MethodResolver & MethodResolverInputOptions & MethodResolverOutputOptions;
|
|
156
|
+
export type CountMethodResolver = MethodResolver & {};
|
|
157
|
+
export type DeleteMethodResolver = MethodResolver & {};
|
|
158
|
+
export type DeleteManyMethodResolver = MethodResolver & MethodResolverFilterOptions;
|
|
159
|
+
export type GetMethodResolver = MethodResolver & MethodResolverOutputOptions;
|
|
160
|
+
export type UpdateMethodResolver = MethodResolver & MethodResolverInputOptions & MethodResolverOutputOptions;
|
|
161
|
+
export type UpdateManyMethodResolver = MethodResolver & MethodResolverFilterOptions;
|
|
162
|
+
export type SearchMethodResolver = MethodResolver & MethodResolverOutputOptions & {
|
|
163
|
+
sortFields?: string[];
|
|
164
|
+
defaultSort?: string[];
|
|
165
|
+
} & MethodResolverFilterOptions;
|
|
166
|
+
/**
|
|
167
|
+
* *** === Type Guards === ***
|
|
168
|
+
*/
|
|
169
|
+
export function isDataType(obj: any): obj is DataType;
|
|
170
|
+
export function isComplexType(obj: any): obj is ComplexType;
|
|
171
|
+
export function isSimpleType(obj: any): obj is SimpleType;
|
|
172
|
+
export function isUnionTypee(obj: any): obj is UnionType;
|
|
173
|
+
export function isResource(obj: any): obj is Resource;
|
|
174
|
+
export function isCollectionResource(obj: any): obj is CollectionResource;
|
|
175
|
+
export function isSingletonResource(obj: any): obj is SingletonResource;
|
|
176
|
+
export function isContainerResource(obj: any): obj is ContainerResource;
|
|
177
|
+
export {};
|
|
178
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export var OpraSchema;
|
|
2
|
+
(function (OpraSchema) {
|
|
3
|
+
/**
|
|
4
|
+
* *** === Constants === ***
|
|
5
|
+
*/
|
|
6
|
+
OpraSchema.Version = '1.0';
|
|
7
|
+
/**
|
|
8
|
+
* *** === Type Guards === ***
|
|
9
|
+
*/
|
|
10
|
+
function isDataType(obj) {
|
|
11
|
+
return obj && typeof obj === 'object' &&
|
|
12
|
+
(obj.kind === 'ComplexType' || obj.kind === 'SimpleType' || obj.kind === 'UnionType');
|
|
13
|
+
}
|
|
14
|
+
OpraSchema.isDataType = isDataType;
|
|
15
|
+
function isComplexType(obj) {
|
|
16
|
+
return obj && typeof obj === 'object' && obj.kind === 'ComplexType';
|
|
17
|
+
}
|
|
18
|
+
OpraSchema.isComplexType = isComplexType;
|
|
19
|
+
function isSimpleType(obj) {
|
|
20
|
+
return obj && typeof obj === 'object' && obj.kind === 'SimpleType';
|
|
21
|
+
}
|
|
22
|
+
OpraSchema.isSimpleType = isSimpleType;
|
|
23
|
+
function isUnionTypee(obj) {
|
|
24
|
+
return obj && typeof obj === 'object' && obj.kind === 'UnionType';
|
|
25
|
+
}
|
|
26
|
+
OpraSchema.isUnionTypee = isUnionTypee;
|
|
27
|
+
function isResource(obj) {
|
|
28
|
+
return obj && typeof obj === 'object' &&
|
|
29
|
+
obj.kind === 'ContainerResource' ||
|
|
30
|
+
obj.kind === 'CollectionResource' ||
|
|
31
|
+
obj.kind === 'SingletonResource';
|
|
32
|
+
}
|
|
33
|
+
OpraSchema.isResource = isResource;
|
|
34
|
+
function isCollectionResource(obj) {
|
|
35
|
+
return obj && typeof obj === 'object' && obj.kind === 'CollectionResource';
|
|
36
|
+
}
|
|
37
|
+
OpraSchema.isCollectionResource = isCollectionResource;
|
|
38
|
+
function isSingletonResource(obj) {
|
|
39
|
+
return obj && typeof obj === 'object' && obj.kind === 'SingletonResource';
|
|
40
|
+
}
|
|
41
|
+
OpraSchema.isSingletonResource = isSingletonResource;
|
|
42
|
+
function isContainerResource(obj) {
|
|
43
|
+
return obj && typeof obj === 'object' && obj.kind === 'ContainerResource';
|
|
44
|
+
}
|
|
45
|
+
OpraSchema.isContainerResource = isContainerResource;
|
|
46
|
+
})(OpraSchema || (OpraSchema = {}));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Class } from 'ts-gems';
|
|
2
|
+
export declare function PickType<T extends any[], I1, S1, K extends keyof I1>(classRef: Class<T, I1, S1>, keys: readonly K[]): Class<T, Pick<I1, K>> & Omit<Pick<S1, keyof typeof classRef>, 'prototype' | 'constructor'>;
|
|
3
|
+
export declare function OmitType<T extends any[], I1, S1, K extends keyof I1>(classRef: Class<T, I1, S1>, keys: readonly K[]): Class<T, Omit<I1, K>> & Omit<Pick<S1, keyof typeof classRef>, 'prototype' | 'constructor'>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as Optionals from '@opra/optionals';
|
|
2
|
+
import { DATATYPE_METADATA, MAPPED_TYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { applyMixins, inheritPropertyInitializers } from './mixin.utils.js';
|
|
4
|
+
export function PickType(classRef, keys) {
|
|
5
|
+
return ExtendType(classRef, classRef, { pickKeys: keys });
|
|
6
|
+
}
|
|
7
|
+
export function OmitType(classRef, keys) {
|
|
8
|
+
return ExtendType(classRef, classRef, { omitKeys: keys });
|
|
9
|
+
}
|
|
10
|
+
function ExtendType(classRef, orgClassRef, options) {
|
|
11
|
+
const pickKeys = options.pickKeys && options.pickKeys.map(x => String(x).toLowerCase());
|
|
12
|
+
const omitKeys = options.omitKeys && options.omitKeys.map(x => String(x).toLowerCase());
|
|
13
|
+
const isInheritedPredicate = (propertyName) => {
|
|
14
|
+
if (omitKeys && omitKeys.includes(propertyName.toLowerCase()))
|
|
15
|
+
return false;
|
|
16
|
+
if (pickKeys)
|
|
17
|
+
return pickKeys.includes(propertyName.toLowerCase());
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
// const isRequiredPredicate = (propertyName: string): boolean | undefined => {
|
|
21
|
+
// if (options.requiredKeys && options.requiredKeys.includes(propertyName as RequiredKey))
|
|
22
|
+
// return true;
|
|
23
|
+
// if (options.partialKeys && options.partialKeys.includes(propertyName as PartialKey))
|
|
24
|
+
// return false;
|
|
25
|
+
// return;
|
|
26
|
+
// };
|
|
27
|
+
class MappedClass {
|
|
28
|
+
constructor() {
|
|
29
|
+
inheritPropertyInitializers(this, classRef, isInheritedPredicate);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
applyMixins(MappedClass, classRef);
|
|
33
|
+
const mappedTypeMetadata = [];
|
|
34
|
+
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, classRef);
|
|
35
|
+
if (m) {
|
|
36
|
+
if (!(m.kind === 'ComplexType'))
|
|
37
|
+
throw new TypeError(`Class "${classRef}" is not a ComplexType`);
|
|
38
|
+
const meta = {
|
|
39
|
+
type: classRef
|
|
40
|
+
};
|
|
41
|
+
if (options.pickKeys)
|
|
42
|
+
meta.pick = options.pickKeys;
|
|
43
|
+
if (options.omitKeys)
|
|
44
|
+
meta.omit = options.omitKeys;
|
|
45
|
+
mappedTypeMetadata.push(meta);
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
throw new TypeError(`Class "${classRef}" doesn't have datatype metadata information`);
|
|
49
|
+
if (Optionals.SqbConnect) {
|
|
50
|
+
const { Entity, EntityMetadata } = Optionals.SqbConnect;
|
|
51
|
+
const srcMeta = Entity.getMetadata(classRef);
|
|
52
|
+
if (srcMeta) {
|
|
53
|
+
const trgMeta = EntityMetadata.define(MappedClass);
|
|
54
|
+
EntityMetadata.mixin(trgMeta, srcMeta, k => isInheritedPredicate(k));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
Reflect.defineMetadata(MAPPED_TYPE_METADATA, mappedTypeMetadata, MappedClass);
|
|
58
|
+
return MappedClass;
|
|
59
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Class } from 'ts-gems';
|
|
2
|
+
export declare function MixinType<A1 extends any[], I1, S1, A2 extends any[], I2, S2, A3 extends any[], I3, S3, A4 extends any[], I4, S4>(c1: Class<A1, I1, S1>, c2: Class<A2, I2, S2>, c3?: Class<A3, I3, S3>, c4?: Class<A4, I4, S4>): Class<any[], I1 & I2 & I3 & I4, S1 & S2 & S3 & S4>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Optionals from '@opra/optionals';
|
|
2
|
+
import { DATATYPE_METADATA, MAPPED_TYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { applyMixins, inheritPropertyInitializers } from './mixin.utils.js';
|
|
4
|
+
export function MixinType(c1, c2, c3, c4) {
|
|
5
|
+
const clasRefs = [...arguments].filter(x => !!x);
|
|
6
|
+
if (!clasRefs.length)
|
|
7
|
+
throw new TypeError('You must provide base classeses');
|
|
8
|
+
if (clasRefs.length === 1)
|
|
9
|
+
return clasRefs[0];
|
|
10
|
+
class MappedClass {
|
|
11
|
+
constructor() {
|
|
12
|
+
for (const c of clasRefs)
|
|
13
|
+
inheritPropertyInitializers(this, c);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const mappedTypeMetadata = [];
|
|
17
|
+
for (const c of clasRefs) {
|
|
18
|
+
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, c);
|
|
19
|
+
if (m) {
|
|
20
|
+
if (!(m.kind === 'ComplexType'))
|
|
21
|
+
throw new TypeError(`Class "${c}" is not a ComplexType`);
|
|
22
|
+
mappedTypeMetadata.push({
|
|
23
|
+
type: c
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (Reflect.hasMetadata(MAPPED_TYPE_METADATA, c)) {
|
|
27
|
+
const mtm = Reflect.getMetadata(MAPPED_TYPE_METADATA, c);
|
|
28
|
+
if (mtm)
|
|
29
|
+
mappedTypeMetadata.push(...mtm);
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
throw new TypeError(`Class "${c}" doesn't have datatype metadata information`);
|
|
33
|
+
applyMixins(MappedClass, c);
|
|
34
|
+
}
|
|
35
|
+
if (Optionals.SqbConnect) {
|
|
36
|
+
const { Entity } = Optionals.SqbConnect;
|
|
37
|
+
Entity.mixin(MappedClass, ...clasRefs);
|
|
38
|
+
}
|
|
39
|
+
Reflect.defineMetadata(MAPPED_TYPE_METADATA, mappedTypeMetadata, MappedClass);
|
|
40
|
+
return MappedClass;
|
|
41
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Type } from 'ts-gems';
|
|
2
|
+
export declare function applyMixins(derivedCtor: any, baseCtor: any, filter?: (k: string) => boolean): void;
|
|
3
|
+
export declare function inheritPropertyInitializers(target: Record<string, any>, sourceClass: Type, isPropertyInherited?: (key: string) => boolean): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function applyMixins(derivedCtor, baseCtor, filter) {
|
|
2
|
+
for (const k of Object.getOwnPropertyNames(baseCtor.prototype)) {
|
|
3
|
+
if ((k === 'constructor' || k === '__proto__' || k === 'toJSON' || k === 'toString') ||
|
|
4
|
+
filter && !filter(k))
|
|
5
|
+
continue;
|
|
6
|
+
Object.defineProperty(derivedCtor.prototype, k, Object.getOwnPropertyDescriptor(baseCtor.prototype, k) ||
|
|
7
|
+
Object.create(null));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function inheritPropertyInitializers(target, sourceClass,
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
isPropertyInherited = (key) => true) {
|
|
13
|
+
try {
|
|
14
|
+
const tempInstance = new sourceClass();
|
|
15
|
+
const propertyNames = Object.getOwnPropertyNames(tempInstance);
|
|
16
|
+
propertyNames
|
|
17
|
+
.filter((propertyName) => typeof tempInstance[propertyName] !== 'undefined' &&
|
|
18
|
+
typeof target[propertyName] === 'undefined')
|
|
19
|
+
.filter((propertyName) => isPropertyInherited(propertyName))
|
|
20
|
+
.forEach((propertyName) => {
|
|
21
|
+
target[propertyName] = tempInstance[propertyName];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
//
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { Builtin, DeepPickWritable } from 'ts-gems';
|
|
1
|
+
import { Builtin, DeepPickWritable, Type } from 'ts-gems';
|
|
2
2
|
export declare type PartialInput<T> = DeepNullablePartial<DeepPickWritable<T>>;
|
|
3
3
|
export declare type PartialOutput<T> = DeepNullablePartial<T>;
|
|
4
4
|
declare type DeepNullablePartial<T> = T extends Builtin ? T : T extends Promise<infer U> ? Promise<DeepNullablePartial<U>> : T extends (infer U)[] ? DeepNullablePartial<U>[] : {
|
|
5
5
|
[P in keyof T]?: DeepNullablePartial<Exclude<T[P], undefined>> | null;
|
|
6
6
|
};
|
|
7
|
+
export declare type Thunk<T> = T | (() => T);
|
|
8
|
+
export declare type ThunkAsync<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
|
|
9
|
+
export declare type TypeThunk<T = any> = Thunk<Type<T>>;
|
|
10
|
+
export declare type TypeThunkAsync<T = any> = ThunkAsync<Type<T>>;
|
|
11
|
+
export declare type Named<T> = T & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
7
14
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cloneObject<T extends {}>(obj: T, jsonOnly?: boolean): T;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import isPlainObject from 'putil-isplainobject';
|
|
2
|
+
import merge from 'putil-merge';
|
|
3
|
+
export function cloneObject(obj, jsonOnly) {
|
|
4
|
+
return merge({}, obj, {
|
|
5
|
+
deep: true,
|
|
6
|
+
clone: true,
|
|
7
|
+
filter: (source, key) => {
|
|
8
|
+
const v = source[key];
|
|
9
|
+
return v != null &&
|
|
10
|
+
!jsonOnly || (typeof v !== 'function' &&
|
|
11
|
+
(typeof v !== 'object' || isPlainObject(v) || Array.isArray(v)));
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ComplexType } from '../implementation/data-type/complex-type.js';
|
|
2
|
+
import type { OpraDocument } from '../implementation/opra-document.js';
|
|
3
|
+
export declare function normalizeFieldArray(document: OpraDocument, dataType: ComplexType | undefined, fields: string[], parentPath?: string): string[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComplexType } from '../implementation/data-type/complex-type.js';
|
|
2
|
+
import { pathToTree } from './path-to-tree.util.js';
|
|
3
|
+
export function normalizeFieldArray(document, dataType, fields, parentPath = '') {
|
|
4
|
+
const fieldsTree = pathToTree(fields) || {};
|
|
5
|
+
return _normalizeFieldsList([], document, dataType, fieldsTree, '', parentPath, {
|
|
6
|
+
additionalFields: true
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function _normalizeFieldsList(target, document, dataType, node, parentPath = '', actualPath = '', options) {
|
|
10
|
+
let curPath = '';
|
|
11
|
+
for (const k of Object.keys(node)) {
|
|
12
|
+
const nodeVal = node[k];
|
|
13
|
+
const prop = dataType?.fields.get(k);
|
|
14
|
+
if (!prop) {
|
|
15
|
+
curPath = parentPath ? parentPath + '.' + k : k;
|
|
16
|
+
if (!options?.additionalFields || (dataType && !dataType.additionalFields))
|
|
17
|
+
throw new TypeError(`Unknown field "${curPath}"`);
|
|
18
|
+
if (typeof nodeVal === 'object')
|
|
19
|
+
_normalizeFieldsList(target, document, undefined, nodeVal, curPath, actualPath, options);
|
|
20
|
+
else
|
|
21
|
+
target.push(curPath);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
curPath = parentPath ? parentPath + '.' + prop.name : prop.name;
|
|
25
|
+
const propType = document.getDataType(prop.type || 'string');
|
|
26
|
+
if (typeof nodeVal === 'object') {
|
|
27
|
+
if (!(propType && propType instanceof ComplexType))
|
|
28
|
+
throw new TypeError(`"${(actualPath ? actualPath + '.' + curPath : curPath)}" is not a complex type and has no sub fields`);
|
|
29
|
+
if (target.findIndex(x => x === parentPath) >= 0)
|
|
30
|
+
continue;
|
|
31
|
+
target = _normalizeFieldsList(target, document, propType, nodeVal, curPath, actualPath, options);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (target.findIndex(x => x.startsWith(curPath + '.')) >= 0) {
|
|
35
|
+
target = target.filter(x => !x.startsWith(curPath + '.'));
|
|
36
|
+
}
|
|
37
|
+
target.push(curPath);
|
|
38
|
+
}
|
|
39
|
+
return target;
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const dotPattern = /^([^.]+)\.(.*)$/;
|
|
2
|
+
export function pathToTree(arr) {
|
|
3
|
+
if (!arr.length)
|
|
4
|
+
return;
|
|
5
|
+
return _stringPathToObjectTree(arr, {});
|
|
6
|
+
}
|
|
7
|
+
function _stringPathToObjectTree(arr, target) {
|
|
8
|
+
for (const k of arr) {
|
|
9
|
+
const m = dotPattern.exec(k);
|
|
10
|
+
if (m) {
|
|
11
|
+
const key = m[1];
|
|
12
|
+
if (target[key] === true)
|
|
13
|
+
continue;
|
|
14
|
+
const sub = target[key] = typeof target[key] === 'object' ? target[key] : {};
|
|
15
|
+
_stringPathToObjectTree([m[2]], sub);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
target[k] = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stringCompare(a: string, b: string): number;
|