@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,339 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Statement = void 0;
7
+ var _types = require("./types");
8
+ /**
9
+ * Statement
10
+ *
11
+ * High-level wrapper around NativeStatement providing a clean API.
12
+ * Handles parameter binding, row conversion, and result collection.
13
+ */
14
+
15
+ /**
16
+ * Prepared SQL statement
17
+ */
18
+ class Statement {
19
+ _finalized = false;
20
+ constructor(statement, extraIo) {
21
+ this._statement = statement;
22
+ this._extraIo = extraIo;
23
+ }
24
+
25
+ /**
26
+ * Bind parameters to the statement
27
+ *
28
+ * @param params - Parameters to bind (array, object, or single value)
29
+ * @returns this for chaining
30
+ */
31
+ bind(...params) {
32
+ if (this._finalized) {
33
+ throw new Error('Statement has been finalized');
34
+ }
35
+
36
+ // Flatten parameters if single array passed
37
+ let flatParams;
38
+ if (params.length === 1 && Array.isArray(params[0])) {
39
+ flatParams = params[0];
40
+ } else if (params.length === 1 && typeof params[0] === 'object' && params[0] !== null) {
41
+ // Named parameters
42
+ const namedParams = params[0];
43
+ this.bindNamed(namedParams);
44
+ return this;
45
+ } else {
46
+ flatParams = params;
47
+ }
48
+
49
+ // Bind positional parameters
50
+ this.bindPositional(flatParams);
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Bind positional parameters (1-indexed)
56
+ *
57
+ * @param params - Array of values to bind
58
+ */
59
+ bindPositional(params) {
60
+ for (let i = 0; i < params.length; i++) {
61
+ const position = i + 1; // 1-indexed
62
+ const value = params[i];
63
+ this.bindValue(position, value);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Bind named parameters
69
+ *
70
+ * @param params - Object with named parameters
71
+ */
72
+ bindNamed(params) {
73
+ for (const [name, value] of Object.entries(params)) {
74
+ // Get position for named parameter
75
+ const position = this._statement.namedPosition(name);
76
+ if (position < 0) {
77
+ throw new Error(`Unknown parameter name: ${name}`);
78
+ }
79
+ this.bindValue(position, value);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Bind a single value at a position
85
+ *
86
+ * @param position - 1-indexed position
87
+ * @param value - Value to bind
88
+ */
89
+ bindValue(position, value) {
90
+ if (value === null || value === undefined) {
91
+ this._statement.bindPositionalNull(position);
92
+ } else if (typeof value === 'number') {
93
+ // Check if integer or float
94
+ if (Number.isInteger(value)) {
95
+ this._statement.bindPositionalInt(position, value);
96
+ } else {
97
+ this._statement.bindPositionalDouble(position, value);
98
+ }
99
+ } else if (typeof value === 'string') {
100
+ this._statement.bindPositionalText(position, value);
101
+ } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
102
+ const buffer = value;
103
+ this._statement.bindPositionalBlob(position, buffer);
104
+ } else {
105
+ throw new Error(`Unsupported parameter type: ${typeof value}`);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Execute statement without returning rows (for INSERT, UPDATE, DELETE)
111
+ *
112
+ * @param params - Optional parameters to bind
113
+ * @returns Result with changes and lastInsertRowid
114
+ */
115
+ async run(...params) {
116
+ if (this._finalized) {
117
+ throw new Error('Statement has been finalized');
118
+ }
119
+
120
+ // Bind parameters if provided
121
+ if (params.length > 0) {
122
+ this.bind(...params);
123
+ }
124
+
125
+ // Execute statement with IO handling
126
+ const result = await this.executeWithIo();
127
+
128
+ // Reset for next execution
129
+ this._statement.reset();
130
+ return {
131
+ changes: result.rowsChanged,
132
+ lastInsertRowid: 0 // Not available from execute, would need connection
133
+ };
134
+ }
135
+
136
+ /**
137
+ * Execute statement handling potential IO (for partial sync)
138
+ * Matches Python's _run_execute_with_io pattern
139
+ *
140
+ * @returns Execution result
141
+ */
142
+ async executeWithIo() {
143
+ while (true) {
144
+ const result = this._statement.execute();
145
+ if (result.status === _types.TursoStatus.IO) {
146
+ // Statement needs IO (e.g., loading missing pages with partial sync)
147
+ this._statement.runIo();
148
+
149
+ // Drain sync engine IO queue
150
+ if (this._extraIo) {
151
+ await this._extraIo();
152
+ }
153
+ continue;
154
+ }
155
+ if (result.status !== _types.TursoStatus.DONE) {
156
+ throw new Error(`Statement execution failed with status: ${result.status}`);
157
+ }
158
+ return result;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Step statement once handling potential IO (for partial sync)
164
+ * Matches Python's _step_once_with_io pattern
165
+ *
166
+ * @returns Status code
167
+ */
168
+ async stepWithIo() {
169
+ while (true) {
170
+ const status = this._statement.step();
171
+ if (status === _types.TursoStatus.IO) {
172
+ // Statement needs IO (e.g., loading missing pages with partial sync)
173
+ this._statement.runIo();
174
+
175
+ // Drain sync engine IO queue
176
+ if (this._extraIo) {
177
+ await this._extraIo();
178
+ }
179
+ continue;
180
+ }
181
+ return status;
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Execute statement and return first row
187
+ *
188
+ * @param params - Optional parameters to bind
189
+ * @returns First row or undefined
190
+ */
191
+ async get(...params) {
192
+ if (this._finalized) {
193
+ throw new Error('Statement has been finalized');
194
+ }
195
+
196
+ // Bind parameters if provided
197
+ if (params.length > 0) {
198
+ this.bind(...params);
199
+ }
200
+
201
+ // Step once with async IO handling
202
+ const status = await this.stepWithIo();
203
+ if (status === _types.TursoStatus.ROW) {
204
+ const row = this.readRow();
205
+ this._statement.reset();
206
+ return row;
207
+ }
208
+ if (status === _types.TursoStatus.DONE) {
209
+ this._statement.reset();
210
+ return undefined;
211
+ }
212
+ throw new Error(`Statement step failed with status: ${status}`);
213
+ }
214
+
215
+ /**
216
+ * Execute statement and return all rows
217
+ *
218
+ * @param params - Optional parameters to bind
219
+ * @returns Array of rows
220
+ */
221
+ async all(...params) {
222
+ if (this._finalized) {
223
+ throw new Error('Statement has been finalized');
224
+ }
225
+
226
+ // Bind parameters if provided
227
+ if (params.length > 0) {
228
+ this.bind(...params);
229
+ }
230
+ const rows = [];
231
+
232
+ // Step through all rows with async IO handling
233
+ while (true) {
234
+ const status = await this.stepWithIo();
235
+ if (status === _types.TursoStatus.ROW) {
236
+ rows.push(this.readRow());
237
+ } else if (status === _types.TursoStatus.DONE) {
238
+ break;
239
+ } else {
240
+ throw new Error(`Statement step failed with status: ${status}`);
241
+ }
242
+ }
243
+ this._statement.reset();
244
+ return rows;
245
+ }
246
+
247
+ /**
248
+ * Read current row into an object
249
+ *
250
+ * @returns Row object with column name keys
251
+ */
252
+ readRow() {
253
+ const row = {};
254
+ const columnCount = this._statement.columnCount();
255
+ for (let i = 0; i < columnCount; i++) {
256
+ const name = this._statement.columnName(i);
257
+ if (!name) {
258
+ throw new Error(`Failed to get column name at index ${i}`);
259
+ }
260
+ const value = this.readColumnValue(i);
261
+ row[name] = value;
262
+ }
263
+ return row;
264
+ }
265
+
266
+ /**
267
+ * Read value at column index
268
+ *
269
+ * @param index - Column index
270
+ * @returns Column value
271
+ */
272
+ readColumnValue(index) {
273
+ const kind = this._statement.rowValueKind(index);
274
+ switch (kind) {
275
+ case _types.TursoType.NULL:
276
+ return null;
277
+ case _types.TursoType.INTEGER:
278
+ return this._statement.rowValueInt(index);
279
+ case _types.TursoType.REAL:
280
+ return this._statement.rowValueDouble(index);
281
+ case _types.TursoType.TEXT:
282
+ // Use rowValueText which directly returns a string from C++ (avoids encoding issues)
283
+ return this._statement.rowValueText(index);
284
+ case _types.TursoType.BLOB:
285
+ return this._statement.rowValueBytesPtr(index) || new ArrayBuffer(0);
286
+ default:
287
+ throw new Error(`Unknown column type: ${kind}`);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Reset statement for re-execution
293
+ *
294
+ * @returns this for chaining
295
+ */
296
+ reset() {
297
+ if (this._finalized) {
298
+ throw new Error('Statement has been finalized');
299
+ }
300
+ this._statement.reset();
301
+ return this;
302
+ }
303
+
304
+ /**
305
+ * Finalize and release statement resources
306
+ */
307
+ async finalize() {
308
+ if (this._finalized) {
309
+ return;
310
+ }
311
+ while (true) {
312
+ const status = this._statement.finalize();
313
+ if (status === _types.TursoStatus.IO) {
314
+ // Statement needs IO (e.g., loading missing pages with partial sync)
315
+ this._statement.runIo();
316
+
317
+ // Drain sync engine IO queue
318
+ if (this._extraIo) {
319
+ await this._extraIo();
320
+ }
321
+ continue;
322
+ }
323
+ if (status !== _types.TursoStatus.DONE) {
324
+ throw new Error(`Statement finalization failed with status: ${status}`);
325
+ }
326
+ break;
327
+ }
328
+ this._finalized = true;
329
+ }
330
+
331
+ /**
332
+ * Check if statement has been finalized
333
+ */
334
+ get finalized() {
335
+ return this._finalized;
336
+ }
337
+ }
338
+ exports.Statement = Statement;
339
+ //# sourceMappingURL=Statement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","Statement","_finalized","constructor","statement","extraIo","_statement","_extraIo","bind","params","Error","flatParams","length","Array","isArray","namedParams","bindNamed","bindPositional","i","position","value","bindValue","name","Object","entries","namedPosition","undefined","bindPositionalNull","Number","isInteger","bindPositionalInt","bindPositionalDouble","bindPositionalText","ArrayBuffer","isView","buffer","bindPositionalBlob","run","result","executeWithIo","reset","changes","rowsChanged","lastInsertRowid","execute","status","TursoStatus","IO","runIo","DONE","stepWithIo","step","get","ROW","row","readRow","all","rows","push","columnCount","columnName","readColumnValue","index","kind","rowValueKind","TursoType","NULL","INTEGER","rowValueInt","REAL","rowValueDouble","TEXT","rowValueText","BLOB","rowValueBytesPtr","finalize","finalized","exports"],"sourceRoot":"../../src","sources":["Statement.ts"],"mappings":";;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACO,MAAMC,SAAS,CAAC;EAEbC,UAAU,GAAG,KAAK;EAG1BC,WAAWA,CAACC,SAA0B,EAAEC,OAA6B,EAAE;IACrE,IAAI,CAACC,UAAU,GAAGF,SAAS;IAC3B,IAAI,CAACG,QAAQ,GAAGF,OAAO;EACzB;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEG,IAAIA,CAAC,GAAGC,MAAoB,EAAQ;IAClC,IAAI,IAAI,CAACP,UAAU,EAAE;MACnB,MAAM,IAAIQ,KAAK,CAAC,8BAA8B,CAAC;IACjD;;IAEA;IACA,IAAIC,UAAyB;IAC7B,IAAIF,MAAM,CAACG,MAAM,KAAK,CAAC,IAAIC,KAAK,CAACC,OAAO,CAACL,MAAM,CAAC,CAAC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, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Database", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Database.Database;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Statement", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Statement.Statement;
16
+ }
17
+ });
18
+ exports.connect = connect;
19
+ exports.default = void 0;
20
+ exports.getDbPath = getDbPath;
21
+ exports.paths = void 0;
22
+ Object.defineProperty(exports, "setFileSystemImpl", {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _ioProcessor.setFileSystemImpl;
26
+ }
27
+ });
28
+ exports.setup = setup;
29
+ exports.version = version;
30
+ var _reactNative = require("react-native");
31
+ var _Database = require("./Database");
32
+ var _ioProcessor = require("./internal/ioProcessor");
33
+ var _Statement = require("./Statement");
34
+ /**
35
+ * Turso React Native SDK
36
+ *
37
+ * Main entry point for the SDK. Supports both local-only and sync databases.
38
+ */
39
+
40
+ // Re-export all public types
41
+
42
+ // Re-export classes
43
+
44
+ // Export file system configuration function
45
+
46
+ // Get the native module
47
+ const TursoNative = _reactNative.NativeModules.Turso;
48
+
49
+ // Check if native module is available
50
+ if (!TursoNative) {
51
+ throw new Error(`@tursodatabase/sync-react-native: Native module not found. Make sure you have properly linked the library.\n` + `- iOS: Run 'pod install' in your ios directory\n` + `- Android: Make sure the package is properly included in your MainApplication.java`);
52
+ }
53
+
54
+ // Install the JSI bindings
55
+ const installed = TursoNative.install();
56
+ if (!installed) {
57
+ throw new Error('@tursodatabase/sync-react-native: Failed to install JSI bindings. Make sure the New Architecture is enabled.');
58
+ }
59
+
60
+ // Get the proxy that was installed on the global object
61
+ // __TursoProxy is declared globally in types.ts
62
+ const TursoProxy = __TursoProxy;
63
+ if (!TursoProxy) {
64
+ throw new Error('@tursodatabase/sync-react-native: JSI bindings not found on global object. This is a bug.');
65
+ }
66
+
67
+ /**
68
+ * Helper function to construct a database path in a writable directory.
69
+ * On mobile platforms, you must use writable directories (not relative paths).
70
+ *
71
+ * @param filename - Database filename (e.g., 'mydb.db')
72
+ * @param directory - Directory to use ('documents', 'database', or 'library')
73
+ * @returns Absolute path to the database file
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { getDbPath, connect } from '@tursodatabase/sync-react-native';
78
+ *
79
+ * const dbPath = getDbPath('mydb.db');
80
+ * const db = await connect({ path: dbPath });
81
+ * ```
82
+ */
83
+ function getDbPath(filename, directory = 'documents') {
84
+ const basePath = paths[directory];
85
+ if (!basePath || basePath === '.') {
86
+ throw new Error(`Unable to get ${directory} path for this platform. ` + 'Make sure the native module is properly loaded.');
87
+ }
88
+ return `${basePath}/${filename}`;
89
+ }
90
+
91
+ /**
92
+ * Connect to a database asynchronously (matches JavaScript bindings API)
93
+ *
94
+ * This is the main entry point for the SDK, matching the API from
95
+ * @tursodatabase/sync-native and @tursodatabase/database-native.
96
+ *
97
+ * **Path handling**: Relative paths are automatically placed in writable directories:
98
+ * - Android: app's database directory (`/data/data/com.app/databases/`)
99
+ * - iOS: app's documents directory
100
+ *
101
+ * Absolute paths and `:memory:` are used as-is.
102
+ *
103
+ * @param opts - Database options
104
+ * @returns Promise resolving to Database instance
105
+ *
106
+ * @example Local database (relative path)
107
+ * ```ts
108
+ * import { connect } from '@tursodatabase/sync-react-native';
109
+ *
110
+ * // Relative path automatically placed in writable directory
111
+ * const db = await connect({ path: 'local.db' });
112
+ * await db.exec('CREATE TABLE users (id INTEGER, name TEXT)');
113
+ * ```
114
+ *
115
+ * @example Using :memory: for in-memory database
116
+ * ```ts
117
+ * const db = await connect({ path: ':memory:' });
118
+ * ```
119
+ *
120
+ * @example Sync database
121
+ * ```ts
122
+ * const db = await connect({
123
+ * path: 'replica.db',
124
+ * url: 'libsql://mydb.turso.io',
125
+ * authToken: 'token-here',
126
+ * });
127
+ * const users = await db.all('SELECT * FROM users');
128
+ * await db.push();
129
+ * await db.pull();
130
+ * ```
131
+ *
132
+ * @example Using absolute path (advanced)
133
+ * ```ts
134
+ * import { connect, paths } from '@tursodatabase/sync-react-native';
135
+ *
136
+ * const db = await connect({ path: `${paths.documents}/mydb.db` });
137
+ * ```
138
+ */
139
+ async function connect(opts) {
140
+ const db = new _Database.Database(opts);
141
+ await db.connect();
142
+ return db;
143
+ }
144
+
145
+ /**
146
+ * Returns the Turso library version.
147
+ */
148
+ function version() {
149
+ return TursoProxy.version();
150
+ }
151
+
152
+ /**
153
+ * Configure Turso settings such as logging.
154
+ * Should be called before any database operations.
155
+ *
156
+ * @param options - Configuration options
157
+ * @example
158
+ * ```ts
159
+ * import { setup } from '@tursodatabase/sync-react-native';
160
+ *
161
+ * setup({ logLevel: 'debug' });
162
+ * ```
163
+ */
164
+ function setup(options) {
165
+ TursoProxy.setup(options);
166
+ }
167
+
168
+ /**
169
+ * Platform-specific writable directory paths.
170
+ * Use these to construct absolute paths for database files.
171
+ *
172
+ * NOTE: With automatic path normalization, you typically don't need this.
173
+ * Just pass relative paths like 'mydb.db' and they'll be placed in the correct directory.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * import { paths, connect } from '@tursodatabase/sync-react-native';
178
+ *
179
+ * // Create database in app's documents/files directory
180
+ * const dbPath = `${paths.documents}/mydb.db`;
181
+ * const db = await connect({ path: dbPath });
182
+ * ```
183
+ */
184
+ const paths = exports.paths = {
185
+ /**
186
+ * Primary documents/database directory (writable)
187
+ * - iOS: App's Documents directory (absolute path)
188
+ * - Android: App's database directory (absolute path) - preferred for databases
189
+ */
190
+ get documents() {
191
+ return TursoNative?.IOS_DOCUMENT_PATH || TursoNative?.ANDROID_DATABASE_PATH || '.';
192
+ },
193
+ /**
194
+ * Database-specific directory (writable)
195
+ * - iOS: Same as documents
196
+ * - Android: Database directory (absolute path)
197
+ */
198
+ get database() {
199
+ return TursoNative?.IOS_DOCUMENT_PATH || TursoNative?.ANDROID_DATABASE_PATH || '.';
200
+ },
201
+ /**
202
+ * Files directory (writable)
203
+ * - iOS: Same as documents
204
+ * - Android: App's files directory (absolute path)
205
+ */
206
+ get files() {
207
+ return TursoNative?.IOS_DOCUMENT_PATH || TursoNative?.ANDROID_FILES_PATH || '.';
208
+ },
209
+ /**
210
+ * Library directory (iOS only, writable)
211
+ * - iOS: App's Library directory (absolute path)
212
+ * - Android: Same as files
213
+ */
214
+ get library() {
215
+ return TursoNative?.IOS_LIBRARY_PATH || TursoNative?.ANDROID_FILES_PATH || '.';
216
+ }
217
+ };
218
+
219
+ // Default export
220
+ var _default = exports.default = {
221
+ connect,
222
+ version,
223
+ setup,
224
+ setFileSystemImpl: _ioProcessor.setFileSystemImpl,
225
+ getDbPath,
226
+ paths,
227
+ Database: _Database.Database
228
+ };
229
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_Database","_ioProcessor","_Statement","TursoNative","NativeModules","Turso","Error","installed","install","TursoProxy","__TursoProxy","getDbPath","filename","directory","basePath","paths","connect","opts","db","Database","version","setup","options","exports","documents","IOS_DOCUMENT_PATH","ANDROID_DATABASE_PATH","database","files","ANDROID_FILES_PATH","library","IOS_LIBRARY_PATH","_default","default","setFileSystemImpl"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAMA,IAAAE,YAAA,GAAAF,OAAA;AAwBA,IAAAG,UAAA,GAAAH,OAAA;AArCA;AACA;AACA;AACA;AACA;;AAWA;;AAoBA;;AAIA;;AAGA;AACA,MAAMI,WAA0C,GAAGC,0BAAa,CAACC,KAAK;;AAEtE;AACA,IAAI,CAACF,WAAW,EAAE;EAChB,MAAM,IAAIG,KAAK,CACb,8GAA8G,GAC9G,kDAAkD,GAClD,oFACF,CAAC;AACH;;AAEA;AACA,MAAMC,SAAS,GAAGJ,WAAW,CAACK,OAAO,CAAC,CAAC;AACvC,IAAI,CAACD,SAAS,EAAE;EACd,MAAM,IAAID,KAAK,CACb,8GACF,CAAC;AACH;;AAEA;AACA;AACA,MAAMG,UAA0B,GAAGC,YAAY;AAE/C,IAAI,CAACD,UAAU,EAAE;EACf,MAAM,IAAIH,KAAK,CACb,2FACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,SAASA,CAACC,QAAgB,EAAEC,SAA+C,GAAG,WAAW,EAAU;EACjH,MAAMC,QAAQ,GAAGC,KAAK,CAACF,SAAS,CAAC;EACjC,IAAI,CAACC,QAAQ,IAAIA,QAAQ,KAAK,GAAG,EAAE;IACjC,MAAM,IAAIR,KAAK,CACb,iBAAiBO,SAAS,2BAA2B,GACrD,iDACF,CAAC;EACH;EACA,OAAO,GAAGC,QAAQ,IAAIF,QAAQ,EAAE;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeI,OAAOA,CAACC,IAAkB,EAAqB;EACnE,MAAMC,EAAE,GAAG,IAAIC,kBAAQ,CAACF,IAAI,CAAC;EAC7B,MAAMC,EAAE,CAACF,OAAO,CAAC,CAAC;EAClB,OAAOE,EAAE;AACX;;AAEA;AACA;AACA;AACO,SAASE,OAAOA,CAAA,EAAW;EAChC,OAAOX,UAAU,CAACW,OAAO,CAAC,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,KAAKA,CAACC,OAA4B,EAAQ;EACxDb,UAAU,CAACY,KAAK,CAACC,OAAO,CAAC;AAC3B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,M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