@punks/backend-entity-manager 0.0.350 → 0.0.351
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 +18 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/base/serializer.d.ts +6 -1
- package/dist/cjs/types/platforms/nest/__test__/server/app/foos/foo.controller.d.ts +4 -3
- package/dist/esm/index.js +18 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/base/serializer.d.ts +6 -1
- package/dist/esm/types/platforms/nest/__test__/server/app/foos/foo.controller.d.ts +4 -3
- package/dist/index.d.ts +6 -1
- package/package.json +1 -1
|
@@ -3,11 +3,16 @@ import { EntitySerializationFormat, IEntitySerializer } from "../abstractions";
|
|
|
3
3
|
import { EntityExportFile, EntitySerializerSheetDefinition, ImportEntry } from "../abstractions/serializer";
|
|
4
4
|
import { EntityServiceLocator } from "../providers/services";
|
|
5
5
|
import { EntityReference } from "../models";
|
|
6
|
+
export type EntitySerializerOptions = {
|
|
7
|
+
delimiter?: string;
|
|
8
|
+
useTypeColumn?: boolean;
|
|
9
|
+
};
|
|
6
10
|
export declare abstract class EntitySerializer<TEntity, TEntityId, TEntitySearchParameters, TSheetItem, TContext, TPayload = unknown> implements IEntitySerializer<TEntity, TEntityId, TEntitySearchParameters, TSheetItem> {
|
|
7
11
|
protected readonly services: EntityServiceLocator<TEntity, TEntityId>;
|
|
12
|
+
protected readonly options?: EntitySerializerOptions | undefined;
|
|
8
13
|
private readonly logger;
|
|
9
14
|
protected readonly entityName: string;
|
|
10
|
-
constructor(services: EntityServiceLocator<TEntity, TEntityId
|
|
15
|
+
constructor(services: EntityServiceLocator<TEntity, TEntityId>, options?: EntitySerializerOptions | undefined);
|
|
11
16
|
export(filters?: TEntitySearchParameters): Promise<TSheetItem[]>;
|
|
12
17
|
import(items: TSheetItem[], payload?: TPayload): Promise<void>;
|
|
13
18
|
parse(data: Buffer, format: EntitySerializationFormat): Promise<ImportEntry<TSheetItem, TEntityId>[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="multer" />
|
|
2
2
|
import { FooActions } from "./foo.actions";
|
|
3
|
-
import { FooCreateDto, FooDto, FooExportRequest, FooExportResponse,
|
|
3
|
+
import { FooCreateDto, FooDto, FooExportRequest, FooExportResponse, FooParseResponse, FooSampleDownloadRequest, FooSampleDownloadResponse, FooSearchRequest, FooSearchResponse, FooUpdateDto, FooVersionsSearchRequest, FooVersionsSearchResponse } from "./foo.dto";
|
|
4
|
+
import { EntitySerializationFormat } from "../../../../../../abstractions/serializer";
|
|
4
5
|
export declare class FooController {
|
|
5
6
|
private readonly actions;
|
|
6
7
|
constructor(actions: FooActions);
|
|
@@ -9,8 +10,8 @@ export declare class FooController {
|
|
|
9
10
|
update(id: string, item: FooUpdateDto): Promise<FooDto>;
|
|
10
11
|
delete(id: string): Promise<void>;
|
|
11
12
|
search(request: FooSearchRequest): Promise<FooSearchResponse>;
|
|
12
|
-
parse(file: Express.Multer.File
|
|
13
|
-
import(file: Express.Multer.File
|
|
13
|
+
parse(format: EntitySerializationFormat, file: Express.Multer.File): Promise<FooParseResponse>;
|
|
14
|
+
import(format: EntitySerializationFormat, file: Express.Multer.File): Promise<void>;
|
|
14
15
|
export(request: FooExportRequest): Promise<FooExportResponse>;
|
|
15
16
|
sampleDownload(request: FooSampleDownloadRequest): Promise<FooSampleDownloadResponse>;
|
|
16
17
|
versions(request: FooVersionsSearchRequest): Promise<FooVersionsSearchResponse>;
|
package/dist/esm/index.js
CHANGED
|
@@ -179,8 +179,9 @@ class EntitySeeder {
|
|
|
179
179
|
|
|
180
180
|
const DEFAULT_DELIMITER = ";";
|
|
181
181
|
class EntitySerializer {
|
|
182
|
-
constructor(services) {
|
|
182
|
+
constructor(services, options) {
|
|
183
183
|
this.services = services;
|
|
184
|
+
this.options = options;
|
|
184
185
|
this.entityName = services.getEntityName();
|
|
185
186
|
this.logger = Log.getLogger(`${services.getEntityName()} -> Serializer`);
|
|
186
187
|
}
|
|
@@ -272,10 +273,14 @@ class EntitySerializer {
|
|
|
272
273
|
fileName,
|
|
273
274
|
contentType: "text/csv",
|
|
274
275
|
content: Buffer.from(csvBuild([{}], [
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
...(this.options?.useTypeColumn
|
|
277
|
+
? [
|
|
278
|
+
{
|
|
279
|
+
name: "_type",
|
|
280
|
+
value: () => this.entityName,
|
|
281
|
+
},
|
|
282
|
+
]
|
|
283
|
+
: []),
|
|
279
284
|
...definition.columns.map((c) => ({
|
|
280
285
|
name: c.name,
|
|
281
286
|
value: () => c.sampleValue ?? "",
|
|
@@ -292,10 +297,14 @@ class EntitySerializer {
|
|
|
292
297
|
data: [{}],
|
|
293
298
|
sheetName: this.entityName,
|
|
294
299
|
columns: [
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
300
|
+
...(this.options?.useTypeColumn
|
|
301
|
+
? [
|
|
302
|
+
{
|
|
303
|
+
header: "_type",
|
|
304
|
+
value: () => this.entityName,
|
|
305
|
+
},
|
|
306
|
+
]
|
|
307
|
+
: []),
|
|
299
308
|
...definition.columns.map((c) => ({
|
|
300
309
|
header: c.name,
|
|
301
310
|
value: () => c.sampleValue ?? "",
|