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
14 changes: 7 additions & 7 deletions src/__tests__/async-task.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SearchParams, Task, TaskRequest, TaskStatus } from 'linkup-sdk';
import { pollTask, runAsyncTaskFlow } from '../commands/async-task';
import { pollTask, runTaskFlow } from '../commands/async-task';
import { captureConsole } from './helpers/capture';
import { makeTask } from './helpers/fixtures';

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('pollTask', () => {
});
});

describe('runAsyncTaskFlow', () => {
describe('runTaskFlow', () => {
type TestResponse = { answer: string };

beforeEach(() => {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('runAsyncTaskFlow', () => {
const runSync = jest.fn().mockResolvedValue({ answer: 'done' });
const { errorSpy, logSpy } = captureConsole();

await runAsyncTaskFlow({
await runTaskFlow({
buildRequest,
client,
formatSync,
Expand All @@ -137,7 +137,7 @@ describe('runAsyncTaskFlow', () => {
const runSync = jest.fn();
const { logSpy } = captureConsole();

await runAsyncTaskFlow({
await runTaskFlow({
async: true,
buildRequest,
client,
Expand All @@ -158,7 +158,7 @@ describe('runAsyncTaskFlow', () => {
});
const { logSpy } = captureConsole();

await runAsyncTaskFlow({
await runTaskFlow({
async: true,
buildRequest,
client,
Expand All @@ -184,7 +184,7 @@ describe('runAsyncTaskFlow', () => {
});
const { logSpy } = captureConsole();

await runAsyncTaskFlow({
await runTaskFlow({
async: true,
buildRequest,
client,
Expand All @@ -207,7 +207,7 @@ describe('runAsyncTaskFlow', () => {
});
const { errorSpy, logSpy } = captureConsole();

await runAsyncTaskFlow({
await runTaskFlow({
async: true,
buildRequest,
client,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/async-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function waitForTask<TTask extends PollableTask>(
}
}

export async function runAsyncTaskFlow<TParams, TResponse>(
export async function runTaskFlow<TParams, TResponse>(
options: AsyncTaskFlowOptions<TParams, TResponse>,
): Promise<void> {
if (options.wait && !options.async) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolveGlobals } from '../client';
import { exitWithError, formatErrorLine } from '../output/errors';
import { formatFetch } from '../output/fetch';
import { formatTaskErrorLine } from '../output/task-errors';
import { createPollIntervalOption, createTimeoutOption, runAsyncTaskFlow } from './async-task';
import { createPollIntervalOption, createTimeoutOption, runTaskFlow } from './async-task';

type FetchCommandOptions = {
renderJs?: boolean;
Expand Down Expand Up @@ -47,7 +47,7 @@ async function runFetch(
const { client, json } = resolveGlobals(command);
const params = buildFetchParams(url, options);

await runAsyncTaskFlow({
await runTaskFlow({
async: options.async,
buildRequest: buildFetchTaskRequest,
client,
Expand Down
37 changes: 19 additions & 18 deletions src/commands/research.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ function printResearchResult(result: PollTaskResult<ResearchTask>, json: boolean
printLines(lines);
}

async function waitForResearchAndPrint(
client: ReturnType<typeof resolveGlobals>['client'],
id: string,
options: { pollInterval: number; timeout: number },
json: boolean,
): Promise<void> {
const result = await waitForTask({
getTask: taskId => client.getResearch(taskId),
id,
json,
label: 'Researching...',
pollIntervalSeconds: options.pollInterval,
timeoutSeconds: options.timeout,
});
printResearchResult(result, json);
}

async function runResearchSubmit(
queryParts: string[],
options: ResearchCommandOptions,
Expand Down Expand Up @@ -210,15 +227,7 @@ async function runResearchSubmit(
const task = await client.research(params);

if (options.wait) {
const result = await waitForTask({
getTask: id => client.getResearch(id),
id: task.id,
json,
label: 'Researching...',
pollIntervalSeconds: options.pollInterval,
timeoutSeconds: options.timeout,
});
printResearchResult(result, json);
await waitForResearchAndPrint(client, task.id, options, json);
return;
}

Expand All @@ -238,15 +247,7 @@ async function runResearchGet(

try {
if (options.wait) {
const result = await waitForTask({
getTask: taskId => client.getResearch(taskId),
id,
json,
label: 'Researching...',
pollIntervalSeconds: options.pollInterval,
timeoutSeconds: options.timeout,
});
printResearchResult(result, json);
await waitForResearchAndPrint(client, id, options, json);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolveGlobals } from '../client';
import { exitWithError, formatErrorLine } from '../output/errors';
import { formatSearch } from '../output/search';
import { formatTaskErrorLine } from '../output/task-errors';
import { createPollIntervalOption, createTimeoutOption, runAsyncTaskFlow } from './async-task';
import { createPollIntervalOption, createTimeoutOption, runTaskFlow } from './async-task';
import { parseDateOption, parseDomainList, parsePositiveInt } from './option-parsers';
import { queryUsageLines, resolveQueryOrExit } from './query-input';
import {
Expand Down Expand Up @@ -177,7 +177,7 @@ async function runSearch(
console.error(warning);
}

await runAsyncTaskFlow({
await runTaskFlow({
async: options.async,
buildRequest: buildSearchTaskRequest,
client,
Expand Down