@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,68 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { bigint, boolean, check, index, integer, jsonb, numeric, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
3
+ export const llmCallStatuses = ["started", "ok", "error", "abandoned"];
4
+ export const actionLogStatuses = ["started", "ok", "failed", "uncertain"];
5
+ export const hfBudgetPeriod = pgTable("hf_budget_period", {
6
+ period: text("period").primaryKey(),
7
+ budgetUsd: numeric("budget_usd", { precision: 12, scale: 4 }).notNull(),
8
+ spentUsd: numeric("spent_usd", { precision: 12, scale: 4 }).notNull().default("0"),
9
+ createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
10
+ .notNull()
11
+ .defaultNow(),
12
+ }, (t) => [check("hf_budget_period_spent_non_negative", sql `${t.spentUsd} >= 0`)]);
13
+ export const hfLlmCall = pgTable("hf_llm_call", {
14
+ id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
15
+ runId: text("run_id").notNull(),
16
+ key: text("key").notNull(),
17
+ // The attempt that wrote the row: informational once `ok`, load-bearing while
18
+ // `started` because the derived reservation only counts rows whose workflow_id
19
+ // still equals their run's current_workflow_id.
20
+ workflowId: text("workflow_id").notNull(),
21
+ period: text("period").notNull(),
22
+ stepName: text("step_name"),
23
+ promptName: text("prompt_name"),
24
+ promptHash: text("prompt_hash"),
25
+ inputHash: text("input_hash").notNull(),
26
+ model: text("model"),
27
+ status: text("status", { enum: llmCallStatuses }).notNull(),
28
+ input: jsonb("input"),
29
+ output: jsonb("output"),
30
+ tokensIn: integer("tokens_in"),
31
+ tokensOut: integer("tokens_out"),
32
+ estimatedCostUsd: numeric("estimated_cost_usd", { precision: 12, scale: 6 }).notNull(),
33
+ costUsd: numeric("cost_usd", { precision: 12, scale: 6 }),
34
+ possibleDoubleCharge: boolean("possible_double_charge").notNull().default(false),
35
+ latencyMs: integer("latency_ms"),
36
+ traceId: text("trace_id"),
37
+ startedAt: timestamp("started_at", { withTimezone: true, mode: "date" })
38
+ .notNull()
39
+ .defaultNow(),
40
+ finishedAt: timestamp("finished_at", { withTimezone: true, mode: "date" }),
41
+ }, (t) => [
42
+ uniqueIndex("hf_llm_call_run_key_uq").on(t.runId, t.key),
43
+ // The drift index. The reservation's covering index — (period, run_id,
44
+ // workflow_id) INCLUDE (estimated_cost_usd) WHERE status = 'started' — cannot
45
+ // be declared here: Drizzle has no builder for INCLUDE. It ships as a
46
+ // hand-written migration, and is invisible to `drizzle-kit generate`'s diff
47
+ // because the snapshot never learns about it.
48
+ index("hf_llm_call_period_status_idx").on(t.period, t.status),
49
+ ]);
50
+ export const hfActionLog = pgTable("hf_action_log", {
51
+ id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
52
+ runId: text("run_id").notNull(),
53
+ key: text("key").notNull(),
54
+ workflowId: text("workflow_id").notNull(),
55
+ channel: text("channel").notNull(),
56
+ idempotencyKey: text("idempotency_key").notNull(),
57
+ status: text("status", { enum: actionLogStatuses }).notNull(),
58
+ externalId: text("external_id"),
59
+ approvalId: bigint("approval_id", { mode: "number" }),
60
+ recordType: text("record_type"),
61
+ recordId: text("record_id"),
62
+ request: jsonb("request"),
63
+ response: jsonb("response"),
64
+ startedAt: timestamp("started_at", { withTimezone: true, mode: "date" })
65
+ .notNull()
66
+ .defaultNow(),
67
+ finishedAt: timestamp("finished_at", { withTimezone: true, mode: "date" }),
68
+ }, (t) => [uniqueIndex("hf_action_log_run_key_uq").on(t.runId, t.key)]);