feat(node): connect the client to the combined sysml-wasm module - #872
Merged
Merged
Conversation
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…/node-wasm-transport
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
…e once Co-Authored-By: jason.han <hanhuijun@gmail.com>
5 of 6 tasks
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Lets
@openmbee/opensysmlrun against the combinedsysml-wasmWebAssembly module (#870, now ondevelop) instead of a nativesysml-grpc, in Node and in the browser. The existingConnection,Model, values and errors are unchanged; only the transport is different.src/core/wasm.ts:createWasmTransport(host, options)is a ConnectTransport. For each unary call it encodes the request with protobuf-estoJsonand calls the module'scall(method, json). A JSON-RPC error envelope becomes aConnectErrorwith the same code, and a result is decoded withfromJson(ignoreUnknownFields). It runs throughrunUnaryCall, so interceptors,onResponsetaps, deadlines and abort signals all apply. Streaming calls answerUnimplemented.connectWasmHostopens aConnectionwith JSON encoding and the usualGetServerInfohandshake, so version and capability checks behave as they do against a service. A call the module doesn't serve fails withMissingCapabilityError, or withUNIMPLEMENTEDif the call isn't capability-gated.instantiateInlinestarts Go in the current realm. It captures and removesglobalThis.sysmlWasmso that a second instance can't overwrite the first.loadGoConstructor(wasmExec)loads eachwasm_exec.jsonce per specifier and caches itsGoconstructor. Loads are serialized, so modules built with different Go toolchains can run side by side.wasmExecand use the installedGo.globalThis.Gois restored. A failed load leaves the global exactly as it found it.wasmExec, the loader waits for in-flight loads and then uses the installedGo.WorkerWasmHostandserveWasmPortshare an init/call protocol for workers. Each call carries the request'sAbortSignal. A cancelled or timed-out call is dropped from the pending table, and its late answer is ignored.connectWasm({ wasm, wasmExec, thread })runs in aworker_threadsworker by default (src/node/wasm-worker.ts);thread: "inline"runs it on the calling thread.connectWasm({ wasm, wasmExec, worker })runs inline, or in a module worker the caller creates from the new@openmbee/opensysml/browser/wasm-workerexport. A page that loadswasm_exec.jsitself omitswasmExec.wasmand the matchingwasm_exec.js. feat(release): publish sysml-wasm as release assets and an npm package #875 (stacked on this one) publishes them and resolves them automatically in Node.buildjob also buildsbin/wasm/sysml-wasm.wasmand copies the toolchain'swasm_exec.js.node-testpoints the tests at them withOPENSYSML_REQUIRE_WASM=1, so the WASM tests can't silently skip there.docs/reference/node-api.md,clients.mdandwasm.md.How it was verified
test/wasm.test.tsruns with both theworkerandinlinethreads and compares results against the nativeconnect()client:loads+eval(integers, big integers, quantities, sequences)symbol/childreninstantiate,executeActionandexecuteStateparseSourcesonResponsetaps,close(), and a stale-version refusal that terminates the worker.wasmExecis passed but used when it's omittedwasmExecthat waits for a concurrent loadnpm run build,typecheck,lintandnpm testall pass (385 passed, 0 skipped), as doespython3 scripts/changelog.py check.Checklist
make testandmake lintpass locally (client suite, lint and typecheck; the Go side is feat(wasm): add combined sysml-wasm command #870's, already on develop)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build)F4,K5) in the body, docs, or changelog