Skip to content

Commit f06d1fa

Browse files
chrolivierpluma
authored andcommitted
Tightened up types on graph collection operations (#625)
1 parent 90afbd4 commit f06d1fa

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/graph.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ import {
1111
import { Connection } from "./connection";
1212
import { isArangoError } from "./error";
1313

14+
export interface InsertOptions {
15+
waitForSync?: boolean;
16+
returnNew?: boolean;
17+
}
18+
19+
export interface ReplaceOptions extends InsertOptions {
20+
waitForSync?: boolean;
21+
keepNull?: boolean;
22+
returnOld?: boolean;
23+
returnNew?: boolean;
24+
rev?: string;
25+
}
26+
27+
export interface RemoveOptions {
28+
waitForSync?: boolean;
29+
returnOld?: boolean;
30+
rev?: string;
31+
}
32+
33+
export interface UpdateOptions extends ReplaceOptions {}
34+
1435
export class GraphVertexCollection extends BaseCollection {
1536
type = CollectionType.DOCUMENT_COLLECTION;
1637

@@ -67,7 +88,7 @@ export class GraphVertexCollection extends BaseCollection {
6788
return this.document(documentHandle, opts);
6889
}
6990

70-
save(data: Object | Array<Object>, opts?: { waitForSync?: boolean }) {
91+
save(data: Object | Array<Object>, opts?: InsertOptions) {
7192
return this._connection.request(
7293
{
7394
method: "POST",
@@ -82,7 +103,7 @@ export class GraphVertexCollection extends BaseCollection {
82103
replace(
83104
documentHandle: DocumentHandle,
84105
newValue: Object | Array<Object>,
85-
opts: any = {}
106+
opts: ReplaceOptions | string = {}
86107
) {
87108
const headers: { [key: string]: string } = {};
88109
if (typeof opts === "string") {
@@ -110,7 +131,7 @@ export class GraphVertexCollection extends BaseCollection {
110131
update(
111132
documentHandle: DocumentHandle,
112133
newValue: Object | Array<Object>,
113-
opts: any = {}
134+
opts: UpdateOptions | string = {}
114135
) {
115136
const headers: { [key: string]: string } = {};
116137
if (typeof opts === "string") {
@@ -135,7 +156,7 @@ export class GraphVertexCollection extends BaseCollection {
135156
);
136157
}
137158

138-
remove(documentHandle: DocumentHandle, opts: any = {}) {
159+
remove(documentHandle: DocumentHandle, opts: RemoveOptions | string = {}) {
139160
const headers: { [key: string]: string } = {};
140161
if (typeof opts === "string") {
141162
opts = { rev: opts };
@@ -203,19 +224,19 @@ export class GraphEdgeCollection extends EdgeCollection {
203224

204225
save(
205226
data: Object | Array<Object>,
206-
opts?: { waitForSync?: boolean }
227+
opts?: InsertOptions
207228
): Promise<any>;
208229
save(
209230
data: Object | Array<Object>,
210231
fromId: DocumentHandle,
211232
toId: DocumentHandle,
212-
opts?: { waitForSync?: boolean }
233+
opts?: InsertOptions
213234
): Promise<any>;
214235
save(
215236
data: Object | Array<Object>,
216-
fromIdOrOpts?: DocumentHandle | { waitForSync?: boolean },
237+
fromIdOrOpts?: DocumentHandle | InsertOptions,
217238
toId?: DocumentHandle,
218-
opts?: { waitForSync?: boolean }
239+
opts?: InsertOptions
219240
) {
220241
if (toId !== undefined) {
221242
const fromId = this._documentHandle(fromIdOrOpts as DocumentHandle);
@@ -227,7 +248,7 @@ export class GraphEdgeCollection extends EdgeCollection {
227248
}
228249
} else {
229250
if (fromIdOrOpts !== undefined) {
230-
opts = fromIdOrOpts as { waitForSync?: boolean };
251+
opts = fromIdOrOpts as InsertOptions;
231252
}
232253
}
233254
return this._connection.request(
@@ -244,7 +265,7 @@ export class GraphEdgeCollection extends EdgeCollection {
244265
replace(
245266
documentHandle: DocumentHandle,
246267
newValue: Object | Array<Object>,
247-
opts: any = {}
268+
opts: ReplaceOptions | string = {}
248269
) {
249270
const headers: { [key: string]: string } = {};
250271
if (typeof opts === "string") {
@@ -272,7 +293,7 @@ export class GraphEdgeCollection extends EdgeCollection {
272293
update(
273294
documentHandle: DocumentHandle,
274295
newValue: Object | Array<Object>,
275-
opts: any = {}
296+
opts: UpdateOptions | string = {}
276297
) {
277298
const headers: { [key: string]: string } = {};
278299
if (typeof opts === "string") {
@@ -297,7 +318,7 @@ export class GraphEdgeCollection extends EdgeCollection {
297318
);
298319
}
299320

300-
remove(documentHandle: DocumentHandle, opts: any = {}) {
321+
remove(documentHandle: DocumentHandle, opts: RemoveOptions | string = {}) {
301322
const headers: { [key: string]: string } = {};
302323
if (typeof opts === "string") {
303324
opts = { rev: opts };

0 commit comments

Comments
 (0)