@lunora/hyperdrive 1.0.0-alpha.9 → 1.0.0-alpha.91
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/dist/global.d.mts +100 -45
- package/dist/global.d.ts +100 -45
- package/dist/global.mjs +1 -9
- package/dist/index.d.mts +135 -152
- package/dist/index.d.ts +135 -152
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/buildMysqlExec-CPwtojyL.mjs +1 -0
- package/dist/packem_shared/createHyperdrive-DEXMfGd0.mjs +1 -0
- package/dist/packem_shared/mysqlDialect-DitNAlpV.mjs +1 -0
- package/dist/packem_shared/projectSourceRow-DN8ywPRl.mjs +1 -0
- package/dist/packem_shared/types.d-DE1NYxyA.d.mts +113 -0
- package/dist/packem_shared/types.d-DE1NYxyA.d.ts +113 -0
- package/package.json +4 -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/index.d.mts
CHANGED
|
@@ -1,165 +1,148 @@
|
|
|
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-DE1NYxyA.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
|
-
|
|
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
|
+
* // inside an action (never a query/mutation):
|
|
18
|
+
* const { connectionString } = createHyperdrive(env.HYPERDRIVE);
|
|
19
|
+
* ctx.sql = fromPostgresJs(postgres(connectionString));
|
|
20
|
+
* const rows = await ctx.sql.query("select id from users where org = $1", [orgId]);
|
|
21
|
+
* ```
|
|
22
|
+
* @remarks
|
|
23
|
+
* Hyperdrive talks to an **external** database Lunora has no visibility into.
|
|
24
|
+
* Queries through `ctx.sql` are non-deterministic (action-only — enforced by the
|
|
25
|
+
* `hyperdrive_outside_action` advisor lint) and external writes are NOT tracked
|
|
26
|
+
* by Lunora live queries: subscriptions will not re-run when external rows
|
|
27
|
+
* change. Use Hyperdrive to *integrate* an existing DB from an action; if you
|
|
28
|
+
* want that data to be reactive, write a projection of it into a `defineSchema`
|
|
29
|
+
* DO/D1 table.
|
|
30
|
+
* @param binding The `env.HYPERDRIVE` binding (or a structural double).
|
|
31
|
+
* @returns The raw `connectionString` plus the discrete connection parts.
|
|
32
|
+
*/
|
|
33
|
+
declare const createHyperdrive: (binding: HyperdriveLike) => {
|
|
34
|
+
config: HyperdriveConnection;
|
|
25
35
|
connectionString: string;
|
|
26
|
-
|
|
27
|
-
database: string;
|
|
28
|
-
/** Host Hyperdrive presents to the driver (the local proxy, not your origin DB). */
|
|
29
|
-
host: string;
|
|
30
|
-
/** Password component of the connection. */
|
|
31
|
-
password: string;
|
|
32
|
-
/** Port Hyperdrive presents to the driver. */
|
|
33
|
-
port: number;
|
|
34
|
-
/** User component of the connection. */
|
|
35
|
-
user: string;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
user: string;
|
|
52
|
-
}
|
|
38
|
+
* Wrap a `postgres` (postgres.js) client as a {@link SqlClient}.
|
|
39
|
+
*
|
|
40
|
+
* Uses the driver's `.unsafe(text, params)` escape hatch so the caller supplies
|
|
41
|
+
* a plain SQL string with `$1, $2, …` placeholders and a positional params
|
|
42
|
+
* array. postgres.js's `.unsafe` resolves to a row array.
|
|
43
|
+
*/
|
|
44
|
+
declare const fromPostgresJs: (client: PostgresJsLike) => SqlClient;
|
|
45
|
+
/**
|
|
46
|
+
* Wrap a `pg` (node-postgres) `Client` or `Pool` as a {@link SqlClient}.
|
|
47
|
+
*
|
|
48
|
+
* node-postgres returns a result object whose `rows` field holds the row array.
|
|
49
|
+
*/
|
|
50
|
+
declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
53
51
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* `
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
interface SqlClient {
|
|
52
|
+
* Wrap a `mysql2/promise` connection or pool as a {@link SqlClient}.
|
|
53
|
+
*
|
|
54
|
+
* Use `?` placeholders (MySQL positional syntax). `mysql2`'s `execute` resolves
|
|
55
|
+
* to a `[rows, fields]` tuple; the adapter returns the first element. For a
|
|
56
|
+
* non-`SELECT` (DML), `mysql2` yields a `ResultSetHeader` object rather than a
|
|
57
|
+
* row array, so the adapter normalises that to `[]` — matching the empty-array
|
|
58
|
+
* contract the postgres.js / node-postgres adapters already honour.
|
|
59
|
+
*/
|
|
60
|
+
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
61
|
+
/** How an external row maps to a Lunora document. */
|
|
62
|
+
interface ProjectOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Column whose value becomes the Lunora `_id` (stringified). Defaults to `"id"`.
|
|
65
|
+
* With no `map`, this column is dropped from the document body (it lives on as
|
|
66
|
+
* `_id`); with a `map`, the mapper owns the body and `_id` is added from here.
|
|
67
|
+
*/
|
|
68
|
+
idColumn?: string;
|
|
72
69
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/
|
|
79
|
-
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
70
|
+
* Transform an external row into the stored document body. Omit for the default:
|
|
71
|
+
* every selected column except `idColumn` is copied verbatim. The returned object
|
|
72
|
+
* must not include `_id` — it is set from `idColumn`.
|
|
73
|
+
*/
|
|
74
|
+
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
80
75
|
}
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
query:
|
|
87
|
-
rows: unknown[];
|
|
88
|
-
}>;
|
|
76
|
+
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
77
|
+
interface PullSourceOptions extends ProjectOptions {
|
|
78
|
+
/** Bound parameter values, positionally matched to `query` (the tenant scope binds here). */
|
|
79
|
+
params?: ReadonlyArray<unknown>;
|
|
80
|
+
/** The full tenant-membership query with driver-native placeholders (`$1` / `?`). */
|
|
81
|
+
query: string;
|
|
89
82
|
}
|
|
90
83
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
* Project one external row to a Lunora document: lift `idColumn` to a stringified
|
|
85
|
+
* `_id`, then either apply `map` or copy every other column verbatim. Throws when
|
|
86
|
+
* the id column is missing/nullish so a misconfigured query fails loudly rather than
|
|
87
|
+
* materializing rows under an `"undefined"` id.
|
|
88
|
+
*
|
|
89
|
+
* Delegates to `@lunora/shard-engine`'s `liftSourceId` — the single id-lift the declarative
|
|
90
|
+
* `.source()` poll loop also uses — so the manual bridge and the codegen path can
|
|
91
|
+
* never diverge in their missing-id handling.
|
|
92
|
+
*/
|
|
93
|
+
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
98
94
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
95
|
+
* Run a parameterised tenant query against Hyperdrive and project every row to a
|
|
96
|
+
* Lunora document ready to hand to `materializeExternalRows`. Call this inside an
|
|
97
|
+
* **action** (where `ctx.sql` lives); pass the result to a mutation for the write.
|
|
98
|
+
*/
|
|
99
|
+
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
100
|
+
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient,
|
|
106
101
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* `
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* {@link
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
*/
|
|
137
|
-
declare const createHyperdrive: (binding: HyperdriveLike) => {
|
|
138
|
-
config: HyperdriveConnection;
|
|
139
|
-
connectionString: string;
|
|
140
|
-
};
|
|
102
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
103
|
+
* Hyperdrive.
|
|
104
|
+
*
|
|
105
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
106
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
107
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
108
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
109
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
110
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
111
|
+
*/
|
|
112
|
+
createHyperdrive,
|
|
141
113
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* a
|
|
146
|
-
*
|
|
147
|
-
|
|
148
|
-
|
|
114
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
115
|
+
* Hyperdrive.
|
|
116
|
+
*
|
|
117
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
118
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
119
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
120
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
121
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
122
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
123
|
+
*/
|
|
124
|
+
fromMysql2,
|
|
149
125
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
|
|
126
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
127
|
+
* Hyperdrive.
|
|
128
|
+
*
|
|
129
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
130
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
131
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
132
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
133
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
134
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
135
|
+
*/
|
|
136
|
+
fromNodePg,
|
|
155
137
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
138
|
+
* `@lunora/hyperdrive` — bring-your-own Postgres/MySQL for Lunora via Cloudflare
|
|
139
|
+
* Hyperdrive.
|
|
140
|
+
*
|
|
141
|
+
* Surfaces a Hyperdrive binding's connection string and a driver-agnostic
|
|
142
|
+
* {@link import("./types").SqlClient | SqlClient} bound to `ctx.sql` on
|
|
143
|
+
* **`ActionCtx` only**. External SQL is non-deterministic (action-only) and
|
|
144
|
+
* non-reactive (live queries do not track external writes) — integrate an
|
|
145
|
+
* existing DB, do not replace the Lunora data layer. See the README and
|
|
146
|
+
* {@link import("./create-hyperdrive").createHyperdrive | createHyperdrive} JSDoc.
|
|
147
|
+
*/
|
|
148
|
+
fromPostgresJs, projectSourceRow, pullSourceRows };
|