@axiom-lattice/local-stores 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +69 -1
- package/dist/index.d.ts +69 -1
- package/dist/index.js +104 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/migrations/migration.ts +156 -0
- package/src/stores/LocalThreadStore.ts +11 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/local-stores@1.0.
|
|
2
|
+
> @axiom-lattice/local-stores@1.0.16 build /home/runner/work/agentic/agentic/packages/local-stores
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2020
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m116.68 KB[39m
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m221.36 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 429ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m119.95 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m223.95 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 433ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 16180ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m26.92 KB[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m26.92 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -119,6 +119,74 @@ declare function nowISO(): string;
|
|
|
119
119
|
*/
|
|
120
120
|
declare function parseISO(iso: string): Date;
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Migration system for SQLite (sql.js) local stores.
|
|
124
|
+
*
|
|
125
|
+
* ## Identity vs Ordering
|
|
126
|
+
*
|
|
127
|
+
* **name = identity** — each migration is uniquely identified by its name
|
|
128
|
+
* within a store. Two stores may use the same name without conflict because
|
|
129
|
+
* the tracking table includes a `store_name` column.
|
|
130
|
+
*
|
|
131
|
+
* **version = ordering** — migrations are applied in ascending version order.
|
|
132
|
+
*
|
|
133
|
+
* ## Usage
|
|
134
|
+
*
|
|
135
|
+
* Each store creates its own MigrationManager with a unique store name:
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* const mm = new MigrationManager(db, "lt_threads");
|
|
139
|
+
* mm.register({ version: 1, name: "create_table", up: (db) => { db.exec(DDL); } });
|
|
140
|
+
* mm.register({ version: 2, name: "add_column_x", up: (db) => { db.exec(ALTER); } });
|
|
141
|
+
* mm.migrate();
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* - All methods are synchronous (SQLite via sql.js is single-threaded)
|
|
146
|
+
* - Duplicate **names** within the same store are rejected at registration time
|
|
147
|
+
* - Duplicate **versions** are allowed (same positioning, different tables)
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Migration definition
|
|
152
|
+
*/
|
|
153
|
+
interface Migration {
|
|
154
|
+
version: number;
|
|
155
|
+
name: string;
|
|
156
|
+
up: (db: DatabaseWrapper) => void;
|
|
157
|
+
down?: (db: DatabaseWrapper) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Migration manager — one per store.
|
|
161
|
+
* Each store manages its own independent migration namespace via `storeName`.
|
|
162
|
+
*/
|
|
163
|
+
declare class MigrationManager {
|
|
164
|
+
private db;
|
|
165
|
+
private storeName;
|
|
166
|
+
private migrations;
|
|
167
|
+
constructor(db: DatabaseWrapper, storeName: string);
|
|
168
|
+
/**
|
|
169
|
+
* Register a migration.
|
|
170
|
+
* Duplicate names within this store are rejected immediately.
|
|
171
|
+
* Duplicate versions are allowed.
|
|
172
|
+
*/
|
|
173
|
+
register(migration: Migration): void;
|
|
174
|
+
/**
|
|
175
|
+
* Apply all pending migrations in version order.
|
|
176
|
+
*/
|
|
177
|
+
migrate(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Rollback the last-applied migration (highest version) for this store.
|
|
180
|
+
*/
|
|
181
|
+
rollback(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Get the highest applied migration version for this store.
|
|
184
|
+
*/
|
|
185
|
+
getCurrentVersion(): number;
|
|
186
|
+
private ensureTrackingTable;
|
|
187
|
+
private getAppliedNames;
|
|
188
|
+
}
|
|
189
|
+
|
|
122
190
|
/**
|
|
123
191
|
* Local SQLite implementation of ThreadStore.
|
|
124
192
|
*/
|
|
@@ -566,4 +634,4 @@ declare function createLocalStoreConfig(options?: LocalStoreConfigOptions): Prom
|
|
|
566
634
|
checkpoint: SqliteSaver;
|
|
567
635
|
}>;
|
|
568
636
|
|
|
569
|
-
export { DatabaseWrapper, LocalA2AApiKeyStore, LocalAssistantStore, LocalChannelBindingStore, LocalChannelInstallationStore, LocalDatabaseConfigStore, LocalEvalStore, LocalMcpServerConfigStore, LocalMetricsServerConfigStore, LocalProjectStore, LocalScheduleStorage, LocalSkillStore, type LocalStoreConfigOptions, type LocalStoreOptions, LocalTaskStore, LocalTenantStore, LocalThreadMessageQueueStore, LocalThreadStore, LocalUserStore, LocalUserTenantLinkStore, LocalWorkflowTrackingStore, LocalWorkspaceStore, RunResult, StatementWrapper, closeDatabase, createLocalStoreConfig, ensureTable, getDatabase, initDatabase, nowISO, parseISO };
|
|
637
|
+
export { DatabaseWrapper, LocalA2AApiKeyStore, LocalAssistantStore, LocalChannelBindingStore, LocalChannelInstallationStore, LocalDatabaseConfigStore, LocalEvalStore, LocalMcpServerConfigStore, LocalMetricsServerConfigStore, LocalProjectStore, LocalScheduleStorage, LocalSkillStore, type LocalStoreConfigOptions, type LocalStoreOptions, LocalTaskStore, LocalTenantStore, LocalThreadMessageQueueStore, LocalThreadStore, LocalUserStore, LocalUserTenantLinkStore, LocalWorkflowTrackingStore, LocalWorkspaceStore, type Migration, MigrationManager, RunResult, StatementWrapper, closeDatabase, createLocalStoreConfig, ensureTable, getDatabase, initDatabase, nowISO, parseISO };
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,74 @@ declare function nowISO(): string;
|
|
|
119
119
|
*/
|
|
120
120
|
declare function parseISO(iso: string): Date;
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Migration system for SQLite (sql.js) local stores.
|
|
124
|
+
*
|
|
125
|
+
* ## Identity vs Ordering
|
|
126
|
+
*
|
|
127
|
+
* **name = identity** — each migration is uniquely identified by its name
|
|
128
|
+
* within a store. Two stores may use the same name without conflict because
|
|
129
|
+
* the tracking table includes a `store_name` column.
|
|
130
|
+
*
|
|
131
|
+
* **version = ordering** — migrations are applied in ascending version order.
|
|
132
|
+
*
|
|
133
|
+
* ## Usage
|
|
134
|
+
*
|
|
135
|
+
* Each store creates its own MigrationManager with a unique store name:
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* const mm = new MigrationManager(db, "lt_threads");
|
|
139
|
+
* mm.register({ version: 1, name: "create_table", up: (db) => { db.exec(DDL); } });
|
|
140
|
+
* mm.register({ version: 2, name: "add_column_x", up: (db) => { db.exec(ALTER); } });
|
|
141
|
+
* mm.migrate();
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* - All methods are synchronous (SQLite via sql.js is single-threaded)
|
|
146
|
+
* - Duplicate **names** within the same store are rejected at registration time
|
|
147
|
+
* - Duplicate **versions** are allowed (same positioning, different tables)
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Migration definition
|
|
152
|
+
*/
|
|
153
|
+
interface Migration {
|
|
154
|
+
version: number;
|
|
155
|
+
name: string;
|
|
156
|
+
up: (db: DatabaseWrapper) => void;
|
|
157
|
+
down?: (db: DatabaseWrapper) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Migration manager — one per store.
|
|
161
|
+
* Each store manages its own independent migration namespace via `storeName`.
|
|
162
|
+
*/
|
|
163
|
+
declare class MigrationManager {
|
|
164
|
+
private db;
|
|
165
|
+
private storeName;
|
|
166
|
+
private migrations;
|
|
167
|
+
constructor(db: DatabaseWrapper, storeName: string);
|
|
168
|
+
/**
|
|
169
|
+
* Register a migration.
|
|
170
|
+
* Duplicate names within this store are rejected immediately.
|
|
171
|
+
* Duplicate versions are allowed.
|
|
172
|
+
*/
|
|
173
|
+
register(migration: Migration): void;
|
|
174
|
+
/**
|
|
175
|
+
* Apply all pending migrations in version order.
|
|
176
|
+
*/
|
|
177
|
+
migrate(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Rollback the last-applied migration (highest version) for this store.
|
|
180
|
+
*/
|
|
181
|
+
rollback(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Get the highest applied migration version for this store.
|
|
184
|
+
*/
|
|
185
|
+
getCurrentVersion(): number;
|
|
186
|
+
private ensureTrackingTable;
|
|
187
|
+
private getAppliedNames;
|
|
188
|
+
}
|
|
189
|
+
|
|
122
190
|
/**
|
|
123
191
|
* Local SQLite implementation of ThreadStore.
|
|
124
192
|
*/
|
|
@@ -566,4 +634,4 @@ declare function createLocalStoreConfig(options?: LocalStoreConfigOptions): Prom
|
|
|
566
634
|
checkpoint: SqliteSaver;
|
|
567
635
|
}>;
|
|
568
636
|
|
|
569
|
-
export { DatabaseWrapper, LocalA2AApiKeyStore, LocalAssistantStore, LocalChannelBindingStore, LocalChannelInstallationStore, LocalDatabaseConfigStore, LocalEvalStore, LocalMcpServerConfigStore, LocalMetricsServerConfigStore, LocalProjectStore, LocalScheduleStorage, LocalSkillStore, type LocalStoreConfigOptions, type LocalStoreOptions, LocalTaskStore, LocalTenantStore, LocalThreadMessageQueueStore, LocalThreadStore, LocalUserStore, LocalUserTenantLinkStore, LocalWorkflowTrackingStore, LocalWorkspaceStore, RunResult, StatementWrapper, closeDatabase, createLocalStoreConfig, ensureTable, getDatabase, initDatabase, nowISO, parseISO };
|
|
637
|
+
export { DatabaseWrapper, LocalA2AApiKeyStore, LocalAssistantStore, LocalChannelBindingStore, LocalChannelInstallationStore, LocalDatabaseConfigStore, LocalEvalStore, LocalMcpServerConfigStore, LocalMetricsServerConfigStore, LocalProjectStore, LocalScheduleStorage, LocalSkillStore, type LocalStoreConfigOptions, type LocalStoreOptions, LocalTaskStore, LocalTenantStore, LocalThreadMessageQueueStore, LocalThreadStore, LocalUserStore, LocalUserTenantLinkStore, LocalWorkflowTrackingStore, LocalWorkspaceStore, type Migration, MigrationManager, RunResult, StatementWrapper, closeDatabase, createLocalStoreConfig, ensureTable, getDatabase, initDatabase, nowISO, parseISO };
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ __export(index_exports, {
|
|
|
50
50
|
LocalUserTenantLinkStore: () => LocalUserTenantLinkStore,
|
|
51
51
|
LocalWorkflowTrackingStore: () => LocalWorkflowTrackingStore,
|
|
52
52
|
LocalWorkspaceStore: () => LocalWorkspaceStore,
|
|
53
|
+
MigrationManager: () => MigrationManager,
|
|
53
54
|
RunResult: () => RunResult,
|
|
54
55
|
StatementWrapper: () => StatementWrapper,
|
|
55
56
|
closeDatabase: () => closeDatabase,
|
|
@@ -232,10 +233,103 @@ function parseISO(iso) {
|
|
|
232
233
|
return new Date(iso);
|
|
233
234
|
}
|
|
234
235
|
|
|
236
|
+
// src/migrations/migration.ts
|
|
237
|
+
var MigrationManager = class {
|
|
238
|
+
constructor(db, storeName) {
|
|
239
|
+
this.migrations = [];
|
|
240
|
+
this.db = db;
|
|
241
|
+
this.storeName = storeName;
|
|
242
|
+
this.ensureTrackingTable();
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Register a migration.
|
|
246
|
+
* Duplicate names within this store are rejected immediately.
|
|
247
|
+
* Duplicate versions are allowed.
|
|
248
|
+
*/
|
|
249
|
+
register(migration) {
|
|
250
|
+
const existing = this.migrations.find((m) => m.name === migration.name);
|
|
251
|
+
if (existing) {
|
|
252
|
+
throw new Error(
|
|
253
|
+
`[${this.storeName}] Migration name conflict: "${migration.name}" v${migration.version} collides with existing registration at v${existing.version}`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
this.migrations.push(migration);
|
|
257
|
+
this.migrations.sort((a, b) => a.version - b.version);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Apply all pending migrations in version order.
|
|
261
|
+
*/
|
|
262
|
+
migrate() {
|
|
263
|
+
const appliedNames = this.getAppliedNames();
|
|
264
|
+
const pending = this.migrations.filter((m) => !appliedNames.has(m.name));
|
|
265
|
+
if (pending.length === 0) return;
|
|
266
|
+
for (const m of pending) {
|
|
267
|
+
m.up(this.db);
|
|
268
|
+
this.db.run(
|
|
269
|
+
`INSERT INTO lattice_schema_migrations (store_name, name, version, applied_at)
|
|
270
|
+
VALUES (?, ?, ?, ?)`,
|
|
271
|
+
[this.storeName, m.name, m.version, (/* @__PURE__ */ new Date()).toISOString()]
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Rollback the last-applied migration (highest version) for this store.
|
|
277
|
+
*/
|
|
278
|
+
rollback() {
|
|
279
|
+
const row = this.db.prepare(
|
|
280
|
+
`SELECT name, version FROM lattice_schema_migrations
|
|
281
|
+
WHERE store_name = ? ORDER BY version DESC LIMIT 1`
|
|
282
|
+
).get(this.storeName);
|
|
283
|
+
if (!row) {
|
|
284
|
+
throw new Error(`[${this.storeName}] No migrations to rollback`);
|
|
285
|
+
}
|
|
286
|
+
const migration = this.migrations.find((m) => m.name === row.name);
|
|
287
|
+
if (!migration?.down) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
`[${this.storeName}] Migration "${row.name}" (v${row.version}) has no down migration`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
migration.down(this.db);
|
|
293
|
+
this.db.run(
|
|
294
|
+
`DELETE FROM lattice_schema_migrations WHERE store_name = ? AND name = ?`,
|
|
295
|
+
[this.storeName, row.name]
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Get the highest applied migration version for this store.
|
|
300
|
+
*/
|
|
301
|
+
getCurrentVersion() {
|
|
302
|
+
const row = this.db.prepare(
|
|
303
|
+
`SELECT COALESCE(MAX(version), 0) AS max FROM lattice_schema_migrations
|
|
304
|
+
WHERE store_name = ?`
|
|
305
|
+
).get(this.storeName);
|
|
306
|
+
return row?.max ?? 0;
|
|
307
|
+
}
|
|
308
|
+
// ── private ────────────────────────────────────────────────
|
|
309
|
+
ensureTrackingTable() {
|
|
310
|
+
this.db.exec(`
|
|
311
|
+
CREATE TABLE IF NOT EXISTS lattice_schema_migrations (
|
|
312
|
+
store_name TEXT NOT NULL,
|
|
313
|
+
name TEXT NOT NULL,
|
|
314
|
+
version INTEGER NOT NULL,
|
|
315
|
+
applied_at TEXT NOT NULL,
|
|
316
|
+
PRIMARY KEY (store_name, name)
|
|
317
|
+
)
|
|
318
|
+
`);
|
|
319
|
+
}
|
|
320
|
+
getAppliedNames() {
|
|
321
|
+
const rows = this.db.prepare(
|
|
322
|
+
`SELECT name FROM lattice_schema_migrations WHERE store_name = ? ORDER BY version`
|
|
323
|
+
).all(this.storeName);
|
|
324
|
+
return new Set(rows.map((r) => r.name));
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
235
328
|
// src/createLocalStoreConfig.ts
|
|
236
329
|
var import_langgraph_checkpoint_sqlite = require("@langchain/langgraph-checkpoint-sqlite");
|
|
237
330
|
|
|
238
331
|
// src/stores/LocalThreadStore.ts
|
|
332
|
+
var STORE_NAME = "lt_threads";
|
|
239
333
|
var DDL = `
|
|
240
334
|
CREATE TABLE IF NOT EXISTS lt_threads (
|
|
241
335
|
id TEXT NOT NULL,
|
|
@@ -251,7 +345,15 @@ CREATE INDEX IF NOT EXISTS idx_lt_threads_assistant ON lt_threads(tenant_id, ass
|
|
|
251
345
|
var LocalThreadStore = class {
|
|
252
346
|
constructor(db) {
|
|
253
347
|
this.db = db;
|
|
254
|
-
|
|
348
|
+
const mm = new MigrationManager(db, STORE_NAME);
|
|
349
|
+
mm.register({
|
|
350
|
+
version: 1,
|
|
351
|
+
name: "create_lt_threads",
|
|
352
|
+
up: (d) => {
|
|
353
|
+
d.exec(DDL);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
mm.migrate();
|
|
255
357
|
}
|
|
256
358
|
async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
|
|
257
359
|
const rows = this.db.prepare(
|
|
@@ -3613,6 +3715,7 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
3613
3715
|
LocalUserTenantLinkStore,
|
|
3614
3716
|
LocalWorkflowTrackingStore,
|
|
3615
3717
|
LocalWorkspaceStore,
|
|
3718
|
+
MigrationManager,
|
|
3616
3719
|
RunResult,
|
|
3617
3720
|
StatementWrapper,
|
|
3618
3721
|
closeDatabase,
|