react-native-mosquito-transport 0.0.14
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/CODE_OF_CONDUCT.md +133 -0
- package/CONTRIBUTING.md +114 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/mosquitodb/MosquitodbModule.java +32 -0
- package/android/src/main/java/com/mosquitodb/MosquitodbPackage.java +28 -0
- package/example/.bundle/config +2 -0
- package/example/.node-version +1 -0
- package/example/.watchmanconfig +1 -0
- package/example/Gemfile +6 -0
- package/example/android/app/build.gradle +170 -0
- package/example/android/app/debug.keystore +0 -0
- package/example/android/app/proguard-rules.pro +10 -0
- package/example/android/app/src/debug/AndroidManifest.xml +13 -0
- package/example/android/app/src/debug/java/com/mosquitodbexample/ReactNativeFlipper.java +75 -0
- package/example/android/app/src/main/AndroidManifest.xml +25 -0
- package/example/android/app/src/main/java/com/mosquitodbexample/MainActivity.java +35 -0
- package/example/android/app/src/main/java/com/mosquitodbexample/MainApplication.java +62 -0
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +3 -0
- package/example/android/app/src/main/res/values/styles.xml +9 -0
- package/example/android/app/src/release/java/com/mosquitodbexample/ReactNativeFlipper.java +20 -0
- package/example/android/build.gradle +21 -0
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/example/android/gradle.properties +44 -0
- package/example/android/gradlew +234 -0
- package/example/android/gradlew.bat +89 -0
- package/example/android/settings.gradle +4 -0
- package/example/app.json +4 -0
- package/example/babel.config.js +17 -0
- package/example/index.js +5 -0
- package/example/ios/.xcode.env +11 -0
- package/example/ios/File.swift +6 -0
- package/example/ios/MosquitodbExample/AppDelegate.h +6 -0
- package/example/ios/MosquitodbExample/AppDelegate.mm +36 -0
- package/example/ios/MosquitodbExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/example/ios/MosquitodbExample/Images.xcassets/Contents.json +6 -0
- package/example/ios/MosquitodbExample/Info.plist +55 -0
- package/example/ios/MosquitodbExample/LaunchScreen.storyboard +47 -0
- package/example/ios/MosquitodbExample/main.m +10 -0
- package/example/ios/MosquitodbExample-Bridging-Header.h +3 -0
- package/example/ios/MosquitodbExample.xcodeproj/project.pbxproj +702 -0
- package/example/ios/MosquitodbExample.xcodeproj/xcshareddata/xcschemes/MosquitodbExample.xcscheme +88 -0
- package/example/ios/MosquitodbExampleTests/Info.plist +24 -0
- package/example/ios/MosquitodbExampleTests/MosquitodbExampleTests.m +66 -0
- package/example/ios/Podfile +60 -0
- package/example/metro.config.js +40 -0
- package/example/package.json +22 -0
- package/example/react-native.config.js +10 -0
- package/example/src/App.tsx +31 -0
- package/ios/Mosquitodb-Bridging-Header.h +2 -0
- package/ios/Mosquitodb.m +22 -0
- package/ios/Mosquitodb.swift +305 -0
- package/ios/Mosquitodb.xcodeproj/project.pbxproj +283 -0
- package/package.json +45 -0
- package/react-native-mosquitodb.podspec +35 -0
- package/src/helpers/EngineApi.js +34 -0
- package/src/helpers/listeners.js +7 -0
- package/src/helpers/peripherals.js +195 -0
- package/src/helpers/utils.js +113 -0
- package/src/helpers/values.js +72 -0
- package/src/helpers/variables.js +34 -0
- package/src/index.d.ts +373 -0
- package/src/index.js +369 -0
- package/src/products/auth/accessor.js +151 -0
- package/src/products/auth/index.js +279 -0
- package/src/products/database/accessor.js +316 -0
- package/src/products/database/index.js +603 -0
- package/src/products/database/types.js +22 -0
- package/src/products/database/validator.js +282 -0
- package/src/products/http_callable/index.js +230 -0
- package/src/products/storage/index.js +217 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
import { ServerReachableListener, StoreReadyListener } from "./listeners";
|
|
3
|
+
import { CACHE_PROTOCOL, CACHE_STORAGE_PATH, DEFAULT_CACHE_PASSWORD, LOCAL_STORAGE_PATH } from "./values";
|
|
4
|
+
import { CacheStore, Scoped } from "./variables";
|
|
5
|
+
import { decryptString, encryptString, niceTry, serializeE2E } from "./peripherals";
|
|
6
|
+
|
|
7
|
+
export const updateCacheStore = () => {
|
|
8
|
+
const { cachePassword = DEFAULT_CACHE_PASSWORD, cacheProtocol = CACHE_PROTOCOL.ASYNC_STORAGE } = Scoped.ReleaseCacheData;
|
|
9
|
+
|
|
10
|
+
clearTimeout(Scoped.cacheStorageReducer);
|
|
11
|
+
Scoped.cacheStorageReducer = setTimeout(() => {
|
|
12
|
+
const txt = encryptString(
|
|
13
|
+
JSON.stringify({ ...CacheStore }),
|
|
14
|
+
cachePassword,
|
|
15
|
+
cachePassword
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (cacheProtocol === CACHE_PROTOCOL.ASYNC_STORAGE) {
|
|
19
|
+
AsyncStorage.setItem(CACHE_STORAGE_PATH, txt);
|
|
20
|
+
} else {
|
|
21
|
+
const fs = require('react-native-fs');
|
|
22
|
+
fs.writeFile(LOCAL_STORAGE_PATH(), txt, 'utf8');
|
|
23
|
+
}
|
|
24
|
+
}, 500);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const releaseCacheStore = async (builder) => {
|
|
28
|
+
const { cachePassword = DEFAULT_CACHE_PASSWORD, cacheProtocol = CACHE_PROTOCOL.ASYNC_STORAGE } = builder;
|
|
29
|
+
|
|
30
|
+
let txt;
|
|
31
|
+
|
|
32
|
+
if (cacheProtocol === CACHE_PROTOCOL.ASYNC_STORAGE) {
|
|
33
|
+
txt = await niceTry(() => AsyncStorage.getItem(CACHE_STORAGE_PATH));
|
|
34
|
+
} else {
|
|
35
|
+
const fs = require('react-native-fs');
|
|
36
|
+
txt = await niceTry(() => fs.readFile(LOCAL_STORAGE_PATH(), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const j = JSON.parse(decryptString(txt || '', cachePassword, cachePassword) || '{}');
|
|
40
|
+
|
|
41
|
+
Object.entries(j).forEach(([k, v]) => {
|
|
42
|
+
CacheStore[k] = v;
|
|
43
|
+
});
|
|
44
|
+
Object.entries(CacheStore.AuthStore).forEach(([key, value]) => {
|
|
45
|
+
Scoped.AuthJWTToken[key] = value?.token;
|
|
46
|
+
});
|
|
47
|
+
Scoped.IsStoreReady = true;
|
|
48
|
+
StoreReadyListener.dispatch('_', 'ready');
|
|
49
|
+
// TODO: commit pending write
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const awaitStore = () => new Promise(resolve => {
|
|
53
|
+
if (Scoped.IsStoreReady) {
|
|
54
|
+
resolve();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const l = StoreReadyListener.listenTo('_', t => {
|
|
58
|
+
if (t === 'ready') {
|
|
59
|
+
resolve();
|
|
60
|
+
l();
|
|
61
|
+
}
|
|
62
|
+
}, true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const awaitReachableServer = (projectUrl) => new Promise(resolve => {
|
|
66
|
+
if (Scoped.IS_CONNECTED[projectUrl]) {
|
|
67
|
+
resolve();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const l = ServerReachableListener.listenTo(projectUrl, t => {
|
|
71
|
+
if (t) {
|
|
72
|
+
resolve();
|
|
73
|
+
l();
|
|
74
|
+
}
|
|
75
|
+
}, true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const getReachableServer = (projectUrl) => new Promise(resolve => {
|
|
79
|
+
if (typeof Scoped.IS_CONNECTED[projectUrl] === 'boolean') {
|
|
80
|
+
resolve(Scoped.IS_CONNECTED[projectUrl]);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const l = ServerReachableListener.listenTo(projectUrl, t => {
|
|
84
|
+
if (typeof t === 'boolean') {
|
|
85
|
+
resolve(t);
|
|
86
|
+
l();
|
|
87
|
+
}
|
|
88
|
+
}, true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const buildFetchInterface = ({ body, accessKey, authToken, method, uglify, serverE2E_PublicKey }) => {
|
|
92
|
+
if (!uglify) body = JSON.stringify({ ...body });
|
|
93
|
+
const [plate, keyPair] = uglify ? serializeE2E(body, authToken, serverE2E_PublicKey) : [undefined, []];
|
|
94
|
+
|
|
95
|
+
return [{
|
|
96
|
+
body: uglify ? plate : body,
|
|
97
|
+
cache: 'no-cache',
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-type': uglify ? 'text/plain' : 'application/json',
|
|
100
|
+
'Authorization': accessKey,
|
|
101
|
+
...((authToken && !uglify) ? { 'Mosquito-Token': authToken } : {})
|
|
102
|
+
},
|
|
103
|
+
method: method || 'POST'
|
|
104
|
+
}, keyPair];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const simplifyError = (error, message) => ({
|
|
108
|
+
simpleError: { error, message }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export const validateRequestMethod = (method) => {
|
|
112
|
+
// TODO:
|
|
113
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
DEFAULT_DB_NAME = 'DEFAULT_DB',
|
|
11
|
+
DEFAULT_DB_URL = 'mongodb://127.0.0.1:27017',
|
|
12
|
+
DEFAULT_ENCRYPT_IV = '****';
|
|
13
|
+
|
|
14
|
+
export const CACHE_PROTOCOL = {
|
|
15
|
+
ASYNC_STORAGE: 'async-storage',
|
|
16
|
+
REACT_NATIVE_FS: 'reat-native-fs'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const RETRIEVAL = {
|
|
20
|
+
STICKY: 'sticky',
|
|
21
|
+
STICKY_NO_AWAIT: 'sticky-no-await',
|
|
22
|
+
STICKY_RELOAD: 'sticky-reload',
|
|
23
|
+
DEFAULT: 'default',
|
|
24
|
+
CACHE_NO_AWAIT: 'cache-no-await',
|
|
25
|
+
NO_CACHE_NO_AWAIT: 'no-cache-no-await'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const DELIVERY = {
|
|
29
|
+
DEFAULT: 'default',
|
|
30
|
+
NO_CACHE: 'no-cache',
|
|
31
|
+
NO_AWAIT: 'no-await',
|
|
32
|
+
NO_AWAIT_NO_CACHE: 'no-await-no-cache',
|
|
33
|
+
AWAIT_NO_CACHE: 'await-no-cache',
|
|
34
|
+
CACHE_NO_AWAIT: 'cache-no-await'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const WRITE_OPS = {
|
|
38
|
+
$SET: '$set',
|
|
39
|
+
$PUSH: '$push',
|
|
40
|
+
$PULL: '$pull',
|
|
41
|
+
$UNSET: '$unset',
|
|
42
|
+
$INC: '$inc',
|
|
43
|
+
$MAX: '$max',
|
|
44
|
+
$MIN: '$min',
|
|
45
|
+
$MUL: '$mul',
|
|
46
|
+
$RENAME: '$rename'
|
|
47
|
+
// $SET_ON_INSERT: '$setOnInsert'
|
|
48
|
+
};
|
|
49
|
+
export const WRITE_OPS_LIST = Object.values(WRITE_OPS);
|
|
50
|
+
|
|
51
|
+
export const READ_OPS = {
|
|
52
|
+
$IN: '$in',
|
|
53
|
+
$ALL: '$all',
|
|
54
|
+
$NIN: '$nin',
|
|
55
|
+
$GT: '$gt',
|
|
56
|
+
$GTE: '$gte',
|
|
57
|
+
$LT: '$lt',
|
|
58
|
+
$LTE: '$lte',
|
|
59
|
+
$TEXT: '$text',
|
|
60
|
+
// $EQ: '$eq',
|
|
61
|
+
// $REGEX: '$regex',
|
|
62
|
+
// $EXISTS: '$exists',
|
|
63
|
+
$NEAR: '$near',
|
|
64
|
+
$TYPE: '$type',
|
|
65
|
+
$SIZE: '$size',
|
|
66
|
+
// $NE: '$ne'
|
|
67
|
+
};
|
|
68
|
+
export const READ_OPS_LIST = Object.values(READ_OPS);
|
|
69
|
+
|
|
70
|
+
export const Regexs = {
|
|
71
|
+
LINK: () => /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
|
|
72
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const Scoped = {
|
|
2
|
+
PendingIte: 0,
|
|
3
|
+
AnyProcessIte: 0,
|
|
4
|
+
IS_CONNECTED: {},
|
|
5
|
+
IS_TOKEN_READY: {},
|
|
6
|
+
InitializedProject: {},
|
|
7
|
+
ReleaseCacheData: undefined,
|
|
8
|
+
AuthJWTToken: {},
|
|
9
|
+
cacheStorageReducer: undefined,
|
|
10
|
+
IsStoreReady: false,
|
|
11
|
+
TokenRefreshTimer: {},
|
|
12
|
+
LastTokenRefreshRef: {},
|
|
13
|
+
StorageProcessID: 0,
|
|
14
|
+
InitiatedForcedToken: {},
|
|
15
|
+
PendingFetchCollective: {
|
|
16
|
+
pendingProcess: {},
|
|
17
|
+
pendingResolution: {}
|
|
18
|
+
},
|
|
19
|
+
PendingDbReadCollective: {
|
|
20
|
+
pendingProcess: {},
|
|
21
|
+
pendingResolution: {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const CacheStore = {
|
|
26
|
+
DatabaseStore: {},
|
|
27
|
+
DatabaseRecords: {},
|
|
28
|
+
DatabaseCountResult: {},
|
|
29
|
+
AuthStore: {},
|
|
30
|
+
PendingWrites: {},
|
|
31
|
+
FetchedStore: {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const CacheConstant = { ...CacheStore };
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
interface RNMTConfig {
|
|
2
|
+
dbName?: string;
|
|
3
|
+
dbUrl?: string;
|
|
4
|
+
heapMemory?: number;
|
|
5
|
+
projectUrl: string;
|
|
6
|
+
disableCache?: boolean;
|
|
7
|
+
accessKey: string;
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
/**
|
|
10
|
+
* setting this to true will encrypt all outgoing and incoming request. This enables end-to-end encryption using [Tweetnacl](https://github.com/dchest/tweetnacl-js) and to prevent request interception by browser extensions, network intermediaries or other hijacking tools
|
|
11
|
+
*/
|
|
12
|
+
enableE2E_Encryption?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* this is the base64 public key for end-to-end encryption on the server
|
|
15
|
+
*/
|
|
16
|
+
serverE2E_PublicKey?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface GetDatabase {
|
|
20
|
+
collection: (path: string) => RNMTCollection;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface mtimestamp { $timestamp: 'now' }
|
|
24
|
+
|
|
25
|
+
export const TIMESTAMP: mtimestamp;
|
|
26
|
+
export function DOCUMENT_EXTRACTION(path: string): { $dynamicValue: number };
|
|
27
|
+
|
|
28
|
+
interface ReleaseCacheOption {
|
|
29
|
+
/**
|
|
30
|
+
* This password will be used to securely store your data locally
|
|
31
|
+
*/
|
|
32
|
+
cachePassword?: string;
|
|
33
|
+
/**
|
|
34
|
+
* select the mechanism for storing data locally
|
|
35
|
+
* - async-storage: uses [@react-native-async-storage/async-storage](https://github.com/react-native-async-storage/async-storage) for storing data, make sure you have this package installed before setting this as the value
|
|
36
|
+
* - reat-native-fs: uses [reat-native-fs](https://github.com/itinance/react-native-fs) for storing data, make sure you have this package installed before setting this as the value
|
|
37
|
+
*/
|
|
38
|
+
cacheProtocol?: 'async-storage' | 'reat-native-fs';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface RNMTSocket {
|
|
42
|
+
timeout: (timeout?: number) => ({
|
|
43
|
+
emitWithAck: (...args: any) => Promise<any>;
|
|
44
|
+
});
|
|
45
|
+
emit: (...args: any) => void;
|
|
46
|
+
emitWithAck: () => Promise<any>;
|
|
47
|
+
on: (route: string, callback?: () => any) => void;
|
|
48
|
+
once: (route: string, callback?: () => any) => void;
|
|
49
|
+
destroy: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BatchWriteValue {
|
|
53
|
+
scope: 'setOne' | 'setMany' | 'updateOne' | 'mergeOne' | 'deleteOne' | 'deleteMany' | 'replaceOne' | 'putOne';
|
|
54
|
+
find?: DocumentFind;
|
|
55
|
+
value?: DocumentWriteValue[] | DocumentWriteValue;
|
|
56
|
+
path: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface BatchWriteConfig extends WriteConfig {
|
|
60
|
+
stepping?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default class RNMT {
|
|
64
|
+
constructor(config: RNMTConfig);
|
|
65
|
+
static releaseCache(option?: ReleaseCacheOption): void;
|
|
66
|
+
getDatabase(dbName?: string, dbUrl?: string): GetDatabase;
|
|
67
|
+
collection(path: string): RNMTCollection;
|
|
68
|
+
auth(): RNMTAuth;
|
|
69
|
+
storage(): RNMTStorage;
|
|
70
|
+
fetchHttp(endpoint: string, init?: RequestInit, config?: FetchHttpConfig): Promise<Response>;
|
|
71
|
+
listenReachableServer(callback: (reachable: boolean) => void): () => void;
|
|
72
|
+
getSocket(options: { disableAuth?: boolean; authHandshake?: Object }): RNMTSocket;
|
|
73
|
+
batchWrite(map: BatchWriteValue[], config?: BatchWriteConfig): Promise<DocumentWriteResult[] | undefined>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface RNMTCollection {
|
|
77
|
+
find: (find?: DocumentFind) => ({
|
|
78
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
79
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
80
|
+
count: () => Promise<number>;
|
|
81
|
+
limit: (limit: number) => ({
|
|
82
|
+
random: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
83
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
84
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
85
|
+
sort: (sort: Sort | string, direction?: SortDirection) => ({
|
|
86
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
87
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
sort: (sort: Sort | string, direction?: SortDirection) => ({
|
|
91
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
92
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
93
|
+
limit: (limit: number) => ({
|
|
94
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
95
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
sort: (sort: Sort | string, direction?: SortDirection) => ({
|
|
100
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
101
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
102
|
+
limit: (limit: number) => ({
|
|
103
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
104
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
limit: (limit: number) => ({
|
|
108
|
+
random: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
109
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
110
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
111
|
+
sort: (sort: Sort | string, direction?: SortDirection) => ({
|
|
112
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
113
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
count: () => Promise<number>;
|
|
117
|
+
get: (config?: GetConfig) => Promise<DocumentResult[]>;
|
|
118
|
+
listen: (callback: (snapshot?: DocumentResult[]) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
119
|
+
findOne: (findOne?: DocumentFind) => ({
|
|
120
|
+
get: (config?: GetConfig) => Promise<DocumentResult>;
|
|
121
|
+
listen: (callback: (snapshot?: DocumentResult) => void, onError?: (error?: DocumentError) => void, config?: GetConfig) => void;
|
|
122
|
+
});
|
|
123
|
+
onDisconnect: () => ({
|
|
124
|
+
setOne: (value: DocumentWriteValue) => () => void;
|
|
125
|
+
setMany: (value: DocumentWriteValue[]) => () => void;
|
|
126
|
+
updateOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
127
|
+
updateMany: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
128
|
+
mergeOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
129
|
+
mergeMany: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
130
|
+
replaceOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
131
|
+
putOne: (find: DocumentFind, value: DocumentWriteValue) => () => void;
|
|
132
|
+
deleteOne: (find: DocumentFind) => () => void;
|
|
133
|
+
deleteMany: (find?: DocumentFind) => () => void;
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
setOne: (value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
137
|
+
|
|
138
|
+
setMany: (value: DocumentWriteValue[], config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
139
|
+
|
|
140
|
+
updateOne: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
141
|
+
|
|
142
|
+
updateMany: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
143
|
+
|
|
144
|
+
mergeOne: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
145
|
+
|
|
146
|
+
mergeMany: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
147
|
+
|
|
148
|
+
replaceOne: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
149
|
+
|
|
150
|
+
putOne: (find: DocumentFind, value: DocumentWriteValue, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
151
|
+
|
|
152
|
+
deleteOne: (find?: DocumentFind, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
153
|
+
|
|
154
|
+
deleteMany: (find?: DocumentFind, config?: WriteConfig) => Promise<DocumentWriteResult>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface DocumentResult {
|
|
158
|
+
_id: any
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface DocumentError extends ErrorResponse {
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface FetchHttpConfig {
|
|
166
|
+
retrieval?: GetConfig['retrieval'];
|
|
167
|
+
disableAuth?: boolean;
|
|
168
|
+
enableMinimizer?: boolean;
|
|
169
|
+
rawApproach?: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type Delievery = 'default' | 'no-cache' | 'no-await' | 'no-await-no-cache' | 'await-no-cache' | 'cache-no-await';
|
|
173
|
+
|
|
174
|
+
interface WriteConfig {
|
|
175
|
+
/**
|
|
176
|
+
* send authentication token along with this request
|
|
177
|
+
*/
|
|
178
|
+
disableAuth?: boolean;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* This property defines how the write will be committed and sent
|
|
182
|
+
*
|
|
183
|
+
* - default:
|
|
184
|
+
* - no-cache:
|
|
185
|
+
* - no-await:
|
|
186
|
+
* - no-await-no-cache:
|
|
187
|
+
* - await-no-cache:
|
|
188
|
+
* - cache-no-await:
|
|
189
|
+
*/
|
|
190
|
+
delivery?: Delievery;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type Retrieval = 'sticky' | 'sticky-no-await' | 'sticky-reload' | 'default' | 'cache-no-await' | 'no-cache-no-await';
|
|
194
|
+
|
|
195
|
+
interface GetConfig {
|
|
196
|
+
excludeFields?: string | string[];
|
|
197
|
+
returnOnly?: string | string[];
|
|
198
|
+
extraction?: GetConfigExtraction | GetConfigExtraction[];
|
|
199
|
+
/**
|
|
200
|
+
* This property determines how requested data is being access and handled
|
|
201
|
+
*
|
|
202
|
+
* - default: we try getting fresh data from server if server is reachable, else we check if local data exists and return it, if no local data exist we await for client->server connectivity, then try getting the data, return it and cache it for future need. ⚠️ This respect disableCache value
|
|
203
|
+
*
|
|
204
|
+
* - 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 does not respect disableCache value
|
|
205
|
+
*
|
|
206
|
+
* - sticky-no-await: if local data exists for the specified query, such data is returned and no-ops afterwards. If no local data is found, we try to get fresh data from serve, we throw an error if server is not reachable else if server returns requested data, we return such data and cache it for future need. ⚠️ This does not respect disableCache value
|
|
207
|
+
*
|
|
208
|
+
* - sticky-reload: if local data exists for the specified query, such data is returned, then we try getting fresh data from the server and caching it for future need. 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
|
|
209
|
+
*
|
|
210
|
+
* - cache-no-await: we try getting fresh data from server if server is reachable, else we check if local data exists and return it, if no local data exist we throw an error
|
|
211
|
+
*
|
|
212
|
+
* - no-cache-no-await: we try getting fresh data from server if server is reachable, else we throw an error
|
|
213
|
+
*
|
|
214
|
+
* To learn and see more examples on this, Please visit https://brainbehindx.com/mosquito-transport/docs/reading_data/retrieval
|
|
215
|
+
*/
|
|
216
|
+
retrieval?: Retrieval;
|
|
217
|
+
/**
|
|
218
|
+
* - 0: returns data that may have been internally updated locally with updateOne, updateMany, mergeOne, deleteOne, deleteMany, putOne, replaceOne
|
|
219
|
+
* - 1: returns exact data which was cached in the last query process
|
|
220
|
+
*
|
|
221
|
+
* @defaults - 0
|
|
222
|
+
*
|
|
223
|
+
* To learn and see more examples on this, Please visit https://brainbehindx.com/mosquito-transport/docs/reading_data/retrieval
|
|
224
|
+
*/
|
|
225
|
+
episode?: 0 | 1;
|
|
226
|
+
/**
|
|
227
|
+
* send authentication token along with this request
|
|
228
|
+
*
|
|
229
|
+
* @default - false
|
|
230
|
+
*/
|
|
231
|
+
disableAuth?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* this reduces duplicate query calls with the same operation resultant to a single request call.
|
|
234
|
+
*
|
|
235
|
+
* - Example:
|
|
236
|
+
*
|
|
237
|
+
* ```js
|
|
238
|
+
*
|
|
239
|
+
* const mserver = new RNMT({ projectUrl: 'http..', accessKey: '..'});
|
|
240
|
+
* const minimizedUser = ['james', 'john', 'james', 'john'];
|
|
241
|
+
* const unminimizedUser = ['anthony', 'albert', 'anthony', 'albert'];
|
|
242
|
+
*
|
|
243
|
+
* // operation will be reduced to two request: james and john
|
|
244
|
+
*
|
|
245
|
+
* minimizedUser.forEach(e=> {
|
|
246
|
+
* mserver.collection('user').findOne({ _id: e }).get();
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* // operation will not be reduced and therefore four request will be sent: anthony, albert, anthony, albert
|
|
250
|
+
*
|
|
251
|
+
* unminimizedUser.forEach(e=> {
|
|
252
|
+
* mserver.collection('user').findOne({ _id: e }).get();
|
|
253
|
+
* });
|
|
254
|
+
* ```
|
|
255
|
+
* defaults to false
|
|
256
|
+
*
|
|
257
|
+
* To learn and see more examples on this, Please visit https://brainbehindx.com/mosquito-transport/docs/reading_data/retrieval
|
|
258
|
+
*/
|
|
259
|
+
disableMinimizer?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
interface GetConfigExtraction {
|
|
263
|
+
limit?: number;
|
|
264
|
+
sort: string;
|
|
265
|
+
direction?: 'desc' | 'asc' | 1 | -1
|
|
266
|
+
collection: string;
|
|
267
|
+
find?: DocumentFind;
|
|
268
|
+
findOne?: DocumentFind
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface DocumentFind {
|
|
272
|
+
$and?: any[];
|
|
273
|
+
$nor?: any[];
|
|
274
|
+
$or?: any[];
|
|
275
|
+
$text?: {
|
|
276
|
+
$search: string;
|
|
277
|
+
$language?: string;
|
|
278
|
+
$caseSensitive?: boolean;
|
|
279
|
+
$diacriticSensitive?: boolean;
|
|
280
|
+
};
|
|
281
|
+
// $where?: string | ((this: TSchema) => boolean);
|
|
282
|
+
$comment?: string | Document;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
declare interface Document {
|
|
286
|
+
[key: string]: any;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface DocumentWriteResult { }
|
|
290
|
+
|
|
291
|
+
interface DocumentWriteValue {
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface RNMTAuth {
|
|
296
|
+
customSignin: (email: string, password: string) => Promise<SigninResult>;
|
|
297
|
+
customSignup: (email: string, password: string, name?: string, metadata?: Object) => Promise<SigninResult>;
|
|
298
|
+
googleSignin: (token: string) => Promise<SignupResult>;
|
|
299
|
+
appleSignin: () => Promise<SignupResult>;
|
|
300
|
+
facebookSignin: () => Promise<SignupResult>;
|
|
301
|
+
twitterSignin: () => Promise<SignupResult>;
|
|
302
|
+
githubSignin: () => Promise<SignupResult>;
|
|
303
|
+
listenVerifiedStatus: (callback?: (verified?: boolean) => void, onError?: (error?: ErrorResponse) => void) => () => void;
|
|
304
|
+
listenAuthToken: (callback: (token: string) => void) => () => void;
|
|
305
|
+
getAuthToken: () => Promise<string>;
|
|
306
|
+
listenAuth: (callback: (auth: AuthData) => void) => () => void;
|
|
307
|
+
getAuth: () => Promise<AuthData>;
|
|
308
|
+
signOut: () => Promise<void>;
|
|
309
|
+
forceRefreshToken: () => Promise<string>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
interface SigninResult {
|
|
313
|
+
user: AuthData;
|
|
314
|
+
token: string;
|
|
315
|
+
refreshToken: string;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
interface SignupResult extends SigninResult {
|
|
319
|
+
isNewUser: boolean;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
interface AuthData {
|
|
323
|
+
email?: string;
|
|
324
|
+
metadata: Object;
|
|
325
|
+
signupMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
|
|
326
|
+
currentAuthMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
|
|
327
|
+
joinedOn: number;
|
|
328
|
+
encryptionKey: string;
|
|
329
|
+
uid: string;
|
|
330
|
+
claims: Object;
|
|
331
|
+
emailVerified: boolean;
|
|
332
|
+
profile: {
|
|
333
|
+
photo: string;
|
|
334
|
+
name: string;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface RNMTStorage {
|
|
339
|
+
downloadFile: (link: string, onComplete?: (error?: ErrorResponse, filepath?: string) => void, destination?: string, onProgress?: (stats: DownloadProgressStats) => void) => () => void;
|
|
340
|
+
uploadFile: (file: string, destination: string, onComplete?: (error?: ErrorResponse, downloadUrl?: string) => void, onProgress?: (stats: UploadProgressStats) => void) => () => void;
|
|
341
|
+
deleteFile: (path: string) => Promise<void>;
|
|
342
|
+
deleteFolder: (folder: string) => Promise<void>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface DownloadProgressStats {
|
|
346
|
+
receivedBtyes: number;
|
|
347
|
+
expectedBytes: number;
|
|
348
|
+
isPaused: boolean;
|
|
349
|
+
pause: () => void;
|
|
350
|
+
resume: () => void;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
interface UploadProgressStats {
|
|
354
|
+
sentBtyes: number;
|
|
355
|
+
totalBytes: number;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface ErrorResponse {
|
|
359
|
+
error: string;
|
|
360
|
+
message: string;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** @public */
|
|
364
|
+
export declare type Sort = string | Exclude<SortDirection, {
|
|
365
|
+
$meta: string;
|
|
366
|
+
}> | string[] | {
|
|
367
|
+
[key: string]: SortDirection;
|
|
368
|
+
} | Map<string, SortDirection> | [string, SortDirection][] | [string, SortDirection];
|
|
369
|
+
|
|
370
|
+
/** @public */
|
|
371
|
+
export declare type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending' | {
|
|
372
|
+
$meta: string;
|
|
373
|
+
};
|