@punks/backend-entity-manager 0.0.89 → 0.0.91
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 +48 -14
- 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 +48 -14
- 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
package/dist/cjs/index.js
CHANGED
|
@@ -148,10 +148,16 @@ class EntitySerializer {
|
|
|
148
148
|
return {
|
|
149
149
|
fileName,
|
|
150
150
|
contentType: "text/csv",
|
|
151
|
-
content: Buffer.from(backendCore.csvBuild([{}],
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
content: Buffer.from(backendCore.csvBuild([{}], [
|
|
152
|
+
{
|
|
153
|
+
name: "_type",
|
|
154
|
+
value: () => this.entityName,
|
|
155
|
+
},
|
|
156
|
+
...this.getDefinition().columns.map((c) => ({
|
|
157
|
+
name: c.name,
|
|
158
|
+
value: () => c.sampleValue ?? "",
|
|
159
|
+
})),
|
|
160
|
+
]), "utf-8"),
|
|
155
161
|
};
|
|
156
162
|
case exports.EntitySerializationFormat.Xlsx:
|
|
157
163
|
return {
|
|
@@ -160,11 +166,17 @@ class EntitySerializer {
|
|
|
160
166
|
content: Buffer.from(backendCore.excelBuild({
|
|
161
167
|
data: [{}],
|
|
162
168
|
sheetName: this.entityName,
|
|
163
|
-
columns:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
columns: [
|
|
170
|
+
{
|
|
171
|
+
header: "_type",
|
|
172
|
+
value: () => this.entityName,
|
|
173
|
+
},
|
|
174
|
+
...this.getDefinition().columns.map((c) => ({
|
|
175
|
+
header: c.name,
|
|
176
|
+
value: () => c.sampleValue ?? "",
|
|
177
|
+
headerSize: c.colSpan,
|
|
178
|
+
})),
|
|
179
|
+
],
|
|
168
180
|
})),
|
|
169
181
|
};
|
|
170
182
|
case exports.EntitySerializationFormat.Json:
|
|
@@ -718,11 +730,11 @@ class EntitiesSampleDownloadAction {
|
|
|
718
730
|
this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
719
731
|
}
|
|
720
732
|
async execute(input) {
|
|
721
|
-
this.logger.debug("
|
|
733
|
+
this.logger.debug("Sample download action started", { input });
|
|
722
734
|
const result = await this.services
|
|
723
735
|
.resolveSampleDownloadCommand()
|
|
724
736
|
.execute(input);
|
|
725
|
-
this.logger.debug("
|
|
737
|
+
this.logger.debug("Sample download action completed", { input });
|
|
726
738
|
return result;
|
|
727
739
|
}
|
|
728
740
|
}
|
|
@@ -924,7 +936,7 @@ class EntitiesExportCommand {
|
|
|
924
936
|
});
|
|
925
937
|
}
|
|
926
938
|
buildAbsoluteBucketPath(relativePath) {
|
|
927
|
-
return `${this.settings.exportBucket.rootFolderPath ?? ""}/${createDayPath(new Date())}/${relativePath}`;
|
|
939
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/exports/${createDayPath(new Date())}/${relativePath}`;
|
|
928
940
|
}
|
|
929
941
|
async getExportEntities(filters) {
|
|
930
942
|
return this.services.resolveSearchQuery().execute(filters ?? {});
|
|
@@ -945,21 +957,43 @@ class EntitiesImportCommand {
|
|
|
945
957
|
}
|
|
946
958
|
|
|
947
959
|
class EntitiesSampleDownloadCommand {
|
|
948
|
-
constructor(services) {
|
|
960
|
+
constructor(services, settings) {
|
|
949
961
|
this.services = services;
|
|
962
|
+
this.settings = settings;
|
|
950
963
|
}
|
|
951
964
|
async execute(input) {
|
|
952
965
|
const sample = await this.services
|
|
953
966
|
.resolveSerializer()
|
|
954
967
|
.createSample(input.format);
|
|
968
|
+
const downloadUrl = await this.uploadSampleFile(sample);
|
|
955
969
|
return {
|
|
956
970
|
file: {
|
|
957
971
|
content: sample.content,
|
|
958
972
|
contentType: sample.contentType,
|
|
959
973
|
name: sample.fileName,
|
|
960
974
|
},
|
|
975
|
+
downloadUrl,
|
|
961
976
|
};
|
|
962
977
|
}
|
|
978
|
+
async uploadSampleFile(file) {
|
|
979
|
+
await this.bucket.fileUpload({
|
|
980
|
+
bucket: this.settings.exportBucket.bucket,
|
|
981
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
982
|
+
content: file.content,
|
|
983
|
+
contentType: file.contentType,
|
|
984
|
+
});
|
|
985
|
+
return await this.bucket.filePublicUrlCreate({
|
|
986
|
+
bucket: this.settings.exportBucket.bucket,
|
|
987
|
+
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
988
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
buildAbsoluteBucketPath(relativePath) {
|
|
992
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/samples/${createDayPath(new Date())}/${relativePath}`;
|
|
993
|
+
}
|
|
994
|
+
get bucket() {
|
|
995
|
+
return this.services.getRootServices().resolveBucketProvider();
|
|
996
|
+
}
|
|
963
997
|
}
|
|
964
998
|
|
|
965
999
|
class EntityUpdateCommand {
|
|
@@ -2106,7 +2140,7 @@ class EntityManagerServiceCollection {
|
|
|
2106
2140
|
this.locator.registerExportAction(this.entityName, new EntitiesExportAction(this.resolver));
|
|
2107
2141
|
this.locator.registerImportCommand(this.entityName, new EntitiesImportCommand(this.resolver, settings));
|
|
2108
2142
|
this.locator.registerImportAction(this.entityName, new EntitiesImportAction(this.resolver));
|
|
2109
|
-
this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver));
|
|
2143
|
+
this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver, settings));
|
|
2110
2144
|
this.locator.registerSampleDownloadAction(this.entityName, new EntitiesSampleDownloadAction(this.resolver));
|
|
2111
2145
|
return this;
|
|
2112
2146
|
}
|