orange-orm 4.2.0-beta.1 → 4.2.0-beta.2
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/index.js +23 -25
- package/src/client/index.mjs +12 -12
- package/src/getManyDto.js +2 -3
package/package.json
CHANGED
package/src/client/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const createPatch = require('./createPatch');
|
|
2
2
|
const stringify = require('./stringify');
|
|
3
|
-
const cloneFromDb = require('./cloneFromDb');
|
|
4
3
|
const netAdapter = require('./netAdapter');
|
|
5
4
|
const toKeyPositionMap = require('./toKeyPositionMap');
|
|
6
5
|
const rootMap = new WeakMap();
|
|
@@ -229,7 +228,7 @@ function rdbClient(options = {}) {
|
|
|
229
228
|
let args = [_, strategy].concat(Array.prototype.slice.call(arguments).slice(2));
|
|
230
229
|
let rows = await getManyCore.apply(null, args);
|
|
231
230
|
await metaPromise;
|
|
232
|
-
return proxify(rows, strategy);
|
|
231
|
+
return proxify(rows, strategy, {fastStringify : true});
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
async function groupBy(strategy) {
|
|
@@ -261,7 +260,7 @@ function rdbClient(options = {}) {
|
|
|
261
260
|
await metaPromise;
|
|
262
261
|
if (rows.length === 0)
|
|
263
262
|
return;
|
|
264
|
-
return proxify(rows[0], strategy);
|
|
263
|
+
return proxify(rows[0], strategy, {fastStringify : true});
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
async function getById() {
|
|
@@ -449,14 +448,14 @@ function rdbClient(options = {}) {
|
|
|
449
448
|
}
|
|
450
449
|
|
|
451
450
|
|
|
452
|
-
function proxify(itemOrArray, strategy) {
|
|
451
|
+
function proxify(itemOrArray, strategy, options) {
|
|
453
452
|
if (Array.isArray(itemOrArray))
|
|
454
|
-
return proxifyArray(itemOrArray, strategy);
|
|
453
|
+
return proxifyArray(itemOrArray, strategy, options);
|
|
455
454
|
else
|
|
456
|
-
return proxifyRow(itemOrArray, strategy);
|
|
455
|
+
return proxifyRow(itemOrArray, strategy, options);
|
|
457
456
|
}
|
|
458
457
|
|
|
459
|
-
function proxifyArray(array, strategy) {
|
|
458
|
+
function proxifyArray(array, strategy, { fastStringify } = {}) {
|
|
460
459
|
let _array = array;
|
|
461
460
|
if (_reactive)
|
|
462
461
|
array = _reactive(array);
|
|
@@ -484,8 +483,7 @@ function rdbClient(options = {}) {
|
|
|
484
483
|
|
|
485
484
|
};
|
|
486
485
|
let innerProxy = new Proxy(array, handler);
|
|
487
|
-
|
|
488
|
-
rootMap.set(array, { json: cloneFromDb(array), strategy, originalArray: [...array] });
|
|
486
|
+
rootMap.set(array, { json: fastStringify ? JSON.stringify(array) : stringify(array), strategy, originalArray: [...array] });
|
|
489
487
|
if (strategy !== undefined) {
|
|
490
488
|
const { limit, ...cleanStrategy } = { ...strategy };
|
|
491
489
|
fetchingStrategyMap.set(array, cleanStrategy);
|
|
@@ -493,18 +491,18 @@ function rdbClient(options = {}) {
|
|
|
493
491
|
return innerProxy;
|
|
494
492
|
}
|
|
495
493
|
|
|
496
|
-
function proxifyRow(row, strategy) {
|
|
494
|
+
function proxifyRow(row, strategy, { fastStringify } = {}) {
|
|
497
495
|
let handler = {
|
|
498
496
|
get(_target, property,) {
|
|
499
497
|
if (property === 'save' || property === 'saveChanges') //call server then acceptChanges
|
|
500
498
|
return saveRow.bind(null, row);
|
|
501
|
-
else if (property === 'delete') //call server then remove from
|
|
499
|
+
else if (property === 'delete') //call server then remove from jsonMap and original
|
|
502
500
|
return deleteRow.bind(null, row);
|
|
503
501
|
else if (property === 'refresh') //refresh from server then acceptChanges
|
|
504
502
|
return refreshRow.bind(null, row);
|
|
505
|
-
else if (property === 'clearChanges') //refresh from
|
|
503
|
+
else if (property === 'clearChanges') //refresh from jsonMap, update original if present
|
|
506
504
|
return clearChangesRow.bind(null, row);
|
|
507
|
-
else if (property === 'acceptChanges') //remove from
|
|
505
|
+
else if (property === 'acceptChanges') //remove from jsonMap
|
|
508
506
|
return acceptChangesRow.bind(null, row);
|
|
509
507
|
else if (property === 'toJSON')
|
|
510
508
|
return () => {
|
|
@@ -518,7 +516,7 @@ function rdbClient(options = {}) {
|
|
|
518
516
|
|
|
519
517
|
};
|
|
520
518
|
let innerProxy = new Proxy(row, handler);
|
|
521
|
-
rootMap.set(row, { json:
|
|
519
|
+
rootMap.set(row, { json: fastStringify ? JSON.stringify(row) : stringify(row), strategy });
|
|
522
520
|
fetchingStrategyMap.set(row, strategy);
|
|
523
521
|
return innerProxy;
|
|
524
522
|
}
|
|
@@ -593,7 +591,7 @@ function rdbClient(options = {}) {
|
|
|
593
591
|
strategy = extractFetchingStrategy(array, strategy);
|
|
594
592
|
|
|
595
593
|
let meta = await getMeta();
|
|
596
|
-
const patch = createPatch(json, array, meta);
|
|
594
|
+
const patch = createPatch(JSON.parse(json), array, meta);
|
|
597
595
|
if (patch.length === 0)
|
|
598
596
|
return;
|
|
599
597
|
let body = stringify({ patch, options: { strategy, ...tableOptions, ...concurrencyOptions, deduceStrategy } });
|
|
@@ -608,7 +606,7 @@ function rdbClient(options = {}) {
|
|
|
608
606
|
let insertedPositions = getInsertedRowsPosition(array);
|
|
609
607
|
let { changed, strategy: newStrategy } = await p;
|
|
610
608
|
copyIntoArray(changed, array, [...insertedPositions, ...updatedPositions]);
|
|
611
|
-
rootMap.set(array, { json:
|
|
609
|
+
rootMap.set(array, { json: stringify(array), strategy: newStrategy, originalArray: [...array] });
|
|
612
610
|
}
|
|
613
611
|
|
|
614
612
|
async function patch(patch, concurrencyOptions, strategy) {
|
|
@@ -688,13 +686,13 @@ function rdbClient(options = {}) {
|
|
|
688
686
|
|
|
689
687
|
function clearChangesArray(array) {
|
|
690
688
|
let { json } = rootMap.get(array);
|
|
691
|
-
let old =
|
|
689
|
+
let old = JSON.parse(json);
|
|
692
690
|
array.splice(0, old.length, ...old);
|
|
693
691
|
}
|
|
694
692
|
|
|
695
693
|
function acceptChangesArray(array) {
|
|
696
694
|
const map = rootMap.get(array);
|
|
697
|
-
map.json =
|
|
695
|
+
map.json = stringify(array);
|
|
698
696
|
map.originalArray = [...array];
|
|
699
697
|
}
|
|
700
698
|
|
|
@@ -707,7 +705,7 @@ function rdbClient(options = {}) {
|
|
|
707
705
|
let adapter = netAdapter(url, tableName, { axios: axiosInterceptor, tableOptions });
|
|
708
706
|
let { strategy } = await adapter.patch(body);
|
|
709
707
|
array.length = 0;
|
|
710
|
-
rootMap.set(array, {
|
|
708
|
+
rootMap.set(array, { jsonMap: stringify(array), strategy });
|
|
711
709
|
}
|
|
712
710
|
|
|
713
711
|
function setMapValue(rowsMap, keys, row, index) {
|
|
@@ -770,7 +768,7 @@ function rdbClient(options = {}) {
|
|
|
770
768
|
array.splice(i + offset, 1);
|
|
771
769
|
offset--;
|
|
772
770
|
}
|
|
773
|
-
rootMap.set(array, { json:
|
|
771
|
+
rootMap.set(array, { json: stringify(array), strategy, originalArray: [...array] });
|
|
774
772
|
fetchingStrategyMap.set(array, strategy);
|
|
775
773
|
}
|
|
776
774
|
|
|
@@ -796,7 +794,7 @@ function rdbClient(options = {}) {
|
|
|
796
794
|
return;
|
|
797
795
|
let meta = await getMeta();
|
|
798
796
|
|
|
799
|
-
let patch = createPatch([json], [row], meta);
|
|
797
|
+
let patch = createPatch([JSON.parse(json)], [row], meta);
|
|
800
798
|
if (patch.length === 0)
|
|
801
799
|
return;
|
|
802
800
|
|
|
@@ -805,7 +803,7 @@ function rdbClient(options = {}) {
|
|
|
805
803
|
let adapter = netAdapter(url, tableName, { axios: axiosInterceptor, tableOptions });
|
|
806
804
|
let { changed, strategy: newStrategy } = await adapter.patch(body);
|
|
807
805
|
copyInto(changed, [row]);
|
|
808
|
-
rootMap.set(row, { json:
|
|
806
|
+
rootMap.set(row, { json: stringify(row), strategy: newStrategy });
|
|
809
807
|
}
|
|
810
808
|
|
|
811
809
|
async function refreshRow(row, strategy) {
|
|
@@ -829,20 +827,20 @@ function rdbClient(options = {}) {
|
|
|
829
827
|
for (let p in rows[0]) {
|
|
830
828
|
row[p] = rows[0][p];
|
|
831
829
|
}
|
|
832
|
-
rootMap.set(row, { json:
|
|
830
|
+
rootMap.set(row, { json: stringify(row), strategy });
|
|
833
831
|
fetchingStrategyMap.set(row, strategy);
|
|
834
832
|
}
|
|
835
833
|
|
|
836
834
|
function acceptChangesRow(row) {
|
|
837
835
|
const { strategy } = rootMap.get(row);
|
|
838
|
-
rootMap.set(row, { json:
|
|
836
|
+
rootMap.set(row, { json: stringify(row), strategy });
|
|
839
837
|
}
|
|
840
838
|
|
|
841
839
|
function clearChangesRow(row) {
|
|
842
840
|
let { json } = rootMap.get(row);
|
|
843
841
|
if (!json)
|
|
844
842
|
return;
|
|
845
|
-
let old =
|
|
843
|
+
let old = JSON.parse(json);
|
|
846
844
|
for (let p in row) {
|
|
847
845
|
delete row[p];
|
|
848
846
|
}
|
package/src/client/index.mjs
CHANGED
|
@@ -3607,7 +3607,7 @@ function isAbsoluteURL(url) {
|
|
|
3607
3607
|
*/
|
|
3608
3608
|
function combineURLs(baseURL, relativeURL) {
|
|
3609
3609
|
return relativeURL
|
|
3610
|
-
? baseURL.replace(
|
|
3610
|
+
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
3611
3611
|
: baseURL;
|
|
3612
3612
|
}
|
|
3613
3613
|
|
|
@@ -4241,7 +4241,7 @@ function mergeConfig(config1, config2) {
|
|
|
4241
4241
|
return config;
|
|
4242
4242
|
}
|
|
4243
4243
|
|
|
4244
|
-
const VERSION = "1.6.
|
|
4244
|
+
const VERSION = "1.6.3";
|
|
4245
4245
|
|
|
4246
4246
|
const validators$1 = {};
|
|
4247
4247
|
|
|
@@ -4857,7 +4857,7 @@ function httpAdapter(baseURL, path, axiosInterceptor) {
|
|
|
4857
4857
|
const res = await axios.request(path, { headers, method: 'patch', data: body });
|
|
4858
4858
|
return res.data;
|
|
4859
4859
|
}
|
|
4860
|
-
catch (e) {
|
|
4860
|
+
catch (e) {
|
|
4861
4861
|
if (typeof e.response?.data === 'string')
|
|
4862
4862
|
throw new Error(e.response.data.replace(/^Error: /, ''));
|
|
4863
4863
|
else
|
|
@@ -5524,7 +5524,7 @@ function rdbClient(options = {}) {
|
|
|
5524
5524
|
let args = [_, strategy].concat(Array.prototype.slice.call(arguments).slice(2));
|
|
5525
5525
|
let rows = await getManyCore.apply(null, args);
|
|
5526
5526
|
await metaPromise;
|
|
5527
|
-
return proxify(rows, strategy);
|
|
5527
|
+
return proxify(rows, strategy, {fastStringify : true});
|
|
5528
5528
|
}
|
|
5529
5529
|
|
|
5530
5530
|
async function groupBy(strategy) {
|
|
@@ -5556,7 +5556,7 @@ function rdbClient(options = {}) {
|
|
|
5556
5556
|
await metaPromise;
|
|
5557
5557
|
if (rows.length === 0)
|
|
5558
5558
|
return;
|
|
5559
|
-
return proxify(rows[0], strategy);
|
|
5559
|
+
return proxify(rows[0], strategy, {fastStringify : true});
|
|
5560
5560
|
}
|
|
5561
5561
|
|
|
5562
5562
|
async function getById() {
|
|
@@ -5744,14 +5744,14 @@ function rdbClient(options = {}) {
|
|
|
5744
5744
|
}
|
|
5745
5745
|
|
|
5746
5746
|
|
|
5747
|
-
function proxify(itemOrArray, strategy) {
|
|
5747
|
+
function proxify(itemOrArray, strategy, options) {
|
|
5748
5748
|
if (Array.isArray(itemOrArray))
|
|
5749
|
-
return proxifyArray(itemOrArray, strategy);
|
|
5749
|
+
return proxifyArray(itemOrArray, strategy, options);
|
|
5750
5750
|
else
|
|
5751
|
-
return proxifyRow(itemOrArray, strategy);
|
|
5751
|
+
return proxifyRow(itemOrArray, strategy, options);
|
|
5752
5752
|
}
|
|
5753
5753
|
|
|
5754
|
-
function proxifyArray(array, strategy) {
|
|
5754
|
+
function proxifyArray(array, strategy, { fastStringify } = {}) {
|
|
5755
5755
|
let _array = array;
|
|
5756
5756
|
if (_reactive)
|
|
5757
5757
|
array = _reactive(array);
|
|
@@ -5779,7 +5779,7 @@ function rdbClient(options = {}) {
|
|
|
5779
5779
|
|
|
5780
5780
|
};
|
|
5781
5781
|
let innerProxy = new Proxy(array, handler);
|
|
5782
|
-
rootMap.set(array, { json: stringify(array), strategy, originalArray: [...array] });
|
|
5782
|
+
rootMap.set(array, { json: fastStringify ? JSON.stringify(array) : stringify(array), strategy, originalArray: [...array] });
|
|
5783
5783
|
if (strategy !== undefined) {
|
|
5784
5784
|
const { limit, ...cleanStrategy } = { ...strategy };
|
|
5785
5785
|
fetchingStrategyMap.set(array, cleanStrategy);
|
|
@@ -5787,7 +5787,7 @@ function rdbClient(options = {}) {
|
|
|
5787
5787
|
return innerProxy;
|
|
5788
5788
|
}
|
|
5789
5789
|
|
|
5790
|
-
function proxifyRow(row, strategy) {
|
|
5790
|
+
function proxifyRow(row, strategy, { fastStringify } = {}) {
|
|
5791
5791
|
let handler = {
|
|
5792
5792
|
get(_target, property,) {
|
|
5793
5793
|
if (property === 'save' || property === 'saveChanges') //call server then acceptChanges
|
|
@@ -5812,7 +5812,7 @@ function rdbClient(options = {}) {
|
|
|
5812
5812
|
|
|
5813
5813
|
};
|
|
5814
5814
|
let innerProxy = new Proxy(row, handler);
|
|
5815
|
-
rootMap.set(row, { json: stringify(row), strategy });
|
|
5815
|
+
rootMap.set(row, { json: fastStringify ? JSON.stringify(row) : stringify(row), strategy });
|
|
5816
5816
|
fetchingStrategyMap.set(row, strategy);
|
|
5817
5817
|
return innerProxy;
|
|
5818
5818
|
}
|
package/src/getManyDto.js
CHANGED
|
@@ -140,9 +140,8 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
140
140
|
span._rowsMap = rowsMap;
|
|
141
141
|
span._ids = fkIds;
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
143
|
+
keys.splice(0, columnsLength + aggregateKeys.length);
|
|
144
|
+
|
|
146
145
|
await decodeRelations(strategy, span, rows, outRows, keys);
|
|
147
146
|
return outRows;
|
|
148
147
|
|