@punks/backend-entity-manager 0.0.402 → 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 +160 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/files.d.ts +1 -0
- package/dist/cjs/types/abstractions/repository.d.ts +5 -0
- package/dist/cjs/types/integrations/repository/typeorm/repository.d.ts +5 -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/cjs/types/testing/mocks/repository.d.ts +5 -0
- package/dist/esm/index.js +162 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/files.d.ts +1 -0
- package/dist/esm/types/abstractions/repository.d.ts +5 -0
- package/dist/esm/types/integrations/repository/typeorm/repository.d.ts +5 -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/esm/types/testing/mocks/repository.d.ts +5 -0
- package/dist/index.d.ts +48 -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,22 @@ class TypeOrmRepository {
|
|
|
4129
4129
|
id,
|
|
4130
4130
|
});
|
|
4131
4131
|
}
|
|
4132
|
+
// todo: fix this
|
|
4133
|
+
async upsertBy({ data, filter, }) {
|
|
4134
|
+
this.logger.debug("Upsert entities by condition", { filter, data });
|
|
4135
|
+
const current = await this.find(filter);
|
|
4136
|
+
if (current) {
|
|
4137
|
+
const id = current.id;
|
|
4138
|
+
await this.update(id, data);
|
|
4139
|
+
return {
|
|
4140
|
+
id,
|
|
4141
|
+
};
|
|
4142
|
+
}
|
|
4143
|
+
const entity = await this.create(data);
|
|
4144
|
+
return {
|
|
4145
|
+
id: entity.id,
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4132
4148
|
}
|
|
4133
4149
|
|
|
4134
4150
|
class NestEntityAuthorizationMiddleware {
|
|
@@ -22780,6 +22796,128 @@ exports.EmailService = __decorate([
|
|
|
22780
22796
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22781
22797
|
], exports.EmailService);
|
|
22782
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
|
+
|
|
22783
22921
|
exports.CacheService = class CacheService {
|
|
22784
22922
|
constructor(registry) {
|
|
22785
22923
|
this.registry = registry;
|
|
@@ -23750,14 +23888,15 @@ const Services$1 = [
|
|
|
23750
23888
|
exports.AppSessionService,
|
|
23751
23889
|
exports.AppHashingService,
|
|
23752
23890
|
exports.CacheService,
|
|
23891
|
+
exports.DataExportService,
|
|
23753
23892
|
exports.EntityManagerService,
|
|
23754
23893
|
exports.EmailService,
|
|
23755
23894
|
exports.EventsService,
|
|
23756
23895
|
exports.FilesManager,
|
|
23757
23896
|
exports.MediaLibraryService,
|
|
23897
|
+
exports.OperationLockService,
|
|
23758
23898
|
exports.SecretsService,
|
|
23759
23899
|
exports.TrackingService,
|
|
23760
|
-
exports.OperationLockService,
|
|
23761
23900
|
];
|
|
23762
23901
|
|
|
23763
23902
|
const IoC = [exports.EntityManagerRegistry];
|
|
@@ -35633,7 +35772,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35633
35772
|
async uploadFile(file) {
|
|
35634
35773
|
const path = this.getBucketFileUploadPath(file.fileName, new Date());
|
|
35635
35774
|
await this.bucket.fileUpload({
|
|
35636
|
-
bucket:
|
|
35775
|
+
bucket: this.defaultBucket,
|
|
35637
35776
|
filePath: path,
|
|
35638
35777
|
content: file.content,
|
|
35639
35778
|
contentType: file.contentType,
|
|
@@ -35644,13 +35783,13 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35644
35783
|
}
|
|
35645
35784
|
async deleteFile(reference) {
|
|
35646
35785
|
await this.bucket.fileDelete({
|
|
35647
|
-
bucket:
|
|
35786
|
+
bucket: this.defaultBucket,
|
|
35648
35787
|
filePath: reference.reference,
|
|
35649
35788
|
});
|
|
35650
35789
|
}
|
|
35651
35790
|
async downloadFile(reference) {
|
|
35652
35791
|
const content = await this.bucket.fileDownload({
|
|
35653
|
-
bucket:
|
|
35792
|
+
bucket: this.defaultBucket,
|
|
35654
35793
|
filePath: reference.reference,
|
|
35655
35794
|
});
|
|
35656
35795
|
return {
|
|
@@ -35659,7 +35798,7 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35659
35798
|
}
|
|
35660
35799
|
async getFileProviderDownloadUrl(reference) {
|
|
35661
35800
|
const url = await this.bucket.filePublicUrlCreate({
|
|
35662
|
-
bucket:
|
|
35801
|
+
bucket: this.defaultBucket,
|
|
35663
35802
|
expirationMinutes: awsBucketSettings.value.publicLinksExpirationMinutes,
|
|
35664
35803
|
filePath: reference.reference,
|
|
35665
35804
|
});
|
|
@@ -35670,6 +35809,9 @@ let AwsS3FileProvider = class AwsS3FileProvider {
|
|
|
35670
35809
|
getBucketFileUploadPath(fileName, date) {
|
|
35671
35810
|
return `${backendCore.ensureTailingSlash(awsBucketSettings.value.paths.filesUpload)}${createDayPath(date)}${backendCore.ensureStartSlash(backendCore.newUuid())}_${fileName}`;
|
|
35672
35811
|
}
|
|
35812
|
+
get defaultBucket() {
|
|
35813
|
+
return awsBucketSettings.value.defaultBucket;
|
|
35814
|
+
}
|
|
35673
35815
|
};
|
|
35674
35816
|
AwsS3FileProvider = __decorate([
|
|
35675
35817
|
WpFileProvider("awsS3"),
|
|
@@ -35745,6 +35887,9 @@ exports.InMemoryFileProvider = class InMemoryFileProvider {
|
|
|
35745
35887
|
}),
|
|
35746
35888
|
};
|
|
35747
35889
|
}
|
|
35890
|
+
get defaultBucket() {
|
|
35891
|
+
return "in-memory-bucket";
|
|
35892
|
+
}
|
|
35748
35893
|
};
|
|
35749
35894
|
exports.InMemoryFileProvider = __decorate([
|
|
35750
35895
|
WpFileProvider("inMemory"),
|