@punks/backend-entity-manager 0.0.428 → 0.0.429
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 +5 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/serializer.d.ts +1 -0
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/serializer.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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,16 +268,15 @@ 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) {
|
|
280
277
|
const columnName = normalizeSheetColumn(column.name);
|
|
278
|
+
if (!(columnName in record))
|
|
279
|
+
continue;
|
|
281
280
|
if (column.parseAction) {
|
|
282
281
|
column.parseAction(record[columnName], entity);
|
|
283
282
|
continue;
|
|
@@ -294,6 +293,8 @@ class EntitySerializer {
|
|
|
294
293
|
}
|
|
295
294
|
const validationErrors = [];
|
|
296
295
|
for (const column of definition.columns) {
|
|
296
|
+
if (!(normalizeSheetColumn(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) {
|