@lunora/hyperdrive 1.0.0-alpha.82 → 1.0.0-alpha.84

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 CHANGED
@@ -9,10 +9,43 @@ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxy
9
9
  type RowClient = SqlClient;
10
10
  /**
11
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.
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`.
14
36
  */
15
- type Mysql2Execute = Mysql2Like;
37
+ type Mysql2Execute = Mysql2Like & {
38
+ config?: {
39
+ clientFlags?: number;
40
+ };
41
+ pool?: {
42
+ config?: {
43
+ connectionConfig?: {
44
+ clientFlags?: number;
45
+ };
46
+ };
47
+ };
48
+ };
16
49
  /**
17
50
  * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
18
51
  * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
@@ -42,7 +75,8 @@ declare const buildPgExec: (client: RowClient) => SqlExec;
42
75
  * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
43
76
  * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
44
77
  * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
45
- * same values reports 0 and the OCC guard raises a spurious conflict.
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.
46
80
  *
47
81
  * `batch` dispatches every statement concurrently (`Promise.all`), same
48
82
  * rationale as {@link buildPgExec}'s `batch` — `Mysql2Like` only exposes a
package/dist/global.d.ts CHANGED
@@ -9,10 +9,43 @@ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxy
9
9
  type RowClient = SqlClient;
10
10
  /**
11
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.
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`.
14
36
  */
15
- type Mysql2Execute = Mysql2Like;
37
+ type Mysql2Execute = Mysql2Like & {
38
+ config?: {
39
+ clientFlags?: number;
40
+ };
41
+ pool?: {
42
+ config?: {
43
+ connectionConfig?: {
44
+ clientFlags?: number;
45
+ };
46
+ };
47
+ };
48
+ };
16
49
  /**
17
50
  * Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
18
51
  * `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
@@ -42,7 +75,8 @@ declare const buildPgExec: (client: RowClient) => SqlExec;
42
75
  * **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
43
76
  * (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
44
77
  * counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
45
- * same values reports 0 and the OCC guard raises a spurious conflict.
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.
46
80
  *
47
81
  * `batch` dispatches every statement concurrently (`Promise.all`), same
48
82
  * rationale as {@link buildPgExec}'s `batch` — `Mysql2Like` only exposes a
package/dist/global.mjs CHANGED
@@ -1 +1 @@
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-DriYb1l9.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};
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};
@@ -0,0 +1 @@
1
+ import{LunoraError as o}from"@lunora/errors";const n=2,s=new WeakSet,i=r=>{const e=r.config?.clientFlags;if(typeof e=="number")return e;const t=r.pool?.config?.connectionConfig?.clientFlags;return typeof t=="number"?t:void 0},c=r=>{const e=i(r);if(e===void 0){if(s.has(r))return;s.add(r),console.warn('@lunora/hyperdrive: could not determine whether this MySQL connection negotiated CLIENT_FOUND_ROWS (the driver exposes no flag introspection). If it was NOT created with the `CLIENT_FOUND_ROWS` flag (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`), an idempotent patch/replace that rewrites identical values may report 0 affectedRows and raise a spurious OCC ConflictError.');return}if((e&n)===0)throw new o("INTERNAL",'@lunora/hyperdrive: this MySQL connection was not created with the `CLIENT_FOUND_ROWS` flag (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows` counts changed (not matched) rows, so an idempotent patch/replace that rewrites identical values reports 0 and the OCC guard raises a spurious conflict.')},u=r=>({all:(e,t)=>r.query(e,t),batch:async e=>{await Promise.all(e.map(t=>r.query(t.sql,t.params)))},run:async(e,t)=>(await r.query(e,t),{rowsAffected:0})}),d=r=>(c(r),{all:async(e,t)=>{const[a]=await r.execute(e,t);return a},batch:async e=>{await Promise.all(e.map(t=>r.execute(t.sql,t.params)))},run:async(e,t)=>{const[a]=await r.execute(e,t);return{rowsAffected:a.affectedRows??0}}});export{d as buildMysqlExec,u as buildPgExec};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/hyperdrive",
3
- "version": "1.0.0-alpha.82",
3
+ "version": "1.0.0-alpha.84",
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,8 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/shard-engine": "1.0.0-alpha.30",
54
- "@lunora/sql-store": "1.0.0-alpha.82",
53
+ "@lunora/errors": "1.0.0-alpha.22",
54
+ "@lunora/shard-engine": "1.0.0-alpha.32",
55
+ "@lunora/sql-store": "1.0.0-alpha.84",
55
56
  "drizzle-orm": "^0.45.2"
56
57
  },
57
58
  "peerDependencies": {
@@ -1 +0,0 @@
1
- const u=e=>({all:(r,a)=>e.query(r,a),batch:async r=>{await Promise.all(r.map(a=>e.query(a.sql,a.params)))},run:async(r,a)=>(await e.query(r,a),{rowsAffected:0})}),t=e=>({all:async(r,a)=>{const[s]=await e.execute(r,a);return s},batch:async r=>{await Promise.all(r.map(a=>e.execute(a.sql,a.params)))},run:async(r,a)=>{const[s]=await e.execute(r,a);return{rowsAffected:s.affectedRows??0}}});export{t as buildMysqlExec,u as buildPgExec};