@hyperfixation/db 0.1.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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app-state.d.ts +12 -0
  3. package/dist/app-state.js +18 -0
  4. package/dist/boot-checks.d.ts +56 -0
  5. package/dist/boot-checks.js +228 -0
  6. package/dist/classify.d.ts +6 -0
  7. package/dist/classify.js +75 -0
  8. package/dist/control-plane.d.ts +75 -0
  9. package/dist/control-plane.js +155 -0
  10. package/dist/delete-guard.d.ts +32 -0
  11. package/dist/delete-guard.js +62 -0
  12. package/dist/fenced-client.d.ts +35 -0
  13. package/dist/fenced-client.js +153 -0
  14. package/dist/grant-ro.d.ts +23 -0
  15. package/dist/grant-ro.js +49 -0
  16. package/dist/index.d.ts +12 -0
  17. package/dist/index.js +10 -0
  18. package/dist/internal/control-pool.d.ts +20 -0
  19. package/dist/internal/control-pool.js +17 -0
  20. package/dist/loader.d.ts +15 -0
  21. package/dist/loader.js +82 -0
  22. package/dist/migrate.d.ts +54 -0
  23. package/dist/migrate.js +143 -0
  24. package/dist/migration-policy.d.ts +14 -0
  25. package/dist/migration-policy.js +85 -0
  26. package/dist/migrator.d.ts +9 -0
  27. package/dist/migrator.js +9 -0
  28. package/dist/roles.d.ts +47 -0
  29. package/dist/roles.js +112 -0
  30. package/dist/schema/app.d.ts +235 -0
  31. package/dist/schema/app.js +23 -0
  32. package/dist/schema/approvals.d.ts +352 -0
  33. package/dist/schema/approvals.js +43 -0
  34. package/dist/schema/auth.d.ts +1272 -0
  35. package/dist/schema/auth.js +120 -0
  36. package/dist/schema/index.d.ts +7 -0
  37. package/dist/schema/index.js +7 -0
  38. package/dist/schema/ledger.d.ts +722 -0
  39. package/dist/schema/ledger.js +68 -0
  40. package/dist/schema/machinery.d.ts +1343 -0
  41. package/dist/schema/machinery.js +146 -0
  42. package/dist/schema/records.d.ts +15 -0
  43. package/dist/schema/records.js +16 -0
  44. package/dist/schema/runs.d.ts +213 -0
  45. package/dist/schema/runs.js +26 -0
  46. package/dist/step-pool.d.ts +26 -0
  47. package/dist/step-pool.js +57 -0
  48. package/migrations/0000_core_schema.sql +185 -0
  49. package/migrations/0001_llm_call_reservation_index.sql +4 -0
  50. package/migrations/0002_approvals.sql +25 -0
  51. package/migrations/0003_auth_invitation.sql +13 -0
  52. package/migrations/0004_machinery.sql +105 -0
  53. package/migrations/0005_nullable_activity_task_record.sql +4 -0
  54. package/migrations/0006_activity_score_key.sql +5 -0
  55. package/migrations/0007_score_spec_name.sql +3 -0
  56. package/migrations/meta/0000_snapshot.json +1238 -0
  57. package/migrations/meta/0001_snapshot.json +1238 -0
  58. package/migrations/meta/0002_snapshot.json +1426 -0
  59. package/migrations/meta/0003_snapshot.json +1516 -0
  60. package/migrations/meta/0004_snapshot.json +2353 -0
  61. package/migrations/meta/0005_snapshot.json +2353 -0
  62. package/migrations/meta/0006_snapshot.json +2415 -0
  63. package/migrations/meta/0007_snapshot.json +2427 -0
  64. package/migrations/meta/_journal.json +62 -0
  65. package/package.json +58 -0
