mosquito-transport-js 0.2.6 → 0.2.8
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 +3 -1
- package/package.json +3 -4
- package/src/index.js +32 -30
- package/src/products/database/accessor.js +2 -1
- package/src/products/database/index.js +22 -6
package/TODO
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
- fix local cache query on sqlite and fs
|
|
2
2
|
- fix and add all mongodb query and update operator
|
|
3
3
|
- reauthenticate
|
|
4
|
-
- change `Object` in d.ts to [key: string]: any
|
|
4
|
+
- change `Object` in d.ts to [key: string]: any
|
|
5
|
+
- add `getServerTimeOffset` method
|
|
6
|
+
- change null to undefined in `value`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosquito-transport-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Javascript web sdk for mosquito-transport (https://github.com/deflexable/mosquito-transport)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"javascript",
|
|
18
18
|
"selfhosted",
|
|
19
19
|
"serverless",
|
|
20
|
-
"BaaS",
|
|
21
20
|
"database",
|
|
22
21
|
"react",
|
|
23
22
|
"mongodb"
|
|
@@ -34,7 +33,7 @@
|
|
|
34
33
|
"buffer": "^6.0.3",
|
|
35
34
|
"crypto-js": "^4.2.0",
|
|
36
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
37
|
-
"guard-object": "^1.0.
|
|
36
|
+
"guard-object": "^1.0.9",
|
|
38
37
|
"json-buffer": "^3.0.1",
|
|
39
38
|
"lodash.get": "^4.4.2",
|
|
40
39
|
"lodash.isequal": "^4.5.0",
|
|
@@ -58,4 +57,4 @@
|
|
|
58
57
|
"engines": {
|
|
59
58
|
"node": ">=14"
|
|
60
59
|
}
|
|
61
|
-
}
|
|
60
|
+
}
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { MTAuth } from "./products/auth";
|
|
|
5
5
|
import { MTCollection, batchWrite } from "./products/database";
|
|
6
6
|
import { MTStorage } from "./products/storage";
|
|
7
7
|
import { ServerReachableListener, TokenRefreshListener } from "./helpers/listeners";
|
|
8
|
-
import { initTokenRefresher, listenToken, listenTokenReady,
|
|
8
|
+
import { initTokenRefresher, listenToken, listenTokenReady, triggerAuthToken } from "./products/auth/accessor";
|
|
9
9
|
import { TIMESTAMP, DOCUMENT_EXTRACTION, FIND_GEO_JSON, GEO_JSON } from "./products/database/types";
|
|
10
10
|
import { mfetch } from "./products/http_callable";
|
|
11
11
|
import { io } from "socket.io-client";
|
|
@@ -47,41 +47,43 @@ export class MosquitoTransport {
|
|
|
47
47
|
triggerAuthToken(projectUrl);
|
|
48
48
|
initTokenRefresher({ ...this.config }, true);
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
let socket, lastUid, lastSocketProcess = 0, hasInited;
|
|
50
|
+
let isConnected, lastSentToken, queuedToken;
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
|
|
53
|
+
transports: ['websocket', 'polling', 'flashsocket'],
|
|
54
|
+
auth: {
|
|
55
|
+
_m_internal: true,
|
|
56
|
+
_from_base: true
|
|
57
|
+
}
|
|
58
|
+
});
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
lastUid = thisUid;
|
|
60
|
+
socket.on('_signal_signout', () => {
|
|
61
|
+
this.auth().signOut();
|
|
62
|
+
});
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
socket.on('connect', () => {
|
|
65
|
+
isConnected = true;
|
|
66
|
+
if (queuedToken) updateMountedToken(queuedToken.token);
|
|
67
|
+
ServerReachableListener.dispatch(projectUrl, true);
|
|
68
|
+
});
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
_m_internal: true,
|
|
69
|
-
_from_base: true,
|
|
70
|
-
atoken: token
|
|
71
|
-
}
|
|
72
|
-
});
|
|
70
|
+
socket.on('disconnect', () => {
|
|
71
|
+
isConnected = false;
|
|
72
|
+
ServerReachableListener.dispatch(projectUrl, false);
|
|
73
|
+
});
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const updateMountedToken = (token) => {
|
|
76
|
+
if ((lastSentToken || null) !== (token || null)) {
|
|
77
|
+
socket.emit('_update_mounted_user', token || null);
|
|
78
|
+
lastSentToken = token;
|
|
79
|
+
}
|
|
80
|
+
queuedToken = undefined;
|
|
81
|
+
}
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!disconnectionGlich[thisProcess])
|
|
83
|
-
ServerReachableListener.dispatch(projectUrl, false);
|
|
84
|
-
});
|
|
83
|
+
listenToken(token => {
|
|
84
|
+
if (isConnected) {
|
|
85
|
+
updateMountedToken(token);
|
|
86
|
+
} else queuedToken = { token };
|
|
85
87
|
}, projectUrl);
|
|
86
88
|
|
|
87
89
|
listenReachableServer(c => {
|
|
@@ -36,8 +36,9 @@ export const insertRecord = async (builder, accessId, query, value) => {
|
|
|
36
36
|
kaf = `${objToUniqueString(extraction || {})},${(excludeFields || []).join(',')},${(returnOnly || []).join(',')}`,
|
|
37
37
|
colData = getLodash(CacheStore.DatabaseStore, [projectUrl, dbUrl, dbName, path, 'data', kaf], []);
|
|
38
38
|
|
|
39
|
+
// TODO:
|
|
39
40
|
(Array.isArray(value) ? value : [value]).forEach(e => {
|
|
40
|
-
const b4DocIndex = colData.findIndex(v => v
|
|
41
|
+
const b4DocIndex = colData.findIndex(v => v?._id === e?._id);
|
|
41
42
|
if (b4DocIndex === -1) {
|
|
42
43
|
colData.push(e);
|
|
43
44
|
} else colData[b4DocIndex] = e;
|
|
@@ -69,8 +69,8 @@ export class MTCollection {
|
|
|
69
69
|
updateMany: (find, value) => initOnDisconnectionTask({ ...this.builder, command: { find } }, value, 'updateMany'),
|
|
70
70
|
mergeOne: (find, value) => initOnDisconnectionTask({ ...this.builder, command: { find } }, value, 'mergeOne'),
|
|
71
71
|
mergeMany: (find, value) => initOnDisconnectionTask({ ...this.builder, command: { find } }, value, 'mergeMany'),
|
|
72
|
-
deleteOne: (find) => initOnDisconnectionTask({ ...this.builder, command: { find } },
|
|
73
|
-
deleteMany: (find) => initOnDisconnectionTask({ ...this.builder, command: { find } },
|
|
72
|
+
deleteOne: (find) => initOnDisconnectionTask({ ...this.builder, command: { find } }, undefined, 'deleteOne'),
|
|
73
|
+
deleteMany: (find) => initOnDisconnectionTask({ ...this.builder, command: { find } }, undefined, 'deleteMany'),
|
|
74
74
|
replaceOne: (find, value) => initOnDisconnectionTask({ ...this.builder, command: { find } }, value, 'replaceOne'),
|
|
75
75
|
putOne: (find, value) => initOnDisconnectionTask({ ...this.builder, command: { find } }, value, 'putOne')
|
|
76
76
|
})
|
|
@@ -91,9 +91,9 @@ export class MTCollection {
|
|
|
91
91
|
|
|
92
92
|
putOne = (find, value, config) => commitData({ ...this.builder, find }, value, 'putOne', config);
|
|
93
93
|
|
|
94
|
-
deleteOne = (find, config) => commitData({ ...this.builder, find },
|
|
94
|
+
deleteOne = (find, config) => commitData({ ...this.builder, find }, undefined, 'deleteOne', config);
|
|
95
95
|
|
|
96
|
-
deleteMany = (find, config) => commitData({ ...this.builder, find },
|
|
96
|
+
deleteMany = (find, config) => commitData({ ...this.builder, find }, undefined, 'deleteMany', config);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
export const batchWrite = (builder, map, config) => commitData({ ...builder }, map, 'batchWrite', config);
|
|
@@ -150,7 +150,7 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
150
150
|
const mtoken = disableAuth ? undefined : Scoped.AuthJWTToken[projectUrl],
|
|
151
151
|
authObj = {
|
|
152
152
|
commands: {
|
|
153
|
-
config,
|
|
153
|
+
config: stripRequestConfig(config),
|
|
154
154
|
path,
|
|
155
155
|
find: findOne || find,
|
|
156
156
|
sort,
|
|
@@ -370,6 +370,14 @@ const countCollection = async (builder, config) => {
|
|
|
370
370
|
return g;
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
+
const stripRequestConfig = (config) => {
|
|
374
|
+
const known_fields = ['extraction', 'returnOnly', 'excludeFields'];
|
|
375
|
+
const requestConfig = Object.entries({ ...config }).map(([k, v]) =>
|
|
376
|
+
known_fields.includes(k) ? [k, v] : null
|
|
377
|
+
).filter(v => v);
|
|
378
|
+
return requestConfig.length ? Object.fromEntries(requestConfig) : undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
373
381
|
const findObject = async (builder, config) => {
|
|
374
382
|
const { projectUrl, serverE2E_PublicKey, dbUrl, dbName, accessKey, maxRetries = 7, path, disableCache, uglify, command } = builder,
|
|
375
383
|
{ find, findOne, sort, direction, limit, random } = command,
|
|
@@ -447,7 +455,15 @@ const findObject = async (builder, config) => {
|
|
|
447
455
|
|
|
448
456
|
const [reqBuilder, [privateKey]] = buildFetchInterface({
|
|
449
457
|
body: {
|
|
450
|
-
commands: {
|
|
458
|
+
commands: {
|
|
459
|
+
config: stripRequestConfig(config),
|
|
460
|
+
path,
|
|
461
|
+
find: findOne || find,
|
|
462
|
+
sort,
|
|
463
|
+
direction,
|
|
464
|
+
limit,
|
|
465
|
+
random
|
|
466
|
+
},
|
|
451
467
|
dbName,
|
|
452
468
|
dbUrl
|
|
453
469
|
},
|