pg-interleave 0.1.0 → 0.2.0

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/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { Client } from "pg";
2
2
  export interface InterceptOptions {
3
3
  client?: Client;
4
4
  clientPid?: number;
5
+ sessionTag?: string;
5
6
  onQueryMatch: string | RegExp;
6
7
  action?: "PAUSE_BEFORE_QUERY" | "PAUSE_AFTER_RESPONSE" | "pause_before_query" | "pause_after_response";
7
8
  times?: number;
@@ -16,6 +17,10 @@ export declare class BarrierHandle {
16
17
  export declare class PgInterleaveClient {
17
18
  private readonly controlUrl;
18
19
  constructor(controlUrl?: string);
20
+ /**
21
+ * Appends session routing comment to an SQL query for connection pool compatibility
22
+ */
23
+ static tag(sql: string, sessionTag: string): string;
19
24
  reset(): Promise<void>;
20
25
  hasTimeouts(): Promise<boolean>;
21
26
  getPid(client: Client): Promise<number>;
package/dist/index.js CHANGED
@@ -42,6 +42,12 @@ class PgInterleaveClient {
42
42
  constructor(controlUrl = "http://127.0.0.1:9090") {
43
43
  this.controlUrl = controlUrl;
44
44
  }
45
+ /**
46
+ * Appends session routing comment to an SQL query for connection pool compatibility
47
+ */
48
+ static tag(sql, sessionTag) {
49
+ return `/* interleave: session=${sessionTag} */ ${sql}`;
50
+ }
45
51
  async reset() {
46
52
  const res = await fetch(`${this.controlUrl}/reset`, { method: "POST" });
47
53
  if (!res.ok) {
@@ -76,6 +82,7 @@ class PgInterleaveClient {
76
82
  headers: { "Content-Type": "application/json" },
77
83
  body: JSON.stringify({
78
84
  target_pid: pid ?? null,
85
+ session_tag: options.sessionTag ?? null,
79
86
  query_pattern: pattern,
80
87
  action,
81
88
  times: options.times ?? 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-interleave",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Deterministic PostgreSQL wire-protocol proxy client for concurrency and chaos testing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",