@azrico/webobject 1.3.12 → 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,8 +46,42 @@ 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
|
+
*/
|
|
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
|
+
*/
|
|
84
|
+
clear: (key: WriteablePropOf<this>) => boolean;
|
|
51
85
|
/**
|
|
52
86
|
* set key of subObject
|
|
53
87
|
* @param key
|
|
@@ -56,14 +90,43 @@ export declare class SimpleObject extends MapableObject {
|
|
|
56
90
|
* @return true if changed , false otherwise
|
|
57
91
|
*/
|
|
58
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
|
+
*/
|
|
59
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
|
+
*/
|
|
60
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
|
+
*/
|
|
61
116
|
static canChangeKey(object: SimpleObject, key: string, useExtraProps: boolean): boolean;
|
|
62
117
|
/**
|
|
63
118
|
* Apply the changes and empty the delta object
|
|
64
119
|
*/
|
|
65
120
|
apply_changes(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* clear and discard all changes
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
66
125
|
clear_changes(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* clear and discard all temp values
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
67
130
|
clear_cache(): boolean;
|
|
68
131
|
/**
|
|
69
132
|
* Sets readonly property on given objects
|
|
@@ -41,6 +41,7 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
41
41
|
var _setSubProperty = /*#__PURE__*/new WeakSet();
|
|
42
42
|
var _getSubProperty = /*#__PURE__*/new WeakSet();
|
|
43
43
|
var _setProperty = /*#__PURE__*/new WeakSet();
|
|
44
|
+
var _clearDeltaProperty = /*#__PURE__*/new WeakSet();
|
|
44
45
|
var _setDefaultProperty = /*#__PURE__*/new WeakSet();
|
|
45
46
|
var _getProperty = /*#__PURE__*/new WeakSet();
|
|
46
47
|
var _getTempProperty = /*#__PURE__*/new WeakSet();
|
|
@@ -63,19 +64,25 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
63
64
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getTempProperty);
|
|
64
65
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getProperty);
|
|
65
66
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setDefaultProperty);
|
|
67
|
+
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _clearDeltaProperty);
|
|
66
68
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setProperty);
|
|
67
69
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getSubProperty);
|
|
68
70
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSubProperty);
|
|
71
|
+
//an exact copy of this object is stored here
|
|
69
72
|
_defineProperty(_assertThisInitialized(_this), "__originalobject", void 0);
|
|
70
|
-
//changes
|
|
73
|
+
//changes are saved here
|
|
71
74
|
_defineProperty(_assertThisInitialized(_this), "__delta", {});
|
|
72
75
|
_defineProperty(_assertThisInitialized(_this), "__temp", undefined);
|
|
73
76
|
_defineProperty(_assertThisInitialized(_this), "__changed", false);
|
|
74
|
-
|
|
77
|
+
//the last thing that was changed on this object
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "__lastChanged", void 0);
|
|
79
|
+
//is the object read only
|
|
75
80
|
_defineProperty(_assertThisInitialized(_this), "__is_readonly", void 0);
|
|
81
|
+
//should we throw errors when encountering an error?
|
|
82
|
+
//is TRUE by default
|
|
76
83
|
_defineProperty(_assertThisInitialized(_this), "__throw_errors", void 0);
|
|
77
84
|
//is this object marked as deleted?
|
|
78
|
-
_defineProperty(_assertThisInitialized(_this), "_deleted",
|
|
85
|
+
_defineProperty(_assertThisInitialized(_this), "_deleted", void 0);
|
|
79
86
|
_defineProperty(_assertThisInitialized(_this), "_deletedBy", void 0);
|
|
80
87
|
//errors
|
|
81
88
|
_defineProperty(_assertThisInitialized(_this), "__errors", void 0);
|
|
@@ -84,7 +91,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
84
91
|
_defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
|
|
85
92
|
_defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
|
|
86
93
|
_defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
|
|
87
|
-
//sequence key
|
|
94
|
+
//sequence key (usually managed by the database)
|
|
88
95
|
_defineProperty(_assertThisInitialized(_this), "_index_key", "");
|
|
89
96
|
//sequence value , used to index the object with increasing numbers
|
|
90
97
|
_defineProperty(_assertThisInitialized(_this), "_index_value", -1);
|
|
@@ -93,13 +100,28 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
93
100
|
_defineProperty(_assertThisInitialized(_this), "getTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _getTempProperty, _getTempProperty2));
|
|
94
101
|
_defineProperty(_assertThisInitialized(_this), "set", _this.setValue);
|
|
95
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
|
+
*/
|
|
96
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
|
+
*/
|
|
120
|
+
_defineProperty(_assertThisInitialized(_this), "clear", _this.clearDeltaValue);
|
|
97
121
|
_defineProperty(_assertThisInitialized(_this), "get_managerClass", function () {
|
|
98
122
|
return null;
|
|
99
123
|
});
|
|
100
|
-
if (_this._deleted == null) _this._deleted = false;
|
|
101
124
|
_this.__is_readonly = is_readonly;
|
|
102
|
-
_this.__throw_errors = true;
|
|
103
125
|
_this.clear_changes();
|
|
104
126
|
return _this;
|
|
105
127
|
}
|
|
@@ -147,7 +169,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
147
169
|
_context.next = 7;
|
|
148
170
|
break;
|
|
149
171
|
}
|
|
150
|
-
if (!this.__throw_errors) {
|
|
172
|
+
if (!(this.__throw_errors !== false)) {
|
|
151
173
|
_context.next = 6;
|
|
152
174
|
break;
|
|
153
175
|
}
|
|
@@ -190,9 +212,37 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
190
212
|
}()
|
|
191
213
|
}, {
|
|
192
214
|
key: "setDefaultValue",
|
|
193
|
-
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) {
|
|
194
223
|
return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
|
|
195
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
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
key: "clearDeltaValue",
|
|
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) {
|
|
244
|
+
return _classPrivateMethodGet(this, _clearDeltaProperty, _clearDeltaProperty2).call(this, key);
|
|
245
|
+
}
|
|
196
246
|
}, {
|
|
197
247
|
key: "setSubValue",
|
|
198
248
|
value:
|
|
@@ -217,7 +267,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
217
267
|
_context2.next = 7;
|
|
218
268
|
break;
|
|
219
269
|
}
|
|
220
|
-
if (!this.__throw_errors) {
|
|
270
|
+
if (!(this.__throw_errors !== false)) {
|
|
221
271
|
_context2.next = 6;
|
|
222
272
|
break;
|
|
223
273
|
}
|
|
@@ -257,7 +307,14 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
257
307
|
return _setSubValue.apply(this, arguments);
|
|
258
308
|
}
|
|
259
309
|
return setSubValue;
|
|
260
|
-
}()
|
|
310
|
+
}()
|
|
311
|
+
/**
|
|
312
|
+
* Push value on array
|
|
313
|
+
* @param key
|
|
314
|
+
* @param value
|
|
315
|
+
* @param sendChanges
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
261
318
|
}, {
|
|
262
319
|
key: "pushValue",
|
|
263
320
|
value: function () {
|
|
@@ -279,7 +336,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
279
336
|
_context3.next = 9;
|
|
280
337
|
break;
|
|
281
338
|
}
|
|
282
|
-
if (!this.__throw_errors) {
|
|
339
|
+
if (!(this.__throw_errors !== false)) {
|
|
283
340
|
_context3.next = 8;
|
|
284
341
|
break;
|
|
285
342
|
}
|
|
@@ -295,7 +352,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
295
352
|
_context3.next = 17;
|
|
296
353
|
break;
|
|
297
354
|
}
|
|
298
|
-
if (!this.__throw_errors) {
|
|
355
|
+
if (!(this.__throw_errors !== false)) {
|
|
299
356
|
_context3.next = 16;
|
|
300
357
|
break;
|
|
301
358
|
}
|
|
@@ -323,6 +380,13 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
323
380
|
}
|
|
324
381
|
return pushValue;
|
|
325
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
|
+
*/
|
|
326
390
|
}, {
|
|
327
391
|
key: "notifyChanged",
|
|
328
392
|
value: function () {
|
|
@@ -360,6 +424,13 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
360
424
|
}
|
|
361
425
|
return notifyChanged;
|
|
362
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
|
+
*/
|
|
363
434
|
}, {
|
|
364
435
|
key: "apply_changes",
|
|
365
436
|
value: /* -------------------------------------------------------------------------- */
|
|
@@ -388,6 +459,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
388
459
|
this.clear_changes();
|
|
389
460
|
}
|
|
390
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* clear and discard all changes
|
|
464
|
+
* @returns
|
|
465
|
+
*/
|
|
391
466
|
}, {
|
|
392
467
|
key: "clear_changes",
|
|
393
468
|
value: function clear_changes() {
|
|
@@ -395,10 +470,14 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
395
470
|
this.__changed = false;
|
|
396
471
|
return true;
|
|
397
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* clear and discard all temp values
|
|
475
|
+
* @returns
|
|
476
|
+
*/
|
|
398
477
|
}, {
|
|
399
478
|
key: "clear_cache",
|
|
400
479
|
value: function clear_cache() {
|
|
401
|
-
this.__temp
|
|
480
|
+
delete this.__temp;
|
|
402
481
|
return true;
|
|
403
482
|
}
|
|
404
483
|
/**
|
|
@@ -503,7 +582,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
503
582
|
}, {
|
|
504
583
|
key: "lastChanged",
|
|
505
584
|
get: function get() {
|
|
506
|
-
return this.__lastChanged;
|
|
585
|
+
return this.__lastChanged || "";
|
|
507
586
|
}
|
|
508
587
|
}, {
|
|
509
588
|
key: "manager",
|
|
@@ -843,9 +922,24 @@ function _getSubProperty2(key, subkey) {
|
|
|
843
922
|
return subobj[subkey];
|
|
844
923
|
}
|
|
845
924
|
function _setProperty2(key, value) {
|
|
846
|
-
this
|
|
847
|
-
|
|
848
|
-
|
|
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
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function _clearDeltaProperty2(key) {
|
|
938
|
+
if (this.__use_delta) {
|
|
939
|
+
delete this.__delta[key];
|
|
940
|
+
return true;
|
|
941
|
+
}
|
|
942
|
+
return false;
|
|
849
943
|
}
|
|
850
944
|
function _setDefaultProperty2(key, value) {
|
|
851
945
|
//@ts-ignore
|