@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,540 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for SyncedOfflineEdge.
|
|
3
|
+
*
|
|
4
|
+
* SyncedOfflineEdge is a high-level API that combines offline-first persistence
|
|
5
|
+
* with configurable sync modes and lifecycle hooks.
|
|
6
|
+
*
|
|
7
|
+
* @module synced-offline-edge-types
|
|
8
|
+
*/
|
|
9
|
+
import type { PersistenceProvider } from '../persistence/types.js';
|
|
10
|
+
import type { OfflineEdgeConfig, OfflineEdgeClient, SyncError, SyncedDocument, SyncMetadata, SyncRejectedEvent, Signal, Unsubscribe, InsertOptions, UpdateOptions, QueryOptions } from './types.js';
|
|
11
|
+
import type { ConnectionState, SyncEngine } from './sync-engine.js';
|
|
12
|
+
/**
|
|
13
|
+
* Sync mode for a collection.
|
|
14
|
+
*
|
|
15
|
+
* - 'auto': Changes are synced automatically in the background (default)
|
|
16
|
+
* - 'manual': Changes are queued but only synced when explicitly triggered
|
|
17
|
+
* - 'disabled': No syncing - local changes stay local
|
|
18
|
+
*/
|
|
19
|
+
export type SyncMode = 'auto' | 'manual' | 'disabled';
|
|
20
|
+
/**
|
|
21
|
+
* Map of collection names to their sync modes.
|
|
22
|
+
* Used for per-collection sync configuration.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const syncConfig: SyncConfigMap = {
|
|
27
|
+
* tasks: 'auto', // Sync automatically
|
|
28
|
+
* drafts: 'manual', // Only sync when triggered
|
|
29
|
+
* localCache: 'disabled', // Never sync
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type SyncConfigMap = Record<string, SyncMode>;
|
|
34
|
+
/**
|
|
35
|
+
* Context provided to the onBeforeSync hook.
|
|
36
|
+
* Contains information about the pending sync operation.
|
|
37
|
+
*/
|
|
38
|
+
export interface BeforeSyncContext {
|
|
39
|
+
/** The collection being synced */
|
|
40
|
+
readonly collection: string;
|
|
41
|
+
/** The document ID being synced */
|
|
42
|
+
readonly documentId: string;
|
|
43
|
+
/** The binary changes (Yjs update) about to be sent */
|
|
44
|
+
readonly changes: Uint8Array;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Context provided to the onAfterSync hook.
|
|
48
|
+
* Contains information about the completed sync operation.
|
|
49
|
+
*/
|
|
50
|
+
export interface AfterSyncContext {
|
|
51
|
+
/** The collection that was synced */
|
|
52
|
+
readonly collection: string;
|
|
53
|
+
/** The document ID that was synced */
|
|
54
|
+
readonly documentId: string;
|
|
55
|
+
/** Whether the sync was successful */
|
|
56
|
+
readonly success: boolean;
|
|
57
|
+
/** Timestamp when the sync completed */
|
|
58
|
+
readonly timestamp: number;
|
|
59
|
+
/** Error if the sync failed (only present when success is false) */
|
|
60
|
+
readonly error?: Error;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Context provided to the onSyncError hook.
|
|
64
|
+
* Contains information about the sync error and retry state.
|
|
65
|
+
*/
|
|
66
|
+
export interface SyncErrorContext {
|
|
67
|
+
/** The collection where the error occurred */
|
|
68
|
+
readonly collection: string;
|
|
69
|
+
/** The document ID where the error occurred */
|
|
70
|
+
readonly documentId: string;
|
|
71
|
+
/** The error that occurred */
|
|
72
|
+
readonly error: Error;
|
|
73
|
+
/** The current retry count (0 for first attempt) */
|
|
74
|
+
readonly retryCount: number;
|
|
75
|
+
/** Whether the sync will be retried */
|
|
76
|
+
readonly willRetry: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Context provided to the onSyncRejected hook.
|
|
80
|
+
* Contains information about the server rejection.
|
|
81
|
+
*/
|
|
82
|
+
export interface SyncRejectedContext {
|
|
83
|
+
/** The collection where the rejection occurred */
|
|
84
|
+
readonly collection: string;
|
|
85
|
+
/** The document ID where the rejection occurred */
|
|
86
|
+
readonly documentId: string;
|
|
87
|
+
/** The rejection error from the server */
|
|
88
|
+
readonly error: {
|
|
89
|
+
readonly code: string;
|
|
90
|
+
readonly message: string;
|
|
91
|
+
readonly field?: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Lifecycle hooks for sync operations.
|
|
96
|
+
* All hooks are optional and can be used to customize sync behavior.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const hooks: SyncLifecycleHooks = {
|
|
101
|
+
* onBeforeSync: async (context) => {
|
|
102
|
+
* // Log or modify sync behavior
|
|
103
|
+
* console.log(`Syncing ${context.documentId}`);
|
|
104
|
+
* return true; // Return false to skip this sync
|
|
105
|
+
* },
|
|
106
|
+
* onAfterSync: (context) => {
|
|
107
|
+
* if (context.success) {
|
|
108
|
+
* console.log(`Synced ${context.documentId}`);
|
|
109
|
+
* }
|
|
110
|
+
* },
|
|
111
|
+
* onSyncError: (collection, documentId, error) => {
|
|
112
|
+
* console.error(`Sync error: ${error.message}`);
|
|
113
|
+
* },
|
|
114
|
+
* onSyncRejected: (collection, documentId, error) => {
|
|
115
|
+
* // Handle server-side rejection (e.g., validation error)
|
|
116
|
+
* alert(`Server rejected: ${error.message}`);
|
|
117
|
+
* },
|
|
118
|
+
* };
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export interface SyncLifecycleHooks {
|
|
122
|
+
/**
|
|
123
|
+
* Called before a sync operation starts.
|
|
124
|
+
* Return false to skip the sync, or true/void to proceed.
|
|
125
|
+
* Can be async for performing validation or transformation.
|
|
126
|
+
*
|
|
127
|
+
* @param context - Information about the pending sync
|
|
128
|
+
* @returns Whether to proceed with the sync (default: true)
|
|
129
|
+
*/
|
|
130
|
+
onBeforeSync?: (context: BeforeSyncContext) => boolean | void | Promise<boolean | void>;
|
|
131
|
+
/**
|
|
132
|
+
* Called after a sync operation completes (success or failure).
|
|
133
|
+
* Useful for updating UI state or logging.
|
|
134
|
+
*
|
|
135
|
+
* @param context - Information about the completed sync
|
|
136
|
+
*/
|
|
137
|
+
onAfterSync?: (context: AfterSyncContext) => void | Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Called when a sync operation fails due to a network or transport error.
|
|
140
|
+
* The error is typically retryable.
|
|
141
|
+
*
|
|
142
|
+
* @param collection - The collection name
|
|
143
|
+
* @param documentId - The document ID
|
|
144
|
+
* @param error - The error that occurred
|
|
145
|
+
*/
|
|
146
|
+
onSyncError?: (collection: string, documentId: string, error: Error) => void | Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Called when the server rejects a sync operation.
|
|
149
|
+
* This typically indicates a validation error, permission issue,
|
|
150
|
+
* or constraint violation that requires user intervention.
|
|
151
|
+
*
|
|
152
|
+
* @param collection - The collection name
|
|
153
|
+
* @param documentId - The document ID
|
|
154
|
+
* @param error - Detailed sync error from the server
|
|
155
|
+
*/
|
|
156
|
+
onSyncRejected?: (collection: string, documentId: string, error: SyncError) => void | Promise<void>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for creating a SyncedOfflineEdge instance.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const config: SyncedOfflineEdgeConfig = {
|
|
164
|
+
* persistence: new IndexedDBPersistence('my-app'),
|
|
165
|
+
* config: {
|
|
166
|
+
* serverUrl: 'nats://localhost:4222',
|
|
167
|
+
* apiKey: 'edge-api-key',
|
|
168
|
+
* },
|
|
169
|
+
* syncConfig: {
|
|
170
|
+
* tasks: 'auto',
|
|
171
|
+
* drafts: 'manual',
|
|
172
|
+
* },
|
|
173
|
+
* hooks: {
|
|
174
|
+
* onAfterSync: (ctx) => console.log('Synced:', ctx.documentId),
|
|
175
|
+
* },
|
|
176
|
+
* };
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export interface SyncedOfflineEdgeConfig {
|
|
180
|
+
/** Persistence provider for local storage (required) */
|
|
181
|
+
readonly persistence: PersistenceProvider;
|
|
182
|
+
/** Connection configuration (required) */
|
|
183
|
+
readonly config: OfflineEdgeConfig;
|
|
184
|
+
/**
|
|
185
|
+
* Per-collection sync mode configuration.
|
|
186
|
+
* Collections not specified default to 'auto' mode.
|
|
187
|
+
*/
|
|
188
|
+
readonly syncConfig?: SyncConfigMap;
|
|
189
|
+
/**
|
|
190
|
+
* Lifecycle hooks for customizing sync behavior.
|
|
191
|
+
*/
|
|
192
|
+
readonly hooks?: SyncLifecycleHooks;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* A synced collection with offline-first capabilities.
|
|
196
|
+
* Provides all standard collection operations plus sync-specific methods.
|
|
197
|
+
*/
|
|
198
|
+
export interface SyncedOfflineCollection<T extends {
|
|
199
|
+
id: string;
|
|
200
|
+
}> {
|
|
201
|
+
/** Collection name */
|
|
202
|
+
readonly name: string;
|
|
203
|
+
/**
|
|
204
|
+
* Insert a new document into the collection.
|
|
205
|
+
* The document is stored locally immediately and queued for sync.
|
|
206
|
+
*/
|
|
207
|
+
insert(data: Omit<T, 'id'>, options?: InsertOptions): Promise<SyncedDocument<T>>;
|
|
208
|
+
/**
|
|
209
|
+
* Update an existing document.
|
|
210
|
+
* Changes are applied locally immediately and queued for sync.
|
|
211
|
+
*/
|
|
212
|
+
update(id: string, data: Partial<Omit<T, 'id'>>, options?: UpdateOptions): Promise<SyncedDocument<T>>;
|
|
213
|
+
/**
|
|
214
|
+
* Delete a document from the collection.
|
|
215
|
+
* The deletion is applied locally immediately and queued for sync.
|
|
216
|
+
*/
|
|
217
|
+
delete(id: string): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Get a document by ID.
|
|
220
|
+
* Returns the local version of the document.
|
|
221
|
+
*/
|
|
222
|
+
get(id: string): Promise<SyncedDocument<T> | null>;
|
|
223
|
+
/**
|
|
224
|
+
* List all documents in the collection.
|
|
225
|
+
* Returns local documents including unsynced changes.
|
|
226
|
+
*/
|
|
227
|
+
list(): Promise<SyncedDocument<T>[]>;
|
|
228
|
+
/**
|
|
229
|
+
* Query documents with filtering, sorting, and pagination.
|
|
230
|
+
*/
|
|
231
|
+
query(options: QueryOptions<T>): Promise<SyncedDocument<T>[]>;
|
|
232
|
+
/**
|
|
233
|
+
* Subscribe to collection changes.
|
|
234
|
+
* Callback is invoked immediately with current documents and on every change.
|
|
235
|
+
*/
|
|
236
|
+
subscribe(callback: (docs: SyncedDocument<T>[]) => void): Unsubscribe;
|
|
237
|
+
/**
|
|
238
|
+
* Subscribe to sync rejection events for this collection.
|
|
239
|
+
*/
|
|
240
|
+
onSyncRejected(callback: (event: SyncRejectedEvent<T>) => void): Unsubscribe;
|
|
241
|
+
/**
|
|
242
|
+
* Get sync status for a specific document.
|
|
243
|
+
*/
|
|
244
|
+
getSyncStatus(id: string): Promise<SyncMetadata | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Retry sync for a specific document.
|
|
247
|
+
* Resets retry counter and triggers immediate sync attempt.
|
|
248
|
+
*/
|
|
249
|
+
retrySync(id: string): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Get the count of documents with pending changes in this collection.
|
|
252
|
+
*/
|
|
253
|
+
getPendingSyncCount(): Promise<number>;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* SyncedOfflineEdge is a high-level API for offline-first applications.
|
|
257
|
+
*
|
|
258
|
+
* It provides:
|
|
259
|
+
* - Automatic local persistence with configurable providers
|
|
260
|
+
* - Configurable sync modes (auto/manual/disabled) per collection
|
|
261
|
+
* - Lifecycle hooks for customizing sync behavior
|
|
262
|
+
* - Manual sync control for fine-grained sync management
|
|
263
|
+
* - Real-time connection state tracking
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* import { createSyncedOfflineEdge } from '@fatagnus/dink-sync';
|
|
268
|
+
*
|
|
269
|
+
* const edge = await createSyncedOfflineEdge({
|
|
270
|
+
* persistence: new IndexedDBPersistence('my-app'),
|
|
271
|
+
* config: {
|
|
272
|
+
* serverUrl: 'nats://localhost:4222',
|
|
273
|
+
* apiKey: 'your-edge-api-key',
|
|
274
|
+
* },
|
|
275
|
+
* syncConfig: {
|
|
276
|
+
* tasks: 'auto',
|
|
277
|
+
* drafts: 'manual',
|
|
278
|
+
* },
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* // Get a collection - works offline!
|
|
282
|
+
* const tasks = edge.collection<Task>('tasks');
|
|
283
|
+
*
|
|
284
|
+
* // Insert works immediately, syncs in background
|
|
285
|
+
* await tasks.insert({ title: 'Buy milk', completed: false });
|
|
286
|
+
*
|
|
287
|
+
* // Manual sync when needed
|
|
288
|
+
* await edge.syncCollection('drafts');
|
|
289
|
+
*
|
|
290
|
+
* // Pause all syncing (e.g., for battery saving)
|
|
291
|
+
* edge.pauseSync();
|
|
292
|
+
*
|
|
293
|
+
* // Cleanup when done
|
|
294
|
+
* await edge.destroy();
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export interface SyncedOfflineEdge {
|
|
298
|
+
/**
|
|
299
|
+
* Get or create a typed collection.
|
|
300
|
+
* The collection provides offline-first CRUD operations.
|
|
301
|
+
*
|
|
302
|
+
* @param name - Collection name
|
|
303
|
+
* @returns A synced collection instance
|
|
304
|
+
*/
|
|
305
|
+
collection<T extends {
|
|
306
|
+
id: string;
|
|
307
|
+
}>(name: string): SyncedOfflineCollection<T>;
|
|
308
|
+
/**
|
|
309
|
+
* Get the underlying OfflineEdgeClient.
|
|
310
|
+
* Provides direct access to the raw client for advanced use cases.
|
|
311
|
+
*
|
|
312
|
+
* @returns The OfflineEdgeClient instance
|
|
313
|
+
*/
|
|
314
|
+
getOfflineClient(): OfflineEdgeClient;
|
|
315
|
+
/**
|
|
316
|
+
* Get the underlying SyncEngine.
|
|
317
|
+
* Provides direct access to the sync engine for advanced use cases.
|
|
318
|
+
*
|
|
319
|
+
* @returns The SyncEngine instance
|
|
320
|
+
*/
|
|
321
|
+
getSyncEngine(): SyncEngine;
|
|
322
|
+
/**
|
|
323
|
+
* Reactive signal tracking the current connection state.
|
|
324
|
+
* Delegates to the SyncEngine's connection state.
|
|
325
|
+
*/
|
|
326
|
+
readonly connectionState: Signal<ConnectionState>;
|
|
327
|
+
/**
|
|
328
|
+
* Get the current connection state.
|
|
329
|
+
*/
|
|
330
|
+
getConnectionState(): ConnectionState;
|
|
331
|
+
/**
|
|
332
|
+
* Check if currently connected to the server.
|
|
333
|
+
* Shorthand for getConnectionState() === 'online'.
|
|
334
|
+
*/
|
|
335
|
+
isConnected(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Subscribe to connection state changes.
|
|
338
|
+
* Callback is invoked immediately with current state and on every change.
|
|
339
|
+
*
|
|
340
|
+
* @param callback - Function called with new connection state
|
|
341
|
+
* @returns Unsubscribe function
|
|
342
|
+
*/
|
|
343
|
+
onConnectionChange(callback: (state: ConnectionState) => void): Unsubscribe;
|
|
344
|
+
/**
|
|
345
|
+
* Get the sync mode for a collection.
|
|
346
|
+
* Returns 'auto' if not explicitly configured.
|
|
347
|
+
*
|
|
348
|
+
* @param collection - Collection name
|
|
349
|
+
* @returns The sync mode for the collection
|
|
350
|
+
*/
|
|
351
|
+
getSyncMode(collection: string): SyncMode;
|
|
352
|
+
/**
|
|
353
|
+
* Set the sync mode for a collection.
|
|
354
|
+
* Changes take effect immediately.
|
|
355
|
+
*
|
|
356
|
+
* @param collection - Collection name
|
|
357
|
+
* @param mode - New sync mode
|
|
358
|
+
*/
|
|
359
|
+
setSyncMode(collection: string, mode: SyncMode): void;
|
|
360
|
+
/**
|
|
361
|
+
* Subscribe to sync mode change events.
|
|
362
|
+
* Called when a collection's sync mode is changed via setSyncMode.
|
|
363
|
+
*
|
|
364
|
+
* @param callback - Function called with collection name and new mode
|
|
365
|
+
* @returns Unsubscribe function
|
|
366
|
+
*/
|
|
367
|
+
onSyncModeChange(callback: (collection: string, mode: SyncMode) => void): Unsubscribe;
|
|
368
|
+
/**
|
|
369
|
+
* Add a callback to be called before sync operations.
|
|
370
|
+
* Callbacks are called in registration order.
|
|
371
|
+
* Return false to cancel the sync, true or void to proceed.
|
|
372
|
+
*
|
|
373
|
+
* @param callback - Function called before sync with context
|
|
374
|
+
*/
|
|
375
|
+
addOnBeforeSync(callback: (context: BeforeSyncContext) => boolean | void | Promise<boolean | void>): void;
|
|
376
|
+
/**
|
|
377
|
+
* Remove a previously added onBeforeSync callback.
|
|
378
|
+
*
|
|
379
|
+
* @param callback - The callback to remove
|
|
380
|
+
*/
|
|
381
|
+
removeOnBeforeSync(callback: (context: BeforeSyncContext) => boolean | void | Promise<boolean | void>): void;
|
|
382
|
+
/**
|
|
383
|
+
* Add a callback to be called after successful sync operations.
|
|
384
|
+
* Callbacks are called in registration order.
|
|
385
|
+
*
|
|
386
|
+
* @param callback - Function called after sync with context
|
|
387
|
+
*/
|
|
388
|
+
addOnAfterSync(callback: (context: AfterSyncContext) => void | Promise<void>): void;
|
|
389
|
+
/**
|
|
390
|
+
* Remove a previously added onAfterSync callback.
|
|
391
|
+
*
|
|
392
|
+
* @param callback - The callback to remove
|
|
393
|
+
*/
|
|
394
|
+
removeOnAfterSync(callback: (context: AfterSyncContext) => void | Promise<void>): void;
|
|
395
|
+
/**
|
|
396
|
+
* Add a callback to be called when sync errors occur.
|
|
397
|
+
* Callbacks are called in registration order.
|
|
398
|
+
*
|
|
399
|
+
* @param callback - Function called on sync error with context
|
|
400
|
+
*/
|
|
401
|
+
addOnSyncError(callback: (context: SyncErrorContext) => void | Promise<void>): void;
|
|
402
|
+
/**
|
|
403
|
+
* Remove a previously added onSyncError callback.
|
|
404
|
+
*
|
|
405
|
+
* @param callback - The callback to remove
|
|
406
|
+
*/
|
|
407
|
+
removeOnSyncError(callback: (context: SyncErrorContext) => void | Promise<void>): void;
|
|
408
|
+
/**
|
|
409
|
+
* Add a callback to be called when sync is rejected by the server.
|
|
410
|
+
* Callbacks are called in registration order.
|
|
411
|
+
*
|
|
412
|
+
* @param callback - Function called on sync rejection with context
|
|
413
|
+
*/
|
|
414
|
+
addOnSyncRejected(callback: (context: SyncRejectedContext) => void | Promise<void>): void;
|
|
415
|
+
/**
|
|
416
|
+
* Remove a previously added onSyncRejected callback.
|
|
417
|
+
*
|
|
418
|
+
* @param callback - The callback to remove
|
|
419
|
+
*/
|
|
420
|
+
removeOnSyncRejected(callback: (context: SyncRejectedContext) => void | Promise<void>): void;
|
|
421
|
+
/**
|
|
422
|
+
* Immediately sync pending changes.
|
|
423
|
+
*
|
|
424
|
+
* @param collection - Optional collection name. If provided, syncs only that collection.
|
|
425
|
+
* If omitted, syncs all collections with pending changes.
|
|
426
|
+
* @returns Promise that resolves when sync completes
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* // Flush all pending changes
|
|
431
|
+
* await edge.flush();
|
|
432
|
+
*
|
|
433
|
+
* // Flush only the 'drafts' collection
|
|
434
|
+
* await edge.flush('drafts');
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
flush(collection?: string): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Trigger immediate sync for all pending changes.
|
|
440
|
+
* Only affects collections in 'auto' or 'manual' mode.
|
|
441
|
+
*
|
|
442
|
+
* @returns Promise that resolves when sync completes
|
|
443
|
+
* @deprecated Use flush() instead
|
|
444
|
+
*/
|
|
445
|
+
syncNow(): Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* Trigger immediate sync for a specific collection.
|
|
448
|
+
*
|
|
449
|
+
* @param collection - Collection name to sync
|
|
450
|
+
* @returns Promise that resolves when sync completes
|
|
451
|
+
* @deprecated Use flush(collection) instead
|
|
452
|
+
*/
|
|
453
|
+
syncCollection(collection: string): Promise<void>;
|
|
454
|
+
/**
|
|
455
|
+
* Trigger immediate sync for a specific document.
|
|
456
|
+
*
|
|
457
|
+
* @param collection - Collection name
|
|
458
|
+
* @param documentId - Document ID to sync
|
|
459
|
+
* @returns Promise that resolves when sync completes
|
|
460
|
+
*/
|
|
461
|
+
syncDocument(collection: string, documentId: string): Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* Pause all automatic sync operations globally.
|
|
464
|
+
* Changes continue to be queued locally but won't be sent to the server.
|
|
465
|
+
* Manual flush() calls still work while paused.
|
|
466
|
+
* Useful for battery saving, batch operations, or user-initiated offline mode.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* edge.pause();
|
|
471
|
+
* // Make many changes without triggering syncs
|
|
472
|
+
* await tasks.insert({ title: 'Task 1' });
|
|
473
|
+
* await tasks.insert({ title: 'Task 2' });
|
|
474
|
+
* // When ready, resume to sync all changes
|
|
475
|
+
* edge.resume();
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
pause(): void;
|
|
479
|
+
/**
|
|
480
|
+
* Resume automatic sync operations after pausing.
|
|
481
|
+
* Triggers immediate flush of pending changes for all auto-mode collections.
|
|
482
|
+
* Manual-mode collections still require explicit flush() calls.
|
|
483
|
+
*/
|
|
484
|
+
resume(): void;
|
|
485
|
+
/**
|
|
486
|
+
* Check if automatic sync is currently paused.
|
|
487
|
+
*
|
|
488
|
+
* @returns true if paused, false otherwise
|
|
489
|
+
*/
|
|
490
|
+
isPaused(): boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Pause all sync operations.
|
|
493
|
+
* Changes continue to be queued locally but won't be sent to the server.
|
|
494
|
+
* Useful for battery saving or user-initiated offline mode.
|
|
495
|
+
* @deprecated Use pause() instead
|
|
496
|
+
*/
|
|
497
|
+
pauseSync(): void;
|
|
498
|
+
/**
|
|
499
|
+
* Resume sync operations after pausing.
|
|
500
|
+
* Triggers immediate sync of any pending changes.
|
|
501
|
+
* @deprecated Use resume() instead
|
|
502
|
+
*/
|
|
503
|
+
resumeSync(): void;
|
|
504
|
+
/**
|
|
505
|
+
* Check if sync is currently paused.
|
|
506
|
+
* @deprecated Use isPaused() instead
|
|
507
|
+
*/
|
|
508
|
+
isSyncPaused(): boolean;
|
|
509
|
+
/**
|
|
510
|
+
* Manually force offline mode.
|
|
511
|
+
* Prevents sync operations even when network is available.
|
|
512
|
+
* Useful for testing offline behavior or saving battery.
|
|
513
|
+
* Delegates to SyncEngine.goOffline().
|
|
514
|
+
*/
|
|
515
|
+
goOffline(): void;
|
|
516
|
+
/**
|
|
517
|
+
* Exit manual offline mode.
|
|
518
|
+
* Flushes any pending changes if transport and network are available.
|
|
519
|
+
* Delegates to SyncEngine.goOnline().
|
|
520
|
+
*/
|
|
521
|
+
goOnline(): void;
|
|
522
|
+
/**
|
|
523
|
+
* Check if there are any pending changes across all collections.
|
|
524
|
+
*/
|
|
525
|
+
hasPendingChanges(): boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Get the count of documents with pending changes.
|
|
528
|
+
*
|
|
529
|
+
* @param collection - Optional collection name to filter by
|
|
530
|
+
* @returns Count of documents with pending changes
|
|
531
|
+
*/
|
|
532
|
+
getPendingCount(collection?: string): Promise<number>;
|
|
533
|
+
/**
|
|
534
|
+
* Destroy the edge client and release all resources.
|
|
535
|
+
* Disconnects from the server and closes persistence.
|
|
536
|
+
* The instance cannot be used after calling destroy.
|
|
537
|
+
*/
|
|
538
|
+
destroy(): Promise<void>;
|
|
539
|
+
}
|
|
540
|
+
//# sourceMappingURL=synced-offline-edge-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synced-offline-edge-types.d.ts","sourceRoot":"","sources":["../../src/client/synced-offline-edge-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,MAAM,EACN,WAAW,EACX,aAAa,EACb,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,mCAAmC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WA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|
|
3
|
+
*
|
|
4
|
+
* SyncedOfflineEdge is a high-level API that combines offline-first persistence
|
|
5
|
+
* with configurable sync modes and lifecycle hooks.
|
|
6
|
+
*
|
|
7
|
+
* @module synced-offline-edge-types
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=synced-offline-edge-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synced-offline-edge-types.js","sourceRoot":"","sources":["../../src/client/synced-offline-edge-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SyncedOfflineEdge - A high-level API for offline-first applications
|
|
3
|
+
* with configurable per-collection sync modes.
|
|
4
|
+
*
|
|
5
|
+
* Combines OfflineEdgeClient with SyncEngine for automatic sync,
|
|
6
|
+
* providing granular per-collection sync control, lifecycle hooks,
|
|
7
|
+
* and manual sync controls.
|
|
8
|
+
*
|
|
9
|
+
* @module synced-offline-edge
|
|
10
|
+
*/
|
|
11
|
+
import type { PersistenceProvider } from '../persistence/types.js';
|
|
12
|
+
import type { OfflineEdgeConfig } from './types.js';
|
|
13
|
+
import type { SyncConfigMap, SyncLifecycleHooks, SyncedOfflineEdge } from './synced-offline-edge-types.js';
|
|
14
|
+
import type { Transport } from './transport.js';
|
|
15
|
+
/**
|
|
16
|
+
* Extended configuration for creating a SyncedOfflineEdge instance.
|
|
17
|
+
* Includes optional transport for testing.
|
|
18
|
+
*/
|
|
19
|
+
export interface CreateSyncedOfflineEdgeOptions {
|
|
20
|
+
/** Persistence provider for local storage (required) */
|
|
21
|
+
persistence: PersistenceProvider;
|
|
22
|
+
/** Connection configuration (required) */
|
|
23
|
+
config: OfflineEdgeConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Per-collection sync mode configuration.
|
|
26
|
+
* Collections not specified default to 'auto' mode.
|
|
27
|
+
*/
|
|
28
|
+
syncConfig?: SyncConfigMap;
|
|
29
|
+
/**
|
|
30
|
+
* Lifecycle hooks for customizing sync behavior.
|
|
31
|
+
*/
|
|
32
|
+
hooks?: SyncLifecycleHooks;
|
|
33
|
+
/**
|
|
34
|
+
* Custom transport for testing (optional).
|
|
35
|
+
* If not provided, a real NATS transport will be created.
|
|
36
|
+
*/
|
|
37
|
+
transport?: Transport;
|
|
38
|
+
/**
|
|
39
|
+
* Debounce time in ms before syncing changes (default: 200).
|
|
40
|
+
*/
|
|
41
|
+
debounceMs?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Max retries for failed sync operations (default: 5).
|
|
44
|
+
*/
|
|
45
|
+
maxRetries?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a SyncedOfflineEdge instance.
|
|
49
|
+
*
|
|
50
|
+
* @param options - Configuration options
|
|
51
|
+
* @returns A promise that resolves to a SyncedOfflineEdge instance
|
|
52
|
+
*/
|
|
53
|
+
export declare function createSyncedOfflineEdge(options: CreateSyncedOfflineEdgeOptions): Promise<SyncedOfflineEdge>;
|
|
54
|
+
//# sourceMappingURL=synced-offline-edge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synced-offline-edge.d.ts","sourceRoot":"","sources":["../../src/client/synced-offline-edge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EASV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAEV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAMlB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,gBAAgB,CAAC;AAK1E;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C,wDAAwD;IACxD,WAAW,EAAE,mBAAmB,CAAC;IAEjC,0CAA0C;IAC1C,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,iBAAiB,CAAC,CAo0B5B"}
|