dataflux 1.14.8 → 1.15.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
@@ -302,7 +302,9 @@ All the possible options for a model creation are (they are all optional):
302
302
  | lazyLoad | A boolean defining if the model should be lazy loaded on the first use. This takes precedence over the lazyLoad declared during store initialization. | false |
303
303
  | validate | A dictionary containing functions to validate the objects of this model. See [objects validation](#objects-validation) | no validation |
304
304
  | autoRefresh | Set auto refresh for the specific model. See `autoRefresh` in the [store config](#configuration). | |
305
- |autoSave| It allows to specify `autoSave` at model level. If store.autoSave is true, `autoSave: false` at model level will allow to disable autoSave only for the specific model. |
305
+ | autoSave | It allows to specify `autoSave` at model level. If store.autoSave is true, `autoSave: false` at model level will allow to disable autoSave only for the specific model. |
306
+ | pre | A function that is executed for every object retrieved, before creating the collection in the store. It is useful for pre-processing every data item received from the API. |
307
+ | post | A function that is executed for every object retrieved before delete, update, and insert operations. It is useful for post-processing every data item before sending them back to the API. |
306
308
 
307
309
  ### Operations
308
310
  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.
package/dist/Model.js CHANGED
@@ -90,7 +90,11 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
90
90
  _ref5,
91
91
  _options$autoSave,
92
92
  _ref6,
93
- _options$autoRefresh;
93
+ _options$autoRefresh,
94
+ _ref7,
95
+ _options$pre,
96
+ _ref8,
97
+ _options$post;
94
98
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
95
99
  var defaults = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
96
100
  _classCallCheck(this, Model);
@@ -219,6 +223,9 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
219
223
  _classPrivateFieldSet(_singleItemQuery, _this, true);
220
224
  }
221
225
  return _classPrivateFieldGet(_toArray, _this).call(_this, data);
226
+ }).then(function (data) {
227
+ var _this$options;
228
+ return (_this$options = _this.options) !== null && _this$options !== void 0 && _this$options.pre ? data.map(_this.options.pre) : data;
222
229
  });
223
230
  });
224
231
  _defineProperty(this, "insertObjects", function (objects) {
@@ -292,6 +299,9 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
292
299
  _classPrivateFieldInitSpec(this, _unWrap, function (objects) {
293
300
  var data = Object.values(objects).map(function (object) {
294
301
  return _classPrivateFieldGet(_removeHiddenFields, _this).call(_this, object.toJSON());
302
+ }).map(function (object) {
303
+ var _this$options2;
304
+ return (_this$options2 = _this.options) !== null && _this$options2 !== void 0 && _this$options2.post ? _this.options.post(object) : object;
295
305
  });
296
306
  if (data.value != null && Object.keys(data).length === 1) {
297
307
  return data.value;
@@ -386,7 +396,9 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
386
396
  lazyLoad: (_options$lazyLoad = options.lazyLoad) !== null && _options$lazyLoad !== void 0 ? _options$lazyLoad : defaults.lazyLoad,
387
397
  validate: (_ref4 = (_options$validate = options.validate) !== null && _options$validate !== void 0 ? _options$validate : defaults.validate) !== null && _ref4 !== void 0 ? _ref4 : {},
388
398
  autoSave: (_ref5 = (_options$autoSave = options.autoSave) !== null && _options$autoSave !== void 0 ? _options$autoSave : defaults.autoSave) !== null && _ref5 !== void 0 ? _ref5 : null,
389
- autoRefresh: (_ref6 = (_options$autoRefresh = options.autoRefresh) !== null && _options$autoRefresh !== void 0 ? _options$autoRefresh : defaults.autoRefresh) !== null && _ref6 !== void 0 ? _ref6 : false
399
+ autoRefresh: (_ref6 = (_options$autoRefresh = options.autoRefresh) !== null && _options$autoRefresh !== void 0 ? _options$autoRefresh : defaults.autoRefresh) !== null && _ref6 !== void 0 ? _ref6 : false,
400
+ pre: (_ref7 = (_options$pre = options.pre) !== null && _options$pre !== void 0 ? _options$pre : defaults.pre) !== null && _ref7 !== void 0 ? _ref7 : null,
401
+ post: (_ref8 = (_options$post = options.post) !== null && _options$post !== void 0 ? _options$post : defaults.post) !== null && _ref8 !== void 0 ? _ref8 : null
390
402
  });
391
403
  _classPrivateFieldSet(_store, this, null);
392
404
  _classPrivateFieldSet(_includes, this, {});
@@ -399,12 +411,12 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
399
411
  if (_classPrivateFieldGet(_loadFunction, this) && typeof _classPrivateFieldGet(_loadFunction, this) !== "function") {
400
412
  throw new Error("The load option must be a function");
401
413
  }
402
- var _ref7 = _typeof(options) === "object" ? (0, _modelHooksUtils.getHooksFromOptions)(options) : (0, _modelHooksUtils.getHooksFromUrl)(options),
403
- _ref8 = _slicedToArray(_ref7, 4),
404
- retrieveHook = _ref8[0],
405
- insertHook = _ref8[1],
406
- updateHook = _ref8[2],
407
- deleteHook = _ref8[3];
414
+ var _ref9 = _typeof(options) === "object" ? (0, _modelHooksUtils.getHooksFromOptions)(options) : (0, _modelHooksUtils.getHooksFromUrl)(options),
415
+ _ref10 = _slicedToArray(_ref9, 4),
416
+ retrieveHook = _ref10[0],
417
+ insertHook = _ref10[1],
418
+ updateHook = _ref10[2],
419
+ deleteHook = _ref10[3];
408
420
  _classPrivateFieldSet(_retrieveHook, this, retrieveHook);
409
421
  _classPrivateFieldSet(_updateHook, this, updateHook);
410
422
  _classPrivateFieldSet(_insertHook, this, insertHook);