surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
303 stars 49 forks source link

Bug: Surrealdb.wait() doesn't exist #376

Closed ahmedali5530 closed 1 week ago

ahmedali5530 commented 2 weeks ago

Describe the bug

I am trying to use wait() function but it doesn't exist.

TS2339: Property wait does not exist on type Surreal

Steps to reproduce

regular install with bun. bun install surrealdb.

let db: Surreal | undefined;

export const connect = async () => {
  if (db) return db;
  db = new Surreal();
  try {
    await db.connect(withApi('/rpc'));

    await db.wait();

    await db.use({
      namespace: DB_REST_NS,
      database: DB_REST_DB,
    });

    await db.signin({
      username: DB_REST_USER,
      password: DB_REST_PASS,
    });

    return db;
  }catch(err){
    console.error(err);
    throw err;
  }
}

Expected behaviour

As per documentation wait function should work

SurrealDB version

2.0.0 for linux on x86_64

JavaScript SDK version

1.0.6

Contact Details

ahmedali5530@gmail.com

Is there an existing issue for this?

Code of Conduct

kearfy commented 1 week ago

Hey @ahmedali5530, I'm not sure how it's possible that .wait() has been able to stay in the docs for so long, as it's been removed a while ago. I'll get that sorted now. Instead, there is a ready property with a promise you can await, a status property with the current connection status and an event emitter (to be documented) which can be used to wait for certain events. Hope this helps!