dataflux 1.4.5 → 1.5.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 CHANGED
@@ -275,6 +275,7 @@ All the possible options for a model creation are (they are all optional):
275
275
  | 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 |
276
276
  | 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. | |
277
277
  | hiddenFields | An array of attribute names that will never be sent back to the API. E.g., if you set `hiddenFields: ["pages"]`, a book object can contain an attribute `pages` locally, but this will be stripped out in PUT/POST requests. |
278
+ | deep | A boolean defining if nested objects should be enriched with the object methods. | true |
278
279
 
279
280
  ### Operations
280
281
  As described in the table above, there are four possible operations: **retrieve, insert, update,** and **delete**. An operation can be defined as an operation object or a function.
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.dateRegex = exports.BasicObj = void 0;
7
+
8
+ var _moment = _interopRequireDefault(require("moment/moment"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
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); } }
13
+
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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; }
19
+
20
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
21
+
22
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
23
+
24
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
25
+
26
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
27
+
28
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
29
+
30
+ var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
31
+ exports.dateRegex = dateRegex;
32
+
33
+ var _setHidden = /*#__PURE__*/new WeakMap();
34
+
35
+ var BasicObj = /*#__PURE__*/_createClass(function BasicObj(values, model) {
36
+ var _this = this;
37
+
38
+ _classCallCheck(this, BasicObj);
39
+
40
+ _classPrivateFieldInitSpec(this, _setHidden, {
41
+ writable: true,
42
+ value: {}
43
+ });
44
+
45
+ _defineProperty(this, "get", function (attribute, defaultValue) {
46
+ var _ref, _classPrivateFieldGet2;
47
+
48
+ return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
49
+ });
50
+
51
+ _defineProperty(this, "set", function (attribute, value, hidden) {
52
+ if (hidden) {
53
+ _classPrivateFieldGet(_this, _setHidden)[attribute] = value;
54
+ } else {
55
+ if (attribute === "id") {
56
+ throw new Error("You cannot change the ID");
57
+ }
58
+
59
+ _this[attribute] = value;
60
+ }
61
+
62
+ return _this.update();
63
+ });
64
+
65
+ _defineProperty(this, "setConstant", function (attribute, value) {
66
+ var _classPrivateFieldGet3;
67
+
68
+ _classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : value;
69
+ });
70
+
71
+ _defineProperty(this, "toJSON", function () {
72
+ var attrs = Object.keys(_this);
73
+ var out = {};
74
+
75
+ for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
76
+ var a = _attrs[_i];
77
+
78
+ if (_this[a] instanceof _moment["default"]) {
79
+ out[a] = _this[a].toISOString();
80
+ } else if (_this[a] instanceof Date) {
81
+ out[a] = (0, _moment["default"])(_this[a]).toISOString();
82
+ } else if (_this[a].toJSON) {
83
+ out[a] = _this[a].toJSON();
84
+ } else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
85
+ return i.toJSON;
86
+ })) {
87
+ out[a] = _this[a].map(function (i) {
88
+ return i.toJSON();
89
+ });
90
+ } else if (typeof _this[a] !== "function") {
91
+ out[a] = _this[a];
92
+ }
93
+ }
94
+
95
+ return out;
96
+ });
97
+
98
+ _defineProperty(this, "toString", function () {
99
+ return JSON.stringify(_this.toJSON());
100
+ });
101
+
102
+ _defineProperty(this, "update", function () {
103
+ return Promise.resolve();
104
+ });
105
+ });
106
+
107
+ exports.BasicObj = BasicObj;
package/dist/Model.js CHANGED
@@ -110,7 +110,9 @@ var _updateObjects = /*#__PURE__*/new WeakMap();
110
110
  var _deleteObjects = /*#__PURE__*/new WeakMap();
111
111
 
