react-native-mosquito-transport 0.0.39 → 0.0.41
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/TODO
CHANGED
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -230,6 +230,7 @@ interface RNMTCollection {
|
|
|
230
230
|
});
|
|
231
231
|
count: (config?: CountConfig) => Promise<number>;
|
|
232
232
|
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
233
|
+
// TODO: change GetConfig for this listen
|
|
233
234
|
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
234
235
|
findOne: (findOne?: DocumentFind) => ({
|
|
235
236
|
get: (config?: GetConfig) => Promise<DocumentResult>;
|
|
@@ -380,6 +381,12 @@ interface GetConfig {
|
|
|
380
381
|
* To learn and see more examples on this, Please visit https://brainbehindx.com/mosquito-transport/docs/reading_data/retrieval
|
|
381
382
|
*/
|
|
382
383
|
disableMinimizer?: boolean;
|
|
384
|
+
onWaiting: (intruder: WaitingIntruder) => void | Promise<void>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
interface WaitingIntruder {
|
|
388
|
+
resolve?: undefined | ((data: any) => void);
|
|
389
|
+
reject?: undefined | ((err: any) => void);
|
|
383
390
|
}
|
|
384
391
|
|
|
385
392
|
interface GetConfigExtraction {
|
|
@@ -455,15 +455,17 @@ const transformBSON = (d, castBSON) => {
|
|
|
455
455
|
return basicClone(d);
|
|
456
456
|
};
|
|
457
457
|
|
|
458
|
-
const findObject = async (builder,
|
|
458
|
+
const findObject = async (builder, initConfig) => {
|
|
459
459
|
builder = basicClone(builder);
|
|
460
|
-
config = basicClone(config);
|
|
461
460
|
const { projectUrl, serverE2E_PublicKey, dbUrl, dbName, maxRetries = 1, path, disableCache = false, uglify, extraHeaders, command, castBSON } = builder;
|
|
462
|
-
|
|
461
|
+
|
|
462
|
+
const pureConfig = stripRequestConfig(initConfig);
|
|
463
463
|
validateFindObject(command);
|
|
464
|
-
validateFindConfig(
|
|
464
|
+
validateFindConfig(initConfig);
|
|
465
465
|
validateCollectionName(path);
|
|
466
466
|
|
|
467
|
+
let { onWaiting, ...config } = basicClone(initConfig) || {};
|
|
468
|
+
|
|
467
469
|
const { find, findOne, sort, direction, limit, random } = command;
|
|
468
470
|
const { retrieval = RETRIEVAL.DEFAULT, episode = 0, disableAuth, disableMinimizer } = config || {};
|
|
469
471
|
const enableMinimizer = !disableMinimizer;
|
|
@@ -475,6 +477,7 @@ const findObject = async (builder, config) => {
|
|
|
475
477
|
|
|
476
478
|
await awaitStore();
|
|
477
479
|
|
|
480
|
+
let intruder = {};
|
|
478
481
|
let retries = 0, hasFinalize;
|
|
479
482
|
|
|
480
483
|
const readValue = () => new Promise(async (resolve, reject) => {
|
|
@@ -482,11 +485,12 @@ const findObject = async (builder, config) => {
|
|
|
482
485
|
instantProcess = retryProcess === 1;
|
|
483
486
|
|
|
484
487
|
const finalize = (a, b) => {
|
|
485
|
-
const res = (instantProcess && a) ? transformBSON(a[0] || undefined, castBSON) : a;
|
|
488
|
+
const res = (instantProcess && a) ? intruder ? transformBSON(a[0] || undefined, castBSON) : a[0] : a;
|
|
489
|
+
const doClone = v => intruder ? basicClone(v) : v;
|
|
486
490
|
|
|
487
491
|
if (a) {
|
|
488
|
-
resolve(instantProcess ?
|
|
489
|
-
} else reject(instantProcess ?
|
|
492
|
+
resolve(instantProcess ? doClone(res) : a);
|
|
493
|
+
} else reject(instantProcess ? doClone(b) : b);
|
|
490
494
|
if (hasFinalize || !instantProcess) return;
|
|
491
495
|
hasFinalize = true;
|
|
492
496
|
|
|
@@ -497,7 +501,7 @@ const findObject = async (builder, config) => {
|
|
|
497
501
|
delete Scoped.PendingDbReadCollective[processAccessId];
|
|
498
502
|
|
|
499
503
|
resolutionList.forEach(e => {
|
|
500
|
-
e(a ? { result: res } : undefined, b);
|
|
504
|
+
e(a ? { result: doClone(res) } : undefined, doClone(b));
|
|
501
505
|
});
|
|
502
506
|
}
|
|
503
507
|
};
|
|
@@ -507,8 +511,8 @@ const findObject = async (builder, config) => {
|
|
|
507
511
|
if (enableMinimizer) {
|
|
508
512
|
if (Scoped.PendingDbReadCollective[processAccessId]) {
|
|
509
513
|
Scoped.PendingDbReadCollective[processAccessId].push((a, b) => {
|
|
510
|
-
if (a) resolve(
|
|
511
|
-
else reject(
|
|
514
|
+
if (a) resolve(a.result);
|
|
515
|
+
else reject(b);
|
|
512
516
|
});
|
|
513
517
|
return;
|
|
514
518
|
}
|
|
@@ -585,6 +589,8 @@ const findObject = async (builder, config) => {
|
|
|
585
589
|
} else {
|
|
586
590
|
const onlineListener = listenReachableServer(connected => {
|
|
587
591
|
if (connected) {
|
|
592
|
+
intruder.resolve = undefined;
|
|
593
|
+
intruder.reject = undefined;
|
|
588
594
|
onlineListener();
|
|
589
595
|
readValue().then(
|
|
590
596
|
e => { finalize(e); },
|
|
@@ -592,6 +598,22 @@ const findObject = async (builder, config) => {
|
|
|
592
598
|
);
|
|
593
599
|
}
|
|
594
600
|
}, projectUrl);
|
|
601
|
+
|
|
602
|
+
const cleanseIntruder = () => {
|
|
603
|
+
onlineListener?.();
|
|
604
|
+
intruder = undefined;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
intruder.resolve = (data) => {
|
|
608
|
+
cleanseIntruder();
|
|
609
|
+
finalize([data]);
|
|
610
|
+
};
|
|
611
|
+
intruder.reject = (err) => {
|
|
612
|
+
cleanseIntruder();
|
|
613
|
+
finalize(undefined, err);
|
|
614
|
+
};
|
|
615
|
+
onWaiting?.(intruder);
|
|
616
|
+
onWaiting = undefined;
|
|
595
617
|
}
|
|
596
618
|
}
|
|
597
619
|
});
|
|
@@ -31,7 +31,7 @@ const FindConfig = {
|
|
|
31
31
|
).length,
|
|
32
32
|
returnOnly: ReturnAndExcludeFootprint,
|
|
33
33
|
excludeFields: ReturnAndExcludeFootprint,
|
|
34
|
-
|
|
34
|
+
onWaiting: t => t === undefined || typeof t === 'function',
|
|
35
35
|
episode: t => [undefined, 0, 1].includes(t),
|
|
36
36
|
retrieval: t => t === undefined || Object.values(RETRIEVAL).includes(t),
|
|
37
37
|
disableAuth: t => t === undefined || typeof t === 'boolean',
|
|
@@ -70,13 +70,15 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
70
70
|
!Validator.JSON(body)
|
|
71
71
|
) throw `"body" must be any of string, buffer, object`;
|
|
72
72
|
}
|
|
73
|
+
await awaitStore();
|
|
73
74
|
|
|
74
75
|
const reqId = await niceHash(
|
|
75
76
|
serialize([
|
|
76
77
|
rawHeader,
|
|
77
78
|
body,
|
|
78
79
|
!!disableAuth,
|
|
79
|
-
input
|
|
80
|
+
input,
|
|
81
|
+
disableAuth ? '' : (Scoped.AuthJWTToken[projectUrl] || '')
|
|
80
82
|
]).toString('base64')
|
|
81
83
|
);
|
|
82
84
|
const processReqId = `${reqId}_${disableCache}_${retrieval}`;
|
|
@@ -104,7 +106,6 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
104
106
|
}
|
|
105
107
|
};
|
|
106
108
|
|
|
107
|
-
await awaitStore();
|
|
108
109
|
const resolveCache = (reqData) => {
|
|
109
110
|
finalize(reqData, undefined, { fromCache: true });
|
|
110
111
|
};
|