chain-db-ts 0.0.1 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import { Access } from './access';
2
- import { BasicResponse, SignedUserAccount, TransferUnitsRegistry } from './types';
1
+ import Table from './table';
2
+ import { Connection, EventCallback } from './types';
3
3
  export declare class ChainDB {
4
- api: string;
5
- name: string;
6
- access: Access | null;
7
- access_key: string;
4
+ server: string;
5
+ database: string;
6
+ auth: string;
7
+ private _events;
8
8
  /**
9
9
  * Connection information.
10
10
  * @param server Server location. If the `server` parameter is empty, then "http://localhost" will be used.
@@ -12,63 +12,28 @@ export declare class ChainDB {
12
12
  * @param user User to access the data base
13
13
  * @param password Password to access the data base
14
14
  */
15
- connect(server: string | null, data_base: string, user: string, password: string): void;
16
- /**
17
- * Create a new user account inside the connected table
18
- * @param user_name
19
- * @param password
20
- * @param units
21
- * @param password_hint
22
- * @returns
23
- */
24
- create_user_account(user_name: string, password: string, units?: number, password_hint?: string): Promise<BasicResponse<SignedUserAccount>>;
25
- /**
26
- * Get user account info (login method)
27
- * @param user_name
28
- * @param password
29
- * @returns
30
- */
31
- get_user_account(user_name: string, password: string): Promise<BasicResponse<SignedUserAccount>>;
32
- /**
33
- * Get user account info by its id
34
- * @param user_id
35
- * @returns
36
- */
37
- get_user_account_by_id(user_id: string): Promise<BasicResponse<SignedUserAccount>>;
38
- /**
39
- * Check if user_name is already taken
40
- * @param user_name
41
- */
42
- check_user_name(user_name: string): Promise<BasicResponse<string>>;
43
- /**
44
- * Transfer units between users
45
- * @param from user_id
46
- * @param to user_id
47
- * @param units
48
- * @returns
49
- */
50
- transfer_units(from: string, to: string, units: number): Promise<BasicResponse<null>>;
51
- /**
52
- * Fetch the last Transference of units Records by User
53
- * @param user_id
54
- * @returns
55
- */
56
- get_transfer_by_user_id(user_id: string): Promise<BasicResponse<TransferUnitsRegistry>>;
57
- /**
58
- * Fetch all Transference of units Records by User
59
- * @param user_id
60
- * @returns
61
- */
62
- get_all_transfers_by_user_id(user_id: string): Promise<BasicResponse<TransferUnitsRegistry[]>>;
15
+ connect(connection: Connection): Promise<void>;
63
16
  /**
64
17
  * Initialize a table, fetching its more updated data
65
18
  */
66
- get_table<Model>(table_name: string, model: Model): Promise<{
67
- table: Model;
19
+ getTable<Model>(table_name: string): Promise<Table<Model>>;
20
+ events(): {
21
+ /**
22
+ * Subscribe to an event
23
+ * @param event Event name to subscribe to @see {EventTypes}
24
+ * @param callback Function to call when the event is received
25
+ */
26
+ subscribe: (event: string, callback: EventCallback) => void;
27
+ /**
28
+ * Unsubscribe from an event
29
+ * @param event Event name to unsubscribe from @see {EventTypes}
30
+ * @param callback Optional callback to remove. If not provided, all callbacks for the event will be removed.
31
+ */
32
+ unsubscribe: (event: string, callback?: EventCallback) => void;
68
33
  /**
69
- * Persist table data on chain
34
+ * Close the events transmission
70
35
  */
71
- persist: () => Promise<void>;
72
- }>;
36
+ closeEvents: () => void;
37
+ };
73
38
  }
74
- export declare const connect: (server: string | null, data_base: string, user: string, password: string) => ChainDB;
39
+ export declare const connect: (connection: Connection) => Promise<ChainDB>;
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -63,18 +40,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
63
40
  };
64
41
  exports.__esModule = true;
65
42
  exports.connect = exports.ChainDB = void 0;
66
- var sha256_1 = __importDefault(require("sha256"));
67
- var axios_1 = __importDefault(require("axios"));
68
- var access_1 = require("./access");
69
43
  var constants_1 = require("./constants");
