From 86b58b855b8bc1937fbc0ff7b4a654397d0b0afb Mon Sep 17 00:00:00 2001 From: Denis Gursky Date: Mon, 3 Apr 2023 11:12:40 -0400 Subject: [PATCH] added getTransactionQuery --- examples/getTransactionQuery.ts | 44 +++++++++++++++++++ .../transaction/transactionAsyncApi.test.ts | 10 +++++ src/api/transaction/transactionAsyncApi.ts | 6 +++ src/api/transaction/types.ts | 4 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 examples/getTransactionQuery.ts diff --git a/examples/getTransactionQuery.ts b/examples/getTransactionQuery.ts new file mode 100644 index 0000000..50d50cc --- /dev/null +++ b/examples/getTransactionQuery.ts @@ -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 ', 'transaction id') + .option('-p, --profile ', 'profile', 'default') + .parse(process.argv) + .opts(); + + try { + await run(options.id, options.profile); + } catch (error: any) { + console.error(error.toString()); + } +})(); diff --git a/src/api/transaction/transactionAsyncApi.test.ts b/src/api/transaction/transactionAsyncApi.test.ts index bf51b31..3a75a01 100644 --- a/src/api/transaction/transactionAsyncApi.test.ts +++ b/src/api/transaction/transactionAsyncApi.test.ts @@ -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); diff --git a/src/api/transaction/transactionAsyncApi.ts b/src/api/transaction/transactionAsyncApi.ts index fc523fa..e97051d 100644 --- a/src/api/transaction/transactionAsyncApi.ts +++ b/src/api/transaction/transactionAsyncApi.ts @@ -96,6 +96,12 @@ export class TransactionAsyncApi extends Base { return result; } + async getTransactionQuery(transactionId: string) { + const result = await this.get(`${ENDPOINT}/${transactionId}/query`); + + return result; + } + async cancelTransaction(transactionId: string) { const result = await this.post( `${ENDPOINT}/${transactionId}/cancel`, diff --git a/src/api/transaction/types.ts b/src/api/transaction/types.ts index 6335ba0..029530d 100644 --- a/src/api/transaction/types.ts +++ b/src/api/transaction/types.ts @@ -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[];