@azrico/webobject 1.3.23 → 1.3.24

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,731 +1,1013 @@
1
- import { gcache, gfunc } from "@azrico/global";
2
- import { object_clone, object_equals, object_isEmpty, object_isTrue, object_removeKeys, } from "@azrico/object";
3
- import { MapableObject } from "./MapableObject";
4
- import ObjectManager from "./ObjectManager";
5
- import WebObjectManager from "../WebObjects/WebObjectManager";
6
- import { combine_if_not_blank } from "@azrico/string";
7
- export class SimpleObject extends MapableObject {
8
- static __cache_name;
9
- //these properties should not be changed and are usually set by server
10
- static __unchangeables;
11
- //these properties can be directly changed and are included in deltaObject
12
- static __changeables;
13
- //these properties usually are not directly changed and sometimes are included in deltaObject
14
- static __extraProperties;
15
- static __use_delta = true;
16
- _static() {
17
- return this.constructor;
18
- }
19
- //an exact copy of this object is stored here
20
- __originalobject;
21
- //changes are saved here
22
- __delta = {};
23
- __temp = undefined;
24
- __changed = false;
25
- //the last thing that was changed on this object
26
- __lastChanged;
27
- //is the object read only
28
- __is_readonly;
29
- //should we throw errors when encountering an error?
30
- //is TRUE by default
31
- __throw_errors;
32
- //is this object marked as deleted?
33
- _deleted;
34
- _deletedBy;
35
- //errors
36
- __errors;
37
- __showErrors;
38
- //save results
39
- __saveResultObject;
40
- __saveResultIsSuccess = true;
41
- __saveResultType;
42
- //sequence key (usually managed by the database)
43
- _index_key = "";
44
- //sequence value , used to index the object with increasing numbers
45
- _index_value = -1;
46
- constructor(is_readonly = false) {
47
- super();
48
- this.__is_readonly = is_readonly;
49
- this.clear_changes();
50
- }
51
- #setSubProperty(key, subkey, value) {
52
- let subobj = this.#getProperty(key);
53
- //@ts-ignore
54
- if (subobj == null || typeof subobj !== "object")
55
- subobj = {};
56
- subobj[subkey] = value;
57
- this.#setProperty(key, subobj);
58
- }
59
- #getSubProperty(key, subkey, original = false) {
60
- let subobj = this.#getProperty(key, original);
61
- if (subobj == null || typeof subobj !== "object")
62
- return undefined;
63
- return subobj[subkey];
64
- }
65
- #setProperty(key, value) {
66
- if (this[key] === value) {
67
- /**
68
- * We set something back to its original value so no need to save it as Delta
69
- */
70
- delete this.__delta[key];
71
- return false;
72
- }
73
- else {
74
- this.__delta[key] = value; //always update delta to keep track of changes
75
- if (!this.__use_delta)
76
- this[key] = value; //on noDelta mode, also update the obj
77
- return true;
78
- }
79
- }
80
- #setDefaultProperty(key, value) {
81
- //@ts-ignore
82
- if (this[key] == undefined || this[key] === "" || this[key] === 0) {
83
- this[key] = value;
84
- return true;
85
- }
86
- return false;
87
- }
88
- #getProperty(key, original = false) {
89
- //check if we should use delta version or normal version for this property
90
- if (original || !this.__use_delta || !(key in this.__delta))
91
- return this[key];
92
- //@ts-ignore
93
- return this.__delta[key];
94
- }
95
- #getTempProperty(key) {
96
- if (this.__temp == null)
97
- return undefined;
98
- return this.__temp[key];
99
- }
100
- #setTempProperty(key, value) {
101
- if (this.__temp == null)
102
- this.__temp = {};
103
- this.__temp[key] = value;
104
- }
105
- /* -------------------------------------------------------------------------- */
106
- /* Load */
107
- /* -------------------------------------------------------------------------- */
108
- loadValues(initObject, fullUpdate = false) {
109
- return SimpleObject.loadValues(this, initObject, fullUpdate);
110
- }
111
- static loadValues(obj, initObject, fullUpdate = false) {
112
- SimpleObject.factoryClear(obj);
113
- if (initObject == null) {
114
- for (const key in obj) {
115
- if (typeof obj[key] === "function")
116
- continue;
117
- if (key.startsWith("__"))
118
- continue;
119
- delete obj[key];
120
- }
121
- }
122
- else if (typeof initObject == "object") {
123
- for (const key in initObject) {
124
- if (key.startsWith("__"))
125
- continue;
126
- if (fullUpdate ||
127
- Object.prototype.hasOwnProperty.call(obj, key)) {
128
- obj[key] = initObject[key];
129
- }
130
- }
131
- }
132
- return true;
133
- }
134
- /* -------------------------------------------------------------------------- */
135
- static getValue(o, key, original = false) {
136
- if (o == null)
137
- return undefined;
138
- if (o instanceof SimpleObject && typeof o.getValue === "function")
139
- return o.getValue(key, original);
140
- if (!original &&
141
- o.__use_delta != false &&
142
- typeof o.__delta === "object" &&
143
- key in o.__delta) {
144
- //@ts-ignore
145
- return o.__delta[key];
146
- }
147
- return o[key];
148
- }
149
- getValue = this.#getProperty;
150
- get = this.#getProperty;
151
- getTemp = this.#getTempProperty;
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.SimpleObject = void 0;
7
+ var _global = require("@azrico/global");
8
+ var _object = require("@azrico/object");
9
+ var _MapableObject2 = require("./MapableObject");
10
+ var _ObjectManager = _interopRequireDefault(require("./ObjectManager"));
11
+ var _WebObjectManager = _interopRequireDefault(require("../WebObjects/WebObjectManager"));
12
+ var _string = require("@azrico/string");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
18
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
21
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
22
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
23
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
24
+ 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); } }
25
+ 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); }); }; }
26
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
+ 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); } }
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
+ 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); }
33
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
34
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
35
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
36
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
37
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
38
+ 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; }
39
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
40
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
41
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
42
+ var _setSubProperty = /*#__PURE__*/new WeakSet();
43
+ var _getSubProperty = /*#__PURE__*/new WeakSet();
44
+ var _setProperty = /*#__PURE__*/new WeakSet();
45
+ var _setDefaultProperty = /*#__PURE__*/new WeakSet();
46
+ var _getProperty = /*#__PURE__*/new WeakSet();
47
+ var _getTempProperty = /*#__PURE__*/new WeakSet();
48
+ var _setTempProperty = /*#__PURE__*/new WeakSet();
49
+ var _setSaveResultObject = /*#__PURE__*/new WeakSet();
50
+ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
51
+ _inherits(SimpleObject, _MapableObject);
52
+ var _super = _createSuper(SimpleObject);
53
+ function SimpleObject() {
54
+ var _this;
55
+ var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
56
+ _classCallCheck(this, SimpleObject);
57
+ _this = _super.call(this);
152
58
  /**
153
- * set value
154
- * @param key
155
- * @param value
156
- * @return true if changed , false otherwise
157
- */
158
- async setValue(key, value, sendChanges = "auto") {
159
- if (!this.canModify) {
160
- if (this.__throw_errors !== false)
161
- throw Error("Cant use setValue when on readonly mode");
162
- else
163
- return false;
164
- }
165
- let isValueChanged = false;
166
- try {
167
- const oldval = this.getValue(key);
168
- if (!object_equals(oldval, value, { ignoredStartingWords: "_" })) {
169
- this.#setProperty(key, value);
170
- isValueChanged = true;
171
- }
172
- else
173
- isValueChanged = false;
174
- //console.log("SV:", isValueChanged, oldval, key, value);
175
- }
176
- finally {
177
- if (sendChanges === true ||
178
- (sendChanges === "auto" && isValueChanged)) {
179
- await this.notifyChanged("", String(key), value);
180
- }
181
- }
182
- return isValueChanged;
183
- }
184
- set = this.setValue;
185
- setTemp = this.#setTempProperty;
59
+ * set the response of last save from site
60
+ * @param toObj
61
+ */
62
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSaveResultObject);
63
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setTempProperty);
64
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getTempProperty);
65
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getProperty);
66
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setDefaultProperty);
67
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setProperty);
68
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getSubProperty);
69
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSubProperty);
70
+ //an exact copy of this object is stored here
71
+ _defineProperty(_assertThisInitialized(_this), "__originalobject", void 0);
72
+ //changes are saved here
73
+ _defineProperty(_assertThisInitialized(_this), "__delta", {});
74
+ _defineProperty(_assertThisInitialized(_this), "__temp", undefined);
75
+ _defineProperty(_assertThisInitialized(_this), "__changed", false);
76
+ //the last thing that was changed on this object
77
+ _defineProperty(_assertThisInitialized(_this), "__lastChanged", void 0);
78
+ //is the object read only
79
+ _defineProperty(_assertThisInitialized(_this), "__is_readonly", void 0);
80
+ //should we throw errors when encountering an error?
81
+ //is TRUE by default
82
+ _defineProperty(_assertThisInitialized(_this), "__throw_errors", void 0);
83
+ //is this object marked as deleted?
84
+ _defineProperty(_assertThisInitialized(_this), "_deleted", void 0);
85
+ _defineProperty(_assertThisInitialized(_this), "_deletedBy", void 0);
86
+ //errors
87
+ _defineProperty(_assertThisInitialized(_this), "__errors", void 0);
88
+ _defineProperty(_assertThisInitialized(_this), "__showErrors", void 0);
89
+ //save results
90
+ _defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
91
+ _defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
92
+ _defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
93
+ //sequence key (usually managed by the database)
94
+ _defineProperty(_assertThisInitialized(_this), "_index_key", "");
95
+ //sequence value , used to index the object with increasing numbers
96
+ _defineProperty(_assertThisInitialized(_this), "_index_value", -1);
97
+ _defineProperty(_assertThisInitialized(_this), "getValue", _classPrivateMethodGet(_assertThisInitialized(_this), _getProperty, _getProperty2));
98
+ _defineProperty(_assertThisInitialized(_this), "get", _classPrivateMethodGet(_assertThisInitialized(_this), _getProperty, _getProperty2));
99
+ _defineProperty(_assertThisInitialized(_this), "getTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _getTempProperty, _getTempProperty2));
100
+ _defineProperty(_assertThisInitialized(_this), "set", _this.setValue);
101
+ _defineProperty(_assertThisInitialized(_this), "setTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _setTempProperty, _setTempProperty2));
186
102
  /**
187
103
  * set value of a key only if the value is empty
188
104
  * @param key
189
105
  * @param value
190
106
  * @returns
191
- */
192
- setDefaultValue(key, value) {
193
- return this.#setDefaultProperty(key, value);
194
- }
107
+ */
108
+ _defineProperty(_assertThisInitialized(_this), "setDefault", _this.setDefaultValue);
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:
133
+ /**
134
+ * set value
135
+ * @param key
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
+ ignoredStartingWords: "_"
166
+ })) {
167
+ _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, value);
168
+ isValueChanged = true;
169
+ } else isValueChanged = false;
170
+ //console.log("SV:", isValueChanged, oldval, key, value);
171
+ case 11:
172
+ _context.prev = 11;
173
+ if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
174
+ _context.next = 15;
175
+ break;
176
+ }
177
+ _context.next = 15;
178
+ return this.notifyChanged("", key, value);
179
+ case 15:
180
+ return _context.finish(11);
181
+ case 16:
182
+ return _context.abrupt("return", isValueChanged);
183
+ case 17:
184
+ case "end":
185
+ return _context.stop();
186
+ }
187
+ }, _callee, this, [[8,, 11, 16]]);
188
+ }));
189
+ function setValue(_x, _x2) {
190
+ return _setValue.apply(this, arguments);
191
+ }
192
+ return setValue;
193
+ }()
194
+ }, {
195
+ key: "setDefaultValue",
196
+ value:
195
197
  /**
196
198
  * set value of a key only if the value is empty
197
199
  * @param key
198
200
  * @param value
199
201
  * @returns
200
- */
201
- setDefault = this.setDefaultValue;
202
+ */
203
+ function setDefaultValue(key, value) {
204
+ return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
205
+ }
206
+ }, {
207
+ key: "reset",
208
+ value:
202
209
  /**
203
210
  * set the value to its original
204
211
  * @param key
205
- */
206
- async reset(key, notifyChanged = "auto") {
207
- return await this.setValue(key, this[key], notifyChanged);
208
- }
212
+ */
213
+ function () {
214
+ var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
215
+ var notifyChanged,
216
+ _args2 = arguments;
217
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
218
+ while (1) switch (_context2.prev = _context2.next) {
219
+ case 0:
220
+ notifyChanged = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : "auto";
221
+ _context2.next = 3;
222
+ return this.setValue(key, this[key], notifyChanged);
223
+ case 3:
224
+ return _context2.abrupt("return", _context2.sent);
225
+ case 4:
226
+ case "end":
227
+ return _context2.stop();
228
+ }
229
+ }, _callee2, this);
230
+ }));
231
+ function reset(_x3) {
232
+ return _reset.apply(this, arguments);
233
+ }
234
+ return reset;
235
+ }()
209
236
  /**
210
237
  * reset all values back to their original
211
238
  * @param key
212
- */
213
- async resetAll(notifyChanged = "auto") {
214
- let fr = true;
215
- for (const key in this.__delta) {
216
- fr = fr && (await this.reset(key, notifyChanged));
217
- }
218
- return fr;
219
- }
239
+ */
240
+ }, {
241
+ key: "resetAll",
242
+ value: function () {
243
+ var _resetAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
244
+ var notifyChanged,
245
+ fr,
246
+ key,
247
+ _args3 = arguments;
248
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
249
+ while (1) switch (_context3.prev = _context3.next) {
250
+ case 0:
251
+ notifyChanged = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : "auto";
252
+ fr = true;
253
+ _context3.t0 = _regeneratorRuntime().keys(this.__delta);
254
+ case 3:
255
+ if ((_context3.t1 = _context3.t0()).done) {
256
+ _context3.next = 13;
257
+ break;
258
+ }
259
+ key = _context3.t1.value;
260
+ _context3.t2 = fr;
261
+ if (!_context3.t2) {
262
+ _context3.next = 10;
263
+ break;
264
+ }
265
+ _context3.next = 9;
266
+ return this.reset(key, notifyChanged);
267
+ case 9:
268
+ _context3.t2 = _context3.sent;
269
+ case 10:
270
+ fr = _context3.t2;
271
+ _context3.next = 3;
272
+ break;
273
+ case 13:
274
+ return _context3.abrupt("return", fr);
275
+ case 14:
276
+ case "end":
277
+ return _context3.stop();
278
+ }
279
+ }, _callee3, this);
280
+ }));
281
+ function resetAll() {
282
+ return _resetAll.apply(this, arguments);
283
+ }
284
+ return resetAll;
285
+ }()
220
286
  /**
221
287
  * set key of subObject
222
288
  * @param key
223
289
  * @param value
224
290
  * @param subvalue
225
291
  * @return true if changed , false otherwise
226
- */
227
- async setSubValue(key, objKey, subvalue, sendChanges = "auto") {
228
- if (!this.canModify) {
229
- if (this.__throw_errors !== false)
230
- throw Error("Cant use setValue when on readonly mode");
231
- else
232
- return false;
233
- }
234
- let isValueChanged = false;
235
- try {
236
- //if accessing subval of an object, make sure the object is not null
237
- const subval = this.#getSubProperty(key, objKey);
238
- if (!object_equals(subval, subvalue, {
239
- ignoredStartingWords: "_",
240
- })) {
241
- this.#setSubProperty(key, objKey, subvalue);
242
- isValueChanged = true;
243
- }
244
- else
245
- isValueChanged = false;
246
- }
247
- finally {
248
- if (sendChanges === true ||
249
- (sendChanges === "auto" && isValueChanged)) {
250
- await this.notifyChanged("", String(key), objKey, subvalue);
251
- }
252
- }
253
- return isValueChanged;
254
- }
292
+ */
293
+ }, {
294
+ key: "setSubValue",
295
+ value: function () {
296
+ var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, objKey, subvalue) {
297
+ var sendChanges,
298
+ isValueChanged,
299
+ subval,
300
+ _args4 = arguments;
301
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
302
+ while (1) switch (_context4.prev = _context4.next) {
303
+ case 0:
304
+ sendChanges = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "auto";
305
+ if (this.canModify) {
306
+ _context4.next = 7;
307
+ break;
308
+ }
309
+ if (!(this.__throw_errors !== false)) {
310
+ _context4.next = 6;
311
+ break;
312
+ }
313
+ throw Error("Cant use setValue when on readonly mode");
314
+ case 6:
315
+ return _context4.abrupt("return", false);
316
+ case 7:
317
+ isValueChanged = false;
318
+ _context4.prev = 8;
319
+ //if accessing subval of an object, make sure the object is not null
320
+ subval = _classPrivateMethodGet(this, _getSubProperty, _getSubProperty2).call(this, key, objKey);
321
+ if (!(0, _object.object_equals)(subval, subvalue, {
322
+ ignoredStartingWords: "_"
323
+ })) {
324
+ _classPrivateMethodGet(this, _setSubProperty, _setSubProperty2).call(this, key, objKey, subvalue);
325
+ isValueChanged = true;
326
+ } else isValueChanged = false;
327
+ case 11:
328
+ _context4.prev = 11;
329
+ if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
330
+ _context4.next = 15;
331
+ break;
332
+ }
333
+ _context4.next = 15;
334
+ return this.notifyChanged("", key, objKey, subvalue);
335
+ case 15:
336
+ return _context4.finish(11);
337
+ case 16:
338
+ return _context4.abrupt("return", isValueChanged);
339
+ case 17:
340
+ case "end":
341
+ return _context4.stop();
342
+ }
343
+ }, _callee4, this, [[8,, 11, 16]]);
344
+ }));
345
+ function setSubValue(_x4, _x5, _x6) {
346
+ return _setSubValue.apply(this, arguments);
347
+ }
348
+ return setSubValue;
349
+ }()
255
350
  /**
256
351
  * Push value on array
257
352
  * @param key
258
353
  * @param value
259
354
  * @param sendChanges
260
355
  * @returns
261
- */
262
- async pushValue(key, value, sendChanges = "auto") {
263
- if (value == null)
264
- return false;
265
- if (!this.canModify) {
266
- if (this.__throw_errors !== false)
267
- throw Error("Cant use pushValue when on readonly mode");
268
- else
269
- return false;
270
- }
271
- if (this.#getProperty(key) == null) {
272
- this.#setProperty(key, []);
273
- }
274
- let tempArray = this.#getProperty(key);
275
- if (!Array.isArray(tempArray)) {
276
- if (this.__throw_errors !== false)
277
- throw Error("Cant use pushValue on non Array keys");
278
- else
279
- return false;
280
- }
281
- this.#setProperty(key, [...tempArray, value]);
282
- if (sendChanges === true || sendChanges === "auto") {
283
- await this.notifyChanged("", String(key), value);
284
- }
285
- return tempArray;
286
- }
287
- /**
288
- * notify the manager class when a value is changed on this object
289
- * @param type
290
- * @param key
291
- * @param value
292
- * @param subvalue
293
- */
294
- async notifyChanged(type, key, value, subvalue) {
295
- if (value === undefined && type != "meta")
296
- value = this.getValue(key);
297
- this.__changed = true;
298
- let lc = "";
299
- if (type)
300
- lc += `$${String(type)}$`;
301
- if (subvalue) {
302
- lc += `${String(key)}.${value}`;
303
- }
304
- else {
305
- lc += `${String(key)}`;
306
- }
307
- this.__lastChanged = lc;
308
- /* --------------------------- notify the manager --------------------------- */
309
- const manager_class = this.manager;
310
- if (manager_class instanceof ObjectManager) {
311
- await manager_class.notifyChanged(type, key, value, subvalue);
312
- }
313
- }
356
+ */
357
+ }, {
358
+ key: "pushValue",
359
+ value: function () {
360
+ var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, value) {
361
+ var sendChanges,
362
+ tempArray,
363
+ _args5 = arguments;
364
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
365
+ while (1) switch (_context5.prev = _context5.next) {
366
+ case 0:
367
+ sendChanges = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "auto";
368
+ if (!(value == null)) {
369
+ _context5.next = 3;
370
+ break;
371
+ }
372
+ return _context5.abrupt("return", false);
373
+ case 3:
374
+ if (this.canModify) {
375
+ _context5.next = 9;
376
+ break;
377
+ }
378
+ if (!(this.__throw_errors !== false)) {
379
+ _context5.next = 8;
380
+ break;
381
+ }
382
+ throw Error("Cant use pushValue when on readonly mode");
383
+ case 8:
384
+ return _context5.abrupt("return", false);
385
+ case 9:
386
+ if (_classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key) == null) {
387
+ _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, []);
388
+ }
389
+ tempArray = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
390
+ if (Array.isArray(tempArray)) {
391
+ _context5.next = 17;
392
+ break;
393
+ }
394
+ if (!(this.__throw_errors !== false)) {
395
+ _context5.next = 16;
396
+ break;
397
+ }
398
+ throw Error("Cant use pushValue on non Array keys");
399
+ case 16:
400
+ return _context5.abrupt("return", false);
401
+ case 17:
402
+ _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, [].concat(_toConsumableArray(tempArray), [value]));
403
+ if (!(sendChanges === true || sendChanges === "auto")) {
404
+ _context5.next = 21;
405
+ break;
406
+ }
407
+ _context5.next = 21;
408
+ return this.notifyChanged("", key, value);
409
+ case 21:
410
+ return _context5.abrupt("return", tempArray);
411
+ case 22:
412
+ case "end":
413
+ return _context5.stop();
414
+ }
415
+ }, _callee5, this);
416
+ }));
417
+ function pushValue(_x7, _x8) {
418
+ return _pushValue.apply(this, arguments);
419
+ }
420
+ return pushValue;
421
+ }()
422
+ }, {
423
+ key: "notifyChanged",
424
+ value: function () {
425
+ var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(type, key, value, subvalue) {
426
+ var lc, manager_class;
427
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
428
+ while (1) switch (_context6.prev = _context6.next) {
429
+ case 0:
430
+ if (value === undefined && type != "meta") value = this.getValue(key);
431
+ this.__changed = true;
432
+ lc = "";
433
+ if (type) lc += "$".concat(String(type), "$");
434
+ if (subvalue) {
435
+ lc += "".concat(String(key), ".").concat(value);
436
+ } else {
437
+ lc += "".concat(String(key));
438
+ }
439
+ this.__lastChanged = lc;
440
+ /* --------------------------- notify the manager --------------------------- */
441
+ manager_class = this.manager;
442
+ if (!(manager_class instanceof _ObjectManager["default"])) {
443
+ _context6.next = 10;
444
+ break;
445
+ }
446
+ _context6.next = 10;
447
+ return manager_class.notifyChanged(type, key, value, subvalue);
448
+ case 10:
449
+ case "end":
450
+ return _context6.stop();
451
+ }
452
+ }, _callee6, this);
453
+ }));
454
+ function notifyChanged(_x9, _x10, _x11, _x12) {
455
+ return _notifyChanged.apply(this, arguments);
456
+ }
457
+ return notifyChanged;
458
+ }()
314
459
  /**
315
460
  * check if a key can be changed on an object
316
461
  * @param object
317
462
  * @param key
318
463
  * @param useExtraProps
319
464
  * @returns
320
- */
321
- static canChangeKey(object, key, useExtraProps) {
322
- if (!object || !key)
323
- return false;
324
- if (useExtraProps) {
325
- const __extraProperties = object.constructor["__extraProperties"];
326
- if (__extraProperties != null && __extraProperties.includes(key))
327
- return true;
328
- }
329
- const __changeables = object.constructor["__changeables"];
330
- const __unchangeables = object.constructor["__unchangeables"];
331
- if (__changeables != null && !__changeables.includes(key))
332
- return false;
333
- if (__unchangeables != null && __unchangeables.includes(key))
334
- return false;
335
- return true;
336
- }
337
- /* -------------------------------------------------------------------------- */
338
- /* Changes */
339
- /* -------------------------------------------------------------------------- */
465
+ */
466
+ }, {
467
+ key: "apply_changes",
468
+ value: /* -------------------------------------------------------------------------- */
469
+ /* Changes */
470
+ /* -------------------------------------------------------------------------- */
340
471
  /**
341
472
  * Apply the changes and empty the delta object
342
- */
343
- apply_changes() {
344
- try {
345
- if (!this.__use_delta) {
346
- //in this mode , we track changes by updating the original product
347
- this.setOriginal();
348
- return true;
349
- }
350
- if (!this.isChanged) {
351
- console.warn("No changes to apply");
352
- return false;
353
- }
354
- for (const key in this.__delta) {
355
- const nv = this.__delta[key];
356
- this[key] = nv;
357
- }
358
- return true;
359
- }
360
- finally {
361
- this.clear_changes();
362
- }
363
- }
473
+ */
474
+ function apply_changes() {
475
+ try {
476
+ if (!this.__use_delta) {
477
+ //in this mode , we track changes by updating the original product
478
+ this.setOriginal();
479
+ return true;
480
+ }
481
+ if (!this.isChanged) {
482
+ console.warn("No changes to apply");
483
+ return false;
484
+ }
485
+ for (var key in this.__delta) {
486
+ var nv = this.__delta[key];
487
+ this[key] = nv;
488
+ }
489
+ return true;
490
+ } finally {
491
+ this.clear_changes();
492
+ }
493
+ }
364
494
  /**
365
495
  * clear and discard all changes
366
496
  * @returns
367
- */
368
- clear_changes() {
369
- this.__delta = {};
370
- this.__changed = false;
371
- return true;
372
- }
497
+ */
498
+ }, {
499
+ key: "clear_changes",
500
+ value: function clear_changes() {
501
+ this.__delta = {};
502
+ this.__changed = false;
503
+ return true;
504
+ }
373
505
  /**
374
506
  * clear and discard all temp values
375
507
  * @returns
376
- */
377
- clear_cache() {
378
- delete this.__temp;
379
- return true;
380
- }
508
+ */
509
+ }, {
510
+ key: "clear_cache",
511
+ value: function clear_cache() {
512
+ delete this.__temp;
513
+ return true;
514
+ }
381
515
  /**
382
516
  * Sets readonly property on given objects
383
517
  * @param objs array of given objects or a single object
384
518
  * @param readonlyval readonly
385
519
  * @param clearChanges should we clean the changes after setting readonly
386
- */
387
- static setReadonly(objs, readonlyval = true, clearChanges = false) {
388
- let checkObjs = [];
389
- if (!objs)
390
- objs = [];
391
- if (!Array.isArray(objs))
392
- checkObjs = [objs];
393
- else
394
- checkObjs = objs;
395
- for (let index = 0; index < checkObjs.length; index++) {
396
- const obj = checkObjs[index];
397
- obj.__is_readonly = readonlyval;
398
- if (obj instanceof SimpleObject) {
399
- if (obj.canModify) {
400
- if (!obj.getOriginal())
401
- obj.setOriginal();
402
- }
403
- else {
404
- if (clearChanges)
405
- obj.clear_changes();
406
- //we dont need the original object in readonly mode
407
- obj.setOriginal(null);
408
- }
409
- }
410
- }
411
- }
412
- static setThrowErrors(objs, throwErr = true) {
413
- let checkObjs = [];
414
- if (!objs)
415
- objs = [];
416
- if (!Array.isArray(objs))
417
- checkObjs = [objs];
418
- else
419
- checkObjs = objs;
420
- for (let index = 0; index < checkObjs.length; index++) {
421
- const element = checkObjs[index];
422
- element.__throw_errors = throwErr;
423
- }
424
- }
425
- /* -------------------------------------------------------------------------- */
426
- /* Get/Check */
427
- /* -------------------------------------------------------------------------- */
428
- get isChanged() {
429
- ////const deltaIsBlank = object_isEmpty(this.__delta);
430
- ////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
431
- ////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
432
- if (this.__use_delta)
433
- return !object_isEmpty(this.__delta);
434
- /* -------------------------------------------------------------------------- */
435
- /* check the properties one by one */
436
- /* -------------------------------------------------------------------------- */
437
- const orig = this.getOriginal();
438
- if (!orig)
439
- return false; //we dont know if anything has changed
440
- /* if object is not using delta mode, check changes by comparing changable fields with original object */
441
- if (Array.isArray(this.__changeables)) {
442
- //console.log("chk", this.__changeables, "for changes");
443
- return (this.__changeables.find((c) => {
444
- return !object_equals(this[c], orig[c]);
445
- }) != undefined);
446
- }
447
- else {
448
- /* check all fields */
449
- for (const key in this) {
450
- if (key.startsWith("__"))
451
- continue;
452
- if (!object_equals(this[key], orig[key]))
453
- return true;
454
- }
455
- return false;
456
- }
457
- return false;
458
- }
459
- get isDeleted() {
460
- return this._deleted || false;
461
- }
462
- set isDeleted(v) {
463
- this._deleted = v;
464
- }
465
- get d() {
466
- return this.__use_delta ? this.__delta : this;
467
- }
468
- /* all updated properties */
469
- get allproperties() {
470
- const result = { ...this, ...this.__delta };
471
- result.__delta = {};
472
- return result;
473
- }
474
- get canModify() {
475
- return !Boolean(this.__is_readonly);
476
- }
477
- get __cache_name() {
478
- return this.constructor["__cache_name"];
479
- }
480
- get __changeables() {
481
- return this.constructor["__changeables"];
482
- }
483
- get __unchangeables() {
484
- return this.constructor["__unchangeables"];
485
- }
486
- get __use_delta() {
487
- return this.constructor["__use_delta"];
488
- }
489
- get isSaved() {
490
- return Boolean(this.__saveResultIsSuccess ?? false);
491
- }
492
- get isNew() {
493
- const mid = this.getID();
494
- if (!mid)
495
- return true;
496
- if (typeof mid === "string")
497
- return mid === "" || mid === "-1";
498
- if (typeof mid === "number")
499
- return mid === -1;
500
- return false;
501
- }
502
- get lastChanged() {
503
- return this.__lastChanged || "";
504
- }
505
- get manager() {
506
- return this.#get_managerClass() || undefined;
507
- }
508
- #get_managerClass = () => undefined;
509
- set_managerClass(mng) {
510
- if ((mng instanceof ObjectManager || mng instanceof WebObjectManager) &&
511
- typeof mng.event_run === "function")
512
- this.#get_managerClass = () => mng;
513
- else {
514
- console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
515
- }
516
- }
517
- static isDeleted(obj) {
518
- if (obj instanceof SimpleObject)
519
- return obj.isDeleted === true;
520
- return false;
521
- }
522
- getIndexOrID() {
523
- return SimpleObject.getIndexOrID(this);
524
- }
525
- getIndex() {
526
- return SimpleObject.getIndex(this);
527
- }
528
- getID() {
529
- return SimpleObject.getID(this);
530
- }
531
- static getIndexOrID(o) {
532
- let res = SimpleObject.getIndex(o);
533
- if (!res || res == -1)
534
- res = SimpleObject.getID(o);
535
- return res || -1;
536
- }
537
- static getIndex(o) {
538
- if (o == null || o == undefined)
539
- return -1;
540
- switch (typeof o) {
541
- case "object":
542
- return o._index_value || -1;
543
- case "number":
544
- case "string":
545
- return Number(o);
546
- }
547
- return -1;
548
- }
549
- static getID(o) {
550
- if (o == null || o == undefined)
551
- return "";
552
- switch (typeof o) {
553
- case "object":
554
- if (o._bsontype == "ObjectID" &&
555
- typeof o.toString === "function") {
556
- return o.toString();
557
- }
558
- return String(o._id || o.ID || o.id || o.__data_id || "");
559
- case "string":
560
- case "number":
561
- return String(o);
562
- }
563
- return "";
564
- }
565
- /* -------------------------------------------------------------------------- */
566
- /* Original */
567
- /* -------------------------------------------------------------------------- */
568
- getOriginal() {
569
- return this.__originalobject || undefined;
570
- }
571
- setOriginal(toObj = 0) {
572
- if (toObj === null) {
573
- delete this.__originalobject;
574
- return;
575
- }
576
- if (!this.canModify) {
577
- console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
578
- delete this.__originalobject;
579
- return;
580
- }
581
- if (toObj === 0) {
582
- toObj = this;
583
- }
584
- const cloneObject = object_clone(toObj);
585
- SimpleObject.setReadonly(cloneObject, true);
586
- this.__originalobject = object_removeKeys(cloneObject, ["__"]);
587
- return this;
588
- }
589
- static setOriginal(obj, toObj = 0) {
590
- if (!(obj instanceof SimpleObject))
591
- return undefined;
592
- return obj.setOriginal(toObj);
593
- }
594
- static getOriginal(obj) {
595
- if (obj instanceof SimpleObject)
596
- return obj.getOriginal();
597
- return obj?.__originalobject;
598
- }
599
- /* -------------------------------------------------------------------------- */
600
- /* Errors */
601
- /* -------------------------------------------------------------------------- */
602
- static addError(o, title, message, sendToRegister = "auto") {
603
- const errStr = combine_if_not_blank(title, " : ", message);
604
- if (o) {
605
- if (!Array.isArray(o.__errors))
606
- o.__errors = [];
607
- o.__errors.push(errStr);
608
- if (o.__showErrors === false)
609
- return;
610
- }
611
- else if (sendToRegister === "auto")
612
- sendToRegister = true;
613
- if (sendToRegister === true) {
614
- console.error("[REGISTER-ERROR]", errStr);
615
- gfunc.run_action("add_error", {
616
- title: title,
617
- message: message,
618
- type: "error",
619
- });
620
- }
621
- else {
622
- console.error("[ERROR]", errStr);
623
- }
624
- return o?.__errors || [];
625
- }
626
- static getErrors(o) {
627
- return o?.__errors || [];
628
- }
629
- static clearErrors(o) {
630
- if (o)
631
- o.__errors = [];
632
- return true;
633
- }
634
- /* -------------------------------------------------------------------------- */
635
- /* Save Results */
636
- /* -------------------------------------------------------------------------- */
637
- /**
638
- * Checks if the given object is a valid and truthy save result
639
- * @param result_object
640
- * @returns
641
- */
642
- static isResultValid(result_object, sub = false) {
643
- if (object_isEmpty(result_object))
644
- return false;
645
- switch (typeof result_object) {
646
- case "string":
647
- try {
648
- result_object = JSON.parse(result_object);
649
- return this.isResultValid(result_object);
650
- }
651
- catch {
652
- return false;
653
- }
654
- case "object":
655
- if (object_isTrue(result_object.acknowledged)) {
656
- return true;
657
- }
658
- if (result_object.expected && result_object.result) {
659
- return object_equals(result_object.expected, result_object.result);
660
- }
661
- return Number(this.getID(result_object)) >= 0;
662
- case "number":
663
- return result_object > 0;
664
- case "boolean":
665
- return result_object === true;
666
- }
667
- return false;
668
- }
520
+ */
521
+ }, {
522
+ key: "isChanged",
523
+ get: /* -------------------------------------------------------------------------- */
524
+ /* Get/Check */
525
+ /* -------------------------------------------------------------------------- */
526
+ function get() {
527
+ var _this2 = this;
528
+ ////const deltaIsBlank = object_isEmpty(this.__delta);
529
+ ////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
530
+ ////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
531
+ if (this.__use_delta) return !(0, _object.object_isEmpty)(this.__delta);
532
+ /* -------------------------------------------------------------------------- */
533
+ /* check the properties one by one */
534
+ /* -------------------------------------------------------------------------- */
535
+ var orig = this.getOriginal();
536
+ if (!orig) return false; //we dont know if anything has changed
537
+ /* if object is not using delta mode, check changes by comparing changable fields with original object */
538
+ if (Array.isArray(this.__changeables)) {
539
+ //console.log("chk", this.__changeables, "for changes");
540
+ return this.__changeables.find(function (c) {
541
+ return !(0, _object.object_equals)(_this2[c], orig[c]);
542
+ }) != undefined;
543
+ } else {
544
+ /* check all fields */
545
+ for (var key in this) {
546
+ if (key.startsWith("__")) continue;
547
+ if (!(0, _object.object_equals)(this[key], orig[key])) return true;
548
+ }
549
+ return false;
550
+ }
551
+ return false;
552
+ }
553
+ }, {
554
+ key: "isDeleted",
555
+ get: function get() {
556
+ return this._deleted || false;
557
+ },
558
+ set: function set(v) {
559
+ this._deleted = v;
560
+ }
561
+ }, {
562
+ key: "d",
563
+ get: function get() {
564
+ return this.__use_delta ? this.__delta : this;
565
+ }
566
+ /* all updated properties */
567
+ }, {
568
+ key: "allproperties",
569
+ get: function get() {
570
+ var result = _objectSpread(_objectSpread({}, this), this.__delta);
571
+ result.__delta = {};
572
+ return result;
573
+ }
574
+ }, {
575
+ key: "canModify",
576
+ get: function get() {
577
+ return !Boolean(this.__is_readonly);
578
+ }
579
+ }, {
580
+ key: "__cache_name",
581
+ get: function get() {
582
+ return this.constructor["__cache_name"];
583
+ }
584
+ }, {
585
+ key: "__changeables",
586
+ get: function get() {
587
+ return this.constructor["__changeables"];
588
+ }
589
+ }, {
590
+ key: "__unchangeables",
591
+ get: function get() {
592
+ return this.constructor["__unchangeables"];
593
+ }
594
+ }, {
595
+ key: "__use_delta",
596
+ get: function get() {
597
+ return this.constructor["__use_delta"];
598
+ }
599
+ }, {
600
+ key: "isSaved",
601
+ get: function get() {
602
+ var _this$__saveResultIsS;
603
+ return Boolean((_this$__saveResultIsS = this.__saveResultIsSuccess) !== null && _this$__saveResultIsS !== void 0 ? _this$__saveResultIsS : false);
604
+ }
605
+ }, {
606
+ key: "isNew",
607
+ get: function get() {
608
+ var mid = this.getID();
609
+ if (!mid) return true;
610
+ if (typeof mid === "string") return mid === "" || mid === "-1";
611
+ if (typeof mid === "number") return mid === -1;
612
+ return false;
613
+ }
614
+ }, {
615
+ key: "lastChanged",
616
+ get: function get() {
617
+ return this.__lastChanged || "";
618
+ }
619
+ }, {
620
+ key: "manager",
621
+ get: function get() {
622
+ return this.get_managerClass() || undefined;
623
+ }
624
+ }, {
625
+ key: "set_managerClass",
626
+ value: function set_managerClass(mng) {
627
+ if ((mng instanceof _ObjectManager["default"] || mng instanceof _WebObjectManager["default"]) && typeof mng.event_run === "function") this.get_managerClass = function () {
628
+ return mng;
629
+ };else {
630
+ console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
631
+ }
632
+ }
633
+ }, {
634
+ key: "getIndexOrID",
635
+ value: function getIndexOrID() {
636
+ return SimpleObject.getIndexOrID(this);
637
+ }
638
+ }, {
639
+ key: "getIndex",
640
+ value: function getIndex() {
641
+ return SimpleObject.getIndex(this);
642
+ }
643
+ }, {
644
+ key: "getID",
645
+ value: function getID() {
646
+ return SimpleObject.getID(this);
647
+ }
648
+ }, {
649
+ key: "getOriginal",
650
+ value: /* -------------------------------------------------------------------------- */
651
+ /* Original */
652
+ /* -------------------------------------------------------------------------- */
653
+ function getOriginal() {
654
+ return this.__originalobject || undefined;
655
+ }
656
+ }, {
657
+ key: "setOriginal",
658
+ value: function setOriginal() {
659
+ var toObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
660
+ if (toObj === null) {
661
+ delete this.__originalobject;
662
+ return;
663
+ }
664
+ if (!this.canModify) {
665
+ console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
666
+ delete this.__originalobject;
667
+ return;
668
+ }
669
+ if (toObj === 0) {
670
+ toObj = this;
671
+ }
672
+ var cloneObject = (0, _object.object_clone)(toObj);
673
+ SimpleObject.setReadonly(cloneObject, true);
674
+ this.__originalobject = (0, _object.object_removeKeys)(cloneObject, ["__"]);
675
+ return this;
676
+ }
677
+ }, {
678
+ key: "setSaveResult",
679
+ value:
669
680
  /**
670
681
  * set the response of last save from site
671
682
  * and its type
672
683
  * @param toObj
673
- */
674
- setSaveResult(toObj, type) {
675
- if (toObj != null) {
676
- this.#setSaveResultObject(toObj);
677
- }
678
- else {
679
- this.#setSaveResultObject(null);
680
- }
681
- //check if the given object is a valid save result
682
- if (type === "error")
683
- this.__saveResultIsSuccess = false;
684
- else
685
- this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
686
- if (type === "auto") {
687
- type = this.__saveResultIsSuccess ? "normal" : "error";
688
- }
689
- this.__saveResultType = type;
690
- }
684
+ */
685
+ function setSaveResult(toObj, type) {
686
+ if (toObj != null) {
687
+ _classPrivateMethodGet(this, _setSaveResultObject, _setSaveResultObject2).call(this, toObj);
688
+ } else {
689
+ _classPrivateMethodGet(this, _setSaveResultObject, _setSaveResultObject2).call(this, null);
690
+ }
691
+ //check if the given object is a valid save result
692
+ if (type === "error") this.__saveResultIsSuccess = false;else this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
693
+ if (type === "auto") {
694
+ type = this.__saveResultIsSuccess ? "normal" : "error";
695
+ }
696
+ this.__saveResultType = type;
697
+ }
698
+ }, {
699
+ key: "getSaveResult",
700
+ value: function getSaveResult() {
701
+ var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
702
+ if (this.isSaved) return this.__saveResultObject;
703
+ return false;
704
+ }
705
+ }, {
706
+ key: "getSaveResultType",
707
+ value: function getSaveResultType() {
708
+ return this.__saveResultType || "nothing";
709
+ }
710
+ /* -------------------------------------------------------------------------- */
711
+ /* statics */
712
+ /* -------------------------------------------------------------------------- */
713
+ }], [{
714
+ key: "loadValues",
715
+ value: function loadValues(obj, initObject) {
716
+ var fullUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
717
+ SimpleObject.factoryClear(obj);
718
+ if (initObject == null) {
719
+ for (var key in obj) {
720
+ if (typeof obj[key] === "function") continue;
721
+ if (key.startsWith("__")) continue;
722
+ delete obj[key];
723
+ }
724
+ } else if (_typeof(initObject) == "object") {
725
+ for (var _key in initObject) {
726
+ if (_key.startsWith("__")) continue;
727
+ if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key)) {
728
+ obj[_key] = initObject[_key];
729
+ }
730
+ }
731
+ }
732
+ return true;
733
+ }
734
+ /* -------------------------------------------------------------------------- */
735
+ }, {
736
+ key: "getValue",
737
+ value: function getValue(o, key) {
738
+ var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
739
+ if (o == null) return undefined;
740
+ if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
741
+ if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
742
+ //@ts-ignore
743
+ return o.__delta[key];
744
+ }
745
+ return o[key];
746
+ }
747
+ }, {
748
+ key: "canChangeKey",
749
+ value: function canChangeKey(object, key, useExtraProps) {
750
+ if (!object || !key) return false;
751
+ if (useExtraProps) {
752
+ var __extraProperties = object.constructor["__extraProperties"];
753
+ if (__extraProperties != null && __extraProperties.includes(key)) return true;
754
+ }
755
+ var __changeables = object.constructor["__changeables"];
756
+ var __unchangeables = object.constructor["__unchangeables"];
757
+ if (__changeables != null && !__changeables.includes(key)) return false;
758
+ if (__unchangeables != null && __unchangeables.includes(key)) return false;
759
+ return true;
760
+ }
761
+ }, {
762
+ key: "setReadonly",
763
+ value: function setReadonly(objs) {
764
+ var readonlyval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
765
+ var clearChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
766
+ var checkObjs = [];
767
+ if (!objs) objs = [];
768
+ if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
769
+ for (var index = 0; index < checkObjs.length; index++) {
770
+ var obj = checkObjs[index];
771
+ obj.__is_readonly = readonlyval;
772
+ if (obj instanceof SimpleObject) {
773
+ if (obj.canModify) {
774
+ if (!obj.getOriginal()) obj.setOriginal();
775
+ } else {
776
+ if (clearChanges) obj.clear_changes();
777
+ //we dont need the original object in readonly mode
778
+ obj.setOriginal(null);
779
+ }
780
+ }
781
+ }
782
+ }
783
+ }, {
784
+ key: "setThrowErrors",
785
+ value: function setThrowErrors(objs) {
786
+ var throwErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
787
+ var checkObjs = [];
788
+ if (!objs) objs = [];
789
+ if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
790
+ for (var index = 0; index < checkObjs.length; index++) {
791
+ var element = checkObjs[index];
792
+ element.__throw_errors = throwErr;
793
+ }
794
+ }
795
+ }, {
796
+ key: "isDeleted",
797
+ value: function isDeleted(obj) {
798
+ if (obj instanceof SimpleObject) return obj.isDeleted === true;
799
+ return false;
800
+ }
801
+ }, {
802
+ key: "getIndexOrID",
803
+ value: function getIndexOrID(o) {
804
+ var res = SimpleObject.getIndex(o);
805
+ if (!res || res == -1) res = SimpleObject.getID(o);
806
+ return res || -1;
807
+ }
808
+ }, {
809
+ key: "getIndex",
810
+ value: function getIndex(o) {
811
+ if (o == null || o == undefined) return -1;
812
+ switch (_typeof(o)) {
813
+ case "object":
814
+ return o._index_value || -1;
815
+ case "number":
816
+ case "string":
817
+ return Number(o);
818
+ }
819
+ return -1;
820
+ }
821
+ }, {
822
+ key: "getID",
823
+ value: function getID(o) {
824
+ if (o == null || o == undefined) return "";
825
+ switch (_typeof(o)) {
826
+ case "object":
827
+ if (o._bsontype == "ObjectID" && typeof o.toString === "function") {
828
+ return o.toString();
829
+ }
830
+ return String(o._id || o.ID || o.id || o.__data_id || "");
831
+ case "string":
832
+ case "number":
833
+ return String(o);
834
+ }
835
+ return "";
836
+ }
837
+ }, {
838
+ key: "setOriginal",
839
+ value: function setOriginal(obj) {
840
+ var toObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
841
+ if (!(obj instanceof SimpleObject)) return undefined;
842
+ return obj.setOriginal(toObj);
843
+ }
844
+ }, {
845
+ key: "getOriginal",
846
+ value: function getOriginal(obj) {
847
+ if (obj instanceof SimpleObject) return obj.getOriginal();
848
+ return obj === null || obj === void 0 ? void 0 : obj.__originalobject;
849
+ }
850
+ /* -------------------------------------------------------------------------- */
851
+ /* Errors */
852
+ /* -------------------------------------------------------------------------- */
853
+ }, {
854
+ key: "addError",
855
+ value: function addError(o, title, message) {
856
+ var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
857
+ var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
858
+ if (o) {
859
+ if (!Array.isArray(o.__errors)) o.__errors = [];
860
+ o.__errors.push(errStr);
861
+ if (o.__showErrors === false) return;
862
+ } else if (sendToRegister === "auto") sendToRegister = true;
863
+ if (sendToRegister === true) {
864
+ console.error("[REGISTER-ERROR]", errStr);
865
+ _global.gfunc.run_action("add_error", {
866
+ title: title,
867
+ message: message,
868
+ type: "error"
869
+ });
870
+ } else {
871
+ console.error("[ERROR]", errStr);
872
+ }
873
+ return (o === null || o === void 0 ? void 0 : o.__errors) || [];
874
+ }
875
+ }, {
876
+ key: "getErrors",
877
+ value: function getErrors(o) {
878
+ return (o === null || o === void 0 ? void 0 : o.__errors) || [];
879
+ }
880
+ }, {
881
+ key: "clearErrors",
882
+ value: function clearErrors(o) {
883
+ if (o) o.__errors = [];
884
+ return true;
885
+ }
886
+ /* -------------------------------------------------------------------------- */
887
+ /* Save Results */
888
+ /* -------------------------------------------------------------------------- */
691
889
  /**
692
- * set the response of last save from site
693
- * @param toObj
694
- */
695
- #setSaveResultObject(toObj) {
696
- this.__saveResultObject = toObj;
697
- }
698
- getSaveResult(original = false) {
699
- if (this.isSaved)
700
- return this.__saveResultObject;
701
- return false;
702
- }
703
- getSaveResultType() {
704
- return this.__saveResultType || "nothing";
705
- }
706
- /* -------------------------------------------------------------------------- */
707
- /* statics */
708
- /* -------------------------------------------------------------------------- */
709
- static factoryClear(obj) {
710
- obj.clear_changes();
711
- SimpleObject.clearErrors(obj);
712
- }
713
- static delete_cache() {
714
- if (!this.__cache_name)
715
- return;
716
- gcache.delete_cache(this.__cache_name);
717
- }
718
- static get_canModify(o) {
719
- if (o instanceof SimpleObject)
720
- return o.canModify;
721
- return false;
722
- }
723
- /* -------------------------------------------------------------------------- */
724
- static equals(a, b) {
725
- console.warn("Dont use the default equals method !");
726
- if (a == undefined || b == undefined)
727
- return false;
728
- return a === b;
729
- }
730
- }
731
- export default SimpleObject;
890
+ * Checks if the given object is a valid and truthy save result
891
+ * @param result_object
892
+ * @returns
893
+ */
894
+ }, {
895
+ key: "isResultValid",
896
+ value: function isResultValid(result_object) {
897
+ var sub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
898
+ if ((0, _object.object_isEmpty)(result_object)) return false;
899
+ switch (_typeof(result_object)) {
900
+ case "string":
901
+ try {
902
+ result_object = JSON.parse(result_object);
903
+ return this.isResultValid(result_object);
904
+ } catch (_unused) {
905
+ return false;
906
+ }
907
+ case "object":
908
+ if ((0, _object.object_isTrue)(result_object.acknowledged)) {
909
+ return true;
910
+ }
911
+ if (result_object.expected && result_object.result) {
912
+ return (0, _object.object_equals)(result_object.expected, result_object.result);
913
+ }
914
+ return Number(this.getID(result_object)) >= 0;
915
+ case "number":
916
+ return result_object > 0;
917
+ case "boolean":
918
+ return result_object === true;
919
+ }
920
+ return false;
921
+ }
922
+ }, {
923
+ key: "factoryClear",
924
+ value: function factoryClear(obj) {
925
+ obj.clear_changes();
926
+ SimpleObject.clearErrors(obj);
927
+ }
928
+ }, {
929
+ key: "delete_cache",
930
+ value: function delete_cache() {
931
+ if (!this.__cache_name) return;
932
+ _global.gcache.delete_cache(this.__cache_name);
933
+ }
934
+ }, {
935
+ key: "get_canModify",
936
+ value: function get_canModify(o) {
937
+ if (o instanceof SimpleObject) return o.canModify;
938
+ return false;
939
+ }
940
+ /* -------------------------------------------------------------------------- */
941
+ }, {
942
+ key: "equals",
943
+ value: function equals(a, b) {
944
+ console.warn("Dont use the default equals method !");
945
+ if (a == undefined || b == undefined) return false;
946
+ return a === b;
947
+ }
948
+ }]);
949
+ return SimpleObject;
950
+ }(_MapableObject2.MapableObject);
951
+ exports.SimpleObject = SimpleObject;
952
+ function _setSubProperty2(key, subkey, value) {
953
+ var subobj = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
954
+ //@ts-ignore
955
+ if (subobj == null || _typeof(subobj) !== "object") subobj = {};
956
+ subobj[subkey] = value;
957
+ _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, subobj);
958
+ }
959
+ function _getSubProperty2(key, subkey) {
960
+ var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
961
+ var subobj = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key, original);
962
+ if (subobj == null || _typeof(subobj) !== "object") return undefined;
963
+ return subobj[subkey];
964
+ }
965
+ function _setProperty2(key, value) {
966
+ if (this[key] === value) {
967
+ /**
968
+ * We set something back to its original value so no need to save it as Delta
969
+ */
970
+ delete this.__delta[key];
971
+ return false;
972
+ } else {
973
+ this.__delta[key] = value; //always update delta to keep track of changes
974
+ if (!this.__use_delta) this[key] = value; //on noDelta mode, also update the obj
975
+ return true;
976
+ }
977
+ }
978
+ function _setDefaultProperty2(key, value) {
979
+ //@ts-ignore
980
+ if (this[key] == undefined || this[key] === "" || this[key] === 0) {
981
+ this[key] = value;
982
+ return true;
983
+ }
984
+ return false;
985
+ }
986
+ function _getProperty2(key) {
987
+ var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
988
+ //check if we should use delta version or normal version for this property
989
+ if (original || !this.__use_delta || !(key in this.__delta)) return this[key];
990
+ //@ts-ignore
991
+ return this.__delta[key];
992
+ }
993
+ function _getTempProperty2(key) {
994
+ if (this.__temp == null) return undefined;
995
+ return this.__temp[key];
996
+ }
997
+ function _setTempProperty2(key, value) {
998
+ if (this.__temp == null) this.__temp = {};
999
+ this.__temp[key] = value;
1000
+ }
1001
+ function _setSaveResultObject2(toObj) {
1002
+ this.__saveResultObject = toObj;
1003
+ }
1004
+ _defineProperty(SimpleObject, "__cache_name", void 0);
1005
+ //these properties should not be changed and are usually set by server
1006
+ _defineProperty(SimpleObject, "__unchangeables", void 0);
1007
+ //these properties can be directly changed and are included in deltaObject
1008
+ _defineProperty(SimpleObject, "__changeables", void 0);
1009
+ //these properties usually are not directly changed and sometimes are included in deltaObject
1010
+ _defineProperty(SimpleObject, "__extraProperties", void 0);
1011
+ _defineProperty(SimpleObject, "__use_delta", true);
1012
+ var _default = SimpleObject;
1013
+ exports["default"] = _default;