@retter/elasticsearch 8.4.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 (256) hide show
  1. package/.dockerignore +5 -0
  2. package/CHANGELOG.md +3 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE.txt +2 -0
  5. package/README.md +186 -0
  6. package/codecov.yml +14 -0
  7. package/index.d.ts +27 -0
  8. package/index.js +55 -0
  9. package/lib/api/api/async_search.d.ts +23 -0
  10. package/lib/api/api/async_search.js +131 -0
  11. package/lib/api/api/async_search.js.map +1 -0
  12. package/lib/api/api/autoscaling.d.ts +23 -0
  13. package/lib/api/api/autoscaling.js +109 -0
  14. package/lib/api/api/autoscaling.js.map +1 -0
  15. package/lib/api/api/bulk.d.ts +10 -0
  16. package/lib/api/api/bulk.js +54 -0
  17. package/lib/api/api/bulk.js.map +1 -0
  18. package/lib/api/api/cat.d.ts +89 -0
  19. package/lib/api/api/cat.js +637 -0
  20. package/lib/api/api/cat.js.map +1 -0
  21. package/lib/api/api/ccr.d.ts +50 -0
  22. package/lib/api/api/ccr.js +320 -0
  23. package/lib/api/api/ccr.js.map +1 -0
  24. package/lib/api/api/clear_scroll.d.ts +10 -0
  25. package/lib/api/api/clear_scroll.js +54 -0
  26. package/lib/api/api/clear_scroll.js.map +1 -0
  27. package/lib/api/api/close_point_in_time.d.ts +10 -0
  28. package/lib/api/api/close_point_in_time.js +53 -0
  29. package/lib/api/api/close_point_in_time.js.map +1 -0
  30. package/lib/api/api/cluster.d.ts +56 -0
  31. package/lib/api/api/cluster.js +392 -0
  32. package/lib/api/api/cluster.js.map +1 -0
  33. package/lib/api/api/count.d.ts +10 -0
  34. package/lib/api/api/count.js +62 -0
  35. package/lib/api/api/count.js.map +1 -0
  36. package/lib/api/api/create.d.ts +10 -0
  37. package/lib/api/api/create.js +46 -0
  38. package/lib/api/api/create.js.map +1 -0
  39. package/lib/api/api/dangling_indices.d.ts +20 -0
  40. package/lib/api/api/dangling_indices.js +85 -0
  41. package/lib/api/api/dangling_indices.js.map +1 -0
  42. package/lib/api/api/delete.d.ts +10 -0
  43. package/lib/api/api/delete.js +39 -0
  44. package/lib/api/api/delete.js.map +1 -0
  45. package/lib/api/api/delete_by_query.d.ts +10 -0
  46. package/lib/api/api/delete_by_query.js +53 -0
  47. package/lib/api/api/delete_by_query.js.map +1 -0
  48. package/lib/api/api/delete_by_query_rethrottle.d.ts +10 -0
  49. package/lib/api/api/delete_by_query_rethrottle.js +39 -0
  50. package/lib/api/api/delete_by_query_rethrottle.js.map +1 -0
  51. package/lib/api/api/delete_script.d.ts +10 -0
  52. package/lib/api/api/delete_script.js +39 -0
  53. package/lib/api/api/delete_script.js.map +1 -0
  54. package/lib/api/api/enrich.d.ts +26 -0
  55. package/lib/api/api/enrich.js +142 -0
  56. package/lib/api/api/enrich.js.map +1 -0
  57. package/lib/api/api/eql.d.ts +23 -0
  58. package/lib/api/api/eql.js +115 -0
  59. package/lib/api/api/eql.js.map +1 -0
  60. package/lib/api/api/exists.d.ts +10 -0
  61. package/lib/api/api/exists.js +39 -0
  62. package/lib/api/api/exists.js.map +1 -0
  63. package/lib/api/api/exists_source.d.ts +10 -0
  64. package/lib/api/api/exists_source.js +39 -0
  65. package/lib/api/api/exists_source.js.map +1 -0
  66. package/lib/api/api/explain.d.ts +10 -0
  67. package/lib/api/api/explain.js +53 -0
  68. package/lib/api/api/explain.js.map +1 -0
  69. package/lib/api/api/features.d.ts +17 -0
  70. package/lib/api/api/features.js +69 -0
  71. package/lib/api/api/features.js.map +1 -0
  72. package/lib/api/api/field_caps.d.ts +10 -0
  73. package/lib/api/api/field_caps.js +61 -0
  74. package/lib/api/api/field_caps.js.map +1 -0
  75. package/lib/api/api/fleet.d.ts +20 -0
  76. package/lib/api/api/fleet.js +113 -0
  77. package/lib/api/api/fleet.js.map +1 -0
  78. package/lib/api/api/get.d.ts +10 -0
  79. package/lib/api/api/get.js +39 -0
  80. package/lib/api/api/get.js.map +1 -0
  81. package/lib/api/api/get_script.d.ts +10 -0
  82. package/lib/api/api/get_script.js +39 -0
  83. package/lib/api/api/get_script.js.map +1 -0
  84. package/lib/api/api/get_script_context.d.ts +10 -0
  85. package/lib/api/api/get_script_context.js +40 -0
  86. package/lib/api/api/get_script_context.js.map +1 -0
  87. package/lib/api/api/get_script_languages.d.ts +10 -0
  88. package/lib/api/api/get_script_languages.js +40 -0
  89. package/lib/api/api/get_script_languages.js.map +1 -0
  90. package/lib/api/api/get_source.d.ts +10 -0
  91. package/lib/api/api/get_source.js +39 -0
  92. package/lib/api/api/get_source.js.map +1 -0
  93. package/lib/api/api/graph.d.ts +14 -0
  94. package/lib/api/api/graph.js +64 -0
  95. package/lib/api/api/graph.js.map +1 -0
  96. package/lib/api/api/ilm.d.ts +44 -0
  97. package/lib/api/api/ilm.js +275 -0
  98. package/lib/api/api/ilm.js.map +1 -0
  99. package/lib/api/api/index.d.ts +10 -0
  100. package/lib/api/api/index.js +54 -0
  101. package/lib/api/api/index.js.map +1 -0
  102. package/lib/api/api/indices.d.ts +170 -0
  103. package/lib/api/api/indices.js +1378 -0
  104. package/lib/api/api/indices.js.map +1 -0
  105. package/lib/api/api/info.d.ts +10 -0
  106. package/lib/api/api/info.js +40 -0
  107. package/lib/api/api/info.js.map +1 -0
  108. package/lib/api/api/ingest.d.ts +29 -0
  109. package/lib/api/api/ingest.js +183 -0
  110. package/lib/api/api/ingest.js.map +1 -0
  111. package/lib/api/api/knn_search.d.ts +10 -0
  112. package/lib/api/api/knn_search.js +53 -0
  113. package/lib/api/api/knn_search.js.map +1 -0
  114. package/lib/api/api/license.d.ts +32 -0
  115. package/lib/api/api/license.js +172 -0
  116. package/lib/api/api/license.js.map +1 -0
  117. package/lib/api/api/logstash.d.ts +20 -0
  118. package/lib/api/api/logstash.js +91 -0
  119. package/lib/api/api/logstash.js.map +1 -0
  120. package/lib/api/api/mget.d.ts +10 -0
  121. package/lib/api/api/mget.js +62 -0
  122. package/lib/api/api/mget.js.map +1 -0
  123. package/lib/api/api/migration.d.ts +20 -0
  124. package/lib/api/api/migration.js +95 -0
  125. package/lib/api/api/migration.js.map +1 -0
  126. package/lib/api/api/ml.d.ts +224 -0
  127. package/lib/api/api/ml.js +1929 -0
  128. package/lib/api/api/ml.js.map +1 -0
  129. package/lib/api/api/monitoring.d.ts +14 -0
  130. package/lib/api/api/monitoring.js +57 -0
  131. package/lib/api/api/monitoring.js.map +1 -0
  132. package/lib/api/api/msearch.d.ts +10 -0
  133. package/lib/api/api/msearch.js +54 -0
  134. package/lib/api/api/msearch.js.map +1 -0
  135. package/lib/api/api/msearch_template.d.ts +10 -0
  136. package/lib/api/api/msearch_template.js +54 -0
  137. package/lib/api/api/msearch_template.js.map +1 -0
  138. package/lib/api/api/mtermvectors.d.ts +10 -0
  139. package/lib/api/api/mtermvectors.js +62 -0
  140. package/lib/api/api/mtermvectors.js.map +1 -0
  141. package/lib/api/api/nodes.d.ts +32 -0
  142. package/lib/api/api/nodes.js +243 -0
  143. package/lib/api/api/nodes.js.map +1 -0
  144. package/lib/api/api/open_point_in_time.d.ts +10 -0
  145. package/lib/api/api/open_point_in_time.js +39 -0
  146. package/lib/api/api/open_point_in_time.js.map +1 -0
  147. package/lib/api/api/ping.d.ts +10 -0
  148. package/lib/api/api/ping.js +40 -0
  149. package/lib/api/api/ping.js.map +1 -0
  150. package/lib/api/api/put_script.d.ts +10 -0
  151. package/lib/api/api/put_script.js +61 -0
  152. package/lib/api/api/put_script.js.map +1 -0
  153. package/lib/api/api/rank_eval.d.ts +10 -0
  154. package/lib/api/api/rank_eval.js +61 -0
  155. package/lib/api/api/rank_eval.js.map +1 -0
  156. package/lib/api/api/reindex.d.ts +10 -0
  157. package/lib/api/api/reindex.js +53 -0
  158. package/lib/api/api/reindex.js.map +1 -0
  159. package/lib/api/api/reindex_rethrottle.d.ts +10 -0
  160. package/lib/api/api/reindex_rethrottle.js +39 -0
  161. package/lib/api/api/reindex_rethrottle.js.map +1 -0
  162. package/lib/api/api/render_search_template.d.ts +10 -0
  163. package/lib/api/api/render_search_template.js +62 -0
  164. package/lib/api/api/render_search_template.js.map +1 -0
  165. package/lib/api/api/rollup.d.ts +38 -0
  166. package/lib/api/api/rollup.js +239 -0
  167. package/lib/api/api/rollup.js.map +1 -0
  168. package/lib/api/api/scripts_painless_execute.d.ts +10 -0
  169. package/lib/api/api/scripts_painless_execute.js +54 -0
  170. package/lib/api/api/scripts_painless_execute.js.map +1 -0
  171. package/lib/api/api/scroll.d.ts +10 -0
  172. package/lib/api/api/scroll.js +53 -0
  173. package/lib/api/api/scroll.js.map +1 -0
  174. package/lib/api/api/search.d.ts +10 -0
  175. package/lib/api/api/search.js +69 -0
  176. package/lib/api/api/search.js.map +1 -0
  177. package/lib/api/api/search_mvt.d.ts +10 -0
  178. package/lib/api/api/search_mvt.js +53 -0
  179. package/lib/api/api/search_mvt.js.map +1 -0
  180. package/lib/api/api/search_shards.d.ts +10 -0
  181. package/lib/api/api/search_shards.js +48 -0
  182. package/lib/api/api/search_shards.js.map +1 -0
  183. package/lib/api/api/search_template.d.ts +10 -0
  184. package/lib/api/api/search_template.js +62 -0
  185. package/lib/api/api/search_template.js.map +1 -0
  186. package/lib/api/api/searchable_snapshots.d.ts +23 -0
  187. package/lib/api/api/searchable_snapshots.js +142 -0
  188. package/lib/api/api/searchable_snapshots.js.map +1 -0
  189. package/lib/api/api/security.d.ts +173 -0
  190. package/lib/api/api/security.js +1344 -0
  191. package/lib/api/api/security.js.map +1 -0
  192. package/lib/api/api/shutdown.d.ts +20 -0
  193. package/lib/api/api/shutdown.js +107 -0
  194. package/lib/api/api/shutdown.js.map +1 -0
  195. package/lib/api/api/slm.d.ts +38 -0
  196. package/lib/api/api/slm.js +214 -0
  197. package/lib/api/api/slm.js.map +1 -0
  198. package/lib/api/api/snapshot.d.ts +47 -0
  199. package/lib/api/api/snapshot.js +315 -0
  200. package/lib/api/api/snapshot.js.map +1 -0
  201. package/lib/api/api/sql.d.ts +29 -0
  202. package/lib/api/api/sql.js +178 -0
  203. package/lib/api/api/sql.js.map +1 -0
  204. package/lib/api/api/ssl.d.ts +14 -0
  205. package/lib/api/api/ssl.js +51 -0
  206. package/lib/api/api/ssl.js.map +1 -0
  207. package/lib/api/api/tasks.d.ts +20 -0
  208. package/lib/api/api/tasks.js +94 -0
  209. package/lib/api/api/tasks.js.map +1 -0
  210. package/lib/api/api/terms_enum.d.ts +10 -0
  211. package/lib/api/api/terms_enum.js +53 -0
  212. package/lib/api/api/terms_enum.js.map +1 -0
  213. package/lib/api/api/termvectors.d.ts +10 -0
  214. package/lib/api/api/termvectors.js +61 -0
  215. package/lib/api/api/termvectors.js.map +1 -0
  216. package/lib/api/api/text_structure.d.ts +14 -0
  217. package/lib/api/api/text_structure.js +57 -0
  218. package/lib/api/api/text_structure.js.map +1 -0
  219. package/lib/api/api/transform.d.ts +41 -0
  220. package/lib/api/api/transform.js +264 -0
  221. package/lib/api/api/transform.js.map +1 -0
  222. package/lib/api/api/update.d.ts +10 -0
  223. package/lib/api/api/update.js +53 -0
  224. package/lib/api/api/update.js.map +1 -0
  225. package/lib/api/api/update_by_query.d.ts +10 -0
  226. package/lib/api/api/update_by_query.js +53 -0
  227. package/lib/api/api/update_by_query.js.map +1 -0
  228. package/lib/api/api/update_by_query_rethrottle.d.ts +10 -0
  229. package/lib/api/api/update_by_query_rethrottle.js +39 -0
  230. package/lib/api/api/update_by_query_rethrottle.js.map +1 -0
  231. package/lib/api/api/watcher.d.ts +44 -0
  232. package/lib/api/api/watcher.js +291 -0
  233. package/lib/api/api/watcher.js.map +1 -0
  234. package/lib/api/api/xpack.d.ts +17 -0
  235. package/lib/api/api/xpack.js +69 -0
  236. package/lib/api/api/xpack.js.map +1 -0
  237. package/lib/api/index.d.ts +225 -0
  238. package/lib/api/index.js +520 -0
  239. package/lib/api/index.js.map +1 -0
  240. package/lib/api/types.d.ts +15306 -0
  241. package/lib/api/types.js +21 -0
  242. package/lib/api/types.js.map +1 -0
  243. package/lib/api/typesWithBodyKey.d.ts +15718 -0
  244. package/lib/api/typesWithBodyKey.js +21 -0
  245. package/lib/api/typesWithBodyKey.js.map +1 -0
  246. package/lib/client.d.ts +70 -0
  247. package/lib/client.js +287 -0
  248. package/lib/client.js.map +1 -0
  249. package/lib/helpers.d.ts +149 -0
  250. package/lib/helpers.js +776 -0
  251. package/lib/helpers.js.map +1 -0
  252. package/lib/sniffingTransport.d.ts +4 -0
  253. package/lib/sniffingTransport.js +56 -0
  254. package/lib/sniffingTransport.js.map +1 -0
  255. package/package.json +93 -0
  256. package/tsconfig.json +37 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ //# sourceMappingURL=typesWithBodyKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesWithBodyKey.js","sourceRoot":"","sources":["../../src/api/typesWithBodyKey.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG"}
