@vulfram/transport-napi 0.17.2-alpha → 0.19.2-alpha

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.

Potentially problematic release.


This version of @vulfram/transport-napi might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -34,50 +34,163 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
34
34
 
35
35
  // lib/macos-arm64/vulfram_core.node
36
36
  var require_vulfram_core = __commonJS((exports, module) => {
37
- module.exports = __require("./vulfram_core-ft75ssqs.node");
37
+ module.exports = __require("./vulfram_core-w4dx1mnf.node");
38
38
  });
39
39
 
40
40
  // lib/macos-x64/vulfram_core.node
41
41
  var require_vulfram_core2 = __commonJS((exports, module) => {
42
- module.exports = __require("./vulfram_core-qbdcr6jt.node");
42
+ module.exports = __require("./vulfram_core-zdzrhnjc.node");
43
43
  });
44
44
 
45
45
  // lib/linux-arm64/vulfram_core.node
46
46
  var require_vulfram_core3 = __commonJS((exports, module) => {
47
- module.exports = __require("./vulfram_core-09fsy0tb.node");
47
+ module.exports = __require("./vulfram_core-77tjnpae.node");
48
48
  });
49
49
 
50
50
  // lib/linux-x64/vulfram_core.node
51
51
  var require_vulfram_core4 = __commonJS((exports, module) => {
52
- module.exports = __require("./vulfram_core-mx29y6cy.node");
52
+ module.exports = __require("./vulfram_core-gc5kt6t3.node");
53
53
  });
54
54
 
55
55
  // lib/windows-arm64/vulfram_core.node
56
56
  var require_vulfram_core5 = __commonJS((exports, module) => {
57
- module.exports = __require("./vulfram_core-f4dw99gh.node");
57
+ module.exports = __require("./vulfram_core-2pty1yvt.node");
58
58
  });
59
59
 
60
60
  // lib/windows-x64/vulfram_core.node
61
61
  var require_vulfram_core6 = __commonJS((exports, module) => {
62
- module.exports = __require("./vulfram_core-v45afrt6.node");
62
+ module.exports = __require("./vulfram_core-nffbksne.node");
63
63
  });
64
64
 
