@azrico/webobject 1.5.61 → 1.5.63

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