@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.
@@ -37,6 +37,8 @@ export type EntitySerializerColumnDefinition<TSheetItem> = {
37
37
  validators?: EntitySerializerColumnValidator<TSheetItem>[];
38
38
  idColumn?: boolean;
39
39
  sheetParser?: EntitySerializerSheetCustomParser;
40
+ array?: boolean;
41
+ arraySeparator?: string;
40
42
  };
41
43
  export type EntitySerializerSheetDefinition<TSheetItem> = {
42
44
  columns: EntitySerializerColumnDefinition<TSheetItem>[];
package/dist/esm/index.js CHANGED
@@ -185,6 +185,9 @@ class EntitySeeder {
185
185
 
186
186
  const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
187
187
  const DEFAULT_DELIMITER = ";";
188
+ const DEFAULT_ARRAY_SEPARATOR = "|";
189
+ const splitArrayColumn = (value, separator) => value?.toString().split(separator ?? DEFAULT_ARRAY_SEPARATOR);
190
+ const joinArrayColumn = (value, separator) => value?.map((x) => x.toString()).join(separator ?? DEFAULT_ARRAY_SEPARATOR);
188
191
  class EntitySerializer {
189
192
  constructor(services, options) {
190
193
  this.services = services;
@@ -244,7 +247,10 @@ class EntitySerializer {
244
247
  if (typeof column.selector === "function") {
245
248
  throw new Error("Function selectors are not supported with parseAction specified");
246
249
  }
247
- entity[column.selector] = this.parseColumnValue(record, column);
250
+ const parsedColumn = this.parseColumnValue(record, column);
251
+ entity[column.selector] = column.array
252
+ ? splitArrayColumn(parsedColumn, column.arraySeparator)
253
+ : parsedColumn;
248
254
  }
249
255
  const validationErrors = [];
250
256
  for (const column of definition.columns) {
@@ -371,7 +377,12 @@ class EntitySerializer {
371
377
  : []),
372
378
  ...definition.columns.map((c) => ({
373
379
  name: c.name,
374
- value: (item) => this.getColumnValue(item, c),
380
+ value: (item) => {
381
+ const value = this.getColumnValue(item, c);
382
+ return c.array
383
+ ? joinArrayColumn(value, c.arraySeparator)
384
+ : value;
385
+ },
375
386
  })),
376
387
  ], {
377
388
  delimiter: DEFAULT_DELIMITER,