@pol-studios/db 1.0.19 → 1.0.22
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/DataLayerContext-ZmLPYR_s.d.ts +825 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +48 -0
- package/dist/auth/context.js +2 -2
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-2T6WTCP4.js → chunk-3EVWXMUV.js} +54 -155
- package/dist/chunk-3EVWXMUV.js.map +1 -0
- package/dist/{chunk-YERWPV6B.js → chunk-3FHAKRDV.js} +145 -19
- package/dist/{chunk-YERWPV6B.js.map → chunk-3FHAKRDV.js.map} +1 -1
- package/dist/{chunk-X3HZLNBV.js → chunk-FKRACEHV.js} +2 -962
- package/dist/chunk-FKRACEHV.js.map +1 -0
- package/dist/{chunk-N26IEHZT.js → chunk-FZF26ZRB.js} +18 -2
- package/dist/{chunk-N26IEHZT.js.map → chunk-FZF26ZRB.js.map} +1 -1
- package/dist/chunk-HTJ2FQW5.js +963 -0
- package/dist/chunk-HTJ2FQW5.js.map +1 -0
- package/dist/{chunk-R5B2XMN5.js → chunk-I4BDZDHX.js} +1614 -2141
- package/dist/chunk-I4BDZDHX.js.map +1 -0
- package/dist/{chunk-36DVUMQD.js → chunk-LPC64MD4.js} +2 -2
- package/dist/{chunk-72WV3ALS.js → chunk-OUUQSI3Y.js} +2 -2
- package/dist/{chunk-RMRYGICS.js → chunk-WP6TIVPH.js} +4 -4
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +568 -0
- package/dist/database.types-ChFCG-4M.d.ts +8604 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +119 -0
- package/dist/hooks/index.js +1 -1
- package/dist/index-2YySlz7X.d.ts +433 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -95
- package/dist/index.native.d.ts +775 -0
- package/dist/index.native.js +17 -96
- package/dist/index.web.d.ts +438 -0
- package/dist/index.web.js +585 -46
- package/dist/index.web.js.map +1 -1
- package/dist/mutation/index.d.ts +58 -0
- package/dist/parser/index.d.ts +366 -0
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/powersync-bridge/index.js +1 -1
- package/dist/query/index.d.ts +723 -0
- package/dist/query/index.js +10 -8
- package/dist/realtime/index.d.ts +44 -0
- package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
- package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types-CYr9JiUE.d.ts +62 -0
- package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
- package/dist/useDbCount-s-aR9YeV.d.ts +1082 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
- package/dist/useResolveFeedback-DTGcHpCs.d.ts +882 -0
- package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
- package/dist/with-auth/index.d.ts +704 -0
- package/dist/with-auth/index.js +4 -4
- package/package.json +50 -1
- package/dist/chunk-2T6WTCP4.js.map +0 -1
- package/dist/chunk-R5B2XMN5.js.map +0 -1
- package/dist/chunk-X3HZLNBV.js.map +0 -1
- /package/dist/{chunk-36DVUMQD.js.map → chunk-LPC64MD4.js.map} +0 -0
- /package/dist/{chunk-72WV3ALS.js.map → chunk-OUUQSI3Y.js.map} +0 -0
- /package/dist/{chunk-RMRYGICS.js.map → chunk-WP6TIVPH.js.map} +0 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { SyncControl, SyncStatus } from '../core/index.js';
|
|
2
|
+
export { P as PowerSyncDatabase } from '../executor-CB4KHyYG.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PowerSync Bridge for @pol-studios/db
|
|
6
|
+
*
|
|
7
|
+
* This module provides integration utilities between @pol-studios/db and
|
|
8
|
+
* @pol-studios/powersync packages. It re-exports key types and provides
|
|
9
|
+
* helper functions for type-safe integration.
|
|
10
|
+
*
|
|
11
|
+
* The @pol-studios/powersync package is an optional peer dependency.
|
|
12
|
+
* This bridge allows the db package to work seamlessly with or without
|
|
13
|
+
* the powersync package installed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { isPowerSyncAvailable, usePowerSyncDatabase } from '@pol-studios/db/powersync-bridge';
|
|
18
|
+
*
|
|
19
|
+
* if (isPowerSyncAvailable()) {
|
|
20
|
+
* // Use PowerSync features
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Re-export core types from @pol-studios/powersync for convenience.
|
|
26
|
+
* These types are defined here to avoid runtime dependency on the package.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Abstract interface for PowerSync database operations.
|
|
30
|
+
* This matches the interface from @pol-studios/powersync/core.
|
|
31
|
+
*/
|
|
32
|
+
interface AbstractPowerSyncDatabase {
|
|
33
|
+
/** Execute a query and return all results */
|
|
34
|
+
getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
35
|
+
/** Execute a query and return first result or null */
|
|
36
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
37
|
+
/** Execute a SQL statement (INSERT, UPDATE, DELETE) */
|
|
38
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
39
|
+
rowsAffected: number;
|
|
40
|
+
}>;
|
|
41
|
+
/** Whether the database is currently connected */
|
|
42
|
+
connected: boolean;
|
|
43
|
+
/** Current sync status */
|
|
44
|
+
currentStatus: {
|
|
45
|
+
connected: boolean;
|
|
46
|
+
connecting: boolean;
|
|
47
|
+
hasSynced: boolean;
|
|
48
|
+
lastSyncedAt: Date | null;
|
|
49
|
+
dataFlowStatus?: {
|
|
50
|
+
uploading: boolean;
|
|
51
|
+
downloading: boolean;
|
|
52
|
+
};
|
|
53
|
+
downloadProgress?: {
|
|
54
|
+
downloadedFraction: number;
|
|
55
|
+
downloadedOperations: number;
|
|
56
|
+
totalOperations: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Initialize the database */
|
|
60
|
+
init(): Promise<void>;
|
|
61
|
+
/** Close the database connection */
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
/** Connect to the PowerSync service */
|
|
64
|
+
connect(connector: unknown): Promise<void>;
|
|
65
|
+
/** Disconnect from the PowerSync service */
|
|
66
|
+
disconnect(): Promise<void>;
|
|
67
|
+
/** Register a listener for status changes */
|
|
68
|
+
registerListener(listener: {
|
|
69
|
+
statusChanged?: (status: unknown) => void;
|
|
70
|
+
}): () => void;
|
|
71
|
+
/** Get the next pending CRUD transaction */
|
|
72
|
+
getNextCrudTransaction(): Promise<unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sync status from @pol-studios/powersync.
|
|
76
|
+
*/
|
|
77
|
+
interface PowerSyncSyncStatus {
|
|
78
|
+
/** Whether connected to the PowerSync service */
|
|
79
|
+
connected: boolean;
|
|
80
|
+
/** Whether currently attempting to connect */
|
|
81
|
+
connecting: boolean;
|
|
82
|
+
/** Whether initial sync has completed */
|
|
83
|
+
hasSynced: boolean;
|
|
84
|
+
/** Timestamp of last successful sync */
|
|
85
|
+
lastSyncedAt: Date | null;
|
|
86
|
+
/** Whether currently uploading local changes */
|
|
87
|
+
uploading: boolean;
|
|
88
|
+
/** Whether currently downloading remote changes */
|
|
89
|
+
downloading: boolean;
|
|
90
|
+
/** Download progress details */
|
|
91
|
+
downloadProgress: {
|
|
92
|
+
current: number;
|
|
93
|
+
target: number;
|
|
94
|
+
percentage: number;
|
|
95
|
+
} | null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Connection health status from @pol-studios/powersync.
|
|
99
|
+
*/
|
|
100
|
+
interface PowerSyncConnectionHealth {
|
|
101
|
+
/** Current connection status */
|
|
102
|
+
status: "healthy" | "degraded" | "disconnected";
|
|
103
|
+
/** Last measured query latency in milliseconds */
|
|
104
|
+
latency: number | null;
|
|
105
|
+
/** Timestamp of the last health check */
|
|
106
|
+
lastHealthCheck: Date | null;
|
|
107
|
+
/** Number of consecutive health check failures */
|
|
108
|
+
consecutiveFailures: number;
|
|
109
|
+
/** Total reconnection attempts since last successful connection */
|
|
110
|
+
reconnectAttempts: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sync metrics from @pol-studios/powersync.
|
|
114
|
+
*/
|
|
115
|
+
interface PowerSyncMetrics {
|
|
116
|
+
/** Total number of sync operations attempted */
|
|
117
|
+
totalSyncs: number;
|
|
118
|
+
/** Number of successful sync operations */
|
|
119
|
+
successfulSyncs: number;
|
|
120
|
+
/** Number of failed sync operations */
|
|
121
|
+
failedSyncs: number;
|
|
122
|
+
/** Duration of the last sync in milliseconds */
|
|
123
|
+
lastSyncDuration: number | null;
|
|
124
|
+
/** Average sync duration in milliseconds */
|
|
125
|
+
averageSyncDuration: number | null;
|
|
126
|
+
/** Total bytes downloaded across all syncs */
|
|
127
|
+
totalDataDownloaded: number;
|
|
128
|
+
/** Total bytes uploaded across all syncs */
|
|
129
|
+
totalDataUploaded: number;
|
|
130
|
+
/** Last sync error details */
|
|
131
|
+
lastError: {
|
|
132
|
+
type: string;
|
|
133
|
+
message: string;
|
|
134
|
+
timestamp: Date;
|
|
135
|
+
} | null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sync control actions from @pol-studios/powersync.
|
|
139
|
+
*/
|
|
140
|
+
interface PowerSyncControlActions {
|
|
141
|
+
/** Trigger a sync operation */
|
|
142
|
+
triggerSync: () => Promise<void>;
|
|
143
|
+
/** Pause sync operations */
|
|
144
|
+
pause: () => Promise<void>;
|
|
145
|
+
/** Resume sync operations */
|
|
146
|
+
resume: () => Promise<void>;
|
|
147
|
+
/** Disconnect from the PowerSync service */
|
|
148
|
+
disconnect: () => Promise<void>;
|
|
149
|
+
/** Set the sync scope for selective sync */
|
|
150
|
+
setScope: (scope: {
|
|
151
|
+
type: string;
|
|
152
|
+
ids: string[];
|
|
153
|
+
} | null) => void;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if @pol-studios/powersync is available.
|
|
157
|
+
*
|
|
158
|
+
* This function performs a lazy check to see if the powersync package
|
|
159
|
+
* is installed and can be imported. The result is cached for subsequent calls.
|
|
160
|
+
*
|
|
161
|
+
* @returns true if @pol-studios/powersync is available, false otherwise
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { isPowerSyncAvailable } from '@pol-studios/db/powersync-bridge';
|
|
166
|
+
*
|
|
167
|
+
* if (isPowerSyncAvailable()) {
|
|
168
|
+
* // Safe to use PowerSync features
|
|
169
|
+
* const { usePowerSync } = await import('@pol-studios/powersync');
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function isPowerSyncAvailable(): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Reset the availability check cache.
|
|
176
|
+
* Useful for testing or when package installation state might change.
|
|
177
|
+
*/
|
|
178
|
+
declare function resetPowerSyncAvailabilityCache(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Type guard to check if a value is an AbstractPowerSyncDatabase.
|
|
181
|
+
*
|
|
182
|
+
* @param value - The value to check
|
|
183
|
+
* @returns true if value implements AbstractPowerSyncDatabase interface
|
|
184
|
+
*/
|
|
185
|
+
declare function isAbstractPowerSyncDatabase(value: unknown): value is AbstractPowerSyncDatabase;
|
|
186
|
+
/**
|
|
187
|
+
* Type guard to check if a value is a PowerSyncSyncStatus.
|
|
188
|
+
*
|
|
189
|
+
* @param value - The value to check
|
|
190
|
+
* @returns true if value matches PowerSyncSyncStatus interface
|
|
191
|
+
*/
|
|
192
|
+
declare function isPowerSyncSyncStatus(value: unknown): value is PowerSyncSyncStatus;
|
|
193
|
+
/**
|
|
194
|
+
* Convert PowerSync sync status to the V3 DataLayer SyncStatus format.
|
|
195
|
+
*
|
|
196
|
+
* This utility helps bridge the sync status from @pol-studios/powersync
|
|
197
|
+
* to the format expected by @pol-studios/db's DataLayerProvider.
|
|
198
|
+
*
|
|
199
|
+
* @param powerSyncStatus - The sync status from @pol-studios/powersync
|
|
200
|
+
* @param pendingCount - Number of pending uploads (from pendingMutations)
|
|
201
|
+
* @returns SyncStatus in @pol-studios/db format
|
|
202
|
+
*/
|
|
203
|
+
declare function convertToDataLayerSyncStatus(powerSyncStatus: PowerSyncSyncStatus, pendingCount?: number): SyncStatus;
|
|
204
|
+
/**
|
|
205
|
+
* Convert PowerSync sync control to the V3 DataLayer SyncControl format.
|
|
206
|
+
*
|
|
207
|
+
* @param powerSyncControl - The sync control actions from @pol-studios/powersync
|
|
208
|
+
* @returns SyncControl in @pol-studios/db format
|
|
209
|
+
*/
|
|
210
|
+
declare function convertToDataLayerSyncControl(powerSyncControl: PowerSyncControlActions): SyncControl;
|
|
211
|
+
/**
|
|
212
|
+
* Create a database instance getter that works with PowerSync context.
|
|
213
|
+
*
|
|
214
|
+
* This is useful for integrating PowerSyncProvider with DataLayerProvider
|
|
215
|
+
* by providing a way to get the database instance from the PowerSync context.
|
|
216
|
+
*
|
|
217
|
+
* @param getPowerSyncDb - Function to get the PowerSync database from context
|
|
218
|
+
* @returns A function that returns the database or null
|
|
219
|
+
*/
|
|
220
|
+
declare function createDatabaseGetter(getPowerSyncDb: () => AbstractPowerSyncDatabase | null): () => AbstractPowerSyncDatabase | null;
|
|
221
|
+
/**
|
|
222
|
+
* Options for setting up DataLayerProvider with PowerSync integration.
|
|
223
|
+
*/
|
|
224
|
+
interface PowerSyncIntegrationOptions {
|
|
225
|
+
/**
|
|
226
|
+
* The PowerSync database instance from PowerSyncProvider.
|
|
227
|
+
*/
|
|
228
|
+
database: AbstractPowerSyncDatabase | null;
|
|
229
|
+
/**
|
|
230
|
+
* Whether the PowerSync database is ready.
|
|
231
|
+
*/
|
|
232
|
+
isReady: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Current sync status from PowerSyncProvider.
|
|
235
|
+
*/
|
|
236
|
+
syncStatus?: PowerSyncSyncStatus;
|
|
237
|
+
/**
|
|
238
|
+
* Sync control actions from PowerSyncProvider.
|
|
239
|
+
*/
|
|
240
|
+
syncControl?: PowerSyncControlActions;
|
|
241
|
+
/**
|
|
242
|
+
* Number of pending mutations.
|
|
243
|
+
*/
|
|
244
|
+
pendingCount?: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get the powerSyncInstance prop for DataLayerProvider from PowerSync context values.
|
|
248
|
+
*
|
|
249
|
+
* This helper extracts the necessary values from @pol-studios/powersync hooks
|
|
250
|
+
* and returns them in a format suitable for DataLayerProvider.
|
|
251
|
+
*
|
|
252
|
+
* @param options - The PowerSync integration options
|
|
253
|
+
* @returns The powerSyncInstance to pass to DataLayerProvider, or null if not ready
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* // Inside a component wrapped with PowerSyncProvider
|
|
258
|
+
* const { db, isReady } = usePowerSync();
|
|
259
|
+
* const { status, pendingCount } = useSyncStatus();
|
|
260
|
+
* const syncControl = useSyncControl();
|
|
261
|
+
*
|
|
262
|
+
* const powerSyncInstance = getPowerSyncInstance({
|
|
263
|
+
* database: db,
|
|
264
|
+
* isReady,
|
|
265
|
+
* syncStatus: status,
|
|
266
|
+
* syncControl,
|
|
267
|
+
* pendingCount,
|
|
268
|
+
* });
|
|
269
|
+
*
|
|
270
|
+
* return (
|
|
271
|
+
* <DataLayerProvider
|
|
272
|
+
* config={config}
|
|
273
|
+
* powerSyncInstance={powerSyncInstance}
|
|
274
|
+
* supabaseClient={supabase}
|
|
275
|
+
* queryClient={queryClient}
|
|
276
|
+
* >
|
|
277
|
+
* {children}
|
|
278
|
+
* </DataLayerProvider>
|
|
279
|
+
* );
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
declare function getPowerSyncInstance(options: PowerSyncIntegrationOptions): AbstractPowerSyncDatabase | null;
|
|
283
|
+
|
|
284
|
+
export { type AbstractPowerSyncDatabase, type PowerSyncConnectionHealth, type PowerSyncControlActions, type PowerSyncIntegrationOptions, type PowerSyncMetrics, type PowerSyncSyncStatus, convertToDataLayerSyncControl, convertToDataLayerSyncStatus, createDatabaseGetter, getPowerSyncInstance, isAbstractPowerSyncDatabase, isPowerSyncAvailable, isPowerSyncSyncStatus, resetPowerSyncAvailabilityCache };
|