roboto-js 1.8.5 → 1.8.7
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.
- package/.last-build +1 -1
- package/BUILD_NOTES.md +40 -0
- package/babel.config.json +29 -0
- package/dist/cjs/cookie_storage_adaptor.cjs +38 -84
- package/dist/cjs/index.cjs +21 -14
- package/dist/cjs/rbt_api.cjs +28 -97
- package/dist/cjs/rbt_object.cjs +8 -15
- package/dist/cjs/rbt_user.cjs +1 -3
- package/dist/esm/cookie_storage_adaptor.js +349 -197
- package/dist/esm/index.js +565 -169
- package/dist/esm/rbt_api.js +1956 -1164
- package/dist/esm/rbt_file.js +213 -123
- package/dist/esm/rbt_metrics_api.js +158 -69
- package/dist/esm/rbt_object.js +1008 -706
- package/dist/esm/rbt_user.js +202 -137
- package/dist/index.js +31 -10
- package/dist/rbt_api.js +13 -0
- package/package.json +5 -4
- package/src/index.js +21 -11
- package/src/rbt_api.js +3 -0
- package/src/rbt_object.js +3 -1
package/dist/esm/rbt_object.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
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 new 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 new 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 new 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; }
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
+
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."); }
|
|
11
|
+
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); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
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; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
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); } }
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
23
|
+
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); }
|
|
1
24
|
import _ from 'lodash';
|
|
2
|
-
|
|
3
|
-
|
|
25
|
+
var RbtObject = /*#__PURE__*/function () {
|
|
26
|
+
function RbtObject(record, axiosInstance) {
|
|
27
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
28
|
+
_classCallCheck(this, RbtObject);
|
|
4
29
|
this._axios = axiosInstance;
|
|
5
30
|
this._internalData = record;
|
|
6
31
|
this.isRbtObject = true;
|
|
@@ -37,781 +62,1058 @@ export default class RbtObject {
|
|
|
37
62
|
this._broadcastDebounceTimer = null;
|
|
38
63
|
this._pendingBroadcasts = new Map(); // path -> value
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Return an object with only the specified keys
|
|
47
|
-
return keys.reduce((result, key) => {
|
|
48
|
-
// Use lodash.get to handle deep key paths
|
|
49
|
-
const value = _.get(this._data, key);
|
|
50
|
-
// If the value exists, add it to the result object using the key path as the property name
|
|
51
|
-
if (value !== undefined) {
|
|
52
|
-
// Create nested structure based on the key path
|
|
53
|
-
_.set(result, key, value);
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}, {});
|
|
57
|
-
} else {
|
|
58
|
-
// Return a shallow copy of the full data if no keys are provided
|
|
59
|
-
return {
|
|
60
|
-
...this._data
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
_addChange(path) {
|
|
65
|
-
// Ensure no duplicate paths
|
|
66
|
-
if (!this.rpcMeta.changes.includes(path)) {
|
|
67
|
-
this.rpcMeta.changes.push(path);
|
|
65
|
+
_createClass(RbtObject, [{
|
|
66
|
+
key: "get",
|
|
67
|
+
value: function get(path) {
|
|
68
|
+
var value = _.get(this._data, path);
|
|
69
|
+
// Return a deep clone to prevent reference issues when modifying returned objects
|
|
70
|
+
return _.cloneDeep(value);
|
|
68
71
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
if (!_.isEqual(currentValue, mergedValue)) {
|
|
93
|
-
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
94
|
-
this._addChange(path);
|
|
95
|
-
// Trigger local change events for any registered handlers
|
|
96
|
-
this._trigger('change', {
|
|
97
|
-
path,
|
|
98
|
-
value: mergedValue,
|
|
99
|
-
options
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
// If value is undefined and not merging, delete the key
|
|
104
|
-
if (value === undefined) {
|
|
105
|
-
_.unset(this._data, path);
|
|
106
|
-
this._addChange(path);
|
|
107
|
-
// Trigger local change events for any registered handlers
|
|
108
|
-
this._trigger('change', {
|
|
109
|
-
path,
|
|
110
|
-
value: undefined,
|
|
111
|
-
options
|
|
112
|
-
});
|
|
113
|
-
} else if (!_.isEqual(currentValue, value)) {
|
|
114
|
-
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
115
|
-
this._addChange(path);
|
|
116
|
-
this._broadcastChange(path, value);
|
|
117
|
-
// Trigger local change events for any registered handlers
|
|
118
|
-
this._trigger('change', {
|
|
119
|
-
path,
|
|
120
|
-
value,
|
|
121
|
-
options
|
|
122
|
-
});
|
|
72
|
+
}, {
|
|
73
|
+
key: "getData",
|
|
74
|
+
value: function getData() {
|
|
75
|
+
var _this = this;
|
|
76
|
+
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
77
|
+
// Check if keys are provided
|
|
78
|
+
if (keys && Array.isArray(keys)) {
|
|
79
|
+
// Return an object with only the specified keys
|
|
80
|
+
return keys.reduce(function (result, key) {
|
|
81
|
+
// Use lodash.get to handle deep key paths
|
|
82
|
+
var value = _.get(_this._data, key);
|
|
83
|
+
// If the value exists, add it to the result object using the key path as the property name
|
|
84
|
+
if (value !== undefined) {
|
|
85
|
+
// Create nested structure based on the key path
|
|
86
|
+
_.set(result, key, value);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}, {});
|
|
90
|
+
} else {
|
|
91
|
+
// Return a shallow copy of the full data if no keys are provided
|
|
92
|
+
return _objectSpread({}, this._data);
|
|
123
93
|
}
|
|
124
94
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
}, {
|
|
96
|
+
key: "_addChange",
|
|
97
|
+
value: function _addChange(path) {
|
|
98
|
+
// Ensure no duplicate paths
|
|
99
|
+
if (!this.rpcMeta.changes.includes(path)) {
|
|
100
|
+
this.rpcMeta.changes.push(path);
|
|
101
|
+
}
|
|
129
102
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (merge
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
return
|
|
103
|
+
}, {
|
|
104
|
+
key: "set",
|
|
105
|
+
value: function set(path, value) {
|
|
106
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
107
|
+
var currentValue = _.get(this._data, path); // Fetch current value at deep path
|
|
108
|
+
|
|
109
|
+
if (options.merge) {
|
|
110
|
+
var mergedValue = _.mergeWith({}, currentValue, value, function (objValue, srcValue) {
|
|
111
|
+
if (srcValue === undefined) {
|
|
112
|
+
return undefined; // Indicate to delete when merging
|
|
113
|
+
}
|
|
114
|
+
if (_.isArray(objValue)) {
|
|
115
|
+
return srcValue; // Customize merging behavior for arrays
|
|
140
116
|
}
|
|
141
117
|
// Handle null, 0, and "" explicitly
|
|
142
118
|
if (srcValue === null || srcValue === 0 || srcValue === "") {
|
|
143
119
|
return srcValue;
|
|
144
120
|
}
|
|
145
121
|
});
|
|
122
|
+
// Process merged object to remove any keys set explicitly to undefined
|
|
123
|
+
Object.keys(mergedValue).forEach(function (key) {
|
|
124
|
+
if (mergedValue[key] === undefined) {
|
|
125
|
+
_.unset(mergedValue, key);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
146
128
|
if (!_.isEqual(currentValue, mergedValue)) {
|
|
147
|
-
_.set(this._data, path, mergedValue);
|
|
129
|
+
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
148
130
|
this._addChange(path);
|
|
149
|
-
// Trigger change
|
|
131
|
+
// Trigger local change events for any registered handlers
|
|
150
132
|
this._trigger('change', {
|
|
151
|
-
path,
|
|
133
|
+
path: path,
|
|
152
134
|
value: mergedValue,
|
|
153
|
-
options
|
|
135
|
+
options: options
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
// If value is undefined and not merging, delete the key
|
|
140
|
+
if (value === undefined) {
|
|
141
|
+
_.unset(this._data, path);
|
|
142
|
+
this._addChange(path);
|
|
143
|
+
// Trigger local change events for any registered handlers
|
|
144
|
+
this._trigger('change', {
|
|
145
|
+
path: path,
|
|
146
|
+
value: undefined,
|
|
147
|
+
options: options
|
|
148
|
+
});
|
|
149
|
+
} else if (!_.isEqual(currentValue, value)) {
|
|
150
|
+
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
151
|
+
this._addChange(path);
|
|
152
|
+
this._broadcastChange(path, value);
|
|
153
|
+
// Trigger local change events for any registered handlers
|
|
154
|
+
this._trigger('change', {
|
|
155
|
+
path: path,
|
|
156
|
+
value: value,
|
|
157
|
+
options: options
|
|
154
158
|
});
|
|
155
159
|
}
|
|
156
|
-
} else if (!_.isEqual(currentValue, newValue)) {
|
|
157
|
-
_.setWith(this._data, path, newValue, (nsValue, key, nsObject, nsPath) => {
|
|
158
|
-
if (key === nsPath.split('.').pop() && !_.has(nsObject, key)) {
|
|
159
|
-
return nsObject[key] = {}; // Create any missing parts of the path as plain objects
|
|
160
|
-
}
|
|
161
|
-
return nsValue;
|
|
162
|
-
});
|
|
163
|
-
this._addChange(path);
|
|
164
|
-
// Trigger change event for this path
|
|
165
|
-
this._trigger('change', {
|
|
166
|
-
path,
|
|
167
|
-
value: newValue,
|
|
168
|
-
options
|
|
169
|
-
});
|
|
170
160
|
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
// For Arrays
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
async setAppend(key, value, options = {}) {
|
|
179
|
-
let existingValue = this.get(key) || []; // Get the existing value or default to an empty array
|
|
180
|
-
if (!Array.isArray(existingValue)) {
|
|
181
|
-
existingValue = []; // Ensure existingValue is an array if not already
|
|
182
161
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.rpcMeta.delta = true;
|
|
233
|
-
const clonedData = _.cloneDeep(this._internalData);
|
|
234
|
-
clonedData.data = deltaData;
|
|
235
|
-
return {
|
|
236
|
-
...clonedData,
|
|
237
|
-
dataJson: JSON.stringify(deltaData),
|
|
238
|
-
rpcMeta: this.rpcMeta
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
clone() {
|
|
242
|
-
// Create a deep copy of the current object's data
|
|
243
|
-
const clonedData = _.cloneDeep(this._internalData);
|
|
244
|
-
|
|
245
|
-
// Reset unique identifiers to ensure a new ID is generated upon saving
|
|
246
|
-
delete clonedData.id;
|
|
247
|
-
delete clonedData.id_revision;
|
|
248
|
-
delete clonedData.rpcMeta;
|
|
249
|
-
if (clonedData.data) {
|
|
250
|
-
delete clonedData.data.id;
|
|
251
|
-
delete clonedData.data.id_revision;
|
|
162
|
+
}, {
|
|
163
|
+
key: "setData",
|
|
164
|
+
value: function setData(newData) {
|
|
165
|
+
var _this2 = this;
|
|
166
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
167
|
+
if (_typeof(newData) !== 'object' || newData === null) {
|
|
168
|
+
throw new Error('setData expects an object');
|
|
169
|
+
}
|
|
170
|
+
var _options$merge = options.merge,
|
|
171
|
+
merge = _options$merge === void 0 ? false : _options$merge;
|
|
172
|
+
Object.keys(newData).forEach(function (path) {
|
|
173
|
+
var currentValue = _.get(_this2._data, path);
|
|
174
|
+
var newValue = newData[path];
|
|
175
|
+
if (merge && _.isObject(currentValue) && _.isObject(newValue)) {
|
|
176
|
+
var mergedValue = _.mergeWith({}, currentValue, newValue, function (objValue, srcValue) {
|
|
177
|
+
if (_.isArray(srcValue)) {
|
|
178
|
+
return _toConsumableArray(srcValue); // Customize merging behavior for arrays
|
|
179
|
+
}
|
|
180
|
+
// Handle null, 0, and "" explicitly
|
|
181
|
+
if (srcValue === null || srcValue === 0 || srcValue === "") {
|
|
182
|
+
return srcValue;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
if (!_.isEqual(currentValue, mergedValue)) {
|
|
186
|
+
_.set(_this2._data, path, mergedValue);
|
|
187
|
+
_this2._addChange(path);
|
|
188
|
+
// Trigger change event for this path
|
|
189
|
+
_this2._trigger('change', {
|
|
190
|
+
path: path,
|
|
191
|
+
value: mergedValue,
|
|
192
|
+
options: options
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
} else if (!_.isEqual(currentValue, newValue)) {
|
|
196
|
+
_.setWith(_this2._data, path, newValue, function (nsValue, key, nsObject, nsPath) {
|
|
197
|
+
if (key === nsPath.split('.').pop() && !_.has(nsObject, key)) {
|
|
198
|
+
return nsObject[key] = {}; // Create any missing parts of the path as plain objects
|
|
199
|
+
}
|
|
200
|
+
return nsValue;
|
|
201
|
+
});
|
|
202
|
+
_this2._addChange(path);
|
|
203
|
+
// Trigger change event for this path
|
|
204
|
+
_this2._trigger('change', {
|
|
205
|
+
path: path,
|
|
206
|
+
value: newValue,
|
|
207
|
+
options: options
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
252
211
|
}
|
|
253
212
|
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
213
|
+
//
|
|
214
|
+
// For Arrays
|
|
215
|
+
//
|
|
216
|
+
}, {
|
|
217
|
+
key: "setAppend",
|
|
218
|
+
value: function () {
|
|
219
|
+
var _setAppend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
|
|
220
|
+
var options,
|
|
221
|
+
existingValue,
|
|
222
|
+
valuesToAdd,
|
|
223
|
+
mergedValues,
|
|
224
|
+
_args = arguments;
|
|
225
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
226
|
+
while (1) switch (_context.prev = _context.next) {
|
|
227
|
+
case 0:
|
|
228
|
+
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
229
|
+
existingValue = this.get(key) || []; // Get the existing value or default to an empty array
|
|
230
|
+
if (!Array.isArray(existingValue)) {
|
|
231
|
+
existingValue = []; // Ensure existingValue is an array if not already
|
|
232
|
+
}
|
|
233
|
+
valuesToAdd = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
|
|
234
|
+
// Combine existingValue and valuesToAdd, filtering out duplicates
|
|
235
|
+
mergedValues = Array.from(new Set([].concat(_toConsumableArray(existingValue), _toConsumableArray(valuesToAdd))));
|
|
236
|
+
this.set(key, mergedValues, options); // Set the updated array back to the user data
|
|
237
|
+
case 6:
|
|
238
|
+
case "end":
|
|
239
|
+
return _context.stop();
|
|
240
|
+
}
|
|
241
|
+
}, _callee, this);
|
|
242
|
+
}));
|
|
243
|
+
function setAppend(_x, _x2) {
|
|
244
|
+
return _setAppend.apply(this, arguments);
|
|
278
245
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
246
|
+
return setAppend;
|
|
247
|
+
}()
|
|
248
|
+
}, {
|
|
249
|
+
key: "setRemove",
|
|
250
|
+
value: function () {
|
|
251
|
+
var _setRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
|
|
252
|
+
var options,
|
|
253
|
+
existingValue,
|
|
254
|
+
valuesToRemove,
|
|
255
|
+
filteredValues,
|
|
256
|
+
_args2 = arguments;
|
|
257
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
258
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
259
|
+
case 0:
|
|
260
|
+
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
261
|
+
existingValue = this.get(key) || []; // Get the existing value or default to an empty array
|
|
262
|
+
if (Array.isArray(existingValue)) {
|
|
263
|
+
_context2.next = 4;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
return _context2.abrupt("return");
|
|
267
|
+
case 4:
|
|
268
|
+
valuesToRemove = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
|
|
269
|
+
// Filter out the values to remove from the existing value array
|
|
270
|
+
filteredValues = existingValue.filter(function (item) {
|
|
271
|
+
return !valuesToRemove.includes(item);
|
|
272
|
+
});
|
|
273
|
+
this.set(key, filteredValues); // Set the updated array back to the user data
|
|
274
|
+
case 7:
|
|
275
|
+
case "end":
|
|
276
|
+
return _context2.stop();
|
|
277
|
+
}
|
|
278
|
+
}, _callee2, this);
|
|
279
|
+
}));
|
|
280
|
+
function setRemove(_x3, _x4) {
|
|
281
|
+
return _setRemove.apply(this, arguments);
|
|
282
282
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Grants access to this object for specific users and/or user groups.
|
|
298
|
-
* Updates the IAC (Identity and Access Control) permissions.
|
|
299
|
-
*
|
|
300
|
-
* @param {Object} options - Access grant options
|
|
301
|
-
* @param {string[]} [options.userIds=[]] - Array of user IDs to grant read access
|
|
302
|
-
* @param {string[]} [options.groupIds=[]] - Array of user group IDs to grant read access
|
|
303
|
-
* @param {boolean} [options.write=false] - If true, grants write access instead of read access
|
|
304
|
-
* @param {boolean} [options.replace=false] - If true, replaces existing grants; if false, merges with existing
|
|
305
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
306
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* // Grant read access to specific users
|
|
310
|
-
* await myObject.grantAccess({
|
|
311
|
-
* userIds: ['user123', 'user456']
|
|
312
|
-
* });
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* // Grant read access to user groups
|
|
316
|
-
* await myObject.grantAccess({
|
|
317
|
-
* groupIds: ['grpRngAccount', 'grpAdmins']
|
|
318
|
-
* });
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* // Grant write access to users and groups
|
|
322
|
-
* await myObject.grantAccess({
|
|
323
|
-
* userIds: ['user123'],
|
|
324
|
-
* groupIds: ['grpAdmins'],
|
|
325
|
-
* write: true
|
|
326
|
-
* });
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* // Replace existing permissions instead of merging
|
|
330
|
-
* await myObject.grantAccess({
|
|
331
|
-
* userIds: ['user123'],
|
|
332
|
-
* replace: true
|
|
333
|
-
* });
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* // Update permissions without auto-saving
|
|
337
|
-
* await myObject.grantAccess({
|
|
338
|
-
* userIds: ['user123'],
|
|
339
|
-
* save: false
|
|
340
|
-
* });
|
|
341
|
-
* // ... make other changes ...
|
|
342
|
-
* await myObject.save();
|
|
343
|
-
*/
|
|
344
|
-
async grantAccess(options = {}) {
|
|
345
|
-
const {
|
|
346
|
-
userIds = [],
|
|
347
|
-
groupIds = [],
|
|
348
|
-
write = false,
|
|
349
|
-
replace = false,
|
|
350
|
-
save = true
|
|
351
|
-
} = options;
|
|
352
|
-
|
|
353
|
-
// Validate inputs
|
|
354
|
-
if (!Array.isArray(userIds)) {
|
|
355
|
-
throw new Error('userIds must be an array');
|
|
283
|
+
return setRemove;
|
|
284
|
+
}()
|
|
285
|
+
}, {
|
|
286
|
+
key: "getMetaData",
|
|
287
|
+
value: function getMetaData() {
|
|
288
|
+
var meta = {
|
|
289
|
+
timeCreated: this._internalData.timeCreated,
|
|
290
|
+
timeModified: this._internalData.timeModified,
|
|
291
|
+
timeDeleted: this._internalData.timeDeleted,
|
|
292
|
+
revision: this._internalData.revision
|
|
293
|
+
};
|
|
294
|
+
return meta;
|
|
356
295
|
}
|
|
357
|
-
|
|
358
|
-
|
|
296
|
+
}, {
|
|
297
|
+
key: "toRecord",
|
|
298
|
+
value: function toRecord() {
|
|
299
|
+
return _objectSpread(_objectSpread({}, this._internalData), {}, {
|
|
300
|
+
dataJson: JSON.stringify(this._data),
|
|
301
|
+
rpcMeta: this.rpcMeta
|
|
302
|
+
});
|
|
359
303
|
}
|
|
304
|
+
}, {
|
|
305
|
+
key: "toDeltaRecord",
|
|
306
|
+
value: function toDeltaRecord() {
|
|
307
|
+
var changes = this.rpcMeta.changes;
|
|
360
308
|
|
|
361
|
-
|
|
362
|
-
|
|
309
|
+
// Initialize deltaData as an empty object
|
|
310
|
+
var sourceData = this._data;
|
|
311
|
+
var deltaData = {};
|
|
363
312
|
|
|
364
|
-
|
|
365
|
-
|
|
313
|
+
// Populate deltaData only with keys specified in changes
|
|
314
|
+
changes.forEach(function (path) {
|
|
315
|
+
// default value explicitly set to undefined
|
|
316
|
+
var value = _.get(sourceData, path, undefined);
|
|
317
|
+
// Use _.set to ensure nested keys are correctly assigned
|
|
318
|
+
_.set(deltaData, path, value);
|
|
319
|
+
});
|
|
366
320
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
321
|
+
// mark as delta
|
|
322
|
+
this.rpcMeta.delta = true;
|
|
323
|
+
var clonedData = _.cloneDeep(this._internalData);
|
|
324
|
+
clonedData.data = deltaData;
|
|
325
|
+
return _objectSpread(_objectSpread({}, clonedData), {}, {
|
|
326
|
+
dataJson: JSON.stringify(deltaData),
|
|
327
|
+
rpcMeta: this.rpcMeta
|
|
328
|
+
});
|
|
370
329
|
}
|
|
330
|
+
}, {
|
|
331
|
+
key: "clone",
|
|
332
|
+
value: function clone() {
|
|
333
|
+
// Create a deep copy of the current object's data
|
|
334
|
+
var clonedData = _.cloneDeep(this._internalData);
|
|
371
335
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const existingUsers = iac[grantType].users || [];
|
|
380
|
-
const mergedUsers = [...new Set([...existingUsers, ...userIds])];
|
|
381
|
-
iac[grantType].users = mergedUsers;
|
|
336
|
+
// Reset unique identifiers to ensure a new ID is generated upon saving
|
|
337
|
+
delete clonedData.id;
|
|
338
|
+
delete clonedData.id_revision;
|
|
339
|
+
delete clonedData.rpcMeta;
|
|
340
|
+
if (clonedData.data) {
|
|
341
|
+
delete clonedData.data.id;
|
|
342
|
+
delete clonedData.data.id_revision;
|
|
382
343
|
}
|
|
383
|
-
}
|
|
384
344
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
} else {
|
|
391
|
-
// Merge with existing groups (avoiding duplicates)
|
|
392
|
-
const existingGroups = iac[grantType].userGroups || [];
|
|
393
|
-
const mergedGroups = [...new Set([...existingGroups, ...groupIds])];
|
|
394
|
-
iac[grantType].userGroups = mergedGroups;
|
|
395
|
-
}
|
|
345
|
+
// Create a new instance of RbtObject with the cloned data
|
|
346
|
+
var clonedObject = new RbtObject(clonedData, this._axios, {
|
|
347
|
+
isNew: true
|
|
348
|
+
});
|
|
349
|
+
return clonedObject;
|
|
396
350
|
}
|
|
351
|
+
}, {
|
|
352
|
+
key: "save",
|
|
353
|
+
value: function () {
|
|
354
|
+
var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
355
|
+
var _response$data, _response$data2, record, response;
|
|
356
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
357
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
358
|
+
case 0:
|
|
359
|
+
if (this._internalData.type) {
|
|
360
|
+
_context3.next = 2;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
throw new Error('Cannot save object without type');
|
|
364
|
+
case 2:
|
|
365
|
+
_context3.prev = 2;
|
|
366
|
+
if (this.rpcMeta.isNew) {
|
|
367
|
+
record = this.toRecord();
|
|
368
|
+
} else {
|
|
369
|
+
record = this.toDeltaRecord();
|
|
370
|
+
}
|
|
371
|
+
_context3.next = 6;
|
|
372
|
+
return this._axios.post('/object_service/saveObject', [record]);
|
|
373
|
+
case 6:
|
|
374
|
+
response = _context3.sent;
|
|
375
|
+
if (!(response.data.ok === false)) {
|
|
376
|
+
_context3.next = 9;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
throw new Error(response.data.message);
|
|
380
|
+
case 9:
|
|
381
|
+
if (!(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.result) == 'NO_CHANGES')) {
|
|
382
|
+
_context3.next = 12;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
this.rpcMeta.isNew = false;
|
|
386
|
+
return _context3.abrupt("return", this);
|
|
387
|
+
case 12:
|
|
388
|
+
if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
|
|
389
|
+
// apply new incoming data
|
|
390
|
+
this.setData(response.newData);
|
|
391
|
+
}
|
|
392
|
+
this.id = response.data.id;
|
|
393
|
+
this.id_revision = response.data.id_revision;
|
|
394
|
+
this.type = response.data.type;
|
|
395
|
+
this.rpcMeta.isNew = false;
|
|
396
|
+
return _context3.abrupt("return", this);
|
|
397
|
+
case 20:
|
|
398
|
+
_context3.prev = 20;
|
|
399
|
+
_context3.t0 = _context3["catch"](2);
|
|
400
|
+
this._error = _context3.t0;
|
|
401
|
+
//console.log(e.response.data);
|
|
402
|
+
throw _context3.t0;
|
|
403
|
+
case 24:
|
|
404
|
+
case "end":
|
|
405
|
+
return _context3.stop();
|
|
406
|
+
}
|
|
407
|
+
}, _callee3, this, [[2, 20]]);
|
|
408
|
+
}));
|
|
409
|
+
function save() {
|
|
410
|
+
return _save.apply(this, arguments);
|
|
411
|
+
}
|
|
412
|
+
return save;
|
|
413
|
+
}()
|
|
414
|
+
/**
|
|
415
|
+
* Grants access to this object for specific users and/or user groups.
|
|
416
|
+
* Updates the IAC (Identity and Access Control) permissions.
|
|
417
|
+
*
|
|
418
|
+
* @param {Object} options - Access grant options
|
|
419
|
+
* @param {string[]} [options.userIds=[]] - Array of user IDs to grant read access
|
|
420
|
+
* @param {string[]} [options.groupIds=[]] - Array of user group IDs to grant read access
|
|
421
|
+
* @param {boolean} [options.write=false] - If true, grants write access instead of read access
|
|
422
|
+
* @param {boolean} [options.replace=false] - If true, replaces existing grants; if false, merges with existing
|
|
423
|
+
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
424
|
+
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* // Grant read access to specific users
|
|
428
|
+
* await myObject.grantAccess({
|
|
429
|
+
* userIds: ['user123', 'user456']
|
|
430
|
+
* });
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* // Grant read access to user groups
|
|
434
|
+
* await myObject.grantAccess({
|
|
435
|
+
* groupIds: ['grpRngAccount', 'grpAdmins']
|
|
436
|
+
* });
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* // Grant write access to users and groups
|
|
440
|
+
* await myObject.grantAccess({
|
|
441
|
+
* userIds: ['user123'],
|
|
442
|
+
* groupIds: ['grpAdmins'],
|
|
443
|
+
* write: true
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* // Replace existing permissions instead of merging
|
|
448
|
+
* await myObject.grantAccess({
|
|
449
|
+
* userIds: ['user123'],
|
|
450
|
+
* replace: true
|
|
451
|
+
* });
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* // Update permissions without auto-saving
|
|
455
|
+
* await myObject.grantAccess({
|
|
456
|
+
* userIds: ['user123'],
|
|
457
|
+
* save: false
|
|
458
|
+
* });
|
|
459
|
+
* // ... make other changes ...
|
|
460
|
+
* await myObject.save();
|
|
461
|
+
*/
|
|
462
|
+
}, {
|
|
463
|
+
key: "grantAccess",
|
|
464
|
+
value: (function () {
|
|
465
|
+
var _grantAccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
466
|
+
var options,
|
|
467
|
+
_options$userIds,
|
|
468
|
+
userIds,
|
|
469
|
+
_options$groupIds,
|
|
470
|
+
groupIds,
|
|
471
|
+
_options$write,
|
|
472
|
+
write,
|
|
473
|
+
_options$replace,
|
|
474
|
+
replace,
|
|
475
|
+
_options$save,
|
|
476
|
+
save,
|
|
477
|
+
iac,
|
|
478
|
+
grantType,
|
|
479
|
+
existingUsers,
|
|
480
|
+
mergedUsers,
|
|
481
|
+
existingGroups,
|
|
482
|
+
mergedGroups,
|
|
483
|
+
_args4 = arguments;
|
|
484
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
485
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
486
|
+
case 0:
|
|
487
|
+
options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
|
|
488
|
+
_options$userIds = options.userIds, userIds = _options$userIds === void 0 ? [] : _options$userIds, _options$groupIds = options.groupIds, groupIds = _options$groupIds === void 0 ? [] : _options$groupIds, _options$write = options.write, write = _options$write === void 0 ? false : _options$write, _options$replace = options.replace, replace = _options$replace === void 0 ? false : _options$replace, _options$save = options.save, save = _options$save === void 0 ? true : _options$save; // Validate inputs
|
|
489
|
+
if (Array.isArray(userIds)) {
|
|
490
|
+
_context4.next = 4;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
throw new Error('userIds must be an array');
|
|
494
|
+
case 4:
|
|
495
|
+
if (Array.isArray(groupIds)) {
|
|
496
|
+
_context4.next = 6;
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
throw new Error('groupIds must be an array');
|
|
500
|
+
case 6:
|
|
501
|
+
// Get current IAC settings
|
|
502
|
+
iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
|
|
503
|
+
grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
|
|
504
|
+
if (!iac[grantType]) {
|
|
505
|
+
iac[grantType] = {};
|
|
506
|
+
}
|
|
397
507
|
|
|
398
|
-
|
|
399
|
-
|
|
508
|
+
// Handle users
|
|
509
|
+
if (userIds.length > 0) {
|
|
510
|
+
if (replace) {
|
|
511
|
+
// Replace existing users
|
|
512
|
+
iac[grantType].users = _toConsumableArray(userIds);
|
|
513
|
+
} else {
|
|
514
|
+
// Merge with existing users (avoiding duplicates)
|
|
515
|
+
existingUsers = iac[grantType].users || [];
|
|
516
|
+
mergedUsers = _toConsumableArray(new Set([].concat(_toConsumableArray(existingUsers), _toConsumableArray(userIds))));
|
|
517
|
+
iac[grantType].users = mergedUsers;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
400
520
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
521
|
+
// Handle user groups
|
|
522
|
+
if (groupIds.length > 0) {
|
|
523
|
+
if (replace) {
|
|
524
|
+
// Replace existing groups
|
|
525
|
+
iac[grantType].userGroups = _toConsumableArray(groupIds);
|
|
526
|
+
} else {
|
|
527
|
+
// Merge with existing groups (avoiding duplicates)
|
|
528
|
+
existingGroups = iac[grantType].userGroups || [];
|
|
529
|
+
mergedGroups = _toConsumableArray(new Set([].concat(_toConsumableArray(existingGroups), _toConsumableArray(groupIds))));
|
|
530
|
+
iac[grantType].userGroups = mergedGroups;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
407
533
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
* Adds or removes 'public_user' from the IAC read permissions.
|
|
411
|
-
*
|
|
412
|
-
* @param {Object} options - Publishing options
|
|
413
|
-
* @param {boolean} [options.publish=true] - If true, publishes the object; if false, unpublishes it
|
|
414
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
415
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
416
|
-
*
|
|
417
|
-
* @example
|
|
418
|
-
* // Publish an object (make it public)
|
|
419
|
-
* await myObject.publishObject();
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* // Unpublish an object (make it private)
|
|
423
|
-
* await myObject.publishObject({ publish: false });
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* // Publish without auto-saving
|
|
427
|
-
* await myObject.publishObject({ save: false });
|
|
428
|
-
* // ... make other changes ...
|
|
429
|
-
* await myObject.save();
|
|
430
|
-
*/
|
|
431
|
-
async publishObject(options = {}) {
|
|
432
|
-
const {
|
|
433
|
-
publish = true,
|
|
434
|
-
save = true
|
|
435
|
-
} = options;
|
|
436
|
-
|
|
437
|
-
// Get current IAC settings and create a deep clone to ensure change detection
|
|
438
|
-
const currentIac = this.get('iac') || {};
|
|
439
|
-
const iac = _.cloneDeep(currentIac);
|
|
440
|
-
|
|
441
|
-
// Initialize readGrants if it doesn't exist
|
|
442
|
-
if (!iac.readGrants) {
|
|
443
|
-
iac.readGrants = {};
|
|
444
|
-
}
|
|
534
|
+
// Update the object
|
|
535
|
+
this.set('iac', iac);
|
|
445
536
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
537
|
+
// Save if requested
|
|
538
|
+
if (!save) {
|
|
539
|
+
_context4.next = 16;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
_context4.next = 15;
|
|
543
|
+
return this.save();
|
|
544
|
+
case 15:
|
|
545
|
+
return _context4.abrupt("return", _context4.sent);
|
|
546
|
+
case 16:
|
|
547
|
+
return _context4.abrupt("return", this);
|
|
548
|
+
case 17:
|
|
549
|
+
case "end":
|
|
550
|
+
return _context4.stop();
|
|
551
|
+
}
|
|
552
|
+
}, _callee4, this);
|
|
553
|
+
}));
|
|
554
|
+
function grantAccess() {
|
|
555
|
+
return _grantAccess.apply(this, arguments);
|
|
454
556
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
557
|
+
return grantAccess;
|
|
558
|
+
}()
|
|
559
|
+
/**
|
|
560
|
+
* Publishes this object to make it publicly accessible (or unpublishes it).
|
|
561
|
+
* Adds or removes 'public_user' from the IAC read permissions.
|
|
562
|
+
*
|
|
563
|
+
* @param {Object} options - Publishing options
|
|
564
|
+
* @param {boolean} [options.publish=true] - If true, publishes the object; if false, unpublishes it
|
|
565
|
+
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
566
|
+
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* // Publish an object (make it public)
|
|
570
|
+
* await myObject.publishObject();
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* // Unpublish an object (make it private)
|
|
574
|
+
* await myObject.publishObject({ publish: false });
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* // Publish without auto-saving
|
|
578
|
+
* await myObject.publishObject({ save: false });
|
|
579
|
+
* // ... make other changes ...
|
|
580
|
+
* await myObject.save();
|
|
581
|
+
*/
|
|
582
|
+
)
|
|
583
|
+
}, {
|
|
584
|
+
key: "publishObject",
|
|
585
|
+
value: (function () {
|
|
586
|
+
var _publishObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
587
|
+
var options,
|
|
588
|
+
_options$publish,
|
|
589
|
+
publish,
|
|
590
|
+
_options$save2,
|
|
591
|
+
save,
|
|
592
|
+
currentIac,
|
|
593
|
+
iac,
|
|
594
|
+
_args5 = arguments;
|
|
595
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
596
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
597
|
+
case 0:
|
|
598
|
+
options = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
|
|
599
|
+
_options$publish = options.publish, publish = _options$publish === void 0 ? true : _options$publish, _options$save2 = options.save, save = _options$save2 === void 0 ? true : _options$save2; // Get current IAC settings and create a deep clone to ensure change detection
|
|
600
|
+
currentIac = this.get('iac') || {};
|
|
601
|
+
iac = _.cloneDeep(currentIac); // Initialize readGrants if it doesn't exist
|
|
602
|
+
if (!iac.readGrants) {
|
|
603
|
+
iac.readGrants = {};
|
|
604
|
+
}
|
|
459
605
|
|
|
460
|
-
|
|
461
|
-
|
|
606
|
+
// Initialize users array if it doesn't exist
|
|
607
|
+
if (!Array.isArray(iac.readGrants.users)) {
|
|
608
|
+
iac.readGrants.users = [];
|
|
609
|
+
}
|
|
610
|
+
if (publish) {
|
|
611
|
+
// Add public_user if not already present
|
|
612
|
+
if (!iac.readGrants.users.includes('public_user')) {
|
|
613
|
+
iac.readGrants.users.push('public_user');
|
|
614
|
+
}
|
|
615
|
+
} else {
|
|
616
|
+
// Remove public_user
|
|
617
|
+
iac.readGrants.users = iac.readGrants.users.filter(function (userId) {
|
|
618
|
+
return userId !== 'public_user';
|
|
619
|
+
});
|
|
620
|
+
}
|
|
462
621
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return await this.save();
|
|
466
|
-
}
|
|
467
|
-
return this;
|
|
468
|
-
}
|
|
622
|
+
// Update the object with the cloned and modified IAC
|
|
623
|
+
this.set('iac', iac);
|
|
469
624
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
625
|
+
// Save if requested
|
|
626
|
+
if (!save) {
|
|
627
|
+
_context5.next = 12;
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
_context5.next = 11;
|
|
631
|
+
return this.save();
|
|
632
|
+
case 11:
|
|
633
|
+
return _context5.abrupt("return", _context5.sent);
|
|
634
|
+
case 12:
|
|
635
|
+
return _context5.abrupt("return", this);
|
|
636
|
+
case 13:
|
|
637
|
+
case "end":
|
|
638
|
+
return _context5.stop();
|
|
639
|
+
}
|
|
640
|
+
}, _callee5, this);
|
|
641
|
+
}));
|
|
642
|
+
function publishObject() {
|
|
643
|
+
return _publishObject.apply(this, arguments);
|
|
644
|
+
}
|
|
645
|
+
return publishObject;
|
|
646
|
+
}()
|
|
647
|
+
/**
|
|
648
|
+
* Unpublishes this object to remove public access.
|
|
649
|
+
* Removes 'public_user' from the IAC read permissions.
|
|
650
|
+
* This is an alias for publishObject({ publish: false }) for better code clarity.
|
|
651
|
+
*
|
|
652
|
+
* @param {Object} options - Unpublishing options
|
|
653
|
+
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
654
|
+
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* // Unpublish an object (remove public access)
|
|
658
|
+
* await myObject.unpublishObject();
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* // Unpublish without auto-saving
|
|
662
|
+
* await myObject.unpublishObject({ save: false });
|
|
663
|
+
* // ... make other changes ...
|
|
664
|
+
* await myObject.save();
|
|
665
|
+
*/
|
|
666
|
+
)
|
|
667
|
+
}, {
|
|
668
|
+
key: "unpublishObject",
|
|
669
|
+
value: (function () {
|
|
670
|
+
var _unpublishObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
671
|
+
var options,
|
|
672
|
+
_args6 = arguments;
|
|
673
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
674
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
675
|
+
case 0:
|
|
676
|
+
options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
|
|
677
|
+
_context6.next = 3;
|
|
678
|
+
return this.publishObject({
|
|
679
|
+
publish: false,
|
|
680
|
+
save: options.save !== undefined ? options.save : true
|
|
681
|
+
});
|
|
682
|
+
case 3:
|
|
683
|
+
return _context6.abrupt("return", _context6.sent);
|
|
684
|
+
case 4:
|
|
685
|
+
case "end":
|
|
686
|
+
return _context6.stop();
|
|
687
|
+
}
|
|
688
|
+
}, _callee6, this);
|
|
689
|
+
}));
|
|
690
|
+
function unpublishObject() {
|
|
691
|
+
return _unpublishObject.apply(this, arguments);
|
|
692
|
+
}
|
|
693
|
+
return unpublishObject;
|
|
694
|
+
}()
|
|
695
|
+
/**
|
|
696
|
+
* Revokes access from specific users and/or user groups.
|
|
697
|
+
*
|
|
698
|
+
* @param {Object} options - Access revocation options
|
|
699
|
+
* @param {string[]} [options.userIds=[]] - Array of user IDs to remove from read or write access
|
|
700
|
+
* @param {string[]} [options.groupIds=[]] - Array of group IDs to remove from read or write access
|
|
701
|
+
* @param {boolean} [options.write=false] - If true, removes write access; if false, removes read access
|
|
702
|
+
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
703
|
+
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* // Revoke read access from specific users
|
|
707
|
+
* await myObject.revokeAccess({
|
|
708
|
+
* userIds: ['user_123', 'user_456']
|
|
709
|
+
* });
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* // Revoke write access from specific groups
|
|
713
|
+
* await myObject.revokeAccess({
|
|
714
|
+
* groupIds: ['grpEditors'],
|
|
715
|
+
* write: true
|
|
716
|
+
* });
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* // Revoke access from users and groups
|
|
720
|
+
* await myObject.revokeAccess({
|
|
721
|
+
* userIds: ['user_123'],
|
|
722
|
+
* groupIds: ['grpViewers']
|
|
723
|
+
* });
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* // Revoke without auto-saving
|
|
727
|
+
* await myObject.revokeAccess({
|
|
728
|
+
* userIds: ['user_123'],
|
|
729
|
+
* save: false
|
|
730
|
+
* });
|
|
731
|
+
*/
|
|
732
|
+
)
|
|
733
|
+
}, {
|
|
734
|
+
key: "revokeAccess",
|
|
735
|
+
value: (function () {
|
|
736
|
+
var _revokeAccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
737
|
+
var options,
|
|
738
|
+
_options$userIds2,
|
|
739
|
+
userIds,
|
|
740
|
+
_options$groupIds2,
|
|
741
|
+
groupIds,
|
|
742
|
+
_options$write2,
|
|
743
|
+
write,
|
|
744
|
+
_options$save3,
|
|
745
|
+
save,
|
|
746
|
+
iac,
|
|
747
|
+
grantType,
|
|
748
|
+
_args7 = arguments;
|
|
749
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
750
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
751
|
+
case 0:
|
|
752
|
+
options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
|
753
|
+
_options$userIds2 = options.userIds, userIds = _options$userIds2 === void 0 ? [] : _options$userIds2, _options$groupIds2 = options.groupIds, groupIds = _options$groupIds2 === void 0 ? [] : _options$groupIds2, _options$write2 = options.write, write = _options$write2 === void 0 ? false : _options$write2, _options$save3 = options.save, save = _options$save3 === void 0 ? true : _options$save3; // Validate inputs
|
|
754
|
+
if (Array.isArray(userIds)) {
|
|
755
|
+
_context7.next = 4;
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
throw new Error('userIds must be an array');
|
|
759
|
+
case 4:
|
|
760
|
+
if (Array.isArray(groupIds)) {
|
|
761
|
+
_context7.next = 6;
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
throw new Error('groupIds must be an array');
|
|
765
|
+
case 6:
|
|
766
|
+
// Get current IAC settings
|
|
767
|
+
iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
|
|
768
|
+
grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
|
|
769
|
+
if (!iac[grantType]) {
|
|
770
|
+
iac[grantType] = {};
|
|
771
|
+
}
|
|
495
772
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
* @param {boolean} [options.write=false] - If true, removes write access; if false, removes read access
|
|
503
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
504
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
505
|
-
*
|
|
506
|
-
* @example
|
|
507
|
-
* // Revoke read access from specific users
|
|
508
|
-
* await myObject.revokeAccess({
|
|
509
|
-
* userIds: ['user_123', 'user_456']
|
|
510
|
-
* });
|
|
511
|
-
*
|
|
512
|
-
* @example
|
|
513
|
-
* // Revoke write access from specific groups
|
|
514
|
-
* await myObject.revokeAccess({
|
|
515
|
-
* groupIds: ['grpEditors'],
|
|
516
|
-
* write: true
|
|
517
|
-
* });
|
|
518
|
-
*
|
|
519
|
-
* @example
|
|
520
|
-
* // Revoke access from users and groups
|
|
521
|
-
* await myObject.revokeAccess({
|
|
522
|
-
* userIds: ['user_123'],
|
|
523
|
-
* groupIds: ['grpViewers']
|
|
524
|
-
* });
|
|
525
|
-
*
|
|
526
|
-
* @example
|
|
527
|
-
* // Revoke without auto-saving
|
|
528
|
-
* await myObject.revokeAccess({
|
|
529
|
-
* userIds: ['user_123'],
|
|
530
|
-
* save: false
|
|
531
|
-
* });
|
|
532
|
-
*/
|
|
533
|
-
async revokeAccess(options = {}) {
|
|
534
|
-
const {
|
|
535
|
-
userIds = [],
|
|
536
|
-
groupIds = [],
|
|
537
|
-
write = false,
|
|
538
|
-
save = true
|
|
539
|
-
} = options;
|
|
540
|
-
|
|
541
|
-
// Validate inputs
|
|
542
|
-
if (!Array.isArray(userIds)) {
|
|
543
|
-
throw new Error('userIds must be an array');
|
|
544
|
-
}
|
|
545
|
-
if (!Array.isArray(groupIds)) {
|
|
546
|
-
throw new Error('groupIds must be an array');
|
|
547
|
-
}
|
|
773
|
+
// Remove specified users
|
|
774
|
+
if (userIds.length > 0 && Array.isArray(iac[grantType].users)) {
|
|
775
|
+
iac[grantType].users = iac[grantType].users.filter(function (userId) {
|
|
776
|
+
return !userIds.includes(userId);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
548
779
|
|
|
549
|
-
|
|
550
|
-
|
|
780
|
+
// Remove specified groups
|
|
781
|
+
if (groupIds.length > 0 && Array.isArray(iac[grantType].userGroups)) {
|
|
782
|
+
iac[grantType].userGroups = iac[grantType].userGroups.filter(function (groupId) {
|
|
783
|
+
return !groupIds.includes(groupId);
|
|
784
|
+
});
|
|
785
|
+
}
|
|
551
786
|
|
|
552
|
-
|
|
553
|
-
|
|
787
|
+
// Update the object
|
|
788
|
+
this.set('iac', iac);
|
|
554
789
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
790
|
+
// Save if requested
|
|
791
|
+
if (!save) {
|
|
792
|
+
_context7.next = 16;
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
_context7.next = 15;
|
|
796
|
+
return this.save();
|
|
797
|
+
case 15:
|
|
798
|
+
return _context7.abrupt("return", _context7.sent);
|
|
799
|
+
case 16:
|
|
800
|
+
return _context7.abrupt("return", this);
|
|
801
|
+
case 17:
|
|
802
|
+
case "end":
|
|
803
|
+
return _context7.stop();
|
|
804
|
+
}
|
|
805
|
+
}, _callee7, this);
|
|
806
|
+
}));
|
|
807
|
+
function revokeAccess() {
|
|
808
|
+
return _revokeAccess.apply(this, arguments);
|
|
809
|
+
}
|
|
810
|
+
return revokeAccess;
|
|
811
|
+
}()
|
|
812
|
+
/**
|
|
813
|
+
* Checks if this object is currently published (publicly accessible).
|
|
814
|
+
*
|
|
815
|
+
* @returns {boolean} - True if 'public_user' is in the read grants, false otherwise
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* if (myObject.isPublished()) {
|
|
819
|
+
* console.log('Object is public');
|
|
820
|
+
* }
|
|
821
|
+
*/
|
|
822
|
+
)
|
|
823
|
+
}, {
|
|
824
|
+
key: "isPublished",
|
|
825
|
+
value: function isPublished() {
|
|
826
|
+
var iac = this.get('iac');
|
|
827
|
+
if (!iac || !iac.readGrants || !Array.isArray(iac.readGrants.users)) {
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
return iac.readGrants.users.includes('public_user');
|
|
558
831
|
}
|
|
559
832
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
833
|
+
/**
|
|
834
|
+
* Gets the current sharing permissions for this object.
|
|
835
|
+
*
|
|
836
|
+
* @returns {Object} - Object containing read and write grants
|
|
837
|
+
* @returns {Object} returns.readGrants - Read access grants
|
|
838
|
+
* @returns {string[]} returns.readGrants.users - Array of user IDs with read access
|
|
839
|
+
* @returns {string[]} returns.readGrants.userGroups - Array of group IDs with read access
|
|
840
|
+
* @returns {string[]} returns.readGrants.organizations - Array of organization IDs with read access
|
|
841
|
+
* @returns {Object} returns.writeGrants - Write access grants
|
|
842
|
+
* @returns {string[]} returns.writeGrants.users - Array of user IDs with write access
|
|
843
|
+
* @returns {string[]} returns.writeGrants.userGroups - Array of group IDs with write access
|
|
844
|
+
* @returns {string[]} returns.writeGrants.organizations - Array of organization IDs with write access
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* const permissions = myObject.getSharing();
|
|
848
|
+
* console.log('Read users:', permissions.readGrants.users);
|
|
849
|
+
* console.log('Read groups:', permissions.readGrants.userGroups);
|
|
850
|
+
*/
|
|
851
|
+
}, {
|
|
852
|
+
key: "getSharing",
|
|
853
|
+
value: function getSharing() {
|
|
854
|
+
var _iac$readGrants, _iac$readGrants2, _iac$readGrants3, _iac$readGrants4, _iac$writeGrants, _iac$writeGrants2, _iac$writeGrants3, _iac$writeGrants4;
|
|
855
|
+
var iac = this.get('iac') || {};
|
|
856
|
+
return {
|
|
857
|
+
readGrants: {
|
|
858
|
+
users: ((_iac$readGrants = iac.readGrants) === null || _iac$readGrants === void 0 ? void 0 : _iac$readGrants.users) || [],
|
|
859
|
+
userGroups: ((_iac$readGrants2 = iac.readGrants) === null || _iac$readGrants2 === void 0 ? void 0 : _iac$readGrants2.userGroups) || [],
|
|
860
|
+
organizations: ((_iac$readGrants3 = iac.readGrants) === null || _iac$readGrants3 === void 0 ? void 0 : _iac$readGrants3.organizations) || [],
|
|
861
|
+
userSegments: ((_iac$readGrants4 = iac.readGrants) === null || _iac$readGrants4 === void 0 ? void 0 : _iac$readGrants4.userSegments) || []
|
|
862
|
+
},
|
|
863
|
+
writeGrants: {
|
|
864
|
+
users: ((_iac$writeGrants = iac.writeGrants) === null || _iac$writeGrants === void 0 ? void 0 : _iac$writeGrants.users) || [],
|
|
865
|
+
userGroups: ((_iac$writeGrants2 = iac.writeGrants) === null || _iac$writeGrants2 === void 0 ? void 0 : _iac$writeGrants2.userGroups) || [],
|
|
866
|
+
organizations: ((_iac$writeGrants3 = iac.writeGrants) === null || _iac$writeGrants3 === void 0 ? void 0 : _iac$writeGrants3.organizations) || [],
|
|
867
|
+
userSegments: ((_iac$writeGrants4 = iac.writeGrants) === null || _iac$writeGrants4 === void 0 ? void 0 : _iac$writeGrants4.userSegments) || []
|
|
868
|
+
}
|
|
869
|
+
};
|
|
563
870
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
871
|
+
}, {
|
|
872
|
+
key: "delete",
|
|
873
|
+
value: function () {
|
|
874
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
875
|
+
var record, response;
|
|
876
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
877
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
878
|
+
case 0:
|
|
879
|
+
if (this._internalData.type) {
|
|
880
|
+
_context8.next = 2;
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
throw new Error('Cannot delete object without type');
|
|
884
|
+
case 2:
|
|
885
|
+
_context8.prev = 2;
|
|
886
|
+
record = this.toRecord();
|
|
887
|
+
_context8.next = 6;
|
|
888
|
+
return this._axios.post('/object_service/deleteObject', {
|
|
889
|
+
id: record.id,
|
|
890
|
+
type: record.type
|
|
891
|
+
});
|
|
892
|
+
case 6:
|
|
893
|
+
response = _context8.sent;
|
|
894
|
+
if (!(response.data.ok === false)) {
|
|
895
|
+
_context8.next = 9;
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
throw new Error(response.data.message);
|
|
899
|
+
case 9:
|
|
900
|
+
this._internalData = response.data;
|
|
901
|
+
return _context8.abrupt("return", this);
|
|
902
|
+
case 13:
|
|
903
|
+
_context8.prev = 13;
|
|
904
|
+
_context8.t0 = _context8["catch"](2);
|
|
905
|
+
throw _context8.t0;
|
|
906
|
+
case 16:
|
|
907
|
+
case "end":
|
|
908
|
+
return _context8.stop();
|
|
909
|
+
}
|
|
910
|
+
}, _callee8, this, [[2, 13]]);
|
|
911
|
+
}));
|
|
912
|
+
function _delete() {
|
|
913
|
+
return _delete2.apply(this, arguments);
|
|
914
|
+
}
|
|
915
|
+
return _delete;
|
|
916
|
+
}()
|
|
917
|
+
}, {
|
|
918
|
+
key: "_deepUnpackJson",
|
|
919
|
+
value: function _deepUnpackJson(value) {
|
|
920
|
+
if (typeof value === 'string') {
|
|
921
|
+
try {
|
|
922
|
+
// Only parse as JSON if it's not a large number
|
|
923
|
+
// https://chatgpt.com/c/6745902c-edf4-800c-ab52-31bf27dde2bd
|
|
924
|
+
//
|
|
925
|
+
if (!/^\d{16,}$/.test(value)) {
|
|
926
|
+
var parsed = JSON.parse(value);
|
|
927
|
+
// Recursively parse if the result is a string, object, or array
|
|
928
|
+
return this._deepUnpackJson(parsed);
|
|
929
|
+
}
|
|
930
|
+
} catch (e) {
|
|
931
|
+
return value; // Return the original string if parsing fails
|
|
932
|
+
}
|
|
933
|
+
} else if (value !== null && _typeof(value) === 'object') {
|
|
934
|
+
// If it's an object (including arrays), recursively parse each value
|
|
935
|
+
for (var key in value) {
|
|
936
|
+
value[key] = this._deepUnpackJson(value[key]);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return value;
|
|
568
940
|
}
|
|
569
941
|
|
|
570
|
-
//
|
|
571
|
-
|
|
942
|
+
//
|
|
943
|
+
// Realtime WebSocket
|
|
944
|
+
//
|
|
945
|
+
//
|
|
946
|
+
}, {
|
|
947
|
+
key: "_initRealtime",
|
|
948
|
+
value: function _initRealtime() {
|
|
949
|
+
if (this._realtime || !this._axios) return;
|
|
572
950
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return await this.save();
|
|
576
|
-
}
|
|
577
|
-
return this;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Checks if this object is currently published (publicly accessible).
|
|
582
|
-
*
|
|
583
|
-
* @returns {boolean} - True if 'public_user' is in the read grants, false otherwise
|
|
584
|
-
*
|
|
585
|
-
* @example
|
|
586
|
-
* if (myObject.isPublished()) {
|
|
587
|
-
* console.log('Object is public');
|
|
588
|
-
* }
|
|
589
|
-
*/
|
|
590
|
-
isPublished() {
|
|
591
|
-
const iac = this.get('iac');
|
|
592
|
-
if (!iac || !iac.readGrants || !Array.isArray(iac.readGrants.users)) {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
return iac.readGrants.users.includes('public_user');
|
|
596
|
-
}
|
|
951
|
+
// Use stored websocket client if available
|
|
952
|
+
var ws = this._ws;
|
|
597
953
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
* @returns {string[]} returns.readGrants.userGroups - Array of group IDs with read access
|
|
605
|
-
* @returns {string[]} returns.readGrants.organizations - Array of organization IDs with read access
|
|
606
|
-
* @returns {Object} returns.writeGrants - Write access grants
|
|
607
|
-
* @returns {string[]} returns.writeGrants.users - Array of user IDs with write access
|
|
608
|
-
* @returns {string[]} returns.writeGrants.userGroups - Array of group IDs with write access
|
|
609
|
-
* @returns {string[]} returns.writeGrants.organizations - Array of organization IDs with write access
|
|
610
|
-
*
|
|
611
|
-
* @example
|
|
612
|
-
* const permissions = myObject.getSharing();
|
|
613
|
-
* console.log('Read users:', permissions.readGrants.users);
|
|
614
|
-
* console.log('Read groups:', permissions.readGrants.userGroups);
|
|
615
|
-
*/
|
|
616
|
-
getSharing() {
|
|
617
|
-
const iac = this.get('iac') || {};
|
|
618
|
-
return {
|
|
619
|
-
readGrants: {
|
|
620
|
-
users: iac.readGrants?.users || [],
|
|
621
|
-
userGroups: iac.readGrants?.userGroups || [],
|
|
622
|
-
organizations: iac.readGrants?.organizations || [],
|
|
623
|
-
userSegments: iac.readGrants?.userSegments || []
|
|
624
|
-
},
|
|
625
|
-
writeGrants: {
|
|
626
|
-
users: iac.writeGrants?.users || [],
|
|
627
|
-
userGroups: iac.writeGrants?.userGroups || [],
|
|
628
|
-
organizations: iac.writeGrants?.organizations || [],
|
|
629
|
-
userSegments: iac.writeGrants?.userSegments || []
|
|
954
|
+
// Otherwise, lazily pull WebSocket from parent API (injected via axios instance)
|
|
955
|
+
if (!ws) {
|
|
956
|
+
var _this$_axios;
|
|
957
|
+
var api = (_this$_axios = this._axios) === null || _this$_axios === void 0 ? void 0 : _this$_axios.__rbtApiInstance;
|
|
958
|
+
if (!api || typeof api.getWebSocketClient !== 'function') return;
|
|
959
|
+
ws = api.getWebSocketClient();
|
|
630
960
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
throw new Error('Cannot delete object without type');
|
|
961
|
+
if (!ws || this._realtime) return;
|
|
962
|
+
this._ws = ws;
|
|
963
|
+
this._realtime = true;
|
|
964
|
+
this._subscribeToRealtime(ws);
|
|
636
965
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
966
|
+
}, {
|
|
967
|
+
key: "_subscribeToRealtime",
|
|
968
|
+
value: function _subscribeToRealtime(ws) {
|
|
969
|
+
var _this$_axios2,
|
|
970
|
+
_this3 = this;
|
|
971
|
+
// Track subscription for reconnection
|
|
972
|
+
var api = (_this$_axios2 = this._axios) === null || _this$_axios2 === void 0 ? void 0 : _this$_axios2.__rbtApiInstance;
|
|
973
|
+
if (api && typeof api._trackSubscription === 'function') {
|
|
974
|
+
api._trackSubscription(this.id);
|
|
645
975
|
}
|
|
646
|
-
|
|
647
|
-
return this;
|
|
648
|
-
} catch (e) {
|
|
649
|
-
console.log('RbtObject.delete.error:');
|
|
650
|
-
console.log(e.response.data);
|
|
651
|
-
throw e;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
_deepUnpackJson(value) {
|
|
655
|
-
if (typeof value === 'string') {
|
|
656
|
-
try {
|
|
657
|
-
// Only parse as JSON if it's not a large number
|
|
658
|
-
// https://chatgpt.com/c/6745902c-edf4-800c-ab52-31bf27dde2bd
|
|
659
|
-
//
|
|
660
|
-
if (!/^\d{16,}$/.test(value)) {
|
|
661
|
-
const parsed = JSON.parse(value);
|
|
662
|
-
// Recursively parse if the result is a string, object, or array
|
|
663
|
-
return this._deepUnpackJson(parsed);
|
|
664
|
-
}
|
|
665
|
-
} catch (e) {
|
|
666
|
-
return value; // Return the original string if parsing fails
|
|
667
|
-
}
|
|
668
|
-
} else if (value !== null && typeof value === 'object') {
|
|
669
|
-
// If it's an object (including arrays), recursively parse each value
|
|
670
|
-
for (const key in value) {
|
|
671
|
-
value[key] = this._deepUnpackJson(value[key]);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
return value;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
//
|
|
678
|
-
// Realtime WebSocket
|
|
679
|
-
//
|
|
680
|
-
//
|
|
681
|
-
_initRealtime() {
|
|
682
|
-
if (this._realtime || !this._axios) return;
|
|
683
|
-
|
|
684
|
-
// Use stored websocket client if available
|
|
685
|
-
let ws = this._ws;
|
|
686
|
-
|
|
687
|
-
// Otherwise, lazily pull WebSocket from parent API (injected via axios instance)
|
|
688
|
-
if (!ws) {
|
|
689
|
-
const api = this._axios?.__rbtApiInstance;
|
|
690
|
-
if (!api || typeof api.getWebSocketClient !== 'function') return;
|
|
691
|
-
ws = api.getWebSocketClient();
|
|
692
|
-
}
|
|
693
|
-
if (!ws || this._realtime) return;
|
|
694
|
-
this._ws = ws;
|
|
695
|
-
this._realtime = true;
|
|
696
|
-
this._subscribeToRealtime(ws);
|
|
697
|
-
}
|
|
698
|
-
_subscribeToRealtime(ws) {
|
|
699
|
-
// Track subscription for reconnection
|
|
700
|
-
const api = this._axios?.__rbtApiInstance;
|
|
701
|
-
if (api && typeof api._trackSubscription === 'function') {
|
|
702
|
-
api._trackSubscription(this.id);
|
|
703
|
-
}
|
|
704
|
-
if (ws.readyState === 1) {
|
|
705
|
-
ws.send(JSON.stringify({
|
|
706
|
-
type: 'subscribe',
|
|
707
|
-
objectId: this.id
|
|
708
|
-
}));
|
|
709
|
-
} else {
|
|
710
|
-
ws.addEventListener('open', () => {
|
|
976
|
+
if (ws.readyState === 1) {
|
|
711
977
|
ws.send(JSON.stringify({
|
|
712
978
|
type: 'subscribe',
|
|
713
979
|
objectId: this.id
|
|
714
980
|
}));
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
981
|
+
} else {
|
|
982
|
+
ws.addEventListener('open', function () {
|
|
983
|
+
ws.send(JSON.stringify({
|
|
984
|
+
type: 'subscribe',
|
|
985
|
+
objectId: _this3.id
|
|
986
|
+
}));
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
ws.addEventListener('message', function (event) {
|
|
990
|
+
try {
|
|
991
|
+
var msg = JSON.parse(event.data);
|
|
992
|
+
if (msg.objectId !== _this3.id) return;
|
|
993
|
+
if (msg.type === 'update') {
|
|
994
|
+
if (msg.delta && msg.delta.path !== undefined) {
|
|
995
|
+
_.set(_this3._data, msg.delta.path, msg.delta.value);
|
|
996
|
+
|
|
997
|
+
// Add metadata to indicate if this is state sync vs live update
|
|
998
|
+
var changeData = _objectSpread(_objectSpread({}, msg.delta), {}, {
|
|
999
|
+
isStateSync: msg.isStateSync || false,
|
|
1000
|
+
source: msg.isStateSync ? 'state-sync' : 'realtime',
|
|
1001
|
+
userId: msg.userId || msg.delta.userId || null
|
|
1002
|
+
});
|
|
1003
|
+
_this3._trigger('change', changeData);
|
|
1004
|
+
if (msg.isStateSync) {}
|
|
1005
|
+
} else {}
|
|
1006
|
+
} else if (msg.type === 'save') {
|
|
1007
|
+
_this3._trigger('save', msg.revision || {});
|
|
738
1008
|
}
|
|
739
|
-
}
|
|
740
|
-
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
console.error('[RbtObject] Error processing WebSocket message:', error, event.data);
|
|
741
1011
|
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
}
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
747
1014
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
this
|
|
1015
|
+
// General change handler for both local and remote changes
|
|
1016
|
+
}, {
|
|
1017
|
+
key: "onChange",
|
|
1018
|
+
value: function onChange(cb) {
|
|
1019
|
+
this._eventHandlers.change.push(cb);
|
|
1020
|
+
// Auto-initialize realtime if this object has WebSocket capability
|
|
1021
|
+
if (this._ws && !this._realtime) {
|
|
1022
|
+
this._initRealtime();
|
|
1023
|
+
}
|
|
754
1024
|
}
|
|
755
|
-
}
|
|
756
1025
|
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
console.log('[AgentProviderSync] _trigger called:', type, 'handlers:', this._eventHandlers[type]?.length, 'data:', data);
|
|
764
|
-
for (const fn of this._eventHandlers[type] || []) {
|
|
765
|
-
fn(data);
|
|
1026
|
+
// General save handler for both local and remote saves
|
|
1027
|
+
}, {
|
|
1028
|
+
key: "onSave",
|
|
1029
|
+
value: function onSave(cb) {
|
|
1030
|
+
this._eventHandlers.save.push(cb);
|
|
1031
|
+
// Note: Does not initialize realtime connection
|
|
766
1032
|
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
1033
|
+
}, {
|
|
1034
|
+
key: "_trigger",
|
|
1035
|
+
value: function _trigger(type, data) {
|
|
1036
|
+
var _iterator = _createForOfIteratorHelper(this._eventHandlers[type] || []),
|
|
1037
|
+
_step;
|
|
1038
|
+
try {
|
|
1039
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1040
|
+
var fn = _step.value;
|
|
1041
|
+
fn(data);
|
|
1042
|
+
}
|
|
1043
|
+
} catch (err) {
|
|
1044
|
+
_iterator.e(err);
|
|
1045
|
+
} finally {
|
|
1046
|
+
_iterator.f();
|
|
1047
|
+
}
|
|
771
1048
|
}
|
|
1049
|
+
}, {
|
|
1050
|
+
key: "_broadcastChange",
|
|
1051
|
+
value: function _broadcastChange(path, value) {
|
|
1052
|
+
var _this4 = this;
|
|
1053
|
+
if (!this._realtime || !this._ws || this._ws.readyState !== 1) {
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
772
1056
|
|
|
773
|
-
|
|
774
|
-
|
|
1057
|
+
// Store the pending broadcast
|
|
1058
|
+
this._pendingBroadcasts.set(path, value);
|
|
775
1059
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1060
|
+
// Clear existing timer if any
|
|
1061
|
+
if (this._broadcastDebounceTimer) {
|
|
1062
|
+
clearTimeout(this._broadcastDebounceTimer);
|
|
1063
|
+
}
|
|
780
1064
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
_flushPendingBroadcasts() {
|
|
787
|
-
if (!this._realtime || !this._ws || this._ws.readyState !== 1) {
|
|
788
|
-
this._pendingBroadcasts.clear();
|
|
789
|
-
return;
|
|
1065
|
+
// Set new debounced timer
|
|
1066
|
+
this._broadcastDebounceTimer = setTimeout(function () {
|
|
1067
|
+
_this4._flushPendingBroadcasts();
|
|
1068
|
+
}, 300);
|
|
790
1069
|
}
|
|
1070
|
+
}, {
|
|
1071
|
+
key: "_flushPendingBroadcasts",
|
|
1072
|
+
value: function _flushPendingBroadcasts() {
|
|
1073
|
+
if (!this._realtime || !this._ws || this._ws.readyState !== 1) {
|
|
1074
|
+
this._pendingBroadcasts.clear();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
791
1077
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1078
|
+
// Send all pending broadcasts
|
|
1079
|
+
var _iterator2 = _createForOfIteratorHelper(this._pendingBroadcasts),
|
|
1080
|
+
_step2;
|
|
1081
|
+
try {
|
|
1082
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1083
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
1084
|
+
path = _step2$value[0],
|
|
1085
|
+
value = _step2$value[1];
|
|
1086
|
+
this._ws.send(JSON.stringify({
|
|
1087
|
+
type: 'update',
|
|
1088
|
+
objectId: this.id,
|
|
1089
|
+
delta: {
|
|
1090
|
+
path: path,
|
|
1091
|
+
value: value
|
|
1092
|
+
}
|
|
1093
|
+
}));
|
|
800
1094
|
}
|
|
801
|
-
}));
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
// Clear pending broadcasts and timer
|
|
805
|
-
this._pendingBroadcasts.clear();
|
|
806
|
-
this._broadcastDebounceTimer = null;
|
|
807
|
-
}
|
|
808
1095
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
1096
|
+
// Clear pending broadcasts and timer
|
|
1097
|
+
} catch (err) {
|
|
1098
|
+
_iterator2.e(err);
|
|
1099
|
+
} finally {
|
|
1100
|
+
_iterator2.f();
|
|
1101
|
+
}
|
|
1102
|
+
this._pendingBroadcasts.clear();
|
|
813
1103
|
this._broadcastDebounceTimer = null;
|
|
814
1104
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
1105
|
+
|
|
1106
|
+
// Cleanup method to clear any pending debounced broadcasts
|
|
1107
|
+
}, {
|
|
1108
|
+
key: "_cleanup",
|
|
1109
|
+
value: function _cleanup() {
|
|
1110
|
+
if (this._broadcastDebounceTimer) {
|
|
1111
|
+
clearTimeout(this._broadcastDebounceTimer);
|
|
1112
|
+
this._broadcastDebounceTimer = null;
|
|
1113
|
+
}
|
|
1114
|
+
this._pendingBroadcasts.clear();
|
|
1115
|
+
}
|
|
1116
|
+
}]);
|
|
1117
|
+
return RbtObject;
|
|
1118
|
+
}();
|
|
1119
|
+
export { RbtObject as default };
|