@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,280 @@
|
|
|
1
|
+
import { A as AbstractPowerSyncDatabase } from '../types-afHtE1U_.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform Adapter Types for @pol-studios/powersync
|
|
5
|
+
*
|
|
6
|
+
* This module defines the interfaces that platform-specific adapters must implement.
|
|
7
|
+
* Consumers provide an adapter for their platform (React Native or Web) that handles
|
|
8
|
+
* platform-specific operations like file system access, async storage, and network status.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a PowerSync database instance
|
|
13
|
+
*/
|
|
14
|
+
interface DatabaseOptions {
|
|
15
|
+
/** Database file name (e.g., "pol-offline.db") */
|
|
16
|
+
dbFilename: string;
|
|
17
|
+
/** PowerSync schema definition */
|
|
18
|
+
schema: unknown;
|
|
19
|
+
/** Optional: Encryption key for SQLite */
|
|
20
|
+
encryptionKey?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Information about a file or directory
|
|
24
|
+
*/
|
|
25
|
+
interface FileInfo {
|
|
26
|
+
/** Whether the file/directory exists */
|
|
27
|
+
exists: boolean;
|
|
28
|
+
/** Size in bytes (0 for directories) */
|
|
29
|
+
size: number;
|
|
30
|
+
/** Last modification time */
|
|
31
|
+
modificationTime?: Date;
|
|
32
|
+
/** Whether this is a directory */
|
|
33
|
+
isDirectory: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* File system operations interface.
|
|
37
|
+
*
|
|
38
|
+
* React Native: Implemented using expo-file-system
|
|
39
|
+
* Web: Implemented using IndexedDB or Cache API
|
|
40
|
+
*/
|
|
41
|
+
interface FileSystemAdapter {
|
|
42
|
+
/**
|
|
43
|
+
* Read a file's contents
|
|
44
|
+
* @param uri - The file URI/path
|
|
45
|
+
* @param encoding - How to encode the result ('base64' or 'utf8')
|
|
46
|
+
*/
|
|
47
|
+
readFile(uri: string, encoding?: 'base64' | 'utf8'): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Write data to a file (creates parent directories if needed)
|
|
50
|
+
* @param uri - The file URI/path
|
|
51
|
+
* @param data - The data to write
|
|
52
|
+
* @param encoding - How the data is encoded ('base64' or 'utf8')
|
|
53
|
+
*/
|
|
54
|
+
writeFile(uri: string, data: string, encoding?: 'base64' | 'utf8'): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Delete a file
|
|
57
|
+
* @param uri - The file URI/path
|
|
58
|
+
*/
|
|
59
|
+
deleteFile(uri: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Copy a file from source to destination
|
|
62
|
+
* @param source - Source file URI/path
|
|
63
|
+
* @param destination - Destination file URI/path
|
|
64
|
+
*/
|
|
65
|
+
copyFile(source: string, destination: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Move a file from source to destination
|
|
68
|
+
* @param source - Source file URI/path
|
|
69
|
+
* @param destination - Destination file URI/path
|
|
70
|
+
*/
|
|
71
|
+
moveFile(source: string, destination: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Get information about a file or directory
|
|
74
|
+
* @param uri - The file URI/path
|
|
75
|
+
* @returns File info or null if it doesn't exist
|
|
76
|
+
*/
|
|
77
|
+
getFileInfo(uri: string): Promise<FileInfo | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Create a directory
|
|
80
|
+
* @param uri - The directory URI/path
|
|
81
|
+
* @param options - Options for directory creation
|
|
82
|
+
*/
|
|
83
|
+
makeDirectory(uri: string, options?: {
|
|
84
|
+
intermediates?: boolean;
|
|
85
|
+
}): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Get the documents directory path for this platform
|
|
88
|
+
*/
|
|
89
|
+
getDocumentsDirectory(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Get the cache directory path for this platform
|
|
92
|
+
*/
|
|
93
|
+
getCacheDirectory(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Get the free disk space in bytes
|
|
96
|
+
*/
|
|
97
|
+
getFreeDiskSpace(): Promise<number>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Key-value storage interface for persisting preferences and state.
|
|
101
|
+
*
|
|
102
|
+
* React Native: Implemented using @react-native-async-storage/async-storage
|
|
103
|
+
* Web: Implemented using localStorage
|
|
104
|
+
*/
|
|
105
|
+
interface AsyncStorageAdapter {
|
|
106
|
+
/**
|
|
107
|
+
* Get a value by key
|
|
108
|
+
* @param key - The storage key
|
|
109
|
+
* @returns The stored value or null if not found
|
|
110
|
+
*/
|
|
111
|
+
getItem(key: string): Promise<string | null>;
|
|
112
|
+
/**
|
|
113
|
+
* Set a value by key
|
|
114
|
+
* @param key - The storage key
|
|
115
|
+
* @param value - The value to store
|
|
116
|
+
*/
|
|
117
|
+
setItem(key: string, value: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Remove a value by key
|
|
120
|
+
* @param key - The storage key
|
|
121
|
+
*/
|
|
122
|
+
removeItem(key: string): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Get multiple values by keys
|
|
125
|
+
* @param keys - Array of storage keys
|
|
126
|
+
* @returns Array of [key, value] tuples
|
|
127
|
+
*/
|
|
128
|
+
multiGet(keys: string[]): Promise<[string, string | null][]>;
|
|
129
|
+
/**
|
|
130
|
+
* Set multiple values
|
|
131
|
+
* @param entries - Array of [key, value] tuples
|
|
132
|
+
*/
|
|
133
|
+
multiSet(entries: [string, string][]): Promise<void>;
|
|
134
|
+
}
|
|
135
|
+
/** Network connection types */
|
|
136
|
+
type ConnectionType = 'wifi' | 'cellular' | 'ethernet' | 'unknown' | 'none';
|
|
137
|
+
/**
|
|
138
|
+
* Network connectivity monitoring interface.
|
|
139
|
+
*
|
|
140
|
+
* React Native: Implemented using @react-native-community/netinfo
|
|
141
|
+
* Web: Implemented using navigator.onLine + online/offline events
|
|
142
|
+
*/
|
|
143
|
+
interface NetworkAdapter {
|
|
144
|
+
/**
|
|
145
|
+
* Check if the device is currently connected to the internet
|
|
146
|
+
*/
|
|
147
|
+
isConnected(): Promise<boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* Get the current connection type
|
|
150
|
+
*/
|
|
151
|
+
getConnectionType(): Promise<ConnectionType>;
|
|
152
|
+
/**
|
|
153
|
+
* Add a listener for connection status changes
|
|
154
|
+
* @param callback - Called when connection status changes
|
|
155
|
+
* @returns Unsubscribe function
|
|
156
|
+
*/
|
|
157
|
+
addConnectionListener(callback: (isConnected: boolean) => void): () => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Logging interface for debugging and monitoring.
|
|
161
|
+
* Allows consumers to use their existing logging infrastructure.
|
|
162
|
+
*/
|
|
163
|
+
interface LoggerAdapter {
|
|
164
|
+
/**
|
|
165
|
+
* Log a debug message (verbose, for development)
|
|
166
|
+
*/
|
|
167
|
+
debug(message: string, ...args: unknown[]): void;
|
|
168
|
+
/**
|
|
169
|
+
* Log an info message (general information)
|
|
170
|
+
*/
|
|
171
|
+
info(message: string, ...args: unknown[]): void;
|
|
172
|
+
/**
|
|
173
|
+
* Log a warning message (potential issues)
|
|
174
|
+
*/
|
|
175
|
+
warn(message: string, ...args: unknown[]): void;
|
|
176
|
+
/**
|
|
177
|
+
* Log an error message (failures)
|
|
178
|
+
*/
|
|
179
|
+
error(message: string, ...args: unknown[]): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Result of an image compression operation
|
|
183
|
+
*/
|
|
184
|
+
interface CompressedImage {
|
|
185
|
+
/** URI/path to the compressed image */
|
|
186
|
+
uri: string;
|
|
187
|
+
/** Width of the compressed image in pixels */
|
|
188
|
+
width: number;
|
|
189
|
+
/** Height of the compressed image in pixels */
|
|
190
|
+
height: number;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Options for image compression
|
|
194
|
+
*/
|
|
195
|
+
interface CompressionOptions {
|
|
196
|
+
/** Compression quality (0.0 to 1.0, where 1.0 is best quality) */
|
|
197
|
+
quality: number;
|
|
198
|
+
/** Maximum width in pixels (will scale down if larger) */
|
|
199
|
+
maxWidth?: number;
|
|
200
|
+
/** Maximum height in pixels (will scale down if larger) */
|
|
201
|
+
maxHeight?: number;
|
|
202
|
+
/** Output format */
|
|
203
|
+
format?: 'jpeg' | 'png' | 'webp';
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Image processing interface for attachment compression.
|
|
207
|
+
*
|
|
208
|
+
* React Native: Implemented using expo-image-manipulator
|
|
209
|
+
* Web: Implemented using canvas API
|
|
210
|
+
*
|
|
211
|
+
* This is optional - if not provided, attachments won't be compressed.
|
|
212
|
+
*/
|
|
213
|
+
interface ImageProcessorAdapter {
|
|
214
|
+
/**
|
|
215
|
+
* Compress an image
|
|
216
|
+
* @param uri - The source image URI/path
|
|
217
|
+
* @param options - Compression options
|
|
218
|
+
* @returns The compressed image result
|
|
219
|
+
*/
|
|
220
|
+
compress(uri: string, options: CompressionOptions): Promise<CompressedImage>;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Platform-specific adapter that consumers must provide.
|
|
224
|
+
* This allows the package to work across React Native and Web.
|
|
225
|
+
*
|
|
226
|
+
* @example React Native
|
|
227
|
+
* ```typescript
|
|
228
|
+
* import { createNativePlatformAdapter } from '@pol-studios/powersync/platform';
|
|
229
|
+
*
|
|
230
|
+
* const platform = createNativePlatformAdapter(logger);
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @example Web
|
|
234
|
+
* ```typescript
|
|
235
|
+
* import { createWebPlatformAdapter } from '@pol-studios/powersync/platform';
|
|
236
|
+
*
|
|
237
|
+
* const platform = createWebPlatformAdapter(logger);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
interface PlatformAdapter {
|
|
241
|
+
/**
|
|
242
|
+
* Create a PowerSync database instance for this platform.
|
|
243
|
+
*
|
|
244
|
+
* React Native: Uses PowerSyncDatabase from @powersync/react-native
|
|
245
|
+
* Web: Uses PowerSyncDatabase from @powersync/web
|
|
246
|
+
*
|
|
247
|
+
* @param options - Database creation options
|
|
248
|
+
* @returns Initialized PowerSync database
|
|
249
|
+
*/
|
|
250
|
+
createDatabase(options: DatabaseOptions): Promise<AbstractPowerSyncDatabase>;
|
|
251
|
+
/**
|
|
252
|
+
* File system operations for attachment caching.
|
|
253
|
+
*/
|
|
254
|
+
fileSystem: FileSystemAdapter;
|
|
255
|
+
/**
|
|
256
|
+
* Key-value storage for preferences and metrics persistence.
|
|
257
|
+
*/
|
|
258
|
+
storage: AsyncStorageAdapter;
|
|
259
|
+
/**
|
|
260
|
+
* Network connectivity monitoring.
|
|
261
|
+
*/
|
|
262
|
+
network: NetworkAdapter;
|
|
263
|
+
/**
|
|
264
|
+
* Logging interface.
|
|
265
|
+
*/
|
|
266
|
+
logger: LoggerAdapter;
|
|
267
|
+
/**
|
|
268
|
+
* Optional: Image compression for attachment optimization.
|
|
269
|
+
* If not provided, attachments won't be compressed.
|
|
270
|
+
*/
|
|
271
|
+
imageProcessor?: ImageProcessorAdapter;
|
|
272
|
+
}
|
|
273
|
+
/** Supported platform types */
|
|
274
|
+
type PlatformType = 'react-native' | 'web' | 'unknown';
|
|
275
|
+
/**
|
|
276
|
+
* Detect the current platform based on environment
|
|
277
|
+
*/
|
|
278
|
+
declare function detectPlatform(): PlatformType;
|
|
279
|
+
|
|
280
|
+
export { type AsyncStorageAdapter, type CompressedImage, type CompressionOptions, type ConnectionType, type DatabaseOptions, type FileInfo, type FileSystemAdapter, type ImageProcessorAdapter, type LoggerAdapter, type NetworkAdapter, type PlatformAdapter, type PlatformType, detectPlatform };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/platform/types.ts
|
|
2
|
+
function detectPlatform() {
|
|
3
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
4
|
+
return "react-native";
|
|
5
|
+
}
|
|
6
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
7
|
+
return "web";
|
|
8
|
+
}
|
|
9
|
+
return "unknown";
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
detectPlatform
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/platform/types.ts"],"sourcesContent":["/**\n * Platform Adapter Types for @pol-studios/powersync\n *\n * This module defines the interfaces that platform-specific adapters must implement.\n * Consumers provide an adapter for their platform (React Native or Web) that handles\n * platform-specific operations like file system access, async storage, and network status.\n */\n\nimport type { AbstractPowerSyncDatabase } from '../core/types';\n\n// ─── Database Factory Options ────────────────────────────────────────────────\n\n/**\n * Options for creating a PowerSync database instance\n */\nexport interface DatabaseOptions {\n /** Database file name (e.g., \"pol-offline.db\") */\n dbFilename: string;\n /** PowerSync schema definition */\n schema: unknown; // Schema type from @powersync/common\n /** Optional: Encryption key for SQLite */\n encryptionKey?: string;\n}\n\n// ─── File System Adapter ─────────────────────────────────────────────────────\n\n/**\n * Information about a file or directory\n */\nexport interface FileInfo {\n /** Whether the file/directory exists */\n exists: boolean;\n /** Size in bytes (0 for directories) */\n size: number;\n /** Last modification time */\n modificationTime?: Date;\n /** Whether this is a directory */\n isDirectory: boolean;\n}\n\n/**\n * File system operations interface.\n *\n * React Native: Implemented using expo-file-system\n * Web: Implemented using IndexedDB or Cache API\n */\nexport interface FileSystemAdapter {\n /**\n * Read a file's contents\n * @param uri - The file URI/path\n * @param encoding - How to encode the result ('base64' or 'utf8')\n */\n readFile(uri: string, encoding?: 'base64' | 'utf8'): Promise<string>;\n\n /**\n * Write data to a file (creates parent directories if needed)\n * @param uri - The file URI/path\n * @param data - The data to write\n * @param encoding - How the data is encoded ('base64' or 'utf8')\n */\n writeFile(uri: string, data: string, encoding?: 'base64' | 'utf8'): Promise<void>;\n\n /**\n * Delete a file\n * @param uri - The file URI/path\n */\n deleteFile(uri: string): Promise<void>;\n\n /**\n * Copy a file from source to destination\n * @param source - Source file URI/path\n * @param destination - Destination file URI/path\n */\n copyFile(source: string, destination: string): Promise<void>;\n\n /**\n * Move a file from source to destination\n * @param source - Source file URI/path\n * @param destination - Destination file URI/path\n */\n moveFile(source: string, destination: string): Promise<void>;\n\n /**\n * Get information about a file or directory\n * @param uri - The file URI/path\n * @returns File info or null if it doesn't exist\n */\n getFileInfo(uri: string): Promise<FileInfo | null>;\n\n /**\n * Create a directory\n * @param uri - The directory URI/path\n * @param options - Options for directory creation\n */\n makeDirectory(uri: string, options?: { intermediates?: boolean }): Promise<void>;\n\n /**\n * Get the documents directory path for this platform\n */\n getDocumentsDirectory(): string;\n\n /**\n * Get the cache directory path for this platform\n */\n getCacheDirectory(): string;\n\n /**\n * Get the free disk space in bytes\n */\n getFreeDiskSpace(): Promise<number>;\n}\n\n// ─── Async Storage Adapter ───────────────────────────────────────────────────\n\n/**\n * Key-value storage interface for persisting preferences and state.\n *\n * React Native: Implemented using @react-native-async-storage/async-storage\n * Web: Implemented using localStorage\n */\nexport interface AsyncStorageAdapter {\n /**\n * Get a value by key\n * @param key - The storage key\n * @returns The stored value or null if not found\n */\n getItem(key: string): Promise<string | null>;\n\n /**\n * Set a value by key\n * @param key - The storage key\n * @param value - The value to store\n */\n setItem(key: string, value: string): Promise<void>;\n\n /**\n * Remove a value by key\n * @param key - The storage key\n */\n removeItem(key: string): Promise<void>;\n\n /**\n * Get multiple values by keys\n * @param keys - Array of storage keys\n * @returns Array of [key, value] tuples\n */\n multiGet(keys: string[]): Promise<[string, string | null][]>;\n\n /**\n * Set multiple values\n * @param entries - Array of [key, value] tuples\n */\n multiSet(entries: [string, string][]): Promise<void>;\n}\n\n// ─── Network Adapter ─────────────────────────────────────────────────────────\n\n/** Network connection types */\nexport type ConnectionType = 'wifi' | 'cellular' | 'ethernet' | 'unknown' | 'none';\n\n/**\n * Network connectivity monitoring interface.\n *\n * React Native: Implemented using @react-native-community/netinfo\n * Web: Implemented using navigator.onLine + online/offline events\n */\nexport interface NetworkAdapter {\n /**\n * Check if the device is currently connected to the internet\n */\n isConnected(): Promise<boolean>;\n\n /**\n * Get the current connection type\n */\n getConnectionType(): Promise<ConnectionType>;\n\n /**\n * Add a listener for connection status changes\n * @param callback - Called when connection status changes\n * @returns Unsubscribe function\n */\n addConnectionListener(callback: (isConnected: boolean) => void): () => void;\n}\n\n// ─── Logger Adapter ──────────────────────────────────────────────────────────\n\n/**\n * Logging interface for debugging and monitoring.\n * Allows consumers to use their existing logging infrastructure.\n */\nexport interface LoggerAdapter {\n /**\n * Log a debug message (verbose, for development)\n */\n debug(message: string, ...args: unknown[]): void;\n\n /**\n * Log an info message (general information)\n */\n info(message: string, ...args: unknown[]): void;\n\n /**\n * Log a warning message (potential issues)\n */\n warn(message: string, ...args: unknown[]): void;\n\n /**\n * Log an error message (failures)\n */\n error(message: string, ...args: unknown[]): void;\n}\n\n// ─── Image Processor Adapter ─────────────────────────────────────────────────\n\n/**\n * Result of an image compression operation\n */\nexport interface CompressedImage {\n /** URI/path to the compressed image */\n uri: string;\n /** Width of the compressed image in pixels */\n width: number;\n /** Height of the compressed image in pixels */\n height: number;\n}\n\n/**\n * Options for image compression\n */\nexport interface CompressionOptions {\n /** Compression quality (0.0 to 1.0, where 1.0 is best quality) */\n quality: number;\n /** Maximum width in pixels (will scale down if larger) */\n maxWidth?: number;\n /** Maximum height in pixels (will scale down if larger) */\n maxHeight?: number;\n /** Output format */\n format?: 'jpeg' | 'png' | 'webp';\n}\n\n/**\n * Image processing interface for attachment compression.\n *\n * React Native: Implemented using expo-image-manipulator\n * Web: Implemented using canvas API\n *\n * This is optional - if not provided, attachments won't be compressed.\n */\nexport interface ImageProcessorAdapter {\n /**\n * Compress an image\n * @param uri - The source image URI/path\n * @param options - Compression options\n * @returns The compressed image result\n */\n compress(uri: string, options: CompressionOptions): Promise<CompressedImage>;\n}\n\n// ─── Main Platform Adapter Interface ─────────────────────────────────────────\n\n/**\n * Platform-specific adapter that consumers must provide.\n * This allows the package to work across React Native and Web.\n *\n * @example React Native\n * ```typescript\n * import { createNativePlatformAdapter } from '@pol-studios/powersync/platform';\n *\n * const platform = createNativePlatformAdapter(logger);\n * ```\n *\n * @example Web\n * ```typescript\n * import { createWebPlatformAdapter } from '@pol-studios/powersync/platform';\n *\n * const platform = createWebPlatformAdapter(logger);\n * ```\n */\nexport interface PlatformAdapter {\n /**\n * Create a PowerSync database instance for this platform.\n *\n * React Native: Uses PowerSyncDatabase from @powersync/react-native\n * Web: Uses PowerSyncDatabase from @powersync/web\n *\n * @param options - Database creation options\n * @returns Initialized PowerSync database\n */\n createDatabase(options: DatabaseOptions): Promise<AbstractPowerSyncDatabase>;\n\n /**\n * File system operations for attachment caching.\n */\n fileSystem: FileSystemAdapter;\n\n /**\n * Key-value storage for preferences and metrics persistence.\n */\n storage: AsyncStorageAdapter;\n\n /**\n * Network connectivity monitoring.\n */\n network: NetworkAdapter;\n\n /**\n * Logging interface.\n */\n logger: LoggerAdapter;\n\n /**\n * Optional: Image compression for attachment optimization.\n * If not provided, attachments won't be compressed.\n */\n imageProcessor?: ImageProcessorAdapter;\n}\n\n// ─── Platform Detection ──────────────────────────────────────────────────────\n\n/** Supported platform types */\nexport type PlatformType = 'react-native' | 'web' | 'unknown';\n\n/**\n * Detect the current platform based on environment\n */\nexport function detectPlatform(): PlatformType {\n // Check for React Native\n if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {\n return 'react-native';\n }\n\n // Check for browser environment\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n return 'web';\n }\n\n return 'unknown';\n}\n"],"mappings":";AAsUO,SAAS,iBAA+B;AAE7C,MAAI,OAAO,cAAc,eAAe,UAAU,YAAY,eAAe;AAC3E,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACpE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LoggerAdapter, PlatformAdapter } from './index.js';
|
|
2
|
+
import '../types-afHtE1U_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React Native Platform Adapter for @pol-studios/powersync
|
|
6
|
+
*
|
|
7
|
+
* Implements the PlatformAdapter interface using React Native specific APIs:
|
|
8
|
+
* - @powersync/react-native for SQLite database
|
|
9
|
+
* - expo-file-system for file operations
|
|
10
|
+
* - @react-native-async-storage/async-storage for key-value storage
|
|
11
|
+
* - @react-native-community/netinfo for network monitoring
|
|
12
|
+
* - expo-image-manipulator for image compression
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a React Native platform adapter
|
|
17
|
+
*
|
|
18
|
+
* @param logger - Logger implementation to use
|
|
19
|
+
* @returns Platform adapter configured for React Native
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { createNativePlatformAdapter } from '@pol-studios/powersync/platform';
|
|
24
|
+
*
|
|
25
|
+
* const logger = {
|
|
26
|
+
* debug: console.log,
|
|
27
|
+
* info: console.log,
|
|
28
|
+
* warn: console.warn,
|
|
29
|
+
* error: console.error,
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* const platform = createNativePlatformAdapter(logger);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createNativePlatformAdapter(logger: LoggerAdapter): PlatformAdapter;
|
|
36
|
+
|
|
37
|
+
export { LoggerAdapter, PlatformAdapter, createNativePlatformAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LoggerAdapter, PlatformAdapter } from './index.js';
|
|
2
|
+
import '../types-afHtE1U_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Web Platform Adapter for @pol-studios/powersync
|
|
6
|
+
*
|
|
7
|
+
* Implements the PlatformAdapter interface using Web APIs:
|
|
8
|
+
* - @powersync/web for SQLite database (via wa-sqlite)
|
|
9
|
+
* - IndexedDB for file storage (via idb-keyval pattern)
|
|
10
|
+
* - localStorage for key-value storage
|
|
11
|
+
* - navigator.onLine + events for network monitoring
|
|
12
|
+
* - Canvas API for image compression
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a Web platform adapter
|
|
17
|
+
*
|
|
18
|
+
* @param logger - Logger implementation to use
|
|
19
|
+
* @returns Platform adapter configured for Web/PWA
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { createWebPlatformAdapter } from '@pol-studios/powersync/platform';
|
|
24
|
+
*
|
|
25
|
+
* const logger = {
|
|
26
|
+
* debug: console.log,
|
|
27
|
+
* info: console.log,
|
|
28
|
+
* warn: console.warn,
|
|
29
|
+
* error: console.error,
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* const platform = createWebPlatformAdapter(logger);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createWebPlatformAdapter(logger: LoggerAdapter): PlatformAdapter;
|
|
36
|
+
|
|
37
|
+
export { LoggerAdapter, PlatformAdapter, createWebPlatformAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|