@azrico/webobject 1.5.45 → 1.5.47

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.
@@ -282,7 +282,7 @@ export declare class SimpleObject extends MapableObject {
282
282
  * @param result_object
283
283
  * @returns
284
284
  */
285
- static isResultValid(result_object: any, sub?: boolean): any;
285
+ static isResultValid(result_object: any, depth?: number): boolean;
286
286
  /**
287
287
  * set the response of last save from site
288
288
  * and its type
@@ -1479,18 +1479,48 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1479
1479
  }, {
1480
1480
  key: "isResultValid",
1481
1481
  value: function isResultValid(result_object) {
1482
- var sub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1482
+ var _this4 = this;
1483
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1483
1484
  if ((0, _object.object_isEmpty)(result_object)) return false;
1484
1485
  switch (_typeof(result_object)) {
1486
+ case "string":
1487
+ try {
1488
+ result_object = JSON.parse(result_object);
1489
+ return this.isResultValid(result_object);
1490
+ } catch (_unused) {
1491
+ return false;
1492
+ }
1493
+ case "number":
1494
+ return result_object > 0;
1495
+ case "boolean":
1496
+ return result_object === true;
1485
1497
  case "object":
1486
1498
  /* ----------------------------- result is error ---------------------------- */
1487
1499
  if (result_object instanceof Error) {
1488
1500
  return false;
1489
1501
  }
1490
- /* --------- maybe website sends the result as array with 1 element --------- */
1502
+ /* ----------------- maybe website sends the result as array ---------------- */
1491
1503
  if (Array.isArray(result_object)) {
1492
- if (sub) return false; //avoid going too deep
1493
- return this.isResultValid((0, _object.array_first)(result_object), true);
1504
+ var allResults = result_object.map(function (r) {
1505
+ return Boolean(_this4.isResultValid(r, depth + 1));
1506
+ });
1507
+ return allResults.find(function (s) {
1508
+ return s === false;
1509
+ }) == null;
1510
+ }
1511
+ /* ----------------------------- check products ----------------------------- */
1512
+ if (result_object.products) {
1513
+ /**
1514
+ * if one product is not valid the result is not valid
1515
+ * but if all products are valid we still need to check the object itself
1516
+ */
1517
+ if (!this.isResultValid(result_object.products, depth + 1)) return false;
1518
+ }
1519
+ if (result_object.order) {
1520
+ /**
1521
+ * if we get a order-products pair, checking the order is enough
1522
+ */
1523
+ return this.isResultValid(result_object.order, depth + 1);
1494
1524
  }
1495
1525
  /* -------------------------- check if acknowledged ------------------------- */
1496
1526
  if ((0, _object.object_isTrue)(result_object.acknowledged)) {
@@ -1500,17 +1530,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1500
1530
  return (0, _object.object_equals)(result_object.expected, result_object.result);
1501
1531
  }
1502
1532
  return !(0, _string.string_isEmpty)(this.getID(result_object));
1503
- case "string":
1504
- try {
1505
- result_object = JSON.parse(result_object);
1506
- return this.isResultValid(result_object);
1507
- } catch (_unused) {
1508
- return false;
1509
- }
1510
- case "number":
1511
- return result_object > 0;
1512
- case "boolean":
1513
- return result_object === true;
1514
1533
  }
1515
1534
  return false;
1516
1535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.45",
3
+ "version": "1.5.47",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",