Skip to content

Commit

Permalink
Add withStats to collection#indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
pluma4345 committed Jun 6, 2024
1 parent 1cb7624 commit 8500c03
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ This driver uses semantic versioning:
- A change in the major version (e.g. 1.Y.Z -> 2.0.0) indicates _breaking_
changes that require changes in your code to upgrade.

## [Unreleased]

### Added

- Added support for `withStats` option in `collection.indexes`

This method now takes an object with `withStats` and `withHidden` options
instead of a boolean flag.

## [9.0.0-preview.2]

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

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

[unreleased]: https://github.com/arangodb/arangojs/compare/v9.0.0-preview.2...HEAD
[9.0.0-preview.2]: https://github.com/arangodb/arangojs/compare/v9.0.0-preview.1...v9.0.0-preview.2
[9.0.0-preview.1]: https://github.com/arangodb/arangojs/compare/v8.8.1...v9.0.0-preview.1
[8.8.1]: https://github.com/arangodb/arangojs/compare/v8.8.0...v8.8.1
Expand Down
41 changes: 21 additions & 20 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,22 @@ export type SimpleQueryFulltextOptions = {
skip?: number;
};

export type IndexListOptions = {
/**
* If set to `true`, includes additional information about each index.
*
* Default: `false`
*/
withStats?: boolean;
/**
* If set to `true`, includes indexes that are not yet fully built but are
* in the building phase.
*
* Default: `false`.
*/
withHidden?: boolean;
};

/**
* Options for performing a graph traversal.
*
Expand Down Expand Up @@ -2561,8 +2577,7 @@ export interface DocumentCollection<T extends Record<string, any> = any>
/**
* Returns a list of all index descriptions for the collection.
*
* @param withHidden - If set to `true`, includes indexes that are not yet
* fully built but are in the building phase. Default: `false`.
* @param options - Options for fetching the index list.
*
* @example
* ```js
Expand All @@ -2571,21 +2586,7 @@ export interface DocumentCollection<T extends Record<string, any> = any>
* const indexes = await collection.indexes();
* ```
*/
indexes(withHidden?: boolean): Promise<Index[]>;
/**
* Returns a list of all index descriptions for the collection.
*
* @param withHidden - If set to `true`, includes indexes that are not yet
* fully built but are in the building phase. Default: `false`.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const indexes = await collection.indexes(true);
* ```
*/
indexes(withHidden?: boolean): Promise<(Index & { progress: number })[]>;
indexes(options?: IndexListOptions): Promise<Index[]>;
/**
* Returns an index description by name or `id` if it exists.
*
Expand Down Expand Up @@ -4169,7 +4170,7 @@ export class Collection<T extends Record<string, any> = any>
method: "PUT",
path: "/_api/simple/remove-by-keys",
body: {
options: options,
options,
keys,
collection: this._name,
},
Expand All @@ -4178,11 +4179,11 @@ export class Collection<T extends Record<string, any> = any>
//#endregion

//#region indexes
indexes(withHidden = false) {
indexes(options?: IndexListOptions) {
return this._db.request(
{
path: "/_api/index",
search: { collection: this._name, withHidden: String(withHidden) },
search: { collection: this._name, ...options },
},
(res) => res.parsedBody.indexes
);
Expand Down
13 changes: 13 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ export type GenericIndex = {
* Whether this index enforces uniqueness for values of its attribute paths.
*/
unique: boolean;
/**
* Additional stats about this index.
*/
figures?: Record<string, any>;
/**
* Progress of this index if it is still being created.
*/
progress?: number;
};

/**
Expand Down Expand Up @@ -663,6 +671,11 @@ export type Index =
| MdiIndex
| InvertedIndex;

export type IndexDetails = Index & {
figures?: Record<string, any>;
progress?: number;
};

export type ObjectWithId = {
[key: string]: any;
id: string;
Expand Down

0 comments on commit 8500c03

Please sign in to comment.