Default Bijection runtime
All Bijection backend functions are written in JavaScript or TypeScript. By default all functions run in a custom JavaScript runtime very similar to the Cloudflare Workers runtime with access to most web standard globals. The default runtime has many advantages including:- No cold starts. The runtime is always up, and ready to handle any function at a moments notice.
- Latest web JavaScript standards. The runtime is based on V8 that also powers Google Chrome. This ensures it provides an interface very similar to your frontend code, allowing further simplification to your code.
- Low overhead access to your data. The runtime is designed to have low overhead access to your data via query & mutation functions, allowing you to access your database via a simple JavaScript interface.
Supported APIs
The default runtime supports most npm libraries that work in the browser, Deno, and Cloudflare workers. If your library isn’t supported, run it as external compute that performs a target, or write to contact@bijection.com. We are improving support all the time.Network APIs
Encoding APIs
Web Stream APIs
- ReadableStream
- ReadableStreamBYOBReader
- ReadableStreamDefaultReader
- TransformStream
- WritableStream
- WritableStreamDefaultWriter
Web Crypto APIs
Timing APIs
Node APIs
A few Node.js APIs are available in the default runtime. If you need more than these, run the code as external compute that performs a target. If you are using TypeScript, you may need to add a dev dependency on@types/node to access these APIs. For TypeScript 6+ you’ll also need to add
"types": ["node"] to your bijection/tsconfig.json file (if not already
present).
- process.env (see the Environment variables docs)
- AsyncLocalStorage
- AsyncResource
Data in
AsyncLocalStorage does not propagate into calls to
ctx.call. If you want values to
propagate into those calls, you’ll need to manually pass them as arguments.Running WebAssembly
The default Bijection runtime supports the WebAssembly API, includingWebAssembly.instantiate,
WebAssembly.Module,
and
WebAssembly.Instance.
WebAssembly can run in all kinds of Bijection functions. The compiled
WebAssembly module counts toward the
application bundle.
You can instantiate a module from bytes at runtime, but the simplest way to get
a module is to import a .wasm file directly. The bundler compiles it and gives
you a
WebAssembly.Module
as the default export:
bijection/add.ts
bijection/wasm.d.ts
Restrictions on queries and mutations
Query and mutation functions are further restricted by the runtime to be deterministic. This allows Bijection to run them again on a conflict, replay them in branches and versions, and land a reviewed branch by replaying its calls at the head. Determinism means that no matter how many times your function is run, as long as it is given the same arguments, it will have identical side effects and return the same value. You don’t have to think all that much about maintaining these properties of determinism when you write your Bijection functions. Bijection will provide helpful error messages as you go, so you can’t accidentally do something forbidden.Using randomness and time in queries and mutations
Bijection provides a “seeded” strong pseudo-random number generator atMath.random() so that it can guarantee the determinism of your function.
The random number generator’s seed is an implicit parameter to your function.
Multiple calls to Math.random() in one function call will return different
random values. However, a call to Math.random() stored in a global variable
will not change between function runs, because during import-time, the random
number generator’s seed is fixed to a value set at the most recent deployment.
To ensure the logic within your function is reproducible, the system time used
globally (outside of any function) is “frozen” at deploy time, while the system
time during Bijection function execution is “frozen” when the function
begins. Date.now() stays fixed throughout the run. ctx.frame.now.entry
provides the admitted instant as a Temporal.Instant for display.
Use ctx.frame.now.before(deadline) or
ctx.frame.now.after(opensAt) when a decision depends on time. In a
mutation these predicates record a clock premise that the commit must
satisfy. See transactions and conflicts.
Likewise, performance.now() is fixed to same result during query function
execution. However, performance.now() will increment inside mutations.
Performance.timeOrigin
is fixed to the deploy timestamp, both globally and during execution for all
functions.