arangojs 7.4.0 → 7.6.1

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/analyzer.d.ts +188 -1
  3. package/analyzer.d.ts.map +1 -1
  4. package/analyzer.js.map +1 -1
  5. package/aql.d.ts +2 -1
  6. package/aql.d.ts.map +1 -1
  7. package/aql.js +5 -1
  8. package/aql.js.map +1 -1
  9. package/collection.d.ts +72 -11
  10. package/collection.d.ts.map +1 -1
  11. package/collection.js +15 -2
  12. package/collection.js.map +1 -1
  13. package/connection.d.ts +2 -2
  14. package/connection.d.ts.map +1 -1
  15. package/connection.js.map +1 -1
  16. package/cursor.d.ts +12 -6
  17. package/cursor.d.ts.map +1 -1
  18. package/cursor.js +4 -4
  19. package/cursor.js.map +1 -1
  20. package/database.d.ts +451 -4
  21. package/database.d.ts.map +1 -1
  22. package/database.js +357 -0
  23. package/database.js.map +1 -1
  24. package/documents.d.ts +5 -5
  25. package/documents.d.ts.map +1 -1
  26. package/documents.js.map +1 -1
  27. package/graph.d.ts +16 -4
  28. package/graph.d.ts.map +1 -1
  29. package/graph.js +18 -1
  30. package/graph.js.map +1 -1
  31. package/indexes.d.ts +70 -0
  32. package/indexes.d.ts.map +1 -1
  33. package/indexes.js.map +1 -1
  34. package/lib/error.d.ts.map +1 -1
  35. package/lib/error.js +1 -0
  36. package/lib/error.js.map +1 -1
  37. package/lib/multipart.d.ts.map +1 -1
  38. package/lib/multipart.js +1 -0
  39. package/lib/multipart.js.map +1 -1
  40. package/lib/normalizeUrl.js +1 -1
  41. package/lib/normalizeUrl.js.map +1 -1
  42. package/lib/request.node.js.map +1 -1
  43. package/lib/xhr.d.ts.map +1 -1
  44. package/lib/xhr.js +1 -0
  45. package/lib/xhr.js.map +1 -1
  46. package/package.json +1 -1
  47. package/view.d.ts +1 -1
  48. package/view.d.ts.map +1 -1
  49. package/view.js.map +1 -1
  50. package/web.js +1 -1
  51. package/web.js.map +1 -1
package/database.js CHANGED
@@ -862,6 +862,363 @@ class Database {
862
862
  const analyzers = await this.listAnalyzers();
863
863
  return analyzers.map((data) => this.analyzer(data.name));
864
864
  }
