@azrico/webobject 1.5.10 → 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,9 +71,10 @@ 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
80
  get_fullObject(p?: deltaParams): Promise<any>;
@@ -512,9 +512,10 @@ 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
  )
@@ -526,10 +527,11 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
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:
@@ -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
@@ -707,7 +707,14 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
707
707
  return _notifyChanged.apply(this, arguments);
708
708
  }
709
709
  return notifyChanged;
710
- }())
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
+ )
711
718
  }, {
712
719
  key: "apply_changes",
713
720
  value: /* -------------------------------------------------------------------------- */
@@ -1270,26 +1277,26 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1270
1277
  }, {
1271
1278
  key: "getChangeableKeys",
1272
1279
  value: function getChangeableKeys(object, options) {
1273
- var _key_list2;
1280
+ var _key_list;
1274
1281
  if (!object) return [];
1275
- var useExtraProps = options.useExtraProps,
1276
- ignoreProtected = options.ignoreProtected;
1277
1282
  var key_list = [];
1278
- if (useExtraProps) {
1279
- var _key_list;
1280
- var __extraProperties = object.constructor["__extraProperties"];
1281
- if (!(0, _object.array_isEmpty)(__extraProperties)) (_key_list = key_list).push.apply(_key_list, _toConsumableArray(__extraProperties));
1282
- }
1283
- /* -------------------------------------------------------------------------- */
1284
- var __changeables = object.constructor["__changeables"];
1285
- 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"]));
1286
1284
  var __unchangeables = object.constructor["__unchangeables"];
1287
1285
  if (!(0, _object.array_isEmpty)(__unchangeables)) {
1288
1286
  key_list = key_list.filter(function (s) {
1289
1287
  return !__unchangeables.includes(s);
1290
1288
  });
1291
1289
  }
1292
- 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) {
1293
1300
  var __protectedProperties = object.constructor["__protectedProperties"];
1294
1301
  //protected keys can only be changed by the creator of this object
1295
1302
  //make sure you set the is_current_user function correctly
@@ -1314,36 +1321,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1314
1321
  if (!object || !key) return false;
1315
1322
  var keys = this.getChangeableKeys(object, options);
1316
1323
  return keys.includes(key);
1317
- // const {useExtraProps, ignoreProtected} = options;
1318
- // if (useExtraProps) {
1319
- // const __extraProperties = object.constructor["__extraProperties"];
1320
- // if (__extraProperties != null && __extraProperties.includes(key))
1321
- // return true;
1322
- // }
1323
- // /* -------------------------------------------------------------------------- */
1324
- // const __changeables = object.constructor["__changeables"];
1325
- // const __unchangeables = object.constructor["__unchangeables"];
1326
- // /* -------------------------------------------------------------------------- */
1327
- // if (__changeables != null && !__changeables.includes(key)) return false;
1328
- // if (__unchangeables != null && __unchangeables.includes(key))
1329
- // return false;
1330
- // if (ignoreProtected !== true) {
1331
- // const __protectedProperties =
1332
- // object.constructor["__protectedProperties"];
1333
- // if (
1334
- // __protectedProperties != null &&
1335
- // __protectedProperties.includes(key)
1336
- // ) {
1337
- // //protected keys can only be changed by the creator of this object
1338
- // //make sure you set the is_current_user function correctly
1339
- // if (object.isNew) return true;
1340
- // const creatorOfObject = (object as any).get("_creator");
1341
- // return Boolean(
1342
- // gfunc.run_action_sync("is_current_user", creatorOfObject),
1343
- // );
1344
- // }
1345
- // }
1346
- // return true;
1347
1324
  }
1348
1325
  }, {
1349
1326
  key: "hasIllegalChanges",
@@ -1690,22 +1667,24 @@ function _setSaveResultObject(toObj) {
1690
1667
  _defineProperty(SimpleObject, "__db_name", "");
1691
1668
  _defineProperty(SimpleObject, "__object_name", "");
1692
1669
  //these properties should not be changed and are usually set by server
1693
- _defineProperty(SimpleObject, "__unchangeables", void 0);
1670
+ _defineProperty(SimpleObject, "__unchangeables", []);
1694
1671
  //these properties can be directly changed and are included in deltaObject
1695
- _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", []);
1696
1677
  //these properties can only be changed by the _creator
1697
- _defineProperty(SimpleObject, "__protectedProperties", void 0);
1678
+ _defineProperty(SimpleObject, "__protectedProperties", []);
1698
1679
  //these properties will be evaluated when needed
1699
- _defineProperty(SimpleObject, "__functionProperties", void 0);
1680
+ _defineProperty(SimpleObject, "__functionProperties", []);
1700
1681
  //apply these string formats
1701
1682
  _defineProperty(SimpleObject, "__formatList", void 0);
1702
- //these properties usually are not directly changed and sometimes are included in deltaObject
1703
- _defineProperty(SimpleObject, "__extraProperties", void 0);
1704
1683
  //types for children can be used when importing children
1705
1684
  _defineProperty(SimpleObject, "__childTypes", void 0);
1706
1685
  //these fields are used when importing
1707
1686
  _defineProperty(SimpleObject, "__importColumns", void 0);
1708
1687
  //these fields can be used when importing and checking if an item exists
1709
- _defineProperty(SimpleObject, "__checkProperties", void 0);
1688
+ _defineProperty(SimpleObject, "__checkProperties", []);
1710
1689
  _defineProperty(SimpleObject, "__use_delta", true);
1711
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.10",
3
+ "version": "1.5.11",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",