@bobfrankston/mailx-store 0.1.21 → 0.1.22

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/index.d.ts CHANGED
@@ -4,4 +4,5 @@
4
4
  */
5
5
  export { MailxDB } from "./db.js";
6
6
  export { FileMessageStore } from "./file-store.js";
7
+ export { parseSerial } from "./parse-serial.js";
7
8
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -4,4 +4,5 @@
4
4
  */
5
5
  export { MailxDB } from "./db.js";
6
6
  export { FileMessageStore } from "./file-store.js";
7
+ export { parseSerial } from "./parse-serial.js";
7
8
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-store",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -10,7 +10,8 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@bobfrankston/mailx-types": "^0.1.11",
13
- "@bobfrankston/mailx-settings": "^0.1.16"
13
+ "@bobfrankston/mailx-settings": "^0.1.16",
14
+ "mailparser": "^3.7.2"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -21,12 +22,14 @@
21
22
  },
22
23
  ".dependencies": {
23
24
  "@bobfrankston/mailx-types": "file:../mailx-types",
24
- "@bobfrankston/mailx-settings": "file:../mailx-settings"
25
+ "@bobfrankston/mailx-settings": "file:../mailx-settings",
26
+ "mailparser": "^3.7.2"
25
27
  },
26
28
  ".transformedSnapshot": {
27
29
  "dependencies": {
28
30
  "@bobfrankston/mailx-types": "^0.1.11",
29
- "@bobfrankston/mailx-settings": "^0.1.16"
31
+ "@bobfrankston/mailx-settings": "^0.1.16",
32
+ "mailparser": "^3.7.2"
30
33
  }
31
34
  }
32
35
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Process-wide serialized simpleParser.
3
+ *
4
+ * mailparser's `simpleParser` is declared `async` but its work is CPU-bound
5
+ * (Node Streams + libmime decoding). When N parses run concurrently on the
6
+ * single-threaded event loop they share CPU and each finishes at roughly
7
+ * N× wall-clock. Real evidence (2026-05-13): four near-concurrent parses
8
+ * each reported `14691ms for 3 KB` — pure contention, not size.
9
+ *
10
+ * The downstream symptom is the IPC pipe: while the event loop is
11
+ * saturated by interleaving parses, unrelated IPC operations (mark-as-spam,
12
+ * move, delete) wait their turn and the WebView-side `mailxapi` shim
13
+ * times out at 120s with a misleading "stayed in the list" alert.
14
+ *
15
+ * Serializing through a module-level promise chain bounds the damage with
16
+ * minimal plumbing: a single parse runs at full CPU and finishes in its
17
+ * natural ~50-500ms budget; the next parse starts when it's done. Each
18
+ * UI click produces a clean preview latency instead of a 14-second stall.
19
+ *
20
+ * Lives in mailx-store rather than mailx-service so both the UI-hot path
21
+ * (mailx-service/local-store.ts) and the sync path (mailx-imap) can share
22
+ * one queue — otherwise sync-time parses would still contend with UI
23
+ * parses through the event loop, just not through this module's chain.
24
+ *
25
+ * Future work: replace the in-process chain with a `node:worker_threads`
26
+ * pool. The chain is the precursor that bounds the worst case while the
27
+ * pool is built.
28
+ */
29
+ import { type ParsedMail, type Source } from "mailparser";
30
+ /** Serialized wrapper around `mailparser.simpleParser`. Drop-in replacement —
31
+ * same signature, same return value. */
32
+ export declare function parseSerial(source: Source): Promise<ParsedMail>;
33
+ //# sourceMappingURL=parse-serial.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Process-wide serialized simpleParser.
3
+ *
4
+ * mailparser's `simpleParser` is declared `async` but its work is CPU-bound
5
+ * (Node Streams + libmime decoding). When N parses run concurrently on the
6
+ * single-threaded event loop they share CPU and each finishes at roughly
7
+ * N× wall-clock. Real evidence (2026-05-13): four near-concurrent parses
8
+ * each reported `14691ms for 3 KB` — pure contention, not size.
9
+ *
10
+ * The downstream symptom is the IPC pipe: while the event loop is
11
+ * saturated by interleaving parses, unrelated IPC operations (mark-as-spam,
12
+ * move, delete) wait their turn and the WebView-side `mailxapi` shim
13
+ * times out at 120s with a misleading "stayed in the list" alert.
14
+ *
15
+ * Serializing through a module-level promise chain bounds the damage with
16
+ * minimal plumbing: a single parse runs at full CPU and finishes in its
17
+ * natural ~50-500ms budget; the next parse starts when it's done. Each
18
+ * UI click produces a clean preview latency instead of a 14-second stall.
19
+ *
20
+ * Lives in mailx-store rather than mailx-service so both the UI-hot path
21
+ * (mailx-service/local-store.ts) and the sync path (mailx-imap) can share
22
+ * one queue — otherwise sync-time parses would still contend with UI
23
+ * parses through the event loop, just not through this module's chain.
24
+ *
25
+ * Future work: replace the in-process chain with a `node:worker_threads`
26
+ * pool. The chain is the precursor that bounds the worst case while the
27
+ * pool is built.
28
+ */
29
+ import { simpleParser } from "mailparser";
30
+ let _chain = Promise.resolve();
31
+ /** Serialized wrapper around `mailparser.simpleParser`. Drop-in replacement —
32
+ * same signature, same return value. */
33
+ export async function parseSerial(source) {
34
+ const queued = _chain.then(() => simpleParser(source));
35
+ _chain = queued.catch(() => undefined);
36
+ return queued;
37
+ }
38
+ //# sourceMappingURL=parse-serial.js.map