@azrico/webobject 1.3.0 → 1.3.2

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,6 +9,7 @@ export type deltaParams = {
9
9
  extraProperties?: boolean;
10
10
  };
11
11
  export declare class WebObject extends SimpleObject {
12
+ #private;
12
13
  static readonly __web_path: string;
13
14
  static readonly __web_type: string;
14
15
  meta_data: MetaObject[];
@@ -27,9 +27,13 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
27
27
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
28
  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; } }
29
29
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
31
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
30
32
  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; }
31
33
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
32
34
  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); }
35
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
36
+ var _isValidSR = /*#__PURE__*/new WeakSet();
33
37
  var WebObject = /*#__PURE__*/function (_SimpleObject) {
34
38
  _inherits(WebObject, _SimpleObject);
35
39
  var _super = _createSuper(WebObject);
@@ -38,6 +42,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
38
42
  var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
39
43
  _classCallCheck(this, WebObject);
40
44
  _this = _super.call(this, is_readonly);
45
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _isValidSR);
41
46
  _defineProperty(_assertThisInitialized(_this), "meta_data", void 0);
42
47
  _defineProperty(_assertThisInitialized(_this), "_id", "");
43
48
  _defineProperty(_assertThisInitialized(_this), "_created_date", "");
@@ -372,22 +377,47 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
372
377
  key: "onSave",
373
378
  value: function () {
374
379
  var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
375
- var _this$manager2;
376
- var _len2,
380
+ var _this3 = this,
381
+ _this$manager2;
382
+ var srObject,
383
+ actual_sr,
384
+ _len2,
377
385
  p,
378
386
  _key2,
379
387
  _args7 = arguments;
380
388
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
381
389
  while (1) switch (_context7.prev = _context7.next) {
382
390
  case 0:
391
+ if (this.isSaved) {
392
+ this.apply_changes();
393
+ srObject = this.getSaveResult(true);
394
+ if (srObject != null) {
395
+ //we may have some extra data in the save result.
396
+ //try to find the main data
397
+ if (Array.isArray(srObject)) {
398
+ actual_sr = srObject.find(function (s) {
399
+ return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
400
+ });
401
+ if (actual_sr) srObject = actual_sr;
402
+ }
403
+ if (_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
404
+ if (srObject.insertedId || srObject._id) {
405
+ this._id = srObject.insertedId || srObject._id;
406
+ }
407
+ if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
408
+ this._index_value = Number(srObject._index_value);
409
+ }
410
+ }
411
+ }
412
+ }
383
413
  for (_len2 = _args7.length, p = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
384
414
  p[_key2] = _args7[_key2];
385
415
  }
386
- _context7.next = 3;
416
+ _context7.next = 4;
387
417
  return (_this$manager2 = this.manager) === null || _this$manager2 === void 0 ? void 0 : _this$manager2.onSave.apply(_this$manager2, p);
388
- case 3:
389
- return _context7.abrupt("return", _context7.sent);
390
418
  case 4:
419
+ return _context7.abrupt("return", _context7.sent);
420
+ case 5:
391
421
  case "end":
392
422
  return _context7.stop();
393
423
  }
@@ -590,6 +620,10 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
590
620
  return WebObject;
591
621
  }(_SimpleObject2["default"]);
592
622
  exports.WebObject = WebObject;
623
+ function _isValidSR2(s) {
624
+ if (_typeof(s) !== "object" && s == null) return false;
625
+ return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
626
+ }
593
627
  _defineProperty(WebObject, "__web_path", "");
594
628
  _defineProperty(WebObject, "__web_type", "");
595
629
  var _default = WebObject;
@@ -5,7 +5,6 @@ import WebObject from "./WebObject";
5
5
  * This class manages the events of an Simple Object
6
6
  */
7
7
  export declare class WebObjectManager<T extends WebObject> extends ObjectManager<T> {
8
- #private;
9
8
  static readonly __web_path: string;
10
9
  static readonly __web_type: string;
11
10
  /**
@@ -20,13 +20,9 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
20
20
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
21
  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; } }
22
22
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
23
- function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
24
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
25
23
  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; }
26
24
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
27
25
  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); }
28
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
29
- var _isValidSR = /*#__PURE__*/new WeakSet();
30
26
  /**
31
27
  * This class manages the events of an Simple Object
32
28
  */
@@ -34,18 +30,15 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
34
30
  _inherits(WebObjectManager, _ObjectManager);
35
31
  var _super = _createSuper(WebObjectManager);
36
32
  function WebObjectManager() {
37
- var _this;
38
33
  _classCallCheck(this, WebObjectManager);
39
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
40
- args[_key] = arguments[_key];
41
- }
42
- _this = _super.call.apply(_super, [this].concat(args));
43
- _classPrivateMethodInitSpec(_assertThisInitialized(_this), _isValidSR);
44
- return _this;
34
+ return _super.apply(this, arguments);
45
35
  }
