import * as grpc from '@grpc/grpc-js'; import type { KeyspaceScope, SearchBackend } from '../backends'; import type { ObservableRequestHandler } from '../observabilityhandler'; import type { SearchQuery } from '../searchquery'; import { SearchMetaData, SearchQueryOptions, SearchRequest, SearchResult, SearchRow } from '../searchtypes'; import { StreamableRowPromise } from '../streamablepromises'; import type { Facet as FacetPb } from './generated/couchbase/search/v1/Facet'; import type { Query as QueryPb } from './generated/couchbase/search/v1/Query'; import type { SearchQueryRequest as SearchQueryRequestPb } from './generated/couchbase/search/v1/SearchQueryRequest'; import type { _couchbase_search_v1_SearchQueryResponse_FacetResult__Output as FacetResultPb, _couchbase_search_v1_SearchQueryResponse_MetaData__Output as MetaDataPb, _couchbase_search_v1_SearchQueryResponse_SearchQueryRow__Output as HitPb } from './generated/couchbase/search/v1/SearchQueryResponse'; import type { SearchServiceClient } from './generated/couchbase/search/v1/SearchService'; import type { Sorting as SortingPb } from './generated/couchbase/search/v1/Sorting'; import type { Couchbase2Op, RequestContext } from './requestcontext'; import { OpenStreams } from './streaming'; /** * A search, which changes nothing. * * @internal */ export declare const SEARCH: Couchbase2Op; /** * A JSON object, as a query, sort or facet serializes to. */ type Json = { [key: string]: unknown; }; /** * Whether `value` survives the gateway unchanged: the gateway holds it as a * 32 bit float and forwards the shortest decimal naming that float. * * @internal */ export declare function exactFloat32(value: number): boolean; /** * A query, from the JSON a classic connection sends, as the gateway's. * * @internal */ export declare function queryToProto(query: unknown): QueryPb; /** * A sort, from a string or the JSON of a `SearchSort`, as the gateway's. A * string names a field, `_id` or `_score`, descending after a `-`. * * @internal */ export declare function sortToProto(sort: unknown): SortingPb; /** * A facet, from the JSON of a `SearchFacet`, as the gateway's. * * @internal */ export declare function facetToProto(facet: unknown): FacetPb; /** * A search's request, with what reading its answer needs to know of it. * * @internal */ export interface EncodedSearch { /** * The request the gateway is sent. */ message: SearchQueryRequestPb; /** * Whether the request asked for highlighting, so that a hit keeps its * fragments. */ fragments: boolean; /** * Whether the request asked for highlighting or locations, so that a hit * keeps its locations. */ locations: boolean; /** * Each facet's JSON, by name, which its ranges' bounds are read back from. */ facets: { [name: string]: Json; }; } /** * A search's request. The gateway ignores a search's bucket and scope, so * a scope's index is sent by its full name, `bucket.scope.index`. * * @internal */ export declare function searchRequestToProto(indexName: string, request: SearchQuery | SearchRequest, options: SearchQueryOptions, scope?: KeyspaceScope): EncodedSearch; /** * A hit, as classic reports one. The gateway sends each stored field as * its own JSON, merged here into one object. It highlights every search, so * fragments and locations are kept only when the request asked for them. * * @internal */ export declare function searchRowFromProto(hit: HitPb, encoded: EncodedSearch): any; /** * A facet's result, as classic reports one. The gateway sends numeric bounds * as integers and date bounds as timestamps, so each range's bounds are * taken from the request, as the Search service would echo them. * * @internal */ export declare function searchFacetFromProto(name: string, result: FacetResultPb, requested: Json | undefined): any; /** * A search's metadata and facets, as classic reports them. The gateway * carries no client context ID. * * @internal */ export declare function searchMetaDataFromProto(meta: MetaDataPb | undefined, facets: { [name: string]: FacetResultPb; }, encoded: EncodedSearch): SearchMetaData; /** * What a search needs from the backend. * * @internal */ export interface Couchbase2SearchChannel { /** * 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 search that does not set its own, in milliseconds. */ readonly searchTimeout: 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 search's rows, metadata and failure are reported through. */ type SearchEmitter = StreamableRowPromise; /** * Searches over the gateway's `SearchService`. * * @internal */ export declare class Couchbase2Search implements SearchBackend { private readonly _channel; private readonly _client; constructor(channel: Couchbase2SearchChannel, client: SearchServiceClient); /** * Sends the search and emits its hits as each message arrives. A request * that cannot be built fails on a later tick, so the caller can attach * listeners first. `obs` ends with the stream. */ search(indexName: string, request: SearchQuery | SearchRequest, options: SearchQueryOptions, scope?: KeyspaceScope, obs?: ObservableRequestHandler | null): SearchEmitter; /** * Reads the stream one message at a time and emits each message's hits * before reading the next. The gateway may send facets and metadata in * any message, so they are gathered and emitted once the stream ends. */ private _stream; } export {};