@rpcbase/client 0.376.0 → 0.378.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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/initWithRoutes.d.ts.map +1 -1
- package/dist/rts/index.d.ts +1 -0
- package/dist/rts/index.d.ts.map +1 -1
- package/dist/rts/index.js +8 -2
- package/dist/rts/queryKey.d.ts +5 -0
- package/dist/rts/queryKey.d.ts.map +1 -0
- package/dist/rts/ssrHydration.d.ts +41 -0
- package/dist/rts/ssrHydration.d.ts.map +1 -0
- package/dist/rts/useQuery.d.ts +2 -0
- package/dist/rts/useQuery.d.ts.map +1 -1
- package/dist/rts/wsClient.d.ts +3 -1
- package/dist/rts/wsClient.d.ts.map +1 -1
- package/dist/{useQuery-DnrhB9w2.js → useQuery-pN9LndUY.js} +208 -35
- package/dist/useQuery-pN9LndUY.js.map +1 -0
- package/package.json +1 -1
- package/dist/useQuery-DnrhB9w2.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,EAAsB,wBAAwB,EAAiB,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,EAAsB,wBAAwB,EAAiB,MAAM,iBAAiB,CAAA;AAQ7F,OAAO,EAGL,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAiFxB,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,kBAqF7B,CAAA"}
|
package/dist/rts/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { configureRtsPouchStore, destroyAllCollections, destroyCollection, deleteDocs, getCollection, resetRtsPouchStore, runQuery, updateDocs, type RtsPouchQueryContext, type RtsPouchQueryOptions, type RtsPouchStoreConfig, } from './pouchStore';
|
|
2
2
|
export { addLocalTxn, connect, disconnect, onMessage, reconnect, registerQuery, sendMessage, syncRtsChanges, type RtsConnectOptions, type RtsQueryContext, type RtsQueryOptions, } from './wsClient';
|
|
3
|
+
export { hydrateRtsFromWindow, clearHydratedRtsQueryData, peekHydratedRtsQueryData, resolveRtsHydrationIdentityFromStaticRouterData, RtsSsrRuntimeProvider, STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY, type RtsSsrHydrationQueryData, type RtsSsrIdentity, type RtsSsrQueryRegistration, type RtsSsrRuntime, type StaticRpcbaseRtsHydrationData, } from './ssrHydration';
|
|
3
4
|
export { type RtsModelMap, type RtsModelName, } from './modelTypes';
|
|
4
5
|
export { useQuery, type UseRtsQueryOptions, type UseRtsQueryResult, } from './useQuery';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/rts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACX,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,wBAAwB,EACxB,+CAA+C,EAC/C,qBAAqB,EACrB,qCAAqC,EACrC,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,6BAA6B,GACnC,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAA"}
|
package/dist/rts/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { f, c, h, b, d, a, i, g, o, j, k, r, e, s, l, u,
|
|
1
|
+
import { R, S, f, n, c, h, b, d, a, i, g, m, o, p, j, k, r, q, e, s, l, u, t } from "../useQuery-pN9LndUY.js";
|
|
2
2
|
export {
|
|
3
|
+
R as RtsSsrRuntimeProvider,
|
|
4
|
+
S as STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY,
|
|
3
5
|
f as addLocalTxn,
|
|
6
|
+
n as clearHydratedRtsQueryData,
|
|
4
7
|
c as configureRtsPouchStore,
|
|
5
8
|
h as connect,
|
|
6
9
|
b as deleteDocs,
|
|
@@ -8,14 +11,17 @@ export {
|
|
|
8
11
|
a as destroyCollection,
|
|
9
12
|
i as disconnect,
|
|
10
13
|
g as getCollection,
|
|
14
|
+
m as hydrateRtsFromWindow,
|
|
11
15
|
o as onMessage,
|
|
16
|
+
p as peekHydratedRtsQueryData,
|
|
12
17
|
j as reconnect,
|
|
13
18
|
k as registerQuery,
|
|
14
19
|
r as resetRtsPouchStore,
|
|
20
|
+
q as resolveRtsHydrationIdentityFromStaticRouterData,
|
|
15
21
|
e as runQuery,
|
|
16
22
|
s as sendMessage,
|
|
17
23
|
l as syncRtsChanges,
|
|
18
24
|
u as updateDocs,
|
|
19
|
-
|
|
25
|
+
t as useQuery
|
|
20
26
|
};
|
|
21
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryKey.d.ts","sourceRoot":"","sources":["../../src/rts/queryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,eAAO,MAAM,kBAAkB,GAAI,OAAO,UAAU,EAAE,SAAS,eAAe,KAAG,MAMhF,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { RtsModelName } from './modelTypes';
|
|
3
|
+
import { RtsQueryOptions } from './wsClient';
|
|
4
|
+
type JsonObject = Record<string, unknown>;
|
|
5
|
+
export declare const STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY = "__staticRpcbaseRtsHydrationData";
|
|
6
|
+
export type RtsSsrHydrationQueryData = {
|
|
7
|
+
modelName: RtsModelName;
|
|
8
|
+
queryKey: string;
|
|
9
|
+
data: unknown[];
|
|
10
|
+
};
|
|
11
|
+
export type StaticRpcbaseRtsHydrationData = {
|
|
12
|
+
v: 1;
|
|
13
|
+
tenantId: string | null;
|
|
14
|
+
uid: string | null;
|
|
15
|
+
queries: RtsSsrHydrationQueryData[];
|
|
16
|
+
};
|
|
17
|
+
export type RtsSsrIdentity = {
|
|
18
|
+
tenantId: string | null;
|
|
19
|
+
uid: string | null;
|
|
20
|
+
};
|
|
21
|
+
export type RtsSsrQueryRegistration = {
|
|
22
|
+
modelName: RtsModelName;
|
|
23
|
+
query: JsonObject;
|
|
24
|
+
options: RtsQueryOptions;
|
|
25
|
+
queryKey: string;
|
|
26
|
+
};
|
|
27
|
+
export type RtsSsrRuntime = {
|
|
28
|
+
registerQuery: (query: RtsSsrQueryRegistration) => void;
|
|
29
|
+
getQueryData: (modelName: RtsModelName, queryKey: string) => unknown[] | undefined;
|
|
30
|
+
};
|
|
31
|
+
export declare const hydrateRtsFromWindow: (identity: RtsSsrIdentity) => void;
|
|
32
|
+
export declare const peekHydratedRtsQueryData: (modelName: RtsModelName, queryKey: string) => unknown[] | undefined;
|
|
33
|
+
export declare const clearHydratedRtsQueryData: () => void;
|
|
34
|
+
export declare const resolveRtsHydrationIdentityFromStaticRouterData: () => RtsSsrIdentity;
|
|
35
|
+
export declare const RtsSsrRuntimeProvider: ({ value, children, }: {
|
|
36
|
+
value: RtsSsrRuntime;
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare const useRtsSsrRuntime: () => RtsSsrRuntime | null;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=ssrHydration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssrHydration.d.ts","sourceRoot":"","sources":["../../src/rts/ssrHydration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,eAAO,MAAM,qCAAqC,oCAAoC,CAAA;AAEtF,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,YAAY,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,OAAO,EAAE,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,CAAC,EAAE,CAAC,CAAA;IACJ,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,OAAO,EAAE,wBAAwB,EAAE,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,YAAY,CAAA;IACvB,KAAK,EAAE,UAAU,CAAA;IACjB,OAAO,EAAE,eAAe,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;IACvD,YAAY,EAAE,CAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,EAAE,GAAG,SAAS,CAAA;CACnF,CAAA;AAyDD,eAAO,MAAM,oBAAoB,GAAI,UAAU,cAAc,KAAG,IAkB/D,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,WAAW,YAAY,EACvB,UAAU,MAAM,KACf,OAAO,EAAE,GAAG,SAEd,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAO,IAE5C,CAAA;AA4BD,eAAO,MAAM,+CAA+C,QAAO,cAiBlE,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,sBAGnC;IACD,KAAK,EAAE,aAAa,CAAA;IACpB,QAAQ,EAAE,SAAS,CAAA;CACpB,4CAMA,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAO,aAAa,GAAG,IAEnD,CAAA"}
|
package/dist/rts/useQuery.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/rts/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/rts/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIlE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG;IACjD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,CAAA;IACrB,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IAC7C,KAAK,EAAE,OAAO,GAAG,SAAS,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClF,WAAW,YAAY,EACvB,QAAO,UAAe,EACtB,UAAS,kBAAuB,KAC/B,iBAAiB,CAAC,CAAC,CA6JrB,CAAA"}
|
package/dist/rts/wsClient.d.ts
CHANGED
|
@@ -33,7 +33,9 @@ export declare const syncRtsChanges: (tenantId: string, uid: string, options?: P
|
|
|
33
33
|
export declare const connect: (tenantId: string, uid: string, options?: RtsConnectOptions) => Promise<void>;
|
|
34
34
|
export declare const disconnect: () => void;
|
|
35
35
|
export declare const reconnect: (tenantId: string, uid: string, options?: RtsConnectOptions) => Promise<void>;
|
|
36
|
-
export declare const registerQuery: (modelName: RtsModelName, query: JsonObject, optionsOrCallback?: RtsQueryOptions | QueryCallback, callbackMaybe?: QueryCallback
|
|
36
|
+
export declare const registerQuery: (modelName: RtsModelName, query: JsonObject, optionsOrCallback?: RtsQueryOptions | QueryCallback, callbackMaybe?: QueryCallback, behavior?: {
|
|
37
|
+
runInitialNetworkQuery?: boolean;
|
|
38
|
+
}) => (() => void) | undefined;
|
|
37
39
|
export declare const sendMessage: (event: string, payload?: unknown) => void;
|
|
38
40
|
export declare const onMessage: (event: string, callback: (payload: unknown) => void) => (() => void);
|
|
39
41
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../src/rts/wsClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../src/rts/wsClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAIhD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,oBAAoB,CAAA;AAE3E,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,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,iBAAiB,GAAG;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,SAAS,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF,CAAA;AAED,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,KAAK,IAAI,CAAA;AA8L7F,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,IAM3C,CAAA;AA8DD,eAAO,MAAM,cAAc,GAAU,UAAU,MAAM,EAAE,KAAK,MAAM,EAAE,UAAS,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAM,KAAG,OAAO,CAAC,IAAI,CAkElI,CAAA;AA0FD,eAAO,MAAM,OAAO,GAAI,UAAU,MAAM,EAAE,KAAK,MAAM,EAAE,UAAS,iBAAsB,KAAG,OAAO,CAAC,IAAI,CAEpG,CAAA;AAED,eAAO,MAAM,UAAU,QAAO,IAc7B,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,EAAE,KAAK,MAAM,EAAE,UAAS,iBAAsB,KAAG,OAAO,CAAC,IAAI,CActG,CAAA;AAED,eAAO,MAAM,aAAa,GACxB,WAAW,YAAY,EACvB,OAAO,UAAU,EACjB,oBAAoB,eAAe,GAAG,aAAa,EACnD,gBAAgB,aAAa,EAC7B,WAAW;IACT,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC,KACA,CAAC,MAAM,IAAI,CAAC,GAAG,SAwDjB,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"}
|
|
@@ -1,4 +1,102 @@
|
|
|
1
|
-
import { useId, useState, useRef, useEffect, useMemo } from "react";
|
|
1
|
+
import { createContext, useContext, useId, useState, useRef, useEffect, useMemo } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
const STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY = "__staticRpcbaseRtsHydrationData";
|
|
4
|
+
const RtsSsrRuntimeContext = createContext(null);
|
|
5
|
+
const hydrationDataStore = /* @__PURE__ */ new Map();
|
|
6
|
+
const makeStoreKey = (modelName, queryKey) => `${modelName}.${queryKey}`;
|
|
7
|
+
const normalizeStringOrNull = (value) => {
|
|
8
|
+
if (typeof value !== "string") return null;
|
|
9
|
+
const normalized = value.trim();
|
|
10
|
+
return normalized ? normalized : null;
|
|
11
|
+
};
|
|
12
|
+
const parseHydrationData = (value) => {
|
|
13
|
+
if (!value || typeof value !== "object") return null;
|
|
14
|
+
const raw = value;
|
|
15
|
+
if (raw.v !== 1) return null;
|
|
16
|
+
if (!Array.isArray(raw.queries)) return null;
|
|
17
|
+
const queries = [];
|
|
18
|
+
for (const entry of raw.queries) {
|
|
19
|
+
if (!entry || typeof entry !== "object") continue;
|
|
20
|
+
const query = entry;
|
|
21
|
+
const modelName = normalizeStringOrNull(query.modelName);
|
|
22
|
+
const queryKey = normalizeStringOrNull(query.queryKey);
|
|
23
|
+
if (!modelName || !queryKey) continue;
|
|
24
|
+
if (!Array.isArray(query.data)) continue;
|
|
25
|
+
queries.push({
|
|
26
|
+
modelName,
|
|
27
|
+
queryKey,
|
|
28
|
+
data: query.data
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
v: 1,
|
|
33
|
+
tenantId: normalizeStringOrNull(raw.tenantId),
|
|
34
|
+
uid: normalizeStringOrNull(raw.uid),
|
|
35
|
+
queries
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const hydrateRtsFromWindow = (identity) => {
|
|
39
|
+
if (typeof window === "undefined") return;
|
|
40
|
+
const browserWindow = window;
|
|
41
|
+
const raw = browserWindow[STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY];
|
|
42
|
+
delete browserWindow[STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY];
|
|
43
|
+
const parsed = parseHydrationData(raw);
|
|
44
|
+
if (!parsed) return;
|
|
45
|
+
if (parsed.tenantId !== identity.tenantId || parsed.uid !== identity.uid) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
hydrationDataStore.clear();
|
|
49
|
+
for (const query of parsed.queries) {
|
|
50
|
+
hydrationDataStore.set(makeStoreKey(query.modelName, query.queryKey), query.data);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const peekHydratedRtsQueryData = (modelName, queryKey) => {
|
|
54
|
+
return hydrationDataStore.get(makeStoreKey(modelName, queryKey));
|
|
55
|
+
};
|
|
56
|
+
const clearHydratedRtsQueryData = () => {
|
|
57
|
+
hydrationDataStore.clear();
|
|
58
|
+
};
|
|
59
|
+
const readRootLikeLoaderData = () => {
|
|
60
|
+
if (typeof window === "undefined") return null;
|
|
61
|
+
const hydration = window.__staticRouterHydrationData;
|
|
62
|
+
if (!hydration || typeof hydration !== "object") return null;
|
|
63
|
+
const loaderData = hydration.loaderData;
|
|
64
|
+
if (!loaderData || typeof loaderData !== "object") return null;
|
|
65
|
+
const entries = Object.entries(loaderData);
|
|
66
|
+
let fallback = null;
|
|
67
|
+
for (const [routeId, data] of entries) {
|
|
68
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) continue;
|
|
69
|
+
const obj = data;
|
|
70
|
+
const hasTenantId = Object.prototype.hasOwnProperty.call(obj, "tenantId");
|
|
71
|
+
const hasUser = Object.prototype.hasOwnProperty.call(obj, "user");
|
|
72
|
+
if (!hasTenantId && !hasUser) continue;
|
|
73
|
+
if (routeId === "root") return obj;
|
|
74
|
+
if (!fallback) fallback = obj;
|
|
75
|
+
}
|
|
76
|
+
return fallback;
|
|
77
|
+
};
|
|
78
|
+
const resolveRtsHydrationIdentityFromStaticRouterData = () => {
|
|
79
|
+
const rootData = readRootLikeLoaderData();
|
|
80
|
+
if (!rootData) {
|
|
81
|
+
return { tenantId: null, uid: null };
|
|
82
|
+
}
|
|
83
|
+
const tenantId = normalizeStringOrNull(rootData.tenantId);
|
|
84
|
+
const user = rootData.user;
|
|
85
|
+
const userId = user && typeof user === "object" ? normalizeStringOrNull(user.id) : null;
|
|
86
|
+
return {
|
|
87
|
+
tenantId,
|
|
88
|
+
uid: userId
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const RtsSsrRuntimeProvider = ({
|
|
92
|
+
value,
|
|
93
|
+
children
|
|
94
|
+
}) => {
|
|
95
|
+
return /* @__PURE__ */ jsx(RtsSsrRuntimeContext.Provider, { value, children });
|
|
96
|
+
};
|
|
97
|
+
const useRtsSsrRuntime = () => {
|
|
98
|
+
return useContext(RtsSsrRuntimeContext);
|
|
99
|
+
};
|
|
2
100
|
const UNDERSCORE_PREFIX = "$_";
|
|
3
101
|
const DEFAULT_FIND_LIMIT = 4096;
|
|
4
102
|
let storeConfig = null;
|
|
@@ -322,9 +420,18 @@ const destroyAllCollections = async () => {
|
|
|
322
420
|
await Promise.all(dbs.map((db) => db.destroy()));
|
|
323
421
|
collections.clear();
|
|
324
422
|
};
|
|
423
|
+
const computeRtsQueryKey = (query, options) => {
|
|
424
|
+
const key = options.key ?? "";
|
|
425
|
+
const projection = options.projection ? JSON.stringify(options.projection) : "";
|
|
426
|
+
const sort = options.sort ? JSON.stringify(options.sort) : "";
|
|
427
|
+
const limit = typeof options.limit === "number" ? String(options.limit) : "";
|
|
428
|
+
return `${key}${JSON.stringify(query)}${projection}${sort}${limit}`;
|
|
429
|
+
};
|
|
325
430
|
const TENANT_ID_QUERY_PARAM = "rb-tenant-id";
|
|
326
431
|
const RTS_CHANGES_ROUTE = "/api/rb/rts/changes";
|
|
327
432
|
const MAX_TXN_BUF = 2048;
|
|
433
|
+
const SERVER_RECONNECT_DELAY_MIN_MS = 1e4;
|
|
434
|
+
const SERVER_RECONNECT_DELAY_MAX_MS = 15e3;
|
|
328
435
|
let socket = null;
|
|
329
436
|
let connectPromise = null;
|
|
330
437
|
let explicitDisconnect = false;
|
|
@@ -337,6 +444,8 @@ const subscriptions = /* @__PURE__ */ new Map();
|
|
|
337
444
|
const messageCallbacks = /* @__PURE__ */ new Map();
|
|
338
445
|
let reconnectTimer = null;
|
|
339
446
|
let reconnectAttempts = 0;
|
|
447
|
+
let hasEstablishedConnection = false;
|
|
448
|
+
let pendingServerReconnectJitter = false;
|
|
340
449
|
let syncPromise = null;
|
|
341
450
|
let syncKey = null;
|
|
342
451
|
const ensureBrowser = () => {
|
|
@@ -358,33 +467,21 @@ const buildSocketUrl = (tenantId, _uid, options) => {
|
|
|
358
467
|
base.searchParams.set(TENANT_ID_QUERY_PARAM, tenantId);
|
|
359
468
|
return base.toString();
|
|
360
469
|
};
|
|
361
|
-
const computeQueryKey = (query, options) => {
|
|
362
|
-
const key = options.key ?? "";
|
|
363
|
-
const projection = options.projection ? JSON.stringify(options.projection) : "";
|
|
364
|
-
const sort = options.sort ? JSON.stringify(options.sort) : "";
|
|
365
|
-
const limit = typeof options.limit === "number" ? String(options.limit) : "";
|
|
366
|
-
return `${key}${JSON.stringify(query)}${projection}${sort}${limit}`;
|
|
367
|
-
};
|
|
368
470
|
const sendToServer = (message) => {
|
|
369
471
|
if (!socket) return;
|
|
370
472
|
if (socket.readyState !== WebSocket.OPEN) return;
|
|
371
473
|
socket.send(JSON.stringify(message));
|
|
372
474
|
};
|
|
373
|
-
const resubscribeAll = () => {
|
|
475
|
+
const resubscribeAll = ({ forceInitialQuery }) => {
|
|
374
476
|
for (const sub of subscriptions.values()) {
|
|
477
|
+
const runInitialQuery = forceInitialQuery || sub.runInitialNetworkQuery;
|
|
375
478
|
sendToServer({
|
|
376
479
|
type: "register-query",
|
|
377
480
|
modelName: sub.modelName,
|
|
378
481
|
queryKey: sub.queryKey,
|
|
379
482
|
query: sub.query,
|
|
380
|
-
options: sub.options
|
|
381
|
-
|
|
382
|
-
sendToServer({
|
|
383
|
-
type: "run-query",
|
|
384
|
-
modelName: sub.modelName,
|
|
385
|
-
queryKey: sub.queryKey,
|
|
386
|
-
query: sub.query,
|
|
387
|
-
options: sub.options
|
|
483
|
+
options: sub.options,
|
|
484
|
+
runInitialQuery
|
|
388
485
|
});
|
|
389
486
|
}
|
|
390
487
|
};
|
|
@@ -397,14 +494,22 @@ const clearReconnectTimer = () => {
|
|
|
397
494
|
};
|
|
398
495
|
const scheduleReconnect = () => {
|
|
399
496
|
clearReconnectTimer();
|
|
400
|
-
if (explicitDisconnect)
|
|
497
|
+
if (explicitDisconnect) {
|
|
498
|
+
pendingServerReconnectJitter = false;
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
401
501
|
if (!currentTenantId || !currentUid) return;
|
|
402
502
|
const cfg = connectOptions.reconnect ?? {};
|
|
403
503
|
const maxAttempts = cfg.attempts ?? 128;
|
|
404
504
|
const delayMs = cfg.delayMs ?? 400;
|
|
405
505
|
const delayMaxMs = cfg.delayMaxMs ?? 1e4;
|
|
406
506
|
if (reconnectAttempts >= maxAttempts) return;
|
|
407
|
-
|
|
507
|
+
let delay = Math.min(delayMaxMs, delayMs * Math.pow(2, reconnectAttempts));
|
|
508
|
+
if (pendingServerReconnectJitter) {
|
|
509
|
+
const span = SERVER_RECONNECT_DELAY_MAX_MS - SERVER_RECONNECT_DELAY_MIN_MS;
|
|
510
|
+
delay = SERVER_RECONNECT_DELAY_MIN_MS + Math.floor(Math.random() * (span + 1));
|
|
511
|
+
pendingServerReconnectJitter = false;
|
|
512
|
+
}
|
|
408
513
|
reconnectAttempts += 1;
|
|
409
514
|
reconnectTimer = window.setTimeout(() => {
|
|
410
515
|
void connectInternal(currentTenantId, currentUid, connectOptions, { resetReconnectAttempts: false });
|
|
@@ -594,7 +699,10 @@ const connectInternal = (tenantId, uid, options, { resetReconnectAttempts }) =>
|
|
|
594
699
|
opened = true;
|
|
595
700
|
settled = true;
|
|
596
701
|
reconnectAttempts = 0;
|
|
597
|
-
|
|
702
|
+
pendingServerReconnectJitter = false;
|
|
703
|
+
const forceInitialQuery = hasEstablishedConnection;
|
|
704
|
+
resubscribeAll({ forceInitialQuery });
|
|
705
|
+
hasEstablishedConnection = true;
|
|
598
706
|
resolve();
|
|
599
707
|
});
|
|
600
708
|
socket.addEventListener("message", handleMessage);
|
|
@@ -603,6 +711,9 @@ const connectInternal = (tenantId, uid, options, { resetReconnectAttempts }) =>
|
|
|
603
711
|
settled = true;
|
|
604
712
|
reject(new Error(`RTS WebSocket closed before opening (code=${event.code})`));
|
|
605
713
|
}
|
|
714
|
+
if (!explicitDisconnect) {
|
|
715
|
+
pendingServerReconnectJitter = opened;
|
|
716
|
+
}
|
|
606
717
|
socket = null;
|
|
607
718
|
connectPromise = null;
|
|
608
719
|
scheduleReconnect();
|
|
@@ -621,6 +732,8 @@ const connect = (tenantId, uid, options = {}) => {
|
|
|
621
732
|
const disconnect = () => {
|
|
622
733
|
explicitDisconnect = true;
|
|
623
734
|
clearReconnectTimer();
|
|
735
|
+
hasEstablishedConnection = false;
|
|
736
|
+
pendingServerReconnectJitter = false;
|
|
624
737
|
if (socket) {
|
|
625
738
|
try {
|
|
626
739
|
socket.close();
|
|
@@ -631,10 +744,20 @@ const disconnect = () => {
|
|
|
631
744
|
connectPromise = null;
|
|
632
745
|
};
|
|
633
746
|
const reconnect = (tenantId, uid, options = {}) => {
|
|
634
|
-
|
|
747
|
+
explicitDisconnect = true;
|
|
748
|
+
clearReconnectTimer();
|
|
749
|
+
pendingServerReconnectJitter = false;
|
|
750
|
+
if (socket) {
|
|
751
|
+
try {
|
|
752
|
+
socket.close();
|
|
753
|
+
} catch {
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
socket = null;
|
|
757
|
+
connectPromise = null;
|
|
635
758
|
return connect(tenantId, uid, options);
|
|
636
759
|
};
|
|
637
|
-
const registerQuery = (modelName, query, optionsOrCallback, callbackMaybe) => {
|
|
760
|
+
const registerQuery = (modelName, query, optionsOrCallback, callbackMaybe, behavior) => {
|
|
638
761
|
let options;
|
|
639
762
|
let callback;
|
|
640
763
|
if (typeof optionsOrCallback === "function") {
|
|
@@ -648,12 +771,13 @@ const registerQuery = (modelName, query, optionsOrCallback, callbackMaybe) => {
|
|
|
648
771
|
if (typeof modelName !== "string" || modelName.trim().length === 0) {
|
|
649
772
|
throw new Error("registerQuery: modelName must be a non-empty string");
|
|
650
773
|
}
|
|
651
|
-
const queryKey =
|
|
774
|
+
const queryKey = computeRtsQueryKey(query, options);
|
|
652
775
|
const cbKey = `${modelName}.${queryKey}`;
|
|
776
|
+
const runInitialNetworkQuery = behavior?.runInitialNetworkQuery !== false;
|
|
653
777
|
const set = queryCallbacks.get(cbKey) ?? /* @__PURE__ */ new Set();
|
|
654
778
|
set.add(callback);
|
|
655
779
|
queryCallbacks.set(cbKey, set);
|
|
656
|
-
subscriptions.set(cbKey, { modelName, query, options, queryKey });
|
|
780
|
+
subscriptions.set(cbKey, { modelName, query, options, queryKey, runInitialNetworkQuery });
|
|
657
781
|
if (currentUid) {
|
|
658
782
|
void runQuery({
|
|
659
783
|
modelName,
|
|
@@ -669,8 +793,7 @@ const registerQuery = (modelName, query, optionsOrCallback, callbackMaybe) => {
|
|
|
669
793
|
}).catch(() => {
|
|
670
794
|
});
|
|
671
795
|
}
|
|
672
|
-
sendToServer({ type: "
|
|
673
|
-
sendToServer({ type: "register-query", modelName, queryKey, query, options });
|
|
796
|
+
sendToServer({ type: "register-query", modelName, queryKey, query, options, runInitialQuery: runInitialNetworkQuery });
|
|
674
797
|
return () => {
|
|
675
798
|
sendToServer({ type: "remove-query", modelName, queryKey });
|
|
676
799
|
const callbacks = queryCallbacks.get(cbKey);
|
|
@@ -700,21 +823,55 @@ const useQuery = (modelName, query = {}, options = {}) => {
|
|
|
700
823
|
}
|
|
701
824
|
const id = useId();
|
|
702
825
|
const enabled = options.enabled ?? true;
|
|
826
|
+
const ssrEnabled = options.ssr !== false;
|
|
827
|
+
const refreshOnMount = options.refreshOnMount === true;
|
|
703
828
|
const key = options.key ?? id;
|
|
829
|
+
const queryJson = JSON.stringify(query);
|
|
704
830
|
const projectionJson = options.projection ? JSON.stringify(options.projection) : "";
|
|
705
831
|
const sortJson = options.sort ? JSON.stringify(options.sort) : "";
|
|
706
832
|
const limitStr = typeof options.limit === "number" ? String(options.limit) : "";
|
|
707
|
-
const
|
|
708
|
-
|
|
833
|
+
const queryKey = computeRtsQueryKey(query, {
|
|
834
|
+
key,
|
|
835
|
+
projection: options.projection,
|
|
836
|
+
sort: options.sort,
|
|
837
|
+
limit: options.limit
|
|
838
|
+
});
|
|
839
|
+
const ssrRuntime = useRtsSsrRuntime();
|
|
840
|
+
if (enabled && ssrEnabled && ssrRuntime) {
|
|
841
|
+
ssrRuntime.registerQuery({
|
|
842
|
+
modelName,
|
|
843
|
+
query,
|
|
844
|
+
options: {
|
|
845
|
+
key,
|
|
846
|
+
projection: options.projection,
|
|
847
|
+
sort: options.sort,
|
|
848
|
+
limit: options.limit
|
|
849
|
+
},
|
|
850
|
+
queryKey
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
const seedDataRaw = enabled && ssrEnabled ? ssrRuntime ? ssrRuntime.getQueryData(modelName, queryKey) : peekHydratedRtsQueryData(modelName, queryKey) : void 0;
|
|
854
|
+
const hasSeedData = Array.isArray(seedDataRaw);
|
|
855
|
+
const seedData = hasSeedData ? seedDataRaw : void 0;
|
|
856
|
+
const seedJson = (() => {
|
|
857
|
+
if (!hasSeedData) return "";
|
|
858
|
+
try {
|
|
859
|
+
return JSON.stringify(seedDataRaw);
|
|
860
|
+
} catch {
|
|
861
|
+
return "";
|
|
862
|
+
}
|
|
863
|
+
})();
|
|
864
|
+
const [data, setData] = useState(() => seedData);
|
|
865
|
+
const [source, setSource] = useState(() => hasSeedData ? "cache" : void 0);
|
|
709
866
|
const [error, setError] = useState(void 0);
|
|
710
|
-
const [loading, setLoading] = useState(enabled);
|
|
867
|
+
const [loading, setLoading] = useState(enabled && !hasSeedData);
|
|
711
868
|
const hasFirstReply = useRef(false);
|
|
712
869
|
const hasNetworkReply = useRef(false);
|
|
713
870
|
const lastDataJsonRef = useRef("");
|
|
714
871
|
useEffect(() => {
|
|
715
|
-
hasFirstReply.current =
|
|
872
|
+
hasFirstReply.current = hasSeedData;
|
|
716
873
|
hasNetworkReply.current = false;
|
|
717
|
-
lastDataJsonRef.current =
|
|
874
|
+
lastDataJsonRef.current = seedJson;
|
|
718
875
|
setError(void 0);
|
|
719
876
|
if (!enabled) {
|
|
720
877
|
setLoading(false);
|
|
@@ -722,10 +879,17 @@ const useQuery = (modelName, query = {}, options = {}) => {
|
|
|
722
879
|
setSource(void 0);
|
|
723
880
|
return;
|
|
724
881
|
}
|
|
882
|
+
if (hasSeedData) {
|
|
883
|
+
setLoading(false);
|
|
884
|
+
setData(seedData);
|
|
885
|
+
setSource("cache");
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
725
888
|
setLoading(true);
|
|
726
|
-
}, [enabled, modelName,
|
|
889
|
+
}, [enabled, modelName, queryKey, hasSeedData, seedData, seedJson]);
|
|
727
890
|
useEffect(() => {
|
|
728
891
|
if (!enabled) return;
|
|
892
|
+
const runInitialNetworkQuery = refreshOnMount || !hasSeedData;
|
|
729
893
|
const unsubscribe = registerQuery(
|
|
730
894
|
modelName,
|
|
731
895
|
query,
|
|
@@ -763,12 +927,15 @@ const useQuery = (modelName, query = {}, options = {}) => {
|
|
|
763
927
|
lastDataJsonRef.current = nextJson;
|
|
764
928
|
setSource(context.source);
|
|
765
929
|
setData(result);
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
runInitialNetworkQuery
|
|
766
933
|
}
|
|
767
934
|
);
|
|
768
935
|
return () => {
|
|
769
936
|
unsubscribe?.();
|
|
770
937
|
};
|
|
771
|
-
}, [enabled, modelName,
|
|
938
|
+
}, [enabled, modelName, queryKey, queryJson, projectionJson, sortJson, limitStr, hasSeedData, refreshOnMount]);
|
|
772
939
|
return useMemo(
|
|
773
940
|
() => ({
|
|
774
941
|
data,
|
|
@@ -780,6 +947,8 @@ const useQuery = (modelName, query = {}, options = {}) => {
|
|
|
780
947
|
);
|
|
781
948
|
};
|
|
782
949
|
export {
|
|
950
|
+
RtsSsrRuntimeProvider as R,
|
|
951
|
+
STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY as S,
|
|
783
952
|
destroyCollection as a,
|
|
784
953
|
deleteDocs as b,
|
|
785
954
|
configureRtsPouchStore as c,
|
|
@@ -792,10 +961,14 @@ export {
|
|
|
792
961
|
reconnect as j,
|
|
793
962
|
registerQuery as k,
|
|
794
963
|
syncRtsChanges as l,
|
|
795
|
-
|
|
964
|
+
hydrateRtsFromWindow as m,
|
|
965
|
+
clearHydratedRtsQueryData as n,
|
|
796
966
|
onMessage as o,
|
|
967
|
+
peekHydratedRtsQueryData as p,
|
|
968
|
+
resolveRtsHydrationIdentityFromStaticRouterData as q,
|
|
797
969
|
resetRtsPouchStore as r,
|
|
798
970
|
sendMessage as s,
|
|
971
|
+
useQuery as t,
|
|
799
972
|
updateDocs as u
|
|
800
973
|
};
|
|
801
|
-
//# sourceMappingURL=useQuery-
|
|
974
|
+
//# sourceMappingURL=useQuery-pN9LndUY.js.map
|