@stll/anonymize 2.4.2 → 2.5.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.
@@ -0,0 +1,55 @@
1
+ import { assertNativeBindingVersion } from "./native.mjs";
2
+ import { N as setNativeBindingOverride, f as loadNativeAnonymizeBinding } from "./native-node2.mjs";
3
+ //#region src/native-runtime.ts
4
+ /**
5
+ * Runtime-aware selection of the native binding.
6
+ *
7
+ * Node uses the fast NAPI addon (`stella_anonymize_napi.node`). Bun cannot run
8
+ * it: the addon calls libuv functions Bun's NAPI shim does not implement
9
+ * (`uv_get_osfhandle`), which aborts the process. The `@stll/anonymize-wasm`
10
+ * binding exposes the identical `NativeAnonymizeBinding` surface and runs
11
+ * cleanly under both runtimes.
12
+ *
13
+ * The wasm binding loads asynchronously, but most consumers (the docx and pdf
14
+ * packages, `getDefaultNativePipeline`) call `loadNativeAnonymizeBinding()`
15
+ * synchronously. So under Bun an entry point calls `preloadNativeBinding()`
16
+ * once (async) at startup; it installs the wasm binding as the loader override,
17
+ * after which every synchronous `loadNativeAnonymizeBinding()` returns it. On
18
+ * Node this is a no-op and the NAPI path is unchanged.
19
+ */
20
+ const isBunRuntime = () => typeof globalThis.Bun !== "undefined";
21
+ let wasmBindingPromise;
22
+ const loadWasmBinding = async () => {
23
+ return (await import("@stll/anonymize-wasm")).getBinding();
24
+ };
25
+ /**
26
+ * Resolve the default native binding for the current runtime: the NAPI addon on
27
+ * Node, the wasm binding on Bun (loaded and cached once).
28
+ */
29
+ const loadDefaultNativeBinding = async (options = {}) => {
30
+ if (!isBunRuntime()) return loadNativeAnonymizeBinding(options);
31
+ wasmBindingPromise ??= loadWasmBinding();
32
+ const binding = await wasmBindingPromise;
33
+ if (options.expectedVersion !== void 0) assertNativeBindingVersion({
34
+ binding,
35
+ expectedVersion: options.expectedVersion
36
+ });
37
+ return binding;
38
+ };
39
+ let preloadPromise;
40
+ /**
41
+ * Under Bun, load the wasm binding once and install it as the synchronous
42
+ * loader override so every `loadNativeAnonymizeBinding()` caller uses it. A
43
+ * no-op on Node. Idempotent and safe to await from every entry point.
44
+ */
45
+ const preloadNativeBinding = async () => {
46
+ if (!isBunRuntime()) return;
47
+ preloadPromise ??= (async () => {
48
+ setNativeBindingOverride(await loadDefaultNativeBinding());
49
+ })();
50
+ return preloadPromise;
51
+ };
52
+ //#endregion
53
+ export { isBunRuntime, loadDefaultNativeBinding, preloadNativeBinding };
54
+
55
+ //# sourceMappingURL=native-runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-runtime.mjs","names":[],"sources":["../src/native-runtime.ts"],"sourcesContent":["import type { NativeAnonymizeBinding } from \"./native\";\nimport {\n assertNativeBindingVersion,\n loadNativeAnonymizeBinding,\n setNativeBindingOverride,\n type LoadNativeBindingOptions,\n} from \"./native-node\";\n\n/**\n * Runtime-aware selection of the native binding.\n *\n * Node uses the fast NAPI addon (`stella_anonymize_napi.node`). Bun cannot run\n * it: the addon calls libuv functions Bun's NAPI shim does not implement\n * (`uv_get_osfhandle`), which aborts the process. The `@stll/anonymize-wasm`\n * binding exposes the identical `NativeAnonymizeBinding` surface and runs\n * cleanly under both runtimes.\n *\n * The wasm binding loads asynchronously, but most consumers (the docx and pdf\n * packages, `getDefaultNativePipeline`) call `loadNativeAnonymizeBinding()`\n * synchronously. So under Bun an entry point calls `preloadNativeBinding()`\n * once (async) at startup; it installs the wasm binding as the loader override,\n * after which every synchronous `loadNativeAnonymizeBinding()` returns it. On\n * Node this is a no-op and the NAPI path is unchanged.\n */\nexport const isBunRuntime = (): boolean =>\n typeof (globalThis as { Bun?: unknown }).Bun !== \"undefined\";\n\nlet wasmBindingPromise: Promise<NativeAnonymizeBinding> | undefined;\n\nconst loadWasmBinding = async (): Promise<NativeAnonymizeBinding> => {\n // Dynamic so Node never pulls the wasm binding into its module graph, and so\n // the specifier is only resolved on the runtime that needs it.\n const wasm = await import(\"@stll/anonymize-wasm\");\n return wasm.getBinding();\n};\n\n/**\n * Resolve the default native binding for the current runtime: the NAPI addon on\n * Node, the wasm binding on Bun (loaded and cached once).\n */\nexport const loadDefaultNativeBinding = async (\n options: LoadNativeBindingOptions = {},\n): Promise<NativeAnonymizeBinding> => {\n if (!isBunRuntime()) {\n return loadNativeAnonymizeBinding(options);\n }\n wasmBindingPromise ??= loadWasmBinding();\n const binding = await wasmBindingPromise;\n if (options.expectedVersion !== undefined) {\n assertNativeBindingVersion({\n binding,\n expectedVersion: options.expectedVersion,\n });\n }\n return binding;\n};\n\nlet preloadPromise: Promise<void> | undefined;\n\n/**\n * Under Bun, load the wasm binding once and install it as the synchronous\n * loader override so every `loadNativeAnonymizeBinding()` caller uses it. A\n * no-op on Node. Idempotent and safe to await from every entry point.\n */\nexport const preloadNativeBinding = async (): Promise<void> => {\n if (!isBunRuntime()) {\n return;\n }\n preloadPromise ??= (async () => {\n setNativeBindingOverride(await loadDefaultNativeBinding());\n })();\n return preloadPromise;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,MAAa,qBACX,OAAQ,WAAiC,QAAQ;AAEnD,IAAI;AAEJ,MAAM,kBAAkB,YAA6C;CAInE,QAAO,MADY,OAAO,wBAAA,CACd,WAAW;AACzB;;;;;AAMA,MAAa,2BAA2B,OACtC,UAAoC,CAAC,MACD;CACpC,IAAI,CAAC,aAAa,GAChB,OAAO,2BAA2B,OAAO;CAE3C,uBAAuB,gBAAgB;CACvC,MAAM,UAAU,MAAM;CACtB,IAAI,QAAQ,oBAAoB,KAAA,GAC9B,2BAA2B;EACzB;EACA,iBAAiB,QAAQ;CAC3B,CAAC;CAEH,OAAO;AACT;AAEA,IAAI;;;;;;AAOJ,MAAa,uBAAuB,YAA2B;CAC7D,IAAI,CAAC,aAAa,GAChB;CAEF,oBAAoB,YAAY;EAC9B,yBAAyB,MAAM,yBAAyB,CAAC;CAC3D,EAAA,CAAG;CACH,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/anonymize",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "description": "Deterministic PII detection and anonymization with regex, deny lists, and coreference resolution",
5
5
  "keywords": [
6
6
  "anonymization",
@@ -27,6 +27,16 @@
27
27
  "import": "./dist/capabilities.mjs",
28
28
  "default": "./dist/capabilities.mjs"
29
29
  },
