@rpcbase/client 0.394.0 → 0.396.0
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/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/initWithRoutes.d.ts.map +1 -1
- package/dist/isPlaywrightTestEnvironment.d.ts +2 -0
- package/dist/isPlaywrightTestEnvironment.d.ts.map +1 -0
- package/dist/rts/index.js +1 -1
- package/dist/rts/pouchStore.d.ts.map +1 -1
- package/dist/rts/runtimeStorage.d.ts +9 -0
- package/dist/rts/runtimeStorage.d.ts.map +1 -0
- package/dist/rts/wsClient.d.ts.map +1 -1
- package/dist/{useQuery-Q5Bygu9_.js → useQuery-RjGxHubQ.js} +164 -35
- package/dist/useQuery-RjGxHubQ.js.map +1 -0
- package/package.json +1 -1
- package/dist/useQuery-Q5Bygu9_.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initWithRoutes.d.ts","sourceRoot":"","sources":["../src/initWithRoutes.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmC,MAAM,OAAO,CAAA;AAClE,OAAO,EAEL,wBAAwB,EAIzB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"initWithRoutes.d.ts","sourceRoot":"","sources":["../src/initWithRoutes.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmC,MAAM,OAAO,CAAA;AAClE,OAAO,EAEL,wBAAwB,EAIzB,MAAM,iBAAiB,CAAA;AAUxB,OAAO,EAGL,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAsJxB,KAAK,qBAAqB,GAAG;IAC3B,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,SAAS,CAAA;CAC9D,CAAA;AAED,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAA;AA0CnE,eAAO,MAAM,cAAc,GACzB,eAAe,aAAa,EAC5B,OAAO,qBAAqB,kBA6F7B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlaywrightTestEnvironment.d.ts","sourceRoot":"","sources":["../src/isPlaywrightTestEnvironment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAO,OAM9C,CAAA"}
|
package/dist/rts/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R, S, f, p, c, h, b, d, a, i, g, n, o, q, t, v, j, k, r, l, e, s, m, u, w } from "../useQuery-
|
|
1
|
+
import { R, S, f, p, c, h, b, d, a, i, g, n, o, q, t, v, j, k, r, l, e, s, m, u, w } from "../useQuery-RjGxHubQ.js";
|
|
2
2
|
export {
|
|
3
3
|
R as RtsSsrRuntimeProvider,
|
|
4
4
|
S as STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pouchStore.d.ts","sourceRoot":"","sources":["../../src/rts/pouchStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"pouchStore.d.ts","sourceRoot":"","sources":["../../src/rts/pouchStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAW5E,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC,CAAA;IACxF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,OAAO,CA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AAC,IAAI,CAI1D,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type RuntimeStorage = {
|
|
2
|
+
getItem: (key: string) => string | null;
|
|
3
|
+
setItem: (key: string, value: string) => void;
|
|
4
|
+
removeItem: (key: string) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const isReactNativeRuntime: () => boolean;
|
|
7
|
+
export declare const getRuntimeStorage: () => RuntimeStorage;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=runtimeStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeStorage.d.ts","sourceRoot":"","sources":["../../src/rts/runtimeStorage.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACvC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC,CAAA;AA6CD,eAAO,MAAM,oBAAoB,QAAO,OAGvC,CAAA;AAsDD,eAAO,MAAM,iBAAiB,QAAO,cAYpC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../src/rts/wsClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAKtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../src/rts/wsClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAKtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;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MAAM,IAAI,CAAC,GAAG,SAkFjB,CAAA;AAID,eAAO,MAAM,eAAe,GAAU,2CAKnC;IACD,SAAS,EAAE,YAAY,CAAA;IACvB,KAAK,EAAE,UAAU,CAAA;IACjB,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAsGtD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,UAAU,OAAO,KAAG,IAE9D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAU1F,CAAA"}
|
|
@@ -124,11 +124,97 @@ const RtsSsrRuntimeProvider = (t0) => {
|
|
|
124
124
|
const useRtsSsrRuntime = () => {
|
|
125
125
|
return useContext(RtsSsrRuntimeContext);
|
|
126
126
|
};
|
|
127
|
+
const memoryStore = /* @__PURE__ */ new Map();
|
|
128
|
+
let reactNativeStorage = null;
|
|
129
|
+
const MMKV_STORAGE_ID = "rpcbase-rts";
|
|
130
|
+
const memoryStorage = {
|
|
131
|
+
getItem: (key) => memoryStore.get(key) ?? null,
|
|
132
|
+
setItem: (key, value) => {
|
|
133
|
+
memoryStore.set(key, String(value));
|
|
134
|
+
},
|
|
135
|
+
removeItem: (key) => {
|
|
136
|
+
memoryStore.delete(key);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const asRuntimeStorage = (value) => {
|
|
140
|
+
if (!value || typeof value !== "object") return null;
|
|
141
|
+
const candidate = value;
|
|
142
|
+
if (typeof candidate.getItem !== "function" || typeof candidate.setItem !== "function" || typeof candidate.removeItem !== "function") {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
getItem: candidate.getItem.bind(value),
|
|
147
|
+
setItem: candidate.setItem.bind(value),
|
|
148
|
+
removeItem: candidate.removeItem.bind(value)
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const isReactNativeRuntime = () => {
|
|
152
|
+
if (typeof navigator === "undefined") return false;
|
|
153
|
+
return navigator.product === "ReactNative";
|
|
154
|
+
};
|
|
155
|
+
const getRuntimeRequire = () => {
|
|
156
|
+
const globalRequire = globalThis.require;
|
|
157
|
+
if (typeof globalRequire === "function") {
|
|
158
|
+
return globalRequire;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
return (0, eval)("require");
|
|
162
|
+
} catch {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const getReactNativeStorage = () => {
|
|
167
|
+
if (reactNativeStorage) return reactNativeStorage;
|
|
168
|
+
const runtimeRequire = getRuntimeRequire();
|
|
169
|
+
if (!runtimeRequire) {
|
|
170
|
+
throw new Error("RTS storage: react-native-mmkv is required in React Native runtime");
|
|
171
|
+
}
|
|
172
|
+
let mmkvModule;
|
|
173
|
+
try {
|
|
174
|
+
mmkvModule = runtimeRequire("react-native-mmkv");
|
|
175
|
+
} catch (error) {
|
|
176
|
+
const runtimeError = error instanceof Error ? ` ${error.message}` : "";
|
|
177
|
+
throw new Error(`RTS storage: react-native-mmkv is required in React Native runtime.${runtimeError}`);
|
|
178
|
+
}
|
|
179
|
+
const MMKV = mmkvModule.MMKV;
|
|
180
|
+
if (typeof MMKV !== "function") {
|
|
181
|
+
throw new Error("RTS storage: invalid react-native-mmkv module shape");
|
|
182
|
+
}
|
|
183
|
+
const mmkv = new MMKV({
|
|
184
|
+
id: MMKV_STORAGE_ID
|
|
185
|
+
});
|
|
186
|
+
reactNativeStorage = {
|
|
187
|
+
getItem: (key) => {
|
|
188
|
+
const value = mmkv.getString(key);
|
|
189
|
+
return typeof value === "string" ? value : null;
|
|
190
|
+
},
|
|
191
|
+
setItem: (key, value) => {
|
|
192
|
+
mmkv.set(key, String(value));
|
|
193
|
+
},
|
|
194
|
+
removeItem: (key) => {
|
|
195
|
+
mmkv.delete(key);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return reactNativeStorage;
|
|
199
|
+
};
|
|
200
|
+
const getRuntimeStorage = () => {
|
|
201
|
+
if (isReactNativeRuntime()) {
|
|
202
|
+
return getReactNativeStorage();
|
|
203
|
+
}
|
|
204
|
+
const direct = asRuntimeStorage(globalThis.localStorage);
|
|
205
|
+
if (direct) return direct;
|
|
206
|
+
const windowStorage = asRuntimeStorage(globalThis.window?.localStorage);
|
|
207
|
+
if (windowStorage) return windowStorage;
|
|
208
|
+
return memoryStorage;
|
|
209
|
+
};
|
|
127
210
|
const UNDERSCORE_PREFIX = "$_";
|
|
128
211
|
const DEFAULT_FIND_LIMIT = 4096;
|
|
212
|
+
const INDEXED_DB_ADAPTER = "indexeddb";
|
|
213
|
+
const REACT_NATIVE_SQLITE_ADAPTER = "react-native-sqlite";
|
|
129
214
|
let storeConfig = null;
|
|
130
215
|
let pouchDbPromise = null;
|
|
131
216
|
let lastAppliedPrefix = null;
|
|
217
|
+
let activePouchAdapter = INDEXED_DB_ADAPTER;
|
|
132
218
|
const collections = /* @__PURE__ */ new Map();
|
|
133
219
|
const dbNamesByPrefix = /* @__PURE__ */ new Map();
|
|
134
220
|
const unwrapDefault = (mod) => {
|
|
@@ -136,11 +222,6 @@ const unwrapDefault = (mod) => {
|
|
|
136
222
|
const maybe = mod;
|
|
137
223
|
return maybe.default ?? mod;
|
|
138
224
|
};
|
|
139
|
-
const ensureBrowser$1 = () => {
|
|
140
|
-
if (typeof window === "undefined") {
|
|
141
|
-
throw new Error("RTS PouchDB store can only be used in the browser");
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
225
|
const computeBasePrefix = ({
|
|
145
226
|
tenantId,
|
|
146
227
|
appName
|
|
@@ -159,8 +240,9 @@ const readPrefixOverride = ({
|
|
|
159
240
|
tenantId,
|
|
160
241
|
appName
|
|
161
242
|
}) => {
|
|
243
|
+
const storage = getRuntimeStorage();
|
|
162
244
|
try {
|
|
163
|
-
const value =
|
|
245
|
+
const value = storage.getItem(getPrefixOverrideKey({
|
|
164
246
|
tenantId,
|
|
165
247
|
appName
|
|
166
248
|
}));
|
|
@@ -190,8 +272,9 @@ const loadDbNames = (prefix) => {
|
|
|
190
272
|
const existing = dbNamesByPrefix.get(prefix);
|
|
191
273
|
if (existing) return existing;
|
|
192
274
|
const names = /* @__PURE__ */ new Set();
|
|
275
|
+
const storage = getRuntimeStorage();
|
|
193
276
|
try {
|
|
194
|
-
const raw =
|
|
277
|
+
const raw = storage.getItem(getDbNamesKey(prefix));
|
|
195
278
|
if (raw) {
|
|
196
279
|
const parsed = JSON.parse(raw);
|
|
197
280
|
if (Array.isArray(parsed)) {
|
|
@@ -207,13 +290,14 @@ const loadDbNames = (prefix) => {
|
|
|
207
290
|
return names;
|
|
208
291
|
};
|
|
209
292
|
const persistDbNames = (prefix, names) => {
|
|
293
|
+
const storage = getRuntimeStorage();
|
|
210
294
|
try {
|
|
211
295
|
if (!names.size) {
|
|
212
|
-
|
|
296
|
+
storage.removeItem(getDbNamesKey(prefix));
|
|
213
297
|
dbNamesByPrefix.delete(prefix);
|
|
214
298
|
return;
|
|
215
299
|
}
|
|
216
|
-
|
|
300
|
+
storage.setItem(getDbNamesKey(prefix), JSON.stringify(Array.from(names)));
|
|
217
301
|
dbNamesByPrefix.set(prefix, names);
|
|
218
302
|
} catch {
|
|
219
303
|
return;
|
|
@@ -233,12 +317,29 @@ const unregisterDbName = (prefix, dbName) => {
|
|
|
233
317
|
persistDbNames(prefix, names);
|
|
234
318
|
};
|
|
235
319
|
const getPouchDb = async () => {
|
|
236
|
-
ensureBrowser$1();
|
|
237
320
|
if (!pouchDbPromise) {
|
|
238
321
|
pouchDbPromise = (async () => {
|
|
239
|
-
const [core,
|
|
322
|
+
const [core, findPlugin] = await Promise.all([import("pouchdb-core"), import("pouchdb-find")]);
|
|
240
323
|
const PouchDB = unwrapDefault(core);
|
|
241
|
-
|
|
324
|
+
if (isReactNativeRuntime()) {
|
|
325
|
+
const moduleName = "pouchdb-adapter-react-native-sqlite";
|
|
326
|
+
let sqliteAdapterModule;
|
|
327
|
+
try {
|
|
328
|
+
sqliteAdapterModule = await import(
|
|
329
|
+
/* @vite-ignore */
|
|
330
|
+
moduleName
|
|
331
|
+
);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
const runtimeError = error instanceof Error ? ` ${error.message}` : "";
|
|
334
|
+
throw new Error(`RTS PouchDB: missing react-native sqlite adapter. Install \`pouchdb-adapter-react-native-sqlite\` in the app.${runtimeError}`);
|
|
335
|
+
}
|
|
336
|
+
PouchDB.plugin(unwrapDefault(sqliteAdapterModule));
|
|
337
|
+
activePouchAdapter = REACT_NATIVE_SQLITE_ADAPTER;
|
|
338
|
+
} else {
|
|
339
|
+
const indexedDbAdapter = await import("pouchdb-adapter-indexeddb");
|
|
340
|
+
PouchDB.plugin(unwrapDefault(indexedDbAdapter));
|
|
341
|
+
activePouchAdapter = INDEXED_DB_ADAPTER;
|
|
342
|
+
}
|
|
242
343
|
PouchDB.plugin(unwrapDefault(findPlugin));
|
|
243
344
|
return PouchDB;
|
|
244
345
|
})();
|
|
@@ -266,7 +367,7 @@ const getCollection = async (modelName, options) => {
|
|
|
266
367
|
if (existing) return existing;
|
|
267
368
|
registerDbName(prefix, dbName);
|
|
268
369
|
const db = new PouchDB(dbName, {
|
|
269
|
-
adapter:
|
|
370
|
+
adapter: activePouchAdapter,
|
|
270
371
|
revs_limit: 1
|
|
271
372
|
});
|
|
272
373
|
collections.set(dbKey, db);
|
|
@@ -843,7 +944,6 @@ const resetRtsPouchStore = ({
|
|
|
843
944
|
tenantId,
|
|
844
945
|
appName
|
|
845
946
|
}) => {
|
|
846
|
-
ensureBrowser$1();
|
|
847
947
|
const basePrefix = computeBasePrefix({
|
|
848
948
|
tenantId,
|
|
849
949
|
appName
|
|
@@ -864,7 +964,7 @@ const resetRtsPouchStore = ({
|
|
|
864
964
|
PouchDBForPrefix.prefix = oldPrefix;
|
|
865
965
|
await Promise.all(Array.from(remaining).map(async (name) => {
|
|
866
966
|
const db = new PouchDBForPrefix(name, {
|
|
867
|
-
adapter:
|
|
967
|
+
adapter: activePouchAdapter,
|
|
868
968
|
revs_limit: 1
|
|
869
969
|
});
|
|
870
970
|
await db.destroy().then(() => {
|
|
@@ -880,8 +980,9 @@ const resetRtsPouchStore = ({
|
|
|
880
980
|
}
|
|
881
981
|
})();
|
|
882
982
|
const newPrefix = `${basePrefix}reset-${Date.now().toString(16)}/`;
|
|
983
|
+
const storage = getRuntimeStorage();
|
|
883
984
|
try {
|
|
884
|
-
|
|
985
|
+
storage.setItem(getPrefixOverrideKey({
|
|
885
986
|
tenantId,
|
|
886
987
|
appName
|
|
887
988
|
}), newPrefix);
|
|
@@ -1080,10 +1181,34 @@ let hasEstablishedConnection = false;
|
|
|
1080
1181
|
let pendingServerReconnectJitter = false;
|
|
1081
1182
|
let syncPromise = null;
|
|
1082
1183
|
let syncKey = null;
|
|
1083
|
-
const
|
|
1084
|
-
if (typeof
|
|
1085
|
-
throw new Error("RTS websocket client
|
|
1184
|
+
const ensureRealtimeRuntime = () => {
|
|
1185
|
+
if (typeof WebSocket !== "function") {
|
|
1186
|
+
throw new Error("RTS websocket client requires WebSocket support");
|
|
1086
1187
|
}
|
|
1188
|
+
if (typeof globalThis.setTimeout !== "function" || typeof globalThis.clearTimeout !== "function") {
|
|
1189
|
+
throw new Error("RTS websocket client requires timer support");
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
const ensureSyncRuntime = () => {
|
|
1193
|
+
if (typeof fetch !== "function") {
|
|
1194
|
+
throw new Error("syncRtsChanges requires fetch support");
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
const getRuntimeLocationHref = () => {
|
|
1198
|
+
if (typeof window !== "undefined" && typeof window.location?.href === "string" && window.location.href) {
|
|
1199
|
+
return window.location.href;
|
|
1200
|
+
}
|
|
1201
|
+
const location = globalThis.location;
|
|
1202
|
+
if (typeof location?.href === "string" && location.href) {
|
|
1203
|
+
return location.href;
|
|
1204
|
+
}
|
|
1205
|
+
return null;
|
|
1206
|
+
};
|
|
1207
|
+
const setRuntimeTimeout = (handler, delayMs) => {
|
|
1208
|
+
return globalThis.setTimeout(handler, delayMs);
|
|
1209
|
+
};
|
|
1210
|
+
const clearRuntimeTimeout = (timer) => {
|
|
1211
|
+
globalThis.clearTimeout(timer);
|
|
1087
1212
|
};
|
|
1088
1213
|
const buildSocketUrl = (tenantId, _uid, options) => {
|
|
1089
1214
|
if (options.url) {
|
|
@@ -1091,7 +1216,11 @@ const buildSocketUrl = (tenantId, _uid, options) => {
|
|
|
1091
1216
|
url.searchParams.set(TENANT_ID_QUERY_PARAM, tenantId);
|
|
1092
1217
|
return url.toString();
|
|
1093
1218
|
}
|
|
1094
|
-
const
|
|
1219
|
+
const locationHref = getRuntimeLocationHref();
|
|
1220
|
+
if (!locationHref) {
|
|
1221
|
+
throw new Error("connect: options.url is required when location.href is unavailable");
|
|
1222
|
+
}
|
|
1223
|
+
const base = new URL(locationHref);
|
|
1095
1224
|
base.protocol = base.protocol === "https:" ? "wss:" : "ws:";
|
|
1096
1225
|
base.pathname = options.path ?? "/rts";
|
|
1097
1226
|
base.search = "";
|
|
@@ -1121,9 +1250,7 @@ const resubscribeAll = ({
|
|
|
1121
1250
|
};
|
|
1122
1251
|
const clearReconnectTimer = () => {
|
|
1123
1252
|
if (reconnectTimer === null) return;
|
|
1124
|
-
|
|
1125
|
-
window.clearTimeout(reconnectTimer);
|
|
1126
|
-
}
|
|
1253
|
+
clearRuntimeTimeout(reconnectTimer);
|
|
1127
1254
|
reconnectTimer = null;
|
|
1128
1255
|
};
|
|
1129
1256
|
const scheduleReconnect = () => {
|
|
@@ -1145,7 +1272,7 @@ const scheduleReconnect = () => {
|
|
|
1145
1272
|
pendingServerReconnectJitter = false;
|
|
1146
1273
|
}
|
|
1147
1274
|
reconnectAttempts += 1;
|
|
1148
|
-
reconnectTimer =
|
|
1275
|
+
reconnectTimer = setRuntimeTimeout(() => {
|
|
1149
1276
|
void connectInternal(currentTenantId, currentUid, connectOptions, {
|
|
1150
1277
|
resetReconnectAttempts: false
|
|
1151
1278
|
});
|
|
@@ -1264,8 +1391,9 @@ const getSyncStorageKey = ({
|
|
|
1264
1391
|
appName
|
|
1265
1392
|
}) => `rb:rts:changesSeq:${appName ?? ""}:${tenantId}:${uid}`;
|
|
1266
1393
|
const readStoredSeq = (key) => {
|
|
1394
|
+
const storage = getRuntimeStorage();
|
|
1267
1395
|
try {
|
|
1268
|
-
const raw =
|
|
1396
|
+
const raw = storage.getItem(key);
|
|
1269
1397
|
const num = raw ? Number(raw) : 0;
|
|
1270
1398
|
return Number.isFinite(num) && num >= 0 ? Math.floor(num) : 0;
|
|
1271
1399
|
} catch {
|
|
@@ -1273,8 +1401,9 @@ const readStoredSeq = (key) => {
|
|
|
1273
1401
|
}
|
|
1274
1402
|
};
|
|
1275
1403
|
const writeStoredSeq = (key, value) => {
|
|
1404
|
+
const storage = getRuntimeStorage();
|
|
1276
1405
|
try {
|
|
1277
|
-
|
|
1406
|
+
storage.setItem(key, String(Math.max(0, Math.floor(value))));
|
|
1278
1407
|
} catch {
|
|
1279
1408
|
return;
|
|
1280
1409
|
}
|
|
@@ -1308,7 +1437,7 @@ const applyChangeBatch = async (changes, uid) => {
|
|
|
1308
1437
|
}
|
|
1309
1438
|
};
|
|
1310
1439
|
const syncRtsChanges = async (tenantId, uid, options = {}) => {
|
|
1311
|
-
|
|
1440
|
+
ensureSyncRuntime();
|
|
1312
1441
|
if (!tenantId || !uid) return;
|
|
1313
1442
|
const storageKey = getSyncStorageKey({
|
|
1314
1443
|
tenantId,
|
|
@@ -1393,7 +1522,7 @@ const ensureSynced = (tenantId, uid, options) => {
|
|
|
1393
1522
|
const connectInternal = (tenantId, uid, options, {
|
|
1394
1523
|
resetReconnectAttempts
|
|
1395
1524
|
}) => {
|
|
1396
|
-
|
|
1525
|
+
ensureRealtimeRuntime();
|
|
1397
1526
|
if (!tenantId) return Promise.resolve();
|
|
1398
1527
|
if (!uid) throw new Error("Missing uid");
|
|
1399
1528
|
currentTenantId = tenantId;
|
|
@@ -1606,14 +1735,14 @@ const runNetworkQuery = async ({
|
|
|
1606
1735
|
});
|
|
1607
1736
|
if (hasTimeout) {
|
|
1608
1737
|
await new Promise((resolve, reject) => {
|
|
1609
|
-
const timeoutId =
|
|
1738
|
+
const timeoutId = setRuntimeTimeout(() => {
|
|
1610
1739
|
reject(new Error(RUN_NETWORK_QUERY_TIMEOUT_ERROR));
|
|
1611
1740
|
}, timeoutMs);
|
|
1612
1741
|
connectAttempt.then(() => {
|
|
1613
|
-
|
|
1742
|
+
clearRuntimeTimeout(timeoutId);
|
|
1614
1743
|
resolve();
|
|
1615
1744
|
}, (error) => {
|
|
1616
|
-
|
|
1745
|
+
clearRuntimeTimeout(timeoutId);
|
|
1617
1746
|
reject(error);
|
|
1618
1747
|
});
|
|
1619
1748
|
});
|
|
@@ -1647,8 +1776,8 @@ const runNetworkQuery = async ({
|
|
|
1647
1776
|
const callbacks2 = queryCallbacks.get(cbKey);
|
|
1648
1777
|
callbacks2?.delete(callback);
|
|
1649
1778
|
if (callbacks2 && callbacks2.size === 0) queryCallbacks.delete(cbKey);
|
|
1650
|
-
if (timeoutId !== null
|
|
1651
|
-
|
|
1779
|
+
if (timeoutId !== null) {
|
|
1780
|
+
clearRuntimeTimeout(timeoutId);
|
|
1652
1781
|
}
|
|
1653
1782
|
};
|
|
1654
1783
|
const settle = (next) => {
|
|
@@ -1671,7 +1800,7 @@ const runNetworkQuery = async ({
|
|
|
1671
1800
|
callbacks.add(callback);
|
|
1672
1801
|
queryCallbacks.set(cbKey, callbacks);
|
|
1673
1802
|
if (remainingTimeoutMs !== null) {
|
|
1674
|
-
timeoutId =
|
|
1803
|
+
timeoutId = setRuntimeTimeout(() => {
|
|
1675
1804
|
settle(() => reject(new Error(RUN_NETWORK_QUERY_TIMEOUT_ERROR)));
|
|
1676
1805
|
}, remainingTimeoutMs);
|
|
1677
1806
|
}
|
|
@@ -2134,4 +2263,4 @@ export {
|
|
|
2134
2263
|
peekHydratedRtsQueryTotalCount as v,
|
|
2135
2264
|
useQuery as w
|
|
2136
2265
|
};
|
|
2137
|
-
//# sourceMappingURL=useQuery-
|
|
2266
|
+
//# sourceMappingURL=useQuery-RjGxHubQ.js.map
|