forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.js
More file actions
217 lines (217 loc) · 5.73 KB
/
Copy pathview.js
File metadata and controls
217 lines (217 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.View = exports.isArangoView = exports.ViewType = void 0;
const error_1 = require("./error");
const codes_1 = require("./lib/codes");
/**
* String values indicating the View type.
*/
var ViewType;
(function (ViewType) {
ViewType["ARANGOSEARCH_VIEW"] = "arangosearch";
})(ViewType = exports.ViewType || (exports.ViewType = {}));
/**
* Indicates whether the given value represents a {@link View}.
*
* @param view - A value that might be a View.
*/
function isArangoView(view) {
return Boolean(view && view.isArangoView);
}
exports.isArangoView = isArangoView;
/**
* Represents a View in a {@link Database}.
*
* See {@link ArangoSearchView} for the concrete type representing an
* ArangoSearch View.
*/
class View {
/**
* @internal
* @hidden
*/
constructor(db, name) {
this._db = db;
this._name = name;
}
/**
* @internal
*
* Indicates that this object represents an ArangoDB View.
*/
get isArangoView() {
return true;
}
/**
* Name of the View.
*/
get name() {
return this._name;
}
/**
* Retrieves general information about the View.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("some-view");
* const data = await view.get();
* // data contains general information about the View
* ```
*/
get() {
return this._db.request({ path: `/_api/view/${this.name}` }, (res) => res.body);
}
/**
* Checks whether the View exists.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("some-view");
* const exists = await view.exists();
* console.log(exists); // indicates whether the View exists
* ```
*/
async exists() {
try {
await this.get();
return true;
}
catch (err) {
if (error_1.isArangoError(err) && err.errorNum === codes_1.VIEW_NOT_FOUND) {
return false;
}
throw err;
}
}
/**
* Creates a View with the given `options` and the instance's name.
*
* See also {@link Database.createView}.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("potatoes");
* await view.create();
* // the ArangoSearch View "potatoes" now exists
* ```
*/
create(options) {
return this._db.request({
method: "POST",
path: "/_api/view",
body: {
type: ViewType.ARANGOSEARCH_VIEW,
...(options || {}),
name: this.name,
},
}, (res) => res.body);
}
/**
* Renames the View and updates the instance's `name` to `newName`.
*
* Additionally removes the instance from the {@link Database}'s internal
* cache.
*
* **Note**: Renaming Views may not be supported when ArangoDB is
* running in a cluster configuration.
*
* @param newName - The new name of the View.
*
* @example
* ```js
* const db = new Database();
* const view1 = db.view("some-view");
* await view1.rename("other-view");
* const view2 = db.view("some-view");
* const view3 = db.view("other-view");
* // Note all three View instances are different objects but
* // view1 and view3 represent the same ArangoDB view!
* ```
*/
async rename(newName) {
const result = this._db.renameView(this._name, newName);
this._name = newName;
return result;
}
/**
* Retrieves the View's properties.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("some-view");
* const data = await view.properties();
* // data contains the View's properties
* ```
*/
properties() {
return this._db.request({ path: `/_api/view/${this.name}/properties` }, (res) => res.body);
}
/**
* Updates the properties of the View.
*
* @param properties - Properties of the View to update.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("some-view");
* const result = await view.updateProperties({
* consolidationIntervalMsec: 234
* });
* console.log(result.consolidationIntervalMsec); // 234
* ```
*/
updateProperties(properties) {
return this._db.request({
method: "PATCH",
path: `/_api/view/${this.name}/properties`,
body: properties || {},
}, (res) => res.body);
}
/**
* Replaces the properties of the View.
*
* @param properties - New properties of the View.
*
* @example
* ```js
* const db = new Database();
* const view = db.view("some-view");
* const result = await view.replaceProperties({
* consolidationIntervalMsec: 234
* });
* console.log(result.consolidationIntervalMsec); // 234
* ```
*/
replaceProperties(properties) {
return this._db.request({
method: "PUT",
path: `/_api/view/${this.name}/properties`,
body: properties || {},
}, (res) => res.body);
}
/**
* Deletes the View from the database.
*
* @example
*
* ```js
* const db = new Database();
* const view = db.view("some-view");
* await view.drop();
* // the View "some-view" no longer exists
* ```
*/
drop() {
return this._db.request({
method: "DELETE",
path: `/_api/view/${this.name}`,
}, (res) => res.body.result);
}
}
exports.View = View;
//# sourceMappingURL=view.js.map