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