@tursodatabase/sync-react-native 0.5.0-pre.4

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.
Files changed (72) hide show
  1. package/README.md +117 -0
  2. package/android/CMakeLists.txt +53 -0
  3. package/android/build.gradle +84 -0
  4. package/android/cpp-adapter.cpp +49 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/turso/sync/reactnative/TursoBridge.java +44 -0
  7. package/android/src/main/java/com/turso/sync/reactnative/TursoModule.java +82 -0
  8. package/android/src/main/java/com/turso/sync/reactnative/TursoPackage.java +29 -0
  9. package/cpp/TursoConnectionHostObject.cpp +179 -0
  10. package/cpp/TursoConnectionHostObject.h +52 -0
  11. package/cpp/TursoDatabaseHostObject.cpp +98 -0
  12. package/cpp/TursoDatabaseHostObject.h +49 -0
  13. package/cpp/TursoHostObject.cpp +561 -0
  14. package/cpp/TursoHostObject.h +24 -0
  15. package/cpp/TursoStatementHostObject.cpp +414 -0
  16. package/cpp/TursoStatementHostObject.h +65 -0
  17. package/cpp/TursoSyncChangesHostObject.cpp +41 -0
  18. package/cpp/TursoSyncChangesHostObject.h +52 -0
  19. package/cpp/TursoSyncDatabaseHostObject.cpp +328 -0
  20. package/cpp/TursoSyncDatabaseHostObject.h +61 -0
  21. package/cpp/TursoSyncIoItemHostObject.cpp +304 -0
  22. package/cpp/TursoSyncIoItemHostObject.h +52 -0
  23. package/cpp/TursoSyncOperationHostObject.cpp +168 -0
  24. package/cpp/TursoSyncOperationHostObject.h +53 -0
  25. package/ios/TursoModule.h +8 -0
  26. package/ios/TursoModule.mm +95 -0
  27. package/lib/commonjs/Database.js +445 -0
  28. package/lib/commonjs/Database.js.map +1 -0
  29. package/lib/commonjs/Statement.js +339 -0
  30. package/lib/commonjs/Statement.js.map +1 -0
  31. package/lib/commonjs/index.js +229 -0
  32. package/lib/commonjs/index.js.map +1 -0
  33. package/lib/commonjs/internal/asyncOperation.js +124 -0
  34. package/lib/commonjs/internal/asyncOperation.js.map +1 -0
  35. package/lib/commonjs/internal/ioProcessor.js +315 -0
  36. package/lib/commonjs/internal/ioProcessor.js.map +1 -0
  37. package/lib/commonjs/package.json +1 -0
  38. package/lib/commonjs/types.js +133 -0
  39. package/lib/commonjs/types.js.map +1 -0
  40. package/lib/module/Database.js +441 -0
  41. package/lib/module/Database.js.map +1 -0
  42. package/lib/module/Statement.js +335 -0
  43. package/lib/module/Statement.js.map +1 -0
  44. package/lib/module/index.js +205 -0
  45. package/lib/module/index.js.map +1 -0
  46. package/lib/module/internal/asyncOperation.js +116 -0
  47. package/lib/module/internal/asyncOperation.js.map +1 -0
  48. package/lib/module/internal/ioProcessor.js +309 -0
  49. package/lib/module/internal/ioProcessor.js.map +1 -0
  50. package/lib/module/package.json +1 -0
  51. package/lib/module/types.js +163 -0
  52. package/lib/module/types.js.map +1 -0
  53. package/lib/typescript/Database.d.ts +140 -0
  54. package/lib/typescript/Database.d.ts.map +1 -0
  55. package/lib/typescript/Statement.d.ts +105 -0
  56. package/lib/typescript/Statement.d.ts.map +1 -0
  57. package/lib/typescript/index.d.ts +175 -0
  58. package/lib/typescript/index.d.ts.map +1 -0
  59. package/lib/typescript/internal/asyncOperation.d.ts +39 -0
  60. package/lib/typescript/internal/asyncOperation.d.ts.map +1 -0
  61. package/lib/typescript/internal/ioProcessor.d.ts +48 -0
  62. package/lib/typescript/internal/ioProcessor.d.ts.map +1 -0
  63. package/lib/typescript/types.d.ts +316 -0
  64. package/lib/typescript/types.d.ts.map +1 -0
  65. package/package.json +97 -0
  66. package/src/Database.ts +480 -0
  67. package/src/Statement.ts +372 -0
  68. package/src/index.ts +240 -0
  69. package/src/internal/asyncOperation.ts +147 -0
  70. package/src/internal/ioProcessor.ts +328 -0
  71. package/src/types.ts +391 -0
  72. package/turso-sync-react-native.podspec +56 -0
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * IO Processor
5
+ *
6
+ * Processes IO requests from the sync engine using JavaScript APIs.
7
+ * This is the key benefit of the thin JSI layer - all IO is handled by
8
+ * React Native's standard APIs (fetch, file system), not C++ code.
9
+ *
10
+ * Benefits:
11
+ * - Network requests visible in React Native debugger
12
+ * - Can customize fetch (add proxies, custom headers, etc.)
13
+ * - Easier to test (can mock fetch)
14
+ * - Uses platform-native networking (not C++ HTTP libraries)
15
+ */
16
+
17
+ /**
18
+ * IO context contains auth and URL information for HTTP requests
19
+ */
20
+
21
+ // Allow users to optionally override file system implementation
22
+ let fsReadFileOverride = null;
23
+ let fsWriteFileOverride = null;
24
+
25
+ /**
26
+ * Set custom file system implementation (optional)
27
+ * By default, uses built-in JSI file system functions.
28
+ * Only call this if you need custom behavior (e.g., encryption, compression).
29
+ *
30
+ * @param readFile - Function to read file as Uint8Array
31
+ * @param writeFile - Function to write Uint8Array to file
32
+ */
33
+ export function setFileSystemImpl(readFile, writeFile) {
34
+ fsReadFileOverride = readFile;
35
+ fsWriteFileOverride = writeFile;
36
+ }
37
+
38
+ /**
39
+ * Read file using custom implementation or built-in JSI function
40
+ */
41
+ async function fsReadFile(path) {
42
+ if (fsReadFileOverride) {
43
+ return fsReadFileOverride(path);
44
+ }
45
+
46
+ // Use built-in JSI function
47
+ const buffer = __TursoProxy.fsReadFile(path);
48
+ if (buffer === null) {
49
+ // File not found - return empty
50
+ return new Uint8Array(0);
51
+ }
52
+ return new Uint8Array(buffer);
53
+ }
54
+
55
+ /**
56
+ * Write file using custom implementation or built-in JSI function
57
+ */
58
+ async function fsWriteFile(path, data) {
59
+ if (fsWriteFileOverride) {
60
+ return fsWriteFileOverride(path, data);
61
+ }
62
+
63
+ // Use built-in JSI function
64
+ __TursoProxy.fsWriteFile(path, data.buffer);
65
+ }
66
+
67
+ /**
68
+ * Process a single IO item
69
+ *
70
+ * @param item - The IO item to process
71
+ * @param context - IO context with auth and URL information
72
+ */
73
+ export async function processIoItem(item, context) {
74
+ try {
75
+ const kind = item.getKind();
76
+ switch (kind) {
77
+ case 'HTTP':
78
+ await processHttpRequest(item, context);
79
+ break;
80
+ case 'FULL_READ':
81
+ await processFullRead(item);
82
+ break;
83
+ case 'FULL_WRITE':
84
+ await processFullWrite(item);
85
+ break;
86
+ case 'NONE':
87
+ default:
88
+ // Nothing to do
89
+ item.done();
90
+ break;
91
+ }
92
+ } catch (error) {
93
+ // Poison the item with error message
94
+ const errorMsg = error instanceof Error ? error.message : String(error);
95
+ item.poison(errorMsg);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Normalize URL from libsql:// to https://
101
+ */
102
+ function normalizeUrl(url) {
103
+ if (url.startsWith('libsql://')) {
104
+ return url.replace('libsql://', 'https://');
105
+ }
106
+ return url;
107
+ }
108
+
109
+ /**
110
+ * Get auth token from context (handles both string and function)
111
+ */
112
+ function getAuthToken(context) {
113
+ if (!context.authToken) {
114
+ return null;
115
+ }
116
+ if (typeof context.authToken === 'function') {
117
+ return context.authToken();
118
+ }
119
+ return context.authToken;
120
+ }
121
+
122
+ /**
123
+ * Process an HTTP request using fetch()
124
+ *
125
+ * @param item - The IO item
126
+ * @param context - IO context with auth and URL information
127
+ */
128
+ async function processHttpRequest(item, context) {
129
+ const request = item.getHttpRequest();
130
+
131
+ // Build full URL
132
+ let fullUrl = '';
133
+ if (request.url) {
134
+ // Normalize URL (libsql:// -> https://)
135
+ let baseUrl = normalizeUrl(request.url);
136
+
137
+ // Combine base URL with path if path is provided
138
+ if (request.path) {
139
+ // Ensure proper URL formatting (avoid double slashes, ensure single slash)
140
+ if (baseUrl.endsWith('/') && request.path.startsWith('/')) {
141
+ fullUrl = baseUrl + request.path.substring(1);
142
+ } else if (!baseUrl.endsWith('/') && !request.path.startsWith('/')) {
143
+ fullUrl = baseUrl + '/' + request.path;
144
+ } else {
145
+ fullUrl = baseUrl + request.path;
146
+ }
147
+ } else {
148
+ fullUrl = baseUrl;
149
+ }
150
+ } else if (request.path) {
151
+ // Path without base URL - shouldn't happen
152
+ throw new Error('HTTP request missing base URL');
153
+ } else {
154
+ throw new Error('HTTP request missing URL and path');
155
+ }
156
+
157
+ // Build fetch options
158
+ const options = {
159
+ method: request.method,
160
+ headers: {
161
+ ...request.headers
162
+ }
163
+ };
164
+
165
+ // Inject Authorization header if auth token is available
166
+ const authToken = getAuthToken(context);
167
+ if (authToken) {
168
+ options.headers['Authorization'] = `Bearer ${authToken}`;
169
+ }
170
+
171
+ // Add body if present
172
+ if (request.body) {
173
+ options.body = request.body;
174
+ }
175
+
176
+ // Debug logging for HTTP requests
177
+ console.log('[Turso HTTP] Request:', {
178
+ method: request.method,
179
+ url: fullUrl,
180
+ hasBody: !!request.body,
181
+ bodySize: request.body ? request.body.byteLength : 0,
182
+ headers: options.headers
183
+ });
184
+
185
+ // Make the HTTP request
186
+ let response;
187
+ try {
188
+ response = await fetch(fullUrl, options);
189
+ } catch (e) {
190
+ // Detailed error logging
191
+ const errorDetails = {
192
+ url: fullUrl,
193
+ method: request.method,
194
+ hasBody: !!request.body,
195
+ bodySize: request.body ? request.body.byteLength : 0,
196
+ bodyType: request.body ? Object.prototype.toString.call(options.body) : 'none',
197
+ error: e instanceof Error ? {
198
+ message: e.message,
199
+ name: e.name,
200
+ stack: e.stack
201
+ } : String(e)
202
+ };
203
+ console.error('[Turso HTTP] Request failed:', JSON.stringify(errorDetails, null, 2));
204
+ throw new Error(`HTTP request failed: ${e instanceof Error ? e.message : String(e)}. URL: ${fullUrl}, Method: ${request.method}, Body size: ${request.body ? request.body.byteLength : 0} bytes`);
205
+ }
206
+
207
+ // Set status code
208
+ item.setStatus(response.status);
209
+
210
+ // Read response body and push to item
211
+ const responseData = await response.arrayBuffer();
212
+ if (responseData.byteLength > 0) {
213
+ item.pushBuffer(responseData);
214
+ }
215
+
216
+ // Mark as done
217
+ item.done();
218
+ }
219
+
220
+ /**
221
+ * Process a full read request (atomic file read)
222
+ *
223
+ * @param item - The IO item
224
+ */
225
+ async function processFullRead(item) {
226
+ const path = item.getFullReadPath();
227
+ try {
228
+ // Read the file (uses built-in JSI function or custom override)
229
+ const data = await fsReadFile(path);
230
+
231
+ // Push data to item
232
+ if (data.byteLength > 0) {
233
+ item.pushBuffer(data.buffer);
234
+ }
235
+
236
+ // Mark as done
237
+ item.done();
238
+ } catch (error) {
239
+ // File not found is okay - treat as empty file
240
+ if (isFileNotFoundError(error)) {
241
+ // Empty file - just mark as done without pushing data
242
+ item.done();
243
+ } else {
244
+ throw error;
245
+ }
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Process a full write request (atomic file write)
251
+ *
252
+ * @param item - The IO item
253
+ */
254
+ async function processFullWrite(item) {
255
+ const request = item.getFullWriteRequest();
256
+
257
+ // Convert ArrayBuffer to Uint8Array
258
+ const data = request.content ? new Uint8Array(request.content) : new Uint8Array(0);
259
+
260
+ // Write the file atomically (uses built-in JSI function or custom override)
261
+ await fsWriteFile(request.path, data);
262
+
263
+ // Mark as done
264
+ item.done();
265
+ }
266
+
267
+ /**
268
+ * Check if error is a file-not-found error
269
+ *
270
+ * @param error - The error to check
271
+ * @returns true if file not found
272
+ */
273
+ function isFileNotFoundError(error) {
274
+ if (error instanceof Error) {
275
+ const message = error.message.toLowerCase();
276
+ return message.includes('enoent') || message.includes('not found') || message.includes('no such file');
277
+ }
278
+ return false;
279
+ }
280
+
281
+ /**
282
+ * Drain all pending IO items from sync engine queue and process them.
283
+ * This is called during statement execution when partial sync needs to load missing pages.
284
+ *
285
+ * @param database - The native sync database
286
+ * @param context - IO context with auth and URL information
287
+ */
288
+ export async function drainSyncIo(database, context) {
289
+ const promises = [];
290
+
291
+ // Take all available IO items from the queue
292
+ while (true) {
293
+ const ioItem = database.ioTakeItem();
294
+ if (!ioItem) {
295
+ break; // No more items
296
+ }
297
+
298
+ // Process each item
299
+ promises.push(processIoItem(ioItem, context));
300
+ }
301
+
302
+ // Wait for all IO operations to complete
303
+ await Promise.all(promises);
304
+
305
+ // Step callbacks after IO processing
306
+ // This allows the sync engine to run any post-IO callbacks
307
+ database.ioStepCallbacks();
308
+ }
309
+ //# sourceMappingURL=ioProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fsReadFileOverride","fsWriteFileOverride","setFileSystemImpl","readFile","writeFile","fsReadFile","path","buffer","__TursoProxy","Uint8Array","fsWriteFile","data","processIoItem","item","context","kind","getKind","processHttpRequest","processFullRead","processFullWrite","done","error","errorMsg","Error","message","String","poison","normalizeUrl","url","startsWith","replace","getAuthToken","authToken","request","getHttpRequest","fullUrl","baseUrl","endsWith","substring","options","method","headers","body","console","log","hasBody","bodySize","byteLength","response","fetch","e","errorDetails","bodyType","Object","prototype","toString","call","name","stack","JSON","stringify","setStatus","status","responseData","arrayBuffer","pushBuffer","getFullReadPath","isFileNotFoundError","getFullWriteRequest","content","toLowerCase","includes","drainSyncIo","database","promises","ioItem","ioTakeItem","push","Promise","all","ioStepCallbacks"],"sourceRoot":"../../../src","sources":["internal/ioProcessor.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;;AAQA;AACA,IAAIA,kBAAkE,GAAG,IAAI;AAC7E,IAAIC,mBAA+E,GAAG,IAAI;;AAE1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAC/BC,QAA+C,EAC/CC,SAA4D,EACtD;EACNJ,kBAAkB,GAAGG,QAAQ;EAC7BF,mBAAmB,GAAGG,SAAS;AACjC;;AAEA;AACA;AACA;AACA,eAAeC,UAAUA,CAACC,IAAY,EAAuB;EAC3D,IAAIN,kBAAkB,EAAE;IACtB,OAAOA,kBAAkB,CAACM,IAAI,CAAC;EACjC;;EAEA;EACA,MAAMC,MAAM,GAAGC,YAAY,CAACH,UAAU,CAACC,IAAI,CAAC;EAC5C,IAAIC,MAAM,KAAK,IAAI,EAAE;IACnB;IACA,OAAO,IAAIE,UAAU,CAAC,CAAC,CAAC;EAC1B;EACA,OAAO,IAAIA,UAAU,CAACF,MAAM,CAAC;AAC/B;;AAEA;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AAE7D,OAAO,CAAC,CAAC;EAC/C;;EAEA;EACA,MAAMgE,OAAO,CAACC,GAAG,CAACL,QAAQ,CAAC;;EAE3B;EACA;EACAD,QAAQ,CAACO,eAAe,CAAC,CAAC;AAC5B","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Turso React Native SDK-KIT Types
5
+ *
6
+ * Clean TypeScript types matching the SDK-KIT C API patterns.
7
+ * All logic lives in TypeScript or Rust - the C++ layer is just a thin bridge.
8
+ */
9
+
10
+ // ============================================================================
11
+ // Core SDK-KIT Types (Local Database)
12
+ // ============================================================================
13
+
14
+ /**
15
+ * Native database interface (local-only)
16
+ * Thin wrapper around TursoDatabaseHostObject
17
+ */
18
+
19
+ /**
20
+ * Native connection interface
21
+ * Thin wrapper around TursoConnectionHostObject
22
+ */
23
+
24
+ /**
25
+ * Native statement interface
26
+ * Thin wrapper around TursoStatementHostObject
27
+ */
28
+
29
+ // ============================================================================
30
+ // Sync SDK-KIT Types (Embedded Replica)
31
+ // ============================================================================
32
+
33
+ /**
34
+ * Native sync database interface (embedded replica)
35
+ * Thin wrapper around TursoSyncDatabaseHostObject
36
+ */
37
+
38
+ /**
39
+ * Native sync operation interface
40
+ * Thin wrapper around TursoSyncOperationHostObject
41
+ * Represents an async operation that must be driven by calling resume()
42
+ */
43
+
44
+ /**
45
+ * Native sync IO item interface
46
+ * Thin wrapper around TursoSyncIoItemHostObject
47
+ * Represents an IO request that JavaScript must process using fetch() or fs
48
+ */
49
+
50
+ /**
51
+ * Native sync changes interface
52
+ * Thin wrapper around TursoSyncChangesHostObject
53
+ * Represents changes fetched from remote (opaque, passed to applyChanges)
54
+ */
55
+
56
+ // ============================================================================
57
+ // Turso Status Codes
58
+ // ============================================================================
59
+
60
+ export let TursoStatus = /*#__PURE__*/function (TursoStatus) {
61
+ TursoStatus[TursoStatus["OK"] = 0] = "OK";
62
+ TursoStatus[TursoStatus["DONE"] = 1] = "DONE";
63
+ TursoStatus[TursoStatus["ROW"] = 2] = "ROW";
64
+ TursoStatus[TursoStatus["IO"] = 3] = "IO";
65
+ TursoStatus[TursoStatus["BUSY"] = 4] = "BUSY";
66
+ TursoStatus[TursoStatus["INTERRUPT"] = 5] = "INTERRUPT";
67
+ TursoStatus[TursoStatus["BUSY_SNAPSHOT"] = 6] = "BUSY_SNAPSHOT";
68
+ TursoStatus[TursoStatus["ERROR"] = 127] = "ERROR";
69
+ TursoStatus[TursoStatus["MISUSE"] = 128] = "MISUSE";
70
+ TursoStatus[TursoStatus["CONSTRAINT"] = 129] = "CONSTRAINT";
71
+ TursoStatus[TursoStatus["READONLY"] = 130] = "READONLY";
72
+ TursoStatus[TursoStatus["DATABASE_FULL"] = 131] = "DATABASE_FULL";
73
+ TursoStatus[TursoStatus["NOTADB"] = 132] = "NOTADB";
74
+ TursoStatus[TursoStatus["CORRUPT"] = 133] = "CORRUPT";
75
+ TursoStatus[TursoStatus["IOERR"] = 134] = "IOERR";
76
+ return TursoStatus;
77
+ }({});
78
+
79
+ // ============================================================================
80
+ // Turso Value Types
81
+ // ============================================================================
82
+
83
+ export let TursoType = /*#__PURE__*/function (TursoType) {
84
+ TursoType[TursoType["UNKNOWN"] = 0] = "UNKNOWN";
85
+ TursoType[TursoType["INTEGER"] = 1] = "INTEGER";
86
+ TursoType[TursoType["REAL"] = 2] = "REAL";
87
+ TursoType[TursoType["TEXT"] = 3] = "TEXT";
88
+ TursoType[TursoType["BLOB"] = 4] = "BLOB";
89
+ TursoType[TursoType["NULL"] = 5] = "NULL";
90
+ return TursoType;
91
+ }({});
92
+
93
+ // ============================================================================
94
+ // Sync Operation Result Types
95
+ // ============================================================================
96
+
97
+ export let SyncOperationResultType = /*#__PURE__*/function (SyncOperationResultType) {
98
+ SyncOperationResultType[SyncOperationResultType["NONE"] = 0] = "NONE";
99
+ SyncOperationResultType[SyncOperationResultType["CONNECTION"] = 1] = "CONNECTION";
100
+ SyncOperationResultType[SyncOperationResultType["CHANGES"] = 2] = "CHANGES";
101
+ SyncOperationResultType[SyncOperationResultType["STATS"] = 3] = "STATS";
102
+ return SyncOperationResultType;
103
+ }({});
104
+
105
+ // ============================================================================
106
+ // Public API Types (High-level TypeScript)
107
+ // ============================================================================
108
+
109
+ /**
110
+ * Supported SQLite value types for the public API
111
+ */
112
+
113
+ /**
114
+ * Parameters that can be bound to SQL statements
115
+ */
116
+
117
+ /**
118
+ * Result of a run() or exec() operation
119
+ */
120
+
121
+ /**
122
+ * A row returned from a query
123
+ */
124
+
125
+ /**
126
+ * Encryption options (matches JavaScript bindings)
127
+ */
128
+
129
+ /**
130
+ * Database options (matches JavaScript bindings)
131
+ * Single unified config for both local and sync databases
132
+ */
133
+
134
+ /**
135
+ * Sync stats returned by stats() operation
136
+ */
137
+
138
+ /**
139
+ * HTTP request from sync engine
140
+ */
141
+
142
+ /**
143
+ * Full write request from sync engine
144
+ */
145
+
146
+ // ============================================================================
147
+ // Global Turso Proxy Interface
148
+ // ============================================================================
149
+
150
+ /**
151
+ * Native proxy interface exposed via JSI
152
+ */
153
+
154
+ /**
155
+ * Native module interface (React Native bridge)
156
+ */
157
+
158
+ /**
159
+ * Global __TursoProxy object injected by native code
160
+ */
161
+
162
+ export {};
163
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TursoStatus","TursoType","SyncOperationResultType"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;;AAgCA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;;AAEA,WAAYA,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;;AAkBvB;AACA;AACA;;AAEA,WAAYC,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;;AASrB;AACA;AACA;;AAEA,WAAYC,uBAAuB,0BAAvBA,uBAAuB;EAAvBA,uBAAuB,CAAvBA,uBAAuB;EAAvBA,uBAAuB,CAAvBA,uBAAuB;EAAvBA,uBAAuB,CAAvBA,uBAAuB;EAAvBA,uBAAuB,CAAvBA,uBAAuB;EAAA,OAAvBA,uBAAuB;AAAA;;AAOnC;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAQA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AACA;;AAgFA;AACA;AACA;;AAYA;AACA;AACA;;AASA;AACA;AACA;;AAMA;AACA;AACA;;AAEA;AACA;AACA;;AAUA;AACA;AACA;;AAWA;AACA;AACA;;AAMA","ignoreList":[]}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Database
3
+ *
4
+ * Unified high-level API for both local and sync databases.
5
+ * Constructor determines whether to use local-only or sync mode based on config.
6
+ */
7
+ import { Statement } from './Statement';
8
+ import type { Row, RunResult, BindParams, DatabaseOpts, SyncStats } from './types';
9
+ /**
10
+ * Database class - works for both local-only and sync databases
11
+ *
12
+ * All database operations are async to properly handle IO requirements:
13
+ * - For local databases: async allows yielding to JS event loop
14
+ * - For sync databases: async required for network operations
15
+ * - For partial sync: async required to load missing pages on-demand
16
+ */
17
+ export declare class Database {
18
+ private _opts;
19
+ private _nativeDb;
20
+ private _nativeSyncDb;
21
+ private _connection;
22
+ private _isSync;
23
+ private _connected;
24
+ private _closed;
25
+ private _extraIo?;
26
+ private _ioContext?;
27
+ /**
28
+ * Create a new database (doesn't connect yet - call connect())
29
+ *
30
+ * @param opts - Database options
31
+ */
32
+ constructor(opts: DatabaseOpts);
33
+ /**
34
+ * Connect to the database (matches JavaScript bindings)
35
+ * For local databases: opens immediately
36
+ * For sync databases: bootstraps if needed
37
+ */
38
+ connect(): Promise<void>;
39
+ /**
40
+ * Initialize local-only database
41
+ */
42
+ private initLocalDatabase;
43
+ /**
44
+ * Initialize sync database
45
+ */
46
+ private initSyncDatabase;
47
+ /**
48
+ * Prepare a SQL statement
49
+ *
50
+ * @param sql - SQL statement to prepare
51
+ * @returns Prepared statement
52
+ */
53
+ prepare(sql: string): Statement;
54
+ /**
55
+ * Execute SQL without returning results (for DDL, multi-statement SQL)
56
+ *
57
+ * @param sql - SQL to execute
58
+ */
59
+ exec(sql: string): Promise<void>;
60
+ /**
61
+ * Execute statement and return result info
62
+ *
63
+ * @param sql - SQL statement
64
+ * @param params - Bind parameters
65
+ * @returns Run result with changes and lastInsertRowid
66
+ */
67
+ run(sql: string, ...params: BindParams[]): Promise<RunResult>;
68
+ /**
69
+ * Execute query and return first row
70
+ *
71
+ * @param sql - SQL query
72
+ * @param params - Bind parameters
73
+ * @returns First row or undefined
74
+ */
75
+ get(sql: string, ...params: BindParams[]): Promise<Row | undefined>;
76
+ /**
77
+ * Execute query and return all rows
78
+ *
79
+ * @param sql - SQL query
80
+ * @param params - Bind parameters
81
+ * @returns All rows
82
+ */
83
+ all(sql: string, ...params: BindParams[]): Promise<Row[]>;
84
+ /**
85
+ * Execute function within a transaction
86
+ *
87
+ * @param fn - Function to execute
88
+ * @returns Function result
89
+ */
90
+ transaction<T>(fn: () => T | Promise<T>): Promise<T>;
91
+ /**
92
+ * Push local changes to remote (sync databases only)
93
+ */
94
+ push(): Promise<void>;
95
+ /**
96
+ * Pull remote changes and apply locally (sync databases only)
97
+ *
98
+ * @returns true if changes were applied, false if no changes
99
+ */
100
+ pull(): Promise<boolean>;
101
+ /**
102
+ * Get sync statistics (sync databases only)
103
+ *
104
+ * @returns Sync stats
105
+ */
106
+ stats(): Promise<SyncStats>;
107
+ /**
108
+ * Checkpoint database (sync databases only)
109
+ */
110
+ checkpoint(): Promise<void>;
111
+ /**
112
+ * Close the database
113
+ */
114
+ close(): void;
115
+ /**
116
+ * Get database path
117
+ */
118
+ get path(): string;
119
+ /**
120
+ * Check if database is a sync database
121
+ */
122
+ get isSync(): boolean;
123
+ /**
124
+ * Check if database is open
125
+ */
126
+ get open(): boolean;
127
+ /**
128
+ * Check if in transaction
129
+ */
130
+ get inTransaction(): boolean;
131
+ /**
132
+ * Get last insert rowid
133
+ */
134
+ get lastInsertRowid(): number;
135
+ /**
136
+ * Check if open and throw if not
137
+ */
138
+ private checkOpen;
139
+ }
140
+ //# sourceMappingURL=Database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../src/Database.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAIV,GAAG,EACH,SAAS,EAET,UAAU,EACV,YAAY,EACZ,SAAS,EAEV,MAAM,SAAS,CAAC;AA2CjB;;;;;;;GAOG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,WA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