@lunora/hyperdrive 1.0.0-alpha.115 → 1.0.0-alpha.117

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/README.md CHANGED
@@ -42,7 +42,7 @@ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-sa
42
42
  >
43
43
  > Hyperdrive talks to a database **Lunora does not own**. That breaks two invariants the rest of Lunora relies on:
44
44
  >
45
- > 1. **Non-deterministic (action-only).** A SQL query over Hyperdrive is a network call with an external, mutable result — exactly like `fetch`. It is **forbidden in `query`/`mutation`** (which must be deterministic so the coordinator can re-run them on OCC retry / subscription re-evaluation) and allowed **only in `action`s**. The `hyperdrive_outside_action` advisor lint flags `ctx.sql` used in a query/mutation.
45
+ > 1. **Non-deterministic (action-only).** A SQL query over Hyperdrive is a network call with an external, mutable result — exactly like `fetch`. It is **forbidden in `query`/`mutation`** (which must be deterministic so the coordinator can re-run them on subscription re-evaluation; an OCC conflict surfaces as a `409` to the caller, not an internal retry) and allowed **only in `action`s**. The `hyperdrive_outside_action` advisor lint flags `ctx.sql` used in a query/mutation.
46
46
  > 2. **Non-reactive.** External writes do **not** flow through the Durable-Object / SQLite change-feed, so **Lunora live queries and subscriptions will NOT re-run** when an external Postgres/MySQL row changes. There is no honest way to make external writes reactive here.
47
47
  >
48
48
  > Use Hyperdrive to _read/write your existing DB from an action_. It is the **wrong** tool for "make my Postgres reactive". If you want external data to be reactive, write a **projection** of it into a `defineSchema` DO/D1 table from the action — that write _is_ tracked.
package/dist/global.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DatabaseWriterLike } from '@lunora/shard-engine';
2
2
  import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
3
- import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.mjs";
3
+ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-IgdRydpF.mjs";
4
4
  import { VectorMetric, VectorizeIndexLike } from '@lunora/platform';
5
5
  /**
6
6
  * Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
package/dist/global.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DatabaseWriterLike } from '@lunora/shard-engine';
2
2
  import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
3
- import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-DE1NYxyA.js";
3
+ import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-IgdRydpF.js";
4
4
  import { VectorMetric, VectorizeIndexLike } from '@lunora/platform';
5
5
  /**
6
6
  * Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { H as HyperdriveLike, a as HyperdriveConnection, M as Mysql2Like, S as SqlClient, N as NodePgLike, P as PostgresJsLike } from "./packem_shared/types.d-DE1NYxyA.mjs";
1
+ import { H as HyperdriveLike, a as HyperdriveConnection, M as Mysql2Like, S as SqlClient, N as NodePgLike, P as PostgresJsLike } from "./packem_shared/types.d-IgdRydpF.mjs";
2
2
  /**
3
3
  * Surface a Cloudflare Hyperdrive binding as a connection ready to feed a
4
4
  * user-supplied SQL driver.
@@ -14,9 +14,14 @@ import { H as HyperdriveLike, a as HyperdriveConnection, M as Mysql2Like, S as S
14
14
  * import { createHyperdrive, fromPostgresJs } from "@lunora/hyperdrive";
15
15
  * import postgres from "postgres";
16
16
  *
17
- * // inside an action (never a query/mutation):
18
- * const { connectionString } = createHyperdrive(env.HYPERDRIVE);
19
- * ctx.sql = fromPostgresJs(postgres(connectionString));
17
+ * // Wire the client once, on the app builder — called per shard construction,
18
+ * // not per request. `ctx.sql` is emitted `readonly`; it is never assigned.
19
+ * const app = defineApp<Env>()
20
+ * .shard((env) => env.SHARD)
21
+ * .hyperdrive((env) => fromPostgresJs(postgres(createHyperdrive(env.HYPERDRIVE).connectionString)))
22
+ * .build();
23
+ *
24
+ * // Then, inside an action (never a query/mutation):
20
25
  * const rows = await ctx.sql.query("select id from users where org = $1", [orgId]);
21
26
  * ```
22
27
  * @remarks
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
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-IgdRydpF.js";
2
2
  /**
3
3
  * Surface a Cloudflare Hyperdrive binding as a connection ready to feed a
4
4
  * user-supplied SQL driver.
@@ -14,9 +14,14 @@ import { H as HyperdriveLike, a as HyperdriveConnection, M as Mysql2Like, S as S
14
14
  * import { createHyperdrive, fromPostgresJs } from "@lunora/hyperdrive";
15
15
  * import postgres from "postgres";
16
16
  *
17
- * // inside an action (never a query/mutation):
18
- * const { connectionString } = createHyperdrive(env.HYPERDRIVE);
19
- * ctx.sql = fromPostgresJs(postgres(connectionString));
17
+ * // Wire the client once, on the app builder — called per shard construction,
18
+ * // not per request. `ctx.sql` is emitted `readonly`; it is never assigned.
19
+ * const app = defineApp<Env>()
20
+ * .shard((env) => env.SHARD)
21
+ * .hyperdrive((env) => fromPostgresJs(postgres(createHyperdrive(env.HYPERDRIVE).connectionString)))
22
+ * .build();
23
+ *
24
+ * // Then, inside an action (never a query/mutation):
20
25
  * const rows = await ctx.sql.query("select id from users where org = $1", [orgId]);
21
26
  * ```
22
27
  * @remarks
@@ -88,9 +88,11 @@ interface SqlClient {
88
88
  /**
89
89
  * Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
90
90
  * `query` method `fromNodePg` calls is required, kept structural for testing.
91
+ *
92
+ * Method syntax, not an arrow property — see {@link PostgresJsLike}.
91
93
  */
