@azrico/webobject 1.4.198 → 1.4.200
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.
|
@@ -553,8 +553,7 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
553
553
|
key: "get_deltaObject",
|
|
554
554
|
value: (function () {
|
|
555
555
|
var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(p) {
|
|
556
|
-
var
|
|
557
|
-
var final_object, isChild, useDelta, allProperties, needId, chkChangables, useExtraProps, dlt, key, allkeys, changableKeys, functionProps, index, fp, parseObj, _parseObj, _iterator, _step, _key, gotIndex, gotId, tempusers;
|
|
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
557
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
559
558
|
while (1) switch (_context12.prev = _context12.next) {
|
|
560
559
|
case 0:
|
|
@@ -630,13 +629,15 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
630
629
|
if (!p) p = {};
|
|
631
630
|
final_object = {}; //@ts-ignore
|
|
632
631
|
isChild = Boolean(p.isChild || p.ischild); //@ts-ignore
|
|
633
|
-
useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
|
|
634
|
-
allProperties = Boolean(
|
|
632
|
+
useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
|
|
633
|
+
allProperties = Boolean(
|
|
634
|
+
//@ts-ignore
|
|
635
|
+
p.allProperties || p.allproperties || isChild); //@ts-ignore
|
|
635
636
|
needId = Boolean(p.needId || p.needid);
|
|
636
637
|
chkChangables = this.__changeables != null || this.__unchangeables != null;
|
|
637
638
|
useExtraProps = Boolean(p.extraProperties); //child objects usually dont update their __delta, so we read info from all of its properties
|
|
638
639
|
dlt = allProperties || !useDelta && isChild && chkChangables ? _objectSpread({}, this.allproperties) : _objectSpread({}, this.__delta);
|
|
639
|
-
/* ------------- parse children that have WebObject as
|
|
640
|
+
/* ------------- parse children that have WebObject as delta ------------- */
|
|
640
641
|
_context12.t0 = _regeneratorRuntime().keys(this);
|
|
641
642
|
case 12:
|
|
642
643
|
if ((_context12.t1 = _context12.t0()).done) {
|
|
@@ -659,21 +660,26 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
659
660
|
_context12.next = 12;
|
|
660
661
|
break;
|
|
661
662
|
case 19:
|
|
662
|
-
|
|
663
|
-
changableKeys =
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
663
|
+
/* ------------------------- 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;
|
|
670
676
|
return _convert["default"].applyFormats({
|
|
671
677
|
inputobject: dlt,
|
|
672
678
|
formats: (0, _object.object_getStatic)(this, "__formatList"),
|
|
673
679
|
changableKeys: changableKeys,
|
|
674
680
|
applyDefaults: true
|
|
675
681
|
});
|
|
676
|
-
case
|
|
682
|
+
case 22:
|
|
677
683
|
/* -------------------------------------------------------------------------- */
|
|
678
684
|
/* __functionProperties */
|
|
679
685
|
/* -------------------------------------------------------------------------- */
|
|
@@ -688,33 +694,33 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
688
694
|
/* parse all changableKeys */
|
|
689
695
|
/* -------------------------------------------------------------------------- */
|
|
690
696
|
_iterator = _createForOfIteratorHelper(changableKeys);
|
|
691
|
-
_context12.prev =
|
|
697
|
+
_context12.prev = 25;
|
|
692
698
|
_iterator.s();
|
|
693
|
-
case
|
|
699
|
+
case 27:
|
|
694
700
|
if ((_step = _iterator.n()).done) {
|
|
695
|
-
_context12.next =
|
|
701
|
+
_context12.next = 34;
|
|
696
702
|
break;
|
|
697
703
|
}
|
|
698
704
|
_key = _step.value;
|
|
699
|
-
_context12.next =
|
|
705
|
+
_context12.next = 31;
|
|
700
706
|
return parseObj(dlt[_key]);
|
|
701
|
-
case
|
|
707
|
+
case 31:
|
|
702
708
|
final_object[_key] = _context12.sent;
|
|
703
|
-
case
|
|
704
|
-
_context12.next =
|
|
709
|
+
case 32:
|
|
710
|
+
_context12.next = 27;
|
|
705
711
|
break;
|
|
706
|
-
case
|
|
707
|
-
_context12.next =
|
|
712
|
+
case 34:
|
|
713
|
+
_context12.next = 39;
|
|
708
714
|
break;
|
|
709
|
-
case
|
|
710
|
-
_context12.prev =
|
|
711
|
-
_context12.t2 = _context12["catch"](
|
|
715
|
+
case 36:
|
|
716
|
+
_context12.prev = 36;
|
|
717
|
+
_context12.t2 = _context12["catch"](25);
|
|
712
718
|
_iterator.e(_context12.t2);
|
|
713
|
-
case
|
|
714
|
-
_context12.prev =
|
|
719
|
+
case 39:
|
|
720
|
+
_context12.prev = 39;
|
|
715
721
|
_iterator.f();
|
|
716
|
-
return _context12.finish(
|
|
717
|
-
case
|
|
722
|
+
return _context12.finish(39);
|
|
723
|
+
case 42:
|
|
718
724
|
/* -------------------- add acrhived and date properties -------------------- */
|
|
719
725
|
if (allProperties) {
|
|
720
726
|
final_object["_created_date"] = this["_created_date"];
|
|
@@ -740,11 +746,11 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
740
746
|
final_object["_users"] = (0, _object.wrap_array)(tempusers);
|
|
741
747
|
}
|
|
742
748
|
return _context12.abrupt("return", final_object);
|
|
743
|
-
case
|
|
749
|
+
case 46:
|
|
744
750
|
case "end":
|
|
745
751
|
return _context12.stop();
|
|
746
752
|
}
|
|
747
|
-
}, _callee12, this, [[
|
|
753
|
+
}, _callee12, this, [[25, 36, 39, 42]]);
|
|
748
754
|
}));
|
|
749
755
|
function get_deltaObject(_x4) {
|
|
750
756
|
return _get_deltaObject.apply(this, arguments);
|
|
@@ -1035,13 +1041,13 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
1035
1041
|
}, {
|
|
1036
1042
|
key: "getSaveResult",
|
|
1037
1043
|
value: function getSaveResult() {
|
|
1038
|
-
var
|
|
1044
|
+
var _this2 = this;
|
|
1039
1045
|
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1040
1046
|
var srObject = _get(_getPrototypeOf(WebObject.prototype), "getSaveResult", this).call(this, original);
|
|
1041
1047
|
if (!srObject) return false;
|
|
1042
1048
|
if (Array.isArray(srObject)) {
|
|
1043
1049
|
var actual_sr = srObject.find(function (s) {
|
|
1044
|
-
return
|
|
1050
|
+
return _this2.saveResultHasID(s);
|
|
1045
1051
|
});
|
|
1046
1052
|
if (actual_sr) srObject = actual_sr;
|
|
1047
1053
|
}
|
|
@@ -7,6 +7,10 @@ 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;
|
|
13
|
+
};
|
|
10
14
|
export declare class SimpleObject extends MapableObject {
|
|
11
15
|
#private;
|
|
12
16
|
static readonly __db_name: string;
|
|
@@ -134,6 +138,7 @@ export declare class SimpleObject extends MapableObject {
|
|
|
134
138
|
* @returns true if manager was notified. false otherwise
|
|
135
139
|
*/
|
|
136
140
|
notifyChanged<MKey extends PropOf<this>>(type: string, key: MKey | string, value: any, subvalue?: any): Promise<false | any[] | undefined>;
|
|
141
|
+
static getChangeableKeys(object: SimpleObject, options: getKeysProps): any[];
|
|
137
142
|
/**
|
|
138
143
|
* check if a key can be changed on an object
|
|
139
144
|
* @param object the object we are checking
|
|
@@ -141,10 +146,7 @@ export declare class SimpleObject extends MapableObject {
|
|
|
141
146
|
* @param useExtraProps should we check extra props?
|
|
142
147
|
* @returns
|
|
143
148
|
*/
|
|
144
|
-
static canChangeKey(object: SimpleObject, key: string, options:
|
|
145
|
-
useExtraProps?: boolean;
|
|
146
|
-
ignoreProtected?: boolean;
|
|
147
|
-
}): boolean;
|
|
149
|
+
static canChangeKey(object: SimpleObject, key: string, options: getKeysProps): boolean;
|
|
148
150
|
static hasIllegalChanges(referenceObject: any, changesObject: any, updaterUser: any): boolean;
|
|
149
151
|
/**
|
|
150
152
|
* Apply all the changes and empty the delta object
|
|
@@ -10,6 +10,12 @@ var _global = require("@azrico/global");
|
|
|
10
10
|
var _MapableObject2 = require("./MapableObject");
|
|
11
11
|
var _ObjectManager = _interopRequireDefault(require("./ObjectManager"));
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
14
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
17
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
21
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -632,15 +638,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
|
|
|
632
638
|
return _notifyChanged.apply(this, arguments);
|
|
633
639
|
}
|
|
634
640
|
return notifyChanged;
|
|
635
|
-
}()
|
|
636
|
-
/**
|
|
637
|
-
* check if a key can be changed on an object
|
|
638
|
-
* @param object the object we are checking
|
|
639
|
-
* @param key key of the object
|
|
640
|
-
* @param useExtraProps should we check extra props?
|
|
641
|
-
* @returns
|
|
642
|
-
*/
|
|
643
|
-
)
|
|
641
|
+
}())
|
|
644
642
|
}, {
|
|
645
643
|
key: "apply_changes",
|
|
646
644
|
value: /* -------------------------------------------------------------------------- */
|
|
@@ -1203,32 +1201,82 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
|
|
|
1203
1201
|
return true;
|
|
1204
1202
|
}
|
|
1205
1203
|
}, {
|
|
1206
|
-
key: "
|
|
1207
|
-
value: function
|
|
1208
|
-
|
|
1204
|
+
key: "getChangeableKeys",
|
|
1205
|
+
value: function getChangeableKeys(object, options) {
|
|
1206
|
+
var _key_list2;
|
|
1207
|
+
if (!object) return [];
|
|
1209
1208
|
var useExtraProps = options.useExtraProps,
|
|
1210
1209
|
ignoreProtected = options.ignoreProtected;
|
|
1210
|
+
var key_list = [];
|
|
1211
1211
|
if (useExtraProps) {
|
|
1212
|
+
var _key_list;
|
|
1212
1213
|
var __extraProperties = object.constructor["__extraProperties"];
|
|
1213
|
-
if (__extraProperties
|
|
1214
|
+
if (!(0, _object.array_isEmpty)(__extraProperties)) (_key_list = key_list).push.apply(_key_list, _toConsumableArray(__extraProperties));
|
|
1214
1215
|
}
|
|
1215
1216
|
/* -------------------------------------------------------------------------- */
|
|
1216
1217
|
var __changeables = object.constructor["__changeables"];
|
|
1218
|
+
if (!(0, _object.array_isEmpty)(__changeables)) (_key_list2 = key_list).push.apply(_key_list2, _toConsumableArray(__changeables));
|
|
1217
1219
|
var __unchangeables = object.constructor["__unchangeables"];
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1220
|
+
if (!(0, _object.array_isEmpty)(__unchangeables)) {
|
|
1221
|
+
key_list = key_list.filter(function (s) {
|
|
1222
|
+
return !__unchangeables.includes(s);
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1221
1225
|
if (ignoreProtected !== true) {
|
|
1222
1226
|
var __protectedProperties = object.constructor["__protectedProperties"];
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1227
|
+
//protected keys can only be changed by the creator of this object
|
|
1228
|
+
//make sure you set the is_current_user function correctly
|
|
1229
|
+
if (!object.isNew && !(0, _object.array_isEmpty)(__protectedProperties) && !Boolean(_global.gfunc.run_action_sync("is_current_user", object.get("_creator")))) {
|
|
1230
|
+
key_list = key_list.filter(function (s) {
|
|
1231
|
+
return !__protectedProperties.includes(s);
|
|
1232
|
+
});
|
|
1229
1233
|
}
|
|
1230
1234
|
}
|
|
1231
|
-
return
|
|
1235
|
+
return key_list;
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* check if a key can be changed on an object
|
|
1239
|
+
* @param object the object we are checking
|
|
1240
|
+
* @param key key of the object
|
|
1241
|
+
* @param useExtraProps should we check extra props?
|
|
1242
|
+
* @returns
|
|
1243
|
+
*/
|
|
1244
|
+
}, {
|
|
1245
|
+
key: "canChangeKey",
|
|
1246
|
+
value: function canChangeKey(object, key, options) {
|
|
1247
|
+
if (!object || !key) return false;
|
|
1248
|
+
var keys = this.getChangeableKeys(object, options);
|
|
1249
|
+
return keys.includes(key);
|
|
1250
|
+
// const {useExtraProps, ignoreProtected} = options;
|
|
1251
|
+
// if (useExtraProps) {
|
|
1252
|
+
// const __extraProperties = object.constructor["__extraProperties"];
|
|
1253
|
+
// if (__extraProperties != null && __extraProperties.includes(key))
|
|
1254
|
+
// return true;
|
|
1255
|
+
// }
|
|
1256
|
+
// /* -------------------------------------------------------------------------- */
|
|
1257
|
+
// const __changeables = object.constructor["__changeables"];
|
|
1258
|
+
// const __unchangeables = object.constructor["__unchangeables"];
|
|
1259
|
+
// /* -------------------------------------------------------------------------- */
|
|
1260
|
+
// if (__changeables != null && !__changeables.includes(key)) return false;
|
|
1261
|
+
// if (__unchangeables != null && __unchangeables.includes(key))
|
|
1262
|
+
// return false;
|
|
1263
|
+
// if (ignoreProtected !== true) {
|
|
1264
|
+
// const __protectedProperties =
|
|
1265
|
+
// object.constructor["__protectedProperties"];
|
|
1266
|
+
// if (
|
|
1267
|
+
// __protectedProperties != null &&
|
|
1268
|
+
// __protectedProperties.includes(key)
|
|
1269
|
+
// ) {
|
|
1270
|
+
// //protected keys can only be changed by the creator of this object
|
|
1271
|
+
// //make sure you set the is_current_user function correctly
|
|
1272
|
+
// if (object.isNew) return true;
|
|
1273
|
+
// const creatorOfObject = (object as any).get("_creator");
|
|
1274
|
+
// return Boolean(
|
|
1275
|
+
// gfunc.run_action_sync("is_current_user", creatorOfObject),
|
|
1276
|
+
// );
|
|
1277
|
+
// }
|
|
1278
|
+
// }
|
|
1279
|
+
// return true;
|
|
1232
1280
|
}
|
|
1233
1281
|
}, {
|
|
1234
1282
|
key: "hasIllegalChanges",
|