@punks/backend-entity-manager 0.0.355 → 0.0.357

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
@@ -234,17 +234,20 @@ class EntitySerializer {
234
234
  return records.map((x, i) => this.convertSheetRecord(x, definition, i));
235
235
  }
236
236
  convertSheetRecord(record, definition, rowIndex) {
237
- if (!record._type || record._type !== this.entityName) {
237
+ if (this.options?.useTypeColumn &&
238
+ (!record._type || record._type !== this.entityName)) {
238
239
  throw new Error(`Invalid record type ${record._type} -> record: \n${JSON.stringify(record)}`);
239
240
  }
240
241
  const entity = {};
241
242
  for (const column of definition.columns) {
242
243
  if (column.parseAction) {
243
244
  column.parseAction(record[column.name], entity);
245
+ continue;
244
246
  }
245
- else {
246
- entity[column.selector] = this.parseColumnValue(record, column);
247
+ if (typeof column.selector === "function") {
248
+ throw new Error("Function selectors are not supported with parseAction specified");
247
249
  }
250
+ entity[column.selector] = this.parseColumnValue(record, column);
248
251
  }
249
252
  const validationErrors = [];
250
253
  for (const column of definition.columns) {
@@ -253,13 +256,19 @@ class EntitySerializer {
253
256
  if (!result.isValid) {
254
257
  validationErrors.push({
255
258
  errorCode: validator.key,
259
+ column: {
260
+ name: column.name,
261
+ key: column.key,
262
+ },
256
263
  });
257
264
  }
258
265
  }
259
266
  }
260
267
  const idField = definition.columns.find((x) => x.idColumn || x.selector === "id");
261
268
  return {
262
- id: idField ? entity[idField.selector] : undefined,
269
+ id: idField
270
+ ? this.selectColumnValue(entity, idField.selector)
271
+ : undefined,
263
272
  item: entity,
264
273
  rowIndex,
265
274
  status: {
@@ -354,10 +363,14 @@ class EntitySerializer {
354
363
  fileName,
355
364
  contentType: "text/csv",
356
365
  content: Buffer.from(backendCore.csvBuild(data, [
357
- {
358
- name: "_type",
359
- value: () => this.entityName,
360
- },
366
+ ...(this.options?.useTypeColumn
367
+ ? [
368
+ {
369
+ name: "_type",
370
+ value: () => this.entityName,
371
+ },
372
+ ]
373
+ : []),
361
374
  ...definition.columns.map((c) => ({
362
375
  name: c.name,
363
376
  value: (item) => this.getColumnValue(item, c),
@@ -395,11 +408,14 @@ class EntitySerializer {
395
408
  }
396
409
  }
397
410
  getColumnValue(item, definition) {
398
- const rawValue = item[definition.selector];
411
+ const rawValue = this.selectColumnValue(item, definition.selector);
399
412
  return definition.converter
400
413
  ? definition.converter(rawValue, item)
401
414
  : rawValue;
402
415
  }
416
+ selectColumnValue(item, selector) {
417
+ return typeof selector === "function" ? selector(item) : item[selector];
418
+ }
403
419
  buildExportFileName(input) {
404
420
  return `${input.refDate.toISOString().replaceAll(":", "_")}_${this.entityName}.${input.format}`;
405
421
  }
@@ -34841,12 +34857,26 @@ class AppExceptionsFilterBase {
34841
34857
  }
34842
34858
  }
34843
34859
 
34860
+ class EntityParseValidationColumn {
34861
+ }
34862
+ __decorate([
34863
+ swagger.ApiProperty(),
34864
+ __metadata("design:type", String)
34865
+ ], EntityParseValidationColumn.prototype, "name", void 0);
34866
+ __decorate([
34867
+ swagger.ApiProperty(),
34868
+ __metadata("design:type", String)
34869
+ ], EntityParseValidationColumn.prototype, "key", void 0);
34844
34870
  class EntityParseValidationError {
34845
34871
  }
34846
34872
  __decorate([
34847
34873
  swagger.ApiProperty(),
34848
34874
  __metadata("design:type", String)
34849
34875
  ], EntityParseValidationError.prototype, "errorCode", void 0);
34876
+ __decorate([
34877
+ swagger.ApiProperty(),
34878
+ __metadata("design:type", EntityParseValidationColumn)
34879
+ ], EntityParseValidationError.prototype, "column", void 0);
34850
34880
  class EntityParseStatus {
34851
34881
  }
34852
34882
  __decorate([