@@ -0,0 +1,70 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { ConnectionOptions as TlsConnectionOptions } from 'tls';
4
+ import { URL } from 'url';
5
+ import { Transport, Serializer, Diagnostic, BaseConnectionPool } from '@elastic/transport';
6
+ import { HttpAgentOptions, UndiciAgentOptions, agentFn, nodeFilterFn, nodeSelectorFn, generateRequestIdFn, BasicAuth, ApiKeyAuth, BearerAuth, Context } from '@elastic/transport/lib/types';
7
+ import BaseConnection from '@elastic/transport/lib/connection/BaseConnection';
8
+ import SniffingTransport from './sniffingTransport';
9
+ import Helpers from './helpers';
10
+ import API from './api';
11
+ export interface NodeOptions {
12
+ url: URL;
13
+ id?: string;
14
+ agent?: HttpAgentOptions | UndiciAgentOptions;
15
+ ssl?: TlsConnectionOptions;
16
+ headers?: Record<string, any>;
17
+ roles?: {
18
+ master: boolean;
19
+ data: boolean;
20
+ ingest: boolean;
21
+ ml: boolean;
22
+ };
23
+ }
24
+ export interface ClientOptions {
25
+ node?: string | string[] | NodeOptions | NodeOptions[];
26
+ nodes?: string | string[] | NodeOptions | NodeOptions[];
27
+ Connection?: typeof BaseConnection;
28
+ ConnectionPool?: typeof BaseConnectionPool;
29
+ Transport?: typeof Transport;
30
+ Serializer?: typeof Serializer;
31
+ maxRetries?: number;
32
+ requestTimeout?: number;
33
+ pingTimeout?: number;
34
+ sniffInterval?: number | boolean;
35
+ sniffOnStart?: boolean;
36
+ sniffEndpoint?: string;
37
+ sniffOnConnectionFault?: boolean;
38
+ resurrectStrategy?: 'ping' | 'optimistic' | 'none';
39
+ compression?: boolean;
40
+ tls?: TlsConnectionOptions;
41
+ agent?: HttpAgentOptions | UndiciAgentOptions | agentFn | false;
42
+ nodeFilter?: nodeFilterFn;
43
+ nodeSelector?: nodeSelectorFn;
44
+ headers?: Record<string, any>;
45
+ opaqueIdPrefix?: string;
46
+ generateRequestId?: generateRequestIdFn;
47
+ name?: string | symbol;
48
+ auth?: BasicAuth | ApiKeyAuth | BearerAuth;
49
+ context?: Context;
50
+ proxy?: string | URL;
51
+ enableMetaHeader?: boolean;
52
+ cloud?: {
53
+ id: string;
54
+ };
55
+ disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor';
56
+ caFingerprint?: string;
57
+ maxResponseSize?: number;
58
+ maxCompressedResponseSize?: number;
59
+ }
60
+ export default class Client extends API {
61
+ diagnostic: Diagnostic;
62
+ name: string | symbol;
63
+ connectionPool: BaseConnectionPool;
64
+ transport: SniffingTransport;
65
+ serializer: Serializer;
66
+ helpers: Helpers;
67
+ constructor(opts: ClientOptions);
68
+ child(opts: ClientOptions): Client;
69
+ close(): Promise<void>;
70
+ }
package/lib/client.js ADDED
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License") you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const tslib_1 = require("tslib");
22
+ const url_1 = require("url");
23
+ const buffer_1 = tslib_1.__importDefault(require("buffer"));
24
+ const transport_1 = require("@elastic/transport");
25
+ const BaseConnection_1 = require("@elastic/transport/lib/connection/BaseConnection");
26
+ const sniffingTransport_1 = tslib_1.__importDefault(require("./sniffingTransport"));
27
+ const helpers_1 = tslib_1.__importDefault(require("./helpers"));
28
+ const api_1 = tslib_1.__importDefault(require("./api"));
29
+ const kChild = Symbol('elasticsearchjs-child');
30
+ const kInitialOptions = Symbol('elasticsearchjs-initial-options');
31
+ let clientVersion = require('../package.json').version; // eslint-disable-line
32
+ /* istanbul ignore next */
33
+ if (clientVersion.includes('-')) {
34
+ // clean prerelease
35
+ clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p';
36
+ }
37
+ let transportVersion = require('@elastic/transport/package.json').version; // eslint-disable-line
38
+ /* istanbul ignore next */
39
+ if (transportVersion.includes('-')) {
40
+ // clean prerelease
41
+ transportVersion = transportVersion.slice(0, transportVersion.indexOf('-')) + 'p';
42
+ }
43
+ const nodeVersion = process.versions.node;
44
+ class Client extends api_1.default {
45
+ constructor(opts) {
46
+ var _a, _b, _c, _d;
47
+ super();
48
+ Object.defineProperty(this, "diagnostic", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "name", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "connectionPool", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "transport", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ Object.defineProperty(this, "serializer", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ Object.defineProperty(this, "helpers", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: void 0
83
+ });
84
+ // @ts-expect-error kChild symbol is for internal use only
85
+ if ((opts.cloud != null) && opts[kChild] === undefined) {
86
+ const { id } = opts.cloud;
87
+ // the cloud id is `cluster-name:base64encodedurl`
88
+ // the url is a string divided by two '$', the first is the cloud url
89
+ // the second the elasticsearch instance, the third the kibana instance
90
+ const cloudUrls = Buffer.from(id.split(':')[1], 'base64').toString().split('$');
91
+ opts.node = `https://${cloudUrls[1]}.${cloudUrls[0]}`;
92
+ // Cloud has better performances with compression enabled
93
+ // see https://github.com/elastic/elasticsearch-py/pull/704.
94
+ // So unless the user specifies otherwise, we enable compression.
95
+ if (opts.compression == null)
96
+ opts.compression = true;
97
+ if (opts.tls == null ||
98
+ (opts.tls != null && opts.tls.secureProtocol == null)) {
99
+ opts.tls = (_a = opts.tls) !== null && _a !== void 0 ? _a : {};
100
+ opts.tls.secureProtocol = 'TLSv1_2_method';
101
+ }
102
+ }
103
+ if (opts.node == null && opts.nodes == null) {
104
+ throw new transport_1.errors.ConfigurationError('Missing node(s) option');
105
+ }
106
+ // @ts-expect-error kChild symbol is for internal use only
107
+ if (opts[kChild] === undefined) {
108
+ const checkAuth = getAuth((_b = opts.node) !== null && _b !== void 0 ? _b : opts.nodes);
109
+ if ((checkAuth != null) && checkAuth.username !== '' && checkAuth.password !== '') {
110
+ opts.auth = Object.assign({}, opts.auth, { username: checkAuth.username, password: checkAuth.password });
111
+ }
112
+ }
113
+ const options = Object.assign({}, {
114
+ Connection: transport_1.UndiciConnection,
115
+ Transport: sniffingTransport_1.default,
116
+ Serializer: transport_1.Serializer,
117
+ ConnectionPool: (opts.cloud != null) ? transport_1.CloudConnectionPool : transport_1.WeightedConnectionPool,
118
+ maxRetries: 3,
119
+ requestTimeout: 30000,
120
+ pingTimeout: 3000,
121
+ sniffInterval: false,
122
+ sniffOnStart: false,
123
+ sniffEndpoint: '_nodes/_all/http',
124
+ sniffOnConnectionFault: false,
125
+ resurrectStrategy: 'ping',
126
+ compression: false,
127
+ tls: null,
128
+ caFingerprint: null,
129
+ agent: null,
130
+ headers: {},
131
+ nodeFilter: null,
132
+ generateRequestId: null,
133
+ name: 'elasticsearch-js',
134
+ auth: null,
135
+ opaqueIdPrefix: null,
136
+ context: null,
137
+ proxy: null,
138
+ enableMetaHeader: true,
139
+ maxResponseSize: null,
140
+ maxCompressedResponseSize: null
141
+ }, opts);
142
+ if (options.caFingerprint != null && isHttpConnection((_c = opts.node) !== null && _c !== void 0 ? _c : opts.nodes)) {
143
+ throw new transport_1.errors.ConfigurationError('You can\'t configure the caFingerprint with a http connection');
144
+ }
145
+ if (options.maxResponseSize != null && options.maxResponseSize > buffer_1.default.constants.MAX_STRING_LENGTH) {
146
+ throw new transport_1.errors.ConfigurationError(`The maxResponseSize cannot be bigger than ${buffer_1.default.constants.MAX_STRING_LENGTH}`);
147
+ }
148
+ if (options.maxCompressedResponseSize != null && options.maxCompressedResponseSize > buffer_1.default.constants.MAX_LENGTH) {
149
+ throw new transport_1.errors.ConfigurationError(`The maxCompressedResponseSize cannot be bigger than ${buffer_1.default.constants.MAX_LENGTH}`);
150
+ }
151
+ if (options.enableMetaHeader) {
152
+ options.headers['x-elastic-client-meta'] = `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`;
153
+ }
154
+ this.name = options.name;
155
+ // @ts-expect-error kInitialOptions symbol is for internal use only
156
+ this[kInitialOptions] = options;
157
+ // @ts-expect-error kChild symbol is for internal use only
158
+ if (opts[kChild] !== undefined) {
159
+ // @ts-expect-error kChild symbol is for internal use only
160
+ this.serializer = opts[kChild].serializer;
161
+ // @ts-expect-error kChild symbol is for internal use only
162
+ this.connectionPool = opts[kChild].connectionPool;
163
+ // @ts-expect-error kChild symbol is for internal use only
164
+ this.diagnostic = opts[kChild].diagnostic;
165
+ }
166
+ else {
167
+ this.diagnostic = new transport_1.Diagnostic();
168
+ this.serializer = new options.Serializer();
169
+ this.connectionPool = new options.ConnectionPool({
170
+ pingTimeout: options.pingTimeout,
171
+ resurrectStrategy: options.resurrectStrategy,
172
+ tls: options.tls,
173
+ agent: options.agent,
174
+ proxy: options.proxy,
175
+ Connection: options.Connection,
176
+ auth: options.auth,
177
+ diagnostic: this.diagnostic,
178
+ caFingerprint: options.caFingerprint
179
+ });
180
+ this.connectionPool.addConnection((_d = options.node) !== null && _d !== void 0 ? _d : options.nodes);
181
+ }
182
+ this.transport = new options.Transport({
183
+ diagnostic: this.diagnostic,
184
+ connectionPool: this.connectionPool,
185
+ serializer: this.serializer,
186
+ maxRetries: options.maxRetries,
187
+ requestTimeout: options.requestTimeout,
188
+ sniffInterval: options.sniffInterval,
189
+ sniffOnStart: options.sniffOnStart,
190
+ sniffOnConnectionFault: options.sniffOnConnectionFault,
191
+ sniffEndpoint: options.sniffEndpoint,
192
+ compression: options.compression,
193
+ headers: options.headers,
194
+ nodeFilter: options.nodeFilter,
195
+ nodeSelector: options.nodeSelector,
196
+ generateRequestId: options.generateRequestId,
197
+ name: options.name,
198
+ opaqueIdPrefix: options.opaqueIdPrefix,
199
+ context: options.context,
200
+ productCheck: 'Elasticsearch',
201
+ maxResponseSize: options.maxResponseSize,
202
+ maxCompressedResponseSize: options.maxCompressedResponseSize,
203
+ vendoredHeaders: {
204
+ jsonContentType: 'application/vnd.elasticsearch+json; compatible-with=8',
205
+ ndjsonContentType: 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
206
+ accept: 'application/vnd.elasticsearch+json; compatible-with=8,text/plain'
207
+ }
208
+ });
209
+ this.helpers = new helpers_1.default({
210
+ client: this,
211
+ metaHeader: options.enableMetaHeader
212
+ ? `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
213
+ : null,
214
+ maxRetries: options.maxRetries
215
+ });
216
+ }
217
+ child(opts) {
218
+ // Merge the new options with the initial ones
219
+ // @ts-expect-error kChild symbol is for internal use only
220
+ const options = Object.assign({}, this[kInitialOptions], opts);
221
+ // Pass to the child client the parent instances that cannot be overriden
222
+ // @ts-expect-error kInitialOptions symbol is for internal use only
223
+ options[kChild] = {
224
+ connectionPool: this.connectionPool,
225
+ serializer: this.serializer,
226
+ diagnostic: this.diagnostic,
227
+ initialOptions: options
228
+ };
229
+ /* istanbul ignore else */
230
+ if (options.auth !== undefined) {
231
+ options.headers = (0, BaseConnection_1.prepareHeaders)(options.headers, options.auth);
232
+ }
233
+ return new Client(options);
234
+ }
235
+ async close() {
236
+ return await this.connectionPool.empty();
237
+ }
238
+ }
239
+ exports.default = Client;
240
+ function isHttpConnection(node) {
241
+ if (Array.isArray(node)) {
242
+ return node.some((n) => (typeof n === 'string' ? new url_1.URL(n).protocol : n.url.protocol) === 'http:');
243
+ }
244
+ else {
245
+ if (node == null)
246
+ return false;
247
+ return (typeof node === 'string' ? new url_1.URL(node).protocol : node.url.protocol) === 'http:';
248
+ }
249
+ }
250
+ function getAuth(node) {
251
+ if (Array.isArray(node)) {
252
+ for (const url of node) {
253
+ const auth = getUsernameAndPassword(url);
254
+ if (auth != null && auth.username !== '' && auth.password !== '') {
255
+ return auth;
256
+ }
257
+ }
258
+ return null;
259
+ }
260
+ else {
261
+ const auth = getUsernameAndPassword(node);
262
+ if (auth != null && auth.username !== '' && auth.password !== '') {
263
+ return auth;
264
+ }
265
+ return null;
266
+ }
267
+ function getUsernameAndPassword(node) {
268
+ /* istanbul ignore else */
269
+ if (typeof node === 'string') {
270
+ const { username, password } = new url_1.URL(node);
271
+ return {
272
+ username: decodeURIComponent(username),
273
+ password: decodeURIComponent(password)
274
+ };
275
+ }
276
+ else if (node != null && node.url instanceof url_1.URL) {
277
+ return {
278
+ username: decodeURIComponent(node.url.username),
279
+ password: decodeURIComponent(node.url.password)
280
+ };
281
+ }
282
+ else {
283
+ return null;
284
+ }
285
+ }
286
+ }
287
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAGH,6BAAyB;AACzB,4DAA2B;AAC3B,kDAS2B;AAa3B,qFAAiG;AACjG,oFAAmD;AACnD,gEAA+B;AAC/B,wDAAuB;AAEvB,MAAM,MAAM,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAA;AAC9C,MAAM,eAAe,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAA;AACjE,IAAI,aAAa,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA,CAAC,sBAAsB;AACrF,0BAA0B;AAC1B,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC/B,mBAAmB;IACnB,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;CACzE;AACD,IAAI,gBAAgB,GAAW,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
3
+ import { Readable } from 'stream';
4
+ import { TransportResult, TransportRequestOptions } from '@elastic/transport';
5
+ import Client from './client';
6
+ import * as T from './api/types';
7
+ export interface HelpersOptions {
8
+ client: Client;
9
+ metaHeader: string | null;
10
+ maxRetries: number;
11
+ }
12
+ export interface ScrollSearchOptions extends TransportRequestOptions {
13
+ wait?: number;
14
+ }
15
+ export interface ScrollSearchResponse<TDocument, TAggregations> extends TransportResult<T.SearchResponse<TDocument, TAggregations>, unknown> {
16
+ clear: () => Promise<void>;
17
+ documents: TDocument[];
18
+ }
19
+ export interface MsearchHelperOptions extends T.MsearchRequest {
20
+ operations?: number;
21
+ flushInterval?: number;
22
+ concurrency?: number;
23
+ retries?: number;
24
+ wait?: number;
25
+ }
26
+ export interface MsearchHelper extends Promise<void> {
27
+ stop: (error?: Error | null) => void;
28
+ search: <TDocument = unknown>(header: T.MsearchMultisearchHeader, body: T.MsearchMultisearchBody) => Promise<MsearchHelperResponse<TDocument>>;
29
+ }
30
+ export interface MsearchHelperResponse<TDocument> {
31
+ body: T.SearchResponse<TDocument>;
32
+ documents: TDocument[];
33
+ status: number;
34
+ responses: T.MsearchResponse;
35
+ }
36
+ export interface BulkStats {
37
+ total: number;
38
+ failed: number;
39
+ retry: number;
40
+ successful: number;
41
+ noop: number;
42
+ time: number;
43
+ bytes: number;
44
+ aborted: boolean;
45
+ }
46
+ interface IndexAction {
47
+ index: T.BulkIndexOperation;
48
+ }
49
+ interface CreateAction {
50
+ create: T.BulkCreateOperation;
51
+ }
52
+ interface UpdateActionOperation {
53
+ update: T.BulkUpdateOperation;
54
+ }
55
+ interface DeleteAction {
56
+ delete: T.BulkDeleteOperation;
57
+ }
58
+ type UpdateAction = [UpdateActionOperation, Record<string, any>];
59
+ type Action = IndexAction | CreateAction | UpdateAction | DeleteAction;
60
+ export interface OnDropDocument<TDocument = unknown> {
61
+ status: number;
62
+ operation: Action;
63
+ error: T.ErrorCause | null;
64
+ document: TDocument;
65
+ retried: boolean;
66
+ }
67
+ export interface BulkHelperOptions<TDocument = unknown> extends T.BulkRequest {
68
+ datasource: TDocument[] | Buffer | Readable | AsyncIterator<TDocument>;
69
+ onDocument: (doc: TDocument) => Action;
70
+ flushBytes?: number;
71
+ flushInterval?: number;
72
+ concurrency?: number;
73
+ retries?: number;
74
+ wait?: number;
75
+ onDrop?: (doc: OnDropDocument<TDocument>) => void;
76
+ refreshOnCompletion?: boolean | string;
77
+ }
78
+ export interface BulkHelper<T> extends Promise<BulkStats> {
79
+ abort: () => BulkHelper<T>;
80
+ readonly stats: BulkStats;
81
+ }
82
+ declare const kClient: unique symbol;
83
+ declare const kMetaHeader: unique symbol;
84
+ declare const kMaxRetries: unique symbol;
85
+ export default class Helpers {
86
+ [kClient]: Client;
87
+ [kMetaHeader]: string | null;
88
+ [kMaxRetries]: number;
89
+ constructor(opts: HelpersOptions);
90
+ /**
91
+ * Runs a search operation. The only difference between client.search and this utility,
92
+ * is that we are only returning the hits to the user and not the full ES response.
93
+ * This helper automatically adds `filter_path=hits.hits._source` to the querystring,
94
+ * as it will only need the documents source.
95
+ * @param {object} params - The Elasticsearch's search parameters.
96
+ * @param {object} options - The client optional configuration for this request.
97
+ * @return {array} The documents that matched the request.
98
+ */
99
+ search<TDocument = unknown>(params: T.SearchRequest, options?: TransportRequestOptions): Promise<TDocument[]>;
100
+ /**
101
+ * Runs a scroll search operation. This function returns an async iterator, allowing
102
+ * the user to use a for await loop to get all the results of a given search.
103
+ * ```js
104
+ * for await (const result of client.helpers.scrollSearch({ params })) {
105
+ * console.log(result)
106
+ * }
107
+ * ```
108
+ * Each result represents the entire body of a single scroll search request,
109
+ * if you just need to scroll the results, use scrollDocuments.
110
+ * This function handles automatically retries on 429 status code.
111
+ * @param {object} params - The Elasticsearch's search parameters.
112
+ * @param {object} options - The client optional configuration for this request.
113
+ * @return {iterator} the async iterator
114
+ */
115
+ scrollSearch<TDocument = unknown, TAggregations = unknown>(params: T.SearchRequest, options?: ScrollSearchOptions): AsyncIterable<ScrollSearchResponse<TDocument, TAggregations>>;
116
+ /**
117
+ * Runs a scroll search operation. This function returns an async iterator, allowing
118
+ * the user to use a for await loop to get all the documents of a given search.
119
+ * ```js
120
+ * for await (const document of client.helpers.scrollSearch({ params })) {
121
+ * console.log(document)
122
+ * }
123
+ * ```
124
+ * Each document is what you will find by running a scrollSearch and iterating on the hits array.
125
+ * This helper automatically adds `filter_path=hits.hits._source` to the querystring,
126
+ * as it will only need the documents source.
127
+ * @param {object} params - The Elasticsearch's search parameters.
128
+ * @param {object} options - The client optional configuration for this request.
129
+ * @return {iterator} the async iterator
130
+ */
131
+ scrollDocuments<TDocument = unknown>(params: T.SearchRequest, options?: ScrollSearchOptions): AsyncIterable<TDocument>;
132
+ /**
133
+ * Creates a msearch helper instance. Once you configure it, you can use the provided
134
+ * `search` method to add new searches in the queue.
135
+ * @param {object} options - The configuration of the msearch operations.
136
+ * @param {object} reqOptions - The client optional configuration for this request.
137
+ * @return {object} The possible operations to run.
138
+ */
139
+ msearch(options?: MsearchHelperOptions, reqOptions?: TransportRequestOptions): MsearchHelper;
140
+ /**
141
+ * Creates a bulk helper instance. Once you configure it, you can pick which operation
142
+ * to execute with the given dataset, index, create, update, and delete.
143
+ * @param {object} options - The configuration of the bulk operation.
144
+ * @param {object} reqOptions - The client optional configuration for this request.
145
+ * @return {object} The possible operations to run with the datasource.
146
+ */
147
+ bulk<TDocument = unknown>(options: BulkHelperOptions<TDocument>, reqOptions?: TransportRequestOptions): BulkHelper<TDocument>;
148
+ }
149
+ export {};