@verdict-ai/db 0.0.0-stage → 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.
- package/LICENSE +9 -0
- package/README.md +21 -2
- package/dist/auth.d.ts +34 -0
- package/dist/auth.js +80 -0
- package/dist/auth.js.map +1 -0
- package/dist/d1.d.ts +1034 -0
- package/dist/d1.js +21 -0
- package/dist/d1.js.map +1 -0
- package/dist/dialects.d.ts +14 -0
- package/dist/dialects.js +66 -0
- package/dist/dialects.js.map +1 -0
- package/dist/documents.d.ts +87 -0
- package/dist/documents.js +45 -0
- package/dist/documents.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/postgres.d.ts +1925 -0
- package/dist/postgres.js +63 -0
- package/dist/postgres.js.map +1 -0
- package/dist/queries.d.ts +31 -0
- package/dist/queries.js +68 -0
- package/dist/queries.js.map +1 -0
- package/dist/schema/pg.d.ts +1892 -0
- package/dist/schema/pg.js +90 -0
- package/dist/schema/pg.js.map +1 -0
- package/dist/schema/sqlite.d.ts +2050 -0
- package/dist/schema/sqlite.js +90 -0
- package/dist/schema/sqlite.js.map +1 -0
- package/dist/sqlite.d.ts +25 -0
- package/dist/sqlite.js +64 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/store.d.ts +47 -0
- package/dist/store.js +149 -0
- package/dist/store.js.map +1 -0
- package/drizzle/0000_init.sql +66 -0
- package/drizzle/0001_idempotency.sql +12 -0
- package/drizzle/meta/0000_snapshot.json +452 -0
- package/drizzle/meta/0001_snapshot.json +527 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle/pg/0000_init.sql +78 -0
- package/drizzle/pg/meta/0000_snapshot.json +605 -0
- package/drizzle/pg/meta/_journal.json +13 -0
- package/package.json +81 -3
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines Postgres document tables and query indexes.
|
|
3
|
+
* JSON documents hold full domain state; tenant and key indexes support scoped lookups and reservations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Drizzle schema — Postgres dialect; mirrors the SQLite table plan.
|
|
7
|
+
*
|
|
8
|
+
* Design: documents (rubric / evaluation) are stored as JSON blobs — their shapes are owned by the zod schemas in
|
|
9
|
+
* @verdict-ai/core and evolve quickly. Columns exist only for what we query or report on: tenant, status, score, timestamps,
|
|
10
|
+
* and a denormalized `ratings` table for calibration / inter-rater analytics.
|
|
11
|
+
*/
|
|
12
|
+
import { index, integer, doublePrecision, boolean, jsonb, pgTable, text, uniqueIndex } from "drizzle-orm/pg-core";
|
|
13
|
+
export const rubrics = pgTable("rubrics", {
|
|
14
|
+
id: text("id").primaryKey(),
|
|
15
|
+
tenantId: text("tenant_id"),
|
|
16
|
+
name: text("name").notNull(),
|
|
17
|
+
version: text("version").notNull().default("1"),
|
|
18
|
+
/** Full StoredRubric JSON (zod-validated by core). */
|
|
19
|
+
doc: jsonb("doc").notNull().$type(),
|
|
20
|
+
createdAt: text("created_at").notNull(),
|
|
21
|
+
updatedAt: text("updated_at").notNull(),
|
|
22
|
+
}, (t) => [index("rubrics_tenant_created").on(t.tenantId, t.createdAt)]);
|
|
23
|
+
export const evaluations = pgTable("evaluations", {
|
|
24
|
+
id: text("id").primaryKey(),
|
|
25
|
+
tenantId: text("tenant_id"),
|
|
26
|
+
rubricId: text("rubric_id"),
|
|
27
|
+
rubricName: text("rubric_name").notNull(),
|
|
28
|
+
subjectName: text("subject_name"),
|
|
29
|
+
status: text("status").notNull(), // queued | running | pending_human | completed | failed
|
|
30
|
+
score: doublePrecision("score"),
|
|
31
|
+
grade: text("grade"),
|
|
32
|
+
passed: boolean("passed"),
|
|
33
|
+
pendingHuman: integer("pending_human").notNull().default(0),
|
|
34
|
+
decisionCalls: integer("decision_calls").notNull().default(0),
|
|
35
|
+
llmCalls: integer("llm_calls").notNull().default(0),
|
|
36
|
+
inputTokens: integer("input_tokens").notNull().default(0),
|
|
37
|
+
durationMs: integer("duration_ms").notNull().default(0),
|
|
38
|
+
/** Full Evaluation JSON (frozen rubric, evidence, criteria, ratings). */
|
|
39
|
+
doc: jsonb("doc").notNull().$type(),
|
|
40
|
+
createdAt: text("created_at").notNull(),
|
|
41
|
+
updatedAt: text("updated_at").notNull(),
|
|
42
|
+
}, (t) => [
|
|
43
|
+
index("evaluations_tenant_created").on(t.tenantId, t.createdAt),
|
|
44
|
+
index("evaluations_rubric_created").on(t.rubricId, t.createdAt),
|
|
45
|
+
index("evaluations_tenant_status").on(t.tenantId, t.status),
|
|
46
|
+
]);
|
|
47
|
+
/** One row per rating — lets you ask "how do Jev's confidences track human agreement for rubric X" with plain SQL. */
|
|
48
|
+
export const ratings = pgTable("ratings", {
|
|
49
|
+
id: text("id").primaryKey(),
|
|
50
|
+
evaluationId: text("evaluation_id").notNull(),
|
|
51
|
+
tenantId: text("tenant_id"),
|
|
52
|
+
rubricId: text("rubric_id"),
|
|
53
|
+
criterionId: text("criterion_id").notNull(),
|
|
54
|
+
raterId: text("rater_id").notNull(),
|
|
55
|
+
judgeType: text("judge_type").notNull(), // decision | llm | human | benchmark | panel
|
|
56
|
+
status: text("status").notNull(), // scored | pending | error
|
|
57
|
+
score: doublePrecision("score"),
|
|
58
|
+
normalized: doublePrecision("normalized"),
|
|
59
|
+
confidence: doublePrecision("confidence"),
|
|
60
|
+
model: text("model"),
|
|
61
|
+
createdAt: text("created_at").notNull(),
|
|
62
|
+
}, (t) => [
|
|
63
|
+
index("ratings_evaluation").on(t.evaluationId),
|
|
64
|
+
index("ratings_rubric_criterion").on(t.rubricId, t.criterionId),
|
|
65
|
+
index("ratings_tenant_judge").on(t.tenantId, t.judgeType),
|
|
66
|
+
]);
|
|
67
|
+
export const apiKeys = pgTable("api_keys", {
|
|
68
|
+
id: text("id").primaryKey(),
|
|
69
|
+
tenantId: text("tenant_id").notNull(),
|
|
70
|
+
name: text("name").notNull(),
|
|
71
|
+
/** sha256(hex) of the plaintext key; the plaintext is shown once at creation. */
|
|
72
|
+
keyHash: text("key_hash").notNull(),
|
|
73
|
+
/** First 8 chars of the key, for display (`vk_live_ab12…`). */
|
|
74
|
+
prefix: text("prefix").notNull(),
|
|
75
|
+
createdAt: text("created_at").notNull(),
|
|
76
|
+
lastUsedAt: text("last_used_at"),
|
|
77
|
+
revokedAt: text("revoked_at"),
|
|
78
|
+
}, (t) => [uniqueIndex("api_keys_hash").on(t.keyHash), index("api_keys_tenant").on(t.tenantId)]);
|
|
79
|
+
export const idempotencyKeys = pgTable("idempotency_keys", {
|
|
80
|
+
tenantId: text("tenant_id"),
|
|
81
|
+
key: text("key").notNull(),
|
|
82
|
+
fingerprint: text("fingerprint").notNull(),
|
|
83
|
+
targetType: text("target_type").notNull().$type(),
|
|
84
|
+
targetId: text("target_id"),
|
|
85
|
+
targetIds: jsonb("target_ids").$type(),
|
|
86
|
+
createdAt: text("created_at").notNull(),
|
|
87
|
+
expiresAt: text("expires_at").notNull(),
|
|
88
|
+
}, t => [uniqueIndex("idempotency_keys_tenant_key").on(t.tenantId, t.key)]);
|
|
89
|
+
export const schema = { rubrics, evaluations, ratings, apiKeys, idempotencyKeys };
|
|
90
|
+
//# sourceMappingURL=pg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.js","sourceRoot":"","sources":["../../src/schema/pg.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAC5B,SAAS,EACT;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,QAAQ,EAAE,IAAI,C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