@punks/backend-entity-manager 0.0.375 → 0.0.376

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 CHANGED
@@ -200,6 +200,9 @@ class EntitySeeder {
200
200
 
201
201
  const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
202
202
  const DEFAULT_DELIMITER = ";";
203
+ const DEFAULT_ARRAY_SEPARATOR = "|";
204
+ const splitArrayColumn = (value, separator) => value?.toString().split(separator ?? DEFAULT_ARRAY_SEPARATOR);
205
+ const joinArrayColumn = (value, separator) => value?.map((x) => x.toString()).join(separator ?? DEFAULT_ARRAY_SEPARATOR);
203
206
  class EntitySerializer {
204
207
  constructor(services, options) {
205
208
  this.services = services;
@@ -259,7 +262,10 @@ class EntitySerializer {
259
262
  if (typeof column.selector === "function") {
260
263
  throw new Error("Function selectors are not supported with parseAction specified");
261
264
  }
262
- entity[column.selector] = this.parseColumnValue(record, column);
265
+ const parsedColumn = this.parseColumnValue(record, column);
266
+ entity[column.selector] = column.array
267
+ ? splitArrayColumn(parsedColumn, column.arraySeparator)
268
+ : parsedColumn;
263
269
  }
264
270
  const validationErrors = [];
265
271
  for (const column of definition.columns) {
@@ -386,7 +392,12 @@ class EntitySerializer {
386
392
  : []),
387
393
  ...definition.columns.map((c) => ({
388
394
  name: c.name,
389
- value: (item) => this.getColumnValue(item, c),
395
+ value: (item) => {
396
+ const value = this.getColumnValue(item, c);
397
+ return c.array
398
+ ? joinArrayColumn(value, c.arraySeparator)
399
+ : value;
400
+ },
390
401
  })),
391
402
  ], {
392
403
  delimiter: DEFAULT_DELIMITER,