@azrico/webobject 1.3.21 → 1.3.22

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