@coffre/db 0.14.3 → 0.14.4

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.
@@ -120,6 +120,13 @@
120
120
  "when": 1792835446455,
121
121
  "tag": "0016_capped_alerts",
122
122
  "breakpoints": true
123
+ },
124
+ {
125
+ "idx": 17,
126
+ "version": "6",
127
+ "when": 1793017781451,
128
+ "tag": "0017_vault_releases",
129
+ "breakpoints": true
123
130
  }
124
131
  ]
125
132
  }
@@ -1,5 +1,5 @@
1
- import { g as schema_d_exports } from "./schema-DcVkJhCf.js";
2
- import { t as Database } from "./database-Ds1Y79h6.js";
1
+ import { g as schema_d_exports } from "./schema-z8GcN_Xu.js";
2
+ import { t as Database } from "./database-CFhTnnzM.js";
3
3
  import { t as schema_sqlite_d_exports } from "./schema-sqlite.js";
4
4
  import { LibSQLDatabase } from "drizzle-orm/libsql";
5
5
  //#region src/portable.d.ts
@@ -1,5 +1,5 @@
1
1
  declare namespace schema_sqlite_d_exports {
2
- export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers };
2
+ export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers, vaultReleases };
3
3
  }
4
4
  export declare const projects: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
5
5
  name: "projects";
@@ -1292,6 +1292,80 @@ export declare const vaultGrants: import("drizzle-orm/sqlite-core").SQLiteTableW
1292
1292
  };
1293
1293
  dialect: "sqlite";
1294
1294
  }>;
1295
+ /**
1296
+ * Each key the vault released to a principal, and when last: what its bulk
1297
+ * limit counts (R28), the distinct keys released within a window, without
1298
+ * reading the log. The database keeps it from the log itself, in the
1299
+ * transaction of each vault `secret.read` allowed: a trigger on
1300
+ * `audit_log` upserts a row for each key the entry names, as the count
1301
+ * read them from the entries before (an entry that names none, which only
1302
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
1303
+ * writes it: the vault and the backup read it. A row a window old counts
1304
+ * for nothing, so nothing prunes them: there are at most as many as
1305
+ * principals times keys, and a count reads one principal's.
1306
+ */
1307
+ export declare const vaultReleases: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
1308
+ name: "vault_releases";
1309
+ schema: undefined;
1310
+ columns: {
1311
+ principal: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1312
+ name: "principal";
1313
+ tableName: "vault_releases";
1314
+ dataType: "string";
1315
+ columnType: "SQLiteText";
1316
+ data: string;
1317
+ driverParam: string;
1318
+ notNull: true;
1319
+ hasDefault: false;
1320
+ isPrimaryKey: false;
1321
+ isAutoincrement: false;
1322
+ hasRuntimeDefault: false;
1323
+ enumValues: [string, ...string[]];
1324
+ baseColumn: never;
1325
+ identity: undefined;
1326
+ generated: undefined;
1327
+ }, {}, {
1328
+ length: undefined;
1329
+ }>;
1330
+ key: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1331
+ name: "key";
1332
+ tableName: "vault_releases";
1333
+ dataType: "string";
1334
+ columnType: "SQLiteText";
1335
+ data: string;
1336
+ driverParam: string;
1337
+ notNull: true;
1338
+ hasDefault: false;
1339
+ isPrimaryKey: false;
1340
+ isAutoincrement: false;
1341
+ hasRuntimeDefault: false;
1342
+ enumValues: [string, ...string[]];
1343
+ baseColumn: never;
1344
+ identity: undefined;
1345
+ generated: undefined;
1346
+ }, {}, {
1347
+ length: undefined;
1348
+ }>;
1349
+ releasedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1350
+ name: "released_at";
1351
+ tableName: "vault_releases";
1352
+ dataType: "number";
1353
+ columnType: "SQLiteInteger";
1354
+ data: number;
1355
+ driverParam: number;
1356
+ notNull: true;
1357
+ hasDefault: false;
1358
+ isPrimaryKey: false;
1359
+ isAutoincrement: false;
1360
+ hasRuntimeDefault: false;
1361
+ enumValues: undefined;
1362
+ baseColumn: never;
1363
+ identity: undefined;
1364
+ generated: undefined;
1365
+ }, {}, {}>;
1366
+ };
1367
+ dialect: "sqlite";
1368
+ }>;
1295
1369
  export declare const auditLog: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
