teraslice-client-js 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/src/assets.d.ts +5 -5
  2. package/dist/src/assets.d.ts.map +1 -1
  3. package/dist/src/assets.js.map +1 -1
  4. package/dist/src/client.d.ts +4 -4
  5. package/dist/src/client.d.ts.map +1 -1
  6. package/dist/src/client.js +5 -3
  7. package/dist/src/client.js.map +1 -1
  8. package/dist/src/ex.d.ts +5 -5
  9. package/dist/src/ex.d.ts.map +1 -1
  10. package/dist/src/ex.js +6 -2
  11. package/dist/src/ex.js.map +1 -1
  12. package/dist/src/executions.d.ts.map +1 -1
  13. package/dist/src/executions.js.map +1 -1
  14. package/dist/src/interfaces.d.ts +3 -4
  15. package/dist/src/interfaces.d.ts.map +1 -1
  16. package/dist/src/job.d.ts +7 -7
  17. package/dist/src/job.d.ts.map +1 -1
  18. package/dist/src/job.js +6 -2
  19. package/dist/src/job.js.map +1 -1
  20. package/dist/src/jobs.d.ts +2 -2
  21. package/dist/src/jobs.d.ts.map +1 -1
  22. package/dist/src/jobs.js.map +1 -1
  23. package/dist/test/assets-spec.js +1 -1
  24. package/dist/test/assets-spec.js.map +1 -1
  25. package/dist/test/client-spec.js +3 -6
  26. package/dist/test/client-spec.js.map +1 -1
  27. package/dist/test/executions-spec.js +1 -1
  28. package/dist/test/executions-spec.js.map +1 -1
  29. package/dist/test/jobs-spec.js +2 -2
  30. package/dist/test/jobs-spec.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +4 -4
  33. package/src/assets.ts +5 -5
  34. package/src/client.ts +13 -11
  35. package/src/ex.ts +12 -8
  36. package/src/executions.ts +4 -4
  37. package/src/interfaces.ts +2 -5
  38. package/src/job.ts +13 -13
  39. package/src/jobs.ts +2 -2
  40. package/test/assets-spec.ts +1 -1
  41. package/test/client-spec.ts +3 -9
  42. package/test/executions-spec.ts +1 -1
  43. package/test/jobs-spec.ts +2 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "teraslice-client-js",
3
3
  "displayName": "Teraslice Client (JavaScript)",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "description": "A Node.js client for teraslice jobs, assets, and cluster references.",
