@vulfram/transport-napi 0.19.3-alpha → 0.20.1-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.
package/dist/index.js CHANGED
@@ -34,38 +34,35 @@ 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-w4dx1mnf.node");
37
+ module.exports = __require("./vulfram_core-znysm17z.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-zdzrhnjc.node");
42
+ module.exports = __require("./vulfram_core-tr2ykmnn.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-77tjnpae.node");
47
+ module.exports = __require("./vulfram_core-fs2xxb19.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-gc5kt6t3.node");
52
+ module.exports = __require("./vulfram_core-4a1sbtxr.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-2pty1yvt.node");
57
+ module.exports = __require("./vulfram_core-r1a4qbvx.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-nffbksne.node");
62
+ module.exports = __require("./vulfram_core-559xqvzb.node");
63
63
  });
64
64
 
65
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";
69
66
  function detectRuntime() {
70
67
  if (typeof globalThis.Deno !== "undefined" && typeof globalThis.Deno?.version?.deno === "string") {
71
68
  const deno = globalThis.Deno;
@@ -144,53 +141,10 @@ function getArtifactFileName(binding, platform) {
144
141
  return "vulfram_core.dylib";
145
142
  return "vulfram_core.so";
146
143
  }
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
- };
182
- }
183
144
 
184
145
  // src/bind/napi-loader.ts
185
- import { createHash } from "crypto";
186
- import { existsSync } from "fs";
187
- import { mkdir, readFile, writeFile } from "fs/promises";
188
146
  import { createRequire as createRequire2 } from "module";
189
- import { homedir } from "os";
190
- import { dirname, join } from "path";
191
147
  var requireNative = createRequire2(import.meta.url);
192
- var pkg = requireNative("../../package.json");
193
- var { channel, artifactVersion } = parsePackageArtifactTarget(pkg.version);
194
148
  var loaders = {
195
149
  darwin: {
196
150
  arm64: () => Promise.resolve().then(() => __toESM(require_vulfram_core(), 1)),
@@ -205,58 +159,23 @@ var loaders = {
205
159
  x64: () => Promise.resolve().then(() => __toESM(require_vulfram_core6(), 1))
206
160
  }
207
161
  };
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);
162
+ function getExpectedLocalArtifact() {
163
+ try {
164
+ const platform = resolveNativePlatform();
165
+ const filename = getArtifactFileName("napi", platform);
166
+ return `../../lib/${platform}/${filename}`;
167
+ } catch {
168
+ return "../../lib/<platform>/vulfram_core.node";
251
169
  }
252
- return cachePath;
253
170
  }
254
171
  async function resolveNativeModulePath() {
255
172
  const importLoader = selectPlatformLoader(loaders, "N-API");
256
173
  try {
257
174
  return (await importLoader()).default;
258
- } catch {
259
- return resolveRemoteModulePath();
175
+ } catch (error) {
176
+ const runtime = detectRuntime();
177
+ const expectedArtifact = getExpectedLocalArtifact();
178
+ throw new Error(`Failed to load bundled N-API artifact (runtime=${runtime.runtime}, platform=${runtime.platform ?? "unknown"}, arch=${runtime.arch ?? "unknown"}, expected=${expectedArtifact}): ${String(error)}`);
260
179
  }
261
180
  }
262
181
  var modulePath = await resolveNativeModulePath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulfram/transport-napi",
3
- "version": "0.19.3-alpha",
3
+ "version": "0.20.1-alpha",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",