65
- // src/bind/utils.ts
65
+ // ../transport-types/src/index.ts
66
+ var VULFRAM_R2_DEFAULT_BASE_URL = "https://pub-95922dbd81b344a893425215a2695b88.r2.dev";
67
+ var VULFRAM_ARTIFACT_PREFIX = "v1";
68
+ var VULFRAM_DEFAULT_CHANNEL = "alpha";
66
69
  function detectRuntime() {
67
70
  if (typeof globalThis.Deno !== "undefined" && typeof globalThis.Deno?.version?.deno === "string") {
68
- return { runtime: "deno", version: globalThis.Deno.version.deno };
71
+ const deno = globalThis.Deno;
72
+ return {
73
+ runtime: "deno",
74
+ version: deno.version.deno,
75
+ platform: deno.build?.os ?? null,
76
+ arch: deno.build?.arch ?? null
77
+ };
69
78
  }
70
79
  if (typeof globalThis.Bun !== "undefined" && typeof globalThis.Bun?.version === "string") {
71
- return { runtime: "bun", version: globalThis.Bun.version };
80
+ return {
81
+ runtime: "bun",
82
+ version: globalThis.Bun.version,
83
+ platform: typeof process !== "undefined" ? process.platform : null,
84
+ arch: typeof process !== "undefined" ? process.arch : null
85
+ };
72
86
  }
73
87
  if (typeof globalThis.process !== "undefined" && typeof globalThis.process?.versions?.node === "string") {
74
- return { runtime: "node", version: globalThis.process.versions.node };
88
+ const proc = globalThis.process;
89
+ return {
90
+ runtime: "node",
91
+ version: proc.versions.node,
92
+ platform: proc.platform ?? null,
93
+ arch: proc.arch ?? null
94
+ };
75
95
  }
76
- return { runtime: "unknown", version: null };
96
+ return {
97
+ runtime: "unknown",
98
+ version: null,
99
+ platform: null,
100
+ arch: null
101
+ };
102
+ }
103
+ function selectPlatformLoader(loaders, artifactKind) {
104
+ const runtime = detectRuntime();
105
+ const platformKey = runtime.platform ?? "";
106
+ const archKey = runtime.arch ?? "";
107
+ const byPlatform = loaders[platformKey];
108
+ const selected = byPlatform?.[archKey];
109
+ if (selected)
110
+ return selected;
111
+ throw new Error(`${artifactKind} build not found for the current runtime: ${JSON.stringify(runtime)}`);
112
+ }
113
+ function resolveNativePlatform(runtime = detectRuntime()) {
114
+ const platform = runtime.platform;
115
+ const arch = runtime.arch;
116
+ if (platform === "linux" && arch === "x64")
117
+ return "linux-x64";
118
+ if (platform === "linux" && arch === "arm64")
119
+ return "linux-arm64";
120
+ if (platform === "darwin" && arch === "x64")
121
+ return "macos-x64";
122
+ if (platform === "darwin" && arch === "arm64")
123
+ return "macos-arm64";
124
+ if (platform === "win32" && arch === "x64")
125
+ return "windows-x64";
126
+ if (platform === "win32" && arch === "arm64")
127
+ return "windows-arm64";
128
+ throw new Error(`Unsupported native platform for Vulfram transports: ${JSON.stringify(runtime)}`);
129
+ }
130
+ function getArtifactFileName(binding, platform) {
131
+ if (binding === "napi")
132
+ return "vulfram_core.node";
133
+ if (binding === "wasm")
134
+ return "vulfram_core_bg.wasm";
135
+ if (binding === "ffi" && platform.startsWith("windows"))
136
+ return "vulfram_core.dll";
137
+ if (binding === "ffi" && platform.startsWith("macos"))
138
+ return "vulfram_core.dylib";
139
+ if (binding === "ffi")
140
+ return "vulfram_core.so";
141
+ if (platform.startsWith("windows"))
142
+ return "vulfram_core.dll";
143
+ if (platform.startsWith("macos"))
144
+ return "vulfram_core.dylib";
145
+ return "vulfram_core.so";
146
+ }
147
+ function buildArtifactPath(config) {
148
+ const channel = config.channel ?? VULFRAM_DEFAULT_CHANNEL;
149
+ const prefix = config.prefix ?? VULFRAM_ARTIFACT_PREFIX;
150
+ const artifact = config.artifact ?? getArtifactFileName(config.binding, config.platform);
151
+ return [
152
+ prefix,
153
+ channel,
154
+ config.artifactVersion,
155
+ config.binding,
156
+ config.platform,
157
+ artifact
158
+ ].join("/");
159
+ }
160
+ function buildArtifactUrl(config) {
161
+ const base = (config.baseUrl ?? VULFRAM_R2_DEFAULT_BASE_URL).replace(/\/+$/, "");
162
+ return `${base}/${buildArtifactPath(config)}`;
163
+ }
164
+ function parsePackageArtifactTarget(packageVersion) {
165
+ const normalized = packageVersion.trim();
166
+ const match = normalized.match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);
167
+ if (!match) {
168
+ throw new Error(`Invalid package version "${packageVersion}". Expected semver format "X.Y.Z[-tag]".`);
169
+ }
170
+ const major = match[1];
171
+ const minor = match[2];
172
+ const pre = (match[4] ?? "").toLowerCase();
173
+ let channel = "release";
174
+ if (pre.includes("alpha"))
175
+ channel = "alpha";
176
+ else if (pre.includes("beta"))
177
+ channel = "beta";
178
+ return {
179
+ channel,
180
+ artifactVersion: `v${major}.${minor}`
181
+ };
77
182
  }
78
183
 
79
184
  // src/bind/napi-loader.ts
