@pol-studios/powersync 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/dist/attachments/index.d.ts +399 -0
- package/dist/attachments/index.js +16 -0
- package/dist/attachments/index.js.map +1 -0
- package/dist/chunk-32OLICZO.js +1 -0
- package/dist/chunk-32OLICZO.js.map +1 -0
- package/dist/chunk-4FJVBR3X.js +227 -0
- package/dist/chunk-4FJVBR3X.js.map +1 -0
- package/dist/chunk-7BPTGEVG.js +1 -0
- package/dist/chunk-7BPTGEVG.js.map +1 -0
- package/dist/chunk-7JQZBZ5N.js +1 -0
- package/dist/chunk-7JQZBZ5N.js.map +1 -0
- package/dist/chunk-BJ36QDFN.js +290 -0
- package/dist/chunk-BJ36QDFN.js.map +1 -0
- package/dist/chunk-CFCK2LHI.js +1002 -0
- package/dist/chunk-CFCK2LHI.js.map +1 -0
- package/dist/chunk-CHRTN5PF.js +322 -0
- package/dist/chunk-CHRTN5PF.js.map +1 -0
- package/dist/chunk-FLHDT4TS.js +327 -0
- package/dist/chunk-FLHDT4TS.js.map +1 -0
- package/dist/chunk-GBGATW2S.js +749 -0
- package/dist/chunk-GBGATW2S.js.map +1 -0
- package/dist/chunk-NPNBGCRC.js +65 -0
- package/dist/chunk-NPNBGCRC.js.map +1 -0
- package/dist/chunk-Q3LFFMRR.js +925 -0
- package/dist/chunk-Q3LFFMRR.js.map +1 -0
- package/dist/chunk-T225XEML.js +298 -0
- package/dist/chunk-T225XEML.js.map +1 -0
- package/dist/chunk-W7HSR35B.js +1 -0
- package/dist/chunk-W7HSR35B.js.map +1 -0
- package/dist/connector/index.d.ts +5 -0
- package/dist/connector/index.js +14 -0
- package/dist/connector/index.js.map +1 -0
- package/dist/core/index.d.ts +197 -0
- package/dist/core/index.js +96 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index-nae7nzib.d.ts +147 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +14 -0
- package/dist/index.native.js +195 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.web.d.ts +14 -0
- package/dist/index.web.js +195 -0
- package/dist/index.web.js.map +1 -0
- package/dist/platform/index.d.ts +280 -0
- package/dist/platform/index.js +14 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/index.native.d.ts +37 -0
- package/dist/platform/index.native.js +7 -0
- package/dist/platform/index.native.js.map +1 -0
- package/dist/platform/index.web.d.ts +37 -0
- package/dist/platform/index.web.js +7 -0
- package/dist/platform/index.web.js.map +1 -0
- package/dist/provider/index.d.ts +873 -0
- package/dist/provider/index.js +63 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/supabase-connector-D14-kl5v.d.ts +232 -0
- package/dist/sync/index.d.ts +421 -0
- package/dist/sync/index.js +14 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/types-Cd7RhNqf.d.ts +224 -0
- package/dist/types-afHtE1U_.d.ts +391 -0
- package/package.json +101 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AttachmentQueueContext,
|
|
3
|
+
ConnectionHealthContext,
|
|
4
|
+
PowerSyncContext,
|
|
5
|
+
PowerSyncProvider,
|
|
6
|
+
SyncMetricsContext,
|
|
7
|
+
SyncStatusContext,
|
|
8
|
+
useAttachmentQueue,
|
|
9
|
+
useConnectionHealth,
|
|
10
|
+
useDatabase,
|
|
11
|
+
useDownloadProgress,
|
|
12
|
+
useEntitySyncStatus,
|
|
13
|
+
useIsSyncing,
|
|
14
|
+
useOnlineStatus,
|
|
15
|
+
usePendingMutations,
|
|
16
|
+
usePlatform,
|
|
17
|
+
usePowerSync,
|
|
18
|
+
useSyncActivity,
|
|
19
|
+
useSyncControl,
|
|
20
|
+
useSyncMetrics,
|
|
21
|
+
useSyncMode,
|
|
22
|
+
useSyncStatus,
|
|
23
|
+
useUploadStatus
|
|
24
|
+
} from "../chunk-Q3LFFMRR.js";
|
|
25
|
+
import "../chunk-GBGATW2S.js";
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_CONNECTION_HEALTH,
|
|
28
|
+
DEFAULT_SYNC_CONFIG,
|
|
29
|
+
DEFAULT_SYNC_METRICS,
|
|
30
|
+
DEFAULT_SYNC_STATUS
|
|
31
|
+
} from "../chunk-CFCK2LHI.js";
|
|
32
|
+
import "../chunk-NPNBGCRC.js";
|
|
33
|
+
import "../chunk-FLHDT4TS.js";
|
|
34
|
+
import "../chunk-CHRTN5PF.js";
|
|
35
|
+
export {
|
|
36
|
+
AttachmentQueueContext,
|
|
37
|
+
ConnectionHealthContext,
|
|
38
|
+
DEFAULT_CONNECTION_HEALTH,
|
|
39
|
+
DEFAULT_SYNC_CONFIG,
|
|
40
|
+
DEFAULT_SYNC_METRICS,
|
|
41
|
+
DEFAULT_SYNC_STATUS,
|
|
42
|
+
PowerSyncContext,
|
|
43
|
+
PowerSyncProvider,
|
|
44
|
+
SyncMetricsContext,
|
|
45
|
+
SyncStatusContext,
|
|
46
|
+
useAttachmentQueue,
|
|
47
|
+
useConnectionHealth,
|
|
48
|
+
useDatabase,
|
|
49
|
+
useDownloadProgress,
|
|
50
|
+
useEntitySyncStatus,
|
|
51
|
+
useIsSyncing,
|
|
52
|
+
useOnlineStatus,
|
|
53
|
+
usePendingMutations,
|
|
54
|
+
usePlatform,
|
|
55
|
+
usePowerSync,
|
|
56
|
+
useSyncActivity,
|
|
57
|
+
useSyncControl,
|
|
58
|
+
useSyncMetrics,
|
|
59
|
+
useSyncMode,
|
|
60
|
+
useSyncStatus,
|
|
61
|
+
useUploadStatus
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { C as CrudEntry, i as ClassifiedError, P as PowerSyncBackendConnector, A as AbstractPowerSyncDatabase } from './types-afHtE1U_.js';
|
|
2
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
3
|
+
import { LoggerAdapter } from './platform/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Connector Types for @pol-studios/powersync
|
|
7
|
+
*
|
|
8
|
+
* Defines interfaces for PowerSync backend connectors.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a SupabaseConnector
|
|
13
|
+
*/
|
|
14
|
+
interface SupabaseConnectorOptions {
|
|
15
|
+
/** Supabase client instance */
|
|
16
|
+
supabaseClient: SupabaseClient;
|
|
17
|
+
/** PowerSync service URL */
|
|
18
|
+
powerSyncUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional: Custom schema routing function.
|
|
21
|
+
* Determines which Supabase schema a table belongs to.
|
|
22
|
+
* @default Returns 'public' for all tables
|
|
23
|
+
*/
|
|
24
|
+
schemaRouter?: SchemaRouter;
|
|
25
|
+
/**
|
|
26
|
+
* Optional: Custom CRUD handler for complex mutations.
|
|
27
|
+
* Allows overriding default upsert/update/delete behavior.
|
|
28
|
+
*/
|
|
29
|
+
crudHandler?: CrudHandler;
|
|
30
|
+
/** Logger for debugging */
|
|
31
|
+
logger?: LoggerAdapter;
|
|
32
|
+
/** Called when a transaction is successfully uploaded */
|
|
33
|
+
onTransactionSuccess?: (entries: CrudEntry[]) => void;
|
|
34
|
+
/** Called when a transaction fails to upload */
|
|
35
|
+
onTransactionFailure?: (entries: CrudEntry[], error: Error, classified: ClassifiedError) => void;
|
|
36
|
+
/** Called when a transaction is fully completed (after transaction.complete()) */
|
|
37
|
+
onTransactionComplete?: (entries: CrudEntry[]) => void;
|
|
38
|
+
/** Function to check if upload should proceed. Used for sync mode gating. */
|
|
39
|
+
shouldUpload?: () => boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration passed to PowerSyncProvider for connector setup
|
|
43
|
+
*/
|
|
44
|
+
interface ConnectorConfig {
|
|
45
|
+
/**
|
|
46
|
+
* Custom schema routing function.
|
|
47
|
+
* Determines which Supabase schema a table belongs to.
|
|
48
|
+
* @default Returns 'public' for all tables
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* schemaRouter: (table) => {
|
|
53
|
+
* if (['Profile', 'Comment'].includes(table)) return 'core';
|
|
54
|
+
* return 'public';
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
schemaRouter?: SchemaRouter;
|
|
59
|
+
/**
|
|
60
|
+
* Custom CRUD handler for complex mutations.
|
|
61
|
+
* @default Uses standard upsert/update/delete operations
|
|
62
|
+
*/
|
|
63
|
+
crudHandler?: CrudHandler;
|
|
64
|
+
/**
|
|
65
|
+
* Token refresh configuration.
|
|
66
|
+
*/
|
|
67
|
+
tokenRefresh?: {
|
|
68
|
+
/** Refresh token when it expires within this many seconds (default: 60) */
|
|
69
|
+
refreshThresholdSeconds?: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Function that determines which Supabase schema a table belongs to.
|
|
74
|
+
*
|
|
75
|
+
* @param tableName - The name of the table
|
|
76
|
+
* @returns The schema name (e.g., 'public', 'core')
|
|
77
|
+
*/
|
|
78
|
+
type SchemaRouter = (tableName: string) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Default schema router that returns 'public' for all tables
|
|
81
|
+
*/
|
|
82
|
+
declare const defaultSchemaRouter: SchemaRouter;
|
|
83
|
+
/**
|
|
84
|
+
* Custom handler for CRUD operations.
|
|
85
|
+
*
|
|
86
|
+
* Return `true` from a handler to indicate the operation was handled.
|
|
87
|
+
* Return `false` to fall back to default behavior.
|
|
88
|
+
*/
|
|
89
|
+
interface CrudHandler {
|
|
90
|
+
/**
|
|
91
|
+
* Handle a PUT operation (insert or replace).
|
|
92
|
+
* @param entry - The CRUD entry
|
|
93
|
+
* @param supabase - Supabase client
|
|
94
|
+
* @param schema - The resolved schema for this table
|
|
95
|
+
* @returns true if handled, false to use default behavior
|
|
96
|
+
*/
|
|
97
|
+
handlePut?(entry: CrudEntry, supabase: SupabaseClient, schema: string): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Handle a PATCH operation (update).
|
|
100
|
+
* @param entry - The CRUD entry
|
|
101
|
+
* @param supabase - Supabase client
|
|
102
|
+
* @param schema - The resolved schema for this table
|
|
103
|
+
* @returns true if handled, false to use default behavior
|
|
104
|
+
*/
|
|
105
|
+
handlePatch?(entry: CrudEntry, supabase: SupabaseClient, schema: string): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Handle a DELETE operation.
|
|
108
|
+
* @param entry - The CRUD entry
|
|
109
|
+
* @param supabase - Supabase client
|
|
110
|
+
* @param schema - The resolved schema for this table
|
|
111
|
+
* @returns true if handled, false to use default behavior
|
|
112
|
+
*/
|
|
113
|
+
handleDelete?(entry: CrudEntry, supabase: SupabaseClient, schema: string): Promise<boolean>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Credentials returned by fetchCredentials
|
|
117
|
+
*/
|
|
118
|
+
interface PowerSyncCredentials {
|
|
119
|
+
/** PowerSync service endpoint URL */
|
|
120
|
+
endpoint: string;
|
|
121
|
+
/** JWT token for authentication */
|
|
122
|
+
token: string;
|
|
123
|
+
/** When the token expires */
|
|
124
|
+
expiresAt?: Date;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Supabase Connector for PowerSync
|
|
129
|
+
*
|
|
130
|
+
* A generic, configurable connector that handles:
|
|
131
|
+
* - Authentication with Supabase JWT tokens
|
|
132
|
+
* - Uploading local changes back to Supabase
|
|
133
|
+
* - Schema routing for multi-schema databases
|
|
134
|
+
* - Custom CRUD handling for complex operations
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generic Supabase connector for PowerSync.
|
|
139
|
+
*
|
|
140
|
+
* This connector handles authentication and CRUD uploads to Supabase.
|
|
141
|
+
* It supports configurable schema routing and custom CRUD handlers
|
|
142
|
+
* for complex use cases.
|
|
143
|
+
*
|
|
144
|
+
* @example Basic usage
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const connector = new SupabaseConnector({
|
|
147
|
+
* supabaseClient: supabase,
|
|
148
|
+
* powerSyncUrl: 'https://your-powersync-instance.com',
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @example With schema routing
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const connector = new SupabaseConnector({
|
|
155
|
+
* supabaseClient: supabase,
|
|
156
|
+
* powerSyncUrl: 'https://your-powersync-instance.com',
|
|
157
|
+
* schemaRouter: (table) => {
|
|
158
|
+
* if (['Profile', 'Comment', 'CommentSection'].includes(table)) {
|
|
159
|
+
* return 'core';
|
|
160
|
+
* }
|
|
161
|
+
* return 'public';
|
|
162
|
+
* },
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example With custom CRUD handler
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const connector = new SupabaseConnector({
|
|
169
|
+
* supabaseClient: supabase,
|
|
170
|
+
* powerSyncUrl: 'https://your-powersync-instance.com',
|
|
171
|
+
* crudHandler: {
|
|
172
|
+
* async handlePut(entry, supabase, schema) {
|
|
173
|
+
* // Custom handling for specific tables
|
|
174
|
+
* if (entry.table === 'SpecialTable') {
|
|
175
|
+
* await myCustomUpsert(entry);
|
|
176
|
+
* return true; // Handled
|
|
177
|
+
* }
|
|
178
|
+
* return false; // Use default
|
|
179
|
+
* },
|
|
180
|
+
* },
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
declare class SupabaseConnector implements PowerSyncBackendConnector {
|
|
185
|
+
private readonly supabase;
|
|
186
|
+
private readonly powerSyncUrl;
|
|
187
|
+
private readonly schemaRouter;
|
|
188
|
+
private readonly crudHandler?;
|
|
189
|
+
private readonly logger?;
|
|
190
|
+
private readonly onTransactionSuccess?;
|
|
191
|
+
private readonly onTransactionFailure?;
|
|
192
|
+
private readonly onTransactionComplete?;
|
|
193
|
+
private readonly shouldUploadFn?;
|
|
194
|
+
private activeProjectIds;
|
|
195
|
+
constructor(options: SupabaseConnectorOptions);
|
|
196
|
+
/**
|
|
197
|
+
* Set the active project IDs for scoped sync.
|
|
198
|
+
* Call this when user selects/opens projects.
|
|
199
|
+
*/
|
|
200
|
+
setActiveProjectIds(projectIds: string[]): void;
|
|
201
|
+
/**
|
|
202
|
+
* Get the current active project IDs.
|
|
203
|
+
*/
|
|
204
|
+
getActiveProjectIds(): string[];
|
|
205
|
+
/**
|
|
206
|
+
* Get credentials for PowerSync connection.
|
|
207
|
+
* Uses Supabase session token.
|
|
208
|
+
*
|
|
209
|
+
* Note: Token refresh is handled by Supabase's startAutoRefresh() which must be
|
|
210
|
+
* called on app initialization. getSession() returns the auto-refreshed token.
|
|
211
|
+
*/
|
|
212
|
+
fetchCredentials(): Promise<PowerSyncCredentials>;
|
|
213
|
+
/**
|
|
214
|
+
* Upload local changes to Supabase.
|
|
215
|
+
* Called automatically by PowerSync when there are pending uploads.
|
|
216
|
+
*/
|
|
217
|
+
uploadData(database: AbstractPowerSyncDatabase): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Process a single CRUD operation.
|
|
220
|
+
*
|
|
221
|
+
* UUID-native tables (public schema, post-migration) use `id` as the UUID column.
|
|
222
|
+
* Core schema tables (Profile, Comment, CommentSection) still use a separate `uuid` column.
|
|
223
|
+
*/
|
|
224
|
+
/**
|
|
225
|
+
* Process a single CRUD operation.
|
|
226
|
+
*
|
|
227
|
+
* All synced tables use `id` as their UUID primary key column.
|
|
228
|
+
*/
|
|
229
|
+
private processCrudEntry;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { type ConnectorConfig as C, type PowerSyncCredentials as P, SupabaseConnector as S, type SupabaseConnectorOptions as a, type SchemaRouter as b, type CrudHandler as c, defaultSchemaRouter as d };
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { b as SyncStatusTrackerOptions, P as PowerSyncRawStatus, U as Unsubscribe, M as MetricsCollectorOptions, d as SyncOperationData, H as HealthMonitorOptions, e as HealthCheckResult } from '../types-Cd7RhNqf.js';
|
|
2
|
+
export { c as SyncControlActions, f as SyncEvent, g as SyncEventListener, S as SyncScope, a as SyncStatusState } from '../types-Cd7RhNqf.js';
|
|
3
|
+
import { a as SyncStatus, S as SyncMode, C as CrudEntry, f as SyncError, F as FailedTransaction, h as CompletedTransaction, e as SyncMetrics, A as AbstractPowerSyncDatabase, b as ConnectionHealth } from '../types-afHtE1U_.js';
|
|
4
|
+
import { AsyncStorageAdapter, LoggerAdapter } from '../platform/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sync Status Tracker for @pol-studios/powersync
|
|
8
|
+
*
|
|
9
|
+
* Tracks and normalizes PowerSync status changes, providing a consistent
|
|
10
|
+
* interface for status updates with throttling support.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tracks sync status from PowerSync and provides normalized updates.
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* - Normalizes raw PowerSync status to a consistent format
|
|
18
|
+
* - Throttles notifications to prevent UI thrashing
|
|
19
|
+
* - Tracks pending mutations count
|
|
20
|
+
* - Persists and restores paused state
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const tracker = new SyncStatusTracker({
|
|
25
|
+
* storage,
|
|
26
|
+
* logger,
|
|
27
|
+
* onStatusChange: (status) => console.log('Status:', status),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Register with PowerSync
|
|
31
|
+
* db.registerListener({
|
|
32
|
+
* statusChanged: (rawStatus) => tracker.handleStatusChange(rawStatus),
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Get current status
|
|
36
|
+
* const status = tracker.getStatus();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare class SyncStatusTracker {
|
|
40
|
+
private readonly storage;
|
|
41
|
+
private readonly logger;
|
|
42
|
+
private readonly notifyThrottleMs;
|
|
43
|
+
private readonly onStatusChange?;
|
|
44
|
+
private _state;
|
|
45
|
+
private _pendingMutations;
|
|
46
|
+
private _lastNotifyTime;
|
|
47
|
+
private _notifyTimer;
|
|
48
|
+
private _listeners;
|
|
49
|
+
private _syncModeListeners;
|
|
50
|
+
private _forceNextUpload;
|
|
51
|
+
private _lastProgress;
|
|
52
|
+
private _failedTransactions;
|
|
53
|
+
private readonly _maxStoredFailures;
|
|
54
|
+
private readonly _failureTTLMs;
|
|
55
|
+
private _failureListeners;
|
|
56
|
+
private _completedTransactions;
|
|
57
|
+
private readonly _maxCompletedHistory;
|
|
58
|
+
private _completedListeners;
|
|
59
|
+
constructor(storage: AsyncStorageAdapter, logger: LoggerAdapter, options?: SyncStatusTrackerOptions);
|
|
60
|
+
/**
|
|
61
|
+
* Initialize the tracker by loading persisted state.
|
|
62
|
+
* Includes migration from old isPaused boolean to new syncMode.
|
|
63
|
+
*/
|
|
64
|
+
init(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Dispose the tracker and clear timers.
|
|
67
|
+
*/
|
|
68
|
+
dispose(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current sync status.
|
|
71
|
+
*/
|
|
72
|
+
getStatus(): SyncStatus;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current sync mode.
|
|
75
|
+
*/
|
|
76
|
+
getSyncMode(): SyncMode;
|
|
77
|
+
/**
|
|
78
|
+
* Get whether sync is paused (offline mode).
|
|
79
|
+
* @deprecated Use getSyncMode() instead
|
|
80
|
+
*/
|
|
81
|
+
isPaused(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Check if uploads are allowed based on current sync mode.
|
|
84
|
+
*/
|
|
85
|
+
canUpload(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if downloads are allowed based on current sync mode.
|
|
88
|
+
*/
|
|
89
|
+
canDownload(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Set the force next upload flag for "Sync Now" functionality.
|
|
92
|
+
*/
|
|
93
|
+
setForceNextUpload(force: boolean): void;
|
|
94
|
+
/**
|
|
95
|
+
* Clear the force next upload flag.
|
|
96
|
+
* Should be called after all pending uploads have been processed.
|
|
97
|
+
*/
|
|
98
|
+
clearForceNextUpload(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Check if upload should proceed, considering force flag.
|
|
101
|
+
* NOTE: Does NOT auto-reset the flag - caller must use clearForceNextUpload()
|
|
102
|
+
* after all uploads are complete. This prevents race conditions when
|
|
103
|
+
* PowerSync calls uploadData() multiple times for multiple transactions.
|
|
104
|
+
*/
|
|
105
|
+
shouldUpload(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Get pending mutations.
|
|
108
|
+
*/
|
|
109
|
+
getPendingMutations(): CrudEntry[];
|
|
110
|
+
/**
|
|
111
|
+
* Get pending mutation count.
|
|
112
|
+
*/
|
|
113
|
+
getPendingCount(): number;
|
|
114
|
+
/**
|
|
115
|
+
* Handle a raw status update from PowerSync.
|
|
116
|
+
*/
|
|
117
|
+
handleStatusChange(rawStatus: PowerSyncRawStatus): void;
|
|
118
|
+
/**
|
|
119
|
+
* Update pending mutations from a CRUD transaction.
|
|
120
|
+
*/
|
|
121
|
+
updatePendingMutations(mutations: CrudEntry[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Valid sync modes for runtime validation.
|
|
124
|
+
*/
|
|
125
|
+
private static readonly VALID_SYNC_MODES;
|
|
126
|
+
/**
|
|
127
|
+
* Set the sync mode.
|
|
128
|
+
*/
|
|
129
|
+
setSyncMode(mode: SyncMode): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Set paused state.
|
|
132
|
+
* @deprecated Use setSyncMode() instead
|
|
133
|
+
*/
|
|
134
|
+
setPaused(paused: boolean): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Subscribe to status changes.
|
|
137
|
+
* @returns Unsubscribe function
|
|
138
|
+
*/
|
|
139
|
+
onStatusUpdate(listener: (status: SyncStatus) => void): Unsubscribe;
|
|
140
|
+
/**
|
|
141
|
+
* Subscribe to sync mode changes.
|
|
142
|
+
* @returns Unsubscribe function
|
|
143
|
+
*/
|
|
144
|
+
onSyncModeChange(listener: (mode: SyncMode) => void): Unsubscribe;
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to paused state changes.
|
|
147
|
+
* @deprecated Use onSyncModeChange() instead
|
|
148
|
+
* @returns Unsubscribe function
|
|
149
|
+
*/
|
|
150
|
+
onPausedChange(listener: (isPaused: boolean) => void): Unsubscribe;
|
|
151
|
+
/**
|
|
152
|
+
* Record a transaction failure.
|
|
153
|
+
* If a failure for the same entries already exists, updates the retry count.
|
|
154
|
+
* Otherwise, creates a new failure record.
|
|
155
|
+
*/
|
|
156
|
+
recordTransactionFailure(entries: CrudEntry[], error: SyncError, isPermanent: boolean, affectedEntityIds: string[], affectedTables: string[]): void;
|
|
157
|
+
/**
|
|
158
|
+
* Clear a specific failure by ID.
|
|
159
|
+
*/
|
|
160
|
+
clearFailure(failureId: string): void;
|
|
161
|
+
/**
|
|
162
|
+
* Clear all failures.
|
|
163
|
+
*/
|
|
164
|
+
clearAllFailures(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Get failures affecting a specific entity.
|
|
167
|
+
*/
|
|
168
|
+
getFailuresForEntity(entityId: string): FailedTransaction[];
|
|
169
|
+
/**
|
|
170
|
+
* Get all failed transactions.
|
|
171
|
+
*/
|
|
172
|
+
getFailedTransactions(): FailedTransaction[];
|
|
173
|
+
/**
|
|
174
|
+
* Check if there are any upload errors.
|
|
175
|
+
*/
|
|
176
|
+
hasUploadErrors(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Get count of permanent errors.
|
|
179
|
+
*/
|
|
180
|
+
getPermanentErrorCount(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Subscribe to failure changes.
|
|
183
|
+
* @returns Unsubscribe function
|
|
184
|
+
*/
|
|
185
|
+
onFailureChange(listener: (failures: FailedTransaction[]) => void): Unsubscribe;
|
|
186
|
+
/**
|
|
187
|
+
* Clean up stale failures (older than TTL).
|
|
188
|
+
*/
|
|
189
|
+
cleanupStaleFailures(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Record a successfully completed transaction.
|
|
192
|
+
* Creates a CompletedTransaction record and adds it to history.
|
|
193
|
+
*/
|
|
194
|
+
recordTransactionComplete(entries: CrudEntry[]): void;
|
|
195
|
+
/**
|
|
196
|
+
* Get all completed transactions.
|
|
197
|
+
*/
|
|
198
|
+
getCompletedTransactions(): CompletedTransaction[];
|
|
199
|
+
/**
|
|
200
|
+
* Clear completed transaction history.
|
|
201
|
+
*/
|
|
202
|
+
clearCompletedHistory(): void;
|
|
203
|
+
/**
|
|
204
|
+
* Subscribe to completed transaction changes.
|
|
205
|
+
* @returns Unsubscribe function
|
|
206
|
+
*/
|
|
207
|
+
onCompletedChange(listener: (completed: CompletedTransaction[]) => void): Unsubscribe;
|
|
208
|
+
private _hasStatusChanged;
|
|
209
|
+
private _notifyListeners;
|
|
210
|
+
private _notifyFailureListeners;
|
|
211
|
+
private _notifyCompletedListeners;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Sync Metrics Collector for @pol-studios/powersync
|
|
216
|
+
*
|
|
217
|
+
* Collects and persists sync operation metrics for monitoring and debugging.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Collects sync metrics including operation counts, timing, and errors.
|
|
222
|
+
*
|
|
223
|
+
* Features:
|
|
224
|
+
* - Tracks sync operation success/failure rates
|
|
225
|
+
* - Calculates average sync duration
|
|
226
|
+
* - Monitors data transfer amounts
|
|
227
|
+
* - Persists metrics to storage for continuity across sessions
|
|
228
|
+
* - Records last error for debugging
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const collector = new MetricsCollector({
|
|
233
|
+
* storage,
|
|
234
|
+
* logger,
|
|
235
|
+
* onMetricsChange: (metrics) => updateUI(metrics),
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* // Start tracking a sync
|
|
239
|
+
* const startTime = Date.now();
|
|
240
|
+
*
|
|
241
|
+
* // On sync complete
|
|
242
|
+
* collector.recordSync({
|
|
243
|
+
* durationMs: Date.now() - startTime,
|
|
244
|
+
* success: true,
|
|
245
|
+
* operationsDownloaded: 150,
|
|
246
|
+
* });
|
|
247
|
+
*
|
|
248
|
+
* // Get current metrics
|
|
249
|
+
* const metrics = collector.getMetrics();
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare class MetricsCollector {
|
|
253
|
+
private readonly storage;
|
|
254
|
+
private readonly logger;
|
|
255
|
+
private readonly storageKey;
|
|
256
|
+
private readonly persistMetrics;
|
|
257
|
+
private readonly onMetricsChange?;
|
|
258
|
+
private _metrics;
|
|
259
|
+
private _listeners;
|
|
260
|
+
private _initialized;
|
|
261
|
+
private _syncStartTime;
|
|
262
|
+
private _wasSyncing;
|
|
263
|
+
constructor(storage: AsyncStorageAdapter, logger: LoggerAdapter, options?: MetricsCollectorOptions);
|
|
264
|
+
/**
|
|
265
|
+
* Initialize the collector by loading persisted metrics.
|
|
266
|
+
*/
|
|
267
|
+
init(): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Dispose the collector.
|
|
270
|
+
*/
|
|
271
|
+
dispose(): void;
|
|
272
|
+
/**
|
|
273
|
+
* Get current sync metrics.
|
|
274
|
+
*/
|
|
275
|
+
getMetrics(): SyncMetrics;
|
|
276
|
+
/**
|
|
277
|
+
* Record a completed sync operation.
|
|
278
|
+
*/
|
|
279
|
+
recordSync(data: SyncOperationData): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Record a sync error without a full sync operation.
|
|
282
|
+
*/
|
|
283
|
+
recordError(error: Error): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Record an upload operation.
|
|
286
|
+
*/
|
|
287
|
+
recordUpload(operationCount: number): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Clear all metrics and start fresh.
|
|
290
|
+
*/
|
|
291
|
+
reset(): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Called when sync starts (downloading becomes true).
|
|
294
|
+
*/
|
|
295
|
+
markSyncStart(): void;
|
|
296
|
+
/**
|
|
297
|
+
* Called when sync ends (downloading becomes false).
|
|
298
|
+
* Returns the duration if a sync was in progress.
|
|
299
|
+
*/
|
|
300
|
+
markSyncEnd(): number | null;
|
|
301
|
+
/**
|
|
302
|
+
* Check if sync is currently in progress.
|
|
303
|
+
*/
|
|
304
|
+
isSyncInProgress(): boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Subscribe to metrics changes.
|
|
307
|
+
* @returns Unsubscribe function
|
|
308
|
+
*/
|
|
309
|
+
onMetricsUpdate(listener: (metrics: SyncMetrics) => void): Unsubscribe;
|
|
310
|
+
private _persist;
|
|
311
|
+
private _notifyListeners;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Connection Health Monitor for @pol-studios/powersync
|
|
316
|
+
*
|
|
317
|
+
* Monitors database connection health with periodic checks and latency tracking.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Monitors connection health with periodic checks.
|
|
322
|
+
*
|
|
323
|
+
* Features:
|
|
324
|
+
* - Periodic health checks with configurable interval
|
|
325
|
+
* - Latency measurement and degraded state detection
|
|
326
|
+
* - Consecutive failure tracking
|
|
327
|
+
* - Auto-recovery detection
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const monitor = new HealthMonitor(db, logger, {
|
|
332
|
+
* checkIntervalMs: 30000,
|
|
333
|
+
* onHealthChange: (health) => {
|
|
334
|
+
* if (health.status === 'degraded') {
|
|
335
|
+
* showWarning('Connection is slow');
|
|
336
|
+
* }
|
|
337
|
+
* },
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* // Start monitoring
|
|
341
|
+
* monitor.start();
|
|
342
|
+
*
|
|
343
|
+
* // Get current health
|
|
344
|
+
* const health = monitor.getHealth();
|
|
345
|
+
*
|
|
346
|
+
* // Stop when done
|
|
347
|
+
* monitor.stop();
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
declare class HealthMonitor {
|
|
351
|
+
private readonly logger;
|
|
352
|
+
private readonly checkIntervalMs;
|
|
353
|
+
private readonly checkTimeoutMs;
|
|
354
|
+
private readonly degradedThresholdMs;
|
|
355
|
+
private readonly maxConsecutiveFailures;
|
|
356
|
+
private readonly onHealthChange?;
|
|
357
|
+
private _db;
|
|
358
|
+
private _health;
|
|
359
|
+
private _intervalId;
|
|
360
|
+
private _listeners;
|
|
361
|
+
private _running;
|
|
362
|
+
private _paused;
|
|
363
|
+
constructor(logger: LoggerAdapter, options?: HealthMonitorOptions);
|
|
364
|
+
/**
|
|
365
|
+
* Set the database instance to monitor.
|
|
366
|
+
*/
|
|
367
|
+
setDatabase(db: AbstractPowerSyncDatabase | null): void;
|
|
368
|
+
/**
|
|
369
|
+
* Start the health monitor.
|
|
370
|
+
*/
|
|
371
|
+
start(): void;
|
|
372
|
+
/**
|
|
373
|
+
* Stop the health monitor.
|
|
374
|
+
*/
|
|
375
|
+
stop(): void;
|
|
376
|
+
/**
|
|
377
|
+
* Pause health checks temporarily.
|
|
378
|
+
*/
|
|
379
|
+
pause(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Resume health checks.
|
|
382
|
+
*/
|
|
383
|
+
resume(): void;
|
|
384
|
+
/**
|
|
385
|
+
* Dispose the monitor and clear all resources.
|
|
386
|
+
*/
|
|
387
|
+
dispose(): void;
|
|
388
|
+
/**
|
|
389
|
+
* Get current connection health.
|
|
390
|
+
*/
|
|
391
|
+
getHealth(): ConnectionHealth;
|
|
392
|
+
/**
|
|
393
|
+
* Check if the monitor is running.
|
|
394
|
+
*/
|
|
395
|
+
isRunning(): boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Perform an immediate health check.
|
|
398
|
+
* @returns The result of the health check
|
|
399
|
+
*/
|
|
400
|
+
checkNow(): Promise<HealthCheckResult>;
|
|
401
|
+
/**
|
|
402
|
+
* Record a reconnection attempt.
|
|
403
|
+
*/
|
|
404
|
+
recordReconnectAttempt(): void;
|
|
405
|
+
/**
|
|
406
|
+
* Reset reconnection attempts counter (call on successful connection).
|
|
407
|
+
*/
|
|
408
|
+
resetReconnectAttempts(): void;
|
|
409
|
+
/**
|
|
410
|
+
* Subscribe to health changes.
|
|
411
|
+
* @returns Unsubscribe function
|
|
412
|
+
*/
|
|
413
|
+
onHealthUpdate(listener: (health: ConnectionHealth) => void): Unsubscribe;
|
|
414
|
+
private _checkHealth;
|
|
415
|
+
private _updateHealth;
|
|
416
|
+
private _hasHealthChanged;
|
|
417
|
+
private _notifyListeners;
|
|
418
|
+
private _withTimeout;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export { HealthCheckResult, HealthMonitor, HealthMonitorOptions, MetricsCollector, MetricsCollectorOptions, PowerSyncRawStatus, SyncOperationData, SyncStatusTracker, SyncStatusTrackerOptions, Unsubscribe };
|