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