import * as grpc from '@grpc/grpc-js'; import type { KeyspaceScope, QueryBackend } from '../backends'; import type { ObservableRequestHandler } from '../observabilityhandler'; import { QueryMetaData, QueryOptions, QueryResult } from '../querytypes'; import { StreamableRowPromise } from '../streamablepromises'; import type { QueryRequest as QueryRequestPb } from './generated/couchbase/query/v1/QueryRequest'; import type { _couchbase_query_v1_QueryResponse_MetaData__Output as QueryMetaDataOutputPb } from './generated/couchbase/query/v1/QueryResponse'; import type { QueryServiceClient } from './generated/couchbase/query/v1/QueryService'; import type { Duration__Output as DurationOutputPb } from './generated/google/protobuf/Duration'; import type { Couchbase2Op, RequestContext } from './requestcontext'; import { OpenStreams } from './streaming'; /** * The operation a query is sent as. Only a read-only query changes nothing, * so only one leaves no doubt about its outcome when it runs out of time. * * @internal */ export declare function queryOp(options: QueryOptions): Couchbase2Op; /** * A query's request. An option the gateway has no field for is not sent, * with a warning, so a query written for a classic connection still runs. * * @internal */ export declare function queryRequestToProto(statement: string, options: QueryOptions, scope?: KeyspaceScope): QueryRequestPb; /** * A duration in whole milliseconds, as a classic connection reports one. * * @internal */ export declare function durationFromProto(duration: DurationOutputPb | null): number; /** * A query's metadata, from the last message of its stream. The gateway * reports a query's errors as the call's status, so the metadata carries * none. * * @internal */ export declare function queryMetaDataFromProto(meta: QueryMetaDataOutputPb): QueryMetaData; /** * What a query needs from the backend. * * @internal */ export interface Couchbase2QueryChannel { /** * The metadata every call carries. */ readonly metadata: grpc.Metadata; /** * The streams open on the channel, canceled when it closes. */ readonly streams: OpenStreams; /** * The timeout of a query that does not set its own, in milliseconds. */ readonly queryTimeout: number; /** * A new request's context, traced under `obs` when it is given. */ context(op: Couchbase2Op, timeoutMs: number, obs?: ObservableRequestHandler | null): RequestContext; } /** * The emitter a query's rows, metadata and failure are reported through. */ type QueryEmitter = StreamableRowPromise, TRow, QueryMetaData>; /** * SQL++ queries over the gateway's `QueryService`. * * @internal */ export declare class Couchbase2Query implements QueryBackend { private readonly _channel; private readonly _client; constructor(channel: Couchbase2QueryChannel, client: QueryServiceClient); /** * Sends the query and emits its rows as each message arrives. A request * that cannot be built fails on a later tick, so the caller has the * chance to attach its listeners or await it first. `obs` ends with the * stream. */ query(statement: string, options: QueryOptions, scope?: KeyspaceScope, obs?: ObservableRequestHandler | null): QueryEmitter; /** * Reads the stream one message at a time and emits each message's rows * before reading the next, so the SDK holds at most one message beyond * what grpc-js buffers. The metadata is the last message's. * * An abort of `signal` ends the query at once and cancels the call, and * the stream's own end is then ignored. */ private _stream; } export {};