@punks/backend-entity-manager 0.0.363 → 0.0.365
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/cjs/index.js +31 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +32 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Log, csvParse, excelParse, excelBuild, csvBuild, mapAsync, isNullOrUndefined, addTime, newUuid as newUuid$1, buildObject, toDict, sleep, sort, byField, toArrayDict, toItemsDict, ensureTailingSlash, ensureStartSlash, removeUndefinedProps } from '@punks/backend-core';
|
|
1
|
+
import { Log, csvParse, excelParse, ExcelKeyTransform, excelBuild, csvBuild, mapAsync, isNullOrUndefined, addTime, newUuid as newUuid$1, buildObject, toDict, sleep, sort, byField, toArrayDict, toItemsDict, ensureTailingSlash, ensureStartSlash, removeUndefinedProps } from '@punks/backend-core';
|
|
2
2
|
import { QueryCommand, ScanCommand, GetItemCommand, PutItemCommand, DeleteItemCommand, DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
3
3
|
import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
|
|
4
4
|
import { Module, applyDecorators, Injectable, SetMetadata, createParamDecorator, Global, Scope, Inject, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
|
|
@@ -177,6 +177,7 @@ class EntitySeeder {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
|
|
180
181
|
const DEFAULT_DELIMITER = ";";
|
|
181
182
|
class EntitySerializer {
|
|
182
183
|
constructor(services, options) {
|
|
@@ -215,7 +216,9 @@ class EntitySerializer {
|
|
|
215
216
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
216
217
|
}
|
|
217
218
|
parseXlsx(data, definition) {
|
|
218
|
-
const records = excelParse(data
|
|
219
|
+
const records = excelParse(data, {
|
|
220
|
+
keysTransform: ExcelKeyTransform.Lower,
|
|
221
|
+
});
|
|
219
222
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
220
223
|
}
|
|
221
224
|
convertSheetRecord(record, definition, rowIndex) {
|
|
@@ -225,8 +228,9 @@ class EntitySerializer {
|
|
|
225
228
|
}
|
|
226
229
|
const entity = {};
|
|
227
230
|
for (const column of definition.columns) {
|
|
231
|
+
const columnName = normalizeSheetColumn(column.name);
|
|
228
232
|
if (column.parseAction) {
|
|
229
|
-
column.parseAction(record[
|
|
233
|
+
column.parseAction(record[columnName], entity);
|
|
230
234
|
continue;
|
|
231
235
|
}
|
|
232
236
|
if (typeof column.selector === "function") {
|
|
@@ -263,7 +267,8 @@ class EntitySerializer {
|
|
|
263
267
|
};
|
|
264
268
|
}
|
|
265
269
|
parseColumnValue(row, definition) {
|
|
266
|
-
const
|
|
270
|
+
const columnName = normalizeSheetColumn(definition.name);
|
|
271
|
+
const rawValue = row[columnName];
|
|
267
272
|
return definition.parser ? definition.parser(rawValue) : rawValue;
|
|
268
273
|
}
|
|
269
274
|
async createSample(format) {
|
|
@@ -40357,7 +40362,30 @@ if (typeof commonjsRequire !== 'undefined' && commonjsRequire.extensions) {
|
|
|
40357
40362
|
commonjsRequire.extensions['.hbs'] = extension;
|
|
40358
40363
|
}
|
|
40359
40364
|
|
|
40365
|
+
let helpersRegistered = false;
|
|
40366
|
+
const registerHandlebarsHelpers = () => {
|
|
40367
|
+
if (helpersRegistered) {
|
|
40368
|
+
return;
|
|
40369
|
+
}
|
|
40370
|
+
lib.registerHelper("uppercase", function (str) {
|
|
40371
|
+
return str.toUpperCase();
|
|
40372
|
+
});
|
|
40373
|
+
lib.registerHelper("isDefined", function (value) {
|
|
40374
|
+
return !isNullOrUndefined(value);
|
|
40375
|
+
});
|
|
40376
|
+
lib.registerHelper("isUndefined", function (value) {
|
|
40377
|
+
return isNullOrUndefined(value);
|
|
40378
|
+
});
|
|
40379
|
+
lib.registerHelper("eq", function (a, b) {
|
|
40380
|
+
return a === b;
|
|
40381
|
+
});
|
|
40382
|
+
lib.registerHelper("ne", function (a, b) {
|
|
40383
|
+
return a !== b;
|
|
40384
|
+
});
|
|
40385
|
+
helpersRegistered = true;
|
|
40386
|
+
};
|
|
40360
40387
|
const renderHandlebarsTemplate = (input) => {
|
|
40388
|
+
registerHandlebarsHelpers();
|
|
40361
40389
|
const compiled = lib.compile(input.template);
|
|
40362
40390
|
return compiled(input.context);
|
|
40363
40391
|
};
|