1296
1370
  name: "audit_log";
1297
1371
  schema: undefined;
@@ -214,6 +214,26 @@ const vaultGrants = sqliteTable("vault_grants", {
214
214
  foreignColumns: [environments.id]
215
215
  }).onDelete("restrict")
216
216
  ]);
217
+ /**
218
+ * Each key the vault released to a principal, and when last: what its bulk
219
+ * limit counts (R28), the distinct keys released within a window, without
220
+ * reading the log. The database keeps it from the log itself, in the
221
+ * transaction of each vault `secret.read` allowed: a trigger on
222
+ * `audit_log` upserts a row for each key the entry names, as the count
223
+ * read them from the entries before (an entry that names none, which only
224
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
225
+ * writes it: the vault and the backup read it. A row a window old counts
226
+ * for nothing, so nothing prunes them: there are at most as many as
227
+ * principals times keys, and a count reads one principal's.
228
+ */
229
+ const vaultReleases = sqliteTable("vault_releases", {
230
+ principal: text().notNull(),
231
+ key: text().notNull(),
232
+ releasedAt: integer("released_at", { mode: "number" }).notNull()
233
+ }, (table) => [primaryKey({
234
+ name: "vault_releases_pkey",
235
+ columns: [table.principal, table.key]
236
+ })]);
217
237
  const auditLog = sqliteTable("audit_log", {
218
238
  seq: int64("seq").primaryKey(),
219
239
  author: text().notNull(),
@@ -616,4 +636,4 @@ const { environmentsRelations, secretsRelations } = relationsOf(asPostgres({
616
636
  secretVersions
617
637
  }));
618
638
  //#endregion
619
- export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers };
639
+ export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers, vaultReleases };
@@ -1,4 +1,4 @@
1
- import { i as Queryable } from "./database-Ds1Y79h6.js";
1
+ import { i as Queryable } from "./database-CFhTnnzM.js";
2
2
  import { Engine } from "./dialect.js";
3
3
  //#region src/schema-version.d.ts
