@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 CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
package/dist/global.d.mts CHANGED
@@ -1,46 +1,105 @@
1
- import { DatabaseWriterLike } from '@lunora/do';
1
+ import { DatabaseWriterLike } from '@lunora/shard-engine';
2
2
  import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
3
- /** Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg` result). */
4
- interface RowClient {
5
- query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
6
- }
7
- /** Minimal `mysql2/promise` connection/pool surface `execute` resolves to `[rows | ResultSetHeader, fields]`. */
8
- interface Mysql2Execute {
9
- execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
10
- }
3
+ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.mjs";
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
+ */
9
+ type RowClient = SqlClient;
10
+ /**
11
+ * Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
12
+ * `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global
13
+ * entry's driver surface can never drift from the main entry's, widened with the
14
+ * (optional, structural) shape {@link assertFoundRows}'s `CLIENT_FOUND_ROWS`
15
+ * probe reads.
16
+ *
17
+ * A real `mysql2/promise` connection/pool exposes the merged client-flags
18
+ * bitmask synchronously, but at two different depths depending on which one it
19
+ * is, and NEITHER is in `mysql2`'s own `.d.ts` — its `Pool extends Connection`
20
+ * signature claims a top-level `config`, but at runtime a `mysql2/promise`
21
+ * `Pool` has none; the real value lives one level down, on the core pool it
22
+ * wraps:
23
+ *
24
+ * - a single `Connection`/`PoolConnection` → `connection.config.clientFlags`
25
+ * - a `Pool` (the `createPool({ flags: ["FOUND_ROWS"] })` example above) →
26
+ * `pool.pool.config.connectionConfig.clientFlags`
27
+ *
28
+ * Because those paths are undocumented driver internals, `global-dialect.test.ts`
29
+ * pins them against a REAL `mysql2` pool (built without connecting) rather than
30
+ * only against hand-written doubles — if a `mysql2` release relocates them, the
31
+ * probe would otherwise degrade silently to the warn branch and the OCC guard
32
+ * would go unchecked.
33
+ *
34
+ * Both fields are optional so a minimal `Mysql2Like` test double (only
35
+ * `execute`) safely resolves to "undeterminable" instead of a `TypeError`.
36
+ */
37
+ type Mysql2Execute = Mysql2Like & {
38
+ config?: {
39
+ clientFlags?: number;
40
+ };
41
+ pool?: {
42
+ config?: {
43
+ connectionConfig?: {
44
+ clientFlags?: number;
45
+ };
46
+ };
47
+ };
48
+ };
11
49
  /**
12
- * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
13
- * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
14
- * for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
15
- * OCC (read via `all`), so `run` reports no affected-row count.
16
- */
50
+ * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
51
+ * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
52
+ * for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
53
+ * OCC (read via `all`), so `run` reports no affected-row count.
54
+ *
55
+ * `batch` dispatches every statement concurrently (`Promise.all`) over `client`
56
+ * rather than awaiting each `query` call in turn — `RowClient` only exposes a
57
+ * single-statement `query`, so there is no wire-level multi-statement command
58
+ * to reach for. When `client` is backed by a pool (the common production
59
+ * shape), this genuinely spreads the statements across multiple physical
60
+ * connections instead of serializing one full round trip at a time; against a
61
+ * single connection it still removes the sequential *await*, though the
62
+ * underlying driver may itself queue the sends. Either way it stays
63
+ * non-atomic, at-least-once, and unordered between elements, same as the
64
+ * sequential fallback minus the ordering — safe only for statements whose
65
+ * effects don't depend on each other, which is what every current caller
66
+ * batches (distinct-keyed companion rows).
67
+ */
17
68
  declare const buildPgExec: (client: RowClient) => SqlExec;