92
94
  interface NodePgLike {
93
- query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
95
+ query(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<{
94
96
  rows: unknown[];
95
97
  }>;
96
98
  }
@@ -98,16 +100,38 @@ interface NodePgLike {
98
100
  * Structural projection of a `postgres` (postgres.js) tagged-template client.
99
101
  * The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
100
102
  * full control of the parameter list.
103
+ *
104
+ * **`unsafe` is declared with METHOD syntax, and that is load-bearing.** Under
105
+ * `strictFunctionTypes` an arrow PROPERTY is checked contravariantly in its
106
+ * parameters, so a driver whose `unsafe` takes a MUTABLE array — which real
107
+ * postgres.js does (`parameters?: ParameterOrJSON<never>[]`) — is not assignable
108
+ * to one declared `params?: ReadonlyArray<unknown>`. As an arrow property this
109
+ * projection could therefore never accept the package it projects: every
110
+ * consumer got
111
+ * `TS2345: Argument of type 'Sql<{}>' is not assignable to parameter of type
112
+ * 'PostgresJsLike'`, and this repo's own test reached for
113
+ * `as unknown as PostgresJsLike` to get past it. Method syntax is checked
114
+ * bivariantly, which is what a structural projection of someone else's type
115
+ * needs — `readonly unknown[]` and postgres.js's mutable array relate in one
116
+ * direction, which is all bivariance asks for.
101
117
  */
102
118
  interface PostgresJsLike {
103
- unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
119
+ unsafe(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<unknown>;
104
120
  }
105
121
  /**
106
122
  * Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
107
123
  * `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
108
124
  * element as the rows.
125
+ *
126
+ * Method syntax, not an arrow property — see {@link PostgresJsLike} — but here
127
+ * that is necessary and NOT sufficient, so the live-driver test still casts.
128
+ * mysql2 types its second argument as a single `ExecuteValues`, a union of
129
+ * scalars, `ExecuteValues[]` and `{ [key: string]: ExecuteValues }`. Neither
130
+ * direction relates to `ReadonlyArray<unknown>`, so no variance rule can bridge
131
+ * it: closing this needs a deliberate widening of the parameter type here (and
132
+ * of what {@link SqlClient} promises), not a declaration-style change.
109
133
  */
110
134
  interface Mysql2Like {
111
- execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
135
+ execute(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<[unknown, unknown]>;
112
136
  }
113
137
  export { HyperdriveLike as H, Mysql2Like as M, NodePgLike as N, PostgresJsLike as P, SqlClient as S, HyperdriveConnection as a };
@@ -88,9 +88,11 @@ interface SqlClient {
88
88
  /**
89
89
  * Structural projection of a `pg` (node-postgres) `Client`/`Pool`. Only the
90
90
  * `query` method `fromNodePg` calls is required, kept structural for testing.
91
+ *
92
+ * Method syntax, not an arrow property — see {@link PostgresJsLike}.
91
93
  */
92
94
  interface NodePgLike {
93
- query: (text: string, params?: ReadonlyArray<unknown>) => Promise<{
95
+ query(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<{
94
96
  rows: unknown[];
95
97
  }>;
96
98
  }
@@ -98,16 +100,38 @@ interface NodePgLike {
98
100
  * Structural projection of a `postgres` (postgres.js) tagged-template client.
99
101
  * The adapter uses the `.unsafe(text, params)` escape hatch so callers keep
100
102
  * full control of the parameter list.
103
+ *
104
+ * **`unsafe` is declared with METHOD syntax, and that is load-bearing.** Under
105
+ * `strictFunctionTypes` an arrow PROPERTY is checked contravariantly in its
106
+ * parameters, so a driver whose `unsafe` takes a MUTABLE array — which real
107
+ * postgres.js does (`parameters?: ParameterOrJSON<never>[]`) — is not assignable
108
+ * to one declared `params?: ReadonlyArray<unknown>`. As an arrow property this
109
+ * projection could therefore never accept the package it projects: every
110
+ * consumer got
111
+ * `TS2345: Argument of type 'Sql<{}>' is not assignable to parameter of type
112
+ * 'PostgresJsLike'`, and this repo's own test reached for
113
+ * `as unknown as PostgresJsLike` to get past it. Method syntax is checked
114
+ * bivariantly, which is what a structural projection of someone else's type
115
+ * needs — `readonly unknown[]` and postgres.js's mutable array relate in one
116
+ * direction, which is all bivariance asks for.
101
117
  */
102
118
  interface PostgresJsLike {
103
- unsafe: (text: string, params?: ReadonlyArray<unknown>) => Promise<unknown>;
119
+ unsafe(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<unknown>;
104
120
  }
105
121
  /**
106
122
  * Structural projection of a `mysql2/promise` connection/pool. `mysql2`'s
107
123
  * `execute` resolves to a `[rows, fields]` tuple; the adapter takes the first
108
124
  * element as the rows.
125
+ *
126
+ * Method syntax, not an arrow property — see {@link PostgresJsLike} — but here
127
+ * that is necessary and NOT sufficient, so the live-driver test still casts.
128
+ * mysql2 types its second argument as a single `ExecuteValues`, a union of
129
+ * scalars, `ExecuteValues[]` and `{ [key: string]: ExecuteValues }`. Neither
130
+ * direction relates to `ReadonlyArray<unknown>`, so no variance rule can bridge
131
+ * it: closing this needs a deliberate widening of the parameter type here (and
132
+ * of what {@link SqlClient} promises), not a declaration-style change.
109
133
  */
110
134
  interface Mysql2Like {
111
- execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
135
+ execute(this: void, text: string, params?: ReadonlyArray<unknown>): Promise<[unknown, unknown]>;
112
136
  }
113
137
  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.115",
3
+ "version": "1.0.0-alpha.117",
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",
@@ -51,9 +51,9 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@lunora/errors": "1.0.0-alpha.36",
54
- "@lunora/platform": "1.0.0-alpha.30",
55
- "@lunora/shard-engine": "1.0.0-alpha.64",
56
- "@lunora/sql-store": "1.0.0-alpha.116",
54
+ "@lunora/platform": "1.0.0-alpha.32",
55
+ "@lunora/shard-engine": "1.0.0-alpha.69",
56
+ "@lunora/sql-store": "1.0.0-alpha.120",
57
57
  "drizzle-orm": "^0.45.2"
58
58
  },
59
59
  "peerDependencies": {