@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
package/dist/d1.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs D1 persistence and authentication from a Workers binding.
|
|
3
|
+
* Reservation statements use a D1 batch so the key and initial documents commit atomically.
|
|
4
|
+
*/
|
|
5
|
+
import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
6
|
+
import { drizzle } from "drizzle-orm/d1";
|
|
7
|
+
import { schema } from "./schema/sqlite.js";
|
|
8
|
+
import { DrizzleStore } from "./store.js";
|
|
9
|
+
import { DrizzleAuth } from "./auth.js";
|
|
10
|
+
/** Cloudflare Workers: `const { store, auth } = fromD1(env.DB)`. Migrations are applied with `wrangler d1 migrations apply`. */
|
|
11
|
+
export function fromD1(binding, fallbackAuth) {
|
|
12
|
+
const db = drizzle(binding, { schema });
|
|
13
|
+
return { db, store: new DrizzleStore(db, async (statements) => {
|
|
14
|
+
const dialect = new SQLiteAsyncDialect();
|
|
15
|
+
await binding.batch(statements.map(statement => {
|
|
16
|
+
const query = dialect.sqlToQuery(statement);
|
|
17
|
+
return binding.prepare(query.sql).bind(...query.params);
|
|
18
|
+
}));
|
|
19
|
+
}), auth: new DrizzleAuth(db, fallbackAuth) };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=d1.js.map
|
package/dist/d1.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"d1.js","sourceRoot":"","sources":["../src/d1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAgB,MAAM,WAAW,CAAC;AAEtD,gIAAgI;AAChI,MAAM,UAAU,MAAM,CAAC,OAAmB,EAAE,YAAsB;IAChE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,YAAY,CAAC,EAAE,EAAE,KAAK,EAAC,UAAU,EAAC,EAAE;YAC1D,MAAM,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACzC,MAAM,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;gBAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,WAAW,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SQL } from "drizzle-orm";
|
|
2
|
+
import type { IdempotencyRecord, Evaluation } from "@verdict-ai/core";
|
|
3
|
+
import { schema } from "./schema/sqlite.js";
|
|
4
|
+
import { schema as pgSchema } from "./schema/pg.js";
|
|
5
|
+
import type { SqliteDb } from "./store.js";
|
|
6
|
+
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
7
|
+
/** Each reservation accepts only its own driver and schema. */
|
|
8
|
+
export interface Dialect<Db = SqliteDb, Tables = typeof schema> {
|
|
9
|
+
tables: Tables;
|
|
10
|
+
reserve(db: Db, r: IdempotencyRecord, initial: Evaluation[], atomicBatch?: (statements: SQL[]) => Promise<void>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare const sqliteDialect: Dialect;
|
|
13
|
+
export type PgDb = PgDatabase<PgQueryResultHKT, typeof pgSchema>;
|
|
14
|
+
export declare const pgDialect: Dialect<PgDb, typeof pgSchema>;
|
package/dist/dialects.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Targets and reservations commit together; Postgres advisory locks require a fresh committed snapshot.
|
|
3
|
+
*/
|
|
4
|
+
import { storeOperation } from "./errors.js";
|
|
5
|
+
import { sql } from "drizzle-orm";
|
|
6
|
+
import { schema } from "./schema/sqlite.js";
|
|
7
|
+
import { schema as pgSchema } from "./schema/pg.js";
|
|
8
|
+
export const sqliteDialect = {
|
|
9
|
+
tables: schema,
|
|
10
|
+
async reserve(db, r, initial, atomicBatch) {
|
|
11
|
+
const statements = reservationStatements(r, initial, {
|
|
12
|
+
expand: sql `json_each(idempotency_keys.target_ids) as target`,
|
|
13
|
+
first: sql `json_extract(target_ids, '$[0]')`,
|
|
14
|
+
});
|
|
15
|
+
// why: D1 batches are atomic; local SQLite needs an immediate transaction to serialize writers.
|
|
16
|
+
await storeOperation("reserveIdempotency.sqlite", async () => {
|
|
17
|
+
if (atomicBatch)
|
|
18
|
+
await atomicBatch(statements);
|
|
19
|
+
else
|
|
20
|
+
db.transaction(tx => { for (const statement of statements)
|
|
21
|
+
tx.run(statement); }, { behavior: "immediate" });
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export const pgDialect = {
|
|
26
|
+
tables: pgSchema,
|
|
27
|
+
async reserve(db, r, initial) {
|
|
28
|
+
const tenant = r.tenantId ?? "";
|
|
29
|
+
const statements = reservationStatements(r, initial, {
|
|
30
|
+
expand: sql `jsonb_array_elements_text(idempotency_keys.target_ids) as target(value)`,
|
|
31
|
+
first: sql `target_ids->>0`,
|
|
32
|
+
});
|
|
33
|
+
await storeOperation("reserveIdempotency.postgres", () => db.transaction(async (tx) => {
|
|
34
|
+
// Get a fresh READ COMMITTED snapshot after competing reservations commit.
|
|
35
|
+
await tx.execute(sql `select pg_advisory_xact_lock(hashtextextended(${JSON.stringify([tenant, r.key])}, 0))`);
|
|
36
|
+
for (const statement of statements)
|
|
37
|
+
await tx.execute(statement);
|
|
38
|
+
}));
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
function reservationStatements(r, initial, fragments) {
|
|
42
|
+
const tenant = r.tenantId ?? "";
|
|
43
|
+
// Expiry uses the attempt timestamp so every adapter shares the engine clock.
|
|
44
|
+
// The reservation and initial documents commit together. Concurrent connections see
|
|
45
|
+
// either no reservation or a reservation whose targets already exist.
|
|
46
|
+
const statements = [sql `insert into idempotency_keys
|
|
47
|
+
(tenant_id, key, fingerprint, target_type, target_id, target_ids, created_at, expires_at)
|
|
48
|
+
values (${tenant}, ${r.key}, ${r.fingerprint}, ${r.targetType}, ${r.targetId ?? null}, ${r.evaluationIds ? JSON.stringify(r.evaluationIds) : null}, ${r.createdAt}, ${r.expiresAt})
|
|
49
|
+
on conflict (tenant_id, key) do update set fingerprint=excluded.fingerprint, target_type=excluded.target_type,
|
|
50
|
+
target_id=excluded.target_id, target_ids=excluded.target_ids, created_at=excluded.created_at, expires_at=excluded.expires_at
|
|
51
|
+
where idempotency_keys.expires_at <= ${r.createdAt}
|
|
52
|
+
or (idempotency_keys.target_type = 'evaluation' and not exists
|
|
53
|
+
(select 1 from evaluations where id = idempotency_keys.target_id and coalesce(tenant_id, '') = ${tenant}))
|
|
54
|
+
or (idempotency_keys.target_type = 'batch' and exists
|
|
55
|
+
(select 1 from ${fragments.expand} where not exists
|
|
56
|
+
(select 1 from evaluations where id = target.value and coalesce(tenant_id, '') = ${tenant})))`];
|
|
57
|
+
const owner = r.targetId ?? r.evaluationIds?.[0];
|
|
58
|
+
for (const e of initial) {
|
|
59
|
+
statements.push(sql `insert into evaluations (id, tenant_id, rubric_id, rubric_name, subject_name, status, doc, created_at, updated_at)
|
|
60
|
+
select ${e.id}, ${e.tenantId ?? null}, ${e.rubricId ?? null}, ${e.rubric.name}, ${e.subject.name ?? null}, ${e.status}, ${JSON.stringify(e)}, ${e.createdAt}, ${e.updatedAt}
|
|
61
|
+
where exists (select 1 from idempotency_keys where tenant_id=${tenant} and key=${r.key}
|
|
62
|
+
and coalesce(target_id, ${fragments.first})=${owner ?? null})`);
|
|
63
|
+
}
|
|
64
|
+
return statements;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=dialects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialects.js","sourceRoot":"","sources":["../src/dialects.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AASpD,MAAM,CAAC,MAAM,aAAa,GAAY;IACpC,MAAM,EAAE,MAAM;IACd,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW;QACvC,MAAM,UAAU,GAAG,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE;YACnD,MAAM,EAAE,GAAG,CAAA,kDAAkD;YAC7D,KAAK,EAAE,GAAG,CAAA,kCAAkC;SAC7C,CAAC,CAAC;QACH,gGAAgG;QAChG,MAAM,cAAc,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;YAC3D,IAAI,WAAW;gBAAE,MAAM,WAAW,CAAC,UAAU,CAAC,CAAC;;gBAC1C,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,SAAS,IAAI,UAAU;oBAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;QACnH,CAAC,CAAC,CAAC;IAEL,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAmC;IACvD,MAAM,EAAE,QAAQ;IAChB,KAAK,CAAC,OAAO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CAAC,MAAM;+FACoD,MAAM,KAAK,CAAC,CAAC;IAC1G,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAA;iBACN,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,IAAI,IAAI,KAAK,CAAC,CAAC,QAAQ,IAAI,IAAI,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS;uEAC5G,MAAM,YAAY,CAAC,CAAC,GAAG;oCAC1D,SAAS,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translates stored documents and evaluations into database projections.
|
|
3
|
+
* Document JSON remains authoritative; indexed rows derive from the same evaluation snapshot.
|
|
4
|
+
*/
|
|
5
|
+
import type { Evaluation, StoredRubric } from "@verdict-ai/core";
|
|
6
|
+
/** Documents originate in core and are stored intact; Drizzle's JSON column is deliberately schema agnostic. */
|
|
7
|
+
export declare function readDocument<T extends Evaluation | StoredRubric>(doc: unknown): T;
|
|
8
|
+
/** Derives indexed evaluation columns from the authoritative document; performs no I/O. */
|
|
9
|
+
export declare function evaluationRow(e: Evaluation): {
|
|
10
|
+
id: string;
|
|
11
|
+
tenantId: string | null;
|
|
12
|
+
rubricId: string | null;
|
|
13
|
+
rubricName: string;
|
|
14
|
+
subjectName: string | null;
|
|
15
|
+
status: import("@verdict-ai/core").EvaluationStatus;
|
|
16
|
+
score: number | null;
|
|
17
|
+
grade: string | null;
|
|
18
|
+
passed: boolean | null;
|
|
19
|
+
pendingHuman: number;
|
|
20
|
+
decisionCalls: number;
|
|
21
|
+
llmCalls: number;
|
|
22
|
+
inputTokens: number;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
doc: {
|
|
25
|
+
job?: {
|
|
26
|
+
attempts: number;
|
|
27
|
+
maxAttempts: number;
|
|
28
|
+
lastError?: string;
|
|
29
|
+
nextAttemptAt?: string;
|
|
30
|
+
deadLettered?: boolean;
|
|
31
|
+
};
|
|
32
|
+
id: string;
|
|
33
|
+
tenantId?: string;
|
|
34
|
+
idempotencyKey?: string;
|
|
35
|
+
rubricId?: string;
|
|
36
|
+
rubric: import("@verdict-ai/core").Rubric;
|
|
37
|
+
subject: import("@verdict-ai/core").Subject;
|
|
38
|
+
evidence: import("@verdict-ai/core").Evidence[];
|
|
39
|
+
status: import("@verdict-ai/core").EvaluationStatus;
|
|
40
|
+
criteria: import("@verdict-ai/core").CriterionResult[];
|
|
41
|
+
aggregate: import("@verdict-ai/core").AggregateResult;
|
|
42
|
+
pendingTasks: Array<{
|
|
43
|
+
criterionId: string;
|
|
44
|
+
raterId?: string;
|
|
45
|
+
allowedRaters?: string[];
|
|
46
|
+
instructions?: string;
|
|
47
|
+
}>;
|
|
48
|
+
checks?: Array<{
|
|
49
|
+
id: string;
|
|
50
|
+
probability: number | null;
|
|
51
|
+
passed: boolean;
|
|
52
|
+
action: "abort" | "fail" | "flag";
|
|
53
|
+
message?: string;
|
|
54
|
+
error?: string;
|
|
55
|
+
}>;
|
|
56
|
+
error?: string;
|
|
57
|
+
usage: {
|
|
58
|
+
decisionCalls: number;
|
|
59
|
+
llmCalls: number;
|
|
60
|
+
inputTokens: number;
|
|
61
|
+
outputTokens: number;
|
|
62
|
+
durationMs: number;
|
|
63
|
+
};
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
webhook?: string;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
};
|
|
69
|
+
createdAt: string;
|
|
70
|
+
updatedAt: string;
|
|
71
|
+
};
|
|
72
|
+
/** Derives analytics rows from criterion ratings; performs no I/O. */
|
|
73
|
+
export declare function ratingRows(e: Evaluation): {
|
|
74
|
+
id: string;
|
|
75
|
+
evaluationId: string;
|
|
76
|
+
tenantId: string | null;
|
|
77
|
+
rubricId: string | null;
|
|
78
|
+
criterionId: string;
|
|
79
|
+
raterId: string;
|
|
80
|
+
judgeType: "decision" | "human" | "llm" | "benchmark" | "panel";
|
|
81
|
+
status: import("@verdict-ai/core").RatingStatus;
|
|
82
|
+
score: number | null;
|
|
83
|
+
normalized: number | null;
|
|
84
|
+
confidence: number | null;
|
|
85
|
+
model: string | null;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
}[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Documents originate in core and are stored intact; Drizzle's JSON column is deliberately schema agnostic. */
|
|
2
|
+
export function readDocument(doc) {
|
|
3
|
+
return doc;
|
|
4
|
+
}
|
|
5
|
+
/** Derives indexed evaluation columns from the authoritative document; performs no I/O. */
|
|
6
|
+
export function evaluationRow(e) {
|
|
7
|
+
return {
|
|
8
|
+
id: e.id,
|
|
9
|
+
tenantId: e.tenantId ?? null,
|
|
10
|
+
rubricId: e.rubricId ?? null,
|
|
11
|
+
rubricName: e.rubric.name,
|
|
12
|
+
subjectName: e.subject.name ?? null,
|
|
13
|
+
status: e.status,
|
|
14
|
+
score: e.aggregate.score ?? null,
|
|
15
|
+
grade: e.aggregate.grade ?? null,
|
|
16
|
+
passed: e.aggregate.passed ?? null,
|
|
17
|
+
pendingHuman: e.pendingTasks.length,
|
|
18
|
+
decisionCalls: e.usage.decisionCalls,
|
|
19
|
+
llmCalls: e.usage.llmCalls,
|
|
20
|
+
inputTokens: e.usage.inputTokens,
|
|
21
|
+
durationMs: e.usage.durationMs,
|
|
22
|
+
doc: { ...e },
|
|
23
|
+
createdAt: e.createdAt,
|
|
24
|
+
updatedAt: e.updatedAt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Derives analytics rows from criterion ratings; performs no I/O. */
|
|
28
|
+
export function ratingRows(e) {
|
|
29
|
+
return e.criteria.flatMap(c => c.ratings.map(r => ({
|
|
30
|
+
id: r.id,
|
|
31
|
+
evaluationId: e.id,
|
|
32
|
+
tenantId: e.tenantId ?? null,
|
|
33
|
+
rubricId: e.rubricId ?? null,
|
|
34
|
+
criterionId: c.criterionId,
|
|
35
|
+
raterId: r.raterId,
|
|
36
|
+
judgeType: r.judgeType,
|
|
37
|
+
status: r.status,
|
|
38
|
+
score: r.score ?? null,
|
|
39
|
+
normalized: r.normalized ?? null,
|
|
40
|
+
confidence: r.confidence ?? null,
|
|
41
|
+
model: (r.raw && "model" in r.raw ? r.raw.model : undefined) ?? null,
|
|
42
|
+
createdAt: r.createdAt,
|
|
43
|
+
})));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAMA,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAAsC,GAAY;IAC5E,OAAO,GAAQ,CAAC;AAClB,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,aAAa,CAAC,CAAa;IACzC,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;QAC5B,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;QAC5B,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI;QACzB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI;QACnC,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI;QAChC,KAAK,EA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CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI;QACpE,SAAS,EAAE,CAAC,CAAC,SAAS;KACvB,CAAC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A persistence failure retains the operation and original driver cause for recovery. */
|
|
2
|
+
export declare class StoreError extends Error {
|
|
3
|
+
readonly operation: string;
|
|
4
|
+
constructor(operation: string, cause: unknown);
|
|
5
|
+
}
|
|
6
|
+
/** Keep driver details as a cause while exposing a stable persistence error contract. */
|
|
7
|
+
export declare function storeOperation<T>(operation: string, run: () => PromiseLike<T> | T): Promise<T>;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** A persistence failure retains the operation and original driver cause for recovery. */
|
|
2
|
+
export class StoreError extends Error {
|
|
3
|
+
operation;
|
|
4
|
+
constructor(operation, cause) {
|
|
5
|
+
super(`Store ${operation} failed: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
6
|
+
this.operation = operation;
|
|
7
|
+
this.name = "StoreError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Keep driver details as a cause while exposing a stable persistence error contract. */
|
|
11
|
+
export async function storeOperation(operation, run) {
|
|
12
|
+
try {
|
|
13
|
+
return await run();
|
|
14
|
+
}
|
|
15
|
+
catch (cause) {
|
|
16
|
+
if (cause instanceof StoreError)
|
|
17
|
+
throw cause;
|
|
18
|
+
throw new StoreError(operation, cause);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,OAAO,UAAW,SAAQ,KAAK;IACP;IAA5B,YAA4B,SAAiB,EAAE,KAAc;QAC3D,KAAK,CAAC,SAAS,SAAS,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAD/E,cAAS,GAAT,SAAS,CAAQ;QAE3C,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,SAAiB,EAAE,GAA6B;IACtF,IAAI,CAAC;QAAC,OAAO,MAAM,GAAG,EAAE,CAAC;IAAC,CAAC;IAC3B,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,KAAK,YAAY,UAAU;YAAE,MAAM,KAAK,CAAC;QAC7C,MAAM,IAAI,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exports the package entry points without starting services.
|
|
3
|
+
* Consumers choose their runtime adapters explicitly; importing types must not open network or database connections.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./schema/sqlite.js";
|
|
6
|
+
export { DrizzleStore, type SqliteDb } from "./store.js";
|
|
7
|
+
export { DrizzleAuth, sha256Hex, type KeyAuth } from "./auth.js";
|
|
8
|
+
export { fromD1 } from "./d1.js";
|
|
9
|
+
export { StoreError } from "./errors.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exports the package entry points without starting services.
|
|
3
|
+
* Consumers choose their runtime adapters explicitly; importing types must not open network or database connections.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./schema/sqlite.js";
|
|
6
|
+
export { DrizzleStore } from "./store.js";
|
|
7
|
+
export { DrizzleAuth, sha256Hex } from "./auth.js";
|
|
8
|
+
export { fromD1 } from "./d1.js";
|
|
9
|
+
// Node-only helpers (better-sqlite3, fs) live in "./sqlite.js" and are imported lazily by callers:
|
|
10
|
+
// const { fromSqliteFile } = await import("@verdict-ai/db/sqlite");
|
|
11
|
+
export { StoreError } from "./errors.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,YAAY,EAAiB,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,mGAAmG;AACnG,sEAAsE;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|