powersync-bridge 0.0.1-alpha.0 → 0.0.1-alpha.2
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 +111 -20
- package/dist/{chunk-TANEBEGU.js → chunk-WJDQWVO5.js} +64 -67
- package/dist/chunk-WJDQWVO5.js.map +1 -0
- package/dist/{clock-BAt_Za0Q.d.cts → clock-DANrBsZH.d.cts} +2 -2
- package/dist/{clock-BAt_Za0Q.d.ts → clock-DANrBsZH.d.ts} +2 -2
- package/dist/index.cjs +895 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +327 -175
- package/dist/index.d.ts +327 -175
- package/dist/index.js +833 -55
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-TANEBEGU.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,173 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ApiOffsetPolicy,
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* External store with a stable snapshot for useSyncExternalStore (R10/R11).
|
|
6
|
-
* `replace()` swaps the snapshot and notifies once; `swapRoot()` is what an identity change
|
|
7
|
-
* calls — it is synchronous, so no committed frame can observe the outgoing state (R15).
|
|
8
|
-
*/
|
|
9
|
-
declare class SnapshotStore<S> implements Store<S> {
|
|
10
|
-
private snapshot;
|
|
11
|
-
private readonly listeners;
|
|
12
|
-
constructor(initial: S);
|
|
13
|
-
getSnapshot(): S;
|
|
14
|
-
subscribe(listener: () => void): () => void;
|
|
15
|
-
replace(next: S): void;
|
|
16
|
-
get listenerCount(): number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type FlagState = 'idle' | 'flagging' | 'syncing' | 'synced' | 'timeout' | 'error';
|
|
20
|
-
interface FlaggerConfig {
|
|
21
|
-
/** App-supplied backend call, e.g. POST /sync/flag. */
|
|
22
|
-
readonly requestFlag: (ids: readonly string[]) => Promise<void>;
|
|
23
|
-
/** Stream whose JOIN reads the per-user sync_requests table. */
|
|
24
|
-
readonly stream: string;
|
|
25
|
-
/** Table the flagged rows land in (for presence detection). */
|
|
26
|
-
readonly table: string;
|
|
27
|
-
readonly timeoutMs?: number;
|
|
28
|
-
}
|
|
29
|
-
interface FlagResult {
|
|
30
|
-
readonly state: FlagState;
|
|
31
|
-
readonly error?: Error;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* OPTIONAL primitive (§7): client-triggered, per-user server-side flagging. Use only for bucket
|
|
35
|
-
* economy or server-decided membership; `useOnDemandStream` is the default single-row path.
|
|
36
|
-
* `synced` is detected by watching the SPECIFIC requested ids, never by waitForFirstSync.
|
|
37
|
-
*/
|
|
38
|
-
declare class AutoSyncFlagStore {
|
|
39
|
-
private readonly driver;
|
|
40
|
-
private readonly clock;
|
|
41
|
-
private readonly config;
|
|
42
|
-
private readonly ids;
|
|
43
|
-
readonly store: SnapshotStore<FlagResult>;
|
|
44
|
-
private handle;
|
|
45
|
-
private unsubStatus;
|
|
46
|
-
private cancelTimeout;
|
|
47
|
-
private disposed;
|
|
48
|
-
private refs;
|
|
49
|
-
constructor(driver: BridgeDriver, clock: BridgeClock, config: FlaggerConfig, ids: readonly string[]);
|
|
50
|
-
retain(): void;
|
|
51
|
-
release(): void;
|
|
52
|
-
get isDisposed(): boolean;
|
|
53
|
-
swapRoot(): void;
|
|
54
|
-
dispose(): void;
|
|
55
|
-
private start;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Identity is DERIVED from the JWT the connector returns, never supplied by the app (R15, [DX]).
|
|
60
|
-
* The key is the canonical JSON of the stable claims — a cache key, not a hash.
|
|
61
|
-
*/
|
|
62
|
-
declare const DEFAULT_VOLATILE_CLAIMS: readonly string[];
|
|
63
|
-
declare function decodeJwtPayload(token: string): Record<string, unknown>;
|
|
64
|
-
interface IdentityKeyOptions {
|
|
65
|
-
readonly denyList?: readonly string[];
|
|
66
|
-
/** Connection parameters opted in BY KEY (rotating values must be excluded explicitly). */
|
|
67
|
-
readonly connectionParams?: Record<string, unknown>;
|
|
68
|
-
}
|
|
69
|
-
declare function identityKeyFromClaims(claims: Record<string, unknown>, opts?: IdentityKeyOptions): string;
|
|
70
|
-
declare function identityKeyFromToken(token: string, opts?: IdentityKeyOptions): string;
|
|
71
|
-
|
|
72
|
-
interface InfiniteDeps {
|
|
73
|
-
readonly driver: BridgeDriver;
|
|
74
|
-
readonly adapter: QueryAdapter;
|
|
75
|
-
readonly clock: BridgeClock;
|
|
76
|
-
readonly onEvicted?: ((ids: readonly string[]) => void) | undefined;
|
|
77
|
-
}
|
|
78
|
-
declare function emptyInfiniteResult<T>(): InfiniteListResult<T>;
|
|
79
|
-
/**
|
|
80
|
-
* The infinite list engine (§6.2): one global id set, a loaded-range local watch, and bounded
|
|
81
|
-
* escalation through equality partitions or API pages.
|
|
82
|
-
*/
|
|
83
|
-
declare class InfiniteListStore<TItem, TScope, K extends OrderKey<TItem>, TCursor, TPartition> {
|
|
84
|
-
private readonly deps;
|
|
85
|
-
private readonly def;
|
|
86
|
-
private readonly scope;
|
|
87
|
-
readonly store: SnapshotStore<InfiniteListResult<TItem>>;
|
|
88
|
-
private readonly compare;
|
|
89
|
-
private readonly table;
|
|
90
|
-
private readonly abort;
|
|
91
|
-
private pages;
|
|
92
|
-
private local;
|
|
93
|
-
private lookahead;
|
|
94
|
-
private emissionSeen;
|
|
95
|
-
private localError;
|
|
96
|
-
private unsubDiffs;
|
|
97
|
-
private readonly apiRows;
|
|
98
|
-
private readonly retained;
|
|
99
|
-
private readonly tombstones;
|
|
100
|
-
private readonly subs;
|
|
101
|
-
private readonly lru;
|
|
102
|
-
private probeCursor;
|
|
103
|
-
private serverFloor;
|
|
104
|
-
private floorRevalidated;
|
|
105
|
-
private boundary;
|
|
106
|
-
private reason;
|
|
107
|
-
private awaitingSync;
|
|
108
|
-
private loading;
|
|
109
|
-
private errors;
|
|
110
|
-
private warnings;
|
|
111
|
-
private errorCount;
|
|
112
|
-
private nextRetryAt;
|
|
113
|
-
private disposed;
|
|
114
|
-
private refs;
|
|
115
|
-
constructor(deps: InfiniteDeps, def: InfiniteListDefinition<TItem, TScope, K, TCursor, TPartition>, scope: TScope);
|
|
116
|
-
retain(): void;
|
|
117
|
-
release(): void;
|
|
118
|
-
get isDisposed(): boolean;
|
|
119
|
-
swapRoot(): void;
|
|
120
|
-
dispose(): void;
|
|
121
|
-
private subscribeLocal;
|
|
122
|
-
private onDiff;
|
|
123
|
-
private provenance;
|
|
124
|
-
private applyRemovals;
|
|
125
|
-
private lastCursor;
|
|
126
|
-
/** Explicit user retry clears the backoff (R16). */
|
|
127
|
-
retry(): Promise<void>;
|
|
128
|
-
loadMore(): Promise<void>;
|
|
129
|
-
private setUnknown;
|
|
130
|
-
private escalatePartition;
|
|
131
|
-
private finishEnd;
|
|
132
|
-
private track;
|
|
133
|
-
private untrack;
|
|
134
|
-
private apiGate;
|
|
135
|
-
private apiFailure;
|
|
136
|
-
private escalateApi;
|
|
137
|
-
private escalateOffset;
|
|
138
|
-
private absorbApi;
|
|
139
|
-
private mergedEntries;
|
|
140
|
-
private render;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
interface OnDemandOptions {
|
|
144
|
-
readonly ttl?: number;
|
|
145
|
-
readonly priority?: 0 | 1 | 2 | 3;
|
|
146
|
-
readonly timeoutMs?: number;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* The default "pull one row" primitive (§7, [DX]): a plain on-demand equality-parameter stream.
|
|
150
|
-
* Held while retained; the TTL keeps rows warm after release.
|
|
151
|
-
*/
|
|
152
|
-
declare class OnDemandStreamStore {
|
|
153
|
-
private readonly driver;
|
|
154
|
-
private readonly clock;
|
|
155
|
-
private readonly name;
|
|
156
|
-
private readonly params;
|
|
157
|
-
private readonly opts;
|
|
158
|
-
readonly store: SnapshotStore<OnDemandResult>;
|
|
159
|
-
private handle;
|
|
160
|
-
private readonly abort;
|
|
161
|
-
private refs;
|
|
162
|
-
private disposed;
|
|
163
|
-
constructor(driver: BridgeDriver, clock: BridgeClock, name: string, params: Params | null, opts: OnDemandOptions);
|
|
164
|
-
retain(): void;
|
|
165
|
-
release(): void;
|
|
166
|
-
get isDisposed(): boolean;
|
|
167
|
-
swapRoot(): void;
|
|
168
|
-
dispose(): void;
|
|
169
|
-
private start;
|
|
170
|
-
}
|
|
1
|
+
import { B as BridgeDriver, S as StreamDescription, O as OrderKey, C as CursorOf, a as OpaqueCursor, K as KeyOf, b as SortDirection, c as CrudDelta, P as PendingOpRef, d as BridgeClock, e as Store, Q as QueryAdapter, M as MeasureSink, R as RacedListResult, f as RacedListDefinition, g as RowsBuilder, h as PagedRow, L as ListErrors, I as InfiniteListResult, i as InfiniteListDefinition, j as OnDemandResult, k as Params } from './clock-DANrBsZH.cjs';
|
|
2
|
+
export { A as ApiOffsetPolicy, l as ApiPolicy, m as Boundary, n as BoundaryReason, o as CompilableQuery, p as Cursor, D as DifferentialStream, E as EscalationPolicy, q as ListState, r as OnDemandStatus, s as PageArgs, t as PartitionPolicy, u as PendingOp, v as PreparedQuery, w as PriorityStatus, x as RaceMeasurement, y as RowDiff, z as RowOrigin, F as Snapshot, G as StreamHandle, H as StreamStatus, J as SyncStatusView, N as realClock } from './clock-DANrBsZH.cjs';
|
|
171
3
|
|
|
172
4
|
type Clock = () => number;
|
|
173
5
|
interface CheckpointCompletion {
|
|
@@ -198,7 +30,6 @@ declare class FreshnessTracker {
|
|
|
198
30
|
private lastHasSynced;
|
|
199
31
|
private readonly streamFreshAt;
|
|
200
32
|
private readonly streamSeenSyncedAt;
|
|
201
|
-
private readonly completions;
|
|
202
33
|
private readonly completionListeners;
|
|
203
34
|
private readonly clearListeners;
|
|
204
35
|
private unsubscribe;
|
|
@@ -276,8 +107,20 @@ declare class CrudMirror {
|
|
|
276
107
|
onChange(l: () => void): () => void;
|
|
277
108
|
}
|
|
278
109
|
|
|
110
|
+
/** Checkpoint maintenance has one shared slot; first reads and pagination bypass it. */
|
|
111
|
+
declare class BackgroundReads {
|
|
112
|
+
private running;
|
|
113
|
+
private readonly queue;
|
|
114
|
+
run<T>(read: () => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
115
|
+
private drain;
|
|
116
|
+
}
|
|
117
|
+
|
|
279
118
|
/** Minimal TanStack QueryClient surface the bridge relies on (R11: fetchQuery + keying only). */
|
|
280
119
|
interface MinimalQueryClient {
|
|
120
|
+
cancelQueries?(filters: {
|
|
121
|
+
queryKey: readonly unknown[];
|
|
122
|
+
exact: boolean;
|
|
123
|
+
}): Promise<unknown>;
|
|
281
124
|
fetchQuery<T>(opts: {
|
|
282
125
|
queryKey: readonly unknown[];
|
|
283
126
|
queryFn: (ctx: {
|
|
@@ -307,10 +150,27 @@ declare class SnapshotCache {
|
|
|
307
150
|
asOf?: string;
|
|
308
151
|
}>): Promise<SnapshotRecord<TApi>>;
|
|
309
152
|
/** Cancel every in-flight fetch under a key prefix (identity swap). */
|
|
153
|
+
invalidate(key: readonly unknown[]): void;
|
|
154
|
+
/** Cancel every in-flight fetch under a key prefix (identity swap). */
|
|
310
155
|
abortAll(prefix: readonly unknown[]): void;
|
|
311
156
|
clear(): void;
|
|
312
157
|
}
|
|
313
158
|
|
|
159
|
+
/**
|
|
160
|
+
* External store with a stable snapshot for useSyncExternalStore (R10/R11).
|
|
161
|
+
* `replace()` swaps the snapshot and notifies once; `swapRoot()` is what an identity change
|
|
162
|
+
* calls — it is synchronous, so no committed frame can observe the outgoing state (R15).
|
|
163
|
+
*/
|
|
164
|
+
declare class SnapshotStore<S> implements Store<S> {
|
|
165
|
+
private snapshot;
|
|
166
|
+
private readonly listeners;
|
|
167
|
+
constructor(initial: S);
|
|
168
|
+
readonly getSnapshot: () => S;
|
|
169
|
+
readonly subscribe: (listener: () => void) => (() => void);
|
|
170
|
+
replace(next: S): void;
|
|
171
|
+
get listenerCount(): number;
|
|
172
|
+
}
|
|
173
|
+
|
|
314
174
|
interface RacedDeps {
|
|
315
175
|
readonly driver: BridgeDriver;
|
|
316
176
|
readonly adapter: QueryAdapter;
|
|
@@ -322,6 +182,7 @@ interface RacedDeps {
|
|
|
322
182
|
readonly identityKey: string | null;
|
|
323
183
|
readonly apiLegEnabled: boolean;
|
|
324
184
|
readonly measure: MeasureSink | undefined;
|
|
185
|
+
readonly backgroundReads?: BackgroundReads;
|
|
325
186
|
}
|
|
326
187
|
declare function emptyRacedResult<T>(): RacedListResult<T>;
|
|
327
188
|
/**
|
|
@@ -335,7 +196,10 @@ declare class RacedListStore<TItem, TScope, TApi, K extends OrderKey<TItem>> {
|
|
|
335
196
|
readonly store: SnapshotStore<RacedListResult<TItem>>;
|
|
336
197
|
private readonly compare;
|
|
337
198
|
private readonly table;
|
|
338
|
-
private
|
|
199
|
+
private abort;
|
|
200
|
+
private observation;
|
|
201
|
+
private readonly checkpointRefresh;
|
|
202
|
+
private localFreshAt;
|
|
339
203
|
private readonly startedAt;
|
|
340
204
|
private snap;
|
|
341
205
|
private snapPending;
|
|
@@ -354,18 +218,21 @@ declare class RacedListStore<TItem, TScope, TApi, K extends OrderKey<TItem>> {
|
|
|
354
218
|
private readonly tombstones;
|
|
355
219
|
private disposed;
|
|
356
220
|
private refs;
|
|
221
|
+
private activeRefs;
|
|
357
222
|
private measured;
|
|
358
223
|
private localMs;
|
|
359
224
|
private apiMs;
|
|
360
225
|
constructor(deps: RacedDeps, def: RacedListDefinition<TItem, TScope, TApi, K>, scope: TScope, scopeKey: string);
|
|
361
|
-
retain(): void;
|
|
362
|
-
release(): void;
|
|
226
|
+
retain(active?: boolean): void;
|
|
227
|
+
release(active?: boolean): void;
|
|
363
228
|
get isDisposed(): boolean;
|
|
364
229
|
/** Synchronous part of an identity swap: the snapshot becomes empty 'pending' at once (R15). */
|
|
365
230
|
swapRoot(): void;
|
|
366
231
|
dispose(): void;
|
|
232
|
+
private pause;
|
|
367
233
|
private start;
|
|
368
234
|
private startApiLeg;
|
|
235
|
+
private snapshotKey;
|
|
369
236
|
/**
|
|
370
237
|
* A checkpoint completed. Status events and diff emissions are separate SDK events with no
|
|
371
238
|
* ordering guarantee; taking ownership on the stale local map would render the pre-checkpoint
|
|
@@ -387,6 +254,284 @@ declare class RacedListStore<TItem, TScope, TApi, K extends OrderKey<TItem>> {
|
|
|
387
254
|
lastCursor(): ReturnType<typeof cursorOfRow<TItem, K>> | undefined;
|
|
388
255
|
}
|
|
389
256
|
|
|
257
|
+
interface QueryPage<T> {
|
|
258
|
+
readonly cursor: T | undefined;
|
|
259
|
+
readonly limit: number;
|
|
260
|
+
}
|
|
261
|
+
/** Query keys include every predicate, identity and permission that can change the result. */
|
|
262
|
+
interface InfiniteQueryOptions<T extends {
|
|
263
|
+
id: string;
|
|
264
|
+
}> {
|
|
265
|
+
readonly queryKey: readonly unknown[];
|
|
266
|
+
readonly query: (page: QueryPage<T>) => RowsBuilder<T>;
|
|
267
|
+
/** Return rows in the same order as SQLite. Honor limit, including its lookahead row. */
|
|
268
|
+
readonly fetchPage: (page: QueryPage<T> & {
|
|
269
|
+
readonly signal: AbortSignal;
|
|
270
|
+
}) => Promise<readonly T[]>;
|
|
271
|
+
readonly orderBy: OrderKey<T>;
|
|
272
|
+
readonly direction?: 'asc' | 'desc';
|
|
273
|
+
readonly pageSize?: number;
|
|
274
|
+
readonly maxRows?: number;
|
|
275
|
+
readonly staleTime?: number;
|
|
276
|
+
readonly enabled?: boolean;
|
|
277
|
+
readonly table?: string;
|
|
278
|
+
/** Heterogeneous feeds identify each underlying business row for pending-write protection. */
|
|
279
|
+
readonly getRowIdentity?: (row: T) => {
|
|
280
|
+
table: string;
|
|
281
|
+
id: string;
|
|
282
|
+
};
|
|
283
|
+
readonly isInWindow?: (row: T) => boolean;
|
|
284
|
+
}
|
|
285
|
+
/** Shared by core and React so changing page configuration cannot reuse an incompatible store. */
|
|
286
|
+
declare const infiniteQueryKey: <T extends {
|
|
287
|
+
id: string;
|
|
288
|
+
}>(options: InfiniteQueryOptions<T>) => string;
|
|
289
|
+
interface InfiniteQueryResult<T> {
|
|
290
|
+
readonly data: T[];
|
|
291
|
+
readonly items: readonly PagedRow<T>[];
|
|
292
|
+
readonly isLoading: boolean;
|
|
293
|
+
readonly isFetching: boolean;
|
|
294
|
+
readonly isFetchingNextPage: boolean;
|
|
295
|
+
readonly hasNextPage: boolean;
|
|
296
|
+
readonly needsOlderWindow: boolean;
|
|
297
|
+
readonly error: Error | undefined;
|
|
298
|
+
readonly errors: ListErrors;
|
|
299
|
+
readonly isError: boolean;
|
|
300
|
+
readonly windowRevision: number;
|
|
301
|
+
}
|
|
302
|
+
declare class OfflineError extends Error {
|
|
303
|
+
readonly name = "OfflineError";
|
|
304
|
+
constructor();
|
|
305
|
+
}
|
|
306
|
+
interface QueryDeps extends RacedDeps {
|
|
307
|
+
readonly connectivity: Store<boolean | undefined>;
|
|
308
|
+
}
|
|
309
|
+
/** One loaded-range watch and one ordered API cursor chain. Every requested page races both. */
|
|
310
|
+
declare class InfiniteQueryStore<T extends {
|
|
311
|
+
id: string;
|
|
312
|
+
}> {
|
|
313
|
+
private readonly deps;
|
|
314
|
+
private readonly options;
|
|
315
|
+
readonly store: SnapshotStore<InfiniteQueryResult<T>>;
|
|
316
|
+
private readonly pageSize;
|
|
317
|
+
private readonly maxRows;
|
|
318
|
+
private readonly compare;
|
|
319
|
+
private table;
|
|
320
|
+
private target;
|
|
321
|
+
private anchor;
|
|
322
|
+
private revision;
|
|
323
|
+
private local;
|
|
324
|
+
private readonly retained;
|
|
325
|
+
private readonly tombstones;
|
|
326
|
+
private readonly filtered;
|
|
327
|
+
private readonly inSession;
|
|
328
|
+
private pages;
|
|
329
|
+
private localPending;
|
|
330
|
+
private localStamp;
|
|
331
|
+
private localError;
|
|
332
|
+
private apiError;
|
|
333
|
+
private apiPending;
|
|
334
|
+
private apiFailed;
|
|
335
|
+
private offline;
|
|
336
|
+
private generation;
|
|
337
|
+
private watchGeneration;
|
|
338
|
+
private lastLocalWatch;
|
|
339
|
+
private refs;
|
|
340
|
+
private activeRefs;
|
|
341
|
+
private readonly checkpointRefresh;
|
|
342
|
+
private localAbort;
|
|
343
|
+
private ready;
|
|
344
|
+
private disposed;
|
|
345
|
+
private unwatch;
|
|
346
|
+
private stops;
|
|
347
|
+
private request;
|
|
348
|
+
private requestKey;
|
|
349
|
+
constructor(deps: QueryDeps, options: InfiniteQueryOptions<T>);
|
|
350
|
+
get isDisposed(): boolean;
|
|
351
|
+
retain(active?: boolean): void;
|
|
352
|
+
release(active?: boolean): void;
|
|
353
|
+
swapRoot(): void;
|
|
354
|
+
dispose(): void;
|
|
355
|
+
private pause;
|
|
356
|
+
private readOffline;
|
|
357
|
+
private cancelRequest;
|
|
358
|
+
private networkChanged;
|
|
359
|
+
private identity;
|
|
360
|
+
private pending;
|
|
361
|
+
private localBuilder;
|
|
362
|
+
private watch;
|
|
363
|
+
private acceptLocal;
|
|
364
|
+
private checkpoint;
|
|
365
|
+
private clearPages;
|
|
366
|
+
private apiEnd;
|
|
367
|
+
private apiCount;
|
|
368
|
+
private apiCursor;
|
|
369
|
+
private cursorKey;
|
|
370
|
+
private pump;
|
|
371
|
+
private entries;
|
|
372
|
+
private result;
|
|
373
|
+
private render;
|
|
374
|
+
readonly fetchNextPage: () => void;
|
|
375
|
+
readonly retry: () => void;
|
|
376
|
+
readonly refresh: () => void;
|
|
377
|
+
readonly continueOlder: () => void;
|
|
378
|
+
private reset;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
type FlagState = 'idle' | 'flagging' | 'syncing' | 'synced' | 'timeout' | 'error';
|
|
382
|
+
interface FlaggerConfig {
|
|
383
|
+
/** App-supplied backend call, e.g. POST /sync/flag. */
|
|
384
|
+
readonly requestFlag: (ids: readonly string[]) => Promise<void>;
|
|
385
|
+
/** Stream whose JOIN reads the per-user sync_requests table. */
|
|
386
|
+
readonly stream: string;
|
|
387
|
+
/** Table the flagged rows land in (for presence detection). */
|
|
388
|
+
readonly table: string;
|
|
389
|
+
readonly timeoutMs?: number;
|
|
390
|
+
}
|
|
391
|
+
interface FlagResult {
|
|
392
|
+
readonly state: FlagState;
|
|
393
|
+
readonly error?: Error;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* OPTIONAL primitive (§7): client-triggered, per-user server-side flagging. Use only for bucket
|
|
397
|
+
* economy or server-decided membership; `useOnDemandStream` is the default single-row path.
|
|
398
|
+
* `synced` is detected by watching the SPECIFIC requested ids, never by waitForFirstSync.
|
|
399
|
+
*/
|
|
400
|
+
declare class AutoSyncFlagStore {
|
|
401
|
+
private readonly driver;
|
|
402
|
+
private readonly clock;
|
|
403
|
+
private readonly config;
|
|
404
|
+
private readonly ids;
|
|
405
|
+
readonly store: SnapshotStore<FlagResult>;
|
|
406
|
+
private handle;
|
|
407
|
+
private unsubStatus;
|
|
408
|
+
private cancelTimeout;
|
|
409
|
+
private disposed;
|
|
410
|
+
private refs;
|
|
411
|
+
constructor(driver: BridgeDriver, clock: BridgeClock, config: FlaggerConfig, ids: readonly string[]);
|
|
412
|
+
retain(): void;
|
|
413
|
+
release(): void;
|
|
414
|
+
get isDisposed(): boolean;
|
|
415
|
+
swapRoot(): void;
|
|
416
|
+
dispose(): void;
|
|
417
|
+
private start;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Identity is DERIVED from the JWT the connector returns, never supplied by the app (R15, [DX]).
|
|
422
|
+
* The key is the canonical JSON of the stable claims — a cache key, not a hash.
|
|
423
|
+
*/
|
|
424
|
+
declare const DEFAULT_VOLATILE_CLAIMS: readonly string[];
|
|
425
|
+
declare function decodeJwtPayload(token: string): Record<string, unknown>;
|
|
426
|
+
interface IdentityKeyOptions {
|
|
427
|
+
readonly denyList?: readonly string[];
|
|
428
|
+
/** Connection parameters opted in BY KEY (rotating values must be excluded explicitly). */
|
|
429
|
+
readonly connectionParams?: Record<string, unknown>;
|
|
430
|
+
}
|
|
431
|
+
declare function identityKeyFromClaims(claims: Record<string, unknown>, opts?: IdentityKeyOptions): string;
|
|
432
|
+
declare function identityKeyFromToken(token: string, opts?: IdentityKeyOptions): string;
|
|
433
|
+
|
|
434
|
+
interface InfiniteDeps {
|
|
435
|
+
readonly driver: BridgeDriver;
|
|
436
|
+
readonly adapter: QueryAdapter;
|
|
437
|
+
readonly clock: BridgeClock;
|
|
438
|
+
readonly onEvicted?: ((ids: readonly string[]) => void) | undefined;
|
|
439
|
+
}
|
|
440
|
+
declare function emptyInfiniteResult<T>(): InfiniteListResult<T>;
|
|
441
|
+
/**
|
|
442
|
+
* The infinite list engine (§6.2): one global id set, a loaded-range local watch, and bounded
|
|
443
|
+
* escalation through equality partitions or API pages.
|
|
444
|
+
*/
|
|
445
|
+
declare class InfiniteListStore<TItem, TScope, K extends OrderKey<TItem>, TCursor, TPartition> {
|
|
446
|
+
private readonly deps;
|
|
447
|
+
private readonly def;
|
|
448
|
+
private readonly scope;
|
|
449
|
+
readonly store: SnapshotStore<InfiniteListResult<TItem>>;
|
|
450
|
+
private readonly compare;
|
|
451
|
+
private readonly table;
|
|
452
|
+
private readonly abort;
|
|
453
|
+
private pages;
|
|
454
|
+
private local;
|
|
455
|
+
private lookahead;
|
|
456
|
+
private emissionSeen;
|
|
457
|
+
private localError;
|
|
458
|
+
private unsubDiffs;
|
|
459
|
+
private readonly apiRows;
|
|
460
|
+
private readonly retained;
|
|
461
|
+
private readonly tombstones;
|
|
462
|
+
private readonly subs;
|
|
463
|
+
private readonly lru;
|
|
464
|
+
private probeCursor;
|
|
465
|
+
private serverFloor;
|
|
466
|
+
private floorRevalidated;
|
|
467
|
+
private boundary;
|
|
468
|
+
private reason;
|
|
469
|
+
private awaitingSync;
|
|
470
|
+
private loading;
|
|
471
|
+
private localPagePending;
|
|
472
|
+
private errors;
|
|
473
|
+
private warnings;
|
|
474
|
+
private errorCount;
|
|
475
|
+
private nextRetryAt;
|
|
476
|
+
private disposed;
|
|
477
|
+
private refs;
|
|
478
|
+
constructor(deps: InfiniteDeps, def: InfiniteListDefinition<TItem, TScope, K, TCursor, TPartition>, scope: TScope);
|
|
479
|
+
retain(): void;
|
|
480
|
+
release(): void;
|
|
481
|
+
get isDisposed(): boolean;
|
|
482
|
+
swapRoot(): void;
|
|
483
|
+
dispose(): void;
|
|
484
|
+
private subscribeLocal;
|
|
485
|
+
private onDiff;
|
|
486
|
+
private provenance;
|
|
487
|
+
private applyRemovals;
|
|
488
|
+
private lastCursor;
|
|
489
|
+
/** Explicit user retry clears the backoff (R16). */
|
|
490
|
+
retry(): Promise<void>;
|
|
491
|
+
loadMore(): Promise<void>;
|
|
492
|
+
private setUnknown;
|
|
493
|
+
private escalatePartition;
|
|
494
|
+
private finishEnd;
|
|
495
|
+
private track;
|
|
496
|
+
private untrack;
|
|
497
|
+
private apiGate;
|
|
498
|
+
private apiFailure;
|
|
499
|
+
private escalateApi;
|
|
500
|
+
private escalateOffset;
|
|
501
|
+
private absorbApi;
|
|
502
|
+
private mergedEntries;
|
|
503
|
+
private render;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
interface OnDemandOptions {
|
|
507
|
+
readonly ttl?: number;
|
|
508
|
+
readonly priority?: 0 | 1 | 2 | 3;
|
|
509
|
+
readonly timeoutMs?: number;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* The default "pull one row" primitive (§7, [DX]): a plain on-demand equality-parameter stream.
|
|
513
|
+
* Held while retained; the TTL keeps rows warm after release.
|
|
514
|
+
*/
|
|
515
|
+
declare class OnDemandStreamStore {
|
|
516
|
+
private readonly driver;
|
|
517
|
+
private readonly clock;
|
|
518
|
+
private readonly name;
|
|
519
|
+
private readonly params;
|
|
520
|
+
private readonly opts;
|
|
521
|
+
readonly store: SnapshotStore<OnDemandResult>;
|
|
522
|
+
private handle;
|
|
523
|
+
private readonly abort;
|
|
524
|
+
private refs;
|
|
525
|
+
private disposed;
|
|
526
|
+
constructor(driver: BridgeDriver, clock: BridgeClock, name: string, params: Params | null, opts: OnDemandOptions);
|
|
527
|
+
retain(): void;
|
|
528
|
+
release(): void;
|
|
529
|
+
get isDisposed(): boolean;
|
|
530
|
+
swapRoot(): void;
|
|
531
|
+
dispose(): void;
|
|
532
|
+
private start;
|
|
533
|
+
}
|
|
534
|
+
|
|
390
535
|
type Platform = 'web' | 'native';
|
|
391
536
|
type RacePolicy = 'race' | 'local-first';
|
|
392
537
|
interface PlatformGates {
|
|
@@ -429,10 +574,12 @@ declare class Bridge {
|
|
|
429
574
|
readonly clock: BridgeClock;
|
|
430
575
|
/** Increments on every identity swap; hooks subscribe to re-acquire their stores. */
|
|
431
576
|
readonly epochStore: Store<number>;
|
|
577
|
+
readonly connectivity: SnapshotStore<boolean | undefined>;
|
|
432
578
|
private readonly identity;
|
|
433
579
|
private readonly freshness;
|
|
434
580
|
private readonly crud;
|
|
435
581
|
private readonly snapshots;
|
|
582
|
+
private readonly backgroundReads;
|
|
436
583
|
private readonly epochSnapshot;
|
|
437
584
|
private readonly stores;
|
|
438
585
|
private readonly gates;
|
|
@@ -440,9 +587,14 @@ declare class Bridge {
|
|
|
440
587
|
private readonly identityOpts;
|
|
441
588
|
private readonly onEvicted;
|
|
442
589
|
private disposed;
|
|
590
|
+
private readonly onNetwork;
|
|
443
591
|
constructor(opts: BridgeOptions);
|
|
444
592
|
get epoch(): number;
|
|
445
593
|
get identityKey(): string | null;
|
|
594
|
+
setOnline(online: boolean | undefined): void;
|
|
595
|
+
query<T extends {
|
|
596
|
+
id: string;
|
|
597
|
+
}>(options: InfiniteQueryOptions<T>): InfiniteQueryStore<T>;
|
|
446
598
|
/** Resolves once the initial upload-queue read has landed (tests). */
|
|
447
599
|
ready(): Promise<void>;
|
|
448
600
|
/** Connect THROUGH the bridge so identity is derived from every token the connector produces. */
|
|
@@ -493,4 +645,4 @@ interface RemovalContext<T> {
|
|
|
493
645
|
declare function probePresence(driver: BridgeDriver, table: string, ids: readonly string[]): Promise<Set<string>>;
|
|
494
646
|
declare function classifyRemovals<T>(ctx: RemovalContext<T>, removed: ReadonlyMap<string, T>): Promise<Map<string, RemovalClass>>;
|
|
495
647
|
|
|
496
|
-
export { AutoSyncFlagStore, Bridge, BridgeClock, BridgeDriver, type BridgeOptions, type ConnectorLike, CrudDelta, CursorOf, DEFAULT_VOLATILE_CLAIMS, type FlagResult, type FlagState, type FlaggerConfig, type IdentityKeyOptions, InfiniteListDefinition, InfiniteListResult, InfiniteListStore, KeyOf, MeasureSink, type MinimalQueryClient, type OnDemandOptions, OnDemandResult, OnDemandStreamStore, OpaqueCursor, OrderKey, Params, PendingOpRef, type Platform, type PlatformGates, QueryAdapter, type RacePolicy, RacedListDefinition, RacedListResult, RacedListStore, type RemovalClass, SnapshotStore, SortDirection, Store, StreamDescription, classifyRemovals, createBridge, cursorOfRow, decodeCursor, decodeJwtPayload, defineInfiniteList, defineRacedList, emptyInfiniteResult, emptyRacedResult, encodeCursor, identityKeyFromClaims, identityKeyFromToken, keyColumns, probePresence, rowComparator };
|
|
648
|
+
export { AutoSyncFlagStore, Bridge, BridgeClock, BridgeDriver, type BridgeOptions, type ConnectorLike, CrudDelta, CursorOf, DEFAULT_VOLATILE_CLAIMS, type FlagResult, type FlagState, type FlaggerConfig, type IdentityKeyOptions, InfiniteListDefinition, InfiniteListResult, InfiniteListStore, type InfiniteQueryOptions, type InfiniteQueryResult, InfiniteQueryStore, KeyOf, ListErrors, MeasureSink, type MinimalQueryClient, OfflineError, type OnDemandOptions, OnDemandResult, OnDemandStreamStore, OpaqueCursor, OrderKey, PagedRow, Params, PendingOpRef, type Platform, type PlatformGates, QueryAdapter, type QueryPage, type RacePolicy, RacedListDefinition, RacedListResult, RacedListStore, type RemovalClass, RowsBuilder, SnapshotStore, SortDirection, Store, StreamDescription, classifyRemovals, createBridge, cursorOfRow, decodeCursor, decodeJwtPayload, defineInfiniteList, defineRacedList, emptyInfiniteResult, emptyRacedResult, encodeCursor, identityKeyFromClaims, identityKeyFromToken, infiniteQueryKey, keyColumns, probePresence, rowComparator };
|