cloudflare-next-intl 0.8.33 → 0.8.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/README.md CHANGED
@@ -609,7 +609,7 @@ Every query in the array is executed sequentially in a single transaction block/
609
609
 
610
610
  Either way, a failure on any statement rolls back every statement that ran before it in the transaction.
611
611
 
612
- Each result is the `{ rows, rowCount }` shape. Because the callback only builds queries, a later statement in a `.transaction()` callback cannot read an earlier one's result — build every statement from arguments/closures you already have. `await`ing a query directly inside `.transaction()` throws immediately to prevent running queries outside the transaction boundary.
612
+ Each result is the `{ rows, rowCount }` shape. Because the callback only builds queries, a later statement in a `.transaction()` callback cannot read an earlier one's result — build every statement from arguments/closures you already have. The handle passed into the callback is a fully working Drizzle query builder — chain `.insert()`/`.select()`/`.where()`/etc. freely — but it has no real connection behind it: `await`ing a query directly (instead of calling `.toSQL()` and returning it) throws once execution is actually attempted, not on the property access or chaining itself, to prevent running queries outside the transaction boundary.
613
613
 
614
614
  #### Supabase mode and REST translation
615
615
 
@@ -101,7 +101,7 @@ async function postgresDb(drizzleHandle, rawClient) {
101
101
  * interleave statements into this transaction.
102
102
  */
103
103
  async function runPostgresTransaction(rawClient, build) {
104
- const queries = await build(buildOnlyDb());
104
+ const queries = await callBuild(build);
105
105
  await rawClient.query('begin');
106
106
  try {
107
107
  const results = [];
@@ -126,14 +126,31 @@ async function runPostgresTransaction(rawClient, build) {
126
126
  * output) throws immediately here instead of hanging or silently running
127
127
  * outside the batch.
128
128
  */
129
- function buildOnlyDb() {
130
- const throwIfExecuted = () => {
129
+ async function buildOnlyDb() {
130
+ const { drizzle } = await import('drizzle-orm/pg-proxy');
131
+ return drizzle(() => {
131
132
  throw new Error('db: this Drizzle handle is for building statements only — call `.toSQL()` on each ' +
132
133
  'query and return the array, do not `await`/execute it directly. Awaiting a query ' +
133
134
  'inside a Supabase-mode db.transaction() callback runs it outside the batch, with no ' +
134
135
  'atomicity, which is exactly what `.transaction()` exists to prevent.');
135
- };
136
- return new Proxy({}, { get: () => throwIfExecuted });
136
+ });
137
+ }
138
+ /**
139
+ * Runs `build` against a fresh build-only handle, unwrapping pg-proxy's
140
+ * `Failed query: ...` wrapper (with the real message on `.cause`) so a
141
+ * caller who awaits a query instead of collecting `.toSQL()` sees the
142
+ * build-only guidance directly, not the wrapper's generic text.
143
+ */
144
+ async function callBuild(build) {
145
+ try {
146
+ return await build(await buildOnlyDb());
147
+ }
148
+ catch (error) {
149
+ const cause = error?.cause;
150
+ if (error instanceof Error && cause instanceof Error)
151
+ throw cause;
152
+ throw error;
153
+ }
137
154
  }
138
155
  /**
139
156
  * Runs a query as the **anonymous** role: no transaction, no role switch, no
@@ -299,7 +316,7 @@ async function runTransaction(supabase, bearerToken, build) {
299
316
  'unavailable while `db.supabase.rawSql` is `false`. Install cfni_exec.sql and drop ' +
300
317
  '`rawSql: false`, or use `db.connectionString` for a direct Postgres connection instead.');
301
318
  }
302
- const queries = await build(buildOnlyDb());
319
+ const queries = await callBuild(build);
303
320
  const batchQueries = queries.map((query) => ({ sql: query.sql, params: query.params }));
304
321
  return runTransactionBatch(supabase, bearerToken, batchQueries);
305
322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.8.33",
3
+ "version": "0.8.34",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",