roboto-js 1.7.0 → 1.7.1

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.
@@ -0,0 +1,241 @@
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(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
10
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
11
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
12
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
13
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
14
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
16
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
17
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
18
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
+ 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); }
20
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
23
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
24
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
25
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
27
+ 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); }
28
+ var RbtUser = exports["default"] = /*#__PURE__*/function () {
29
+ function RbtUser(record, axiosInstance) {
30
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
31
+ _classCallCheck(this, RbtUser);
32
+ this._axios = axiosInstance;
33
+ this._internalData = record;
34
+ this.id = record.id;
35
+ this.id_revision = record.id_revision;
36
+ this.rpcMeta = {
37
+ changes: [],
38
+ isNew: options.isNew || false
39
+ };
40
+ if (record.data) {
41
+ this._data = this._deepUnpackJson(record.data);
42
+ } else {
43
+ this._data = record.dataJson ? this._deepUnpackJson(record.dataJson) : {};
44
+ }
45
+ }
46
+ return _createClass(RbtUser, [{
47
+ key: "get",
48
+ value: function get(path) {
49
+ return _lodash["default"].get(this._data, path);
50
+ }
51
+ }, {
52
+ key: "getData",
53
+ value: function getData() {
54
+ return _objectSpread({}, this._data);
55
+ }
56
+ }, {
57
+ key: "_addChange",
58
+ value: function _addChange(path) {
59
+ // Ensure no duplicate paths
60
+ if (!this.rpcMeta.changes.includes(path)) {
61
+ this.rpcMeta.changes.push(path);
62
+ }
63
+ }
64
+ }, {
65
+ key: "set",
66
+ value: function set(path, value) {
67
+ var currentValue = _lodash["default"].get(this._data, path);
68
+ if (!_lodash["default"].isEqual(currentValue, value)) {
69
+ _lodash["default"].set(this._data, path, value);
70
+ this._addChange(path);
71
+ }
72
+ }
73
+ }, {
74
+ key: "setData",
75
+ value: function setData(newData) {
76
+ var _this = this;
77
+ if (_typeof(newData) !== 'object' || newData === null) {
78
+ throw new Error('setData expects an object');
79
+ }
80
+ Object.keys(newData).forEach(function (key) {
81
+ if (!_lodash["default"].isEqual(_lodash["default"].get(_this._data, key), newData[key])) {
82
+ _lodash["default"].set(_this._data, key, newData[key]);
83
+ _this._addChange(key);
84
+ }
85
+ });
86
+ }
87
+
88
+ //
89
+ // For Arrays
90
+ //
91
+ }, {
92
+ key: "setAppend",
93
+ value: function setAppend(key, value) {
94
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
95
+ var existingValue = this.get(key) || []; // Get the existing value or default to an empty array
96
+ if (!Array.isArray(existingValue)) {
97
+ existingValue = []; // Ensure existingValue is an array if not already
98
+ }
99
+ var valuesToAdd = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
100
+
101
+ // Combine existingValue and valuesToAdd, filtering out duplicates
102
+ var mergedValues = Array.from(new Set([].concat(_toConsumableArray(existingValue), _toConsumableArray(valuesToAdd))));
103
+ this.set(key, mergedValues, options); // Set the updated array back to the user data
104
+ }
105
+ }, {
106
+ key: "setRemove",
107
+ value: function setRemove(key, value) {
108
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
109
+ var existingValue = this.get(key) || []; // Get the existing value or default to an empty array
110
+ if (!Array.isArray(existingValue)) {
111
+ return; // If it's not an array, there's nothing to remove, so exit early
112
+ }
113
+ var valuesToRemove = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
114
+
115
+ // Filter out the values to remove from the existing value array
116
+ var filteredValues = existingValue.filter(function (item) {
117
+ return !valuesToRemove.includes(item);
118
+ });
119
+ this.set(key, filteredValues); // Set the updated array back to the user data
120
+ }
121
+
122
+ //
123
+ //
124
+ //
125
+ }, {
126
+ key: "toRecord",
127
+ value: function toRecord() {
128
+ return _objectSpread(_objectSpread({}, this._internalData), {}, {
129
+ dataJson: JSON.stringify(this._data),
130
+ rpcMeta: this.rpcMeta
131
+ });
132
+ }
133
+ }, {
134
+ key: "clone",
135
+ value: function clone() {
136
+ // Create a deep copy of the current object's data
137
+ var clonedData = _lodash["default"].cloneDeep(this._internalData);
138
+
139
+ // Reset unique identifiers to ensure a new ID is generated upon saving
140
+ delete clonedData.id;
141
+ delete clonedData.id_revision;
142
+
143
+ // Create a new instance of RbtUser with the cloned data
144
+ var clonedObject = new RbtUser(clonedData, this._axios, {
145
+ isNew: true
146
+ });
147
+ return clonedObject;
148
+ }
149
+ }, {
150
+ key: "save",
151
+ value: function () {
152
+ var _save = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
153
+ var record, response, _t;
154
+ return _regenerator().w(function (_context) {
155
+ while (1) switch (_context.p = _context.n) {
156
+ case 0:
157
+ _context.p = 0;
158
+ debugger;
159
+ record = this.toRecord();
160
+ record.type = '<@iac.user>';
161
+ _context.n = 1;
162
+ return this._axios.post('/user_service/saveUser', [record]);
163
+ case 1:
164
+ response = _context.v;
165
+ if (!(response.data.ok === false)) {
166
+ _context.n = 2;
167
+ break;
168
+ }
169
+ throw new Error(response.data.message);
170
+ case 2:
171
+ this._internalData = response.data;
172
+ this.id = response.data.id;
173
+ this.id_revision = response.data.id_revision;
174
+ this.type = response.data.type;
175
+ this.rpcMeta.isNew = false;
176
+ return _context.a(2, this);
177
+ case 3:
178
+ _context.p = 3;
179
+ _t = _context.v;
180
+ console.log('RbtUser.save.error:', _t);
181
+ //console.log(e.response.data);
182
+ throw _t;
183
+ case 4:
184
+ return _context.a(2);
185
+ }
186
+ }, _callee, this, [[0, 3]]);
187
+ }));
188
+ function save() {
189
+ return _save.apply(this, arguments);
190
+ }
191
+ return save;
192
+ }()
193
+ }, {
194
+ key: "_deepUnpackJson",
195
+ value: function _deepUnpackJson(value) {
196
+ if (typeof value === 'string') {
197
+ try {
198
+ // Only parse as JSON if it's not a large number
199
+ // https://chatgpt.com/c/6745902c-edf4-800c-ab52-31bf27dde2bd
200
+ //
201
+ if (!/^\d{16,}$/.test(value)) {
202
+ var parsed = JSON.parse(value);
203
+ // Recursively parse if the result is a string, object, or array
204
+ return this._deepUnpackJson(parsed);
205
+ }
206
+ } catch (e) {
207
+ return value; // Return the original string if parsing fails
208
+ }
209
+ } else if (value !== null && _typeof(value) === 'object') {
210
+ // If it's an object (including arrays), recursively parse each value
211
+ for (var key in value) {
212
+ value[key] = this._deepUnpackJson(value[key]);
213
+ }
214
+ }
215
+ return value;
216
+ }
217
+
218
+ //async delete() {
219
+ // if (!this._internalData.type) {
220
+ // throw new Error('Cannot delete object without type');
221
+ // }
222
+ //
223
+ // try {
224
+ // const record = this.toRecord();
225
+ // const response = await this._axios.post('/object_service/deleteObject', [record]);
226
+ //
227
+ // if (response.data.ok === false) {
228
+ // throw new Error(response.data.message);
229
+ // }
230
+ //
231
+ // this._internalData = response.data;
232
+ // return this;
233
+ //
234
+ // } catch (e) {
235
+ // console.log('RbtUser.delete.error:');
236
+ // console.log(e.response.data);
237
+ // throw e;
238
+ // }
239
+ //}
240
+ }]);
241
+ }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/index.js CHANGED
@@ -15,7 +15,7 @@ export {
15
15
  export default class Roboto{
16
16
 
17
17
  getVersion(){
18
- return '1.6.17';
18
+ return '1.7.0';
19
19
  }
20
20
 
21
21
  constructor({ host, accessKey, localStorageAdaptor, disableWebSocket = false, metricsHost }, proxyReq = null) {