@powersync/react 0.0.0-dev-20251106124255 → 0.0.0-dev-20260202160933

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 (61) hide show
  1. package/package.json +9 -6
  2. package/lib/QueryStore.d.ts +0 -10
  3. package/lib/QueryStore.js +0 -63
  4. package/lib/QueryStore.js.map +0 -1
  5. package/lib/hooks/PowerSyncContext.d.ts +0 -21
  6. package/lib/hooks/PowerSyncContext.js +0 -21
  7. package/lib/hooks/PowerSyncContext.js.map +0 -1
  8. package/lib/hooks/deprecated/usePowerSyncQuery.d.ts +0 -7
  9. package/lib/hooks/deprecated/usePowerSyncQuery.js +0 -26
  10. package/lib/hooks/deprecated/usePowerSyncQuery.js.map +0 -1
  11. package/lib/hooks/deprecated/usePowerSyncStatus.d.ts +0 -15
  12. package/lib/hooks/deprecated/usePowerSyncStatus.js +0 -30
  13. package/lib/hooks/deprecated/usePowerSyncStatus.js.map +0 -1
  14. package/lib/hooks/deprecated/usePowerSyncWatchedQuery.d.ts +0 -17
  15. package/lib/hooks/deprecated/usePowerSyncWatchedQuery.js +0 -45
  16. package/lib/hooks/deprecated/usePowerSyncWatchedQuery.js.map +0 -1
  17. package/lib/hooks/streams.d.ts +0 -31
  18. package/lib/hooks/streams.js +0 -93
  19. package/lib/hooks/streams.js.map +0 -1
  20. package/lib/hooks/suspense/SuspenseQueryResult.d.ts +0 -3
  21. package/lib/hooks/suspense/SuspenseQueryResult.js +0 -2
  22. package/lib/hooks/suspense/SuspenseQueryResult.js.map +0 -1
  23. package/lib/hooks/suspense/suspense-utils.d.ts +0 -16
  24. package/lib/hooks/suspense/suspense-utils.js +0 -76
  25. package/lib/hooks/suspense/suspense-utils.js.map +0 -1
  26. package/lib/hooks/suspense/useSingleSuspenseQuery.d.ts +0 -10
  27. package/lib/hooks/suspense/useSingleSuspenseQuery.js +0 -73
  28. package/lib/hooks/suspense/useSingleSuspenseQuery.js.map +0 -1
  29. package/lib/hooks/suspense/useSuspenseQuery.d.ts +0 -53
  30. package/lib/hooks/suspense/useSuspenseQuery.js +0 -11
  31. package/lib/hooks/suspense/useSuspenseQuery.js.map +0 -1
  32. package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.d.ts +0 -23
  33. package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js +0 -52
  34. package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js.map +0 -1
  35. package/lib/hooks/suspense/useWatchedSuspenseQuery.d.ts +0 -6
  36. package/lib/hooks/suspense/useWatchedSuspenseQuery.js +0 -26
  37. package/lib/hooks/suspense/useWatchedSuspenseQuery.js.map +0 -1
  38. package/lib/hooks/useStatus.d.ts +0 -15
  39. package/lib/hooks/useStatus.js +0 -17
  40. package/lib/hooks/useStatus.js.map +0 -1
  41. package/lib/hooks/watched/useQuery.d.ts +0 -39
  42. package/lib/hooks/watched/useQuery.js +0 -43
  43. package/lib/hooks/watched/useQuery.js.map +0 -1
  44. package/lib/hooks/watched/useSingleQuery.d.ts +0 -6
  45. package/lib/hooks/watched/useSingleQuery.js +0 -59
  46. package/lib/hooks/watched/useSingleQuery.js.map +0 -1
  47. package/lib/hooks/watched/useWatchedQuery.d.ts +0 -13
  48. package/lib/hooks/watched/useWatchedQuery.js +0 -78
  49. package/lib/hooks/watched/useWatchedQuery.js.map +0 -1
  50. package/lib/hooks/watched/useWatchedQuerySubscription.d.ts +0 -20
  51. package/lib/hooks/watched/useWatchedQuerySubscription.js +0 -37
  52. package/lib/hooks/watched/useWatchedQuerySubscription.js.map +0 -1
  53. package/lib/hooks/watched/watch-types.d.ts +0 -87
  54. package/lib/hooks/watched/watch-types.js +0 -2
  55. package/lib/hooks/watched/watch-types.js.map +0 -1
  56. package/lib/hooks/watched/watch-utils.d.ts +0 -17
  57. package/lib/hooks/watched/watch-utils.js +0 -62
  58. package/lib/hooks/watched/watch-utils.js.map +0 -1
  59. package/lib/index.d.ts +0 -12
  60. package/lib/index.js +0 -11
  61. package/lib/index.js.map +0 -1
