@venkateshcv1809/prosetta-sdk 0.4.0 → 0.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.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Prosetta SDK
2
2
 
3
3
  The JavaScript SDK wrapper for the Polyglot Rosetta project. The SDK will
4
- eventually prepare the assets needed by the WebAssembly runtime. This starter
5
- package currently exposes only `init()`.
4
+ eventually prepare the assets needed by the WebAssembly runtime. The current
5
+ starter exposes `init()` and `shutdown()` for the WASM module lifecycle.
6
6
 
7
7
  ## Local development
8
8
 
@@ -12,16 +12,32 @@ activate the project tools and install dependencies:
12
12
  ```sh
13
13
  mise trust
14
14
  mise install
15
+ cp .env.example .env
15
16
  just install
16
17
  ```
17
18
 
18
- mise enables Corepack when it installs Node 24 and installs the Yarn version
19
+ mise installs Node 24 and enables Corepack. Corepack selects the Yarn version
19
20
  pinned by the `packageManager` field in `package.json`.
20
21
 
21
- Run the available commands with `just` or the matching Yarn scripts:
22
+ mise loads `PROSETTA_WASM_PATH` from `.env`. Set it to a local directory that
23
+ contains `prosetta.wasm`, or to the HTTP(S) core release root or versioned
24
+ release directory. For local
25
+ development, use `../polyglot-rosetta/dist`; the core build writes the WASM file
26
+ and its matching Go runtime loader there. For production, the SDK appends the
27
+ core version pinned in `src/config/constants.ts` to the release root.
28
+
29
+ Run the development build with `just build` or `yarn build:dev`. It places the
30
+ ESM and CommonJS npm outputs with declarations under `dist/npm/`, plus the
31
+ standalone browser bundle and its source map in `dist/`.
32
+
33
+ Run the production build with `just build-prod` or `yarn build:prod`. It places
34
+ the standalone browser bundle and a production npm archive in `dist/`. The npm
35
+ archive includes the ESM, CommonJS, and TypeScript declaration outputs for
36
+ package consumers.
37
+
38
+ Other available commands:
22
39
 
23
40
  ```sh
24
- just build
25
41
  just check
26
42
  just clean
27
43
  ```
@@ -29,11 +45,54 @@ just clean
29
45
  ## Usage
30
46
 
31
47
  ```js
32
- import { init } from 'prosetta-sdk';
48
+ import { init, shutdown } from '@venkateshcv1809/prosetta-sdk';
33
49
 
34
- init();
50
+ const wasmModule = await init();
51
+ // Use the compiled module here.
52
+ shutdown();
35
53
  ```
36
54
 