18
69
  /**
19
- * Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
20
- * renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
21
- * forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
22
- * for the store's affected-rows OCC guard.
23
- *
24
- * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
25
- * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
26
- * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
27
- * same values reports 0 and the OCC guard raises a spurious conflict.
28
- */
70
+ * Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
71
+ * renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
72
+ * forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
73
+ * for the store's affected-rows OCC guard.
74
+ *
75
+ * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
76
+ * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
77
+ * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
78
+ * same values reports 0 and the OCC guard raises a spurious conflict. Verified
79
+ * once here at construction — see {@link assertFoundRows} — never per statement.
80
+ *
81
+ * `batch` dispatches every statement concurrently (`Promise.all`), same
82
+ * rationale as {@link buildPgExec}'s `batch` — `Mysql2Like` only exposes a
83
+ * single-statement `execute`, so this is "spread across a pool's connections"
84
+ * rather than one wire-level multi-statement command; still non-atomic,
85
+ * at-least-once, and unordered between elements, safe only for statements
86
+ * with no cross-effect (what every current caller batches).
87
+ */
29
88
  declare const buildMysqlExec: (connection: Mysql2Execute) => SqlExec;
30
89
  /**
31
- * **Postgres** dialect. Differs from SQLite only in column types
32
- * (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
33
- * probe, and unique-violation detection (SQLSTATE `23505`).
34
- */
90
+ * **Postgres** dialect. Differs from SQLite only in column types
91
+ * (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
92
+ * probe, and unique-violation detection (SQLSTATE `23505`).
93
+ */
35
94
  declare const postgresDialect: SqlDialect;
36
95
  /**
37
- * **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
38
- * to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
39
- * a no-op update still reports a matched row, see `buildMysqlExec`); bounded
40
- * `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
41
- * prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
42
- * dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
43
- */
96
+ * **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
97
+ * to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
98
+ * a no-op update still reports a matched row, see `buildMysqlExec`); bounded
99
+ * `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
100
+ * prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
101
+ * dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
102
+ */
44
103
  declare const mysqlDialect: SqlDialect;
45
104
  /** Which engine a Hyperdrive-backed `.global()` store targets. */
46
105
  type HyperdriveEngine = "mysql" | "postgres";
@@ -52,16 +111,12 @@ interface CreateHyperdriveGlobalCtxDbOptions extends Omit<SqlCtxDbOptions, "dial
52
111
  exec: SqlExec;
53
112
  }
54
113
  /**
55
- * Build a reactive `.global()` writer backed by a Hyperdrive-reachable
56
- * Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
57
- * {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
58
- * D1 store options.
59
- */
60
- declare const createHyperdriveGlobalCtxDb: ({
61
- engine,
62
- exec,
63
- ...rest
64
- }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
114
+ * Build a reactive `.global()` writer backed by a Hyperdrive-reachable
115
+ * Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
116
+ * {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
117
+ * D1 store options.
118
+ */
119
+ declare const createHyperdriveGlobalCtxDb: ({ engine, exec, ...rest }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
65
120
  /** Convenience: a **Postgres** `.global()` writer from a row-client (postgres.js/pg over Hyperdrive). */
66
121
  declare const createPostgresGlobalCtxDb: (client: RowClient, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
67
122
  /** Convenience: a **MySQL** `.global()` writer from a `mysql2/promise` connection/pool (created with `flags: ["FOUND_ROWS"]`). */
package/dist/global.d.ts CHANGED
@@ -1,46 +1,105 @@
1
- import { DatabaseWriterLike } from '@lunora/do';
1
+ import { DatabaseWriterLike } from '@lunora/shard-engine';
2
2
  import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
3
- /** Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg` result). */
4
- interface RowClient {
5
- query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
6
- }
7
- /** Minimal `mysql2/promise` connection/pool surface `execute` resolves to `[rows | ResultSetHeader, fields]`. */
8
- interface Mysql2Execute {
9
- execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
10
- }
3
+ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.js";
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
+ */
9
+ type RowClient = SqlClient;
10
+ /**
11
+ * Minimal `mysql2/promise` connection/pool surface — `execute` resolves to
12
+ * `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global
13
+ * entry's driver surface can never drift from the main entry's, widened with the
14
+ * (optional, structural) shape {@link assertFoundRows}'s `CLIENT_FOUND_ROWS`
15
+ * probe reads.
16
+ *
17
+ * A real `mysql2/promise` connection/pool exposes the merged client-flags
18
+ * bitmask synchronously, but at two different depths depending on which one it
19
+ * is, and NEITHER is in `mysql2`'s own `.d.ts` — its `Pool extends Connection`
20
+ * signature claims a top-level `config`, but at runtime a `mysql2/promise`
21
+ * `Pool` has none; the real value lives one level down, on the core pool it
22
+ * wraps:
23
+ *
24
+ * - a single `Connection`/`PoolConnection` → `connection.config.clientFlags`
25
+ * - a `Pool` (the `createPool({ flags: ["FOUND_ROWS"] })` example above) →
26
+ * `pool.pool.config.connectionConfig.clientFlags`
27
+ *
28
+ * Because those paths are undocumented driver internals, `global-dialect.test.ts`
29
+ * pins them against a REAL `mysql2` pool (built without connecting) rather than
30
+ * only against hand-written doubles — if a `mysql2` release relocates them, the
31
+ * probe would otherwise degrade silently to the warn branch and the OCC guard
32
+ * would go unchecked.
33
+ *
34
+ * Both fields are optional so a minimal `Mysql2Like` test double (only
35
+ * `execute`) safely resolves to "undeterminable" instead of a `TypeError`.
36
+ */
37
+ type Mysql2Execute = Mysql2Like & {
38
+ config?: {
39
+ clientFlags?: number;
40
+ };
41
+ pool?: {
42
+ config?: {
43
+ connectionConfig?: {
44
+ clientFlags?: number;
45
+ };
46
+ };
47
+ };
48
+ };
11
49
  /**
12
- * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
13
- * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
14
- * for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
15
- * OCC (read via `all`), so `run` reports no affected-row count.
16
- */
50
+ * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
51
+ * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
52
+ * for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
53
+ * OCC (read via `all`), so `run` reports no affected-row count.
54
+ *
55
+ * `batch` dispatches every statement concurrently (`Promise.all`) over `client`
56
+ * rather than awaiting each `query` call in turn — `RowClient` only exposes a
57
+ * single-statement `query`, so there is no wire-level multi-statement command
58
+ * to reach for. When `client` is backed by a pool (the common production
59
+ * shape), this genuinely spreads the statements across multiple physical
60
+ * connections instead of serializing one full round trip at a time; against a
61
+ * single connection it still removes the sequential *await*, though the
62
+ * underlying driver may itself queue the sends. Either way it stays
63
+ * non-atomic, at-least-once, and unordered between elements, same as the
64
+ * sequential fallback minus the ordering — safe only for statements whose
65
+ * effects don't depend on each other, which is what every current caller
66
+ * batches (distinct-keyed companion rows).
67
+ */
17
68
  declare const buildPgExec: (client: RowClient) => SqlExec;
