@fatagnus/dink-sync 1.0.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 +312 -0
- package/dist/client/attachment.d.ts +225 -0
- package/dist/client/attachment.d.ts.map +1 -0
- package/dist/client/attachment.js +402 -0
- package/dist/client/attachment.js.map +1 -0
- package/dist/client/binary-encoding.d.ts +45 -0
- package/dist/client/binary-encoding.d.ts.map +1 -0
- package/dist/client/binary-encoding.js +90 -0
- package/dist/client/binary-encoding.js.map +1 -0
- package/dist/client/collection.d.ts +10 -0
- package/dist/client/collection.d.ts.map +1 -0
- package/dist/client/collection.js +924 -0
- package/dist/client/collection.js.map +1 -0
- package/dist/client/compression.d.ts +56 -0
- package/dist/client/compression.d.ts.map +1 -0
- package/dist/client/compression.js +173 -0
- package/dist/client/compression.js.map +1 -0
- package/dist/client/crdt/index.d.ts +2 -0
- package/dist/client/crdt/index.d.ts.map +1 -0
- package/dist/client/crdt/index.js +2 -0
- package/dist/client/crdt/index.js.map +1 -0
- package/dist/client/crdt/yjs-doc.d.ts +88 -0
- package/dist/client/crdt/yjs-doc.d.ts.map +1 -0
- package/dist/client/crdt/yjs-doc.js +123 -0
- package/dist/client/crdt/yjs-doc.js.map +1 -0
- package/dist/client/index.d.ts +66 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +233 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/mock-transport.d.ts +155 -0
- package/dist/client/mock-transport.d.ts.map +1 -0
- package/dist/client/mock-transport.js +292 -0
- package/dist/client/mock-transport.js.map +1 -0
- package/dist/client/network-detector.d.ts +65 -0
- package/dist/client/network-detector.d.ts.map +1 -0
- package/dist/client/network-detector.js +147 -0
- package/dist/client/network-detector.js.map +1 -0
- package/dist/client/provisioning.d.ts +126 -0
- package/dist/client/provisioning.d.ts.map +1 -0
- package/dist/client/provisioning.js +125 -0
- package/dist/client/provisioning.js.map +1 -0
- package/dist/client/signal.d.ts +13 -0
- package/dist/client/signal.d.ts.map +1 -0
- package/dist/client/signal.js +27 -0
- package/dist/client/signal.js.map +1 -0
- package/dist/client/sync-engine.d.ts +298 -0
- package/dist/client/sync-engine.d.ts.map +1 -0
- package/dist/client/sync-engine.js +904 -0
- package/dist/client/sync-engine.js.map +1 -0
- package/dist/client/synced-edge.d.ts +109 -0
- package/dist/client/synced-edge.d.ts.map +1 -0
- package/dist/client/synced-edge.js +179 -0
- package/dist/client/synced-edge.js.map +1 -0
- package/dist/client/synced-offline-edge-types.d.ts +540 -0
- package/dist/client/synced-offline-edge-types.d.ts.map +1 -0
- package/dist/client/synced-offline-edge-types.js +10 -0
- package/dist/client/synced-offline-edge-types.js.map +1 -0
- package/dist/client/synced-offline-edge.d.ts +54 -0
- package/dist/client/synced-offline-edge.d.ts.map +1 -0
- package/dist/client/synced-offline-edge.js +731 -0
- package/dist/client/synced-offline-edge.js.map +1 -0
- package/dist/client/transport.d.ts +202 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +409 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client/types.d.ts +622 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +60 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/validation.d.ts +61 -0
- package/dist/client/validation.d.ts.map +1 -0
- package/dist/client/validation.js +57 -0
- package/dist/client/validation.js.map +1 -0
- package/dist/client/versioning.d.ts +134 -0
- package/dist/client/versioning.d.ts.map +1 -0
- package/dist/client/versioning.js +304 -0
- package/dist/client/versioning.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence/encryption.d.ts +114 -0
- package/dist/persistence/encryption.d.ts.map +1 -0
- package/dist/persistence/encryption.js +286 -0
- package/dist/persistence/encryption.js.map +1 -0
- package/dist/persistence/index.d.ts +21 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +20 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/memory.d.ts +32 -0
- package/dist/persistence/memory.d.ts.map +1 -0
- package/dist/persistence/memory.js +57 -0
- package/dist/persistence/memory.js.map +1 -0
- package/dist/persistence/migrations.d.ts +106 -0
- package/dist/persistence/migrations.d.ts.map +1 -0
- package/dist/persistence/migrations.js +176 -0
- package/dist/persistence/migrations.js.map +1 -0
- package/dist/persistence/pending-queue.d.ts +109 -0
- package/dist/persistence/pending-queue.d.ts.map +1 -0
- package/dist/persistence/pending-queue.js +249 -0
- package/dist/persistence/pending-queue.js.map +1 -0
- package/dist/persistence/pglite.d.ts +72 -0
- package/dist/persistence/pglite.d.ts.map +1 -0
- package/dist/persistence/pglite.js +126 -0
- package/dist/persistence/pglite.js.map +1 -0
- package/dist/persistence/quota-manager.d.ts +134 -0
- package/dist/persistence/quota-manager.d.ts.map +1 -0
- package/dist/persistence/quota-manager.js +242 -0
- package/dist/persistence/quota-manager.js.map +1 -0
- package/dist/persistence/types.d.ts +54 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +2 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/react/OfflineEdgeProvider.d.ts +91 -0
- package/dist/react/OfflineEdgeProvider.d.ts.map +1 -0
- package/dist/react/OfflineEdgeProvider.js +127 -0
- package/dist/react/OfflineEdgeProvider.js.map +1 -0
- package/dist/react/SyncedOfflineEdgeProvider.d.ts +105 -0
- package/dist/react/SyncedOfflineEdgeProvider.d.ts.map +1 -0
- package/dist/react/SyncedOfflineEdgeProvider.js +138 -0
- package/dist/react/SyncedOfflineEdgeProvider.js.map +1 -0
- package/dist/react/index.d.ts +50 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +51 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCollection.d.ts +77 -0
- package/dist/react/useCollection.d.ts.map +1 -0
- package/dist/react/useCollection.js +113 -0
- package/dist/react/useCollection.js.map +1 -0
- package/dist/react/useCollectionSyncMode.d.ts +61 -0
- package/dist/react/useCollectionSyncMode.d.ts.map +1 -0
- package/dist/react/useCollectionSyncMode.js +93 -0
- package/dist/react/useCollectionSyncMode.js.map +1 -0
- package/dist/react/useConnectionState.d.ts +44 -0
- package/dist/react/useConnectionState.d.ts.map +1 -0
- package/dist/react/useConnectionState.js +46 -0
- package/dist/react/useConnectionState.js.map +1 -0
- package/dist/react/useDocumentSyncStatus.d.ts +72 -0
- package/dist/react/useDocumentSyncStatus.d.ts.map +1 -0
- package/dist/react/useDocumentSyncStatus.js +110 -0
- package/dist/react/useDocumentSyncStatus.js.map +1 -0
- package/dist/react/useOfflineEdge.d.ts +58 -0
- package/dist/react/useOfflineEdge.d.ts.map +1 -0
- package/dist/react/useOfflineEdge.js +54 -0
- package/dist/react/useOfflineEdge.js.map +1 -0
- package/dist/react/usePendingChanges.d.ts +67 -0
- package/dist/react/usePendingChanges.d.ts.map +1 -0
- package/dist/react/usePendingChanges.js +90 -0
- package/dist/react/usePendingChanges.js.map +1 -0
- package/dist/react/useRejectedDocuments.d.ts +112 -0
- package/dist/react/useRejectedDocuments.d.ts.map +1 -0
- package/dist/react/useRejectedDocuments.js +213 -0
- package/dist/react/useRejectedDocuments.js.map +1 -0
- package/dist/react/useSyncControls.d.ts +96 -0
- package/dist/react/useSyncControls.d.ts.map +1 -0
- package/dist/react/useSyncControls.js +112 -0
- package/dist/react/useSyncControls.js.map +1 -0
- package/dist/react/useSyncProgress.d.ts +78 -0
- package/dist/react/useSyncProgress.d.ts.map +1 -0
- package/dist/react/useSyncProgress.js +90 -0
- package/dist/react/useSyncProgress.js.map +1 -0
- package/dist/react/useSyncRejected.d.ts +47 -0
- package/dist/react/useSyncRejected.d.ts.map +1 -0
- package/dist/react/useSyncRejected.js +55 -0
- package/dist/react/useSyncRejected.js.map +1 -0
- package/dist/react/useSyncStatus.d.ts +56 -0
- package/dist/react/useSyncStatus.d.ts.map +1 -0
- package/dist/react/useSyncStatus.js +59 -0
- package/dist/react/useSyncStatus.js.map +1 -0
- package/dist/react/useSyncedOfflineEdge.d.ts +69 -0
- package/dist/react/useSyncedOfflineEdge.d.ts.map +1 -0
- package/dist/react/useSyncedOfflineEdge.js +65 -0
- package/dist/react/useSyncedOfflineEdge.js.map +1 -0
- package/dist/service-worker/index.d.ts +7 -0
- package/dist/service-worker/index.d.ts.map +1 -0
- package/dist/service-worker/index.js +7 -0
- package/dist/service-worker/index.js.map +1 -0
- package/dist/service-worker/sync-worker.d.ts +230 -0
- package/dist/service-worker/sync-worker.d.ts.map +1 -0
- package/dist/service-worker/sync-worker.js +471 -0
- package/dist/service-worker/sync-worker.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSyncRejected - React hook for handling sync rejection events.
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import { SyncErrorCode } from '../client/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to sync rejection events from a collection.
|
|
8
|
+
*
|
|
9
|
+
* @param collection - The collection to listen for rejections
|
|
10
|
+
* @param options - Callbacks for handling different rejection types
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function TaskList() {
|
|
15
|
+
* const tasks = client.collection<Task>('tasks');
|
|
16
|
+
*
|
|
17
|
+
* useSyncRejected(tasks, {
|
|
18
|
+
* onRejected: (event) => {
|
|
19
|
+
* toast.error(`Failed to sync: ${event.error.message}`);
|
|
20
|
+
* },
|
|
21
|
+
* onUniqueViolation: (event, field) => {
|
|
22
|
+
* toast.error(`Duplicate ${field || 'value'} detected`);
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // ... rest of component
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function useSyncRejected(collection, options) {
|
|
31
|
+
// Use refs to avoid re-subscribing when callbacks change
|
|
32
|
+
const optionsRef = useRef(options);
|
|
33
|
+
optionsRef.current = options;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const unsubscribe = collection.onSyncRejected((event) => {
|
|
36
|
+
const opts = optionsRef.current;
|
|
37
|
+
// Call general handler
|
|
38
|
+
opts.onRejected?.(event);
|
|
39
|
+
// Call specific handlers based on error code
|
|
40
|
+
switch (event.error.code) {
|
|
41
|
+
case SyncErrorCode.UniqueViolation:
|
|
42
|
+
opts.onUniqueViolation?.(event, event.error.field);
|
|
43
|
+
break;
|
|
44
|
+
case SyncErrorCode.ValidationError:
|
|
45
|
+
opts.onValidationError?.(event);
|
|
46
|
+
break;
|
|
47
|
+
case SyncErrorCode.PermissionDenied:
|
|
48
|
+
opts.onPermissionDenied?.(event);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return unsubscribe;
|
|
53
|
+
}, [collection]);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=useSyncRejected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncRejected.js","sourceRoot":"","sources":["../../src/react/useSyncRejected.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,aAAa,EAA2C,MAAM,oBAAoB,CAAC;AAgB5F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,eAAe,CAC7B,UAAyB,EACzB,OAAkC;IAElC,yDAAyD;IACzD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,EAAE;YACtD,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;YAEhC,uBAAuB;YACvB,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC;YAEzB,6CAA6C;YAC7C,QAAQ,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;gBACzB,KAAK,aAAa,CAAC,eAAe;oBAChC,IAAI,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACnD,MAAM;gBACR,KAAK,aAAa,CAAC,eAAe;oBAChC,IAAI,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,CAAC;oBAChC,MAAM;gBACR,KAAK,aAAa,CAAC,gBAAgB;oBACjC,IAAI,CAAC,kBAAkB,EAAE,CAAC,KAAK,CAAC,CAAC;oBACjC,MAAM;YACV,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSyncStatus - React hook for accessing sync status from a SyncedDocument.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides a convenient way to access sync status with derived boolean flags.
|
|
5
|
+
*/
|
|
6
|
+
import { SyncStatus, type SyncError, type SyncedDocument } from '../client/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Result of useSyncStatus hook with derived boolean flags.
|
|
9
|
+
*/
|
|
10
|
+
export interface SyncStatusResult {
|
|
11
|
+
/** Current sync status */
|
|
12
|
+
readonly status: SyncStatus;
|
|
13
|
+
/** True if document has not been synced yet (local only) */
|
|
14
|
+
readonly isLocal: boolean;
|
|
15
|
+
/** True if document is currently being synced */
|
|
16
|
+
readonly isSyncing: boolean;
|
|
17
|
+
/** True if document is synced with server */
|
|
18
|
+
readonly isSynced: boolean;
|
|
19
|
+
/** True if sync was rejected by server */
|
|
20
|
+
readonly isRejected: boolean;
|
|
21
|
+
/** True if document has pending changes (local or syncing) */
|
|
22
|
+
readonly isPending: boolean;
|
|
23
|
+
/** Error details if sync was rejected */
|
|
24
|
+
readonly error?: SyncError;
|
|
25
|
+
/** Timestamp of last sync attempt */
|
|
26
|
+
readonly lastSyncAttempt?: number;
|
|
27
|
+
/** Timestamp of last successful sync */
|
|
28
|
+
readonly lastSynced?: number;
|
|
29
|
+
/** Number of retry attempts */
|
|
30
|
+
readonly retryCount: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Extract sync status from a SyncedDocument with derived boolean flags.
|
|
34
|
+
*
|
|
35
|
+
* @param document - A document with sync metadata (_sync property)
|
|
36
|
+
* @returns Sync status with convenience boolean flags
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* function TaskItem({ task }: { task: SyncedDocument<Task> }) {
|
|
41
|
+
* const { isPending, isRejected, error } = useSyncStatus(task);
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <div className={isRejected ? 'border-red-500' : ''}>
|
|
45
|
+
* <span>{task.title}</span>
|
|
46
|
+
* {isPending && <Spinner className="ml-2" />}
|
|
47
|
+
* {isRejected && <span className="text-red-500">{error?.message}</span>}
|
|
48
|
+
* </div>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function useSyncStatus<T extends {
|
|
54
|
+
id: string;
|
|
55
|
+
}>(document: SyncedDocument<T> | null | undefined): SyncStatusResult;
|
|
56
|
+
//# sourceMappingURL=useSyncStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncStatus.d.ts","sourceRoot":"","sources":["../../src/react/useSyncStatus.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,wCAAwC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACpD,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAC7C,gBAAgB,CA+BlB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSyncStatus - React hook for accessing sync status from a SyncedDocument.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides a convenient way to access sync status with derived boolean flags.
|
|
5
|
+
*/
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { SyncStatus } from '../client/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Extract sync status from a SyncedDocument with derived boolean flags.
|
|
10
|
+
*
|
|
11
|
+
* @param document - A document with sync metadata (_sync property)
|
|
12
|
+
* @returns Sync status with convenience boolean flags
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function TaskItem({ task }: { task: SyncedDocument<Task> }) {
|
|
17
|
+
* const { isPending, isRejected, error } = useSyncStatus(task);
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div className={isRejected ? 'border-red-500' : ''}>
|
|
21
|
+
* <span>{task.title}</span>
|
|
22
|
+
* {isPending && <Spinner className="ml-2" />}
|
|
23
|
+
* {isRejected && <span className="text-red-500">{error?.message}</span>}
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function useSyncStatus(document) {
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
if (!document || !document._sync) {
|
|
32
|
+
// Return default "synced" state for missing documents
|
|
33
|
+
return {
|
|
34
|
+
status: SyncStatus.Synced,
|
|
35
|
+
isLocal: false,
|
|
36
|
+
isSyncing: false,
|
|
37
|
+
isSynced: true,
|
|
38
|
+
isRejected: false,
|
|
39
|
+
isPending: false,
|
|
40
|
+
retryCount: 0,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const sync = document._sync;
|
|
44
|
+
const status = sync.status;
|
|
45
|
+
return {
|
|
46
|
+
status,
|
|
47
|
+
isLocal: status === SyncStatus.Local,
|
|
48
|
+
isSyncing: status === SyncStatus.Syncing,
|
|
49
|
+
isSynced: status === SyncStatus.Synced,
|
|
50
|
+
isRejected: status === SyncStatus.Rejected,
|
|
51
|
+
isPending: status === SyncStatus.Local || status === SyncStatus.Syncing,
|
|
52
|
+
error: sync.error,
|
|
53
|
+
lastSyncAttempt: sync.lastSyncAttempt,
|
|
54
|
+
lastSynced: sync.lastSynced,
|
|
55
|
+
retryCount: sync.retryCount ?? 0,
|
|
56
|
+
};
|
|
57
|
+
}, [document?._sync?.status, document?._sync?.error, document?._sync?.lastSyncAttempt, document?._sync?.lastSynced, document?._sync?.retryCount]);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=useSyncStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncStatus.js","sourceRoot":"","sources":["../../src/react/useSyncStatus.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAuC,MAAM,oBAAoB,CAAC;AA4BrF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAC3B,QAA8C;IAE9C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjC,sDAAsD;YACtD,OAAO;gBACL,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,KAAK;gBAChB,QAAQ,EAAE,IAAI;gBACd,UAAU,EAAE,KAAK;gBACjB,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,CAAC;aACd,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE3B,OAAO;YACL,MAAM;YACN,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC,KAAK;YACpC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC,OAAO;YACxC,QAAQ,EAAE,MAAM,KAAK,UAAU,CAAC,MAAM;YACtC,UAAU,EAAE,MAAM,KAAK,UAAU,CAAC,QAAQ;YAC1C,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC,KAAK,IAAI,MAAM,KAAK,UAAU,CAAC,OAAO;YACvE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,CAAC;SACjC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AACpJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSyncedOfflineEdge - React hook to access the SyncedOfflineEdge from context.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the full SyncedOfflineEdge instance and its initialization state.
|
|
5
|
+
* Must be used within a SyncedOfflineEdgeProvider.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useSyncedOfflineEdge } from '@fatagnus/dink-sync/react';
|
|
10
|
+
*
|
|
11
|
+
* function MyComponent() {
|
|
12
|
+
* const { edge, isLoading, isReady, error } = useSyncedOfflineEdge();
|
|
13
|
+
*
|
|
14
|
+
* if (isLoading) return <Spinner />;
|
|
15
|
+
* if (error) return <Error message={error.message} />;
|
|
16
|
+
* if (!isReady || !edge) return null;
|
|
17
|
+
*
|
|
18
|
+
* const tasks = edge.collection<Task>('tasks');
|
|
19
|
+
* // Use tasks collection with full sync capabilities...
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { SyncedOfflineEdge } from '../client/synced-offline-edge-types.js';
|
|
24
|
+
/**
|
|
25
|
+
* Result of useSyncedOfflineEdge hook.
|
|
26
|
+
*/
|
|
27
|
+
export interface UseSyncedOfflineEdgeResult {
|
|
28
|
+
/** The initialized SyncedOfflineEdge, or null if not yet ready */
|
|
29
|
+
edge: SyncedOfflineEdge | null;
|
|
30
|
+
/** True while initializing */
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
/** True when edge is ready to use */
|
|
33
|
+
isReady: boolean;
|
|
34
|
+
/** Error if initialization failed */
|
|
35
|
+
error: Error | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook to access the full SyncedOfflineEdge context state.
|
|
39
|
+
*
|
|
40
|
+
* Returns loading state, error state, and the edge instance when ready.
|
|
41
|
+
* The edge provides access to typed collections with full sync capabilities.
|
|
42
|
+
*
|
|
43
|
+
* @throws Error if used outside of SyncedOfflineEdgeProvider
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* function TaskList() {
|
|
48
|
+
* const { edge, isLoading, isReady, error } = useSyncedOfflineEdge();
|
|
49
|
+
*
|
|
50
|
+
* if (isLoading) return <Spinner />;
|
|
51
|
+
* if (error) return <Error message={error.message} />;
|
|
52
|
+
* if (!isReady || !edge) return null;
|
|
53
|
+
*
|
|
54
|
+
* // Get a typed collection with sync capabilities
|
|
55
|
+
* const tasks = edge.collection<Task>('tasks');
|
|
56
|
+
*
|
|
57
|
+
* // Access sync control methods
|
|
58
|
+
* const syncMode = edge.getSyncMode('tasks');
|
|
59
|
+
* edge.setSyncMode('tasks', 'manual');
|
|
60
|
+
*
|
|
61
|
+
* // Manual sync control
|
|
62
|
+
* await edge.flush('tasks');
|
|
63
|
+
* edge.pause();
|
|
64
|
+
* edge.resume();
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function useSyncedOfflineEdge(): UseSyncedOfflineEdgeResult;
|
|
69
|
+
//# sourceMappingURL=useSyncedOfflineEdge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncedOfflineEdge.d.ts","sourceRoot":"","sources":["../../src/react/useSyncedOfflineEdge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kEAAkE;IAClE,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,IAAI,0BAA0B,CAQjE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSyncedOfflineEdge - React hook to access the SyncedOfflineEdge from context.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the full SyncedOfflineEdge instance and its initialization state.
|
|
5
|
+
* Must be used within a SyncedOfflineEdgeProvider.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useSyncedOfflineEdge } from '@fatagnus/dink-sync/react';
|
|
10
|
+
*
|
|
11
|
+
* function MyComponent() {
|
|
12
|
+
* const { edge, isLoading, isReady, error } = useSyncedOfflineEdge();
|
|
13
|
+
*
|
|
14
|
+
* if (isLoading) return <Spinner />;
|
|
15
|
+
* if (error) return <Error message={error.message} />;
|
|
16
|
+
* if (!isReady || !edge) return null;
|
|
17
|
+
*
|
|
18
|
+
* const tasks = edge.collection<Task>('tasks');
|
|
19
|
+
* // Use tasks collection with full sync capabilities...
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { useContext } from 'react';
|
|
24
|
+
// Import the context from SyncedOfflineEdgeProvider
|
|
25
|
+
// We use a lazy import pattern to avoid circular dependencies
|
|
26
|
+
import { SyncedOfflineEdgeContext } from './SyncedOfflineEdgeProvider.js';
|
|
27
|
+
/**
|
|
28
|
+
* Hook to access the full SyncedOfflineEdge context state.
|
|
29
|
+
*
|
|
30
|
+
* Returns loading state, error state, and the edge instance when ready.
|
|
31
|
+
* The edge provides access to typed collections with full sync capabilities.
|
|
32
|
+
*
|
|
33
|
+
* @throws Error if used outside of SyncedOfflineEdgeProvider
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* function TaskList() {
|
|
38
|
+
* const { edge, isLoading, isReady, error } = useSyncedOfflineEdge();
|
|
39
|
+
*
|
|
40
|
+
* if (isLoading) return <Spinner />;
|
|
41
|
+
* if (error) return <Error message={error.message} />;
|
|
42
|
+
* if (!isReady || !edge) return null;
|
|
43
|
+
*
|
|
44
|
+
* // Get a typed collection with sync capabilities
|
|
45
|
+
* const tasks = edge.collection<Task>('tasks');
|
|
46
|
+
*
|
|
47
|
+
* // Access sync control methods
|
|
48
|
+
* const syncMode = edge.getSyncMode('tasks');
|
|
49
|
+
* edge.setSyncMode('tasks', 'manual');
|
|
50
|
+
*
|
|
51
|
+
* // Manual sync control
|
|
52
|
+
* await edge.flush('tasks');
|
|
53
|
+
* edge.pause();
|
|
54
|
+
* edge.resume();
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function useSyncedOfflineEdge() {
|
|
59
|
+
const context = useContext(SyncedOfflineEdgeContext);
|
|
60
|
+
if (context === null) {
|
|
61
|
+
throw new Error('useSyncedOfflineEdge must be used within a SyncedOfflineEdgeProvider');
|
|
62
|
+
}
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=useSyncedOfflineEdge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncedOfflineEdge.js","sourceRoot":"","sources":["../../src/react/useSyncedOfflineEdge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAiBnC,oDAAoD;AACpD,8DAA8D;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,OAAO,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAC;IAErD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Worker Background Sync module
|
|
3
|
+
*
|
|
4
|
+
* Provides background sync capabilities for offline-first applications.
|
|
5
|
+
*/
|
|
6
|
+
export { BackgroundSyncManager, SyncWorkerHandler, SyncWorkerMessageType, createSyncWorkerScript, registerSyncWorker, getBackgroundSyncManager, DEFAULT_SYNC_TAG, DEFAULT_PERIODIC_SYNC_TAG, DEFAULT_PERIODIC_SYNC_INTERVAL, type SyncWorkerMessage, type SyncWorkerMessageEvent, type SyncEvent, type PeriodicSyncEvent, type SyncWorkerScriptConfig, type Unsubscribe, } from './sync-worker.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service-worker/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,yBAAyB,EACzB,8BAA8B,EAC9B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Worker Background Sync module
|
|
3
|
+
*
|
|
4
|
+
* Provides background sync capabilities for offline-first applications.
|
|
5
|
+
*/
|
|
6
|
+
export { BackgroundSyncManager, SyncWorkerHandler, SyncWorkerMessageType, createSyncWorkerScript, registerSyncWorker, getBackgroundSyncManager, DEFAULT_SYNC_TAG, DEFAULT_PERIODIC_SYNC_TAG, DEFAULT_PERIODIC_SYNC_INTERVAL, } from './sync-worker.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service-worker/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,yBAAyB,EACzB,8BAA8B,GAO/B,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Worker Background Sync for Dink Offline-First SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - Background Sync API registration for one-time sync when online
|
|
6
|
+
* - Periodic Background Sync for regular sync intervals
|
|
7
|
+
* - Fallback interval-based sync for browsers without Background Sync
|
|
8
|
+
* - Message passing between main thread and service worker
|
|
9
|
+
* - IndexedDB access for pending queue in service worker context
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Service Worker ExtendableMessageEvent type
|
|
13
|
+
* Using a local interface to avoid conflicts with DOM lib types
|
|
14
|
+
*/
|
|
15
|
+
export interface SyncWorkerMessageEvent {
|
|
16
|
+
readonly data: unknown;
|
|
17
|
+
readonly source: {
|
|
18
|
+
postMessage: (message: unknown) => void;
|
|
19
|
+
} | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Message types for communication between main thread and service worker
|
|
23
|
+
*/
|
|
24
|
+
export declare const SyncWorkerMessageType: {
|
|
25
|
+
/** Request sync from main thread */
|
|
26
|
+
readonly SYNC_REQUEST: "SYNC_REQUEST";
|
|
27
|
+
/** Sync completed successfully */
|
|
28
|
+
readonly SYNC_COMPLETE: "SYNC_COMPLETE";
|
|
29
|
+
/** Sync failed with error */
|
|
30
|
+
readonly SYNC_ERROR: "SYNC_ERROR";
|
|
31
|
+
/** Notify worker of pending changes count */
|
|
32
|
+
readonly PENDING_CHANGES: "PENDING_CHANGES";
|
|
33
|
+
/** Request to register a sync tag */
|
|
34
|
+
readonly REGISTER_SYNC: "REGISTER_SYNC";
|
|
35
|
+
};
|
|
36
|
+
export type SyncWorkerMessageType = typeof SyncWorkerMessageType[keyof typeof SyncWorkerMessageType];
|
|
37
|
+
/**
|
|
38
|
+
* Message structure for worker communication
|
|
39
|
+
*/
|
|
40
|
+
export interface SyncWorkerMessage {
|
|
41
|
+
type: SyncWorkerMessageType;
|
|
42
|
+
payload: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe function type
|
|
46
|
+
*/
|
|
47
|
+
export type Unsubscribe = () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Sync event from Background Sync API
|
|
50
|
+
*/
|
|
51
|
+
export interface SyncEvent {
|
|
52
|
+
tag: string;
|
|
53
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
54
|
+
lastChance: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Periodic sync event
|
|
58
|
+
*/
|
|
59
|
+
export interface PeriodicSyncEvent {
|
|
60
|
+
tag: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* BackgroundSyncManager - Main thread API for Background Sync
|
|
64
|
+
*
|
|
65
|
+
* Manages registration of background sync events and provides
|
|
66
|
+
* fallback for browsers without Background Sync support.
|
|
67
|
+
*/
|
|
68
|
+
export declare class BackgroundSyncManager {
|
|
69
|
+
private registration;
|
|
70
|
+
private fallbackTimer;
|
|
71
|
+
private fallbackHandler;
|
|
72
|
+
constructor(registration: ServiceWorkerRegistration);
|
|
73
|
+
/**
|
|
74
|
+
* Check if Background Sync API is supported
|
|
75
|
+
*/
|
|
76
|
+
isSupported(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Check if Periodic Background Sync API is supported
|
|
79
|
+
*/
|
|
80
|
+
isPeriodicSyncSupported(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Request a one-time background sync
|
|
83
|
+
* @param tag - Unique tag to identify this sync
|
|
84
|
+
* @returns true if registration succeeded, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
requestSync(tag: string): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Request periodic background sync
|
|
89
|
+
* @param tag - Unique tag to identify this periodic sync
|
|
90
|
+
* @param minInterval - Minimum interval between syncs in milliseconds
|
|
91
|
+
* @returns true if registration succeeded, false otherwise
|
|
92
|
+
*/
|
|
93
|
+
requestPeriodicSync(tag: string, minInterval: number): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Unregister a periodic background sync
|
|
96
|
+
* @param tag - Tag of the periodic sync to unregister
|
|
97
|
+
*/
|
|
98
|
+
unregisterPeriodicSync(tag: string): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Get all active sync tags
|
|
101
|
+
* @returns Array of active sync tags
|
|
102
|
+
*/
|
|
103
|
+
getActiveSyncTags(): Promise<string[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Set the fallback sync handler for browsers without Background Sync
|
|
106
|
+
* @param handler - Async function to call for sync
|
|
107
|
+
*/
|
|
108
|
+
setFallbackSyncHandler(handler: () => Promise<void>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Start fallback interval-based sync
|
|
111
|
+
* Only activates if Background Sync is not supported
|
|
112
|
+
* @param intervalMs - Sync interval in milliseconds
|
|
113
|
+
*/
|
|
114
|
+
startFallbackSync(intervalMs: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Stop fallback interval-based sync
|
|
117
|
+
*/
|
|
118
|
+
stopFallbackSync(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Post a message to the service worker
|
|
121
|
+
* @param message - Message to send
|
|
122
|
+
*/
|
|
123
|
+
postMessage(message: SyncWorkerMessage): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* SyncWorkerHandler - Service Worker side handler
|
|
127
|
+
*
|
|
128
|
+
* Handles sync events and messages in the service worker context.
|
|
129
|
+
*/
|
|
130
|
+
export declare class SyncWorkerHandler {
|
|
131
|
+
private syncHandler;
|
|
132
|
+
private periodicSyncHandler;
|
|
133
|
+
private tagPrefix;
|
|
134
|
+
private errorCallbacks;
|
|
135
|
+
private lastChanceCallbacks;
|
|
136
|
+
/**
|
|
137
|
+
* Set the tag prefix for filtering sync events
|
|
138
|
+
* @param prefix - Only handle sync events with tags starting with this prefix
|
|
139
|
+
*/
|
|
140
|
+
setTagPrefix(prefix: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Set the sync handler function
|
|
143
|
+
* @param handler - Async function to call when sync event fires
|
|
144
|
+
*/
|
|
145
|
+
setSyncHandler(handler: (tag: string) => Promise<void>): void;
|
|
146
|
+
/**
|
|
147
|
+
* Set the periodic sync handler function
|
|
148
|
+
* @param handler - Async function to call when periodic sync event fires
|
|
149
|
+
*/
|
|
150
|
+
setPeriodicSyncHandler(handler: (tag: string) => Promise<void>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Handle a sync event from the Background Sync API
|
|
153
|
+
* @param event - Sync event
|
|
154
|
+
*/
|
|
155
|
+
handleSyncEvent(event: SyncEvent): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Handle a periodic sync event
|
|
158
|
+
* @param event - Periodic sync event
|
|
159
|
+
*/
|
|
160
|
+
handlePeriodicSyncEvent(event: PeriodicSyncEvent): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Handle a message from the main thread
|
|
163
|
+
* @param event - Message event
|
|
164
|
+
*/
|
|
165
|
+
handleMessage(event: SyncWorkerMessageEvent): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Subscribe to error events
|
|
168
|
+
* @param callback - Function to call when an error occurs
|
|
169
|
+
* @returns Unsubscribe function
|
|
170
|
+
*/
|
|
171
|
+
onError(callback: (error: Error) => void): Unsubscribe;
|
|
172
|
+
/**
|
|
173
|
+
* Subscribe to last chance events
|
|
174
|
+
* Called when a sync fails and it's the browser's last attempt
|
|
175
|
+
* @param callback - Function to call on last chance
|
|
176
|
+
* @returns Unsubscribe function
|
|
177
|
+
*/
|
|
178
|
+
onLastChance(callback: (tag: string) => void): Unsubscribe;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Configuration for generating a service worker script
|
|
182
|
+
*/
|
|
183
|
+
export interface SyncWorkerScriptConfig {
|
|
184
|
+
/** Tag for one-time sync events */
|
|
185
|
+
syncTag: string;
|
|
186
|
+
/** Tag for periodic sync events (optional) */
|
|
187
|
+
periodicSyncTag?: string;
|
|
188
|
+
/** IndexedDB database name for pending queue */
|
|
189
|
+
dbName: string;
|
|
190
|
+
/** Store name within IndexedDB */
|
|
191
|
+
storeName?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Generate a service worker script string for background sync
|
|
195
|
+
*
|
|
196
|
+
* This generates a self-contained service worker script that can be
|
|
197
|
+
* registered to handle background sync events and access IndexedDB
|
|
198
|
+
* for the pending queue.
|
|
199
|
+
*
|
|
200
|
+
* @param config - Configuration for the script
|
|
201
|
+
* @returns Service worker script as a string
|
|
202
|
+
*/
|
|
203
|
+
export declare function createSyncWorkerScript(config: SyncWorkerScriptConfig): string;
|
|
204
|
+
/**
|
|
205
|
+
* Register the background sync service worker
|
|
206
|
+
*
|
|
207
|
+
* @param scriptUrl - URL of the service worker script
|
|
208
|
+
* @param options - Registration options
|
|
209
|
+
* @returns BackgroundSyncManager instance
|
|
210
|
+
*/
|
|
211
|
+
export declare function registerSyncWorker(scriptUrl: string, options?: RegistrationOptions): Promise<BackgroundSyncManager>;
|
|
212
|
+
/**
|
|
213
|
+
* Get the BackgroundSyncManager for an existing service worker
|
|
214
|
+
*
|
|
215
|
+
* @returns BackgroundSyncManager instance or null if no service worker
|
|
216
|
+
*/
|
|
217
|
+
export declare function getBackgroundSyncManager(): Promise<BackgroundSyncManager | null>;
|
|
218
|
+
/**
|
|
219
|
+
* Default sync tag for Dink background sync
|
|
220
|
+
*/
|
|
221
|
+
export declare const DEFAULT_SYNC_TAG = "dink-sync";
|
|
222
|
+
/**
|
|
223
|
+
* Default periodic sync tag for Dink background sync
|
|
224
|
+
*/
|
|
225
|
+
export declare const DEFAULT_PERIODIC_SYNC_TAG = "dink-periodic-sync";
|
|
226
|
+
/**
|
|
227
|
+
* Default minimum interval for periodic sync (1 hour)
|
|
228
|
+
*/
|
|
229
|
+
export declare const DEFAULT_PERIODIC_SYNC_INTERVAL: number;
|
|
230
|
+
//# sourceMappingURL=sync-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-worker.d.ts","sourceRoot":"","sources":["../../src/service-worker/sync-worker.ts"],"names":[],"mappings":"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"}
|