arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
601 stars 107 forks source link

db.listUsers not rerturning an array of ArangoUser #782

Closed fspegni closed 1 year ago

fspegni commented 1 year ago

Hi everyone,

I'm observing an odd behavior with the following script (using arangojs 7.7.0):

const { Database, aql } = require("arangojs");
const db = new Database("http://db:8529");
db.useBasicAuth("myusername", "mypassword");
db.useDatabase("MyDatabase");
const col = db.collection("MyCollection");
db.query(aql`FOR doc in ${col} RETURN doc`).then(async (cursor) => { console.log("Done"); }); // it works up to here

db.listUsers().then((usersData) => { 
    console.log("Users data", usersData); // this does not print an array of ArangoUser as I'd expect, but an object of type IncomingMessage ... 
});

const usersData = await db.listUsers(); 
console.log("Users data", usersData); // same as above ...

const userDBs = await db.listUserDatabases(); // this works OK, it prints the names of available databasess, as expected (array of strings ...)

The value of variables usersData in both examples above is the following:

Users data <ref *2> IncomingMessage {
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: true,
    ended: true,
    endEmitted: true,
    reading: false,
    constructed: true,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    destroyed: true,
    errored: null,
    closed: true,
    closeEmitted: true,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: true,
    dataEmitted: true,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: false
  },
...

Following this documentation I'd expect an array of ArangoUser objects, instead.

Am I doing something wrong? Note that if I call another method (e.g. listUserDatabases()) I get the expected result (an array of strings).

fspegni commented 1 year ago

ok, doing some in-depth search in your code e.g. here and comparing with the listUserDatabases, I realize I could get what I want by doing the same:

db.request({ path:"/_api/user" }, (res) => console.log("Users", res.body.result))

Thus, It seems to me there is a small bug in the listUsers function, that should pass a callback (as the listUserDatabases does)