@barry-rocks/sdk/stores
Per-bag SQLite stores: openBagStore opens (and migrates) a bag’s store,
migrateStore and Migration run ordered migrations, and the registry types
describe where each store lives. The machine or an identity owns each store,
as bag.yaml declares.
import { … } from "@barry-rocks/sdk/stores";Classes
Section titled “Classes”AmbiguousSessionLocation
Section titled “AmbiguousSessionLocation”Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AmbiguousSessionLocation():
AmbiguousSessionLocation
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor
StoreRegistry
Section titled “StoreRegistry”Providers are installed locally. Snapshot metadata never supplies executable code.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StoreRegistry(
nodeId,root?):StoreRegistry
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
nodeId |
string |
root |
string |
Returns
Section titled “Returns”Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
nodeId |
readonly |
string |
root |
readonly |
string |
Methods
Section titled “Methods”declarationsFor()
Section titled “declarationsFor()”declarationsFor(
scope?):object[]
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
scope? |
StoreScope |
Returns
Section titled “Returns”object[]
forRoot()
Section titled “forRoot()”forRoot(
root):StoreRegistry
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
root |
string |
Returns
Section titled “Returns”hasRestoreAdapter()
Section titled “hasRestoreAdapter()”hasRestoreAdapter(
bag,name):boolean
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
name |
string |
Returns
Section titled “Returns”boolean
hasSnapshotAdapter()
Section titled “hasSnapshotAdapter()”hasSnapshotAdapter(
bag,name):boolean
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
name |
string |
Returns
Section titled “Returns”boolean
open()
Section titled “open()”open(
ref,readonly?):Promise<RegistryStoreHandle>
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
ref |
StoreRef |
undefined |
readonly |
boolean |
false |
Returns
Section titled “Returns”Promise<RegistryStoreHandle>
prepareRestore()
Section titled “prepareRestore()”prepareRestore(
snapshot,destination):Promise<void>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
StoreSnapshot |
destination |
string |
Returns
Section titled “Returns”Promise<void>
register()
Section titled “register()”register(
bag,name,declaration,provider):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
name |
string |
declaration |
StoreDeclaration |
provider |
StoreProvider |
Returns
Section titled “Returns”void
registerRestoreAdapter()
Section titled “registerRestoreAdapter()”registerRestoreAdapter(
bag,name,adapter):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
name |
string |
adapter |
StoreRestoreAdapter |
Returns
Section titled “Returns”void
registerSnapshotAdapter()
Section titled “registerSnapshotAdapter()”registerSnapshotAdapter(
bag,name,adapter):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
name |
string |
adapter |
StoreSnapshotAdapter |
Returns
Section titled “Returns”void
snapshot()
Section titled “snapshot()”snapshot(
ref,directory):Promise<StoreSnapshot>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
StoreRef |
directory |
string |
Returns
Section titled “Returns”Promise<StoreSnapshot>
validateDatabase()
Section titled “validateDatabase()”validateDatabase(
ref,path):Promise<void>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
StoreRef |
path |
string |
Returns
Section titled “Returns”Promise<void>
Interfaces
Section titled “Interfaces”BagStore
Section titled “BagStore”Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
D extends StoreHandle |
Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Close every handle; the next use opens again.
Returns
Section titled “Returns”void
db():
D
The handle for the current store context, opened on first use.
Returns
Section titled “Returns”D
path()
Section titled “path()”path():
string
The path the current store context’s handle opens.
Returns
Section titled “Returns”string
replace()
Section titled “replace()”replace(
db):void
Use this handle instead (a test); it is migrated, and the previous one closed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
db |
D |
Returns
Section titled “Returns”void
BagStoreOptions
Section titled “BagStoreOptions”Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
D extends StoreHandle |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
adopt? |
(db) => void |
Run on each newly opened handle before its migrations: adopting a store from before it had any. |
connect |
(path) => D |
Open the file with the bag’s driver: (path) => new Database(path). |
file |
string |
The store’s file name, as migrations and errors name it: events.db. |
foreignKeys? |
boolean |
On by default. |
identityScoped? |
boolean |
Keep a handle per identity when the store context names one. |
migrations |
readonly Migration[] |
- |
onOpen? |
(db, path) => void |
Run on each newly opened handle, after its migrations. |
path |
() => string |
Where the store is for the current store context; asked on every open. |
scratchGuard? |
string |
Refuse a path outside a scratch directory under test, naming this label. |
synchronous? |
"FULL" | "NORMAL" |
- |
MigratableDatabase
Section titled “MigratableDatabase”The part of a SQLite handle this needs. better-sqlite3 and node:sqlite both fit.
Extended by
Section titled “Extended by”Methods
Section titled “Methods”exec()
Section titled “exec()”exec(
sql):unknown
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
Returns
Section titled “Returns”unknown
prepare()
Section titled “prepare()”prepare(
sql):object
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
all() |
(…params) => unknown |
get() |
(…params) => unknown |
run() |
(…params) => unknown |
Migration
Section titled “Migration”One forward schema change loaded from SQL or a generated migration catalog.
Properties
Section titled “Properties”| Property | Type |
|---|---|
name |
string |
sql |
string |
MigrationResult
Section titled “MigrationResult”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
from |
number |
The version the store was at when opened. |
to |
number |
The version it is at now. |
RegistryStoreHandle
Section titled “RegistryStoreHandle”Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Returns
Section titled “Returns”void
revision()
Section titled “revision()”revision():
string
Returns
Section titled “Returns”string
schemaVersion()
Section titled “schemaVersion()”schemaVersion():
number
Returns
Section titled “Returns”number
snapshot()
Section titled “snapshot()”snapshot(
destination):Promise<void|object[]>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
destination |
string |
Returns
Section titled “Returns”Promise<void | object[]>
SnapshotManifest
Section titled “SnapshotManifest”Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Inherited from |
|---|---|---|
bag |
string |
StoreRef.bag |
bytes |
number |
- |
capturedAt |
string |
- |
checksum |
string |
- |
format |
1 |
- |
identity? |
string |
StoreRef.identity |
node |
string |
StoreRef.node |
resources? |
object[] |
- |
revision |
string |
- |
schemaVersion |
number |
- |
store |
string |
StoreRef.store |
StoreBagConfiguration
Section titled “StoreBagConfiguration”Properties
Section titled “Properties”| Property | Type |
|---|---|
overrides? |
Readonly<Record<string, { app_url?: string; engine?: "sqlite"; filepath?: string; url?: string; }>> |
remoteProtocols? |
readonly string[] |
stores |
Readonly<Record<string, StoreDeclaration>> |
StoreContext
Section titled “StoreContext”Properties
Section titled “Properties”| Property | Type |
|---|---|
bags? |
Readonly<Record<string, StoreBagConfiguration>> |
execution? |
ExecutionContext |
identity? |
string |
node? |
string |
root? |
string |
workflowActor? |
(path, body?) => string | Promise<string> |
StoreDeclaration
Section titled “StoreDeclaration”Properties
Section titled “Properties”| Property | Type |
|---|---|
engine |
"sqlite" |
migrations |
string |
owned_by |
StoreScope |
StoreHandle
Section titled “StoreHandle”The part of a SQLite handle a bag store needs. better-sqlite3 and node:sqlite both fit.
Extends
Section titled “Extends”Methods
Section titled “Methods”close()
Section titled “close()”close():
unknown
Returns
Section titled “Returns”unknown
exec()
Section titled “exec()”exec(
sql):unknown
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
Returns
Section titled “Returns”unknown
Inherited from
Section titled “Inherited from”prepare()
Section titled “prepare()”prepare(
sql):object
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
all() |
(…params) => unknown |
get() |
(…params) => unknown |
run() |
(…params) => unknown |
Inherited from
Section titled “Inherited from”StoreProvider
Section titled “StoreProvider”Properties
Section titled “Properties”| Property | Type |
|---|---|
migrations |
readonly Migration[] |
Methods
Section titled “Methods”open()
Section titled “open()”open(
path,options):RegistryStoreHandle|Promise<RegistryStoreHandle>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
options |
{ readonly: boolean; } |
options.readonly |
boolean |
Returns
Section titled “Returns”RegistryStoreHandle | Promise<RegistryStoreHandle>
StoreRef
Section titled “StoreRef”Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type |
|---|---|
bag |
string |
identity? |
string |
node |
string |
store |
string |
StoreResolution
Section titled “StoreResolution”Properties
Section titled “Properties”StoreSnapshot
Section titled “StoreSnapshot”Properties
Section titled “Properties”| Property | Type |
|---|---|
manifest |
SnapshotManifest |
path |
string |
Type Aliases
Section titled “Type Aliases”SnapshotResource
Section titled “SnapshotResource”SnapshotResource =
z.infer<typeofSnapshotResourceSchema>
StoreOptions
Section titled “StoreOptions”StoreOptions =
z.infer<typeofStoreOptionsSchema>
StoreRestoreAdapter
Section titled “StoreRestoreAdapter”StoreRestoreAdapter = (
snapshot,ref,destination) =>Promise<void>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
StoreSnapshot |
ref |
StoreRef |
destination |
string |
Returns
Section titled “Returns”Promise<void>
StoreScope
Section titled “StoreScope”StoreScope =
"identity"|"node"
StoreSnapshotAdapter
Section titled “StoreSnapshotAdapter”StoreSnapshotAdapter = (
ref,source,destination) =>Promise<SnapshotResource[]>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
StoreRef |
source |
string |
destination |
string |
Returns
Section titled “Returns”Promise<SnapshotResource[]>
Variables
Section titled “Variables”SnapshotManifestSchema
Section titled “SnapshotManifestSchema”
constSnapshotManifestSchema:ZodObject<{bag:ZodString;bytes:ZodNumber;capturedAt:ZodISODateTime;checksum:ZodString;format:ZodLiteral<1>;identity:ZodOptional<ZodString>;node:ZodString;resources:ZodOptional<ZodArray<ZodObject<{files:ZodArray<ZodObject<{bytes:ZodNumber;checksum:ZodString;path:ZodString; },$strict>>;name:ZodString; },$strict>>>;revision:ZodString;schemaVersion:ZodNumber;store:ZodString; },$strict>
SnapshotResourceSchema
Section titled “SnapshotResourceSchema”
constSnapshotResourceSchema:ZodObject<{files:ZodArray<ZodObject<{bytes:ZodNumber;checksum:ZodString;path:ZodString; },$strict>>;name:ZodString; },$strict>
StoreOptionsSchema
Section titled “StoreOptionsSchema”
constStoreOptionsSchema:ZodObject<{app_url:ZodOptional<ZodURL>;engine:ZodOptional<ZodLiteral<"sqlite">>;filepath:ZodOptional<ZodString>;url:ZodOptional<ZodURL>; },$strict>
Functions
Section titled “Functions”assertScratchStoreUnderTest()
Section titled “assertScratchStoreUnderTest()”assertScratchStoreUnderTest(
label,path):void
Enforce scratch paths at store opening under VITEST, unless the explicit BARRY_ALLOW_NON_TEST_STORE opt-out is set. Path-only lookups do not open stores. See docs/decisions/0038-test-isolation-and-command-reservations.md.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
label |
string |
path |
string |
Returns
Section titled “Returns”void
copySnapshot()
Section titled “copySnapshot()”copySnapshot(
snapshot,destination):Promise<void>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
StoreSnapshot |
destination |
string |
Returns
Section titled “Returns”Promise<void>
identityStorePaths()
Section titled “identityStorePaths()”identityStorePaths(
bag,store):object[]
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
store |
string |
Returns
Section titled “Returns”object[]
installSnapshot()
Section titled “installSnapshot()”installSnapshot(
snapshot,directory):Promise<StoreSnapshot>
Install into a new generation; callers switch their index only after validation.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
StoreSnapshot |
directory |
string |
Returns
Section titled “Returns”Promise<StoreSnapshot>
mergeStoreOptions()
Section titled “mergeStoreOptions()”mergeStoreOptions(
parent?,child?):object
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parent |
{ app_url?: string; engine?: "sqlite"; filepath?: string; url?: string; } |
parent.app_url? |
string |
parent.engine? |
"sqlite" |
parent.filepath? |
string |
parent.url? |
string |
child |
{ app_url?: string; engine?: "sqlite"; filepath?: string; url?: string; } |
child.app_url? |
string |
child.engine? |
"sqlite" |
child.filepath? |
string |
child.url? |
string |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
app_url? |
string |
engine? |
"sqlite" |
filepath? |
string |
url? |
string |
migratedStorePath()
Section titled “migratedStorePath()”migratedStorePath(
bag,store,legacy,nodeStore?,scope?):string
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
bag |
string |
undefined |
store |
string |
undefined |
legacy |
() => string |
undefined |
nodeStore |
string |
store |
scope |
"identity" | "node" |
"identity" |
Returns
Section titled “Returns”string
migrateStore()
Section titled “migrateStore()”migrateStore(
db,migrations,store):MigrationResult
Apply every migration the store has not seen, in order, all in one transaction with the version read.
Refuses a store stamped newer than migrations knows about: an older build
would otherwise read the tables it recognises and silently ignore columns
added since.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
db |
MigratableDatabase |
- |
migrations |
readonly Migration[] |
- |
store |
string |
A name for error messages, e.g. “sessions.db”. |
Returns
Section titled “Returns”openBagStore()
Section titled “openBagStore()”openBagStore<
D>(options):BagStore<D>
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
D extends StoreHandle |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
BagStoreOptions<D> |
Returns
Section titled “Returns”BagStore<D>
openStoreFile()
Section titled “openStoreFile()”openStoreFile<
D>(path,options):D
Open a SQLite file with the settings every bag store uses, before any migration.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
D extends StoreHandle |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
options |
Pick<BagStoreOptions<D>, "connect" | "foreignKeys" | "synchronous"> |
Returns
Section titled “Returns”D
resolveStoreBinding()
Section titled “resolveStoreBinding()”resolveStoreBinding(
bag,declarations,resolution):StoreBinding
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bag |
string |
declarations |
Readonly<Record<string, StoreDeclaration>> |
resolution |
StoreResolution |
Returns
Section titled “Returns”sessionIdentity()
Section titled “sessionIdentity()”sessionIdentity(
sessionId):string|undefined
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
Returns
Section titled “Returns”string | undefined
storeKey()
Section titled “storeKey()”storeKey(
ref):string
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
StoreRef |
Returns
Section titled “Returns”string
storePath()
Section titled “storePath()”storePath(
ref,scope,root?):string
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
StoreRef |
scope |
StoreScope |
root |
string |
Returns
Section titled “Returns”string
validateSnapshot()
Section titled “validateSnapshot()”validateSnapshot(
snapshot):Promise<void>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
StoreSnapshot |
Returns
Section titled “Returns”Promise<void>
References
Section titled “References”StoreBinding
Section titled “StoreBinding”Re-exports StoreBinding