@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,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.driveChangesOperation = driveChangesOperation;
7
+ exports.driveConnectionOperation = driveConnectionOperation;
8
+ exports.driveOperation = driveOperation;
9
+ exports.driveStatsOperation = driveStatsOperation;
10
+ exports.driveVoidOperation = driveVoidOperation;
11
+ var _types = require("../types");
12
+ var _ioProcessor = require("./ioProcessor");
13
+ /**
14
+ * Async Operation Driver
15
+ *
16
+ * Drives async operations returned by sync SDK-KIT methods.
17
+ * This is where ALL the async logic lives - the C++ layer is just a thin bridge.
18
+ *
19
+ * Key responsibilities:
20
+ * - Call resume() in a loop until DONE
21
+ * - When IO is needed, process all pending IO items
22
+ * - Extract and return the final result
23
+ */
24
+
25
+ /**
26
+ * Drive an async operation to completion
27
+ *
28
+ * @param operation - The native operation to drive
29
+ * @param database - The native sync database (for IO queue access)
30
+ * @param context - IO context with auth and URL information
31
+ * @returns Promise that resolves when operation completes
32
+ */
33
+ async function driveOperation(operation, database, context) {
34
+ while (true) {
35
+ // Resume the operation
36
+ const status = operation.resume();
37
+
38
+ // Operation completed successfully
39
+ if (status === _types.TursoStatus.DONE) {
40
+ // Extract and return the result based on result type
41
+ const resultKind = operation.resultKind();
42
+ switch (resultKind) {
43
+ case _types.SyncOperationResultType.NONE:
44
+ return undefined;
45
+ case _types.SyncOperationResultType.CONNECTION:
46
+ return operation.extractConnection();
47
+ case _types.SyncOperationResultType.CHANGES:
48
+ return operation.extractChanges();
49
+ case _types.SyncOperationResultType.STATS:
50
+ return operation.extractStats();
51
+ default:
52
+ throw new Error(`Unknown result type: ${resultKind}`);
53
+ }
54
+ }
55
+
56
+ // Operation needs IO
57
+ if (status === _types.TursoStatus.IO) {
58
+ // Process all pending IO items
59
+ await processIoQueue(database, context);
60
+
61
+ // Step callbacks after IO processing
62
+ database.ioStepCallbacks();
63
+
64
+ // Continue resume loop
65
+ continue;
66
+ }
67
+
68
+ // Any other status is an error
69
+ throw new Error(`Unexpected status from operation.resume(): ${status}`);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Process all pending IO items in the queue
75
+ *
76
+ * @param database - The native sync database
77
+ * @param context - IO context with auth and URL information
78
+ */
79
+ async function processIoQueue(database, context) {
80
+ const promises = [];
81
+
82
+ // Take all available IO items from the queue
83
+ while (true) {
84
+ const ioItem = database.ioTakeItem();
85
+ if (!ioItem) {
86
+ break; // No more items
87
+ }
88
+
89
+ // Process each item (potentially in parallel)
90
+ promises.push((0, _ioProcessor.processIoItem)(ioItem, context));
91
+ }
92
+
93
+ // Wait for all IO operations to complete
94
+ await Promise.all(promises);
95
+ }
96
+
97
+ /**
98
+ * Helper type for operations that return connections
99
+ */
100
+ async function driveConnectionOperation(operation, database, context) {
101
+ return driveOperation(operation, database, context);
102
+ }
103
+
104
+ /**
105
+ * Helper type for operations that return changes
106
+ */
107
+ async function driveChangesOperation(operation, database, context) {
108
+ return driveOperation(operation, database, context);
109
+ }
110
+
111
+ /**
112
+ * Helper type for operations that return stats
113
+ */
114
+ async function driveStatsOperation(operation, database, context) {
115
+ return driveOperation(operation, database, context);
116
+ }
117
+
118
+ /**
119
+ * Helper type for operations that return void
120
+ */
121
+ async function driveVoidOperation(operation, database, context) {
122
+ return driveOperation(operation, database, context);
123
+ }
124
+ //# sourceMappingURL=asyncOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_ioProcessor","driveOperation","operation","database","context","status","resume","TursoStatus","DONE","resultKind","SyncOperationResultType","NONE","undefined","CONNECTION","extractConnection","CHANGES","extractChanges","STATS","extractStats","Error","IO","processIoQueue","ioStepCallbacks","promises","ioItem","ioTakeItem","push","processIoItem","Promise","all","driveConnectionOperation","driveChangesOperation","driveStatsOperation","driveVoidOperation"],"sourceRoot":"../../../src","sources":["internal/asyncOperation.ts"],"mappings":";;;;;;;;;;AAmBA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;A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,IAAAC,0BAAa,EAACH,MAAM,EAAEpB,OAAO,CAAC,CAAC;EAC/C;;EAEA;EACA,MAAMwB,OAAO,CAACC,GAAG,CAACN,QAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACO,eAAeO,wBAAwBA,CAC5C5B,SAA8B,EAC9BC,QAA4B,EAC5BC,OAAkB,EACS;EAC3B,OAAOH,cAAc,CAAmBC,SAAS,EAAEC,QAAQ,EAAEC,OAAO,CAAC;AACvE;;AAEA;AACA;AACA;AACO,eAAe2B,qBAAqBA,CACzC7B,SAA8B,EAC9BC,QAA4B,EAC5BC,OAAkB,EACiB;EACnC,OAAOH,cAAc,CAA2BC,SAAS,EAAEC,QAAQ,EAAEC,OAAO,CAAC;AAC/E;;AAEA;AACA;AACA;AACO,eAAe4B,mBAAmBA,CACvC9B,SAA8B,EAC9BC,QAA4B,EAC5BC,OAAkB,EACE;EACpB,OAAOH,cAAc,CAAYC,SAAS,EAAEC,QAAQ,EAAEC,OAAO,CAAC;AAChE;;AAEA;AACA;AACA;AACO,eAAe6B,kBAAkBA,CACtC/B,SAA8B,EAC9BC,QAA4B,EAC5BC,OAAkB,EACH;EACf,OAAOH,cAAc,CAAOC,SAAS,EAAEC,QAAQ,EAAEC,OAAO,CAAC;AAC3D","ignoreList":[]}
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.drainSyncIo = drainSyncIo;
7
+ exports.processIoItem = processIoItem;
8
+ exports.setFileSystemImpl = setFileSystemImpl;
9
+ /**
10
+ * IO Processor
11
+ *
12
+ * Processes IO requests from the sync engine using JavaScript APIs.
13
+ * This is the key benefit of the thin JSI layer - all IO is handled by
14
+ * React Native's standard APIs (fetch, file system), not C++ code.
15
+ *
16
+ * Benefits:
17
+ * - Network requests visible in React Native debugger
18
+ * - Can customize fetch (add proxies, custom headers, etc.)
19
+ * - Easier to test (can mock fetch)
20
+ * - Uses platform-native networking (not C++ HTTP libraries)
21
+ */
22
+
23
+ /**
24
+ * IO context contains auth and URL information for HTTP requests
25
+ */
26
+
27
+ // Allow users to optionally override file system implementation
28
+ let fsReadFileOverride = null;
29
+ let fsWriteFileOverride = null;
30
+
31
+ /**
32
+ * Set custom file system implementation (optional)
33
+ * By default, uses built-in JSI file system functions.
34
+ * Only call this if you need custom behavior (e.g., encryption, compression).
35
+ *
36
+ * @param readFile - Function to read file as Uint8Array
37
+ * @param writeFile - Function to write Uint8Array to file
38
+ */
39
+ function setFileSystemImpl(readFile, writeFile) {
40
+ fsReadFileOverride = readFile;
41
+ fsWriteFileOverride = writeFile;
42
+ }
43
+
44
+ /**
45
+ * Read file using custom implementation or built-in JSI function
46
+ */
47
+ async function fsReadFile(path) {
48
+ if (fsReadFileOverride) {
49
+ return fsReadFileOverride(path);
50
+ }
51
+
52
+ // Use built-in JSI function
53
+ const buffer = __TursoProxy.fsReadFile(path);
54
+ if (buffer === null) {
55
+ // File not found - return empty
56
+ return new Uint8Array(0);
57
+ }
58
+ return new Uint8Array(buffer);
59
+ }
60
+
61
+ /**
62
+ * Write file using custom implementation or built-in JSI function
63
+ */
64
+ async function fsWriteFile(path, data) {
65
+ if (fsWriteFileOverride) {
66
+ return fsWriteFileOverride(path, data);
67
+ }
68
+
69
+ // Use built-in JSI function
70
+ __TursoProxy.fsWriteFile(path, data.buffer);
71
+ }
72
+
73
+ /**
74
+ * Process a single IO item
75
+ *
76
+ * @param item - The IO item to process
77
+ * @param context - IO context with auth and URL information
78
+ */
79
+ async function processIoItem(item, context) {
80
+ try {
81
+ const kind = item.getKind();
82
+ switch (kind) {
83
+ case 'HTTP':
84
+ await processHttpRequest(item, context);
85
+ break;
86
+ case 'FULL_READ':
87
+ await processFullRead(item);
88
+ break;
89
+ case 'FULL_WRITE':
90
+ await processFullWrite(item);
91
+ break;
92
+ case 'NONE':
93
+ default:
94
+ // Nothing to do
95
+ item.done();
96
+ break;
97
+ }
98
+ } catch (error) {
99
+ // Poison the item with error message
100
+ const errorMsg = error instanceof Error ? error.message : String(error);
101
+ item.poison(errorMsg);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Normalize URL from libsql:// to https://
107
+ */
108
+ function normalizeUrl(url) {
109
+ if (url.startsWith('libsql://')) {
110
+ return url.replace('libsql://', 'https://');
111
+ }
112
+ return url;
113
+ }
114
+
115
+ /**
116
+ * Get auth token from context (handles both string and function)
117
+ */
118
+ function getAuthToken(context) {
119
+ if (!context.authToken) {
120
+ return null;
121
+ }
122
+ if (typeof context.authToken === 'function') {
123
+ return context.authToken();
124
+ }
125
+ return context.authToken;
126
+ }
127
+
128
+ /**
129
+ * Process an HTTP request using fetch()
130
+ *
131
+ * @param item - The IO item
132
+ * @param context - IO context with auth and URL information
133
+ */
134
+ async function processHttpRequest(item, context) {
135
+ const request = item.getHttpRequest();
136
+
137
+ // Build full URL
138
+ let fullUrl = '';
139
+ if (request.url) {
140
+ // Normalize URL (libsql:// -> https://)
141
+ let baseUrl = normalizeUrl(request.url);
142
+
143
+ // Combine base URL with path if path is provided
144
+ if (request.path) {
145
+ // Ensure proper URL formatting (avoid double slashes, ensure single slash)
146
+ if (baseUrl.endsWith('/') && request.path.startsWith('/')) {
147
+ fullUrl = baseUrl + request.path.substring(1);
148
+ } else if (!baseUrl.endsWith('/') && !request.path.startsWith('/')) {
149
+ fullUrl = baseUrl + '/' + request.path;
150
+ } else {
151
+ fullUrl = baseUrl + request.path;
152
+ }
153
+ } else {
154
+ fullUrl = baseUrl;
155
+ }
156
+ } else if (request.path) {
157
+ // Path without base URL - shouldn't happen
158
+ throw new Error('HTTP request missing base URL');
159
+ } else {
160
+ throw new Error('HTTP request missing URL and path');
161
+ }
162
+
163
+ // Build fetch options
164
+ const options = {
165
+ method: request.method,
166
+ headers: {
167
+ ...request.headers
168
+ }
169
+ };
170
+
171
+ // Inject Authorization header if auth token is available
172
+ const authToken = getAuthToken(context);
173
+ if (authToken) {
174
+ options.headers['Authorization'] = `Bearer ${authToken}`;
175
+ }
176
+
177
+ // Add body if present
178
+ if (request.body) {
179
+ options.body = request.body;
180
+ }
181
+
182
+ // Debug logging for HTTP requests
183
+ console.log('[Turso HTTP] Request:', {
184
+ method: request.method,
185
+ url: fullUrl,
186
+ hasBody: !!request.body,
187
+ bodySize: request.body ? request.body.byteLength : 0,
188
+ headers: options.headers
189
+ });
190
+
191
+ // Make the HTTP request
192
+ let response;
193
+ try {
194
+ response = await fetch(fullUrl, options);
195
+ } catch (e) {
196
+ // Detailed error logging
197
+ const errorDetails = {
198
+ url: fullUrl,
199
+ method: request.method,
200
+ hasBody: !!request.body,
201
+ bodySize: request.body ? request.body.byteLength : 0,
202
+ bodyType: request.body ? Object.prototype.toString.call(options.body) : 'none',
203
+ error: e instanceof Error ? {
204
+ message: e.message,
205
+ name: e.name,
206
+ stack: e.stack
207
+ } : String(e)
208
+ };
209
+ console.error('[Turso HTTP] Request failed:', JSON.stringify(errorDetails, null, 2));
210
+ 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`);
211
+ }
212
+
213
+ // Set status code
214
+ item.setStatus(response.status);
215
+
216
+ // Read response body and push to item
217
+ const responseData = await response.arrayBuffer();
218
+ if (responseData.byteLength > 0) {
219
+ item.pushBuffer(responseData);
220
+ }
221
+
222
+ // Mark as done
223
+ item.done();
224
+ }
225
+
226
+ /**
227
+ * Process a full read request (atomic file read)
228
+ *
229
+ * @param item - The IO item
230
+ */
231
+ async function processFullRead(item) {
232
+ const path = item.getFullReadPath();
233
+ try {
234
+ // Read the file (uses built-in JSI function or custom override)
235
+ const data = await fsReadFile(path);
236
+
237
+ // Push data to item
238
+ if (data.byteLength > 0) {
239
+ item.pushBuffer(data.buffer);
240
+ }
241
+
242
+ // Mark as done
243
+ item.done();
244
+ } catch (error) {
245
+ // File not found is okay - treat as empty file
246
+ if (isFileNotFoundError(error)) {
247
+ // Empty file - just mark as done without pushing data
248
+ item.done();
249
+ } else {
250
+ throw error;
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Process a full write request (atomic file write)
257
+ *
258
+ * @param item - The IO item
259
+ */
260
+ async function processFullWrite(item) {
261
+ const request = item.getFullWriteRequest();
262
+
263
+ // Convert ArrayBuffer to Uint8Array
264
+ const data = request.content ? new Uint8Array(request.content) : new Uint8Array(0);
265
+
266
+ // Write the file atomically (uses built-in JSI function or custom override)
267
+ await fsWriteFile(request.path, data);
268
+
269
+ // Mark as done
270
+ item.done();
271
+ }
272
+
273
+ /**
274
+ * Check if error is a file-not-found error
275
+ *
276
+ * @param error - The error to check
277
+ * @returns true if file not found
278
+ */
279
+ function isFileNotFoundError(error) {
280
+ if (error instanceof Error) {
281
+ const message = error.message.toLowerCase();
282
+ return message.includes('enoent') || message.includes('not found') || message.includes('no such file');
283
+ }
284
+ return false;
285
+ }
286
+
287
+ /**
288
+ * Drain all pending IO items from sync engine queue and process them.
289
+ * This is called during statement execution when partial sync needs to load missing pages.
290
+ *
291
+ * @param database - The native sync database
292
+ * @param context - IO context with auth and URL information
293
+ */
294
+ async function drainSyncIo(database, context) {
295
+ const promises = [];
296
+
297
+ // Take all available IO items from the queue
298
+ while (true) {
299
+ const ioItem = database.ioTakeItem();
300
+ if (!ioItem) {
301
+ break; // No more items
302
+ }
303
+
304
+ // Process each item
305
+ promises.push(processIoItem(ioItem, context));
306
+ }
307
+
308
+ // Wait for all IO operations to complete
309
+ await Promise.all(promises);
310
+
311
+ // Step callbacks after IO processing
312
+ // This allows the sync engine to run any post-IO callbacks
313
+ database.ioStepCallbacks();
314
+ }
315
+ //# 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;AACO,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;AACA;AACA;AACA,eAAeG,WAAWA,CAACJ,IAAY,EAAEK,IAAgB,EAAiB;EACxE,IAAIV,mBAAmB,EAAE;IACvB,OAAOA,mBAAmB,CAACK,IAAI,EAAEK,IAAI,CAAC;EACxC;;EAEA;EACAH,YAAY,CAACE,WAAW,CAACJ,IAAI,EAAEK,IAAI,CAACJ,MAAqB,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+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TursoType = exports.TursoStatus = exports.SyncOperationResultType = void 0;
7
+ /**
8
+ * Turso React Native SDK-KIT Types
9
+ *
10
+ * Clean TypeScript types matching the SDK-KIT C API patterns.
11
+ * All logic lives in TypeScript or Rust - the C++ layer is just a thin bridge.
12
+ */
13
+ // ============================================================================
14
+ // Core SDK-KIT Types (Local Database)
15
+ // ============================================================================
16
+ /**
17
+ * Native database interface (local-only)
18
+ * Thin wrapper around TursoDatabaseHostObject
19
+ */
20
+ /**
21
+ * Native connection interface
22
+ * Thin wrapper around TursoConnectionHostObject
23
+ */
24
+ /**
25
+ * Native statement interface
26
+ * Thin wrapper around TursoStatementHostObject
27
+ */
28
+ // ============================================================================
29
+ // Sync SDK-KIT Types (Embedded Replica)
30
+ // ============================================================================
31
+ /**
32
+ * Native sync database interface (embedded replica)
33
+ * Thin wrapper around TursoSyncDatabaseHostObject
34
+ */
35
+ /**
36
+ * Native sync operation interface
37
+ * Thin wrapper around TursoSyncOperationHostObject
38
+ * Represents an async operation that must be driven by calling resume()
39
+ */
40
+ /**
41
+ * Native sync IO item interface
42
+ * Thin wrapper around TursoSyncIoItemHostObject
43
+ * Represents an IO request that JavaScript must process using fetch() or fs
44
+ */
45
+ /**
46
+ * Native sync changes interface
47
+ * Thin wrapper around TursoSyncChangesHostObject
48
+ * Represents changes fetched from remote (opaque, passed to applyChanges)
49
+ */
50
+ // ============================================================================
51
+ // Turso Status Codes
52
+ // ============================================================================
53
+ let TursoStatus = exports.TursoStatus = /*#__PURE__*/function (TursoStatus) {
54
+ TursoStatus[TursoStatus["OK"] = 0] = "OK";
55
+ TursoStatus[TursoStatus["DONE"] = 1] = "DONE";
56
+ TursoStatus[TursoStatus["ROW"] = 2] = "ROW";
57
+ TursoStatus[TursoStatus["IO"] = 3] = "IO";
58
+ TursoStatus[TursoStatus["BUSY"] = 4] = "BUSY";
59
+ TursoStatus[TursoStatus["INTERRUPT"] = 5] = "INTERRUPT";
60
+ TursoStatus[TursoStatus["BUSY_SNAPSHOT"] = 6] = "BUSY_SNAPSHOT";
61
+ TursoStatus[TursoStatus["ERROR"] = 127] = "ERROR";
62
+ TursoStatus[TursoStatus["MISUSE"] = 128] = "MISUSE";
63
+ TursoStatus[TursoStatus["CONSTRAINT"] = 129] = "CONSTRAINT";
64
+ TursoStatus[TursoStatus["READONLY"] = 130] = "READONLY";
65
+ TursoStatus[TursoStatus["DATABASE_FULL"] = 131] = "DATABASE_FULL";
66
+ TursoStatus[TursoStatus["NOTADB"] = 132] = "NOTADB";
67
+ TursoStatus[TursoStatus["CORRUPT"] = 133] = "CORRUPT";
68
+ TursoStatus[TursoStatus["IOERR"] = 134] = "IOERR";
69
+ return TursoStatus;
70
+ }({}); // ============================================================================
71
+ // Turso Value Types
72
+ // ============================================================================
73
+ let TursoType = exports.TursoType = /*#__PURE__*/function (TursoType) {
74
+ TursoType[TursoType["UNKNOWN"] = 0] = "UNKNOWN";
75
+ TursoType[TursoType["INTEGER"] = 1] = "INTEGER";
76
+ TursoType[TursoType["REAL"] = 2] = "REAL";
77
+ TursoType[TursoType["TEXT"] = 3] = "TEXT";
78
+ TursoType[TursoType["BLOB"] = 4] = "BLOB";
79
+ TursoType[TursoType["NULL"] = 5] = "NULL";
80
+ return TursoType;
81
+ }({}); // ============================================================================
82
+ // Sync Operation Result Types
83
+ // ============================================================================
84
+ let SyncOperationResultType = exports.SyncOperationResultType = /*#__PURE__*/function (SyncOperationResultType) {
85
+ SyncOperationResultType[SyncOperationResultType["NONE"] = 0] = "NONE";
86
+ SyncOperationResultType[SyncOperationResultType["CONNECTION"] = 1] = "CONNECTION";
87
+ SyncOperationResultType[SyncOperationResultType["CHANGES"] = 2] = "CHANGES";
88
+ SyncOperationResultType[SyncOperationResultType["STATS"] = 3] = "STATS";
89
+ return SyncOperationResultType;
90
+ }({}); // ============================================================================
91
+ // Public API Types (High-level TypeScript)
92
+ // ============================================================================
93
+ /**
94
+ * Supported SQLite value types for the public API
95
+ */
96
+ /**
97
+ * Parameters that can be bound to SQL statements
98
+ */
99
+ /**
100
+ * Result of a run() or exec() operation
101
+ */
102
+ /**
103
+ * A row returned from a query
104
+ */
105
+ /**
106
+ * Encryption options (matches JavaScript bindings)
107
+ */
108
+ /**
109
+ * Database options (matches JavaScript bindings)
110
+ * Single unified config for both local and sync databases
111
+ */
112
+ /**
113
+ * Sync stats returned by stats() operation
114
+ */
115
+ /**
116
+ * HTTP request from sync engine
117
+ */
118
+ /**
119
+ * Full write request from sync engine
120
+ */
121
+ // ============================================================================
122
+ // Global Turso Proxy Interface
123
+ // ============================================================================
124
+ /**
125
+ * Native proxy interface exposed via JSI
126
+ */
127
+ /**
128
+ * Native module interface (React Native bridge)
129
+ */
130
+ /**
131
+ * Global __TursoProxy object injected by native code
132
+ */
133
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TursoStatus","exports","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;AAAA,IAEYA,WAAW,GAAAC,OAAA,CAAAD,WAAA,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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