@azrico/webobject 1.4.129 → 1.4.131

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