dataflux 1.23.3 → 1.24.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 CHANGED
@@ -350,25 +350,26 @@ const book = new Model("book", options);
350
350
 
351
351
  All the possible options for a model creation are (they are all optional):
352
352
 
353
- | Name | Description | Default |
354
- |----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
355
- | 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"}` |
356
- | 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"}` |
357
- | update | Describes the operation to update objects of the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "put"}` |
358
- | delete | Describes the operation to remove objects from the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "delete"}` |
359
- | 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 |
360
- | headers | A dictionary of headers for the HTTP request. E.g., `{"Authorization": "bearer XXXX"}`. | No headers |
361
- | 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). |
362
- | 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 |
363
- | 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. | |
364
- | 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. |
365
- | deep | A boolean defining if nested objects should be enriched with the object methods. | true |
366
- | 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 |
367
- | validate | A dictionary containing functions to validate the objects of this model. See [objects validation](#objects-validation) | no validation |
368
- | autoRefresh | Set auto refresh for the specific model. See `autoRefresh` in the [store config](#configuration). | |
369
- | 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. |
370
- | pre(object, objects) | 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. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
371
- | 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. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
353
+ | Name | Description | Default |
354
+ |-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
355
+ | 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"}` |
356
+ | 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"}` |
357
+ | update | Describes the operation to update objects of the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "put"}` |
358
+ | delete | Describes the operation to remove objects from the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "delete"}` |
359
+ | 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 |
360
+ | headers | A dictionary of headers for the HTTP request. E.g., `{"Authorization": "bearer XXXX"}`. | No headers |
361
+ | 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). |
362
+ | 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 |
363
+ | 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. | |
364
+ | 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. |
365
+ | deep | A boolean defining if nested objects should be enriched with the object methods. | true |
366
+ | 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 |
367
+ | validate | A dictionary containing functions to validate the objects of this model. See [objects validation](#objects-validation) | no validation |
368
+ | autoRefresh | Set auto refresh for the specific model. See `autoRefresh` in the [store config](#configuration). | |
369
+ | 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. |
370
+ | pre(object, objects) | 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. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
371
+ | 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. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
372
+ | filter(object, objects) | A function executed for each retrieved object before the collection is created in the store. If the function returns true, the object is added to the store; if it returns false, the object is excluded. |
372
373
 
373
374
  ### Operations
374
375
  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
@@ -94,8 +94,10 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
94
94
  _ref8,
95
95
  _options$pre,
96
96
  _ref9,
97
- _options$hiddenFields,
97
+ _options$filter,
98
98
  _ref0,
99
+ _options$hiddenFields,
100
+ _ref1,
99
101
  _options$post;
100
102
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
101
103
  var defaults = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -234,6 +236,11 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
234
236
  return (_this$options = _this.options) !== null && _this$options !== void 0 && _this$options.pre ? data.map(function (n) {
235
237
  return _this.options.pre(n, data);
236
238
  }) : data;
239
+ }).then(function (data) {
240
+ var _this$options2;
241
+ return (_this$options2 = _this.options) !== null && _this$options2 !== void 0 && _this$options2.filter ? data.filter(function (n) {
242
+ return _this.options.filter(n, data);
243
+ }) : data;
237
244
  });
238
245
  });
