@veripublica/epubsana-wasm 0.1.0 → 0.2.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  WebAssembly bindings for [**epubsana**](https://github.com/veripublica/epubsana) — a
4
4
  pure-Rust EPUB repairer. Repair an `.epub` **entirely in the browser** (or any JS
5
- runtime): no JVM, no server round-trip, no native dependencies. **The bytes never
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
8
  It reuses the exact core epubsana uses on the command line, so the behaviour is
@@ -24,16 +24,27 @@ import { Session } from "@veripublica/epubsana-wasm";
24
24
  const bytes = new Uint8Array(await file.arrayBuffer()); // a File / fetched .epub
25
25
  const s = Session.load(bytes);
26
26
 
27
- const { errors_before, fixes } = s.state();
28
- // fixes[i] = { index, tier: "AutoSafe" | "ConfirmNeeded", id, title, rationale, preview, applied }
27
+ const { fatals_before, errors_before, fixes } = s.plan();
28
+ // fixes[i] = { index, tier: "AutoSafe" | "ConfirmNeeded", id, severity, title,
29
+ // rationale, preview, outcome: "proposed" | "applied" }
29
30
 
30
31
  s.apply_auto_safe(); // apply every provably-safe fix in one go
31
32
  s.apply(fixes[2].index); // approve a specific ConfirmNeeded fix
32
33
 
33
- console.log(errors_before, "→", s.errors_after());
34
+ // Re-validates with epubveri and returns the veripublica machine envelope's
35
+ // `inputs[i]` shape — the same object the CLI's `--format json` emits.
36
+ const r = s.report("valid"); // or "openable": no fatals remain; the book opens
37
+ console.log(r.status, r.summary.fatals_before, "→", r.summary.fatals_after);
38
+ for (const item of r.items) console.log(item.outcome, item.severity, item.code);
39
+
34
40
  const repaired = s.result_bytes(); // Uint8Array — download as <name>_fixed.epub
35
41
  ```
36
42
 
43
+ `severity` is **inherited** from the finding a fix addresses (epubveri's
44
+ five-value vocabulary: `fatal | error | warning | info | usage`) — it describes
45
+ the defect, not the fix. A **fatal** is what stops a book from opening at all, so
46
+ a fatal-only book has zero *errors* and is not remotely valid; count them apart.
47
+
37
48
  Using it **directly in a browser without a bundler**? Build the `web` target
38
49
  (`wasm-pack build --target web`), which exposes an async `init()` you `await`
39
50
  once before constructing a `Session` — that's what `demo/index.html` uses.
@@ -11,12 +11,20 @@ export interface Fix {
11
11
  index: number;
12
12
  /**
13
13
  * `\"AutoSafe\"` (safe to auto-apply) or `\"ConfirmNeeded\"` (a visible change).
14
+ * epubsana\'s own axis: how much judgement the fix needs. Orthogonal to
15
+ * `severity`, which describes the *defect*.
14
16
  */
15
17
  tier: string;
16
18
  /**
17
- * The epubcheck-compatible ID this addresses, e.g. `\"RSC-005\"`.
19
+ * The epubcheck-compatible ID this addresses, e.g. `\"RSC-016\"`.
18
20
  */
19
21
  id: string;
22
+ /**
23
+ * Lowercase severity of the finding this fix clears, **inherited** from
24
+ * epubveri: `\"fatal\" | \"error\" | \"warning\" | \"info\" | \"usage\"`. A fatal is
25
+ * what stops the book from opening at all.
26
+ */
27
+ severity: string;
20
28
  /**
21
29
  * One-line summary.
22
30
  */
@@ -30,26 +38,103 @@ export interface Fix {
30
38
  */
31
39
  preview: Change[];
32
40
  /**
33
- * `true` once this fix has been applied in this session.
41
+ * `\"applied\"` once approved in this session, else `\"proposed\"`.
42
+ */
43
+ outcome: string;
44
+ }
45
+
46
+ /**
47
+ * One concrete edit a fix would make (mirrors `epubsana::Change`).
48
+ */
49
+ export interface Change {
50
+ path: string;
51
+ note: string;
52
+ }
53
+
54
+ /**
55
+ * One fix, in the shared item shape (FORMATS.md §1.3).
56
+ */
57
+ export interface Item {
58
+ /**
59
+ * Always `\"fix\"` for a repairer.
60
+ */
61
+ type: string;
62
+ /**
63
+ * `\"applied\"`, `\"skipped\"`, or `\"proposed\"` — what became of this fix.
64
+ * Required on a fix item: a report that cannot say which fixes the user
65
+ * approved is not a report of what changed.
66
+ */
67
+ outcome: string;
68
+ /**
69
+ * epubcheck-compatible message ID this fix addresses, e.g. `\"RSC-016\"`.
70
+ */
71
+ code: string;
72
+ /**
73
+ * epubveri\'s finer semantic sub-code, when the finding carries one.
74
+ */
75
+ rule: string | undefined;
76
+ /**
77
+ * Lowercase severity, inherited from the finding this fix addresses.
78
+ */
79
+ severity: string;
80
+ /**
81
+ * Container-relative path the fix touches, when it touches just one.
34
82
  */
35
- applied: boolean;
83
+ location: string | undefined;
84
+ message: string;
85
+ data: Data;
36
86
  }
37
87
 
38
88
  /**
39
- * A snapshot of a session: the starting error count and every proposed fix
40
- * (each with its current `applied` flag).
89
+ * Per-input counts, mirroring the envelope\'s `summary`.
41
90
  */
42
- export interface State {
91
+ export interface Summary {
92
+ fatals_before: number;
93
+ fatals_after: number;
43
94
  errors_before: number;
95
+ errors_after: number;
96
+ applied: number;
97
+ skipped: number;
98
+ /**
99
+ * The bar this result was measured against: `\"valid\"` or `\"openable\"`.
100
+ */
101
+ goal: string;
102
+ }
103
+
104
+ /**
105
+ * The re-validated result — the envelope\'s `inputs[i]` object without
106
+ * `path`/`error` (a wasm caller has no path, and in-memory bytes are always
107
+ * readable, so there is no unprocessable/`\"error\"` case here).
108
+ */
109
+ export interface Report {
110
+ /**
111
+ * `\"ok\"` (the goal was met) or `\"problems\"` (it was not).
112
+ */
113
+ status: string;
114
+ summary: Summary;
115
+ items: Item[];
116
+ }
117
+
118
+ /**
119
+ * The session\'s plan: the book\'s state before repair, and every proposed fix.
120
+ *
121
+ * Fatals are counted apart from errors, as epubveri reports them — a book whose
122
+ * defects are all fatal has `errors_before: 0` and does not even open.
123
+ */
124
+ export interface Plan {
125
+ fatals_before: number;
126
+ errors_before: number;
127
+ warnings_before: number;
44
128
  fixes: Fix[];
45
129
  }
46
130
 
47
131
  /**
48
- * One concrete edit a fix would make (mirrors `epubsana::Change`).
132
+ * Tool-specific extras: epubsana\'s tier, and the exact edits.
49
133
  */
50
- export interface Change {
51
- path: string;
52
- note: string;
134
+ export interface Data {
135
+ fix_id: string;
136
+ tier: string;
137
+ changes: string[];
53
138
  }
54
139
 
55
140
 
@@ -70,26 +155,30 @@ export class Session {
70
155
  * applied. The shortcut for "just fix what's unambiguously safe."
71
156
  */
72
157
  apply_auto_safe(): number;
73
- /**
74
- * Re-validate the current (possibly repaired) EPUB, returning its error
75
- * count — the same independent check the CLI reports as `errors: N → M`.
76
- */
77
- errors_after(): number;
78
158
  /**
79
159
  * Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
80
160
  */
81
161
  static load(bytes: Uint8Array): Session;
82
162
  /**
83
- * The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
163
+ * The session's plan: the starting counts and every proposed fix (each with
164
+ * its current `outcome`). Cheap — it re-validates nothing.
84
165
  */
85
- result_bytes(): Uint8Array;
166
+ plan(): Plan;
167
+ /**
168
+ * **Re-validate** the current (possibly repaired) EPUB with epubveri and
169
+ * return the result in the shared envelope shape — the same independent
170
+ * check the CLI reports. `goal` is `"valid"` (the default: no fatals and no
171
+ * errors remain) or `"openable"` (no fatals remain — the book opens).
172
+ */
173
+ report(goal?: string | null): Report;
86
174
  /**
87
- * The current session snapshot: the starting error count and the fixes.
175
+ * The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
88
176
  */
89
- state(): State;
177
+ result_bytes(): Uint8Array;
90
178
  }
91
179
 
92
180
  /**
93
- * The `epubsana-wasm` crate version.
181
+ * The version string — the same one the CLI's `-V` and the json envelope's
182
+ * `tool_version` print, git build metadata included.
94
183
  */
95
184
  export function version(): string;
@@ -38,18 +38,6 @@ export class Session {
38
38
  const ret = wasm.session_apply_auto_safe(this.__wbg_ptr);
39
39
  return ret >>> 0;
40
40
  }
41
- /**
42
- * Re-validate the current (possibly repaired) EPUB, returning its error
43
- * count — the same independent check the CLI reports as `errors: N → M`.
44
- * @returns {number}
45
- */
46
- errors_after() {
47
- const ret = wasm.session_errors_after(this.__wbg_ptr);
48
- if (ret[2]) {
49
- throw takeFromExternrefTable0(ret[1]);
50
- }
51
- return ret[0] >>> 0;
52
- }
53
41
  /**
54
42
  * Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
55
43
  * @param {Uint8Array} bytes
@@ -64,6 +52,32 @@ export class Session {
64
52
  }
65
53
  return Session.__wrap(ret[0]);
66
54
  }
55
+ /**
56
+ * The session's plan: the starting counts and every proposed fix (each with
57
+ * its current `outcome`). Cheap — it re-validates nothing.
58
+ * @returns {Plan}
59
+ */
60
+ plan() {
61
+ const ret = wasm.session_plan(this.__wbg_ptr);
62
+ return ret;
63
+ }
64
+ /**
65
+ * **Re-validate** the current (possibly repaired) EPUB with epubveri and
66
+ * return the result in the shared envelope shape — the same independent
67
+ * check the CLI reports. `goal` is `"valid"` (the default: no fatals and no
68
+ * errors remain) or `"openable"` (no fatals remain — the book opens).
69
+ * @param {string | null} [goal]
70
+ * @returns {Report}
71
+ */
72
+ report(goal) {
73
+ var ptr0 = isLikeNone(goal) ? 0 : passStringToWasm0(goal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
74
+ var len0 = WASM_VECTOR_LEN;
75
+ const ret = wasm.session_report(this.__wbg_ptr, ptr0, len0);
76
+ if (ret[2]) {
77
+ throw takeFromExternrefTable0(ret[1]);
78
+ }
79
+ return takeFromExternrefTable0(ret[0]);
80
+ }
67
81
  /**
68
82
  * The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
69
83
  * @returns {Uint8Array}
@@ -77,19 +91,12 @@ export class Session {
77
91
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
78
92
  return v1;
79
93
  }
80
- /**
81
- * The current session snapshot: the starting error count and the fixes.
82
- * @returns {State}
83
- */
84
- state() {
85
- const ret = wasm.session_state(this.__wbg_ptr);
86
- return ret;
87
- }
88
94
  }
89
95
  if (Symbol.dispose) Session.prototype[Symbol.dispose] = Session.prototype.free;
90
96
 
91
97
  /**
92
- * The `epubsana-wasm` crate version.
98
+ * The version string — the same one the CLI's `-V` and the json envelope's
99
+ * `tool_version` print, git build metadata included.
93
100
  * @returns {string}
94
101
  */
95
102
  export function version() {
@@ -185,6 +192,10 @@ function getUint8ArrayMemory0() {
185
192
  return cachedUint8ArrayMemory0;
186
193
  }
187
194
 
195
+ function isLikeNone(x) {
196
+ return x === undefined || x === null;
197
+ }
198
+
188
199
  function passArray8ToWasm0(arg, malloc) {
189
200
  const ptr = malloc(arg.length * 1, 1) >>> 0;
190
201
  getUint8ArrayMemory0().set(arg, ptr / 1);
Binary file
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@veripublica/epubsana-wasm",
3
3
  "type": "module",
4
- "description": "WebAssembly bindings for epubsana — repair EPUB defects in the browser, no upload.",
5
- "version": "0.1.0",
4
+ "description": "WebAssembly bindings for epubsana \u2014 repair EPUB defects in the browser, no upload.",
5
+ "version": "0.2.1",
6
6
  "license": "AGPL-3.0-only OR LicenseRef-veripublica-Commercial",
7
7
  "repository": {
8
8
  "type": "git",
@@ -29,4 +29,4 @@
29
29
  "wasm",
30
30
  "ebook"
31
31
  ]
32
- }
32
+ }