@azrico/webobject 1.4.51 → 1.4.54

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.
@@ -12,12 +12,25 @@ export declare class WebObject extends SimpleObject {
12
12
  static readonly __web_path: string;
13
13
  static readonly __web_type: string;
14
14
  static readonly __protectedProperties: string[];
15
+ static readonly __requiredProperties: never[];
15
16
  meta_data: MetaObject[];
16
17
  _id: string;
17
18
  _created_date?: string | Date;
18
19
  _creator?: string;
19
20
  _users?: string[];
20
21
  constructor(is_readonly?: boolean);
22
+ /**
23
+ * get a list of all users that work on this object
24
+ * _creator + _users + attentions(old)
25
+ * @returns
26
+ */
27
+ getAllUsers(): string[];
28
+ /**
29
+ * get a list of all users that work on the given object
30
+ * _creator + _users + attentions(old)
31
+ * @returns
32
+ */
33
+ static getAllUsers(obj: any): string[];
21
34
  /**
22
35
  * Update meta value of this object , meta data is stored in meta_data variable
23
36
  * @param key
@@ -57,20 +57,35 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
57
57
  _this.meta_data = [];
58
58
  return _this;
59
59
  }
60
- /* -------------------------------------------------------------------------- */
61
- /* Meta data */
62
- /* -------------------------------------------------------------------------- */
63
60
  /**
64
- * Update meta value of this object , meta data is stored in meta_data variable
65
- * @param key
66
- * @param value
67
- * @param createIfNotExists should we create a new meta if key does not exist
68
- * @param sendChange
61
+ * get a list of all users that work on this object
62
+ * _creator + _users + attentions(old)
69
63
  * @returns
70
64
  */
71
65
  _createClass(WebObject, [{
66
+ key: "getAllUsers",
67
+ value: function getAllUsers() {
68
+ return WebObject.getAllUsers(this);
69
+ }
70
+ /**
71
+ * get a list of all users that work on the given object
72
+ * _creator + _users + attentions(old)
73
+ * @returns
74
+ */
75
+ }, {
72
76
  key: "setMetaValue",
73
- value: function setMetaValue(key, value) {
77
+ value: /* -------------------------------------------------------------------------- */
78
+ /* Meta data */
79
+ /* -------------------------------------------------------------------------- */
80
+ /**
81
+ * Update meta value of this object , meta data is stored in meta_data variable
82
+ * @param key
83
+ * @param value
84
+ * @param createIfNotExists should we create a new meta if key does not exist
85
+ * @param sendChange
86
+ * @returns
87
+ */
88
+ function setMetaValue(key, value) {
74
89
  var createIfNotExists = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
75
90
  var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
76
91
  if (!this.canModify) {
@@ -191,7 +206,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
191
206
  value: function () {
192
207
  var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(p) {
193
208
  var _this2 = this;
194
- var final_object, isChild, useDelta, allProperties, chkChangables, useExtraProps, dlt, allkeys, changableKeys, parseObj, _parseObj, functionProps, index, fp, _iterator, _step, key, tempusers;
209
+ var final_object, isChild, useDelta, allProperties, chkChangables, useExtraProps, dlt, allkeys, changableKeys, parseObj, _parseObj, functionProps, index, fp, _iterator, _step, key, tempusers, simpleProps;
195
210
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
196
211
  while (1) switch (_context5.prev = _context5.next) {
197
212
  case 0:
@@ -327,8 +342,18 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
327
342
  });
328
343
  final_object["_users"] = (0, _object.wrap_array)(tempusers);
329
344
  }
345
+ simpleProps = (0, _object.object_getStatic)(this, "__simpleProperties");
346
+ if (Array.isArray(simpleProps)) {
347
+ simpleProps.forEach(function (sp) {
348
+ if (final_object[sp] == null) return;
349
+ var oldValue = final_object[sp];
350
+ var newKey = "simple_" + sp;
351
+ var newValue = typeof oldValue === "string" ? (0, _string.convert_to_simple_string)(oldValue) : undefined;
352
+ final_object[newKey] = newValue;
353
+ });
354
+ }
330
355
  return _context5.abrupt("return", final_object);
331
- case 35:
356
+ case 37:
332
357
  case "end":
333
358
  return _context5.stop();
334
359
  }
@@ -548,6 +573,11 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
548
573
  return WebObject.saveResultHasID(s);
549
574
  }
550
575
  }], [{
576
+ key: "getAllUsers",
577
+ value: function getAllUsers(obj) {
578
+ return (0, _object.array_remove_duplicates)((0, _object.array_merge)(obj._creator, (0, _object.wrap_array)(obj._users), (0, _object.wrap_array)(obj.attentions)));
579
+ }
580
+ }, {
551
581
  key: "getMeta",
552
582
  value: function getMeta(o, key) {
553
583
  if (o == null) return null;
@@ -874,5 +904,7 @@ exports.WebObject = WebObject;
874
904
  _defineProperty(WebObject, "__web_path", "");
875
905
  _defineProperty(WebObject, "__web_type", "");
876
906
  _defineProperty(WebObject, "__protectedProperties", ["_users"]);
907
+ //you cant create a new weboject without these properties
908
+ _defineProperty(WebObject, "__requiredProperties", []);
877
909
  var _default = WebObject;
878
910
  exports["default"] = _default;
@@ -13,6 +13,7 @@ export declare class SimpleObject extends MapableObject {
13
13
  static readonly __changeables?: string[];
14
14
  static readonly __protectedProperties?: string[];
15
15
  static readonly __functionProperties?: string[];
16
+ static readonly __simpleProperties?: string[];
16
17
  static readonly __extraProperties?: string[];
17
18
  static readonly __childTypes?: any[];
18
19
  static readonly __importColumns?: string[];
@@ -65,16 +66,6 @@ export declare class SimpleObject extends MapableObject {
65
66
  * @returns
66
67
  */
67
68
  setDefault: (key: WriteablePropOf<this>, value: any) => boolean;
68
- /**
69
- * set the value to its original
70
- * @param key
71
- */
72
- reset(key: WriteablePropOf<this>, notifyChanged?: sendChangesType): Promise<boolean>;
73
- /**
74
- * reset all values back to their original
75
- * @param key
76
- */
77
- resetAll(notifyChanged?: sendChangesType): Promise<boolean>;
78
69
  /**
79
70
  * set key of subObject
80
71
  * @param key
@@ -109,8 +100,20 @@ export declare class SimpleObject extends MapableObject {
109
100
  * Apply the changes and empty the delta object
110
101
  */
111
102
  apply_changes(): boolean;
103
+ /**
104
+ * set the value to its original
105
+ * @param key
106
+ */
107
+ reset(key: WriteablePropOf<this>, notifyChanged?: sendChangesType): Promise<boolean>;
108
+ /**
109
+ * reset all values back to their original
110
+ * difference between this and clear_changes is that this function also calls on_change
111
+ * @param key
112
+ */
113
+ resetAll(notifyChanged?: sendChangesType): Promise<boolean>;
112
114
  /**
113
115
  * clear and discard all changes
116
+ * does not call any on_change functions
114
117
  * @returns
115
118
  */
116
119
  clear_changes(): boolean;
@@ -205,85 +205,8 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
205
205
  return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
206
206
  }
207
207
  }, {
208
- key: "reset",
208
+ key: "setSubValue",
209
209
  value:
210
- /**
211
- * set the value to its original
212
- * @param key
213
- */
214
- function () {
215
- var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
216
- var notifyChanged,
217
- _args2 = arguments;
218
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
219
- while (1) switch (_context2.prev = _context2.next) {
220
- case 0:
221
- notifyChanged = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : "auto";
222
- _context2.next = 3;
223
- return this.setValue(key, this[key], notifyChanged);
224
- case 3:
225
- return _context2.abrupt("return", _context2.sent);
226
- case 4:
227
- case "end":
228
- return _context2.stop();
229
- }
230
- }, _callee2, this);
231
- }));
232
- function reset(_x3) {
233
- return _reset.apply(this, arguments);
234
- }
235
- return reset;
236
- }()
237
- /**
238
- * reset all values back to their original
239
- * @param key
240
- */
241
- }, {
242
- key: "resetAll",
243
- value: function () {
244
- var _resetAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
245
- var notifyChanged,
246
- fr,
247
- key,
248
- _args3 = arguments;
249
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
250
- while (1) switch (_context3.prev = _context3.next) {
251
- case 0:
252
- notifyChanged = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : "auto";
253
- fr = true;
254
- _context3.t0 = _regeneratorRuntime().keys(this.__delta);
255
- case 3:
256
- if ((_context3.t1 = _context3.t0()).done) {
257
- _context3.next = 13;
258
- break;
259
- }
260
- key = _context3.t1.value;
261
- _context3.t2 = fr;
262
- if (!_context3.t2) {
263
- _context3.next = 10;
264
- break;
265
- }
266
- _context3.next = 9;
267
- return this.reset(key, notifyChanged);
268
- case 9:
269
- _context3.t2 = _context3.sent;
270
- case 10:
271
- fr = _context3.t2;
272
- _context3.next = 3;
273
- break;
274
- case 13:
275
- return _context3.abrupt("return", fr);
276
- case 14:
277
- case "end":
278
- return _context3.stop();
279
- }
280
- }, _callee3, this);
281
- }));
282
- function resetAll() {
283
- return _resetAll.apply(this, arguments);
284
- }
285
- return resetAll;
286
- }()
287
210
  /**
288
211
  * set key of subObject
289
212
  * @param key
@@ -291,32 +214,30 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
291
214
  * @param subvalue
292
215
  * @return true if changed , false otherwise
293
216
  */
