@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 @@
|
|
|
1
|
+
{"version":3,"file":"belongs-to.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAMhE,0DAK6B;AAM7B,6DAA8D;AAE9D;;;;;;;;;GASG;AACH,SAAgB,gCAAgC,CAK9C,IAAyB,EACzB,aAEC;IAED,MAAM,YAAY,GAAG,IAAA,6CAAwB,EAAC,IAAI,CAAC,CAAC;IAEpD,OAAO,KAAK,UAAU,mBAAmB,CACvC,QAAkB,EAClB,SAA0B,EAC1B,OAAiB;QAEjB,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAEhC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,KAA4B,CAAC;QAC5D,MAAM,gBAAgB,GAAG,IAAA,8BAAW,EAAC,SAAS,CAAC,CAAC;QAEhD,MAAM,KAAK,GACT,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,SAAS,CAAC,KAAwB,CAAC;QAE3E,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;QACzC,MAAM,YAAY,GAAG,MAAM,IAAA,oCAAiB,EAC1C,UAAU,EACV,SAAS,EACT,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAC/B,KAAK,EACL,OAAO,CACR,CAAC;QAEF,OAAO,IAAA,mDAAgC,EAAC,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC;AAtCD,4EAsCC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Getter } from '@loopback/core';
|
|
2
|
+
import { DataObject, Options } from '../../common-types';
|
|
3
|
+
import { Entity } from '../../model';
|
|
4
|
+
import { EntityCrudRepository } from '../../repositories';
|
|
5
|
+
/**
|
|
6
|
+
* CRUD operations for a target repository of a BelongsTo relation
|
|
7
|
+
*/
|
|
8
|
+
export interface BelongsToRepository<Target extends Entity> {
|
|
9
|
+
/**
|
|
10
|
+
* Gets the target model instance
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns A promise resolved with the target object or rejected
|
|
13
|
+
* with an EntityNotFoundError when target model instance was not found.
|
|
14
|
+
*/
|
|
15
|
+
get(options?: Options): Promise<Target>;
|
|
16
|
+
}
|
|
17
|
+
export declare class DefaultBelongsToRepository<TargetEntity extends Entity, TargetId, TargetRepository extends EntityCrudRepository<TargetEntity, TargetId>> implements BelongsToRepository<TargetEntity> {
|
|
18
|
+
getTargetRepository: Getter<TargetRepository>;
|
|
19
|
+
constraint: DataObject<TargetEntity>;
|
|
20
|
+
/**
|
|
21
|
+
* Constructor of DefaultBelongsToEntityCrudRepository
|
|
22
|
+
* @param getTargetRepository - the getter of the related target model repository instance
|
|
23
|
+
* @param constraint - the key value pair representing foreign key name to constrain
|
|
24
|
+
* the target repository instance
|
|
25
|
+
*/
|
|
26
|
+
constructor(getTargetRepository: Getter<TargetRepository>, constraint: DataObject<TargetEntity>);
|
|
27
|
+
get(options?: Options): Promise<TargetEntity>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DefaultBelongsToRepository = void 0;
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const repositories_1 = require("../../repositories");
|
|
10
|
+
class DefaultBelongsToRepository {
|
|
11
|
+
/**
|
|
12
|
+
* Constructor of DefaultBelongsToEntityCrudRepository
|
|
13
|
+
* @param getTargetRepository - the getter of the related target model repository instance
|
|
14
|
+
* @param constraint - the key value pair representing foreign key name to constrain
|
|
15
|
+
* the target repository instance
|
|
16
|
+
*/
|
|
17
|
+
constructor(getTargetRepository, constraint) {
|
|
18
|
+
this.getTargetRepository = getTargetRepository;
|
|
19
|
+
this.constraint = constraint;
|
|
20
|
+
}
|
|
21
|
+
async get(options) {
|
|
22
|
+
const targetRepo = await this.getTargetRepository();
|
|
23
|
+
const result = await targetRepo.find((0, repositories_1.constrainFilter)(undefined, this.constraint), options);
|
|
24
|
+
if (!result.length) {
|
|
25
|
+
// We don't have a direct access to the foreign key value here :(
|
|
26
|
+
const id = 'constraint ' + JSON.stringify(this.constraint);
|
|
27
|
+
throw new errors_1.EntityNotFoundError(targetRepo.entityClass, id);
|
|
28
|
+
}
|
|
29
|
+
return result[0];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.DefaultBelongsToRepository = DefaultBelongsToRepository;
|
|
33
|
+
//# sourceMappingURL=belongs-to.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongs-to.repository.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.repository.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAIhE,yCAAiD;AAEjD,qDAAyE;AAezE,MAAa,0BAA0B;IAMrC;;;;;OAKG;IACH,YACS,mBAA6C,EAC7C,UAAoC;QADpC,wBAAmB,GAAnB,mBAAmB,CAA0B;QAC7C,eAAU,GAAV,UAAU,CAA0B;IAC1C,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,OAAiB;QACzB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAClC,IAAA,8BAAe,EAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,EAC3C,OAAO,CACR,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,iEAAiE;YACjE,MAAM,EAAE,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3D,MAAM,IAAI,4BAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;SAC3D;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;CACF;AA9BD,gEA8BC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./belongs-to.decorator"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./belongs-to.repository"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./belongs-to.accessor"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./belongs-to.inclusion-resolver"), exports);
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,sEAAuC;AACvC,uEAAwC;AACxC,qEAAsC;AACtC,+EAAgD"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { DataObject, Entity, HasManyDefinition } from '../..';
|
|
2
|
+
export declare type HasManyThroughResolvedDefinition = HasManyDefinition & {
|
|
3
|
+
keyTo: string;
|
|
4
|
+
keyFrom: string;
|
|
5
|
+
through: {
|
|
6
|
+
keyTo: string;
|
|
7
|
+
keyFrom: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates target constraint based on through models
|
|
12
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
13
|
+
* @param throughInstances - an array of through instances
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const resolvedMetadata = {
|
|
18
|
+
* // .. other props
|
|
19
|
+
* keyFrom: 'id',
|
|
20
|
+
* keyTo: 'id',
|
|
21
|
+
* through: {
|
|
22
|
+
* model: () => CategoryProductLink,
|
|
23
|
+
* keyFrom: 'categoryId',
|
|
24
|
+
* keyTo: 'productId',
|
|
25
|
+
* },
|
|
26
|
+
* };
|
|
27
|
+
* createTargetConstraintFromThrough(resolvedMetadata,[{
|
|
28
|
+
id: 2,
|
|
29
|
+
categoryId: 2,
|
|
30
|
+
productId: 8,
|
|
31
|
+
}]);
|
|
32
|
+
* >>> {id: 8}
|
|
33
|
+
* createTargetConstraintFromThrough(resolvedMetadata, [
|
|
34
|
+
{
|
|
35
|
+
id: 2,
|
|
36
|
+
categoryId: 2,
|
|
37
|
+
productId: 8,
|
|
38
|
+
}, {
|
|
39
|
+
id: 1,
|
|
40
|
+
categoryId: 2,
|
|
41
|
+
productId: 9,
|
|
42
|
+
}
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
>>> {id: {inq: [9, 8]}}
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function createTargetConstraintFromThrough<Target extends Entity, Through extends Entity>(relationMeta: HasManyThroughResolvedDefinition, throughInstances: Through[]): DataObject<Target>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns an array of target fks of the given throughInstances.
|
|
51
|
+
*
|
|
52
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
53
|
+
* @param throughInstances - an array of through instances
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const resolvedMetadata = {
|
|
58
|
+
* // .. other props
|
|
59
|
+
* keyFrom: 'id',
|
|
60
|
+
* keyTo: 'id',
|
|
61
|
+
* through: {
|
|
62
|
+
* model: () => CategoryProductLink,
|
|
63
|
+
* keyFrom: 'categoryId',
|
|
64
|
+
* keyTo: 'productId',
|
|
65
|
+
* },
|
|
66
|
+
* };
|
|
67
|
+
* getTargetKeysFromThroughModels(resolvedMetadata,[{
|
|
68
|
+
id: 2,
|
|
69
|
+
categoryId: 2,
|
|
70
|
+
productId: 8,
|
|
71
|
+
}]);
|
|
72
|
+
* >>> [8]
|
|
73
|
+
* getTargetKeysFromThroughModels(resolvedMetadata, [
|
|
74
|
+
{
|
|
75
|
+
id: 2,
|
|
76
|
+
categoryId: 2,
|
|
77
|
+
productId: 8,
|
|
78
|
+
}, {
|
|
79
|
+
id: 1,
|
|
80
|
+
categoryId: 2,
|
|
81
|
+
productId: 9,
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
>>> [8, 9]
|
|
85
|
+
*/
|
|
86
|
+
export declare function getTargetKeysFromThroughModels<Through extends Entity, TargetID>(relationMeta: HasManyThroughResolvedDefinition, throughInstances: Through[]): TargetID[];
|
|
87
|
+
/**
|
|
88
|
+
* Creates through constraint based on the source key
|
|
89
|
+
*
|
|
90
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
91
|
+
* @param fkValue - foreign key of the source instance
|
|
92
|
+
* @internal
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const resolvedMetadata = {
|
|
97
|
+
* // .. other props
|
|
98
|
+
* keyFrom: 'id',
|
|
99
|
+
* keyTo: 'id',
|
|
100
|
+
* through: {
|
|
101
|
+
* model: () => CategoryProductLink,
|
|
102
|
+
* keyFrom: 'categoryId',
|
|
103
|
+
* keyTo: 'productId',
|
|
104
|
+
* },
|
|
105
|
+
* };
|
|
106
|
+
* createThroughConstraintFromSource(resolvedMetadata, 1);
|
|
107
|
+
*
|
|
108
|
+
* >>> {categoryId: 1}
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function createThroughConstraintFromSource<Through extends Entity, SourceID>(relationMeta: HasManyThroughResolvedDefinition, fkValue: SourceID): DataObject<Through>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns an array of target ids of the given target instances.
|
|
114
|
+
*
|
|
115
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
116
|
+
* @param targetInstances - an array of target instances
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const resolvedMetadata = {
|
|
121
|
+
* // .. other props
|
|
122
|
+
* keyFrom: 'id',
|
|
123
|
+
* keyTo: 'id',
|
|
124
|
+
* through: {
|
|
125
|
+
* model: () => CategoryProductLink,
|
|
126
|
+
* keyFrom: 'categoryId',
|
|
127
|
+
* keyTo: 'productId',
|
|
128
|
+
* },
|
|
129
|
+
* };
|
|
130
|
+
* getTargetKeysFromTargetModels(resolvedMetadata,[{
|
|
131
|
+
id: 2,
|
|
132
|
+
des: 'a target',
|
|
133
|
+
}]);
|
|
134
|
+
* >>> [2]
|
|
135
|
+
* getTargetKeysFromTargetModels(resolvedMetadata, [
|
|
136
|
+
{
|
|
137
|
+
id: 2,
|
|
138
|
+
des: 'a target',
|
|
139
|
+
}, {
|
|
140
|
+
id: 1,
|
|
141
|
+
des: 'a target',
|
|
142
|
+
}
|
|
143
|
+
]);
|
|
144
|
+
>>> [2, 1]
|
|
145
|
+
*/
|
|
146
|
+
export declare function getTargetIdsFromTargetModels<Target extends Entity, TargetID>(relationMeta: HasManyThroughResolvedDefinition, targetInstances: Target[]): TargetID[];
|
|
147
|
+
/**
|
|
148
|
+
* Creates through constraint based on the target foreign key
|
|
149
|
+
*
|
|
150
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
151
|
+
* @param fkValue an array of the target instance foreign keys
|
|
152
|
+
* @internal
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const resolvedMetadata = {
|
|
157
|
+
* // .. other props
|
|
158
|
+
* keyFrom: 'id',
|
|
159
|
+
* keyTo: 'id',
|
|
160
|
+
* through: {
|
|
161
|
+
* model: () => CategoryProductLink,
|
|
162
|
+
* keyFrom: 'categoryId',
|
|
163
|
+
* keyTo: 'productId',
|
|
164
|
+
* },
|
|
165
|
+
* };
|
|
166
|
+
* createThroughConstraintFromTarget(resolvedMetadata, [3]);
|
|
167
|
+
*
|
|
168
|
+
* >>> {productId: 3}
|
|
169
|
+
*
|
|
170
|
+
* createThroughConstraintFromTarget(resolvedMetadata, [3,4]);
|
|
171
|
+
*
|
|
172
|
+
* >>> {productId: {inq:[3,4]}}
|
|
173
|
+
*/
|
|
174
|
+
export declare function createThroughConstraintFromTarget<Through extends Entity, TargetID>(relationMeta: HasManyThroughResolvedDefinition, fkValues: TargetID[]): DataObject<Through>;
|
|
175
|
+
/**
|
|
176
|
+
* Resolves given hasMany metadata if target is specified to be a resolver.
|
|
177
|
+
* Mainly used to infer what the `keyTo` property should be from the target's
|
|
178
|
+
* belongsTo metadata
|
|
179
|
+
* @param relationMeta - hasManyThrough metadata to resolve
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
export declare function resolveHasManyThroughMetadata(relationMeta: HasManyDefinition): HasManyThroughResolvedDefinition;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveHasManyThroughMetadata = exports.createThroughConstraintFromTarget = exports.getTargetIdsFromTargetModels = exports.createThroughConstraintFromSource = exports.getTargetKeysFromThroughModels = exports.createTargetConstraintFromThrough = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const __1 = require("../..");
|
|
12
|
+
const has_many_helpers_1 = require("./has-many.helpers");
|
|
13
|
+
const debug = (0, debug_1.default)('loopback:repository:relations:has-many-through:helpers');
|
|
14
|
+
/**
|
|
15
|
+
* Creates target constraint based on through models
|
|
16
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
17
|
+
* @param throughInstances - an array of through instances
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const resolvedMetadata = {
|
|
22
|
+
* // .. other props
|
|
23
|
+
* keyFrom: 'id',
|
|
24
|
+
* keyTo: 'id',
|
|
25
|
+
* through: {
|
|
26
|
+
* model: () => CategoryProductLink,
|
|
27
|
+
* keyFrom: 'categoryId',
|
|
28
|
+
* keyTo: 'productId',
|
|
29
|
+
* },
|
|
30
|
+
* };
|
|
31
|
+
* createTargetConstraintFromThrough(resolvedMetadata,[{
|
|
32
|
+
id: 2,
|
|
33
|
+
categoryId: 2,
|
|
34
|
+
productId: 8,
|
|
35
|
+
}]);
|
|
36
|
+
* >>> {id: 8}
|
|
37
|
+
* createTargetConstraintFromThrough(resolvedMetadata, [
|
|
38
|
+
{
|
|
39
|
+
id: 2,
|
|
40
|
+
categoryId: 2,
|
|
41
|
+
productId: 8,
|
|
42
|
+
}, {
|
|
43
|
+
id: 1,
|
|
44
|
+
categoryId: 2,
|
|
45
|
+
productId: 9,
|
|
46
|
+
}
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
>>> {id: {inq: [9, 8]}}
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function createTargetConstraintFromThrough(relationMeta, throughInstances) {
|
|
53
|
+
const fkValues = getTargetKeysFromThroughModels(relationMeta, throughInstances);
|
|
54
|
+
const targetPrimaryKey = relationMeta.keyTo;
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
const constraint = {
|
|
57
|
+
[targetPrimaryKey]: fkValues.length === 1 ? fkValues[0] : { inq: fkValues },
|
|
58
|
+
};
|
|
59
|
+
return constraint;
|
|
60
|
+
}
|
|
61
|
+
exports.createTargetConstraintFromThrough = createTargetConstraintFromThrough;
|
|
62
|
+
/**
|
|
63
|
+
* Returns an array of target fks of the given throughInstances.
|
|
64
|
+
*
|
|
65
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
66
|
+
* @param throughInstances - an array of through instances
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const resolvedMetadata = {
|
|
71
|
+
* // .. other props
|
|
72
|
+
* keyFrom: 'id',
|
|
73
|
+
* keyTo: 'id',
|
|
74
|
+
* through: {
|
|
75
|
+
* model: () => CategoryProductLink,
|
|
76
|
+
* keyFrom: 'categoryId',
|
|
77
|
+
* keyTo: 'productId',
|
|
78
|
+
* },
|
|
79
|
+
* };
|
|
80
|
+
* getTargetKeysFromThroughModels(resolvedMetadata,[{
|
|
81
|
+
id: 2,
|
|
82
|
+
categoryId: 2,
|
|
83
|
+
productId: 8,
|
|
84
|
+
}]);
|
|
85
|
+
* >>> [8]
|
|
86
|
+
* getTargetKeysFromThroughModels(resolvedMetadata, [
|
|
87
|
+
{
|
|
88
|
+
id: 2,
|
|
89
|
+
categoryId: 2,
|
|
90
|
+
productId: 8,
|
|
91
|
+
}, {
|
|
92
|
+
id: 1,
|
|
93
|
+
categoryId: 2,
|
|
94
|
+
productId: 9,
|
|
95
|
+
}
|
|
96
|
+
]);
|
|
97
|
+
>>> [8, 9]
|
|
98
|
+
*/
|
|
99
|
+
function getTargetKeysFromThroughModels(relationMeta, throughInstances) {
|
|
100
|
+
const targetFkName = relationMeta.through.keyTo;
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
let fkValues = throughInstances.map((throughInstance) => throughInstance[targetFkName]);
|
|
103
|
+
fkValues = (0, __1.deduplicate)(fkValues);
|
|
104
|
+
return fkValues;
|
|
105
|
+
}
|
|
106
|
+
exports.getTargetKeysFromThroughModels = getTargetKeysFromThroughModels;
|
|
107
|
+
/**
|
|
108
|
+
* Creates through constraint based on the source key
|
|
109
|
+
*
|
|
110
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
111
|
+
* @param fkValue - foreign key of the source instance
|
|
112
|
+
* @internal
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const resolvedMetadata = {
|
|
117
|
+
* // .. other props
|
|
118
|
+
* keyFrom: 'id',
|
|
119
|
+
* keyTo: 'id',
|
|
120
|
+
* through: {
|
|
121
|
+
* model: () => CategoryProductLink,
|
|
122
|
+
* keyFrom: 'categoryId',
|
|
123
|
+
* keyTo: 'productId',
|
|
124
|
+
* },
|
|
125
|
+
* };
|
|
126
|
+
* createThroughConstraintFromSource(resolvedMetadata, 1);
|
|
127
|
+
*
|
|
128
|
+
* >>> {categoryId: 1}
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
function createThroughConstraintFromSource(relationMeta, fkValue) {
|
|
132
|
+
const sourceFkName = relationMeta.through.keyFrom;
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
const constraint = { [sourceFkName]: fkValue };
|
|
135
|
+
return constraint;
|
|
136
|
+
}
|
|
137
|
+
exports.createThroughConstraintFromSource = createThroughConstraintFromSource;
|
|
138
|
+
/**
|
|
139
|
+
* Returns an array of target ids of the given target instances.
|
|
140
|
+
*
|
|
141
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
142
|
+
* @param targetInstances - an array of target instances
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const resolvedMetadata = {
|
|
147
|
+
* // .. other props
|
|
148
|
+
* keyFrom: 'id',
|
|
149
|
+
* keyTo: 'id',
|
|
150
|
+
* through: {
|
|
151
|
+
* model: () => CategoryProductLink,
|
|
152
|
+
* keyFrom: 'categoryId',
|
|
153
|
+
* keyTo: 'productId',
|
|
154
|
+
* },
|
|
155
|
+
* };
|
|
156
|
+
* getTargetKeysFromTargetModels(resolvedMetadata,[{
|
|
157
|
+
id: 2,
|
|
158
|
+
des: 'a target',
|
|
159
|
+
}]);
|
|
160
|
+
* >>> [2]
|
|
161
|
+
* getTargetKeysFromTargetModels(resolvedMetadata, [
|
|
162
|
+
{
|
|
163
|
+
id: 2,
|
|
164
|
+
des: 'a target',
|
|
165
|
+
}, {
|
|
166
|
+
id: 1,
|
|
167
|
+
des: 'a target',
|
|
168
|
+
}
|
|
169
|
+
]);
|
|
170
|
+
>>> [2, 1]
|
|
171
|
+
*/
|
|
172
|
+
function getTargetIdsFromTargetModels(relationMeta, targetInstances) {
|
|
173
|
+
const targetId = relationMeta.keyTo;
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
+
let ids = [];
|
|
176
|
+
ids = targetInstances.map((targetInstance) => targetInstance[targetId]);
|
|
177
|
+
ids = (0, __1.deduplicate)(ids);
|
|
178
|
+
return ids;
|
|
179
|
+
}
|
|
180
|
+
exports.getTargetIdsFromTargetModels = getTargetIdsFromTargetModels;
|
|
181
|
+
/**
|
|
182
|
+
* Creates through constraint based on the target foreign key
|
|
183
|
+
*
|
|
184
|
+
* @param relationMeta - resolved hasManyThrough metadata
|
|
185
|
+
* @param fkValue an array of the target instance foreign keys
|
|
186
|
+
* @internal
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const resolvedMetadata = {
|
|
191
|
+
* // .. other props
|
|
192
|
+
* keyFrom: 'id',
|
|
193
|
+
* keyTo: 'id',
|
|
194
|
+
* through: {
|
|
195
|
+
* model: () => CategoryProductLink,
|
|
196
|
+
* keyFrom: 'categoryId',
|
|
197
|
+
* keyTo: 'productId',
|
|
198
|
+
* },
|
|
199
|
+
* };
|
|
200
|
+
* createThroughConstraintFromTarget(resolvedMetadata, [3]);
|
|
201
|
+
*
|
|
202
|
+
* >>> {productId: 3}
|
|
203
|
+
*
|
|
204
|
+
* createThroughConstraintFromTarget(resolvedMetadata, [3,4]);
|
|
205
|
+
*
|
|
206
|
+
* >>> {productId: {inq:[3,4]}}
|
|
207
|
+
*/
|
|
208
|
+
function createThroughConstraintFromTarget(relationMeta, fkValues) {
|
|
209
|
+
if (fkValues === undefined || fkValues.length === 0) {
|
|
210
|
+
throw new Error('"fkValue" must be provided');
|
|
211
|
+
}
|
|
212
|
+
const targetFkName = relationMeta.through.keyTo;
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
214
|
+
const constraint = fkValues.length === 1
|
|
215
|
+
? { [targetFkName]: fkValues[0] }
|
|
216
|
+
: { [targetFkName]: { inq: fkValues } };
|
|
217
|
+
return constraint;
|
|
218
|
+
}
|
|
219
|
+
exports.createThroughConstraintFromTarget = createThroughConstraintFromTarget;
|
|
220
|
+
/**
|
|
221
|
+
* Resolves given hasMany metadata if target is specified to be a resolver.
|
|
222
|
+
* Mainly used to infer what the `keyTo` property should be from the target's
|
|
223
|
+
* belongsTo metadata
|
|
224
|
+
* @param relationMeta - hasManyThrough metadata to resolve
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
function resolveHasManyThroughMetadata(relationMeta) {
|
|
228
|
+
var _a, _b, _c, _d, _e, _f;
|
|
229
|
+
// some checks and relationMeta.keyFrom are handled in here
|
|
230
|
+
relationMeta = (0, has_many_helpers_1.resolveHasManyMetaHelper)(relationMeta);
|
|
231
|
+
if (!relationMeta.through) {
|
|
232
|
+
const reason = 'through must be specified';
|
|
233
|
+
throw new __1.InvalidRelationError(reason, relationMeta);
|
|
234
|
+
}
|
|
235
|
+
if (!(0, __1.isTypeResolver)((_a = relationMeta.through) === null || _a === void 0 ? void 0 : _a.model)) {
|
|
236
|
+
const reason = 'through.model must be a type resolver';
|
|
237
|
+
throw new __1.InvalidRelationError(reason, relationMeta);
|
|
238
|
+
}
|
|
239
|
+
const throughModel = relationMeta.through.model();
|
|
240
|
+
const throughModelProperties = (_b = throughModel.definition) === null || _b === void 0 ? void 0 : _b.properties;
|
|
241
|
+
const targetModel = relationMeta.target();
|
|
242
|
+
const targetModelProperties = (_c = targetModel.definition) === null || _c === void 0 ? void 0 : _c.properties;
|
|
243
|
+
// check if metadata is already complete
|
|
244
|
+
if (relationMeta.through.keyTo &&
|
|
245
|
+
throughModelProperties[relationMeta.through.keyTo] &&
|
|
246
|
+
relationMeta.through.keyFrom &&
|
|
247
|
+
throughModelProperties[relationMeta.through.keyFrom] &&
|
|
248
|
+
relationMeta.keyTo &&
|
|
249
|
+
targetModelProperties[relationMeta.keyTo]) {
|
|
250
|
+
// The explicit cast is needed because of a limitation of type inference
|
|
251
|
+
return relationMeta;
|
|
252
|
+
}
|
|
253
|
+
const sourceModel = relationMeta.source;
|
|
254
|
+
debug('Resolved model %s from given metadata: %o', targetModel.modelName, targetModel);
|
|
255
|
+
debug('Resolved model %s from given metadata: %o', throughModel.modelName, throughModel);
|
|
256
|
+
const sourceFkName = (_d = relationMeta.through.keyFrom) !== null && _d !== void 0 ? _d : (0, lodash_1.camelCase)(sourceModel.modelName + '_id');
|
|
257
|
+
if (!throughModelProperties[sourceFkName]) {
|
|
258
|
+
const reason = `through model ${throughModel.name} is missing definition of source foreign key`;
|
|
259
|
+
throw new __1.InvalidRelationError(reason, relationMeta);
|
|
260
|
+
}
|
|
261
|
+
const targetFkName = (_e = relationMeta.through.keyTo) !== null && _e !== void 0 ? _e : (0, lodash_1.camelCase)(targetModel.modelName + '_id');
|
|
262
|
+
if (!throughModelProperties[targetFkName]) {
|
|
263
|
+
const reason = `through model ${throughModel.name} is missing definition of target foreign key`;
|
|
264
|
+
throw new __1.InvalidRelationError(reason, relationMeta);
|
|
265
|
+
}
|
|
266
|
+
const targetPrimaryKey = (_f = relationMeta.keyTo) !== null && _f !== void 0 ? _f : targetModel.definition.idProperties()[0];
|
|
267
|
+
if (!targetPrimaryKey || !targetModelProperties[targetPrimaryKey]) {
|
|
268
|
+
const reason = `target model ${targetModel.modelName} does not have any primary key (id property)`;
|
|
269
|
+
throw new __1.InvalidRelationError(reason, relationMeta);
|
|
270
|
+
}
|
|
271
|
+
return Object.assign(relationMeta, {
|
|
272
|
+
keyTo: targetPrimaryKey,
|
|
273
|
+
keyFrom: relationMeta.keyFrom,
|
|
274
|
+
through: {
|
|
275
|
+
...relationMeta.through,
|
|
276
|
+
keyTo: targetFkName,
|
|
277
|
+
keyFrom: sourceFkName,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
exports.resolveHasManyThroughMetadata = resolveHasManyThroughMetadata;
|
|
282
|
+
//# sourceMappingURL=has-many-through.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-many-through.helpers.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.helpers.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAiC;AACjC,mCAAiC;AACjC,6BAOe;AACf,yDAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,eAAY,EACxB,wDAAwD,CACzD,CAAC;AAWF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,iCAAiC,CAI/C,YAA8C,EAC9C,gBAA2B;IAE3B,MAAM,QAAQ,GAAG,8BAA8B,CAC7C,YAAY,EACZ,gBAAgB,CACjB,CAAC;IACF,MAAM,gBAAgB,GAAG,YAAY,CAAC,KAAK,CAAC;IAE5C,8DAA8D;IAC9D,MAAM,UAAU,GAAQ;QACtB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,QAAQ,EAAC;KAC1E,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAlB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,CAAC;IACjE,IAAI,CAAC,gBAAgB,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,EAAE;QACjE,MAAM,MAAM,GAAG,gBAAgB,WAAW,CAAC,SAAS,8CAA8C,CAAC;QACnG,MAAM,IAAI,wBAAoB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;KACtD;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;QACjC,KAAK,EAAE,gBAAgB;QACvB,OAAO,EAAE,YAAY,CAAC,OAAQ;QAC9B,OAAO,EAAE;YACP,GAAG,YAAY,CAAC,OAAO;YACvB,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,YAAY;SACtB;KACF,CAAC,CAAC;AACL,CAAC;AA9ED,sEA8EC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Entity } from '../../model';
|
|
2
|
+
import { EntityCrudRepository } from '../../repositories';
|
|
3
|
+
import { Getter, HasManyDefinition, InclusionResolver } from '../relation.types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates InclusionResolver for HasManyThrough relation.
|
|
6
|
+
* Notice that this function only generates the inclusionResolver.
|
|
7
|
+
* It doesn't register it for the source repository.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @param meta - metadata of the hasMany relation (including through)
|
|
11
|
+
* @param getThroughRepo - through repository getter i.e. where through
|
|
12
|
+
* instances are
|
|
13
|
+
* @param getTargetRepo - target repository getter i.e where target instances
|
|
14
|
+
* are
|
|
15
|
+
*/
|
|
16
|
+
export declare function createHasManyThroughInclusionResolver<Through extends Entity, ThroughID, ThroughRelations extends object, Target extends Entity, TargetID, TargetRelations extends object>(meta: HasManyDefinition, getThroughRepo: Getter<EntityCrudRepository<Through, ThroughID, ThroughRelations>>, getTargetRepo: Getter<EntityCrudRepository<Target, TargetID, TargetRelations>>): InclusionResolver<Entity, Target>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createHasManyThroughInclusionResolver = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
10
|
+
const relation_helpers_1 = require("../relation.helpers");
|
|
11
|
+
const has_many_helpers_1 = require("./has-many.helpers");
|
|
12
|
+
const debug = (0, debug_1.default)('loopback:repository:relations:has-many-through:inclusion-resolver');
|
|
13
|
+
/**
|
|
14
|
+
* Creates InclusionResolver for HasManyThrough relation.
|
|
15
|
+
* Notice that this function only generates the inclusionResolver.
|
|
16
|
+
* It doesn't register it for the source repository.
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @param meta - metadata of the hasMany relation (including through)
|
|
20
|
+
* @param getThroughRepo - through repository getter i.e. where through
|
|
21
|
+
* instances are
|
|
22
|
+
* @param getTargetRepo - target repository getter i.e where target instances
|
|
23
|
+
* are
|
|
24
|
+
*/
|
|
25
|
+
function createHasManyThroughInclusionResolver(meta, getThroughRepo, getTargetRepo) {
|
|
26
|
+
const relationMeta = (0, has_many_helpers_1.resolveHasManyMetadata)(meta);
|
|
27
|
+
return async function fetchHasManyThroughModels(entities, inclusion, options) {
|
|
28
|
+
if (!entities.length)
|
|
29
|
+
return [];
|
|
30
|
+
debug('Fetching target models for entities:', entities);
|
|
31
|
+
debug('Relation metadata:', relationMeta);
|
|
32
|
+
const sourceKey = relationMeta.keyFrom;
|
|
33
|
+
const sourceIds = entities.map(e => e[sourceKey]);
|
|
34
|
+
const targetKey = relationMeta.keyTo;
|
|
35
|
+
if (!relationMeta.through) {
|
|
36
|
+
throw new Error(`relationMeta.through must be defined on ${relationMeta}`);
|
|
37
|
+
}
|
|
38
|
+
const throughKeyTo = relationMeta.through.keyTo;
|
|
39
|
+
const throughKeyFrom = relationMeta.through.keyFrom;
|
|
40
|
+
debug('Parameters:', {
|
|
41
|
+
sourceKey,
|
|
42
|
+
sourceIds,
|
|
43
|
+
targetKey,
|
|
44
|
+
throughKeyTo,
|
|
45
|
+
throughKeyFrom,
|
|
46
|
+
});
|
|
47
|
+
debug('sourceId types', sourceIds.map(i => typeof i));
|
|
48
|
+
const throughRepo = await getThroughRepo();
|
|
49
|
+
const targetRepo = await getTargetRepo();
|
|
50
|
+
// find through models
|
|
51
|
+
const throughFound = await (0, relation_helpers_1.findByForeignKeys)(throughRepo, throughKeyFrom, sourceIds, {}, // scope will be applied at the target level
|
|
52
|
+
options);
|
|
53
|
+
const throughResult = (0, relation_helpers_1.flattenTargetsOfOneToManyRelation)(sourceIds, throughFound, throughKeyFrom);
|
|
54
|
+
const result = [];
|
|
55
|
+
const scope = typeof inclusion === 'string' ? {} : inclusion.scope;
|
|
56
|
+
// convert from through entities to the target entities
|
|
57
|
+
for (const entityList of throughResult) {
|
|
58
|
+
if (entityList) {
|
|
59
|
+
// get target ids from the through entities by foreign key
|
|
60
|
+
const targetIds = entityList.map(entity => entity[throughKeyTo]);
|
|
61
|
+
// the explicit types and casts are needed
|
|
62
|
+
const targetEntityList = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, targetIds, scope, {
|
|
63
|
+
...options,
|
|
64
|
+
isThroughModelInclude: true,
|
|
65
|
+
});
|
|
66
|
+
result.push(targetEntityList);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// no entities found, add undefined to results
|
|
70
|
+
result.push(entityList);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
debug('fetchHasManyThroughModels result', result);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exports.createHasManyThroughInclusionResolver = createHasManyThroughInclusionResolver;
|
|
78
|
+
//# sourceMappingURL=has-many-through.inclusion-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-many-through.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,+DAAiC;AAIjC,0DAI6B;AAE7B,yDAA0D;AAE1D,MAAM,KAAK,GAAG,IAAA,eAAY,EACxB,mEAAmE,CACpE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,SAAgB,qCAAqC,CAQnD,IAAuB,EACvB,cAEC,EACD,aAEC;IAED,MAAM,YAAY,GAAG,IAAA,yCAAsB,EAAC,IAAI,CAAC,CAAC;IAElD,OAAO,KAAK,UAAU,yBAAyB,CAC7C,QAAkB,EAClB,SAA0B,EAC1B,OAAiB;QAEjB,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAEhC,KAAK,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAC;QACxD,KAAK,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;QAE1C,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,KAA4B,CAAC;QAC5D,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YACzB,MAAM,IAAI,KAAK,CACb,2CAA2C,YAAY,EAAE,CAC1D,CAAC;SACH;QACD,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,KAA6B,CAAC;QACxE,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,OAA+B,CAAC;QAE5E,KAAK,CAAC,aAAa,EAAE;YACnB,SAAS;YACT,SAAS;YACT,SAAS;YACT,YAAY;YACZ,cAAc;SACf,CAAC,CAAC;QAEH,KAAK,C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