@ifc-lite/geometry 4.3.0 → 6.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.
@@ -2,106 +2,13 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
  /**
5
- * Forward a worker realm's wasm panic-location stash to the main thread
6
- * (#2527 follow-up).
5
+ * Re-export of the shared worker-to-main-thread wasm panic-location forwarder
6
+ * (issue #4247).
7
7
  *
8
- * The Rust panic hook (`rust/wasm-bindings/src/utils.rs`) stashes
9
- * `{ location, at }` on whichever realm's JS global it runs in — `self` in a
10
- * worker, `window` on the main thread. #2527 taught the main thread to read
11
- * its OWN global's stash and attach it to a trap's exception event
12
- * (`apps/viewer/src/lib/analytics-scrub.ts`'s `attachWasmPanicLocation`), but
13
- * a worker-realm trap leaves that stash stranded in the worker's global,
14
- * which the main thread can never see across the realm boundary.
15
- *
16
- * `takeWasmPanicStash` reads + consumes the stash worker-side so it can ride
17
- * the worker's own `{type:'error'}` message; `restashWasmPanicLocation`
18
- * re-plants it on the main thread's global so the EXISTING #2527 gate (same
19
- * key, same TTL, same consume-once semantics) picks it up unmodified.
20
- *
21
- * Location only, never the panic's message — the message can embed
22
- * model-derived text (see `utils.rs`'s privacy contract); the location alone
23
- * travels on the error message and through this module.
24
- *
25
- * NOTE: this file is intentionally byte-identical to
26
- * `packages/parser/src/wasm-panic-forward.ts` — both `@ifc-lite/geometry`
27
- * and `@ifc-lite/parser` need the exact same realm-forwarding contract, and
28
- * neither package depends on the other (nor is `@ifc-lite/wasm`, the one
29
- * package both DO depend on, a safe home: it ships only the wasm-pack build
30
- * output, with no TypeScript build step of its own, and `test`/`typecheck`
31
- * for either consumer already runs its build via turbo's `^build` — adding a
32
- * hand-written TS module there would make every geometry/parser test run
33
- * gate on a full Rust→wasm rebuild). Keep any change to one copy in lockstep
34
- * with the other; `wasm-panic-forward.test.ts` is duplicated the same way.
35
- */
36
- /** Kept in lockstep with `PANIC_STASH_KEY` in `rust/wasm-bindings/src/utils.rs`,
37
- * `WASM_PANIC_STASH_KEY` in `apps/viewer/src/lib/analytics-scrub.ts`, and this
38
- * module's twin at `packages/parser/src/wasm-panic-forward.ts`. */
39
- export const WASM_PANIC_STASH_KEY = '__ifclite_wasm_panic';
40
- /**
41
- * Trap-shape text match, kept in lockstep with `WASM_TRAP_TEXT` in
42
- * `apps/viewer/src/lib/analytics-scrub.ts` and this module's twin at
43
- * `packages/parser/src/wasm-panic-forward.ts`. Deliberately excludes bare
44
- * "unreachable" inside network-failure phrasing ("network is unreachable",
45
- * "host unreachable") — those are not wasm traps.
46
- */
47
- const WASM_TRAP_TEXT = /(?<!network is |host |destination |address )\bunreachable\b|\bRuntimeError\b|memory access out of bounds|index out of bounds|indirect call to null|integer (?:overflow|divide by zero)|call stack exhausted/i;
48
- function looksLikeWasmTrap(message) {
49
- return WASM_TRAP_TEXT.test(message);
50
- }
51
- /** Validate + narrow an unknown stash value read off a realm global. */
52
- function readStashShape(value) {
53
- if (typeof value !== 'object' || value === null)
54
- return undefined;
55
- const { location, at } = value;
56
- if (typeof location !== 'string' || location === '')
57
- return undefined;
58
- // Reject non-finite (`NaN`/`Infinity`) and future timestamps — both pass
59
- // the analytics TTL gate's `Date.now() - at <= TTL` check trivially
60
- // (`Infinity` makes the delta `-Infinity`; a future `at` makes it
61
- // negative), which would let a malformed stash label a later trap.
62
- if (typeof at !== 'number' || !Number.isFinite(at) || at > Date.now())
63
- return undefined;
64
- return { location, at };
65
- }
66
- /**
67
- * Worker-side: read and CONSUME this realm's panic stash so it can be
68
- * forwarded on the worker's own error message. Consume-once regardless of
69
- * shape validity — an unconsumed malformed stash must not linger to
70
- * mislabel a later trap, mirroring the main-thread gate's own rule.
71
- */
72
- export function takeWasmPanicStash(realm) {
73
- const g = realm;
74
- const raw = g[WASM_PANIC_STASH_KEY];
75
- delete g[WASM_PANIC_STASH_KEY];
76
- return readStashShape(raw);
77
- }
78
- /**
79
- * Main-side: re-plant a worker-forwarded stash on this realm's global so the
80
- * existing #2527 `attachWasmPanicLocation` gate consumes it unmodified.
81
- *
82
- * Gated on `errorMessage` looking like a wasm trap: the worker forwards
83
- * `wasmPanicLocation`/`wasmPanicAt` on ANY `{type:'error'}` message (a stale
84
- * stash from an earlier suppressed panic can ride out on an ordinary,
85
- * non-trap worker error), and re-planting unconditionally would let that
86
- * stale location sit on `globalThis` until an unrelated trap-shaped
87
- * exception consumed it — mislabeling that trap. Only a message that itself
88
- * looks like a wasm trap is allowed to re-plant.
89
- *
90
- * Never clobbers an existing, unconsumed stash — a genuine main-thread trap
91
- * that hasn't been captured yet must win over a worker trap that merely
92
- * arrived first (the older-looking stash, if stale, is simply dropped later
93
- * by the TTL check at attach time; this function never overwrites either
94
- * way).
8
+ * The real implementation lives in `@ifc-lite/wasm-lifecycle` so
9
+ * `@ifc-lite/geometry` and `@ifc-lite/parser` share exactly one copy of the
10
+ * #2527 realm-forwarding contract instead of maintaining two
11
+ * independently-editable "twin" files.
95
12
  */
