pg-interleave 0.1.0 → 0.3.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,7 +17,16 @@ 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>;
25
+ resumeNext(): Promise<{
26
+ status: string;
27
+ barrier_id?: string;
28
+ }>;
29
+ barriers(): Promise<string[]>;
20
30
  hasTimeouts(): Promise<boolean>;
21
31
  getPid(client: Client): Promise<number>;
22
32
  intercept(options: InterceptOptions): Promise<BarrierHandle>;
package/dist/index.js CHANGED
@@ -42,12 +42,34 @@ 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) {
48
54
  throw new Error(`Failed to reset proxy: HTTP ${res.status}`);
49
55
  }
50
56
  }
57
+ async resumeNext() {
58
+ const res = await fetch(`${this.controlUrl}/resume-next`, {
59
+ method: "POST",
60
+ });
61
+ if (!res.ok) {
62
+ throw new Error(`Failed to resume next barrier: HTTP ${res.status}`);
63
+ }
64
+ return (await res.json());
65
+ }
66
+ async barriers() {
67
+ const res = await fetch(`${this.controlUrl}/barriers`);
68
+ if (!res.ok) {
69
+ throw new Error(`Failed to fetch active barriers: HTTP ${res.status}`);
70
+ }
71
+ return (await res.json());
72
+ }
51
73
  async hasTimeouts() {
52
74
  const res = await fetch(`${this.controlUrl}/events`);
53
75
  if (!res.ok) {
@@ -76,6 +98,7 @@ class PgInterleaveClient {
76
98
  headers: { "Content-Type": "application/json" },
77
99
  body: JSON.stringify({
78
100
  target_pid: pid ?? null,
101
+ session_tag: options.sessionTag ?? null,
79
102
  query_pattern: pattern,
80
103
  action,
81
104
  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.3.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",