18
69
  /**
19
- * Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
20
- * renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
21
- * forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
22
- * for the store's affected-rows OCC guard.
23
- *
24
- * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
25
- * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
26
- * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
27
- * same values reports 0 and the OCC guard raises a spurious conflict.
28
- */
70
+ * Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
71
+ * renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
72
+ * forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
73
+ * for the store's affected-rows OCC guard.
74
+ *
75
+ * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
76
+ * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
77
+ * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
78
+ * same values reports 0 and the OCC guard raises a spurious conflict. Verified
79
+ * once here at construction — see {@link assertFoundRows} — never per statement.
80
+ *
81
+ * `batch` dispatches every statement concurrently (`Promise.all`), same
82
+ * rationale as {@link buildPgExec}'s `batch` — `Mysql2Like` only exposes a
83
+ * single-statement `execute`, so this is "spread across a pool's connections"
84
+ * rather than one wire-level multi-statement command; still non-atomic,
85
+ * at-least-once, and unordered between elements, safe only for statements
86
+ * with no cross-effect (what every current caller batches).
87
+ */
29
88
  declare const buildMysqlExec: (connection: Mysql2Execute) => SqlExec;
30
89
  /**
31
- * **Postgres** dialect. Differs from SQLite only in column types
32
- * (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
33
- * probe, and unique-violation detection (SQLSTATE `23505`).
34
- */
90
+ * **Postgres** dialect. Differs from SQLite only in column types
91
+ * (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
92
+ * probe, and unique-violation detection (SQLSTATE `23505`).
93
+ */
35
94
  declare const postgresDialect: SqlDialect;
36
95
  /**
37
- * **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
38
- * to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
39
- * a no-op update still reports a matched row, see `buildMysqlExec`); bounded
40
- * `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
41
- * prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
42
- * dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
43
- */
96
+ * **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
97
+ * to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
98
+ * a no-op update still reports a matched row, see `buildMysqlExec`); bounded
99
+ * `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
100
+ * prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
101
+ * dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
102
+ */
44
103
  declare const mysqlDialect: SqlDialect;
45
104
  /** Which engine a Hyperdrive-backed `.global()` store targets. */
46
105
  type HyperdriveEngine = "mysql" | "postgres";
@@ -52,16 +111,12 @@ interface CreateHyperdriveGlobalCtxDbOptions extends Omit<SqlCtxDbOptions, "dial
52
111
  exec: SqlExec;
53
112
  }
54
113
  /**
55
- * Build a reactive `.global()` writer backed by a Hyperdrive-reachable
56
- * Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
57
- * {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
58
- * D1 store options.
59
- */
60
- declare const createHyperdriveGlobalCtxDb: ({
61
- engine,
62
- exec,
63
- ...rest
64
- }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
114
+ * Build a reactive `.global()` writer backed by a Hyperdrive-reachable
115
+ * Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
116
+ * {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
117
+ * D1 store options.
118
+ */
119
+ declare const createHyperdriveGlobalCtxDb: ({ engine, exec, ...rest }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
65
120
  /** Convenience: a **Postgres** `.global()` writer from a row-client (postgres.js/pg over Hyperdrive). */
66
121
  declare const createPostgresGlobalCtxDb: (client: RowClient, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
67
122
  /** Convenience: a **MySQL** `.global()` writer from a `mysql2/promise` connection/pool (created with `flags: ["FOUND_ROWS"]`). */
package/dist/global.mjs CHANGED
@@ -1,9 +1 @@
1
- import { createSqlCtxDb } from '@lunora/sql-store';
2
- import { postgresDialect, mysqlDialect } from './packem_shared/mysqlDialect-oNhZ58s8.mjs';
3
- import { buildMysqlExec, buildPgExec } from './packem_shared/buildMysqlExec-DBbCjyq3.mjs';
4
-
5
- const createHyperdriveGlobalCtxDb = ({ engine, exec, ...rest }) => createSqlCtxDb({ ...rest, dialect: engine === "postgres" ? postgresDialect : mysqlDialect, exec });
6
- const createPostgresGlobalCtxDb = (client, options) => createHyperdriveGlobalCtxDb({ ...options, engine: "postgres", exec: buildPgExec(client) });
7
- const createMysqlGlobalCtxDb = (connection, options) => createHyperdriveGlobalCtxDb({ ...options, engine: "mysql", exec: buildMysqlExec(connection) });
8
-
9
- export { buildMysqlExec, buildPgExec, createHyperdriveGlobalCtxDb, createMysqlGlobalCtxDb, createPostgresGlobalCtxDb, mysqlDialect, postgresDialect };
1
+ import{createSqlCtxDb as l}from"@lunora/sql-store";import{postgresDialect as s,mysqlDialect as c}from"./packem_shared/mysqlDialect-DitNAlpV.mjs";import{buildMysqlExec as i,buildPgExec as a}from"./packem_shared/buildMysqlExec-CPwtojyL.mjs";const o=({engine:e,exec:t,...r})=>l({...r,dialect:e==="postgres"?s:c,exec:t}),p=(e,t)=>o({...t,engine:"postgres",exec:a(e)}),g=(e,t)=>o({...t,engine:"mysql",exec:i(e)});export{i as buildMysqlExec,a as buildPgExec,o as createHyperdriveGlobalCtxDb,g as createMysqlGlobalCtxDb,p as createPostgresGlobalCtxDb,c as mysqlDialect,s as postgresDialect};