Skip to content

Commit 8c7d1c7

Browse files
feat: FIR-46459 support Firebolt-Remove-Parameters header in node sdk
1 parent d01887e commit 8c7d1c7

File tree

8 files changed

+617
-2
lines changed

8 files changed

+617
-2
lines changed

src/connection/base.ts

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

2424
const updateParametersHeader = "Firebolt-Update-Parameters";
25-
const allowedUpdateParameters = ["database"];
25+
const allowedUpdateParameters = [
26+
"database",
27+
"transaction_id",
28+
"transaction_sequence_id"
29+
];
2630
const updateEndpointHeader = "Firebolt-Update-Endpoint";
2731
const resetSessionHeader = "Firebolt-Reset-Session";
32+
const removeParametersHeader = "Firebolt-Remove-Parameters";
2833
const immutableParameters = ["database", "account_id", "output_format"];
2934
const testConnectionQuery = "SELECT 1";
3035

@@ -119,6 +124,14 @@ export abstract class Connection {
119124
};
120125
}
121126

127+
private handleRemoveParametersHeader(headerValue: string) {
128+
const removeParameters = headerValue.split(",");
129+
130+
removeParameters.forEach(key => {
131+
delete this.parameters[key.trim()];
132+
});
133+
}
134+
122135
private handleResetSessionHeader() {
123136
const remainingParameters: Record<string, string> = {};
124137
for (const key in this.parameters) {
@@ -161,6 +174,11 @@ export abstract class Connection {
161174
if (updateEndpointValue) {
162175
await this.handleUpdateEndpointHeader(updateEndpointValue);
163176
}
177+
178+
const removeParametersValue = headers.get(removeParametersHeader);
179+
if (removeParametersValue) {
180+
this.handleRemoveParametersHeader(removeParametersValue);
181+
}
164182
}
165183

166184
abstract executeAsync(

src/connection/connection_v1.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,22 @@ export class ConnectionV1 extends BaseConnection {
103103
"Stream execution is not supported in this Firebolt version."
104104
);
105105
}
106+
107+
async begin(): Promise<void> {
108+
throw new Error(
109+
"Transaction management is not supported in this Firebolt version."
110+
);
111+
}
112+
113+
async commit(): Promise<void> {
114+
throw new Error(
115+
"Transaction management is not supported in this Firebolt version."
116+
);
117+
}
118+
119+
async rollback(): Promise<void> {
120+
throw new Error(
121+
"Transaction management is not supported in this Firebolt version."
122+
);
123+
}
106124
}

src/connection/connection_v2.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,16 @@ export class ConnectionV2 extends BaseConnection {
218218
const settings = { internal: [{ auto_start_stop_control: "ignore" }] };
219219
await this.execute("select 1", { settings });
220220
}
221+
222+
async begin(): Promise<void> {
223+
await this.execute("BEGIN TRANSACTION");
224+
}
225+
226+
async commit(): Promise<void> {
227+
await this.execute("COMMIT");
228+
}
229+
230+
async rollback(): Promise<void> {
231+
await this.execute("ROLLBACK");
232+
}
221233
}

src/http/node.ts

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

3030
const PROTOCOL_VERSION_HEADER = "Firebolt-Protocol-Version";
31-
const PROTOCOL_VERSION = "2.3";
31+
const PROTOCOL_VERSION = "2.4";
3232
const createSocket = HttpsAgent.prototype.createSocket;
3333

3434
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)