@azrico/webobject 1.3.21 → 1.3.23
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.
- package/dist/index.js +1 -16
- package/dist/src/WebObjects/ParentWebObject.js +20 -51
- package/dist/src/WebObjects/WebObject.d.ts +0 -4
- package/dist/src/WebObjects/WebObject.js +262 -657
- package/dist/src/WebObjects/WebObjectManager.js +125 -386
- package/dist/src/index.js +9 -104
- package/dist/src/structs/DummyObject.js +8 -35
- package/dist/src/structs/MapableObject.js +74 -113
- package/dist/src/structs/MetaObject.js +35 -125
- package/dist/src/structs/ObjectArray.js +43 -71
- package/dist/src/structs/ObjectManager.js +210 -529
- package/dist/src/structs/SimpleObject.d.ts +4 -3
- package/dist/src/structs/SimpleObject.js +672 -958
- package/package.json +1 -1
|
@@ -1,1017 +1,731 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
import { gcache, gfunc } from "@azrico/global";
|
|
2
|
+
import { object_clone, object_equals, object_isEmpty, object_isTrue, object_removeKeys, } from "@azrico/object";
|
|
3
|
+
import { MapableObject } from "./MapableObject";
|
|
4
|
+
import ObjectManager from "./ObjectManager";
|
|
5
|
+
import WebObjectManager from "../WebObjects/WebObjectManager";
|
|
6
|
+
import { combine_if_not_blank } from "@azrico/string";
|
|
7
|
+
export class SimpleObject extends MapableObject {
|
|
8
|
+
static __cache_name;
|
|
9
|
+
//these properties should not be changed and are usually set by server
|
|
10
|
+
static __unchangeables;
|
|
11
|
+
//these properties can be directly changed and are included in deltaObject
|
|
12
|
+
static __changeables;
|
|
13
|
+
//these properties usually are not directly changed and sometimes are included in deltaObject
|
|
14
|
+
static __extraProperties;
|
|
15
|
+
static __use_delta = true;
|
|
16
|
+
_static() {
|
|
17
|
+
return this.constructor;
|
|
18
|
+
}
|
|
19
|
+
//an exact copy of this object is stored here
|
|
20
|
+
__originalobject;
|
|
21
|
+
//changes are saved here
|
|
22
|
+
__delta = {};
|
|
23
|
+
__temp = undefined;
|
|
24
|
+
__changed = false;
|
|
25
|
+
//the last thing that was changed on this object
|
|
26
|
+
__lastChanged;
|
|
27
|
+
//is the object read only
|
|
28
|
+
__is_readonly;
|
|
29
|
+
//should we throw errors when encountering an error?
|
|
30
|
+
//is TRUE by default
|
|
31
|
+
__throw_errors;
|
|
32
|
+
//is this object marked as deleted?
|
|
33
|
+
_deleted;
|
|
34
|
+
_deletedBy;
|
|
35
|
+
//errors
|
|
36
|
+
__errors;
|
|
37
|
+
__showErrors;
|
|
38
|
+
//save results
|
|
39
|
+
__saveResultObject;
|
|
40
|
+
__saveResultIsSuccess = true;
|
|
41
|
+
__saveResultType;
|
|
42
|
+
//sequence key (usually managed by the database)
|
|
43
|
+
_index_key = "";
|
|
44
|
+
//sequence value , used to index the object with increasing numbers
|
|
45
|
+
_index_value = -1;
|
|
46
|
+
constructor(is_readonly = false) {
|
|
47
|
+
super();
|
|
48
|
+
this.__is_readonly = is_readonly;
|
|
49
|
+
this.clear_changes();
|
|
50
|
+
}
|
|
51
|
+
#setSubProperty(key, subkey, value) {
|
|
52
|
+
let subobj = this.#getProperty(key);
|
|
53
|
+
//@ts-ignore
|
|
54
|
+
if (subobj == null || typeof subobj !== "object")
|
|
55
|
+
subobj = {};
|
|
56
|
+
subobj[subkey] = value;
|
|
57
|
+
this.#setProperty(key, subobj);
|
|
58
|
+
}
|
|
59
|
+
#getSubProperty(key, subkey, original = false) {
|
|
60
|
+
let subobj = this.#getProperty(key, original);
|
|
61
|
+
if (subobj == null || typeof subobj !== "object")
|
|
62
|
+
return undefined;
|
|
63
|
+
return subobj[subkey];
|
|
64
|
+
}
|
|
65
|
+
#setProperty(key, value) {
|
|
66
|
+
if (this[key] === value) {
|
|
67
|
+
/**
|
|
68
|
+
* We set something back to its original value so no need to save it as Delta
|
|
69
|
+
*/
|
|
70
|
+
delete this.__delta[key];
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
75
|
+
if (!this.__use_delta)
|
|
76
|
+
this[key] = value; //on noDelta mode, also update the obj
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
#setDefaultProperty(key, value) {
|
|
81
|
+
//@ts-ignore
|
|
82
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
83
|
+
this[key] = value;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
#getProperty(key, original = false) {
|
|
89
|
+
//check if we should use delta version or normal version for this property
|
|
90
|
+
if (original || !this.__use_delta || !(key in this.__delta))
|
|
91
|
+
return this[key];
|
|
92
|
+
//@ts-ignore
|
|
93
|
+
return this.__delta[key];
|
|
94
|
+
}
|
|
95
|
+
#getTempProperty(key) {
|
|
96
|
+
if (this.__temp == null)
|
|
97
|
+
return undefined;
|
|
98
|
+
return this.__temp[key];
|
|
99
|
+
}
|
|
100
|
+
#setTempProperty(key, value) {
|
|
101
|
+
if (this.__temp == null)
|
|
102
|
+
this.__temp = {};
|
|
103
|
+
this.__temp[key] = value;
|
|
104
|
+
}
|
|
105
|
+
/* -------------------------------------------------------------------------- */
|
|
106
|
+
/* Load */
|
|
107
|
+
/* -------------------------------------------------------------------------- */
|
|
108
|
+
loadValues(initObject, fullUpdate = false) {
|
|
109
|
+
return SimpleObject.loadValues(this, initObject, fullUpdate);
|
|
110
|
+
}
|
|
111
|
+
static loadValues(obj, initObject, fullUpdate = false) {
|
|
112
|
+
SimpleObject.factoryClear(obj);
|
|
113
|
+
if (initObject == null) {
|
|
114
|
+
for (const key in obj) {
|
|
115
|
+
if (typeof obj[key] === "function")
|
|
116
|
+
continue;
|
|
117
|
+
if (key.startsWith("__"))
|
|
118
|
+
continue;
|
|
119
|
+
delete obj[key];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (typeof initObject == "object") {
|
|
123
|
+
for (const key in initObject) {
|
|
124
|
+
if (key.startsWith("__"))
|
|
125
|
+
continue;
|
|
126
|
+
if (fullUpdate ||
|
|
127
|
+
Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
128
|
+
obj[key] = initObject[key];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
/* -------------------------------------------------------------------------- */
|
|
135
|
+
static getValue(o, key, original = false) {
|
|
136
|
+
if (o == null)
|
|
137
|
+
return undefined;
|
|
138
|
+
if (o instanceof SimpleObject && typeof o.getValue === "function")
|
|
139
|
+
return o.getValue(key, original);
|
|
140
|
+
if (!original &&
|
|
141
|
+
o.__use_delta != false &&
|
|
142
|
+
typeof o.__delta === "object" &&
|
|
143
|
+
key in o.__delta) {
|
|
144
|
+
//@ts-ignore
|
|
145
|
+
return o.__delta[key];
|
|
146
|
+
}
|
|
147
|
+
return o[key];
|
|
148
|
+
}
|
|
149
|
+
getValue = this.#getProperty;
|
|
150
|
+
get = this.#getProperty;
|
|
151
|
+
getTemp = this.#getTempProperty;
|
|
57
152
|
/**
|
|
58
|
-
* set
|
|
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
|
|
153
|
+
* set value
|
|
103
154
|
* @param key
|
|
104
155
|
* @param value
|
|
105
|
-
* @
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
156
|
+
* @return true if changed , false otherwise
|
|
157
|
+
*/
|
|
158
|
+
async setValue(key, value, sendChanges = "auto") {
|
|
159
|
+
if (!this.canModify) {
|
|
160
|
+
if (this.__throw_errors !== false)
|
|
161
|
+
throw Error("Cant use setValue when on readonly mode");
|
|
162
|
+
else
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
let isValueChanged = false;
|
|
166
|
+
try {
|
|
167
|
+
const oldval = this.getValue(key);
|
|
168
|
+
if (!object_equals(oldval, value, { ignoredStartingWords: "_" })) {
|
|
169
|
+
this.#setProperty(key, value);
|
|
170
|
+
isValueChanged = true;
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
isValueChanged = false;
|
|
174
|
+
//console.log("SV:", isValueChanged, oldval, key, value);
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
if (sendChanges === true ||
|
|
178
|
+
(sendChanges === "auto" && isValueChanged)) {
|
|
179
|
+
await this.notifyChanged("", String(key), value);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return isValueChanged;
|
|
183
|
+
}
|
|
184
|
+
set = this.setValue;
|
|
185
|
+
setTemp = this.#setTempProperty;
|
|
132
186
|
/**
|
|
133
|
-
* set value
|
|
187
|
+
* set value of a key only if the value is empty
|
|
134
188
|
* @param key
|
|
135
189
|
* @param value
|
|
136
|
-
* @
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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:
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
setDefaultValue(key, value) {
|
|
193
|
+
return this.#setDefaultProperty(key, value);
|
|
194
|
+
}
|
|
196
195
|
/**
|
|
197
196
|
* set value of a key only if the value is empty
|
|
198
197
|
* @param key
|
|
199
198
|
* @param value
|
|
200
199
|
* @returns
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
|
-
return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
|
|
204
|
-
}
|
|
205
|
-
}, {
|
|
206
|
-
key: "reset",
|
|
207
|
-
value:
|
|
200
|
+
*/
|
|
201
|
+
setDefault = this.setDefaultValue;
|
|
208
202
|
/**
|
|
209
203
|
* set the value to its original
|
|
210
204
|
* @param key
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
}()
|
|
205
|
+
*/
|
|
206
|
+
async reset(key, notifyChanged = "auto") {
|
|
207
|
+
return await this.setValue(key, this[key], notifyChanged);
|
|
208
|
+
}
|
|
235
209
|
/**
|
|
236
210
|
* reset all values back to their original
|
|
237
211
|
* @param key
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
}()
|
|
212
|
+
*/
|
|
213
|
+
async resetAll(notifyChanged = "auto") {
|
|
214
|
+
let fr = true;
|
|
215
|
+
for (const key in this.__delta) {
|
|
216
|
+
fr = fr && (await this.reset(key, notifyChanged));
|
|
217
|
+
}
|
|
218
|
+
return fr;
|
|
219
|
+
}
|
|
285
220
|
/**
|
|
286
221
|
* set key of subObject
|
|
287
222
|
* @param key
|
|
288
223
|
* @param value
|
|
289
224
|
* @param subvalue
|
|
290
225
|
* @return true if changed , false otherwise
|
|
291
|
-
*/
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
}()
|
|
226
|
+
*/
|
|
227
|
+
async setSubValue(key, objKey, subvalue, sendChanges = "auto") {
|
|
228
|
+
if (!this.canModify) {
|
|
229
|
+
if (this.__throw_errors !== false)
|
|
230
|
+
throw Error("Cant use setValue when on readonly mode");
|
|
231
|
+
else
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
let isValueChanged = false;
|
|
235
|
+
try {
|
|
236
|
+
//if accessing subval of an object, make sure the object is not null
|
|
237
|
+
const subval = this.#getSubProperty(key, objKey);
|
|
238
|
+
if (!object_equals(subval, subvalue, {
|
|
239
|
+
ignoredStartingWords: "_",
|
|
240
|
+
})) {
|
|
241
|
+
this.#setSubProperty(key, objKey, subvalue);
|
|
242
|
+
isValueChanged = true;
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
isValueChanged = false;
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
if (sendChanges === true ||
|
|
249
|
+
(sendChanges === "auto" && isValueChanged)) {
|
|
250
|
+
await this.notifyChanged("", String(key), objKey, subvalue);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return isValueChanged;
|
|
254
|
+
}
|
|
349
255
|
/**
|
|
350
256
|
* Push value on array
|
|
351
257
|
* @param key
|
|
352
258
|
* @param value
|
|
353
259
|
* @param sendChanges
|
|
354
260
|
* @returns
|
|
355
|
-
*/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
}()
|
|
261
|
+
*/
|
|
262
|
+
async pushValue(key, value, sendChanges = "auto") {
|
|
263
|
+
if (value == null)
|
|
264
|
+
return false;
|
|
265
|
+
if (!this.canModify) {
|
|
266
|
+
if (this.__throw_errors !== false)
|
|
267
|
+
throw Error("Cant use pushValue when on readonly mode");
|
|
268
|
+
else
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (this.#getProperty(key) == null) {
|
|
272
|
+
this.#setProperty(key, []);
|
|
273
|
+
}
|
|
274
|
+
let tempArray = this.#getProperty(key);
|
|
275
|
+
if (!Array.isArray(tempArray)) {
|
|
276
|
+
if (this.__throw_errors !== false)
|
|
277
|
+
throw Error("Cant use pushValue on non Array keys");
|
|
278
|
+
else
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
this.#setProperty(key, [...tempArray, value]);
|
|
282
|
+
if (sendChanges === true || sendChanges === "auto") {
|
|
283
|
+
await this.notifyChanged("", String(key), value);
|
|
284
|
+
}
|
|
285
|
+
return tempArray;
|
|
286
|
+
}
|
|
421
287
|
/**
|
|
422
288
|
* notify the manager class when a value is changed on this object
|
|
423
289
|
* @param type
|
|
424
290
|
* @param key
|
|
425
291
|
* @param value
|
|
426
292
|
* @param subvalue
|
|
427
|
-
*/
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
}()
|
|
293
|
+
*/
|
|
294
|
+
async notifyChanged(type, key, value, subvalue) {
|
|
295
|
+
if (value === undefined && type != "meta")
|
|
296
|
+
value = this.getValue(key);
|
|
297
|
+
this.__changed = true;
|
|
298
|
+
let lc = "";
|
|
299
|
+
if (type)
|
|
300
|
+
lc += `$${String(type)}$`;
|
|
301
|
+
if (subvalue) {
|
|
302
|
+
lc += `${String(key)}.${value}`;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
lc += `${String(key)}`;
|
|
306
|
+
}
|
|
307
|
+
this.__lastChanged = lc;
|
|
308
|
+
/* --------------------------- notify the manager --------------------------- */
|
|
309
|
+
const manager_class = this.manager;
|
|
310
|
+
if (manager_class instanceof ObjectManager) {
|
|
311
|
+
await manager_class.notifyChanged(type, key, value, subvalue);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
465
314
|
/**
|
|
466
315
|
* check if a key can be changed on an object
|
|
467
316
|
* @param object
|
|
468
317
|
* @param key
|
|
469
318
|
* @param useExtraProps
|
|
470
319
|
* @returns
|
|
471
|
-
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
320
|
+
*/
|
|
321
|
+
static canChangeKey(object, key, useExtraProps) {
|
|
322
|
+
if (!object || !key)
|
|
323
|
+
return false;
|
|
324
|
+
if (useExtraProps) {
|
|
325
|
+
const __extraProperties = object.constructor["__extraProperties"];
|
|
326
|
+
if (__extraProperties != null && __extraProperties.includes(key))
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
const __changeables = object.constructor["__changeables"];
|
|
330
|
+
const __unchangeables = object.constructor["__unchangeables"];
|
|
331
|
+
if (__changeables != null && !__changeables.includes(key))
|
|
332
|
+
return false;
|
|
333
|
+
if (__unchangeables != null && __unchangeables.includes(key))
|
|
334
|
+
return false;
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
/* -------------------------------------------------------------------------- */
|
|
338
|
+
/* Changes */
|
|
339
|
+
/* -------------------------------------------------------------------------- */
|
|
477
340
|
/**
|
|
478
341
|
* Apply the changes and empty the delta object
|
|
479
|
-
*/
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
342
|
+
*/
|
|
343
|
+
apply_changes() {
|
|
344
|
+
try {
|
|
345
|
+
if (!this.__use_delta) {
|
|
346
|
+
//in this mode , we track changes by updating the original product
|
|
347
|
+
this.setOriginal();
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
if (!this.isChanged) {
|
|
351
|
+
console.warn("No changes to apply");
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
for (const key in this.__delta) {
|
|
355
|
+
const nv = this.__delta[key];
|
|
356
|
+
this[key] = nv;
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
this.clear_changes();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
500
364
|
/**
|
|
501
365
|
* clear and discard all changes
|
|
502
366
|
* @returns
|
|
503
|
-
*/
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
return true;
|
|
510
|
-
}
|
|
367
|
+
*/
|
|
368
|
+
clear_changes() {
|
|
369
|
+
this.__delta = {};
|
|
370
|
+
this.__changed = false;
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
511
373
|
/**
|
|
512
374
|
* clear and discard all temp values
|
|
513
375
|
* @returns
|
|
514
|
-
*/
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return true;
|
|
520
|
-
}
|
|
376
|
+
*/
|
|
377
|
+
clear_cache() {
|
|
378
|
+
delete this.__temp;
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
521
381
|
/**
|
|
522
382
|
* Sets readonly property on given objects
|
|
523
383
|
* @param objs array of given objects or a single object
|
|
524
384
|
* @param readonlyval readonly
|
|
525
385
|
* @param clearChanges should we clean the changes after setting readonly
|
|
526
|
-
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
return;
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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
|
-
/* -------------------------------------------------------------------------- */
|
|
386
|
+
*/
|
|
387
|
+
static setReadonly(objs, readonlyval = true, clearChanges = false) {
|
|
388
|
+
let checkObjs = [];
|
|
389
|
+
if (!objs)
|
|
390
|
+
objs = [];
|
|
391
|
+
if (!Array.isArray(objs))
|
|
392
|
+
checkObjs = [objs];
|
|
393
|
+
else
|
|
394
|
+
checkObjs = objs;
|
|
395
|
+
for (let index = 0; index < checkObjs.length; index++) {
|
|
396
|
+
const obj = checkObjs[index];
|
|
397
|
+
obj.__is_readonly = readonlyval;
|
|
398
|
+
if (obj instanceof SimpleObject) {
|
|
399
|
+
if (obj.canModify) {
|
|
400
|
+
if (!obj.getOriginal())
|
|
401
|
+
obj.setOriginal();
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
if (clearChanges)
|
|
405
|
+
obj.clear_changes();
|
|
406
|
+
//we dont need the original object in readonly mode
|
|
407
|
+
obj.setOriginal(null);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
static setThrowErrors(objs, throwErr = true) {
|
|
413
|
+
let checkObjs = [];
|
|
414
|
+
if (!objs)
|
|
415
|
+
objs = [];
|
|
416
|
+
if (!Array.isArray(objs))
|
|
417
|
+
checkObjs = [objs];
|
|
418
|
+
else
|
|
419
|
+
checkObjs = objs;
|
|
420
|
+
for (let index = 0; index < checkObjs.length; index++) {
|
|
421
|
+
const element = checkObjs[index];
|
|
422
|
+
element.__throw_errors = throwErr;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/* -------------------------------------------------------------------------- */
|
|
426
|
+
/* Get/Check */
|
|
427
|
+
/* -------------------------------------------------------------------------- */
|
|
428
|
+
get isChanged() {
|
|
429
|
+
////const deltaIsBlank = object_isEmpty(this.__delta);
|
|
430
|
+
////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
|
|
431
|
+
////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
|
|
432
|
+
if (this.__use_delta)
|
|
433
|
+
return !object_isEmpty(this.__delta);
|
|
434
|
+
/* -------------------------------------------------------------------------- */
|
|
435
|
+
/* check the properties one by one */
|
|
436
|
+
/* -------------------------------------------------------------------------- */
|
|
437
|
+
const orig = this.getOriginal();
|
|
438
|
+
if (!orig)
|
|
439
|
+
return false; //we dont know if anything has changed
|
|
440
|
+
/* if object is not using delta mode, check changes by comparing changable fields with original object */
|
|
441
|
+
if (Array.isArray(this.__changeables)) {
|
|
442
|
+
//console.log("chk", this.__changeables, "for changes");
|
|
443
|
+
return (this.__changeables.find((c) => {
|
|
444
|
+
return !object_equals(this[c], orig[c]);
|
|
445
|
+
}) != undefined);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
/* check all fields */
|
|
449
|
+
for (const key in this) {
|
|
450
|
+
if (key.startsWith("__"))
|
|
451
|
+
continue;
|
|
452
|
+
if (!object_equals(this[key], orig[key]))
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
get isDeleted() {
|
|
460
|
+
return this._deleted || false;
|
|
461
|
+
}
|
|
462
|
+
set isDeleted(v) {
|
|
463
|
+
this._deleted = v;
|
|
464
|
+
}
|
|
465
|
+
get d() {
|
|
466
|
+
return this.__use_delta ? this.__delta : this;
|
|
467
|
+
}
|
|
468
|
+
/* all updated properties */
|
|
469
|
+
get allproperties() {
|
|
470
|
+
const result = { ...this, ...this.__delta };
|
|
471
|
+
result.__delta = {};
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
get canModify() {
|
|
475
|
+
return !Boolean(this.__is_readonly);
|
|
476
|
+
}
|
|
477
|
+
get __cache_name() {
|
|
478
|
+
return this.constructor["__cache_name"];
|
|
479
|
+
}
|
|
480
|
+
get __changeables() {
|
|
481
|
+
return this.constructor["__changeables"];
|
|
482
|
+
}
|
|
483
|
+
get __unchangeables() {
|
|
484
|
+
return this.constructor["__unchangeables"];
|
|
485
|
+
}
|
|
486
|
+
get __use_delta() {
|
|
487
|
+
return this.constructor["__use_delta"];
|
|
488
|
+
}
|
|
489
|
+
get isSaved() {
|
|
490
|
+
return Boolean(this.__saveResultIsSuccess ?? false);
|
|
491
|
+
}
|
|
492
|
+
get isNew() {
|
|
493
|
+
const mid = this.getID();
|
|
494
|
+
if (!mid)
|
|
495
|
+
return true;
|
|
496
|
+
if (typeof mid === "string")
|
|
497
|
+
return mid === "" || mid === "-1";
|
|
498
|
+
if (typeof mid === "number")
|
|
499
|
+
return mid === -1;
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
get lastChanged() {
|
|
503
|
+
return this.__lastChanged || "";
|
|
504
|
+
}
|
|
505
|
+
get manager() {
|
|
506
|
+
return this.#get_managerClass() || undefined;
|
|
507
|
+
}
|
|
508
|
+
#get_managerClass = () => undefined;
|
|
509
|
+
set_managerClass(mng) {
|
|
510
|
+
if ((mng instanceof ObjectManager || mng instanceof WebObjectManager) &&
|
|
511
|
+
typeof mng.event_run === "function")
|
|
512
|
+
this.#get_managerClass = () => mng;
|
|
513
|
+
else {
|
|
514
|
+
console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
static isDeleted(obj) {
|
|
518
|
+
if (obj instanceof SimpleObject)
|
|
519
|
+
return obj.isDeleted === true;
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
getIndexOrID() {
|
|
523
|
+
return SimpleObject.getIndexOrID(this);
|
|
524
|
+
}
|
|
525
|
+
getIndex() {
|
|
526
|
+
return SimpleObject.getIndex(this);
|
|
527
|
+
}
|
|
528
|
+
getID() {
|
|
529
|
+
return SimpleObject.getID(this);
|
|
530
|
+
}
|
|
531
|
+
static getIndexOrID(o) {
|
|
532
|
+
let res = SimpleObject.getIndex(o);
|
|
533
|
+
if (!res || res == -1)
|
|
534
|
+
res = SimpleObject.getID(o);
|
|
535
|
+
return res || -1;
|
|
536
|
+
}
|
|
537
|
+
static getIndex(o) {
|
|
538
|
+
if (o == null || o == undefined)
|
|
539
|
+
return -1;
|
|
540
|
+
switch (typeof o) {
|
|
541
|
+
case "object":
|
|
542
|
+
return o._index_value || -1;
|
|
543
|
+
case "number":
|
|
544
|
+
case "string":
|
|
545
|
+
return Number(o);
|
|
546
|
+
}
|
|
547
|
+
return -1;
|
|
548
|
+
}
|
|
549
|
+
static getID(o) {
|
|
550
|
+
if (o == null || o == undefined)
|
|
551
|
+
return "";
|
|
552
|
+
switch (typeof o) {
|
|
553
|
+
case "object":
|
|
554
|
+
if (o._bsontype == "ObjectID" &&
|
|
555
|
+
typeof o.toString === "function") {
|
|
556
|
+
return o.toString();
|
|
557
|
+
}
|
|
558
|
+
return String(o._id || o.ID || o.id || o.__data_id || "");
|
|
559
|
+
case "string":
|
|
560
|
+
case "number":
|
|
561
|
+
return String(o);
|
|
562
|
+
}
|
|
563
|
+
return "";
|
|
564
|
+
}
|
|
565
|
+
/* -------------------------------------------------------------------------- */
|
|
566
|
+
/* Original */
|
|
567
|
+
/* -------------------------------------------------------------------------- */
|
|
568
|
+
getOriginal() {
|
|
569
|
+
return this.__originalobject || undefined;
|
|
570
|
+
}
|
|
571
|
+
setOriginal(toObj = 0) {
|
|
572
|
+
if (toObj === null) {
|
|
573
|
+
delete this.__originalobject;
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (!this.canModify) {
|
|
577
|
+
console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
|
|
578
|
+
delete this.__originalobject;
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (toObj === 0) {
|
|
582
|
+
toObj = this;
|
|
583
|
+
}
|
|
584
|
+
const cloneObject = object_clone(toObj);
|
|
585
|
+
SimpleObject.setReadonly(cloneObject, true);
|
|
586
|
+
this.__originalobject = object_removeKeys(cloneObject, ["__"]);
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
static setOriginal(obj, toObj = 0) {
|
|
590
|
+
if (!(obj instanceof SimpleObject))
|
|
591
|
+
return undefined;
|
|
592
|
+
return obj.setOriginal(toObj);
|
|
593
|
+
}
|
|
594
|
+
static getOriginal(obj) {
|
|
595
|
+
if (obj instanceof SimpleObject)
|
|
596
|
+
return obj.getOriginal();
|
|
597
|
+
return obj?.__originalobject;
|
|
598
|
+
}
|
|
599
|
+
/* -------------------------------------------------------------------------- */
|
|
600
|
+
/* Errors */
|
|
601
|
+
/* -------------------------------------------------------------------------- */
|
|
602
|
+
static addError(o, title, message, sendToRegister = "auto") {
|
|
603
|
+
const errStr = combine_if_not_blank(title, " : ", message);
|
|
604
|
+
if (o) {
|
|
605
|
+
if (!Array.isArray(o.__errors))
|
|
606
|
+
o.__errors = [];
|
|
607
|
+
o.__errors.push(errStr);
|
|
608
|
+
if (o.__showErrors === false)
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
else if (sendToRegister === "auto")
|
|
612
|
+
sendToRegister = true;
|
|
613
|
+
if (sendToRegister === true) {
|
|
614
|
+
console.error("[REGISTER-ERROR]", errStr);
|
|
615
|
+
gfunc.run_action("add_error", {
|
|
616
|
+
title: title,
|
|
617
|
+
message: message,
|
|
618
|
+
type: "error",
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
console.error("[ERROR]", errStr);
|
|
623
|
+
}
|
|
624
|
+
return o?.__errors || [];
|
|
625
|
+
}
|
|
626
|
+
static getErrors(o) {
|
|
627
|
+
return o?.__errors || [];
|
|
628
|
+
}
|
|
629
|
+
static clearErrors(o) {
|
|
630
|
+
if (o)
|
|
631
|
+
o.__errors = [];
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
/* -------------------------------------------------------------------------- */
|
|
635
|
+
/* Save Results */
|
|
636
|
+
/* -------------------------------------------------------------------------- */
|
|
893
637
|
/**
|
|
894
638
|
* Checks if the given object is a valid and truthy save result
|
|
895
639
|
* @param result_object
|
|
896
640
|
* @returns
|
|
897
|
-
*/
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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) {
|
|
641
|
+
*/
|
|
642
|
+
static isResultValid(result_object, sub = false) {
|
|
643
|
+
if (object_isEmpty(result_object))
|
|
644
|
+
return false;
|
|
645
|
+
switch (typeof result_object) {
|
|
646
|
+
case "string":
|
|
647
|
+
try {
|
|
648
|
+
result_object = JSON.parse(result_object);
|
|
649
|
+
return this.isResultValid(result_object);
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
case "object":
|
|
655
|
+
if (object_isTrue(result_object.acknowledged)) {
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
if (result_object.expected && result_object.result) {
|
|
659
|
+
return object_equals(result_object.expected, result_object.result);
|
|
660
|
+
}
|
|
661
|
+
return Number(this.getID(result_object)) >= 0;
|
|
662
|
+
case "number":
|
|
663
|
+
return result_object > 0;
|
|
664
|
+
case "boolean":
|
|
665
|
+
return result_object === true;
|
|
666
|
+
}
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* set the response of last save from site
|
|
671
|
+
* and its type
|
|
672
|
+
* @param toObj
|
|
673
|
+
*/
|
|
674
|
+
setSaveResult(toObj, type) {
|
|
675
|
+
if (toObj != null) {
|
|
676
|
+
this.#setSaveResultObject(toObj);
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
this.#setSaveResultObject(null);
|
|
680
|
+
}
|
|
681
|
+
//check if the given object is a valid save result
|
|
682
|
+
if (type === "error")
|
|
683
|
+
this.__saveResultIsSuccess = false;
|
|
684
|
+
else
|
|
685
|
+
this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
|
|
686
|
+
if (type === "auto") {
|
|
687
|
+
type = this.__saveResultIsSuccess ? "normal" : "error";
|
|
688
|
+
}
|
|
689
|
+
this.__saveResultType = type;
|
|
690
|
+
}
|
|
971
691
|
/**
|
|
972
|
-
*
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
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;
|
|
692
|
+
* set the response of last save from site
|
|
693
|
+
* @param toObj
|
|
694
|
+
*/
|
|
695
|
+
#setSaveResultObject(toObj) {
|
|
696
|
+
this.__saveResultObject = toObj;
|
|
697
|
+
}
|
|
698
|
+
getSaveResult(original = false) {
|
|
699
|
+
if (this.isSaved)
|
|
700
|
+
return this.__saveResultObject;
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
getSaveResultType() {
|
|
704
|
+
return this.__saveResultType || "nothing";
|
|
705
|
+
}
|
|
706
|
+
/* -------------------------------------------------------------------------- */
|
|
707
|
+
/* statics */
|
|
708
|
+
/* -------------------------------------------------------------------------- */
|
|
709
|
+
static factoryClear(obj) {
|
|
710
|
+
obj.clear_changes();
|
|
711
|
+
SimpleObject.clearErrors(obj);
|
|
712
|
+
}
|
|
713
|
+
static delete_cache() {
|
|
714
|
+
if (!this.__cache_name)
|
|
715
|
+
return;
|
|
716
|
+
gcache.delete_cache(this.__cache_name);
|
|
717
|
+
}
|
|
718
|
+
static get_canModify(o) {
|
|
719
|
+
if (o instanceof SimpleObject)
|
|
720
|
+
return o.canModify;
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
/* -------------------------------------------------------------------------- */
|
|
724
|
+
static equals(a, b) {
|
|
725
|
+
console.warn("Dont use the default equals method !");
|
|
726
|
+
if (a == undefined || b == undefined)
|
|
727
|
+
return false;
|
|
728
|
+
return a === b;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
export default SimpleObject;
|