@pol-studios/db 1.0.59 → 1.0.61
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/{chunk-K46TGKB2.js → chunk-7PBTPCRN.js} +86 -76
- package/dist/chunk-7PBTPCRN.js.map +1 -0
- package/dist/{chunk-VADZSRHY.js → chunk-FWCHS5NN.js} +2 -2
- package/dist/{chunk-VSY6766U.js → chunk-H4Z73DC4.js} +2 -2
- package/dist/{chunk-7BGDQT5X.js → chunk-PIPB3JMK.js} +1 -7
- package/dist/{chunk-7BGDQT5X.js.map → chunk-PIPB3JMK.js.map} +1 -1
- package/dist/{chunk-WY6MNB6K.js → chunk-ZPFZ2ZRW.js} +3 -12
- package/dist/{chunk-WY6MNB6K.js.map → chunk-ZPFZ2ZRW.js.map} +1 -1
- package/dist/core/index.d.ts +7 -43
- package/dist/hooks/index.js +1 -1
- package/dist/index.js +5 -5
- package/dist/index.native.js +4 -4
- package/dist/index.web.js +3 -10
- package/dist/index.web.js.map +1 -1
- package/dist/powersync-bridge/index.js +1 -1
- package/dist/with-auth/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-K46TGKB2.js.map +0 -1
- /package/dist/{chunk-VADZSRHY.js.map → chunk-FWCHS5NN.js.map} +0 -0
- /package/dist/{chunk-VSY6766U.js.map → chunk-H4Z73DC4.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useDbUpsert
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZPFZ2ZRW.js";
|
|
4
4
|
import {
|
|
5
5
|
normalizeFilter
|
|
6
6
|
} from "./chunk-F4HW4NT5.js";
|
|
@@ -7944,4 +7944,4 @@ moment/moment.js:
|
|
|
7944
7944
|
(*! license : MIT *)
|
|
7945
7945
|
(*! momentjs.com *)
|
|
7946
7946
|
*/
|
|
7947
|
-
//# sourceMappingURL=chunk-
|
|
7947
|
+
//# sourceMappingURL=chunk-FWCHS5NN.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useDbUpsert
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZPFZ2ZRW.js";
|
|
4
4
|
import {
|
|
5
5
|
UserMetadata
|
|
6
6
|
} from "./chunk-SM73S2DY.js";
|
|
@@ -470,4 +470,4 @@ export {
|
|
|
470
470
|
useSetUserMetadata,
|
|
471
471
|
useUserMetadataState
|
|
472
472
|
};
|
|
473
|
-
//# sourceMappingURL=chunk-
|
|
473
|
+
//# sourceMappingURL=chunk-H4Z73DC4.js.map
|
|
@@ -72,12 +72,6 @@ function convertToDataLayerSyncControl(powerSyncControl) {
|
|
|
72
72
|
ids: values
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
|
-
// Auto-retry controls - managed by the provider/context
|
|
76
|
-
pauseAutoRetry: () => {
|
|
77
|
-
},
|
|
78
|
-
resumeAutoRetry: () => {
|
|
79
|
-
},
|
|
80
|
-
isAutoRetryPaused: false,
|
|
81
75
|
// Pending mutations - managed by the provider/context, not this bridge
|
|
82
76
|
addPendingMutation: () => {
|
|
83
77
|
},
|
|
@@ -105,4 +99,4 @@ export {
|
|
|
105
99
|
createDatabaseGetter,
|
|
106
100
|
getPowerSyncInstance
|
|
107
101
|
};
|
|
108
|
-
//# sourceMappingURL=chunk-
|
|
102
|
+
//# sourceMappingURL=chunk-PIPB3JMK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/powersync-bridge/index.ts"],"sourcesContent":["/**\n * PowerSync Bridge for @pol-studios/db\n *\n * This module provides integration utilities between @pol-studios/db and\n * @pol-studios/powersync packages. It re-exports key types and provides\n * helper functions for type-safe integration.\n *\n * The @pol-studios/powersync package is an optional peer dependency.\n * This bridge allows the db package to work seamlessly with or without\n * the powersync package installed.\n *\n * @example\n * ```typescript\n * import { isPowerSyncAvailable, usePowerSyncDatabase } from '@pol-studios/db/powersync-bridge';\n *\n * if (isPowerSyncAvailable()) {\n * // Use PowerSync features\n * }\n * ```\n */\n\n// =============================================================================\n// Type Re-exports from @pol-studios/powersync\n// =============================================================================\n\n/**\n * Re-export core types from @pol-studios/powersync for convenience.\n * These types are defined here to avoid runtime dependency on the package.\n */\n\n/**\n * Abstract interface for PowerSync database operations.\n * This matches the interface from @pol-studios/powersync/core.\n */\nexport interface AbstractPowerSyncDatabase {\n /** Execute a query and return all results */\n getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;\n /** Execute a query and return first result or null */\n get<T>(sql: string, params?: unknown[]): Promise<T | null>;\n /** Execute a SQL statement (INSERT, UPDATE, DELETE) */\n execute(sql: string, params?: unknown[]): Promise<{\n rowsAffected: number;\n }>;\n /** Whether the database is currently connected */\n connected: boolean;\n /** Current sync status */\n currentStatus: {\n connected: boolean;\n connecting: boolean;\n hasSynced: boolean;\n lastSyncedAt: Date | null;\n dataFlowStatus?: {\n uploading: boolean;\n downloading: boolean;\n };\n downloadProgress?: {\n downloadedFraction: number;\n downloadedOperations: number;\n totalOperations: number;\n };\n };\n /** Initialize the database */\n init(): Promise<void>;\n /** Close the database connection */\n close(): Promise<void>;\n /** Connect to the PowerSync service */\n connect(connector: unknown): Promise<void>;\n /** Disconnect from the PowerSync service */\n disconnect(): Promise<void>;\n /** Register a listener for status changes */\n registerListener(listener: {\n statusChanged?: (status: unknown) => void;\n }): () => void;\n /** Get the next pending CRUD transaction */\n getNextCrudTransaction(): Promise<unknown>;\n}\n\n/**\n * Sync status from @pol-studios/powersync.\n */\nexport interface PowerSyncSyncStatus {\n /** Whether connected to the PowerSync service */\n connected: boolean;\n /** Whether currently attempting to connect */\n connecting: boolean;\n /** Whether initial sync has completed */\n hasSynced: boolean;\n /** Timestamp of last successful sync */\n lastSyncedAt: Date | null;\n /** Whether currently uploading local changes */\n uploading: boolean;\n /** Whether currently downloading remote changes */\n downloading: boolean;\n /** Download progress details */\n downloadProgress: {\n current: number;\n target: number;\n percentage: number;\n } | null;\n}\n\n/**\n * Connection health status from @pol-studios/powersync.\n */\nexport interface PowerSyncConnectionHealth {\n /** Current connection status */\n status: \"healthy\" | \"degraded\" | \"disconnected\";\n /** Last measured query latency in milliseconds */\n latency: number | null;\n /** Timestamp of the last health check */\n lastHealthCheck: Date | null;\n /** Number of consecutive health check failures */\n consecutiveFailures: number;\n /** Total reconnection attempts since last successful connection */\n reconnectAttempts: number;\n}\n\n/**\n * Sync metrics from @pol-studios/powersync.\n */\nexport interface PowerSyncMetrics {\n /** Total number of sync operations attempted */\n totalSyncs: number;\n /** Number of successful sync operations */\n successfulSyncs: number;\n /** Number of failed sync operations */\n failedSyncs: number;\n /** Duration of the last sync in milliseconds */\n lastSyncDuration: number | null;\n /** Average sync duration in milliseconds */\n averageSyncDuration: number | null;\n /** Total bytes downloaded across all syncs */\n totalDataDownloaded: number;\n /** Total bytes uploaded across all syncs */\n totalDataUploaded: number;\n /** Last sync error details */\n lastError: {\n type: string;\n message: string;\n timestamp: Date;\n } | null;\n}\n\n/**\n * Sync control actions from @pol-studios/powersync.\n */\nexport interface PowerSyncControlActions {\n /** Trigger a sync operation */\n triggerSync: () => Promise<void>;\n /** Pause sync operations */\n pause: () => Promise<void>;\n /** Resume sync operations */\n resume: () => Promise<void>;\n /** Disconnect from the PowerSync service */\n disconnect: () => Promise<void>;\n /** Set the sync scope for selective sync */\n setScope: (scope: {\n type: string;\n ids: string[];\n } | null) => void;\n}\n\n// =============================================================================\n// Availability Check\n// =============================================================================\n\n/**\n * Flag to track whether @pol-studios/powersync is available.\n * This is set lazily on first check.\n */\nlet _powerSyncAvailable: boolean | null = null;\n\n/**\n * Check if @pol-studios/powersync is available.\n *\n * This function performs a lazy check to see if the powersync package\n * is installed and can be imported. The result is cached for subsequent calls.\n *\n * @returns true if @pol-studios/powersync is available, false otherwise\n *\n * @example\n * ```typescript\n * import { isPowerSyncAvailable } from '@pol-studios/db/powersync-bridge';\n *\n * if (isPowerSyncAvailable()) {\n * // Safe to use PowerSync features\n * const { usePowerSync } = await import('@pol-studios/powersync');\n * }\n * ```\n */\nexport function isPowerSyncAvailable(): boolean {\n if (_powerSyncAvailable === null) {\n try {\n // Try to require the package to check availability\n // This will throw if the package is not installed\n require.resolve(\"@pol-studios/powersync\");\n _powerSyncAvailable = true;\n } catch {\n _powerSyncAvailable = false;\n }\n }\n return _powerSyncAvailable;\n}\n\n/**\n * Reset the availability check cache.\n * Useful for testing or when package installation state might change.\n */\nexport function resetPowerSyncAvailabilityCache(): void {\n _powerSyncAvailable = null;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Type guard to check if a value is an AbstractPowerSyncDatabase.\n *\n * @param value - The value to check\n * @returns true if value implements AbstractPowerSyncDatabase interface\n */\nexport function isAbstractPowerSyncDatabase(value: unknown): value is AbstractPowerSyncDatabase {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const db = value as Record<string, unknown>;\n return typeof db.getAll === \"function\" && typeof db.get === \"function\" && typeof db.execute === \"function\" && typeof db.init === \"function\" && typeof db.close === \"function\" && typeof db.connect === \"function\" && typeof db.disconnect === \"function\" && typeof db.registerListener === \"function\" && \"connected\" in db && \"currentStatus\" in db;\n}\n\n/**\n * Type guard to check if a value is a PowerSyncSyncStatus.\n *\n * @param value - The value to check\n * @returns true if value matches PowerSyncSyncStatus interface\n */\nexport function isPowerSyncSyncStatus(value: unknown): value is PowerSyncSyncStatus {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const status = value as Record<string, unknown>;\n return typeof status.connected === \"boolean\" && typeof status.connecting === \"boolean\" && typeof status.hasSynced === \"boolean\" && typeof status.uploading === \"boolean\" && typeof status.downloading === \"boolean\";\n}\n\n// =============================================================================\n// Conversion Utilities\n// =============================================================================\n\n/**\n * Error information that can be passed from PowerSync layer.\n * This allows propagating sync errors through the bridge.\n */\nexport interface PowerSyncErrorInfo {\n /** Error message */\n message: string;\n /** Error type/category (e.g., 'network', 'auth', 'conflict') */\n type?: string;\n /** Whether this is a permanent error */\n isPermanent?: boolean;\n /** Timestamp when error occurred */\n timestamp?: Date;\n}\n\n/**\n * Convert PowerSync sync status to the V3 DataLayer SyncStatus format.\n *\n * This utility helps bridge the sync status from @pol-studios/powersync\n * to the format expected by @pol-studios/db's DataLayerProvider.\n *\n * @param powerSyncStatus - The sync status from @pol-studios/powersync\n * @param pendingCount - Number of pending uploads (from pendingMutations)\n * @param error - Optional error information from PowerSync layer\n * @returns SyncStatus in @pol-studios/db format\n */\nexport function convertToDataLayerSyncStatus(powerSyncStatus: PowerSyncSyncStatus, pendingCount: number = 0, error?: PowerSyncErrorInfo | Error | null): import(\"../core/types\").SyncStatus {\n // Convert error to Error instance if provided\n let syncError: Error | null = null;\n if (error) {\n if (error instanceof Error) {\n syncError = error;\n } else {\n // Create an Error with the message and attach additional properties\n const err = new Error(error.message);\n err.name = error.type ?? 'SyncError';\n // Attach metadata as non-enumerable properties for debugging\n Object.defineProperty(err, 'isPermanent', {\n value: error.isPermanent ?? false,\n enumerable: false\n });\n Object.defineProperty(err, 'timestamp', {\n value: error.timestamp ?? new Date(),\n enumerable: false\n });\n syncError = err;\n }\n }\n return {\n isConnected: powerSyncStatus.connected,\n isSyncing: powerSyncStatus.uploading || powerSyncStatus.downloading,\n lastSyncedAt: powerSyncStatus.lastSyncedAt,\n pendingUploads: pendingCount,\n error: syncError\n };\n}\n\n/**\n * Convert PowerSync sync control to the V3 DataLayer SyncControl format.\n *\n * @param powerSyncControl - The sync control actions from @pol-studios/powersync\n * @returns SyncControl in @pol-studios/db format\n */\nexport function convertToDataLayerSyncControl(powerSyncControl: PowerSyncControlActions): import(\"../core/types\").SyncControl {\n return {\n triggerSync: powerSyncControl.triggerSync,\n startLiveSync: powerSyncControl.resume,\n stopLiveSync: () => {\n powerSyncControl.pause();\n },\n setScope: async (scopeName: string, values: string[]) => {\n powerSyncControl.setScope({\n type: scopeName,\n ids: values\n });\n },\n // Auto-retry controls - managed by the provider/context\n pauseAutoRetry: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n },\n resumeAutoRetry: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n },\n isAutoRetryPaused: false,\n // Pending mutations - managed by the provider/context, not this bridge\n addPendingMutation: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n },\n removePendingMutation: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n }\n };\n}\n\n// =============================================================================\n// Integration Helpers\n// =============================================================================\n\n/**\n * Create a database instance getter that works with PowerSync context.\n *\n * This is useful for integrating PowerSyncProvider with DataLayerProvider\n * by providing a way to get the database instance from the PowerSync context.\n *\n * @param getPowerSyncDb - Function to get the PowerSync database from context\n * @returns A function that returns the database or null\n */\nexport function createDatabaseGetter(getPowerSyncDb: () => AbstractPowerSyncDatabase | null): () => AbstractPowerSyncDatabase | null {\n return getPowerSyncDb;\n}\n\n/**\n * Options for setting up DataLayerProvider with PowerSync integration.\n */\nexport interface PowerSyncIntegrationOptions {\n /**\n * The PowerSync database instance from PowerSyncProvider.\n */\n database: AbstractPowerSyncDatabase | null;\n\n /**\n * Whether the PowerSync database is ready.\n */\n isReady: boolean;\n\n /**\n * Current sync status from PowerSyncProvider.\n */\n syncStatus?: PowerSyncSyncStatus;\n\n /**\n * Sync control actions from PowerSyncProvider.\n */\n syncControl?: PowerSyncControlActions;\n\n /**\n * Number of pending mutations.\n */\n pendingCount?: number;\n}\n\n/**\n * Get the powerSyncInstance prop for DataLayerProvider from PowerSync context values.\n *\n * This helper extracts the necessary values from @pol-studios/powersync hooks\n * and returns them in a format suitable for DataLayerProvider.\n *\n * @param options - The PowerSync integration options\n * @returns The powerSyncInstance to pass to DataLayerProvider, or null if not ready\n *\n * @example\n * ```typescript\n * // Inside a component wrapped with PowerSyncProvider\n * const { db, isReady } = usePowerSync();\n * const { status, pendingCount } = useSyncStatus();\n * const syncControl = useSyncControl();\n *\n * const powerSyncInstance = getPowerSyncInstance({\n * database: db,\n * isReady,\n * syncStatus: status,\n * syncControl,\n * pendingCount,\n * });\n *\n * return (\n * <DataLayerProvider\n * config={config}\n * powerSyncInstance={powerSyncInstance}\n * supabaseClient={supabase}\n * queryClient={queryClient}\n * >\n * {children}\n * </DataLayerProvider>\n * );\n * ```\n */\nexport function getPowerSyncInstance(options: PowerSyncIntegrationOptions): AbstractPowerSyncDatabase | null {\n if (!options.isReady || !options.database) {\n return null;\n }\n return options.database;\n}\n\n// =============================================================================\n// Re-export for Convenience\n// =============================================================================\n\n/**\n * Re-export the PowerSyncDatabase type from the query executor for convenience.\n * This is the minimal interface used internally by @pol-studios/db.\n */\nexport type { PowerSyncDatabase } from \"../query/executor\";"],"mappings":";;;;;AA0KA,IAAI,sBAAsC;AAoBnC,SAAS,uBAAgC;AAC9C,MAAI,wBAAwB,MAAM;AAChC,QAAI;AAGF,gBAAQ,QAAQ,wBAAwB;AACxC,4BAAsB;AAAA,IACxB,QAAQ;AACN,4BAAsB;AAAA,IACxB;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,kCAAwC;AACtD,wBAAsB;AACxB;AAYO,SAAS,4BAA4B,OAAoD;AAC9F,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,KAAK;AACX,SAAO,OAAO,GAAG,WAAW,cAAc,OAAO,GAAG,QAAQ,cAAc,OAAO,GAAG,YAAY,cAAc,OAAO,GAAG,SAAS,cAAc,OAAO,GAAG,UAAU,cAAc,OAAO,GAAG,YAAY,cAAc,OAAO,GAAG,eAAe,cAAc,OAAO,GAAG,qBAAqB,cAAc,eAAe,MAAM,mBAAmB;AACnV;AAQO,SAAS,sBAAsB,OAA8C;AAClF,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,SAAS;AACf,SAAO,OAAO,OAAO,cAAc,aAAa,OAAO,OAAO,eAAe,aAAa,OAAO,OAAO,cAAc,aAAa,OAAO,OAAO,cAAc,aAAa,OAA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QAAQ,UAAU;AACzC,WAAO;AAAA,EACT;AACA,SAAO,QAAQ;AACjB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/powersync-bridge/index.ts"],"sourcesContent":["/**\n * PowerSync Bridge for @pol-studios/db\n *\n * This module provides integration utilities between @pol-studios/db and\n * @pol-studios/powersync packages. It re-exports key types and provides\n * helper functions for type-safe integration.\n *\n * The @pol-studios/powersync package is an optional peer dependency.\n * This bridge allows the db package to work seamlessly with or without\n * the powersync package installed.\n *\n * @example\n * ```typescript\n * import { isPowerSyncAvailable, usePowerSyncDatabase } from '@pol-studios/db/powersync-bridge';\n *\n * if (isPowerSyncAvailable()) {\n * // Use PowerSync features\n * }\n * ```\n */\n\n// =============================================================================\n// Type Re-exports from @pol-studios/powersync\n// =============================================================================\n\n/**\n * Re-export core types from @pol-studios/powersync for convenience.\n * These types are defined here to avoid runtime dependency on the package.\n */\n\n/**\n * Abstract interface for PowerSync database operations.\n * This matches the interface from @pol-studios/powersync/core.\n */\nexport interface AbstractPowerSyncDatabase {\n /** Execute a query and return all results */\n getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;\n /** Execute a query and return first result or null */\n get<T>(sql: string, params?: unknown[]): Promise<T | null>;\n /** Execute a SQL statement (INSERT, UPDATE, DELETE) */\n execute(sql: string, params?: unknown[]): Promise<{\n rowsAffected: number;\n }>;\n /** Whether the database is currently connected */\n connected: boolean;\n /** Current sync status */\n currentStatus: {\n connected: boolean;\n connecting: boolean;\n hasSynced: boolean;\n lastSyncedAt: Date | null;\n dataFlowStatus?: {\n uploading: boolean;\n downloading: boolean;\n };\n downloadProgress?: {\n downloadedFraction: number;\n downloadedOperations: number;\n totalOperations: number;\n };\n };\n /** Initialize the database */\n init(): Promise<void>;\n /** Close the database connection */\n close(): Promise<void>;\n /** Connect to the PowerSync service */\n connect(connector: unknown): Promise<void>;\n /** Disconnect from the PowerSync service */\n disconnect(): Promise<void>;\n /** Register a listener for status changes */\n registerListener(listener: {\n statusChanged?: (status: unknown) => void;\n }): () => void;\n /** Get the next pending CRUD transaction */\n getNextCrudTransaction(): Promise<unknown>;\n}\n\n/**\n * Sync status from @pol-studios/powersync.\n */\nexport interface PowerSyncSyncStatus {\n /** Whether connected to the PowerSync service */\n connected: boolean;\n /** Whether currently attempting to connect */\n connecting: boolean;\n /** Whether initial sync has completed */\n hasSynced: boolean;\n /** Timestamp of last successful sync */\n lastSyncedAt: Date | null;\n /** Whether currently uploading local changes */\n uploading: boolean;\n /** Whether currently downloading remote changes */\n downloading: boolean;\n /** Download progress details */\n downloadProgress: {\n current: number;\n target: number;\n percentage: number;\n } | null;\n}\n\n/**\n * Connection health status from @pol-studios/powersync.\n */\nexport interface PowerSyncConnectionHealth {\n /** Current connection status */\n status: \"healthy\" | \"degraded\" | \"disconnected\";\n /** Last measured query latency in milliseconds */\n latency: number | null;\n /** Timestamp of the last health check */\n lastHealthCheck: Date | null;\n /** Number of consecutive health check failures */\n consecutiveFailures: number;\n /** Total reconnection attempts since last successful connection */\n reconnectAttempts: number;\n}\n\n/**\n * Sync metrics from @pol-studios/powersync.\n */\nexport interface PowerSyncMetrics {\n /** Total number of sync operations attempted */\n totalSyncs: number;\n /** Number of successful sync operations */\n successfulSyncs: number;\n /** Number of failed sync operations */\n failedSyncs: number;\n /** Duration of the last sync in milliseconds */\n lastSyncDuration: number | null;\n /** Average sync duration in milliseconds */\n averageSyncDuration: number | null;\n /** Total bytes downloaded across all syncs */\n totalDataDownloaded: number;\n /** Total bytes uploaded across all syncs */\n totalDataUploaded: number;\n /** Last sync error details */\n lastError: {\n type: string;\n message: string;\n timestamp: Date;\n } | null;\n}\n\n/**\n * Sync control actions from @pol-studios/powersync.\n */\nexport interface PowerSyncControlActions {\n /** Trigger a sync operation */\n triggerSync: () => Promise<void>;\n /** Pause sync operations */\n pause: () => Promise<void>;\n /** Resume sync operations */\n resume: () => Promise<void>;\n /** Disconnect from the PowerSync service */\n disconnect: () => Promise<void>;\n /** Set the sync scope for selective sync */\n setScope: (scope: {\n type: string;\n ids: string[];\n } | null) => void;\n}\n\n// =============================================================================\n// Availability Check\n// =============================================================================\n\n/**\n * Flag to track whether @pol-studios/powersync is available.\n * This is set lazily on first check.\n */\nlet _powerSyncAvailable: boolean | null = null;\n\n/**\n * Check if @pol-studios/powersync is available.\n *\n * This function performs a lazy check to see if the powersync package\n * is installed and can be imported. The result is cached for subsequent calls.\n *\n * @returns true if @pol-studios/powersync is available, false otherwise\n *\n * @example\n * ```typescript\n * import { isPowerSyncAvailable } from '@pol-studios/db/powersync-bridge';\n *\n * if (isPowerSyncAvailable()) {\n * // Safe to use PowerSync features\n * const { usePowerSync } = await import('@pol-studios/powersync');\n * }\n * ```\n */\nexport function isPowerSyncAvailable(): boolean {\n if (_powerSyncAvailable === null) {\n try {\n // Try to require the package to check availability\n // This will throw if the package is not installed\n require.resolve(\"@pol-studios/powersync\");\n _powerSyncAvailable = true;\n } catch {\n _powerSyncAvailable = false;\n }\n }\n return _powerSyncAvailable;\n}\n\n/**\n * Reset the availability check cache.\n * Useful for testing or when package installation state might change.\n */\nexport function resetPowerSyncAvailabilityCache(): void {\n _powerSyncAvailable = null;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Type guard to check if a value is an AbstractPowerSyncDatabase.\n *\n * @param value - The value to check\n * @returns true if value implements AbstractPowerSyncDatabase interface\n */\nexport function isAbstractPowerSyncDatabase(value: unknown): value is AbstractPowerSyncDatabase {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const db = value as Record<string, unknown>;\n return typeof db.getAll === \"function\" && typeof db.get === \"function\" && typeof db.execute === \"function\" && typeof db.init === \"function\" && typeof db.close === \"function\" && typeof db.connect === \"function\" && typeof db.disconnect === \"function\" && typeof db.registerListener === \"function\" && \"connected\" in db && \"currentStatus\" in db;\n}\n\n/**\n * Type guard to check if a value is a PowerSyncSyncStatus.\n *\n * @param value - The value to check\n * @returns true if value matches PowerSyncSyncStatus interface\n */\nexport function isPowerSyncSyncStatus(value: unknown): value is PowerSyncSyncStatus {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const status = value as Record<string, unknown>;\n return typeof status.connected === \"boolean\" && typeof status.connecting === \"boolean\" && typeof status.hasSynced === \"boolean\" && typeof status.uploading === \"boolean\" && typeof status.downloading === \"boolean\";\n}\n\n// =============================================================================\n// Conversion Utilities\n// =============================================================================\n\n/**\n * Error information that can be passed from PowerSync layer.\n * This allows propagating sync errors through the bridge.\n */\nexport interface PowerSyncErrorInfo {\n /** Error message */\n message: string;\n /** Error type/category (e.g., 'network', 'auth', 'conflict') */\n type?: string;\n /** Whether this is a permanent error */\n isPermanent?: boolean;\n /** Timestamp when error occurred */\n timestamp?: Date;\n}\n\n/**\n * Convert PowerSync sync status to the V3 DataLayer SyncStatus format.\n *\n * This utility helps bridge the sync status from @pol-studios/powersync\n * to the format expected by @pol-studios/db's DataLayerProvider.\n *\n * @param powerSyncStatus - The sync status from @pol-studios/powersync\n * @param pendingCount - Number of pending uploads (from pendingMutations)\n * @param error - Optional error information from PowerSync layer\n * @returns SyncStatus in @pol-studios/db format\n */\nexport function convertToDataLayerSyncStatus(powerSyncStatus: PowerSyncSyncStatus, pendingCount: number = 0, error?: PowerSyncErrorInfo | Error | null): import(\"../core/types\").SyncStatus {\n // Convert error to Error instance if provided\n let syncError: Error | null = null;\n if (error) {\n if (error instanceof Error) {\n syncError = error;\n } else {\n // Create an Error with the message and attach additional properties\n const err = new Error(error.message);\n err.name = error.type ?? 'SyncError';\n // Attach metadata as non-enumerable properties for debugging\n Object.defineProperty(err, 'isPermanent', {\n value: error.isPermanent ?? false,\n enumerable: false\n });\n Object.defineProperty(err, 'timestamp', {\n value: error.timestamp ?? new Date(),\n enumerable: false\n });\n syncError = err;\n }\n }\n return {\n isConnected: powerSyncStatus.connected,\n isSyncing: powerSyncStatus.uploading || powerSyncStatus.downloading,\n lastSyncedAt: powerSyncStatus.lastSyncedAt,\n pendingUploads: pendingCount,\n error: syncError\n };\n}\n\n/**\n * Convert PowerSync sync control to the V3 DataLayer SyncControl format.\n *\n * @param powerSyncControl - The sync control actions from @pol-studios/powersync\n * @returns SyncControl in @pol-studios/db format\n */\nexport function convertToDataLayerSyncControl(powerSyncControl: PowerSyncControlActions): import(\"../core/types\").SyncControl {\n return {\n triggerSync: powerSyncControl.triggerSync,\n startLiveSync: powerSyncControl.resume,\n stopLiveSync: () => {\n powerSyncControl.pause();\n },\n setScope: async (scopeName: string, values: string[]) => {\n powerSyncControl.setScope({\n type: scopeName,\n ids: values\n });\n },\n // Pending mutations - managed by the provider/context, not this bridge\n addPendingMutation: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n },\n removePendingMutation: () => {\n // No-op - actual implementation provided by PowerSyncProvider via DataLayerProvider props\n }\n };\n}\n\n// =============================================================================\n// Integration Helpers\n// =============================================================================\n\n/**\n * Create a database instance getter that works with PowerSync context.\n *\n * This is useful for integrating PowerSyncProvider with DataLayerProvider\n * by providing a way to get the database instance from the PowerSync context.\n *\n * @param getPowerSyncDb - Function to get the PowerSync database from context\n * @returns A function that returns the database or null\n */\nexport function createDatabaseGetter(getPowerSyncDb: () => AbstractPowerSyncDatabase | null): () => AbstractPowerSyncDatabase | null {\n return getPowerSyncDb;\n}\n\n/**\n * Options for setting up DataLayerProvider with PowerSync integration.\n */\nexport interface PowerSyncIntegrationOptions {\n /**\n * The PowerSync database instance from PowerSyncProvider.\n */\n database: AbstractPowerSyncDatabase | null;\n\n /**\n * Whether the PowerSync database is ready.\n */\n isReady: boolean;\n\n /**\n * Current sync status from PowerSyncProvider.\n */\n syncStatus?: PowerSyncSyncStatus;\n\n /**\n * Sync control actions from PowerSyncProvider.\n */\n syncControl?: PowerSyncControlActions;\n\n /**\n * Number of pending mutations.\n */\n pendingCount?: number;\n}\n\n/**\n * Get the powerSyncInstance prop for DataLayerProvider from PowerSync context values.\n *\n * This helper extracts the necessary values from @pol-studios/powersync hooks\n * and returns them in a format suitable for DataLayerProvider.\n *\n * @param options - The PowerSync integration options\n * @returns The powerSyncInstance to pass to DataLayerProvider, or null if not ready\n *\n * @example\n * ```typescript\n * // Inside a component wrapped with PowerSyncProvider\n * const { db, isReady } = usePowerSync();\n * const { status, pendingCount } = useSyncStatus();\n * const syncControl = useSyncControl();\n *\n * const powerSyncInstance = getPowerSyncInstance({\n * database: db,\n * isReady,\n * syncStatus: status,\n * syncControl,\n * pendingCount,\n * });\n *\n * return (\n * <DataLayerProvider\n * config={config}\n * powerSyncInstance={powerSyncInstance}\n * supabaseClient={supabase}\n * queryClient={queryClient}\n * >\n * {children}\n * </DataLayerProvider>\n * );\n * ```\n */\nexport function getPowerSyncInstance(options: PowerSyncIntegrationOptions): AbstractPowerSyncDatabase | null {\n if (!options.isReady || !options.database) {\n return null;\n }\n return options.database;\n}\n\n// =============================================================================\n// Re-export for Convenience\n// =============================================================================\n\n/**\n * Re-export the PowerSyncDatabase type from the query executor for convenience.\n * This is the minimal interface used internally by @pol-studios/db.\n */\nexport type { PowerSyncDatabase } from \"../query/executor\";"],"mappings":";;;;;AA0KA,IAAI,sBAAsC;AAoBnC,SAAS,uBAAgC;AAC9C,MAAI,wBAAwB,MAAM;AAChC,QAAI;AAGF,gBAAQ,QAAQ,wBAAwB;AACxC,4BAAsB;AAAA,IACxB,QAAQ;AACN,4BAAsB;AAAA,IACxB;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,kCAAwC;AACtD,wBAAsB;AACxB;AAYO,SAAS,4BAA4B,OAAoD;AAC9F,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,KAAK;AACX,SAAO,OAAO,GAAG,WAAW,cAAc,OAAO,GAAG,QAAQ,cAAc,OAAO,GAAG,YAAY,cAAc,OAAO,GAAG,SAAS,cAAc,OAAO,GAAG,UAAU,cAAc,OAAO,GAAG,YAAY,cAAc,OAAO,GAAG,eAAe,cAAc,OAAO,GAAG,qBAAqB,cAAc,eAAe,MAAM,mBAAmB;AACnV;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ACF;AAeO,SAAS,qBAAqB,gBAAgG;AACnI,SAAO;AACT;AAoEO,SAAS,qBAAqB,SAAwE;AAC3G,MAAI,CAAC,QAAQ,WAAW,CAAC,QAAQ,UAAU;AACzC,WAAO;AAAA,EACT;AACA,SAAO,QAAQ;AACjB;","names":[]}
|
|
@@ -1154,11 +1154,8 @@ function useSyncControl() {
|
|
|
1154
1154
|
startLiveSync: _temp2,
|
|
1155
1155
|
stopLiveSync: _temp3,
|
|
1156
1156
|
setScope: _temp4,
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
isAutoRetryPaused: false,
|
|
1160
|
-
addPendingMutation: _temp7,
|
|
1161
|
-
removePendingMutation: _temp8
|
|
1157
|
+
addPendingMutation: _temp5,
|
|
1158
|
+
removePendingMutation: _temp6
|
|
1162
1159
|
};
|
|
1163
1160
|
$[0] = t0;
|
|
1164
1161
|
} else {
|
|
@@ -1176,15 +1173,9 @@ function useSyncControl() {
|
|
|
1176
1173
|
const controls = t1;
|
|
1177
1174
|
return controls;
|
|
1178
1175
|
}
|
|
1179
|
-
function _temp8() {
|
|
1180
|
-
}
|
|
1181
|
-
function _temp7() {
|
|
1182
|
-
}
|
|
1183
1176
|
function _temp6() {
|
|
1184
|
-
console.warn("[useSyncControl] resumeAutoRetry called but PowerSync is not available");
|
|
1185
1177
|
}
|
|
1186
1178
|
function _temp5() {
|
|
1187
|
-
console.warn("[useSyncControl] pauseAutoRetry called but PowerSync is not available");
|
|
1188
1179
|
}
|
|
1189
1180
|
async function _temp4(_scopeName, _values) {
|
|
1190
1181
|
console.warn("[useSyncControl] setScope called but PowerSync is not available");
|
|
@@ -1239,4 +1230,4 @@ export {
|
|
|
1239
1230
|
useSyncControl,
|
|
1240
1231
|
useOnlineStatus
|
|
1241
1232
|
};
|
|
1242
|
-
//# sourceMappingURL=chunk-
|
|
1233
|
+
//# sourceMappingURL=chunk-ZPFZ2ZRW.js.map
|