Skip to content

Commit fbbbece

Browse files
authored
Add docstrings for Client class and related properties (#2484)
1 parent a30c3dc commit fbbbece

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

src/client.ts

+84-1
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ if (transportVersion.includes('-')) {
6969
const nodeVersion = process.versions.node
7070

7171
export interface NodeOptions {
72+
/** @property url Elasticsearch node's location */
7273
url: URL
7374
id?: string
75+
/** @property agent Custom HTTP agent options */
7476
agent?: HttpAgentOptions | UndiciAgentOptions
77+
/** @property ssl Overrides default TLS connection settings */
7578
ssl?: TlsConnectionOptions
79+
/** @property headers Custom HTTP headers that should be sent with each request */
7680
headers?: Record<string, any>
81+
/** @property roles Common Elasticsearch roles that can be assigned to this node. Can be helpful when writing custom nodeFilter or nodeSelector functions. */
7782
roles?: {
7883
master: boolean
7984
data: boolean
@@ -83,40 +88,110 @@ export interface NodeOptions {
8388
}
8489

8590
export interface ClientOptions {
91+
/** @property node Elasticsearch node settings, if there is only one node. Required if `nodes` or `cloud` is not set. */
8692
node?: string | string[] | NodeOptions | NodeOptions[]
93+
/** @property nodes Elasticsearch node settings, if there are multiple nodes. Required if `node` or `cloud` is not set. */
8794
nodes?: string | string[] | NodeOptions | NodeOptions[]
95+
/** @property Connection HTTP connection class to use
96+
* @defaultValue `UndiciConnection` */
8897
Connection?: typeof BaseConnection
98+
/** @property ConnectionPool HTTP connection pool class to use
99+
* @defaultValue `CloudConnectionPool`, if connecting to Elastic Cloud, otherwise `WeightedConnectionPool` */
89100
ConnectionPool?: typeof BaseConnectionPool
101+
/** @property Transport Elastic transport class to use
102+
* @defaultValue `Transport` */
90103
Transport?: typeof Transport
104+
/** @property Serializer Serialization class to use
105+
* @defaultValue `Serializer` */
91106
Serializer?: typeof Serializer
107+
/** @property maxRetries Max number of retries for each request
108+
* @defaultValue 3 */
92109
maxRetries?: number
110+
/** @property requestTimeout Max request timeout in milliseconds for each request
111+
* @defaultValue 30000 */
93112
requestTimeout?: number
113+
/** @property pingTimeout Max number of milliseconds a `ClusterConnectionPool` will wait when pinging nodes before marking them dead
114+
* @defaultValue 3000 */
94115
pingTimeout?: number
116+
/** @property sniffInterval Perform a sniff operation every `n` milliseconds
117+
* @remarks Sniffing might not be the best solution for you. Read https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how to learn more.
118+
* @defaultValue */
95119
sniffInterval?: number | boolean
120+
/** @property sniffOnStart Perform a sniff once the client is started
121+
* @remarks Sniffing might not be the best solution for you. Read https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how to learn more.
122+
* @defaultValue false */
96123
sniffOnStart?: boolean
124+
/** @property sniffEndpoint Endpoint to ping during a sniff
125+
* @remarks Sniffing might not be the best solution for you. Read https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how to learn more.
126+
* @defaultValue "_nodes/_all/http" */
97127
sniffEndpoint?: string
128+
/** @property sniffOnConnectionFault Perform a sniff on connection fault
129+
* @remarks Sniffing might not be the best solution for you. Read https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how to learn more.
130+
* @defaultValue false */
98131
sniffOnConnectionFault?: boolean
132+
/** @property resurrectStrategy Strategy for resurrecting dead nodes when using `ClusterConnectionPool`. 'ping' will issue a test request to a node and resurrect it if it responds. 'optimistic' marks a node as alive without testing it. 'none` will never attempt to revive a dead connection.
133+
* @defaultValue 'ping' */
99134
resurrectStrategy?: 'ping' | 'optimistic' | 'none'
135+
/** @property compression Enables gzip request body compression
136+
* @defaultValue `true` if connecting to Elastic Cloud, otherwise `false`. */
100137
compression?: boolean
138+
/** @property tls [TLS configuraton](https://nodejs.org/api/tls.html)
139+
* @defaultValue null */
101140
tls?: TlsConnectionOptions
141+
/** @property agent Custom HTTP agent options
142+
* @defaultValue null */
102143
agent?: HttpAgentOptions | UndiciAgentOptions | agentFn | false
144+
/** @property nodeFilter A custom function used by the connection pool to determine which nodes are qualified to receive a request
145+
* @defaultValue () => true */
103146
nodeFilter?: nodeFilterFn
147+
/** @property nodeSelector A custom function used by the connection pool to determine which node should receive the next request
148+
* @defaultValue A "round robin" function that loops sequentially through each node in the pool. */
104149
nodeSelector?: nodeSelectorFn
150+
/** @property headers Custom HTTP headers that should be sent with each request
151+
* @defaultValue An object with a custom `user-agent` header */
105152
headers?: Record<string, any>
153+
/** @property opaqueIdPrefix A string prefix to apply to every generated X-Opaque-Id header
154+
* @defaultValue null */
106155
opaqueIdPrefix?: string
156+
/** @property generateRequestId A custom function for generating unique IDs for each request, to make it easier to associate each API request to a single response
157+
* @defaultValue A function that increments a number counter starting from 1 */
107158
generateRequestId?: generateRequestIdFn
159+
/** @property name A name for this client
160+
* @defaultValue 'elasticsearch-js' */
108161
name?: string | symbol
162+
/** @property auth Authentication options for this Elasticsearch cluster
163+
* @defaultValue null */
109164
auth?: BasicAuth | ApiKeyAuth | BearerAuth
165+
/** @property context A custom object attached to each request that can be used to pass data to client events
166+
* @defaultValue null */
110167
context?: Context
168+
/** @property proxy A proxy URL that, when provided, the client will automatically send all requests through
169+
* @defaultValue null */
111170
proxy?: string | URL
171+
/** @property enableMetaHeader If true, adds an header named `x-elastic-client-meta`, containing a small amount of high-level telemetry data, such as the client and platform version
172+
* @defaultValue true */
112173
enableMetaHeader?: boolean
174+
/** @property cloud Custom configuration for connecting to Elastic Cloud, in lieu of a `node` or `nodes` configuration
175+
* @remarks Read https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#client-usage for more details
176+
* @defaultValue null */
113177
cloud?: {
114178
id: string
115179
}
180+
/** @property disablePrototypePoisoningProtection Disables safe JSON parsing that protects execution of prototype poisoning attacks; disabled by default, as it can introduce a performance penalty
181+
* @defaultValue true */
116182
disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor'
183+
/** @property caFingerprint If configured, verifies that the fingerprint of the CA certificate that has signed the certificate of the server matches the supplied fingerprint; only accepts SHA256 digest fingerprints
184+
* @defaultValue null */
117185
caFingerprint?: string
186+
/** @property maxResponseSize When configured, verifies that the uncompressed response size is lower than the configured number. If it's higher, it will abort the request. It cannot be higher than `buffer.constants.MAX_STRING_LENGTH`
187+
* @defaultValue null */
118188
maxResponseSize?: number
189+
/** @property maxCompressedResponseSize When configured, verifies that the compressed response size is lower than the configured number. If it's higher, it will abort the request. It cannot be higher than `buffer.constants.MAX_LENGTH`
190+
* @defaultValue null */
119191
maxCompressedResponseSize?: number
192+
/** @property redaction Options for how to redact potentially sensitive data from metadata attached to `Error` objects
193+
* @remarks Read https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/advanced-config.html#redaction for more details
194+
* @defaultValue Configuration that will replace known sources of sensitive data */
120195
redaction?: RedactionOptions
121196
}
122197

@@ -127,6 +202,7 @@ export default class Client extends API {
127202
transport: SniffingTransport
128203
serializer: Serializer
129204
helpers: Helpers
205+
130206
constructor (opts: ClientOptions) {
131207
super()
132208
// @ts-expect-error kChild symbol is for internal use only
@@ -139,7 +215,7 @@ export default class Client extends API {
139215

140216
opts.node = `https://${cloudUrls[1]}.${cloudUrls[0]}`
141217

142-
// Cloud has better performances with compression enabled
218+
// Cloud has better performance with compression enabled
143219
// see https://github.com/elastic/elasticsearch-py/pull/704.
144220
// So unless the user specifies otherwise, we enable compression.
145221
if (opts.compression == null) opts.compression = true
@@ -323,6 +399,10 @@ export default class Client extends API {
323399
})
324400
}
325401

402+
/**
403+
* Creates a child client instance that shared its connection pool with the parent client
404+
* @see {@link https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/child.html}
405+
*/
326406
child (opts: ClientOptions): Client {
327407
// Merge the new options with the initial ones
328408
// @ts-expect-error kChild symbol is for internal use only
@@ -344,6 +424,9 @@ export default class Client extends API {
344424
return new Client(options)
345425
}
346426

427+
/**
428+
* Closes all connections in the connection pool. Connections shared with any parent or child instances will also be closed.
429+
*/
347430
async close (): Promise<void> {
348431
return await this.connectionPool.empty()
349432
}

0 commit comments

Comments
 (0)