@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,39 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2019. 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 {RelationType, RelationMetadata} from '../relations';
|
|
7
|
+
|
|
8
|
+
export class InvalidRelationError<Props extends object = {}> extends Error {
|
|
9
|
+
code: string;
|
|
10
|
+
reason: string;
|
|
11
|
+
relationName: string;
|
|
12
|
+
relationType: RelationType;
|
|
13
|
+
sourceModelName: string;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
reason: string,
|
|
17
|
+
relationMeta: RelationMetadata,
|
|
18
|
+
extraProperties?: Props,
|
|
19
|
+
) {
|
|
20
|
+
const {name, type, source} = relationMeta;
|
|
21
|
+
const model = source?.modelName || '<Unknown Model>';
|
|
22
|
+
const message = `Invalid ${type} definition for ${model}#${name}: ${reason}`;
|
|
23
|
+
super(message);
|
|
24
|
+
|
|
25
|
+
Error.captureStackTrace(this, this.constructor);
|
|
26
|
+
|
|
27
|
+
this.code = 'INVALID_RELATION_DEFINITION';
|
|
28
|
+
this.relationName = name;
|
|
29
|
+
this.relationType = type;
|
|
30
|
+
this.sourceModelName = model;
|
|
31
|
+
|
|
32
|
+
Object.assign(this, extraProperties);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
export function isInvalidRelationError(e: any): e is InvalidRelationError<any> {
|
|
38
|
+
return e instanceof InvalidRelationError;
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2017,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
|
+
/**
|
|
7
|
+
* A common set of interfaces for interacting with databases.
|
|
8
|
+
*
|
|
9
|
+
* This module provides data access facilities to various databases and services
|
|
10
|
+
* as well as the constructs for modeling and accessing those data.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export * from '@loopback/filter';
|
|
16
|
+
export {JSONSchema7 as JsonSchema} from 'json-schema';
|
|
17
|
+
/**
|
|
18
|
+
* Export the DataSource to avoid TypeScript 4.2's complaint about
|
|
19
|
+
* RepositoryMixin as it references `juggler.DataSource`
|
|
20
|
+
*/
|
|
21
|
+
export {DataSource as JugglerDataSource} from 'loopback-datasource-juggler';
|
|
22
|
+
export * from './common-types';
|
|
23
|
+
export * from './connectors';
|
|
24
|
+
export * from './datasource';
|
|
25
|
+
export * from './decorators';
|
|
26
|
+
export * from './define-model-class';
|
|
27
|
+
export * from './define-repository-class';
|
|
28
|
+
export * from './errors';
|
|
29
|
+
export * from './keys';
|
|
30
|
+
export * from './mixins';
|
|
31
|
+
export * from './model';
|
|
32
|
+
export * from './relations';
|
|
33
|
+
export * from './repositories';
|
|
34
|
+
export * from './transaction';
|
|
35
|
+
export * from './type-resolver';
|
|
36
|
+
export * from './types';
|
package/src/keys.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/repository
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Binding tags for repository related bindings
|
|
8
|
+
*/
|
|
9
|
+
export namespace RepositoryTags {
|
|
10
|
+
/**
|
|
11
|
+
* Tag for model class bindings
|
|
12
|
+
*/
|
|
13
|
+
export const MODEL = 'model';
|
|
14
|
+
/**
|
|
15
|
+
* Tag for repository bindings
|
|
16
|
+
*/
|
|
17
|
+
export const REPOSITORY = 'repository';
|
|
18
|
+
/**
|
|
19
|
+
* Tag for datasource bindings
|
|
20
|
+
*/
|
|
21
|
+
export const DATASOURCE = 'datasource';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Binding keys and namespaces for repository related bindings
|
|
26
|
+
*/
|
|
27
|
+
export namespace RepositoryBindings {
|
|
28
|
+
/**
|
|
29
|
+
* Namespace for model class bindings
|
|
30
|
+
*/
|
|
31
|
+
export const MODELS = 'models';
|
|
32
|
+
/**
|
|
33
|
+
* Namespace for repository bindings
|
|
34
|
+
*/
|
|
35
|
+
export const REPOSITORIES = 'repositories';
|
|
36
|
+
/**
|
|
37
|
+
* Namespace for datasource bindings
|
|
38
|
+
*/
|
|
39
|
+
export const DATASOURCES = 'datasources';
|
|
40
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Copyright IBM Corp.
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
2
|
// Node module: @loopback/repository
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './repository.mixin';
|
|
@@ -0,0 +1,499 @@
|
|
|
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 {
|
|
7
|
+
Application,
|
|
8
|
+
Binding,
|
|
9
|
+
BindingFromClassOptions,
|
|
10
|
+
BindingScope,
|
|
11
|
+
Component,
|
|
12
|
+
Constructor,
|
|
13
|
+
CoreBindings,
|
|
14
|
+
createBindingFromClass,
|
|
15
|
+
MixinTarget,
|
|
16
|
+
} from '@loopback/core';
|
|
17
|
+
import debugFactory from 'debug';
|
|
18
|
+
import {Class} from '../common-types';
|
|
19
|
+
import {SchemaMigrationOptions} from '../datasource';
|
|
20
|
+
import {RepositoryBindings, RepositoryTags} from '../keys';
|
|
21
|
+
import {Model} from '../model';
|
|
22
|
+
import {juggler, Repository} from '../repositories';
|
|
23
|
+
|
|
24
|
+
const debug = debugFactory('loopback:repository:mixin');
|
|
25
|
+
|
|
26
|
+
// FIXME(rfeng): Workaround for https://github.com/microsoft/rushstack/pull/1867
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
28
|
+
import * as loopbackContext from '@loopback/core';
|
|
29
|
+
import * as loopbackCore from '@loopback/core';
|
|
30
|
+
|
|
31
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A mixin class for Application that creates a .repository()
|
|
35
|
+
* function to register a repository automatically. Also overrides
|
|
36
|
+
* component function to allow it to register repositories automatically.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* class MyApplication extends RepositoryMixin(Application) {}
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Please note: the members in the mixin function are documented in a dummy class
|
|
44
|
+
* called <a href="#RepositoryMixinDoc">RepositoryMixinDoc</a>
|
|
45
|
+
*
|
|
46
|
+
* @param superClass - Application class
|
|
47
|
+
* @returns A new class that extends the super class with repository related
|
|
48
|
+
* methods
|
|
49
|
+
*
|
|
50
|
+
* @typeParam T - Type of the application class as the target for the mixin
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export function RepositoryMixin<T extends MixinTarget<Application>>(
|
|
54
|
+
superClass: T,
|
|
55
|
+
) {
|
|
56
|
+
return class extends superClass {
|
|
57
|
+
/**
|
|
58
|
+
* Add a repository to this application.
|
|
59
|
+
*
|
|
60
|
+
* @param repoClass - The repository to add.
|
|
61
|
+
* @param nameOrOptions - Name or options for the binding
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
*
|
|
66
|
+
* class NoteRepo {
|
|
67
|
+
* model: any;
|
|
68
|
+
*
|
|
69
|
+
* constructor() {
|
|
70
|
+
* const ds: juggler.DataSource = new juggler.DataSource({
|
|
71
|
+
* name: 'db',
|
|
72
|
+
* connector: 'memory',
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* this.model = ds.createModel(
|
|
76
|
+
* 'note',
|
|
77
|
+
* {title: 'string', content: 'string'},
|
|
78
|
+
* {}
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* app.repository(NoteRepo);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
repository<R extends Repository<any>>(
|
|
88
|
+
repoClass: Class<R>,
|
|
89
|
+
nameOrOptions?: string | BindingFromClassOptions,
|
|
90
|
+
): Binding<R> {
|
|
91
|
+
const binding = createBindingFromClass(repoClass, {
|
|
92
|
+
namespace: RepositoryBindings.REPOSITORIES,
|
|
93
|
+
type: RepositoryTags.REPOSITORY,
|
|
94
|
+
defaultScope: BindingScope.TRANSIENT,
|
|
95
|
+
...toOptions(nameOrOptions),
|
|
96
|
+
}).tag(RepositoryTags.REPOSITORY);
|
|
97
|
+
this.add(binding);
|
|
98
|
+
return binding;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Retrieve the repository instance from the given Repository class
|
|
103
|
+
*
|
|
104
|
+
* @param repo - The repository class to retrieve the instance of
|
|
105
|
+
*/
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
async getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R> {
|
|
108
|
+
return this.get(`repositories.${repo.name}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Add the dataSource to this application.
|
|
113
|
+
*
|
|
114
|
+
* @param dataSource - The dataSource to add.
|
|
115
|
+
* @param nameOrOptions - The binding name or options of the datasource;
|
|
116
|
+
* defaults to dataSource.name
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
*
|
|
121
|
+
* const ds: juggler.DataSource = new juggler.DataSource({
|
|
122
|
+
* name: 'db',
|
|
123
|
+
* connector: 'memory',
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* app.dataSource(ds);
|
|
127
|
+
*
|
|
128
|
+
* // The datasource can be injected with
|
|
129
|
+
* constructor(@inject('datasources.db') dataSource: DataSourceType) {
|
|
130
|
+
*
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
dataSource<D extends juggler.DataSource>(
|
|
135
|
+
dataSource: Class<D> | D,
|
|
136
|
+
nameOrOptions?: string | BindingFromClassOptions,
|
|
137
|
+
): Binding<D> {
|
|
138
|
+
const options = toOptions(nameOrOptions);
|
|
139
|
+
// We have an instance of
|
|
140
|
+
if (dataSource instanceof juggler.DataSource) {
|
|
141
|
+
const name = options.name || dataSource.name;
|
|
142
|
+
const namespace = options.namespace ?? RepositoryBindings.DATASOURCES;
|
|
143
|
+
const key = `${namespace}.${name}`;
|
|
144
|
+
return this.bind(key).to(dataSource).tag(RepositoryTags.DATASOURCE);
|
|
145
|
+
} else if (typeof dataSource === 'function') {
|
|
146
|
+
options.name = options.name || dataSource.dataSourceName;
|
|
147
|
+
const binding = createBindingFromClass(dataSource, {
|
|
148
|
+
namespace: RepositoryBindings.DATASOURCES,
|
|
149
|
+
type: RepositoryTags.DATASOURCE,
|
|
150
|
+
defaultScope: BindingScope.SINGLETON,
|
|
151
|
+
...options,
|
|
152
|
+
});
|
|
153
|
+
this.add(binding);
|
|
154
|
+
return binding;
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error('not a valid DataSource.');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Register a model class as a binding in the target context
|
|
162
|
+
* @param modelClass - Model class
|
|
163
|
+
*/
|
|
164
|
+
model<M extends Class<unknown>>(modelClass: M) {
|
|
165
|
+
const binding = createModelClassBinding(modelClass);
|
|
166
|
+
this.add(binding);
|
|
167
|
+
return binding;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Add a component to this application. Also mounts
|
|
172
|
+
* all the components repositories.
|
|
173
|
+
*
|
|
174
|
+
* @param component - The component to add.
|
|
175
|
+
* @param nameOrOptions - Name or options for the binding.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
*
|
|
180
|
+
* export class ProductComponent {
|
|
181
|
+
* controllers = [ProductController];
|
|
182
|
+
* repositories = [ProductRepo, UserRepo];
|
|
183
|
+
* providers = {
|
|
184
|
+
* [AUTHENTICATION_STRATEGY]: AuthStrategy,
|
|
185
|
+
* [AUTHORIZATION_ROLE]: Role,
|
|
186
|
+
* };
|
|
187
|
+
* };
|
|
188
|
+
*
|
|
189
|
+
* app.component(ProductComponent);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
// Unfortunately, TypeScript does not allow overriding methods inherited
|
|
193
|
+
// from mapped types. https://github.com/microsoft/TypeScript/issues/38496
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
public component<C extends Component = Component>(
|
|
197
|
+
componentCtor: Constructor<C>,
|
|
198
|
+
nameOrOptions?: string | BindingFromClassOptions,
|
|
199
|
+
) {
|
|
200
|
+
const binding = super.component(componentCtor, nameOrOptions);
|
|
201
|
+
const instance = this.getSync<C & RepositoryComponent>(binding.key);
|
|
202
|
+
this.mountComponentRepositories(instance);
|
|
203
|
+
this.mountComponentModels(instance);
|
|
204
|
+
return binding;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Get an instance of a component and mount all it's
|
|
209
|
+
* repositories. This function is intended to be used internally
|
|
210
|
+
* by `component()`.
|
|
211
|
+
*
|
|
212
|
+
* NOTE: Calling `mountComponentRepositories` with a component class
|
|
213
|
+
* constructor is deprecated. You should instantiate the component
|
|
214
|
+
* yourself and provide the component instance instead.
|
|
215
|
+
*
|
|
216
|
+
* @param componentInstanceOrClass - The component to mount repositories of
|
|
217
|
+
* @internal
|
|
218
|
+
*/
|
|
219
|
+
mountComponentRepositories(
|
|
220
|
+
// accept also component class to preserve backwards compatibility
|
|
221
|
+
// TODO(semver-major) Remove support for component class constructor
|
|
222
|
+
componentInstanceOrClass: Class<unknown> | RepositoryComponent,
|
|
223
|
+
) {
|
|
224
|
+
const component = resolveComponentInstance(this);
|
|
225
|
+
|
|
226
|
+
if (component.repositories) {
|
|
227
|
+
for (const repo of component.repositories) {
|
|
228
|
+
this.repository(repo);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// `Readonly<Application>` is a hack to remove protected members
|
|
233
|
+
// and thus allow `this` to be passed as a value for `ctx`
|
|
234
|
+
function resolveComponentInstance(ctx: Readonly<Application>) {
|
|
235
|
+
if (typeof componentInstanceOrClass !== 'function')
|
|
236
|
+
return componentInstanceOrClass;
|
|
237
|
+
|
|
238
|
+
const componentName = componentInstanceOrClass.name;
|
|
239
|
+
const componentKey = `${CoreBindings.COMPONENTS}.${componentName}`;
|
|
240
|
+
return ctx.getSync<RepositoryComponent>(componentKey);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Bind all model classes provided by a component.
|
|
246
|
+
* @param component
|
|
247
|
+
* @internal
|
|
248
|
+
*/
|
|
249
|
+
mountComponentModels(component: RepositoryComponent) {
|
|
250
|
+
if (!component.models) return;
|
|
251
|
+
for (const m of component.models) {
|
|
252
|
+
this.model(m);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Update or recreate the database schema for all repositories.
|
|
258
|
+
*
|
|
259
|
+
* **WARNING**: By default, `migrateSchema()` will attempt to preserve data
|
|
260
|
+
* while updating the schema in your target database, but this is not
|
|
261
|
+
* guaranteed to be safe.
|
|
262
|
+
*
|
|
263
|
+
* Please check the documentation for your specific connector(s) for
|
|
264
|
+
* a detailed breakdown of behaviors for automigrate!
|
|
265
|
+
*
|
|
266
|
+
* @param options - Migration options, e.g. whether to update tables
|
|
267
|
+
* preserving data or rebuild everything from scratch.
|
|
268
|
+
*/
|
|
269
|
+
async migrateSchema(options: SchemaMigrationOptions = {}): Promise<void> {
|
|
270
|
+
const operation =
|
|
271
|
+
options.existingSchema === 'drop' ? 'automigrate' : 'autoupdate';
|
|
272
|
+
|
|
273
|
+
// Instantiate all repositories to ensure models are registered & attached
|
|
274
|
+
// to their datasources
|
|
275
|
+
const repoBindings: Readonly<Binding<unknown>>[] =
|
|
276
|
+
this.findByTag('repository');
|
|
277
|
+
await Promise.all(repoBindings.map(b => this.get(b.key)));
|
|
278
|
+
|
|
279
|
+
// Look up all datasources and update/migrate schemas one by one
|
|
280
|
+
const dsBindings: Readonly<Binding<object>>[] = this.findByTag(
|
|
281
|
+
RepositoryTags.DATASOURCE,
|
|
282
|
+
);
|
|
283
|
+
for (const b of dsBindings) {
|
|
284
|
+
const ds = await this.get<juggler.DataSource>(b.key);
|
|
285
|
+
const disableMigration = ds.settings.disableMigration ?? false;
|
|
286
|
+
|
|
287
|
+
if (
|
|
288
|
+
operation in ds &&
|
|
289
|
+
typeof ds[operation] === 'function' &&
|
|
290
|
+
!disableMigration
|
|
291
|
+
) {
|
|
292
|
+
debug('Migrating dataSource %s', b.key);
|
|
293
|
+
await ds[operation](options.models);
|
|
294
|
+
} else {
|
|
295
|
+
debug('Skipping migration of dataSource %s', b.key);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* This interface describes additional Component properties
|
|
304
|
+
* allowing components to contribute Repository-related artifacts.
|
|
305
|
+
*/
|
|
306
|
+
export interface RepositoryComponent {
|
|
307
|
+
/**
|
|
308
|
+
* An optional list of Repository classes to bind for dependency injection
|
|
309
|
+
* via `app.repository()` API.
|
|
310
|
+
*/
|
|
311
|
+
repositories?: Class<Repository<Model>>[];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* An optional list of Model classes to bind for dependency injection
|
|
315
|
+
* via `app.model()` API.
|
|
316
|
+
*/
|
|
317
|
+
models?: Class<Model>[];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Normalize name or options to `BindingFromClassOptions`
|
|
322
|
+
* @param nameOrOptions - Name or options for binding from class
|
|
323
|
+
*/
|
|
324
|
+
function toOptions(nameOrOptions?: string | BindingFromClassOptions) {
|
|
325
|
+
if (typeof nameOrOptions === 'string') {
|
|
326
|
+
return {name: nameOrOptions};
|
|
327
|
+
}
|
|
328
|
+
return nameOrOptions ?? {};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Interface for an Application mixed in with RepositoryMixin
|
|
333
|
+
*/
|
|
334
|
+
export interface ApplicationWithRepositories extends Application {
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
336
|
+
repository<R extends Repository<any>>(
|
|
337
|
+
repo: Class<R>,
|
|
338
|
+
name?: string,
|
|
339
|
+
): Binding<R>;
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
|
+
getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R>;
|
|
342
|
+
dataSource<D extends juggler.DataSource>(
|
|
343
|
+
dataSource: Class<D> | D,
|
|
344
|
+
name?: string,
|
|
345
|
+
): Binding<D>;
|
|
346
|
+
model<M extends Class<unknown>>(modelClass: M): Binding<M>;
|
|
347
|
+
component(component: Class<unknown>, name?: string): Binding;
|
|
348
|
+
mountComponentRepositories(component: Class<unknown>): void;
|
|
349
|
+
migrateSchema(options?: SchemaMigrationOptions): Promise<void>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* A dummy class created to generate the tsdoc for the members in repository
|
|
354
|
+
* mixin. Please don't use it.
|
|
355
|
+
*
|
|
356
|
+
* The members are implemented in function
|
|
357
|
+
* <a href="#RepositoryMixin">RepositoryMixin</a>
|
|
358
|
+
*/
|
|
359
|
+
export class RepositoryMixinDoc {
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
361
|
+
constructor(...args: any[]) {
|
|
362
|
+
throw new Error(
|
|
363
|
+
'This is a dummy class created for apidoc!' + 'Please do not use it!',
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Add a repository to this application.
|
|
369
|
+
*
|
|
370
|
+
* @param repo - The repository to add.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
*
|
|
375
|
+
* class NoteRepo {
|
|
376
|
+
* model: any;
|
|
377
|
+
*
|
|
378
|
+
* constructor() {
|
|
379
|
+
* const ds: juggler.DataSource = new juggler.DataSource({
|
|
380
|
+
* name: 'db',
|
|
381
|
+
* connector: 'memory',
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* this.model = ds.createModel(
|
|
385
|
+
* 'note',
|
|
386
|
+
* {title: 'string', content: 'string'},
|
|
387
|
+
* {}
|
|
388
|
+
* );
|
|
389
|
+
* }
|
|
390
|
+
* };
|
|
391
|
+
*
|
|
392
|
+
* app.repository(NoteRepo);
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
396
|
+
repository(repo: Class<Repository<any>>): Binding {
|
|
397
|
+
throw new Error();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Retrieve the repository instance from the given Repository class
|
|
402
|
+
*
|
|
403
|
+
* @param repo - The repository class to retrieve the instance of
|
|
404
|
+
*/
|
|
405
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
406
|
+
async getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R> {
|
|
407
|
+
return new repo() as R;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Add the dataSource to this application.
|
|
412
|
+
*
|
|
413
|
+
* @param dataSource - The dataSource to add.
|
|
414
|
+
* @param name - The binding name of the datasource; defaults to dataSource.name
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
*
|
|
419
|
+
* const ds: juggler.DataSource = new juggler.DataSource({
|
|
420
|
+
* name: 'db',
|
|
421
|
+
* connector: 'memory',
|
|
422
|
+
* });
|
|
423
|
+
*
|
|
424
|
+
* app.dataSource(ds);
|
|
425
|
+
*
|
|
426
|
+
* // The datasource can be injected with
|
|
427
|
+
* constructor(@inject('datasources.db') dataSource: DataSourceType) {
|
|
428
|
+
*
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
dataSource(
|
|
433
|
+
dataSource: Class<juggler.DataSource> | juggler.DataSource,
|
|
434
|
+
name?: string,
|
|
435
|
+
): Binding {
|
|
436
|
+
throw new Error();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Add a component to this application. Also mounts
|
|
441
|
+
* all the components repositories.
|
|
442
|
+
*
|
|
443
|
+
* @param component - The component to add.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
*
|
|
448
|
+
* export class ProductComponent {
|
|
449
|
+
* controllers = [ProductController];
|
|
450
|
+
* repositories = [ProductRepo, UserRepo];
|
|
451
|
+
* providers = {
|
|
452
|
+
* [AUTHENTICATION_STRATEGY]: AuthStrategy,
|
|
453
|
+
* [AUTHORIZATION_ROLE]: Role,
|
|
454
|
+
* };
|
|
455
|
+
* };
|
|
456
|
+
*
|
|
457
|
+
* app.component(ProductComponent);
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
public component(component: Class<{}>): Binding {
|
|
461
|
+
throw new Error();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Get an instance of a component and mount all it's
|
|
466
|
+
* repositories. This function is intended to be used internally
|
|
467
|
+
* by component()
|
|
468
|
+
*
|
|
469
|
+
* @param component - The component to mount repositories of
|
|
470
|
+
*/
|
|
471
|
+
mountComponentRepository(component: Class<{}>) {}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Update or recreate the database schema for all repositories.
|
|
475
|
+
*
|
|
476
|
+
* **WARNING**: By default, `migrateSchema()` will attempt to preserve data
|
|
477
|
+
* while updating the schema in your target database, but this is not
|
|
478
|
+
* guaranteed to be safe.
|
|
479
|
+
*
|
|
480
|
+
* Please check the documentation for your specific connector(s) for
|
|
481
|
+
* a detailed breakdown of behaviors for automigrate!
|
|
482
|
+
*
|
|
483
|
+
* @param options - Migration options, e.g. whether to update tables
|
|
484
|
+
* preserving data or rebuild everything from scratch.
|
|
485
|
+
*/
|
|
486
|
+
async migrateSchema(options?: SchemaMigrationOptions): Promise<void> {}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Create a binding for the given model class
|
|
491
|
+
* @param modelClass - Model class
|
|
492
|
+
*/
|
|
493
|
+
export function createModelClassBinding<M extends Class<unknown>>(
|
|
494
|
+
modelClass: M,
|
|
495
|
+
) {
|
|
496
|
+
return Binding.bind<M>(`${RepositoryBindings.MODELS}.${modelClass.name}`)
|
|
497
|
+
.to(modelClass)
|
|
498
|
+
.tag(RepositoryTags.MODEL);
|
|
499
|
+
}
|