@lunora/hyperdrive 1.0.0-alpha.32 → 1.0.0-alpha.34
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/dist/global.d.mts +41 -45
- package/dist/global.d.ts +41 -45
- package/dist/index.d.mts +70 -70
- package/dist/index.d.ts +70 -70
- 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 -4
- package/dist/packem_shared/types.d-C6SU6Aw3.d.mts +0 -113
- package/dist/packem_shared/types.d-C6SU6Aw3.d.ts +0 -113
package/dist/global.d.mts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
import { DatabaseWriterLike } from '@lunora/do';
|
|
2
2
|
import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
|
|
3
|
-
import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-
|
|
3
|
+
import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.mjs";
|
|
4
4
|
/**
|
|
5
|
-
* Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
|
|
6
|
-
* result). Aliases {@link SqlClient} — the exec-facing name is kept so call sites read
|
|
7
|
-
* intent, but the shape is the single source of truth in `./types` (no drift).
|
|
8
|
-
*/
|
|
5
|
+
* Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
|
|
6
|
+
* result). Aliases {@link SqlClient} — the exec-facing name is kept so call sites read
|
|
7
|
+
* intent, but the shape is the single source of truth in `./types` (no drift).
|
|
8
|
+
*/
|
|
9
9
|
type RowClient = SqlClient;
|
|
10
10
|
/**
|
|
11
|
-
* Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
|
|
12
|
-
* `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global entry's
|
|
13
|
-
* driver surface can never drift from the main entry's.
|
|
14
|
-
*/
|
|
11
|
+
* Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
|
|
12
|
+
* `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global entry's
|
|
13
|
+
* driver surface can never drift from the main entry's.
|
|
14
|
+
*/
|
|
15
15
|
type Mysql2Execute = Mysql2Like;
|
|
16
16
|
/**
|
|
17
|
-
* Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
|
|
18
|
-
* `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
|
|
19
|
-
* for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
|
|
20
|
-
* OCC (read via `all`), so `run` reports no affected-row count.
|
|
21
|
-
*/
|
|
17
|
+
* Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
|
|
18
|
+
* `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
|
|
19
|
+
* for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
|
|
20
|
+
* OCC (read via `all`), so `run` reports no affected-row count.
|
|
21
|
+
*/
|
|
22
22
|
declare const buildPgExec: (client: RowClient) => SqlExec;
|
|
23
23
|
/**
|
|
24
|
-
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
25
|
-
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
26
|
-
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
27
|
-
* for the store's affected-rows OCC guard.
|
|
28
|
-
*
|
|
29
|
-
* **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
|
|
30
|
-
* (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
|
|
31
|
-
* counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
|
|
32
|
-
* same values reports 0 and the OCC guard raises a spurious conflict.
|
|
33
|
-
*/
|
|
24
|
+
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
25
|
+
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
26
|
+
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
27
|
+
* for the store's affected-rows OCC guard.
|
|
28
|
+
*
|
|
29
|
+
* **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
|
|
30
|
+
* (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
|
|
31
|
+
* counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
|
|
32
|
+
* same values reports 0 and the OCC guard raises a spurious conflict.
|
|
33
|
+
*/
|
|
34
34
|
declare const buildMysqlExec: (connection: Mysql2Execute) => SqlExec;
|
|
35
35
|
/**
|
|
36
|
-
* **Postgres** dialect. Differs from SQLite only in column types
|
|
37
|
-
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
38
|
-
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
39
|
-
*/
|
|
36
|
+
* **Postgres** dialect. Differs from SQLite only in column types
|
|
37
|
+
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
38
|
+
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
39
|
+
*/
|
|
40
40
|
declare const postgresDialect: SqlDialect;
|
|
41
41
|
/**
|
|
42
|
-
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
43
|
-
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
44
|
-
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
45
|
-
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
46
|
-
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
47
|
-
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
48
|
-
*/
|
|
42
|
+
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
43
|
+
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
44
|
+
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
45
|
+
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
46
|
+
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
47
|
+
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
48
|
+
*/
|
|
49
49
|
declare const mysqlDialect: SqlDialect;
|
|
50
50
|
/** Which engine a Hyperdrive-backed `.global()` store targets. */
|
|
51
51
|
type HyperdriveEngine = "mysql" | "postgres";
|
|
@@ -57,16 +57,12 @@ interface CreateHyperdriveGlobalCtxDbOptions extends Omit<SqlCtxDbOptions, "dial
|
|
|
57
57
|
exec: SqlExec;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
61
|
-
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
62
|
-
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
63
|
-
* D1 store options.
|
|
64
|
-
*/
|
|
65
|
-
declare const createHyperdriveGlobalCtxDb: ({
|
|
66
|
-
engine,
|
|
67
|
-
exec,
|
|
68
|
-
...rest
|
|
69
|
-
}: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
|
|
60
|
+
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
61
|
+
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
62
|
+
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
63
|
+
* D1 store options.
|
|
64
|
+
*/
|
|
65
|
+
declare const createHyperdriveGlobalCtxDb: ({ engine, exec, ...rest }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
|
|
70
66
|
/** Convenience: a **Postgres** `.global()` writer from a row-client (postgres.js/pg over Hyperdrive). */
|
|
71
67
|
declare const createPostgresGlobalCtxDb: (client: RowClient, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
|
|
72
68
|
/** Convenience: a **MySQL** `.global()` writer from a `mysql2/promise` connection/pool (created with `flags: ["FOUND_ROWS"]`). */
|
package/dist/global.d.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
import { DatabaseWriterLike } from '@lunora/do';
|
|
2
2
|
import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
|
|
3
|
-
import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-
|
|
3
|
+
import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.js";
|
|
4
4
|
/**
|
|
5
|
-
* Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
|
|
6
|
-
* result). Aliases {@link SqlClient} — the exec-facing name is kept so call sites read
|
|
7
|
-
* intent, but the shape is the single source of truth in `./types` (no drift).
|
|
8
|
-
*/
|
|
5
|
+
* Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
|
|
6
|
+
* result). Aliases {@link SqlClient} — the exec-facing name is kept so call sites read
|
|
7
|
+
* intent, but the shape is the single source of truth in `./types` (no drift).
|
|
8
|
+
*/
|
|
9
9
|
type RowClient = SqlClient;
|
|
10
10
|
/**
|
|
11
|
-
* Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
|
|
12
|
-
* `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global entry's
|
|
13
|
-
* driver surface can never drift from the main entry's.
|
|
14
|
-
*/
|
|
11
|
+
* Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
|
|
12
|
+
* `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global entry's
|
|
13
|
+
* driver surface can never drift from the main entry's.
|
|
14
|
+
*/
|
|
15
15
|
type Mysql2Execute = Mysql2Like;
|
|
16
16
|
/**
|
|
17
|
-
* Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
|
|
18
|
-
* `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
|
|
19
|
-
* for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
|
|
20
|
-
* OCC (read via `all`), so `run` reports no affected-row count.
|
|
21
|
-
*/
|
|
17
|
+
* Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
|
|
18
|
+
* `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
|
|
19
|
+
* for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
|
|
20
|
+
* OCC (read via `all`), so `run` reports no affected-row count.
|
|
21
|
+
*/
|
|
22
22
|
declare const buildPgExec: (client: RowClient) => SqlExec;
|
|
23
23
|
/**
|
|
24
|
-
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
25
|
-
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
26
|
-
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
27
|
-
* for the store's affected-rows OCC guard.
|
|
28
|
-
*
|
|
29
|
-
* **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
|
|
30
|
-
* (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
|
|
31
|
-
* counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
|
|
32
|
-
* same values reports 0 and the OCC guard raises a spurious conflict.
|
|
33
|
-
*/
|
|
24
|
+
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
25
|
+
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
26
|
+
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
27
|
+
* for the store's affected-rows OCC guard.
|
|
28
|
+
*
|
|
29
|
+
* **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
|
|
30
|
+
* (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
|
|
31
|
+
* counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
|
|
32
|
+
* same values reports 0 and the OCC guard raises a spurious conflict.
|
|
33
|
+
*/
|
|
34
34
|
declare const buildMysqlExec: (connection: Mysql2Execute) => SqlExec;
|
|
35
35
|
/**
|
|
36
|
-
* **Postgres** dialect. Differs from SQLite only in column types
|
|
37
|
-
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
38
|
-
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
39
|
-
*/
|
|
36
|
+
* **Postgres** dialect. Differs from SQLite only in column types
|
|
37
|
+
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
38
|
+
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
39
|
+
*/
|
|
40
40
|
declare const postgresDialect: SqlDialect;
|
|
41
41
|
/**
|
|
42
|
-
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
43
|
-
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
44
|
-
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
45
|
-
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
46
|
-
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
47
|
-
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
48
|
-
*/
|
|
42
|
+
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
43
|
+
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
44
|
+
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
45
|
+
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
46
|
+
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
47
|
+
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
48
|
+
*/
|
|
49
49
|
declare const mysqlDialect: SqlDialect;
|
|
50
50
|
/** Which engine a Hyperdrive-backed `.global()` store targets. */
|
|
51
51
|
type HyperdriveEngine = "mysql" | "postgres";
|
|
@@ -57,16 +57,12 @@ interface CreateHyperdriveGlobalCtxDbOptions extends Omit<SqlCtxDbOptions, "dial
|
|
|
57
57
|
exec: SqlExec;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
61
|
-
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
62
|
-
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
63
|
-
* D1 store options.
|
|
64
|
-
*/
|
|
65
|
-
declare const createHyperdriveGlobalCtxDb: ({
|
|
66
|
-
engine,
|
|
67
|
-
exec,
|
|
68
|
-
...rest
|
|
69
|
-
}: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
|
|
60
|
+
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
61
|
+
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
62
|
+
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
63
|
+
* D1 store options.
|
|
64
|
+
*/
|
|
65
|
+
declare const createHyperdriveGlobalCtxDb: ({ engine, exec, ...rest }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
|
|
70
66
|
/** Convenience: a **Postgres** `.global()` writer from a row-client (postgres.js/pg over Hyperdrive). */
|
|
71
67
|
declare const createPostgresGlobalCtxDb: (client: RowClient, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
|
|
72
68
|
/** Convenience: a **MySQL** `.global()` writer from a `mysql2/promise` connection/pool (created with `flags: ["FOUND_ROWS"]`). */
|
package/dist/index.d.mts
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
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-
|
|
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";
|
|
2
2
|
/**
|
|
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
|
-
*/
|
|
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
33
|
declare const createHyperdrive: (binding: HyperdriveLike) => {
|
|
34
34
|
config: HyperdriveConnection;
|
|
35
35
|
connectionString: string;
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
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
|
-
*/
|
|
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
44
|
declare const fromPostgresJs: (client: PostgresJsLike) => SqlClient;
|
|
45
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
|
-
*/
|
|
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
50
|
declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
51
51
|
/**
|
|
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
|
-
*/
|
|
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
60
|
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
61
61
|
/** How an external row maps to a Lunora document. */
|
|
62
62
|
interface ProjectOptions {
|
|
63
63
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
68
|
idColumn?: string;
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
74
|
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
75
75
|
}
|
|
76
76
|
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
@@ -81,20 +81,20 @@ interface PullSourceOptions extends ProjectOptions {
|
|
|
81
81
|
query: string;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
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/do`'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
|
-
*/
|
|
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/do`'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
93
|
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
94
94
|
/**
|
|
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
|
-
*/
|
|
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
99
|
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
100
100
|
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient, createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs, projectSourceRow, pullSourceRows };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
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-
|
|
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.js";
|
|
2
2
|
/**
|
|
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
|
-
*/
|
|
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
33
|
declare const createHyperdrive: (binding: HyperdriveLike) => {
|
|
34
34
|
config: HyperdriveConnection;
|
|
35
35
|
connectionString: string;
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
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
|
-
*/
|
|
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
44
|
declare const fromPostgresJs: (client: PostgresJsLike) => SqlClient;
|
|
45
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
|
-
*/
|
|
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
50
|
declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
51
51
|
/**
|
|
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
|
-
*/
|
|
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
60
|
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
61
61
|
/** How an external row maps to a Lunora document. */
|
|
62
62
|
interface ProjectOptions {
|
|
63
63
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
68
|
idColumn?: string;
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
74
|
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
75
75
|
}
|
|
76
76
|
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
@@ -81,20 +81,20 @@ interface PullSourceOptions extends ProjectOptions {
|
|
|
81
81
|
query: string;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
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/do`'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
|
-
*/
|
|
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/do`'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
93
|
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
94
94
|
/**
|
|
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
|
-
*/
|
|
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
99
|
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
100
100
|
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient, createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs, projectSourceRow, pullSourceRows };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `@lunora/hyperdrive`.
|
|
3
|
+
*
|
|
4
|
+
* Hyperdrive points at a database **Lunora does not own**. Everything here is
|
|
5
|
+
* deliberately structural (no hard dependency on `@cloudflare/workers-types` or
|
|
6
|
+
* any SQL driver) so unit tests can pass plain-object doubles, exactly like the
|
|
7
|
+
* `D1DatabaseLike` projection in `@lunora/d1`.
|
|
8
|
+
*
|
|
9
|
+
* The hard constraint, restated wherever this surface is used: Hyperdrive
|
|
10
|
+
* queries are **non-deterministic** (forbidden in `query`/`mutation`, allowed
|
|
11
|
+
* only in `action`s — see the `hyperdrive_outside_action` advisor lint), and
|
|
12
|
+
* external writes are **invisible to Lunora live queries** — a subscription will
|
|
13
|
+
* NOT re-run when an external Postgres/MySQL row changes.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Structural projection of the Cloudflare `Hyperdrive` binding (`env.HYPERDRIVE`).
|
|
17
|
+
*
|
|
18
|
+
* Mirrors the fields of the real `Hyperdrive` from `@cloudflare/workers-types`
|
|
19
|
+
* but stays structural so a unit test can pass a plain object. At runtime only
|
|
20
|
+
* `connectionString` is needed to construct a driver; the discrete connection
|
|
21
|
+
* parts are surfaced for drivers that prefer a config object over a DSN.
|
|
22
|
+
*/
|
|
23
|
+
interface HyperdriveLike {
|
|
24
|
+
/** A connection string Hyperdrive routes through its pooled, cached edge connection. */
|
|
25
|
+
connectionString: string;
|
|
26
|
+
/** Database name component of the connection. */
|
|
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
|
+
}
|
|
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
|
+
*
|
|
75
|
+
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
+
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
+
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
+
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
+
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
+
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
81
|
+
* @param text SQL text with driver-native positional placeholders.
|
|
82
|
+
* @param params Bound parameter values, positionally matched to `text`.
|
|
83
|
+
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
84
|
+
* return no rows).
|
|
85
|
+
*/
|
|
86
|
+
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
|
|
90
|
+
* `query` method `fromNodePg` calls is required, kept structural for testing.
|
|
91
|
+
*/
|
|
92
|
+
interface NodePgLike {
|
|
93
|
+
query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
|
|
94
|
+
rows: unknown[];
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Structural projection of a `postgres` (postgres.js) tagged-template client.
|
|
99
|
+
* The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
|
|
100
|
+
* full control of the parameter list.
|
|
101
|
+
*/
|
|
102
|
+
interface PostgresJsLike {
|
|
103
|
+
unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
|
|
107
|
+
* `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
|
|
108
|
+
* element as the rows.
|
|
109
|
+
*/
|
|
110
|
+
interface Mysql2Like {
|
|
111
|
+
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
112
|
+
}
|
|
113
|
+
export { HyperdriveLike as H, Mysql2Like as M, NodePgLike as N, PostgresJsLike as P, SqlClient as S, HyperdriveConnection as a };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `@lunora/hyperdrive`.
|
|
3
|
+
*
|
|
4
|
+
* Hyperdrive points at a database **Lunora does not own**. Everything here is
|
|
5
|
+
* deliberately structural (no hard dependency on `@cloudflare/workers-types` or
|
|
6
|
+
* any SQL driver) so unit tests can pass plain-object doubles, exactly like the
|
|
7
|
+
* `D1DatabaseLike` projection in `@lunora/d1`.
|
|
8
|
+
*
|
|
9
|
+
* The hard constraint, restated wherever this surface is used: Hyperdrive
|
|
10
|
+
* queries are **non-deterministic** (forbidden in `query`/`mutation`, allowed
|
|
11
|
+
* only in `action`s — see the `hyperdrive_outside_action` advisor lint), and
|
|
12
|
+
* external writes are **invisible to Lunora live queries** — a subscription will
|
|
13
|
+
* NOT re-run when an external Postgres/MySQL row changes.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Structural projection of the Cloudflare `Hyperdrive` binding (`env.HYPERDRIVE`).
|
|
17
|
+
*
|
|
18
|
+
* Mirrors the fields of the real `Hyperdrive` from `@cloudflare/workers-types`
|
|
19
|
+
* but stays structural so a unit test can pass a plain object. At runtime only
|
|
20
|
+
* `connectionString` is needed to construct a driver; the discrete connection
|
|
21
|
+
* parts are surfaced for drivers that prefer a config object over a DSN.
|
|
22
|
+
*/
|
|
23
|
+
interface HyperdriveLike {
|
|
24
|
+
/** A connection string Hyperdrive routes through its pooled, cached edge connection. */
|
|
25
|
+
connectionString: string;
|
|
26
|
+
/** Database name component of the connection. */
|
|
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
|
+
}
|
|
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
|
+
*
|
|
75
|
+
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
+
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
+
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
+
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
+
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
+
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
81
|
+
* @param text SQL text with driver-native positional placeholders.
|
|
82
|
+
* @param params Bound parameter values, positionally matched to `text`.
|
|
83
|
+
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
84
|
+
* return no rows).
|
|
85
|
+
*/
|
|
86
|
+
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
|
|
90
|
+
* `query` method `fromNodePg` calls is required, kept structural for testing.
|
|
91
|
+
*/
|
|
92
|
+
interface NodePgLike {
|
|
93
|
+
query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
|
|
94
|
+
rows: unknown[];
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Structural projection of a `postgres` (postgres.js) tagged-template client.
|
|
99
|
+
* The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
|
|
100
|
+
* full control of the parameter list.
|
|
101
|
+
*/
|
|
102
|
+
interface PostgresJsLike {
|
|
103
|
+
unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
|
|
107
|
+
* `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
|
|
108
|
+
* element as the rows.
|
|
109
|
+
*/
|
|
110
|
+
interface Mysql2Like {
|
|
111
|
+
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
112
|
+
}
|
|
113
|
+
export { HyperdriveLike as H, Mysql2Like as M, NodePgLike as N, PostgresJsLike as P, SqlClient as S, HyperdriveConnection as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/hyperdrive",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.34",
|
|
4
4
|
"description": "Bring-your-own Postgres/MySQL for Lunora via Cloudflare Hyperdrive: a driver-agnostic, action-only ctx.sql",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/do": "1.0.0-alpha.
|
|
54
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
55
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
53
|
+
"@lunora/do": "1.0.0-alpha.35",
|
|
54
|
+
"@lunora/errors": "1.0.0-alpha.6",
|
|
55
|
+
"@lunora/sql-store": "1.0.0-alpha.35",
|
|
56
56
|
"drizzle-orm": "^0.45.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public types for `@lunora/hyperdrive`.
|
|
3
|
-
*
|
|
4
|
-
* Hyperdrive points at a database **Lunora does not own**. Everything here is
|
|
5
|
-
* deliberately structural (no hard dependency on `@cloudflare/workers-types` or
|
|
6
|
-
* any SQL driver) so unit tests can pass plain-object doubles, exactly like the
|
|
7
|
-
* `D1DatabaseLike` projection in `@lunora/d1`.
|
|
8
|
-
*
|
|
9
|
-
* The hard constraint, restated wherever this surface is used: Hyperdrive
|
|
10
|
-
* queries are **non-deterministic** (forbidden in `query`/`mutation`, allowed
|
|
11
|
-
* only in `action`s — see the `hyperdrive_outside_action` advisor lint), and
|
|
12
|
-
* external writes are **invisible to Lunora live queries** — a subscription will
|
|
13
|
-
* NOT re-run when an external Postgres/MySQL row changes.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Structural projection of the Cloudflare `Hyperdrive` binding (`env.HYPERDRIVE`).
|
|
17
|
-
*
|
|
18
|
-
* Mirrors the fields of the real `Hyperdrive` from `@cloudflare/workers-types`
|
|
19
|
-
* but stays structural so a unit test can pass a plain object. At runtime only
|
|
20
|
-
* `connectionString` is needed to construct a driver; the discrete connection
|
|
21
|
-
* parts are surfaced for drivers that prefer a config object over a DSN.
|
|
22
|
-
*/
|
|
23
|
-
interface HyperdriveLike {
|
|
24
|
-
/** A connection string Hyperdrive routes through its pooled, cached edge connection. */
|
|
25
|
-
connectionString: string;
|
|
26
|
-
/** Database name component of the connection. */
|
|
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
|
-
}
|
|
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
|
-
*
|
|
75
|
-
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
-
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
-
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
-
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
-
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
-
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
81
|
-
* @param text SQL text with driver-native positional placeholders.
|
|
82
|
-
* @param params Bound parameter values, positionally matched to `text`.
|
|
83
|
-
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
84
|
-
* return no rows).
|
|
85
|
-
*/
|
|
86
|
-
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
|
|
90
|
-
* `query` method `fromNodePg` calls is required, kept structural for testing.
|
|
91
|
-
*/
|
|
92
|
-
interface NodePgLike {
|
|
93
|
-
query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
|
|
94
|
-
rows: unknown[];
|
|
95
|
-
}>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Structural projection of a `postgres` (postgres.js) tagged-template client.
|
|
99
|
-
* The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
|
|
100
|
-
* full control of the parameter list.
|
|
101
|
-
*/
|
|
102
|
-
interface PostgresJsLike {
|
|
103
|
-
unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
|
|
107
|
-
* `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
|
|
108
|
-
* element as the rows.
|
|
109
|
-
*/
|
|
110
|
-
interface Mysql2Like {
|
|
111
|
-
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
112
|
-
}
|
|
113
|
-
export { HyperdriveLike as H, Mysql2Like as M, NodePgLike as N, PostgresJsLike as P, SqlClient as S, HyperdriveConnection as a };
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public types for `@lunora/hyperdrive`.
|
|
3
|
-
*
|
|
4
|
-
* Hyperdrive points at a database **Lunora does not own**. Everything here is
|
|
5
|
-
* deliberately structural (no hard dependency on `@cloudflare/workers-types` or
|
|
6
|
-
* any SQL driver) so unit tests can pass plain-object doubles, exactly like the
|
|
7
|
-
* `D1DatabaseLike` projection in `@lunora/d1`.
|
|
8
|
-
*
|
|
9
|
-
* The hard constraint, restated wherever this surface is used: Hyperdrive
|
|
10
|
-
* queries are **non-deterministic** (forbidden in `query`/`mutation`, allowed
|
|
11
|
-
* only in `action`s — see the `hyperdrive_outside_action` advisor lint), and
|
|
12
|
-
* external writes are **invisible to Lunora live queries** — a subscription will
|
|
13
|
-
* NOT re-run when an external Postgres/MySQL row changes.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Structural projection of the Cloudflare `Hyperdrive` binding (`env.HYPERDRIVE`).
|
|
17
|
-
*
|
|
18
|
-
* Mirrors the fields of the real `Hyperdrive` from `@cloudflare/workers-types`
|
|
19
|
-
* but stays structural so a unit test can pass a plain object. At runtime only
|
|
20
|
-
* `connectionString` is needed to construct a driver; the discrete connection
|
|
21
|
-
* parts are surfaced for drivers that prefer a config object over a DSN.
|
|
22
|
-
*/
|
|
23
|
-
interface HyperdriveLike {
|
|
24
|
-
/** A connection string Hyperdrive routes through its pooled, cached edge connection. */
|
|
25
|
-
connectionString: string;
|
|
26
|
-
/** Database name component of the connection. */
|
|
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
|
-
}
|
|
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
|
-
*
|
|
75
|
-
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
-
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
-
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
-
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
-
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
-
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
81
|
-
* @param text SQL text with driver-native positional placeholders.
|
|
82
|
-
* @param params Bound parameter values, positionally matched to `text`.
|
|
83
|
-
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
84
|
-
* return no rows).
|
|
85
|
-
*/
|
|
86
|
-
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
|
|
90
|
-
* `query` method `fromNodePg` calls is required, kept structural for testing.
|
|
91
|
-
*/
|
|
92
|
-
interface NodePgLike {
|
|
93
|
-
query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
|
|
94
|
-
rows: unknown[];
|
|
95
|
-
}>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Structural projection of a `postgres` (postgres.js) tagged-template client.
|
|
99
|
-
* The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
|
|
100
|
-
* full control of the parameter list.
|
|
101
|
-
*/
|
|
102
|
-
interface PostgresJsLike {
|
|
103
|
-
unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
|
|
107
|
-
* `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
|
|
108
|
-
* element as the rows.
|
|
109
|
-
*/
|
|
110
|
-
interface Mysql2Like {
|
|
111
|
-
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
112
|
-
}
|
|
113
|
-
export { HyperdriveLike as H, Mysql2Like as M, NodePgLike as N, PostgresJsLike as P, SqlClient as S, HyperdriveConnection as a };
|