37
- The tsdown build produces one UMD bundle at `dist/prosetta-sdk.js` for browser
38
- script loading, CommonJS `require()`, and ES module imports. TypeScript emits
39
- the package declarations alongside the bundle.
55
+ `init()` reads `prosetta.wasm` from the configured directory and returns a
56
+ `Promise<WebAssembly.Module>`. For remote release assets, it checks the cache,
57
+ then downloads `SHA256SUMS` and compares its published `prosetta.wasm` checksum
58
+ against any cached bytes. It downloads and caches the WASM only when the
59
+ checksum differs or no cached copy exists, and verifies downloaded bytes before
60
+ using them. The
61
+ browser build uses the Cache API when available; Node.js stores downloads in the
62
+ user cache directory (`$XDG_CACHE_HOME/prosetta-sdk/assets`,
63
+ `~/Library/Caches/prosetta-sdk/assets`, or `%LOCALAPPDATA%/prosetta-sdk/assets`). If
64
+ `SHA256SUMS` is unavailable, as in development builds, the SDK downloads the
65
+ WASM directly without persistent caching. Local directory paths are read
66
+ directly.
67
+ `shutdown()` clears the in-memory compiled module but keeps the persistent
68
+ download cache. The browser Cache API requires a secure context and may be
69
+ unavailable or evicted by the browser; in that case the SDK verifies and uses
70
+ the downloaded WASM without persistent caching.
71
+
72
+ The tsdown build produces an ESM and CommonJS npm package under `dist/npm/`, plus
73
+ a standalone browser IIFE at `dist/prosetta-sdk.js`. The browser global is
74
+ `ProsettaSDK`. The browser bundle embeds `PROSETTA_WASM_PATH` from the build
75
+ environment. Locally, mise reads it from `.env`; CI reads the repository Actions
76
+ variable. The npm package reads the environment variable at runtime.
77
+
78
+ ## Publishing
79
+
80
+ Pushes to `develop` run `.github/workflows/build.yml`, which builds the production
81
+ bundle and npm archive as workflow artifacts only. Publishing a GitHub Release
82
+ runs `.github/workflows/release.yml`. Its tag must match the version in
83
+ `package.json` (for example, `v0.2.0`) and point to a commit in `main`'s
84
+ history. The release workflow attaches the bundle and npm archive to the
85
+ release, then publishes the package to npm and GitHub Packages.
86
+
87
+ Set the repository Actions variable `PROSETTA_WASM_PATH` to the core release
88
+ root: `https://github.com/venkateshcv1809/polyglot-rosetta/releases/download/`.
89
+ The SDK appends `v0.9.1/` (from `PROSETTA_WASM_VERSION` in
90
+ `src/config/constants.ts`), producing the versioned release directory
91
+ `https://github.com/venkateshcv1809/polyglot-rosetta/releases/download/v0.9.1/`.
92
+ You can also set the variable directly to that versioned directory; if its
93
+ version differs from the SDK constant, loading fails with a clear error.
94
+
95
+ Add an `NPM_TOKEN` repository secret with permission to publish this package.
96
+ GitHub Packages uses the workflow's `GITHUB_TOKEN`. After its first publish,
97
+ make the GitHub package public in the package settings. GitHub Packages
98
+ consumers also need npm registry configuration and a token to install it.
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=`PROSETTA_WASM_PATH`,t={[e]:void 0};function n(){let e=globalThis.process,n=typeof __PROSETTA_CONFIG__>`u`?t:__PROSETTA_CONFIG__;return Object.fromEntries(Object.keys(t).map(t=>[t,n[t]||e?.env[t]]))}const r=`Set ${e} to a local prosetta.wasm path or an HTTP(S) URL.`;let i,a,o=0;function s(){if(i)return Promise.resolve(i);if(a)return a;let e=o,t=l();return a=t,t.then(t=>(e===o&&(i=t),t)).finally(()=>{e===o&&(a=void 0)})}function c(){o+=1,i=void 0,a=void 0}async function l(){let{PROSETTA_WASM_PATH:e}=n();if(!e)throw Error(r);if(u(e)){let t=await fetch(e);if(!t.ok)throw Error(`Failed to download WASM from ${e}: ${t.status} ${t.statusText}`);return WebAssembly.compile(await t.arrayBuffer())}let t=globalThis.process?.getBuiltinModule?.(`fs`);if(!t)throw Error(`Loading a local WASM file requires Node.js with process.getBuiltinModule().`);let i=await t.promises.readFile(e);return WebAssembly.compile(i)}function u(e){return/^https?:\/\//i.test(e)}function d(){return s()}function f(){c()}exports.init=d,exports.shutdown=f;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=`PROSETTA_WASM_PATH`,t={[e]:void 0};function n(){let e=globalThis.process,n=typeof __PROSETTA_CONFIG__>`u`?t:__PROSETTA_CONFIG__;return Object.fromEntries(Object.keys(t).map(t=>[t,n[t]||e?.env[t]]))}function r(e){let t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(e),t}const i=`v0.9.1`,a=`prosetta.wasm`,o=`SHA256SUMS`,s=`Set ${e} to a local directory or an HTTP(S) release directory URL.`;function c(e){return/^https?:\/\//i.test(e)}function l(e,t){let n=e.endsWith(`/`)?e:`${e}/`;return new URL(t,n).toString()}const u=`prosetta-sdk-assets-v1`;async function d(e){try{let t=await(await globalThis.caches?.open(u))?.match(e);return t?new Uint8Array(await t.arrayBuffer()):void 0}catch{return}}async function f(e,t){try{await(await globalThis.caches?.open(u))?.put(e,new Response(r(t)))}catch{}}function p(){return globalThis.process}function m(e){return p()?.getBuiltinModule?.(e)}function h(){let e=m(`fs`),t=m(`path`),n=m(`crypto`),r=p();if(!e?.promises||!t?.join||!n?.createHash||!r)return;let i=r.env??{},a=y(i,i.HOME??i.USERPROFILE,r.platform);if(a)return{fileSystem:e,path:t,crypto:n,directory:t.join(a,`prosetta-sdk`,`assets`),pid:r.pid}}function g(){return h()!==void 0}async function _(e){let t=h();if(!t)return;let n=t.crypto.createHash(`sha256`).update(e).digest(`hex`),r=t.path.join(t.directory,`${n}.bin`);try{return await t.fileSystem.promises.readFile(r)}catch{return}}async function v(e,t){let n=h();if(!n)return;let r=n.crypto.createHash(`sha256`).update(e).digest(`hex`),i=n.path.join(n.directory,`${r}.bin`),a=`${i}.${n.pid??Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;try{await n.fileSystem.promises.mkdir(n.directory,{recursive:!0}),await n.fileSystem.promises.writeFile(a,t),await n.fileSystem.promises.rename(a,i)}catch{}}function y(e,t,n){return e.XDG_CACHE_HOME?e.XDG_CACHE_HOME:n===`win32`?e.LOCALAPPDATA??(t?`${t}\\AppData\\Local`:void 0):n===`darwin`?t?`${t}/Library/Caches`:void 0:t?`${t}/.cache`:void 0}async function b(e){return g()?_(e):d(e)}async function x(e,t){g()?await v(e,t):await f(e,t)}function S(e,t){for(let n of e.split(/\r?\n/)){let e=n.match(/^([a-f\d]{64})\s+\*?(.+)$/i);if(e?.[2]===t)return e[1].toLowerCase()}throw Error(`SHA256SUMS does not contain a SHA-256 checksum for ${t}.`)}async function C(e){let t=m(`crypto`);if(t?.createHash)return t.createHash(`sha256`).update(e).digest(`hex`);let n=await globalThis.crypto.subtle.digest(`SHA-256`,r(e));return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}async function w(e,t,n){let r=await C(e);if(r!==t)throw Error(`SHA-256 mismatch for WASM from ${n}: expected ${t}, received ${r}`)}async function T(e,t){let n=m(`fs`),r=m(`path`);if(!n?.promises||!r?.join)throw Error(`Reading local assets requires Node.js.`);return n.promises.readFile(r.join(e,t))}async function E(e,t,{cache:n=`no-cache`,allowNotFound:r=!1}={}){let i=await fetch(e,{cache:n});if(i.ok||r&&i.status===404)return i;throw Error(`Failed to download ${t} from ${e}: ${i.status} ${i.statusText}`)}async function D(e){if(!c(e))return T(e,a);let t=A(e),n=l(t,a),r=l(t,o),i=await b(n),s=await O(r);if(s&&i&&await C(i)===s)return i;let u=await k(n,s);return s&&await x(n,u),u}async function O(e){let t=await E(e,o,{cache:`no-store`,allowNotFound:!0});if(t.status!==404)return S(await t.text(),a)}async function k(e,t){let n=await E(e,a,{cache:`no-store`}),r=new Uint8Array(await n.arrayBuffer());return t&&await w(r,t,e),r}function A(e){let t=new URL(e),n=t.pathname.replace(/\/+$/,``),r=n.slice(n.lastIndexOf(`/`)+1);if(r===`v0.9.1`)return t.pathname=`${n}/`,t.toString();if(/^v\d/.test(r))throw Error(`Configured WASM release directory uses ${r}; this SDK supports ${i}.`);if(r===`download`){let e=t.toString().endsWith(`/`)?t.toString():`${t.toString()}/`;return new URL(`${i}/`,e).toString()}return t.pathname=`${n}/`,t.toString()}let j,M,N=0;function P(){if(j)return Promise.resolve(j);if(M)return M;let e=N,t=I();return M=t,t.then(t=>(e===N&&(j=t),t)).finally(()=>{e===N&&(M=void 0)})}function F(){N+=1,j=void 0,M=void 0}async function I(){let{PROSETTA_WASM_PATH:e}=n();if(!e)throw Error(s);if(!c(e)&&!L())throw Error(`Loading a local WASM asset requires Node.js with process.getBuiltinModule().`);return WebAssembly.compile(r(await D(e)))}function L(){return!!globalThis.process?.getBuiltinModule?.(`fs`)}function R(){return P()}function z(){F()}exports.init=R,exports.shutdown=z;
@@ -1 +1 @@
1
- const e=`PROSETTA_WASM_PATH`,t={[e]:void 0};function n(){let e=globalThis.process,n=typeof __PROSETTA_CONFIG__>`u`?t:__PROSETTA_CONFIG__;return Object.fromEntries(Object.keys(t).map(t=>[t,n[t]||e?.env[t]]))}const r=`Set ${e} to a local prosetta.wasm path or an HTTP(S) URL.`;let i,a,o=0;function s(){if(i)return Promise.resolve(i);if(a)return a;let e=o,t=l();return a=t,t.then(t=>(e===o&&(i=t),t)).finally(()=>{e===o&&(a=void 0)})}function c(){o+=1,i=void 0,a=void 0}async function l(){let{PROSETTA_WASM_PATH:e}=n();if(!e)throw Error(r);if(u(e)){let t=await fetch(e);if(!t.ok)throw Error(`Failed to download WASM from ${e}: ${t.status} ${t.statusText}`);return WebAssembly.compile(await t.arrayBuffer())}let t=globalThis.process?.getBuiltinModule?.(`fs`);if(!t)throw Error(`Loading a local WASM file requires Node.js with process.getBuiltinModule().`);let i=await t.promises.readFile(e);return WebAssembly.compile(i)}function u(e){return/^https?:\/\//i.test(e)}function d(){return s()}function f(){c()}export{d as init,f as shutdown};
1
+ const e=`PROSETTA_WASM_PATH`,t={[e]:void 0};function n(){let e=globalThis.process,n=typeof __PROSETTA_CONFIG__>`u`?t:__PROSETTA_CONFIG__;return Object.fromEntries(Object.keys(t).map(t=>[t,n[t]||e?.env[t]]))}function r(e){let t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(e),t}const i=`v0.9.1`,a=`prosetta.wasm`,o=`SHA256SUMS`,s=`Set ${e} to a local directory or an HTTP(S) release directory URL.`;function c(e){return/^https?:\/\//i.test(e)}function l(e,t){let n=e.endsWith(`/`)?e:`${e}/`;return new URL(t,n).toString()}const u=`prosetta-sdk-assets-v1`;async function d(e){try{let t=await(await globalThis.caches?.open(u))?.match(e);return t?new Uint8Array(await t.arrayBuffer()):void 0}catch{return}}async function f(e,t){try{await(await globalThis.caches?.open(u))?.put(e,new Response(r(t)))}catch{}}function p(){return globalThis.process}function m(e){return p()?.getBuiltinModule?.(e)}function h(){let e=m(`fs`),t=m(`path`),n=m(`crypto`),r=p();if(!e?.promises||!t?.join||!n?.createHash||!r)return;let i=r.env??{},a=y(i,i.HOME??i.USERPROFILE,r.platform);if(a)return{fileSystem:e,path:t,crypto:n,directory:t.join(a,`prosetta-sdk`,`assets`),pid:r.pid}}function g(){return h()!==void 0}async function _(e){let t=h();if(!t)return;let n=t.crypto.createHash(`sha256`).update(e).digest(`hex`),r=t.path.join(t.directory,`${n}.bin`);try{return await t.fileSystem.promises.readFile(r)}catch{return}}async function v(e,t){let n=h();if(!n)return;let r=n.crypto.createHash(`sha256`).update(e).digest(`hex`),i=n.path.join(n.directory,`${r}.bin`),a=`${i}.${n.pid??Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;try{await n.fileSystem.promises.mkdir(n.directory,{recursive:!0}),await n.fileSystem.promises.writeFile(a,t),await n.fileSystem.promises.rename(a,i)}catch{}}function y(e,t,n){return e.XDG_CACHE_HOME?e.XDG_CACHE_HOME:n===`win32`?e.LOCALAPPDATA??(t?`${t}\\AppData\\Local`:void 0):n===`darwin`?t?`${t}/Library/Caches`:void 0:t?`${t}/.cache`:void 0}async function b(e){return g()?_(e):d(e)}async function x(e,t){g()?await v(e,t):await f(e,t)}function S(e,t){for(let n of e.split(/\r?\n/)){let e=n.match(/^([a-f\d]{64})\s+\*?(.+)$/i);if(e?.[2]===t)return e[1].toLowerCase()}throw Error(`SHA256SUMS does not contain a SHA-256 checksum for ${t}.`)}async function C(e){let t=m(`crypto`);if(t?.createHash)return t.createHash(`sha256`).update(e).digest(`hex`);let n=await globalThis.crypto.subtle.digest(`SHA-256`,r(e));return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}async function w(e,t,n){let r=await C(e);if(r!==t)throw Error(`SHA-256 mismatch for WASM from ${n}: expected ${t}, received ${r}`)}async function T(e,t){let n=m(`fs`),r=m(`path`);if(!n?.promises||!r?.join)throw Error(`Reading local assets requires Node.js.`);return n.promises.readFile(r.join(e,t))}async function E(e,t,{cache:n=`no-cache`,allowNotFound:r=!1}={}){let i=await fetch(e,{cache:n});if(i.ok||r&&i.status===404)return i;throw Error(`Failed to download ${t} from ${e}: ${i.status} ${i.statusText}`)}async function D(e){if(!c(e))return T(e,a);let t=A(e),n=l(t,a),r=l(t,o),i=await b(n),s=await O(r);if(s&&i&&await C(i)===s)return i;let u=await k(n,s);return s&&await x(n,u),u}async function O(e){let t=await E(e,o,{cache:`no-store`,allowNotFound:!0});if(t.status!==404)return S(await t.text(),a)}async function k(e,t){let n=await E(e,a,{cache:`no-store`}),r=new Uint8Array(await n.arrayBuffer());return t&&await w(r,t,e),r}function A(e){let t=new URL(e),n=t.pathname.replace(/\/+$/,``),r=n.slice(n.lastIndexOf(`/`)+1);if(r===`v0.9.1`)return t.pathname=`${n}/`,t.toString();if(/^v\d/.test(r))throw Error(`Configured WASM release directory uses ${r}; this SDK supports ${i}.`);if(r===`download`){let e=t.toString().endsWith(`/`)?t.toString():`${t.toString()}/`;return new URL(`${i}/`,e).toString()}return t.pathname=`${n}/`,t.toString()}let j,M,N=0;function P(){if(j)return Promise.resolve(j);if(M)return M;let e=N,t=I();return M=t,t.then(t=>(e===N&&(j=t),t)).finally(()=>{e===N&&(M=void 0)})}function F(){N+=1,j=void 0,M=void 0}async function I(){let{PROSETTA_WASM_PATH:e}=n();if(!e)throw Error(s);if(!c(e)&&!L())throw Error(`Loading a local WASM asset requires Node.js with process.getBuiltinModule().`);return WebAssembly.compile(r(await D(e)))}function L(){return!!globalThis.process?.getBuiltinModule?.(`fs`)}function R(){return P()}function z(){F()}export{R as init,z as shutdown};
@@ -1 +1 @@
1
- var ProsettaSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=`PROSETTA_WASM_PATH`,n={[t]:void 0};function r(){let e=globalThis.process,t={PROSETTA_WASM_PATH:`https://github.com/venkateshcv1809/polyglot-rosetta/releases/latest/download/prosetta.wasm`};return Object.fromEntries(Object.keys(n).map(n=>[n,t[n]||e?.env[n]]))}let i=`Set ${t} to a local prosetta.wasm path or an HTTP(S) URL.`,a,o,s=0;function c(){if(a)return Promise.resolve(a);if(o)return o;let e=s,t=u();return o=t,t.then(t=>(e===s&&(a=t),t)).finally(()=>{e===s&&(o=void 0)})}function l(){s+=1,a=void 0,o=void 0}async function u(){let{PROSETTA_WASM_PATH:e}=r();if(!e)throw Error(i);if(d(e)){let t=await fetch(e);if(!t.ok)throw Error(`Failed to download WASM from ${e}: ${t.status} ${t.statusText}`);return WebAssembly.compile(await t.arrayBuffer())}let t=globalThis.process?.getBuiltinModule?.(`fs`);if(!t)throw Error(`Loading a local WASM file requires Node.js with process.getBuiltinModule().`);let n=await t.promises.readFile(e);return WebAssembly.compile(n)}function d(e){return/^https?:\/\//i.test(e)}function f(){return c()}function p(){l()}return e.init=f,e.shutdown=p,e})({});
1
+ var ProsettaSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=`PROSETTA_WASM_PATH`,n={[t]:void 0};function r(){let e=globalThis.process,t={PROSETTA_WASM_PATH:`https://github.com/venkateshcv1809/polyglot-rosetta/releases/latest/download/prosetta.wasm`};return Object.fromEntries(Object.keys(n).map(n=>[n,t[n]||e?.env[n]]))}function i(e){let t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(e),t}let a=`v0.9.1`,o=`prosetta.wasm`,s=`SHA256SUMS`,c=`Set ${t} to a local directory or an HTTP(S) release directory URL.`;function l(e){return/^https?:\/\//i.test(e)}function u(e,t){let n=e.endsWith(`/`)?e:`${e}/`;return new URL(t,n).toString()}let d=`prosetta-sdk-assets-v1`;async function f(e){try{let t=await(await globalThis.caches?.open(d))?.match(e);return t?new Uint8Array(await t.arrayBuffer()):void 0}catch{return}}async function p(e,t){try{await(await globalThis.caches?.open(d))?.put(e,new Response(i(t)))}catch{}}function m(){return globalThis.process}function h(e){return m()?.getBuiltinModule?.(e)}function g(){let e=h(`fs`),t=h(`path`),n=h(`crypto`),r=m();if(!e?.promises||!t?.join||!n?.createHash||!r)return;let i=r.env??{},a=b(i,i.HOME??i.USERPROFILE,r.platform);if(a)return{fileSystem:e,path:t,crypto:n,directory:t.join(a,`prosetta-sdk`,`assets`),pid:r.pid}}function _(){return g()!==void 0}async function v(e){let t=g();if(!t)return;let n=t.crypto.createHash(`sha256`).update(e).digest(`hex`),r=t.path.join(t.directory,`${n}.bin`);try{return await t.fileSystem.promises.readFile(r)}catch{return}}async function y(e,t){let n=g();if(!n)return;let r=n.crypto.createHash(`sha256`).update(e).digest(`hex`),i=n.path.join(n.directory,`${r}.bin`),a=`${i}.${n.pid??Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;try{await n.fileSystem.promises.mkdir(n.directory,{recursive:!0}),await n.fileSystem.promises.writeFile(a,t),await n.fileSystem.promises.rename(a,i)}catch{}}function b(e,t,n){return e.XDG_CACHE_HOME?e.XDG_CACHE_HOME:n===`win32`?e.LOCALAPPDATA??(t?`${t}\\AppData\\Local`:void 0):n===`darwin`?t?`${t}/Library/Caches`:void 0:t?`${t}/.cache`:void 0}async function x(e){return _()?v(e):f(e)}async function S(e,t){_()?await y(e,t):await p(e,t)}function C(e,t){for(let n of e.split(/\r?\n/)){let e=n.match(/^([a-f\d]{64})\s+\*?(.+)$/i);if(e?.[2]===t)return e[1].toLowerCase()}throw Error(`SHA256SUMS does not contain a SHA-256 checksum for ${t}.`)}async function w(e){let t=h(`crypto`);if(t?.createHash)return t.createHash(`sha256`).update(e).digest(`hex`);let n=await globalThis.crypto.subtle.digest(`SHA-256`,i(e));return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}async function T(e,t,n){let r=await w(e);if(r!==t)throw Error(`SHA-256 mismatch for WASM from ${n}: expected ${t}, received ${r}`)}async function E(e,t){let n=h(`fs`),r=h(`path`);if(!n?.promises||!r?.join)throw Error(`Reading local assets requires Node.js.`);return n.promises.readFile(r.join(e,t))}async function D(e,t,{cache:n=`no-cache`,allowNotFound:r=!1}={}){let i=await fetch(e,{cache:n});if(i.ok||r&&i.status===404)return i;throw Error(`Failed to download ${t} from ${e}: ${i.status} ${i.statusText}`)}async function O(e){if(!l(e))return E(e,o);let t=j(e),n=u(t,o),r=u(t,s),i=await x(n),a=await k(r);if(a&&i&&await w(i)===a)return i;let c=await A(n,a);return a&&await S(n,c),c}async function k(e){let t=await D(e,s,{cache:`no-store`,allowNotFound:!0});if(t.status!==404)return C(await t.text(),o)}async function A(e,t){let n=await D(e,o,{cache:`no-store`}),r=new Uint8Array(await n.arrayBuffer());return t&&await T(r,t,e),r}function j(e){let t=new URL(e),n=t.pathname.replace(/\/+$/,``),r=n.slice(n.lastIndexOf(`/`)+1);if(r===`v0.9.1`)return t.pathname=`${n}/`,t.toString();if(/^v\d/.test(r))throw Error(`Configured WASM release directory uses ${r}; this SDK supports ${a}.`);if(r===`download`){let e=t.toString().endsWith(`/`)?t.toString():`${t.toString()}/`;return new URL(`${a}/`,e).toString()}return t.pathname=`${n}/`,t.toString()}let M,N,P=0;function F(){if(M)return Promise.resolve(M);if(N)return N;let e=P,t=L();return N=t,t.then(t=>(e===P&&(M=t),t)).finally(()=>{e===P&&(N=void 0)})}function I(){P+=1,M=void 0,N=void 0}async function L(){let{PROSETTA_WASM_PATH:e}=r();if(!e)throw Error(c);if(!l(e)&&!R())throw Error(`Loading a local WASM asset requires Node.js with process.getBuiltinModule().`);return WebAssembly.compile(i(await O(e)))}function R(){return!!globalThis.process?.getBuiltinModule?.(`fs`)}function z(){return F()}function B(){I()}return e.init=z,e.shutdown=B,e})({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venkateshcv1809/prosetta-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "JavaScript SDK wrapper for the Polyglot Rosetta WebAssembly runtime.",
5
5
  "license": "MIT",
6
6
  "repository": {