@rxferrix/client 0.0.0-stage → 0.2.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/api.d.ts +60 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +22 -0
- package/dist/api.js.map +1 -0
- package/dist/auth.d.ts +256 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +541 -0
- package/dist/auth.js.map +1 -0
- package/dist/bytes.d.ts +21 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +51 -0
- package/dist/bytes.js.map +1 -0
- package/dist/canonical.d.ts +13 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +66 -0
- package/dist/canonical.js.map +1 -0
- package/dist/client.d.ts +170 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +638 -0
- package/dist/client.js.map +1 -0
- package/dist/diff.d.ts +20 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +100 -0
- package/dist/diff.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/local_query_set.d.ts +56 -0
- package/dist/local_query_set.d.ts.map +1 -0
- package/dist/local_query_set.js +108 -0
- package/dist/local_query_set.js.map +1 -0
- package/dist/logging.d.ts +15 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +17 -0
- package/dist/logging.js.map +1 -0
- package/dist/optimistic_updates.d.ts +48 -0
- package/dist/optimistic_updates.d.ts.map +1 -0
- package/dist/optimistic_updates.js +113 -0
- package/dist/optimistic_updates.js.map +1 -0
- package/dist/paginated_query.d.ts +118 -0
- package/dist/paginated_query.d.ts.map +1 -0
- package/dist/paginated_query.js +199 -0
- package/dist/paginated_query.js.map +1 -0
- package/dist/protocol.d.ts +136 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +11 -0
- package/dist/protocol.js.map +1 -0
- package/dist/query_state.d.ts +16 -0
- package/dist/query_state.d.ts.map +1 -0
- package/dist/query_state.js +2 -0
- package/dist/query_state.js.map +1 -0
- package/dist/remote_query_set.d.ts +37 -0
- package/dist/remote_query_set.d.ts.map +1 -0
- package/dist/remote_query_set.js +87 -0
- package/dist/remote_query_set.js.map +1 -0
- package/dist/request_manager.d.ts +57 -0
- package/dist/request_manager.d.ts.map +1 -0
- package/dist/request_manager.js +163 -0
- package/dist/request_manager.js.map +1 -0
- package/dist/storage.d.ts +45 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +120 -0
- package/dist/storage.js.map +1 -0
- package/dist/testing.d.ts +68 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +97 -0
- package/dist/testing.js.map +1 -0
- package/dist/web_socket_manager.d.ts +88 -0
- package/dist/web_socket_manager.d.ts.map +1 -0
- package/dist/web_socket_manager.js +291 -0
- package/dist/web_socket_manager.js.map +1 -0
- package/package.json +50 -4
- package/src/api.ts +86 -0
- package/src/auth.ts +646 -0
- package/src/bytes.ts +57 -0
- package/src/canonical.ts +61 -0
- package/src/client.ts +740 -0
- package/src/diff.ts +87 -0
- package/src/errors.ts +36 -0
- package/src/index.ts +60 -0
- package/src/local_query_set.ts +130 -0
- package/src/logging.ts +26 -0
- package/src/optimistic_updates.ts +137 -0
- package/src/paginated_query.ts +299 -0
- package/src/protocol.ts +152 -0
- package/src/query_state.ts +12 -0
- package/src/remote_query_set.ts +105 -0
- package/src/request_manager.ts +199 -0
- package/src/storage.ts +171 -0
- package/src/testing.ts +120 -0
- package/src/web_socket_manager.ts +322 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAiBD,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAErF;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAoBzD;AAED,qGAAqG;AACrG,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMpE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON: `JSON.stringify` with object keys sorted recursively. Two arg objects that are structurally equal
|
|
3
|
+
* produce the same string, regardless of key insertion order. `undefined` object values are dropped, as in JSON.
|
|
4
|
+
*/
|
|
5
|
+
export function canonicalJSON(value) {
|
|
6
|
+
return JSON.stringify(sortKeys(value)) ?? "null";
|
|
7
|
+
}
|
|
8
|
+
function sortKeys(value) {
|
|
9
|
+
if (value === null || typeof value !== "object")
|
|
10
|
+
return value;
|
|
11
|
+
if (typeof value.toJSON === "function") {
|
|
12
|
+
return sortKeys(value.toJSON());
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value))
|
|
15
|
+
return value.map(sortKeys);
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const key of Object.keys(value).sort()) {
|
|
18
|
+
const v = value[key];
|
|
19
|
+
if (v === undefined || typeof v === "function" || typeof v === "symbol")
|
|
20
|
+
continue;
|
|
21
|
+
out[key] = sortKeys(v);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export function queryToken(udfPath, args) {
|
|
26
|
+
return udfPath + canonicalJSON(args);
|
|
27
|
+
}
|
|
28
|
+
/** Structural equality for JSON values (as produced by `JSON.parse`). */
|
|
29
|
+
export function jsonEqual(a, b) {
|
|
30
|
+
if (a === b)
|
|
31
|
+
return true;
|
|
32
|
+
if (typeof a !== typeof b || a === null || b === null || typeof a !== "object") {
|
|
33
|
+
// NaN never appears in JSON; plain === suffices for primitives.
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(a)) {
|
|
37
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
38
|
+
return false;
|
|
39
|
+
for (let i = 0; i < a.length; i++)
|
|
40
|
+
if (!jsonEqual(a[i], b[i]))
|
|
41
|
+
return false;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(b))
|
|
45
|
+
return false;
|
|
46
|
+
const ao = a;
|
|
47
|
+
const bo = b;
|
|
48
|
+
const aKeys = Object.keys(ao);
|
|
49
|
+
if (aKeys.length !== Object.keys(bo).length)
|
|
50
|
+
return false;
|
|
51
|
+
for (const k of aKeys) {
|
|
52
|
+
if (!Object.prototype.hasOwnProperty.call(bo, k) || !jsonEqual(ao[k], bo[k]))
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/** Normalizes user-supplied args: `undefined` becomes `{}`; anything else must be a plain object. */
|
|
58
|
+
export function normalizeArgs(args) {
|
|
59
|
+
if (args === undefined || args === null)
|
|
60
|
+
return {};
|
|
61
|
+
if (typeof args !== "object" || Array.isArray(args)) {
|
|
62
|
+
throw new TypeError(`RxFerrix function args must be an object, got ${Array.isArray(args) ? "array" : typeof args}`);
|
|
63
|
+
}
|
|
64
|
+
return args;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAI,CAAC,SAAS,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AAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,SAAS,CAAC,iDAAiD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACtH,CAAC;IACD,OAAO,IAA+B,CAAC;AACzC,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ArgsAndOptions, ArgsOf, FunctionReference, OptionalArgs, OutputOf } from "./api.js";
|
|
2
|
+
import { type QueryToken } from "./canonical.js";
|
|
3
|
+
import { type OptimisticUpdate } from "./optimistic_updates.js";
|
|
4
|
+
import type { QueryId } from "./protocol.js";
|
|
5
|
+
import type { QueryState } from "./query_state.js";
|
|
6
|
+
import { type PaginatedQuery, type PaginatedQueryArgs, type PaginatedQueryItem, type PaginatedQueryOptions, type PaginatedQueryReference } from "./paginated_query.js";
|
|
7
|
+
export interface RxFerrixClientOptions {
|
|
8
|
+
/** WebSocket implementation to use (defaults to `globalThis.WebSocket`). Needed on Node < 22 or for tests. */
|
|
9
|
+
webSocketConstructor?: typeof WebSocket;
|
|
10
|
+
/** Log every protocol message to `console.debug`. */
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
/** Log connection diagnostics (reconnects and their reasons) to `console.info`. */
|
|
13
|
+
reportDebugInfoToConsole?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Show the browser's "unsaved changes" prompt when the page is closed while mutations are in flight.
|
|
16
|
+
* Defaults to true in browsers.
|
|
17
|
+
*/
|
|
18
|
+
unsavedChangesWarning?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface MutationOptions<Args> {
|
|
21
|
+
optimisticUpdate?: OptimisticUpdate<Args>;
|
|
22
|
+
}
|
|
23
|
+
/** Fetches a JWT (or other bearer token). `forceRefresh` is true when the cached token was rejected or expires. */
|
|
24
|
+
export type AuthTokenFetcher = (options: {
|
|
25
|
+
forceRefresh: boolean;
|
|
26
|
+
}) => Promise<string | null | undefined>;
|
|
27
|
+
export interface ConnectionState {
|
|
28
|
+
/** The socket is open and the session handshake has been sent. */
|
|
29
|
+
readonly isWebSocketConnected: boolean;
|
|
30
|
+
/** At least one mutation or action has not settled yet. */
|
|
31
|
+
readonly hasInflightRequests: boolean;
|
|
32
|
+
readonly hasEverConnected: boolean;
|
|
33
|
+
/** Number of sockets opened so far, minus one (the `connectionCount` of the current `Connect`). */
|
|
34
|
+
readonly connectionCount: number;
|
|
35
|
+
/** Consecutive failed connection attempts since the last healthy socket. */
|
|
36
|
+
readonly connectionRetries: number;
|
|
37
|
+
readonly inflightMutations: number;
|
|
38
|
+
readonly inflightActions: number;
|
|
39
|
+
readonly timeOfOldestInflightRequest: Date | null;
|
|
40
|
+
/** Whether the server has confirmed the current auth token. */
|
|
41
|
+
readonly isAuthenticated: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface QueryWatch<T> {
|
|
44
|
+
/** Subscribes to changes of this query. The server subscription lives while at least one callback is registered. */
|
|
45
|
+
onUpdate(callback: () => void): () => void;
|
|
46
|
+
/** The current value, `undefined` while loading. Throws the query's {@link RxFerrixError} if it failed. */
|
|
47
|
+
localQueryResult(): T | undefined;
|
|
48
|
+
/** The current state. The returned object is referentially stable while the visible value does not change. */
|
|
49
|
+
localQueryState(): QueryState<T>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The RxFerrix sync client: subscribes to queries over a WebSocket and runs mutations and actions.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const client = new RxFerrixClient("http://localhost:3210");
|
|
56
|
+
* const watch = client.watchQuery(api.todos.list, {});
|
|
57
|
+
* watch.onUpdate(() => console.log(watch.localQueryResult()));
|
|
58
|
+
* await client.mutation(api.todos.add, { text: "hi" });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare class RxFerrixClient {
|
|
62
|
+
/** The http(s) base URL this client was created with. */
|
|
63
|
+
readonly url: string;
|
|
64
|
+
/** The WebSocket URL (`ws(s)://host/api/sync`). */
|
|
65
|
+
readonly syncUrl: string;
|
|
66
|
+
readonly sessionId: string;
|
|
67
|
+
private readonly logger;
|
|
68
|
+
private readonly ws;
|
|
69
|
+
private readonly localQueries;
|
|
70
|
+
private readonly remoteQueries;
|
|
71
|
+
private readonly requests;
|
|
72
|
+
private readonly optimistic;
|
|
73
|
+
private readonly listeners;
|
|
74
|
+
private readonly connectionListeners;
|
|
75
|
+
private cachedConnectionState;
|
|
76
|
+
private flushScheduled;
|
|
77
|
+
private closed;
|
|
78
|
+
/**
|
|
79
|
+
* Set after a reconnect while live queries have not yet received results from the new socket. The local view then
|
|
80
|
+
* still shows results from the old socket, so it is not "at" the new socket's ts; mutation completion waits.
|
|
81
|
+
*/
|
|
82
|
+
private resyncQuerySetVersion;
|
|
83
|
+
private auth;
|
|
84
|
+
private authToken;
|
|
85
|
+
/** The token held by the server on this socket (null = none sent / cleared). */
|
|
86
|
+
private serverToken;
|
|
87
|
+
/** Identity version sent on this socket (the server's identity version once processed). */
|
|
88
|
+
private identityVersion;
|
|
89
|
+
/** Identity version whose confirmation (a Transition reaching it) turns `isAuthenticated` on. */
|
|
90
|
+
private awaitingAuthConfirmation;
|
|
91
|
+
private isAuthenticated;
|
|
92
|
+
private authGeneration;
|
|
93
|
+
private authRefreshTimer;
|
|
94
|
+
private readonly removeUnloadListener;
|
|
95
|
+
constructor(url: string, options?: RxFerrixClientOptions);
|
|
96
|
+
/**
|
|
97
|
+
* Creates a watch on a query. Nothing is sent until `onUpdate` registers the first callback; all watches on the
|
|
98
|
+
* same `(udfPath, canonicalJSON(args))` share one server subscription.
|
|
99
|
+
*/
|
|
100
|
+
watchQuery<Q extends FunctionReference<"query">>(ref: Q, ...args: OptionalArgs<Q>): QueryWatch<OutputOf<Q>>;
|
|
101
|
+
/** Runs a query once: subscribes, waits for the first result, then unsubscribes. */
|
|
102
|
+
query<Q extends FunctionReference<"query">>(ref: Q, ...args: OptionalArgs<Q>): Promise<OutputOf<Q>>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a reactive paginated query over a query that takes `paginationOpts` and returns a `PaginationResult`
|
|
105
|
+
* (see `paginated_query.ts`). Pages are subscribed while the returned object has subscribers.
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* const messages = client.paginatedQuery(api.messages.list, { channel }, { initialNumItems: 20 });
|
|
109
|
+
* messages.subscribe(() => render(messages.getCurrent())); // { results, status, loadMore, ... }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
paginatedQuery<Q extends PaginatedQueryReference>(ref: Q, args: PaginatedQueryArgs<Q>, options: PaginatedQueryOptions): PaginatedQuery<PaginatedQueryItem<Q>>;
|
|
113
|
+
private subscribe;
|
|
114
|
+
/** Batches query-set changes made in the same tick into one ModifyQuerySet. */
|
|
115
|
+
private scheduleFlush;
|
|
116
|
+
private flushQuerySet;
|
|
117
|
+
/**
|
|
118
|
+
* Runs a mutation. The returned promise resolves with the mutation's result once the client's queries reflect the
|
|
119
|
+
* mutation (read-your-writes); it rejects with a {@link RxFerrixError} if the mutation fails.
|
|
120
|
+
*/
|
|
121
|
+
mutation<M extends FunctionReference<"mutation">>(ref: M, ...argsAndOptions: ArgsAndOptions<M, MutationOptions<ArgsOf<M>>>): Promise<OutputOf<M>>;
|
|
122
|
+
/** Runs an action. Rejects with a "connection lost" error if the socket drops while it is in flight. */
|
|
123
|
+
action<A extends FunctionReference<"action">>(ref: A, ...args: OptionalArgs<A>): Promise<OutputOf<A>>;
|
|
124
|
+
private sendUnsentRequests;
|
|
125
|
+
/**
|
|
126
|
+
* Sets the auth token source. The client fetches a token right away (holding back query subscriptions until it
|
|
127
|
+
* has one), sends it with `Authenticate`, re-sends it on every reconnect, refreshes JWTs shortly before they expire,
|
|
128
|
+
* and retries once with `forceRefresh: true` when the server rejects the token.
|
|
129
|
+
*
|
|
130
|
+
* `onChange(true)` fires once the server has confirmed the token; `onChange(false)` when auth is lost or cleared.
|
|
131
|
+
*/
|
|
132
|
+
setAuth(fetchToken: AuthTokenFetcher, onChange?: (isAuthenticated: boolean) => void): void;
|
|
133
|
+
/** Removes the token: the server falls back to an anonymous identity. */
|
|
134
|
+
clearAuth(): void;
|
|
135
|
+
private fetchAndApplyToken;
|
|
136
|
+
/** Records the desired token and sends `Authenticate` when the server's token differs. */
|
|
137
|
+
private applyToken;
|
|
138
|
+
private sendAuthenticateIfNeeded;
|
|
139
|
+
private scheduleTokenRefresh;
|
|
140
|
+
private clearAuthRefreshTimer;
|
|
141
|
+
private onAuthError;
|
|
142
|
+
private setAuthenticated;
|
|
143
|
+
/** A new socket is open and `Connect` was sent: rebuild the server's state from scratch. */
|
|
144
|
+
private onSocketOpen;
|
|
145
|
+
/** Sends everything the server does not know yet, in protocol order: Authenticate, ModifyQuerySet, requests. */
|
|
146
|
+
private syncToServer;
|
|
147
|
+
private onSocketClosed;
|
|
148
|
+
private onMessage;
|
|
149
|
+
/** The ts the local view is consistent with, or null while resyncing after a reconnect. */
|
|
150
|
+
private observedTs;
|
|
151
|
+
private onTransition;
|
|
152
|
+
/** Drops the settled mutations' optimistic updates, updates the view and notifies watchers, then settles. */
|
|
153
|
+
private finishMutations;
|
|
154
|
+
private serverView;
|
|
155
|
+
/** Rebuilds the visible view; after the whole update is applied, notifies the watchers of changed queries. */
|
|
156
|
+
private recomputeAndNotify;
|
|
157
|
+
/** The current connection state. Referentially stable until something changes. */
|
|
158
|
+
connectionState(): ConnectionState;
|
|
159
|
+
subscribeToConnectionState(callback: (state: ConnectionState) => void): () => void;
|
|
160
|
+
private computeConnectionState;
|
|
161
|
+
private notifyConnectionState;
|
|
162
|
+
/** Closes the socket for good. Pending mutations and actions are rejected. */
|
|
163
|
+
close(): void;
|
|
164
|
+
private installUnloadListener;
|
|
165
|
+
/** @internal Exposed for tests and devtools. */
|
|
166
|
+
get _debug(): {
|
|
167
|
+
queryIds: Map<QueryToken, QueryId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