@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.
- package/configs/service.config.ts +14 -0
- package/constants/table.ts +3 -0
- package/controllers/entity/create-entity.controller.ts +51 -0
- package/controllers/entity/delete-entity.controller.ts +35 -0
- package/controllers/entity/entity.http +62 -0
- package/controllers/entity/get-entity.controller.ts +33 -0
- package/controllers/entity/list-entities.controller.ts +69 -0
- package/controllers/entity/update-entity.controller.ts +56 -0
- package/controllers/entity/upsert-entity.controller.ts +97 -0
- package/controllers/mutual/create-mutual.controller.ts +89 -0
- package/controllers/mutual/delete-mutual.controller.ts +40 -0
- package/controllers/mutual/get-mutual.controller.ts +38 -0
- package/controllers/mutual/list-entities-by-entity.controller.ts +76 -0
- package/controllers/mutual/mutual.http +88 -0
- package/controllers/mutual/update-mutual.controller.ts +50 -0
- package/controllers/setupRoutes.ts +73 -0
- package/controllers/tag/list-tags.controller.ts +57 -0
- package/data/DbUtils.ts +40 -0
- package/data/Entity.ts +499 -0
- package/data/EventUtils.ts +47 -0
- package/data/FileObject.ts +16 -0
- package/data/Mutual.ts +779 -0
- package/data/ProjectionExpression.ts +8 -0
- package/data/Tag.ts +470 -0
- package/data/abstract/Item.base.ts +19 -0
- package/data/abstract/Repository.base.ts +92 -0
- package/dist/configs/service.config.d.ts +5 -0
- package/dist/configs/service.config.d.ts.map +1 -0
- package/dist/configs/service.config.js +5 -0
- package/dist/configs/service.config.js.map +1 -0
- package/dist/constants/table.d.ts +4 -0
- package/dist/constants/table.d.ts.map +1 -0
- package/dist/constants/table.js +4 -0
- package/dist/constants/table.js.map +1 -0
- package/dist/controllers/entity/create-entity.controller.d.ts +8 -0
- package/dist/controllers/entity/create-entity.controller.d.ts.map +1 -0
- package/dist/controllers/entity/create-entity.controller.js +44 -0
- package/dist/controllers/entity/create-entity.controller.js.map +1 -0
- package/dist/controllers/entity/delete-entity.controller.d.ts +8 -0
- package/dist/controllers/entity/delete-entity.controller.d.ts.map +1 -0
- package/dist/controllers/entity/delete-entity.controller.js +29 -0
- package/dist/controllers/entity/delete-entity.controller.js.map +1 -0
- package/dist/controllers/entity/get-entity.controller.d.ts +8 -0
- package/dist/controllers/entity/get-entity.controller.d.ts.map +1 -0
- package/dist/controllers/entity/get-entity.controller.js +24 -0
- package/dist/controllers/entity/get-entity.controller.js.map +1 -0
- package/dist/controllers/entity/list-entities.controller.d.ts +8 -0
- package/dist/controllers/entity/list-entities.controller.d.ts.map +1 -0
- package/dist/controllers/entity/list-entities.controller.js +56 -0
- package/dist/controllers/entity/list-entities.controller.js.map +1 -0
- package/dist/controllers/entity/update-entity.controller.d.ts +8 -0
- package/dist/controllers/entity/update-entity.controller.d.ts.map +1 -0
- package/dist/controllers/entity/update-entity.controller.js +45 -0
- package/dist/controllers/entity/update-entity.controller.js.map +1 -0
- package/dist/controllers/entity/upsert-entity.controller.d.ts +10 -0
- package/dist/controllers/entity/upsert-entity.controller.d.ts.map +1 -0
- package/dist/controllers/entity/upsert-entity.controller.js +73 -0
- package/dist/controllers/entity/upsert-entity.controller.js.map +1 -0
- package/dist/controllers/mutual/create-mutual.controller.d.ts +10 -0
- package/dist/controllers/mutual/create-mutual.controller.d.ts.map +1 -0
- package/dist/controllers/mutual/create-mutual.controller.js +70 -0
- package/dist/controllers/mutual/create-mutual.controller.js.map +1 -0
- package/dist/controllers/mutual/delete-mutual.controller.d.ts +8 -0
- package/dist/controllers/mutual/delete-mutual.controller.d.ts.map +1 -0
- package/dist/controllers/mutual/delete-mutual.controller.js +31 -0
- package/dist/controllers/mutual/delete-mutual.controller.js.map +1 -0
- package/dist/controllers/mutual/get-mutual.controller.d.ts +8 -0
- package/dist/controllers/mutual/get-mutual.controller.d.ts.map +1 -0
- package/dist/controllers/mutual/get-mutual.controller.js +24 -0
- package/dist/controllers/mutual/get-mutual.controller.js.map +1 -0
- package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts +8 -0
- package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts.map +1 -0
- package/dist/controllers/mutual/list-entities-by-entity.controller.js +56 -0
- package/dist/controllers/mutual/list-entities-by-entity.controller.js.map +1 -0
- package/dist/controllers/mutual/update-mutual.controller.d.ts +8 -0
- package/dist/controllers/mutual/update-mutual.controller.d.ts.map +1 -0
- package/dist/controllers/mutual/update-mutual.controller.js +40 -0
- package/dist/controllers/mutual/update-mutual.controller.js.map +1 -0
- package/dist/controllers/setupRoutes.d.ts +4 -0
- package/dist/controllers/setupRoutes.d.ts.map +1 -0
- package/dist/controllers/setupRoutes.js +31 -0
- package/dist/controllers/setupRoutes.js.map +1 -0
- package/dist/controllers/tag/list-tags.controller.d.ts +8 -0
- package/dist/controllers/tag/list-tags.controller.d.ts.map +1 -0
- package/dist/controllers/tag/list-tags.controller.js +48 -0
- package/dist/controllers/tag/list-tags.controller.js.map +1 -0
- package/dist/data/DbUtils.d.ts +7 -0
- package/dist/data/DbUtils.d.ts.map +1 -0
- package/dist/data/DbUtils.js +23 -0
- package/dist/data/DbUtils.js.map +1 -0
- package/dist/data/Entity.d.ts +71 -0
- package/dist/data/Entity.d.ts.map +1 -0
- package/dist/data/Entity.js +358 -0
- package/dist/data/Entity.js.map +1 -0
- package/dist/data/EventUtils.d.ts +14 -0
- package/dist/data/EventUtils.d.ts.map +1 -0
- package/dist/data/EventUtils.js +34 -0
- package/dist/data/EventUtils.js.map +1 -0
- package/dist/data/FileObject.d.ts +62 -0
- package/dist/data/FileObject.d.ts.map +1 -0
- package/dist/data/FileObject.js +13 -0
- package/dist/data/FileObject.js.map +1 -0
- package/dist/data/Mutual.d.ts +94 -0
- package/dist/data/Mutual.d.ts.map +1 -0
- package/dist/data/Mutual.js +492 -0
- package/dist/data/Mutual.js.map +1 -0
- package/dist/data/ProjectionExpression.d.ts +6 -0
- package/dist/data/ProjectionExpression.d.ts.map +1 -0
- package/dist/data/ProjectionExpression.js +5 -0
- package/dist/data/ProjectionExpression.js.map +1 -0
- package/dist/data/Tag.d.ts +77 -0
- package/dist/data/Tag.d.ts.map +1 -0
- package/dist/data/Tag.js +330 -0
- package/dist/data/Tag.js.map +1 -0
- package/dist/data/abstract/Item.base.d.ts +11 -0
- package/dist/data/abstract/Item.base.d.ts.map +1 -0
- package/dist/data/abstract/Item.base.js +9 -0
- package/dist/data/abstract/Item.base.js.map +1 -0
- package/dist/data/abstract/Repository.base.d.ts +11 -0
- package/dist/data/abstract/Repository.base.d.ts.map +1 -0
- package/dist/data/abstract/Repository.base.js +54 -0
- package/dist/data/abstract/Repository.base.js.map +1 -0
- package/dist/errors/api-error.d.ts +23 -0
- package/dist/errors/api-error.d.ts.map +1 -0
- package/dist/errors/api-error.js +26 -0
- package/dist/errors/api-error.js.map +1 -0
- package/dist/errors/extendable-error.d.ts +18 -0
- package/dist/errors/extendable-error.d.ts.map +1 -0
- package/dist/errors/extendable-error.js +22 -0
- package/dist/errors/extendable-error.js.map +1 -0
- package/dist/errors/standard-error.d.ts +11 -0
- package/dist/errors/standard-error.d.ts.map +1 -0
- package/dist/errors/standard-error.js +21 -0
- package/dist/errors/standard-error.js.map +1 -0
- package/dist/helpers/dependencies.d.ts +8 -0
- package/dist/helpers/dependencies.d.ts.map +1 -0
- package/dist/helpers/dependencies.js +10 -0
- package/dist/helpers/dependencies.js.map +1 -0
- package/dist/helpers/event.d.ts +22 -0
- package/dist/helpers/event.d.ts.map +1 -0
- package/dist/helpers/event.js +47 -0
- package/dist/helpers/event.js.map +1 -0
- package/dist/helpers/fromLastKeyQuery.d.ts +3 -0
- package/dist/helpers/fromLastKeyQuery.d.ts.map +1 -0
- package/dist/helpers/fromLastKeyQuery.js +7 -0
- package/dist/helpers/fromLastKeyQuery.js.map +1 -0
- package/dist/helpers/sleep.d.ts +2 -0
- package/dist/helpers/sleep.d.ts.map +1 -0
- package/dist/helpers/sleep.js +2 -0
- package/dist/helpers/sleep.js.map +1 -0
- package/dist/helpers/toLastKeyResponse.d.ts +3 -0
- package/dist/helpers/toLastKeyResponse.d.ts.map +1 -0
- package/dist/helpers/toLastKeyResponse.js +7 -0
- package/dist/helpers/toLastKeyResponse.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/entity-type-check.d.ts +3 -0
- package/dist/middlewares/entity-type-check.d.ts.map +1 -0
- package/dist/middlewares/entity-type-check.js +12 -0
- package/dist/middlewares/entity-type-check.js.map +1 -0
- package/dist/middlewares/mutual-type-check.d.ts +3 -0
- package/dist/middlewares/mutual-type-check.d.ts.map +1 -0
- package/dist/middlewares/mutual-type-check.js +13 -0
- package/dist/middlewares/mutual-type-check.js.map +1 -0
- package/dist/mock/container.d.ts +3 -0
- package/dist/mock/container.d.ts.map +1 -0
- package/dist/mock/container.js +3 -0
- package/dist/mock/container.js.map +1 -0
- package/dist/mock/entity.d.ts +13 -0
- package/dist/mock/entity.d.ts.map +1 -0
- package/dist/mock/entity.js +14 -0
- package/dist/mock/entity.js.map +1 -0
- package/dist/mock/monorise/admin.d.ts +127 -0
- package/dist/mock/monorise/admin.d.ts.map +1 -0
- package/dist/mock/monorise/admin.js +29 -0
- package/dist/mock/monorise/admin.js.map +1 -0
- package/dist/mock/monorise/chapter.d.ts +457 -0
- package/dist/mock/monorise/chapter.d.ts.map +1 -0
- package/dist/mock/monorise/chapter.js +81 -0
- package/dist/mock/monorise/chapter.js.map +1 -0
- package/dist/mock/monorise/course.d.ts +311 -0
- package/dist/mock/monorise/course.d.ts.map +1 -0
- package/dist/mock/monorise/course.js +128 -0
- package/dist/mock/monorise/course.js.map +1 -0
- package/dist/mock/monorise/index.d.ts +3599 -0
- package/dist/mock/monorise/index.d.ts.map +1 -0
- package/dist/mock/monorise/index.js +62 -0
- package/dist/mock/monorise/index.js.map +1 -0
- package/dist/mock/monorise/learner.d.ts +390 -0
- package/dist/mock/monorise/learner.d.ts.map +1 -0
- package/dist/mock/monorise/learner.js +59 -0
- package/dist/mock/monorise/learner.js.map +1 -0
- package/dist/mock/monorise/learning-activity.d.ts +266 -0
- package/dist/mock/monorise/learning-activity.d.ts.map +1 -0
- package/dist/mock/monorise/learning-activity.js +50 -0
- package/dist/mock/monorise/learning-activity.js.map +1 -0
- package/dist/mock/monorise/learning-journey-config.d.ts +84 -0
- package/dist/mock/monorise/learning-journey-config.d.ts.map +1 -0
- package/dist/mock/monorise/learning-journey-config.js +27 -0
- package/dist/mock/monorise/learning-journey-config.js.map +1 -0
- package/dist/mock/monorise/module.d.ts +211 -0
- package/dist/mock/monorise/module.d.ts.map +1 -0
- package/dist/mock/monorise/module.js +91 -0
- package/dist/mock/monorise/module.js.map +1 -0
- package/dist/mock/monorise/organization.d.ts +346 -0
- package/dist/mock/monorise/organization.d.ts.map +1 -0
- package/dist/mock/monorise/organization.js +54 -0
- package/dist/mock/monorise/organization.js.map +1 -0
- package/dist/mock/monorise/reference.d.ts +171 -0
- package/dist/mock/monorise/reference.d.ts.map +1 -0
- package/dist/mock/monorise/reference.js +25 -0
- package/dist/mock/monorise/reference.js.map +1 -0
- package/dist/mock/monorise/video.d.ts +346 -0
- package/dist/mock/monorise/video.d.ts.map +1 -0
- package/dist/mock/monorise/video.js +33 -0
- package/dist/mock/monorise/video.js.map +1 -0
- package/dist/packages/core/configs/service.config.d.ts +5 -0
- package/dist/packages/core/configs/service.config.d.ts.map +1 -0
- package/dist/packages/core/configs/service.config.js +5 -0
- package/dist/packages/core/configs/service.config.js.map +1 -0
- package/dist/packages/core/constants/table.d.ts +4 -0
- package/dist/packages/core/constants/table.d.ts.map +1 -0
- package/dist/packages/core/constants/table.js +4 -0
- package/dist/packages/core/constants/table.js.map +1 -0
- package/dist/packages/core/controllers/entity/create-entity.controller.d.ts +8 -0
- package/dist/packages/core/controllers/entity/create-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/create-entity.controller.js +44 -0
- package/dist/packages/core/controllers/entity/create-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/entity/delete-entity.controller.d.ts +8 -0
- package/dist/packages/core/controllers/entity/delete-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/delete-entity.controller.js +29 -0
- package/dist/packages/core/controllers/entity/delete-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/entity/get-entity.controller.d.ts +8 -0
- package/dist/packages/core/controllers/entity/get-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/get-entity.controller.js +24 -0
- package/dist/packages/core/controllers/entity/get-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/entity/list-entities.controller.d.ts +8 -0
- package/dist/packages/core/controllers/entity/list-entities.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/list-entities.controller.js +56 -0
- package/dist/packages/core/controllers/entity/list-entities.controller.js.map +1 -0
- package/dist/packages/core/controllers/entity/update-entity.controller.d.ts +8 -0
- package/dist/packages/core/controllers/entity/update-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/update-entity.controller.js +45 -0
- package/dist/packages/core/controllers/entity/update-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/entity/upsert-entity.controller.d.ts +10 -0
- package/dist/packages/core/controllers/entity/upsert-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/entity/upsert-entity.controller.js +73 -0
- package/dist/packages/core/controllers/entity/upsert-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/mutual/create-mutual.controller.d.ts +10 -0
- package/dist/packages/core/controllers/mutual/create-mutual.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/mutual/create-mutual.controller.js +70 -0
- package/dist/packages/core/controllers/mutual/create-mutual.controller.js.map +1 -0
- package/dist/packages/core/controllers/mutual/delete-mutual.controller.d.ts +8 -0
- package/dist/packages/core/controllers/mutual/delete-mutual.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/mutual/delete-mutual.controller.js +31 -0
- package/dist/packages/core/controllers/mutual/delete-mutual.controller.js.map +1 -0
- package/dist/packages/core/controllers/mutual/get-mutual.controller.d.ts +8 -0
- package/dist/packages/core/controllers/mutual/get-mutual.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/mutual/get-mutual.controller.js +24 -0
- package/dist/packages/core/controllers/mutual/get-mutual.controller.js.map +1 -0
- package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.d.ts +8 -0
- package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.js +56 -0
- package/dist/packages/core/controllers/mutual/list-entities-by-entity.controller.js.map +1 -0
- package/dist/packages/core/controllers/mutual/update-mutual.controller.d.ts +8 -0
- package/dist/packages/core/controllers/mutual/update-mutual.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/mutual/update-mutual.controller.js +40 -0
- package/dist/packages/core/controllers/mutual/update-mutual.controller.js.map +1 -0
- package/dist/packages/core/controllers/setupRoutes.d.ts +3 -0
- package/dist/packages/core/controllers/setupRoutes.d.ts.map +1 -0
- package/dist/packages/core/controllers/setupRoutes.js +33 -0
- package/dist/packages/core/controllers/setupRoutes.js.map +1 -0
- package/dist/packages/core/controllers/tag/list-tags.controller.d.ts +8 -0
- package/dist/packages/core/controllers/tag/list-tags.controller.d.ts.map +1 -0
- package/dist/packages/core/controllers/tag/list-tags.controller.js +48 -0
- package/dist/packages/core/controllers/tag/list-tags.controller.js.map +1 -0
- package/dist/packages/core/data/DbUtils.d.ts +7 -0
- package/dist/packages/core/data/DbUtils.d.ts.map +1 -0
- package/dist/packages/core/data/DbUtils.js +23 -0
- package/dist/packages/core/data/DbUtils.js.map +1 -0
- package/dist/packages/core/data/Entity.d.ts +71 -0
- package/dist/packages/core/data/Entity.d.ts.map +1 -0
- package/dist/packages/core/data/Entity.js +358 -0
- package/dist/packages/core/data/Entity.js.map +1 -0
- package/dist/packages/core/data/EventUtils.d.ts +14 -0
- package/dist/packages/core/data/EventUtils.d.ts.map +1 -0
- package/dist/packages/core/data/EventUtils.js +34 -0
- package/dist/packages/core/data/EventUtils.js.map +1 -0
- package/dist/packages/core/data/FileObject.d.ts +62 -0
- package/dist/packages/core/data/FileObject.d.ts.map +1 -0
- package/dist/packages/core/data/FileObject.js +13 -0
- package/dist/packages/core/data/FileObject.js.map +1 -0
- package/dist/packages/core/data/Mutual.d.ts +94 -0
- package/dist/packages/core/data/Mutual.d.ts.map +1 -0
- package/dist/packages/core/data/Mutual.js +492 -0
- package/dist/packages/core/data/Mutual.js.map +1 -0
- package/dist/packages/core/data/ProjectionExpression.d.ts +6 -0
- package/dist/packages/core/data/ProjectionExpression.d.ts.map +1 -0
- package/dist/packages/core/data/ProjectionExpression.js +5 -0
- package/dist/packages/core/data/ProjectionExpression.js.map +1 -0
- package/dist/packages/core/data/Tag.d.ts +77 -0
- package/dist/packages/core/data/Tag.d.ts.map +1 -0
- package/dist/packages/core/data/Tag.js +330 -0
- package/dist/packages/core/data/Tag.js.map +1 -0
- package/dist/packages/core/data/abstract/Item.base.d.ts +11 -0
- package/dist/packages/core/data/abstract/Item.base.d.ts.map +1 -0
- package/dist/packages/core/data/abstract/Item.base.js +9 -0
- package/dist/packages/core/data/abstract/Item.base.js.map +1 -0
- package/dist/packages/core/data/abstract/Repository.base.d.ts +11 -0
- package/dist/packages/core/data/abstract/Repository.base.d.ts.map +1 -0
- package/dist/packages/core/data/abstract/Repository.base.js +54 -0
- package/dist/packages/core/data/abstract/Repository.base.js.map +1 -0
- package/dist/packages/core/errors/api-error.d.ts +23 -0
- package/dist/packages/core/errors/api-error.d.ts.map +1 -0
- package/dist/packages/core/errors/api-error.js +26 -0
- package/dist/packages/core/errors/api-error.js.map +1 -0
- package/dist/packages/core/errors/extendable-error.d.ts +18 -0
- package/dist/packages/core/errors/extendable-error.d.ts.map +1 -0
- package/dist/packages/core/errors/extendable-error.js +22 -0
- package/dist/packages/core/errors/extendable-error.js.map +1 -0
- package/dist/packages/core/errors/standard-error.d.ts +11 -0
- package/dist/packages/core/errors/standard-error.d.ts.map +1 -0
- package/dist/packages/core/errors/standard-error.js +21 -0
- package/dist/packages/core/errors/standard-error.js.map +1 -0
- package/dist/packages/core/helpers/dependencies.d.ts +8 -0
- package/dist/packages/core/helpers/dependencies.d.ts.map +1 -0
- package/dist/packages/core/helpers/dependencies.js +10 -0
- package/dist/packages/core/helpers/dependencies.js.map +1 -0
- package/dist/packages/core/helpers/event.d.ts +22 -0
- package/dist/packages/core/helpers/event.d.ts.map +1 -0
- package/dist/packages/core/helpers/event.js +47 -0
- package/dist/packages/core/helpers/event.js.map +1 -0
- package/dist/packages/core/helpers/fromLastKeyQuery.d.ts +3 -0
- package/dist/packages/core/helpers/fromLastKeyQuery.d.ts.map +1 -0
- package/dist/packages/core/helpers/fromLastKeyQuery.js +7 -0
- package/dist/packages/core/helpers/fromLastKeyQuery.js.map +1 -0
- package/dist/packages/core/helpers/sleep.d.ts +2 -0
- package/dist/packages/core/helpers/sleep.d.ts.map +1 -0
- package/dist/packages/core/helpers/sleep.js +2 -0
- package/dist/packages/core/helpers/sleep.js.map +1 -0
- package/dist/packages/core/helpers/toLastKeyResponse.d.ts +3 -0
- package/dist/packages/core/helpers/toLastKeyResponse.d.ts.map +1 -0
- package/dist/packages/core/helpers/toLastKeyResponse.js +7 -0
- package/dist/packages/core/helpers/toLastKeyResponse.js.map +1 -0
- package/dist/packages/core/index.d.ts +12 -0
- package/dist/packages/core/index.d.ts.map +1 -0
- package/dist/packages/core/index.js +12 -0
- package/dist/packages/core/index.js.map +1 -0
- package/dist/packages/core/middlewares/entity-type-check.d.ts +3 -0
- package/dist/packages/core/middlewares/entity-type-check.d.ts.map +1 -0
- package/dist/packages/core/middlewares/entity-type-check.js +12 -0
- package/dist/packages/core/middlewares/entity-type-check.js.map +1 -0
- package/dist/packages/core/middlewares/mutual-type-check.d.ts +3 -0
- package/dist/packages/core/middlewares/mutual-type-check.d.ts.map +1 -0
- package/dist/packages/core/middlewares/mutual-type-check.js +13 -0
- package/dist/packages/core/middlewares/mutual-type-check.js.map +1 -0
- package/dist/packages/core/mock/container.d.ts +3 -0
- package/dist/packages/core/mock/container.d.ts.map +1 -0
- package/dist/packages/core/mock/container.js +3 -0
- package/dist/packages/core/mock/container.js.map +1 -0
- package/dist/packages/core/mock/entity.d.ts +13 -0
- package/dist/packages/core/mock/entity.d.ts.map +1 -0
- package/dist/packages/core/mock/entity.js +14 -0
- package/dist/packages/core/mock/entity.js.map +1 -0
- package/dist/packages/core/mock/monorise/admin.d.ts +127 -0
- package/dist/packages/core/mock/monorise/admin.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/admin.js +29 -0
- package/dist/packages/core/mock/monorise/admin.js.map +1 -0
- package/dist/packages/core/mock/monorise/audio.d.ts +324 -0
- package/dist/packages/core/mock/monorise/audio.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/audio.js +32 -0
- package/dist/packages/core/mock/monorise/audio.js.map +1 -0
- package/dist/packages/core/mock/monorise/chapter.d.ts +457 -0
- package/dist/packages/core/mock/monorise/chapter.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/chapter.js +81 -0
- package/dist/packages/core/mock/monorise/chapter.js.map +1 -0
- package/dist/packages/core/mock/monorise/cohort-track.d.ts +118 -0
- package/dist/packages/core/mock/monorise/cohort-track.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/cohort-track.js +38 -0
- package/dist/packages/core/mock/monorise/cohort-track.js.map +1 -0
- package/dist/packages/core/mock/monorise/course-banner.d.ts +149 -0
- package/dist/packages/core/mock/monorise/course-banner.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/course-banner.js +24 -0
- package/dist/packages/core/mock/monorise/course-banner.js.map +1 -0
- package/dist/packages/core/mock/monorise/course.d.ts +311 -0
- package/dist/packages/core/mock/monorise/course.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/course.js +128 -0
- package/dist/packages/core/mock/monorise/course.js.map +1 -0
- package/dist/packages/core/mock/monorise/expert.d.ts +380 -0
- package/dist/packages/core/mock/monorise/expert.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/expert.js +32 -0
- package/dist/packages/core/mock/monorise/expert.js.map +1 -0
- package/dist/packages/core/mock/monorise/index.d.ts +3599 -0
- package/dist/packages/core/mock/monorise/index.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/index.js +62 -0
- package/dist/packages/core/mock/monorise/index.js.map +1 -0
- package/dist/packages/core/mock/monorise/learner-video-progress.d.ts +198 -0
- package/dist/packages/core/mock/monorise/learner-video-progress.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learner-video-progress.js +21 -0
- package/dist/packages/core/mock/monorise/learner-video-progress.js.map +1 -0
- package/dist/packages/core/mock/monorise/learner.d.ts +390 -0
- package/dist/packages/core/mock/monorise/learner.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learner.js +59 -0
- package/dist/packages/core/mock/monorise/learner.js.map +1 -0
- package/dist/packages/core/mock/monorise/learning-activity-submission.d.ts +160 -0
- package/dist/packages/core/mock/monorise/learning-activity-submission.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learning-activity-submission.js +17 -0
- package/dist/packages/core/mock/monorise/learning-activity-submission.js.map +1 -0
- package/dist/packages/core/mock/monorise/learning-activity.d.ts +266 -0
- package/dist/packages/core/mock/monorise/learning-activity.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learning-activity.js +50 -0
- package/dist/packages/core/mock/monorise/learning-activity.js.map +1 -0
- package/dist/packages/core/mock/monorise/learning-journey-config.d.ts +84 -0
- package/dist/packages/core/mock/monorise/learning-journey-config.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learning-journey-config.js +27 -0
- package/dist/packages/core/mock/monorise/learning-journey-config.js.map +1 -0
- package/dist/packages/core/mock/monorise/learning-journey-progress.d.ts +290 -0
- package/dist/packages/core/mock/monorise/learning-journey-progress.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/learning-journey-progress.js +46 -0
- package/dist/packages/core/mock/monorise/learning-journey-progress.js.map +1 -0
- package/dist/packages/core/mock/monorise/module.d.ts +211 -0
- package/dist/packages/core/mock/monorise/module.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/module.js +91 -0
- package/dist/packages/core/mock/monorise/module.js.map +1 -0
- package/dist/packages/core/mock/monorise/organization.d.ts +346 -0
- package/dist/packages/core/mock/monorise/organization.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/organization.js +54 -0
- package/dist/packages/core/mock/monorise/organization.js.map +1 -0
- package/dist/packages/core/mock/monorise/pathway.d.ts +267 -0
- package/dist/packages/core/mock/monorise/pathway.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/pathway.js +221 -0
- package/dist/packages/core/mock/monorise/pathway.js.map +1 -0
- package/dist/packages/core/mock/monorise/phase.d.ts +580 -0
- package/dist/packages/core/mock/monorise/phase.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/phase.js +166 -0
- package/dist/packages/core/mock/monorise/phase.js.map +1 -0
- package/dist/packages/core/mock/monorise/reference.d.ts +171 -0
- package/dist/packages/core/mock/monorise/reference.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/reference.js +25 -0
- package/dist/packages/core/mock/monorise/reference.js.map +1 -0
- package/dist/packages/core/mock/monorise/track.d.ts +617 -0
- package/dist/packages/core/mock/monorise/track.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/track.js +270 -0
- package/dist/packages/core/mock/monorise/track.js.map +1 -0
- package/dist/packages/core/mock/monorise/video.d.ts +346 -0
- package/dist/packages/core/mock/monorise/video.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise/video.js +33 -0
- package/dist/packages/core/mock/monorise/video.js.map +1 -0
- package/dist/packages/core/mock/monorise.d.ts +6 -0
- package/dist/packages/core/mock/monorise.d.ts.map +1 -0
- package/dist/packages/core/mock/monorise.js +5 -0
- package/dist/packages/core/mock/monorise.js.map +1 -0
- package/dist/packages/core/processors/create-entity-processor.d.ts +5 -0
- package/dist/packages/core/processors/create-entity-processor.d.ts.map +1 -0
- package/dist/packages/core/processors/create-entity-processor.js +32 -0
- package/dist/packages/core/processors/create-entity-processor.js.map +1 -0
- package/dist/packages/core/processors/mutual-processor.d.ts +15 -0
- package/dist/packages/core/processors/mutual-processor.d.ts.map +1 -0
- package/dist/packages/core/processors/mutual-processor.js +128 -0
- package/dist/packages/core/processors/mutual-processor.js.map +1 -0
- package/dist/packages/core/processors/prejoin-processor.d.ts +12 -0
- package/dist/packages/core/processors/prejoin-processor.d.ts.map +1 -0
- package/dist/packages/core/processors/prejoin-processor.js +150 -0
- package/dist/packages/core/processors/prejoin-processor.js.map +1 -0
- package/dist/packages/core/processors/replication-processor.d.ts +8 -0
- package/dist/packages/core/processors/replication-processor.d.ts.map +1 -0
- package/dist/packages/core/processors/replication-processor.js +180 -0
- package/dist/packages/core/processors/replication-processor.js.map +1 -0
- package/dist/packages/core/processors/tag-processor.d.ts +11 -0
- package/dist/packages/core/processors/tag-processor.d.ts.map +1 -0
- package/dist/packages/core/processors/tag-processor.js +106 -0
- package/dist/packages/core/processors/tag-processor.js.map +1 -0
- package/dist/packages/core/services/DependencyContainer.d.ts +51 -0
- package/dist/packages/core/services/DependencyContainer.d.ts.map +1 -0
- package/dist/packages/core/services/DependencyContainer.js +115 -0
- package/dist/packages/core/services/DependencyContainer.js.map +1 -0
- package/dist/packages/core/services/entity-service-lifecycle.d.ts +12 -0
- package/dist/packages/core/services/entity-service-lifecycle.d.ts.map +1 -0
- package/dist/packages/core/services/entity-service-lifecycle.js +23 -0
- package/dist/packages/core/services/entity-service-lifecycle.js.map +1 -0
- package/dist/packages/core/services/entity.service.d.ts +32 -0
- package/dist/packages/core/services/entity.service.d.ts.map +1 -0
- package/dist/packages/core/services/entity.service.js +121 -0
- package/dist/packages/core/services/entity.service.js.map +1 -0
- package/dist/packages/core/services/mutual.service.d.ts +64 -0
- package/dist/packages/core/services/mutual.service.d.ts.map +1 -0
- package/dist/packages/core/services/mutual.service.js +144 -0
- package/dist/packages/core/services/mutual.service.js.map +1 -0
- package/dist/packages/core/types/entity.type.d.ts +20 -0
- package/dist/packages/core/types/entity.type.d.ts.map +1 -0
- package/dist/packages/core/types/entity.type.js +2 -0
- package/dist/packages/core/types/entity.type.js.map +1 -0
- package/dist/processors/create-entity-processor.d.ts +5 -0
- package/dist/processors/create-entity-processor.d.ts.map +1 -0
- package/dist/processors/create-entity-processor.js +33 -0
- package/dist/processors/create-entity-processor.js.map +1 -0
- package/dist/processors/mutual-processor.d.ts +15 -0
- package/dist/processors/mutual-processor.d.ts.map +1 -0
- package/dist/processors/mutual-processor.js +129 -0
- package/dist/processors/mutual-processor.js.map +1 -0
- package/dist/processors/prejoin-processor.d.ts +12 -0
- package/dist/processors/prejoin-processor.d.ts.map +1 -0
- package/dist/processors/prejoin-processor.js +151 -0
- package/dist/processors/prejoin-processor.js.map +1 -0
- package/dist/processors/replication-processor.d.ts +8 -0
- package/dist/processors/replication-processor.d.ts.map +1 -0
- package/dist/processors/replication-processor.js +181 -0
- package/dist/processors/replication-processor.js.map +1 -0
- package/dist/processors/tag-processor.d.ts +11 -0
- package/dist/processors/tag-processor.d.ts.map +1 -0
- package/dist/processors/tag-processor.js +107 -0
- package/dist/processors/tag-processor.js.map +1 -0
- package/dist/services/DependencyContainer.d.ts +51 -0
- package/dist/services/DependencyContainer.d.ts.map +1 -0
- package/dist/services/DependencyContainer.js +115 -0
- package/dist/services/DependencyContainer.js.map +1 -0
- package/dist/services/entity-service-lifecycle.d.ts +12 -0
- package/dist/services/entity-service-lifecycle.d.ts.map +1 -0
- package/dist/services/entity-service-lifecycle.js +23 -0
- package/dist/services/entity-service-lifecycle.js.map +1 -0
- package/dist/services/entity.service.d.ts +32 -0
- package/dist/services/entity.service.d.ts.map +1 -0
- package/dist/services/entity.service.js +121 -0
- package/dist/services/entity.service.js.map +1 -0
- package/dist/services/mutual.service.d.ts +64 -0
- package/dist/services/mutual.service.d.ts.map +1 -0
- package/dist/services/mutual.service.js +144 -0
- package/dist/services/mutual.service.js.map +1 -0
- package/dist/shared/types/event.d.ts +72 -0
- package/dist/shared/types/event.d.ts.map +1 -0
- package/dist/shared/types/event.js +74 -0
- package/dist/shared/types/event.js.map +1 -0
- package/dist/types/entity.type.d.ts +20 -0
- package/dist/types/entity.type.d.ts.map +1 -0
- package/dist/types/entity.type.js +2 -0
- package/dist/types/entity.type.js.map +1 -0
- package/dist/types/event.d.ts +72 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +74 -0
- package/dist/types/event.js.map +1 -0
- package/errors/api-error.ts +39 -0
- package/errors/extendable-error.ts +35 -0
- package/errors/standard-error.ts +29 -0
- package/helpers/dependencies.ts +10 -0
- package/helpers/event.ts +85 -0
- package/helpers/fromLastKeyQuery.ts +11 -0
- package/helpers/sleep.ts +1 -0
- package/helpers/toLastKeyResponse.ts +11 -0
- package/index.ts +23 -0
- package/middlewares/entity-type-check.ts +20 -0
- package/middlewares/mutual-type-check.ts +26 -0
- package/mock/entity.ts +12 -0
- package/mock/monorise/admin.ts +35 -0
- package/mock/monorise/chapter.ts +94 -0
- package/mock/monorise/course.ts +149 -0
- package/mock/monorise/index.ts +143 -0
- package/mock/monorise/learner.ts +66 -0
- package/mock/monorise/learning-activity.ts +62 -0
- package/mock/monorise/learning-journey-config.ts +34 -0
- package/mock/monorise/module.ts +108 -0
- package/mock/monorise/organization.ts +63 -0
- package/mock/monorise/reference.ts +28 -0
- package/mock/monorise/video.ts +36 -0
- package/package.json +31 -0
- package/processors/create-entity-processor.ts +55 -0
- package/processors/mutual-processor.ts +262 -0
- package/processors/prejoin-processor.ts +264 -0
- package/processors/replication-processor.ts +261 -0
- package/processors/tag-processor.ts +174 -0
- package/services/DependencyContainer.ts +208 -0
- package/services/entity-service-lifecycle.ts +41 -0
- package/services/entity.service.ts +201 -0
- package/services/mutual.service.ts +285 -0
- package/tsconfig.json +118 -0
- package/types/entity.type.ts +62 -0
- package/types/event.ts +84 -0
package/data/Mutual.ts
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AttributeValue,
|
|
3
|
+
BatchStatementErrorCodeEnum,
|
|
4
|
+
type DynamoDB,
|
|
5
|
+
type QueryCommandInput,
|
|
6
|
+
type TransactWriteItem,
|
|
7
|
+
TransactionCanceledException,
|
|
8
|
+
} from '@aws-sdk/client-dynamodb';
|
|
9
|
+
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
|
|
10
|
+
import type { Entity, EntitySchemaMap } from '@monorise/base';
|
|
11
|
+
import { ulid } from 'ulid';
|
|
12
|
+
import type { DbUtils } from '#/data/DbUtils';
|
|
13
|
+
import { StandardError } from '#/errors/standard-error';
|
|
14
|
+
import { sleep } from '#/helpers/sleep';
|
|
15
|
+
import {
|
|
16
|
+
PROJECTION_EXPRESSION,
|
|
17
|
+
type ProjectionExpressionValues,
|
|
18
|
+
} from './ProjectionExpression';
|
|
19
|
+
import { Repository } from './abstract/Repository.base';
|
|
20
|
+
|
|
21
|
+
export class Mutual<
|
|
22
|
+
B extends Entity,
|
|
23
|
+
T extends Entity,
|
|
24
|
+
M extends Record<string, unknown>,
|
|
25
|
+
> {
|
|
26
|
+
constructor(
|
|
27
|
+
public byEntityType: B,
|
|
28
|
+
public byEntityId: string,
|
|
29
|
+
public byData: Partial<EntitySchemaMap[B]>,
|
|
30
|
+
public entityType: T,
|
|
31
|
+
public entityId: string,
|
|
32
|
+
public data: Partial<EntitySchemaMap[T]>,
|
|
33
|
+
public mutualData: M,
|
|
34
|
+
public mutualId?: string,
|
|
35
|
+
private _createdAt?: Date,
|
|
36
|
+
private _updatedAt?: Date,
|
|
37
|
+
private _mutualUpdatedAt?: Date,
|
|
38
|
+
private _expiresAt?: Date,
|
|
39
|
+
) {}
|
|
40
|
+
|
|
41
|
+
static fromItem<
|
|
42
|
+
B extends Entity,
|
|
43
|
+
T extends Entity,
|
|
44
|
+
M extends Record<string, unknown>,
|
|
45
|
+
>(item?: Record<string, AttributeValue>): Mutual<B, T, M> {
|
|
46
|
+
if (!item)
|
|
47
|
+
throw new StandardError('MUTUAL_IS_UNDEFINED', 'Mutual item empty');
|
|
48
|
+
|
|
49
|
+
const parsedItem = unmarshall(item);
|
|
50
|
+
|
|
51
|
+
return new Mutual<B, T, M>(
|
|
52
|
+
parsedItem.byEntityType,
|
|
53
|
+
parsedItem.byEntityId,
|
|
54
|
+
parsedItem.byData,
|
|
55
|
+
parsedItem.entityType,
|
|
56
|
+
parsedItem.entityId,
|
|
57
|
+
parsedItem.data,
|
|
58
|
+
parsedItem.mutualData,
|
|
59
|
+
parsedItem.mutualId,
|
|
60
|
+
parsedItem.createdAt ? new Date(parsedItem.createdAt) : undefined,
|
|
61
|
+
parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : undefined,
|
|
62
|
+
parsedItem.mutualUpdatedAt
|
|
63
|
+
? new Date(parsedItem.mutualUpdatedAt)
|
|
64
|
+
: undefined,
|
|
65
|
+
parsedItem.expiresAt ? new Date(parsedItem.expiresAt) : undefined,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public mainKeys(): Record<string, AttributeValue> {
|
|
70
|
+
return {
|
|
71
|
+
PK: { S: this.mainPk },
|
|
72
|
+
SK: { S: this.mainSk },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public subKeys(): Record<string, AttributeValue> {
|
|
77
|
+
return {
|
|
78
|
+
PK: { S: this.byFullEntityId },
|
|
79
|
+
SK: { S: this.fullEntityId },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get byFullEntityId(): string {
|
|
84
|
+
return `${this.byEntityType}#${this.byEntityId}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get fullEntityId(): string {
|
|
88
|
+
return `${this.entityType}#${this.entityId}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get listEntitySK(): string {
|
|
92
|
+
return this.entityType as unknown as string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get mainPk(): string {
|
|
96
|
+
return `MUTUAL#${this.mutualId}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get mainSk(): string {
|
|
100
|
+
return '#METADATA#';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get createdAt(): string | undefined {
|
|
104
|
+
return this._createdAt?.toISOString();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get updatedAt(): string | undefined {
|
|
108
|
+
return this._updatedAt?.toISOString();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get mutualUpdatedAt(): string | undefined {
|
|
112
|
+
return this._mutualUpdatedAt?.toISOString();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get expiresAt(): string | undefined {
|
|
116
|
+
return this._expiresAt?.toISOString();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
toMutualItemOnly(): Record<string, AttributeValue> {
|
|
120
|
+
// Mutual #METADATA# has `mutualData` only
|
|
121
|
+
return {
|
|
122
|
+
...marshall(
|
|
123
|
+
{ ...this.toJSON(), data: {} },
|
|
124
|
+
{ removeUndefinedValues: true },
|
|
125
|
+
),
|
|
126
|
+
...this.mainKeys(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
toItem(): Record<string, AttributeValue> {
|
|
131
|
+
return {
|
|
132
|
+
...marshall(this.toJSON(), { removeUndefinedValues: true }),
|
|
133
|
+
...this.mainKeys(),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
toReversedItem(): Record<string, AttributeValue> {
|
|
138
|
+
const item = this.toJSON();
|
|
139
|
+
|
|
140
|
+
const reversedMutual: Record<string, unknown> = {
|
|
141
|
+
...item,
|
|
142
|
+
byEntityType: item.entityType,
|
|
143
|
+
byEntityId: item.entityId,
|
|
144
|
+
entityType: item.byEntityType,
|
|
145
|
+
entityId: item.byEntityId,
|
|
146
|
+
data: this.byData,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
...marshall(reversedMutual, { removeUndefinedValues: true }),
|
|
151
|
+
...this.mainKeys(),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
toJSON(): Record<string, unknown> {
|
|
156
|
+
return {
|
|
157
|
+
byEntityType: this.byEntityType,
|
|
158
|
+
byEntityId: this.byEntityId,
|
|
159
|
+
entityType: this.entityType,
|
|
160
|
+
entityId: this.entityId,
|
|
161
|
+
mutualId: this.mutualId,
|
|
162
|
+
data: this.data,
|
|
163
|
+
mutualData: this.mutualData,
|
|
164
|
+
createdAt: this.createdAt,
|
|
165
|
+
updatedAt: this.updatedAt,
|
|
166
|
+
mutualUpdatedAt: this.mutualUpdatedAt,
|
|
167
|
+
expiresAt: this.expiresAt,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export class MutualRepository extends Repository {
|
|
173
|
+
constructor(
|
|
174
|
+
private readonly TABLE_NAME: string,
|
|
175
|
+
private readonly dynamodbClient: DynamoDB,
|
|
176
|
+
private readonly ddbUtils: DbUtils,
|
|
177
|
+
) {
|
|
178
|
+
super();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async listEntitiesByEntity<
|
|
182
|
+
B extends Entity,
|
|
183
|
+
T extends Entity,
|
|
184
|
+
M extends Record<string, unknown>,
|
|
185
|
+
>(
|
|
186
|
+
byEntityType: B,
|
|
187
|
+
byEntityId: string,
|
|
188
|
+
entityType: T,
|
|
189
|
+
opts: {
|
|
190
|
+
lastKey?: Record<string, AttributeValue>;
|
|
191
|
+
ProjectionExpression?: ProjectionExpressionValues;
|
|
192
|
+
limit?: number; // if this is not set, retrieve all items
|
|
193
|
+
} = {},
|
|
194
|
+
): Promise<{
|
|
195
|
+
items: Mutual<B, T, M>[];
|
|
196
|
+
lastKey?: Record<string, AttributeValue>;
|
|
197
|
+
}> {
|
|
198
|
+
const mutual = new Mutual(
|
|
199
|
+
byEntityType,
|
|
200
|
+
byEntityId,
|
|
201
|
+
{},
|
|
202
|
+
entityType,
|
|
203
|
+
'list_by_only',
|
|
204
|
+
{},
|
|
205
|
+
{},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const listAssociationsQuery: QueryCommandInput = {
|
|
209
|
+
TableName: this.TABLE_NAME,
|
|
210
|
+
KeyConditionExpression: '#PK = :PK and begins_with(#SK, :SK)',
|
|
211
|
+
FilterExpression:
|
|
212
|
+
'attribute_not_exists(#expiresAt) or attribute_type(#expiresAt, :nullType)',
|
|
213
|
+
ExpressionAttributeNames: {
|
|
214
|
+
'#PK': 'PK',
|
|
215
|
+
'#SK': 'SK',
|
|
216
|
+
'#expiresAt': 'expiresAt',
|
|
217
|
+
},
|
|
218
|
+
ExpressionAttributeValues: {
|
|
219
|
+
':PK': {
|
|
220
|
+
S: mutual.byFullEntityId,
|
|
221
|
+
},
|
|
222
|
+
':SK': {
|
|
223
|
+
S: mutual.listEntitySK,
|
|
224
|
+
},
|
|
225
|
+
':nullType': { S: 'NULL' },
|
|
226
|
+
},
|
|
227
|
+
ProjectionExpression: opts.ProjectionExpression,
|
|
228
|
+
};
|
|
229
|
+
let lastKey = opts.lastKey;
|
|
230
|
+
let items: Mutual<B, T, M>[] = [];
|
|
231
|
+
let remainingCount = opts.limit ?? 0;
|
|
232
|
+
do {
|
|
233
|
+
const resp = await this.dynamodbClient.query({
|
|
234
|
+
...listAssociationsQuery,
|
|
235
|
+
...(remainingCount && { Limit: remainingCount }),
|
|
236
|
+
...(lastKey && {
|
|
237
|
+
ExclusiveStartKey: lastKey,
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
items = items.concat(
|
|
242
|
+
resp.Items?.map((item) => Mutual.fromItem(item)) || [],
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
lastKey = resp.LastEvaluatedKey;
|
|
246
|
+
if (opts.limit) {
|
|
247
|
+
remainingCount = remainingCount - (resp.Items?.length ?? 0);
|
|
248
|
+
}
|
|
249
|
+
} while (
|
|
250
|
+
// limit is given, haven't reach limit, and there are still items to retrieve
|
|
251
|
+
(opts.limit && remainingCount && lastKey) ||
|
|
252
|
+
// no limit is given and there are still items to retrieve
|
|
253
|
+
(!opts.limit && lastKey)
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
items,
|
|
258
|
+
lastKey,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async getMutual<
|
|
263
|
+
B extends Entity,
|
|
264
|
+
T extends Entity,
|
|
265
|
+
M extends Record<string, unknown>,
|
|
266
|
+
>(
|
|
267
|
+
byEntityType: B,
|
|
268
|
+
byEntityId: string,
|
|
269
|
+
entityType: T,
|
|
270
|
+
entityId: string,
|
|
271
|
+
opts?: {
|
|
272
|
+
// isFromMetadata to prevent race condition by querying #METADATA#
|
|
273
|
+
isFromMetadata?: boolean;
|
|
274
|
+
ProjectionExpression?: string;
|
|
275
|
+
},
|
|
276
|
+
): Promise<Mutual<B, T, M>> {
|
|
277
|
+
const mutual = new Mutual(
|
|
278
|
+
byEntityType,
|
|
279
|
+
byEntityId,
|
|
280
|
+
{},
|
|
281
|
+
entityType,
|
|
282
|
+
entityId,
|
|
283
|
+
{},
|
|
284
|
+
{},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const resp = await this.dynamodbClient.getItem({
|
|
288
|
+
TableName: this.TABLE_NAME,
|
|
289
|
+
Key: mutual.subKeys(),
|
|
290
|
+
ProjectionExpression: opts?.ProjectionExpression,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
let mutualMetadata: Mutual<B, T, M> | null = null;
|
|
294
|
+
if (opts?.isFromMetadata) {
|
|
295
|
+
const tempMutual = Mutual.fromItem<B, T, M>(resp.Item);
|
|
296
|
+
const respMetadataMutual = await this.dynamodbClient.getItem({
|
|
297
|
+
TableName: this.TABLE_NAME,
|
|
298
|
+
Key: tempMutual.mainKeys(),
|
|
299
|
+
ProjectionExpression: opts?.ProjectionExpression,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
mutualMetadata = Mutual.fromItem(respMetadataMutual.Item);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return mutualMetadata || Mutual.fromItem<B, T, M>(resp.Item);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async checkMutualExist<B extends Entity, T extends Entity>(
|
|
309
|
+
byEntityType: B,
|
|
310
|
+
byEntityId: string,
|
|
311
|
+
entityType: T,
|
|
312
|
+
entityId: string,
|
|
313
|
+
): Promise<void> {
|
|
314
|
+
const mutual = new Mutual(
|
|
315
|
+
byEntityType,
|
|
316
|
+
byEntityId,
|
|
317
|
+
{},
|
|
318
|
+
entityType,
|
|
319
|
+
entityId,
|
|
320
|
+
{},
|
|
321
|
+
{},
|
|
322
|
+
);
|
|
323
|
+
const resp = await this.dynamodbClient.getItem({
|
|
324
|
+
TableName: this.TABLE_NAME,
|
|
325
|
+
Key: mutual.subKeys(),
|
|
326
|
+
ProjectionExpression: 'PK, SK, expiresAt',
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
if (resp.Item && !resp.Item?.expiresAt) {
|
|
330
|
+
throw new StandardError('MUTUAL_EXISTS', 'Entities are already linked');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
createMutualTransactItems<
|
|
337
|
+
B extends Entity,
|
|
338
|
+
T extends Entity,
|
|
339
|
+
M extends Record<string, unknown>,
|
|
340
|
+
>(
|
|
341
|
+
mutual: Mutual<B, T, M>,
|
|
342
|
+
opts?: {
|
|
343
|
+
ConditionExpression?: string;
|
|
344
|
+
ExpressionAttributeNames?: Record<string, string>;
|
|
345
|
+
ExpressionAttributeValues?: Record<string, AttributeValue>;
|
|
346
|
+
},
|
|
347
|
+
): TransactWriteItem[] {
|
|
348
|
+
const TransactItems: TransactWriteItem[] = [
|
|
349
|
+
{
|
|
350
|
+
Put: {
|
|
351
|
+
TableName: this.TABLE_NAME,
|
|
352
|
+
ConditionExpression:
|
|
353
|
+
opts?.ConditionExpression ||
|
|
354
|
+
'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
|
|
355
|
+
ExpressionAttributeNames: opts?.ExpressionAttributeNames,
|
|
356
|
+
ExpressionAttributeValues: opts?.ExpressionAttributeValues,
|
|
357
|
+
Item: mutual.toItem(),
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
Put: {
|
|
362
|
+
TableName: this.TABLE_NAME,
|
|
363
|
+
ConditionExpression:
|
|
364
|
+
opts?.ConditionExpression ||
|
|
365
|
+
'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
|
|
366
|
+
ExpressionAttributeNames: opts?.ExpressionAttributeNames,
|
|
367
|
+
ExpressionAttributeValues: opts?.ExpressionAttributeValues,
|
|
368
|
+
Item: {
|
|
369
|
+
...mutual.toItem(),
|
|
370
|
+
PK: { S: mutual.byFullEntityId },
|
|
371
|
+
SK: { S: mutual.fullEntityId },
|
|
372
|
+
R1PK: { S: mutual.fullEntityId },
|
|
373
|
+
R1SK: { S: mutual.byFullEntityId },
|
|
374
|
+
R2PK: { S: mutual.mainPk },
|
|
375
|
+
R2SK: { S: mutual.byFullEntityId },
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
Put: {
|
|
381
|
+
TableName: this.TABLE_NAME,
|
|
382
|
+
ConditionExpression:
|
|
383
|
+
opts?.ConditionExpression ||
|
|
384
|
+
'attribute_not_exists(PK) OR attribute_exists(expiresAt)',
|
|
385
|
+
ExpressionAttributeNames: opts?.ExpressionAttributeNames,
|
|
386
|
+
ExpressionAttributeValues: opts?.ExpressionAttributeValues,
|
|
387
|
+
Item: {
|
|
388
|
+
...mutual.toReversedItem(),
|
|
389
|
+
PK: { S: mutual.fullEntityId },
|
|
390
|
+
SK: { S: mutual.byFullEntityId },
|
|
391
|
+
R1PK: { S: mutual.byFullEntityId },
|
|
392
|
+
R1SK: { S: mutual.fullEntityId },
|
|
393
|
+
R2PK: { S: mutual.mainPk },
|
|
394
|
+
R2SK: { S: mutual.fullEntityId },
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
];
|
|
399
|
+
|
|
400
|
+
return TransactItems;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
async createMutual<
|
|
404
|
+
B extends Entity,
|
|
405
|
+
T extends Entity,
|
|
406
|
+
M extends Record<string, unknown>,
|
|
407
|
+
>(
|
|
408
|
+
byEntityType: B,
|
|
409
|
+
byEntityId: string,
|
|
410
|
+
byData: EntitySchemaMap[B],
|
|
411
|
+
entityType: T,
|
|
412
|
+
entityId: string,
|
|
413
|
+
data: EntitySchemaMap[T],
|
|
414
|
+
mutualData: M = {} as M,
|
|
415
|
+
opts?: {
|
|
416
|
+
ConditionExpression?: string;
|
|
417
|
+
ExpressionAttributeNames?: Record<string, string>;
|
|
418
|
+
ExpressionAttributeValues?: Record<string, AttributeValue>;
|
|
419
|
+
createAndUpdateDatetime?: Date;
|
|
420
|
+
},
|
|
421
|
+
): Promise<Mutual<B, T, M>> {
|
|
422
|
+
const errorContext: Record<string, unknown> = {};
|
|
423
|
+
const currentDatetime = opts?.createAndUpdateDatetime || new Date();
|
|
424
|
+
const mutual = new Mutual<B, T, M>(
|
|
425
|
+
byEntityType,
|
|
426
|
+
byEntityId,
|
|
427
|
+
byData,
|
|
428
|
+
entityType,
|
|
429
|
+
entityId,
|
|
430
|
+
data,
|
|
431
|
+
mutualData,
|
|
432
|
+
ulid(),
|
|
433
|
+
currentDatetime,
|
|
434
|
+
currentDatetime,
|
|
435
|
+
currentDatetime,
|
|
436
|
+
);
|
|
437
|
+
const TransactItems = this.createMutualTransactItems(mutual, {
|
|
438
|
+
ConditionExpression: opts?.ConditionExpression,
|
|
439
|
+
ExpressionAttributeNames: opts?.ExpressionAttributeNames,
|
|
440
|
+
ExpressionAttributeValues: opts?.ExpressionAttributeValues,
|
|
441
|
+
});
|
|
442
|
+
errorContext.TransactItems = TransactItems;
|
|
443
|
+
|
|
444
|
+
await this.dynamodbClient.transactWriteItems({ TransactItems });
|
|
445
|
+
|
|
446
|
+
return mutual;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async updateMutual<
|
|
450
|
+
B extends Entity,
|
|
451
|
+
T extends Entity,
|
|
452
|
+
M extends Record<string, unknown>,
|
|
453
|
+
>(
|
|
454
|
+
byEntityType: B,
|
|
455
|
+
byEntityId: string,
|
|
456
|
+
entityType: T,
|
|
457
|
+
entityId: string,
|
|
458
|
+
toUpdate: {
|
|
459
|
+
mutualData: Record<string, unknown>;
|
|
460
|
+
mutualUpdatedAt?: string;
|
|
461
|
+
updatedAt?: string;
|
|
462
|
+
},
|
|
463
|
+
opts?: {
|
|
464
|
+
ConditionExpression?: string;
|
|
465
|
+
ExpressionAttributeNames?: Record<string, string>;
|
|
466
|
+
ExpressionAttributeValues?: Record<string, AttributeValue>;
|
|
467
|
+
returnUpdatedValue?: boolean;
|
|
468
|
+
maxObjectUpdateLevel?: number;
|
|
469
|
+
},
|
|
470
|
+
): Promise<Mutual<B, T, M> | undefined> {
|
|
471
|
+
const returnUpdatedValue = opts?.returnUpdatedValue ?? false;
|
|
472
|
+
const errorContext: Record<string, unknown> = {};
|
|
473
|
+
|
|
474
|
+
try {
|
|
475
|
+
const mutual = await this.getMutual<B, T, M>(
|
|
476
|
+
byEntityType,
|
|
477
|
+
byEntityId,
|
|
478
|
+
entityType,
|
|
479
|
+
entityId,
|
|
480
|
+
{ ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA },
|
|
481
|
+
);
|
|
482
|
+
|
|
483
|
+
const currentDatetime = new Date().toISOString();
|
|
484
|
+
const toUpdateExpressions = this.toUpdate(
|
|
485
|
+
{
|
|
486
|
+
mutualUpdatedAt: currentDatetime,
|
|
487
|
+
...toUpdate,
|
|
488
|
+
},
|
|
489
|
+
{ maxLevel: opts?.maxObjectUpdateLevel },
|
|
490
|
+
);
|
|
491
|
+
const updateExpression = {
|
|
492
|
+
ConditionExpression:
|
|
493
|
+
opts?.ConditionExpression || 'attribute_exists(PK)',
|
|
494
|
+
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
495
|
+
ExpressionAttributeNames: {
|
|
496
|
+
...toUpdateExpressions.ExpressionAttributeNames,
|
|
497
|
+
...opts?.ExpressionAttributeNames,
|
|
498
|
+
},
|
|
499
|
+
ExpressionAttributeValues: {
|
|
500
|
+
...toUpdateExpressions.ExpressionAttributeValues,
|
|
501
|
+
...opts?.ExpressionAttributeValues,
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const TransactItems: TransactWriteItem[] = [
|
|
506
|
+
{
|
|
507
|
+
Update: {
|
|
508
|
+
TableName: this.TABLE_NAME,
|
|
509
|
+
Key: mutual.mainKeys(),
|
|
510
|
+
...updateExpression,
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
Update: {
|
|
515
|
+
TableName: this.TABLE_NAME,
|
|
516
|
+
Key: {
|
|
517
|
+
PK: { S: mutual.byFullEntityId },
|
|
518
|
+
SK: { S: mutual.fullEntityId },
|
|
519
|
+
},
|
|
520
|
+
...updateExpression,
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
Update: {
|
|
525
|
+
TableName: this.TABLE_NAME,
|
|
526
|
+
Key: {
|
|
527
|
+
PK: { S: mutual.fullEntityId },
|
|
528
|
+
SK: { S: mutual.byFullEntityId },
|
|
529
|
+
},
|
|
530
|
+
...updateExpression,
|
|
531
|
+
},
|
|
532
|
+
},
|
|
533
|
+
];
|
|
534
|
+
errorContext.TransactItems = TransactItems;
|
|
535
|
+
|
|
536
|
+
await this.ddbUtils.executeTransactWrite({ TransactItems });
|
|
537
|
+
|
|
538
|
+
if (!returnUpdatedValue) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const updatedMutual = await this.getMutual<B, T, M>(
|
|
543
|
+
byEntityType,
|
|
544
|
+
byEntityId,
|
|
545
|
+
entityType,
|
|
546
|
+
entityId,
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
return updatedMutual;
|
|
550
|
+
} catch (err) {
|
|
551
|
+
if (
|
|
552
|
+
err instanceof StandardError &&
|
|
553
|
+
err.code === 'CONDITIONAL_CHECK_FAILED'
|
|
554
|
+
) {
|
|
555
|
+
throw new StandardError('MUTUAL_NOT_FOUND', 'Mutual not found', err, {
|
|
556
|
+
errorContext,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
throw err;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async deleteMutual<
|
|
565
|
+
B extends Entity,
|
|
566
|
+
T extends Entity,
|
|
567
|
+
M extends Record<string, unknown>,
|
|
568
|
+
>(
|
|
569
|
+
byEntityType: B,
|
|
570
|
+
byEntityId: string,
|
|
571
|
+
entityType: T,
|
|
572
|
+
entityId: string,
|
|
573
|
+
opts?: {
|
|
574
|
+
ConditionExpression?: string;
|
|
575
|
+
ExpressionAttributeNames?: Record<string, string>;
|
|
576
|
+
ExpressionAttributeValues?: Record<string, AttributeValue>;
|
|
577
|
+
},
|
|
578
|
+
): Promise<Mutual<B, T, M>> {
|
|
579
|
+
const errorContext: Record<string, unknown> = {
|
|
580
|
+
byEntityType,
|
|
581
|
+
byEntityId,
|
|
582
|
+
entityType,
|
|
583
|
+
entityId,
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
try {
|
|
587
|
+
const mutual = await this.getMutual<B, T, M>(
|
|
588
|
+
byEntityType,
|
|
589
|
+
byEntityId,
|
|
590
|
+
entityType,
|
|
591
|
+
entityId,
|
|
592
|
+
{ ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA },
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
const tenMinsLater = Math.floor(new Date().getTime() / 1000 + 10 * 60);
|
|
596
|
+
const expressions = {
|
|
597
|
+
UpdateExpression:
|
|
598
|
+
'SET #expiresAt = :expiresAt, #mutualUpdatedAt = :mutualUpdatedAt, #updatedAt = :mutualUpdatedAt',
|
|
599
|
+
ConditionExpression:
|
|
600
|
+
opts?.ConditionExpression ||
|
|
601
|
+
'attribute_exists(PK) AND attribute_not_exists(#expiresAt)',
|
|
602
|
+
ExpressionAttributeNames: {
|
|
603
|
+
'#expiresAt': 'expiresAt',
|
|
604
|
+
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
605
|
+
'#updatedAt': 'updatedAt',
|
|
606
|
+
...opts?.ExpressionAttributeNames,
|
|
607
|
+
},
|
|
608
|
+
ExpressionAttributeValues: {
|
|
609
|
+
':expiresAt': { N: String(tenMinsLater) },
|
|
610
|
+
':mutualUpdatedAt': { S: new Date().toISOString() },
|
|
611
|
+
...opts?.ExpressionAttributeValues,
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
const TransactItems: TransactWriteItem[] = [
|
|
616
|
+
{
|
|
617
|
+
Update: {
|
|
618
|
+
TableName: this.TABLE_NAME,
|
|
619
|
+
Key: mutual.mainKeys(),
|
|
620
|
+
...expressions,
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
Update: {
|
|
625
|
+
TableName: this.TABLE_NAME,
|
|
626
|
+
Key: {
|
|
627
|
+
PK: { S: mutual.byFullEntityId },
|
|
628
|
+
SK: { S: mutual.fullEntityId },
|
|
629
|
+
},
|
|
630
|
+
...expressions,
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
Update: {
|
|
635
|
+
TableName: this.TABLE_NAME,
|
|
636
|
+
Key: {
|
|
637
|
+
PK: { S: mutual.fullEntityId },
|
|
638
|
+
SK: { S: mutual.byFullEntityId },
|
|
639
|
+
},
|
|
640
|
+
...expressions,
|
|
641
|
+
},
|
|
642
|
+
},
|
|
643
|
+
];
|
|
644
|
+
errorContext.TransactItems = TransactItems;
|
|
645
|
+
|
|
646
|
+
await this.dynamodbClient.transactWriteItems({ TransactItems });
|
|
647
|
+
|
|
648
|
+
return mutual;
|
|
649
|
+
} catch (err) {
|
|
650
|
+
const isConditionalCheckFailed =
|
|
651
|
+
err instanceof TransactionCanceledException &&
|
|
652
|
+
err.CancellationReasons?.some(
|
|
653
|
+
(reason) =>
|
|
654
|
+
reason.Code === BatchStatementErrorCodeEnum.ConditionalCheckFailed,
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
const isMutualIsUndefined =
|
|
658
|
+
err instanceof StandardError && err.code === 'MUTUAL_IS_UNDEFINED';
|
|
659
|
+
|
|
660
|
+
if (isConditionalCheckFailed || isMutualIsUndefined) {
|
|
661
|
+
throw new StandardError('MUTUAL_NOT_FOUND', 'Mutual not found', err, {
|
|
662
|
+
errorContext,
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
throw err;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async createMutualLock<B extends Entity, T extends Entity>({
|
|
671
|
+
byEntityType,
|
|
672
|
+
byEntityId,
|
|
673
|
+
entityType,
|
|
674
|
+
version,
|
|
675
|
+
}: {
|
|
676
|
+
byEntityType: B;
|
|
677
|
+
byEntityId: string;
|
|
678
|
+
entityType: T;
|
|
679
|
+
version: string;
|
|
680
|
+
}): Promise<void> {
|
|
681
|
+
let retryCount = 2;
|
|
682
|
+
|
|
683
|
+
const itemKey = {
|
|
684
|
+
PK: {
|
|
685
|
+
S: `MUTUAL#${byEntityType}#${byEntityId}#${entityType}`,
|
|
686
|
+
},
|
|
687
|
+
SK: { S: '#LOCK#' },
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
do {
|
|
691
|
+
try {
|
|
692
|
+
const fiveMinsLater = Math.floor(new Date().getTime() / 1000 + 5 * 60);
|
|
693
|
+
|
|
694
|
+
await this.dynamodbClient.putItem({
|
|
695
|
+
TableName: this.TABLE_NAME,
|
|
696
|
+
Item: {
|
|
697
|
+
...itemKey,
|
|
698
|
+
version: { S: version },
|
|
699
|
+
status: { S: 'LOCK' },
|
|
700
|
+
expiresAt: {
|
|
701
|
+
// auto release lock in case the mutual logic gone wrong to prevent dead lock
|
|
702
|
+
N: `${fiveMinsLater}`,
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
ConditionExpression:
|
|
706
|
+
'attribute_not_exists(PK) OR version < :version AND #status <> :status',
|
|
707
|
+
ExpressionAttributeNames: { '#status': 'status' },
|
|
708
|
+
ExpressionAttributeValues: {
|
|
709
|
+
':version': { S: version },
|
|
710
|
+
':status': { S: 'LOCK' },
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
return;
|
|
715
|
+
} catch (err) {
|
|
716
|
+
console.log('=====CATCHED_MUTUAL_LOCK_CONFLICT=====');
|
|
717
|
+
|
|
718
|
+
const lock = await this.dynamodbClient.getItem({
|
|
719
|
+
TableName: this.TABLE_NAME,
|
|
720
|
+
Key: itemKey,
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
// if version is lower, throw not retryable error to skip
|
|
724
|
+
const existingVersion = lock.Item?.version?.S ?? '';
|
|
725
|
+
const isExistingVersionGreaterThanNewVersion =
|
|
726
|
+
existingVersion >= version;
|
|
727
|
+
if (isExistingVersionGreaterThanNewVersion) {
|
|
728
|
+
throw new StandardError(
|
|
729
|
+
'MUTUAL_LOCK_CONFLICT',
|
|
730
|
+
'Lock conflict',
|
|
731
|
+
err,
|
|
732
|
+
{ lock: lock.Item },
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// default behaviour
|
|
737
|
+
// if version is higher, retry
|
|
738
|
+
// if lock not found, retry
|
|
739
|
+
|
|
740
|
+
await sleep(2000);
|
|
741
|
+
console.log('=====RETRY_MUTUAL_LOCK=====');
|
|
742
|
+
}
|
|
743
|
+
} while (retryCount-- > 0);
|
|
744
|
+
|
|
745
|
+
// catch real unhandled error, so it can reach DLQ for inspection
|
|
746
|
+
throw new StandardError(
|
|
747
|
+
'RETRYABLE_MUTUAL_LOCK_CONFLICT',
|
|
748
|
+
'Retryable lock conflict',
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
async deleteMutualLock<B extends Entity, T extends Entity>({
|
|
753
|
+
byEntityType,
|
|
754
|
+
byEntityId,
|
|
755
|
+
entityType,
|
|
756
|
+
}: {
|
|
757
|
+
byEntityType: B;
|
|
758
|
+
byEntityId: string;
|
|
759
|
+
entityType: T;
|
|
760
|
+
}): Promise<void> {
|
|
761
|
+
try {
|
|
762
|
+
await this.dynamodbClient.updateItem({
|
|
763
|
+
TableName: this.TABLE_NAME,
|
|
764
|
+
Key: {
|
|
765
|
+
PK: {
|
|
766
|
+
S: `MUTUAL#${byEntityType}#${byEntityId}#${entityType}`,
|
|
767
|
+
},
|
|
768
|
+
SK: { S: '#LOCK#' },
|
|
769
|
+
},
|
|
770
|
+
UpdateExpression: 'REMOVE #status',
|
|
771
|
+
ExpressionAttributeNames: { '#status': 'status' },
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
return;
|
|
775
|
+
} catch (error) {
|
|
776
|
+
// if lock is not found, it's okay
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|