70
44
  var utils_1 = require("./utils");
71
- var table = __importStar(require("./table"));
45
+ var table_1 = __importDefault(require("./table"));
46
+ var events_1 = __importDefault(require("./events"));
72
47
  var ChainDB = /** @class */ (function () {
73
48
  function ChainDB() {
74
- this.api = '';
75
- this.name = '';
76
- this.access = null;
77
- this.access_key = '';
49
+ this.server = constants_1.DEFAULT_API_SERVER;
50
+ this.database = '';
51
+ this.auth = '';
52
+ this._events = null;
78
53
  }
79
54
  /**
80
55
  * Connection information.
@@ -83,224 +58,34 @@ var ChainDB = /** @class */ (function () {
83
58
  * @param user User to access the data base
84
59
  * @param password Password to access the data base
85
60
  */
86
- ChainDB.prototype.connect = function (server, data_base, user, password) {
87
- var key_data = "".concat(data_base).concat(user).concat(password);
88
- var key = (0, sha256_1["default"])(key_data);
89
- this.api = server || constants_1.API;
90
- this.name = data_base;
91
- this.access = new access_1.Access(user, password);
92
- this.access_key = key;
93
- };
94
- /**
95
- * Create a new user account inside the connected table
96
- * @param user_name
97
- * @param password
98
- * @param units
99
- * @param password_hint
100
- * @returns
101
- */
102
- ChainDB.prototype.create_user_account = function (user_name, password, units, password_hint) {
103
- return __awaiter(this, void 0, void 0, function () {
104
- var url, body, response, _a;
105
- return __generator(this, function (_b) {
106
- switch (_b.label) {
107
- case 0:
108
- url = "".concat(this.api).concat(constants_1.CREATE_USER_ACCOUNT);
109
- body = {
110
- db_access_key: this.access_key,
111
- user_name: user_name,
112
- password: password,
113
- password_hint: password_hint,
114
- units: units
115
- };
116
- _b.label = 1;
117
- case 1:
118
- _b.trys.push([1, 4, , 5]);
119
- return [4 /*yield*/, (0, utils_1.post)(url, body)];
120
- case 2:
121
- response = _b.sent();
122
- return [4 /*yield*/, response.data];
123
- case 3: return [2 /*return*/, _b.sent()];
124
- case 4:
125
- _a = _b.sent();
126
- throw new Error('Something went wrong!');
127
- case 5: return [2 /*return*/];
128
- }
129
- });
130
- });
131
- };
132
- /**
133
- * Get user account info (login method)
134
- * @param user_name
135
- * @param password
136
- * @returns
137
- */
138
- ChainDB.prototype.get_user_account = function (user_name, password) {
139
- return __awaiter(this, void 0, void 0, function () {
140
- var url, response, _a;
141
- return __generator(this, function (_b) {
142
- switch (_b.label) {
143
- case 0:
144
- url = "".concat(this.api).concat(constants_1.GET_USER_ACCOUNT, "/").concat(user_name, "/").concat(password, "/").concat(this.access_key);
145
- _b.label = 1;
146
- case 1:
147
- _b.trys.push([1, 4, , 5]);
148
- return [4 /*yield*/, axios_1["default"].get(url)];
149
- case 2:
150
- response = _b.sent();
151
- return [4 /*yield*/, response.data];
152
- case 3: return [2 /*return*/, _b.sent()];
153
- case 4:
154
- _a = _b.sent();
155
- throw new Error('Something went wrong!');
156
- case 5: return [2 /*return*/];
157
- }
158
- });
159
- });
160
- };
161
- /**
162
- * Get user account info by its id
163
- * @param user_id
164
- * @returns
165
- */
166
- ChainDB.prototype.get_user_account_by_id = function (user_id) {
61
+ ChainDB.prototype.connect = function (connection) {
167
62
  return __awaiter(this, void 0, void 0, function () {
168
- var url, response, _a;
169
- return __generator(this, function (_b) {
170
- switch (_b.label) {
171
- case 0:
172
- url = "".concat(this.api).concat(constants_1.GET_USER_ACCOUNT_BY_ID, "/").concat(user_id, "/").concat(this.access_key);
173
- _b.label = 1;
174
- case 1:
175
- _b.trys.push([1, 4, , 5]);
176
- return [4 /*yield*/, axios_1["default"].get(url)];
177
- case 2:
178
- response = _b.sent();
179
- return [4 /*yield*/, response.data];
180
- case 3: return [2 /*return*/, _b.sent()];
181
- case 4:
182
- _a = _b.sent();
183
- throw new Error('Something went wrong!');
184
- case 5: return [2 /*return*/];
185
- }
186
- });
187
- });
188
- };
189
- /**
190
- * Check if user_name is already taken
191
- * @param user_name
192
- */
193
- ChainDB.prototype.check_user_name = function (user_name) {
194
- return __awaiter(this, void 0, void 0, function () {
195
- var url, response, _a;
196
- return __generator(this, function (_b) {
197
- switch (_b.label) {
198
- case 0:
199
- url = "".concat(this.api).concat(constants_1.CHECK_USER_NAME, "/").concat(user_name, "/").concat(this.access_key);
200
- _b.label = 1;
201
- case 1:
202
- _b.trys.push([1, 4, , 5]);
203
- return [4 /*yield*/, axios_1["default"].get(url)];
204
- case 2:
205
- response = _b.sent();
206
- return [4 /*yield*/, response.data];
207
- case 3: return [2 /*return*/, _b.sent()];
208
- case 4:
209
- _a = _b.sent();
210
- throw new Error('Something went wrong!');
211
- case 5: return [2 /*return*/];
212
- }
213
- });
214
- });
215
- };
216
- /**
217
- * Transfer units between users
218
- * @param from user_id
219
- * @param to user_id
220
- * @param units
221
- * @returns
222
- */
223
- ChainDB.prototype.transfer_units = function (from, to, units) {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var url, body, response, _a;
226
- return __generator(this, function (_b) {
227
- switch (_b.label) {
228
- case 0:
229
- url = "".concat(this.api).concat(constants_1.TRANSFER_UNITS);
230
- body = {
231
- db_access_key: this.access_key,
232
- from: from,
233
- to: to,
234
- units: units
235
- };
236
- _b.label = 1;
237
- case 1:
238
- _b.trys.push([1, 4, , 5]);
239
- return [4 /*yield*/, (0, utils_1.post)(url, body)];
240
- case 2:
241
- response = _b.sent();
242
- return [4 /*yield*/, response.data];
243
- case 3: return [2 /*return*/, _b.sent()];
244
- case 4:
245
- _a = _b.sent();
246
- throw new Error('Something went wrong!');
247
- case 5: return [2 /*return*/];
248
- }
249
- });
250
- });
251
- };
252
- /**
253
- * Fetch the last Transference of units Records by User
254
- * @param user_id
255
- * @returns
256
- */
257
- ChainDB.prototype.get_transfer_by_user_id = function (user_id) {
258
- return __awaiter(this, void 0, void 0, function () {
259
- var url, response, _a;
260
- return __generator(this, function (_b) {
261
- switch (_b.label) {
262
- case 0:
263
- url = "".concat(this.api).concat(constants_1.GET_TRANSFER_BY_USER_ID, "/").concat(user_id, "/").concat(this.access_key);
264
- _b.label = 1;
265
- case 1:
266
- _b.trys.push([1, 4, , 5]);
267
- return [4 /*yield*/, axios_1["default"].get(url)];
268
- case 2:
269
- response = _b.sent();
270
- return [4 /*yield*/, response.data];
271
- case 3: return [2 /*return*/, _b.sent()];
272
- case 4:
273
- _a = _b.sent();
274
- throw new Error('Something went wrong!');
275
- case 5: return [2 /*return*/];
276
- }
277
- });
278
- });
279
- };
280
- /**
281
- * Fetch all Transference of units Records by User
282
- * @param user_id
283
- * @returns
284
- */
285
- ChainDB.prototype.get_all_transfers_by_user_id = function (user_id) {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var url, response, _a;
288
- return __generator(this, function (_b) {
289
- switch (_b.label) {
63
+ var server, database, user, password, response, e_1;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
290
66
  case 0:
291
- url = "".concat(this.api).concat(constants_1.GET_ALL_TRANSFER_BY_USER_ID, "/").concat(user_id, "/").concat(this.access_key);
292
- _b.label = 1;
67
+ server = connection.server, database = connection.database, user = connection.user, password = connection.password;
68
+ this.server = server || constants_1.DEFAULT_API_SERVER;
69
+ this.database = database;
70
+ _a.label = 1;
293
71
  case 1:
294
- _b.trys.push([1, 4, , 5]);
295
- return [4 /*yield*/, axios_1["default"].get(url)];
72
+ _a.trys.push([1, 3, , 4]);
73
+ return [4 /*yield*/, (0, utils_1.post)("".concat(this.server).concat(constants_1.CONNECT), {
74
+ name: this.database,
75
+ user: user,
76
+ password: password
77
+ })];
296
78
  case 2:
297
- response = _b.sent();
298
- return [4 /*yield*/, response.data];
299
- case 3: return [2 /*return*/, _b.sent()];
300
- case 4:
301
- _a = _b.sent();
302
- throw new Error('Something went wrong!');
303
- case 5: return [2 /*return*/];
79
+ response = _a.sent();
80
+ if (!response.data.success) {
81
+ throw new Error(response.data.message);
82
+ }
83
+ this.auth = response.data.data;
84
+ return [3 /*break*/, 4];
85
+ case 3:
86
+ e_1 = _a.sent();
87
+ throw new Error("Something went wrong! ".concat(e_1.message || String(e_1)));
88
+ case 4: return [2 /*return*/];
304
89
  }
305
90
  });
306
91
  });
@@ -308,40 +93,92 @@ var ChainDB = /** @class */ (function () {
308
93
  /**
309
94
  * Initialize a table, fetching its more updated data
310
95
  */
311
- ChainDB.prototype.get_table = function (table_name, model) {
96
+ ChainDB.prototype.getTable = function (table_name) {
312
97
  return __awaiter(this, void 0, void 0, function () {
313
- var chainDbCopy, table_data;
98
+ var tableData;
314
99
  return __generator(this, function (_a) {
315
100
  switch (_a.label) {
316
101
  case 0:
317
- chainDbCopy = (0, exports.connect)(this.api, this.name, this.access.user, this.access.password);
318
- return [4 /*yield*/, table.get(chainDbCopy, table_name, model)
102
+ tableData = new table_1["default"](table_name, this);
103
+ return [4 /*yield*/, tableData.refetch()];
104
+ case 1:
105
+ _a.sent();
106
+ return [2 /*return*/, tableData
107
+ // const table_data = await table.get<Model>(this, table_name, model)
319
108
  // NOTE: Although only the "table" and "persist" properties are displayed by
320
109
  // the lint, all Table properties are being exposed.
321
110
  // This is due to a javascript limitation on classes.
322
111
  //
323
112
  // There was an attempt to return a new object with only the required
324
113
  // data, but this generates an error in the "this" instance of the Table.
114
+ // return table_data as {
115
+ // table: Model
116
+ // /**
117
+ // * Persist table data on chain
118
+ // */
119
+ // persist: () => Promise<void>
120
+ // /**
121
+ // * Get the history of changes. A list of transactions from the most recent to the most old
122
+ // * in a range of depth
123
+ // * @param depth
124
+ // */
125
+ // getHistory: (depth: number) => Promise<Model[]>
126
+ // }
325
127
  ];
326
- case 1:
327
- table_data = _a.sent();
328
- // NOTE: Although only the "table" and "persist" properties are displayed by
329
- // the lint, all Table properties are being exposed.
330
- // This is due to a javascript limitation on classes.
331
- //
332
- // There was an attempt to return a new object with only the required
333
- // data, but this generates an error in the "this" instance of the Table.
334
- return [2 /*return*/, table_data];
335
128
  }
336
129
  });
337
130
  });
338
131
  };
132
+ ChainDB.prototype.events = function () {
133
+ var _this = this;
134
+ return {
135
+ /**
136
+ * Subscribe to an event
137
+ * @param event Event name to subscribe to @see {EventTypes}
138
+ * @param callback Function to call when the event is received
139
+ */
140
+ subscribe: function (event, callback) {
141
+ var _a;
142
+ if (_this._events === null) {
143
+ var wsUrl = "".concat(_this.server.replace('http', 'ws')).concat(constants_1.WEB_SOCKET_EVENTS);
144
+ _this._events = new events_1["default"](wsUrl, _this.auth);
145
+ }
146
+ (_a = _this._events) === null || _a === void 0 ? void 0 : _a.subscribe(event, callback);
147
+ },
148
+ /**
149
+ * Unsubscribe from an event
150
+ * @param event Event name to unsubscribe from @see {EventTypes}
151
+ * @param callback Optional callback to remove. If not provided, all callbacks for the event will be removed.
152
+ */
153
+ unsubscribe: function (event, callback) {
154
+ if (!_this._events || !_this._events.isConnected()) {
155
+ return;
156
+ }
157
+ _this._events.unsubscribe(event, callback);
158
+ },
159
+ /**
160
+ * Close the events transmission
161
+ */
162
+ closeEvents: function () {
163
+ var _a;
164
+ (_a = _this._events) === null || _a === void 0 ? void 0 : _a.close();
165
+ }
166
+ };
167
+ };
339
168
  return ChainDB;
340
169
  }());
341
170
  exports.ChainDB = ChainDB;
342
- var connect = function (server, data_base, user, password) {
343
- var chainDb = new ChainDB();
344
- chainDb.connect(server, data_base, user, password);
345
- return chainDb;
346
- };
171
+ var connect = function (connection) { return __awaiter(void 0, void 0, void 0, function () {
172
+ var chainDb;
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0:
176
+ chainDb = new ChainDB();
177
+ return [4 /*yield*/, chainDb.connect(connection)];
178
+ case 1:
179
+ _a.sent();
180
+ return [2 /*return*/, chainDb];
181
+ }
182
+ });
183
+ }); };
347
184
  exports.connect = connect;
@@ -1,10 +1,10 @@
1
- export declare const API = "http://localhost:2818";
2
- export declare const CONTRACT_PAYLOAD = "/get_last_contract_transaction";
3
- export declare const CONTRACT_TRANSACTION = "/post_contract_transaction";
4
- export declare const CREATE_USER_ACCOUNT = "/create_user_account";
5
- export declare const GET_USER_ACCOUNT = "/get_user_account";
6
- export declare const GET_USER_ACCOUNT_BY_ID = "/get_user_account_by_id";
7
- export declare const TRANSFER_UNITS = "/transfer_units";
8
- export declare const GET_TRANSFER_BY_USER_ID = "/get_transfer_by_user_id";
9
- export declare const GET_ALL_TRANSFER_BY_USER_ID = "/get_all_transfers_by_user_id";
10
- export declare const CHECK_USER_NAME = "/check_user_name";
1
+ export declare const DEFAULT_API_SERVER = "http://localhost:2818";
2
+ export declare const API_BASE = "/api/v1";
3
+ export declare const CONNECT: string;
4
+ export declare const GET_TABLE: (table: string) => string;
5
+ export declare const UPDATE_LAST_ITEM: (table: string) => string;
6
+ export declare const PERSIST_NEW_DATA: (table: string) => string;
7
+ export declare const GET_HISTORY: (table: string, limit?: number) => string;
8
+ export declare const FIND_WHERE_BASIC: (table: string) => string;
9
+ export declare const FIND_WHERE_ADVANCED: (table: string) => string;
10
+ export declare const WEB_SOCKET_EVENTS: string;
@@ -1,14 +1,23 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.CHECK_USER_NAME = exports.GET_ALL_TRANSFER_BY_USER_ID = exports.GET_TRANSFER_BY_USER_ID = exports.TRANSFER_UNITS = exports.GET_USER_ACCOUNT_BY_ID = exports.GET_USER_ACCOUNT = exports.CREATE_USER_ACCOUNT = exports.CONTRACT_TRANSACTION = exports.CONTRACT_PAYLOAD = exports.API = void 0;
3
+ exports.WEB_SOCKET_EVENTS = exports.FIND_WHERE_ADVANCED = exports.FIND_WHERE_BASIC = exports.GET_HISTORY = exports.PERSIST_NEW_DATA = exports.UPDATE_LAST_ITEM = exports.GET_TABLE = exports.CONNECT = exports.API_BASE = exports.DEFAULT_API_SERVER = void 0;
4
4
  // Contants
5
- exports.API = 'http://localhost:2818';
6
- exports.CONTRACT_PAYLOAD = '/get_last_contract_transaction';
7
- exports.CONTRACT_TRANSACTION = '/post_contract_transaction';
8
- exports.CREATE_USER_ACCOUNT = '/create_user_account';
9
- exports.GET_USER_ACCOUNT = '/get_user_account';
10
- exports.GET_USER_ACCOUNT_BY_ID = '/get_user_account_by_id';
11
- exports.TRANSFER_UNITS = '/transfer_units';
12
- exports.GET_TRANSFER_BY_USER_ID = '/get_transfer_by_user_id';
13
- exports.GET_ALL_TRANSFER_BY_USER_ID = '/get_all_transfers_by_user_id';
14
- exports.CHECK_USER_NAME = '/check_user_name';
5
+ exports.DEFAULT_API_SERVER = 'http://localhost:2818';
6
+ exports.API_BASE = '/api/v1';
7
+ exports.CONNECT = "".concat(exports.API_BASE, "/database/connect");
8
+ var GET_TABLE = function (table) { return "".concat(exports.API_BASE, "/table/").concat(table); };
9
+ exports.GET_TABLE = GET_TABLE;
10
+ var UPDATE_LAST_ITEM = function (table) { return "".concat(exports.API_BASE, "/table/").concat(table, "/update"); };
11
+ exports.UPDATE_LAST_ITEM = UPDATE_LAST_ITEM;
12
+ var PERSIST_NEW_DATA = function (table) { return "".concat(exports.API_BASE, "/table/").concat(table, "/persist"); };
13
+ exports.PERSIST_NEW_DATA = PERSIST_NEW_DATA;
14
+ var GET_HISTORY = function (table, limit) {
15
+ if (limit === void 0) { limit = 25; }
16
+ return "".concat(exports.API_BASE, "/table/").concat(table, "/history?limit=").concat(limit);
17
+ };
18
+ exports.GET_HISTORY = GET_HISTORY;
19
+ var FIND_WHERE_BASIC = function (table) { return "".concat(exports.API_BASE, "/table/").concat(table, "/find"); };
20
+ exports.FIND_WHERE_BASIC = FIND_WHERE_BASIC;
21
+ var FIND_WHERE_ADVANCED = function (table) { return "".concat(exports.API_BASE, "/table/").concat(table, "/find-advanced"); };
22
+ exports.FIND_WHERE_ADVANCED = FIND_WHERE_ADVANCED;
23
+ exports.WEB_SOCKET_EVENTS = "".concat(exports.API_BASE, "/events");
@@ -0,0 +1,28 @@
1
+ type EventCallback = (data: any) => void;
2
+ declare class Events {
3
+ private socket;
4
+ private eventListeners;
5
+ private connected;
6
+ constructor(url: string, auth: string);
7
+ /**
8
+ * Subscribe to an event
9
+ * @param event Event name to subscribe to
10
+ * @param callback Function to call when the event is received
11
+ */
12
+ subscribe(event: string, callback: EventCallback): void;
13
+ /**
14
+ * Unsubscribe from an event
15
+ * @param event Event name to unsubscribe from
16
+ * @param callback Optional callback to remove. If not provided, all callbacks for the event will be removed.
17
+ */
18
+ unsubscribe(event: string, callback?: EventCallback): void;
19
+ /**
20
+ * Close the WebSocket connection
21
+ */
22
+ close(): void;
23
+ /**
24
+ * Check if the WebSocket connection is established
25
+ */
26
+ isConnected(): boolean;
27
+ }
28
+ export default Events;