@monorise/core 1.0.4-7 → 3.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/dist/constants/table.d.ts +0 -1
- package/dist/constants/table.d.ts.map +1 -1
- package/dist/constants/table.js +0 -1
- package/dist/constants/table.js.map +1 -1
- package/dist/controllers/entity/create-entity.controller.d.ts +1 -2
- package/dist/controllers/entity/create-entity.controller.d.ts.map +1 -1
- package/dist/controllers/entity/create-entity.controller.js +54 -34
- package/dist/controllers/entity/create-entity.controller.js.map +1 -1
- package/dist/controllers/entity/delete-entity.controller.d.ts +1 -2
- package/dist/controllers/entity/delete-entity.controller.d.ts.map +1 -1
- package/dist/controllers/entity/delete-entity.controller.js +30 -21
- package/dist/controllers/entity/delete-entity.controller.js.map +1 -1
- package/dist/controllers/entity/get-entity-by-unique-field-value.controller.d.ts +7 -0
- package/dist/controllers/entity/get-entity-by-unique-field-value.controller.d.ts.map +1 -0
- package/dist/controllers/entity/get-entity-by-unique-field-value.controller.js +36 -0
- package/dist/controllers/entity/get-entity-by-unique-field-value.controller.js.map +1 -0
- package/dist/controllers/entity/get-entity.controller.d.ts +1 -2
- package/dist/controllers/entity/get-entity.controller.d.ts.map +1 -1
- package/dist/controllers/entity/get-entity.controller.js +30 -17
- package/dist/controllers/entity/get-entity.controller.js.map +1 -1
- package/dist/controllers/entity/list-entities.controller.d.ts +1 -2
- package/dist/controllers/entity/list-entities.controller.d.ts.map +1 -1
- package/dist/controllers/entity/list-entities.controller.js +44 -39
- package/dist/controllers/entity/list-entities.controller.js.map +1 -1
- package/dist/controllers/entity/update-entity.controller.d.ts +1 -2
- package/dist/controllers/entity/update-entity.controller.d.ts.map +1 -1
- package/dist/controllers/entity/update-entity.controller.js +52 -35
- package/dist/controllers/entity/update-entity.controller.js.map +1 -1
- package/dist/controllers/entity/upsert-entity.controller.d.ts +3 -3
- package/dist/controllers/entity/upsert-entity.controller.d.ts.map +1 -1
- package/dist/controllers/entity/upsert-entity.controller.js +70 -60
- package/dist/controllers/entity/upsert-entity.controller.js.map +1 -1
- package/dist/controllers/mutual/create-mutual.controller.d.ts +2 -4
- package/dist/controllers/mutual/create-mutual.controller.d.ts.map +1 -1
- package/dist/controllers/mutual/create-mutual.controller.js +51 -45
- package/dist/controllers/mutual/create-mutual.controller.js.map +1 -1
- package/dist/controllers/mutual/delete-mutual.controller.d.ts +1 -2
- package/dist/controllers/mutual/delete-mutual.controller.d.ts.map +1 -1
- package/dist/controllers/mutual/delete-mutual.controller.js +32 -23
- package/dist/controllers/mutual/delete-mutual.controller.js.map +1 -1
- package/dist/controllers/mutual/get-mutual.controller.d.ts +1 -2
- package/dist/controllers/mutual/get-mutual.controller.d.ts.map +1 -1
- package/dist/controllers/mutual/get-mutual.controller.js +29 -17
- package/dist/controllers/mutual/get-mutual.controller.js.map +1 -1
- package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts +1 -2
- package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts.map +1 -1
- package/dist/controllers/mutual/list-entities-by-entity.controller.js +60 -44
- package/dist/controllers/mutual/list-entities-by-entity.controller.js.map +1 -1
- package/dist/controllers/mutual/update-mutual.controller.d.ts +1 -2
- package/dist/controllers/mutual/update-mutual.controller.d.ts.map +1 -1
- package/dist/controllers/mutual/update-mutual.controller.js +44 -30
- package/dist/controllers/mutual/update-mutual.controller.js.map +1 -1
- package/dist/controllers/setupRoutes.d.ts +2 -3
- package/dist/controllers/setupRoutes.d.ts.map +1 -1
- package/dist/controllers/setupRoutes.js +19 -17
- package/dist/controllers/setupRoutes.js.map +1 -1
- package/dist/controllers/tag/list-tags.controller.d.ts +1 -2
- package/dist/controllers/tag/list-tags.controller.d.ts.map +1 -1
- package/dist/controllers/tag/list-tags.controller.js +42 -33
- package/dist/controllers/tag/list-tags.controller.js.map +1 -1
- package/dist/data/DbUtils.js +24 -13
- package/dist/data/DbUtils.js.map +1 -1
- package/dist/data/Entity.d.ts +14 -10
- package/dist/data/Entity.d.ts.map +1 -1
- package/dist/data/Entity.js +370 -227
- package/dist/data/Entity.js.map +1 -1
- package/dist/data/EventUtils.d.ts +3 -3
- package/dist/data/EventUtils.d.ts.map +1 -1
- package/dist/data/EventUtils.js +35 -27
- package/dist/data/EventUtils.js.map +1 -1
- package/dist/data/Mutual.d.ts +7 -8
- package/dist/data/Mutual.d.ts.map +1 -1
- package/dist/data/Mutual.js +288 -341
- package/dist/data/Mutual.js.map +1 -1
- package/dist/data/Tag.d.ts +2 -2
- package/dist/data/Tag.d.ts.map +1 -1
- package/dist/data/Tag.js +229 -230
- package/dist/data/Tag.js.map +1 -1
- package/dist/data/abstract/Repository.base.js +4 -7
- package/dist/data/abstract/Repository.base.js.map +1 -1
- package/dist/errors/extendable-error.js +0 -7
- package/dist/errors/extendable-error.js.map +1 -1
- package/dist/errors/standard-error.d.ts +22 -0
- package/dist/errors/standard-error.d.ts.map +1 -1
- package/dist/errors/standard-error.js +21 -3
- package/dist/errors/standard-error.js.map +1 -1
- package/dist/handles/app.d.ts +16 -0
- package/dist/handles/app.d.ts.map +1 -0
- package/dist/handles/app.js +31 -0
- package/dist/handles/app.js.map +1 -0
- package/dist/helpers/event.d.ts.map +1 -1
- package/dist/helpers/event.js +35 -34
- package/dist/helpers/event.js.map +1 -1
- package/dist/index.d.ts +24 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -21
- package/dist/index.js.map +1 -1
- package/dist/middlewares/api-key-auth.d.ts +3 -0
- package/dist/middlewares/api-key-auth.d.ts.map +1 -0
- package/dist/middlewares/api-key-auth.js +32 -0
- package/dist/middlewares/api-key-auth.js.map +1 -0
- package/dist/middlewares/entity-type-check.d.ts +1 -1
- package/dist/middlewares/entity-type-check.d.ts.map +1 -1
- package/dist/middlewares/entity-type-check.js +17 -7
- package/dist/middlewares/entity-type-check.js.map +1 -1
- package/dist/middlewares/general-error-handler.d.ts +7 -0
- package/dist/middlewares/general-error-handler.d.ts.map +1 -0
- package/dist/middlewares/general-error-handler.js +40 -0
- package/dist/middlewares/general-error-handler.js.map +1 -0
- package/dist/middlewares/mutual-type-check.d.ts +1 -1
- package/dist/middlewares/mutual-type-check.d.ts.map +1 -1
- package/dist/middlewares/mutual-type-check.js +18 -8
- package/dist/middlewares/mutual-type-check.js.map +1 -1
- package/dist/processors/create-entity-processor.d.ts.map +1 -1
- package/dist/processors/create-entity-processor.js +17 -5
- package/dist/processors/create-entity-processor.js.map +1 -1
- package/dist/processors/mutual-processor.d.ts.map +1 -1
- package/dist/processors/mutual-processor.js +39 -29
- package/dist/processors/mutual-processor.js.map +1 -1
- package/dist/processors/prejoin-processor.d.ts.map +1 -1
- package/dist/processors/prejoin-processor.js +117 -104
- package/dist/processors/prejoin-processor.js.map +1 -1
- package/dist/processors/replication-processor.d.ts.map +1 -1
- package/dist/processors/replication-processor.js +31 -31
- package/dist/processors/replication-processor.js.map +1 -1
- package/dist/processors/tag-processor.js +48 -35
- package/dist/processors/tag-processor.js.map +1 -1
- package/dist/services/DependencyContainer.d.ts +16 -7
- package/dist/services/DependencyContainer.d.ts.map +1 -1
- package/dist/services/DependencyContainer.js +13 -24
- package/dist/services/DependencyContainer.js.map +1 -1
- package/dist/services/entity-service-lifecycle.js +29 -20
- package/dist/services/entity-service-lifecycle.js.map +1 -1
- package/dist/services/entity.service.d.ts +6 -6
- package/dist/services/entity.service.d.ts.map +1 -1
- package/dist/services/entity.service.js +96 -93
- package/dist/services/entity.service.js.map +1 -1
- package/dist/services/mutual.service.js +117 -113
- package/dist/services/mutual.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/entity.type.d.ts.map +1 -1
- package/dist/types/event.d.ts +4 -3
- package/dist/types/event.d.ts.map +1 -1
- package/dist/types/event.js +9 -9
- package/dist/types/event.js.map +1 -1
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +10 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +8 -6
- package/dist/mock/entity.d.ts +0 -13
- package/dist/mock/entity.d.ts.map +0 -1
- package/dist/mock/entity.js +0 -14
- package/dist/mock/entity.js.map +0 -1
- package/dist/mock/monorise/admin.d.ts +0 -127
- package/dist/mock/monorise/admin.d.ts.map +0 -1
- package/dist/mock/monorise/admin.js +0 -29
- package/dist/mock/monorise/admin.js.map +0 -1
- package/dist/mock/monorise/chapter.d.ts +0 -457
- package/dist/mock/monorise/chapter.d.ts.map +0 -1
- package/dist/mock/monorise/chapter.js +0 -81
- package/dist/mock/monorise/chapter.js.map +0 -1
- package/dist/mock/monorise/course.d.ts +0 -311
- package/dist/mock/monorise/course.d.ts.map +0 -1
- package/dist/mock/monorise/course.js +0 -128
- package/dist/mock/monorise/course.js.map +0 -1
- package/dist/mock/monorise/index.d.ts +0 -3599
- package/dist/mock/monorise/index.d.ts.map +0 -1
- package/dist/mock/monorise/index.js +0 -62
- package/dist/mock/monorise/index.js.map +0 -1
- package/dist/mock/monorise/learner.d.ts +0 -390
- package/dist/mock/monorise/learner.d.ts.map +0 -1
- package/dist/mock/monorise/learner.js +0 -59
- package/dist/mock/monorise/learner.js.map +0 -1
- package/dist/mock/monorise/learning-activity.d.ts +0 -266
- package/dist/mock/monorise/learning-activity.d.ts.map +0 -1
- package/dist/mock/monorise/learning-activity.js +0 -50
- package/dist/mock/monorise/learning-activity.js.map +0 -1
- package/dist/mock/monorise/learning-journey-config.d.ts +0 -84
- package/dist/mock/monorise/learning-journey-config.d.ts.map +0 -1
- package/dist/mock/monorise/learning-journey-config.js +0 -27
- package/dist/mock/monorise/learning-journey-config.js.map +0 -1
- package/dist/mock/monorise/module.d.ts +0 -211
- package/dist/mock/monorise/module.d.ts.map +0 -1
- package/dist/mock/monorise/module.js +0 -91
- package/dist/mock/monorise/module.js.map +0 -1
- package/dist/mock/monorise/organization.d.ts +0 -346
- package/dist/mock/monorise/organization.d.ts.map +0 -1
- package/dist/mock/monorise/organization.js +0 -54
- package/dist/mock/monorise/organization.js.map +0 -1
- package/dist/mock/monorise/reference.d.ts +0 -171
- package/dist/mock/monorise/reference.d.ts.map +0 -1
- package/dist/mock/monorise/reference.js +0 -25
- package/dist/mock/monorise/reference.js.map +0 -1
- package/dist/mock/monorise/video.d.ts +0 -346
- package/dist/mock/monorise/video.d.ts.map +0 -1
- package/dist/mock/monorise/video.js +0 -33
- package/dist/mock/monorise/video.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { createFactory } from 'hono/factory';
|
|
11
|
+
import { getDependencies } from '../helpers/dependencies';
|
|
12
|
+
const factory = createFactory();
|
|
13
|
+
const generalErrorHandler = (dependencies = getDependencies()) => factory.createMiddleware((c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
if (c.error) {
|
|
15
|
+
const { nanoid, publishErrorEvent } = dependencies;
|
|
16
|
+
const errorId = nanoid();
|
|
17
|
+
const body = yield c.req.json();
|
|
18
|
+
yield publishErrorEvent({
|
|
19
|
+
serviceName: 'monorise-core',
|
|
20
|
+
method: c.req.method,
|
|
21
|
+
path: c.req.path,
|
|
22
|
+
id: errorId,
|
|
23
|
+
body,
|
|
24
|
+
error: c.error,
|
|
25
|
+
});
|
|
26
|
+
console.warn(JSON.stringify({
|
|
27
|
+
message: 'INTERNAL_SERVER_EXCEPTION',
|
|
28
|
+
details: c.error,
|
|
29
|
+
}));
|
|
30
|
+
c.status(500);
|
|
31
|
+
c.json({
|
|
32
|
+
code: 'INTERNAL_SERVER_EXCEPTION',
|
|
33
|
+
id: errorId,
|
|
34
|
+
});
|
|
35
|
+
// so lambda monitor able to track error rate
|
|
36
|
+
throw new Error(`INTERNAL_SERVER_EXCEPTION: ${errorId}: ${c.req.method} ${c.req.path}: ${c.error}`);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
export default generalErrorHandler;
|
|
40
|
+
//# sourceMappingURL=general-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general-error-handler.js","sourceRoot":"","sources":["../../middlewares/general-error-handler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;AAEhC,MAAM,mBAAmB,GAAG,CAAC,YAAY,GAAG,eAAe,EAAE,EAAE,EAAE,CAC/D,OAAO,CAAC,gBAAgB,CAAC,CAAO,CAAC,EAAE,EAAE;IACnC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;QAEnD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;QAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,iBAAiB,CAAC;YACtB,WAAW,EAAE,eAAe;YAC5B,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM;YACpB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI;YAChB,EAAE,EAAE,OAAO;YACX,IAAI;YACJ,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CACV,IAAI,CAAC,SAAS,CAAC;YACb,OAAO,EAAE,2BAA2B;YACpC,OAAO,EAAE,CAAC,CAAC,KAAK;SACjB,CAAC,CACH,CAAC;QAEF,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,2BAA2B;YACjC,EAAE,EAAE,OAAO;SACZ,CAAC,CAAC;QAEH,6CAA6C;QAC7C,MAAM,IAAI,KAAK,CACb,8BAA8B,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE,CACnF,CAAC;IACJ,CAAC;AACH,CAAC,CAAA,CAAC,CAAC;AAEL,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DependencyContainer } from '../services/DependencyContainer';
|
|
2
|
-
export declare const mutualTypeCheck: (container: DependencyContainer) => (
|
|
2
|
+
export declare const mutualTypeCheck: (container: DependencyContainer) => import("hono").MiddlewareHandler<any, string, {}>;
|
|
3
3
|
//# sourceMappingURL=mutual-type-check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutual-type-check.d.ts","sourceRoot":"","sources":["../../middlewares/mutual-type-check.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"mutual-type-check.d.ts","sourceRoot":"","sources":["../../middlewares/mutual-type-check.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,eAAO,MAAM,eAAe,GAAI,WAAW,mBAAmB,sDAkB1D,CAAC"}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { createMiddleware } from 'hono/factory';
|
|
1
11
|
import httpStatus from 'http-status';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
12
|
+
export const mutualTypeCheck = (container) => createMiddleware((c, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const { entityType, byEntityType } = c.req.param();
|
|
14
|
+
if (!container.config.AllowedEntityTypes.includes(entityType) ||
|
|
15
|
+
!container.config.AllowedEntityTypes.includes(byEntityType)) {
|
|
16
|
+
c.status(httpStatus.NOT_FOUND);
|
|
17
|
+
return c.json({
|
|
8
18
|
code: 'NOT_FOUND',
|
|
9
19
|
});
|
|
10
20
|
}
|
|
11
|
-
next();
|
|
12
|
-
};
|
|
21
|
+
yield next();
|
|
22
|
+
}));
|
|
13
23
|
//# sourceMappingURL=mutual-type-check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutual-type-check.js","sourceRoot":"","sources":["../../middlewares/mutual-type-check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutual-type-check.js","sourceRoot":"","sources":["../../middlewares/mutual-type-check.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAA8B,EAAE,EAAE,CAChE,gBAAgB,CAAC,CAAO,CAAC,EAAE,IAAI,EAAE,EAAE;IACjC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,EAG/C,CAAC;IAEF,IACE,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC;QACzD,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAC3D,CAAC;QACD,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,EAAE,CAAC;AACf,CAAC,CAAA,CAAC,CAAC"}
|
|
@@ -1 +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;AAGhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAa3E,eAAO,MAAM,OAAO,GACjB,WAAW,mBAAmB,MAAY,IAAI,QAAQ;;
|
|
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;AAGhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAa3E,eAAO,MAAM,OAAO,GACjB,WAAW,mBAAmB,MAAY,IAAI,QAAQ;;EA2CtD,CAAC"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { StandardError, StandardErrorCode } from '../errors/standard-error';
|
|
2
11
|
import { parseSQSBusEvent } from '../helpers/event';
|
|
3
|
-
export const handler = (container) =>
|
|
12
|
+
export const handler = (container) => (ev) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4
13
|
const { entityService } = container;
|
|
5
14
|
const batchItemFailures = [];
|
|
6
15
|
for (const record of ev.Records) {
|
|
@@ -10,7 +19,10 @@ export const handler = (container) => async (ev) => {
|
|
|
10
19
|
const { entityType, entityId, entityPayload, accountId, options } = detail;
|
|
11
20
|
errorContext.body = body;
|
|
12
21
|
try {
|
|
13
|
-
|
|
22
|
+
if (!entityType) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
yield entityService.createEntity({
|
|
14
26
|
entityType,
|
|
15
27
|
entityId,
|
|
16
28
|
entityPayload,
|
|
@@ -21,12 +33,12 @@ export const handler = (container) => async (ev) => {
|
|
|
21
33
|
catch (err) {
|
|
22
34
|
console.error('=====CREATE_ENTITY_PROCESSOR_ERROR=====', err, JSON.stringify({ errorContext }, null, 2));
|
|
23
35
|
if (err instanceof StandardError &&
|
|
24
|
-
err.code ===
|
|
36
|
+
err.code === StandardErrorCode.INVALID_ENTITY_TYPE) {
|
|
25
37
|
continue; // do not retry
|
|
26
38
|
}
|
|
27
39
|
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
return { batchItemFailures };
|
|
31
|
-
};
|
|
43
|
+
});
|
|
32
44
|
//# sourceMappingURL=create-entity-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-entity-processor.js","sourceRoot":"","sources":["../../processors/create-entity-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"create-entity-processor.js","sourceRoot":"","sources":["../../processors/create-entity-processor.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAcpD,MAAM,CAAC,MAAM,OAAO,GAClB,CAAC,SAA8B,EAAE,EAAE,CAAC,CAAO,EAAY,EAAE,EAAE;IACzD,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,GAC/D,MAAM,CAAC;QACT,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;QAEzB,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,SAAS;YACX,CAAC;YAED,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,IACE,GAAG,YAAY,aAAa;gBAC5B,GAAG,CAAC,IAAI,KAAK,iBAAiB,CAAC,mBAAmB,EAClD,CAAC;gBACD,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,CAAA,CAAC"}
|
|
@@ -1 +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;AAKhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,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;
|
|
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;AAKhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,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,GACjB,WAAW,mBAAmB,MAAY,IAAI,QAAQ;;EAuPtD,CAAC"}
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { TransactionCanceledException } from '@aws-sdk/client-dynamodb';
|
|
2
11
|
// import { EntityConfig } from '#/lambda-layer/monorise';
|
|
3
12
|
import { Mutual } from '../data/Mutual';
|
|
4
|
-
import { StandardError } from '../errors/standard-error';
|
|
13
|
+
import { StandardError, StandardErrorCode } from '../errors/standard-error';
|
|
5
14
|
import { parseSQSBusEvent } from '../helpers/event';
|
|
6
15
|
import { EVENT } from '../types/event';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
export const handler = (container) => async (ev) => {
|
|
16
|
+
const processEntities = (entityIds, action) => __awaiter(void 0, void 0, void 0, function* () { return Promise.allSettled(entityIds.map(action)); });
|
|
17
|
+
export const handler = (container) => (ev) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
18
|
const batchItemFailures = [];
|
|
11
19
|
const { entityRepository, mutualRepository, publishEvent } = container;
|
|
12
|
-
|
|
20
|
+
yield Promise.allSettled(ev.Records.map((record) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
13
22
|
const errorContext = {};
|
|
14
23
|
const body = parseSQSBusEvent(record.body);
|
|
15
24
|
const { detail } = body;
|
|
@@ -17,26 +26,26 @@ export const handler = (container) => async (ev) => {
|
|
|
17
26
|
errorContext.body = body;
|
|
18
27
|
try {
|
|
19
28
|
// Validate if mutual configuration exists
|
|
20
|
-
const config = container.EntityConfig[byEntityType]
|
|
29
|
+
const config = (_c = (_b = (_a = container.config.EntityConfig[byEntityType]) === null || _a === void 0 ? void 0 : _a.mutual) === null || _b === void 0 ? void 0 : _b.mutualFields) === null || _c === void 0 ? void 0 : _c[field];
|
|
21
30
|
if (!config) {
|
|
22
|
-
throw new StandardError(
|
|
31
|
+
throw new StandardError(StandardErrorCode.INVALID_MUTUAL, 'Invalid mutual');
|
|
23
32
|
}
|
|
24
|
-
const mutualDataProcessor = config.mutualDataProcessor
|
|
33
|
+
const mutualDataProcessor = (_d = config.mutualDataProcessor) !== null && _d !== void 0 ? _d : (() => ({}));
|
|
25
34
|
// Create a lock to prevent concurrent modifications
|
|
26
|
-
|
|
35
|
+
yield mutualRepository.createMutualLock({
|
|
27
36
|
byEntityType,
|
|
28
37
|
byEntityId,
|
|
29
38
|
entityType,
|
|
30
39
|
version: publishedAt,
|
|
31
40
|
});
|
|
32
41
|
// Fetch related entities in parallel
|
|
33
|
-
const [byEntity, mutuals] =
|
|
42
|
+
const [byEntity, mutuals] = yield Promise.all([
|
|
34
43
|
entityRepository.getEntity(byEntityType, byEntityId),
|
|
35
44
|
mutualRepository.listEntitiesByEntity(byEntityType, byEntityId, entityType),
|
|
36
45
|
]);
|
|
37
46
|
// Determine which entities were added, removed, or need updates
|
|
38
47
|
const existingEntityIds = new Set(mutuals.items.map((m) => m.entityId));
|
|
39
|
-
const newMutualIds = new Set(mutualIds
|
|
48
|
+
const newMutualIds = new Set(mutualIds !== null && mutualIds !== void 0 ? mutualIds : []);
|
|
40
49
|
const addedEntityIds = [...newMutualIds].filter((id) => !existingEntityIds.has(id));
|
|
41
50
|
const deletedEntityIds = [...existingEntityIds].filter((id) => !newMutualIds.has(id));
|
|
42
51
|
const toUpdateEntityIds = [...existingEntityIds].filter((id) => newMutualIds.has(id));
|
|
@@ -44,9 +53,9 @@ export const handler = (container) => async (ev) => {
|
|
|
44
53
|
errorContext.addedEntityIds = addedEntityIds;
|
|
45
54
|
errorContext.deletedEntityIds = deletedEntityIds;
|
|
46
55
|
errorContext.toUpdateEntityIds = toUpdateEntityIds;
|
|
47
|
-
const addEntities =
|
|
48
|
-
const entity =
|
|
49
|
-
|
|
56
|
+
const addEntities = yield processEntities(addedEntityIds, (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const entity = yield entityRepository.getEntity(entityType, id);
|
|
58
|
+
yield mutualRepository.createMutual(byEntityType, byEntityId, byEntity.data, entityType, id, entity.data, mutualDataProcessor(mutualIds, new Mutual(byEntityType, byEntityId, byEntity.data, entityType, id, entity.data, {}), customContext), {
|
|
50
59
|
ConditionExpression: 'attribute_not_exists(#mutualUpdatedAt) OR #mutualUpdatedAt < :publishedAt',
|
|
51
60
|
ExpressionAttributeNames: {
|
|
52
61
|
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
@@ -56,9 +65,9 @@ export const handler = (container) => async (ev) => {
|
|
|
56
65
|
},
|
|
57
66
|
createAndUpdateDatetime: new Date(publishedAt),
|
|
58
67
|
});
|
|
59
|
-
});
|
|
60
|
-
const deleteEntities =
|
|
61
|
-
|
|
68
|
+
}));
|
|
69
|
+
const deleteEntities = yield processEntities(deletedEntityIds, (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
yield mutualRepository.deleteMutual(byEntityType, byEntityId, entityType, id, {
|
|
62
71
|
ConditionExpression: 'attribute_exists(PK) AND #mutualUpdatedAt < :publishedAt',
|
|
63
72
|
ExpressionAttributeNames: {
|
|
64
73
|
'#mutualUpdatedAt': 'mutualUpdatedAt',
|
|
@@ -67,9 +76,9 @@ export const handler = (container) => async (ev) => {
|
|
|
67
76
|
':publishedAt': { S: publishedAt },
|
|
68
77
|
},
|
|
69
78
|
});
|
|
70
|
-
});
|
|
71
|
-
const updateEntities =
|
|
72
|
-
|
|
79
|
+
}));
|
|
80
|
+
const updateEntities = yield processEntities(toUpdateEntityIds, (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
yield mutualRepository.updateMutual(byEntityType, byEntityId, entityType, id, {
|
|
73
82
|
mutualData: mutualDataProcessor(mutualIds, new Mutual(byEntityType, byEntityId, byEntity.data, entityType, id, {}, {}), customContext),
|
|
74
83
|
mutualUpdatedAt: publishedAt,
|
|
75
84
|
}, {
|
|
@@ -81,14 +90,14 @@ export const handler = (container) => async (ev) => {
|
|
|
81
90
|
':publishedAt': { S: publishedAt },
|
|
82
91
|
},
|
|
83
92
|
});
|
|
84
|
-
});
|
|
93
|
+
}));
|
|
85
94
|
errorContext.results = {
|
|
86
95
|
addEntities,
|
|
87
96
|
deleteEntities,
|
|
88
97
|
updateEntities,
|
|
89
98
|
};
|
|
90
99
|
// release lock
|
|
91
|
-
|
|
100
|
+
yield mutualRepository.deleteMutualLock({
|
|
92
101
|
byEntityType,
|
|
93
102
|
byEntityId,
|
|
94
103
|
entityType,
|
|
@@ -97,10 +106,10 @@ export const handler = (container) => async (ev) => {
|
|
|
97
106
|
if ([...addEntities, ...deleteEntities, ...updateEntities].some((res) => res.status === 'rejected' &&
|
|
98
107
|
!(res.reason instanceof TransactionCanceledException ||
|
|
99
108
|
(res.reason instanceof StandardError &&
|
|
100
|
-
res.reason.code ===
|
|
101
|
-
throw new StandardError(
|
|
109
|
+
res.reason.code === StandardErrorCode.MUTUAL_NOT_FOUND)))) {
|
|
110
|
+
throw new StandardError(StandardErrorCode.MUTUAL_PROCESSOR_ERROR, 'Mutual processor error', null, errorContext);
|
|
102
111
|
}
|
|
103
|
-
|
|
112
|
+
yield publishEvent({
|
|
104
113
|
event: EVENT.CORE.ENTITY_MUTUAL_PROCESSED,
|
|
105
114
|
payload: {
|
|
106
115
|
byEntityType,
|
|
@@ -115,18 +124,19 @@ export const handler = (container) => async (ev) => {
|
|
|
115
124
|
catch (err) {
|
|
116
125
|
console.error('=====MUTUAL_PROCESSOR_ERROR=====', err, JSON.stringify({ errorContext }, null, 2));
|
|
117
126
|
// Release the lock to avoid deadlocks
|
|
118
|
-
|
|
127
|
+
yield mutualRepository.deleteMutualLock({
|
|
119
128
|
byEntityType,
|
|
120
129
|
byEntityId,
|
|
121
130
|
entityType,
|
|
122
131
|
});
|
|
123
132
|
if (err instanceof StandardError &&
|
|
124
|
-
|
|
133
|
+
(err.code === StandardErrorCode.INVALID_MUTUAL ||
|
|
134
|
+
err.code === StandardErrorCode.MUTUAL_LOCK_CONFLICT)) {
|
|
125
135
|
return;
|
|
126
136
|
}
|
|
127
137
|
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
128
138
|
}
|
|
129
|
-
}));
|
|
139
|
+
})));
|
|
130
140
|
return { batchItemFailures };
|
|
131
|
-
};
|
|
141
|
+
});
|
|
132
142
|
//# sourceMappingURL=mutual-processor.js.map
|
|
@@ -1 +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,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
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ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAI3E,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;
|
|
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;AAMhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAI3E,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;AA2LF,eAAO,MAAM,OAAO,GACjB,WAAW,mBAAmB,MAAY,IAAI,QAAQ;;EA8DtD,CAAC"}
|
|
@@ -1,106 +1,122 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { PROJECTION_EXPRESSION } from '../data/ProjectionExpression';
|
|
2
11
|
import { parseSQSBusEvent } from '../helpers/event';
|
|
3
12
|
import { EVENT } from '../types/event';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for (const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.entityType;
|
|
37
|
-
const parentEntities = mutualCache[parentEntityType] ?? [];
|
|
38
|
-
// find all nested entities
|
|
39
|
-
for (const parentEntity of parentEntities) {
|
|
40
|
-
const { entityType: parentEntityType, entityId: parentEntityId } = parentEntity;
|
|
41
|
-
const { items: mutualItems } = await mutualRepository.listEntitiesByEntity(parentEntityType, parentEntityId, entityPath.entityType, {
|
|
42
|
-
ProjectionExpression: PROJECTION_EXPRESSION.MUTUAL_DATA_ONLY,
|
|
43
|
-
});
|
|
44
|
-
// custom processor defined in prejoin config for each path
|
|
45
|
-
const processor = entityPath.processor || ((items, context) => ({ items, context }));
|
|
46
|
-
const processed = processor(mutualItems, toBePublishedContext);
|
|
47
|
-
toBePublishedContext = processed?.context || toBePublishedContext;
|
|
48
|
-
mutualCache[entityType] = [
|
|
49
|
-
...(mutualCache[entityType] ?? []),
|
|
50
|
-
...(processed ? processed.items : mutualItems),
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
if (!mutualCache[entityType] && !Array.isArray(mutualCache[entityType])) {
|
|
54
|
-
// to avoid empty array
|
|
13
|
+
function processPrejoins(_a) {
|
|
14
|
+
return __awaiter(this, arguments, void 0, function* ({ mutualRepository, publishEvent, byEntityType, byEntityId, prejoins, publishedAt, }) {
|
|
15
|
+
var _b, _c, _d;
|
|
16
|
+
const mutualCache = {
|
|
17
|
+
/*
|
|
18
|
+
course: [{
|
|
19
|
+
byEntityType: 'module',
|
|
20
|
+
byEntityId: '1',
|
|
21
|
+
entityType: 'course',
|
|
22
|
+
entityId: '1',
|
|
23
|
+
}],
|
|
24
|
+
module: [],
|
|
25
|
+
chapter: [],
|
|
26
|
+
video: []
|
|
27
|
+
*/
|
|
28
|
+
};
|
|
29
|
+
//initiate
|
|
30
|
+
mutualCache[byEntityType] = [
|
|
31
|
+
{
|
|
32
|
+
entityType: byEntityType,
|
|
33
|
+
entityId: byEntityId,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
for (const { mutualField, targetEntityType, entityPaths } of prejoins) {
|
|
37
|
+
let toBePublishedContext = {};
|
|
38
|
+
for (const [index, entityPath] of entityPaths.entries()) {
|
|
39
|
+
const entityType = entityPath.entityType;
|
|
40
|
+
// skip cached
|
|
41
|
+
if (!entityPath.skipCache && mutualCache[entityType]) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// if skipping cache should not have previous run data
|
|
55
45
|
mutualCache[entityType] = [];
|
|
46
|
+
const parentEntityType = entityPaths[index - 1]
|
|
47
|
+
.entityType;
|
|
48
|
+
const parentEntities = (_b = mutualCache[parentEntityType]) !== null && _b !== void 0 ? _b : [];
|
|
49
|
+
// find all nested entities
|
|
50
|
+
for (const parentEntity of parentEntities) {
|
|
51
|
+
const { entityType: parentEntityType, entityId: parentEntityId } = parentEntity;
|
|
52
|
+
const { items: mutualItems } = yield mutualRepository.listEntitiesByEntity(parentEntityType, parentEntityId, entityPath.entityType, {
|
|
53
|
+
ProjectionExpression: PROJECTION_EXPRESSION.MUTUAL_DATA_ONLY,
|
|
54
|
+
});
|
|
55
|
+
// custom processor defined in prejoin config for each path
|
|
56
|
+
const processor = entityPath.processor || ((items, context) => ({ items, context }));
|
|
57
|
+
const processed = processor(mutualItems, toBePublishedContext);
|
|
58
|
+
toBePublishedContext = (processed === null || processed === void 0 ? void 0 : processed.context) || toBePublishedContext;
|
|
59
|
+
mutualCache[entityType] = [
|
|
60
|
+
...((_c = mutualCache[entityType]) !== null && _c !== void 0 ? _c : []),
|
|
61
|
+
...(processed ? processed.items : mutualItems),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
if (!mutualCache[entityType] && !Array.isArray(mutualCache[entityType])) {
|
|
65
|
+
// to avoid empty array
|
|
66
|
+
mutualCache[entityType] = [];
|
|
67
|
+
}
|
|
56
68
|
}
|
|
69
|
+
const mutualIds = ((_d = mutualCache[targetEntityType]) !== null && _d !== void 0 ? _d : []).map((item) => item.entityId);
|
|
70
|
+
yield publishEvent({
|
|
71
|
+
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
72
|
+
payload: {
|
|
73
|
+
byEntityType,
|
|
74
|
+
byEntityId,
|
|
75
|
+
entityType: targetEntityType,
|
|
76
|
+
field: mutualField,
|
|
77
|
+
mutualIds,
|
|
78
|
+
customContext: toBePublishedContext,
|
|
79
|
+
publishedAt,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
57
82
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function publishToSubscribers(_a) {
|
|
86
|
+
return __awaiter(this, arguments, void 0, function* ({ container, publishEvent, byEntityType, byEntityId, publishedAt, }) {
|
|
87
|
+
const listeners = container.config.AllowedEntityTypes.reduce((acc, configKey) => {
|
|
88
|
+
var _a;
|
|
89
|
+
const { subscribes } = (_a = container.config.EntityConfig[configKey].mutual) !== null && _a !== void 0 ? _a : {};
|
|
90
|
+
const hasSubscription = (subscribes !== null && subscribes !== void 0 ? subscribes : []).some(({ entityType }) => entityType === byEntityType);
|
|
91
|
+
return [
|
|
92
|
+
...acc,
|
|
93
|
+
...(hasSubscription
|
|
94
|
+
? [
|
|
95
|
+
{
|
|
96
|
+
entityType: configKey,
|
|
97
|
+
},
|
|
98
|
+
]
|
|
99
|
+
: []),
|
|
100
|
+
];
|
|
101
|
+
}, []);
|
|
102
|
+
// publish event for each interested entity
|
|
103
|
+
const subscribedMutualItems = yield Promise.all(listeners.map(({ entityType: subscribedEntityType }) => container.mutualRepository.listEntitiesByEntity(byEntityType, byEntityId, subscribedEntityType, {
|
|
104
|
+
ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA,
|
|
105
|
+
})));
|
|
106
|
+
const subscribedMutuals = subscribedMutualItems.flatMap((item) => item.items);
|
|
107
|
+
yield Promise.all(subscribedMutuals.map((subscribedMutual) => publishEvent({
|
|
108
|
+
event: EVENT.CORE.PREJOIN_RELATIONSHIP_SYNC,
|
|
61
109
|
payload: {
|
|
62
|
-
byEntityType,
|
|
63
|
-
byEntityId,
|
|
64
|
-
entityType:
|
|
65
|
-
field: mutualField,
|
|
66
|
-
mutualIds,
|
|
67
|
-
customContext: toBePublishedContext,
|
|
110
|
+
byEntityType: subscribedMutual.entityType,
|
|
111
|
+
byEntityId: subscribedMutual.entityId,
|
|
112
|
+
entityType: subscribedMutual.byEntityType,
|
|
68
113
|
publishedAt,
|
|
69
114
|
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function publishToSubscribers({ container, publishEvent, byEntityType, byEntityId, publishedAt, }) {
|
|
74
|
-
const listeners = container.AllowedEntityTypes.reduce((acc, configKey) => {
|
|
75
|
-
const { subscribes } = container.EntityConfig[configKey].mutual ?? {};
|
|
76
|
-
const hasSubscription = (subscribes ?? []).some(({ entityType }) => entityType === byEntityType);
|
|
77
|
-
return [
|
|
78
|
-
...acc,
|
|
79
|
-
...(hasSubscription
|
|
80
|
-
? [
|
|
81
|
-
{
|
|
82
|
-
entityType: configKey,
|
|
83
|
-
},
|
|
84
|
-
]
|
|
85
|
-
: []),
|
|
86
|
-
];
|
|
87
|
-
}, []);
|
|
88
|
-
// publish event for each interested entity
|
|
89
|
-
const subscribedMutualItems = await Promise.all(listeners.map(({ entityType: subscribedEntityType }) => container.mutualRepository.listEntitiesByEntity(byEntityType, byEntityId, subscribedEntityType, {
|
|
90
|
-
ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA,
|
|
91
|
-
})));
|
|
92
|
-
const subscribedMutuals = subscribedMutualItems.flatMap((item) => item.items);
|
|
93
|
-
await Promise.all(subscribedMutuals.map((subscribedMutual) => publishEvent({
|
|
94
|
-
event: EVENT.CORE.PREJOIN_RELATIONSHIP_SYNC,
|
|
95
|
-
payload: {
|
|
96
|
-
byEntityType: subscribedMutual.entityType,
|
|
97
|
-
byEntityId: subscribedMutual.entityId,
|
|
98
|
-
entityType: subscribedMutual.byEntityType,
|
|
99
|
-
publishedAt,
|
|
100
|
-
},
|
|
101
|
-
})));
|
|
115
|
+
})));
|
|
116
|
+
});
|
|
102
117
|
}
|
|
103
|
-
export const handler = (container) =>
|
|
118
|
+
export const handler = (container) => (ev) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
104
120
|
const batchItemFailures = [];
|
|
105
121
|
const { mutualRepository, publishEvent } = container;
|
|
106
122
|
for (const record of ev.Records) {
|
|
@@ -111,26 +127,23 @@ export const handler = (container) => async (ev) => {
|
|
|
111
127
|
body,
|
|
112
128
|
};
|
|
113
129
|
try {
|
|
114
|
-
const isEntityTypeSubscribed = (container.EntityConfig[byEntityType]
|
|
115
|
-
const hasPrejoins = container.EntityConfig[byEntityType]
|
|
130
|
+
const isEntityTypeSubscribed = ((_c = (_b = (_a = container.config.EntityConfig[byEntityType]) === null || _a === void 0 ? void 0 : _a.mutual) === null || _b === void 0 ? void 0 : _b.subscribes) !== null && _c !== void 0 ? _c : []).some(({ entityType: subscribedEntityType }) => subscribedEntityType === entityType);
|
|
131
|
+
const hasPrejoins = (_e = (_d = container.config.EntityConfig[byEntityType]) === null || _d === void 0 ? void 0 : _d.mutual) === null || _e === void 0 ? void 0 : _e.prejoins;
|
|
116
132
|
const shouldProcessPrejoins = isEntityTypeSubscribed && hasPrejoins;
|
|
117
|
-
errorContext = {
|
|
118
|
-
...errorContext,
|
|
119
|
-
isEntityTypeSubscribed,
|
|
133
|
+
errorContext = Object.assign(Object.assign({}, errorContext), { isEntityTypeSubscribed,
|
|
120
134
|
hasPrejoins,
|
|
121
|
-
shouldProcessPrejoins
|
|
122
|
-
};
|
|
135
|
+
shouldProcessPrejoins });
|
|
123
136
|
if (shouldProcessPrejoins) {
|
|
124
|
-
|
|
137
|
+
yield processPrejoins({
|
|
125
138
|
mutualRepository,
|
|
126
139
|
publishEvent,
|
|
127
140
|
byEntityType,
|
|
128
141
|
byEntityId,
|
|
129
|
-
prejoins: container.EntityConfig[byEntityType]
|
|
142
|
+
prejoins: (_h = (_g = (_f = container.config.EntityConfig[byEntityType]) === null || _f === void 0 ? void 0 : _f.mutual) === null || _g === void 0 ? void 0 : _g.prejoins) !== null && _h !== void 0 ? _h : [],
|
|
130
143
|
publishedAt,
|
|
131
144
|
});
|
|
132
145
|
}
|
|
133
|
-
|
|
146
|
+
yield publishToSubscribers({
|
|
134
147
|
container,
|
|
135
148
|
publishEvent,
|
|
136
149
|
byEntityType,
|
|
@@ -144,5 +157,5 @@ export const handler = (container) => async (ev) => {
|
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
159
|
return { batchItemFailures };
|
|
147
|
-
};
|
|
160
|
+
});
|
|
148
161
|
//# sourceMappingURL=prejoin-processor.js.map
|