@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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.primitiveClasses = exports.builtInTypes = void 0;
|
|
4
|
+
const responsive_map_js_1 = require("../../../helpers/responsive-map.js");
|
|
5
|
+
const any_type_js_1 = require("./builtin/any.type.js");
|
|
6
|
+
const base64_binary_type_js_1 = require("./builtin/base64-binary.type.js");
|
|
7
|
+
const bigint_type_js_1 = require("./builtin/bigint.type.js");
|
|
8
|
+
const boolean_type_js_1 = require("./builtin/boolean.type.js");
|
|
9
|
+
const date_type_js_1 = require("./builtin/date.type.js");
|
|
10
|
+
const date_string_type_js_1 = require("./builtin/date-string.type.js");
|
|
11
|
+
const guid_type_js_1 = require("./builtin/guid.type.js");
|
|
12
|
+
const integer_type_js_1 = require("./builtin/integer.type.js");
|
|
13
|
+
const number_type_js_1 = require("./builtin/number.type.js");
|
|
14
|
+
const object_type_js_1 = require("./builtin/object.type.js");
|
|
15
|
+
const string_type_js_1 = require("./builtin/string.type.js");
|
|
16
|
+
const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
|
|
17
|
+
const BufferConstructor = Object.getPrototypeOf(Buffer.from('')).constructor;
|
|
18
|
+
exports.builtInTypes = new responsive_map_js_1.ResponsiveMap();
|
|
19
|
+
exports.builtInTypes.set('any', any_type_js_1.AnyType);
|
|
20
|
+
exports.builtInTypes.set('base64Binary', base64_binary_type_js_1.Base64BinaryType);
|
|
21
|
+
exports.builtInTypes.set('bigint', bigint_type_js_1.BigIntType);
|
|
22
|
+
exports.builtInTypes.set('boolean', boolean_type_js_1.BooleanType);
|
|
23
|
+
exports.builtInTypes.set('date', date_type_js_1.DateType);
|
|
24
|
+
exports.builtInTypes.set('dateString', date_string_type_js_1.DateStringType);
|
|
25
|
+
exports.builtInTypes.set('guid', guid_type_js_1.GuidType);
|
|
26
|
+
exports.builtInTypes.set('integer', integer_type_js_1.IntegerType);
|
|
27
|
+
exports.builtInTypes.set('number', number_type_js_1.NumberType);
|
|
28
|
+
exports.builtInTypes.set('object', object_type_js_1.ObjectType);
|
|
29
|
+
exports.builtInTypes.set('string', string_type_js_1.StringType);
|
|
30
|
+
exports.primitiveClasses = new Map();
|
|
31
|
+
exports.primitiveClasses.set(Boolean, 'boolean');
|
|
32
|
+
exports.primitiveClasses.set(String, 'string');
|
|
33
|
+
exports.primitiveClasses.set(Number, 'number');
|
|
34
|
+
exports.primitiveClasses.set(Date, 'date');
|
|
35
|
+
exports.primitiveClasses.set(BigIntConstructor, 'bigint');
|
|
36
|
+
exports.primitiveClasses.set(BufferConstructor, 'base64Binary');
|
|
37
|
+
exports.primitiveClasses.set(Object, 'object');
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComplexType = void 0;
|
|
4
|
+
const responsive_map_js_1 = require("../../../helpers/responsive-map.js");
|
|
5
|
+
const clone_object_util_js_1 = require("../../utils/clone-object.util.js");
|
|
6
|
+
const inspect_util_js_1 = require("../../utils/inspect.util.js");
|
|
7
|
+
const data_type_js_1 = require("./data-type.js");
|
|
8
|
+
class ComplexType extends data_type_js_1.DataType {
|
|
9
|
+
_initialized = false;
|
|
10
|
+
_mixinAdditionalFields;
|
|
11
|
+
ownFields = new responsive_map_js_1.ResponsiveMap();
|
|
12
|
+
fields = new responsive_map_js_1.ResponsiveMap();
|
|
13
|
+
constructor(owner, name, args) {
|
|
14
|
+
super(owner, name, {
|
|
15
|
+
kind: 'ComplexType',
|
|
16
|
+
...args
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get abstract() {
|
|
20
|
+
return !!this._metadata.abstract;
|
|
21
|
+
}
|
|
22
|
+
get additionalFields() {
|
|
23
|
+
return this._metadata.additionalFields || this._mixinAdditionalFields;
|
|
24
|
+
}
|
|
25
|
+
get extends() {
|
|
26
|
+
return this._metadata.extends;
|
|
27
|
+
}
|
|
28
|
+
getField(fieldName) {
|
|
29
|
+
if (fieldName.includes('.')) {
|
|
30
|
+
let dt = this;
|
|
31
|
+
const arr = fieldName.split('.');
|
|
32
|
+
let field;
|
|
33
|
+
for (const a of arr) {
|
|
34
|
+
field = dt.getField(a);
|
|
35
|
+
dt = dt.document.getDataType(field.type || 'string');
|
|
36
|
+
}
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
return field;
|
|
39
|
+
}
|
|
40
|
+
const t = this.fields.get(fieldName);
|
|
41
|
+
if (!t)
|
|
42
|
+
throw new Error(`"${this.name}" type doesn't have a field named "${fieldName}"`);
|
|
43
|
+
return t;
|
|
44
|
+
}
|
|
45
|
+
getFieldType(fieldName) {
|
|
46
|
+
const field = this.getField(fieldName);
|
|
47
|
+
return this.document.getDataType(field.type || 'string');
|
|
48
|
+
}
|
|
49
|
+
getOwnField(name) {
|
|
50
|
+
const t = this.ownFields.get(name);
|
|
51
|
+
if (!t)
|
|
52
|
+
throw new Error(`"${this.name}" type doesn't have an own field named "${name}"`);
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
getSchema() {
|
|
56
|
+
const out = super.getSchema();
|
|
57
|
+
if (this.additionalFields)
|
|
58
|
+
out.additionalFields = this.additionalFields;
|
|
59
|
+
if (this.ownFields.size) {
|
|
60
|
+
out.fields = {};
|
|
61
|
+
for (const [k, prop] of this.ownFields) {
|
|
62
|
+
out.fields[k] = (0, clone_object_util_js_1.cloneObject)(prop);
|
|
63
|
+
delete out.fields[k].name;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
toString() {
|
|
69
|
+
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
70
|
+
}
|
|
71
|
+
[inspect_util_js_1.nodeInspectCustom]() {
|
|
72
|
+
return `[${inspect_util_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + inspect_util_js_1.colorReset}` +
|
|
73
|
+
` ${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
74
|
+
}
|
|
75
|
+
init() {
|
|
76
|
+
if (this._initialized)
|
|
77
|
+
return;
|
|
78
|
+
this._initialized = true;
|
|
79
|
+
const metadata = this._metadata;
|
|
80
|
+
if (metadata.extends) {
|
|
81
|
+
for (const ext of metadata.extends) {
|
|
82
|
+
const baseType = this.document.types.get(ext.type);
|
|
83
|
+
if (!baseType)
|
|
84
|
+
throw new TypeError(`Extending schema (${ext.type}) of data type "${this.name}" does not exists`);
|
|
85
|
+
if (!(baseType instanceof ComplexType))
|
|
86
|
+
throw new TypeError(`Cannot extend ${this.name} from a "${baseType.kind}"`);
|
|
87
|
+
baseType.init();
|
|
88
|
+
if (baseType.additionalFields)
|
|
89
|
+
this._mixinAdditionalFields = true;
|
|
90
|
+
for (const [k, prop] of baseType.fields) {
|
|
91
|
+
const f = (0, clone_object_util_js_1.cloneObject)(prop);
|
|
92
|
+
f.name = k;
|
|
93
|
+
f.parent = this;
|
|
94
|
+
this.fields.set(k, f);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (metadata.fields) {
|
|
99
|
+
for (const [k, prop] of Object.entries(metadata.fields)) {
|
|
100
|
+
const t = this.document.types.get(prop.type);
|
|
101
|
+
if (!t)
|
|
102
|
+
throw new TypeError(`Type "${prop.type}" defined for "${this.name}.${k}" does not exists`);
|
|
103
|
+
const f = (0, clone_object_util_js_1.cloneObject)(prop);
|
|
104
|
+
f.name = k;
|
|
105
|
+
this.fields.set(k, f);
|
|
106
|
+
this.ownFields.set(k, f);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.ComplexType = ComplexType;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataType = void 0;
|
|
4
|
+
const clone_object_util_js_1 = require("../../utils/clone-object.util.js");
|
|
5
|
+
class DataType {
|
|
6
|
+
_document;
|
|
7
|
+
_metadata;
|
|
8
|
+
_name;
|
|
9
|
+
constructor(document, name, metadata) {
|
|
10
|
+
this._document = document;
|
|
11
|
+
this._name = name;
|
|
12
|
+
this._metadata = metadata;
|
|
13
|
+
}
|
|
14
|
+
get document() {
|
|
15
|
+
return this._document;
|
|
16
|
+
}
|
|
17
|
+
get kind() {
|
|
18
|
+
return this._metadata.kind;
|
|
19
|
+
}
|
|
20
|
+
get name() {
|
|
21
|
+
return this._name;
|
|
22
|
+
}
|
|
23
|
+
get description() {
|
|
24
|
+
return this._metadata.description;
|
|
25
|
+
}
|
|
26
|
+
get ctor() {
|
|
27
|
+
return this._metadata.ctor;
|
|
28
|
+
}
|
|
29
|
+
parse(value) {
|
|
30
|
+
return this._metadata.parse ? this._metadata.parse(value) : value;
|
|
31
|
+
}
|
|
32
|
+
getSchema(jsonOnly) {
|
|
33
|
+
return (0, clone_object_util_js_1.cloneObject)(this._metadata, jsonOnly);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DataType = DataType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleType = void 0;
|
|
4
|
+
const inspect_util_js_1 = require("../../utils/inspect.util.js");
|
|
5
|
+
const data_type_js_1 = require("./data-type.js");
|
|
6
|
+
class SimpleType extends data_type_js_1.DataType {
|
|
7
|
+
constructor(owner, name, args) {
|
|
8
|
+
super(owner, name, {
|
|
9
|
+
kind: 'SimpleType',
|
|
10
|
+
...args
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
15
|
+
}
|
|
16
|
+
[inspect_util_js_1.nodeInspectCustom]() {
|
|
17
|
+
return `[${inspect_util_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + inspect_util_js_1.colorReset}` +
|
|
18
|
+
` ${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.SimpleType = SimpleType;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionType = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const inspect_util_js_1 = require("../../utils/inspect.util.js");
|
|
6
|
+
const complex_type_js_1 = require("./complex-type.js");
|
|
7
|
+
const data_type_js_1 = require("./data-type.js");
|
|
8
|
+
class UnionType extends data_type_js_1.DataType {
|
|
9
|
+
types;
|
|
10
|
+
hasAdditionalFields;
|
|
11
|
+
constructor(owner, name, args) {
|
|
12
|
+
super(owner, name, (0, lodash_1.omit)({ kind: 'UnionType', ...args }, ['types']));
|
|
13
|
+
this.types = args.types;
|
|
14
|
+
this.hasAdditionalFields = name === 'any' ||
|
|
15
|
+
!!this.types.find(t => t instanceof complex_type_js_1.ComplexType && t.additionalFields);
|
|
16
|
+
}
|
|
17
|
+
toString() {
|
|
18
|
+
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
19
|
+
}
|
|
20
|
+
[inspect_util_js_1.nodeInspectCustom]() {
|
|
21
|
+
return `[${inspect_util_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + inspect_util_js_1.colorReset}` +
|
|
22
|
+
` ${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.UnionType = UnionType;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentBuilder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const putil_promisify_1 = require("putil-promisify");
|
|
6
|
+
const Optionals = tslib_1.__importStar(require("@opra/optionals"));
|
|
7
|
+
const responsive_map_js_1 = require("../../helpers/responsive-map.js");
|
|
8
|
+
const opra_schema_definition_js_1 = require("../opra-schema.definition.js");
|
|
9
|
+
const class_utils_js_1 = require("../utils/class.utils.js");
|
|
10
|
+
const builtin_data_types_js_1 = require("./data-type/builtin-data-types.js");
|
|
11
|
+
const extract_resource_metadata_util_js_1 = require("./schema-builder/extract-resource-metadata.util.js");
|
|
12
|
+
const extract_type_metadata_util_js_1 = require("./schema-builder/extract-type-metadata.util.js");
|
|
13
|
+
class DocumentBuilder {
|
|
14
|
+
_args;
|
|
15
|
+
_dataTypes = new responsive_map_js_1.ResponsiveMap();
|
|
16
|
+
_resources = new responsive_map_js_1.ResponsiveMap();
|
|
17
|
+
constructor(args) {
|
|
18
|
+
this._args = args;
|
|
19
|
+
}
|
|
20
|
+
buildSchema() {
|
|
21
|
+
const out = {
|
|
22
|
+
...this._args,
|
|
23
|
+
version: opra_schema_definition_js_1.OpraSchema.Version,
|
|
24
|
+
};
|
|
25
|
+
if (this._dataTypes.size)
|
|
26
|
+
out.types = Array.from(this._dataTypes.keys()).sort()
|
|
27
|
+
.reduce((target, name) => {
|
|
28
|
+
target[name] = this._dataTypes.get(name);
|
|
29
|
+
return target;
|
|
30
|
+
}, {});
|
|
31
|
+
if (this._resources.size)
|
|
32
|
+
out.resources = Array.from(this._resources.keys()).sort()
|
|
33
|
+
.reduce((target, name) => {
|
|
34
|
+
target[name] = this._resources.get(name);
|
|
35
|
+
return target;
|
|
36
|
+
}, {});
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
async addDataTypeSchema(name, schema) {
|
|
40
|
+
if (!opra_schema_definition_js_1.OpraSchema.isDataType(schema))
|
|
41
|
+
throw new TypeError(`Invalid DataType schema`);
|
|
42
|
+
const currentSchema = this._dataTypes.get(name);
|
|
43
|
+
if (currentSchema) {
|
|
44
|
+
if (!(currentSchema.kind === schema.kind && currentSchema.ctor && currentSchema.ctor === schema.ctor))
|
|
45
|
+
throw new Error(`An other instance of "${name}" data type previously defined`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this._dataTypes.set(name, schema);
|
|
49
|
+
if (opra_schema_definition_js_1.OpraSchema.isComplexType(schema)) {
|
|
50
|
+
if (schema.extends) {
|
|
51
|
+
for (const imp of schema.extends) {
|
|
52
|
+
// noinspection SuspiciousTypeOfGuard
|
|
53
|
+
if (typeof imp.type !== 'string') {
|
|
54
|
+
imp.type = await this.addDataTypeClass(imp.type);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (schema.fields) {
|
|
59
|
+
for (const field of Object.values(schema.fields)) {
|
|
60
|
+
field.type = field.type || 'string';
|
|
61
|
+
// noinspection SuspiciousTypeOfGuard
|
|
62
|
+
if (typeof field.type !== 'string') {
|
|
63
|
+
field.type = await this.addDataTypeClass(field.type);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async addDataTypeClass(thunk) {
|
|
70
|
+
thunk = (0, putil_promisify_1.isPromise)(thunk) ? await thunk : thunk;
|
|
71
|
+
if (!(0, class_utils_js_1.isConstructor)(thunk))
|
|
72
|
+
return this.addDataTypeClass(thunk());
|
|
73
|
+
const internalTypeName = builtin_data_types_js_1.primitiveClasses.get(thunk);
|
|
74
|
+
if (internalTypeName)
|
|
75
|
+
return internalTypeName;
|
|
76
|
+
const namedSchema = await (0, extract_type_metadata_util_js_1.extractDataTypeSchema)(thunk);
|
|
77
|
+
const name = namedSchema.name;
|
|
78
|
+
const schema = namedSchema;
|
|
79
|
+
delete schema.name;
|
|
80
|
+
await this.addDataTypeSchema(name, schema);
|
|
81
|
+
return name;
|
|
82
|
+
}
|
|
83
|
+
async addResourceSchema(name, schema) {
|
|
84
|
+
if (!opra_schema_definition_js_1.OpraSchema.isResource(schema))
|
|
85
|
+
throw new TypeError(`Invalid Resource schema`);
|
|
86
|
+
if (this._resources.has(name))
|
|
87
|
+
throw new Error(`An other instance of "${name}" resource previously defined`);
|
|
88
|
+
if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema) || opra_schema_definition_js_1.OpraSchema.isSingletonResource(schema)) {
|
|
89
|
+
const type = typeof schema.type === 'function'
|
|
90
|
+
? await this.addDataTypeClass(schema.type)
|
|
91
|
+
: schema.type;
|
|
92
|
+
schema.type = type;
|
|
93
|
+
if (!(this._dataTypes.has(schema.type) || builtin_data_types_js_1.builtInTypes.has(schema.type)))
|
|
94
|
+
throw new Error(`Resource registration error. Type "${schema.type}" not found.`);
|
|
95
|
+
}
|
|
96
|
+
if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema)) {
|
|
97
|
+
// Determine keyFields if not set
|
|
98
|
+
if (!schema.keyFields) {
|
|
99
|
+
const dataType = this._dataTypes.get(schema.type);
|
|
100
|
+
if (Optionals.SqbConnect && dataType?.ctor) {
|
|
101
|
+
const sqbEntity = Optionals.SqbConnect.EntityMetadata.get(dataType?.ctor);
|
|
102
|
+
if (sqbEntity?.indexes) {
|
|
103
|
+
const primaryIndex = sqbEntity.indexes.find(x => x.primary);
|
|
104
|
+
if (primaryIndex) {
|
|
105
|
+
schema.keyFields = primaryIndex.columns;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
schema.keyFields = Array.isArray(schema.keyFields)
|
|
110
|
+
? (schema.keyFields.length ? schema.keyFields : '')
|
|
111
|
+
: schema.keyFields;
|
|
112
|
+
if (!schema.keyFields)
|
|
113
|
+
throw new TypeError(`You must provide keyFields for "${name}" entity resource`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
this._resources.set(name, schema);
|
|
117
|
+
}
|
|
118
|
+
async addResourceInstance(thunk) {
|
|
119
|
+
thunk = (0, putil_promisify_1.isPromise)(thunk) ? await thunk : thunk;
|
|
120
|
+
let instance;
|
|
121
|
+
if (typeof thunk === 'function') {
|
|
122
|
+
if ((0, class_utils_js_1.isConstructor)(thunk)) {
|
|
123
|
+
instance = {};
|
|
124
|
+
Object.setPrototypeOf(instance, thunk.prototype);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
instance = await thunk();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
instance = thunk;
|
|
132
|
+
const namedSchema = await (0, extract_resource_metadata_util_js_1.extractResourceSchema)(instance);
|
|
133
|
+
const name = namedSchema.name;
|
|
134
|
+
const schema = namedSchema;
|
|
135
|
+
delete schema.name;
|
|
136
|
+
await this.addResourceSchema(name, schema);
|
|
137
|
+
return name;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.DocumentBuilder = DocumentBuilder;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpraDocument = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const responsive_map_js_1 = require("../../helpers/responsive-map.js");
|
|
6
|
+
const opra_schema_definition_js_1 = require("../opra-schema.definition.js");
|
|
7
|
+
const clone_object_util_js_1 = require("../utils/clone-object.util.js");
|
|
8
|
+
const string_compare_util_js_1 = require("../utils/string-compare.util.js");
|
|
9
|
+
const builtin_data_types_js_1 = require("./data-type/builtin-data-types.js");
|
|
10
|
+
const complex_type_js_1 = require("./data-type/complex-type.js");
|
|
11
|
+
const simple_type_js_1 = require("./data-type/simple-type.js");
|
|
12
|
+
const union_type_js_1 = require("./data-type/union-type.js");
|
|
13
|
+
const document_builder_js_1 = require("./document-builder.js");
|
|
14
|
+
const collection_resource_info_js_1 = require("./resource/collection-resource-info.js");
|
|
15
|
+
const singleton_resource_info_js_1 = require("./resource/singleton-resource-info.js");
|
|
16
|
+
class OpraDocument {
|
|
17
|
+
_ownTypes = new responsive_map_js_1.ResponsiveMap();
|
|
18
|
+
_types = new responsive_map_js_1.ResponsiveMap();
|
|
19
|
+
_resources = new responsive_map_js_1.ResponsiveMap();
|
|
20
|
+
constructor(schema) {
|
|
21
|
+
this._meta = (0, lodash_1.omit)(schema, ['types', 'resources']);
|
|
22
|
+
for (const [name, t] of builtin_data_types_js_1.builtInTypes.entries()) {
|
|
23
|
+
this._addDataType(name, t, false);
|
|
24
|
+
}
|
|
25
|
+
if (schema.types)
|
|
26
|
+
for (const [name, t] of Object.entries(schema.types)) {
|
|
27
|
+
this._addDataType(name, t, true);
|
|
28
|
+
}
|
|
29
|
+
this._initTypes();
|
|
30
|
+
if (schema.resources)
|
|
31
|
+
for (const [name, t] of Object.entries(schema.resources)) {
|
|
32
|
+
this._addResource(name, t);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get info() {
|
|
36
|
+
return this._meta.info;
|
|
37
|
+
}
|
|
38
|
+
get types() {
|
|
39
|
+
return this._types;
|
|
40
|
+
}
|
|
41
|
+
getDataType(name) {
|
|
42
|
+
const t = this.types.get(name);
|
|
43
|
+
if (t)
|
|
44
|
+
return t;
|
|
45
|
+
throw new Error(`Data type "${name}" does not exists`);
|
|
46
|
+
}
|
|
47
|
+
getComplexDataType(name) {
|
|
48
|
+
const t = this.getDataType(name);
|
|
49
|
+
if (t && t instanceof complex_type_js_1.ComplexType)
|
|
50
|
+
return t;
|
|
51
|
+
throw new Error(`Data type "${name}" is not a ComplexType`);
|
|
52
|
+
}
|
|
53
|
+
getSimpleDataType(name) {
|
|
54
|
+
const t = this.getDataType(name);
|
|
55
|
+
if (t && t instanceof simple_type_js_1.SimpleType)
|
|
56
|
+
return t;
|
|
57
|
+
throw new Error(`Data type "${name}" is not a SimpleType`);
|
|
58
|
+
}
|
|
59
|
+
getUnionDataType(name) {
|
|
60
|
+
const t = this.getDataType(name);
|
|
61
|
+
if (t && t instanceof union_type_js_1.UnionType)
|
|
62
|
+
return t;
|
|
63
|
+
throw new Error(`Data type "${name}" is not a UnionType`);
|
|
64
|
+
}
|
|
65
|
+
get resources() {
|
|
66
|
+
return this._resources;
|
|
67
|
+
}
|
|
68
|
+
get servers() {
|
|
69
|
+
return this._meta.servers;
|
|
70
|
+
}
|
|
71
|
+
getResource(name) {
|
|
72
|
+
const t = this.resources.get(name);
|
|
73
|
+
if (!t)
|
|
74
|
+
throw new Error(`Resource "${name}" does not exists`);
|
|
75
|
+
return t;
|
|
76
|
+
}
|
|
77
|
+
getCollectionResource(name) {
|
|
78
|
+
const t = this.getResource(name);
|
|
79
|
+
if (!(t instanceof collection_resource_info_js_1.CollectionResourceInfo))
|
|
80
|
+
throw new Error(`"${name}" is not a CollectionResource`);
|
|
81
|
+
return t;
|
|
82
|
+
}
|
|
83
|
+
getSingletonResource(name) {
|
|
84
|
+
const t = this.getResource(name);
|
|
85
|
+
if (!(t instanceof singleton_resource_info_js_1.SingletonResourceInfo))
|
|
86
|
+
throw new Error(`"${name}" is not a SingletonResource`);
|
|
87
|
+
return t;
|
|
88
|
+
}
|
|
89
|
+
getMetadata(jsonOnly) {
|
|
90
|
+
const out = {
|
|
91
|
+
version: opra_schema_definition_js_1.OpraSchema.Version,
|
|
92
|
+
info: (0, clone_object_util_js_1.cloneObject)(this.info),
|
|
93
|
+
};
|
|
94
|
+
if (this._ownTypes.size) {
|
|
95
|
+
out.types = Array.from(this._ownTypes.values())
|
|
96
|
+
.sort((a, b) => (0, string_compare_util_js_1.stringCompare)(a.name, b.name))
|
|
97
|
+
.reduce((target, t) => {
|
|
98
|
+
target[t.name] = t.getSchema(jsonOnly);
|
|
99
|
+
return target;
|
|
100
|
+
}, {});
|
|
101
|
+
}
|
|
102
|
+
if (this.resources.size) {
|
|
103
|
+
out.resources = Array.from(this._resources.values())
|
|
104
|
+
.sort((a, b) => (0, string_compare_util_js_1.stringCompare)(a.name, b.name))
|
|
105
|
+
.reduce((target, t) => {
|
|
106
|
+
target[t.name] = t.getSchema(jsonOnly);
|
|
107
|
+
return target;
|
|
108
|
+
}, {});
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
_addDataType(name, schema, isOwn) {
|
|
113
|
+
let dataType = this._types.get(name);
|
|
114
|
+
if (dataType)
|
|
115
|
+
return dataType;
|
|
116
|
+
if (opra_schema_definition_js_1.OpraSchema.isComplexType(schema)) {
|
|
117
|
+
dataType = new complex_type_js_1.ComplexType(this, name, schema);
|
|
118
|
+
}
|
|
119
|
+
else if (opra_schema_definition_js_1.OpraSchema.isSimpleType(schema)) {
|
|
120
|
+
dataType = new simple_type_js_1.SimpleType(this, name, schema);
|
|
121
|
+
}
|
|
122
|
+
else if (opra_schema_definition_js_1.OpraSchema.isUnionTypee(schema)) {
|
|
123
|
+
// todo build types array
|
|
124
|
+
dataType = new union_type_js_1.UnionType(this, name, { ...schema, types: [] });
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
throw new TypeError(`Invalid data type schema`);
|
|
128
|
+
this._types.set(name, dataType);
|
|
129
|
+
if (isOwn)
|
|
130
|
+
this._ownTypes.set(name, dataType);
|
|
131
|
+
return dataType;
|
|
132
|
+
}
|
|
133
|
+
_addResource(name, schema) {
|
|
134
|
+
if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema) || opra_schema_definition_js_1.OpraSchema.isSingletonResource(schema)) {
|
|
135
|
+
const dataType = this.getDataType(schema.type);
|
|
136
|
+
if (!dataType)
|
|
137
|
+
throw new TypeError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
|
|
138
|
+
if (!(dataType instanceof complex_type_js_1.ComplexType))
|
|
139
|
+
throw new TypeError(`${schema.type} is not an ComplexType`);
|
|
140
|
+
if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema))
|
|
141
|
+
this.resources.set(name, new collection_resource_info_js_1.CollectionResourceInfo(this, name, dataType, schema));
|
|
142
|
+
else
|
|
143
|
+
this.resources.set(name, new singleton_resource_info_js_1.SingletonResourceInfo(this, name, dataType, schema));
|
|
144
|
+
}
|
|
145
|
+
else
|
|
146
|
+
throw new TypeError(`Unknown resource kind (${schema.kind})`);
|
|
147
|
+
}
|
|
148
|
+
_initTypes() {
|
|
149
|
+
for (const dataType of this._types.values()) {
|
|
150
|
+
if (dataType instanceof complex_type_js_1.ComplexType) {
|
|
151
|
+
dataType.init();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
static async create(args) {
|
|
156
|
+
const builder = new document_builder_js_1.DocumentBuilder(args);
|
|
157
|
+
if (args.types) {
|
|
158
|
+
if (Array.isArray(args.types)) {
|
|
159
|
+
for (const t of args.types)
|
|
160
|
+
await builder.addDataTypeClass(t);
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
for (const [k, v] of Object.entries(args.types)) {
|
|
164
|
+
await builder.addDataTypeSchema(k, v);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (args.resources) {
|
|
168
|
+
if (Array.isArray(args.resources)) {
|
|
169
|
+
for (const t of args.resources)
|
|
170
|
+
await builder.addResourceInstance(t);
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
for (const [k, v] of Object.entries(args.resources)) {
|
|
174
|
+
await builder.addResourceSchema(k, v);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const schema = builder.buildSchema();
|
|
178
|
+
return new OpraDocument(schema);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.OpraDocument = OpraDocument;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionCountQuery = void 0;
|
|
4
|
+
const index_js_1 = require("../../../filter/index.js");
|
|
5
|
+
class CollectionCountQuery {
|
|
6
|
+
resource;
|
|
7
|
+
kind = 'CollectionCountQuery';
|
|
8
|
+
method = 'count';
|
|
9
|
+
operation = 'read';
|
|
10
|
+
filter;
|
|
11
|
+
constructor(resource, options) {
|
|
12
|
+
this.resource = resource;
|
|
13
|
+
this.filter = typeof options?.filter === 'string' ? (0, index_js_1.parseFilter)(options.filter) : options?.filter;
|
|
14
|
+
}
|
|
15
|
+
get dataType() {
|
|
16
|
+
return this.resource.dataType;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CollectionCountQuery = CollectionCountQuery;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionCreateQuery = void 0;
|
|
4
|
+
const normalize_field_array_util_js_1 = require("../../utils/normalize-field-array.util.js");
|
|
5
|
+
class CollectionCreateQuery {
|
|
6
|
+
resource;
|
|
7
|
+
data;
|
|
8
|
+
kind = 'CollectionCreateQuery';
|
|
9
|
+
method = 'create';
|
|
10
|
+
operation = 'create';
|
|
11
|
+
pick;
|
|
12
|
+
omit;
|
|
13
|
+
include;
|
|
14
|
+
constructor(resource, data, options) {
|
|
15
|
+
this.resource = resource;
|
|
16
|
+
this.data = data;
|
|
17
|
+
if (options?.pick)
|
|
18
|
+
this.pick = (0, normalize_field_array_util_js_1.normalizeFieldArray)(resource.document, resource.dataType, options.pick);
|
|
19
|
+
if (options?.omit)
|
|
20
|
+
this.omit = (0, normalize_field_array_util_js_1.normalizeFieldArray)(resource.document, resource.dataType, options.omit);
|
|
21
|
+
if (options?.include)
|
|
22
|
+
this.include = (0, normalize_field_array_util_js_1.normalizeFieldArray)(resource.document, resource.dataType, options.include);
|
|
23
|
+
}
|
|
24
|
+
get dataType() {
|
|
25
|
+
return this.resource.dataType;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CollectionCreateQuery = CollectionCreateQuery;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionDeleteManyQuery = void 0;
|
|
4
|
+
const index_js_1 = require("../../../filter/index.js");
|
|
5
|
+
class CollectionDeleteManyQuery {
|
|
6
|
+
resource;
|
|
7
|
+
kind = 'CollectionDeleteManyQuery';
|
|
8
|
+
method = 'deleteMany';
|
|
9
|
+
operation = 'delete';
|
|
10
|
+
filter;
|
|
11
|
+
constructor(resource, options) {
|
|
12
|
+
this.resource = resource;
|
|
13
|
+
this.filter = typeof options?.filter === 'string' ? (0, index_js_1.parseFilter)(options.filter) : options?.filter;
|
|
14
|
+
}
|
|
15
|
+
get dataType() {
|
|
16
|
+
return this.resource.dataType;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CollectionDeleteManyQuery = CollectionDeleteManyQuery;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionDeleteQuery = void 0;
|
|
4
|
+
class CollectionDeleteQuery {
|
|
5
|
+
resource;
|
|
6
|
+
kind = 'CollectionDeleteQuery';
|
|
7
|
+
method = 'delete';
|
|
8
|
+
operation = 'delete';
|
|
9
|
+
keyValue;
|
|
10
|
+
constructor(resource, keyValue) {
|
|
11
|
+
this.resource = resource;
|
|
12
|
+
if (resource.keyFields.length > 1) {
|
|
13
|
+
if (typeof keyValue !== 'object')
|
|
14
|
+
throw new Error(`You must provide an key/value object for all key fields (${resource.keyFields})`);
|
|
15
|
+
resource.keyFields.reduce((o, k) => {
|
|
16
|
+
o[k] = keyValue[k];
|
|
17
|
+
return o;
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
this.keyValue = resource.dataType.getFieldType(resource.keyFields[0]).parse(keyValue);
|
|
22
|
+
}
|
|
23
|
+
get dataType() {
|
|
24
|
+
return this.resource.dataType;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.CollectionDeleteQuery = CollectionDeleteQuery;
|