Machine versions

Machine definition version operations.

Machine definition versions contain the actual machine definition, which consists of a single self-contained javascript file that default exports an XState state machine as well as an allowRead and allowWrite function.

They are immutable and identified by an ID. The clientInfo field is informational only and intended to be used to identify the source of the machine version (e.g. git commit sha, semantic version number, timestamp, etc).

The allowRead and allowWrite functions are called to authorize read and write operations on machine instances, respectively. Write authorization implies the authority to read the result of your write.

Anything stored in the machine's context under the public key will be exposed to authorized readers and writers as publicContext.

Example machine definition

import type {
  AllowRead,
  AllowWrite,
} from "@statebacked/machine-def";
import { createMachine } from "xstate";

export const allowRead: AllowRead = (
  { machineInstanceName, authContext },
) => machineInstanceName === authContext.sub;

export const allowWrite: AllowWrite = (
  { machineInstanceName, authContext },
) => machineInstanceName === authContext.sub;

export default createMachine(...);