sandstorm-capnp-es
v0.2.1
Published
Generated TypeScript and ESM bindings for Sandstorm Cap'n Proto schemas.
Readme
sandstorm-capnp-es
Generated ESM and TypeScript declaration bindings for Sandstorm Cap'n Proto
schemas, built with @mnutt/capnp-es.
Build
This package expects a Sandstorm checkout at /tmp/sandstorm by default:
npm install
npm run buildSet SANDSTORM_SRC to use a different checkout source directory:
SANDSTORM_SRC=/path/to/sandstorm/src npm run buildGenerated files are written to dist/ and are the published package contents.
Usage
Raw generated bindings are available by schema path:
import { MainView } from "sandstorm-capnp-es/sandstorm/grain";
import { WebSession } from "sandstorm-capnp-es/sandstorm/web-session";For app code, prefer the adapter and response helpers:
import { serveSandstormApp, mainView, webSession } from "sandstorm-capnp-es/app";
import { html, json, methodNotAllowed } from "sandstorm-capnp-es/web";
await serveSandstormApp({
mainView: mainView({
viewInfo: {
appTitle: { defaultText: "My Sandstorm App" },
permissions: [],
roles: [],
deniedPermissions: [],
matchRequests: [],
matchOffers: [],
eventTypes: [],
},
webSession: webSession({
get(request) {
if (request.path === "status.json") {
return json({ ok: true });
}
return html("<!doctype html><h1>Hello</h1>");
},
post() {
return methodNotAllowed();
},
}),
}),
});The web helpers return objects compatible with the generated WebSession schema.
Request wrappers normalize common fields lazily, so lists and request bodies are
only decoded when accessed.
