@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 CHANGED
@@ -718,11 +718,11 @@ class EntitiesSampleDownloadAction {
718
718
  this.logger = backendCore.Log.getLogger(`${services.getEntityName()} -> Import`);
719
719
  }
720
720
  async execute(input) {
721
- this.logger.debug("Import action started", { input });
721
+ this.logger.debug("Sample download action started", { input });
722
722
  const result = await this.services
723
723
  .resolveSampleDownloadCommand()
724
724
  .execute(input);
725
- this.logger.debug("Import action completed", { input });
725
+ this.logger.debug("Sample download action completed", { input });
726
726
  return result;
727
727
  }
728
728
  }
@@ -924,7 +924,7 @@ class EntitiesExportCommand {
924
924
  });
925
925
  }
926
926
  buildAbsoluteBucketPath(relativePath) {
927
- return `${this.settings.exportBucket.rootFolderPath ?? ""}/${createDayPath(new Date())}/${relativePath}`;
927
+ return `${this.settings.exportBucket.rootFolderPath ?? ""}/exports/${createDayPath(new Date())}/${relativePath}`;
928
928
  }
929
929
  async getExportEntities(filters) {
930
930
  return this.services.resolveSearchQuery().execute(filters ?? {});
@@ -945,21 +945,43 @@ class EntitiesImportCommand {
945
945
  }
946
946
 
947
947
  class EntitiesSampleDownloadCommand {
948
- constructor(services) {
948
+ constructor(services, settings) {
949
949
  this.services = services;
950
+ this.settings = settings;
950
951
  }
951
952
  async execute(input) {
952
953
  const sample = await this.services
953
954
  .resolveSerializer()
954
955
  .createSample(input.format);
956
+ const downloadUrl = await this.uploadSampleFile(sample);
955
957
  return {
956
958
  file: {
957
959
  content: sample.content,
958
960
  contentType: sample.contentType,
959
961
  name: sample.fileName,
960
962
  },
963
+ downloadUrl,
961
964
  };
962
965
  }
966
+ async uploadSampleFile(file) {
967
+ await this.bucket.fileUpload({
968
+ bucket: this.settings.exportBucket.bucket,
969
+ filePath: this.buildAbsoluteBucketPath(file.fileName),
970
+ content: file.content,
971
+ contentType: file.contentType,
972
+ });
973
+ return await this.bucket.filePublicUrlCreate({
974
+ bucket: this.settings.exportBucket.bucket,
975
+ expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
976
+ filePath: this.buildAbsoluteBucketPath(file.fileName),
977
+ });
978
+ }
979
+ buildAbsoluteBucketPath(relativePath) {
980
+ return `${this.settings.exportBucket.rootFolderPath ?? ""}/samples/${createDayPath(new Date())}/${relativePath}`;
981
+ }
982
+ get bucket() {
983
+ return this.services.getRootServices().resolveBucketProvider();
984
+ }
963
985
  }
964
986
 
965
987
  class EntityUpdateCommand {
@@ -2106,7 +2128,7 @@ class EntityManagerServiceCollection {
2106
2128
  this.locator.registerExportAction(this.entityName, new EntitiesExportAction(this.resolver));
2107
2129
  this.locator.registerImportCommand(this.entityName, new EntitiesImportCommand(this.resolver, settings));
2108
2130
  this.locator.registerImportAction(this.entityName, new EntitiesImportAction(this.resolver));
2109
- this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver));
2131
+ this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver, settings));
2110
2132
  this.locator.registerSampleDownloadAction(this.entityName, new EntitiesSampleDownloadAction(this.resolver));
2111
2133
  return this;
2112
2134
  }