@powersync/react 0.0.0-dev-20261015114518 → 0.0.0-dev-20261020125654

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.
Files changed (36) hide show
  1. package/lib/QueryStore.d.ts +10 -0
  2. package/lib/QueryStore.js +63 -0
  3. package/lib/QueryStore.js.map +1 -0
  4. package/lib/hooks/suspense/suspense-utils.d.ts +16 -0
  5. package/lib/hooks/suspense/suspense-utils.js +76 -0
  6. package/lib/hooks/suspense/suspense-utils.js.map +1 -0
  7. package/lib/hooks/suspense/useSingleSuspenseQuery.d.ts +10 -0
  8. package/lib/hooks/suspense/useSingleSuspenseQuery.js +70 -0
  9. package/lib/hooks/suspense/useSingleSuspenseQuery.js.map +1 -0
  10. package/lib/hooks/suspense/useSuspenseQuery.d.ts +3 -3
  11. package/lib/hooks/suspense/useSuspenseQuery.js +7 -28
  12. package/lib/hooks/suspense/useSuspenseQuery.js.map +1 -1
  13. package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js +24 -60
  14. package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js.map +1 -1
  15. package/lib/hooks/suspense/useWatchedSuspenseQuery.d.ts +6 -0
  16. package/lib/hooks/suspense/useWatchedSuspenseQuery.js +23 -0
  17. package/lib/hooks/suspense/useWatchedSuspenseQuery.js.map +1 -0
  18. package/lib/hooks/watched/QueryRunner.d.ts +4 -15
  19. package/lib/hooks/watched/QueryRunner.js +9 -35
  20. package/lib/hooks/watched/QueryRunner.js.map +1 -1
  21. package/lib/hooks/watched/watch-types.d.ts +1 -18
  22. package/lib/index.d.ts +1 -1
  23. package/package.json +5 -5
  24. package/src/QueryStore.ts +81 -0
  25. package/src/hooks/suspense/suspense-utils.ts +86 -0
  26. package/src/hooks/suspense/useSingleSuspenseQuery.ts +78 -0
  27. package/src/hooks/suspense/useSuspenseQuery.ts +13 -40
  28. package/src/hooks/suspense/useWatchedQuerySuspenseSubscription.ts +25 -65
  29. package/src/hooks/suspense/useWatchedSuspenseQuery.ts +33 -0
  30. package/src/hooks/watched/QueryRunner.ts +11 -40
  31. package/src/hooks/watched/watch-types.ts +1 -20
  32. package/src/index.ts +1 -7
  33. package/lib/hooks/suspense/SuspenseQueryCache.d.ts +0 -46
  34. package/lib/hooks/suspense/SuspenseQueryCache.js +0 -231
  35. package/lib/hooks/suspense/SuspenseQueryCache.js.map +0 -1
  36. package/src/hooks/suspense/SuspenseQueryCache.ts +0 -253
@@ -17,7 +17,7 @@ import { WatchCompatibleQueryWithParams } from './watch-utils.js';
17
17
 
18
18
  // We want to generate readonly results, but declare mutable results when useQuery is used without differential hooks
19
19
  // for backwards compatibility.
20
- export type Result<RowType> = QueryResult<RowType> | ReadonlyQueryResult<RowType>;
20
+ type Result<RowType> = QueryResult<RowType> | ReadonlyQueryResult<RowType>;
21
21
 
22
22
  /**
23
23
  * The configured state a {@link QueryRunner} is in.
@@ -33,7 +33,7 @@ export type RunnerConfig<RowType> =
33
33
  | { kind: 'compile-error'; error: Error }
34
34
  | QueryConfig<RowType>;
35
35
 
36
- export interface QueryConfig<RowType> {
36
+ interface QueryConfig<RowType> {
37
37
  kind: 'query';
38
38
  db: CommonPowerSyncDatabase;
39
39
  query: WatchCompatibleQueryWithParams<RowType[]>;
@@ -72,22 +72,6 @@ function configEquals<RowType>(a: RunnerConfig<RowType>, b: RunnerConfig<RowType
72
72
  }
73
73
  }
74
74
 
75
- /**
76
- * Returns a string identifying a query config, such that two configs have the same key if {@link configEquals} considers
77
- * them equal (apart from the database, which callers are expected to scope keys to).
78
- */
79
- export function configKey<RowType>(config: QueryConfig<RowType>): string {
80
- const { runOnce, rowComparator, throttleMs, reportFetching, sql, stringifiedParams } = config;
81
- return JSON.stringify([runOnce, !!rowComparator, throttleMs ?? null, reportFetching, sql, stringifiedParams]);
82
- }
83
-
84
- /**
85
- * For configs that can't run a query, returns the error to report.
86
- */
87
- export function configError<RowType>(config: Exclude<RunnerConfig<RowType>, QueryConfig<RowType>>): Error | null {
88
- return idleResultFor(config).error ?? null;
89
- }
90
-
91
75
  const _loadingState: QueryResult<never> = { isLoading: true, isFetching: false, data: [], error: undefined };
