dataflux 1.2.5 → 1.3.0
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 -10
- package/dist/Model.js +4 -0
- package/dist/Obj.js +20 -4
- package/dist/fingerprint.js +13 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -261,16 +261,17 @@ const book = new Model("book", options);
|
|
|
261
261
|
|
|
262
262
|
All the possible options for a model creation are (they are all optional):
|
|
263
263
|
|
|
264
|
-
| Name
|
|
265
|
-
|
|
266
|
-
| retrieve
|
|
267
|
-
| insert
|
|
268
|
-
| update
|
|
269
|
-
| delete
|
|
270
|
-
| fields
|
|
271
|
-
| headers
|
|
272
|
-
| load
|
|
273
|
-
| axios
|
|
264
|
+
| Name | Description | Default |
|
|
265
|
+
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
|
|
266
|
+
| retrieve | Describes the operation to retrieve the collection of objects from the REST API. It can be an operation object or a function. See [operations](#operations). | `{method: "get"}` |
|
|
267
|
+
| insert | Describes the operation to insert a new object in the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "post"}` |
|
|
268
|
+
| update | Describes the operation to update objects of the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "put"}` |
|
|
269
|
+
| delete | Describes the operation to remove objects from the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "delete"}` |
|
|
270
|
+
| fields | An array of strings defining which attributes the retrieved objects should have. Essentially, it allows you to contemporarily specify the [X-Fields header](https://flask-restplus.readthedocs.io/en/stable/mask.html) and the [fields GET parameter](https://developers.google.com/slides/api/guides/performance#partial). This reduces transfer size and memory usage. E.g., if you have a collection of books, of which you are interested only in the name, you can define `fields: ["name"]`. In combination with `load` it allows for partial lazy load of the objects. | All the fields |
|
|
271
|
+
| headers | A dictionary of headers for the HTTP request. E.g., `{"Authorization": "bearer XXXX"}`. | No headers |
|
|
272
|
+
| load | A function that allows to enrich the objects on demand. E.g., you can use `fields` to download only the titles of a collection of books, and `load` to load completely the object. See [object enrichment](#object-enrichment). |
|
|
273
|
+
| axios | It allows to specify an axios instance to be used for the queries. If not specified, a new one will be used. | A new axios instance |
|
|
274
|
+
| parseMoment | Automatically creates Moment.js objects out of ISO8601 strings. E.g., if an object has a property `createdAt: "2022-01-07T21:38:50.295Z"`, this will be transformed to a moment object. | |
|
|
274
275
|
|
|
275
276
|
|
|
276
277
|
### Operations
|
package/dist/Model.js
CHANGED
|
@@ -342,6 +342,10 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
342
342
|
|
|
343
343
|
_classPrivateFieldSet(this, _type, name);
|
|
344
344
|
|
|
345
|
+
this.options = {
|
|
346
|
+
parseMoment: options.parseMoment
|
|
347
|
+
};
|
|
348
|
+
|
|
345
349
|
_classPrivateFieldSet(this, _store, null);
|
|
346
350
|
|
|
347
351
|
_classPrivateFieldSet(this, _includes, {});
|
package/dist/Obj.js
CHANGED
|
@@ -9,6 +9,8 @@ var _fingerprint = _interopRequireDefault(require("./fingerprint"));
|
|
|
9
9
|
|
|
10
10
|
var _uuid = require("uuid");
|
|
11
11
|
|
|
12
|
+
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
16
|
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); } }
|
|
@@ -33,6 +35,8 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
|
|
|
33
35
|
|
|
34
36
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
35
37
|
|
|
38
|
+
var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
|
|
39
|
+
|
|
36
40
|
var _loaded = /*#__PURE__*/new WeakMap();
|
|
37
41
|
|
|
38
42
|
var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
@@ -97,7 +101,11 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
|
97
101
|
for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
|
|
98
102
|
var a = _attrs[_i];
|
|
99
103
|
|
|
100
|
-
if (
|
|
104
|
+
if (_this[a] instanceof _moment["default"]) {
|
|
105
|
+
out[a] = _this[a].toISOString();
|
|
106
|
+
} else if (_this[a] instanceof Date) {
|
|
107
|
+
out[a] = (0, _moment["default"])(_this[a]).toISOString();
|
|
108
|
+
} else if (typeof _this[a] !== "function") {
|
|
101
109
|
out[a] = _this[a];
|
|
102
110
|
}
|
|
103
111
|
}
|
|
@@ -113,9 +121,17 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
|
113
121
|
return _model;
|
|
114
122
|
};
|
|
115
123
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
var frEach = _model.options.parseMoment ? function (key) {
|
|
125
|
+
if (dateRegex.test(values[key])) {
|
|
126
|
+
var mmnt = (0, _moment["default"])(values[key]);
|
|
127
|
+
_this[key] = mmnt.isValid() ? mmnt : values[key];
|
|
128
|
+
} else {
|
|
129
|
+
_this[key] = values[key];
|
|
130
|
+
}
|
|
131
|
+
} : function (key) {
|
|
132
|
+
return _this[key] = values[key];
|
|
133
|
+
};
|
|
134
|
+
Object.keys(values).forEach(frEach);
|
|
119
135
|
var id;
|
|
120
136
|
|
|
121
137
|
if (this.id && (typeof this.id === "string" || typeof this.id === "number")) {
|
package/dist/fingerprint.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = fingerprint;
|
|
7
7
|
|
|
8
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
8
12
|
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; } } }; }
|
|
9
13
|
|
|
10
14
|
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); }
|
|
@@ -18,7 +22,15 @@ var CRC32 = require('crc-32');
|
|
|
18
22
|
var _getFingerprint = function _getFingerprint(object) {
|
|
19
23
|
switch (_typeof(object)) {
|
|
20
24
|
case "object":
|
|
21
|
-
|
|
25
|
+
if (object._isAMomentObject) {
|
|
26
|
+
return "m:".concat(object.toISOString());
|
|
27
|
+
} else if (object instanceof Date) {
|
|
28
|
+
return "m:".concat((0, _moment["default"])(object).toISOString());
|
|
29
|
+
} else if (object !== null) {
|
|
30
|
+
return "o:".concat(getObjectFingerprint(object));
|
|
31
|
+
} else {
|
|
32
|
+
return "o:null";
|
|
33
|
+
}
|
|
22
34
|
|
|
23
35
|
case "boolean":
|
|
24
36
|
return "b:".concat(object ? "t" : "f");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"batch-promises": "^0.0.3",
|
|
98
98
|
"brembo": "^2.0.6",
|
|
99
99
|
"crc-32": "^1.2.0",
|
|
100
|
+
"moment": "^2.29.1",
|
|
100
101
|
"uuid": "^8.3.2"
|
|
101
102
|
},
|
|
102
103
|
"resolutions": {}
|