0

In javascript I am using this function

export async function createNewRealm(name) {
  if (process.env.REALM_DISABLED === 'true') return Promise.resolve();
  if (!connectionAdminUser) await establishRealmConnection();
  console.log(`Creating ${name} at realms://${server}/${name}`);
  return Realm.open({
    sync: {
      user: connectionAdminUser,
      url:  `realms://${server}/${name}`
    }
  });
}

Upon calling the function like this

  let test = await realm.createNewRealm('test');
  console.log(test);
  console.log(test.empty);

I get following output

Creating test at realms://:SNIPPED/company-test
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint ':SNIPPED' (from ':SNIPPED')
Connection[1]: Disconnected

Realm {}  <-- THIS being first console.log
true      <-- THIS being second console.log

Connection[2]: Session[2]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[2]: Connected to endpoint ':SNIPPED' (from ':SNIPPED')

Now I get that this is because test in let test = await realm.createNewRealm('test'); is not proper javascript object, but proxy object.

What I would like to know - How can I inspect in code the content or at least see the keys via console.log?

The documentation here can be used, but I did notice that it is not always updated and I would like to avoid context switching by having to look every time if it is user.id or user.identity, etc...

So is there JS way to get those to output via console.log? I don't mind if it ends up being string, or array, just to be able to see the content of various realm objects on demand.

Also bonus question, in the log from realm itself I can see Realm exists = true, but there is nothing in documentation saying if I can see that via object being returned. So far I am checking if it is new by calling test.empty, is there an easier way? (related since this is the reason why I am asking main question)

Miroslav Saracevic
  • 1,446
  • 1
  • 13
  • 32

1 Answers1

0

I dont have right env, but try this code

 let test = await realm.createNewRealm('test');
 console.log(test.__proto__);

I think you can print all properties like this

for(let n in test)  console.log(n,' = ',test[n]);
Yaroslav Gaponov
  • 1,997
  • 13
  • 12