294
- }, {
295
- key: "setSubValue",
296
- value: function () {
297
- var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, objKey, subvalue) {
217
+ function () {
218
+ var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, objKey, subvalue) {
298
219
  var sendChanges,
299
220
  isValueChanged,
300
221
  subval,
301
- _args4 = arguments;
302
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
303
- while (1) switch (_context4.prev = _context4.next) {
222
+ _args2 = arguments;
223
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
224
+ while (1) switch (_context2.prev = _context2.next) {
304
225
  case 0:
305
- sendChanges = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "auto";
226
+ sendChanges = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : "auto";
306
227
  if (this.canModify) {
307
- _context4.next = 7;
228
+ _context2.next = 7;
308
229
  break;
309
230
  }
310
231
  if (!(this.__throw_errors !== false)) {
311
- _context4.next = 6;
232
+ _context2.next = 6;
312
233
  break;
313
234
  }
314
235
  throw Error("Cant use setValue when on readonly mode");
315
236
  case 6:
316
- return _context4.abrupt("return", false);
237
+ return _context2.abrupt("return", false);
317
238
  case 7:
318
239
  isValueChanged = false;
319
- _context4.prev = 8;
240
+ _context2.prev = 8;
320
241
  //if accessing subval of an object, make sure the object is not null
321
242
  subval = _classPrivateMethodGet(this, _getSubProperty, _getSubProperty2).call(this, key, objKey);
322
243
  if (!(0, _object.object_equals)(subval, subvalue, {
@@ -327,24 +248,24 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
327
248
  isValueChanged = true;
328
249
  } else isValueChanged = false;
329
250
  case 11:
330
- _context4.prev = 11;
251
+ _context2.prev = 11;
331
252
  if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
332
- _context4.next = 15;
253
+ _context2.next = 15;
333
254
  break;
334
255
  }
335
- _context4.next = 15;
256
+ _context2.next = 15;
336
257
  return this.notifyChanged("", key, objKey, subvalue);
337
258
  case 15:
338
- return _context4.finish(11);
259
+ return _context2.finish(11);
339
260
  case 16:
340
- return _context4.abrupt("return", isValueChanged);
261
+ return _context2.abrupt("return", isValueChanged);
341
262
  case 17:
342
263
  case "end":
343
- return _context4.stop();
264
+ return _context2.stop();
344
265
  }
345
- }, _callee4, this, [[8,, 11, 16]]);
266
+ }, _callee2, this, [[8,, 11, 16]]);
346
267
  }));
