Skip to content

Commit

Permalink
added PIT APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Gupta committed Dec 16, 2022
1 parent 2f840e5 commit bb949f4
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 0 deletions.
67 changes: 67 additions & 0 deletions api/api/create_pit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

'use strict';

/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
const acceptedQuerystring = [
'allow_partial_pit_creation',
'keep_alive',
'preference',
'routing',
'pretty',
'human',
'error_trace',
'source',
'filter_path',
];
const snakeCase = {
allowPartialPitCreation: 'allow_partial_pit_creation',
keepAlive: 'keep_alive',
errorTrace: 'error_trace',
filterPath: 'filter_path',
};

function createPitApi(params, options, callback) {
[params, options, callback] = normalizeArguments(params, options, callback);

// check required parameters
if (params['index'] == null) {
const err = new this[kConfigurationError]('Missing required parameter: index');
return handleError(err, callback);
}

if (params['keep_alive'] == null) {
const err = new this[kConfigurationError]('Missing required parameter: keep_alive');
return handleError(err, callback);
}

let { method, body, index, ...querystring } = params;
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);

let path = '';
if (method == null) method = 'POST';
path = '/' + encodeURIComponent(index) + '/' + '_search' + '/' + 'point_in_time';

// build request object
const request = {
method,
path,
body: body || '',
querystring,
};

return this.transport.request(request, options, callback);
}

module.exports = createPitApi;
41 changes: 41 additions & 0 deletions api/api/delete_all_pits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

'use strict';

/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
const acceptedQuerystring = ['pretty', 'human', 'error_trace', 'source', 'filter_path'];
const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path' };

function deleteAllPitsApi(params, options, callback) {
[params, options, callback] = normalizeArguments(params, options, callback);

let { method, body, ...querystring } = params;
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);

let path = '';
if (method == null) method = 'DELETE';
path = '/' + '_search' + '/' + 'point_in_time' + '/' + '_all';

// build request object
const request = {
method,
path,
body: body || '',
querystring,
};

return this.transport.request(request, options, callback);
}

module.exports = deleteAllPitsApi;
47 changes: 47 additions & 0 deletions api/api/delete_pit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

'use strict';

/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
const acceptedQuerystring = ['pretty', 'human', 'error_trace', 'source', 'filter_path'];
const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path' };

function deletePitApi(params, options, callback) {
[params, options, callback] = normalizeArguments(params, options, callback);

// check required parameters
if (params['body'] == null) {
const err = new this[kConfigurationError]('Missing required parameter: body');
return handleError(err, callback);
}

let { method, body, ...querystring } = params;
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);

let path = '';
if (method == null) method = 'DELETE';
path = '/' + '_search' + '/' + 'point_in_time';

// build request object
const request = {
method,
path,
body: body || '',
querystring,
};

return this.transport.request(request, options, callback);
}

module.exports = deletePitApi;
41 changes: 41 additions & 0 deletions api/api/get_all_pits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

'use strict';

/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
const acceptedQuerystring = ['pretty', 'human', 'error_trace', 'source', 'filter_path'];
const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path' };

function getAllPitsApi(params, options, callback) {
[params, options, callback] = normalizeArguments(params, options, callback);

let { method, body, ...querystring } = params;
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);

let path = '';
if (method == null) method = 'GET';
path = '/' + '_search' + '/' + 'point_in_time' + '/' + '_all';

// build request object
const request = {
method,
path,
body: null,
querystring,
};

return this.transport.request(request, options, callback);
}

