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