80
- console.log(process.platform, process.arch);
185
+ import { createHash } from "crypto";
186
+ import { existsSync } from "fs";
187
+ import { mkdir, readFile, writeFile } from "fs/promises";
188
+ import { createRequire as createRequire2 } from "module";
189
+ import { homedir } from "os";
190
+ import { dirname, join } from "path";
191
+ var requireNative = createRequire2(import.meta.url);
192
+ var pkg = requireNative("../../package.json");
193
+ var { channel, artifactVersion } = parsePackageArtifactTarget(pkg.version);
81
194
  var loaders = {
82
195
  darwin: {
83
196
  arm64: () => Promise.resolve().then(() => __toESM(require_vulfram_core(), 1)),
@@ -92,12 +205,62 @@ var loaders = {
92
205
  x64: () => Promise.resolve().then(() => __toESM(require_vulfram_core6(), 1))
93
206
  }
94
207
  };
95
- var importLoader = loaders[process.platform]?.[process.arch];
96
- if (!importLoader) {
97
- throw new Error(`FFI build not found for the current runtime: ${JSON.stringify(detectRuntime())}`);
208
+ function getCacheDir() {
209
+ return join(homedir(), ".cache", "vulfram-transport");
210
+ }
211
+ async function ensureFileDir(path) {
212
+ await mkdir(dirname(path), { recursive: true });
213
+ }
214
+ async function sha256File(path) {
215
+ const data = await readFile(path);
216
+ return createHash("sha256").update(data).digest("hex");
217
+ }
218
+ async function downloadArtifactWithHash(url, destination) {
219
+ const response = await fetch(url);
220
+ if (!response.ok) {
221
+ throw new Error(`Failed to download artifact: ${url} (${response.status})`);
222
+ }
223
+ const bytes = new Uint8Array(await response.arrayBuffer());
224
+ await ensureFileDir(destination);
225
+ await writeFile(destination, bytes);
226
+ const hashResponse = await fetch(`${url}.sha256`);
227
+ if (!hashResponse.ok)
228
+ return;
229
+ const expected = (await hashResponse.text()).trim().split(/\s+/)[0] ?? "";
230
+ if (!expected)
231
+ return;
232
+ const actual = await sha256File(destination);
233
+ if (actual !== expected) {
234
+ throw new Error(`SHA256 mismatch for ${url}: expected=${expected} actual=${actual}`);
235
+ }
236
+ }
237
+ async function resolveRemoteModulePath() {
238
+ const platform = resolveNativePlatform();
239
+ const filename = getArtifactFileName("napi", platform);
240
+ const remoteUrl = buildArtifactUrl({
241
+ baseUrl: VULFRAM_R2_DEFAULT_BASE_URL,
242
+ channel,
243
+ artifactVersion,
244
+ binding: "napi",
245
+ platform,
246
+ artifact: filename
247
+ });
248
+ const cachePath = join(getCacheDir(), "runtime", channel, artifactVersion, "napi", platform, filename);
249
+ if (!existsSync(cachePath)) {
250
+ await downloadArtifactWithHash(remoteUrl, cachePath);
251
+ }
252
+ return cachePath;
253
+ }
254
+ async function resolveNativeModulePath() {
255
+ const importLoader = selectPlatformLoader(loaders, "N-API");
256
+ try {
257
+ return (await importLoader()).default;
258
+ } catch {
259
+ return resolveRemoteModulePath();
260
+ }
98
261
  }
99
- var lib = await importLoader().then((mod) => mod.default);
100
- var raw = lib;
262
+ var modulePath = await resolveNativeModulePath();
263
+ var raw = requireNative(modulePath);
101
264
  var VULFRAM_CORE = {
102
265
  vulframInit: () => raw.vulframInit(),
103
266
  vulframDispose: () => raw.vulframDispose(),
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulfram/transport-napi",
3
- "version": "0.17.2-alpha",
3
+ "version": "0.19.2-alpha",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
- "@vulfram/transport-types": "^0.2.6"
15
+ "@vulfram/transport-types": "^0.3.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/bun": "^1.3.10"
Binary file
Binary file
Binary file