UNPKG

9.82 kBTypeScriptView Raw
1import { CppTransactions, CppTransaction, CppTransactionLinks, CppTransactionGetMetaData } from './binding';
2import { Cluster } from './cluster';
3import { Collection } from './collection';
4import { DurabilityLevel } from './generaltypes';
5import { QueryMetaData, QueryProfileMode, QueryResult, QueryScanConsistency } from './querytypes';
6import { Scope } from './scope';
7import { Cas } from './utilities';
8/**
9 * Represents the path to a document.
10 *
11 * @category Transactions
12 */
13export declare class DocumentId {
14 constructor();
15 /**
16 * The name of the bucket containing the document.
17 */
18 bucket: string;
19 /**
20 * The name of the scope containing the document.
21 */
22 scope: string;
23 /**
24 * The name of the collection containing the document.
25 */
26 collection: string;
27 /**
28 * The key of the docuemnt.
29 */
30 key: string;
31}
32/**
33 * Specifies the configuration options for a Transaction Keyspace.
34 *
35 * @category Transactions
36 */
37export interface TransactionKeyspace {
38 /**
39 * The name of the bucket for the Keyspace.
40 */
41 bucket: string;
42 /**
43 * The name of the scope for the Keyspace.
44 */
45 scope?: string;
46 /**
47 * The name of the collection for the Keyspace.
48 */
49 collection?: string;
50}
51/**
52 * Specifies the configuration options for Transactions cleanup.
53 *
54 * @category Transactions
55 */
56export interface TransactionsCleanupConfig {
57 /**
58 * Specifies the period of the cleanup system.
59 */
60 cleanupWindow?: number;
61 /**
62 * Specifies whether or not the cleanup system should clean lost attempts.
63 */
64 disableLostAttemptCleanup?: boolean;
65 /**
66 * Specifies whether or not the cleanup system should clean client attempts.
67 */
68 disableClientAttemptCleanup?: boolean;
69}
70/**
71 * Specifies the configuration options for Transactions queries.
72 *
73 * @category Transactions
74 */
75export interface TransactionsQueryConfig {
76 /**
77 * Specifies the default scan consistency level for queries.
78 */
79 scanConsistency?: QueryScanConsistency;
80}
81/**
82 * Specifies the configuration options for Transactions.
83 *
84 * @category Transactions
85 */
86export interface TransactionsConfig {
87 /**
88 * Specifies the level of synchronous durability level.
89 */
90 durabilityLevel?: DurabilityLevel;
91 /**
92 * Specifies the default timeout for KV operations, specified in millseconds.
93 *
94 * @deprecated Currently a no-op. CXXCBC-391: Adds support for ExtSDKIntegration which uses KV durable timeout internally.
95 */
96 kvTimeout?: number;
97 /**
98 * Specifies the default timeout for transactions.
99 */
100 timeout?: number;
101 /**
102 * Specifies the configuration for queries.
103 */
104 queryConfig?: TransactionsQueryConfig;
105 /**
106 * Specifies the configuration for the cleanup system.
107 */
108 cleanupConfig?: TransactionsCleanupConfig;
109 /**
110 * Specifies the Keyspace (bucket, scope & collection) for the transaction metadata.
111 */
112 metadataCollection?: TransactionKeyspace;
113}
114/**
115 * Specifies the configuration options for a Transaction.
116 *
117 * @category Transactions
118 */
119export interface TransactionOptions {
120 /**
121 * Specifies the level of synchronous durability level.
122 */
123 durabilityLevel?: DurabilityLevel;
124 /**
125 * Specifies the timeout for the transaction.
126 */
127 timeout?: number;
128}
129/**
130 * Contains the results of a Transaction.
131 *
132 * @category Transactions
133 */
134export declare class TransactionResult {
135 /**
136 * @internal
137 */
138 constructor(data: {
139 transactionId: string;
140 unstagingComplete: boolean;
141 });
142 /**
143 * The ID of the completed transaction.
144 */
145 transactionId: string;
146 /**
147 * Whether all documents were successfully unstaged and are now available
148 * for non-transactional operations to see.
149 */
150 unstagingComplete: boolean;
151}
152/**
153 * Contains the results of a transactional Get operation.
154 *
155 * @category Transactions
156 */
157export declare class TransactionGetResult {
158 /**
159 * @internal
160 */
161 constructor(data: TransactionGetResult);
162 /**
163 * The id of the document.
164 */
165 id: DocumentId;
166 /**
167 * The content of the document.
168 */
169 content: any;
170 /**
171 * The CAS of the document.
172 */
173 cas: Cas;
174 /**
175 * @internal
176 */
177 _links: CppTransactionLinks;
178 /**
179 * @internal
180 */
181 _metadata: CppTransactionGetMetaData;
182}
183/**
184 * Contains the results of a transactional Query operation.
185 *
186 * @category Transactions
187 */
188export declare class TransactionQueryResult<TRow = any> {
189 /**
190 * The rows which have been returned by the query.
191 */
192 rows: TRow[];
193 /**
194 * The meta-data which has been returned by the query.
195 */
196 meta: QueryMetaData;
197 /**
198 * @internal
199 */
200 constructor(data: QueryResult);
201}
202/**
203 * @category Transactions
204 */
205export interface TransactionQueryOptions {
206 /**
207 * Values to be used for the placeholders within the query.
208 */
209 parameters?: {
210 [key: string]: any;
211 } | any[];
212 /**
213 * Specifies the consistency requirements when executing the query.
214 *
215 * @see QueryScanConsistency
216 */
217 scanConsistency?: QueryScanConsistency;
218 /**
219 * Specifies whether this is an ad-hoc query, or if it should be prepared
220 * for faster execution in the future.
221 */
222 adhoc?: boolean;
223 /**
224 * The returned client context id for this query.
225 */
226 clientContextId?: string;
227 /**
228 * This is an advanced option, see the query service reference for more
229 * information on the proper use and tuning of this option.
230 */
231 maxParallelism?: number;
232 /**
233 * This is an advanced option, see the query service reference for more
234 * information on the proper use and tuning of this option.
235 */
236 pipelineBatch?: number;
237 /**
238 * This is an advanced option, see the query service reference for more
239 * information on the proper use and tuning of this option.
240 */
241 pipelineCap?: number;
242 /**
243 * This is an advanced option, see the query service reference for more
244 * information on the proper use and tuning of this option. Specified
245 * in milliseconds.
246 */
247 scanWait?: number;
248 /**
249 * This is an advanced option, see the query service reference for more
250 * information on the proper use and tuning of this option.
251 */
252 scanCap?: number;
253 /**
254 * Specifies that this query should be executed in read-only mode, disabling
255 * the ability for the query to make any changes to the data.
256 */
257 readOnly?: boolean;
258 /**
259 * Specifies the level of profiling that should be used for the query.
260 */
261 profile?: QueryProfileMode;
262 /**
263 * Specifies whether metrics should be captured as part of the execution of
264 * the query.
265 */
266 metrics?: boolean;
267 /**
268 * Specifies any additional parameters which should be passed to the query engine
269 * when executing the query.
270 */
271 raw?: {
272 [key: string]: any;
273 };
274 /**
275 * Specifies the scope to run this query in.
276 */
277 scope?: Scope;
278}
279/**
280 * Provides an interface to preform transactional operations in a transaction.
281 *
282 * @category Transactions
283 */
284export declare class TransactionAttemptContext {
285 private _impl;
286 private _transcoder;
287 /**
288 * @internal
289 */
290 constructor(txns: Transactions, config?: TransactionOptions);
291 /**
292 @internal
293 */
294 get impl(): CppTransaction;
295 /**
296 * @internal
297 */
298 _newAttempt(): Promise<void>;
299 /**
300 * Retrieves the value of a document from the collection.
301 *
302 * @param collection The collection the document lives in.
303 * @param key The document key to retrieve.
304 */
305 get(collection: Collection, key: string): Promise<TransactionGetResult>;
306 /**
307 * Inserts a new document to the collection, failing if the document already exists.
308 *
309 * @param collection The collection the document lives in.
310 * @param key The document key to insert.
311 * @param content The document content to insert.
312 */
313 insert(collection: Collection, key: string, content: any): Promise<TransactionGetResult>;
314 /**
315 * Replaces a document in a collection.
316 *
317 * @param doc The document to replace.
318 * @param content The document content to insert.
319 */
320 replace(doc: TransactionGetResult, content: any): Promise<TransactionGetResult>;
321 /**
322 * Removes a document from a collection.
323 *
324 * @param doc The document to remove.
325 */
326 remove(doc: TransactionGetResult): Promise<void>;
327 /**
328 * Executes a query in the context of this transaction.
329 *
330 * @param statement The statement to execute.
331 * @param options Optional parameters for this operation.
332 */
333 query<TRow = any>(statement: string, options?: TransactionQueryOptions): Promise<TransactionQueryResult<TRow>>;
334 /**
335 * @internal
336 */
337 _commit(): Promise<TransactionResult>;
338 /**
339 * @internal
340 */
341 _rollback(): Promise<void>;
342}
343/**
344 * Provides an interface to access transactions.
345 *
346 * @category Transactions
347 */
348export declare class Transactions {
349 private _cluster;
350 private _impl;
351 /**
352 @internal
353 */
354 constructor(cluster: Cluster, config?: TransactionsConfig);
355 /**
356 @internal
357 */
358 get impl(): CppTransactions;
359 /**
360 @internal
361 */
362 _close(): Promise<void>;
363 /**
364 * Executes a transaction.
365 *
366 * @param logicFn The transaction lambda to execute.
367 * @param config Configuration operations for the transaction.
368 */
369 run(logicFn: (attempt: TransactionAttemptContext) => Promise<void>, config?: TransactionOptions): Promise<TransactionResult>;
370}