Skip to content

Commit e634738

Browse files
committed
Expose database instances
Fixes DE-935.
1 parent bf84655 commit e634738

File tree

10 files changed

+242
-137
lines changed

10 files changed

+242
-137
lines changed

CHANGELOG.md

Lines changed: 15 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+
### Added
20+
21+
- Added `database` property to `Analyzer`, `ArrayCursor`, `BatchedArrayCursor`,
22+
`Collection`, `Graph`, `Job`, `Route`, `Transaction` and `View` types (DE-935)
23+
24+
This property can be used to access the database instance a given object
25+
belongs to.
26+
27+
- Added `headers` and `path` properties to `Route` type
28+
29+
These properties can be used to access the headers and path used when creating
30+
the route.
31+
1732
## [9.1.0] - 2024-09-25
1833

1934
### Changed

src/analyzer.ts

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,13 @@ export class Analyzer {
924924
this._name = name;
925925
}
926926

927+
/**
928+
* Database this analyzer belongs to.
929+
*/
930+
get database() {
931+
return this._db;
932+
}
933+
927934
/**
928935
* @internal
929936
*
@@ -1001,40 +1008,40 @@ export class Analyzer {
10011008
options: Options
10021009
): Promise<
10031010
Options extends CreateIdentityAnalyzerOptions
1004-
? IdentityAnalyzerDescription
1005-
: Options extends CreateDelimiterAnalyzerOptions
1006-
? DelimiterAnalyzerDescription
1007-
: Options extends CreateStemAnalyzerOptions
1008-
? StemAnalyzerDescription
1009-
: Options extends CreateNormAnalyzerOptions
1010-
? NormAnalyzerDescription
1011-
: Options extends CreateNgramAnalyzerOptions
1012-
? NgramAnalyzerDescription
1013-
: Options extends CreateTextAnalyzerOptions
1014-
? TextAnalyzerDescription
1015-
: Options extends CreateSegmentationAnalyzerOptions
1016-
? SegmentationAnalyzerDescription
1017-
: Options extends CreateAqlAnalyzerOptions
1018-
? AqlAnalyzerDescription
1019-
: Options extends CreatePipelineAnalyzerOptions
1020-
? PipelineAnalyzerDescription
1021-
: Options extends CreateStopwordsAnalyzerOptions
1022-
? StopwordsAnalyzerDescription
1023-
: Options extends CreateCollationAnalyzerOptions
1024-
? CollationAnalyzerDescription
1025-
: Options extends CreateMinHashAnalyzerOptions
1026-
? MinHashAnalyzerDescription
1027-
: Options extends CreateClassificationAnalyzerOptions
1028-
? ClassificationAnalyzerDescription
1029-
: Options extends CreateNearestNeighborsAnalyzerOptions
1030-
? NearestNeighborsAnalyzerDescription
1031-
: Options extends CreateGeoJsonAnalyzerOptions
1032-
? GeoJsonAnalyzerDescription
1033-
: Options extends CreateGeoPointAnalyzerOptions
1034-
? GeoPointAnalyzerDescription
1035-
: Options extends CreateGeoS2AnalyzerOptions
1036-
? GeoS2AnalyzerDescription
1037-
: AnalyzerDescription
1011+
? IdentityAnalyzerDescription
1012+
: Options extends CreateDelimiterAnalyzerOptions
1013+
? DelimiterAnalyzerDescription
1014+
: Options extends CreateStemAnalyzerOptions
1015+
? StemAnalyzerDescription
1016+
: Options extends CreateNormAnalyzerOptions
1017+
? NormAnalyzerDescription
1018+
: Options extends CreateNgramAnalyzerOptions
1019+
? NgramAnalyzerDescription
1020+
: Options extends CreateTextAnalyzerOptions
1021+
? TextAnalyzerDescription
1022+
: Options extends CreateSegmentationAnalyzerOptions
1023+
? SegmentationAnalyzerDescription
1024+
: Options extends CreateAqlAnalyzerOptions
1025+
? AqlAnalyzerDescription
1026+
: Options extends CreatePipelineAnalyzerOptions
1027+
? PipelineAnalyzerDescription
1028+
: Options extends CreateStopwordsAnalyzerOptions
1029+
? StopwordsAnalyzerDescription
1030+
: Options extends CreateCollationAnalyzerOptions
1031+
? CollationAnalyzerDescription
1032+
: Options extends CreateMinHashAnalyzerOptions
1033+
? MinHashAnalyzerDescription
1034+
: Options extends CreateClassificationAnalyzerOptions
1035+
? ClassificationAnalyzerDescription
1036+
: Options extends CreateNearestNeighborsAnalyzerOptions
1037+
? NearestNeighborsAnalyzerDescription
1038+
: Options extends CreateGeoJsonAnalyzerOptions
1039+
? GeoJsonAnalyzerDescription
1040+
: Options extends CreateGeoPointAnalyzerOptions
1041+
? GeoPointAnalyzerDescription
1042+
: Options extends CreateGeoS2AnalyzerOptions
1043+
? GeoS2AnalyzerDescription
1044+
: AnalyzerDescription
10381045
> {
10391046
return this._db.request({
10401047
method: "POST",

src/collection.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,10 @@ export interface DocumentCollection<
10631063
EntryResultType extends Record<string, any> = any,
10641064
EntryInputType extends Record<string, any> = EntryResultType,
10651065
> extends ArangoCollection {
1066+
/**
1067+
* Database this collection belongs to.
1068+
*/
1069+
readonly database: Database;
10661070
/**
10671071
* Checks whether the collection exists.
10681072
*
@@ -1215,7 +1219,7 @@ export interface DocumentCollection<
12151219
): Promise<
12161220
ArangoApiResponse<
12171221
CollectionMetadata &
1218-
CollectionProperties & { count: number; figures: Record<string, any> }
1222+
CollectionProperties & { count: number; figures: Record<string, any> }
12191223
>
12201224
>;
12211225
/**
@@ -1550,9 +1554,9 @@ export interface DocumentCollection<
15501554
): Promise<
15511555
Array<
15521556
| (DocumentOperationMetadata & {
1553-
new?: Document<EntryResultType>;
1554-
old?: Document<EntryResultType>;
1555-
})
1557+
new?: Document<EntryResultType>;
1558+
old?: Document<EntryResultType>;
1559+
})
15561560
| DocumentOperationFailure
15571561
>
15581562
>;
@@ -1622,9 +1626,9 @@ export interface DocumentCollection<
16221626
): Promise<
16231627
Array<
16241628
| (DocumentOperationMetadata & {
1625-
new?: Document<EntryResultType>;
1626-
old?: Document<EntryResultType>;
1627-
})
1629+
new?: Document<EntryResultType>;
1630+
old?: Document<EntryResultType>;
1631+
})
16281632
| DocumentOperationFailure
16291633
>
16301634
>;
@@ -1694,9 +1698,9 @@ export interface DocumentCollection<
16941698
): Promise<
16951699
Array<
16961700
| (DocumentOperationMetadata & {
1697-
new?: Document<EntryResultType>;
1698-
old?: Document<EntryResultType>;
1699-
})
1701+
new?: Document<EntryResultType>;
1702+
old?: Document<EntryResultType>;
1703+
})
17001704
| DocumentOperationFailure
17011705
>
17021706
>;
@@ -2255,9 +2259,9 @@ export interface EdgeCollection<
22552259
): Promise<
22562260
Array<
22572261
| (DocumentOperationMetadata & {
2258-
new?: Edge<EntryResultType>;
2259-
old?: Edge<EntryResultType>;
2260-
})
2262+
new?: Edge<EntryResultType>;
2263+
old?: Edge<EntryResultType>;
2264+
})
22612265
| DocumentOperationFailure
22622266
>
22632267
>;
@@ -2351,9 +2355,9 @@ export interface EdgeCollection<
23512355
): Promise<
23522356
Array<
23532357
| (DocumentOperationMetadata & {
2354-
new?: Edge<EntryResultType>;
2355-
old?: Edge<EntryResultType>;
2356-
})
2358+
new?: Edge<EntryResultType>;
2359+
old?: Edge<EntryResultType>;
2360+
})
23572361
| DocumentOperationFailure
23582362
>
23592363
>;
@@ -2445,9 +2449,9 @@ export interface EdgeCollection<
24452449
): Promise<
24462450
Array<
24472451
| (DocumentOperationMetadata & {
2448-
new?: Edge<EntryResultType>;
2449-
old?: Edge<EntryResultType>;
2450-
})
2452+
new?: Edge<EntryResultType>;
2453+
old?: Edge<EntryResultType>;
2454+
})
24512455
| DocumentOperationFailure
24522456
>
24532457
>;
@@ -2705,13 +2709,12 @@ export interface EdgeCollection<
27052709
* @internal
27062710
*/
27072711
export class Collection<
2708-
EntryResultType extends Record<string, any> = any,
2709-
EntryInputType extends Record<string, any> = EntryResultType,
2710-
>
2712+
EntryResultType extends Record<string, any> = any,
2713+
EntryInputType extends Record<string, any> = EntryResultType,
2714+
>
27112715
implements
2712-
EdgeCollection<EntryResultType, EntryInputType>,
2713-
DocumentCollection<EntryResultType, EntryInputType>
2714-
{
2716+
EdgeCollection<EntryResultType, EntryInputType>,
2717+
DocumentCollection<EntryResultType, EntryInputType> {
27152718
//#region attributes
27162719
protected _name: string;
27172720
protected _db: Database;
@@ -2730,6 +2733,10 @@ export class Collection<
27302733
return true;
27312734
}
27322735

2736+
get database() {
2737+
return this._db;
2738+
}
2739+
27332740
get name() {
27342741
return this._name;
27352742
}
@@ -2838,9 +2845,9 @@ export class Collection<
28382845
details = false
28392846
): Promise<
28402847
CollectionMetadata &
2841-
ArangoApiResponse<
2842-
CollectionProperties & { count: number; figures: Record<string, any> }
2843-
>
2848+
ArangoApiResponse<
2849+
CollectionProperties & { count: number; figures: Record<string, any> }
2850+
>
28442851
> {
28452852
return this._db.request({
28462853
path: `/_api/collection/${encodeURIComponent(this._name)}/figures`,

src/cursor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ export class BatchedArrayCursor<T = any> {
226226
this._nextBatchId = body.nextBatchId;
227227
}
228228

229+
/**
230+
* Database this cursor belongs to.
231+
*/
232+
get database() {
233+
return this._db;
234+
}
235+
229236
/**
230237
* An {@link ArrayCursor} providing item-wise access to the cursor result set.
231238
*
@@ -769,6 +776,13 @@ export class ArrayCursor<T = any> {
769776
this._view = view;
770777
}
771778

779+
/**
780+
* Database this cursor belongs to.
781+
*/
782+
get database() {
783+
return this._batches.database;
784+
}
785+
772786
/**
773787
* A {@link BatchedArrayCursor} providing batch-wise access to the cursor
774788
* result set.

0 commit comments

Comments
 (0)