botinabox 2.9.9 → 2.10.1
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/dist/core/data/data-store.d.ts +3 -0
- package/dist/index.js +34 -2
- package/package.json +2 -2
|
@@ -16,6 +16,8 @@ export declare class DataStore {
|
|
|
16
16
|
private readonly outputDir;
|
|
17
17
|
private _initialized;
|
|
18
18
|
private readonly deferredStatements;
|
|
19
|
+
private readonly definedTables;
|
|
20
|
+
private readonly columnCache;
|
|
19
21
|
constructor(opts: {
|
|
20
22
|
dbPath: string;
|
|
21
23
|
outputDir?: string;
|
|
@@ -40,6 +42,7 @@ export declare class DataStore {
|
|
|
40
42
|
sql: string;
|
|
41
43
|
}>;
|
|
42
44
|
}): Promise<void>;
|
|
45
|
+
private _refreshColumnCache;
|
|
43
46
|
private assertInitialized;
|
|
44
47
|
insert(table: string, row: Row): Promise<Row>;
|
|
45
48
|
upsert(table: string, row: Row): Promise<Row>;
|
package/dist/index.js
CHANGED
|
@@ -2469,6 +2469,8 @@ var DataStore = class {
|
|
|
2469
2469
|
outputDir;
|
|
2470
2470
|
_initialized = false;
|
|
2471
2471
|
deferredStatements = [];
|
|
2472
|
+
definedTables = [];
|
|
2473
|
+
columnCache = /* @__PURE__ */ new Map();
|
|
2472
2474
|
constructor(opts) {
|
|
2473
2475
|
this.lattice = new Lattice(opts.dbPath, {
|
|
2474
2476
|
wal: opts.wal ?? true
|
|
@@ -2508,6 +2510,7 @@ var DataStore = class {
|
|
|
2508
2510
|
render: def.render,
|
|
2509
2511
|
outputFile: def.outputFile
|
|
2510
2512
|
});
|
|
2513
|
+
this.definedTables.push(name);
|
|
2511
2514
|
}
|
|
2512
2515
|
/**
|
|
2513
2516
|
* Register an entity context definition for per-entity file rendering.
|
|
@@ -2557,11 +2560,34 @@ ${lines.join("\n")}
|
|
|
2557
2560
|
}
|
|
2558
2561
|
async init(opts) {
|
|
2559
2562
|
await this.lattice.init({ migrations: opts?.migrations });
|
|
2563
|
+
const adapter = this.lattice.adapter;
|
|
2564
|
+
if (!adapter.runAsync || !adapter.introspectColumnsAsync) {
|
|
2565
|
+
throw new DataStoreError(
|
|
2566
|
+
"StorageAdapter must implement runAsync and introspectColumnsAsync (latticesql 1.10.0+)"
|
|
2567
|
+
);
|
|
2568
|
+
}
|
|
2560
2569
|
for (const stmt of this.deferredStatements) {
|
|
2561
|
-
|
|
2570
|
+
await adapter.runAsync(stmt);
|
|
2562
2571
|
}
|
|
2572
|
+
await this._refreshColumnCache();
|
|
2563
2573
|
this._initialized = true;
|
|
2564
2574
|
}
|
|
2575
|
+
// Pre-populate column cache so synchronous tableInfo() works on Postgres,
|
|
2576
|
+
// where introspectColumns sync throws as of latticesql 1.10.0. Refreshed
|
|
2577
|
+
// from init() and migrate() — both are the only entry points that can
|
|
2578
|
+
// alter table schemas.
|
|
2579
|
+
async _refreshColumnCache() {
|
|
2580
|
+
const adapter = this.lattice.adapter;
|
|
2581
|
+
if (!adapter.introspectColumnsAsync) {
|
|
2582
|
+
throw new DataStoreError(
|
|
2583
|
+
"StorageAdapter must implement introspectColumnsAsync (latticesql 1.10.0+)"
|
|
2584
|
+
);
|
|
2585
|
+
}
|
|
2586
|
+
for (const table of this.definedTables) {
|
|
2587
|
+
const cols = await adapter.introspectColumnsAsync(table);
|
|
2588
|
+
this.columnCache.set(table, cols);
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2565
2591
|
assertInitialized() {
|
|
2566
2592
|
if (!this._initialized) {
|
|
2567
2593
|
throw new DataStoreError("DataStore not initialized \u2014 call init() first");
|
|
@@ -2616,6 +2642,8 @@ ${lines.join("\n")}
|
|
|
2616
2642
|
async migrate(migrations) {
|
|
2617
2643
|
this.assertInitialized();
|
|
2618
2644
|
await this.lattice.migrate(migrations);
|
|
2645
|
+
this.columnCache.clear();
|
|
2646
|
+
await this._refreshColumnCache();
|
|
2619
2647
|
}
|
|
2620
2648
|
// --- Seed -----------------------------------------------------------
|
|
2621
2649
|
async seed(items) {
|
|
@@ -2653,7 +2681,11 @@ ${lines.join("\n")}
|
|
|
2653
2681
|
// --- Schema introspection ------------------------------------------
|
|
2654
2682
|
tableInfo(table) {
|
|
2655
2683
|
this.assertInitialized();
|
|
2656
|
-
|
|
2684
|
+
let names = this.columnCache.get(table);
|
|
2685
|
+
if (!names) {
|
|
2686
|
+
names = this.lattice.adapter.introspectColumns(table);
|
|
2687
|
+
this.columnCache.set(table, names);
|
|
2688
|
+
}
|
|
2657
2689
|
return names.map((name, cid) => ({
|
|
2658
2690
|
cid,
|
|
2659
2691
|
name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "botinabox",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"description": "Bot in a Box — framework for building multi-agent bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@types/uuid": "^10.0.0",
|
|
61
61
|
"ajv": "^8.17.1",
|
|
62
62
|
"cron-parser": "^4.9.0",
|
|
63
|
-
"latticesql": "^1.
|
|
63
|
+
"latticesql": "^1.10.0",
|
|
64
64
|
"uuid": "^13.0.0",
|
|
65
65
|
"yaml": "^2.7.0"
|
|
66
66
|
},
|