@onehat/data 1.21.3 → 1.21.6

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.21.3",
3
+ "version": "1.21.6",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1761,9 +1761,9 @@ class Entity extends EventEmitter {
1761
1761
  parentIds.push(parent.id);
1762
1762
  parent = parent.parent;
1763
1763
  }
1764
- if (parent.id !== this.id) {
1764
+ // if (parent.id !== this.id) {
1765
1765
  parentIds.push(parent.id); // add root id
1766
- }
1766
+ // }
1767
1767
 
1768
1768
  return parentIds.reverse().join('/');
1769
1769
  }
@@ -31,6 +31,32 @@ export default class Command extends EventEmitter {
31
31
  this.setCheckReturnValues();
32
32
  }
33
33
 
34
+ useDefaultHandler() {
35
+ this.on('handleServerResponse', this.defaultHandler);
36
+ }
37
+
38
+ defaultHandler(entity) {
39
+
40
+ const response = entity.prop.response.parsedValue;
41
+
42
+ if (!response || !response.status) {
43
+ entity.isError = true;
44
+ entity.errorMsg = 'No discernable response from server.';
45
+ entity.handled = true;
46
+ return;
47
+ }
48
+
49
+ if (response.status !== 'OK') {
50
+ entity.isError = true;
51
+ entity.errorMsg = 'Encountered server error(s): ' + response.message;
52
+ entity.handled = true;
53
+ return;
54
+ }
55
+
56
+ // Success!
57
+ entity.handled = true;
58
+ }
59
+
34
60
  /**
35
61
  * Register a handler for this command.
36
62
  * @param {function} handler - The event handler
@@ -214,11 +214,15 @@ class LocalFromRemoteRepository extends EventEmitter {
214
214
  /**
215
215
  * Registers multiple commands for when syncing in MODE_COMMAND_QUEUE mode.
216
216
  */
217
- registerCommands(commands) {
217
+ registerCommands(commands, useDefaultHandler = true) {
218
218
  const oThis = this;
219
219
  _.each(commands, (name) => {
220
220
  if (!oThis.isRegisteredCommand(name)) {
221
- oThis.commands[name] = new Command(name);
221
+ const command = new Command(name);
222
+ if (useDefaultHandler) {
223
+ command.useDefaultHandler();
224
+ }
225
+ oThis.commands[name] = command;
222
226
  }
223
227
  });
224
228
  }
@@ -432,6 +432,7 @@ class OneBuildRepository extends AjaxRepository {
432
432
  }
433
433
 
434
434
  const entity = this.createStandaloneEntity(root[0]);
435
+ entity.isPersisted = true;
435
436
  entity.isRemotePhantom = false;
436
437
  return entity;
437
438
  })