@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,17 @@
1
+ import { Entity, EntityCrudRepository, Getter, HasManyDefinition, InclusionResolver } from '../..';
2
+ import { HasManyThroughRepository } from './has-many-through.repository';
3
+ /**
4
+ * a factory to generate hasManyThrough repository class.
5
+ *
6
+ * Warning: The hasManyThrough interface is experimental and is subject to change.
7
+ * If backwards-incompatible changes are made, a new major version may not be
8
+ * released.
9
+ */
10
+ export declare type HasManyThroughRepositoryFactory<TargetEntity extends Entity, TargetID, ThroughEntity extends Entity, SourceID> = {
11
+ (fkValue: SourceID): HasManyThroughRepository<TargetEntity, TargetID, ThroughEntity>;
12
+ /**
13
+ * Use `resolver` property to obtain an InclusionResolver for this relation.
14
+ */
15
+ inclusionResolver: InclusionResolver<Entity, TargetEntity>;
16
+ };
17
+ export declare function createHasManyThroughRepositoryFactory<Target extends Entity, TargetID, Through extends Entity, ThroughID, SourceID>(relationMetadata: HasManyDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>, throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>): HasManyThroughRepositoryFactory<Target, TargetID, Through, SourceID>;
@@ -0,0 +1,37 @@
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.createHasManyThroughRepositoryFactory = void 0;
8
+ const has_many_through_helpers_1 = require("./has-many-through.helpers");
9
+ const has_many_through_inclusion_resolver_1 = require("./has-many-through.inclusion-resolver");
10
+ const has_many_through_repository_1 = require("./has-many-through.repository");
11
+ function createHasManyThroughRepositoryFactory(relationMetadata, targetRepositoryGetter, throughRepositoryGetter) {
12
+ const meta = (0, has_many_through_helpers_1.resolveHasManyThroughMetadata)(relationMetadata);
13
+ const result = function (fkValue) {
14
+ function getTargetConstraintFromThroughModels(throughInstances) {
15
+ return (0, has_many_through_helpers_1.createTargetConstraintFromThrough)(meta, throughInstances);
16
+ }
17
+ function getTargetKeys(throughInstances) {
18
+ return (0, has_many_through_helpers_1.getTargetKeysFromThroughModels)(meta, throughInstances);
19
+ }
20
+ function getThroughConstraintFromSource() {
21
+ const constraint = (0, has_many_through_helpers_1.createThroughConstraintFromSource)(meta, fkValue);
22
+ return constraint;
23
+ }
24
+ function getTargetIds(targetInstances) {
25
+ return (0, has_many_through_helpers_1.getTargetIdsFromTargetModels)(meta, targetInstances);
26
+ }
27
+ function getThroughConstraintFromTarget(fkValues) {
28
+ const constraint = (0, has_many_through_helpers_1.createThroughConstraintFromTarget)(meta, fkValues);
29
+ return constraint;
30
+ }
31
+ return new has_many_through_repository_1.DefaultHasManyThroughRepository(targetRepositoryGetter, throughRepositoryGetter, getTargetConstraintFromThroughModels, getTargetKeys, getThroughConstraintFromSource, getTargetIds, getThroughConstraintFromTarget);
32
+ };
33
+ result.inclusionResolver = (0, has_many_through_inclusion_resolver_1.createHasManyThroughInclusionResolver)(meta, throughRepositoryGetter, targetRepositoryGetter);
34
+ return result;
35
+ }
36
+ exports.createHasManyThroughRepositoryFactory = createHasManyThroughRepositoryFactory;
37
+ //# sourceMappingURL=has-many-through.repository-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many-through.repository-factory.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.repository-factory.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAUhE,yEAOoC;AACpC,+FAA4F;AAC5F,+EAGuC;AA4BvC,SAAgB,qCAAqC,CAOnD,gBAAmC,EACnC,sBAAsE,EACtE,uBAAyE;IAEzE,MAAM,IAAI,GAAG,IAAA,wDAA6B,EAAC,gBAAgB,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,UAAU,OAAiB;QACxC,SAAS,oCAAoC,CAC3C,gBAA2B;YAE3B,OAAO,IAAA,4DAAiC,EACtC,IAAI,EACJ,gBAAgB,CACjB,CAAC;QACJ,CAAC;QACD,SAAS,aAAa,CAAC,gBAA2B;YAChD,OAAO,IAAA,yDAA8B,EAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAChE,CAAC;QACD,SAAS,8BAA8B;YACrC,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,OAAO,CAAC,CAAC;YACjB,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,SAAS,YAAY,CAAC,eAAyB;YAC7C,OAAO,IAAA,uDAA4B,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC7D,CAAC;QACD,SAAS,8BAA8B,CACrC,QAAoB;YAEpB,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAClB,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,6DAA+B,CAQxC,sBAAsB,EACtB,uBAAuB,EACvB,oCAAoC,EACpC,aAAa,EACb,8BAA8B,EAC9B,YAAY,EACZ,8BAA8B,CAC/B,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,CAAC,iBAAiB,GAAG,IAAA,2EAAqC,EAC9D,IAAI,EACJ,uBAAuB,EACvB,sBAAsB,CACvB,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAnED,sFAmEC"}
@@ -0,0 +1,114 @@
1
+ import { Count, DataObject, Entity, EntityCrudRepository, Filter, Getter, Options, Where } from '../..';
2
+ /**
3
+ * CRUD operations for a target repository of a HasManyThrough relation
4
+ *
5
+ * EXPERIMENTAL: This interface is not stable and may change in the near future.
6
+ * Backwards-incompatible changes may be introduced in semver-minor versions.
7
+ */
8
+ export interface HasManyThroughRepository<Target extends Entity, TargetID, Through extends Entity> {
9
+ /**
10
+ * Create a target model instance
11
+ * @param targetModelData - The target model data
12
+ * @param options - Options for the operation
13
+ * @returns A promise which resolves to the newly created target model instance
14
+ */
15
+ create(targetModelData: DataObject<Target>, options?: Options & {
16
+ throughData?: DataObject<Through>;
17
+ throughOptions?: Options;
18
+ }): Promise<Target>;
19
+ /**
20
+ * Find target model instance(s)
21
+ * @param filter - A filter object for where, order, limit, etc.
22
+ * @param options - Options for the operation
23
+ * @returns A promise which resolves with the found target instance(s)
24
+ */
25
+ find(filter?: Filter<Target>, options?: Options & {
26
+ throughOptions?: Options;
27
+ }): Promise<Target[]>;
28
+ /**
29
+ * Delete multiple target model instances
30
+ * @param where - Instances within the where scope are deleted
31
+ * @param options
32
+ * @returns A promise which resolves the deleted target model instances
33
+ */
34
+ delete(where?: Where<Target>, options?: Options & {
35
+ throughOptions?: Options;
36
+ }): Promise<Count>;
37
+ /**
38
+ * Patch multiple target model instances
39
+ * @param dataObject - The fields and their new values to patch
40
+ * @param where - Instances within the where scope are patched
41
+ * @param options
42
+ * @returns A promise which resolves the patched target model instances
43
+ */
44
+ patch(dataObject: DataObject<Target>, where?: Where<Target>, options?: Options & {
45
+ throughOptions?: Options;
46
+ }): Promise<Count>;
47
+ /**
48
+ * Creates a new many-to-many association to an existing target model instance
49
+ * @param targetModelId - The target model ID to link
50
+ * @param options
51
+ * @returns A promise which resolves to the linked target model instance
52
+ */
53
+ link(targetModelId: TargetID, options?: Options & {
54
+ throughData?: DataObject<Through>;
55
+ throughOptions?: Options;
56
+ }): Promise<void>;
57
+ /**
58
+ * Removes an association to an existing target model instance
59
+ * @param targetModelId - The target model to unlink
60
+ * @param options
61
+ * @returns A promise which resolves to null
62
+ */
63
+ unlink(targetModelId: TargetID, options?: Options & {
64
+ throughOptions?: Options;
65
+ }): Promise<void>;
66
+ /**
67
+ * Remove all association to an existing target model instance
68
+ * @param options
69
+ * @return A promise which resolves to void
70
+ */
71
+ unlinkAll(options?: Options & {
72
+ throughOptions?: Options;
73
+ }): Promise<void>;
74
+ }
75
+ /**
76
+ * a class for CRUD operations for hasManyThrough relation.
77
+ *
78
+ * Warning: The hasManyThrough interface is experimental and is subject to change.
79
+ * If backwards-incompatible changes are made, a new major version may not be
80
+ * released.
81
+ */
82
+ export declare class DefaultHasManyThroughRepository<TargetEntity extends Entity, TargetID, TargetRepository extends EntityCrudRepository<TargetEntity, TargetID>, ThroughEntity extends Entity, ThroughID, ThroughRepository extends EntityCrudRepository<ThroughEntity, ThroughID>> implements HasManyThroughRepository<TargetEntity, TargetID, ThroughEntity> {
83
+ getTargetRepository: Getter<TargetRepository>;
84
+ getThroughRepository: Getter<ThroughRepository>;
85
+ getTargetConstraintFromThroughModels: (throughInstances: ThroughEntity[]) => DataObject<TargetEntity>;
86
+ getTargetKeys: (throughInstances: ThroughEntity[]) => TargetID[];
87
+ getThroughConstraintFromSource: () => DataObject<ThroughEntity>;
88
+ getTargetIds: (targetInstances: TargetEntity[]) => TargetID[];
89
+ getThroughConstraintFromTarget: (targetID: TargetID[]) => DataObject<ThroughEntity>;
90
+ constructor(getTargetRepository: Getter<TargetRepository>, getThroughRepository: Getter<ThroughRepository>, getTargetConstraintFromThroughModels: (throughInstances: ThroughEntity[]) => DataObject<TargetEntity>, getTargetKeys: (throughInstances: ThroughEntity[]) => TargetID[], getThroughConstraintFromSource: () => DataObject<ThroughEntity>, getTargetIds: (targetInstances: TargetEntity[]) => TargetID[], getThroughConstraintFromTarget: (targetID: TargetID[]) => DataObject<ThroughEntity>);
91
+ create(targetModelData: DataObject<TargetEntity>, options?: Options & {
92
+ throughData?: DataObject<ThroughEntity>;
93
+ throughOptions?: Options;
94
+ }): Promise<TargetEntity>;
95
+ find(filter?: Filter<TargetEntity>, options?: Options & {
96
+ throughOptions?: Options;
97
+ }): Promise<TargetEntity[]>;
98
+ delete(where?: Where<TargetEntity>, options?: Options & {
99
+ throughOptions?: Options;
100
+ }): Promise<Count>;
101
+ patch(dataObject: DataObject<TargetEntity>, where?: Where<TargetEntity>, options?: Options & {
102
+ throughOptions?: Options;
103
+ }): Promise<Count>;
104
+ link(targetId: TargetID, options?: Options & {
105
+ throughData?: DataObject<ThroughEntity>;
106
+ throughOptions?: Options;
107
+ }): Promise<void>;
108
+ unlink(targetId: TargetID, options?: Options & {
109
+ throughOptions?: Options;
110
+ }): Promise<void>;
111
+ unlinkAll(options?: Options & {
112
+ throughOptions?: Options;
113
+ }): Promise<void>;
114
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,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.DefaultHasManyThroughRepository = void 0;
8
+ const __1 = require("../..");
9
+ /**
10
+ * a class for CRUD operations for hasManyThrough relation.
11
+ *
12
+ * Warning: The hasManyThrough interface is experimental and is subject to change.
13
+ * If backwards-incompatible changes are made, a new major version may not be
14
+ * released.
15
+ */
16
+ class DefaultHasManyThroughRepository {
17
+ constructor(getTargetRepository, getThroughRepository, getTargetConstraintFromThroughModels, getTargetKeys, getThroughConstraintFromSource, getTargetIds, getThroughConstraintFromTarget) {
18
+ this.getTargetRepository = getTargetRepository;
19
+ this.getThroughRepository = getThroughRepository;
20
+ this.getTargetConstraintFromThroughModels = getTargetConstraintFromThroughModels;
21
+ this.getTargetKeys = getTargetKeys;
22
+ this.getThroughConstraintFromSource = getThroughConstraintFromSource;
23
+ this.getTargetIds = getTargetIds;
24
+ this.getThroughConstraintFromTarget = getThroughConstraintFromTarget;
25
+ }
26
+ async create(targetModelData, options) {
27
+ const targetRepository = await this.getTargetRepository();
28
+ const targetInstance = await targetRepository.create(targetModelData, options);
29
+ await this.link(targetInstance.getId(), options);
30
+ return targetInstance;
31
+ }
32
+ async find(filter, options) {
33
+ const targetRepository = await this.getTargetRepository();
34
+ const throughRepository = await this.getThroughRepository();
35
+ const sourceConstraint = this.getThroughConstraintFromSource();
36
+ const throughInstances = await throughRepository.find((0, __1.constrainFilter)(undefined, sourceConstraint), options === null || options === void 0 ? void 0 : options.throughOptions);
37
+ const targetConstraint = this.getTargetConstraintFromThroughModels(throughInstances);
38
+ return targetRepository.find((0, __1.constrainFilter)(filter, targetConstraint), options);
39
+ }
40
+ async delete(where, options) {
41
+ const targetRepository = await this.getTargetRepository();
42
+ const throughRepository = await this.getThroughRepository();
43
+ const sourceConstraint = this.getThroughConstraintFromSource();
44
+ const throughInstances = await throughRepository.find((0, __1.constrainFilter)(undefined, sourceConstraint), options === null || options === void 0 ? void 0 : options.throughOptions);
45
+ if (where) {
46
+ // only delete related through models
47
+ // TODO(Agnes): this performance can be improved by only fetching related data
48
+ // TODO: add target ids to the `where` constraint
49
+ const targets = await targetRepository.find({ where });
50
+ const targetIds = this.getTargetIds(targets);
51
+ if (targetIds.length > 0) {
52
+ const targetConstraint = this.getThroughConstraintFromTarget(targetIds);
53
+ const constraints = { ...targetConstraint, ...sourceConstraint };
54
+ await throughRepository.deleteAll((0, __1.constrainDataObject)({}, constraints), options === null || options === void 0 ? void 0 : options.throughOptions);
55
+ }
56
+ }
57
+ else {
58
+ // otherwise, delete through models that relate to the sourceId
59
+ const targetFkValues = this.getTargetKeys(throughInstances);
60
+ // delete through instances that have the targets that are going to be deleted
61
+ const throughFkConstraint = this.getThroughConstraintFromTarget(targetFkValues);
62
+ await throughRepository.deleteAll((0, __1.constrainWhereOr)({}, [sourceConstraint, throughFkConstraint]));
63
+ }
64
+ // delete target(s)
65
+ const targetConstraint = this.getTargetConstraintFromThroughModels(throughInstances);
66
+ return targetRepository.deleteAll((0, __1.constrainWhere)(where, targetConstraint), options);
67
+ }
68
+ // only allows patch target instances for now
69
+ async patch(dataObject, where, options) {
70
+ const targetRepository = await this.getTargetRepository();
71
+ const throughRepository = await this.getThroughRepository();
72
+ const sourceConstraint = this.getThroughConstraintFromSource();
73
+ const throughInstances = await throughRepository.find((0, __1.constrainFilter)(undefined, sourceConstraint), options === null || options === void 0 ? void 0 : options.throughOptions);
74
+ const targetConstraint = this.getTargetConstraintFromThroughModels(throughInstances);
75
+ return targetRepository.updateAll((0, __1.constrainDataObject)(dataObject, targetConstraint), (0, __1.constrainWhere)(where, targetConstraint), options);
76
+ }
77
+ async link(targetId, options) {
78
+ var _a;
79
+ const throughRepository = await this.getThroughRepository();
80
+ const sourceConstraint = this.getThroughConstraintFromSource();
81
+ const targetConstraint = this.getThroughConstraintFromTarget([targetId]);
82
+ const constraints = { ...targetConstraint, ...sourceConstraint };
83
+ await throughRepository.create((0, __1.constrainDataObject)((_a = options === null || options === void 0 ? void 0 : options.throughData) !== null && _a !== void 0 ? _a : {}, constraints), options === null || options === void 0 ? void 0 : options.throughOptions);
84
+ }
85
+ async unlink(targetId, options) {
86
+ const throughRepository = await this.getThroughRepository();
87
+ const sourceConstraint = this.getThroughConstraintFromSource();
88
+ const targetConstraint = this.getThroughConstraintFromTarget([targetId]);
89
+ const constraints = { ...targetConstraint, ...sourceConstraint };
90
+ await throughRepository.deleteAll((0, __1.constrainDataObject)({}, constraints), options === null || options === void 0 ? void 0 : options.throughOptions);
91
+ }
92
+ async unlinkAll(options) {
93
+ const throughRepository = await this.getThroughRepository();
94
+ const sourceConstraint = this.getThroughConstraintFromSource();
95
+ const throughInstances = await throughRepository.find((0, __1.constrainFilter)(undefined, sourceConstraint), options === null || options === void 0 ? void 0 : options.throughOptions);
96
+ const targetFkValues = this.getTargetKeys(throughInstances);
97
+ const targetConstraint = this.getThroughConstraintFromTarget(targetFkValues);
98
+ const constraints = { ...targetConstraint, ...sourceConstraint };
99
+ await throughRepository.deleteAll((0, __1.constrainDataObject)({}, constraints), options === null || options === void 0 ? void 0 : options.throughOptions);
100
+ }
101
+ }
102
+ exports.DefaultHasManyThroughRepository = DefaultHasManyThroughRepository;
103
+ //# sourceMappingURL=has-many-through.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many-through.repository.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.repository.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,6BAae;AA2Gf;;;;;;GAMG;AACH,MAAa,+BAA+B;IAS1C,YACS,mBAA6C,EAC7C,oBAA+C,EAC/C,oCAEsB,EACtB,aAAgE,EAChE,8BAA+D,EAC/D,YAA6D,EAC7D,8BAEuB;QAVvB,wBAAmB,GAAnB,mBAAmB,CA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D,MAAM,iBAAiB,CAAC,SAAS,CAC/B,IAAA,uBAAmB,EAAC,EAAE,EAAE,WAAwC,CAAC,EACjE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,CACxB,CAAC;IACJ,CAAC;CACF;AAzLD,0EAyLC"}
@@ -0,0 +1,11 @@
1
+ import { Entity, EntityResolver } from '../../model';
2
+ import { HasManyDefinition } from '../relation.types';
3
+ /**
4
+ * Decorator for hasMany
5
+ * Calls property.array decorator underneath the hood and infers foreign key
6
+ * name from target model name unless explicitly specified
7
+ * @param targetResolver - Target model for hasMany relation
8
+ * @param definition - Optional metadata for setting up hasMany relation
9
+ * @returns A property decorator
10
+ */
11
+ export declare function hasMany<T extends Entity>(targetResolver: EntityResolver<T>, definition?: Partial<HasManyDefinition>): (decoratedTarget: object, key: string) => void;
@@ -0,0 +1,36 @@
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.hasMany = void 0;
8
+ const relation_decorator_1 = require("../relation.decorator");
9
+ const relation_types_1 = require("../relation.types");
10
+ /**
11
+ * Decorator for hasMany
12
+ * Calls property.array decorator underneath the hood and infers foreign key
13
+ * name from target model name unless explicitly specified
14
+ * @param targetResolver - Target model for hasMany relation
15
+ * @param definition - Optional metadata for setting up hasMany relation
16
+ * @returns A property decorator
17
+ */
18
+ function hasMany(targetResolver, definition) {
19
+ return function (decoratedTarget, key) {
20
+ const meta = Object.assign(
21
+ // default values, can be customized by the caller
22
+ { name: key },
23
+ // properties provided by the caller
24
+ definition,
25
+ // properties enforced by the decorator
26
+ {
27
+ type: relation_types_1.RelationType.hasMany,
28
+ targetsMany: true,
29
+ source: decoratedTarget.constructor,
30
+ target: targetResolver,
31
+ });
32
+ (0, relation_decorator_1.relation)(meta)(decoratedTarget, key);
33
+ };
34
+ }
35
+ exports.hasMany = hasMany;
36
+ //# sourceMappingURL=has-many.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many.decorator.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many.decorator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,8DAA+C;AAC/C,sDAAkE;AAElE;;;;;;;GAOG;AACH,SAAgB,OAAO,CACrB,cAAiC,EACjC,UAAuC;IAEvC,OAAO,UAAU,eAAuB,EAAE,GAAW;QACnD,MAAM,IAAI,GAAsB,MAAM,CAAC,MAAM;QAC3C,kDAAkD;QAClD,EAAC,IAAI,EAAE,GAAG,EAAC;QACX,oCAAoC;QACpC,UAAU;QACV,uCAAuC;QACvC;YACE,IAAI,EAAE,6BAAY,CAAC,OAAO;YAC1B,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,eAAe,CAAC,WAAW;YACnC,MAAM,EAAE,cAAc;SACvB,CACF,CAAC;QACF,IAAA,6BAAQ,EAAC,IAAI,CAAC,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC;AApBD,0BAoBC"}
@@ -0,0 +1,26 @@
1
+ import { HasManyDefinition } from '../relation.types';
2
+ /**
3
+ * Relation definition with optional metadata (e.g. `keyTo`) filled in.
4
+ * @internal
5
+ */
6
+ export declare type HasManyResolvedDefinition = HasManyDefinition & {
7
+ keyFrom: string;
8
+ keyTo: string;
9
+ };
10
+ /**
11
+ * Resolves given hasMany metadata if target is specified to be a resolver.
12
+ * Mainly used to infer what the `keyTo` property should be from the target's
13
+ * belongsTo metadata
14
+ * @param relationMeta - hasMany metadata to resolve
15
+ * @internal
16
+ */
17
+ export declare function resolveHasManyMetadata(relationMeta: HasManyDefinition): HasManyResolvedDefinition;
18
+ /**
19
+ * A helper to check relation type and the existence of the source/target models
20
+ * and set up keyFrom
21
+ * for HasMany(Through) relations
22
+ * @param relationMeta
23
+ *
24
+ * @returns relationMeta that has set up keyFrom
25
+ */
26
+ export declare function resolveHasManyMetaHelper(relationMeta: HasManyDefinition): HasManyDefinition;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,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.resolveHasManyMetaHelper = exports.resolveHasManyMetadata = 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 errors_1 = require("../../errors");
12
+ const type_resolver_1 = require("../../type-resolver");
13
+ const relation_types_1 = require("../relation.types");
14
+ const debug = (0, debug_1.default)('loopback:repository:relations:has-many:helpers');
15
+ /**
16
+ * Resolves given hasMany metadata if target is specified to be a resolver.
17
+ * Mainly used to infer what the `keyTo` property should be from the target's
18
+ * belongsTo metadata
19
+ * @param relationMeta - hasMany metadata to resolve
20
+ * @internal
21
+ */
22
+ function resolveHasManyMetadata(relationMeta) {
23
+ var _a;
24
+ // some checks and relationMeta.keyFrom are handled in here
25
+ relationMeta = resolveHasManyMetaHelper(relationMeta);
26
+ const targetModel = relationMeta.target();
27
+ const targetModelProperties = (_a = targetModel.definition) === null || _a === void 0 ? void 0 : _a.properties;
28
+ const sourceModel = relationMeta.source;
29
+ if (relationMeta.keyTo && targetModelProperties[relationMeta.keyTo]) {
30
+ // The explicit cast is needed because of a limitation of type inference
31
+ return relationMeta;
32
+ }
33
+ debug('Resolved model %s from given metadata: %o', targetModel.modelName, targetModel);
34
+ const defaultFkName = (0, lodash_1.camelCase)(sourceModel.modelName + '_id');
35
+ const hasDefaultFkProperty = targetModelProperties[defaultFkName];
36
+ if (!hasDefaultFkProperty) {
37
+ const reason = `target model ${targetModel.name} is missing definition of foreign key ${defaultFkName}`;
38
+ throw new errors_1.InvalidRelationError(reason, relationMeta);
39
+ }
40
+ return Object.assign(relationMeta, {
41
+ keyTo: defaultFkName,
42
+ });
43
+ }
44
+ exports.resolveHasManyMetadata = resolveHasManyMetadata;
45
+ /**
46
+ * A helper to check relation type and the existence of the source/target models
47
+ * and set up keyFrom
48
+ * for HasMany(Through) relations
49
+ * @param relationMeta
50
+ *
51
+ * @returns relationMeta that has set up keyFrom
52
+ */
53
+ function resolveHasManyMetaHelper(relationMeta) {
54
+ if (relationMeta.type !== relation_types_1.RelationType.hasMany) {
55
+ const reason = 'relation type must be HasMany';
56
+ throw new errors_1.InvalidRelationError(reason, relationMeta);
57
+ }
58
+ if (!(0, type_resolver_1.isTypeResolver)(relationMeta.target)) {
59
+ const reason = 'target must be a type resolver';
60
+ throw new errors_1.InvalidRelationError(reason, relationMeta);
61
+ }
62
+ const sourceModel = relationMeta.source;
63
+ if (!sourceModel || !sourceModel.modelName) {
64
+ const reason = 'source model must be defined';
65
+ throw new errors_1.InvalidRelationError(reason, relationMeta);
66
+ }
67
+ let keyFrom;
68
+ if (relationMeta.keyFrom &&
69
+ relationMeta.source.definition.properties[relationMeta.keyFrom]) {
70
+ keyFrom = relationMeta.keyFrom;
71
+ }
72
+ else {
73
+ keyFrom = sourceModel.getIdProperties()[0];
74
+ }
75
+ return Object.assign(relationMeta, { keyFrom });
76
+ }
77
+ exports.resolveHasManyMetaHelper = resolveHasManyMetaHelper;
78
+ //# sourceMappingURL=has-many.helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many.helpers.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many.helpers.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAiC;AACjC,mCAAiC;AACjC,yCAAkD;AAClD,uDAAmD;AACnD,sDAAkE;AAElE,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,gDAAgD,CAAC,CAAC;AAW7E;;;;;;GAMG;AAC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AgC,CAAC;QAChD,MAAM,IAAI,6BAAoB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;KACtD;IAED,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC;IACxC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE;QAC1C,MAAM,MAAM,GAAG,8BAA8B,CAAC;QAC9C,MAAM,IAAI,6BAAoB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;KACtD;IACD,IAAI,OAAO,CAAC;IACZ,IACE,YAAY,CAAC,OAAO;QACpB,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,EAC/D;QACA,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;KAChC;SAAM;QACL,OAAO,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5C;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAC,OAAO,EAAC,CAAsB,CAAC;AACrE,CAAC;AA5BD,4DA4BC"}
@@ -0,0 +1,14 @@
1
+ import { Entity } from '../../model';
2
+ import { EntityCrudRepository } from '../../repositories';
3
+ import { Getter, HasManyDefinition, InclusionResolver } from '../relation.types';
4
+ /**
5
+ * Creates InclusionResolver for HasMany relation.
6
+ * Notice that this function only generates the inclusionResolver.
7
+ * It doesn't register it for the source repository.
8
+ *
9
+ * Notice: scope field for inclusion is not supported yet.
10
+ *
11
+ * @param meta - resolved metadata of the hasMany relation
12
+ * @param getTargetRepo - target repository i.e where related instances are
13
+ */
14
+ export declare function createHasManyInclusionResolver<Target extends Entity, TargetID, TargetRelations extends object>(meta: HasManyDefinition, getTargetRepo: Getter<EntityCrudRepository<Target, TargetID, TargetRelations>>): InclusionResolver<Entity, Target>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2019,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.createHasManyInclusionResolver = 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:inclusion-resolver');
13
+ /**
14
+ * Creates InclusionResolver for HasMany relation.
15
+ * Notice that this function only generates the inclusionResolver.
16
+ * It doesn't register it for the source repository.
17
+ *
18
+ * Notice: scope field for inclusion is not supported yet.
19
+ *
20
+ * @param meta - resolved metadata of the hasMany relation
21
+ * @param getTargetRepo - target repository i.e where related instances are
22
+ */
23
+ function createHasManyInclusionResolver(meta, getTargetRepo) {
24
+ const relationMeta = (0, has_many_helpers_1.resolveHasManyMetadata)(meta);
25
+ return async function fetchHasManyModels(entities, inclusion, options) {
26
+ if (!entities.length)
27
+ return [];
28
+ debug('Fetching target models for entities:', entities);
29
+ debug('Relation metadata:', relationMeta);
30
+ const sourceKey = relationMeta.keyFrom;
31
+ const sourceIds = entities.map(e => e[sourceKey]);
32
+ const targetKey = relationMeta.keyTo;
33
+ debug('Parameters:', { sourceKey, sourceIds, targetKey });
34
+ debug('sourceId types', sourceIds.map(i => typeof i));
35
+ const scope = typeof inclusion === 'string' ? {} : inclusion.scope;
36
+ const targetRepo = await getTargetRepo();
37
+ const targetsFound = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, sourceIds, scope, options);
38
+ debug('Targets found:', targetsFound);
39
+ const result = (0, relation_helpers_1.flattenTargetsOfOneToManyRelation)(sourceIds, targetsFound, targetKey);
40
+ debug('fetchHasManyModels result', result);
41
+ return result;
42
+ };
43
+ }
44
+ exports.createHasManyInclusionResolver = createHasManyInclusionResolver;
45
+ //# sourceMappingURL=has-many.inclusion-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-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iB,EAC1C,UAAU,EACV,SAAS,EACT,SAAS,EACT,KAAK,EACL,OAAO,CACR,CAAC;QAEF,KAAK,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;QAEtC,MAAM,MAAM,GAAG,IAAA,oDAAiC,EAC9C,SAAS,EACT,YAAY,EACZ,SAAS,CACV,CAAC;QAEF,KAAK,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAvDD,wEAuDC"}
@@ -0,0 +1,28 @@
1
+ import { Entity } from '../../model';
2
+ import { EntityCrudRepository } from '../../repositories';
3
+ import { Getter, HasManyDefinition, InclusionResolver } from '../relation.types';
4
+ import { HasManyRepository } from './has-many.repository';
5
+ export interface HasManyRepositoryFactory<Target extends Entity, ForeignKeyType> {
6
+ /**
7
+ * Invoke the function to obtain HasManyRepository.
8
+ */
9
+ (fkValue: ForeignKeyType): HasManyRepository<Target>;
10
+ /**
11
+ * Use `resolver` property to obtain an InclusionResolver for this relation.
12
+ */
13
+ inclusionResolver: InclusionResolver<Entity, Target>;
14
+ }
15
+ /**
16
+ * Enforces a constraint on a repository based on a relationship contract
17
+ * between models. For example, if a Customer model is related to an Order model
18
+ * via a HasMany relation, then, the relational repository returned by the
19
+ * factory function would be constrained by a Customer model instance's id(s).
20
+ *
21
+ * @param relationMetadata - The relation metadata used to describe the
22
+ * relationship and determine how to apply the constraint.
23
+ * @param targetRepositoryGetter - The repository which represents the target model of a
24
+ * relation attached to a datasource.
25
+ * @returns The factory function which accepts a foreign key value to constrain
26
+ * the given target repository
27
+ */
28
+ export declare function createHasManyRepositoryFactory<Target extends Entity, TargetID, ForeignKeyType>(relationMetadata: HasManyDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>): HasManyRepositoryFactory<Target, ForeignKeyType>;
@@ -0,0 +1,39 @@
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.createHasManyRepositoryFactory = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
10
+ const has_many_helpers_1 = require("./has-many.helpers");
11
+ const has_many_inclusion_resolver_1 = require("./has-many.inclusion-resolver");
12
+ const has_many_repository_1 = require("./has-many.repository");
13
+ const debug = (0, debug_1.default)('loopback:repository:relations:has-many:repository-factory');
14
+ /**
15
+ * Enforces a constraint on a repository based on a relationship contract
16
+ * between models. For example, if a Customer model is related to an Order model
17
+ * via a HasMany relation, then, the relational repository returned by the
18
+ * factory function would be constrained by a Customer model instance's id(s).
19
+ *
20
+ * @param relationMetadata - The relation metadata used to describe the
21
+ * relationship and determine how to apply the constraint.
22
+ * @param targetRepositoryGetter - The repository which represents the target model of a
23
+ * relation attached to a datasource.
24
+ * @returns The factory function which accepts a foreign key value to constrain
25
+ * the given target repository
26
+ */
27
+ function createHasManyRepositoryFactory(relationMetadata, targetRepositoryGetter) {
28
+ const meta = (0, has_many_helpers_1.resolveHasManyMetadata)(relationMetadata);
29
+ debug('Resolved HasMany relation metadata: %o', meta);
30
+ const result = function (fkValue) {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ const constraint = { [meta.keyTo]: fkValue };
33
+ return new has_many_repository_1.DefaultHasManyRepository(targetRepositoryGetter, constraint);
34
+ };
35
+ result.inclusionResolver = (0, has_many_inclusion_resolver_1.createHasManyInclusionResolver)(meta, targetRepositoryGetter);
36
+ return result;
37
+ }
38
+ exports.createHasManyRepositoryFactory = createHasManyRepositoryFactory;
39
+ //# sourceMappingURL=has-many.repository-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many.repository-factory.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many.repository-factory.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAiC;AAKjC,yDAA0D;AAC1D,+EAA6E;AAC7E,+DAG+B;AAE/B,MAAM,KAAK,GAAG,IAAA,eAAY,EACxB,2DAA2D,CAC5D,CAAC;AAiBF;;;;;;;;;;;;GAYG;AACH,SAAgB,8BAA8B,CAK5C,gBAAmC,EACnC,sBAAsE;IAEtE,MAAM,IAAI,GAAG,IAAA,yCAAsB,EAAC,gBAAgB,CAAC,CAAC;IACtD,KAAK,CAAC,wCAAwC,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,MAAM,GAAqD,UAC/D,OAAuB;QAEvB,8DAA8D;QAC9D,MAAM,UAAU,GAAQ,EAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAC,CAAC;QAChD,OAAO,IAAI,8CAAwB,CAIjC,sBAAsB,EAAE,UAAgC,CAAC,CAAC;IAC9D,CAAC,CAAC;IACF,MAAM,CAAC,iBAAiB,GAAG,IAAA,4DAA8B,EACvD,IAAI,EACJ,sBAAsB,CACvB,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,wEA0BC"}