UNPKG

24.7 kBTypeScriptView Raw
1/// <reference types="node" />
2import { IncrementOptions, DecrementOptions, AppendOptions, PrependOptions, BinaryCollection } from './binarycollection';
3import { CppDocumentId, CppConnection, CppScanIterator, CppRangeScanOrchestratorOptions } from './binding';
4import { Cluster } from './cluster';
5import { CounterResult, ExistsResult, GetReplicaResult, GetResult, LookupInResult, LookupInReplicaResult, MutateInResult, MutationResult, ScanResult } from './crudoptypes';
6import { CouchbaseList, CouchbaseMap, CouchbaseQueue, CouchbaseSet } from './datastructures';
7import { DurabilityLevel, StoreSemantics } from './generaltypes';
8import { MutationState } from './mutationstate';
9import { CollectionQueryIndexManager } from './queryindexmanager';
10import { RangeScan, SamplingScan, PrefixScan } from './rangeScan';
11import { Scope } from './scope';
12import { LookupInSpec, MutateInSpec } from './sdspecs';
13import { StreamableReplicasPromise, StreamableScanPromise } from './streamablepromises';
14import { Transcoder } from './transcoders';
15import { NodeCallback, CasInput } from './utilities';
16/**
17 * @category Key-Value
18 */
19export interface GetOptions {
20 /**
21 * Specifies a list of fields within the document which should be fetched.
22 * This allows for easy retrieval of select fields without incurring the
23 * overhead of fetching the whole document.
24 */
25 project?: string[];
26 /**
27 * Indicates that the expiry of the document should be fetched alongside
28 * the data itself.
29 */
30 withExpiry?: boolean;
31 /**
32 * Specifies an explicit transcoder to use for this specific operation.
33 */
34 transcoder?: Transcoder;
35 /**
36 * The timeout for this operation, represented in milliseconds.
37 */
38 timeout?: number;
39}
40/**
41 * @category Key-Value
42 */
43export interface ExistsOptions {
44 /**
45 * The timeout for this operation, represented in milliseconds.
46 */
47 timeout?: number;
48}
49/**
50 * @category Key-Value
51 */
52export interface InsertOptions {
53 /**
54 * Specifies the expiry time for this document, specified in seconds.
55 */
56 expiry?: number;
57 /**
58 * Specifies the level of synchronous durability for this operation.
59 */
60 durabilityLevel?: DurabilityLevel;
61 /**
62 * Specifies the number of nodes this operation should be persisted to
63 * before it is considered successful. Note that this option is mutually
64 * exclusive of {@link durabilityLevel}.
65 */
66 durabilityPersistTo?: number;
67 /**
68 * Specifies the number of nodes this operation should be replicated to
69 * before it is considered successful. Note that this option is mutually
70 * exclusive of {@link durabilityLevel}.
71 */
72 durabilityReplicateTo?: number;
73 /**
74 * Specifies an explicit transcoder to use for this specific operation.
75 */
76 transcoder?: Transcoder;
77 /**
78 * The timeout for this operation, represented in milliseconds.
79 */
80 timeout?: number;
81}
82/**
83 * @category Key-Value
84 */
85export interface UpsertOptions {
86 /**
87 * Specifies the expiry time for this document, specified in seconds.
88 */
89 expiry?: number;
90 /**
91 * Specifies that any existing expiry on the document should be preserved.
92 */
93 preserveExpiry?: boolean;
94 /**
95 * Specifies the level of synchronous durability for this operation.
96 */
97 durabilityLevel?: DurabilityLevel;
98 /**
99 * Specifies the number of nodes this operation should be persisted to
100 * before it is considered successful. Note that this option is mutually
101 * exclusive of {@link durabilityLevel}.
102 */
103 durabilityPersistTo?: number;
104 /**
105 * Specifies the number of nodes this operation should be replicated to
106 * before it is considered successful. Note that this option is mutually
107 * exclusive of {@link durabilityLevel}.
108 */
109 durabilityReplicateTo?: number;
110 /**
111 * Specifies an explicit transcoder to use for this specific operation.
112 */
113 transcoder?: Transcoder;
114 /**
115 * The timeout for this operation, represented in milliseconds.
116 */
117 timeout?: number;
118}
119/**
120 * @category Key-Value
121 */
122export interface ReplaceOptions {
123 /**
124 * Specifies the expiry time for this document, specified in seconds.
125 */
126 expiry?: number;
127 /**
128 * Specifies that any existing expiry on the document should be preserved.
129 */
130 preserveExpiry?: boolean;
131 /**
132 * If specified, indicates that operation should be failed if the CAS
133 * has changed from this value, indicating that the document has changed.
134 */
135 cas?: CasInput;
136 /**
137 * Specifies the level of synchronous durability for this operation.
138 */
139 durabilityLevel?: DurabilityLevel;
140 /**
141 * Specifies the number of nodes this operation should be persisted to
142 * before it is considered successful. Note that this option is mutually
143 * exclusive of {@link durabilityLevel}.
144 */
145 durabilityPersistTo?: number;
146 /**
147 * Specifies the number of nodes this operation should be replicated to
148 * before it is considered successful. Note that this option is mutually
149 * exclusive of {@link durabilityLevel}.
150 */
151 durabilityReplicateTo?: number;
152 /**
153 * Specifies an explicit transcoder to use for this specific operation.
154 */
155 transcoder?: Transcoder;
156 /**
157 * The timeout for this operation, represented in milliseconds.
158 */
159 timeout?: number;
160}
161/**
162 * @category Key-Value
163 */
164export interface RemoveOptions {
165 /**
166 * If specified, indicates that operation should be failed if the CAS
167 * has changed from this value, indicating that the document has changed.
168 */
169 cas?: CasInput;
170 /**
171 * Specifies the level of synchronous durability for this operation.
172 */
173 durabilityLevel?: DurabilityLevel;
174 /**
175 * Specifies the number of nodes this operation should be persisted to
176 * before it is considered successful. Note that this option is mutually
177 * exclusive of {@link durabilityLevel}.
178 */
179 durabilityPersistTo?: number;
180 /**
181 * Specifies the number of nodes this operation should be replicated to
182 * before it is considered successful. Note that this option is mutually
183 * exclusive of {@link durabilityLevel}.
184 */
185 durabilityReplicateTo?: number;
186 /**
187 * The timeout for this operation, represented in milliseconds.
188 */
189 timeout?: number;
190}
191/**
192 * @category Key-Value
193 */
194export interface GetAnyReplicaOptions {
195 /**
196 * Specifies an explicit transcoder to use for this specific operation.
197 */
198 transcoder?: Transcoder;
199 /**
200 * The timeout for this operation, represented in milliseconds.
201 */
202 timeout?: number;
203}
204/**
205 * @category Key-Value
206 */
207export interface GetAllReplicasOptions {
208 /**
209 * Specifies an explicit transcoder to use for this specific operation.
210 */
211 transcoder?: Transcoder;
212 /**
213 * The timeout for this operation, represented in milliseconds.
214 */
215 timeout?: number;
216}
217/**
218 * @category Key-Value
219 */
220export interface TouchOptions {
221 /**
222 * Specifies the level of synchronous durability for this operation.
223 */
224 durabilityLevel?: DurabilityLevel;
225 /**
226 * The timeout for this operation, represented in milliseconds.
227 */
228 timeout?: number;
229}
230/**
231 * @category Key-Value
232 */
233export interface GetAndTouchOptions {
234 /**
235 * Specifies an explicit transcoder to use for this specific operation.
236 */
237 transcoder?: Transcoder;
238 /**
239 * The timeout for this operation, represented in milliseconds.
240 */
241 timeout?: number;
242}
243/**
244 * @category Key-Value
245 */
246export interface GetAndLockOptions {
247 /**
248 * Specifies an explicit transcoder to use for this specific operation.
249 */
250 transcoder?: Transcoder;
251 /**
252 * The timeout for this operation, represented in milliseconds.
253 */
254 timeout?: number;
255}
256/**
257 * @category Key-Value
258 */
259export interface UnlockOptions {
260 /**
261 * The timeout for this operation, represented in milliseconds.
262 */
263 timeout?: number;
264}
265/**
266 * @category Key-Value
267 */
268export interface LookupInOptions {
269 /**
270 * The timeout for this operation, represented in milliseconds.
271 */
272 timeout?: number;
273 /**
274 * For internal use only - allows access to deleted documents that are in 'tombstone' form
275 *
276 * @internal
277 */
278 accessDeleted?: boolean;
279}
280/**
281 * @category Key-Value
282 */
283export interface LookupInAnyReplicaOptions {
284 /**
285 * The timeout for this operation, represented in milliseconds.
286 */
287 timeout?: number;
288}
289/**
290 * @category Key-Value
291 */
292export interface LookupInAllReplicasOptions {
293 /**
294 * The timeout for this operation, represented in milliseconds.
295 */
296 timeout?: number;
297}
298/**
299 * @category Key-Value
300 */
301export interface MutateInOptions {
302 /**
303 * Specifies the expiry time for this document, specified in seconds.
304 */
305 expiry?: number;
306 /**
307 * Specifies that any existing expiry on the document should be preserved.
308 */
309 preserveExpiry?: boolean;
310 /**
311 * If specified, indicates that operation should be failed if the CAS
312 * has changed from this value, indicating that the document has changed.
313 */
314 cas?: CasInput;
315 /**
316 * Specifies the level of synchronous durability for this operation.
317 */
318 durabilityLevel?: DurabilityLevel;
319 /**
320 * Specifies the number of nodes this operation should be persisted to
321 * before it is considered successful. Note that this option is mutually
322 * exclusive of {@link durabilityLevel}.
323 */
324 durabilityPersistTo?: number;
325 /**
326 * Specifies the number of nodes this operation should be replicated to
327 * before it is considered successful. Note that this option is mutually
328 * exclusive of {@link durabilityLevel}.
329 */
330 durabilityReplicateTo?: number;
331 /**
332 * Specifies the store semantics to use for this operation.
333 */
334 storeSemantics?: StoreSemantics;
335 /**
336 * The timeout for this operation, represented in milliseconds.
337 */
338 timeout?: number;
339 /**
340 * Specifies whether the operation should be performed with upsert semantics,
341 * creating the document if it does not already exist.
342 *
343 * @deprecated Use {@link MutateInOptions.storeSemantics} instead.
344 */
345 upsertDocument?: boolean;
346}
347/**
348 * @category Key-Value
349 */
350export interface ScanOptions {
351 /**
352 * Specifies an explicit transcoder to use for this specific operation.
353 */
354 transcoder?: Transcoder;
355 /**
356 * The timeout for this operation, represented in milliseconds.
357 */
358 timeout?: number;
359 /**
360 * If the scan should only return document ids.
361 */
362 idsOnly?: boolean;
363 /**
364 * The limit applied to the number of bytes returned from the server
365 * for each partition batch.
366 */
367 batchByteLimit?: number;
368 /**
369 * The limit applied to the number of items returned from the server
370 * for each partition batch.
371 */
372 batchItemLimit?: number;
373 /**
374 * Specifies a MutationState which the scan should be consistent with.
375 *
376 * @see {@link MutationState}
377 */
378 consistentWith?: MutationState;
379 /**
380 * Specifies the number of vBuckets which the client should scan in parallel.
381 */
382 concurrency?: number;
383}
384/**
385 * Exposes the operations which are available to be performed against a collection.
386 * Namely the ability to perform KV operations.
387 *
388 * @category Core
389 */
390export declare class Collection {
391 /**
392 * @internal
393 */
394 static get DEFAULT_NAME(): string;
395 private _scope;
396 private _name;
397 private _conn;
398 private _kvScanTimeout;
399 private _scanBatchItemLimit;
400 private _scanBatchByteLimit;
401 /**
402 @internal
403 */
404 constructor(scope: Scope, collectionName: string);
405 /**
406 @internal
407 */
408 get conn(): CppConnection;
409 /**
410 @internal
411 */
412 get cluster(): Cluster;
413 /**
414 @internal
415 */
416 get scope(): Scope;
417 /**
418 @internal
419 */
420 get transcoder(): Transcoder;
421 /**
422 @internal
423 */
424 _mutationTimeout(durabilityLevel?: DurabilityLevel): number;
425 /**
426 * @internal
427 */
428 _cppDocId(key: string): CppDocumentId;
429 /**
430 * @internal
431 */
432 _encodeDoc(transcoder: Transcoder, value: any, callback: (err: Error | null, bytes: Buffer, flags: number) => void): void;
433 /**
434 * @internal
435 */
436 _decodeDoc(transcoder: Transcoder, bytes: Buffer, flags: number, callback: (err: Error | null, content: any) => void): void;
437 /**
438 * @internal
439 */
440 _subdocEncode(value: any): any;
441 /**
442 * @internal
443 */
444 _subdocDecode(bytes: Buffer): any;
445 /**
446 * The name of the collection this Collection object references.
447 */
448 get name(): string;
449 /**
450 * Retrieves the value of a document from the collection.
451 *
452 * @param key The document key to retrieve.
453 * @param options Optional parameters for this operation.
454 * @param callback A node-style callback to be invoked after execution.
455 */
456 get(key: string, options?: GetOptions, callback?: NodeCallback<GetResult>): Promise<GetResult>;
457 private _projectedGet;
458 /**
459 * Checks whether a specific document exists or not.
460 *
461 * @param key The document key to check for existence.
462 * @param options Optional parameters for this operation.
463 * @param callback A node-style callback to be invoked after execution.
464 */
465 exists(key: string, options?: ExistsOptions, callback?: NodeCallback<ExistsResult>): Promise<ExistsResult>;
466 /**
467 * @internal
468 */
469 _getReplica(key: string, getAllReplicas: boolean, options?: {
470 transcoder?: Transcoder;
471 timeout?: number;
472 }, callback?: NodeCallback<GetReplicaResult[]>): StreamableReplicasPromise<GetReplicaResult[], GetReplicaResult>;
473 /**
474 * Retrieves the value of the document from any of the available replicas. This
475 * will return as soon as the first response is received from any replica node.
476 *
477 * @param key The document key to retrieve.
478 * @param options Optional parameters for this operation.
479 * @param callback A node-style callback to be invoked after execution.
480 */
481 getAnyReplica(key: string, options?: GetAnyReplicaOptions, callback?: NodeCallback<GetReplicaResult>): Promise<GetReplicaResult>;
482 /**
483 * Retrieves the value of the document from all available replicas. Note that
484 * as replication is asynchronous, each node may return a different value.
485 *
486 * @param key The document key to retrieve.
487 * @param options Optional parameters for this operation.
488 * @param callback A node-style callback to be invoked after execution.
489 */
490 getAllReplicas(key: string, options?: GetAllReplicasOptions, callback?: NodeCallback<GetReplicaResult[]>): Promise<GetReplicaResult[]>;
491 /**
492 * Inserts a new document to the collection, failing if the document already exists.
493 *
494 * @param key The document key to insert.
495 * @param value The value of the document to insert.
496 * @param options Optional parameters for this operation.
497 * @param callback A node-style callback to be invoked after execution.
498 */
499 insert(key: string, value: any, options?: InsertOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
500 /**
501 * Upserts a document to the collection. This operation succeeds whether or not the
502 * document already exists.
503 *
504 * @param key The document key to upsert.
505 * @param value The new value for the document.
506 * @param options Optional parameters for this operation.
507 * @param callback A node-style callback to be invoked after execution.
508 */
509 upsert(key: string, value: any, options?: UpsertOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
510 /**
511 * Replaces the value of an existing document. Failing if the document does not exist.
512 *
513 * @param key The document key to replace.
514 * @param value The new value for the document.
515 * @param options Optional parameters for this operation.
516 * @param callback A node-style callback to be invoked after execution.
517 */
518 replace(key: string, value: any, options?: ReplaceOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
519 /**
520 * Remove an existing document from the collection.
521 *
522 * @param key The document key to remove.
523 * @param options Optional parameters for this operation.
524 * @param callback A node-style callback to be invoked after execution.
525 */
526 remove(key: string, options?: RemoveOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
527 /**
528 * Retrieves the value of the document and simultanously updates the expiry time
529 * for the same document.
530 *
531 * @param key The document to fetch and touch.
532 * @param expiry The new expiry to apply to the document, specified in seconds.
533 * @param options Optional parameters for this operation.
534 * @param callback A node-style callback to be invoked after execution.
535 */
536 getAndTouch(key: string, expiry: number, options?: GetAndTouchOptions, callback?: NodeCallback<GetResult>): Promise<GetResult>;
537 /**
538 * Updates the expiry on an existing document.
539 *
540 * @param key The document key to touch.
541 * @param expiry The new expiry to set for the document, specified in seconds.
542 * @param options Optional parameters for this operation.
543 * @param callback A node-style callback to be invoked after execution.
544 */
545 touch(key: string, expiry: number, options?: TouchOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
546 /**
547 * Locks a document and retrieves the value of that document at the time it is locked.
548 *
549 * @param key The document key to retrieve and lock.
550 * @param lockTime The amount of time to lock the document for, specified in seconds.
551 * @param options Optional parameters for this operation.
552 * @param callback A node-style callback to be invoked after execution.
553 */
554 getAndLock(key: string, lockTime: number, options?: GetAndLockOptions, callback?: NodeCallback<GetResult>): Promise<GetResult>;
555 /**
556 * Unlocks a previously locked document.
557 *
558 * @param key The document key to unlock.
559 * @param cas The CAS of the document, used to validate lock ownership.
560 * @param options Optional parameters for this operation.
561 * @param callback A node-style callback to be invoked after execution.
562 */
563 unlock(key: string, cas: CasInput, options?: UnlockOptions, callback?: NodeCallback<void>): Promise<void>;
564 /**
565 * @internal
566 */
567 _continueScan(iterator: CppScanIterator, transcoder: Transcoder, emitter: StreamableScanPromise<ScanResult[], ScanResult>): void;
568 /**
569 * @internal
570 */
571 _doScan(scanType: RangeScan | SamplingScan | PrefixScan, options: CppRangeScanOrchestratorOptions, transcoder: Transcoder, callback?: NodeCallback<ScanResult[]>): StreamableScanPromise<ScanResult[], ScanResult>;
572 /**
573 * Performs a key-value scan operation.
574 *
575 * Use this API for low concurrency batch queries where latency is not a critical as the system
576 * may have to scan a lot of documents to find the matching documents.
577 * For low latency range queries, it is recommended that you use SQL++ with the necessary indexes.
578 *
579 * @param scanType The type of scan to execute.
580 * @param options Optional parameters for the scan operation.
581 * @param callback A node-style callback to be invoked after execution.
582 */
583 scan(scanType: RangeScan | SamplingScan | PrefixScan, options?: ScanOptions, callback?: NodeCallback<ScanResult[]>): Promise<ScanResult[]>;
584 /**
585 * Performs a lookup-in operation against a document, fetching individual fields or
586 * information about specific fields inside the document value.
587 *
588 * @param key The document key to look in.
589 * @param specs A list of specs describing the data to fetch from the document.
590 * @param options Optional parameters for this operation.
591 * @param callback A node-style callback to be invoked after execution.
592 */
593 lookupIn(key: string, specs: LookupInSpec[], options?: LookupInOptions, callback?: NodeCallback<LookupInResult>): Promise<LookupInResult>;
594 /**
595 * @internal
596 */
597 _lookupInReplica(key: string, lookupInAllReplicas: boolean, specs: LookupInSpec[], options?: {
598 timeout?: number;
599 }, callback?: NodeCallback<LookupInReplicaResult[]>): StreamableReplicasPromise<LookupInReplicaResult[], LookupInReplicaResult>;
600 /**
601 * Performs a lookup-in operation against a document, fetching individual fields or
602 * information about specific fields inside the document value from any of the available
603 * replicas in the cluster.
604 *
605 * @param key The document key to look in.
606 * @param specs A list of specs describing the data to fetch from the document.
607 * @param options Optional parameters for this operation.
608 * @param callback A node-style callback to be invoked after execution.
609 */
610 lookupInAnyReplica(key: string, specs: LookupInSpec[], options?: LookupInOptions, callback?: NodeCallback<LookupInReplicaResult>): Promise<LookupInReplicaResult>;
611 /**
612 * Performs a lookup-in operation against a document, fetching individual fields or
613 * information about specific fields inside the document value from all available replicas.
614 * Note that as replication is asynchronous, each node may return a different value.
615 *
616 * @param key The document key to look in.
617 * @param specs A list of specs describing the data to fetch from the document.
618 * @param options Optional parameters for this operation.
619 * @param callback A node-style callback to be invoked after execution.
620 */
621 lookupInAllReplicas(key: string, specs: LookupInSpec[], options?: LookupInOptions, callback?: NodeCallback<LookupInReplicaResult[]>): Promise<LookupInReplicaResult[]>;
622 /**
623 * Performs a mutate-in operation against a document. Allowing atomic modification of
624 * specific fields within a document. Also enables access to document extended-attributes.
625 *
626 * @param key The document key to mutate.
627 * @param specs A list of specs describing the operations to perform on the document.
628 * @param options Optional parameters for this operation.
629 * @param callback A node-style callback to be invoked after execution.
630 */
631 mutateIn(key: string, specs: MutateInSpec[], options?: MutateInOptions, callback?: NodeCallback<MutateInResult>): Promise<MutateInResult>;
632 /**
633 * Returns a CouchbaseList permitting simple list storage in a document.
634 *
635 * @param key The document key the data-structure resides in.
636 */
637 list(key: string): CouchbaseList;
638 /**
639 * Returns a CouchbaseQueue permitting simple queue storage in a document.
640 *
641 * @param key The document key the data-structure resides in.
642 */
643 queue(key: string): CouchbaseQueue;
644 /**
645 * Returns a CouchbaseMap permitting simple map storage in a document.
646 *
647 * @param key The document key the data-structure resides in.
648 */
649 map(key: string): CouchbaseMap;
650 /**
651 * Returns a CouchbaseSet permitting simple set storage in a document.
652 *
653 * @param key The document key the data-structure resides in.
654 */
655 set(key: string): CouchbaseSet;
656 /**
657 * Returns a BinaryCollection object reference, allowing access to various
658 * binary operations possible against a collection.
659 */
660 binary(): BinaryCollection;
661 /**
662 * @internal
663 */
664 _binaryIncrement(key: string, delta: number, options?: IncrementOptions, callback?: NodeCallback<CounterResult>): Promise<CounterResult>;
665 /**
666 * @internal
667 */
668 _binaryDecrement(key: string, delta: number, options?: DecrementOptions, callback?: NodeCallback<CounterResult>): Promise<CounterResult>;
669 /**
670 * @internal
671 */
672 _binaryAppend(key: string, value: string | Buffer, options?: AppendOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
673 /**
674 * @internal
675 */
676 _binaryPrepend(key: string, value: string | Buffer, options?: PrependOptions, callback?: NodeCallback<MutationResult>): Promise<MutationResult>;
677 /**
678 * Returns a CollectionQueryIndexManager which can be used to manage the query indexes
679 * of this collection.
680 */
681 queryIndexes(): CollectionQueryIndexManager;
682}