Skip to content

Commit 072cef7

Browse files
author
Alan Plum
committed
Implement search-alias view
1 parent 6dac3d6 commit 072cef7

File tree

8 files changed

+275
-213
lines changed

8 files changed

+275
-213
lines changed

CHANGELOG.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ This driver uses semantic versioning:
7373

7474
This attribute has been replaced with `response.arangojsHostUrl`.
7575

76+
- Removed `CollectionStatus` and `CollectionType` enum re-exports
77+
78+
Previously these would be re-exported by the arangojs module for backwards
79+
compatibility. If you still need to access these enums, you can import them
80+
from the `collection` sub-module instead. Note that the `ViewType` enum
81+
has been removed completely.
82+
7683
### Changed
7784

7885
- Changed default URL to `http://127.0.0.1:8529` to match ArangoDB default
@@ -164,16 +171,21 @@ This driver uses semantic versioning:
164171

165172
- Renamed type `PrimarySortCompression` to `Compression`
166173

167-
- Changed generic type `View` to take additional `CreateOptions` type argument
168-
169-
- Replaced `AnalyzerInfo` type and all its constituent types
174+
- Replaced type `AnalyzerInfo` and all its constituent types
170175

171176
Previously each type of Analyzer was represented by an `AnalyzerInfo` type
172177
and (where relevant) an `AnalyzerProperties` type, which were used for both
173178
creating and fetching Analyzers. The new types more closely follow the
174179
pattern already used for index types, providing pairs of
175180
`CreateAnalyzerOptions` and `AnalyzerDescription` types.
176181

182+
- Removed enum `ViewType`, type `ArangoSearchView` and changed `View` class to
183+
be non-generic
184+
185+
The `View` class now behaves analogous to the `Analyzer` class. The various
186+
types related to different view types have been restructured to more closely
187+
follow the pattern used for indexes and analyzers.
188+
177189
### Deprecated
178190

179191
- Deprecated `EnsureFulltextIndexOptions` and `FulltextIndex` types

