@pao-at-office/reports-web 1.0.0 → 1.3.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.md +1 -1
- package/README.md +3 -3
- package/dist/PrintData.d.ts +1 -0
- package/dist/PrintData.js +49 -12
- package/package.json +2 -2
package/LICENSE.md
CHANGED
|
@@ -5,7 +5,7 @@ Copyright (c) Pao@Office. All rights reserved.
|
|
|
5
5
|
This package is part of **Reports.Web**, a commercial product of Pao@Office.
|
|
6
6
|
Use of this package is governed by the Reports.Web End User License Agreement:
|
|
7
7
|
|
|
8
|
-
-
|
|
8
|
+
- 使用許諾(正式な条件、共通マニュアル第16章): https://www.pao.ac/reports.web/manual/Reports-Web-Guide.pdf
|
|
9
9
|
- 製品サイト: https://www.pao.ac/reports.web/
|
|
10
10
|
- ご購入・お見積もり: https://www.pao.ac/reports.web/buy.html
|
|
11
11
|
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ your Node.js app ──(PREPEJ JSON)──▶ Reports.Web engine (Docker: ghcr.i
|
|
|
22
22
|
|
|
23
23
|
```sh
|
|
24
24
|
npm install @pao-at-office/reports-web
|
|
25
|
-
docker run -d -p 3107:3107 ghcr.io/reportsweb/engine:1.
|
|
25
|
+
docker run -d -p 3107:3107 ghcr.io/reportsweb/engine:1.3.0
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Node.js 18 以降。エンジンは Docker イメージで動きます。
|
|
@@ -78,10 +78,10 @@ Errors are thrown as `ReportsWebEngineError` with the HTTP `status`.
|
|
|
78
78
|
The package and the engine image are trial builds: output carries a red "SAMPLE" mark. Mount the license file delivered on purchase to remove it:
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
|
-
docker run -d -p 3107:3107 -v /path/to/reports-web.license:/app/reports-web.license:ro ghcr.io/reportsweb/engine:1.
|
|
81
|
+
docker run -d -p 3107:3107 -v /path/to/reports-web.license:/app/reports-web.license:ro ghcr.io/reportsweb/engine:1.3.0
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
開発用パソコン 1 台につき 1 ライセンス、運用環境はランタイムライセンスフリーです。詳しくは [LICENSE.md](LICENSE.md) と [
|
|
84
|
+
開発用パソコン 1 台につき 1 ライセンス、運用環境はランタイムライセンスフリーです。詳しくは [LICENSE.md](LICENSE.md) と [使用許諾(共通マニュアル第16章)](https://www.pao.ac/reports.web/manual/Reports-Web-Guide.pdf) をご覧ください。
|
|
85
85
|
|
|
86
86
|
## 他の言語 / Other languages
|
|
87
87
|
|
package/dist/PrintData.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class PrintData {
|
|
|
17
17
|
drawObject(n: string, i?: number, type?: string | null): this;
|
|
18
18
|
changeAttributes(n: string, values: Record<string, Scalar>, i?: number): this;
|
|
19
19
|
changeRepeatedAttributes(n: string, values: Record<string, Scalar>, i?: number, x?: number, y?: number, type?: string | null): this;
|
|
20
|
+
private requireObject;
|
|
20
21
|
private resolveType;
|
|
21
22
|
pageEnd(): this;
|
|
22
23
|
toObject(): JsonObject;
|
package/dist/PrintData.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { writeFile, rename, unlink } from "node:fs/promises";
|
|
1
|
+
import { writeFile, rename, unlink, stat, open } from "node:fs/promises";
|
|
2
|
+
import { constants } from "node:fs";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
const copy = (v) => structuredClone(v);
|
|
4
5
|
const name = (v) => {
|
|
5
6
|
if (typeof v !== "string" || !v.trim())
|
|
6
|
-
throw new Error("
|
|
7
|
+
throw new Error("名前を指定してください。");
|
|
7
8
|
return v.trim();
|
|
8
9
|
};
|
|
9
10
|
const index = (v) => {
|
|
10
11
|
if (!Number.isSafeInteger(v) || v < 0)
|
|
11
|
-
throw new Error("
|
|
12
|
+
throw new Error("物体・繰返しのインデックスには0以上の整数を指定してください。");
|
|
12
13
|
return v;
|
|
13
14
|
};
|
|
14
15
|
const scalar = (v) => {
|
|
@@ -16,9 +17,34 @@ const scalar = (v) => {
|
|
|
16
17
|
return null;
|
|
17
18
|
if (!["string", "number", "boolean"].includes(typeof v) ||
|
|
18
19
|
(typeof v === "number" && !Number.isFinite(v)))
|
|
19
|
-
throw new Error("
|
|
20
|
+
throw new Error("値は文字列・有限の数値・真偽値・nullのいずれかで指定してください。");
|
|
20
21
|
return String(v);
|
|
21
22
|
};
|
|
23
|
+
async function requireWritable(path) {
|
|
24
|
+
let info;
|
|
25
|
+
try {
|
|
26
|
+
info = await stat(path);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === 'ENOENT')
|
|
30
|
+
return;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (!info.isFile())
|
|
34
|
+
return;
|
|
35
|
+
const message = "読み取り専用のため保存できません。別名で保存してください。";
|
|
36
|
+
if ((info.mode & 0o222) === 0)
|
|
37
|
+
throw new Error(message);
|
|
38
|
+
try {
|
|
39
|
+
const probe = await open(path, constants.O_WRONLY);
|
|
40
|
+
await probe.close();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (['EACCES', 'EPERM'].includes(error.code ?? ''))
|
|
44
|
+
throw new Error(message, { cause: error });
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
22
48
|
export class PrintData {
|
|
23
49
|
definition = null;
|
|
24
50
|
pages = [];
|
|
@@ -33,12 +59,12 @@ export class PrintData {
|
|
|
33
59
|
d.version === 1 &&
|
|
34
60
|
Array.isArray(d.pages) &&
|
|
35
61
|
d.pages.length)))
|
|
36
|
-
throw new Error("
|
|
62
|
+
throw new Error("帳票定義の形式が不正です。");
|
|
37
63
|
}
|
|
38
64
|
setDefinition(d) {
|
|
39
65
|
PrintData.assertDefinition(d);
|
|
40
66
|
if (this.page)
|
|
41
|
-
throw new Error("
|
|
67
|
+
throw new Error("現在のページを終了してください。");
|
|
42
68
|
if (this.definition)
|
|
43
69
|
for (const p of this.pages)
|
|
44
70
|
if (!p.Definition)
|
|
@@ -48,11 +74,11 @@ export class PrintData {
|
|
|
48
74
|
}
|
|
49
75
|
pageStart(d = null) {
|
|
50
76
|
if (this.page)
|
|
51
|
-
throw new Error("
|
|
77
|
+
throw new Error("次のページを開始する前にpageEndで現在のページを終了してください。");
|
|
52
78
|
if (d)
|
|
53
79
|
PrintData.assertDefinition(d);
|
|
54
80
|
if (!this.definition)
|
|
55
|
-
throw new Error("
|
|
81
|
+
throw new Error("先に帳票定義を設定してください。");
|
|
56
82
|
this.page = {
|
|
57
83
|
Index: this.pages.length + 1,
|
|
58
84
|
Definition: copy(d),
|
|
@@ -63,10 +89,11 @@ export class PrintData {
|
|
|
63
89
|
}
|
|
64
90
|
current() {
|
|
65
91
|
if (!this.page)
|
|
66
|
-
throw new Error("
|
|
92
|
+
throw new Error("先にページを開始してください。");
|
|
67
93
|
return this.page;
|
|
68
94
|
}
|
|
69
95
|
value(n, v, i, drawing, type, x, y) {
|
|
96
|
+
this.requireObject(n);
|
|
70
97
|
const item = {
|
|
71
98
|
Name: name(n),
|
|
72
99
|
Type: this.resolveType(n, type),
|
|
@@ -103,8 +130,9 @@ export class PrintData {
|
|
|
103
130
|
return this.changeRepeatedAttributes(n, values, i);
|
|
104
131
|
}
|
|
105
132
|
changeRepeatedAttributes(n, values, i = 0, x, y, type = null) {
|
|
133
|
+
this.requireObject(n);
|
|
106
134
|
if ((x === undefined) !== (y === undefined))
|
|
107
|
-
throw new Error("
|
|
135
|
+
throw new Error("繰返し座標のxとyを両方指定してください。");
|
|
108
136
|
const item = {
|
|
109
137
|
Name: name(n),
|
|
110
138
|
Type: this.resolveType(n, type),
|
|
@@ -113,7 +141,7 @@ export class PrintData {
|
|
|
113
141
|
};
|
|
114
142
|
for (const [k, v] of Object.entries(values)) {
|
|
115
143
|
if (v === null)
|
|
116
|
-
throw new Error("
|
|
144
|
+
throw new Error("属性値にnullは指定できません。");
|
|
117
145
|
item.Values[k] = scalar(v);
|
|
118
146
|
}
|
|
119
147
|
if (x !== undefined && y !== undefined) {
|
|
@@ -123,6 +151,13 @@ export class PrintData {
|
|
|
123
151
|
this.current().DynamicAttributes.push(item);
|
|
124
152
|
return this;
|
|
125
153
|
}
|
|
154
|
+
// V1-03:Reports.net の Write と同じく、帳票に無い名前はその場で断る(以前は黙って受け、あとで送った PDF 全体が失敗した)。
|
|
155
|
+
requireObject(n) {
|
|
156
|
+
const d = this.current().Definition ?? this.definition;
|
|
157
|
+
const objects = [...(d.Objects ?? []), ...(d.pages ?? []).flatMap((p) => p.objects ?? [])];
|
|
158
|
+
if (!objects.some((o) => (o.Name ?? o.name) === name(n)))
|
|
159
|
+
throw new Error(`帳票にオブジェクト「${n}」がありません。`);
|
|
160
|
+
}
|
|
126
161
|
// 型省略時は当該ページの定義を参照する。明示指定はそのまま保持する。
|
|
127
162
|
resolveType(n, explicit) {
|
|
128
163
|
if (explicit !== null)
|
|
@@ -148,7 +183,7 @@ export class PrintData {
|
|
|
148
183
|
}
|
|
149
184
|
toObject() {
|
|
150
185
|
if (this.page || !this.definition || !this.pages.length)
|
|
151
|
-
throw new Error("
|
|
186
|
+
throw new Error("帳票定義と終了したページが必要です。");
|
|
152
187
|
return copy({
|
|
153
188
|
Format: "Reports.net PrintData",
|
|
154
189
|
Version: "1.0",
|
|
@@ -160,9 +195,11 @@ export class PrintData {
|
|
|
160
195
|
return JSON.stringify(this.toObject(), null, pretty ? 2 : undefined) + "\n";
|
|
161
196
|
}
|
|
162
197
|
async save(path) {
|
|
198
|
+
await requireWritable(path);
|
|
163
199
|
const temp = path + "." + randomUUID() + ".tmp";
|
|
164
200
|
try {
|
|
165
201
|
await writeFile(temp, this.toJson(), { flag: "wx" });
|
|
202
|
+
await requireWritable(path);
|
|
166
203
|
await rename(temp, path);
|
|
167
204
|
}
|
|
168
205
|
finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pao-at-office/reports-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Reports.Web for Node.js: build PREPEJ print data from report definitions (.prepdj) and render PDF with the Reports.Web engine (C++ WebAssembly). Japanese business forms such as invoices, estimates and labels.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"japanese",
|
|
42
42
|
"帳票",
|
|
43
43
|
"Reports.Web",
|
|
44
|
-
"Reports
|
|
44
|
+
"Reports Web"
|
|
45
45
|
],
|
|
46
46
|
"homepage": "https://www.pao.ac/reports.web/",
|
|
47
47
|
"bugs": {
|