30
+ "./agent-surface": {
31
+ "types": "./dist/agent-surface.d.mts",
32
+ "import": "./dist/agent-surface.mjs",
33
+ "default": "./dist/agent-surface.mjs"
34
+ },
35
+ "./feedback": {
36
+ "types": "./dist/feedback.d.mts",
37
+ "import": "./dist/feedback.mjs",
38
+ "default": "./dist/feedback.mjs"
39
+ },
30
40
  "./native": {
31
41
  "types": "./dist/native.d.mts",
32
42
  "import": "./dist/native.mjs",
@@ -36,6 +46,11 @@
36
46
  "types": "./dist/native-node.d.mts",
37
47
  "import": "./dist/native-node.mjs",
38
48
  "default": "./dist/native-node.mjs"
49
+ },
50
+ "./native-runtime": {
51
+ "types": "./dist/native-runtime.d.mts",
52
+ "import": "./dist/native-runtime.mjs",
53
+ "default": "./dist/native-runtime.mjs"
39
54
  }
40
55
  },
41
56
  "types": "dist/index.d.mts",
@@ -89,11 +104,12 @@
89
104
  }
90
105
  },
91
106
  "optionalDependencies": {
92
- "@stll/anonymize-darwin-arm64": "2.4.2",
93
- "@stll/anonymize-darwin-x64": "2.4.2",
94
- "@stll/anonymize-linux-arm64-gnu": "2.4.2",
95
- "@stll/anonymize-linux-x64-gnu": "2.4.2",
96
- "@stll/anonymize-win32-x64-msvc": "2.4.2"
107
+ "@stll/anonymize-wasm": "2.5.0",
108
+ "@stll/anonymize-darwin-arm64": "2.5.0",
109
+ "@stll/anonymize-darwin-x64": "2.5.0",
110
+ "@stll/anonymize-linux-arm64-gnu": "2.5.0",
111
+ "@stll/anonymize-linux-x64-gnu": "2.5.0",
112
+ "@stll/anonymize-win32-x64-msvc": "2.5.0"
97
113
  },
98
114
  "devDependencies": {
99
115
  "@napi-rs/cli": "^3.7.3",