@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/cjs/index.js
CHANGED
|
@@ -192,6 +192,7 @@ class EntitySeeder {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
|
|
195
196
|
const DEFAULT_DELIMITER = ";";
|
|
196
197
|
class EntitySerializer {
|
|
197
198
|
constructor(services, options) {
|
|
@@ -230,7 +231,9 @@ class EntitySerializer {
|
|
|
230
231
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
231
232
|
}
|
|
232
233
|
parseXlsx(data, definition) {
|
|
233
|
-
const records = backendCore.excelParse(data
|
|
234
|
+
const records = backendCore.excelParse(data, {
|
|
235
|
+
keysTransform: backendCore.ExcelKeyTransform.Lower,
|
|
236
|
+
});
|
|
234
237
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
235
238
|
}
|
|
236
239
|
convertSheetRecord(record, definition, rowIndex) {
|
|
@@ -240,8 +243,9 @@ class EntitySerializer {
|
|
|
240
243
|
}
|
|
241
244
|
const entity = {};
|
|
242
245
|
for (const column of definition.columns) {
|
|
246
|
+
const columnName = normalizeSheetColumn(column.name);
|
|
243
247
|
if (column.parseAction) {
|
|
244
|
-
column.parseAction(record[
|
|
248
|
+
column.parseAction(record[columnName], entity);
|
|
245
249
|
continue;
|
|
246
250
|
}
|
|
247
251
|
if (typeof column.selector === "function") {
|
|
@@ -278,7 +282,8 @@ class EntitySerializer {
|
|
|
278
282
|
};
|
|
279
283
|
}
|
|
280
284
|
parseColumnValue(row, definition) {
|
|
281
|
-
const
|
|
285
|
+
const columnName = normalizeSheetColumn(definition.name);
|
|
286
|
+
const rawValue = row[columnName];
|
|
282
287
|
return definition.parser ? definition.parser(rawValue) : rawValue;
|
|
283
288
|
}
|
|
284
289
|
async createSample(format) {
|
|
@@ -40372,7 +40377,30 @@ if (typeof commonjsRequire !== 'undefined' && commonjsRequire.extensions) {
|
|
|
40372
40377
|
commonjsRequire.extensions['.hbs'] = extension;
|
|
40373
40378
|
}
|
|
40374
40379
|
|
|
40380
|
+
let helpersRegistered = false;
|
|
40381
|
+
const registerHandlebarsHelpers = () => {
|
|
40382
|
+
if (helpersRegistered) {
|
|
40383
|
+
return;
|
|
40384
|
+
}
|
|
40385
|
+
lib.registerHelper("uppercase", function (str) {
|
|
40386
|
+
return str.toUpperCase();
|
|
40387
|
+
});
|
|
40388
|
+
lib.registerHelper("isDefined", function (value) {
|
|
40389
|
+
return !backendCore.isNullOrUndefined(value);
|
|
40390
|
+
});
|
|
40391
|
+
lib.registerHelper("isUndefined", function (value) {
|
|
40392
|
+
return backendCore.isNullOrUndefined(value);
|
|
40393
|
+
});
|
|
40394
|
+
lib.registerHelper("eq", function (a, b) {
|
|
40395
|
+
return a === b;
|
|
40396
|
+
});
|
|
40397
|
+
lib.registerHelper("ne", function (a, b) {
|
|
40398
|
+
return a !== b;
|
|
40399
|
+
});
|
|
40400
|
+
helpersRegistered = true;
|
|
40401
|
+
};
|
|
40375
40402
|
const renderHandlebarsTemplate = (input) => {
|
|
40403
|
+
registerHandlebarsHelpers();
|
|
40376
40404
|
const compiled = lib.compile(input.template);
|
|
40377
40405
|
return compiled(input.context);
|
|
40378
40406
|
};
|