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