@punks/backend-entity-manager 0.0.356 → 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.
@@ -1,6 +1,17 @@
1
1
  /// <reference types="node" />
2
+ export type EntryValidationError = {
3
+ errorCode: string;
4
+ };
5
+ export type EntryValidationResult = {
6
+ isValid: boolean;
7
+ validationErrors: EntryValidationError[];
8
+ };
2
9
  export type ImportEntryValidationError = {
3
10
  errorCode: string;
11
+ column: {
12
+ name: string;
13
+ key: string;
14
+ };
4
15
  };
5
16
  export type ImportEntryValidationResult = {
6
17
  isValid: boolean;
@@ -11,11 +22,12 @@ export type EntitySerializerColumnParseAction<TSheetItem> = (value: any, item: T
11
22
  export type EntitySerializerColumnConverter<TSheetItem> = (value: any, item: TSheetItem) => any;
12
23
  export type EntitySerializerColumnValidator<TSheetItem> = {
13
24
  key: string;
14
- fn: (item: TSheetItem) => ImportEntryValidationResult;
25
+ fn: (item: TSheetItem) => EntryValidationResult;
15
26
  };
16
27
  export type EntitySerializerColumnDefinition<TSheetItem> = {
17
28
  name: string;
18
- selector: keyof TSheetItem;
29
+ key: string;
30
+ selector: keyof TSheetItem | ((item: TSheetItem) => any);
19
31
  colSpan?: number;
20
32
  sampleValue?: any;
21
33
  parser?: EntitySerializerColumnParser;
@@ -31,5 +31,6 @@ export declare abstract class EntitySerializer<TEntity, TEntityId, TEntitySearch
31
31
  protected getContext(): Promise<TContext>;
32
32
  private buildExportFile;
33
33
  private getColumnValue;
34
+ private selectColumnValue;
34
35
  private buildExportFileName;
35
36
  }
@@ -1,5 +1,10 @@
1
+ export declare class EntityParseValidationColumn {
2
+ name: string;
3
+ key: string;
4
+ }
1
5
  export declare class EntityParseValidationError {
2
6
  errorCode: string;
7
+ column: EntityParseValidationColumn;
3
8
  }
4
9
  export declare class EntityParseStatus {
5
10
  isValid: boolean;
@@ -1,2 +1,2 @@
1
- import { ImportEntryValidationResult } from "../abstractions/serializer";
2
- export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => ImportEntryValidationResult;
1
+ import { EntryValidationResult } from "../abstractions/serializer";
2
+ export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
package/dist/esm/index.js CHANGED
@@ -227,10 +227,12 @@ class EntitySerializer {
227
227
  for (const column of definition.columns) {
228
228
  if (column.parseAction) {
229
229
  column.parseAction(record[column.name], entity);
230
+ continue;
230
231
  }
231
- else {
232
- entity[column.selector] = this.parseColumnValue(record, column);
232
+ if (typeof column.selector === "function") {
233
+ throw new Error("Function selectors are not supported with parseAction specified");
233
234
  }
235
+ entity[column.selector] = this.parseColumnValue(record, column);
234
236
  }
235
237
  const validationErrors = [];
236
238
  for (const column of definition.columns) {
@@ -239,13 +241,19 @@ class EntitySerializer {
239
241
  if (!result.isValid) {
240
242
  validationErrors.push({
241
243
  errorCode: validator.key,
244
+ column: {
245
+ name: column.name,
246
+ key: column.key,
247
+ },
242
248
  });
243
249
  }
244
250
  }
245
251
  }
246
252
  const idField = definition.columns.find((x) => x.idColumn || x.selector === "id");
247
253
  return {
248
- id: idField ? entity[idField.selector] : undefined,
254
+ id: idField
255
+ ? this.selectColumnValue(entity, idField.selector)
256
+ : undefined,
249
257
  item: entity,
250
258
  rowIndex,
251
259
  status: {
@@ -385,11 +393,14 @@ class EntitySerializer {
385
393
  }
386
394
  }
387
395
  getColumnValue(item, definition) {
388
- const rawValue = item[definition.selector];
396
+ const rawValue = this.selectColumnValue(item, definition.selector);
389
397
  return definition.converter
390
398
  ? definition.converter(rawValue, item)
391
399
  : rawValue;
392
400
  }
401
+ selectColumnValue(item, selector) {
402
+ return typeof selector === "function" ? selector(item) : item[selector];
403
+ }
393
404
  buildExportFileName(input) {
394
405
  return `${input.refDate.toISOString().replaceAll(":", "_")}_${this.entityName}.${input.format}`;
395
406
  }
@@ -34831,12 +34842,26 @@ class AppExceptionsFilterBase {
34831
34842
  }
34832
34843
  }
34833
34844
 
34845
+ class EntityParseValidationColumn {
34846
+ }
34847
+ __decorate([
34848
+ ApiProperty(),
34849
+ __metadata("design:type", String)
34850
+ ], EntityParseValidationColumn.prototype, "name", void 0);
34851
+ __decorate([
34852
+ ApiProperty(),
34853
+ __metadata("design:type", String)
34854
+ ], EntityParseValidationColumn.prototype, "key", void 0);
34834
34855
  class EntityParseValidationError {
34835
34856
  }
34836
34857
  __decorate([
34837
34858
  ApiProperty(),
34838
34859
  __metadata("design:type", String)
34839
34860
  ], EntityParseValidationError.prototype, "errorCode", void 0);
34861
+ __decorate([
34862
+ ApiProperty(),
34863
+ __metadata("design:type", EntityParseValidationColumn)
34864
+ ], EntityParseValidationError.prototype, "column", void 0);
34840
34865
  class EntityParseStatus {
34841
34866
  }
34842
34867
  __decorate([