src/analyzer.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,43 @@ export class Analyzer {
864864
* // the identity Analyzer "potatoes" now exists
865865
* ```
866866
*/
867-
create(options: CreateAnalyzerOptions): Promise<AnalyzerDescription> {
867+
create<Options extends CreateAnalyzerOptions>(
868+
options: Options
869+
): Promise<
870+
Options extends CreateIdentityAnalyzerOptions
871+
? IdentityAnalyzerDescription
872+
: Options extends CreateDelimiterAnalyzerOptions
873+
? DelimiterAnalyzerDescription
874+
: Options extends CreateStemAnalyzerOptions
875+
? StemAnalyzerDescription
876+
: Options extends CreateNormAnalyzerOptions
877+
? NormAnalyzerDescription
878+
: Options extends CreateNgramAnalyzerOptions
879+
? NgramAnalyzerDescription
880+
: Options extends CreateTextAnalyzerOptions
881+
? TextAnalyzerDescription
882+
: Options extends CreateSegmentationAnalyzerOptions
883+
? SegmentationAnalyzerDescription
884+
: Options extends CreateAqlAnalyzerOptions
885+
? AqlAnalyzerDescription
886+
: Options extends CreatePipelineAnalyzerOptions
887+
? PipelineAnalyzerDescription
888+
: Options extends CreateStopwordsAnalyzerOptions
889+
? StopwordsAnalyzerDescription
890+
: Options extends CreateCollationAnalyzerOptions
891+
? CollationAnalyzerDescription
892+
: Options extends CreateMinHashAnalyzerOptions
893+
? MinHashAnalyzerDescription
894+
: Options extends CreateClassificationAnalyzerOptions
895+
? ClassificationAnalyzerDescription
896+
: Options extends CreateNearestNeighborsAnalyzerOptions
897+
? NearestNeighborsAnalyzerDescription
898+
: Options extends CreateGeoJsonAnalyzerOptions
899+
? GeoJsonAnalyzerDescription
900+
: Options extends CreateGeoPointAnalyzerOptions
901+
? GeoPointAnalyzerDescription
902+
: AnalyzerDescription
903+
> {
868904
return this._db.request({
869905
method: "POST",
870906
path: "/_api/analyzer",

src/database.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ import { toForm } from "./lib/multipart";
5050
import { ArangojsResponse } from "./lib/request";
5151
import { Route } from "./route";
5252
import { Transaction } from "./transaction";
53-
import {
54-
ArangoSearchView,
55-
ArangoSearchViewPropertiesOptions,
56-
View,
57-
ViewDescription,
58-
ViewType,
59-
} from "./view";
53+
import { CreateViewOptions, View, ViewDescription } from "./view";
6054

6155
/**
6256
* Indicates whether the given value represents a {@link Database}.
@@ -1428,7 +1422,7 @@ export class Database {
14281422
protected _analyzers = new Map<string, Analyzer>();
14291423
protected _collections = new Map<string, Collection>();
14301424
protected _graphs = new Map<string, Graph>();
1431-
protected _views = new Map<string, ArangoSearchView>();
1425+
protected _views = new Map<string, View>();
14321426

14331427
/**
14341428
* Creates a new `Database` instance with its own connection pool.
@@ -2344,17 +2338,17 @@ export class Database {
23442338

23452339
//#region views
23462340
/**
2347-
* Returns an {@link view.ArangoSearchView} instance for the given `viewName`.
2341+
* Returns a {@link view.View} instance for the given `viewName`.
23482342
*
2349-
* @param viewName - Name of the ArangoSearch View.
2343+
* @param viewName - Name of the ArangoSearch or SearchAlias View.
23502344
*
23512345
* @example
23522346
* ```js
23532347
* const db = new Database();
23542348
* const view = db.view("potatoes");
23552349
* ```
23562350
*/
2357-
view(viewName: string): ArangoSearchView {
2351+
view(viewName: string): View {
23582352
viewName = viewName.normalize("NFC");
23592353
if (!this._views.has(viewName)) {
23602354
this._views.set(viewName, new View(this, viewName));
@@ -2363,25 +2357,25 @@ export class Database {
23632357
}
23642358

23652359
/**
2366-
* Creates a new ArangoSearch View with the given `viewName` and `options`
2367-
* and returns an {@link view.ArangoSearchView} instance for the created View.
2360+
* Creates a new View with the given `viewName` and `options`, then returns a
2361+
* {@link view.View} instance for the new View.
23682362
*
2369-
* @param viewName - Name of the ArangoSearch View.
2363+
* @param viewName - Name of the View.
23702364
* @param options - An object defining the properties of the View.
23712365
*
23722366
* @example
23732367
* ```js
23742368
* const db = new Database();
2375-
* const view = await db.createView("potatoes");
2369+
* const view = await db.createView("potatoes", { type: "arangosearch" });
23762370
* // the ArangoSearch View "potatoes" now exists
23772371
* ```
23782372
*/
23792373
async createView(
23802374
viewName: string,
2381-
options?: ArangoSearchViewPropertiesOptions
2382-
): Promise<ArangoSearchView> {
2375+
options: CreateViewOptions
2376+
): Promise<View> {
23832377
const view = this.view(viewName.normalize("NFC"));
2384-
await view.create({ ...options, type: ViewType.ARANGOSEARCH_VIEW });
2378+
await view.create(options);
23852379
return view;
23862380
}
23872381

@@ -2431,7 +2425,8 @@ export class Database {
24312425

24322426
/**
24332427
* Fetches all Views from the database and returns an array of
2434-
* {@link view.ArangoSearchView} instances for the Views.
2428+
* {@link view.View} instances
2429+
* for the Views.
24352430
*
24362431
* See also {@link Database#listViews}.
24372432
*
@@ -2442,7 +2437,7 @@ export class Database {
24422437
* // views is an array of ArangoSearch View instances
24432438
* ```
24442439
*/
2445-
async views(): Promise<ArangoSearchView[]> {
2440+
async views(): Promise<View[]> {
24462441
const views = await this.listViews();
24472442
return views.map((data) => this.view(data.name));
24482443
}

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ export function arangojs(config?: string | string[] | Config, name?: string) {
5757
}
5858
export default arangojs;
5959
export { aql } from "./aql";
60-
export { CollectionStatus, CollectionType } from "./collection";
6160
export { Database } from "./database";
62-
export { ViewType } from "./view";

src/test/24-accessing-views.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("Accessing views", function () {
3535
await Promise.all(
3636
viewNames.map(async (name) => {
3737
const view = db.view(name);
38-
await view.create();
38+
await view.create({ type: "arangosearch" });
3939
await db.waitForPropagation(
4040
{ path: `/_api/view/${view.name}` },
4141
10000
@@ -58,7 +58,7 @@ describe("Accessing views", function () {
5858
await Promise.all(
5959
arangoSearchViewNames.map(async (name) => {
6060
const view = db.view(name);
61-
await view.create();
61+
await view.create({ type: "arangosearch" });
6262
await db.waitForPropagation(
6363
{ path: `/_api/view/${view.name}` },
6464
10000

src/test/25-view-metadata.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { expect } from "chai";
22
import { Database } from "../database";
3-
import { ArangoSearchView } from "../view";
3+
import { ArangoSearchViewProperties, View } from "../view";
44
import { config } from "./_config";
55

66
describe("View metadata", function () {
77
const dbName = `testdb_${Date.now()}`;
88
const viewName = `view-${Date.now()}`;
99
let system: Database, db: Database;
10-
let view: ArangoSearchView;
10+
let view: View;
1111
before(async () => {
1212
system = new Database(config);
1313
if (Array.isArray(config.url) && config.loadBalancingStrategy !== "NONE")
1414
await system.acquireHostList();
1515
await system.createDatabase(dbName);
1616
db = system.database(dbName);
1717
view = db.view(viewName);
18-
await view.create();
18+
await view.create({ type: "arangosearch" });
1919
await db.waitForPropagation({ path: `/_api/view/${view.name}` }, 10000);
2020
});
2121
after(async () => {
@@ -40,7 +40,8 @@ describe("View metadata", function () {
4040
});
4141
describe("view.properties", () => {
4242
it("should return properties of a view", async () => {
43-
const properties = await view.properties();
43+
const properties =
44+
(await view.properties()) as ArangoSearchViewProperties;
4445
expect(properties).to.have.property("name", viewName);
4546
expect(properties).to.have.property("id");
4647
expect(properties).to.have.property("type", "arangosearch");

src/test/26-manipulating-views.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import { Database } from "../database";
3-
import { ArangoSearchView } from "../view";
3+
import { ArangoSearchViewProperties, View } from "../view";
44
import { config } from "./_config";
55

66
// NOTE These tests will not reliably work in a cluster.
@@ -10,7 +10,7 @@ const describeNLB =
1010
describe("Manipulating views", function () {
1111
const name = `testdb_${Date.now()}`;
1212
let system: Database, db: Database;
13-
let view: ArangoSearchView;
13+
let view: View;
1414
before(async () => {
1515
system = new Database(config);
1616
if (Array.isArray(config.url) && config.loadBalancingStrategy !== "NONE")
@@ -26,7 +26,7 @@ describe("Manipulating views", function () {
2626
});
2727
beforeEach(async () => {
2828
view = db.view(`v-${Date.now()}`);
29-
await view.create();
29+
await view.create({ type: "arangosearch" });
3030
await db.waitForPropagation({ path: `/_api/view/${view.name}` }, 10000);
3131
});
3232
afterEach(async () => {
@@ -40,7 +40,7 @@ describe("Manipulating views", function () {
4040
describe("view.create", () => {
4141
it("creates a new arangosearch view", async () => {
4242
const view = db.view(`asv-${Date.now()}`);
43-
await view.create();
43+
await view.create({ type: "arangosearch" });
4444
await db.waitForPropagation({ path: `/_api/view/${view.name}` }, 10000);
4545
const info = await view.get();
4646
expect(info).to.have.property("name", view.name);
@@ -49,7 +49,7 @@ describe("Manipulating views", function () {
4949
});
5050
describe("view.updateProperties", () => {
5151
it("should not overwrite properties", async () => {
52-
const initial = await view.properties();
52+
const initial = (await view.properties()) as ArangoSearchViewProperties;
5353
expect(initial.consolidationIntervalMsec).not.to.equal(45000);
5454
const oldProps = await view.updateProperties({
5555
consolidationIntervalMsec: 45000,
@@ -65,7 +65,7 @@ describe("Manipulating views", function () {
6565
});
6666
describe("view.replaceProperties", () => {
6767
it("should overwrite properties", async () => {
68-
const initial = await view.properties();
68+
const initial = (await view.properties()) as ArangoSearchViewProperties;
6969
expect(initial.consolidationIntervalMsec).not.to.equal(45000);
7070
const oldProps = await view.replaceProperties({
7171
consolidationIntervalMsec: 45000,

0 commit comments

Comments
 (0)