neo.mjs 4.6.5 → 4.6.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.6.5",
3
+ "version": "4.6.7",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -47,7 +47,7 @@
47
47
  "autoprefixer": "^10.4.13",
48
48
  "chalk": "^5.2.0",
49
49
  "clean-webpack-plugin": "^4.0.0",
50
- "commander": "^9.4.1",
50
+ "commander": "^9.5.0",
51
51
  "cssnano": "^5.1.14",
52
52
  "envinfo": "^7.8.1",
53
53
  "fs-extra": "^11.1.0",
@@ -55,7 +55,7 @@
55
55
  "inquirer": "^9.1.4",
56
56
  "neo-jsdoc": "^1.0.1",
57
57
  "neo-jsdoc-x": "^1.0.4",
58
- "postcss": "^8.4.20",
58
+ "postcss": "^8.4.21",
59
59
  "sass": "^1.57.1",
60
60
  "webpack": "^5.75.0",
61
61
  "webpack-cli": "^5.0.1",
@@ -743,23 +743,26 @@ class Base extends CoreBase {
743
743
  }
744
744
 
745
745
  /**
746
- * Returns all items which match the property and value
746
+ * Returns items which match the property and value
747
747
  * @param {Object|String} property
748
- * @param {String|Number} [value] Optional, in case the first param is an object
749
- * @returns {Array} Returns an empty Array in case no items are found
748
+ * @param {String|Number} [value] Only required in case the first param is a string
749
+ * @param {Boolean} returnFirstMatch=false
750
+ * @returns {Object|Object[]}
751
+ * returnFirstMatch=false: Returns an empty Array in case no items are found
752
+ * returnFirstMatch=true: Returns the first found item or null
750
753
  */
751
- find(property, value) {
754
+ find(property, value, returnFirstMatch=false) {
752
755
  let me = this,
753
756
  items = [],
754
757
  isObjectProperty = Neo.isObject(property),
755
- matchArray, propertiesArray, propertiesLength;
758
+ item, matchArray, propertiesArray, propertiesLength;
756
759
 
757
760
  if (isObjectProperty) {
758
761
  propertiesArray = Object.entries(property);
759
762
  propertiesLength = propertiesArray.length;
760
763
  }
761
764
 
762
- me.items.forEach(item => {
765
+ for (item of me.items) {
763
766
  if (isObjectProperty) {
764
767
  matchArray = [];
765
768
 
@@ -770,33 +773,35 @@ class Base extends CoreBase {
770
773
  });
771
774
 
772
775
  if (matchArray.length === propertiesLength) {
776
+ if (returnFirstMatch) {
777
+ return item;
778
+ }
779
+
773
780
  items.push(item);
774
781
  }
775
- }
776
- else if (item[property] === value) {
782
+ } else if (item[property] === value) {
777
783
  items.push(item);
778
784
  }
779
- });
785
+ }
780
786
 
781
- return items;
787
+ return returnFirstMatch ? null : items;
782
788
  }
783
789
 
784
790
  /**
785
791
  * Returns all items in the collection for which the passed function returns true
786
792
  * @param {function} fn The function to run for each item inside the start-end range. Return true for a match.
787
793
  * @param {Object} fn.item The current collection item
788
- * @param {Object} [scope=this] The scope in which the passed function gets executed
789
- * @param {Number} [start=0] The start index
790
- * @param {Number} [end=this.getCount()] The end index (up to, last value excluded)
794
+ * @param {Object} scope=this The scope in which the passed function gets executed
795
+ * @param {Number} start=0 The start index
796
+ * @param {Number} end=this.getCount() The end index (up to, last value excluded)
791
797
  * @returns {Array} Returns an empty Array in case no items are found
792
798
  */
793
- findBy(fn, scope=this, start, end) {
799
+ findBy(fn, scope=this, start=0, end=this.getCount()) {
794
800
  let me = this,
795
801
  items = [],
796
- i = start || 0,
797
- len = end || me.getCount();
802
+ i = start;
798
803
 
799
- for (; i < len; i++) {
804
+ for (; i < end; i++) {
800
805
  if (fn.call(scope, me.items[i])) {
801
806
  items.push(me.items[i]);
802
807
  }
@@ -805,6 +810,16 @@ class Base extends CoreBase {
805
810
  return items;
806
811
  }
807
812
 
813
+ /**
814
+ * Returns the first item which matches the property and value
815
+ * @param {Object|String} property
816
+ * @param {String|Number} [value] Only required in case the first param is a string
817
+ * @returns {Object} Returns the first found item or null
818
+ */
819
+ findFirst(property, value) {
820
+ return this.find(property, value, true);
821
+ }
822
+
808
823
  /**
809
824
  * Returns the first item inside the collection
810
825
  * @returns {Object}
@@ -311,9 +311,20 @@ class Store extends Base {
311
311
  RecordFactory.createRecord(config);
312
312
  }
313
313
 
314
- load() {
315
- let me = this,
316
- params = {page: me.currentPage, pageSize: me.pageSize};
314
+ /**
315
+ * @param {Object} opts={}
316
+ * @param {Object} opts.data
317
+ * @param {Object} opts.headers
318
+ * @param {String} opts.method DELETE, GET, POST, PUT
319
+ * @param {Object} opts.params
320
+ * @param {String} opts.responseType
321
+ * @param {Object} opts.scope
322
+ * @param {String} opts.url
323
+ * @protected
324
+ */
325
+ load(opts={}) {
326
+ let me = this,
327
+ params = {page: me.currentPage, pageSize: me.pageSize, ...opts.params};
317
328
 
318
329
  if (me.remoteFilter) {
319
330
  params.filters = me.exportFilters();
@@ -332,18 +343,18 @@ class Store extends Base {
332
343
  console.log('Api is not defined', this);
333
344
  } else {
334
345
  service[fn](params).then(response => {
346
+ response = Neo.ns(me.responseRoot, false, response);
347
+
335
348
  if (response.success) {
336
349
  me.totalCount = response.totalCount;
337
- me.data = response.data; // fires the load event
350
+ me.data = Neo.ns(me.responseRoot, false, response); // fires the load event
338
351
  }
339
352
  });
340
353
  }
341
354
  } else {
342
- params.url = me.url;
355
+ opts.url ??= me.url;
343
356
 
344
- Neo.Xhr.promiseJson({
345
- url: params.url
346
- }).catch(err => {
357
+ Neo.Xhr.promiseJson(opts).catch(err => {
347
358
  console.log('Error for Neo.Xhr.request', err, me.id);
348
359
  }).then(data => {
349
360
  me.data = Neo.ns(me.responseRoot, false, data.json) || data.json;
@@ -32,7 +32,9 @@ class Instance extends Base {
32
32
 
33
33
  me.consumeNeoIdMap();
34
34
 
35
- Neo.get = me.get.bind(me); // alias
35
+ Neo.find = me.find .bind(me); // alias
36
+ Neo.findFirst = me.findFirst.bind(me); // alias
37
+ Neo.get = me.get .bind(me); // alias
36
38
  }
37
39
 
38
40
  /**