jasper_nodejs 1.0.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/dist/index.d.ts +27 -0
- package/dist/index.js +61 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface DbConfig {
|
|
2
|
+
driver: string;
|
|
3
|
+
host: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
dbname: string;
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
}
|
|
9
|
+
interface ExportOptions {
|
|
10
|
+
reportFile: string;
|
|
11
|
+
outputDir: string;
|
|
12
|
+
format?: string;
|
|
13
|
+
params?: Record<string, any>;
|
|
14
|
+
db?: DbConfig | null;
|
|
15
|
+
}
|
|
16
|
+
interface ReportServiceOptions {
|
|
17
|
+
jasperBinaryPath?: string;
|
|
18
|
+
basePath?: string;
|
|
19
|
+
}
|
|
20
|
+
declare class ReportService {
|
|
21
|
+
private jasperPath;
|
|
22
|
+
constructor(options?: ReportServiceOptions);
|
|
23
|
+
private compileJrxml;
|
|
24
|
+
export(options: ExportOptions): Promise<string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { type DbConfig, type ExportOptions, type ReportServiceOptions, ReportService as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { exec } from "child_process";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
var execAsync = promisify(exec);
|
|
6
|
+
var ReportService = class {
|
|
7
|
+
jasperPath;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
const basePath = options.basePath ?? process.cwd();
|
|
10
|
+
this.jasperPath = options.jasperBinaryPath ?? path.join(basePath, "jasper", "bin", "jasper");
|
|
11
|
+
}
|
|
12
|
+
async compileJrxml(jrxmlPath) {
|
|
13
|
+
const outputDir = path.dirname(jrxmlPath);
|
|
14
|
+
const outputFile = path.join(
|
|
15
|
+
outputDir,
|
|
16
|
+
`${path.basename(jrxmlPath, ".jrxml")}.jasper`
|
|
17
|
+
);
|
|
18
|
+
const cmd = `"${this.jasperPath}" compile "${jrxmlPath}" -o "${outputDir}"`;
|
|
19
|
+
try {
|
|
20
|
+
const { stderr } = await execAsync(cmd);
|
|
21
|
+
if (stderr) {
|
|
22
|
+
console.warn("\u26A0\uFE0F Jasper stderr:", stderr);
|
|
23
|
+
}
|
|
24
|
+
return outputFile;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`\u274C Failed to compile jrxml: ${(err == null ? void 0 : err.stderr) || (err == null ? void 0 : err.message) || err}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async export(options) {
|
|
32
|
+
const {
|
|
33
|
+
reportFile,
|
|
34
|
+
outputDir,
|
|
35
|
+
format = "pdf",
|
|
36
|
+
params = {},
|
|
37
|
+
db = null
|
|
38
|
+
} = options;
|
|
39
|
+
let reportToUse = reportFile;
|
|
40
|
+
if (path.extname(reportFile) === ".jrxml") {
|
|
41
|
+
reportToUse = await this.compileJrxml(reportFile);
|
|
42
|
+
}
|
|
43
|
+
const paramString = Object.entries(params).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
44
|
+
let dbString = "";
|
|
45
|
+
if (db) {
|
|
46
|
+
dbString = ` -t ${db.driver} -H ${db.host}${db.port ? ` --db-port ${db.port}` : ""} -n ${db.dbname} -u ${db.username} -p ${db.password}`;
|
|
47
|
+
}
|
|
48
|
+
const cmd = `"${this.jasperPath}" process "${reportToUse}" -o "${outputDir}" -f ${format} -P${paramString}${dbString}`;
|
|
49
|
+
try {
|
|
50
|
+
const { stdout } = await execAsync(cmd);
|
|
51
|
+
return stdout;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`\u274C Failed to generate report: ${(err == null ? void 0 : err.stderr) || (err == null ? void 0 : err.message) || err}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
ReportService as default
|
|
61
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jasper_nodejs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "wrapper jasper report untuk nodejs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "tsup src/index.ts --format esm --dts"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/anggadedysaputro/jasper_nodejs.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"jasper",
|
|
21
|
+
"report",
|
|
22
|
+
"jasper",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"jasper",
|
|
25
|
+
"javascript"
|
|
26
|
+
],
|
|
27
|
+
"author": "angga dedy saputro",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/anggadedysaputro/jasper_nodejs/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/anggadedysaputro/jasper_nodejs#readme",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^25.0.3",
|
|
35
|
+
"tsup": "^8.5.1",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
}
|
|
38
|
+
}
|