/// import * as grpc from '@grpc/grpc-js'; import { inspect } from 'util'; import type { KvAppendRequest, KvBackend, KvCounterRequest, KvDurability, KvGetAndLockRequest, KvGetAndTouchRequest, KvGetRequest, KvInsertRequest, KvLookupInReplicaRequest, KvLookupInRequest, KvMutateInRequest, KvPrependRequest, KvReadRequest, KvReplaceRequest, KvReplicaReadRequest, KvRemoveRequest, KvRequest, KvScanRequest, KvTouchRequest, KvUnlockRequest, KvUpsertRequest } from '../backends'; import type { GetReplicaResult, LookupInReplicaResult, ScanResult } from '../crudoptypes'; import { CounterResult, ExistsResult, GetResult, LookupInResult, MutateInResult, MutationResult } from '../crudoptypes'; import type { MutationToken } from '../mutationstate'; import type { ObservableRequestHandler } from '../observabilityhandler'; import type { StreamableReplicasPromise, StreamableScanPromise } from '../streamablepromises'; import type { Cas, CasInput } from '../utilities'; import type { AppendRequest as AppendRequestPb } from './generated/couchbase/kv/v1/AppendRequest'; import type { DecrementResponse__Output as DecrementResponsePb } from './generated/couchbase/kv/v1/DecrementResponse'; import type { DurabilityLevel as DurabilityLevelInputPb } from './generated/couchbase/kv/v1/DurabilityLevel'; import type { GetRequest as GetRequestPb } from './generated/couchbase/kv/v1/GetRequest'; import type { GetResponse__Output as GetResponsePb } from './generated/couchbase/kv/v1/GetResponse'; import type { InsertRequest as InsertRequestPb } from './generated/couchbase/kv/v1/InsertRequest'; import type { IncrementRequest as IncrementRequestPb } from './generated/couchbase/kv/v1/IncrementRequest'; import type { IncrementResponse__Output as IncrementResponsePb } from './generated/couchbase/kv/v1/IncrementResponse'; import type { ExistsRequest as ExistsRequestPb } from './generated/couchbase/kv/v1/ExistsRequest'; import type { ExistsResponse__Output as ExistsResponsePb } from './generated/couchbase/kv/v1/ExistsResponse'; import type { GetAndLockRequest as GetAndLockRequestPb } from './generated/couchbase/kv/v1/GetAndLockRequest'; import type { GetAndLockResponse__Output as GetAndLockResponsePb } from './generated/couchbase/kv/v1/GetAndLockResponse'; import type { GetAndTouchRequest as GetAndTouchRequestPb } from './generated/couchbase/kv/v1/GetAndTouchRequest'; import type { GetAndTouchResponse__Output as GetAndTouchResponsePb } from './generated/couchbase/kv/v1/GetAndTouchResponse'; import type { KvServiceClient } from './generated/couchbase/kv/v1/KvService'; import type { LookupInRequest as LookupInRequestPb } from './generated/couchbase/kv/v1/LookupInRequest'; import type { LookupInResponse__Output as LookupInResponsePb } from './generated/couchbase/kv/v1/LookupInResponse'; import type { MutateInRequest as MutateInRequestPb } from './generated/couchbase/kv/v1/MutateInRequest'; import type { MutateInResponse__Output as MutateInResponsePb } from './generated/couchbase/kv/v1/MutateInResponse'; import type { MutationToken__Output as MutationTokenOutputPb } from './generated/couchbase/kv/v1/MutationToken'; import type { PrependRequest as PrependRequestPb } from './generated/couchbase/kv/v1/PrependRequest'; import type { RemoveRequest as RemoveRequestPb } from './generated/couchbase/kv/v1/RemoveRequest'; import type { ReplaceRequest as ReplaceRequestPb } from './generated/couchbase/kv/v1/ReplaceRequest'; import type { TouchRequest as TouchRequestPb } from './generated/couchbase/kv/v1/TouchRequest'; import type { UnlockRequest as UnlockRequestPb } from './generated/couchbase/kv/v1/UnlockRequest'; import type { UpsertRequest as UpsertRequestPb } from './generated/couchbase/kv/v1/UpsertRequest'; import type { UpsertResponse__Output as UpsertResponsePb } from './generated/couchbase/kv/v1/UpsertResponse'; import type { Couchbase2Op, RequestContext } from './requestcontext'; /** * @internal */ export declare const GET: Couchbase2Op; /** * @internal */ export declare const UPSERT: Couchbase2Op; /** * @internal */ export declare const INSERT: Couchbase2Op; /** * @internal */ export declare const REPLACE: Couchbase2Op; /** * @internal */ export declare const REMOVE: Couchbase2Op; /** * @internal */ export declare const EXISTS: Couchbase2Op; /** * @internal */ export declare const GET_AND_TOUCH: Couchbase2Op; /** * @internal */ export declare const TOUCH: Couchbase2Op; /** * @internal */ export declare const GET_AND_LOCK: Couchbase2Op; /** * @internal */ export declare const UNLOCK: Couchbase2Op; /** * @internal */ export declare const INCREMENT: Couchbase2Op; /** * @internal */ export declare const DECREMENT: Couchbase2Op; /** * @internal */ export declare const APPEND: Couchbase2Op; /** * @internal */ export declare const PREPEND: Couchbase2Op; /** * @internal */ export declare const LOOKUP_IN: Couchbase2Op; /** * @internal */ export declare const MUTATE_IN: Couchbase2Op; /** * A CAS read from the gateway. Prints and serializes as its decimal value, * as a classic CAS does. * * @internal */ export declare class Couchbase2Cas implements Cas { private readonly _value; constructor(value: string); /** * The decimal value. */ toString(): string; /** * The decimal value, as a string. */ toJSON(): any; /** * @internal */ [inspect.custom](): string; } /** * A mutation token read from the gateway. `toJSON` has the shape a classic * connection's token has, which `MutationState` reads. * * @internal */ export declare class Couchbase2MutationToken implements MutationToken { readonly bucket_name: string; readonly partition_id: number; readonly partition_uuid: string; readonly sequence_number: string; constructor(token: MutationTokenOutputPb); /** * The token as `bucket:partition:uuid:sequence`. */ toString(): string; /** * The token in the shape a classic connection serializes it to. */ toJSON(): any; /** * @internal */ [inspect.custom](): string; } /** * The proto durability level for a mutation's durability, or undefined for * none. The legacy observe based durability has no couchbase2 form. * * @internal */ export declare function durabilityToProto(durability: KvDurability): DurabilityLevelInputPb | undefined; /** * A CAS as the decimal string the proto takes, or undefined for none. Zero * is none, as on classic. A couchbase2 CAS prints as its decimal value; a * classic one, like a bare `Buffer`, carries its eight bytes in `raw` in the * platform's byte order. * * @internal */ export declare function casToProto(cas: CasInput | undefined): string | undefined; /** * A mutation's expiry fields. `expiry` is in the server's form: up to 30 * days is relative seconds, anything larger is epoch seconds. * * The gateway reads a missing expiry as "keep the existing one", so no * expiry is sent as zero and preserving is the field left out. Preserving * beside an expiry applies it to a new document only; the gateway refuses * that flag with no expiry. * * @internal */ export declare function expiryToProto(expiry: number, preserveExpiry: boolean): Pick; /** * The expiry a touch sets, in the form `expiryToProto` takes. Zero is sent * as it is, since a touch to zero clears the expiry. * * @internal */ export declare function touchExpiryToProto(expiry: number): Pick; /** * @internal */ export declare function getRequestToProto(req: KvGetRequest): GetRequestPb; /** * A get's result. The gateway always sends the expiry; the result carries * it only when asked for, as epoch seconds or 0 for none, as on classic. * * @internal */ export declare function getResultFromProto(resp: GetResponsePb, req: KvGetRequest): GetResult; /** * @internal */ export declare function existsRequestToProto(req: KvRequest): ExistsRequestPb; /** * An exists result. A missing document has a CAS of zero, as on a classic * connection. * * @internal */ export declare function existsResultFromProto(resp: ExistsResponsePb): ExistsResult; /** * @internal */ export declare function getAndTouchRequestToProto(req: KvGetAndTouchRequest): GetAndTouchRequestPb; /** * @internal */ export declare function touchRequestToProto(req: KvTouchRequest): TouchRequestPb; /** * @internal */ export declare function getAndLockRequestToProto(req: KvGetAndLockRequest): GetAndLockRequestPb; /** * A getAndTouch or getAndLock result. Like a classic connection's, it * carries no expiry. * * @internal */ export declare function lockedOrTouchedResultFromProto(resp: GetAndTouchResponsePb | GetAndLockResponsePb, req: KvReadRequest, op: string): GetResult; /** * An unlock's request. The CAS is the one the lock returned, so none is * refused rather than sent as zero. * * @internal */ export declare function unlockRequestToProto(req: KvUnlockRequest): UnlockRequestPb; /** * @internal */ export declare function upsertRequestToProto(req: KvUpsertRequest): UpsertRequestPb; /** * @internal */ export declare function insertRequestToProto(req: KvInsertRequest): InsertRequestPb; /** * A replace's request. `ReplaceRequest` has no preserve flag; leaving the * expiry out preserves it, so preserving drops any expiry given beside it. * * @internal */ export declare function replaceRequestToProto(req: KvReplaceRequest): ReplaceRequestPb; /** * @internal */ export declare function removeRequestToProto(req: KvRemoveRequest): RemoveRequestPb; /** * An increment's or a decrement's request (the messages share fields). The * expiry applies only to a counter the call creates, and is sent as is, zero * included. * * @internal */ export declare function counterRequestToProto(req: KvCounterRequest): IncrementRequestPb; /** * A counter's result. The proto's `content` is signed and the counter is * not, so the value is read back as unsigned. * * @internal */ export declare function counterResultFromProto(resp: IncrementResponsePb | DecrementResponsePb): CounterResult; /** * An append's request. * * @internal */ export declare function appendRequestToProto(req: KvAppendRequest): AppendRequestPb; /** * A prepend's request. `PrependRequest` has the same fields as * `AppendRequest`. * * @internal */ export declare function prependRequestToProto(req: KvPrependRequest): PrependRequestPb; /** * A mutation's result. * * @internal */ export declare function mutationResultFromProto(resp: Pick): MutationResult; /** * The order to send a request's specs in: the xattr specs, then the rest, * each group as written. * * The server needs xattr specs first. The gateway reorders them itself but * then matches answers to specs in the sent order, so an xattr spec after a * body spec gets another spec's answer. Sending them first avoids that; the * SDK restores the caller's order on the way back. * * @internal */ export declare function xattrsFirst(xattr: boolean[]): number[]; /** * A lookup-in's request, its specs sent in `order`. * * @internal */ export declare function lookupInRequestToProto(req: KvLookupInRequest, order: number[]): LookupInRequestPb; /** * A lookup-in's result, its entries in the order the caller wrote the specs. * * The gateway answers `exists` with content `true` or `false` and no * status; as on classic, `false` becomes `path_not_found` with no error. The * gateway does not report tombstones. * * @internal */ export declare function lookupInResultFromProto(resp: LookupInResponsePb, req: KvLookupInRequest, order: number[]): LookupInResult; /** * A mutate-in's request, its specs sent in `order`. * * `MutateInRequest` has no preserve flag (leaving the expiry out preserves * it), so preserving beside an expiry is refused. The gateway would store a * mutation macro as written rather than expand it, so macros are refused. * * @internal */ export declare function mutateInRequestToProto(req: KvMutateInRequest, order: number[]): MutateInRequestPb; /** * A mutate-in's result, its entries in the order the caller wrote the specs. * Only a counter's answer carries content, the counter's new value. * * @internal */ export declare function mutateInResultFromProto(resp: MutateInResponsePb, order: number[]): MutateInResult; /** * What the key-value operations need from the backend. * * @internal */ export interface Couchbase2KvChannel { /** * The metadata every call carries. */ readonly metadata: grpc.Metadata; /** * A new request's context, traced under `obs` when it is given. */ context(op: Couchbase2Op, timeoutMs: number, obs?: ObservableRequestHandler | null): RequestContext; } /** * Key-value operations over the gateway's `KvService`. * * @internal */ export declare class Couchbase2Kv implements KvBackend { private readonly _channel; private readonly _client; constructor(channel: Couchbase2KvChannel, client: KvServiceClient); /** * Reads a document with `KvService.Get`. */ get(req: KvGetRequest): Promise; /** * Writes a document with `KvService.Upsert`. */ upsert(req: KvUpsertRequest): Promise; /** * Checks for a document with `KvService.Exists`. */ exists(req: KvRequest): Promise; /** * Not supported over couchbase2. Throws `FeatureNotAvailableError`. */ getAnyReplica(_req: KvReplicaReadRequest): Promise; /** * Not supported over couchbase2. Throws `FeatureNotAvailableError`. */ getAllReplicas(_req: KvReplicaReadRequest): StreamableReplicasPromise; /** * Creates a document with `KvService.Insert`. */ insert(req: KvInsertRequest): Promise; /** * Replaces a document with `KvService.Replace`. */ replace(req: KvReplaceRequest): Promise; /** * Removes a document with `KvService.Remove`. */ remove(req: KvRemoveRequest): Promise; /** * Reads a document and sets its expiry with `KvService.GetAndTouch`. */ getAndTouch(req: KvGetAndTouchRequest): Promise; /** * Sets a document's expiry with `KvService.Touch`. */ touch(req: KvTouchRequest): Promise; /** * Reads and locks a document with `KvService.GetAndLock`. */ getAndLock(req: KvGetAndLockRequest): Promise; /** * Releases a lock with `KvService.Unlock`. */ unlock(req: KvUnlockRequest): Promise; /** * Reads paths in a document with `KvService.LookupIn`. */ lookupIn(req: KvLookupInRequest): Promise; /** * Not supported over couchbase2. Throws `FeatureNotAvailableError`. */ lookupInAnyReplica(_req: KvLookupInReplicaRequest): Promise; /** * Not supported over couchbase2. Throws `FeatureNotAvailableError`. */ lookupInAllReplicas(_req: KvLookupInReplicaRequest): StreamableReplicasPromise; /** * Changes paths in a document with `KvService.MutateIn`. */ mutateIn(req: KvMutateInRequest): Promise; /** * Increments a counter with `KvService.Increment`. */ increment(req: KvCounterRequest): Promise; /** * Decrements a counter with `KvService.Decrement`. */ decrement(req: KvCounterRequest): Promise; /** * Adds bytes to the end of a document with `KvService.Append`. */ append(req: KvAppendRequest): Promise; /** * Adds bytes to the start of a document with `KvService.Prepend`. */ prepend(req: KvPrependRequest): Promise; /** * Not supported over couchbase2. Throws `FeatureNotAvailableError`. */ scan(_req: KvScanRequest): StreamableScanPromise; }