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