@syncular/react 0.19.0 → 0.20.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/README.md +9 -0
- package/dist/client.d.ts +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/runtime-version.d.ts +1 -1
- package/dist/runtime-version.js +1 -1
- package/dist/use-sync-progress.d.ts +6 -0
- package/dist/use-sync-progress.js +7 -0
- package/package.json +4 -4
- package/src/client.ts +4 -0
- package/src/index.ts +2 -0
- package/src/runtime-version.ts +1 -1
- package/src/use-sync-progress.ts +15 -0
package/README.md
CHANGED
|
@@ -343,3 +343,12 @@ come from that snapshot. Direct `conflicts`, `rejections`, and
|
|
|
343
343
|
`securityLifecycle` reads are now method calls. `normalizeClient` has been
|
|
344
344
|
removed; custom adapters must implement the canonical snapshot methods.
|
|
345
345
|
See the [client migration](https://syncular.dev/platform-web/#snapshot-api-migration).
|
|
346
|
+
|
|
347
|
+
## Live sync progress
|
|
348
|
+
|
|
349
|
+
`useSyncProgress(client)` subscribes to a direct, worker, Tauri, or React Native
|
|
350
|
+
client's live progress stream and returns `SyncProgress | undefined`. The hook
|
|
351
|
+
releases its subscription on unmount or when `client` changes. Download counters
|
|
352
|
+
use bytes; import counters use processed rows and can include uncommitted work.
|
|
353
|
+
See [browser progress](https://syncular.dev/platform-web/#live-sync-progress) for
|
|
354
|
+
the attempt, phase, failure, and completion contract.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** The provider uses the supplied client identity and canonical snapshot methods. */
|
|
2
|
-
import type { ClientSnapshotReader, ClientChangeListener, ClientDiagnosticsListener, InvalidationListener, LeadershipState, LocalDataPurgeInput, LocalDataPurgeResult, LocalDataRebootstrapInput, LocalDataRebootstrapResult, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, SecurityLifecycle, SqlRow, SqlValue, WindowBase, WindowState } from '@syncular/client';
|
|
2
|
+
import type { ClientSnapshotReader, SyncProgress, SyncProgressListener, ClientChangeListener, ClientDiagnosticsListener, InvalidationListener, LeadershipState, LocalDataPurgeInput, LocalDataPurgeResult, LocalDataRebootstrapInput, LocalDataRebootstrapResult, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, SecurityLifecycle, SqlRow, SqlValue, WindowBase, WindowState } from '@syncular/client';
|
|
3
3
|
export interface SyncClientLike extends ClientSnapshotReader {
|
|
4
4
|
readonly currentSchemaVersion?: number;
|
|
5
|
+
onProgress(listener: SyncProgressListener): () => void;
|
|
6
|
+
progressSnapshot(): SyncProgress | undefined;
|
|
5
7
|
onChange(listener: ClientChangeListener): () => void;
|
|
6
8
|
onDiagnostics(listener: ClientDiagnosticsListener): () => void;
|
|
7
9
|
onInvalidate(listener: InvalidationListener): () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export { type UseRawSqlOptions, type UseRawSqlResult, useRawSql, } from './use-r
|
|
|
23
23
|
export { type SyncStatus, useSyncStatus } from './use-sync-status.js';
|
|
24
24
|
export { type UseRetainedWindowResult, type UseWindowResult, useRetainedWindow, useWindow, } from './use-window.js';
|
|
25
25
|
export { createViteSyncClientResource, type RetainedSyncularResource, retainViteSyncClientResource, type ViteSyncClientResourceBootstrap, type ViteSyncClientResourceResult, } from './vite-hmr.js';
|
|
26
|
+
export { useSyncProgress } from './use-sync-progress.js';
|
package/dist/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { useRawSql, } from './use-raw-sql.js';
|
|
|
13
13
|
export { useSyncStatus } from './use-sync-status.js';
|
|
14
14
|
export { useRetainedWindow, useWindow, } from './use-window.js';
|
|
15
15
|
export { createViteSyncClientResource, retainViteSyncClientResource, } from './vite-hmr.js';
|
|
16
|
+
export { useSyncProgress } from './use-sync-progress.js';
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Vite HMR uses it to replace a worker owner after a Syncular package upgrade
|
|
4
4
|
* even when the application's generated schema version did not change.
|
|
5
5
|
*/
|
|
6
|
-
export declare const SYNCULAR_REACT_RUNTIME_VERSION = "0.
|
|
6
|
+
export declare const SYNCULAR_REACT_RUNTIME_VERSION = "0.20.0";
|
package/dist/runtime-version.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SyncProgress, SyncProgressListener } from '@syncular/client';
|
|
2
|
+
/** Live work snapshots; completion refers to one round (SPEC §7.6). */
|
|
3
|
+
export declare function useSyncProgress(client: {
|
|
4
|
+
onProgress(listener: SyncProgressListener): () => void;
|
|
5
|
+
progressSnapshot(): SyncProgress | undefined;
|
|
6
|
+
}): SyncProgress | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
/** Live work snapshots; completion refers to one round (SPEC §7.6). */
|
|
3
|
+
export function useSyncProgress(client) {
|
|
4
|
+
const subscribe = useCallback((notify) => client.onProgress(notify), [client]);
|
|
5
|
+
const snapshot = useCallback(() => client.progressSnapshot(), [client]);
|
|
6
|
+
return useSyncExternalStore(subscribe, snapshot, snapshot);
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "React hooks for Syncular offline-first sync",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
"test": "bun test --preload ./test/setup.ts"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@syncular/client": "0.
|
|
58
|
+
"@syncular/client": "0.20.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": ">=18.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@happy-dom/global-registrator": "^20.0.0",
|
|
65
|
-
"@syncular/core": "0.
|
|
66
|
-
"@syncular/server": "0.
|
|
65
|
+
"@syncular/core": "0.20.0",
|
|
66
|
+
"@syncular/server": "0.20.0",
|
|
67
67
|
"@testing-library/react": "^16.1.0",
|
|
68
68
|
"@types/react": "^18.3.0",
|
|
69
69
|
"@types/react-dom": "^18.3.0",
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** The provider uses the supplied client identity and canonical snapshot methods. */
|
|
2
2
|
import type {
|
|
3
3
|
ClientSnapshotReader,
|
|
4
|
+
SyncProgress,
|
|
5
|
+
SyncProgressListener,
|
|
4
6
|
ClientChangeListener,
|
|
5
7
|
ClientDiagnosticsListener,
|
|
6
8
|
InvalidationListener,
|
|
@@ -22,6 +24,8 @@ import type {
|
|
|
22
24
|
|
|
23
25
|
export interface SyncClientLike extends ClientSnapshotReader {
|
|
24
26
|
readonly currentSchemaVersion?: number;
|
|
27
|
+
onProgress(listener: SyncProgressListener): () => void;
|
|
28
|
+
progressSnapshot(): SyncProgress | undefined;
|
|
25
29
|
onChange(listener: ClientChangeListener): () => void;
|
|
26
30
|
onDiagnostics(listener: ClientDiagnosticsListener): () => void;
|
|
27
31
|
onInvalidate(listener: InvalidationListener): () => void;
|
package/src/index.ts
CHANGED
package/src/runtime-version.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SyncProgress, SyncProgressListener } from '@syncular/client';
|
|
2
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Live work snapshots; completion refers to one round (SPEC §7.6). */
|
|
5
|
+
export function useSyncProgress(client: {
|
|
6
|
+
onProgress(listener: SyncProgressListener): () => void;
|
|
7
|
+
progressSnapshot(): SyncProgress | undefined;
|
|
8
|
+
}): SyncProgress | undefined {
|
|
9
|
+
const subscribe = useCallback(
|
|
10
|
+
(notify: () => void) => client.onProgress(notify),
|
|
11
|
+
[client],
|
|
12
|
+
);
|
|
13
|
+
const snapshot = useCallback(() => client.progressSnapshot(), [client]);
|
|
14
|
+
return useSyncExternalStore(subscribe, snapshot, snapshot);
|
|
15
|
+
}
|