liveBook · Manning

Jco

As explained in Server-Side WebAssembly

jco is a JavaScript toolchain for generating bindings and interoperability code for WebAssembly components.

jco is a JavaScript toolchain for turning WIT definitions and JavaScript into WebAssembly components, then generating JavaScript glue for using those components. section 3.2.1 section 3.4.3

A practical jco workflow is:

  • Install Node.js and npm, then install jco and componentize-js globally. section 3.2.1
  • Run jco componentize with the JavaScript file, WIT file, world name, output path, and explicitly disabled capabilities. section 3.2.3
  • Run jco transpile on the resulting .wasm file to inspect generated TypeScript declarations and JavaScript type mappings. section 3.4.3

SmartCMS key-value guest

A JavaScript guest imports get and set from component:smartcms/kvstore, stores guest-hello, and returns the retrieved value. jco componentizes it against the host WIT interface; transpilation maps Rust’s Option type to string | undefined. The component runs with stdio, random, clocks, and HTTP disabled, producing “Hello from the Guest!”. section 3.4.3

jco componentize greet.js --wit greet.wit --world-name 
➥example --out greet.wasm --disable stdio random clocks http

Inspect the complete componentization command, including WIT input, world selection, output naming, and disabled capabilities. section 3.2.3

Listing 3.8 The TypeScript declaration file for our key-value store interface
/** @module Interface component:smartcms/kvstore **/
export function get(key: string): string | undefined;
export function set(key: string, value: string): void;

Inspect the generated TypeScript declarations that expose the host key-value interface to JavaScript. section 3.4.3

How Server-Side WebAssembly covers it

How deep it goes
Explains installation, WIT-driven componentization, capability restrictions, transpilation, and runtime type mapping, while exposing a runtime-only signature caveat.
Examples
Uses a Hello World greeting component and a SmartCMS guest backed by a host key-value store.
What it assumes
Assumes a WIT file and JavaScript source, while introducing Node.js, npm, jco, componentize-js, and WIT linkage.
What you can do after
Builds and inspects JavaScript WebAssembly components with jco componentize and jco transpile.
How it connects
Connects WebAssembly components, WIT, JavaScript, TypeScript declarations, host imports, and capability-based security.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.