@azrico/webobject 1.5.9 → 1.5.11

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.
@@ -1,14 +1,5 @@
1
- import { SimpleObject, sendChangesType } from "../index";
1
+ import { SimpleObject, deltaParams, sendChangesType } from "../index";
2
2
  import { WebObjectManager } from "../index";
3
- export type deltaParams = {
4
- type?: string;
5
- isChild?: boolean;
6
- useDelta?: boolean;
7
- allProperties?: boolean;
8
- extraProperties?: boolean;
9
- needId?: boolean;
10
- applyFilter?: boolean;
11
- };
12
3
  export declare class WebObject extends SimpleObject {
13
4
  static readonly __web_path: string;
14
5
  static readonly __protectedProperties: string[];
@@ -80,12 +71,13 @@ export declare class WebObject extends SimpleObject {
80
71
  */
81
72
  get_basicObject(): Promise<Partial<this>>;
82
73
  /**
83
- * calls the `get_deltaObject` with `allProperties=true` `extraProperties=true`
74
+ * calls the `get_deltaObject` with
75
+ * `allProperties` `extraProperties` `tempProperties`
76
+ * set to true
84
77
  *
85
- * useful in server applications
86
78
  * @returns
87
79
  */
88
- get_fullDeltaObject(p?: deltaParams): Promise<any>;
80
+ get_fullObject(p?: deltaParams): Promise<any>;
89
81
  /**
90
82
  * You will post this to the server for saving
91
83
  * automatically removes unchangable fields
@@ -480,26 +480,26 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
480
480
  key: "get_basicObject",
481
481
  value: (function () {
482
482
  var _get_basicObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
483
- var fulldelta, key, element;
483
+ var fullobject, key, element;
484
484
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
485
485
  while (1) switch (_context8.prev = _context8.next) {
486
486
  case 0:
487
487
  _context8.next = 2;
488
- return this.get_fullDeltaObject();
488
+ return this.get_fullObject();
489
489
  case 2:
490
- fulldelta = _context8.sent;
491
- for (key in fulldelta) {
492
- element = fulldelta[key];
490
+ fullobject = _context8.sent;
491
+ for (key in fullobject) {
492
+ element = fullobject[key];
493
493
  /* --------------------------- check for id fields -------------------------- */
494
494
  if (element != null && _typeof(element) === "object") {
495
495
  if ((key === "id" || key.endsWith("_id")) && typeof element.toString === "function") {
496
- fulldelta[key] = String(element);
496
+ fullobject[key] = String(element);
497
497
  } else {
498
- fulldelta[key] = JSON.parse(JSON.stringify(element));
498
+ fullobject[key] = JSON.parse(JSON.stringify(element));
499
499
  }
500
500
  }
501
501
  }
502
- return _context8.abrupt("return", fulldelta);
502
+ return _context8.abrupt("return", fullobject);
503
503
  case 5:
504
504
  case "end":
505
505
  return _context8.stop();
@@ -512,24 +512,26 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
512
512
  return get_basicObject;
513
513
  }()
514
514
  /**
515
- * calls the `get_deltaObject` with `allProperties=true` `extraProperties=true`
515
+ * calls the `get_deltaObject` with
516
+ * `allProperties` `extraProperties` `tempProperties`
517
+ * set to true
516
518
  *
517
- * useful in server applications
518
519
  * @returns
519
520
  */
520
521
  )
521
522
  }, {
522
- key: "get_fullDeltaObject",
523
+ key: "get_fullObject",
523
524
  value: (function () {
524
- var _get_fullDeltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(p) {
525
+ var _get_fullObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(p) {
525
526
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
526
527
  while (1) switch (_context9.prev = _context9.next) {
527
528
  case 0:
528
529
  _context9.next = 2;
529
- return this.get_deltaObject({
530
+ return this.get_deltaObject(_objectSpread({
530
531
  allProperties: true,
531
- extraProperties: true
532
- });
532
+ extraProperties: true,
533
+ tempProperties: true
534
+ }, p));
533
535
  case 2:
534
536
  return _context9.abrupt("return", _context9.sent);
535
537
  case 3:
@@ -538,10 +540,10 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
538
540
  }
539
541
  }, _callee9, this);
540
542
  }));
