@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,14 @@
|
|
|
1
|
+
import "../chunk-7JQZBZ5N.js";
|
|
2
|
+
import {
|
|
3
|
+
HealthMonitor,
|
|
4
|
+
MetricsCollector,
|
|
5
|
+
SyncStatusTracker
|
|
6
|
+
} from "../chunk-CFCK2LHI.js";
|
|
7
|
+
import "../chunk-NPNBGCRC.js";
|
|
8
|
+
import "../chunk-CHRTN5PF.js";
|
|
9
|
+
export {
|
|
10
|
+
HealthMonitor,
|
|
11
|
+
MetricsCollector,
|
|
12
|
+
SyncStatusTracker
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { a as SyncStatus, S as SyncMode, e as SyncMetrics, b as ConnectionHealth, f as SyncError } from './types-afHtE1U_.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sync Module Types for @pol-studios/powersync
|
|
5
|
+
*
|
|
6
|
+
* Defines interfaces for sync status tracking, metrics collection,
|
|
7
|
+
* and health monitoring.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines a scope for selective sync.
|
|
12
|
+
* Used to limit which data is synced based on project or user context.
|
|
13
|
+
*/
|
|
14
|
+
interface SyncScope {
|
|
15
|
+
/**
|
|
16
|
+
* Scope type identifier.
|
|
17
|
+
* @example "project", "user", "organization"
|
|
18
|
+
*/
|
|
19
|
+
type: string;
|
|
20
|
+
/**
|
|
21
|
+
* IDs to include in the scope.
|
|
22
|
+
* @example ["project-uuid-1", "project-uuid-2"]
|
|
23
|
+
*/
|
|
24
|
+
ids: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Optional metadata for the scope.
|
|
27
|
+
*/
|
|
28
|
+
metadata?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal state for the status tracker.
|
|
32
|
+
*/
|
|
33
|
+
interface SyncStatusState {
|
|
34
|
+
/** Current sync status */
|
|
35
|
+
status: SyncStatus;
|
|
36
|
+
/** Current sync mode */
|
|
37
|
+
syncMode: SyncMode;
|
|
38
|
+
/** Timestamp when status was last updated */
|
|
39
|
+
lastUpdated: Date;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for creating a SyncStatusTracker.
|
|
43
|
+
*/
|
|
44
|
+
interface SyncStatusTrackerOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Throttle notifications to avoid excessive updates.
|
|
47
|
+
* @default 500 (ms)
|
|
48
|
+
*/
|
|
49
|
+
notifyThrottleMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Called when status changes.
|
|
52
|
+
*/
|
|
53
|
+
onStatusChange?: (status: SyncStatus) => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Raw status from PowerSync database.
|
|
57
|
+
*/
|
|
58
|
+
interface PowerSyncRawStatus {
|
|
59
|
+
connected?: boolean;
|
|
60
|
+
connecting?: boolean;
|
|
61
|
+
hasSynced?: boolean;
|
|
62
|
+
lastSyncedAt?: Date | null;
|
|
63
|
+
dataFlowStatus?: {
|
|
64
|
+
uploading?: boolean;
|
|
65
|
+
downloading?: boolean;
|
|
66
|
+
};
|
|
67
|
+
downloadProgress?: {
|
|
68
|
+
downloadedFraction?: number;
|
|
69
|
+
downloadedOperations?: number;
|
|
70
|
+
totalOperations?: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Actions available for sync control.
|
|
75
|
+
*/
|
|
76
|
+
interface SyncControlActions {
|
|
77
|
+
/**
|
|
78
|
+
* Trigger a sync operation.
|
|
79
|
+
* Forces a fresh sync by disconnecting and reconnecting.
|
|
80
|
+
*/
|
|
81
|
+
triggerSync: () => Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Sync Now - forces a full sync including uploads regardless of sync mode.
|
|
84
|
+
* Sets forceNextUpload flag and reconnects.
|
|
85
|
+
*/
|
|
86
|
+
syncNow: () => Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Pause sync operations.
|
|
89
|
+
* Sets sync mode to 'offline' and disconnects.
|
|
90
|
+
*/
|
|
91
|
+
pause: () => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Resume sync operations.
|
|
94
|
+
* Sets sync mode to 'push-pull' and reconnects.
|
|
95
|
+
*/
|
|
96
|
+
resume: () => Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Set the sync mode.
|
|
99
|
+
* @param mode - The sync mode to set ('push-pull', 'pull-only', or 'offline')
|
|
100
|
+
*/
|
|
101
|
+
setSyncMode: (mode: SyncMode) => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Disconnect from the PowerSync service.
|
|
104
|
+
*/
|
|
105
|
+
disconnect: () => Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Set the sync scope for selective sync.
|
|
108
|
+
* @param scope - The scope to apply
|
|
109
|
+
*/
|
|
110
|
+
setScope: (scope: SyncScope | null) => void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Options for creating a MetricsCollector.
|
|
114
|
+
*/
|
|
115
|
+
interface MetricsCollectorOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Storage key for persisting metrics.
|
|
118
|
+
* @default "@pol-studios/powersync-metrics"
|
|
119
|
+
*/
|
|
120
|
+
storageKey?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to persist metrics to storage.
|
|
123
|
+
* @default true
|
|
124
|
+
*/
|
|
125
|
+
persistMetrics?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Called when metrics change.
|
|
128
|
+
*/
|
|
129
|
+
onMetricsChange?: (metrics: SyncMetrics) => void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Data to record for a sync operation.
|
|
133
|
+
*/
|
|
134
|
+
interface SyncOperationData {
|
|
135
|
+
/** Duration of the sync in milliseconds */
|
|
136
|
+
durationMs: number;
|
|
137
|
+
/** Whether the sync was successful */
|
|
138
|
+
success: boolean;
|
|
139
|
+
/** Number of operations downloaded (optional) */
|
|
140
|
+
operationsDownloaded?: number;
|
|
141
|
+
/** Number of operations uploaded (optional) */
|
|
142
|
+
operationsUploaded?: number;
|
|
143
|
+
/** Error that occurred, if any */
|
|
144
|
+
error?: Error;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Options for creating a HealthMonitor.
|
|
148
|
+
*/
|
|
149
|
+
interface HealthMonitorOptions {
|
|
150
|
+
/**
|
|
151
|
+
* Interval between health checks in milliseconds.
|
|
152
|
+
* @default 30000 (30 seconds)
|
|
153
|
+
*/
|
|
154
|
+
checkIntervalMs?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Timeout for health check queries in milliseconds.
|
|
157
|
+
* @default 5000 (5 seconds)
|
|
158
|
+
*/
|
|
159
|
+
checkTimeoutMs?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Latency threshold above which connection is considered degraded.
|
|
162
|
+
* @default 1000 (1 second)
|
|
163
|
+
*/
|
|
164
|
+
degradedThresholdMs?: number;
|
|
165
|
+
/**
|
|
166
|
+
* Number of consecutive failures before marking as disconnected.
|
|
167
|
+
* @default 2
|
|
168
|
+
*/
|
|
169
|
+
maxConsecutiveFailures?: number;
|
|
170
|
+
/**
|
|
171
|
+
* Called when health status changes.
|
|
172
|
+
*/
|
|
173
|
+
onHealthChange?: (health: ConnectionHealth) => void;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Result of a health check.
|
|
177
|
+
*/
|
|
178
|
+
interface HealthCheckResult {
|
|
179
|
+
/** Whether the check succeeded */
|
|
180
|
+
success: boolean;
|
|
181
|
+
/** Latency in milliseconds (if successful) */
|
|
182
|
+
latencyMs?: number;
|
|
183
|
+
/** Error that occurred (if failed) */
|
|
184
|
+
error?: Error;
|
|
185
|
+
/** Timestamp of the check */
|
|
186
|
+
timestamp: Date;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Events emitted by sync components.
|
|
190
|
+
*/
|
|
191
|
+
type SyncEvent = {
|
|
192
|
+
type: 'status_changed';
|
|
193
|
+
status: SyncStatus;
|
|
194
|
+
} | {
|
|
195
|
+
type: 'health_changed';
|
|
196
|
+
health: ConnectionHealth;
|
|
197
|
+
} | {
|
|
198
|
+
type: 'metrics_updated';
|
|
199
|
+
metrics: SyncMetrics;
|
|
200
|
+
} | {
|
|
201
|
+
type: 'sync_started';
|
|
202
|
+
} | {
|
|
203
|
+
type: 'sync_completed';
|
|
204
|
+
durationMs: number;
|
|
205
|
+
} | {
|
|
206
|
+
type: 'sync_failed';
|
|
207
|
+
error: SyncError;
|
|
208
|
+
} | {
|
|
209
|
+
type: 'paused';
|
|
210
|
+
} | {
|
|
211
|
+
type: 'resumed';
|
|
212
|
+
} | {
|
|
213
|
+
type: 'disconnected';
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Listener for sync events.
|
|
217
|
+
*/
|
|
218
|
+
type SyncEventListener = (event: SyncEvent) => void;
|
|
219
|
+
/**
|
|
220
|
+
* Function to unsubscribe from a listener.
|
|
221
|
+
*/
|
|
222
|
+
type Unsubscribe = () => void;
|
|
223
|
+
|
|
224
|
+
export type { HealthMonitorOptions as H, MetricsCollectorOptions as M, PowerSyncRawStatus as P, SyncScope as S, Unsubscribe as U, SyncStatusState as a, SyncStatusTrackerOptions as b, SyncControlActions as c, SyncOperationData as d, HealthCheckResult as e, SyncEvent as f, SyncEventListener as g };
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for @pol-studios/powersync
|
|
3
|
+
*
|
|
4
|
+
* This module contains all the shared TypeScript interfaces for sync status,
|
|
5
|
+
* connection health, storage information, metrics, and cache statistics.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Unified sync state for a specific entity.
|
|
9
|
+
* Used by useEntitySyncStatus hook to provide a simple status for UI rendering.
|
|
10
|
+
*
|
|
11
|
+
* State transitions:
|
|
12
|
+
* - 'idle' → No pending operations, no errors
|
|
13
|
+
* - 'saving' → Local changes detected but not yet syncing (reserved for future local-only tracking)
|
|
14
|
+
* - 'syncing' → Changes are being uploaded to the server
|
|
15
|
+
* - 'synced' → Recently synced successfully (within last few seconds)
|
|
16
|
+
* - 'error' → Permanent failure that needs user attention
|
|
17
|
+
*/
|
|
18
|
+
type EntitySyncState = 'idle' | 'saving' | 'syncing' | 'synced' | 'error';
|
|
19
|
+
/**
|
|
20
|
+
* Sync mode controlling data flow behavior.
|
|
21
|
+
* - 'push-pull': Normal bidirectional sync (upload and download)
|
|
22
|
+
* - 'pull-only': Download updates but don't upload local changes
|
|
23
|
+
* - 'offline': No sync at all (fully disconnected)
|
|
24
|
+
*/
|
|
25
|
+
type SyncMode = 'push-pull' | 'pull-only' | 'offline';
|
|
26
|
+
/**
|
|
27
|
+
* CrudEntry represents a pending CRUD operation in the sync queue
|
|
28
|
+
*/
|
|
29
|
+
interface CrudEntry {
|
|
30
|
+
/** Unique identifier for the record (typically UUID) */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Client-side ID for tracking */
|
|
33
|
+
clientId: number;
|
|
34
|
+
/** The type of operation */
|
|
35
|
+
op: "PUT" | "PATCH" | "DELETE";
|
|
36
|
+
/** The table name */
|
|
37
|
+
table: string;
|
|
38
|
+
/** The data being modified (for PUT/PATCH operations) */
|
|
39
|
+
opData?: Record<string, unknown>;
|
|
40
|
+
/** Transaction ID for grouping operations */
|
|
41
|
+
transactionId?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Download progress information during sync
|
|
45
|
+
*/
|
|
46
|
+
interface DownloadProgress {
|
|
47
|
+
/** Number of operations downloaded so far */
|
|
48
|
+
current: number;
|
|
49
|
+
/** Total number of operations to download */
|
|
50
|
+
target: number;
|
|
51
|
+
/** Percentage complete (0-100) */
|
|
52
|
+
percentage: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Current sync status from PowerSync
|
|
56
|
+
*/
|
|
57
|
+
interface SyncStatus {
|
|
58
|
+
/** Whether connected to the PowerSync service */
|
|
59
|
+
connected: boolean;
|
|
60
|
+
/** Whether currently attempting to connect */
|
|
61
|
+
connecting: boolean;
|
|
62
|
+
/** Whether initial sync has completed */
|
|
63
|
+
hasSynced: boolean;
|
|
64
|
+
/** Timestamp of last successful sync */
|
|
65
|
+
lastSyncedAt: Date | null;
|
|
66
|
+
/** Whether currently uploading local changes */
|
|
67
|
+
uploading: boolean;
|
|
68
|
+
/** Whether currently downloading remote changes */
|
|
69
|
+
downloading: boolean;
|
|
70
|
+
/** Download progress details */
|
|
71
|
+
downloadProgress: DownloadProgress | null;
|
|
72
|
+
/** Failed transactions that need attention */
|
|
73
|
+
failedTransactions: FailedTransaction[];
|
|
74
|
+
/** Whether there are any upload errors */
|
|
75
|
+
hasUploadErrors: boolean;
|
|
76
|
+
/** Count of permanent errors that need user action */
|
|
77
|
+
permanentErrorCount: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Connection health status for monitoring database connectivity
|
|
81
|
+
*/
|
|
82
|
+
interface ConnectionHealth {
|
|
83
|
+
/** Current connection status */
|
|
84
|
+
status: "healthy" | "degraded" | "disconnected";
|
|
85
|
+
/** Last measured query latency in milliseconds */
|
|
86
|
+
latency: number | null;
|
|
87
|
+
/** Timestamp of the last health check */
|
|
88
|
+
lastHealthCheck: Date | null;
|
|
89
|
+
/** Number of consecutive health check failures */
|
|
90
|
+
consecutiveFailures: number;
|
|
91
|
+
/** Total reconnection attempts since last successful connection */
|
|
92
|
+
reconnectAttempts: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Storage information with detailed breakdown
|
|
96
|
+
*/
|
|
97
|
+
interface StorageInfo {
|
|
98
|
+
/** Actual data bytes (excluding free pages) */
|
|
99
|
+
used: number;
|
|
100
|
+
/** Formatted used storage string (e.g., "1.5 GB") */
|
|
101
|
+
usedFormatted: string;
|
|
102
|
+
/** Total file size on disk */
|
|
103
|
+
total: number;
|
|
104
|
+
/** Formatted total storage string */
|
|
105
|
+
totalFormatted: string;
|
|
106
|
+
/** Free pages that can be reclaimed via VACUUM */
|
|
107
|
+
reclaimable: number;
|
|
108
|
+
/** Formatted reclaimable storage string */
|
|
109
|
+
reclaimableFormatted: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Device storage quota information
|
|
113
|
+
*/
|
|
114
|
+
interface StorageQuota {
|
|
115
|
+
/** Free space available on device in bytes */
|
|
116
|
+
deviceFreeSpace: number;
|
|
117
|
+
/** Current database file size in bytes */
|
|
118
|
+
databaseSize: number;
|
|
119
|
+
/** Warning threshold in bytes */
|
|
120
|
+
warningThreshold: number;
|
|
121
|
+
/** Critical threshold in bytes */
|
|
122
|
+
criticalThreshold: number;
|
|
123
|
+
/** Current storage status based on free space vs thresholds */
|
|
124
|
+
status: "ok" | "warning" | "critical";
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sync operation metrics for monitoring and debugging
|
|
128
|
+
*/
|
|
129
|
+
interface SyncMetrics {
|
|
130
|
+
/** Total number of sync operations attempted */
|
|
131
|
+
totalSyncs: number;
|
|
132
|
+
/** Number of successful sync operations */
|
|
133
|
+
successfulSyncs: number;
|
|
134
|
+
/** Number of failed sync operations */
|
|
135
|
+
failedSyncs: number;
|
|
136
|
+
/** Duration of the last sync in milliseconds */
|
|
137
|
+
lastSyncDuration: number | null;
|
|
138
|
+
/** Average sync duration in milliseconds */
|
|
139
|
+
averageSyncDuration: number | null;
|
|
140
|
+
/** Total bytes downloaded across all syncs */
|
|
141
|
+
totalDataDownloaded: number;
|
|
142
|
+
/** Total bytes uploaded across all syncs */
|
|
143
|
+
totalDataUploaded: number;
|
|
144
|
+
/** Last sync error details */
|
|
145
|
+
lastError: SyncError | null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Details about a sync error
|
|
149
|
+
*/
|
|
150
|
+
interface SyncError {
|
|
151
|
+
/** Error type classification */
|
|
152
|
+
type: SyncErrorType;
|
|
153
|
+
/** Error message (original/technical) */
|
|
154
|
+
message: string;
|
|
155
|
+
/** User-friendly error message for display */
|
|
156
|
+
userMessage: string;
|
|
157
|
+
/** When the error occurred */
|
|
158
|
+
timestamp: Date;
|
|
159
|
+
/** PostgreSQL error code if available */
|
|
160
|
+
pgCode?: string;
|
|
161
|
+
/** Whether this is a permanent failure (requires user action) */
|
|
162
|
+
isPermanent: boolean;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Categorized error types for sync operations
|
|
166
|
+
*/
|
|
167
|
+
type SyncErrorType = "network" | "auth" | "server" | "conflict" | "validation" | "quota" | "unknown";
|
|
168
|
+
/**
|
|
169
|
+
* Represents a successfully completed CRUD transaction.
|
|
170
|
+
* Used to track recent sync activity for UI feedback.
|
|
171
|
+
*/
|
|
172
|
+
interface CompletedTransaction {
|
|
173
|
+
/** Unique identifier for this completion record */
|
|
174
|
+
id: string;
|
|
175
|
+
/** All CRUD entries that were successfully synced */
|
|
176
|
+
entries: CrudEntry[];
|
|
177
|
+
/** When the transaction was completed */
|
|
178
|
+
completedAt: Date;
|
|
179
|
+
/** Table names involved in this transaction */
|
|
180
|
+
affectedTables: string[];
|
|
181
|
+
/** Entity IDs affected by this transaction */
|
|
182
|
+
affectedEntityIds: string[];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Represents a failed CRUD transaction that needs attention.
|
|
186
|
+
*
|
|
187
|
+
* PowerSync uses atomic transactions - when any operation fails,
|
|
188
|
+
* the entire transaction fails and will be retried. We track failures
|
|
189
|
+
* at the transaction level to avoid data integrity issues.
|
|
190
|
+
*/
|
|
191
|
+
interface FailedTransaction {
|
|
192
|
+
/** Unique ID for this failure record */
|
|
193
|
+
id: string;
|
|
194
|
+
/** All CRUD entries in the failed transaction */
|
|
195
|
+
entries: CrudEntry[];
|
|
196
|
+
/** The error that caused the failure */
|
|
197
|
+
error: SyncError;
|
|
198
|
+
/** Number of times PowerSync has retried this transaction */
|
|
199
|
+
retryCount: number;
|
|
200
|
+
/** When the failure first occurred */
|
|
201
|
+
firstFailedAt: Date;
|
|
202
|
+
/** When the last retry failed */
|
|
203
|
+
lastFailedAt: Date;
|
|
204
|
+
/** Whether this is a permanent failure that needs user action */
|
|
205
|
+
isPermanent: boolean;
|
|
206
|
+
/** Entity IDs affected (for UI filtering by entity) */
|
|
207
|
+
affectedEntityIds: string[];
|
|
208
|
+
/** Table names involved in this transaction */
|
|
209
|
+
affectedTables: string[];
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Result of classifying a Supabase/PostgreSQL error
|
|
213
|
+
*/
|
|
214
|
+
interface ClassifiedError {
|
|
215
|
+
/** The error type category */
|
|
216
|
+
type: SyncErrorType;
|
|
217
|
+
/** Whether this error is permanent (won't be fixed by retrying) */
|
|
218
|
+
isPermanent: boolean;
|
|
219
|
+
/** Whether this is a conflict with existing data */
|
|
220
|
+
isConflict: boolean;
|
|
221
|
+
/** PostgreSQL error code if available */
|
|
222
|
+
pgCode?: string;
|
|
223
|
+
/** User-friendly error message */
|
|
224
|
+
userMessage: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Result of database compaction (VACUUM) operation
|
|
228
|
+
*/
|
|
229
|
+
interface CompactResult {
|
|
230
|
+
/** Whether the compaction was successful */
|
|
231
|
+
success: boolean;
|
|
232
|
+
/** Number of bytes reclaimed */
|
|
233
|
+
bytesReclaimed: number;
|
|
234
|
+
/** Error message if compaction failed */
|
|
235
|
+
error?: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Result of database integrity check
|
|
239
|
+
*/
|
|
240
|
+
interface IntegrityResult {
|
|
241
|
+
/** Whether the database is healthy */
|
|
242
|
+
isHealthy: boolean;
|
|
243
|
+
/** List of issues found (empty if healthy) */
|
|
244
|
+
issues: string[];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Statistics for a single cached table
|
|
248
|
+
*/
|
|
249
|
+
interface TableCacheStats {
|
|
250
|
+
/** User-friendly table name */
|
|
251
|
+
name: string;
|
|
252
|
+
/** Internal PowerSync table name (e.g., "ps_data__TableName") */
|
|
253
|
+
internalName: string;
|
|
254
|
+
/** Number of rows in the table */
|
|
255
|
+
rowCount: number;
|
|
256
|
+
/** Storage size in bytes for this table */
|
|
257
|
+
storageBytes: number;
|
|
258
|
+
/** Formatted storage size string */
|
|
259
|
+
storageFormatted: string;
|
|
260
|
+
/** Whether this is an internal PowerSync table */
|
|
261
|
+
isInternal: boolean;
|
|
262
|
+
/** Whether this is a local-only table (not synced) */
|
|
263
|
+
isLocalOnly: boolean;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Complete cache statistics for the PowerSync database
|
|
267
|
+
*/
|
|
268
|
+
interface CacheStats {
|
|
269
|
+
/** Statistics for each table */
|
|
270
|
+
tables: TableCacheStats[];
|
|
271
|
+
/** Total number of user tables (excluding internal) */
|
|
272
|
+
totalTables: number;
|
|
273
|
+
/** Total number of rows across all user tables */
|
|
274
|
+
totalRows: number;
|
|
275
|
+
/** Detailed storage information */
|
|
276
|
+
storage: StorageInfo;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Abstract interface for PowerSync database operations.
|
|
280
|
+
* This allows the package to work with different PowerSync implementations
|
|
281
|
+
* (react-native, web) without direct dependencies.
|
|
282
|
+
*/
|
|
283
|
+
interface AbstractPowerSyncDatabase {
|
|
284
|
+
/** Execute a query and return all results */
|
|
285
|
+
getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
286
|
+
/** Execute a query and return first result or null */
|
|
287
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
288
|
+
/** Execute a SQL statement (INSERT, UPDATE, DELETE) */
|
|
289
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
290
|
+
rowsAffected: number;
|
|
291
|
+
}>;
|
|
292
|
+
/** Whether the database is currently connected */
|
|
293
|
+
connected: boolean;
|
|
294
|
+
/** Current sync status */
|
|
295
|
+
currentStatus: {
|
|
296
|
+
connected: boolean;
|
|
297
|
+
connecting: boolean;
|
|
298
|
+
hasSynced: boolean;
|
|
299
|
+
lastSyncedAt: Date | null;
|
|
300
|
+
dataFlowStatus?: {
|
|
301
|
+
uploading: boolean;
|
|
302
|
+
downloading: boolean;
|
|
303
|
+
};
|
|
304
|
+
downloadProgress?: {
|
|
305
|
+
downloadedFraction: number;
|
|
306
|
+
downloadedOperations: number;
|
|
307
|
+
totalOperations: number;
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
/** Initialize the database */
|
|
311
|
+
init(): Promise<void>;
|
|
312
|
+
/** Close the database connection */
|
|
313
|
+
close(): Promise<void>;
|
|
314
|
+
/** Connect to the PowerSync service */
|
|
315
|
+
connect(connector: PowerSyncBackendConnector): Promise<void>;
|
|
316
|
+
/** Disconnect from the PowerSync service */
|
|
317
|
+
disconnect(): Promise<void>;
|
|
318
|
+
/** Register a listener for status changes */
|
|
319
|
+
registerListener(listener: {
|
|
320
|
+
statusChanged?: (status: unknown) => void;
|
|
321
|
+
}): () => void;
|
|
322
|
+
/** Get the next pending CRUD transaction */
|
|
323
|
+
getNextCrudTransaction(): Promise<CrudTransaction | null>;
|
|
324
|
+
/** Watch a query for changes with callback-based API */
|
|
325
|
+
watch(sql: string, params: unknown[], callbacks: {
|
|
326
|
+
onResult: (results: {
|
|
327
|
+
rows?: {
|
|
328
|
+
_array?: unknown[];
|
|
329
|
+
};
|
|
330
|
+
}) => void;
|
|
331
|
+
onError?: (error: Error) => void;
|
|
332
|
+
}, options?: {
|
|
333
|
+
signal?: AbortSignal;
|
|
334
|
+
tables?: string[];
|
|
335
|
+
throttleMs?: number;
|
|
336
|
+
}): void;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* A transaction containing pending CRUD operations
|
|
340
|
+
*/
|
|
341
|
+
interface CrudTransaction {
|
|
342
|
+
/** The CRUD operations in this transaction */
|
|
343
|
+
crud: CrudEntry[];
|
|
344
|
+
/** Mark the transaction as complete */
|
|
345
|
+
complete(): Promise<void>;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Backend connector interface for PowerSync
|
|
349
|
+
*/
|
|
350
|
+
interface PowerSyncBackendConnector {
|
|
351
|
+
/** Fetch credentials for authentication */
|
|
352
|
+
fetchCredentials(): Promise<{
|
|
353
|
+
endpoint: string;
|
|
354
|
+
token: string;
|
|
355
|
+
expiresAt?: Date;
|
|
356
|
+
}>;
|
|
357
|
+
/** Upload local changes to the backend */
|
|
358
|
+
uploadData(database: AbstractPowerSyncDatabase): Promise<void>;
|
|
359
|
+
}
|
|
360
|
+
/** Row returned by: SELECT name FROM sqlite_master */
|
|
361
|
+
interface SqliteTableRow {
|
|
362
|
+
name: string;
|
|
363
|
+
}
|
|
364
|
+
/** Row returned by: SELECT name, SUM(pgsize) as size FROM dbstat GROUP BY name */
|
|
365
|
+
interface DbStatRow {
|
|
366
|
+
name: string;
|
|
367
|
+
size: number;
|
|
368
|
+
}
|
|
369
|
+
/** Row returned by: SELECT COUNT(*) as c FROM ... */
|
|
370
|
+
interface CountRow {
|
|
371
|
+
c: number;
|
|
372
|
+
}
|
|
373
|
+
/** Row returned by: PRAGMA page_size */
|
|
374
|
+
interface PageSizeRow {
|
|
375
|
+
page_size: number;
|
|
376
|
+
}
|
|
377
|
+
/** Row returned by: PRAGMA page_count */
|
|
378
|
+
interface PageCountRow {
|
|
379
|
+
page_count: number;
|
|
380
|
+
}
|
|
381
|
+
/** Row returned by: PRAGMA freelist_count */
|
|
382
|
+
interface FreelistCountRow {
|
|
383
|
+
freelist_count: number;
|
|
384
|
+
}
|
|
385
|
+
/** Row returned by: PRAGMA integrity_check */
|
|
386
|
+
interface IntegrityCheckRow {
|
|
387
|
+
integrity_check: string;
|
|
388
|
+
[key: string]: unknown;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export type { AbstractPowerSyncDatabase as A, CrudEntry as C, DownloadProgress as D, EntitySyncState as E, FailedTransaction as F, IntegrityResult as I, PowerSyncBackendConnector as P, SyncMode as S, TableCacheStats as T, SyncStatus as a, ConnectionHealth as b, StorageInfo as c, StorageQuota as d, SyncMetrics as e, SyncError as f, SyncErrorType as g, CompletedTransaction as h, ClassifiedError as i, CompactResult as j, CacheStats as k, CrudTransaction as l, SqliteTableRow as m, DbStatRow as n, CountRow as o, PageSizeRow as p, PageCountRow as q, FreelistCountRow as r, IntegrityCheckRow as s };
|