@azrico/webobject 1.3.13 → 1.3.14
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.
|
@@ -75,10 +75,10 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
75
75
|
var createIfNotExists = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
76
76
|
var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
|
|
77
77
|
if (!this.canModify) {
|
|
78
|
-
if (this.__throw_errors) throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));else return false;
|
|
78
|
+
if (this.__throw_errors !== false) throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));else return false;
|
|
79
79
|
}
|
|
80
80
|
if (!key || typeof key != "string") {
|
|
81
|
-
if (this.__throw_errors) throw Error("Bad key at setMetaValue");else return false;
|
|
81
|
+
if (this.__throw_errors !== false) throw Error("Bad key at setMetaValue");else return false;
|
|
82
82
|
}
|
|
83
83
|
var old_value = WebObject.getMetaValue(this, key);
|
|
84
84
|
if ((0, _object.object_equals)(old_value, value)) return false; //same value, no changes
|
|
@@ -127,7 +127,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
127
127
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
128
128
|
while (1) switch (_context.prev = _context.next) {
|
|
129
129
|
case 0:
|
|
130
|
-
if (!this.__throw_errors) {
|
|
130
|
+
if (!(this.__throw_errors !== false)) {
|
|
131
131
|
_context.next = 2;
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
@@ -154,7 +154,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
154
154
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
155
155
|
while (1) switch (_context2.prev = _context2.next) {
|
|
156
156
|
case 0:
|
|
157
|
-
if (!this.__throw_errors) {
|
|
157
|
+
if (!(this.__throw_errors !== false)) {
|
|
158
158
|
_context2.next = 2;
|
|
159
159
|
break;
|
|
160
160
|
}
|
|
@@ -18,10 +18,10 @@ export declare class SimpleObject extends MapableObject {
|
|
|
18
18
|
__delta: Partial<this>;
|
|
19
19
|
__temp: any;
|
|
20
20
|
__changed: boolean;
|
|
21
|
-
__lastChanged
|
|
22
|
-
__is_readonly
|
|
23
|
-
__throw_errors
|
|
24
|
-
_deleted
|
|
21
|
+
__lastChanged?: string;
|
|
22
|
+
__is_readonly?: boolean;
|
|
23
|
+
__throw_errors?: boolean;
|
|
24
|
+
_deleted?: boolean;
|
|
25
25
|
_deletedBy?: string;
|
|
26
26
|
__errors?: any[];
|
|
27
27
|
__showErrors?: boolean;
|
|
@@ -46,9 +46,41 @@ export declare class SimpleObject extends MapableObject {
|
|
|
46
46
|
setValue(key: WriteablePropOf<this>, value: any, sendChanges?: sendChangesType): Promise<boolean>;
|
|
47
47
|
set: (key: WriteablePropOf<this>, value: any, sendChanges?: sendChangesType) => Promise<boolean>;
|
|
48
48
|
setTemp: (key: string, value: any) => any;
|
|
49
|
+
/**
|
|
50
|
+
* set value of a key only if the value is empty
|
|
51
|
+
* @param key
|
|
52
|
+
* @param value
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
49
55
|
setDefaultValue(key: WriteablePropOf<this>, value: any): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* set value of a key only if the value is empty
|
|
58
|
+
* @param key
|
|
59
|
+
* @param value
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
50
62
|
setDefault: (key: WriteablePropOf<this>, value: any) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* set the value to its original
|
|
65
|
+
* @param key
|
|
66
|
+
*/
|
|
67
|
+
resetValue(key: WriteablePropOf<this>): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* set the value to its original
|
|
70
|
+
* @param key
|
|
71
|
+
*/
|
|
72
|
+
reset: (key: WriteablePropOf<this>) => Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* clear any changes related to the key
|
|
75
|
+
* only works in when useDelta is true
|
|
76
|
+
* @param key
|
|
77
|
+
*/
|
|
51
78
|
clearDeltaValue(key: WriteablePropOf<this>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* clear any changes related to the key
|
|
81
|
+
* only works in when useDelta is true
|
|
82
|
+
* @param key
|
|
83
|
+
*/
|
|
52
84
|
clear: (key: WriteablePropOf<this>) => boolean;
|
|
53
85
|
/**
|
|
54
86
|
* set key of subObject
|
|
@@ -58,14 +90,43 @@ export declare class SimpleObject extends MapableObject {
|
|
|
58
90
|
* @return true if changed , false otherwise
|
|
59
91
|
*/
|
|
60
92
|
setSubValue(key: PropOf<this>, objKey: string, subvalue: any, sendChanges?: sendChangesType): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Push value on array
|
|
95
|
+
* @param key
|
|
96
|
+
* @param value
|
|
97
|
+
* @param sendChanges
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
61
100
|
pushValue<MKey extends PropOf<this>>(key: MKey, value: any, sendChanges?: sendChangesType): Promise<this[MKey] | false>;
|
|
101
|
+
/**
|
|
102
|
+
* notify the manager class when a value is changed on this object
|
|
103
|
+
* @param type
|
|
104
|
+
* @param key
|
|
105
|
+
* @param value
|
|
106
|
+
* @param subvalue
|
|
107
|
+
*/
|
|
62
108
|
notifyChanged(type: string, key: string, value: any, subvalue?: any): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* check if a key can be changed on an object
|
|
111
|
+
* @param object
|
|
112
|
+
* @param key
|
|
113
|
+
* @param useExtraProps
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
63
116
|
static canChangeKey(object: SimpleObject, key: string, useExtraProps: boolean): boolean;
|
|
64
117
|
/**
|
|
65
118
|
* Apply the changes and empty the delta object
|
|
66
119
|
*/
|
|
67
120
|
apply_changes(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* clear and discard all changes
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
68
125
|
clear_changes(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* clear and discard all temp values
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
69
130
|
clear_cache(): boolean;
|
|
70
131
|
/**
|
|
71
132
|
* Sets readonly property on given objects
|
|
@@ -68,16 +68,21 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
68
68
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setProperty);
|
|
69
69
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getSubProperty);
|
|
70
70
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSubProperty);
|
|
71
|
+
//an exact copy of this object is stored here
|
|
71
72
|
_defineProperty(_assertThisInitialized(_this), "__originalobject", void 0);
|
|
72
|
-
//changes
|
|
73
|
+
//changes are saved here
|
|
73
74
|
_defineProperty(_assertThisInitialized(_this), "__delta", {});
|
|
74
75
|
_defineProperty(_assertThisInitialized(_this), "__temp", undefined);
|
|
75
76
|
_defineProperty(_assertThisInitialized(_this), "__changed", false);
|
|
76
|
-
|
|
77
|
+
//the last thing that was changed on this object
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "__lastChanged", void 0);
|
|
79
|
+
//is the object read only
|
|
77
80
|
_defineProperty(_assertThisInitialized(_this), "__is_readonly", void 0);
|
|
81
|
+
//should we throw errors when encountering an error?
|
|
82
|
+
//is TRUE by default
|
|
78
83
|
_defineProperty(_assertThisInitialized(_this), "__throw_errors", void 0);
|
|
79
84
|
//is this object marked as deleted?
|
|
80
|
-
_defineProperty(_assertThisInitialized(_this), "_deleted",
|
|
85
|
+
_defineProperty(_assertThisInitialized(_this), "_deleted", void 0);
|
|
81
86
|
_defineProperty(_assertThisInitialized(_this), "_deletedBy", void 0);
|
|
82
87
|
//errors
|
|
83
88
|
_defineProperty(_assertThisInitialized(_this), "__errors", void 0);
|
|
@@ -86,7 +91,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
86
91
|
_defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
|
|
87
92
|
_defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
|
|
88
93
|
_defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
|
|
89
|
-
//sequence key
|
|
94
|
+
//sequence key (usually managed by the database)
|
|
90
95
|
_defineProperty(_assertThisInitialized(_this), "_index_key", "");
|
|
91
96
|
//sequence value , used to index the object with increasing numbers
|
|
92
97
|
_defineProperty(_assertThisInitialized(_this), "_index_value", -1);
|
|
@@ -95,14 +100,28 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
95
100
|
_defineProperty(_assertThisInitialized(_this), "getTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _getTempProperty, _getTempProperty2));
|
|
96
101
|
_defineProperty(_assertThisInitialized(_this), "set", _this.setValue);
|
|
97
102
|
_defineProperty(_assertThisInitialized(_this), "setTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _setTempProperty, _setTempProperty2));
|
|
103
|
+
/**
|
|
104
|
+
* set value of a key only if the value is empty
|
|
105
|
+
* @param key
|
|
106
|
+
* @param value
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
98
109
|
_defineProperty(_assertThisInitialized(_this), "setDefault", _this.setDefaultValue);
|
|
110
|
+
/**
|
|
111
|
+
* set the value to its original
|
|
112
|
+
* @param key
|
|
113
|
+
*/
|
|
114
|
+
_defineProperty(_assertThisInitialized(_this), "reset", _this.resetValue);
|
|
115
|
+
/**
|
|
116
|
+
* clear any changes related to the key
|
|
117
|
+
* only works in when useDelta is true
|
|
118
|
+
* @param key
|
|
119
|
+
*/
|
|
99
120
|
_defineProperty(_assertThisInitialized(_this), "clear", _this.clearDeltaValue);
|
|
100
121
|
_defineProperty(_assertThisInitialized(_this), "get_managerClass", function () {
|
|
101
122
|
return null;
|
|
102
123
|
});
|
|
103
|
-
if (_this._deleted == null) _this._deleted = false;
|
|
104
124
|
_this.__is_readonly = is_readonly;
|
|
105
|
-
_this.__throw_errors = true;
|
|
106
125
|
_this.clear_changes();
|
|
107
126
|
return _this;
|
|
108
127
|
}
|
|
@@ -150,7 +169,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
150
169
|
_context.next = 7;
|
|
151
170
|
break;
|
|
152
171
|
}
|
|
153
|
-
if (!this.__throw_errors) {
|
|
172
|
+
if (!(this.__throw_errors !== false)) {
|
|
154
173
|
_context.next = 6;
|
|
155
174
|
break;
|
|
156
175
|
}
|
|
@@ -193,12 +212,35 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
193
212
|
}()
|
|
194
213
|
}, {
|
|
195
214
|
key: "setDefaultValue",
|
|
196
|
-
value:
|
|
215
|
+
value:
|
|
216
|
+
/**
|
|
217
|
+
* set value of a key only if the value is empty
|
|
218
|
+
* @param key
|
|
219
|
+
* @param value
|
|
220
|
+
* @returns
|
|
221
|
+
*/
|
|
222
|
+
function setDefaultValue(key, value) {
|
|
197
223
|
return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
|
|
198
224
|
}
|
|
225
|
+
}, {
|
|
226
|
+
key: "resetValue",
|
|
227
|
+
value:
|
|
228
|
+
/**
|
|
229
|
+
* set the value to its original
|
|
230
|
+
* @param key
|
|
231
|
+
*/
|
|
232
|
+
function resetValue(key) {
|
|
233
|
+
return this.setValue(key, _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key, true));
|
|
234
|
+
}
|
|
199
235
|
}, {
|
|
200
236
|
key: "clearDeltaValue",
|
|
201
|
-
value:
|
|
237
|
+
value:
|
|
238
|
+
/**
|
|
239
|
+
* clear any changes related to the key
|
|
240
|
+
* only works in when useDelta is true
|
|
241
|
+
* @param key
|
|
242
|
+
*/
|
|
243
|
+
function clearDeltaValue(key) {
|
|
202
244
|
return _classPrivateMethodGet(this, _clearDeltaProperty, _clearDeltaProperty2).call(this, key);
|
|
203
245
|
}
|
|
204
246
|
}, {
|
|
@@ -225,7 +267,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
225
267
|
_context2.next = 7;
|
|
226
268
|
break;
|
|
227
269
|
}
|
|
228
|
-
if (!this.__throw_errors) {
|
|
270
|
+
if (!(this.__throw_errors !== false)) {
|
|
229
271
|
_context2.next = 6;
|
|
230
272
|
break;
|
|
231
273
|
}
|
|
@@ -265,7 +307,14 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
265
307
|
return _setSubValue.apply(this, arguments);
|
|
266
308
|
}
|
|
267
309
|
return setSubValue;
|
|
268
|
-
}()
|
|
310
|
+
}()
|
|
311
|
+
/**
|
|
312
|
+
* Push value on array
|
|
313
|
+
* @param key
|
|
314
|
+
* @param value
|
|
315
|
+
* @param sendChanges
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
269
318
|
}, {
|
|
270
319
|
key: "pushValue",
|
|
271
320
|
value: function () {
|
|
@@ -287,7 +336,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
287
336
|
_context3.next = 9;
|
|
288
337
|
break;
|
|
289
338
|
}
|
|
290
|
-
if (!this.__throw_errors) {
|
|
339
|
+
if (!(this.__throw_errors !== false)) {
|
|
291
340
|
_context3.next = 8;
|
|
292
341
|
break;
|
|
293
342
|
}
|
|
@@ -303,7 +352,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
303
352
|
_context3.next = 17;
|
|
304
353
|
break;
|
|
305
354
|
}
|
|
306
|
-
if (!this.__throw_errors) {
|
|
355
|
+
if (!(this.__throw_errors !== false)) {
|
|
307
356
|
_context3.next = 16;
|
|
308
357
|
break;
|
|
309
358
|
}
|
|
@@ -331,6 +380,13 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
331
380
|
}
|
|
332
381
|
return pushValue;
|
|
333
382
|
}()
|
|
383
|
+
/**
|
|
384
|
+
* notify the manager class when a value is changed on this object
|
|
385
|
+
* @param type
|
|
386
|
+
* @param key
|
|
387
|
+
* @param value
|
|
388
|
+
* @param subvalue
|
|
389
|
+
*/
|
|
334
390
|
}, {
|
|
335
391
|
key: "notifyChanged",
|
|
336
392
|
value: function () {
|
|
@@ -368,6 +424,13 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
368
424
|
}
|
|
369
425
|
return notifyChanged;
|
|
370
426
|
}()
|
|
427
|
+
/**
|
|
428
|
+
* check if a key can be changed on an object
|
|
429
|
+
* @param object
|
|
430
|
+
* @param key
|
|
431
|
+
* @param useExtraProps
|
|
432
|
+
* @returns
|
|
433
|
+
*/
|
|
371
434
|
}, {
|
|
372
435
|
key: "apply_changes",
|
|
373
436
|
value: /* -------------------------------------------------------------------------- */
|
|
@@ -396,6 +459,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
396
459
|
this.clear_changes();
|
|
397
460
|
}
|
|
398
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* clear and discard all changes
|
|
464
|
+
* @returns
|
|
465
|
+
*/
|
|
399
466
|
}, {
|
|
400
467
|
key: "clear_changes",
|
|
401
468
|
value: function clear_changes() {
|
|
@@ -403,10 +470,14 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
403
470
|
this.__changed = false;
|
|
404
471
|
return true;
|
|
405
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* clear and discard all temp values
|
|
475
|
+
* @returns
|
|
476
|
+
*/
|
|
406
477
|
}, {
|
|
407
478
|
key: "clear_cache",
|
|
408
479
|
value: function clear_cache() {
|
|
409
|
-
this.__temp
|
|
480
|
+
delete this.__temp;
|
|
410
481
|
return true;
|
|
411
482
|
}
|
|
412
483
|
/**
|
|
@@ -511,7 +582,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
511
582
|
}, {
|
|
512
583
|
key: "lastChanged",
|
|
513
584
|
get: function get() {
|
|
514
|
-
return this.__lastChanged;
|
|
585
|
+
return this.__lastChanged || "";
|
|
515
586
|
}
|
|
516
587
|
}, {
|
|
517
588
|
key: "manager",
|
|
@@ -851,9 +922,17 @@ function _getSubProperty2(key, subkey) {
|
|
|
851
922
|
return subobj[subkey];
|
|
852
923
|
}
|
|
853
924
|
function _setProperty2(key, value) {
|
|
854
|
-
this
|
|
855
|
-
|
|
856
|
-
|
|
925
|
+
if (this[key] === value) {
|
|
926
|
+
/**
|
|
927
|
+
* We set something back to its original value so no need to save it as Delta
|
|
928
|
+
*/
|
|
929
|
+
delete this.__delta[key];
|
|
930
|
+
return false;
|
|
931
|
+
} else {
|
|
932
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
933
|
+
if (!this.__use_delta) this[key] = value; //on noDelta mode, also update the obj
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
857
936
|
}
|
|
858
937
|
function _clearDeltaProperty2(key) {
|
|
859
938
|
if (this.__use_delta) {
|