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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.2.0-beta.3",
3
+ "version": "4.2.0-beta.4",
4
4
  "main": "./src/index.js",
5
5
  "browser": "./src/client/index.mjs",
6
6
  "bin": {
@@ -1,12 +1,18 @@
1
1
  let dateToISOString = require('../dateToISOString');
2
2
 
3
- function cloneFromDb(obj) {
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] = cloneFromDb(obj[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] = cloneFromDb(obj[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;
@@ -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, {fast: true});
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, {fast: true});
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, options) {
452
+ function proxify(itemOrArray, strategy, fast) {
453
453
  if (Array.isArray(itemOrArray))
454
- return proxifyArray(itemOrArray, strategy, options);
454
+ return proxifyArray(itemOrArray, strategy, fast);
455
455
  else
456
- return proxifyRow(itemOrArray, strategy, options);
456
+ return proxifyRow(itemOrArray, strategy, fast);
457
457
  }
458
458
 
459
- function proxifyArray(array, strategy, { fast } = { }) {
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: fast ? structuredClone(array) : cloneFromDb(array), strategy, originalArray: [...array] });
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, { fast } = {}) {
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: fast ? structuredClone(row) : cloneFromDb(row), strategy });
521
+ rootMap.set(row, { json: cloneFromDb(row, fast), strategy });
522
522
  fetchingStrategyMap.set(row, strategy);
523
523
  return innerProxy;
524
524
  }