@azrico/webobject 1.4.16 → 1.4.18
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.
|
@@ -52,7 +52,7 @@ export declare class WebObject extends SimpleObject {
|
|
|
52
52
|
* @returns value or undefined
|
|
53
53
|
*/
|
|
54
54
|
static getMetaValue(o: WebObject | null | undefined, key: string): any;
|
|
55
|
-
static saveList(itemList: WebObject[]): Promise<boolean>;
|
|
55
|
+
static saveList(itemList: WebObject[], extraOptions?: {}): Promise<boolean>;
|
|
56
56
|
Save(): Promise<boolean>;
|
|
57
57
|
Delete(): Promise<boolean>;
|
|
58
58
|
canSave(deltaObj?: any): true | string;
|
|
@@ -73,6 +73,7 @@ export declare class WebObject extends SimpleObject {
|
|
|
73
73
|
onDelete(...p: any): Promise<any>;
|
|
74
74
|
onLoad(...p: any): Promise<any>;
|
|
75
75
|
onSave(...p: any): Promise<any>;
|
|
76
|
+
getSaveResult(original?: boolean): any;
|
|
76
77
|
onNew(...p: any): Promise<any>;
|
|
77
78
|
/**
|
|
78
79
|
* get a single web object
|
|
@@ -20,6 +20,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
20
20
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
21
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
22
22
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
23
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
24
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
23
25
|
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); }
|
|
24
26
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
27
|
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); }; }
|
|
@@ -407,10 +409,8 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
407
409
|
key: "onSave",
|
|
408
410
|
value: function () {
|
|
409
411
|
var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
410
|
-
var
|
|
411
|
-
_this$manager4;
|
|
412
|
+
var _this$manager4;
|
|
412
413
|
var srObject,
|
|
413
|
-
actual_sr,
|
|
414
414
|
_this$manager3,
|
|
415
415
|
_len3,
|
|
416
416
|
p,
|
|
@@ -420,25 +420,13 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
420
420
|
while (1) switch (_context8.prev = _context8.next) {
|
|
421
421
|
case 0:
|
|
422
422
|
if (!this.isSaved) {
|
|
423
|
-
_context8.next =
|
|
423
|
+
_context8.next = 8;
|
|
424
424
|
break;
|
|
425
425
|
}
|
|
426
426
|
this.apply_changes();
|
|
427
427
|
srObject = this.getSaveResult(true);
|
|
428
|
-
if (!(srObject != null)) {
|
|
429
|
-
_context8.next = 10;
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
|
-
//we may have some extra data in the save result.
|
|
433
|
-
//try to find the main data
|
|
434
|
-
if (Array.isArray(srObject)) {
|
|
435
|
-
actual_sr = srObject.find(function (s) {
|
|
436
|
-
return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
|
|
437
|
-
});
|
|
438
|
-
if (actual_sr) srObject = actual_sr;
|
|
439
|
-
}
|
|
440
428
|
if (!_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
|
|
441
|
-
_context8.next =
|
|
429
|
+
_context8.next = 8;
|
|
442
430
|
break;
|
|
443
431
|
}
|
|
444
432
|
if (srObject.insertedId || srObject._id) {
|
|
@@ -447,17 +435,17 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
447
435
|
if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
|
|
448
436
|
this._index_value = Number(srObject._index_value);
|
|
449
437
|
}
|
|
450
|
-
_context8.next =
|
|
438
|
+
_context8.next = 8;
|
|
451
439
|
return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.event_run("on_id_change");
|
|
452
|
-
case
|
|
440
|
+
case 8:
|
|
453
441
|
for (_len3 = _args8.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
454
442
|
p[_key3] = _args8[_key3];
|
|
455
443
|
}
|
|
456
|
-
_context8.next =
|
|
444
|
+
_context8.next = 11;
|
|
457
445
|
return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onSave.apply(_this$manager4, p);
|
|
458
|
-
case
|
|
446
|
+
case 11:
|
|
459
447
|
return _context8.abrupt("return", _context8.sent);
|
|
460
|
-
case
|
|
448
|
+
case 12:
|
|
461
449
|
case "end":
|
|
462
450
|
return _context8.stop();
|
|
463
451
|
}
|
|
@@ -468,6 +456,21 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
468
456
|
}
|
|
469
457
|
return onSave;
|
|
470
458
|
}()
|
|
459
|
+
}, {
|
|
460
|
+
key: "getSaveResult",
|
|
461
|
+
value: function getSaveResult() {
|
|
462
|
+
var _this3 = this;
|
|
463
|
+
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
464
|
+
var srObject = _get(_getPrototypeOf(WebObject.prototype), "getSaveResult", this).call(this, original);
|
|
465
|
+
if (!srObject) return false;
|
|
466
|
+
if (Array.isArray(srObject)) {
|
|
467
|
+
var actual_sr = srObject.find(function (s) {
|
|
468
|
+
return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
|
|
469
|
+
});
|
|
470
|
+
if (actual_sr) srObject = actual_sr;
|
|
471
|
+
}
|
|
472
|
+
return srObject;
|
|
473
|
+
}
|
|
471
474
|
}, {
|
|
472
475
|
key: "onNew",
|
|
473
476
|
value: function () {
|
|
@@ -533,94 +536,110 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
533
536
|
key: "saveList",
|
|
534
537
|
value: function () {
|
|
535
538
|
var _saveList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(itemList) {
|
|
536
|
-
var
|
|
539
|
+
var extraOptions,
|
|
540
|
+
chunks,
|
|
541
|
+
putAddress,
|
|
542
|
+
index,
|
|
543
|
+
items_to_save,
|
|
544
|
+
save_array,
|
|
545
|
+
k,
|
|
546
|
+
item,
|
|
547
|
+
dlt,
|
|
548
|
+
resultObject,
|
|
549
|
+
_index,
|
|
550
|
+
res,
|
|
551
|
+
_item,
|
|
552
|
+
_index2,
|
|
553
|
+
_item2,
|
|
554
|
+
_args10 = arguments;
|
|
537
555
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
538
556
|
while (1) switch (_context10.prev = _context10.next) {
|
|
539
557
|
case 0:
|
|
558
|
+
extraOptions = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
|
|
540
559
|
chunks = (0, _object.array_chunks)(itemList, 30);
|
|
541
560
|
putAddress = this.get_webname();
|
|
542
561
|
index = 0;
|
|
543
|
-
case
|
|
562
|
+
case 4:
|
|
544
563
|
if (!(index < chunks.length)) {
|
|
545
|
-
_context10.next =
|
|
564
|
+
_context10.next = 34;
|
|
546
565
|
break;
|
|
547
566
|
}
|
|
548
567
|
items_to_save = chunks[index];
|
|
549
568
|
save_array = [];
|
|
550
569
|
k = 0;
|
|
551
|
-
case
|
|
570
|
+
case 8:
|
|
552
571
|
if (!(k < items_to_save.length)) {
|
|
553
|
-
_context10.next =
|
|
572
|
+
_context10.next = 17;
|
|
554
573
|
break;
|
|
555
574
|
}
|
|
556
575
|
item = items_to_save[k];
|
|
557
|
-
_context10.next =
|
|
576
|
+
_context10.next = 12;
|
|
558
577
|
return item.get_deltaObject();
|
|
559
|
-
case
|
|
578
|
+
case 12:
|
|
560
579
|
dlt = _context10.sent;
|
|
561
580
|
save_array.push(item.isNew ? _objectSpread({}, dlt) : _objectSpread({
|
|
562
581
|
_id: item.getID()
|
|
563
582
|
}, dlt));
|
|
564
|
-
case
|
|
583
|
+
case 14:
|
|
565
584
|
k++;
|
|
566
|
-
_context10.next =
|
|
585
|
+
_context10.next = 8;
|
|
567
586
|
break;
|
|
568
|
-
case
|
|
569
|
-
_context10.next =
|
|
570
|
-
return _global.gfunc.run_action("post", putAddress, {
|
|
587
|
+
case 17:
|
|
588
|
+
_context10.next = 19;
|
|
589
|
+
return _global.gfunc.run_action("post", putAddress, _objectSpread({
|
|
571
590
|
__save_list: save_array
|
|
572
|
-
});
|
|
573
|
-
case
|
|
591
|
+
}, extraOptions));
|
|
592
|
+
case 19:
|
|
574
593
|
resultObject = _context10.sent;
|
|
575
594
|
if (!Array.isArray(resultObject)) {
|
|
576
|
-
_context10.next =
|
|
595
|
+
_context10.next = 31;
|
|
577
596
|
break;
|
|
578
597
|
}
|
|
579
598
|
_index = 0;
|
|
580
|
-
case
|
|
599
|
+
case 22:
|
|
581
600
|
if (!(_index < Math.min(resultObject.length, items_to_save.length))) {
|
|
582
|
-
_context10.next =
|
|
601
|
+
_context10.next = 31;
|
|
583
602
|
break;
|
|
584
603
|
}
|
|
585
604
|
res = resultObject[_index];
|
|
586
605
|
_item = items_to_save[_index];
|
|
587
606
|
_item.setSaveResult(res);
|
|
588
|
-
_context10.next =
|
|
607
|
+
_context10.next = 28;
|
|
589
608
|
return _item.onSave();
|
|
590
|
-
case
|
|
609
|
+
case 28:
|
|
591
610
|
_index++;
|
|
592
|
-
_context10.next =
|
|
611
|
+
_context10.next = 22;
|
|
593
612
|
break;
|
|
594
|
-
case
|
|
613
|
+
case 31:
|
|
595
614
|
index++;
|
|
596
|
-
_context10.next =
|
|
615
|
+
_context10.next = 4;
|
|
597
616
|
break;
|
|
598
|
-
case 33:
|
|
599
|
-
_index2 = 0;
|
|
600
617
|
case 34:
|
|
618
|
+
_index2 = 0;
|
|
619
|
+
case 35:
|
|
601
620
|
if (!(_index2 < itemList.length)) {
|
|
602
|
-
_context10.next =
|
|
621
|
+
_context10.next = 44;
|
|
603
622
|
break;
|
|
604
623
|
}
|
|
605
624
|
_item2 = itemList[_index2];
|
|
606
625
|
if (_item2.isSaved) {
|
|
607
|
-
_context10.next =
|
|
626
|
+
_context10.next = 39;
|
|
608
627
|
break;
|
|
609
628
|
}
|
|
610
629
|
return _context10.abrupt("return", false);
|
|
611
|
-
case
|
|
630
|
+
case 39:
|
|
612
631
|
if (!(_item2.getSaveResultType() != "normal")) {
|
|
613
|
-
_context10.next =
|
|
632
|
+
_context10.next = 41;
|
|
614
633
|
break;
|
|
615
634
|
}
|
|
616
635
|
return _context10.abrupt("return", false);
|
|
617
|
-
case
|
|
636
|
+
case 41:
|
|
618
637
|
_index2++;
|
|
619
|
-
_context10.next =
|
|
638
|
+
_context10.next = 35;
|
|
620
639
|
break;
|
|
621
|
-
case 43:
|
|
622
|
-
return _context10.abrupt("return", true);
|
|
623
640
|
case 44:
|
|
641
|
+
return _context10.abrupt("return", true);
|
|
642
|
+
case 45:
|
|
624
643
|
case "end":
|
|
625
644
|
return _context10.stop();
|
|
626
645
|
}
|
|
@@ -766,7 +785,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
766
785
|
}(_SimpleObject2["default"]);
|
|
767
786
|
exports.WebObject = WebObject;
|
|
768
787
|
function _isValidSR2(s) {
|
|
769
|
-
if (_typeof(s) !== "object"
|
|
788
|
+
if (_typeof(s) !== "object" || s == null || !s) return false;
|
|
770
789
|
return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
|
|
771
790
|
}
|
|
772
791
|
_defineProperty(WebObject, "__web_path", "");
|