347
- function setSubValue(_x4, _x5, _x6) {
268
+ function setSubValue(_x3, _x4, _x5) {
348
269
  return _setSubValue.apply(this, arguments);
349
270
  }
350
271
  return setSubValue;
@@ -360,64 +281,64 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
360
281
  * @returns
361
282
  */
362
283
  function () {
363
- var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, value) {
284
+ var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, value) {
364
285
  var sendChanges,
365
286
  tempArray,
366
- _args5 = arguments;
367
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
368
- while (1) switch (_context5.prev = _context5.next) {
287
+ _args3 = arguments;
288
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
289
+ while (1) switch (_context3.prev = _context3.next) {
369
290
  case 0:
370
- sendChanges = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "auto";
291
+ sendChanges = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : "auto";
371
292
  if (!(value == null)) {
372
- _context5.next = 3;
293
+ _context3.next = 3;
373
294
  break;
374
295
  }
375
- return _context5.abrupt("return", false);
296
+ return _context3.abrupt("return", false);
376
297
  case 3:
377
298
  if (this.canModify) {
378
- _context5.next = 9;
299
+ _context3.next = 9;
379
300
  break;
380
301
  }
381
302
  if (!(this.__throw_errors !== false)) {
382
- _context5.next = 8;
303
+ _context3.next = 8;
383
304
  break;
384
305
  }
385
306
  throw Error("Cant use pushValue when on readonly mode");
386
307
  case 8:
387
- return _context5.abrupt("return", false);
308
+ return _context3.abrupt("return", false);
388
309
  case 9:
389
310
  if (_classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key) == null) {
390
311
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, []);
391
312
  }
392
313
  tempArray = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
393
314
  if (Array.isArray(tempArray)) {
394
- _context5.next = 17;
315
+ _context3.next = 17;
395
316
  break;
396
317
  }
397
318
  if (!(this.__throw_errors !== false)) {
398
- _context5.next = 16;
319
+ _context3.next = 16;
399
320
  break;
400
321
  }
401
322
  throw Error("Cant use pushValue on non Array keys");
402
323
  case 16:
403
- return _context5.abrupt("return", false);
324
+ return _context3.abrupt("return", false);
404
325
  case 17:
405
326
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, [].concat(_toConsumableArray(tempArray), [value]));
406
327
  if (!(sendChanges === true || sendChanges === "auto")) {
407
- _context5.next = 21;
328
+ _context3.next = 21;
408
329
  break;
409
330
  }
410
- _context5.next = 21;
331
+ _context3.next = 21;
411
332
  return this.notifyChanged("", key, value);
412
333
  case 21:
413
- return _context5.abrupt("return", tempArray);
334
+ return _context3.abrupt("return", tempArray);
414
335
  case 22:
415
336
  case "end":
416
- return _context5.stop();
337
+ return _context3.stop();
417
338
  }
