@azrico/webobject 1.2.17 → 1.2.18

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