@loopback/repository 4.0.0-alpha.9 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +93 -389
  3. package/dist/common-types.d.ts +96 -0
  4. package/dist/common-types.js +24 -0
  5. package/dist/common-types.js.map +1 -0
  6. package/dist/connectors/connector.d.ts +48 -0
  7. package/{lib → dist/connectors}/connector.js +1 -1
  8. package/dist/connectors/connector.js.map +1 -0
  9. package/{lib/crud-connector.d.ts → dist/connectors/crud.connector.d.ts} +51 -51
  10. package/{lib/common-types.js → dist/connectors/crud.connector.js} +2 -2
  11. package/dist/connectors/crud.connector.js.map +1 -0
  12. package/dist/connectors/index.d.ts +3 -0
  13. package/dist/connectors/index.js +11 -0
  14. package/dist/connectors/index.js.map +1 -0
  15. package/{lib6/kv-connector.d.ts → dist/connectors/kv.connector.d.ts} +28 -28
  16. package/{lib/datasource.js → dist/connectors/kv.connector.js} +2 -2
  17. package/dist/connectors/kv.connector.js.map +1 -0
  18. package/dist/datasource.d.ts +27 -0
  19. package/{lib6 → dist}/datasource.js +1 -1
  20. package/dist/datasource.js.map +1 -0
  21. package/dist/decorators/index.d.ts +3 -0
  22. package/dist/decorators/index.js +11 -0
  23. package/dist/decorators/index.js.map +1 -0
  24. package/dist/decorators/metadata.d.ts +12 -0
  25. package/dist/decorators/metadata.js +51 -0
  26. package/dist/decorators/metadata.js.map +1 -0
  27. package/dist/decorators/model.decorator.d.ts +40 -0
  28. package/dist/decorators/model.decorator.js +112 -0
  29. package/dist/decorators/model.decorator.js.map +1 -0
  30. package/dist/decorators/repository.decorator.d.ts +106 -0
  31. package/dist/decorators/repository.decorator.js +114 -0
  32. package/dist/decorators/repository.decorator.js.map +1 -0
  33. package/dist/define-model-class.d.ts +55 -0
  34. package/dist/define-model-class.js +57 -0
  35. package/dist/define-model-class.js.map +1 -0
  36. package/dist/define-repository-class.d.ts +119 -0
  37. package/dist/define-repository-class.js +98 -0
  38. package/dist/define-repository-class.js.map +1 -0
  39. package/dist/errors/entity-not-found.error.d.ts +8 -0
  40. package/dist/errors/entity-not-found.error.js +28 -0
  41. package/dist/errors/entity-not-found.error.js.map +1 -0
  42. package/dist/errors/index.d.ts +2 -0
  43. package/dist/errors/index.js +10 -0
  44. package/dist/errors/index.js.map +1 -0
  45. package/dist/errors/invalid-relation.error.d.ts +10 -0
  46. package/dist/errors/invalid-relation.error.js +28 -0
  47. package/dist/errors/invalid-relation.error.js.map +1 -0
  48. package/dist/index.d.ts +30 -0
  49. package/dist/index.js +39 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/keys.d.ts +34 -0
  52. package/dist/keys.js +44 -0
  53. package/dist/keys.js.map +1 -0
  54. package/dist/mixins/index.d.ts +1 -0
  55. package/dist/mixins/index.js +9 -0
  56. package/dist/mixins/index.js.map +1 -0
  57. package/dist/mixins/repository.mixin.d.ts +377 -0
  58. package/dist/mixins/repository.mixin.js +405 -0
  59. package/dist/mixins/repository.mixin.js.map +1 -0
  60. package/dist/model.d.ts +232 -0
  61. package/dist/model.js +367 -0
  62. package/dist/model.js.map +1 -0
  63. package/dist/relations/belongs-to/belongs-to.accessor.d.ts +17 -0
  64. package/dist/relations/belongs-to/belongs-to.accessor.js +40 -0
  65. package/dist/relations/belongs-to/belongs-to.accessor.js.map +1 -0
  66. package/dist/relations/belongs-to/belongs-to.decorator.d.ts +11 -0
  67. package/dist/relations/belongs-to/belongs-to.decorator.js +64 -0
  68. package/dist/relations/belongs-to/belongs-to.decorator.js.map +1 -0
  69. package/dist/relations/belongs-to/belongs-to.helpers.d.ts +17 -0
  70. package/dist/relations/belongs-to/belongs-to.helpers.js +63 -0
  71. package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -0
  72. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.d.ts +14 -0
  73. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +36 -0
  74. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -0
  75. package/dist/relations/belongs-to/belongs-to.repository.d.ts +28 -0
  76. package/dist/relations/belongs-to/belongs-to.repository.js +33 -0
  77. package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -0
  78. package/dist/relations/belongs-to/index.d.ts +4 -0
  79. package/dist/relations/belongs-to/index.js +12 -0
  80. package/dist/relations/belongs-to/index.js.map +1 -0
  81. package/dist/relations/has-many/has-many-through.helpers.d.ts +182 -0
  82. package/dist/relations/has-many/has-many-through.helpers.js +282 -0
  83. package/dist/relations/has-many/has-many-through.helpers.js.map +1 -0
  84. package/dist/relations/has-many/has-many-through.inclusion-resolver.d.ts +16 -0
  85. package/dist/relations/has-many/has-many-through.inclusion-resolver.js +78 -0
  86. package/dist/relations/has-many/has-many-through.inclusion-resolver.js.map +1 -0
  87. package/dist/relations/has-many/has-many-through.repository-factory.d.ts +17 -0
  88. package/dist/relations/has-many/has-many-through.repository-factory.js +37 -0
  89. package/dist/relations/has-many/has-many-through.repository-factory.js.map +1 -0
  90. package/dist/relations/has-many/has-many-through.repository.d.ts +114 -0
  91. package/dist/relations/has-many/has-many-through.repository.js +103 -0
  92. package/dist/relations/has-many/has-many-through.repository.js.map +1 -0
  93. package/dist/relations/has-many/has-many.decorator.d.ts +11 -0
  94. package/dist/relations/has-many/has-many.decorator.js +36 -0
  95. package/dist/relations/has-many/has-many.decorator.js.map +1 -0
  96. package/dist/relations/has-many/has-many.helpers.d.ts +26 -0
  97. package/dist/relations/has-many/has-many.helpers.js +78 -0
  98. package/dist/relations/has-many/has-many.helpers.js.map +1 -0
  99. package/dist/relations/has-many/has-many.inclusion-resolver.d.ts +14 -0
  100. package/dist/relations/has-many/has-many.inclusion-resolver.js +45 -0
  101. package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -0
  102. package/dist/relations/has-many/has-many.repository-factory.d.ts +28 -0
  103. package/dist/relations/has-many/has-many.repository-factory.js +39 -0
  104. package/dist/relations/has-many/has-many.repository-factory.js.map +1 -0
  105. package/dist/relations/has-many/has-many.repository.d.ts +54 -0
  106. package/dist/relations/has-many/has-many.repository.js +38 -0
  107. package/dist/relations/has-many/has-many.repository.js.map +1 -0
  108. package/dist/relations/has-many/index.d.ts +6 -0
  109. package/dist/relations/has-many/index.js +14 -0
  110. package/dist/relations/has-many/index.js.map +1 -0
  111. package/dist/relations/has-one/has-one.decorator.d.ts +3 -0
  112. package/dist/relations/has-one/has-one.decorator.js +37 -0
  113. package/dist/relations/has-one/has-one.decorator.js.map +1 -0
  114. package/dist/relations/has-one/has-one.helpers.d.ts +17 -0
  115. package/dist/relations/has-one/has-one.helpers.js +64 -0
  116. package/dist/relations/has-one/has-one.helpers.js.map +1 -0
  117. package/dist/relations/has-one/has-one.inclusion-resolver.d.ts +14 -0
  118. package/dist/relations/has-one/has-one.inclusion-resolver.js +35 -0
  119. package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -0
  120. package/dist/relations/has-one/has-one.repository-factory.d.ts +28 -0
  121. package/dist/relations/has-one/has-one.repository-factory.js +39 -0
  122. package/dist/relations/has-one/has-one.repository-factory.js.map +1 -0
  123. package/dist/relations/has-one/has-one.repository.d.ts +53 -0
  124. package/dist/relations/has-one/has-one.repository.js +45 -0
  125. package/dist/relations/has-one/has-one.repository.js.map +1 -0
  126. package/dist/relations/has-one/index.d.ts +3 -0
  127. package/dist/relations/has-one/index.js +11 -0
  128. package/dist/relations/has-one/index.js.map +1 -0
  129. package/dist/relations/index.d.ts +6 -0
  130. package/dist/relations/index.js +14 -0
  131. package/dist/relations/index.js.map +1 -0
  132. package/dist/relations/relation.decorator.d.ts +39 -0
  133. package/dist/relations/relation.decorator.js +88 -0
  134. package/dist/relations/relation.decorator.js.map +1 -0
  135. package/dist/relations/relation.helpers.d.ts +105 -0
  136. package/dist/relations/relation.helpers.js +298 -0
  137. package/dist/relations/relation.helpers.js.map +1 -0
  138. package/dist/relations/relation.types.d.ts +142 -0
  139. package/dist/relations/relation.types.js +21 -0
  140. package/dist/relations/relation.types.js.map +1 -0
  141. package/dist/repositories/constraint-utils.d.ts +49 -0
  142. package/dist/repositories/constraint-utils.js +87 -0
  143. package/dist/repositories/constraint-utils.js.map +1 -0
  144. package/dist/repositories/index.d.ts +5 -0
  145. package/dist/repositories/index.js +13 -0
  146. package/dist/repositories/index.js.map +1 -0
  147. package/dist/repositories/kv.repository.bridge.d.ts +30 -0
  148. package/dist/repositories/kv.repository.bridge.js +76 -0
  149. package/dist/repositories/kv.repository.bridge.js.map +1 -0
  150. package/dist/repositories/kv.repository.d.ts +74 -0
  151. package/{lib/crud-connector.js → dist/repositories/kv.repository.js} +2 -2
  152. package/dist/repositories/kv.repository.js.map +1 -0
  153. package/dist/repositories/legacy-juggler-bridge.d.ts +305 -0
  154. package/dist/repositories/legacy-juggler-bridge.js +452 -0
  155. package/dist/repositories/legacy-juggler-bridge.js.map +1 -0
  156. package/dist/repositories/repository.d.ts +223 -0
  157. package/dist/repositories/repository.js +157 -0
  158. package/dist/repositories/repository.js.map +1 -0
  159. package/dist/transaction.d.ts +30 -0
  160. package/dist/transaction.js +18 -0
  161. package/dist/transaction.js.map +1 -0
  162. package/dist/type-resolver.d.ts +42 -0
  163. package/dist/type-resolver.js +61 -0
  164. package/dist/type-resolver.js.map +1 -0
  165. package/{lib → dist}/types/any.d.ts +1 -1
  166. package/{lib6 → dist}/types/any.js +3 -2
  167. package/dist/types/any.js.map +1 -0
  168. package/{lib6 → dist}/types/array.d.ts +4 -4
  169. package/{lib → dist}/types/array.js +6 -4
  170. package/dist/types/array.js.map +1 -0
  171. package/{lib → dist}/types/boolean.d.ts +1 -1
  172. package/{lib6 → dist}/types/boolean.js +3 -2
  173. package/dist/types/boolean.js.map +1 -0
  174. package/{lib6 → dist}/types/buffer.d.ts +2 -2
  175. package/{lib → dist}/types/buffer.js +8 -6
  176. package/dist/types/buffer.js.map +1 -0
  177. package/{lib → dist}/types/date.d.ts +1 -1
  178. package/{lib → dist}/types/date.js +6 -4
  179. package/dist/types/date.js.map +1 -0
  180. package/{lib → dist}/types/index.d.ts +11 -9
  181. package/dist/types/index.js +49 -0
  182. package/dist/types/index.js.map +1 -0
  183. package/{lib6 → dist}/types/model.d.ts +2 -1
  184. package/{lib6 → dist}/types/model.js +2 -2
  185. package/dist/types/model.js.map +1 -0
  186. package/dist/types/null.d.ts +12 -0
  187. package/{lib/types/boolean.js → dist/types/null.js} +12 -11
  188. package/dist/types/null.js.map +1 -0
  189. package/{lib6 → dist}/types/number.d.ts +1 -1
  190. package/{lib → dist}/types/number.js +6 -4
  191. package/dist/types/number.js.map +1 -0
  192. package/{lib → dist}/types/object.d.ts +1 -1
  193. package/{lib → dist}/types/object.js +7 -6
  194. package/dist/types/object.js.map +1 -0
  195. package/{lib → dist}/types/string.d.ts +1 -1
  196. package/{lib → dist}/types/string.js +3 -2
  197. package/dist/types/string.js.map +1 -0
  198. package/{lib6 → dist}/types/type.d.ts +7 -7
  199. package/{lib6 → dist}/types/type.js +1 -1
  200. package/dist/types/type.js.map +1 -0
  201. package/{lib → dist}/types/union.d.ts +1 -1
  202. package/{lib → dist}/types/union.js +6 -4
  203. package/dist/types/union.js.map +1 -0
  204. package/package.json +49 -33
  205. package/src/common-types.ts +123 -0
  206. package/src/connectors/connector.ts +70 -0
  207. package/src/connectors/crud.connector.ts +208 -0
  208. package/src/connectors/index.ts +8 -0
  209. package/src/connectors/kv.connector.ts +113 -0
  210. package/src/datasource.ts +37 -0
  211. package/src/decorators/index.ts +8 -0
  212. package/src/decorators/metadata.ts +84 -0
  213. package/src/decorators/model.decorator.ts +166 -0
  214. package/src/decorators/repository.decorator.ts +223 -0
  215. package/src/define-model-class.ts +90 -0
  216. package/src/define-repository-class.ts +170 -0
  217. package/src/errors/entity-not-found.error.ts +40 -0
  218. package/src/errors/index.ts +7 -0
  219. package/src/errors/invalid-relation.error.ts +39 -0
  220. package/src/index.ts +36 -0
  221. package/src/keys.ts +40 -0
  222. package/{index.d.ts → src/mixins/index.ts} +2 -2
  223. package/src/mixins/repository.mixin.ts +499 -0
  224. package/src/model.ts +539 -0
  225. package/src/relations/belongs-to/belongs-to.accessor.ts +74 -0
  226. package/src/relations/belongs-to/belongs-to.decorator.ts +81 -0
  227. package/src/relations/belongs-to/belongs-to.helpers.ts +78 -0
  228. package/src/relations/belongs-to/belongs-to.inclusion-resolver.ts +71 -0
  229. package/src/relations/belongs-to/belongs-to.repository.ts +55 -0
  230. package/src/relations/belongs-to/index.ts +9 -0
  231. package/src/relations/has-many/has-many-through.helpers.ts +361 -0
  232. package/src/relations/has-many/has-many-through.inclusion-resolver.ts +135 -0
  233. package/src/relations/has-many/has-many-through.repository-factory.ts +121 -0
  234. package/src/relations/has-many/has-many-through.repository.ts +318 -0
  235. package/src/relations/has-many/has-many.decorator.ts +38 -0
  236. package/src/relations/has-many/has-many.helpers.ts +100 -0
  237. package/src/relations/has-many/has-many.inclusion-resolver.ts +88 -0
  238. package/src/relations/has-many/has-many.repository-factory.ts +76 -0
  239. package/src/relations/has-many/has-many.repository.ts +118 -0
  240. package/src/relations/has-many/index.ts +11 -0
  241. package/src/relations/has-one/has-one.decorator.ts +40 -0
  242. package/src/relations/has-one/has-one.helpers.ts +84 -0
  243. package/src/relations/has-one/has-one.inclusion-resolver.ts +65 -0
  244. package/src/relations/has-one/has-one.repository-factory.ts +72 -0
  245. package/src/relations/has-one/has-one.repository.ts +127 -0
  246. package/src/relations/has-one/index.ts +8 -0
  247. package/src/relations/index.ts +11 -0
  248. package/src/relations/relation.decorator.ts +90 -0
  249. package/src/relations/relation.helpers.ts +364 -0
  250. package/src/relations/relation.types.ts +180 -0
  251. package/src/repositories/constraint-utils.ts +98 -0
  252. package/src/repositories/index.ts +10 -0
  253. package/src/repositories/kv.repository.bridge.ts +97 -0
  254. package/src/repositories/kv.repository.ts +87 -0
  255. package/src/repositories/legacy-juggler-bridge.ts +788 -0
  256. package/src/repositories/repository.ts +441 -0
  257. package/src/transaction.ts +39 -0
  258. package/src/type-resolver.ts +98 -0
  259. package/src/types/any.ts +38 -0
  260. package/src/types/array.ts +53 -0
  261. package/src/types/boolean.ts +35 -0
  262. package/src/types/buffer.ts +53 -0
  263. package/src/types/date.ts +61 -0
  264. package/src/types/index.ts +52 -0
  265. package/src/types/model.ts +24 -0
  266. package/src/types/null.ts +35 -0
  267. package/src/types/number.ts +42 -0
  268. package/src/types/object.ts +53 -0
  269. package/src/types/string.ts +42 -0
  270. package/src/types/type.ts +51 -0
  271. package/src/types/union.ts +55 -0
  272. package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
  273. package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
  274. package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
  275. package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
  276. package/api-docs/apple-touch-icon-precomposed.png +0 -0
  277. package/api-docs/apple-touch-icon.png +0 -0
  278. package/api-docs/css/bootstrap.min.css +0 -9
  279. package/api-docs/css/code-themes/arta.css +0 -158
  280. package/api-docs/css/code-themes/ascetic.css +0 -50
  281. package/api-docs/css/code-themes/brown_paper.css +0 -104
  282. package/api-docs/css/code-themes/brown_papersq.png +0 -0
  283. package/api-docs/css/code-themes/dark.css +0 -103
  284. package/api-docs/css/code-themes/default.css +0 -135
  285. package/api-docs/css/code-themes/far.css +0 -111
  286. package/api-docs/css/code-themes/github.css +0 -127
  287. package/api-docs/css/code-themes/googlecode.css +0 -144
  288. package/api-docs/css/code-themes/idea.css +0 -121
  289. package/api-docs/css/code-themes/ir_black.css +0 -104
  290. package/api-docs/css/code-themes/magula.css +0 -121
  291. package/api-docs/css/code-themes/monokai.css +0 -114
  292. package/api-docs/css/code-themes/pojoaque.css +0 -104
  293. package/api-docs/css/code-themes/pojoaque.jpg +0 -0
  294. package/api-docs/css/code-themes/rainbow.css +0 -114
  295. package/api-docs/css/code-themes/school_book.css +0 -111
  296. package/api-docs/css/code-themes/school_book.png +0 -0
  297. package/api-docs/css/code-themes/sl-theme.css +0 -45
  298. package/api-docs/css/code-themes/solarized_dark.css +0 -88
  299. package/api-docs/css/code-themes/solarized_light.css +0 -88
  300. package/api-docs/css/code-themes/sunburst.css +0 -158
  301. package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
  302. package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
  303. package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
  304. package/api-docs/css/code-themes/tomorrow-night.css +0 -52
  305. package/api-docs/css/code-themes/tomorrow.css +0 -49
  306. package/api-docs/css/code-themes/vs.css +0 -86
  307. package/api-docs/css/code-themes/xcode.css +0 -154
  308. package/api-docs/css/code-themes/zenburn.css +0 -115
  309. package/api-docs/css/main.css +0 -139
  310. package/api-docs/favicon.ico +0 -0
  311. package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  312. package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  313. package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  314. package/api-docs/index.html +0 -18017
  315. package/api-docs/js/main.js +0 -19
  316. package/api-docs/js/vendor/bootstrap.min.js +0 -6
  317. package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
  318. package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
  319. package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
  320. package/index.js +0 -9
  321. package/lib/common-types.d.ts +0 -44
  322. package/lib/common-types.js.map +0 -1
  323. package/lib/connector.d.ts +0 -12
  324. package/lib/connector.js.map +0 -1
  325. package/lib/crud-connector.js.map +0 -1
  326. package/lib/datasource.d.ts +0 -11
  327. package/lib/datasource.js.map +0 -1
  328. package/lib/decorators/model.d.ts +0 -17
  329. package/lib/decorators/model.js +0 -55
  330. package/lib/decorators/model.js.map +0 -1
  331. package/lib/decorators/relation.d.ts +0 -65
  332. package/lib/decorators/relation.js +0 -126
  333. package/lib/decorators/relation.js.map +0 -1
  334. package/lib/decorators/repository.d.ts +0 -61
  335. package/lib/decorators/repository.js +0 -107
  336. package/lib/decorators/repository.js.map +0 -1
  337. package/lib/index.d.ts +0 -17
  338. package/lib/index.js +0 -21
  339. package/lib/index.js.map +0 -1
  340. package/lib/kv-connector.d.ts +0 -77
  341. package/lib/kv-connector.js +0 -7
  342. package/lib/kv-connector.js.map +0 -1
  343. package/lib/kv-repository.d.ts +0 -78
  344. package/lib/kv-repository.js +0 -7
  345. package/lib/kv-repository.js.map +0 -1
  346. package/lib/legacy-juggler-bridge.d.ts +0 -53
  347. package/lib/legacy-juggler-bridge.js +0 -142
  348. package/lib/legacy-juggler-bridge.js.map +0 -1
  349. package/lib/loopback-datasource-juggler.d.ts +0 -666
  350. package/lib/loopback-datasource-juggler.js +0 -8
  351. package/lib/loopback-datasource-juggler.js.map +0 -1
  352. package/lib/mixin.d.ts +0 -43
  353. package/lib/mixin.js +0 -34
  354. package/lib/mixin.js.map +0 -1
  355. package/lib/model.d.ts +0 -137
  356. package/lib/model.js +0 -182
  357. package/lib/model.js.map +0 -1
  358. package/lib/query.d.ts +0 -112
  359. package/lib/query.js +0 -25
  360. package/lib/query.js.map +0 -1
  361. package/lib/repository-mixin.d.ts +0 -20
  362. package/lib/repository-mixin.js +0 -111
  363. package/lib/repository-mixin.js.map +0 -1
  364. package/lib/repository.d.ts +0 -172
  365. package/lib/repository.js +0 -128
  366. package/lib/repository.js.map +0 -1
  367. package/lib/types/any.js +0 -35
  368. package/lib/types/any.js.map +0 -1
  369. package/lib/types/array.d.ts +0 -14
  370. package/lib/types/array.js.map +0 -1
  371. package/lib/types/boolean.js.map +0 -1
  372. package/lib/types/buffer.d.ts +0 -14
  373. package/lib/types/buffer.js.map +0 -1
  374. package/lib/types/date.js.map +0 -1
  375. package/lib/types/index.js +0 -33
  376. package/lib/types/index.js.map +0 -1
  377. package/lib/types/model.d.ts +0 -11
  378. package/lib/types/model.js +0 -25
  379. package/lib/types/model.js.map +0 -1
  380. package/lib/types/number.d.ts +0 -12
  381. package/lib/types/number.js.map +0 -1
  382. package/lib/types/object.js.map +0 -1
  383. package/lib/types/string.js.map +0 -1
  384. package/lib/types/type.d.ts +0 -38
  385. package/lib/types/type.js +0 -7
  386. package/lib/types/type.js.map +0 -1
  387. package/lib/types/union.js.map +0 -1
  388. package/lib6/common-types.d.ts +0 -44
  389. package/lib6/common-types.js +0 -7
  390. package/lib6/common-types.js.map +0 -1
  391. package/lib6/connector.d.ts +0 -12
  392. package/lib6/connector.js +0 -7
  393. package/lib6/connector.js.map +0 -1
  394. package/lib6/crud-connector.d.ts +0 -130
  395. package/lib6/crud-connector.js +0 -7
  396. package/lib6/crud-connector.js.map +0 -1
  397. package/lib6/datasource.d.ts +0 -11
  398. package/lib6/datasource.js.map +0 -1
  399. package/lib6/decorators/model.d.ts +0 -17
  400. package/lib6/decorators/model.js +0 -55
  401. package/lib6/decorators/model.js.map +0 -1
  402. package/lib6/decorators/relation.d.ts +0 -65
  403. package/lib6/decorators/relation.js +0 -126
  404. package/lib6/decorators/relation.js.map +0 -1
  405. package/lib6/decorators/repository.d.ts +0 -61
  406. package/lib6/decorators/repository.js +0 -117
  407. package/lib6/decorators/repository.js.map +0 -1
  408. package/lib6/index.d.ts +0 -17
  409. package/lib6/index.js +0 -21
  410. package/lib6/index.js.map +0 -1
  411. package/lib6/kv-connector.js +0 -7
  412. package/lib6/kv-connector.js.map +0 -1
  413. package/lib6/kv-repository.d.ts +0 -78
  414. package/lib6/kv-repository.js +0 -7
  415. package/lib6/kv-repository.js.map +0 -1
  416. package/lib6/legacy-juggler-bridge.d.ts +0 -53
  417. package/lib6/legacy-juggler-bridge.js +0 -158
  418. package/lib6/legacy-juggler-bridge.js.map +0 -1
  419. package/lib6/loopback-datasource-juggler.d.ts +0 -666
  420. package/lib6/loopback-datasource-juggler.js +0 -8
  421. package/lib6/loopback-datasource-juggler.js.map +0 -1
  422. package/lib6/mixin.d.ts +0 -43
  423. package/lib6/mixin.js +0 -34
  424. package/lib6/mixin.js.map +0 -1
  425. package/lib6/model.d.ts +0 -137
  426. package/lib6/model.js +0 -182
  427. package/lib6/model.js.map +0 -1
  428. package/lib6/query.d.ts +0 -112
  429. package/lib6/query.js +0 -25
  430. package/lib6/query.js.map +0 -1
  431. package/lib6/repository-mixin.d.ts +0 -20
  432. package/lib6/repository-mixin.js +0 -111
  433. package/lib6/repository-mixin.js.map +0 -1
  434. package/lib6/repository.d.ts +0 -172
  435. package/lib6/repository.js +0 -128
  436. package/lib6/repository.js.map +0 -1
  437. package/lib6/types/any.d.ts +0 -12
  438. package/lib6/types/any.js.map +0 -1
  439. package/lib6/types/array.js +0 -53
  440. package/lib6/types/array.js.map +0 -1
  441. package/lib6/types/boolean.d.ts +0 -12
  442. package/lib6/types/boolean.js.map +0 -1
  443. package/lib6/types/buffer.js +0 -57
  444. package/lib6/types/buffer.js.map +0 -1
  445. package/lib6/types/date.d.ts +0 -12
  446. package/lib6/types/date.js +0 -60
  447. package/lib6/types/date.js.map +0 -1
  448. package/lib6/types/index.d.ts +0 -30
  449. package/lib6/types/index.js +0 -33
  450. package/lib6/types/index.js.map +0 -1
  451. package/lib6/types/model.js.map +0 -1
  452. package/lib6/types/number.js +0 -40
  453. package/lib6/types/number.js.map +0 -1
  454. package/lib6/types/object.d.ts +0 -15
  455. package/lib6/types/object.js +0 -49
  456. package/lib6/types/object.js.map +0 -1
  457. package/lib6/types/string.d.ts +0 -12
  458. package/lib6/types/string.js +0 -40
  459. package/lib6/types/string.js.map +0 -1
  460. package/lib6/types/type.js.map +0 -1
  461. package/lib6/types/union.d.ts +0 -14
  462. package/lib6/types/union.js +0 -51
  463. package/lib6/types/union.js.map +0 -1
