pg-interleave 0.3.2 → 0.5.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 +2 -0
- package/dist/index.js +23 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface InterceptOptions {
|
|
|
4
4
|
clientPid?: number;
|
|
5
5
|
sessionTag?: string;
|
|
6
6
|
onQueryMatch: string | RegExp;
|
|
7
|
+
withParams?: Array<string | number | boolean | null>;
|
|
7
8
|
action?: "PAUSE_BEFORE_QUERY" | "PAUSE_AFTER_RESPONSE" | "pause_before_query" | "pause_after_response";
|
|
8
9
|
times?: number;
|
|
9
10
|
}
|
|
@@ -31,6 +32,7 @@ export declare class PgInterleaveClient {
|
|
|
31
32
|
getPid(client: Client): Promise<number>;
|
|
32
33
|
intercept(options: InterceptOptions): Promise<BarrierHandle>;
|
|
33
34
|
injectTornCommit(client: Client, times?: number): Promise<void>;
|
|
35
|
+
flushTrace(): Promise<void>;
|
|
34
36
|
injectDeadlock(options: {
|
|
35
37
|
client?: Client;
|
|
36
38
|
clientPid?: number;
|
package/dist/index.js
CHANGED
|
@@ -93,16 +93,24 @@ class PgInterleaveClient {
|
|
|
93
93
|
const action = options.action
|
|
94
94
|
? options.action.toLowerCase()
|
|
95
95
|
: "pause_before_query";
|
|
96
|
+
const serializedParams = options.withParams !== undefined
|
|
97
|
+
? options.withParams.map((p) => (p === null || p === undefined ? null : String(p)))
|
|
98
|
+
: undefined;
|
|
99
|
+
const body = {
|
|
100
|
+
query_pattern: pattern,
|
|
101
|
+
action,
|
|
102
|
+
times: options.times ?? 1,
|
|
103
|
+
};
|
|
104
|
+
if (pid !== undefined)
|
|
105
|
+
body.target_pid = pid;
|
|
106
|
+
if (options.sessionTag !== undefined)
|
|
107
|
+
body.session_tag = options.sessionTag;
|
|
108
|
+
if (serializedParams !== undefined)
|
|
109
|
+
body.with_params = serializedParams;
|
|
96
110
|
const res = await fetch(`${this.controlUrl}/intercept`, {
|
|
97
111
|
method: "POST",
|
|
98
112
|
headers: { "Content-Type": "application/json" },
|
|
99
|
-
body: JSON.stringify(
|
|
100
|
-
target_pid: pid ?? null,
|
|
101
|
-
session_tag: options.sessionTag ?? null,
|
|
102
|
-
query_pattern: pattern,
|
|
103
|
-
action,
|
|
104
|
-
times: options.times ?? 1,
|
|
105
|
-
}),
|
|
113
|
+
body: JSON.stringify(body),
|
|
106
114
|
});
|
|
107
115
|
if (!res.ok) {
|
|
108
116
|
const errBody = await res.text();
|
|
@@ -126,6 +134,14 @@ class PgInterleaveClient {
|
|
|
126
134
|
throw new Error(`Failed to inject torn commit: HTTP ${res.status}`);
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
async flushTrace() {
|
|
138
|
+
const res = await fetch(`${this.controlUrl}/flush-trace`, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
});
|
|
141
|
+
if (!res.ok) {
|
|
142
|
+
throw new Error(`Failed to flush trace: HTTP ${res.status}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
129
145
|
async injectDeadlock(options) {
|
|
130
146
|
let pid = options.clientPid;
|
|
131
147
|
if (!pid && options.client) {
|