@@ -1,73 +0,0 @@
1
- import React from 'react';
2
- import { generateQueryKey, getQueryStore } from '../../QueryStore.js';
3
- import { usePowerSync } from '../PowerSyncContext.js';
4
- import { constructCompatibleQuery } from '../watched/watch-utils.js';
5
- import { createSuspendingPromise, useTemporaryHold } from './suspense-utils.js';
6
- /**
7
- * Use a query which is not watched, but suspends until the initial result has loaded.
8
- * Internally this uses a WatchedQuery during suspense for state management. The watched
9
- * query is potentially disposed, if there are no subscribers attached to it, after the initial load.
10
- * The query can be refreshed by calling the `refresh` function after initial load.
11
- */
12
- export const useSingleSuspenseQuery = (query, parameters = [], options = {}) => {
13
- const powerSync = usePowerSync();
14
- if (!powerSync) {
15
- throw new Error('PowerSync not configured.');
16
- }
17
- // Manually track data for single queries
18
- const [data, setData] = React.useState(null);
19
- const [error, setError] = React.useState(null);
20
- // Note, we don't need to check if the query changed since we fetch the WatchedQuery
21
- // from the store given these query params
22
- const { parsedQuery } = constructCompatibleQuery(query, parameters, options);
23
- const { sql: parsedSql, parameters: parsedParameters } = parsedQuery.compile();
24
- const key = generateQueryKey(parsedSql, parsedParameters, options);
25
- const store = getQueryStore(powerSync);
26
- // Only use a temporary watched query if we don't have data yet.
27
- const watchedQuery = data ? null : store.getQuery(key, parsedQuery, options);
28
- useTemporaryHold(watchedQuery);
29
- React.useEffect(() => {
30
- // Set the initial yielded data
31
- // it should be available once we commit the component
32
- if (watchedQuery?.state.error) {
33
- setError(watchedQuery.state.error);
34
- }
35
- else if (watchedQuery?.state.isLoading === false) {
36
- setData(watchedQuery.state.data);
37
- setError(null);
38
- }
39
- }, []);
40
- if (error != null) {
41
- // Report errors - this is caught by an error boundary
42
- throw error;
43
- }
44
- else if (data || watchedQuery?.state.isLoading === false) {
45
- // Happy path data return
46
- return {
47
- data: data ?? watchedQuery?.state.data ?? [],
48
- refresh: async (signal) => {
49
- try {
50
- const compiledQuery = parsedQuery.compile();
51
- const result = await parsedQuery.execute({
52
- sql: compiledQuery.sql,
53
- parameters: [...compiledQuery.parameters],
54
- db: powerSync
55
- });
56
- if (signal.aborted) {
57
- return; // Abort if the signal is already aborted
58
- }
59
- setData(result);
60
- setError(null);
61
- }
62
- catch (e) {
63
- setError(e);
64
- }
65
- }
66
- };
67
- }
68
- else {
69
- // Notify suspense is required
70
- throw createSuspendingPromise(watchedQuery);
71
- }
72
- };
73
- //# sourceMappingURL=useSingleSuspenseQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSingleSuspenseQuery.js","sourceRoot":"","sources":["../../../src/hooks/suspense/useSingleSuspenseQuery.ts"],"names":[],"mappings":"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"}
@@ -1,53 +0,0 @@
1
- import { CompilableQuery } from '@powersync/common';
2
- import { AdditionalOptions, DifferentialHookOptions } from '../watched/watch-types.js';
3
- import { ReadonlySuspenseQueryResult, SuspenseQueryResult } from './SuspenseQueryResult.js';
4
- /**
5
- * A hook to access the results of a watched query that suspends until the initial result has loaded.
6
- * @example
7
- * export const ContentComponent = () => {
8
- * // The lists array here will be a new Array reference whenever a change to the
9
- * // lists table is made.
10
- * const { data: lists } = useSuspenseQuery('SELECT * from lists');
11
- *
12
- * return <View>
13
- * {lists.map((l) => (
14
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
15
- * ))}
16
- * </View>;
17
- * }
18
- *
19
- * export const DisplayComponent = () => {
20
- * return (
21
- * <Suspense fallback={<div>Loading content...</div>}>
22
- * <ContentComponent />
23
- * </Suspense>
24
- * );
25
- * }
26
- *
27
- * export const DiffContentComponent = () => {
28
- * // A differential query will emit results when a change to the result set occurs.
29
- * // The internal array object references are maintained for unchanged rows.
30
- * // The returned lists array is read only when a `rowComparator` is provided.
31
- * const { data: lists } = useSuspenseQuery('SELECT * from lists', [], {
32
- * rowComparator: {
33
- * keyBy: (item) => item.id,
34
- * compareBy: (item) => JSON.stringify(item)
35
- * }
36
- * });
37
- * return <View>
38
- * {lists.map((l) => (
39
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
40
- * ))}
41
- * </View>;
42
- * }
43
- *
44
- * export const DisplayComponent = () => {
45
- * return (
46
- * <Suspense fallback={<div>Loading content...</div>}>
47
- * <ContentComponent />
48
- * </Suspense>
49
- * );
50
- * }
51
- */
52
- export declare function useSuspenseQuery<RowType = any>(query: string | CompilableQuery<RowType>, parameters?: any[], options?: AdditionalOptions): SuspenseQueryResult<RowType>;
53
- export declare function useSuspenseQuery<RowType = any>(query: string | CompilableQuery<RowType>, paramerers?: any[], options?: DifferentialHookOptions<RowType>): ReadonlySuspenseQueryResult<RowType>;
@@ -1,11 +0,0 @@
1
- import { useSingleSuspenseQuery } from './useSingleSuspenseQuery.js';
2
- import { useWatchedSuspenseQuery } from './useWatchedSuspenseQuery.js';
3
- export function useSuspenseQuery(query, parameters = [], options = {}) {
4
- switch (options?.runQueryOnce) {
5
- case true:
6
- return useSingleSuspenseQuery(query, parameters, options);
7
- default:
8
- return useWatchedSuspenseQuery(query, parameters, options);
9
- }
10
- }
11
- //# sourceMappingURL=useSuspenseQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/hooks/suspense/useSuspenseQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AA4DvE,MAAM,UAAU,gBAAgB,CAC9B,KAAwC,EACxC,aAAoB,EAAE,EACtB,UAAgE,EAAE;IAElE,QAAQ,OAAO,EAAE,YAAY,EAAE,CAAC;QAC9B,KAAK,IAAI;YACP,OAAO,sBAAsB,CAAU,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACrE;YACE,OAAO,uBAAuB,CAAU,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
@@ -1,23 +0,0 @@
1
- import { WatchedQuery } from '@powersync/common';
2
- /**
3
- * A hook to access and subscribe to the results of an existing {@link WatchedQuery}.
4
- * @example
5
- * export const ContentComponent = () => {
6
- * const { data: lists } = useWatchedQuerySuspenseSubscription(listsQuery);
7
- *
8
- * return <View>
9
- * {lists.map((l) => (
10
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
11
- * ))}
12
- * </View>;
13
- * }
14
- *
15
- * export const DisplayComponent = () => {
16
- * return (
17
- * <Suspense fallback={<div>Loading content...</div>}>
18
- * <ContentComponent />
19
- * </Suspense>
20
- * );
21
- * }
22
- */
23
- export declare const useWatchedQuerySuspenseSubscription: <ResultType = unknown, Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>>(query: Query) => Query["state"];
@@ -1,52 +0,0 @@
1
- import React from 'react';
2
- import { createSuspendingPromise, useTemporaryHold } from './suspense-utils.js';
3
- /**
4
- * A hook to access and subscribe to the results of an existing {@link WatchedQuery}.
5
- * @example
6
- * export const ContentComponent = () => {
7
- * const { data: lists } = useWatchedQuerySuspenseSubscription(listsQuery);
8
- *
9
- * return <View>
10
- * {lists.map((l) => (
11
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
12
- * ))}
13
- * </View>;
14
- * }
15
- *
16
- * export const DisplayComponent = () => {
17
- * return (
18
- * <Suspense fallback={<div>Loading content...</div>}>
19
- * <ContentComponent />
20
- * </Suspense>
21
- * );
22
- * }
23
- */
24
- export const useWatchedQuerySuspenseSubscription = (query) => {
25
- useTemporaryHold(query);
26
- // Force update state function
27
- const [, setUpdateCounter] = React.useState(0);
28
- React.useEffect(() => {
29
- // This runs when the component came out of suspense
30
- // This add a permanent hold since a listener has been added to the query
31
- const dispose = query.registerListener({
32
- onStateChange() {
33
- // Trigger rerender
34
- setUpdateCounter((prev) => prev + 1);
35
- }
36
- });
37
- return dispose;
38
- }, []);
39
- if (query.state.error != null) {
40
- // Report errors - this is caught by an error boundary
41
- throw query.state.error;
42
- }
43
- else if (!query.state.isLoading) {
44
- // Happy path data return
45
- return query.state;
46
- }
47
- else {
48
- // Notify suspense is required
49
- throw createSuspendingPromise(query);
50
- }
51
- };
52
- //# sourceMappingURL=useWatchedQuerySuspenseSubscription.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useWatchedQuerySuspenseSubscription.js","sourceRoot":"","sources":["../../../src/hooks/suspense/useWatchedQuerySuspenseSubscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAIjD,KAAY,EACI,EAAE;IAClB,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAExB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,gBAAgB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,oDAAoD;QACpD,yEAAyE;QACzE,MAAM,OAAO,GAAG,KAAK,CAAC,gBAAgB,CAAC;YACrC,aAAa;gBACX,mBAAmB;gBACnB,gBAAgB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YACvC,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QAC9B,sDAAsD;QACtD,MAAM,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;IAC1B,CAAC;SAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QAClC,yBAAyB;QACzB,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,8BAA8B;QAC9B,MAAM,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;AACH,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { CompilableQuery } from '@powersync/common';
2
- import { AdditionalOptions } from '../watched/watch-types.js';
3
- /**
4
- * @internal This is not exported in the index.ts
5
- */
6
- export declare const useWatchedSuspenseQuery: <T = any>(query: string | CompilableQuery<T>, parameters?: any[], options?: AdditionalOptions) => import("@powersync/common").WatchedQueryState<readonly Readonly<T>[]>;
@@ -1,26 +0,0 @@
1
- import { generateQueryKey, getQueryStore } from '../../QueryStore.js';
2
- import { usePowerSync } from '../PowerSyncContext.js';
3
- import { constructCompatibleQuery } from '../watched/watch-utils.js';
4
- import { useWatchedQuerySuspenseSubscription } from './useWatchedQuerySuspenseSubscription.js';
5
- /**
6
- * @internal This is not exported in the index.ts
7
- */
8
- export const useWatchedSuspenseQuery = (query, parameters = [], options = {}) => {
9
- const powerSync = usePowerSync();
10
- if (!powerSync) {
11
- throw new Error('PowerSync not configured.');
12
- }
13
- // Note, we don't need to check if the query changed since we fetch the WatchedQuery
14
- // from the store given these query params
15
- const { parsedQuery } = constructCompatibleQuery(query, parameters, options);
16
- const { sql: parsedSql, parameters: parsedParameters } = parsedQuery.compile();
17
- const key = generateQueryKey(parsedSql, parsedParameters, options);
18
- // When the component is suspended, all state is discarded. We don't get
19
- // any notification of that. So checkoutQuery reserves a temporary hold
20
- // on the query.
21
- // Once the component "commits", we exchange that for a permanent hold.
22
- const store = getQueryStore(powerSync);
23
- const watchedQuery = store.getQuery(key, parsedQuery, options);
24
- return useWatchedQuerySuspenseSubscription(watchedQuery);
25
- };
26
- //# sourceMappingURL=useWatchedSuspenseQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useWatchedSuspenseQuery.js","sourceRoot":"","sources":["../../../src/hooks/suspense/useWatchedSuspenseQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0CAA0C,CAAC;AAE/F;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,aAAoB,EAAE,EACtB,UAA6B,EAAE,EAC/B,EAAE;IACF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,oFAAoF;IACpF,0CAA0C;IAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,wBAAwB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7E,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;IAE/E,MAAM,GAAG,GAAG,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAEnE,wEAAwE;IACxE,uEAAuE;IACvE,gBAAgB;IAChB,uEAAuE;IACvE,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAE/D,OAAO,mCAAmC,CAAC,YAAY,CAAC,CAAC;AAC3D,CAAC,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Custom hook that provides access to the current status of PowerSync.
3
- * @returns The PowerSync Database status.
4
- * @example
5
- * import { useStatus } from "@powersync/react";
6
- *
7
- * const Component = () => {
8
- * const status = useStatus();
9
- *
10
- * return <div>
11
- * status.connected ? 'wifi' : 'wifi-off'
12
- * </div>
13
- * };
14
- */
15
- export declare const useStatus: () => import("@powersync/common").SyncStatus;
@@ -1,17 +0,0 @@
1
- import { usePowerSyncStatus } from './deprecated/usePowerSyncStatus.js';
2
- /**
3
- * Custom hook that provides access to the current status of PowerSync.
4
- * @returns The PowerSync Database status.
5
- * @example
6
- * import { useStatus } from "@powersync/react";
7
- *
8
- * const Component = () => {
9
- * const status = useStatus();
10
- *
11
- * return <div>
12
- * status.connected ? 'wifi' : 'wifi-off'
13
- * </div>
14
- * };
15
- */
16
- export const useStatus = () => usePowerSyncStatus();
17
- //# sourceMappingURL=useStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStatus.js","sourceRoot":"","sources":["../../src/hooks/useStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,kBAAkB,EAAE,CAAC"}
@@ -1,39 +0,0 @@
1
- import { type CompilableQuery } from '@powersync/common';
2
- import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types.js';
3
- /**
4
- * A hook to access the results of a watched query.
5
- * @example
6
- *
7
- * export const Component = () => {
8
- * // The lists array here will be a new Array reference whenever a change to the
9
- * // lists table is made.
10
- * const { data: lists } = useQuery('SELECT * from lists');
11
- *
12
- * return <View>
13
- * {lists.map((l) => (
14
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
15
- * ))}
16
- * </View>
17
- * }
18
- *
19
- * export const DiffComponent = () => {
20
- * // Providing a `rowComparator` results in the hook using an incremental query under the hood.
21
- * // An incremental query will only emit results when a change to the result set occurs.
22
- * // The internal array object references are maintained for unchanged rows.
23
- * // The returned lists array is read only when a `rowComparator` is provided.
24
- * const { data: lists } = useQuery('SELECT * from lists', [], {
25
- * rowComparator: {
26
- * keyBy: (item) => item.id,
27
- * compareBy: (item) => JSON.stringify(item)
28
- * }
29
- * });
30
- *
31
- * return <View>
32
- * {lists.map((l) => (
33
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
34
- * ))}
35
- * </View>
36
- * }
37
- */
38
- export declare function useQuery<RowType = any>(query: string | CompilableQuery<RowType>, parameters?: any[], options?: AdditionalOptions): QueryResult<RowType>;
39
- export declare function useQuery<RowType = any>(query: string | CompilableQuery<RowType>, parameters?: any[], options?: DifferentialHookOptions<RowType>): ReadonlyQueryResult<RowType>;
@@ -1,43 +0,0 @@
1
- import { usePowerSync } from '../PowerSyncContext.js';
2
- import { useSingleQuery } from './useSingleQuery.js';
3
- import { useWatchedQuery } from './useWatchedQuery.js';
4
- import { constructCompatibleQuery } from './watch-utils.js';
5
- import { useAllSyncStreamsHaveSynced } from '../streams.js';
6
- export function useQuery(query, parameters = [], options = {}) {
7
- const powerSync = usePowerSync();
8
- if (!powerSync) {
9
- return {
10
- ..._loadingState,
11
- isLoading: false,
12
- error: new Error('PowerSync not configured.')
13
- };
14
- }
15
- const { parsedQuery, queryChanged } = constructCompatibleQuery(query, parameters, options);
16
- const streamsHaveSynced = useAllSyncStreamsHaveSynced(powerSync, options?.streams);
17
- const runOnce = options?.runQueryOnce == true;
18
- const single = useSingleQuery({
19
- query: parsedQuery,
20
- powerSync,
21
- queryChanged,
22
- active: runOnce && streamsHaveSynced
23
- });
24
- const watched = useWatchedQuery({
25
- query: parsedQuery,
26
- powerSync,
27
- queryChanged,
28
- options: {
29
- reportFetching: options.reportFetching,
30
- // Maintains backwards compatibility with previous versions
31
- // Differentiation is opt-in by default
32
- // We emit new data for each table change by default.
33
- rowComparator: options.rowComparator
34
- },
35
- active: !runOnce && streamsHaveSynced
36
- });
37
- if (!streamsHaveSynced) {
38
- return { ..._loadingState };
39
- }
40
- return (runOnce ? single : watched) ?? _loadingState;
41
- }
42
- const _loadingState = { isLoading: true, isFetching: false, data: [], error: undefined };
43
- //# sourceMappingURL=useQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/hooks/watched/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAgD5D,MAAM,UAAU,QAAQ,CACtB,KAAwC,EACxC,aAAoB,EAAE,EACtB,UAAgE,EAAE;IAElE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,GAAG,aAAa;YAChB,SAAS,EAAE,KAAK;YAChB,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;SAC9C,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,wBAAwB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3F,MAAM,iBAAiB,GAAG,2BAA2B,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,OAAO,EAAE,YAAY,IAAI,IAAI,CAAC;IAC9C,MAAM,MAAM,GAAG,cAAc,CAAU;QACrC,KAAK,EAAE,WAAW;QAClB,SAAS;QACT,YAAY;QACZ,MAAM,EAAE,OAAO,IAAI,iBAAiB;KACrC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,eAAe,CAAU;QACvC,KAAK,EAAE,WAAW;QAClB,SAAS;QACT,YAAY;QACZ,OAAO,EAAE;YACP,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,2DAA2D;YAC3D,uCAAuC;YACvC,qDAAqD;YACrD,aAAa,EAAE,OAAO,CAAC,aAAa;SACrC;QACD,MAAM,EAAE,CAAC,OAAO,IAAI,iBAAiB;KACtC,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC;AACvD,CAAC;AAED,MAAM,aAAa,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC"}
@@ -1,6 +0,0 @@
1
- import { QueryResult } from './watch-types.js';
2
- import { InternalHookOptions } from './watch-utils.js';
3
- /**
4
- * @internal not exported from `index.ts`
5
- */
6
- export declare const useSingleQuery: <RowType = any>(options: InternalHookOptions<RowType[]>) => QueryResult<RowType>;
@@ -1,59 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * @internal not exported from `index.ts`
4
- */
5
- export const useSingleQuery = (options) => {
6
- const { query, powerSync, queryChanged, active } = options;
7
- const [output, setOutputState] = React.useState({
8
- isLoading: true,
9
- isFetching: true,
10
- data: [],
11
- error: undefined
12
- });
13
- const runQuery = React.useCallback(async (signal) => {
14
- setOutputState((prev) => ({ ...prev, isLoading: true, isFetching: true, error: undefined }));
15
- try {
16
- const compiledQuery = query.compile();
17
- const result = await query.execute({
18
- sql: compiledQuery.sql,
19
- parameters: [...compiledQuery.parameters],
20
- db: powerSync
21
- });
22
- if (signal.aborted) {
23
- return;
24
- }
25
- setOutputState((prev) => ({
26
- ...prev,
27
- isLoading: false,
28
- isFetching: false,
29
- data: result,
30
- error: undefined
31
- }));
32
- }
33
- catch (error) {
34
- setOutputState((prev) => ({
35
- ...prev,
36
- isLoading: false,
37
- isFetching: false,
38
- data: [],
39
- error
40
- }));
41
- }
42
- }, [queryChanged, query]);
43
- // Trigger initial query execution
44
- // @ts-ignore: Complains about not all code paths returning a value
45
- React.useEffect(() => {
46
- if (active) {
47
- const abortController = new AbortController();
48
- runQuery(abortController.signal);
49
- return () => {
50
- abortController.abort();
51
- };
52
- }
53
- }, [powerSync, active, queryChanged]);
54
- return {
55
- ...output,
56
- refresh: runQuery
57
- };
58
- };
59
- //# sourceMappingURL=useSingleQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSingleQuery.js","sourceRoot":"","sources":["../../../src/hooks/watched/useSingleQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAgB,OAAuC,EAAwB,EAAE;IAC7G,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3D,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAuB;QACpE,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,EAAE;QACR,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAChC,KAAK,EAAE,MAAoB,EAAE,EAAE;QAC7B,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;gBACjC,GAAG,EAAE,aAAa,CAAC,GAAG;gBACtB,UAAU,EAAE,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC;gBACzC,EAAE,EAAE,SAAS;aACd,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO;YACT,CAAC;YACD,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACxB,GAAG,IAAI;gBACP,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,KAAK;gBACjB,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,cAAc,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACxB,GAAG,IAAI;gBACP,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,KAAK;gBACjB,IAAI,EAAE,EAAE;gBACR,KAAK;aACN,CAAC,CAAC,CAAC;QACN,CAAC;IACH,CAAC,EACD,CAAC,YAAY,EAAE,KAAK,CAAC,CACtB,CAAC;IAEF,kCAAkC;IAClC,mEAAmE;IACnE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;YAC9C,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YACjC,OAAO,GAAG,EAAE;gBACV,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAEtC,OAAO;QACL,GAAG,MAAM;QACT,OAAO,EAAE,QAAQ;KAClB,CAAC;AACJ,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- import { DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types.js';
2
- import { InternalHookOptions } from './watch-utils.js';
3
- /**
4
- * @internal This is not exported from the index.ts
5
- *
6
- * When an incremental query is used the return type is readonly. This is required
7
- * since the implementation requires a stable ref.
8
- * For legacy compatibility we allow mutating when a standard query is used. Mutations should
9
- * not affect the internal implementation in this case.
10
- */
11
- export declare const useWatchedQuery: <RowType = unknown>(options: InternalHookOptions<RowType[]> & {
12
- options: DifferentialHookOptions<RowType>;
13
- }) => QueryResult<RowType> | ReadonlyQueryResult<RowType>;
@@ -1,78 +0,0 @@
1
- import React from 'react';
2
- import { useNullableWatchedQuerySubscription } from './useWatchedQuerySubscription.js';
3
- /**
4
- * @internal This is not exported from the index.ts
5
- *
6
- * When an incremental query is used the return type is readonly. This is required
7
- * since the implementation requires a stable ref.
8
- * For legacy compatibility we allow mutating when a standard query is used. Mutations should
9
- * not affect the internal implementation in this case.
10
- */
11
- export const useWatchedQuery = (options) => {
12
- const { query, powerSync, queryChanged, options: hookOptions, active } = options;
13
- function createWatchedQuery() {
14
- if (!active) {
15
- return null;
16
- }
17
- const watch = hookOptions.rowComparator
18
- ? powerSync.customQuery(query).differentialWatch({
19
- rowComparator: hookOptions.rowComparator,
20
- reportFetching: hookOptions.reportFetching,
21
- throttleMs: hookOptions.throttleMs
22
- })
23
- : powerSync.customQuery(query).watch({
24
- reportFetching: hookOptions.reportFetching,
25
- throttleMs: hookOptions.throttleMs
26
- });
27
- return watch;
28
- }
29
- const [watchedQuery, setWatchedQuery] = React.useState(createWatchedQuery);
30
- const disposePendingUpdateListener = React.useRef(null);
31
- React.useEffect(() => {
32
- watchedQuery?.close();
33
- const newQuery = createWatchedQuery();
34
- setWatchedQuery(newQuery);
35
- return () => {
36
- disposePendingUpdateListener.current?.();
37
- newQuery?.close();
38
- };
39
- }, [powerSync, active]);
40
- /**
41
- * Indicates that the query will be re-fetched due to a change in the query.
42
- * We execute this in-line (not using an effect) since effects are delayed till after the hook returns.
43
- * The `queryChanged` value should only be true for a single render.
44
- * The `updateSettings` method is asynchronous, thus it will update the state asynchronously.
45
- * In the React hooks we'd like to report that we are fetching the data for an updated query
46
- * as soon as the query has been updated. This prevents a result flow where e.g. the hook:
47
- * - already returned a result: isLoading, isFetching are both false
48
- * - the query is updated, but the state is still isFetching=false from the previous state
49
- * We override the isFetching status while the `updateSettings` method is running (if we report `isFetching`),
50
- * we override this value just until the `updateSettings` method itself will update the `isFetching` status.
51
- * We achieve this by registering a `settingsWillUpdate` listener on the `WatchedQuery`. This will fire
52
- * just before the `isFetching` status is updated.
53
- */
54
- if (queryChanged) {
55
- // Keep track of this pending operation
56
- watchedQuery?.updateSettings({
57
- query,
58
- throttleMs: hookOptions.throttleMs,
59
- reportFetching: hookOptions.reportFetching
60
- });
61
- // This could have been called multiple times, clear any old listeners.
62
- disposePendingUpdateListener.current?.();
63
- disposePendingUpdateListener.current = watchedQuery?.registerListener({
64
- settingsWillUpdate: () => {
65
- // We'll use the fact that we have a listener at all as an indication
66
- disposePendingUpdateListener.current?.();
67
- disposePendingUpdateListener.current = null;
68
- }
69
- });
70
- }
71
- const shouldReportCurrentlyFetching = (hookOptions.reportFetching ?? true) && !!disposePendingUpdateListener.current;
72
- const result = useNullableWatchedQuerySubscription(watchedQuery);
73
- return {
74
- ...result,
75
- isFetching: result?.isFetching || shouldReportCurrentlyFetching
76
- };
77
- };
78
- //# sourceMappingURL=useWatchedQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useWatchedQuery.js","sourceRoot":"","sources":["../../../src/hooks/watched/useWatchedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AAIvF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAuF,EAClC,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEjF,SAAS,kBAAkB;QACzB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,aAAa;YACrC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC;gBAC7C,aAAa,EAAE,WAAW,CAAC,aAAa;gBACxC,cAAc,EAAE,WAAW,CAAC,cAAc;gBAC1C,UAAU,EAAE,WAAW,CAAC,UAAU;aACnC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;gBACjC,cAAc,EAAE,WAAW,CAAC,cAAc;gBAC1C,UAAU,EAAE,WAAW,CAAC,UAAU;aACnC,CAAC,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC3E,MAAM,4BAA4B,GAAG,KAAK,CAAC,MAAM,CAAoB,IAAI,CAAC,CAAC;IAE3E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,YAAY,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;QACtC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAE1B,OAAO,GAAG,EAAE;YACV,4BAA4B,CAAC,OAAO,EAAE,EAAE,CAAC;YACzC,QAAQ,EAAE,KAAK,EAAE,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAExB;;;;;;;;;;;;;OAaG;IACH,IAAI,YAAY,EAAE,CAAC;QACjB,uCAAuC;QACvC,YAAY,EAAE,cAAc,CAAC;YAC3B,KAAK;YACL,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,cAAc,EAAE,WAAW,CAAC,cAAc;SAC3C,CAAC,CAAC;QACH,uEAAuE;QACvE,4BAA4B,CAAC,OAAO,EAAE,EAAE,CAAC;QACzC,4BAA4B,CAAC,OAAO,GAAG,YAAY,EAAE,gBAAgB,CAAC;YACpE,kBAAkB,EAAE,GAAG,EAAE;gBACvB,qEAAqE;gBACrE,4BAA4B,CAAC,OAAO,EAAE,EAAE,CAAC;gBACzC,4BAA4B,CAAC,OAAO,GAAG,IAAI,CAAC;YAC9C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,6BAA6B,GAAG,CAAC,WAAW,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,4BAA4B,CAAC,OAAO,CAAC;IACrH,MAAM,MAAM,GAAG,mCAAmC,CAAC,YAAY,CAAC,CAAC;IACjE,OAAO;QACL,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,6BAA6B;KAChE,CAAC;AACJ,CAAC,CAAC"}
@@ -1,20 +0,0 @@
1
- import { WatchedQuery } from '@powersync/common';
2
- /**
3
- * A hook to access and subscribe to the results of an existing {@link WatchedQuery} instance.
4
- * @example
5
- * export const ContentComponent = () => {
6
- * const { data: lists } = useWatchedQuerySubscription(listsQuery);
7
- *
8
- * return <View>
9
- * {lists.map((l) => (
10
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
11
- * ))}
12
- * </View>;
13
- * }
14
- *
15
- */
16
- export declare const useWatchedQuerySubscription: <ResultType = unknown, Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>>(query: Query) => Query["state"];
17
- /**
18
- * @internal
19
- */
20
- export declare const useNullableWatchedQuerySubscription: <ResultType = unknown, Query extends WatchedQuery<ResultType> = WatchedQuery<ResultType>>(query: Query | null) => Query["state"] | undefined;
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * A hook to access and subscribe to the results of an existing {@link WatchedQuery} instance.
4
- * @example
5
- * export const ContentComponent = () => {
6
- * const { data: lists } = useWatchedQuerySubscription(listsQuery);
7
- *
8
- * return <View>
9
- * {lists.map((l) => (
10
- * <Text key={l.id}>{JSON.stringify(l)}</Text>
11
- * ))}
12
- * </View>;
13
- * }
14
- *
15
- */
16
- export const useWatchedQuerySubscription = (query) => {
17
- return useNullableWatchedQuerySubscription(query);
18
- };
19
- /**
20
- * @internal
21
- */
22
- export const useNullableWatchedQuerySubscription = (query) => {
23
- const [output, setOutputState] = React.useState(query?.state);
24
- // @ts-ignore: Complains about not all code paths returning a value
25
- React.useEffect(() => {
26
- if (query) {
27
- setOutputState(query.state);
28
- return query.registerListener({
29
- onStateChange: (state) => {
30
- setOutputState({ ...state });
31
- }
32
- });
33
- }
34
- }, [query]);
35
- return output;
36
- };
37
- //# sourceMappingURL=useWatchedQuerySubscription.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useWatchedQuerySubscription.js","sourceRoot":"","sources":["../../../src/hooks/watched/useWatchedQuerySubscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAIzC,KAAY,EACI,EAAE;IAClB,OAAO,mCAAmC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAIjD,KAAmB,EACS,EAAE;IAC9B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAE9D,mEAAmE;IACnE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,KAAK,EAAE,CAAC;YACV,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAE5B,OAAO,KAAK,CAAC,gBAAgB,CAAC;gBAC5B,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,cAAc,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;gBAC/B,CAAC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}