orange-orm 4.2.0-beta.3 → 4.2.0-beta.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/package.json +1 -1
- package/src/client/cloneFromDb.js +15 -3
- package/src/client/index.js +9 -9
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
let dateToISOString = require('../dateToISOString');
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function cloneFromDbFast(obj) {
|
|
4
|
+
if (obj === null || typeof obj !== 'object') return obj;
|
|
5
|
+
if (Array.isArray(obj)) return obj.map(cloneFromDbFast);
|
|
6
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, cloneFromDbFast(value)]));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function cloneRegular(obj) {
|
|
4
10
|
if (obj === null || typeof obj !== 'object')
|
|
5
11
|
return obj;
|
|
6
12
|
if (Array.isArray(obj)) {
|
|
7
13
|
const arrClone = [];
|
|
8
14
|
for (let i = 0; i < obj.length; i++) {
|
|
9
|
-
arrClone[i] =
|
|
15
|
+
arrClone[i] = cloneRegular(obj[i]);
|
|
10
16
|
}
|
|
11
17
|
return arrClone;
|
|
12
18
|
}
|
|
@@ -16,10 +22,16 @@ function cloneFromDb(obj) {
|
|
|
16
22
|
const keys = Object.keys(obj);
|
|
17
23
|
for (let i = 0; i < keys.length; i++) {
|
|
18
24
|
const key = keys[i];
|
|
19
|
-
clone[key] =
|
|
25
|
+
clone[key] = cloneRegular(obj[key]);
|
|
20
26
|
}
|
|
21
27
|
return clone;
|
|
22
28
|
}
|
|
23
29
|
|
|
30
|
+
function cloneFromDb(obj, isFast) {
|
|
31
|
+
if (isFast)
|
|
32
|
+
return cloneFromDbFast(obj);
|
|
33
|
+
else
|
|
34
|
+
return cloneRegular(obj);
|
|
35
|
+
}
|
|
24
36
|
|
|
25
37
|
module.exports = cloneFromDb;
|
package/src/client/index.js
CHANGED
|
@@ -229,7 +229,7 @@ function rdbClient(options = {}) {
|
|
|
229
229
|
let args = [_, strategy].concat(Array.prototype.slice.call(arguments).slice(2));
|
|
230
230
|
let rows = await getManyCore.apply(null, args);
|
|
231
231
|
await metaPromise;
|
|
232
|
-
return proxify(rows, strategy,
|
|
232
|
+
return proxify(rows, strategy, true);
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
async function groupBy(strategy) {
|
|
@@ -261,7 +261,7 @@ function rdbClient(options = {}) {
|
|
|
261
261
|
await metaPromise;
|
|
262
262
|
if (rows.length === 0)
|
|
263
263
|
return;
|
|
264
|
-
return proxify(rows[0], strategy,
|
|
264
|
+
return proxify(rows[0], strategy, true);
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
async function getById() {
|
|
@@ -449,14 +449,14 @@ function rdbClient(options = {}) {
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
|
|
452
|
-
function proxify(itemOrArray, strategy,
|
|
452
|
+
function proxify(itemOrArray, strategy, fast) {
|
|
453
453
|
if (Array.isArray(itemOrArray))
|
|
454
|
-
return proxifyArray(itemOrArray, strategy,
|
|
454
|
+
return proxifyArray(itemOrArray, strategy, fast);
|
|
455
455
|
else
|
|
456
|
-
return proxifyRow(itemOrArray, strategy,
|
|
456
|
+
return proxifyRow(itemOrArray, strategy, fast);
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
function proxifyArray(array, strategy,
|
|
459
|
+
function proxifyArray(array, strategy, fast) {
|
|
460
460
|
let _array = array;
|
|
461
461
|
if (_reactive)
|
|
462
462
|
array = _reactive(array);
|
|
@@ -485,7 +485,7 @@ function rdbClient(options = {}) {
|
|
|
485
485
|
};
|
|
486
486
|
let innerProxy = new Proxy(array, handler);
|
|
487
487
|
//todo
|
|
488
|
-
rootMap.set(array, { json:
|
|
488
|
+
rootMap.set(array, { json: cloneFromDb(array, fast), strategy, originalArray: [...array] });
|
|
489
489
|
if (strategy !== undefined) {
|
|
490
490
|
const { limit, ...cleanStrategy } = { ...strategy };
|
|
491
491
|
fetchingStrategyMap.set(array, cleanStrategy);
|
|
@@ -493,7 +493,7 @@ function rdbClient(options = {}) {
|
|
|
493
493
|
return innerProxy;
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
function proxifyRow(row, strategy,
|
|
496
|
+
function proxifyRow(row, strategy, fast) {
|
|
497
497
|
let handler = {
|
|
498
498
|
get(_target, property,) {
|
|
499
499
|
if (property === 'save' || property === 'saveChanges') //call server then acceptChanges
|
|
@@ -518,7 +518,7 @@ function rdbClient(options = {}) {
|
|
|
518
518
|
|
|
519
519
|
};
|
|
520
520
|
let innerProxy = new Proxy(row, handler);
|
|
521
|
-
rootMap.set(row, { json:
|
|
521
|
+
rootMap.set(row, { json: cloneFromDb(row, fast), strategy });
|
|
522
522
|
fetchingStrategyMap.set(row, strategy);
|
|
523
523
|
return innerProxy;
|
|
524
524
|
}
|