@azrico/webobject 1.4.45 → 1.4.47

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.
@@ -13,8 +13,9 @@ export declare class WebObject extends SimpleObject {
13
13
  static readonly __web_type: string;
14
14
  meta_data: MetaObject[];
15
15
  _id: string;
16
- _creator?: string;
17
16
  _created_date?: string | Date;
17
+ _creator?: string;
18
+ _users?: string[];
18
19
  constructor(is_readonly?: boolean);
19
20
  /**
20
21
  * Update meta value of this object , meta data is stored in meta_data variable
@@ -43,8 +43,11 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
43
43
  _this = _super.call(this, is_readonly);
44
44
  _defineProperty(_assertThisInitialized(_this), "meta_data", void 0);
45
45
  _defineProperty(_assertThisInitialized(_this), "_id", "");
46
- _defineProperty(_assertThisInitialized(_this), "_creator", void 0);
47
46
  _defineProperty(_assertThisInitialized(_this), "_created_date", void 0);
47
+ //the owner of the object
48
+ _defineProperty(_assertThisInitialized(_this), "_creator", void 0);
49
+ //multiple users can work on one object
50
+ _defineProperty(_assertThisInitialized(_this), "_users", void 0);
48
51
  _defineProperty(_assertThisInitialized(_this), "get_webtype", function () {
49
52
  return _this.__web_type || _this.get_webpath();
50
53
  });
@@ -188,7 +191,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
188
191
  value: function () {
189
192
  var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(p) {
190
193
  var _this2 = this;
191
- var final_object, isChild, useDelta, allProperties, chkChangables, useExtraProps, dlt, allkeys, changableKeys, parseObj, _parseObj, functionProps, index, fp, _iterator, _step, key;
194
+ var final_object, isChild, useDelta, allProperties, chkChangables, useExtraProps, dlt, allkeys, changableKeys, parseObj, _parseObj, functionProps, index, fp, _iterator, _step, key, tempusers;
192
195
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
193
196
  while (1) switch (_context5.prev = _context5.next) {
194
197
  case 0:
@@ -317,8 +320,15 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
317
320
  final_object["_index_value"] = this.getIndex();
318
321
  final_object["_created_date"] = this["_created_date"];
319
322
  }
323
+ if (final_object["_users"]) {
324
+ tempusers = final_object["_users"];
325
+ if (typeof tempusers === "string") tempusers = tempusers.split(",").filter(function (s) {
326
+ return s;
327
+ });
328
+ final_object["_users"] = (0, _object.wrap_array)(tempusers);
329
+ }
320
330
  return _context5.abrupt("return", final_object);
321
- case 34:
331
+ case 35:
322
332
  case "end":
323
333
  return _context5.stop();
324
334
  }
@@ -0,0 +1,17 @@
1
+ import WebObject from "./WebObject";
2
+ export declare class WebObjectHelper {
3
+ /**
4
+ * get a list of all _creator and _users of the given objects
5
+ * @param objectlist
6
+ * @returns
7
+ */
8
+ static getUsersOfObject(objectlist: WebObject | WebObject[]): string[];
9
+ /**
10
+ * check if the given user object is list of _users or _creator of the given object(s)
11
+ * @param user
12
+ * @param obj
13
+ * @returns
14
+ */
15
+ static isUserInObject(user: any, obj: WebObject | WebObject[]): boolean;
16
+ }
17
+ export default WebObjectHelper;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.WebObjectHelper = void 0;
7
+ var _WebObject = _interopRequireDefault(require("./WebObject"));
8
+ var _object = require("@azrico/object");
9
+ var _string = require("@azrico/string");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
12
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+ 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."); }
14
+ 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); }
15
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
16
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
17
+ 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; }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
23
+ var WebObjectHelper = /*#__PURE__*/function () {
24
+ function WebObjectHelper() {
25
+ _classCallCheck(this, WebObjectHelper);
26
+ }
27
+ _createClass(WebObjectHelper, null, [{
28
+ key: "getUsersOfObject",
29
+ value:
30
+ /**
31
+ * get a list of all _creator and _users of the given objects
32
+ * @param objectlist
33
+ * @returns
34
+ */
35
+ function getUsersOfObject(objectlist) {
36
+ objectlist = (0, _object.wrap_array)(objectlist);
37
+ var userlist = [];
38
+ for (var index = 0; index < objectlist.length; index++) {
39
+ var obj = objectlist[index];
40
+ userlist.push(obj._creator || "");
41
+ userlist.push.apply(userlist, _toConsumableArray((0, _object.wrap_array)(obj._users)));
42
+ //backwards compatibility: (orders have this)
43
+ userlist.push.apply(userlist, _toConsumableArray((0, _object.wrap_array)(obj.attentions)));
44
+ }
45
+ var useridlist = userlist.map(function (r) {
46
+ return _typeof(r) === "object" ? _WebObject["default"].getID(r) : r;
47
+ });
48
+ return (0, _object.array_remove_duplicates)(useridlist).filter(function (s) {
49
+ return !(0, _string.string_isEmpty)(s);
50
+ });
51
+ }
52
+ /**
53
+ * check if the given user object is list of _users or _creator of the given object(s)
54
+ * @param user
55
+ * @param obj
56
+ * @returns
57
+ */
58
+ }, {
59
+ key: "isUserInObject",
60
+ value: function isUserInObject(user, obj) {
61
+ var userid = _WebObject["default"].getID(user);
62
+ var orderWorkers = this.getUsersOfObject(obj);
63
+ return orderWorkers.includes(userid);
64
+ }
65
+ }]);
66
+ return WebObjectHelper;
67
+ }();
68
+ exports.WebObjectHelper = WebObjectHelper;
69
+ var _default = WebObjectHelper;
70
+ exports["default"] = _default;
@@ -7,3 +7,4 @@ export * from "./structs/ObjectManager";
7
7
  export * from "./WebObjects/WebObjectManager";
8
8
  export * from "./WebObjects/WebObject";
9
9
  export * from "./WebObjects/ParentWebObject";
10
+ export * from "./WebObjects/WebObjectHelper";
package/dist/src/index.js CHANGED
@@ -101,4 +101,15 @@ Object.keys(_ParentWebObject).forEach(function (key) {
101
101
  return _ParentWebObject[key];
102
102
  }
103
103
  });
104
+ });
105
+ var _WebObjectHelper = require("./WebObjects/WebObjectHelper");
106
+ Object.keys(_WebObjectHelper).forEach(function (key) {
107
+ if (key === "default" || key === "__esModule") return;
108
+ if (key in exports && exports[key] === _WebObjectHelper[key]) return;
109
+ Object.defineProperty(exports, key, {
110
+ enumerable: true,
111
+ get: function get() {
112
+ return _WebObjectHelper[key];
113
+ }
114
+ });
104
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.45",
3
+ "version": "1.4.47",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",