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