-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathcollections.ts
2982 lines (2913 loc) · 83.3 KB
/
collections.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* ```ts
* import type {
* DocumentCollection,
* EdgeCollection,
* } from "arangojs/collections";
* ```
*
* The "collections" module provides collection related types and interfaces
* for TypeScript.
*
* @packageDocumentation
*/
import * as aql from "./aql.js";
import * as connection from "./connection.js";
import * as databases from "./databases.js";
import * as documents from "./documents.js";
import * as errors from "./errors.js";
import * as indexes from "./indexes.js";
import { COLLECTION_NOT_FOUND, DOCUMENT_NOT_FOUND } from "./lib/codes.js";
//#region ArangoCollection interface
/**
* Indicates whether the given value represents an {@link ArangoCollection}.
*
* @param collection - A value that might be a collection.
*/
export function isArangoCollection(
collection: any
): collection is ArangoCollection {
return Boolean(collection && collection.isArangoCollection);
}
/**
* Coerces the given collection name or {@link ArangoCollection} object to
* a string representing the collection name.
*
* @param collection - Collection name or {@link ArangoCollection} object.
*/
export function collectionToString(
collection: string | ArangoCollection
): string {
if (isArangoCollection(collection)) {
return String(collection.name);
} else return String(collection);
}
/**
* A marker interface identifying objects that can be used in AQL template
* strings to create references to ArangoDB collections.
*
* See {@link aql.aql}.
*/
export interface ArangoCollection {
/**
* @internal
*
* Indicates that this object represents an ArangoDB collection.
*/
readonly isArangoCollection: true;
/**
* Name of the collection.
*/
readonly name: string;
}
//#endregion
//#region Shared types
/**
* Integer values indicating the collection type.
*/
export enum CollectionType {
DOCUMENT_COLLECTION = 2,
EDGE_COLLECTION = 3,
}
/**
* Integer values indicating the collection loading status.
*/
export enum CollectionStatus {
NEWBORN = 1,
UNLOADED = 2,
LOADED = 3,
UNLOADING = 4,
DELETED = 5,
LOADING = 6,
}
/**
* Type of key generator.
*/
export type KeyGenerator = "traditional" | "autoincrement" | "uuid" | "padded";
/**
* Strategy for sharding a collection.
*/
export type ShardingStrategy =
| "hash"
| "enterprise-hash-smart-edge"
| "enterprise-hash-smart-vertex"
| "community-compat"
| "enterprise-compat"
| "enterprise-smart-edge-compat";
/**
* When a validation should be applied.
*
* * `"none"`: No validation.
* * `"new"`: Newly inserted documents are validated.
* * `"moderate"`: New and modified documents are validated unless the modified
* document was already invalid.
* * `"strict"`: New and modified documents are always validated.
*/
export type ValidationLevel = "none" | "new" | "moderate" | "strict";
/**
* Write operation that can result in a computed value being computed.
*/
export type WriteOperation = "insert" | "update" | "replace";
//#endregion
//#region Collection operation options
/**
* Options for creating a collection.
*
* See {@link databases.Database#createCollection}, {@link databases.Database#createEdgeCollection}
* and {@link DocumentCollection#create} or {@link EdgeCollection#create}.
*/
export type CreateCollectionOptions = CollectionPropertiesOptions & {
/**
* @internal
*
* Whether the collection should be created as a system collection.
*
* Default: `false`
*/
isSystem?: boolean;
/**
* An object defining the collection's key generation.
*/
keyOptions?: CollectionKeyOptions;
/**
* (Cluster only.) Unless set to `false`, the server will wait for all
* replicas to create the collection before returning.
*
* Default: `true`
*/
waitForSyncReplication?: boolean;
/**
* (Cluster only.) Unless set to `false`, the server will check whether
* enough replicas are available at creation time and bail out otherwise.
*
* Default: `true`
*/
enforceReplicationFactor?: boolean;
/**
* (Cluster only.) Number of shards to distribute the collection across.
*
* Default: `1`
*/
numberOfShards?: number;
/**
* (Cluster only.) Document attributes to use to determine the target shard
* for each document.
*
* Default: `["_key"]`
*/
shardKeys?: string[];
/**
* (Cluster only.) Sharding strategy to use.
*/
shardingStrategy?: ShardingStrategy;
/**
* (Enterprise Edition cluster only.) If set to a collection name, sharding
* of the new collection will follow the rules for that collection. As long
* as the new collection exists, the indicated collection can not be dropped.
*/
distributeShardsLike?: string;
/**
* (Enterprise Edition cluster only.) Attribute containing the shard key
* value of the referred-to smart join collection.
*/
smartJoinAttribute?: string;
/**
* (Enterprise Edition cluster only.) Attribute used for sharding.
*/
smartGraphAttribute?: string;
};
/**
* An object defining the collection's key generation.
*/
export type CollectionKeyOptions = {
/**
* Type of key generator to use.
*/
type?: KeyGenerator;
/**
* Unless set to `false`, documents can be created with a user-specified
* `_key` attribute.
*
* Default: `true`
*/
allowUserKeys?: boolean;
/**
* (Autoincrement only.) How many steps to increment the key each time.
*/
increment?: number;
/**
* (Autoincrement only.) Initial offset for the key.
*/
offset?: number;
};
/**
* Options for setting a collection's properties.
*
* See {@link DocumentCollection#properties} and {@link EdgeCollection#properties}.
*/
export type CollectionPropertiesOptions = {
/**
* If set to `true`, data will be synchronized to disk before returning from
* a document create, update, replace or removal operation.
*
* Default: `false`
*/
waitForSync?: boolean;
/**
* (Cluster only.) How many copies of each document should be kept in the
* cluster.
*
* Default: `1`
*/
replicationFactor?: number | "satellite";
/**
* (Cluster only.) Write concern for this collection.
*/
writeConcern?: number;
/**
* Options for validating documents in this collection.
*/
schema?: SchemaOptions;
/**
* Computed values to apply to documents in this collection.
*/
computedValues?: ComputedValueOptions[];
/**
* Whether the in-memory hash cache is enabled for this collection.
*
* Default: `false`
*/
cacheEnabled?: boolean;
};
/**
* Options for validating collection documents.
*/
export type SchemaOptions = {
/**
* JSON Schema description of the validation schema for documents.
*/
rule: any;
/**
* When validation should be applied.
*
* Default: `"strict"`
*/
level?: ValidationLevel;
/**
* Message to be used if validation fails.
*/
message?: string;
};
/**
* Options for creating a computed value.
*/
export type ComputedValueOptions = {
/**
* Name of the target attribute of the computed value.
*/
name: string;
/**
* AQL `RETURN` expression that computes the value.
*
* Note that when passing an AQL query object, the `bindVars` will be ignored.
*/
expression: string | aql.AqlLiteral | aql.AqlQuery;
/**
* If set to `false`, the computed value will not be applied if the
* expression evaluates to `null`.
*
* Default: `true`
*/
overwrite?: boolean;
/**
* Which operations should result in the value being computed.
*
* Default: `["insert", "update", "replace"]`
*/
computeOn?: WriteOperation[];
/**
* If set to `false`, the field will be unset if the expression evaluates to
* `null`. Otherwise the field will be set to the value `null`. Has no effect
* if `overwrite` is set to `false`.
*
* Default: `true`
*/
keepNull?: boolean;
/**
* Whether the write operation should fail if the expression produces a
* warning.
*
* Default: `false`
*/
failOnWarning?: boolean;
};
/**
* Options for retrieving a collection checksum.
*/
export type CollectionChecksumOptions = {
/**
* If set to `true`, revision IDs will be included in the calculation
* of the checksum.
*
* Default: `false`
*/
withRevisions?: boolean;
/**
* If set to `true`, document data will be included in the calculation
* of the checksum.
*
* Default: `false`
*/
withData?: boolean;
};
/**
* Options for truncating collections.
*/
export type TruncateCollectionOptions = {
/**
* Whether the collection should be compacted after truncation.
*/
compact?: boolean;
/**
* Whether data should be synchronized to disk before returning from this
* operation.
*/
waitForSync?: boolean;
};
/**
* Options for dropping collections.
*/
export type DropCollectionOptions = {
/**
* Whether the collection is a system collection. If the collection is a
* system collection, this option must be set to `true` or ArangoDB will
* refuse to drop the collection.
*
* Default: `false`
*/
isSystem?: boolean;
};
//#endregion
//#region CollectionDescription
/**
* General information about a collection.
*/
export type CollectionDescription = {
/**
* Collection name.
*/
name: string;
/**
* A globally unique identifier for this collection.
*/
globallyUniqueId: string;
/**
* An integer indicating the collection loading status.
*/
status: CollectionStatus;
/**
* An integer indicating the collection type.
*/
type: CollectionType;
/**
* @internal
*
* Whether the collection is a system collection.
*/
isSystem: boolean;
};
//#endregion
//#region CollectionProperties
/**
* An object defining the properties of a collection.
*/
export type CollectionProperties = {
/**
* A human-readable representation of the collection loading status.
*/
statusString: string;
/**
* Whether data should be synchronized to disk before returning from
* a document create, update, replace or removal operation.
*/
waitForSync: boolean;
/**
* An object defining the collection's key generation.
*/
keyOptions: CollectionKeyProperties;
/**
* Properties for validating documents in the collection.
*/
schema: SchemaProperties | null;
/**
* (Cluster only.) Write concern for this collection.
*/
writeConcern: number;
/**
* (Cluster only.) Number of shards of this collection.
*/
numberOfShards?: number;
/**
* (Cluster only.) Keys of this collection that will be used for
* sharding.
*/
shardKeys?: string[];
/**
* (Cluster only.) Replication factor of the collection.
*/
replicationFactor?: number | "satellite";
/**
* (Cluster only.) Sharding strategy of the collection.
*/
shardingStrategy?: ShardingStrategy;
/**
* (Enterprise Edition cluster only.) If set to a collection name, sharding
* of the new collection will follow the rules for that collection. As long
* as the new collection exists, the indicated collection can not be dropped.
*/
distributeShardsLike?: string;
/**
* (Enterprise Edition cluster only.) Attribute containing the shard key
* value of the referred-to smart join collection.
*/
smartJoinAttribute?: string;
/**
* (Enterprise Edition cluster only.) Attribute used for sharding.
*/
smartGraphAttribute?: string;
/**
* Computed values applied to documents in this collection.
*/
computedValues: ComputedValueProperties[];
/**
* Whether the in-memory hash cache is enabled for this collection.
*/
cacheEnabled: boolean;
/**
* Whether the newer revision-based replication protocol is enabled for
* this collection.
*/
syncByRevision: boolean;
/**
* (Enterprise Edition only.) Whether the collection is used in a SmartGraph or EnterpriseGraph.
*/
isSmart?: boolean;
/**
* (Enterprise Edition only.) Whether the SmartGraph this collection belongs to is disjoint.
*/
isDisjoint?: string;
};
/**
* An object defining the collection's key generation.
*/
export type CollectionKeyProperties = {
/**
* Type of key generator to use.
*/
type: KeyGenerator;
/**
* Whether documents can be created with a user-specified `_key` attribute.
*/
allowUserKeys: boolean;
/**
* (Autoincrement only.) How many steps to increment the key each time.
*/
increment?: number;
/**
* (Autoincrement only.) Initial offset for the key.
*/
offset?: number;
/**
* Most recent key that has been generated.
*/
lastValue: number;
};
/**
* Properties for validating documents in a collection.
*/
export type SchemaProperties = {
/**
* Type of document validation.
*/
type: "json";
/**
* JSON Schema description of the validation schema for documents.
*/
rule: any;
/**
* When validation should be applied.
*/
level: ValidationLevel;
/**
* Message to be used if validation fails.
*/
message: string;
};
/**
* Properties defining a computed value.
*/
export type ComputedValueProperties = {
/**
* Name of the target attribute of the computed value.
*/
name: string;
/**
* AQL `RETURN` expression that computes the value.
*/
expression: string;
/**
* If set to `false`, the computed value will not be applied if the
* expression evaluates to `null`.
*/
overwrite: boolean;
/**
* Which operations should result in the value being computed.
*/
computeOn: WriteOperation[];
/**
* If set to `false`, the field will be unset if the expression evaluates to
* `null`. Otherwise the field will be set to the value `null`. Has no effect
* if `overwrite` is set to `false`.
*/
keepNull: boolean;
/**
* Whether the write operation should fail if the expression produces a
* warning.
*/
failOnWarning: boolean;
};
//#endregion
//#region DocumentCollection interface
/**
* Represents an document collection in a {@link databases.Database}.
*
* See {@link EdgeCollection} for a variant of this interface more suited for
* edge collections.
*
* When using TypeScript, collections can be cast to a specific document data
* type to increase type safety.
*
* @param EntryResultType - Type to represent document contents returned by the
* server (including computed properties).
* @param EntryInputType - Type to represent document contents passed when
* inserting or replacing documents (without computed properties).
*
* @example
* ```ts
* interface Person {
* name: string;
* }
* const db = new Database();
* const documents = db.collection("persons") as DocumentCollection<Person>;
* ```
*/
export interface DocumentCollection<
EntryResultType extends Record<string, any> = any,
EntryInputType extends Record<string, any> = EntryResultType,
> extends ArangoCollection {
/**
* Database this collection belongs to.
*/
readonly database: databases.Database;
//#region Collection operations
/**
* Checks whether the collection exists.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const result = await collection.exists();
* // result indicates whether the collection exists
* ```
*/
exists(): Promise<boolean>;
/**
* Retrieves general information about the collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.get();
* // data contains general information about the collection
* ```
*/
get(): Promise<connection.ArangoApiResponse<CollectionDescription>>;
/**
* Creates a collection with the given `options` and the instance's name.
*
* See also {@link databases.Database#createCollection} and
* {@link databases.Database#createEdgeCollection}.
*
* **Note**: When called on an {@link EdgeCollection} instance in TypeScript,
* the `type` option must still be set to the correct {@link CollectionType}.
* Otherwise this will result in the collection being created with the
* default type (i.e. as a document collection).
*
* @param options - Options for creating the collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("potatoes");
* await collection.create();
* // the document collection "potatoes" now exists
* ```
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("friends");
* await collection.create({ type: CollectionType.EDGE_COLLECTION });
* // the edge collection "friends" now exists
* ```
*
* @example
* ```ts
* interface Friend {
* startDate: number;
* endDate?: number;
* }
* const db = new Database();
* const collection = db.collection("friends") as EdgeCollection<Friend>;
* // even in TypeScript you still need to indicate the collection type
* // if you want to create an edge collection
* await collection.create({ type: CollectionType.EDGE_COLLECTION });
* // the edge collection "friends" now exists
* ```
*/
create(
options?: CreateCollectionOptions & {
type?: CollectionType;
}
): Promise<
connection.ArangoApiResponse<CollectionDescription & CollectionProperties>
>;
/**
* Retrieves the collection's properties.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.properties();
* // data contains the collection's properties
* ```
*/
properties(): Promise<
connection.ArangoApiResponse<CollectionDescription & CollectionProperties>
>;
/**
* Replaces the properties of the collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const result = await collection.setProperties({ waitForSync: true });
* // the collection will now wait for data being written to disk
* // whenever a document is changed
* ```
*/
properties(
properties: CollectionPropertiesOptions
): Promise<
connection.ArangoApiResponse<CollectionDescription & CollectionProperties>
>;
/**
* Retrieves information about the number of documents in a collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.count();
* // data contains the collection's count
* ```
*/
count(): Promise<
connection.ArangoApiResponse<
CollectionDescription & CollectionProperties & { count: number }
>
>;
/**
* Instructs ArangoDB to recalculate the collection's document count to fix
* any inconsistencies.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("inconsistent-collection");
* const badData = await collection.count();
* // oh no, the collection count looks wrong -- fix it!
* await collection.recalculateCount();
* const goodData = await collection.count();
* // goodData contains the collection's improved count
* ```
*/
recalculateCount(): Promise<boolean>;
/**
* Retrieves statistics for a collection.
*
* @param details - whether to return extended storage engine-specific details
* to the figures, which may cause additional load and impact performance
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.figures();
* // data contains the collection's figures
* ```
*/
figures(
details?: boolean
): Promise<
connection.ArangoApiResponse<
CollectionDescription &
CollectionProperties & { count: number; figures: Record<string, any> }
>
>;
/**
* Retrieves the collection revision ID.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.revision();
* // data contains the collection's revision
* ```
*/
revision(): Promise<
connection.ArangoApiResponse<
CollectionDescription & CollectionProperties & { revision: string }
>
>;
/**
* Retrieves the collection checksum.
*
* @param options - Options for retrieving the checksum.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const data = await collection.checksum();
* // data contains the collection's checksum
* ```
*/
checksum(
options?: CollectionChecksumOptions
): Promise<
connection.ArangoApiResponse<
CollectionDescription & { revision: string; checksum: string }
>
>;
/**
* Retrieves the collection's shard IDs.
*
* @param details - If set to `true`, the response will include the responsible
* servers for each shard.
*/
shards(
details?: false
): Promise<
connection.ArangoApiResponse<
CollectionDescription & CollectionProperties & { shards: string[] }
>
>;
/**
* Retrieves the collection's shard IDs and the responsible servers for each
* shard.
*
* @param details - If set to `false`, the response will only include the
* shard IDs without the responsible servers for each shard.
*/
shards(
details: true
): Promise<
connection.ArangoApiResponse<
CollectionDescription &
CollectionProperties & { shards: Record<string, string[]> }
>
>;
/**
* Retrieves the collection's shard IDs.
*
* @param details - If set to `true`, the response will include the responsible
* servers for each shard.
*/
shards(
details?: false
): Promise<
connection.ArangoApiResponse<
CollectionDescription & CollectionProperties & { shards: string[] }
>
>;
/**
* Retrieves the collection's shard IDs and the responsible servers for each
* shard.
*
* @param details - If set to `false`, the response will only include the
* shard IDs without the responsible servers for each shard.
*/
shards(
details: true
): Promise<
connection.ArangoApiResponse<
CollectionDescription &
CollectionProperties & { shards: Record<string, string[]> }
>
>;
/**
* Renames the collection and updates the instance's `name` to `newName`.
*
* Additionally removes the instance from the {@link databases.Database}'s internal
* cache.
*
* **Note**: Renaming collections may not be supported when ArangoDB is
* running in a cluster configuration.
*
* @param newName - The new name of the collection.
*
* @example
* ```js
* const db = new Database();
* const collection1 = db.collection("some-collection");
* await collection1.rename("other-collection");
* const collection2 = db.collection("some-collection");
* const collection3 = db.collection("other-collection");
* // Note all three collection instances are different objects but
* // collection1 and collection3 represent the same ArangoDB collection!
* ```
*/
rename(
newName: string
): Promise<connection.ArangoApiResponse<CollectionDescription>>;
/**
* Deletes all documents in the collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* await collection.truncate();
* // millions of documents cry out in terror and are suddenly silenced,
* // the collection "some-collection" is now empty
* ```
*/
truncate(
options?: TruncateCollectionOptions
): Promise<connection.ArangoApiResponse<CollectionDescription>>;
/**
* Deletes the collection from the database.
*
* @param options - Options for dropping the collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* await collection.drop();
* // The collection "some-collection" is now an ex-collection
* ```
*/
drop(
options?: DropCollectionOptions
): Promise<connection.ArangoApiResponse<{ id: string }>>;
/**
* Triggers compaction for a collection.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* await collection.compact();
* // Background compaction is triggered on the collection
* ```
*/
compact(): Promise<connection.ArangoApiResponse<CollectionDescription>>;
//#endregion
//#region Document operations
/**
* Retrieves the `shardId` of the shard responsible for the given document.
*
* @param document - Document in the collection to look up the `shardId` of.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const responsibleShard = await collection.getResponsibleShard();
* ```
*/
getResponsibleShard(
document: Partial<documents.Document<EntryResultType>>
): Promise<string>;
/**
* Derives a document `_id` from the given selector for this collection.
*
* Throws an exception when passed a document or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a document from this collection).
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const meta = await collection.save({ foo: "bar" }, { returnNew: true });
* const doc = meta.new;
* console.log(collection.documentId(meta)); // via meta._id
* console.log(collection.documentId(doc)); // via doc._id
* console.log(collection.documentId(meta._key)); // also works
* ```
*
* @example
* ```js
* const db = new Database();
* const collection1 = db.collection("some-collection");
* const collection2 = db.collection("other-collection");
* const meta = await collection1.save({ foo: "bar" });
* // Mixing collections is usually a mistake
* console.log(collection1.documentId(meta)); // ok: same collection
* console.log(collection2.documentId(meta)); // throws: wrong collection
* console.log(collection2.documentId(meta._id)); // also throws
* console.log(collection2.documentId(meta._key)); // ok but wrong collection
* ```
*/
documentId(selector: documents.DocumentSelector): string;
/**
* Checks whether a document matching the given key or id exists in this
* collection.
*
* Throws an exception when passed a document or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a document from this collection).
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const exists = await collection.documentExists("abc123");
* if (!exists) {
* console.log("Document does not exist");
* }
* ```
*/
documentExists(
selector: documents.DocumentSelector,
options?: documents.DocumentExistsOptions
): Promise<boolean>;
/**
* Retrieves the document matching the given key or id.
*
* Throws an exception when passed a document or `_id` from a different
* collection.
*
* @param selector - Document `_key`, `_id` or object with either of those
* properties (e.g. a document from this collection).
* @param options - Options for retrieving the document.
*