Skip to content

Commit

Permalink
Expose database instances
Browse files Browse the repository at this point in the history
Fixes DE-935.
  • Loading branch information
pluma4345 committed Oct 30, 2024
1 parent bf84655 commit e634738
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 137 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ 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 `database` property to `Analyzer`, `ArrayCursor`, `BatchedArrayCursor`,
`Collection`, `Graph`, `Job`, `Route`, `Transaction` and `View` types (DE-935)

This property can be used to access the database instance a given object
belongs to.

- Added `headers` and `path` properties to `Route` type

These properties can be used to access the headers and path used when creating
the route.

## [9.1.0] - 2024-09-25

### Changed
Expand Down
75 changes: 41 additions & 34 deletions src/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,13 @@ export class Analyzer {
this._name = name;
}

/**
* Database this analyzer belongs to.
*/
get database() {
return this._db;
}

/**
* @internal
*
Expand Down Expand Up @@ -1001,40 +1008,40 @@ export class Analyzer {
options: Options
): Promise<
Options extends CreateIdentityAnalyzerOptions
? IdentityAnalyzerDescription
: Options extends CreateDelimiterAnalyzerOptions
? DelimiterAnalyzerDescription
: Options extends CreateStemAnalyzerOptions
? StemAnalyzerDescription
: Options extends CreateNormAnalyzerOptions
? NormAnalyzerDescription
: Options extends CreateNgramAnalyzerOptions
? NgramAnalyzerDescription
: Options extends CreateTextAnalyzerOptions
? TextAnalyzerDescription
: Options extends CreateSegmentationAnalyzerOptions
? SegmentationAnalyzerDescription
: Options extends CreateAqlAnalyzerOptions
? AqlAnalyzerDescription
: Options extends CreatePipelineAnalyzerOptions
? PipelineAnalyzerDescription
: Options extends CreateStopwordsAnalyzerOptions
? StopwordsAnalyzerDescription
: Options extends CreateCollationAnalyzerOptions
? CollationAnalyzerDescription
: Options extends CreateMinHashAnalyzerOptions
? MinHashAnalyzerDescription
: Options extends CreateClassificationAnalyzerOptions
? ClassificationAnalyzerDescription
: Options extends CreateNearestNeighborsAnalyzerOptions
? NearestNeighborsAnalyzerDescription
: Options extends CreateGeoJsonAnalyzerOptions
? GeoJsonAnalyzerDescription
: Options extends CreateGeoPointAnalyzerOptions
? GeoPointAnalyzerDescription
: Options extends CreateGeoS2AnalyzerOptions
? GeoS2AnalyzerDescription
: AnalyzerDescription
? IdentityAnalyzerDescription
: Options extends CreateDelimiterAnalyzerOptions
? DelimiterAnalyzerDescription
: Options extends CreateStemAnalyzerOptions
? StemAnalyzerDescription
: Options extends CreateNormAnalyzerOptions
? NormAnalyzerDescription
: Options extends CreateNgramAnalyzerOptions
? NgramAnalyzerDescription
: Options extends CreateTextAnalyzerOptions
? TextAnalyzerDescription
: Options extends CreateSegmentationAnalyzerOptions
? SegmentationAnalyzerDescription
: Options extends CreateAqlAnalyzerOptions
? AqlAnalyzerDescription
: Options extends CreatePipelineAnalyzerOptions
? PipelineAnalyzerDescription
: Options extends CreateStopwordsAnalyzerOptions
? StopwordsAnalyzerDescription
: Options extends CreateCollationAnalyzerOptions
? CollationAnalyzerDescription
: Options extends CreateMinHashAnalyzerOptions
? MinHashAnalyzerDescription
: Options extends CreateClassificationAnalyzerOptions
? ClassificationAnalyzerDescription
: Options extends CreateNearestNeighborsAnalyzerOptions
? NearestNeighborsAnalyzerDescription
: Options extends CreateGeoJsonAnalyzerOptions
? GeoJsonAnalyzerDescription
: Options extends CreateGeoPointAnalyzerOptions
? GeoPointAnalyzerDescription
: Options extends CreateGeoS2AnalyzerOptions
? GeoS2AnalyzerDescription
: AnalyzerDescription
> {
return this._db.request({
method: "POST",
Expand Down
63 changes: 35 additions & 28 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,10 @@ export interface DocumentCollection<
EntryResultType extends Record<string, any> = any,
EntryInputType extends Record<string, any> = EntryResultType,
> extends ArangoCollection {
/**
* Database this collection belongs to.
*/
readonly database: Database;
/**
* Checks whether the collection exists.
*
Expand Down Expand Up @@ -1215,7 +1219,7 @@ export interface DocumentCollection<
): Promise<
ArangoApiResponse<
CollectionMetadata &
CollectionProperties & { count: number; figures: Record<string, any> }
CollectionProperties & { count: number; figures: Record<string, any> }
>
>;
/**
Expand Down Expand Up @@ -1550,9 +1554,9 @@ export interface DocumentCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -1622,9 +1626,9 @@ export interface DocumentCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -1694,9 +1698,9 @@ export interface DocumentCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
new?: Document<EntryResultType>;
old?: Document<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -2255,9 +2259,9 @@ export interface EdgeCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -2351,9 +2355,9 @@ export interface EdgeCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -2445,9 +2449,9 @@ export interface EdgeCollection<
): Promise<
Array<
| (DocumentOperationMetadata & {
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
new?: Edge<EntryResultType>;
old?: Edge<EntryResultType>;
})
| DocumentOperationFailure
>
>;
Expand Down Expand Up @@ -2705,13 +2709,12 @@ export interface EdgeCollection<
* @internal
*/
export class Collection<
EntryResultType extends Record<string, any> = any,
EntryInputType extends Record<string, any> = EntryResultType,
>
EntryResultType extends Record<string, any> = any,
EntryInputType extends Record<string, any> = EntryResultType,
>
implements
EdgeCollection<EntryResultType, EntryInputType>,
DocumentCollection<EntryResultType, EntryInputType>
{
EdgeCollection<EntryResultType, EntryInputType>,
DocumentCollection<EntryResultType, EntryInputType> {
//#region attributes
protected _name: string;
protected _db: Database;
Expand All @@ -2730,6 +2733,10 @@ export class Collection<
return true;
}

get database() {
return this._db;
}

get name() {
return this._name;
}
Expand Down Expand Up @@ -2838,9 +2845,9 @@ export class Collection<
details = false
): Promise<
CollectionMetadata &
ArangoApiResponse<
CollectionProperties & { count: number; figures: Record<string, any> }
>
ArangoApiResponse<
CollectionProperties & { count: number; figures: Record<string, any> }
>
> {
return this._db.request({
path: `/_api/collection/${encodeURIComponent(this._name)}/figures`,
Expand Down
14 changes: 14 additions & 0 deletions src/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ export class BatchedArrayCursor<T = any> {
this._nextBatchId = body.nextBatchId;
}

/**
* Database this cursor belongs to.
*/
get database() {
return this._db;
}

/**
* An {@link ArrayCursor} providing item-wise access to the cursor result set.
*
Expand Down Expand Up @@ -769,6 +776,13 @@ export class ArrayCursor<T = any> {
this._view = view;
}

/**
* Database this cursor belongs to.
*/
get database() {
return this._batches.database;
}

/**
* A {@link BatchedArrayCursor} providing batch-wise access to the cursor
* result set.
Expand Down
Loading

0 comments on commit e634738

Please sign in to comment.