@onehat/data 1.13.3 → 1.13.5

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": "@onehat/data",
3
- "version": "1.13.3",
3
+ "version": "1.13.5",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -68,26 +68,35 @@ class AsyncStorageRepository extends OfflineRepository {
68
68
  console.log(this.name, 'AsyncStorage.multiGet results', keys, results);
69
69
  }
70
70
 
71
- let values = [];
71
+ const values = [];
72
72
  if (!_.isNil(results)) {
73
- _.each(results, ([key, value]) => {
74
- let parsed;
75
- try {
76
- parsed = JSON.parse(value);
77
- } catch (e) {
78
- parsed = value; // Invalid JSON, just return raw result
73
+ const chunks = _.chunk(results, 400); // create chunks of 400, which we'll iterate through, so we don't get "Excessive number of pending callbacks" error
74
+ let i, n, thisChunk, promises, promise, parsed;
75
+ for (i = 0; i < chunks.length; i++) { // iterate the chunks
76
+ thisChunk = chunks[i];
77
+ for (n = 0; n < thisChunk.length; n++) { // iterate the storage items
78
+ let [ key, value ] = thisChunk[n];
79
+
80
+ try {
81
+ parsed = JSON.parse(value);
82
+ } catch (e) {
83
+ parsed = value; // Invalid JSON, just return raw result
84
+ }
85
+ if (parsed === null) {
86
+ // Values should be stored as JSON, so it should be either {} or []. If it's null, that means the AsyncStorage can't find the record
87
+ // Delete the index to this record
88
+ const re = new RegExp('^' + this.name + '\-' + '(.*)'),
89
+ matches = key.match(re);
90
+ const id = parseInt(matches, 10);
91
+ promise = this._deleteFromIndex(id);
92
+ promises.push(promise);
93
+ } else {
94
+ values.push(parsed);
95
+ }
79
96
  }
80
- if (parsed === null) {
81
- // Values should be stored as JSON, so it should be either {} or []. If it's null, that means the AsyncStorage can't find the record
82
- // Delete the index to this record
83
- const re = new RegExp('^' + this.name + '\-' + '(.*)'),
84
- matches = key.match(re);
85
- const id = parseInt(matches, 10);
86
- this._deleteFromIndex(id);
87
- } else {
88
- values.push(parsed);
89
- }
90
- })
97
+
98
+ await Promise.all(promises);
99
+ }
91
100
  }
92
101
 
93
102
  // if (this.debugMode && _.size(keys) < 20) {
@@ -232,8 +232,49 @@ class OneBuildRepository extends AjaxRepository {
232
232
  };
233
233
  }
234
234
 
235
+
235
236
  /**
236
- * Login to OnBuild API
237
+ * Integrates with RestTrait::reorder in OneBuild API
238
+ * @param {entity} dragRecord - which entity was being dragged
239
+ * @param {entity} dropRecord - which entity it was dropped on to
240
+ * @param {string} dropPosition - position in which it was dropped; could be 'before' or 'after'
241
+ * @return {Promise}
242
+ */
243
+ reorder = (dragRecord, dropRecord, dropPosition) => {
244
+ const data = {
245
+ url: 'reorder',
246
+ data: qs.stringify({
247
+ ids: dragRecord.id,
248
+ dropPosition,
249
+ dropRecord_id: dropRecord.id,
250
+ }),
251
+ method: 'POST',
252
+ baseURL: this.api.baseURL,
253
+ };
254
+
255
+ if (this.debugMode) {
256
+ console.log('reorder', data);
257
+ }
258
+
259
+ return this.axios(data)
260
+ .then((result) => {
261
+ if (this.debugMode) {
262
+ console.log('reorder response', result);
263
+ }
264
+
265
+ const response = result.data;
266
+ if (!response.success) {
267
+ throw new Error(response.data);
268
+ }
269
+
270
+ // Reload the repository, so updated sort_order values can be retrieved
271
+ this.reload();
272
+
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Login to OneBuild API
237
278
  * @param {object} creds - object with two properties:
238
279
  * - username,
239
280
  * - password,
@@ -269,7 +310,7 @@ class OneBuildRepository extends AjaxRepository {
269
310
  }
270
311
 
271
312
  /**
272
- * Logout from OnBuild API
313
+ * Logout from OneBuild API
273
314
  * @return {Promise}
274
315
  */
275
316
  logout = () => {