@azrico/webobject 1.5.59 → 1.5.62

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,469 +1,270 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = exports.WebObject = void 0;
7
- var _index3 = require("../index");
8
- var _object = require("@azrico/object");
9
- var _string = require("@azrico/string");
10
- var _global = require("@azrico/global");
11
- var _convert = _interopRequireDefault(require("@azrico/convert"));
12
- var _WebObjectPathHelper = _interopRequireDefault(require("./WebObjectPathHelper"));
13
- var _WebObjectHelper = _interopRequireDefault(require("./WebObjectHelper"));
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
16
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
17
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
- 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); }
19
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
20
- 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; }
21
- 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; }
22
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
23
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
24
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
25
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
26
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
27
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
28
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
29
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
30
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
31
- function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
32
- function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
33
- function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
34
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
35
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
36
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
37
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
38
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
39
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
40
- var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
41
- function WebObject() {
42
- var _this;
43
- var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
44
- _classCallCheck(this, WebObject);
45
- _this = _callSuper(this, WebObject, [is_readonly]);
46
- _defineProperty(_this, "meta_data", void 0);
47
- //created date
48
- _defineProperty(_this, "_created_date", void 0);
49
- //the owner of the object
50
- _defineProperty(_this, "_creator", void 0);
51
- //multiple users can work on one object
52
- _defineProperty(_this, "_users", void 0);
53
- _this.meta_data = {};
54
- return _this;
55
- }
56
- /**
57
- * get a list of all user ids that work on the given object
58
- * _creator + _users + attentions(old)
59
- * removes duplicates
60
- * @returns array of ids
61
- */
62
- _inherits(WebObject, _SimpleObject);
63
- return _createClass(WebObject, [{
64
- key: "getAllUsers",
65
- value: function getAllUsers() {
66
- return WebObject.getAllUsers(this);
67
- }
1
+ import { SimpleObject } from "../index";
2
+ import { array_chunks, array_first, array_intersection, array_merge, array_remove_duplicates, fn_eval_this, object_clean, object_equals, object_getStatic, object_isEmpty, wrap_array, } from "@azrico/object";
3
+ import { string_compress, string_decompress } from "@azrico/string";
4
+ import { gcache, gfunc } from "@azrico/global";
5
+ import FormatHelper from "@azrico/convert";
6
+ import WebObjectPathHelper from "./WebObjectPathHelper";
7
+ import WebObjectHelper from "./WebObjectHelper";
8
+ export class WebObject extends SimpleObject {
9
+ static __web_path = "";
10
+ static __protectedProperties = ["_users"];
11
+ //you cant create a new weboject without these properties
12
+ static __requiredProperties = [];
13
+ meta_data;
14
+ //created date
15
+ _created_date;
16
+ //the owner of the object
17
+ _creator;
18
+ //multiple users can work on one object
19
+ _users;
20
+ constructor(is_readonly = false) {
21
+ super(is_readonly);
22
+ this.meta_data = {};
23
+ }
24
+ /**
25
+ * get a list of all user ids that work on the given object
26
+ * _creator + _users + attentions(old)
27
+ * removes duplicates
28
+ * @returns array of ids
29
+ */
30
+ getAllUsers() {
31
+ return WebObject.getAllUsers(this);
32
+ }
68
33
  /**
69
34
  * get a unique list of all user ids that work on the given object
70
35
  * `_creator + _users + attentions`
71
36
  * @returns array of ids
72
- */
73
- }, {
74
- key: "setMetaValue",
75
- value: (
76
- /* -------------------------------------------------------------------------- */
77
- /* Meta data */
78
- /* -------------------------------------------------------------------------- */
37
+ */
38
+ static getAllUsers(obj) {
39
+ if (typeof obj != "object")
40
+ return [];
41
+ return array_remove_duplicates(array_merge(obj._creator, wrap_array(obj._users), wrap_array(obj.attentions))
42
+ .map((r) => String(typeof r === "object" ? WebObject.getID(r) : r))
43
+ .filter((s) => s));
44
+ }
45
+ /* -------------------------------------------------------------------------- */
46
+ /* Meta data */
47
+ /* -------------------------------------------------------------------------- */
79
48
  /**
80
49
  * Update meta value of this object , meta data is stored in meta_data variable
81
50
  * @param key
82
51
  * @param value
83
52
  * @param sendChange
84
53
  * @returns
85
- */
86
- function () {
87
- var _setMetaValue = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
88
- var sendChange,
89
- old_value,
90
- new_metalist,
91
- _args = arguments;
92
- return _regeneratorRuntime().wrap(function _callee$(_context) {
93
- while (1) switch (_context.prev = _context.next) {
94
- case 0:
95
- sendChange = _args.length > 2 && _args[2] !== undefined ? _args[2] : "auto";
96
- if (this.canModify) {
97
- _context.next = 7;
98
- break;
99
- }
100
- if (!(this.__throw_errors !== false)) {
101
- _context.next = 6;
102
- break;
103
- }
104
- throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));
105
- case 6:
106
- return _context.abrupt("return", false);
107
- case 7:
108
- if (!(!key || typeof key != "string")) {
109
- _context.next = 13;
110
- break;
111
- }
112
- if (!(this.__throw_errors !== false)) {
113
- _context.next = 12;
114
- break;
115
- }
116
- throw Error("Bad key at setMetaValue");
117
- case 12:
118
- return _context.abrupt("return", false);
119
- case 13:
120
- old_value = WebObject.getMetaValue(this, key);
121
- if (!(0, _object.object_equals)(old_value, value)) {
122
- _context.next = 16;
123
- break;
124
- }
125
- return _context.abrupt("return", false);
126
- case 16:
127
- //same value, no changes
128
- new_metalist = _objectSpread({}, this.get("meta_data"));
129
- new_metalist[key] = value;
130
- _context.next = 20;
131
- return this.set("meta_data", new_metalist);
132
- case 20:
133
- if (!(sendChange !== false)) {
134
- _context.next = 23;
135
- break;
136
- }
137
- _context.next = 23;
138
- return this.notifyChanged("meta", key, value);
139
- case 23:
140
- return _context.abrupt("return", true);
141
- case 24:
142
- case "end":
143
- return _context.stop();
144
- }
145
- }, _callee, this);
146
- }));
147
- function setMetaValue(_x, _x2) {
148
- return _setMetaValue.apply(this, arguments);
149
- }
150
- return setMetaValue;
151
- }()
54
+ */
55
+ async setMetaValue(key, value, sendChange = "auto") {
56
+ if (!this.canModify) {
57
+ if (this.__throw_errors !== false)
58
+ throw Error(`Cant use setMetaValue on ${key} when on readonly mode`);
59
+ else
60
+ return false;
61
+ }
62
+ if (!key || typeof key != "string") {
63
+ if (this.__throw_errors !== false)
64
+ throw Error(`Bad key at setMetaValue`);
65
+ else
66
+ return false;
67
+ }
68
+ const old_value = WebObject.getMetaValue(this, key);
69
+ if (object_equals(old_value, value))
70
+ return false; //same value, no changes
71
+ const new_metalist = { ...this.get("meta_data") };
72
+ new_metalist[key] = value;
73
+ await this.set("meta_data", new_metalist);
74
+ if (sendChange !== false)
75
+ await this.notifyChanged("meta", key, value);
76
+ return true;
77
+ }
152
78
  /**
153
79
  * Get meta value by key
154
80
  * @param key
155
81
  * @returns value or undefined
156
- */
157
- )
158
- }, {
159
- key: "getMetaValue",
160
- value: function getMetaValue(key) {
161
- return WebObject.getMetaValue(this, key);
162
- }
82
+ */
83
+ getMetaValue(key) {
84
+ return WebObject.getMetaValue(this, key);
85
+ }
163
86
  /**
164
87
  * Get meta value by key
165
88
  * @param o
166
89
  * @param key
167
90
  * @returns value or undefined
168
- */
169
- }, {
170
- key: "Save",
171
- value: function () {
172
- var _Save = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
173
- var deltaObject, putAction, usepath, canSaveResult, resultObject;
174
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
175
- while (1) switch (_context2.prev = _context2.next) {
176
- case 0:
177
- _context2.prev = 0;
178
- if (!this.manager) {
179
- _context2.next = 6;
180
- break;
181
- }
182
- _context2.next = 4;
183
- return this.manager.setOption("saving", true);
184
- case 4:
185
- _context2.next = 6;
186
- return this.manager.setOption("loading", true);
187
- case 6:
188
- _context2.next = 8;
189
- return this.get_deltaObject();
190
- case 8:
191
- deltaObject = _context2.sent;
192
- putAction = "post";
193
- _context2.next = 12;
194
- return _WebObjectPathHelper["default"].get_path(this, this.isNew ? "new" : "save");
195
- case 12:
196
- usepath = _context2.sent;
197
- if ((0, _object.object_isEmpty)(deltaObject)) {
198
- _context2.next = 25;
199
- break;
200
- }
201
- canSaveResult = this.canSave(deltaObject);
202
- if (!(canSaveResult !== true)) {
203
- _context2.next = 19;
204
- break;
205
- }
206
- WebObject.addError(this, "Save not allowed", String(canSaveResult), true);
207
- this.setSaveResult(false, "canceled");
208
- return _context2.abrupt("return", false);
209
- case 19:
210
- _context2.next = 21;
211
- return _global.gfunc.run_action(putAction, usepath, deltaObject);
212
- case 21:
213
- resultObject = _context2.sent;
214
- this.setSaveResult(resultObject, "auto", true);
215
- _context2.next = 26;
216
- break;
217
- case 25:
218
- /* nothing to save */
219
- this.setSaveResult(null, "nothing");
220
- case 26:
221
- if (!this.isSaved) {
222
- _context2.next = 30;
223
- break;
224
- }
225
- _context2.next = 29;
226
- return this.onSave();
227
- case 29:
228
- return _context2.abrupt("return", this.getSaveResult());
229
- case 30:
230
- _context2.prev = 30;
231
- if (!this.manager) {
232
- _context2.next = 36;
233
- break;
234
- }
235
- _context2.next = 34;
236
- return this.manager.setOption("saving", false);
237
- case 34:
238
- _context2.next = 36;
239
- return this.manager.setOption("loading", false);
240
- case 36:
241
- return _context2.finish(30);
242
- case 37:
243
- case "end":
244
- return _context2.stop();
245
- }
246
- }, _callee2, this, [[0,, 30, 37]]);
247
- }));
248
- function Save() {
249
- return _Save.apply(this, arguments);
250
- }
251
- return Save;
252
- }()
253
- }, {
254
- key: "Delete",
255
- value: function () {
256
- var _Delete = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
257
- var usepath, resultObject;
258
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
259
- while (1) switch (_context3.prev = _context3.next) {
260
- case 0:
261
- if (!this.isNew) {
262
- _context3.next = 2;
263
- break;
264
- }
265
- return _context3.abrupt("return");
266
- case 2:
267
- _context3.next = 4;
268
- return _WebObjectPathHelper["default"].get_path(this, "delete");
269
- case 4:
270
- usepath = _context3.sent;
271
- _context3.next = 7;
272
- return _global.gfunc.run_action("delete", usepath);
273
- case 7:
274
- resultObject = _context3.sent;
275
- this.setSaveResult(resultObject, "auto", true);
276
- _context3.next = 11;
277
- return this.onDelete();
278
- case 11:
279
- return _context3.abrupt("return", resultObject);
280
- case 12:
281
- case "end":
282
- return _context3.stop();
283
- }
284
- }, _callee3, this);
285
- }));
286
- function Delete() {
287
- return _Delete.apply(this, arguments);
288
- }
289
- return Delete;
290
- }()
291
- }, {
292
- key: "Lock",
293
- value: function () {
294
- var _Lock = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
295
- var usepath, resultObject;
296
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
297
- while (1) switch (_context4.prev = _context4.next) {
298
- case 0:
299
- if (!(this.isNew || this.isArchived)) {
300
- _context4.next = 2;
301
- break;
302
- }
303
- return _context4.abrupt("return");
304
- case 2:
305
- _context4.next = 4;
306
- return _WebObjectPathHelper["default"].get_path(this, "lock");
307
- case 4:
308
- usepath = _context4.sent;
309
- _context4.next = 7;
310
- return _global.gfunc.run_action("post", usepath);
311
- case 7:
312
- resultObject = _context4.sent;
313
- this.setSaveResult(resultObject, "auto", true);
314
- _context4.next = 11;
315
- return this.onLock();
316
- case 11:
317
- return _context4.abrupt("return", resultObject);
318
- case 12:
319
- case "end":
320
- return _context4.stop();
321
- }
322
- }, _callee4, this);
323
- }));
324
- function Lock() {
325
- return _Lock.apply(this, arguments);
326
- }
327
- return Lock;
328
- }()
329
- }, {
330
- key: "UnLock",
331
- value: function () {
332
- var _UnLock = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
333
- var usepath, resultObject;
334
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
335
- while (1) switch (_context5.prev = _context5.next) {
336
- case 0:
337
- if (!(this.isNew || this.isArchived)) {
338
- _context5.next = 2;
339
- break;
340
- }
341
- return _context5.abrupt("return");
342
- case 2:
343
- _context5.next = 4;
344
- return _WebObjectPathHelper["default"].get_path(this, "unlock");
345
- case 4:
346
- usepath = _context5.sent;
347
- _context5.next = 7;
348
- return _global.gfunc.run_action("post", usepath);
349
- case 7:
350
- resultObject = _context5.sent;
351
- this.setSaveResult(resultObject, "auto", true);
352
- _context5.next = 11;
353
- return this.onUnLock();
354
- case 11:
355
- return _context5.abrupt("return", resultObject);
356
- case 12:
357
- case "end":
358
- return _context5.stop();
359
- }
360
- }, _callee5, this);
361
- }));
362
- function UnLock() {
363
- return _UnLock.apply(this, arguments);
364
- }
365
- return UnLock;
366
- }()
367
- }, {
368
- key: "Archive",
369
- value: function () {
370
- var _Archive = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
371
- var usepath, resultObject;
372
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
373
- while (1) switch (_context6.prev = _context6.next) {
374
- case 0:
375
- if (!(this.isNew || this.isArchived)) {
376
- _context6.next = 2;
377
- break;
378
- }
379
- return _context6.abrupt("return");
380
- case 2:
381
- _context6.next = 4;
382
- return _WebObjectPathHelper["default"].get_path(this, "archive");
383
- case 4:
384
- usepath = _context6.sent;
385
- _context6.next = 7;
386
- return _global.gfunc.run_action("post", usepath);
387
- case 7:
388
- resultObject = _context6.sent;
389
- this.setSaveResult(resultObject, "auto", true);
390
- _context6.next = 11;
391
- return this.onArchive();
392
- case 11:
393
- return _context6.abrupt("return", resultObject);
394
- case 12:
395
- case "end":
396
- return _context6.stop();
397
- }
398
- }, _callee6, this);
399
- }));
400
- function Archive() {
401
- return _Archive.apply(this, arguments);
402
- }
403
- return Archive;
404
- }()
405
- }, {
406
- key: "UnArchive",
407
- value: function () {
408
- var _UnArchive = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
409
- var usepath, resultObject;
410
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
411
- while (1) switch (_context7.prev = _context7.next) {
412
- case 0:
413
- if (!(this.isNew || !this.isArchived)) {
414
- _context7.next = 2;
415
- break;
416
- }
417
- return _context7.abrupt("return");
418
- case 2:
419
- _context7.next = 4;
420
- return _WebObjectPathHelper["default"].get_path(this, "unarchive");
421
- case 4:
422
- usepath = _context7.sent;
423
- _context7.next = 7;
424
- return _global.gfunc.run_action("post", usepath);
425
- case 7:
426
- resultObject = _context7.sent;
427
- _context7.next = 10;
428
- return this.onUnArchive();
429
- case 10:
430
- return _context7.abrupt("return", resultObject);
431
- case 11:
432
- case "end":
433
- return _context7.stop();
434
- }
435
- }, _callee7, this);
436
- }));
437
- function UnArchive() {
438
- return _UnArchive.apply(this, arguments);
439
- }
440
- return UnArchive;
441
- }() /* -------------------------------------------------------------------------- */
442
- }, {
443
- key: "canSave",
444
- value: function canSave(deltaObj) {
445
- var deltaRes = this.deltaIsValid(deltaObj);
446
- if (deltaRes !== true) return deltaRes;
447
- return true;
448
- }
449
- }, {
450
- key: "canDelete",
451
- value: function canDelete() {
452
- return true;
453
- }
454
- }, {
455
- key: "canArchive",
456
- value: function canArchive() {
457
- return true;
458
- }
459
- }, {
460
- key: "deltaIsValid",
461
- value: function deltaIsValid(d) {
462
- return true;
463
- }
464
- /* -------------------------------------------------------------------------- */
465
- /* get delta */
466
- /* -------------------------------------------------------------------------- */
91
+ */
92
+ static getMetaValue(o, key) {
93
+ if (o == null)
94
+ return null;
95
+ if (!key || typeof key != "string")
96
+ return undefined;
97
+ let metalist = {};
98
+ if (typeof o === "object") {
99
+ metalist =
100
+ typeof o.get === "function" ? o.get("meta_data") : o.meta_data;
101
+ }
102
+ return metalist[key];
103
+ }
104
+ /* -------------------------------------------------------------------------- */
105
+ /* Save */
106
+ /* -------------------------------------------------------------------------- */
107
+ static zipSaveList(svlist) {
108
+ if (typeof svlist === "object")
109
+ svlist = JSON.stringify(svlist);
110
+ return string_compress(svlist);
111
+ }
112
+ static unzipSaveList(svlist) {
113
+ try {
114
+ if (typeof svlist === "object") {
115
+ if (Array.isArray(svlist))
116
+ return svlist;
117
+ if (svlist.__save_list)
118
+ return this.unzipSaveList(svlist.__save_list);
119
+ }
120
+ else if (typeof svlist === "string")
121
+ return wrap_array(JSON.parse(string_decompress(svlist)));
122
+ }
123
+ catch { }
124
+ return wrap_array(svlist);
125
+ }
126
+ static async saveList(itemList, extraOptions = {}) {
127
+ if (!extraOptions)
128
+ extraOptions = {};
129
+ const chunks = array_chunks(itemList, extraOptions.chunksize ?? 50);
130
+ delete extraOptions.chunksize;
131
+ const putAddress = this.get_webpath();
132
+ for (let index = 0; index < chunks.length; index++) {
133
+ const items_to_save = chunks[index];
134
+ const save_array = [];
135
+ for (let k = 0; k < items_to_save.length; k++) {
136
+ const item = items_to_save[k];
137
+ const dlt = await item.get_deltaObject();
138
+ save_array.push(item.isNew
139
+ ? {
140
+ ...dlt,
141
+ }
142
+ : {
143
+ _id: item.getID(),
144
+ ...dlt,
145
+ });
146
+ }
147
+ const resultObject = await gfunc.run_action("post", putAddress, {
148
+ __save_list: WebObject.zipSaveList(save_array),
149
+ ...extraOptions,
150
+ });
151
+ if (Array.isArray(resultObject)) {
152
+ for (let index = 0; index < Math.min(resultObject.length, items_to_save.length); index++) {
153
+ const res = resultObject[index];
154
+ const item = items_to_save[index];
155
+ item.setSaveResult(res);
156
+ await item.onSave();
157
+ }
158
+ }
159
+ }
160
+ for (let index = 0; index < itemList.length; index++) {
161
+ const item = itemList[index];
162
+ if (!item.isSaved)
163
+ return false;
164
+ if (item.getSaveResultType() != "normal")
165
+ return false;
166
+ }
167
+ return true;
168
+ }
169
+ async Save() {
170
+ try {
171
+ if (this.manager) {
172
+ await this.manager.setOption("saving", true);
173
+ await this.manager.setOption("loading", true);
174
+ }
175
+ const deltaObject = await this.get_deltaObject();
176
+ const putAction = "post";
177
+ const usepath = await WebObjectPathHelper.get_path(this, this.isNew ? "new" : "save");
178
+ /* ---------------------------------- save ---------------------------------- */
179
+ if (!object_isEmpty(deltaObject)) {
180
+ const canSaveResult = this.canSave(deltaObject);
181
+ if (canSaveResult !== true) {
182
+ WebObject.addError(this, "Save not allowed", String(canSaveResult), true);
183
+ this.setSaveResult(false, "canceled");
184
+ return false;
185
+ }
186
+ const resultObject = await gfunc.run_action(putAction, usepath, deltaObject);
187
+ this.setSaveResult(resultObject, "auto", true);
188
+ }
189
+ else {
190
+ /* nothing to save */
191
+ this.setSaveResult(null, "nothing");
192
+ }
193
+ if (this.isSaved) {
194
+ await this.onSave();
195
+ return this.getSaveResult();
196
+ }
197
+ }
198
+ finally {
199
+ if (this.manager) {
200
+ await this.manager.setOption("saving", false);
201
+ await this.manager.setOption("loading", false);
202
+ }
203
+ }
204
+ }
205
+ async Delete() {
206
+ if (this.isNew)
207
+ return;
208
+ const usepath = await WebObjectPathHelper.get_path(this, "delete");
209
+ const resultObject = await gfunc.run_action("delete", usepath);
210
+ this.setSaveResult(resultObject, "auto", true);
211
+ await this.onDelete();
212
+ return resultObject;
213
+ }
214
+ async Lock() {
215
+ if (this.isNew || this.isArchived)
216
+ return;
217
+ const usepath = await WebObjectPathHelper.get_path(this, "lock");
218
+ const resultObject = await gfunc.run_action("post", usepath);
219
+ this.setSaveResult(resultObject, "auto", true);
220
+ await this.onLock();
221
+ return resultObject;
222
+ }
223
+ async UnLock() {
224
+ if (this.isNew || this.isArchived)
225
+ return;
226
+ const usepath = await WebObjectPathHelper.get_path(this, "unlock");
227
+ const resultObject = await gfunc.run_action("post", usepath);
228
+ this.setSaveResult(resultObject, "auto", true);
229
+ await this.onUnLock();
230
+ return resultObject;
231
+ }
232
+ async Archive() {
233
+ if (this.isNew || this.isArchived)
234
+ return;
235
+ const usepath = await WebObjectPathHelper.get_path(this, "archive");
236
+ const resultObject = await gfunc.run_action("post", usepath);
237
+ this.setSaveResult(resultObject, "auto", true);
238
+ await this.onArchive();
239
+ return resultObject;
240
+ }
241
+ async UnArchive() {
242
+ if (this.isNew || !this.isArchived)
243
+ return;
244
+ const usepath = await WebObjectPathHelper.get_path(this, "unarchive");
245
+ const resultObject = await gfunc.run_action("post", usepath);
246
+ await this.onUnArchive();
247
+ return resultObject;
248
+ }
249
+ /* -------------------------------------------------------------------------- */
250
+ canSave(deltaObj) {
251
+ const deltaRes = this.deltaIsValid(deltaObj);
252
+ if (deltaRes !== true)
253
+ return deltaRes;
254
+ return true;
255
+ }
256
+ canDelete() {
257
+ return true;
258
+ }
259
+ canArchive() {
260
+ return true;
261
+ }
262
+ deltaIsValid(d) {
263
+ return true;
264
+ }
265
+ /* -------------------------------------------------------------------------- */
266
+ /* get delta */
267
+ /* -------------------------------------------------------------------------- */
467
268
  /**
468
269
  * converts this object to an basic object
469
270
  * that can be passed into client components from server components
@@ -471,1154 +272,383 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
471
272
  * uses `get_fullDeltaObject`
472
273
  * @param p
473
274
  * @returns
474
- */
475
- }, {
476
- key: "get_basicObject",
477
- value: (function () {
478
- var _get_basicObject = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
479
- var fullobject, key, element;
480
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
481
- while (1) switch (_context8.prev = _context8.next) {
482
- case 0:
483
- _context8.next = 2;
484
- return this.get_fullObject();
485
- case 2:
486
- fullobject = _context8.sent;
487
- for (key in fullobject) {
488
- element = fullobject[key];
489
- /* --------------------------- check for id fields -------------------------- */
490
- if (element != null && _typeof(element) === "object") {
491
- if ((key === "id" || key.endsWith("_id")) && typeof element.toString === "function") {
492
- fullobject[key] = String(element);
493
- } else {
494
- fullobject[key] = JSON.parse(JSON.stringify(element));
495
- }
496
- }
497
- }
498
- return _context8.abrupt("return", fullobject);
499
- case 5:
500
- case "end":
501
- return _context8.stop();
502
- }
503
- }, _callee8, this);
504
- }));
505
- function get_basicObject() {
506
- return _get_basicObject.apply(this, arguments);
507
- }
508
- return get_basicObject;
509
- }()
275
+ */
276
+ async get_basicObject() {
277
+ const fullobject = await this.get_fullObject();
278
+ for (const key in fullobject) {
279
+ const element = fullobject[key];
280
+ /* --------------------------- check for id fields -------------------------- */
281
+ if (element != null && typeof element === "object") {
282
+ if ((key === "id" || key.endsWith("_id")) &&
283
+ typeof element.toString === "function") {
284
+ fullobject[key] = String(element);
285
+ }
286
+ else {
287
+ fullobject[key] = JSON.parse(JSON.stringify(element));
288
+ }
289
+ }
290
+ }
291
+ return fullobject;
292
+ }
510
293
  /**
511
294
  * calls the `get_deltaObject` with
512
295
  * `allProperties` `extraProperties`
513
296
  * set to true
514
297
  *
515
298
  * @returns
516
- */
517
- )
518
- }, {
519
- key: "get_fullDeltaObject",
520
- value: (function () {
521
- var _get_fullDeltaObject = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(p) {
522
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
523
- while (1) switch (_context9.prev = _context9.next) {
524
- case 0:
525
- _context9.next = 2;
526
- return this.get_deltaObject(_objectSpread({
527
- allProperties: true,
528
- extraProperties: true
529
- }, p));
530
- case 2:
531
- return _context9.abrupt("return", _context9.sent);
532
- case 3:
533
- case "end":
534
- return _context9.stop();
535
- }
536
- }, _callee9, this);
537
- }));
538
- function get_fullDeltaObject(_x3) {
539
- return _get_fullDeltaObject.apply(this, arguments);
540
- }
541
- return get_fullDeltaObject;
542
- }()
299
+ */
300
+ async get_fullDeltaObject(p) {
301
+ return await this.get_deltaObject({
302
+ allProperties: true,
303
+ extraProperties: true,
304
+ ...p,
305
+ });
306
+ }
543
307
  /**
544
308
  * calls the `get_deltaObject` with
545
309
  * `allProperties` `extraProperties` `tempProperties`
546
310
  * set to true
547
311
  *
548
312
  * @returns
549
- */
550
- )
551
- }, {
552
- key: "get_fullObject",
553
- value: (function () {
554
- var _get_fullObject = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(p) {
555
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
556
- while (1) switch (_context10.prev = _context10.next) {
557
- case 0:
558
- _context10.next = 2;
559
- return this.get_deltaObject(_objectSpread({
560
- allProperties: true,
561
- extraProperties: true,
562
- tempProperties: true
563
- }, p));
564
- case 2:
565
- return _context10.abrupt("return", _context10.sent);
566
- case 3:
567
- case "end":
568
- return _context10.stop();
569
- }
570
- }, _callee10, this);
571
- }));
572
- function get_fullObject(_x4) {
573
- return _get_fullObject.apply(this, arguments);
574
- }
575
- return get_fullObject;
576
- }()
313
+ */
314
+ async get_fullObject(p) {
315
+ return await this.get_deltaObject({
316
+ allProperties: true,
317
+ extraProperties: true,
318
+ tempProperties: true,
319
+ ...p,
320
+ });
321
+ }
577
322
  /**
578
323
  * You will post this to the server for saving
579
324
  * automatically removes unchangeable fields
580
325
  * @returns
581
- */
582
- )
583
- }, {
584
- key: "get_deltaObject",
585
- value: (function () {
586
- var _get_deltaObject = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(p) {
587
- var final_object, useDelta, changedFields, key, changeableKeys, functionProps, index, fp, parseObj, _parseObj, _iterator, _step, _key, gotIndex, gotId, tempusers;
588
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
589
- while (1) switch (_context13.prev = _context13.next) {
590
- case 0:
591
- _parseObj = function _parseObj3() {
592
- _parseObj = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(key, obj) {
593
- var _p, _child_changeableKeys, keydot, child_changeableKeys, newobj_dlt;
594
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
595
- while (1) switch (_context12.prev = _context12.next) {
596
- case 0:
597
- if (!(obj == null)) {
598
- _context12.next = 2;
599
- break;
600
- }
601
- return _context12.abrupt("return", undefined);
602
- case 2:
603
- if (!Array.isArray(obj)) {
604
- _context12.next = 6;
605
- break;
606
- }
607
- _context12.next = 5;
608
- return Promise.all(obj.map(/*#__PURE__*/function () {
609
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(r, i) {
610
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
611
- while (1) switch (_context11.prev = _context11.next) {
612
- case 0:
613
- _context11.next = 2;
614
- return parseObj(key, r);
615
- case 2:
616
- return _context11.abrupt("return", _context11.sent);
617
- case 3:
618
- case "end":
619
- return _context11.stop();
620
- }
621
- }, _callee11);
622
- }));
623
- return function (_x8, _x9) {
624
- return _ref.apply(this, arguments);
625
- };
626
- }()));
627
- case 5:
628
- return _context12.abrupt("return", _context12.sent);
629
- case 6:
630
- if (!(obj instanceof WebObject && typeof obj.get_deltaObject === "function")) {
631
- _context12.next = 18;
632
- break;
633
- }
634
- /* -------------------- parse changeableKeys for children -------------------- */
635
- keydot = "".concat(key, ".");
636
- child_changeableKeys = (_p = p) === null || _p === void 0 || (_p = _p.changeableKeys) === null || _p === void 0 ? void 0 : _p.filter(function (s) {
637
- return s.startsWith(keydot);
638
- }).map(function (r) {
639
- return r.substring(keydot.length);
640
- });
641
- /**
642
- * if no key is set for children consider it as undefined
643
- * if we send the empty array to get_delta we get no keys
644
- */
645
- if (child_changeableKeys == null || ((_child_changeableKeys = child_changeableKeys) === null || _child_changeableKeys === void 0 ? void 0 : _child_changeableKeys.length) === 0) {
646
- child_changeableKeys = undefined;
647
- }
648
- /* -------------------------------------------------------------------------- */
649
- //child elements have different kind of delta
650
- _context12.next = 12;
651
- return obj.get_deltaObject(_objectSpread(_objectSpread({}, p), {}, {
652
- isChild: true,
653
- changeableKeys: child_changeableKeys
654
- }));
655
- case 12:
656
- newobj_dlt = _context12.sent;
657
- if ((0, _object.object_isEmpty)(newobj_dlt)) {
658
- _context12.next = 17;
659
- break;
660
- }
661
- return _context12.abrupt("return", newobj_dlt);
662
- case 17:
663
- return _context12.abrupt("return", obj);
664
- case 18:
665
- return _context12.abrupt("return", obj);
666
- case 19:
667
- case "end":
668
- return _context12.stop();
669
- }
670
- }, _callee12);
671
- }));
672
- return _parseObj.apply(this, arguments);
673
- };
674
- parseObj = function _parseObj2(_x6, _x7) {
675
- return _parseObj.apply(this, arguments);
676
- };
677
- if (!p) p = {};
678
- final_object = {};
679
- useDelta = Boolean(this.__use_delta || p.useDelta);
680
- /**
681
- * child objects usually dont update their __delta
682
- * so we read info from all of its properties
683
- */
684
- changedFields = Boolean(p.allProperties || p.isChild || !useDelta) ? _objectSpread({}, this.allproperties) : _objectSpread({}, this.__delta);
685
- /* ------------- parse children that have WebObject as delta ------------- */
686
- _context13.t0 = _regeneratorRuntime().keys(this);
687
- case 7:
688
- if ((_context13.t1 = _context13.t0()).done) {
689
- _context13.next = 14;
690
- break;
691
- }
692
- key = _context13.t1.value;
693
- if (!(key.startsWith("__") || key in changedFields)) {
694
- _context13.next = 11;
695
- break;
696
- }
697
- return _context13.abrupt("continue", 7);
698
- case 11:
699
- if (_WebObjectHelper["default"].isChangedWebObjectField(this[key])) {
326
+ */
327
+ async get_deltaObject(p) {
328
+ if (!p)
329
+ p = {};
330
+ const final_object = {};
331
+ const useDelta = Boolean(this.__use_delta || p.useDelta);
332
+ /**
333
+ * child objects usually dont update their __delta
334
+ * so we read info from all of its properties
335
+ */
336
+ const changedFields = Boolean(p.allProperties || p.isChild || !useDelta)
337
+ ? { ...this.allproperties }
338
+ : { ...this.__delta };
339
+ /* ------------- parse children that have WebObject as delta ------------- */
340
+ for (const key in this) {
341
+ if (key.startsWith("__") || key in changedFields)
342
+ continue;
343
+ if (WebObjectHelper.isChangedWebObjectField(this[key])) {
700
344
  /**
701
345
  * if a child has any change we must add it into our delta
702
346
  * notice that the changes may not be saved to database depending on __changeables
703
347
  * but they are changes nevertheless
704
- */
705
- changedFields[key] = this[key];
706
- }
707
- _context13.next = 7;
708
- break;
709
- case 14:
710
- /**
711
- * get keys that can be changed.
712
- * intersection of keys in delta and keys that are defined as changeable
713
- */
714
- changeableKeys = (0, _object.array_intersection)(Object.keys(changedFields), WebObject.getChangeableKeys(this, p));
715
- /**
716
- * if parameter of changeableKeys is given, limit our keys with that param
717
- */
718
- if (p.changeableKeys) {
719
- changeableKeys = (0, _object.array_intersection)(changeableKeys, p.changeableKeys);
720
- }
721
- /* -------------------------------------------------------------------------- */
722
- _convert["default"].format({
723
- original: this,
724
- inputobject: changedFields,
725
- formats: (0, _object.object_getStatic)(this, "__formatList"),
726
- isNew: this.isNew,
727
- changeableKeys: changeableKeys,
728
- applyDefaults: true
729
- });
730
- /* -------------------------------------------------------------------------- */
731
- /* __functionProperties */
732
- /* -------------------------------------------------------------------------- */
733
- functionProps = (0, _object.object_getStatic)(this, "__functionProperties");
734
- for (index = 0; index < functionProps.length; index++) {
735
- fp = functionProps[index];
736
- if (changedFields[fp]) changedFields[fp] = (0, _object.fn_eval_this)(this, changedFields[fp]);
737
- }
738
- /* -------------------------------------------------------------------------- */
739
- /* parse all changeableKeys */
740
- /* -------------------------------------------------------------------------- */
741
- _iterator = _createForOfIteratorHelper(changeableKeys);
742
- _context13.prev = 20;
743
- _iterator.s();
744
- case 22:
745
- if ((_step = _iterator.n()).done) {
746
- _context13.next = 29;
747
- break;
748
- }
749
- _key = _step.value;
750
- _context13.next = 26;
751
- return parseObj(_key, changedFields[_key]);
752
- case 26:
753
- final_object[_key] = _context13.sent;
754
- case 27:
755
- _context13.next = 22;
756
- break;
757
- case 29:
758
- _context13.next = 34;
759
- break;
760
- case 31:
761
- _context13.prev = 31;
762
- _context13.t2 = _context13["catch"](20);
763
- _iterator.e(_context13.t2);
764
- case 34:
765
- _context13.prev = 34;
766
- _iterator.f();
767
- return _context13.finish(34);
768
- case 37:
769
- /* -------------------- add acrhived and date properties -------------------- */
770
- if (p.allProperties) {
771
- final_object["_created_date"] = this["_created_date"];
772
- final_object["_archived"] = this.isArchived;
773
- final_object["_deleted"] = this.isDeleted;
774
- }
775
- if (p.tempProperties) {
776
- final_object["__temp"] = this.__temp;
777
- }
778
- /* ---------------------------- add id properties --------------------------- */
779
- if (p.allProperties || p.needId || p.isChild) {
780
- if (this["_index_key"]) final_object["_index_key"] = this["_index_key"];
781
- gotIndex = this.getIndex();
782
- gotId = this.getID();
783
- if (gotIndex && gotIndex >= 0) final_object["_index_value"] = gotIndex;
784
- if (gotId) final_object["_id"] = gotId;
785
- }
786
- /* -------------------------------------------------------------------------- */
787
- /* fix _user property */
788
- /* -------------------------------------------------------------------------- */
789
- if (final_object["_users"]) {
790
- tempusers = final_object["_users"];
791
- if (typeof tempusers === "string") tempusers = tempusers.split(",").filter(function (s) {
792
- return s;
793
- });
794
- final_object["_users"] = (0, _object.wrap_array)(tempusers);
795
- }
796
- if (!p.clean) {
797
- _context13.next = 43;
798
- break;
799
- }
800
- return _context13.abrupt("return", (0, _object.object_clean)(final_object, false, true));
801
- case 43:
802
- return _context13.abrupt("return", final_object);
803
- case 44:
804
- case "end":
805
- return _context13.stop();
806
- }
807
- }, _callee13, this, [[20, 31, 34, 37]]);
808
- }));
809
- function get_deltaObject(_x5) {
810
- return _get_deltaObject.apply(this, arguments);
811
- }
812
- return get_deltaObject;
813
- }() /* --------------------------------- Getters -------------------------------- */)
814
- }, {
815
- key: "manager",
816
- get: function get() {
817
- return this.get_managerClass() || undefined;
818
- }
819
- }, {
820
- key: "__web_path",
821
- get: function get() {
822
- return this.constructor["__web_path"] || this.__db_name;
823
- }
824
- }, {
825
- key: "get_webpath",
826
- value: function get_webpath() {
827
- return this.__web_path || this.__db_name || "";
828
- }
829
- }, {
830
- key: "onDelete",
831
- value: (/* -------------------------------------------------------------------------- */function () {
832
- var _onDelete = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
833
- var _this$manager;
834
- var _len,
835
- p,
836
- _key2,
837
- _args14 = arguments;
838
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
839
- while (1) switch (_context14.prev = _context14.next) {
840
- case 0:
841
- if (this.isSaved) this.isDeleted = true;
842
- for (_len = _args14.length, p = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
843
- p[_key2] = _args14[_key2];
844
- }
845
- _context14.next = 4;
846
- return (_this$manager = this.manager) === null || _this$manager === void 0 ? void 0 : _this$manager.onDelete.apply(_this$manager, p);
847
- case 4:
848
- return _context14.abrupt("return", _context14.sent);
849
- case 5:
850
- case "end":
851
- return _context14.stop();
852
- }
853
- }, _callee14, this);
854
- }));
855
- function onDelete() {
856
- return _onDelete.apply(this, arguments);
857
- }
858
- return onDelete;
859
- }())
860
- }, {
861
- key: "onArchive",
862
- value: function () {
863
- var _onArchive = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
864
- var _this$manager2;
865
- var _len2,
866
- p,
867
- _key3,
868
- _args15 = arguments;
869
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
870
- while (1) switch (_context15.prev = _context15.next) {
871
- case 0:
872
- if (this.isSaved) this.isArchived = true;
873
- for (_len2 = _args15.length, p = new Array(_len2), _key3 = 0; _key3 < _len2; _key3++) {
874
- p[_key3] = _args15[_key3];
875
- }
876
- _context15.next = 4;
877
- return (_this$manager2 = this.manager) === null || _this$manager2 === void 0 ? void 0 : _this$manager2.onArchive.apply(_this$manager2, p);
878
- case 4:
879
- return _context15.abrupt("return", _context15.sent);
880
- case 5:
881
- case "end":
882
- return _context15.stop();
883
- }
884
- }, _callee15, this);
885
- }));
886
- function onArchive() {
887
- return _onArchive.apply(this, arguments);
888
- }
889
- return onArchive;
890
- }()
891
- }, {
892
- key: "onUnArchive",
893
- value: function () {
894
- var _onUnArchive = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
895
- var _this$manager3;
896
- var _len3,
897
- p,
898
- _key4,
899
- _args16 = arguments;
900
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
901
- while (1) switch (_context16.prev = _context16.next) {
902
- case 0:
903
- if (this.isSaved) this.isArchived = false;
904
- for (_len3 = _args16.length, p = new Array(_len3), _key4 = 0; _key4 < _len3; _key4++) {
905
- p[_key4] = _args16[_key4];
906
- }
907
- _context16.next = 4;
908
- return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.onUnArchive.apply(_this$manager3, p);
909
- case 4:
910
- return _context16.abrupt("return", _context16.sent);
911
- case 5:
912
- case "end":
913
- return _context16.stop();
914
- }
915
- }, _callee16, this);
916
- }));
917
- function onUnArchive() {
918
- return _onUnArchive.apply(this, arguments);
919
- }
920
- return onUnArchive;
921
- }()
922
- }, {
923
- key: "onLock",
924
- value: function () {
925
- var _onLock = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
926
- var _this$manager4;
927
- var _len4,
928
- p,
929
- _key5,
930
- _args17 = arguments;
931
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
932
- while (1) switch (_context17.prev = _context17.next) {
933
- case 0:
934
- if (this.isSaved) this.isLocked = true;
935
- for (_len4 = _args17.length, p = new Array(_len4), _key5 = 0; _key5 < _len4; _key5++) {
936
- p[_key5] = _args17[_key5];
937
- }
938
- _context17.next = 4;
939
- return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onLock.apply(_this$manager4, p);
940
- case 4:
941
- return _context17.abrupt("return", _context17.sent);
942
- case 5:
943
- case "end":
944
- return _context17.stop();
945
- }
946
- }, _callee17, this);
947
- }));
948
- function onLock() {
949
- return _onLock.apply(this, arguments);
950
- }
951
- return onLock;
952
- }()
953
- }, {
954
- key: "onUnLock",
955
- value: function () {
956
- var _onUnLock = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
957
- var _this$manager5;
958
- var _len5,
959
- p,
960
- _key6,
961
- _args18 = arguments;
962
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
963
- while (1) switch (_context18.prev = _context18.next) {
964
- case 0:
965
- if (this.isSaved) this.isLocked = false;
966
- for (_len5 = _args18.length, p = new Array(_len5), _key6 = 0; _key6 < _len5; _key6++) {
967
- p[_key6] = _args18[_key6];
968
- }
969
- _context18.next = 4;
970
- return (_this$manager5 = this.manager) === null || _this$manager5 === void 0 ? void 0 : _this$manager5.onUnLock.apply(_this$manager5, p);
971
- case 4:
972
- return _context18.abrupt("return", _context18.sent);
973
- case 5:
974
- case "end":
975
- return _context18.stop();
976
- }
977
- }, _callee18, this);
978
- }));
979
- function onUnLock() {
980
- return _onUnLock.apply(this, arguments);
981
- }
982
- return onUnLock;
983
- }()
984
- }, {
985
- key: "onLoad",
986
- value: function () {
987
- var _onLoad = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
988
- var _this$manager6;
989
- var _len6,
990
- p,
991
- _key7,
992
- _args19 = arguments;
993
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
994
- while (1) switch (_context19.prev = _context19.next) {
995
- case 0:
996
- this.isDeleted = false;
997
- for (_len6 = _args19.length, p = new Array(_len6), _key7 = 0; _key7 < _len6; _key7++) {
998
- p[_key7] = _args19[_key7];
999
- }
1000
- _context19.next = 4;
1001
- return (_this$manager6 = this.manager) === null || _this$manager6 === void 0 ? void 0 : _this$manager6.onLoad.apply(_this$manager6, p);
1002
- case 4:
1003
- return _context19.abrupt("return", _context19.sent);
1004
- case 5:
1005
- case "end":
1006
- return _context19.stop();
1007
- }
1008
- }, _callee19, this);
1009
- }));
1010
- function onLoad() {
1011
- return _onLoad.apply(this, arguments);
1012
- }
1013
- return onLoad;
1014
- }()
1015
- }, {
1016
- key: "onSave",
1017
- value: function () {
1018
- var _onSave = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1019
- var _this$manager8;
1020
- var srObject,
1021
- _this$manager7,
1022
- _len7,
1023
- p,
1024
- _key8,
1025
- _args20 = arguments;
1026
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1027
- while (1) switch (_context20.prev = _context20.next) {
1028
- case 0:
1029
- if (!this.isSaved) {
1030
- _context20.next = 7;
1031
- break;
1032
- }
1033
- this.apply_changes();
1034
- srObject = this.getSaveResult(true);
1035
- if (!this.saveResultHasID(srObject)) {
1036
- _context20.next = 7;
1037
- break;
1038
- }
1039
- /* -------------------------------------------------------------------------- */
1040
- WebObject.LoadIdsFromSaveResult(this, srObject);
1041
- _context20.next = 7;
1042
- return (_this$manager7 = this.manager) === null || _this$manager7 === void 0 ? void 0 : _this$manager7.event_run("on_id_change");
1043
- case 7:
1044
- for (_len7 = _args20.length, p = new Array(_len7), _key8 = 0; _key8 < _len7; _key8++) {
1045
- p[_key8] = _args20[_key8];
1046
- }
1047
- _context20.next = 10;
1048
- return (_this$manager8 = this.manager) === null || _this$manager8 === void 0 ? void 0 : _this$manager8.onSave.apply(_this$manager8, p);
1049
- case 10:
1050
- _context20.next = 12;
1051
- return this.onAfterSave();
1052
- case 12:
1053
- return _context20.abrupt("return", true);
1054
- case 13:
1055
- case "end":
1056
- return _context20.stop();
1057
- }
1058
- }, _callee20, this);
1059
- }));
1060
- function onSave() {
1061
- return _onSave.apply(this, arguments);
1062
- }
1063
- return onSave;
1064
- }()
1065
- }, {
1066
- key: "onAfterSave",
1067
- value: function () {
1068
- var _onAfterSave = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1069
- var _this$manager9;
1070
- var _len8,
1071
- p,
1072
- _key9,
1073
- _args21 = arguments;
1074
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1075
- while (1) switch (_context21.prev = _context21.next) {
1076
- case 0:
1077
- for (_len8 = _args21.length, p = new Array(_len8), _key9 = 0; _key9 < _len8; _key9++) {
1078
- p[_key9] = _args21[_key9];
1079
- }
1080
- _context21.next = 3;
1081
- return (_this$manager9 = this.manager) === null || _this$manager9 === void 0 ? void 0 : _this$manager9.onAfterSave.apply(_this$manager9, p);
1082
- case 3:
1083
- return _context21.abrupt("return", true);
1084
- case 4:
1085
- case "end":
1086
- return _context21.stop();
1087
- }
1088
- }, _callee21, this);
1089
- }));
1090
- function onAfterSave() {
1091
- return _onAfterSave.apply(this, arguments);
1092
- }
1093
- return onAfterSave;
1094
- }()
1095
- }, {
1096
- key: "getSaveResult",
1097
- value: function getSaveResult() {
1098
- var _this2 = this;
1099
- var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1100
- var srObject = _superPropGet(WebObject, "getSaveResult", this, 3)([original]);
1101
- if (!srObject) return false;
1102
- if (Array.isArray(srObject)) {
1103
- var actual_sr = srObject.find(function (s) {
1104
- return _this2.saveResultHasID(s);
1105
- });
1106
- if (actual_sr) srObject = actual_sr;
1107
- }
1108
- return srObject;
1109
- }
1110
- }, {
1111
- key: "onNew",
1112
- value: function () {
1113
- var _onNew = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1114
- var _this$manager10;
1115
- var _len9,
1116
- p,
1117
- _key10,
1118
- _args22 = arguments;
1119
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1120
- while (1) switch (_context22.prev = _context22.next) {
1121
- case 0:
1122
- for (_len9 = _args22.length, p = new Array(_len9), _key10 = 0; _key10 < _len9; _key10++) {
1123
- p[_key10] = _args22[_key10];
1124
- }
1125
- _context22.next = 3;
1126
- return (_this$manager10 = this.manager) === null || _this$manager10 === void 0 ? void 0 : _this$manager10.onNew.apply(_this$manager10, p);
1127
- case 3:
1128
- return _context22.abrupt("return", _context22.sent);
1129
- case 4:
1130
- case "end":
1131
- return _context22.stop();
1132
- }
1133
- }, _callee22, this);
1134
- }));
1135
- function onNew() {
1136
- return _onNew.apply(this, arguments);
1137
- }
1138
- return onNew;
1139
- }() /* -------------------------------------------------------------------------- */
1140
- }, {
1141
- key: "saveResultHasID",
1142
- value: function saveResultHasID(s) {
1143
- return WebObject.saveResultHasID(s);
1144
- }
1145
- }], [{
1146
- key: "getAllUsers",
1147
- value: function getAllUsers(obj) {
1148
- if (_typeof(obj) != "object") return [];
1149
- return (0, _object.array_remove_duplicates)((0, _object.array_merge)(obj._creator, (0, _object.wrap_array)(obj._users), (0, _object.wrap_array)(obj.attentions)).map(function (r) {
1150
- return String(_typeof(r) === "object" ? WebObject.getID(r) : r);
1151
- }).filter(function (s) {
1152
- return s;
1153
- }));
1154
- }
1155
- }, {
1156
- key: "getMetaValue",
1157
- value: function getMetaValue(o, key) {
1158
- if (o == null) return null;
1159
- if (!key || typeof key != "string") return undefined;
1160
- var metalist = {};
1161
- if (_typeof(o) === "object") {
1162
- metalist = typeof o.get === "function" ? o.get("meta_data") : o.meta_data;
1163
- }
1164
- return metalist[key];
1165
- }
1166
- /* -------------------------------------------------------------------------- */
1167
- /* Save */
1168
- /* -------------------------------------------------------------------------- */
1169
- }, {
1170
- key: "zipSaveList",
1171
- value: function zipSaveList(svlist) {
1172
- if (_typeof(svlist) === "object") svlist = JSON.stringify(svlist);
1173
- return (0, _string.string_compress)(svlist);
1174
- }
1175
- }, {
1176
- key: "unzipSaveList",
1177
- value: function unzipSaveList(svlist) {
1178
- try {
1179
- if (_typeof(svlist) === "object") {
1180
- if (Array.isArray(svlist)) return svlist;
1181
- if (svlist.__save_list) return this.unzipSaveList(svlist.__save_list);
1182
- } else if (typeof svlist === "string") return (0, _object.wrap_array)(JSON.parse((0, _string.string_decompress)(svlist)));
1183
- } catch (_unused) {}
1184
- return (0, _object.wrap_array)(svlist);
1185
- }
1186
- }, {
1187
- key: "saveList",
1188
- value: function () {
1189
- var _saveList = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee23(itemList) {
1190
- var _extraOptions$chunksi;
1191
- var extraOptions,
1192
- chunks,
1193
- putAddress,
1194
- index,
1195
- items_to_save,
1196
- save_array,
1197
- k,
1198
- item,
1199
- dlt,
1200
- resultObject,
1201
- _index,
1202
- res,
1203
- _item,
1204
- _index2,
1205
- _item2,
1206
- _args23 = arguments;
1207
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1208
- while (1) switch (_context23.prev = _context23.next) {
1209
- case 0:
1210
- extraOptions = _args23.length > 1 && _args23[1] !== undefined ? _args23[1] : {};
1211
- if (!extraOptions) extraOptions = {};
1212
- chunks = (0, _object.array_chunks)(itemList, (_extraOptions$chunksi = extraOptions.chunksize) !== null && _extraOptions$chunksi !== void 0 ? _extraOptions$chunksi : 50);
1213
- delete extraOptions.chunksize;
1214
- putAddress = this.get_webpath();
1215
- index = 0;
1216
- case 6:
1217
- if (!(index < chunks.length)) {
1218
- _context23.next = 36;
1219
- break;
1220
- }
1221
- items_to_save = chunks[index];
1222
- save_array = [];
1223
- k = 0;
1224
- case 10:
1225
- if (!(k < items_to_save.length)) {
1226
- _context23.next = 19;
1227
- break;
1228
- }
1229
- item = items_to_save[k];
1230
- _context23.next = 14;
1231
- return item.get_deltaObject();
1232
- case 14:
1233
- dlt = _context23.sent;
1234
- save_array.push(item.isNew ? _objectSpread({}, dlt) : _objectSpread({
1235
- _id: item.getID()
1236
- }, dlt));
1237
- case 16:
1238
- k++;
1239
- _context23.next = 10;
1240
- break;
1241
- case 19:
1242
- _context23.next = 21;
1243
- return _global.gfunc.run_action("post", putAddress, _objectSpread({
1244
- __save_list: WebObject.zipSaveList(save_array)
1245
- }, extraOptions));
1246
- case 21:
1247
- resultObject = _context23.sent;
1248
- if (!Array.isArray(resultObject)) {
1249
- _context23.next = 33;
1250
- break;
1251
- }
1252
- _index = 0;
1253
- case 24:
1254
- if (!(_index < Math.min(resultObject.length, items_to_save.length))) {
1255
- _context23.next = 33;
1256
- break;
1257
- }
1258
- res = resultObject[_index];
1259
- _item = items_to_save[_index];
1260
- _item.setSaveResult(res);
1261
- _context23.next = 30;
1262
- return _item.onSave();
1263
- case 30:
1264
- _index++;
1265
- _context23.next = 24;
1266
- break;
1267
- case 33:
1268
- index++;
1269
- _context23.next = 6;
1270
- break;
1271
- case 36:
1272
- _index2 = 0;
1273
- case 37:
1274
- if (!(_index2 < itemList.length)) {
1275
- _context23.next = 46;
1276
- break;
1277
- }
1278
- _item2 = itemList[_index2];
1279
- if (_item2.isSaved) {
1280
- _context23.next = 41;
1281
- break;
1282
- }
1283
- return _context23.abrupt("return", false);
1284
- case 41:
1285
- if (!(_item2.getSaveResultType() != "normal")) {
1286
- _context23.next = 43;
1287
- break;
1288
- }
1289
- return _context23.abrupt("return", false);
1290
- case 43:
1291
- _index2++;
1292
- _context23.next = 37;
1293
- break;
1294
- case 46:
1295
- return _context23.abrupt("return", true);
1296
- case 47:
1297
- case "end":
1298
- return _context23.stop();
1299
- }
1300
- }, _callee23, this);
1301
- }));
1302
- function saveList(_x10) {
1303
- return _saveList.apply(this, arguments);
1304
- }
1305
- return saveList;
1306
- }()
1307
- }, {
1308
- key: "get_webpath",
1309
- value: function get_webpath() {
1310
- return this.__web_path || this.__db_name || "";
1311
- }
1312
- }, {
1313
- key: "get_dbname",
1314
- value: function get_dbname() {
1315
- return this.__db_name || this.__web_path || "";
1316
- }
1317
- }, {
1318
- key: "saveResultHasID",
1319
- value: function saveResultHasID(s) {
1320
- if (_typeof(s) !== "object" || s == null || !s) return false;
1321
- return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
1322
- }
348
+ */
349
+ changedFields[key] = this[key];
350
+ }
351
+ }
352
+ /**
353
+ * get keys that can be changed.
354
+ * intersection of keys in delta and keys that are defined as changeable
355
+ */
356
+ let changeableKeys = array_intersection(Object.keys(changedFields), WebObject.getChangeableKeys(this, p));
357
+ /**
358
+ * if parameter of changeableKeys is given, limit our keys with that param
359
+ */
360
+ if (p.changeableKeys) {
361
+ changeableKeys = array_intersection(changeableKeys, p.changeableKeys);
362
+ }
363
+ /* -------------------------------------------------------------------------- */
364
+ FormatHelper.format({
365
+ original: this,
366
+ inputobject: changedFields,
367
+ formats: object_getStatic(this, "__formatList"),
368
+ isNew: this.isNew,
369
+ changeableKeys: changeableKeys,
370
+ applyDefaults: true,
371
+ });
372
+ /* -------------------------------------------------------------------------- */
373
+ /* __functionProperties */
374
+ /* -------------------------------------------------------------------------- */
375
+ const functionProps = object_getStatic(this, "__functionProperties");
376
+ for (let index = 0; index < functionProps.length; index++) {
377
+ const fp = functionProps[index];
378
+ if (changedFields[fp])
379
+ changedFields[fp] = fn_eval_this(this, changedFields[fp]);
380
+ }
381
+ /* -------------------------------------------------------------------------- */
382
+ /* parse all changeableKeys */
383
+ /* -------------------------------------------------------------------------- */
384
+ async function parseObj(key, obj) {
385
+ if (obj == null)
386
+ return undefined;
387
+ if (Array.isArray(obj))
388
+ return await Promise.all(obj.map(async (r, i) => await parseObj(key, r)));
389
+ if (obj instanceof WebObject &&
390
+ typeof obj.get_deltaObject === "function") {
391
+ /* -------------------- parse changeableKeys for children -------------------- */
392
+ const keydot = `${key}.`;
393
+ let child_changeableKeys = p?.changeableKeys
394
+ ?.filter((s) => s.startsWith(keydot))
395
+ .map((r) => r.substring(keydot.length));
396
+ /**
397
+ * if no key is set for children consider it as undefined
398
+ * if we send the empty array to get_delta we get no keys
399
+ */
400
+ if (child_changeableKeys == null ||
401
+ child_changeableKeys?.length === 0) {
402
+ child_changeableKeys = undefined;
403
+ }
404
+ /* -------------------------------------------------------------------------- */
405
+ //child elements have different kind of delta
406
+ const newobj_dlt = await obj.get_deltaObject({
407
+ ...p,
408
+ isChild: true,
409
+ changeableKeys: child_changeableKeys,
410
+ });
411
+ if (!object_isEmpty(newobj_dlt))
412
+ return newobj_dlt;
413
+ else
414
+ return obj;
415
+ }
416
+ return obj;
417
+ }
418
+ for (const key of changeableKeys) {
419
+ final_object[key] = await parseObj(key, changedFields[key]);
420
+ }
421
+ /* -------------------- add acrhived and date properties -------------------- */
422
+ if (p.allProperties) {
423
+ final_object["_created_date"] = this["_created_date"];
424
+ final_object["_archived"] = this.isArchived;
425
+ final_object["_deleted"] = this.isDeleted;
426
+ }
427
+ if (p.tempProperties) {
428
+ final_object["__temp"] = this.__temp;
429
+ }
430
+ /* ---------------------------- add id properties --------------------------- */
431
+ if (p.allProperties || p.needId || p.isChild) {
432
+ if (this["_index_key"])
433
+ final_object["_index_key"] = this["_index_key"];
434
+ const gotIndex = this.getIndex();
435
+ const gotId = this.getID();
436
+ if (gotIndex && gotIndex >= 0)
437
+ final_object["_index_value"] = gotIndex;
438
+ if (gotId)
439
+ final_object["_id"] = gotId;
440
+ }
441
+ /* -------------------------------------------------------------------------- */
442
+ /* fix _user property */
443
+ /* -------------------------------------------------------------------------- */
444
+ if (final_object["_users"]) {
445
+ let tempusers = final_object["_users"];
446
+ if (typeof tempusers === "string")
447
+ tempusers = tempusers.split(",").filter((s) => s);
448
+ final_object["_users"] = wrap_array(tempusers);
449
+ }
450
+ if (p.clean)
451
+ return object_clean(final_object, false, true);
452
+ return final_object;
453
+ }
454
+ /* --------------------------------- Getters -------------------------------- */
455
+ get manager() {
456
+ return this.get_managerClass() || undefined;
457
+ }
458
+ get __web_path() {
459
+ return this.constructor["__web_path"] || this.__db_name;
460
+ }
461
+ get_webpath() {
462
+ return this.__web_path || this.__db_name || "";
463
+ }
464
+ static get_webpath() {
465
+ return this.__web_path || this.__db_name || "";
466
+ }
467
+ static get_dbname() {
468
+ return this.__db_name || this.__web_path || "";
469
+ }
470
+ /* -------------------------------------------------------------------------- */
471
+ async onDelete(...p) {
472
+ if (this.isSaved)
473
+ this.isDeleted = true;
474
+ return await this.manager?.onDelete(...p); //events are handled by the manager
475
+ }
476
+ async onArchive(...p) {
477
+ if (this.isSaved)
478
+ this.isArchived = true;
479
+ return await this.manager?.onArchive(...p); //events are handled by the manager
480
+ }
481
+ async onUnArchive(...p) {
482
+ if (this.isSaved)
483
+ this.isArchived = false;
484
+ return await this.manager?.onUnArchive(...p); //events are handled by the manager
485
+ }
486
+ async onLock(...p) {
487
+ if (this.isSaved)
488
+ this.isLocked = true;
489
+ return await this.manager?.onLock(...p); //events are handled by the manager
490
+ }
491
+ async onUnLock(...p) {
492
+ if (this.isSaved)
493
+ this.isLocked = false;
494
+ return await this.manager?.onUnLock(...p); //events are handled by the manager
495
+ }
496
+ async onLoad(...p) {
497
+ this.isDeleted = false;
498
+ return await this.manager?.onLoad(...p); //events are handled by the manager
499
+ }
500
+ async onSave(...p) {
501
+ if (this.isSaved) {
502
+ this.apply_changes();
503
+ var srObject = this.getSaveResult(true);
504
+ if (this.saveResultHasID(srObject)) {
505
+ /* -------------------------------------------------------------------------- */
506
+ WebObject.LoadIdsFromSaveResult(this, srObject);
507
+ await this.manager?.event_run("on_id_change");
508
+ }
509
+ }
510
+ await this.manager?.onSave(...p); //events are handled by the manager
511
+ await this.onAfterSave();
512
+ return true;
513
+ }
514
+ async onAfterSave(...p) {
515
+ await this.manager?.onAfterSave(...p); //events are handled by the manager
516
+ return true;
517
+ }
518
+ getSaveResult(original = false) {
519
+ let srObject = super.getSaveResult(original);
520
+ if (!srObject)
521
+ return false;
522
+ if (Array.isArray(srObject)) {
523
+ const actual_sr = srObject.find((s) => this.saveResultHasID(s));
524
+ if (actual_sr)
525
+ srObject = actual_sr;
526
+ }
527
+ return srObject;
528
+ }
529
+ async onNew(...p) {
530
+ return await this.manager?.onNew(...p); //events are handled by the manager
531
+ }
532
+ /* -------------------------------------------------------------------------- */
533
+ saveResultHasID(s) {
534
+ return WebObject.saveResultHasID(s);
535
+ }
536
+ static saveResultHasID(s) {
537
+ if (typeof s !== "object" || s == null || !s)
538
+ return false;
539
+ return (s.insertedId ||
540
+ s._id ||
541
+ (s._index_value && !Number.isNaN(s._index_value)));
542
+ }
1323
543
  /**
1324
544
  * Load Id and _index_value from the given save result into our object
1325
545
  * @param o
1326
546
  * @param srObject
1327
547
  * @returns
1328
- */
1329
- }, {
1330
- key: "LoadIdsFromSaveResult",
1331
- value: function LoadIdsFromSaveResult(o, srObject) {
1332
- if (_typeof(o) !== "object" || _typeof(srObject) !== "object") return;
1333
- /* -------------------------------------------------------------------------- */
1334
- var srID = srObject.insertedId || srObject._id || WebObject.getID(srObject);
1335
- if (srID) {
1336
- o._id = srID;
1337
- }
1338
- /* -------------------------------------------------------------------------- */
1339
- if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
1340
- o._index_value = Number(srObject._index_value);
1341
- }
1342
- /* -------------------------------------------------------------------------- */
1343
- if (srObject._index_key) {
1344
- o._index_key = srObject._index_key;
1345
- }
1346
- }
1347
- /* -------------------------------------------------------------------------- */
548
+ */
549
+ static LoadIdsFromSaveResult(o, srObject) {
550
+ if (typeof o !== "object" || typeof srObject !== "object")
551
+ return;
552
+ /* -------------------------------------------------------------------------- */
553
+ const srID = srObject.insertedId || srObject._id || WebObject.getID(srObject);
554
+ if (srID) {
555
+ o._id = srID;
556
+ }
557
+ /* -------------------------------------------------------------------------- */
558
+ if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
559
+ o._index_value = Number(srObject._index_value);
560
+ }
561
+ /* -------------------------------------------------------------------------- */
562
+ if (srObject._index_key) {
563
+ o._index_key = srObject._index_key;
564
+ }
565
+ }
566
+ /* -------------------------------------------------------------------------- */
1348
567
  /**
1349
568
  * get a single web object
1350
569
  * default order of parameters : search,readonly,fetchID
1351
- */
1352
- }, {
1353
- key: "get_single",
1354
- value: (function () {
1355
- var _get_single = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1356
- var _p$shift;
1357
- var _len10,
1358
- p,
1359
- _key11,
1360
- search,
1361
- readonly,
1362
- fetchID,
1363
- result,
1364
- params,
1365
- _args24 = arguments;
1366
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1367
- while (1) switch (_context24.prev = _context24.next) {
1368
- case 0:
1369
- for (_len10 = _args24.length, p = new Array(_len10), _key11 = 0; _key11 < _len10; _key11++) {
1370
- p[_key11] = _args24[_key11];
1371
- }
1372
- search = p.shift();
1373
- readonly = (_p$shift = p.shift()) !== null && _p$shift !== void 0 ? _p$shift : false;
1374
- fetchID = p.shift();
1375
- if (!(0, _object.object_isEmpty)(search)) {
1376
- _context24.next = 6;
1377
- break;
1378
- }
1379
- return _context24.abrupt("return", undefined);
1380
- case 6:
1381
- params = {};
1382
- params.__context = readonly ? "view" : "edit";
1383
- _context24.t0 = _typeof(search);
1384
- _context24.next = _context24.t0 === "string" ? 11 : _context24.t0 === "number" ? 11 : _context24.t0 === "object" ? 16 : 16;
1385
- break;
1386
- case 11:
1387
- search = String(search);
1388
- // const usepath =
1389
- // (await WebObjectPathHelper.get_path(this, "get")) +
1390
- // "/" +
1391
- // search;
1392
- // res = await gfunc.run_action("get", usepath, params, {
1393
- // fetchID: fetchID,
1394
- // });
1395
- _context24.next = 14;
1396
- return this.get_list({
1397
- __searchid: search
1398
- }, readonly, fetchID);
1399
- case 14:
1400
- result = _context24.sent;
1401
- return _context24.abrupt("break", 20);
1402
- case 16:
1403
- _context24.next = 18;
1404
- return this.get_list(search, readonly, fetchID);
1405
- case 18:
1406
- result = _context24.sent;
1407
- return _context24.abrupt("break", 20);
1408
- case 20:
1409
- if (result) result = (0, _object.array_first)(result);
1410
- if (!(0, _object.object_isEmpty)(result)) {
1411
- result = this.ensure(this, result);
1412
- WebObject.setReadonly(result, readonly);
1413
- }
1414
- return _context24.abrupt("return", result);
1415
- case 23:
1416
- case "end":
1417
- return _context24.stop();
1418
- }
1419
- }, _callee24, this);
1420
- }));
1421
- function get_single() {
1422
- return _get_single.apply(this, arguments);
1423
- }
1424
- return get_single;
1425
- }()
570
+ */
571
+ static async get_single(...p) {
572
+ let search = p.shift();
573
+ let readonly = p.shift() ?? false;
574
+ let fetchID = p.shift();
575
+ if (object_isEmpty(search))
576
+ return undefined;
577
+ let result;
578
+ const params = {};
579
+ params.__context = readonly ? "view" : "edit";
580
+ switch (typeof search) {
581
+ case "string":
582
+ case "number":
583
+ search = String(search);
584
+ // const usepath =
585
+ // (await WebObjectPathHelper.get_path(this, "get")) +
586
+ // "/" +
587
+ // search;
588
+ // res = await gfunc.run_action("get", usepath, params, {
589
+ // fetchID: fetchID,
590
+ // });
591
+ result = await this.get_list({ __searchid: search }, readonly, fetchID);
592
+ break;
593
+ case "object":
594
+ default:
595
+ result = await this.get_list(search, readonly, fetchID);
596
+ break;
597
+ }
598
+ if (result)
599
+ result = array_first(result);
600
+ if (!object_isEmpty(result)) {
601
+ result = this.ensure(this, result);
602
+ WebObject.setReadonly(result, readonly);
603
+ }
604
+ return result;
605
+ }
1426
606
  /**
1427
607
  * Get a list of web objects
1428
608
  * default order of parameters : search,readonly,fetchID
1429
- */
1430
- )
1431
- }, {
1432
- key: "get_list",
1433
- value: (function () {
1434
- var _get_list = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1435
- var _p$shift2;
1436
- var _len11,
1437
- p,
1438
- _key12,
1439
- search,
1440
- readonly,
1441
- fetchID,
1442
- usepath,
1443
- result_items,
1444
- res,
1445
- _args25 = arguments;
1446
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1447
- while (1) switch (_context25.prev = _context25.next) {
1448
- case 0:
1449
- for (_len11 = _args25.length, p = new Array(_len11), _key12 = 0; _key12 < _len11; _key12++) {
1450
- p[_key12] = _args25[_key12];
1451
- }
1452
- search = p.shift();
1453
- readonly = (_p$shift2 = p.shift()) !== null && _p$shift2 !== void 0 ? _p$shift2 : false;
1454
- fetchID = p.shift();
1455
- if (!search) search = {};
1456
- _context25.next = 7;
1457
- return _WebObjectPathHelper["default"].get_path(this, "get");
1458
- case 7:
1459
- usepath = _context25.sent;
1460
- _context25.next = 10;
1461
- return _global.gfunc.run_action("get", usepath, search, {
1462
- fetchID: fetchID
1463
- });
1464
- case 10:
1465
- result_items = _context25.sent;
1466
- // const selftype = (this.constructor ||
1467
- // Object.getPrototypeOf(this)) as any;
1468
- res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
1469
- WebObject.setReadonly(res, readonly);
1470
- return _context25.abrupt("return", res);
1471
- case 14:
1472
- case "end":
1473
- return _context25.stop();
1474
- }
1475
- }, _callee25, this);
1476
- }));
1477
- function get_list() {
1478
- return _get_list.apply(this, arguments);
1479
- }
1480
- return get_list;
1481
- }()
609
+ */
610
+ static async get_list(...p) {
611
+ let search = p.shift();
612
+ let readonly = p.shift() ?? false;
613
+ let fetchID = p.shift();
614
+ if (!search)
615
+ search = {};
616
+ const usepath = await WebObjectPathHelper.get_path(this, "get");
617
+ let result_items = await gfunc.run_action("get", usepath, search, { fetchID: fetchID });
618
+ // const selftype = (this.constructor ||
619
+ // Object.getPrototypeOf(this)) as any;
620
+ const res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
621
+ WebObject.setReadonly(res, readonly);
622
+ return res;
623
+ }
1482
624
  /**
1483
625
  * uses `get_list` and then saves the result to `gcache`
1484
626
  * then uses the `equals` function to return matched results
1485
627
  * @param search
1486
628
  * @returns
1487
- */
1488
- )
1489
- }, {
1490
- key: "get_list_cache",
1491
- value: (function () {
1492
- var _get_list_cache = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee27(search) {
1493
- var _this3 = this;
1494
- var all_data;
1495
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1496
- while (1) switch (_context27.prev = _context27.next) {
1497
- case 0:
1498
- _context27.next = 2;
1499
- return _global.gcache.get_temp_cache(this.get_webpath(), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1500
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1501
- while (1) switch (_context26.prev = _context26.next) {
1502
- case 0:
1503
- _context26.next = 2;
1504
- return _this3.get_list();
1505
- case 2:
1506
- return _context26.abrupt("return", _context26.sent);
1507
- case 3:
1508
- case "end":
1509
- return _context26.stop();
1510
- }
1511
- }, _callee26);
1512
- })));
1513
- case 2:
1514
- all_data = _context27.sent;
1515
- if (search) {
1516
- _context27.next = 5;
1517
- break;
1518
- }
1519
- return _context27.abrupt("return", all_data);
1520
- case 5:
1521
- return _context27.abrupt("return", all_data.filter(function (s) {
1522
- return _this3.equals(s, search);
1523
- }));
1524
- case 6:
1525
- case "end":
1526
- return _context27.stop();
1527
- }
1528
- }, _callee27, this);
1529
- }));
1530
- function get_list_cache(_x11) {
1531
- return _get_list_cache.apply(this, arguments);
1532
- }
1533
- return get_list_cache;
1534
- }()
629
+ */
630
+ static async get_list_cache(search) {
631
+ const all_data = await gcache.get_temp_cache(this.get_webpath(), async () => await this.get_list());
632
+ if (!search)
633
+ return all_data;
634
+ return all_data.filter((s) => this.equals(s, search));
635
+ }
1535
636
  /**
1536
637
  * uses `get_list_cache` then the `equals` function to return matched result
1537
638
  * @param search
1538
639
  * @returns
1539
- */
1540
- )
1541
- }, {
1542
- key: "get_single_cache",
1543
- value: (function () {
1544
- var _get_single_cache = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee28(search) {
1545
- var _this4 = this;
1546
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1547
- while (1) switch (_context28.prev = _context28.next) {
1548
- case 0:
1549
- _context28.next = 2;
1550
- return this.get_list_cache();
1551
- case 2:
1552
- return _context28.abrupt("return", _context28.sent.find(function (s) {
1553
- return _this4.equals(s, search);
1554
- }));
1555
- case 3:
1556
- case "end":
1557
- return _context28.stop();
1558
- }
1559
- }, _callee28, this);
1560
- }));
1561
- function get_single_cache(_x12) {
1562
- return _get_single_cache.apply(this, arguments);
1563
- }
1564
- return get_single_cache;
1565
- }()
640
+ */
641
+ static async get_single_cache(search) {
642
+ return (await this.get_list_cache()).find((s) => this.equals(s, search));
643
+ }
1566
644
  /**
1567
645
  * Get a list of web objects and convert them to basic objects
1568
646
  * can be passed to client components
1569
647
  * default order of parameters : search,readonly,fetchID
1570
- */
1571
- )
1572
- }, {
1573
- key: "get_basicList",
1574
- value: (function () {
1575
- var _get_basicList = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
1576
- var itemlist,
1577
- _args30 = arguments;
1578
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
1579
- while (1) switch (_context30.prev = _context30.next) {
1580
- case 0:
1581
- _context30.next = 2;
1582
- return this.get_list.apply(this, _args30);
1583
- case 2:
1584
- itemlist = _context30.sent;
1585
- _context30.next = 5;
1586
- return Promise.all(itemlist.map(/*#__PURE__*/function () {
1587
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee29(r) {
1588
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1589
- while (1) switch (_context29.prev = _context29.next) {
1590
- case 0:
1591
- _context29.next = 2;
1592
- return r.get_basicObject();
1593
- case 2:
1594
- return _context29.abrupt("return", _context29.sent);
1595
- case 3:
1596
- case "end":
1597
- return _context29.stop();
1598
- }
1599
- }, _callee29);
1600
- }));
1601
- return function (_x13) {
1602
- return _ref3.apply(this, arguments);
1603
- };
1604
- }()));
1605
- case 5:
1606
- return _context30.abrupt("return", _context30.sent);
1607
- case 6:
1608
- case "end":
1609
- return _context30.stop();
1610
- }
1611
- }, _callee30, this);
1612
- }));
1613
- function get_basicList() {
1614
- return _get_basicList.apply(this, arguments);
1615
- }
1616
- return get_basicList;
1617
- }())
1618
- }]);
1619
- }(_index3.SimpleObject);
1620
- _defineProperty(WebObject, "__web_path", "");
1621
- _defineProperty(WebObject, "__protectedProperties", ["_users"]);
1622
- //you cant create a new weboject without these properties
1623
- _defineProperty(WebObject, "__requiredProperties", []);
1624
- var _default = exports["default"] = WebObject;
648
+ */
649
+ static async get_basicList(...p) {
650
+ const itemlist = await this.get_list(...p);
651
+ return await Promise.all(itemlist.map(async (r) => await r.get_basicObject()));
652
+ }
653
+ }
654
+ export default WebObject;