nestjs-export-module 1.0.1 → 1.1.0
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/LICENSE +21 -0
- package/README.md +19 -87
- package/dist/data-exporter/dto/data-export-args.dto.d.ts +14 -1
- package/dist/data-exporter/dto/data-export-args.dto.js +9 -1
- package/dist/data-exporter/dto/data-export-args.dto.js.map +1 -1
- package/dist/data-exporter/dto/index.d.ts +1 -0
- package/dist/data-exporter/dto/index.js +1 -0
- package/dist/data-exporter/dto/index.js.map +1 -1
- package/dist/data-exporter/providers/csv/csv.service.d.ts +3 -1
- package/dist/data-exporter/providers/csv/csv.service.js +45 -7
- package/dist/data-exporter/providers/csv/csv.service.js.map +1 -1
- package/dist/data-exporter/providers/excel/excel.service.d.ts +1 -0
- package/dist/data-exporter/providers/excel/excel.service.js +26 -2
- package/dist/data-exporter/providers/excel/excel.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Novatorsoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,98 +1,30 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
|
3
|
-
</p>
|
|
1
|
+
<p align="center"><a href="https://novatorsoft.com" target="_blank"><img src="https://os.novatorsoft.com/novatorsoft/dark-logo.png" width="700" alt="Novatorsoft Logo"/></a></p>
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
<h1 align="center">NestJS Export Module</h1>
|
|
4
|
+
<p align="center">A NestJS export module that provides a provider-based abstraction for generating and handling data exports in different formats.</p>
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<a href="https://
|
|
11
|
-
<a href="https://www.npmjs.com
|
|
12
|
-
<a href="https://www.npmjs.com
|
|
13
|
-
<a href="https://
|
|
14
|
-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
|
15
|
-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
|
16
|
-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
|
17
|
-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
|
18
|
-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
|
19
|
-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://sonarcloud.io/summary/overall?id=novatorsoft_nestjs-export-module" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=novatorsoft_nestjs-export-module&metric=alert_status"/></a>
|
|
8
|
+
<a href="https://sonarcloud.io/summary/overall?id=novatorsoft_nestjs-export-module" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=novatorsoft_nestjs-export-module&metric=coverage"/></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/nestjs-export-module" target="_blank"><img src="https://img.shields.io/npm/v/nestjs-export-module.svg" alt="NPM Version" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/nestjs-export-module" target="_blank"><img src="https://img.shields.io/npm/l/nestjs-export-module.svg" alt="Package License" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/nestjs-export-module" target="_blank"><img src="https://img.shields.io/npm/dm/nestjs-export-module.svg" alt="NPM Downloads" /></a>
|
|
20
12
|
</p>
|
|
21
|
-
<!--[](https://opencollective.com/nest#backer)
|
|
22
|
-
[](https://opencollective.com/nest#sponsor)-->
|
|
23
|
-
|
|
24
|
-
## Description
|
|
25
|
-
|
|
26
|
-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
|
27
|
-
|
|
28
|
-
## Project setup
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
$ yarn install
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Compile and run the project
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
# development
|
|
38
|
-
$ yarn run start
|
|
39
|
-
|
|
40
|
-
# watch mode
|
|
41
|
-
$ yarn run start:dev
|
|
42
|
-
|
|
43
|
-
# production mode
|
|
44
|
-
$ yarn run start:prod
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Run tests
|
|
48
13
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# e2e tests
|
|
54
|
-
$ yarn run test:e2e
|
|
55
|
-
|
|
56
|
-
# test coverage
|
|
57
|
-
$ yarn run test:cov
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Deployment
|
|
61
|
-
|
|
62
|
-
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
|
|
63
|
-
|
|
64
|
-
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
$ yarn install -g @nestjs/mau
|
|
68
|
-
$ mau deploy
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
|
|
72
|
-
|
|
73
|
-
## Resources
|
|
74
|
-
|
|
75
|
-
Check out a few resources that may come in handy when working with NestJS:
|
|
76
|
-
|
|
77
|
-
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
|
78
|
-
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
|
79
|
-
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
|
80
|
-
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
|
81
|
-
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
|
82
|
-
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
|
83
|
-
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
|
84
|
-
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.instagram.com/novatorsoft/" target="_blank"><img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white" alt="Instagram" /></a>
|
|
16
|
+
<a href="https://www.linkedin.com/company/novatorsoft/" target="_blank"><img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn" /></a>
|
|
17
|
+
</p>
|
|
85
18
|
|
|
86
|
-
##
|
|
19
|
+
## About
|
|
87
20
|
|
|
88
|
-
|
|
21
|
+
NestJS Export Module helps you standardize export flows by exposing a single `DataExporterService` API while keeping provider-specific details (such as file format, transformation rules, and output options) configurable.
|
|
89
22
|
|
|
90
|
-
##
|
|
23
|
+
## Documentation
|
|
91
24
|
|
|
92
|
-
|
|
93
|
-
-
|
|
94
|
-
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
|
25
|
+
For installation, usage, configuration, and examples, see the documentation:
|
|
26
|
+
- [Documentation](https://opensource.novatorsoft.com/docs/nestjs-export-module/intro)
|
|
95
27
|
|
|
96
28
|
## License
|
|
97
29
|
|
|
98
|
-
|
|
30
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { CsvDataExportArgs, ExcelDataExportArgs } from '../providers';
|
|
2
2
|
import { DataExporterType } from '../enum';
|
|
3
|
+
export declare class PaginationArgs {
|
|
4
|
+
limit?: number;
|
|
5
|
+
offset?: number;
|
|
6
|
+
nextCursor?: string;
|
|
7
|
+
data?: Record<string, any>;
|
|
8
|
+
}
|
|
3
9
|
export declare class DataExportBaseArgs {
|
|
4
10
|
type: DataExporterType;
|
|
5
|
-
|
|
11
|
+
paginationOptions?: {
|
|
12
|
+
limit?: number;
|
|
13
|
+
data?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
data: Array<object> | ((args: PaginationArgs) => Promise<{
|
|
16
|
+
data: Array<object>;
|
|
17
|
+
nextCursor?: string;
|
|
18
|
+
}>);
|
|
6
19
|
}
|
|
7
20
|
export type DataExportArgs = CsvDataExportArgs | ExcelDataExportArgs;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataExportBaseArgs = void 0;
|
|
3
|
+
exports.DataExportBaseArgs = exports.PaginationArgs = void 0;
|
|
4
|
+
class PaginationArgs {
|
|
5
|
+
limit;
|
|
6
|
+
offset;
|
|
7
|
+
nextCursor;
|
|
8
|
+
data;
|
|
9
|
+
}
|
|
10
|
+
exports.PaginationArgs = PaginationArgs;
|
|
4
11
|
class DataExportBaseArgs {
|
|
5
12
|
type;
|
|
13
|
+
paginationOptions;
|
|
6
14
|
data;
|
|
7
15
|
}
|
|
8
16
|
exports.DataExportBaseArgs = DataExportBaseArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-export-args.dto.js","sourceRoot":"","sources":["../../../src/data-exporter/dto/data-export-args.dto.ts"],"names":[],"mappings":";;;AAIA,MAAa,kBAAkB;IAC7B,IAAI,CAAmB;IACvB,IAAI,
|
|
1
|
+
{"version":3,"file":"data-export-args.dto.js","sourceRoot":"","sources":["../../../src/data-exporter/dto/data-export-args.dto.ts"],"names":[],"mappings":";;;AAIA,MAAa,cAAc;IACzB,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,UAAU,CAAU;IACpB,IAAI,CAAuB;CAC5B;AALD,wCAKC;AAED,MAAa,kBAAkB;IAC7B,IAAI,CAAmB;IACvB,iBAAiB,CAGf;IACF,IAAI,CAKI;CACT;AAZD,gDAYC"}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./data-export-result.dto"), exports);
|
|
18
|
+
__exportStar(require("./data-export-args.dto"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-exporter/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-exporter/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,yDAAuC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { CsvDataExportArgs } from './dto';
|
|
2
1
|
import { DataExportResult } from '../../dto';
|
|
2
|
+
import { CsvDataExportArgs } from './dto';
|
|
3
3
|
import { DataExporterBaseService } from '../../data-exporter-base.service';
|
|
4
4
|
export declare class CsvService extends DataExporterBaseService {
|
|
5
5
|
exportAsync(dataExportArgs: CsvDataExportArgs): Promise<DataExportResult>;
|
|
6
|
+
private exportObject;
|
|
7
|
+
private exportPaginationArgsAsync;
|
|
6
8
|
}
|
|
@@ -14,20 +14,58 @@ const nestjs_factory_pattern_module_1 = require("nestjs-factory-pattern-module")
|
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const json_2_csv_1 = require("json-2-csv");
|
|
16
16
|
let CsvService = class CsvService extends data_exporter_base_service_1.DataExporterBaseService {
|
|
17
|
-
exportAsync(dataExportArgs) {
|
|
18
|
-
|
|
17
|
+
async exportAsync(dataExportArgs) {
|
|
18
|
+
let data;
|
|
19
|
+
if (Array.isArray(dataExportArgs.data)) {
|
|
20
|
+
data = this.exportObject(dataExportArgs.data, dataExportArgs);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
data = await this.exportPaginationArgsAsync(dataExportArgs);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
mimeType: 'text/csv',
|
|
27
|
+
extension: 'csv',
|
|
28
|
+
data: data,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exportObject(rows, dataExportArgs, includeHeaders = true) {
|
|
32
|
+
const data = (0, json_2_csv_1.json2csv)(rows, {
|
|
19
33
|
keys: dataExportArgs.options?.headers,
|
|
20
34
|
fieldTitleMap: dataExportArgs.options?.headersMap,
|
|
35
|
+
prependHeader: includeHeaders,
|
|
21
36
|
delimiter: {
|
|
22
37
|
field: dataExportArgs.options?.delimiter ?? ',',
|
|
23
38
|
wrap: dataExportArgs.options?.quote,
|
|
24
39
|
},
|
|
25
40
|
});
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
return Buffer.from(data, dataExportArgs.options?.encoding ?? 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
async exportPaginationArgsAsync(dataExportArgs) {
|
|
44
|
+
const limit = dataExportArgs.paginationOptions?.limit ?? 100;
|
|
45
|
+
const encoding = dataExportArgs.options?.encoding ?? 'utf-8';
|
|
46
|
+
const newline = Buffer.from('\n', encoding);
|
|
47
|
+
const chunks = [];
|
|
48
|
+
let offset = 0;
|
|
49
|
+
let result = {
|
|
50
|
+
data: [],
|
|
51
|
+
};
|
|
52
|
+
do {
|
|
53
|
+
result = await dataExportArgs.data({
|
|
54
|
+
limit,
|
|
55
|
+
...(result.nextCursor ? { nextCursor: result.nextCursor } : { offset }),
|
|
56
|
+
...(dataExportArgs?.paginationOptions?.data && {
|
|
57
|
+
data: dataExportArgs?.paginationOptions?.data,
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
if (!result.data.length)
|
|
61
|
+
break;
|
|
62
|
+
const chunk = this.exportObject(result.data, dataExportArgs, offset === 0);
|
|
63
|
+
if (offset !== 0)
|
|
64
|
+
chunks.push(newline);
|
|
65
|
+
chunks.push(chunk);
|
|
66
|
+
offset += limit;
|
|
67
|
+
} while (result.data.length === limit);
|
|
68
|
+
return Buffer.concat(chunks);
|
|
31
69
|
}
|
|
32
70
|
};
|
|
33
71
|
exports.CsvService = CsvService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv.service.js","sourceRoot":"","sources":["../../../../src/data-exporter/providers/csv/csv.service.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"csv.service.js","sourceRoot":"","sources":["../../../../src/data-exporter/providers/csv/csv.service.ts"],"names":[],"mappings":";;;;;;;;;AAGA,+CAA8D;AAC9D,iFAA2E;AAC3E,qCAA8C;AAC9C,iFAAgE;AAChE,2CAA4C;AAC5C,2CAAsC;AAI/B,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,oDAAuB;IACrD,KAAK,CAAC,WAAW,CACf,cAAiC;QAEjC,IAAI,IAAY,CAAC;QACjB,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;IAEO,YAAY,CAClB,IAAmB,EACnB,cAAiC,EACjC,iBAA0B,IAAI;QAE9B,MAAM,IAAI,GAAG,IAAA,qBAAQ,EAAC,IAAI,EAAE;YAC1B,IAAI,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO;YACrC,aAAa,EAAE,cAAc,CAAC,OAAO,EAAE,UAAU;YACjD,aAAa,EAAE,cAAc;YAC7B,SAAS,EAAE;gBACT,KAAK,EAAE,cAAc,CAAC,OAAO,EAAE,SAAS,IAAI,GAAG;gBAC/C,I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CAAC,CAAC;YAEnB,MAAM,IAAI,KAAK,CAAC;QAClB,CAAC,QAAQ,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,EAAE;QAEvC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AA9EY,gCAAU;qBAAV,UAAU;IAFtB,IAAA,mBAAU,GAAE;IACZ,IAAA,+CAAe,EAAC,uCAA2B,EAAE,uBAAgB,CAAC,GAAG,CAAC;GACtD,UAAU,CA8EtB"}
|
|
@@ -3,5 +3,6 @@ import { DataExporterBaseService } from '../../data-exporter-base.service';
|
|
|
3
3
|
import { ExcelDataExportArgs } from './dto';
|
|
4
4
|
export declare class ExcelService extends DataExporterBaseService {
|
|
5
5
|
exportAsync(dataExportArgs: ExcelDataExportArgs): Promise<DataExportResult>;
|
|
6
|
+
private addDataToWorksheetAsync;
|
|
6
7
|
private getHeaders;
|
|
7
8
|
}
|
|
@@ -50,8 +50,12 @@ let ExcelService = class ExcelService extends data_exporter_base_service_1.DataE
|
|
|
50
50
|
async exportAsync(dataExportArgs) {
|
|
51
51
|
const workbook = new ExcelJS.Workbook();
|
|
52
52
|
const worksheet = workbook.addWorksheet(dataExportArgs.options?.sheetName ?? 'Sheet1');
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (Array.isArray(dataExportArgs.data)) {
|
|
54
|
+
worksheet.columns = this.getHeaders(dataExportArgs.data.at(0) ?? {}, dataExportArgs.options);
|
|
55
|
+
worksheet.addRows(dataExportArgs.data);
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
await this.addDataToWorksheetAsync(dataExportArgs, worksheet);
|
|
55
59
|
const data = await workbook.xlsx.writeBuffer();
|
|
56
60
|
return {
|
|
57
61
|
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
@@ -59,6 +63,26 @@ let ExcelService = class ExcelService extends data_exporter_base_service_1.DataE
|
|
|
59
63
|
data: data,
|
|
60
64
|
};
|
|
61
65
|
}
|
|
66
|
+
async addDataToWorksheetAsync(dataExportArgs, worksheet) {
|
|
67
|
+
const limit = dataExportArgs.paginationOptions?.limit ?? 100;
|
|
68
|
+
let offset = 0;
|
|
69
|
+
let result = {
|
|
70
|
+
data: [],
|
|
71
|
+
};
|
|
72
|
+
do {
|
|
73
|
+
result = await dataExportArgs.data({
|
|
74
|
+
limit,
|
|
75
|
+
...(result.nextCursor ? { nextCursor: result.nextCursor } : { offset }),
|
|
76
|
+
...(dataExportArgs?.paginationOptions?.data && {
|
|
77
|
+
data: dataExportArgs?.paginationOptions?.data,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
if (offset === 0)
|
|
81
|
+
worksheet.columns = this.getHeaders(result.data.at(0) ?? {}, dataExportArgs.options);
|
|
82
|
+
worksheet.addRows(result.data);
|
|
83
|
+
offset += limit;
|
|
84
|
+
} while (result.data.length === limit);
|
|
85
|
+
}
|
|
62
86
|
getHeaders(firstRowData, options) {
|
|
63
87
|
let result = [];
|
|
64
88
|
if (options?.headers)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excel.service.js","sourceRoot":"","sources":["../../../../src/data-exporter/providers/excel/excel.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;
|
|
1
|
+
{"version":3,"file":"excel.service.js","sourceRoot":"","sources":["../../../../src/data-exporter/providers/excel/excel.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAInC,+CAA8D;AAC9D,iFAA2E;AAC3E,qCAA8C;AAE9C,iFAAgE;AAChE,2CAA4C;AAIrC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,oDAAuB;IACvD,KAAK,CAAC,WAAW,CACf,cAAmC;QAEnC,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACxC,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