@punks/backend-entity-manager 0.0.428 → 0.0.430

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.
@@ -51,6 +51,7 @@ export type EntitySerializerSheetOptions = {
51
51
  useTypeColumn?: boolean;
52
52
  };
53
53
  export type EntitySerializerSheetDefinition<TSheetItem> = {
54
+ autoColumns?: boolean;
54
55
  columns: EntitySerializerColumnDefinition<TSheetItem>[];
55
56
  sheet?: EntitySerializerSheetOptions;
56
57
  options?: ExcelParseOptions;
package/dist/esm/index.js CHANGED
@@ -268,15 +268,14 @@ class EntitySerializer {
268
268
  return records.map((x, i) => this.convertSheetRecord(x, definition, i));
269
269
  }
270
270
  convertSheetRecord(record, definition, rowIndex) {
271
- console.log("record", record);
272
- console.log("definition", definition);
273
- console.log("rowIndex", rowIndex);
274
271
  if (definition.sheet?.useTypeColumn &&
275
272
  (!record._type || record._type !== this.entityName)) {
276
273
  throw new Error(`Invalid record type ${record._type} -> record: \n${JSON.stringify(record)}`);
277
274
  }
278
- const entity = {};
275
+ const entity = (definition.autoColumns ? { ...record } : {});
279
276
  for (const column of definition.columns) {
277
+ if (!(column.name in record))
278
+ continue;
280
279
  const columnName = normalizeSheetColumn(column.name);
281
280
  if (column.parseAction) {
282
281
  column.parseAction(record[columnName], entity);
@@ -294,6 +293,8 @@ class EntitySerializer {
294
293
  }
295
294
  const validationErrors = [];
296
295
  for (const column of definition.columns) {
296
+ if (!(column.name in record))
297
+ continue;
297
298
  for (const validator of column.validators ?? []) {
298
299
  const result = validator.fn(entity);
299
300
  if (!result.isValid) {