239
246
  _defineProperty(this, "insertObjects", function (objects) {
@@ -318,8 +325,8 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
318
325
  var data = arrayObjects.map(function (object) {
319
326
  return _classPrivateFieldGet(_removeHiddenFields, _this).call(_this, object.toJSON());
320
327
  }).map(function (object) {
321
- var _this$options2;
322
- return (_this$options2 = _this.options) !== null && _this$options2 !== void 0 && _this$options2.post ? _this.options.post(object, arrayObjects) : object;
328
+ var _this$options3;
329
+ return (_this$options3 = _this.options) !== null && _this$options3 !== void 0 && _this$options3.post ? _this.options.post(object, arrayObjects) : object;
323
330
  });
324
331
  if (data.value != null && Object.keys(data).length === 1) {
325
332
  return data.value;
@@ -421,8 +428,9 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
421
428
  autoSave: (_ref6 = (_options$autoSave = options.autoSave) !== null && _options$autoSave !== void 0 ? _options$autoSave : defaults.autoSave) !== null && _ref6 !== void 0 ? _ref6 : null,
422
429
  autoRefresh: (_ref7 = (_options$autoRefresh = options.autoRefresh) !== null && _options$autoRefresh !== void 0 ? _options$autoRefresh : defaults.autoRefresh) !== null && _ref7 !== void 0 ? _ref7 : false,
423
430
  pre: (_ref8 = (_options$pre = options.pre) !== null && _options$pre !== void 0 ? _options$pre : defaults.pre) !== null && _ref8 !== void 0 ? _ref8 : null,
424
- hiddenFields: (_ref9 = (_options$hiddenFields = options.hiddenFields) !== null && _options$hiddenFields !== void 0 ? _options$hiddenFields : defaults.hiddenFields) !== null && _ref9 !== void 0 ? _ref9 : [],
425
- post: (_ref0 = (_options$post = options.post) !== null && _options$post !== void 0 ? _options$post : defaults.post) !== null && _ref0 !== void 0 ? _ref0 : null
431
+ filter: (_ref9 = (_options$filter = options.filter) !== null && _options$filter !== void 0 ? _options$filter : defaults.filter) !== null && _ref9 !== void 0 ? _ref9 : null,
432
+ hiddenFields: (_ref0 = (_options$hiddenFields = options.hiddenFields) !== null && _options$hiddenFields !== void 0 ? _options$hiddenFields : defaults.hiddenFields) !== null && _ref0 !== void 0 ? _ref0 : [],
433
+ post: (_ref1 = (_options$post = options.post) !== null && _options$post !== void 0 ? _options$post : defaults.post) !== null && _ref1 !== void 0 ? _ref1 : null
426
434
  });
427
435
  _classPrivateFieldSet(_store, this, null);
428
436
  _classPrivateFieldSet(_includes, this, {});
@@ -435,12 +443,12 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
435
443
  if (_classPrivateFieldGet(_loadFunction, this) && typeof _classPrivateFieldGet(_loadFunction, this) !== "function") {
436
444
  throw new Error("The load option must be a function");
437
445
  }
438
- var _ref1 = _typeof(options) === "object" ? (0, _modelHooksUtils.getHooksFromOptions)(options) : (0, _modelHooksUtils.getHooksFromUrl)(options),
439
- _ref10 = _slicedToArray(_ref1, 4),
440
- retrieveHook = _ref10[0],
441
- insertHook = _ref10[1],
442
- updateHook = _ref10[2],
443
- deleteHook = _ref10[3];
446
+ var _ref10 = _typeof(options) === "object" ? (0, _modelHooksUtils.getHooksFromOptions)(options) : (0, _modelHooksUtils.getHooksFromUrl)(options),
447
+ _ref11 = _slicedToArray(_ref10, 4),
448
+ retrieveHook = _ref11[0],
449
+ insertHook = _ref11[1],
450
+ updateHook = _ref11[2],
451
+ deleteHook = _ref11[3];
444
452
  _classPrivateFieldSet(_retrieveHook, this, retrieveHook);
445
453
  _classPrivateFieldSet(_updateHook, this, updateHook);
446
454
  _classPrivateFieldSet(_insertHook, this, insertHook);
package/dist/Store.js CHANGED
@@ -536,7 +536,7 @@ function _deleteByFilter(type, filterFunction) {
536
536
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
537
537
  var object = _step6.value;
538
538
  if (object.status === "new") {
539
- delete _this11.models[type].storedObjects[object.getId()];
539
+ delete _this11.models[type].storedObjects[object.object.getId()];
540
540
  } else {
541
541
  object.status = "deleted";
542
542
  }