@coffre/db 0.14.2 → 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.
Files changed (40) hide show
  1. package/dist/connect.d.ts +1 -1
  2. package/dist/{database-Ds1Y79h6.d.ts → database-CFhTnnzM.d.ts} +1 -1
  3. package/dist/dialect.d.ts +4 -3
  4. package/dist/dialect.js +1 -0
  5. package/dist/grants.d.ts +1 -1
  6. package/dist/hyperdrive.d.ts +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/log.d.ts +1 -1
  9. package/dist/migrate.d.ts +21 -5
  10. package/dist/migrate.js +49 -9
  11. package/dist/migrations/postgres/0019_backup_role.sql +63 -0
  12. package/dist/migrations/postgres/0020_vault_releases.sql +36 -0
  13. package/dist/migrations/postgres/meta/0019_snapshot.json +3295 -0
  14. package/dist/migrations/postgres/meta/0020_snapshot.json +3334 -0
  15. package/dist/migrations/postgres/meta/_journal.json +14 -0
  16. package/dist/migrations/sqlite/0017_vault_releases.sql +26 -0
  17. package/dist/migrations/sqlite/meta/0017_snapshot.json +3037 -0
  18. package/dist/migrations/sqlite/meta/_journal.json +7 -0
  19. package/dist/portable.d.ts +2 -2
  20. package/dist/schema-sqlite.d.ts +75 -1
  21. package/dist/schema-sqlite.js +21 -1
  22. package/dist/schema-version.d.ts +1 -1
  23. package/dist/schema-version.js +21 -0
  24. package/dist/{schema-DcVkJhCf.d.ts → schema-z8GcN_Xu.d.ts} +72 -2
  25. package/dist/schema.d.ts +2 -2
  26. package/dist/schema.js +23 -2
  27. package/package.json +2 -2
  28. package/src/dialect.ts +3 -2
  29. package/src/migrate-main.ts +6 -3
  30. package/src/migrate.ts +49 -10
  31. package/src/migrations/postgres/0019_backup_role.sql +63 -0
  32. package/src/migrations/postgres/0020_vault_releases.sql +36 -0
  33. package/src/migrations/postgres/meta/0019_snapshot.json +3295 -0
  34. package/src/migrations/postgres/meta/0020_snapshot.json +3334 -0
  35. package/src/migrations/postgres/meta/_journal.json +14 -0
  36. package/src/migrations/sqlite/0017_vault_releases.sql +26 -0
  37. package/src/migrations/sqlite/meta/0017_snapshot.json +3037 -0
  38. package/src/migrations/sqlite/meta/_journal.json +7 -0
  39. package/src/schema.sqlite.ts +22 -0
  40. package/src/schema.ts +24 -0
@@ -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
  }
@@ -303,6 +303,28 @@ export const vaultGrants = sqliteTable(
303
303
  ],
304
304
  );
305
305
 
306
+ /**
307
+ * Each key the vault released to a principal, and when last: what its bulk
308
+ * limit counts (R28), the distinct keys released within a window, without
309
+ * reading the log. The database keeps it from the log itself, in the
310
+ * transaction of each vault `secret.read` allowed: a trigger on
311
+ * `audit_log` upserts a row for each key the entry names, as the count
312
+ * read them from the entries before (an entry that names none, which only
313
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
314
+ * writes it: the vault and the backup read it. A row a window old counts
315
+ * for nothing, so nothing prunes them: there are at most as many as
316
+ * principals times keys, and a count reads one principal's.
317
+ */
318
+ export const vaultReleases = sqliteTable(
319
+ 'vault_releases',
320
+ {
321
+ principal: text().notNull(),
322
+ key: text().notNull(),
323
+ releasedAt: integer('released_at', { mode: 'number' }).notNull(),
324
+ },
325
+ (table) => [primaryKey({ name: 'vault_releases_pkey', columns: [table.principal, table.key] })],
326
+ );
327
+
306
328
  export const auditLog = sqliteTable(
307
329
  'audit_log',
308
330
  {
package/src/schema.ts CHANGED
@@ -321,6 +321,30 @@ export const vaultGrants = pgTable(
321
321
  ],
322
322
  );
323
323
 
324
+ /**
325
+ * Each key the vault released to a principal, and when last: what its bulk
326
+ * limit counts (R28), the distinct keys released within a window, without
327
+ * reading the log. The database keeps it from the log itself, in the
328
+ * transaction of each vault `secret.read` allowed: a trigger on
329
+ * `audit_log` upserts a row for each key the entry names, as the count
330
+ * read them from the entries before (an entry that names none, which only
331
+ * a forged one is, counts as a key of its own, `entry:<seq>`). No login
332
+ * writes it: the vault and the backup read it. A row a window old counts
333
+ * for nothing, so nothing prunes them: there are at most as many as
334
+ * principals times keys, and a count reads one principal's.
335
+ */
336
+ export const vaultReleases = pgTable(
337
+ 'vault_releases',
338
+ {
339
+ principal: text().notNull(),
340
+ key: text().notNull(),
341
+ releasedAt: bigint('released_at', { mode: 'number' }).notNull(),
342
+ },
343
+ // The key alone is indexed: a read moves its keys' times on in place (a HOT update), leaving no index entry behind,
344
+ // and the count reads the principal's keys from the key, a row each, however often they are read.
345
+ (table) => [primaryKey({ name: 'vault_releases_pkey', columns: [table.principal, table.key] })],
346
+ );
347
+
324
348
  export const auditLog = pgTable(
325
349
  'audit_log',
326
350
  {