@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
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) IBM Corp. 2017,2019.
|
|
2
|
+
Node module: @loopback/repository
|
|
3
|
+
This project is licensed under the MIT License, full text below.
|
|
4
|
+
|
|
5
|
+
--------
|
|
6
|
+
|
|
7
|
+
MIT license
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,469 +1,173 @@
|
|
|
1
1
|
# @loopback/repository
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module provides a common set of interfaces for interacting with databases.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
the legacy `loopback-datasource-juggler` and connector modules from LoopBack
|
|
10
|
-
3.x.
|
|
11
|
-
|
|
12
|
-
This module provides data access facilities to various databases and services.
|
|
13
|
-
It contains the constructs for modeling and accessing data. Repositories can be
|
|
14
|
-
used alone or as part of `Controller` implementation.
|
|
7
|
+
This module provides data access facilities to various databases and services as
|
|
8
|
+
well as the constructs for modeling and accessing those data.
|
|
15
9
|
|
|
16
10
|
## Installation
|
|
17
11
|
|
|
18
|
-
```
|
|
19
|
-
|
|
12
|
+
```sh
|
|
13
|
+
npm install --save @loopback/repository
|
|
20
14
|
```
|
|
21
15
|
|
|
22
16
|
## Basic use
|
|
23
17
|
|
|
18
|
+
At the moment, we only have implementations of `Repository` based on LoopBack
|
|
19
|
+
3.x `loopback-datasource-juggler` and connectors. The following steps illustrate
|
|
20
|
+
how to define repositories and use them with controllers.
|
|
21
|
+
|
|
22
|
+
### Defining a legacy datasource and a model
|
|
23
|
+
|
|
24
24
|
The repository module provides APIs to define LoopBack 3.x data sources and
|
|
25
25
|
models. For example,
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
juggler,
|
|
31
|
-
} from '@loopback/repository';
|
|
28
|
+
// src/datasources/db.datasource.ts
|
|
29
|
+
import {juggler} from '@loopback/repository';
|
|
32
30
|
|
|
33
|
-
const
|
|
31
|
+
export const db: juggler.DataSource = new juggler.DataSource({
|
|
34
32
|
name: 'db',
|
|
35
33
|
connector: 'memory',
|
|
36
34
|
});
|
|
37
|
-
|
|
38
|
-
/* tslint:disable-next-line:variable-name */
|
|
39
|
-
const Note = ds.createModel<typeof juggler.PersistedModel>(
|
|
40
|
-
'note',
|
|
41
|
-
{title: 'string', content: 'string'},
|
|
42
|
-
{},
|
|
43
|
-
);
|
|
44
35
|
```
|
|
45
|
-
A repository can be created directly using `DefaultCrudRepository`.
|
|
46
36
|
|
|
47
37
|
```ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Bind the repository instance
|
|
51
|
-
ctx.bind('repositories.noteRepo').to(repo);
|
|
52
|
-
```
|
|
53
|
-
Fore more detailed info about the repository usage and implementation with a controller, please refer to [Use Repository](#use-repository)
|
|
54
|
-
|
|
55
|
-
## Concepts
|
|
56
|
-
|
|
57
|
-
### Repository
|
|
58
|
-
|
|
59
|
-
`Repository` represents a specialized `Service` interface that provides
|
|
60
|
-
strong-typed data access (for example, CRUD) operations of a domain model
|
|
61
|
-
against the underlying database or service.
|
|
62
|
-
|
|
63
|
-
`Repository` can be defined and implemented by application developers. LoopBack
|
|
64
|
-
ships a few predefined `Repository` interfaces for typical CRUD and KV
|
|
65
|
-
operations. Such `Repository` implements leverage `Model` definition and
|
|
66
|
-
`DataSource` configuration to fulfill the logic for data access.
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
interface Repository<T extends Model> {}
|
|
70
|
-
|
|
71
|
-
interface CustomerRepository extends Repository<Customer> {
|
|
72
|
-
find(filter?: Filter, options?: Options): Promise<Customer[]>;
|
|
73
|
-
findByEmail(email: string): Promise<Customer>;
|
|
74
|
-
// ...
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
See more examples at:
|
|
79
|
-
- [Repository/CrudRepository/EntityRepository](src/repository.ts)
|
|
80
|
-
- [KVRepository](src/kv-repository.ts)
|
|
81
|
-
|
|
82
|
-
### Model
|
|
83
|
-
|
|
84
|
-
A model describes business domain objects, for example, `Customer`, `Address`,
|
|
85
|
-
and `Order`. It usually defines a list of properties with name, type, and other
|
|
86
|
-
constraints.
|
|
87
|
-
|
|
88
|
-
Models can be used for data exchange on the wire or between different systems.
|
|
89
|
-
For example, a JSON object conforming to the `Customer` model definition can be
|
|
90
|
-
passed in REST/HTTP payload to create a new customer or stored in a document
|
|
91
|
-
database such as MongoDB. Model definitions can also be mapped to other forms,
|
|
92
|
-
such as relational database schema, XML schema, JSON schema, OpenAPI schema, or
|
|
93
|
-
gRPC message definition, and vice versa.
|
|
94
|
-
|
|
95
|
-
There are two subtly different types of models for domain objects:
|
|
96
|
-
|
|
97
|
-
- Value Object: A domain object that does not have an identity (ID). Its
|
|
98
|
-
equality is based on the structural value. For example, `Address` can be
|
|
99
|
-
modeled as `Value Object` as two US addresses are equal if they have the same
|
|
100
|
-
street number, street name, city, and zip code values. For example:
|
|
101
|
-
```json
|
|
102
|
-
{
|
|
103
|
-
"name": "Address",
|
|
104
|
-
"properties": {
|
|
105
|
-
"streetNum": "string",
|
|
106
|
-
"streetName": "string",
|
|
107
|
-
"city": "string",
|
|
108
|
-
"zipCode": "string"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
- Entity: A domain object that has an identity (ID). Its equality is based on
|
|
114
|
-
the identity. For example, `Customer` can be modeled as `Entity` as each
|
|
115
|
-
customer should have a unique customer id. Two instances of `Customer` with
|
|
116
|
-
the same customer id are equal since they refer to the same customer. For
|
|
117
|
-
example:
|
|
118
|
-
```json
|
|
119
|
-
{
|
|
120
|
-
"name": "Customer",
|
|
121
|
-
"properties": {
|
|
122
|
-
"id": "string",
|
|
123
|
-
"lastName": "string",
|
|
124
|
-
"firstName": "string",
|
|
125
|
-
"email": "string",
|
|
126
|
-
"address": "Address"
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### DataSource
|
|
132
|
-
|
|
133
|
-
`DataSource` is a named configuration of a connector. The configuration
|
|
134
|
-
properties vary by connectors. For example, a datasource for `MySQL` needs to
|
|
135
|
-
set the `connector` property to `loopback-connector-mysql` with settings such
|
|
136
|
-
as:
|
|
137
|
-
```json
|
|
138
|
-
{
|
|
139
|
-
"host": "localhost",
|
|
140
|
-
"port": 3306,
|
|
141
|
-
"user": "my-user",
|
|
142
|
-
"password": "my-password",
|
|
143
|
-
"database": "demo"
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
When a `DataSource` is instantiated, the configuration properties will be used
|
|
148
|
-
to initialize the connector to connect to the backend system.
|
|
149
|
-
|
|
150
|
-
### Connector
|
|
151
|
-
|
|
152
|
-
`Connector` is a provider that implements data access or api calls with a
|
|
153
|
-
specific backend system, such as a database, a REST service, a SOAP Web Service,
|
|
154
|
-
or a gRPC micro-service. It abstracts such interactions as a list of operations
|
|
155
|
-
in the form of Node.js methods.
|
|
38
|
+
// src/models/note.model.ts
|
|
39
|
+
import {model, Entity, property} from '@loopback/repository';
|
|
156
40
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
`create` method to SQL INSERT statement, which can be executed through MySQL
|
|
161
|
-
driver for Node.js.
|
|
162
|
-
|
|
163
|
-
### Mixin
|
|
164
|
-
|
|
165
|
-
`Mixin` is a way of building up classes from reusable components by combining
|
|
166
|
-
simpler partial classes, which can be modeled as `Mixin`.
|
|
167
|
-
|
|
168
|
-
For example, the mixins belows add methods and properties to a base class to
|
|
169
|
-
create a new one.
|
|
170
|
-
|
|
171
|
-
```js
|
|
172
|
-
// Mixin as a function
|
|
173
|
-
function timestampMixin(Base) {
|
|
174
|
-
return class extends Base {
|
|
175
|
-
created: Date = new Date();
|
|
176
|
-
modified: Date = new Date();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Mixin as an arrow function
|
|
181
|
-
const fullNameMixin = Base => class extends Base {
|
|
182
|
-
fullName() {
|
|
183
|
-
return `${this.firstName} ${this.lastName}`;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// The base class
|
|
188
|
-
class Customer {
|
|
41
|
+
@model()
|
|
42
|
+
export class Note extends Entity {
|
|
43
|
+
@property({id: true})
|
|
189
44
|
id: string;
|
|
190
|
-
|
|
191
|
-
|
|
45
|
+
@property()
|
|
46
|
+
title: string;
|
|
47
|
+
@property()
|
|
48
|
+
content: string;
|
|
192
49
|
}
|
|
193
50
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const CustomerWithTSAndFullName = fullNameMixin(CustomerWithTS);
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Type
|
|
201
|
-
|
|
202
|
-
To support property and parameter typing, LoopBack Next introduces an extensible
|
|
203
|
-
typing system to capture the metadata and perform corresponding checks and
|
|
204
|
-
coercion. The following types are supported out of box.
|
|
205
|
-
|
|
206
|
-
- StringType
|
|
207
|
-
- BooleanType
|
|
208
|
-
- NumberType
|
|
209
|
-
- DateType
|
|
210
|
-
- BufferType
|
|
211
|
-
- AnyType
|
|
212
|
-
- ArrayType
|
|
213
|
-
- UnionType
|
|
214
|
-
|
|
215
|
-
## Use Repository
|
|
216
|
-
The `Repository` and other interfaces extended from `Repository` provide access
|
|
217
|
-
to backend databases and services. Repositories can be used alone or as part
|
|
218
|
-
of `Controller` implementation.
|
|
219
|
-
|
|
220
|
-
At the moment, we only have implementations of `Repository` based on LoopBack
|
|
221
|
-
3.x `loopback-datasource-juggler` and connectors. The following steps illustrate
|
|
222
|
-
how to define repositories and use them with controllers.
|
|
223
|
-
|
|
224
|
-
### Define legacy data sources and models
|
|
225
|
-
|
|
226
|
-
The repository module provides APIs to define LoopBack 3.x data sources and
|
|
227
|
-
models. For example,
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
import {
|
|
231
|
-
DataSourceConstructor,
|
|
232
|
-
juggler,
|
|
233
|
-
} from '@loopback/repository';
|
|
234
|
-
|
|
235
|
-
const ds: juggler.DataSource = new DataSourceConstructor({
|
|
236
|
-
name: 'db',
|
|
237
|
-
connector: 'memory',
|
|
238
|
-
});
|
|
51
|
+
export interface NoteRelations {
|
|
52
|
+
// describe navigational properties here
|
|
53
|
+
}
|
|
239
54
|
|
|
240
|
-
|
|
241
|
-
const Note = ds.createModel<typeof juggler.PersistedModel>(
|
|
242
|
-
'note',
|
|
243
|
-
{title: 'string', content: 'string'},
|
|
244
|
-
{},
|
|
245
|
-
);
|
|
55
|
+
export type NoteWithRelations = Note & NoteRelations;
|
|
246
56
|
```
|
|
247
57
|
|
|
248
58
|
**NOTE**: There is no declarative support for data source and model yet in
|
|
249
|
-
LoopBack
|
|
250
|
-
|
|
59
|
+
LoopBack 4. These constructs need to be created programmatically as illustrated
|
|
60
|
+
above.
|
|
251
61
|
|
|
252
|
-
###
|
|
62
|
+
### Defining a repository
|
|
253
63
|
|
|
254
|
-
A repository can be created
|
|
64
|
+
A repository can be created by extending `DefaultCrudRepository` and using
|
|
65
|
+
dependency injection to resolve the datasource.
|
|
255
66
|
|
|
256
67
|
```ts
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// FIXME For some reason ts-node fails by complaining that
|
|
271
|
-
// juggler is undefined if the following is used:
|
|
272
|
-
// @inject('dataSources.memory') dataSource: juggler.DataSource
|
|
273
|
-
// tslint:disable-next-line:no-any
|
|
274
|
-
@inject('dataSources.memory') dataSource: any) {
|
|
275
|
-
super(myModel, dataSource);
|
|
276
|
-
}
|
|
68
|
+
// src/repositories/note.repository.ts
|
|
69
|
+
import {DefaultCrudRepository, DataSourceType} from '@loopback/repository';
|
|
70
|
+
import {Note, NoteRelations} from '../models';
|
|
71
|
+
import {inject} from '@loopback/core';
|
|
72
|
+
|
|
73
|
+
export class NoteRepository extends DefaultCrudRepository<
|
|
74
|
+
Note,
|
|
75
|
+
typeof Note.prototype.id,
|
|
76
|
+
NoteRelations
|
|
77
|
+
> {
|
|
78
|
+
constructor(@inject('datasources.db') protected dataSource: DataSourceType) {
|
|
79
|
+
super(Note, dataSource);
|
|
80
|
+
}
|
|
277
81
|
}
|
|
278
82
|
```
|
|
279
83
|
|
|
280
|
-
###
|
|
84
|
+
### Defining a controller
|
|
281
85
|
|
|
282
86
|
Controllers serve as handlers for API requests. We declare controllers as
|
|
283
87
|
classes with optional dependency injection by decorating constructor parameters
|
|
284
88
|
or properties.
|
|
285
89
|
|
|
286
90
|
```ts
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
import {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
Filter,
|
|
295
|
-
EntityCrudRepository,
|
|
296
|
-
} from '@loopback/repository';
|
|
297
|
-
|
|
298
|
-
// The Controller for Note
|
|
299
|
-
class NoteController {
|
|
91
|
+
// src/controllers/note.controller.ts
|
|
92
|
+
import {repository} from '@loopback/repository';
|
|
93
|
+
import {NoteRepository} from '../repositories';
|
|
94
|
+
import {Note} from '../models';
|
|
95
|
+
import {post, requestBody, get, param} from '@loopback/rest';
|
|
96
|
+
|
|
97
|
+
export class NoteController {
|
|
300
98
|
constructor(
|
|
301
99
|
// Use constructor dependency injection to set up the repository
|
|
302
|
-
@repository(
|
|
303
|
-
public noteRepo: EntityCrudRepository<Entity, number>,
|
|
100
|
+
@repository(NoteRepository) public noteRepo: NoteRepository,
|
|
304
101
|
) {}
|
|
305
102
|
|
|
306
103
|
// Create a new note
|
|
307
|
-
|
|
308
|
-
|
|
104
|
+
@post('/note')
|
|
105
|
+
create(@requestBody() data: Note) {
|
|
106
|
+
return this.noteRepo.create(data);
|
|
309
107
|
}
|
|
310
108
|
|
|
311
109
|
// Find notes by title
|
|
312
|
-
|
|
313
|
-
|
|
110
|
+
@get('/note/{title}')
|
|
111
|
+
findByTitle(@param.path.string('title') title: string) {
|
|
112
|
+
return this.noteRepo.find({where: {title}});
|
|
314
113
|
}
|
|
315
114
|
}
|
|
316
115
|
```
|
|
317
116
|
|
|
318
|
-
Alternatively, the controller can be declared using property injection:
|
|
319
|
-
|
|
320
|
-
```ts
|
|
321
|
-
class NoteController {
|
|
322
|
-
@repository('noteRepo')
|
|
323
|
-
public noteRepo: EntityCrudRepository<Entity, number>;
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
117
|
### Run the controller and repository together
|
|
328
118
|
|
|
329
|
-
#### Bind the repository to context
|
|
330
|
-
|
|
331
|
-
```ts
|
|
332
|
-
// Create a context
|
|
333
|
-
const ctx = new Context();
|
|
334
|
-
|
|
335
|
-
// Mock up a predefined repository
|
|
336
|
-
const repo = new DefaultCrudRepository(Note, ds);
|
|
337
|
-
|
|
338
|
-
// Bind the repository instance
|
|
339
|
-
ctx.bind('repositories.noteRepo').to(repo);
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
```ts
|
|
343
|
-
// Create a context
|
|
344
|
-
const ctx = new Context();
|
|
345
|
-
|
|
346
|
-
// Bind model `Note`
|
|
347
|
-
ctx.bind('models.Note').to(Note);
|
|
348
|
-
|
|
349
|
-
// Bind the in-memory DB dataSource
|
|
350
|
-
ctx.bind('dataSources.memory').to(ds);
|
|
351
|
-
|
|
352
|
-
// Bind the repository class
|
|
353
|
-
ctx.bind('repositories.noteRepo').toClass(MyNoteRepository);
|
|
354
|
-
```
|
|
355
|
-
|
|
356
119
|
#### Using the Repository Mixin for Application
|
|
357
|
-
A Repository Mixin is available for Application that provides convenience methods for binding and instantiating a repository class. Bound instances can be used anywhere in your application using Dependency Injection. An array set to the key `repositories` can be passed to the constructor or the `.repository(RepositoryClass)` function can be used. The mixin will also instantiate any repositories declared by a component in its constructor using the `repositories` key.
|
|
358
120
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
121
|
+
A Repository Mixin is available for Application that provides convenience
|
|
122
|
+
methods for binding and instantiating a repository class. Bound instances can be
|
|
123
|
+
used anywhere in your application using Dependency Injection. The
|
|
124
|
+
`.repository(RepositoryClass)` function can be used to bind a repository class
|
|
125
|
+
to an Application. The mixin will also instantiate any repositories declared by
|
|
126
|
+
a component in its constructor using the `repositories` key.
|
|
364
127
|
|
|
365
|
-
|
|
366
|
-
|
|
128
|
+
Repositories will be bound to the key `repositories.RepositoryClass` where
|
|
129
|
+
`RepositoryClass` is the name of the Repository class being bound.
|
|
367
130
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// MyRepository2 will be bound to key `repositories.CategoryRepository`
|
|
371
|
-
app.repository(CategoryRepository);
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### Compose repositories and controllers in a context
|
|
131
|
+
We'll use `BootMixin` on top of `RepositoryMixin` so that Repository bindings
|
|
132
|
+
can be taken care of automatically at boot time before the application starts.
|
|
375
133
|
|
|
376
134
|
```ts
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
// Resolve the controller
|
|
391
|
-
const controller: NoteController = await ctx.get('controllers.MyController');
|
|
392
|
-
|
|
393
|
-
// Create some notes
|
|
394
|
-
await controller.create({title: 't1', content: 'Note 1'});
|
|
395
|
-
await controller.create({title: 't2', content: 'Note 2'});
|
|
396
|
-
|
|
397
|
-
// Find notes by title
|
|
398
|
-
const notes = await controller.findByTitle('t1');
|
|
399
|
-
return notes;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// Invoke the example
|
|
403
|
-
main().then(notes => {
|
|
404
|
-
// It should print `Notes [ { title: 't1', content: 'Note 1', id: 1 } ]`
|
|
405
|
-
console.log('Notes', notes);
|
|
406
|
-
});
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
### Mix in a repository into the controller (To be implemented)
|
|
410
|
-
|
|
411
|
-
This style allows repository methods to be mixed into the controller class
|
|
412
|
-
to mimic LoopBack 3.x style model classes with remote CRUD methods. It blends
|
|
413
|
-
the repository responsibility/capability into the controller.
|
|
414
|
-
|
|
415
|
-
```js
|
|
416
|
-
import {EntityCrudRepository} from '../../src/repository';
|
|
417
|
-
import {Customer} from '../models/customer';
|
|
418
|
-
import {repository} from "../../src/decorator";
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Use class level @repository decorator to mixin repository methods into the
|
|
422
|
-
* controller class. Think about @repository as a shortcut to @mixin(...)
|
|
423
|
-
*/
|
|
424
|
-
// Style 1
|
|
425
|
-
// Create a repository that binds Customer to mongodbDataSource
|
|
426
|
-
@repository(Customer, 'mongodbDataSource')
|
|
427
|
-
// Style 2
|
|
428
|
-
// Reference a pre-configured repository by name. This is close to LoopBack
|
|
429
|
-
// 3.x model-config.json
|
|
430
|
-
// @repository('myCustomerRepository')
|
|
431
|
-
export class CustomerController {
|
|
432
|
-
// find() will be mixed in
|
|
433
|
-
}
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
## Declare pre-defined repositories in JSON/YAML (To be implemented)
|
|
437
|
-
|
|
438
|
-
Repositories can be declared in JSON/YAML files as follows:
|
|
439
|
-
|
|
440
|
-
server/repositories.json
|
|
441
|
-
```json
|
|
442
|
-
{
|
|
443
|
-
"customerRepo": {
|
|
444
|
-
"dataSource": "mysql",
|
|
445
|
-
"model": "Customer",
|
|
446
|
-
"settings": {}
|
|
135
|
+
import {BootMixin} from '@loopback/boot';
|
|
136
|
+
import {ApplicationConfig} from '@loopback/core';
|
|
137
|
+
import {RepositoryMixin} from '@loopback/repository';
|
|
138
|
+
import {RestApplication} from '@loopback/rest';
|
|
139
|
+
import {db} from './datasources/db.datasource';
|
|
140
|
+
|
|
141
|
+
export class RepoApplication extends BootMixin(
|
|
142
|
+
RepositoryMixin(RestApplication),
|
|
143
|
+
) {
|
|
144
|
+
constructor(options?: ApplicationConfig) {
|
|
145
|
+
super(options);
|
|
146
|
+
this.projectRoot = __dirname;
|
|
147
|
+
this.dataSource(db);
|
|
447
148
|
}
|
|
448
149
|
}
|
|
449
150
|
```
|
|
151
|
+
|
|
450
152
|
## Related resources
|
|
451
|
-
|
|
452
|
-
- https://
|
|
453
|
-
-
|
|
153
|
+
|
|
154
|
+
- <https://martinfowler.com/eaaCatalog/repository.html>
|
|
155
|
+
- <https://msdn.microsoft.com/en-us/library/ff649690.aspx>
|
|
156
|
+
- <http://docs.spring.io/spring-data/data-commons/docs/2.0.0.M3/reference/html/#repositories>
|
|
454
157
|
|
|
455
158
|
## Contributions
|
|
456
159
|
|
|
457
|
-
- [Guidelines](https://github.com/
|
|
458
|
-
- [Join the team](https://github.com/
|
|
160
|
+
- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
|
|
161
|
+
- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
|
|
459
162
|
|
|
460
163
|
## Tests
|
|
461
164
|
|
|
462
|
-
|
|
165
|
+
Run `npm test` from the root folder.
|
|
463
166
|
|
|
464
167
|
## Contributors
|
|
465
168
|
|
|
466
|
-
See
|
|
169
|
+
See
|
|
170
|
+
[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
|
|
467
171
|
|
|
468
172
|
## License
|
|
469
173
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types/interfaces such as Class/Constructor/Options/Callback
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Interface for classes with `new` operator and static properties/methods
|
|
6
|
+
*/
|
|
7
|
+
export interface Class<T> {
|
|
8
|
+
new (...args: any[]): T;
|
|
9
|
+
[property: string]: any;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface for constructor functions without `new` operator.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* function Foo(x) {
|
|
17
|
+
* if (!(this instanceof Foo)) { return new Foo(x); }
|
|
18
|
+
* this.x = x;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ConstructorFunction<T> {
|
|
23
|
+
(...args: any[]): T;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Constructor type - class or function
|
|
27
|
+
*/
|
|
28
|
+
export declare type Constructor<T> = Class<T> | ConstructorFunction<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Objects with open properties
|
|
31
|
+
*/
|
|
32
|
+
export interface AnyObject {
|
|
33
|
+
[property: string]: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* An extension of the built-in Partial<T> type which allows partial values
|
|
37
|
+
* in deeply nested properties too.
|
|
38
|
+
*/
|
|
39
|
+
export declare type DeepPartial<T> = Partial<T> | {
|
|
40
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Type alias for strongly or weakly typed objects of T
|
|
44
|
+
*/
|
|
45
|
+
export declare type DataObject<T extends object> = T | DeepPartial<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Type alias for Node.js options object
|
|
48
|
+
*/
|
|
49
|
+
export declare type Options = AnyObject;
|
|
50
|
+
/**
|
|
51
|
+
* Type alias for Node.js callback functions
|
|
52
|
+
*/
|
|
53
|
+
export declare type Callback<T> = (err: Error | string | null | undefined, result?: T) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Type for a command
|
|
56
|
+
*/
|
|
57
|
+
export declare type Command = string | AnyObject;
|
|
58
|
+
/**
|
|
59
|
+
* Named parameters, such as `{x: 1, y: 'a'}`
|
|
60
|
+
*/
|
|
61
|
+
export declare type NamedParameters = AnyObject;
|
|
62
|
+
/**
|
|
63
|
+
* Positional parameters, such as [1, 'a']
|
|
64
|
+
*/
|
|
65
|
+
export declare type PositionalParameters = any[];
|
|
66
|
+
/**
|
|
67
|
+
* Count of Model instances that were successful for methods like `updateAll`,
|
|
68
|
+
* `deleteAll`, etc.
|
|
69
|
+
*/
|
|
70
|
+
export interface Count {
|
|
71
|
+
count: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* JSON Schema describing the Count interface. It's the response type for
|
|
75
|
+
* REST calls to APIs which return `count`. The type is compatible with
|
|
76
|
+
* `SchemaObject` from `@loopback/openapi-v3`, which is not an explicit
|
|
77
|
+
* dependency for `@loopback/repository`.
|
|
78
|
+
*/
|
|
79
|
+
export declare const CountSchema: {
|
|
80
|
+
type: "object";
|
|
81
|
+
title: string;
|
|
82
|
+
'x-typescript-type': string;
|
|
83
|
+
properties: {
|
|
84
|
+
count: {
|
|
85
|
+
type: "number";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Type helper to infer prototype from a constructor function.
|
|
91
|
+
*
|
|
92
|
+
* Example: `PrototypeOf<typeof Entity>` is resolved to `Entity`.
|
|
93
|
+
*/
|
|
94
|
+
export declare type PrototypeOf<Ctor extends Function> = Ctor extends {
|
|
95
|
+
prototype: infer Proto;
|
|
96
|
+
} ? Proto : never;
|