@rpcbase/client 0.395.0 → 0.397.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 +2 -2
- 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 +1 -1
- package/dist/rts/wsClient.d.ts.map +1 -1
- package/dist/{useQuery-Q5Bygu9_.js → useQuery-XvXbEwG_.js} +215 -40
- package/dist/useQuery-XvXbEwG_.js.map +1 -0
- package/package.json +1 -1
- package/dist/useQuery-Q5Bygu9_.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import { getNavigationGuards, createRoutesFromElements, createBrowserRouter, Rou
|
|
|
6
6
|
import { hydrateRoot } from "react-dom/client";
|
|
7
7
|
import { r as reportClientException } from "./errorReporting-CVoUUKxW.js";
|
|
8
8
|
import { s } from "./errorReporting-CVoUUKxW.js";
|
|
9
|
-
import { n as hydrateRtsFromWindow, w as useQuery } from "./useQuery-
|
|
10
|
-
import { R, S, p, q, t, v } from "./useQuery-
|
|
9
|
+
import { n as hydrateRtsFromWindow, w as useQuery } from "./useQuery-XvXbEwG_.js";
|
|
10
|
+
import { R, S, p, q, t, v } from "./useQuery-XvXbEwG_.js";
|
|
11
11
|
const emptyUnsubscribe = () => {
|
|
12
12
|
};
|
|
13
13
|
const useMediaQuery = (query) => {
|
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-XvXbEwG_.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,CAAC,OAAO,CAAC,CAAA;IAC/D,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,E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C,IAAI,EAAE,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,CAyCrE,CAAA;AAED,eAAO,MAAM,UAAU,GACrB,WAAW,MAAM,EACjB,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,EACtD,KAAK,MAAM,KACV,OAAO,CAAC,IAAI,CAqCd,CAAA;AAED,eAAO,MAAM,UAAU,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,IAAI,CAsB5F,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,IAAI,CAOpF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,uBAAuB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,MA4ClG,CAAA;AAED,eAAO,MAAM,qBAAqB,QAAa,OAAO,CAAC,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"}
|
package/dist/rts/wsClient.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export type RtsConnectOptions = {
|
|
|
46
46
|
};
|
|
47
47
|
type QueryCallback = (error: unknown | null, data: unknown, context: RtsQueryContext) => void;
|
|
48
48
|
export declare const addLocalTxn: (txnId: string) => void;
|
|
49
|
-
export declare const syncRtsChanges: (tenantId: string, uid: string, options?: Pick<RtsConnectOptions, "appName">) => Promise<void>;
|
|
49
|
+
export declare const syncRtsChanges: (tenantId: string, uid: string, options?: Pick<RtsConnectOptions, "appName" | "url">) => Promise<void>;
|
|
50
50
|
export declare const connect: (tenantId: string, uid: string, options?: RtsConnectOptions) => Promise<void>;
|
|
51
51
|
export declare const disconnect: () => void;
|
|
52
52
|
export declare const reconnect: (tenantId: string, uid: string, options?: RtsConnectOptions) => Promise<void>;
|
|
@@ -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;AAKhD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,E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,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);
|
|
@@ -1059,7 +1160,7 @@ const computeRtsQueryKey = (query, options) => {
|
|
|
1059
1160
|
return `${key}${JSON.stringify(query)}${projection}${sort}${limit}${populate}${pagination}`;
|
|
1060
1161
|
};
|
|
1061
1162
|
const TENANT_ID_QUERY_PARAM = "rb-tenant-id";
|
|
1062
|
-
const
|
|
1163
|
+
const RTS_CHANGES_PATH = "/api/rb/rts/changes";
|
|
1063
1164
|
const MAX_TXN_BUF = 2048;
|
|
1064
1165
|
const SERVER_RECONNECT_DELAY_MIN_MS = 1e4;
|
|
1065
1166
|
const SERVER_RECONNECT_DELAY_MAX_MS = 15e3;
|
|
@@ -1080,18 +1181,89 @@ 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");
|
|
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);
|
|
1212
|
+
};
|
|
1213
|
+
const resolveWebSocketUrlFromCandidate = (candidateUrl, options) => {
|
|
1214
|
+
const url = new URL(candidateUrl);
|
|
1215
|
+
if (url.protocol === "http:") {
|
|
1216
|
+
url.protocol = "ws:";
|
|
1217
|
+
} else if (url.protocol === "https:") {
|
|
1218
|
+
url.protocol = "wss:";
|
|
1086
1219
|
}
|
|
1220
|
+
if (!url.pathname || url.pathname === "/") {
|
|
1221
|
+
url.pathname = options.path ?? "/rts";
|
|
1222
|
+
}
|
|
1223
|
+
return url;
|
|
1224
|
+
};
|
|
1225
|
+
const resolveApiOriginUrl = ({
|
|
1226
|
+
url
|
|
1227
|
+
}) => {
|
|
1228
|
+
if (url) {
|
|
1229
|
+
const base2 = new URL(url);
|
|
1230
|
+
if (base2.protocol === "ws:") {
|
|
1231
|
+
base2.protocol = "http:";
|
|
1232
|
+
} else if (base2.protocol === "wss:") {
|
|
1233
|
+
base2.protocol = "https:";
|
|
1234
|
+
}
|
|
1235
|
+
base2.pathname = "/";
|
|
1236
|
+
base2.search = "";
|
|
1237
|
+
base2.hash = "";
|
|
1238
|
+
return base2;
|
|
1239
|
+
}
|
|
1240
|
+
const locationHref = getRuntimeLocationHref();
|
|
1241
|
+
if (!locationHref) {
|
|
1242
|
+
throw new Error("syncRtsChanges: options.url is required when location.href is unavailable");
|
|
1243
|
+
}
|
|
1244
|
+
const base = new URL(locationHref);
|
|
1245
|
+
base.pathname = "/";
|
|
1246
|
+
base.search = "";
|
|
1247
|
+
base.hash = "";
|
|
1248
|
+
return base;
|
|
1249
|
+
};
|
|
1250
|
+
const buildSyncChangesUrl = (tenantId, options) => {
|
|
1251
|
+
const base = resolveApiOriginUrl(options);
|
|
1252
|
+
const url = new URL(RTS_CHANGES_PATH, base);
|
|
1253
|
+
url.searchParams.set(TENANT_ID_QUERY_PARAM, tenantId);
|
|
1254
|
+
return url.toString();
|
|
1087
1255
|
};
|
|
1088
1256
|
const buildSocketUrl = (tenantId, _uid, options) => {
|
|
1089
1257
|
if (options.url) {
|
|
1090
|
-
const url =
|
|
1258
|
+
const url = resolveWebSocketUrlFromCandidate(options.url, options);
|
|
1091
1259
|
url.searchParams.set(TENANT_ID_QUERY_PARAM, tenantId);
|
|
1092
1260
|
return url.toString();
|
|
1093
1261
|
}
|
|
1094
|
-
const
|
|
1262
|
+
const locationHref = getRuntimeLocationHref();
|
|
1263
|
+
if (!locationHref) {
|
|
1264
|
+
throw new Error("connect: options.url is required when location.href is unavailable");
|
|
1265
|
+
}
|
|
1266
|
+
const base = new URL(locationHref);
|
|
1095
1267
|
base.protocol = base.protocol === "https:" ? "wss:" : "ws:";
|
|
1096
1268
|
base.pathname = options.path ?? "/rts";
|
|
1097
1269
|
base.search = "";
|
|
@@ -1121,9 +1293,7 @@ const resubscribeAll = ({
|
|
|
1121
1293
|
};
|
|
1122
1294
|
const clearReconnectTimer = () => {
|
|
1123
1295
|
if (reconnectTimer === null) return;
|
|
1124
|
-
|
|
1125
|
-
window.clearTimeout(reconnectTimer);
|
|
1126
|
-
}
|
|
1296
|
+
clearRuntimeTimeout(reconnectTimer);
|
|
1127
1297
|
reconnectTimer = null;
|
|
1128
1298
|
};
|
|
1129
1299
|
const scheduleReconnect = () => {
|
|
@@ -1145,7 +1315,7 @@ const scheduleReconnect = () => {
|
|
|
1145
1315
|
pendingServerReconnectJitter = false;
|
|
1146
1316
|
}
|
|
1147
1317
|
reconnectAttempts += 1;
|
|
1148
|
-
reconnectTimer =
|
|
1318
|
+
reconnectTimer = setRuntimeTimeout(() => {
|
|
1149
1319
|
void connectInternal(currentTenantId, currentUid, connectOptions, {
|
|
1150
1320
|
resetReconnectAttempts: false
|
|
1151
1321
|
});
|
|
@@ -1264,8 +1434,9 @@ const getSyncStorageKey = ({
|
|
|
1264
1434
|
appName
|
|
1265
1435
|
}) => `rb:rts:changesSeq:${appName ?? ""}:${tenantId}:${uid}`;
|
|
1266
1436
|
const readStoredSeq = (key) => {
|
|
1437
|
+
const storage = getRuntimeStorage();
|
|
1267
1438
|
try {
|
|
1268
|
-
const raw =
|
|
1439
|
+
const raw = storage.getItem(key);
|
|
1269
1440
|
const num = raw ? Number(raw) : 0;
|
|
1270
1441
|
return Number.isFinite(num) && num >= 0 ? Math.floor(num) : 0;
|
|
1271
1442
|
} catch {
|
|
@@ -1273,8 +1444,9 @@ const readStoredSeq = (key) => {
|
|
|
1273
1444
|
}
|
|
1274
1445
|
};
|
|
1275
1446
|
const writeStoredSeq = (key, value) => {
|
|
1447
|
+
const storage = getRuntimeStorage();
|
|
1276
1448
|
try {
|
|
1277
|
-
|
|
1449
|
+
storage.setItem(key, String(Math.max(0, Math.floor(value))));
|
|
1278
1450
|
} catch {
|
|
1279
1451
|
return;
|
|
1280
1452
|
}
|
|
@@ -1308,7 +1480,7 @@ const applyChangeBatch = async (changes, uid) => {
|
|
|
1308
1480
|
}
|
|
1309
1481
|
};
|
|
1310
1482
|
const syncRtsChanges = async (tenantId, uid, options = {}) => {
|
|
1311
|
-
|
|
1483
|
+
ensureSyncRuntime();
|
|
1312
1484
|
if (!tenantId || !uid) return;
|
|
1313
1485
|
const storageKey = getSyncStorageKey({
|
|
1314
1486
|
tenantId,
|
|
@@ -1316,9 +1488,11 @@ const syncRtsChanges = async (tenantId, uid, options = {}) => {
|
|
|
1316
1488
|
appName: options.appName
|
|
1317
1489
|
});
|
|
1318
1490
|
let sinceSeq = readStoredSeq(storageKey);
|
|
1491
|
+
const syncUrl = buildSyncChangesUrl(tenantId, {
|
|
1492
|
+
url: options.url
|
|
1493
|
+
});
|
|
1319
1494
|
for (let i = 0; i < 32; i += 1) {
|
|
1320
|
-
const
|
|
1321
|
-
const response = await fetch(url, {
|
|
1495
|
+
const response = await fetch(syncUrl, {
|
|
1322
1496
|
method: "POST",
|
|
1323
1497
|
credentials: "include",
|
|
1324
1498
|
headers: {
|
|
@@ -1382,7 +1556,8 @@ const ensureSynced = (tenantId, uid, options) => {
|
|
|
1382
1556
|
if (syncPromise && syncKey === key) return;
|
|
1383
1557
|
syncKey = key;
|
|
1384
1558
|
syncPromise = syncRtsChanges(tenantId, uid, {
|
|
1385
|
-
appName: options.appName
|
|
1559
|
+
appName: options.appName,
|
|
1560
|
+
url: options.url
|
|
1386
1561
|
}).catch(() => {
|
|
1387
1562
|
}).finally(() => {
|
|
1388
1563
|
if (syncKey === key) {
|
|
@@ -1393,7 +1568,7 @@ const ensureSynced = (tenantId, uid, options) => {
|
|
|
1393
1568
|
const connectInternal = (tenantId, uid, options, {
|
|
1394
1569
|
resetReconnectAttempts
|
|
1395
1570
|
}) => {
|
|
1396
|
-
|
|
1571
|
+
ensureRealtimeRuntime();
|
|
1397
1572
|
if (!tenantId) return Promise.resolve();
|
|
1398
1573
|
if (!uid) throw new Error("Missing uid");
|
|
1399
1574
|
currentTenantId = tenantId;
|
|
@@ -1606,14 +1781,14 @@ const runNetworkQuery = async ({
|
|
|
1606
1781
|
});
|
|
1607
1782
|
if (hasTimeout) {
|
|
1608
1783
|
await new Promise((resolve, reject) => {
|
|
1609
|
-
const timeoutId =
|
|
1784
|
+
const timeoutId = setRuntimeTimeout(() => {
|
|
1610
1785
|
reject(new Error(RUN_NETWORK_QUERY_TIMEOUT_ERROR));
|
|
1611
1786
|
}, timeoutMs);
|
|
1612
1787
|
connectAttempt.then(() => {
|
|
1613
|
-
|
|
1788
|
+
clearRuntimeTimeout(timeoutId);
|
|
1614
1789
|
resolve();
|
|
1615
1790
|
}, (error) => {
|
|
1616
|
-
|
|
1791
|
+
clearRuntimeTimeout(timeoutId);
|
|
1617
1792
|
reject(error);
|
|
1618
1793
|
});
|
|
1619
1794
|
});
|
|
@@ -1647,8 +1822,8 @@ const runNetworkQuery = async ({
|
|
|
1647
1822
|
const callbacks2 = queryCallbacks.get(cbKey);
|
|
1648
1823
|
callbacks2?.delete(callback);
|
|
1649
1824
|
if (callbacks2 && callbacks2.size === 0) queryCallbacks.delete(cbKey);
|
|
1650
|
-
if (timeoutId !== null
|
|
1651
|
-
|
|
1825
|
+
if (timeoutId !== null) {
|
|
1826
|
+
clearRuntimeTimeout(timeoutId);
|
|
1652
1827
|
}
|
|
1653
1828
|
};
|
|
1654
1829
|
const settle = (next) => {
|
|
@@ -1671,7 +1846,7 @@ const runNetworkQuery = async ({
|
|
|
1671
1846
|
callbacks.add(callback);
|
|
1672
1847
|
queryCallbacks.set(cbKey, callbacks);
|
|
1673
1848
|
if (remainingTimeoutMs !== null) {
|
|
1674
|
-
timeoutId =
|
|
1849
|
+
timeoutId = setRuntimeTimeout(() => {
|
|
1675
1850
|
settle(() => reject(new Error(RUN_NETWORK_QUERY_TIMEOUT_ERROR)));
|
|
1676
1851
|
}, remainingTimeoutMs);
|
|
1677
1852
|
}
|
|
@@ -2134,4 +2309,4 @@ export {
|
|
|
2134
2309
|
peekHydratedRtsQueryTotalCount as v,
|
|
2135
2310
|
useQuery as w
|
|
2136
2311
|
};
|
|
2137
|
-
//# sourceMappingURL=useQuery-
|
|
2312
|
+
//# sourceMappingURL=useQuery-XvXbEwG_.js.map
|