@powersync/react 0.0.0-dev-20260202162549 → 0.0.0-dev-20260216124709
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 +10 -0
- package/lib/QueryStore.js +63 -0
- package/lib/QueryStore.js.map +1 -0
- package/lib/hooks/PowerSyncContext.d.ts +21 -0
- package/lib/hooks/PowerSyncContext.js +21 -0
- package/lib/hooks/PowerSyncContext.js.map +1 -0
- package/lib/hooks/deprecated/usePowerSyncQuery.d.ts +7 -0
- package/lib/hooks/deprecated/usePowerSyncQuery.js +26 -0
- package/lib/hooks/deprecated/usePowerSyncQuery.js.map +1 -0
- package/lib/hooks/deprecated/usePowerSyncStatus.d.ts +15 -0
- package/lib/hooks/deprecated/usePowerSyncStatus.js +30 -0
- package/lib/hooks/deprecated/usePowerSyncStatus.js.map +1 -0
- package/lib/hooks/deprecated/usePowerSyncWatchedQuery.d.ts +17 -0
- package/lib/hooks/deprecated/usePowerSyncWatchedQuery.js +45 -0
- package/lib/hooks/deprecated/usePowerSyncWatchedQuery.js.map +1 -0
- package/lib/hooks/streams.d.ts +31 -0
- package/lib/hooks/streams.js +93 -0
- package/lib/hooks/streams.js.map +1 -0
- package/lib/hooks/suspense/SuspenseQueryResult.d.ts +3 -0
- package/lib/hooks/suspense/SuspenseQueryResult.js +2 -0
- package/lib/hooks/suspense/SuspenseQueryResult.js.map +1 -0
- package/lib/hooks/suspense/suspense-utils.d.ts +16 -0
- package/lib/hooks/suspense/suspense-utils.js +76 -0
- package/lib/hooks/suspense/suspense-utils.js.map +1 -0
- package/lib/hooks/suspense/useSingleSuspenseQuery.d.ts +10 -0
- package/lib/hooks/suspense/useSingleSuspenseQuery.js +73 -0
- package/lib/hooks/suspense/useSingleSuspenseQuery.js.map +1 -0
- package/lib/hooks/suspense/useSuspenseQuery.d.ts +53 -0
- package/lib/hooks/suspense/useSuspenseQuery.js +11 -0
- package/lib/hooks/suspense/useSuspenseQuery.js.map +1 -0
- package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.d.ts +23 -0
- package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js +52 -0
- package/lib/hooks/suspense/useWatchedQuerySuspenseSubscription.js.map +1 -0
- package/lib/hooks/suspense/useWatchedSuspenseQuery.d.ts +6 -0
- package/lib/hooks/suspense/useWatchedSuspenseQuery.js +26 -0
- package/lib/hooks/suspense/useWatchedSuspenseQuery.js.map +1 -0
- package/lib/hooks/useStatus.d.ts +15 -0
- package/lib/hooks/useStatus.js +17 -0
- package/lib/hooks/useStatus.js.map +1 -0
- package/lib/hooks/watched/useQuery.d.ts +39 -0
- package/lib/hooks/watched/useQuery.js +43 -0
- package/lib/hooks/watched/useQuery.js.map +1 -0
- package/lib/hooks/watched/useSingleQuery.d.ts +6 -0
- package/lib/hooks/watched/useSingleQuery.js +59 -0
- package/lib/hooks/watched/useSingleQuery.js.map +1 -0
- package/lib/hooks/watched/useWatchedQuery.d.ts +13 -0
- package/lib/hooks/watched/useWatchedQuery.js +78 -0
- package/lib/hooks/watched/useWatchedQuery.js.map +1 -0
- package/lib/hooks/watched/useWatchedQuerySubscription.d.ts +20 -0
- package/lib/hooks/watched/useWatchedQuerySubscription.js +37 -0
- package/lib/hooks/watched/useWatchedQuerySubscription.js.map +1 -0
- package/lib/hooks/watched/watch-types.d.ts +87 -0
- package/lib/hooks/watched/watch-types.js +2 -0
- package/lib/hooks/watched/watch-types.js.map +1 -0
- package/lib/hooks/watched/watch-utils.d.ts +17 -0
- package/lib/hooks/watched/watch-utils.js +62 -0
- package/lib/hooks/watched/watch-utils.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AbstractPowerSyncDatabase, CompilableQuery, WatchCompatibleQuery } from '@powersync/common';
|
|
2
|
+
import { AdditionalOptions } from './watch-types.js';
|
|
3
|
+
export type InternalHookOptions<DataType> = {
|
|
4
|
+
query: WatchCompatibleQuery<DataType>;
|
|
5
|
+
powerSync: AbstractPowerSyncDatabase;
|
|
6
|
+
queryChanged: boolean;
|
|
7
|
+
active: boolean;
|
|
8
|
+
};
|
|
9
|
+
interface WatchCompatibleQueryWithParams<T> extends WatchCompatibleQuery<T> {
|
|
10
|
+
stringifiedParameters?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const checkQueryChanged: <T>(query: WatchCompatibleQueryWithParams<T>, options: AdditionalOptions) => boolean;
|
|
13
|
+
export declare const constructCompatibleQuery: <RowType>(query: string | CompilableQuery<RowType>, parameters: any[], options: AdditionalOptions) => {
|
|
14
|
+
parsedQuery: WatchCompatibleQueryWithParams<RowType[]>;
|
|
15
|
+
queryChanged: boolean;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { usePowerSync } from '../PowerSyncContext.js';
|
|
3
|
+
export const checkQueryChanged = (query, options) => {
|
|
4
|
+
let _compiled;
|
|
5
|
+
try {
|
|
6
|
+
_compiled = query.compile();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
return false; // If compilation fails, we assume the query has changed
|
|
10
|
+
}
|
|
11
|
+
const compiled = _compiled;
|
|
12
|
+
const stringifiedParams = query.stringifiedParameters ?? JSON.stringify(compiled.parameters);
|
|
13
|
+
const stringifiedOptions = JSON.stringify(options);
|
|
14
|
+
const previousQueryRef = React.useRef({ sqlStatement: compiled.sql, stringifiedParams, stringifiedOptions });
|
|
15
|
+
if (previousQueryRef.current.sqlStatement !== compiled.sql ||
|
|
16
|
+
previousQueryRef.current.stringifiedParams != stringifiedParams ||
|
|
17
|
+
previousQueryRef.current.stringifiedOptions != stringifiedOptions) {
|
|
18
|
+
previousQueryRef.current.sqlStatement = compiled.sql;
|
|
19
|
+
previousQueryRef.current.stringifiedParams = stringifiedParams;
|
|
20
|
+
previousQueryRef.current.stringifiedOptions = stringifiedOptions;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
export const constructCompatibleQuery = (query, parameters = [], options) => {
|
|
26
|
+
const powerSync = usePowerSync();
|
|
27
|
+
const stringifiedParameters = React.useMemo(() => JSON.stringify(parameters), [parameters]);
|
|
28
|
+
const parsedQuery = React.useMemo(() => {
|
|
29
|
+
if (typeof query == 'string') {
|
|
30
|
+
return {
|
|
31
|
+
compile: () => ({
|
|
32
|
+
sql: query,
|
|
33
|
+
parameters
|
|
34
|
+
}),
|
|
35
|
+
execute: () => powerSync.getAll(query, parameters),
|
|
36
|
+
// Setting this is a small optimization that avoids checkQueryChanged recomputing the JSON representation.
|
|
37
|
+
stringifiedParameters
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return {
|
|
42
|
+
// Generics differ a bit but holistically this is the same
|
|
43
|
+
compile: () => {
|
|
44
|
+
const compiled = query.compile();
|
|
45
|
+
return {
|
|
46
|
+
sql: compiled.sql,
|
|
47
|
+
parameters: [...compiled.parameters]
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
execute: () => query.execute()
|
|
51
|
+
// Note that we can't set stringifiedParameters here because we only know parameters after the query has been
|
|
52
|
+
// compiled.
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, [query, powerSync, stringifiedParameters]);
|
|
56
|
+
const queryChanged = checkQueryChanged(parsedQuery, options);
|
|
57
|
+
return {
|
|
58
|
+
parsedQuery,
|
|
59
|
+
queryChanged
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=watch-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-utils.js","sourceRoot":"","sources":["../../../src/hooks/watched/watch-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MA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ACjC,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAE5F,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAA4C,GAAG,EAAE;QAChF,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,OAAO;gBACL,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;oBACd,GAAG,EAAE,KAAK;oBACV,UAAU;iBACX,CAAC;gBACF,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC;gBAClD,0GAA0G;gBAC1G,qBAAqB;aACtB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,0DAA0D;gBAC1D,OAAO,EAAE,GAAG,EAAE;oBACZ,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;oBACjC,OAAO;wBACL,GAAG,EAAE,QAAQ,CAAC,GAAG;wBACjB,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC;qBACrC,CAAC;gBACJ,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE;gBAC9B,6GAA6G;gBAC7G,YAAY;aACb,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAE9C,MAAM,YAAY,GAAG,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE7D,OAAO;QACL,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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 { useSyncStream, UseSyncStreamOptions } from './hooks/streams.js';
|
|
9
|
+
export { useStatus } from './hooks/useStatus.js';
|
|
10
|
+
export { useQuery } from './hooks/watched/useQuery.js';
|
|
11
|
+
export { useWatchedQuerySubscription } from './hooks/watched/useWatchedQuerySubscription.js';
|
|
12
|
+
export { AdditionalOptions } from './hooks/watched/watch-types.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 { useSyncStream } from './hooks/streams.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
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,mCAAmC,EAAE,MAAM,yDAAyD,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAwB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260216124709",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://docs.powersync.com",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@powersync/common": "0.0.0-dev-
|
|
28
|
+
"@powersync/common": "0.0.0-dev-20260216124709",
|
|
29
29
|
"react": "*"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"react": "18.3.1",
|
|
40
40
|
"react-dom": "18.3.1",
|
|
41
41
|
"react-error-boundary": "^4.1.0",
|
|
42
|
-
"@powersync/common": "0.0.0-dev-
|
|
43
|
-
"@powersync/drizzle-driver": "0.0.0-dev-
|
|
44
|
-
"@powersync/web": "0.0.0-dev-
|
|
42
|
+
"@powersync/common": "0.0.0-dev-20260216124709",
|
|
43
|
+
"@powersync/drizzle-driver": "0.0.0-dev-20260216124709",
|
|
44
|
+
"@powersync/web": "0.0.0-dev-20260216124709"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsc -b",
|