Skip to content

Commit a906466

Browse files
committed
Fix DE-849: Add HiddenIndex type
1 parent 0bbd204 commit a906466

File tree

5 files changed

+85
-10
lines changed

5 files changed

+85
-10
lines changed

.eslintrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"sourceType": "module",
99
"project": "./tsconfig.json"
1010
},
11-
"plugins": ["@typescript-eslint", "prettier", "security"],
11+
"plugins": [
12+
"@typescript-eslint",
13+
"prettier",
14+
"security"
15+
],
1216
"extends": [
1317
"plugin:@typescript-eslint/recommended",
1418
"plugin:security/recommended",
@@ -26,7 +30,9 @@
2630
"@typescript-eslint/no-non-null-assertion": "off",
2731
"@typescript-eslint/no-unused-vars": [
2832
"error",
29-
{ "argsIgnorePattern": "^_" }
33+
{
34+
"argsIgnorePattern": "^_"
35+
}
3036
],
3137
"security/detect-object-injection": "off"
3238
}

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ 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+
### Changed
20+
21+
- Removed `progress` property from `Index` type
22+
23+
This property is only available when fetching indexes with the `withHidden`
24+
option set to `true`.
25+
26+
- Added `HiddenIndex` type (DE-849)
27+
28+
This type is used to represent an index returned by `collection.indexes` when
29+
the `withHidden` option is set to `true` and includes the `progress` property
30+
in addition to internal indexes.
31+
1732
## [9.0.0] - 2024-07-31
1833

1934
This is a major release and breaks backwards compatibility.
@@ -1904,6 +1919,7 @@ For a detailed list of changes between pre-release versions of v7 see the
19041919

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

1922+
[unreleased]: https://github.com/arangodb/arangojs/compare/v9.0.0...HEAD
19071923
[9.0.0]: https://github.com/arangodb/arangojs/compare/v8.8.1...v9.0.0
19081924
[8.8.1]: https://github.com/arangodb/arangojs/compare/v8.8.0...v8.8.1
19091925
[8.8.0]: https://github.com/arangodb/arangojs/compare/v8.7.0...v8.8.0

src/collection.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
MdiIndex,
4242
_indexHandle,
4343
EnsureIndexOptions,
44+
HiddenIndex,
4445
} from "./indexes.js";
4546
import { COLLECTION_NOT_FOUND, DOCUMENT_NOT_FOUND } from "./lib/codes.js";
4647

@@ -978,8 +979,11 @@ export type IndexListOptions = {
978979
*/
979980
withStats?: boolean;
980981
/**
981-
* If set to `true`, includes indexes that are not yet fully built but are
982-
* in the building phase.
982+
* If set to `true`, includes internal indexes as well as indexes that are
983+
* not yet fully built but are in the building phase.
984+
*
985+
* You should cast the resulting indexes to `HiddenIndex` to ensure internal
986+
* and incomplete indexes are accurately represented.
983987
*
984988
* Default: `false`.
985989
*/
@@ -1879,8 +1883,19 @@ export interface DocumentCollection<
18791883
* const collection = db.collection("some-collection");
18801884
* const indexes = await collection.indexes();
18811885
* ```
1886+
*
1887+
* @example
1888+
* ```js
1889+
* const db = new Database();
1890+
* const collection = db.collection("some-collection");
1891+
* const allIndexes = await collection.indexes<HiddenIndex>({
1892+
* withHidden: true
1893+
* });
1894+
* ```
18821895
*/
1883-
indexes(options?: IndexListOptions): Promise<Index[]>;
1896+
indexes<IndexType extends Index | HiddenIndex = Index>(
1897+
options?: IndexListOptions
1898+
): Promise<IndexType[]>;
18841899
/**
18851900
* Returns an index description by name or `id` if it exists.
18861901
*

src/indexes.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,6 @@ export type GenericIndex = {
553553
* Additional stats about this index.
554554
*/
555555
figures?: Record<string, any>;
556-
/**
557-
* Progress of this index if it is still being created.
558-
*/
559-
progress?: number;
560556
};
561557

562558
/**
@@ -670,6 +666,21 @@ export type InvertedIndex = GenericIndex & {
670666
optimizeTopK: string[];
671667
};
672668

669+
/**
670+
* An object representing an arangosearch index.
671+
*/
672+
export type InternalArangosearchIndex = {
673+
id: string;
674+
type: "arangosearch";
675+
view: string;
676+
figures?: Record<string, any>;
677+
analyzers: string[];
678+
fields: Record<string, Record<string, any>>;
679+
includeAllFields: boolean;
680+
trackListPositions: boolean;
681+
storeValues: "none" | "id";
682+
};
683+
673684
/**
674685
* An object representing an index.
675686
*/
@@ -681,6 +692,33 @@ export type Index =
681692
| MdiIndex
682693
| InvertedIndex;
683694

695+
/**
696+
* An object representing an internal index.
697+
*/
698+
export type InternalIndex = InternalArangosearchIndex;
699+
700+
/**
701+
* An object representing a potentially hidden index.
702+
*
703+
* This type can be used to cast the result of `collection.indexes` to better
704+
* reflect the actual data returned by the server when using the `withHidden`
705+
* option:
706+
*
707+
* ```ts
708+
* const indexes = await collection.indexes<HiddenIndex>({
709+
* withHidden: true
710+
* }));
711+
* // indexes may include internal indexes and indexes with a "progress"
712+
* // property
713+
* ```
714+
*/
715+
export type HiddenIndex = (Index | InternalArangosearchIndex) & {
716+
/**
717+
* Progress of this index if it is still being created.
718+
*/
719+
progress?: number;
720+
};
721+
684722
export type IndexDetails = Index & {
685723
figures?: Record<string, any>;
686724
progress?: number;

typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"excludeProtected": true,
1616
"excludePrivate": true,
1717
"includeVersion": false,
18-
"entryPoints": "src",
18+
"entryPoints": ["src"],
1919
"entryPointStrategy": "expand",
2020
"validation": {
2121
"notExported": true,

0 commit comments

Comments
 (0)