@lunora/hyperdrive 1.0.0-alpha.14 → 1.0.0-alpha.141
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/README.md +58 -6
- package/dist/global.d.mts +136 -46
- package/dist/global.d.ts +136 -46
- package/dist/global.mjs +1 -9
- package/dist/index.d.mts +124 -175
- package/dist/index.d.ts +124 -175
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/buildMysqlExec-BTmXrDGL.mjs +1 -0
- package/dist/packem_shared/createHyperdrive-DEXMfGd0.mjs +1 -0
- package/dist/packem_shared/createPgVectorIndex-CSNnG065.mjs +1 -0
- package/dist/packem_shared/mysqlDialect-WuCGPd2_.mjs +1 -0
- package/dist/packem_shared/projectSourceRow-DN8ywPRl.mjs +1 -0
- package/dist/packem_shared/types.d-DpWhWTrT.d.mts +150 -0
- package/dist/packem_shared/types.d-DpWhWTrT.d.ts +150 -0
- package/package.json +5 -3
- package/dist/packem_shared/buildMysqlExec-DBbCjyq3.mjs +0 -23
- package/dist/packem_shared/createHyperdrive-DD8GoDZo.mjs +0 -36
- package/dist/packem_shared/mysqlDialect-oNhZ58s8.mjs +0 -102
- package/dist/packem_shared/projectSourceRow-DtKuMRIm.mjs +0 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,180 +1,81 @@
|
|
|
1
|
+
import { H as HyperdriveLike, a as HyperdriveConnection, M as Mysql2Like, S as SqlClient, N as NodePgLike, P as PostgresJsLike } from "./packem_shared/types.d-DpWhWTrT.mjs";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* deliberately
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The connection config surfaced by {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive}: the raw
|
|
39
|
-
* `connectionString` plus the discrete parts, ready to hand to a driver.
|
|
40
|
-
*/
|
|
41
|
-
interface HyperdriveConnection {
|
|
42
|
-
/** Database name. */
|
|
43
|
-
database: string;
|
|
44
|
-
/** Host (Hyperdrive's local proxy). */
|
|
45
|
-
host: string;
|
|
46
|
-
/** Password. */
|
|
47
|
-
password: string;
|
|
48
|
-
/** Port. */
|
|
49
|
-
port: number;
|
|
50
|
-
/** User. */
|
|
51
|
-
user: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The driver-agnostic SQL surface bound to `ctx.sql` on **`ActionCtx` only**.
|
|
55
|
-
*
|
|
56
|
-
* This is the exact type the generated ctx imports as
|
|
57
|
-
* `import("@lunora/hyperdrive").SqlClient`. Keep the name and shape stable — the
|
|
58
|
-
* codegen ctx wiring (Phase 1) depends on it.
|
|
59
|
-
*
|
|
60
|
-
* It is intentionally minimal — a single parameterised `query` — so it maps onto
|
|
61
|
-
* `postgres` (postgres.js), `pg` (node-postgres) and `mysql2` alike via the
|
|
62
|
-
* {@link import("./create-hyperdrive").fromPostgresJs | fromPostgresJs} /
|
|
63
|
-
* {@link import("./create-hyperdrive").fromNodePg | fromNodePg} /
|
|
64
|
-
* {@link import("./create-hyperdrive").fromMysql2 | fromMysql2} adapters. Use
|
|
65
|
-
* positional placeholders that match your driver (`$1, $2` for Postgres, `?` for
|
|
66
|
-
* MySQL); the package does not rewrite SQL.
|
|
67
|
-
*
|
|
68
|
-
* Reminder (also on the emitted JSDoc): non-deterministic, action-only,
|
|
69
|
-
* non-reactive — writes here are not tracked by Lunora live queries.
|
|
70
|
-
*/
|
|
71
|
-
interface SqlClient {
|
|
72
|
-
/**
|
|
73
|
-
* Run a parameterised SQL statement and return the result rows.
|
|
74
|
-
* @param text SQL text with driver-native positional placeholders.
|
|
75
|
-
* @param params Bound parameter values, positionally matched to `text`.
|
|
76
|
-
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
77
|
-
* return no rows).
|
|
78
|
-
*/
|
|
79
|
-
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
|
|
83
|
-
* `query` method `fromNodePg` calls is required, kept structural for testing.
|
|
84
|
-
*/
|
|
85
|
-
interface NodePgLike {
|
|
86
|
-
query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
|
|
87
|
-
rows: unknown[];
|
|
88
|
-
}>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Structural projection of a `postgres` (postgres.js) tagged-template client.
|
|
92
|
-
* The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
|
|
93
|
-
* full control of the parameter list.
|
|
94
|
-
*/
|
|
95
|
-
interface PostgresJsLike {
|
|
96
|
-
unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
|
|
100
|
-
* `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
|
|
101
|
-
* element as the rows.
|
|
102
|
-
*/
|
|
103
|
-
interface Mysql2Like {
|
|
104
|
-
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Surface a Cloudflare Hyperdrive binding as a connection ready to feed a
|
|
108
|
-
* user-supplied SQL driver.
|
|
109
|
-
*
|
|
110
|
-
* `@lunora/hyperdrive` deliberately **bundles no driver** — `postgres`, `pg` and
|
|
111
|
-
* `mysql2` are heavy and the choice is the user's (they are `optional`
|
|
112
|
-
* `peerDependencies`, never `dependencies`). This factory's only job is to lift
|
|
113
|
-
* the binding's connection details out; the user constructs their own driver
|
|
114
|
-
* from `connectionString` and wraps it with one of the {@link fromPostgresJs} /
|
|
115
|
-
* {@link fromNodePg} / {@link fromMysql2} adapters to get a {@link SqlClient}.
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* import { createHyperdrive, fromPostgresJs } from "@lunora/hyperdrive";
|
|
119
|
-
* import postgres from "postgres";
|
|
120
|
-
*
|
|
121
|
-
* // inside an action (never a query/mutation):
|
|
122
|
-
* const { connectionString } = createHyperdrive(env.HYPERDRIVE);
|
|
123
|
-
* ctx.sql = fromPostgresJs(postgres(connectionString));
|
|
124
|
-
* const rows = await ctx.sql.query("select id from users where org = $1", [orgId]);
|
|
125
|
-
* ```
|
|
126
|
-
* @remarks
|
|
127
|
-
* Hyperdrive talks to an **external** database Lunora has no visibility into.
|
|
128
|
-
* Queries through `ctx.sql` are non-deterministic (action-only — enforced by the
|
|
129
|
-
* `hyperdrive_outside_action` advisor lint) and external writes are NOT tracked
|
|
130
|
-
* by Lunora live queries: subscriptions will not re-run when external rows
|
|
131
|
-
* change. Use Hyperdrive to *integrate* an existing DB from an action; if you
|
|
132
|
-
* want that data to be reactive, write a projection of it into a `defineSchema`
|
|
133
|
-
* DO/D1 table.
|
|
134
|
-
* @param binding The `env.HYPERDRIVE` binding (or a structural double).
|
|
135
|
-
* @returns The raw `connectionString` plus the discrete connection parts.
|
|
136
|
-
*/
|
|
3
|
+
* Surface a Cloudflare Hyperdrive binding as a connection ready to feed a
|
|
4
|
+
* user-supplied SQL driver.
|
|
5
|
+
*
|
|
6
|
+
* `@lunora/hyperdrive` deliberately **bundles no driver** — `postgres`, `pg` and
|
|
7
|
+
* `mysql2` are heavy and the choice is the user's (they are `optional`
|
|
8
|
+
* `peerDependencies`, never `dependencies`). This factory's only job is to lift
|
|
9
|
+
* the binding's connection details out; the user constructs their own driver
|
|
10
|
+
* from `connectionString` and wraps it with one of the {@link fromPostgresJs} /
|
|
11
|
+
* {@link fromNodePg} / {@link fromMysql2} adapters to get a {@link SqlClient}.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { createHyperdrive, fromPostgresJs } from "@lunora/hyperdrive";
|
|
15
|
+
* import postgres from "postgres";
|
|
16
|
+
*
|
|
17
|
+
* // Wire the client once, on the app builder — called per shard construction,
|
|
18
|
+
* // not per request. `ctx.sql` is emitted `readonly`; it is never assigned.
|
|
19
|
+
* const app = defineApp<Env>()
|
|
20
|
+
* .shard((env) => env.SHARD)
|
|
21
|
+
* .hyperdrive((env) => fromPostgresJs(postgres(createHyperdrive(env.HYPERDRIVE).connectionString)))
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // Then, inside an action (never a query/mutation):
|
|
25
|
+
* const rows = await ctx.sql.query("select id from users where org = $1", [orgId]);
|
|
26
|
+
* ```
|
|
27
|
+
* @remarks
|
|
28
|
+
* Hyperdrive talks to an **external** database Lunora has no visibility into.
|
|
29
|
+
* Queries through `ctx.sql` are non-deterministic (action-only — enforced by the
|
|
30
|
+
* `hyperdrive_outside_action` advisor lint) and external writes are NOT tracked
|
|
31
|
+
* by Lunora live queries: subscriptions will not re-run when external rows
|
|
32
|
+
* change. Use Hyperdrive to *integrate* an existing DB from an action; if you
|
|
33
|
+
* want that data to be reactive, write a projection of it into a `defineSchema`
|
|
34
|
+
* DO/D1 table.
|
|
35
|
+
* @param binding The `env.HYPERDRIVE` binding (or a structural double).
|
|
36
|
+
* @returns The raw `connectionString` plus the discrete connection parts.
|
|
37
|
+
*/
|
|
137
38
|
declare const createHyperdrive: (binding: HyperdriveLike) => {
|
|
138
39
|
config: HyperdriveConnection;
|
|
139
40
|
connectionString: string;
|
|
140
41
|
};
|
|
141
42
|
/**
|
|
142
|
-
* Wrap a `postgres` (postgres.js) client as a {@link SqlClient}.
|
|
143
|
-
*
|
|
144
|
-
* Uses the driver's `.unsafe(text, params)` escape hatch so the caller supplies
|
|
145
|
-
* a plain SQL string with `$1, $2, …` placeholders and a positional params
|
|
146
|
-
* array. postgres.js's `.unsafe` resolves to a row array.
|
|
147
|
-
*/
|
|
43
|
+
* Wrap a `postgres` (postgres.js) client as a {@link SqlClient}.
|
|
44
|
+
*
|
|
45
|
+
* Uses the driver's `.unsafe(text, params)` escape hatch so the caller supplies
|
|
46
|
+
* a plain SQL string with `$1, $2, …` placeholders and a positional params
|
|
47
|
+
* array. postgres.js's `.unsafe` resolves to a row array.
|
|
48
|
+
*/
|
|
148
49
|
declare const fromPostgresJs: (client: PostgresJsLike) => SqlClient;
|
|
149
50
|
/**
|
|
150
|
-
* Wrap a `pg` (node-postgres) `Client` or `Pool` as a {@link SqlClient}.
|
|
151
|
-
*
|
|
152
|
-
* node-postgres returns a result object whose `rows` field holds the row array.
|
|
153
|
-
*/
|
|
51
|
+
* Wrap a `pg` (node-postgres) `Client` or `Pool` as a {@link SqlClient}.
|
|
52
|
+
*
|
|
53
|
+
* node-postgres returns a result object whose `rows` field holds the row array.
|
|
54
|
+
*/
|
|
154
55
|
declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
155
56
|
/**
|
|
156
|
-
* Wrap a `mysql2/promise` connection or pool as a {@link SqlClient}.
|
|
157
|
-
*
|
|
158
|
-
* Use `?` placeholders (MySQL positional syntax). `mysql2`'s `execute` resolves
|
|
159
|
-
* to a `[rows, fields]` tuple; the adapter returns the first element. For a
|
|
160
|
-
* non-`SELECT` (DML), `mysql2` yields a `ResultSetHeader` object rather than a
|
|
161
|
-
* row array, so the adapter normalises that to `[]` — matching the empty-array
|
|
162
|
-
* contract the postgres.js / node-postgres adapters already honour.
|
|
163
|
-
*/
|
|
57
|
+
* Wrap a `mysql2/promise` connection or pool as a {@link SqlClient}.
|
|
58
|
+
*
|
|
59
|
+
* Use `?` placeholders (MySQL positional syntax). `mysql2`'s `execute` resolves
|
|
60
|
+
* to a `[rows, fields]` tuple; the adapter returns the first element. For a
|
|
61
|
+
* non-`SELECT` (DML), `mysql2` yields a `ResultSetHeader` object rather than a
|
|
62
|
+
* row array, so the adapter normalises that to `[]` — matching the empty-array
|
|
63
|
+
* contract the postgres.js / node-postgres adapters already honour.
|
|
64
|
+
*/
|
|
164
65
|
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
165
66
|
/** How an external row maps to a Lunora document. */
|
|
166
67
|
interface ProjectOptions {
|
|
167
68
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
69
|
+
* Column whose value becomes the Lunora `_id` (stringified). Defaults to `"id"`.
|
|
70
|
+
* With no `map`, this column is dropped from the document body (it lives on as
|
|
71
|
+
* `_id`); with a `map`, the mapper owns the body and `_id` is added from here.
|
|
72
|
+
*/
|
|
172
73
|
idColumn?: string;
|
|
173
74
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
75
|
+
* Transform an external row into the stored document body. Omit for the default:
|
|
76
|
+
* every selected column except `idColumn` is copied verbatim. The returned object
|
|
77
|
+
* must not include `_id` — it is set from `idColumn`.
|
|
78
|
+
*/
|
|
178
79
|
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
179
80
|
}
|
|
180
81
|
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
@@ -185,20 +86,68 @@ interface PullSourceOptions extends ProjectOptions {
|
|
|
185
86
|
query: string;
|
|
186
87
|
}
|
|
187
88
|
/**
|
|
188
|
-
* Project one external row to a Lunora document: lift `idColumn` to a stringified
|
|
189
|
-
* `_id`, then either apply `map` or copy every other column verbatim. Throws when
|
|
190
|
-
* the id column is missing/nullish so a misconfigured query fails loudly rather than
|
|
191
|
-
* materializing rows under an `"undefined"` id.
|
|
192
|
-
*
|
|
193
|
-
* Delegates to `@lunora/
|
|
194
|
-
* `.source()` poll loop also uses — so the manual bridge and the codegen path can
|
|
195
|
-
* never diverge in their missing-id handling.
|
|
196
|
-
*/
|
|
89
|
+
* Project one external row to a Lunora document: lift `idColumn` to a stringified
|
|
90
|
+
* `_id`, then either apply `map` or copy every other column verbatim. Throws when
|
|
91
|
+
* the id column is missing/nullish so a misconfigured query fails loudly rather than
|
|
92
|
+
* materializing rows under an `"undefined"` id.
|
|
93
|
+
*
|
|
94
|
+
* Delegates to `@lunora/shard-engine`'s `liftSourceId` — the single id-lift the declarative
|
|
95
|
+
* `.source()` poll loop also uses — so the manual bridge and the codegen path can
|
|
96
|
+
* never diverge in their missing-id handling.
|
|
97
|
+
*/
|
|
197
98
|
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
198
99
|
/**
|
|
199
|
-
* Run a parameterised tenant query against Hyperdrive and project every row to a
|
|
200
|
-
* Lunora document ready to hand to `materializeExternalRows`. Call this inside an
|
|
201
|
-
* **action** (where `ctx.sql` lives); pass the result to a mutation for the write.
|
|
202
|
-
*/
|
|
100
|
+
* Run a parameterised tenant query against Hyperdrive and project every row to a
|
|
101
|
+
* Lunora document ready to hand to `materializeExternalRows`. Call this inside an
|
|
102
|
+
* **action** (where `ctx.sql` lives); pass the result to a mutation for the write.
|
|
103
|
+
*/
|
|
203
104
|
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
204
|
-
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient,
|
|
105
|
+
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient,
|
|
106
|
+
/**
|
|
107
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
108
|
+
* Hyperdrive.
|
|
109
|
+
*
|
|
110
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
111
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
112
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
113
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
114
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
115
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
116
|
+
*/
|
|
117
|
+
createHyperdrive,
|
|
118
|
+
/**
|
|
119
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
120
|
+
* Hyperdrive.
|
|
121
|
+
*
|
|
122
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
123
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
124
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
125
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
126
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
127
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
128
|
+
*/
|
|
129
|
+
fromMysql2,
|
|
130
|
+
/**
|
|
131
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
132
|
+
* Hyperdrive.
|
|
133
|
+
*
|
|
134
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
135
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
136
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
137
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
138
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
139
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
140
|
+
*/
|
|
141
|
+
fromNodePg,
|
|
142
|
+
/**
|
|
143
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
144
|
+
* Hyperdrive.
|
|
145
|
+
*
|
|
146
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
147
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
148
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
149
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
150
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
151
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
152
|
+
*/
|
|
153
|
+
fromPostgresJs, projectSourceRow, pullSourceRows };
|