import { ArrayMap, BucketName, Cas, CasInput, CollectionName, CouchbaseClusterTypes, DefaultClusterTypes, DocDefMatchingKey, If, IsNever, KeyspaceDocDef, QueryContext, ScopeName } from '@cbjsdev/shared'; import { CppDocumentId, CppTransaction, CppTransactionGetMetaData, CppTransactionLinks, CppTransactions } from './binding.js'; import { Cluster } from './cluster.js'; import { CollectionKeyspace } from './clusterTypes/clusterTypes.js'; import { AnyCollection } from './clusterTypes/index.js'; import { Collection } from './collection.js'; import { DurabilityLevel } from './generaltypes.js'; import { QueryMetaData, QueryProfileMode, QueryResult, QueryScanConsistency } from './querytypes.js'; import { Transcoder } from './transcoders.js'; /** * Represents the path to a document. * * @category Transactions */ export declare class DocumentId, S extends ScopeName, C extends CollectionName, const Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> { /** * The name of the bucket containing the document. */ bucket: B; /** * The name of the scope containing the document. */ scope: S; /** * The name of the collection containing the document. */ collection: C; /** * The key of the document. */ key: Key; constructor(bucket: B, scope: S, collection: C, key: Key); } /** * Specifies the configuration options for a Transaction Keyspace. * * @category Transactions */ export type TransactionKeyspace = { /** * The name of the bucket for the Keyspace. */ bucket: string; /** * The name of the scope for the Keyspace. */ scope?: string; /** * The name of the collection for the Keyspace. */ collection?: string; }; /** * Represents the mode of the Transactional GetMulti operation. * * @category Transactions */ export declare enum TransactionGetMultiMode { /** * Indicates that the Transactional GetMulti op should prioritise latency. */ PrioritiseLatency = "prioritise_latency", /** * Indicates that the Transactional GetMulti op should disable read skew detection. */ DisableReadSkewDetection = "disable_read_skew_detection", /** * Indicates that the Transactional GetMulti op should prioritise read skew detection. */ PrioritiseReadSkewDetection = "prioritise_read_skew_detection" } /** * Represents the mode of the Transactional GetMultiReplicasFromPreferredServerGroup operation. * * @category Transactions */ export declare enum TransactionGetMultiReplicasFromPreferredServerGroupMode { /** * Indicates that the Transactional GetMultiReplicasFromPreferredServerGroup op should prioritise latency. */ PrioritiseLatency = "prioritise_latency", /** * Indicates that the Transactional GetMultiReplicasFromPreferredServerGroup op should disable read skew detection. */ DisableReadSkewDetection = "disable_read_skew_detection", /** * Indicates that the Transactional GetMultiReplicasFromPreferredServerGroup op should prioritise read skew detection. */ PrioritiseReadSkewDetection = "prioritise_read_skew_detection" } /** * Specifies the configuration options for Transactions cleanup. * * @category Transactions */ export type TransactionsCleanupConfig = { /** * Specifies the period of the cleanup system. */ cleanupWindow?: number; /** * Specifies whether or not the cleanup system should clean lost attempts. */ disableLostAttemptCleanup?: boolean; /** * Specifies whether or not the cleanup system should clean client attempts. */ disableClientAttemptCleanup?: boolean; }; /** * Specifies the configuration options for Transactions queries. * * @category Transactions */ export type TransactionsQueryConfig = { /** * Specifies the default scan consistency level for queries. */ scanConsistency?: QueryScanConsistency; }; /** * Specifies the configuration options for Transactions. * * @category Transactions */ export type TransactionsConfig = { /** * Specifies the level of synchronous durability level. */ durabilityLevel?: DurabilityLevel; /** * Specifies the default timeout for KV operations, specified in millseconds. * * @deprecated Currently a no-op. CXXCBC-391: Adds support for ExtSDKIntegration which uses KV durable timeout internally. */ kvTimeout?: number; /** * Specifies the default timeout for transactions. */ timeout?: number; /** * Specifies the configuration for queries. */ queryConfig?: TransactionsQueryConfig; /** * Specifies the configuration for the cleanup system. */ cleanupConfig?: TransactionsCleanupConfig; /** * Specifies the Keyspace (bucket, scope & collection) for the transaction metadata. */ metadataCollection?: TransactionKeyspace; }; /** * Specifies the configuration options for a Transaction. * * @category Transactions */ export type TransactionOptions = { /** * Specifies the level of synchronous durability level. */ durabilityLevel?: DurabilityLevel; /** * Specifies the timeout for the transaction. */ timeout?: number; }; /** * Represents the path to a document. * * @category Transactions */ export declare class TransactionGetMultiSpec, S extends ScopeName, C extends CollectionName, const Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> { constructor(collection: Collection, id: Key, transcoder?: Transcoder); /** * The Collection where the document belongs. */ collection: Collection; /** * The id (or key) of the document. */ id: Key; /** * The Transcoder to encode/decode the document. */ transcoder?: Transcoder; /** * @internal */ _toCppDocumentId(): CppDocumentId; } /** * Represents the path to a document. * * @category Transactions */ export declare class TransactionGetMultiReplicasFromPreferredServerGroupSpec, S extends ScopeName, C extends CollectionName, const Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> { constructor(collection: Collection, id: Key, transcoder?: Transcoder); /** * The Collection where the document belongs. */ collection: Collection; /** * The id (or key) of the document. */ id: Key; /** * The Transcoder to encode/decode the document. */ transcoder?: Transcoder; /** * @internal */ _toCppDocumentId(): CppDocumentId; } /** * Contains the results of a Transaction. * * @category Transactions */ export declare class TransactionResult { /** * @internal */ constructor(data: { transactionId: string; unstagingComplete: boolean; }); /** * The ID of the completed transaction. */ transactionId: string; /** * Whether all documents were successfully unstaged and are now available * for non-transactional operations to see. */ unstagingComplete: boolean; } export type TransactionDocInfo = BucketName, S extends ScopeName = ScopeName, C extends CollectionName = CollectionName, Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> = { /** * The id of the document. */ id: DocumentId; /** * The CAS of the document. */ cas: Cas; /** * @internal */ _links: CppTransactionLinks; /** * @internal */ _metadata: CppTransactionGetMetaData; }; /** * Contains the results of a transactional Get operation. * * @category Transactions */ export declare class TransactionGetResult = BucketName, S extends ScopeName = ScopeName, C extends CollectionName = CollectionName, Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> { /** * The id of the document. */ id: DocumentId; /** * The content of the document. */ content: DocDefMatchingKey['Body']; /** * The CAS of the document. */ cas: Cas; /** * @internal */ _links: CppTransactionLinks; /** * @internal */ _metadata: CppTransactionGetMetaData; /** * @internal */ constructor(data: TransactionGetResult); } /** * Contains the results of a specific sub-operation within a transactional GetMulti operation. * * @category Transactions */ export declare class TransactionGetMultiResultEntry { /** * The error, if any, which occured when attempting to perform this sub-operation. */ error: Err; /** * The value returned by the sub-operation. */ value: Value; /** * @internal */ constructor(data: { value: Value; error: Err; }); } /** * Contains the results of a transactional GetMulti operation. * * @category Transactions */ export declare class TransactionGetMultiResult> { /** * The content of the document. */ content: Entries; /** * @internal */ constructor(data: { content: Entries; }); /** * Indicates whether the document at the specified index exists. * * @param index The result index to check. */ exists(index: number): boolean; /** * Provides the content at the specified index, if it exists. * * @param index The result index to check. */ contentAt(index: Index): ArrayMap[Index]; } /** * Contains the results of a specific sub-operation within * a transactional GetMultiReplicasFromPreferredServerGroup operation. * * @category Transactions */ export declare class TransactionGetMultiReplicasFromPreferredServerGroupResultEntry { /** * The error, if any, which occured when attempting to access the document. */ error: Err; /** * The value of the document. */ value: Value; /** * @internal */ constructor(data: { value: Value; error: Err; }); } /** * Contains the results of a transactional GetMultiReplicasFromPreferredServerGroup operation. * * @category Transactions */ export declare class TransactionGetMultiReplicasFromPreferredServerGroupResult> { /** * The content of the document. */ content: Entries; /** * @internal */ constructor(data: { content: Entries; }); /** * Indicates whether the document at the specified index exists. * * @param index The result index to check. */ exists(index: number): boolean; /** * Provides the content at the specified index, if it exists. * * @param index The result index to check. */ contentAt(index: Index): ArrayMap[Index]; } /** * Contains the results of a transactional Exists operation. * * @category Transactions */ export declare class TransactionExistsResult = BucketName, S extends ScopeName = ScopeName, C extends CollectionName = CollectionName, Key extends KeyspaceDocDef['Key'] = KeyspaceDocDef['Key']> { /** * The id of the document. */ id: DocumentId; /** * Indicates whether the document existed or not. */ exists: Exists; /** * The CAS of the document. */ cas: If; /** * @internal */ _links: If; /** * @internal */ _metadata: If; /** * @internal */ constructor(data: { id: DocumentId; exists: Exists; cas: If; _links: If; _metadata: If; }); } /** * Contains the results of a transactional Query operation. * * @category Transactions */ export declare class TransactionQueryResult { /** * The rows which have been returned by the query. */ rows: TRow[]; /** * The meta-data which has been returned by the query. */ meta: QueryMetaData; /** * @internal */ constructor(data: QueryResult); } /** * @category Transactions */ export type TransactionQueryOptions = { queryContext?: QueryContext; /** * Values to be used for the placeholders within the query. */ parameters?: { [key: string]: any; } | any[]; /** * Specifies the consistency requirements when executing the query. * * @default QueryScanConsistency.NotBounded * @see QueryScanConsistency */ scanConsistency?: QueryScanConsistency; /** * Specifies whether this is an ad-hoc query, or if it should be prepared * for faster execution in the future. * * @default true */ adhoc?: boolean; /** * The returned client context id for this query. */ clientContextId?: string; /** * This is an advanced option, see the query service reference for more * information on the proper use and tuning of this option. */ maxParallelism?: number; /** * This is an advanced option, see the query service reference for more * information on the proper use and tuning of this option. */ pipelineBatch?: number; /** * This is an advanced option, see the query service reference for more * information on the proper use and tuning of this option. */ pipelineCap?: number; /** * This is an advanced option, see the query service reference for more * information on the proper use and tuning of this option. Specified * in milliseconds. */ scanWait?: number; /** * This is an advanced option, see the query service reference for more * information on the proper use and tuning of this option. */ scanCap?: number; /** * Specifies that this query should be executed in read-only mode, disabling * the ability for the query to make any changes to the data. * * @default false */ readOnly?: boolean; /** * Specifies the level of profiling that should be used for the query. */ profile?: QueryProfileMode; /** * Specifies whether metrics should be captured as part of the execution of * the query. * * @default false */ metrics?: WithMetrics; /** * Specifies any additional parameters which should be passed to the query engine * when executing the query. */ raw?: { [key: string]: any; }; /** * Specifies the default function to parse results from the query service. * * @default {@link JSON.parse} */ queryResultParser?: (value: string) => any; }; /** * @category Transactions */ export interface TransactionGetOptions { /** * Specifies an explicit transcoder to use for this specific operation. */ transcoder?: Transcoder; } /** * @category Transactions */ export interface TransactionGetReplicaFromPreferredServerGroupOptions { /** * Specifies an explicit transcoder to use for this specific operation. */ transcoder?: Transcoder; } /** * @category Transactions */ export interface TransactionGetMultiOptions { /** * Specifies a mode to use for this specific operation. */ mode?: TransactionGetMultiMode; } /** * @category Transactions */ export interface TransactionGetMultiReplicasFromPreferredServerGroupOptions { /** * Specifies a mode to use for this specific operation. */ mode?: TransactionGetMultiReplicasFromPreferredServerGroupMode; } /** * @category Transactions */ export interface TransactionInsertOptions { /** * Specifies an explicit transcoder to use for this specific operation. */ transcoder?: Transcoder; } /** * @category Transactions */ export interface TransactionReplaceOptions { /** * Specifies an explicit transcoder to use for this specific operation. */ transcoder?: Transcoder; } /** * Represents a {@link TransactionAttemptContext} where the bucket has been defined. */ export type TransactionAttemptContextBucket = never> = ReturnType['bucket']>; type SpecsToEntries = Specs extends readonly [TransactionGetMultiSpec, ...infer Rest] ? [ TransactionGetMultiResultEntry['Body']>, ...SpecsToEntries ] : [ ]; type SpecsToPreferredEntries = Specs extends readonly [TransactionGetMultiReplicasFromPreferredServerGroupSpec, ...infer Rest] ? [ TransactionGetMultiReplicasFromPreferredServerGroupResultEntry['Body']>, ...SpecsToPreferredEntries ] : [ ]; /** * Represents a {@link TransactionAttemptContext} where the bucket and the scope have been defined. */ export type TransactionAttemptContextScope = never, S extends ScopeName = never> = ReturnType['bucket']>['scope']>; /** * Provides an interface to preform transactional operations in a transaction. * * @category Transactions */ export declare class TransactionAttemptContext = never, B extends BucketName = never, S extends ScopeName = never, C extends CollectionName = never> { private cluster; private _impl; private transcoder; /** * @internal */ constructor(txns: Transactions, config?: TransactionOptions); /** @internal */ get impl(): CppTransaction; /** * @internal */ _newAttempt(): Promise; /** * Retrieves the value of a document from the collection. * * @param collection The collection the document lives in. * @param key The document key to retrieve. * @param options Optional parameters for this operation. */ get, const LKey extends KeyspaceDocDef['Key'], const Key extends KeyspaceDocDef['Key']>(...args: If, [ collection: LInstance, key: LKey, options?: TransactionGetOptions ], [ key: Key, options?: TransactionGetOptions ]>): Promise, TransactionGetResult, TransactionGetResult>>; /** * Retrieves the value of a document from the collection. * * @param collection The collection the document lives in. * @param key The document key to retrieve. * @param options Optional parameters for this operation. */ getReplicaFromPreferredServerGroup, const LKey extends KeyspaceDocDef['Key'], const Key extends KeyspaceDocDef['Key']>(...args: If, [ collection: LInstance, key: LKey, options?: TransactionGetReplicaFromPreferredServerGroupOptions ], [ key: Key, options?: TransactionGetOptions ]>): Promise; /** * Retrieves the documents specified in the list of specs. * * @param specs The documents to retrieve. * @param options Optional parameters for this operation. */ getMulti>>(specs: Specs, options?: TransactionGetMultiOptions): Promise>>; /** * * @param specs The documents to retrieve. * @param options Optional parameters for this operation. */ getMultiReplicasFromPreferredServerGroup>>(specs: Specs, options?: TransactionGetMultiReplicasFromPreferredServerGroupOptions): Promise>>; /** * Check if a specific document exists in the collection or not. * * @param collection The collection the document may lives in. * @param key The document key to check. */ exists, const LKey extends KeyspaceDocDef['Key'], const Key extends KeyspaceDocDef['Key']>(...args: If, [collection: LInstance, key: LKey], [key: Key]>): Promise, TransactionExistsResult | TransactionExistsResult, TransactionExistsResult | TransactionExistsResult>>; /** * Inserts a new document to the collection, failing if the document already exists. * * @param collection The {@link Collection} the document lives in. * @param key The document key to insert. * @param content The document content to insert. * @param options Optional parameters for this operation. */ insert, const LKey extends KeyspaceDocDef['Key'], const Key extends KeyspaceDocDef['Key']>(...args: If, [ collection: LInstance, key: LKey, content: DocDefMatchingKey['Body'], options?: TransactionInsertOptions ], [ key: Key, content: DocDefMatchingKey['Body'], options?: TransactionInsertOptions ]>): Promise, TransactionGetResult, TransactionGetResult>>; /** * Replaces a document in a collection. * * @param doc The document to replace. * @param content The document content to insert. * @param options Optional parameters for this operation. */ replace, LS extends ScopeName, LC extends CollectionName, const Key extends KeyspaceDocDef['Key']>(doc: Exclude, 'cas'> & { cas: CasInput; }, content: DocDefMatchingKey['Body'], options?: TransactionReplaceOptions): Promise>; /** * Removes a document from a collection. * * @param doc The document to remove. */ remove, LS extends ScopeName, LC extends CollectionName, const Key extends KeyspaceDocDef['Key']>(doc: Exclude, 'cas'> & { cas: CasInput; }): Promise; /** * Executes a query in the context of this transaction. * * @param statement The statement to execute. * @param options Optional parameters for this operation. */ query(statement: string, options?: TransactionQueryOptions): Promise>; /** * @internal */ _commit(): Promise; /** * @internal */ _rollback(): Promise; bucket>(this: TransactionAttemptContext, bucketName: LB): { scope: >(scopeName: LS) => { collection: >(collectionName: LC) => TransactionAttemptContext, LB, LS, LC>; }; }; } /** * Provides an interface to access transactions. * * @category Transactions */ export declare class Transactions { private _cluster; private _impl; /** @internal */ constructor(cluster: Cluster, config?: TransactionsConfig); get cluster(): Cluster; /** @internal */ get impl(): CppTransactions; /** @internal */ _close(): Promise; /** * Executes a transaction. * * @param logicFn The transaction lambda to execute. * @param config Configuration operations for the transaction. */ run(logicFn: (attempt: TransactionAttemptContext) => Promise, config?: TransactionOptions): Promise; } export {};