46
36
  _createClass(WebObjectManager, [{
47
37
  key: "setMetaValue",
48
- value: /* -------------------------------------------------------------------------- */
38
+ value:
39
+ //we use this as backup
40
+
41
+ /* -------------------------------------------------------------------------- */
49
42
  /* -------------------------------------------------------------------------- */
50
43
  /* Meta data */
51
44
  /* -------------------------------------------------------------------------- */
@@ -201,10 +194,13 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
201
194
  return this.event_run("on_change", true);
202
195
  case 5:
203
196
  _context4.next = 7;
204
- return Promise.resolve(true);
197
+ return this.event_run("on_after_new");
205
198
  case 7:
199
+ _context4.next = 9;
200
+ return Promise.resolve(true);
201
+ case 9:
206
202
  return _context4.abrupt("return", _context4.sent);
207
- case 8:
203
+ case 10:
208
204
  case "end":
209
205
  return _context4.stop();
210
206
  }
@@ -238,10 +234,13 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
238
234
  return this.event_run("on_change", true);
239
235
  case 5:
240
236
  _context5.next = 7;
241
- return Promise.resolve(true);
237
+ return this.event_run("on_after_load");
242
238
  case 7:
239
+ _context5.next = 9;
240
+ return Promise.resolve(true);
241
+ case 9:
243
242
  return _context5.abrupt("return", _context5.sent);
244
- case 8:
243
+ case 10:
245
244
  case "end":
246
245
  return _context5.stop();
247
246
  }
@@ -252,55 +251,32 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
252
251
  }
253
252
  return onLoad;
254
253
  }()
255
- }, {
256
- key: "onSave",
257
- value:
258
254
  /**
259
255
  * Use this after succesful save to Database
260
256
  * @param p
261
257
  * @returns
262
258
  */
263
- function () {
259
+ }, {
260
+ key: "onSave",
261
+ value: function () {
264
262
  var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
265
- var _this2 = this;
266
- var srObject, actual_sr;
267
263
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
268
264
  while (1) switch (_context6.prev = _context6.next) {
269
265
  case 0:
270
- if (this.isSaved && this.obj) {
271
- this.apply_changes();
272
- srObject = this.obj.getSaveResult(true);
273
- if (srObject != null) {
274
- //we may have some extra data in the save result.
275
- //try to find the main data
276
- if (Array.isArray(srObject)) {
277
- actual_sr = srObject.find(function (s) {
278
- return _classPrivateMethodGet(_this2, _isValidSR, _isValidSR2).call(_this2, s);
279
- });
280
- if (actual_sr) srObject = actual_sr;
281
- }
282
- if (_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
283
- if (srObject.insertedId || srObject._id) {
284
- this.obj._id = srObject.insertedId || srObject._id;
285
- }
286
- if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
287
- this.obj._index_value = Number(srObject._index_value);
288
- }
289
- }
290
- }
291
- //this.loadValues(srObject);
292
- }
293
- _context6.next = 3;
266
+ _context6.next = 2;
294
267
  return this.event_run("on_save");
295
- case 3:
296
- _context6.next = 5;
268
+ case 2:
269
+ _context6.next = 4;
297
270
  return this.event_run("on_change", true);
298
- case 5:
299
- _context6.next = 7;
271
+ case 4:
272
+ _context6.next = 6;
273
+ return this.event_run("on_after_save");
274
+ case 6:
275
+ _context6.next = 8;
300
276
  return Promise.resolve(true);
301
- case 7:
302
- return _context6.abrupt("return", _context6.sent);
303
277
  case 8:
278
+ return _context6.abrupt("return", _context6.sent);
279
+ case 9:
304
280
  case "end":
305
281
  return _context6.stop();
306
282
  }
@@ -315,11 +291,6 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
315
291
  return WebObjectManager;
316
292
  }(_ObjectManager2["default"]);
317
293
  exports.WebObjectManager = WebObjectManager;
318
- function _isValidSR2(s) {
319
- if (_typeof(s) !== "object" && s == null) return false;
320
- return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
321
- }
322
- //we use this as backup
323
294
  _defineProperty(WebObjectManager, "__web_path", "");
324
295
  _defineProperty(WebObjectManager, "__web_type", "");
325
296
  var _default = WebObjectManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",