@punks/backend-entity-manager 0.0.364 → 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/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[column.name], entity);
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 rawValue = row[definition.name];
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) {