@azrico/webobject 1.4.162 → 1.4.163
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.d.ts +1 -0
- package/dist/index.js +16 -0
- package/dist/src/WebObjects/ParentWebObject.d.ts +24 -0
- package/dist/src/WebObjects/ParentWebObject.js +121 -0
- package/dist/src/WebObjects/WebObject.d.ts +120 -0
- package/dist/src/WebObjects/WebObject.js +1319 -0
- package/dist/src/WebObjects/WebObjectManager.d.ts +65 -0
- package/dist/src/WebObjects/WebObjectManager.js +806 -0
- package/dist/src/WebObjects/WebObjectPathHelper.d.ts +36 -0
- package/dist/src/WebObjects/WebObjectPathHelper.js +155 -0
- package/dist/src/WebObjects/WebObjectPathHelper.test.d.ts +1 -0
- package/dist/src/WebObjects/WebObjectPathHelper.test.js +122 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +115 -0
- package/dist/src/structs/DummyObject.d.ts +5 -0
- package/dist/src/structs/DummyObject.js +32 -0
- package/dist/src/structs/MapableObject.d.ts +43 -0
- package/dist/src/structs/MapableObject.js +123 -0
- package/dist/src/structs/MetaObject.d.ts +15 -0
- package/dist/src/structs/MetaObject.js +121 -0
- package/dist/src/structs/ObjectArray.d.ts +10 -0
- package/dist/src/structs/ObjectArray.js +68 -0
- package/dist/src/structs/ObjectManager.d.ts +123 -0
- package/dist/src/structs/ObjectManager.js +737 -0
- package/dist/src/structs/ObjectWithTemp.d.ts +11 -0
- package/dist/src/structs/ObjectWithTemp.js +66 -0
- package/dist/src/structs/SimpleObject.d.ts +266 -0
- package/dist/src/structs/SimpleObject.js +1586 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1586 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.SimpleObject = void 0;
|
|
7
|
+
var _object = require("@azrico/object");
|
|
8
|
+
var _string = require("@azrico/string");
|
|
9
|
+
var _global = require("@azrico/global");
|
|
10
|
+
var _MapableObject2 = require("./MapableObject");
|
|
11
|
+
var _ObjectManager = _interopRequireDefault(require("./ObjectManager"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
|
+
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
17
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
18
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
22
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
24
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
27
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
28
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
29
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
30
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
32
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
33
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
34
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
35
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
36
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
37
|
+
var _SimpleObject_brand = /*#__PURE__*/new WeakSet();
|
|
38
|
+
var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
39
|
+
function SimpleObject() {
|
|
40
|
+
var _this;
|
|
41
|
+
var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
42
|
+
_classCallCheck(this, SimpleObject);
|
|
43
|
+
_this = _callSuper(this, SimpleObject);
|
|
44
|
+
_classPrivateMethodInitSpec(_this, _SimpleObject_brand);
|
|
45
|
+
//an exact copy of this object is stored here
|
|
46
|
+
_defineProperty(_this, "__originalobject", void 0);
|
|
47
|
+
//changes are saved here
|
|
48
|
+
_defineProperty(_this, "__delta", {});
|
|
49
|
+
_defineProperty(_this, "__changed", false);
|
|
50
|
+
//the last thing that was changed on this object
|
|
51
|
+
_defineProperty(_this, "__lastChanged", void 0);
|
|
52
|
+
//is the object read only
|
|
53
|
+
_defineProperty(_this, "__is_readonly", void 0);
|
|
54
|
+
//should we throw errors when encountering an error?
|
|
55
|
+
//is TRUE by default
|
|
56
|
+
_defineProperty(_this, "__throw_errors", void 0);
|
|
57
|
+
//is this object marked as deleted?
|
|
58
|
+
_defineProperty(_this, "_deleted", void 0);
|
|
59
|
+
_defineProperty(_this, "_archived", void 0);
|
|
60
|
+
_defineProperty(_this, "_deletedBy", void 0);
|
|
61
|
+
//is this object locked?
|
|
62
|
+
_defineProperty(_this, "_locked", void 0);
|
|
63
|
+
//errors
|
|
64
|
+
_defineProperty(_this, "__errors", void 0);
|
|
65
|
+
_defineProperty(_this, "__showErrors", void 0);
|
|
66
|
+
//refresh func
|
|
67
|
+
_defineProperty(_this, "__refresh_functions", void 0);
|
|
68
|
+
//save results
|
|
69
|
+
_defineProperty(_this, "__saveResultObject", void 0);
|
|
70
|
+
_defineProperty(_this, "__saveResultIsSuccess", true);
|
|
71
|
+
_defineProperty(_this, "__saveResultType", void 0);
|
|
72
|
+
_defineProperty(_this, "_id", "");
|
|
73
|
+
//sequence key (usually managed by the database)
|
|
74
|
+
_defineProperty(_this, "_index_key", "");
|
|
75
|
+
//sequence value , used to index the object with increasing numbers
|
|
76
|
+
_defineProperty(_this, "_index_value", -1);
|
|
77
|
+
_defineProperty(_this, "getValue", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
|
|
78
|
+
_defineProperty(_this, "get", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
|
|
79
|
+
/**
|
|
80
|
+
* set value
|
|
81
|
+
* @param key
|
|
82
|
+
* @param value
|
|
83
|
+
* @return true if changed , false otherwise
|
|
84
|
+
*/
|
|
85
|
+
_defineProperty(_this, "set", _this.setValue);
|
|
86
|
+
/**
|
|
87
|
+
* set value of a key to now date time
|
|
88
|
+
* @param key
|
|
89
|
+
* @param value
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
_defineProperty(_this, "setDefaultValueNow", _assertClassBrand(_SimpleObject_brand, _this, _setDefaultPropertyNow));
|
|
93
|
+
/**
|
|
94
|
+
* set value of a key only if the value is empty (null,undef,"")
|
|
95
|
+
* @param key
|
|
96
|
+
* @param value
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
_defineProperty(_this, "setDefault", _this.setDefaultValue);
|
|
100
|
+
_defineProperty(_this, "getSubValue", _assertClassBrand(_SimpleObject_brand, _this, _getSubProperty));
|
|
101
|
+
_defineProperty(_this, "get_managerClass", function () {
|
|
102
|
+
return undefined;
|
|
103
|
+
});
|
|
104
|
+
_this.__is_readonly = is_readonly;
|
|
105
|
+
if (_this._id) _this.__table_id = _this._id;
|
|
106
|
+
_this.clear_changes();
|
|
107
|
+
return _this;
|
|
108
|
+
}
|
|
109
|
+
_inherits(SimpleObject, _MapableObject);
|
|
110
|
+
return _createClass(SimpleObject, [{
|
|
111
|
+
key: "_static",
|
|
112
|
+
value: function _static() {
|
|
113
|
+
return this.constructor;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "loadValues",
|
|
117
|
+
value: /* -------------------------------------------------------------------------- */
|
|
118
|
+
/* Load */
|
|
119
|
+
/* -------------------------------------------------------------------------- */
|
|
120
|
+
/**
|
|
121
|
+
* load all properties in `initObject` into the current object
|
|
122
|
+
* @param initObject
|
|
123
|
+
* @param fullUpdate
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
function loadValues(initObject) {
|
|
127
|
+
var fullUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
128
|
+
return SimpleObject.loadValues(this, initObject, fullUpdate);
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "setValue",
|
|
132
|
+
value: (
|
|
133
|
+
/**
|
|
134
|
+
* set value
|
|
135
|
+
* @param key
|
|
136
|
+
* @param value
|
|
137
|
+
* @return true if changed , false otherwise
|
|
138
|
+
*/
|
|
139
|
+
function () {
|
|
140
|
+
var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
|
|
141
|
+
var shouldNotify,
|
|
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
|
+
shouldNotify = _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 (".concat(String(key), ") when on readonly mode"));
|
|
158
|
+
case 6:
|
|
159
|
+
return _context.abrupt("return", false);
|
|
160
|
+
case 7:
|
|
161
|
+
isValueChanged = false;
|
|
162
|
+
/* --------------------------- set if not changed --------------------------- */
|
|
163
|
+
oldval = this.getValue(key);
|
|
164
|
+
if (!(0, _object.object_equals)(oldval, value, {
|
|
165
|
+
strictArrayCheck: true,
|
|
166
|
+
ignoredStartingWords: "_"
|
|
167
|
+
})) {
|
|
168
|
+
_assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, value);
|
|
169
|
+
isValueChanged = true;
|
|
170
|
+
} else isValueChanged = false;
|
|
171
|
+
/* --------------------------------- notify --------------------------------- */
|
|
172
|
+
if (!(shouldNotify === true || shouldNotify === "auto" && isValueChanged)) {
|
|
173
|
+
_context.next = 13;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
_context.next = 13;
|
|
177
|
+
return this.notifyChanged("", key, value);
|
|
178
|
+
case 13:
|
|
179
|
+
return _context.abrupt("return", isValueChanged);
|
|
180
|
+
case 14:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee, this);
|
|
185
|
+
}));
|
|
186
|
+
function setValue(_x, _x2) {
|
|
187
|
+
return _setValue.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
return setValue;
|
|
190
|
+
}())
|
|
191
|
+
}, {
|
|
192
|
+
key: "setTemp",
|
|
193
|
+
value: function () {
|
|
194
|
+
var _setTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
|
|
195
|
+
var sendChanges,
|
|
196
|
+
isValueChanged,
|
|
197
|
+
_args2 = arguments;
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
199
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
200
|
+
case 0:
|
|
201
|
+
sendChanges = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
|
|
202
|
+
_context2.next = 3;
|
|
203
|
+
return _get(_getPrototypeOf(SimpleObject.prototype), "setTemp", this).call(this, key, value);
|
|
204
|
+
case 3:
|
|
205
|
+
isValueChanged = _context2.sent;
|
|
206
|
+
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
207
|
+
_context2.next = 7;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
_context2.next = 7;
|
|
211
|
+
return this.notifyChanged("temp", key, value);
|
|
212
|
+
case 7:
|
|
213
|
+
return _context2.abrupt("return", isValueChanged);
|
|
214
|
+
case 8:
|
|
215
|
+
case "end":
|
|
216
|
+
return _context2.stop();
|
|
217
|
+
}
|
|
218
|
+
}, _callee2, this);
|
|
219
|
+
}));
|
|
220
|
+
function setTemp(_x3, _x4) {
|
|
221
|
+
return _setTemp.apply(this, arguments);
|
|
222
|
+
}
|
|
223
|
+
return setTemp;
|
|
224
|
+
}() /* ---------------------------- refresh functions --------------------------- */
|
|
225
|
+
}, {
|
|
226
|
+
key: "clearRefreshFunction",
|
|
227
|
+
value: (function () {
|
|
228
|
+
var _clearRefreshFunction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
229
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
230
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
231
|
+
case 0:
|
|
232
|
+
this.__refresh_functions = undefined;
|
|
233
|
+
case 1:
|
|
234
|
+
case "end":
|
|
235
|
+
return _context3.stop();
|
|
236
|
+
}
|
|
237
|
+
}, _callee3, this);
|
|
238
|
+
}));
|
|
239
|
+
function clearRefreshFunction() {
|
|
240
|
+
return _clearRefreshFunction.apply(this, arguments);
|
|
241
|
+
}
|
|
242
|
+
return clearRefreshFunction;
|
|
243
|
+
}())
|
|
244
|
+
}, {
|
|
245
|
+
key: "setRefreshFunction",
|
|
246
|
+
value: function () {
|
|
247
|
+
var _setRefreshFunction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(new_fnc) {
|
|
248
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
249
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
250
|
+
case 0:
|
|
251
|
+
_context4.next = 2;
|
|
252
|
+
return this.addRefreshFunction(new_fnc);
|
|
253
|
+
case 2:
|
|
254
|
+
return _context4.abrupt("return", _context4.sent);
|
|
255
|
+
case 3:
|
|
256
|
+
case "end":
|
|
257
|
+
return _context4.stop();
|
|
258
|
+
}
|
|
259
|
+
}, _callee4, this);
|
|
260
|
+
}));
|
|
261
|
+
function setRefreshFunction(_x5) {
|
|
262
|
+
return _setRefreshFunction.apply(this, arguments);
|
|
263
|
+
}
|
|
264
|
+
return setRefreshFunction;
|
|
265
|
+
}()
|
|
266
|
+
}, {
|
|
267
|
+
key: "addRefreshFunction",
|
|
268
|
+
value: function () {
|
|
269
|
+
var _addRefreshFunction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, new_fnc) {
|
|
270
|
+
var oldFunctions;
|
|
271
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
272
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
273
|
+
case 0:
|
|
274
|
+
if (typeof key === "function") {
|
|
275
|
+
new_fnc = key;
|
|
276
|
+
key = "main";
|
|
277
|
+
}
|
|
278
|
+
key = key || "main";
|
|
279
|
+
oldFunctions = this.__refresh_functions;
|
|
280
|
+
if (oldFunctions == null || _typeof(oldFunctions) !== "object") oldFunctions = {};
|
|
281
|
+
oldFunctions[key] = new_fnc;
|
|
282
|
+
this.__refresh_functions = oldFunctions;
|
|
283
|
+
case 6:
|
|
284
|
+
case "end":
|
|
285
|
+
return _context5.stop();
|
|
286
|
+
}
|
|
287
|
+
}, _callee5, this);
|
|
288
|
+
}));
|
|
289
|
+
function addRefreshFunction(_x6, _x7) {
|
|
290
|
+
return _addRefreshFunction.apply(this, arguments);
|
|
291
|
+
}
|
|
292
|
+
return addRefreshFunction;
|
|
293
|
+
}()
|
|
294
|
+
}, {
|
|
295
|
+
key: "runRefreshFunction",
|
|
296
|
+
value: function () {
|
|
297
|
+
var _runRefreshFunction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
298
|
+
var oldFunctions,
|
|
299
|
+
fncArray,
|
|
300
|
+
_len,
|
|
301
|
+
params,
|
|
302
|
+
_key,
|
|
303
|
+
index,
|
|
304
|
+
fnc,
|
|
305
|
+
_args6 = arguments;
|
|
306
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
307
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
308
|
+
case 0:
|
|
309
|
+
oldFunctions = this.__refresh_functions;
|
|
310
|
+
if (!(oldFunctions == null || _typeof(oldFunctions) !== "object")) {
|
|
311
|
+
_context6.next = 3;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
return _context6.abrupt("return");
|
|
315
|
+
case 3:
|
|
316
|
+
fncArray = Object.values(oldFunctions);
|
|
317
|
+
for (_len = _args6.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
318
|
+
params[_key] = _args6[_key];
|
|
319
|
+
}
|
|
320
|
+
index = 0;
|
|
321
|
+
case 6:
|
|
322
|
+
if (!(index < fncArray.length)) {
|
|
323
|
+
_context6.next = 13;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
fnc = fncArray[index];
|
|
327
|
+
_context6.next = 10;
|
|
328
|
+
return _object.fn_eval.apply(void 0, [fnc].concat(params));
|
|
329
|
+
case 10:
|
|
330
|
+
index++;
|
|
331
|
+
_context6.next = 6;
|
|
332
|
+
break;
|
|
333
|
+
case 13:
|
|
334
|
+
case "end":
|
|
335
|
+
return _context6.stop();
|
|
336
|
+
}
|
|
337
|
+
}, _callee6, this);
|
|
338
|
+
}));
|
|
339
|
+
function runRefreshFunction() {
|
|
340
|
+
return _runRefreshFunction.apply(this, arguments);
|
|
341
|
+
}
|
|
342
|
+
return runRefreshFunction;
|
|
343
|
+
}()
|
|
344
|
+
/* -------------------------------------------------------------------------- */
|
|
345
|
+
/**
|
|
346
|
+
* calls `setValue` function for all props of `setObj`
|
|
347
|
+
* @param setObj
|
|
348
|
+
* @param changeablesOnly only updates the `__changeables` fields
|
|
349
|
+
* @returns
|
|
350
|
+
*/
|
|
351
|
+
}, {
|
|
352
|
+
key: "setAll",
|
|
353
|
+
value: (function () {
|
|
354
|
+
var _setAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(setObj) {
|
|
355
|
+
var changeablesOnly,
|
|
356
|
+
finalRes,
|
|
357
|
+
checkKeys,
|
|
358
|
+
index,
|
|
359
|
+
key,
|
|
360
|
+
_args7 = arguments;
|
|
361
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
362
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
363
|
+
case 0:
|
|
364
|
+
changeablesOnly = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
|
|
365
|
+
finalRes = true;
|
|
366
|
+
checkKeys = changeablesOnly ? (0, _object.array_intersection)(this.__changeables, Object.keys(setObj)) : Object.keys(setObj);
|
|
367
|
+
index = 0;
|
|
368
|
+
case 4:
|
|
369
|
+
if (!(index < checkKeys.length)) {
|
|
370
|
+
_context7.next = 13;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
key = checkKeys[index];
|
|
374
|
+
_context7.next = 8;
|
|
375
|
+
return this.setValue(key, setObj[key]);
|
|
376
|
+
case 8:
|
|
377
|
+
if (_context7.sent) {
|
|
378
|
+
_context7.next = 10;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
finalRes = false;
|
|
382
|
+
case 10:
|
|
383
|
+
index++;
|
|
384
|
+
_context7.next = 4;
|
|
385
|
+
break;
|
|
386
|
+
case 13:
|
|
387
|
+
return _context7.abrupt("return", finalRes);
|
|
388
|
+
case 14:
|
|
389
|
+
case "end":
|
|
390
|
+
return _context7.stop();
|
|
391
|
+
}
|
|
392
|
+
}, _callee7, this);
|
|
393
|
+
}));
|
|
394
|
+
function setAll(_x8) {
|
|
395
|
+
return _setAll.apply(this, arguments);
|
|
396
|
+
}
|
|
397
|
+
return setAll;
|
|
398
|
+
}()
|
|
399
|
+
/**
|
|
400
|
+
* set value of a key only if the value is empty (null,undef,"")
|
|
401
|
+
* @param key
|
|
402
|
+
* @param value
|
|
403
|
+
* @returns
|
|
404
|
+
*/
|
|
405
|
+
)
|
|
406
|
+
}, {
|
|
407
|
+
key: "setDefaultValue",
|
|
408
|
+
value: function setDefaultValue(key, value) {
|
|
409
|
+
return _assertClassBrand(_SimpleObject_brand, this, _setDefaultProperty).call(this, key, value);
|
|
410
|
+
}
|
|
411
|
+
}, {
|
|
412
|
+
key: "setSubValue",
|
|
413
|
+
value: (
|
|
414
|
+
/**
|
|
415
|
+
* set key of subObject
|
|
416
|
+
* @param key
|
|
417
|
+
* @param value
|
|
418
|
+
* @param subvalue
|
|
419
|
+
* @return true if changed , false otherwise
|
|
420
|
+
*/
|
|
421
|
+
function () {
|
|
422
|
+
var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(key, objKey, subvalue) {
|
|
423
|
+
var sendChanges,
|
|
424
|
+
isValueChanged,
|
|
425
|
+
subval,
|
|
426
|
+
_args8 = arguments;
|
|
427
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
428
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
429
|
+
case 0:
|
|
430
|
+
sendChanges = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : "auto";
|
|
431
|
+
if (this.canModify) {
|
|
432
|
+
_context8.next = 7;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
if (!(this.__throw_errors !== false)) {
|
|
436
|
+
_context8.next = 6;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
throw Error("Cant use setSubValue (".concat(String(key), ") when on readonly mode"));
|
|
440
|
+
case 6:
|
|
441
|
+
return _context8.abrupt("return", false);
|
|
442
|
+
case 7:
|
|
443
|
+
isValueChanged = false;
|
|
444
|
+
_context8.prev = 8;
|
|
445
|
+
//if accessing subval of an object, make sure the object is not null
|
|
446
|
+
subval = _assertClassBrand(_SimpleObject_brand, this, _getSubProperty).call(this, key, objKey);
|
|
447
|
+
if (!(0, _object.object_equals)(subval, subvalue, {
|
|
448
|
+
ignoredStartingWords: "_",
|
|
449
|
+
strictArrayCheck: true
|
|
450
|
+
})) {
|
|
451
|
+
_assertClassBrand(_SimpleObject_brand, this, _setSubProperty).call(this, key, objKey, subvalue);
|
|
452
|
+
isValueChanged = true;
|
|
453
|
+
} else isValueChanged = false;
|
|
454
|
+
case 11:
|
|
455
|
+
_context8.prev = 11;
|
|
456
|
+
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
457
|
+
_context8.next = 15;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
_context8.next = 15;
|
|
461
|
+
return this.notifyChanged("", key, objKey, subvalue);
|
|
462
|
+
case 15:
|
|
463
|
+
return _context8.finish(11);
|
|
464
|
+
case 16:
|
|
465
|
+
return _context8.abrupt("return", isValueChanged);
|
|
466
|
+
case 17:
|
|
467
|
+
case "end":
|
|
468
|
+
return _context8.stop();
|
|
469
|
+
}
|
|
470
|
+
}, _callee8, this, [[8,, 11, 16]]);
|
|
471
|
+
}));
|
|
472
|
+
function setSubValue(_x9, _x10, _x11) {
|
|
473
|
+
return _setSubValue.apply(this, arguments);
|
|
474
|
+
}
|
|
475
|
+
return setSubValue;
|
|
476
|
+
}())
|
|
477
|
+
}, {
|
|
478
|
+
key: "pushValue",
|
|
479
|
+
value: (
|
|
480
|
+
/**
|
|
481
|
+
* Push a single value to array property
|
|
482
|
+
* @param key
|
|
483
|
+
* @param value
|
|
484
|
+
* @param sendChanges
|
|
485
|
+
* @returns
|
|
486
|
+
*/
|
|
487
|
+
function () {
|
|
488
|
+
var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(key, value) {
|
|
489
|
+
var sendChanges,
|
|
490
|
+
_args9 = arguments;
|
|
491
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
492
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
493
|
+
case 0:
|
|
494
|
+
sendChanges = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : "auto";
|
|
495
|
+
_context9.next = 3;
|
|
496
|
+
return this.pushValues(key, [value], sendChanges);
|
|
497
|
+
case 3:
|
|
498
|
+
return _context9.abrupt("return", _context9.sent);
|
|
499
|
+
case 4:
|
|
500
|
+
case "end":
|
|
501
|
+
return _context9.stop();
|
|
502
|
+
}
|
|
503
|
+
}, _callee9, this);
|
|
504
|
+
}));
|
|
505
|
+
function pushValue(_x12, _x13) {
|
|
506
|
+
return _pushValue.apply(this, arguments);
|
|
507
|
+
}
|
|
508
|
+
return pushValue;
|
|
509
|
+
}()
|
|
510
|
+
/**
|
|
511
|
+
* Push a list of values to array property
|
|
512
|
+
* @param key
|
|
513
|
+
* @param values
|
|
514
|
+
* @param sendChanges
|
|
515
|
+
* @returns
|
|
516
|
+
*/
|
|
517
|
+
)
|
|
518
|
+
}, {
|
|
519
|
+
key: "pushValues",
|
|
520
|
+
value: (function () {
|
|
521
|
+
var _pushValues = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(key, values) {
|
|
522
|
+
var sendChanges,
|
|
523
|
+
tempArray,
|
|
524
|
+
_args10 = arguments;
|
|
525
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
526
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
527
|
+
case 0:
|
|
528
|
+
sendChanges = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : "auto";
|
|
529
|
+
if (!(0, _object.array_isEmpty)(values)) {
|
|
530
|
+
_context10.next = 3;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
return _context10.abrupt("return", false);
|
|
534
|
+
case 3:
|
|
535
|
+
if (this.canModify) {
|
|
536
|
+
_context10.next = 9;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
if (!(this.__throw_errors !== false)) {
|
|
540
|
+
_context10.next = 8;
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
throw Error("Cant use pushValues (".concat(String(key), ") when on readonly mode"));
|
|
544
|
+
case 8:
|
|
545
|
+
return _context10.abrupt("return", false);
|
|
546
|
+
case 9:
|
|
547
|
+
if (_assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key) == null) _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, []);
|
|
548
|
+
tempArray = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
|
|
549
|
+
if (Array.isArray(tempArray)) {
|
|
550
|
+
_context10.next = 17;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
if (!(this.__throw_errors !== false)) {
|
|
554
|
+
_context10.next = 16;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
throw Error("Cant use pushValues (".concat(String(key), ") on non Array keys"));
|
|
558
|
+
case 16:
|
|
559
|
+
return _context10.abrupt("return", false);
|
|
560
|
+
case 17:
|
|
561
|
+
_assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, (0, _object.array_merge)(tempArray, values));
|
|
562
|
+
if (!(sendChanges === true || sendChanges === "auto")) {
|
|
563
|
+
_context10.next = 21;
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
_context10.next = 21;
|
|
567
|
+
return this.notifyChanged("", key, values);
|
|
568
|
+
case 21:
|
|
569
|
+
return _context10.abrupt("return", tempArray);
|
|
570
|
+
case 22:
|
|
571
|
+
case "end":
|
|
572
|
+
return _context10.stop();
|
|
573
|
+
}
|
|
574
|
+
}, _callee10, this);
|
|
575
|
+
}));
|
|
576
|
+
function pushValues(_x14, _x15) {
|
|
577
|
+
return _pushValues.apply(this, arguments);
|
|
578
|
+
}
|
|
579
|
+
return pushValues;
|
|
580
|
+
}()
|
|
581
|
+
/**
|
|
582
|
+
*
|
|
583
|
+
* @param type
|
|
584
|
+
* @param key
|
|
585
|
+
* @param value
|
|
586
|
+
* @param subvalue
|
|
587
|
+
* @returns true if manager was notified. false otherwise
|
|
588
|
+
*/
|
|
589
|
+
)
|
|
590
|
+
}, {
|
|
591
|
+
key: "notifyChanged",
|
|
592
|
+
value: (function () {
|
|
593
|
+
var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(type, key, value, subvalue) {
|
|
594
|
+
var lc, manager_class;
|
|
595
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
596
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
597
|
+
case 0:
|
|
598
|
+
if (value === undefined && type == "") value = this.getValue(key);
|
|
599
|
+
this.__changed = true;
|
|
600
|
+
lc = "";
|
|
601
|
+
if (type) lc += "$".concat(String(type), "$");
|
|
602
|
+
if (subvalue) {
|
|
603
|
+
lc += "".concat(String(key), ".").concat(value);
|
|
604
|
+
} else {
|
|
605
|
+
lc += "".concat(String(key));
|
|
606
|
+
}
|
|
607
|
+
this.__lastChanged = lc;
|
|
608
|
+
/* --------------------------- notify the manager --------------------------- */
|
|
609
|
+
manager_class = this.manager;
|
|
610
|
+
if (!(typeof (manager_class === null || manager_class === void 0 ? void 0 : manager_class.notifyChanged) === "function")) {
|
|
611
|
+
_context11.next = 11;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
_context11.next = 10;
|
|
615
|
+
return manager_class.notifyChanged(type, key, value, subvalue);
|
|
616
|
+
case 10:
|
|
617
|
+
return _context11.abrupt("return", _context11.sent);
|
|
618
|
+
case 11:
|
|
619
|
+
return _context11.abrupt("return", false);
|
|
620
|
+
case 12:
|
|
621
|
+
case "end":
|
|
622
|
+
return _context11.stop();
|
|
623
|
+
}
|
|
624
|
+
}, _callee11, this);
|
|
625
|
+
}));
|
|
626
|
+
function notifyChanged(_x16, _x17, _x18, _x19) {
|
|
627
|
+
return _notifyChanged.apply(this, arguments);
|
|
628
|
+
}
|
|
629
|
+
return notifyChanged;
|
|
630
|
+
}()
|
|
631
|
+
/**
|
|
632
|
+
* check if a key can be changed on an object
|
|
633
|
+
* @param object the object we are checking
|
|
634
|
+
* @param key key of the object
|
|
635
|
+
* @param useExtraProps should we check extra props?
|
|
636
|
+
* @returns
|
|
637
|
+
*/
|
|
638
|
+
)
|
|
639
|
+
}, {
|
|
640
|
+
key: "apply_changes",
|
|
641
|
+
value: /* -------------------------------------------------------------------------- */
|
|
642
|
+
/* Changes */
|
|
643
|
+
/* -------------------------------------------------------------------------- */
|
|
644
|
+
/**
|
|
645
|
+
* Apply all the changes and empty the delta object
|
|
646
|
+
*/
|
|
647
|
+
function apply_changes() {
|
|
648
|
+
try {
|
|
649
|
+
if (!this.__use_delta) {
|
|
650
|
+
//in this mode , we track changes by updating the original product
|
|
651
|
+
this.setOriginal();
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
if (!this.isChanged) {
|
|
655
|
+
console.warn("No changes to apply");
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
for (var key in this.__delta) {
|
|
659
|
+
var nv = this.__delta[key];
|
|
660
|
+
this[key] = nv;
|
|
661
|
+
}
|
|
662
|
+
return true;
|
|
663
|
+
} finally {
|
|
664
|
+
this.clear_changes();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* apply changes for the given fields
|
|
669
|
+
* @param key
|
|
670
|
+
* @returns
|
|
671
|
+
*/
|
|
672
|
+
}, {
|
|
673
|
+
key: "apply",
|
|
674
|
+
value: function apply(keylist) {
|
|
675
|
+
var _this2 = this;
|
|
676
|
+
(0, _object.wrap_array)(keylist).forEach(function (key) {
|
|
677
|
+
try {
|
|
678
|
+
if (!_this2.__use_delta) {
|
|
679
|
+
//in this mode , we track changes by updating the original
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
if (_this2.__delta != null && key in _this2.__delta) {
|
|
683
|
+
_this2[key] = _this2.__delta[key];
|
|
684
|
+
delete _this2.__delta[key];
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
} finally {}
|
|
688
|
+
});
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* set the value to its original
|
|
693
|
+
* @param key
|
|
694
|
+
*/
|
|
695
|
+
}, {
|
|
696
|
+
key: "reset",
|
|
697
|
+
value: (function () {
|
|
698
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(key) {
|
|
699
|
+
var shouldNotify,
|
|
700
|
+
_args12 = arguments;
|
|
701
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
702
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
703
|
+
case 0:
|
|
704
|
+
shouldNotify = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : "auto";
|
|
705
|
+
_context12.next = 3;
|
|
706
|
+
return this.setValue(key, this[key], shouldNotify);
|
|
707
|
+
case 3:
|
|
708
|
+
return _context12.abrupt("return", _context12.sent);
|
|
709
|
+
case 4:
|
|
710
|
+
case "end":
|
|
711
|
+
return _context12.stop();
|
|
712
|
+
}
|
|
713
|
+
}, _callee12, this);
|
|
714
|
+
}));
|
|
715
|
+
function reset(_x20) {
|
|
716
|
+
return _reset.apply(this, arguments);
|
|
717
|
+
}
|
|
718
|
+
return reset;
|
|
719
|
+
}()
|
|
720
|
+
/**
|
|
721
|
+
* reset all values back to their original
|
|
722
|
+
* difference between this and clear_changes is that this function also calls on_change
|
|
723
|
+
* @param key
|
|
724
|
+
*/
|
|
725
|
+
)
|
|
726
|
+
}, {
|
|
727
|
+
key: "resetAll",
|
|
728
|
+
value: (function () {
|
|
729
|
+
var _resetAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
730
|
+
var shouldNotify,
|
|
731
|
+
fr,
|
|
732
|
+
key,
|
|
733
|
+
_args13 = arguments;
|
|
734
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
735
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
736
|
+
case 0:
|
|
737
|
+
shouldNotify = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : "auto";
|
|
738
|
+
fr = true;
|
|
739
|
+
_context13.t0 = _regeneratorRuntime().keys(this.__delta);
|
|
740
|
+
case 3:
|
|
741
|
+
if ((_context13.t1 = _context13.t0()).done) {
|
|
742
|
+
_context13.next = 13;
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
key = _context13.t1.value;
|
|
746
|
+
_context13.t2 = fr;
|
|
747
|
+
if (!_context13.t2) {
|
|
748
|
+
_context13.next = 10;
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
_context13.next = 9;
|
|
752
|
+
return this.reset(key, shouldNotify);
|
|
753
|
+
case 9:
|
|
754
|
+
_context13.t2 = _context13.sent;
|
|
755
|
+
case 10:
|
|
756
|
+
fr = _context13.t2;
|
|
757
|
+
_context13.next = 3;
|
|
758
|
+
break;
|
|
759
|
+
case 13:
|
|
760
|
+
return _context13.abrupt("return", fr);
|
|
761
|
+
case 14:
|
|
762
|
+
case "end":
|
|
763
|
+
return _context13.stop();
|
|
764
|
+
}
|
|
765
|
+
}, _callee13, this);
|
|
766
|
+
}));
|
|
767
|
+
function resetAll() {
|
|
768
|
+
return _resetAll.apply(this, arguments);
|
|
769
|
+
}
|
|
770
|
+
return resetAll;
|
|
771
|
+
}()
|
|
772
|
+
/**
|
|
773
|
+
* clear and discard all changes
|
|
774
|
+
* does not call any on_change functions
|
|
775
|
+
* @returns
|
|
776
|
+
*/
|
|
777
|
+
)
|
|
778
|
+
}, {
|
|
779
|
+
key: "clear_changes",
|
|
780
|
+
value: function clear_changes() {
|
|
781
|
+
this.__delta = {};
|
|
782
|
+
this.__changed = false;
|
|
783
|
+
return true;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* clear and discard all temp values
|
|
787
|
+
* @returns
|
|
788
|
+
*/
|
|
789
|
+
}, {
|
|
790
|
+
key: "clear_cache",
|
|
791
|
+
value: function clear_cache() {
|
|
792
|
+
delete this.__temp;
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Sets readonly property on given objects
|
|
797
|
+
* @param objs array of given objects or a single object
|
|
798
|
+
* @param readonlyval readonly
|
|
799
|
+
* @param clearChanges should we clean the changes after setting readonly
|
|
800
|
+
*/
|
|
801
|
+
}, {
|
|
802
|
+
key: "__object_name",
|
|
803
|
+
get: /* -------------------------------------------------------------------------- */
|
|
804
|
+
/* Get/Check */
|
|
805
|
+
/* -------------------------------------------------------------------------- */
|
|
806
|
+
function get() {
|
|
807
|
+
return this.constructor["__object_name"] || this.__db_name;
|
|
808
|
+
}
|
|
809
|
+
}, {
|
|
810
|
+
key: "__db_name",
|
|
811
|
+
get: function get() {
|
|
812
|
+
return this.constructor["__db_name"] || this.constructor["__web_path"];
|
|
813
|
+
}
|
|
814
|
+
/* -------------------------------------------------------------------------- */
|
|
815
|
+
}, {
|
|
816
|
+
key: "isChanged",
|
|
817
|
+
get: function get() {
|
|
818
|
+
var _this3 = this;
|
|
819
|
+
////const deltaIsBlank = object_isEmpty(this.__delta);
|
|
820
|
+
////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
|
|
821
|
+
////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
|
|
822
|
+
if (this.__use_delta) return !(0, _object.object_isEmpty)(this.__delta);
|
|
823
|
+
/* -------------------------------------------------------------------------- */
|
|
824
|
+
/* check the properties one by one */
|
|
825
|
+
/* -------------------------------------------------------------------------- */
|
|
826
|
+
var orig = this.getOriginal();
|
|
827
|
+
if (!orig) return false; //we dont know if anything has changed
|
|
828
|
+
/* if object is not using delta mode, check changes by comparing changable fields with original object */
|
|
829
|
+
if (Array.isArray(this.__changeables)) {
|
|
830
|
+
return this.__changeables.find(function (c) {
|
|
831
|
+
return !(0, _object.object_equals)(_this3[c], orig[c]);
|
|
832
|
+
}) != undefined;
|
|
833
|
+
} else {
|
|
834
|
+
/* check all fields */
|
|
835
|
+
for (var key in this) {
|
|
836
|
+
if (key.startsWith("__")) continue;
|
|
837
|
+
if (!(0, _object.object_equals)(this[key], orig[key])) return true;
|
|
838
|
+
}
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
}, {
|
|
844
|
+
key: "isArchived",
|
|
845
|
+
get: function get() {
|
|
846
|
+
return this._archived || false;
|
|
847
|
+
},
|
|
848
|
+
set: function set(v) {
|
|
849
|
+
this._archived = v;
|
|
850
|
+
}
|
|
851
|
+
}, {
|
|
852
|
+
key: "isDeleted",
|
|
853
|
+
get: function get() {
|
|
854
|
+
return this.get("_deleted") || false;
|
|
855
|
+
},
|
|
856
|
+
set: function set(v) {
|
|
857
|
+
this._deleted = v;
|
|
858
|
+
}
|
|
859
|
+
}, {
|
|
860
|
+
key: "isLocked",
|
|
861
|
+
get: function get() {
|
|
862
|
+
return this.get("_locked") || false;
|
|
863
|
+
},
|
|
864
|
+
set: function set(v) {
|
|
865
|
+
this._locked = v;
|
|
866
|
+
}
|
|
867
|
+
}, {
|
|
868
|
+
key: "d",
|
|
869
|
+
get: function get() {
|
|
870
|
+
return this.__use_delta ? this.__delta : this;
|
|
871
|
+
}
|
|
872
|
+
/* all updated properties */
|
|
873
|
+
}, {
|
|
874
|
+
key: "allproperties",
|
|
875
|
+
get: function get() {
|
|
876
|
+
var result = _objectSpread(_objectSpread({}, this), this.__delta);
|
|
877
|
+
result.__delta = {};
|
|
878
|
+
return result;
|
|
879
|
+
}
|
|
880
|
+
}, {
|
|
881
|
+
key: "canModify",
|
|
882
|
+
get: function get() {
|
|
883
|
+
return !Boolean(this.__is_readonly);
|
|
884
|
+
}
|
|
885
|
+
}, {
|
|
886
|
+
key: "__changeables",
|
|
887
|
+
get: function get() {
|
|
888
|
+
return this.constructor["__changeables"];
|
|
889
|
+
}
|
|
890
|
+
}, {
|
|
891
|
+
key: "__unchangeables",
|
|
892
|
+
get: function get() {
|
|
893
|
+
return this.constructor["__unchangeables"];
|
|
894
|
+
}
|
|
895
|
+
}, {
|
|
896
|
+
key: "__use_delta",
|
|
897
|
+
get: function get() {
|
|
898
|
+
return this.constructor["__use_delta"];
|
|
899
|
+
}
|
|
900
|
+
}, {
|
|
901
|
+
key: "isSaved",
|
|
902
|
+
get: function get() {
|
|
903
|
+
var _this$__saveResultIsS;
|
|
904
|
+
return Boolean((_this$__saveResultIsS = this.__saveResultIsSuccess) !== null && _this$__saveResultIsS !== void 0 ? _this$__saveResultIsS : false);
|
|
905
|
+
}
|
|
906
|
+
}, {
|
|
907
|
+
key: "isNew",
|
|
908
|
+
get: function get() {
|
|
909
|
+
var mid = this.getID();
|
|
910
|
+
if (!mid) return true;
|
|
911
|
+
if (typeof mid === "string") return mid === "" || mid === "-1";
|
|
912
|
+
if (typeof mid === "number") return mid === -1;
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
}, {
|
|
916
|
+
key: "lastChanged",
|
|
917
|
+
get: function get() {
|
|
918
|
+
return this.__lastChanged || "";
|
|
919
|
+
}
|
|
920
|
+
}, {
|
|
921
|
+
key: "manager",
|
|
922
|
+
get: function get() {
|
|
923
|
+
return this.get_managerClass() || undefined;
|
|
924
|
+
}
|
|
925
|
+
}, {
|
|
926
|
+
key: "set_managerClass",
|
|
927
|
+
value:
|
|
928
|
+
/**
|
|
929
|
+
* @deprecated use setManager
|
|
930
|
+
* @param mng
|
|
931
|
+
*/
|
|
932
|
+
function set_managerClass(mng) {
|
|
933
|
+
return this.setManager(mng);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* update the manager class for this object
|
|
937
|
+
* @param mng
|
|
938
|
+
*/
|
|
939
|
+
}, {
|
|
940
|
+
key: "setManager",
|
|
941
|
+
value: function setManager(mng) {
|
|
942
|
+
if (mng instanceof _ObjectManager["default"] && typeof mng.setObject === "function") {
|
|
943
|
+
//make sure the manager knows what object it is managing
|
|
944
|
+
return mng.setObject(this);
|
|
945
|
+
} else {
|
|
946
|
+
console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}, {
|
|
950
|
+
key: "getIndexOrID",
|
|
951
|
+
value: function getIndexOrID() {
|
|
952
|
+
return SimpleObject.getIndexOrID(this);
|
|
953
|
+
}
|
|
954
|
+
}, {
|
|
955
|
+
key: "getIndex",
|
|
956
|
+
value: function getIndex() {
|
|
957
|
+
return SimpleObject.getIndex(this);
|
|
958
|
+
}
|
|
959
|
+
}, {
|
|
960
|
+
key: "getID",
|
|
961
|
+
value: function getID() {
|
|
962
|
+
return SimpleObject.getID(this);
|
|
963
|
+
}
|
|
964
|
+
}, {
|
|
965
|
+
key: "event_run",
|
|
966
|
+
value: (
|
|
967
|
+
/* -------------------------------------------------------------------------- */
|
|
968
|
+
/* Events */
|
|
969
|
+
/* -------------------------------------------------------------------------- */
|
|
970
|
+
function () {
|
|
971
|
+
var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(eventName) {
|
|
972
|
+
var _this$manager;
|
|
973
|
+
var _len2,
|
|
974
|
+
params,
|
|
975
|
+
_key2,
|
|
976
|
+
_args14 = arguments;
|
|
977
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
978
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
979
|
+
case 0:
|
|
980
|
+
if (this.manager) {
|
|
981
|
+
_context14.next = 3;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(eventName, ") if your object has no manager"));
|
|
985
|
+
return _context14.abrupt("return");
|
|
986
|
+
case 3:
|
|
987
|
+
for (_len2 = _args14.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
988
|
+
params[_key2 - 1] = _args14[_key2];
|
|
989
|
+
}
|
|
990
|
+
_context14.next = 6;
|
|
991
|
+
return (_this$manager = this.manager).event_run.apply(_this$manager, [eventName].concat(params));
|
|
992
|
+
case 6:
|
|
993
|
+
return _context14.abrupt("return", _context14.sent);
|
|
994
|
+
case 7:
|
|
995
|
+
case "end":
|
|
996
|
+
return _context14.stop();
|
|
997
|
+
}
|
|
998
|
+
}, _callee14, this);
|
|
999
|
+
}));
|
|
1000
|
+
function event_run(_x21) {
|
|
1001
|
+
return _event_run.apply(this, arguments);
|
|
1002
|
+
}
|
|
1003
|
+
return event_run;
|
|
1004
|
+
}())
|
|
1005
|
+
}, {
|
|
1006
|
+
key: "event_use",
|
|
1007
|
+
value: function event_use(name, runEvent) {
|
|
1008
|
+
var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1009
|
+
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1010
|
+
if (!this.manager) {
|
|
1011
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
return this.manager.event_use(name, runEvent, onlyOn, runOnce);
|
|
1015
|
+
}
|
|
1016
|
+
}, {
|
|
1017
|
+
key: "event_remove",
|
|
1018
|
+
value: function event_remove(name, uname) {
|
|
1019
|
+
if (!this.manager) {
|
|
1020
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
return this.manager.event_remove(name, uname);
|
|
1024
|
+
}
|
|
1025
|
+
}, {
|
|
1026
|
+
key: "event_add",
|
|
1027
|
+
value: function () {
|
|
1028
|
+
var _event_add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(name, uname, runEvent) {
|
|
1029
|
+
var onlyOn,
|
|
1030
|
+
runOnce,
|
|
1031
|
+
_args15 = arguments;
|
|
1032
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1033
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1034
|
+
case 0:
|
|
1035
|
+
onlyOn = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : null;
|
|
1036
|
+
runOnce = _args15.length > 4 && _args15[4] !== undefined ? _args15[4] : false;
|
|
1037
|
+
if (this.manager) {
|
|
1038
|
+
_context15.next = 5;
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
if (this.__showErrors === true) console.error("you cant use events (".concat(name, ") if your object has no manager"));
|
|
1042
|
+
return _context15.abrupt("return");
|
|
1043
|
+
case 5:
|
|
1044
|
+
_context15.next = 7;
|
|
1045
|
+
return this.manager.event_add(name, uname, runEvent, onlyOn, runOnce);
|
|
1046
|
+
case 7:
|
|
1047
|
+
case "end":
|
|
1048
|
+
return _context15.stop();
|
|
1049
|
+
}
|
|
1050
|
+
}, _callee15, this);
|
|
1051
|
+
}));
|
|
1052
|
+
function event_add(_x22, _x23, _x24) {
|
|
1053
|
+
return _event_add.apply(this, arguments);
|
|
1054
|
+
}
|
|
1055
|
+
return event_add;
|
|
1056
|
+
}()
|
|
1057
|
+
/* -------------------------------------------------------------------------- */
|
|
1058
|
+
/* Original */
|
|
1059
|
+
/* -------------------------------------------------------------------------- */
|
|
1060
|
+
}, {
|
|
1061
|
+
key: "getOriginal",
|
|
1062
|
+
value: function getOriginal() {
|
|
1063
|
+
return this.__originalobject || undefined;
|
|
1064
|
+
}
|
|
1065
|
+
}, {
|
|
1066
|
+
key: "setOriginal",
|
|
1067
|
+
value: function setOriginal() {
|
|
1068
|
+
var toObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1069
|
+
if (toObj === null) {
|
|
1070
|
+
delete this.__originalobject;
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (!this.canModify) {
|
|
1074
|
+
console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
|
|
1075
|
+
delete this.__originalobject;
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (toObj === 0) {
|
|
1079
|
+
toObj = this;
|
|
1080
|
+
}
|
|
1081
|
+
var cloneObject = (0, _object.object_clone)(toObj);
|
|
1082
|
+
SimpleObject.setReadonly(cloneObject, true);
|
|
1083
|
+
this.__originalobject = (0, _object.object_removeKeys)(cloneObject, ["__"]);
|
|
1084
|
+
return this;
|
|
1085
|
+
}
|
|
1086
|
+
}, {
|
|
1087
|
+
key: "addError",
|
|
1088
|
+
value: /* -------------------------------------------------------------------------- */
|
|
1089
|
+
/* Errors */
|
|
1090
|
+
/* -------------------------------------------------------------------------- */
|
|
1091
|
+
function addError(title, message) {
|
|
1092
|
+
var sendToRegister = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "auto";
|
|
1093
|
+
return SimpleObject.addError(this, title, message, sendToRegister);
|
|
1094
|
+
}
|
|
1095
|
+
}, {
|
|
1096
|
+
key: "clearErrors",
|
|
1097
|
+
value: function clearErrors() {
|
|
1098
|
+
return SimpleObject.clearErrors(this);
|
|
1099
|
+
}
|
|
1100
|
+
}, {
|
|
1101
|
+
key: "getErrors",
|
|
1102
|
+
value: function getErrors() {
|
|
1103
|
+
return SimpleObject.getErrors(this);
|
|
1104
|
+
}
|
|
1105
|
+
}, {
|
|
1106
|
+
key: "setSaveResult",
|
|
1107
|
+
value:
|
|
1108
|
+
/**
|
|
1109
|
+
* set the response of last save from site
|
|
1110
|
+
* and its type
|
|
1111
|
+
* @param toObj
|
|
1112
|
+
*/
|
|
1113
|
+
function setSaveResult(toObj) {
|
|
1114
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "auto";
|
|
1115
|
+
var registerErrors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1116
|
+
_assertClassBrand(_SimpleObject_brand, this, _setSaveResultObject).call(this, toObj);
|
|
1117
|
+
//check if the given object is a valid save result
|
|
1118
|
+
if (type === "error") this.__saveResultIsSuccess = false;else this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
|
|
1119
|
+
if (type === "auto") {
|
|
1120
|
+
type = this.__saveResultIsSuccess ? "normal" : "error";
|
|
1121
|
+
}
|
|
1122
|
+
if (registerErrors && !this.__saveResultIsSuccess) {
|
|
1123
|
+
console.error("bad save result : ", this.__saveResultObject);
|
|
1124
|
+
SimpleObject.addError(this, "save result is not valid", "the response from server was not valid", true);
|
|
1125
|
+
}
|
|
1126
|
+
this.__saveResultType = type;
|
|
1127
|
+
return type;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* set the response of last save from site
|
|
1131
|
+
* @param toObj
|
|
1132
|
+
*/
|
|
1133
|
+
}, {
|
|
1134
|
+
key: "getSaveResult",
|
|
1135
|
+
value: function getSaveResult() {
|
|
1136
|
+
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1137
|
+
if (this.isSaved) return this.__saveResultObject;
|
|
1138
|
+
return false;
|
|
1139
|
+
}
|
|
1140
|
+
}, {
|
|
1141
|
+
key: "getSaveResultType",
|
|
1142
|
+
value: function getSaveResultType() {
|
|
1143
|
+
return this.__saveResultType || "nothing";
|
|
1144
|
+
}
|
|
1145
|
+
/** did we create on the last save */
|
|
1146
|
+
}, {
|
|
1147
|
+
key: "getIsLastSaveCreate",
|
|
1148
|
+
value: function getIsLastSaveCreate() {
|
|
1149
|
+
return this.isSaved && this.getSaveResult().insertedId;
|
|
1150
|
+
}
|
|
1151
|
+
/* -------------------------------------------------------------------------- */
|
|
1152
|
+
/* statics */
|
|
1153
|
+
/* -------------------------------------------------------------------------- */
|
|
1154
|
+
}], [{
|
|
1155
|
+
key: "loadValues",
|
|
1156
|
+
value: function loadValues(obj, initObject) {
|
|
1157
|
+
var fullUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1158
|
+
if (typeof initObject === "number" || typeof initObject === "string") {
|
|
1159
|
+
initObject = {
|
|
1160
|
+
_id: initObject
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
SimpleObject.factoryClear(obj);
|
|
1164
|
+
if (initObject == null) {
|
|
1165
|
+
for (var key in obj) {
|
|
1166
|
+
if (typeof obj[key] === "function") continue;
|
|
1167
|
+
if (key.startsWith("__")) continue;
|
|
1168
|
+
delete obj[key];
|
|
1169
|
+
}
|
|
1170
|
+
} else if (_typeof(initObject) == "object") {
|
|
1171
|
+
for (var _key3 in initObject) {
|
|
1172
|
+
if (_key3.startsWith("__")) continue;
|
|
1173
|
+
if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key3)) {
|
|
1174
|
+
obj[_key3] = initObject[_key3];
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
/* -------------------------------------------------------------------------- */
|
|
1181
|
+
}, {
|
|
1182
|
+
key: "getValue",
|
|
1183
|
+
value: function getValue(o, key) {
|
|
1184
|
+
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1185
|
+
if (o == null) return undefined;
|
|
1186
|
+
if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
|
|
1187
|
+
if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
|
|
1188
|
+
//@ts-ignore
|
|
1189
|
+
return o.__delta[key];
|
|
1190
|
+
}
|
|
1191
|
+
return o[key];
|
|
1192
|
+
}
|
|
1193
|
+
}, {
|
|
1194
|
+
key: "canChangeKey",
|
|
1195
|
+
value: function canChangeKey(object, key, options) {
|
|
1196
|
+
if (!object || !key) return false;
|
|
1197
|
+
var useExtraProps = options.useExtraProps,
|
|
1198
|
+
ignoreProtected = options.ignoreProtected;
|
|
1199
|
+
if (useExtraProps) {
|
|
1200
|
+
var __extraProperties = object.constructor["__extraProperties"];
|
|
1201
|
+
if (__extraProperties != null && __extraProperties.includes(key)) return true;
|
|
1202
|
+
}
|
|
1203
|
+
/* -------------------------------------------------------------------------- */
|
|
1204
|
+
var __changeables = object.constructor["__changeables"];
|
|
1205
|
+
var __unchangeables = object.constructor["__unchangeables"];
|
|
1206
|
+
/* -------------------------------------------------------------------------- */
|
|
1207
|
+
if (__changeables != null && !__changeables.includes(key)) return false;
|
|
1208
|
+
if (__unchangeables != null && __unchangeables.includes(key)) return false;
|
|
1209
|
+
if (ignoreProtected !== true) {
|
|
1210
|
+
var __protectedProperties = object.constructor["__protectedProperties"];
|
|
1211
|
+
if (__protectedProperties != null && __protectedProperties.includes(key)) {
|
|
1212
|
+
//protected keys can only be changed by the creator of this object
|
|
1213
|
+
//make sure you set the is_current_user function correctly
|
|
1214
|
+
if (object.isNew) return true;
|
|
1215
|
+
var creatorOfObject = object.get("_creator");
|
|
1216
|
+
return Boolean(_global.gfunc.run_action_sync("is_current_user", creatorOfObject));
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
return true;
|
|
1220
|
+
}
|
|
1221
|
+
}, {
|
|
1222
|
+
key: "hasIllegalChanges",
|
|
1223
|
+
value: function hasIllegalChanges(referenceObject, changesObject, updaterUser) {
|
|
1224
|
+
var __protectedProperties = (0, _object.object_getStatic)(referenceObject, "__protectedProperties");
|
|
1225
|
+
if ((0, _object.object_isEmpty)(__protectedProperties)) return false;
|
|
1226
|
+
var referenceUser = (0, _object.object_isClass)(referenceObject) ? (0, _object.object_get)(changesObject, "__user", "_creator") : (0, _object.object_get)(referenceObject, "__user", "_creator");
|
|
1227
|
+
if (Boolean(SimpleObject.getID(referenceUser) == SimpleObject.getID(updaterUser))) {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
for (var key in changesObject) {
|
|
1231
|
+
if (__protectedProperties.includes(key)) {
|
|
1232
|
+
return true;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return false;
|
|
1236
|
+
}
|
|
1237
|
+
}, {
|
|
1238
|
+
key: "setReadonly",
|
|
1239
|
+
value: function setReadonly(objs) {
|
|
1240
|
+
var readonlyval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1241
|
+
var clearChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1242
|
+
var checkObjs = [];
|
|
1243
|
+
if (!objs) objs = [];
|
|
1244
|
+
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1245
|
+
for (var index = 0; index < checkObjs.length; index++) {
|
|
1246
|
+
var obj = checkObjs[index];
|
|
1247
|
+
obj.__is_readonly = readonlyval;
|
|
1248
|
+
if (obj instanceof SimpleObject) {
|
|
1249
|
+
if (obj.canModify) {
|
|
1250
|
+
if (!obj.getOriginal()) obj.setOriginal();
|
|
1251
|
+
} else {
|
|
1252
|
+
if (clearChanges) obj.clear_changes();
|
|
1253
|
+
//we dont need the original object in readonly mode
|
|
1254
|
+
obj.setOriginal(null);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}, {
|
|
1260
|
+
key: "setThrowErrors",
|
|
1261
|
+
value: function setThrowErrors(objs) {
|
|
1262
|
+
var throwErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1263
|
+
var checkObjs = [];
|
|
1264
|
+
if (!objs) objs = [];
|
|
1265
|
+
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1266
|
+
for (var index = 0; index < checkObjs.length; index++) {
|
|
1267
|
+
var element = checkObjs[index];
|
|
1268
|
+
element.__throw_errors = throwErr;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}, {
|
|
1272
|
+
key: "isDeleted",
|
|
1273
|
+
value: function isDeleted(obj) {
|
|
1274
|
+
if (obj instanceof SimpleObject) return obj.isDeleted === true;
|
|
1275
|
+
return false;
|
|
1276
|
+
}
|
|
1277
|
+
}, {
|
|
1278
|
+
key: "getIndexOrID",
|
|
1279
|
+
value: function getIndexOrID(o) {
|
|
1280
|
+
var res = SimpleObject.getIndex(o);
|
|
1281
|
+
if (!res || res == -1) res = SimpleObject.getID(o);
|
|
1282
|
+
return res || -1;
|
|
1283
|
+
}
|
|
1284
|
+
}, {
|
|
1285
|
+
key: "getIndex",
|
|
1286
|
+
value: function getIndex(o) {
|
|
1287
|
+
if (o == null || o == undefined) return -1;
|
|
1288
|
+
switch (_typeof(o)) {
|
|
1289
|
+
case "object":
|
|
1290
|
+
return o._index_value || -1;
|
|
1291
|
+
case "number":
|
|
1292
|
+
case "string":
|
|
1293
|
+
return Number(o);
|
|
1294
|
+
}
|
|
1295
|
+
return -1;
|
|
1296
|
+
}
|
|
1297
|
+
}, {
|
|
1298
|
+
key: "getID",
|
|
1299
|
+
value: function getID(o) {
|
|
1300
|
+
if (o == null || o == undefined) return "";
|
|
1301
|
+
switch (_typeof(o)) {
|
|
1302
|
+
case "object":
|
|
1303
|
+
if (o._bsontype == "ObjectID" && typeof o.toString === "function") {
|
|
1304
|
+
return o.toString();
|
|
1305
|
+
}
|
|
1306
|
+
return String(o._id || o.insertedId || o.ID || o.id || o.__data_id || "");
|
|
1307
|
+
case "string":
|
|
1308
|
+
case "number":
|
|
1309
|
+
return String(o);
|
|
1310
|
+
}
|
|
1311
|
+
return "";
|
|
1312
|
+
}
|
|
1313
|
+
}, {
|
|
1314
|
+
key: "setOriginal",
|
|
1315
|
+
value: function setOriginal(obj) {
|
|
1316
|
+
var toObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1317
|
+
if (!(obj instanceof SimpleObject)) return undefined;
|
|
1318
|
+
return obj.setOriginal(toObj);
|
|
1319
|
+
}
|
|
1320
|
+
}, {
|
|
1321
|
+
key: "getOriginal",
|
|
1322
|
+
value: function getOriginal(obj) {
|
|
1323
|
+
if (obj instanceof SimpleObject) return obj.getOriginal();
|
|
1324
|
+
return obj === null || obj === void 0 ? void 0 : obj.__originalobject;
|
|
1325
|
+
}
|
|
1326
|
+
}, {
|
|
1327
|
+
key: "addError",
|
|
1328
|
+
value: function addError(o, title, message) {
|
|
1329
|
+
var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
|
|
1330
|
+
var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
|
|
1331
|
+
if (o) {
|
|
1332
|
+
if (!Array.isArray(o.__errors)) o.__errors = [];
|
|
1333
|
+
o.__errors.push(errStr);
|
|
1334
|
+
if (o.__showErrors === false) return;
|
|
1335
|
+
} else if (sendToRegister === "auto") sendToRegister = true;
|
|
1336
|
+
if (sendToRegister === true) {
|
|
1337
|
+
console.error("[REGISTER-ERROR]", errStr);
|
|
1338
|
+
_global.gfunc.run_action("add_error", {
|
|
1339
|
+
title: title,
|
|
1340
|
+
message: message,
|
|
1341
|
+
type: "error"
|
|
1342
|
+
});
|
|
1343
|
+
} else {
|
|
1344
|
+
console.error("[ERROR]", errStr);
|
|
1345
|
+
}
|
|
1346
|
+
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1347
|
+
}
|
|
1348
|
+
}, {
|
|
1349
|
+
key: "getErrors",
|
|
1350
|
+
value: function getErrors(o) {
|
|
1351
|
+
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1352
|
+
}
|
|
1353
|
+
}, {
|
|
1354
|
+
key: "clearErrors",
|
|
1355
|
+
value: function clearErrors(o) {
|
|
1356
|
+
if (o) o.__errors = [];
|
|
1357
|
+
return true;
|
|
1358
|
+
}
|
|
1359
|
+
/* -------------------------------------------------------------------------- */
|
|
1360
|
+
/* Save Results */
|
|
1361
|
+
/* -------------------------------------------------------------------------- */
|
|
1362
|
+
/**
|
|
1363
|
+
* Checks if the given object is a valid and truthy save result
|
|
1364
|
+
* @param result_object
|
|
1365
|
+
* @returns
|
|
1366
|
+
*/
|
|
1367
|
+
}, {
|
|
1368
|
+
key: "isResultValid",
|
|
1369
|
+
value: function isResultValid(result_object) {
|
|
1370
|
+
var sub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1371
|
+
if ((0, _object.object_isEmpty)(result_object)) return false;
|
|
1372
|
+
switch (_typeof(result_object)) {
|
|
1373
|
+
case "string":
|
|
1374
|
+
try {
|
|
1375
|
+
result_object = JSON.parse(result_object);
|
|
1376
|
+
return this.isResultValid(result_object);
|
|
1377
|
+
} catch (_unused) {
|
|
1378
|
+
return false;
|
|
1379
|
+
}
|
|
1380
|
+
case "object":
|
|
1381
|
+
/* --------- maybe website sends the result as array with 1 element --------- */
|
|
1382
|
+
if (Array.isArray(result_object)) {
|
|
1383
|
+
if (sub) return false; //avoid going too deep
|
|
1384
|
+
return this.isResultValid((0, _object.array_first)(result_object), true);
|
|
1385
|
+
}
|
|
1386
|
+
/* -------------------------- check if acknowledged ------------------------- */
|
|
1387
|
+
if ((0, _object.object_isTrue)(result_object.acknowledged)) {
|
|
1388
|
+
return true;
|
|
1389
|
+
}
|
|
1390
|
+
if (result_object.expected && result_object.result) {
|
|
1391
|
+
return (0, _object.object_equals)(result_object.expected, result_object.result);
|
|
1392
|
+
}
|
|
1393
|
+
return !(0, _string.string_isEmpty)(this.getID(result_object));
|
|
1394
|
+
case "number":
|
|
1395
|
+
return result_object > 0;
|
|
1396
|
+
case "boolean":
|
|
1397
|
+
return result_object === true;
|
|
1398
|
+
}
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1401
|
+
}, {
|
|
1402
|
+
key: "setTemp",
|
|
1403
|
+
value: (function () {
|
|
1404
|
+
var _setTemp2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(obj, key, value) {
|
|
1405
|
+
var sendChanges,
|
|
1406
|
+
_args16 = arguments;
|
|
1407
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1408
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1409
|
+
case 0:
|
|
1410
|
+
sendChanges = _args16.length > 3 && _args16[3] !== undefined ? _args16[3] : false;
|
|
1411
|
+
if (!(_typeof(obj) !== "object" || !obj || Array.isArray(obj))) {
|
|
1412
|
+
_context16.next = 3;
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
return _context16.abrupt("return");
|
|
1416
|
+
case 3:
|
|
1417
|
+
if (!(obj instanceof SimpleObject)) {
|
|
1418
|
+
_context16.next = 7;
|
|
1419
|
+
break;
|
|
1420
|
+
}
|
|
1421
|
+
_context16.next = 6;
|
|
1422
|
+
return obj.setTemp(key, value, sendChanges);
|
|
1423
|
+
case 6:
|
|
1424
|
+
return _context16.abrupt("return", _context16.sent);
|
|
1425
|
+
case 7:
|
|
1426
|
+
//
|
|
1427
|
+
if (obj.__temp == null) obj.__temp = {};
|
|
1428
|
+
(0, _object.object_set)(obj.__temp, key, value);
|
|
1429
|
+
case 9:
|
|
1430
|
+
case "end":
|
|
1431
|
+
return _context16.stop();
|
|
1432
|
+
}
|
|
1433
|
+
}, _callee16);
|
|
1434
|
+
}));
|
|
1435
|
+
function setTemp(_x25, _x26, _x27) {
|
|
1436
|
+
return _setTemp2.apply(this, arguments);
|
|
1437
|
+
}
|
|
1438
|
+
return setTemp;
|
|
1439
|
+
}())
|
|
1440
|
+
}, {
|
|
1441
|
+
key: "factoryClear",
|
|
1442
|
+
value: function factoryClear(obj) {
|
|
1443
|
+
obj.clear_changes();
|
|
1444
|
+
SimpleObject.clearErrors(obj);
|
|
1445
|
+
}
|
|
1446
|
+
}, {
|
|
1447
|
+
key: "delete_cache",
|
|
1448
|
+
value: function () {
|
|
1449
|
+
var _delete_cache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(context) {
|
|
1450
|
+
var cacheKey;
|
|
1451
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1452
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1453
|
+
case 0:
|
|
1454
|
+
if (this.__db_name) {
|
|
1455
|
+
_context17.next = 2;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
return _context17.abrupt("return");
|
|
1459
|
+
case 2:
|
|
1460
|
+
if (context) {
|
|
1461
|
+
_context17.next = 7;
|
|
1462
|
+
break;
|
|
1463
|
+
}
|
|
1464
|
+
_context17.next = 5;
|
|
1465
|
+
return _global.gcache.delete_session_cache(this.__db_name);
|
|
1466
|
+
case 5:
|
|
1467
|
+
_context17.next = 10;
|
|
1468
|
+
break;
|
|
1469
|
+
case 7:
|
|
1470
|
+
cacheKey = "".concat(this.__db_name, "-").concat(context);
|
|
1471
|
+
_context17.next = 10;
|
|
1472
|
+
return _global.gcache.delete_session_cache(cacheKey);
|
|
1473
|
+
case 10:
|
|
1474
|
+
case "end":
|
|
1475
|
+
return _context17.stop();
|
|
1476
|
+
}
|
|
1477
|
+
}, _callee17, this);
|
|
1478
|
+
}));
|
|
1479
|
+
function delete_cache(_x28) {
|
|
1480
|
+
return _delete_cache.apply(this, arguments);
|
|
1481
|
+
}
|
|
1482
|
+
return delete_cache;
|
|
1483
|
+
}()
|
|
1484
|
+
}, {
|
|
1485
|
+
key: "get_canModify",
|
|
1486
|
+
value: function get_canModify(o) {
|
|
1487
|
+
if (o instanceof SimpleObject) return o.canModify;
|
|
1488
|
+
return false;
|
|
1489
|
+
}
|
|
1490
|
+
/* -------------------------------------------------------------------------- */
|
|
1491
|
+
}, {
|
|
1492
|
+
key: "equals",
|
|
1493
|
+
value: function equals(a, b) {
|
|
1494
|
+
console.warn("Dont use the default equals method !");
|
|
1495
|
+
if (a == undefined || b == undefined) return false;
|
|
1496
|
+
return a === b;
|
|
1497
|
+
}
|
|
1498
|
+
}]);
|
|
1499
|
+
}(_MapableObject2.MapableObject);
|
|
1500
|
+
function _setSubProperty(key, subkey, value) {
|
|
1501
|
+
var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
|
|
1502
|
+
//@ts-ignore
|
|
1503
|
+
if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
|
|
1504
|
+
subobj[subkey] = value;
|
|
1505
|
+
_assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, subobj);
|
|
1506
|
+
}
|
|
1507
|
+
function _getSubProperty(key, subkey) {
|
|
1508
|
+
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1509
|
+
var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key, original);
|
|
1510
|
+
if (subobj == null || _typeof(subobj) !== "object") return undefined;
|
|
1511
|
+
return subobj[subkey];
|
|
1512
|
+
}
|
|
1513
|
+
function _setProperty(key, value) {
|
|
1514
|
+
if (!this.__use_delta) {
|
|
1515
|
+
this[key] = value; //on noDelta mode, also update the obj
|
|
1516
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1517
|
+
return true;
|
|
1518
|
+
} else {
|
|
1519
|
+
if (this[key] === value) {
|
|
1520
|
+
/**
|
|
1521
|
+
* We set something back to its original value so no need to save it as Delta
|
|
1522
|
+
*/
|
|
1523
|
+
delete this.__delta[key];
|
|
1524
|
+
return false;
|
|
1525
|
+
} else {
|
|
1526
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1527
|
+
return true;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
function _setDefaultProperty(key, value) {
|
|
1532
|
+
//@ts-ignore
|
|
1533
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
1534
|
+
this[key] = value;
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
return false;
|
|
1538
|
+
}
|
|
1539
|
+
function _setDefaultPropertyNow(key) {
|
|
1540
|
+
//@ts-ignore
|
|
1541
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
1542
|
+
this[key] = new Date();
|
|
1543
|
+
return true;
|
|
1544
|
+
}
|
|
1545
|
+
return false;
|
|
1546
|
+
}
|
|
1547
|
+
function _getProperty(key) {
|
|
1548
|
+
var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1549
|
+
//check if we should treat the prop as a function
|
|
1550
|
+
var is_fnc = this.constructor["__functionProperties"] != null && this.constructor["__functionProperties"].includes(key);
|
|
1551
|
+
//check if we should use delta version or normal version for this property
|
|
1552
|
+
var use_orig = original || !this.__use_delta || !(key in this.__delta);
|
|
1553
|
+
if (is_fnc) {
|
|
1554
|
+
if (use_orig) return (0, _object.fn_eval_this)(this, this[key]);
|
|
1555
|
+
return (0, _object.fn_eval_this)(this, this.__delta[key]);
|
|
1556
|
+
}
|
|
1557
|
+
if (use_orig) return this[key];
|
|
1558
|
+
return this.__delta[key];
|
|
1559
|
+
}
|
|
1560
|
+
function _setSaveResultObject(toObj) {
|
|
1561
|
+
if (toObj == null) toObj = null; //null or undefined
|
|
1562
|
+
this.__saveResultObject = toObj;
|
|
1563
|
+
return true;
|
|
1564
|
+
}
|
|
1565
|
+
_defineProperty(SimpleObject, "__db_name", "");
|
|
1566
|
+
_defineProperty(SimpleObject, "__object_name", "");
|
|
1567
|
+
//these properties should not be changed and are usually set by server
|
|
1568
|
+
_defineProperty(SimpleObject, "__unchangeables", void 0);
|
|
1569
|
+
//these properties can be directly changed and are included in deltaObject
|
|
1570
|
+
_defineProperty(SimpleObject, "__changeables", void 0);
|
|
1571
|
+
//these properties can only be changed by the _creator
|
|
1572
|
+
_defineProperty(SimpleObject, "__protectedProperties", void 0);
|
|
1573
|
+
//these properties will be evaluated when needed
|
|
1574
|
+
_defineProperty(SimpleObject, "__functionProperties", void 0);
|
|
1575
|
+
//apply these string formats
|
|
1576
|
+
_defineProperty(SimpleObject, "__formatList", void 0);
|
|
1577
|
+
//these properties usually are not directly changed and sometimes are included in deltaObject
|
|
1578
|
+
_defineProperty(SimpleObject, "__extraProperties", void 0);
|
|
1579
|
+
//types for children can be used when importing children
|
|
1580
|
+
_defineProperty(SimpleObject, "__childTypes", void 0);
|
|
1581
|
+
//these fields are used when importing
|
|
1582
|
+
_defineProperty(SimpleObject, "__importColumns", void 0);
|
|
1583
|
+
//these fields can be used when importing and checking if an item exists
|
|
1584
|
+
_defineProperty(SimpleObject, "__checkProperties", void 0);
|
|
1585
|
+
_defineProperty(SimpleObject, "__use_delta", true);
|
|
1586
|
+
var _default = exports["default"] = SimpleObject;
|