418
- }, _callee5, this);
339
+ }, _callee3, this);
419
340
  }));
420
- function pushValue(_x7, _x8) {
341
+ function pushValue(_x6, _x7) {
421
342
  return _pushValue.apply(this, arguments);
422
343
  }
423
344
  return pushValue;
@@ -425,10 +346,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
425
346
  }, {
426
347
  key: "notifyChanged",
427
348
  value: function () {
428
- var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(type, key, value, subvalue) {
349
+ var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(type, key, value, subvalue) {
429
350
  var lc, manager_class;
430
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
431
- while (1) switch (_context6.prev = _context6.next) {
351
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
352
+ while (1) switch (_context4.prev = _context4.next) {
432
353
  case 0:
433
354
  if (value === undefined && type != "meta") value = this.getValue(key);
434
355
  this.__changed = true;
@@ -443,18 +364,18 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
443
364
  /* --------------------------- notify the manager --------------------------- */
444
365
  manager_class = this.manager;
445
366
  if (!(manager_class instanceof _ObjectManager["default"])) {
446
- _context6.next = 10;
367
+ _context4.next = 10;
447
368
  break;
448
369
  }
449
- _context6.next = 10;
370
+ _context4.next = 10;
450
371
  return manager_class.notifyChanged(type, key, value, subvalue);
451
372
  case 10:
452
373
  case "end":
453
- return _context6.stop();
374
+ return _context4.stop();
454
375
  }
455
- }, _callee6, this);
376
+ }, _callee4, this);
456
377
  }));
