orange-orm 4.2.0-beta.0 → 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/cloneFromDb.js +25 -0
- package/src/client/index.js +9 -9
- package/src/client/index.mjs +12 -12
- package/src/getManyDto.js +5 -6
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let dateToISOString = require('../dateToISOString');
|
|
2
|
+
|
|
3
|
+
function cloneFromDb(obj) {
|
|
4
|
+
if (obj === null || typeof obj !== 'object')
|
|
5
|
+
return obj;
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
const arrClone = [];
|
|
8
|
+
for (let i = 0; i < obj.length; i++) {
|
|
9
|
+
arrClone[i] = cloneFromDb(obj[i]);
|
|
10
|
+
}
|
|
11
|
+
return arrClone;
|
|
12
|
+
}
|
|
13
|
+
else if (obj instanceof Date && !isNaN(obj))
|
|
14
|
+
return dateToISOString(obj);
|
|
15
|
+
const clone = {};
|
|
16
|
+
const keys = Object.keys(obj);
|
|
17
|
+
for (let i = 0; i < keys.length; i++) {
|
|
18
|
+
const key = keys[i];
|
|
19
|
+
clone[key] = cloneFromDb(obj[key]);
|
|
20
|
+
}
|
|
21
|
+
return clone;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
module.exports = cloneFromDb;
|
package/src/client/index.js
CHANGED
|
@@ -228,7 +228,7 @@ function rdbClient(options = {}) {
|
|
|
228
228
|
let args = [_, strategy].concat(Array.prototype.slice.call(arguments).slice(2));
|
|
229
229
|
let rows = await getManyCore.apply(null, args);
|
|
230
230
|
await metaPromise;
|
|
231
|
-
return proxify(rows, strategy);
|
|
231
|
+
return proxify(rows, strategy, {fastStringify : true});
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
async function groupBy(strategy) {
|
|
@@ -260,7 +260,7 @@ function rdbClient(options = {}) {
|
|
|
260
260
|
await metaPromise;
|
|
261
261
|
if (rows.length === 0)
|
|
262
262
|
return;
|
|
263
|
-
return proxify(rows[0], strategy);
|
|
263
|
+
return proxify(rows[0], strategy, {fastStringify : true});
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
async function getById() {
|
|
@@ -448,14 +448,14 @@ function rdbClient(options = {}) {
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
|
|
451
|
-
function proxify(itemOrArray, strategy) {
|
|
451
|
+
function proxify(itemOrArray, strategy, options) {
|
|
452
452
|
if (Array.isArray(itemOrArray))
|
|
453
|
-
return proxifyArray(itemOrArray, strategy);
|
|
453
|
+
return proxifyArray(itemOrArray, strategy, options);
|
|
454
454
|
else
|
|
455
|
-
return proxifyRow(itemOrArray, strategy);
|
|
455
|
+
return proxifyRow(itemOrArray, strategy, options);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
function proxifyArray(array, strategy) {
|
|
458
|
+
function proxifyArray(array, strategy, { fastStringify } = {}) {
|
|
459
459
|
let _array = array;
|
|
460
460
|
if (_reactive)
|
|
461
461
|
array = _reactive(array);
|
|
@@ -483,7 +483,7 @@ function rdbClient(options = {}) {
|
|
|
483
483
|
|
|
484
484
|
};
|
|
485
485
|
let innerProxy = new Proxy(array, handler);
|
|
486
|
-
rootMap.set(array, { json: stringify(array), strategy, originalArray: [...array] });
|
|
486
|
+
rootMap.set(array, { json: fastStringify ? JSON.stringify(array) : stringify(array), strategy, originalArray: [...array] });
|
|
487
487
|
if (strategy !== undefined) {
|
|
488
488
|
const { limit, ...cleanStrategy } = { ...strategy };
|
|
489
489
|
fetchingStrategyMap.set(array, cleanStrategy);
|
|
@@ -491,7 +491,7 @@ function rdbClient(options = {}) {
|
|
|
491
491
|
return innerProxy;
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
-
function proxifyRow(row, strategy) {
|
|
494
|
+
function proxifyRow(row, strategy, { fastStringify } = {}) {
|
|
495
495
|
let handler = {
|
|
496
496
|
get(_target, property,) {
|
|
497
497
|
if (property === 'save' || property === 'saveChanges') //call server then acceptChanges
|
|
@@ -516,7 +516,7 @@ function rdbClient(options = {}) {
|
|
|
516
516
|
|
|
517
517
|
};
|
|
518
518
|
let innerProxy = new Proxy(row, handler);
|
|
519
|
-
rootMap.set(row, { json: stringify(row), strategy });
|
|
519
|
+
rootMap.set(row, { json: fastStringify ? JSON.stringify(row) : stringify(row), strategy });
|
|
520
520
|
fetchingStrategyMap.set(row, strategy);
|
|
521
521
|
return innerProxy;
|
|
522
522
|
}
|
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
|
@@ -123,8 +123,6 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
123
123
|
}
|
|
124
124
|
const column = columns[j];
|
|
125
125
|
outRow[column.alias] = column.decode(row[keys[j]]);
|
|
126
|
-
if (shouldCreateMap)
|
|
127
|
-
fkIds[i] = getIds(outRow);
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
@@ -134,15 +132,16 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
outRows[i] = outRow;
|
|
137
|
-
if (shouldCreateMap)
|
|
135
|
+
if (shouldCreateMap) {
|
|
136
|
+
fkIds[i] = getIds(outRow);
|
|
138
137
|
addToMap(rowsMap, primaryColumns, outRow);
|
|
138
|
+
}
|
|
139
139
|
}
|
|
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
|
|