Skip to content

client API

phoenixide edited this page Feb 2, 2023 · 4 revisions

init

Create a connection to the cocoDbServiceEndPoint and listens for messages. The connection will be maintained and, it will try to automatically re-establish broken connections if there are network issues. You need to await on this function before staring to use any db APIs. Any APIs called while the connection is not fully setup will throw an error.

Hibernation after inactivity

After around 10 seconds of no send activity and if there are no outstanding requests, the db connection will be dropped and the client move into a hibernation state. The connection will be immediately re-established on any db activity transparently, though a slight jitter may be observed during the connection establishment time. This auto start-stop will save database resources as servers can be on for months on end.

Parameters

  • cocoDbServiceEndPoint string The URL of the coco-db service.
  • authKey string The authKey is a base64 encoded string of the username and password.

Returns Promise<null> Resolves when the cocodb client is ready to send/receive requests for the first time. Rejects only if the user calls close API before any connection is established.

close

Closes the connection to the server. You need to await on this function before you can call init again.

Returns Promise<null> Resolves when the cocodb client is closed and you are free to call init again. Never rejects.

getId

It returns a string representation of the next integer in a sequence

Returns string A function that increments the id variable and returns the new value as a hexadecimal string.

sendMessage

It takes a message object, sends it to the server, and returns a promise that resolves when the server responds

Parameters

  • message Object The message to be sent to the server.

Returns Promise A function that returns a promise.

__receiveMessage

Exported for testing

Process data from the server and resolves client promises

Parameters

  • rawData The raw data received from the server.

Returns any A function that takes in a rawData string and returns a boolean.

Clone this wiki locally