@axiom-lattice/pg-stores 1.0.86 → 1.0.87
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 +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +147 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/createPgStoreConfig.ts +4 -0
- package/src/index.ts +4 -0
- package/src/migrations/connection_config_migrations.ts +50 -0
- package/src/stores/PostgreSQLConnectionStore.ts +128 -0
package/dist/index.mjs
CHANGED
|
@@ -1247,6 +1247,101 @@ var PostgreSQLDatabaseConfigStore = class {
|
|
|
1247
1247
|
}
|
|
1248
1248
|
};
|
|
1249
1249
|
|
|
1250
|
+
// src/stores/PostgreSQLConnectionStore.ts
|
|
1251
|
+
import { v4 as uuid } from "uuid";
|
|
1252
|
+
var TABLE = "lattice_connection_configs";
|
|
1253
|
+
var PostgreSQLConnectionStore = class {
|
|
1254
|
+
constructor(db) {
|
|
1255
|
+
this.db = db;
|
|
1256
|
+
}
|
|
1257
|
+
async listByType(tenantId, type) {
|
|
1258
|
+
const result = await this.db.query(
|
|
1259
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 ORDER BY created_at`,
|
|
1260
|
+
[tenantId, type]
|
|
1261
|
+
);
|
|
1262
|
+
return result.rows.map((row) => this.mapRow(row));
|
|
1263
|
+
}
|
|
1264
|
+
async getByKey(tenantId, type, key) {
|
|
1265
|
+
const result = await this.db.query(
|
|
1266
|
+
`SELECT * FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1267
|
+
[tenantId, type, key]
|
|
1268
|
+
);
|
|
1269
|
+
if (result.rows.length === 0) return null;
|
|
1270
|
+
return this.mapRow(result.rows[0]);
|
|
1271
|
+
}
|
|
1272
|
+
async create(entry) {
|
|
1273
|
+
const id = uuid();
|
|
1274
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1275
|
+
await this.db.query(
|
|
1276
|
+
`INSERT INTO ${TABLE} (id, tenant_id, type, key, name, description, config, status, created_at, updated_at)
|
|
1277
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, 'active', $8::timestamp, $9::timestamp)`,
|
|
1278
|
+
[
|
|
1279
|
+
id,
|
|
1280
|
+
entry.tenantId,
|
|
1281
|
+
entry.type,
|
|
1282
|
+
entry.key,
|
|
1283
|
+
entry.name,
|
|
1284
|
+
entry.description || null,
|
|
1285
|
+
JSON.stringify(entry.config),
|
|
1286
|
+
now,
|
|
1287
|
+
now
|
|
1288
|
+
]
|
|
1289
|
+
);
|
|
1290
|
+
return { id, ...entry, createdAt: now, updatedAt: now };
|
|
1291
|
+
}
|
|
1292
|
+
async update(tenantId, type, key, updates) {
|
|
1293
|
+
const existing = await this.getByKey(tenantId, type, key);
|
|
1294
|
+
if (!existing) return null;
|
|
1295
|
+
const setClauses = [];
|
|
1296
|
+
const values = [];
|
|
1297
|
+
let paramIndex = 1;
|
|
1298
|
+
if (updates.name !== void 0) {
|
|
1299
|
+
setClauses.push(`name = $${paramIndex++}`);
|
|
1300
|
+
values.push(updates.name);
|
|
1301
|
+
}
|
|
1302
|
+
if (updates.description !== void 0) {
|
|
1303
|
+
setClauses.push(`description = $${paramIndex++}`);
|
|
1304
|
+
values.push(updates.description || null);
|
|
1305
|
+
}
|
|
1306
|
+
if (updates.config !== void 0) {
|
|
1307
|
+
setClauses.push(`config = $${paramIndex++}`);
|
|
1308
|
+
values.push(JSON.stringify(updates.config));
|
|
1309
|
+
}
|
|
1310
|
+
if (setClauses.length === 0) return existing;
|
|
1311
|
+
setClauses.push(`updated_at = $${paramIndex++}::timestamp`);
|
|
1312
|
+
values.push((/* @__PURE__ */ new Date()).toISOString());
|
|
1313
|
+
values.push(tenantId, type, key);
|
|
1314
|
+
const whereTenant = paramIndex++;
|
|
1315
|
+
const whereType = paramIndex++;
|
|
1316
|
+
const whereKey = paramIndex;
|
|
1317
|
+
await this.db.query(
|
|
1318
|
+
`UPDATE ${TABLE} SET ${setClauses.join(", ")} WHERE tenant_id = $${whereTenant} AND type = $${whereType} AND key = $${whereKey}`,
|
|
1319
|
+
values
|
|
1320
|
+
);
|
|
1321
|
+
return this.getByKey(tenantId, type, key);
|
|
1322
|
+
}
|
|
1323
|
+
async delete(tenantId, type, key) {
|
|
1324
|
+
const result = await this.db.query(
|
|
1325
|
+
`DELETE FROM ${TABLE} WHERE tenant_id = $1 AND type = $2 AND key = $3`,
|
|
1326
|
+
[tenantId, type, key]
|
|
1327
|
+
);
|
|
1328
|
+
return (result.rowCount ?? 0) > 0;
|
|
1329
|
+
}
|
|
1330
|
+
mapRow(row) {
|
|
1331
|
+
return {
|
|
1332
|
+
id: row.id,
|
|
1333
|
+
tenantId: row.tenant_id,
|
|
1334
|
+
type: row.type,
|
|
1335
|
+
key: row.key,
|
|
1336
|
+
name: row.name,
|
|
1337
|
+
description: row.description || void 0,
|
|
1338
|
+
config: typeof row.config === "string" ? JSON.parse(row.config) : row.config,
|
|
1339
|
+
createdAt: row.created_at instanceof Date ? row.created_at.toISOString() : String(row.created_at),
|
|
1340
|
+
updatedAt: row.updated_at instanceof Date ? row.updated_at.toISOString() : String(row.updated_at)
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1250
1345
|
// src/stores/PostgreSQLMetricsServerConfigStore.ts
|
|
1251
1346
|
import { Pool as Pool4 } from "pg";
|
|
1252
1347
|
|
|
@@ -7309,6 +7404,46 @@ var createChannelIdentityMappingTables = {
|
|
|
7309
7404
|
}
|
|
7310
7405
|
};
|
|
7311
7406
|
|
|
7407
|
+
// src/migrations/connection_config_migrations.ts
|
|
7408
|
+
var createConnectionConfigsTable = {
|
|
7409
|
+
version: 160,
|
|
7410
|
+
name: "create_connection_configs_table",
|
|
7411
|
+
up: async (client) => {
|
|
7412
|
+
await client.query(`
|
|
7413
|
+
CREATE TABLE IF NOT EXISTS lattice_connection_configs (
|
|
7414
|
+
id VARCHAR(255) NOT NULL,
|
|
7415
|
+
tenant_id VARCHAR(255) NOT NULL,
|
|
7416
|
+
type VARCHAR(255) NOT NULL,
|
|
7417
|
+
key VARCHAR(255) NOT NULL,
|
|
7418
|
+
name VARCHAR(255) NOT NULL,
|
|
7419
|
+
description TEXT,
|
|
7420
|
+
config JSONB NOT NULL DEFAULT '{}',
|
|
7421
|
+
status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
7422
|
+
last_test_result JSONB,
|
|
7423
|
+
metadata JSONB NOT NULL DEFAULT '{}',
|
|
7424
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7425
|
+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7426
|
+
|
|
7427
|
+
PRIMARY KEY (tenant_id, id),
|
|
7428
|
+
CONSTRAINT uk_lattice_connection_configs_tenant_type_key UNIQUE (tenant_id, type, key)
|
|
7429
|
+
)
|
|
7430
|
+
`);
|
|
7431
|
+
await client.query(`
|
|
7432
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_id
|
|
7433
|
+
ON lattice_connection_configs(tenant_id)
|
|
7434
|
+
`);
|
|
7435
|
+
await client.query(`
|
|
7436
|
+
CREATE INDEX IF NOT EXISTS idx_connection_configs_tenant_type
|
|
7437
|
+
ON lattice_connection_configs(tenant_id, type)
|
|
7438
|
+
`);
|
|
7439
|
+
},
|
|
7440
|
+
down: async (client) => {
|
|
7441
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_type");
|
|
7442
|
+
await client.query("DROP INDEX IF EXISTS idx_connection_configs_tenant_id");
|
|
7443
|
+
await client.query("DROP TABLE IF EXISTS lattice_connection_configs");
|
|
7444
|
+
}
|
|
7445
|
+
};
|
|
7446
|
+
|
|
7312
7447
|
// src/migrations/collection_migrations.ts
|
|
7313
7448
|
var createCollectionsTable = {
|
|
7314
7449
|
version: 137,
|
|
@@ -7390,6 +7525,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7390
7525
|
mm.register(createSharedResourcesTable);
|
|
7391
7526
|
mm.register(addFileContentType);
|
|
7392
7527
|
mm.register(createCollectionsTable);
|
|
7528
|
+
mm.register(createConnectionConfigsTable);
|
|
7393
7529
|
await mm.migrate();
|
|
7394
7530
|
const checkpoint = PostgresSaver.fromConnString(connectionString);
|
|
7395
7531
|
checkpoint.setup().catch((err) => {
|
|
@@ -7407,6 +7543,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
7407
7543
|
channelInstallation: new PostgreSQLChannelInstallationStore(opts),
|
|
7408
7544
|
thread: new PostgreSQLThreadStore(opts),
|
|
7409
7545
|
database: new PostgreSQLDatabaseConfigStore(opts),
|
|
7546
|
+
connection: new PostgreSQLConnectionStore(pool),
|
|
7410
7547
|
metrics: new PostgreSQLMetricsServerConfigStore(opts),
|
|
7411
7548
|
mcp: new PostgreSQLMcpServerConfigStore(opts),
|
|
7412
7549
|
assistant: new PostgreSQLAssistantStore(opts),
|
|
@@ -7981,6 +8118,7 @@ export {
|
|
|
7981
8118
|
PostgreSQLAssistantStore,
|
|
7982
8119
|
PostgreSQLChannelInstallationStore,
|
|
7983
8120
|
PostgreSQLCollectionStore,
|
|
8121
|
+
PostgreSQLConnectionStore,
|
|
7984
8122
|
PostgreSQLDatabaseConfigStore,
|
|
7985
8123
|
PostgreSQLEvalStore,
|
|
7986
8124
|
PostgreSQLMcpServerConfigStore,
|