Skip to content

Commit

Permalink
Merge pull request #1 from timursaurus/ts-timur
Browse files Browse the repository at this point in the history
Ts timur
  • Loading branch information
timursaurus authored Mar 22, 2023
2 parents d09d5f7 + 8f8d680 commit 13ba397
Show file tree
Hide file tree
Showing 43 changed files with 21,719 additions and 3,277 deletions.
5 changes: 5 additions & 0 deletions api/api/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


export default function getApi(params, options, callback) {

}
98 changes: 98 additions & 0 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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.
*
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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 { ApiResponse, Context, TransportRequestOptions, TransportRequestPromise } from "lib/Transport";
import { ClientOptions, RequestParams } from "..";
import { kConfigurationError } from './utils'

const kCat = Symbol('Cat');
const kCluster = Symbol('Cluster');
const kDanglingIndices = Symbol('DanglingIndices');
const kFeatures = Symbol('Features');
const kIndices = Symbol('Indices');
const kIngest = Symbol('Ingest');
const kNodes = Symbol('Nodes');
const kShutdown = Symbol('Shutdown');
const kSnapshot = Symbol('Snapshot');
const kTasks = Symbol('Tasks');

export default class OpenSearchAPI {
[kCat]: symbol | null
[kCluster]: symbol | null
[kDanglingIndices]: symbol | null
[kFeatures]: symbol | null
[kIndices]: symbol | null
[kIngest]: symbol | null
[kNodes]: symbol | null
[kShutdown]: symbol | null
[kSnapshot]: symbol | null
[kTasks]: symbol | null
// TODO: FIX. No configuration error on ClientOptions
[kConfigurationError]: symbol | null

constructor(opts: ClientOptions) {
this[kCat] = null;
this[kCluster] = null;
this[kDanglingIndices] = null;
this[kFeatures] = null;
this[kIndices] = null;
this[kIngest] = null;
this[kNodes] = null;
this[kShutdown] = null;
this[kSnapshot] = null;
this[kTasks] = null;
// TODO: FIX. No configuration error on ClientOptions. It's in root index.ts
this[kConfigurationError] = null;
}
// get<TResponse = Record<string, any>, TContext = Context>(
// params?: RequestParams.SnapshotGet,
// options?: TransportRequestOptions
// ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;

// get<TResponse = Record<string, any>, TContext = Context>(
// callback: callbackFn<TResponse, TContext>
// ): TransportRequestCallback;

// get<TResponse = Record<string, any>, TContext = Context>(
// params: RequestParams.SnapshotGet,
// callback: callbackFn<TResponse, TContext>
// ): TransportRequestCallback;

// get<TResponse = Record<string, any>, TContext = Context>(
// params: RequestParams.SnapshotGet,
// options: TransportRequestOptions,
// callback: callbackFn<TResponse, TContext>
// ): TransportRequestCallback;

// cat<TResponse = Record<string, any>, TContext = Context>(params: RequestParams.SnapshotGet, callback: callbackFn<TResponse, TContext>)
// cat<TResponse = Record<string, any>, TContext = Context>(params: RequestParams.SnapshotGet, options: TransportRequestOptions): TransportRequestPromise<ApiResponse<TResponse, TContext>> {

// }
}

68 changes: 68 additions & 0 deletions api/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.
*
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
*/

const result = { body: null, statusCode: null, headers: null, warnings: null };
export const kConfigurationError = Symbol('Configuration error');

export function handleError(err: symbol, callback: Function) {
if (callback) {
process.nextTick(callback, err, result);
return { then: NOOP, catch: NOOP, abort: NOOP };
}
return Promise.reject(err);
}

export function snakeCaseKeys(
acceptedQuerystring: string[],
snakeCase: Record<string, string>,
querystring: Record<string, string>
) {
const target = {};
const keys = Object.keys(querystring);
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i];
target[snakeCase[key] || key] = querystring[key];
}
return target;
}

export function normalizeArguments(params, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
if (typeof params === 'function' || params == null) {
callback = params;
params = {};
options = {};
}
return [params, options, callback];
}

export function NOOP(): void {}
Loading

0 comments on commit 13ba397

Please sign in to comment.