react-native-mosquito-transport 0.0.17 → 0.0.19

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
@@ -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`
@@ -354,7 +354,6 @@
354
354
  );
355
355
  name = "[CP] Copy Pods Resources";
356
356
  outputFileListPaths = (
357
- "${PODS_ROOT}/Target Support Files/Pods-MosquitodbExample/Pods-MosquitodbExample-resources-${CONFIGURATION}-output-files.xcfilelist",
358
357
  );
359
358
  runOnlyForDeploymentPostprocessing = 0;
360
359
  shellPath = /bin/sh;
@@ -501,7 +500,7 @@
501
500
  PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
502
501
  PRODUCT_NAME = MosquitodbExample;
503
502
  SWIFT_OPTIMIZATION_LEVEL = "-Onone";
504
- SWIFT_VERSION = 5.0;
503
+ SWIFT_VERSION = 5.3;
505
504
  VERSIONING_SYSTEM = "apple-generic";
506
505
  };
507
506
  name = Debug;
@@ -526,7 +525,7 @@
526
525
  );
527
526
  PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
528
527
  PRODUCT_NAME = MosquitodbExample;
529
- SWIFT_VERSION = 5.0;
528
+ SWIFT_VERSION = 5.3;
530
529
  VERSIONING_SYSTEM = "apple-generic";
531
530
  };
532
531
  name = Release;
@@ -564,7 +563,7 @@
564
563
  COPY_PHASE_STRIP = NO;
565
564
  ENABLE_STRICT_OBJC_MSGSEND = YES;
566
565
  ENABLE_TESTABILITY = YES;
567
- "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
566
+ "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
568
567
  GCC_C_LANGUAGE_STANDARD = gnu99;
569
568
  GCC_DYNAMIC_NO_PIC = NO;
570
569
  GCC_NO_COMMON_BLOCKS = YES;
@@ -598,6 +597,7 @@
598
597
  "-DFOLLY_MOBILE=1",
599
598
  "-DFOLLY_USE_LIBCPP=1",
600
599
  );
600
+ REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
601
601
  SDKROOT = iphoneos;
602
602
  };
603
603
  name = Debug;
@@ -635,7 +635,7 @@
635
635
  COPY_PHASE_STRIP = YES;
636
636
  ENABLE_NS_ASSERTIONS = NO;
637
637
  ENABLE_STRICT_OBJC_MSGSEND = YES;
638
- "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
638
+ "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
639
639
  GCC_C_LANGUAGE_STANDARD = gnu99;
640
640
  GCC_NO_COMMON_BLOCKS = YES;
641
641
  GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -661,6 +661,7 @@
661
661
  "-DFOLLY_MOBILE=1",
662
662
  "-DFOLLY_USE_LIBCPP=1",
663
663
  );
664
+ REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
664
665
  SDKROOT = iphoneos;
665
666
  VALIDATE_PRODUCT = YES;
666
667
  };
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "group:MosquitodbExample.xcodeproj">
6
+ </FileRef>
7
+ <FileRef
8
+ location = "group:Pods/Pods.xcodeproj">
9
+ </FileRef>
10
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>PreviewsEnabled</key>
6
+ <false/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>BuildLocationStyle</key>
6
+ <string>UseAppPreferences</string>
7
+ <key>CustomBuildLocationType</key>
8
+ <string>RelativeToDerivedData</string>
9
+ <key>DerivedDataLocationStyle</key>
10
+ <string>Default</string>
11
+ <key>ShowSharedSchemesAutomaticallyEnabled</key>
12
+ <true/>
13
+ </dict>
14
+ </plist>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mosquito-transport",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "React native javascript sdk for mosquito-transport (https://github.com/deflexable/mosquito-transport)",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -15,7 +15,6 @@
15
15
  "javascript",
16
16
  "selfhosted",
17
17
  "serverless",
18
- "Baas",
19
18
  "database",
20
19
  "react-native",
21
20
  "mongodb"
@@ -32,7 +31,7 @@
32
31
  "buffer": "^6.0.3",
33
32
  "crypto-js": "^4.2.0",
34
33
  "fast-json-stable-stringify": "^2.1.0",
35
- "guard-object": "^1.0.6",
34
+ "guard-object": "^1.0.9",
36
35
  "json-buffer": "^3.0.1",
37
36
  "lodash.get": "^4.4.2",
38
37
  "lodash.isequal": "^4.5.0",
@@ -44,7 +43,8 @@
44
43
  "subscription-listener": "^1.1.2",
45
44
  "tweetnacl": "^1.0.3"
46
45
  },
47
- "engines": {
48
- "node": ">= 16.0.0"
46
+ "peerDependencies": {
47
+ "react": "*",
48
+ "react-native": "*"
49
49
  }
50
- }
50
+ }
package/src/index.js CHANGED
@@ -6,7 +6,7 @@ import { MTAuth } from "./products/auth";
6
6
  import { MTCollection, batchWrite } from "./products/database";
7
7
  import { MTStorage } from "./products/storage";
8
8
  import { ServerReachableListener, TokenRefreshListener } from "./helpers/listeners";
9
- import { initTokenRefresher, listenToken, listenTokenReady, parseToken, triggerAuthToken } from "./products/auth/accessor";
9
+ import { initTokenRefresher, listenToken, listenTokenReady, triggerAuthToken } from "./products/auth/accessor";
10
10
  import { TIMESTAMP, DOCUMENT_EXTRACTION, FIND_GEO_JSON, GEO_JSON } from "./products/database/types";
11
11
  import { mfetch } from "./products/http_callable";
12
12
  import { io } from "socket.io-client";
@@ -48,40 +48,42 @@ class RNMT {
48
48
  triggerAuthToken(projectUrl);
49
49
  initTokenRefresher({ ...this.config }, true);
50
50
 
51
- const disconnectionGlich = {};
52
- let socket, lastUid, lastSocketProcess = 0, hasInited;
51
+ let isConnected, lastSentToken, queuedToken;
53
52
 
54
- listenToken((token, thisInited) => {
55
- const user = token && parseToken(token);
53
+ const socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
54
+ auth: {
55
+ _m_internal: true,
56
+ _from_base: true
57
+ }
58
+ });
56
59
 
57
- const thisUid = (user?.uid || null);
58
- if (lastUid === thisUid && (hasInited || !thisInited)) return;
59
- if (!hasInited) hasInited = thisInited;
60
- lastUid = thisUid;
60
+ socket.on('_signal_signout', () => {
61
+ this.auth().signOut();
62
+ });
61
63
 
62
- if (lastSocketProcess) disconnectionGlich[lastSocketProcess] = true;
63
- if (socket) socket.close();
64
+ socket.on('connect', () => {
65
+ isConnected = true;
66
+ if (queuedToken) updateMountedToken(queuedToken.token);
67
+ ServerReachableListener.dispatch(projectUrl, true);
68
+ });
64
69
 
65
- const thisProcess = ++lastSocketProcess;
66
- socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
67
- auth: {
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
- socket.on('_signal_signout', () => {
75
- this.auth().signOut();
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
- socket.on('connect', () => {
79
- ServerReachableListener.dispatch(projectUrl, true);
80
- });
81
- socket.on('disconnect', () => {
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._id === e._id);
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 } }, null, 'deleteOne'),
73
- deleteMany: (find) => initOnDisconnectionTask({ ...this.builder, command: { find } }, null, 'deleteMany'),
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 }, null, 'deleteOne', config);
94
+ deleteOne = (find, config) => commitData({ ...this.builder, find }, undefined, 'deleteOne', config);
95
95
 
96
- deleteMany = (find, config) => commitData({ ...this.builder, find }, null, 'deleteMany', config);
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,
@@ -368,6 +368,14 @@ const countCollection = async (builder, config) => {
368
368
  return g;
369
369
  }
370
370
 
371
+ const stripRequestConfig = (config) => {
372
+ const known_fields = ['extraction', 'returnOnly', 'excludeFields'];
373
+ const requestConfig = Object.entries({ ...config }).map(([k, v]) =>
374
+ known_fields.includes(k) ? [k, v] : null
375
+ ).filter(v => v);
376
+ return requestConfig.length ? Object.fromEntries(requestConfig) : undefined;
377
+ }
378
+
371
379
  const findObject = async (builder, config) => {
372
380
  const { projectUrl, serverE2E_PublicKey, dbUrl, dbName, accessKey, maxRetries = 7, path, disableCache, uglify, command } = builder,
373
381
  { find, findOne, sort, direction, limit, random } = command,
@@ -445,7 +453,15 @@ const findObject = async (builder, config) => {
445
453
 
446
454
  const [reqBuilder, [privateKey]] = buildFetchInterface({
447
455
  body: {
448
- commands: { config, path, find: findOne || find, sort, direction, limit, random },
456
+ commands: {
457
+ config: stripRequestConfig(config),
458
+ path,
459
+ find: findOne || find,
460
+ sort,
461
+ direction,
462
+ limit,
463
+ random
464
+ },
449
465
  dbName,
450
466
  dbUrl
451
467
  },