84 kBTypeScriptView Raw
1/// <reference types="node" resolution-mode="require"/>
2/**
3 * ```ts
4 * import type {
5 * DocumentCollection,
6 * EdgeCollection,
7 * } from "arangojs/collection.js";
8 * ```
9 *
10 * The "collection" module provides collection related types and interfaces
11 * for TypeScript.
12 *
13 * @packageDocumentation
14 */
15import { AqlLiteral, AqlQuery } from "./aql.js";
16import { ArangoApiResponse } from "./connection.js";
17import { Database } from "./database.js";
18import { Document, DocumentData, DocumentMetadata, DocumentSelector, Edge, EdgeData, ObjectWithKey, Patch } from "./documents.js";
19import { EnsureGeoIndexOptions, EnsureInvertedIndexOptions, EnsurePersistentIndexOptions, EnsureTtlIndexOptions, EnsureMdiIndexOptions, GeoIndex, Index, IndexSelector, InvertedIndex, PersistentIndex, TtlIndex, MdiIndex, EnsureIndexOptions } from "./indexes.js";
20/**
21 * Indicates whether the given value represents an {@link ArangoCollection}.
22 *
23 * @param collection - A value that might be a collection.
24 */
25export declare function isArangoCollection(collection: any): collection is ArangoCollection;
26/**
27 * Coerces the given collection name or {@link ArangoCollection} object to
28 * a string representing the collection name.
29 *
30 * @param collection - Collection name or {@link ArangoCollection} object.
31 */
32export declare function collectionToString(collection: string | ArangoCollection): string;
33/**
34 * A marker interface identifying objects that can be used in AQL template
35 * strings to create references to ArangoDB collections.
36 *
37 * See {@link aql!aql}.
38 */
39export interface ArangoCollection {
40 /**
41 * @internal
42 *
43 * Indicates that this object represents an ArangoDB collection.
44 */
45 readonly isArangoCollection: true;
46 /**
47 * Name of the collection.
48 */
49 readonly name: string;
50}
51/**
52 * Integer values indicating the collection type.
53 */
54export declare enum CollectionType {
55 DOCUMENT_COLLECTION = 2,
56 EDGE_COLLECTION = 3
57}
58/**
59 * Integer values indicating the collection loading status.
60 */
61export declare enum CollectionStatus {
62 NEWBORN = 1,
63 UNLOADED = 2,
64 LOADED = 3,
65 UNLOADING = 4,
66 DELETED = 5,
67 LOADING = 6
68}
69/**
70 * Type of key generator.
71 */
72export type KeyGenerator = "traditional" | "autoincrement" | "uuid" | "padded";
73/**
74 * Strategy for sharding a collection.
75 */
76export type ShardingStrategy = "hash" | "enterprise-hash-smart-edge" | "enterprise-hash-smart-vertex" | "community-compat" | "enterprise-compat" | "enterprise-smart-edge-compat";
77/**
78 * When a validation should be applied.
79 *
80 * * `"none"`: No validation.
81 * * `"new"`: Newly inserted documents are validated.
82 * * `"moderate"`: New and modified documents are validated unless the modified
83 * document was already invalid.
84 * * `"strict"`: New and modified documents are always validated.
85 */
86export type ValidationLevel = "none" | "new" | "moderate" | "strict";
87/**
88 * Write operation that can result in a computed value being computed.
89 */
90export type WriteOperation = "insert" | "update" | "replace";
91/**
92 * Represents a bulk operation failure for an individual document.
93 */
94export type DocumentOperationFailure = {
95 /**
96 * Indicates that the operation failed.
97 */
98 error: true;
99 /**
100 * Human-readable description of the failure.
101 */
102 errorMessage: string;
103 /**
104 * Numeric representation of the failure.
105 */
106 errorNum: number;
107};
108/**
109 * Metadata returned by a document operation.
110 */
111export type DocumentOperationMetadata = DocumentMetadata & {
112 /**
113 * Revision of the document that was updated or replaced by this operation.
114 */
115 _oldRev?: string;
116};
117/**
118 * Properties defining a computed value.
119 */
120export type ComputedValueProperties = {
121 /**
122 * Name of the target attribute of the computed value.
123 */
124 name: string;
125 /**
126 * AQL `RETURN` expression that computes the value.
127 */
128 expression: string;
129 /**
130 * If set to `false`, the computed value will not be applied if the
131 * expression evaluates to `null`.
132 */
133 overwrite: boolean;
134 /**
135 * Which operations should result in the value being computed.
136 */
137 computeOn: WriteOperation[];
138 /**
139 * If set to `false`, the field will be unset if the expression evaluates to
140 * `null`. Otherwise the field will be set to the value `null`. Has no effect
141 * if `overwrite` is set to `false`.
142 */
143 keepNull: boolean;
144 /**
145 * Whether the write operation should fail if the expression produces a
146 * warning.
147 */
148 failOnWarning: boolean;
149};
150/**
151 * General information about a collection.
152 */
153export type CollectionMetadata = {
154 /**
155 * Collection name.
156 */
157 name: string;
158 /**
159 * A globally unique identifier for this collection.
160 */
161 globallyUniqueId: string;
162 /**
163 * An integer indicating the collection loading status.
164 */
165 status: CollectionStatus;
166 /**
167 * An integer indicating the collection type.
168 */
169 type: CollectionType;
170 /**
171 * @internal
172 *
173 * Whether the collection is a system collection.
174 */
175 isSystem: boolean;
176};
177/**
178 * An object defining the collection's key generation.
179 */
180export type CollectionKeyProperties = {
181 /**
182 * Type of key generator to use.
183 */
184 type: KeyGenerator;
185 /**
186 * Whether documents can be created with a user-specified `_key` attribute.
187 */
188 allowUserKeys: boolean;
189 /**
190 * (Autoincrement only.) How many steps to increment the key each time.
191 */
192 increment?: number;
193 /**
194 * (Autoincrement only.) Initial offset for the key.
195 */
196 offset?: number;
197 /**
198 * Most recent key that has been generated.
199 */
200 lastValue: number;
201};
202/**
203 * Properties for validating documents in a collection.
204 */
205export type SchemaProperties = {
206 /**
207 * Type of document validation.
208 */
209 type: "json";
210 /**
211 * JSON Schema description of the validation schema for documents.
212 */
213 rule: any;
214 /**
215 * When validation should be applied.
216 */
217 level: ValidationLevel;
218 /**
219 * Message to be used if validation fails.
220 */
221 message: string;
222};
223/**
224 * An object defining the properties of a collection.
225 */
226export type CollectionProperties = {
227 /**
228 * A human-readable representation of the collection loading status.
229 */
230 statusString: string;
231 /**
232 * Whether data should be synchronized to disk before returning from
233 * a document create, update, replace or removal operation.
234 */
235 waitForSync: boolean;
236 /**
237 * An object defining the collection's key generation.
238 */
239 keyOptions: CollectionKeyProperties;
240 /**
241 * Properties for validating documents in the collection.
242 */
243 schema: SchemaProperties | null;
244 /**
245 * (Cluster only.) Write concern for this collection.
246 */
247 writeConcern: number;
248 /**
249 * (Cluster only.) Number of shards of this collection.
250 */
251 numberOfShards?: number;
252 /**
253 * (Cluster only.) Keys of this collection that will be used for
254 * sharding.
255 */
256 shardKeys?: string[];
257 /**
258 * (Cluster only.) Replication factor of the collection.
259 */
260 replicationFactor?: number | "satellite";
261 /**
262 * (Cluster only.) Sharding strategy of the collection.
263 */
264 shardingStrategy?: ShardingStrategy;
265 /**
266 * (Enterprise Edition cluster only.) If set to a collection name, sharding
267 * of the new collection will follow the rules for that collection. As long
268 * as the new collection exists, the indicated collection can not be dropped.
269 */
270 distributeShardsLike?: string;
271 /**
272 * (Enterprise Edition cluster only.) Attribute containing the shard key
273 * value of the referred-to smart join collection.
274 */
275 smartJoinAttribute?: string;
276 /**
277 * (Enterprise Edition cluster only.) Attribute used for sharding.
278 */
279 smartGraphAttribute?: string;
280 /**
281 * Computed values applied to documents in this collection.
282 */
283 computedValues: ComputedValueProperties[];
284 /**
285 * Whether the in-memory hash cache is enabled for this collection.
286 */
287 cacheEnabled: boolean;
288 /**
289 * Whether the newer revision-based replication protocol is enabled for
290 * this collection.
291 */
292 syncByRevision: boolean;
293 /**
294 * (Enterprise Edition only.) Whether the collection is used in a SmartGraph or EnterpriseGraph.
295 */
296 isSmart?: boolean;
297 /**
298 * (Enterprise Edition only.) Whether the SmartGraph this collection belongs to is disjoint.
299 */
300 isDisjoint?: string;
301};
302/**
303 * Options for creating a computed value.
304 */
305export type ComputedValueOptions = {
306 /**
307 * Name of the target attribute of the computed value.
308 */
309 name: string;
310 /**
311 * AQL `RETURN` expression that computes the value.
312 *
313 * Note that when passing an AQL query object, the `bindVars` will be ignored.
314 */
315 expression: string | AqlLiteral | AqlQuery;
316 /**
317 * If set to `false`, the computed value will not be applied if the
318 * expression evaluates to `null`.
319 *
320 * Default: `true`
321 */
322 overwrite?: boolean;
323 /**
324 * Which operations should result in the value being computed.
325 *
326 * Default: `["insert", "update", "replace"]`
327 */
328 computeOn?: WriteOperation[];
329 /**
330 * If set to `false`, the field will be unset if the expression evaluates to
331 * `null`. Otherwise the field will be set to the value `null`. Has no effect
332 * if `overwrite` is set to `false`.
333 *
334 * Default: `true`
335 */
336 keepNull?: boolean;
337 /**
338 * Whether the write operation should fail if the expression produces a
339 * warning.
340 *
341 * Default: `false`
342 */
343 failOnWarning?: boolean;
344};
345/**
346 * Options for validating collection documents.
347 */
348export type SchemaOptions = {
349 /**
350 * JSON Schema description of the validation schema for documents.
351 */
352 rule: any;
353 /**
354 * When validation should be applied.
355 *
356 * Default: `"strict"`
357 */
358 level?: ValidationLevel;
359 /**
360 * Message to be used if validation fails.
361 */
362 message?: string;
363};
364/**
365 * Options for setting a collection's properties.
366 *
367 * See {@link DocumentCollection#properties} and {@link EdgeCollection#properties}.
368 */
369export type CollectionPropertiesOptions = {
370 /**
371 * Whether data should be synchronized to disk before returning from
372 * a document create, update, replace or removal operation.
373 */
374 waitForSync?: boolean;
375 /**
376 * (Cluster only.) How many copies of each document should be kept in the
377 * cluster.
378 *
379 * Default: `1`
380 */
381 replicationFactor?: number | "satellite";
382 /**
383 * (Cluster only.) Write concern for this collection.
384 */
385 writeConcern?: number;
386 /**
387 * Options for validating documents in this collection.
388 */
389 schema?: SchemaOptions;
390 /**
391 * Computed values to apply to documents in this collection.
392 */
393 computedValues?: ComputedValueOptions[];
394 /**
395 * Whether the in-memory hash cache is enabled for this collection.
396 *
397 * Default: `false`
398 */
399 cacheEnabled?: boolean;
400};
401/**
402 * Options for retrieving a collection checksum.
403 */
404export type CollectionChecksumOptions = {
405 /**
406 * If set to `true`, revision IDs will be included in the calculation
407 * of the checksum.
408 *
409 * Default: `false`
410 */
411 withRevisions?: boolean;
412 /**
413 * If set to `true`, document data will be included in the calculation
414 * of the checksum.
415 *
416 * Default: `false`
417 */
418 withData?: boolean;
419};
420/**
421 * Options for dropping collections.
422 */
423export type CollectionDropOptions = {
424 /**
425 * Whether the collection is a system collection. If the collection is a
426 * system collection, this option must be set to `true` or ArangoDB will
427 * refuse to drop the collection.
428 *
429 * Default: `false`
430 */
431 isSystem?: boolean;
432};
433/**
434 * An object defining the collection's key generation.
435 */
436export type CollectionKeyOptions = {
437 /**
438 * Type of key generator to use.
439 */
440 type?: KeyGenerator;
441 /**
442 * Unless set to `false`, documents can be created with a user-specified
443 * `_key` attribute.
444 *
445 * Default: `true`
446 */
447 allowUserKeys?: boolean;
448 /**
449 * (Autoincrement only.) How many steps to increment the key each time.
450 */
451 increment?: number;
452 /**
453 * (Autoincrement only.) Initial offset for the key.
454 */
455 offset?: number;
456};
457/**
458 * Options for creating a collection.
459 *
460 * See {@link database.Database#createCollection}, {@link database.Database#createEdgeCollection}
461 * and {@link DocumentCollection#create} or {@link EdgeCollection#create}.
462 */
463export type CreateCollectionOptions = {
464 /**
465 * If set to `true`, data will be synchronized to disk before returning from
466 * a document create, update, replace or removal operation.
467 *
468 * Default: `false`
469 */
470 waitForSync?: boolean;
471 /**
472 * @internal
473 *
474 * Whether the collection should be created as a system collection.
475 *
476 * Default: `false`
477 */
478 isSystem?: boolean;
479 /**
480 * An object defining the collection's key generation.
481 */
482 keyOptions?: CollectionKeyOptions;
483 /**
484 * Options for validating documents in the collection.
485 */
486 schema?: SchemaOptions;
487 /**
488 * (Cluster only.) Unless set to `false`, the server will wait for all
489 * replicas to create the collection before returning.
490 *
491 * Default: `true`
492 */
493 waitForSyncReplication?: boolean;
494 /**
495 * (Cluster only.) Unless set to `false`, the server will check whether
496 * enough replicas are available at creation time and bail out otherwise.
497 *
498 * Default: `true`
499 */
500 enforceReplicationFactor?: boolean;
501 /**
502 * (Cluster only.) Number of shards to distribute the collection across.
503 *
504 * Default: `1`
505 */
506 numberOfShards?: number;
507 /**
508 * (Cluster only.) Document attributes to use to determine the target shard
509 * for each document.
510 *
511 * Default: `["_key"]`
512 */
513 shardKeys?: string[];
514 /**
515 * (Cluster only.) How many copies of each document should be kept in the
516 * cluster.
517 *
518 * Default: `1`
519 */
520 replicationFactor?: number;
521 /**
522 * (Cluster only.) Write concern for this collection.
523 */
524 writeConcern?: number;
525 /**
526 * (Cluster only.) Sharding strategy to use.
527 */
528 shardingStrategy?: ShardingStrategy;
529 /**
530 * (Enterprise Edition cluster only.) If set to a collection name, sharding
531 * of the new collection will follow the rules for that collection. As long
532 * as the new collection exists, the indicated collection can not be dropped.
533 */
534 distributeShardsLike?: string;
535 /**
536 * (Enterprise Edition cluster only.) Attribute containing the shard key
537 * value of the referred-to smart join collection.
538 */
539 smartJoinAttribute?: string;
540 /**
541 * (Enterprise Edition cluster only.) Attribute used for sharding.
542 */
543 smartGraphAttribute?: string;
544 /**
545 * Computed values to apply to documents in this collection.
546 */
547 computedValues?: ComputedValueOptions[];
548 /**
549 * Whether the in-memory hash cache is enabled for this collection.
550 */
551 cacheEnabled?: boolean;
552};
553/**
554 * Options for checking whether a document exists in a collection.
555 */
556export type DocumentExistsOptions = {
557 /**
558 * If set to a document revision, the document will only match if its `_rev`
559 * matches the given revision.
560 */
561 ifMatch?: string;
562 /**
563 * If set to a document revision, the document will only match if its `_rev`
564 * does not match the given revision.
565 */
566 ifNoneMatch?: string;
567};
568/**
569 * Options for retrieving a document from a collection.
570 */
571export type CollectionReadOptions = {
572 /**
573 * If set to `true`, `null` is returned instead of an exception being thrown
574 * if the document does not exist.
575 */
576 graceful?: boolean;
577 /**
578 * If set to `true`, the request will explicitly permit ArangoDB to return a
579 * potentially dirty or stale result and arangojs will load balance the
580 * request without distinguishing between leaders and followers.
581 */
582 allowDirtyRead?: boolean;
583 /**
584 * If set to a document revision, the request will fail with an error if the
585 * document exists but its `_rev` does not match the given revision.
586 */
587 ifMatch?: string;
588 /**
589 * If set to a document revision, the request will fail with an error if the
590 * document exists and its `_rev` matches the given revision. Note that an
591 * `HttpError` with code 304 will be thrown instead of an `ArangoError`.
592 */
593 ifNoneMatch?: string;
594};
595/**
596 * Options for retrieving multiple documents from a collection.
597 */
598export type CollectionBatchReadOptions = {
599 /**
600 * If set to `true`, the request will explicitly permit ArangoDB to return a
601 * potentially dirty or stale result and arangojs will load balance the
602 * request without distinguishing between leaders and followers.
603 */
604 allowDirtyRead?: boolean;
605};
606/**
607 * Options for inserting a new document into a collection.
608 */
609export type CollectionInsertOptions = {
610 /**
611 * If set to `true`, data will be synchronized to disk before returning.
612 *
613 * Default: `false`
614 */
615 waitForSync?: boolean;
616 /**
617 * If set to `true`, no data will be returned by the server. This option can
618 * be used to reduce network traffic.
619 *
620 * Default: `false`
621 */
622 silent?: boolean;
623 /**
624 * If set to `true`, the complete new document will be returned as the `new`
625 * property on the result object. Has no effect if `silent` is set to `true`.
626 *
627 * Default: `false`
628 */
629 returnNew?: boolean;
630 /**
631 * If set to `true`, the complete old document will be returned as the `old`
632 * property on the result object. Has no effect if `silent` is set to `true`.
633 * This option is only available when `overwriteMode` is set to `"update"` or
634 * `"replace"`.
635 *
636 * Default: `false`
637 */
638 returnOld?: boolean;
639 /**
640 * Defines what should happen if a document with the same `_key` or `_id`
641 * already exists, instead of throwing an exception.
642 *
643 * Default: `"conflict"
644 */
645 overwriteMode?: "ignore" | "update" | "replace" | "conflict";
646 /**
647 * If set to `false`, object properties that already exist in the old
648 * document will be overwritten rather than merged when an existing document
649 * with the same `_key` or `_id` is updated. This does not affect arrays.
650 *
651 * Default: `true`
652 */
653 mergeObjects?: boolean;
654 /**
655 * If set to `true`, new entries will be added to in-memory index caches if
656 * document insertions affect the edge index or cache-enabled persistent
657 * indexes.
658 *
659 * Default: `false`
660 */
661 refillIndexCaches?: boolean;
662 /**
663 * If set, the attribute with the name specified by the option is looked up
664 * in the stored document and the attribute value is compared numerically to
665 * the value of the versioning attribute in the supplied document that is
666 * supposed to update/replace it.
667 */
668 versionAttribute?: string;
669};
670/**
671 * Options for replacing an existing document in a collection.
672 */
673export type CollectionReplaceOptions = {
674 /**
675 * If set to `true`, data will be synchronized to disk before returning.
676 *
677 * Default: `false`
678 */
679 waitForSync?: boolean;
680 /**
681 * If set to `true`, no data will be returned by the server. This option can
682 * be used to reduce network traffic.
683 *
684 * Default: `false`
685 */
686 silent?: boolean;
687 /**
688 * If set to `true`, the complete new document will be returned as the `new`
689 * property on the result object. Has no effect if `silent` is set to `true`.
690 *
691 * Default: `false`
692 */
693 returnNew?: boolean;
694 /**
695 * If set to `false`, the existing document will only be modified if its
696 * `_rev` property matches the same property on the new data.
697 *
698 * Default: `true`
699 */
700 ignoreRevs?: boolean;
701 /**
702 * If set to `true`, the complete old document will be returned as the `old`
703 * property on the result object. Has no effect if `silent` is set to `true`.
704 *
705 * Default: `false`
706 */
707 returnOld?: boolean;
708 /**
709 * If set to a document revision, the document will only be replaced if its
710 * `_rev` matches the given revision.
711 */
712 ifMatch?: string;
713 /**
714 * If set to `true`, existing entries in in-memory index caches will be
715 * updated if document replacements affect the edge index or cache-enabled
716 * persistent indexes.
717 *
718 * Default: `false`
719 */
720 refillIndexCaches?: boolean;
721 /**
722 * If set, the attribute with the name specified by the option is looked up
723 * in the stored document and the attribute value is compared numerically to
724 * the value of the versioning attribute in the supplied document that is
725 * supposed to update/replace it.
726 */
727 versionAttribute?: string;
728};
729/**
730 * Options for updating a document in a collection.
731 */
732export type CollectionUpdateOptions = {
733 /**
734 * If set to `true`, data will be synchronized to disk before returning.
735 *
736 * Default: `false`
737 */
738 waitForSync?: boolean;
739 /**
740 * If set to `true`, no data will be returned by the server. This option can
741 * be used to reduce network traffic.
742 *
743 * Default: `false`
744 */
745 silent?: boolean;
746 /**
747 * If set to `true`, the complete new document will be returned as the `new`
748 * property on the result object. Has no effect if `silent` is set to `true`.
749 *
750 * Default: `false`
751 */
752 returnNew?: boolean;
753 /**
754 * If set to `false`, the existing document will only be modified if its
755 * `_rev` property matches the same property on the new data.
756 *
757 * Default: `true`
758 */
759 ignoreRevs?: boolean;
760 /**
761 * If set to `true`, the complete old document will be returned as the `old`
762 * property on the result object. Has no effect if `silent` is set to `true`.
763 *
764 * Default: `false`
765 */
766 returnOld?: boolean;
767 /**
768 * If set to `false`, properties with a value of `null` will be removed from
769 * the new document.
770 *
771 * Default: `true`
772 */
773 keepNull?: boolean;
774 /**
775 * If set to `false`, object properties that already exist in the old
776 * document will be overwritten rather than merged. This does not affect
777 * arrays.
778 *
779 * Default: `true`
780 */
781 mergeObjects?: boolean;
782 /**
783 * If set to a document revision, the document will only be updated if its
784 * `_rev` matches the given revision.
785 */
786 ifMatch?: string;
787 /**
788 * If set to `true`, existing entries in in-memory index caches will be
789 * updated if document updates affect the edge index or cache-enabled
790 * persistent indexes.
791 *
792 * Default: `false`
793 */
794 refillIndexCaches?: boolean;
795 /**
796 * If set, the attribute with the name specified by the option is looked up
797 * in the stored document and the attribute value is compared numerically to
798 * the value of the versioning attribute in the supplied document that is
799 * supposed to update/replace it.
800 */
801 versionAttribute?: string;
802};
803/**
804 * Options for removing a document from a collection.
805 */
806export type CollectionRemoveOptions = {
807 /**
808 * If set to `true`, changes will be synchronized to disk before returning.
809 *
810 * Default: `false`
811 */
812 waitForSync?: boolean;
813 /**
814 * If set to `true`, the complete old document will be returned as the `old`
815 * property on the result object. Has no effect if `silent` is set to `true`.
816 *
817 * Default: `false`
818 */
819 returnOld?: boolean;
820 /**
821 * If set to `true`, no data will be returned by the server. This option can
822 * be used to reduce network traffic.
823 *
824 * Default: `false`
825 */
826 silent?: boolean;
827 /**
828 * If set to a document revision, the document will only be removed if its
829 * `_rev` matches the given revision.
830 */
831 ifMatch?: string;
832 /**
833 * If set to `true`, existing entries in in-memory index caches will be
834 * deleted if document removals affect the edge index or cache-enabled
835 * persistent indexes.
836 *
837 * Default: `false`
838 */
839 refillIndexCaches?: boolean;
840};
841/**
842 * Options for bulk importing documents into a collection.
843 */
844export type CollectionImportOptions = {
845 /**
846 * (Edge collections only.) Prefix to prepend to `_from` attribute values.
847 */
848 fromPrefix?: string;
849 /**
850 * (Edge collections only.) Prefix to prepend to `_to` attribute values.
851 */
852 toPrefix?: string;
853 /**
854 * If set to `true`, the collection is truncated before the data is imported.
855 *
856 * Default: `false`
857 */
858 overwrite?: boolean;
859 /**
860 * Whether to wait for the documents to have been synced to disk.
861 */
862 waitForSync?: boolean;
863 /**
864 * Controls behavior when a unique constraint is violated on the document key.
865 *
866 * * `"error"`: the document will not be imported.
867 * * `"update`: the document will be merged into the existing document.
868 * * `"replace"`: the document will replace the existing document.
869 * * `"ignore"`: the document will not be imported and the unique constraint
870 * error will be ignored.
871 *
872 * Default: `"error"`
873 */
874 onDuplicate?: "error" | "update" | "replace" | "ignore";
875 /**
876 * If set to `true`, the import will abort if any error occurs.
877 */
878 complete?: boolean;
879 /**
880 * Whether the response should contain additional details about documents
881 * that could not be imported.
882 */
883 details?: boolean;
884};
885/**
886 * Options for retrieving a document's edges from a collection.
887 */
888export type CollectionEdgesOptions = {
889 /**
890 * If set to `true`, the request will explicitly permit ArangoDB to return a
891 * potentially dirty or stale result and arangojs will load balance the
892 * request without distinguishing between leaders and followers.
893 */
894 allowDirtyRead?: boolean;
895};
896export type IndexListOptions = {
897 /**
898 * If set to `true`, includes additional information about each index.
899 *
900 * Default: `false`
901 */
902 withStats?: boolean;
903 /**
904 * If set to `true`, includes indexes that are not yet fully built but are
905 * in the building phase.
906 *
907 * Default: `false`.
908 */
909 withHidden?: boolean;
910};
911/**
912 * Result of a collection bulk import.
913 */
914export type CollectionImportResult = {
915 /**
916 * Whether the import failed.
917 */
918 error: false;
919 /**
920 * Number of new documents imported.
921 */
922 created: number;
923 /**
924 * Number of documents that failed with an error.
925 */
926 errors: number;
927 /**
928 * Number of empty documents.
929 */
930 empty: number;
931 /**
932 * Number of documents updated.
933 */
934 updated: number;
935 /**
936 * Number of documents that failed with an error that is ignored.
937 */
938 ignored: number;
939 /**
940 * Additional details about any errors encountered during the import.
941 */
942 details?: string[];
943};
944/**
945 * Result of retrieving edges in a collection.
946 */
947export type CollectionEdgesResult<T extends Record<string, any> = any> = {
948 edges: Edge<T>[];
949 stats: {
950 scannedIndex: number;
951 filtered: number;
952 };
953};
954/**
955 * Represents an document collection in a {@link database.Database}.
956 *
957 * See {@link EdgeCollection} for a variant of this interface more suited for
958 * edge collections.
959 *
960 * When using TypeScript, collections can be cast to a specific document data
961 * type to increase type safety.
962 *
963 * @param T - Type to use for document data. Defaults to `any`.
964 *
965 * @example
966 * ```ts
967 * interface Person {
968 * name: string;
969 * }
970 * const db = new Database();
971 * const documents = db.collection("persons") as DocumentCollection<Person>;
972 * ```
973 */
974export interface DocumentCollection<EntryResultType extends Record<string, any> = any, EntryInputType extends Record<string, any> = EntryResultType> extends ArangoCollection {
975 /**
976 * Checks whether the collection exists.
977 *
978 * @example
979 * ```js
980 * const db = new Database();
981 * const collection = db.collection("some-collection");
982 * const result = await collection.exists();
983 * // result indicates whether the collection exists
984 * ```
985 */
986 exists(): Promise<boolean>;
987 /**
988 * Retrieves general information about the collection.
989 *
990 * @example
991 * ```js
992 * const db = new Database();
993 * const collection = db.collection("some-collection");
994 * const data = await collection.get();
995 * // data contains general information about the collection
996 * ```
997 */
998 get(): Promise<ArangoApiResponse<CollectionMetadata>>;
999 /**
1000 * Creates a collection with the given `options` and the instance's name.
1001 *
1002 * See also {@link database.Database#createCollection} and
1003 * {@link database.Database#createEdgeCollection}.
1004 *
1005 * **Note**: When called on an {@link EdgeCollection} instance in TypeScript,
1006 * the `type` option must still be set to the correct {@link CollectionType}.
1007 * Otherwise this will result in the collection being created with the
1008 * default type (i.e. as a document collection).
1009 *
1010 * @param options - Options for creating the collection.
1011 *
1012 * @example
1013 * ```js
1014 * const db = new Database();
1015 * const collection = db.collection("potatoes");
1016 * await collection.create();
1017 * // the document collection "potatoes" now exists
1018 * ```
1019 *
1020 * @example
1021 * ```js
1022 * const db = new Database();
1023 * const collection = db.collection("friends");
1024 * await collection.create({ type: CollectionType.EDGE_COLLECTION });
1025 * // the edge collection "friends" now exists
1026 * ```
1027 *
1028 * @example
1029 * ```ts
1030 * interface Friend {
1031 * startDate: number;
1032 * endDate?: number;
1033 * }
1034 * const db = new Database();
1035 * const collection = db.collection("friends") as EdgeCollection<Friend>;
1036 * // even in TypeScript you still need to indicate the collection type
1037 * // if you want to create an edge collection
1038 * await collection.create({ type: CollectionType.EDGE_COLLECTION });
1039 * // the edge collection "friends" now exists
1040 * ```
1041 */
1042 create(options?: CreateCollectionOptions & {
1043 type?: CollectionType;
1044 }): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties>>;
1045 /**
1046 * Retrieves the collection's properties.
1047 *
1048 * @example
1049 * ```js
1050 * const db = new Database();
1051 * const collection = db.collection("some-collection");
1052 * const data = await collection.properties();
1053 * // data contains the collection's properties
1054 * ```
1055 */
1056 properties(): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties>>;
1057 /**
1058 * Replaces the properties of the collection.
1059 *
1060 * @example
1061 * ```js
1062 * const db = new Database();
1063 * const collection = db.collection("some-collection");
1064 * const result = await collection.setProperties({ waitForSync: true });
1065 * // the collection will now wait for data being written to disk
1066 * // whenever a document is changed
1067 * ```
1068 */
1069 properties(properties: CollectionPropertiesOptions): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties>>;
1070 /**
1071 * Retrieves information about the number of documents in a collection.
1072 *
1073 * @example
1074 * ```js
1075 * const db = new Database();
1076 * const collection = db.collection("some-collection");
1077 * const data = await collection.count();
1078 * // data contains the collection's count
1079 * ```
1080 */
1081 count(): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties & {
1082 count: number;
1083 }>>;
1084 /**
1085 * Instructs ArangoDB to recalculate the collection's document count to fix
1086 * any inconsistencies.
1087 *
1088 * @example
1089 * ```js
1090 * const db = new Database();
1091 * const collection = db.collection("inconsistent-collection");
1092 * const badData = await collection.count();
1093 * // oh no, the collection count looks wrong -- fix it!
1094 * await collection.recalculateCount();
1095 * const goodData = await collection.count();
1096 * // goodData contains the collection's improved count
1097 * ```
1098 */
1099 recalculateCount(): Promise<boolean>;
1100 /**
1101 * Retrieves statistics for a collection.
1102 *
1103 * @param details - whether to return extended storage engine-specific details
1104 * to the figures, which may cause additional load and impact performance
1105 *
1106 * @example
1107 * ```js
1108 * const db = new Database();
1109 * const collection = db.collection("some-collection");
1110 * const data = await collection.figures();
1111 * // data contains the collection's figures
1112 * ```
1113 */
1114 figures(details?: boolean): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties & {
1115 count: number;
1116 figures: Record<string, any>;
1117 }>>;
1118 /**
1119 * Retrieves the collection revision ID.
1120 *
1121 * @example
1122 * ```js
1123 * const db = new Database();
1124 * const collection = db.collection("some-collection");
1125 * const data = await collection.revision();
1126 * // data contains the collection's revision
1127 * ```
1128 */
1129 revision(): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties & {
1130 revision: string;
1131 }>>;
1132 /**
1133 * Retrieves the collection checksum.
1134 *
1135 * @param options - Options for retrieving the checksum.
1136 *
1137 * @example
1138 * ```js
1139 * const db = new Database();
1140 * const collection = db.collection("some-collection");
1141 * const data = await collection.checksum();
1142 * // data contains the collection's checksum
1143 * ```
1144 */
1145 checksum(options?: CollectionChecksumOptions): Promise<ArangoApiResponse<CollectionMetadata & {
1146 revision: string;
1147 checksum: string;
1148 }>>;
1149 /**
1150 * Instructs ArangoDB to load as many indexes of the collection into memory
1151 * as permitted by the memory limit.
1152 *
1153 * @example
1154 * ```js
1155 * const db = new Database();
1156 * const collection = db.collection("indexed-collection");
1157 * await collection.loadIndexes();
1158 * // the indexes are now loaded into memory
1159 * ```
1160 */
1161 loadIndexes(): Promise<boolean>;
1162 /**
1163 * Renames the collection and updates the instance's `name` to `newName`.
1164 *
1165 * Additionally removes the instance from the {@link database.Database}'s internal
1166 * cache.
1167 *
1168 * **Note**: Renaming collections may not be supported when ArangoDB is
1169 * running in a cluster configuration.
1170 *
1171 * @param newName - The new name of the collection.
1172 *
1173 * @example
1174 * ```js
1175 * const db = new Database();
1176 * const collection1 = db.collection("some-collection");
1177 * await collection1.rename("other-collection");
1178 * const collection2 = db.collection("some-collection");
1179 * const collection3 = db.collection("other-collection");
1180 * // Note all three collection instances are different objects but
1181 * // collection1 and collection3 represent the same ArangoDB collection!
1182 * ```
1183 */
1184 rename(newName: string): Promise<ArangoApiResponse<CollectionMetadata>>;
1185 /**
1186 * Deletes all documents in the collection.
1187 *
1188 * @example
1189 * ```js
1190 * const db = new Database();
1191 * const collection = db.collection("some-collection");
1192 * await collection.truncate();
1193 * // millions of documents cry out in terror and are suddenly silenced,
1194 * // the collection "some-collection" is now empty
1195 * ```
1196 */
1197 truncate(): Promise<ArangoApiResponse<CollectionMetadata>>;
1198 /**
1199 * Deletes the collection from the database.
1200 *
1201 * @param options - Options for dropping the collection.
1202 *
1203 * @example
1204 * ```js
1205 * const db = new Database();
1206 * const collection = db.collection("some-collection");
1207 * await collection.drop();
1208 * // The collection "some-collection" is now an ex-collection
1209 * ```
1210 */
1211 drop(options?: CollectionDropOptions): Promise<ArangoApiResponse<Record<string, never>>>;
1212 /**
1213 * Retrieves the `shardId` of the shard responsible for the given document.
1214 *
1215 * @param document - Document in the collection to look up the `shardId` of.
1216 *
1217 * @example
1218 * ```js
1219 * const db = new Database();
1220 * const collection = db.collection("some-collection");
1221 * const responsibleShard = await collection.getResponsibleShard();
1222 * ```
1223 */
1224 getResponsibleShard(document: Partial<Document<EntryResultType>>): Promise<string>;
1225 /**
1226 * Derives a document `_id` from the given selector for this collection.
1227 *
1228 * Throws an exception when passed a document or `_id` from a different
1229 * collection.
1230 *
1231 * @param selector - Document `_key`, `_id` or object with either of those
1232 * properties (e.g. a document from this collection).
1233 *
1234 * @example
1235 * ```js
1236 * const db = new Database();
1237 * const collection = db.collection("some-collection");
1238 * const meta = await collection.save({ foo: "bar" }, { returnNew: true });
1239 * const doc = meta.new;
1240 * console.log(collection.documentId(meta)); // via meta._id
1241 * console.log(collection.documentId(doc)); // via doc._id
1242 * console.log(collection.documentId(meta._key)); // also works
1243 * ```
1244 *
1245 * @example
1246 * ```js
1247 * const db = new Database();
1248 * const collection1 = db.collection("some-collection");
1249 * const collection2 = db.collection("other-collection");
1250 * const meta = await collection1.save({ foo: "bar" });
1251 * // Mixing collections is usually a mistake
1252 * console.log(collection1.documentId(meta)); // ok: same collection
1253 * console.log(collection2.documentId(meta)); // throws: wrong collection
1254 * console.log(collection2.documentId(meta._id)); // also throws
1255 * console.log(collection2.documentId(meta._key)); // ok but wrong collection
1256 * ```
1257 */
1258 documentId(selector: DocumentSelector): string;
1259 /**
1260 * Checks whether a document matching the given key or id exists in this
1261 * collection.
1262 *
1263 * Throws an exception when passed a document or `_id` from a different
1264 * collection.
1265 *
1266 * @param selector - Document `_key`, `_id` or object with either of those
1267 * properties (e.g. a document from this collection).
1268 *
1269 * @example
1270 * ```js
1271 * const db = new Database();
1272 * const collection = db.collection("some-collection");
1273 * const exists = await collection.documentExists("abc123");
1274 * if (!exists) {
1275 * console.log("Document does not exist");
1276 * }
1277 * ```
1278 */
1279 documentExists(selector: DocumentSelector, options?: DocumentExistsOptions): Promise<boolean>;
1280 /**
1281 * Retrieves the document matching the given key or id.
1282 *
1283 * Throws an exception when passed a document or `_id` from a different
1284 * collection.
1285 *
1286 * @param selector - Document `_key`, `_id` or object with either of those
1287 * properties (e.g. a document from this collection).
1288 * @param options - Options for retrieving the document.
1289 *
1290 * @example
1291 * ```js
1292 * const db = new Database();
1293 * const collection = db.collection("some-collection");
1294 * try {
1295 * const document = await collection.document("abc123");
1296 * console.log(document);
1297 * } catch (e: any) {
1298 * console.error("Could not find document");
1299 * }
1300 * ```
1301 *
1302 * @example
1303 * ```js
1304 * const db = new Database();
1305 * const collection = db.collection("some-collection");
1306 * const document = await collection.document("abc123", { graceful: true });
1307 * if (document) {
1308 * console.log(document);
1309 * } else {
1310 * console.error("Could not find document");
1311 * }
1312 * ```
1313 */
1314 document(selector: DocumentSelector, options?: CollectionReadOptions): Promise<Document<EntryResultType>>;
1315 /**
1316 * Retrieves the document matching the given key or id.
1317 *
1318 * Throws an exception when passed a document or `_id` from a different
1319 * collection.
1320 *
1321 * @param selector - Document `_key`, `_id` or object with either of those
1322 * properties (e.g. a document from this collection).
1323 * @param graceful - If set to `true`, `null` is returned instead of an
1324 * exception being thrown if the document does not exist.
1325 *
1326 * @example
1327 * ```js
1328 * const db = new Database();
1329 * const collection = db.collection("some-collection");
1330 * try {
1331 * const document = await collection.document("abc123", false);
1332 * console.log(document);
1333 * } catch (e: any) {
1334 * console.error("Could not find document");
1335 * }
1336 * ```
1337 *
1338 * @example
1339 * ```js
1340 * const db = new Database();
1341 * const collection = db.collection("some-collection");
1342 * const document = await collection.document("abc123", true);
1343 * if (document) {
1344 * console.log(document);
1345 * } else {
1346 * console.error("Could not find document");
1347 * }
1348 * ```
1349 */
1350 document(selector: DocumentSelector, graceful: boolean): Promise<Document<EntryResultType>>;
1351 /**
1352 * Retrieves the documents matching the given key or id values.
1353 *
1354 * Throws an exception when passed a document or `_id` from a different
1355 * collection, or if the document does not exist.
1356 *
1357 * @param selectors - Array of document `_key`, `_id` or objects with either
1358 * of those properties (e.g. a document from this collection).
1359 * @param options - Options for retrieving the documents.
1360 *
1361 * @example
1362 * ```js
1363 * const db = new Database();
1364 * const collection = db.collection("some-collection");
1365 * try {
1366 * const documents = await collection.documents(["abc123", "xyz456"]);
1367 * console.log(documents);
1368 * } catch (e: any) {
1369 * console.error("Could not find document");
1370 * }
1371 * ```
1372 */
1373 documents(selectors: (string | ObjectWithKey)[], options?: CollectionBatchReadOptions): Promise<Document<EntryResultType>[]>;
1374 /**
1375 * Inserts a new document with the given `data` into the collection.
1376 *
1377 * @param data - The contents of the new document.
1378 * @param options - Options for inserting the document.
1379 *
1380 * @example
1381 * ```js
1382 * const db = new Database();
1383 * const collection = db.collection("some-collection");
1384 * const result = await collection.save(
1385 * { _key: "a", color: "blue", count: 1 },
1386 * { returnNew: true }
1387 * );
1388 * console.log(result.new.color, result.new.count); // "blue" 1
1389 * ```
1390 */
1391 save(data: DocumentData<EntryInputType>, options?: CollectionInsertOptions): Promise<DocumentOperationMetadata & {
1392 new?: Document<EntryResultType>;
1393 old?: Document<EntryResultType>;
1394 }>;
1395 /**
1396 * Inserts new documents with the given `data` into the collection.
1397 *
1398 * @param data - The contents of the new documents.
1399 * @param options - Options for inserting the documents.
1400 *
1401 * @example
1402 * ```js
1403 * const db = new Database();
1404 * const collection = db.collection("some-collection");
1405 * const result = await collection.saveAll(
1406 * [
1407 * { _key: "a", color: "blue", count: 1 },
1408 * { _key: "b", color: "red", count: 2 },
1409 * ],
1410 * { returnNew: true }
1411 * );
1412 * console.log(result[0].new.color, result[0].new.count); // "blue" 1
1413 * console.log(result[1].new.color, result[1].new.count); // "red" 2
1414 * ```
1415 */
1416 saveAll(data: Array<DocumentData<EntryInputType>>, options?: CollectionInsertOptions): Promise<Array<(DocumentOperationMetadata & {
1417 new?: Document<EntryResultType>;
1418 old?: Document<EntryResultType>;
1419 }) | DocumentOperationFailure>>;
1420 /**
1421 * Replaces an existing document in the collection.
1422 *
1423 * Throws an exception when passed a document or `_id` from a different
1424 * collection.
1425 *
1426 * @param selector - Document `_key`, `_id` or object with either of those
1427 * properties (e.g. a document from this collection).
1428 * @param newData - The contents of the new document.
1429 * @param options - Options for replacing the document.
1430 *
1431 * @example
1432 * ```js
1433 * const db = new Database();
1434 * const collection = db.collection("some-collection");
1435 * await collection.save({ _key: "a", color: "blue", count: 1 });
1436 * const result = await collection.replace(
1437 * "a",
1438 * { color: "red" },
1439 * { returnNew: true }
1440 * );
1441 * console.log(result.new.color, result.new.count); // "red" undefined
1442 * ```
1443 */
1444 replace(selector: DocumentSelector, newData: DocumentData<EntryInputType>, options?: CollectionReplaceOptions): Promise<DocumentOperationMetadata & {
1445 new?: Document<EntryResultType>;
1446 old?: Document<EntryResultType>;
1447 }>;
1448 /**
1449 * Replaces existing documents in the collection, identified by the `_key` or
1450 * `_id` of each document.
1451 *
1452 * @param newData - The documents to replace.
1453 * @param options - Options for replacing the documents.
1454 *
1455 * @example
1456 * ```js
1457 * const db = new Database();
1458 * const collection = db.collection("some-collection");
1459 * await collection.save({ _key: "a", color: "blue", count: 1 });
1460 * await collection.save({ _key: "b", color: "green", count: 3 });
1461 * const result = await collection.replaceAll(
1462 * [
1463 * { _key: "a", color: "red" },
1464 * { _key: "b", color: "yellow", count: 2 }
1465 * ],
1466 * { returnNew: true }
1467 * );
1468 * console.log(result[0].new.color, result[0].new.count); // "red" undefined
1469 * console.log(result[1].new.color, result[1].new.count); // "yellow" 2
1470 * ```
1471 */
1472 replaceAll(newData: Array<DocumentData<EntryInputType> & ({
1473 _key: string;
1474 } | {
1475 _id: string;
1476 })>, options?: Omit<CollectionReplaceOptions, "ifMatch">): Promise<Array<(DocumentOperationMetadata & {
1477 new?: Document<EntryResultType>;
1478 old?: Document<EntryResultType>;
1479 }) | DocumentOperationFailure>>;
1480 /**
1481 * Updates an existing document in the collection.
1482 *
1483 * Throws an exception when passed a document or `_id` from a different
1484 * collection.
1485 *
1486 * @param selector - Document `_key`, `_id` or object with either of those
1487 * properties (e.g. a document from this collection).
1488 * @param newData - The data for updating the document.
1489 * @param options - Options for updating the document.
1490 *
1491 * @example
1492 * ```js
1493 * const db = new Database();
1494 * const collection = db.collection("some-collection");
1495 * await collection.save({ _key: "a", color: "blue", count: 1 });
1496 * const result = await collection.update(
1497 * "a",
1498 * { count: 2 },
1499 * { returnNew: true }
1500 * );
1501 * console.log(result.new.color, result.new.count); // "blue" 2
1502 * ```
1503 */
1504 update(selector: DocumentSelector, newData: Patch<DocumentData<EntryInputType>>, options?: CollectionUpdateOptions): Promise<DocumentOperationMetadata & {
1505 new?: Document<EntryResultType>;
1506 old?: Document<EntryResultType>;
1507 }>;
1508 /**
1509 * Updates existing documents in the collection, identified by the `_key` or
1510 * `_id` of each document.
1511 *
1512 * @param newData - The data for updating the documents.
1513 * @param options - Options for updating the documents.
1514 *
1515 * @example
1516 * ```js
1517 * const db = new Database();
1518 * const collection = db.collection("some-collection");
1519 * await collection.save({ _key: "a", color: "blue", count: 1 });
1520 * await collection.save({ _key: "b", color: "green", count: 3 });
1521 * const result = await collection.updateAll(
1522 * [
1523 * { _key: "a", count: 2 },
1524 * { _key: "b", count: 4 }
1525 * ],
1526 * { returnNew: true }
1527 * );
1528 * console.log(result[0].new.color, result[0].new.count); // "blue" 2
1529 * console.log(result[1].new.color, result[1].new.count); // "green" 4
1530 * ```
1531 */
1532 updateAll(newData: Array<Patch<DocumentData<EntryInputType>> & ({
1533 _key: string;
1534 } | {
1535 _id: string;
1536 })>, options?: Omit<CollectionUpdateOptions, "ifMatch">): Promise<Array<(DocumentOperationMetadata & {
1537 new?: Document<EntryResultType>;
1538 old?: Document<EntryResultType>;
1539 }) | DocumentOperationFailure>>;
1540 /**
1541 * Removes an existing document from the collection.
1542 *
1543 * Throws an exception when passed a document or `_id` from a different
1544 * collection.
1545 *
1546 * @param selector - Document `_key`, `_id` or object with either of those
1547 * properties (e.g. a document from this collection).
1548 * @param options - Options for removing the document.
1549 *
1550 * @example
1551 * ```js
1552 * const db = new Database();
1553 * const collection = db.collection("some-collection");
1554 * await collection.remove("abc123");
1555 * // document with key "abc123" deleted
1556 * ```
1557 *
1558 * @example
1559 * ```js
1560 * const db = new Database();
1561 * const collection = db.collection("some-collection");
1562 * const doc = await collection.document("abc123");
1563 * await collection.remove(doc);
1564 * // document with key "abc123" deleted
1565 * ```
1566 */
1567 remove(selector: DocumentSelector, options?: CollectionRemoveOptions): Promise<DocumentMetadata & {
1568 old?: Document<EntryResultType>;
1569 }>;
1570 /**
1571 * Removes existing documents from the collection.
1572 *
1573 * Throws an exception when passed any document or `_id` from a different
1574 * collection.
1575 *
1576 * @param selectors - Documents `_key`, `_id` or objects with either of those
1577 * properties (e.g. documents from this collection).
1578 * @param options - Options for removing the documents.
1579 *
1580 * @example
1581 * ```js
1582 * const db = new Database();
1583 * const collection = db.collection("some-collection");
1584 * await collection.removeAll(["abc123", "def456"]);
1585 * // document with keys "abc123" and "def456" deleted
1586 * ```
1587 */
1588 removeAll(selectors: (string | ObjectWithKey)[], options?: Omit<CollectionRemoveOptions, "ifMatch">): Promise<Array<(DocumentMetadata & {
1589 old?: Document<EntryResultType>;
1590 }) | DocumentOperationFailure>>;
1591 /**
1592 * Bulk imports the given `data` into the collection.
1593 *
1594 * @param data - The data to import, as an array of document data.
1595 * @param options - Options for importing the data.
1596 *
1597 * @example
1598 * ```js
1599 * const db = new Database();
1600 * const collection = db.collection("some-collection");
1601 * await collection.import(
1602 * [
1603 * { _key: "jcd", password: "bionicman" },
1604 * { _key: "jreyes", password: "amigo" },
1605 * { _key: "ghermann", password: "zeitgeist" }
1606 * ]
1607 * );
1608 * ```
1609 */
1610 import(data: DocumentData<EntryInputType>[], options?: CollectionImportOptions): Promise<CollectionImportResult>;
1611 /**
1612 * Bulk imports the given `data` into the collection.
1613 *
1614 * @param data - The data to import, as an array containing a single array of
1615 * attribute names followed by one or more arrays of attribute values for
1616 * each document.
1617 * @param options - Options for importing the data.
1618 *
1619 * @example
1620 * ```js
1621 * const db = new Database();
1622 * const collection = db.collection("some-collection");
1623 * await collection.import(
1624 * [
1625 * [ "_key", "password" ],
1626 * [ "jcd", "bionicman" ],
1627 * [ "jreyes", "amigo" ],
1628 * [ "ghermann", "zeitgeist" ]
1629 * ]
1630 * );
1631 * ```
1632 */
1633 import(data: any[][], options?: CollectionImportOptions): Promise<CollectionImportResult>;
1634 /**
1635 * Bulk imports the given `data` into the collection.
1636 *
1637 * If `type` is omitted, `data` must contain one JSON array per line with
1638 * the first array providing the attribute names and all other arrays
1639 * providing attribute values for each document.
1640 *
1641 * If `type` is set to `"documents"`, `data` must contain one JSON document
1642 * per line.
1643 *
1644 * If `type` is set to `"list"`, `data` must contain a JSON array of
1645 * documents.
1646 *
1647 * If `type` is set to `"auto"`, `data` can be in either of the formats
1648 * supported by `"documents"` or `"list"`.
1649 *
1650 * @param data - The data to import as a Buffer (Node), Blob (browser) or
1651 * string.
1652 * @param options - Options for importing the data.
1653 *
1654 * @example
1655 * ```js
1656 * const db = new Database();
1657 * const collection = db.collection("some-collection");
1658 * await collection.import(
1659 * '{"_key":"jcd","password":"bionicman"}\r\n' +
1660 * '{"_key":"jreyes","password":"amigo"}\r\n' +
1661 * '{"_key":"ghermann","password":"zeitgeist"}\r\n',
1662 * { type: "documents" } // or "auto"
1663 * );
1664 * ```
1665 *
1666 * @example
1667 * ```js
1668 * const db = new Database();
1669 * const collection = db.collection("some-collection");
1670 * await collection.import(
1671 * '[{"_key":"jcd","password":"bionicman"},' +
1672 * '{"_key":"jreyes","password":"amigo"},' +
1673 * '{"_key":"ghermann","password":"zeitgeist"}]',
1674 * { type: "list" } // or "auto"
1675 * );
1676 * ```
1677 *
1678 * @example
1679 * ```js
1680 * const db = new Database();
1681 * const collection = db.collection("some-collection");
1682 * await collection.import(
1683 * '["_key","password"]\r\n' +
1684 * '["jcd","bionicman"]\r\n' +
1685 * '["jreyes","amigo"]\r\n' +
1686 * '["ghermann","zeitgeist"]\r\n'
1687 * );
1688 * ```
1689 */
1690 import(data: Buffer | Blob | string, options?: CollectionImportOptions & {
1691 type?: "documents" | "list" | "auto";
1692 }): Promise<CollectionImportResult>;
1693 /**
1694 * Returns a list of all index descriptions for the collection.
1695 *
1696 * @param options - Options for fetching the index list.
1697 *
1698 * @example
1699 * ```js
1700 * const db = new Database();
1701 * const collection = db.collection("some-collection");
1702 * const indexes = await collection.indexes();
1703 * ```
1704 */
1705 indexes(options?: IndexListOptions): Promise<Index[]>;
1706 /**
1707 * Returns an index description by name or `id` if it exists.
1708 *
1709 * @param selector - Index name, id or object with either property.
1710 *
1711 * @example
1712 * ```js
1713 * const db = new Database();
1714 * const collection = db.collection("some-collection");
1715 * const index = await collection.index("some-index");
1716 * ```
1717 */
1718 index(selector: IndexSelector): Promise<Index>;
1719 /**
1720 * Creates a persistent index on the collection if it does not already exist.
1721 *
1722 * @param details - Options for creating the persistent index.
1723 *
1724 * @example
1725 * ```js
1726 * const db = new Database();
1727 * const collection = db.collection("some-collection");
1728 * // Create a unique index for looking up documents by username
1729 * await collection.ensureIndex({
1730 * type: "persistent",
1731 * fields: ["username"],
1732 * name: "unique-usernames",
1733 * unique: true
1734 * });
1735 * ```
1736 */
1737 ensureIndex(details: EnsurePersistentIndexOptions): Promise<ArangoApiResponse<PersistentIndex & {
1738 isNewlyCreated: boolean;
1739 }>>;
1740 /**
1741 * Creates a TTL index on the collection if it does not already exist.
1742 *
1743 * @param details - Options for creating the TTL index.
1744 *
1745 * @example
1746 * ```js
1747 * const db = new Database();
1748 * const collection = db.collection("some-collection");
1749 * // Expire documents with "createdAt" timestamp one day after creation
1750 * await collection.ensureIndex({
1751 * type: "ttl",
1752 * fields: ["createdAt"],
1753 * expireAfter: 60 * 60 * 24 // 24 hours
1754 * });
1755 * ```
1756 *
1757 * @example
1758 * ```js
1759 * const db = new Database();
1760 * const collection = db.collection("some-collection");
1761 * // Expire documents with "expiresAt" timestamp according to their value
1762 * await collection.ensureIndex({
1763 * type: "ttl",
1764 * fields: ["expiresAt"],
1765 * expireAfter: 0 // when attribute value is exceeded
1766 * });
1767 * ```
1768 */
1769 ensureIndex(details: EnsureTtlIndexOptions): Promise<ArangoApiResponse<TtlIndex & {
1770 isNewlyCreated: boolean;
1771 }>>;
1772 /**
1773 * Creates a multi-dimensional index on the collection if it does not already exist.
1774 *
1775 * @param details - Options for creating the multi-dimensional index.
1776 *
1777 * @example
1778 * ```js
1779 * const db = new Database();
1780 * const collection = db.collection("some-points");
1781 * // Create a multi-dimensional index for the attributes x, y and z
1782 * await collection.ensureIndex({
1783 * type: "mdi",
1784 * fields: ["x", "y", "z"],
1785 * fieldValueTypes: "double"
1786 * });
1787 * ```
1788 * ```
1789 */
1790 ensureIndex(details: EnsureMdiIndexOptions): Promise<ArangoApiResponse<MdiIndex & {
1791 isNewlyCreated: boolean;
1792 }>>;
1793 /**
1794 * Creates a geo index on the collection if it does not already exist.
1795 *
1796 * @param details - Options for creating the geo index.
1797 *
1798 * @example
1799 * ```js
1800 * const db = new Database();
1801 * const collection = db.collection("some-collection");
1802 * // Create an index for GeoJSON data
1803 * await collection.ensureIndex({
1804 * type: "geo",
1805 * fields: ["lngLat"],
1806 * geoJson: true
1807 * });
1808 * ```
1809 */
1810 ensureIndex(details: EnsureGeoIndexOptions): Promise<ArangoApiResponse<GeoIndex & {
1811 isNewlyCreated: boolean;
1812 }>>;
1813 /**
1814 * Creates a inverted index on the collection if it does not already exist.
1815 *
1816 * @param details - Options for creating the inverted index.
1817 *
1818 * @example
1819 * ```js
1820 * const db = new Database();
1821 * const collection = db.collection("some-collection");
1822 * // Create an inverted index
1823 * await collection.ensureIndex({
1824 * type: "inverted",
1825 * fields: ["a", { name: "b", analyzer: "text_en" }]
1826 * });
1827 * ```
1828 */
1829 ensureIndex(details: EnsureInvertedIndexOptions): Promise<ArangoApiResponse<InvertedIndex & {
1830 isNewlyCreated: boolean;
1831 }>>;
1832 /**
1833 * Creates an index on the collection if it does not already exist.
1834 *
1835 * @param details - Options for creating the index.
1836 *
1837 * @example
1838 * ```js
1839 * const db = new Database();
1840 * const collection = db.collection("some-collection");
1841 * // Create a unique index for looking up documents by username
1842 * await collection.ensureIndex({
1843 * type: "persistent",
1844 * fields: ["username"],
1845 * name: "unique-usernames",
1846 * unique: true
1847 * });
1848 * ```
1849 */
1850 ensureIndex(details: EnsureIndexOptions): Promise<ArangoApiResponse<Index & {
1851 isNewlyCreated: boolean;
1852 }>>;
1853 /**
1854 * Deletes the index with the given name or `id` from the database.
1855 *
1856 * @param selector - Index name, id or object with either property.
1857 *
1858 * @example
1859 * ```js
1860 * const db = new Database();
1861 * const collection = db.collection("some-collection");
1862 * await collection.dropIndex("some-index");
1863 * // The index "some-index" no longer exists
1864 * ```
1865 */
1866 dropIndex(selector: IndexSelector): Promise<ArangoApiResponse<{
1867 id: string;
1868 }>>;
1869 /**
1870 * Triggers compaction for a collection.
1871 *
1872 * @example
1873 * ```js
1874 * const db = new Database();
1875 * const collection = db.collection("some-collection");
1876 * await collection.compact();
1877 * // Background compaction is triggered on the collection
1878 * ```
1879 */
1880 compact(): Promise<ArangoApiResponse<Record<string, never>>>;
1881}
1882/**
1883 * Represents an edge collection in a {@link database.Database}.
1884 *
1885 * See {@link DocumentCollection} for a more generic variant of this interface
1886 * more suited for regular document collections.
1887 *
1888 * See also {@link graph.GraphEdgeCollection} for the type representing an edge
1889 * collection in a {@link graph.Graph}.
1890 *
1891 * When using TypeScript, collections can be cast to a specific edge document
1892 * data type to increase type safety.
1893 *
1894 * @param T - Type to use for edge document data. Defaults to `any`.
1895 *
1896 * @example
1897 * ```ts
1898 * interface Friend {
1899 * startDate: number;
1900 * endDate?: number;
1901 * }
1902 * const db = new Database();
1903 * const edges = db.collection("friends") as EdgeCollection<Friend>;
1904 * ```
1905 */
1906export interface EdgeCollection<EntryResultType extends Record<string, any> = any, EntryInputType extends Record<string, any> = EntryResultType> extends DocumentCollection<EntryResultType, EntryInputType> {
1907 /**
1908 * Retrieves the document matching the given key or id.
1909 *
1910 * Throws an exception when passed a document or `_id` from a different
1911 * collection, or if the document does not exist.
1912 *
1913 * @param selector - Document `_key`, `_id` or object with either of those
1914 * properties (e.g. a document from this collection).
1915 * @param options - Options for retrieving the document.
1916 *
1917 * @example
1918 * ```js
1919 * const db = new Database();
1920 * const collection = db.collection("some-collection");
1921 * try {
1922 * const document = await collection.document("abc123");
1923 * console.log(document);
1924 * } catch (e: any) {
1925 * console.error("Could not find document");
1926 * }
1927 * ```
1928 *
1929 * @example
1930 * ```js
1931 * const db = new Database();
1932 * const collection = db.collection("some-collection");
1933 * const document = await collection.document("abc123", { graceful: true });
1934 * if (document) {
1935 * console.log(document);
1936 * } else {
1937 * console.error("Document does not exist");
1938 * }
1939 * ```
1940 */
1941 document(selector: DocumentSelector, options?: CollectionReadOptions): Promise<Edge<EntryResultType>>;
1942 /**
1943 * Retrieves the document matching the given key or id.
1944 *
1945 * Throws an exception when passed a document or `_id` from a different
1946 * collection, or if the document does not exist.
1947 *
1948 * @param selector - Document `_key`, `_id` or object with either of those
1949 * properties (e.g. a document from this collection).
1950 * @param graceful - If set to `true`, `null` is returned instead of an
1951 * exception being thrown if the document does not exist.
1952 *
1953 * @example
1954 * ```js
1955 * const db = new Database();
1956 * const collection = db.collection("some-collection");
1957 * try {
1958 * const document = await collection.document("abc123", false);
1959 * console.log(document);
1960 * } catch (e: any) {
1961 * console.error("Could not find document");
1962 * }
1963 * ```
1964 *
1965 * @example
1966 * ```js
1967 * const db = new Database();
1968 * const collection = db.collection("some-collection");
1969 * const document = await collection.document("abc123", true);
1970 * if (document) {
1971 * console.log(document);
1972 * } else {
1973 * console.error("Document does not exist");
1974 * }
1975 * ```
1976 */
1977 document(selector: DocumentSelector, graceful: boolean): Promise<Edge<EntryResultType>>;
1978 /**
1979 * Retrieves the documents matching the given key or id values.
1980 *
1981 * Throws an exception when passed a document or `_id` from a different
1982 * collection, or if the document does not exist.
1983 *
1984 * @param selectors - Array of document `_key`, `_id` or objects with either
1985 * of those properties (e.g. a document from this collection).
1986 * @param options - Options for retrieving the documents.
1987 *
1988 * @example
1989 * ```js
1990 * const db = new Database();
1991 * const collection = db.collection("some-collection");
1992 * try {
1993 * const documents = await collection.documents(["abc123", "xyz456"]);
1994 * console.log(documents);
1995 * } catch (e: any) {
1996 * console.error("Could not find document");
1997 * }
1998 * ```
1999 */
2000 documents(selectors: (string | ObjectWithKey)[], options?: CollectionBatchReadOptions): Promise<Edge<EntryResultType>[]>;
2001 /**
2002 * Inserts a new document with the given `data` into the collection.
2003 *
2004 * @param data - The contents of the new document.
2005 * @param options - Options for inserting the document.
2006 *
2007 * @example
2008 * ```js
2009 * const db = new Database();
2010 * const collection = db.collection("friends");
2011 * const result = await collection.save(
2012 * { _from: "users/rana", _to: "users/mudasir", active: false },
2013 * { returnNew: true }
2014 * );
2015 * ```
2016 */
2017 save(data: EdgeData<EntryInputType>, options?: CollectionInsertOptions): Promise<DocumentOperationMetadata & {
2018 new?: Edge<EntryResultType>;
2019 old?: Edge<EntryResultType>;
2020 }>;
2021 /**
2022 * Inserts new documents with the given `data` into the collection.
2023 *
2024 * @param data - The contents of the new documents.
2025 * @param options - Options for inserting the documents.
2026 *
2027 * @example
2028 * ```js
2029 * const db = new Database();
2030 * const collection = db.collection("friends");
2031 * const result = await collection.saveAll(
2032 * [
2033 * { _from: "users/rana", _to: "users/mudasir", active: false },
2034 * { _from: "users/rana", _to: "users/salman", active: true }
2035 * ],
2036 * { returnNew: true }
2037 * );
2038 * ```
2039 */
2040 saveAll(data: Array<EdgeData<EntryInputType>>, options?: CollectionInsertOptions): Promise<Array<(DocumentOperationMetadata & {
2041 new?: Edge<EntryResultType>;
2042 old?: Edge<EntryResultType>;
2043 }) | DocumentOperationFailure>>;
2044 /**
2045 * Replaces an existing document in the collection.
2046 *
2047 * Throws an exception when passed a document or `_id` from a different
2048 * collection.
2049 *
2050 * @param selector - Document `_key`, `_id` or object with either of those
2051 * properties (e.g. a document from this collection).
2052 * @param newData - The contents of the new document.
2053 * @param options - Options for replacing the document.
2054 *
2055 * @example
2056 * ```js
2057 * const db = new Database();
2058 * const collection = db.collection("friends");
2059 * await collection.save(
2060 * {
2061 * _key: "musadir",
2062 * _from: "users/rana",
2063 * _to: "users/mudasir",
2064 * active: true,
2065 * best: true
2066 * }
2067 * );
2068 * const result = await collection.replace(
2069 * "musadir",
2070 * { active: false },
2071 * { returnNew: true }
2072 * );
2073 * console.log(result.new.active, result.new.best); // false undefined
2074 * ```
2075 */
2076 replace(selector: DocumentSelector, newData: DocumentData<EntryInputType>, options?: CollectionReplaceOptions): Promise<DocumentOperationMetadata & {
2077 new?: Edge<EntryResultType>;
2078 old?: Edge<EntryResultType>;
2079 }>;
2080 /**
2081 * Replaces existing documents in the collection, identified by the `_key` or
2082 * `_id` of each document.
2083 *
2084 * @param newData - The documents to replace.
2085 * @param options - Options for replacing the documents.
2086 *
2087 * @example
2088 * ```js
2089 * const db = new Database();
2090 * const collection = db.collection("friends");
2091 * await collection.save(
2092 * {
2093 * _key: "musadir",
2094 * _from: "users/rana",
2095 * _to: "users/mudasir",
2096 * active: true,
2097 * best: true
2098 * }
2099 * );
2100 * await collection.save(
2101 * {
2102 * _key: "salman",
2103 * _from: "users/rana",
2104 * _to: "users/salman",
2105 * active: false,
2106 * best: false
2107 * }
2108 * );
2109 * const result = await collection.replaceAll(
2110 * [
2111 * { _key: "musadir", active: false },
2112 * { _key: "salman", active: true, best: true }
2113 * ],
2114 * { returnNew: true }
2115 * );
2116 * console.log(result[0].new.active, result[0].new.best); // false undefined
2117 * console.log(result[1].new.active, result[1].new.best); // true true
2118 * ```
2119 */
2120 replaceAll(newData: Array<DocumentData<EntryInputType> & ({
2121 _key: string;
2122 } | {
2123 _id: string;
2124 })>, options?: CollectionReplaceOptions): Promise<Array<(DocumentOperationMetadata & {
2125 new?: Edge<EntryResultType>;
2126 old?: Edge<EntryResultType>;
2127 }) | DocumentOperationFailure>>;
2128 /**
2129 * Updates an existing document in the collection.
2130 *
2131 * Throws an exception when passed a document or `_id` from a different
2132 * collection.
2133 *
2134 * @param selector - Document `_key`, `_id` or object with either of those
2135 * properties (e.g. a document from this collection).
2136 * @param newData - The data for updating the document.
2137 * @param options - Options for updating the document.
2138 *
2139 * @example
2140 * ```js
2141 * const db = new Database();
2142 * const collection = db.collection("friends");
2143 * await collection.save(
2144 * {
2145 * _key: "musadir",
2146 * _from: "users/rana",
2147 * _to: "users/mudasir",
2148 * active: true,
2149 * best: true
2150 * }
2151 * );
2152 * const result = await collection.update(
2153 * "musadir",
2154 * { active: false },
2155 * { returnNew: true }
2156 * );
2157 * console.log(result.new.active, result.new.best); // false true
2158 * ```
2159 */
2160 update(selector: DocumentSelector, newData: Patch<DocumentData<EntryInputType>>, options?: CollectionUpdateOptions): Promise<DocumentOperationMetadata & {
2161 new?: Edge<EntryResultType>;
2162 old?: Edge<EntryResultType>;
2163 }>;
2164 /**
2165 * Updates existing documents in the collection, identified by the `_key` or
2166 * `_id` of each document.
2167 *
2168 * @param newData - The data for updating the documents.
2169 * @param options - Options for updating the documents.
2170 * ```js
2171 * const db = new Database();
2172 * const collection = db.collection("friends");
2173 * await collection.save(
2174 * {
2175 * _key: "musadir",
2176 * _from: "users/rana",
2177 * _to: "users/mudasir",
2178 * active: true,
2179 * best: true
2180 * }
2181 * );
2182 * await collection.save(
2183 * {
2184 * _key: "salman",
2185 * _from: "users/rana",
2186 * _to: "users/salman",
2187 * active: false,
2188 * best: false
2189 * }
2190 * );
2191 * const result = await collection.updateAll(
2192 * [
2193 * { _key: "musadir", active: false },
2194 * { _key: "salman", active: true, best: true }
2195 * ],
2196 * { returnNew: true }
2197 * );
2198 * console.log(result[0].new.active, result[0].new.best); // false true
2199 * console.log(result[1].new.active, result[1].new.best); // true true
2200 * ```
2201 */
2202 updateAll(newData: Array<Patch<DocumentData<EntryInputType>> & ({
2203 _key: string;
2204 } | {
2205 _id: string;
2206 })>, options?: CollectionUpdateOptions): Promise<Array<(DocumentOperationMetadata & {
2207 new?: Edge<EntryResultType>;
2208 old?: Edge<EntryResultType>;
2209 }) | DocumentOperationFailure>>;
2210 /**
2211 * Removes an existing document from the collection.
2212 *
2213 * Throws an exception when passed a document or `_id` from a different
2214 * collection.
2215 *
2216 * @param selector - Document `_key`, `_id` or object with either of those
2217 * properties (e.g. a document from this collection).
2218 * @param options - Options for removing the document.
2219 *
2220 * @example
2221 * ```js
2222 * const db = new Database();
2223 * const collection = db.collection("friends");
2224 * const doc = await collection.document("musadir");
2225 * await collection.remove(doc);
2226 * // document with key "musadir" deleted
2227 * ```
2228 */
2229 remove(selector: DocumentSelector, options?: CollectionRemoveOptions): Promise<DocumentMetadata & {
2230 old?: Edge<EntryResultType>;
2231 }>;
2232 /**
2233 * Removes existing documents from the collection.
2234 *
2235 * Throws an exception when passed any document or `_id` from a different
2236 * collection.
2237 *
2238 * @param selectors - Documents `_key`, `_id` or objects with either of those
2239 * properties (e.g. documents from this collection).
2240 * @param options - Options for removing the documents.
2241 *
2242 * @example
2243 * ```js
2244 * const db = new Database();
2245 * const collection = db.collection("friends");
2246 * await collection.removeAll(["musadir", "salman"]);
2247 * // document with keys "musadir" and "salman" deleted
2248 * ```
2249 */
2250 removeAll(selectors: DocumentSelector[], options?: CollectionRemoveOptions): Promise<Array<(DocumentMetadata & {
2251 old?: Edge<EntryResultType>;
2252 }) | DocumentOperationFailure>>;
2253 /**
2254 * Bulk imports the given `data` into the collection.
2255 *
2256 * @param data - The data to import, as an array of edge data.
2257 * @param options - Options for importing the data.
2258 *
2259 * @example
2260 * ```js
2261 * const db = new Database();
2262 * const collection = db.collection("some-collection");
2263 * await collection.import(
2264 * [
2265 * { _key: "x", _from: "vertices/a", _to: "vertices/b", weight: 1 },
2266 * { _key: "y", _from: "vertices/a", _to: "vertices/c", weight: 2 }
2267 * ]
2268 * );
2269 * ```
2270 */
2271 import(data: EdgeData<EntryInputType>[], options?: CollectionImportOptions): Promise<CollectionImportResult>;
2272 /**
2273 * Bulk imports the given `data` into the collection.
2274 *
2275 * @param data - The data to import, as an array containing a single array of
2276 * attribute names followed by one or more arrays of attribute values for
2277 * each edge document.
2278 * @param options - Options for importing the data.
2279 *
2280 * @example
2281 * ```js
2282 * const db = new Database();
2283 * const collection = db.collection("some-collection");
2284 * await collection.import(
2285 * [
2286 * [ "_key", "_from", "_to", "weight" ],
2287 * [ "x", "vertices/a", "vertices/b", 1 ],
2288 * [ "y", "vertices/a", "vertices/c", 2 ]
2289 * ]
2290 * );
2291 * ```
2292 */
2293 import(data: any[][], options?: CollectionImportOptions): Promise<CollectionImportResult>;
2294 /**
2295 * Bulk imports the given `data` into the collection.
2296 *
2297 * If `type` is omitted, `data` must contain one JSON array per line with
2298 * the first array providing the attribute names and all other arrays
2299 * providing attribute values for each edge document.
2300 *
2301 * If `type` is set to `"documents"`, `data` must contain one JSON document
2302 * per line.
2303 *
2304 * If `type` is set to `"list"`, `data` must contain a JSON array of
2305 * edge documents.
2306 *
2307 * If `type` is set to `"auto"`, `data` can be in either of the formats
2308 * supported by `"documents"` or `"list"`.
2309 *
2310 * @param data - The data to import as a Buffer (Node), Blob (browser) or
2311 * string.
2312 * @param options - Options for importing the data.
2313 *
2314 * @example
2315 * ```js
2316 * const db = new Database();
2317 * const collection = db.collection("some-collection");
2318 * await collection.import(
2319 * '{"_key":"x","_from":"vertices/a","_to":"vertices/b","weight":1}\r\n' +
2320 * '{"_key":"y","_from":"vertices/a","_to":"vertices/c","weight":2}\r\n',
2321 * { type: "documents" } // or "auto"
2322 * );
2323 * ```
2324 *
2325 * @example
2326 * ```js
2327 * const db = new Database();
2328 * const collection = db.collection("some-collection");
2329 * await collection.import(
2330 * '[{"_key":"x","_from":"vertices/a","_to":"vertices/b","weight":1},' +
2331 * '{"_key":"y","_from":"vertices/a","_to":"vertices/c","weight":2}]',
2332 * { type: "list" } // or "auto"
2333 * );
2334 * ```
2335 *
2336 * @example
2337 * ```js
2338 * const db = new Database();
2339 * const collection = db.collection("some-collection");
2340 * await collection.import(
2341 * '["_key","_from","_to","weight"]\r\n' +
2342 * '["x","vertices/a","vertices/b",1]\r\n' +
2343 * '["y","vertices/a","vertices/c",2]\r\n'
2344 * );
2345 * ```
2346 */
2347 import(data: Buffer | Blob | string, options?: CollectionImportOptions & {
2348 type?: "documents" | "list" | "auto";
2349 }): Promise<CollectionImportResult>;
2350 /**
2351 * Retrieves a list of all edges of the document matching the given
2352 * `selector`.
2353 *
2354 * Throws an exception when passed a document or `_id` from a different
2355 * collection.
2356 *
2357 * @param selector - Document `_key`, `_id` or object with either of those
2358 * properties (e.g. a document from this collection).
2359 * @param options - Options for retrieving the edges.
2360 *
2361 * @example
2362 * ```js
2363 * const db = new Database();
2364 * const collection = db.collection("edges");
2365 * await collection.import([
2366 * ["_key", "_from", "_to"],
2367 * ["x", "vertices/a", "vertices/b"],
2368 * ["y", "vertices/a", "vertices/c"],
2369 * ["z", "vertices/d", "vertices/a"],
2370 * ]);
2371 * const edges = await collection.edges("vertices/a");
2372 * console.log(edges.map((edge) => edge._key)); // ["x", "y", "z"]
2373 * ```
2374 */
2375 edges(selector: DocumentSelector, options?: CollectionEdgesOptions): Promise<ArangoApiResponse<CollectionEdgesResult<EntryResultType>>>;
2376 /**
2377 * Retrieves a list of all incoming edges of the document matching the given
2378 * `selector`.
2379 *
2380 * Throws an exception when passed a document or `_id` from a different
2381 * collection.
2382 *
2383 * @param selector - Document `_key`, `_id` or object with either of those
2384 * properties (e.g. a document from this collection).
2385 * @param options - Options for retrieving the edges.
2386 *
2387 * @example
2388 * ```js
2389 * const db = new Database();
2390 * const collection = db.collection("edges");
2391 * await collection.import([
2392 * ["_key", "_from", "_to"],
2393 * ["x", "vertices/a", "vertices/b"],
2394 * ["y", "vertices/a", "vertices/c"],
2395 * ["z", "vertices/d", "vertices/a"],
2396 * ]);
2397 * const edges = await collection.inEdges("vertices/a");
2398 * console.log(edges.map((edge) => edge._key)); // ["z"]
2399 * ```
2400 */
2401 inEdges(selector: DocumentSelector, options?: CollectionEdgesOptions): Promise<ArangoApiResponse<CollectionEdgesResult<EntryResultType>>>;
2402 /**
2403 * Retrieves a list of all outgoing edges of the document matching the given
2404 * `selector`.
2405 *
2406 * Throws an exception when passed a document or `_id` from a different
2407 * collection.
2408 *
2409 * @param selector - Document `_key`, `_id` or object with either of those
2410 * properties (e.g. a document from this collection).
2411 * @param options - Options for retrieving the edges.
2412 *
2413 * @example
2414 * ```js
2415 * const db = new Database();
2416 * const collection = db.collection("edges");
2417 * await collection.import([
2418 * ["_key", "_from", "_to"],
2419 * ["x", "vertices/a", "vertices/b"],
2420 * ["y", "vertices/a", "vertices/c"],
2421 * ["z", "vertices/d", "vertices/a"],
2422 * ]);
2423 * const edges = await collection.outEdges("vertices/a");
2424 * console.log(edges.map((edge) => edge._key)); // ["x", "y"]
2425 * ```
2426 */
2427 outEdges(selector: DocumentSelector, options?: CollectionEdgesOptions): Promise<ArangoApiResponse<CollectionEdgesResult<EntryResultType>>>;
2428}
2429/**
2430 * @internal
2431 */
2432export declare class Collection<EntryResultType extends Record<string, any> = any, EntryInputType extends Record<string, any> = EntryResultType> implements EdgeCollection<EntryResultType, EntryInputType>, DocumentCollection<EntryResultType, EntryInputType> {
2433 protected _name: string;
2434 protected _db: Database;
2435 /**
2436 * @internal
2437 */
2438 constructor(db: Database, name: string);
2439 get isArangoCollection(): true;
2440 get name(): string;
2441 get(): Promise<any>;
2442 exists(): Promise<boolean>;
2443 create(options?: CreateCollectionOptions & {
2444 type?: CollectionType;
2445 }): Promise<any>;
2446 properties(properties?: CollectionPropertiesOptions): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties>>;
2447 count(): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties & {
2448 count: number;
2449 }>>;
2450 recalculateCount(): Promise<boolean>;
2451 figures(details?: boolean): Promise<CollectionMetadata & ArangoApiResponse<CollectionProperties & {
2452 count: number;
2453 figures: Record<string, any>;
2454 }>>;
2455 revision(): Promise<ArangoApiResponse<CollectionMetadata & CollectionProperties & {
2456 revision: string;
2457 }>>;
2458 checksum(options?: CollectionChecksumOptions): Promise<ArangoApiResponse<CollectionMetadata & {
2459 revision: string;
2460 checksum: string;
2461 }>>;
2462 loadIndexes(): Promise<boolean>;
2463 rename(newName: string): Promise<ArangoApiResponse<CollectionMetadata>>;
2464 truncate(): Promise<ArangoApiResponse<CollectionMetadata>>;
2465 drop(options?: CollectionDropOptions): Promise<any>;
2466 getResponsibleShard(document: Partial<Document<EntryResultType>>): Promise<string>;
2467 documentId(selector: DocumentSelector): string;
2468 documentExists(selector: DocumentSelector, options?: DocumentExistsOptions): Promise<boolean>;
2469 documents(selectors: (string | ObjectWithKey)[], options?: CollectionBatchReadOptions): Promise<any>;
2470 document(selector: DocumentSelector, options?: boolean | CollectionReadOptions): Promise<any>;
2471 save(data: DocumentData<EntryInputType>, options?: CollectionInsertOptions): Promise<any>;
2472 saveAll(data: Array<DocumentData<EntryInputType>>, options?: CollectionInsertOptions): Promise<any>;
2473 replace(selector: DocumentSelector, newData: DocumentData<EntryInputType>, options?: CollectionReplaceOptions): Promise<any>;
2474 replaceAll(newData: Array<DocumentData<EntryInputType> & ({
2475 _key: string;
2476 } | {
2477 _id: string;
2478 })>, options?: CollectionReplaceOptions): Promise<any>;
2479 update(selector: DocumentSelector, newData: Patch<DocumentData<EntryInputType>>, options?: CollectionUpdateOptions): Promise<any>;
2480 updateAll(newData: Array<Patch<DocumentData<EntryInputType>> & ({
2481 _key: string;
2482 } | {
2483 _id: string;
2484 })>, options?: CollectionUpdateOptions): Promise<any>;
2485 remove(selector: DocumentSelector, options?: CollectionRemoveOptions): Promise<any>;
2486 removeAll(selectors: (string | ObjectWithKey)[], options?: CollectionRemoveOptions): Promise<any>;
2487 import(data: Buffer | Blob | string | any[], options?: CollectionImportOptions & {
2488 type?: "documents" | "list" | "auto";
2489 }): Promise<CollectionImportResult>;
2490 protected _edges(selector: DocumentSelector, options?: CollectionEdgesOptions, direction?: "in" | "out"): Promise<any>;
2491 edges(vertex: DocumentSelector, options?: CollectionEdgesOptions): Promise<any>;
2492 inEdges(vertex: DocumentSelector, options?: CollectionEdgesOptions): Promise<any>;
2493 outEdges(vertex: DocumentSelector, options?: CollectionEdgesOptions): Promise<any>;
2494 indexes(options?: IndexListOptions): Promise<any>;
2495 index(selector: IndexSelector): Promise<any>;
2496 ensureIndex(options: EnsurePersistentIndexOptions | EnsureGeoIndexOptions | EnsureTtlIndexOptions | EnsureMdiIndexOptions | EnsureInvertedIndexOptions): Promise<any>;
2497 dropIndex(selector: IndexSelector): Promise<any>;
2498 compact(): Promise<any>;
2499}
2500//# sourceMappingURL=collection.d.ts.map
\No newline at end of file