112
112
  var Model = /*#__PURE__*/_createClass(function Model(name) {
113
- var _this = this;
113
+ var _this = this,
114
+ _options$deep,
115
+ _options$parseMoment;
114
116
 
115
117
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
116
118
 
@@ -375,7 +377,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
375
377
  _classPrivateFieldSet(this, _type, name);
376
378
 
377
379
  this.options = {
378
- parseMoment: options.parseMoment
380
+ deep: (_options$deep = options.deep) !== null && _options$deep !== void 0 ? _options$deep : true,
381
+ parseMoment: (_options$parseMoment = options.parseMoment) !== null && _options$parseMoment !== void 0 ? _options$parseMoment : false
379
382
  };
380
383
 
381
384
  _classPrivateFieldSet(this, _store, null);
package/dist/Obj.js CHANGED
@@ -9,16 +9,36 @@ var _fingerprint = _interopRequireDefault(require("./fingerprint"));
9
9
 
10
10
  var _uuid = require("uuid");
11
11
 
12
+ var _BasicObj2 = require("./BasicObj");
13
+
12
14
  var _moment = _interopRequireDefault(require("moment/moment"));
13
15
 
16
+ var _SubObj = _interopRequireDefault(require("./SubObj"));
17
+
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
19
 
20
+ 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); }
21
+
16
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); } }
17
23
 
18
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; }
19
25
 
20
26
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
27
 
28
+ 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); }
29
+
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
+
32
+ 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); }; }
33
+
34
+ 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); }
35
+
36
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
37
+
38
+ 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; } }
39
+
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
41
+
22
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; }
23
43
 
24
44
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
@@ -35,134 +55,98 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
35
55
 
36
56
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
37
57
 
38
- var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
39
-
40
58
  var _loaded = /*#__PURE__*/new WeakMap();
41
59
 
