@veripublica/epubsana-wasm 0.19.0 → 0.20.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/README.md +30 -10
- package/epubsana_wasm.d.ts +57 -26
- package/epubsana_wasm_bg.js +65 -24
- package/epubsana_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@ pure-Rust EPUB repairer. Repair an `.epub` **entirely in the browser** (or any J
|
|
|
5
5
|
runtime): no server round-trip, no native dependencies. **The bytes never
|
|
6
6
|
leave the page** — a real privacy guarantee for unpublished manuscripts.
|
|
7
7
|
|
|
8
|
-
It
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
It runs the same repair function as the command line: it proposes the same
|
|
9
|
+
fixes, you choose which to approve, and the run applies them, validates the
|
|
10
|
+
book, and undoes any fix that made a finding more frequent. The same book with
|
|
11
|
+
the same approvals comes back byte for byte what the CLI produces.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -28,20 +28,40 @@ const s = Session.load(bytes);
|
|
|
28
28
|
|
|
29
29
|
const { fatals_before, errors_before, fixes } = s.plan();
|
|
30
30
|
// fixes[i] = { index, tier: "AutoSafe" | "ConfirmNeeded", id, severity, title,
|
|
31
|
-
// rationale, preview, outcome
|
|
31
|
+
// rationale, preview, outcome, reverted_for }
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// The fixes the user approved, by index: here every safe one, plus one more.
|
|
34
|
+
const approved = fixes.filter((f) => f.tier === "AutoSafe").map((f) => f.index);
|
|
35
|
+
approved.push(fixes[2].index);
|
|
35
36
|
|
|
36
|
-
//
|
|
37
|
+
// Applies the approved fixes, validates the book, undoes any fix that made a
|
|
38
|
+
// finding more frequent, and returns the veripublica machine envelope's
|
|
37
39
|
// `inputs[i]` shape — the same object the CLI's `--format json` emits.
|
|
38
|
-
const r = s.
|
|
39
|
-
console.log(r.status, r.summary.
|
|
40
|
+
const r = s.repair(Uint32Array.from(approved), "valid"); // or "openable"
|
|
41
|
+
console.log(r.status, r.summary.errors_before, "→", r.summary.errors_after);
|
|
40
42
|
for (const item of r.items) console.log(item.outcome, item.severity, item.code);
|
|
43
|
+
// outcome: "applied" | "skipped" (not approved) | "reverted" (undone)
|
|
41
44
|
|
|
42
45
|
const repaired = s.result_bytes(); // Uint8Array — download as <name>_fixed.epub
|
|
43
46
|
```
|
|
44
47
|
|
|
48
|
+
`repair` always starts from the book as loaded, so calling it again with a
|
|
49
|
+
different selection replaces the previous run. `s.report(goal)` re-validates the
|
|
50
|
+
current bytes against another goal without repairing again.
|
|
51
|
+
|
|
52
|
+
**The error count can go up, and that is not damage.** A fix that lets the
|
|
53
|
+
validator see part of the book it could not see before (a package `version` no
|
|
54
|
+
validator recognises, or an entity that made a chapter unreadable) is not
|
|
55
|
+
undone for what then appears: those findings were always in the book.
|
|
56
|
+
`s.revealed()` returns how many. They were not in the plan, so repairing
|
|
57
|
+
`result_bytes()` again can fix some of them. The count is not in the envelope's
|
|
58
|
+
`summary`, which the conventions own; the CLI prints it as a note.
|
|
59
|
+
|
|
60
|
+
**Breaking change in 0.20.0:** `apply(index)` and `apply_auto_safe()` are gone.
|
|
61
|
+
They applied each fix the moment it was approved and never checked the result,
|
|
62
|
+
so a fix that made the book worse went into the download. Collect the approvals
|
|
63
|
+
and call `repair` once.
|
|
64
|
+
|
|
45
65
|
`severity` is **inherited** from the finding a fix addresses (epubveri's
|
|
46
66
|
five-value vocabulary: `fatal | error | warning | info | usage`) — it describes
|
|
47
67
|
the defect, not the fix. A **fatal** is what stops a book from opening at all, so
|
package/epubsana_wasm.d.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* A proposed fix as shown to the user. The apply logic stays in Rust; JS only
|
|
5
|
-
* sees this description and
|
|
5
|
+
* sees this description and passes `index` to `Session.repair`.
|
|
6
6
|
*/
|
|
7
7
|
export interface Fix {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* This fix\'s handle in `Session.repair`\'s `approved` list. **0-based** — it
|
|
10
|
+
* indexes this array.
|
|
10
11
|
*
|
|
11
12
|
* The envelope\'s [`Data::index`], on a report item, is the same fix\'s
|
|
12
13
|
* **1-based** plan position, because that is the handle `epubsana --apply`
|
|
@@ -43,9 +44,16 @@ export interface Fix {
|
|
|
43
44
|
*/
|
|
44
45
|
preview: Change[];
|
|
45
46
|
/**
|
|
46
|
-
* `\"
|
|
47
|
+
* `\"proposed\"` until [`Session::repair`] runs; then `\"applied\"`,
|
|
48
|
+
* `\"skipped\"` (not approved) or `\"reverted\"` (approved, applied, and undone
|
|
49
|
+
* because it made a finding more frequent).
|
|
47
50
|
*/
|
|
48
51
|
outcome: string;
|
|
52
|
+
/**
|
|
53
|
+
* For a `\"reverted\"` fix, the finding whose count applying it raised, as
|
|
54
|
+
* `\"RSC-005 (opf.package.schema_violation)\"` — the line the CLI prints.
|
|
55
|
+
*/
|
|
56
|
+
reverted_for: string | undefined;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
/**
|
|
@@ -74,7 +82,8 @@ export interface Item {
|
|
|
74
82
|
*/
|
|
75
83
|
type: string;
|
|
76
84
|
/**
|
|
77
|
-
* `\"applied\"`, `\"skipped\"`, or `\"
|
|
85
|
+
* `\"applied\"`, `\"skipped\"`, `\"proposed\"` or `\"reverted\"` — what became of
|
|
86
|
+
* this fix.
|
|
78
87
|
* Required on a fix item: a report that cannot say which fixes the user
|
|
79
88
|
* approved is not a report of what changed.
|
|
80
89
|
*/
|
|
@@ -124,15 +133,18 @@ export interface Summary {
|
|
|
124
133
|
applied: number;
|
|
125
134
|
skipped: number;
|
|
126
135
|
/**
|
|
127
|
-
* Planned and neither applied nor declined —
|
|
128
|
-
*
|
|
129
|
-
* and a summary that reports
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* `applied + skipped + proposed == items.len()` holds here too, with
|
|
133
|
-
* `skipped` always zero.
|
|
136
|
+
* Planned and neither applied nor declined — every fix, before
|
|
137
|
+
* [`Session::repair`] has run. Counted because `outcome` is a closed set
|
|
138
|
+
* and a summary that reports some of its members disagrees with its own
|
|
139
|
+
* `items` (conventions #30, rule 1).
|
|
134
140
|
*/
|
|
135
141
|
proposed: number;
|
|
142
|
+
/**
|
|
143
|
+
* Approved and applied, then undone because applying it made a finding
|
|
144
|
+
* more frequent, exactly as in the CLI envelope. The identity is the CLI\'s:
|
|
145
|
+
* `applied + skipped + proposed + reverted == items.len()`.
|
|
146
|
+
*/
|
|
147
|
+
reverted: number;
|
|
136
148
|
/**
|
|
137
149
|
* The bar this result was measured against: `\"valid\"` or `\"openable\"`.
|
|
138
150
|
*/
|
|
@@ -174,7 +186,7 @@ export interface Data {
|
|
|
174
186
|
* This fix\'s **1-based** position in the plan, mirroring the CLI
|
|
175
187
|
* envelope\'s `data.index` — the selector `epubsana --apply` accepts.
|
|
176
188
|
*
|
|
177
|
-
* **Not the
|
|
189
|
+
* **Not the handle `Session.repair` takes.** That one is [`Fix::index`],
|
|
178
190
|
* which is 0-based because it indexes the `Plan.fixes` array JS already
|
|
179
191
|
* holds. The two differ on purpose: this field exists so a report saved
|
|
180
192
|
* from the browser is the *same document* a plugin gets from the CLI, and
|
|
@@ -201,16 +213,6 @@ export class Session {
|
|
|
201
213
|
private constructor();
|
|
202
214
|
free(): void;
|
|
203
215
|
[Symbol.dispose](): void;
|
|
204
|
-
/**
|
|
205
|
-
* Apply the fix at `index` (a user-approved step). A no-op if that fix was
|
|
206
|
-
* already applied; an error only if `index` is out of range.
|
|
207
|
-
*/
|
|
208
|
-
apply(index: number): void;
|
|
209
|
-
/**
|
|
210
|
-
* Apply every provably-safe (`AutoSafe`) fix at once; returns how many were
|
|
211
|
-
* applied. The shortcut for "just fix what's unambiguously safe."
|
|
212
|
-
*/
|
|
213
|
-
apply_auto_safe(): number;
|
|
214
216
|
/**
|
|
215
217
|
* Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
|
|
216
218
|
*/
|
|
@@ -221,16 +223,45 @@ export class Session {
|
|
|
221
223
|
*/
|
|
222
224
|
plan(): Plan;
|
|
223
225
|
/**
|
|
224
|
-
*
|
|
225
|
-
* return the result
|
|
226
|
-
*
|
|
227
|
-
*
|
|
226
|
+
* Run the repair with the fixes at `approved` (0-based [`Fix::index`]
|
|
227
|
+
* values) and return the result — **the core's `epubsana::repair`, the
|
|
228
|
+
* function the CLI runs**, so the same book with the same approvals comes
|
|
229
|
+
* back identical from both.
|
|
230
|
+
*
|
|
231
|
+
* Every approved fix is applied, the book is validated, and a fix that
|
|
232
|
+
* made any finding more frequent is undone and reported `"reverted"`,
|
|
233
|
+
* except for findings a fix revealed (see [`Session::revealed`]). A fix not
|
|
234
|
+
* in `approved` is `"skipped"`, as it is under the CLI's `--apply`.
|
|
235
|
+
*
|
|
236
|
+
* Starts from the book as loaded every time, so calling it again with a
|
|
237
|
+
* different selection replaces the previous run. An index out of range is
|
|
238
|
+
* an error and changes nothing.
|
|
239
|
+
*/
|
|
240
|
+
repair(approved: Uint32Array, goal?: string | null): Report;
|
|
241
|
+
/**
|
|
242
|
+
* **Re-validate** the current EPUB with epubveri and return the result in
|
|
243
|
+
* the shared envelope shape — the same independent check the CLI reports.
|
|
244
|
+
* `goal` is `"valid"` (the default: no fatals and no errors remain) or
|
|
245
|
+
* `"openable"` (no fatals remain — the book opens). Before any
|
|
246
|
+
* [`Session::repair`] every item is `"proposed"` and the book is unchanged.
|
|
228
247
|
*/
|
|
229
248
|
report(goal?: string | null): Report;
|
|
230
249
|
/**
|
|
231
250
|
* The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
|
|
232
251
|
*/
|
|
233
252
|
result_bytes(): Uint8Array;
|
|
253
|
+
/**
|
|
254
|
+
* How many findings the last [`Session::repair`] accepted as **revealed**:
|
|
255
|
+
* always in the book, and visible only once a fix let the validator in —
|
|
256
|
+
* by making an unreadable document readable, or by correcting a package
|
|
257
|
+
* version no validator recognises. They were not in the plan, so running
|
|
258
|
+
* again on [`Session::result_bytes`] can repair some of them. `0` before
|
|
259
|
+
* any repair.
|
|
260
|
+
*
|
|
261
|
+
* Not in the envelope's `summary`, which the conventions own; the CLI
|
|
262
|
+
* prints the same number as a note after its report.
|
|
263
|
+
*/
|
|
264
|
+
revealed(): number;
|
|
234
265
|
}
|
|
235
266
|
|
|
236
267
|
/**
|
package/epubsana_wasm_bg.js
CHANGED
|
@@ -18,26 +18,6 @@ export class Session {
|
|
|
18
18
|
const ptr = this.__destroy_into_raw();
|
|
19
19
|
wasm.__wbg_session_free(ptr, 0);
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Apply the fix at `index` (a user-approved step). A no-op if that fix was
|
|
23
|
-
* already applied; an error only if `index` is out of range.
|
|
24
|
-
* @param {number} index
|
|
25
|
-
*/
|
|
26
|
-
apply(index) {
|
|
27
|
-
const ret = wasm.session_apply(this.__wbg_ptr, index);
|
|
28
|
-
if (ret[1]) {
|
|
29
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Apply every provably-safe (`AutoSafe`) fix at once; returns how many were
|
|
34
|
-
* applied. The shortcut for "just fix what's unambiguously safe."
|
|
35
|
-
* @returns {number}
|
|
36
|
-
*/
|
|
37
|
-
apply_auto_safe() {
|
|
38
|
-
const ret = wasm.session_apply_auto_safe(this.__wbg_ptr);
|
|
39
|
-
return ret >>> 0;
|
|
40
|
-
}
|
|
41
21
|
/**
|
|
42
22
|
* Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
|
|
43
23
|
* @param {Uint8Array} bytes
|
|
@@ -62,10 +42,40 @@ export class Session {
|
|
|
62
42
|
return ret;
|
|
63
43
|
}
|
|
64
44
|
/**
|
|
65
|
-
*
|
|
66
|
-
* return the result
|
|
67
|
-
*
|
|
68
|
-
*
|
|
45
|
+
* Run the repair with the fixes at `approved` (0-based [`Fix::index`]
|
|
46
|
+
* values) and return the result — **the core's `epubsana::repair`, the
|
|
47
|
+
* function the CLI runs**, so the same book with the same approvals comes
|
|
48
|
+
* back identical from both.
|
|
49
|
+
*
|
|
50
|
+
* Every approved fix is applied, the book is validated, and a fix that
|
|
51
|
+
* made any finding more frequent is undone and reported `"reverted"`,
|
|
52
|
+
* except for findings a fix revealed (see [`Session::revealed`]). A fix not
|
|
53
|
+
* in `approved` is `"skipped"`, as it is under the CLI's `--apply`.
|
|
54
|
+
*
|
|
55
|
+
* Starts from the book as loaded every time, so calling it again with a
|
|
56
|
+
* different selection replaces the previous run. An index out of range is
|
|
57
|
+
* an error and changes nothing.
|
|
58
|
+
* @param {Uint32Array} approved
|
|
59
|
+
* @param {string | null} [goal]
|
|
60
|
+
* @returns {Report}
|
|
61
|
+
*/
|
|
62
|
+
repair(approved, goal) {
|
|
63
|
+
const ptr0 = passArray32ToWasm0(approved, wasm.__wbindgen_malloc);
|
|
64
|
+
const len0 = WASM_VECTOR_LEN;
|
|
65
|
+
var ptr1 = isLikeNone(goal) ? 0 : passStringToWasm0(goal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
66
|
+
var len1 = WASM_VECTOR_LEN;
|
|
67
|
+
const ret = wasm.session_repair(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
68
|
+
if (ret[2]) {
|
|
69
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
70
|
+
}
|
|
71
|
+
return takeFromExternrefTable0(ret[0]);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* **Re-validate** the current EPUB with epubveri and return the result in
|
|
75
|
+
* the shared envelope shape — the same independent check the CLI reports.
|
|
76
|
+
* `goal` is `"valid"` (the default: no fatals and no errors remain) or
|
|
77
|
+
* `"openable"` (no fatals remain — the book opens). Before any
|
|
78
|
+
* [`Session::repair`] every item is `"proposed"` and the book is unchanged.
|
|
69
79
|
* @param {string | null} [goal]
|
|
70
80
|
* @returns {Report}
|
|
71
81
|
*/
|
|
@@ -91,6 +101,22 @@ export class Session {
|
|
|
91
101
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
92
102
|
return v1;
|
|
93
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* How many findings the last [`Session::repair`] accepted as **revealed**:
|
|
106
|
+
* always in the book, and visible only once a fix let the validator in —
|
|
107
|
+
* by making an unreadable document readable, or by correcting a package
|
|
108
|
+
* version no validator recognises. They were not in the plan, so running
|
|
109
|
+
* again on [`Session::result_bytes`] can repair some of them. `0` before
|
|
110
|
+
* any repair.
|
|
111
|
+
*
|
|
112
|
+
* Not in the envelope's `summary`, which the conventions own; the CLI
|
|
113
|
+
* prints the same number as a note after its report.
|
|
114
|
+
* @returns {number}
|
|
115
|
+
*/
|
|
116
|
+
revealed() {
|
|
117
|
+
const ret = wasm.session_revealed(this.__wbg_ptr);
|
|
118
|
+
return ret >>> 0;
|
|
119
|
+
}
|
|
94
120
|
}
|
|
95
121
|
if (Symbol.dispose) Session.prototype[Symbol.dispose] = Session.prototype.free;
|
|
96
122
|
|
|
@@ -184,6 +210,14 @@ function getStringFromWasm0(ptr, len) {
|
|
|
184
210
|
return decodeText(ptr >>> 0, len);
|
|
185
211
|
}
|
|
186
212
|
|
|
213
|
+
let cachedUint32ArrayMemory0 = null;
|
|
214
|
+
function getUint32ArrayMemory0() {
|
|
215
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
216
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
217
|
+
}
|
|
218
|
+
return cachedUint32ArrayMemory0;
|
|
219
|
+
}
|
|
220
|
+
|
|
187
221
|
let cachedUint8ArrayMemory0 = null;
|
|
188
222
|
function getUint8ArrayMemory0() {
|
|
189
223
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
@@ -196,6 +230,13 @@ function isLikeNone(x) {
|
|
|
196
230
|
return x === undefined || x === null;
|
|
197
231
|
}
|
|
198
232
|
|
|
233
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
234
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
235
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
236
|
+
WASM_VECTOR_LEN = arg.length;
|
|
237
|
+
return ptr;
|
|
238
|
+
}
|
|
239
|
+
|
|
199
240
|
function passArray8ToWasm0(arg, malloc) {
|
|
200
241
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
201
242
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
package/epubsana_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@veripublica/epubsana-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly bindings for epubsana — repair EPUB defects in the browser, no upload.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.20.0",
|
|
6
6
|
"license": "AGPL-3.0-only OR LicenseRef-veripublica-Commercial",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|