@monorise/core 1.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 (578) hide show
  1. package/configs/service.config.ts +14 -0
  2. package/constants/table.ts +3 -0
  3. package/controllers/entity/create-entity.controller.ts +51 -0
  4. package/controllers/entity/delete-entity.controller.ts +35 -0
  5. package/controllers/entity/entity.http +62 -0
  6. package/controllers/entity/get-entity.controller.ts +33 -0
  7. package/controllers/entity/list-entities.controller.ts +69 -0
  8. package/controllers/entity/update-entity.controller.ts +56 -0
  9. package/controllers/entity/upsert-entity.controller.ts +97 -0
  10. package/controllers/mutual/create-mutual.controller.ts +89 -0
  11. package/controllers/mutual/delete-mutual.controller.ts +40 -0
  12. package/controllers/mutual/get-mutual.controller.ts +38 -0
  13. package/controllers/mutual/list-entities-by-entity.controller.ts +76 -0
  14. package/controllers/mutual/mutual.http +88 -0
  15. package/controllers/mutual/update-mutual.controller.ts +50 -0
  16. package/controllers/setupRoutes.ts +73 -0
  17. package/controllers/tag/list-tags.controller.ts +57 -0
  18. package/data/DbUtils.ts +40 -0
  19. package/data/Entity.ts +499 -0
  20. package/data/EventUtils.ts +47 -0
  21. package/data/FileObject.ts +16 -0
  22. package/data/Mutual.ts +779 -0
  23. package/data/ProjectionExpression.ts +8 -0
  24. package/data/Tag.ts +470 -0
  25. package/data/abstract/Item.base.ts +19 -0
  26. package/data/abstract/Repository.base.ts +92 -0
  27. package/dist/configs/service.config.d.ts +5 -0
  28. package/dist/configs/service.config.d.ts.map +1 -0
  29. package/dist/configs/service.config.js +5 -0
  30. package/dist/configs/service.config.js.map +1 -0
  31. package/dist/constants/table.d.ts +4 -0
  32. package/dist/constants/table.d.ts.map +1 -0
  33. package/dist/constants/table.js +4 -0
  34. package/dist/constants/table.js.map +1 -0
  35. package/dist/controllers/entity/create-entity.controller.d.ts +8 -0
  36. package/dist/controllers/entity/create-entity.controller.d.ts.map +1 -0
  37. package/dist/controllers/entity/create-entity.controller.js +44 -0
  38. package/dist/controllers/entity/create-entity.controller.js.map +1 -0
  39. package/dist/controllers/entity/delete-entity.controller.d.ts +8 -0
  40. package/dist/controllers/entity/delete-entity.controller.d.ts.map +1 -0
  41. package/dist/controllers/entity/delete-entity.controller.js +29 -0
  42. package/dist/controllers/entity/delete-entity.controller.js.map +1 -0
  43. package/dist/controllers/entity/get-entity.controller.d.ts +8 -0
  44. package/dist/controllers/entity/get-entity.controller.d.ts.map +1 -0
  45. package/dist/controllers/entity/get-entity.controller.js +24 -0
  46. package/dist/controllers/entity/get-entity.controller.js.map +1 -0
  47. package/dist/controllers/entity/list-entities.controller.d.ts +8 -0
  48. package/dist/controllers/entity/list-entities.controller.d.ts.map +1 -0
  49. package/dist/controllers/entity/list-entities.controller.js +56 -0
  50. package/dist/controllers/entity/list-entities.controller.js.map +1 -0
  51. package/dist/controllers/entity/update-entity.controller.d.ts +8 -0
  52. package/dist/controllers/entity/update-entity.controller.d.ts.map +1 -0
  53. package/dist/controllers/entity/update-entity.controller.js +45 -0
  54. package/dist/controllers/entity/update-entity.controller.js.map +1 -0
  55. package/dist/controllers/entity/upsert-entity.controller.d.ts +10 -0
  56. package/dist/controllers/entity/upsert-entity.controller.d.ts.map +1 -0
  57. package/dist/controllers/entity/upsert-entity.controller.js +73 -0
  58. package/dist/controllers/entity/upsert-entity.controller.js.map +1 -0
  59. package/dist/controllers/mutual/create-mutual.controller.d.ts +10 -0
  60. package/dist/controllers/mutual/create-mutual.controller.d.ts.map +1 -0
  61. package/dist/controllers/mutual/create-mutual.controller.js +70 -0
  62. package/dist/controllers/mutual/create-mutual.controller.js.map +1 -0
  63. package/dist/controllers/mutual/delete-mutual.controller.d.ts +8 -0
  64. package/dist/controllers/mutual/delete-mutual.controller.d.ts.map +1 -0
  65. package/dist/controllers/mutual/delete-mutual.controller.js +31 -0
  66. package/dist/controllers/mutual/delete-mutual.controller.js.map +1 -0
  67. package/dist/controllers/mutual/get-mutual.controller.d.ts +8 -0
  68. package/dist/controllers/mutual/get-mutual.controller.d.ts.map +1 -0
  69. package/dist/controllers/mutual/get-mutual.controller.js +24 -0
  70. package/dist/controllers/mutual/get-mutual.controller.js.map +1 -0
  71. package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts +8 -0
  72. package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts.map +1 -0
  73. package/dist/controllers/mutual/list-entities-by-entity.controller.js +56 -0
  74. package/dist/controllers/mutual/list-entities-by-entity.controller.js.map +1 -0
  75. package/dist/controllers/mutual/update-mutual.controller.d.ts +8 -0
  76. package/dist/controllers/mutual/update-mutual.controller.d.ts.map +1 -0
  77. package/dist/controllers/mutual/update-mutual.controller.js +40 -0
  78. package/dist/controllers/mutual/update-mutual.controller.js.map +1 -0
  79. package/dist/controllers/setupRoutes.d.ts +4 -0
  80. package/dist/controllers/setupRoutes.d.ts.map +1 -0
  81. package/dist/controllers/setupRoutes.js +31 -0
  82. package/dist/controllers/setupRoutes.js.map +1 -0
  83. package/dist/controllers/tag/list-tags.controller.d.ts +8 -0
  84. package/dist/controllers/tag/list-tags.controller.d.ts.map +1 -0
  85. package/dist/controllers/tag/list-tags.controller.js +48 -0
  86. package/dist/controllers/tag/list-tags.controller.js.map +1 -0
  87. package/dist/data/DbUtils.d.ts +7 -0
  88. package/dist/data/DbUtils.d.ts.map +1 -0
  89. package/dist/data/DbUtils.js +23 -0
  90. package/dist/data/DbUtils.js.map +1 -0
  91. package/dist/data/Entity.d.ts +71 -0
  92. package/dist/data/Entity.d.ts.map +1 -0
  93. package/dist/data/Entity.js +358 -0
  94. package/dist/data/Entity.js.map +1 -0
  95. package/dist/data/EventUtils.d.ts +14 -0
  96. package/dist/data/EventUtils.d.ts.map +1 -0
  97. package/dist/data/EventUtils.js +34 -0
  98. package/dist/data/EventUtils.js.map +1 -0
  99. package/dist/data/FileObject.d.ts +62 -0
  100. package/dist/data/FileObject.d.ts.map +1 -0
  101. package/dist/data/FileObject.js +13 -0
  102. package/dist/data/FileObject.js.map +1 -0
  103. package/dist/data/Mutual.d.ts +94 -0
  104. package/dist/data/Mutual.d.ts.map +1 -0
  105. package/dist/data/Mutual.js +492 -0
  106. package/dist/data/Mutual.js.map +1 -0
  107. package/dist/data/ProjectionExpression.d.ts +6 -0
  108. package/dist/data/ProjectionExpression.d.ts.map +1 -0
  109. package/dist/data/ProjectionExpression.js +5 -0
  110. package/dist/data/ProjectionExpression.js.map +1 -0
  111. package/dist/data/Tag.d.ts +77 -0
  112. package/dist/data/Tag.d.ts.map +1 -0
  113. package/dist/data/Tag.js +330 -0
  114. package/dist/data/Tag.js.map +1 -0
  115. package/dist/data/abstract/Item.base.d.ts +11 -0
  116. package/dist/data/abstract/Item.base.d.ts.map +1 -0
  117. package/dist/data/abstract/Item.base.js +9 -0
  118. package/dist/data/abstract/Item.base.js.map +1 -0
  119. package/dist/data/abstract/Repository.base.d.ts +11 -0
  120. package/dist/data/abstract/Repository.base.d.ts.map +1 -0
  121. package/dist/data/abstract/Repository.base.js +54 -0
  122. package/dist/data/abstract/Repository.base.js.map +1 -0
  123. package/dist/errors/api-error.d.ts +23 -0
  124. package/dist/errors/api-error.d.ts.map +1 -0
  125. package/dist/errors/api-error.js +26 -0
  126. package/dist/errors/api-error.js.map +1 -0
  127. package/dist/errors/extendable-error.d.ts +18 -0
  128. package/dist/errors/extendable-error.d.ts.map +1 -0
  129. package/dist/errors/extendable-error.js +22 -0
  130. package/dist/errors/extendable-error.js.map +1 -0
  131. package/dist/errors/standard-error.d.ts +11 -0
  132. package/dist/errors/standard-error.d.ts.map +1 -0
  133. package/dist/errors/standard-error.js +21 -0
  134. package/dist/errors/standard-error.js.map +1 -0
  135. package/dist/helpers/dependencies.d.ts +8 -0
  136. package/dist/helpers/dependencies.d.ts.map +1 -0
  137. package/dist/helpers/dependencies.js +10 -0
  138. package/dist/helpers/dependencies.js.map +1 -0
  139. package/dist/helpers/event.d.ts +22 -0
  140. package/dist/helpers/event.d.ts.map +1 -0
  141. package/dist/helpers/event.js +47 -0
  142. package/dist/helpers/event.js.map +1 -0
  143. package/dist/helpers/fromLastKeyQuery.d.ts +3 -0
  144. package/dist/helpers/fromLastKeyQuery.d.ts.map +1 -0
  145. package/dist/helpers/fromLastKeyQuery.js +7 -0
  146. package/dist/helpers/fromLastKeyQuery.js.map +1 -0
  147. package/dist/helpers/sleep.d.ts +2 -0
  148. package/dist/helpers/sleep.d.ts.map +1 -0
  149. package/dist/helpers/sleep.js +2 -0
  150. package/dist/helpers/sleep.js.map +1 -0
  151. package/dist/helpers/toLastKeyResponse.d.ts +3 -0
  152. package/dist/helpers/toLastKeyResponse.d.ts.map +1 -0
  153. package/dist/helpers/toLastKeyResponse.js +7 -0
  154. package/dist/helpers/toLastKeyResponse.js.map +1 -0
  155. package/dist/index.d.ts +12 -0
  156. package/dist/index.d.ts.map +1 -0
  157. package/dist/index.js +12 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/middlewares/entity-type-check.d.ts +3 -0
  160. package/dist/middlewares/entity-type-check.d.ts.map +1 -0
  161. package/dist/middlewares/entity-type-check.js +12 -0
  162. package/dist/middlewares/entity-type-check.js.map +1 -0
  163. package/dist/middlewares/mutual-type-check.d.ts +3 -0
  164. package/dist/middlewares/mutual-type-check.d.ts.map +1 -0
  165. package/dist/middlewares/mutual-type-check.js +13 -0
  166. package/dist/middlewares/mutual-type-check.js.map +1 -0
  167. package/dist/mock/container.d.ts +3 -0
  168. package/dist/mock/container.d.ts.map +1 -0
  169. package/dist/mock/container.js +3 -0
  170. package/dist/mock/container.js.map +1 -0
  171. package/dist/mock/entity.d.ts +13 -0
  172. package/dist/mock/entity.d.ts.map +1 -0
  173. package/dist/mock/entity.js +14 -0
  174. package/dist/mock/entity.js.map +1 -0
  175. package/dist/mock/monorise/admin.d.ts +127 -0
  176. package/dist/mock/monorise/admin.d.ts.map +1 -0
  177. package/dist/mock/monorise/admin.js +29 -0
  178. package/dist/mock/monorise/admin.js.map +1 -0
  179. package/dist/mock/monorise/chapter.d.ts +457 -0
  180. package/dist/mock/monorise/chapter.d.ts.map +1 -0
  181. package/dist/mock/monorise/chapter.js +81 -0
  182. package/dist/mock/monorise/chapter.js.map +1 -0
  183. package/dist/mock/monorise/course.d.ts +311 -0
  184. package/dist/mock/monorise/course.d.ts.map +1 -0
  185. package/dist/mock/monorise/course.js +128 -0
  186. package/dist/mock/monorise/course.js.map +1 -0
  187. package/dist/mock/monorise/index.d.ts +3599 -0
  188. package/dist/mock/monorise/index.d.ts.map +1 -0
  189. package/dist/mock/monorise/index.js +62 -0
  190. package/dist/mock/monorise/index.js.map +1 -0
  191. package/dist/mock/monorise/learner.d.ts +390 -0
  192. package/dist/mock/monorise/learner.d.ts.map +1 -0
  193. package/dist/mock/monorise/learner.js +59 -0
  194. package/dist/mock/monorise/learner.js.map +1 -0
  195. package/dist/mock/monorise/learning-activity.d.ts +266 -0
  196. package/dist/mock/monorise/learning-activity.d.ts.map +1 -0
  197. package/dist/mock/monorise/learning-activity.js +50 -0
  198. package/dist/mock/monorise/learning-activity.js.map +1 -0
  199. package/dist/mock/monorise/learning-journey-config.d.ts +84 -0
  200. package/dist/mock/monorise/learning-journey-config.d.ts.map +1 -0
  201. package/dist/mock/monorise/learning-journey-config.js +27 -0
  202. package/dist/mock/monorise/learning-journey-config.js.map +1 -0
  203. package/dist/mock/monorise/module.d.ts +211 -0
  204. package/dist/mock/monorise/module.d.ts.map +1 -0
  205. package/dist/mock/monorise/module.js +91 -0
  206. package/dist/mock/monorise/module.js.map +1 -0
  207. package/dist/mock/monorise/organization.d.ts +346 -0
  208. package/dist/mock/monorise/organization.d.ts.map +1 -0
  209. package/dist/mock/monorise/organization.js +54 -0
  210. package/dist/mock/monorise/organization.js.map +1 -0
  211. package/dist/mock/monorise/reference.d.ts +171 -0
  212. package/dist/mock/monorise/reference.d.ts.map +1 -0
  213. package/dist/mock/monorise/reference.js +25 -0
  214. package/dist/mock/monorise/reference.js.map +1 -0
  215. package/dist/mock/monorise/video.d.ts +346 -0
  216. package/dist/mock/monorise/video.d.ts.map +1 -0
  217. package/dist/mock/monorise/video.js +33 -0
  218. package/dist/mock/monorise/video.js.map +1 -0
  219. package/dist/packages/core/configs/service.config.d.ts +5 -0
  220. package/dist/packages/core/configs/service.config.d.ts.map +1 -0
  221. package/dist/packages/core/configs/service.config.js +5 -0
  222. package/dist/packages/core/configs/service.config.js.map +1 -0
  223. package/dist/packages/core/constants/table.d.ts +4 -0
  224. package/dist/packages/core/constants/table.d.ts.map +1 -0
  225. package/dist/packages/core/constants/table.js +4 -0
  226. package/dist/packages/core/constants/table.js.map +1 -0
  227. package/dist/packages/core/controllers/entity/create-entity.controller.d.ts +8 -0
  228. package/dist/packages/core/controllers/entity/create-entity.controller.d.ts.map +1 -0
  229. package/dist/packages/core/controllers/entity/create-entity.controller.js +44 -0
  230. package/dist/packages/core/controllers/entity/create-entity.controller.js.map +1 -0
  231. package/dist/packages/core/controllers/entity/delete-entity.controller.d.ts +8 -0
  232. package/dist/packages/core/controllers/entity/delete-entity.controller.d.ts.map +1 -0
  233. package/dist/packages/core/controllers/entity/delete-entity.controller.js +29 -0
  234. package/dist/packages/core/controllers/entity/delete-entity.controller.js.map +1 -0
  235. package/dist/packages/core/controllers/entity/get-entity.controller.d.ts +8 -0
  236. package/dist/packages/core/controllers/entity/get-entity.controller.d.ts.map +1 -0
  237. package/dist/packages/core/controllers/entity/get-entity.controller.js +24 -0
  238. package/dist/packages/core/controllers/entity/get-entity.controller.js.map +1 -0
  239. package/dist/packages/core/controllers/entity/list-entities.controller.d.ts +8 -0
  240. package/dist/packages/core/controllers/entity/list-entities.controller.d.ts.map +1 -0
  241. package/dist/packages/core/controllers/entity/list-entities.controller.js +56 -0
  242. package/dist/packages/core/controllers/entity/list-entities.controller.js.map +1 -0
  243. package/dist/packages/core/controllers/entity/update-entity.controller.d.ts +8 -0
  244. package/dist/packages/core/controllers/entity/update-entity.controller.d.ts.map +1 -0
  245. package/dist/packages/core/controllers/entity/update-entity.controller.js +45 -0
  246. package/dist/packages/core/controllers/entity/update-entity.controller.js.map +1 -0
  247. package/dist/packages/core/controllers/entity/upsert-entity.controller.d.ts +10 -0
  248. package/dist/packages/core/controllers/entity/upsert-entity.controller.d.ts.map +1 -0
  249. package/dist/packages/core/controllers/entity/upsert-entity.controller.js +73 -0
  250. package/dist/packages/core/controllers/entity/upsert-entity.controller.js.map +1 -0
  251. package/dist/packages/core/controllers/mutual/create-mutual.controller.d.ts +10 -0
  252. package/dist/packages/core/controllers/mutual/create-mutual.controller.d.ts.map +1 -0
  253. package/dist/packages/core/controllers/mutual/create-mutual.controller.js +70 -0
  254. package/dist/packages/core/controllers/mutual/create-mutual.controller.js.map +1 -0
  255. package/dist/packages/core/controllers/mutual/delete-mutual.controller.d.ts +8 -0
  256. package/dist/packages/core/controllers/mutual/delete-mutual.controller.d.ts.map +1 -0
  257. package/dist/packages/core/controllers/mutual/delete-mutual.controller.js +31 -0
  258. package/dist/packages/core/controllers/mutual/delete-mutual.controller.js.map +1 -0
  259. package/dist/packages/core/controllers/mutual/get-mutual.controller.d.ts +8 -0
  260. package/dist/packages/core/controllers/mutual/get-mutual.controller.d.ts.map +1 -0
  261. package/dist/packages/core/controllers/mutual/get-mutual.controller.js +24 -0
  262. package/dist/packages/core/controllers/mutual/get-mutual.controller.js.map +1 -0
  263. package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.d.ts +8 -0
  264. package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.d.ts.map +1 -0
  265. package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.js +56 -0
  266. package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.js.map +1 -0
  267. package/dist/packages/core/controllers/mutual/update-mutual.controller.d.ts +8 -0
  268. package/dist/packages/core/controllers/mutual/update-mutual.controller.d.ts.map +1 -0
  269. package/dist/packages/core/controllers/mutual/update-mutual.controller.js +40 -0
  270. package/dist/packages/core/controllers/mutual/update-mutual.controller.js.map +1 -0
  271. package/dist/packages/core/controllers/setupRoutes.d.ts +3 -0
  272. package/dist/packages/core/controllers/setupRoutes.d.ts.map +1 -0
  273. package/dist/packages/core/controllers/setupRoutes.js +33 -0
  274. package/dist/packages/core/controllers/setupRoutes.js.map +1 -0
  275. package/dist/packages/core/controllers/tag/list-tags.controller.d.ts +8 -0
  276. package/dist/packages/core/controllers/tag/list-tags.controller.d.ts.map +1 -0
  277. package/dist/packages/core/controllers/tag/list-tags.controller.js +48 -0
  278. package/dist/packages/core/controllers/tag/list-tags.controller.js.map +1 -0
  279. package/dist/packages/core/data/DbUtils.d.ts +7 -0
  280. package/dist/packages/core/data/DbUtils.d.ts.map +1 -0
  281. package/dist/packages/core/data/DbUtils.js +23 -0
  282. package/dist/packages/core/data/DbUtils.js.map +1 -0
  283. package/dist/packages/core/data/Entity.d.ts +71 -0
  284. package/dist/packages/core/data/Entity.d.ts.map +1 -0
  285. package/dist/packages/core/data/Entity.js +358 -0
  286. package/dist/packages/core/data/Entity.js.map +1 -0
  287. package/dist/packages/core/data/EventUtils.d.ts +14 -0
  288. package/dist/packages/core/data/EventUtils.d.ts.map +1 -0
  289. package/dist/packages/core/data/EventUtils.js +34 -0
  290. package/dist/packages/core/data/EventUtils.js.map +1 -0
  291. package/dist/packages/core/data/FileObject.d.ts +62 -0
  292. package/dist/packages/core/data/FileObject.d.ts.map +1 -0
  293. package/dist/packages/core/data/FileObject.js +13 -0
  294. package/dist/packages/core/data/FileObject.js.map +1 -0
  295. package/dist/packages/core/data/Mutual.d.ts +94 -0
  296. package/dist/packages/core/data/Mutual.d.ts.map +1 -0
  297. package/dist/packages/core/data/Mutual.js +492 -0
  298. package/dist/packages/core/data/Mutual.js.map +1 -0
  299. package/dist/packages/core/data/ProjectionExpression.d.ts +6 -0
  300. package/dist/packages/core/data/ProjectionExpression.d.ts.map +1 -0
  301. package/dist/packages/core/data/ProjectionExpression.js +5 -0
  302. package/dist/packages/core/data/ProjectionExpression.js.map +1 -0
  303. package/dist/packages/core/data/Tag.d.ts +77 -0
  304. package/dist/packages/core/data/Tag.d.ts.map +1 -0
  305. package/dist/packages/core/data/Tag.js +330 -0
  306. package/dist/packages/core/data/Tag.js.map +1 -0
  307. package/dist/packages/core/data/abstract/Item.base.d.ts +11 -0
  308. package/dist/packages/core/data/abstract/Item.base.d.ts.map +1 -0
  309. package/dist/packages/core/data/abstract/Item.base.js +9 -0
  310. package/dist/packages/core/data/abstract/Item.base.js.map +1 -0
  311. package/dist/packages/core/data/abstract/Repository.base.d.ts +11 -0
  312. package/dist/packages/core/data/abstract/Repository.base.d.ts.map +1 -0
  313. package/dist/packages/core/data/abstract/Repository.base.js +54 -0
  314. package/dist/packages/core/data/abstract/Repository.base.js.map +1 -0
  315. package/dist/packages/core/errors/api-error.d.ts +23 -0
  316. package/dist/packages/core/errors/api-error.d.ts.map +1 -0
  317. package/dist/packages/core/errors/api-error.js +26 -0
  318. package/dist/packages/core/errors/api-error.js.map +1 -0
  319. package/dist/packages/core/errors/extendable-error.d.ts +18 -0
  320. package/dist/packages/core/errors/extendable-error.d.ts.map +1 -0
  321. package/dist/packages/core/errors/extendable-error.js +22 -0
  322. package/dist/packages/core/errors/extendable-error.js.map +1 -0
  323. package/dist/packages/core/errors/standard-error.d.ts +11 -0
  324. package/dist/packages/core/errors/standard-error.d.ts.map +1 -0
  325. package/dist/packages/core/errors/standard-error.js +21 -0
  326. package/dist/packages/core/errors/standard-error.js.map +1 -0
  327. package/dist/packages/core/helpers/dependencies.d.ts +8 -0
  328. package/dist/packages/core/helpers/dependencies.d.ts.map +1 -0
  329. package/dist/packages/core/helpers/dependencies.js +10 -0
  330. package/dist/packages/core/helpers/dependencies.js.map +1 -0
  331. package/dist/packages/core/helpers/event.d.ts +22 -0
  332. package/dist/packages/core/helpers/event.d.ts.map +1 -0
  333. package/dist/packages/core/helpers/event.js +47 -0
  334. package/dist/packages/core/helpers/event.js.map +1 -0
  335. package/dist/packages/core/helpers/fromLastKeyQuery.d.ts +3 -0
  336. package/dist/packages/core/helpers/fromLastKeyQuery.d.ts.map +1 -0
  337. package/dist/packages/core/helpers/fromLastKeyQuery.js +7 -0
  338. package/dist/packages/core/helpers/fromLastKeyQuery.js.map +1 -0
  339. package/dist/packages/core/helpers/sleep.d.ts +2 -0
  340. package/dist/packages/core/helpers/sleep.d.ts.map +1 -0
  341. package/dist/packages/core/helpers/sleep.js +2 -0
  342. package/dist/packages/core/helpers/sleep.js.map +1 -0
  343. package/dist/packages/core/helpers/toLastKeyResponse.d.ts +3 -0
  344. package/dist/packages/core/helpers/toLastKeyResponse.d.ts.map +1 -0
  345. package/dist/packages/core/helpers/toLastKeyResponse.js +7 -0
  346. package/dist/packages/core/helpers/toLastKeyResponse.js.map +1 -0
  347. package/dist/packages/core/index.d.ts +12 -0
  348. package/dist/packages/core/index.d.ts.map +1 -0
  349. package/dist/packages/core/index.js +12 -0
  350. package/dist/packages/core/index.js.map +1 -0
  351. package/dist/packages/core/middlewares/entity-type-check.d.ts +3 -0
  352. package/dist/packages/core/middlewares/entity-type-check.d.ts.map +1 -0
  353. package/dist/packages/core/middlewares/entity-type-check.js +12 -0
  354. package/dist/packages/core/middlewares/entity-type-check.js.map +1 -0
  355. package/dist/packages/core/middlewares/mutual-type-check.d.ts +3 -0
  356. package/dist/packages/core/middlewares/mutual-type-check.d.ts.map +1 -0
  357. package/dist/packages/core/middlewares/mutual-type-check.js +13 -0
  358. package/dist/packages/core/middlewares/mutual-type-check.js.map +1 -0
  359. package/dist/packages/core/mock/container.d.ts +3 -0
  360. package/dist/packages/core/mock/container.d.ts.map +1 -0
  361. package/dist/packages/core/mock/container.js +3 -0
  362. package/dist/packages/core/mock/container.js.map +1 -0
  363. package/dist/packages/core/mock/entity.d.ts +13 -0
  364. package/dist/packages/core/mock/entity.d.ts.map +1 -0
  365. package/dist/packages/core/mock/entity.js +14 -0
  366. package/dist/packages/core/mock/entity.js.map +1 -0
  367. package/dist/packages/core/mock/monorise/admin.d.ts +127 -0
  368. package/dist/packages/core/mock/monorise/admin.d.ts.map +1 -0
  369. package/dist/packages/core/mock/monorise/admin.js +29 -0
  370. package/dist/packages/core/mock/monorise/admin.js.map +1 -0
  371. package/dist/packages/core/mock/monorise/audio.d.ts +324 -0
  372. package/dist/packages/core/mock/monorise/audio.d.ts.map +1 -0
  373. package/dist/packages/core/mock/monorise/audio.js +32 -0
  374. package/dist/packages/core/mock/monorise/audio.js.map +1 -0
  375. package/dist/packages/core/mock/monorise/chapter.d.ts +457 -0
  376. package/dist/packages/core/mock/monorise/chapter.d.ts.map +1 -0
  377. package/dist/packages/core/mock/monorise/chapter.js +81 -0
  378. package/dist/packages/core/mock/monorise/chapter.js.map +1 -0
  379. package/dist/packages/core/mock/monorise/cohort-track.d.ts +118 -0
  380. package/dist/packages/core/mock/monorise/cohort-track.d.ts.map +1 -0
  381. package/dist/packages/core/mock/monorise/cohort-track.js +38 -0
  382. package/dist/packages/core/mock/monorise/cohort-track.js.map +1 -0
  383. package/dist/packages/core/mock/monorise/course-banner.d.ts +149 -0
  384. package/dist/packages/core/mock/monorise/course-banner.d.ts.map +1 -0
  385. package/dist/packages/core/mock/monorise/course-banner.js +24 -0
  386. package/dist/packages/core/mock/monorise/course-banner.js.map +1 -0
  387. package/dist/packages/core/mock/monorise/course.d.ts +311 -0
  388. package/dist/packages/core/mock/monorise/course.d.ts.map +1 -0
  389. package/dist/packages/core/mock/monorise/course.js +128 -0
  390. package/dist/packages/core/mock/monorise/course.js.map +1 -0
  391. package/dist/packages/core/mock/monorise/expert.d.ts +380 -0
  392. package/dist/packages/core/mock/monorise/expert.d.ts.map +1 -0
  393. package/dist/packages/core/mock/monorise/expert.js +32 -0
  394. package/dist/packages/core/mock/monorise/expert.js.map +1 -0
  395. package/dist/packages/core/mock/monorise/index.d.ts +3599 -0
  396. package/dist/packages/core/mock/monorise/index.d.ts.map +1 -0
  397. package/dist/packages/core/mock/monorise/index.js +62 -0
  398. package/dist/packages/core/mock/monorise/index.js.map +1 -0
  399. package/dist/packages/core/mock/monorise/learner-video-progress.d.ts +198 -0
  400. package/dist/packages/core/mock/monorise/learner-video-progress.d.ts.map +1 -0
  401. package/dist/packages/core/mock/monorise/learner-video-progress.js +21 -0
  402. package/dist/packages/core/mock/monorise/learner-video-progress.js.map +1 -0
  403. package/dist/packages/core/mock/monorise/learner.d.ts +390 -0
  404. package/dist/packages/core/mock/monorise/learner.d.ts.map +1 -0
  405. package/dist/packages/core/mock/monorise/learner.js +59 -0
  406. package/dist/packages/core/mock/monorise/learner.js.map +1 -0
  407. package/dist/packages/core/mock/monorise/learning-activity-submission.d.ts +160 -0
  408. package/dist/packages/core/mock/monorise/learning-activity-submission.d.ts.map +1 -0
  409. package/dist/packages/core/mock/monorise/learning-activity-submission.js +17 -0
  410. package/dist/packages/core/mock/monorise/learning-activity-submission.js.map +1 -0
  411. package/dist/packages/core/mock/monorise/learning-activity.d.ts +266 -0
  412. package/dist/packages/core/mock/monorise/learning-activity.d.ts.map +1 -0
  413. package/dist/packages/core/mock/monorise/learning-activity.js +50 -0
  414. package/dist/packages/core/mock/monorise/learning-activity.js.map +1 -0
  415. package/dist/packages/core/mock/monorise/learning-journey-config.d.ts +84 -0
  416. package/dist/packages/core/mock/monorise/learning-journey-config.d.ts.map +1 -0
  417. package/dist/packages/core/mock/monorise/learning-journey-config.js +27 -0
  418. package/dist/packages/core/mock/monorise/learning-journey-config.js.map +1 -0
  419. package/dist/packages/core/mock/monorise/learning-journey-progress.d.ts +290 -0
  420. package/dist/packages/core/mock/monorise/learning-journey-progress.d.ts.map +1 -0
  421. package/dist/packages/core/mock/monorise/learning-journey-progress.js +46 -0
  422. package/dist/packages/core/mock/monorise/learning-journey-progress.js.map +1 -0
  423. package/dist/packages/core/mock/monorise/module.d.ts +211 -0
  424. package/dist/packages/core/mock/monorise/module.d.ts.map +1 -0
  425. package/dist/packages/core/mock/monorise/module.js +91 -0
  426. package/dist/packages/core/mock/monorise/module.js.map +1 -0
  427. package/dist/packages/core/mock/monorise/organization.d.ts +346 -0
  428. package/dist/packages/core/mock/monorise/organization.d.ts.map +1 -0
  429. package/dist/packages/core/mock/monorise/organization.js +54 -0
  430. package/dist/packages/core/mock/monorise/organization.js.map +1 -0
  431. package/dist/packages/core/mock/monorise/pathway.d.ts +267 -0
  432. package/dist/packages/core/mock/monorise/pathway.d.ts.map +1 -0
  433. package/dist/packages/core/mock/monorise/pathway.js +221 -0
  434. package/dist/packages/core/mock/monorise/pathway.js.map +1 -0
  435. package/dist/packages/core/mock/monorise/phase.d.ts +580 -0
  436. package/dist/packages/core/mock/monorise/phase.d.ts.map +1 -0
  437. package/dist/packages/core/mock/monorise/phase.js +166 -0
  438. package/dist/packages/core/mock/monorise/phase.js.map +1 -0
  439. package/dist/packages/core/mock/monorise/reference.d.ts +171 -0
  440. package/dist/packages/core/mock/monorise/reference.d.ts.map +1 -0
  441. package/dist/packages/core/mock/monorise/reference.js +25 -0
  442. package/dist/packages/core/mock/monorise/reference.js.map +1 -0
  443. package/dist/packages/core/mock/monorise/track.d.ts +617 -0
  444. package/dist/packages/core/mock/monorise/track.d.ts.map +1 -0
  445. package/dist/packages/core/mock/monorise/track.js +270 -0
  446. package/dist/packages/core/mock/monorise/track.js.map +1 -0
  447. package/dist/packages/core/mock/monorise/video.d.ts +346 -0
  448. package/dist/packages/core/mock/monorise/video.d.ts.map +1 -0
  449. package/dist/packages/core/mock/monorise/video.js +33 -0
  450. package/dist/packages/core/mock/monorise/video.js.map +1 -0
  451. package/dist/packages/core/mock/monorise.d.ts +6 -0
  452. package/dist/packages/core/mock/monorise.d.ts.map +1 -0
  453. package/dist/packages/core/mock/monorise.js +5 -0
  454. package/dist/packages/core/mock/monorise.js.map +1 -0
  455. package/dist/packages/core/processors/create-entity-processor.d.ts +5 -0
  456. package/dist/packages/core/processors/create-entity-processor.d.ts.map +1 -0
  457. package/dist/packages/core/processors/create-entity-processor.js +32 -0
  458. package/dist/packages/core/processors/create-entity-processor.js.map +1 -0
  459. package/dist/packages/core/processors/mutual-processor.d.ts +15 -0
  460. package/dist/packages/core/processors/mutual-processor.d.ts.map +1 -0
  461. package/dist/packages/core/processors/mutual-processor.js +128 -0
  462. package/dist/packages/core/processors/mutual-processor.js.map +1 -0
  463. package/dist/packages/core/processors/prejoin-processor.d.ts +12 -0
  464. package/dist/packages/core/processors/prejoin-processor.d.ts.map +1 -0
  465. package/dist/packages/core/processors/prejoin-processor.js +150 -0
  466. package/dist/packages/core/processors/prejoin-processor.js.map +1 -0
  467. package/dist/packages/core/processors/replication-processor.d.ts +8 -0
  468. package/dist/packages/core/processors/replication-processor.d.ts.map +1 -0
  469. package/dist/packages/core/processors/replication-processor.js +180 -0
  470. package/dist/packages/core/processors/replication-processor.js.map +1 -0
  471. package/dist/packages/core/processors/tag-processor.d.ts +11 -0
  472. package/dist/packages/core/processors/tag-processor.d.ts.map +1 -0
  473. package/dist/packages/core/processors/tag-processor.js +106 -0
  474. package/dist/packages/core/processors/tag-processor.js.map +1 -0
  475. package/dist/packages/core/services/DependencyContainer.d.ts +51 -0
  476. package/dist/packages/core/services/DependencyContainer.d.ts.map +1 -0
  477. package/dist/packages/core/services/DependencyContainer.js +115 -0
  478. package/dist/packages/core/services/DependencyContainer.js.map +1 -0
  479. package/dist/packages/core/services/entity-service-lifecycle.d.ts +12 -0
  480. package/dist/packages/core/services/entity-service-lifecycle.d.ts.map +1 -0
  481. package/dist/packages/core/services/entity-service-lifecycle.js +23 -0
  482. package/dist/packages/core/services/entity-service-lifecycle.js.map +1 -0
  483. package/dist/packages/core/services/entity.service.d.ts +32 -0
  484. package/dist/packages/core/services/entity.service.d.ts.map +1 -0
  485. package/dist/packages/core/services/entity.service.js +121 -0
  486. package/dist/packages/core/services/entity.service.js.map +1 -0
  487. package/dist/packages/core/services/mutual.service.d.ts +64 -0
  488. package/dist/packages/core/services/mutual.service.d.ts.map +1 -0
  489. package/dist/packages/core/services/mutual.service.js +144 -0
  490. package/dist/packages/core/services/mutual.service.js.map +1 -0
  491. package/dist/packages/core/types/entity.type.d.ts +20 -0
  492. package/dist/packages/core/types/entity.type.d.ts.map +1 -0
  493. package/dist/packages/core/types/entity.type.js +2 -0
  494. package/dist/packages/core/types/entity.type.js.map +1 -0
  495. package/dist/processors/create-entity-processor.d.ts +5 -0
  496. package/dist/processors/create-entity-processor.d.ts.map +1 -0
  497. package/dist/processors/create-entity-processor.js +33 -0
  498. package/dist/processors/create-entity-processor.js.map +1 -0
  499. package/dist/processors/mutual-processor.d.ts +15 -0
  500. package/dist/processors/mutual-processor.d.ts.map +1 -0
  501. package/dist/processors/mutual-processor.js +129 -0
  502. package/dist/processors/mutual-processor.js.map +1 -0
  503. package/dist/processors/prejoin-processor.d.ts +12 -0
  504. package/dist/processors/prejoin-processor.d.ts.map +1 -0
  505. package/dist/processors/prejoin-processor.js +151 -0
  506. package/dist/processors/prejoin-processor.js.map +1 -0
  507. package/dist/processors/replication-processor.d.ts +8 -0
  508. package/dist/processors/replication-processor.d.ts.map +1 -0
  509. package/dist/processors/replication-processor.js +181 -0
  510. package/dist/processors/replication-processor.js.map +1 -0
  511. package/dist/processors/tag-processor.d.ts +11 -0
  512. package/dist/processors/tag-processor.d.ts.map +1 -0
  513. package/dist/processors/tag-processor.js +107 -0
  514. package/dist/processors/tag-processor.js.map +1 -0
  515. package/dist/services/DependencyContainer.d.ts +51 -0
  516. package/dist/services/DependencyContainer.d.ts.map +1 -0
  517. package/dist/services/DependencyContainer.js +115 -0
  518. package/dist/services/DependencyContainer.js.map +1 -0
  519. package/dist/services/entity-service-lifecycle.d.ts +12 -0
  520. package/dist/services/entity-service-lifecycle.d.ts.map +1 -0
  521. package/dist/services/entity-service-lifecycle.js +23 -0
  522. package/dist/services/entity-service-lifecycle.js.map +1 -0
  523. package/dist/services/entity.service.d.ts +32 -0
  524. package/dist/services/entity.service.d.ts.map +1 -0
  525. package/dist/services/entity.service.js +121 -0
  526. package/dist/services/entity.service.js.map +1 -0
  527. package/dist/services/mutual.service.d.ts +64 -0
  528. package/dist/services/mutual.service.d.ts.map +1 -0
  529. package/dist/services/mutual.service.js +144 -0
  530. package/dist/services/mutual.service.js.map +1 -0
  531. package/dist/shared/types/event.d.ts +72 -0
  532. package/dist/shared/types/event.d.ts.map +1 -0
  533. package/dist/shared/types/event.js +74 -0
  534. package/dist/shared/types/event.js.map +1 -0
  535. package/dist/types/entity.type.d.ts +20 -0
  536. package/dist/types/entity.type.d.ts.map +1 -0
  537. package/dist/types/entity.type.js +2 -0
  538. package/dist/types/entity.type.js.map +1 -0
  539. package/dist/types/event.d.ts +72 -0
  540. package/dist/types/event.d.ts.map +1 -0
  541. package/dist/types/event.js +74 -0
  542. package/dist/types/event.js.map +1 -0
  543. package/errors/api-error.ts +39 -0
  544. package/errors/extendable-error.ts +35 -0
  545. package/errors/standard-error.ts +29 -0
  546. package/helpers/dependencies.ts +10 -0
  547. package/helpers/event.ts +85 -0
  548. package/helpers/fromLastKeyQuery.ts +11 -0
  549. package/helpers/sleep.ts +1 -0
  550. package/helpers/toLastKeyResponse.ts +11 -0
  551. package/index.ts +23 -0
  552. package/middlewares/entity-type-check.ts +20 -0
  553. package/middlewares/mutual-type-check.ts +26 -0
  554. package/mock/entity.ts +12 -0
  555. package/mock/monorise/admin.ts +35 -0
  556. package/mock/monorise/chapter.ts +94 -0
  557. package/mock/monorise/course.ts +149 -0
  558. package/mock/monorise/index.ts +143 -0
  559. package/mock/monorise/learner.ts +66 -0
  560. package/mock/monorise/learning-activity.ts +62 -0
  561. package/mock/monorise/learning-journey-config.ts +34 -0
  562. package/mock/monorise/module.ts +108 -0
  563. package/mock/monorise/organization.ts +63 -0
  564. package/mock/monorise/reference.ts +28 -0
  565. package/mock/monorise/video.ts +36 -0
  566. package/package.json +31 -0
  567. package/processors/create-entity-processor.ts +55 -0
  568. package/processors/mutual-processor.ts +262 -0
  569. package/processors/prejoin-processor.ts +264 -0
  570. package/processors/replication-processor.ts +261 -0
  571. package/processors/tag-processor.ts +174 -0
  572. package/services/DependencyContainer.ts +208 -0
  573. package/services/entity-service-lifecycle.ts +41 -0
  574. package/services/entity.service.ts +201 -0
  575. package/services/mutual.service.ts +285 -0
  576. package/tsconfig.json +118 -0
  577. package/types/entity.type.ts +62 -0
  578. package/types/event.ts +84 -0
