Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/getTransactionQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2021 RelationalAI, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

import { Command } from 'commander';

import { Client, readConfig } from '../index.node';
import { show } from './show';

async function run(id: string, profile?: string) {
const config = await readConfig(profile);
const client = new Client(config);
const result = await client.getTransactionQuery(id);

show(result);
}

(async () => {
const program = new Command();

const options = program
.requiredOption('--id <type>', 'transaction id')
.option('-p, --profile <type>', 'profile', 'default')
.parse(process.argv)
.opts();

try {
await run(options.id, options.profile);
} catch (error: any) {
console.error(error.toString());
}
})();
10 changes: 10 additions & 0 deletions src/api/transaction/transactionAsyncApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ describe('TransactionAsyncApi', () => {
expect(result).toEqual(response);
});

it('should get transaction query', async () => {
const response = 'query-text';
const scope = nock(baseUrl).get(`${path}/id1/query`).reply(200, response);
const result = await api.getTransactionQuery('id1');

scope.done();

expect(result).toEqual(response);
});

it('should cancel transaction', async () => {
const response = {};
const scope = nock(baseUrl).post(`${path}/id1/cancel`).reply(200, response);
Expand Down
6 changes: 6 additions & 0 deletions src/api/transaction/transactionAsyncApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class TransactionAsyncApi extends Base {
return result;
}

async getTransactionQuery(transactionId: string) {
const result = await this.get<string>(`${ENDPOINT}/${transactionId}/query`);

return result;
}

async cancelTransaction(transactionId: string) {
const result = await this.post<CancelResponse>(
`${ENDPOINT}/${transactionId}/cancel`,
Expand Down
4 changes: 3 additions & 1 deletion src/api/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ export type TransactionAsync = {
finished_at?: number;
duration?: number;
read_only: boolean;
last_requested_interval: string;
last_requested_interval: number;
response_format_version: string;
query: string;
query_size: number;
language: string;
user_agent: string;
abort_reason?: string;
tags?: string[];
Expand Down