96
- export function restashWasmPanicLocation(realm, location, at, errorMessage) {
97
- const stash = readStashShape({ location, at });
98
- if (!stash)
99
- return;
100
- if (!looksLikeWasmTrap(errorMessage))
101
- return;
102
- const g = realm;
103
- if (g[WASM_PANIC_STASH_KEY] !== undefined)
104
- return;
105
- g[WASM_PANIC_STASH_KEY] = stash;
106
- }
13
+ export { WASM_PANIC_STASH_KEY, takeWasmPanicStash, restashWasmPanicLocation, } from '@ifc-lite/wasm-lifecycle';
107
14
  //# sourceMappingURL=wasm-panic-forward.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-panic-forward.js","sourceRoot":"","sources":["../src/wasm-panic-forward.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;oEAEoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AA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AAO;IAC7C,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,IAAI,CAAC,CAAC,oBAAoB,CAAC,KAAK,SAAS;QAAE,OAAO;IAClD,CAAC,CAAC,oBAAoB,CAAC,GAAG,KAAK,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"wasm-panic-forward.js","sourceRoot":"","sources":["../src/wasm-panic-forward.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;GAQG;AACH,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAEzB,MAAM,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ifc-lite/geometry",
3
- "version": "4.3.0",
3
+ "version": "6.0.0",
4
4
  "description": "Geometry processing bridge for IFC-Lite - exact-arithmetic CSG, streamed across workers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,9 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@ifc-lite/data": "^4.0.0",
22
- "@ifc-lite/wasm": "^6.4.0"
21
+ "@ifc-lite/data": "^4.2.1",
22
+ "@ifc-lite/wasm": "^8.0.1",
23
+ "@ifc-lite/wasm-lifecycle": "^0.2.0"
23
24
  },
24
25
  "optionalDependencies": {
25
26
  "@tauri-apps/api": "^2.11.1"