@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,62 @@
1
+ import { z } from 'zod';
2
+ export declare const fileObjectSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ url: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ name: string;
7
+ url: string;
8
+ }, {
9
+ name: string;
10
+ url: string;
11
+ }>;
12
+ export declare const fileSchema: z.ZodObject<{
13
+ uid: z.ZodString;
14
+ name: z.ZodString;
15
+ regular: z.ZodObject<{
16
+ name: z.ZodString;
17
+ url: z.ZodString;
18
+ }, "strip", z.ZodTypeAny, {
19
+ name: string;
20
+ url: string;
21
+ }, {
22
+ name: string;
23
+ url: string;
24
+ }>;
25
+ thumbnail: z.ZodOptional<z.ZodObject<{
26
+ name: z.ZodString;
27
+ url: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ name: string;
30
+ url: string;
31
+ }, {
32
+ name: string;
33
+ url: string;
34
+ }>>;
35
+ jobId: z.ZodOptional<z.ZodString>;
36
+ }, "strip", z.ZodTypeAny, {
37
+ name: string;
38
+ uid: string;
39
+ regular: {
40
+ name: string;
41
+ url: string;
42
+ };
43
+ thumbnail?: {
44
+ name: string;
45
+ url: string;
46
+ } | undefined;
47
+ jobId?: string | undefined;
48
+ }, {
49
+ name: string;
50
+ uid: string;
51
+ regular: {
52
+ name: string;
53
+ url: string;
54
+ };
55
+ thumbnail?: {
56
+ name: string;
57
+ url: string;
58
+ } | undefined;
59
+ jobId?: string | undefined;
60
+ }>;
61
+ export type File = z.infer<typeof fileSchema>;
62
+ //# sourceMappingURL=FileObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../../data/FileObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB;;;;;;;;;EAG3B,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMrB,CAAC;AAEH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export const fileObjectSchema = z.object({
3
+ name: z.string(),
4
+ url: z.string(),
5
+ });
6
+ export const fileSchema = z.object({
7
+ uid: z.string(),
8
+ name: z.string(),
9
+ regular: fileObjectSchema,
10
+ thumbnail: fileObjectSchema.optional(),
11
+ jobId: z.string().optional(),
12
+ });
13
+ //# sourceMappingURL=FileObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileObject.js","sourceRoot":"","sources":["../../../../data/FileObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,gBAAgB,CAAC,QAAQ,EAAE;IACtC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { type AttributeValue, type DynamoDB, type TransactWriteItem } from '@aws-sdk/client-dynamodb';
2
+ import type { Entity, EntitySchemaMap } from '@monorise/base';
3
+ import type { DbUtils } from '#/data/DbUtils';
4
+ import { type ProjectionExpressionValues } from './ProjectionExpression';
5
+ import { Repository } from './abstract/Repository.base';
6
+ export declare class Mutual<B extends Entity, T extends Entity, M extends Record<string, unknown>> {
7
+ byEntityType: B;
8
+ byEntityId: string;
9
+ byData: Partial<EntitySchemaMap[B]>;
10
+ entityType: T;
11
+ entityId: string;
12
+ data: Partial<EntitySchemaMap[T]>;
13
+ mutualData: M;
14
+ mutualId?: string | undefined;
15
+ private _createdAt?;
16
+ private _updatedAt?;
17
+ private _mutualUpdatedAt?;
18
+ private _expiresAt?;
19
+ constructor(byEntityType: B, byEntityId: string, byData: Partial<EntitySchemaMap[B]>, entityType: T, entityId: string, data: Partial<EntitySchemaMap[T]>, mutualData: M, mutualId?: string | undefined, _createdAt?: Date | undefined, _updatedAt?: Date | undefined, _mutualUpdatedAt?: Date | undefined, _expiresAt?: Date | undefined);
20
+ static fromItem<B extends Entity, T extends Entity, M extends Record<string, unknown>>(item?: Record<string, AttributeValue>): Mutual<B, T, M>;
21
+ mainKeys(): Record<string, AttributeValue>;
22
+ subKeys(): Record<string, AttributeValue>;
23
+ get byFullEntityId(): string;
24
+ get fullEntityId(): string;
25
+ get listEntitySK(): string;
26
+ get mainPk(): string;
27
+ get mainSk(): string;
28
+ get createdAt(): string | undefined;
29
+ get updatedAt(): string | undefined;
30
+ get mutualUpdatedAt(): string | undefined;
31
+ get expiresAt(): string | undefined;
32
+ toMutualItemOnly(): Record<string, AttributeValue>;
33
+ toItem(): Record<string, AttributeValue>;
34
+ toReversedItem(): Record<string, AttributeValue>;
35
+ toJSON(): Record<string, unknown>;
36
+ }
37
+ export declare class MutualRepository extends Repository {
38
+ private readonly TABLE_NAME;
39
+ private readonly dynamodbClient;
40
+ private readonly ddbUtils;
41
+ constructor(TABLE_NAME: string, dynamodbClient: DynamoDB, ddbUtils: DbUtils);
42
+ listEntitiesByEntity<B extends Entity, T extends Entity, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, opts?: {
43
+ lastKey?: Record<string, AttributeValue>;
44
+ ProjectionExpression?: ProjectionExpressionValues;
45
+ limit?: number;
46
+ }): Promise<{
47
+ items: Mutual<B, T, M>[];
48
+ lastKey?: Record<string, AttributeValue>;
49
+ }>;
50
+ getMutual<B extends Entity, T extends Entity, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, opts?: {
51
+ isFromMetadata?: boolean;
52
+ ProjectionExpression?: string;
53
+ }): Promise<Mutual<B, T, M>>;
54
+ checkMutualExist<B extends Entity, T extends Entity>(byEntityType: B, byEntityId: string, entityType: T, entityId: string): Promise<void>;
55
+ createMutualTransactItems<B extends Entity, T extends Entity, M extends Record<string, unknown>>(mutual: Mutual<B, T, M>, opts?: {
56
+ ConditionExpression?: string;
57
+ ExpressionAttributeNames?: Record<string, string>;
58
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
59
+ }): TransactWriteItem[];
60
+ createMutual<B extends Entity, T extends Entity, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, byData: EntitySchemaMap[B], entityType: T, entityId: string, data: EntitySchemaMap[T], mutualData?: M, opts?: {
61
+ ConditionExpression?: string;
62
+ ExpressionAttributeNames?: Record<string, string>;
63
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
64
+ createAndUpdateDatetime?: Date;
65
+ }): Promise<Mutual<B, T, M>>;
66
+ updateMutual<B extends Entity, T extends Entity, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, toUpdate: {
67
+ mutualData: Record<string, unknown>;
68
+ mutualUpdatedAt?: string;
69
+ updatedAt?: string;
70
+ }, opts?: {
71
+ ConditionExpression?: string;
72
+ ExpressionAttributeNames?: Record<string, string>;
73
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
74
+ returnUpdatedValue?: boolean;
75
+ maxObjectUpdateLevel?: number;
76
+ }): Promise<Mutual<B, T, M> | undefined>;
77
+ deleteMutual<B extends Entity, T extends Entity, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, opts?: {
78
+ ConditionExpression?: string;
79
+ ExpressionAttributeNames?: Record<string, string>;
80
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
81
+ }): Promise<Mutual<B, T, M>>;
82
+ createMutualLock<B extends Entity, T extends Entity>({ byEntityType, byEntityId, entityType, version, }: {
83
+ byEntityType: B;
84
+ byEntityId: string;
85
+ entityType: T;
86
+ version: string;
87
+ }): Promise<void>;
88
+ deleteMutualLock<B extends Entity, T extends Entity>({ byEntityType, byEntityId, entityType, }: {
89
+ byEntityType: B;
90
+ byEntityId: string;
91
+ entityType: T;
92
+ }): Promise<void>;
93
+ }
94
+ //# sourceMappingURL=Mutual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mutual.d.ts","sourceRoot":"","sources":["../../../../data/Mutual.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,qBAAa,MAAM,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAGxB,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,MAAM;IAClB,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACnC,UAAU,EAAE,CAAC;IACb,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACjC,UAAU,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM;IACxB,OAAO,CAAC,U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MAAM,CAAC,CAAC;QAClD,yBAAyB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;KAC5D,GACA,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IA4FrB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,EACzD,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,GACR,EAAE;QACD,YAAY,EAAE,CAAC,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,CAAC,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwEX,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,EACzD,YAAY,EACZ,UAAU,EACV,UAAU,GACX,EAAE;QACD,YAAY,EAAE,CAAC,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,CAAC,CAAC;KACf,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBlB"}
@@ -0,0 +1,492 @@
1
+ import { BatchStatementErrorCodeEnum, TransactionCanceledException, } from '@aws-sdk/client-dynamodb';
2
+ import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
3
+ import { ulid } from 'ulid';
4
+ import { StandardError } from '#/errors/standard-error';
5
+ import { sleep } from '#/helpers/sleep';
6
+ import { PROJECTION_EXPRESSION, } from './ProjectionExpression';
7
+ import { Repository } from './abstract/Repository.base';
8
+ export class Mutual {
9
+ byEntityType;
10
+ byEntityId;
11
+ byData;
12
+ entityType;
13
+ entityId;
14
+ data;
15
+ mutualData;
16
+ mutualId;
17
+ _createdAt;
18
+ _updatedAt;
19
+ _mutualUpdatedAt;
20
+ _expiresAt;
21
+ constructor(byEntityType, byEntityId, byData, entityType, entityId, data, mutualData, mutualId, _createdAt, _updatedAt, _mutualUpdatedAt, _expiresAt) {
22
+ this.byEntityType = byEntityType;
23
+ this.byEntityId = byEntityId;
24
+ this.byData = byData;
25
+ this.entityType = entityType;
26
+ this.entityId = entityId;
27
+ this.data = data;
28
+ this.mutualData = mutualData;
29
+ this.mutualId = mutualId;
30
+ this._createdAt = _createdAt;
31
+ this._updatedAt = _updatedAt;
32
+ this._mutualUpdatedAt = _mutualUpdatedAt;
33
+ this._expiresAt = _expiresAt;
34
+ }
35
+ static fromItem(item) {
36
+ if (!item)
37
+ throw new StandardError('MUTUAL_IS_UNDEFINED', 'Mutual item empty');
38
+ const parsedItem = unmarshall(item);
39
+ return new Mutual(parsedItem.byEntityType, parsedItem.byEntityId, parsedItem.byData, parsedItem.entityType, parsedItem.entityId, parsedItem.data, parsedItem.mutualData, parsedItem.mutualId, parsedItem.createdAt ? new Date(parsedItem.createdAt) : undefined, parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : undefined, parsedItem.mutualUpdatedAt
40
+ ? new Date(parsedItem.mutualUpdatedAt)
41
+ : undefined, parsedItem.expiresAt ? new Date(parsedItem.expiresAt) : undefined);
42
+ }
43
+ mainKeys() {
44
+ return {
45
+ PK: { S: this.mainPk },
46
+ SK: { S: this.mainSk },
47
+ };
48
+ }
49
+ subKeys() {
50
+ return {
51
+ PK: { S: this.byFullEntityId },
52
+ SK: { S: this.fullEntityId },
53
+ };
54
+ }
55
+ get byFullEntityId() {
56
+ return `${this.byEntityType}#${this.byEntityId}`;
57
+ }
58
+ get fullEntityId() {
59
+ return `${this.entityType}#${this.entityId}`;
60
+ }
61
+ get listEntitySK() {
62
+ return this.entityType;
63
+ }
64
+ get mainPk() {
65
+ return `MUTUAL#${this.mutualId}`;
66
+ }
67
+ get mainSk() {
68
+ return '#METADATA#';
69
+ }
70
+ get createdAt() {
71
+ return this._createdAt?.toISOString();
72
+ }
73
+ get updatedAt() {
74
+ return this._updatedAt?.toISOString();
75
+ }
76
+ get mutualUpdatedAt() {
77
+ return this._mutualUpdatedAt?.toISOString();
78
+ }
79
+ get expiresAt() {
80
+ return this._expiresAt?.toISOString();
81
+ }
82
+ toMutualItemOnly() {
83
+ // Mutual #METADATA# has `mutualData` only
84
+ return {
85
+ ...marshall({ ...this.toJSON(), data: {} }, { removeUndefinedValues: true }),
86
+ ...this.mainKeys(),
87
+ };
88
+ }
89
+ toItem() {
90
+ return {
91
+ ...marshall(this.toJSON(), { removeUndefinedValues: true }),
92
+ ...this.mainKeys(),
93
+ };
94
+ }
95
+ toReversedItem() {
96
+ const item = this.toJSON();
97
+ const reversedMutual = {
98
+ ...item,
99
+ byEntityType: item.entityType,
100
+ byEntityId: item.entityId,
101
+ entityType: item.byEntityType,
102
+ entityId: item.byEntityId,
103
+ data: this.byData,
104
+ };
105
+ return {
106
+ ...marshall(reversedMutual, { removeUndefinedValues: true }),
107
+ ...this.mainKeys(),
108
+ };
109
+ }
110
+ toJSON() {
111
+ return {
112
+ byEntityType: this.byEntityType,
113
+ byEntityId: this.byEntityId,
114
+ entityType: this.entityType,
115
+ entityId: this.entityId,
116
+ mutualId: this.mutualId,
117
+ data: this.data,
118
+ mutualData: this.mutualData,
119
+ createdAt: this.createdAt,
120
+ updatedAt: this.updatedAt,
121
+ mutualUpdatedAt: this.mutualUpdatedAt,
122
+ expiresAt: this.expiresAt,
123
+ };
124
+ }
125
+ }
126
+ export class MutualRepository extends Repository {
127
+ TABLE_NAME;
128
+ dynamodbClient;
129
+ ddbUtils;
130
+ constructor(TABLE_NAME, dynamodbClient, ddbUtils) {
131
+ super();
132
+ this.TABLE_NAME = TABLE_NAME;
133
+ this.dynamodbClient = dynamodbClient;
134
+ this.ddbUtils = ddbUtils;
135
+ }
136
+ async listEntitiesByEntity(byEntityType, byEntityId, entityType, opts = {}) {
137
+ const mutual = new Mutual(byEntityType, byEntityId, {}, entityType, 'list_by_only', {}, {});
138
+ const listAssociationsQuery = {
139
+ TableName: this.TABLE_NAME,
140
+ KeyConditionExpression: '#PK = :PK and begins_with(#SK, :SK)',
141
+ FilterExpression: 'attribute_not_exists(#expiresAt) or attribute_type(#expiresAt, :nullType)',
142
+ ExpressionAttributeNames: {
143
+ '#PK': 'PK',
144
+ '#SK': 'SK',
145
+ '#expiresAt': 'expiresAt',
146
+ },
147
+ ExpressionAttributeValues: {
148
+ ':PK': {
149
+ S: mutual.byFullEntityId,
150
+ },
151
+ ':SK': {
152
+ S: mutual.listEntitySK,
153
+ },
154
+ ':nullType': { S: 'NULL' },
155
+ },
156
+ ProjectionExpression: opts.ProjectionExpression,
157
+ };
158
+ let lastKey = opts.lastKey;
159
+ let items = [];
160
+ let remainingCount = opts.limit ?? 0;
161
+ do {
162
+ const resp = await this.dynamodbClient.query({
163
+ ...listAssociationsQuery,
164
+ ...(remainingCount && { Limit: remainingCount }),
165
+ ...(lastKey && {
166
+ ExclusiveStartKey: lastKey,
167
+ }),
168
+ });
169
+ items = items.concat(resp.Items?.map((item) => Mutual.fromItem(item)) || []);
170
+ lastKey = resp.LastEvaluatedKey;
171
+ if (opts.limit) {
172
+ remainingCount = remainingCount - (resp.Items?.length ?? 0);
173
+ }
174
+ } while (
175
+ // limit is given, haven't reach limit, and there are still items to retrieve
176
+ (opts.limit && remainingCount && lastKey) ||
177
+ // no limit is given and there are still items to retrieve
178
+ (!opts.limit && lastKey));
179
+ return {
180
+ items,
181
+ lastKey,
182
+ };
183
+ }
184
+ async getMutual(byEntityType, byEntityId, entityType, entityId, opts) {
185
+ const mutual = new Mutual(byEntityType, byEntityId, {}, entityType, entityId, {}, {});
186
+ const resp = await this.dynamodbClient.getItem({
187
+ TableName: this.TABLE_NAME,
188
+ Key: mutual.subKeys(),
189
+ ProjectionExpression: opts?.ProjectionExpression,
190
+ });
191
+ let mutualMetadata = null;
192
+ if (opts?.isFromMetadata) {
193
+ const tempMutual = Mutual.fromItem(resp.Item);
194
+ const respMetadataMutual = await this.dynamodbClient.getItem({
195
+ TableName: this.TABLE_NAME,
196
+ Key: tempMutual.mainKeys(),
197
+ ProjectionExpression: opts?.ProjectionExpression,
198
+ });
199
+ mutualMetadata = Mutual.fromItem(respMetadataMutual.Item);
200
+ }
201
+ return mutualMetadata || Mutual.fromItem(resp.Item);
202
+ }
203
+ async checkMutualExist(byEntityType, byEntityId, entityType, entityId) {
204
+ const mutual = new Mutual(byEntityType, byEntityId, {}, entityType, entityId, {}, {});
205
+ const resp = await this.dynamodbClient.getItem({
206
+ TableName: this.TABLE_NAME,
207
+ Key: mutual.subKeys(),
208
+ ProjectionExpression: 'PK, SK, expiresAt',
209
+ });
210
+ if (resp.Item && !resp.Item?.expiresAt) {
211
+ throw new StandardError('MUTUAL_EXISTS', 'Entities are already linked');
212
+ }
213
+ return;
214
+ }
215
+ createMutualTransactItems(mutual, opts) {
216
+ const TransactItems = [
217
+ {
218
+ Put: {
219
+ TableName: this.TABLE_NAME,
220
+ ConditionExpression: opts?.ConditionExpression ||
221
+ 'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
222
+ ExpressionAttributeNames: opts?.ExpressionAttributeNames,
223
+ ExpressionAttributeValues: opts?.ExpressionAttributeValues,
224
+ Item: mutual.toItem(),
225
+ },
226
+ },
227
+ {
228
+ Put: {
229
+ TableName: this.TABLE_NAME,
230
+ ConditionExpression: opts?.ConditionExpression ||
231
+ 'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
232
+ ExpressionAttributeNames: opts?.ExpressionAttributeNames,
233
+ ExpressionAttributeValues: opts?.ExpressionAttributeValues,
234
+ Item: {
235
+ ...mutual.toItem(),
236
+ PK: { S: mutual.byFullEntityId },
237
+ SK: { S: mutual.fullEntityId },
238
+ R1PK: { S: mutual.fullEntityId },
239
+ R1SK: { S: mutual.byFullEntityId },
240
+ R2PK: { S: mutual.mainPk },
241
+ R2SK: { S: mutual.byFullEntityId },
242
+ },
243
+ },
244
+ },
245
+ {
246
+ Put: {
247
+ TableName: this.TABLE_NAME,
248
+ ConditionExpression: opts?.ConditionExpression ||
249
+ 'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
250
+ ExpressionAttributeNames: opts?.ExpressionAttributeNames,
251
+ ExpressionAttributeValues: opts?.ExpressionAttributeValues,
252
+ Item: {
253
+ ...mutual.toReversedItem(),
254
+ PK: { S: mutual.fullEntityId },
255
+ SK: { S: mutual.byFullEntityId },
256
+ R1PK: { S: mutual.byFullEntityId },
257
+ R1SK: { S: mutual.fullEntityId },
258
+ R2PK: { S: mutual.mainPk },
259
+ R2SK: { S: mutual.fullEntityId },
260
+ },
261
+ },
262
+ },
263
+ ];
264
+ return TransactItems;
265
+ }
266
+ async createMutual(byEntityType, byEntityId, byData, entityType, entityId, data, mutualData = {}, opts) {
267
+ const errorContext = {};
268
+ const currentDatetime = opts?.createAndUpdateDatetime || new Date();
269
+ const mutual = new Mutual(byEntityType, byEntityId, byData, entityType, entityId, data, mutualData, ulid(), currentDatetime, currentDatetime, currentDatetime);
270
+ const TransactItems = this.createMutualTransactItems(mutual, {
271
+ ConditionExpression: opts?.ConditionExpression,
272
+ ExpressionAttributeNames: opts?.ExpressionAttributeNames,
273
+ ExpressionAttributeValues: opts?.ExpressionAttributeValues,
274
+ });
275
+ errorContext.TransactItems = TransactItems;
276
+ await this.dynamodbClient.transactWriteItems({ TransactItems });
277
+ return mutual;
278
+ }
279
+ async updateMutual(byEntityType, byEntityId, entityType, entityId, toUpdate, opts) {
280
+ const returnUpdatedValue = opts?.returnUpdatedValue ?? false;
281
+ const errorContext = {};
282
+ try {
283
+ const mutual = await this.getMutual(byEntityType, byEntityId, entityType, entityId, { ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA });
284
+ const currentDatetime = new Date().toISOString();
285
+ const toUpdateExpressions = this.toUpdate({
286
+ mutualUpdatedAt: currentDatetime,
287
+ ...toUpdate,
288
+ }, { maxLevel: opts?.maxObjectUpdateLevel });
289
+ const updateExpression = {
290
+ ConditionExpression: opts?.ConditionExpression || 'attribute_exists(PK)',
291
+ UpdateExpression: toUpdateExpressions.UpdateExpression,
292
+ ExpressionAttributeNames: {
293
+ ...toUpdateExpressions.ExpressionAttributeNames,
294
+ ...opts?.ExpressionAttributeNames,
295
+ },
296
+ ExpressionAttributeValues: {
297
+ ...toUpdateExpressions.ExpressionAttributeValues,
298
+ ...opts?.ExpressionAttributeValues,
299
+ },
300
+ };
301
+ const TransactItems = [
302
+ {
303
+ Update: {
304
+ TableName: this.TABLE_NAME,
305
+ Key: mutual.mainKeys(),
306
+ ...updateExpression,
307
+ },
308
+ },
309
+ {
310
+ Update: {
311
+ TableName: this.TABLE_NAME,
312
+ Key: {
313
+ PK: { S: mutual.byFullEntityId },
314
+ SK: { S: mutual.fullEntityId },
315
+ },
316
+ ...updateExpression,
317
+ },
318
+ },
319
+ {
320
+ Update: {
321
+ TableName: this.TABLE_NAME,
322
+ Key: {
323
+ PK: { S: mutual.fullEntityId },
324
+ SK: { S: mutual.byFullEntityId },
325
+ },
326
+ ...updateExpression,
327
+ },
328
+ },
329
+ ];
330
+ errorContext.TransactItems = TransactItems;
331
+ await this.ddbUtils.executeTransactWrite({ TransactItems });
332
+ if (!returnUpdatedValue) {
333
+ return;
334
+ }
335
+ const updatedMutual = await this.getMutual(byEntityType, byEntityId, entityType, entityId);
336
+ return updatedMutual;
337
+ }
338
+ catch (err) {
339
+ if (err instanceof StandardError &&
340
+ err.code === 'CONDITIONAL_CHECK_FAILED') {
341
+ throw new StandardError('MUTUAL_NOT_FOUND', 'Mutual not found', err, {
342
+ errorContext,
343
+ });
344
+ }
345
+ throw err;
346
+ }
347
+ }
348
+ async deleteMutual(byEntityType, byEntityId, entityType, entityId, opts) {
349
+ const errorContext = {
350
+ byEntityType,
351
+ byEntityId,
352
+ entityType,
353
+ entityId,
354
+ };
355
+ try {
356
+ const mutual = await this.getMutual(byEntityType, byEntityId, entityType, entityId, { ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA });
357
+ const tenMinsLater = Math.floor(new Date().getTime() / 1000 + 10 * 60);
358
+ const expressions = {
359
+ UpdateExpression: 'SET #expiresAt = :expiresAt, #mutualUpdatedAt = :mutualUpdatedAt, #updatedAt = :mutualUpdatedAt',
360
+ ConditionExpression: opts?.ConditionExpression ||
361
+ 'attribute_exists(PK) AND attribute_not_exists(#expiresAt)',
362
+ ExpressionAttributeNames: {
363
+ '#expiresAt': 'expiresAt',
364
+ '#mutualUpdatedAt': 'mutualUpdatedAt',
365
+ '#updatedAt': 'updatedAt',
366
+ ...opts?.ExpressionAttributeNames,
367
+ },
368
+ ExpressionAttributeValues: {
369
+ ':expiresAt': { N: String(tenMinsLater) },
370
+ ':mutualUpdatedAt': { S: new Date().toISOString() },
371
+ ...opts?.ExpressionAttributeValues,
372
+ },
373
+ };
374
+ const TransactItems = [
375
+ {
376
+ Update: {
377
+ TableName: this.TABLE_NAME,
378
+ Key: mutual.mainKeys(),
379
+ ...expressions,
380
+ },
381
+ },
382
+ {
383
+ Update: {
384
+ TableName: this.TABLE_NAME,
385
+ Key: {
386
+ PK: { S: mutual.byFullEntityId },
387
+ SK: { S: mutual.fullEntityId },
388
+ },
389
+ ...expressions,
390
+ },
391
+ },
392
+ {
393
+ Update: {
394
+ TableName: this.TABLE_NAME,
395
+ Key: {
396
+ PK: { S: mutual.fullEntityId },
397
+ SK: { S: mutual.byFullEntityId },
398
+ },
399
+ ...expressions,
400
+ },
401
+ },
402
+ ];
403
+ errorContext.TransactItems = TransactItems;
404
+ await this.dynamodbClient.transactWriteItems({ TransactItems });
405
+ return mutual;
406
+ }
407
+ catch (err) {
408
+ const isConditionalCheckFailed = err instanceof TransactionCanceledException &&
409
+ err.CancellationReasons?.some((reason) => reason.Code === BatchStatementErrorCodeEnum.ConditionalCheckFailed);
410
+ const isMutualIsUndefined = err instanceof StandardError && err.code === 'MUTUAL_IS_UNDEFINED';
411
+ if (isConditionalCheckFailed || isMutualIsUndefined) {
412
+ throw new StandardError('MUTUAL_NOT_FOUND', 'Mutual not found', err, {
413
+ errorContext,
414
+ });
415
+ }
416
+ throw err;
417
+ }
418
+ }
419
+ async createMutualLock({ byEntityType, byEntityId, entityType, version, }) {
420
+ let retryCount = 2;
421
+ const itemKey = {
422
+ PK: {
423
+ S: `MUTUAL#${byEntityType}#${byEntityId}#${entityType}`,
424
+ },
425
+ SK: { S: '#LOCK#' },
426
+ };
427
+ do {
428
+ try {
429
+ const fiveMinsLater = Math.floor(new Date().getTime() / 1000 + 5 * 60);
430
+ await this.dynamodbClient.putItem({
431
+ TableName: this.TABLE_NAME,
432
+ Item: {
433
+ ...itemKey,
434
+ version: { S: version },
435
+ status: { S: 'LOCK' },
436
+ expiresAt: {
437
+ // auto release lock in case the mutual logic gone wrong to prevent dead lock
438
+ N: `${fiveMinsLater}`,
439
+ },
440
+ },
441
+ ConditionExpression: 'attribute_not_exists(PK) OR version < :version AND #status <> :status',
442
+ ExpressionAttributeNames: { '#status': 'status' },
443
+ ExpressionAttributeValues: {
444
+ ':version': { S: version },
445
+ ':status': { S: 'LOCK' },
446
+ },
447
+ });
448
+ return;
449
+ }
450
+ catch (err) {
451
+ console.log('=====CATCHED_MUTUAL_LOCK_CONFLICT=====');
452
+ const lock = await this.dynamodbClient.getItem({
453
+ TableName: this.TABLE_NAME,
454
+ Key: itemKey,
455
+ });
456
+ // if version is lower, throw not retryable error to skip
457
+ const existingVersion = lock.Item?.version?.S ?? '';
458
+ const isExistingVersionGreaterThanNewVersion = existingVersion >= version;
459
+ if (isExistingVersionGreaterThanNewVersion) {
460
+ throw new StandardError('MUTUAL_LOCK_CONFLICT', 'Lock conflict', err, { lock: lock.Item });
461
+ }
462
+ // default behaviour
463
+ // if version is higher, retry
464
+ // if lock not found, retry
465
+ await sleep(2000);
466
+ console.log('=====RETRY_MUTUAL_LOCK=====');
467
+ }
468
+ } while (retryCount-- > 0);
469
+ // catch real unhandled error, so it can reach DLQ for inspection
470
+ throw new StandardError('RETRYABLE_MUTUAL_LOCK_CONFLICT', 'Retryable lock conflict');
471
+ }
472
+ async deleteMutualLock({ byEntityType, byEntityId, entityType, }) {
473
+ try {
474
+ await this.dynamodbClient.updateItem({
475
+ TableName: this.TABLE_NAME,
476
+ Key: {
477
+ PK: {
478
+ S: `MUTUAL#${byEntityType}#${byEntityId}#${entityType}`,
479
+ },
480
+ SK: { S: '#LOCK#' },
481
+ },
482
+ UpdateExpression: 'REMOVE #status',
483
+ ExpressionAttributeNames: { '#status': 'status' },
484
+ });
485
+ return;
486
+ }
487
+ catch (error) {
488
+ // if lock is not found, it's okay
489
+ }
490
+ }
491
+ }
492
+ //# sourceMappingURL=Mutual.js.map