{"_id":"@atifsyedali/host","_rev":"2-baa889f862046a730595621f738cead8","name":"@atifsyedali/host","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.4":{"name":"@atifsyedali/host","description":"waPC host for node.js and the browser","author":{"name":"jsoverson"},"version":"0.0.4","main":"dist/src/index.js","types":"dist/src/index.d.ts","scripts":{"build":"npm run build:cjs && npm run build:browser","build:cjs":"tsc --declaration","build:browser":"webpack-cli --config etc/webpack.config.js","build:tests":"webpack-cli --config etc/webpack.config.test.js","compile":"npm run clean && npm run build","clean":"rimraf dist","lint":"eslint src test","prepublishOnly":"npm run compile","format":"prettier --write 'src/**/*.ts' 'test/**/*.ts'","watch":"npm run clean && tsc -w --declaration","test:unit":"mocha","test:browser":"npm run build:browser && npm run build:tests && ts-node test/browser/run.ts","test":"npm run lint && npm run test:unit && npm run test:browser"},"mocha":{"extends":"etc/.mocharc.json"},"prettier":"./etc/.prettierrc.json","eslintConfig":{"extends":"./etc/.eslintrc.json"},"keywords":[],"license":"ISC","devDependencies":{"@jsoverson/test-server":"^1.3.3","@msgpack/msgpack":"^2.5.1","@types/chai":"^4.2.16","@types/chai-as-promised":"^7.1.3","@types/debug":"^4.1.5","@types/estree":"^1.0.2","@types/find-root":"^1.1.2","@types/mocha":"^8.2.2","@types/node":"^14.14.41","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","chai":"^4.3.4","chai-as-promised":"^7.1.1","eslint":"^7.24.0","find-root":"^1.1.0","mocha":"^8.3.2","prettier":"^2.2.1","puppeteer":"^21.3.4","rimraf":"^3.0.2","ts-loader":"^9.0.0","ts-node":"^10.9.1","typescript":"^4.2.4","webpack":"^5.33.2","webpack-cli":"^4.6.0"},"dependencies":{"@bjorn3/browser_wasi_shim":"^0.2.15","debug":"^4.3.1"},"gitHead":"e8d4dbd2ae55646f98516f0c6c548ed9ccca1cd8","_id":"@atifsyedali/host@0.0.4","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-gbPFAnQGRElxTt0QHlva8QnkdyphFjdqSD4bmm8E63Gk0Wd9Dn6/Rd7jwm3JrsUNJ6P2dPjaiWrLOMfUiIbw4w==","shasum":"6b419afe7ee895a0e1aeb11c881206dfce2cd14f","tarball":"https://registry.npmjs.org/@atifsyedali/host/-/host-0.0.4.tgz","fileCount":43,"unpackedSize":3544032,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGUq8NnP6y37Z7V5xLSnQhnenjIeZS91IyKNgHm+kzUCAiEAu2++0G8kbTqaO+Z+2GcK/YkxYyE0hcKEwBZXlO6GMrk="}]},"_npmUser":{"name":"atifsyedali","email":"atifsyedali@gmail.com"},"directories":{},"maintainers":[{"name":"atifsyedali","email":"atifsyedali@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/host_0.0.4_1695666259933_0.4561489642342682"},"_hasShrinkwrap":false},"0.0.5":{"name":"@atifsyedali/host","description":"waPC host for node.js and the browser","author":{"name":"jsoverson"},"version":"0.0.5","main":"dist/src/index.js","types":"dist/src/index.d.ts","scripts":{"build":"npm run build:cjs && npm run build:browser","build:cjs":"tsc --declaration","build:browser":"webpack-cli --config etc/webpack.config.js","build:tests":"webpack-cli --config etc/webpack.config.test.js","compile":"npm run clean && npm run build","clean":"rimraf dist","lint":"eslint src test","prepublishOnly":"npm run compile","format":"prettier --write 'src/**/*.ts' 'test/**/*.ts'","watch":"npm run clean && tsc -w --declaration","test:unit":"mocha","test:browser":"npm run build:browser && npm run build:tests && ts-node test/browser/run.ts","test":"npm run lint && npm run test:unit && npm run test:browser"},"mocha":{"extends":"etc/.mocharc.json"},"prettier":"./etc/.prettierrc.json","eslintConfig":{"extends":"./etc/.eslintrc.json"},"keywords":[],"license":"ISC","devDependencies":{"@jsoverson/test-server":"^1.3.3","@msgpack/msgpack":"^2.5.1","@types/chai":"^4.2.16","@types/chai-as-promised":"^7.1.3","@types/debug":"^4.1.5","@types/estree":"^1.0.2","@types/find-root":"^1.1.2","@types/mocha":"^8.2.2","@types/node":"^14.14.41","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","chai":"^4.3.4","chai-as-promised":"^7.1.1","eslint":"^7.24.0","find-root":"^1.1.0","mocha":"^8.3.2","prettier":"^2.2.1","puppeteer":"^21.3.4","rimraf":"^3.0.2","ts-loader":"^9.0.0","ts-node":"^10.9.1","typescript":"^4.2.4","webpack":"^5.33.2","webpack-cli":"^4.6.0"},"dependencies":{"@bjorn3/browser_wasi_shim":"^0.2.15","debug":"^4.3.1"},"gitHead":"bb5408d44204ffb817abada44ac711f36fea0f6a","_id":"@atifsyedali/host@0.0.5","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-keKAyK7G5hmwNln4i7aiUELN37Amwq1paCsTUxfe4DZ2CZkhjFfkgfXLrE8TZ7y/N9Q/IlT6Cg7Sr48pPcJj9g==","shasum":"57d7ad9aa773077665cf9bee8fb6fee1629a5fb1","tarball":"https://registry.npmjs.org/@atifsyedali/host/-/host-0.0.5.tgz","fileCount":43,"unpackedSize":3545182,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID6Yqyyif2+qMUY0PiUbSJWPTLT0znkt2IP21TRRoLZ+AiEA5Rubx2bZqdBZFlWNFrrASvr7JsqKK5mY8apDcpW7YLU="}]},"_npmUser":{"name":"atifsyedali","email":"atifsyedali@gmail.com"},"directories":{},"maintainers":[{"name":"atifsyedali","email":"atifsyedali@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/host_0.0.5_1695667521576_0.49841191355663805"},"_hasShrinkwrap":false},"0.0.6":{"name":"@atifsyedali/host","description":"waPC host for node.js and the browser","author":{"name":"jsoverson"},"version":"0.0.6","main":"dist/src/index.js","types":"dist/src/index.d.ts","scripts":{"build":"npm run build:cjs && npm run build:browser","build:cjs":"tsc --declaration","build:browser":"webpack-cli --config etc/webpack.config.js","build:tests":"webpack-cli --config etc/webpack.config.test.js","compile":"npm run clean && npm run build","clean":"rimraf dist","lint":"eslint src test","prepublishOnly":"npm run compile","format":"prettier --write 'src/**/*.ts' 'test/**/*.ts'","watch":"npm run clean && tsc -w --declaration","test:unit":"mocha","test:browser":"npm run build:browser && npm run build:tests && ts-node test/browser/run.ts","test":"npm run lint && npm run test:unit && npm run test:browser"},"mocha":{"extends":"etc/.mocharc.json"},"prettier":"./etc/.prettierrc.json","eslintConfig":{"extends":"./etc/.eslintrc.json"},"keywords":[],"license":"ISC","devDependencies":{"@jsoverson/test-server":"^1.3.3","@msgpack/msgpack":"^2.5.1","@types/chai":"^4.2.16","@types/chai-as-promised":"^7.1.3","@types/debug":"^4.1.5","@types/estree":"^1.0.2","@types/find-root":"^1.1.2","@types/mocha":"^8.2.2","@types/node":"^14.14.41","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","chai":"^4.3.4","chai-as-promised":"^7.1.1","eslint":"^7.24.0","find-root":"^1.1.0","mocha":"^8.3.2","prettier":"^2.2.1","puppeteer":"^21.3.4","rimraf":"^3.0.2","ts-loader":"^9.0.0","ts-node":"^10.9.1","typescript":"^4.2.4","webpack":"^5.33.2","webpack-cli":"^4.6.0"},"dependencies":{"@bjorn3/browser_wasi_shim":"^0.2.15","debug":"^4.3.1"},"gitHead":"8c729233bd3f91cdc889e6504581b785aa12d399","_id":"@atifsyedali/host@0.0.6","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-M4f8QVT3kOuikHyT4qgL+XMrDeRNsk+RlB8HFX5bUx3Dy3ZGQpj2sYW+0DIpA021b8/ZLnqQm0XlBVsZpYXaPw==","shasum":"b91229862e8fbd699bb2edd58316e28627ed0623","tarball":"https://registry.npmjs.org/@atifsyedali/host/-/host-0.0.6.tgz","fileCount":43,"unpackedSize":3545487,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG+DIpT94L57r/8ZYZ8Gta3YeQmhiUlpBd2JKqz6kDGzAiEAyWlZ/yC9DGXsf+kkj6e5+bgkWm050NQtdUV2Dic+RZo="}]},"_npmUser":{"name":"atifsyedali","email":"atifsyedali@gmail.com"},"directories":{},"maintainers":[{"name":"atifsyedali","email":"atifsyedali@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/host_0.0.6_1695675113538_0.19313036906592695"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-25T18:24:19.825Z","0.0.4":"2023-09-25T18:24:20.194Z","modified":"2023-09-25T20:51:54.003Z","0.0.5":"2023-09-25T18:45:21.970Z","0.0.6":"2023-09-25T20:51:53.837Z"},"maintainers":[{"name":"atifsyedali","email":"atifsyedali@gmail.com"}],"description":"waPC host for node.js and the browser","keywords":[],"author":{"name":"jsoverson"},"license":"ISC","readme":"# waPC JavaScript Host (Node + Browser)\n\nThis is the JavaScript implementation of the **waPC** standard for WebAssembly host runtimes. It allows any WebAssembly module to be loaded as a guest and receive requests for invocation as well as to make its own function requests of the host.\n\nThis package defines the protocol for RPC exchange between guest (WebAssembly) modules and the host runtime.\n\n## Who is this for?\n\nLibrary developers who want to load waPC-compliant WebAssembly binaries in nodejs or browser environments. The waPC protocol allows a host to execute arbitrary wasm functions without knowing the exported bindings beforehand.\n\nWhile waPC does not prescribe a serialization/deserialization format, MessagePack is common recommended unless you need otherwise.\n\n## Installation\n\n```sh\n$ npm install @wapc/host\n```\n\n## Usage\n\n**Node**\n\n```js\nconst { instantiate } = require('@wapc/host');\nconst { encode, decode } = require('@msgpack/msgpack');\nconst { promises: fs } = require('fs');\nconst path = require('path');\n\nasync function main() {\n  // Read wasm off the local disk as Uint8Array\n  buffer = await fs.readFile(path.join(__dirname, 'fixtures', 'rust_echo_string.wasm'));\n\n  // Instantiate a WapcHost with the bytes read off disk\n  const host = await instantiate(buffer);\n\n  // Encode the payload with MessagePack\n  const payload = encode({ msg: 'hello world' });\n\n  // Invoke the operation in the wasm guest\n  const result = await host.invoke('echo', payload);\n\n  // Decode the results using MessagePack\n  const decoded = decode(result);\n\n  // log to the console\n  console.log(`Result: ${decoded}`);\n}\n\nmain().catch(err => console.error(err));\n```\n\n**Browser**\n\nBrowser environments can instantiate from a FetchResponse with `waPC.instantiateStreaming()`. If the browser does not support streaming wasm then waPC gracefully degrades and waits for the response to complete before instantiating.\n\n```html\n<script src=\"https://unpkg.com/@msgpack/msgpack@2.5.1/dist.es5+umd/msgpack.min.js\"></script>\n<script src=\"dist/index.bundle.js\"></script>\n<script>\n  (async () => {\n    // Fetch wasm bytes\n    response = await fetch('/test/fixtures/rust_echo_string.wasm');\n\n    // Instantiate a WapcHost with fetch response object\n    const host = await waPC.instantiateStreaming(response);\n\n    // Encode the arguments to send to the wasm function (Example using msgpack)\n    const payload = MessagePack.encode({ msg: 'hello world' });\n\n    // Invoke the \"echo\" function in the wasm guest\n    const result = await host.invoke('echo', payload);\n\n    // Decode the results (using msgpack in this example)\n    const decoded = MessagePack.decode(result);\n  })();\n</script>\n```\n\n## Contributing\n\n### Running tests\n\n**Node unit tests**\n\n```sh\n$ npm run test:unit\n```\n\n**Browser unit tests**\n\n```sh\n$ npm run test:browser\n```\n\n### Building\n\n```sh\n$ npm run build\n```\n","readmeFilename":"README.md"}