4
4
  /**
@@ -148,6 +148,13 @@ const KNOWN_MIGRATIONS = {
148
148
  "when": 1792937576477,
149
149
  "tag": "0019_backup_role",
150
150
  "breakpoints": true
151
+ },
152
+ {
153
+ "idx": 20,
154
+ "version": "7",
155
+ "when": 1793017780802,
156
+ "tag": "0020_vault_releases",
157
+ "breakpoints": true
151
158
  }
152
159
  ].map((entry) => entry.tag),
153
160
  sqlite: [
@@ -269,6 +276,13 @@ const KNOWN_MIGRATIONS = {
269
276
  "when": 1792835446455,
270
277
  "tag": "0016_capped_alerts",
271
278
  "breakpoints": true
279
+ },
280
+ {
281
+ "idx": 17,
282
+ "version": "6",
283
+ "when": 1793017781451,
284
+ "tag": "0017_vault_releases",
285
+ "breakpoints": true
272
286
  }
273
287
  ].map((entry) => entry.tag)
274
288
  };
@@ -1,5 +1,5 @@
1
1
  declare namespace schema_d_exports {
2
- export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers };
2
+ export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers, vaultReleases };
3
3
  }
4
4
  declare const projects: import("drizzle-orm/pg-core").PgTableWithColumns<{
5
5
  name: "projects";
@@ -1238,6 +1238,76 @@ declare const vaultGrants: import("drizzle-orm/pg-core").PgTableWithColumns<{
1238
1238
  };
1239
1239
  dialect: "pg";
1240
1240
  }>;
1241
+ /**
1242
+ * Each key the vault released to a principal, and when last: what its bulk
1243
+ * limit counts (R28), the distinct keys released within a window, without
1244
+ * reading the log. The database keeps it from the log itself, in the
1245
+ * transaction of each vault `secret.read` allowed: a trigger on
1246
+ * `audit_log` upserts a row for each key the entry names, as the count
1247
+ * read them from the entries before (an entry that names none, which only
1248
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
1249
+ * writes it: the vault and the backup read it. A row a window old counts
1250
+ * for nothing, so nothing prunes them: there are at most as many as
1251
+ * principals times keys, and a count reads one principal's.
1252
+ */
1253
+ declare const vaultReleases: import("drizzle-orm/pg-core").PgTableWithColumns<{
1254
+ name: "vault_releases";
1255
+ schema: undefined;
1256
+ columns: {
1257
+ principal: import("drizzle-orm/pg-core").PgColumn<{
1258
+ name: "principal";
1259
+ tableName: "vault_releases";
1260
+ dataType: "string";
1261
+ columnType: "PgText";
1262
+ data: string;
1263
+ driverParam: string;
1264
+ notNull: true;
1265
+ hasDefault: false;
1266
+ isPrimaryKey: false;
1267
+ isAutoincrement: false;
1268
+ hasRuntimeDefault: false;
1269
+ enumValues: [string, ...string[]];
1270
+ baseColumn: never;
1271
+ identity: undefined;
1272
+ generated: undefined;
1273
+ }, {}, {}>;
1274
+ key: import("drizzle-orm/pg-core").PgColumn<{
1275
+ name: "key";
1276
+ tableName: "vault_releases";
1277
+ dataType: "string";
1278
+ columnType: "PgText";
1279
+ data: string;
1280
+ driverParam: string;
1281
+ notNull: true;
1282
+ hasDefault: false;
1283
+ isPrimaryKey: false;
1284
+ isAutoincrement: false;
1285
+ hasRuntimeDefault: false;
1286
+ enumValues: [string, ...string[]];
1287
+ baseColumn: never;
1288
+ identity: undefined;
1289
+ generated: undefined;
1290
+ }, {}, {}>;
1291
+ releasedAt: import("drizzle-orm/pg-core").PgColumn<{
1292
+ name: "released_at";
1293
+ tableName: "vault_releases";
1294
+ dataType: "number";
1295
+ columnType: "PgBigInt53";
1296
+ data: number;
1297
+ driverParam: string | number;
1298
+ notNull: true;
1299
+ hasDefault: false;
1300
+ isPrimaryKey: false;
1301
+ isAutoincrement: false;
1302
+ hasRuntimeDefault: false;
1303
+ enumValues: undefined;
1304
+ baseColumn: never;
1305
+ identity: undefined;
1306
+ generated: undefined;
1307
+ }, {}, {}>;
1308
+ };
1309
+ dialect: "pg";
1310
+ }>;
1241
1311
  declare const auditLog: import("drizzle-orm/pg-core").PgTableWithColumns<{
1242
1312
  name: "audit_log";
1243
1313
  schema: undefined;
@@ -4125,4 +4195,4 @@ declare const environmentsRelations: import("drizzle-orm").Relations<"environmen
4125
4195
  environment: import("drizzle-orm").One<"environments", true>;
4126
4196
  }>;
4127
4197
  //#endregion