457
- function notifyChanged(_x9, _x10, _x11, _x12) {
378
+ function notifyChanged(_x8, _x9, _x10, _x11) {
458
379
  return _notifyChanged.apply(this, arguments);
459
380
  }
460
381
  return notifyChanged;
@@ -494,8 +415,89 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
494
415
  this.clear_changes();
495
416
  }
496
417
  }
418
+ /**
419
+ * set the value to its original
420
+ * @param key
421
+ */
422
+ }, {
423
+ key: "reset",
424
+ value: function () {
425
+ var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key) {
426
+ var notifyChanged,
427
+ _args5 = arguments;
428
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
429
+ while (1) switch (_context5.prev = _context5.next) {
430
+ case 0:
431
+ notifyChanged = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : "auto";
432
+ _context5.next = 3;
433
+ return this.setValue(key, this[key], notifyChanged);
434
+ case 3:
435
+ return _context5.abrupt("return", _context5.sent);
436
+ case 4:
437
+ case "end":
438
+ return _context5.stop();
439
+ }
440
+ }, _callee5, this);
441
+ }));
442
+ function reset(_x12) {
443
+ return _reset.apply(this, arguments);
444
+ }
445
+ return reset;
446
+ }()
447
+ /**
448
+ * reset all values back to their original
449
+ * difference between this and clear_changes is that this function also calls on_change
450
+ * @param key
451
+ */
452
+ }, {
453
+ key: "resetAll",
454
+ value: function () {
455
+ var _resetAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
456
+ var notifyChanged,
457
+ fr,
458
+ key,
459
+ _args6 = arguments;
460
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
461
+ while (1) switch (_context6.prev = _context6.next) {
462
+ case 0:
463
+ notifyChanged = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : "auto";
464
+ fr = true;
465
+ _context6.t0 = _regeneratorRuntime().keys(this.__delta);
466
+ case 3:
467
+ if ((_context6.t1 = _context6.t0()).done) {
468
+ _context6.next = 13;
469
+ break;
470
+ }
471
+ key = _context6.t1.value;
472
+ _context6.t2 = fr;
473
+ if (!_context6.t2) {
474
+ _context6.next = 10;
475
+ break;
476
+ }
477
+ _context6.next = 9;
478
+ return this.reset(key, notifyChanged);
479
+ case 9:
480
+ _context6.t2 = _context6.sent;
481
+ case 10:
482
+ fr = _context6.t2;
483
+ _context6.next = 3;
484
+ break;
485
+ case 13:
486
+ return _context6.abrupt("return", fr);
487
+ case 14:
488
+ case "end":
489
+ return _context6.stop();
490
+ }
491
+ }, _callee6, this);
492
+ }));
493
+ function resetAll() {
494
+ return _resetAll.apply(this, arguments);
495
+ }
496
+ return resetAll;
497
+ }()
497
498
  /**
498
499
  * clear and discard all changes
500
+ * does not call any on_change functions
499
501
  * @returns
500
502
  */
501
503
  }, {
@@ -1173,6 +1175,8 @@ _defineProperty(SimpleObject, "__changeables", void 0);
1173
1175
  _defineProperty(SimpleObject, "__protectedProperties", void 0);
1174
1176
  //these properties will be evaluated when needed
1175
1177
  _defineProperty(SimpleObject, "__functionProperties", void 0);
1178
+ //a lowercase copy of these properties will be saved
1179
+ _defineProperty(SimpleObject, "__simpleProperties", void 0);
1176
1180
  //these properties usually are not directly changed and sometimes are included in deltaObject
1177
1181
  _defineProperty(SimpleObject, "__extraProperties", void 0);
1178
1182
  //types for children can be used when importing children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.51",
3
+ "version": "1.4.54",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",
@@ -65,7 +65,7 @@
65
65
  "@azrico/global": "*",
66
66
  "@azrico/object": "*",
67
67
  "@azrico/string": "*",
68
- "@azrico/uid": "^*",
68
+ "@azrico/uid": "*",
69
69
  "lodash.clonedeep": "*"
70
70
  },
71
71
  "dependencies": {