@aicore/cocodb-ws-client 1.0.10 → 1.0.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aicore/cocodb-ws-client",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Websocket client for cocoDb",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -47,20 +47,20 @@
47
47
  },
48
48
  "homepage": "https://github.com/aicore/cocoDbWsClient#readme",
49
49
  "devDependencies": {
50
- "@commitlint/cli": "17.4.2",
51
- "@commitlint/config-conventional": "17.4.2",
52
- "c8": "7.12.0",
50
+ "@commitlint/cli": "17.4.3",
51
+ "@commitlint/config-conventional": "17.4.3",
52
+ "c8": "7.13.0",
53
53
  "chai": "4.3.7",
54
54
  "cli-color": "2.0.3",
55
55
  "documentation": "14.0.1",
56
- "eslint": "8.33.0",
56
+ "eslint": "8.34.0",
57
57
  "glob": "8.1.0",
58
58
  "husky": "8.0.3",
59
59
  "mocha": "10.2.0"
60
60
  },
61
61
  "dependencies": {
62
62
  "@aicore/libcommonutils": "1.0.19",
63
- "ws": "8.12.0"
63
+ "ws": "8.12.1"
64
64
  },
65
65
  "optionalDependencies": {
66
66
  "bufferutil": "4.0.7",
package/src/utils/api.js CHANGED
@@ -163,9 +163,14 @@ export function createIndex(tableName, jsonField, dataType, isUnique, isNotNull)
163
163
  * It returns list of documents matching the queryObject
164
164
  * @param {string} tableName - The name of the table you want to query.
165
165
  * @param{Object} queryObject - This is the object that you want to query the table with.
166
+ * @param {Object} options Optional parameter to add pagination.
167
+ * @param {number} options.pageOffset specify which row to start retrieving documents from. Eg: to get 10 documents from
168
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
169
+ * @param {number} options.pageLimit specify number of documents to retrieve. Eg: to get 10 documents from
170
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
166
171
  * @returns {Promise}
167
172
  */
168
- export function getFromIndex(tableName, queryObject) {
173
+ export function getFromIndex(tableName, queryObject, options= {}) {
169
174
  if (isStringEmpty(tableName)) {
170
175
  throw new Error('Please provide valid table name');
171
176
  }
@@ -177,7 +182,8 @@ export function getFromIndex(tableName, queryObject) {
177
182
  fn: COCO_DB_FUNCTIONS.getFromIndex,
178
183
  request: {
179
184
  tableName: tableName,
180
- queryObject: queryObject
185
+ queryObject: queryObject,
186
+ options
181
187
  }
182
188
  });
183
189
  }
@@ -186,9 +192,14 @@ export function getFromIndex(tableName, queryObject) {
186
192
  * It returns list of documents matching the queryObject after scanning the COCO DB
187
193
  * @param {string} tableName - The name of the table you want to query.
188
194
  * @param{Object} queryObject - This is the object that you want to query the table with.
195
+ * @param {Object} options Optional parameter to add pagination.
196
+ * @param {number} options.pageOffset specify which row to start retrieving documents from. Eg: to get 10 documents from
197
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
198
+ * @param {number} options.pageLimit specify number of documents to retrieve. Eg: to get 10 documents from
199
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
189
200
  * @returns {Promise}
190
201
  */
191
- export function getFromNonIndex(tableName, queryObject = {}) {
202
+ export function getFromNonIndex(tableName, queryObject = {}, options= {}) {
192
203
  if (isStringEmpty(tableName)) {
193
204
  throw new Error('Please provide valid table name');
194
205
  }
@@ -197,7 +208,8 @@ export function getFromNonIndex(tableName, queryObject = {}) {
197
208
  fn: COCO_DB_FUNCTIONS.getFromNonIndex,
198
209
  request: {
199
210
  tableName: tableName,
200
- queryObject: queryObject
211
+ queryObject: queryObject,
212
+ options
201
213
  }
202
214
  });
203
215
  }
@@ -307,9 +319,14 @@ export function update(tableName, documentId, document) {
307
319
  * @param {string} tableName - The name of the table you want to query.
308
320
  * @param {string} queryString - The query string to be executed.
309
321
  * @param {Array<string>}[useIndexForFields=null] - This is an array of fields that you want to use the index for.
322
+ * @param {Object} options Optional parameter to add pagination.
323
+ * @param {number} options.pageOffset specify which row to start retrieving documents from. Eg: to get 10 documents from
324
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
325
+ * @param {number} options.pageLimit specify number of documents to retrieve. Eg: to get 10 documents from
326
+ * the 100'th document, you should specify `pageOffset = 100` and `pageLimit = 10`
310
327
  * @returns {Promise}A promise
311
328
  */
312
- export function query(tableName, queryString, useIndexForFields = null) {
329
+ export function query(tableName, queryString, useIndexForFields = null, options= {}) {
313
330
  if (isStringEmpty(tableName)) {
314
331
  throw new Error('Please provide valid table name');
315
332
  }
@@ -322,7 +339,8 @@ export function query(tableName, queryString, useIndexForFields = null) {
322
339
  fn: COCO_DB_FUNCTIONS.query,
323
340
  request: {
324
341
  tableName: tableName,
325
- queryString: queryString
342
+ queryString: queryString,
343
+ options
326
344
  }
327
345
  });
328
346
  }
@@ -283,6 +283,8 @@ function _sendPendingMessages() {
283
283
  * @returns {Promise} A function that returns a promise.
284
284
  */
285
285
  export function sendMessage(message) {
286
+ // make a copy as the user may start modifying the object while we are sending it.
287
+ message = structuredClone(message);
286
288
  return new Promise(function (resolve, reject) {
287
289
  if(bufferRequests){
288
290
  if(pendingSendMessages.length > MAX_PENDING_SEND_BUFFER_SIZE){