/// import { inspect } from 'util'; import { BucketName, CouchbaseClusterTypes, DefaultClusterTypes } from '@cbjsdev/shared'; import { AnalyticsIndexManager } from './analyticsindexmanager.js'; import { AnalyticsMetaData, AnalyticsQueryOptions, AnalyticsResult } from './analyticstypes.js'; import { Authenticator } from './authenticators.js'; import { CppConnection } from './binding.js'; import { Bucket } from './bucket.js'; import { BucketManager } from './bucketmanager.js'; import { DiagnosticsOptions, DiagnosticsResult, PingOptions, PingResult } from './diagnosticstypes.js'; import { EventingFunctionManager } from './eventingfunctionmanager.js'; import { CouchbaseLogger, Logger } from './logger.js'; import { Meter } from './metrics.js'; import { ObservabilityInstruments } from './observabilitytypes.js'; import { QueryIndexManager } from './queryindexmanager.js'; import { QueryMetaData, QueryOptions, QueryResult } from './querytypes.js'; import { SearchIndexManager } from './searchindexmanager.js'; import { SearchQuery } from './searchquery.js'; import { SearchMetaData, SearchQueryOptions, SearchRequest, SearchResult, SearchRow } from './searchtypes.js'; import { StreamableRowPromise } from './streamablepromises.js'; import { ThresholdLoggingOptions } from './thresholdlogging.js'; import { RequestTracer } from './tracing.js'; import { Transactions, TransactionsConfig } from './transactions.js'; import { Transcoder } from './transcoders.js'; import { UserManager } from './usermanager.js'; import { NodeCallback, VoidNodeCallback } from './utilities.js'; /** * Specifies the timeout options for the client. * * @category Core */ export type TimeoutConfig = { /** * Specifies the default timeout for KV operations, specified in millseconds. */ kvTimeout?: number; /** * Specifies the default timeout for durable KV operations, specified in millseconds. */ kvDurableTimeout?: number; /** * Specifies the default timeout for views operations, specified in millseconds. */ viewTimeout?: number; /** * Specifies the default timeout for query operations, specified in millseconds. */ queryTimeout?: number; /** * Specifies the default timeout for analytics query operations, specified in millseconds. */ analyticsTimeout?: number; /** * Specifies the default timeout for search query operations, specified in millseconds. */ searchTimeout?: number; /** * Specifies the default timeout for management operations, specified in millseconds. */ managementTimeout?: number; /** * Specifies the default timeout allocated to complete bootstrap, specified in millseconds. */ bootstrapTimeout?: number; /** * Specifies the default timeout for attempting to connect to a node’s KV service via a socket, specified in millseconds. */ connectTimeout?: number; /** * Specifies the default timeout to resolve DNS name of the node to IP address, specified in millseconds. */ resolveTimeout?: number; }; /** * Specifies security options for the client. * * @category Core */ export type SecurityConfig = { /** * Specifies the path to a trust store file to be used when validating the * authenticity of the server when connecting over SSL. */ trustStorePath?: string; }; /** * Specifies DNS options for the client. * * Volatile: This API is subject to change at any time. * * @category Core */ export type DnsConfig = { /** * Specifies the nameserver to be used for DNS query when connecting. */ nameserver?: string; /** * Specifies the port to be used for DNS query when connecting. */ port?: number; /** * Specifies the default timeout for DNS SRV operations, specified in millseconds. */ dnsSrvTimeout?: number; }; /** * Specifies Application Telemetry options for the client. * * @category Core */ export interface AppTelemetryConfig { /** * Specifies if application telemetry feature should be enabled or not. */ enabled?: boolean; /** * Specifies an endpoint to override the application metrics endpoint discovered during configuration. */ endpoint?: string; /** * Specifies the time to wait before attempting a websocket reconnection, specified in millseconds. */ backoff?: number; /** * Specifies the time to wait between sending consecutive websocket PING commands to the server, specified in millseconds. */ pingInterval?: number; /** * Specifies the time allowed for the server to respond to websocket PING command, specified in millseconds. */ pingTimeout?: number; } export type Hooks = { /** * Any error thrown in a hook will be swallowed and this function will be called * @param err The error thrown by the hook function. */ onHookError: (err: unknown) => void; onQueryStart: (opts: { statement: string; options: QueryOptions; }) => unknown; onQueryEnd: (opts: { statement: string; options: QueryOptions; result: QueryResult; } | { statement: string; options: QueryOptions; error: Error; }, returnOfOnQueryStart: unknown) => void; }; /** * Specifies threshold logging options for the client. * * NOTE: These options are used to configure the underlying C++ core threshold logging. * * Typed after {@link ThresholdLoggingOptions} (the default tracer's options) plus the * cluster-level `enableTracing` flag: `tracingConfig` configures the default * {@link ThresholdLoggingTracer} and only that. A custom `tracer` owns its own options * (e.g. `recordRequestArguments`) and is not affected by `tracingConfig`. * * @category Core */ export interface TracingConfig extends ThresholdLoggingOptions { /** * Specifies to enable or disable threshold logging. * * @default true */ enableTracing?: boolean; } /** * Specifies orphan report logging options for the client. * * NOTE: These options are used to configure the underlying C++ core orphan report logging. * * @category Core */ export interface OrphanReporterConfig { /** * Specifies to enable or disable orphaned response logging. * * @default true */ enableOrphanReporting?: boolean; /** * Specifies the interval after which the aggregated orphaned response * information is logged, specified in milliseconds (10 seconds). * * @default 10_000 */ emitInterval?: number; /** * Specifies how many orphaned response entries to sample per service in each * emit interval. * * @default 64 */ sampleSize?: number; } /** * Specifies metrics logging options for the client. * * NOTE: These options are used to configure the underlying C++ core metrics logging. * * @category Core */ export interface MetricsConfig { /** * Specifies to enable or disable metrics logging. * * @default true */ enableMetrics?: boolean; /** * Specifies the interval after which metrics information is logged, specified * in milliseconds (10 minutes). * * @default 600_000 */ emitInterval?: number; } /** * Specifies the options which can be specified when connecting * to a cluster. * * @category Core */ export type ConnectOptions = { /** * Specifies a username to use for an implicitly created IPasswordAuthenticator * used for authentication with the cluster. */ username?: string; /** * Specifies a password to be used in concert with username for authentication. * * @see ConnectOptions.username */ password?: string; /** * Specifies a specific authenticator to use when connecting to the cluster. */ authenticator?: Authenticator; /** * Specifies the security config for connections of this cluster. */ security?: SecurityConfig; /** * Specifies the default timeouts for various operations performed by the SDK. */ timeouts?: TimeoutConfig; /** * Specifies the default transcoder to use when encoding or decoding document values. * This is specific to the KV service. */ transcoder?: Transcoder; /** * Specifies the default function to parse results from the query service. * * @default {@link JSON.parse} */ queryResultParser?: (value: string) => any; /** * Specifies hook functions that allow you to perform actions before and after some Couchbase operations. */ hooks?: Partial>; /** * Specifies the options for transactions. */ transactions?: TransactionsConfig; /** * Specifies the DNS config for connections of this cluster. * * Volatile: This API is subject to change at any time. * */ dnsConfig?: DnsConfig; /** * Applies the specified ConfigProfile options to the cluster. * * Volatile: This API is subject to change at any time. * */ configProfile?: string; /** * Specifies the preferred server group to use for replica operations that specify a non-default * read preference. */ preferredServerGroup?: string; /** * Specifies the Application Telemetry config for connections of this cluster. */ appTelemetryConfig?: AppTelemetryConfig; /** * Specifies the tracing (threshold logging) config for connections of this cluster. */ tracingConfig?: TracingConfig; /** * Specifies the orphan report logging config for connections of this cluster. */ orphanReporterConfig?: OrphanReporterConfig; /** * Specifies the metrics config for connections of this cluster. */ metricsConfig?: MetricsConfig; /** * Specifies the request tracer to use for this cluster. When omitted, a * {@link ThresholdLoggingTracer} is used unless tracing is explicitly disabled * via {@link TracingConfig.enableTracing}. */ tracer?: RequestTracer; /** * Specifies the meter to use for this cluster. When omitted, a * {@link LoggingMeter} is used unless metrics are explicitly disabled via * {@link MetricsConfig.enableMetrics}. */ meter?: Meter; /** * Provides an implementation of the {@link Logger} interface to be used by the SDK. * * When omitted, the log level is read from the `CNLOGLEVEL` environment variable * (falling back to a no-op logger). */ logger?: Logger; }; /** * Exposes the operations which are available to be performed against a cluster. * Namely the ability to access to Buckets as well as performing management * operations against the cluster. * * @category Core */ export declare class Cluster { private _connStr; private _trustStorePath; private _kvTimeout; private _kvDurableTimeout; private _viewTimeout; private _queryTimeout; private _analyticsTimeout; private _searchTimeout; private _managementTimeout; private _connectTimeout; private _bootstrapTimeout; private _resolveTimeout; private _auth; private _conn; private _transcoder; private _queryResultParser; private _hooks?; private _txnConfig; private _transactions?; private readonly _openBuckets; private _dnsConfig; private _preferredServerGroup; private _appTelemetryConfig; private _tracingConfig; private _orphanReporterConfig; private _metricsConfig; private _tracer; private _meter; private _observabilityInstruments; private _logger; /** * @internal */ get conn(): CppConnection; /** @internal */ get transcoder(): Transcoder; /** * @internal */ get logger(): CouchbaseLogger; /** * @internal */ get observabilityInstruments(): ObservabilityInstruments; /** @internal */ get queryResultParser(): (value: string) => any; /** @internal */ get hooks(): Partial> | undefined; /** @internal */ get kvTimeout(): number; /** @internal */ get kvDurableTimeout(): number; /** @internal */ get viewTimeout(): number; /** @internal */ get queryTimeout(): number; /** @internal */ get analyticsTimeout(): number; /** @internal */ get searchTimeout(): number; /** @internal */ get managementTimeout(): number; /** @internal */ get bootstrapTimeout(): number | undefined; /** @internal */ get connectTimeout(): number | undefined; /** @internal */ get resolveTimeout(): number | undefined; /** * @internal */ [inspect.custom](): Record; /** * @internal */ toJSON(): Record; /** * Builds a serialization-safe snapshot of the cluster: the authenticator is * masked, and the tracer/meter are rendered without recursing into their * internals — which commonly include a timer handle (a circular structure that * breaks `JSON.stringify` and floods `util.inspect`). If the implementation * defines the serializer for the current path — `toJSON` for `JSON.stringify`, * `[inspect.custom]` for `util.inspect` — the instance is kept as-is so the * native machinery invokes it; otherwise it falls back to the class name. * * @internal */ private _toSafeRepresentation; /** @internal @deprecated Use the static sdk-level {@link connect} method instead. */ constructor(connStr: string, options?: ConnectOptions); /** @internal @throws AuthenticationFailureError @throws InvalidArgumentError */ static connect(connStr: string, options?: ConnectOptions, callback?: NodeCallback>): Promise>; /** * Creates a Bucket object reference to a specific bucket. * * @param bucketName The name of the bucket to reference. */ bucket>(bucketName: B): Bucket; /** * Returns a UserManager which can be used to manage the users * of this cluster. */ users(): UserManager; /** * Returns a BucketManager which can be used to manage the buckets * of this cluster. */ buckets(): BucketManager; /** * Returns a QueryIndexManager which can be used to manage the query indexes * of this cluster. */ queryIndexes(): QueryIndexManager; /** * Returns a AnalyticsIndexManager which can be used to manage the analytics * indexes of this cluster. */ analyticsIndexes(): AnalyticsIndexManager; /** * Returns a SearchIndexManager which can be used to manage the search * indexes of this cluster. */ searchIndexes(): SearchIndexManager; /** * Returns a EventingFunctionManager which can be used to manage the eventing * functions of this cluster. * Uncommitted: This API is subject to change in the future. */ eventingFunctions(): EventingFunctionManager; /** * Returns a Transactions object which can be used to perform transactions * on this cluster. */ transactions(): Transactions; /** * Executes a N1QL query against the cluster. * * @param statement The N1QL statement to execute. * @param callback A node-style callback to be invoked after execution. */ query(statement: string, callback?: NodeCallback>): StreamableRowPromise, TRow, QueryMetaData>; /** * Executes a N1QL query against the cluster. * * @param statement The N1QL statement to execute. * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ query(statement: string, options: QueryOptions, callback?: NodeCallback>): StreamableRowPromise, TRow, QueryMetaData>; /** * Executes an analytics query against the cluster. * * @param statement The analytics statement to execute. * @param callback A node-style callback to be invoked after execution. */ analyticsQuery(statement: string, callback?: NodeCallback>): StreamableRowPromise, TRow, AnalyticsMetaData>; /** * Executes an analytics query against the cluster. * * @param statement The analytics statement to execute. * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ analyticsQuery(statement: string, options: AnalyticsQueryOptions, callback?: NodeCallback>): StreamableRowPromise, TRow, AnalyticsMetaData>; /** * Executes a search query against the cluster. * * @param indexName The name of the index to query. * @param query The SearchQuery describing the query to execute. * @param callback A node-style callback to be invoked after execution. */ searchQuery(indexName: string, query: SearchQuery, callback?: NodeCallback): StreamableRowPromise; /** * Executes a search query against the cluster. * * @param indexName The name of the index to query. * @param query The SearchQuery describing the query to execute. * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ searchQuery(indexName: string, query: SearchQuery, options: SearchQueryOptions, callback?: NodeCallback): StreamableRowPromise; /** * Executes a search query against the cluster. * * @param indexName The name of the index to query. * @param request The SearchRequest describing the search to execute. * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ search(indexName: string, request: SearchRequest, options: SearchQueryOptions, callback?: NodeCallback): StreamableRowPromise; /** * Executes a search query against the cluster. * * @param indexName The name of the index to query. * @param request The SearchRequest describing the search to execute. * @param callback A node-style callback to be invoked after execution. */ search(indexName: string, request: SearchRequest, callback?: NodeCallback): StreamableRowPromise; /** * Returns a diagnostics report about the currently active connections with the * cluster. Includes information about remote and local addresses, last activity, * and other diagnostics information. * * @param callback A node-style callback to be invoked after execution. */ diagnostics(callback?: NodeCallback): Promise; /** * Returns a diagnostics report about the currently active connections with the * cluster. Includes information about remote and local addresses, last activity, * and other diagnostics information. * * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ diagnostics(options: DiagnosticsOptions, callback?: NodeCallback): Promise; /** * Performs a ping operation against the cluster. Pinging the services which * are specified (or all services if none are specified). Returns a report * which describes the outcome of the ping operations which were performed. * * @param callback A node-style callback to be invoked after execution. */ ping(callback?: NodeCallback): Promise; /** * Performs a ping operation against the cluster. Pinging the services which * are specified (or all services if none are specified). Returns a report * which describes the outcome of the ping operations which were performed. * * @param options Optional parameters for this operation. * @param callback A node-style callback to be invoked after execution. */ ping(options: PingOptions, callback?: NodeCallback): Promise; /** * Shuts down this cluster object. Cleaning up all resources associated with it. * * @param callback A node-style callback to be invoked after execution. */ close(callback?: VoidNodeCallback): Promise; /** * Do a best effort to await for pending, internal, operations to settle before closing the cluster. * * Experimental. */ closeGracefully(callback?: VoidNodeCallback): Promise; waitForBuckets(): Promise; /** * Update the credentials used by this cluster. * * This is primarily useful to refresh the certificate and key used for mutual TLS (mTLS) * authentication without having to reconnect the cluster. * * @param auth The new credentials to use. * @throws AuthenticationFailureError */ updateCredentials(auth: Authenticator): void; /** * Builds the C++ core credentials from an {@link Authenticator}. * * @internal */ private _getCppCredentials; /** * @internal */ _getClusterLabels(): Record; /** * Resolves the effective tracer and meter for this cluster and builds the * {@link ObservabilityInstruments} threaded through every operation. * * Tracing/metrics are considered explicitly disabled only when the relevant * config is present AND its `enable*` flag is `false`. A user-provided * tracer/meter always wins; otherwise we default to the threshold-logging * tracer / logging meter, falling back to no-op implementations when disabled. * * @returns A `[enableTracing, enableMetrics]` tuple. * @internal */ private _setupObservability; /** * @throws AuthenticationFailureError * @throws InvalidArgumentError * @private */ private _connect; }