react-native-mosquito-transport 0.0.21 → 0.0.22
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/README.md +3 -7
- package/TODO +18 -8
- package/ios/Mosquitodb.swift +0 -4
- package/package.json +7 -7
- package/src/helpers/engine_api.js +2 -7
- package/src/helpers/peripherals.js +7 -31
- package/src/helpers/purger.js +264 -0
- package/src/helpers/sqlite_manager.js +138 -0
- package/src/helpers/utils.js +63 -43
- package/src/helpers/values.js +5 -20
- package/src/helpers/variables.js +36 -10
- package/src/index.d.ts +97 -56
- package/src/index.js +42 -38
- package/src/products/auth/accessor.js +10 -11
- package/src/products/auth/index.js +13 -28
- package/src/products/database/accessor.js +429 -165
- package/src/products/database/counter.js +12 -10
- package/src/products/database/index.js +177 -162
- package/src/products/database/types.js +1 -0
- package/src/products/database/validator.js +1 -1
- package/src/products/http_callable/accessor.js +72 -0
- package/src/products/http_callable/counter.js +11 -0
- package/src/products/http_callable/index.js +57 -66
- package/src/products/storage/index.js +20 -13
package/src/helpers/utils.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
1
|
import { ServerReachableListener, StoreReadyListener } from "./listeners";
|
|
3
|
-
import { CACHE_PROTOCOL, CACHE_STORAGE_PATH, DEFAULT_CACHE_PASSWORD, LOCAL_STORAGE_PATH } from "./values";
|
|
4
2
|
import { CacheStore, Scoped } from "./variables";
|
|
5
|
-
import {
|
|
3
|
+
import { serializeE2E } from "./peripherals";
|
|
6
4
|
import { deserializeBSON, serializeToBase64 } from "../products/database/bson";
|
|
7
5
|
import { trySendPendingWrite } from "../products/database";
|
|
8
6
|
import { deserialize } from "entity-serializer";
|
|
7
|
+
import { openDB, SQLITE_COMMANDS, SQLITE_PATH } from "./sqlite_manager";
|
|
8
|
+
import { purgeRedundantRecords } from "./purger";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const { cachePassword = DEFAULT_CACHE_PASSWORD, cacheProtocol = CACHE_PROTOCOL.ASYNC_STORAGE, io, promoteCache } = Scoped.ReleaseCacheData;
|
|
10
|
+
const { FILE_NAME, TABLE_NAME } = SQLITE_PATH;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const CacheKeys = Object.keys(CacheStore);
|
|
13
|
+
|
|
14
|
+
export const updateCacheStore = (timer = 300, node) => {
|
|
15
|
+
const { io, promoteCache } = Scoped.ReleaseCacheData;
|
|
16
|
+
|
|
17
|
+
const doUpdate = async () => {
|
|
18
|
+
const {
|
|
19
|
+
AuthStore,
|
|
20
|
+
EmulatedAuth,
|
|
21
|
+
PendingAuthPurge,
|
|
22
|
+
DatabaseStore,
|
|
23
|
+
PendingWrites,
|
|
24
|
+
...restStore
|
|
25
|
+
} = CacheStore;
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
JSON.stringify({
|
|
27
|
+
if (io) {
|
|
28
|
+
const txt = JSON.stringify({
|
|
19
29
|
AuthStore,
|
|
20
30
|
EmulatedAuth,
|
|
21
31
|
PendingAuthPurge,
|
|
@@ -24,51 +34,62 @@ export const updateCacheStore = (timer = 300) => {
|
|
|
24
34
|
PendingWrites: serializeToBase64(PendingWrites)
|
|
25
35
|
} : {},
|
|
26
36
|
...promoteCache ? restStore : {}
|
|
27
|
-
})
|
|
28
|
-
cachePassword,
|
|
29
|
-
cachePassword
|
|
30
|
-
);
|
|
37
|
+
});
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
io.output(txt);
|
|
34
|
-
} else if (cacheProtocol === CACHE_PROTOCOL.ASYNC_STORAGE) {
|
|
35
|
-
AsyncStorage.setItem(CACHE_STORAGE_PATH, txt);
|
|
36
|
-
} else if (cacheProtocol === CACHE_PROTOCOL.SQLITE) {
|
|
37
|
-
console.error('unsupported protocol "sqlite"');
|
|
39
|
+
io.output(txt, node);
|
|
38
40
|
} else {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
// use sqlite
|
|
42
|
+
const exclusion = ['DatabaseStore', 'DatabaseCountResult', 'FetchedStore'];
|
|
43
|
+
const updationKey = (node ? Array.isArray(node) ? node : [node] : CacheKeys).filter(v => !exclusion.includes(v));
|
|
44
|
+
|
|
45
|
+
if (!updationKey.length) return;
|
|
46
|
+
const sqlite = await openDB(FILE_NAME);
|
|
47
|
+
await Promise.allSettled(
|
|
48
|
+
updationKey
|
|
49
|
+
.map(v => [v, v === 'PendingWrites' ? serializeToBase64(CacheStore[v]) : CacheStore[v]])
|
|
50
|
+
.map(([ref, value]) =>
|
|
51
|
+
sqlite.executeSql(SQLITE_COMMANDS.MERGE(TABLE_NAME, ['ref', 'value']), [ref, JSON.stringify(value)])
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
sqlite.close();
|
|
41
55
|
}
|
|
42
|
-
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
clearTimeout(Scoped.cacheStorageReducer);
|
|
59
|
+
if (timer) {
|
|
60
|
+
Scoped.cacheStorageReducer = setTimeout(doUpdate, timer);
|
|
61
|
+
} else doUpdate();
|
|
43
62
|
};
|
|
44
63
|
|
|
45
64
|
export const releaseCacheStore = async (builder) => {
|
|
46
|
-
const {
|
|
65
|
+
const { io } = builder;
|
|
47
66
|
|
|
48
|
-
let
|
|
67
|
+
let data = {};
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
try {
|
|
70
|
+
if (io) {
|
|
71
|
+
data = JSON.parse((await io.input()) || '{}');
|
|
72
|
+
} else {
|
|
73
|
+
const sqlite = await openDB(FILE_NAME);
|
|
74
|
+
await sqlite.executeSql(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} ( ref TEXT PRIMARY KEY, value TEXT )`).catch(() => null);
|
|
75
|
+
const [query] = await sqlite.executeSql(`SELECT * FROM ${TABLE_NAME}`);
|
|
76
|
+
data = Object.fromEntries(query.rows.raw().map(v => [v.ref, JSON.parse(v.value)]));
|
|
77
|
+
sqlite.close();
|
|
78
|
+
}
|
|
79
|
+
await purgeRedundantRecords(data, builder);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error('releaseCacheStore data err:', e);
|
|
57
82
|
}
|
|
58
83
|
|
|
59
|
-
|
|
60
|
-
const projectList = new Set([]);
|
|
61
|
-
|
|
62
|
-
Object.entries(j).forEach(([k, v]) => {
|
|
84
|
+
Object.entries(data).forEach(([k, v]) => {
|
|
63
85
|
if (['DatabaseStore', 'PendingWrites'].includes(k)) {
|
|
64
86
|
CacheStore[k] = deserializeBSON(v);
|
|
65
87
|
} else CacheStore[k] = v;
|
|
66
|
-
projectList.add(k);
|
|
67
88
|
});
|
|
68
89
|
Object.entries(CacheStore.AuthStore).forEach(([key, value]) => {
|
|
69
90
|
Scoped.AuthJWTToken[key] = value?.token;
|
|
70
91
|
});
|
|
71
|
-
|
|
92
|
+
Object.keys(CacheStore.PendingWrites).forEach(projectUrl => {
|
|
72
93
|
if (Scoped.IS_CONNECTED[projectUrl])
|
|
73
94
|
trySendPendingWrite(projectUrl);
|
|
74
95
|
});
|
|
@@ -117,18 +138,17 @@ export const getReachableServer = (projectUrl) => new Promise(resolve => {
|
|
|
117
138
|
}, true);
|
|
118
139
|
});
|
|
119
140
|
|
|
120
|
-
export const buildFetchInterface = async ({ body,
|
|
141
|
+
export const buildFetchInterface = async ({ body, authToken, method, uglify, serverE2E_PublicKey, extraHeaders }) => {
|
|
121
142
|
if (!uglify) body = JSON.stringify({ ...body });
|
|
122
143
|
const [plate, keyPair] = uglify ? await serializeE2E(body, authToken, serverE2E_PublicKey) : [undefined, []];
|
|
123
144
|
|
|
124
145
|
return [{
|
|
125
146
|
body: uglify ? plate : body,
|
|
126
|
-
cache: 'no-cache',
|
|
147
|
+
// cache: 'no-cache',
|
|
127
148
|
headers: {
|
|
149
|
+
...extraHeaders,
|
|
128
150
|
'Content-type': uglify ? 'request/buffer' : 'application/json',
|
|
129
|
-
'
|
|
130
|
-
...(authToken && !uglify) ? { 'Mosquito-Token': authToken } : {},
|
|
131
|
-
...extraHeaders
|
|
151
|
+
...(authToken && !uglify) ? { 'Mosquito-Token': authToken } : {}
|
|
132
152
|
},
|
|
133
153
|
method: method || 'POST'
|
|
134
154
|
}, keyPair];
|
package/src/helpers/values.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import { encodeBinary } from './peripherals';
|
|
3
|
-
|
|
4
|
-
export const CACHE_STORAGE_PATH = encodeBinary('MOSQUITO_TRANSPORT_FREEZER'),
|
|
5
|
-
DEFAULT_CACHE_PASSWORD = encodeBinary('MOSQUITO_TRANSPORT_CACHE_PASSWORD'),
|
|
6
|
-
LOCAL_STORAGE_PATH = () => {
|
|
7
|
-
const fs = require('react-native-fs');
|
|
8
|
-
return `${Platform.OS === 'android' ? fs.ExternalCachesDirectoryPath : fs.CachesDirectoryPath}/${encodeBinary('MOSQUITO_TRANSPORT_STORAGE')}`;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const CACHE_PROTOCOL = {
|
|
12
|
-
ASYNC_STORAGE: 'async-storage',
|
|
13
|
-
REACT_NATIVE_FS: 'reat-native-fs',
|
|
14
|
-
SQLITE: 'sqlite' // TODO:
|
|
15
|
-
};
|
|
16
1
|
|
|
17
2
|
export const RETRIEVAL = {
|
|
18
3
|
STICKY: 'sticky',
|
|
19
4
|
STICKY_NO_AWAIT: 'sticky-no-await',
|
|
20
5
|
STICKY_RELOAD: 'sticky-reload',
|
|
21
6
|
DEFAULT: 'default',
|
|
7
|
+
CACHE_AWAIT: 'cache-await',
|
|
22
8
|
CACHE_NO_AWAIT: 'cache-no-await',
|
|
23
9
|
NO_CACHE_NO_AWAIT: 'no-cache-no-await',
|
|
24
10
|
NO_CACHE_AWAIT: 'no-cache-await'
|
|
@@ -26,11 +12,10 @@ export const RETRIEVAL = {
|
|
|
26
12
|
|
|
27
13
|
export const DELIVERY = {
|
|
28
14
|
DEFAULT: 'default',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
CACHE_NO_AWAIT: 'cache-no-await'
|
|
15
|
+
CACHE_AWAIT: 'cache-await',
|
|
16
|
+
CACHE_NO_AWAIT: 'cache-no-await',
|
|
17
|
+
NO_CACHE_NO_AWAIT: 'no-cache-no-await',
|
|
18
|
+
NO_CACHE_AWAIT: 'no-cache-await'
|
|
34
19
|
};
|
|
35
20
|
|
|
36
21
|
export const AUTH_PROVIDER_ID = {
|
package/src/helpers/variables.js
CHANGED
|
@@ -14,26 +14,52 @@ export const Scoped = {
|
|
|
14
14
|
LastTokenRefreshRef: {},
|
|
15
15
|
StorageProcessID: 0,
|
|
16
16
|
InitiatedForcedToken: {},
|
|
17
|
-
PendingFetchCollective: {
|
|
18
|
-
|
|
19
|
-
pendingResolution: {}
|
|
20
|
-
},
|
|
21
|
-
PendingDbReadCollective: {
|
|
22
|
-
pendingProcess: {},
|
|
23
|
-
pendingResolution: {}
|
|
24
|
-
},
|
|
17
|
+
PendingFetchCollective: {},
|
|
18
|
+
PendingDbReadCollective: {},
|
|
25
19
|
ActiveDatabaseListeners: {},
|
|
26
20
|
OutgoingWrites: {},
|
|
27
21
|
/**
|
|
28
22
|
* @type {Promise<any> | undefined}
|
|
29
23
|
*/
|
|
30
|
-
dispatchingWritesPromise: undefined
|
|
24
|
+
dispatchingWritesPromise: undefined,
|
|
25
|
+
linearSqliteProcess: {
|
|
26
|
+
database: {},
|
|
27
|
+
dbQueryCount: {},
|
|
28
|
+
httpFetch: {}
|
|
29
|
+
},
|
|
30
|
+
initedSqliteInstances: {
|
|
31
|
+
httpFetch: undefined,
|
|
32
|
+
dbQueryCount: {},
|
|
33
|
+
database: {}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const SqliteCollective = {
|
|
38
|
+
openedDb: {},
|
|
39
|
+
openedDbProcess: {},
|
|
40
|
+
closeDbPromises: {},
|
|
41
|
+
openedDbReducerTimer: {}
|
|
31
42
|
};
|
|
32
43
|
|
|
33
44
|
export const CacheStore = {
|
|
34
45
|
DatabaseStore: {},
|
|
35
46
|
DatabaseCountResult: {},
|
|
36
|
-
DatabaseStats: {
|
|
47
|
+
DatabaseStats: {
|
|
48
|
+
/**
|
|
49
|
+
* @type {{[projectUrl: string]: {[dbUrl: string]: {[dbName: string]: {[path: string]: number}}}}}
|
|
50
|
+
*/
|
|
51
|
+
database: {},
|
|
52
|
+
/**
|
|
53
|
+
* @type {{[projectUrl: string]: {[dbUrl: string]: {[dbName: string]: {[path: string]: boolean}}}}}
|
|
54
|
+
*/
|
|
55
|
+
counters: {},
|
|
56
|
+
/**
|
|
57
|
+
* @type {{[projectUrl: string]: number}}
|
|
58
|
+
*/
|
|
59
|
+
fetchers: {},
|
|
60
|
+
_db_size: 0,
|
|
61
|
+
_fetcher_size: 0
|
|
62
|
+
},
|
|
37
63
|
AuthStore: {},
|
|
38
64
|
PendingAuthPurge: {},
|
|
39
65
|
EmulatedAuth: {},
|
package/src/index.d.ts
CHANGED
|
@@ -2,10 +2,16 @@ interface RNMTConfig {
|
|
|
2
2
|
dbName?: string;
|
|
3
3
|
dbUrl?: string;
|
|
4
4
|
projectUrl: string;
|
|
5
|
+
/**
|
|
6
|
+
* disable caching for database and fetchHttp in this instance.
|
|
7
|
+
*
|
|
8
|
+
* defaults to `false` but `true` in scenerio where an invoked fetchHttp does have a request body and disableCache is undefined
|
|
9
|
+
*/
|
|
5
10
|
disableCache?: boolean;
|
|
6
|
-
accessKey: string;
|
|
7
11
|
/**
|
|
8
|
-
* maximum numbers of attempts to retry sending a request
|
|
12
|
+
* maximum numbers of attempts to retry sending a failed request
|
|
13
|
+
*
|
|
14
|
+
* @default 3
|
|
9
15
|
*/
|
|
10
16
|
maxRetries?: number;
|
|
11
17
|
/**
|
|
@@ -37,6 +43,7 @@ interface GetDatabase {
|
|
|
37
43
|
interface mtimestamp { $timestamp: 'now' }
|
|
38
44
|
|
|
39
45
|
export const TIMESTAMP: mtimestamp;
|
|
46
|
+
export function TIMESTAMP_OFFSET(offset: number): { $timestamp_offset: number };
|
|
40
47
|
export function DOCUMENT_EXTRACTION(path: string): { $dynamicValue: string };
|
|
41
48
|
|
|
42
49
|
type longitude = number;
|
|
@@ -64,6 +71,7 @@ export const AUTH_PROVIDER_ID: auth_provider_id;
|
|
|
64
71
|
* useful for avoiding encrypting data and extra overhead
|
|
65
72
|
*/
|
|
66
73
|
export class DoNotEncrypt {
|
|
74
|
+
constructor(value: any);
|
|
67
75
|
value: any;
|
|
68
76
|
}
|
|
69
77
|
|
|
@@ -84,40 +92,45 @@ type auth_provider_id_values = auth_provider_id['GOOGLE'] |
|
|
|
84
92
|
auth_provider_id['APPLE'];
|
|
85
93
|
|
|
86
94
|
interface ReleaseCacheOption_IO {
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface ReleaseCacheOption {
|
|
87
98
|
/**
|
|
88
|
-
* This
|
|
99
|
+
* This key will be used to encrypt sqlite data stored locally
|
|
100
|
+
*/
|
|
101
|
+
sqliteKey?: string;
|
|
102
|
+
/**
|
|
103
|
+
* sqlite is used as the default caching mechanism
|
|
104
|
+
*
|
|
105
|
+
* providing `io` means you want to override this behaviour and handle caching yourself in the system's memory
|
|
89
106
|
*/
|
|
90
|
-
cachePassword?: string;
|
|
91
107
|
io: {
|
|
92
108
|
/**
|
|
93
|
-
*
|
|
109
|
+
* you should handle retrieval of mosquito-transport data here by returning it
|
|
94
110
|
*/
|
|
95
|
-
input: () => string
|
|
111
|
+
input: () => string | Promise<string>;
|
|
96
112
|
/**
|
|
97
|
-
*
|
|
113
|
+
* you should handle storage of mosquito-transport data here by caching the emitted string
|
|
98
114
|
*/
|
|
99
115
|
output: (data: string) => void;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface ReleaseCacheOption {
|
|
104
|
-
/**
|
|
105
|
-
* This password will be used to encrypt data stored locally
|
|
106
|
-
*/
|
|
107
|
-
cachePassword?: string;
|
|
116
|
+
},
|
|
108
117
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
118
|
+
* the maximum size allocated to local database
|
|
119
|
+
*
|
|
120
|
+
* when local database size exceed this value, redundant database documents will be purge retaining only recently used ones
|
|
121
|
+
*
|
|
122
|
+
* @default 10485760 - 'which is 10 megabytes'
|
|
112
123
|
*/
|
|
113
|
-
|
|
124
|
+
maxLocalDatabaseSize?: number;
|
|
114
125
|
/**
|
|
115
|
-
* the maximum database
|
|
126
|
+
* the maximum size allocated to local database for storing {@link RNMT.fetchHttp}
|
|
127
|
+
*
|
|
128
|
+
* @default 10485760 - 'which is 10 megabytes'
|
|
116
129
|
*/
|
|
117
|
-
|
|
130
|
+
maxLocalFetchHttpSize?: number;
|
|
118
131
|
/**
|
|
119
132
|
* true to cache database and {@link RNMT.fetchHttp} data.
|
|
120
|
-
* the value only applies to in-memory storage protocol such as `io
|
|
133
|
+
* the value only applies to in-memory storage protocol such as `io`
|
|
121
134
|
*
|
|
122
135
|
* @default false
|
|
123
136
|
*/
|
|
@@ -146,16 +159,28 @@ interface BatchWriteConfig extends WriteConfig {
|
|
|
146
159
|
stepping?: boolean;
|
|
147
160
|
}
|
|
148
161
|
|
|
162
|
+
interface CountConfig {
|
|
163
|
+
disableAuth?: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface FetchHttpResponse extends Response {
|
|
167
|
+
/**
|
|
168
|
+
* true if this response was from local cache
|
|
169
|
+
*/
|
|
170
|
+
fromCache?: boolean | undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
149
173
|
export default class RNMT {
|
|
150
174
|
constructor(config: RNMTConfig);
|
|
151
|
-
static initializeCache(option?: ReleaseCacheOption
|
|
175
|
+
static initializeCache(option?: ReleaseCacheOption): void;
|
|
152
176
|
getDatabase(dbName?: string, dbUrl?: string): GetDatabase;
|
|
153
177
|
collection(path: string): RNMTCollection;
|
|
154
178
|
auth(): RNMTAuth;
|
|
155
179
|
storage(): RNMTStorage;
|
|
156
|
-
fetchHttp(endpoint: string, init?: RequestInit, config?: FetchHttpConfig): Promise<
|
|
180
|
+
fetchHttp(endpoint: string, init?: RequestInit, config?: FetchHttpConfig): Promise<FetchHttpResponse>;
|
|
157
181
|
listenReachableServer(callback: (reachable: boolean) => void): () => void;
|
|
158
182
|
getSocket(options: { disableAuth?: boolean; authHandshake?: Object }): RNMTSocket;
|
|
183
|
+
onConnect: () => CollectionIO;
|
|
159
184
|
batchWrite(map: BatchWriteValue[], config?: BatchWriteConfig): Promise<DocumentWriteResult[] | undefined>;
|
|
160
185
|
}
|
|
161
186
|
|
|
@@ -163,7 +188,7 @@ interface RNMTCollection {
|
|
|
163
188
|
find: (find?: DocumentFind) => ({
|
|
164
189
|
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
165
190
|
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
166
|
-
count: () => Promise<number>;
|
|
191
|
+
count: (config?: CountConfig) => Promise<number>;
|
|
167
192
|
limit: (limit: number) => ({
|
|
168
193
|
random: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
169
194
|
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
@@ -199,25 +224,13 @@ interface RNMTCollection {
|
|
|
199
224
|
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
200
225
|
})
|
|
201
226
|
});
|
|
202
|
-
count: () => Promise<number>;
|
|
227
|
+
count: (config?: CountConfig) => Promise<number>;
|
|
203
228
|
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
204
229
|
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
205
230
|
findOne: (findOne?: DocumentFind) => ({
|
|
206
231
|
get: (config?: GetConfig) => Promise<DocumentResult>;
|
|
207
232
|
listen: (callback: (snapshot?: DocumentResult) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
208
233
|
});
|
|
209
|
-
onDisconnect: () => ({
|
|
210
|
-
setOne: (value: DocumentWriteValue) => () => void;
|
|
211
|
-
setMany: (value: DocumentWriteValue[]) => () => void;
|
|
212
|
-
updateOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
213
|
-
updateMany: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
214
|
-
mergeOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
215
|
-
mergeMany: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
216
|
-
replaceOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
217
|
-
putOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
218
|
-
deleteOne: (find: DocumentFind) => () => void;
|
|
219
|
-
deleteMany: (find?: DocumentFind) => () => void;
|
|
220
|
-
})
|
|
221
234
|
|
|
222
235
|
setOne: (value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
223
236
|
|
|
@@ -240,8 +253,24 @@ interface RNMTCollection {
|
|
|
240
253
|
deleteMany: (find?: DocumentFind, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
241
254
|
}
|
|
242
255
|
|
|
243
|
-
interface
|
|
244
|
-
|
|
256
|
+
interface CollectionTaskIO<T> {
|
|
257
|
+
batchWrite(map: BatchWriteValue[], config?: BatchWriteConfig): T;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
interface StartStop {
|
|
261
|
+
start: () => () => void;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
interface OnConnectChain extends StartStop {
|
|
265
|
+
onDisconnect: () => CollectionTaskIO<StartStop>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
interface CollectionIO extends CollectionTaskIO<OnConnectChain> {
|
|
269
|
+
onDisconnect: () => CollectionTaskIO<StartStop>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
interface DocumentResult extends Document {
|
|
273
|
+
_foreign_doc?: Document | Document[] | Document[][]
|
|
245
274
|
}
|
|
246
275
|
|
|
247
276
|
interface DocumentError extends ErrorResponse {
|
|
@@ -263,15 +292,21 @@ interface WriteConfig {
|
|
|
263
292
|
*/
|
|
264
293
|
disableAuth?: boolean;
|
|
265
294
|
|
|
295
|
+
DEFAULT: 'default',
|
|
296
|
+
CACHE_AWAIT: 'cache-await',
|
|
297
|
+
CACHE_NO_AWAIT: 'cache-no-await',
|
|
298
|
+
NO_CACHE_NO_AWAIT: 'no-cache-no-await',
|
|
299
|
+
NO_CACHE_AWAIT: 'no-cache-await'
|
|
300
|
+
|
|
266
301
|
/**
|
|
267
|
-
* This property
|
|
302
|
+
* This property determines how the write will be dispatch to the remote server
|
|
303
|
+
* TODO:
|
|
268
304
|
*
|
|
269
|
-
*
|
|
270
|
-
* -
|
|
271
|
-
* -
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* - cache-no-await:
|
|
305
|
+
* `default`:
|
|
306
|
+
* `cache-await`:
|
|
307
|
+
* `cache-no-await`:
|
|
308
|
+
* `no-cache-no-await`:
|
|
309
|
+
* `no-cache-await`:
|
|
275
310
|
*/
|
|
276
311
|
delivery?: Delievery;
|
|
277
312
|
}
|
|
@@ -283,23 +318,28 @@ interface GetConfig {
|
|
|
283
318
|
returnOnly?: string | string[];
|
|
284
319
|
extraction?: GetConfigExtraction | GetConfigExtraction[];
|
|
285
320
|
/**
|
|
286
|
-
* This property determines how requested data
|
|
321
|
+
* This property determines how requested data should be accessed and handled
|
|
287
322
|
*
|
|
288
|
-
*
|
|
323
|
+
* `default`: will try getting fresh data from the server if the server is reachable then cache the result for future use. In scenerio where the server is unreachable, we check if local data exists and return it, if no local data exist we wait for reachable a server to complete the task.
|
|
324
|
+
* ⚠️ This respect `disableCache` value therefore if disableCache is true, no local cache read/write will be made for the request.
|
|
289
325
|
*
|
|
290
|
-
*
|
|
326
|
+
* `sticky`: if local data exists for the specified query, such data is returned and no-ops afterwards. If no local data is found, we await for client->server connectivity and try to get fresh data from serve, return the data and cache it for future need. ⚠️ This overrides `disableCache` value
|
|
291
327
|
*
|
|
292
|
-
*
|
|
328
|
+
* `sticky-no-await`: if local data exists for the specified query, such data is returned and no operation is performed afterwards. If no local data is found, will try to get fresh data from serve, we throw an error if server is unreachable else if server returns requested data, we return such data and cache it for future need. ⚠️ This overrides `disableCache` value
|
|
293
329
|
*
|
|
294
|
-
*
|
|
330
|
+
* `sticky-reload`: if local data exists for the specified query, such data is returned, then will try getting fresh data from the server and caching it for future need. If no local data is found, we await for a reachable server and try to get fresh data from the serve, return the data and cache it for future need. ⚠️ This overrides `disableCache` value
|
|
295
331
|
*
|
|
296
|
-
*
|
|
332
|
+
* `cache-await`: will try getting fresh data from the server if the server is reachable then cache the result for future use. In scenerio where the server is unreachable, then we check if local data exists and return it, if no local data exist we wait for a reachable server to complete the task. ⚠️ This overrides `disableCache` value
|
|
297
333
|
*
|
|
298
|
-
*
|
|
334
|
+
* `cache-no-await`: will try getting fresh data from the server if the server is reachable then cache the result for future use. In scenerio where the server is unreachable, then we check if local data exists and return it, if no local data exist an error is thrown instead. ⚠️ This overrides `disableCache` value
|
|
299
335
|
*
|
|
300
|
-
*
|
|
336
|
+
* `no-cache-no-await`: will try getting fresh data from the server and the result won't be cached. In scenerio where the server is unreachable, an error will be thrown. ⚠️ This overrides `disableCache` value
|
|
337
|
+
*
|
|
338
|
+
* `no-cache-await`: will wait for a reachable server then try getting fresh data from that server and the result won't be cache. ⚠️ This overrides `disableCache` value
|
|
301
339
|
*
|
|
302
340
|
* To learn and see more examples on this, Please visit https://brainbehindx.com/mosquito-transport/docs/reading_data/retrieval
|
|
341
|
+
*
|
|
342
|
+
* @default 'default'
|
|
303
343
|
*/
|
|
304
344
|
retrieval?: Retrieval;
|
|
305
345
|
/**
|
|
@@ -324,7 +364,7 @@ interface GetConfig {
|
|
|
324
364
|
*
|
|
325
365
|
* ```js
|
|
326
366
|
*
|
|
327
|
-
* const mserver = new RNMT({ projectUrl: 'http
|
|
367
|
+
* const mserver = new RNMT({ projectUrl: 'http://..' });
|
|
328
368
|
*
|
|
329
369
|
* // operation will be reduced to only one request
|
|
330
370
|
*
|
|
@@ -375,6 +415,7 @@ interface DocumentFind {
|
|
|
375
415
|
}
|
|
376
416
|
|
|
377
417
|
declare interface Document {
|
|
418
|
+
_id: any;
|
|
378
419
|
[key: string]: any;
|
|
379
420
|
}
|
|
380
421
|
|