@azrico/webobject 1.5.68 → 1.5.70
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/dist/index.js +16 -1
- package/dist/src/WebObjects/ParentWebObject.js +115 -71
- package/dist/src/WebObjects/WebObject.js +1554 -584
- package/dist/src/WebObjects/WebObjectHelper.js +35 -15
- package/dist/src/WebObjects/WebObjectHelper.test.js +67 -45
- package/dist/src/WebObjects/WebObjectManager.js +864 -265
- package/dist/src/WebObjects/WebObjectPathHelper.js +142 -71
- package/dist/src/WebObjects/WebObjectPathHelper.test.js +122 -31
- package/dist/src/index.js +115 -10
- package/dist/src/structs/DummyObject.js +32 -8
- package/dist/src/structs/MapableObject.js +121 -75
- package/dist/src/structs/MetaObject.js +121 -35
- package/dist/src/structs/ObjectArray.js +68 -43
- package/dist/src/structs/ObjectManager.d.ts +4 -3
- package/dist/src/structs/ObjectManager.js +746 -285
- package/dist/src/structs/ObjectWithTemp.d.ts +2 -2
- package/dist/src/structs/ObjectWithTemp.js +67 -28
- package/dist/src/structs/SimpleObject.d.ts +2 -1
- package/dist/src/structs/SimpleObject.js +1704 -1044
- package/package.json +2 -2
|
@@ -1,214 +1,198 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.SimpleObject = void 0;
|
|
7
|
+
var _object = require("@azrico/object");
|
|
8
|
+
var _string = require("@azrico/string");
|
|
9
|
+
var _global = require("@azrico/global");
|
|
10
|
+
var _MapableObject2 = require("./MapableObject");
|
|
11
|
+
var _ObjectManager = _interopRequireDefault(require("./ObjectManager"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
14
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
16
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
20
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
21
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
|
|
23
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
24
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
25
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
26
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
27
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
28
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
29
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
30
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
31
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
32
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
33
|
+
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
34
|
+
function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
|
|
35
|
+
function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
|
|
36
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
37
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
38
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
39
|
+
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
40
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
41
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
42
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
43
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
44
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
45
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
46
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
47
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
48
|
+
var _objectColor = /*#__PURE__*/new WeakMap();
|
|
49
|
+
var _SimpleObject_brand = /*#__PURE__*/new WeakSet();
|
|
50
|
+
var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
51
|
+
function SimpleObject() {
|
|
52
|
+
var _this;
|
|
53
|
+
var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
54
|
+
_classCallCheck(this, SimpleObject);
|
|
55
|
+
_this = _callSuper(this, SimpleObject);
|
|
56
|
+
_classPrivateMethodInitSpec(_this, _SimpleObject_brand);
|
|
57
|
+
//an exact copy of this object is stored here
|
|
58
|
+
_defineProperty(_this, "__originalobject", void 0);
|
|
59
|
+
//changes are saved here
|
|
60
|
+
_defineProperty(_this, "__delta", {});
|
|
61
|
+
//// protected __has_delta: boolean = false;
|
|
62
|
+
//the last thing that was changed on this object
|
|
63
|
+
_defineProperty(_this, "__lastChanged", void 0);
|
|
64
|
+
//is the object read only
|
|
65
|
+
_defineProperty(_this, "__is_readonly", void 0);
|
|
66
|
+
//should we throw errors when encountering an error?
|
|
67
|
+
//is TRUE by default
|
|
68
|
+
_defineProperty(_this, "__throw_errors", void 0);
|
|
69
|
+
//is this object marked as deleted?
|
|
70
|
+
_defineProperty(_this, "_deleted", void 0);
|
|
71
|
+
_defineProperty(_this, "_archived", void 0);
|
|
72
|
+
_defineProperty(_this, "_deletedBy", void 0);
|
|
73
|
+
//is this object locked?
|
|
74
|
+
_defineProperty(_this, "_locked", void 0);
|
|
75
|
+
//errors
|
|
76
|
+
_defineProperty(_this, "__errors", void 0);
|
|
77
|
+
_defineProperty(_this, "__showErrors", void 0);
|
|
78
|
+
//refresh func
|
|
79
|
+
_defineProperty(_this, "__refresh_functions", void 0);
|
|
80
|
+
//save results
|
|
81
|
+
_defineProperty(_this, "__saveResultObject", void 0);
|
|
82
|
+
_defineProperty(_this, "__saveResultIsSuccess", true);
|
|
83
|
+
_defineProperty(_this, "__saveResultType", void 0);
|
|
84
|
+
//init function
|
|
85
|
+
_defineProperty(_this, "__initialized", void 0);
|
|
86
|
+
_classPrivateFieldInitSpec(_this, _objectColor, void 0);
|
|
87
|
+
//id in the database
|
|
88
|
+
_defineProperty(_this, "_id", "");
|
|
89
|
+
//sequence key (usually managed by the database)
|
|
90
|
+
_defineProperty(_this, "_index_key", "");
|
|
91
|
+
//sequence value , used to index the object with increasing numbers
|
|
92
|
+
_defineProperty(_this, "_index_value", -1);
|
|
93
|
+
_defineProperty(_this, "getSubValue", _assertClassBrand(_SimpleObject_brand, _this, _getSubProperty));
|
|
94
|
+
_defineProperty(_this, "setDefault", _this.setDefaultValue);
|
|
95
|
+
_defineProperty(_this, "setTemp", _this.set_temp);
|
|
96
|
+
_defineProperty(_this, "get_managerClass", function () {
|
|
97
|
+
return undefined;
|
|
98
|
+
});
|
|
99
|
+
_this.__is_readonly = is_readonly;
|
|
100
|
+
if (_this._id) _this.__table_id = _this._id;
|
|
101
|
+
_this.clear_changes();
|
|
102
|
+
return _this;
|
|
103
|
+
}
|
|
104
|
+
_inherits(SimpleObject, _MapableObject);
|
|
105
|
+
return _createClass(SimpleObject, [{
|
|
106
|
+
key: "_static",
|
|
107
|
+
value: function _static() {
|
|
108
|
+
return this.constructor;
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "init",
|
|
112
|
+
value: function init() {
|
|
113
|
+
this.__initialized = true;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "get",
|
|
117
|
+
value: function get(key) {
|
|
118
|
+
var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
119
|
+
//check if we should treat the prop as a function
|
|
120
|
+
var is_fnc = this.constructor["__functionProperties"] != null && this.constructor["__functionProperties"].includes(key);
|
|
121
|
+
//check if we should use delta version or normal version for this property
|
|
122
|
+
var used_value;
|
|
123
|
+
if (typeof key === "string" && key.includes(".")) {
|
|
124
|
+
/* ----------------------------- using sub value ---------------------------- */
|
|
125
|
+
var keysp = key.split(".");
|
|
126
|
+
var key_part = keysp.shift();
|
|
127
|
+
var subkey_part = keysp.shift();
|
|
128
|
+
used_value = _assertClassBrand(_SimpleObject_brand, this, _getSubProperty).call(this, key_part, subkey_part);
|
|
129
|
+
} else {
|
|
130
|
+
/* --------------------------- using this or delta -------------------------- */
|
|
131
|
+
var self_key = key;
|
|
132
|
+
var use_orig = original || !this.__use_delta || !(self_key in this.__delta);
|
|
133
|
+
used_value = use_orig ? this[self_key] : this.__delta[self_key];
|
|
134
|
+
}
|
|
135
|
+
return is_fnc ? (0, _object.fn_eval_this)(this, used_value) : used_value;
|
|
136
|
+
}
|
|
100
137
|
/**
|
|
101
138
|
* static get method for SimpleObject
|
|
102
139
|
* @param obj
|
|
103
140
|
* @param key
|
|
104
141
|
* @param original
|
|
105
142
|
* @returns
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (obj instanceof SimpleObject && typeof obj.get === "function")
|
|
111
|
-
return obj.get(key, original);
|
|
112
|
-
/* ------------------------------- manual get ------------------------------- */
|
|
113
|
-
if (!original &&
|
|
114
|
-
obj.__use_delta != false &&
|
|
115
|
-
typeof obj.__delta === "object" &&
|
|
116
|
-
key in obj.__delta) {
|
|
117
|
-
//@ts-ignore
|
|
118
|
-
return obj.__delta[key];
|
|
119
|
-
}
|
|
120
|
-
return obj[key];
|
|
121
|
-
}
|
|
143
|
+
*/
|
|
144
|
+
}, {
|
|
145
|
+
key: "use",
|
|
146
|
+
value:
|
|
122
147
|
/**
|
|
123
148
|
* use a property from the object, this will return latest value of the property
|
|
124
149
|
* uses `EventManager` to detect changes
|
|
125
150
|
*
|
|
126
151
|
* Only objects with a manager can use this function
|
|
127
|
-
*/
|
|
128
|
-
use(key) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return undefined;
|
|
145
|
-
return subobj[subkey];
|
|
146
|
-
}
|
|
147
|
-
getSubValue = this.#getSubProperty;
|
|
148
|
-
/* -------------------------------------------------------------------------- */
|
|
149
|
-
/* set */
|
|
150
|
-
/* -------------------------------------------------------------------------- */
|
|
152
|
+
*/
|
|
153
|
+
function use(key) {
|
|
154
|
+
if (this.manager == null) {
|
|
155
|
+
console.warn("Objects with no manager should not use useProperty");
|
|
156
|
+
return this.get(key);
|
|
157
|
+
}
|
|
158
|
+
var property_obj = this.manager.use(key);
|
|
159
|
+
if (_typeof(property_obj) === "object" && null != property_obj && key in property_obj) {
|
|
160
|
+
return property_obj[key];
|
|
161
|
+
}
|
|
162
|
+
return property_obj;
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "setDefaultValue",
|
|
166
|
+
value: /* -------------------------------------------------------------------------- */
|
|
167
|
+
/* set */
|
|
168
|
+
/* -------------------------------------------------------------------------- */
|
|
151
169
|
/**
|
|
152
170
|
* set value of a key only if the value is empty (null,undef,"")
|
|
153
171
|
* @param key
|
|
154
172
|
* @param value
|
|
155
173
|
* @returns
|
|
156
|
-
*/
|
|
157
|
-
setDefaultValue(key, value) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
subobj = {};
|
|
179
|
-
else
|
|
180
|
-
subobj = { ...subobj }; //make a clone so we dont update the original
|
|
181
|
-
subobj[subkey] = value;
|
|
182
|
-
this.#setProperty(key, subobj);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* update a property on this object by updating the `__delta`
|
|
186
|
-
* or update the object property directly depending on `__use_delta` setting
|
|
187
|
-
*
|
|
188
|
-
* @param key
|
|
189
|
-
* @param value
|
|
190
|
-
*/
|
|
191
|
-
#setProperty(key, value) {
|
|
192
|
-
let checkIsChanged = false;
|
|
193
|
-
if (this.__use_delta) {
|
|
194
|
-
if (this[key] === value) {
|
|
195
|
-
/**
|
|
196
|
-
* we set something back to its original value
|
|
197
|
-
* no need to save it as delta
|
|
198
|
-
*/
|
|
199
|
-
delete this.__delta[key];
|
|
200
|
-
////checkIsChanged = true; //check if we should set __has_delta to false
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
this.__delta[key] = value; //always update delta to keep track of changes
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this[key] = value; //on noDelta mode update the object itself
|
|
208
|
-
this.__delta[key] = value; //always update delta to keep track of changes
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
174
|
+
*/
|
|
175
|
+
function setDefaultValue(key, value) {
|
|
176
|
+
//@ts-ignore
|
|
177
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
178
|
+
this[key] = value;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "setDefaultPropertyNow",
|
|
185
|
+
value: function setDefaultPropertyNow(key) {
|
|
186
|
+
//@ts-ignore
|
|
187
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
188
|
+
this[key] = new Date();
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "set",
|
|
195
|
+
value: (
|
|
212
196
|
/**
|
|
213
197
|
* set value and run the event handlers if needed
|
|
214
198
|
* @param key
|
|
@@ -216,112 +200,236 @@ export class SimpleObject extends MapableObject {
|
|
|
216
200
|
* @param shouldNotify
|
|
217
201
|
* @param autoApply if the field is not in delta, instantly calls the `apply` function to remove from delta
|
|
218
202
|
* @returns
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
203
|
+
*/
|
|
204
|
+
function () {
|
|
205
|
+
var _set = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
|
|
206
|
+
var shouldNotify,
|
|
207
|
+
autoApply,
|
|
208
|
+
isValueChanged,
|
|
209
|
+
mkey,
|
|
210
|
+
keyExists,
|
|
211
|
+
finalResult,
|
|
212
|
+
changeablesOnly,
|
|
213
|
+
checkKeys,
|
|
214
|
+
index,
|
|
215
|
+
_key,
|
|
216
|
+
keysp,
|
|
217
|
+
subkey_part,
|
|
218
|
+
subval,
|
|
219
|
+
old_value,
|
|
220
|
+
_this$manager,
|
|
221
|
+
_args = arguments;
|
|
222
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
223
|
+
while (1) switch (_context.prev = _context.next) {
|
|
224
|
+
case 0:
|
|
225
|
+
shouldNotify = _args.length > 2 && _args[2] !== undefined ? _args[2] : "auto";
|
|
226
|
+
autoApply = _args.length > 3 && _args[3] !== undefined ? _args[3] : false;
|
|
227
|
+
if (this.canModify) {
|
|
228
|
+
_context.next = 8;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
if (!(this.__throw_errors !== false)) {
|
|
232
|
+
_context.next = 7;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
throw Error("Cant use set(".concat(String(key), ") when on readonly mode"));
|
|
236
|
+
case 7:
|
|
237
|
+
return _context.abrupt("return", false);
|
|
238
|
+
case 8:
|
|
239
|
+
keyExists = false;
|
|
240
|
+
/* -------------------------------------------------------------------------- */
|
|
241
|
+
/* set all values from object */
|
|
242
|
+
/* -------------------------------------------------------------------------- */
|
|
243
|
+
if (!(_typeof(key) === "object")) {
|
|
244
|
+
_context.next = 26;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
finalResult = true;
|
|
248
|
+
changeablesOnly = Boolean(value);
|
|
249
|
+
value = key;
|
|
250
|
+
checkKeys = changeablesOnly ? (0, _object.array_intersection)(this.__changeables, Object.keys(value)) : Object.keys(value);
|
|
251
|
+
index = 0;
|
|
252
|
+
case 15:
|
|
253
|
+
if (!(index < checkKeys.length)) {
|
|
254
|
+
_context.next = 25;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
_key = checkKeys[index];
|
|
258
|
+
_context.next = 19;
|
|
259
|
+
return this.set(_key, value[_key], shouldNotify, autoApply);
|
|
260
|
+
case 19:
|
|
261
|
+
_context.t0 = _context.sent;
|
|
262
|
+
if (!(false == _context.t0)) {
|
|
263
|
+
_context.next = 22;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
finalResult = false;
|
|
267
|
+
case 22:
|
|
268
|
+
index++;
|
|
269
|
+
_context.next = 15;
|
|
270
|
+
break;
|
|
271
|
+
case 25:
|
|
272
|
+
return _context.abrupt("return", finalResult);
|
|
273
|
+
case 26:
|
|
274
|
+
if (typeof key === "string" && key.includes(".")) {
|
|
275
|
+
/* -------------------------------------------------------------------------- */
|
|
276
|
+
/* set value of object */
|
|
277
|
+
/* -------------------------------------------------------------------------- */
|
|
278
|
+
keysp = key.split(".");
|
|
279
|
+
mkey = keysp.shift();
|
|
280
|
+
keyExists = mkey in this.__delta;
|
|
281
|
+
subkey_part = keysp.shift(); //if accessing subval of an object, make sure the object is not null
|
|
282
|
+
subval = _assertClassBrand(_SimpleObject_brand, this, _getSubProperty).call(this, mkey, subkey_part);
|
|
283
|
+
isValueChanged = !(0, _object.object_equals)(subval, value, {
|
|
284
|
+
ignoredStartingWords: "_",
|
|
285
|
+
strictArrayCheck: true
|
|
286
|
+
});
|
|
287
|
+
if (isValueChanged) _assertClassBrand(_SimpleObject_brand, this, _setSubProperty).call(this, mkey, subkey_part, value);
|
|
288
|
+
} else {
|
|
289
|
+
/* -------------------------------------------------------------------------- */
|
|
290
|
+
/* set basic value */
|
|
291
|
+
/* -------------------------------------------------------------------------- */
|
|
292
|
+
mkey = key;
|
|
293
|
+
keyExists = mkey in this.__delta;
|
|
294
|
+
old_value = this.get(mkey);
|
|
295
|
+
isValueChanged = !(0, _object.object_equals)(old_value, value, {
|
|
296
|
+
strictArrayCheck: true,
|
|
297
|
+
ignoredStartingWords: "_"
|
|
298
|
+
});
|
|
299
|
+
if (isValueChanged) _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, mkey, value);
|
|
300
|
+
}
|
|
301
|
+
if (autoApply && keyExists === false) {
|
|
302
|
+
/**
|
|
303
|
+
* if the field is not in delta
|
|
304
|
+
* instantly calls the `apply` function to remove from delta
|
|
305
|
+
*/
|
|
306
|
+
this.apply(mkey);
|
|
307
|
+
if (shouldNotify === "auto") shouldNotify = false;
|
|
308
|
+
}
|
|
309
|
+
if (isValueChanged) {
|
|
310
|
+
/**
|
|
311
|
+
* notify the manager when the state of `__has_delta` is changed
|
|
312
|
+
* managers can use this to detect if they need to save
|
|
313
|
+
*/
|
|
314
|
+
(_this$manager = this.manager) === null || _this$manager === void 0 || _this$manager.checkIsChanged();
|
|
315
|
+
}
|
|
316
|
+
/* --------------------------------- notify --------------------------------- */
|
|
317
|
+
if (!(shouldNotify === true || shouldNotify === "auto" && isValueChanged)) {
|
|
318
|
+
_context.next = 32;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
_context.next = 32;
|
|
322
|
+
return this.notifyChanged("", key, value);
|
|
323
|
+
case 32:
|
|
324
|
+
return _context.abrupt("return", isValueChanged);
|
|
325
|
+
case 33:
|
|
326
|
+
case "end":
|
|
327
|
+
return _context.stop();
|
|
328
|
+
}
|
|
329
|
+
}, _callee, this);
|
|
330
|
+
}));
|
|
331
|
+
function set(_x, _x2) {
|
|
332
|
+
return _set.apply(this, arguments);
|
|
333
|
+
}
|
|
334
|
+
return set;
|
|
335
|
+
}()
|
|
301
336
|
/**
|
|
302
337
|
* @deprecated use `set`
|
|
303
338
|
* set value and run the event handlers if needed
|
|
304
339
|
* @return true if changed , false otherwise
|
|
305
|
-
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
340
|
+
*/
|
|
341
|
+
)
|
|
342
|
+
}, {
|
|
343
|
+
key: "setValue",
|
|
344
|
+
value: (function () {
|
|
345
|
+
var _setValue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
|
|
346
|
+
var shouldNotify,
|
|
347
|
+
autoApply,
|
|
348
|
+
_args2 = arguments;
|
|
349
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
350
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
351
|
+
case 0:
|
|
352
|
+
shouldNotify = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : "auto";
|
|
353
|
+
autoApply = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : false;
|
|
354
|
+
_context2.next = 4;
|
|
355
|
+
return this.set(key, value, shouldNotify, autoApply);
|
|
356
|
+
case 4:
|
|
357
|
+
return _context2.abrupt("return", _context2.sent);
|
|
358
|
+
case 5:
|
|
359
|
+
case "end":
|
|
360
|
+
return _context2.stop();
|
|
361
|
+
}
|
|
362
|
+
}, _callee2, this);
|
|
363
|
+
}));
|
|
364
|
+
function setValue(_x3, _x4) {
|
|
365
|
+
return _setValue.apply(this, arguments);
|
|
366
|
+
}
|
|
367
|
+
return setValue;
|
|
368
|
+
}()
|
|
309
369
|
/**
|
|
310
370
|
* @deprecated use set function
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
371
|
+
*/
|
|
372
|
+
)
|
|
373
|
+
}, {
|
|
374
|
+
key: "setAll",
|
|
375
|
+
value: (function () {
|
|
376
|
+
var _setAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, value) {
|
|
377
|
+
var shouldNotify,
|
|
378
|
+
autoApply,
|
|
379
|
+
_args3 = arguments;
|
|
380
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
381
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
382
|
+
case 0:
|
|
383
|
+
shouldNotify = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : "auto";
|
|
384
|
+
autoApply = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : false;
|
|
385
|
+
_context3.next = 4;
|
|
386
|
+
return this.set(key, value, shouldNotify, autoApply);
|
|
387
|
+
case 4:
|
|
388
|
+
return _context3.abrupt("return", _context3.sent);
|
|
389
|
+
case 5:
|
|
390
|
+
case "end":
|
|
391
|
+
return _context3.stop();
|
|
392
|
+
}
|
|
393
|
+
}, _callee3, this);
|
|
394
|
+
}));
|
|
395
|
+
function setAll(_x5, _x6) {
|
|
396
|
+
return _setAll.apply(this, arguments);
|
|
397
|
+
}
|
|
398
|
+
return setAll;
|
|
399
|
+
}()
|
|
315
400
|
/**
|
|
316
401
|
* set value and run the event handlers if needed
|
|
317
402
|
*
|
|
318
403
|
* if the field is not in delta instantly calls the `apply` function to remove from delta
|
|
319
404
|
* @param key
|
|
320
405
|
* @param value
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
406
|
+
*/
|
|
407
|
+
)
|
|
408
|
+
}, {
|
|
409
|
+
key: "setPreferApply",
|
|
410
|
+
value: (function () {
|
|
411
|
+
var _setPreferApply = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, value) {
|
|
412
|
+
var shouldNotify,
|
|
413
|
+
_args4 = arguments;
|
|
414
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
415
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
416
|
+
case 0:
|
|
417
|
+
shouldNotify = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : "auto";
|
|
418
|
+
_context4.next = 3;
|
|
419
|
+
return this.set(key, value, shouldNotify, true);
|
|
420
|
+
case 3:
|
|
421
|
+
return _context4.abrupt("return", _context4.sent);
|
|
422
|
+
case 4:
|
|
423
|
+
case "end":
|
|
424
|
+
return _context4.stop();
|
|
425
|
+
}
|
|
426
|
+
}, _callee4, this);
|
|
427
|
+
}));
|
|
428
|
+
function setPreferApply(_x7, _x8) {
|
|
429
|
+
return _setPreferApply.apply(this, arguments);
|
|
430
|
+
}
|
|
431
|
+
return setPreferApply;
|
|
432
|
+
}()
|
|
325
433
|
/**
|
|
326
434
|
* set key of subObject
|
|
327
435
|
* @param key
|
|
@@ -329,131 +437,310 @@ export class SimpleObject extends MapableObject {
|
|
|
329
437
|
* @param subvalue
|
|
330
438
|
* @param sendChanges
|
|
331
439
|
* @return true if changed , false otherwise
|
|
332
|
-
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
440
|
+
*/
|
|
441
|
+
)
|
|
442
|
+
}, {
|
|
443
|
+
key: "setSubValue",
|
|
444
|
+
value: (function () {
|
|
445
|
+
var _setSubValue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, objKey, subvalue) {
|
|
446
|
+
var sendChanges,
|
|
447
|
+
_args5 = arguments;
|
|
448
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
449
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
450
|
+
case 0:
|
|
451
|
+
sendChanges = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : "auto";
|
|
452
|
+
_context5.next = 3;
|
|
453
|
+
return this.set("".concat(String(key), ".").concat(objKey), subvalue, sendChanges);
|
|
454
|
+
case 3:
|
|
455
|
+
return _context5.abrupt("return", _context5.sent);
|
|
456
|
+
case 4:
|
|
457
|
+
case "end":
|
|
458
|
+
return _context5.stop();
|
|
459
|
+
}
|
|
460
|
+
}, _callee5, this);
|
|
461
|
+
}));
|
|
462
|
+
function setSubValue(_x9, _x0, _x1) {
|
|
463
|
+
return _setSubValue.apply(this, arguments);
|
|
464
|
+
}
|
|
465
|
+
return setSubValue;
|
|
466
|
+
}())
|
|
467
|
+
}, {
|
|
468
|
+
key: "set_temp",
|
|
469
|
+
value: function () {
|
|
470
|
+
var _set_temp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(key, value) {
|
|
471
|
+
var sendChanges,
|
|
472
|
+
isValueChanged,
|
|
473
|
+
_args6 = arguments;
|
|
474
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
475
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
476
|
+
case 0:
|
|
477
|
+
sendChanges = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : false;
|
|
478
|
+
_context6.next = 3;
|
|
479
|
+
return _superPropGet(SimpleObject, "set_temp", this, 3)([key, value]);
|
|
480
|
+
case 3:
|
|
481
|
+
isValueChanged = _context6.sent;
|
|
482
|
+
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
483
|
+
_context6.next = 7;
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
_context6.next = 7;
|
|
487
|
+
return this.notifyChanged("temp", key, value);
|
|
488
|
+
case 7:
|
|
489
|
+
return _context6.abrupt("return", isValueChanged);
|
|
490
|
+
case 8:
|
|
491
|
+
case "end":
|
|
492
|
+
return _context6.stop();
|
|
493
|
+
}
|
|
494
|
+
}, _callee6, this);
|
|
495
|
+
}));
|
|
496
|
+
function set_temp(_x10, _x11) {
|
|
497
|
+
return _set_temp.apply(this, arguments);
|
|
498
|
+
}
|
|
499
|
+
return set_temp;
|
|
500
|
+
}()
|
|
501
|
+
}, {
|
|
502
|
+
key: "pushValue",
|
|
503
|
+
value: (
|
|
344
504
|
/**
|
|
345
505
|
* Push a single value to array property
|
|
346
506
|
* @param key
|
|
347
507
|
* @param value
|
|
348
508
|
* @param sendChanges
|
|
349
509
|
* @returns
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
510
|
+
*/
|
|
511
|
+
function () {
|
|
512
|
+
var _pushValue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(key, value) {
|
|
513
|
+
var sendChanges,
|
|
514
|
+
_args7 = arguments;
|
|
515
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
516
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
517
|
+
case 0:
|
|
518
|
+
sendChanges = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : "auto";
|
|
519
|
+
_context7.next = 3;
|
|
520
|
+
return this.pushValues(key, [value], sendChanges);
|
|
521
|
+
case 3:
|
|
522
|
+
return _context7.abrupt("return", _context7.sent);
|
|
523
|
+
case 4:
|
|
524
|
+
case "end":
|
|
525
|
+
return _context7.stop();
|
|
526
|
+
}
|
|
527
|
+
}, _callee7, this);
|
|
528
|
+
}));
|
|
529
|
+
function pushValue(_x12, _x13) {
|
|
530
|
+
return _pushValue.apply(this, arguments);
|
|
531
|
+
}
|
|
532
|
+
return pushValue;
|
|
533
|
+
}()
|
|
354
534
|
/**
|
|
355
535
|
* Push a list of values to array property
|
|
356
536
|
* @param key
|
|
357
537
|
* @param values
|
|
358
538
|
* @param sendChanges
|
|
359
539
|
* @returns
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
540
|
+
*/
|
|
541
|
+
)
|
|
542
|
+
}, {
|
|
543
|
+
key: "pushValues",
|
|
544
|
+
value: (function () {
|
|
545
|
+
var _pushValues = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(key, values) {
|
|
546
|
+
var sendChanges,
|
|
547
|
+
tempArray,
|
|
548
|
+
_args8 = arguments;
|
|
549
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
550
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
551
|
+
case 0:
|
|
552
|
+
sendChanges = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : "auto";
|
|
553
|
+
if (!(0, _object.array_isEmpty)(values)) {
|
|
554
|
+
_context8.next = 3;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
return _context8.abrupt("return", false);
|
|
558
|
+
case 3:
|
|
559
|
+
if (this.canModify) {
|
|
560
|
+
_context8.next = 9;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
if (!(this.__throw_errors !== false)) {
|
|
564
|
+
_context8.next = 8;
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
throw Error("Cant use pushValues (".concat(String(key), ") when on readonly mode"));
|
|
568
|
+
case 8:
|
|
569
|
+
return _context8.abrupt("return", false);
|
|
570
|
+
case 9:
|
|
571
|
+
if (this.get(key) == null) _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, []);
|
|
572
|
+
tempArray = this.get(key);
|
|
573
|
+
if (Array.isArray(tempArray)) {
|
|
574
|
+
_context8.next = 17;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
if (!(this.__throw_errors !== false)) {
|
|
578
|
+
_context8.next = 16;
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
throw Error("Cant use pushValues (".concat(String(key), ") on non Array keys"));
|
|
582
|
+
case 16:
|
|
583
|
+
return _context8.abrupt("return", false);
|
|
584
|
+
case 17:
|
|
585
|
+
_assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, (0, _object.array_merge)(tempArray, values));
|
|
586
|
+
if (!(sendChanges === true || sendChanges === "auto")) {
|
|
587
|
+
_context8.next = 21;
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
_context8.next = 21;
|
|
591
|
+
return this.notifyChanged("", key, values);
|
|
592
|
+
case 21:
|
|
593
|
+
return _context8.abrupt("return", tempArray);
|
|
594
|
+
case 22:
|
|
595
|
+
case "end":
|
|
596
|
+
return _context8.stop();
|
|
597
|
+
}
|
|
598
|
+
}, _callee8, this);
|
|
599
|
+
}));
|
|
600
|
+
function pushValues(_x14, _x15) {
|
|
601
|
+
return _pushValues.apply(this, arguments);
|
|
602
|
+
}
|
|
603
|
+
return pushValues;
|
|
604
|
+
}()
|
|
605
|
+
/* -------------------------------------------------------------------------- */
|
|
606
|
+
/* Load */
|
|
607
|
+
/* -------------------------------------------------------------------------- */
|
|
387
608
|
/**
|
|
388
609
|
* load all properties in `initObject` into the current object
|
|
389
610
|
* @param initObject
|
|
390
611
|
* @param fullUpdate
|
|
391
612
|
* @returns
|
|
392
|
-
*/
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
613
|
+
*/
|
|
614
|
+
)
|
|
615
|
+
}, {
|
|
616
|
+
key: "loadValues",
|
|
617
|
+
value: function loadValues(initObject) {
|
|
618
|
+
var fullUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
619
|
+
return SimpleObject.loadValues(this, initObject, fullUpdate);
|
|
620
|
+
}
|
|
621
|
+
}, {
|
|
622
|
+
key: "clearRefreshFunction",
|
|
623
|
+
value: (
|
|
624
|
+
/* -------------------------------------------------------------------------- */
|
|
625
|
+
/* Refresh Functions */
|
|
626
|
+
/* -------------------------------------------------------------------------- */
|
|
627
|
+
function () {
|
|
628
|
+
var _clearRefreshFunction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
629
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
630
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
631
|
+
case 0:
|
|
632
|
+
this.__refresh_functions = undefined;
|
|
633
|
+
case 1:
|
|
634
|
+
case "end":
|
|
635
|
+
return _context9.stop();
|
|
636
|
+
}
|
|
637
|
+
}, _callee9, this);
|
|
638
|
+
}));
|
|
639
|
+
function clearRefreshFunction() {
|
|
640
|
+
return _clearRefreshFunction.apply(this, arguments);
|
|
641
|
+
}
|
|
642
|
+
return clearRefreshFunction;
|
|
643
|
+
}())
|
|
644
|
+
}, {
|
|
645
|
+
key: "setRefreshFunction",
|
|
646
|
+
value: function () {
|
|
647
|
+
var _setRefreshFunction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(new_fnc) {
|
|
648
|
+
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
649
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
650
|
+
case 0:
|
|
651
|
+
_context0.next = 2;
|
|
652
|
+
return this.addRefreshFunction(new_fnc);
|
|
653
|
+
case 2:
|
|
654
|
+
return _context0.abrupt("return", _context0.sent);
|
|
655
|
+
case 3:
|
|
656
|
+
case "end":
|
|
657
|
+
return _context0.stop();
|
|
658
|
+
}
|
|
659
|
+
}, _callee0, this);
|
|
660
|
+
}));
|
|
661
|
+
function setRefreshFunction(_x16) {
|
|
662
|
+
return _setRefreshFunction.apply(this, arguments);
|
|
663
|
+
}
|
|
664
|
+
return setRefreshFunction;
|
|
665
|
+
}()
|
|
666
|
+
}, {
|
|
667
|
+
key: "addRefreshFunction",
|
|
668
|
+
value: function () {
|
|
669
|
+
var _addRefreshFunction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(key, new_fnc) {
|
|
670
|
+
var oldFunctions;
|
|
671
|
+
return _regeneratorRuntime().wrap(function _callee1$(_context1) {
|
|
672
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
673
|
+
case 0:
|
|
674
|
+
if (typeof key === "function") {
|
|
675
|
+
new_fnc = key;
|
|
676
|
+
key = "main";
|
|
677
|
+
}
|
|
678
|
+
key = key || "main";
|
|
679
|
+
oldFunctions = this.__refresh_functions;
|
|
680
|
+
if (oldFunctions == null || _typeof(oldFunctions) !== "object") oldFunctions = {};
|
|
681
|
+
oldFunctions[key] = new_fnc;
|
|
682
|
+
this.__refresh_functions = oldFunctions;
|
|
683
|
+
case 6:
|
|
684
|
+
case "end":
|
|
685
|
+
return _context1.stop();
|
|
686
|
+
}
|
|
687
|
+
}, _callee1, this);
|
|
688
|
+
}));
|
|
689
|
+
function addRefreshFunction(_x17, _x18) {
|
|
690
|
+
return _addRefreshFunction.apply(this, arguments);
|
|
691
|
+
}
|
|
692
|
+
return addRefreshFunction;
|
|
693
|
+
}()
|
|
694
|
+
}, {
|
|
695
|
+
key: "runRefreshFunction",
|
|
696
|
+
value: function () {
|
|
697
|
+
var _runRefreshFunction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
698
|
+
var oldFunctions,
|
|
699
|
+
fncArray,
|
|
700
|
+
_len,
|
|
701
|
+
params,
|
|
702
|
+
_key2,
|
|
703
|
+
index,
|
|
704
|
+
fnc,
|
|
705
|
+
_args10 = arguments;
|
|
706
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
707
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
708
|
+
case 0:
|
|
709
|
+
oldFunctions = this.__refresh_functions;
|
|
710
|
+
if (!(oldFunctions == null || _typeof(oldFunctions) !== "object")) {
|
|
711
|
+
_context10.next = 3;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
return _context10.abrupt("return");
|
|
715
|
+
case 3:
|
|
716
|
+
fncArray = Object.values(oldFunctions);
|
|
717
|
+
for (_len = _args10.length, params = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
|
|
718
|
+
params[_key2] = _args10[_key2];
|
|
719
|
+
}
|
|
720
|
+
index = 0;
|
|
721
|
+
case 6:
|
|
722
|
+
if (!(index < fncArray.length)) {
|
|
723
|
+
_context10.next = 13;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
fnc = fncArray[index];
|
|
727
|
+
_context10.next = 10;
|
|
728
|
+
return _object.fn_eval.apply(void 0, [fnc].concat(params));
|
|
729
|
+
case 10:
|
|
730
|
+
index++;
|
|
731
|
+
_context10.next = 6;
|
|
732
|
+
break;
|
|
733
|
+
case 13:
|
|
734
|
+
case "end":
|
|
735
|
+
return _context10.stop();
|
|
736
|
+
}
|
|
737
|
+
}, _callee10, this);
|
|
738
|
+
}));
|
|
739
|
+
function runRefreshFunction() {
|
|
740
|
+
return _runRefreshFunction.apply(this, arguments);
|
|
741
|
+
}
|
|
742
|
+
return runRefreshFunction;
|
|
743
|
+
}()
|
|
457
744
|
/**
|
|
458
745
|
*
|
|
459
746
|
* @param type
|
|
@@ -461,693 +748,1066 @@ export class SimpleObject extends MapableObject {
|
|
|
461
748
|
* @param value
|
|
462
749
|
* @param subvalue
|
|
463
750
|
* @returns true if manager was notified. false otherwise
|
|
464
|
-
*/
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
751
|
+
*/
|
|
752
|
+
}, {
|
|
753
|
+
key: "notifyChanged",
|
|
754
|
+
value: (function () {
|
|
755
|
+
var _notifyChanged = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(type, key, value, subvalue) {
|
|
756
|
+
var lc, manager_class;
|
|
757
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
758
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
759
|
+
case 0:
|
|
760
|
+
if (value === undefined && type == "") value = this.get(key);
|
|
761
|
+
lc = "";
|
|
762
|
+
if (type) lc += "$".concat(String(type), "$");
|
|
763
|
+
if (subvalue) {
|
|
764
|
+
lc += "".concat(String(key), ".").concat(value);
|
|
765
|
+
} else {
|
|
766
|
+
lc += "".concat(String(key));
|
|
767
|
+
}
|
|
768
|
+
this.__lastChanged = lc;
|
|
769
|
+
/* --------------------------- notify the manager --------------------------- */
|
|
770
|
+
manager_class = this.manager;
|
|
771
|
+
if (!(typeof (manager_class === null || manager_class === void 0 ? void 0 : manager_class.notifyChanged) === "function")) {
|
|
772
|
+
_context11.next = 10;
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
_context11.next = 9;
|
|
776
|
+
return manager_class.notifyChanged(type, key, value, subvalue);
|
|
777
|
+
case 9:
|
|
778
|
+
return _context11.abrupt("return", _context11.sent);
|
|
779
|
+
case 10:
|
|
780
|
+
return _context11.abrupt("return", false);
|
|
781
|
+
case 11:
|
|
782
|
+
case "end":
|
|
783
|
+
return _context11.stop();
|
|
784
|
+
}
|
|
785
|
+
}, _callee11, this);
|
|
786
|
+
}));
|
|
787
|
+
function notifyChanged(_x19, _x20, _x21, _x22) {
|
|
788
|
+
return _notifyChanged.apply(this, arguments);
|
|
789
|
+
}
|
|
790
|
+
return notifyChanged;
|
|
791
|
+
}()
|
|
485
792
|
/**
|
|
486
793
|
* get a list of all keys that can be changed in given objcet
|
|
487
794
|
* @param object
|
|
488
795
|
* @param options
|
|
489
796
|
* @returns
|
|
490
|
-
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (!array_isEmpty(__unchangeables)) {
|
|
498
|
-
key_list = key_list.filter((s) => !__unchangeables.includes(s));
|
|
499
|
-
}
|
|
500
|
-
/* -------------------------------------------------------------------------- */
|
|
501
|
-
if (options.extraProperties) {
|
|
502
|
-
key_list.push(...object.constructor["__extraProperties"]);
|
|
503
|
-
}
|
|
504
|
-
if (options.tempProperties) {
|
|
505
|
-
key_list.push("__temp");
|
|
506
|
-
key_list.push(...object.constructor["__tempProperties"]);
|
|
507
|
-
}
|
|
508
|
-
if (options.bypassProtected !== true && !options.allProperties) {
|
|
509
|
-
const __protectedProperties = object.constructor["__protectedProperties"];
|
|
510
|
-
//protected keys can only be changed by the creator of this object
|
|
511
|
-
//make sure you set the is_current_user function correctly
|
|
512
|
-
if (!object.isNew &&
|
|
513
|
-
!array_isEmpty(__protectedProperties) &&
|
|
514
|
-
!Boolean(gfunc.run_action_sync("is_current_user", object.get("_creator")))) {
|
|
515
|
-
key_list = key_list.filter((s) => !__protectedProperties.includes(s));
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
return key_list;
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* check if a key can be changed on an object
|
|
522
|
-
* @param object the object we are checking
|
|
523
|
-
* @param key key of the object
|
|
524
|
-
* @param useExtraProps should we check extra props?
|
|
525
|
-
* @returns
|
|
526
|
-
*/
|
|
527
|
-
static canChangeKey(object, key, options) {
|
|
528
|
-
if (!object || !key)
|
|
529
|
-
return false;
|
|
530
|
-
const keys = this.getChangeableKeys(object, options);
|
|
531
|
-
return keys.includes(key);
|
|
532
|
-
}
|
|
533
|
-
static hasIllegalChanges(referenceObject, changesObject, updaterUser) {
|
|
534
|
-
const __protectedProperties = object_getStatic(referenceObject, "__protectedProperties");
|
|
535
|
-
if (object_isEmpty(__protectedProperties))
|
|
536
|
-
return false;
|
|
537
|
-
const referenceUser = object_isClass(referenceObject)
|
|
538
|
-
? object_get(changesObject, "__user", "_creator")
|
|
539
|
-
: object_get(referenceObject, "__user", "_creator");
|
|
540
|
-
if (Boolean(SimpleObject.getID(referenceUser) ==
|
|
541
|
-
SimpleObject.getID(updaterUser))) {
|
|
542
|
-
return false;
|
|
543
|
-
}
|
|
544
|
-
for (const key in changesObject) {
|
|
545
|
-
if (__protectedProperties.includes(key)) {
|
|
546
|
-
return true;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
/* -------------------------------------------------------------------------- */
|
|
552
|
-
/* Changes */
|
|
553
|
-
/* -------------------------------------------------------------------------- */
|
|
797
|
+
*/
|
|
798
|
+
)
|
|
799
|
+
}, {
|
|
800
|
+
key: "apply_changes",
|
|
801
|
+
value: /* -------------------------------------------------------------------------- */
|
|
802
|
+
/* Changes */
|
|
803
|
+
/* -------------------------------------------------------------------------- */
|
|
554
804
|
/**
|
|
555
805
|
* Apply all the changes and empty the delta object
|
|
556
|
-
*/
|
|
557
|
-
apply_changes() {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
806
|
+
*/
|
|
807
|
+
function apply_changes() {
|
|
808
|
+
try {
|
|
809
|
+
if (!this.__use_delta) {
|
|
810
|
+
/**
|
|
811
|
+
* in this mode , we track changes by updating the original product
|
|
812
|
+
*/
|
|
813
|
+
this.setOriginal();
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
if (!this.isChanged) {
|
|
817
|
+
console.warn("No changes to apply");
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
for (var key in this.__delta) {
|
|
821
|
+
var nv = this.__delta[key];
|
|
822
|
+
this[key] = nv;
|
|
823
|
+
}
|
|
824
|
+
return true;
|
|
825
|
+
} finally {
|
|
826
|
+
this.clear_changes();
|
|
827
|
+
}
|
|
828
|
+
}
|
|
580
829
|
/**
|
|
581
830
|
* apply changes for the given fields
|
|
582
831
|
* @param key
|
|
583
832
|
* @returns
|
|
584
|
-
*/
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
833
|
+
*/
|
|
834
|
+
}, {
|
|
835
|
+
key: "apply",
|
|
836
|
+
value: function apply(keylist) {
|
|
837
|
+
if (!this.__use_delta) {
|
|
838
|
+
/**
|
|
839
|
+
* in this mode , we track changes by updating the original
|
|
840
|
+
*/
|
|
841
|
+
return true;
|
|
842
|
+
}
|
|
843
|
+
if (this.__delta == null || Object.keys(this.__delta).length == 0) {
|
|
844
|
+
/**
|
|
845
|
+
* nothing to apply
|
|
846
|
+
*/
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
keylist = (0, _object.wrap_array)(keylist);
|
|
850
|
+
if (keylist.length == 0) {
|
|
851
|
+
/**
|
|
852
|
+
* nothing to apply
|
|
853
|
+
*/
|
|
854
|
+
return true;
|
|
855
|
+
}
|
|
856
|
+
var _iterator = _createForOfIteratorHelper(keylist),
|
|
857
|
+
_step;
|
|
858
|
+
try {
|
|
859
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
860
|
+
var key = _step.value;
|
|
861
|
+
if (key in this.__delta) {
|
|
862
|
+
this[key] = this.__delta[key];
|
|
863
|
+
delete this.__delta[key];
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
} catch (err) {
|
|
867
|
+
_iterator.e(err);
|
|
868
|
+
} finally {
|
|
869
|
+
_iterator.f();
|
|
870
|
+
}
|
|
871
|
+
return true;
|
|
872
|
+
}
|
|
613
873
|
/**
|
|
614
874
|
* set the value to its original
|
|
615
875
|
* @param key
|
|
616
|
-
*/
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
876
|
+
*/
|
|
877
|
+
}, {
|
|
878
|
+
key: "discard",
|
|
879
|
+
value: (function () {
|
|
880
|
+
var _discard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(key) {
|
|
881
|
+
var shouldNotify,
|
|
882
|
+
originalValue,
|
|
883
|
+
_args12 = arguments;
|
|
884
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
885
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
886
|
+
case 0:
|
|
887
|
+
shouldNotify = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : "auto";
|
|
888
|
+
if (this.__use_delta) {
|
|
889
|
+
originalValue = this[key];
|
|
890
|
+
} else if (this.__originalobject) originalValue = this.__originalobject[key];else originalValue = this[key];
|
|
891
|
+
_context12.next = 4;
|
|
892
|
+
return this.set(key, originalValue, shouldNotify);
|
|
893
|
+
case 4:
|
|
894
|
+
return _context12.abrupt("return", _context12.sent);
|
|
895
|
+
case 5:
|
|
896
|
+
case "end":
|
|
897
|
+
return _context12.stop();
|
|
898
|
+
}
|
|
899
|
+
}, _callee12, this);
|
|
900
|
+
}));
|
|
901
|
+
function discard(_x23) {
|
|
902
|
+
return _discard.apply(this, arguments);
|
|
903
|
+
}
|
|
904
|
+
return discard;
|
|
905
|
+
}()
|
|
628
906
|
/**
|
|
629
907
|
* reset all values back to their original
|
|
630
908
|
*
|
|
631
909
|
* this function also calls `on_change` and then `clear_changes`
|
|
632
910
|
* @param key
|
|
633
|
-
*/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
911
|
+
*/
|
|
912
|
+
)
|
|
913
|
+
}, {
|
|
914
|
+
key: "discardAll",
|
|
915
|
+
value: (function () {
|
|
916
|
+
var _discardAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
917
|
+
var shouldNotify,
|
|
918
|
+
final_result,
|
|
919
|
+
key,
|
|
920
|
+
_args13 = arguments;
|
|
921
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
922
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
923
|
+
case 0:
|
|
924
|
+
shouldNotify = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : "auto";
|
|
925
|
+
final_result = true;
|
|
926
|
+
_context13.t0 = _regeneratorRuntime().keys(this.__delta);
|
|
927
|
+
case 3:
|
|
928
|
+
if ((_context13.t1 = _context13.t0()).done) {
|
|
929
|
+
_context13.next = 13;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
key = _context13.t1.value;
|
|
933
|
+
_context13.t2 = final_result;
|
|
934
|
+
if (!_context13.t2) {
|
|
935
|
+
_context13.next = 10;
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
_context13.next = 9;
|
|
939
|
+
return this.discard(key, shouldNotify);
|
|
940
|
+
case 9:
|
|
941
|
+
_context13.t2 = _context13.sent;
|
|
942
|
+
case 10:
|
|
943
|
+
final_result = _context13.t2;
|
|
944
|
+
_context13.next = 3;
|
|
945
|
+
break;
|
|
946
|
+
case 13:
|
|
947
|
+
if (final_result) this.clear_changes();
|
|
948
|
+
return _context13.abrupt("return", final_result);
|
|
949
|
+
case 15:
|
|
950
|
+
case "end":
|
|
951
|
+
return _context13.stop();
|
|
952
|
+
}
|
|
953
|
+
}, _callee13, this);
|
|
954
|
+
}));
|
|
955
|
+
function discardAll() {
|
|
956
|
+
return _discardAll.apply(this, arguments);
|
|
957
|
+
}
|
|
958
|
+
return discardAll;
|
|
959
|
+
}()
|
|
644
960
|
/**
|
|
645
961
|
* clear and discard all changes
|
|
646
962
|
*
|
|
647
963
|
* does not call `on_change` functions
|
|
648
964
|
* @returns
|
|
649
|
-
*/
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
965
|
+
*/
|
|
966
|
+
)
|
|
967
|
+
}, {
|
|
968
|
+
key: "clear_changes",
|
|
969
|
+
value: function clear_changes() {
|
|
970
|
+
this.__delta = {};
|
|
971
|
+
////this.__has_delta = false;
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
655
974
|
/**
|
|
656
975
|
* Sets readonly property on given objects
|
|
657
976
|
* @param objs array of given objects or a single object
|
|
658
977
|
* @param readonlyval readonly
|
|
659
978
|
* @param clearChanges should we clean the changes after setting readonly
|
|
660
|
-
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
static setThrowErrors(objs, throwErr = true) {
|
|
687
|
-
let checkObjs = [];
|
|
688
|
-
if (!objs)
|
|
689
|
-
objs = [];
|
|
690
|
-
if (!Array.isArray(objs))
|
|
691
|
-
checkObjs = [objs];
|
|
692
|
-
else
|
|
693
|
-
checkObjs = objs;
|
|
694
|
-
for (let index = 0; index < checkObjs.length; index++) {
|
|
695
|
-
const element = checkObjs[index];
|
|
696
|
-
element.__throw_errors = throwErr;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
/* -------------------------------------------------------------------------- */
|
|
700
|
-
/* Get/Check */
|
|
701
|
-
/* -------------------------------------------------------------------------- */
|
|
702
|
-
get __object_name() {
|
|
703
|
-
return this.constructor["__object_name"] || this.__db_name;
|
|
704
|
-
}
|
|
705
|
-
get __db_name() {
|
|
706
|
-
return this.constructor["__db_name"] || this.constructor["__web_path"];
|
|
707
|
-
}
|
|
708
|
-
get isChanged() {
|
|
709
|
-
////const deltaIsBlank = object_isEmpty(this.__delta);
|
|
710
|
-
////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
|
|
711
|
-
////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
|
|
712
|
-
if (this.__use_delta) {
|
|
713
|
-
////return this.__has_delta;
|
|
714
|
-
/**
|
|
715
|
-
* if there is any key in delta, then the object is changed
|
|
716
|
-
*/
|
|
717
|
-
for (const key in this.__delta)
|
|
718
|
-
return true;
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
/* --------------------- check the properties one by one -------------------- */
|
|
722
|
-
const orig = this.getOriginal();
|
|
723
|
-
if (!orig)
|
|
724
|
-
return false; //we dont know if anything has changed
|
|
979
|
+
*/
|
|
980
|
+
}, {
|
|
981
|
+
key: "__object_name",
|
|
982
|
+
get: /* -------------------------------------------------------------------------- */
|
|
983
|
+
/* Get/Check */
|
|
984
|
+
/* -------------------------------------------------------------------------- */
|
|
985
|
+
function get() {
|
|
986
|
+
return this.constructor["__object_name"] || this.__db_name;
|
|
987
|
+
}
|
|
988
|
+
}, {
|
|
989
|
+
key: "__db_name",
|
|
990
|
+
get: function get() {
|
|
991
|
+
return this.constructor["__db_name"] || this.constructor["__web_path"];
|
|
992
|
+
}
|
|
993
|
+
}, {
|
|
994
|
+
key: "isChanged",
|
|
995
|
+
get: function get() {
|
|
996
|
+
var _this2 = this;
|
|
997
|
+
////const deltaIsBlank = object_isEmpty(this.__delta);
|
|
998
|
+
////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
|
|
999
|
+
////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
|
|
1000
|
+
if (this.__use_delta) {
|
|
1001
|
+
////return this.__has_delta;
|
|
725
1002
|
/**
|
|
726
|
-
* if
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
get
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
get
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1003
|
+
* if there is any key in delta, then the object is changed
|
|
1004
|
+
*/
|
|
1005
|
+
for (var key in this.__delta) return true;
|
|
1006
|
+
return false;
|
|
1007
|
+
}
|
|
1008
|
+
/* --------------------- check the properties one by one -------------------- */
|
|
1009
|
+
var orig = this.getOriginal();
|
|
1010
|
+
if (!orig) return false; //we dont know if anything has changed
|
|
1011
|
+
/**
|
|
1012
|
+
* if object is not using delta mode,
|
|
1013
|
+
* check changes by comparing changeable fields with original object
|
|
1014
|
+
*/
|
|
1015
|
+
if (Array.isArray(this.__changeables)) {
|
|
1016
|
+
return this.__changeables.find(function (c) {
|
|
1017
|
+
return !(0, _object.object_equals)(_this2[c], orig[c]);
|
|
1018
|
+
}) != undefined;
|
|
1019
|
+
} else {
|
|
1020
|
+
/* check all fields */
|
|
1021
|
+
for (var _key3 in this) {
|
|
1022
|
+
if (_key3.startsWith("__")) continue;
|
|
1023
|
+
if (!(0, _object.object_equals)(this[_key3], orig[_key3])) return true;
|
|
1024
|
+
}
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}, {
|
|
1029
|
+
key: "isArchived",
|
|
1030
|
+
get: function get() {
|
|
1031
|
+
return this._archived || false;
|
|
1032
|
+
},
|
|
1033
|
+
set: function set(v) {
|
|
1034
|
+
this._archived = v;
|
|
1035
|
+
}
|
|
1036
|
+
}, {
|
|
1037
|
+
key: "isDeleted",
|
|
1038
|
+
get: function get() {
|
|
1039
|
+
return this.get("_deleted") || false;
|
|
1040
|
+
},
|
|
1041
|
+
set: function set(v) {
|
|
1042
|
+
this._deleted = v;
|
|
1043
|
+
}
|
|
1044
|
+
}, {
|
|
1045
|
+
key: "isLocked",
|
|
1046
|
+
get: function get() {
|
|
1047
|
+
return this.get("_locked") || false;
|
|
1048
|
+
},
|
|
1049
|
+
set: function set(v) {
|
|
1050
|
+
this._locked = v;
|
|
1051
|
+
}
|
|
1052
|
+
}, {
|
|
1053
|
+
key: "objectColor",
|
|
1054
|
+
get: function get() {
|
|
1055
|
+
if (!_classPrivateFieldGet(_objectColor, this)) {
|
|
1056
|
+
var lastid = this.getID();
|
|
1057
|
+
if (lastid) _classPrivateFieldSet(_objectColor, this, (0, _string.string_to_color)(lastid));
|
|
1058
|
+
}
|
|
1059
|
+
return _classPrivateFieldGet(_objectColor, this) || "#000000";
|
|
1060
|
+
}
|
|
1061
|
+
}, {
|
|
1062
|
+
key: "d",
|
|
1063
|
+
get: function get() {
|
|
1064
|
+
return this.__use_delta ? this.__delta : this;
|
|
1065
|
+
}
|
|
1066
|
+
/* all updated properties */
|
|
1067
|
+
}, {
|
|
1068
|
+
key: "allproperties",
|
|
1069
|
+
get: function get() {
|
|
1070
|
+
var result = _objectSpread(_objectSpread({}, this), this.__delta);
|
|
1071
|
+
result.__delta = {};
|
|
1072
|
+
return result;
|
|
1073
|
+
}
|
|
1074
|
+
}, {
|
|
1075
|
+
key: "canModify",
|
|
1076
|
+
get: function get() {
|
|
1077
|
+
return !Boolean(this.__is_readonly);
|
|
1078
|
+
}
|
|
1079
|
+
}, {
|
|
1080
|
+
key: "__changeables",
|
|
1081
|
+
get: function get() {
|
|
1082
|
+
return this.constructor["__changeables"];
|
|
1083
|
+
}
|
|
1084
|
+
}, {
|
|
1085
|
+
key: "__unchangeables",
|
|
1086
|
+
get: function get() {
|
|
1087
|
+
return this.constructor["__unchangeables"];
|
|
1088
|
+
}
|
|
1089
|
+
}, {
|
|
1090
|
+
key: "__use_delta",
|
|
1091
|
+
get: function get() {
|
|
1092
|
+
return this.constructor["__use_delta"];
|
|
1093
|
+
}
|
|
1094
|
+
}, {
|
|
1095
|
+
key: "isSaved",
|
|
1096
|
+
get: function get() {
|
|
1097
|
+
var _this$__saveResultIsS;
|
|
1098
|
+
return Boolean((_this$__saveResultIsS = this.__saveResultIsSuccess) !== null && _this$__saveResultIsS !== void 0 ? _this$__saveResultIsS : false);
|
|
1099
|
+
}
|
|
1100
|
+
}, {
|
|
1101
|
+
key: "isNew",
|
|
1102
|
+
get: function get() {
|
|
1103
|
+
var mid = this.getID();
|
|
1104
|
+
if (!mid) return true;
|
|
1105
|
+
if (typeof mid === "string") return mid === "" || mid === "-1";
|
|
1106
|
+
if (typeof mid === "number") return mid === -1;
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
}, {
|
|
1110
|
+
key: "lastChanged",
|
|
1111
|
+
get: function get() {
|
|
1112
|
+
return this.__lastChanged || "";
|
|
1113
|
+
}
|
|
1114
|
+
}, {
|
|
1115
|
+
key: "manager",
|
|
1116
|
+
get: function get() {
|
|
1117
|
+
return this.get_managerClass() || undefined;
|
|
1118
|
+
}
|
|
1119
|
+
}, {
|
|
1120
|
+
key: "set_managerClass",
|
|
1121
|
+
value:
|
|
812
1122
|
/**
|
|
813
1123
|
* @deprecated use setManager
|
|
814
1124
|
* @param mng
|
|
815
|
-
*/
|
|
816
|
-
set_managerClass(mng) {
|
|
817
|
-
|
|
818
|
-
}
|
|
1125
|
+
*/
|
|
1126
|
+
function set_managerClass(mng) {
|
|
1127
|
+
return this.setManager(mng);
|
|
1128
|
+
}
|
|
819
1129
|
/**
|
|
820
1130
|
* update the manager class for this object
|
|
821
1131
|
* @param mng
|
|
822
|
-
*/
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
getID
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
case "
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
static clearErrors(o) {
|
|
994
|
-
if (o)
|
|
995
|
-
o.__errors = [];
|
|
996
|
-
return true;
|
|
997
|
-
}
|
|
998
|
-
/* -------------------------------------------------------------------------- */
|
|
999
|
-
/* Save Results */
|
|
1000
|
-
/* -------------------------------------------------------------------------- */
|
|
1001
|
-
/**
|
|
1002
|
-
* Checks if the given object is a valid and truthy save result
|
|
1003
|
-
* @param result_object
|
|
1004
|
-
* @returns
|
|
1005
|
-
*/
|
|
1006
|
-
static isResultValid(result_object, depth = 0) {
|
|
1007
|
-
if (object_isEmpty(result_object))
|
|
1008
|
-
return false;
|
|
1009
|
-
switch (typeof result_object) {
|
|
1010
|
-
case "string":
|
|
1011
|
-
try {
|
|
1012
|
-
result_object = JSON.parse(result_object);
|
|
1013
|
-
return this.isResultValid(result_object);
|
|
1014
|
-
}
|
|
1015
|
-
catch {
|
|
1016
|
-
return false;
|
|
1017
|
-
}
|
|
1018
|
-
case "number":
|
|
1019
|
-
return result_object > 0;
|
|
1020
|
-
case "boolean":
|
|
1021
|
-
return result_object === true;
|
|
1022
|
-
case "object":
|
|
1023
|
-
/* ----------------------------- result is error ---------------------------- */
|
|
1024
|
-
if (result_object instanceof Error) {
|
|
1025
|
-
return false;
|
|
1026
|
-
}
|
|
1027
|
-
/* ----------------- maybe website sends the result as array ---------------- */
|
|
1028
|
-
if (Array.isArray(result_object)) {
|
|
1029
|
-
const allResults = result_object.map((r) => {
|
|
1030
|
-
return Boolean(this.isResultValid(r, depth + 1));
|
|
1031
|
-
});
|
|
1032
|
-
return allResults.find((s) => s === false) == null;
|
|
1033
|
-
}
|
|
1034
|
-
/* ----------------------------- check products/variations ----------------------------- */
|
|
1035
|
-
const varKeys = ["products", "variations"];
|
|
1036
|
-
for (const vk of varKeys) {
|
|
1037
|
-
if (!(vk in result_object) ||
|
|
1038
|
-
array_isEmpty(result_object[vk]))
|
|
1039
|
-
continue;
|
|
1040
|
-
/**
|
|
1041
|
-
* if one product is not valid the result is not valid
|
|
1042
|
-
* but if all products are valid we still need to check the object itself
|
|
1043
|
-
*/
|
|
1044
|
-
if (!this.isResultValid(result_object[vk], depth + 1))
|
|
1045
|
-
return false;
|
|
1046
|
-
}
|
|
1047
|
-
if (result_object.order) {
|
|
1048
|
-
/**
|
|
1049
|
-
* if we get a order-products pair, checking the order is enough
|
|
1050
|
-
*/
|
|
1051
|
-
return this.isResultValid(result_object.order, depth + 1);
|
|
1052
|
-
}
|
|
1053
|
-
/* -------------------------- check if acknowledged ------------------------- */
|
|
1054
|
-
if (object_isTrue(result_object.acknowledged)) {
|
|
1055
|
-
return true;
|
|
1056
|
-
}
|
|
1057
|
-
if (result_object.expected && result_object.result) {
|
|
1058
|
-
return object_equals(result_object.expected, result_object.result);
|
|
1059
|
-
}
|
|
1060
|
-
return !string_isEmpty(this.getID(result_object));
|
|
1061
|
-
}
|
|
1062
|
-
return false;
|
|
1063
|
-
}
|
|
1132
|
+
*/
|
|
1133
|
+
}, {
|
|
1134
|
+
key: "setManager",
|
|
1135
|
+
value: function setManager(mng) {
|
|
1136
|
+
if (mng instanceof _ObjectManager["default"] && typeof mng.setObject === "function") {
|
|
1137
|
+
//make sure the manager knows what object it is managing
|
|
1138
|
+
return mng.setObject(this);
|
|
1139
|
+
} else {
|
|
1140
|
+
console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}, {
|
|
1144
|
+
key: "getIndexOrID",
|
|
1145
|
+
value: function getIndexOrID() {
|
|
1146
|
+
return SimpleObject.getIndexOrID(this);
|
|
1147
|
+
}
|
|
1148
|
+
}, {
|
|
1149
|
+
key: "getIndex",
|
|
1150
|
+
value: function getIndex() {
|
|
1151
|
+
return SimpleObject.getIndex(this);
|
|
1152
|
+
}
|
|
1153
|
+
}, {
|
|
1154
|
+
key: "getID",
|
|
1155
|
+
value: function getID() {
|
|
1156
|
+
return SimpleObject.getID(this);
|
|
1157
|
+
}
|
|
1158
|
+
}, {
|
|
1159
|
+
key: "event_run",
|
|
1160
|
+
value: (
|
|
1161
|
+
/* -------------------------------------------------------------------------- */
|
|
1162
|
+
/* Events */
|
|
1163
|
+
/* -------------------------------------------------------------------------- */
|
|
1164
|
+
function () {
|
|
1165
|
+
var _event_run = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(eventName) {
|
|
1166
|
+
var _this$manager2;
|
|
1167
|
+
var _len2,
|
|
1168
|
+
params,
|
|
1169
|
+
_key4,
|
|
1170
|
+
_args14 = arguments;
|
|
1171
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1172
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1173
|
+
case 0:
|
|
1174
|
+
if (this.manager) {
|
|
1175
|
+
_context14.next = 3;
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(eventName, ") if your object has no manager"));
|
|
1179
|
+
return _context14.abrupt("return");
|
|
1180
|
+
case 3:
|
|
1181
|
+
for (_len2 = _args14.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key4 = 1; _key4 < _len2; _key4++) {
|
|
1182
|
+
params[_key4 - 1] = _args14[_key4];
|
|
1183
|
+
}
|
|
1184
|
+
_context14.next = 6;
|
|
1185
|
+
return (_this$manager2 = this.manager).event_run.apply(_this$manager2, [eventName].concat(params));
|
|
1186
|
+
case 6:
|
|
1187
|
+
return _context14.abrupt("return", _context14.sent);
|
|
1188
|
+
case 7:
|
|
1189
|
+
case "end":
|
|
1190
|
+
return _context14.stop();
|
|
1191
|
+
}
|
|
1192
|
+
}, _callee14, this);
|
|
1193
|
+
}));
|
|
1194
|
+
function event_run(_x24) {
|
|
1195
|
+
return _event_run.apply(this, arguments);
|
|
1196
|
+
}
|
|
1197
|
+
return event_run;
|
|
1198
|
+
}())
|
|
1199
|
+
}, {
|
|
1200
|
+
key: "event_use",
|
|
1201
|
+
value: function event_use(name, runEvent) {
|
|
1202
|
+
var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1203
|
+
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1204
|
+
if (!this.manager) {
|
|
1205
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
return this.manager.event_use(name, runEvent, onlyOn, runOnce);
|
|
1209
|
+
}
|
|
1210
|
+
}, {
|
|
1211
|
+
key: "event_remove",
|
|
1212
|
+
value: function event_remove(name, uname) {
|
|
1213
|
+
if (!this.manager) {
|
|
1214
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
return this.manager.event_remove(name, uname);
|
|
1218
|
+
}
|
|
1219
|
+
}, {
|
|
1220
|
+
key: "event_add",
|
|
1221
|
+
value: function () {
|
|
1222
|
+
var _event_add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(name, uname, runEvent) {
|
|
1223
|
+
var onlyOn,
|
|
1224
|
+
runOnce,
|
|
1225
|
+
_args15 = arguments;
|
|
1226
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1227
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1228
|
+
case 0:
|
|
1229
|
+
onlyOn = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : null;
|
|
1230
|
+
runOnce = _args15.length > 4 && _args15[4] !== undefined ? _args15[4] : false;
|
|
1231
|
+
if (this.manager) {
|
|
1232
|
+
_context15.next = 5;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1236
|
+
return _context15.abrupt("return");
|
|
1237
|
+
case 5:
|
|
1238
|
+
_context15.next = 7;
|
|
1239
|
+
return this.manager.event_add(name, uname, runEvent, onlyOn, runOnce);
|
|
1240
|
+
case 7:
|
|
1241
|
+
case "end":
|
|
1242
|
+
return _context15.stop();
|
|
1243
|
+
}
|
|
1244
|
+
}, _callee15, this);
|
|
1245
|
+
}));
|
|
1246
|
+
function event_add(_x25, _x26, _x27) {
|
|
1247
|
+
return _event_add.apply(this, arguments);
|
|
1248
|
+
}
|
|
1249
|
+
return event_add;
|
|
1250
|
+
}()
|
|
1251
|
+
/* -------------------------------------------------------------------------- */
|
|
1252
|
+
/* Original */
|
|
1253
|
+
/* -------------------------------------------------------------------------- */
|
|
1254
|
+
}, {
|
|
1255
|
+
key: "getOriginal",
|
|
1256
|
+
value: function getOriginal() {
|
|
1257
|
+
return this.__originalobject || undefined;
|
|
1258
|
+
}
|
|
1259
|
+
}, {
|
|
1260
|
+
key: "setOriginal",
|
|
1261
|
+
value: function setOriginal() {
|
|
1262
|
+
var toObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1263
|
+
if (toObj === null) {
|
|
1264
|
+
delete this.__originalobject;
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
if (!this.canModify) {
|
|
1268
|
+
console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
|
|
1269
|
+
delete this.__originalobject;
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
if (toObj === 0) {
|
|
1273
|
+
toObj = this;
|
|
1274
|
+
}
|
|
1275
|
+
var cloneObject = (0, _object.object_clone)(toObj);
|
|
1276
|
+
SimpleObject.setReadonly(cloneObject, true);
|
|
1277
|
+
this.__originalobject = (0, _object.object_removeKeys)(cloneObject, ["__"]);
|
|
1278
|
+
return this;
|
|
1279
|
+
}
|
|
1280
|
+
}, {
|
|
1281
|
+
key: "addError",
|
|
1282
|
+
value: /* -------------------------------------------------------------------------- */
|
|
1283
|
+
/* Errors */
|
|
1284
|
+
/* -------------------------------------------------------------------------- */
|
|
1285
|
+
function addError(title, message) {
|
|
1286
|
+
var sendToRegister = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "auto";
|
|
1287
|
+
return SimpleObject.addError(this, title, message, sendToRegister);
|
|
1288
|
+
}
|
|
1289
|
+
}, {
|
|
1290
|
+
key: "clearErrors",
|
|
1291
|
+
value: function clearErrors() {
|
|
1292
|
+
return SimpleObject.clearErrors(this);
|
|
1293
|
+
}
|
|
1294
|
+
}, {
|
|
1295
|
+
key: "getErrors",
|
|
1296
|
+
value: function getErrors() {
|
|
1297
|
+
return SimpleObject.getErrors(this);
|
|
1298
|
+
}
|
|
1299
|
+
}, {
|
|
1300
|
+
key: "setSaveResult",
|
|
1301
|
+
value:
|
|
1064
1302
|
/**
|
|
1065
1303
|
* set the response of last save from site
|
|
1066
1304
|
* and its type
|
|
1067
1305
|
* @param toObj
|
|
1068
|
-
*/
|
|
1069
|
-
setSaveResult(toObj
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
SimpleObject.addError(this, "save result is not valid", errorString, true);
|
|
1087
|
-
}
|
|
1088
|
-
this.__saveResultType = type;
|
|
1089
|
-
return type;
|
|
1090
|
-
}
|
|
1306
|
+
*/
|
|
1307
|
+
function setSaveResult(toObj) {
|
|
1308
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "auto";
|
|
1309
|
+
var registerErrors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1310
|
+
_assertClassBrand(_SimpleObject_brand, this, _setSaveResultObject).call(this, toObj);
|
|
1311
|
+
//check if the given object is a valid save result
|
|
1312
|
+
if (type === "error") this.__saveResultIsSuccess = false;else this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
|
|
1313
|
+
if (type === "auto") {
|
|
1314
|
+
type = this.__saveResultIsSuccess ? "normal" : "error";
|
|
1315
|
+
}
|
|
1316
|
+
if (registerErrors && !this.__saveResultIsSuccess) {
|
|
1317
|
+
var sr = this.__saveResultObject;
|
|
1318
|
+
var errorString = sr == null ? "" : sr instanceof Error ? sr.message : JSON.stringify(sr);
|
|
1319
|
+
SimpleObject.addError(this, "save result is not valid", errorString, true);
|
|
1320
|
+
}
|
|
1321
|
+
this.__saveResultType = type;
|
|
1322
|
+
return type;
|
|
1323
|
+
}
|
|
1091
1324
|
/**
|
|
1092
1325
|
* set the response of last save from site
|
|
1093
1326
|
* @param toObj
|
|
1094
|
-
*/
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
getIsLastSaveCreate() {
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
/* -------------------------------------------------------------------------- */
|
|
1114
|
-
/* statics */
|
|
1115
|
-
/* -------------------------------------------------------------------------- */
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1327
|
+
*/
|
|
1328
|
+
}, {
|
|
1329
|
+
key: "getSaveResult",
|
|
1330
|
+
value: function getSaveResult() {
|
|
1331
|
+
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1332
|
+
if (this.isSaved) return this.__saveResultObject;
|
|
1333
|
+
return false;
|
|
1334
|
+
}
|
|
1335
|
+
}, {
|
|
1336
|
+
key: "getSaveResultType",
|
|
1337
|
+
value: function getSaveResultType() {
|
|
1338
|
+
return this.__saveResultType || "nothing";
|
|
1339
|
+
}
|
|
1340
|
+
/** did we create on the last save */
|
|
1341
|
+
}, {
|
|
1342
|
+
key: "getIsLastSaveCreate",
|
|
1343
|
+
value: function getIsLastSaveCreate() {
|
|
1344
|
+
return this.isSaved && this.getSaveResult().insertedId;
|
|
1345
|
+
}
|
|
1346
|
+
/* -------------------------------------------------------------------------- */
|
|
1347
|
+
/* statics */
|
|
1348
|
+
/* -------------------------------------------------------------------------- */
|
|
1349
|
+
}], [{
|
|
1350
|
+
key: "get",
|
|
1351
|
+
value: function get(obj, key) {
|
|
1352
|
+
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1353
|
+
if (obj == null) return undefined;
|
|
1354
|
+
if (obj instanceof SimpleObject && typeof obj.get === "function") return obj.get(key, original);
|
|
1355
|
+
/* ------------------------------- manual get ------------------------------- */
|
|
1356
|
+
if (!original && obj.__use_delta != false && _typeof(obj.__delta) === "object" && key in obj.__delta) {
|
|
1357
|
+
//@ts-ignore
|
|
1358
|
+
return obj.__delta[key];
|
|
1359
|
+
}
|
|
1360
|
+
return obj[key];
|
|
1361
|
+
}
|
|
1362
|
+
}, {
|
|
1363
|
+
key: "loadValues",
|
|
1364
|
+
value: function loadValues(obj, initObject) {
|
|
1365
|
+
var fullUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1366
|
+
if (typeof initObject === "number" || typeof initObject === "string") {
|
|
1367
|
+
initObject = {
|
|
1368
|
+
_id: initObject
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
SimpleObject.factoryClear(obj);
|
|
1372
|
+
if (initObject == null) {
|
|
1373
|
+
for (var key in obj) {
|
|
1374
|
+
if (typeof obj[key] === "function") continue;
|
|
1375
|
+
if (key.startsWith("__")) continue;
|
|
1376
|
+
delete obj[key];
|
|
1377
|
+
}
|
|
1378
|
+
} else if (_typeof(initObject) == "object") {
|
|
1379
|
+
for (var _key5 in initObject) {
|
|
1380
|
+
if (_key5.startsWith("__")) continue;
|
|
1381
|
+
if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key5)) {
|
|
1382
|
+
obj[_key5] = initObject[_key5];
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
/* --------------------- special case 1, temp properties -------------------- */
|
|
1386
|
+
if ("__temp" in initObject) {
|
|
1387
|
+
obj["__temp"] = initObject["__temp"];
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return true;
|
|
1391
|
+
}
|
|
1392
|
+
}, {
|
|
1393
|
+
key: "getChangeableKeys",
|
|
1394
|
+
value: function getChangeableKeys(object, options) {
|
|
1395
|
+
var _key_list;
|
|
1396
|
+
if (!object) return [];
|
|
1397
|
+
var key_list = [];
|
|
1398
|
+
(_key_list = key_list).push.apply(_key_list, _toConsumableArray(object.constructor["__changeables"]));
|
|
1399
|
+
var __unchangeables = object.constructor["__unchangeables"];
|
|
1400
|
+
if (!(0, _object.array_isEmpty)(__unchangeables)) {
|
|
1401
|
+
key_list = key_list.filter(function (s) {
|
|
1402
|
+
return !__unchangeables.includes(s);
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
/* -------------------------------------------------------------------------- */
|
|
1406
|
+
if (options.extraProperties) {
|
|
1407
|
+
var _key_list2;
|
|
1408
|
+
(_key_list2 = key_list).push.apply(_key_list2, _toConsumableArray(object.constructor["__extraProperties"]));
|
|
1409
|
+
}
|
|
1410
|
+
if (options.tempProperties) {
|
|
1411
|
+
var _key_list3;
|
|
1412
|
+
key_list.push("__temp");
|
|
1413
|
+
(_key_list3 = key_list).push.apply(_key_list3, _toConsumableArray(object.constructor["__tempProperties"]));
|
|
1414
|
+
}
|
|
1415
|
+
if (options.bypassProtected !== true && !options.allProperties) {
|
|
1416
|
+
var __protectedProperties = object.constructor["__protectedProperties"];
|
|
1417
|
+
//protected keys can only be changed by the creator of this object
|
|
1418
|
+
//make sure you set the is_current_user function correctly
|
|
1419
|
+
if (!object.isNew && !(0, _object.array_isEmpty)(__protectedProperties) && !Boolean(_global.gfunc.run_action_sync("is_current_user", object.get("_creator")))) {
|
|
1420
|
+
key_list = key_list.filter(function (s) {
|
|
1421
|
+
return !__protectedProperties.includes(s);
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return key_list;
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* check if a key can be changed on an object
|
|
1429
|
+
* @param object the object we are checking
|
|
1430
|
+
* @param key key of the object
|
|
1431
|
+
* @param useExtraProps should we check extra props?
|
|
1432
|
+
* @returns
|
|
1433
|
+
*/
|
|
1434
|
+
}, {
|
|
1435
|
+
key: "canChangeKey",
|
|
1436
|
+
value: function canChangeKey(object, key, options) {
|
|
1437
|
+
if (!object || !key) return false;
|
|
1438
|
+
var keys = this.getChangeableKeys(object, options);
|
|
1439
|
+
return keys.includes(key);
|
|
1440
|
+
}
|
|
1441
|
+
}, {
|
|
1442
|
+
key: "hasIllegalChanges",
|
|
1443
|
+
value: function hasIllegalChanges(referenceObject, changesObject, updaterUser) {
|
|
1444
|
+
var __protectedProperties = (0, _object.object_getStatic)(referenceObject, "__protectedProperties");
|
|
1445
|
+
if ((0, _object.object_isEmpty)(__protectedProperties)) return false;
|
|
1446
|
+
var referenceUser = (0, _object.object_isClass)(referenceObject) ? (0, _object.object_get)(changesObject, "__user", "_creator") : (0, _object.object_get)(referenceObject, "__user", "_creator");
|
|
1447
|
+
if (Boolean(SimpleObject.getID(referenceUser) == SimpleObject.getID(updaterUser))) {
|
|
1448
|
+
return false;
|
|
1449
|
+
}
|
|
1450
|
+
for (var key in changesObject) {
|
|
1451
|
+
if (__protectedProperties.includes(key)) {
|
|
1452
|
+
return true;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
}, {
|
|
1458
|
+
key: "setReadonly",
|
|
1459
|
+
value: function setReadonly(objs) {
|
|
1460
|
+
var readonlyval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1461
|
+
var clearChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1462
|
+
var checkObjs = [];
|
|
1463
|
+
if (!objs) objs = [];
|
|
1464
|
+
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1465
|
+
for (var index = 0; index < checkObjs.length; index++) {
|
|
1466
|
+
var obj = checkObjs[index];
|
|
1467
|
+
obj.__is_readonly = Boolean(readonlyval);
|
|
1468
|
+
if (obj instanceof SimpleObject) {
|
|
1469
|
+
if (obj.canModify) {
|
|
1470
|
+
if (!obj.getOriginal()) obj.setOriginal();
|
|
1471
|
+
} else {
|
|
1472
|
+
if (clearChanges) obj.clear_changes();
|
|
1473
|
+
//we dont need the original object in readonly mode
|
|
1474
|
+
obj.setOriginal(null);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}, {
|
|
1480
|
+
key: "setThrowErrors",
|
|
1481
|
+
value: function setThrowErrors(objs) {
|
|
1482
|
+
var throwErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1483
|
+
var checkObjs = [];
|
|
1484
|
+
if (!objs) objs = [];
|
|
1485
|
+
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1486
|
+
for (var index = 0; index < checkObjs.length; index++) {
|
|
1487
|
+
var element = checkObjs[index];
|
|
1488
|
+
element.__throw_errors = throwErr;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}, {
|
|
1492
|
+
key: "isDeleted",
|
|
1493
|
+
value: function isDeleted(obj) {
|
|
1494
|
+
if (obj instanceof SimpleObject) return obj.isDeleted === true;
|
|
1495
|
+
return false;
|
|
1496
|
+
}
|
|
1497
|
+
}, {
|
|
1498
|
+
key: "getIndexOrID",
|
|
1499
|
+
value: function getIndexOrID(o) {
|
|
1500
|
+
var res = SimpleObject.getIndex(o);
|
|
1501
|
+
if (!res || res == -1) res = SimpleObject.getID(o);
|
|
1502
|
+
return res || -1;
|
|
1503
|
+
}
|
|
1504
|
+
}, {
|
|
1505
|
+
key: "getIndex",
|
|
1506
|
+
value: function getIndex(o) {
|
|
1507
|
+
if (o == null || o == undefined) return -1;
|
|
1508
|
+
switch (_typeof(o)) {
|
|
1509
|
+
case "object":
|
|
1510
|
+
return o._index_value || -1;
|
|
1511
|
+
case "number":
|
|
1512
|
+
case "string":
|
|
1513
|
+
return Number(o);
|
|
1514
|
+
}
|
|
1515
|
+
return -1;
|
|
1516
|
+
}
|
|
1517
|
+
}, {
|
|
1518
|
+
key: "getID",
|
|
1519
|
+
value: function getID(obj) {
|
|
1520
|
+
if (obj == null || obj == undefined) return "";
|
|
1521
|
+
switch (_typeof(obj)) {
|
|
1522
|
+
case "object":
|
|
1523
|
+
if (String(obj._bsontype).toLowerCase() == "objectid") {
|
|
1524
|
+
return String(obj);
|
|
1525
|
+
}
|
|
1526
|
+
return String(obj._id || obj.insertedId || obj.ID || obj.id || obj.__data_id || "");
|
|
1527
|
+
case "string":
|
|
1528
|
+
case "number":
|
|
1529
|
+
return String(obj);
|
|
1530
|
+
}
|
|
1531
|
+
return "";
|
|
1532
|
+
}
|
|
1533
|
+
}, {
|
|
1534
|
+
key: "setOriginal",
|
|
1535
|
+
value: function setOriginal(obj) {
|
|
1536
|
+
var toObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1537
|
+
if (!(obj instanceof SimpleObject)) return undefined;
|
|
1538
|
+
return obj.setOriginal(toObj);
|
|
1539
|
+
}
|
|
1540
|
+
}, {
|
|
1541
|
+
key: "getOriginal",
|
|
1542
|
+
value: function getOriginal(obj) {
|
|
1543
|
+
if (obj instanceof SimpleObject) return obj.getOriginal();
|
|
1544
|
+
return obj === null || obj === void 0 ? void 0 : obj.__originalobject;
|
|
1545
|
+
}
|
|
1546
|
+
}, {
|
|
1547
|
+
key: "addError",
|
|
1548
|
+
value: function addError(o, title, message) {
|
|
1549
|
+
var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
|
|
1550
|
+
var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
|
|
1551
|
+
if (o) {
|
|
1552
|
+
if (!Array.isArray(o.__errors)) o.__errors = [];
|
|
1553
|
+
o.__errors.push(errStr);
|
|
1554
|
+
if (o.__showErrors === false) return;
|
|
1555
|
+
} else if (sendToRegister === "auto") sendToRegister = true;
|
|
1556
|
+
if (sendToRegister === true) {
|
|
1557
|
+
console.error("[REGISTER-ERROR]", errStr);
|
|
1558
|
+
_global.gfunc.run_action("add_error", {
|
|
1559
|
+
title: title,
|
|
1560
|
+
message: message,
|
|
1561
|
+
type: "error"
|
|
1562
|
+
});
|
|
1563
|
+
} else {
|
|
1564
|
+
console.error("[ERROR]", errStr);
|
|
1565
|
+
}
|
|
1566
|
+
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1567
|
+
}
|
|
1568
|
+
}, {
|
|
1569
|
+
key: "getErrors",
|
|
1570
|
+
value: function getErrors(o) {
|
|
1571
|
+
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1572
|
+
}
|
|
1573
|
+
}, {
|
|
1574
|
+
key: "clearErrors",
|
|
1575
|
+
value: function clearErrors(o) {
|
|
1576
|
+
if (o) o.__errors = [];
|
|
1577
|
+
return true;
|
|
1578
|
+
}
|
|
1579
|
+
/* -------------------------------------------------------------------------- */
|
|
1580
|
+
/* Save Results */
|
|
1581
|
+
/* -------------------------------------------------------------------------- */
|
|
1582
|
+
/**
|
|
1583
|
+
* Checks if the given object is a valid and truthy save result
|
|
1584
|
+
* @param result_object
|
|
1585
|
+
* @returns
|
|
1586
|
+
*/
|
|
1587
|
+
}, {
|
|
1588
|
+
key: "isResultValid",
|
|
1589
|
+
value: function isResultValid(result_object) {
|
|
1590
|
+
var _this3 = this;
|
|
1591
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1592
|
+
if ((0, _object.object_isEmpty)(result_object)) return false;
|
|
1593
|
+
switch (_typeof(result_object)) {
|
|
1594
|
+
case "string":
|
|
1595
|
+
try {
|
|
1596
|
+
result_object = JSON.parse(result_object);
|
|
1597
|
+
return this.isResultValid(result_object);
|
|
1598
|
+
} catch (_unused) {
|
|
1599
|
+
return false;
|
|
1600
|
+
}
|
|
1601
|
+
case "number":
|
|
1602
|
+
return result_object > 0;
|
|
1603
|
+
case "boolean":
|
|
1604
|
+
return result_object === true;
|
|
1605
|
+
case "object":
|
|
1606
|
+
/* ----------------------------- result is error ---------------------------- */
|
|
1607
|
+
if (result_object instanceof Error) {
|
|
1608
|
+
return false;
|
|
1609
|
+
}
|
|
1610
|
+
/* ----------------- maybe website sends the result as array ---------------- */
|
|
1611
|
+
if (Array.isArray(result_object)) {
|
|
1612
|
+
var allResults = result_object.map(function (r) {
|
|
1613
|
+
return Boolean(_this3.isResultValid(r, depth + 1));
|
|
1614
|
+
});
|
|
1615
|
+
return allResults.find(function (s) {
|
|
1616
|
+
return s === false;
|
|
1617
|
+
}) == null;
|
|
1618
|
+
}
|
|
1619
|
+
/* ----------------------------- check products/variations ----------------------------- */
|
|
1620
|
+
var varKeys = ["products", "variations"];
|
|
1621
|
+
for (var _i = 0, _varKeys = varKeys; _i < _varKeys.length; _i++) {
|
|
1622
|
+
var vk = _varKeys[_i];
|
|
1623
|
+
if (!(vk in result_object) || (0, _object.array_isEmpty)(result_object[vk])) continue;
|
|
1624
|
+
/**
|
|
1625
|
+
* if one product is not valid the result is not valid
|
|
1626
|
+
* but if all products are valid we still need to check the object itself
|
|
1627
|
+
*/
|
|
1628
|
+
if (!this.isResultValid(result_object[vk], depth + 1)) return false;
|
|
1629
|
+
}
|
|
1630
|
+
if (result_object.order) {
|
|
1631
|
+
/**
|
|
1632
|
+
* if we get a order-products pair, checking the order is enough
|
|
1633
|
+
*/
|
|
1634
|
+
return this.isResultValid(result_object.order, depth + 1);
|
|
1635
|
+
}
|
|
1636
|
+
/* -------------------------- check if acknowledged ------------------------- */
|
|
1637
|
+
if ((0, _object.object_isTrue)(result_object.acknowledged)) {
|
|
1638
|
+
return true;
|
|
1639
|
+
}
|
|
1640
|
+
if (result_object.expected && result_object.result) {
|
|
1641
|
+
return (0, _object.object_equals)(result_object.expected, result_object.result);
|
|
1642
|
+
}
|
|
1643
|
+
return !(0, _string.string_isEmpty)(this.getID(result_object));
|
|
1644
|
+
}
|
|
1645
|
+
return false;
|
|
1646
|
+
}
|
|
1647
|
+
}, {
|
|
1648
|
+
key: "setTemp",
|
|
1649
|
+
value: (function () {
|
|
1650
|
+
var _setTemp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16(obj, key, value) {
|
|
1651
|
+
var sendChanges,
|
|
1652
|
+
_args16 = arguments;
|
|
1653
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1654
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1655
|
+
case 0:
|
|
1656
|
+
sendChanges = _args16.length > 3 && _args16[3] !== undefined ? _args16[3] : false;
|
|
1657
|
+
if (!(_typeof(obj) !== "object" || !obj || Array.isArray(obj))) {
|
|
1658
|
+
_context16.next = 3;
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
return _context16.abrupt("return");
|
|
1662
|
+
case 3:
|
|
1663
|
+
if (!(obj instanceof SimpleObject)) {
|
|
1664
|
+
_context16.next = 7;
|
|
1665
|
+
break;
|
|
1666
|
+
}
|
|
1667
|
+
_context16.next = 6;
|
|
1668
|
+
return obj.setTemp(key, value, sendChanges);
|
|
1669
|
+
case 6:
|
|
1670
|
+
return _context16.abrupt("return", _context16.sent);
|
|
1671
|
+
case 7:
|
|
1672
|
+
//
|
|
1673
|
+
if (obj.__temp == null) obj.__temp = {};
|
|
1674
|
+
(0, _object.object_set)(obj.__temp, key, value);
|
|
1675
|
+
case 9:
|
|
1676
|
+
case "end":
|
|
1677
|
+
return _context16.stop();
|
|
1678
|
+
}
|
|
1679
|
+
}, _callee16);
|
|
1680
|
+
}));
|
|
1681
|
+
function setTemp(_x28, _x29, _x30) {
|
|
1682
|
+
return _setTemp.apply(this, arguments);
|
|
1683
|
+
}
|
|
1684
|
+
return setTemp;
|
|
1685
|
+
}())
|
|
1686
|
+
}, {
|
|
1687
|
+
key: "factoryClear",
|
|
1688
|
+
value: function factoryClear(obj) {
|
|
1689
|
+
obj.clear_changes();
|
|
1690
|
+
SimpleObject.clearErrors(obj);
|
|
1691
|
+
}
|
|
1692
|
+
}, {
|
|
1693
|
+
key: "delete_cache",
|
|
1694
|
+
value: function () {
|
|
1695
|
+
var _delete_cache = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17(context) {
|
|
1696
|
+
var cacheKey;
|
|
1697
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1698
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1699
|
+
case 0:
|
|
1700
|
+
if (this.__db_name) {
|
|
1701
|
+
_context17.next = 2;
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
return _context17.abrupt("return");
|
|
1705
|
+
case 2:
|
|
1706
|
+
if (context) {
|
|
1707
|
+
_context17.next = 7;
|
|
1708
|
+
break;
|
|
1709
|
+
}
|
|
1710
|
+
_context17.next = 5;
|
|
1711
|
+
return _global.gcache.delete_session_cache(this.__db_name);
|
|
1712
|
+
case 5:
|
|
1713
|
+
_context17.next = 10;
|
|
1714
|
+
break;
|
|
1715
|
+
case 7:
|
|
1716
|
+
cacheKey = "".concat(this.__db_name, "-").concat(context);
|
|
1717
|
+
_context17.next = 10;
|
|
1718
|
+
return _global.gcache.delete_session_cache(cacheKey);
|
|
1719
|
+
case 10:
|
|
1720
|
+
case "end":
|
|
1721
|
+
return _context17.stop();
|
|
1722
|
+
}
|
|
1723
|
+
}, _callee17, this);
|
|
1724
|
+
}));
|
|
1725
|
+
function delete_cache(_x31) {
|
|
1726
|
+
return _delete_cache.apply(this, arguments);
|
|
1727
|
+
}
|
|
1728
|
+
return delete_cache;
|
|
1729
|
+
}()
|
|
1730
|
+
}, {
|
|
1731
|
+
key: "get_canModify",
|
|
1732
|
+
value: function get_canModify(o) {
|
|
1733
|
+
if (o instanceof SimpleObject) return o.canModify;
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
/* -------------------------------------------------------------------------- */
|
|
1737
|
+
}, {
|
|
1738
|
+
key: "equals",
|
|
1739
|
+
value: function equals(a, b) {
|
|
1740
|
+
console.warn("Dont use the default equals method !");
|
|
1741
|
+
if (a == undefined || b == undefined) return false;
|
|
1742
|
+
return a === b;
|
|
1743
|
+
}
|
|
1744
|
+
}]);
|
|
1745
|
+
}(_MapableObject2.MapableObject);
|
|
1746
|
+
function _getSubProperty(key, subkey) {
|
|
1747
|
+
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1748
|
+
var subobj = this.get(key, original);
|
|
1749
|
+
if (subobj == null || _typeof(subobj) !== "object") return undefined;
|
|
1750
|
+
return subobj[subkey];
|
|
1751
|
+
}
|
|
1752
|
+
function _setSubProperty(key, subkey, value) {
|
|
1753
|
+
var subobj = this.get(key);
|
|
1754
|
+
//@ts-ignore
|
|
1755
|
+
if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
|
|
1756
|
+
subobj[subkey] = value;
|
|
1757
|
+
_assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, subobj);
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* update a property on this object by updating the `__delta`
|
|
1761
|
+
* or update the object property directly depending on `__use_delta` setting
|
|
1762
|
+
*
|
|
1763
|
+
* @param key
|
|
1764
|
+
* @param value
|
|
1765
|
+
*/
|
|
1766
|
+
function _setProperty(key, value) {
|
|
1767
|
+
var checkIsChanged = false;
|
|
1768
|
+
if (this.__use_delta) {
|
|
1769
|
+
if (this[key] === value) {
|
|
1770
|
+
/**
|
|
1771
|
+
* we set something back to its original value
|
|
1772
|
+
* no need to save it as delta
|
|
1773
|
+
*/
|
|
1774
|
+
delete this.__delta[key];
|
|
1775
|
+
////checkIsChanged = true; //check if we should set __has_delta to false
|
|
1776
|
+
} else {
|
|
1777
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1778
|
+
}
|
|
1779
|
+
} else {
|
|
1780
|
+
this[key] = value; //on noDelta mode update the object itself
|
|
1781
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1782
|
+
}
|
|
1783
|
+
return true;
|
|
1784
|
+
}
|
|
1785
|
+
function _setSaveResultObject(toObj) {
|
|
1786
|
+
if (toObj == null) toObj = null; //null or undefined
|
|
1787
|
+
this.__saveResultObject = toObj;
|
|
1788
|
+
return true;
|
|
1789
|
+
}
|
|
1790
|
+
_defineProperty(SimpleObject, "__db_name", "");
|
|
1791
|
+
_defineProperty(SimpleObject, "__object_name", "");
|
|
1792
|
+
//these properties should not be changed and are usually set by server
|
|
1793
|
+
_defineProperty(SimpleObject, "__unchangeables", []);
|
|
1794
|
+
//these properties can be directly changed and are included in deltaObject
|
|
1795
|
+
_defineProperty(SimpleObject, "__changeables", []);
|
|
1796
|
+
//these properties usually are not directly changed and sometimes are included in deltaObject
|
|
1797
|
+
_defineProperty(SimpleObject, "__extraProperties", []);
|
|
1798
|
+
//these properties are never sent to database but may be sent to client
|
|
1799
|
+
_defineProperty(SimpleObject, "__tempProperties", []);
|
|
1800
|
+
//these properties can only be changed by the _creator
|
|
1801
|
+
_defineProperty(SimpleObject, "__protectedProperties", []);
|
|
1802
|
+
//these properties will be evaluated when needed
|
|
1803
|
+
_defineProperty(SimpleObject, "__functionProperties", []);
|
|
1804
|
+
//apply these string formats
|
|
1805
|
+
_defineProperty(SimpleObject, "__formatList", void 0);
|
|
1806
|
+
//types for children can be used when importing children
|
|
1807
|
+
_defineProperty(SimpleObject, "__childTypes", void 0);
|
|
1808
|
+
//these fields are used when importing
|
|
1809
|
+
_defineProperty(SimpleObject, "__importColumns", void 0);
|
|
1810
|
+
//these fields can be used when importing and checking if an item exists
|
|
1811
|
+
_defineProperty(SimpleObject, "__checkProperties", []);
|
|
1812
|
+
_defineProperty(SimpleObject, "__use_delta", true);
|
|
1813
|
+
var _default = exports["default"] = SimpleObject;
|