@powersync/react 0.0.0-dev-20251111122755 → 0.0.0-dev-20260202162549

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,87 +0,0 @@
1
- import { DifferentialWatchedQueryComparator, SQLOnChangeOptions } from '@powersync/common';
2
- import { UseSyncStreamOptions } from '../streams.js';
3
- export interface HookWatchOptions extends Omit<SQLOnChangeOptions, 'signal'> {
4
- /**
5
- * An optional array of sync streams (with names and parameters) backing the query.
6
- *
7
- * When set, `useQuery` will subscribe to those streams (and automatically handle unsubscribing from them, too).
8
- *
9
- * If {@link QuerySyncStreamOptions} is set on a stream, `useQuery` will remain in a loading state until that stream
10
- * is marked as {@link SyncSubscriptionDescription.hasSynced}. This ensures the query is not missing rows that haven't
11
- * been downloaded.
12
- * Note however that after an initial sync, the query will not block itself while new rows are downloading. Instead,
13
- * consistent sync snapshots will be made available as they've been processed by PowerSync.
14
- *
15
- * @experimental Sync streams are currently in alpha.
16
- */
17
- streams?: QuerySyncStreamOptions[];
18
- reportFetching?: boolean;
19
- }
20
- /**
21
- * Additional options to control how `useQuery` behaves when subscribing to a stream.
22
- */
23
- export interface QuerySyncStreamOptions extends UseSyncStreamOptions {
24
- /**
25
- * When set to `true`, a `useQuery` hook will remain in a loading state as long as the stream is resolving or
26
- * downloading for the first time (in other words, until {@link SyncSubscriptionDescription.hasSynced} is true).
27
- */
28
- waitForStream?: boolean;
29
- }
30
- export interface AdditionalOptions extends HookWatchOptions {
31
- runQueryOnce?: boolean;
32
- }
33
- export interface DifferentialHookOptions<RowType> extends HookWatchOptions {
34
- /**
35
- * Used to compare result sets.
36
- *
37
- * By default the hook will requery on any dependent table change. This will
38
- * emit a new hook result even if the result set has not changed.
39
- *
40
- * Specifying a {@link DifferentialWatchedQueryComparator} will remove emissions for
41
- * unchanged result sets.
42
- * Furthermore, emitted `data` arrays will preserve object references between result set emissions
43
- * for unchanged rows.
44
- * @example
45
- * ```javascript
46
- * {
47
- * rowComparator: {
48
- * keyBy: (item) => item.id,
49
- * compareBy: (item) => JSON.stringify(item)
50
- * }
51
- * }
52
- * ```
53
- */
54
- rowComparator?: DifferentialWatchedQueryComparator<RowType>;
55
- }
56
- export type ReadonlyQueryResult<RowType> = {
57
- readonly data: ReadonlyArray<Readonly<RowType>>;
58
- /**
59
- * Indicates the initial loading state (hard loading). Loading becomes false once the first set of results from the watched query is available or an error occurs.
60
- */
61
- readonly isLoading: boolean;
62
- /**
63
- * Indicates whether the query is currently fetching data, is true during the initial load and any time when the query is re-evaluating (useful for large queries).
64
- */
65
- readonly isFetching: boolean;
66
- readonly error: Error | undefined;
67
- /**
68
- * Function used to run the query again.
69
- */
70
- refresh?: (signal?: AbortSignal) => Promise<void>;
71
- };
72
- export type QueryResult<RowType> = {
73
- data: RowType[];
74
- /**
75
- * Indicates the initial loading state (hard loading). Loading becomes false once the first set of results from the watched query is available or an error occurs.
76
- */
77
- isLoading: boolean;
78
- /**
79
- * Indicates whether the query is currently fetching data, is true during the initial load and any time when the query is re-evaluating (useful for large queries).
80
- */
81
- isFetching: boolean;
82
- error: Error | undefined;
83
- /**
84
- * Function used to run the query again.
85
- */
86
- refresh?: (signal?: AbortSignal) => Promise<void>;
87
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=watch-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch-types.js","sourceRoot":"","sources":["../../../src/hooks/watched/watch-types.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
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 {};
@@ -1,62 +0,0 @@
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
@@ -1 +0,0 @@
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,MAAM,wBAAwB,CAAC;AActD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAI,KAAwC,EAAE,OAA0B,EAAE,EAAE;IAC3G,IAAI,SAAwB,CAAC;IAC7B,IAAI,CAAC;QACH,SAAS,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC,CAAC,wDAAwD;IACxE,CAAC;IACD,MAAM,QAAQ,GAAG,SAAU,CAAC;IAE5B,MAAM,iBAAiB,GAAG,KAAK,CAAC,qBAAqB,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7F,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAEnD,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,GAAG,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE7G,IACE,gBAAgB,CAAC,OAAO,CAAC,YAAY,KAAK,QAAQ,CAAC,GAAG;QACtD,gBAAgB,CAAC,OAAO,CAAC,iBAAiB,IAAI,iBAAiB;QAC/D,gBAAgB,CAAC,OAAO,CAAC,kBAAkB,IAAI,kBAAkB,EACjE,CAAC;QACD,gBAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC;QACrD,gBAAgB,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC/D,gBAAgB,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BAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE7D,OAAO;QACL,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC,CAAC"}
package/lib/index.d.ts DELETED
@@ -1,12 +0,0 @@
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 DELETED
@@ -1,11 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
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"}