dataflux 1.10.3 → 1.10.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 +0 -53
- package/dist/Model.js +24 -148
- package/dist/Obj.js +0 -47
- package/dist/ObserverStore.js +21 -131
- package/dist/PersistentStore.js +10 -61
- package/dist/PubSub.js +1 -17
- package/dist/ReactStore.js +1 -52
- package/dist/Store.js +16 -116
- package/dist/SubObj.js +0 -45
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/dist/fingerprint.js +1 -19
- package/dist/index.js +0 -3
- package/dist/modelHooksUtils.js +0 -28
- package/package.json +10 -10
package/dist/Model.js
CHANGED
|
@@ -4,198 +4,134 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _modelHooksUtils = require("./modelHooksUtils");
|
|
9
|
-
|
|
10
8
|
var _axios2 = _interopRequireDefault(require("axios"));
|
|
11
|
-
|
|
12
9
|
var _BasicObj = require("./BasicObj");
|
|
13
|
-
|
|
14
10
|
var _SubObj = _interopRequireDefault(require("./SubObj"));
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
|
|
18
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
19
|
-
|
|
20
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
-
|
|
22
14
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
23
|
-
|
|
24
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
-
|
|
26
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
-
|
|
30
18
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
31
|
-
|
|
32
19
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
33
|
-
|
|
34
20
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
35
|
-
|
|
36
21
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
37
|
-
|
|
38
22
|
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); } }
|
|
39
|
-
|
|
40
23
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
41
|
-
|
|
42
24
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
43
|
-
|
|
44
25
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
45
|
-
|
|
46
26
|
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; }
|
|
47
|
-
|
|
48
27
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
49
|
-
|
|
50
28
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
51
|
-
|
|
52
29
|
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
53
|
-
|
|
54
30
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
55
|
-
|
|
56
31
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
57
|
-
|
|
58
32
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
59
|
-
|
|
60
33
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
61
|
-
|
|
62
34
|
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
63
|
-
|
|
64
35
|
var _type = /*#__PURE__*/new WeakMap();
|
|
65
|
-
|
|
66
36
|
var _store = /*#__PURE__*/new WeakMap();
|
|
67
|
-
|
|
68
37
|
var _includes = /*#__PURE__*/new WeakMap();
|
|
69
|
-
|
|
70
38
|
var _retrieveHook = /*#__PURE__*/new WeakMap();
|
|
71
|
-
|
|
72
39
|
var _updateHook = /*#__PURE__*/new WeakMap();
|
|
73
|
-
|
|
74
40
|
var _insertHook = /*#__PURE__*/new WeakMap();
|
|
75
|
-
|
|
76
41
|
var _deleteHook = /*#__PURE__*/new WeakMap();
|
|
77
|
-
|
|
78
42
|
var _singleItemQuery = /*#__PURE__*/new WeakMap();
|
|
79
|
-
|
|
80
43
|
var _batchSize = /*#__PURE__*/new WeakMap();
|
|
81
|
-
|
|
82
44
|
var _axios = /*#__PURE__*/new WeakMap();
|
|
83
|
-
|
|
84
45
|
var _loadFunction = /*#__PURE__*/new WeakMap();
|
|
85
|
-
|
|
86
46
|
var _hiddenFields = /*#__PURE__*/new WeakMap();
|
|
87
|
-
|
|
88
47
|
var _error = /*#__PURE__*/new WeakSet();
|
|
89
|
-
|
|
90
48
|
var _addRelationByField = /*#__PURE__*/new WeakMap();
|
|
91
|
-
|
|
92
49
|
var _addRelationByFilter = /*#__PURE__*/new WeakMap();
|
|
93
|
-
|
|
94
50
|
var _removeHiddenFields = /*#__PURE__*/new WeakMap();
|
|
95
|
-
|
|
96
51
|
var _toArray = /*#__PURE__*/new WeakMap();
|
|
97
|
-
|
|
98
52
|
var _unWrap = /*#__PURE__*/new WeakMap();
|
|
99
|
-
|
|
100
53
|
var _insertObjects = /*#__PURE__*/new WeakMap();
|
|
101
|
-
|
|
102
54
|
var _assignId = /*#__PURE__*/new WeakMap();
|
|
103
|
-
|
|
104
55
|
var _updateObjects = /*#__PURE__*/new WeakMap();
|
|
105
|
-
|
|
106
56
|
var _deleteObjects = /*#__PURE__*/new WeakMap();
|
|
107
|
-
|
|
108
57
|
var _hanldeApiError = /*#__PURE__*/new WeakMap();
|
|
109
|
-
|
|
110
58
|
var _cleanApiError = /*#__PURE__*/new WeakMap();
|
|
111
|
-
|
|
112
59
|
var _removeFromStoreSilentlyAfterFailure = /*#__PURE__*/new WeakMap();
|
|
113
|
-
|
|
114
60
|
var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
115
61
|
var _this = this,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
62
|
+
_options$deep,
|
|
63
|
+
_options$parseMoment,
|
|
64
|
+
_options$validate;
|
|
120
65
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
121
|
-
|
|
122
66
|
_classCallCheck(this, Model);
|
|
123
|
-
|
|
124
67
|
_classPrivateMethodInitSpec(this, _error);
|
|
125
|
-
|
|
126
68
|
_classPrivateFieldInitSpec(this, _type, {
|
|
127
69
|
writable: true,
|
|
128
70
|
value: void 0
|
|
129
71
|
});
|
|
130
|
-
|
|
131
72
|
_classPrivateFieldInitSpec(this, _store, {
|
|
132
73
|
writable: true,
|
|
133
74
|
value: void 0
|
|
134
75
|
});
|
|
135
|
-
|
|
136
76
|
_classPrivateFieldInitSpec(this, _includes, {
|
|
137
77
|
writable: true,
|
|
138
78
|
value: void 0
|
|
139
79
|
});
|
|
140
|
-
|
|
141
80
|
_classPrivateFieldInitSpec(this, _retrieveHook, {
|
|
142
81
|
writable: true,
|
|
143
82
|
value: void 0
|
|
144
83
|
});
|
|
145
|
-
|
|
146
84
|
_classPrivateFieldInitSpec(this, _updateHook, {
|
|
147
85
|
writable: true,
|
|
148
86
|
value: void 0
|
|
149
87
|
});
|
|
150
|
-
|
|
151
88
|
_classPrivateFieldInitSpec(this, _insertHook, {
|
|
152
89
|
writable: true,
|
|
153
90
|
value: void 0
|
|
154
91
|
});
|
|
155
|
-
|
|
156
92
|
_classPrivateFieldInitSpec(this, _deleteHook, {
|
|
157
93
|
writable: true,
|
|
158
94
|
value: void 0
|
|
159
95
|
});
|
|
160
|
-
|
|
161
96
|
_classPrivateFieldInitSpec(this, _singleItemQuery, {
|
|
162
97
|
writable: true,
|
|
163
98
|
value: void 0
|
|
164
99
|
});
|
|
165
|
-
|
|
166
100
|
_classPrivateFieldInitSpec(this, _batchSize, {
|
|
167
101
|
writable: true,
|
|
168
102
|
value: void 0
|
|
169
103
|
});
|
|
170
|
-
|
|
171
104
|
_classPrivateFieldInitSpec(this, _axios, {
|
|
172
105
|
writable: true,
|
|
173
106
|
value: void 0
|
|
174
107
|
});
|
|
175
|
-
|
|
176
108
|
_classPrivateFieldInitSpec(this, _loadFunction, {
|
|
177
109
|
writable: true,
|
|
178
110
|
value: void 0
|
|
179
111
|
});
|
|
180
|
-
|
|
181
112
|
_classPrivateFieldInitSpec(this, _hiddenFields, {
|
|
182
113
|
writable: true,
|
|
183
114
|
value: void 0
|
|
184
115
|
});
|
|
185
|
-
|
|
186
116
|
_defineProperty(this, "validateObjectAttribute", function (object, key) {
|
|
187
117
|
var validate = _this.options.validate;
|
|
188
|
-
|
|
189
118
|
if (validate && validate[key]) {
|
|
190
119
|
try {
|
|
191
|
-
validate[key](object);
|
|
192
|
-
|
|
120
|
+
var call = validate[key](object, _classPrivateFieldGet(_this, _store));
|
|
121
|
+
if (call.then) {
|
|
122
|
+
call.then(function () {
|
|
123
|
+
return object.setError(false, key);
|
|
124
|
+
})["catch"](function (error) {
|
|
125
|
+
return object.setError(error.message, key);
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
object.setError(false, key);
|
|
129
|
+
}
|
|
193
130
|
} catch (error) {
|
|
194
131
|
object.setError(error.message, key);
|
|
195
132
|
}
|
|
196
133
|
}
|
|
197
134
|
});
|
|
198
|
-
|
|
199
135
|
_defineProperty(this, "isObjectValid", function (object) {
|
|
200
136
|
for (var key in object) {
|
|
201
137
|
if (typeof object[key] !== "function") {
|
|
@@ -204,14 +140,11 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
204
140
|
}
|
|
205
141
|
}
|
|
206
142
|
}
|
|
207
|
-
|
|
208
143
|
return true;
|
|
209
144
|
});
|
|
210
|
-
|
|
211
145
|
_defineProperty(this, "getStore", function () {
|
|
212
146
|
return _classPrivateFieldGet(_this, _store);
|
|
213
147
|
});
|
|
214
|
-
|
|
215
148
|
_defineProperty(this, "setStore", function (store) {
|
|
216
149
|
if (!_classPrivateFieldGet(_this, _store)) {
|
|
217
150
|
_classPrivateFieldSet(_this, _store, store);
|
|
@@ -219,7 +152,6 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
219
152
|
throw new Error("This model was already assigned to a store.");
|
|
220
153
|
}
|
|
221
154
|
});
|
|
222
|
-
|
|
223
155
|
_defineProperty(this, "load", function (obj) {
|
|
224
156
|
if (_classPrivateFieldGet(_this, _loadFunction)) {
|
|
225
157
|
return _this.getStore().whenSaved(_this.getType())["catch"](function (e) {
|
|
@@ -227,7 +159,6 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
227
159
|
}).then(function () {
|
|
228
160
|
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON()); // toJSON to avoid side effects;
|
|
229
161
|
|
|
230
|
-
|
|
231
162
|
if (typeof res === "string") {
|
|
232
163
|
return _classPrivateFieldGet(_this, _axios).call(_this, {
|
|
233
164
|
method: "get",
|
|
@@ -249,11 +180,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
249
180
|
return _classPrivateMethodGet(_this, _error, _error2).call(_this, "You must define a loading function in the model to enable load().");
|
|
250
181
|
}
|
|
251
182
|
});
|
|
252
|
-
|
|
253
183
|
_defineProperty(this, "addRelation", function (model, param2, param3) {
|
|
254
184
|
if (model) {
|
|
255
185
|
_this.getStore().validateModel(model);
|
|
256
|
-
|
|
257
186
|
if (typeof param2 === "string" && (!param3 || typeof param3 === "string")) {
|
|
258
187
|
// explicit model, from, to
|
|
259
188
|
return _classPrivateFieldGet(_this, _addRelationByField).call(_this, model, param2, param3);
|
|
@@ -270,10 +199,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
270
199
|
throw new Error("A relation needs a model");
|
|
271
200
|
}
|
|
272
201
|
});
|
|
273
|
-
|
|
274
202
|
_defineProperty(this, "getRelation", function (parentObject, includedType, filterFunction) {
|
|
275
203
|
var filterRelation = _classPrivateFieldGet(_this, _includes)[includedType];
|
|
276
|
-
|
|
277
204
|
if (filterRelation) {
|
|
278
205
|
return (parentObject.getModel().options.load ? parentObject.load()["catch"](function () {}) : Promise.resolve()).then(function () {
|
|
279
206
|
return _this.getStore().find(includedType, function (item) {
|
|
@@ -286,33 +213,26 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
286
213
|
return _classPrivateMethodGet(_this, _error, _error2).call(_this, "The relation doesn't exist");
|
|
287
214
|
}
|
|
288
215
|
});
|
|
289
|
-
|
|
290
216
|
_defineProperty(this, "getType", function () {
|
|
291
217
|
return _classPrivateFieldGet(_this, _type);
|
|
292
218
|
});
|
|
293
|
-
|
|
294
219
|
_defineProperty(this, "retrieveAll", function () {
|
|
295
220
|
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), null, _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
296
221
|
if (!Array.isArray(data)) {
|
|
297
222
|
_classPrivateFieldSet(_this, _singleItemQuery, true);
|
|
298
223
|
}
|
|
299
|
-
|
|
300
224
|
return _classPrivateFieldGet(_this, _toArray).call(_this, data);
|
|
301
225
|
});
|
|
302
226
|
});
|
|
303
|
-
|
|
304
227
|
_defineProperty(this, "insertObjects", function (objects) {
|
|
305
228
|
return objects.length ? _classPrivateFieldGet(_this, _insertObjects).call(_this, objects) : Promise.resolve();
|
|
306
229
|
});
|
|
307
|
-
|
|
308
230
|
_defineProperty(this, "updateObjects", function (objects) {
|
|
309
231
|
return objects.length ? _classPrivateFieldGet(_this, _updateObjects).call(_this, objects) : Promise.resolve();
|
|
310
232
|
});
|
|
311
|
-
|
|
312
233
|
_defineProperty(this, "deleteObjects", function (objects) {
|
|
313
234
|
return objects.length ? _classPrivateFieldGet(_this, _deleteObjects).call(_this, objects) : Promise.resolve();
|
|
314
235
|
});
|
|
315
|
-
|
|
316
236
|
_defineProperty(this, "factory", function (params) {
|
|
317
237
|
if (!_this.options.lazyLoad) {
|
|
318
238
|
return Promise.reject("Factory can be used only on a model declared with lazyLoad: true");
|
|
@@ -321,25 +241,20 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
321
241
|
if (!Array.isArray(data)) {
|
|
322
242
|
_classPrivateFieldSet(_this, _singleItemQuery, true);
|
|
323
243
|
}
|
|
324
|
-
|
|
325
244
|
return _classPrivateFieldGet(_this, _toArray).call(_this, data);
|
|
326
245
|
});
|
|
327
246
|
}
|
|
328
247
|
});
|
|
329
|
-
|
|
330
248
|
_classPrivateFieldInitSpec(this, _addRelationByField, {
|
|
331
249
|
writable: true,
|
|
332
250
|
value: function value(model, localField) {
|
|
333
251
|
var remoteField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "id";
|
|
334
|
-
|
|
335
252
|
var filterFunction = function filterFunction(parentObject, child) {
|
|
336
253
|
return parentObject[localField] === child[remoteField];
|
|
337
254
|
};
|
|
338
|
-
|
|
339
255
|
return _classPrivateFieldGet(_this, _addRelationByFilter).call(_this, model, filterFunction);
|
|
340
256
|
}
|
|
341
257
|
});
|
|
342
|
-
|
|
343
258
|
_classPrivateFieldInitSpec(this, _addRelationByFilter, {
|
|
344
259
|
writable: true,
|
|
345
260
|
value: function value(model, filterFunction) {
|
|
@@ -347,13 +262,11 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
347
262
|
_classPrivateFieldGet(_this, _includes)[includedType] = filterFunction;
|
|
348
263
|
}
|
|
349
264
|
});
|
|
350
|
-
|
|
351
265
|
_classPrivateFieldInitSpec(this, _removeHiddenFields, {
|
|
352
266
|
writable: true,
|
|
353
267
|
value: function value(json) {
|
|
354
268
|
var _iterator = _createForOfIteratorHelper(_classPrivateFieldGet(_this, _hiddenFields)),
|
|
355
|
-
|
|
356
|
-
|
|
269
|
+
_step;
|
|
357
270
|
try {
|
|
358
271
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
359
272
|
var attribute = _step.value;
|
|
@@ -364,11 +277,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
364
277
|
} finally {
|
|
365
278
|
_iterator.f();
|
|
366
279
|
}
|
|
367
|
-
|
|
368
280
|
return json;
|
|
369
281
|
}
|
|
370
282
|
});
|
|
371
|
-
|
|
372
283
|
_classPrivateFieldInitSpec(this, _toArray, {
|
|
373
284
|
writable: true,
|
|
374
285
|
value: function value(data) {
|
|
@@ -393,14 +304,12 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
393
304
|
}
|
|
394
305
|
}
|
|
395
306
|
});
|
|
396
|
-
|
|
397
307
|
_classPrivateFieldInitSpec(this, _unWrap, {
|
|
398
308
|
writable: true,
|
|
399
309
|
value: function value(objects) {
|
|
400
310
|
var data = Object.values(objects).map(function (object) {
|
|
401
311
|
return _classPrivateFieldGet(_this, _removeHiddenFields).call(_this, object.toJSON());
|
|
402
312
|
});
|
|
403
|
-
|
|
404
313
|
if (data.value != null && Object.keys(data).length === 1) {
|
|
405
314
|
return data.value;
|
|
406
315
|
} else if (Array.isArray(data) && data.length === 1 && data[0].value != null && Object.keys(data[0]).length === 1) {
|
|
@@ -410,7 +319,6 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
410
319
|
}
|
|
411
320
|
}
|
|
412
321
|
});
|
|
413
|
-
|
|
414
322
|
_classPrivateFieldInitSpec(this, _insertObjects, {
|
|
415
323
|
writable: true,
|
|
416
324
|
value: function value(objects) {
|
|
@@ -419,18 +327,14 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
419
327
|
if (data) {
|
|
420
328
|
_classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
|
|
421
329
|
}
|
|
422
|
-
|
|
423
330
|
_classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
|
|
424
|
-
|
|
425
331
|
return data;
|
|
426
332
|
}).then(_classPrivateFieldGet(_this, _toArray))["catch"](function (error) {
|
|
427
333
|
_classPrivateFieldGet(_this, _removeFromStoreSilentlyAfterFailure).call(_this, objects);
|
|
428
|
-
|
|
429
334
|
return _classPrivateFieldGet(_this, _hanldeApiError).call(_this, error, objects, operation);
|
|
430
335
|
});
|
|
431
336
|
}
|
|
432
337
|
});
|
|
433
|
-
|
|
434
338
|
_classPrivateFieldInitSpec(this, _assignId, {
|
|
435
339
|
writable: true,
|
|
436
340
|
value: function value(data, objects) {
|
|
@@ -442,45 +346,40 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
442
346
|
}
|
|
443
347
|
}
|
|
444
348
|
});
|
|
445
|
-
|
|
446
349
|
_classPrivateFieldInitSpec(this, _updateObjects, {
|
|
447
350
|
writable: true,
|
|
448
351
|
value: function value(objects) {
|
|
449
352
|
var operation = "update";
|
|
450
353
|
return (0, _modelHooksUtils.executeHook)(operation, _classPrivateFieldGet(_this, _updateHook), _classPrivateFieldGet(_this, _unWrap).call(_this, objects), _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
451
354
|
_classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
|
|
452
|
-
|
|
453
355
|
return data;
|
|
454
356
|
}).then(_classPrivateFieldGet(_this, _toArray))["catch"](function (error) {
|
|
455
357
|
return _classPrivateFieldGet(_this, _hanldeApiError).call(_this, error, objects, operation);
|
|
456
358
|
});
|
|
457
359
|
}
|
|
458
360
|
});
|
|
459
|
-
|
|
460
361
|
_classPrivateFieldInitSpec(this, _deleteObjects, {
|
|
461
362
|
writable: true,
|
|
462
363
|
value: function value(objects) {
|
|
463
364
|
var operation = "delete";
|
|
464
365
|
return (0, _modelHooksUtils.executeHook)(operation, _classPrivateFieldGet(_this, _deleteHook), _classPrivateFieldGet(_this, _unWrap).call(_this, objects), _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
465
366
|
_classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
|
|
466
|
-
|
|
467
367
|
return data;
|
|
468
368
|
}).then(_classPrivateFieldGet(_this, _toArray))["catch"](function (error) {
|
|
469
369
|
return _classPrivateFieldGet(_this, _hanldeApiError).call(_this, error, objects, operation);
|
|
470
370
|
});
|
|
471
371
|
}
|
|
472
372
|
});
|
|
473
|
-
|
|
474
373
|
_classPrivateFieldInitSpec(this, _hanldeApiError, {
|
|
475
374
|
writable: true,
|
|
476
375
|
value: function value(error, objects, operation) {
|
|
477
376
|
var _error$response$data, _error3, _error3$response, _ref, _error$message, _error4, _error5;
|
|
478
|
-
|
|
479
377
|
error = (_error$response$data = (_error3 = error) === null || _error3 === void 0 ? void 0 : (_error3$response = _error3.response) === null || _error3$response === void 0 ? void 0 : _error3$response.data) !== null && _error$response$data !== void 0 ? _error$response$data : error;
|
|
480
378
|
var targets = objects.map(function (object) {
|
|
481
379
|
return object.getId();
|
|
482
|
-
});
|
|
380
|
+
});
|
|
483
381
|
|
|
382
|
+
// Set errors
|
|
484
383
|
var strError = (_ref = (_error$message = (_error4 = error) === null || _error4 === void 0 ? void 0 : _error4.message) !== null && _error$message !== void 0 ? _error$message : (_error5 = error) === null || _error5 === void 0 ? void 0 : _error5.error) !== null && _ref !== void 0 ? _ref : error;
|
|
485
384
|
Object.values(objects).map(function (object) {
|
|
486
385
|
return object.setError(strError);
|
|
@@ -491,7 +390,6 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
491
390
|
}));
|
|
492
391
|
}
|
|
493
392
|
});
|
|
494
|
-
|
|
495
393
|
_classPrivateFieldInitSpec(this, _cleanApiError, {
|
|
496
394
|
writable: true,
|
|
497
395
|
value: function value(objects) {
|
|
@@ -500,15 +398,13 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
500
398
|
});
|
|
501
399
|
}
|
|
502
400
|
});
|
|
503
|
-
|
|
504
401
|
_classPrivateFieldInitSpec(this, _removeFromStoreSilentlyAfterFailure, {
|
|
505
402
|
writable: true,
|
|
506
403
|
value: function value(objects) {
|
|
507
404
|
var _iterator2 = _createForOfIteratorHelper(objects.map(function (object) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
405
|
+
return object.getId();
|
|
406
|
+
})),
|
|
407
|
+
_step2;
|
|
512
408
|
try {
|
|
513
409
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
514
410
|
var target = _step2.value;
|
|
@@ -521,58 +417,38 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
521
417
|
}
|
|
522
418
|
}
|
|
523
419
|
});
|
|
524
|
-
|
|
525
420
|
_classPrivateFieldSet(this, _type, name);
|
|
526
|
-
|
|
527
421
|
this.options = _objectSpread(_objectSpread({}, options), {}, {
|
|
528
422
|
deep: (_options$deep = options.deep) !== null && _options$deep !== void 0 ? _options$deep : true,
|
|
529
423
|
parseMoment: (_options$parseMoment = options.parseMoment) !== null && _options$parseMoment !== void 0 ? _options$parseMoment : false,
|
|
530
424
|
lazyLoad: options.lazyLoad,
|
|
531
425
|
validate: (_options$validate = options.validate) !== null && _options$validate !== void 0 ? _options$validate : {}
|
|
532
426
|
});
|
|
533
|
-
|
|
534
427
|
_classPrivateFieldSet(this, _store, null);
|
|
535
|
-
|
|
536
428
|
_classPrivateFieldSet(this, _includes, {});
|
|
537
|
-
|
|
538
429
|
_classPrivateFieldSet(this, _axios, this.options.axios || _axios2["default"]);
|
|
539
|
-
|
|
540
430
|
_classPrivateFieldSet(this, _hiddenFields, this.options.hiddenFields || []);
|
|
541
|
-
|
|
542
431
|
_classPrivateFieldSet(this, _loadFunction, this.options.load || null);
|
|
543
|
-
|
|
544
432
|
if (!name || !options) {
|
|
545
433
|
throw new Error("A Model requires at least a name and a hook");
|
|
546
434
|
}
|
|
547
|
-
|
|
548
435
|
if (_classPrivateFieldGet(this, _loadFunction) && typeof _classPrivateFieldGet(this, _loadFunction) !== "function") {
|
|
549
436
|
throw new Error("The load option must be a function");
|
|
550
437
|
}
|
|
551
|
-
|
|
552
438
|
var _ref2 = _typeof(options) === "object" ? (0, _modelHooksUtils.getHooksFromOptions)(options) : (0, _modelHooksUtils.getHooksFromUrl)(options),
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
439
|
+
_ref3 = _slicedToArray(_ref2, 4),
|
|
440
|
+
retrieveHook = _ref3[0],
|
|
441
|
+
insertHook = _ref3[1],
|
|
442
|
+
updateHook = _ref3[2],
|
|
443
|
+
deleteHook = _ref3[3];
|
|
559
444
|
_classPrivateFieldSet(this, _retrieveHook, retrieveHook);
|
|
560
|
-
|
|
561
445
|
_classPrivateFieldSet(this, _updateHook, updateHook);
|
|
562
|
-
|
|
563
446
|
_classPrivateFieldSet(this, _insertHook, insertHook);
|
|
564
|
-
|
|
565
447
|
_classPrivateFieldSet(this, _deleteHook, deleteHook);
|
|
566
|
-
|
|
567
448
|
_classPrivateFieldSet(this, _singleItemQuery, false); // By default use arrays
|
|
568
|
-
|
|
569
|
-
|
|
570
449
|
_classPrivateFieldSet(this, _batchSize, 4); // For HTTP requests in parallel if your API doesn't support multiple resources
|
|
571
|
-
|
|
572
450
|
});
|
|
573
|
-
|
|
574
451
|
exports["default"] = Model;
|
|
575
|
-
|
|
576
452
|
function _error2(error) {
|
|
577
453
|
error = error.message || error;
|
|
578
454
|
this.getStore().pubSub.publish("error", error);
|
package/dist/Obj.js
CHANGED
|
@@ -4,76 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _fingerprint = _interopRequireDefault(require("./fingerprint"));
|
|
9
|
-
|
|
10
8
|
var _BasicObj2 = require("./BasicObj");
|
|
11
|
-
|
|
12
9
|
var _SubObj = _interopRequireDefault(require("./SubObj"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
|
|
16
11
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
17
|
-
|
|
18
12
|
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); } }
|
|
19
|
-
|
|
20
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
-
|
|
22
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
-
|
|
24
15
|
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
|
-
|
|
26
16
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
27
|
-
|
|
28
17
|
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
|
-
|
|
30
18
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
31
|
-
|
|
32
19
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
33
|
-
|
|
34
20
|
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
|
-
|
|
36
21
|
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
22
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
39
|
-
|
|
40
23
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
|
-
|
|
42
24
|
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; }
|
|
43
|
-
|
|
44
25
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
45
|
-
|
|
46
26
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
47
|
-
|
|
48
27
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
49
|
-
|
|
50
28
|
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
51
|
-
|
|
52
29
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
53
|
-
|
|
54
30
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
55
|
-
|
|
56
31
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
57
|
-
|
|
58
32
|
var _loaded = /*#__PURE__*/new WeakMap();
|
|
59
|
-
|
|
60
33
|
var Obj = /*#__PURE__*/function (_BasicObj) {
|
|
61
34
|
_inherits(Obj, _BasicObj);
|
|
62
|
-
|
|
63
35
|
var _super = _createSuper(Obj);
|
|
64
|
-
|
|
65
36
|
function Obj(values, _model) {
|
|
66
37
|
var _thisSuper, _this;
|
|
67
|
-
|
|
68
38
|
_classCallCheck(this, Obj);
|
|
69
|
-
|
|
70
39
|
_this = _super.call(this, values, _model);
|
|
71
|
-
|
|
72
40
|
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _loaded, {
|
|
73
41
|
writable: true,
|
|
74
42
|
value: false
|
|
75
43
|
});
|
|
76
|
-
|
|
77
44
|
_defineProperty(_assertThisInitialized(_this), "set", function (attribute, value, hidden) {
|
|
78
45
|
if (Array.isArray(value) && _this.getModel().options.deep) {
|
|
79
46
|
value = value.map(function (i) {
|
|
@@ -84,56 +51,42 @@ var Obj = /*#__PURE__*/function (_BasicObj) {
|
|
|
84
51
|
}
|
|
85
52
|
});
|
|
86
53
|
}
|
|
87
|
-
|
|
88
54
|
return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(Obj.prototype)), "set", _thisSuper).call(_thisSuper, attribute, value, hidden);
|
|
89
55
|
});
|
|
90
|
-
|
|
91
56
|
_defineProperty(_assertThisInitialized(_this), "load", function () {
|
|
92
57
|
if (_classPrivateFieldGet(_assertThisInitialized(_this), _loaded)) {
|
|
93
58
|
return Promise.resolve(_assertThisInitialized(_this));
|
|
94
59
|
} else {
|
|
95
60
|
var model = _this.getModel();
|
|
96
|
-
|
|
97
61
|
return model.load(_assertThisInitialized(_this)).then(function () {
|
|
98
62
|
_classPrivateFieldSet(_assertThisInitialized(_this), _loaded, true);
|
|
99
|
-
|
|
100
63
|
return model.getStore().update([_assertThisInitialized(_this)], true); // Propagate update
|
|
101
64
|
}).then(function () {
|
|
102
65
|
return _assertThisInitialized(_this);
|
|
103
66
|
}); // return always this
|
|
104
67
|
}
|
|
105
68
|
});
|
|
106
|
-
|
|
107
69
|
_defineProperty(_assertThisInitialized(_this), "getFingerprint", function () {
|
|
108
70
|
return (0, _fingerprint["default"])(_this.toJSON());
|
|
109
71
|
});
|
|
110
|
-
|
|
111
72
|
_defineProperty(_assertThisInitialized(_this), "getRelation", function (type, filterFunction) {
|
|
112
73
|
return _this.getModel().getRelation(_assertThisInitialized(_this), type, filterFunction);
|
|
113
74
|
});
|
|
114
|
-
|
|
115
75
|
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
116
76
|
return _this.getModel().getStore().save([_assertThisInitialized(_this)]);
|
|
117
77
|
});
|
|
118
|
-
|
|
119
78
|
_defineProperty(_assertThisInitialized(_this), "destroy", function () {
|
|
120
79
|
return _this.getModel().getStore()["delete"]([_assertThisInitialized(_this)]);
|
|
121
80
|
});
|
|
122
|
-
|
|
123
81
|
_defineProperty(_assertThisInitialized(_this), "update", function () {
|
|
124
82
|
return _this.getModel().getStore().update([_assertThisInitialized(_this)]);
|
|
125
83
|
});
|
|
126
|
-
|
|
127
84
|
(0, _BasicObj2.setValues)(values, _model, _SubObj["default"], _assertThisInitialized(_this), _assertThisInitialized(_this));
|
|
128
|
-
|
|
129
85
|
_this.getModel = function () {
|
|
130
86
|
return _model;
|
|
131
87
|
};
|
|
132
|
-
|
|
133
88
|
return _this;
|
|
134
89
|
}
|
|
135
|
-
|
|
136
90
|
return _createClass(Obj);
|
|
137
91
|
}(_BasicObj2.BasicObj);
|
|
138
|
-
|
|
139
92
|
exports["default"] = Obj;
|