@mbc-cqrs-serverless/import 0.1.74-beta.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/LICENSE.txt +7 -0
- package/README.md +55 -0
- package/dist/constant/index.d.ts +1 -0
- package/dist/constant/index.js +5 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/dto/create-csv-import.dto.d.ts +8 -0
- package/dist/dto/create-csv-import.dto.js +43 -0
- package/dist/dto/create-csv-import.dto.js.map +1 -0
- package/dist/dto/create-import.dto.d.ts +6 -0
- package/dist/dto/create-import.dto.js +34 -0
- package/dist/dto/create-import.dto.js.map +1 -0
- package/dist/dto/csv-import-row.interface.d.ts +7 -0
- package/dist/dto/csv-import-row.interface.js +4 -0
- package/dist/dto/csv-import-row.interface.js.map +1 -0
- package/dist/dto/index.d.ts +3 -0
- package/dist/dto/index.js +20 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/entity/import-entity-list.d.ts +6 -0
- package/dist/entity/import-entity-list.js +12 -0
- package/dist/entity/import-entity-list.js.map +1 -0
- package/dist/entity/import-entity.d.ts +20 -0
- package/dist/entity/import-entity.js +24 -0
- package/dist/entity/import-entity.js.map +1 -0
- package/dist/entity/index.d.ts +2 -0
- package/dist/entity/index.js +19 -0
- package/dist/entity/index.js.map +1 -0
- package/dist/enum/comparison-status.enum.d.ts +8 -0
- package/dist/enum/comparison-status.enum.js +13 -0
- package/dist/enum/comparison-status.enum.js.map +1 -0
- package/dist/enum/import-status.enum.d.ts +7 -0
- package/dist/enum/import-status.enum.js +12 -0
- package/dist/enum/import-status.enum.js.map +1 -0
- package/dist/enum/index.d.ts +3 -0
- package/dist/enum/index.js +20 -0
- package/dist/enum/index.js.map +1 -0
- package/dist/enum/processing-mode.enum.d.ts +4 -0
- package/dist/enum/processing-mode.enum.js +9 -0
- package/dist/enum/processing-mode.enum.js.map +1 -0
- package/dist/event/csv-import.queue.event.handler.d.ts +15 -0
- package/dist/event/csv-import.queue.event.handler.js +75 -0
- package/dist/event/csv-import.queue.event.handler.js.map +1 -0
- package/dist/event/csv-import.sfn.event.d.ts +9 -0
- package/dist/event/csv-import.sfn.event.handler.d.ts +17 -0
- package/dist/event/csv-import.sfn.event.handler.js +151 -0
- package/dist/event/csv-import.sfn.event.handler.js.map +1 -0
- package/dist/event/csv-import.sfn.event.js +42 -0
- package/dist/event/csv-import.sfn.event.js.map +1 -0
- package/dist/event/import.event.d.ts +22 -0
- package/dist/event/import.event.handler.d.ts +10 -0
- package/dist/event/import.event.handler.js +38 -0
- package/dist/event/import.event.handler.js.map +1 -0
- package/dist/event/import.event.js +34 -0
- package/dist/event/import.event.js.map +1 -0
- package/dist/event/import.queue.event.d.ts +18 -0
- package/dist/event/import.queue.event.handler.d.ts +26 -0
- package/dist/event/import.queue.event.handler.js +121 -0
- package/dist/event/import.queue.event.handler.js.map +1 -0
- package/dist/event/import.queue.event.js +20 -0
- package/dist/event/import.queue.event.js.map +1 -0
- package/dist/event/index.d.ts +7 -0
- package/dist/event/index.js +24 -0
- package/dist/event/index.js.map +1 -0
- package/dist/import.controller.d.ts +22 -0
- package/dist/import.controller.js +99 -0
- package/dist/import.controller.js.map +1 -0
- package/dist/import.module-definition.d.ts +31 -0
- package/dist/import.module-definition.js +20 -0
- package/dist/import.module-definition.js.map +1 -0
- package/dist/import.module.d.ts +11 -0
- package/dist/import.module.js +69 -0
- package/dist/import.module.js.map +1 -0
- package/dist/import.service.d.ts +59 -0
- package/dist/import.service.js +250 -0
- package/dist/import.service.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interface/csv-mapping-strategy.interface.d.ts +14 -0
- package/dist/interface/csv-mapping-strategy.interface.js +3 -0
- package/dist/interface/csv-mapping-strategy.interface.js.map +1 -0
- package/dist/interface/import-entity-profile.interface.d.ts +23 -0
- package/dist/interface/import-entity-profile.interface.js +3 -0
- package/dist/interface/import-entity-profile.interface.js.map +1 -0
- package/dist/interface/import-strategy.interface.d.ts +27 -0
- package/dist/interface/import-strategy.interface.js +55 -0
- package/dist/interface/import-strategy.interface.js.map +1 -0
- package/dist/interface/index.d.ts +4 -0
- package/dist/interface/index.js +21 -0
- package/dist/interface/index.js.map +1 -0
- package/dist/interface/processing-strategy.interface.d.ts +57 -0
- package/dist/interface/processing-strategy.interface.js +10 -0
- package/dist/interface/processing-strategy.interface.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,99 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var ImportController_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ImportController = void 0;
|
|
17
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
20
|
+
const create_csv_import_dto_1 = require("./dto/create-csv-import.dto");
|
|
21
|
+
const create_import_dto_1 = require("./dto/create-import.dto");
|
|
22
|
+
const import_service_1 = require("./import.service");
|
|
23
|
+
let ImportController = ImportController_1 = class ImportController {
|
|
24
|
+
constructor(importService) {
|
|
25
|
+
this.importService = importService;
|
|
26
|
+
this.logger = new common_1.Logger(ImportController_1.name);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Endpoint for importing a single data record.
|
|
30
|
+
* This is typically used for real-time or low-volume data synchronization.
|
|
31
|
+
* The actual processing is asynchronous; this endpoint only validates the input
|
|
32
|
+
* and queues the import task.
|
|
33
|
+
*/
|
|
34
|
+
async createImport(invokeContext, createImportDto) {
|
|
35
|
+
this.logger.log(`Received single import request for table: ${createImportDto.tableName}`);
|
|
36
|
+
return this.importService.createWithApi(createImportDto, { invokeContext });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Endpoint for initiating a CSV file import.
|
|
40
|
+
* This endpoint accepts the location of a CSV file in S3 and allows the client
|
|
41
|
+
* to specify the processing strategy ('DIRECT' for small files, 'STEP_FUNCTION' for large files).
|
|
42
|
+
*/
|
|
43
|
+
async createCsvImport(invokeContext, createCsvImportDto) {
|
|
44
|
+
this.logger.log(`Received CSV import request for key: ${createCsvImportDto.key} with processing mode: ${createCsvImportDto.processingMode}`);
|
|
45
|
+
// The service contains the routing logic to either process directly
|
|
46
|
+
// or create the master job for the Step Function.
|
|
47
|
+
return this.importService.handleCsvImport(createCsvImportDto, {
|
|
48
|
+
invokeContext,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.ImportController = ImportController;
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, common_1.Post)(),
|
|
55
|
+
(0, swagger_1.ApiOperation)({
|
|
56
|
+
summary: 'Create a single import',
|
|
57
|
+
description: 'Accepts a single data record, validates it using the configured ImportStrategy, and queues it for asynchronous processing.',
|
|
58
|
+
}),
|
|
59
|
+
(0, swagger_1.ApiBody)({ type: create_import_dto_1.CreateImportDto }),
|
|
60
|
+
(0, swagger_1.ApiResponse)({
|
|
61
|
+
status: 202,
|
|
62
|
+
description: 'The import task has been accepted and queued for processing.',
|
|
63
|
+
}),
|
|
64
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.ACCEPTED),
|
|
65
|
+
(0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true, whitelist: true })),
|
|
66
|
+
__param(0, (0, core_1.INVOKE_CONTEXT)()),
|
|
67
|
+
__param(1, (0, common_1.Body)()),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [Object, create_import_dto_1.CreateImportDto]),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], ImportController.prototype, "createImport", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, common_1.Post)('csv'),
|
|
74
|
+
(0, swagger_1.ApiOperation)({
|
|
75
|
+
summary: 'Initiate a CSV file import',
|
|
76
|
+
description: 'Accepts the S3 location of a CSV file and an execution strategy. It will either process the file directly or trigger a Step Function workflow.',
|
|
77
|
+
}),
|
|
78
|
+
(0, swagger_1.ApiBody)({ type: create_csv_import_dto_1.CreateCsvImportDto }),
|
|
79
|
+
(0, swagger_1.ApiResponse)({
|
|
80
|
+
status: 200,
|
|
81
|
+
description: 'For DIRECT mode, returns the created import entities. For STEP_FUNCTION mode, returns the master job entity.',
|
|
82
|
+
}),
|
|
83
|
+
(0, swagger_1.ApiResponse)({
|
|
84
|
+
status: 202,
|
|
85
|
+
description: 'The import task has been accepted and queued for processing (for STEP_FUNCTION mode).',
|
|
86
|
+
}),
|
|
87
|
+
(0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true, whitelist: true })),
|
|
88
|
+
__param(0, (0, core_1.INVOKE_CONTEXT)()),
|
|
89
|
+
__param(1, (0, common_1.Body)()),
|
|
90
|
+
__metadata("design:type", Function),
|
|
91
|
+
__metadata("design:paramtypes", [Object, create_csv_import_dto_1.CreateCsvImportDto]),
|
|
92
|
+
__metadata("design:returntype", Promise)
|
|
93
|
+
], ImportController.prototype, "createCsvImport", null);
|
|
94
|
+
exports.ImportController = ImportController = ImportController_1 = __decorate([
|
|
95
|
+
(0, swagger_1.ApiTags)('Imports'),
|
|
96
|
+
(0, common_1.Controller)('imports'),
|
|
97
|
+
__metadata("design:paramtypes", [import_service_1.ImportService])
|
|
98
|
+
], ImportController);
|
|
99
|
+
//# sourceMappingURL=import.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.controller.js","sourceRoot":"","sources":["../src/import.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAmE;AACnE,2CASuB;AACvB,6CAA6E;AAE7E,uEAAgE;AAChE,+DAAyD;AACzD,qDAAgD;AAIzC,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAG3B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAFxC,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAA;IAEC,CAAC;IAE7D;;;;;OAKG;IAcG,AAAN,KAAK,CAAC,YAAY,CACE,aAAsB,EAChC,eAAgC;QAExC,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,6CAA6C,eAAe,CAAC,SAAS,EAAE,CACzE,CAAA;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,eAAe,EAAE,EAAE,aAAa,EAAE,CAAC,CAAA;IAC7E,CAAC;IAED;;;;OAIG;IAmBG,AAAN,KAAK,CAAC,eAAe,CACD,aAAsB,EAChC,kBAAsC;QAE9C,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,wCAAwC,kBAAkB,CAAC,GAAG,0BAA0B,kBAAkB,CAAC,cAAc,EAAE,CAC5H,CAAA;QACD,oEAAoE;QACpE,kDAAkD;QAClD,OAAO,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,kBAAkB,EAAE;YAC5D,aAAa;SACd,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAtEY,4CAAgB;AAwBrB;IAbL,IAAA,aAA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-0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Defines the configuration for the dynamic ImportModule using ConfigurableModuleBuilder.
|
|
3
|
+
*/
|
|
4
|
+
import { ModuleMetadata } from '@nestjs/common';
|
|
5
|
+
import { ImportEntityProfile } from './interface';
|
|
6
|
+
export declare const IMPORT_STRATEGY_MAP = "ImportStrategyMapInjectToken";
|
|
7
|
+
export declare const PROCESS_STRATEGY_MAP = "ProcessStrategyMapInjectToken";
|
|
8
|
+
/**
|
|
9
|
+
* The main options object for the ImportModule's `register` method.
|
|
10
|
+
*/
|
|
11
|
+
export interface ImportModuleOptions {
|
|
12
|
+
/**
|
|
13
|
+
* (Required) An array of profiles, where each profile defines the complete
|
|
14
|
+
* import configuration for a specific entity.
|
|
15
|
+
*/
|
|
16
|
+
profiles: ImportEntityProfile[];
|
|
17
|
+
/**
|
|
18
|
+
* (Optional) An array of modules that export the providers needed by the
|
|
19
|
+
* classes in the profiles
|
|
20
|
+
*/
|
|
21
|
+
imports?: ModuleMetadata['imports'];
|
|
22
|
+
/**
|
|
23
|
+
* (Optional) Enables the built-in `/import` and `/import/csv` endpoints.
|
|
24
|
+
*/
|
|
25
|
+
enableController?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ImportModuleOptions, "register", "create", {
|
|
28
|
+
profiles: ImportEntityProfile[];
|
|
29
|
+
}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ImportModuleOptions & Partial<{
|
|
30
|
+
profiles: ImportEntityProfile[];
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.PROCESS_STRATEGY_MAP = exports.IMPORT_STRATEGY_MAP = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @description Defines the configuration for the dynamic ImportModule using ConfigurableModuleBuilder.
|
|
7
|
+
*/
|
|
8
|
+
const common_1 = require("@nestjs/common");
|
|
9
|
+
// --- Injection Tokens for our internal provider maps ---
|
|
10
|
+
exports.IMPORT_STRATEGY_MAP = 'ImportStrategyMapInjectToken';
|
|
11
|
+
exports.PROCESS_STRATEGY_MAP = 'ProcessStrategyMapInjectToken';
|
|
12
|
+
// --- Configurable Module Setup ---
|
|
13
|
+
_a = new common_1.ConfigurableModuleBuilder()
|
|
14
|
+
// The module will always be configured with the profiles array.
|
|
15
|
+
.setExtras({ profiles: [] }, (definition, extras) => ({
|
|
16
|
+
...definition,
|
|
17
|
+
profiles: extras.profiles,
|
|
18
|
+
}))
|
|
19
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE;
|
|
20
|
+
//# sourceMappingURL=import.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.module-definition.js","sourceRoot":"","sources":["../src/import.module-definition.ts"],"names":[],"mappings":";;;;AAAA;;GAEG;AACH,2CAA0E;AAI1E,0DAA0D;AAC7C,QAAA,mBAAmB,GAAG,8BAA8B,CAAA;AACpD,QAAA,oBAAoB,GAAG,+BAA+B,CAAA;AAwBnE,oCAAoC;AACvB,KACX,IAAI,kCAAyB,EAAuB;IAClD,gEAAgE;KAC/D,SAAS,CACR,EAAE,QAAQ,EAAE,EAAE,EAAE,EAChB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B,CAAC,CACH;KACA,KAAK,EAAE,EAVG,+BAAuB,+BAAE,4BAAoB,4BAAE,oBAAY,mBAU9D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ConfigurableModuleClass, OPTIONS_TYPE } from './import.module-definition';
|
|
3
|
+
export declare class ImportModule extends ConfigurableModuleClass {
|
|
4
|
+
static register(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
5
|
+
/**
|
|
6
|
+
* A private helper to create a factory provider for a strategy map.
|
|
7
|
+
* This factory injects all necessary strategy instances and maps them
|
|
8
|
+
* to their corresponding tableName from the profiles.
|
|
9
|
+
*/
|
|
10
|
+
private static createStrategyMapFactory;
|
|
11
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ImportModule = void 0;
|
|
10
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const csv_import_queue_event_handler_1 = require("./event/csv-import.queue.event.handler");
|
|
13
|
+
const csv_import_sfn_event_handler_1 = require("./event/csv-import.sfn.event.handler");
|
|
14
|
+
const import_event_handler_1 = require("./event/import.event.handler");
|
|
15
|
+
const import_queue_event_handler_1 = require("./event/import.queue.event.handler");
|
|
16
|
+
const import_controller_1 = require("./import.controller");
|
|
17
|
+
const import_module_definition_1 = require("./import.module-definition");
|
|
18
|
+
const import_service_1 = require("./import.service");
|
|
19
|
+
let ImportModule = class ImportModule extends import_module_definition_1.ConfigurableModuleClass {
|
|
20
|
+
static register(options) {
|
|
21
|
+
const module = super.register(options);
|
|
22
|
+
const { enableController, profiles, imports } = options;
|
|
23
|
+
module.imports = [...(module.imports || []), ...(imports || [])];
|
|
24
|
+
const dynamicProviders = [
|
|
25
|
+
this.createStrategyMapFactory(import_module_definition_1.IMPORT_STRATEGY_MAP, profiles, (p) => p.importStrategy),
|
|
26
|
+
this.createStrategyMapFactory(import_module_definition_1.PROCESS_STRATEGY_MAP, profiles, (p) => p.processStrategy),
|
|
27
|
+
];
|
|
28
|
+
module.providers = [...(module.providers || []), ...dynamicProviders];
|
|
29
|
+
if (enableController) {
|
|
30
|
+
module.controllers = [...(module.controllers || []), import_controller_1.ImportController];
|
|
31
|
+
}
|
|
32
|
+
return module;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A private helper to create a factory provider for a strategy map.
|
|
36
|
+
* This factory injects all necessary strategy instances and maps them
|
|
37
|
+
* to their corresponding tableName from the profiles.
|
|
38
|
+
*/
|
|
39
|
+
static createStrategyMapFactory(provide, profiles, classExtractor) {
|
|
40
|
+
// Extract the class types to be used as injection tokens
|
|
41
|
+
const injectionTokens = profiles.map(classExtractor);
|
|
42
|
+
return {
|
|
43
|
+
provide,
|
|
44
|
+
useFactory: (...instances) => {
|
|
45
|
+
const map = new Map();
|
|
46
|
+
instances.forEach((instance, index) => {
|
|
47
|
+
map.set(profiles[index].tableName, instance);
|
|
48
|
+
});
|
|
49
|
+
return map;
|
|
50
|
+
},
|
|
51
|
+
inject: injectionTokens,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.ImportModule = ImportModule;
|
|
56
|
+
exports.ImportModule = ImportModule = __decorate([
|
|
57
|
+
(0, common_1.Module)({
|
|
58
|
+
imports: [core_1.DataStoreModule, core_1.QueueModule],
|
|
59
|
+
providers: [
|
|
60
|
+
import_service_1.ImportService,
|
|
61
|
+
import_event_handler_1.ImportEventHandler,
|
|
62
|
+
import_queue_event_handler_1.ImportQueueEventHandler,
|
|
63
|
+
csv_import_queue_event_handler_1.CsvImportQueueEventHandler,
|
|
64
|
+
csv_import_sfn_event_handler_1.CsvImportSfnEventHandler,
|
|
65
|
+
],
|
|
66
|
+
exports: [import_service_1.ImportService],
|
|
67
|
+
})
|
|
68
|
+
], ImportModule);
|
|
69
|
+
//# sourceMappingURL=import.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.module.js","sourceRoot":"","sources":["../src/import.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAwE;AACxE,2CAAsE;AAEtE,2FAAmF;AACnF,uFAA+E;AAC/E,uEAAiE;AACjE,mFAA4E;AAC5E,2DAAsD;AACtD,yEAKmC;AACnC,qDAAgD;AAgBzC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,kDAAuB;IACvD,MAAM,CAAC,QAAQ,CAAC,OAA4B;QAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAEtC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;QAEvD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;QAEhE,MAAM,gBAAgB,GAAe;YACnC,IAAI,CAAC,wBAAwB,CAC3B,8CAAmB,EACnB,QAAQ,EACR,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CACxB;YACD,IAAI,CAAC,wBAAwB,CAC3B,+CAAoB,EACpB,QAAQ,EACR,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CACzB;SACF,CAAA;QAED,MAAM,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAA;QAErE,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,oCAAgB,CAAC,CAAA;QACxE,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,wBAAwB,CACrC,OAAe,EACf,QAA+B,EAC/B,cAEiE;QAEjE,yDAAyD;QACzD,MAAM,eAAe,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAEpD,OAAO;YACL,OAAO;YACP,UAAU,EAAE,CACV,GAAG,SAAqE,EACxE,EAAE;gBACF,MAAM,GAAG,GAAG,IAAI,GAAG,EAGhB,CAAA;gBACH,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;oBACpC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;gBAC9C,CAAC,CAAC,CAAA;gBACF,OAAO,GAAG,CAAA;YACZ,CAAC;YACD,MAAM,EAAE,eAAe;SACxB,CAAA;IACH,CAAC;CACF,CAAA;AA9DY,oCAAY;uBAAZ,YAAY;IAXxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,EAAE,kBAAW,CAAC;QACvC,SAAS,EAAE;YACT,8BAAa;YACb,yCAAkB;YAClB,oDAAuB;YACvB,2DAA0B;YAC1B,uDAAwB;SACzB;QACD,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CA8DxB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DetailKey, DynamoDbService, ICommandOptions, IInvoke, S3Service, SnsService } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { CreateCsvImportDto } from './dto/create-csv-import.dto';
|
|
4
|
+
import { CreateImportDto } from './dto/create-import.dto';
|
|
5
|
+
import { ImportEntity } from './entity';
|
|
6
|
+
import { ImportQueueEvent } from './event';
|
|
7
|
+
import { IImportStrategy } from './interface';
|
|
8
|
+
export declare class ImportService {
|
|
9
|
+
private readonly dynamoDbService;
|
|
10
|
+
private readonly snsService;
|
|
11
|
+
private readonly config;
|
|
12
|
+
private readonly s3Service;
|
|
13
|
+
private readonly importStrategyMap;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private readonly tableName;
|
|
16
|
+
private readonly alarmTopicArn;
|
|
17
|
+
constructor(dynamoDbService: DynamoDbService, snsService: SnsService, config: ConfigService, s3Service: S3Service, importStrategyMap: Map<string, IImportStrategy<any, any>>);
|
|
18
|
+
/**
|
|
19
|
+
* Handles a single import request from the API.
|
|
20
|
+
* It uses the appropriate ImportStrategy to transform and validate the data
|
|
21
|
+
* before creating a record in the temporary import table.
|
|
22
|
+
*/
|
|
23
|
+
createWithApi(dto: CreateImportDto, options: ICommandOptions): Promise<ImportEntity>;
|
|
24
|
+
/**
|
|
25
|
+
* Main router for handling CSV imports. It delegates to the correct
|
|
26
|
+
* processing method based on the specified execution strategy.
|
|
27
|
+
*/
|
|
28
|
+
handleCsvImport(dto: CreateCsvImportDto, options: ICommandOptions): Promise<ImportEntity[] | ImportEntity>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a master job record for a CSV import that will be orchestrated
|
|
31
|
+
* by a Step Function.
|
|
32
|
+
*/
|
|
33
|
+
createCsvJob(dto: CreateCsvImportDto, options: {
|
|
34
|
+
invokeContext: IInvoke;
|
|
35
|
+
}): Promise<ImportEntity>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a import job record for a single json import
|
|
38
|
+
*/
|
|
39
|
+
createImport(dto: CreateImportDto, options: ICommandOptions): Promise<ImportEntity>;
|
|
40
|
+
/**
|
|
41
|
+
* Handles the 'DIRECT' execution strategy by fetching the CSV from S3
|
|
42
|
+
* and processing its stream immediately.
|
|
43
|
+
*/
|
|
44
|
+
private _processCsvDirectly;
|
|
45
|
+
/**
|
|
46
|
+
* Centralized logic to process a CSV stream. It reads each row, uses the
|
|
47
|
+
* appropriate ImportStrategy to transform and validate, and creates a
|
|
48
|
+
* temporary import record for each valid row.
|
|
49
|
+
*/
|
|
50
|
+
private _processCsvStream;
|
|
51
|
+
updateStatus(key: DetailKey, status: string, payload?: {
|
|
52
|
+
result?: any;
|
|
53
|
+
error?: any;
|
|
54
|
+
}, attributes?: {
|
|
55
|
+
result?: any;
|
|
56
|
+
error?: any;
|
|
57
|
+
}, notifyId?: string): Promise<void>;
|
|
58
|
+
publishAlarm(event: ImportQueueEvent, errorDetails: any): Promise<void>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var ImportService_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ImportService = void 0;
|
|
20
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
21
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const config_1 = require("@nestjs/config");
|
|
24
|
+
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
25
|
+
const stream_1 = require("stream");
|
|
26
|
+
const ulid_1 = require("ulid");
|
|
27
|
+
const entity_1 = require("./entity");
|
|
28
|
+
const enum_1 = require("./enum");
|
|
29
|
+
const import_module_definition_1 = require("./import.module-definition");
|
|
30
|
+
let ImportService = ImportService_1 = class ImportService {
|
|
31
|
+
constructor(dynamoDbService, snsService, config, s3Service, importStrategyMap) {
|
|
32
|
+
this.dynamoDbService = dynamoDbService;
|
|
33
|
+
this.snsService = snsService;
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.s3Service = s3Service;
|
|
36
|
+
this.importStrategyMap = importStrategyMap;
|
|
37
|
+
this.logger = new common_1.Logger(ImportService_1.name);
|
|
38
|
+
this.tableName = dynamoDbService.getTableName('import_tmp');
|
|
39
|
+
this.alarmTopicArn = this.config.get('SNS_ALARM_TOPIC_ARN');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Handles a single import request from the API.
|
|
43
|
+
* It uses the appropriate ImportStrategy to transform and validate the data
|
|
44
|
+
* before creating a record in the temporary import table.
|
|
45
|
+
*/
|
|
46
|
+
async createWithApi(dto, options) {
|
|
47
|
+
const { tableName, attributes } = dto;
|
|
48
|
+
const strategy = this.importStrategyMap.get(tableName);
|
|
49
|
+
if (!strategy) {
|
|
50
|
+
throw new common_1.BadRequestException(`No import strategy found for table: ${tableName}`);
|
|
51
|
+
}
|
|
52
|
+
const transformedData = await strategy.transform(attributes);
|
|
53
|
+
await strategy.validate(transformedData);
|
|
54
|
+
return this.createImport({ ...dto, attributes: transformedData }, options);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Main router for handling CSV imports. It delegates to the correct
|
|
58
|
+
* processing method based on the specified execution strategy.
|
|
59
|
+
*/
|
|
60
|
+
async handleCsvImport(dto, options) {
|
|
61
|
+
if (dto.processingMode === 'DIRECT') {
|
|
62
|
+
return this._processCsvDirectly(dto, options);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return this.createCsvJob(dto, options);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a master job record for a CSV import that will be orchestrated
|
|
70
|
+
* by a Step Function.
|
|
71
|
+
*/
|
|
72
|
+
async createCsvJob(dto, options) {
|
|
73
|
+
const sourceIp = options.invokeContext?.event?.requestContext?.http?.sourceIp;
|
|
74
|
+
const userContext = (0, core_1.getUserContext)(options.invokeContext);
|
|
75
|
+
const taskCode = (0, ulid_1.ulid)();
|
|
76
|
+
const pk = `CSV_IMPORT${core_1.KEY_SEPARATOR}${dto.tenantCode}`;
|
|
77
|
+
const sk = `${dto.tableName}#${taskCode}`;
|
|
78
|
+
const item = new entity_1.ImportEntity({
|
|
79
|
+
id: `${pk}#${sk}`,
|
|
80
|
+
pk,
|
|
81
|
+
sk,
|
|
82
|
+
version: 0,
|
|
83
|
+
code: taskCode,
|
|
84
|
+
tenantCode: dto.tenantCode,
|
|
85
|
+
type: 'CSV_MASTER_JOB',
|
|
86
|
+
name: `CSV Import: ${dto.key.split('/').pop()}`,
|
|
87
|
+
status: enum_1.ImportStatusEnum.CREATED,
|
|
88
|
+
attributes: dto,
|
|
89
|
+
requestId: options.invokeContext?.context?.awsRequestId,
|
|
90
|
+
createdAt: new Date(),
|
|
91
|
+
updatedAt: new Date(),
|
|
92
|
+
createdBy: userContext.userId,
|
|
93
|
+
updatedBy: userContext.userId,
|
|
94
|
+
createdIp: sourceIp,
|
|
95
|
+
updatedIp: sourceIp,
|
|
96
|
+
});
|
|
97
|
+
await this.dynamoDbService.putItem(this.tableName, item);
|
|
98
|
+
return item;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a import job record for a single json import
|
|
102
|
+
*/
|
|
103
|
+
async createImport(dto, options) {
|
|
104
|
+
const sourceIp = options.invokeContext?.event?.requestContext?.http?.sourceIp;
|
|
105
|
+
const userContext = (0, core_1.getUserContext)(options.invokeContext);
|
|
106
|
+
const taskCode = (0, ulid_1.ulid)();
|
|
107
|
+
const pk = `IMPORT${core_1.KEY_SEPARATOR}${dto.tenantCode}`;
|
|
108
|
+
const sk = `${dto.tableName}#${taskCode}`;
|
|
109
|
+
const item = {
|
|
110
|
+
id: `${pk}${core_1.KEY_SEPARATOR}${sk}`,
|
|
111
|
+
pk,
|
|
112
|
+
sk,
|
|
113
|
+
version: 0,
|
|
114
|
+
code: taskCode,
|
|
115
|
+
tenantCode: dto.tenantCode,
|
|
116
|
+
type: dto.tableName,
|
|
117
|
+
name: dto.name || dto.tableName,
|
|
118
|
+
status: enum_1.ImportStatusEnum.CREATED,
|
|
119
|
+
attributes: dto.attributes,
|
|
120
|
+
requestId: options.invokeContext?.context?.awsRequestId,
|
|
121
|
+
createdAt: new Date(),
|
|
122
|
+
updatedAt: new Date(),
|
|
123
|
+
createdBy: userContext.userId,
|
|
124
|
+
updatedBy: userContext.userId,
|
|
125
|
+
createdIp: sourceIp,
|
|
126
|
+
updatedIp: sourceIp,
|
|
127
|
+
};
|
|
128
|
+
await this.dynamoDbService.putItem(this.tableName, item);
|
|
129
|
+
return new entity_1.ImportEntity(item);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Handles the 'DIRECT' execution strategy by fetching the CSV from S3
|
|
133
|
+
* and processing its stream immediately.
|
|
134
|
+
*/
|
|
135
|
+
async _processCsvDirectly(dto, options) {
|
|
136
|
+
this.logger.log(`Starting DIRECT CSV processing for key: ${dto.key}`);
|
|
137
|
+
// 1. Fetch the S3 object stream
|
|
138
|
+
const { Body: s3Stream } = await this.s3Service.client.send(new client_s3_1.GetObjectCommand({
|
|
139
|
+
Bucket: dto.bucket,
|
|
140
|
+
Key: dto.key,
|
|
141
|
+
}));
|
|
142
|
+
if (!(s3Stream instanceof stream_1.Readable)) {
|
|
143
|
+
throw new Error('Failed to get a readable stream from S3 object.');
|
|
144
|
+
}
|
|
145
|
+
// 2. Pass the stream to the centralized processor
|
|
146
|
+
return this._processCsvStream(s3Stream, dto, options);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Centralized logic to process a CSV stream. It reads each row, uses the
|
|
150
|
+
* appropriate ImportStrategy to transform and validate, and creates a
|
|
151
|
+
* temporary import record for each valid row.
|
|
152
|
+
*/
|
|
153
|
+
async _processCsvStream(stream, attributes, options) {
|
|
154
|
+
const strategy = this.importStrategyMap.get(attributes.tableName);
|
|
155
|
+
if (!strategy) {
|
|
156
|
+
throw new Error(`No import strategy found for table: ${attributes.tableName}`);
|
|
157
|
+
}
|
|
158
|
+
const processingPromises = [];
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
const parser = (0, csv_parser_1.default)({
|
|
161
|
+
mapHeaders: ({ header }) => header.trim(),
|
|
162
|
+
mapValues: ({ value }) => value.trim(),
|
|
163
|
+
});
|
|
164
|
+
stream
|
|
165
|
+
.pipe(parser)
|
|
166
|
+
.on('data', (row) => {
|
|
167
|
+
const processRow = (async () => {
|
|
168
|
+
try {
|
|
169
|
+
const transformedData = await strategy.transform(row);
|
|
170
|
+
await strategy.validate(transformedData);
|
|
171
|
+
const createImportDto = {
|
|
172
|
+
tableName: attributes.tableName,
|
|
173
|
+
tenantCode: attributes.tenantCode,
|
|
174
|
+
attributes: transformedData,
|
|
175
|
+
};
|
|
176
|
+
// Return the created entity
|
|
177
|
+
return await this.createImport(createImportDto, options);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
this.logger.warn(`Skipping CSV row due to error: ${error instanceof Error ? error.message : String(error)}`, { row });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
})();
|
|
184
|
+
processingPromises.push(processRow);
|
|
185
|
+
})
|
|
186
|
+
.on('end', async () => {
|
|
187
|
+
// Wait for all row processing to complete before resolving
|
|
188
|
+
const results = await Promise.all(processingPromises);
|
|
189
|
+
const successfulImports = results.filter((result) => !!result);
|
|
190
|
+
this.logger.log(`Finished CSV stream. Created ${successfulImports.length} import records.`);
|
|
191
|
+
resolve(successfulImports);
|
|
192
|
+
})
|
|
193
|
+
.on('error', (error) => {
|
|
194
|
+
this.logger.error('Error parsing CSV stream:', error);
|
|
195
|
+
reject(error);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async updateStatus(key, status, payload, attributes, notifyId) {
|
|
200
|
+
await this.dynamoDbService.updateItem(this.tableName, key, {
|
|
201
|
+
set: {
|
|
202
|
+
status,
|
|
203
|
+
attributes,
|
|
204
|
+
result: payload?.result || payload?.error,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
// notification via SNS
|
|
208
|
+
await this.snsService.publish({
|
|
209
|
+
action: 'import-status',
|
|
210
|
+
...key,
|
|
211
|
+
table: this.tableName,
|
|
212
|
+
id: notifyId || `${key.pk}#${key.sk}`,
|
|
213
|
+
tenantCode: key.pk.substring(key.pk.indexOf('#') + 1),
|
|
214
|
+
content: {
|
|
215
|
+
status,
|
|
216
|
+
attributes,
|
|
217
|
+
result: payload?.result || payload?.error,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async publishAlarm(event, errorDetails) {
|
|
222
|
+
this.logger.debug('event', event);
|
|
223
|
+
const importKey = event.importEvent.importKey;
|
|
224
|
+
const tenantCode = importKey.pk.substring(importKey.pk.indexOf(core_1.KEY_SEPARATOR) + 1);
|
|
225
|
+
const alarm = {
|
|
226
|
+
action: 'sfn-alarm',
|
|
227
|
+
id: `${importKey.pk}#${importKey.sk}`,
|
|
228
|
+
table: this.tableName,
|
|
229
|
+
pk: importKey.pk,
|
|
230
|
+
sk: importKey.sk,
|
|
231
|
+
tenantCode,
|
|
232
|
+
content: {
|
|
233
|
+
errorMessage: errorDetails,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
this.logger.error('alarm:::', alarm);
|
|
237
|
+
await this.snsService.publish(alarm, this.alarmTopicArn);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
exports.ImportService = ImportService;
|
|
241
|
+
exports.ImportService = ImportService = ImportService_1 = __decorate([
|
|
242
|
+
(0, common_1.Injectable)(),
|
|
243
|
+
__param(4, (0, common_1.Inject)(import_module_definition_1.IMPORT_STRATEGY_MAP)),
|
|
244
|
+
__metadata("design:paramtypes", [core_1.DynamoDbService,
|
|
245
|
+
core_1.SnsService,
|
|
246
|
+
config_1.ConfigService,
|
|
247
|
+
core_1.S3Service,
|
|
248
|
+
Map])
|
|
249
|
+
], ImportService);
|
|
250
|
+
//# sourceMappingURL=import.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.service.js","sourceRoot":"","sources":["../src/import.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,kDAAqD;AACrD,oDAUkC;AAClC,2CAAgF;AAChF,2CAA8C;AAC9C,4DAA4B;AAC5B,mCAAiC;AACjC,+BAA2B;AAI3B,qCAAuC;AACvC,iCAAyC;AAEzC,yEAAgE;AAIzD,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAKxB,YACmB,eAAgC,EAChC,UAAsB,EAEtB,MAAqB,EACrB,SAAoB,EAErC,iBAA0E;QANzD,oBAAe,GAAf,eAAe,CAAiB;QAChC,eAAU,GAAV,UAAU,CAAY;QAEtB,WAAM,GAAN,MAAM,CAAe;QACrB,cAAS,GAAT,SAAS,CAAW;QAEpB,sBAAiB,GAAjB,iBAAiB,CAAwC;QAX3D,WAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAA;QAatD,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,YAAY,CAAC,YA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AS,CAAC,EAAE,EAAE;YACrC,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,EAAE,EAAE,SAAS,CAAC,EAAE;YAChB,EAAE,EAAE,SAAS,CAAC,EAAE;YAChB,UAAU;YACV,OAAO,EAAE;gBACP,YAAY,EAAE,YAAY;aAC3B;SACF,CAAA;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QACpC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAgB,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,CAAC;CACF,CAAA;AA/RY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAYR,WAAA,IAAA,eAAM,EAAC,8CAAmB,CAAC,CAAA;qCALM,sBAAe;QACpB,iBAAU;QAEd,sBAAa;QACV,gBAAS;QAED,GAAG;GAZ9B,aAAa,CA+RzB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './constant';
|
|
2
|
+
export * from './dto';
|
|
3
|
+
export * from './entity';
|
|
4
|
+
export * from './enum';
|
|
5
|
+
export * from './event';
|
|
6
|
+
export * from './import.controller';
|
|
7
|
+
export * from './import.module';
|
|
8
|
+
export * from './import.module-definition';
|
|
9
|
+
export * from './import.service';
|
|
10
|
+
export * from './interface';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constant"), exports);
|
|
18
|
+
__exportStar(require("./dto"), exports);
|
|
19
|
+
__exportStar(require("./entity"), exports);
|
|
20
|
+
__exportStar(require("./enum"), exports);
|
|
21
|
+
__exportStar(require("./event"), exports);
|
|
22
|
+
__exportStar(require("./import.controller"), exports);
|
|
23
|
+
__exportStar(require("./import.module"), exports);
|
|
24
|
+
__exportStar(require("./import.module-definition"), exports);
|
|
25
|
+
__exportStar(require("./import.service"), exports);
|
|
26
|
+
__exportStar(require("./interface"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,wCAAqB;AACrB,2CAAwB;AACxB,yCAAsB;AACtB,0CAAuB;AACvB,sDAAmC;AACnC,kDAA+B;AAC/B,6DAA0C;AAC1C,mDAAgC;AAChC,8CAA2B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the contract for transforming a raw CSV row into a standard
|
|
3
|
+
* validated attributes DTO for a specific table.
|
|
4
|
+
*/
|
|
5
|
+
export interface ICsvMappingStrategy<TAttributesDto extends object> {
|
|
6
|
+
/**
|
|
7
|
+
* Maps a single row from a CSV file to the target attributes DTO.
|
|
8
|
+
* This method should also perform any necessary validation.
|
|
9
|
+
* @param csvRow A key-value object representing one row from the CSV file.
|
|
10
|
+
* @returns A promise that resolves with the strongly-typed attributes DTO.
|
|
11
|
+
* @throws {BadRequestException} if the row data is invalid.
|
|
12
|
+
*/
|
|
13
|
+
mapCsvRow(csvRow: Record<string, any>): Promise<TAttributesDto>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-mapping-strategy.interface.js","sourceRoot":"","sources":["../../src/interface/csv-mapping-strategy.interface.ts"],"names":[],"mappings":""}
|