@loopback/repository 4.0.0-alpha.8 → 4.1.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/LICENSE +25 -0
- package/README.md +93 -389
- package/dist/common-types.d.ts +96 -0
- package/dist/common-types.js +24 -0
- package/dist/common-types.js.map +1 -0
- package/dist/connectors/connector.d.ts +48 -0
- package/{lib → dist/connectors}/connector.js +1 -1
- package/dist/connectors/connector.js.map +1 -0
- package/{lib/crud-connector.d.ts → dist/connectors/crud.connector.d.ts} +51 -51
- package/{lib/common-types.js → dist/connectors/crud.connector.js} +2 -2
- package/dist/connectors/crud.connector.js.map +1 -0
- package/dist/connectors/index.d.ts +3 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/index.js.map +1 -0
- package/{lib6/kv-connector.d.ts → dist/connectors/kv.connector.d.ts} +28 -28
- package/{lib/datasource.js → dist/connectors/kv.connector.js} +2 -2
- package/dist/connectors/kv.connector.js.map +1 -0
- package/dist/datasource.d.ts +27 -0
- package/{lib6 → dist}/datasource.js +1 -1
- package/dist/datasource.js.map +1 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.js +11 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/metadata.d.ts +12 -0
- package/dist/decorators/metadata.js +51 -0
- package/dist/decorators/metadata.js.map +1 -0
- package/dist/decorators/model.decorator.d.ts +40 -0
- package/dist/decorators/model.decorator.js +112 -0
- package/dist/decorators/model.decorator.js.map +1 -0
- package/dist/decorators/repository.decorator.d.ts +106 -0
- package/dist/decorators/repository.decorator.js +114 -0
- package/dist/decorators/repository.decorator.js.map +1 -0
- package/dist/define-model-class.d.ts +55 -0
- package/dist/define-model-class.js +57 -0
- package/dist/define-model-class.js.map +1 -0
- package/dist/define-repository-class.d.ts +119 -0
- package/dist/define-repository-class.js +98 -0
- package/dist/define-repository-class.js.map +1 -0
- package/dist/errors/entity-not-found.error.d.ts +8 -0
- package/dist/errors/entity-not-found.error.js +28 -0
- package/dist/errors/entity-not-found.error.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +10 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/invalid-relation.error.d.ts +10 -0
- package/dist/errors/invalid-relation.error.js +28 -0
- package/dist/errors/invalid-relation.error.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +34 -0
- package/dist/keys.js +44 -0
- package/dist/keys.js.map +1 -0
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +9 -0
- package/dist/mixins/index.js.map +1 -0
- package/dist/mixins/repository.mixin.d.ts +377 -0
- package/dist/mixins/repository.mixin.js +405 -0
- package/dist/mixins/repository.mixin.js.map +1 -0
- package/dist/model.d.ts +232 -0
- package/dist/model.js +367 -0
- package/dist/model.js.map +1 -0
- package/dist/relations/belongs-to/belongs-to.accessor.d.ts +17 -0
- package/dist/relations/belongs-to/belongs-to.accessor.js +40 -0
- package/dist/relations/belongs-to/belongs-to.accessor.js.map +1 -0
- package/dist/relations/belongs-to/belongs-to.decorator.d.ts +11 -0
- package/dist/relations/belongs-to/belongs-to.decorator.js +64 -0
- package/dist/relations/belongs-to/belongs-to.decorator.js.map +1 -0
- package/dist/relations/belongs-to/belongs-to.helpers.d.ts +17 -0
- package/dist/relations/belongs-to/belongs-to.helpers.js +63 -0
- package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -0
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.d.ts +14 -0
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +36 -0
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -0
- package/dist/relations/belongs-to/belongs-to.repository.d.ts +28 -0
- package/dist/relations/belongs-to/belongs-to.repository.js +33 -0
- package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -0
- package/dist/relations/belongs-to/index.d.ts +4 -0
- package/dist/relations/belongs-to/index.js +12 -0
- package/dist/relations/belongs-to/index.js.map +1 -0
- package/dist/relations/has-many/has-many-through.helpers.d.ts +182 -0
- package/dist/relations/has-many/has-many-through.helpers.js +282 -0
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -0
- package/dist/relations/has-many/has-many-through.inclusion-resolver.d.ts +16 -0
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js +78 -0
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js.map +1 -0
- package/dist/relations/has-many/has-many-through.repository-factory.d.ts +17 -0
- package/dist/relations/has-many/has-many-through.repository-factory.js +37 -0
- package/dist/relations/has-many/has-many-through.repository-factory.js.map +1 -0
- package/dist/relations/has-many/has-many-through.repository.d.ts +114 -0
- package/dist/relations/has-many/has-many-through.repository.js +103 -0
- package/dist/relations/has-many/has-many-through.repository.js.map +1 -0
- package/dist/relations/has-many/has-many.decorator.d.ts +11 -0
- package/dist/relations/has-many/has-many.decorator.js +36 -0
- package/dist/relations/has-many/has-many.decorator.js.map +1 -0
- package/dist/relations/has-many/has-many.helpers.d.ts +26 -0
- package/dist/relations/has-many/has-many.helpers.js +78 -0
- package/dist/relations/has-many/has-many.helpers.js.map +1 -0
- package/dist/relations/has-many/has-many.inclusion-resolver.d.ts +14 -0
- package/dist/relations/has-many/has-many.inclusion-resolver.js +45 -0
- package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -0
- package/dist/relations/has-many/has-many.repository-factory.d.ts +28 -0
- package/dist/relations/has-many/has-many.repository-factory.js +39 -0
- package/dist/relations/has-many/has-many.repository-factory.js.map +1 -0
- package/dist/relations/has-many/has-many.repository.d.ts +54 -0
- package/dist/relations/has-many/has-many.repository.js +38 -0
- package/dist/relations/has-many/has-many.repository.js.map +1 -0
- package/dist/relations/has-many/index.d.ts +6 -0
- package/dist/relations/has-many/index.js +14 -0
- package/dist/relations/has-many/index.js.map +1 -0
- package/dist/relations/has-one/has-one.decorator.d.ts +3 -0
- package/dist/relations/has-one/has-one.decorator.js +37 -0
- package/dist/relations/has-one/has-one.decorator.js.map +1 -0
- package/dist/relations/has-one/has-one.helpers.d.ts +17 -0
- package/dist/relations/has-one/has-one.helpers.js +64 -0
- package/dist/relations/has-one/has-one.helpers.js.map +1 -0
- package/dist/relations/has-one/has-one.inclusion-resolver.d.ts +14 -0
- package/dist/relations/has-one/has-one.inclusion-resolver.js +35 -0
- package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -0
- package/dist/relations/has-one/has-one.repository-factory.d.ts +28 -0
- package/dist/relations/has-one/has-one.repository-factory.js +39 -0
- package/dist/relations/has-one/has-one.repository-factory.js.map +1 -0
- package/dist/relations/has-one/has-one.repository.d.ts +53 -0
- package/dist/relations/has-one/has-one.repository.js +45 -0
- package/dist/relations/has-one/has-one.repository.js.map +1 -0
- package/dist/relations/has-one/index.d.ts +3 -0
- package/dist/relations/has-one/index.js +11 -0
- package/dist/relations/has-one/index.js.map +1 -0
- package/dist/relations/index.d.ts +6 -0
- package/dist/relations/index.js +14 -0
- package/dist/relations/index.js.map +1 -0
- package/dist/relations/relation.decorator.d.ts +39 -0
- package/dist/relations/relation.decorator.js +88 -0
- package/dist/relations/relation.decorator.js.map +1 -0
- package/dist/relations/relation.helpers.d.ts +105 -0
- package/dist/relations/relation.helpers.js +304 -0
- package/dist/relations/relation.helpers.js.map +1 -0
- package/dist/relations/relation.types.d.ts +142 -0
- package/dist/relations/relation.types.js +21 -0
- package/dist/relations/relation.types.js.map +1 -0
- package/dist/repositories/constraint-utils.d.ts +49 -0
- package/dist/repositories/constraint-utils.js +87 -0
- package/dist/repositories/constraint-utils.js.map +1 -0
- package/dist/repositories/index.d.ts +5 -0
- package/dist/repositories/index.js +13 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/kv.repository.bridge.d.ts +30 -0
- package/dist/repositories/kv.repository.bridge.js +76 -0
- package/dist/repositories/kv.repository.bridge.js.map +1 -0
- package/dist/repositories/kv.repository.d.ts +74 -0
- package/{lib/crud-connector.js → dist/repositories/kv.repository.js} +2 -2
- package/dist/repositories/kv.repository.js.map +1 -0
- package/dist/repositories/legacy-juggler-bridge.d.ts +305 -0
- package/dist/repositories/legacy-juggler-bridge.js +452 -0
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -0
- package/dist/repositories/repository.d.ts +223 -0
- package/dist/repositories/repository.js +157 -0
- package/dist/repositories/repository.js.map +1 -0
- package/dist/transaction.d.ts +30 -0
- package/dist/transaction.js +18 -0
- package/dist/transaction.js.map +1 -0
- package/dist/type-resolver.d.ts +42 -0
- package/dist/type-resolver.js +61 -0
- package/dist/type-resolver.js.map +1 -0
- package/{lib → dist}/types/any.d.ts +1 -1
- package/{lib6 → dist}/types/any.js +3 -2
- package/dist/types/any.js.map +1 -0
- package/{lib6 → dist}/types/array.d.ts +4 -4
- package/{lib → dist}/types/array.js +6 -4
- package/dist/types/array.js.map +1 -0
- package/{lib → dist}/types/boolean.d.ts +1 -1
- package/{lib6 → dist}/types/boolean.js +3 -2
- package/dist/types/boolean.js.map +1 -0
- package/{lib6 → dist}/types/buffer.d.ts +2 -2
- package/{lib → dist}/types/buffer.js +8 -6
- package/dist/types/buffer.js.map +1 -0
- package/{lib → dist}/types/date.d.ts +1 -1
- package/{lib → dist}/types/date.js +6 -4
- package/dist/types/date.js.map +1 -0
- package/{lib → dist}/types/index.d.ts +11 -9
- package/dist/types/index.js +49 -0
- package/dist/types/index.js.map +1 -0
- package/{lib6 → dist}/types/model.d.ts +2 -1
- package/{lib6 → dist}/types/model.js +2 -2
- package/dist/types/model.js.map +1 -0
- package/dist/types/null.d.ts +12 -0
- package/{lib/types/boolean.js → dist/types/null.js} +12 -11
- package/dist/types/null.js.map +1 -0
- package/{lib6 → dist}/types/number.d.ts +1 -1
- package/{lib → dist}/types/number.js +6 -4
- package/dist/types/number.js.map +1 -0
- package/{lib → dist}/types/object.d.ts +1 -1
- package/{lib → dist}/types/object.js +7 -6
- package/dist/types/object.js.map +1 -0
- package/{lib → dist}/types/string.d.ts +1 -1
- package/{lib → dist}/types/string.js +3 -2
- package/dist/types/string.js.map +1 -0
- package/{lib6 → dist}/types/type.d.ts +7 -7
- package/{lib6 → dist}/types/type.js +1 -1
- package/dist/types/type.js.map +1 -0
- package/{lib → dist}/types/union.d.ts +1 -1
- package/{lib → dist}/types/union.js +6 -4
- package/dist/types/union.js.map +1 -0
- package/package.json +49 -33
- package/src/common-types.ts +123 -0
- package/src/connectors/connector.ts +70 -0
- package/src/connectors/crud.connector.ts +208 -0
- package/src/connectors/index.ts +8 -0
- package/src/connectors/kv.connector.ts +113 -0
- package/src/datasource.ts +37 -0
- package/src/decorators/index.ts +8 -0
- package/src/decorators/metadata.ts +84 -0
- package/src/decorators/model.decorator.ts +166 -0
- package/src/decorators/repository.decorator.ts +223 -0
- package/src/define-model-class.ts +90 -0
- package/src/define-repository-class.ts +170 -0
- package/src/errors/entity-not-found.error.ts +40 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/invalid-relation.error.ts +39 -0
- package/src/index.ts +36 -0
- package/src/keys.ts +40 -0
- package/{index.d.ts → src/mixins/index.ts} +2 -2
- package/src/mixins/repository.mixin.ts +499 -0
- package/src/model.ts +539 -0
- package/src/relations/belongs-to/belongs-to.accessor.ts +74 -0
- package/src/relations/belongs-to/belongs-to.decorator.ts +81 -0
- package/src/relations/belongs-to/belongs-to.helpers.ts +78 -0
- package/src/relations/belongs-to/belongs-to.inclusion-resolver.ts +71 -0
- package/src/relations/belongs-to/belongs-to.repository.ts +55 -0
- package/src/relations/belongs-to/index.ts +9 -0
- package/src/relations/has-many/has-many-through.helpers.ts +361 -0
- package/src/relations/has-many/has-many-through.inclusion-resolver.ts +135 -0
- package/src/relations/has-many/has-many-through.repository-factory.ts +121 -0
- package/src/relations/has-many/has-many-through.repository.ts +318 -0
- package/src/relations/has-many/has-many.decorator.ts +38 -0
- package/src/relations/has-many/has-many.helpers.ts +100 -0
- package/src/relations/has-many/has-many.inclusion-resolver.ts +88 -0
- package/src/relations/has-many/has-many.repository-factory.ts +76 -0
- package/src/relations/has-many/has-many.repository.ts +118 -0
- package/src/relations/has-many/index.ts +11 -0
- package/src/relations/has-one/has-one.decorator.ts +40 -0
- package/src/relations/has-one/has-one.helpers.ts +84 -0
- package/src/relations/has-one/has-one.inclusion-resolver.ts +65 -0
- package/src/relations/has-one/has-one.repository-factory.ts +72 -0
- package/src/relations/has-one/has-one.repository.ts +127 -0
- package/src/relations/has-one/index.ts +8 -0
- package/src/relations/index.ts +11 -0
- package/src/relations/relation.decorator.ts +90 -0
- package/src/relations/relation.helpers.ts +373 -0
- package/src/relations/relation.types.ts +180 -0
- package/src/repositories/constraint-utils.ts +98 -0
- package/src/repositories/index.ts +10 -0
- package/src/repositories/kv.repository.bridge.ts +97 -0
- package/src/repositories/kv.repository.ts +87 -0
- package/src/repositories/legacy-juggler-bridge.ts +788 -0
- package/src/repositories/repository.ts +441 -0
- package/src/transaction.ts +39 -0
- package/src/type-resolver.ts +98 -0
- package/src/types/any.ts +38 -0
- package/src/types/array.ts +53 -0
- package/src/types/boolean.ts +35 -0
- package/src/types/buffer.ts +53 -0
- package/src/types/date.ts +61 -0
- package/src/types/index.ts +52 -0
- package/src/types/model.ts +24 -0
- package/src/types/null.ts +35 -0
- package/src/types/number.ts +42 -0
- package/src/types/object.ts +53 -0
- package/src/types/string.ts +42 -0
- package/src/types/type.ts +51 -0
- package/src/types/union.ts +55 -0
- package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-precomposed.png +0 -0
- package/api-docs/apple-touch-icon.png +0 -0
- package/api-docs/css/bootstrap.min.css +0 -9
- package/api-docs/css/code-themes/arta.css +0 -158
- package/api-docs/css/code-themes/ascetic.css +0 -50
- package/api-docs/css/code-themes/brown_paper.css +0 -104
- package/api-docs/css/code-themes/brown_papersq.png +0 -0
- package/api-docs/css/code-themes/dark.css +0 -103
- package/api-docs/css/code-themes/default.css +0 -135
- package/api-docs/css/code-themes/far.css +0 -111
- package/api-docs/css/code-themes/github.css +0 -127
- package/api-docs/css/code-themes/googlecode.css +0 -144
- package/api-docs/css/code-themes/idea.css +0 -121
- package/api-docs/css/code-themes/ir_black.css +0 -104
- package/api-docs/css/code-themes/magula.css +0 -121
- package/api-docs/css/code-themes/monokai.css +0 -114
- package/api-docs/css/code-themes/pojoaque.css +0 -104
- package/api-docs/css/code-themes/pojoaque.jpg +0 -0
- package/api-docs/css/code-themes/rainbow.css +0 -114
- package/api-docs/css/code-themes/school_book.css +0 -111
- package/api-docs/css/code-themes/school_book.png +0 -0
- package/api-docs/css/code-themes/sl-theme.css +0 -45
- package/api-docs/css/code-themes/solarized_dark.css +0 -88
- package/api-docs/css/code-themes/solarized_light.css +0 -88
- package/api-docs/css/code-themes/sunburst.css +0 -158
- package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
- package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night.css +0 -52
- package/api-docs/css/code-themes/tomorrow.css +0 -49
- package/api-docs/css/code-themes/vs.css +0 -86
- package/api-docs/css/code-themes/xcode.css +0 -154
- package/api-docs/css/code-themes/zenburn.css +0 -115
- package/api-docs/css/main.css +0 -139
- package/api-docs/favicon.ico +0 -0
- package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/index.html +0 -18017
- package/api-docs/js/main.js +0 -19
- package/api-docs/js/vendor/bootstrap.min.js +0 -6
- package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
- package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
- package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
- package/index.js +0 -9
- package/lib/common-types.d.ts +0 -44
- package/lib/common-types.js.map +0 -1
- package/lib/connector.d.ts +0 -12
- package/lib/connector.js.map +0 -1
- package/lib/crud-connector.js.map +0 -1
- package/lib/datasource.d.ts +0 -11
- package/lib/datasource.js.map +0 -1
- package/lib/decorators/model.d.ts +0 -17
- package/lib/decorators/model.js +0 -55
- package/lib/decorators/model.js.map +0 -1
- package/lib/decorators/relation.d.ts +0 -65
- package/lib/decorators/relation.js +0 -126
- package/lib/decorators/relation.js.map +0 -1
- package/lib/decorators/repository.d.ts +0 -61
- package/lib/decorators/repository.js +0 -107
- package/lib/decorators/repository.js.map +0 -1
- package/lib/index.d.ts +0 -17
- package/lib/index.js +0 -21
- package/lib/index.js.map +0 -1
- package/lib/kv-connector.d.ts +0 -77
- package/lib/kv-connector.js +0 -7
- package/lib/kv-connector.js.map +0 -1
- package/lib/kv-repository.d.ts +0 -78
- package/lib/kv-repository.js +0 -7
- package/lib/kv-repository.js.map +0 -1
- package/lib/legacy-juggler-bridge.d.ts +0 -53
- package/lib/legacy-juggler-bridge.js +0 -142
- package/lib/legacy-juggler-bridge.js.map +0 -1
- package/lib/loopback-datasource-juggler.d.ts +0 -666
- package/lib/loopback-datasource-juggler.js +0 -8
- package/lib/loopback-datasource-juggler.js.map +0 -1
- package/lib/mixin.d.ts +0 -43
- package/lib/mixin.js +0 -34
- package/lib/mixin.js.map +0 -1
- package/lib/model.d.ts +0 -137
- package/lib/model.js +0 -182
- package/lib/model.js.map +0 -1
- package/lib/query.d.ts +0 -112
- package/lib/query.js +0 -25
- package/lib/query.js.map +0 -1
- package/lib/repository-mixin.d.ts +0 -20
- package/lib/repository-mixin.js +0 -111
- package/lib/repository-mixin.js.map +0 -1
- package/lib/repository.d.ts +0 -172
- package/lib/repository.js +0 -127
- package/lib/repository.js.map +0 -1
- package/lib/types/any.js +0 -35
- package/lib/types/any.js.map +0 -1
- package/lib/types/array.d.ts +0 -14
- package/lib/types/array.js.map +0 -1
- package/lib/types/boolean.js.map +0 -1
- package/lib/types/buffer.d.ts +0 -14
- package/lib/types/buffer.js.map +0 -1
- package/lib/types/date.js.map +0 -1
- package/lib/types/index.js +0 -33
- package/lib/types/index.js.map +0 -1
- package/lib/types/model.d.ts +0 -11
- package/lib/types/model.js +0 -25
- package/lib/types/model.js.map +0 -1
- package/lib/types/number.d.ts +0 -12
- package/lib/types/number.js.map +0 -1
- package/lib/types/object.js.map +0 -1
- package/lib/types/string.js.map +0 -1
- package/lib/types/type.d.ts +0 -38
- package/lib/types/type.js +0 -7
- package/lib/types/type.js.map +0 -1
- package/lib/types/union.js.map +0 -1
- package/lib6/common-types.d.ts +0 -44
- package/lib6/common-types.js +0 -7
- package/lib6/common-types.js.map +0 -1
- package/lib6/connector.d.ts +0 -12
- package/lib6/connector.js +0 -7
- package/lib6/connector.js.map +0 -1
- package/lib6/crud-connector.d.ts +0 -130
- package/lib6/crud-connector.js +0 -7
- package/lib6/crud-connector.js.map +0 -1
- package/lib6/datasource.d.ts +0 -11
- package/lib6/datasource.js.map +0 -1
- package/lib6/decorators/model.d.ts +0 -17
- package/lib6/decorators/model.js +0 -55
- package/lib6/decorators/model.js.map +0 -1
- package/lib6/decorators/relation.d.ts +0 -65
- package/lib6/decorators/relation.js +0 -126
- package/lib6/decorators/relation.js.map +0 -1
- package/lib6/decorators/repository.d.ts +0 -61
- package/lib6/decorators/repository.js +0 -117
- package/lib6/decorators/repository.js.map +0 -1
- package/lib6/index.d.ts +0 -17
- package/lib6/index.js +0 -21
- package/lib6/index.js.map +0 -1
- package/lib6/kv-connector.js +0 -7
- package/lib6/kv-connector.js.map +0 -1
- package/lib6/kv-repository.d.ts +0 -78
- package/lib6/kv-repository.js +0 -7
- package/lib6/kv-repository.js.map +0 -1
- package/lib6/legacy-juggler-bridge.d.ts +0 -53
- package/lib6/legacy-juggler-bridge.js +0 -158
- package/lib6/legacy-juggler-bridge.js.map +0 -1
- package/lib6/loopback-datasource-juggler.d.ts +0 -666
- package/lib6/loopback-datasource-juggler.js +0 -8
- package/lib6/loopback-datasource-juggler.js.map +0 -1
- package/lib6/mixin.d.ts +0 -43
- package/lib6/mixin.js +0 -34
- package/lib6/mixin.js.map +0 -1
- package/lib6/model.d.ts +0 -137
- package/lib6/model.js +0 -182
- package/lib6/model.js.map +0 -1
- package/lib6/query.d.ts +0 -112
- package/lib6/query.js +0 -25
- package/lib6/query.js.map +0 -1
- package/lib6/repository-mixin.d.ts +0 -20
- package/lib6/repository-mixin.js +0 -111
- package/lib6/repository-mixin.js.map +0 -1
- package/lib6/repository.d.ts +0 -172
- package/lib6/repository.js +0 -127
- package/lib6/repository.js.map +0 -1
- package/lib6/types/any.d.ts +0 -12
- package/lib6/types/any.js.map +0 -1
- package/lib6/types/array.js +0 -53
- package/lib6/types/array.js.map +0 -1
- package/lib6/types/boolean.d.ts +0 -12
- package/lib6/types/boolean.js.map +0 -1
- package/lib6/types/buffer.js +0 -57
- package/lib6/types/buffer.js.map +0 -1
- package/lib6/types/date.d.ts +0 -12
- package/lib6/types/date.js +0 -60
- package/lib6/types/date.js.map +0 -1
- package/lib6/types/index.d.ts +0 -30
- package/lib6/types/index.js +0 -33
- package/lib6/types/index.js.map +0 -1
- package/lib6/types/model.js.map +0 -1
- package/lib6/types/number.js +0 -40
- package/lib6/types/number.js.map +0 -1
- package/lib6/types/object.d.ts +0 -15
- package/lib6/types/object.js +0 -49
- package/lib6/types/object.js.map +0 -1
- package/lib6/types/string.d.ts +0 -12
- package/lib6/types/string.js +0 -40
- package/lib6/types/string.js.map +0 -1
- package/lib6/types/type.js.map +0 -1
- package/lib6/types/union.d.ts +0 -14
- package/lib6/types/union.js +0 -51
- package/lib6/types/union.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.referencesMany = exports.referencesOne = exports.embedsMany = exports.embedsOne = exports.getModelRelations = exports.relation = exports.RELATIONS_KEY = void 0;
|
|
8
|
+
const core_1 = require("@loopback/core");
|
|
9
|
+
const decorators_1 = require("../decorators");
|
|
10
|
+
const relation_types_1 = require("./relation.types");
|
|
11
|
+
exports.RELATIONS_KEY = 'loopback:relations';
|
|
12
|
+
/**
|
|
13
|
+
* Decorator for relations
|
|
14
|
+
* @param definition
|
|
15
|
+
* @returns A property decorator
|
|
16
|
+
*/
|
|
17
|
+
function relation(definition) {
|
|
18
|
+
// Apply relation definition to the model class
|
|
19
|
+
return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, definition, {
|
|
20
|
+
decoratorName: '@relation',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.relation = relation;
|
|
24
|
+
/**
|
|
25
|
+
* Get metadata of all relations defined on a given model class.
|
|
26
|
+
*
|
|
27
|
+
* @param modelCtor - The model class (the constructor function).
|
|
28
|
+
* @returns A map of relation definitions
|
|
29
|
+
*/
|
|
30
|
+
function getModelRelations(modelCtor) {
|
|
31
|
+
// Build model definitions if `@model` is missing
|
|
32
|
+
const modelDef = (0, decorators_1.buildModelDefinition)(modelCtor);
|
|
33
|
+
return (modelDef === null || modelDef === void 0 ? void 0 : modelDef.relations) || {};
|
|
34
|
+
}
|
|
35
|
+
exports.getModelRelations = getModelRelations;
|
|
36
|
+
//
|
|
37
|
+
// placeholder decorators for relations that are not implemented yet
|
|
38
|
+
// TODO: move these decorators to per-relation subdirectories
|
|
39
|
+
//
|
|
40
|
+
/**
|
|
41
|
+
* Decorator for embedsOne
|
|
42
|
+
* @param definition
|
|
43
|
+
* @returns A property decorator
|
|
44
|
+
*/
|
|
45
|
+
function embedsOne(definition) {
|
|
46
|
+
const rel = Object.assign({ type: relation_types_1.RelationType.embedsOne }, definition);
|
|
47
|
+
return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
|
48
|
+
decoratorName: '@embedsOne',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.embedsOne = embedsOne;
|
|
52
|
+
/**
|
|
53
|
+
* Decorator for embedsMany
|
|
54
|
+
* @param definition
|
|
55
|
+
* @returns A property decorator
|
|
56
|
+
*/
|
|
57
|
+
function embedsMany(definition) {
|
|
58
|
+
const rel = Object.assign({ type: relation_types_1.RelationType.embedsMany }, definition);
|
|
59
|
+
return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
|
60
|
+
decoratorName: '@embedsMany',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.embedsMany = embedsMany;
|
|
64
|
+
/**
|
|
65
|
+
* Decorator for referencesOne
|
|
66
|
+
* @param definition
|
|
67
|
+
* @returns A property decorator
|
|
68
|
+
*/
|
|
69
|
+
function referencesOne(definition) {
|
|
70
|
+
const rel = Object.assign({ type: relation_types_1.RelationType.referencesOne }, definition);
|
|
71
|
+
return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
|
72
|
+
decoratorName: '@referencesOne',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.referencesOne = referencesOne;
|
|
76
|
+
/**
|
|
77
|
+
* Decorator for referencesMany
|
|
78
|
+
* @param definition
|
|
79
|
+
* @returns A property decorator
|
|
80
|
+
*/
|
|
81
|
+
function referencesMany(definition) {
|
|
82
|
+
const rel = Object.assign({ type: relation_types_1.RelationType.referencesMany }, definition);
|
|
83
|
+
return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
|
84
|
+
decoratorName: '@referencesMany',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.referencesMany = referencesMany;
|
|
88
|
+
//# sourceMappingURL=relation.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.decorator.js","sourceRoot":"","sources":["../../src/relations/relation.decorator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAwD;AACxD,8CAAmD;AAEnD,qDAA8C;AAEjC,QAAA,aAAa,GAAG,oBAAoB,CAAC;AAElD;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,UAAmB;IAC1C,+CAA+C;IAC/C,OAAO,+BAAwB,CAAC,eAAe,CAAC,qBAAa,EAAE,UAAU,EAAE;QACzE,aAAa,EAAE,WAAW;KAC3B,CAAC,CAAC;AACL,CAAC;AALD,4BAKC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,SAAuB;IAEvB,iDAAiD;IACjD,MAAM,QAAQ,GAAG,IAAA,iCAAoB,EAAC,SAAS,CAAC,CAAC;IACjD,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,KAAI,EAAE,CAAC;AACnC,CAAC;AAND,8CAMC;AAED,EAAE;AACF,oEAAoE;AACpE,6DAA6D;AAC7D,EAAE;AAEF;;;;GAIG;AACH,SAAgB,SAAS,CAAC,UAAmB;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,6BAAY,CAAC,SAAS,EAAC,EAAE,UAAU,CAAC,CAAC;IACtE,OAAO,+BAAwB,CAAC,eAAe,CAAC,qBAAa,EAAE,GAAG,EAAE;QAClE,aAAa,EAAE,YAAY;KAC5B,CAAC,CAAC;AACL,CAAC;AALD,8BAKC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,UAAmB;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,6BAAY,CAAC,UAAU,EAAC,EAAE,UAAU,CAAC,CAAC;IACvE,OAAO,+BAAwB,CAAC,eAAe,CAAC,qBAAa,EAAE,GAAG,EAAE;QAClE,aAAa,EAAE,aAAa;KAC7B,CAAC,CAAC;AACL,CAAC;AALD,gCAKC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,UAAmB;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,6BAAY,CAAC,aAAa,EAAC,EAAE,UAAU,CAAC,CAAC;IAC1E,OAAO,+BAAwB,CAAC,eAAe,CAAC,qBAAa,EAAE,GAAG,EAAE;QAClE,aAAa,EAAE,gBAAgB;KAChC,CAAC,CAAC;AACL,CAAC;AALD,sCAKC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,UAAmB;IAChD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,6BAAY,CAAC,cAAc,EAAC,EAAE,UAAU,CAAC,CAAC;IAC3E,OAAO,+BAAwB,CAAC,eAAe,CAAC,qBAAa,EAAE,GAAG,EAAE;QAClE,aAAa,EAAE,iBAAiB;KACjC,CAAC,CAAC;AACL,CAAC;AALD,wCAKC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AnyObject, Entity, EntityCrudRepository, Filter, InclusionFilter, Options } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Finds model instances that contain any of the provided foreign key values.
|
|
4
|
+
*
|
|
5
|
+
* @param targetRepository - The target repository where the related model instances are found
|
|
6
|
+
* @param fkName - Name of the foreign key
|
|
7
|
+
* @param fkValues - One value or array of values of the foreign key to be included
|
|
8
|
+
* @param scope - Additional scope constraints
|
|
9
|
+
* @param options - Options for the operations
|
|
10
|
+
*/
|
|
11
|
+
export declare function findByForeignKeys<Target extends Entity, TargetRelations extends object, ForeignKey extends StringKeyOf<Target>>(targetRepository: EntityCrudRepository<Target, unknown, TargetRelations>, fkName: ForeignKey, fkValues: Target[ForeignKey][] | Target[ForeignKey], scope?: Filter<Target> & {
|
|
12
|
+
totalLimit?: number;
|
|
13
|
+
}, options?: Options): Promise<(Target & TargetRelations)[]>;
|
|
14
|
+
export declare type StringKeyOf<T> = Extract<keyof T, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns model instances that include related models that have a registered
|
|
17
|
+
* resolver.
|
|
18
|
+
*
|
|
19
|
+
* @param targetRepository - The target repository where the model instances are found
|
|
20
|
+
* @param entities - An array of entity instances or data
|
|
21
|
+
* @param include -Inclusion filter
|
|
22
|
+
* @param options - Options for the operations
|
|
23
|
+
*/
|
|
24
|
+
export declare function includeRelatedModels<T extends Entity, Relations extends object = {}>(targetRepository: EntityCrudRepository<T, unknown, Relations>, entities: T[], include?: InclusionFilter[], options?: Options): Promise<(T & Relations)[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns an array of instances. The order of arrays is based on
|
|
27
|
+
* the order of sourceIds
|
|
28
|
+
*
|
|
29
|
+
* @param sourceIds - One value or array of values of the target key
|
|
30
|
+
* @param targetEntities - target entities that satisfy targetKey's value (ids).
|
|
31
|
+
* @param targetKey - name of the target key
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export declare function flattenTargetsOfOneToOneRelation<Target extends Entity>(sourceIds: unknown[], targetEntities: Target[], targetKey: StringKeyOf<Target>): (Target | undefined)[];
|
|
35
|
+
/**
|
|
36
|
+
* Returns an array of instances. The order of arrays is based on
|
|
37
|
+
* as a result of one to many relation. The order of arrays is based on
|
|
38
|
+
* the order of sourceIds
|
|
39
|
+
*
|
|
40
|
+
* @param sourceIds - One value or array of values of the target key
|
|
41
|
+
* @param targetEntities - target entities that satisfy targetKey's value (ids).
|
|
42
|
+
* @param targetKey - name of the target key
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
export declare function flattenTargetsOfOneToManyRelation<Target extends Entity>(sourceIds: unknown[], targetEntities: Target[], targetKey: StringKeyOf<Target>): (Target[] | undefined)[];
|
|
46
|
+
/**
|
|
47
|
+
* Returns an array of instances from the target map. The order of arrays is based on
|
|
48
|
+
* the order of sourceIds
|
|
49
|
+
*
|
|
50
|
+
* @param sourceIds - One value or array of values (of the target key)
|
|
51
|
+
* @param targetMap - a map that matches sourceIds with instances
|
|
52
|
+
*/
|
|
53
|
+
export declare function flattenMapByKeys<T>(sourceIds: unknown[], targetMap: Map<unknown, T>): (T | undefined)[];
|
|
54
|
+
/**
|
|
55
|
+
* Returns a map which maps key values(ids) to instances. The instances can be
|
|
56
|
+
* grouped by different strategies.
|
|
57
|
+
*
|
|
58
|
+
* @param list - an array of instances
|
|
59
|
+
* @param keyName - key name of the source
|
|
60
|
+
* @param reducer - a strategy to reduce inputs to single item or array
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildLookupMap<Key, InType, OutType = InType>(list: InType[], keyName: StringKeyOf<InType>, reducer: (accumulator: OutType | undefined, current: InType) => OutType): Map<Key, OutType>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns value of a keyName. Aims to resolve ObjectId problem of Mongo.
|
|
65
|
+
*
|
|
66
|
+
* @param model - target model
|
|
67
|
+
* @param keyName - target key that gets the value from
|
|
68
|
+
*/
|
|
69
|
+
export declare function getKeyValue(model: AnyObject, keyName: string): unknown;
|
|
70
|
+
/**
|
|
71
|
+
* Workaround for MongoDB, where the connector returns ObjectID
|
|
72
|
+
* values even for properties configured with "type: string".
|
|
73
|
+
*
|
|
74
|
+
* @param rawKey
|
|
75
|
+
*/
|
|
76
|
+
export declare function normalizeKey(rawKey: unknown): unknown;
|
|
77
|
+
/**
|
|
78
|
+
* Returns an array of instances. For HasMany relation usage.
|
|
79
|
+
*
|
|
80
|
+
* @param acc
|
|
81
|
+
* @param it
|
|
82
|
+
*/
|
|
83
|
+
export declare function reduceAsArray<T>(acc: T[] | undefined, it: T): T[];
|
|
84
|
+
/**
|
|
85
|
+
* Returns a single of an instance. For HasOne and BelongsTo relation usage.
|
|
86
|
+
*
|
|
87
|
+
* @param _acc
|
|
88
|
+
* @param it
|
|
89
|
+
*/
|
|
90
|
+
export declare function reduceAsSingleItem<T>(_acc: T | undefined, it: T): T;
|
|
91
|
+
/**
|
|
92
|
+
* Dedupe an array
|
|
93
|
+
* @param input - an array of sourceIds
|
|
94
|
+
* @returns an array with unique items
|
|
95
|
+
*/
|
|
96
|
+
export declare function deduplicate<T>(input: T[]): T[];
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the value is BsonType (mongodb)
|
|
99
|
+
* It uses a general way to check the type ,so that it can detect
|
|
100
|
+
* different versions of bson that might be used in the code base.
|
|
101
|
+
* Might need to update in the future.
|
|
102
|
+
*
|
|
103
|
+
* @param value
|
|
104
|
+
*/
|
|
105
|
+
export declare function isBsonType(value: unknown): value is object;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isBsonType = exports.deduplicate = exports.reduceAsSingleItem = exports.reduceAsArray = exports.normalizeKey = exports.getKeyValue = exports.buildLookupMap = exports.flattenMapByKeys = exports.flattenTargetsOfOneToManyRelation = exports.flattenTargetsOfOneToOneRelation = exports.includeRelatedModels = exports.findByForeignKeys = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
|
|
10
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
11
|
+
const lodash_1 = (0, tslib_1.__importStar)(require("lodash"));
|
|
12
|
+
const __1 = require("..");
|
|
13
|
+
const debug = (0, debug_1.default)('loopback:repository:relation-helpers');
|
|
14
|
+
/**
|
|
15
|
+
* Finds model instances that contain any of the provided foreign key values.
|
|
16
|
+
*
|
|
17
|
+
* @param targetRepository - The target repository where the related model instances are found
|
|
18
|
+
* @param fkName - Name of the foreign key
|
|
19
|
+
* @param fkValues - One value or array of values of the foreign key to be included
|
|
20
|
+
* @param scope - Additional scope constraints
|
|
21
|
+
* @param options - Options for the operations
|
|
22
|
+
*/
|
|
23
|
+
async function findByForeignKeys(targetRepository, fkName, fkValues, scope, options) {
|
|
24
|
+
let value;
|
|
25
|
+
scope = (0, lodash_1.cloneDeep)(scope);
|
|
26
|
+
if (Array.isArray(fkValues)) {
|
|
27
|
+
if (fkValues.length === 0)
|
|
28
|
+
return [];
|
|
29
|
+
value = fkValues.length === 1 ? fkValues[0] : { inq: fkValues };
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
value = fkValues;
|
|
33
|
+
}
|
|
34
|
+
let useScopeFilterGlobally = false;
|
|
35
|
+
// If its an include from a through model, fkValues will be an array.
|
|
36
|
+
// However, in this case we DO want to use the scope in the entire query, not
|
|
37
|
+
// on a per-fk basis
|
|
38
|
+
if (options) {
|
|
39
|
+
useScopeFilterGlobally = options.isThroughModelInclude;
|
|
40
|
+
}
|
|
41
|
+
// If `scope.limit` is not defined, there is no reason to apply the scope to
|
|
42
|
+
// each fk. This is to prevent unecessarily high database query counts.
|
|
43
|
+
// See: https://github.com/loopbackio/loopback-next/issues/8074
|
|
44
|
+
if (!(scope === null || scope === void 0 ? void 0 : scope.limit)) {
|
|
45
|
+
useScopeFilterGlobally = true;
|
|
46
|
+
}
|
|
47
|
+
// This code is to keep backward compatability.
|
|
48
|
+
// See https://github.com/loopbackio/loopback-next/issues/6832 for more info.
|
|
49
|
+
if (scope === null || scope === void 0 ? void 0 : scope.totalLimit) {
|
|
50
|
+
scope.limit = scope.totalLimit;
|
|
51
|
+
useScopeFilterGlobally = true;
|
|
52
|
+
delete scope.totalLimit;
|
|
53
|
+
}
|
|
54
|
+
const isScopeSet = scope && !lodash_1.default.isEmpty(scope);
|
|
55
|
+
if (isScopeSet && Array.isArray(fkValues) && !useScopeFilterGlobally) {
|
|
56
|
+
// Since there is a scope, there could be a where filter, a limit, an order
|
|
57
|
+
// and we should run the scope in multiple queries so we can respect the
|
|
58
|
+
// scope filter params
|
|
59
|
+
const findPromises = fkValues.map(fk => {
|
|
60
|
+
const where = { [fkName]: fk };
|
|
61
|
+
let localScope = (0, lodash_1.cloneDeep)(scope);
|
|
62
|
+
// combine where clause to scope filter
|
|
63
|
+
localScope = new __1.FilterBuilder(localScope).impose({ where }).filter;
|
|
64
|
+
return targetRepository.find(localScope, options);
|
|
65
|
+
});
|
|
66
|
+
return Promise.all(findPromises).then(findResults => {
|
|
67
|
+
//findResults is an array of arrays for each scope result, so we need to flatten it before returning it
|
|
68
|
+
return lodash_1.default.flatten(findResults);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const where = { [fkName]: value };
|
|
73
|
+
if (isScopeSet) {
|
|
74
|
+
// combine where clause to scope filter
|
|
75
|
+
scope = new __1.FilterBuilder(scope).impose({ where }).filter;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
scope = { where };
|
|
79
|
+
}
|
|
80
|
+
return targetRepository.find(scope, options);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.findByForeignKeys = findByForeignKeys;
|
|
84
|
+
/**
|
|
85
|
+
* Returns model instances that include related models that have a registered
|
|
86
|
+
* resolver.
|
|
87
|
+
*
|
|
88
|
+
* @param targetRepository - The target repository where the model instances are found
|
|
89
|
+
* @param entities - An array of entity instances or data
|
|
90
|
+
* @param include -Inclusion filter
|
|
91
|
+
* @param options - Options for the operations
|
|
92
|
+
*/
|
|
93
|
+
async function includeRelatedModels(targetRepository, entities, include, options) {
|
|
94
|
+
entities = (0, lodash_1.cloneDeep)(entities);
|
|
95
|
+
include = (0, lodash_1.cloneDeep)(include);
|
|
96
|
+
const result = entities;
|
|
97
|
+
if (!include)
|
|
98
|
+
return result;
|
|
99
|
+
const invalidInclusions = include.filter(inclusionFilter => !isInclusionAllowed(targetRepository, inclusionFilter));
|
|
100
|
+
if (invalidInclusions.length) {
|
|
101
|
+
const msg = 'Invalid "filter.include" entries: ' +
|
|
102
|
+
invalidInclusions
|
|
103
|
+
.map(inclusionFilter => JSON.stringify(inclusionFilter))
|
|
104
|
+
.join('; ');
|
|
105
|
+
const err = new Error(msg);
|
|
106
|
+
Object.assign(err, {
|
|
107
|
+
code: 'INVALID_INCLUSION_FILTER',
|
|
108
|
+
statusCode: 400,
|
|
109
|
+
});
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
const resolveTasks = include.map(async (inclusionFilter) => {
|
|
113
|
+
const relationName = typeof inclusionFilter === 'string'
|
|
114
|
+
? inclusionFilter
|
|
115
|
+
: inclusionFilter.relation;
|
|
116
|
+
const resolver = targetRepository.inclusionResolvers.get(relationName);
|
|
117
|
+
const targets = await resolver(entities, inclusionFilter, options);
|
|
118
|
+
result.forEach((entity, ix) => {
|
|
119
|
+
const src = entity;
|
|
120
|
+
src[relationName] = targets[ix];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
await Promise.all(resolveTasks);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
exports.includeRelatedModels = includeRelatedModels;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the resolver of the inclusion relation is registered
|
|
129
|
+
* in the inclusionResolver of the target repository
|
|
130
|
+
*
|
|
131
|
+
* @param targetRepository - The target repository where the relations are registered
|
|
132
|
+
* @param include - Inclusion filter
|
|
133
|
+
*/
|
|
134
|
+
function isInclusionAllowed(targetRepository, include) {
|
|
135
|
+
const relationName = typeof include === 'string' ? include : include.relation;
|
|
136
|
+
if (!relationName) {
|
|
137
|
+
debug('isInclusionAllowed for %j? No: missing relation name', include);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const allowed = targetRepository.inclusionResolvers.has(relationName);
|
|
141
|
+
debug('isInclusionAllowed for %j (relation %s)? %s', include, allowed);
|
|
142
|
+
return allowed;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns an array of instances. The order of arrays is based on
|
|
146
|
+
* the order of sourceIds
|
|
147
|
+
*
|
|
148
|
+
* @param sourceIds - One value or array of values of the target key
|
|
149
|
+
* @param targetEntities - target entities that satisfy targetKey's value (ids).
|
|
150
|
+
* @param targetKey - name of the target key
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
153
|
+
function flattenTargetsOfOneToOneRelation(sourceIds, targetEntities, targetKey) {
|
|
154
|
+
const lookup = buildLookupMap(targetEntities, targetKey, reduceAsSingleItem);
|
|
155
|
+
return flattenMapByKeys(sourceIds, lookup);
|
|
156
|
+
}
|
|
157
|
+
exports.flattenTargetsOfOneToOneRelation = flattenTargetsOfOneToOneRelation;
|
|
158
|
+
/**
|
|
159
|
+
* Returns an array of instances. The order of arrays is based on
|
|
160
|
+
* as a result of one to many relation. The order of arrays is based on
|
|
161
|
+
* the order of sourceIds
|
|
162
|
+
*
|
|
163
|
+
* @param sourceIds - One value or array of values of the target key
|
|
164
|
+
* @param targetEntities - target entities that satisfy targetKey's value (ids).
|
|
165
|
+
* @param targetKey - name of the target key
|
|
166
|
+
*
|
|
167
|
+
*/
|
|
168
|
+
function flattenTargetsOfOneToManyRelation(sourceIds, targetEntities, targetKey) {
|
|
169
|
+
debug('flattenTargetsOfOneToManyRelation');
|
|
170
|
+
debug('sourceIds', sourceIds);
|
|
171
|
+
debug('sourceId types', sourceIds.map(i => typeof i));
|
|
172
|
+
debug('targetEntities', targetEntities);
|
|
173
|
+
debug('targetKey', targetKey);
|
|
174
|
+
const lookup = buildLookupMap(targetEntities, targetKey, reduceAsArray);
|
|
175
|
+
debug('lookup map', lookup);
|
|
176
|
+
return flattenMapByKeys(sourceIds, lookup);
|
|
177
|
+
}
|
|
178
|
+
exports.flattenTargetsOfOneToManyRelation = flattenTargetsOfOneToManyRelation;
|
|
179
|
+
/**
|
|
180
|
+
* Returns an array of instances from the target map. The order of arrays is based on
|
|
181
|
+
* the order of sourceIds
|
|
182
|
+
*
|
|
183
|
+
* @param sourceIds - One value or array of values (of the target key)
|
|
184
|
+
* @param targetMap - a map that matches sourceIds with instances
|
|
185
|
+
*/
|
|
186
|
+
function flattenMapByKeys(sourceIds, targetMap) {
|
|
187
|
+
const result = new Array(sourceIds.length);
|
|
188
|
+
// mongodb: use string as key of targetMap, and convert sourceId to strings
|
|
189
|
+
// to make sure it gets the related instances.
|
|
190
|
+
sourceIds.forEach((id, index) => {
|
|
191
|
+
const key = normalizeKey(id);
|
|
192
|
+
const target = targetMap.get(key);
|
|
193
|
+
result[index] = target;
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
exports.flattenMapByKeys = flattenMapByKeys;
|
|
198
|
+
/**
|
|
199
|
+
* Returns a map which maps key values(ids) to instances. The instances can be
|
|
200
|
+
* grouped by different strategies.
|
|
201
|
+
*
|
|
202
|
+
* @param list - an array of instances
|
|
203
|
+
* @param keyName - key name of the source
|
|
204
|
+
* @param reducer - a strategy to reduce inputs to single item or array
|
|
205
|
+
*/
|
|
206
|
+
function buildLookupMap(list, keyName, reducer) {
|
|
207
|
+
const lookup = new Map();
|
|
208
|
+
for (const entity of list) {
|
|
209
|
+
// get a correct key value
|
|
210
|
+
const key = getKeyValue(entity, keyName);
|
|
211
|
+
// these 3 steps are to set up the map, the map differs according to the reducer.
|
|
212
|
+
const original = lookup.get(key);
|
|
213
|
+
const reduced = reducer(original, entity);
|
|
214
|
+
lookup.set(key, reduced);
|
|
215
|
+
}
|
|
216
|
+
return lookup;
|
|
217
|
+
}
|
|
218
|
+
exports.buildLookupMap = buildLookupMap;
|
|
219
|
+
/**
|
|
220
|
+
* Returns value of a keyName. Aims to resolve ObjectId problem of Mongo.
|
|
221
|
+
*
|
|
222
|
+
* @param model - target model
|
|
223
|
+
* @param keyName - target key that gets the value from
|
|
224
|
+
*/
|
|
225
|
+
function getKeyValue(model, keyName) {
|
|
226
|
+
return normalizeKey(model[keyName]);
|
|
227
|
+
}
|
|
228
|
+
exports.getKeyValue = getKeyValue;
|
|
229
|
+
/**
|
|
230
|
+
* Workaround for MongoDB, where the connector returns ObjectID
|
|
231
|
+
* values even for properties configured with "type: string".
|
|
232
|
+
*
|
|
233
|
+
* @param rawKey
|
|
234
|
+
*/
|
|
235
|
+
function normalizeKey(rawKey) {
|
|
236
|
+
if (isBsonType(rawKey)) {
|
|
237
|
+
return rawKey.toString();
|
|
238
|
+
}
|
|
239
|
+
return rawKey;
|
|
240
|
+
}
|
|
241
|
+
exports.normalizeKey = normalizeKey;
|
|
242
|
+
/**
|
|
243
|
+
* Returns an array of instances. For HasMany relation usage.
|
|
244
|
+
*
|
|
245
|
+
* @param acc
|
|
246
|
+
* @param it
|
|
247
|
+
*/
|
|
248
|
+
function reduceAsArray(acc, it) {
|
|
249
|
+
if (acc)
|
|
250
|
+
acc.push(it);
|
|
251
|
+
else
|
|
252
|
+
acc = [it];
|
|
253
|
+
return acc;
|
|
254
|
+
}
|
|
255
|
+
exports.reduceAsArray = reduceAsArray;
|
|
256
|
+
/**
|
|
257
|
+
* Returns a single of an instance. For HasOne and BelongsTo relation usage.
|
|
258
|
+
*
|
|
259
|
+
* @param _acc
|
|
260
|
+
* @param it
|
|
261
|
+
*/
|
|
262
|
+
function reduceAsSingleItem(_acc, it) {
|
|
263
|
+
return it;
|
|
264
|
+
}
|
|
265
|
+
exports.reduceAsSingleItem = reduceAsSingleItem;
|
|
266
|
+
/**
|
|
267
|
+
* Dedupe an array
|
|
268
|
+
* @param input - an array of sourceIds
|
|
269
|
+
* @returns an array with unique items
|
|
270
|
+
*/
|
|
271
|
+
function deduplicate(input) {
|
|
272
|
+
const uniqArray = [];
|
|
273
|
+
if (!input) {
|
|
274
|
+
return uniqArray;
|
|
275
|
+
}
|
|
276
|
+
(0, assert_1.default)(Array.isArray(input), 'array argument is required');
|
|
277
|
+
const comparableArray = input.map(item => normalizeKey(item));
|
|
278
|
+
for (let i = 0, n = comparableArray.length; i < n; i++) {
|
|
279
|
+
if (comparableArray.indexOf(comparableArray[i]) === i) {
|
|
280
|
+
uniqArray.push(input[i]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return uniqArray;
|
|
284
|
+
}
|
|
285
|
+
exports.deduplicate = deduplicate;
|
|
286
|
+
/**
|
|
287
|
+
* Checks if the value is BsonType (mongodb)
|
|
288
|
+
* It uses a general way to check the type ,so that it can detect
|
|
289
|
+
* different versions of bson that might be used in the code base.
|
|
290
|
+
* Might need to update in the future.
|
|
291
|
+
*
|
|
292
|
+
* @param value
|
|
293
|
+
*/
|
|
294
|
+
function isBsonType(value) {
|
|
295
|
+
if (typeof value !== 'object' || !value)
|
|
296
|
+
return false;
|
|
297
|
+
// bson@1.x stores _bsontype on ObjectID instance, bson@4.x on prototype
|
|
298
|
+
return check(value) || check(value.constructor.prototype);
|
|
299
|
+
function check(target) {
|
|
300
|
+
return Object.prototype.hasOwnProperty.call(target, '_bsontype');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.isBsonType = isBsonType;
|
|
304
|
+
//# sourceMappingURL=relation.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.helpers.js","sourceRoot":"","sources":["../../src/relations/relation.helpers.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,iEAA4B;AAC5B,+DAAiC;AACjC,8DAAoC;AACpC,0BASY;AACZ,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,sCAAsC,CAAC,CAAC;AAEnE;;;;;;;;GAQG;AACI,KAAK,UAAU,iBAAiB,CAKrC,gBAAwE,EACxE,MAAkB,EAClB,QAAmD,EACnD,KAA8C,EAC9C,OAAiB;IAEjB,IAAI,KAAK,CAAC;IACV,KAAK,GAAG,IAAA,kBAAS,EAAC,KAAK,CAAC,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,QAA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I,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAE1D,SAAS,KAAK,CAAC,MAAe;QAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AATD,gCASC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { InclusionFilter } from '@loopback/filter';
|
|
2
|
+
import { Options } from '../common-types';
|
|
3
|
+
import { Entity } from '../model';
|
|
4
|
+
import { TypeResolver } from '../type-resolver';
|
|
5
|
+
export declare enum RelationType {
|
|
6
|
+
belongsTo = "belongsTo",
|
|
7
|
+
hasOne = "hasOne",
|
|
8
|
+
hasMany = "hasMany",
|
|
9
|
+
embedsOne = "embedsOne",
|
|
10
|
+
embedsMany = "embedsMany",
|
|
11
|
+
referencesOne = "referencesOne",
|
|
12
|
+
referencesMany = "referencesMany"
|
|
13
|
+
}
|
|
14
|
+
export interface RelationDefinitionBase {
|
|
15
|
+
/**
|
|
16
|
+
* The type of the relation, must be one of RelationType values.
|
|
17
|
+
*/
|
|
18
|
+
type: RelationType;
|
|
19
|
+
/**
|
|
20
|
+
* True for relations targeting multiple instances (e.g. HasMany),
|
|
21
|
+
* false for relations with a single target (e.g. BelongsTo, HasOne).
|
|
22
|
+
* This property is needed by OpenAPI/JSON Schema generator.
|
|
23
|
+
*/
|
|
24
|
+
targetsMany: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The relation name, typically matching the name of the accessor property
|
|
27
|
+
* defined on the source model. For example "orders" or "customer".
|
|
28
|
+
*/
|
|
29
|
+
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* The source model of this relation.
|
|
32
|
+
*
|
|
33
|
+
* E.g. when a Customer has many Order instances, then Customer is the source.
|
|
34
|
+
*/
|
|
35
|
+
source: typeof Entity;
|
|
36
|
+
/**
|
|
37
|
+
* The target model of this relation.
|
|
38
|
+
*
|
|
39
|
+
* E.g. when a Customer has many Order instances, then Order is the target.
|
|
40
|
+
*/
|
|
41
|
+
target: TypeResolver<Entity, typeof Entity>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* HasManyDefinition defines one-to-many relations and also possible defines
|
|
45
|
+
* many-to-many relations with through models.
|
|
46
|
+
*/
|
|
47
|
+
export interface HasManyDefinition extends RelationDefinitionBase {
|
|
48
|
+
type: RelationType.hasMany;
|
|
49
|
+
targetsMany: true;
|
|
50
|
+
/**
|
|
51
|
+
* keyTo: The foreign key used by the target model for this relation.
|
|
52
|
+
* keyFrom: The source key used by the source model for this relation.
|
|
53
|
+
*
|
|
54
|
+
* E.g. when a Customer has many Order instances, then keyTo is "customerId".
|
|
55
|
+
* Note that "customerId" is the default FK assumed by the framework, users
|
|
56
|
+
* can provide a custom FK name by setting "keyTo".
|
|
57
|
+
* And Customer.id is keyFrom. keyFrom defaults to the id property of a model.
|
|
58
|
+
* Users can provide a custom source key name by setting "keyTo".
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
keyTo?: string;
|
|
62
|
+
keyFrom?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Description of the through model of the hasManyThrough relation.
|
|
65
|
+
*
|
|
66
|
+
* A `hasManyThrough` relation defines a many-to-many connection with another model.
|
|
67
|
+
* This relation indicates that the declaring model can be matched with zero or more
|
|
68
|
+
* instances of another model by proceeding through a third model.
|
|
69
|
+
*
|
|
70
|
+
* E.g a Category has many Products, and a Product can have many Categories.
|
|
71
|
+
* CategoryProductLink can be the through model.
|
|
72
|
+
* Such a through model has information of foreign keys of the source model(Category) and the target model(Product).
|
|
73
|
+
*
|
|
74
|
+
* Warning: The hasManyThrough interface is experimental and is subject to change.
|
|
75
|
+
* If backwards-incompatible changes are made, a new major version may not be
|
|
76
|
+
* released.
|
|
77
|
+
*/
|
|
78
|
+
through?: {
|
|
79
|
+
/**
|
|
80
|
+
* The through model of this relation.
|
|
81
|
+
*
|
|
82
|
+
* E.g. when a Category has many CategoryProductLink instances and a Product has many CategoryProductLink instances,
|
|
83
|
+
* then CategoryProductLink is through.
|
|
84
|
+
*/
|
|
85
|
+
model: TypeResolver<Entity, typeof Entity>;
|
|
86
|
+
/**
|
|
87
|
+
* The foreign key of the source model defined in the through model, e.g. CategoryProductLink#categoryId
|
|
88
|
+
*/
|
|
89
|
+
keyFrom?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The foreign key of the target model defined in the through model, e.g. CategoryProductLink#productId
|
|
92
|
+
*/
|
|
93
|
+
keyTo?: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export interface BelongsToDefinition extends RelationDefinitionBase {
|
|
97
|
+
type: RelationType.belongsTo;
|
|
98
|
+
targetsMany: false;
|
|
99
|
+
keyFrom?: string;
|
|
100
|
+
keyTo?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface HasOneDefinition extends RelationDefinitionBase {
|
|
103
|
+
type: RelationType.hasOne;
|
|
104
|
+
targetsMany: false;
|
|
105
|
+
/**
|
|
106
|
+
* keyTo: The foreign key used by the target model for this relation.
|
|
107
|
+
* keyFrom: The source key used by the source model for this relation.
|
|
108
|
+
*
|
|
109
|
+
* E.g. when a Customer has one Address instance, then keyTo is "customerId".
|
|
110
|
+
* Note that "customerId" is the default FK assumed by the framework, users
|
|
111
|
+
* can provide a custom FK name by setting "keyTo".
|
|
112
|
+
* And Customer.id is keyFrom. keyFrom defaults to the id property of a model.
|
|
113
|
+
* Users can provide a custom source key name by setting "keyTo".
|
|
114
|
+
*/
|
|
115
|
+
keyTo?: string;
|
|
116
|
+
keyFrom?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A union type describing all possible Relation metadata objects.
|
|
120
|
+
*/
|
|
121
|
+
export declare type RelationMetadata = HasManyDefinition | BelongsToDefinition | HasOneDefinition | RelationDefinitionBase;
|
|
122
|
+
export { Getter } from '@loopback/core';
|
|
123
|
+
/**
|
|
124
|
+
* @returns An array of resolved values, the items must be ordered in the same
|
|
125
|
+
* way as `sourceEntities`. The resolved value can be one of:
|
|
126
|
+
* - `undefined` when no target model(s) were found
|
|
127
|
+
* - `Entity` for relations targeting a single model
|
|
128
|
+
* - `Entity[]` for relations targeting multiple models
|
|
129
|
+
*/
|
|
130
|
+
export declare type InclusionResolver<S extends Entity, T extends Entity> = (
|
|
131
|
+
/**
|
|
132
|
+
* List of source models as returned by the first database query.
|
|
133
|
+
*/
|
|
134
|
+
sourceEntities: S[],
|
|
135
|
+
/**
|
|
136
|
+
* Inclusion requested by the user (e.g. scope constraints to apply).
|
|
137
|
+
*/
|
|
138
|
+
inclusion: InclusionFilter,
|
|
139
|
+
/**
|
|
140
|
+
* Generic options object, e.g. carrying the Transaction object.
|
|
141
|
+
*/
|
|
142
|
+
options?: Options) => Promise<(T | undefined)[] | (T[] | undefined)[]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Getter = exports.RelationType = void 0;
|
|
8
|
+
var RelationType;
|
|
9
|
+
(function (RelationType) {
|
|
10
|
+
RelationType["belongsTo"] = "belongsTo";
|
|
11
|
+
RelationType["hasOne"] = "hasOne";
|
|
12
|
+
RelationType["hasMany"] = "hasMany";
|
|
13
|
+
RelationType["embedsOne"] = "embedsOne";
|
|
14
|
+
RelationType["embedsMany"] = "embedsMany";
|
|
15
|
+
RelationType["referencesOne"] = "referencesOne";
|
|
16
|
+
RelationType["referencesMany"] = "referencesMany";
|
|
17
|
+
})(RelationType = exports.RelationType || (exports.RelationType = {}));
|
|
18
|
+
// Re-export Getter so that users don't have to import from @loopback/context
|
|
19
|
+
var core_1 = require("@loopback/core");
|
|
20
|
+
Object.defineProperty(exports, "Getter", { enumerable: true, get: function () { return core_1.Getter; } });
|
|
21
|
+
//# sourceMappingURL=relation.types.js.map
|