@azrico/webobject 1.4.32 → 1.4.33

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.
@@ -9,7 +9,6 @@ export type deltaParams = {
9
9
  extraProperties?: boolean;
10
10
  };
11
11
  export declare class WebObject extends SimpleObject {
12
- #private;
13
12
  static readonly __web_path: string;
14
13
  static readonly __web_type: string;
15
14
  meta_data: MetaObject[];
@@ -61,7 +60,6 @@ export declare class WebObject extends SimpleObject {
61
60
  Delete(): Promise<boolean>;
62
61
  canSave(deltaObj?: any): true | string;
63
62
  deltaIsValid(d: any): true | string;
64
- static isResultValid(result_object: any): boolean;
65
63
  /**
66
64
  * You will post this to the server for saving
67
65
  * automatically removes unchangable fields
@@ -80,6 +78,21 @@ export declare class WebObject extends SimpleObject {
80
78
  onAfterSave(...p: any): Promise<any>;
81
79
  getSaveResult(original?: boolean): any;
82
80
  onNew(...p: any): Promise<any>;
81
+ saveResultHasID(s: any): any;
82
+ static saveResultHasID(s: any): any;
83
+ /**
84
+ * check if the web result of a save action is acknowledged
85
+ * @param result_object
86
+ * @returns
87
+ */
88
+ static isResultValid(result_object: any): boolean;
89
+ /**
90
+ * Load Id and _index_value from the given save result into our object
91
+ * @param o
92
+ * @param srObject
93
+ * @returns
94
+ */
95
+ static LoadIdsFromSaveResult(o: WebObject, srObject: any): void;
83
96
  /**
84
97
  * get a single web object
85
98
  * default order of parameters : search,readonly,fetchID
@@ -30,13 +30,9 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
30
30
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
31
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
32
32
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
- function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
34
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
35
33
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
36
34
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
37
35
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
38
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
39
- var _isValidSR = /*#__PURE__*/new WeakSet();
40
36
  var WebObject = /*#__PURE__*/function (_SimpleObject) {
41
37
  _inherits(WebObject, _SimpleObject);
42
38
  var _super = _createSuper(WebObject);
@@ -45,7 +41,6 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
45
41
  var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
46
42
  _classCallCheck(this, WebObject);
47
43
  _this = _super.call(this, is_readonly);
48
- _classPrivateMethodInitSpec(_assertThisInitialized(_this), _isValidSR);
49
44
  _defineProperty(_assertThisInitialized(_this), "meta_data", void 0);
50
45
  _defineProperty(_assertThisInitialized(_this), "_id", "");
51
46
  _defineProperty(_assertThisInitialized(_this), "_creator", void 0);
@@ -183,15 +178,14 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
183
178
  value: function deltaIsValid(d) {
184
179
  return true;
185
180
  }
186
- }, {
187
- key: "get_deltaObject",
188
- value:
189
181
  /**
190
182
  * You will post this to the server for saving
191
183
  * automatically removes unchangable fields
192
184
  * @returns
193
185
  */
194
- function () {
186
+ }, {
187
+ key: "get_deltaObject",
188
+ value: function () {
195
189
  var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(p) {
196
190
  var _this2 = this;
197
191
  var final_object, isChild, useDelta, allProperties, chkChangables, useExtraProps, dlt, allkeys, changableKeys, parseObj, _parseObj, functionProps, index, fp, _iterator, _step, key;
@@ -420,7 +414,6 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
420
414
  var _this$manager4;
421
415
  var srObject,
422
416
  _this$manager3,
423
- srID,
424
417
  _len3,
425
418
  p,
426
419
  _key3,
@@ -429,42 +422,31 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
429
422
  while (1) switch (_context8.prev = _context8.next) {
430
423
  case 0:
431
424
  if (!this.isSaved) {
432
- _context8.next = 10;
425
+ _context8.next = 7;
433
426
  break;
434
427
  }
435
428
  this.apply_changes();
436
429
  srObject = this.getSaveResult(true);
437
- if (!_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
438
- _context8.next = 10;
430
+ if (!this.saveResultHasID(srObject)) {
431
+ _context8.next = 7;
439
432
  break;
440
433
  }
441
434
  /* -------------------------------------------------------------------------- */
442
- srID = srObject.insertedId || srObject._id;
443
- if (srID) {
444
- this._id = srID;
445
- }
446
- /* -------------------------------------------------------------------------- */
447
- if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
448
- this._index_value = Number(srObject._index_value);
449
- }
450
- /* -------------------------------------------------------------------------- */
451
- if (srObject._index_key) {
452
- this._index_key = srObject._index_key;
453
- }
454
- _context8.next = 10;
435
+ WebObject.LoadIdsFromSaveResult(this, srObject);
436
+ _context8.next = 7;
455
437
  return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.event_run("on_id_change");
456
- case 10:
438
+ case 7:
457
439
  for (_len3 = _args8.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
458
440
  p[_key3] = _args8[_key3];
459
441
  }
460
- _context8.next = 13;
442
+ _context8.next = 10;
461
443
  return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onSave.apply(_this$manager4, p);
462
- case 13:
463
- _context8.next = 15;
444
+ case 10:
445
+ _context8.next = 12;
464
446
  return this.onAfterSave();
465
- case 15:
447
+ case 12:
466
448
  return _context8.abrupt("return", true);
467
- case 16:
449
+ case 13:
468
450
  case "end":
469
451
  return _context8.stop();
470
452
  }
@@ -514,7 +496,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
514
496
  if (!srObject) return false;
515
497
  if (Array.isArray(srObject)) {
516
498
  var actual_sr = srObject.find(function (s) {
517
- return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
499
+ return _this3.saveResultHasID(s);
518
500
  });
519
501
  if (actual_sr) srObject = actual_sr;
520
502
  }
@@ -549,12 +531,12 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
549
531
  return _onNew.apply(this, arguments);
550
532
  }
551
533
  return onNew;
552
- }()
553
- /* -------------------------------------------------------------------------- */
554
- /**
555
- * get a single web object
556
- * default order of parameters : search,readonly,fetchID
557
- */
534
+ }() /* -------------------------------------------------------------------------- */
535
+ }, {
536
+ key: "saveResultHasID",
537
+ value: function saveResultHasID(s) {
538
+ return WebObject.saveResultHasID(s);
539
+ }
558
540
  }], [{
559
541
  key: "getMeta",
560
542
  value: function getMeta(o, key) {
@@ -717,6 +699,22 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
717
699
  }
718
700
  return saveList;
719
701
  }()
702
+ }, {
703
+ key: "get_webname",
704
+ value: function get_webname() {
705
+ return this.__web_path || this.__web_type || this.__cache_name;
706
+ }
707
+ }, {
708
+ key: "saveResultHasID",
709
+ value: function saveResultHasID(s) {
710
+ if (_typeof(s) !== "object" || s == null || !s) return false;
711
+ return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
712
+ }
713
+ /**
714
+ * check if the web result of a save action is acknowledged
715
+ * @param result_object
716
+ * @returns
717
+ */
720
718
  }, {
721
719
  key: "isResultValid",
722
720
  value: function isResultValid(result_object) {
@@ -726,11 +724,35 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
726
724
  }
727
725
  return false;
728
726
  }
727
+ /**
728
+ * Load Id and _index_value from the given save result into our object
729
+ * @param o
730
+ * @param srObject
731
+ * @returns
732
+ */
729
733
  }, {
730
- key: "get_webname",
731
- value: function get_webname() {
732
- return this.__web_path || this.__web_type || this.__cache_name;
734
+ key: "LoadIdsFromSaveResult",
735
+ value: function LoadIdsFromSaveResult(o, srObject) {
736
+ if (_typeof(o) !== "object" || _typeof(srObject) !== "object") return;
737
+ /* -------------------------------------------------------------------------- */
738
+ var srID = srObject.insertedId || srObject._id || WebObject.getID(srObject);
739
+ if (srID) {
740
+ o._id = srID;
741
+ }
742
+ /* -------------------------------------------------------------------------- */
743
+ if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
744
+ o._index_value = Number(srObject._index_value);
745
+ }
746
+ /* -------------------------------------------------------------------------- */
747
+ if (srObject._index_key) {
748
+ o._index_key = srObject._index_key;
749
+ }
733
750
  }
751
+ /* -------------------------------------------------------------------------- */
752
+ /**
753
+ * get a single web object
754
+ * default order of parameters : search,readonly,fetchID
755
+ */
734
756
  }, {
735
757
  key: "get_single",
736
758
  value: function () {
@@ -851,10 +873,6 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
851
873
  return WebObject;
852
874
  }(_SimpleObject2["default"]);
853
875
  exports.WebObject = WebObject;
854
- function _isValidSR2(s) {
855
- if (_typeof(s) !== "object" || s == null || !s) return false;
856
- return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
857
- }
858
876
  _defineProperty(WebObject, "__web_path", "");
859
877
  _defineProperty(WebObject, "__web_type", "");
860
878
  var _default = WebObject;
@@ -969,7 +969,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
969
969
  if (o._bsontype == "ObjectID" && typeof o.toString === "function") {
970
970
  return o.toString();
971
971
  }
972
- return String(o._id || o.ID || o.id || o.__data_id || "");
972
+ return String(o._id || o.ID || o.id || o.__data_id || o.insertedId || "");
973
973
  case "string":
974
974
  case "number":
975
975
  return String(o);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.32",
3
+ "version": "1.4.33",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",