dynamodb-reactive 0.1.21 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +378 -153
- package/dist/client-r_tnzwqi.d.ts +224 -0
- package/dist/client.cjs +1023 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +6 -0
- package/dist/client.d.ts +4 -70
- package/dist/client.js +1013 -1
- package/dist/client.js.map +1 -1
- package/dist/core.cjs +232 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +4 -0
- package/dist/core.d.ts +3 -3
- package/dist/core.js +222 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +232 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +103 -56
- package/dist/index.js +222 -1
- package/dist/index.js.map +1 -1
- package/dist/infra.cjs +623 -0
- package/dist/infra.cjs.map +1 -0
- package/dist/infra.d.cts +119 -0
- package/dist/infra.d.ts +50 -102
- package/dist/infra.js +371 -144
- package/dist/infra.js.map +1 -1
- package/dist/react.cjs +1250 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +68 -0
- package/dist/react.d.ts +68 -3
- package/dist/react.js +1237 -1
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +2351 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +364 -0
- package/dist/server.d.ts +58 -313
- package/dist/server.js +1855 -1208
- package/dist/server.js.map +1 -1
- package/dist/{table-tN3D4Tm-.d.ts → table-BijJ73pX.d.ts} +2 -34
- package/dist/{types-ISMJfyIv.d.ts → types-LMLk8JVC.d.ts} +56 -30
- package/package.json +79 -41
- package/dist/chunk-2A7GJ2UO.js +0 -1088
- package/dist/chunk-2A7GJ2UO.js.map +0 -1
- package/dist/chunk-ZAJA4KBE.js +0 -150
- package/dist/chunk-ZAJA4KBE.js.map +0 -1
- package/dist/react-B2b5RIz_.d.ts +0 -549
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client configuration
|
|
3
|
+
*/
|
|
4
|
+
interface ReactiveClientConfig {
|
|
5
|
+
/**
|
|
6
|
+
* WebSocket URL to connect to
|
|
7
|
+
*/
|
|
8
|
+
url: string;
|
|
9
|
+
/**
|
|
10
|
+
* HTTP URL for subscribe/call requests.
|
|
11
|
+
* Defaults to '/api/reactive' for Next.js apps.
|
|
12
|
+
*/
|
|
13
|
+
httpUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Authentication token or getter function
|
|
16
|
+
*/
|
|
17
|
+
auth?: string | (() => string | Promise<string>);
|
|
18
|
+
/**
|
|
19
|
+
* Custom headers to send with HTTP requests.
|
|
20
|
+
* Can be a static object or a getter function for dynamic headers.
|
|
21
|
+
* Useful for passing auth tokens or user context to the server.
|
|
22
|
+
*/
|
|
23
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
24
|
+
/**
|
|
25
|
+
* Enable automatic reconnection
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
autoReconnect?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Reconnection delay in milliseconds
|
|
31
|
+
* @default 1000
|
|
32
|
+
*/
|
|
33
|
+
reconnectDelay?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum reconnection attempts
|
|
36
|
+
* @default 10
|
|
37
|
+
*/
|
|
38
|
+
maxReconnectAttempts?: number;
|
|
39
|
+
/** Maximum time to wait for a usable connection. @default 10000 */
|
|
40
|
+
connectionTimeout?: number;
|
|
41
|
+
/** Maximum time for the init/connected/pong handshake. @default 10000 */
|
|
42
|
+
handshakeTimeout?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Callback when connected
|
|
45
|
+
*/
|
|
46
|
+
onConnect?: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Callback when disconnected
|
|
49
|
+
*/
|
|
50
|
+
onDisconnect?: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Callback for errors
|
|
53
|
+
*/
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Subscription options
|
|
58
|
+
*/
|
|
59
|
+
interface SubscriptionOptions<TInput = unknown, TData = unknown> {
|
|
60
|
+
/**
|
|
61
|
+
* Input for the subscription
|
|
62
|
+
*/
|
|
63
|
+
input?: TInput;
|
|
64
|
+
/**
|
|
65
|
+
* Callback when data is received
|
|
66
|
+
*/
|
|
67
|
+
onData?: (data: TData) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Callback when an error occurs
|
|
70
|
+
*/
|
|
71
|
+
onError?: (error: Error) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Active subscription
|
|
75
|
+
*/
|
|
76
|
+
interface Subscription<TData> {
|
|
77
|
+
/**
|
|
78
|
+
* Subscription ID (used for registering listeners)
|
|
79
|
+
*/
|
|
80
|
+
id: string;
|
|
81
|
+
/** Stable canonical `(path,input)` key. */
|
|
82
|
+
key: string;
|
|
83
|
+
/**
|
|
84
|
+
* Current data
|
|
85
|
+
*/
|
|
86
|
+
data: TData | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the subscription is loading
|
|
89
|
+
*/
|
|
90
|
+
loading: boolean;
|
|
91
|
+
/** Whether displayed data is waiting for authoritative reconciliation. */
|
|
92
|
+
stale: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Error if any
|
|
95
|
+
*/
|
|
96
|
+
error: Error | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Unsubscribe from updates
|
|
99
|
+
*/
|
|
100
|
+
unsubscribe: () => void;
|
|
101
|
+
/**
|
|
102
|
+
* Manually refetch the data
|
|
103
|
+
*/
|
|
104
|
+
refetch: () => Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Connection state
|
|
108
|
+
*/
|
|
109
|
+
type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
110
|
+
/**
|
|
111
|
+
* Mutation options for optimistic updates
|
|
112
|
+
*/
|
|
113
|
+
interface MutationOptions<TInput = unknown, TOutput = unknown> {
|
|
114
|
+
/**
|
|
115
|
+
* Subscription path to optimistically update (e.g., 'todos.list')
|
|
116
|
+
* No subscription data is changed when no target is provided.
|
|
117
|
+
*/
|
|
118
|
+
invalidates?: string | QueryTarget;
|
|
119
|
+
/** Canonical query key for targeting one exact active query. */
|
|
120
|
+
queryKey?: string;
|
|
121
|
+
/**
|
|
122
|
+
* How to apply the mutation result to subscription data (applied INSTANTLY before HTTP)
|
|
123
|
+
* - 'merge': Find item by input.id and merge input fields into it
|
|
124
|
+
* - 'remove': Remove item by input.id
|
|
125
|
+
* - Custom function for complex cases
|
|
126
|
+
*/
|
|
127
|
+
optimisticUpdate?: 'merge' | 'remove' | ((currentData: unknown[], input: TInput, result?: TOutput) => unknown[]);
|
|
128
|
+
/**
|
|
129
|
+
* For create operations (no input.id), provide the optimistic item to add.
|
|
130
|
+
* Can be the item object or a function that receives input and current data.
|
|
131
|
+
*/
|
|
132
|
+
optimisticData?: TOutput | ((input: TInput, currentData: unknown[]) => TOutput | undefined);
|
|
133
|
+
}
|
|
134
|
+
interface QueryTarget {
|
|
135
|
+
path: string;
|
|
136
|
+
input?: unknown;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Reactive client for shared, versioned subscriptions. */
|
|
140
|
+
declare class ReactiveClient {
|
|
141
|
+
private wsManager;
|
|
142
|
+
private httpUrl;
|
|
143
|
+
private authGetter?;
|
|
144
|
+
private headersGetter?;
|
|
145
|
+
private subscriptionsById;
|
|
146
|
+
private subscriptionsByKey;
|
|
147
|
+
private connectionState;
|
|
148
|
+
private stateListeners;
|
|
149
|
+
constructor(config: ReactiveClientConfig);
|
|
150
|
+
/** Apply live configuration without replacing subscription caches or the socket. */
|
|
151
|
+
configure(config: ReactiveClientConfig): void;
|
|
152
|
+
connect(): Promise<void>;
|
|
153
|
+
disconnect(): void;
|
|
154
|
+
forceReconnect(): void;
|
|
155
|
+
getConnectionState(): ConnectionState;
|
|
156
|
+
onConnectionStateChange(listener: (state: ConnectionState) => void): () => void;
|
|
157
|
+
subscribe<TData, TInput = unknown>(path: string, options?: SubscriptionOptions<TInput, TData>): Subscription<TData>;
|
|
158
|
+
call<TInput, TOutput>(path: string, input: TInput, options?: MutationOptions<TInput, TOutput>): Promise<TOutput>;
|
|
159
|
+
addSubscriptionListener(id: string, listener: () => void): () => void;
|
|
160
|
+
getSubscriptionRevision(id: string): number;
|
|
161
|
+
applyOptimisticUpdate(subscriptionId: string, updater: (data: unknown) => unknown): void;
|
|
162
|
+
private setAuth;
|
|
163
|
+
private setInitialHeaders;
|
|
164
|
+
private toAuthGetter;
|
|
165
|
+
private toHeadersGetter;
|
|
166
|
+
private registerActiveSubscriptions;
|
|
167
|
+
private ensureRegistered;
|
|
168
|
+
private releaseSubscription;
|
|
169
|
+
private sendUnsubscribe;
|
|
170
|
+
private refetch;
|
|
171
|
+
private handleMessage;
|
|
172
|
+
private handleSnapshot;
|
|
173
|
+
private handlePatch;
|
|
174
|
+
private drainPatchBuffer;
|
|
175
|
+
private discardStalePatches;
|
|
176
|
+
private requestResync;
|
|
177
|
+
private createMutationLayers;
|
|
178
|
+
private findMutationTargets;
|
|
179
|
+
private createOptimisticUpdater;
|
|
180
|
+
private settleMutationLayers;
|
|
181
|
+
private removeMutationLayers;
|
|
182
|
+
private recomputeData;
|
|
183
|
+
private hasSettledLayers;
|
|
184
|
+
private buildHeaders;
|
|
185
|
+
private markSubscriptionsStale;
|
|
186
|
+
private notifySubscription;
|
|
187
|
+
private notifyStateListeners;
|
|
188
|
+
}
|
|
189
|
+
type ProcedureInput<T> = T extends {
|
|
190
|
+
inputSchema?: {
|
|
191
|
+
_output: infer TInput;
|
|
192
|
+
};
|
|
193
|
+
} ? TInput : undefined;
|
|
194
|
+
type ProcedureOutput<T> = T extends {
|
|
195
|
+
resolver: (...args: any[]) => infer TReturn;
|
|
196
|
+
} ? Awaited<TReturn> : unknown;
|
|
197
|
+
type ExtractRouterDefinition<T> = T extends {
|
|
198
|
+
definition: infer TDefinition;
|
|
199
|
+
} ? TDefinition : T;
|
|
200
|
+
type QueryProcedure<T> = [ProcedureInput<T>] extends [undefined] ? {
|
|
201
|
+
useSubscription: (input?: undefined, options?: Omit<SubscriptionOptions<undefined, ProcedureOutput<T>>, 'input'>) => Subscription<ProcedureOutput<T>>;
|
|
202
|
+
} : {
|
|
203
|
+
useSubscription: (input: ProcedureInput<T>, options?: Omit<SubscriptionOptions<ProcedureInput<T>, ProcedureOutput<T>>, 'input'>) => Subscription<ProcedureOutput<T>>;
|
|
204
|
+
};
|
|
205
|
+
type MutationProcedure<T> = [ProcedureInput<T>] extends [undefined] ? {
|
|
206
|
+
mutate: (input?: undefined, options?: MutationOptions<undefined, ProcedureOutput<T>>) => Promise<ProcedureOutput<T>>;
|
|
207
|
+
} : {
|
|
208
|
+
mutate: (input: ProcedureInput<T>, options?: MutationOptions<ProcedureInput<T>, ProcedureOutput<T>>) => Promise<ProcedureOutput<T>>;
|
|
209
|
+
};
|
|
210
|
+
type TypedReactiveClientTree<T> = T extends {
|
|
211
|
+
type: 'query';
|
|
212
|
+
} ? QueryProcedure<T> : T extends {
|
|
213
|
+
type: 'mutation';
|
|
214
|
+
} ? MutationProcedure<T> : {
|
|
215
|
+
[K in keyof T]: TypedReactiveClientTree<T[K]>;
|
|
216
|
+
};
|
|
217
|
+
type TypedReactiveClient<TRouter> = TypedReactiveClientTree<ExtractRouterDefinition<TRouter>> & {
|
|
218
|
+
connect: () => Promise<void>;
|
|
219
|
+
disconnect: () => void;
|
|
220
|
+
};
|
|
221
|
+
declare function createReactiveClient<TRouter>(config: ReactiveClientConfig): TypedReactiveClient<TRouter>;
|
|
222
|
+
|
|
223
|
+
export { ReactiveClient as R, createReactiveClient as c };
|
|
224
|
+
export type { ConnectionState as C, MutationOptions as M, QueryTarget as Q, Subscription as S, TypedReactiveClient as T, ReactiveClientConfig as a, SubscriptionOptions as b };
|