Skip to content

Add type definitions - #62

Open
jspanchu wants to merge 8 commits into
mainfrom
add-type-definitions-for-vtk
Open

Add type definitions#62
jspanchu wants to merge 8 commits into
mainfrom
add-type-definitions-for-vtk

Conversation

@jspanchu

Copy link
Copy Markdown
Member

No description provided.

Adding "type": "module" flips Vite's default output extensions (.js for
ES, .umd.cjs for UMD) and its default CSS asset names. Pin fileName and
cssFileName in all three configs so the published artifact names
(index.mjs, vtk.umd.js, viewer.umd.js, viewer.css) stay exactly as the
exports map and script-tag consumers expect.
Every unprefixed plumbing member (id, obj, set, observe, unObserve,
unObserveAll, userData, state, delete) shadowed the C++ member of the
same name, making those VTK methods unreachable through the proxy. $ is
not a legal character in C++ identifiers, so the prefix guarantees no
future collision. toJSON/toString stay unprefixed because JSON.stringify
and string coercion look them up by exactly those names.

BREAKING CHANGE: proxy plumbing members are now $-prefixed, e.g.
actor.delete() becomes actor.$delete() and camera.state becomes
camera.$state.
The proxy used to accept any property name as a method and forward it
blindly, so a typo surfaced as an opaque C++ error at invocation time.
Build a method table from the per-class serdes manifests (types/*.json)
shipped inside the .tar.gz bundle, or from a merged vtk-methods.json
hosted next to loose .mjs/.wasm files, and reject unknown names with a
TypeError naming the class.

The table also carries the [[vtk::maysuspend]] flag: only those methods
route through invokeAsync and return a Promise. Everything else now
dispatches through invoke and returns its value synchronously, so
callers no longer need await for ordinary calls.

Bundles that ship no manifests keep the old forward-anything behaviour.
Zero-copy exchange of bulk data required reaching into Module.HEAPU8 and
_malloc by hand. Expose the pointer primitives (alloc, free, copyToHeap,
copyFromHeap, viewAt) as runtime.heapInterface, and layer the VTK-aware
conversions (toVTKAoSArray, toJSTypedArray) on top as
session.typedArrayInterface, since creating a vtkTypeXxxArray needs a
session's vtk namespace.

Widths come from the runtime's vtkType enum rather than from class names,
so vtkIdTypeArray and friends read correctly on both wasm32 and wasm64.
Declares the runtime, both session classes and the proxy plumbing, plus
the open interfaces (vtkObject, VtkNamespace, ...) that generated
per-class declarations merge into via module augmentation. The loose
index signature on VtkNamespace keeps untyped use compiling when no
generated file is present.

Ignore the generated output (types/generated.d.ts, **/vtk-wasm.gen.d.ts)
in git and Prettier: it is derived from a specific VTK.wasm bundle and
regenerated per project.
Emits a module-augmentation .d.ts from the per-class serdes manifests of
a specific VTK.wasm bundle, so session.vtk is typed against the exact
VTK version and architecture the app loads. Takes either a .tar.gz URL
or a directory of vtk*.json manifests.

Overload collapse in the manifests means a child class often redeclares
an inherited member with an incompatible signature, so interfaces are
emitted as extends Omit<Parent, redeclared...> and nominal brands are
omitted to keep subclasses structurally assignable to their bases.
Covers generating per-bundle declarations with vtk-wasm gen-types and
wiring them into a project. The vitepress config is reformatted by
Prettier in the same pass; the only behavioural change is the new
sidebar entry.
A minimal Vite + TypeScript app that regenerates its declarations from
the bundle it loads (gen:types runs before dev and build) and typechecks
in CI-style with tsc --noEmit, so the generated types stay honest against
the VTK.wasm binary in public/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant