dataflux 1.1.0 → 1.1.1
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/README.md +11 -0
- package/dist/Model.js +18 -5
- package/dist/PersistentStore.js +0 -3
- package/dist/fingerprint.js +3 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -284,6 +284,17 @@ const options = {
|
|
|
284
284
|
const book = new Model("book", options);
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
+
All the possible options for a model creation are:
|
|
288
|
+
|
|
289
|
+
| Name | Description |
|
|
290
|
+
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
291
|
+
| retrieve | Describes the operation to retrieve a collection of objects from a REST API. It can be an object containing `method` and `url` or a function. See examples above. |
|
|
292
|
+
| insert | Describes the operation to insert a new object in the collection. It can be an object containing `method` and `url` or a function. See examples above. |
|
|
293
|
+
| update | Describes the operation to update objects of the collection. It can be an object containing `method` and `url` or a function. See examples above. |
|
|
294
|
+
| delete | Describes the operation to remove objects from the collection. It can be an object containing `method` and `url` or a function. See examples above. |
|
|
295
|
+
| axios | It allows to specify an axios instance to be used for the queries. If not specified, a new one will be used. |
|
|
296
|
+
|
|
297
|
+
|
|
287
298
|
### Model relations
|
|
288
299
|
|
|
289
300
|
Optionally, you can create relations among models.
|
package/dist/Model.js
CHANGED
|
@@ -9,6 +9,8 @@ var _modelHooksUtils = require("./modelHooksUtils");
|
|
|
9
9
|
|
|
10
10
|
var _batchPromises = _interopRequireDefault(require("batch-promises"));
|
|
11
11
|
|
|
12
|
+
var _axios2 = _interopRequireDefault(require("axios"));
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
16
|
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); }
|
|
@@ -65,6 +67,8 @@ var _singleItemQuery = /*#__PURE__*/new WeakMap();
|
|
|
65
67
|
|
|
66
68
|
var _batchSize = /*#__PURE__*/new WeakMap();
|
|
67
69
|
|
|
70
|
+
var _axios = /*#__PURE__*/new WeakMap();
|
|
71
|
+
|
|
68
72
|
var _addRelationByField = /*#__PURE__*/new WeakMap();
|
|
69
73
|
|
|
70
74
|
var _addRelationByFilter = /*#__PURE__*/new WeakMap();
|
|
@@ -79,9 +83,11 @@ var _updateObjects = /*#__PURE__*/new WeakMap();
|
|
|
79
83
|
|
|
80
84
|
var _deleteObjects = /*#__PURE__*/new WeakMap();
|
|
81
85
|
|
|
82
|
-
var Model = /*#__PURE__*/_createClass(function Model(name
|
|
86
|
+
var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
83
87
|
var _this = this;
|
|
84
88
|
|
|
89
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
90
|
+
|
|
85
91
|
_classCallCheck(this, Model);
|
|
86
92
|
|
|
87
93
|
_classPrivateFieldInitSpec(this, _type, {
|
|
@@ -129,6 +135,11 @@ var Model = /*#__PURE__*/_createClass(function Model(name, options) {
|
|
|
129
135
|
value: void 0
|
|
130
136
|
});
|
|
131
137
|
|
|
138
|
+
_classPrivateFieldInitSpec(this, _axios, {
|
|
139
|
+
writable: true,
|
|
140
|
+
value: void 0
|
|
141
|
+
});
|
|
142
|
+
|
|
132
143
|
_defineProperty(this, "getStore", function () {
|
|
133
144
|
return _classPrivateFieldGet(_this, _store);
|
|
134
145
|
});
|
|
@@ -185,7 +196,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name, options) {
|
|
|
185
196
|
});
|
|
186
197
|
|
|
187
198
|
_defineProperty(this, "retrieveAll", function () {
|
|
188
|
-
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), null, _this
|
|
199
|
+
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), null, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
189
200
|
});
|
|
190
201
|
|
|
191
202
|
_defineProperty(this, "insertObjects", function (objects) {
|
|
@@ -248,21 +259,21 @@ var Model = /*#__PURE__*/_createClass(function Model(name, options) {
|
|
|
248
259
|
_classPrivateFieldInitSpec(this, _insertObjects, {
|
|
249
260
|
writable: true,
|
|
250
261
|
value: function value(data) {
|
|
251
|
-
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), data, _this
|
|
262
|
+
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
252
263
|
}
|
|
253
264
|
});
|
|
254
265
|
|
|
255
266
|
_classPrivateFieldInitSpec(this, _updateObjects, {
|
|
256
267
|
writable: true,
|
|
257
268
|
value: function value(data) {
|
|
258
|
-
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), data, _this
|
|
269
|
+
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
259
270
|
}
|
|
260
271
|
});
|
|
261
272
|
|
|
262
273
|
_classPrivateFieldInitSpec(this, _deleteObjects, {
|
|
263
274
|
writable: true,
|
|
264
275
|
value: function value(data) {
|
|
265
|
-
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), data, _this
|
|
276
|
+
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
266
277
|
}
|
|
267
278
|
});
|
|
268
279
|
|
|
@@ -272,6 +283,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name, options) {
|
|
|
272
283
|
|
|
273
284
|
_classPrivateFieldSet(this, _includes, {});
|
|
274
285
|
|
|
286
|
+
_classPrivateFieldSet(this, _axios, options.axios || _axios2["default"]);
|
|
287
|
+
|
|
275
288
|
if (!name || !options) {
|
|
276
289
|
throw new Error("A Model requires at least a name and a hook");
|
|
277
290
|
}
|
package/dist/PersistentStore.js
CHANGED
|
@@ -9,8 +9,6 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _Store2 = _interopRequireDefault(require("./Store"));
|
|
11
11
|
|
|
12
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
13
|
-
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
13
|
|
|
16
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -113,7 +111,6 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
|
|
|
113
111
|
}
|
|
114
112
|
});
|
|
115
113
|
|
|
116
|
-
_this.axios = options.axios || _axios["default"];
|
|
117
114
|
_this._busy = false;
|
|
118
115
|
_this._delayedSaveTimer = null;
|
|
119
116
|
|
package/dist/fingerprint.js
CHANGED
|
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = fingerprint;
|
|
7
7
|
|
|
8
|
-
var _crc = _interopRequireDefault(require("crc/crc32"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
-
|
|
12
8
|
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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
13
9
|
|
|
14
10
|
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); }
|
|
@@ -17,6 +13,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
17
13
|
|
|
18
14
|
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); }
|
|
19
15
|
|
|
16
|
+
var CRC32 = require('crc-32');
|
|
17
|
+
|
|
20
18
|
var _getFingerprint = function _getFingerprint(object) {
|
|
21
19
|
switch (_typeof(object)) {
|
|
22
20
|
case "object":
|
|
@@ -61,5 +59,5 @@ var getObjectFingerprint = function getObjectFingerprint(value) {
|
|
|
61
59
|
};
|
|
62
60
|
|
|
63
61
|
function fingerprint(object) {
|
|
64
|
-
return (
|
|
62
|
+
return CRC32.str(_getFingerprint(object)).toString(16);
|
|
65
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "DataFlux, automatically interfaces with your REST APIs to create a 2-way-synced local data store. Transparently manages data propagation in the React state.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "dist/index.js",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"axios": "^0.25.0",
|
|
94
94
|
"batch-promises": "^0.0.3",
|
|
95
|
-
"crc": "^
|
|
95
|
+
"crc-32": "^1.2.0",
|
|
96
96
|
"uuid": "^8.3.2"
|
|
97
97
|
},
|
|
98
98
|
"resolutions": {}
|