@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,197 @@
|
|
|
1
|
+
import { g as SyncErrorType, i as ClassifiedError, f as SyncError, C as CrudEntry } from '../types-afHtE1U_.js';
|
|
2
|
+
export { A as AbstractPowerSyncDatabase, k as CacheStats, j as CompactResult, h as CompletedTransaction, b as ConnectionHealth, o as CountRow, l as CrudTransaction, n as DbStatRow, D as DownloadProgress, E as EntitySyncState, F as FailedTransaction, r as FreelistCountRow, s as IntegrityCheckRow, I as IntegrityResult, q as PageCountRow, p as PageSizeRow, P as PowerSyncBackendConnector, m as SqliteTableRow, c as StorageInfo, d as StorageQuota, e as SyncMetrics, S as SyncMode, a as SyncStatus, T as TableCacheStats } from '../types-afHtE1U_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Constants for @pol-studios/powersync
|
|
6
|
+
*
|
|
7
|
+
* This module contains all configurable constants with sensible defaults.
|
|
8
|
+
* These can be overridden via configuration.
|
|
9
|
+
*/
|
|
10
|
+
/** Storage key prefix for all PowerSync-related keys */
|
|
11
|
+
declare const STORAGE_KEY_PREFIX = "@pol-studios/powersync";
|
|
12
|
+
/** Storage key for PowerSync enabled state */
|
|
13
|
+
declare const STORAGE_KEY_ENABLED = "@pol-studios/powersync-enabled";
|
|
14
|
+
/** Storage key for PowerSync paused state */
|
|
15
|
+
declare const STORAGE_KEY_PAUSED = "@pol-studios/powersync-paused";
|
|
16
|
+
/** Storage key for persisted sync metrics */
|
|
17
|
+
declare const STORAGE_KEY_METRICS = "@pol-studios/powersync-metrics";
|
|
18
|
+
/** Storage key for attachment queue settings */
|
|
19
|
+
declare const STORAGE_KEY_ATTACHMENT_SETTINGS = "@pol-studios/powersync-attachment-settings";
|
|
20
|
+
/** Storage key for sync mode */
|
|
21
|
+
declare const STORAGE_KEY_SYNC_MODE = "@pol-studios/powersync-sync-mode";
|
|
22
|
+
/** Default sync mode */
|
|
23
|
+
declare const DEFAULT_SYNC_MODE: "push-pull";
|
|
24
|
+
/** Interval between health checks in milliseconds */
|
|
25
|
+
declare const HEALTH_CHECK_INTERVAL_MS = 30000;
|
|
26
|
+
/** Timeout for individual health check queries */
|
|
27
|
+
declare const HEALTH_CHECK_TIMEOUT_MS = 5000;
|
|
28
|
+
/** Latency threshold above which connection is considered degraded */
|
|
29
|
+
declare const LATENCY_DEGRADED_THRESHOLD_MS = 1000;
|
|
30
|
+
/** Number of consecutive failures before marking as disconnected */
|
|
31
|
+
declare const MAX_CONSECUTIVE_FAILURES = 2;
|
|
32
|
+
/** Warning threshold for device free space (default: 100MB) */
|
|
33
|
+
declare const STORAGE_WARNING_THRESHOLD: number;
|
|
34
|
+
/** Critical threshold for device free space (default: 50MB) */
|
|
35
|
+
declare const STORAGE_CRITICAL_THRESHOLD: number;
|
|
36
|
+
/** Default maximum cache size for attachments */
|
|
37
|
+
declare const DEFAULT_ATTACHMENT_CACHE_SIZE: number;
|
|
38
|
+
/** Default number of concurrent attachment downloads */
|
|
39
|
+
declare const DEFAULT_ATTACHMENT_CONCURRENCY = 50;
|
|
40
|
+
/** Delay between retry passes for attachment downloads */
|
|
41
|
+
declare const ATTACHMENT_RETRY_DELAY_MS = 5000;
|
|
42
|
+
/** Timeout for individual attachment downloads */
|
|
43
|
+
declare const ATTACHMENT_DOWNLOAD_TIMEOUT_MS = 60000;
|
|
44
|
+
/** Default image compression quality (0.0 to 1.0) */
|
|
45
|
+
declare const DEFAULT_COMPRESSION_QUALITY = 0.7;
|
|
46
|
+
/** Maximum image width before resizing */
|
|
47
|
+
declare const COMPRESSION_MAX_WIDTH = 2048;
|
|
48
|
+
/** Skip compression for files smaller than this */
|
|
49
|
+
declare const COMPRESSION_SKIP_SIZE_BYTES = 100000;
|
|
50
|
+
/** Skip compression if already smaller than this */
|
|
51
|
+
declare const COMPRESSION_TARGET_SIZE_BYTES = 300000;
|
|
52
|
+
/** Stop downloads at this percentage of cache limit to leave headroom */
|
|
53
|
+
declare const DOWNLOAD_STOP_THRESHOLD = 0.95;
|
|
54
|
+
/** Trigger eviction at this percentage of cache limit */
|
|
55
|
+
declare const EVICTION_TRIGGER_THRESHOLD = 1;
|
|
56
|
+
/** Default sync interval for periodic sync mode */
|
|
57
|
+
declare const DEFAULT_SYNC_INTERVAL_MS: number;
|
|
58
|
+
/** Debounce time for status notifications */
|
|
59
|
+
declare const STATUS_NOTIFY_THROTTLE_MS = 500;
|
|
60
|
+
/** Cache TTL for stats queries */
|
|
61
|
+
declare const STATS_CACHE_TTL_MS = 500;
|
|
62
|
+
/** Default maximum retry attempts */
|
|
63
|
+
declare const DEFAULT_MAX_RETRY_ATTEMPTS = 3;
|
|
64
|
+
/** Default base delay for retry backoff */
|
|
65
|
+
declare const DEFAULT_RETRY_BASE_DELAY_MS = 1000;
|
|
66
|
+
/** Default maximum delay between retries */
|
|
67
|
+
declare const DEFAULT_RETRY_MAX_DELAY_MS = 30000;
|
|
68
|
+
/** Default backoff multiplier */
|
|
69
|
+
declare const DEFAULT_RETRY_BACKOFF_MULTIPLIER = 2;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Custom Error Classes for @pol-studios/powersync
|
|
73
|
+
*
|
|
74
|
+
* This module provides specialized error classes for different failure scenarios.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Base error class for PowerSync-related errors
|
|
79
|
+
*/
|
|
80
|
+
declare class PowerSyncError extends Error {
|
|
81
|
+
constructor(message: string);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Error thrown when PowerSync initialization fails
|
|
85
|
+
*/
|
|
86
|
+
declare class InitializationError extends PowerSyncError {
|
|
87
|
+
readonly cause?: Error;
|
|
88
|
+
constructor(message: string, cause?: Error);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Error thrown when a sync operation fails
|
|
92
|
+
*/
|
|
93
|
+
declare class SyncOperationError extends PowerSyncError {
|
|
94
|
+
readonly errorType: SyncErrorType;
|
|
95
|
+
readonly cause?: Error;
|
|
96
|
+
constructor(message: string, errorType: SyncErrorType, cause?: Error);
|
|
97
|
+
/**
|
|
98
|
+
* Whether this error can be automatically retried
|
|
99
|
+
*/
|
|
100
|
+
get isRetryable(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Get a user-friendly error message
|
|
103
|
+
*/
|
|
104
|
+
get userFriendlyMessage(): string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Error thrown when a connector operation fails
|
|
108
|
+
*/
|
|
109
|
+
declare class ConnectorError extends PowerSyncError {
|
|
110
|
+
readonly operation: 'fetchCredentials' | 'uploadData';
|
|
111
|
+
readonly cause?: Error;
|
|
112
|
+
constructor(message: string, operation: 'fetchCredentials' | 'uploadData', cause?: Error);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Error thrown when an attachment operation fails
|
|
116
|
+
*/
|
|
117
|
+
declare class AttachmentError extends PowerSyncError {
|
|
118
|
+
readonly attachmentId: string;
|
|
119
|
+
readonly operation: 'download' | 'compress' | 'delete' | 'evict';
|
|
120
|
+
readonly cause?: Error;
|
|
121
|
+
constructor(message: string, attachmentId: string, operation: 'download' | 'compress' | 'delete' | 'evict', cause?: Error);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Error thrown when the platform adapter is missing required functionality
|
|
125
|
+
*/
|
|
126
|
+
declare class PlatformAdapterError extends PowerSyncError {
|
|
127
|
+
readonly missingFeature: string;
|
|
128
|
+
constructor(message: string, missingFeature: string);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Error thrown when configuration is invalid
|
|
132
|
+
*/
|
|
133
|
+
declare class ConfigurationError extends PowerSyncError {
|
|
134
|
+
readonly configKey?: string;
|
|
135
|
+
constructor(message: string, configKey?: string);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Classify an error into a SyncErrorType based on its message
|
|
139
|
+
*
|
|
140
|
+
* @param error - The error to classify
|
|
141
|
+
* @returns The classified error type
|
|
142
|
+
*/
|
|
143
|
+
declare function classifyError(error: Error): SyncErrorType;
|
|
144
|
+
/**
|
|
145
|
+
* Create a SyncOperationError from a regular Error
|
|
146
|
+
*
|
|
147
|
+
* @param error - The original error
|
|
148
|
+
* @param message - Optional custom message
|
|
149
|
+
* @returns A classified SyncOperationError
|
|
150
|
+
*/
|
|
151
|
+
declare function toSyncOperationError(error: Error, message?: string): SyncOperationError;
|
|
152
|
+
/**
|
|
153
|
+
* Classify a Supabase/PostgreSQL error into a structured result.
|
|
154
|
+
*
|
|
155
|
+
* This function analyzes errors from Supabase operations and determines:
|
|
156
|
+
* - The error type category
|
|
157
|
+
* - Whether the error is permanent (won't be fixed by retry)
|
|
158
|
+
* - Whether it's a conflict with existing data
|
|
159
|
+
* - A user-friendly message
|
|
160
|
+
*
|
|
161
|
+
* @param error - The error from a Supabase operation
|
|
162
|
+
* @returns Classified error information
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* try {
|
|
167
|
+
* await supabase.from('users').insert({ email: 'duplicate@test.com' });
|
|
168
|
+
* } catch (error) {
|
|
169
|
+
* const classified = classifySupabaseError(error);
|
|
170
|
+
* if (classified.isPermanent) {
|
|
171
|
+
* // Show error to user - retry won't help
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function classifySupabaseError(error: unknown): ClassifiedError;
|
|
177
|
+
/**
|
|
178
|
+
* Create a SyncError from a classified error result.
|
|
179
|
+
*/
|
|
180
|
+
declare function createSyncError(classified: ClassifiedError, originalMessage: string): SyncError;
|
|
181
|
+
/**
|
|
182
|
+
* Generate a unique ID for a failed transaction.
|
|
183
|
+
* Uses a combination of timestamp and entry IDs to ensure uniqueness.
|
|
184
|
+
*/
|
|
185
|
+
declare function generateFailureId(entries: CrudEntry[]): string;
|
|
186
|
+
/**
|
|
187
|
+
* Extract entity IDs from CRUD entries.
|
|
188
|
+
* Includes both the PowerSync entry ID and the record's 'id' from opData if different.
|
|
189
|
+
* This ensures we can match failures to entities regardless of which ID format is used.
|
|
190
|
+
*/
|
|
191
|
+
declare function extractEntityIds(entries: CrudEntry[]): string[];
|
|
192
|
+
/**
|
|
193
|
+
* Extract unique table names from CRUD entries.
|
|
194
|
+
*/
|
|
195
|
+
declare function extractTableNames(entries: CrudEntry[]): string[];
|
|
196
|
+
|
|
197
|
+
export { ATTACHMENT_DOWNLOAD_TIMEOUT_MS, ATTACHMENT_RETRY_DELAY_MS, AttachmentError, COMPRESSION_MAX_WIDTH, COMPRESSION_SKIP_SIZE_BYTES, COMPRESSION_TARGET_SIZE_BYTES, ClassifiedError, ConfigurationError, ConnectorError, CrudEntry, DEFAULT_ATTACHMENT_CACHE_SIZE, DEFAULT_ATTACHMENT_CONCURRENCY, DEFAULT_COMPRESSION_QUALITY, DEFAULT_MAX_RETRY_ATTEMPTS, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_SYNC_INTERVAL_MS, DEFAULT_SYNC_MODE, DOWNLOAD_STOP_THRESHOLD, EVICTION_TRIGGER_THRESHOLD, HEALTH_CHECK_INTERVAL_MS, HEALTH_CHECK_TIMEOUT_MS, InitializationError, LATENCY_DEGRADED_THRESHOLD_MS, MAX_CONSECUTIVE_FAILURES, PlatformAdapterError, PowerSyncError, STATS_CACHE_TTL_MS, STATUS_NOTIFY_THROTTLE_MS, STORAGE_CRITICAL_THRESHOLD, STORAGE_KEY_ATTACHMENT_SETTINGS, STORAGE_KEY_ENABLED, STORAGE_KEY_METRICS, STORAGE_KEY_PAUSED, STORAGE_KEY_PREFIX, STORAGE_KEY_SYNC_MODE, STORAGE_WARNING_THRESHOLD, SyncError, SyncErrorType, SyncOperationError, classifyError, classifySupabaseError, createSyncError, extractEntityIds, extractTableNames, generateFailureId, toSyncOperationError };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import "../chunk-W7HSR35B.js";
|
|
2
|
+
import {
|
|
3
|
+
ATTACHMENT_DOWNLOAD_TIMEOUT_MS,
|
|
4
|
+
ATTACHMENT_RETRY_DELAY_MS,
|
|
5
|
+
COMPRESSION_MAX_WIDTH,
|
|
6
|
+
COMPRESSION_SKIP_SIZE_BYTES,
|
|
7
|
+
COMPRESSION_TARGET_SIZE_BYTES,
|
|
8
|
+
DEFAULT_ATTACHMENT_CACHE_SIZE,
|
|
9
|
+
DEFAULT_ATTACHMENT_CONCURRENCY,
|
|
10
|
+
DEFAULT_COMPRESSION_QUALITY,
|
|
11
|
+
DEFAULT_MAX_RETRY_ATTEMPTS,
|
|
12
|
+
DEFAULT_RETRY_BACKOFF_MULTIPLIER,
|
|
13
|
+
DEFAULT_RETRY_BASE_DELAY_MS,
|
|
14
|
+
DEFAULT_RETRY_MAX_DELAY_MS,
|
|
15
|
+
DEFAULT_SYNC_INTERVAL_MS,
|
|
16
|
+
DEFAULT_SYNC_MODE,
|
|
17
|
+
DOWNLOAD_STOP_THRESHOLD,
|
|
18
|
+
EVICTION_TRIGGER_THRESHOLD,
|
|
19
|
+
HEALTH_CHECK_INTERVAL_MS,
|
|
20
|
+
HEALTH_CHECK_TIMEOUT_MS,
|
|
21
|
+
LATENCY_DEGRADED_THRESHOLD_MS,
|
|
22
|
+
MAX_CONSECUTIVE_FAILURES,
|
|
23
|
+
STATS_CACHE_TTL_MS,
|
|
24
|
+
STATUS_NOTIFY_THROTTLE_MS,
|
|
25
|
+
STORAGE_CRITICAL_THRESHOLD,
|
|
26
|
+
STORAGE_KEY_ATTACHMENT_SETTINGS,
|
|
27
|
+
STORAGE_KEY_ENABLED,
|
|
28
|
+
STORAGE_KEY_METRICS,
|
|
29
|
+
STORAGE_KEY_PAUSED,
|
|
30
|
+
STORAGE_KEY_PREFIX,
|
|
31
|
+
STORAGE_KEY_SYNC_MODE,
|
|
32
|
+
STORAGE_WARNING_THRESHOLD
|
|
33
|
+
} from "../chunk-NPNBGCRC.js";
|
|
34
|
+
import {
|
|
35
|
+
AttachmentError,
|
|
36
|
+
ConfigurationError,
|
|
37
|
+
ConnectorError,
|
|
38
|
+
InitializationError,
|
|
39
|
+
PlatformAdapterError,
|
|
40
|
+
PowerSyncError,
|
|
41
|
+
SyncOperationError,
|
|
42
|
+
classifyError,
|
|
43
|
+
classifySupabaseError,
|
|
44
|
+
createSyncError,
|
|
45
|
+
extractEntityIds,
|
|
46
|
+
extractTableNames,
|
|
47
|
+
generateFailureId,
|
|
48
|
+
toSyncOperationError
|
|
49
|
+
} from "../chunk-CHRTN5PF.js";
|
|
50
|
+
export {
|
|
51
|
+
ATTACHMENT_DOWNLOAD_TIMEOUT_MS,
|
|
52
|
+
ATTACHMENT_RETRY_DELAY_MS,
|
|
53
|
+
AttachmentError,
|
|
54
|
+
COMPRESSION_MAX_WIDTH,
|
|
55
|
+
COMPRESSION_SKIP_SIZE_BYTES,
|
|
56
|
+
COMPRESSION_TARGET_SIZE_BYTES,
|
|
57
|
+
ConfigurationError,
|
|
58
|
+
ConnectorError,
|
|
59
|
+
DEFAULT_ATTACHMENT_CACHE_SIZE,
|
|
60
|
+
DEFAULT_ATTACHMENT_CONCURRENCY,
|
|
61
|
+
DEFAULT_COMPRESSION_QUALITY,
|
|
62
|
+
DEFAULT_MAX_RETRY_ATTEMPTS,
|
|
63
|
+
DEFAULT_RETRY_BACKOFF_MULTIPLIER,
|
|
64
|
+
DEFAULT_RETRY_BASE_DELAY_MS,
|
|
65
|
+
DEFAULT_RETRY_MAX_DELAY_MS,
|
|
66
|
+
DEFAULT_SYNC_INTERVAL_MS,
|
|
67
|
+
DEFAULT_SYNC_MODE,
|
|
68
|
+
DOWNLOAD_STOP_THRESHOLD,
|
|
69
|
+
EVICTION_TRIGGER_THRESHOLD,
|
|
70
|
+
HEALTH_CHECK_INTERVAL_MS,
|
|
71
|
+
HEALTH_CHECK_TIMEOUT_MS,
|
|
72
|
+
InitializationError,
|
|
73
|
+
LATENCY_DEGRADED_THRESHOLD_MS,
|
|
74
|
+
MAX_CONSECUTIVE_FAILURES,
|
|
75
|
+
PlatformAdapterError,
|
|
76
|
+
PowerSyncError,
|
|
77
|
+
STATS_CACHE_TTL_MS,
|
|
78
|
+
STATUS_NOTIFY_THROTTLE_MS,
|
|
79
|
+
STORAGE_CRITICAL_THRESHOLD,
|
|
80
|
+
STORAGE_KEY_ATTACHMENT_SETTINGS,
|
|
81
|
+
STORAGE_KEY_ENABLED,
|
|
82
|
+
STORAGE_KEY_METRICS,
|
|
83
|
+
STORAGE_KEY_PAUSED,
|
|
84
|
+
STORAGE_KEY_PREFIX,
|
|
85
|
+
STORAGE_KEY_SYNC_MODE,
|
|
86
|
+
STORAGE_WARNING_THRESHOLD,
|
|
87
|
+
SyncOperationError,
|
|
88
|
+
classifyError,
|
|
89
|
+
classifySupabaseError,
|
|
90
|
+
createSyncError,
|
|
91
|
+
extractEntityIds,
|
|
92
|
+
extractTableNames,
|
|
93
|
+
generateFailureId,
|
|
94
|
+
toSyncOperationError
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { S as SupabaseConnector, a as SupabaseConnectorOptions } from './supabase-connector-D14-kl5v.js';
|
|
2
|
+
import { A as AbstractPowerSyncDatabase } from './types-afHtE1U_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Conflict Types for @pol-studios/powersync
|
|
6
|
+
*
|
|
7
|
+
* Provides types for version-based conflict detection using AuditLog attribution.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Represents a field-level conflict where both local and server changed the same field.
|
|
11
|
+
*/
|
|
12
|
+
interface FieldConflict {
|
|
13
|
+
/** The field name that has conflicting changes */
|
|
14
|
+
field: string;
|
|
15
|
+
/** The local (pending) value */
|
|
16
|
+
localValue: unknown;
|
|
17
|
+
/** The current server value */
|
|
18
|
+
serverValue: unknown;
|
|
19
|
+
/** User who made the server change (from AuditLog.changeBy) */
|
|
20
|
+
changedBy: string | null;
|
|
21
|
+
/** When the server change occurred (from AuditLog.changeAt) */
|
|
22
|
+
changedAt: Date;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Result of checking for conflicts between local changes and server state.
|
|
26
|
+
*/
|
|
27
|
+
interface ConflictCheckResult {
|
|
28
|
+
/** Whether any field conflicts were detected */
|
|
29
|
+
hasConflict: boolean;
|
|
30
|
+
/** List of field-level conflicts */
|
|
31
|
+
conflicts: FieldConflict[];
|
|
32
|
+
/** Fields that can safely sync (no server changes) */
|
|
33
|
+
nonConflictingChanges: string[];
|
|
34
|
+
/** The table name */
|
|
35
|
+
table: string;
|
|
36
|
+
/** The record ID */
|
|
37
|
+
recordId: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* User's resolution choice for a conflict.
|
|
41
|
+
*/
|
|
42
|
+
type ConflictResolution = {
|
|
43
|
+
action: 'overwrite';
|
|
44
|
+
} | {
|
|
45
|
+
action: 'keep-server';
|
|
46
|
+
} | {
|
|
47
|
+
action: 'partial';
|
|
48
|
+
fields: string[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Handler for conflict events in the connector.
|
|
52
|
+
*/
|
|
53
|
+
interface ConflictHandler {
|
|
54
|
+
/**
|
|
55
|
+
* Called when a conflict is detected during upload.
|
|
56
|
+
*
|
|
57
|
+
* @param result - The conflict check result
|
|
58
|
+
* @returns Resolution to apply, or null to queue for UI resolution
|
|
59
|
+
*/
|
|
60
|
+
onConflict: (result: ConflictCheckResult) => Promise<ConflictResolution | null>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for conflict detection behavior.
|
|
64
|
+
*/
|
|
65
|
+
interface ConflictDetectionConfig {
|
|
66
|
+
/** Tables to skip conflict detection (opt-out). Default: [] */
|
|
67
|
+
skipTables?: string[];
|
|
68
|
+
/** Fields to ignore in conflict detection. Default: ['updatedAt', 'createdAt'] */
|
|
69
|
+
ignoredFields?: string[];
|
|
70
|
+
/** Whether to enable conflict detection. Default: true */
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Conflict-Aware Connector for @pol-studios/powersync
|
|
76
|
+
*
|
|
77
|
+
* Extends SupabaseConnector with version-based conflict detection.
|
|
78
|
+
* Tables with a _version column automatically get conflict checking.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Options for ConflictAwareConnector.
|
|
83
|
+
*/
|
|
84
|
+
interface ConflictAwareConnectorOptions extends SupabaseConnectorOptions {
|
|
85
|
+
/** Handler for conflict resolution. If not provided, conflicts are logged. */
|
|
86
|
+
conflictHandler?: ConflictHandler;
|
|
87
|
+
/** Configuration for conflict detection behavior */
|
|
88
|
+
conflictDetection?: ConflictDetectionConfig;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A PowerSync connector with built-in conflict detection.
|
|
92
|
+
*
|
|
93
|
+
* This connector extends SupabaseConnector to add version-based conflict
|
|
94
|
+
* detection for tables with a `_version` column. When a conflict is detected,
|
|
95
|
+
* it calls the provided conflict handler to determine how to proceed.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const connector = new ConflictAwareConnector({
|
|
100
|
+
* supabaseClient: supabase,
|
|
101
|
+
* powerSyncUrl: POWERSYNC_URL,
|
|
102
|
+
* conflictHandler: {
|
|
103
|
+
* onConflict: async (result) => {
|
|
104
|
+
* // Queue for UI resolution
|
|
105
|
+
* conflictContext.addConflict(result);
|
|
106
|
+
* return null; // Don't proceed with upload
|
|
107
|
+
* },
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare class ConflictAwareConnector extends SupabaseConnector {
|
|
113
|
+
private readonly conflictHandler?;
|
|
114
|
+
private readonly conflictConfig?;
|
|
115
|
+
private readonly supabaseClient;
|
|
116
|
+
private readonly schemaRouterFn;
|
|
117
|
+
private versionColumnCache;
|
|
118
|
+
constructor(options: ConflictAwareConnectorOptions);
|
|
119
|
+
/**
|
|
120
|
+
* Override uploadData to check for conflicts before uploading.
|
|
121
|
+
*
|
|
122
|
+
* For each CRUD entry in the transaction:
|
|
123
|
+
* 1. Check if table has _version column (cached)
|
|
124
|
+
* 2. If yes, compare local vs server version
|
|
125
|
+
* 3. On version mismatch, query AuditLog for field conflicts
|
|
126
|
+
* 4. If conflicts found, call handler to determine resolution
|
|
127
|
+
* 5. Apply resolution or skip entry based on handler response
|
|
128
|
+
*/
|
|
129
|
+
uploadData(database: AbstractPowerSyncDatabase): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Check if a table has a _version column (cached).
|
|
132
|
+
*/
|
|
133
|
+
private checkVersionColumn;
|
|
134
|
+
/**
|
|
135
|
+
* Filter opData to only include specified fields.
|
|
136
|
+
*/
|
|
137
|
+
private filterFields;
|
|
138
|
+
/**
|
|
139
|
+
* Process a single CRUD entry - delegates to parent's private method.
|
|
140
|
+
*
|
|
141
|
+
* Note: This is a workaround since processCrudEntry is private in parent.
|
|
142
|
+
* We replicate the logic here for now.
|
|
143
|
+
*/
|
|
144
|
+
private processEntry;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { ConflictAwareConnector as C, type FieldConflict as F, type ConflictAwareConnectorOptions as a, type ConflictCheckResult as b, type ConflictResolution as c, type ConflictHandler as d, type ConflictDetectionConfig as e };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { A as AbstractPowerSyncDatabase } from './types-afHtE1U_.js';
|
|
2
|
+
export { k as CacheStats, i as ClassifiedError, j as CompactResult, h as CompletedTransaction, b as ConnectionHealth, o as CountRow, C as CrudEntry, l as CrudTransaction, n as DbStatRow, D as DownloadProgress, E as EntitySyncState, F as FailedTransaction, r as FreelistCountRow, s as IntegrityCheckRow, I as IntegrityResult, q as PageCountRow, p as PageSizeRow, P as PowerSyncBackendConnector, m as SqliteTableRow, c as StorageInfo, d as StorageQuota, f as SyncError, g as SyncErrorType, e as SyncMetrics, S as SyncMode, a as SyncStatus, T as TableCacheStats } from './types-afHtE1U_.js';
|
|
3
|
+
export { ATTACHMENT_DOWNLOAD_TIMEOUT_MS, ATTACHMENT_RETRY_DELAY_MS, AttachmentError, COMPRESSION_MAX_WIDTH, COMPRESSION_SKIP_SIZE_BYTES, COMPRESSION_TARGET_SIZE_BYTES, ConfigurationError, ConnectorError, DEFAULT_ATTACHMENT_CACHE_SIZE, DEFAULT_ATTACHMENT_CONCURRENCY, DEFAULT_COMPRESSION_QUALITY, DEFAULT_MAX_RETRY_ATTEMPTS, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_SYNC_INTERVAL_MS, DEFAULT_SYNC_MODE, DOWNLOAD_STOP_THRESHOLD, EVICTION_TRIGGER_THRESHOLD, HEALTH_CHECK_INTERVAL_MS, HEALTH_CHECK_TIMEOUT_MS, InitializationError, LATENCY_DEGRADED_THRESHOLD_MS, MAX_CONSECUTIVE_FAILURES, PlatformAdapterError, PowerSyncError, STATS_CACHE_TTL_MS, STATUS_NOTIFY_THROTTLE_MS, STORAGE_CRITICAL_THRESHOLD, STORAGE_KEY_ATTACHMENT_SETTINGS, STORAGE_KEY_ENABLED, STORAGE_KEY_METRICS, STORAGE_KEY_PAUSED, STORAGE_KEY_PREFIX, STORAGE_KEY_SYNC_MODE, STORAGE_WARNING_THRESHOLD, SyncOperationError, classifyError, classifySupabaseError, createSyncError, extractEntityIds, extractTableNames, generateFailureId, toSyncOperationError } from './core/index.js';
|
|
4
|
+
export { C as ConnectorConfig, c as CrudHandler, P as PowerSyncCredentials, b as SchemaRouter, S as SupabaseConnector, a as SupabaseConnectorOptions, d as defaultSchemaRouter } from './supabase-connector-D14-kl5v.js';
|
|
5
|
+
import { e as ConflictDetectionConfig, b as ConflictCheckResult } from './index-nae7nzib.js';
|
|
6
|
+
export { C as ConflictAwareConnector, a as ConflictAwareConnectorOptions, d as ConflictHandler, c as ConflictResolution, F as FieldConflict } from './index-nae7nzib.js';
|
|
7
|
+
export { AttachmentQueue, AttachmentQueueConfig, AttachmentRecord, AttachmentSourceConfig, AttachmentState, AttachmentStatsRow, AttachmentStorageAdapter, AttachmentSyncStats, AttachmentSyncStatus, CacheConfig, CacheFileRow, CachedSizeRow, CompressionConfig, DEFAULT_CACHE_CONFIG, DEFAULT_COMPRESSION_CONFIG, DEFAULT_DOWNLOAD_CONFIG, DownloadConfig, DownloadPhase, DownloadStatus, EvictRow, IdRow } from './attachments/index.js';
|
|
8
|
+
export { e as HealthCheckResult, H as HealthMonitorOptions, M as MetricsCollectorOptions, P as PowerSyncRawStatus, c as SyncControlActions, f as SyncEvent, g as SyncEventListener, d as SyncOperationData, S as SyncScope, a as SyncStatusState, b as SyncStatusTrackerOptions, U as Unsubscribe } from './types-Cd7RhNqf.js';
|
|
9
|
+
export { HealthMonitor, MetricsCollector, SyncStatusTracker } from './sync/index.js';
|
|
10
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
11
|
+
export { AttachmentQueueContext, ConnectionHealthContext, ConnectionHealthContextValue, DEFAULT_CONNECTION_HEALTH, DEFAULT_SYNC_CONFIG, DEFAULT_SYNC_METRICS, DEFAULT_SYNC_STATUS, EntitySyncStatusResult, PowerSyncConfig, PowerSyncContext, PowerSyncContextValue, PowerSyncProvider, PowerSyncProviderProps, SyncActivityResult, SyncConfig, SyncMetricsContext, SyncMetricsContextValue, SyncStatusContext, SyncStatusContextValue, UploadStatusResult, useAttachmentQueue, useConnectionHealth, useDatabase, useDownloadProgress, useEntitySyncStatus, useIsSyncing, useOnlineStatus, usePendingMutations, usePlatform, usePowerSync, useSyncActivity, useSyncControl, useSyncMetrics, useSyncMode, useSyncStatus, useUploadStatus } from './provider/index.js';
|
|
12
|
+
export { AsyncStorageAdapter, CompressedImage, CompressionOptions, ConnectionType, DatabaseOptions, FileInfo, FileSystemAdapter, ImageProcessorAdapter, LoggerAdapter, NetworkAdapter, PlatformAdapter, PlatformType, detectPlatform } from './platform/index.js';
|
|
13
|
+
import '@tanstack/react-query';
|
|
14
|
+
import 'react';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Conflict Detection for @pol-studios/powersync
|
|
18
|
+
*
|
|
19
|
+
* Provides version-based conflict detection using AuditLog attribution.
|
|
20
|
+
* Only queries AuditLog when version mismatch is detected.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Detect conflicts between local pending changes and server state.
|
|
25
|
+
*
|
|
26
|
+
* Uses a two-step approach:
|
|
27
|
+
* 1. Version match (local._version == server._version) → Sync immediately
|
|
28
|
+
* 2. Version mismatch → Query AuditLog for field changes and attribution
|
|
29
|
+
*
|
|
30
|
+
* @param table - The table name
|
|
31
|
+
* @param recordId - The record ID
|
|
32
|
+
* @param localVersion - Version number from local SQLite
|
|
33
|
+
* @param serverVersion - Version number from server (fetched separately)
|
|
34
|
+
* @param pendingChanges - Fields with local changes to sync
|
|
35
|
+
* @param supabase - Supabase client for AuditLog queries
|
|
36
|
+
* @param config - Optional detection configuration
|
|
37
|
+
* @returns Conflict check result with field-level details
|
|
38
|
+
*/
|
|
39
|
+
declare function detectConflicts(table: string, recordId: string, localVersion: number, serverVersion: number, pendingChanges: Record<string, unknown>, supabase: SupabaseClient, config?: ConflictDetectionConfig): Promise<ConflictCheckResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a table has a _version column for conflict detection.
|
|
42
|
+
*
|
|
43
|
+
* @param table - The table name
|
|
44
|
+
* @param db - PowerSync database instance
|
|
45
|
+
* @returns True if the table has version tracking
|
|
46
|
+
*/
|
|
47
|
+
declare function hasVersionColumn(table: string, db: AbstractPowerSyncDatabase): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Fetch the current server version for a record.
|
|
50
|
+
*
|
|
51
|
+
* @param table - The table name
|
|
52
|
+
* @param recordId - The record ID
|
|
53
|
+
* @param schema - The Supabase schema (default: 'public')
|
|
54
|
+
* @param supabase - Supabase client
|
|
55
|
+
* @returns The server version number, or null if record not found
|
|
56
|
+
*/
|
|
57
|
+
declare function fetchServerVersion(table: string, recordId: string, schema: string, supabase: SupabaseClient): Promise<number | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the local version for a record from PowerSync SQLite.
|
|
60
|
+
*
|
|
61
|
+
* @param table - The table name
|
|
62
|
+
* @param recordId - The record ID
|
|
63
|
+
* @param db - PowerSync database instance
|
|
64
|
+
* @returns The local version number, or null if not found
|
|
65
|
+
*/
|
|
66
|
+
declare function getLocalVersion(table: string, recordId: string, db: AbstractPowerSyncDatabase): Promise<number | null>;
|
|
67
|
+
|
|
68
|
+
export { AbstractPowerSyncDatabase, ConflictCheckResult, ConflictDetectionConfig, detectConflicts, fetchServerVersion, getLocalVersion, hasVersionColumn };
|