pulse-rn 1.0.0 → 1.0.1

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.
@@ -37,16 +37,26 @@ exports.usePulseConfig = exports.PulseProvider = void 0;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const database_1 = require("./database");
39
39
  const sync_engine_1 = require("./sync-engine");
40
+ const react_query_1 = require("@tanstack/react-query");
40
41
  const PulseContext = (0, react_1.createContext)(null);
41
- const PulseProvider = ({ config, children }) => {
42
- (0, react_1.useEffect)(() => {
43
- (0, database_1.initializeDB)(config.tablesConfig);
44
- }, []);
42
+ const queryClient = new react_query_1.QueryClient();
43
+ const PulseSyncManager = ({ config }) => {
45
44
  const tableNames = Object.keys(config.tablesConfig);
46
45
  (0, sync_engine_1.usePulseSync)(config.userId, config.baseUrl, tableNames);
47
- return (<PulseContext.Provider value={config}>
48
- {children}
49
- </PulseContext.Provider>);
46
+ return null;
47
+ };
48
+ const PulseProvider = ({ config, children }) => {
49
+ (0, react_1.useEffect)(() => {
50
+ if (config.tablesConfig) {
51
+ (0, database_1.initializeDB)(config.tablesConfig);
52
+ }
53
+ }, [config.tablesConfig]);
54
+ return (<react_query_1.QueryClientProvider client={queryClient}>
55
+ <PulseContext.Provider value={config}>
56
+ <PulseSyncManager config={config}/>
57
+ {children}
58
+ </PulseContext.Provider>
59
+ </react_query_1.QueryClientProvider>);
50
60
  };
51
61
  exports.PulseProvider = PulseProvider;
52
62
  const usePulseConfig = () => {
@@ -47,7 +47,8 @@ const usePulseSync = (userId, baseUrl, tables) => {
47
47
  let ws;
48
48
  let reconnectTimeout;
49
49
  const connect = () => {
50
- ws = new WebSocket(`ws://${baseUrl}/ws/sync/`);
50
+ const cleanUrl = baseUrl.replace(/^https?:\/\//, '');
51
+ ws = new WebSocket(`ws://${cleanUrl}/ws/sync/`);
51
52
  activeSocket = ws;
52
53
  ws.onopen = () => {
53
54
  tables.forEach((tableName) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulse-rn",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Powerful offline-first sync engine for React Native. Compatible with Django Pulse and future Node.js pulse-core.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,14 @@
12
12
  "build": "tsc",
13
13
  "prepare": "npm run build"
14
14
  },
15
- "keywords": ["react-native", "expo", "sync", "offline-first", "sqlite", "pulse"],
15
+ "keywords": [
16
+ "react-native",
17
+ "expo",
18
+ "sync",
19
+ "offline-first",
20
+ "sqlite",
21
+ "pulse"
22
+ ],
16
23
  "author": "Jesus M.",
17
24
  "license": "MIT",
18
25
  "peerDependencies": {
@@ -26,4 +33,4 @@
26
33
  "@types/react-native": "^0.72.8",
27
34
  "typescript": "^5.0.0"
28
35
  }
29
- }
36
+ }