@mermanjs/node-wasm 0.11.0 → 0.12.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.
@@ -7,7 +7,7 @@ import {
7
7
  validateTransportIdentityExport,
8
8
  } from "../errors.mjs";
9
9
  import {
10
- assertRuntimePackageVersion,
10
+ cacheRuntimeCatalog,
11
11
  nodeLoaderPackageVersion,
12
12
  } from "../native-loader.mjs";
13
13
  import { wrapCandidateEngine } from "./wrap-engine.mjs";
@@ -33,6 +33,8 @@ export async function loadNodeWasmTransport(
33
33
  {
34
34
  modulePath = process.env.MERMAN_NODE_WASM_BINDING,
35
35
  loadModule = (specifier) => import(specifier),
36
+ localLayout = null,
37
+ directSvgResponse = false,
36
38
  } = {},
37
39
  iconPacksJson,
38
40
  ) {
@@ -58,6 +60,7 @@ export async function loadNodeWasmTransport(
58
60
  expectedPackageVersion: nodeLoaderPackageVersion(),
59
61
  expectedTransport: "wasm",
60
62
  label: "The Node-targeted WASM candidate",
63
+ localLayout,
61
64
  });
62
65
  let transport;
63
66
  try {
@@ -66,19 +69,13 @@ export async function loadNodeWasmTransport(
66
69
  ? new WasmEngine(optionsJson)
67
70
  : new WasmEngine(optionsJson, iconPacksJson),
68
71
  "The Node-targeted WASM candidate",
69
- { forwardsAbortSignal: false },
72
+ { forwardsAbortSignal: false, directSvgResponse },
70
73
  );
71
74
  } catch (cause) {
72
75
  throw decodeWireCreationError(cause, "The Node-targeted WASM candidate");
73
76
  }
74
77
  try {
75
- const runtimeCatalogJson = assertRuntimePackageVersion(
76
- transport.runtimeCatalogJson(),
77
- );
78
- return {
79
- ...transport,
80
- runtimeCatalogJson: () => runtimeCatalogJson,
81
- };
78
+ return cacheRuntimeCatalog(transport);
82
79
  } catch (cause) {
83
80
  try {
84
81
  await transport.dispose();
@@ -3,7 +3,7 @@ import { MermanDisposedError, MermanInvalidTransportError } from "../errors.mjs"
3
3
  export function wrapCandidateEngine(
4
4
  engine,
5
5
  label,
6
- { forwardsAbortSignal = false, directSvgAddon = false } = {},
6
+ { forwardsAbortSignal = false, directSvgAddon = false, directSvgResponse = false } = {},
7
7
  ) {
8
8
  if (
9
9
  typeof engine?.execute !== "function" ||
@@ -24,6 +24,7 @@ export function wrapCandidateEngine(
24
24
  throw new MermanInvalidTransportError(`${label} does not implement the direct SVG contract.`);
25
25
  }
26
26
  const transport = {
27
+ __proto__: null,
27
28
  execute: (requestJson, signal, timeoutMs) =>
28
29
  forwardsAbortSignal
29
30
  ? currentEngine().execute(requestJson, signal, timeoutMs)
@@ -35,14 +36,49 @@ export function wrapCandidateEngine(
35
36
  dispose: () => {
36
37
  const disposing = ownedEngine;
37
38
  ownedEngine = null;
38
- return disposing?.dispose?.();
39
+ try {
40
+ return disposing?.dispose?.();
41
+ } finally {
42
+ disposing?.free?.();
43
+ }
39
44
  },
40
45
  };
46
+ // wasm-bindgen installs the optional method directly on the engine's prototype.
47
+ const wasmPrototype = directSvgResponse ? Object.getPrototypeOf(engine) : null;
48
+ const responseMethod = wasmPrototype && wasmPrototype !== Object.prototype
49
+ ? Object.getOwnPropertyDescriptor(wasmPrototype, "executeSvgResponseSync")
50
+ : undefined;
51
+ if (responseMethod && Object.hasOwn(responseMethod, "value") && typeof responseMethod.value === "function") {
52
+ const executeSvgResponseSync = responseMethod.value;
53
+ transport.executeSvgResponseSync = (requestJson, timeoutMs) => {
54
+ const engine = currentEngine();
55
+ try {
56
+ return executeSvgResponseSync.call(engine, requestJson, timeoutMs);
57
+ } catch (cause) {
58
+ // wasm-bindgen throws the Rust operation error envelope as a string.
59
+ if (typeof cause === "string") return { errorJson: cause };
60
+ throw cause;
61
+ }
62
+ };
63
+ }
41
64
  if (directSvgAddon) {
42
65
  transport.executeSvg = (source, optionsJson, signal, timeoutMs) =>
43
66
  executeSvg.call(currentEngine(), source, optionsJson, signal, timeoutMs);
44
67
  transport.executeSvgSync = (source, optionsJson, timeoutMs) =>
45
68
  executeSvgSync.call(currentEngine(), source, optionsJson, timeoutMs);
69
+ const { executeSvgWithId, executeSvgWithIdSync, executeDrawList, executeDrawListSync } = engine;
70
+ if (typeof executeSvgWithId === "function" && typeof executeSvgWithIdSync === "function") {
71
+ transport.executeSvgWithId = (source, diagramId, signal, timeoutMs) =>
72
+ executeSvgWithId.call(currentEngine(), source, diagramId, signal, timeoutMs);
73
+ transport.executeSvgWithIdSync = (source, diagramId, timeoutMs) =>
74
+ executeSvgWithIdSync.call(currentEngine(), source, diagramId, timeoutMs);
75
+ }
76
+ if (typeof executeDrawList === "function" && typeof executeDrawListSync === "function") {
77
+ transport.executeDrawList = (source, optionsJson, signal, timeoutMs) =>
78
+ executeDrawList.call(currentEngine(), source, optionsJson, signal, timeoutMs);
79
+ transport.executeDrawListSync = (source, optionsJson, timeoutMs) =>
80
+ executeDrawListSync.call(currentEngine(), source, optionsJson, timeoutMs);
81
+ }
46
82
  }
47
83
  return transport;
48
84
  }