@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,121 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DataObject,
|
|
8
|
+
Entity,
|
|
9
|
+
EntityCrudRepository,
|
|
10
|
+
Getter,
|
|
11
|
+
HasManyDefinition,
|
|
12
|
+
InclusionResolver,
|
|
13
|
+
} from '../..';
|
|
14
|
+
import {
|
|
15
|
+
createTargetConstraintFromThrough,
|
|
16
|
+
createThroughConstraintFromSource,
|
|
17
|
+
createThroughConstraintFromTarget,
|
|
18
|
+
getTargetIdsFromTargetModels,
|
|
19
|
+
getTargetKeysFromThroughModels,
|
|
20
|
+
resolveHasManyThroughMetadata,
|
|
21
|
+
} from './has-many-through.helpers';
|
|
22
|
+
import {createHasManyThroughInclusionResolver} from './has-many-through.inclusion-resolver';
|
|
23
|
+
import {
|
|
24
|
+
DefaultHasManyThroughRepository,
|
|
25
|
+
HasManyThroughRepository,
|
|
26
|
+
} from './has-many-through.repository';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* a factory to generate hasManyThrough repository class.
|
|
30
|
+
*
|
|
31
|
+
* Warning: The hasManyThrough interface is experimental and is subject to change.
|
|
32
|
+
* If backwards-incompatible changes are made, a new major version may not be
|
|
33
|
+
* released.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export type HasManyThroughRepositoryFactory<
|
|
37
|
+
TargetEntity extends Entity,
|
|
38
|
+
TargetID,
|
|
39
|
+
ThroughEntity extends Entity,
|
|
40
|
+
SourceID,
|
|
41
|
+
> = {
|
|
42
|
+
(fkValue: SourceID): HasManyThroughRepository<
|
|
43
|
+
TargetEntity,
|
|
44
|
+
TargetID,
|
|
45
|
+
ThroughEntity
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Use `resolver` property to obtain an InclusionResolver for this relation.
|
|
50
|
+
*/
|
|
51
|
+
inclusionResolver: InclusionResolver<Entity, TargetEntity>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function createHasManyThroughRepositoryFactory<
|
|
55
|
+
Target extends Entity,
|
|
56
|
+
TargetID,
|
|
57
|
+
Through extends Entity,
|
|
58
|
+
ThroughID,
|
|
59
|
+
SourceID,
|
|
60
|
+
>(
|
|
61
|
+
relationMetadata: HasManyDefinition,
|
|
62
|
+
targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
63
|
+
throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>,
|
|
64
|
+
): HasManyThroughRepositoryFactory<Target, TargetID, Through, SourceID> {
|
|
65
|
+
const meta = resolveHasManyThroughMetadata(relationMetadata);
|
|
66
|
+
const result = function (fkValue: SourceID) {
|
|
67
|
+
function getTargetConstraintFromThroughModels(
|
|
68
|
+
throughInstances: Through[],
|
|
69
|
+
): DataObject<Target> {
|
|
70
|
+
return createTargetConstraintFromThrough<Target, Through>(
|
|
71
|
+
meta,
|
|
72
|
+
throughInstances,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
function getTargetKeys(throughInstances: Through[]): TargetID[] {
|
|
76
|
+
return getTargetKeysFromThroughModels(meta, throughInstances);
|
|
77
|
+
}
|
|
78
|
+
function getThroughConstraintFromSource(): DataObject<Through> {
|
|
79
|
+
const constraint: DataObject<Through> = createThroughConstraintFromSource<
|
|
80
|
+
Through,
|
|
81
|
+
SourceID
|
|
82
|
+
>(meta, fkValue);
|
|
83
|
+
return constraint;
|
|
84
|
+
}
|
|
85
|
+
function getTargetIds(targetInstances: Target[]): TargetID[] {
|
|
86
|
+
return getTargetIdsFromTargetModels(meta, targetInstances);
|
|
87
|
+
}
|
|
88
|
+
function getThroughConstraintFromTarget(
|
|
89
|
+
fkValues: TargetID[],
|
|
90
|
+
): DataObject<Through> {
|
|
91
|
+
const constraint: DataObject<Through> = createThroughConstraintFromTarget<
|
|
92
|
+
Through,
|
|
93
|
+
TargetID
|
|
94
|
+
>(meta, fkValues);
|
|
95
|
+
return constraint;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return new DefaultHasManyThroughRepository<
|
|
99
|
+
Target,
|
|
100
|
+
TargetID,
|
|
101
|
+
EntityCrudRepository<Target, TargetID>,
|
|
102
|
+
Through,
|
|
103
|
+
ThroughID,
|
|
104
|
+
EntityCrudRepository<Through, ThroughID>
|
|
105
|
+
>(
|
|
106
|
+
targetRepositoryGetter,
|
|
107
|
+
throughRepositoryGetter,
|
|
108
|
+
getTargetConstraintFromThroughModels,
|
|
109
|
+
getTargetKeys,
|
|
110
|
+
getThroughConstraintFromSource,
|
|
111
|
+
getTargetIds,
|
|
112
|
+
getThroughConstraintFromTarget,
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
result.inclusionResolver = createHasManyThroughInclusionResolver(
|
|
116
|
+
meta,
|
|
117
|
+
throughRepositoryGetter,
|
|
118
|
+
targetRepositoryGetter,
|
|
119
|
+
);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
constrainDataObject,
|
|
8
|
+
constrainFilter,
|
|
9
|
+
constrainWhere,
|
|
10
|
+
constrainWhereOr,
|
|
11
|
+
Count,
|
|
12
|
+
DataObject,
|
|
13
|
+
Entity,
|
|
14
|
+
EntityCrudRepository,
|
|
15
|
+
Filter,
|
|
16
|
+
Getter,
|
|
17
|
+
Options,
|
|
18
|
+
Where,
|
|
19
|
+
} from '../..';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* CRUD operations for a target repository of a HasManyThrough relation
|
|
23
|
+
*
|
|
24
|
+
* EXPERIMENTAL: This interface is not stable and may change in the near future.
|
|
25
|
+
* Backwards-incompatible changes may be introduced in semver-minor versions.
|
|
26
|
+
*/
|
|
27
|
+
export interface HasManyThroughRepository<
|
|
28
|
+
Target extends Entity,
|
|
29
|
+
TargetID,
|
|
30
|
+
Through extends Entity,
|
|
31
|
+
> {
|
|
32
|
+
/**
|
|
33
|
+
* Create a target model instance
|
|
34
|
+
* @param targetModelData - The target model data
|
|
35
|
+
* @param options - Options for the operation
|
|
36
|
+
* @returns A promise which resolves to the newly created target model instance
|
|
37
|
+
*/
|
|
38
|
+
create(
|
|
39
|
+
targetModelData: DataObject<Target>,
|
|
40
|
+
options?: Options & {
|
|
41
|
+
throughData?: DataObject<Through>;
|
|
42
|
+
throughOptions?: Options;
|
|
43
|
+
},
|
|
44
|
+
): Promise<Target>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Find target model instance(s)
|
|
48
|
+
* @param filter - A filter object for where, order, limit, etc.
|
|
49
|
+
* @param options - Options for the operation
|
|
50
|
+
* @returns A promise which resolves with the found target instance(s)
|
|
51
|
+
*/
|
|
52
|
+
find(
|
|
53
|
+
filter?: Filter<Target>,
|
|
54
|
+
options?: Options & {
|
|
55
|
+
throughOptions?: Options;
|
|
56
|
+
},
|
|
57
|
+
): Promise<Target[]>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Delete multiple target model instances
|
|
61
|
+
* @param where - Instances within the where scope are deleted
|
|
62
|
+
* @param options
|
|
63
|
+
* @returns A promise which resolves the deleted target model instances
|
|
64
|
+
*/
|
|
65
|
+
delete(
|
|
66
|
+
where?: Where<Target>,
|
|
67
|
+
options?: Options & {
|
|
68
|
+
throughOptions?: Options;
|
|
69
|
+
},
|
|
70
|
+
): Promise<Count>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Patch multiple target model instances
|
|
74
|
+
* @param dataObject - The fields and their new values to patch
|
|
75
|
+
* @param where - Instances within the where scope are patched
|
|
76
|
+
* @param options
|
|
77
|
+
* @returns A promise which resolves the patched target model instances
|
|
78
|
+
*/
|
|
79
|
+
patch(
|
|
80
|
+
dataObject: DataObject<Target>,
|
|
81
|
+
where?: Where<Target>,
|
|
82
|
+
options?: Options & {
|
|
83
|
+
throughOptions?: Options;
|
|
84
|
+
},
|
|
85
|
+
): Promise<Count>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new many-to-many association to an existing target model instance
|
|
89
|
+
* @param targetModelId - The target model ID to link
|
|
90
|
+
* @param options
|
|
91
|
+
* @returns A promise which resolves to the linked target model instance
|
|
92
|
+
*/
|
|
93
|
+
link(
|
|
94
|
+
targetModelId: TargetID,
|
|
95
|
+
options?: Options & {
|
|
96
|
+
throughData?: DataObject<Through>;
|
|
97
|
+
throughOptions?: Options;
|
|
98
|
+
},
|
|
99
|
+
): Promise<void>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Removes an association to an existing target model instance
|
|
103
|
+
* @param targetModelId - The target model to unlink
|
|
104
|
+
* @param options
|
|
105
|
+
* @returns A promise which resolves to null
|
|
106
|
+
*/
|
|
107
|
+
unlink(
|
|
108
|
+
targetModelId: TargetID,
|
|
109
|
+
options?: Options & {
|
|
110
|
+
throughOptions?: Options;
|
|
111
|
+
},
|
|
112
|
+
): Promise<void>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Remove all association to an existing target model instance
|
|
116
|
+
* @param options
|
|
117
|
+
* @return A promise which resolves to void
|
|
118
|
+
*/
|
|
119
|
+
unlinkAll(
|
|
120
|
+
options?: Options & {
|
|
121
|
+
throughOptions?: Options;
|
|
122
|
+
},
|
|
123
|
+
): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* a class for CRUD operations for hasManyThrough relation.
|
|
128
|
+
*
|
|
129
|
+
* Warning: The hasManyThrough interface is experimental and is subject to change.
|
|
130
|
+
* If backwards-incompatible changes are made, a new major version may not be
|
|
131
|
+
* released.
|
|
132
|
+
*/
|
|
133
|
+
export class DefaultHasManyThroughRepository<
|
|
134
|
+
TargetEntity extends Entity,
|
|
135
|
+
TargetID,
|
|
136
|
+
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>,
|
|
137
|
+
ThroughEntity extends Entity,
|
|
138
|
+
ThroughID,
|
|
139
|
+
ThroughRepository extends EntityCrudRepository<ThroughEntity, ThroughID>,
|
|
140
|
+
> implements HasManyThroughRepository<TargetEntity, TargetID, ThroughEntity>
|
|
141
|
+
{
|
|
142
|
+
constructor(
|
|
143
|
+
public getTargetRepository: Getter<TargetRepository>,
|
|
144
|
+
public getThroughRepository: Getter<ThroughRepository>,
|
|
145
|
+
public getTargetConstraintFromThroughModels: (
|
|
146
|
+
throughInstances: ThroughEntity[],
|
|
147
|
+
) => DataObject<TargetEntity>,
|
|
148
|
+
public getTargetKeys: (throughInstances: ThroughEntity[]) => TargetID[],
|
|
149
|
+
public getThroughConstraintFromSource: () => DataObject<ThroughEntity>,
|
|
150
|
+
public getTargetIds: (targetInstances: TargetEntity[]) => TargetID[],
|
|
151
|
+
public getThroughConstraintFromTarget: (
|
|
152
|
+
targetID: TargetID[],
|
|
153
|
+
) => DataObject<ThroughEntity>,
|
|
154
|
+
) {}
|
|
155
|
+
|
|
156
|
+
async create(
|
|
157
|
+
targetModelData: DataObject<TargetEntity>,
|
|
158
|
+
options?: Options & {
|
|
159
|
+
throughData?: DataObject<ThroughEntity>;
|
|
160
|
+
throughOptions?: Options;
|
|
161
|
+
},
|
|
162
|
+
): Promise<TargetEntity> {
|
|
163
|
+
const targetRepository = await this.getTargetRepository();
|
|
164
|
+
const targetInstance = await targetRepository.create(
|
|
165
|
+
targetModelData,
|
|
166
|
+
options,
|
|
167
|
+
);
|
|
168
|
+
await this.link(targetInstance.getId(), options);
|
|
169
|
+
return targetInstance;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async find(
|
|
173
|
+
filter?: Filter<TargetEntity>,
|
|
174
|
+
options?: Options & {
|
|
175
|
+
throughOptions?: Options;
|
|
176
|
+
},
|
|
177
|
+
): Promise<TargetEntity[]> {
|
|
178
|
+
const targetRepository = await this.getTargetRepository();
|
|
179
|
+
const throughRepository = await this.getThroughRepository();
|
|
180
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
181
|
+
const throughInstances = await throughRepository.find(
|
|
182
|
+
constrainFilter(undefined, sourceConstraint),
|
|
183
|
+
options?.throughOptions,
|
|
184
|
+
);
|
|
185
|
+
const targetConstraint =
|
|
186
|
+
this.getTargetConstraintFromThroughModels(throughInstances);
|
|
187
|
+
return targetRepository.find(
|
|
188
|
+
constrainFilter(filter, targetConstraint),
|
|
189
|
+
options,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async delete(
|
|
194
|
+
where?: Where<TargetEntity>,
|
|
195
|
+
options?: Options & {
|
|
196
|
+
throughOptions?: Options;
|
|
197
|
+
},
|
|
198
|
+
): Promise<Count> {
|
|
199
|
+
const targetRepository = await this.getTargetRepository();
|
|
200
|
+
const throughRepository = await this.getThroughRepository();
|
|
201
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
202
|
+
const throughInstances = await throughRepository.find(
|
|
203
|
+
constrainFilter(undefined, sourceConstraint),
|
|
204
|
+
options?.throughOptions,
|
|
205
|
+
);
|
|
206
|
+
if (where) {
|
|
207
|
+
// only delete related through models
|
|
208
|
+
// TODO(Agnes): this performance can be improved by only fetching related data
|
|
209
|
+
// TODO: add target ids to the `where` constraint
|
|
210
|
+
const targets = await targetRepository.find({where});
|
|
211
|
+
const targetIds = this.getTargetIds(targets);
|
|
212
|
+
if (targetIds.length > 0) {
|
|
213
|
+
const targetConstraint = this.getThroughConstraintFromTarget(targetIds);
|
|
214
|
+
const constraints = {...targetConstraint, ...sourceConstraint};
|
|
215
|
+
await throughRepository.deleteAll(
|
|
216
|
+
constrainDataObject({}, constraints as DataObject<ThroughEntity>),
|
|
217
|
+
options?.throughOptions,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
// otherwise, delete through models that relate to the sourceId
|
|
222
|
+
const targetFkValues = this.getTargetKeys(throughInstances);
|
|
223
|
+
// delete through instances that have the targets that are going to be deleted
|
|
224
|
+
const throughFkConstraint =
|
|
225
|
+
this.getThroughConstraintFromTarget(targetFkValues);
|
|
226
|
+
await throughRepository.deleteAll(
|
|
227
|
+
constrainWhereOr({}, [sourceConstraint, throughFkConstraint]),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
// delete target(s)
|
|
231
|
+
const targetConstraint =
|
|
232
|
+
this.getTargetConstraintFromThroughModels(throughInstances);
|
|
233
|
+
return targetRepository.deleteAll(
|
|
234
|
+
constrainWhere(where, targetConstraint as Where<TargetEntity>),
|
|
235
|
+
options,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
// only allows patch target instances for now
|
|
239
|
+
async patch(
|
|
240
|
+
dataObject: DataObject<TargetEntity>,
|
|
241
|
+
where?: Where<TargetEntity>,
|
|
242
|
+
options?: Options & {
|
|
243
|
+
throughOptions?: Options;
|
|
244
|
+
},
|
|
245
|
+
): Promise<Count> {
|
|
246
|
+
const targetRepository = await this.getTargetRepository();
|
|
247
|
+
const throughRepository = await this.getThroughRepository();
|
|
248
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
249
|
+
const throughInstances = await throughRepository.find(
|
|
250
|
+
constrainFilter(undefined, sourceConstraint),
|
|
251
|
+
options?.throughOptions,
|
|
252
|
+
);
|
|
253
|
+
const targetConstraint =
|
|
254
|
+
this.getTargetConstraintFromThroughModels(throughInstances);
|
|
255
|
+
return targetRepository.updateAll(
|
|
256
|
+
constrainDataObject(dataObject, targetConstraint),
|
|
257
|
+
constrainWhere(where, targetConstraint as Where<TargetEntity>),
|
|
258
|
+
options,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async link(
|
|
263
|
+
targetId: TargetID,
|
|
264
|
+
options?: Options & {
|
|
265
|
+
throughData?: DataObject<ThroughEntity>;
|
|
266
|
+
throughOptions?: Options;
|
|
267
|
+
},
|
|
268
|
+
): Promise<void> {
|
|
269
|
+
const throughRepository = await this.getThroughRepository();
|
|
270
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
271
|
+
const targetConstraint = this.getThroughConstraintFromTarget([targetId]);
|
|
272
|
+
const constraints = {...targetConstraint, ...sourceConstraint};
|
|
273
|
+
await throughRepository.create(
|
|
274
|
+
constrainDataObject(
|
|
275
|
+
options?.throughData ?? {},
|
|
276
|
+
constraints as DataObject<ThroughEntity>,
|
|
277
|
+
),
|
|
278
|
+
options?.throughOptions,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async unlink(
|
|
283
|
+
targetId: TargetID,
|
|
284
|
+
options?: Options & {
|
|
285
|
+
throughOptions?: Options;
|
|
286
|
+
},
|
|
287
|
+
): Promise<void> {
|
|
288
|
+
const throughRepository = await this.getThroughRepository();
|
|
289
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
290
|
+
const targetConstraint = this.getThroughConstraintFromTarget([targetId]);
|
|
291
|
+
const constraints = {...targetConstraint, ...sourceConstraint};
|
|
292
|
+
await throughRepository.deleteAll(
|
|
293
|
+
constrainDataObject({}, constraints as DataObject<ThroughEntity>),
|
|
294
|
+
options?.throughOptions,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async unlinkAll(
|
|
299
|
+
options?: Options & {
|
|
300
|
+
throughOptions?: Options;
|
|
301
|
+
},
|
|
302
|
+
): Promise<void> {
|
|
303
|
+
const throughRepository = await this.getThroughRepository();
|
|
304
|
+
const sourceConstraint = this.getThroughConstraintFromSource();
|
|
305
|
+
const throughInstances = await throughRepository.find(
|
|
306
|
+
constrainFilter(undefined, sourceConstraint),
|
|
307
|
+
options?.throughOptions,
|
|
308
|
+
);
|
|
309
|
+
const targetFkValues = this.getTargetKeys(throughInstances);
|
|
310
|
+
const targetConstraint =
|
|
311
|
+
this.getThroughConstraintFromTarget(targetFkValues);
|
|
312
|
+
const constraints = {...targetConstraint, ...sourceConstraint};
|
|
313
|
+
await throughRepository.deleteAll(
|
|
314
|
+
constrainDataObject({}, constraints as DataObject<ThroughEntity>),
|
|
315
|
+
options?.throughOptions,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {Entity, EntityResolver} from '../../model';
|
|
7
|
+
import {relation} from '../relation.decorator';
|
|
8
|
+
import {HasManyDefinition, RelationType} from '../relation.types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Decorator for hasMany
|
|
12
|
+
* Calls property.array decorator underneath the hood and infers foreign key
|
|
13
|
+
* name from target model name unless explicitly specified
|
|
14
|
+
* @param targetResolver - Target model for hasMany relation
|
|
15
|
+
* @param definition - Optional metadata for setting up hasMany relation
|
|
16
|
+
* @returns A property decorator
|
|
17
|
+
*/
|
|
18
|
+
export function hasMany<T extends Entity>(
|
|
19
|
+
targetResolver: EntityResolver<T>,
|
|
20
|
+
definition?: Partial<HasManyDefinition>,
|
|
21
|
+
) {
|
|
22
|
+
return function (decoratedTarget: object, key: string) {
|
|
23
|
+
const meta: HasManyDefinition = Object.assign(
|
|
24
|
+
// default values, can be customized by the caller
|
|
25
|
+
{name: key},
|
|
26
|
+
// properties provided by the caller
|
|
27
|
+
definition,
|
|
28
|
+
// properties enforced by the decorator
|
|
29
|
+
{
|
|
30
|
+
type: RelationType.hasMany,
|
|
31
|
+
targetsMany: true,
|
|
32
|
+
source: decoratedTarget.constructor,
|
|
33
|
+
target: targetResolver,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
relation(meta)(decoratedTarget, key);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import debugFactory from 'debug';
|
|
7
|
+
import {camelCase} from 'lodash';
|
|
8
|
+
import {InvalidRelationError} from '../../errors';
|
|
9
|
+
import {isTypeResolver} from '../../type-resolver';
|
|
10
|
+
import {HasManyDefinition, RelationType} from '../relation.types';
|
|
11
|
+
|
|
12
|
+
const debug = debugFactory('loopback:repository:relations:has-many:helpers');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Relation definition with optional metadata (e.g. `keyTo`) filled in.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type HasManyResolvedDefinition = HasManyDefinition & {
|
|
19
|
+
keyFrom: string;
|
|
20
|
+
keyTo: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolves given hasMany metadata if target is specified to be a resolver.
|
|
25
|
+
* Mainly used to infer what the `keyTo` property should be from the target's
|
|
26
|
+
* belongsTo metadata
|
|
27
|
+
* @param relationMeta - hasMany metadata to resolve
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function resolveHasManyMetadata(
|
|
31
|
+
relationMeta: HasManyDefinition,
|
|
32
|
+
): HasManyResolvedDefinition {
|
|
33
|
+
// some checks and relationMeta.keyFrom are handled in here
|
|
34
|
+
relationMeta = resolveHasManyMetaHelper(relationMeta);
|
|
35
|
+
|
|
36
|
+
const targetModel = relationMeta.target();
|
|
37
|
+
const targetModelProperties = targetModel.definition?.properties;
|
|
38
|
+
|
|
39
|
+
const sourceModel = relationMeta.source;
|
|
40
|
+
|
|
41
|
+
if (relationMeta.keyTo && targetModelProperties[relationMeta.keyTo]) {
|
|
42
|
+
// The explicit cast is needed because of a limitation of type inference
|
|
43
|
+
return relationMeta as HasManyResolvedDefinition;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
debug(
|
|
47
|
+
'Resolved model %s from given metadata: %o',
|
|
48
|
+
targetModel.modelName,
|
|
49
|
+
targetModel,
|
|
50
|
+
);
|
|
51
|
+
const defaultFkName = camelCase(sourceModel.modelName + '_id');
|
|
52
|
+
const hasDefaultFkProperty = targetModelProperties[defaultFkName];
|
|
53
|
+
|
|
54
|
+
if (!hasDefaultFkProperty) {
|
|
55
|
+
const reason = `target model ${targetModel.name} is missing definition of foreign key ${defaultFkName}`;
|
|
56
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Object.assign(relationMeta, {
|
|
60
|
+
keyTo: defaultFkName,
|
|
61
|
+
} as HasManyResolvedDefinition);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A helper to check relation type and the existence of the source/target models
|
|
66
|
+
* and set up keyFrom
|
|
67
|
+
* for HasMany(Through) relations
|
|
68
|
+
* @param relationMeta
|
|
69
|
+
*
|
|
70
|
+
* @returns relationMeta that has set up keyFrom
|
|
71
|
+
*/
|
|
72
|
+
export function resolveHasManyMetaHelper(
|
|
73
|
+
relationMeta: HasManyDefinition,
|
|
74
|
+
): HasManyDefinition {
|
|
75
|
+
if ((relationMeta.type as RelationType) !== RelationType.hasMany) {
|
|
76
|
+
const reason = 'relation type must be HasMany';
|
|
77
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!isTypeResolver(relationMeta.target)) {
|
|
81
|
+
const reason = 'target must be a type resolver';
|
|
82
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const sourceModel = relationMeta.source;
|
|
86
|
+
if (!sourceModel || !sourceModel.modelName) {
|
|
87
|
+
const reason = 'source model must be defined';
|
|
88
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
89
|
+
}
|
|
90
|
+
let keyFrom;
|
|
91
|
+
if (
|
|
92
|
+
relationMeta.keyFrom &&
|
|
93
|
+
relationMeta.source.definition.properties[relationMeta.keyFrom]
|
|
94
|
+
) {
|
|
95
|
+
keyFrom = relationMeta.keyFrom;
|
|
96
|
+
} else {
|
|
97
|
+
keyFrom = sourceModel.getIdProperties()[0];
|
|
98
|
+
}
|
|
99
|
+
return Object.assign(relationMeta, {keyFrom}) as HasManyDefinition;
|
|
100
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {Filter, InclusionFilter} from '@loopback/filter';
|
|
7
|
+
import debugFactory from 'debug';
|
|
8
|
+
import {AnyObject, Options} from '../../common-types';
|
|
9
|
+
import {Entity} from '../../model';
|
|
10
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
11
|
+
import {
|
|
12
|
+
findByForeignKeys,
|
|
13
|
+
flattenTargetsOfOneToManyRelation,
|
|
14
|
+
StringKeyOf,
|
|
15
|
+
} from '../relation.helpers';
|
|
16
|
+
import {Getter, HasManyDefinition, InclusionResolver} from '../relation.types';
|
|
17
|
+
import {resolveHasManyMetadata} from './has-many.helpers';
|
|
18
|
+
|
|
19
|
+
const debug = debugFactory(
|
|
20
|
+
'loopback:repository:relations:has-many:inclusion-resolver',
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates InclusionResolver for HasMany relation.
|
|
25
|
+
* Notice that this function only generates the inclusionResolver.
|
|
26
|
+
* It doesn't register it for the source repository.
|
|
27
|
+
*
|
|
28
|
+
* Notice: scope field for inclusion is not supported yet.
|
|
29
|
+
*
|
|
30
|
+
* @param meta - resolved metadata of the hasMany relation
|
|
31
|
+
* @param getTargetRepo - target repository i.e where related instances are
|
|
32
|
+
*/
|
|
33
|
+
export function createHasManyInclusionResolver<
|
|
34
|
+
Target extends Entity,
|
|
35
|
+
TargetID,
|
|
36
|
+
TargetRelations extends object,
|
|
37
|
+
>(
|
|
38
|
+
meta: HasManyDefinition,
|
|
39
|
+
getTargetRepo: Getter<
|
|
40
|
+
EntityCrudRepository<Target, TargetID, TargetRelations>
|
|
41
|
+
>,
|
|
42
|
+
): InclusionResolver<Entity, Target> {
|
|
43
|
+
const relationMeta = resolveHasManyMetadata(meta);
|
|
44
|
+
|
|
45
|
+
return async function fetchHasManyModels(
|
|
46
|
+
entities: Entity[],
|
|
47
|
+
inclusion: InclusionFilter,
|
|
48
|
+
options?: Options,
|
|
49
|
+
): Promise<((Target & TargetRelations)[] | undefined)[]> {
|
|
50
|
+
if (!entities.length) return [];
|
|
51
|
+
|
|
52
|
+
debug('Fetching target models for entities:', entities);
|
|
53
|
+
debug('Relation metadata:', relationMeta);
|
|
54
|
+
|
|
55
|
+
const sourceKey = relationMeta.keyFrom;
|
|
56
|
+
const sourceIds = entities.map(e => (e as AnyObject)[sourceKey]);
|
|
57
|
+
const targetKey = relationMeta.keyTo as StringKeyOf<Target>;
|
|
58
|
+
|
|
59
|
+
debug('Parameters:', {sourceKey, sourceIds, targetKey});
|
|
60
|
+
debug(
|
|
61
|
+
'sourceId types',
|
|
62
|
+
sourceIds.map(i => typeof i),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const scope =
|
|
66
|
+
typeof inclusion === 'string' ? {} : (inclusion.scope as Filter<Target>);
|
|
67
|
+
|
|
68
|
+
const targetRepo = await getTargetRepo();
|
|
69
|
+
const targetsFound = await findByForeignKeys(
|
|
70
|
+
targetRepo,
|
|
71
|
+
targetKey,
|
|
72
|
+
sourceIds,
|
|
73
|
+
scope,
|
|
74
|
+
options,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
debug('Targets found:', targetsFound);
|
|
78
|
+
|
|
79
|
+
const result = flattenTargetsOfOneToManyRelation(
|
|
80
|
+
sourceIds,
|
|
81
|
+
targetsFound,
|
|
82
|
+
targetKey,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
debug('fetchHasManyModels result', result);
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
}
|