@punks/backend-entity-manager 0.0.404 → 0.0.406
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 +146 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/files.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/plugins/buckets/aws-s3/provider/files.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/plugins/buckets/testing/mock.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/services/export/index.d.ts +2 -0
- package/dist/cjs/types/platforms/nest/services/export/serializer.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/services/export/service.d.ts +15 -0
- package/dist/cjs/types/platforms/nest/services/export/types.d.ts +24 -0
- package/dist/cjs/types/platforms/nest/services/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/services/providers.d.ts +2 -1
- package/dist/esm/index.js +148 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/files.d.ts +1 -0
- package/dist/esm/types/platforms/nest/plugins/buckets/aws-s3/provider/files.d.ts +1 -0
- package/dist/esm/types/platforms/nest/plugins/buckets/testing/mock.d.ts +1 -0
- package/dist/esm/types/platforms/nest/services/export/index.d.ts +2 -0
- package/dist/esm/types/platforms/nest/services/export/serializer.d.ts +13 -0
- package/dist/esm/types/platforms/nest/services/export/service.d.ts +15 -0
- package/dist/esm/types/platforms/nest/services/export/types.d.ts +24 -0
- package/dist/esm/types/platforms/nest/services/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/services/providers.d.ts +2 -1
- package/dist/index.d.ts +41 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -199,16 +199,16 @@ class EntitySeeder {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
|
|
202
|
-
const DEFAULT_DELIMITER = ";";
|
|
203
|
-
const DEFAULT_ARRAY_SEPARATOR = "|";
|
|
202
|
+
const DEFAULT_DELIMITER$1 = ";";
|
|
203
|
+
const DEFAULT_ARRAY_SEPARATOR$1 = "|";
|
|
204
204
|
const splitArrayColumn = (value, separator) => value
|
|
205
205
|
?.toString()
|
|
206
|
-
.split(separator ?? DEFAULT_ARRAY_SEPARATOR)
|
|
206
|
+
.split(separator ?? DEFAULT_ARRAY_SEPARATOR$1)
|
|
207
207
|
.filter((x) => x.trim()) ?? [];
|
|
208
|
-
const joinArrayColumn = (value, separator) => value
|
|
208
|
+
const joinArrayColumn$1 = (value, separator) => value
|
|
209
209
|
?.map((x) => x.toString().trim())
|
|
210
210
|
.filter((x) => x)
|
|
211
|
-
.join(separator ?? DEFAULT_ARRAY_SEPARATOR);
|
|
211
|
+
.join(separator ?? DEFAULT_ARRAY_SEPARATOR$1);
|
|
212
212
|
class EntitySerializer {
|
|
213
213
|
constructor(services, options) {
|
|
214
214
|
this.services = services;
|
|
@@ -242,7 +242,7 @@ class EntitySerializer {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
parseCsv(data, definition) {
|
|
245
|
-
const records = backendCore.csvParse(data, DEFAULT_DELIMITER);
|
|
245
|
+
const records = backendCore.csvParse(data, DEFAULT_DELIMITER$1);
|
|
246
246
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
247
247
|
}
|
|
248
248
|
parseXlsx(data, definition) {
|
|
@@ -338,7 +338,7 @@ class EntitySerializer {
|
|
|
338
338
|
value: () => c.sampleValue ?? "",
|
|
339
339
|
})),
|
|
340
340
|
], {
|
|
341
|
-
delimiter: DEFAULT_DELIMITER,
|
|
341
|
+
delimiter: DEFAULT_DELIMITER$1,
|
|
342
342
|
}), "utf-8"),
|
|
343
343
|
};
|
|
344
344
|
case exports.EntitySerializationFormat.Xlsx:
|
|
@@ -404,12 +404,12 @@ class EntitySerializer {
|
|
|
404
404
|
value: (item) => {
|
|
405
405
|
const value = this.getColumnValue(item, c);
|
|
406
406
|
return c.array
|
|
407
|
-
? joinArrayColumn(value, c.arraySeparator)
|
|
407
|
+
? joinArrayColumn$1(value, c.arraySeparator)
|
|
408
408
|
: value;
|
|
409
409
|
},
|
|
410
410
|
})),
|
|
411
411
|
], {
|
|
412
|
-
delimiter: DEFAULT_DELIMITER,
|
|
412
|
+
delimiter: DEFAULT_DELIMITER$1,
|
|
413
413
|
}), "utf-8"),
|
|
414
414
|
};
|
|
415
415
|
case exports.EntitySerializationFormat.Xlsx:
|
|
@@ -433,7 +433,7 @@ class EntitySerializer {
|
|
|
433
433
|
value: (item) => {
|
|
434
434
|
const value = this.getColumnValue(item, c);
|
|
435
435
|
return c.array
|
|
436
|
-
? joinArrayColumn(value, c.arraySeparator)
|
|
436
|
+
? joinArrayColumn$1(value, c.arraySeparator)
|
|
437
437
|
: value;
|
|
438
438
|
},
|
|
439
439
|
headerSize: c.colSpan,
|
|
@@ -4129,6 +4129,7 @@ class TypeOrmRepository {
|
|
|
4129
4129
|
id,
|
|
4130
4130
|
});
|
|
4131
4131
|
}
|
|
4132
|
+
// todo: fix this
|
|
4132
4133
|
async upsertBy({ data, filter, }) {
|
|
4133
4134
|
this.logger.debug("Upsert entities by condition", { filter, data });
|
|
4134
4135
|
const current = await this.find(filter);
|
|
@@ -22795,6 +22796,129 @@ exports.EmailService = __decorate([
|
|
|
22795
22796
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22796
22797
|
], exports.EmailService);
|
|
22797
22798
|
|
|
22799
|
+
exports.DataSerializationFormat = void 0;
|
|
22800
|
+
(function (DataSerializationFormat) {
|
|
22801
|
+
DataSerializationFormat["Csv"] = "csv";
|
|
22802
|
+
DataSerializationFormat["Json"] = "json";
|
|
22803
|
+
DataSerializationFormat["Xlsx"] = "xlsx";
|
|
22804
|
+
})(exports.DataSerializationFormat || (exports.DataSerializationFormat = {}));
|
|
22805
|
+
|
|
22806
|
+
const DEFAULT_DELIMITER = ";";
|
|
22807
|
+
const DEFAULT_ARRAY_SEPARATOR = "|";
|
|
22808
|
+
const joinArrayColumn = (value, separator) => value
|
|
22809
|
+
?.map((x) => x.toString().trim())
|
|
22810
|
+
.filter((x) => x)
|
|
22811
|
+
.join(separator ?? DEFAULT_ARRAY_SEPARATOR);
|
|
22812
|
+
class DataExportSerializer {
|
|
22813
|
+
serialize(items, exportParams) {
|
|
22814
|
+
switch (exportParams.format) {
|
|
22815
|
+
case exports.DataSerializationFormat.Csv:
|
|
22816
|
+
return {
|
|
22817
|
+
contentType: "text/csv",
|
|
22818
|
+
content: Buffer.from(backendCore.csvBuild(items, exportParams.columns.map((c) => ({
|
|
22819
|
+
name: c.name,
|
|
22820
|
+
value: (item) => {
|
|
22821
|
+
const value = this.getColumnValue(item, c);
|
|
22822
|
+
return c.array
|
|
22823
|
+
? joinArrayColumn(value, c.arraySeparator)
|
|
22824
|
+
: value;
|
|
22825
|
+
},
|
|
22826
|
+
})), {
|
|
22827
|
+
delimiter: DEFAULT_DELIMITER,
|
|
22828
|
+
}), "utf-8"),
|
|
22829
|
+
};
|
|
22830
|
+
case exports.DataSerializationFormat.Xlsx:
|
|
22831
|
+
return {
|
|
22832
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
22833
|
+
content: Buffer.from(backendCore.excelBuild({
|
|
22834
|
+
data: items,
|
|
22835
|
+
sheetName: exportParams.name,
|
|
22836
|
+
columns: exportParams.columns.map((c) => ({
|
|
22837
|
+
header: c.name,
|
|
22838
|
+
value: (item) => {
|
|
22839
|
+
const value = this.getColumnValue(item, c);
|
|
22840
|
+
return c.array
|
|
22841
|
+
? joinArrayColumn(value, c.arraySeparator)
|
|
22842
|
+
: value;
|
|
22843
|
+
},
|
|
22844
|
+
headerSize: c.colSpan,
|
|
22845
|
+
})),
|
|
22846
|
+
})),
|
|
22847
|
+
};
|
|
22848
|
+
case exports.DataSerializationFormat.Json:
|
|
22849
|
+
return {
|
|
22850
|
+
contentType: "application/json",
|
|
22851
|
+
content: Buffer.from(JSON.stringify(items), "utf-8"),
|
|
22852
|
+
};
|
|
22853
|
+
}
|
|
22854
|
+
}
|
|
22855
|
+
getColumnValue(item, definition) {
|
|
22856
|
+
return typeof definition.selector === "function"
|
|
22857
|
+
? definition.selector(item)
|
|
22858
|
+
: item[definition.selector];
|
|
22859
|
+
}
|
|
22860
|
+
}
|
|
22861
|
+
|
|
22862
|
+
exports.DataExportService = class DataExportService {
|
|
22863
|
+
constructor(registry) {
|
|
22864
|
+
this.registry = registry;
|
|
22865
|
+
}
|
|
22866
|
+
async exportData(data, input) {
|
|
22867
|
+
const file = await this.extractData(data, input);
|
|
22868
|
+
const downloadUrl = await this.uploadExportFile(file, {
|
|
22869
|
+
dataName: input.dataName,
|
|
22870
|
+
fileName: input.fileName,
|
|
22871
|
+
format: input.format,
|
|
22872
|
+
});
|
|
22873
|
+
return {
|
|
22874
|
+
downloadUrl,
|
|
22875
|
+
file,
|
|
22876
|
+
};
|
|
22877
|
+
}
|
|
22878
|
+
async extractData(data, input) {
|
|
22879
|
+
const content = new DataExportSerializer().serialize(data, {
|
|
22880
|
+
columns: input.columns,
|
|
22881
|
+
format: input.format,
|
|
22882
|
+
name: input.dataName,
|
|
22883
|
+
});
|
|
22884
|
+
return {
|
|
22885
|
+
content: content.content,
|
|
22886
|
+
contentType: content.contentType,
|
|
22887
|
+
};
|
|
22888
|
+
}
|
|
22889
|
+
async uploadExportFile(file, { dataName, fileName, format, }) {
|
|
22890
|
+
const filePath = this.buildExportFilePath(dataName, fileName, format);
|
|
22891
|
+
await this.defaultBucketProvider.fileUpload({
|
|
22892
|
+
bucket: this.defaultFileProvider.defaultBucket,
|
|
22893
|
+
filePath,
|
|
22894
|
+
content: file.content,
|
|
22895
|
+
contentType: file.contentType,
|
|
22896
|
+
});
|
|
22897
|
+
return await this.defaultFileProvider.getFileProviderDownloadUrl({
|
|
22898
|
+
reference: filePath,
|
|
22899
|
+
});
|
|
22900
|
+
}
|
|
22901
|
+
buildExportFilePath(dataName, fileName, format) {
|
|
22902
|
+
return `/data-export/${dataName}/${backendCore.createDayPath(new Date())}/${backendCore.newUuid()}_${fileName}.${format}`;
|
|
22903
|
+
}
|
|
22904
|
+
get defaultFileProvider() {
|
|
22905
|
+
return this.registry
|
|
22906
|
+
.getContainer()
|
|
22907
|
+
.getEntitiesServicesLocator()
|
|
22908
|
+
.resolveDefaultFilesProvider();
|
|
22909
|
+
}
|
|
22910
|
+
get defaultBucketProvider() {
|
|
22911
|
+
return this.registry
|
|
22912
|
+
.getContainer()
|
|
22913
|
+
.getEntitiesServicesLocator()
|
|
22914
|
+
.resolveDefaultBucketProvider();
|
|
22915
|
+
}
|
|
22916
|
+
};
|
|
22917
|
+
exports.DataExportService = __decorate([
|
|
22918
|
+
common.Injectable(),
|
|
22919
|
+
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22920
|
+
], exports.DataExportService);
|
|
22921
|
+
|
|
22798
22922
|
exports.CacheService = class CacheService {
|
|
22799
22923
|
constructor(registry) {
|
|
22800
22924
|
this.registry = registry;
|
|
@@ -23765,14 +23889,15 @@ const Services$1 = [
|
|
|
23765
23889
|
exports.AppSessionService,
|
|
23766
23890
|
exports.AppHashingService,
|
|
23767
23891
|
exports.CacheService,
|
|
23892
|
+
exports.DataExportService,
|
|
23768
23893
|
exports.EntityManagerService,
|
|
23769
23894
|
exports.EmailService,
|
|
23770
23895
|
exports.EventsService,
|
|
23771
23896
|
exports.FilesManager,
|
|
23772
23897
|
exports.MediaLibraryService,
|
|
23898
|
+
exports.OperationLockService,
|
|
23773
23899
|
exports.SecretsService,
|
|
23774
23900
|
exports.TrackingService,
|
|
23775
|
-
exports.OperationLockService,
|
|
23776
23901
|
];
|
|
23777
23902
|
|
|
23778
23903
|
const IoC = [exports.EntityManagerRegistry];
|
|
@@ -35648,7 +35773,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35648
35773
|
async uploadFile(file) {
|
|
35649
35774
|
const path = this.getBucketFileUploadPath(file.fileName, new Date());
|
|
35650
35775
|
await this.bucket.fileUpload({
|
|
35651
|
-
bucket:
|
|
35776
|
+
bucket: this.defaultBucket,
|
|
35652
35777
|
filePath: path,
|
|
35653
35778
|
content: file.content,
|
|
35654
35779
|
contentType: file.contentType,
|
|
@@ -35659,13 +35784,13 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35659
35784
|
}
|
|
35660
35785
|
async deleteFile(reference) {
|
|
35661
35786
|
await this.bucket.fileDelete({
|
|
35662
|
-
bucket:
|
|
35787
|
+
bucket: this.defaultBucket,
|
|
35663
35788
|
filePath: reference.reference,
|
|
35664
35789
|
});
|
|
35665
35790
|
}
|
|
35666
35791
|
async downloadFile(reference) {
|
|
35667
35792
|
const content = await this.bucket.fileDownload({
|
|
35668
|
-
bucket:
|
|
35793
|
+
bucket: this.defaultBucket,
|
|
35669
35794
|
filePath: reference.reference,
|
|
35670
35795
|
});
|
|
35671
35796
|
return {
|
|
@@ -35674,7 +35799,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35674
35799
|
}
|
|
35675
35800
|
async getFileProviderDownloadUrl(reference) {
|
|
35676
35801
|
const url = await this.bucket.filePublicUrlCreate({
|
|
35677
|
-
bucket:
|
|
35802
|
+
bucket: this.defaultBucket,
|
|
35678
35803
|
expirationMinutes: awsBucketSettings.value.publicLinksExpirationMinutes,
|
|
35679
35804
|
filePath: reference.reference,
|
|
35680
35805
|
});
|
|
@@ -35685,6 +35810,9 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35685
35810
|
getBucketFileUploadPath(fileName, date) {
|
|
35686
35811
|
return `${backendCore.ensureTailingSlash(awsBucketSettings.value.paths.filesUpload)}${createDayPath(date)}${backendCore.ensureStartSlash(backendCore.newUuid())}_${fileName}`;
|
|
35687
35812
|
}
|
|
35813
|
+
get defaultBucket() {
|
|
35814
|
+
return awsBucketSettings.value.defaultBucket;
|
|
35815
|
+
}
|
|
35688
35816
|
};
|
|
35689
35817
|
AwsS3FileProvider = __decorate([
|
|
35690
35818
|
WpFileProvider("awsS3"),
|
|
@@ -35760,6 +35888,9 @@ exports.InMemoryFileProvider = class InMemoryFileProvider {
|
|
|
35760
35888
|
}),
|
|
35761
35889
|
};
|
|
35762
35890
|
}
|
|
35891
|
+
get defaultBucket() {
|
|
35892
|
+
return "in-memory-bucket";
|
|
35893
|
+
}
|
|
35763
35894
|
};
|
|
35764
35895
|
exports.InMemoryFileProvider = __decorate([
|
|
35765
35896
|
WpFileProvider("inMemory"),
|