@milaboratories/sandbox-js-1-guest
v0.3.0
Published
Guest library for sandbox-js-1 bundles: register, api and the contract error classes
Readme
@milaboratories/sandbox-js-1-guest
The guest library of sandbox-js-1 bundles: it registers the functions the host calls and hands out the APIs a use grants. Type-agnostic; typed wrappers belong to the layer above.
Install
pnpm add @milaboratories/sandbox-js-1-guest@<exact version>Pin the exact version; every package of this repository is released together under one version.
Exports
register(name, fn)— makesfncallable by the host undername. Call it while the bundle evaluates; after the snapshot is taken it throwsRegisterAfterSealError.api(name)— the API the current use granted undername, one function per method;ApiNotGrantedErrorotherwise. Trailingundefinedarguments are dropped before a method call.ApiNotGrantedError,RegisterAfterSealError,ImportRefusedError— theirnameis the contract name (SandboxApiNotGranted,SandboxRegisterSealed,SandboxImportRefused); match by name.RUNTIME—"sandbox-js-1", the contract token of bundles built with this library.@milaboratories/sandbox-js-1-guest/env— the environment's globals for a model's type check;tsconfig.guest.jsona startingcompilerOptions.
Bundling
Bundle the library into the model, and keep sandbox:sys external through every step: the artifact serves it and refuses every other import, so an inlined copy fails the load. With esbuild: external: ["sandbox:sys"], format: "esm".
