{"id":17786149,"url":"https://github.com/dcodeio/wapi","last_synced_at":"2025-08-25T06:38:37.937Z","repository":{"id":65990086,"uuid":"348824107","full_name":"dcodeIO/wapi","owner":"dcodeIO","description":"A minimal yet viable Web-first Wasm/JS bridge.","archived":false,"fork":false,"pushed_at":"2021-03-20T04:56:26.000Z","size":4,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T18:23:53.746Z","etag":null,"topics":["webassembly"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcodeIO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-17T19:12:22.000Z","updated_at":"2023-12-14T01:29:43.000Z","dependencies_parsed_at":"2023-05-06T19:50:53.919Z","dependency_job_id":null,"html_url":"https://github.com/dcodeIO/wapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dcodeIO/wapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fwapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fwapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fwapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fwapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcodeIO","download_url":"https://codeload.github.com/dcodeIO/wapi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fwapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272014484,"owners_count":24858708,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["webassembly"],"created_at":"2024-10-27T09:04:53.140Z","updated_at":"2025-08-25T06:38:37.903Z","avatar_url":"https://github.com/dcodeIO.png","language":"TypeScript","readme":"# wapi\n\nAn experiment to create a minimal yet viable Web-first Wasm/JS bridge that works today. Similar to Emscripten's `EM_ASM`, but with most glue code contained in the Wasm binary for ease of use.\n\n## Usage\n\n```ts\nimport wapi from \"./index.js\"\n\nconst wapiEnv = {\n  getString(ptr) { ... }, // compiler-specific\n  ...\n}\nconst module = await WebAssembly.instantiate(theModule, { wapi: wapi(wapiEnv) })\n...\n```\n\n## How it works\n\nConstructing a `wapi` environment creates an object to be imported into Wasm with two properties:\n\n* `call`, which executes the JS code given to it from within WebAssembly while caching it for further calls and\n* `env`, which is the common environment of all wapi calls\n\nUpon construction, own properties of the initially provided `wapiEnv` (that then becomes `env`) are added to the scope of the JS code that will be executed, just as if these were globals:\n\n```ts\n// Init common environment\nconst wapiEnv = {\n  hello() { ... }\n  world(a) { ... }\n}\nWebAssembly.instantiate(theModule, { wapi: wapi(wapiEnv) })\n\n// Within WebAssembly (pseudo-code)\nwapi.call(`() =\u003e hello()`)\nwapi.call(`(a) =\u003e world(a)`, a)\n```\n\nWorks best with some level of compiler integration abstracting the `wapi.call`s away, but doesn't strictly require it as long as a compiler supports generating imports of the same name with multiple signatures.\n\n## How it performs\n\nThe JS magic used has some overhead, as it looks up the cached version of the code using a branch and then calls it indirectly, per call. Experiments indicate that a `wapi.call` (just the call, the code it executes is unaffected) is about 35-50% slower than a normal import call in V8. If the code being run performs non-trivial work anyway, this overhead seems to be neglectable. Otherwise it may depend.\n\n## How large is it\n\n[That large](./index.js) plus compiler-specific integration, e.g. to read strings from linear memory in the respective language's string encoding.\n\n## Building\n\n```\nnpm install\nnpm run asbuild\n```\n\n## Testing\n\n```\nnpm test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fwapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcodeio%2Fwapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fwapi/lists"}