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

Class SqliteTaskLedgerStoreImpl

packages/storage/src/task-ledger-store.ts:65–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65class SqliteTaskLedgerStoreImpl implements SqliteTaskLedgerStore {
66 readonly #lease: OperationalStateDatabaseLease;
67 private readonly writeQueues = new Map<string, Promise<void>>();
68 private readonly listeners = new Set<(event: TaskLedgerChangedEvent) => void>();
69
70 constructor(workspaceRoot: string) {
71 this.#lease = acquireOperationalStateDatabase(resolve(workspaceRoot));
72 registerTaskLedgerCanonicalReader(this, {
73 list: (sessionId, options) => this.#listCanonical(sessionId, options),
74 get: (sessionId, id, options) => this.#getCanonical(sessionId, id, options),
75 });
76 }
77
78 ready(): Promise<void> {
79 return Promise.resolve();
80 }
81
82 close(): void {
83 this.#lease.close();
84 }
85
86 async list(sessionId: string, options: TaskLedgerListOptions = {}): Promise<Task[]> {
87 assertSafeSessionId(sessionId);
88 return this.applyListOptions(await this.readForRender(sessionId), options);
89 }
90
91 async get(
92 sessionId: string,
93 id: string,
94 options: TaskLedgerListOptions = {},
95 ): Promise<Task | undefined> {
96 assertSafeSessionId(sessionId);
97 if (!isSafeTaskId(id))
98 throw new Error('Task id must be a stable token (alphanumeric plus . _ : -, max 64 chars)');
99 const tasks = await this.list(sessionId, options);
100 return findTaskByRef(tasks, id);
101 }
102
103 async #listCanonical(sessionId: string, options: TaskLedgerListOptions = {}): Promise<Task[]> {
104 assertSafeSessionId(sessionId);
105 const { tasks } = await this.readForMutateWithSource(sessionId);
106 return this.applyListOptions(tasks, options);
107 }
108
109 async #getCanonical(
110 sessionId: string,
111 id: string,
112 options: TaskLedgerListOptions = {},
113 ): Promise<Task | undefined> {
114 assertSafeSessionId(sessionId);
115 if (!isSafeTaskId(id))
116 throw new Error('Task id must be a stable token (alphanumeric plus . _ : -, max 64 chars)');
117 return findTaskByRef(await this.#listCanonical(sessionId, options), id);
118 }
119
120 subscribe(listener: (event: TaskLedgerChangedEvent) => void): () => void {
121 this.listeners.add(listener);
122 return () => this.listeners.delete(listener);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected