roboto-js 1.5.3 → 1.5.4
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/dist/cjs/rbt_api.cjs +1 -3
- package/dist/cjs/rbt_object.cjs +57 -13
- package/dist/esm/rbt_api.js +1 -3
- package/dist/esm/rbt_object.js +47 -3
- package/package.json +1 -1
- package/src/rbt_api.js +1 -1
- package/src/rbt_object.js +54 -3
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -940,9 +940,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
940
940
|
if (Array.isArray(response.data.items)) {
|
|
941
941
|
//console.log('RBTAPI.query RESPONSE PRE', response.data.items);
|
|
942
942
|
response.data.items = response.data.items.map(function (record) {
|
|
943
|
-
return new _rbt_object["default"](record, _this3.axios
|
|
944
|
-
isNew: true
|
|
945
|
-
});
|
|
943
|
+
return new _rbt_object["default"](record, _this3.axios);
|
|
946
944
|
});
|
|
947
945
|
}
|
|
948
946
|
|
package/dist/cjs/rbt_object.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
35
35
|
this.id_revision = record.id_revision;
|
|
36
36
|
this.rpcMeta = {
|
|
37
37
|
changes: [],
|
|
38
|
-
isNew: options.isNew || false
|
|
38
|
+
isNew: options.isNew || record.revision == 0 || false
|
|
39
39
|
};
|
|
40
40
|
if (record.data) {
|
|
41
41
|
this._data = this._deepUnpackJson(record.data);
|
|
@@ -87,6 +87,9 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
87
87
|
|
|
88
88
|
if (options.merge) {
|
|
89
89
|
var mergedValue = _lodash["default"].mergeWith({}, currentValue, value, function (objValue, srcValue) {
|
|
90
|
+
if (srcValue === undefined) {
|
|
91
|
+
return undefined; // Indicate to delete when merging
|
|
92
|
+
}
|
|
90
93
|
if (_lodash["default"].isArray(objValue)) {
|
|
91
94
|
return srcValue; // Customize merging behavior for arrays
|
|
92
95
|
}
|
|
@@ -95,12 +98,22 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
95
98
|
return srcValue;
|
|
96
99
|
}
|
|
97
100
|
});
|
|
101
|
+
// Process merged object to remove any keys set explicitly to undefined
|
|
102
|
+
Object.keys(mergedValue).forEach(function (key) {
|
|
103
|
+
if (mergedValue[key] === undefined) {
|
|
104
|
+
_lodash["default"].unset(mergedValue, key);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
98
107
|
if (!_lodash["default"].isEqual(currentValue, mergedValue)) {
|
|
99
108
|
_lodash["default"].set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
100
109
|
this._addChange(path);
|
|
101
110
|
}
|
|
102
111
|
} else {
|
|
103
|
-
|
|
112
|
+
// If value is undefined and not merging, delete the key
|
|
113
|
+
if (value === undefined) {
|
|
114
|
+
_lodash["default"].unset(this._data, path);
|
|
115
|
+
this._addChange(path);
|
|
116
|
+
} else if (!_lodash["default"].isEqual(currentValue, value)) {
|
|
104
117
|
_lodash["default"].set(this._data, path, value); // Set the value directly at the deep path
|
|
105
118
|
this._addChange(path);
|
|
106
119
|
}
|
|
@@ -267,6 +280,32 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
267
280
|
rpcMeta: this.rpcMeta
|
|
268
281
|
});
|
|
269
282
|
}
|
|
283
|
+
}, {
|
|
284
|
+
key: "toDeltaRecord",
|
|
285
|
+
value: function toDeltaRecord() {
|
|
286
|
+
var changes = this.rpcMeta.changes;
|
|
287
|
+
|
|
288
|
+
// Initialize deltaData as an empty object
|
|
289
|
+
var sourceData = this._data;
|
|
290
|
+
var deltaData = {};
|
|
291
|
+
|
|
292
|
+
// Populate deltaData only with keys specified in changes
|
|
293
|
+
changes.forEach(function (path) {
|
|
294
|
+
// default value explicitly set to undefined
|
|
295
|
+
var value = _lodash["default"].get(sourceData, path, undefined);
|
|
296
|
+
// Use _.set to ensure nested keys are correctly assigned
|
|
297
|
+
_lodash["default"].set(deltaData, path, value);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// mark as delta
|
|
301
|
+
this.rpcMeta.delta = true;
|
|
302
|
+
var clonedData = _lodash["default"].cloneDeep(this._internalData);
|
|
303
|
+
clonedData.data = deltaData;
|
|
304
|
+
return _objectSpread(_objectSpread({}, clonedData), {}, {
|
|
305
|
+
dataJson: JSON.stringify(deltaData),
|
|
306
|
+
rpcMeta: this.rpcMeta
|
|
307
|
+
});
|
|
308
|
+
}
|
|
270
309
|
}, {
|
|
271
310
|
key: "clone",
|
|
272
311
|
value: function clone() {
|
|
@@ -298,24 +337,29 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
298
337
|
throw new Error('Cannot save object without type');
|
|
299
338
|
case 2:
|
|
300
339
|
_context3.prev = 2;
|
|
301
|
-
|
|
302
|
-
|
|
340
|
+
debugger;
|
|
341
|
+
if (this.rpcMeta.isNew) {
|
|
342
|
+
record = this.toRecord();
|
|
343
|
+
} else {
|
|
344
|
+
record = this.toDeltaRecord();
|
|
345
|
+
}
|
|
346
|
+
_context3.next = 7;
|
|
303
347
|
return this._axios.post('/object_service/saveObject', [record]);
|
|
304
|
-
case
|
|
348
|
+
case 7:
|
|
305
349
|
response = _context3.sent;
|
|
306
350
|
if (!(response.data.ok === false)) {
|
|
307
|
-
_context3.next =
|
|
351
|
+
_context3.next = 10;
|
|
308
352
|
break;
|
|
309
353
|
}
|
|
310
354
|
throw new Error(response.data.message);
|
|
311
|
-
case
|
|
355
|
+
case 10:
|
|
312
356
|
if (!(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.result) == 'NO_CHANGES')) {
|
|
313
|
-
_context3.next =
|
|
357
|
+
_context3.next = 13;
|
|
314
358
|
break;
|
|
315
359
|
}
|
|
316
360
|
this.rpcMeta.isNew = false;
|
|
317
361
|
return _context3.abrupt("return", this);
|
|
318
|
-
case
|
|
362
|
+
case 13:
|
|
319
363
|
if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
|
|
320
364
|
// apply new incoming data
|
|
321
365
|
this.setData(response.newData);
|
|
@@ -325,18 +369,18 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
325
369
|
this.type = response.data.type;
|
|
326
370
|
this.rpcMeta.isNew = false;
|
|
327
371
|
return _context3.abrupt("return", this);
|
|
328
|
-
case
|
|
329
|
-
_context3.prev =
|
|
372
|
+
case 21:
|
|
373
|
+
_context3.prev = 21;
|
|
330
374
|
_context3.t0 = _context3["catch"](2);
|
|
331
375
|
console.log('RbtObject.save.error:', _context3.t0 === null || _context3.t0 === void 0 || (_e$response = _context3.t0.response) === null || _e$response === void 0 ? void 0 : _e$response.data);
|
|
332
376
|
this._error = _context3.t0;
|
|
333
377
|
//console.log(e.response.data);
|
|
334
378
|
throw _context3.t0;
|
|
335
|
-
case
|
|
379
|
+
case 26:
|
|
336
380
|
case "end":
|
|
337
381
|
return _context3.stop();
|
|
338
382
|
}
|
|
339
|
-
}, _callee3, this, [[2,
|
|
383
|
+
}, _callee3, this, [[2, 21]]);
|
|
340
384
|
}));
|
|
341
385
|
function save() {
|
|
342
386
|
return _save.apply(this, arguments);
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -522,9 +522,7 @@ export default class RbtApi {
|
|
|
522
522
|
if (Array.isArray(response.data.items)) {
|
|
523
523
|
//console.log('RBTAPI.query RESPONSE PRE', response.data.items);
|
|
524
524
|
response.data.items = response.data.items.map(record => {
|
|
525
|
-
return new RbtObject(record, this.axios
|
|
526
|
-
isNew: true
|
|
527
|
-
});
|
|
525
|
+
return new RbtObject(record, this.axios);
|
|
528
526
|
});
|
|
529
527
|
}
|
|
530
528
|
|
package/dist/esm/rbt_object.js
CHANGED
|
@@ -8,7 +8,7 @@ export default class RbtObject {
|
|
|
8
8
|
this.id_revision = record.id_revision;
|
|
9
9
|
this.rpcMeta = {
|
|
10
10
|
changes: [],
|
|
11
|
-
isNew: options.isNew || false
|
|
11
|
+
isNew: options.isNew || record.revision == 0 || false
|
|
12
12
|
};
|
|
13
13
|
if (record.data) {
|
|
14
14
|
this._data = this._deepUnpackJson(record.data);
|
|
@@ -51,6 +51,9 @@ export default class RbtObject {
|
|
|
51
51
|
|
|
52
52
|
if (options.merge) {
|
|
53
53
|
const mergedValue = _.mergeWith({}, currentValue, value, (objValue, srcValue) => {
|
|
54
|
+
if (srcValue === undefined) {
|
|
55
|
+
return undefined; // Indicate to delete when merging
|
|
56
|
+
}
|
|
54
57
|
if (_.isArray(objValue)) {
|
|
55
58
|
return srcValue; // Customize merging behavior for arrays
|
|
56
59
|
}
|
|
@@ -59,12 +62,22 @@ export default class RbtObject {
|
|
|
59
62
|
return srcValue;
|
|
60
63
|
}
|
|
61
64
|
});
|
|
65
|
+
// Process merged object to remove any keys set explicitly to undefined
|
|
66
|
+
Object.keys(mergedValue).forEach(key => {
|
|
67
|
+
if (mergedValue[key] === undefined) {
|
|
68
|
+
_.unset(mergedValue, key);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
62
71
|
if (!_.isEqual(currentValue, mergedValue)) {
|
|
63
72
|
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
64
73
|
this._addChange(path);
|
|
65
74
|
}
|
|
66
75
|
} else {
|
|
67
|
-
|
|
76
|
+
// If value is undefined and not merging, delete the key
|
|
77
|
+
if (value === undefined) {
|
|
78
|
+
_.unset(this._data, path);
|
|
79
|
+
this._addChange(path);
|
|
80
|
+
} else if (!_.isEqual(currentValue, value)) {
|
|
68
81
|
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
69
82
|
this._addChange(path);
|
|
70
83
|
}
|
|
@@ -182,6 +195,31 @@ export default class RbtObject {
|
|
|
182
195
|
rpcMeta: this.rpcMeta
|
|
183
196
|
};
|
|
184
197
|
}
|
|
198
|
+
toDeltaRecord() {
|
|
199
|
+
let changes = this.rpcMeta.changes;
|
|
200
|
+
|
|
201
|
+
// Initialize deltaData as an empty object
|
|
202
|
+
let sourceData = this._data;
|
|
203
|
+
let deltaData = {};
|
|
204
|
+
|
|
205
|
+
// Populate deltaData only with keys specified in changes
|
|
206
|
+
changes.forEach(path => {
|
|
207
|
+
// default value explicitly set to undefined
|
|
208
|
+
const value = _.get(sourceData, path, undefined);
|
|
209
|
+
// Use _.set to ensure nested keys are correctly assigned
|
|
210
|
+
_.set(deltaData, path, value);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// mark as delta
|
|
214
|
+
this.rpcMeta.delta = true;
|
|
215
|
+
const clonedData = _.cloneDeep(this._internalData);
|
|
216
|
+
clonedData.data = deltaData;
|
|
217
|
+
return {
|
|
218
|
+
...clonedData,
|
|
219
|
+
dataJson: JSON.stringify(deltaData),
|
|
220
|
+
rpcMeta: this.rpcMeta
|
|
221
|
+
};
|
|
222
|
+
}
|
|
185
223
|
clone() {
|
|
186
224
|
// Create a deep copy of the current object's data
|
|
187
225
|
const clonedData = _.cloneDeep(this._internalData);
|
|
@@ -201,7 +239,13 @@ export default class RbtObject {
|
|
|
201
239
|
throw new Error('Cannot save object without type');
|
|
202
240
|
}
|
|
203
241
|
try {
|
|
204
|
-
|
|
242
|
+
debugger;
|
|
243
|
+
let record;
|
|
244
|
+
if (this.rpcMeta.isNew) {
|
|
245
|
+
record = this.toRecord();
|
|
246
|
+
} else {
|
|
247
|
+
record = this.toDeltaRecord();
|
|
248
|
+
}
|
|
205
249
|
const response = await this._axios.post('/object_service/saveObject', [record]);
|
|
206
250
|
if (response.data.ok === false) {
|
|
207
251
|
throw new Error(response.data.message);
|
package/package.json
CHANGED
package/src/rbt_api.js
CHANGED
|
@@ -597,7 +597,7 @@ export default class RbtApi {
|
|
|
597
597
|
if (Array.isArray(response.data.items)) {
|
|
598
598
|
//console.log('RBTAPI.query RESPONSE PRE', response.data.items);
|
|
599
599
|
response.data.items = response.data.items.map(record => {
|
|
600
|
-
return new RbtObject(record, this.axios
|
|
600
|
+
return new RbtObject(record, this.axios);
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
603
|
|
package/src/rbt_object.js
CHANGED
|
@@ -10,7 +10,7 @@ export default class RbtObject {
|
|
|
10
10
|
this.id_revision = record.id_revision;
|
|
11
11
|
this.rpcMeta = {
|
|
12
12
|
changes: [],
|
|
13
|
-
isNew: options.isNew || false
|
|
13
|
+
isNew: options.isNew || record.revision == 0 || false
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
if(record.data){
|
|
@@ -57,6 +57,9 @@ export default class RbtObject {
|
|
|
57
57
|
|
|
58
58
|
if (options.merge) {
|
|
59
59
|
const mergedValue = _.mergeWith({}, currentValue, value, (objValue, srcValue) => {
|
|
60
|
+
if (srcValue === undefined) {
|
|
61
|
+
return undefined; // Indicate to delete when merging
|
|
62
|
+
}
|
|
60
63
|
if (_.isArray(objValue)) {
|
|
61
64
|
return srcValue; // Customize merging behavior for arrays
|
|
62
65
|
}
|
|
@@ -65,12 +68,22 @@ export default class RbtObject {
|
|
|
65
68
|
return srcValue;
|
|
66
69
|
}
|
|
67
70
|
});
|
|
71
|
+
// Process merged object to remove any keys set explicitly to undefined
|
|
72
|
+
Object.keys(mergedValue).forEach(key => {
|
|
73
|
+
if (mergedValue[key] === undefined) {
|
|
74
|
+
_.unset(mergedValue, key);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
68
77
|
if (!_.isEqual(currentValue, mergedValue)) {
|
|
69
78
|
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
70
79
|
this._addChange(path);
|
|
71
80
|
}
|
|
72
81
|
} else {
|
|
73
|
-
|
|
82
|
+
// If value is undefined and not merging, delete the key
|
|
83
|
+
if (value === undefined) {
|
|
84
|
+
_.unset(this._data, path);
|
|
85
|
+
this._addChange(path);
|
|
86
|
+
} else if (!_.isEqual(currentValue, value)) {
|
|
74
87
|
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
75
88
|
this._addChange(path);
|
|
76
89
|
}
|
|
@@ -202,6 +215,34 @@ export default class RbtObject {
|
|
|
202
215
|
};
|
|
203
216
|
}
|
|
204
217
|
|
|
218
|
+
toDeltaRecord(){
|
|
219
|
+
|
|
220
|
+
let changes = this.rpcMeta.changes;
|
|
221
|
+
|
|
222
|
+
// Initialize deltaData as an empty object
|
|
223
|
+
let sourceData = this._data;
|
|
224
|
+
let deltaData = {};
|
|
225
|
+
|
|
226
|
+
// Populate deltaData only with keys specified in changes
|
|
227
|
+
changes.forEach(path => {
|
|
228
|
+
// default value explicitly set to undefined
|
|
229
|
+
const value = _.get(sourceData, path, undefined);
|
|
230
|
+
// Use _.set to ensure nested keys are correctly assigned
|
|
231
|
+
_.set(deltaData, path, value);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// mark as delta
|
|
235
|
+
this.rpcMeta.delta = true;
|
|
236
|
+
const clonedData = _.cloneDeep(this._internalData);
|
|
237
|
+
clonedData.data = deltaData;
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
...clonedData,
|
|
241
|
+
dataJson: JSON.stringify(deltaData),
|
|
242
|
+
rpcMeta: this.rpcMeta
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
205
246
|
clone() {
|
|
206
247
|
// Create a deep copy of the current object's data
|
|
207
248
|
const clonedData = _.cloneDeep(this._internalData);
|
|
@@ -222,7 +263,17 @@ export default class RbtObject {
|
|
|
222
263
|
}
|
|
223
264
|
|
|
224
265
|
try {
|
|
225
|
-
|
|
266
|
+
|
|
267
|
+
debugger;
|
|
268
|
+
let record;
|
|
269
|
+
if(this.rpcMeta.isNew){
|
|
270
|
+
record = this.toRecord();
|
|
271
|
+
}
|
|
272
|
+
else{
|
|
273
|
+
record = this.toDeltaRecord();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
226
277
|
const response = await this._axios.post('/object_service/saveObject', [record]);
|
|
227
278
|
|
|
228
279
|
if (response.data.ok === false) {
|