6
6
  "keywords": [
7
7
  "elasticsearch",
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@terascope/types": "^1.1.0",
36
- "@terascope/utils": "^1.1.0",
37
- "auto-bind": "^4.0.0",
38
- "got": "^11.8.3"
36
+ "@terascope/utils": "^1.2.0",
37
+ "auto-bind": "^5.0.1",
38
+ "got": "^13.0.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "nock": "^13.5.5"
package/src/assets.ts CHANGED
@@ -3,7 +3,7 @@ import { Teraslice } from '@terascope/types';
3
3
  import path from 'node:path';
4
4
  import autoBind from 'auto-bind';
5
5
  import Client from './client.js';
6
- import { PostData, SearchOptions, ClientConfig } from './interfaces.js';
6
+ import { PostData, RequestOptions, ClientConfig } from './interfaces.js';
7
7
 
8
8
  export default class Assets extends Client {
9
9
  constructor(config: ClientConfig) {
@@ -30,7 +30,7 @@ export default class Assets extends Client {
30
30
 
31
31
  async remove(
32
32
  id: string,
33
- searchOptions: SearchOptions = {}
33
+ searchOptions: RequestOptions = {}
34
34
  ): Promise<Teraslice.AssetIDResponse> {
35
35
  if (isEmpty(id)) {
36
36
  throw new TSError('Asset delete requires a ID', {
@@ -44,7 +44,7 @@ export default class Assets extends Client {
44
44
 
45
45
  async list(
46
46
  query: Teraslice.SearchQuery = {},
47
- searchOptions: SearchOptions = {}
47
+ searchOptions: RequestOptions = {}
48
48
  ): Promise<Teraslice.AssetRecord[]> {
49
49
  const options = { ...searchOptions, searchParams: query };
50
50
  return this.get('/assets', options);
@@ -53,7 +53,7 @@ export default class Assets extends Client {
53
53
  async getAsset(
54
54
  name: string,
55
55
  version = '',
56
- searchOptions: SearchOptions = {}
56
+ searchOptions: RequestOptions = {}
57
57
  ): Promise<Teraslice.AssetRecord[]> {
58
58
  if (!name || !isString(name)) {
59
59
  throw new TSError('Name is required, and must be of type string', {
@@ -75,7 +75,7 @@ export default class Assets extends Client {
75
75
  name = '',
76
76
  version = '',
77
77
  query: Teraslice.TxtSearchParams = {},
78
- searchOptions: SearchOptions = {}
78
+ searchOptions: RequestOptions = {}
79
79
  ): Promise<string> {
80
80
  if (name && !isString(name)) {
81
81
  throw new TSError('Name must be of type string', {
package/src/client.ts CHANGED
@@ -5,8 +5,8 @@ import {
5
5
  } from '@terascope/utils';
6
6
  import { STATUS_CODES } from 'node:http';
7
7
  import { URL } from 'node:url';
8
- import got, { Got } from 'got';
9
- import { ClientConfig, SearchOptions, RequestOptions } from './interfaces.js';
8
+ import got, { type Got, HTTPError } from 'got';
9
+ import { ClientConfig, RequestOptions } from './interfaces.js';
10
10
 
11
11
  export default class Client {
12
12
  private readonly _apiVersion: string;
@@ -32,12 +32,14 @@ export default class Client {
32
32
  limit: isTest ? 0 : 3,
33
33
  maxRetryAfter: 15000 // 15 seconds
34
34
  },
35
- timeout: config.timeout,
35
+ timeout: {
36
+ request: config.timeout
37
+ },
36
38
  responseType: 'json'
37
39
  });
38
40
  }
39
41
 
40
- async get<T = any>(endpoint: string, options?: SearchOptions): Promise<T> {
42
+ async get<T = any>(endpoint: string, options?: RequestOptions): Promise<T> {
41
43
  return this._makeRequest<T>('get', endpoint, options);
42
44
  }
43
45
 
@@ -49,14 +51,14 @@ export default class Client {
49
51
  return this._makeRequest<T>('put', endpoint, options, data);
50
52
  }
51
53
 
52
- async delete<T = any>(endpoint: string, options?: SearchOptions): Promise<T> {
54
+ async delete<T = any>(endpoint: string, options?: RequestOptions): Promise<T> {
53
55
  return this._makeRequest<T>('delete', endpoint, options);
54
56
  }
55
57
 
56
58
  private async _makeRequest<T = any>(
57
- method: 'get'|'post'|'put'|'delete',
59
+ method: 'get' | 'post' | 'put' | 'delete',
58
60
  endpoint: string,
59
- searchOptions?: RequestOptions|SearchOptions,
61
+ searchOptions?: RequestOptions,
60
62
  data?: any
61
63
  ): Promise<T> {
62
64
  const errorMsg = validateRequestOptions(endpoint, searchOptions);
@@ -93,7 +95,7 @@ export default class Client {
93
95
  ...options,
94
96
  } as any) as any as T;
95
97
  } catch (err) {
96
- if (err instanceof got.HTTPError) {
98
+ if (err instanceof HTTPError) {
97
99
  throw makeErrorFromResponse(err.response);
98
100
  }
99
101
 
@@ -106,7 +108,7 @@ export default class Client {
106
108
  }
107
109
 
108
110
  protected makeOptions(
109
- searchParams: Record<string, any>|undefined, options: RequestOptions | SearchOptions
111
+ searchParams: Record<string, any> | undefined, options: RequestOptions
110
112
  ): RequestOptions {
111
113
  return { ...options, searchParams };
112
114
  }
@@ -175,7 +177,7 @@ function makeErrorFromResponse(response: any): OldErrorOutput {
175
177
  }
176
178
 
177
179
  // TODO: do more validations
178
- function validateRequestOptions(endpoint: string, _options?: RequestOptions|SearchOptions) {
180
+ function validateRequestOptions(endpoint: string, _options?: RequestOptions) {
179
181
  if (!endpoint) {
180
182
  return 'endpoint must not be empty';
181
183
  }
@@ -186,7 +188,7 @@ function validateRequestOptions(endpoint: string, _options?: RequestOptions|Sear
186
188
  }
187
189
 
188
190
  function getRequestOptionsWithData(
189
- data: any, options: RequestOptions|SearchOptions
191
+ data: any, options: RequestOptions
190
192
  ): RequestOptions {
191
193
  if (isPlainObject(data) || Array.isArray(data)) {
192
194
  return { ...options, json: data };
package/src/ex.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import { Teraslice } from '@terascope/types';
6
6
  import autoBind from 'auto-bind';
7
7
  import Client from './client.js';
8
- import { ClientConfig, SearchOptions, RequestOptions } from './interfaces.js';
8
+ import { ClientConfig, RequestOptions } from './interfaces.js';
9
9
 
10
10
  export default class Ex extends Client {
11
11
  private readonly _exId: string;
@@ -19,11 +19,13 @@ export default class Ex extends Client {
19
19
  this._exId = exId;
20
20
  }
21
21
 
22
- id(): string { return this._exId; }
22
+ id(): string {
23
+ return this._exId;
24
+ }
23
25
 
24
26
  async stop(
25
27
  query?: Teraslice.StopQuery,
26
- searchOptions: SearchOptions = {}
28
+ searchOptions: RequestOptions = {}
27
29
  ): Promise<Teraslice.ApiStoppedResponse> {
28
30
  const options = this.makeOptions(query, searchOptions);
29
31
  return this.post(`/ex/${this._exId}/_stop`, null, options);
@@ -31,7 +33,7 @@ export default class Ex extends Client {
31
33
 
32
34
  async pause(
33
35
  query?: Teraslice.SearchQuery,
34
- searchOptions: SearchOptions = {}
36
+ searchOptions: RequestOptions = {}
35
37
  ): Promise<Teraslice.ApiPausedResponse> {
36
38
  const options = this.makeOptions(query, searchOptions);
37
39
  return this.post(`/ex/${this._exId}/_pause`, null, options);
@@ -39,7 +41,7 @@ export default class Ex extends Client {
39
41
 
40
42
  async resume(
41
43
  query?: Teraslice.SearchQuery,
42
- searchOptions: SearchOptions = {}
44
+ searchOptions: RequestOptions = {}
43
45
  ): Promise<Teraslice.ApiResumeResponse> {
44
46
  const options = this.makeOptions(query, searchOptions);
45
47
  return this.post(`/ex/${this._exId}/_resume`, null, options);
@@ -47,7 +49,7 @@ export default class Ex extends Client {
47
49
 
48
50
  async recover(
49
51
  query: Teraslice.RecoverQuery = {},
50
- searchOptions: SearchOptions = {}
52
+ searchOptions: RequestOptions = {}
51
53
  ): Promise<Ex> {
52
54
  const options = this.makeOptions(query, searchOptions);
53
55
  const result: Teraslice.ApiJobCreateResponse = await this.post(`/ex/${this._exId}/_recover`, null, options);
@@ -86,7 +88,7 @@ export default class Ex extends Client {
86
88
  async errors(options?: Teraslice.SearchQuery): Promise<Teraslice.ErrorRecord[]> {
87
89
  return this.get(`/ex/${this._exId}/errors`, {
88
90
  searchParams: options,
89
- } as SearchOptions);
91
+ });
90
92
  }
91
93
 
92
94
  async changeWorkers(
@@ -139,7 +141,9 @@ export default class Ex extends Client {
139
141
  const startTime = Date.now();
140
142
  const options = Object.assign({}, {
141
143
  responseType: 'json',
142
- timeout: intervalMs < 1000 ? 1000 : intervalMs,
144
+ timeout: {
145
+ request: intervalMs < 1000 ? 1000 : intervalMs
146
+ },
143
147
  }, requestOptions);
144
148
 
145
149
  const checkStatus = async (): Promise<Teraslice.ExecutionStatus> => {
package/src/executions.ts CHANGED
@@ -6,7 +6,7 @@ import autoBind from 'auto-bind';
6
6
  import Client from './client.js';
7
7
  import Ex from './ex.js';
8
8
 
9
- import { ClientConfig, SearchOptions } from './interfaces';
9
+ import { ClientConfig, RequestOptions } from './interfaces';
10
10
 
11
11
  type ListOptions = undefined | string | Teraslice.SearchQuery;
12
12
 
@@ -39,7 +39,7 @@ export default class Executions extends Client {
39
39
 
40
40
  async list(options?: ListOptions): Promise<Teraslice.ExecutionConfig[]> {
41
41
  const query = _parseListOptions(options);
42
- return this.get('/ex', { searchParams: query } as SearchOptions);
42
+ return this.get('/ex', { searchParams: query } as RequestOptions);
43
43
  }
44
44
 
45
45
  async errors(
@@ -52,14 +52,14 @@ export default class Executions extends Client {
52
52
  options.searchParams = opts;
53
53
  }
54
54
 
55
- return this.get(`/ex/${exId}/errors`, options as SearchOptions);
55
+ return this.get(`/ex/${exId}/errors`, options as RequestOptions);
56
56
  }
57
57
 
58
58
  if (isPlainObject(exId)) {
59
59
  options.searchParams = exId;
60
60
  }
61
61
 
62
- return this.get('/ex/errors', options as SearchOptions);
62
+ return this.get('/ex/errors', options as RequestOptions);
63
63
  }
64
64
 
65
65
  /**
package/src/interfaces.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Omit } from '@terascope/utils';
2
- import * as got from 'got';
1
+ import { Options } from 'got';
3
2
 
4
3
  export interface ClientConfig {
5
4
  host?: string;
@@ -8,8 +7,6 @@ export interface ClientConfig {
8
7
  timeout?: number;
9
8
  }
10
9
 
11
- export type RequestOptions = got.Options;
12
-
13
- export type SearchOptions = Omit<got.Options, 'searchParams'>;
10
+ export type RequestOptions = Partial<Options>;
14
11
 
15
12
  export type PostData = string | NodeJS.ReadableStream | Buffer;
package/src/job.ts CHANGED
@@ -5,11 +5,7 @@ import {
5
5
  TSError, toHumanTime,
6
6
  } from '@terascope/utils';
7
7
  import { Teraslice } from '@terascope/types';
8
- import {
9
- ClientConfig,
10
- SearchOptions,
11
- RequestOptions
12
- } from './interfaces.js';
8
+ import { ClientConfig, RequestOptions } from './interfaces.js';
13
9
  import Client from './client.js';
14
10
 
15
11
  /*
@@ -39,7 +35,9 @@ export default class Job extends Client {
39
35
  autoBind(this);
40
36
  }
41
37
 
42
- id(): string { return this._jobId; }
38
+ id(): string {
39
+ return this._jobId;
40
+ }
43
41
 
44
42
  async slicer(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionList> {
45
43
  return this.get(`/jobs/${this._jobId}/slicer`, requestOptions);
@@ -51,7 +49,7 @@ export default class Job extends Client {
51
49
 
52
50
  async start(
53
51
  query?: Teraslice.SearchQuery,
54
- searchOptions: SearchOptions = {}
52
+ searchOptions: RequestOptions = {}
55
53
  ): Promise<Teraslice.ApiJobCreateResponse> {
56
54
  const options = this.makeOptions(query, searchOptions);
57
55
  return this.post(`/jobs/${this._jobId}/_start`, null, options);
@@ -59,7 +57,7 @@ export default class Job extends Client {
59
57
 
60
58
  async stop(
61
59
  query?: Teraslice.StopQuery,
62
- searchOptions: SearchOptions = {}
60
+ searchOptions: RequestOptions = {}
63
61
  ): Promise<Teraslice.ApiStoppedResponse> {
64
62
  const options = this.makeOptions(query, searchOptions);
65
63
  return this.post(`/jobs/${this._jobId}/_stop`, null, options);
@@ -67,7 +65,7 @@ export default class Job extends Client {
67
65
 
68
66
  async pause(
69
67
  query?: Teraslice.SearchQuery,
70
- searchOptions: SearchOptions = {}
68
+ searchOptions: RequestOptions = {}
71
69
  ): Promise<Teraslice.ApiPausedResponse> {
72
70
  const options = this.makeOptions(query, searchOptions);
73
71
  return this.post(`/jobs/${this._jobId}/_pause`, null, options);
@@ -75,7 +73,7 @@ export default class Job extends Client {
75
73
 
76
74
  async resume(
77
75
  query?: Teraslice.SearchQuery,
78
- searchOptions: SearchOptions = {}
76
+ searchOptions: RequestOptions = {}
79
77
  ): Promise<Teraslice.ApiResumeResponse> {
80
78
  const options = this.makeOptions(query, searchOptions);
81
79
  return this.post(`/jobs/${this._jobId}/_resume`, null, options);
@@ -83,7 +81,7 @@ export default class Job extends Client {
83
81
 
84
82
  async recover(
85
83
  query: Teraslice.RecoverQuery = {},
86
- searchOptions: SearchOptions = {}
84
+ searchOptions: RequestOptions = {}
87
85
  ): Promise<Teraslice.ApiJobCreateResponse> {
88
86
  const options = this.makeOptions(query, searchOptions);
89
87
  return this.post(`/jobs/${this._jobId}/_recover`, null, options);
@@ -136,7 +134,9 @@ export default class Job extends Client {
136
134
  const startTime = Date.now();
137
135
  const options = Object.assign({}, {
138
136
  responseType: 'json',
139
- timeout: intervalMs < 1000 ? 1000 : intervalMs,
137
+ timeout: {
138
+ request: intervalMs < 1000 ? 1000 : intervalMs
139
+ },
140
140
  }, requestOptions);
141
141
  let exId: string;
142
142
 
@@ -192,7 +192,7 @@ export default class Job extends Client {
192
192
 
193
193
  async errors(
194
194
  query: Teraslice.SearchQuery = {},
195
- searchOptions: SearchOptions = {}
195
+ searchOptions: RequestOptions = {}
196
196
  ): Promise<Teraslice.ErrorRecord[]> {
197
197
  return this.get(`/jobs/${this._jobId}/errors`, this.makeOptions(query, searchOptions));
198
198
  }
package/src/jobs.ts CHANGED
@@ -3,7 +3,7 @@ import { Teraslice } from '@terascope/types';
3
3
  import autoBind from 'auto-bind';
4
4
  import Client from './client.js';
5
5
  import Job from './job.js';
6
- import { SearchOptions, ClientConfig } from './interfaces.js';
6
+ import { RequestOptions, ClientConfig } from './interfaces.js';
7
7
 
8
8
  export default class Jobs extends Client {
9
9
  constructor(config: ClientConfig) {
@@ -27,7 +27,7 @@ export default class Jobs extends Client {
27
27
 
28
28
  async list(
29
29
  query?: Teraslice.JobSearchParams,
30
- searchOptions: SearchOptions = {}
30
+ searchOptions: RequestOptions = {}
31
31
  ): Promise<Teraslice.JobConfig[]> {
32
32
  return this.get('/jobs', this.makeOptions(query, searchOptions));
33
33
  }
@@ -73,7 +73,7 @@ describe('Teraslice Assets', () => {
73
73
  // See issue: https://github.com/nock/nock/issues/2595
74
74
  // teraslice/e2e/test/cases/assets/simple-spec.ts covers this test case
75
75
  // eslint-disable-next-line jest/no-disabled-tests
76
- xdescribe('when called with a stream', () => {
76
+ describe.skip('when called with a stream', () => {
77
77
  const testFilePath = path.join(dirname, 'fixtures', 'test.txt');
78
78
  const contents = fs.readFileSync(testFilePath, 'utf-8');
79
79
  const idResponse: AssetIDResponse = { _id: 'some-asset-id' };
@@ -84,9 +84,7 @@ describe('Teraslice Client', () => {
84
84
  it('should resolve with the response from the server', async () => {
85
85
  const results = await client.get('/hello', {
86
86
  headers: { 'Some-Header': 'yes' },
87
- // @ts-expect-error
88
-
89
- query: { hello: true }
87
+ searchParams: { hello: 'true' }
90
88
  });
91
89
  expect(results).toEqual({ example: 'hello' });
92
90
  });
@@ -100,9 +98,7 @@ describe('Teraslice Client', () => {
100
98
  });
101
99
 
102
100
  it('should resolve with the response from the server', async () => {
103
- // @ts-expect-error
104
-
105
- const results = await client.get('/hello', { query: { hello: true } });
101
+ const results = await client.get('/hello', { searchParams: { hello: 'true' } });
106
102
  expect(results).toEqual({ example: 'hello' });
107
103
  });
108
104
  });
@@ -411,9 +407,7 @@ describe('Teraslice Client', () => {
411
407
  });
412
408
 
413
409
  it('should resolve with the response from the server', async () => {
414
- // @ts-expect-error
415
-
416
- const results = await client.delete('/hello', { query: { hello: true } });
410
+ const results = await client.delete('/hello', { searchParams: { hello: 'true' } });
417
411
  expect(results).toEqual(response);
418
412
  });
419
413
  });
@@ -252,7 +252,7 @@ describe('Teraslice Executions', () => {
252
252
  });
253
253
 
254
254
  it('should resolve json results from Teraslice', async () => {
255
- const results = await executions.errors('foo', { from: 10, });
255
+ const results = await executions.errors('foo', { from: 10 });
256
256
  expect(results).toEqual(errors);
257
257
  });
258
258
  });
package/test/jobs-spec.ts CHANGED
@@ -179,9 +179,9 @@ describe('Teraslice Jobs', () => {
179
179
  });
180
180
  });
181
181
 
182
- describe('when called with an query and search objects', () => {
182
+ describe('when called with a query and search objects', () => {
183
183
  const searchOptions = { headers: { 'Some-Header': 'yes' } };
184
- const queryOptions = { active: true } as const;
184
+ const queryOptions = { active: true, size: 10 };
185
185
 
186
186
  beforeEach(() => {
187
187
  scope.get('/jobs')