@punks/backend-entity-manager 0.0.89 → 0.0.90
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 +27 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/export.d.ts +1 -0
- package/dist/cjs/types/commands/sampleDownload.d.ts +6 -2
- package/dist/cjs/types/platforms/nest/__test__/server/app/foos/foo.controller.d.ts +2 -4
- package/dist/cjs/types/platforms/nest/__test__/server/app/foos/foo.dto.d.ts +2 -2
- package/dist/esm/index.js +27 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/export.d.ts +1 -0
- package/dist/esm/types/commands/sampleDownload.d.ts +6 -2
- package/dist/esm/types/platforms/nest/__test__/server/app/foos/foo.controller.d.ts +2 -4
- package/dist/esm/types/platforms/nest/__test__/server/app/foos/foo.dto.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { IEntitiesSampleDownloadCommand } from "../abstractions/commands";
|
|
2
2
|
import { EntityServiceLocator } from "../providers/services";
|
|
3
|
-
import { EntitiesSampleDownloadOptions, EntitiesSampleDownloadResult } from "../abstractions";
|
|
3
|
+
import { EntitiesImportExportSettings, EntitiesSampleDownloadOptions, EntitiesSampleDownloadResult } from "../abstractions";
|
|
4
4
|
export declare class EntitiesSampleDownloadCommand<TEntity> implements IEntitiesSampleDownloadCommand<TEntity> {
|
|
5
5
|
private readonly services;
|
|
6
|
-
|
|
6
|
+
private readonly settings;
|
|
7
|
+
constructor(services: EntityServiceLocator<TEntity, unknown>, settings: EntitiesImportExportSettings);
|
|
7
8
|
execute(input: EntitiesSampleDownloadOptions): Promise<EntitiesSampleDownloadResult>;
|
|
9
|
+
private uploadSampleFile;
|
|
10
|
+
private buildAbsoluteBucketPath;
|
|
11
|
+
private get bucket();
|
|
8
12
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/// <reference types="multer" />
|
|
2
|
-
import { StreamableFile } from "@nestjs/common";
|
|
3
|
-
import type { Response } from "express";
|
|
4
2
|
import { FooActions } from "./foo.actions";
|
|
5
|
-
import { FooCreateDto, FooDto, FooExportRequest, FooExportResponse, FooImportRequest, FooSampleDownloadRequest, FooSearchRequest, FooSearchResponse, FooUpdateDto } from "./foo.dto";
|
|
3
|
+
import { FooCreateDto, FooDto, FooExportRequest, FooExportResponse, FooImportRequest, FooSampleDownloadRequest, FooSampleDownloadResponse, FooSearchRequest, FooSearchResponse, FooUpdateDto } from "./foo.dto";
|
|
6
4
|
export declare class FooController {
|
|
7
5
|
private readonly actions;
|
|
8
6
|
constructor(actions: FooActions);
|
|
@@ -13,5 +11,5 @@ export declare class FooController {
|
|
|
13
11
|
search(request: FooSearchRequest): Promise<FooSearchResponse>;
|
|
14
12
|
import(file: Express.Multer.File, request: FooImportRequest): Promise<void>;
|
|
15
13
|
export(request: FooExportRequest): Promise<FooExportResponse>;
|
|
16
|
-
sampleDownload(
|
|
14
|
+
sampleDownload(request: FooSampleDownloadRequest): Promise<FooSampleDownloadResponse>;
|
|
17
15
|
}
|
|
@@ -37,11 +37,11 @@ export declare class FooExportRequest {
|
|
|
37
37
|
filter?: FooSearchParameters;
|
|
38
38
|
}
|
|
39
39
|
export declare class FooExportResponse {
|
|
40
|
-
|
|
40
|
+
downloadUrl: string;
|
|
41
41
|
}
|
|
42
42
|
export declare class FooSampleDownloadRequest {
|
|
43
43
|
format: EntitySerializationFormat;
|
|
44
44
|
}
|
|
45
45
|
export declare class FooSampleDownloadResponse {
|
|
46
|
-
|
|
46
|
+
downloadUrl: string;
|
|
47
47
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -710,11 +710,11 @@ class EntitiesSampleDownloadAction {
|
|
|
710
710
|
this.logger = Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
711
711
|
}
|
|
712
712
|
async execute(input) {
|
|
713
|
-
this.logger.debug("
|
|
713
|
+
this.logger.debug("Sample download action started", { input });
|
|
714
714
|
const result = await this.services
|
|
715
715
|
.resolveSampleDownloadCommand()
|
|
716
716
|
.execute(input);
|
|
717
|
-
this.logger.debug("
|
|
717
|
+
this.logger.debug("Sample download action completed", { input });
|
|
718
718
|
return result;
|
|
719
719
|
}
|
|
720
720
|
}
|
|
@@ -916,7 +916,7 @@ class EntitiesExportCommand {
|
|
|
916
916
|
});
|
|
917
917
|
}
|
|
918
918
|
buildAbsoluteBucketPath(relativePath) {
|
|
919
|
-
return `${this.settings.exportBucket.rootFolderPath ?? ""}/${createDayPath(new Date())}/${relativePath}`;
|
|
919
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/exports/${createDayPath(new Date())}/${relativePath}`;
|
|
920
920
|
}
|
|
921
921
|
async getExportEntities(filters) {
|
|
922
922
|
return this.services.resolveSearchQuery().execute(filters ?? {});
|
|
@@ -937,21 +937,43 @@ class EntitiesImportCommand {
|
|
|
937
937
|
}
|
|
938
938
|
|
|
939
939
|
class EntitiesSampleDownloadCommand {
|
|
940
|
-
constructor(services) {
|
|
940
|
+
constructor(services, settings) {
|
|
941
941
|
this.services = services;
|
|
942
|
+
this.settings = settings;
|
|
942
943
|
}
|
|
943
944
|
async execute(input) {
|
|
944
945
|
const sample = await this.services
|
|
945
946
|
.resolveSerializer()
|
|
946
947
|
.createSample(input.format);
|
|
948
|
+
const downloadUrl = await this.uploadSampleFile(sample);
|
|
947
949
|
return {
|
|
948
950
|
file: {
|
|
949
951
|
content: sample.content,
|
|
950
952
|
contentType: sample.contentType,
|
|
951
953
|
name: sample.fileName,
|
|
952
954
|
},
|
|
955
|
+
downloadUrl,
|
|
953
956
|
};
|
|
954
957
|
}
|
|
958
|
+
async uploadSampleFile(file) {
|
|
959
|
+
await this.bucket.fileUpload({
|
|
960
|
+
bucket: this.settings.exportBucket.bucket,
|
|
961
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
962
|
+
content: file.content,
|
|
963
|
+
contentType: file.contentType,
|
|
964
|
+
});
|
|
965
|
+
return await this.bucket.filePublicUrlCreate({
|
|
966
|
+
bucket: this.settings.exportBucket.bucket,
|
|
967
|
+
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
968
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
buildAbsoluteBucketPath(relativePath) {
|
|
972
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/samples/${createDayPath(new Date())}/${relativePath}`;
|
|
973
|
+
}
|
|
974
|
+
get bucket() {
|
|
975
|
+
return this.services.getRootServices().resolveBucketProvider();
|
|
976
|
+
}
|
|
955
977
|
}
|
|
956
978
|
|
|
957
979
|
class EntityUpdateCommand {
|
|
@@ -2098,7 +2120,7 @@ class EntityManagerServiceCollection {
|
|
|
2098
2120
|
this.locator.registerExportAction(this.entityName, new EntitiesExportAction(this.resolver));
|
|
2099
2121
|
this.locator.registerImportCommand(this.entityName, new EntitiesImportCommand(this.resolver, settings));
|
|
2100
2122
|
this.locator.registerImportAction(this.entityName, new EntitiesImportAction(this.resolver));
|
|
2101
|
-
this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver));
|
|
2123
|
+
this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver, settings));
|
|
2102
2124
|
this.locator.registerSampleDownloadAction(this.entityName, new EntitiesSampleDownloadAction(this.resolver));
|
|
2103
2125
|
return this;
|
|
2104
2126
|
}
|