@punks/backend-entity-manager 0.0.404 → 0.0.405
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 +145 -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 +23 -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 +147 -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 +23 -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 +40 -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,128 @@ 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.name,
|
|
22870
|
+
format: input.format,
|
|
22871
|
+
});
|
|
22872
|
+
return {
|
|
22873
|
+
downloadUrl,
|
|
22874
|
+
file,
|
|
22875
|
+
};
|
|
22876
|
+
}
|
|
22877
|
+
async extractData(data, input) {
|
|
22878
|
+
const content = new DataExportSerializer().serialize(data, {
|
|
22879
|
+
columns: input.columns,
|
|
22880
|
+
format: input.format,
|
|
22881
|
+
name: input.name,
|
|
22882
|
+
});
|
|
22883
|
+
return {
|
|
22884
|
+
content: content.content,
|
|
22885
|
+
contentType: content.contentType,
|
|
22886
|
+
};
|
|
22887
|
+
}
|
|
22888
|
+
async uploadExportFile(file, { dataName, format, }) {
|
|
22889
|
+
const filePath = this.buildExportFilePath(dataName, format);
|
|
22890
|
+
await this.defaultBucketProvider.fileUpload({
|
|
22891
|
+
bucket: this.defaultFileProvider.defaultBucket,
|
|
22892
|
+
filePath,
|
|
22893
|
+
content: file.content,
|
|
22894
|
+
contentType: file.contentType,
|
|
22895
|
+
});
|
|
22896
|
+
return await this.defaultFileProvider.getFileProviderDownloadUrl({
|
|
22897
|
+
reference: filePath,
|
|
22898
|
+
});
|
|
22899
|
+
}
|
|
22900
|
+
buildExportFilePath(dataName, format) {
|
|
22901
|
+
return `/data-export/${dataName}/${backendCore.createDayPath(new Date())}/${backendCore.newUuid()}_${dataName}.${format}`;
|
|
22902
|
+
}
|
|
22903
|
+
get defaultFileProvider() {
|
|
22904
|
+
return this.registry
|
|
22905
|
+
.getContainer()
|
|
22906
|
+
.getEntitiesServicesLocator()
|
|
22907
|
+
.resolveDefaultFilesProvider();
|
|
22908
|
+
}
|
|
22909
|
+
get defaultBucketProvider() {
|
|
22910
|
+
return this.registry
|
|
22911
|
+
.getContainer()
|
|
22912
|
+
.getEntitiesServicesLocator()
|
|
22913
|
+
.resolveDefaultBucketProvider();
|
|
22914
|
+
}
|
|
22915
|
+
};
|
|
22916
|
+
exports.DataExportService = __decorate([
|
|
22917
|
+
common.Injectable(),
|
|
22918
|
+
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22919
|
+
], exports.DataExportService);
|
|
22920
|
+
|
|
22798
22921
|
exports.CacheService = class CacheService {
|
|
22799
22922
|
constructor(registry) {
|
|
22800
22923
|
this.registry = registry;
|
|
@@ -23765,14 +23888,15 @@ const Services$1 = [
|
|
|
23765
23888
|
exports.AppSessionService,
|
|
23766
23889
|
exports.AppHashingService,
|
|
23767
23890
|
exports.CacheService,
|
|
23891
|
+
exports.DataExportService,
|
|
23768
23892
|
exports.EntityManagerService,
|
|
23769
23893
|
exports.EmailService,
|
|
23770
23894
|
exports.EventsService,
|
|
23771
23895
|
exports.FilesManager,
|
|
23772
23896
|
exports.MediaLibraryService,
|
|
23897
|
+
exports.OperationLockService,
|
|
23773
23898
|
exports.SecretsService,
|
|
23774
23899
|
exports.TrackingService,
|
|
23775
|
-
exports.OperationLockService,
|
|
23776
23900
|
];
|
|
23777
23901
|
|
|
23778
23902
|
const IoC = [exports.EntityManagerRegistry];
|
|
@@ -35648,7 +35772,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35648
35772
|
async uploadFile(file) {
|
|
35649
35773
|
const path = this.getBucketFileUploadPath(file.fileName, new Date());
|
|
35650
35774
|
await this.bucket.fileUpload({
|
|
35651
|
-
bucket:
|
|
35775
|
+
bucket: this.defaultBucket,
|
|
35652
35776
|
filePath: path,
|
|
35653
35777
|
content: file.content,
|
|
35654
35778
|
contentType: file.contentType,
|
|
@@ -35659,13 +35783,13 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35659
35783
|
}
|
|
35660
35784
|
async deleteFile(reference) {
|
|
35661
35785
|
await this.bucket.fileDelete({
|
|
35662
|
-
bucket:
|
|
35786
|
+
bucket: this.defaultBucket,
|
|
35663
35787
|
filePath: reference.reference,
|
|
35664
35788
|
});
|
|
35665
35789
|
}
|
|
35666
35790
|
async downloadFile(reference) {
|
|
35667
35791
|
const content = await this.bucket.fileDownload({
|
|
35668
|
-
bucket:
|
|
35792
|
+
bucket: this.defaultBucket,
|
|
35669
35793
|
filePath: reference.reference,
|
|
35670
35794
|
});
|
|
35671
35795
|
return {
|
|
@@ -35674,7 +35798,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35674
35798
|
}
|
|
35675
35799
|
async getFileProviderDownloadUrl(reference) {
|
|
35676
35800
|
const url = await this.bucket.filePublicUrlCreate({
|
|
35677
|
-
bucket:
|
|
35801
|
+
bucket: this.defaultBucket,
|
|
35678
35802
|
expirationMinutes: awsBucketSettings.value.publicLinksExpirationMinutes,
|
|
35679
35803
|
filePath: reference.reference,
|
|
35680
35804
|
});
|
|
@@ -35685,6 +35809,9 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35685
35809
|
getBucketFileUploadPath(fileName, date) {
|
|
35686
35810
|
return `${backendCore.ensureTailingSlash(awsBucketSettings.value.paths.filesUpload)}${createDayPath(date)}${backendCore.ensureStartSlash(backendCore.newUuid())}_${fileName}`;
|
|
35687
35811
|
}
|
|
35812
|
+
get defaultBucket() {
|
|
35813
|
+
return awsBucketSettings.value.defaultBucket;
|
|
35814
|
+
}
|
|
35688
35815
|
};
|
|
35689
35816
|
AwsS3FileProvider = __decorate([
|
|
35690
35817
|
WpFileProvider("awsS3"),
|
|
@@ -35760,6 +35887,9 @@ exports.InMemoryFileProvider = class InMemoryFileProvider {
|
|
|
35760
35887
|
}),
|
|
35761
35888
|
};
|
|
35762
35889
|
}
|
|
35890
|
+
get defaultBucket() {
|
|
35891
|
+
return "in-memory-bucket";
|
|
35892
|
+
}
|
|
35763
35893
|
};
|
|
35764
35894
|
exports.InMemoryFileProvider = __decorate([
|
|
35765
35895
|
WpFileProvider("inMemory"),
|