arangojs 7.6.0 → 7.8.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
@@ -77,7 +77,7 @@ class Database {
77
77
  this._views = new Map();
78
78
  if (isArangoDatabase(configOrDatabase)) {
79
79
  const connection = configOrDatabase._connection;
80
- const databaseName = name || configOrDatabase.name;
80
+ const databaseName = (name || configOrDatabase.name).normalize("NFC");
81
81
  this._connection = connection;
82
82
  this._name = databaseName;
83
83
  const database = connection.database(databaseName);
@@ -90,7 +90,7 @@ class Database {
90
90
  ? { databaseName: name, url: config }
91
91
  : config;
92
92
  this._connection = new connection_1.Connection(options);
93
- this._name = databaseName || "_system";
93
+ this._name = (databaseName === null || databaseName === void 0 ? void 0 : databaseName.normalize("NFC")) || "_system";
94
94
  }
95
95
  }
96
96
  //#region misc
@@ -158,7 +158,7 @@ class Database {
158
158
  }
159
159
  request({ absolutePath = false, basePath, ...opts }, transform) {
160
160
  if (!absolutePath) {
161
- basePath = `/_db/${this.name}${basePath || ""}`;
161
+ basePath = `/_db/${encodeURIComponent(this._name)}${basePath || ""}`;
162
162
  }
163
163
  return this._connection.request({ basePath, ...opts }, transform);
164
164
  }
@@ -218,7 +218,27 @@ class Database {
218
218
  this._connection.close();
219
219
  }
220
220
  async waitForPropagation({ basePath, ...request }, timeout) {
221
- await this._connection.waitForPropagation({ ...request, basePath: `/_db/${this.name}${basePath || ""}` }, timeout);
221
+ await this._connection.waitForPropagation({
222
+ ...request,
223
+ basePath: `/_db/${encodeURIComponent(this._name)}${basePath || ""}`,
224
+ }, timeout);
225
+ }
226
+ /**
227
+ * Methods for accessing the server-reported queue times of the mostly
228
+ * recently received responses.
229
+ */
230
+ get queueTime() {
231
+ return this._connection.queueTime;
232
+ }
233
+ /**
234
+ * Sets the limit for the number of values of the most recently received
235
+ * server-reported queue times that can be accessed using
236
+ * {@link Database.queueTime}.
237
+ *
238
+ * @param responseQueueTimeSamples - Number of values to maintain.
239
+ */
240
+ setResponseQueueTimeSamples(responseQueueTimeSamples) {
241
+ this._connection.setResponseQueueTimeSamples(responseQueueTimeSamples);
222
242
  }
223
243
  //#endregion
224
244
  //#region auth
@@ -243,7 +263,7 @@ class Database {
243
263
  */
244
264
  useDatabase(databaseName) {
245
265
  this._connection.database(this._name, null);
246
- this._name = databaseName;
266
+ this._name = databaseName.normalize("NFC");
247
267
  return this;
248
268
  }
249
269
  /**
@@ -328,8 +348,7 @@ class Database {
328
348
  * ```
329
349
  */
330
350
  database(databaseName) {
331
- const db = new Database(this, databaseName);
332
- return db;
351
+ return new Database(this, databaseName);
333
352
  }
334
353
  /**
335
354
  * Fetches the database description for the active database from the server.
@@ -373,7 +392,7 @@ class Database {
373
392
  return this.request({
374
393
  method: "POST",
375
394
  path: "/_api/database",
376
- body: { name: databaseName, users, options },
395
+ body: { name: databaseName.normalize("NFC"), users, options },
377
396
  }, () => this.database(databaseName));
378
397
  }
379
398
  /**
@@ -456,9 +475,10 @@ class Database {
456
475
  * ```
457
476
  */
458
477
  dropDatabase(databaseName) {
478
+ databaseName = databaseName.normalize("NFC");
459
479
  return this.request({
460
480
  method: "DELETE",
461
- path: `/_api/database/${databaseName}`,
481
+ path: `/_api/database/${encodeURIComponent(databaseName)}`,
462
482
  }, (res) => res.body.result);
463
483
  }
464
484
  //#endregion
@@ -503,6 +523,7 @@ class Database {
503
523
  * ```
504
524
  */
505
525
  collection(collectionName) {
526
+ collectionName = collectionName.normalize("NFC");
506
527
  if (!this._collections.has(collectionName)) {
507
528
  this._collections.set(collectionName, new collection_1.Collection(this, collectionName));
508
529
  }
@@ -560,10 +581,11 @@ class Database {
560
581
  * @param newName - The new name of the collection.
561
582
  */
562
583
  async renameCollection(collectionName, newName) {
584
+ collectionName = collectionName.normalize("NFC");
563
585
  const result = await this.request({
564
586
  method: "PUT",
565
- path: `/_api/collection/${collectionName}/rename`,
566
- body: { name: newName },
587
+ path: `/_api/collection/${encodeURIComponent(collectionName)}/rename`,
588
+ body: { name: newName.normalize("NFC") },
567
589
  }, (res) => res.body);
568
590
  this._collections.delete(collectionName);
569
591
  return result;
@@ -647,6 +669,7 @@ class Database {
647
669
  * ```
648
670
  */
649
671
  graph(graphName) {
672
+ graphName = graphName.normalize("NFC");
650
673
  if (!this._graphs.has(graphName)) {
651
674
  this._graphs.set(graphName, new graph_1.Graph(this, graphName));
652
675
  }
@@ -661,7 +684,7 @@ class Database {
661
684
  * @param options - An object defining the properties of the graph.
662
685
  */
663
686
  async createGraph(graphName, edgeDefinitions, options) {
664
- const graph = this.graph(graphName);
687
+ const graph = this.graph(graphName.normalize("NFC"));
665
688
  await graph.create(edgeDefinitions, options);
666
689
  return graph;
667
690
  }
@@ -712,6 +735,7 @@ class Database {
712
735
  * ```
713
736
  */
714
737
  view(viewName) {
738
+ viewName = viewName.normalize("NFC");
715
739
  if (!this._views.has(viewName)) {
716
740
  this._views.set(viewName, new view_1.View(this, viewName));
717
741
  }
@@ -732,7 +756,7 @@ class Database {
732
756
  * ```
733
757
  */
734
758
  async createView(viewName, options) {
735
- const view = this.view(viewName);
759
+ const view = this.view(viewName.normalize("NFC"));
736
760
  await view.create({ ...options, type: view_1.ViewType.ARANGOSEARCH_VIEW });
737
761
  return view;
738
762
  }
@@ -749,10 +773,11 @@ class Database {
749
773
  * @param newName - The new name of the view.
750
774
  */
751
775
  async renameView(viewName, newName) {
776
+ viewName = viewName.normalize("NFC");
752
777
  const result = await this.request({
753
778
  method: "PUT",
754
- path: `/_api/view/${viewName}/rename`,
755
- body: { name: newName },
779
+ path: `/_api/view/${encodeURIComponent(viewName)}/rename`,
780
+ body: { name: newName.normalize("NFC") },
756
781
  }, (res) => res.body);
757
782
  this._views.delete(viewName);
758
783
  return result;
@@ -805,6 +830,7 @@ class Database {
805
830
  * ```
806
831
  */
807
832
  analyzer(analyzerName) {
833
+ analyzerName = analyzerName.normalize("NFC");
808
834
  if (!this._analyzers.has(analyzerName)) {
809
835
  this._analyzers.set(analyzerName, new analyzer_1.Analyzer(this, analyzerName));
810
836
  }
@@ -896,7 +922,7 @@ class Database {
896
922
  getUser(username) {
897
923
  return this.request({
898
924
  absolutePath: true,
899
- path: `/_api/user/${username}`,
925
+ path: `/_api/user/${encodeURIComponent(username)}`,
900
926
  });
901
927
  }
902
928
  createUser(username, options) {
@@ -917,7 +943,7 @@ class Database {
917
943
  return this.request({
918
944
  absolutePath: true,
919
945
  method: "PATCH",
920
- path: `/api/user/${username}`,
946
+ path: `/api/user/${encodeURIComponent(username)}`,
921
947
  body: options,
922
948
  }, (res) => res.body);
923
949
  }
@@ -941,7 +967,7 @@ class Database {
941
967
  return this.request({
942
968
  absolutePath: true,
943
969
  method: "PUT",
944
- path: `/api/user/${username}`,
970
+ path: `/api/user/${encodeURIComponent(username)}`,
945
971
  body: options,
946
972
  }, (res) => res.body);
947
973
  }
@@ -961,7 +987,7 @@ class Database {
961
987
  return this.request({
962
988
  absolutePath: true,
963
989
  method: "DELETE",
964
- path: `/_api/user/${username}`,
990
+ path: `/_api/user/${encodeURIComponent(username)}`,
965
991
  }, (res) => res.body);
966
992
  }
967
993
  /**
@@ -1031,19 +1057,23 @@ class Database {
1031
1057
  * });
1032
1058
  * // The access level of the user "steve" has been fetched for the
1033
1059
  * // "pokemons" collection in database "staging".
1060
+ * ```
1034
1061
  */
1035
1062
  getUserAccessLevel(username, { database, collection }) {
1063
+ var _a;
1036
1064
  const databaseName = isArangoDatabase(database)
1037
1065
  ? database.name
1038
- : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1066
+ : (_a = database === null || database === void 0 ? void 0 : database.normalize("NFC")) !== null && _a !== void 0 ? _a : (collection_1.isArangoCollection(collection)
1039
1067
  ? collection._db.name
1040
- : this.name);
1068
+ : this._name);
1041
1069
  const suffix = collection
1042
- ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1070
+ ? `/${encodeURIComponent(collection_1.isArangoCollection(collection)
1071
+ ? collection.name
1072
+ : collection.normalize("NFC"))}`
1043
1073
  : "";
1044
1074
  return this.request({
1045
1075
  absolutePath: true,
1046
- path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1076
+ path: `/_api/user/${encodeURIComponent(username)}/database/${encodeURIComponent(databaseName)}${suffix}`,
1047
1077
  }, (res) => res.body);
1048
1078
  }
1049
1079
  /**
@@ -1119,18 +1149,21 @@ class Database {
1119
1149
  * ```
1120
1150
  */
1121
1151
  setUserAccessLevel(username, { database, collection, grant, }) {
1152
+ var _a;
1122
1153
  const databaseName = isArangoDatabase(database)
1123
1154
  ? database.name
1124
- : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1155
+ : (_a = database === null || database === void 0 ? void 0 : database.normalize("NFC")) !== null && _a !== void 0 ? _a : (collection_1.isArangoCollection(collection)
1125
1156
  ? collection._db.name
1126
- : this.name);
1157
+ : this._name);
1127
1158
  const suffix = collection
1128
- ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1159
+ ? `/${encodeURIComponent(collection_1.isArangoCollection(collection)
1160
+ ? collection.name
1161
+ : collection.normalize("NFC"))}`
1129
1162
  : "";
1130
1163
  return this.request({
1131
1164
  absolutePath: true,
1132
1165
  method: "PUT",
1133
- path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1166
+ path: `/_api/user/${encodeURIComponent(username)}/database/${encodeURIComponent(databaseName)}${suffix}`,
1134
1167
  body: { grant },
1135
1168
  }, (res) => res.body);
1136
1169
  }
@@ -1198,24 +1231,27 @@ class Database {
1198
1231
  * ```
1199
1232
  */
1200
1233
  clearUserAccessLevel(username, { database, collection }) {
1234
+ var _a;
1201
1235
  const databaseName = isArangoDatabase(database)
1202
1236
  ? database.name
1203
- : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1237
+ : (_a = database === null || database === void 0 ? void 0 : database.normalize("NFC")) !== null && _a !== void 0 ? _a : (collection_1.isArangoCollection(collection)
1204
1238
  ? collection._db.name
1205
- : this.name);
1239
+ : this._name);
1206
1240
  const suffix = collection
1207
- ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1241
+ ? `/${encodeURIComponent(collection_1.isArangoCollection(collection)
1242
+ ? collection.name
1243
+ : collection.normalize("NFC"))}`
1208
1244
  : "";
1209
1245
  return this.request({
1210
1246
  absolutePath: true,
1211
1247
  method: "DELETE",
1212
- path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1248
+ path: `/_api/user/${encodeURIComponent(username)}/database/${encodeURIComponent(databaseName)}${suffix}`,
1213
1249
  }, (res) => res.body);
1214
1250
  }
1215
1251
  getUserDatabases(username, full) {
1216
1252
  return this.request({
1217
1253
  absolutePath: true,
1218
- path: `/_api/user/${username}/database`,
1254
+ path: `/_api/user/${encodeURIComponent(username)}/database`,
1219
1255
  qs: { full },
1220
1256
  });
1221
1257
  }
@@ -1302,7 +1338,7 @@ class Database {
1302
1338
  else if (aql_1.isAqlLiteral(query)) {
1303
1339
  query = query.toAQL();
1304
1340
  }
1305
- const { allowDirtyRead, count, batchSize, cache, memoryLimit, ttl, timeout, ...opts } = options || {};
1341
+ const { allowDirtyRead, retryOnConflict, count, batchSize, cache, memoryLimit, ttl, timeout, ...opts } = options || {};
1306
1342
  return this.request({
1307
1343
  method: "POST",
1308
1344
  path: "/_api/cursor",
@@ -1317,6 +1353,7 @@ class Database {
1317
1353
  options: opts,
1318
1354
  },
1319
1355
  allowDirtyRead,
1356
+ retryOnConflict,
1320
1357
  timeout,
1321
1358
  }, (res) => new cursor_1.BatchedArrayCursor(this, res.body, res.arangojsHostId, allowDirtyRead).items);
1322
1359
  }
@@ -1459,7 +1496,7 @@ class Database {
1459
1496
  killQuery(queryId) {
1460
1497
  return this.request({
1461
1498
  method: "DELETE",
1462
- path: `/_api/query/${queryId}`,
1499
+ path: `/_api/query/${encodeURIComponent(queryId)}`,
1463
1500
  }, () => undefined);
1464
1501
  }
1465
1502
  //#endregion
@@ -1533,7 +1570,7 @@ class Database {
1533
1570
  dropFunction(name, group = false) {
1534
1571
  return this.request({
1535
1572
  method: "DELETE",
1536
- path: `/_api/aqlfunction/${name}`,
1573
+ path: `/_api/aqlfunction/${encodeURIComponent(name)}`,
1537
1574
  qs: { group },
1538
1575
  }, (res) => res.body);
1539
1576
  }
@@ -1923,7 +1960,7 @@ class Database {
1923
1960
  runServiceScript(mount, name, params) {
1924
1961
  return this.request({
1925
1962
  method: "POST",
1926
- path: `/_api/foxx/scripts/${name}`,
1963
+ path: `/_api/foxx/scripts/${encodeURIComponent(name)}`,
1927
1964
  body: params,
1928
1965
  qs: { mount },
1929
1966
  }, (res) => res.body);