@punks/backend-entity-manager 0.0.437 → 0.0.440
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,11 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EntitySerializationFormat, IEntitySerializer } from "../abstractions";
|
|
3
|
-
import { EntityExportFile, EntitySerializerSheetDefinition, ImportEntry } from "../abstractions/serializer";
|
|
3
|
+
import { EntityExportFile, EntitySerializerColumnDefinition, EntitySerializerSheetDefinition, ImportEntry } from "../abstractions/serializer";
|
|
4
4
|
import { EntityServiceLocator } from "../providers/services";
|
|
5
5
|
import { EntityReference } from "../models";
|
|
6
6
|
export type EntitySerializerOptions = {
|
|
7
7
|
delimiter?: string;
|
|
8
8
|
};
|
|
9
|
+
export type ParseColumnValueInput<TSheetItem> = {
|
|
10
|
+
row: any;
|
|
11
|
+
columnName: string;
|
|
12
|
+
parser: EntitySerializerColumnDefinition<TSheetItem>["parser"];
|
|
13
|
+
};
|
|
9
14
|
export declare abstract class EntitySerializer<TEntity, TEntityId, TEntitySearchParameters, TSheetItem, TContext, TPayload = unknown> implements IEntitySerializer<TEntity, TEntityId, TEntitySearchParameters, TSheetItem> {
|
|
10
15
|
protected readonly services: EntityServiceLocator<TEntity, TEntityId>;
|
|
11
16
|
protected readonly options?: EntitySerializerOptions | undefined;
|
package/dist/esm/index.js
CHANGED
|
@@ -274,7 +274,7 @@ class EntitySerializer {
|
|
|
274
274
|
}
|
|
275
275
|
const entity = (definition.autoColumns ? { ...record } : {});
|
|
276
276
|
for (const column of definition.columns) {
|
|
277
|
-
const columnName = [column.name, ...(column?.aliases ?? [])].find((x) => x in record) ??
|
|
277
|
+
const columnName = [column.name, ...(column?.aliases ?? [])].find((x) => normalizeSheetColumn(x) in record) ?? null;
|
|
278
278
|
console.log("name", columnName);
|
|
279
279
|
console.log("record", entity);
|
|
280
280
|
if (!columnName)
|
|
@@ -286,13 +286,17 @@ class EntitySerializer {
|
|
|
286
286
|
if (typeof column.selector === "function") {
|
|
287
287
|
throw new Error("Function selectors are not supported with parseAction specified");
|
|
288
288
|
}
|
|
289
|
-
const parsedColumn = this.parseColumnValue(
|
|
289
|
+
const parsedColumn = this.parseColumnValue({
|
|
290
|
+
row: record,
|
|
291
|
+
columnName,
|
|
292
|
+
parser: column.parser,
|
|
293
|
+
});
|
|
290
294
|
entity[column.selector] = column.array
|
|
291
295
|
? splitArrayColumn(parsedColumn, column.arraySeparator)
|
|
292
296
|
.map((x) => applyModifiers(x, column.modifiers))
|
|
293
297
|
.filter((x) => isValidValue(x))
|
|
294
298
|
: applyModifiers(parsedColumn, column.modifiers);
|
|
295
|
-
delete entity[
|
|
299
|
+
delete entity[columnName];
|
|
296
300
|
}
|
|
297
301
|
const validationErrors = [];
|
|
298
302
|
for (const column of definition.columns) {
|
|
@@ -325,10 +329,9 @@ class EntitySerializer {
|
|
|
325
329
|
},
|
|
326
330
|
};
|
|
327
331
|
}
|
|
328
|
-
parseColumnValue(row,
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
return definition.parser ? definition.parser(rawValue) : rawValue;
|
|
332
|
+
parseColumnValue({ row, columnName, parser, }) {
|
|
333
|
+
const value = row[normalizeSheetColumn(columnName)];
|
|
334
|
+
return parser ? parser(value) : value;
|
|
332
335
|
}
|
|
333
336
|
async createSample(format) {
|
|
334
337
|
return await this.buildSampleFile(format);
|