541
- function get_fullDeltaObject(_x3) {
542
- return _get_fullDeltaObject.apply(this, arguments);
543
+ function get_fullObject(_x3) {
544
+ return _get_fullObject.apply(this, arguments);
543
545
  }
544
- return get_fullDeltaObject;
546
+ return get_fullObject;
545
547
  }()
546
548
  /**
547
549
  * You will post this to the server for saving
@@ -553,7 +555,7 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
553
555
  key: "get_deltaObject",
554
556
  value: (function () {
555
557
  var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(p) {
556
- var final_object, isChild, useDelta, allProperties, needId, chkChangables, useExtraProps, dlt, key, changableKeys, functionProps, index, fp, parseObj, _parseObj, _iterator, _step, _key, gotIndex, gotId, tempusers;
558
+ var final_object, useDelta, chkChangables, changedFields, key, changableKeys, functionProps, index, fp, parseObj, _parseObj, _iterator, _step, _key, gotIndex, gotId, tempusers;
557
559
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
558
560
  while (1) switch (_context12.prev = _context12.next) {
559
561
  case 0:
@@ -628,107 +630,95 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
628
630
  };
629
631
  if (!p) p = {};
630
632
  final_object = {}; //@ts-ignore
631
- isChild = Boolean(p.isChild || p.ischild); //@ts-ignore
632
- useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
633
- allProperties = Boolean(
634
- //@ts-ignore
635
- p.allProperties || p.allproperties || isChild); //@ts-ignore
636
- needId = Boolean(p.needId || p.needid);
633
+ useDelta = this.__use_delta || p.useDelta;
637
634
  chkChangables = this.__changeables != null || this.__unchangeables != null;
638
- useExtraProps = Boolean(p.extraProperties); //child objects usually dont update their __delta, so we read info from all of its properties
639
- dlt = allProperties || !useDelta && isChild && chkChangables ? _objectSpread({}, this.allproperties) : _objectSpread({}, this.__delta);
635
+ /**
636
+ * child objects usually dont update their __delta
637
+ * so we read info from all of its properties
638
+ */
639
+ changedFields = p.allProperties || !useDelta && p.isChild && chkChangables ? _objectSpread({}, this.allproperties) : _objectSpread({}, this.__delta);
640
640
  /* ------------- parse children that have WebObject as delta ------------- */
641
641
  _context12.t0 = _regeneratorRuntime().keys(this);
642
- case 12:
642
+ case 8:
643
643
  if ((_context12.t1 = _context12.t0()).done) {
644
- _context12.next = 19;
644
+ _context12.next = 15;
645
645
  break;
646
646
  }
647
647
  key = _context12.t1.value;
