@powersync/react 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/QueryStore.d.ts +1 -1
- package/lib/hooks/deprecated/usePowerSyncQuery.js +1 -1
- package/lib/hooks/deprecated/usePowerSyncStatus.js +1 -1
- package/lib/hooks/deprecated/usePowerSyncWatchedQuery.js +1 -1
- package/lib/hooks/suspense/SuspenseQueryResult.d.ts +1 -1
- package/lib/hooks/suspense/suspense-utils.d.ts +1 -4
- package/lib/hooks/suspense/suspense-utils.js +5 -8
- package/lib/hooks/suspense/useSingleSuspenseQuery.d.ts +2 -2
- package/lib/hooks/suspense/useSingleSuspenseQuery.js +5 -8
- package/lib/hooks/suspense/useSuspenseQuery.d.ts +2 -2
- package/lib/hooks/suspense/useSuspenseQuery.js +2 -2
- package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js +2 -7
- package/lib/hooks/suspense/useWatchedSuspenseQuery.d.ts +1 -1
- package/lib/hooks/suspense/useWatchedSuspenseQuery.js +4 -4
- package/lib/hooks/useStatus.js +1 -1
- package/lib/hooks/watched/useQuery.d.ts +1 -1
- package/lib/hooks/watched/useQuery.js +4 -4
- package/lib/hooks/watched/useSingleQuery.d.ts +2 -2
- package/lib/hooks/watched/useWatchedQuery.d.ts +2 -2
- package/lib/hooks/watched/useWatchedQuery.js +1 -1
- package/lib/hooks/watched/watch-utils.d.ts +1 -1
- package/lib/hooks/watched/watch-utils.js +1 -1
- package/lib/index.d.ts +11 -11
- package/lib/index.js +9 -9
- package/package.json +8 -5
package/lib/QueryStore.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractPowerSyncDatabase, WatchCompatibleQuery, WatchedQuery } from '@powersync/common';
|
|
2
|
-
import { DifferentialHookOptions } from './hooks/watched/watch-types';
|
|
2
|
+
import { DifferentialHookOptions } from './hooks/watched/watch-types.js';
|
|
3
3
|
export declare function generateQueryKey(sqlStatement: string, parameters: ReadonlyArray<unknown>, options: DifferentialHookOptions<unknown>): string;
|
|
4
4
|
export declare class QueryStore {
|
|
5
5
|
private db;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { QueryResult, ReadonlyQueryResult } from '../watched/watch-types';
|
|
1
|
+
import { QueryResult, ReadonlyQueryResult } from '../watched/watch-types.js';
|
|
2
2
|
export type SuspenseQueryResult<T> = Pick<QueryResult<T>, 'data' | 'refresh'>;
|
|
3
3
|
export type ReadonlySuspenseQueryResult<T> = Pick<ReadonlyQueryResult<T>, 'data' | 'refresh'>;
|
|
@@ -5,11 +5,8 @@ import { WatchedQuery } from '@powersync/common';
|
|
|
5
5
|
* before this component is committed. The promise will release it's listener once the query is no longer loading.
|
|
6
6
|
* This temporary hold is used to ensure that the query is not disposed in the interim.
|
|
7
7
|
* Creates a subscription for state change which creates a temporary hold on the query
|
|
8
|
-
* @returns a function to release the hold
|
|
9
8
|
*/
|
|
10
|
-
export declare const useTemporaryHold: (watchedQuery?: WatchedQuery<unknown>) =>
|
|
11
|
-
releaseHold: () => void;
|
|
12
|
-
};
|
|
9
|
+
export declare const useTemporaryHold: (watchedQuery?: WatchedQuery<unknown>) => void;
|
|
13
10
|
/**
|
|
14
11
|
* React suspense relies on a promise that resolves once the initial data has loaded.
|
|
15
12
|
* This creates a promise which registers a listener on the watched query.
|
|
@@ -5,20 +5,20 @@ import React from 'react';
|
|
|
5
5
|
* before this component is committed. The promise will release it's listener once the query is no longer loading.
|
|
6
6
|
* This temporary hold is used to ensure that the query is not disposed in the interim.
|
|
7
7
|
* Creates a subscription for state change which creates a temporary hold on the query
|
|
8
|
-
* @returns a function to release the hold
|
|
9
8
|
*/
|
|
10
9
|
export const useTemporaryHold = (watchedQuery) => {
|
|
11
10
|
const releaseTemporaryHold = React.useRef(undefined);
|
|
12
11
|
const addedHoldTo = React.useRef(undefined);
|
|
13
12
|
if (addedHoldTo.current !== watchedQuery) {
|
|
13
|
+
// The query changed, we no longer need the previous hold if present
|
|
14
14
|
releaseTemporaryHold.current?.();
|
|
15
|
+
releaseTemporaryHold.current = undefined;
|
|
15
16
|
addedHoldTo.current = watchedQuery;
|
|
16
17
|
if (!watchedQuery || !watchedQuery.state.isLoading) {
|
|
17
|
-
// No query to hold or no reason to hold, return
|
|
18
|
-
return
|
|
19
|
-
releaseHold: () => { }
|
|
20
|
-
};
|
|
18
|
+
// No query to hold or no reason to hold, return
|
|
19
|
+
return;
|
|
21
20
|
}
|
|
21
|
+
// Create a hold by subscribing
|
|
22
22
|
const disposeSubscription = watchedQuery.registerListener({
|
|
23
23
|
onStateChange: (state) => { }
|
|
24
24
|
});
|
|
@@ -50,9 +50,6 @@ export const useTemporaryHold = (watchedQuery) => {
|
|
|
50
50
|
// Set a timeout to conditionally remove the temporary hold
|
|
51
51
|
setTimeout(checkHold, timeoutPollMs);
|
|
52
52
|
}
|
|
53
|
-
return {
|
|
54
|
-
releaseHold: releaseTemporaryHold.current
|
|
55
|
-
};
|
|
56
53
|
};
|
|
57
54
|
/**
|
|
58
55
|
* React suspense relies on a promise that resolves once the initial data has loaded.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompilableQuery } from '@powersync/common';
|
|
2
|
-
import { AdditionalOptions } from '../watched/watch-types';
|
|
3
|
-
import { SuspenseQueryResult } from './SuspenseQueryResult';
|
|
2
|
+
import { AdditionalOptions } from '../watched/watch-types.js';
|
|
3
|
+
import { SuspenseQueryResult } from './SuspenseQueryResult.js';
|
|
4
4
|
/**
|
|
5
5
|
* Use a query which is not watched, but suspends until the initial result has loaded.
|
|
6
6
|
* Internally this uses a WatchedQuery during suspense for state management. The watched
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { generateQueryKey, getQueryStore } from '../../QueryStore';
|
|
3
|
-
import { usePowerSync } from '../PowerSyncContext';
|
|
4
|
-
import { constructCompatibleQuery } from '../watched/watch-utils';
|
|
5
|
-
import { createSuspendingPromise, useTemporaryHold } from './suspense-utils';
|
|
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
6
|
/**
|
|
7
7
|
* Use a query which is not watched, but suspends until the initial result has loaded.
|
|
8
8
|
* Internally this uses a WatchedQuery during suspense for state management. The watched
|
|
@@ -25,7 +25,7 @@ export const useSingleSuspenseQuery = (query, parameters = [], options = {}) =>
|
|
|
25
25
|
const store = getQueryStore(powerSync);
|
|
26
26
|
// Only use a temporary watched query if we don't have data yet.
|
|
27
27
|
const watchedQuery = data ? null : store.getQuery(key, parsedQuery, options);
|
|
28
|
-
|
|
28
|
+
useTemporaryHold(watchedQuery);
|
|
29
29
|
React.useEffect(() => {
|
|
30
30
|
// Set the initial yielded data
|
|
31
31
|
// it should be available once we commit the component
|
|
@@ -36,9 +36,6 @@ export const useSingleSuspenseQuery = (query, parameters = [], options = {}) =>
|
|
|
36
36
|
setData(watchedQuery.state.data);
|
|
37
37
|
setError(null);
|
|
38
38
|
}
|
|
39
|
-
if (!watchedQuery?.state.isLoading) {
|
|
40
|
-
releaseHold();
|
|
41
|
-
}
|
|
42
39
|
}, []);
|
|
43
40
|
if (error != null) {
|
|
44
41
|
// Report errors - this is caught by an error boundary
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompilableQuery } from '@powersync/common';
|
|
2
|
-
import { AdditionalOptions, DifferentialHookOptions } from '../watched/watch-types';
|
|
3
|
-
import { ReadonlySuspenseQueryResult, SuspenseQueryResult } from './SuspenseQueryResult';
|
|
2
|
+
import { AdditionalOptions, DifferentialHookOptions } from '../watched/watch-types.js';
|
|
3
|
+
import { ReadonlySuspenseQueryResult, SuspenseQueryResult } from './SuspenseQueryResult.js';
|
|
4
4
|
/**
|
|
5
5
|
* A hook to access the results of a watched query that suspends until the initial result has loaded.
|
|
6
6
|
* @example
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useSingleSuspenseQuery } from './useSingleSuspenseQuery';
|
|
2
|
-
import { useWatchedSuspenseQuery } from './useWatchedSuspenseQuery';
|
|
1
|
+
import { useSingleSuspenseQuery } from './useSingleSuspenseQuery.js';
|
|
2
|
+
import { useWatchedSuspenseQuery } from './useWatchedSuspenseQuery.js';
|
|
3
3
|
export function useSuspenseQuery(query, parameters = [], options = {}) {
|
|
4
4
|
switch (options?.runQueryOnce) {
|
|
5
5
|
case true:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { createSuspendingPromise, useTemporaryHold } from './suspense-utils';
|
|
2
|
+
import { createSuspendingPromise, useTemporaryHold } from './suspense-utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* A hook to access and subscribe to the results of an existing {@link WatchedQuery}.
|
|
5
5
|
* @example
|
|
@@ -22,7 +22,7 @@ import { createSuspendingPromise, useTemporaryHold } from './suspense-utils';
|
|
|
22
22
|
* }
|
|
23
23
|
*/
|
|
24
24
|
export const useWatchedQuerySuspenseSubscription = (query) => {
|
|
25
|
-
|
|
25
|
+
useTemporaryHold(query);
|
|
26
26
|
// Force update state function
|
|
27
27
|
const [, setUpdateCounter] = React.useState(0);
|
|
28
28
|
React.useEffect(() => {
|
|
@@ -34,11 +34,6 @@ export const useWatchedQuerySuspenseSubscription = (query) => {
|
|
|
34
34
|
setUpdateCounter((prev) => prev + 1);
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
// This runs on the first iteration before the component is suspended
|
|
38
|
-
// We should only release the hold once the component is no longer loading
|
|
39
|
-
if (!query.state.isLoading) {
|
|
40
|
-
releaseHold();
|
|
41
|
-
}
|
|
42
37
|
return dispose;
|
|
43
38
|
}, []);
|
|
44
39
|
if (query.state.error != null) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { generateQueryKey, getQueryStore } from '../../QueryStore';
|
|
2
|
-
import { usePowerSync } from '../PowerSyncContext';
|
|
3
|
-
import { constructCompatibleQuery } from '../watched/watch-utils';
|
|
4
|
-
import { useWatchedQuerySuspenseSubscription } from './useWatchedQuerySuspenseSubscription';
|
|
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
5
|
/**
|
|
6
6
|
* @internal This is not exported in the index.ts
|
|
7
7
|
*/
|
package/lib/hooks/useStatus.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CompilableQuery } from '@powersync/common';
|
|
2
|
-
import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types';
|
|
2
|
+
import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types.js';
|
|
3
3
|
/**
|
|
4
4
|
* A hook to access the results of a watched query.
|
|
5
5
|
* @example
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { usePowerSync } from '../PowerSyncContext';
|
|
2
|
-
import { useSingleQuery } from './useSingleQuery';
|
|
3
|
-
import { useWatchedQuery } from './useWatchedQuery';
|
|
4
|
-
import { constructCompatibleQuery } from './watch-utils';
|
|
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
5
|
export function useQuery(query, parameters = [], options = {}) {
|
|
6
6
|
const powerSync = usePowerSync();
|
|
7
7
|
if (!powerSync) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { QueryResult } from './watch-types';
|
|
2
|
-
import { InternalHookOptions } from './watch-utils';
|
|
1
|
+
import { QueryResult } from './watch-types.js';
|
|
2
|
+
import { InternalHookOptions } from './watch-utils.js';
|
|
3
3
|
export declare const useSingleQuery: <RowType = any>(options: InternalHookOptions<RowType[]>) => QueryResult<RowType>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types';
|
|
2
|
-
import { InternalHookOptions } from './watch-utils';
|
|
1
|
+
import { DifferentialHookOptions, QueryResult, ReadonlyQueryResult } from './watch-types.js';
|
|
2
|
+
import { InternalHookOptions } from './watch-utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* @internal This is not exported from the index.ts
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractPowerSyncDatabase, CompilableQuery, WatchCompatibleQuery } from '@powersync/common';
|
|
2
|
-
import { AdditionalOptions } from './watch-types';
|
|
2
|
+
import { AdditionalOptions } from './watch-types.js';
|
|
3
3
|
export type InternalHookOptions<DataType> = {
|
|
4
4
|
query: WatchCompatibleQuery<DataType>;
|
|
5
5
|
powerSync: AbstractPowerSyncDatabase;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { usePowerSyncQuery } from './hooks/deprecated/usePowerSyncQuery';
|
|
2
|
-
export { usePowerSyncStatus } from './hooks/deprecated/usePowerSyncStatus';
|
|
3
|
-
export { usePowerSyncWatchedQuery } from './hooks/deprecated/usePowerSyncWatchedQuery';
|
|
4
|
-
export * from './hooks/PowerSyncContext';
|
|
5
|
-
export { SuspenseQueryResult } from './hooks/suspense/SuspenseQueryResult';
|
|
6
|
-
export { useSuspenseQuery } from './hooks/suspense/useSuspenseQuery';
|
|
7
|
-
export { useWatchedQuerySuspenseSubscription } from './hooks/suspense/useWatchedQuerySuspenseSubscription';
|
|
8
|
-
export { useStatus } from './hooks/useStatus';
|
|
9
|
-
export { useQuery } from './hooks/watched/useQuery';
|
|
10
|
-
export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription';
|
|
11
|
-
export { AdditionalOptions } from './hooks/watched/watch-types';
|
|
1
|
+
export { usePowerSyncQuery } from './hooks/deprecated/usePowerSyncQuery.js';
|
|
2
|
+
export { usePowerSyncStatus } from './hooks/deprecated/usePowerSyncStatus.js';
|
|
3
|
+
export { usePowerSyncWatchedQuery } from './hooks/deprecated/usePowerSyncWatchedQuery.js';
|
|
4
|
+
export * from './hooks/PowerSyncContext.js';
|
|
5
|
+
export { SuspenseQueryResult } from './hooks/suspense/SuspenseQueryResult.js';
|
|
6
|
+
export { useSuspenseQuery } from './hooks/suspense/useSuspenseQuery.js';
|
|
7
|
+
export { useWatchedQuerySuspenseSubscription } from './hooks/suspense/useWatchedQuerySuspenseSubscription.js';
|
|
8
|
+
export { useStatus } from './hooks/useStatus.js';
|
|
9
|
+
export { useQuery } from './hooks/watched/useQuery.js';
|
|
10
|
+
export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription.js';
|
|
11
|
+
export { AdditionalOptions } from './hooks/watched/watch-types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { usePowerSyncQuery } from './hooks/deprecated/usePowerSyncQuery';
|
|
2
|
-
export { usePowerSyncStatus } from './hooks/deprecated/usePowerSyncStatus';
|
|
3
|
-
export { usePowerSyncWatchedQuery } from './hooks/deprecated/usePowerSyncWatchedQuery';
|
|
4
|
-
export * from './hooks/PowerSyncContext';
|
|
5
|
-
export { useSuspenseQuery } from './hooks/suspense/useSuspenseQuery';
|
|
6
|
-
export { useWatchedQuerySuspenseSubscription } from './hooks/suspense/useWatchedQuerySuspenseSubscription';
|
|
7
|
-
export { useStatus } from './hooks/useStatus';
|
|
8
|
-
export { useQuery } from './hooks/watched/useQuery';
|
|
9
|
-
export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription';
|
|
1
|
+
export { usePowerSyncQuery } from './hooks/deprecated/usePowerSyncQuery.js';
|
|
2
|
+
export { usePowerSyncStatus } from './hooks/deprecated/usePowerSyncStatus.js';
|
|
3
|
+
export { usePowerSyncWatchedQuery } from './hooks/deprecated/usePowerSyncWatchedQuery.js';
|
|
4
|
+
export * from './hooks/PowerSyncContext.js';
|
|
5
|
+
export { useSuspenseQuery } from './hooks/suspense/useSuspenseQuery.js';
|
|
6
|
+
export { useWatchedQuerySuspenseSubscription } from './hooks/suspense/useWatchedQuerySuspenseSubscription.js';
|
|
7
|
+
export { useStatus } from './hooks/useStatus.js';
|
|
8
|
+
export { useQuery } from './hooks/watched/useQuery.js';
|
|
9
|
+
export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription.js';
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "React components for JourneyApps PowerSync",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"main": "./lib/index.js",
|
|
11
|
+
"module": "./lib/index.js",
|
|
10
12
|
"types": "./lib/index.d.ts",
|
|
11
13
|
"files": [
|
|
12
14
|
"lib"
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
},
|
|
23
25
|
"homepage": "https://docs.powersync.com",
|
|
24
26
|
"peerDependencies": {
|
|
25
|
-
"@powersync/common": "^1.
|
|
27
|
+
"@powersync/common": "^1.36.0",
|
|
26
28
|
"react": "*"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
@@ -33,14 +35,15 @@
|
|
|
33
35
|
"react": "18.3.1",
|
|
34
36
|
"react-dom": "18.3.1",
|
|
35
37
|
"react-error-boundary": "^4.1.0",
|
|
36
|
-
"@powersync/common": "1.
|
|
37
|
-
"@powersync/web": "1.25.
|
|
38
|
+
"@powersync/common": "1.36.0",
|
|
39
|
+
"@powersync/web": "1.25.1"
|
|
38
40
|
},
|
|
39
41
|
"scripts": {
|
|
40
42
|
"build": "tsc -b",
|
|
41
43
|
"build:prod": "tsc -b --sourceMap false",
|
|
42
|
-
"clean": "rm -rf lib tsconfig.tsbuildinfo
|
|
44
|
+
"clean": "rm -rf lib tsconfig.tsbuildinfo",
|
|
43
45
|
"test": "vitest",
|
|
46
|
+
"test:exports": "attw --pack --profile=esm-only .",
|
|
44
47
|
"watch": "tsc -b -w"
|
|
45
48
|
}
|
|
46
49
|
}
|