@@ -0,0 +1,8 @@
1
+ export type ProjectionExpressionValues =
2
+ (typeof PROJECTION_EXPRESSION)[keyof typeof PROJECTION_EXPRESSION];
3
+
4
+ export const PROJECTION_EXPRESSION = {
5
+ NO_DATA: 'byEntityType, byEntityId, entityType, entityId, mutualId',
6
+ MUTUAL_DATA_ONLY:
7
+ 'byEntityType, byEntityId, entityType, entityId, mutualId, mutualData',
8
+ } as const;
package/data/Tag.ts ADDED
@@ -0,0 +1,470 @@
1
+ import type {
2
+ AttributeValue,
3
+ DynamoDB,
4
+ QueryCommandInput,
5
+ } from '@aws-sdk/client-dynamodb';
6
+ import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
7
+ import type { EntitySchemaMap, Entity as EntityType } from '@monorise/base';
8
+ import { StandardError } from '#/errors/standard-error';
9
+ import { Entity } from './Entity';
10
+ import type { ProjectionExpressionValues } from './ProjectionExpression';
11
+ import { Repository } from './abstract/Repository.base';
12
+
13
+ export class TaggedEntity<T extends EntityType> extends Entity<T> {
14
+ public tagName: string;
15
+ public group?: string;
16
+ public sortValue?: string;
17
+
18
+ constructor({
19
+ tagName,
20
+ group,
21
+ sortValue,
22
+ entityType,
23
+ entityId,
24
+ data,
25
+ createdAt,
26
+ updatedAt,
27
+ }: {
28
+ tagName: string;
29
+ group?: string;
30
+ sortValue?: string;
31
+ entityType: T;
32
+ entityId: string;
33
+ data?: Partial<EntitySchemaMap[T]>;
34
+ createdAt?: Date;
35
+ updatedAt?: Date;
36
+ }) {
37
+ super(entityType, entityId, data, createdAt, updatedAt);
38
+
39
+ this.tagName = tagName;
40
+ this.group = group;
41
+ this.sortValue = sortValue;
42
+ }
43
+
44
+ static fromItem<T extends EntityType>(
45
+ item?: Record<string, AttributeValue>,
46
+ ): TaggedEntity<T> {
47
+ if (!item) throw new StandardError('TAG_IS_UNDEFINED', 'Tag item empty');
48
+
49
+ const parsedItem = unmarshall(item);
50
+
51
+ return new TaggedEntity<T>({
52
+ tagName: parsedItem.tagName,
53
+ group: parsedItem.group,
54
+ sortValue: parsedItem.sortValue,
55
+ entityType: parsedItem.entityType,
56
+ entityId: parsedItem.entityId,
57
+ data: parsedItem.data,
58
+ createdAt: parsedItem.createdAt
59
+ ? new Date(parsedItem.createdAt)
60
+ : undefined,
61
+ updatedAt: parsedItem.updatedAt
62
+ ? new Date(parsedItem.updatedAt)
63
+ : undefined,
64
+ });
65
+ }
66
+
67
+ get pk(): string {
68
+ return `TAG#${this.entityType}#${this.tagName}${this.group ? `#${this.group}` : ''}`;
69
+ }
70
+
71
+ get sk(): string {
72
+ return `${this.sortValue ? `${this.sortValue}#` : ''}${this.entityType}#${this.entityId}`;
73
+ }
74
+
75
+ reversedKeys(): Record<string, AttributeValue> {
76
+ return {
77
+ PK: { S: `${this.entityType}#${this.entityId}` },
78
+ SK: {
79
+ S: this.pk,
80
+ },
81
+ };
82
+ }
83
+
84
+ replicationKeys(): Record<string, AttributeValue> {
85
+ const keys = this.reversedKeys();
86
+
87
+ return {
88
+ R1PK: keys.PK,
89
+ R1SK: keys.SK,
90
+ };
91
+ }
92
+
93
+ toItem(): Record<string, AttributeValue> {
94
+ return {
95
+ ...marshall(this.toJSON(), { removeUndefinedValues: true }),
96
+ ...this.keys(),
97
+ };
98
+ }
99
+
100
+ toJSON(): Record<string, unknown> {
101
+ return {
102
+ tagName: this.tagName,
103
+ group: this.group,
104
+ sortValue: this.sortValue,
105
+ entityType: this.entityType,
106
+ entityId: this.entityId,
107
+ data: this.data,
108
+ createdAt: this.createdAt,
109
+ updatedAt: this.updatedAt,
110
+ };
111
+ }
112
+ }
113
+
114
+ export class TagRepository extends Repository {
115
+ constructor(
116
+ private readonly TABLE_NAME: string,
117
+ private readonly dynamodbClient: DynamoDB,
118
+ ) {
119
+ super();
120
+ }
121
+
122
+ async getExistingTags<T extends EntityType>({
123
+ entityType,
124
+ entityId,
125
+ tagName,
126
+ }: {
127
+ entityType: T;
128
+ entityId: string;
129
+ tagName: string;
130
+ }): Promise<TaggedEntity<T>[]> {
131
+ const PK = `${entityType}#${entityId}`;
132
+ const SK = `TAG#${entityType}#${tagName}`;
133
+
134
+ const results = await this.dynamodbClient.query({
135
+ TableName: this.TABLE_NAME,
136
+ KeyConditionExpression: '#PK = :PK and begins_with(#SK, :SK)',
137
+ ExpressionAttributeNames: {
138
+ '#PK': 'PK',
139
+ '#SK': 'SK',
140
+ },
141
+ ExpressionAttributeValues: {
142
+ ':PK': { S: PK },
143
+ ':SK': { S: SK },
144
+ },
145
+ });
146
+
147
+ return (results.Items || []).map((item: any) => {
148
+ return TaggedEntity.fromItem(item);
149
+ });
150
+ }
151
+
152
+ async deleteTag({
153
+ tagName,
154
+ group,
155
+ sortValue,
156
+ entityType,
157
+ entityId,
158
+ }: {
159
+ tagName: string;
160
+ group?: string;
161
+ sortValue?: string;
162
+ entityType: EntityType;
163
+ entityId: string;
164
+ }): Promise<void> {
165
+ const tag = new TaggedEntity({
166
+ tagName,
167
+ group,
168
+ sortValue,
169
+ entityType,
170
+ entityId,
171
+ });
172
+
173
+ await Promise.all([
174
+ this.dynamodbClient.deleteItem({
175
+ TableName: this.TABLE_NAME,
176
+ Key: tag.keys(),
177
+ }),
178
+ this.dynamodbClient.deleteItem({
179
+ TableName: this.TABLE_NAME,
180
+ Key: tag.reversedKeys(),
181
+ }),
182
+ ]);
183
+
184
+ return;
185
+ }
186
+
187
+ async createTag<T extends EntityType>({
188
+ tagName,
189
+ group,
190
+ sortValue,
191
+ entity,
192
+ }: {
193
+ tagName: string;
194
+ group?: string;
195
+ sortValue?: string;
196
+ entity: Entity<T>;
197
+ }): Promise<TaggedEntity<T>> {
198
+ if (!entity.entityId) {
199
+ throw new StandardError(
200
+ 'ENTITY_ID_IS_UNDEFINED',
201
+ 'entityId is undefined',
202
+ );
203
+ }
204
+
205
+ const tag = new TaggedEntity({
206
+ tagName,
207
+ group,
208
+ sortValue,
209
+ entityType: entity.entityType,
210
+ entityId: entity.entityId,
211
+ data: entity.data,
212
+ createdAt: entity.createdAt ? new Date(entity.createdAt) : new Date(),
213
+ updatedAt: entity.updatedAt ? new Date(entity.updatedAt) : new Date(),
214
+ });
215
+
216
+ await Promise.all([
217
+ this.dynamodbClient.putItem({
218
+ TableName: this.TABLE_NAME,
219
+ Item: {
220
+ ...tag.toItem(),
221
+ ...tag.replicationKeys(),
222
+ },
223
+ }),
224
+ this.dynamodbClient.putItem({
225
+ TableName: this.TABLE_NAME,
226
+ Item: {
227
+ ...marshall(
228
+ {
229
+ tagName,
230
+ group,
231
+ sortValue,
232
+ },
233
+ { removeUndefinedValues: true },
234
+ ),
235
+ ...tag.reversedKeys(),
236
+ ...tag.replicationKeys(),
237
+ },
238
+ }),
239
+ ]);
240
+
241
+ return tag;
242
+ }
243
+
244
+ async listTags<T extends EntityType>({
245
+ entityType,
246
+ tagName,
247
+ limit, // if this is not set, it will return all items
248
+ query,
249
+ group,
250
+ start,
251
+ end,
252
+ options = {},
253
+ }: {
254
+ entityType: T;
255
+ tagName: string;
256
+ limit?: number;
257
+ start?: string;
258
+ end?: string;
259
+ query?: string;
260
+ group?: string;
261
+ options?: {
262
+ lastKey?: Record<string, AttributeValue>;
263
+ ProjectionExpression?: ProjectionExpressionValues;
264
+ };
265
+ }): Promise<{
266
+ items: Entity<T>[];
267
+ totalCount?: number;
268
+ lastKey?: Record<string, AttributeValue>;
269
+ }> {
270
+ const errorContext: Record<string, unknown> = {
271
+ entityType,
272
+ tagName,
273
+ limit,
274
+ query,
275
+ group,
276
+ start,
277
+ end,
278
+ options,
279
+ };
280
+
281
+ const tag = new TaggedEntity({
282
+ tagName,
283
+ entityType,
284
+ entityId: '',
285
+ group,
286
+ });
287
+
288
+ let expression: Pick<
289
+ QueryCommandInput,
290
+ | 'KeyConditionExpression'
291
+ | 'ExpressionAttributeNames'
292
+ | 'ExpressionAttributeValues'
293
+ > | null = null;
294
+
295
+ if (query && !start && !end) {
296
+ expression = {
297
+ KeyConditionExpression: '#PK = :PK and begins_with(#SK, :SK)',
298
+ ExpressionAttributeNames: {
299
+ '#PK': 'PK',
300
+ '#SK': 'SK',
301
+ },
302
+ ExpressionAttributeValues: {
303
+ ':PK': {
304
+ S: tag.pk,
305
+ },
306
+ ':SK': {
307
+ S: `${query}#`,
308
+ },
309
+ },
310
+ };
311
+ } else if (start && end) {
312
+ expression = {
313
+ KeyConditionExpression: '#PK = :PK and #SK between :SKStart and :SKEnd',
314
+ ExpressionAttributeNames: {
315
+ '#PK': 'PK',
316
+ '#SK': 'SK',
317
+ },
318
+ ExpressionAttributeValues: {
319
+ ':PK': {
320
+ S: tag.pk,
321
+ },
322
+ ':SKStart': {
323
+ S: `${start}#`,
324
+ },
325
+ ':SKEnd': {
326
+ S: `${end}#`,
327
+ },
328
+ },
329
+ };
330
+ } else if (start && !end) {
331
+ expression = {
332
+ KeyConditionExpression: '#PK = :PK and #SK >= :SK',
333
+ ExpressionAttributeNames: {
334
+ '#PK': 'PK',
335
+ '#SK': 'SK',
336
+ },
337
+ ExpressionAttributeValues: {
338
+ ':PK': {
339
+ S: tag.pk,
340
+ },
341
+ ':SK': {
342
+ S: `${start}#`,
343
+ },
344
+ },
345
+ };
346
+ } else if (!start && end) {
347
+ expression = {
348
+ KeyConditionExpression: '#PK = :PK and #SK <= :SK',
349
+ ExpressionAttributeNames: {
350
+ '#PK': 'PK',
351
+ '#SK': 'SK',
352
+ },
353
+ ExpressionAttributeValues: {
354
+ ':PK': {
355
+ S: tag.pk,
356
+ },
357
+ ':SK': {
358
+ S: `${end}#`,
359
+ },
360
+ },
361
+ };
362
+ } else if (group && !query && !start && !end) {
363
+ expression = {
364
+ KeyConditionExpression: '#PK = :PK',
365
+ ExpressionAttributeNames: {
366
+ '#PK': 'PK',
367
+ },
368
+ ExpressionAttributeValues: {
369
+ ':PK': {
370
+ S: tag.pk,
371
+ },
372
+ },
373
+ };
374
+ }
375
+
376
+ if (!expression) {
377
+ throw new StandardError(
378
+ 'INVALID_QUERY',
379
+ 'Invalid query. Please provide a valid query',
380
+ null,
381
+ errorContext,
382
+ );
383
+ }
384
+ const defaultListQuery: QueryCommandInput = {
385
+ TableName: this.TABLE_NAME,
386
+ Limit: limit,
387
+ ScanIndexForward: false,
388
+ ProjectionExpression: options?.ProjectionExpression,
389
+ ...expression,
390
+ };
391
+
392
+ let lastKey = options.lastKey;
393
+ let items: Record<string, AttributeValue>[] = [];
394
+ let remainingCount = limit ?? 0;
395
+ do {
396
+ const resp = await this.dynamodbClient.query({
397
+ ...defaultListQuery,
398
+ ...(remainingCount && { Limit: remainingCount }),
399
+ ...(lastKey && {
400
+ ExclusiveStartKey: lastKey,
401
+ }),
402
+ });
403
+ items = items.concat(resp.Items ?? []);
404
+
405
+ lastKey = resp.LastEvaluatedKey;
406
+
407
+ if (limit) {
408
+ remainingCount = remainingCount - (resp.Items?.length ?? 0);
409
+ }
410
+ } while (
411
+ // limit is given, haven't reach limit, and there are still items to retrieve
412
+ (limit && remainingCount && lastKey) ||
413
+ // no limit is given and there are still items to retrieve
414
+ (!limit && lastKey)
415
+ );
416
+
417
+ return {
418
+ items: (items || []).map(Entity.fromItem<T>),
419
+ totalCount: items.length,
420
+ lastKey,
421
+ };
422
+ }
423
+
424
+ async createLock({
425
+ entityType,
426
+ entityId,
427
+ }: {
428
+ entityType: EntityType;
429
+ entityId: string;
430
+ }): Promise<void> {
431
+ const oneMinuteLater = Math.floor(new Date().getTime() / 1000 + 1 * 60);
432
+
433
+ await this.dynamodbClient.putItem({
434
+ TableName: this.TABLE_NAME,
435
+ Item: {
436
+ PK: { S: `TAG#${entityType}#${entityId}` },
437
+ SK: { S: '#LOCK#' },
438
+ expiresAt: {
439
+ // auto delete lock after 1 minute
440
+ N: `${oneMinuteLater}`,
441
+ },
442
+ },
443
+ ConditionExpression: 'attribute_not_exists(PK)',
444
+ });
445
+
446
+ return;
447
+ }
448
+
449
+ async deleteLock({
450
+ entityType,
451
+ entityId,
452
+ }: {
453
+ entityType: EntityType;
454
+ entityId: string;
455
+ }): Promise<void> {
456
+ try {
457
+ await this.dynamodbClient.deleteItem({
458
+ TableName: this.TABLE_NAME,
459
+ Key: {
460
+ PK: { S: `TAG#${entityType}#${entityId}` },
461
+ SK: { S: '#LOCK#' },
462
+ },
463
+ });
464
+
465
+ return;
466
+ } catch (error) {
467
+ // if lock is not found, it's okay
468
+ }
469
+ }
470
+ }
@@ -0,0 +1,19 @@
1
+ import type { AttributeValue } from '@aws-sdk/client-dynamodb';
2
+
3
+ export abstract class Item {
4
+ abstract get pk(): string;
5
+ abstract get sk(): string;
6
+ abstract get createdAt(): string | undefined;
7
+ abstract get updatedAt(): string | undefined;
8
+
9
+ public keys(): Record<string, AttributeValue> {
10
+ return {
11
+ PK: { S: this.pk },
12
+ SK: { S: this.sk },
13
+ };
14
+ }
15
+
16
+ abstract toItem(): Record<string, AttributeValue>;
17
+
18
+ abstract toJSON(): Record<string, unknown>;
19
+ }
@@ -0,0 +1,92 @@
1
+ import type { AttributeValue } from '@aws-sdk/client-dynamodb';
2
+ import { marshall } from '@aws-sdk/util-dynamodb';
3
+
4
+ function flattenObject(
5
+ obj: Record<string, unknown>,
6
+ parentKey = '',
7
+ result: Record<string, unknown> = {},
8
+ level = 1,
9
+ opts?: {
10
+ maxLevel?: number;
11
+ },
12
+ ): Record<string, unknown> {
13
+ const MAX_LEVEL = opts?.maxLevel ?? 2;
14
+
15
+ for (const key in obj) {
16
+ if (obj.hasOwnProperty(key)) {
17
+ const propName = parentKey ? `${parentKey}.${key}` : key;
18
+ if (
19
+ typeof obj[key] === 'object' &&
20
+ obj[key] !== null &&
21
+ !Array.isArray(obj[key]) &&
22
+ level < MAX_LEVEL
23
+ ) {
24
+ flattenObject(
25
+ obj[key] as Record<string, unknown>,
26
+ propName,
27
+ result,
28
+ level + 1,
29
+ opts,
30
+ );
31
+ } else {
32
+ result[propName] = obj[key];
33
+ }
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+
39
+ export abstract class Repository {
40
+ toUpdate(
41
+ parsedUpdateData: Record<string, unknown>,
42
+ opts?: {
43
+ // to limit the partial update depth for an object
44
+ // in some scenario, we have to ensure the object to be written must be an object instead of undefined/null
45
+ // eg, writing to data.cover.name must ensure data.cover is an object already else we will get error
46
+ maxLevel?: number;
47
+ },
48
+ ): {
49
+ UpdateExpression: string;
50
+ ExpressionAttributeNames: Record<string, string>;
51
+ ExpressionAttributeValues: Record<string, AttributeValue>;
52
+ } {
53
+ const flattenedData = flattenObject(parsedUpdateData, '', {}, 1, opts);
54
+
55
+ let updateExpression = '';
56
+ const expressionAttributeNames: Record<string, string> = {};
57
+ const expressionAttributeValues: Record<string, unknown> = {};
58
+
59
+ for (const key in flattenedData) {
60
+ if (updateExpression.length > 0) {
61
+ updateExpression += ', ';
62
+ }
63
+ const attributePath = key
64
+ .split('.')
65
+ .map((part) => `#${part}`)
66
+ .join('.');
67
+ const valuePlaceholder = `:${key.replace(/\./g, '_')}`;
68
+
69
+ updateExpression += `${attributePath} = ${valuePlaceholder}`;
70
+
71
+ key.split('.').forEach((part) => {
72
+ expressionAttributeNames[`#${part}`] = part;
73
+ });
74
+
75
+ expressionAttributeValues[valuePlaceholder] = flattenedData[key];
76
+ }
77
+
78
+ updateExpression = `SET ${updateExpression}`;
79
+
80
+ const updateAttributes = {
81
+ UpdateExpression: updateExpression,
82
+ ExpressionAttributeNames: {
83
+ ...expressionAttributeNames,
84
+ },
85
+ ExpressionAttributeValues: {
86
+ ...marshall(expressionAttributeValues),
87
+ },
88
+ };
89
+
90
+ return updateAttributes;
91
+ }
92
+ }
@@ -0,0 +1,5 @@
1
+ import { ENTITY_REPLICATION_INDEX, MUTUAL_REPLICATION_INDEX } from '../constants/table';
2
+ declare const CORE_TABLE: string;
3
+ declare const CORE_EVENT_BUS: string;
4
+ export { CORE_TABLE, CORE_EVENT_BUS, ENTITY_REPLICATION_INDEX, MUTUAL_REPLICATION_INDEX, };
5
+ //# sourceMappingURL=service.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.config.d.ts","sourceRoot":"","sources":["../../configs/service.config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,oBAAoB,CAAC;AAE5B,QAAA,MAAM,UAAU,QAA+B,CAAC;AAChD,QAAA,MAAM,cAAc,QAAmC,CAAC;AAExD,OAAO,EACL,UAAU,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,GACzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ENTITY_REPLICATION_INDEX, MUTUAL_REPLICATION_INDEX, } from '../constants/table';
2
+ const CORE_TABLE = process.env.CORE_TABLE || '';
3
+ const CORE_EVENT_BUS = process.env.CORE_EVENT_BUS || '';
4
+ export { CORE_TABLE, CORE_EVENT_BUS, ENTITY_REPLICATION_INDEX, MUTUAL_REPLICATION_INDEX, };
5
+ //# sourceMappingURL=service.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.config.js","sourceRoot":"","sources":["../../configs/service.config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;AAChD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;AAExD,OAAO,EACL,UAAU,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,GACzB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const REPLICATION_INDEX = "REPLICATION_INDEX";
2
+ export declare const ENTITY_REPLICATION_INDEX = "ENTITY_REPLICATION_INDEX";
3
+ export declare const MUTUAL_REPLICATION_INDEX = "MUTUAL_REPLICATION_INDEX";
4
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../constants/table.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AACrD,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,wBAAwB,6BAA6B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const REPLICATION_INDEX = 'REPLICATION_INDEX';
2
+ export const ENTITY_REPLICATION_INDEX = 'ENTITY_REPLICATION_INDEX';
3
+ export const MUTUAL_REPLICATION_INDEX = 'MUTUAL_REPLICATION_INDEX';
4
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../../constants/table.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Request, Response } from 'express';
2
+ import type { EntityService } from '#/services/entity.service';
3
+ export declare class CreateEntityController {
4
+ private entityService;
5
+ constructor(entityService: EntityService);
6
+ controller: (req: Request, res: Response) => void;
7
+ }
8
+ //# sourceMappingURL=create-entity.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-entity.controller.d.ts","sourceRoot":"","sources":["../../../controllers/entity/create-entity.controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,qBAAa,sBAAsB;IACrB,OAAO,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAEhD,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,IAAI,CAuC/C;CACH"}
@@ -0,0 +1,44 @@
1
+ import httpStatus from 'http-status';
2
+ import { ZodError } from 'zod';
3
+ import { StandardError } from '#/errors/standard-error';
4
+ export class CreateEntityController {
5
+ entityService;
6
+ constructor(entityService) {
7
+ this.entityService = entityService;
8
+ }
9
+ controller = async (req, res) => {
10
+ const accountId = req.headers['account-id'];
11
+ const { entityType } = req.params;
12
+ try {
13
+ const entity = await this.entityService.createEntity({
14
+ entityType,
15
+ entityPayload: req.body,
16
+ accountId,
17
+ options: {
18
+ createAndUpdateDatetime: req.body.createdAt,
19
+ },
20
+ });
21
+ return res.status(httpStatus.OK).json(entity);
22
+ }
23
+ catch (err) {
24
+ if (err instanceof ZodError) {
25
+ return res.status(httpStatus.BAD_REQUEST).json({
26
+ code: 'API_VALIDATION_ERROR',
27
+ message: 'API validation failed',
28
+ details: err.flatten(),
29
+ });
30
+ }
31
+ if (err instanceof StandardError && err.code === 'EMAIL_EXISTS') {
32
+ return res.status(httpStatus.BAD_REQUEST).json({
33
+ ...err.toJSON(),
34
+ });
35
+ }
36
+ console.log('===create-entity error:', {
37
+ err,
38
+ errorContext: JSON.stringify({ body: req.body, headers: req.headers }),
39
+ });
40
+ throw err;
41
+ }
42
+ };
43
+ }
44
+ //# sourceMappingURL=create-entity.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-entity.controller.js","sourceRoot":"","sources":["../../../controllers/entity/create-entity.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,MAAM,OAAO,sBAAsB;IACb;IAApB,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAEpD,UAAU,GAA0C,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACrE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAE1B,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;gBACnD,UAAU;gBACV,aAAa,EAAE,GAAG,CAAC,IAAI;gBACvB,SAAS;gBACT,OAAO,EAAE;oBACP,uBAAuB,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS;iBAC5C;aACF,CAAC,CAAC;YAEH,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;oBAC7C,IAAI,EAAE,sBAAsB;oBAC5B,OAAO,EAAE,uBAAuB;oBAChC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;iBACvB,CAAC,CAAC;YACL,CAAC;YAED,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBAChE,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;oBAC7C,GAAG,GAAG,CAAC,MAAM,EAAE;iBAChB,CAAC,CAAC;YACL,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE;gBACrC,GAAG;gBACH,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;aACvE,CAAC,CAAC;YAEH,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;CACH"}