648
- if (!(key.startsWith("__") || key in dlt)) {
649
- _context12.next = 16;
648
+ if (!(key.startsWith("__") || key in changedFields)) {
649
+ _context12.next = 12;
650
650
  break;
651
651
  }
652
- return _context12.abrupt("continue", 12);
653
- case 16:
652
+ return _context12.abrupt("continue", 8);
653
+ case 12:
654
654
  if (_WebObjectHelper["default"].isChangedWebObjectField(this[key])) {
655
655
  /**
656
- * if an array child has any change we must change the whole array to database
656
+ * if a child has any change we must add it into our delta
657
+ * notice that the changes may not be saved to database depending on __changeables
658
+ * but they are changes nevertheless
657
659
  */
658
- dlt[key] = this[key];
660
+ changedFields[key] = this[key];
659
661
  }
660
- _context12.next = 12;
662
+ _context12.next = 8;
661
663
  break;
662
- case 19:
664
+ case 15:
663
665
  /* ------------------------- get all changeable keys ------------------------ */
664
- changableKeys = (0, _object.array_intersection)(Object.keys(dlt), WebObject.getChangeableKeys(this, {
665
- useExtraProps: useExtraProps,
666
- ignoreProtected: allProperties
667
- })); // chkChangables
668
- // ? allkeys.filter((s) =>
669
- // SimpleObject.canChangeKey(this, s, {
670
- // useExtraProps: useExtraProps,
671
- // ignoreProtected: allProperties,
672
- // }),
673
- // )
674
- // : allkeys;
675
- _context12.next = 22;
666
+ changableKeys = (0, _object.array_intersection)(Object.keys(changedFields), WebObject.getChangeableKeys(this, p));
667
+ _context12.next = 18;
676
668
  return _convert["default"].applyFormats({
677
- inputobject: dlt,
669
+ inputobject: changedFields,
678
670
  formats: (0, _object.object_getStatic)(this, "__formatList"),
679
671
  changableKeys: changableKeys,
680
672
  applyDefaults: true
681
673
  });
682
- case 22:
674
+ case 18:
683
675
  /* -------------------------------------------------------------------------- */
684
676
  /* __functionProperties */
685
677
  /* -------------------------------------------------------------------------- */
686
678
  functionProps = (0, _object.object_getStatic)(this, "__functionProperties");
687
- if (Array.isArray(functionProps)) {
688
- for (index = 0; index < functionProps.length; index++) {
689
- fp = functionProps[index];
690
- if (dlt[fp]) dlt[fp] = (0, _object.fn_eval_this)(this, dlt[fp]);
691
- }
679
+ for (index = 0; index < functionProps.length; index++) {
680
+ fp = functionProps[index];
681
+ if (changedFields[fp]) changedFields[fp] = (0, _object.fn_eval_this)(this, changedFields[fp]);
692
682
  }
693
683
  /* -------------------------------------------------------------------------- */
694
684
  /* parse all changableKeys */
695
685
  /* -------------------------------------------------------------------------- */
696
686
  _iterator = _createForOfIteratorHelper(changableKeys);
697
- _context12.prev = 25;
687
+ _context12.prev = 21;
698
688
  _iterator.s();
699
- case 27:
689
+ case 23:
700
690
  if ((_step = _iterator.n()).done) {
701
- _context12.next = 34;
691
+ _context12.next = 30;
702
692
  break;
703
693
  }
704
694
  _key = _step.value;
705
- _context12.next = 31;
706
- return parseObj(dlt[_key]);
707
- case 31:
708
- final_object[_key] = _context12.sent;
709
- case 32:
710
695
  _context12.next = 27;
696
+ return parseObj(changedFields[_key]);
697
+ case 27:
698
+ final_object[_key] = _context12.sent;
699
+ case 28:
700
+ _context12.next = 23;
711
701
  break;
712
- case 34:
713
- _context12.next = 39;
702
+ case 30:
703
+ _context12.next = 35;
714
704
  break;
715
- case 36:
716
- _context12.prev = 36;
717
- _context12.t2 = _context12["catch"](25);
705
+ case 32:
706
+ _context12.prev = 32;
707
+ _context12.t2 = _context12["catch"](21);
718
708
  _iterator.e(_context12.t2);
719
- case 39:
720
- _context12.prev = 39;
709
+ case 35:
710
+ _context12.prev = 35;
721
711
  _iterator.f();
722
- return _context12.finish(39);
723
- case 42:
712
+ return _context12.finish(35);
713
+ case 38:
724
714
  /* -------------------- add acrhived and date properties -------------------- */
725
- if (allProperties) {
715
+ if (p.allProperties) {
726
716
  final_object["_created_date"] = this["_created_date"];
727
717
  final_object["_archived"] = this.isArchived;
728
718
  final_object["_deleted"] = this.isDeleted;
729
719
  }
730
720
  /* ---------------------------- add id properties --------------------------- */
731
- if (allProperties || needId) {
721
+ if (p.allProperties || p.needId) {
732
722
  if (this["_index_key"]) final_object["_index_key"] = this["_index_key"];
733
723
  gotIndex = this.getIndex();
734
724
  gotId = this.getID();
@@ -746,11 +736,11 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
746
736
  final_object["_users"] = (0, _object.wrap_array)(tempusers);
747
737
  }
748
738
  return _context12.abrupt("return", final_object);
749
- case 46:
739
+ case 42:
750
740
  case "end":
751
741
  return _context12.stop();
752
742
  }
753
- }, _callee12, this, [[25, 36, 39, 42]]);
743
+ }, _callee12, this, [[21, 32, 35, 38]]);
754
744
  }));
