@opensearch-project/opensearch 1.0.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 (84) hide show
  1. package/.dockerignore +5 -0
  2. package/ADMINS.md +34 -0
  3. package/DEVELOPER_GUIDE.md +60 -0
  4. package/LICENSE.txt +201 -0
  5. package/MAINTAINERS.md +73 -0
  6. package/Makefile +27 -0
  7. package/NOTICE.txt +8 -0
  8. package/README.md +183 -0
  9. package/RELEASING.md +34 -0
  10. package/SECURITY.md +3 -0
  11. package/api/api/bulk.js +81 -0
  12. package/api/api/cat.js +525 -0
  13. package/api/api/clear_scroll.js +66 -0
  14. package/api/api/cluster.js +431 -0
  15. package/api/api/count.js +75 -0
  16. package/api/api/create.js +80 -0
  17. package/api/api/dangling_indices.js +126 -0
  18. package/api/api/delete.js +76 -0
  19. package/api/api/delete_by_query.js +82 -0
  20. package/api/api/delete_by_query_rethrottle.js +71 -0
  21. package/api/api/delete_script.js +67 -0
  22. package/api/api/exists.js +76 -0
  23. package/api/api/exists_source.js +85 -0
  24. package/api/api/explain.js +76 -0
  25. package/api/api/features.js +92 -0
  26. package/api/api/field_caps.js +66 -0
  27. package/api/api/get.js +76 -0
  28. package/api/api/get_script.js +67 -0
  29. package/api/api/get_script_context.js +61 -0
  30. package/api/api/get_script_languages.js +61 -0
  31. package/api/api/get_source.js +76 -0
  32. package/api/api/index.js +82 -0
  33. package/api/api/indices.js +1516 -0
  34. package/api/api/info.js +61 -0
  35. package/api/api/ingest.js +211 -0
  36. package/api/api/mget.js +81 -0
  37. package/api/api/msearch.js +81 -0
  38. package/api/api/msearch_template.js +81 -0
  39. package/api/api/mtermvectors.js +75 -0
  40. package/api/api/nodes.js +279 -0
  41. package/api/api/ping.js +61 -0
  42. package/api/api/put_script.js +82 -0
  43. package/api/api/rank_eval.js +72 -0
  44. package/api/api/reindex.js +67 -0
  45. package/api/api/reindex_rethrottle.js +71 -0
  46. package/api/api/render_search_template.js +66 -0
  47. package/api/api/scripts_painless_execute.js +61 -0
  48. package/api/api/scroll.js +66 -0
  49. package/api/api/search.js +75 -0
  50. package/api/api/search_shards.js +66 -0
  51. package/api/api/search_template.js +81 -0
  52. package/api/api/shutdown.js +135 -0
  53. package/api/api/snapshot.js +450 -0
  54. package/api/api/tasks.js +119 -0
  55. package/api/api/terms_enum.js +67 -0
  56. package/api/api/termvectors.js +78 -0
  57. package/api/api/update.js +80 -0
  58. package/api/api/update_by_query.js +78 -0
  59. package/api/api/update_by_query_rethrottle.js +71 -0
  60. package/api/index.js +254 -0
  61. package/api/new.d.ts +716 -0
  62. package/api/requestParams.d.ts +1583 -0
  63. package/api/types.d.ts +9481 -0
  64. package/api/utils.js +69 -0
  65. package/codecov.yml +14 -0
  66. package/index.d.ts +1210 -0
  67. package/index.js +338 -0
  68. package/index.mjs +40 -0
  69. package/lib/Connection.d.ts +107 -0
  70. package/lib/Connection.js +345 -0
  71. package/lib/Helpers.d.ts +135 -0
  72. package/lib/Helpers.js +779 -0
  73. package/lib/Serializer.d.ts +41 -0
  74. package/lib/Serializer.js +105 -0
  75. package/lib/Transport.d.ts +173 -0
  76. package/lib/Transport.js +646 -0
  77. package/lib/errors.d.ts +101 -0
  78. package/lib/errors.js +168 -0
  79. package/lib/pool/BaseConnectionPool.js +269 -0
  80. package/lib/pool/CloudConnectionPool.js +75 -0
  81. package/lib/pool/ConnectionPool.js +257 -0
  82. package/lib/pool/index.d.ts +215 -0
  83. package/lib/pool/index.js +41 -0
  84. package/package.json +102 -0
