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