755
745
  function get_deltaObject(_x4) {
756
746
  return _get_deltaObject.apply(this, arguments);
@@ -7,23 +7,31 @@ export type saveType = "normal" | "quick";
7
7
  export type sendChangesType = boolean | "auto";
8
8
  export type WithManager<T extends SimpleObject> = Ensure<T, "manager">;
9
9
  export type WithManagerOrNot<T extends SimpleObject> = T | WithManager<T>;
10
- type getKeysProps = {
11
- useExtraProps?: boolean;
12
- ignoreProtected?: boolean;
10
+ export type deltaParams = {
11
+ type?: string;
12
+ useDelta?: boolean;
13
+ isChild?: boolean;
14
+ allProperties?: boolean;
15
+ extraProperties?: boolean;
16
+ tempProperties?: boolean;
17
+ bypassProtected?: boolean;
18
+ needId?: boolean;
19
+ applyFilter?: boolean;
13
20
  };
14
21
  export declare class SimpleObject extends MapableObject {
15
22
  #private;
16
23
  static readonly __db_name: string;
17
24
  static readonly __object_name: string;
18
- static readonly __unchangeables?: string[];
19
- static readonly __changeables?: string[];
20
- static readonly __protectedProperties?: string[];
21
- static readonly __functionProperties?: string[];
25
+ static readonly __unchangeables: string[];
26
+ static readonly __changeables: string[];
27
+ static readonly __extraProperties: string[];
28
+ static readonly __tempProperties: string[];
29
+ static readonly __protectedProperties: string[];
30
+ static readonly __functionProperties: string[];
22
31
  static readonly __formatList?: formatObject;
23
- static readonly __extraProperties?: string[];
24
32
  static readonly __childTypes?: any[];
25
33
  static readonly __importColumns?: string[];
26
- static readonly __checkProperties?: string[];
34
+ static readonly __checkProperties: string[];
27
35
  static readonly __use_delta: boolean;
28
36
  _static(): Function;
29
37
  protected __originalobject?: this;
@@ -158,7 +166,13 @@ export declare class SimpleObject extends MapableObject {
158
166
  * @returns true if manager was notified. false otherwise
159
167
  */
160
168
  notifyChanged<MKey extends PropOf<this>>(type: string, key: MKey | string, value: any, subvalue?: any): Promise<false | any[] | undefined>;
161
- static getChangeableKeys(object: SimpleObject, options: getKeysProps): any[];
169
+ /**
170
+ * get a list of all keys that can be changed in given objcet
171
+ * @param object
172
+ * @param options
173
+ * @returns
174
+ */
175
+ static getChangeableKeys(object: SimpleObject, options: deltaParams): any[];
162
176
  /**
163
177
  * check if a key can be changed on an object
164
178
  * @param object the object we are checking
@@ -166,7 +180,7 @@ export declare class SimpleObject extends MapableObject {
166
180
  * @param useExtraProps should we check extra props?
167
181
  * @returns
168
182
  */
169
- static canChangeKey(object: SimpleObject, key: string, options: getKeysProps): boolean;
183
+ static canChangeKey(object: SimpleObject, key: string, options: deltaParams): boolean;
170
184
  static hasIllegalChanges(referenceObject: any, changesObject: any, updaterUser: any): boolean;
171
185
  /**
172
186
  * Apply all the changes and empty the delta object
@@ -182,10 +182,11 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
182
182
  _context.next = 7;
183
183
  break;
184
184
  }
185
- throw Error("Cant use set (".concat(String(key), ") when on readonly mode"));
185
+ throw Error("Cant use set(".concat(String(key), ") when on readonly mode"));
186
186
  case 7:
187
187
  return _context.abrupt("return", false);
188
188
  case 8:
189
+ /* -------------------------------------------------------------------------- */
189
190
  keyExists = false;
190
191
  if (typeof key === "string" && key.includes(".")) {
191
192
  /* -------------------------------------------------------------------------- */
@@ -706,7 +707,14 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
706
707
  return _notifyChanged.apply(this, arguments);
707
708
  }
708
709
  return notifyChanged;
709
- }())
710
+ }()
711
+ /**
712
+ * get a list of all keys that can be changed in given objcet
713
+ * @param object
714
+ * @param options
715
+ * @returns
716
+ */
717
+ )
710
718
  }, {
711
719
  key: "apply_changes",
712
720
  value: /* -------------------------------------------------------------------------- */
@@ -1269,26 +1277,26 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1269
1277
  }, {
1270
1278
  key: "getChangeableKeys",
1271
1279
  value: function getChangeableKeys(object, options) {
1272
- var _key_list2;
1280
+ var _key_list;
1273
1281
  if (!object) return [];
1274
- var useExtraProps = options.useExtraProps,
1275
- ignoreProtected = options.ignoreProtected;
1276
1282
  var key_list = [];
1277
- if (useExtraProps) {
1278
- var _key_list;
1279
- var __extraProperties = object.constructor["__extraProperties"];
1280
- if (!(0, _object.array_isEmpty)(__extraProperties)) (_key_list = key_list).push.apply(_key_list, _toConsumableArray(__extraProperties));
1281
- }
1282
- /* -------------------------------------------------------------------------- */
1283
- var __changeables = object.constructor["__changeables"];
1284
- if (!(0, _object.array_isEmpty)(__changeables)) (_key_list2 = key_list).push.apply(_key_list2, _toConsumableArray(__changeables));
1283
+ (_key_list = key_list).push.apply(_key_list, _toConsumableArray(object.constructor["__changeables"]));
1285
1284
  var __unchangeables = object.constructor["__unchangeables"];
1286
1285
  if (!(0, _object.array_isEmpty)(__unchangeables)) {
1287
1286
  key_list = key_list.filter(function (s) {
1288
1287
  return !__unchangeables.includes(s);
1289
1288
  });
1290
1289
  }
1291
- if (ignoreProtected !== true) {
1290
+ /* -------------------------------------------------------------------------- */
1291
+ if (options.extraProperties) {
1292
+ var _key_list2;
1293
+ (_key_list2 = key_list).push.apply(_key_list2, _toConsumableArray(object.constructor["__extraProperties"]));
1294
+ }
1295
+ if (options.tempProperties) {
1296
+ var _key_list3;
1297
+ (_key_list3 = key_list).push.apply(_key_list3, _toConsumableArray(object.constructor["__tempProperties"]));
1298
+ }
1299
+ if (options.bypassProtected !== true && !options.allProperties) {
1292
1300
  var __protectedProperties = object.constructor["__protectedProperties"];
1293
1301
  //protected keys can only be changed by the creator of this object
1294
1302
  //make sure you set the is_current_user function correctly
@@ -1313,36 +1321,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1313
1321
  if (!object || !key) return false;
1314
1322
  var keys = this.getChangeableKeys(object, options);
1315
1323
  return keys.includes(key);
1316
- // const {useExtraProps, ignoreProtected} = options;
1317
- // if (useExtraProps) {
1318
- // const __extraProperties = object.constructor["__extraProperties"];
1319
- // if (__extraProperties != null && __extraProperties.includes(key))
1320
- // return true;
1321
- // }
1322
- // /* -------------------------------------------------------------------------- */
1323
- // const __changeables = object.constructor["__changeables"];
1324
- // const __unchangeables = object.constructor["__unchangeables"];
1325
- // /* -------------------------------------------------------------------------- */
1326
- // if (__changeables != null && !__changeables.includes(key)) return false;
1327
- // if (__unchangeables != null && __unchangeables.includes(key))
1328
- // return false;
1329
- // if (ignoreProtected !== true) {
1330
- // const __protectedProperties =
1331
- // object.constructor["__protectedProperties"];
1332
- // if (
1333
- // __protectedProperties != null &&
1334
- // __protectedProperties.includes(key)
1335
- // ) {
1336
- // //protected keys can only be changed by the creator of this object
1337
- // //make sure you set the is_current_user function correctly
1338
- // if (object.isNew) return true;
1339
- // const creatorOfObject = (object as any).get("_creator");
1340
- // return Boolean(
1341
- // gfunc.run_action_sync("is_current_user", creatorOfObject),
1342
- // );
1343
- // }
1344
- // }
1345
- // return true;
1346
1324
  }
1347
1325
  }, {
1348
1326
  key: "hasIllegalChanges",
@@ -1689,22 +1667,24 @@ function _setSaveResultObject(toObj) {
1689
1667
  _defineProperty(SimpleObject, "__db_name", "");
1690
1668
  _defineProperty(SimpleObject, "__object_name", "");
1691
1669
  //these properties should not be changed and are usually set by server
1692
- _defineProperty(SimpleObject, "__unchangeables", void 0);
1670
+ _defineProperty(SimpleObject, "__unchangeables", []);
1693
1671
  //these properties can be directly changed and are included in deltaObject
1694
- _defineProperty(SimpleObject, "__changeables", void 0);
1672
+ _defineProperty(SimpleObject, "__changeables", []);
1673
+ //these properties usually are not directly changed and sometimes are included in deltaObject
1674
+ _defineProperty(SimpleObject, "__extraProperties", []);
1675
+ //these properties are never sent to database but may be sent to client
1676
+ _defineProperty(SimpleObject, "__tempProperties", []);
1695
1677
  //these properties can only be changed by the _creator
1696
- _defineProperty(SimpleObject, "__protectedProperties", void 0);
1678
+ _defineProperty(SimpleObject, "__protectedProperties", []);
1697
1679
  //these properties will be evaluated when needed
1698
- _defineProperty(SimpleObject, "__functionProperties", void 0);
1680
+ _defineProperty(SimpleObject, "__functionProperties", []);
1699
1681
  //apply these string formats
1700
1682
  _defineProperty(SimpleObject, "__formatList", void 0);
1701
- //these properties usually are not directly changed and sometimes are included in deltaObject
1702
- _defineProperty(SimpleObject, "__extraProperties", void 0);
1703
1683
  //types for children can be used when importing children
1704
1684
  _defineProperty(SimpleObject, "__childTypes", void 0);
1705
1685
  //these fields are used when importing
1706
1686
  _defineProperty(SimpleObject, "__importColumns", void 0);
1707
1687
  //these fields can be used when importing and checking if an item exists
1708
- _defineProperty(SimpleObject, "__checkProperties", void 0);
1688
+ _defineProperty(SimpleObject, "__checkProperties", []);
1709
1689
  _defineProperty(SimpleObject, "__use_delta", true);
1710
1690
  var _default = exports["default"] = SimpleObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.9",
3
+ "version": "1.5.11",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",