865
+ //#endregion
866
+ //#region users
867
+ /**
868
+ * Fetches all ArangoDB users visible to the authenticated user and returns
869
+ * an array of user objects.
870
+ *
871
+ * @example
872
+ * ```js
873
+ * const db = new Database();
874
+ * const users = await db.listUsers();
875
+ * // users is an array of user objects
876
+ * ```
877
+ */
878
+ listUsers() {
879
+ return this.request({
880
+ absolutePath: true,
881
+ path: "/_api/user",
882
+ });
883
+ }
884
+ /**
885
+ * Fetches the user data of a single ArangoDB user.
886
+ *
887
+ * @param username - Name of the ArangoDB user to fetch.
888
+ *
889
+ * @example
890
+ * ```js
891
+ * const db = new Database();
892
+ * const user = await db.getUser("steve");
893
+ * // user is the user object for the user named "steve"
894
+ * ```
895
+ */
896
+ getUser(username) {
897
+ return this.request({
898
+ absolutePath: true,
899
+ path: `/_api/user/${username}`,
900
+ });
901
+ }
902
+ createUser(username, options) {
903
+ if (typeof options === "string") {
904
+ options = { passwd: options };
905
+ }
906
+ return this.request({
907
+ absolutePath: true,
908
+ method: "POST",
909
+ path: "/_api/user",
910
+ body: { user: username, ...options },
911
+ }, (res) => res.body);
912
+ }
913
+ updateUser(username, options) {
914
+ if (typeof options === "string") {
915
+ options = { passwd: options };
916
+ }
917
+ return this.request({
918
+ absolutePath: true,
919
+ method: "PATCH",
920
+ path: `/api/user/${username}`,
921
+ body: options,
922
+ }, (res) => res.body);
923
+ }
924
+ /**
925
+ * Replaces the ArangoDB user's option with the new options.
926
+ *
927
+ * @param username - Name of the ArangoDB user to modify.
928
+ * @param options - New options to replace the user's existing options.
929
+ *
930
+ * @example
931
+ * ```js
932
+ * const db = new Database();
933
+ * const user = await db.replaceUser("steve", { passwd: "", active: false });
934
+ * // The user "steve" has been set to inactive with an empty password
935
+ * ```
936
+ */
937
+ replaceUser(username, options) {
938
+ if (typeof options === "string") {
939
+ options = { passwd: options };
940
+ }
941
+ return this.request({
942
+ absolutePath: true,
943
+ method: "PUT",
944
+ path: `/api/user/${username}`,
945
+ body: options,
946
+ }, (res) => res.body);
947
+ }
948
+ /**
949
+ * Removes the ArangoDB user with the given username from the server.
950
+ *
951
+ * @param username - Name of the ArangoDB user to remove.
952
+ *
953
+ * @example
954
+ * ```js
955
+ * const db = new Database();
956
+ * await db.removeUser("steve");
957
+ * // The user "steve" has been removed
958
+ * ```
959
+ */
960
+ removeUser(username) {
961
+ return this.request({
962
+ absolutePath: true,
963
+ method: "DELETE",
964
+ path: `/_api/user/${username}`,
965
+ }, (res) => res.body);
966
+ }
967
+ /**
968
+ * Fetches the given ArangoDB user's access level for the database, or the
969
+ * given collection in the given database.
970
+ *
971
+ * @param username - Name of the ArangoDB user to fetch the access level for.
972
+ * @param database - Database to fetch the access level for.
973
+ * @param collection - Collection to fetch the access level for.
974
+ *
975
+ * @example
976
+ * ```js
977
+ * const db = new Database();
978
+ * const accessLevel = await db.getUserAccessLevel("steve");
979
+ * // The access level of the user "steve" has been fetched for the current
980
+ * // database.
981
+ * ```
982
+ *
983
+ * @example
984
+ * ```js
985
+ * const db = new Database();
986
+ * const accessLevel = await db.getUserAccessLevel("steve", {
987
+ * database: "staging"
988
+ * });
989
+ * // The access level of the user "steve" has been fetched for the "staging"
990
+ * // database.
991
+ * ```
992
+ *
993
+ * @example
994
+ * ```js
995
+ * const db = new Database();
996
+ * const accessLevel = await db.getUserAccessLevel("steve", {
997
+ * collection: "pokemons"
998
+ * });
999
+ * // The access level of the user "steve" has been fetched for the
1000
+ * // "pokemons" collection in the current database.
1001
+ * ```
1002
+ *
1003
+ * @example
1004
+ * ```js
1005
+ * const db = new Database();
1006
+ * const accessLevel = await db.getUserAccessLevel("steve", {
1007
+ * database: "staging",
1008
+ * collection: "pokemons"
1009
+ * });
1010
+ * // The access level of the user "steve" has been fetched for the
1011
+ * // "pokemons" collection in the "staging" database.
1012
+ * ```
1013
+ *
1014
+ * @example
1015
+ * ```js
1016
+ * const db = new Database();
1017
+ * const staging = db.database("staging");
1018
+ * const accessLevel = await db.getUserAccessLevel("steve", {
1019
+ * database: staging
1020
+ * });
1021
+ * // The access level of the user "steve" has been fetched for the "staging"
1022
+ * // database.
1023
+ * ```
1024
+ *
1025
+ * @example
1026
+ * ```js
1027
+ * const db = new Database();
1028
+ * const staging = db.database("staging");
1029
+ * const accessLevel = await db.getUserAccessLevel("steve", {
1030
+ * collection: staging.collection("pokemons")
1031
+ * });
1032
+ * // The access level of the user "steve" has been fetched for the
1033
+ * // "pokemons" collection in database "staging".
1034
+ */
1035
+ getUserAccessLevel(username, { database, collection }) {
1036
+ const databaseName = isArangoDatabase(database)
1037
+ ? database.name
1038
+ : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1039
+ ? collection._db.name
1040
+ : this.name);
1041
+ const suffix = collection
1042
+ ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1043
+ : "";
1044
+ return this.request({
1045
+ absolutePath: true,
1046
+ path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1047
+ }, (res) => res.body);
1048
+ }
1049
+ /**
1050
+ * Sets the given ArangoDB user's access level for the database, or the
1051
+ * given collection in the given database.
1052
+ *
1053
+ * @param username - Name of the ArangoDB user to set the access level for.
1054
+ * @param database - Database to set the access level for.
1055
+ * @param collection - Collection to set the access level for.
1056
+ * @param grant - Access level to set for the given user.
1057
+ *
1058
+ * @example
1059
+ * ```js
1060
+ * const db = new Database();
1061
+ * await db.setUserAccessLevel("steve", { grant: "rw" });
1062
+ * // The user "steve" now has read-write access to the current database.
1063
+ * ```
1064
+ *
1065
+ * @example
1066
+ * ```js
1067
+ * const db = new Database();
1068
+ * await db.setUserAccessLevel("steve", {
1069
+ * database: "staging",
1070
+ * grant: "rw"
1071
+ * });
1072
+ * // The user "steve" now has read-write access to the "staging" database.
1073
+ * ```
1074
+ *
1075
+ * @example
1076
+ * ```js
1077
+ * const db = new Database();
1078
+ * await db.setUserAccessLevel("steve", {
1079
+ * collection: "pokemons",
1080
+ * grant: "rw"
1081
+ * });
1082
+ * // The user "steve" now has read-write access to the "pokemons" collection
1083
+ * // in the current database.
1084
+ * ```
1085
+ *
1086
+ * @example
1087
+ * ```js
1088
+ * const db = new Database();
1089
+ * await db.setUserAccessLevel("steve", {
1090
+ * database: "staging",
1091
+ * collection: "pokemons",
1092
+ * grant: "rw"
1093
+ * });
1094
+ * // The user "steve" now has read-write access to the "pokemons" collection
1095
+ * // in the "staging" database.
1096
+ * ```
1097
+ *
1098
+ * @example
1099
+ * ```js
1100
+ * const db = new Database();
1101
+ * const staging = db.database("staging");
1102
+ * await db.setUserAccessLevel("steve", {
1103
+ * database: staging,
1104
+ * grant: "rw"
1105
+ * });
1106
+ * // The user "steve" now has read-write access to the "staging" database.
1107
+ * ```
1108
+ *
1109
+ * @example
1110
+ * ```js
1111
+ * const db = new Database();
1112
+ * const staging = db.database("staging");
1113
+ * await db.setUserAccessLevel("steve", {
1114
+ * collection: staging.collection("pokemons"),
1115
+ * grant: "rw"
1116
+ * });
1117
+ * // The user "steve" now has read-write access to the "pokemons" collection
1118
+ * // in database "staging".
1119
+ * ```
1120
+ */
1121
+ setUserAccessLevel(username, { database, collection, grant, }) {
1122
+ const databaseName = isArangoDatabase(database)
1123
+ ? database.name
1124
+ : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1125
+ ? collection._db.name
1126
+ : this.name);
1127
+ const suffix = collection
1128
+ ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1129
+ : "";
1130
+ return this.request({
1131
+ absolutePath: true,
1132
+ method: "PUT",
1133
+ path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1134
+ body: { grant },
1135
+ }, (res) => res.body);
1136
+ }
1137
+ /**
1138
+ * Clears the given ArangoDB user's access level for the database, or the
1139
+ * given collection in the given database.
1140
+ *
1141
+ * @param username - Name of the ArangoDB user to clear the access level for.
1142
+ * @param database - Database to clear the access level for.
1143
+ * @param collection - Collection to clear the access level for.
1144
+ *
1145
+ * @example
1146
+ * ```js
1147
+ * const db = new Database();
1148
+ * await db.clearUserAccessLevel("steve");
1149
+ * // The access level of the user "steve" has been cleared for the current
1150
+ * // database.
1151
+ * ```
1152
+ *
1153
+ * @example
1154
+ * ```js
1155
+ * const db = new Database();
1156
+ * await db.clearUserAccessLevel("steve", { database: "staging" });
1157
+ * // The access level of the user "steve" has been cleared for the "staging"
1158
+ * // database.
1159
+ * ```
1160
+ *
1161
+ * @example
1162
+ * ```js
1163
+ * const db = new Database();
1164
+ * await db.clearUserAccessLevel("steve", { collection: "pokemons" });
1165
+ * // The access level of the user "steve" has been cleared for the
1166
+ * // "pokemons" collection in the current database.
1167
+ * ```
1168
+ *
1169
+ * @example
1170
+ * ```js
1171
+ * const db = new Database();
1172
+ * await db.clearUserAccessLevel("steve", {
1173
+ * database: "staging",
1174
+ * collection: "pokemons"
1175
+ * });
1176
+ * // The access level of the user "steve" has been cleared for the
1177
+ * // "pokemons" collection in the "staging" database.
1178
+ * ```
1179
+ *
1180
+ * @example
1181
+ * ```js
1182
+ * const db = new Database();
1183
+ * const staging = db.database("staging");
1184
+ * await db.clearUserAccessLevel("steve", { database: staging });
1185
+ * // The access level of the user "steve" has been cleared for the "staging"
1186
+ * // database.
1187
+ * ```
1188
+ *
1189
+ * @example
1190
+ * ```js
1191
+ * const db = new Database();
1192
+ * const staging = db.database("staging");
1193
+ * await db.clearUserAccessLevel("steve", {
1194
+ * collection: staging.collection("pokemons")
1195
+ * });
1196
+ * // The access level of the user "steve" has been cleared for the
1197
+ * // "pokemons" collection in database "staging".
1198
+ * ```
1199
+ */
1200
+ clearUserAccessLevel(username, { database, collection }) {
1201
+ const databaseName = isArangoDatabase(database)
1202
+ ? database.name
1203
+ : database !== null && database !== void 0 ? database : (collection_1.isArangoCollection(collection)
1204
+ ? collection._db.name
1205
+ : this.name);
1206
+ const suffix = collection
1207
+ ? `/${collection_1.isArangoCollection(collection) ? collection.name : collection}`
1208
+ : "";
1209
+ return this.request({
1210
+ absolutePath: true,
1211
+ method: "DELETE",
1212
+ path: `/_api/user/${username}/database/${databaseName}${suffix}`,
1213
+ }, (res) => res.body);
1214
+ }
1215
+ getUserDatabases(username, full) {
1216
+ return this.request({
1217
+ absolutePath: true,
1218
+ path: `/_api/user/${username}/database`,
1219
+ qs: { full },
1220
+ });
1221
+ }
865
1222
  executeTransaction(collections, action, options) {
866
1223
  return this.request({
867
1224
  method: "POST",