@@ -0,0 +1,90 @@
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 {PropertyDecoratorFactory} from '@loopback/core';
7
+ import {buildModelDefinition} from '../decorators';
8
+ import {Model, RelationDefinitionMap} from '../model';
9
+ import {RelationType} from './relation.types';
10
+
11
+ export const RELATIONS_KEY = 'loopback:relations';
12
+
13
+ /**
14
+ * Decorator for relations
15
+ * @param definition
16
+ * @returns A property decorator
17
+ */
18
+ export function relation(definition?: Object) {
19
+ // Apply relation definition to the model class
20
+ return PropertyDecoratorFactory.createDecorator(RELATIONS_KEY, definition, {
21
+ decoratorName: '@relation',
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Get metadata of all relations defined on a given model class.
27
+ *
28
+ * @param modelCtor - The model class (the constructor function).
29
+ * @returns A map of relation definitions
30
+ */
31
+ export function getModelRelations(
32
+ modelCtor: typeof Model,
33
+ ): RelationDefinitionMap {
34
+ // Build model definitions if `@model` is missing
35
+ const modelDef = buildModelDefinition(modelCtor);
36
+ return modelDef?.relations || {};
37
+ }
38
+
39
+ //
40
+ // placeholder decorators for relations that are not implemented yet
41
+ // TODO: move these decorators to per-relation subdirectories
42
+ //
43
+
44
+ /**
45
+ * Decorator for embedsOne
46
+ * @param definition
47
+ * @returns A property decorator
48
+ */
49
+ export function embedsOne(definition?: Object) {
50
+ const rel = Object.assign({type: RelationType.embedsOne}, definition);
51
+ return PropertyDecoratorFactory.createDecorator(RELATIONS_KEY, rel, {
52
+ decoratorName: '@embedsOne',
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Decorator for embedsMany
58
+ * @param definition
59
+ * @returns A property decorator
60
+ */
61
+ export function embedsMany(definition?: Object) {
62
+ const rel = Object.assign({type: RelationType.embedsMany}, definition);
63
+ return PropertyDecoratorFactory.createDecorator(RELATIONS_KEY, rel, {
64
+ decoratorName: '@embedsMany',
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Decorator for referencesOne
70
+ * @param definition
71
+ * @returns A property decorator
72
+ */
73
+ export function referencesOne(definition?: Object) {
74
+ const rel = Object.assign({type: RelationType.referencesOne}, definition);
75
+ return PropertyDecoratorFactory.createDecorator(RELATIONS_KEY, rel, {
76
+ decoratorName: '@referencesOne',
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Decorator for referencesMany
82
+ * @param definition
83
+ * @returns A property decorator
84
+ */
85
+ export function referencesMany(definition?: Object) {
86
+ const rel = Object.assign({type: RelationType.referencesMany}, definition);
87
+ return PropertyDecoratorFactory.createDecorator(RELATIONS_KEY, rel, {
88
+ decoratorName: '@referencesMany',
89
+ });
90
+ }
@@ -0,0 +1,364 @@
1
+ // Copyright IBM Corp. 2019,2020. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import assert from 'assert';
7
+ import debugFactory from 'debug';
8
+ import _, {cloneDeep} from 'lodash';
9
+ import {
10
+ AnyObject,
11
+ Entity,
12
+ EntityCrudRepository,
13
+ Filter,
14
+ FilterBuilder,
15
+ InclusionFilter,
16
+ Options,
17
+ Where,
18
+ } from '..';
19
+ const debug = debugFactory('loopback:repository:relation-helpers');
20
+
21
+ /**
22
+ * Finds model instances that contain any of the provided foreign key values.
23
+ *
24
+ * @param targetRepository - The target repository where the related model instances are found
25
+ * @param fkName - Name of the foreign key
26
+ * @param fkValues - One value or array of values of the foreign key to be included
27
+ * @param scope - Additional scope constraints
28
+ * @param options - Options for the operations
29
+ */
30
+ export async function findByForeignKeys<
31
+ Target extends Entity,
32
+ TargetRelations extends object,
33
+ ForeignKey extends StringKeyOf<Target>,
34
+ >(
35
+ targetRepository: EntityCrudRepository<Target, unknown, TargetRelations>,
36
+ fkName: ForeignKey,
37
+ fkValues: Target[ForeignKey][] | Target[ForeignKey],
38
+ scope?: Filter<Target> & {totalLimit?: number},
39
+ options?: Options,
40
+ ): Promise<(Target & TargetRelations)[]> {
41
+ let value;
42
+ scope = cloneDeep(scope);
43
+ if (Array.isArray(fkValues)) {
44
+ if (fkValues.length === 0) return [];
45
+ value = fkValues.length === 1 ? fkValues[0] : {inq: fkValues};
46
+ } else {
47
+ value = fkValues;
48
+ }
49
+ let useScopeFilterGlobally = false;
50
+ if (options) {
51
+ useScopeFilterGlobally = options.isThroughModelInclude;
52
+ //if its an include from a through model, fkValues will be an array
53
+ //however, in this case we DO want to use the scope in the entire query
54
+ //no in a per fk basis
55
+ }
56
+ //This code is to keep backward compatability. See https://github.com/loopbackio/loopback-next/issues/6832
57
+ //for more info
58
+ if (scope?.totalLimit) {
59
+ scope.limit = scope.totalLimit;
60
+ useScopeFilterGlobally = true;
61
+ delete scope.totalLimit;
62
+ }
63
+
64
+ const isScopeSet = scope && !_.isEmpty(scope);
65
+ if (isScopeSet && Array.isArray(fkValues) && !useScopeFilterGlobally) {
66
+ // since there is a scope, there could be a where filter, a limit, an order
67
+ // and we should run the scope in multiple queries so we can respect the
68
+ // scope filter params
69
+ const findPromises = fkValues.map(fk => {
70
+ const where = {[fkName]: fk} as unknown as Where<Target>;
71
+ let localScope = cloneDeep(scope);
72
+ // combine where clause to scope filter
73
+ localScope = new FilterBuilder(localScope).impose({where}).filter;
74
+ return targetRepository.find(localScope, options);
75
+ });
76
+ return Promise.all(findPromises).then(findResults => {
77
+ //findResults is an array of arrays for each scope result, so we need to flatten it before returning it
78
+ return _.flatten(findResults);
79
+ });
80
+ } else {
81
+ const where = {[fkName]: value} as unknown as Where<Target>;
82
+
83
+ if (isScopeSet) {
84
+ // combine where clause to scope filter
85
+ scope = new FilterBuilder(scope).impose({where}).filter;
86
+ } else {
87
+ scope = {where} as Filter<Target>;
88
+ }
89
+
90
+ return targetRepository.find(scope, options);
91
+ }
92
+ }
93
+
94
+ export type StringKeyOf<T> = Extract<keyof T, string>;
95
+
96
+ /**
97
+ * Returns model instances that include related models that have a registered
98
+ * resolver.
99
+ *
100
+ * @param targetRepository - The target repository where the model instances are found
101
+ * @param entities - An array of entity instances or data
102
+ * @param include -Inclusion filter
103
+ * @param options - Options for the operations
104
+ */
105
+
106
+ export async function includeRelatedModels<
107
+ T extends Entity,
108
+ Relations extends object = {},
109
+ >(
110
+ targetRepository: EntityCrudRepository<T, unknown, Relations>,
111
+ entities: T[],
112
+ include?: InclusionFilter[],
113
+ options?: Options,
114
+ ): Promise<(T & Relations)[]> {
115
+ entities = cloneDeep(entities);
116
+ include = cloneDeep(include);
117
+ const result = entities as (T & Relations)[];
118
+ if (!include) return result;
119
+
120
+ const invalidInclusions = include.filter(
121
+ inclusionFilter => !isInclusionAllowed(targetRepository, inclusionFilter),
122
+ );
123
+ if (invalidInclusions.length) {
124
+ const msg =
125
+ 'Invalid "filter.include" entries: ' +
126
+ invalidInclusions
127
+ .map(inclusionFilter => JSON.stringify(inclusionFilter))
128
+ .join('; ');
129
+ const err = new Error(msg);
130
+ Object.assign(err, {
131
+ code: 'INVALID_INCLUSION_FILTER',
132
+ statusCode: 400,
133
+ });
134
+ throw err;
135
+ }
136
+
137
+ const resolveTasks = include.map(async inclusionFilter => {
138
+ const relationName =
139
+ typeof inclusionFilter === 'string'
140
+ ? inclusionFilter
141
+ : inclusionFilter.relation;
142
+ const resolver = targetRepository.inclusionResolvers.get(relationName)!;
143
+ const targets = await resolver(entities, inclusionFilter, options);
144
+
145
+ result.forEach((entity, ix) => {
146
+ const src = entity as AnyObject;
147
+ src[relationName] = targets[ix];
148
+ });
149
+ });
150
+
151
+ await Promise.all(resolveTasks);
152
+
153
+ return result;
154
+ }
155
+ /**
156
+ * Checks if the resolver of the inclusion relation is registered
157
+ * in the inclusionResolver of the target repository
158
+ *
159
+ * @param targetRepository - The target repository where the relations are registered
160
+ * @param include - Inclusion filter
161
+ */
162
+ function isInclusionAllowed<T extends Entity, Relations extends object = {}>(
163
+ targetRepository: EntityCrudRepository<T, unknown, Relations>,
164
+ include: InclusionFilter,
165
+ ): boolean {
166
+ const relationName = typeof include === 'string' ? include : include.relation;
167
+ if (!relationName) {
168
+ debug('isInclusionAllowed for %j? No: missing relation name', include);
169
+ return false;
170
+ }
171
+ const allowed = targetRepository.inclusionResolvers.has(relationName);
172
+ debug('isInclusionAllowed for %j (relation %s)? %s', include, allowed);
173
+ return allowed;
174
+ }
175
+
176
+ /**
177
+ * Returns an array of instances. The order of arrays is based on
178
+ * the order of sourceIds
179
+ *
180
+ * @param sourceIds - One value or array of values of the target key
181
+ * @param targetEntities - target entities that satisfy targetKey's value (ids).
182
+ * @param targetKey - name of the target key
183
+ *
184
+ */
185
+ export function flattenTargetsOfOneToOneRelation<Target extends Entity>(
186
+ sourceIds: unknown[],
187
+ targetEntities: Target[],
188
+ targetKey: StringKeyOf<Target>,
189
+ ): (Target | undefined)[] {
190
+ const lookup = buildLookupMap<unknown, Target, Target>(
191
+ targetEntities,
192
+ targetKey,
193
+ reduceAsSingleItem,
194
+ );
195
+
196
+ return flattenMapByKeys(sourceIds, lookup);
197
+ }
198
+
199
+ /**
200
+ * Returns an array of instances. The order of arrays is based on
201
+ * as a result of one to many relation. The order of arrays is based on
202
+ * the order of sourceIds
203
+ *
204
+ * @param sourceIds - One value or array of values of the target key
205
+ * @param targetEntities - target entities that satisfy targetKey's value (ids).
206
+ * @param targetKey - name of the target key
207
+ *
208
+ */
209
+ export function flattenTargetsOfOneToManyRelation<Target extends Entity>(
210
+ sourceIds: unknown[],
211
+ targetEntities: Target[],
212
+ targetKey: StringKeyOf<Target>,
213
+ ): (Target[] | undefined)[] {
214
+ debug('flattenTargetsOfOneToManyRelation');
215
+ debug('sourceIds', sourceIds);
216
+ debug(
217
+ 'sourceId types',
218
+ sourceIds.map(i => typeof i),
219
+ );
220
+ debug('targetEntities', targetEntities);
221
+ debug('targetKey', targetKey);
222
+
223
+ const lookup = buildLookupMap<unknown, Target, Target[]>(
224
+ targetEntities,
225
+ targetKey,
226
+ reduceAsArray,
227
+ );
228
+
229
+ debug('lookup map', lookup);
230
+
231
+ return flattenMapByKeys(sourceIds, lookup);
232
+ }
233
+
234
+ /**
235
+ * Returns an array of instances from the target map. The order of arrays is based on
236
+ * the order of sourceIds
237
+ *
238
+ * @param sourceIds - One value or array of values (of the target key)
239
+ * @param targetMap - a map that matches sourceIds with instances
240
+ */
241
+ export function flattenMapByKeys<T>(
242
+ sourceIds: unknown[],
243
+ targetMap: Map<unknown, T>,
244
+ ): (T | undefined)[] {
245
+ const result: (T | undefined)[] = new Array(sourceIds.length);
246
+ // mongodb: use string as key of targetMap, and convert sourceId to strings
247
+ // to make sure it gets the related instances.
248
+ sourceIds.forEach((id, index) => {
249
+ const key = normalizeKey(id);
250
+ const target = targetMap.get(key);
251
+ result[index] = target;
252
+ });
253
+
254
+ return result;
255
+ }
256
+
257
+ /**
258
+ * Returns a map which maps key values(ids) to instances. The instances can be
259
+ * grouped by different strategies.
260
+ *
261
+ * @param list - an array of instances
262
+ * @param keyName - key name of the source
263
+ * @param reducer - a strategy to reduce inputs to single item or array
264
+ */
265
+ export function buildLookupMap<Key, InType, OutType = InType>(
266
+ list: InType[],
267
+ keyName: StringKeyOf<InType>,
268
+ reducer: (accumulator: OutType | undefined, current: InType) => OutType,
269
+ ): Map<Key, OutType> {
270
+ const lookup = new Map<Key, OutType>();
271
+ for (const entity of list) {
272
+ // get a correct key value
273
+ const key = getKeyValue(entity, keyName) as Key;
274
+ // these 3 steps are to set up the map, the map differs according to the reducer.
275
+ const original = lookup.get(key);
276
+ const reduced = reducer(original, entity);
277
+ lookup.set(key, reduced);
278
+ }
279
+ return lookup;
280
+ }
281
+
282
+ /**
283
+ * Returns value of a keyName. Aims to resolve ObjectId problem of Mongo.
284
+ *
285
+ * @param model - target model
286
+ * @param keyName - target key that gets the value from
287
+ */
288
+ export function getKeyValue(model: AnyObject, keyName: string) {
289
+ return normalizeKey(model[keyName]);
290
+ }
291
+
292
+ /**
293
+ * Workaround for MongoDB, where the connector returns ObjectID
294
+ * values even for properties configured with "type: string".
295
+ *
296
+ * @param rawKey
297
+ */
298
+ export function normalizeKey(rawKey: unknown) {
299
+ if (isBsonType(rawKey)) {
300
+ return rawKey.toString();
301
+ }
302
+ return rawKey;
303
+ }
304
+
305
+ /**
306
+ * Returns an array of instances. For HasMany relation usage.
307
+ *
308
+ * @param acc
309
+ * @param it
310
+ */
311
+ export function reduceAsArray<T>(acc: T[] | undefined, it: T) {
312
+ if (acc) acc.push(it);
313
+ else acc = [it];
314
+ return acc;
315
+ }
316
+ /**
317
+ * Returns a single of an instance. For HasOne and BelongsTo relation usage.
318
+ *
319
+ * @param _acc
320
+ * @param it
321
+ */
322
+ export function reduceAsSingleItem<T>(_acc: T | undefined, it: T) {
323
+ return it;
324
+ }
325
+
326
+ /**
327
+ * Dedupe an array
328
+ * @param input - an array of sourceIds
329
+ * @returns an array with unique items
330
+ */
331
+ export function deduplicate<T>(input: T[]): T[] {
332
+ const uniqArray: T[] = [];
333
+ if (!input) {
334
+ return uniqArray;
335
+ }
336
+ assert(Array.isArray(input), 'array argument is required');
337
+
338
+ const comparableArray = input.map(item => normalizeKey(item));
339
+ for (let i = 0, n = comparableArray.length; i < n; i++) {
340
+ if (comparableArray.indexOf(comparableArray[i]) === i) {
341
+ uniqArray.push(input[i]);
342
+ }
343
+ }
344
+ return uniqArray;
345
+ }
346
+
347
+ /**
348
+ * Checks if the value is BsonType (mongodb)
349
+ * It uses a general way to check the type ,so that it can detect
350
+ * different versions of bson that might be used in the code base.
351
+ * Might need to update in the future.
352
+ *
353
+ * @param value
354
+ */
355
+ export function isBsonType(value: unknown): value is object {
356
+ if (typeof value !== 'object' || !value) return false;
357
+
358
+ // bson@1.x stores _bsontype on ObjectID instance, bson@4.x on prototype
359
+ return check(value) || check(value.constructor.prototype);
360
+
361
+ function check(target: unknown) {
362
+ return Object.prototype.hasOwnProperty.call(target, '_bsontype');
363
+ }
364
+ }
@@ -0,0 +1,180 @@
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 {InclusionFilter} from '@loopback/filter';
7
+ import {Options} from '../common-types';
8
+ import {Entity} from '../model';
9
+ import {TypeResolver} from '../type-resolver';
10
+
11
+ export enum RelationType {
12
+ belongsTo = 'belongsTo',
13
+ hasOne = 'hasOne',
14
+ hasMany = 'hasMany',
15
+ embedsOne = 'embedsOne',
16
+ embedsMany = 'embedsMany',
17
+ referencesOne = 'referencesOne',
18
+ referencesMany = 'referencesMany',
19
+ }
20
+
21
+ export interface RelationDefinitionBase {
22
+ /**
23
+ * The type of the relation, must be one of RelationType values.
24
+ */
25
+ type: RelationType;
26
+
27
+ /**
28
+ * True for relations targeting multiple instances (e.g. HasMany),
29
+ * false for relations with a single target (e.g. BelongsTo, HasOne).
30
+ * This property is needed by OpenAPI/JSON Schema generator.
31
+ */
32
+ targetsMany: boolean;
33
+
34
+ /**
35
+ * The relation name, typically matching the name of the accessor property
36
+ * defined on the source model. For example "orders" or "customer".
37
+ */
38
+ name: string;
39
+
40
+ /**
41
+ * The source model of this relation.
42
+ *
43
+ * E.g. when a Customer has many Order instances, then Customer is the source.
44
+ */
45
+ source: typeof Entity;
46
+
47
+ /**
48
+ * The target model of this relation.
49
+ *
50
+ * E.g. when a Customer has many Order instances, then Order is the target.
51
+ */
52
+ target: TypeResolver<Entity, typeof Entity>;
53
+ }
54
+
55
+ /**
56
+ * HasManyDefinition defines one-to-many relations and also possible defines
57
+ * many-to-many relations with through models.
58
+ */
59
+ export interface HasManyDefinition extends RelationDefinitionBase {
60
+ type: RelationType.hasMany;
61
+ targetsMany: true;
62
+
63
+ /**
64
+ * keyTo: The foreign key used by the target model for this relation.
65
+ * keyFrom: The source key used by the source model for this relation.
66
+ *
67
+ * E.g. when a Customer has many Order instances, then keyTo is "customerId".
68
+ * Note that "customerId" is the default FK assumed by the framework, users
69
+ * can provide a custom FK name by setting "keyTo".
70
+ * And Customer.id is keyFrom. keyFrom defaults to the id property of a model.
71
+ * Users can provide a custom source key name by setting "keyTo".
72
+ *
73
+ */
74
+ keyTo?: string;
75
+ keyFrom?: string;
76
+
77
+ /**
78
+ * Description of the through model of the hasManyThrough relation.
79
+ *
80
+ * A `hasManyThrough` relation defines a many-to-many connection with another model.
81
+ * This relation indicates that the declaring model can be matched with zero or more
82
+ * instances of another model by proceeding through a third model.
83
+ *
84
+ * E.g a Category has many Products, and a Product can have many Categories.
85
+ * CategoryProductLink can be the through model.
86
+ * Such a through model has information of foreign keys of the source model(Category) and the target model(Product).
87
+ *
88
+ * Warning: The hasManyThrough interface is experimental and is subject to change.
89
+ * If backwards-incompatible changes are made, a new major version may not be
90
+ * released.
91
+ */
92
+ through?: {
93
+ /**
94
+ * The through model of this relation.
95
+ *
96
+ * E.g. when a Category has many CategoryProductLink instances and a Product has many CategoryProductLink instances,
97
+ * then CategoryProductLink is through.
98
+ */
99
+ model: TypeResolver<Entity, typeof Entity>;
100
+
101
+ /**
102
+ * The foreign key of the source model defined in the through model, e.g. CategoryProductLink#categoryId
103
+ */
104
+ keyFrom?: string;
105
+
106
+ /**
107
+ * The foreign key of the target model defined in the through model, e.g. CategoryProductLink#productId
108
+ */
109
+ keyTo?: string;
110
+ };
111
+ }
112
+
113
+ export interface BelongsToDefinition extends RelationDefinitionBase {
114
+ type: RelationType.belongsTo;
115
+ targetsMany: false;
116
+
117
+ /*
118
+ * The foreign key in the source model, e.g. Order#customerId.
119
+ */
120
+ keyFrom?: string;
121
+
122
+ /*
123
+ * The primary key of the target model, e.g Customer#id.
124
+ */
125
+ keyTo?: string;
126
+ }
127
+
128
+ export interface HasOneDefinition extends RelationDefinitionBase {
129
+ type: RelationType.hasOne;
130
+ targetsMany: false;
131
+
132
+ /**
133
+ * keyTo: The foreign key used by the target model for this relation.
134
+ * keyFrom: The source key used by the source model for this relation.
135
+ *
136
+ * E.g. when a Customer has one Address instance, then keyTo is "customerId".
137
+ * Note that "customerId" is the default FK assumed by the framework, users
138
+ * can provide a custom FK name by setting "keyTo".
139
+ * And Customer.id is keyFrom. keyFrom defaults to the id property of a model.
140
+ * Users can provide a custom source key name by setting "keyTo".
141
+ */
142
+ keyTo?: string;
143
+ keyFrom?: string;
144
+ }
145
+
146
+ /**
147
+ * A union type describing all possible Relation metadata objects.
148
+ */
149
+ export type RelationMetadata =
150
+ | HasManyDefinition
151
+ | BelongsToDefinition
152
+ | HasOneDefinition
153
+ // TODO(bajtos) add other relation types and remove RelationDefinitionBase once
154
+ // all relation types are covered.
155
+ | RelationDefinitionBase;
156
+
157
+ // Re-export Getter so that users don't have to import from @loopback/context
158
+ export {Getter} from '@loopback/core';
159
+
160
+ /**
161
+ * @returns An array of resolved values, the items must be ordered in the same
162
+ * way as `sourceEntities`. The resolved value can be one of:
163
+ * - `undefined` when no target model(s) were found
164
+ * - `Entity` for relations targeting a single model
165
+ * - `Entity[]` for relations targeting multiple models
166
+ */
167
+ export type InclusionResolver<S extends Entity, T extends Entity> = (
168
+ /**
169
+ * List of source models as returned by the first database query.
170
+ */
171
+ sourceEntities: S[],
172
+ /**
173
+ * Inclusion requested by the user (e.g. scope constraints to apply).
174
+ */
175
+ inclusion: InclusionFilter,
176
+ /**
177
+ * Generic options object, e.g. carrying the Transaction object.
178
+ */
179
+ options?: Options,
180
+ ) => Promise<(T | undefined)[] | (T[] | undefined)[]>;