@coffre/db 0.14.5 → 0.15.0

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 (214) hide show
  1. package/README.md +2 -1
  2. package/dist/change-records-_fKvahvs.js +55 -0
  3. package/dist/connect.d.ts +22 -10
  4. package/dist/connect.js +74 -12
  5. package/dist/database-CVteLhp1.d.ts +410 -0
  6. package/dist/{database-BadNeeN-.js → database-D55ENPX-.js} +46 -25
  7. package/dist/dialect.d.ts +4 -3
  8. package/dist/dialect.js +14 -5
  9. package/dist/grants.d.ts +4 -4
  10. package/dist/grants.js +4 -4
  11. package/dist/hyperdrive.d.ts +48 -23
  12. package/dist/hyperdrive.js +168 -91
  13. package/dist/index.d.ts +3 -3
  14. package/dist/index.js +1 -1
  15. package/dist/log-DaD7fyUq.d.ts +722 -0
  16. package/dist/log.d.ts +2 -622
  17. package/dist/log.js +178 -13
  18. package/dist/migrate.d.ts +43 -3
  19. package/dist/migrate.js +149 -29
  20. package/dist/migrations/postgres/0022_log_015.sql +672 -0
  21. package/dist/migrations/postgres/0023_change_path.sql +153 -0
  22. package/dist/migrations/postgres/0024_use_015.sql +556 -0
  23. package/dist/migrations/postgres/0025_app_change.sql +221 -0
  24. package/dist/migrations/postgres/0026_issue_lock.sql +106 -0
  25. package/dist/migrations/postgres/0027_retention.sql +118 -0
  26. package/dist/migrations/postgres/0028_use_stalls.sql +594 -0
  27. package/dist/migrations/postgres/0029_use_objects.sql +887 -0
  28. package/dist/migrations/postgres/0030_unarchive_restores.sql +259 -0
  29. package/dist/migrations/postgres/0031_app_read.sql +65 -0
  30. package/dist/migrations/postgres/0032_secrets_live_index.sql +4 -0
  31. package/dist/migrations/postgres/0033_use_generations.sql +582 -0
  32. package/dist/migrations/postgres/0034_vault_credentials.sql +153 -0
  33. package/dist/migrations/postgres/0035_first_days.sql +3 -0
  34. package/dist/migrations/postgres/0036_vault_issues.sql +91 -0
  35. package/dist/migrations/postgres/0037_vault_bindings.sql +271 -0
  36. package/dist/migrations/postgres/0040_binding_origin.sql +159 -0
  37. package/dist/migrations/postgres/0041_cutover.sql +132 -0
  38. package/dist/migrations/postgres/0042_sign_in_index.sql +7 -0
  39. package/dist/migrations/postgres/0043_issue_revoke_index.sql +4 -0
  40. package/dist/migrations/postgres/0044_use_by_name.sql +705 -0
  41. package/dist/migrations/postgres/0045_decide_first.sql +878 -0
  42. package/dist/migrations/postgres/0046_way_in_uses.sql +1149 -0
  43. package/dist/migrations/postgres/0047_cutover_finish.sql +268 -0
  44. package/dist/migrations/postgres/0048_use_batch.sql +59 -0
  45. package/dist/migrations/postgres/0049_reads.sql +171 -0
  46. package/dist/migrations/postgres/meta/0022_snapshot.json +3831 -0
  47. package/dist/migrations/postgres/meta/0023_snapshot.json +3831 -0
  48. package/dist/migrations/postgres/meta/0024_snapshot.json +3831 -0
  49. package/dist/migrations/postgres/meta/0025_snapshot.json +3831 -0
  50. package/dist/migrations/postgres/meta/0026_snapshot.json +3831 -0
  51. package/dist/migrations/postgres/meta/0027_snapshot.json +3853 -0
  52. package/dist/migrations/postgres/meta/0028_snapshot.json +3853 -0
  53. package/dist/migrations/postgres/meta/0029_snapshot.json +3859 -0
  54. package/dist/migrations/postgres/meta/0030_snapshot.json +3859 -0
  55. package/dist/migrations/postgres/meta/0031_snapshot.json +3859 -0
  56. package/dist/migrations/postgres/meta/0032_snapshot.json +3875 -0
  57. package/dist/migrations/postgres/meta/0033_snapshot.json +3875 -0
  58. package/dist/migrations/postgres/meta/0034_snapshot.json +3875 -0
  59. package/dist/migrations/postgres/meta/0035_snapshot.json +3875 -0
  60. package/dist/migrations/postgres/meta/0036_snapshot.json +3875 -0
  61. package/dist/migrations/postgres/meta/0037_snapshot.json +3875 -0
  62. package/dist/migrations/postgres/meta/0038_snapshot.json +3881 -0
  63. package/dist/migrations/postgres/meta/0039_snapshot.json +3881 -0
  64. package/dist/migrations/postgres/meta/0040_snapshot.json +3931 -0
  65. package/dist/migrations/postgres/meta/0041_snapshot.json +3981 -0
  66. package/dist/migrations/postgres/meta/0042_snapshot.json +3981 -0
  67. package/dist/migrations/postgres/meta/0043_snapshot.json +3981 -0
  68. package/dist/migrations/postgres/meta/0044_snapshot.json +3991 -0
  69. package/dist/migrations/postgres/meta/0045_snapshot.json +3997 -0
  70. package/dist/migrations/postgres/meta/0046_snapshot.json +3997 -0
  71. package/dist/migrations/postgres/meta/0047_snapshot.json +4234 -0
  72. package/dist/migrations/postgres/meta/_journal.json +182 -0
  73. package/dist/migrations/sqlite/0018_log_015.sql +84 -0
  74. package/dist/migrations/sqlite/0019_retention.sql +2 -0
  75. package/dist/migrations/sqlite/0020_ended_references.sql +1 -0
  76. package/dist/migrations/sqlite/0021_secrets_live_index.sql +1 -0
  77. package/dist/migrations/sqlite/0022_binding_origin.sql +1 -0
  78. package/dist/migrations/sqlite/0023_sign_in_index.sql +2 -0
  79. package/dist/migrations/sqlite/0024_issue_revoke_index.sql +2 -0
  80. package/dist/migrations/sqlite/0025_way_in_uses.sql +42 -0
  81. package/dist/migrations/sqlite/0026_cutover_finish.sql +11 -0
  82. package/dist/migrations/sqlite/0027_reads.sql +38 -0
  83. package/dist/migrations/sqlite/meta/0018_snapshot.json +3529 -0
  84. package/dist/migrations/sqlite/meta/0019_snapshot.json +3538 -0
  85. package/dist/migrations/sqlite/meta/0020_snapshot.json +3545 -0
  86. package/dist/migrations/sqlite/meta/0021_snapshot.json +3553 -0
  87. package/dist/migrations/sqlite/meta/0022_snapshot.json +3560 -0
  88. package/dist/migrations/sqlite/meta/0023_snapshot.json +3579 -0
  89. package/dist/migrations/sqlite/meta/0024_snapshot.json +3598 -0
  90. package/dist/migrations/sqlite/meta/0025_snapshot.json +3609 -0
  91. package/dist/migrations/sqlite/meta/0026_snapshot.json +3616 -0
  92. package/dist/migrations/sqlite/meta/0027_snapshot.json +3834 -0
  93. package/dist/migrations/sqlite/meta/_journal.json +70 -0
  94. package/dist/platform-Y3gICK6n.d.ts +58 -0
  95. package/dist/portable.d.ts +2 -2
  96. package/dist/postgres-BI3xTnyw.js +1718 -0
  97. package/dist/postgres-platform-node.d.ts +14 -0
  98. package/dist/postgres-platform-node.js +21 -0
  99. package/dist/postgres-platform-workerd.d.ts +61 -0
  100. package/dist/postgres-platform-workerd.js +163 -0
  101. package/dist/{schema-BfQEBqFv.d.ts → schema-DgoPqqsI.d.ts} +1326 -7
  102. package/dist/schema-sqlite.d.ts +1306 -6
  103. package/dist/schema-sqlite.js +154 -18
  104. package/dist/schema-version.d.ts +1 -1
  105. package/dist/schema-version.js +254 -2
  106. package/dist/schema.d.ts +2 -2
  107. package/dist/schema.js +226 -20
  108. package/package.json +13 -5
  109. package/src/active-subject.ts +9 -0
  110. package/src/change-records.ts +38 -0
  111. package/src/connect.ts +67 -13
  112. package/src/database.ts +67 -51
  113. package/src/dialect.ts +17 -8
  114. package/src/grants.ts +3 -3
  115. package/src/hyperdrive.ts +181 -104
  116. package/src/log.ts +196 -15
  117. package/src/migrate.ts +157 -30
  118. package/src/migrations/postgres/0022_log_015.sql +672 -0
  119. package/src/migrations/postgres/0023_change_path.sql +153 -0
  120. package/src/migrations/postgres/0024_use_015.sql +556 -0
  121. package/src/migrations/postgres/0025_app_change.sql +221 -0
  122. package/src/migrations/postgres/0026_issue_lock.sql +106 -0
  123. package/src/migrations/postgres/0027_retention.sql +118 -0
  124. package/src/migrations/postgres/0028_use_stalls.sql +594 -0
  125. package/src/migrations/postgres/0029_use_objects.sql +887 -0
  126. package/src/migrations/postgres/0030_unarchive_restores.sql +259 -0
  127. package/src/migrations/postgres/0031_app_read.sql +65 -0
  128. package/src/migrations/postgres/0032_secrets_live_index.sql +4 -0
  129. package/src/migrations/postgres/0033_use_generations.sql +582 -0
  130. package/src/migrations/postgres/0034_vault_credentials.sql +153 -0
  131. package/src/migrations/postgres/0035_first_days.sql +3 -0
  132. package/src/migrations/postgres/0036_vault_issues.sql +91 -0
  133. package/src/migrations/postgres/0037_vault_bindings.sql +271 -0
  134. package/src/migrations/postgres/0040_binding_origin.sql +159 -0
  135. package/src/migrations/postgres/0041_cutover.sql +132 -0
  136. package/src/migrations/postgres/0042_sign_in_index.sql +7 -0
  137. package/src/migrations/postgres/0043_issue_revoke_index.sql +4 -0
  138. package/src/migrations/postgres/0044_use_by_name.sql +705 -0
  139. package/src/migrations/postgres/0045_decide_first.sql +878 -0
  140. package/src/migrations/postgres/0046_way_in_uses.sql +1149 -0
  141. package/src/migrations/postgres/0047_cutover_finish.sql +268 -0
  142. package/src/migrations/postgres/0048_use_batch.sql +59 -0
  143. package/src/migrations/postgres/0049_reads.sql +171 -0
  144. package/src/migrations/postgres/meta/0022_snapshot.json +3831 -0
  145. package/src/migrations/postgres/meta/0023_snapshot.json +3831 -0
  146. package/src/migrations/postgres/meta/0024_snapshot.json +3831 -0
  147. package/src/migrations/postgres/meta/0025_snapshot.json +3831 -0
  148. package/src/migrations/postgres/meta/0026_snapshot.json +3831 -0
  149. package/src/migrations/postgres/meta/0027_snapshot.json +3853 -0
  150. package/src/migrations/postgres/meta/0028_snapshot.json +3853 -0
  151. package/src/migrations/postgres/meta/0029_snapshot.json +3859 -0
  152. package/src/migrations/postgres/meta/0030_snapshot.json +3859 -0
  153. package/src/migrations/postgres/meta/0031_snapshot.json +3859 -0
  154. package/src/migrations/postgres/meta/0032_snapshot.json +3875 -0
  155. package/src/migrations/postgres/meta/0033_snapshot.json +3875 -0
  156. package/src/migrations/postgres/meta/0034_snapshot.json +3875 -0
  157. package/src/migrations/postgres/meta/0035_snapshot.json +3875 -0
  158. package/src/migrations/postgres/meta/0036_snapshot.json +3875 -0
  159. package/src/migrations/postgres/meta/0037_snapshot.json +3875 -0
  160. package/src/migrations/postgres/meta/0038_snapshot.json +3881 -0
  161. package/src/migrations/postgres/meta/0039_snapshot.json +3881 -0
  162. package/src/migrations/postgres/meta/0040_snapshot.json +3931 -0
  163. package/src/migrations/postgres/meta/0041_snapshot.json +3981 -0
  164. package/src/migrations/postgres/meta/0042_snapshot.json +3981 -0
  165. package/src/migrations/postgres/meta/0043_snapshot.json +3981 -0
  166. package/src/migrations/postgres/meta/0044_snapshot.json +3991 -0
  167. package/src/migrations/postgres/meta/0045_snapshot.json +3997 -0
  168. package/src/migrations/postgres/meta/0046_snapshot.json +3997 -0
  169. package/src/migrations/postgres/meta/0047_snapshot.json +4234 -0
  170. package/src/migrations/postgres/meta/_journal.json +182 -0
  171. package/src/migrations/sqlite/0018_log_015.sql +84 -0
  172. package/src/migrations/sqlite/0019_retention.sql +2 -0
  173. package/src/migrations/sqlite/0020_ended_references.sql +1 -0
  174. package/src/migrations/sqlite/0021_secrets_live_index.sql +1 -0
  175. package/src/migrations/sqlite/0022_binding_origin.sql +1 -0
  176. package/src/migrations/sqlite/0023_sign_in_index.sql +2 -0
  177. package/src/migrations/sqlite/0024_issue_revoke_index.sql +2 -0
  178. package/src/migrations/sqlite/0025_way_in_uses.sql +42 -0
  179. package/src/migrations/sqlite/0026_cutover_finish.sql +11 -0
  180. package/src/migrations/sqlite/0027_reads.sql +38 -0
  181. package/src/migrations/sqlite/meta/0018_snapshot.json +3529 -0
  182. package/src/migrations/sqlite/meta/0019_snapshot.json +3538 -0
  183. package/src/migrations/sqlite/meta/0020_snapshot.json +3545 -0
  184. package/src/migrations/sqlite/meta/0021_snapshot.json +3553 -0
  185. package/src/migrations/sqlite/meta/0022_snapshot.json +3560 -0
  186. package/src/migrations/sqlite/meta/0023_snapshot.json +3579 -0
  187. package/src/migrations/sqlite/meta/0024_snapshot.json +3598 -0
  188. package/src/migrations/sqlite/meta/0025_snapshot.json +3609 -0
  189. package/src/migrations/sqlite/meta/0026_snapshot.json +3616 -0
  190. package/src/migrations/sqlite/meta/0027_snapshot.json +3834 -0
  191. package/src/migrations/sqlite/meta/_journal.json +70 -0
  192. package/src/postgres-js/README.md +183 -0
  193. package/src/postgres-js/UNLICENSE +24 -0
  194. package/src/postgres-js/bytes.ts +89 -0
  195. package/src/postgres-js/connection.ts +882 -0
  196. package/src/postgres-js/errors.ts +84 -0
  197. package/src/postgres-js/index.ts +516 -0
  198. package/src/postgres-js/platform.node.ts +29 -0
  199. package/src/postgres-js/platform.ts +60 -0
  200. package/src/postgres-js/platform.workerd.ts +225 -0
  201. package/src/postgres-js/query.ts +123 -0
  202. package/src/postgres-js/queue.ts +42 -0
  203. package/src/postgres-js/result.ts +46 -0
  204. package/src/postgres-js/types.ts +52 -0
  205. package/src/postgres.ts +375 -26
  206. package/src/schema-version.ts +2 -2
  207. package/src/schema.sqlite.ts +198 -7
  208. package/src/schema.ts +291 -6
  209. package/src/verify-runtime.ts +18 -29
  210. package/LICENSE +0 -21
  211. package/dist/database-wq1AVRAP.d.ts +0 -73
  212. package/dist/postgres-Bmar8y0q.js +0 -29
  213. package/dist/relations-BfR3JjT1.js +0 -38
  214. package/src/relations.ts +0 -40