@@ -0,0 +1,41 @@
1
+ /*
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ *
4
+ * The OpenSearch Contributors require contributions made to
5
+ * this file be licensed under the Apache-2.0 license or a
6
+ * compatible open source license.
7
+ *
8
+ * Modifications Copyright OpenSearch Contributors. See
9
+ * GitHub history for details.
10
+ */
11
+
12
+ /*
13
+ * Licensed to Elasticsearch B.V. under one or more contributor
14
+ * license agreements. See the NOTICE file distributed with
15
+ * this work for additional information regarding copyright
16
+ * ownership. Elasticsearch B.V. licenses this file to you under
17
+ * the Apache License, Version 2.0 (the "License"); you may
18
+ * not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing,
24
+ * software distributed under the License is distributed on an
25
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26
+ * KIND, either express or implied. See the License for the
27
+ * specific language governing permissions and limitations
28
+ * under the License.
29
+ */
30
+
31
+ export interface SerializerOptions {
32
+ disablePrototypePoisoningProtection: boolean | 'proto' | 'constructor'
33
+ }
34
+
35
+ export default class Serializer {
36
+ constructor(opts?: SerializerOptions)
37
+ serialize(object: any): string;
38
+ deserialize(json: string): any;
39
+ ndserialize(array: any[]): string;
40
+ qserialize(object: any): string;
41
+ }
@@ -0,0 +1,105 @@
1
+ /*
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ *
4
+ * The OpenSearch Contributors require contributions made to
5
+ * this file be licensed under the Apache-2.0 license or a
6
+ * compatible open source license.
7
+ *
8
+ * Modifications Copyright OpenSearch Contributors. See
9
+ * GitHub history for details.
10
+ */
11
+
12
+ /*
13
+ * Licensed to Elasticsearch B.V. under one or more contributor
14
+ * license agreements. See the NOTICE file distributed with
15
+ * this work for additional information regarding copyright
16
+ * ownership. Elasticsearch B.V. licenses this file to you under
17
+ * the Apache License, Version 2.0 (the "License"); you may
18
+ * not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing,
24
+ * software distributed under the License is distributed on an
25
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26
+ * KIND, either express or implied. See the License for the
27
+ * specific language governing permissions and limitations
28
+ * under the License.
29
+ */
30
+
31
+ 'use strict'
32
+
33
+ const { stringify } = require('querystring')
34
+ const debug = require('debug')('opensearch')
35
+ const sjson = require('secure-json-parse')
36
+ const { SerializationError, DeserializationError } = require('./errors')
37
+ const kJsonOptions = Symbol('secure json parse options')
38
+
39
+ class Serializer {
40
+ constructor (opts = {}) {
41
+ const disable = opts.disablePrototypePoisoningProtection
42
+ this[kJsonOptions] = {
43
+ protoAction: disable === true || disable === 'proto' ? 'ignore' : 'error',
44
+ constructorAction: disable === true || disable === 'constructor' ? 'ignore' : 'error'
45
+ }
46
+ }
47
+
48
+ serialize (object) {
49
+ debug('Serializing', object)
50
+ let json
51
+ try {
52
+ json = JSON.stringify(object)
53
+ } catch (err) {
54
+ throw new SerializationError(err.message, object)
55
+ }
56
+ return json
57
+ }
58
+
59
+ deserialize (json) {
60
+ debug('Deserializing', json)
61
+ let object
62
+ try {
63
+ object = sjson.parse(json, this[kJsonOptions])
64
+ } catch (err) {
65
+ throw new DeserializationError(err.message, json)
66
+ }
67
+ return object
68
+ }
69
+
70
+ ndserialize (array) {
71
+ debug('ndserialize', array)
72
+ if (Array.isArray(array) === false) {
73
+ throw new SerializationError('The argument provided is not an array')
74
+ }
75
+ let ndjson = ''
76
+ for (let i = 0, len = array.length; i < len; i++) {
77
+ if (typeof array[i] === 'string') {
78
+ ndjson += array[i] + '\n'
79
+ } else {
80
+ ndjson += this.serialize(array[i]) + '\n'
81
+ }
82
+ }
83
+ return ndjson
84
+ }
85
+
86
+ qserialize (object) {
87
+ debug('qserialize', object)
88
+ if (object == null) return ''
89
+ if (typeof object === 'string') return object
90
+ // arrays should be serialized as comma separated list
91
+ const keys = Object.keys(object)
92
+ for (let i = 0, len = keys.length; i < len; i++) {
93
+ const key = keys[i]
94
+ // OpenSearch will complain for keys without a value
95
+ if (object[key] === undefined) {
96
+ delete object[key]
97
+ } else if (Array.isArray(object[key]) === true) {
98
+ object[key] = object[key].join(',')
99
+ }
100
+ }
101
+ return stringify(object)
102
+ }
103
+ }
104
+
105
+ module.exports = Serializer
@@ -0,0 +1,173 @@
1
+ /*
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ *
4
+ * The OpenSearch Contributors require contributions made to
5
+ * this file be licensed under the Apache-2.0 license or a
6
+ * compatible open source license.
7
+ *
8
+ * Modifications Copyright OpenSearch Contributors. See
9
+ * GitHub history for details.
10
+ */
11
+
12
+ /*
13
+ * Licensed to Elasticsearch B.V. under one or more contributor
14
+ * license agreements. See the NOTICE file distributed with
15
+ * this work for additional information regarding copyright
16
+ * ownership. Elasticsearch B.V. licenses this file to you under
17
+ * the Apache License, Version 2.0 (the "License"); you may
18
+ * not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing,
24
+ * software distributed under the License is distributed on an
25
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26
+ * KIND, either express or implied. See the License for the
27
+ * specific language governing permissions and limitations
28
+ * under the License.
29
+ */
30
+
31
+ import { Readable as ReadableStream } from 'stream';
32
+ import { ConnectionPool, CloudConnectionPool } from './pool';
33
+ import Connection from './Connection';
34
+ import Serializer from './Serializer';
35
+ import * as errors from './errors';
36
+
37
+ export type ApiError = errors.ConfigurationError | errors.ConnectionError |
38
+ errors.DeserializationError | errors.SerializationError |
39
+ errors.NoLivingConnectionsError | errors.ResponseError |
40
+ errors.TimeoutError | errors.RequestAbortedError |
41
+ errors.NotCompatibleError
42
+
43
+ export type Context = unknown
44
+
45
+ export interface nodeSelectorFn {
46
+ (connections: Connection[]): Connection;
47
+ }
48
+
49
+ export interface nodeFilterFn {
50
+ (connection: Connection): boolean;
51
+ }
52
+
53
+ export interface generateRequestIdFn {
54
+ (params: TransportRequestParams, options: TransportRequestOptions): any;
55
+ }
56
+
57
+ interface TransportOptions {
58
+ emit: (event: string | symbol, ...args: any[]) => boolean;
59
+ connectionPool: ConnectionPool | CloudConnectionPool;
60
+ serializer: Serializer;
61
+ maxRetries: number;
62
+ requestTimeout: number | string;
63
+ suggestCompression?: boolean;
64
+ compression?: 'gzip';
65
+ sniffInterval?: number;
66
+ sniffOnConnectionFault?: boolean;
67
+ sniffEndpoint: string;
68
+ sniffOnStart?: boolean;
69
+ nodeFilter?: nodeFilterFn;
70
+ nodeSelector?: string | nodeSelectorFn;
71
+ headers?: Record<string, any>;
72
+ generateRequestId?: generateRequestIdFn;
73
+ name?: string;
74
+ opaqueIdPrefix?: string;
75
+ }
76
+
77
+ export interface RequestEvent<TResponse = Record<string, any>, TContext = Context> {
78
+ body: TResponse;
79
+ statusCode: number | null;
80
+ headers: Record<string, any> | null;
81
+ warnings: string[] | null;
82
+ meta: {
83
+ context: TContext;
84
+ name: string | symbol;
85
+ request: {
86
+ params: TransportRequestParams;
87
+ options: TransportRequestOptions;
88
+ id: any;
89
+ };
90
+ connection: Connection;
91
+ attempts: number;
92
+ aborted: boolean;
93
+ sniff?: {
94
+ hosts: any[];
95
+ reason: string;
96
+ };
97
+ };
98
+ }
99
+
100
+ // ApiResponse and RequestEvent are the same thing
101
+ // we are doing this for have more clear names
102
+ export interface ApiResponse<TResponse = Record<string, any>, TContext = Context> extends RequestEvent<TResponse, TContext> { }
103
+
104
+ export type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream
105
+ export type RequestNDBody<T = Record<string, any>[]> = T | string | string[] | Buffer | ReadableStream
106
+
107
+ export interface TransportRequestParams {
108
+ method: string;
109
+ path: string;
110
+ body?: RequestBody;
111
+ bulkBody?: RequestNDBody;
112
+ querystring?: Record<string, any> | string;
113
+ }
114
+
115
+ export interface TransportRequestOptions {
116
+ ignore?: number[];
117
+ requestTimeout?: number | string;
118
+ maxRetries?: number;
119
+ asStream?: boolean;
120
+ headers?: Record<string, any>;
121
+ querystring?: Record<string, any>;
122
+ compression?: 'gzip';
123
+ id?: any;
124
+ context?: Context;
125
+ warnings?: string[];
126
+ opaqueId?: string;
127
+ }
128
+
129
+ export interface TransportRequestCallback {
130
+ abort: () => void;
131
+ }
132
+
133
+ export interface TransportRequestPromise<T> extends Promise<T> {
134
+ abort: () => void;
135
+ finally(onFinally?: (() => void) | undefined | null): Promise<T>;
136
+ }
137
+
138
+ export interface TransportGetConnectionOptions {
139
+ requestId: string;
140
+ }
141
+
142
+ export interface TransportSniffOptions {
143
+ reason: string;
144
+ requestId?: string;
145
+ }
146
+
147
+ export default class Transport {
148
+ static sniffReasons: {
149
+ SNIFF_ON_START: string;
150
+ SNIFF_INTERVAL: string;
151
+ SNIFF_ON_CONNECTION_FAULT: string;
152
+ DEFAULT: string;
153
+ };
154
+ emit: (event: string | symbol, ...args: any[]) => boolean;
155
+ connectionPool: ConnectionPool | CloudConnectionPool;
156
+ serializer: Serializer;
157
+ maxRetries: number;
158
+ requestTimeout: number;
159
+ suggestCompression: boolean;
160
+ compression: 'gzip' | false;
161
+ sniffInterval: number;
162
+ sniffOnConnectionFault: boolean;
163
+ opaqueIdPrefix: string | null;
164
+ sniffEndpoint: string;
165
+ _sniffEnabled: boolean;
166
+ _nextSniff: number;
167
+ _isSniffing: boolean;
168
+ constructor(opts: TransportOptions);
169
+ request(params: TransportRequestParams, options?: TransportRequestOptions): TransportRequestPromise<ApiResponse>;
170
+ request(params: TransportRequestParams, options?: TransportRequestOptions, callback?: (err: ApiError, result: ApiResponse) => void): TransportRequestCallback;
171
+ getConnection(opts: TransportGetConnectionOptions): Connection | null;
172
+ sniff(opts?: TransportSniffOptions, callback?: (...args: any[]) => void): void;
173
+ }