@punks/backend-entity-manager 0.0.437 → 0.0.439
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,18 @@ 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
|
+
});
|
|
294
|
+
console.log("parsed", parsedColumn);
|
|
290
295
|
entity[column.selector] = column.array
|
|
291
296
|
? splitArrayColumn(parsedColumn, column.arraySeparator)
|
|
292
297
|
.map((x) => applyModifiers(x, column.modifiers))
|
|
293
298
|
.filter((x) => isValidValue(x))
|
|
294
299
|
: applyModifiers(parsedColumn, column.modifiers);
|
|
295
|
-
delete entity[
|
|
300
|
+
delete entity[columnName];
|
|
296
301
|
}
|
|
297
302
|
const validationErrors = [];
|
|
298
303
|
for (const column of definition.columns) {
|
|
@@ -325,10 +330,9 @@ class EntitySerializer {
|
|
|
325
330
|
},
|
|
326
331
|
};
|
|
327
332
|
}
|
|
328
|
-
parseColumnValue(row,
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
return definition.parser ? definition.parser(rawValue) : rawValue;
|
|
333
|
+
parseColumnValue({ row, columnName, parser, }) {
|
|
334
|
+
const value = row[normalizeSheetColumn(columnName)];
|
|
335
|
+
return parser ? parser(value) : value;
|
|
332
336
|
}
|
|
333
337
|
async createSample(format) {
|
|
334
338
|
return await this.buildSampleFile(format);
|