@@ -0,0 +1,23 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { bigint, boolean, check, integer, jsonb, numeric, pgTable, text, timestamp, } from "drizzle-orm/pg-core";
3
+ // Singleton. `budget_usd` is only the default copied into each new hf_budget_period
4
+ // row; `month`, `spent_usd` and `reserved_usd` deliberately do not exist — spend
5
+ // lives per period in hf_budget_period and the reservation is derived from the
6
+ // hf_llm_call rows still in `started`.
7
+ export const hfAppState = pgTable("hf_app_state", {
8
+ id: integer("id").primaryKey().default(1),
9
+ paused: boolean("paused").notNull().default(false),
10
+ pausedBy: text("paused_by"),
11
+ budgetUsd: numeric("budget_usd", { precision: 12, scale: 4 }).notNull(),
12
+ readTokenHash: text("read_token_hash"),
13
+ writeTokenHash: text("write_token_hash"),
14
+ }, (t) => [check("hf_app_state_singleton", sql `${t.id} = 1`)]);
15
+ export const hfAudit = pgTable("hf_audit", {
16
+ id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
17
+ actorId: text("actor_id"),
18
+ action: text("action").notNull(),
19
+ targetType: text("target_type"),
20
+ targetId: text("target_id"),
21
+ meta: jsonb("meta"),
22
+ at: timestamp("at", { withTimezone: true, mode: "date" }).notNull().defaultNow(),
23
+ });
@@ -0,0 +1,352 @@
1
+ export declare const approvalStatuses: readonly ["pending", "approved", "rejected", "expired", "cancelled"];
2
+ export type ApprovalStatus = (typeof approvalStatuses)[number];
3
+ /** Everything that can decide an approval; `sweep` is `reconcile()` step (5) expiring one. */
4
+ export declare const approvalVias: readonly ["web", "telegram", "admin", "archive", "sweep"];
5
+ export type ApprovalVia = (typeof approvalVias)[number];
6
+ export declare const hfApproval: import("drizzle-orm/pg-core").PgTableWithColumns<{
7
+ name: "hf_approval";
8
+ schema: undefined;
9
+ columns: {
10
+ id: import("drizzle-orm/pg-core").PgColumn<{
11
+ name: "id";
12
+ tableName: "hf_approval";
13
+ dataType: "number";
14
+ columnType: "PgBigInt53";
15
+ data: number;
16
+ driverParam: string | number;
17
+ notNull: true;
18
+ hasDefault: true;
19
+ isPrimaryKey: true;
20
+ isAutoincrement: false;
21
+ hasRuntimeDefault: false;
22
+ enumValues: undefined;
23
+ baseColumn: never;
24
+ identity: "always";
25
+ generated: undefined;
26
+ }, {}, {}>;
27
+ runId: import("drizzle-orm/pg-core").PgColumn<{
28
+ name: "run_id";
29
+ tableName: "hf_approval";
30
+ dataType: "string";
31
+ columnType: "PgText";
32
+ data: string;
33
+ driverParam: string;
34
+ notNull: true;
35
+ hasDefault: false;
36
+ isPrimaryKey: false;
37
+ isAutoincrement: false;
38
+ hasRuntimeDefault: false;
39
+ enumValues: [string, ...string[]];
40
+ baseColumn: never;
41
+ identity: undefined;
42
+ generated: undefined;
43
+ }, {}, {}>;
44
+ key: import("drizzle-orm/pg-core").PgColumn<{
45
+ name: "key";
46
+ tableName: "hf_approval";
47
+ dataType: "string";
48
+ columnType: "PgText";
49
+ data: string;
50
+ driverParam: string;
51
+ notNull: true;
52
+ hasDefault: false;
53
+ isPrimaryKey: false;
54
+ isAutoincrement: false;
55
+ hasRuntimeDefault: false;
56
+ enumValues: [string, ...string[]];
57
+ baseColumn: never;
58
+ identity: undefined;
59
+ generated: undefined;
60
+ }, {}, {}>;
61
+ workflowId: import("drizzle-orm/pg-core").PgColumn<{
62
+ name: "workflow_id";
63
+ tableName: "hf_approval";
64
+ dataType: "string";
65
+ columnType: "PgText";
66
+ data: string;
67
+ driverParam: string;
68
+ notNull: true;
69
+ hasDefault: false;
70
+ isPrimaryKey: false;
71
+ isAutoincrement: false;
72
+ hasRuntimeDefault: false;
73
+ enumValues: [string, ...string[]];
74
+ baseColumn: never;
75
+ identity: undefined;
76
+ generated: undefined;
77
+ }, {}, {}>;
78
+ type: import("drizzle-orm/pg-core").PgColumn<{
79
+ name: "type";
80
+ tableName: "hf_approval";
81
+ dataType: "string";
82
+ columnType: "PgText";
83
+ data: string;
84
+ driverParam: string;
85
+ notNull: true;
86
+ hasDefault: false;
87
+ isPrimaryKey: false;
88
+ isAutoincrement: false;
89
+ hasRuntimeDefault: false;
90
+ enumValues: [string, ...string[]];
91
+ baseColumn: never;
92
+ identity: undefined;
93
+ generated: undefined;
94
+ }, {}, {}>;
95
+ recordType: import("drizzle-orm/pg-core").PgColumn<{
96
+ name: "record_type";
97
+ tableName: "hf_approval";
98
+ dataType: "string";
99
+ columnType: "PgText";
100
+ data: string;
101
+ driverParam: string;
102
+ notNull: false;
103
+ hasDefault: false;
104
+ isPrimaryKey: false;
105
+ isAutoincrement: false;
106
+ hasRuntimeDefault: false;
107
+ enumValues: [string, ...string[]];
108
+ baseColumn: never;
109
+ identity: undefined;
110
+ generated: undefined;
111
+ }, {}, {}>;
112
+ recordId: import("drizzle-orm/pg-core").PgColumn<{
113
+ name: "record_id";
114
+ tableName: "hf_approval";
115
+ dataType: "string";
116
+ columnType: "PgText";
117
+ data: string;
118
+ driverParam: string;
119
+ notNull: false;
120
+ hasDefault: false;
121
+ isPrimaryKey: false;
122
+ isAutoincrement: false;
123
+ hasRuntimeDefault: false;
124
+ enumValues: [string, ...string[]];
125
+ baseColumn: never;
126
+ identity: undefined;
127
+ generated: undefined;
128
+ }, {}, {}>;
129
+ draft: import("drizzle-orm/pg-core").PgColumn<{
130
+ name: "draft";
131
+ tableName: "hf_approval";
132
+ dataType: "json";
133
+ columnType: "PgJsonb";
134
+ data: unknown;
135
+ driverParam: unknown;
136
+ notNull: false;
137
+ hasDefault: false;
138
+ isPrimaryKey: false;
139
+ isAutoincrement: false;
140
+ hasRuntimeDefault: false;
141
+ enumValues: undefined;
142
+ baseColumn: never;
143
+ identity: undefined;
144
+ generated: undefined;
145
+ }, {}, {}>;
146
+ editedDraft: import("drizzle-orm/pg-core").PgColumn<{
147
+ name: "edited_draft";
148
+ tableName: "hf_approval";
149
+ dataType: "json";
150
+ columnType: "PgJsonb";
151
+ data: unknown;
152
+ driverParam: unknown;
153
+ notNull: false;
154
+ hasDefault: false;
155
+ isPrimaryKey: false;
156
+ isAutoincrement: false;
157
+ hasRuntimeDefault: false;
158
+ enumValues: undefined;
159
+ baseColumn: never;
160
+ identity: undefined;
161
+ generated: undefined;
162
+ }, {}, {}>;
163
+ status: import("drizzle-orm/pg-core").PgColumn<{
164
+ name: "status";
165
+ tableName: "hf_approval";
166
+ dataType: "string";
167
+ columnType: "PgText";
168
+ data: "pending" | "approved" | "rejected" | "expired" | "cancelled";
169
+ driverParam: string;
170
+ notNull: true;
171
+ hasDefault: false;
172
+ isPrimaryKey: false;
173
+ isAutoincrement: false;
174
+ hasRuntimeDefault: false;
175
+ enumValues: ["pending", "approved", "rejected", "expired", "cancelled"];
176
+ baseColumn: never;
177
+ identity: undefined;
178
+ generated: undefined;
179
+ }, {}, {}>;
180
+ assigneeId: import("drizzle-orm/pg-core").PgColumn<{
181
+ name: "assignee_id";
182
+ tableName: "hf_approval";
183
+ dataType: "string";
184
+ columnType: "PgText";
185
+ data: string;
186
+ driverParam: string;
187
+ notNull: false;
188
+ hasDefault: false;
189
+ isPrimaryKey: false;
190
+ isAutoincrement: false;
191
+ hasRuntimeDefault: false;
192
+ enumValues: [string, ...string[]];
193
+ baseColumn: never;
194
+ identity: undefined;
195
+ generated: undefined;
196
+ }, {}, {}>;
197
+ decidedBy: import("drizzle-orm/pg-core").PgColumn<{
198
+ name: "decided_by";
199
+ tableName: "hf_approval";
200
+ dataType: "string";
201
+ columnType: "PgText";
202
+ data: string;
203
+ driverParam: string;
204
+ notNull: false;
205
+ hasDefault: false;
206
+ isPrimaryKey: false;
207
+ isAutoincrement: false;
208
+ hasRuntimeDefault: false;
209
+ enumValues: [string, ...string[]];
210
+ baseColumn: never;
211
+ identity: undefined;
212
+ generated: undefined;
213
+ }, {}, {}>;
214
+ decidedAt: import("drizzle-orm/pg-core").PgColumn<{
215
+ name: "decided_at";
216
+ tableName: "hf_approval";
217
+ dataType: "date";
218
+ columnType: "PgTimestamp";
219
+ data: Date;
220
+ driverParam: string;
221
+ notNull: false;
222
+ hasDefault: false;
223
+ isPrimaryKey: false;
224
+ isAutoincrement: false;
225
+ hasRuntimeDefault: false;
226
+ enumValues: undefined;
227
+ baseColumn: never;
228
+ identity: undefined;
229
+ generated: undefined;
230
+ }, {}, {}>;
231
+ decidedVia: import("drizzle-orm/pg-core").PgColumn<{
232
+ name: "decided_via";
233
+ tableName: "hf_approval";
234
+ dataType: "string";
235
+ columnType: "PgText";
236
+ data: "web" | "telegram" | "admin" | "archive" | "sweep";
237
+ driverParam: string;
238
+ notNull: false;
239
+ hasDefault: false;
240
+ isPrimaryKey: false;
241
+ isAutoincrement: false;
242
+ hasRuntimeDefault: false;
243
+ enumValues: ["web", "telegram", "admin", "archive", "sweep"];
244
+ baseColumn: never;
245
+ identity: undefined;
246
+ generated: undefined;
247
+ }, {}, {}>;
248
+ decisionKey: import("drizzle-orm/pg-core").PgColumn<{
249
+ name: "decision_key";
250
+ tableName: "hf_approval";
251
+ dataType: "string";
252
+ columnType: "PgText";
253
+ data: string;
254
+ driverParam: string;
255
+ notNull: false;
256
+ hasDefault: false;
257
+ isPrimaryKey: false;
258
+ isAutoincrement: false;
259
+ hasRuntimeDefault: false;
260
+ enumValues: [string, ...string[]];
261
+ baseColumn: never;
262
+ identity: undefined;
263
+ generated: undefined;
264
+ }, {}, {}>;
265
+ resumeWorkflowId: import("drizzle-orm/pg-core").PgColumn<{
266
+ name: "resume_workflow_id";
267
+ tableName: "hf_approval";
268
+ dataType: "string";
269
+ columnType: "PgText";
270
+ data: string;
271
+ driverParam: string;
272
+ notNull: false;
273
+ hasDefault: false;
274
+ isPrimaryKey: false;
275
+ isAutoincrement: false;
276
+ hasRuntimeDefault: false;
277
+ enumValues: [string, ...string[]];
278
+ baseColumn: never;
279
+ identity: undefined;
280
+ generated: undefined;
281
+ }, {}, {}>;
282
+ notifiedAt: import("drizzle-orm/pg-core").PgColumn<{
283
+ name: "notified_at";
284
+ tableName: "hf_approval";
285
+ dataType: "date";
286
+ columnType: "PgTimestamp";
287
+ data: Date;
288
+ driverParam: string;
289
+ notNull: false;
290
+ hasDefault: false;
291
+ isPrimaryKey: false;
292
+ isAutoincrement: false;
293
+ hasRuntimeDefault: false;
294
+ enumValues: undefined;
295
+ baseColumn: never;
296
+ identity: undefined;
297
+ generated: undefined;
298
+ }, {}, {}>;
299
+ expiresAt: import("drizzle-orm/pg-core").PgColumn<{
300
+ name: "expires_at";
301
+ tableName: "hf_approval";
302
+ dataType: "date";
303
+ columnType: "PgTimestamp";
304
+ data: Date;
305
+ driverParam: string;
306
+ notNull: false;
307
+ hasDefault: false;
308
+ isPrimaryKey: false;
309
+ isAutoincrement: false;
310
+ hasRuntimeDefault: false;
311
+ enumValues: undefined;
312
+ baseColumn: never;
313
+ identity: undefined;
314
+ generated: undefined;
315
+ }, {}, {}>;
316
+ batchId: import("drizzle-orm/pg-core").PgColumn<{
317
+ name: "batch_id";
318
+ tableName: "hf_approval";
319
+ dataType: "string";
320
+ columnType: "PgText";
321
+ data: string;
322
+ driverParam: string;
323
+ notNull: false;
324
+ hasDefault: false;
325
+ isPrimaryKey: false;
326
+ isAutoincrement: false;
327
+ hasRuntimeDefault: false;
328
+ enumValues: [string, ...string[]];
329
+ baseColumn: never;
330
+ identity: undefined;
331
+ generated: undefined;
332
+ }, {}, {}>;
333
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
334
+ name: "created_at";
335
+ tableName: "hf_approval";
336
+ dataType: "date";
337
+ columnType: "PgTimestamp";
338
+ data: Date;
339
+ driverParam: string;
340
+ notNull: true;
341
+ hasDefault: true;
342
+ isPrimaryKey: false;
343
+ isAutoincrement: false;
344
+ hasRuntimeDefault: false;
345
+ enumValues: undefined;
346
+ baseColumn: never;
347
+ identity: undefined;
348
+ generated: undefined;
349
+ }, {}, {}>;
350
+ };
351
+ dialect: "pg";
352
+ }>;
@@ -0,0 +1,43 @@
1
+ import { bigint, index, jsonb, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
2
+ export const approvalStatuses = [
3
+ "pending",
4
+ "approved",
5
+ "rejected",
6
+ "expired",
7
+ "cancelled",
8
+ ];
9
+ /** Everything that can decide an approval; `sweep` is `reconcile()` step (5) expiring one. */
10
+ export const approvalVias = ["web", "telegram", "admin", "archive", "sweep"];
11
+ export const hfApproval = pgTable("hf_approval", {
12
+ id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
13
+ runId: text("run_id").notNull(),
14
+ key: text("key").notNull(),
15
+ // The attempt that created the row. Informational: the decision is fenced by the
16
+ // `hf_run` lock `decide()` takes, not by this column.
17
+ workflowId: text("workflow_id").notNull(),
18
+ type: text("type").notNull(),
19
+ recordType: text("record_type"),
20
+ recordId: text("record_id"),
21
+ draft: jsonb("draft"),
22
+ editedDraft: jsonb("edited_draft"),
23
+ status: text("status", { enum: approvalStatuses }).notNull(),
24
+ assigneeId: text("assignee_id"),
25
+ decidedBy: text("decided_by"),
26
+ decidedAt: timestamp("decided_at", { withTimezone: true, mode: "date" }),
27
+ decidedVia: text("decided_via", { enum: approvalVias }),
28
+ // The replay token: a second `decide()` carrying a key already on the row returns the
29
+ // first one's result and writes nothing.
30
+ decisionKey: text("decision_key"),
31
+ /** The attempt `decide()` enqueued to carry the run on; informational. */
32
+ resumeWorkflowId: text("resume_workflow_id"),
33
+ notifiedAt: timestamp("notified_at", { withTimezone: true, mode: "date" }),
34
+ expiresAt: timestamp("expires_at", { withTimezone: true, mode: "date" }),
35
+ batchId: text("batch_id"),
36
+ createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
37
+ .notNull()
38
+ .defaultNow(),
39
+ }, (t) => [
40
+ uniqueIndex("hf_approval_run_key_uq").on(t.runId, t.key),
41
+ // The inbox scan and `reconcile()` step (5)'s expiry scan, which both read by status.
42
+ index("hf_approval_status_idx").on(t.status, t.expiresAt),
43
+ ]);