@loopback/repository 4.0.0-alpha.7 → 4.0.1
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 +94 -372
- 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/{lib6 → 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 -32
- 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 -16
- package/lib/index.js +0 -20
- 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.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 +0 -53
- 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 -16
- package/lib6/index.js +0 -20
- 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.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.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,76 @@
|
|
|
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 debugFactory from 'debug';
|
|
7
|
+
import {DataObject} from '../../common-types';
|
|
8
|
+
import {Entity} from '../../model';
|
|
9
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
10
|
+
import {Getter, HasManyDefinition, InclusionResolver} from '../relation.types';
|
|
11
|
+
import {resolveHasManyMetadata} from './has-many.helpers';
|
|
12
|
+
import {createHasManyInclusionResolver} from './has-many.inclusion-resolver';
|
|
13
|
+
import {
|
|
14
|
+
DefaultHasManyRepository,
|
|
15
|
+
HasManyRepository,
|
|
16
|
+
} from './has-many.repository';
|
|
17
|
+
|
|
18
|
+
const debug = debugFactory(
|
|
19
|
+
'loopback:repository:relations:has-many:repository-factory',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export interface HasManyRepositoryFactory<
|
|
23
|
+
Target extends Entity,
|
|
24
|
+
ForeignKeyType,
|
|
25
|
+
> {
|
|
26
|
+
/**
|
|
27
|
+
* Invoke the function to obtain HasManyRepository.
|
|
28
|
+
*/
|
|
29
|
+
(fkValue: ForeignKeyType): HasManyRepository<Target>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Use `resolver` property to obtain an InclusionResolver for this relation.
|
|
33
|
+
*/
|
|
34
|
+
inclusionResolver: InclusionResolver<Entity, Target>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Enforces a constraint on a repository based on a relationship contract
|
|
39
|
+
* between models. For example, if a Customer model is related to an Order model
|
|
40
|
+
* via a HasMany relation, then, the relational repository returned by the
|
|
41
|
+
* factory function would be constrained by a Customer model instance's id(s).
|
|
42
|
+
*
|
|
43
|
+
* @param relationMetadata - The relation metadata used to describe the
|
|
44
|
+
* relationship and determine how to apply the constraint.
|
|
45
|
+
* @param targetRepositoryGetter - The repository which represents the target model of a
|
|
46
|
+
* relation attached to a datasource.
|
|
47
|
+
* @returns The factory function which accepts a foreign key value to constrain
|
|
48
|
+
* the given target repository
|
|
49
|
+
*/
|
|
50
|
+
export function createHasManyRepositoryFactory<
|
|
51
|
+
Target extends Entity,
|
|
52
|
+
TargetID,
|
|
53
|
+
ForeignKeyType,
|
|
54
|
+
>(
|
|
55
|
+
relationMetadata: HasManyDefinition,
|
|
56
|
+
targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
57
|
+
): HasManyRepositoryFactory<Target, ForeignKeyType> {
|
|
58
|
+
const meta = resolveHasManyMetadata(relationMetadata);
|
|
59
|
+
debug('Resolved HasMany relation metadata: %o', meta);
|
|
60
|
+
const result: HasManyRepositoryFactory<Target, ForeignKeyType> = function (
|
|
61
|
+
fkValue: ForeignKeyType,
|
|
62
|
+
) {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
+
const constraint: any = {[meta.keyTo]: fkValue};
|
|
65
|
+
return new DefaultHasManyRepository<
|
|
66
|
+
Target,
|
|
67
|
+
TargetID,
|
|
68
|
+
EntityCrudRepository<Target, TargetID>
|
|
69
|
+
>(targetRepositoryGetter, constraint as DataObject<Target>);
|
|
70
|
+
};
|
|
71
|
+
result.inclusionResolver = createHasManyInclusionResolver(
|
|
72
|
+
meta,
|
|
73
|
+
targetRepositoryGetter,
|
|
74
|
+
);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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 {Getter} from '@loopback/core';
|
|
7
|
+
import {Filter, Where} from '@loopback/filter';
|
|
8
|
+
import {Count, DataObject, Options} from '../../common-types';
|
|
9
|
+
import {Entity} from '../../model';
|
|
10
|
+
import {
|
|
11
|
+
constrainDataObject,
|
|
12
|
+
constrainFilter,
|
|
13
|
+
constrainWhere,
|
|
14
|
+
EntityCrudRepository,
|
|
15
|
+
} from '../../repositories';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* CRUD operations for a target repository of a HasMany relation
|
|
19
|
+
*/
|
|
20
|
+
export interface HasManyRepository<Target extends Entity> {
|
|
21
|
+
/**
|
|
22
|
+
* Create a target model instance
|
|
23
|
+
* @param targetModelData - The target model data
|
|
24
|
+
* @param options - Options for the operation
|
|
25
|
+
* @returns A promise which resolves to the newly created target model instance
|
|
26
|
+
*/
|
|
27
|
+
create(
|
|
28
|
+
targetModelData: DataObject<Target>,
|
|
29
|
+
options?: Options,
|
|
30
|
+
): Promise<Target>;
|
|
31
|
+
/**
|
|
32
|
+
* Find target model instance(s)
|
|
33
|
+
* @param filter - A filter object for where, order, limit, etc.
|
|
34
|
+
* @param options - Options for the operation
|
|
35
|
+
* @returns A promise which resolves with the found target instance(s)
|
|
36
|
+
*/
|
|
37
|
+
find(filter?: Filter<Target>, options?: Options): Promise<Target[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete multiple target model instances
|
|
40
|
+
* @param where - Instances within the where scope are deleted
|
|
41
|
+
* @param options
|
|
42
|
+
* @returns A promise which resolves the deleted target model instances
|
|
43
|
+
*/
|
|
44
|
+
delete(where?: Where<Target>, options?: Options): Promise<Count>;
|
|
45
|
+
/**
|
|
46
|
+
* Patch multiple target model instances
|
|
47
|
+
* @param dataObject - The fields and their new values to patch
|
|
48
|
+
* @param where - Instances within the where scope are patched
|
|
49
|
+
* @param options
|
|
50
|
+
* @returns A promise which resolves the patched target model instances
|
|
51
|
+
*/
|
|
52
|
+
patch(
|
|
53
|
+
dataObject: DataObject<Target>,
|
|
54
|
+
where?: Where<Target>,
|
|
55
|
+
options?: Options,
|
|
56
|
+
): Promise<Count>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class DefaultHasManyRepository<
|
|
60
|
+
TargetEntity extends Entity,
|
|
61
|
+
TargetID,
|
|
62
|
+
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>,
|
|
63
|
+
> implements HasManyRepository<TargetEntity>
|
|
64
|
+
{
|
|
65
|
+
/**
|
|
66
|
+
* Constructor of DefaultHasManyEntityCrudRepository
|
|
67
|
+
* @param getTargetRepository - the getter of the related target model repository instance
|
|
68
|
+
* @param constraint - the key value pair representing foreign key name to constrain
|
|
69
|
+
* the target repository instance
|
|
70
|
+
*/
|
|
71
|
+
constructor(
|
|
72
|
+
public getTargetRepository: Getter<TargetRepository>,
|
|
73
|
+
public constraint: DataObject<TargetEntity>,
|
|
74
|
+
) {}
|
|
75
|
+
|
|
76
|
+
async create(
|
|
77
|
+
targetModelData: DataObject<TargetEntity>,
|
|
78
|
+
options?: Options,
|
|
79
|
+
): Promise<TargetEntity> {
|
|
80
|
+
const targetRepository = await this.getTargetRepository();
|
|
81
|
+
return targetRepository.create(
|
|
82
|
+
constrainDataObject(targetModelData, this.constraint),
|
|
83
|
+
options,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async find(
|
|
88
|
+
filter?: Filter<TargetEntity>,
|
|
89
|
+
options?: Options,
|
|
90
|
+
): Promise<TargetEntity[]> {
|
|
91
|
+
const targetRepository = await this.getTargetRepository();
|
|
92
|
+
return targetRepository.find(
|
|
93
|
+
constrainFilter(filter, this.constraint),
|
|
94
|
+
options,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async delete(where?: Where<TargetEntity>, options?: Options): Promise<Count> {
|
|
99
|
+
const targetRepository = await this.getTargetRepository();
|
|
100
|
+
return targetRepository.deleteAll(
|
|
101
|
+
constrainWhere(where, this.constraint as Where<TargetEntity>),
|
|
102
|
+
options,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async patch(
|
|
107
|
+
dataObject: DataObject<TargetEntity>,
|
|
108
|
+
where?: Where<TargetEntity>,
|
|
109
|
+
options?: Options,
|
|
110
|
+
): Promise<Count> {
|
|
111
|
+
const targetRepository = await this.getTargetRepository();
|
|
112
|
+
return targetRepository.updateAll(
|
|
113
|
+
constrainDataObject(dataObject, this.constraint),
|
|
114
|
+
constrainWhere(where, this.constraint as Where<TargetEntity>),
|
|
115
|
+
options,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export * from './has-many.repository-factory';
|
|
7
|
+
export * from './has-many-through.repository-factory';
|
|
8
|
+
export * from './has-many-through.repository';
|
|
9
|
+
export * from './has-many.decorator';
|
|
10
|
+
export * from './has-many.inclusion-resolver';
|
|
11
|
+
export * from './has-many.repository';
|
|
@@ -0,0 +1,40 @@
|
|
|
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 {HasOneDefinition, RelationType} from '../relation.types';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Decorator for hasOne
|
|
12
|
+
* infers foreign key name from target model name unless explicitly specified
|
|
13
|
+
* @param targetResolver - Target model for hasOne relation
|
|
14
|
+
* @param definition - Optional metadata for setting up hasOne relation
|
|
15
|
+
* @returns A property decorator
|
|
16
|
+
*/
|
|
17
|
+
export function hasOne<T extends Entity>(
|
|
18
|
+
targetResolver: EntityResolver<T>,
|
|
19
|
+
definition?: Partial<HasOneDefinition>,
|
|
20
|
+
) {
|
|
21
|
+
return function (decoratedTarget: object, key: string) {
|
|
22
|
+
// property.array(targetResolver)(decoratedTarget, key);
|
|
23
|
+
|
|
24
|
+
const meta: HasOneDefinition = Object.assign(
|
|
25
|
+
// default values, can be customized by the caller
|
|
26
|
+
{},
|
|
27
|
+
// properties provided by the caller
|
|
28
|
+
definition,
|
|
29
|
+
// properties enforced by the decorator
|
|
30
|
+
{
|
|
31
|
+
type: RelationType.hasOne,
|
|
32
|
+
targetsMany: false,
|
|
33
|
+
name: key,
|
|
34
|
+
source: decoratedTarget.constructor,
|
|
35
|
+
target: targetResolver,
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
relation(meta)(decoratedTarget, key);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 {HasOneDefinition, RelationType} from '../relation.types';
|
|
11
|
+
|
|
12
|
+
const debug = debugFactory('loopback:repository:relations:has-one:helpers');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Relation definition with optional metadata (e.g. `keyTo`) filled in.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type HasOneResolvedDefinition = HasOneDefinition & {
|
|
19
|
+
keyFrom: string;
|
|
20
|
+
keyTo: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolves given hasOne 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
|
+
* hasOne metadata
|
|
27
|
+
* @param relationMeta - hasOne metadata to resolve
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function resolveHasOneMetadata(
|
|
31
|
+
relationMeta: HasOneDefinition,
|
|
32
|
+
): HasOneResolvedDefinition {
|
|
33
|
+
if ((relationMeta.type as RelationType) !== RelationType.hasOne) {
|
|
34
|
+
const reason = 'relation type must be HasOne';
|
|
35
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!isTypeResolver(relationMeta.target)) {
|
|
39
|
+
const reason = 'target must be a type resolver';
|
|
40
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const targetModel = relationMeta.target();
|
|
44
|
+
const targetModelProperties = targetModel.definition?.properties;
|
|
45
|
+
|
|
46
|
+
const sourceModel = relationMeta.source;
|
|
47
|
+
if (!sourceModel || !sourceModel.modelName) {
|
|
48
|
+
const reason = 'source model must be defined';
|
|
49
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// keyFrom defaults to id property
|
|
53
|
+
let keyFrom;
|
|
54
|
+
if (
|
|
55
|
+
relationMeta.keyFrom &&
|
|
56
|
+
relationMeta.source.definition.properties[relationMeta.keyFrom]
|
|
57
|
+
) {
|
|
58
|
+
keyFrom = relationMeta.keyFrom;
|
|
59
|
+
} else {
|
|
60
|
+
keyFrom = sourceModel.getIdProperties()[0];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Make sure that if it already keys to the foreign key property,
|
|
64
|
+
// the key exists in the target model
|
|
65
|
+
if (relationMeta.keyTo && targetModelProperties[relationMeta.keyTo]) {
|
|
66
|
+
// The explicit cast is needed because of a limitation of type inference
|
|
67
|
+
return Object.assign(relationMeta, {keyFrom}) as HasOneResolvedDefinition;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
debug(
|
|
71
|
+
'Resolved model %s from given metadata: %o',
|
|
72
|
+
targetModel.modelName,
|
|
73
|
+
targetModel,
|
|
74
|
+
);
|
|
75
|
+
const defaultFkName = camelCase(sourceModel.modelName + '_id');
|
|
76
|
+
const hasDefaultFkProperty = targetModelProperties[defaultFkName];
|
|
77
|
+
|
|
78
|
+
if (!hasDefaultFkProperty) {
|
|
79
|
+
const reason = `target model ${targetModel.name} is missing definition of foreign key ${defaultFkName}`;
|
|
80
|
+
throw new InvalidRelationError(reason, relationMeta);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return Object.assign(relationMeta, {keyFrom, keyTo: defaultFkName});
|
|
84
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 {AnyObject, Options} from '../../common-types';
|
|
8
|
+
import {Entity} from '../../model';
|
|
9
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
10
|
+
import {
|
|
11
|
+
findByForeignKeys,
|
|
12
|
+
flattenTargetsOfOneToOneRelation,
|
|
13
|
+
StringKeyOf,
|
|
14
|
+
} from '../relation.helpers';
|
|
15
|
+
import {Getter, HasOneDefinition, InclusionResolver} from '../relation.types';
|
|
16
|
+
import {resolveHasOneMetadata} from './has-one.helpers';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates InclusionResolver for HasOne relation.
|
|
20
|
+
* Notice that this function only generates the inclusionResolver.
|
|
21
|
+
* It doesn't register it for the source repository.
|
|
22
|
+
*
|
|
23
|
+
* Notice: scope field for inclusion is not supported yet.
|
|
24
|
+
*
|
|
25
|
+
* @param meta
|
|
26
|
+
* @param getTargetRepo
|
|
27
|
+
*/
|
|
28
|
+
export function createHasOneInclusionResolver<
|
|
29
|
+
Target extends Entity,
|
|
30
|
+
TargetID,
|
|
31
|
+
TargetRelations extends object,
|
|
32
|
+
>(
|
|
33
|
+
meta: HasOneDefinition,
|
|
34
|
+
getTargetRepo: Getter<
|
|
35
|
+
EntityCrudRepository<Target, TargetID, TargetRelations>
|
|
36
|
+
>,
|
|
37
|
+
): InclusionResolver<Entity, Target> {
|
|
38
|
+
const relationMeta = resolveHasOneMetadata(meta);
|
|
39
|
+
|
|
40
|
+
return async function fetchHasOneModel(
|
|
41
|
+
entities: Entity[],
|
|
42
|
+
inclusion: InclusionFilter,
|
|
43
|
+
options?: Options,
|
|
44
|
+
): Promise<((Target & TargetRelations) | undefined)[]> {
|
|
45
|
+
if (!entities.length) return [];
|
|
46
|
+
|
|
47
|
+
const sourceKey = relationMeta.keyFrom;
|
|
48
|
+
const sourceIds = entities.map(e => (e as AnyObject)[sourceKey]);
|
|
49
|
+
const targetKey = relationMeta.keyTo as StringKeyOf<Target>;
|
|
50
|
+
|
|
51
|
+
const scope =
|
|
52
|
+
typeof inclusion === 'string' ? {} : (inclusion.scope as Filter<Target>);
|
|
53
|
+
|
|
54
|
+
const targetRepo = await getTargetRepo();
|
|
55
|
+
const targetsFound = await findByForeignKeys(
|
|
56
|
+
targetRepo,
|
|
57
|
+
targetKey,
|
|
58
|
+
sourceIds,
|
|
59
|
+
scope,
|
|
60
|
+
options,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return flattenTargetsOfOneToOneRelation(sourceIds, targetsFound, targetKey);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 debugFactory from 'debug';
|
|
7
|
+
import {DataObject} from '../../common-types';
|
|
8
|
+
import {Entity} from '../../model';
|
|
9
|
+
import {EntityCrudRepository} from '../../repositories';
|
|
10
|
+
import {Getter, HasOneDefinition, InclusionResolver} from '../relation.types';
|
|
11
|
+
import {resolveHasOneMetadata} from './has-one.helpers';
|
|
12
|
+
import {createHasOneInclusionResolver} from './has-one.inclusion-resolver';
|
|
13
|
+
import {DefaultHasOneRepository, HasOneRepository} from './has-one.repository';
|
|
14
|
+
|
|
15
|
+
const debug = debugFactory(
|
|
16
|
+
'loopback:repository:relations:has-one:repository-factory',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export interface HasOneRepositoryFactory<
|
|
20
|
+
Target extends Entity,
|
|
21
|
+
ForeignKeyType,
|
|
22
|
+
> {
|
|
23
|
+
/**
|
|
24
|
+
* Invoke the function to obtain HasOneRepository.
|
|
25
|
+
*/
|
|
26
|
+
(fkValue: ForeignKeyType): HasOneRepository<Target>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Use `resolver` property to obtain an InclusionResolver for this relation.
|
|
30
|
+
*/
|
|
31
|
+
inclusionResolver: InclusionResolver<Entity, Target>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Enforces a constraint on a repository based on a relationship contract
|
|
35
|
+
* between models. For example, if a Customer model is related to an Address model
|
|
36
|
+
* via a HasOne relation, then, the relational repository returned by the
|
|
37
|
+
* factory function would be constrained by a Customer model instance's id(s).
|
|
38
|
+
*
|
|
39
|
+
* @param relationMetadata - The relation metadata used to describe the
|
|
40
|
+
* relationship and determine how to apply the constraint.
|
|
41
|
+
* @param targetRepositoryGetter - The repository which represents the target model of a
|
|
42
|
+
* relation attached to a datasource.
|
|
43
|
+
* @returns The factory function which accepts a foreign key value to constrain
|
|
44
|
+
* the given target repository
|
|
45
|
+
*/
|
|
46
|
+
export function createHasOneRepositoryFactory<
|
|
47
|
+
Target extends Entity,
|
|
48
|
+
TargetID,
|
|
49
|
+
ForeignKeyType,
|
|
50
|
+
>(
|
|
51
|
+
relationMetadata: HasOneDefinition,
|
|
52
|
+
targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>,
|
|
53
|
+
): HasOneRepositoryFactory<Target, ForeignKeyType> {
|
|
54
|
+
const meta = resolveHasOneMetadata(relationMetadata);
|
|
55
|
+
debug('Resolved HasOne relation metadata: %o', meta);
|
|
56
|
+
const result: HasOneRepositoryFactory<Target, ForeignKeyType> = function (
|
|
57
|
+
fkValue: ForeignKeyType,
|
|
58
|
+
) {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
const constraint: any = {[meta.keyTo]: fkValue};
|
|
61
|
+
return new DefaultHasOneRepository<
|
|
62
|
+
Target,
|
|
63
|
+
TargetID,
|
|
64
|
+
EntityCrudRepository<Target, TargetID>
|
|
65
|
+
>(targetRepositoryGetter, constraint as DataObject<Target>);
|
|
66
|
+
};
|
|
67
|
+
result.inclusionResolver = createHasOneInclusionResolver(
|
|
68
|
+
meta,
|
|
69
|
+
targetRepositoryGetter,
|
|
70
|
+
);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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 {Getter} from '@loopback/core';
|
|
7
|
+
import {Filter} from '@loopback/filter';
|
|
8
|
+
import {Count, DataObject, Options} from '../../common-types';
|
|
9
|
+
import {EntityNotFoundError} from '../../errors';
|
|
10
|
+
import {Entity} from '../../model';
|
|
11
|
+
import {
|
|
12
|
+
constrainDataObject,
|
|
13
|
+
constrainFilter,
|
|
14
|
+
constrainWhere,
|
|
15
|
+
EntityCrudRepository,
|
|
16
|
+
} from '../../repositories';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* CRUD operations for a target repository of a HasMany relation
|
|
20
|
+
*/
|
|
21
|
+
export interface HasOneRepository<Target extends Entity> {
|
|
22
|
+
/**
|
|
23
|
+
* Create a target model instance
|
|
24
|
+
* @param targetModelData - The target model data
|
|
25
|
+
* @param options - Options for the operation
|
|
26
|
+
* @returns A promise which resolves to the newly created target model instance
|
|
27
|
+
*/
|
|
28
|
+
create(
|
|
29
|
+
targetModelData: DataObject<Target>,
|
|
30
|
+
options?: Options,
|
|
31
|
+
): Promise<Target>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Find the only target model instance that belongs to the declaring model.
|
|
35
|
+
* @param filter - Query filter without a Where condition
|
|
36
|
+
* @param options - Options for the operations
|
|
37
|
+
* @returns A promise resolved with the target object or rejected
|
|
38
|
+
* with an EntityNotFoundError when target model instance was not found.
|
|
39
|
+
*/
|
|
40
|
+
get(
|
|
41
|
+
filter?: Pick<Filter<Target>, Exclude<keyof Filter<Target>, 'where'>>,
|
|
42
|
+
options?: Options,
|
|
43
|
+
): Promise<Target>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Delete the related target model instance
|
|
47
|
+
* @param options
|
|
48
|
+
* @returns A promise which resolves the deleted target model instances
|
|
49
|
+
*/
|
|
50
|
+
delete(options?: Options): Promise<Count>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Patch the related target model instance
|
|
54
|
+
* @param dataObject - The target model fields and their new values to patch
|
|
55
|
+
* @param options
|
|
56
|
+
* @returns A promise which resolves the patched target model instances
|
|
57
|
+
*/
|
|
58
|
+
patch(dataObject: DataObject<Target>, options?: Options): Promise<Count>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class DefaultHasOneRepository<
|
|
62
|
+
TargetEntity extends Entity,
|
|
63
|
+
TargetID,
|
|
64
|
+
TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>,
|
|
65
|
+
> implements HasOneRepository<TargetEntity>
|
|
66
|
+
{
|
|
67
|
+
/**
|
|
68
|
+
* Constructor of DefaultHasOneEntityCrudRepository
|
|
69
|
+
* @param getTargetRepository - the getter of the related target model repository instance
|
|
70
|
+
* @param constraint - the key value pair representing foreign key name to constrain
|
|
71
|
+
* the target repository instance
|
|
72
|
+
*/
|
|
73
|
+
constructor(
|
|
74
|
+
public getTargetRepository: Getter<TargetRepository>,
|
|
75
|
+
public constraint: DataObject<TargetEntity>,
|
|
76
|
+
) {}
|
|
77
|
+
|
|
78
|
+
async create(
|
|
79
|
+
targetModelData: DataObject<TargetEntity>,
|
|
80
|
+
options?: Options,
|
|
81
|
+
): Promise<TargetEntity> {
|
|
82
|
+
const targetRepository = await this.getTargetRepository();
|
|
83
|
+
return targetRepository.create(
|
|
84
|
+
constrainDataObject(targetModelData, this.constraint),
|
|
85
|
+
options,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async get(
|
|
90
|
+
filter?: Pick<
|
|
91
|
+
Filter<TargetEntity>,
|
|
92
|
+
Exclude<keyof Filter<TargetEntity>, 'where'>
|
|
93
|
+
>,
|
|
94
|
+
options?: Options,
|
|
95
|
+
): Promise<TargetEntity> {
|
|
96
|
+
const targetRepository = await this.getTargetRepository();
|
|
97
|
+
const found = await targetRepository.find(
|
|
98
|
+
Object.assign({limit: 1}, constrainFilter(filter, this.constraint)),
|
|
99
|
+
options,
|
|
100
|
+
);
|
|
101
|
+
if (found.length < 1) {
|
|
102
|
+
// We don't have a direct access to the foreign key value here :(
|
|
103
|
+
const id = 'constraint ' + JSON.stringify(this.constraint);
|
|
104
|
+
throw new EntityNotFoundError(targetRepository.entityClass, id);
|
|
105
|
+
}
|
|
106
|
+
return found[0];
|
|
107
|
+
}
|
|
108
|
+
async delete(options?: Options): Promise<Count> {
|
|
109
|
+
const targetRepository = await this.getTargetRepository();
|
|
110
|
+
return targetRepository.deleteAll(
|
|
111
|
+
constrainWhere({}, this.constraint),
|
|
112
|
+
options,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async patch(
|
|
117
|
+
dataObject: DataObject<TargetEntity>,
|
|
118
|
+
options?: Options,
|
|
119
|
+
): Promise<Count> {
|
|
120
|
+
const targetRepository = await this.getTargetRepository();
|
|
121
|
+
return targetRepository.updateAll(
|
|
122
|
+
constrainDataObject(dataObject, this.constraint),
|
|
123
|
+
constrainWhere({}, this.constraint),
|
|
124
|
+
options,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export * from './has-one.decorator';
|
|
7
|
+
export * from './has-one.repository';
|
|
8
|
+
export * from './has-one.repository-factory';
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export * from './belongs-to';
|
|
7
|
+
export * from './has-many';
|
|
8
|
+
export * from './has-one';
|
|
9
|
+
export * from './relation.decorator';
|
|
10
|
+
export * from './relation.helpers';
|
|
11
|
+
export * from './relation.types';
|