arangojs 8.4.1 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/database.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Database = exports.isArangoDatabase = void 0;
3
+ exports.Database = exports.LogLevel = exports.isArangoDatabase = void 0;
4
4
  const analyzer_1 = require("./analyzer");
5
5
  const aql_1 = require("./aql");
6
6
  const collection_1 = require("./collection");
@@ -8,6 +8,7 @@ const connection_1 = require("./connection");
8
8
  const cursor_1 = require("./cursor");
9
9
  const error_1 = require("./error");
10
10
  const graph_1 = require("./graph");
11
+ const job_1 = require("./job");
11
12
  const codes_1 = require("./lib/codes");
12
13
  const multipart_1 = require("./lib/multipart");
13
14
  const route_1 = require("./route");
@@ -58,6 +59,17 @@ function coerceTransactionCollections(collections) {
58
59
  }
59
60
  return cols;
60
61
  }
62
+ /**
63
+ * Numeric representation of the logging level of a log entry.
64
+ */
65
+ var LogLevel;
66
+ (function (LogLevel) {
67
+ LogLevel[LogLevel["FATAL"] = 0] = "FATAL";
68
+ LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
69
+ LogLevel[LogLevel["WARNING"] = 2] = "WARNING";
70
+ LogLevel[LogLevel["INFO"] = 3] = "INFO";
71
+ LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
72
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
61
73
  /**
62
74
  * An object representing a single ArangoDB database. All arangojs collections,
63
75
  * cursors, analyzers and so on are linked to a `Database` object.
@@ -124,6 +136,15 @@ class Database {
124
136
  qs: { details },
125
137
  });
126
138
  }
139
+ /**
140
+ * Retrives the server's current system time in milliseconds with microsecond
141
+ * precision.
142
+ */
143
+ time() {
144
+ return this.request({
145
+ path: "/_admin/time",
146
+ }, (res) => res.body.time * 1000);
147
+ }
127
148
  /**
128
149
  * Returns a new {@link route.Route} instance for the given path (relative to the
129
150
  * database) that can be used to perform arbitrary HTTP requests.
@@ -218,6 +239,15 @@ class Database {
218
239
  close() {
219
240
  this._connection.close();
220
241
  }
242
+ /**
243
+ * Attempts to initiate a clean shutdown of the server.
244
+ */
245
+ shutdown() {
246
+ return this.request({
247
+ method: "DELETE",
248
+ path: "/_admin/shutdown",
249
+ }, () => undefined);
250
+ }
221
251
  async waitForPropagation({ basePath, ...request }, timeout) {
222
252
  await this._connection.waitForPropagation({
223
253
  ...request,
@@ -974,7 +1004,6 @@ class Database {
974
1004
  return analyzers.map((data) => this.analyzer(data.name));
975
1005
  }
976
1006
  //#endregion
977
- //#region users
978
1007
  /**
979
1008
  * Fetches all ArangoDB users visible to the authenticated user and returns
980
1009
  * an array of user objects.
@@ -2107,6 +2136,241 @@ class Database {
2107
2136
  qs: { replace },
2108
2137
  }, () => undefined);
2109
2138
  }
2139
+ //#endregion
2140
+ //#region hot backups
2141
+ /**
2142
+ * (Enterprise Edition only.) Creates a hot backup of the entire ArangoDB
2143
+ * deployment including all databases, collections, etc.
2144
+ *
2145
+ * Returns an object describing the backup result.
2146
+ *
2147
+ * @param options - Options for creating the backup.
2148
+ *
2149
+ * @example
2150
+ * ```js
2151
+ * const info = await db.createHotBackup();
2152
+ * // a hot backup has been created
2153
+ * ```
2154
+ */
2155
+ createHotBackup(options = {}) {
2156
+ return this.request({
2157
+ method: "POST",
2158
+ path: "/_admin/backup/create",
2159
+ body: options,
2160
+ }, (res) => res.body.result);
2161
+ }
2162
+ /**
2163
+ * (Enterprise Edition only.) Retrieves a list of all locally found hot
2164
+ * backups.
2165
+ *
2166
+ * @param id - If specified, only the backup with the given ID will be
2167
+ * returned.
2168
+ *
2169
+ * @example
2170
+ * ```js
2171
+ * const backups = await db.listHotBackups();
2172
+ * for (const backup of backups) {
2173
+ * console.log(backup.id);
2174
+ * }
2175
+ * ```
2176
+ */
2177
+ listHotBackups(id) {
2178
+ return this.request({
2179
+ method: "POST",
2180
+ path: "/_admin/backup/list",
2181
+ body: id ? { id } : undefined,
2182
+ }, (res) => res.body.result);
2183
+ }
2184
+ /**
2185
+ * (Enteprise Edition only.) Restores a consistent local hot backup.
2186
+ *
2187
+ * Returns the directory path of the restored backup.
2188
+ *
2189
+ * @param id - The ID of the backup to restore.
2190
+ *
2191
+ * @example
2192
+ * ```js
2193
+ * await db.restoreHotBackup("2023-09-19T15.38.21Z_example");
2194
+ * // the backup has been restored
2195
+ * ```
2196
+ */
2197
+ restoreHotBackup(id) {
2198
+ return this.request({
2199
+ method: "POST",
2200
+ path: "/_admin/backup/restore",
2201
+ body: { id },
2202
+ }, (res) => res.body.result.previous);
2203
+ }
2204
+ /**
2205
+ * (Enterprise Edition only.) Deletes a local hot backup.
2206
+ *
2207
+ * @param id - The ID of the backup to delete.
2208
+ *
2209
+ * @example
2210
+ * ```js
2211
+ * await db.deleteHotBackup("2023-09-19T15.38.21Z_example");
2212
+ * // the backup has been deleted
2213
+ * ```
2214
+ */
2215
+ deleteHotBackup(id) {
2216
+ return this.request({
2217
+ method: "POST",
2218
+ path: "/_admin/backup/delete",
2219
+ body: { id },
2220
+ }, () => undefined);
2221
+ }
2222
+ //#endregion
2223
+ //#region logs
2224
+ /**
2225
+ * Retrieves the log messages from the server's global log.
2226
+ *
2227
+ * @param options - Options for retrieving the log entries.
2228
+ *
2229
+ * @example
2230
+ * ```js
2231
+ * const log = await db.getLogEntries();
2232
+ * for (let i = 0; i < log.totalAmount; i++) {
2233
+ * console.log(`${
2234
+ * new Date(log.timestamp[i] * 1000).toISOString()
2235
+ * } - [${LogLevel[log.level[i]]}] ${log.text[i]} (#${log.lid[i]})`);
2236
+ * }
2237
+ * ```
2238
+ */
2239
+ getLogEntries(options) {
2240
+ return this.request({
2241
+ path: "/_admin/log",
2242
+ qs: options,
2243
+ }, (res) => res.body);
2244
+ }
2245
+ /**
2246
+ * Retrieves the log messages from the server's global log.
2247
+ *
2248
+ * @param options - Options for retrieving the log entries.
2249
+ *
2250
+ * @example
2251
+ * ```js
2252
+ * const messages = await db.getLogMessages();
2253
+ * for (const m of messages) {
2254
+ * console.log(`${m.date} - [${m.level}] ${m.message} (#${m.id})`);
2255
+ * }
2256
+ * ```
2257
+ */
2258
+ getLogMessages(options) {
2259
+ return this.request({
2260
+ path: "/_admin/log",
2261
+ qs: options,
2262
+ }, (res) => res.body.messages);
2263
+ }
2264
+ /**
2265
+ * Retrieves the server's current log level for each topic.
2266
+ *
2267
+ * @example
2268
+ * ```js
2269
+ * const levels = await db.getLogLevel();
2270
+ * console.log(levels.request); // log level for incoming requests
2271
+ * ```
2272
+ */
2273
+ getLogLevel() {
2274
+ return this.request({
2275
+ path: "/_admin/log/level",
2276
+ });
2277
+ }
2278
+ /**
2279
+ * Sets the server's log level for each of the given topics to the given level.
2280
+ *
2281
+ * Any omitted topics will be left unchanged.
2282
+ *
2283
+ * @param levels - An object mapping topic names to log levels.
2284
+ *
2285
+ * @example
2286
+ * ```js
2287
+ * await db.setLogLevel({ request: "debug" });
2288
+ * // Debug information will now be logged for each request
2289
+ * ```
2290
+ */
2291
+ setLogLevel(levels) {
2292
+ return this.request({
2293
+ method: "PUT",
2294
+ path: "/_admin/log/level",
2295
+ body: levels,
2296
+ });
2297
+ }
2298
+ //#endregion
2299
+ //#region async jobs
2300
+ /**
2301
+ * Returns a {@link job.Job} instance for the given `jobId`.
2302
+ *
2303
+ * @param jobId - ID of the async job.
2304
+ *
2305
+ * @example
2306
+ * ```js
2307
+ * const db = new Database();
2308
+ * const job = db.job("12345");
2309
+ * ```
2310
+ */
2311
+ job(jobId) {
2312
+ return new job_1.Job(this, jobId);
2313
+ }
2314
+ /**
2315
+ * Returns a list of the IDs of all currently pending async jobs.
2316
+ *
2317
+ * @example
2318
+ * ```js
2319
+ * const db = new Database();
2320
+ * const pendingJobs = await db.listPendingJobs();
2321
+ * console.log(pendingJobs); // e.g. ["12345", "67890"]
2322
+ * ```
2323
+ */
2324
+ listPendingJobs() {
2325
+ return this.request({
2326
+ path: "/_api/job/pending",
2327
+ }, (res) => res.body);
2328
+ }
2329
+ /**
2330
+ * Returns a list of the IDs of all currently available completed async jobs.
2331
+ *
2332
+ * @example
2333
+ * ```js
2334
+ * const db = new Database();
2335
+ * const completedJobs = await db.listCompletedJobs();
2336
+ * console.log(completedJobs); // e.g. ["12345", "67890"]
2337
+ * ```
2338
+ */
2339
+ listCompletedJobs() {
2340
+ return this.request({
2341
+ path: "/_api/job/done",
2342
+ }, (res) => res.body);
2343
+ }
2344
+ /**
2345
+ * Deletes the results of all completed async jobs created before the given
2346
+ * threshold.
2347
+ *
2348
+ * @param threshold - The expiration timestamp in milliseconds.
2349
+ *
2350
+ * @example
2351
+ * ```js
2352
+ * const db = new Database();
2353
+ * const ONE_WEEK = 7 * 24 * 60 * 60 * 1000;
2354
+ * await db.deleteExpiredJobResults(Date.now() - ONE_WEEK);
2355
+ * // all job results older than a week have been deleted
2356
+ * ```
2357
+ */
2358
+ deleteExpiredJobResults(threshold) {
2359
+ return this.request({
2360
+ method: "DELETE",
2361
+ path: `/_api/job/expired`,
2362
+ qs: { stamp: threshold / 1000 },
2363
+ }, () => undefined);
2364
+ }
2365
+ /**
2366
+ * Deletes the results of all completed async jobs.
2367
+ */
2368
+ deleteAllJobResults() {
2369
+ return this.request({
2370
+ method: "DELETE",
2371
+ path: `/_api/job/all`,
2372
+ }, () => undefined);
2373
+ }
2110
2374
  }
2111
2375
  exports.Database = Database;
2112
2376
  //# sourceMappingURL=database.js.map