diff --git a/src/services/search/__tests__/__snapshots__/task.spec.ts.snap b/src/services/search/__tests__/__snapshots__/task.spec.ts.snap new file mode 100644 index 00000000..e863bab7 --- /dev/null +++ b/src/services/search/__tests__/__snapshots__/task.spec.ts.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`search – task get 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "search.api.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://search.api.globus.org/v1/task/a1b2c3d4-e5f6-7890-abcd-ef1234567890", +} +`; + +exports[`search – task getAll 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "search.api.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://search.api.globus.org/v1/task_list/524de2f6-d1a6-4b49-9286-d8dccb4196ae", +} +`; + +exports[`search – task next get 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "search.api.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://search.api.globus.org/v1/task/a1b2c3d4-e5f6-7890-abcd-ef1234567890", +} +`; + +exports[`search – task next getAll 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "search.api.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://search.api.globus.org/v1/task_list/524de2f6-d1a6-4b49-9286-d8dccb4196ae", +} +`; diff --git a/src/services/search/__tests__/task.spec.ts b/src/services/search/__tests__/task.spec.ts new file mode 100644 index 00000000..1ca83669 --- /dev/null +++ b/src/services/search/__tests__/task.spec.ts @@ -0,0 +1,63 @@ +import { task } from '..'; +import { mirror } from '../../../__mocks__/handlers'; + +const INDEX_ID = '524de2f6-d1a6-4b49-9286-d8dccb4196ae'; +const TASK_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'; + +describe('search – task', () => { + test('get', async () => { + const request = await task.get(TASK_ID); + const { + req: { url, method, headers }, + } = await mirror(request); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + + test('getAll', async () => { + const request = await task.getAll(INDEX_ID); + const { + req: { url, method, headers }, + } = await mirror(request); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + + describe('next', () => { + test('get', async () => { + const { + req: { url, method, headers }, + } = await mirror( + await task.next.get({ + task_id: TASK_ID, + }), + ); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + + test('getAll', async () => { + const { + req: { url, method, headers }, + } = await mirror( + await task.next.getAll({ + index_id: INDEX_ID, + }), + ); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + }); +}); diff --git a/src/services/search/index.ts b/src/services/search/index.ts index 5e7f163d..a82d6db9 100644 --- a/src/services/search/index.ts +++ b/src/services/search/index.ts @@ -19,3 +19,4 @@ export * as query from './service/query.js'; export * as subject from './service/subject.js'; export * as entry from './service/entry.js'; export * as index from './service/search-index.js'; +export * as task from './service/task.js'; diff --git a/src/services/search/service/task.ts b/src/services/search/service/task.ts new file mode 100644 index 00000000..738c5947 --- /dev/null +++ b/src/services/search/service/task.ts @@ -0,0 +1,102 @@ +import { serviceRequest } from '../../shared.js'; +import { ID, SCOPES } from '../config.js'; +import { RESOURCE_SERVERS } from '../../auth/config.js'; +import { createServiceMethodFactory } from '../../factory.js'; + +import type { JSONFetchResponse, SDKOptions, ServiceMethodOptions } from '../../types.js'; +import type { OpenAPI } from '../index.js'; + +/** + * Task document types from OpenAPI + */ +export type Task = OpenAPI.components['schemas']['Task']; +export type TaskList = OpenAPI.components['schemas']['TaskList']; +export type TaskSubmitResponse = OpenAPI.components['schemas']['TaskSubmitResponse']; + +/** + * Get a task by ID. + * @param task_id The UUID of the task to retrieve. + * + * @see https://docs.globus.org/api/search/reference/get_task/ + */ +export const get = function ( + task_id: string, + options?: ServiceMethodOptions, + sdkOptions?: SDKOptions, +): Promise> { + return serviceRequest( + { + service: ID, + scope: SCOPES.SEARCH, + path: `/v1/task/${task_id}`, + }, + options, + sdkOptions, + ); +}; + +/** + * Get a list of tasks for an index. + * @param index_id The UUID of the index. + * + * @see https://docs.globus.org/api/search/reference/task_list/ + */ +export const getAll = function ( + index_id: string, + options?: ServiceMethodOptions, + sdkOptions?: SDKOptions, +): Promise> { + return serviceRequest( + { + service: ID, + scope: SCOPES.SEARCH, + path: `/v1/task_list/${index_id}`, + }, + options, + sdkOptions, + ); +}; + +/** + * @private + */ +export const next = { + /** + * Get a task by ID. + * @param task_id The UUID of the task to retrieve. + * + * @see https://docs.globus.org/api/search/reference/get_task/ + */ + get: createServiceMethodFactory({ + service: ID, + resource_server: RESOURCE_SERVERS[ID], + path: `/v1/task/{task_id}`, + }).generate< + { + request?: { + query?: never; + data?: never; + }; + }, + JSONFetchResponse + >(), + /** + * Get a list of tasks for an index. + * @param index_id The UUID of the index. + * + * @see https://docs.globus.org/api/search/reference/task_list/ + */ + getAll: createServiceMethodFactory({ + service: ID, + resource_server: RESOURCE_SERVERS[ID], + path: `/v1/task_list/{index_id}`, + }).generate< + { + request?: { + query?: never; + data?: never; + }; + }, + JSONFetchResponse + >(), +};