@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,441 @@
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 {Filter, FilterExcludingWhere, Where} from '@loopback/filter';
7
+ import {
8
+ AnyObject,
9
+ Command,
10
+ Count,
11
+ DataObject,
12
+ NamedParameters,
13
+ Options,
14
+ PositionalParameters,
15
+ } from '../common-types';
16
+ import {CrudConnector} from '../connectors';
17
+ import {DataSource} from '../datasource';
18
+ import {EntityNotFoundError} from '../errors';
19
+ import {Entity, Model, ValueObject} from '../model';
20
+ import {InclusionResolver} from '../relations/relation.types';
21
+ import {IsolationLevel, Transaction} from '../transaction';
22
+
23
+ /* eslint-disable @typescript-eslint/no-unused-vars */
24
+
25
+ export interface Repository<T extends Model> {}
26
+
27
+ export interface ExecutableRepository<T extends Model> extends Repository<T> {
28
+ /**
29
+ * Execute a query with the given parameter object or an array of parameters
30
+ * @param command - The query string or command object
31
+ * @param parameters - The object with name/value pairs or an array of parameter
32
+ * values
33
+ * @param options - Options
34
+ */
35
+ execute(
36
+ command: Command,
37
+ parameters: NamedParameters | PositionalParameters,
38
+ options?: Options,
39
+ ): Promise<AnyObject>;
40
+ }
41
+
42
+ /**
43
+ * A type for CRUD repositories that are backed by IDs and support
44
+ * Transactions
45
+ */
46
+ export type TransactionalEntityRepository<
47
+ T extends Entity,
48
+ ID,
49
+ Relations extends object = {},
50
+ > = TransactionalRepository<T> & EntityCrudRepository<T, ID>;
51
+ /**
52
+ * Repository Interface for Repositories that support Transactions
53
+ *
54
+ * @typeParam T Generic type for the Entity
55
+ */
56
+ export interface TransactionalRepository<T extends Entity>
57
+ extends Repository<T> {
58
+ /**
59
+ * Begin a new Transaction
60
+ * @param options - Options for the operations
61
+ * @returns Promise<Transaction> Promise that resolves to a new Transaction
62
+ * object
63
+ */
64
+ beginTransaction(options?: IsolationLevel | Options): Promise<Transaction>;
65
+ }
66
+
67
+ /**
68
+ * Basic CRUD operations for ValueObject and Entity. No ID is required.
69
+ */
70
+ export interface CrudRepository<
71
+ T extends ValueObject | Entity,
72
+ Relations extends object = {},
73
+ > extends Repository<T> {
74
+ /**
75
+ * Create a new record
76
+ * @param dataObject - The data to be created
77
+ * @param options - Options for the operations
78
+ * @returns A promise of record created
79
+ */
80
+ create(dataObject: DataObject<T>, options?: Options): Promise<T>;
81
+
82
+ /**
83
+ * Create all records
84
+ * @param dataObjects - An array of data to be created
85
+ * @param options - Options for the operations
86
+ * @returns A promise of an array of records created
87
+ */
88
+ createAll(dataObjects: DataObject<T>[], options?: Options): Promise<T[]>;
89
+
90
+ /**
91
+ * Find matching records
92
+ * @param filter - Query filter
93
+ * @param options - Options for the operations
94
+ * @returns A promise of an array of records found
95
+ */
96
+ find(filter?: Filter<T>, options?: Options): Promise<(T & Relations)[]>;
97
+
98
+ /**
99
+ * Updating matching records with attributes from the data object
100
+ * @param dataObject - The data to be updated
101
+ * @param where - Matching criteria
102
+ * @param options - Options for the operations
103
+ * @returns A promise of number of records updated
104
+ */
105
+ updateAll(
106
+ dataObject: DataObject<T>,
107
+ where?: Where<T>,
108
+ options?: Options,
109
+ ): Promise<Count>;
110
+
111
+ /**
112
+ * Delete matching records
113
+ * @param where - Matching criteria
114
+ * @param options - Options for the operations
115
+ * @returns A promise of number of records deleted
116
+ */
117
+ deleteAll(where?: Where<T>, options?: Options): Promise<Count>;
118
+
119
+ /**
120
+ * Count matching records
121
+ * @param where - Matching criteria
122
+ * @param options - Options for the operations
123
+ * @returns A promise of number of records matched
124
+ */
125
+ count(where?: Where<T>, options?: Options): Promise<Count>;
126
+ }
127
+
128
+ /**
129
+ * Base interface for a repository of entities
130
+ */
131
+ export interface EntityRepository<T extends Entity, ID>
132
+ extends ExecutableRepository<T> {}
133
+
134
+ /**
135
+ * CRUD operations for a repository of entities
136
+ */
137
+ export interface EntityCrudRepository<
138
+ T extends Entity,
139
+ ID,
140
+ Relations extends object = {},
141
+ > extends EntityRepository<T, ID>,
142
+ CrudRepository<T, Relations> {
143
+ // entityClass should have type "typeof T", but that's not supported by TSC
144
+ entityClass: typeof Entity & {prototype: T};
145
+ inclusionResolvers: Map<string, InclusionResolver<T, Entity>>;
146
+
147
+ /**
148
+ * Save an entity. If no id is present, create a new entity
149
+ * @param entity - Entity to be saved
150
+ * @param options - Options for the operations
151
+ * @returns A promise that will be resolve if the operation succeeded or will
152
+ * be rejected if the entity was not found.
153
+ */
154
+ save(entity: DataObject<T>, options?: Options): Promise<T>;
155
+
156
+ /**
157
+ * Update an entity
158
+ * @param entity - Entity to be updated
159
+ * @param options - Options for the operations
160
+ * @returns A promise that will be resolve if the operation succeeded or will
161
+ * be rejected if the entity was not found.
162
+ */
163
+ update(entity: DataObject<T>, options?: Options): Promise<void>;
164
+
165
+ /**
166
+ * Delete an entity
167
+ * @param entity - Entity to be deleted
168
+ * @param options - Options for the operations
169
+ * @returns A promise that will be resolve if the operation succeeded or will
170
+ * be rejected if the entity was not found.
171
+ */
172
+ delete(entity: DataObject<T>, options?: Options): Promise<void>;
173
+
174
+ /**
175
+ * Find an entity by id, return a rejected promise if not found.
176
+ *
177
+ * @remarks
178
+ *
179
+ * The rationale behind findById is to find an instance by its primary key
180
+ * (id). No other search criteria than id should be used. If a client wants
181
+ * to use a `where` clause beyond id, use `find` or `findOne` instead.
182
+ *
183
+ * @param id - Value for the entity id
184
+ * @param filter - Additional query options. E.g. `filter.include` configures
185
+ * which related models to fetch as part of the database query (or queries).
186
+ * @param options - Options for the operations
187
+ * @returns A promise of an entity found for the id
188
+ */
189
+ findById(
190
+ id: ID,
191
+ filter?: FilterExcludingWhere<T>,
192
+ options?: Options,
193
+ ): Promise<T & Relations>;
194
+
195
+ /**
196
+ * Update an entity by id with property/value pairs in the data object
197
+ * @param id - Value for the entity id
198
+ * @param data - Data attributes to be updated
199
+ * @param options - Options for the operations
200
+ * @returns A promise that will be resolve if the operation succeeded or will
201
+ * be rejected if the entity was not found.
202
+ */
203
+ updateById(id: ID, data: DataObject<T>, options?: Options): Promise<void>;
204
+
205
+ /**
206
+ * Replace an entity by id
207
+ * @param id - Value for the entity id
208
+ * @param data - Data attributes to be replaced
209
+ * @param options - Options for the operations
210
+ * @returns A promise that will be resolve if the operation succeeded or will
211
+ * be rejected if the entity was not found.
212
+ */
213
+ replaceById(id: ID, data: DataObject<T>, options?: Options): Promise<void>;
214
+
215
+ /**
216
+ * Delete an entity by id
217
+ * @param id - Value for the entity id
218
+ * @param options - Options for the operations
219
+ * @returns A promise that will be resolve if the operation succeeded or will
220
+ * be rejected if the entity was not found.
221
+ */
222
+ deleteById(id: ID, options?: Options): Promise<void>;
223
+
224
+ /**
225
+ * Check if an entity exists for the given id
226
+ * @param id - Value for the entity id
227
+ * @param options - Options for the operations
228
+ * @returns Promise<true> if an entity exists for the id, otherwise
229
+ * Promise<false>
230
+ */
231
+ exists(id: ID, options?: Options): Promise<boolean>;
232
+ }
233
+
234
+ /**
235
+ * Repository implementation
236
+ *
237
+ * @example
238
+ *
239
+ * User can import `CrudRepositoryImpl` and call its functions like:
240
+ * `CrudRepositoryImpl.find(somefilters, someoptions)`
241
+ *
242
+ * Or extend class `CrudRepositoryImpl` and override its functions:
243
+ * ```ts
244
+ * export class TestRepository extends CrudRepositoryImpl<Test> {
245
+ * constructor(dataSource: DataSource, model: Test) {
246
+ * super(dataSource, Customer);
247
+ * }
248
+ *
249
+ * // Override `deleteAll` to disable the operation
250
+ * deleteAll(where?: Where, options?: Options) {
251
+ * return Promise.reject(new Error('deleteAll is disabled'));
252
+ * }
253
+ * }
254
+ * ```
255
+ */
256
+ export class CrudRepositoryImpl<T extends Entity, ID>
257
+ implements EntityCrudRepository<T, ID>
258
+ {
259
+ private connector: CrudConnector;
260
+ public readonly inclusionResolvers: Map<
261
+ string,
262
+ InclusionResolver<T, Entity>
263
+ > = new Map();
264
+
265
+ constructor(
266
+ public dataSource: DataSource,
267
+ // model should have type "typeof T", but that's not supported by TSC
268
+ public entityClass: typeof Entity & {prototype: T},
269
+ ) {
270
+ this.connector = dataSource.connector as CrudConnector;
271
+ }
272
+
273
+ private toModels(data: Promise<DataObject<Entity>[]>): Promise<T[]> {
274
+ return data.then(items => items.map(i => new this.entityClass(i) as T));
275
+ }
276
+
277
+ private toModel(data: Promise<DataObject<Entity>>): Promise<T> {
278
+ return data.then(d => new this.entityClass(d) as T);
279
+ }
280
+
281
+ create(entity: DataObject<T>, options?: Options): Promise<T> {
282
+ return this.toModel(
283
+ this.connector.create(this.entityClass, entity, options),
284
+ );
285
+ }
286
+
287
+ createAll(entities: DataObject<T>[], options?: Options): Promise<T[]> {
288
+ return this.toModels(
289
+ this.connector.createAll!(this.entityClass, entities, options),
290
+ );
291
+ }
292
+
293
+ async save(entity: DataObject<T>, options?: Options): Promise<T> {
294
+ if (typeof this.connector.save === 'function') {
295
+ return this.toModel(
296
+ this.connector.save(this.entityClass, entity, options),
297
+ );
298
+ } else {
299
+ const id = this.entityClass.getIdOf(entity);
300
+ if (id != null) {
301
+ await this.replaceById(id, entity, options);
302
+ return this.toModel(Promise.resolve(entity));
303
+ } else {
304
+ return this.create(entity, options);
305
+ }
306
+ }
307
+ }
308
+
309
+ find(filter?: Filter<T>, options?: Options): Promise<T[]> {
310
+ return this.toModels(
311
+ this.connector.find(this.entityClass, filter, options),
312
+ );
313
+ }
314
+
315
+ async findById(
316
+ id: ID,
317
+ filter?: FilterExcludingWhere<T>,
318
+ options?: Options,
319
+ ): Promise<T> {
320
+ if (typeof this.connector.findById === 'function') {
321
+ return this.toModel(
322
+ this.connector.findById(this.entityClass, id, options),
323
+ );
324
+ }
325
+ const where = this.entityClass.buildWhereForId(id);
326
+ const entities = await this.toModels(
327
+ this.connector.find(this.entityClass, {where: where}, options),
328
+ );
329
+ if (!entities.length) {
330
+ throw new EntityNotFoundError(this.entityClass, id);
331
+ }
332
+ return entities[0];
333
+ }
334
+
335
+ update(entity: DataObject<T>, options?: Options): Promise<void> {
336
+ return this.updateById(this.entityClass.getIdOf(entity), entity, options);
337
+ }
338
+
339
+ delete(entity: DataObject<T>, options?: Options): Promise<void> {
340
+ return this.deleteById(this.entityClass.getIdOf(entity), options);
341
+ }
342
+
343
+ updateAll(
344
+ data: DataObject<T>,
345
+ where?: Where<T>,
346
+ options?: Options,
347
+ ): Promise<Count> {
348
+ return this.connector.updateAll(this.entityClass, data, where, options);
349
+ }
350
+
351
+ async updateById(
352
+ id: ID,
353
+ data: DataObject<T>,
354
+ options?: Options,
355
+ ): Promise<void> {
356
+ let success: boolean;
357
+ if (typeof this.connector.updateById === 'function') {
358
+ success = await this.connector.updateById(
359
+ this.entityClass,
360
+ id,
361
+ data,
362
+ options,
363
+ );
364
+ } else {
365
+ const where = this.entityClass.buildWhereForId(id);
366
+ const result = await this.updateAll(data, where, options);
367
+ success = result.count > 0;
368
+ }
369
+ if (!success) {
370
+ throw new EntityNotFoundError(this.entityClass, id);
371
+ }
372
+ }
373
+
374
+ async replaceById(
375
+ id: ID,
376
+ data: DataObject<T>,
377
+ options?: Options,
378
+ ): Promise<void> {
379
+ let success: boolean;
380
+ if (typeof this.connector.replaceById === 'function') {
381
+ success = await this.connector.replaceById(
382
+ this.entityClass,
383
+ id,
384
+ data,
385
+ options,
386
+ );
387
+ } else {
388
+ // FIXME: populate inst with all properties
389
+ const inst = data;
390
+ const where = this.entityClass.buildWhereForId(id);
391
+ const result = await this.updateAll(data, where, options);
392
+ success = result.count > 0;
393
+ }
394
+ if (!success) {
395
+ throw new EntityNotFoundError(this.entityClass, id);
396
+ }
397
+ }
398
+
399
+ deleteAll(where?: Where<T>, options?: Options): Promise<Count> {
400
+ return this.connector.deleteAll(this.entityClass, where, options);
401
+ }
402
+
403
+ async deleteById(id: ID, options?: Options): Promise<void> {
404
+ let success: boolean;
405
+ if (typeof this.connector.deleteById === 'function') {
406
+ success = await this.connector.deleteById(this.entityClass, id, options);
407
+ } else {
408
+ const where = this.entityClass.buildWhereForId(id);
409
+ const result = await this.deleteAll(where, options);
410
+ success = result.count > 0;
411
+ }
412
+
413
+ if (!success) {
414
+ throw new EntityNotFoundError(this.entityClass, id);
415
+ }
416
+ }
417
+
418
+ count(where?: Where<T>, options?: Options): Promise<Count> {
419
+ return this.connector.count(this.entityClass, where, options);
420
+ }
421
+
422
+ exists(id: ID, options?: Options): Promise<boolean> {
423
+ if (typeof this.connector.exists === 'function') {
424
+ return this.connector.exists(this.entityClass, id, options);
425
+ } else {
426
+ const where = this.entityClass.buildWhereForId(id);
427
+ return this.count(where, options).then(result => result.count > 0);
428
+ }
429
+ }
430
+
431
+ execute(
432
+ command: Command,
433
+ parameters: NamedParameters | PositionalParameters,
434
+ options?: Options,
435
+ ): Promise<AnyObject> {
436
+ if (typeof this.connector.execute !== 'function') {
437
+ throw new Error('Not implemented');
438
+ }
439
+ return this.connector.execute(command, parameters, options);
440
+ }
441
+ }
@@ -0,0 +1,39 @@
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
+ /**
7
+ * Local transaction
8
+ */
9
+ export interface Transaction {
10
+ /**
11
+ * Commit the transaction
12
+ */
13
+ commit(): Promise<void>;
14
+
15
+ /**
16
+ * Rollback the transaction
17
+ */
18
+ rollback(): Promise<void>;
19
+
20
+ /**
21
+ * Check if the transaction has an active connection
22
+ */
23
+ isActive(): boolean;
24
+
25
+ /**
26
+ * The transaction Identifier
27
+ */
28
+ id: string;
29
+ }
30
+
31
+ /**
32
+ * Isolation level
33
+ */
34
+ export enum IsolationLevel {
35
+ READ_COMMITTED = 'READ COMMITTED', // default
36
+ READ_UNCOMMITTED = 'READ UNCOMMITTED',
37
+ SERIALIZABLE = 'SERIALIZABLE',
38
+ REPEATABLE_READ = 'REPEATABLE READ',
39
+ }
@@ -0,0 +1,98 @@
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 {Class} from './common-types';
7
+
8
+ /**
9
+ * A type resolver is a function that returns a class representing the type,
10
+ * typically a Model or Entity (e.g. Product).
11
+ *
12
+ * We use type resolvers to break require() loops when defining relations.
13
+ * The target model (class) is provided via a provider, thus deferring
14
+ * the actual reference to the class itself until later, when both sides
15
+ * of the relation are created as JavaScript classes.
16
+ *
17
+ * @typeParam Type - The type we are resolving, for example `Entity` or `Product`.
18
+ * This parameter is required.
19
+ *
20
+ * @typeParam StaticMembers - The static properties available on the
21
+ * type class. For example, all models have static `modelName` property.
22
+ * When `StaticMembers` are not provided, we default to static properties of
23
+ * a `Function` - `name`, `length`, `apply`, `call`, etc.
24
+ * Please note the value returned by the resolver is described as having
25
+ * arbitrary additional static properties (see how Class is defined).
26
+ */
27
+ export type TypeResolver<
28
+ Type extends Object,
29
+ StaticMembers = Function,
30
+ > = () => Class<Type> & StaticMembers;
31
+
32
+ /**
33
+ * A function that checks whether a function is a TypeResolver or not.
34
+ * @param fn - The value to check.
35
+ */
36
+ export function isTypeResolver<T extends object>(
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ fn: any,
39
+ ): fn is TypeResolver<T> {
40
+ // 1. A type provider must be a function
41
+ if (typeof fn !== 'function') return false;
42
+
43
+ // 2. A class constructor is not a type provider
44
+ if (/^class/.test(fn.toString())) return false;
45
+
46
+ // 3. Built-in types like Date & Array are not type providers
47
+ if (isBuiltinType(fn)) return false;
48
+
49
+ // TODO(bajtos): support model classes defined via ES5 constructor function
50
+
51
+ return true;
52
+ }
53
+
54
+ /**
55
+ * A boxed type for `null`
56
+ */
57
+ // eslint-disable-next-line @typescript-eslint/naming-convention
58
+ export function Null() {
59
+ return null;
60
+ }
61
+
62
+ /**
63
+ * Check if the provided function is a built-in type provided by JavaScript
64
+ * and/or Node.js. E.g. `Number`, `Array`, `Buffer`, etc.
65
+ */
66
+ export function isBuiltinType(fn: Function): boolean {
67
+ return (
68
+ // scalars
69
+ fn === Number ||
70
+ fn === Boolean ||
71
+ fn === String ||
72
+ // objects
73
+ fn === Object ||
74
+ fn === Array ||
75
+ fn === Date ||
76
+ fn === RegExp ||
77
+ fn === Buffer ||
78
+ fn === Null ||
79
+ // function as a type
80
+ fn === Function
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Resolve a type value that may have been provided via TypeResolver.
86
+ * @param fn - A type class or a type provider.
87
+ * @returns The resolved type.
88
+ */
89
+ export function resolveType<T extends Object>(
90
+ fn: TypeResolver<T> | Class<T>,
91
+ ): Class<T>;
92
+
93
+ // An overload to handle the case when `fn` is not a class nor a resolver.
94
+ export function resolveType<T>(fn: T): T;
95
+
96
+ export function resolveType<T>(fn: TypeResolver<T> | Class<T>) {
97
+ return isTypeResolver(fn) ? fn() : fn;
98
+ }
@@ -0,0 +1,38 @@
1
+ // Copyright IBM Corp. 2017,2019. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {Type} from './type';
7
+
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+
10
+ /**
11
+ * Any type
12
+ */
13
+ export class AnyType implements Type<any> {
14
+ readonly name = 'any';
15
+
16
+ isInstance(value: any) {
17
+ return true;
18
+ }
19
+
20
+ isCoercible(value: any) {
21
+ return true;
22
+ }
23
+
24
+ defaultValue(): any {
25
+ return undefined;
26
+ }
27
+
28
+ coerce(value: any) {
29
+ return value;
30
+ }
31
+
32
+ serialize(value: any) {
33
+ if (value && typeof value.toJSON === 'function') {
34
+ return value.toJSON();
35
+ }
36
+ return value;
37
+ }
38
+ }
@@ -0,0 +1,53 @@
1
+ // Copyright IBM Corp. 2017,2019. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import util from 'util';
7
+ import {Type} from './type';
8
+
9
+ /* eslint-disable @typescript-eslint/no-explicit-any */
10
+
11
+ /**
12
+ * Array type, such as string[]
13
+ */
14
+ export class ArrayType<T> implements Type<T[]> {
15
+ constructor(public itemType: Type<T>) {}
16
+
17
+ readonly name = 'array';
18
+
19
+ isInstance(value: any) {
20
+ if (value == null) return true;
21
+ if (!Array.isArray(value)) {
22
+ return false;
23
+ }
24
+ const list = value as (T | null | undefined)[];
25
+ return list.every(i => this.itemType.isInstance(i));
26
+ }
27
+
28
+ isCoercible(value: any): boolean {
29
+ if (value == null) return true;
30
+ if (!Array.isArray(value)) {
31
+ return false;
32
+ }
33
+ return value.every(i => this.itemType.isCoercible(i));
34
+ }
35
+
36
+ defaultValue(): T[] {
37
+ return [];
38
+ }
39
+
40
+ coerce(value: any) {
41
+ if (value == null) return value;
42
+ if (!Array.isArray(value)) {
43
+ const msg = util.format('Invalid %s: %j', this.name, value);
44
+ throw new TypeError(msg);
45
+ }
46
+ return value.map(i => this.itemType.coerce(i));
47
+ }
48
+
49
+ serialize(value: T[] | null | undefined) {
50
+ if (value == null) return value;
51
+ return value.map(i => this.itemType.serialize(i));
52
+ }
53
+ }
@@ -0,0 +1,35 @@
1
+ // Copyright IBM Corp. 2017,2019. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import {Type} from './type';
7
+
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+
10
+ /**
11
+ * Boolean type
12
+ */
13
+ export class BooleanType implements Type<boolean> {
14
+ readonly name = 'boolean';
15
+
16
+ isInstance(value: any) {
17
+ return value == null || typeof value === 'boolean';
18
+ }
19
+
20
+ defaultValue() {
21
+ return false;
22
+ }
23
+
24
+ isCoercible(value: any): boolean {
25
+ return true;
26
+ }
27
+
28
+ coerce(value: any) {
29
+ return value == null ? value : Boolean(value);
30
+ }
31
+
32
+ serialize(value: boolean | null | undefined) {
33
+ return value;
34
+ }
35
+ }