package/dist/log.d.ts CHANGED
@@ -1,622 +1,2 @@
1
- import { a as Transaction, i as Queryable } from "./database-wq1AVRAP.js";
2
- import { Placeholder, SQL } from "drizzle-orm";
3
- import { LogKey, StoredEntry } from "@coffre/core/audit";
4
- //#region src/log.d.ts
5
- /**
6
- * Appending to the audit log, the one table both the app and the vault
7
- * write, each under its own key (@coffre/core/audit says what an entry's MAC
8
- * and hash cover).
9
- *
10
- * Every append locks the log's head first, `audit_chain_head`, so entries
11
- * from any process take their numbers in one order. It then reads the
12
- * database clock, after the lock, and the log's last entry, which the head
13
- * must name: a head that does not was moved, or entries were deleted behind
14
- * it, and the append refuses. The same statement says whether the log has
15
- * moved on from the key it appends under (`KeyRetired`).
16
- *
17
- * This is deliberately not a queue and not best-effort: the entries go in
18
- * the caller's transaction, so if the append fails, what it records does
19
- * not happen either.
20
- */
21
- /** An entry to append: what it says. The append numbers, dates, signs and chains it. */
22
- export type NewEntry = {
23
- actor: string;
24
- action: string;
25
- decision: 'allow' | 'deny';
26
- code?: string | null;
27
- subjectPrincipal?: string | null;
28
- projectId?: string | null;
29
- environmentId?: string | null;
30
- secretId?: string | null;
31
- secretVersionId?: string | null;
32
- operationId?: string | null;
33
- requestId?: string | null;
34
- sourceIp?: string | null;
35
- relatedSeq?: bigint | null;
36
- /** JSON text. */
37
- metadata?: string;
38
- };
39
- export type Appended = {
40
- /** The first entry's number, and the next number after the last. */
41
- seqStart: bigint;
42
- nextSeq: bigint;
43
- headHash: Buffer;
44
- /** Milliseconds since the epoch, the database's, shared by the batch. */
45
- occurredAt: number;
46
- };
47
- /** The log's head does not name its last entry: something moved it, or cut the log behind it. */
48
- export declare class LogHeadMismatch extends Error {
49
- constructor(message: string);
50
- }
51
- /**
52
- * As many transactions as may already wait for the log's head do
53
- * (`lockLogHeadQueued`): this one waits for nothing, and holds nothing.
54
- * Its code is Postgres's for a lock not available, so every caller already
55
- * answers it as one that gave up waiting: unavailable, ask again shortly.
56
- */
57
- export declare class HeadBusy extends Error {
58
- readonly code = "55P03";
59
- constructor();
60
- }
61
- /**
62
- * The log's head is behind one this process wrote: the database was rolled
63
- * back, or entries were cut off its end. That cannot be told from a restore,
64
- * so the append refuses and someone has to look.
65
- */
66
- export declare class LogRewound extends Error {
67
- constructor(message: string);
68
- }
69
- /**
70
- * An append under a key the log has moved on from: an entry of its
71
- * author's, `key.reseal` or `key.rotate`, names it as the key it moves
72
- * from (`MOVES_FROM`), and a key moved from writes no more.
73
- */
74
- export declare class KeyRetired extends Error {
75
- constructor(message: string);
76
- }
77
- /**
78
- * The actions by which an author moves to a new key, each under the new one
79
- * and naming the key it moves from as its subject: from the first, that key
80
- * writes no more (`KeyRetired`). The app's key rotation writes them
81
- * (packages/server/src/key-rotation.ts).
82
- */
83
- export declare const MOVES_FROM: readonly ["key.reseal", "key.rotate"];
84
- /**
85
- * Forget every head written so far. For tests that empty the database
86
- * between cases, which is exactly what the check above refuses.
87
- */
88
- export declare function forgetLogHeads(): void;
89
- /**
90
- * Lock the log's head, and read it. A transaction that appends takes this
91
- * before any other row, so the lock order is the same everywhere; taking it
92
- * again in the same transaction is free.
93
- */
94
- export declare function lockLogHead(tx: Transaction): Promise<{
95
- nextSeq: bigint;
96
- headHash: Buffer;
97
- }>;
98
- /**
99
- * Lock the log's head if no one holds it, without waiting: whether it is
100
- * held now. For work any caller may do, of which one at a time is enough,
101
- * which a request that finds the head taken leaves to the one that has it.
102
- * SQLite's transactions hold the whole file, so the head is always free.
103
- */
104
- export declare function lockLogHeadIfFree(tx: Transaction): Promise<boolean>;
105
- /**
106
- * Lock the log's head, waiting for it as `lockLogHead` does, if fewer than
107
- * `waiters` other transactions hold one of its places in line; otherwise
108
- * refuse at once (`HeadBusy`), having waited for nothing. A place is an
109
- * advisory lock, tried, never waited for, and held to the end of the
110
- * transaction, which holds the head by then: so at most `waiters`
111
- * connections wait for the head, or hold it, through here, and a burst
112
- * beyond them answers in one round trip rather than seconds later, holding
113
- * a connection all the while. One statement: the place, then, only if one
114
- * was free, the head; refused, one more says whether the head is there at
115
- * all. SQLite's transactions hold the whole file.
116
- */
117
- export declare function lockLogHeadQueued(tx: Transaction, waiters: number): Promise<{
118
- nextSeq: bigint;
119
- headHash: Buffer;
120
- }>;
121
- /**
122
- * Append `entries` under `key`. `check`, when given, runs once the head is
123
- * locked and before anything is written: a writer's own condition on the
124
- * log as it stands, which no other append can change until this one
125
- * commits. It throws to refuse.
126
- */
127
- export declare function appendEntries(tx: Transaction, key: LogKey, entries: readonly NewEntry[], check?: (tx: Transaction) => Promise<void>,
128
- /**
129
- * The head as a statement of the caller's locked it, with the log's last
130
- * entry and the clock as that statement read them once it held the lock:
131
- * nothing to read again.
132
- */
133
- locked?: HeldHead): Promise<Appended>;
134
- /** A head locked by a statement of the caller's, and what it read under the lock (`appendEntries`). */
135
- export type HeldHead = {
136
- head: {
137
- nextSeq: bigint;
138
- headHash: Buffer;
139
- };
140
- last: {
141
- seq: bigint;
142
- hash: Buffer;
143
- } | null;
144
- at: number;
145
- };
146
- /** An entry's columns, as the chain's codec reads them (`StoredEntry`). */
147
- export declare function entryColumns(db: Queryable): {
148
- seq: import("drizzle-orm/pg-core").PgColumn<{
149
- name: "seq";
150
- tableName: "audit_log";
151
- dataType: "bigint";
152
- columnType: "PgBigInt64";
153
- data: bigint;
154
- driverParam: string;
155
- notNull: true;
156
- hasDefault: false;
157
- isPrimaryKey: true;
158
- isAutoincrement: false;
159
- hasRuntimeDefault: false;
160
- enumValues: undefined;
161
- baseColumn: never;
162
- identity: undefined;
163
- generated: undefined;
164
- }, {}, {}>;
165
- author: import("drizzle-orm/pg-core").PgColumn<{
166
- name: "author";
167
- tableName: "audit_log";
168
- dataType: "string";
169
- columnType: "PgText";
170
- data: string;
171
- driverParam: string;
172
- notNull: true;
173
- hasDefault: false;
174
- isPrimaryKey: false;
175
- isAutoincrement: false;
176
- hasRuntimeDefault: false;
177
- enumValues: [string, ...string[]];
178
- baseColumn: never;
179
- identity: undefined;
180
- generated: undefined;
181
- }, {}, {}>;
182
- keyId: import("drizzle-orm/pg-core").PgColumn<{
183
- name: "key_id";
184
- tableName: "audit_log";
185
- dataType: "string";
186
- columnType: "PgText";
187
- data: string;
188
- driverParam: string;
189
- notNull: true;
190
- hasDefault: false;
191
- isPrimaryKey: false;
192
- isAutoincrement: false;
193
- hasRuntimeDefault: false;
194
- enumValues: [string, ...string[]];
195
- baseColumn: never;
196
- identity: undefined;
197
- generated: undefined;
198
- }, {}, {}>;
199
- occurredAt: import("drizzle-orm/pg-core").PgColumn<{
200
- name: "occurred_at";
201
- tableName: "audit_log";
202
- dataType: "number";
203
- columnType: "PgBigInt53";
204
- data: number;
205
- driverParam: string | number;
206
- notNull: true;
207
- hasDefault: false;
208
- isPrimaryKey: false;
209
- isAutoincrement: false;
210
- hasRuntimeDefault: false;
211
- enumValues: undefined;
212
- baseColumn: never;
213
- identity: undefined;
214
- generated: undefined;
215
- }, {}, {}>;
216
- actor: import("drizzle-orm/pg-core").PgColumn<{
217
- name: "actor";
218
- tableName: "audit_log";
219
- dataType: "string";
220
- columnType: "PgText";
221
- data: string;
222
- driverParam: string;
223
- notNull: true;
224
- hasDefault: false;
225
- isPrimaryKey: false;
226
- isAutoincrement: false;
227
- hasRuntimeDefault: false;
228
- enumValues: [string, ...string[]];
229
- baseColumn: never;
230
- identity: undefined;
231
- generated: undefined;
232
- }, {}, {}>;
233
- action: import("drizzle-orm/pg-core").PgColumn<{
234
- name: "action";
235
- tableName: "audit_log";
236
- dataType: "string";
237
- columnType: "PgText";
238
- data: string;
239
- driverParam: string;
240
- notNull: true;
241
- hasDefault: false;
242
- isPrimaryKey: false;
243
- isAutoincrement: false;
244
- hasRuntimeDefault: false;
245
- enumValues: [string, ...string[]];
246
- baseColumn: never;
247
- identity: undefined;
248
- generated: undefined;
249
- }, {}, {}>;
250
- decision: import("drizzle-orm/pg-core").PgColumn<{
251
- name: "decision";
252
- tableName: "audit_log";
253
- dataType: "string";
254
- columnType: "PgText";
255
- data: string;
256
- driverParam: string;
257
- notNull: true;
258
- hasDefault: false;
259
- isPrimaryKey: false;
260
- isAutoincrement: false;
261
- hasRuntimeDefault: false;
262
- enumValues: [string, ...string[]];
263
- baseColumn: never;
264
- identity: undefined;
265
- generated: undefined;
266
- }, {}, {}>;
267
- code: import("drizzle-orm/pg-core").PgColumn<{
268
- name: "code";
269
- tableName: "audit_log";
270
- dataType: "string";
271
- columnType: "PgText";
272
- data: string;
273
- driverParam: string;
274
- notNull: false;
275
- hasDefault: false;
276
- isPrimaryKey: false;
277
- isAutoincrement: false;
278
- hasRuntimeDefault: false;
279
- enumValues: [string, ...string[]];
280
- baseColumn: never;
281
- identity: undefined;
282
- generated: undefined;
283
- }, {}, {}>;
284
- subjectPrincipal: import("drizzle-orm/pg-core").PgColumn<{
285
- name: "subject_principal";
286
- tableName: "audit_log";
287
- dataType: "string";
288
- columnType: "PgText";
289
- data: string;
290
- driverParam: string;
291
- notNull: false;
292
- hasDefault: false;
293
- isPrimaryKey: false;
294
- isAutoincrement: false;
295
- hasRuntimeDefault: false;
296
- enumValues: [string, ...string[]];
297
- baseColumn: never;
298
- identity: undefined;
299
- generated: undefined;
300
- }, {}, {}>;
301
- projectId: import("drizzle-orm/pg-core").PgColumn<{
302
- name: "project_id";
303
- tableName: "audit_log";
304
- dataType: "string";
305
- columnType: "PgUUID";
306
- data: string;
307
- driverParam: string;
308
- notNull: false;
309
- hasDefault: false;
310
- isPrimaryKey: false;
311
- isAutoincrement: false;
312
- hasRuntimeDefault: false;
313
- enumValues: undefined;
314
- baseColumn: never;
315
- identity: undefined;
316
- generated: undefined;
317
- }, {}, {}>;
318
- environmentId: import("drizzle-orm/pg-core").PgColumn<{
319
- name: "environment_id";
320
- tableName: "audit_log";
321
- dataType: "string";
322
- columnType: "PgUUID";
323
- data: string;
324
- driverParam: string;
325
- notNull: false;
326
- hasDefault: false;
327
- isPrimaryKey: false;
328
- isAutoincrement: false;
329
- hasRuntimeDefault: false;
330
- enumValues: undefined;
331
- baseColumn: never;
332
- identity: undefined;
333
- generated: undefined;
334
- }, {}, {}>;
335
- secretId: import("drizzle-orm/pg-core").PgColumn<{
336
- name: "secret_id";
337
- tableName: "audit_log";
338
- dataType: "string";
339
- columnType: "PgUUID";
340
- data: string;
341
- driverParam: string;
342
- notNull: false;
343
- hasDefault: false;
344
- isPrimaryKey: false;
345
- isAutoincrement: false;
346
- hasRuntimeDefault: false;
347
- enumValues: undefined;
348
- baseColumn: never;
349
- identity: undefined;
350
- generated: undefined;
351
- }, {}, {}>;
352
- secretVersionId: import("drizzle-orm/pg-core").PgColumn<{
353
- name: "secret_version_id";
354
- tableName: "audit_log";
355
- dataType: "string";
356
- columnType: "PgUUID";
357
- data: string;
358
- driverParam: string;
359
- notNull: false;
360
- hasDefault: false;
361
- isPrimaryKey: false;
362
- isAutoincrement: false;
363
- hasRuntimeDefault: false;
364
- enumValues: undefined;
365
- baseColumn: never;
366
- identity: undefined;
367
- generated: undefined;
368
- }, {}, {}>;
369
- operationId: import("drizzle-orm/pg-core").PgColumn<{
370
- name: "operation_id";
371
- tableName: "audit_log";
372
- dataType: "string";
373
- columnType: "PgUUID";
374
- data: string;
375
- driverParam: string;
376
- notNull: false;
377
- hasDefault: false;
378
- isPrimaryKey: false;
379
- isAutoincrement: false;
380
- hasRuntimeDefault: false;
381
- enumValues: undefined;
382
- baseColumn: never;
383
- identity: undefined;
384
- generated: undefined;
385
- }, {}, {}>;
386
- requestId: import("drizzle-orm/pg-core").PgColumn<{
387
- name: "request_id";
388
- tableName: "audit_log";
389
- dataType: "string";
390
- columnType: "PgText";
391
- data: string;
392
- driverParam: string;
393
- notNull: false;
394
- hasDefault: false;
395
- isPrimaryKey: false;
396
- isAutoincrement: false;
397
- hasRuntimeDefault: false;
398
- enumValues: [string, ...string[]];
399
- baseColumn: never;
400
- identity: undefined;
401
- generated: undefined;
402
- }, {}, {}>;
403
- sourceIp: import("drizzle-orm/pg-core").PgColumn<{
404
- name: "source_ip";
405
- tableName: "audit_log";
406
- dataType: "string";
407
- columnType: "PgText";
408
- data: string;
409
- driverParam: string;
410
- notNull: false;
411
- hasDefault: false;
412
- isPrimaryKey: false;
413
- isAutoincrement: false;
414
- hasRuntimeDefault: false;
415
- enumValues: [string, ...string[]];
416
- baseColumn: never;
417
- identity: undefined;
418
- generated: undefined;
419
- }, {}, {}>;
420
- relatedSeq: import("drizzle-orm/pg-core").PgColumn<{
421
- name: "related_seq";
422
- tableName: "audit_log";
423
- dataType: "bigint";
424
- columnType: "PgBigInt64";
425
- data: bigint;
426
- driverParam: string;
427
- notNull: false;
428
- hasDefault: false;
429
- isPrimaryKey: false;
430
- isAutoincrement: false;
431
- hasRuntimeDefault: false;
432
- enumValues: undefined;
433
- baseColumn: never;
434
- identity: undefined;
435
- generated: undefined;
436
- }, {}, {}>;
437
- metadata: import("drizzle-orm/pg-core").PgColumn<{
438
- name: "metadata";
439
- tableName: "audit_log";
440
- dataType: "string";
441
- columnType: "PgText";
442
- data: string;
443
- driverParam: string;
444
- notNull: true;
445
- hasDefault: true;
446
- isPrimaryKey: false;
447
- isAutoincrement: false;
448
- hasRuntimeDefault: false;
449
- enumValues: [string, ...string[]];
450
- baseColumn: never;
451
- identity: undefined;
452
- generated: undefined;
453
- }, {}, {}>;
454
- prevHash: import("drizzle-orm/pg-core").PgColumn<{
455
- name: "prev_hash";
456
- tableName: "audit_log";
457
- dataType: "custom";
458
- columnType: "PgCustomColumn";
459
- data: Buffer<ArrayBufferLike>;
460
- driverParam: unknown;
461
- notNull: true;
462
- hasDefault: false;
463
- isPrimaryKey: false;
464
- isAutoincrement: false;
465
- hasRuntimeDefault: false;
466
- enumValues: undefined;
467
- baseColumn: never;
468
- identity: undefined;
469
- generated: undefined;
470
- }, {}, {
471
- pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
472
- }>;
473
- mac: import("drizzle-orm/pg-core").PgColumn<{
474
- name: "mac";
475
- tableName: "audit_log";
476
- dataType: "custom";
477
- columnType: "PgCustomColumn";
478
- data: Buffer<ArrayBufferLike>;
479
- driverParam: unknown;
480
- notNull: true;
481
- hasDefault: false;
482
- isPrimaryKey: false;
483
- isAutoincrement: false;
484
- hasRuntimeDefault: false;
485
- enumValues: undefined;
486
- baseColumn: never;
487
- identity: undefined;
488
- generated: undefined;
489
- }, {}, {
490
- pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
491
- }>;
492
- hash: import("drizzle-orm/pg-core").PgColumn<{
493
- name: "hash";
494
- tableName: "audit_log";
495
- dataType: "custom";
496
- columnType: "PgCustomColumn";
497
- data: Buffer<ArrayBufferLike>;
498
- driverParam: unknown;
499
- notNull: true;
500
- hasDefault: false;
501
- isPrimaryKey: false;
502
- isAutoincrement: false;
503
- hasRuntimeDefault: false;
504
- enumValues: undefined;
505
- baseColumn: never;
506
- identity: undefined;
507
- generated: undefined;
508
- }, {}, {
509
- pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
510
- }>;
511
- };
512
- /**
513
- * Metadata a reader of many entries holds at once, at most: an entry about
514
- * a read of several secrets lists them, a thousand some 150 kilobytes, so a
515
- * count of entries alone does not bound a batch's or a page's memory within
516
- * a Worker's 128 megabytes.
517
- */
518
- export declare const BATCH_BYTES: number;
519
- /**
520
- * Of the entries `where` matches, in `order` of seq, the first `limit` or
521
- * fewer that hold no more than `BATCH_BYTES` of metadata between them, but
522
- * always the first: the seqs they run from and to, and whether the bytes
523
- * cut the run short of `limit`. Null when none matches. A reader asks this
524
- * first, then reads `where` between the two.
525
- */
526
- export declare function withinBytes(db: Queryable, where: SQL | undefined, limit: number, order?: 'asc' | 'desc'): Promise<{
527
- from: bigint;
528
- to: bigint;
529
- cut: boolean;
530
- count: number;
531
- } | null>;
532
- /**
533
- * The first entry missing from the log up to `seq`, and the one found in
534
- * its place, or null when every one is there. Seqs are the primary key, so
535
- * a stretch is whole exactly when its count is its length: one pass over
536
- * the key's index, never the entries. Only a log with a gap pays for more,
537
- * a count per halving to find where.
538
- *
539
- * entries 0..9, 4 cut: { expected: 4n, found: 5n }
540
- */
541
- export declare function missingEntry(db: Queryable, seq: bigint): Promise<{
542
- expected: bigint;
543
- found: bigint | null;
544
- } | null>;
545
- /**
546
- * How a reader tells the vault's own entries from those forged in its name:
547
- * by their MAC, which only the vault holds the key to check. Each it finds
548
- * forged goes to `forged`.
549
- */
550
- export type Authenticity = {
551
- authentic: (entry: StoredEntry) => boolean;
552
- forged: (entry: StoredEntry) => void;
553
- };
554
- /** Up to `limit` of the entries in the vault's name, allowed, of one `action`, before `before` (the newest when undefined), newest first. */
555
- export declare function newestVaultEntries(db: Queryable, action: string, limit: number, before?: bigint): Promise<StoredEntry[]>;
556
- /**
557
- * The number of the newest entry in the vault's name, allowed, of one
558
- * `action`, or null for none: whether one was appended since, and nothing
559
- * of what it says, so its MAC is not checked. One indexed read.
560
- */
561
- export declare function newestVaultSeq(db: Queryable, action: string): Promise<bigint | null>;
562
- /**
563
- * `newestVaultSeq`'s query, to run or to read inside another, as a
564
- * credential's read takes the newest `policy.change` with it: one rule for
565
- * what the newest is, wherever it is read.
566
- */
567
- export declare function newestSeqQuery(db: Queryable, action: string | Placeholder): Omit<import("drizzle-orm/pg-core").PgSelectBase<"audit_log", {
568
- seq: import("drizzle-orm/pg-core").PgColumn<{
569
- name: "seq";
570
- tableName: "audit_log";
571
- dataType: "bigint";
572
- columnType: "PgBigInt64";
573
- data: bigint;
574
- driverParam: string;
575
- notNull: true;
576
- hasDefault: false;
577
- isPrimaryKey: true;
578
- isAutoincrement: false;
579
- hasRuntimeDefault: false;
580
- enumValues: undefined;
581
- baseColumn: never;
582
- identity: undefined;
583
- generated: undefined;
584
- }, {}, {}>;
585
- }, "partial", Record<"audit_log", "not-null">, false, "where" | "orderBy" | "limit", {
586
- seq: bigint;
587
- }[], {
588
- seq: import("drizzle-orm/pg-core").PgColumn<{
589
- name: "seq";
590
- tableName: "audit_log";
591
- dataType: "bigint";
592
- columnType: "PgBigInt64";
593
- data: bigint;
594
- driverParam: string;
595
- notNull: true;
596
- hasDefault: false;
597
- isPrimaryKey: true;
598
- isAutoincrement: false;
599
- hasRuntimeDefault: false;
600
- enumValues: undefined;
601
- baseColumn: never;
602
- identity: undefined;
603
- generated: undefined;
604
- }, {}, {}>;
605
- }>, "where" | "orderBy" | "limit">;
606
- /** How many entries in its name the vault reads back, a page at a time, for its own newest of a kind (`newestAuthentic`). */
607
- export declare const LOOK_BACK: {
608
- page: number;
609
- pages: number;
610
- };
611
- /** What `newestAuthentic` finds: the entry, or why there is none. */
612
- export type Newest = StoredEntry | 'none' | 'forged' | 'unreached';
613
- /**
614
- * The newest of the entries `page` reads, newest first and before a seq,
615
- * that `check` finds authentic: the newest alone first, which it is unless
616
- * entries were forged in the vault's name since, then back a page at a
617
- * time. 'none' when there are none at all, 'forged' when every one is in
618
- * the vault's name but not its own, and 'unreached' once it has read
619
- * LOOK_BACK such entries (1024), whether or not more are left.
620
- */
621
- export declare function newestAuthentic(page: (limit: number, before: bigint | undefined) => Promise<StoredEntry[]>, check: Authenticity): Promise<Newest>;
622
- //#endregion
1
+ import { A as ChangeRecord, C as logObject, D as newestVaultEntries, E as newestSeqQuery, M as recorded, O as newestVaultSeq, S as lockLogHeadQueued, T as newestAuthentic, _ as holdFence, a as HeldHead, b as lockLogHead, c as LogHeadMismatch, d as NewEntry, f as Newest, g as forgetLogHeads, h as entryColumns, i as HeadBusy, j as RECORDS, k as withinBytes, l as LogRewound, m as appendEntries, n as Authenticity, o as KeyRetired, p as appChanges, r as BATCH_BYTES, s as LOOK_BACK, t as Appended, u as MOVES_FROM, v as holdIssues, w as missingEntry, x as lockLogHeadIfFree, y as isStaleChange } from "./log-DaD7fyUq.js";
2
+ export { Appended, Authenticity, BATCH_BYTES, type ChangeRecord, HeadBusy, HeldHead, KeyRetired, LOOK_BACK, LogHeadMismatch, LogRewound, MOVES_FROM, NewEntry, Newest, RECORDS, appChanges, appendEntries, entryColumns, forgetLogHeads, holdFence, holdIssues, isStaleChange, lockLogHead, lockLogHeadIfFree, lockLogHeadQueued, logObject, missingEntry, newestAuthentic, newestSeqQuery, newestVaultEntries, newestVaultSeq, recorded, withinBytes };