Skip to content

Commit

Permalink
chore: init typescript rewrite
Browse files Browse the repository at this point in the history
Signed-off-by: Timur Bolotov <[email protected]>
  • Loading branch information
timursaurus committed Mar 25, 2023
0 parents commit 6983dff
Show file tree
Hide file tree
Showing 14 changed files with 1,286 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# coverage output
coverage.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# mac files
.DS_Store

# vim swap files
*.swp

#Jetbrains editor folder
.idea

# opensearch repo or binary files
opensearch*
!opensearch_dashboards*
!opensearchDashboards*

# documentation
docs/

# temporary
tmp/

test/benchmarks/macro/fixtures/*

*-junit.xml

.cache

test/bundlers/**/bundle.js
test/bundlers/parcel-test/.parcel-cache
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@opensearch-project/opensearch",
"version": "1.0.0",
"description": "The official OpenSearch client for Node.js",
"type": "module",
"main": "index.js",
"scripts": {
"test": "vitest",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build": ""
},
"repository": {
"type": "git",
"url": "git+https://github.com/timursaurus/opensearch-ts.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/timursaurus/opensearch-ts/issues"
},
"homepage": "https://github.com/timursaurus/opensearch-ts#readme",
"devDependencies": {
"@types/debug": "^4.1.7",
"vitest": "^0.29.7"
},
"dependencies": {
"debug": "^4.3.4",
"querystring": "^0.2.1",
"secure-json-parse": "^2.7.0"
}
}
Empty file added src/client.ts
Empty file.
202 changes: 202 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* 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 } from '@/types/transport';
// import { ErrorCause, ErrorResponseBase } from '@/types/internal';

export class OpenSearchClientError extends Error {
name: string;
constructor(message: string) {
super(message);
this.name = 'OpenSearchClientError';
}
}

// export class TimeoutError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// name: string;
// message: string;
// meta?: ApiResponse<TResponse, TContext>;
// constructor(message: string, meta?: ApiResponse<TResponse, TContext>) {
// super(message);
// Error.captureStackTrace(this, TimeoutError);
// this.name = 'TimeoutError';
// this.message = message ?? 'Timeout Error';
// this.meta = meta;
// }
// }

// export class ConnectionError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// name: string;
// message: string;
// meta?: ApiResponse<TResponse, TContext>;
// constructor(message: string, meta?: ApiResponse<TResponse, TContext>) {
// super(message);
// Error.captureStackTrace(this, ConnectionError);
// this.name = 'ConnectionError';
// this.message = message ?? 'Connection Error';
// this.meta = meta;
// }
// }

// export class NoLivingConnectionsError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// name: string;
// message: string;
// meta: ApiResponse<TResponse, TContext>;

// constructor(message: string, meta: ApiResponse<TResponse, TContext>) {
// super(message);
// Error.captureStackTrace(this, NoLivingConnectionsError);
// this.name = 'NoLivingConnectionsError';
// this.message =
// message ??
// 'Given the configuration, the ConnectionPool was not able to find a usable Connection for this request.';
// this.meta = meta;
// }
// }

export class SerializationError extends OpenSearchClientError {
name: string;
message: string;
data: Record<string, unknown>;
constructor(message: string, data: Record<string, unknown>) {
super(message);
Error.captureStackTrace(this, SerializationError);
this.name = 'SerializationError';
this.message = message ?? 'Serialization Error';
this.data = data;
}
}

export class DeserializationError extends OpenSearchClientError {
name: string;
message: string;
data: string;
constructor(message: string, data: string) {
super(message);
Error.captureStackTrace(this, DeserializationError);
this.name = 'DeserializationError';
this.message = message ?? 'Deserialization Error';
this.data = data;
}
}

// export class ConfigurationError extends OpenSearchClientError {
// constructor(message: string) {
// super(message);
// Error.captureStackTrace(this, ConfigurationError);
// this.name = 'ConfigurationError';
// this.message = message ?? 'Configuration Error';
// }
// }

// export class ResponseError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// name: string;
// message: string;
// meta: ApiResponse<TResponse, TContext>;
// constructor(meta: ApiResponse) {
// super('Response Error');
// Error.captureStackTrace(this, ResponseError);
// this.name = 'ResponseError';
// if (meta.body?.error?.type) {
// const error = meta.body.error as ErrorCause;
// if (Array.isArray(error.root_cause)) {
// this.message = `${error.type}: ${error.root_cause
// .map((entry) => `[${entry.type}] Reason: ${entry.reason}`)
// .join('; ')}`;
// } else {
// this.message = error.type;
// }
// } else {
// this.message = 'Response Error';
// }
// this.meta = meta as ApiResponse<TResponse, TContext>;
// }

// get body() {
// return this.meta.body;
// }

// get statusCode() {
// const body = this.meta.body as ErrorResponseBase;
// if (typeof body === 'object' && typeof body.status === 'number') {
// return body.status;
// }
// return this.meta.statusCode;
// }

// get headers() {
// return this.meta.headers;
// }

// toString() {
// return JSON.stringify(this.meta.body);
// }
// }

// export class RequestAbortedError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// name: string;
// message: string;
// meta?: ApiResponse<TResponse, TContext>;
// constructor(message: string, meta?: ApiResponse<TResponse, TContext>) {
// super(message);
// Error.captureStackTrace(this, RequestAbortedError);
// this.name = 'RequestAbortedError';
// this.message = message || 'Request aborted';
// this.meta = meta;
// }
// }

// export class NotCompatibleError<
// TResponse = Record<string, unknown>,
// TContext = Context
// > extends OpenSearchClientError {
// meta: ApiResponse<TResponse, TContext>;
// constructor(meta: ApiResponse<TResponse, TContext>) {
// super('Not Compatible Error');
// Error.captureStackTrace(this, NotCompatibleError);
// this.name = 'NotCompatibleError';
// this.message = 'The client noticed that the server is not a supported distribution';
// this.meta = meta;
// }
// }
30 changes: 30 additions & 0 deletions src/symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
*/

export const kJsonOptions = Symbol('Secure JSON parse options');
1 change: 1 addition & 0 deletions src/transport/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './serializer'
Loading

0 comments on commit 6983dff

Please sign in to comment.