Skip to content

Commit 71ebb83

Browse files
feat: FIR-46459 support Firebolt-Remove-Parameters header in node sdk
1 parent 4fc08c2 commit 71ebb83

File tree

9 files changed

+618
-2
lines changed

9 files changed

+618
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ npm-debug.log*
99
.#*
1010
coverage/
1111
allure-results/
12+
.idea

src/connection/base.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ export const defaultResponseSettings = {
2020
};
2121

2222
const updateParametersHeader = "Firebolt-Update-Parameters";
23-
const allowedUpdateParameters = ["database"];
23+
const allowedUpdateParameters = [
24+
"database",
25+
"transaction_id",
26+
"transaction_sequence_id"
27+
];
2428
const updateEndpointHeader = "Firebolt-Update-Endpoint";
2529
const resetSessionHeader = "Firebolt-Reset-Session";
30+
const removeParametersHeader = "Firebolt-Remove-Parameters";
2631
const immutableParameters = ["database", "account_id", "output_format"];
2732
const testConnectionQuery = "SELECT 1";
2833

@@ -117,6 +122,14 @@ export abstract class Connection {
117122
};
118123
}
119124

125+
private handleRemoveParametersHeader(headerValue: string) {
126+
const removeParameters = headerValue.split(",");
127+
128+
removeParameters.forEach(key => {
129+
delete this.parameters[key.trim()];
130+
});
131+
}
132+
120133
private handleResetSessionHeader() {
121134
const remainingParameters: Record<string, string> = {};
122135
for (const key in this.parameters) {
@@ -159,6 +172,11 @@ export abstract class Connection {
159172
if (updateEndpointValue) {
160173
await this.handleUpdateEndpointHeader(updateEndpointValue);
161174
}
175+
176+
const removeParametersValue = headers.get(removeParametersHeader);
177+
if (removeParametersValue) {
178+
this.handleRemoveParametersHeader(removeParametersValue);
179+
}
162180
}
163181

164182
abstract executeAsync(

src/connection/connection_v1.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,22 @@ export class ConnectionV1 extends BaseConnection {
9393
"Asynchronous execution is not supported in this Firebolt version."
9494
);
9595
}
96+
97+
async begin(): Promise<void> {
98+
throw new Error(
99+
"Transaction management is not supported in this Firebolt version."
100+
);
101+
}
102+
103+
async commit(): Promise<void> {
104+
throw new Error(
105+
"Transaction management is not supported in this Firebolt version."
106+
);
107+
}
108+
109+
async rollback(): Promise<void> {
110+
throw new Error(
111+
"Transaction management is not supported in this Firebolt version."
112+
);
113+
}
96114
}

src/connection/connection_v2.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,16 @@ export class ConnectionV2 extends BaseConnection {
142142
const settings = { internal: [{ auto_start_stop_control: "ignore" }] };
143143
await this.execute("select 1", { settings });
144144
}
145+
146+
async begin(): Promise<void> {
147+
await this.execute("BEGIN TRANSACTION");
148+
}
149+
150+
async commit(): Promise<void> {
151+
await this.execute("COMMIT");
152+
}
153+
154+
async rollback(): Promise<void> {
155+
await this.execute("ROLLBACK");
156+
}
145157
}

src/http/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const DEFAULT_ERROR = "Server error";
2626
const DEFAULT_USER_AGENT = systemInfoString();
2727

2828
const PROTOCOL_VERSION_HEADER = "Firebolt-Protocol-Version";
29-
const PROTOCOL_VERSION = "2.3";
29+
const PROTOCOL_VERSION = "2.4";
3030
const createSocket = HttpsAgent.prototype.createSocket;
3131

3232
const agentOptions = {

test/integration/v1/index.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,42 @@ describe("integration test", () => {
209209

210210
data.pipe(process.stdout);
211211
});
212+
213+
describe("Transaction methods", () => {
214+
it("throws error for begin transaction", async () => {
215+
const firebolt = Firebolt({
216+
apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string
217+
});
218+
219+
const connection = await firebolt.connect(connectionParams);
220+
221+
await expect(connection.begin()).rejects.toThrow(
222+
"Transaction management is not supported in this Firebolt version."
223+
);
224+
});
225+
226+
it("throws error for commit", async () => {
227+
const firebolt = Firebolt({
228+
apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string
229+
});
230+
231+
const connection = await firebolt.connect(connectionParams);
232+
233+
await expect(connection.commit()).rejects.toThrow(
234+
"Transaction management is not supported in this Firebolt version."
235+
);
236+
});
237+
238+
it("throws error for rollback", async () => {
239+
const firebolt = Firebolt({
240+
apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string
241+
});
242+
243+
const connection = await firebolt.connect(connectionParams);
244+
245+
await expect(connection.rollback()).rejects.toThrow(
246+
"Transaction management is not supported in this Firebolt version."
247+
);
248+
});
249+
});
212250
});

0 commit comments

Comments
 (0)