@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monorise.js","sourceRoot":"","sources":["../../../../mock/monorise.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAyC,EAAE,CAAC;AAC9D,MAAM,kBAAkB,GAAa,EAAE,CAAC;AACxC,MAAM,wBAAwB,GAAa,EAAE,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-entity-processor.d.ts","sourceRoot":"","sources":["../../../../processors/create-entity-processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgBhE,eAAO,MAAM,OAAO,GAAU,IAAI,QAAQ;;EAmCzC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StandardError } from '#/errors/standard-error';
|
|
2
|
+
import { parseSQSBusEvent } from '#/helpers/event';
|
|
3
|
+
import { container } from '#/lambda-layer/container';
|
|
4
|
+
export const handler = async (ev) => {
|
|
5
|
+
const { entityService } = container;
|
|
6
|
+
const batchItemFailures = [];
|
|
7
|
+
for (const record of ev.Records) {
|
|
8
|
+
const errorContext = {};
|
|
9
|
+
const body = parseSQSBusEvent(record.body);
|
|
10
|
+
const { detail } = body;
|
|
11
|
+
const { entityType, entityId, entityPayload, accountId, options } = detail;
|
|
12
|
+
errorContext.body = body;
|
|
13
|
+
try {
|
|
14
|
+
await entityService.createEntity({
|
|
15
|
+
entityType,
|
|
16
|
+
entityId,
|
|
17
|
+
entityPayload,
|
|
18
|
+
accountId,
|
|
19
|
+
options,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.error('=====CREATE_ENTITY_PROCESSOR_ERROR=====', err, JSON.stringify({ errorContext }, null, 2));
|
|
24
|
+
if (err instanceof StandardError && err.code === 'INVALID_ENTITY_TYPE') {
|
|
25
|
+
continue; // do not retry
|
|
26
|
+
}
|
|
27
|
+
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { batchItemFailures };
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=create-entity-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-entity-processor.js","sourceRoot":"","sources":["../../../../processors/create-entity-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAarD,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,EAAY,EAAE,EAAE;IAC5C,MAAM,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IACpC,MAAM,iBAAiB,GAA0B,EAAE,CAAC;IAEpD,KAAK,MAAM,MAAM,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,YAAY,GAA4B,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,gBAAgB,CAAkB,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAC3E,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;QAEzB,IAAI,CAAC;YACH,MAAM,aAAa,CAAC,YAAY,CAAC;gBAC/B,UAAU;gBACV,QAAQ;gBACR,aAAa;gBACb,SAAS;gBACT,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CACX,yCAAyC,EACzC,GAAG,EACH,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAC1C,CAAC;YAEF,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBACvE,SAAS,CAAC,eAAe;YAC3B,CAAC;YAED,iBAAiB,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Entity } from '@monorise/base';
|
|
2
|
+
import type { SQSBatchItemFailure, SQSEvent } from 'aws-lambda';
|
|
3
|
+
export type EventDetailBody = {
|
|
4
|
+
mutualIds: string[];
|
|
5
|
+
byEntityType: Entity;
|
|
6
|
+
byEntityId: string;
|
|
7
|
+
entityType: Entity;
|
|
8
|
+
field: string;
|
|
9
|
+
publishedAt: string;
|
|
10
|
+
customContext?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export declare const handler: (ev: SQSEvent) => Promise<{
|
|
13
|
+
batchItemFailures: SQSBatchItemFailure[];
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=mutual-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutual-processor.d.ts","sourceRoot":"","sources":["../../../../processors/mutual-processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQhE,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,CAAC;AAOF,eAAO,MAAM,OAAO,GAAU,IAAI,QAAQ;;EA0OzC,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { TransactionCanceledException } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import { Mutual } from '#/data/Mutual';
|
|
3
|
+
import { StandardError } from '#/errors/standard-error';
|
|
4
|
+
import { parseSQSBusEvent } from '#/helpers/event';
|
|
5
|
+
import { container } from '#/lambda-layer/container';
|
|
6
|
+
import { EntityConfig } from '#/lambda-layer/monorise';
|
|
7
|
+
import { EVENT } from '#/shared/types/event';
|
|
8
|
+
const processEntities = async (entityIds, action) => Promise.allSettled(entityIds.map(action));
|
|
9
|
+
export const handler = async (ev) => {
|
|
10
|
+
const batchItemFailures = [];
|
|
11
|
+
const { entityRepository, mutualRepository, publishEvent } = container;
|
|
12
|
+
await Promise.allSettled(ev.Records.map(async (record) => {
|
|
13
|
+
const errorContext = {};
|
|
14
|
+
const body = parseSQSBusEvent(record.body);
|
|
15
|
+
const { detail } = body;
|
|
16
|
+
const { mutualIds, byEntityType, byEntityId, entityType, field, publishedAt, customContext, } = detail;
|
|
17
|
+
errorContext.body = body;
|
|
18
|
+
try {
|
|
19
|
+
// Validate if mutual configuration exists
|
|
20
|
+
const config = EntityConfig[byEntityType]?.mutual?.mutualFields?.[field];
|
|
21
|
+
if (!config) {
|
|
22
|
+
throw new StandardError('INVALID_MUTUAL', 'Invalid mutual');
|
|
23
|
+
}
|
|
24
|
+
const mutualDataProcessor = config.mutualDataProcessor ?? (() => ({}));
|
|
25
|
+
// Create a lock to prevent concurrent modifications
|
|
26
|
+
await mutualRepository.createMutualLock({
|
|
27
|
+
byEntityType,
|
|
28
|
+
byEntityId,
|
|
29
|
+
entityType,
|
|
30
|
+
version: publishedAt,
|
|
31
|
+
});
|
|
32
|
+
// Fetch related entities in parallel
|
|
33
|
+
const [byEntity, mutuals] = await Promise.all([
|
|
34
|
+
entityRepository.getEntity(byEntityType, byEntityId),
|
|
35
|
+
mutualRepository.listEntitiesByEntity(byEntityType, byEntityId, entityType),
|
|
36
|
+
]);
|
|
37
|
+
// Determine which entities were added, removed, or need updates
|
|
38
|
+
const existingEntityIds = new Set(mutuals.items.map((m) => m.entityId));
|
|
39
|
+
const newMutualIds = new Set(mutualIds ?? []);
|
|
40
|
+
const addedEntityIds = [...newMutualIds].filter((id) => !existingEntityIds.has(id));
|
|
41
|
+
const deletedEntityIds = [...existingEntityIds].filter((id) => !newMutualIds.has(id));
|
|
42
|
+
const toUpdateEntityIds = [...existingEntityIds].filter((id) => newMutualIds.has(id));
|
|
43
|
+
errorContext.existingEntityIds = [...existingEntityIds];
|
|
44
|
+
errorContext.addedEntityIds = addedEntityIds;
|
|
45
|
+
errorContext.deletedEntityIds = deletedEntityIds;
|
|
46
|
+
errorContext.toUpdateEntityIds = toUpdateEntityIds;
|
|
47
|
+
const addEntities = await processEntities(addedEntityIds, async (id) => {
|
|
48
|
+
const entity = await entityRepository.getEntity(entityType, id);
|
|
49
|
+
await mutualRepository.createMutual(byEntityType, byEntityId, byEntity.data, entityType, id, entity.data, mutualDataProcessor(mutualIds, new Mutual(byEntityType, byEntityId, byEntity.data, entityType, id, entity.data, {}), customContext), {
|
|
50
|
+
ConditionExpression: 'attribute_not_exists(#mutualUpdatedAt) OR #mutualUpdatedAt < :publishedAt',
|
|
51
|
+
ExpressionAttributeNames: {
|
|
52
|
+
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
53
|
+
},
|
|
54
|
+
ExpressionAttributeValues: {
|
|
55
|
+
':publishedAt': { S: publishedAt },
|
|
56
|
+
},
|
|
57
|
+
createAndUpdateDatetime: new Date(publishedAt),
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
const deleteEntities = await processEntities(deletedEntityIds, async (id) => {
|
|
61
|
+
await mutualRepository.deleteMutual(byEntityType, byEntityId, entityType, id, {
|
|
62
|
+
ConditionExpression: 'attribute_exists(PK) AND #mutualUpdatedAt < :publishedAt',
|
|
63
|
+
ExpressionAttributeNames: {
|
|
64
|
+
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
65
|
+
},
|
|
66
|
+
ExpressionAttributeValues: {
|
|
67
|
+
':publishedAt': { S: publishedAt },
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
const updateEntities = await processEntities(toUpdateEntityIds, async (id) => {
|
|
72
|
+
await mutualRepository.updateMutual(byEntityType, byEntityId, entityType, id, {
|
|
73
|
+
mutualData: mutualDataProcessor(mutualIds, new Mutual(byEntityType, byEntityId, byEntity.data, entityType, id, {}, {}), customContext),
|
|
74
|
+
mutualUpdatedAt: publishedAt,
|
|
75
|
+
}, {
|
|
76
|
+
ConditionExpression: 'attribute_exists(PK) AND #mutualUpdatedAt < :publishedAt',
|
|
77
|
+
ExpressionAttributeNames: {
|
|
78
|
+
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
79
|
+
},
|
|
80
|
+
ExpressionAttributeValues: {
|
|
81
|
+
':publishedAt': { S: publishedAt },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
errorContext.results = { addEntities, deleteEntities, updateEntities };
|
|
86
|
+
// release lock
|
|
87
|
+
await mutualRepository.deleteMutualLock({
|
|
88
|
+
byEntityType,
|
|
89
|
+
byEntityId,
|
|
90
|
+
entityType,
|
|
91
|
+
});
|
|
92
|
+
// Check for unprocessable errors in processing results
|
|
93
|
+
if ([...addEntities, ...deleteEntities, ...updateEntities].some((res) => res.status === 'rejected' &&
|
|
94
|
+
!(res.reason instanceof TransactionCanceledException ||
|
|
95
|
+
(res.reason instanceof StandardError &&
|
|
96
|
+
res.reason.code === 'MUTUAL_NOT_FOUND')))) {
|
|
97
|
+
throw new StandardError('MUTUAL_PROCESSOR_ERROR', 'Mutual processor error', null, errorContext);
|
|
98
|
+
}
|
|
99
|
+
await publishEvent({
|
|
100
|
+
event: EVENT.CORE.ENTITY_MUTUAL_PROCESSED,
|
|
101
|
+
payload: {
|
|
102
|
+
byEntityType,
|
|
103
|
+
byEntityId,
|
|
104
|
+
entityType,
|
|
105
|
+
field,
|
|
106
|
+
mutualIds,
|
|
107
|
+
publishedAt,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error('=====MUTUAL_PROCESSOR_ERROR=====', err, JSON.stringify({ errorContext }, null, 2));
|
|
113
|
+
// Release the lock to avoid deadlocks
|
|
114
|
+
await mutualRepository.deleteMutualLock({
|
|
115
|
+
byEntityType,
|
|
116
|
+
byEntityId,
|
|
117
|
+
entityType,
|
|
118
|
+
});
|
|
119
|
+
if (err instanceof StandardError &&
|
|
120
|
+
['INVALID_MUTUAL', 'MUTUAL_LOCK_CONFLICT'].includes(err.code)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
return { batchItemFailures };
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=mutual-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutual-processor.js","sourceRoot":"","sources":["../../../../processors/mutual-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAGxE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAY7C,MAAM,eAAe,GAAG,KAAK,EAC3B,SAAmB,EACnB,MAAqC,EACrC,EAAE,CA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,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAC1C,CAAC;YAEF,sCAAsC;YACtC,MAAM,gBAAgB,CAAC,gBAAgB,CAAC;gBACtC,YAAY;gBACZ,UAAU;gBACV,UAAU;aACX,CAAC,CAAC;YAEH,IACE,GAAG,YAAY,aAAa;gBAC5B,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAC7D,CAAC;gBACD,OAAO;YACT,CAAC;YAED,iBAAiB,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Entity } from '@monorise/base';
|
|
2
|
+
import type { SQSBatchItemFailure, SQSEvent } from 'aws-lambda';
|
|
3
|
+
export type EventDetailBody = {
|
|
4
|
+
byEntityType: Entity;
|
|
5
|
+
byEntityId: string;
|
|
6
|
+
entityType: Entity;
|
|
7
|
+
publishedAt: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const handler: (ev: SQSEvent) => Promise<{
|
|
10
|
+
batchItemFailures: SQSBatchItemFailure[];
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=prejoin-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prejoin-processor.d.ts","sourceRoot":"","sources":["../../../../processors/prejoin-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAWhE,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAyLF,eAAO,MAAM,OAAO,GAAU,IAAI,QAAQ;;EA2DzC,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { PROJECTION_EXPRESSION } from '#/data/ProjectionExpression';
|
|
2
|
+
import { parseSQSBusEvent } from '#/helpers/event';
|
|
3
|
+
import { container } from '#/lambda-layer/container';
|
|
4
|
+
import { AllowedEntityTypes, EntityConfig } from '#/lambda-layer/monorise';
|
|
5
|
+
import { EVENT } from '#/shared/types/event';
|
|
6
|
+
async function processPrejoins({ mutualRepository, publishEvent, byEntityType, byEntityId, prejoins, publishedAt, }) {
|
|
7
|
+
const mutualCache = {
|
|
8
|
+
/*
|
|
9
|
+
course: [{
|
|
10
|
+
byEntityType: 'module',
|
|
11
|
+
byEntityId: '1',
|
|
12
|
+
entityType: 'course',
|
|
13
|
+
entityId: '1',
|
|
14
|
+
}],
|
|
15
|
+
module: [],
|
|
16
|
+
chapter: [],
|
|
17
|
+
video: []
|
|
18
|
+
*/
|
|
19
|
+
};
|
|
20
|
+
//initiate
|
|
21
|
+
mutualCache[byEntityType] = [
|
|
22
|
+
{
|
|
23
|
+
entityType: byEntityType,
|
|
24
|
+
entityId: byEntityId,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
for (const { mutualField, targetEntityType, entityPaths } of prejoins) {
|
|
28
|
+
let toBePublishedContext = {};
|
|
29
|
+
for (const [index, entityPath] of entityPaths.entries()) {
|
|
30
|
+
const entityType = entityPath.entityType;
|
|
31
|
+
// skip cached
|
|
32
|
+
if (!entityPath.skipCache && mutualCache[entityType]) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// if skipping cache should not have previous run data
|
|
36
|
+
mutualCache[entityType] = [];
|
|
37
|
+
const parentEntityType = entityPaths[index - 1]
|
|
38
|
+
.entityType;
|
|
39
|
+
const parentEntities = mutualCache[parentEntityType] ?? [];
|
|
40
|
+
// find all nested entities
|
|
41
|
+
for (const parentEntity of parentEntities) {
|
|
42
|
+
const { entityType: parentEntityType, entityId: parentEntityId } = parentEntity;
|
|
43
|
+
const { items: mutualItems } = await mutualRepository.listEntitiesByEntity(parentEntityType, parentEntityId, entityPath.entityType, {
|
|
44
|
+
ProjectionExpression: PROJECTION_EXPRESSION.MUTUAL_DATA_ONLY,
|
|
45
|
+
});
|
|
46
|
+
// custom processor defined in prejoin config for each path
|
|
47
|
+
const processor = entityPath.processor || ((items, context) => ({ items, context }));
|
|
48
|
+
const processed = processor(mutualItems, toBePublishedContext);
|
|
49
|
+
toBePublishedContext = processed?.context || toBePublishedContext;
|
|
50
|
+
mutualCache[entityType] = [
|
|
51
|
+
...(mutualCache[entityType] ?? []),
|
|
52
|
+
...(processed ? processed.items : mutualItems),
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
if (!mutualCache[entityType] && !Array.isArray(mutualCache[entityType])) {
|
|
56
|
+
// to avoid empty array
|
|
57
|
+
mutualCache[entityType] = [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const mutualIds = (mutualCache[targetEntityType] ?? []).map((item) => item.entityId);
|
|
61
|
+
await publishEvent({
|
|
62
|
+
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
63
|
+
payload: {
|
|
64
|
+
byEntityType,
|
|
65
|
+
byEntityId,
|
|
66
|
+
entityType: targetEntityType,
|
|
67
|
+
field: mutualField,
|
|
68
|
+
mutualIds,
|
|
69
|
+
customContext: toBePublishedContext,
|
|
70
|
+
publishedAt,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function publishToSubscribers({ mutualRepository, publishEvent, byEntityType, byEntityId, publishedAt, }) {
|
|
76
|
+
const listeners = AllowedEntityTypes.reduce((acc, configKey) => {
|
|
77
|
+
const { subscribes } = EntityConfig[configKey].mutual ?? {};
|
|
78
|
+
const hasSubscription = (subscribes ?? []).some(({ entityType }) => entityType === byEntityType);
|
|
79
|
+
return [
|
|
80
|
+
...acc,
|
|
81
|
+
...(hasSubscription
|
|
82
|
+
? [
|
|
83
|
+
{
|
|
84
|
+
entityType: configKey,
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
: []),
|
|
88
|
+
];
|
|
89
|
+
}, []);
|
|
90
|
+
// publish event for each interested entity
|
|
91
|
+
const subscribedMutualItems = await Promise.all(listeners.map(({ entityType: subscribedEntityType }) => mutualRepository.listEntitiesByEntity(byEntityType, byEntityId, subscribedEntityType, {
|
|
92
|
+
ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA,
|
|
93
|
+
})));
|
|
94
|
+
const subscribedMutuals = subscribedMutualItems.flatMap((item) => item.items);
|
|
95
|
+
await Promise.all(subscribedMutuals.map((subscribedMutual) => publishEvent({
|
|
96
|
+
event: EVENT.CORE.PREJOIN_RELATIONSHIP_SYNC,
|
|
97
|
+
payload: {
|
|
98
|
+
byEntityType: subscribedMutual.entityType,
|
|
99
|
+
byEntityId: subscribedMutual.entityId,
|
|
100
|
+
entityType: subscribedMutual.byEntityType,
|
|
101
|
+
publishedAt,
|
|
102
|
+
},
|
|
103
|
+
})));
|
|
104
|
+
}
|
|
105
|
+
export const handler = async (ev) => {
|
|
106
|
+
const batchItemFailures = [];
|
|
107
|
+
const { mutualRepository, publishEvent } = container;
|
|
108
|
+
for (const record of ev.Records) {
|
|
109
|
+
const body = parseSQSBusEvent(record.body);
|
|
110
|
+
const { detail } = body;
|
|
111
|
+
const { byEntityType, byEntityId, entityType, publishedAt } = detail;
|
|
112
|
+
let errorContext = {
|
|
113
|
+
body,
|
|
114
|
+
};
|
|
115
|
+
try {
|
|
116
|
+
const isEntityTypeSubscribed = (EntityConfig[byEntityType]?.mutual?.subscribes ?? []).some(({ entityType: subscribedEntityType }) => subscribedEntityType === entityType);
|
|
117
|
+
const hasPrejoins = EntityConfig[byEntityType]?.mutual?.prejoins;
|
|
118
|
+
const shouldProcessPrejoins = isEntityTypeSubscribed && hasPrejoins;
|
|
119
|
+
errorContext = {
|
|
120
|
+
...errorContext,
|
|
121
|
+
isEntityTypeSubscribed,
|
|
122
|
+
hasPrejoins,
|
|
123
|
+
shouldProcessPrejoins,
|
|
124
|
+
};
|
|
125
|
+
if (shouldProcessPrejoins) {
|
|
126
|
+
await processPrejoins({
|
|
127
|
+
mutualRepository,
|
|
128
|
+
publishEvent,
|
|
129
|
+
byEntityType,
|
|
130
|
+
byEntityId,
|
|
131
|
+
prejoins: EntityConfig[byEntityType]?.mutual?.prejoins ?? [],
|
|
132
|
+
publishedAt,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
await publishToSubscribers({
|
|
136
|
+
mutualRepository,
|
|
137
|
+
publishEvent,
|
|
138
|
+
byEntityType,
|
|
139
|
+
byEntityId,
|
|
140
|
+
publishedAt,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
console.log('===PREJOIN-PROCESSOR ERROR===', err, JSON.stringify({ errorContext }, null, 2));
|
|
145
|
+
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { batchItemFailures };
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=prejoin-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prejoin-processor.js","sourceRoot":"","sources":["../../../../processors/prejoin-processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAU7C,KAAK,UAAU,eAAe,CA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gBAChB,YAAY;gBACZ,YAAY;gBACZ,UAAU;gBACV,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CACT,+BAA+B,EAC/B,GAAG,EACH,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAC1C,CAAC;YAEF,iBAAiB,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { _Record as DynamoDBStreamEvent } from '@aws-sdk/client-dynamodb-streams';
|
|
2
|
+
import type { DynamoDBBatchItemFailure } from 'aws-lambda';
|
|
3
|
+
export declare const handler: (event: {
|
|
4
|
+
Records: DynamoDBStreamEvent[];
|
|
5
|
+
}) => Promise<{
|
|
6
|
+
batchItemFailures: DynamoDBBatchItemFailure[];
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=replication-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replication-processor.d.ts","sourceRoot":"","sources":["../../../../processors/replication-processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,OAAO,IAAI,mBAAmB,EAC/B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAU3D,eAAO,MAAM,OAAO,GAAU,OAAO;IAAE,OAAO,EAAE,mBAAmB,EAAE,CAAA;CAAE;;EAoPtE,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import { ENTITY_REPLICATION_INDEX, MUTUAL_REPLICATION_INDEX, } from '#/configs/service.config';
|
|
3
|
+
import { StandardError } from '#/errors/standard-error';
|
|
4
|
+
import { container } from '#/lambda-layer/container';
|
|
5
|
+
const TableName = process.env.DDB_TABLE;
|
|
6
|
+
export const handler = async (event) => {
|
|
7
|
+
const batchItemFailures = [];
|
|
8
|
+
const { dynamodbClient } = container;
|
|
9
|
+
for (const record of event.Records) {
|
|
10
|
+
const errorContext = {};
|
|
11
|
+
errorContext.record = record;
|
|
12
|
+
try {
|
|
13
|
+
if (record.eventName === 'MODIFY') {
|
|
14
|
+
const modifiedItem = record.dynamodb?.NewImage;
|
|
15
|
+
if (!modifiedItem) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const isMetadata = modifiedItem.SK.S?.startsWith('#METADATA#');
|
|
19
|
+
const isMutual = modifiedItem.PK.S?.startsWith('MUTUAL#') && isMetadata;
|
|
20
|
+
const isEntity = isMetadata && !isMutual;
|
|
21
|
+
if (!isEntity && !isMutual) {
|
|
22
|
+
// skip replicated data
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// default variables
|
|
26
|
+
let targetRPK = 'R1PK';
|
|
27
|
+
const targetData = 'data';
|
|
28
|
+
let targetIndexName = ENTITY_REPLICATION_INDEX;
|
|
29
|
+
const targetUpdatedAt = 'updatedAt';
|
|
30
|
+
let queryExpression = {
|
|
31
|
+
FilterExpression: `#${targetUpdatedAt} < :${targetUpdatedAt}`,
|
|
32
|
+
ExpressionAttributeNames: {
|
|
33
|
+
[`#${targetRPK}`]: targetRPK,
|
|
34
|
+
[`#${targetUpdatedAt}`]: targetUpdatedAt,
|
|
35
|
+
},
|
|
36
|
+
ExpressionAttributeValues: {
|
|
37
|
+
[`:${targetRPK}`]: modifiedItem.PK,
|
|
38
|
+
[`:${targetUpdatedAt}`]: modifiedItem.updatedAt,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const updateExpession = {
|
|
42
|
+
UpdateExpression: `SET #${targetUpdatedAt} = :${targetUpdatedAt}, #${targetData} = :${targetData}`,
|
|
43
|
+
ConditionExpression: `#${targetUpdatedAt} < :${targetUpdatedAt}`,
|
|
44
|
+
ExpressionAttributeNames: {
|
|
45
|
+
[`#${targetData}`]: targetData,
|
|
46
|
+
[`#${targetUpdatedAt}`]: targetUpdatedAt,
|
|
47
|
+
},
|
|
48
|
+
ExpressionAttributeValues: {
|
|
49
|
+
[`:${targetData}`]: modifiedItem.data,
|
|
50
|
+
[`:${targetUpdatedAt}`]: modifiedItem.updatedAt,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
if (isMutual) {
|
|
54
|
+
targetRPK = 'R2PK';
|
|
55
|
+
targetIndexName = MUTUAL_REPLICATION_INDEX;
|
|
56
|
+
// condition to only replicate to mutualAsEntity
|
|
57
|
+
queryExpression = {
|
|
58
|
+
FilterExpression: `${queryExpression.FilterExpression} AND #SK = :metadata`, // to replicate to mutualAsEntity only
|
|
59
|
+
ExpressionAttributeNames: {
|
|
60
|
+
'#SK': 'SK',
|
|
61
|
+
[`#${targetRPK}`]: targetRPK,
|
|
62
|
+
[`#${targetUpdatedAt}`]: targetUpdatedAt,
|
|
63
|
+
},
|
|
64
|
+
ExpressionAttributeValues: {
|
|
65
|
+
':metadata': { S: '#METADATA#' },
|
|
66
|
+
[`:${targetRPK}`]: modifiedItem.PK,
|
|
67
|
+
[`:${targetUpdatedAt}`]: modifiedItem.mutualUpdatedAt,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
updateExpession.ExpressionAttributeValues = {
|
|
71
|
+
[`:${targetData}`]: modifiedItem.mutualData,
|
|
72
|
+
[`:${targetUpdatedAt}`]: modifiedItem.mutualUpdatedAt,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
errorContext.queryExpression = queryExpression;
|
|
76
|
+
errorContext.updateExpession = updateExpession;
|
|
77
|
+
// retrieve all to be replicated items
|
|
78
|
+
let toBeReplicatedItems = [];
|
|
79
|
+
let lastKey;
|
|
80
|
+
do {
|
|
81
|
+
const queryResult = await dynamodbClient.query({
|
|
82
|
+
TableName,
|
|
83
|
+
IndexName: targetIndexName,
|
|
84
|
+
KeyConditionExpression: `#${targetRPK} = :${targetRPK}`,
|
|
85
|
+
...queryExpression,
|
|
86
|
+
});
|
|
87
|
+
toBeReplicatedItems = [
|
|
88
|
+
...toBeReplicatedItems,
|
|
89
|
+
...(queryResult.Items || []),
|
|
90
|
+
];
|
|
91
|
+
lastKey = queryResult.LastEvaluatedKey;
|
|
92
|
+
} while (lastKey);
|
|
93
|
+
errorContext.toBeReplicatedItems = toBeReplicatedItems;
|
|
94
|
+
const updatePromises = toBeReplicatedItems.map((item) => {
|
|
95
|
+
const updateParams = {
|
|
96
|
+
TableName,
|
|
97
|
+
Key: {
|
|
98
|
+
PK: item.PK,
|
|
99
|
+
SK: item.SK,
|
|
100
|
+
},
|
|
101
|
+
...updateExpession,
|
|
102
|
+
};
|
|
103
|
+
return dynamodbClient.updateItem(updateParams);
|
|
104
|
+
});
|
|
105
|
+
const results = await Promise.allSettled(updatePromises);
|
|
106
|
+
errorContext.results = results;
|
|
107
|
+
if (results.some((result) => result.status === 'rejected' &&
|
|
108
|
+
!(result.reason instanceof ConditionalCheckFailedException))) {
|
|
109
|
+
throw new StandardError('REPLICATION_ERROR', 'Replication error', null, errorContext);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (record.eventName === 'REMOVE') {
|
|
113
|
+
const removedKeys = record.dynamodb?.Keys || {};
|
|
114
|
+
const isMetadata = removedKeys.SK.S?.startsWith('#METADATA#');
|
|
115
|
+
const isMutual = removedKeys.PK.S?.startsWith('MUTUAL#') && isMetadata;
|
|
116
|
+
const isEntity = isMetadata && !isMutual;
|
|
117
|
+
if (!isEntity && !isMutual) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
// default query settings
|
|
121
|
+
let targetRPK = 'R1PK';
|
|
122
|
+
let targetIndexName = ENTITY_REPLICATION_INDEX;
|
|
123
|
+
if (isMutual) {
|
|
124
|
+
targetRPK = 'R2PK';
|
|
125
|
+
targetIndexName = MUTUAL_REPLICATION_INDEX;
|
|
126
|
+
}
|
|
127
|
+
let itemsToDelete = [];
|
|
128
|
+
let lastKey;
|
|
129
|
+
do {
|
|
130
|
+
const queryResult = await dynamodbClient.query({
|
|
131
|
+
TableName,
|
|
132
|
+
IndexName: targetIndexName,
|
|
133
|
+
KeyConditionExpression: `#${targetRPK} = :${targetRPK}`,
|
|
134
|
+
ExpressionAttributeNames: {
|
|
135
|
+
[`#${targetRPK}`]: targetRPK,
|
|
136
|
+
},
|
|
137
|
+
ExpressionAttributeValues: {
|
|
138
|
+
[`:${targetRPK}`]: removedKeys.PK,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
itemsToDelete = [...itemsToDelete, ...(queryResult.Items || [])];
|
|
142
|
+
lastKey = queryResult.LastEvaluatedKey;
|
|
143
|
+
} while (lastKey);
|
|
144
|
+
const mutualsToDelete = Array.from(new Set(itemsToDelete
|
|
145
|
+
.filter((item) => item.R2PK?.S?.startsWith('MUTUAL#'))
|
|
146
|
+
.map((filteredItem) => filteredItem.R2PK?.S)));
|
|
147
|
+
mutualsToDelete.forEach((mutual) => {
|
|
148
|
+
if (!mutual) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
itemsToDelete.push({ PK: { S: mutual }, SK: { S: '#METADATA#' } });
|
|
152
|
+
});
|
|
153
|
+
const deleteResults = await Promise.allSettled(itemsToDelete.map((item) => dynamodbClient.deleteItem({
|
|
154
|
+
TableName,
|
|
155
|
+
Key: {
|
|
156
|
+
PK: item.PK,
|
|
157
|
+
SK: item.SK,
|
|
158
|
+
},
|
|
159
|
+
})));
|
|
160
|
+
errorContext.deleteResults = deleteResults;
|
|
161
|
+
if (deleteResults.some((result) => result.status === 'rejected' &&
|
|
162
|
+
!(result.reason instanceof ConditionalCheckFailedException))) {
|
|
163
|
+
throw new StandardError('REPLICATION_ERROR', 'Replication error', null, errorContext);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error('====REPLICATION_ERROR', error);
|
|
169
|
+
console.log('====REPLICATION_ERROR errorContext', JSON.stringify(errorContext, null, 2));
|
|
170
|
+
batchItemFailures.push({
|
|
171
|
+
itemIdentifier: record.dynamodb?.SequenceNumber || '',
|
|
172
|
+
});
|
|
173
|
+
// immediately return to prevent processing the rest
|
|
174
|
+
// because stream will restart from this point again
|
|
175
|
+
return { batchItemFailures };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { batchItemFailures };
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=replication-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replication-processor.js","sourceRoot":"","sources":["../../../../processors/replication-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAM3E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AAExC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAyC,EAAE,EAAE;IACzE,MAAM,iBAAiB,GAA+B,EAAE,CAAC;IACzD,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACnC,MAAM,YAAY,GAAQ,EAAE,CAAC;QAC7B,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC;QAE7B,IAAI,CAAC;YACH,IAAI,MAAM,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;gBAClC,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAA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;YAEF,iBAAiB,CAAC,IAAI,CAAC;gBACrB,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,IAAI,EAAE;aACtD,CAAC,CAAC;YAEH,oDAAoD;YACpD,oDAAoD;YACpD,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Entity as EntityType } from '@monorise/base';
|
|
2
|
+
import type { SQSBatchItemFailure, SQSEvent } from 'aws-lambda';
|
|
3
|
+
export type EventDetailBody = {
|
|
4
|
+
entityType: EntityType;
|
|
5
|
+
entityId: string;
|
|
6
|
+
data: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export declare const handler: (ev: SQSEvent) => Promise<{
|
|
9
|
+
batchItemFailures: SQSBatchItemFailure[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=tag-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-processor.d.ts","sourceRoot":"","sources":["../../../../processors/tag-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,MAAM,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAOhE,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,CAAC;AAwFF,eAAO,MAAM,OAAO,GAAU,IAAI,QAAQ;;EAuEzC,CAAC"}
|