Skip to content

Commit 8500c03

Browse files
committed
Add withStats to collection#indexes
1 parent 1cb7624 commit 8500c03

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ This driver uses semantic versioning:
1414
- A change in the major version (e.g. 1.Y.Z -> 2.0.0) indicates _breaking_
1515
changes that require changes in your code to upgrade.
1616

17+
## [Unreleased]
18+
19+
### Added
20+
21+
- Added support for `withStats` option in `collection.indexes`
22+
23+
This method now takes an object with `withStats` and `withHidden` options
24+
instead of a boolean flag.
25+
1726
## [9.0.0-preview.2]
1827

1928
### Changed
@@ -1879,6 +1888,7 @@ For a detailed list of changes between pre-release versions of v7 see the
18791888

18801889
Graph methods now only return the relevant part of the response body.
18811890

1891+
[unreleased]: https://github.com/arangodb/arangojs/compare/v9.0.0-preview.2...HEAD
18821892
[9.0.0-preview.2]: https://github.com/arangodb/arangojs/compare/v9.0.0-preview.1...v9.0.0-preview.2
18831893
[9.0.0-preview.1]: https://github.com/arangodb/arangojs/compare/v8.8.1...v9.0.0-preview.1
18841894
[8.8.1]: https://github.com/arangodb/arangojs/compare/v8.8.0...v8.8.1

src/collection.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,22 @@ export type SimpleQueryFulltextOptions = {
11671167
skip?: number;
11681168
};
11691169

1170+
export type IndexListOptions = {
1171+
/**
1172+
* If set to `true`, includes additional information about each index.
1173+
*
1174+
* Default: `false`
1175+
*/
1176+
withStats?: boolean;
1177+
/**
1178+
* If set to `true`, includes indexes that are not yet fully built but are
1179+
* in the building phase.
1180+
*
1181+
* Default: `false`.
1182+
*/
1183+
withHidden?: boolean;
1184+
};
1185+
11701186
/**
11711187
* Options for performing a graph traversal.
11721188
*
@@ -2561,8 +2577,7 @@ export interface DocumentCollection<T extends Record<string, any> = any>
25612577
/**
25622578
* Returns a list of all index descriptions for the collection.
25632579
*
2564-
* @param withHidden - If set to `true`, includes indexes that are not yet
2565-
* fully built but are in the building phase. Default: `false`.
2580+
* @param options - Options for fetching the index list.
25662581
*
25672582
* @example
25682583
* ```js
@@ -2571,21 +2586,7 @@ export interface DocumentCollection<T extends Record<string, any> = any>
25712586
* const indexes = await collection.indexes();
25722587
* ```
25732588
*/
2574-
indexes(withHidden?: boolean): Promise<Index[]>;
2575-
/**
2576-
* Returns a list of all index descriptions for the collection.
2577-
*
2578-
* @param withHidden - If set to `true`, includes indexes that are not yet
2579-
* fully built but are in the building phase. Default: `false`.
2580-
*
2581-
* @example
2582-
* ```js
2583-
* const db = new Database();
2584-
* const collection = db.collection("some-collection");
2585-
* const indexes = await collection.indexes(true);
2586-
* ```
2587-
*/
2588-
indexes(withHidden?: boolean): Promise<(Index & { progress: number })[]>;
2589+
indexes(options?: IndexListOptions): Promise<Index[]>;
25892590
/**
25902591
* Returns an index description by name or `id` if it exists.
25912592
*
@@ -4169,7 +4170,7 @@ export class Collection<T extends Record<string, any> = any>
41694170
method: "PUT",
41704171
path: "/_api/simple/remove-by-keys",
41714172
body: {
4172-
options: options,
4173+
options,
41734174
keys,
41744175
collection: this._name,
41754176
},
@@ -4178,11 +4179,11 @@ export class Collection<T extends Record<string, any> = any>
41784179
//#endregion
41794180

41804181
//#region indexes
4181-
indexes(withHidden = false) {
4182+
indexes(options?: IndexListOptions) {
41824183
return this._db.request(
41834184
{
41844185
path: "/_api/index",
4185-
search: { collection: this._name, withHidden: String(withHidden) },
4186+
search: { collection: this._name, ...options },
41864187
},
41874188
(res) => res.parsedBody.indexes
41884189
);

src/indexes.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ export type GenericIndex = {
539539
* Whether this index enforces uniqueness for values of its attribute paths.
540540
*/
541541
unique: boolean;
542+
/**
543+
* Additional stats about this index.
544+
*/
545+
figures?: Record<string, any>;
546+
/**
547+
* Progress of this index if it is still being created.
548+
*/
549+
progress?: number;
542550
};
543551

544552
/**
@@ -663,6 +671,11 @@ export type Index =
663671
| MdiIndex
664672
| InvertedIndex;
665673

674+
export type IndexDetails = Index & {
675+
figures?: Record<string, any>;
676+
progress?: number;
677+
};
678+
666679
export type ObjectWithId = {
667680
[key: string]: any;
668681
id: string;

0 commit comments

Comments
 (0)