UNPKG

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