42
- var _setHidden = /*#__PURE__*/new WeakMap();
43
-
44
- var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
45
- var _this = this;
46
-
47
- _classCallCheck(this, Obj);
60
+ var Obj = /*#__PURE__*/function (_BasicObj) {
61
+ _inherits(Obj, _BasicObj);
48
62
 
49
- _classPrivateFieldInitSpec(this, _loaded, {
50
- writable: true,
51
- value: false
52
- });
63
+ var _super = _createSuper(Obj);
53
64
 
54
- _classPrivateFieldInitSpec(this, _setHidden, {
55
- writable: true,
56
- value: {}
57
- });
65
+ function Obj(values, _model) {
66
+ var _this;
58
67
 
59
- _defineProperty(this, "load", function () {
60
- if (_classPrivateFieldGet(_this, _loaded)) {
61
- return Promise.resolve(_this);
62
- } else {
63
- var model = _this.getModel();
64
-
65
- return model.load(_this).then(function () {
66
- _classPrivateFieldSet(_this, _loaded, true);
67
-
68
- return model.getStore().update([_this], true); // Propagate update
69
- }).then(function () {
70
- return _this;
71
- }); // return always this
72
- }
73
- });
68
+ _classCallCheck(this, Obj);
74
69
 
75
- _defineProperty(this, "getFingerprint", function () {
76
- return (0, _fingerprint["default"])(_this.toJSON());
77
- });
70
+ _this = _super.call(this, values, _model);
78
71
 
79
- _defineProperty(this, "get", function (attribute, defaultValue) {
80
- var _ref, _classPrivateFieldGet2;
72
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _loaded, {
73
+ writable: true,
74
+ value: false
75
+ });
81
76
 
82
- return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
83
- });
77
+ _defineProperty(_assertThisInitialized(_this), "load", function () {
78
+ if (_classPrivateFieldGet(_assertThisInitialized(_this), _loaded)) {
79
+ return Promise.resolve(_assertThisInitialized(_this));
80
+ } else {
81
+ var model = _this.getModel();
84
82
 
85
- _defineProperty(this, "getRelation", function (type, filterFunction) {
86
- return _this.getModel().getRelation(_this, type, filterFunction);
87
- });
83
+ return model.load(_assertThisInitialized(_this)).then(function () {
84
+ _classPrivateFieldSet(_assertThisInitialized(_this), _loaded, true);
88
85
 
89
- _defineProperty(this, "set", function (attribute, value, hidden) {
90
- if (hidden) {
91
- _classPrivateFieldGet(_this, _setHidden)[attribute] = value;
92
- } else {
93
- if (attribute === "id") {
94
- throw new Error("You cannot change the ID");
86
+ return model.getStore().update([_assertThisInitialized(_this)], true); // Propagate update
87
+ }).then(function () {
88
+ return _assertThisInitialized(_this);
89
+ }); // return always this
95
90
  }
96
-
97
- _this[attribute] = value;
98
- }
99
-
100
- return _this.getModel().getStore().update([_this]);
101
- });
102
-
103
- _defineProperty(this, "setConstant", function (attribute, value) {
104
- var _classPrivateFieldGet3;
105
-
106
- _classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : value;
107
- });
108
-
109
- _defineProperty(this, "save", function () {
110
- return _this.getModel().getStore().save([_this]);
111
- });
112
-
113
- _defineProperty(this, "destroy", function () {
114
- return _this.getModel().getStore()["delete"]([_this]);
115
- });
116
-
117
- _defineProperty(this, "toJSON", function () {
118
- var attrs = Object.keys(_this);
119
- var out = {};
120
-
121
- for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
122
- var a = _attrs[_i];
123
-
124
- if (_this[a] instanceof _moment["default"]) {
125
- out[a] = _this[a].toISOString();
126
- } else if (_this[a] instanceof Date) {
127
- out[a] = (0, _moment["default"])(_this[a]).toISOString();
128
- } else if (typeof _this[a] !== "function") {
129
- out[a] = _this[a];
91
+ });
92
+
93
+ _defineProperty(_assertThisInitialized(_this), "getFingerprint", function () {
94
+ return (0, _fingerprint["default"])(_this.toJSON());
95
+ });
96
+
97
+ _defineProperty(_assertThisInitialized(_this), "getRelation", function (type, filterFunction) {
98
+ return _this.getModel().getRelation(_assertThisInitialized(_this), type, filterFunction);
99
+ });
100
+
101
+ _defineProperty(_assertThisInitialized(_this), "save", function () {
102
+ return _this.getModel().getStore().save([_assertThisInitialized(_this)]);
103
+ });
104
+
105
+ _defineProperty(_assertThisInitialized(_this), "destroy", function () {
106
+ return _this.getModel().getStore()["delete"]([_assertThisInitialized(_this)]);
107
+ });
108
+
109
+ _defineProperty(_assertThisInitialized(_this), "update", function () {
110
+ return _this.getModel().getStore().update([_assertThisInitialized(_this)]);
111
+ });
112
+
113
+ Object.keys(values).forEach(function (key) {
114
+ var value = values[key];
115
+
116
+ if (_model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
117
+ var mmnt = (0, _moment["default"])(value);
118
+ _this[key] = mmnt.isValid() ? mmnt : value;
119
+ } else if (_model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
120
+ _this[key] = new _SubObj["default"](_assertThisInitialized(_this), value, _model);
121
+ } else if (_model.options.deep && Array.isArray(value)) {
122
+ _this[key] = value.map(function (i) {
123
+ return new _SubObj["default"](_assertThisInitialized(_this), i, _model);
124
+ });
125
+ } else {
126
+ _this[key] = value;
130
127
  }
131
- }
128
+ });
132
129
 
133
- return out;
134
- });
130
+ _this.getModel = function () {
131
+ return _model;
132
+ };
135
133
 
136
- _defineProperty(this, "toString", function () {
137
- return JSON.stringify(_this.toJSON());
138
- });
134
+ var id;
139
135
 
140
- this.getModel = function () {
141
- return _model;
142
- };
143
-
144
- var frEach = _model.options.parseMoment ? function (key) {
145
- if (dateRegex.test(values[key])) {
146
- var mmnt = (0, _moment["default"])(values[key]);
147
- _this[key] = mmnt.isValid() ? mmnt : values[key];
136
+ if (_this.id && (typeof _this.id === "string" || typeof _this.id === "number")) {
137
+ id = _this.id.toString();
148
138
  } else {
149
- _this[key] = values[key];
139
+ id = (0, _uuid.v4)();
150
140
  }
151
- } : function (key) {
152
- return _this[key] = values[key];
153
- };
154
- Object.keys(values).forEach(frEach);
155
- var id;
156
-
157
- if (this.id && (typeof this.id === "string" || typeof this.id === "number")) {
158
- id = this.id.toString();
159
- } else {
160
- id = (0, _uuid.v4)();
141
+
142
+ _this.getId = function () {
143
+ return id;
144
+ };
145
+
146
+ return _this;
161
147
  }
162
148
 
163
- this.getId = function () {
164
- return id;
165
- };
166
- });
149
+ return _createClass(Obj);
150
+ }(_BasicObj2.BasicObj);
167
151
 