module.exports = getAllPitsApi;
28 changes: 28 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ const clearScrollApi = require('./api/clear_scroll');
const ClusterApi = require('./api/cluster');
const countApi = require('./api/count');
const createApi = require('./api/create');
const createPitApi = require('./api/create_pit');
const DanglingIndicesApi = require('./api/dangling_indices');
const deleteApi = require('./api/delete');
const deleteAllPitsApi = require('./api/delete_all_pits');
const deleteByQueryApi = require('./api/delete_by_query');
const deleteByQueryRethrottleApi = require('./api/delete_by_query_rethrottle');
const deletePitApi = require('./api/delete_pit');
const deleteScriptApi = require('./api/delete_script');
const existsApi = require('./api/exists');
const existsSourceApi = require('./api/exists_source');
const explainApi = require('./api/explain');
const FeaturesApi = require('./api/features');
const fieldCapsApi = require('./api/field_caps');
const getApi = require('./api/get');
const getAllPitsApi = require('./api/get_all_pits');
const getScriptApi = require('./api/get_script');
const getScriptContextApi = require('./api/get_script_context');
const getScriptLanguagesApi = require('./api/get_script_languages');
Expand Down Expand Up @@ -109,15 +113,19 @@ OpenSearchAPI.prototype.bulk = bulkApi;
OpenSearchAPI.prototype.clearScroll = clearScrollApi;
OpenSearchAPI.prototype.count = countApi;
OpenSearchAPI.prototype.create = createApi;
OpenSearchAPI.prototype.createPit = createPitApi;
OpenSearchAPI.prototype.delete = deleteApi;
OpenSearchAPI.prototype.deleteAllPits = deleteAllPitsApi;
OpenSearchAPI.prototype.deleteByQuery = deleteByQueryApi;
OpenSearchAPI.prototype.deleteByQueryRethrottle = deleteByQueryRethrottleApi;
OpenSearchAPI.prototype.deletePit = deletePitApi;
OpenSearchAPI.prototype.deleteScript = deleteScriptApi;
OpenSearchAPI.prototype.exists = existsApi;
OpenSearchAPI.prototype.existsSource = existsSourceApi;
OpenSearchAPI.prototype.explain = explainApi;
OpenSearchAPI.prototype.fieldCaps = fieldCapsApi;
OpenSearchAPI.prototype.get = getApi;
OpenSearchAPI.prototype.getAllPits = getAllPitsApi;
OpenSearchAPI.prototype.getScript = getScriptApi;
OpenSearchAPI.prototype.getScriptContext = getScriptContextApi;
OpenSearchAPI.prototype.getScriptLanguages = getScriptLanguagesApi;
Expand Down Expand Up @@ -167,6 +175,11 @@ Object.defineProperties(OpenSearchAPI.prototype, {
return this[kCluster];
},
},
create_pit: {
get() {
return this.createPit;
},
},
danglingIndices: {
get() {
if (this[kDanglingIndices] === null) {
Expand All @@ -180,6 +193,11 @@ Object.defineProperties(OpenSearchAPI.prototype, {
return this.danglingIndices;
},
},
delete_all_pits: {
get() {
return this.deleteAllPits;
},
},
delete_by_query: {
get() {
return this.deleteByQuery;
Expand All @@ -190,6 +208,11 @@ Object.defineProperties(OpenSearchAPI.prototype, {
return this.deleteByQueryRethrottle;
},
},
delete_pit: {
get() {
return this.deletePit;
},
},
delete_script: {
get() {
return this.deleteScript;
Expand All @@ -213,6 +236,11 @@ Object.defineProperties(OpenSearchAPI.prototype, {
return this.fieldCaps;
},
},
get_all_pits: {
get() {
return this.getAllPits;
},
},
get_script: {
get() {
return this.getScript;
Expand Down
64 changes: 64 additions & 0 deletions api/new.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ declare class Client {
options: TransportRequestOptions,
callback: callbackFn<T.CreateResponse, TContext>
): TransportRequestCallback;
createPit<TContext = unknown>(
params?: T.PointInTimeCreateRequest,
options?: TransportRequestOptions
): TransportRequestPromise<ApiResponse<T.PointInTimeCreateResponse, TContext>>;
createPit<TContext = unknown>(
callback: callbackFn<T.PointInTimeCreateResponse, TContext>
): TransportRequestCallback;
createPit<TContext = unknown>(
params: T.PointInTimeCreateRequest,
callback: callbackFn<T.PointInTimeCreateResponse, TContext>
): TransportRequestCallback;
createPit<TContext = unknown>(
params: T.PointInTimeCreateRequest,
options: TransportRequestOptions,
callback: callbackFn<T.PointInTimeCreateResponse, TContext>
): TransportRequestCallback;
danglingIndices: {
deleteDanglingIndex<TContext = unknown>(
params?: TODO,
Expand Down Expand Up @@ -550,6 +566,22 @@ declare class Client {
options: TransportRequestOptions,
callback: callbackFn<T.DeleteResponse, TContext>
): TransportRequestCallback;
deleteAllPits<TContext = unknown>(
params?: T.PointInTimeDeleteAllRequest,
options?: TransportRequestOptions
): TransportRequestPromise<ApiResponse<T.PointInTimeDeleteAllResponse, TContext>>;
deleteAllPits<TContext = unknown>(
callback: callbackFn<T.PointInTimeDeleteAllResponse, TContext>
): TransportRequestCallback;
deleteAllPits<TContext = unknown>(
params: T.PointInTimeDeleteAllRequest,
callback: callbackFn<T.PointInTimeDeleteAllResponse, TContext>
): TransportRequestCallback;
deleteAllPits<TContext = unknown>(
params: T.PointInTimeDeleteAllRequest,
options: TransportRequestOptions,
callback: callbackFn<T.PointInTimeDeleteAllResponse, TContext>
): TransportRequestCallback;
deleteByQuery<TContext = unknown>(
params: T.DeleteByQueryRequest,
options?: TransportRequestOptions
Expand All @@ -576,6 +608,22 @@ declare class Client {
options: TransportRequestOptions,
callback: callbackFn<T.DeleteByQueryRethrottleResponse, TContext>
): TransportRequestCallback;
deletePit<TContext = unknown>(
params?: T.PointInTimeDeleteRequest,
options?: TransportRequestOptions
): TransportRequestPromise<ApiResponse<T.PointInTimeDeleteResponse, TContext>>;
deletePit<TContext = unknown>(
callback: callbackFn<T.PointInTimeDeleteResponse, TContext>
): TransportRequestCallback;
deletePit<TContext = unknown>(
params: T.PointInTimeDeleteRequest,
callback: callbackFn<T.PointInTimeDeleteResponse, TContext>
): TransportRequestCallback;
deletePit<TContext = unknown>(
params: T.PointInTimeDeleteRequest,
options: TransportRequestOptions,
callback: callbackFn<T.PointInTimeDeleteResponse, TContext>
): TransportRequestCallback;
deleteScript<TContext = unknown>(
params: T.DeleteScriptRequest,
options?: TransportRequestOptions
Expand Down Expand Up @@ -689,6 +737,22 @@ declare class Client {
options: TransportRequestOptions,
callback: callbackFn<T.GetResponse<TDocument>, TContext>
): TransportRequestCallback;
getAllPits<TContext = unknown>(
params?: T.PointInTimeGetAllRequest,
options?: TransportRequestOptions
): TransportRequestPromise<ApiResponse<T.PointInTimeGetAllResponse, TContext>>;
getAllPits<TContext = unknown>(
callback: callbackFn<T.PointInTimeGetAllResponse, TContext>
): TransportRequestCallback;
getAllPits<TContext = unknown>(
params: T.PointInTimeGetAllRequest,
callback: callbackFn<T.PointInTimeGetAllResponse, TContext>
): TransportRequestCallback;
getAllPits<TContext = unknown>(
params: T.PointInTimeGetAllRequest,
options: TransportRequestOptions,
callback: callbackFn<T.PointInTimeGetAllResponse, TContext>
): TransportRequestCallback;
getScript<TContext = unknown>(
params: T.GetScriptRequest,
options?: TransportRequestOptions
Expand Down
Loading

0 comments on commit bb949f4

Please sign in to comment.