92
76
 
93
77
  function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType> {
@@ -234,20 +218,16 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
234
218
  * Applies the inputs of a committed render to this runner. This does nothing if they haven't changed.
235
219
  *
236
220
  * This modifies state and should not run during a render.
237
- *
238
- * `initial` can be an existing result from another runner. This is used for one-shot suspense queries where state is
239
- * only shared in the initial loading state and then forked to give each component an independent runner.
240
221
  */
241
- configure(next: RunnerConfig<RowType>, initial?: Result<RowType>) {
222
+ configure(next: RunnerConfig<RowType>) {
242
223
  if (this.config != null && configEquals(this.config, next)) {
243
224
  return;
244
225
  }
245
226
 
246
227
  const pending = this.uncommitedConfigChange;
247
228
  this.config = next;
248
- this.idleResult = initial
249
- ? initial
250
- : pending != null && pending.isOptimisticStateChange && configEquals(pending.config, next)
229
+ this.idleResult =
230
+ pending != null && pending.isOptimisticStateChange && configEquals(pending.config, next)
251
231
  ? // We already returned this as an optimistic state in a previous resultFor call. Use the same result to not
252
232
  // cause another render.
253
233
  pending.result
@@ -307,25 +287,18 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
307
287
  initial: Result<RowType>,
308
288
  private readonly emit: () => void
309
289
  ) {
310
- if (!initial.isLoading && initial.error == null) {
311
- // Seeded with an existing result, no need to run it again.
312
- this.result = { ...(initial as QueryResult<RowType>), refresh: this.refresh };
313
- return;
314
- }
315
-
316
- const fetchReason = 'initial';
317
290
  this.result = {
318
291
  ...(initial as QueryResult<RowType>),
319
292
  isFetching: true,
320
- fetchReason,
293
+ fetchReason: 'initial',
321
294
  refresh: this.refresh
322
295
  };
323
- this.run(fetchReason);
296
+ this.run();
324
297
  }
325
298
 
326
299
  readonly refresh = async (signal?: AbortSignal) => {
327
300
  if (this.disposed) return;
328
- await this.run('refresh', signal);
301
+ await this.run(signal);
329
302
  };
330
303
 
331
304
  private setResult(update: Partial<QueryResult<RowType>>) {
@@ -333,16 +306,14 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
333
306
  this.emit();
334
307
  }
335
308
 
336
- private async run(fetchReason: FetchReason, outerSignal?: AbortSignal) {
309
+ private async run(outerSignal?: AbortSignal) {
337
310
  this.abortController?.abort();
338
311
  const controller = (this.abortController = new AbortController());
339
312
  const signal = controller.signal;
340
313
  const isAborted = () => signal.aborted || outerSignal?.aborted == true;
341
314
 
342
- if (!this.result.isLoading || this.result.error) {
343
- // After an error, data is empty, so we're loading again rather than refreshing existing rows.
344
- const isLoading = fetchReason === 'initial' || this.result.error != null;
345
- this.setResult({ isLoading, isFetching: true, error: undefined, fetchReason });
315
+ if (!this.result.isLoading || !this.result.isFetching || this.result.error) {
316
+ this.setResult({ isLoading: true, isFetching: true, error: undefined, fetchReason: 'initial' });
346
317
  }
347
318
 
348
319
  const { query, sql, parameters, db } = this.config;
@@ -56,34 +56,15 @@ export interface DifferentialHookOptions<RowType> extends HookWatchOptions {
56
56
  rowComparator?: DifferentialWatchedQueryComparator<RowType>;
57
57
  }
58
58
 
59
- type WithoutSyncStreams<T> = Omit<T, 'streams'> & {
60
- /**
61
- * @deprecated Sync streams are not supported by `useSuspenseQuery` and are ignored. Use `useQuery` or
62
- * `useSyncStream` to subscribe to streams instead.
63
- */
64
- streams?: QuerySyncStreamOptions[];
65
- };
66
-
67
- /**
68
- * Options for `useSuspenseQuery`.
69
- */
70
- export type SuspenseQueryOptions = WithoutSyncStreams<AdditionalOptions>;
71
-
72
- /**
73
- * Options for `useSuspenseQuery` with a `rowComparator`.
74
- */
75
- export type DifferentialSuspenseQueryOptions<RowType> = WithoutSyncStreams<DifferentialHookOptions<RowType>>;
76
-
77
59
  /**
78
60
  * Why a `useQuery` hook is currently fetching.
79
61
  *
80
62
  * - `'initial'`: the first load of this query, `isLoading` is true as well.
81
- * - `refresh`: `QueryResult.refresh` was called.
82
63
  * - `'tables-changed'`: a table the query depends on changed and the same query is re-running. `data` is still current.
83
64
  * - `'settings-changed'`: the SQL, parameters or options changed. `data` still holds the previous query's rows until the
84
65
  * updated query has produced its first result.
85
66
  */
86
- export type FetchReason = 'initial' | 'refresh' | 'tables-changed' | 'settings-changed';
67
+ export type FetchReason = 'initial' | 'tables-changed' | 'settings-changed';
87
68
 
88
69
  export type ReadonlyQueryResult<RowType> = {
89
70
  readonly data: ReadonlyArray<Readonly<RowType>>;
package/src/index.ts CHANGED
@@ -6,10 +6,4 @@ export { useAllSyncStreamsHaveSynced, useSyncStream, UseSyncStreamOptions } from
6
6
  export { useStatus } from './hooks/useStatus.js';
7
7
  export { useQuery } from './hooks/watched/useQuery.js';
8
8
  export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription.js';
9
- export {
10
- AdditionalOptions,
11
- FetchReason,
12
- DifferentialSuspenseQueryOptions,
13
- QuerySyncStreamOptions,
14
- SuspenseQueryOptions
15
- } from './hooks/watched/watch-types.js';
9
+ export { AdditionalOptions, FetchReason, QuerySyncStreamOptions } from './hooks/watched/watch-types.js';
@@ -1,46 +0,0 @@
1
- import { CommonPowerSyncDatabase } from '@powersync/common';
2
- import { QueryConfig, Result } from '../watched/QueryRunner.js';
3
- /**
4
- * How long a query checked out by a render stays alive after it has loaded, if no component subscribes to it.
5
- *
6
- * React may take a while to commit a component after its suspending promise resolves (at least 300ms), so this should
7
- * be generous.
8
- */
9
- export declare const TEMPORARY_HOLD_MS = 5000;
10
- /**
11
- * Shares {@link QueryRunner}s between suspending hooks.
12
- *
13
- * Components that suspend before their first commit lose all their state, so the runner for a query can't be stored
14
- * in the component. Instead, rendering checks out the entry for a query from this cache. Checking out an entry places a
15
- * temporary hold on it, which runs the query and keeps it alive until a component has committed and subscribed to it
16
- * (or until the hold expires, e.g. because the render was discarded).
17
- *
18
- * An entry is alive exactly while it is held or has subscribers, and the cache maps each query to at most one entry.
19
- * Hooks never reference entries directly, they use a {@link SuspenseQuery} handle that looks up the current entry for
20
- * its query (creating it if necessary) and then sticks to that entry while it's alive.
21
- *
22
- * Watched queries are shared between all components using them. Queries that only run once are shared only until a
23
- * component commits with their results: We want a suspending hook to obtain the same query when its render is retried,
24
- * but components that have committed must be able to refresh independently, and components mounting later shouldn't
25
- * see stale results. So the first component committing with a one-shot entry claims it, which evicts it from the cache.
26
- * Other components that rendered with the same entry (e.g. siblings in the same suspense boundary) continue with their
27
- * own runner, seeded with the loaded result.
28
- */
29
- declare class SuspenseQueryCache {
30
- private readonly entries;
31
- /**
32
- * Returns a handle for the given query. Creating handles has no side effects.
33
- */
34
- query<RowType>(key: string, config: QueryConfig<RowType>): {
35
- markUsed: () => void;
36
- subscribe: (onChange: () => void) => (() => void);
37
- getSnapshot: () => Result<RowType>;
38
- waitForLoaded: () => Promise<void>;
39
- };
40
- /**
41
- * Returns the entry for the given query after placing a temporary hold on it, creating it if necessary.
42
- */
43
- private checkOut;
44
- }
45
- export declare function getSuspenseQueryCache(db: CommonPowerSyncDatabase): SuspenseQueryCache;
46
- export {};
@@ -1,231 +0,0 @@
1
- import { QueryRunner } from '../watched/QueryRunner.js';
2
- /**
3
- * How long a query checked out by a render stays alive after it has loaded, if no component subscribes to it.
4
- *
5
- * React may take a while to commit a component after its suspending promise resolves (at least 300ms), so this should
6
- * be generous.
7
- */
8
- export const TEMPORARY_HOLD_MS = 5_000;
9
- /**
10
- * Shares {@link QueryRunner}s between suspending hooks.
11
- *
12
- * Components that suspend before their first commit lose all their state, so the runner for a query can't be stored
13
- * in the component. Instead, rendering checks out the entry for a query from this cache. Checking out an entry places a
14
- * temporary hold on it, which runs the query and keeps it alive until a component has committed and subscribed to it
15
- * (or until the hold expires, e.g. because the render was discarded).
16
- *
17
- * An entry is alive exactly while it is held or has subscribers, and the cache maps each query to at most one entry.
18
- * Hooks never reference entries directly, they use a {@link SuspenseQuery} handle that looks up the current entry for
19
- * its query (creating it if necessary) and then sticks to that entry while it's alive.
20
- *
21
- * Watched queries are shared between all components using them. Queries that only run once are shared only until a
22
- * component commits with their results: We want a suspending hook to obtain the same query when its render is retried,
23
- * but components that have committed must be able to refresh independently, and components mounting later shouldn't
24
- * see stale results. So the first component committing with a one-shot entry claims it, which evicts it from the cache.
25
- * Other components that rendered with the same entry (e.g. siblings in the same suspense boundary) continue with their
26
- * own runner, seeded with the loaded result.
27
- */
28
- class SuspenseQueryCache {
29
- entries = new Map();
30
- /**
31
- * Returns a handle for the given query. Creating handles has no side effects.
32
- */
33
- query(key, config) {
34
- let entry = null;
35
- // For one-shot queries, a runner owned by this handle after another one claimed the shared entry.
36
- let settledOneShotFork = null;
37
- const current = () => {
38
- if (entry == null || entry.isRemoved) {
39
- entry = this.entries.get(key) ?? this.checkOut(key, config);
40
- }
41
- return entry;
42
- };
43
- const handle = {
44
- markUsed: () => {
45
- if (settledOneShotFork != null) {
46
- return;
47
- }
48
- else if (entry == null || entry.isRemoved) {
49
- entry = this.checkOut(key, config);
50
- }
51
- else {
52
- entry.ensureHeld();
53
- }
54
- },
55
- subscribe: (onChange) => {
56
- if (settledOneShotFork == null) {
57
- const shared = current();
58
- if (shared.claim(handle)) {
59
- return shared.subscribe(onChange);
60
- }
61
- settledOneShotFork = new QueryRunner();
62
- settledOneShotFork.configure(config, shared.getSnapshot());
63
- }
64
- return settledOneShotFork.subscribe(onChange);
65
- },
66
- getSnapshot: () => {
67
- return (settledOneShotFork ?? current()).getSnapshot();
68
- },
69
- waitForLoaded: () => {
70
- return current().loaded;
71
- }
72
- };
73
- return handle;
74
- }
75
- /**
76
- * Returns the entry for the given query after placing a temporary hold on it, creating it if necessary.
77
- */
78
- checkOut(key, config) {
79
- let entry = this.entries.get(key);
80
- if (entry == null) {
81
- const created = new SuspenseQueryEntry(config, () => {
82
- // A claimed entry may have been replaced already, don't evict its replacement.
83
- if (this.entries.get(key) === created) {
84
- this.entries.delete(key);
85
- }
86
- });
87
- this.entries.set(key, created);
88
- entry = created;
89
- }
90
- entry.ensureHeld();
91
- return entry;
92
- }
93
- }
94
- class SuspenseQueryEntry {
95
- evict;
96
- runner = new QueryRunner();
97
- /**
98
- * The number of subscribed components, not counting the temporary hold.
99
- */
100
- subscribers = 0;
101
- releaseHold = null;
102
- holdTimeout = null;
103
- pendingLoad = null;
104
- runOnce;
105
- /**
106
- * For one-shot queries, the handle of the component that has committed with this entry.
107
- */
108
- owner = null;
109
- /**
110
- * Set once this entry is neither held nor subscribed to. Its runner is idle then, and it must not be used again.
111
- */
112
- isRemoved = false;
113
- constructor(config,
114
- /**
115
- * Evicts this entry from the cache, called once it's removed or claimed.
116
- */
117
- evict) {
118
- this.evict = evict;
119
- this.runOnce = config.runOnce;
120
- // We call configure once here, and then never again. A changed config is represented by a fresh query entry
121
- // (necessary to potentially re-use this across components).
122
- this.runner.configure(config);
123
- }
124
- /**
125
- * Called before a committed component subscribes through the given handle. Returns whether it may subscribe to this
126
- * entry, or whether it needs to use its own runner instead.
127
- *
128
- * Watched queries can always be shared. For queries running once, the first committing component takes ownership of
129
- * this entry, so that refreshing it doesn't affect other components and components mounting later don't get its
130
- * (potentially stale) result.
131
- */
132
- claim(handle) {
133
- if (!this.runOnce) {
134
- return true;
135
- }
136
- if (this.owner == null) {
137
- this.owner = handle;
138
- this.evict();
139
- }
140
- // In StrictMode, React unsubscribes and resubscribes right away, so the owner may claim this entry again.
141
- return this.owner === handle;
142
- }
143
- subscribe(onChange) {
144
- this.subscribers++;
145
- // Note that we don't release the temporary hold here: In StrictMode, React unsubscribes and resubscribes right
146
- // away, which would otherwise dispose and restart the query. The hold expires on its own shortly after loading.
147
- const unsubscribe = this.runner.subscribe(() => {
148
- this.onRunnerChange();
149
- onChange();
150
- });
151
- return () => {
152
- unsubscribe();
153
- this.subscribers--;
154
- this.removeIfUnused();
155
- };
156
- }
157
- getSnapshot() {
158
- return this.runner.getSnapshot();
159
- }
160
- /**
161
- * A promise to throw while the query is loading. It's stable until the query has loaded, and resolves once the
162
- * query has a result or an error.
163
- */
164
- get loaded() {
165
- if (this.isSettled) {
166
- return Promise.resolve();
167
- }
168
- if (this.pendingLoad == null) {
169
- let resolve;
170
- const promise = new Promise((r) => (resolve = r));
171
- this.pendingLoad = { promise, resolve };
172
- }
173
- return this.pendingLoad.promise;
174
- }
175
- /**
176
- * Places a temporary hold on this entry for a render that checked it out, or extends the existing one.
177
- *
178
- * We do this even if components are subscribed already, since they might unsubscribe before the render checking
179
- * out this entry commits (e.g. when one component unmounts while another one using the same query mounts).
180
- */
181
- ensureHeld() {
182
- if (this.releaseHold == null) {
183
- // If this is the first listener, subscribing starts running the query. The runner then only notifies its own
184
- // listeners, which is just the hold. Otherwise, it doesn't notify anyone. So this is safe to call while rendering.
185
- this.releaseHold = this.runner.subscribe(() => this.onRunnerChange());
186
- }
187
- else if (this.holdTimeout != null) {
188
- // Restart the timer in onRunnerChange, so that the hold lasts until shortly after the latest checkout.
189
- clearTimeout(this.holdTimeout);
190
- this.holdTimeout = null;
191
- }
192
- this.onRunnerChange();
193
- }
194
- get isSettled() {
195
- const snapshot = this.runner.getSnapshot();
196
- return !snapshot.isLoading || snapshot.error != null;
197
- }
198
- onRunnerChange() {
199
- if (!this.isSettled) {
200
- return;
201
- }
202
- this.pendingLoad?.resolve();
203
- this.pendingLoad = null;
204
- if (this.releaseHold != null && this.holdTimeout == null) {
205
- this.holdTimeout = setTimeout(() => {
206
- this.holdTimeout = null;
207
- this.releaseHold?.();
208
- this.releaseHold = null;
209
- this.removeIfUnused();
210
- }, TEMPORARY_HOLD_MS);
211
- }
212
- }
213
- removeIfUnused() {
214
- if (this.subscribers == 0 && this.releaseHold == null) {
215
- // The runner has disposed its work since it has no listeners left.
216
- this.isRemoved = true;
217
- this.evict();
218
- }
219
- }
220
- }
221
- let caches;
222
- export function getSuspenseQueryCache(db) {
223
- caches ??= new WeakMap();
224
- let cache = caches.get(db);
225
- if (cache == null) {
226
- cache = new SuspenseQueryCache();
227
- caches.set(db, cache);
228
- }
229
- return cache;
230
- }
231
- //# sourceMappingURL=SuspenseQueryCache.js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