@lunora/d1 1.0.0-alpha.4 → 1.0.0-alpha.41
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.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/dialect.d.mts +29 -27
- package/dist/dialect.d.ts +29 -27
- package/dist/dialect.mjs +1 -35
- package/dist/index.d.mts +141 -132
- package/dist/index.d.ts +141 -132
- package/dist/index.mjs +1 -7
- package/dist/packem_shared/D1Client-B9m0fFLr.mjs +1 -0
- package/dist/packem_shared/MigrationRunner-DvnPBDVT.mjs +2 -0
- package/dist/packem_shared/createD1CtxDb-oii8T0ys.mjs +1 -0
- package/dist/packem_shared/exportGlobalRows-CVw1hOdA.mjs +1 -0
- package/dist/packem_shared/facetGlobalColumn-T4arPSaV.mjs +1 -0
- package/dist/packem_shared/quoteIdentifier-CObIFRhb.mjs +1 -0
- package/dist/packem_shared/sqliteDialect-JvN44Hjf.mjs +1 -0
- package/package.json +5 -4
- package/dist/packem_shared/D1Client-DA3flo1o.mjs +0 -143
- package/dist/packem_shared/MigrationRunner-BkEwQ-Ya.mjs +0 -149
- package/dist/packem_shared/createD1CtxDb-BMR8J0dT.mjs +0 -14
- package/dist/packem_shared/exportGlobalRows-BGCPm_nA.mjs +0 -122
- package/dist/packem_shared/facetGlobalColumn-C6u_WMIY.mjs +0 -142
- package/dist/packem_shared/sqliteDialect-DqYnHPuu.mjs +0 -27
package/dist/dialect.d.mts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
2
|
+
* Canonical SQL identifier quoter shared by `@lunora/d1` and `@lunora/do`.
|
|
3
|
+
*
|
|
4
|
+
* Double-quotes a SQL identifier and escapes any embedded double quotes by
|
|
5
|
+
* doubling them (`"` → `""`) — the ANSI/SQLite/Postgres rule. This is a
|
|
6
|
+
* security-relevant primitive (it is the sole defense against identifier
|
|
7
|
+
* injection wherever a table/column name is spliced into raw SQL), so it must
|
|
8
|
+
* have exactly ONE definition rather than byte-identical copies that can drift.
|
|
9
|
+
*
|
|
10
|
+
* Like `shared/stable-key.ts`, it is deliberately **not** a package: `@lunora/d1`
|
|
11
|
+
* and `@lunora/do` sit on the same tier with no lower-level package to host it,
|
|
12
|
+
* so each imports this file by relative path and the bundler (packem/rollup)
|
|
13
|
+
* inlines it — no runtime dependency edge, duplicated only in emitted output.
|
|
14
|
+
* Keep it genuinely zero-dependency (relative/built-in imports only) or inlining
|
|
15
|
+
* breaks. Consumers must drop `outDir`/`rootDir` from their `tsconfig.json` (a
|
|
16
|
+
* set `rootDir` raises TS6059 for this out-of-package file under `tsc --noEmit`).
|
|
17
|
+
*/
|
|
18
|
+
declare const quoteIdentifier: (name: string) => string;
|
|
15
19
|
/** SQLite column type affinities Lunora emits. */
|
|
16
20
|
type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
|
|
17
|
-
/** Double-quote (and escape) a SQL identifier. */
|
|
18
|
-
declare const quoteIdentifier: (name: string) => string;
|
|
19
21
|
/**
|
|
20
|
-
* SQLite affinity for a column by its validator `kind`, chosen so the value the
|
|
21
|
-
* D1 layer serializes round-trips intact:
|
|
22
|
-
* - `boolean` → INTEGER (stored as 1/0)
|
|
23
|
-
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
24
|
-
* - `bytes` → BLOB
|
|
25
|
-
* - everything else → TEXT — string/id/literal, `bigint` (serialized as a
|
|
26
|
-
* decimal string), and object/array/record/union/any (JSON). A numeric affinity
|
|
27
|
-
* would coerce a numeric-looking string and corrupt the decode.
|
|
28
|
-
*/
|
|
22
|
+
* SQLite affinity for a column by its validator `kind`, chosen so the value the
|
|
23
|
+
* D1 layer serializes round-trips intact:
|
|
24
|
+
* - `boolean` → INTEGER (stored as 1/0)
|
|
25
|
+
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
26
|
+
* - `bytes` → BLOB
|
|
27
|
+
* - everything else → TEXT — string/id/literal, `bigint` (serialized as a
|
|
28
|
+
* decimal string), and object/array/record/union/any (JSON). A numeric affinity
|
|
29
|
+
* would coerce a numeric-looking string and corrupt the decode.
|
|
30
|
+
*/
|
|
29
31
|
declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
|
|
30
32
|
/** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
|
|
31
33
|
declare const frameworkColumnDdl: () => ReadonlyArray<string>;
|
|
32
34
|
/**
|
|
33
|
-
* Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
|
|
34
|
-
* physical `id` column, `_creationTime` to its own, every other field to itself.
|
|
35
|
-
*/
|
|
35
|
+
* Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
|
|
36
|
+
* physical `id` column, `_creationTime` to its own, every other field to itself.
|
|
37
|
+
*/
|
|
36
38
|
declare const columnRef: (field: string) => string;
|
|
37
39
|
/** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
|
|
38
40
|
declare const physicalIndexName: (tableName: string, indexName: string) => string;
|
package/dist/dialect.d.ts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
2
|
+
* Canonical SQL identifier quoter shared by `@lunora/d1` and `@lunora/do`.
|
|
3
|
+
*
|
|
4
|
+
* Double-quotes a SQL identifier and escapes any embedded double quotes by
|
|
5
|
+
* doubling them (`"` → `""`) — the ANSI/SQLite/Postgres rule. This is a
|
|
6
|
+
* security-relevant primitive (it is the sole defense against identifier
|
|
7
|
+
* injection wherever a table/column name is spliced into raw SQL), so it must
|
|
8
|
+
* have exactly ONE definition rather than byte-identical copies that can drift.
|
|
9
|
+
*
|
|
10
|
+
* Like `shared/stable-key.ts`, it is deliberately **not** a package: `@lunora/d1`
|
|
11
|
+
* and `@lunora/do` sit on the same tier with no lower-level package to host it,
|
|
12
|
+
* so each imports this file by relative path and the bundler (packem/rollup)
|
|
13
|
+
* inlines it — no runtime dependency edge, duplicated only in emitted output.
|
|
14
|
+
* Keep it genuinely zero-dependency (relative/built-in imports only) or inlining
|
|
15
|
+
* breaks. Consumers must drop `outDir`/`rootDir` from their `tsconfig.json` (a
|
|
16
|
+
* set `rootDir` raises TS6059 for this out-of-package file under `tsc --noEmit`).
|
|
17
|
+
*/
|
|
18
|
+
declare const quoteIdentifier: (name: string) => string;
|
|
15
19
|
/** SQLite column type affinities Lunora emits. */
|
|
16
20
|
type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
|
|
17
|
-
/** Double-quote (and escape) a SQL identifier. */
|
|
18
|
-
declare const quoteIdentifier: (name: string) => string;
|
|
19
21
|
/**
|
|
20
|
-
* SQLite affinity for a column by its validator `kind`, chosen so the value the
|
|
21
|
-
* D1 layer serializes round-trips intact:
|
|
22
|
-
* - `boolean` → INTEGER (stored as 1/0)
|
|
23
|
-
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
24
|
-
* - `bytes` → BLOB
|
|
25
|
-
* - everything else → TEXT — string/id/literal, `bigint` (serialized as a
|
|
26
|
-
* decimal string), and object/array/record/union/any (JSON). A numeric affinity
|
|
27
|
-
* would coerce a numeric-looking string and corrupt the decode.
|
|
28
|
-
*/
|
|
22
|
+
* SQLite affinity for a column by its validator `kind`, chosen so the value the
|
|
23
|
+
* D1 layer serializes round-trips intact:
|
|
24
|
+
* - `boolean` → INTEGER (stored as 1/0)
|
|
25
|
+
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
26
|
+
* - `bytes` → BLOB
|
|
27
|
+
* - everything else → TEXT — string/id/literal, `bigint` (serialized as a
|
|
28
|
+
* decimal string), and object/array/record/union/any (JSON). A numeric affinity
|
|
29
|
+
* would coerce a numeric-looking string and corrupt the decode.
|
|
30
|
+
*/
|
|
29
31
|
declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
|
|
30
32
|
/** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
|
|
31
33
|
declare const frameworkColumnDdl: () => ReadonlyArray<string>;
|
|
32
34
|
/**
|
|
33
|
-
* Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
|
|
34
|
-
* physical `id` column, `_creationTime` to its own, every other field to itself.
|
|
35
|
-
*/
|
|
35
|
+
* Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
|
|
36
|
+
* physical `id` column, `_creationTime` to its own, every other field to itself.
|
|
37
|
+
*/
|
|
36
38
|
declare const columnRef: (field: string) => string;
|
|
37
39
|
/** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
|
|
38
40
|
declare const physicalIndexName: (tableName: string, indexName: string) => string;
|
package/dist/dialect.mjs
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const sqlAffinityForKind = (kind) => {
|
|
3
|
-
switch (kind) {
|
|
4
|
-
case "boolean": {
|
|
5
|
-
return "INTEGER";
|
|
6
|
-
}
|
|
7
|
-
case "bytes": {
|
|
8
|
-
return "BLOB";
|
|
9
|
-
}
|
|
10
|
-
case "date":
|
|
11
|
-
case "number":
|
|
12
|
-
case "timestamp": {
|
|
13
|
-
return "REAL";
|
|
14
|
-
}
|
|
15
|
-
default: {
|
|
16
|
-
return "TEXT";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const frameworkColumnDdl = () => [
|
|
21
|
-
`${quoteIdentifier("id")} TEXT PRIMARY KEY`,
|
|
22
|
-
`${quoteIdentifier("_creationTime")} REAL NOT NULL`
|
|
23
|
-
];
|
|
24
|
-
const columnRef = (field) => {
|
|
25
|
-
if (field === "_id" || field === "id") {
|
|
26
|
-
return quoteIdentifier("id");
|
|
27
|
-
}
|
|
28
|
-
if (field === "_creationTime") {
|
|
29
|
-
return quoteIdentifier("_creationTime");
|
|
30
|
-
}
|
|
31
|
-
return quoteIdentifier(field);
|
|
32
|
-
};
|
|
33
|
-
const physicalIndexName = (tableName, indexName) => quoteIdentifier(`${tableName}_${indexName}`);
|
|
34
|
-
|
|
35
|
-
export { columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
|
|
1
|
+
import{quoteIdentifier as i}from"./packem_shared/quoteIdentifier-CObIFRhb.mjs";const t=e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BLOB";case"date":case"number":case"timestamp":return"REAL";default:return"TEXT"}},a=()=>[`${i("id")} TEXT PRIMARY KEY`,`${i("_creationTime")} REAL NOT NULL`],o=e=>e==="_id"||e==="id"?i("id"):e==="_creationTime"?i("_creationTime"):i(e),c=(e,r)=>i(`${e}_${r}`);export{o as columnRef,a as frameworkColumnDdl,c as physicalIndexName,i as quoteIdentifier,t as sqlAffinityForKind};
|
package/dist/index.d.mts
CHANGED
|
@@ -42,32 +42,42 @@ interface ImportResult {
|
|
|
42
42
|
inserted: Record<string, number>;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Return every `.global()` table in the schema, optionally narrowed by an
|
|
46
|
-
* allowlist. Shard-local tables are skipped here — they're handled by the DO
|
|
47
|
-
* helpers — so callers get a clean separation between the two storage planes.
|
|
48
|
-
*/
|
|
45
|
+
* Return every `.global()` table in the schema, optionally narrowed by an
|
|
46
|
+
* allowlist. Shard-local tables are skipped here — they're handled by the DO
|
|
47
|
+
* helpers — so callers get a clean separation between the two storage planes.
|
|
48
|
+
*/
|
|
49
49
|
declare const selectGlobalTables: (schema: SchemaLike, requested?: ReadonlyArray<string>) => string[];
|
|
50
50
|
interface ExportGlobalArgs {
|
|
51
51
|
batchSize?: number;
|
|
52
52
|
tables?: ReadonlyArray<string>;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* Yield rows from every requested `.global()` table in batches.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
55
|
+
* Yield rows from every requested `.global()` table in batches.
|
|
56
|
+
*
|
|
57
|
+
* Keyset-paginates on the physical primary key (`id` — every `.global()` table
|
|
58
|
+
* carries it, see `frameworkColumnDdl`): `WHERE "id" > ? ORDER BY "id" LIMIT ?`,
|
|
59
|
+
* carrying the last id forward. A plain `LIMIT/OFFSET` scan would be wrong here —
|
|
60
|
+
* SQLite gives no ordering guarantee for an unordered SELECT and each page is a
|
|
61
|
+
* separate query, so pages could overlap or skip rows (and any concurrent
|
|
62
|
+
* insert/delete would shift offsets and silently drop/duplicate rows in the
|
|
63
|
+
* snapshot). Keyset paging is deterministic under concurrent writes and avoids
|
|
64
|
+
* O(n^2) OFFSET scans on large tables.
|
|
65
|
+
*
|
|
66
|
+
* Tables are provisioned first (idempotent `CREATE … IF NOT EXISTS`): `.global()`
|
|
67
|
+
* tables are created lazily on first write, so a fresh deployment — or any table
|
|
68
|
+
* never written — would otherwise abort the stream with a raw `no such table`
|
|
69
|
+
* instead of exporting it as empty.
|
|
70
|
+
*/
|
|
61
71
|
declare const exportGlobalRows: (exec: SqlCtxExec, schema: SchemaLike, args: ExportGlobalArgs) => AsyncGenerator<ExportRow, void, undefined>;
|
|
62
72
|
interface ImportGlobalArgs {
|
|
63
73
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
* Optional direct exec handle to the same D1 database the writer targets.
|
|
75
|
+
* When supplied, the conflict pre-probe issues a single
|
|
76
|
+
* `SELECT 1 FROM <table> WHERE id = ? LIMIT 1` against the row's declared
|
|
77
|
+
* table instead of falling back to `writer.get(id)`, which scans every
|
|
78
|
+
* global table looking for the id. Strongly recommended for large schemas
|
|
79
|
+
* — the writer-fallback is O(N tables) per row.
|
|
80
|
+
*/
|
|
71
81
|
exec?: D1ExecLike;
|
|
72
82
|
rows: ReadonlyArray<ExportRow>;
|
|
73
83
|
startLine?: number;
|
|
@@ -77,20 +87,19 @@ interface D1ExecLike {
|
|
|
77
87
|
all: (sql: string, parameters: ReadonlyArray<unknown>) => Promise<Record<string, unknown>[]>;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
|
-
* Import rows into `.global()` tables via the schema-aware D1 writer. The
|
|
81
|
-
* writer rejects unknown ids on `insert` (the writer assigns one when `_id` is
|
|
82
|
-
* absent); we pre-probe each row's `_id` so a collision is reported as a
|
|
83
|
-
* conflict instead of bubbled as a UNIQUE error. Schema-failed rows surface in
|
|
84
|
-
* `errors`; the rest land.
|
|
85
|
-
*/
|
|
90
|
+
* Import rows into `.global()` tables via the schema-aware D1 writer. The
|
|
91
|
+
* writer rejects unknown ids on `insert` (the writer assigns one when `_id` is
|
|
92
|
+
* absent); we pre-probe each row's `_id` so a collision is reported as a
|
|
93
|
+
* conflict instead of bubbled as a UNIQUE error. Schema-failed rows surface in
|
|
94
|
+
* `errors`; the rest land.
|
|
95
|
+
*/
|
|
86
96
|
declare const importGlobalRows: (writer: DatabaseWriterLike, schema: SchemaLike, args: ImportGlobalArgs) => Promise<ImportResult>;
|
|
87
97
|
/**
|
|
88
|
-
* Minimal structural projection of `D1Database` to keep the adapter
|
|
89
|
-
* compatible with the real workers-types value as well as unit-test doubles.
|
|
90
|
-
*/
|
|
98
|
+
* Minimal structural projection of `D1Database` to keep the adapter
|
|
99
|
+
* compatible with the real workers-types value as well as unit-test doubles.
|
|
100
|
+
*/
|
|
91
101
|
interface D1DatabaseLike {
|
|
92
102
|
batch?: (statements: D1PreparedStatementLike[]) => Promise<unknown[]>;
|
|
93
|
-
exec?: (sql: string) => Promise<unknown>;
|
|
94
103
|
prepare: (sql: string) => D1PreparedStatementLike;
|
|
95
104
|
withSession: (bookmark?: string) => D1SessionLike;
|
|
96
105
|
}
|
|
@@ -131,67 +140,67 @@ declare class D1Session {
|
|
|
131
140
|
}>;
|
|
132
141
|
first<T = unknown>(sql: string, ...binds: unknown[]): Promise<T | null>;
|
|
133
142
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
* Returns the most recent bookmark known to the session, or `undefined`
|
|
144
|
+
* when D1 has not issued one yet.
|
|
145
|
+
*/
|
|
137
146
|
getBookmark(): string | undefined;
|
|
138
147
|
}
|
|
139
148
|
declare class D1Client {
|
|
140
149
|
private readonly db;
|
|
141
150
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
* SQL string -> prepared statement. Prepared statements are reusable in
|
|
152
|
+
* D1; preparing the same SQL twice forces the worker to round-trip the
|
|
153
|
+
* statement plan. Caching is per-instance so unit-test isolation holds.
|
|
154
|
+
* Bounded to {@link STMT_CACHE_CAPACITY} via LRU eviction.
|
|
155
|
+
*/
|
|
147
156
|
private readonly stmtCache;
|
|
148
157
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
* Lazily-built drizzle handle over the bare binding. Memoised so a single
|
|
159
|
+
* `D1Client` reuses the same dialect/session machinery across calls.
|
|
160
|
+
*/
|
|
152
161
|
private drizzleHandle;
|
|
153
162
|
constructor(database: D1DatabaseLike);
|
|
154
163
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
* Open a Sessions-API scoped session. Pass the bookmark forwarded by
|
|
165
|
+
* the client to opt into read-your-writes consistency.
|
|
166
|
+
*
|
|
167
|
+
* With no bookmark this is the first request of a session — there is no
|
|
168
|
+
* prior write to read, so we open with the explicit `"first-unconstrained"`
|
|
169
|
+
* constraint (Cloudflare's lowest-latency default: the first read may serve
|
|
170
|
+
* from any replica). Read-your-writes for sequenced requests still flows
|
|
171
|
+
* through the forwarded bookmark; a caller needing a strongly-consistent
|
|
172
|
+
* very-first read should pass `"first-primary"` as the bookmark instead.
|
|
173
|
+
*/
|
|
165
174
|
withSession(bookmark?: string): D1Session;
|
|
166
175
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
176
|
+
* Prepare a statement, reusing a cached one when the SQL text matches.
|
|
177
|
+
* `bind()` on a prepared statement returns a new bound statement and
|
|
178
|
+
* leaves the underlying prepared plan reusable, so cache hits are safe
|
|
179
|
+
* even when the previous caller already called `.bind(...).run()`.
|
|
180
|
+
*/
|
|
172
181
|
prepare(sql: string): D1PreparedStatementLike;
|
|
173
182
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
* Drizzle handle over the bare `env.DB` binding. Used for typed queries
|
|
184
|
+
* against generated `sqliteTable` schemas; does **not** participate in the
|
|
185
|
+
* D1 Sessions API (no bookmark pinning). For bookmark-scoped reads, use
|
|
186
|
+
* {@link drizzleSession} instead.
|
|
187
|
+
*/
|
|
179
188
|
get drizzle(): DrizzleD1Database<Record<string, unknown>>;
|
|
180
189
|
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
* Drizzle handle scoped to a D1 Sessions-API session. The bookmark, when
|
|
191
|
+
* supplied, opts into read-your-writes consistency for follow-up reads on
|
|
192
|
+
* the same session.
|
|
193
|
+
*
|
|
194
|
+
* A `D1DatabaseSession` exposes the same `prepare` / `batch` surface
|
|
195
|
+
* drizzle calls into, so a single `unknown` cast lets us treat the session
|
|
196
|
+
* as a `D1Database` for driver-construction purposes.
|
|
197
|
+
*/
|
|
189
198
|
drizzleSession(bookmark?: string): DrizzleD1Database<Record<string, unknown>>;
|
|
190
199
|
/**
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
* Atomic batch over the drizzle d1 driver. Mirrors `db.batch([...])`
|
|
201
|
+
* exactly; exposed on the client so callers don't need to hold a drizzle
|
|
202
|
+
* handle just to run a typed batch.
|
|
203
|
+
*/
|
|
195
204
|
batch<U extends BatchItem<"sqlite">, T extends Readonly<[U, ...U[]]>>(items: T): Promise<BatchResponse<T>>;
|
|
196
205
|
/** Direct access to the underlying binding (advanced use only). */
|
|
197
206
|
get raw(): D1DatabaseLike;
|
|
@@ -205,24 +214,24 @@ interface GlobalTableInfo {
|
|
|
205
214
|
interface GlobalTablePage {
|
|
206
215
|
columns: string[];
|
|
207
216
|
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
217
|
+
* Foreign-key columns (local column → referenced table) for tables that carry
|
|
218
|
+
* real SQL `REFERENCES` constraints — recovered from `PRAGMA foreign_key_list`.
|
|
219
|
+
* Schema `.global()` tables omit this (their refs come from `describeTables`);
|
|
220
|
+
* external tables (e.g. better-auth's `session`/`twoFactor`) expose it so the
|
|
221
|
+
* schema diagram can draw their global→global FK edges.
|
|
222
|
+
*/
|
|
214
223
|
refs?: Record<string, string>;
|
|
215
224
|
rows: Record<string, unknown>[];
|
|
216
225
|
total: number;
|
|
217
226
|
}
|
|
218
227
|
/**
|
|
219
|
-
* One equality constraint a facet-value click adds to the global browser's view:
|
|
220
|
-
* `column = value` (or `column IS NULL` when `value` is nullish). `column` is a
|
|
221
|
-
* displayed column name, validated against the table's columns and mapped to its
|
|
222
|
-
* physical column (`_id` → `id`) before it is quoted; `value` is the **raw stored
|
|
223
|
-
* value** the facet returned (a SQLite scalar), bound as a parameter and never
|
|
224
|
-
* interpolated. AND-combined with the other clauses.
|
|
225
|
-
*/
|
|
228
|
+
* One equality constraint a facet-value click adds to the global browser's view:
|
|
229
|
+
* `column = value` (or `column IS NULL` when `value` is nullish). `column` is a
|
|
230
|
+
* displayed column name, validated against the table's columns and mapped to its
|
|
231
|
+
* physical column (`_id` → `id`) before it is quoted; `value` is the **raw stored
|
|
232
|
+
* value** the facet returned (a SQLite scalar), bound as a parameter and never
|
|
233
|
+
* interpolated. AND-combined with the other clauses.
|
|
234
|
+
*/
|
|
226
235
|
interface GlobalFilterClause {
|
|
227
236
|
column: string;
|
|
228
237
|
value: unknown;
|
|
@@ -234,13 +243,13 @@ interface ReadGlobalTablePageOptions {
|
|
|
234
243
|
table: string;
|
|
235
244
|
}
|
|
236
245
|
/**
|
|
237
|
-
* Options for {@link facetGlobalColumn} — the read-only "what values does this
|
|
238
|
-
* column hold?" summary for the global (D1) browser. `column` is the displayed
|
|
239
|
-
* column to group by (validated and mapped to its physical column, never
|
|
240
|
-
* interpolated); `filters` mirrors {@link ReadGlobalTablePageOptions}'s eq
|
|
241
|
-
* constraints so the facet reflects the **active view** (the same rows the
|
|
242
|
-
* browser is previewing); `limit` caps the distinct values returned (clamped).
|
|
243
|
-
*/
|
|
246
|
+
* Options for {@link facetGlobalColumn} — the read-only "what values does this
|
|
247
|
+
* column hold?" summary for the global (D1) browser. `column` is the displayed
|
|
248
|
+
* column to group by (validated and mapped to its physical column, never
|
|
249
|
+
* interpolated); `filters` mirrors {@link ReadGlobalTablePageOptions}'s eq
|
|
250
|
+
* constraints so the facet reflects the **active view** (the same rows the
|
|
251
|
+
* browser is previewing); `limit` caps the distinct values returned (clamped).
|
|
252
|
+
*/
|
|
244
253
|
interface FacetGlobalColumnOptions {
|
|
245
254
|
column: string;
|
|
246
255
|
filters?: GlobalFilterClause[];
|
|
@@ -253,43 +262,43 @@ interface GlobalFacetValue {
|
|
|
253
262
|
value: unknown;
|
|
254
263
|
}
|
|
255
264
|
/**
|
|
256
|
-
* Payload of a {@link facetGlobalColumn} call: the top-N distinct `values` (each
|
|
257
|
-
* with a `count`) ordered by frequency, plus `truncated` — `true` when more
|
|
258
|
-
* distinct values existed beyond the cap, so the UI can say so rather than imply
|
|
259
|
-
* the list is exhaustive. Mirrors the shard browser's `FacetColumnResult`.
|
|
260
|
-
*/
|
|
265
|
+
* Payload of a {@link facetGlobalColumn} call: the top-N distinct `values` (each
|
|
266
|
+
* with a `count`) ordered by frequency, plus `truncated` — `true` when more
|
|
267
|
+
* distinct values existed beyond the cap, so the UI can say so rather than imply
|
|
268
|
+
* the list is exhaustive. Mirrors the shard browser's `FacetColumnResult`.
|
|
269
|
+
*/
|
|
261
270
|
interface GlobalFacetResult {
|
|
262
271
|
truncated: boolean;
|
|
263
272
|
values: GlobalFacetValue[];
|
|
264
273
|
}
|
|
265
274
|
/**
|
|
266
|
-
* List every browsable D1 table with its row count, ordered by name. Surfaces
|
|
267
|
-
* both the schema's `.global()` tables (provisioned first) and external tables
|
|
268
|
-
* (auth, etc.); internal/companion tables are excluded.
|
|
269
|
-
*/
|
|
275
|
+
* List every browsable D1 table with its row count, ordered by name. Surfaces
|
|
276
|
+
* both the schema's `.global()` tables (provisioned first) and external tables
|
|
277
|
+
* (auth, etc.); internal/companion tables are excluded.
|
|
278
|
+
*/
|
|
270
279
|
declare const listGlobalTables: (exec: SqlCtxExec, schema: SchemaLike) => Promise<GlobalTableInfo[]>;
|
|
271
280
|
/**
|
|
272
|
-
* Read a page of rows from one D1 table. The table is validated against the live
|
|
273
|
-
* browsable-table list before its name is interpolated, so this can't be coerced
|
|
274
|
-
* into reading an internal table or injecting SQL. `limit` is clamped to
|
|
275
|
-
* `[1, 500]`; `offset` floors at `0`. `filters` AND-narrows the page to rows
|
|
276
|
-
* matching each `column = value` eq constraint (a facet-value drill-down), bound
|
|
277
|
-
* through {@link buildEqPredicate} so they never inject SQL.
|
|
278
|
-
*/
|
|
281
|
+
* Read a page of rows from one D1 table. The table is validated against the live
|
|
282
|
+
* browsable-table list before its name is interpolated, so this can't be coerced
|
|
283
|
+
* into reading an internal table or injecting SQL. `limit` is clamped to
|
|
284
|
+
* `[1, 500]`; `offset` floors at `0`. `filters` AND-narrows the page to rows
|
|
285
|
+
* matching each `column = value` eq constraint (a facet-value drill-down), bound
|
|
286
|
+
* through {@link buildEqPredicate} so they never inject SQL.
|
|
287
|
+
*/
|
|
279
288
|
declare const readGlobalTablePage: (exec: SqlCtxExec, schema: SchemaLike, options: ReadGlobalTablePageOptions) => Promise<GlobalTablePage>;
|
|
280
289
|
/**
|
|
281
|
-
* Summarise the distinct values of one displayed column over the **active view**
|
|
282
|
-
* (the same eq `filters` the global browser is previewing) — the D1 twin of the
|
|
283
|
-
* shard browser's `facetColumn`. Read-only: a `SELECT col AS value, COUNT(*) AS
|
|
284
|
-
* count … GROUP BY col ORDER BY count DESC LIMIT N+1`, with the column validated
|
|
285
|
-
* against the table's displayed columns (typed 404 if unknown), mapped to its
|
|
286
|
-
* physical column, and quoted — never interpolated from caller input. The extra
|
|
287
|
-
* over-fetched row is dropped and surfaced as `truncated`. A sensitive column on
|
|
288
|
-
* an external (non-schema) table is never grouped — it collapses to a single
|
|
289
|
-
* redacted `•••` bucket — mirroring the page browser's value redaction so the
|
|
290
|
-
* facet can't leak credentials. The returned `value` is the raw stored scalar, so
|
|
291
|
-
* a click feeds it straight back as an eq filter.
|
|
292
|
-
*/
|
|
290
|
+
* Summarise the distinct values of one displayed column over the **active view**
|
|
291
|
+
* (the same eq `filters` the global browser is previewing) — the D1 twin of the
|
|
292
|
+
* shard browser's `facetColumn`. Read-only: a `SELECT col AS value, COUNT(*) AS
|
|
293
|
+
* count … GROUP BY col ORDER BY count DESC LIMIT N+1`, with the column validated
|
|
294
|
+
* against the table's displayed columns (typed 404 if unknown), mapped to its
|
|
295
|
+
* physical column, and quoted — never interpolated from caller input. The extra
|
|
296
|
+
* over-fetched row is dropped and surfaced as `truncated`. A sensitive column on
|
|
297
|
+
* an external (non-schema) table is never grouped — it collapses to a single
|
|
298
|
+
* redacted `•••` bucket — mirroring the page browser's value redaction so the
|
|
299
|
+
* facet can't leak credentials. The returned `value` is the raw stored scalar, so
|
|
300
|
+
* a click feeds it straight back as an eq filter.
|
|
301
|
+
*/
|
|
293
302
|
declare const facetGlobalColumn: (exec: SqlCtxExec, schema: SchemaLike, options: FacetGlobalColumnOptions) => Promise<GlobalFacetResult>;
|
|
294
303
|
interface Migration {
|
|
295
304
|
/** Human-readable name, e.g. `001_init` (used in logs). */
|
|
@@ -310,20 +319,20 @@ interface MigrationRunnerResult {
|
|
|
310
319
|
}[];
|
|
311
320
|
}
|
|
312
321
|
/**
|
|
313
|
-
* Sequentially applies pending migrations against a D1 database via the
|
|
314
|
-
* drizzle-orm/d1 driver. Each migration is hashed (SHA-256 over its SQL
|
|
315
|
-
* text); the hash is stored in `__drizzle_migrations`, so re-applying the
|
|
316
|
-
* same SQL under a different `version` is rejected and identical migrations
|
|
317
|
-
* are skipped idempotently.
|
|
318
|
-
*/
|
|
322
|
+
* Sequentially applies pending migrations against a D1 database via the
|
|
323
|
+
* drizzle-orm/d1 driver. Each migration is hashed (SHA-256 over its SQL
|
|
324
|
+
* text); the hash is stored in `__drizzle_migrations`, so re-applying the
|
|
325
|
+
* same SQL under a different `version` is rejected and identical migrations
|
|
326
|
+
* are skipped idempotently.
|
|
327
|
+
*/
|
|
319
328
|
declare class MigrationRunner {
|
|
320
329
|
private readonly client;
|
|
321
330
|
private readonly migrations;
|
|
322
331
|
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
332
|
+
* Accepts either a {@link D1Client} (preferred — gets typed batches +
|
|
333
|
+
* drizzle handle for free) or a raw `D1DatabaseLike` binding (wrapped on
|
|
334
|
+
* the caller's behalf so existing `@lunora/cli` callers keep working).
|
|
335
|
+
*/
|
|
327
336
|
constructor(database: D1Client | D1DatabaseLike, migrations: Migration[]);
|
|
328
337
|
run(): Promise<MigrationRunnerResult>;
|
|
329
338
|
private applyOne;
|
|
@@ -331,9 +340,9 @@ declare class MigrationRunner {
|
|
|
331
340
|
private assertUniqueSql;
|
|
332
341
|
}
|
|
333
342
|
/**
|
|
334
|
-
* The canonical SQLite dialect: column affinities, the shared SQLite value
|
|
335
|
-
* codec, `RETURNING` support (both D1 and `node:sqlite`), and `sqlite_master`
|
|
336
|
-
* table probing. The rest of the per-statement shaping is drizzle's.
|
|
337
|
-
*/
|
|
343
|
+
* The canonical SQLite dialect: column affinities, the shared SQLite value
|
|
344
|
+
* codec, `RETURNING` support (both D1 and `node:sqlite`), and `sqlite_master`
|
|
345
|
+
* table probing. The rest of the per-statement shaping is drizzle's.
|
|
346
|
+
*/
|
|
338
347
|
declare const sqliteDialect: SqlDialect;
|
|
339
348
|
export { D1Client, type D1ContextDatabaseOptions as D1CtxDbOptions, type D1DatabaseLike, type D1PreparedStatementLike, D1Session, type D1SessionLike, type ExportGlobalArgs, type FacetGlobalColumnOptions, type ExportRow as GlobalExportRow, type GlobalFacetResult, type GlobalFacetValue, type GlobalFilterClause, type ImportError as GlobalImportError, type ImportResult as GlobalImportResult, type GlobalTableInfo, type GlobalTablePage, type ImportGlobalArgs, type Migration, MigrationRunner, type MigrationRunnerResult, type ReadGlobalTablePageOptions, createD1ContextDatabase as createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, listGlobalTables, readD1CdcChanges, readGlobalTablePage, runD1AggregateMigrations, runD1CdcMigration, runD1GlobalTableMigrations, runD1RankMigrations, runD1SearchMigrations, selectGlobalTables, sqliteDialect, trimD1CdcChanges };
|