168
152
  exports["default"] = Obj;
package/dist/SubObj.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _uuid = require("uuid");
9
+
10
+ var _BasicObj2 = require("./BasicObj");
11
+
12
+ var _moment = _interopRequireDefault(require("moment/moment"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
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); }
17
+
18
+ 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
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
+
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
+
26
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
27
+
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
+
30
+ 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
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
33
+
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
+
36
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
+
38
+ 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
+
40
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
41
+
42
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
43
+
44
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
45
+
46
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
47
+
48
+ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
49
+
50
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
51
+
52
+ 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; } }
53
+
54
+ var _model = /*#__PURE__*/new WeakMap();
55
+
56
+ var _parent = /*#__PURE__*/new WeakMap();
57
+
58
+ var SubObj = /*#__PURE__*/function (_BasicObj) {
59
+ _inherits(SubObj, _BasicObj);
60
+
61
+ var _super = _createSuper(SubObj);
62
+
63
+ function SubObj(parent, values, model) {
64
+ var _this;
65
+
66
+ _classCallCheck(this, SubObj);
67
+
68
+ _this = _super.call(this, values, model);
69
+
70
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _model, {
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+
75
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _parent, {
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+
80
+ _defineProperty(_assertThisInitialized(_this), "save", function () {
81
+ return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().save([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
82
+ });
83
+
84
+ _defineProperty(_assertThisInitialized(_this), "destroy", function () {
85
+ return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore()["delete"]([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
86
+ });
87
+
88
+ _defineProperty(_assertThisInitialized(_this), "update", function () {
89
+ return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().update([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
90
+ });
91
+
92
+ _classPrivateFieldSet(_assertThisInitialized(_this), _model, model);
93
+
94
+ _classPrivateFieldSet(_assertThisInitialized(_this), _parent, parent);
95
+
96
+ Object.keys(values).forEach(function (key) {
97
+ var value = values[key];
98
+
99
+ if (model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
100
+ var mmnt = (0, _moment["default"])(value);
101
+ _this[key] = mmnt.isValid() ? mmnt : value;
102
+ } else if (model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
103
+ _this[key] = new SubObj(_assertThisInitialized(_this), value, model);
104
+ } else if (model.options.deep && Array.isArray(value)) {
105
+ _this[key] = value.map(function (i) {
106
+ return new SubObj(_assertThisInitialized(_this), i, model);
107
+ });
108
+ } else {
109
+ _this[key] = value;
110
+ }
111
+ });
112
+
113
+ _this.getId = function () {
114
+ return (0, _uuid.v4)();
115
+ };
116
+
117
+ return _this;
118
+ }
119
+
120
+ return _createClass(SubObj);
121
+ }(_BasicObj2.BasicObj);
122
+
123
+ exports["default"] = SubObj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataflux",
3
- "version": "1.4.5",
3
+ "version": "1.5.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",