API
// @chia1104/motoko-node/http
motokoHandler<T, C = void>(runtime, { resolve, authorize?, sessionOptions?, calls?, onError?, basePath?, heartbeatMs?, maxBodyBytes?, cluster? }): MotokoHandler<C>
sessionEventStream(instance, sessionId, { from?, signal?, heartbeatMs?, onError? }?): Promise<Response> // a follow's answer, for the app's own route
statusOf(code: CallErrorCode): number // the status a call error is answered with
type CallOverrides<T> = { [M in CallMethod]?: (params, { target, request, run }) => CallResult<M> } // calls: the app's own handling
type MotokoHandler<C = void> = (request: Request, context: C) => Promise<Response> // context: the app's, for resolve
type MotokoCluster = (error: LeaseHeldError, request: Request, path: string, body: string | undefined) => Promise<Response | undefined>
interface MotokoTarget { agent: AgentDefinition | string; name: string } // what resolve answers, with the app's own fields
type HttpCall = Call | FollowCall // what authorize decides on
interface FollowCall { method: "follow"; params: { sessionId: string; from?: Cursor } }
// @chia1104/motoko-node
nodeListener(handler, { onError? }?): (req: IncomingMessage, res: ServerResponse) => void
nodeCluster(options: ClusterOptions): MotokoCluster // experimental: see "Forwarding"
interface ClusterOptions {
self: string; // this node's internal base URL, and its lease holder
peers: readonly string[] | ((holder: string) => boolean); // the holders it may forward to
connectTimeoutMs?: number; // default 2 000
}
FORWARDED_BY = "motoko-forwarded-by" // the header a forward sets
sqliteStore({ directory } | { path }, lease?): AgentStore // sqliteStorage with unfinished and erase
sqliteStorage({ directory } | { path }): StorageFactory
sqliteScopes(directory): AsyncIterable<StorageScope> // every scope with a file under directory
eraseSqliteConversations(file, conversations, { prefix? })
scopeFile(directory, scope) · scopeFileSegment(value)
type StorageFactory = (scope: StorageScope, lease: Lease) => Promise<Storage>;
type LeaseProvider = (scope: StorageScope) => Promise<Lease>;sqliteStore is the complete store on SQLite files: sqliteStorage under lease (default core's
processLeases), erase from eraseSqliteConversations, and, with directory, unfinished from
sqliteScopes. processHost(sqliteStore(options)) is its host. sqliteStorage({ directory }) takes
any lease, so processHost({ storage: sqliteStorage(options) }) is a host too, one that neither
recovers nor erases.
sqliteStorage and sqliteStore also take sqlite, pi-durable's NodeSqliteStorageOptions: the connection's
(such as busyTimeoutMs) and a table prefix. Each file opens in WAL mode with SQLite's secure_delete on, so
what pi-durable deletes while it is open is overwritten, not only unlinked. Any other pi-durable storage is a StorageFactory as it is: for tests and demos,
storage: async () => new MemoryStorage() with MemoryStorage from @earendil-works/pi-durable
(a fresh, empty storage at every open). pi-durable is a peer dependency at ~1.6.0, as for
@chia1104/motoko-core.