State storage
On this page
State that outlives one call, or crosses worker processes.
class BoundStorage
Section titled âclass BoundStorageâexport class BoundStorageMethods
method workerScan
Section titled âmethod workerScanâworkerScan(): Promise<Array<[number, Uint8Array]>>method queuePush
Section titled âmethod queuePushâqueuePush(items: Uint8Array[]): Promise<number>method stateGet
Section titled âmethod stateGetâstateGet(ns: Uint8Array, key: Uint8Array): Promise<Uint8Array | null>method statePut
Section titled âmethod statePutâstatePut(ns: Uint8Array, key: Uint8Array, value: Uint8Array): Promise<void>method stateAppend
Section titled âmethod stateAppendâstateAppend(ns: Uint8Array, key: Uint8Array, item: Uint8Array): Promise<number>method stateLogScan
Section titled âmethod stateLogScanâstateLogScan( ns: Uint8Array, key: Uint8Array, afterId: number = -1, limit: number | null = null,): Promise<Array<[number, Uint8Array]>>method executionClear
Section titled âmethod executionClearâexecutionClear(): Promise<number>type FetchLike
Section titled âtype FetchLikeâexport type FetchLike = (input: string,init?: { method?: string; headers?: Record<string, string>; body?: string },) => Promise<Response>;Description
Minimal fetch signature satisfied by both the global fetch and a
Cloudflare service-binding Fetcher (env.<BINDING>).
const functionStorage
Section titled âconst functionStorageâconst storage: FunctionStorageDescription
Default FunctionStorage instance. Backend is selected via env on first access.
interface FunctionStorage
Section titled âinterface FunctionStorageâexport interface FunctionStorageFields
workerPut(executionId: Uint8Array, workerId: number, state: Uint8Array): Promise<void>workerCollect(executionId: Uint8Array): Promise<Uint8Array[]>workerScan(executionId: Uint8Array): Promise<Array<[number, Uint8Array]>>queuePush(executionId: Uint8Array, items: Uint8Array[]): Promise<number>queuePop(executionId: Uint8Array): Promise<Uint8Array | null>queueClear(executionId: Uint8Array): Promise<number>stateGet(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array): Promise<Uint8Array | null>statePut(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, value: Uint8Array): Promise<void>stateAppend(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, item: Uint8Array): Promise<number>stateLogScan( scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, afterId?: number, limit?: number | null, ): Promise<Array<[number, Uint8Array]>>executionClear(scopeId: Uint8Array): Promise<number>Wipe all state + log rows for a scope across every namespace.
close(): Promise<void> | voidoptionalOptional cleanup hook. Implementations holding a connection should release it here.
class FunctionStorageCfDo
Section titled âclass FunctionStorageCfDoâexport class FunctionStorageCfDo implements FunctionStorageMethods
method forShard
Section titled âmethod forShardâforShard(shardKey: string): FunctionStorageCfDoReturn a view of this backend pinned to one shard key, so callers can route per logical ATTACH. Shares the URL/token; only the shard key differs.
method workerPut
Section titled âmethod workerPutâasync workerPut(executionId: Uint8Array, workerId: number, state: Uint8Array): Promise<void>method workerCollect
Section titled âmethod workerCollectâasync workerCollect(executionId: Uint8Array): Promise<Uint8Array[]>method workerScan
Section titled âmethod workerScanâasync workerScan(executionId: Uint8Array): Promise<Array<[number, Uint8Array]>>method queuePush
Section titled âmethod queuePushâasync queuePush(executionId: Uint8Array, items: Uint8Array[]): Promise<number>method queuePop
Section titled âmethod queuePopâasync queuePop(executionId: Uint8Array): Promise<Uint8Array | null>method queueClear
Section titled âmethod queueClearâasync queueClear(executionId: Uint8Array): Promise<number>method stateGet
Section titled âmethod stateGetâasync stateGet(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array): Promise<Uint8Array | null>method statePut
Section titled âmethod statePutâasync statePut(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, value: Uint8Array): Promise<void>method stateAppend
Section titled âmethod stateAppendâasync stateAppend(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, item: Uint8Array): Promise<number>method stateLogScan
Section titled âmethod stateLogScanâasync stateLogScan( scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, afterId: number = -1, limit: number | null = null,): Promise<Array<[number, Uint8Array]>>method executionClear
Section titled âmethod executionClearâasync executionClear(scopeId: Uint8Array): Promise<number>Wipe all state + log rows for a scope across every namespace.
class FunctionStorageSqlite
Section titled âclass FunctionStorageSqliteâexport class FunctionStorageSqlite implements FunctionStorageProperties
Methods
method close
Section titled âmethod closeâclose(): voidOptional cleanup hook. Implementations holding a connection should release it here.
method stateGet
Section titled âmethod stateGetâasync stateGet(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array): Promise<Uint8Array | null>method statePut
Section titled âmethod statePutâasync statePut(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, value: Uint8Array): Promise<void>method stateAppend
Section titled âmethod stateAppendâasync stateAppend(scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, item: Uint8Array): Promise<number>method stateLogScan
Section titled âmethod stateLogScanâasync stateLogScan( scopeId: Uint8Array, ns: Uint8Array, key: Uint8Array, afterId: number = -1, limit: number | null = null,): Promise<Array<[number, Uint8Array]>>method executionClear
Section titled âmethod executionClearâasync executionClear(scopeId: Uint8Array): Promise<number>Wipe all state + log rows for a scope across every namespace.
method workerPut
Section titled âmethod workerPutâasync workerPut( executionId: Uint8Array, workerId: number, state: Uint8Array): Promise<void>method workerCollect
Section titled âmethod workerCollectâasync workerCollect(executionId: Uint8Array): Promise<Uint8Array[]>method workerScan
Section titled âmethod workerScanâasync workerScan(executionId: Uint8Array): Promise<Array<[number, Uint8Array]>>method queuePush
Section titled âmethod queuePushâasync queuePush(executionId: Uint8Array, items: Uint8Array[]): Promise<number>method queuePop
Section titled âmethod queuePopâasync queuePop(executionId: Uint8Array): Promise<Uint8Array | null>method queueClear
Section titled âmethod queueClearâasync queueClear(executionId: Uint8Array): Promise<number>function resolveStorageFromEnv
Section titled âfunction resolveStorageFromEnvâexport function resolveStorageFromEnv(): FunctionStorageDescription
Resolve the FunctionStorage backend from environment variables.
Mirrors vgi-pythonâs _resolve_storage in vgi/function.py.
VGI_WORKER_SHARED_STORAGE selects the backend (default: sqlite):
memoryâFunctionStorageSqliteat:memory:. Process-local with no cross-process coordination â single-process deployments only. IgnoresVGI_WORKER_SQLITE_PATH.sqliteâFunctionStorageSqlite. HonorsVGI_WORKER_SQLITE_PATH(including:memory:).cloudflare-doâFunctionStorageCfDo. RequiresVGI_CF_DO_URL; optionalVGI_CF_DO_TOKENfor bearer auth.
function setStorage
Section titled âfunction setStorageâexport function setStorage(impl: FunctionStorage): voidDescription
Override the default backend used by the storage singleton. Call once at
worker startup to inject a pre-built backend that env-driven selection canât
construct â notably a FunctionStorageCfDo wired to a Cloudflare
service-binding Fetcher (the binding lives on env, not process.env, and a
same-zone public-URL fetch is rejected with CF error 1042). Takes precedence
over VGI_WORKER_SHARED_STORAGE.
class UnknownInvocationError
Section titled âclass UnknownInvocationErrorâexport class UnknownInvocationError extends Error