MCPcopy Create free account
hub / github.com/apache/maka / SqliteRuntimeStore

Class SqliteRuntimeStore

packages/storage/src/sqlite-runtime-store.ts:231–2930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231export class SqliteRuntimeStore
232 implements
233 RuntimeRecoveryBundleStore,
234 RuntimeContinuationAuthorityStore,
235 RuntimeWorkspaceVersionAuthorityStore
236{
237 readonly durability = 'canonical' as const;
238 readonly toolBoundaryProtocol = 't1_after_preflight_v1' as const;
239 readonly recoveryBundleCapability = TOOL_RECOVERY_BUNDLE_CAPABILITY_V1;
240 readonly continuationAuthorityCapability = RUNTIME_CONTINUATION_AUTHORITY_V1;
241 readonly workspaceVersionAuthorityCapability = WORKSPACE_VERSION_AUTHORITY_CAPABILITY_V1;
242 private readonly db: DatabaseSync;
243 private readonly databaseLease?: OperationalStateDatabaseLease;
244 private toolLedgerHealth: ToolLedgerHealth | undefined;
245 private closed = false;
246
247 constructor(
248 path: string,
249 private readonly options: SqliteRuntimeStoreOptions = {},
250 ) {
251 if (options.readOnly && options.databaseLease) {
252 throw new Error('Operational state database leases cannot be opened read-only');
253 }
254 if (path !== ':memory:' && !options.readOnly) mkdirSync(dirname(path), { recursive: true });
255 if (options.databaseLease) {
256 this.databaseLease = options.databaseLease;
257 this.db = options.databaseLease.database;
258 assertRecoveryAuthorityCapability(this.db);
259 assertContinuationAuthorityCapability(this.db);
260 assertWorkspaceVersionAuthorityCapability(this.db);
261 if (!options.readOnly) {
262 this.registerWorkspaceBaselineAuthorityWriter(options.databaseLease.databasePath);
263 this.refreshToolLedgerHealth();
264 }
265 return;
266 }
267 const DatabaseSync = loadDatabaseSync();
268 this.db = options.readOnly
269 ? new DatabaseSync(path, { readOnly: true })
270 : new DatabaseSync(path);
271 try {
272 if (options.readOnly) {
273 configureSqliteRuntimeReadOnlyDatabase(this.db);
274 const version = readUserVersion(this.db);
275 if (version !== SQLITE_RUNTIME_SCHEMA_VERSION) {
276 throw new Error(
277 `SQLite runtime schema ${version} cannot be read without upgrading to ${SQLITE_RUNTIME_SCHEMA_VERSION}`,
278 );
279 }
280 } else {
281 configureSqliteRuntimeDatabase(this.db);
282 migrateSqliteRuntimeDatabase(this.db);
283 }
284 assertRecoveryAuthorityCapability(this.db);
285 assertContinuationAuthorityCapability(this.db);
286 assertWorkspaceVersionAuthorityCapability(this.db);
287 if (!options.readOnly) {
288 this.registerWorkspaceBaselineAuthorityWriter(path);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected