dataflux 1.9.2 → 1.9.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/dist/BasicObj.js CHANGED
@@ -12,12 +12,12 @@ var _uuid = require("uuid");
12
12
 
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
14
 
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+
15
17
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
16
18
 
17
19
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
18
20
 
19
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
-
21
21
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
22
 
23
23
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
@@ -69,137 +69,144 @@ var _error = /*#__PURE__*/new WeakMap();
69
69
 
70
70
  var _model = /*#__PURE__*/new WeakMap();
71
71
 
72
- var BasicObj = /*#__PURE__*/_createClass(function BasicObj(values, model) {
73
- var _this = this;
72
+ var BasicObj = /*#__PURE__*/function () {
73
+ function BasicObj(values, model) {
74
+ var _this = this;
75
+
76
+ _classCallCheck(this, BasicObj);
77
+
78
+ _classPrivateFieldInitSpec(this, _setHidden, {
79
+ writable: true,
80
+ value: {}
81
+ });
82
+
83
+ _classPrivateFieldInitSpec(this, _id, {
84
+ writable: true,
85
+ value: null
86
+ });
87
+
88
+ _classPrivateFieldInitSpec(this, _error, {
89
+ writable: true,
90
+ value: {}
91
+ });
92
+
93
+ _classPrivateFieldInitSpec(this, _model, {
94
+ writable: true,
95
+ value: void 0
96
+ });
97
+
98
+ _defineProperty(this, "setId", function (id) {
99
+ _classPrivateFieldSet(_this, _id, id);
100
+ });
101
+
102
+ _defineProperty(this, "getId", function () {
103
+ if (!_classPrivateFieldGet(_this, _id)) {
104
+ if (_this.id && (typeof _this.id === "string" || typeof _this.id === "number")) {
105
+ _classPrivateFieldSet(_this, _id, _this.id.toString());
106
+
107
+ delete _this.setId;
108
+ } else {
109
+ _classPrivateFieldSet(_this, _id, (0, _uuid.v4)());
110
+ }
111
+ }
74
112
 
75
- _classCallCheck(this, BasicObj);
113
+ return _classPrivateFieldGet(_this, _id);
114
+ });
76
115
 
77
- _classPrivateFieldInitSpec(this, _setHidden, {
78
- writable: true,
79
- value: {}
80
- });
116
+ _defineProperty(this, "get", function (attribute, defaultValue) {
117
+ var _ref, _classPrivateFieldGet2;
81
118
 
82
- _classPrivateFieldInitSpec(this, _id, {
83
- writable: true,
84
- value: null
85
- });
119
+ return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
120
+ });
86
121
 
87
- _classPrivateFieldInitSpec(this, _error, {
88
- writable: true,
89
- value: {}
90
- });
122
+ _defineProperty(this, "getError", function () {
123
+ var _classPrivateFieldGet3;
91
124
 
92
- _classPrivateFieldInitSpec(this, _model, {
93
- writable: true,
94
- value: void 0
95
- });
125
+ var attribute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
126
+ var key = attribute ? attribute : globalError;
127
+ return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _error)[key]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : false;
128
+ });
96
129
 
97
- _defineProperty(this, "setId", function (id) {
98
- _classPrivateFieldSet(_this, _id, id);
99
- });
130
+ _defineProperty(this, "setError", function (error) {
131
+ var attribute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
100
132
 
101
- _defineProperty(this, "getId", function () {
102
- if (!_classPrivateFieldGet(_this, _id)) {
103
- if (_this.id && (typeof _this.id === "string" || typeof _this.id === "number")) {
104
- _classPrivateFieldSet(_this, _id, _this.id.toString());
105
-
106
- delete _this.setId;
133
+ if (error && attribute) {
134
+ _classPrivateFieldGet(_this, _error)[attribute] = error;
135
+ } else if (error && !attribute) {
136
+ _classPrivateFieldGet(_this, _error)[globalError] = error;
137
+ } else if (!error && attribute) {
138
+ delete _classPrivateFieldGet(_this, _error)[attribute];
107
139
  } else {
108
- _classPrivateFieldSet(_this, _id, (0, _uuid.v4)());
140
+ _classPrivateFieldSet(_this, _error, {});
109
141
  }
110
- }
111
-
112
- return _classPrivateFieldGet(_this, _id);
113
- });
114
-
115
- _defineProperty(this, "get", function (attribute, defaultValue) {
116
- var _ref, _classPrivateFieldGet2;
117
-
118
- return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
119
- });
120
-
121
- _defineProperty(this, "set", function (attribute, value, hidden) {
122
- if (hidden) {
123
- _classPrivateFieldGet(_this, _setHidden)[attribute] = value;
124
- } else {
125
- if (attribute === "id") {
126
- throw new Error("You cannot change the ID");
142
+ });
143
+
144
+ _defineProperty(this, "setConstant", function (attribute, value) {
145
+ var _classPrivateFieldGet4;
146
+
147
+ _classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet4 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet4 !== void 0 ? _classPrivateFieldGet4 : value;
148
+ });
149
+
150
+ _defineProperty(this, "toJSON", function () {
151
+ var attrs = Object.keys(_this);
152
+ var out = {};
153
+
154
+ for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
155
+ var a = _attrs[_i];
156
+
157
+ if (_this[a] == null) {
158
+ out[a] = _this[a];
159
+ } else if (_this[a] instanceof _moment["default"]) {
160
+ out[a] = _this[a].toISOString();
161
+ } else if (_this[a] instanceof Date) {
162
+ out[a] = (0, _moment["default"])(_this[a]).toISOString();
163
+ } else if (_typeof(_this[a]) === "object" && _this[a].toJSON) {
164
+ out[a] = _this[a].toJSON();
165
+ } else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
166
+ return _typeof(i) === "object" && i.toJSON;
167
+ })) {
168
+ out[a] = _this[a].map(function (i) {
169
+ return i.toJSON();
170
+ });
171
+ } else if (typeof _this[a] !== "function") {
172
+ out[a] = _this[a];
173
+ }
127
174
  }
128
175
 
129
- _this[attribute] = value;
176
+ return out;
177
+ });
130
178
 
131
- _classPrivateFieldGet(_this, _model).validateObjectAttribute(_this, attribute);
132
- }
133
-
134
- return _this.update();
135
- });
179
+ _defineProperty(this, "toString", function () {
180
+ return JSON.stringify(_this.toJSON());
181
+ });
136
182
 
137
- _defineProperty(this, "getError", function () {
138
- var _classPrivateFieldGet3;
139
-
140
- var attribute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
141
- var key = attribute ? attribute : globalError;
142
- return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _error)[key]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : false;
143
- });
183
+ _defineProperty(this, "update", function () {
184
+ return Promise.resolve();
185
+ });
144
186
 
145
- _defineProperty(this, "setError", function (error) {
146
- var attribute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
187
+ _classPrivateFieldSet(this, _model, model);
188
+ }
147
189
 
148
- if (error && attribute) {
149
- _classPrivateFieldGet(_this, _error)[attribute] = error;
150
- } else if (error && !attribute) {
151
- _classPrivateFieldGet(_this, _error)[globalError] = error;
152
- } else if (!error && attribute) {
153
- delete _classPrivateFieldGet(_this, _error)[attribute];
154
- } else {
155
- _classPrivateFieldSet(_this, _error, {});
156
- }
157
- });
190
+ _createClass(BasicObj, [{
191
+ key: "set",
192
+ value: function set(attribute, value, hidden) {
193
+ if (hidden) {
194
+ _classPrivateFieldGet(this, _setHidden)[attribute] = value;
195
+ } else {
196
+ if (attribute === "id") {
197
+ throw new Error("You cannot change the ID");
198
+ }
158
199
 
159
- _defineProperty(this, "setConstant", function (attribute, value) {
160
- var _classPrivateFieldGet4;
200
+ this[attribute] = value;
161
201
 
162
- _classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet4 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet4 !== void 0 ? _classPrivateFieldGet4 : value;
163
- });
164
-
165
- _defineProperty(this, "toJSON", function () {
166
- var attrs = Object.keys(_this);
167
- var out = {};
168
-
169
- for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
170
- var a = _attrs[_i];
171
-
172
- if (_this[a] == null) {
173
- out[a] = _this[a];
174
- } else if (_this[a] instanceof _moment["default"]) {
175
- out[a] = _this[a].toISOString();
176
- } else if (_this[a] instanceof Date) {
177
- out[a] = (0, _moment["default"])(_this[a]).toISOString();
178
- } else if (_typeof(_this[a]) === "object" && _this[a].toJSON) {
179
- out[a] = _this[a].toJSON();
180
- } else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
181
- return _typeof(i) === "object" && i.toJSON;
182
- })) {
183
- out[a] = _this[a].map(function (i) {
184
- return i.toJSON();
185
- });
186
- } else if (typeof _this[a] !== "function") {
187
- out[a] = _this[a];
202
+ _classPrivateFieldGet(this, _model).validateObjectAttribute(this, attribute);
188
203
  }
189
- }
190
204
 
191
- return out;
192
- });
193
-
194
- _defineProperty(this, "toString", function () {
195
- return JSON.stringify(_this.toJSON());
196
- });
197
-
198
- _defineProperty(this, "update", function () {
199
- return Promise.resolve();
200
- });
205
+ return this.update();
206
+ }
207
+ }]);
201
208
 
202
- _classPrivateFieldSet(this, _model, model);
203
- });
209
+ return BasicObj;
210
+ }();
204
211
 
205
212
  exports.BasicObj = BasicObj;
package/dist/Model.js CHANGED
@@ -416,7 +416,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
416
416
  value: function value(objects) {
417
417
  var operation = "insert";
418
418
  return (0, _modelHooksUtils.executeHook)(operation, _classPrivateFieldGet(_this, _insertHook), _classPrivateFieldGet(_this, _unWrap).call(_this, objects), _classPrivateFieldGet(_this, _axios)).then(function (data) {
419
- if (data) _classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
419
+ if (data) {
420
+ _classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
421
+ }
420
422
 
421
423
  _classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
422
424
 
@@ -432,7 +434,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
432
434
  _classPrivateFieldInitSpec(this, _assignId, {
433
435
  writable: true,
434
436
  value: function value(data, objects) {
435
- if (data.length === 1) {
437
+ if (data.length === 1 && objects.length === 1) {
436
438
  var newId = data[0].id;
437
439
  objects[0].setId(newId);
438
440
  delete objects[0].setId;
package/dist/Obj.js CHANGED
@@ -23,7 +23,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
23
23
 
24
24
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
25
25
 
26
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
27
27
 
28
28
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
29
29
 
@@ -33,7 +33,11 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
33
33
 
34
34
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
35
35
 
36
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
36
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
37
+
38
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
39
+
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
41
 
38
42
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39
43
 
@@ -59,7 +63,7 @@ var Obj = /*#__PURE__*/function (_BasicObj) {
59
63
  var _super = _createSuper(Obj);
60
64
 
61
65
  function Obj(values, _model) {
62
- var _this;
66
+ var _thisSuper, _this;
63
67
 
64
68
  _classCallCheck(this, Obj);
65
69
 
@@ -70,6 +74,16 @@ var Obj = /*#__PURE__*/function (_BasicObj) {
70
74
  value: false
71
75
  });
72
76
 
77
+ _defineProperty(_assertThisInitialized(_this), "set", function (attribute, value, hidden) {
78
+ if (Array.isArray(value) && _this.getModel().options.deep) {
79
+ value = value.map(function (i) {
80
+ return i !== null && i !== void 0 && i.getId ? i : new _SubObj["default"](_assertThisInitialized(_this), "property", i, _this.getModel());
81
+ });
82
+ }
83
+
84
+ return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(Obj.prototype)), "set", _thisSuper).call(_thisSuper, attribute, value, hidden);
85
+ });
86
+
73
87
  _defineProperty(_assertThisInitialized(_this), "load", function () {
74
88
  if (_classPrivateFieldGet(_assertThisInitialized(_this), _loaded)) {
75
89
  return Promise.resolve(_assertThisInitialized(_this));
@@ -35,13 +35,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
35
35
 
36
36
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
37
 
38
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
38
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
39
39
 
40
40
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
41
41
 
42
42
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
43
43
 
44
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
44
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
45
45
 
46
46
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
47
47
 
@@ -51,7 +51,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
51
51
 
52
52
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
53
53
 
54
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
54
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
55
55
 
56
56
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
57
57
 
@@ -81,8 +81,12 @@ var _getUniqueSubs = /*#__PURE__*/new WeakMap();
81
81
 
82
82
  var _propagateChange = /*#__PURE__*/new WeakMap();
83
83
 
84
+ var _appendIfNotExistent = /*#__PURE__*/new WeakMap();
85
+
84
86
  var _subscribeToObjects = /*#__PURE__*/new WeakMap();
85
87
 
88
+ var _merge = /*#__PURE__*/new WeakMap();
89
+
86
90
  var _propagateInsertChange = /*#__PURE__*/new WeakSet();
87
91
 
88
92
  var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
@@ -165,40 +169,41 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
165
169
  });
166
170
 
167
171
  _defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
168
- if (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length) {
169
- _classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)).then(function () {
170
- if (_this._multipleSubscribed[key]) {
171
- var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
172
- _step;
172
+ _classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length ? Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)) : Promise.resolve()).then(function () {
173
+ if (_this._multipleSubscribed[key]) {
174
+ var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
175
+ _step;
173
176
 
174
- try {
175
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
176
- var sub = _step.value;
177
+ try {
178
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
179
+ var sub = _step.value;
177
180
 
178
- _this.unsubscribe(sub);
179
- }
180
- } catch (err) {
181
- _iterator.e(err);
182
- } finally {
183
- _iterator.f();
181
+ _this.unsubscribe(sub);
184
182
  }
183
+ } catch (err) {
184
+ _iterator.e(err);
185
+ } finally {
186
+ _iterator.f();
187
+ }
185
188
 
186
- delete _this._multipleSubscribed[key];
187
- } else {
188
- for (var type in _this._subscribed) {
189
- for (var id in _this._subscribed[type]) {
190
- _this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
191
- return i.subKey !== key;
192
- });
193
-
194
- if (_this._subscribed[type][id].length === 0) {
195
- delete _this._subscribed[type][id];
196
- }
189
+ delete _this._multipleSubscribed[key];
190
+ } else {
191
+ for (var type in _this._subscribed) {
192
+ for (var id in _this._subscribed[type]) {
193
+ _this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
194
+ return i.subKey !== key;
195
+ });
196
+ _this._subscribed[type]["*"] = _this._subscribed[type]["*"].filter(function (i) {
197
+ return i.subKey !== key;
198
+ });
199
+
200
+ if (_this._subscribed[type][id].length === 0) {
201
+ delete _this._subscribed[type][id];
197
202
  }
198
203
  }
199
204
  }
200
- }));
201
- }
205
+ }
206
+ }));
202
207
  });
203
208
 
204
209
  _classPrivateFieldInitSpec(_assertThisInitialized(_this), _getUniqueSubs, {
@@ -264,32 +269,98 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
264
269
  }
265
270
  });
266
271
 
272
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _appendIfNotExistent, {
273
+ writable: true,
274
+ value: function value(arr, item) {
275
+ if (Object.values(arr).filter(function (_ref4) {
276
+ var subKey = _ref4.subKey;
277
+ return item.subKey === subKey;
278
+ }).length === 0) {
279
+ arr.push(item);
280
+ }
281
+ }
282
+ });
283
+
267
284
  _classPrivateFieldInitSpec(_assertThisInitialized(_this), _subscribeToObjects, {
268
285
  writable: true,
269
286
  value: function value(type, objectsToSubscribe, item) {
287
+ var _this$_subscribed$typ2, _, _this$_subscribed$typ3;
288
+
270
289
  var _iterator4 = _createForOfIteratorHelper(objectsToSubscribe),
271
290
  _step4;
272
291
 
273
292
  try {
274
293
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
275
- var _this$_subscribed$typ2, _this$_subscribed$typ3;
294
+ var _this$_subscribed$typ4, _this$_subscribed$typ5;
276
295
 
277
296
  var object = _step4.value;
278
297
  var id = object.getId();
279
- (_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[id] = [];
298
+ (_this$_subscribed$typ5 = (_this$_subscribed$typ4 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ5 !== void 0 ? _this$_subscribed$typ5 : _this$_subscribed$typ4[id] = [];
280
299
 
281
- _this._subscribed[type][id].push(item);
300
+ _classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type][id], item);
282
301
  }
283
302
  } catch (err) {
284
303
  _iterator4.e(err);
285
304
  } finally {
286
305
  _iterator4.f();
287
306
  }
307
+
308
+ (_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[_ = "*"]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[_] = [];
309
+
310
+ _classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type]["*"], item);
311
+ }
312
+ });
313
+
314
+ _defineProperty(_assertThisInitialized(_this), "refresh", function (type) {
315
+ var refreshByType = function refreshByType(type) {
316
+ _this.pubSub.publish("refresh", {
317
+ status: "start",
318
+ model: type
319
+ });
320
+
321
+ return _this.refreshObjectByType(type).then(function (_ref5) {
322
+ var _ref6 = _slicedToArray(_ref5, 3),
323
+ inserted = _ref6[0],
324
+ updated = _ref6[1],
325
+ deleted = _ref6[2];
326
+
327
+ var item = _this.models[type];
328
+ return Promise.all([_classPrivateMethodGet(_assertThisInitialized(_this), _propagateInsertChange, _propagateInsertChange2).call(_assertThisInitialized(_this), type, inserted), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), updated), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), deleted)]).then(function () {
329
+ _this.pubSub.publish("refresh", {
330
+ status: "end",
331
+ model: type
332
+ });
333
+
334
+ return item.promise;
335
+ });
336
+ });
337
+ };
338
+
339
+ if (type) {
340
+ return refreshByType(type);
341
+ } else {
342
+ return Promise.all(Object.keys(_this.models).map(refreshByType));
343
+ }
344
+ });
345
+
346
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _merge, {
347
+ writable: true,
348
+ value: function value(originalObject, newObject) {
349
+ for (var key in newObject) {
350
+ originalObject[key] = newObject[key];
351
+ }
352
+
353
+ originalObject.update();
288
354
  }
289
355
  });
290
356
 
291
357
  _this._subscribed = {};
292
358
  _this._multipleSubscribed = {};
359
+
360
+ if (options.autoRefresh && typeof options.autoRefresh === "number") {
361
+ setInterval(_this.refresh, options.autoRefresh);
362
+ }
363
+
293
364
  return _this;
294
365
  }
295
366
 
@@ -362,34 +433,15 @@ function _propagateInsertChange2(type, newObjects) {
362
433
  }
363
434
 
364
435
  var possibleSubs = Object.values(uniqueSubs);
365
- (0, _batchPromises["default"])(10, possibleSubs, function (_ref4) {
366
- var callback = _ref4.callback,
367
- filterFunction = _ref4.filterFunction;
436
+ (0, _batchPromises["default"])(10, possibleSubs, function (_ref7) {
437
+ var callback = _ref7.callback,
438
+ filterFunction = _ref7.filterFunction,
439
+ subKey = _ref7.subKey;
368
440
  var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
369
441
 
370
442
  if (objectsToSubscribe.length) {
371
443
  // Check if the new objects matter
372
444
  return _this4.find(type, filterFunction).then(function (data) {
373
- var subKey;
374
-
375
- var _iterator6 = _createForOfIteratorHelper(data),
376
- _step6;
377
-
378
- try {
379
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
380
- var d = _step6.value;
381
-
382
- var item = _this4._subscribed[d.getModel().getType()][d.getId()];
383
-
384
- subKey = item ? item.subKey : null;
385
- if (subKey) break;
386
- }
387
- } catch (err) {
388
- _iterator6.e(err);
389
- } finally {
390
- _iterator6.f();
391
- }
392
-
393
445
  _classPrivateFieldGet(_this4, _subscribeToObjects).call(_this4, type, objectsToSubscribe, {
394
446
  callback: callback,
395
447
  filterFunction: filterFunction,
@@ -23,13 +23,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
23
23
 
24
24
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
25
 
26
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
26
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
27
27
 
28
28
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
29
29
 
30
30
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
31
 
32
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
33
 
34
34
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
35
35
 
@@ -39,7 +39,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
39
39
 
40
40
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
41
41
 
42
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
42
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
43
 
44
44
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
45
45
 
@@ -29,7 +29,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
29
29
 
30
30
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
31
 
32
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
33
 
34
34
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
35
35
 
@@ -39,7 +39,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
39
39
 
40
40
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
41
41
 
42
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
42
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
43
 
44
44
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
45
45