pg-boss 12.18.0 → 12.18.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;CAC/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAE,EAAE,EAAE,sBAAsB,EAAE,GAAG,EAAE,iBAAiB,GAAG,SAAS,CAe1F"}
1
+ {"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;CAC/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAE,EAAE,EAAE,sBAAsB,EAAE,GAAG,EAAE,iBAAiB,GAAG,SAAS,CAQ1F"}
@@ -1,3 +1,4 @@
1
+ import { parsePlaceholders } from "./placeholders.js";
1
2
  /**
2
3
  * Wraps a drizzle-orm transaction as an {@link IDatabase}.
3
4
  *
@@ -18,15 +19,9 @@
18
19
  export function fromDrizzle(tx, sql) {
19
20
  return {
20
21
  async executeSql(text, values) {
21
- if (!values || values.length === 0) {
22
- const strings = Object.assign([text], { raw: [text] });
23
- return tx.execute(sql(strings));
24
- }
25
- // Split on $1, $2, … to get the literal parts, then call sql
26
- // as a tagged template with those parts and the values.
27
- const parts = text.split(/\$\d+/);
22
+ const { parts, reordered } = parsePlaceholders(text, values);
28
23
  const strings = Object.assign([...parts], { raw: [...parts] });
29
- return tx.execute(sql(strings, ...values));
24
+ return tx.execute(sql(strings, ...reordered));
30
25
  }
31
26
  };
32
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"knex.d.ts","sourceRoot":"","sources":["../../src/adapters/knex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAA;CACjF;AAED,wBAAgB,QAAQ,CAAE,GAAG,EAAE,mBAAmB,GAAG,SAAS,CAS7D"}
1
+ {"version":3,"file":"knex.d.ts","sourceRoot":"","sources":["../../src/adapters/knex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAA;CACjF;AAED,wBAAgB,QAAQ,CAAE,GAAG,EAAE,mBAAmB,GAAG,SAAS,CAY7D"}
@@ -1,9 +1,13 @@
1
+ import { parsePlaceholders } from "./placeholders.js";
1
2
  export function fromKnex(trx) {
2
3
  return {
3
4
  async executeSql(text, values) {
4
- // pg-boss emits $1, $2, … placeholders; knex.raw() expects ?
5
- const knexSql = text.replace(/\$(\d+)/g, '?');
6
- const result = await trx.raw(knexSql, values);
5
+ // pg-boss emits $1, $2, … placeholders; knex.raw() expects ? per binding,
6
+ // so each textual occurrence (including reuse of the same $N) must be
7
+ // mapped to its own ? with the value duplicated in textual order.
8
+ const { parts, reordered } = parsePlaceholders(text, values);
9
+ const knexSql = parts.join('?');
10
+ const result = await trx.raw(knexSql, reordered);
7
11
  return { rows: result.rows };
8
12
  }
9
13
  };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parses a SQL string with PostgreSQL-style `$N` placeholders into the
3
+ * literal segments between placeholders and the values in textual order.
4
+ *
5
+ * Handles repeated indexes (e.g. `$2` appearing twice) by duplicating the
6
+ * value at each occurrence, so adapters that target positional `?`-style
7
+ * binders or tagged-template SQL builders stay consistent with what
8
+ * postgres would have produced from the original `$N` form.
9
+ */
10
+ export declare function parsePlaceholders(text: string, values?: readonly unknown[]): {
11
+ parts: string[];
12
+ reordered: unknown[];
13
+ };
14
+ //# sourceMappingURL=placeholders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholders.d.ts","sourceRoot":"","sources":["../../src/adapters/placeholders.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG;IAC7E,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,EAAE,OAAO,EAAE,CAAA;CACrB,CAcA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Parses a SQL string with PostgreSQL-style `$N` placeholders into the
3
+ * literal segments between placeholders and the values in textual order.
4
+ *
5
+ * Handles repeated indexes (e.g. `$2` appearing twice) by duplicating the
6
+ * value at each occurrence, so adapters that target positional `?`-style
7
+ * binders or tagged-template SQL builders stay consistent with what
8
+ * postgres would have produced from the original `$N` form.
9
+ */
10
+ export function parsePlaceholders(text, values) {
11
+ const parts = [];
12
+ const reordered = [];
13
+ // Local /g regex: stateful via lastIndex but never shared across calls.
14
+ const re = /\$(\d+)/g;
15
+ let lastIndex = 0;
16
+ let match;
17
+ while ((match = re.exec(text)) !== null) {
18
+ parts.push(text.slice(lastIndex, match.index));
19
+ reordered.push(values?.[Number(match[1]) - 1]);
20
+ lastIndex = re.lastIndex;
21
+ }
22
+ parts.push(text.slice(lastIndex));
23
+ return { parts, reordered };
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "12.18.0",
3
+ "version": "12.18.1",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",