@mbc-cqrs-serverless/import 1.0.0 → 1.0.1
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/constant/id.d.ts +3 -0
- package/dist/constant/id.js +7 -0
- package/dist/constant/id.js.map +1 -0
- package/dist/constant/index.d.ts +2 -1
- package/dist/constant/index.js +16 -2
- package/dist/constant/index.js.map +1 -1
- package/dist/constant/queue.d.ts +2 -0
- package/dist/constant/queue.js +6 -0
- package/dist/constant/queue.js.map +1 -0
- package/dist/dto/create-csv-import.dto.d.ts +1 -0
- package/dist/dto/create-csv-import.dto.js +5 -0
- package/dist/dto/create-csv-import.dto.js.map +1 -1
- package/dist/dto/create-import.dto.d.ts +1 -0
- package/dist/dto/create-import.dto.js +5 -0
- package/dist/dto/create-import.dto.js.map +1 -1
- package/dist/dto/create-zip-import.dto.d.ts +5 -0
- package/dist/dto/create-zip-import.dto.js +32 -0
- package/dist/dto/create-zip-import.dto.js.map +1 -0
- package/dist/dto/index.d.ts +1 -0
- package/dist/dto/index.js +1 -0
- package/dist/dto/index.js.map +1 -1
- package/dist/entity/import-entity.d.ts +4 -0
- package/dist/entity/import-entity.js +1 -0
- package/dist/entity/import-entity.js.map +1 -1
- package/dist/event/command-finished.queue.event.handler.d.ts +31 -0
- package/dist/event/command-finished.queue.event.handler.js +126 -0
- package/dist/event/command-finished.queue.event.handler.js.map +1 -0
- package/dist/event/csv-import.queue.event.handler.js +7 -3
- package/dist/event/csv-import.queue.event.handler.js.map +1 -1
- package/dist/event/csv-import.sfn.event.handler.d.ts +2 -0
- package/dist/event/csv-import.sfn.event.handler.js +57 -3
- package/dist/event/csv-import.sfn.event.handler.js.map +1 -1
- package/dist/event/import-status.queue.event.d.ts +15 -0
- package/dist/event/import-status.queue.event.handler.d.ts +16 -0
- package/dist/event/import-status.queue.event.handler.js +82 -0
- package/dist/event/import-status.queue.event.handler.js.map +1 -0
- package/dist/event/import-status.queue.event.js +13 -0
- package/dist/event/import-status.queue.event.js.map +1 -0
- package/dist/event/import.queue.event.handler.js +40 -15
- package/dist/event/import.queue.event.handler.js.map +1 -1
- package/dist/event/index.d.ts +6 -0
- package/dist/event/index.js +6 -0
- package/dist/event/index.js.map +1 -1
- package/dist/event/zip-import.queue.event.handler.d.ts +25 -0
- package/dist/event/zip-import.queue.event.handler.js +183 -0
- package/dist/event/zip-import.queue.event.handler.js.map +1 -0
- package/dist/event/zip-import.sfn.event.d.ts +8 -0
- package/dist/event/zip-import.sfn.event.handler.d.ts +21 -0
- package/dist/event/zip-import.sfn.event.handler.js +94 -0
- package/dist/event/zip-import.sfn.event.handler.js.map +1 -0
- package/dist/event/zip-import.sfn.event.js +34 -0
- package/dist/event/zip-import.sfn.event.js.map +1 -0
- package/dist/helpers/id.d.ts +2 -0
- package/dist/helpers/id.js +15 -0
- package/dist/helpers/id.js.map +1 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +18 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/import.controller.d.ts +2 -0
- package/dist/import.controller.js +26 -0
- package/dist/import.controller.js.map +1 -1
- package/dist/import.module.js +8 -0
- package/dist/import.module.js.map +1 -1
- package/dist/import.service.d.ts +30 -1
- package/dist/import.service.js +156 -3
- package/dist/import.service.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZIP_IMPORT_PK_PREFIX = exports.CSV_IMPORT_PK_PREFIX = exports.IMPORT_PK_PREFIX = void 0;
|
|
4
|
+
exports.IMPORT_PK_PREFIX = 'IMPORT';
|
|
5
|
+
exports.CSV_IMPORT_PK_PREFIX = 'CSV_IMPORT';
|
|
6
|
+
exports.ZIP_IMPORT_PK_PREFIX = 'ZIP_IMPORT';
|
|
7
|
+
//# sourceMappingURL=id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/constant/id.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,QAAQ,CAAA;AAC3B,QAAA,oBAAoB,GAAG,YAAY,CAAA;AACnC,QAAA,oBAAoB,GAAG,YAAY,CAAA"}
|
package/dist/constant/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './id';
|
|
2
|
+
export * from './queue';
|
package/dist/constant/index.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
exports
|
|
17
|
+
__exportStar(require("./id"), exports);
|
|
18
|
+
__exportStar(require("./queue"), exports);
|
|
5
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAoB;AACpB,0CAAuB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_IMPORT_STATUS_QUEUE = exports.DEFAULT_IMPORT_ACTION_QUEUE = void 0;
|
|
4
|
+
exports.DEFAULT_IMPORT_ACTION_QUEUE = 'import-action-queue';
|
|
5
|
+
exports.DEFAULT_IMPORT_STATUS_QUEUE = 'import-status-queue';
|
|
6
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/constant/queue.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,qBAAqB,CAAA;AACnD,QAAA,2BAA2B,GAAG,qBAAqB,CAAA"}
|
|
@@ -15,6 +15,11 @@ const enum_1 = require("../enum");
|
|
|
15
15
|
class CreateCsvImportDto {
|
|
16
16
|
}
|
|
17
17
|
exports.CreateCsvImportDto = CreateCsvImportDto;
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, class_validator_1.IsString)(),
|
|
20
|
+
(0, class_validator_1.IsOptional)(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], CreateCsvImportDto.prototype, "sourceId", void 0);
|
|
18
23
|
__decorate([
|
|
19
24
|
(0, class_validator_1.IsNotEmpty)(),
|
|
20
25
|
(0, class_validator_1.IsEnum)(enum_1.ProcessingMode),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-csv-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-csv-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"create-csv-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-csv-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA0E;AAE1E,kCAAwC;AAExC,MAAa,kBAAkB;CAwB9B;AAxBD,gDAwBC;AArBC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;oDACI;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,qBAAc,CAAC;;0DACO;AAI9B;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;kDACC;AAId;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;+CACF;AAIX;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;qDACI;AAIjB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sDACK"}
|
|
@@ -14,6 +14,11 @@ const class_validator_1 = require("class-validator");
|
|
|
14
14
|
class CreateImportDto {
|
|
15
15
|
}
|
|
16
16
|
exports.CreateImportDto = CreateImportDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsOptional)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], CreateImportDto.prototype, "sourceId", void 0);
|
|
17
22
|
__decorate([
|
|
18
23
|
(0, class_validator_1.IsString)(),
|
|
19
24
|
__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAgE;AAEhE,MAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"create-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAgE;AAEhE,MAAa,eAAe;CAiB3B;AAjBD,0CAiBC;AAdC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;iDACI;AAGjB;IADC,IAAA,0BAAQ,GAAE;;kDACM;AAGjB;IADC,IAAA,0BAAQ,GAAE;;mDACO;AAIlB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;6CACA;AAGb;IADC,IAAA,0BAAQ,GAAE;;mDACoB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateZipImportDto = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class CreateZipImportDto {
|
|
15
|
+
}
|
|
16
|
+
exports.CreateZipImportDto = CreateZipImportDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], CreateZipImportDto.prototype, "bucket", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsString)(),
|
|
24
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], CreateZipImportDto.prototype, "key", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, class_validator_1.IsString)(),
|
|
29
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], CreateZipImportDto.prototype, "tenantCode", void 0);
|
|
32
|
+
//# sourceMappingURL=create-zip-import.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-zip-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-zip-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsD;AAEtD,MAAa,kBAAkB;CAY9B;AAZD,gDAYC;AATC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;kDACC;AAId;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;+CACF;AAIX;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sDACK"}
|
package/dist/dto/index.d.ts
CHANGED
package/dist/dto/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./create-csv-import.dto"), exports);
|
|
18
18
|
__exportStar(require("./create-import.dto"), exports);
|
|
19
19
|
__exportStar(require("./csv-import-row.interface"), exports);
|
|
20
|
+
__exportStar(require("./create-zip-import.dto"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/dto/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,sDAAmC;AACnC,6DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,sDAAmC;AACnC,6DAA0C;AAC1C,0DAAuC"}
|
|
@@ -16,5 +16,9 @@ export declare class ImportEntity extends CommandEntity {
|
|
|
16
16
|
status?: ImportStatusEnum;
|
|
17
17
|
attributes: Record<string, any>;
|
|
18
18
|
result?: Record<string, any>;
|
|
19
|
+
totalRows?: number;
|
|
20
|
+
processedRows?: number;
|
|
21
|
+
succeededRows?: number;
|
|
22
|
+
failedRows?: number;
|
|
19
23
|
constructor(partial: Partial<ImportEntity>);
|
|
20
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-entity.js","sourceRoot":"","sources":["../../src/entity/import-entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;GAWG;AACH,MAAa,YAAa,SAAQ,oBAAa;
|
|
1
|
+
{"version":3,"file":"import-entity.js","sourceRoot":"","sources":["../../src/entity/import-entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;GAWG;AACH,MAAa,YAAa,SAAQ,oBAAa;IAU7C,uCAAuC;IAEvC,YAAY,OAA8B;QACxC,KAAK,EAAE,CAAA;QACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9B,CAAC;CACF;AAhBD,oCAgBC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IEventHandler, NotificationEvent } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { ImportService } from '../import.service';
|
|
3
|
+
export declare class CommandFinishedHandler implements IEventHandler<NotificationEvent> {
|
|
4
|
+
private readonly importService;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(importService: ImportService);
|
|
7
|
+
/**
|
|
8
|
+
* Executes the handler logic when a NotificationEvent is received.
|
|
9
|
+
* This method orchestrates the validation, parsing, and processing of command status updates.
|
|
10
|
+
* @param {NotificationEvent} event The incoming event.
|
|
11
|
+
*/
|
|
12
|
+
execute(event: NotificationEvent): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Parses the JSON event body and validates its basic structure.
|
|
15
|
+
* @param {string} body The raw event body string.
|
|
16
|
+
* @returns {CommandStatusNotification | null} The parsed payload or null if invalid.
|
|
17
|
+
*/
|
|
18
|
+
private parseAndValidatePayload;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the event source is an import job.
|
|
21
|
+
* @param {string} source The source identifier from the event.
|
|
22
|
+
* @returns {boolean} True if the source is for an import job.
|
|
23
|
+
*/
|
|
24
|
+
private isImportSource;
|
|
25
|
+
/**
|
|
26
|
+
* Maps a raw command status string to the corresponding ImportStatusEnum.
|
|
27
|
+
* @param {string} commandStatus The status string from the command.
|
|
28
|
+
* @returns {ImportStatusEnum | null} The mapped status or null if it's not a final status.
|
|
29
|
+
*/
|
|
30
|
+
private mapCommandStatusToImportStatus;
|
|
31
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var CommandFinishedHandler_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CommandFinishedHandler = void 0;
|
|
14
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const constant_1 = require("../constant");
|
|
17
|
+
const enum_1 = require("../enum");
|
|
18
|
+
const helpers_1 = require("../helpers");
|
|
19
|
+
const import_service_1 = require("../import.service");
|
|
20
|
+
// Constants for magic strings to improve maintainability.
|
|
21
|
+
const ACTION_COMMAND_STATUS = 'command-status';
|
|
22
|
+
let CommandFinishedHandler = CommandFinishedHandler_1 = class CommandFinishedHandler {
|
|
23
|
+
constructor(importService) {
|
|
24
|
+
this.importService = importService;
|
|
25
|
+
this.logger = new common_1.Logger(CommandFinishedHandler_1.name);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Executes the handler logic when a NotificationEvent is received.
|
|
29
|
+
* This method orchestrates the validation, parsing, and processing of command status updates.
|
|
30
|
+
* @param {NotificationEvent} event The incoming event.
|
|
31
|
+
*/
|
|
32
|
+
async execute(event) {
|
|
33
|
+
this.logger.debug('Processing command notification event...');
|
|
34
|
+
try {
|
|
35
|
+
// 1. Parse and validate the event payload.
|
|
36
|
+
const payload = this.parseAndValidatePayload(event.body);
|
|
37
|
+
if (!payload) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { source, status, result, error } = payload.content;
|
|
41
|
+
// 2. Ensure the notification is for a relevant import job.
|
|
42
|
+
if (!this.isImportSource(source)) {
|
|
43
|
+
this.logger.debug(`Ignoring notification from non-import source: ${source}`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// 3. Map the command status to a final import status (e.g., COMPLETED, FAILED).
|
|
47
|
+
const newStatus = this.mapCommandStatusToImportStatus(status);
|
|
48
|
+
if (!newStatus) {
|
|
49
|
+
this.logger.debug(`Ignoring intermediate command status '${status}' for source ${source}`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// 4. Parse the source string to get the database key.
|
|
53
|
+
const importKey = (0, helpers_1.parseId)(source);
|
|
54
|
+
if (!importKey) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// 5. Update the import entity with the new status and result/error data.
|
|
58
|
+
this.logger.log(`Updating import job ${source} to status ${newStatus}`);
|
|
59
|
+
await this.importService.updateStatus(importKey, newStatus, {
|
|
60
|
+
result,
|
|
61
|
+
error,
|
|
62
|
+
});
|
|
63
|
+
const skParts = importKey.sk.split(core_1.KEY_SEPARATOR);
|
|
64
|
+
const parentId = skParts.slice(0, -1).join(core_1.KEY_SEPARATOR); // Everything except the last part (the child's own ULID)
|
|
65
|
+
if (parentId.startsWith(constant_1.CSV_IMPORT_PK_PREFIX)) {
|
|
66
|
+
const parentKey = (0, helpers_1.parseId)(parentId);
|
|
67
|
+
const childSucceeded = newStatus === enum_1.ImportStatusEnum.COMPLETED;
|
|
68
|
+
// This call will handle incrementing and finalizing the parent job.
|
|
69
|
+
await this.importService.incrementParentJobCounters(parentKey, childSucceeded);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger.error('Failed to process command notification event', error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parses the JSON event body and validates its basic structure.
|
|
79
|
+
* @param {string} body The raw event body string.
|
|
80
|
+
* @returns {CommandStatusNotification | null} The parsed payload or null if invalid.
|
|
81
|
+
*/
|
|
82
|
+
parseAndValidatePayload(body) {
|
|
83
|
+
try {
|
|
84
|
+
const payload = JSON.parse(body);
|
|
85
|
+
if (payload.action !== ACTION_COMMAND_STATUS ||
|
|
86
|
+
!payload.content?.source) {
|
|
87
|
+
this.logger.debug('Ignoring notification: not a valid command status event for import.');
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return payload;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger.error('Failed to parse event body as JSON', body);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the event source is an import job.
|
|
99
|
+
* @param {string} source The source identifier from the event.
|
|
100
|
+
* @returns {boolean} True if the source is for an import job.
|
|
101
|
+
*/
|
|
102
|
+
isImportSource(source = '') {
|
|
103
|
+
return source.startsWith(`${constant_1.IMPORT_PK_PREFIX}${core_1.KEY_SEPARATOR}`);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Maps a raw command status string to the corresponding ImportStatusEnum.
|
|
107
|
+
* @param {string} commandStatus The status string from the command.
|
|
108
|
+
* @returns {ImportStatusEnum | null} The mapped status or null if it's not a final status.
|
|
109
|
+
*/
|
|
110
|
+
mapCommandStatusToImportStatus(commandStatus) {
|
|
111
|
+
switch (commandStatus) {
|
|
112
|
+
case `${core_1.DataSyncCommandSfnName.FINISH}:${core_1.CommandStatus.STATUS_FINISHED}`:
|
|
113
|
+
return enum_1.ImportStatusEnum.COMPLETED;
|
|
114
|
+
case `${core_1.DataSyncCommandSfnName.FINISH}:${core_1.CommandStatus.STATUS_FAILED}`:
|
|
115
|
+
return enum_1.ImportStatusEnum.FAILED;
|
|
116
|
+
default:
|
|
117
|
+
return null; // Not a final status we need to handle.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exports.CommandFinishedHandler = CommandFinishedHandler;
|
|
122
|
+
exports.CommandFinishedHandler = CommandFinishedHandler = CommandFinishedHandler_1 = __decorate([
|
|
123
|
+
(0, core_1.EventHandler)(core_1.NotificationEvent),
|
|
124
|
+
__metadata("design:paramtypes", [import_service_1.ImportService])
|
|
125
|
+
], CommandFinishedHandler);
|
|
126
|
+
//# sourceMappingURL=command-finished.queue.event.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-finished.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/command-finished.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAOkC;AAClC,2CAAuC;AAEvC,0CAAoE;AACpE,kCAA0C;AAC1C,wCAAoC;AACpC,sDAAiD;AAajD,0DAA0D;AAC1D,MAAM,qBAAqB,GAAG,gBAAgB,CAAA;AAGvC,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAKjC,YAA6B,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cAAc,CAAC,SAAiB,EAAE;QACxC,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,2BAAgB,GAAG,oBAAa,EAAE,CAAC,CAAA;IACjE,CAAC;IAED;;;;OAIG;IACK,8BAA8B,CACpC,aAAqB;QAErB,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,GAAG,6BAAsB,CAAC,MAAM,IAAI,oBAAa,CAAC,eAAe,EAAE;gBACtE,OAAO,uBAAgB,CAAC,SAAS,CAAA;YACnC,KAAK,GAAG,6BAAsB,CAAC,MAAM,IAAI,oBAAa,CAAC,aAAa,EAAE;gBACpE,OAAO,uBAAgB,CAAC,MAAM,CAAA;YAChC;gBACE,OAAO,IAAI,CAAA,CAAC,wCAAwC;QACxD,CAAC;IACH,CAAC;CACF,CAAA;AA9HY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAY,EAAC,wBAAiB,CAAC;qCAMc,8BAAa;GAL9C,sBAAsB,CA8HlC"}
|
|
@@ -18,6 +18,7 @@ exports.CsvImportQueueEventHandler = void 0;
|
|
|
18
18
|
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
19
19
|
const common_1 = require("@nestjs/common");
|
|
20
20
|
const config_1 = require("@nestjs/config");
|
|
21
|
+
const constant_1 = require("../constant");
|
|
21
22
|
const import_status_enum_1 = require("../enum/import-status.enum");
|
|
22
23
|
const import_module_definition_1 = require("../import.module-definition");
|
|
23
24
|
const import_service_1 = require("../import.service");
|
|
@@ -33,8 +34,8 @@ let CsvImportQueueEventHandler = CsvImportQueueEventHandler_1 = class CsvImportQ
|
|
|
33
34
|
}
|
|
34
35
|
async execute(event) {
|
|
35
36
|
const importEntity = event.importEvent.importEntity;
|
|
36
|
-
// This handler ONLY acts on master jobs and ignores all other event types.
|
|
37
|
-
if (importEntity.
|
|
37
|
+
// This handler ONLY acts on master csv jobs and ignores all other event types.
|
|
38
|
+
if (!importEntity.id.startsWith(`${constant_1.CSV_IMPORT_PK_PREFIX}${core_1.KEY_SEPARATOR}`)) {
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
41
|
const importKey = event.importEvent.importKey;
|
|
@@ -47,7 +48,10 @@ let CsvImportQueueEventHandler = CsvImportQueueEventHandler_1 = class CsvImportQ
|
|
|
47
48
|
if (!mapper) {
|
|
48
49
|
throw new Error(`No CSV mapping strategy found for table: ${tableName}`);
|
|
49
50
|
}
|
|
50
|
-
await this.sfnService.startExecution(this.csvImportArn,
|
|
51
|
+
await this.sfnService.startExecution(this.csvImportArn, {
|
|
52
|
+
...importEntity.attributes,
|
|
53
|
+
sourceId: importEntity.id,
|
|
54
|
+
}, `${tenantCode}-${tableName}-${Date.now()}`);
|
|
51
55
|
this.logger.log(`Started Step Function execution for master job ${importEntity.id}`);
|
|
52
56
|
// The master job's status will now be updated by the Step Function itself upon completion/failure.
|
|
53
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv-import.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"csv-import.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA8C;AAC9C,oDAKkC;AAClC,2CAA+C;AAC/C,2CAA8C;AAE9C,0CAAkD;AAElD,mEAA6D;AAC7D,0EAAiE;AACjE,sDAAiD;AAEjD,6DAAuD;AAGhD,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IAMrC,YACmB,aAA4B,EAC5B,UAA+B,EAC/B,aAA4B,EAE7C,iBAA0E;QAJzD,kBAAa,GAAb,aAAa,CAAe;QAC5B,eAAU,GAAV,UAAU,CAAqB;QAC/B,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAwC;QAR3D,WAAM,GAAG,IAAI,eAAM,CAAC,4BAA0B,CA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YACD,mGAAmG;QACrG,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,gDAAgD,YAAY,CAAC,EAAE,EAAE,EACjE,KAAK,CACN,CAAA;YACD,qEAAqE;YACrE,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CACnC,SAAS,EACT,qCAAgB,CAAC,MAAM,EACvB;gBACE,KAAK,EAAE;oBACL,OAAO,EAAE,kCAAmC,KAAe,CAAC,OAAO,EAAE;iBACtE;aACF,CACF,CAAA;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA;AA5EY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAY,EAAC,qCAAgB,CAAC;IAW1B,WAAA,IAAA,eAAM,EAAC,8CAAmB,CAAC,CAAA;qCAHI,sBAAa;QAChB,0BAAmB;QAChB,8BAAa;QAET,GAAG;GAX9B,0BAA0B,CA4EtC"}
|
|
@@ -14,4 +14,6 @@ export declare class CsvImportSfnEventHandler implements IEventHandler<CsvImport
|
|
|
14
14
|
execute(event: CsvImportSfnEvent): Promise<any>;
|
|
15
15
|
handleStepState(event: CsvImportSfnEvent): Promise<any>;
|
|
16
16
|
private loadCsv;
|
|
17
|
+
private countCsvRows;
|
|
18
|
+
private finalizeParentJob;
|
|
17
19
|
}
|
|
@@ -23,6 +23,8 @@ const common_1 = require("@nestjs/common");
|
|
|
23
23
|
const config_1 = require("@nestjs/config");
|
|
24
24
|
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
25
25
|
const stream_1 = require("stream");
|
|
26
|
+
const enum_1 = require("../enum");
|
|
27
|
+
const helpers_1 = require("../helpers");
|
|
26
28
|
const import_module_definition_1 = require("../import.module-definition");
|
|
27
29
|
const import_service_1 = require("../import.service");
|
|
28
30
|
const csv_import_sfn_event_1 = require("./csv-import.sfn.event");
|
|
@@ -36,12 +38,10 @@ let CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = class CsvImportSfnEv
|
|
|
36
38
|
this.alarmTopicArn = this.configService.get('SNS_ALARM_TOPIC_ARN');
|
|
37
39
|
}
|
|
38
40
|
async execute(event) {
|
|
39
|
-
this.logger.log('🚀 ~ CsvImporaaatSfnEventHandler ~ execute ~ event:', event);
|
|
40
41
|
try {
|
|
41
42
|
return await this.handleStepState(event);
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
44
|
-
// await this.sendAlarm(event, error) // TODO:
|
|
45
45
|
this.logger.error('import step execution failed', error);
|
|
46
46
|
throw error;
|
|
47
47
|
}
|
|
@@ -49,7 +49,30 @@ let CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = class CsvImportSfnEv
|
|
|
49
49
|
async handleStepState(event) {
|
|
50
50
|
this.logger.debug('Processing event:::', JSON.stringify(event, null, 2));
|
|
51
51
|
if (event.context.State.Name === 'csv_loader') {
|
|
52
|
-
|
|
52
|
+
const input = event.input;
|
|
53
|
+
// 1. Get the parent job's key from the sourceId
|
|
54
|
+
const parentKey = (0, helpers_1.parseId)(input.sourceId);
|
|
55
|
+
// 2. Count the total rows in the CSV
|
|
56
|
+
this.logger.log(`Counting rows for file: ${input.key}`);
|
|
57
|
+
const totalRows = await this.countCsvRows(input);
|
|
58
|
+
this.logger.log(`Found ${totalRows} rows. Updating parent job.`);
|
|
59
|
+
// 3. Update the parent job with the total count
|
|
60
|
+
const updatedEntity = await this.importService.updateImportJob(parentKey, {
|
|
61
|
+
set: { totalRows },
|
|
62
|
+
});
|
|
63
|
+
if (updatedEntity.processedRows >= totalRows) {
|
|
64
|
+
this.logger.log(`Job ${input.sourceId} already finished. Setting final status.`);
|
|
65
|
+
const finalStatus = updatedEntity.failedRows > 0
|
|
66
|
+
? enum_1.ImportStatusEnum.COMPLETED
|
|
67
|
+
: enum_1.ImportStatusEnum.COMPLETED;
|
|
68
|
+
await this.importService.updateStatus(parentKey, finalStatus);
|
|
69
|
+
}
|
|
70
|
+
// 4. Proceed to load the first batch of rows as before
|
|
71
|
+
return this.loadCsv(input);
|
|
72
|
+
}
|
|
73
|
+
if (event.context.State.Name === 'finalize_parent_job') {
|
|
74
|
+
const finalizeEvent = event.input;
|
|
75
|
+
return this.finalizeParentJob(finalizeEvent);
|
|
53
76
|
}
|
|
54
77
|
const input = event.input;
|
|
55
78
|
const items = input.Items;
|
|
@@ -67,6 +90,7 @@ let CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = class CsvImportSfnEv
|
|
|
67
90
|
tableName: attributes.tableName,
|
|
68
91
|
tenantCode: attributes.tenantCode,
|
|
69
92
|
attributes: transformedData,
|
|
93
|
+
sourceId: attributes.sourceId,
|
|
70
94
|
};
|
|
71
95
|
createImportDtos.push(createImport);
|
|
72
96
|
}
|
|
@@ -138,6 +162,36 @@ let CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = class CsvImportSfnEv
|
|
|
138
162
|
});
|
|
139
163
|
});
|
|
140
164
|
}
|
|
165
|
+
async countCsvRows(input) {
|
|
166
|
+
const { Body: s3Stream } = await this.s3Service.client.send(new client_s3_1.GetObjectCommand({ Bucket: input.bucket, Key: input.key }));
|
|
167
|
+
if (!(s3Stream instanceof stream_1.Readable)) {
|
|
168
|
+
throw new Error('Failed to get a readable stream from S3 object.');
|
|
169
|
+
}
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
let count = 0;
|
|
172
|
+
const parser = (0, csv_parser_1.default)();
|
|
173
|
+
s3Stream
|
|
174
|
+
.pipe(parser)
|
|
175
|
+
.on('data', () => count++)
|
|
176
|
+
.on('end', () => resolve(count))
|
|
177
|
+
.on('error', (error) => reject(error));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async finalizeParentJob(event) {
|
|
181
|
+
const parentKey = (0, helpers_1.parseId)(event.sourceId);
|
|
182
|
+
const totalRows = event.MapResult.length;
|
|
183
|
+
this.logger.log(`Setting totalRows=${totalRows} for parent job ${event.sourceId}.`);
|
|
184
|
+
const updatedEntity = await this.importService.updateImportJob(parentKey, {
|
|
185
|
+
set: { totalRows },
|
|
186
|
+
});
|
|
187
|
+
if (updatedEntity.processedRows >= totalRows) {
|
|
188
|
+
this.logger.log(`Job ${event.sourceId} already finished. Setting final status.`);
|
|
189
|
+
const finalStatus = updatedEntity.failedRows > 0
|
|
190
|
+
? enum_1.ImportStatusEnum.COMPLETED
|
|
191
|
+
: enum_1.ImportStatusEnum.COMPLETED;
|
|
192
|
+
await this.importService.updateStatus(parentKey, finalStatus);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
141
195
|
};
|
|
142
196
|
exports.CsvImportSfnEventHandler = CsvImportSfnEventHandler;
|
|
143
197
|
exports.CsvImportSfnEventHandler = CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv-import.sfn.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.sfn.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,kDAAqD;AACrD,oDAMkC;AAClC,2CAA+C;AAC/C,2CAA8C;AAC9C,4DAA4B;AAC5B,mCAAiC;AAKjC,0EAAiE;AACjE,sDAAiD;AAEjD,iEAA0D;
|
|
1
|
+
{"version":3,"file":"csv-import.sfn.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.sfn.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,kDAAqD;AACrD,oDAMkC;AAClC,2CAA+C;AAC/C,2CAA8C;AAC9C,4DAA4B;AAC5B,mCAAiC;AAKjC,kCAA0C;AAC1C,wCAAoC;AACpC,0EAAiE;AACjE,sDAAiD;AAEjD,iEAA0D;AAMnD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAMnC,YACmB,aAA4B,EAE7C,iBAA0E,EACzD,aAA4B,EAC5B,SAAoB;QAJpB,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAwC;QACzD,kBAAa,GAAb,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AiB,CAC7B,KAA4C;QAE5C,MAAM,SAAS,GAAG,IAAA,iBAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACzC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAA;QAExC,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,qBAAqB,SAAS,mBAAmB,KAAK,CAAC,QAAQ,GAAG,CACnE,CAAA;QAED,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,SAAS,EAAE;YACxE,GAAG,EAAE,EAAE,SAAS,EAAE;SACnB,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,aAAa,IAAI,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,OAAO,KAAK,CAAC,QAAQ,0CAA0C,CAChE,CAAA;YACD,MAAM,WAAW,GACf,aAAa,CAAC,UAAU,GAAG,CAAC;gBAC1B,CAAC,CAAC,uBAAgB,CAAC,SAAS;gBAC5B,CAAC,CAAC,uBAAgB,CAAC,SAAS,CAAA;YAEhC,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAC/D,CAAC;IACH,CAAC;CACF,CAAA;AA7NY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAY,EAAC,wCAAiB,CAAC;IAS3B,WAAA,IAAA,eAAM,EAAC,8CAAmB,CAAC,CAAA;qCADI,8BAAa;QAET,GAAG;QACP,sBAAa;QACjB,gBAAS;GAX5B,wBAAwB,CA6NpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IEvent } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { SQSMessageAttributes, SQSRecord, SQSRecordAttributes } from 'aws-lambda';
|
|
3
|
+
export declare class ImportStatusQueueEvent implements IEvent, SQSRecord {
|
|
4
|
+
source: string;
|
|
5
|
+
messageId: string;
|
|
6
|
+
receiptHandle: string;
|
|
7
|
+
body: string;
|
|
8
|
+
attributes: SQSRecordAttributes;
|
|
9
|
+
messageAttributes: SQSMessageAttributes;
|
|
10
|
+
md5OfBody: string;
|
|
11
|
+
eventSource: string;
|
|
12
|
+
eventSourceARN: string;
|
|
13
|
+
awsRegion: string;
|
|
14
|
+
fromSqsRecord(record: SQSRecord): ImportStatusQueueEvent;
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IEventHandler, StepFunctionService } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { ImportService } from '../import.service';
|
|
3
|
+
import { ImportStatusQueueEvent } from './import-status.queue.event';
|
|
4
|
+
export declare class ImportStatusHandler implements IEventHandler<ImportStatusQueueEvent> {
|
|
5
|
+
private readonly importService;
|
|
6
|
+
private readonly sfnService;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(importService: ImportService, sfnService: StepFunctionService);
|
|
9
|
+
execute(event: ImportStatusQueueEvent): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Sends a success signal to a waiting Step Function task.
|
|
12
|
+
* @param taskToken The unique token of the paused task.
|
|
13
|
+
* @param output The JSON output to send back to the state machine.
|
|
14
|
+
*/
|
|
15
|
+
sendTaskSuccess(taskToken: string, output: any): Promise<import("@aws-sdk/client-sfn").SendTaskSuccessCommandOutput>;
|
|
16
|
+
}
|