4128
- export { vaultMembers as C, vaultGrants as S, secretReferences as _, credentials as a, secretsRelations as b, enrollments as c, identities as d, mcpApprovals as f, schema_d_exports as g, projects as h, consumedTokens as i, environments as l, oauthClients as m, auditLog as n, deviceAuthorizations as o, mcpConnections as p, cappedAlerts as r, dismissedKeys as s, auditChainHead as t, environmentsRelations as u, secretVersions as v, serviceBindings as x, secrets as y };
4198
+ export { vaultMembers as C, vaultGrants as S, secretReferences as _, credentials as a, secretsRelations as b, enrollments as c, identities as d, mcpApprovals as f, schema_d_exports as g, projects as h, consumedTokens as i, environments as l, oauthClients as m, auditLog as n, deviceAuthorizations as o, mcpConnections as p, cappedAlerts as r, dismissedKeys as s, auditChainHead as t, environmentsRelations as u, secretVersions as v, vaultReleases as w, serviceBindings as x, secrets as y };
package/dist/schema.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as vaultMembers, S as vaultGrants, _ as secretReferences, a as credentials, b as secretsRelations, c as enrollments, d as identities, f as mcpApprovals, h as projects, i as consumedTokens, l as environments, m as oauthClients, n as auditLog, o as deviceAuthorizations, p as mcpConnections, r as cappedAlerts, s as dismissedKeys, t as auditChainHead, u as environmentsRelations, v as secretVersions, x as serviceBindings, y as secrets } from "./schema-DcVkJhCf.js";
2
- export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers };
1
+ import { C as vaultMembers, S as vaultGrants, _ as secretReferences, a as credentials, b as secretsRelations, c as enrollments, d as identities, f as mcpApprovals, h as projects, i as consumedTokens, l as environments, m as oauthClients, n as auditLog, o as deviceAuthorizations, p as mcpConnections, r as cappedAlerts, s as dismissedKeys, t as auditChainHead, u as environmentsRelations, v as secretVersions, w as vaultReleases, x as serviceBindings, y as secrets } from "./schema-z8GcN_Xu.js";
2
+ export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, vaultGrants, vaultMembers, vaultReleases };
package/dist/schema.js CHANGED
@@ -25,7 +25,8 @@ var schema_exports = /* @__PURE__ */ __exportAll({
25
25
  secretsRelations: () => secretsRelations,
26
26
  serviceBindings: () => serviceBindings,
27
27
  vaultGrants: () => vaultGrants,
28
- vaultMembers: () => vaultMembers
28
+ vaultMembers: () => vaultMembers,
29
+ vaultReleases: () => vaultReleases
29
30
  });
30
31
  const bytea = customType({ dataType: () => "bytea" });
31
32
  const createdAt = () => timestamp("created_at", { withTimezone: true }).notNull().defaultNow();
@@ -240,6 +241,26 @@ const vaultGrants = pgTable("vault_grants", {
240
241
  foreignColumns: [environments.id]
241
242
  }).onDelete("restrict")
242
243
  ]);
