0.1.3 • Published 1 year ago

thingsdb.js v0.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

ThingsDB.js

ko-fi

Description

This project provides a JavaScript connector library that enables seamless interaction with ThingsDB, from both backend and frontend environments. It simplifies data access, manipulation, and querying for developers using JavaScript.

:white_check_mark: Requirements

:floppy_disk: Instalation

This library is available for both frontend and backend. You should choose installation method by your need.

browser

Package is automatically available at unpkg. You can find latest version of package at https://unpkg.com/thingsdb.js@latest/dist/thingsdb.js

Add this into your html head:

<script src="https://unpkg.com/thingsdb.js@latest/dist/thingsdb.js"></script>

npm

Package is available at npm https://www.npmjs.com/package/thingsdb.js

Run this command to install package into your project:

npm i thingsdb.js

:desktop_computer: Usage

Class ThingsDB provide all functionality related to websocket connection with ThingsDB. It contains set of method which are based on documentation. Every method has comment (annotation) with required information and link to documentation. //not yet

Available methods

MethodDescriptionReturns
__constructThingsDB constructorThingsDB instance
connectInitialize websocket connectionPromise<void>
disconnectClose websocket connectionPromise<void>
pingPing, useful as keep-alivePromise<void>
authAuthorization with username and passwordPromise<void>
authTokenAuthorization with tokenPromise<void>
queryQuery ThingsDBPromise<any>
runRun a procedurePromise<any>
joinJoin one or more room(s)Promise<(number\|null)[]> - Array as requested ids to connect. Successful join returns same id at the same index. Unsuccessful returns null at that index.
leaveLeave one or more room(s)Promise<(number\|null)[]> - Same as join.
emitEmit an event to a roomPromise<void>
addEventListenerAdd listener for events - callback: (type: EventType, message: any) => voidvoid
removeEventListenerRemove listener for eventsvoid

Listening

Listening is specific state in which you listen for emitted packages from ThingsDB. You can read more about it in docs.

join, emit, leave also emit package towards the one who did it. Therefore, don't be surprised when first package received with your registered event listener will be ON_JOIN|ON_LEAVE|ON_EMIT event type.

Event types

  • NODE_STATUS = 0,
  • WARNING = 5,
  • ON_JOIN = 6,
  • ON_LEAVE = 7,
  • ON_EMIT = 8,
  • ON_DELETE = 9

Also available as enum EventType for typescript.

Example

const thingsdb = new ThingsDB();
thingsdb.connect().then(() => {
    thingsdb.auth().then(() => {
        thingsdb.query('@:stuff', '"Hello World!";').then(response => {
            console.log(response); // will be "Hello World!"
        });
    });
});
0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago