@punks/backend-entity-manager 0.0.436 → 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,9 @@ 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
|
+
console.log("name", columnName);
|
|
279
|
+
console.log("record", entity);
|
|
278
280
|
if (!columnName)
|
|
279
281
|
continue;
|
|
280
282
|
if (column.parseAction) {
|
|
@@ -284,13 +286,18 @@ class EntitySerializer {
|
|
|
284
286
|
if (typeof column.selector === "function") {
|
|
285
287
|
throw new Error("Function selectors are not supported with parseAction specified");
|
|
286
288
|
}
|
|
287
|
-
const parsedColumn = this.parseColumnValue(
|
|
289
|
+
const parsedColumn = this.parseColumnValue({
|
|
290
|
+
row: record,
|
|
291
|
+
columnName,
|
|
292
|
+
parser: column.parser,
|
|
293
|
+
});
|
|
294
|
+
console.log("parsed", parsedColumn);
|
|
288
295
|
entity[column.selector] = column.array
|
|
289
296
|
? splitArrayColumn(parsedColumn, column.arraySeparator)
|
|
290
297
|
.map((x) => applyModifiers(x, column.modifiers))
|
|
291
298
|
.filter((x) => isValidValue(x))
|
|
292
299
|
: applyModifiers(parsedColumn, column.modifiers);
|
|
293
|
-
delete entity[
|
|
300
|
+
delete entity[columnName];
|
|
294
301
|
}
|
|
295
302
|
const validationErrors = [];
|
|
296
303
|
for (const column of definition.columns) {
|
|
@@ -323,10 +330,9 @@ class EntitySerializer {
|
|
|
323
330
|
},
|
|
324
331
|
};
|
|
325
332
|
}
|
|
326
|
-
parseColumnValue(row,
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
return definition.parser ? definition.parser(rawValue) : rawValue;
|
|
333
|
+
parseColumnValue({ row, columnName, parser, }) {
|
|
334
|
+
const value = row[normalizeSheetColumn(columnName)];
|
|
335
|
+
return parser ? parser(value) : value;
|
|
330
336
|
}
|
|
331
337
|
async createSample(format) {
|
|
332
338
|
return await this.buildSampleFile(format);
|