244
+ /**
245
+ * Each key the vault released to a principal, and when last: what its bulk
246
+ * limit counts (R28), the distinct keys released within a window, without
247
+ * reading the log. The database keeps it from the log itself, in the
248
+ * transaction of each vault `secret.read` allowed: a trigger on
249
+ * `audit_log` upserts a row for each key the entry names, as the count
250
+ * read them from the entries before (an entry that names none, which only
251
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
252
+ * writes it: the vault and the backup read it. A row a window old counts
253
+ * for nothing, so nothing prunes them: there are at most as many as
254
+ * principals times keys, and a count reads one principal's.
255
+ */
256
+ const vaultReleases = pgTable("vault_releases", {
257
+ principal: text().notNull(),
258
+ key: text().notNull(),
259
+ releasedAt: bigint("released_at", { mode: "number" }).notNull()
260
+ }, (table) => [primaryKey({
261
+ name: "vault_releases_pkey",
262
+ columns: [table.principal, table.key]
263
+ })]);
243
264
  const auditLog = pgTable("audit_log", {
244
265
  seq: bigint({ mode: "bigint" }).primaryKey(),
245
266
  author: text().notNull(),
@@ -698,4 +719,4 @@ const { environmentsRelations, secretsRelations } = relationsOf({
698
719
  secretVersions
699
720
  });
700
721
  //#endregion
701
- export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, schema_exports as t, vaultGrants, vaultMembers };
722
+ export { auditChainHead, auditLog, cappedAlerts, consumedTokens, credentials, deviceAuthorizations, dismissedKeys, enrollments, environments, environmentsRelations, identities, mcpApprovals, mcpConnections, oauthClients, projects, secretReferences, secretVersions, secrets, secretsRelations, serviceBindings, schema_exports as t, vaultGrants, vaultMembers, vaultReleases };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/db",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "description": "coffre's database: the schema, its migrations and the connections, on Postgres or SQLite.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -79,7 +79,7 @@
79
79
  "drizzle-orm": "0.45.2",
80
80
  "pg": "8.16.3",
81
81
  "pg-connection-string": "2.14.0",
82
- "@coffre/core": "0.14.3"
82
+ "@coffre/core": "0.14.4"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/node": "26.1.1",
@@ -0,0 +1,36 @@
1
+ -- Releases (W199): each key the vault released to a principal, and when last, so that its bulk limit counts the keys released within a window from a row per key, not from every read the principal ever made. The database keeps it, from each vault `secret.read` allowed, in the append's own transaction; the release before neither reads it nor knows it is kept, and its appends keep it too.
2
+ CREATE TABLE "vault_releases" (
3
+ "principal" text NOT NULL,
4
+ "key" text NOT NULL,
5
+ "released_at" bigint NOT NULL,
6
+ CONSTRAINT "vault_releases_pkey" PRIMARY KEY("principal","key")
7
+ );
8
+ --> statement-breakpoint
9
+ -- Room in each page for the next version of its rows: a read moves its keys' times on in place (a HOT update), so the
10
+ -- table and its key stay a row a key, however often each is read: the page prunes the versions before as it is read.
11
+ ALTER TABLE vault_releases SET (fillfactor = 50);--> statement-breakpoint
12
+ -- Each key the entry names, as the count read them before: the secret, or each item of a read's list at one place, or, for an entry that names none, which only a forged one is, the entry itself. As the owner, so that no login may write the table: the vault's appends reach it only through the log.
13
+ CREATE FUNCTION vault_releases_keep() RETURNS trigger
14
+ LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
15
+ BEGIN
16
+ INSERT INTO public.vault_releases AS kept (principal, key, released_at)
17
+ SELECT DISTINCT NEW.actor, coalesce(NEW.secret_id::text, CASE jsonb_typeof(one -> 'secretId') WHEN 'string' THEN one ->> 'secretId' END, 'entry:' || NEW.seq), NEW.occurred_at
18
+ FROM (SELECT) AS entry
19
+ LEFT JOIN LATERAL jsonb_path_query(CASE WHEN NEW.secret_id IS NULL THEN NEW.metadata::jsonb END, 'strict $.secrets ? (@.type() == "array")[*]', '{}', true) AS one ON true
20
+ ON CONFLICT (principal, key) DO UPDATE SET released_at = greatest(kept.released_at, excluded.released_at);
21
+ RETURN NULL;
22
+ END
23
+ $$;--> statement-breakpoint
24
+ -- A trigger runs its function whoever may execute it: no login may call it otherwise.
25
+ REVOKE ALL ON FUNCTION vault_releases_keep() FROM PUBLIC;--> statement-breakpoint
26
+ CREATE TRIGGER audit_log_releases AFTER INSERT ON audit_log FOR EACH ROW
27
+ WHEN (NEW.author = 'vault' AND NEW.action = 'secret.read' AND NEW.decision = 'allow')
28
+ EXECUTE FUNCTION vault_releases_keep();--> statement-breakpoint
29
+ -- Then the releases already in the log, in the same transaction: an append waits from the trigger to the commit, and none is missed.
30
+ INSERT INTO vault_releases (principal, key, released_at)
31
+ SELECT e.actor, coalesce(e.secret_id::text, CASE jsonb_typeof(one -> 'secretId') WHEN 'string' THEN one ->> 'secretId' END, 'entry:' || e.seq), max(e.occurred_at)
32
+ FROM audit_log e
33
+ LEFT JOIN LATERAL jsonb_path_query(CASE WHEN e.secret_id IS NULL THEN e.metadata::jsonb END, 'strict $.secrets ? (@.type() == "array")[*]', '{}', true) AS one ON true
34
+ WHERE e.author = 'vault' AND e.action = 'secret.read' AND e.decision = 'allow'
35
+ GROUP BY 1, 2;--> statement-breakpoint
36
+ GRANT SELECT ON vault_releases TO coffre_vault, coffre_backup;