@powersync/react-native 0.0.0-dev-20260525085311 → 0.0.0-dev-20260630144038

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 (64) hide show
  1. package/README.md +72 -6
  2. package/android/build.gradle +90 -0
  3. package/android/gradle.properties +4 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +46 -0
  7. package/ios/PowerSyncOpSqlite.h +5 -0
  8. package/ios/PowerSyncOpSqlite.mm +6 -0
  9. package/lib/db/PowerSyncDatabase.d.ts +9 -10
  10. package/lib/db/PowerSyncDatabase.js +33 -25
  11. package/lib/db/PowerSyncDatabase.js.map +1 -1
  12. package/lib/db/adapters/op-sqlite/OPSQLiteConnection.d.ts +25 -0
  13. package/lib/db/adapters/op-sqlite/OPSQLiteConnection.js +63 -0
  14. package/lib/db/adapters/op-sqlite/OPSQLiteConnection.js.map +1 -0
  15. package/lib/db/adapters/op-sqlite/OPSqliteAdapter.d.ts +32 -0
  16. package/lib/db/adapters/op-sqlite/OPSqliteAdapter.js +203 -0
  17. package/lib/db/adapters/op-sqlite/OPSqliteAdapter.js.map +1 -0
  18. package/lib/db/adapters/op-sqlite/OPSqliteDBOpenFactory.d.ts +11 -0
  19. package/lib/db/adapters/op-sqlite/OPSqliteDBOpenFactory.js +21 -0
  20. package/lib/db/adapters/op-sqlite/OPSqliteDBOpenFactory.js.map +1 -0
  21. package/lib/db/adapters/op-sqlite/SqliteOptions.d.ts +68 -0
  22. package/lib/db/adapters/op-sqlite/SqliteOptions.js +37 -0
  23. package/lib/db/adapters/op-sqlite/SqliteOptions.js.map +1 -0
  24. package/lib/index.d.ts +1 -3
  25. package/lib/index.js +0 -3
  26. package/lib/index.js.map +1 -1
  27. package/lib/sync/bucket/ReactNativeBucketStorageAdapter.d.ts +1 -1
  28. package/lib/sync/bucket/ReactNativeBucketStorageAdapter.js +1 -1
  29. package/lib/sync/bucket/ReactNativeBucketStorageAdapter.js.map +1 -1
  30. package/lib/sync/stream/ReactNativeRemote.d.ts +11 -11
  31. package/lib/sync/stream/ReactNativeRemote.js +42 -66
  32. package/lib/sync/stream/ReactNativeRemote.js.map +1 -1
  33. package/lib/sync/stream/ReactNativeStreamingSyncImplementation.d.ts +2 -1
  34. package/lib/sync/stream/ReactNativeStreamingSyncImplementation.js +2 -1
  35. package/lib/sync/stream/ReactNativeStreamingSyncImplementation.js.map +1 -1
  36. package/lib/sync/stream/fetch.d.ts +13 -0
  37. package/lib/sync/stream/fetch.js +31 -0
  38. package/lib/sync/stream/fetch.js.map +1 -0
  39. package/package.json +20 -33
  40. package/powersync-react-native.podspec +32 -0
  41. package/src/db/PowerSyncDatabase.ts +58 -31
  42. package/src/db/adapters/op-sqlite/OPSQLiteConnection.ts +95 -0
  43. package/src/db/adapters/op-sqlite/OPSqliteAdapter.ts +245 -0
  44. package/src/db/adapters/op-sqlite/OPSqliteDBOpenFactory.ts +25 -0
  45. package/src/db/adapters/op-sqlite/SqliteOptions.ts +93 -0
  46. package/src/index.ts +1 -3
  47. package/src/sync/bucket/ReactNativeBucketStorageAdapter.ts +1 -1
  48. package/src/sync/stream/ReactNativeRemote.ts +49 -86
  49. package/src/sync/stream/ReactNativeStreamingSyncImplementation.ts +4 -4
  50. package/src/sync/stream/fetch.ts +45 -0
  51. package/dist/index.js +0 -8741
  52. package/dist/index.js.map +0 -1
  53. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.d.ts +0 -55
  54. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.js +0 -66
  55. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.js.map +0 -1
  56. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory.d.ts +0 -19
  57. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory.js +0 -34
  58. package/lib/db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory.js.map +0 -1
  59. package/lib/db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory.d.ts +0 -9
  60. package/lib/db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory.js +0 -45
  61. package/lib/db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory.js.map +0 -1
  62. package/src/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.ts +0 -85
  63. package/src/db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory.ts +0 -44
  64. package/src/db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory.ts +0 -43
@@ -0,0 +1,203 @@
1
+ import { NativeModules } from 'react-native';
2
+ import { getDylibPath, open } from '@op-engineering/op-sqlite';
3
+ import { DBAdapter } from '@powersync/common';
4
+ import { timeoutSignal, Semaphore } from '@powersync/shared-internals';
5
+ import { Platform } from 'react-native';
6
+ import { OPSQLiteConnection } from './OPSQLiteConnection';
7
+ const READ_CONNECTIONS = 5;
8
+ export class OPSQLiteDBAdapter extends DBAdapter {
9
+ options;
10
+ name;
11
+ initialized;
12
+ readConnections;
13
+ writeConnection;
14
+ abortController;
15
+ constructor(options) {
16
+ super();
17
+ this.options = options;
18
+ this.name = this.options.name;
19
+ this.readConnections = null;
20
+ this.writeConnection = null;
21
+ this.abortController = new AbortController();
22
+ this.initialized = this.init();
23
+ }
24
+ async init() {
25
+ const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous, cacheSizeKb, temporaryStorage } = this.options.sqliteOptions;
26
+ const dbFilename = this.options.name;
27
+ const underlyingWriteConnection = await this.openConnection(false, dbFilename);
28
+ const baseStatements = [
29
+ `PRAGMA busy_timeout = ${lockTimeoutMs}`,
30
+ `PRAGMA cache_size = -${cacheSizeKb}`,
31
+ `PRAGMA temp_store = ${temporaryStorage}`
32
+ ];
33
+ const writeConnectionStatements = [
34
+ ...baseStatements,
35
+ `PRAGMA journal_mode = ${journalMode}`,
36
+ `PRAGMA journal_size_limit = ${journalSizeLimit}`,
37
+ `PRAGMA synchronous = ${synchronous}`
38
+ ];
39
+ for (const statement of writeConnectionStatements) {
40
+ for (let tries = 0; tries < 30; tries++) {
41
+ try {
42
+ await underlyingWriteConnection.execute(statement);
43
+ break;
44
+ }
45
+ catch (e) {
46
+ if (e instanceof Error && e.message.includes('database is locked') && tries < 29) {
47
+ continue;
48
+ }
49
+ else {
50
+ throw e;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ // Changes should only occur in the write connection
56
+ underlyingWriteConnection.tableUpdateDispatcher.registerListener({
57
+ tablesUpdated: (notification) => this.iterateListeners((cb) => cb.tablesUpdated?.(notification))
58
+ });
59
+ const underlyingReadConnections = [];
60
+ for (let i = 0; i < READ_CONNECTIONS; i++) {
61
+ const conn = await this.openConnection(true, dbFilename);
62
+ for (let statement of baseStatements) {
63
+ await conn.execute(statement);
64
+ }
65
+ underlyingReadConnections.push(conn);
66
+ }
67
+ this.writeConnection = new Semaphore([underlyingWriteConnection]);
68
+ this.readConnections = new Semaphore(underlyingReadConnections);
69
+ }
70
+ async openConnection(readOnly, filenameOverride) {
71
+ const dbFilename = filenameOverride ?? this.options.name;
72
+ const DB = this.openDatabase(dbFilename, readOnly, this.options.sqliteOptions?.encryptionKey ?? undefined);
73
+ //Load extensions for all connections
74
+ this.loadAdditionalExtensions(DB);
75
+ this.loadPowerSyncExtension(DB);
76
+ await DB.execute('SELECT powersync_init()');
77
+ return new OPSQLiteConnection({
78
+ baseDB: DB
79
+ });
80
+ }
81
+ openDatabase(dbFilename, readOnly, encryptionKey) {
82
+ const openOptions = {
83
+ name: dbFilename,
84
+ readOnly
85
+ };
86
+ if (this.options.dbLocation) {
87
+ openOptions.location = this.options.dbLocation;
88
+ }
89
+ else if ('NativePowerSyncHelper' in NativeModules) {
90
+ // In older versions of the PowerSync React Native SDK, we used React Native Quick SQLite instead of OP-SQLite.
91
+ // On Android, RQNS uses context.getFilesDir() instead of context.getDatabasePath() (which OP-SQLite uses as a
92
+ // default). So, to ensure that databases opened with RNQS continue to work with OP-SQLite, we have a native
93
+ // helper method that checks whether the database exists in the old path and would apply that as an explicit
94
+ // location in that case.
95
+ const helper = NativeModules.NativePowerSyncHelper;
96
+ const defaultLocation = helper.resolveDefaultDatabaseLocation(dbFilename);
97
+ if (defaultLocation) {
98
+ openOptions.location = defaultLocation;
99
+ }
100
+ }
101
+ // If the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
102
+ if (encryptionKey) {
103
+ openOptions.encryptionKey = encryptionKey;
104
+ }
105
+ return open(openOptions);
106
+ }
107
+ loadAdditionalExtensions(DB) {
108
+ if (this.options.sqliteOptions?.extensions && this.options.sqliteOptions.extensions.length > 0) {
109
+ for (const extension of this.options.sqliteOptions.extensions) {
110
+ DB.loadExtension(extension.path, extension.entryPoint);
111
+ }
112
+ }
113
+ }
114
+ async loadPowerSyncExtension(DB) {
115
+ if (Platform.OS === 'ios') {
116
+ const libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
117
+ DB.loadExtension(libPath, 'sqlite3_powersync_init');
118
+ }
119
+ else {
120
+ DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
121
+ }
122
+ }
123
+ async close() {
124
+ await this.initialized;
125
+ // Abort any pending operations
126
+ this.abortController.abort();
127
+ const { item: writeConnection, release: returnWrite } = await this.writeConnection.requestOne();
128
+ const { items: readers, release: returnReaders } = await this.readConnections.requestAll();
129
+ try {
130
+ writeConnection.close();
131
+ readers.forEach((c) => c.close());
132
+ }
133
+ finally {
134
+ returnWrite();
135
+ returnReaders();
136
+ }
137
+ }
138
+ generateNestedAbortSignal(options) {
139
+ const outerSignal = this.abortController.signal;
140
+ let signal;
141
+ let cleanUpInnerSignal;
142
+ if (options?.timeoutMs && !outerSignal.aborted) {
143
+ // This is essentially an AbortSignal.any() polyfill.
144
+ const innerController = new AbortController();
145
+ cleanUpInnerSignal = () => {
146
+ innerController.abort();
147
+ outerSignal.removeEventListener('abort', cleanUpInnerSignal);
148
+ timeout.removeEventListener('abort', cleanUpInnerSignal);
149
+ };
150
+ outerSignal.addEventListener('abort', cleanUpInnerSignal);
151
+ const timeout = timeoutSignal(options.timeoutMs);
152
+ timeout.addEventListener('abort', cleanUpInnerSignal);
153
+ signal = innerController.signal;
154
+ }
155
+ else {
156
+ signal = outerSignal;
157
+ }
158
+ return { signal, cleanUpInnerSignal };
159
+ }
160
+ async readLock(fn, options) {
161
+ await this.initialized;
162
+ const { signal, cleanUpInnerSignal } = this.generateNestedAbortSignal(options);
163
+ const { item, release } = await this.readConnections.requestOne(signal);
164
+ try {
165
+ return await fn(item);
166
+ }
167
+ finally {
168
+ release();
169
+ cleanUpInnerSignal?.();
170
+ }
171
+ }
172
+ async writeLock(fn, options) {
173
+ await this.initialized;
174
+ const { signal, cleanUpInnerSignal } = this.generateNestedAbortSignal(options);
175
+ const { item, release } = await this.writeConnection.requestOne(signal);
176
+ try {
177
+ return await fn(item).finally(() => item.flushUpdates());
178
+ }
179
+ finally {
180
+ release();
181
+ cleanUpInnerSignal?.();
182
+ }
183
+ }
184
+ async refreshSchema() {
185
+ await this.initialized;
186
+ await this.writeLock((l) => l.refreshSchema());
187
+ const { items, release } = await this.readConnections.requestAll();
188
+ try {
189
+ for (let readConnection of items) {
190
+ await readConnection.refreshSchema();
191
+ }
192
+ }
193
+ finally {
194
+ release();
195
+ }
196
+ }
197
+ executeBatch(query, params) {
198
+ // We need to override this because we don't support executeBatch in connection contexts / transactions, only when
199
+ // called directly on the adapter.
200
+ return this.writeLock((conn) => conn.executeNativeBatch(query, params));
201
+ }
202
+ }
203
+ //# sourceMappingURL=OPSqliteAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OPSqliteAdapter.js","sourceRoot":"","sources":["../../../../src/db/adapters/op-sqlite/OPSqliteAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EA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ACH,KAAK,IAAI,cAAc,IAAI,KAAK,EAAE,CAAC;gBACjC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;YACvC,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,MAAgB;QAC1C,kHAAkH;QAClH,kCAAkC;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/common';
2
+ import { SqliteOptions } from './SqliteOptions';
3
+ export interface OPSQLiteOpenFactoryOptions extends SQLOpenOptions {
4
+ sqliteOptions?: SqliteOptions;
5
+ }
6
+ export declare class OPSqliteOpenFactory implements SQLOpenFactory {
7
+ protected options: OPSQLiteOpenFactoryOptions;
8
+ private sqliteOptions;
9
+ constructor(options: OPSQLiteOpenFactoryOptions);
10
+ openDB(): DBAdapter;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { OPSQLiteDBAdapter } from './OPSqliteAdapter';
2
+ import { DEFAULT_SQLITE_OPTIONS } from './SqliteOptions';
3
+ export class OPSqliteOpenFactory {
4
+ options;
5
+ sqliteOptions;
6
+ constructor(options) {
7
+ this.options = options;
8
+ this.sqliteOptions = {
9
+ ...DEFAULT_SQLITE_OPTIONS,
10
+ ...this.options.sqliteOptions
11
+ };
12
+ }
13
+ openDB() {
14
+ return new OPSQLiteDBAdapter({
15
+ name: this.options.dbFilename,
16
+ dbLocation: this.options.dbLocation,
17
+ sqliteOptions: this.sqliteOptions
18
+ });
19
+ }
20
+ }
21
+ //# sourceMappingURL=OPSqliteDBOpenFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OPSqliteDBOpenFactory.js","sourceRoot":"","sources":["../../../../src/db/adapters/op-sqlite/OPSqliteDBOpenFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAiB,MAAM,iBAAiB,CAAC;AAKxE,MAAM,OAAO,mBAAmB;IAGR;IAFd,aAAa,CAA0B;IAE/C,YAAsB,OAAmC;QAAnC,YAAO,GAAP,OAAO,CAA4B;QACvD,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,sBAAsB;YACzB,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,iBAAiB,CAAC;YAC3B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YAC7B,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YACnC,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,68 @@
1
+ export interface SqliteOptions {
2
+ /**
3
+ * SQLite journal mode. Defaults to [SqliteJournalMode.wal].
4
+ */
5
+ journalMode?: SqliteJournalMode;
6
+ /**
7
+ * SQLite synchronous flag. Defaults to [SqliteSynchronous.normal], which
8
+ * is safe for WAL mode.
9
+ */
10
+ synchronous?: SqliteSynchronous;
11
+ /**
12
+ * Journal/WAL size limit. Defaults to 6MB.
13
+ * The WAL may grow larger than this limit during writes, but SQLite will
14
+ * attempt to truncate the file afterwards.
15
+ */
16
+ journalSizeLimit?: number;
17
+ /**
18
+ * Timeout in milliseconds waiting for locks to be released by other connections.
19
+ * Defaults to 30 seconds.
20
+ * Set to null or zero to fail immediately when the database is locked.
21
+ */
22
+ lockTimeoutMs?: number;
23
+ /**
24
+ * Encryption key for the database.
25
+ * If set, the database will be encrypted using SQLCipher.
26
+ */
27
+ encryptionKey?: string | null;
28
+ /**
29
+ * Where to store SQLite temporary files. Defaults to 'MEMORY'.
30
+ * Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
31
+ *
32
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_temp_store
33
+ */
34
+ temporaryStorage?: TemporaryStorageOption;
35
+ /**
36
+ * Maximum SQLite cache size. Defaults to 50MB.
37
+ *
38
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
39
+ */
40
+ cacheSizeKb?: number;
41
+ /**
42
+ * Load extensions using the path and entryPoint.
43
+ * More info can be found here https://op-engineering.github.io/op-sqlite/docs/api#loading-extensions.
44
+ */
45
+ extensions?: Array<{
46
+ path: string;
47
+ entryPoint?: string;
48
+ }>;
49
+ }
50
+ export declare enum TemporaryStorageOption {
51
+ MEMORY = "memory",
52
+ FILESYSTEM = "file"
53
+ }
54
+ declare enum SqliteJournalMode {
55
+ wal = "WAL",
56
+ delete = "DELETE",
57
+ truncate = "TRUNCATE",
58
+ persist = "PERSIST",
59
+ memory = "MEMORY",
60
+ off = "OFF"
61
+ }
62
+ declare enum SqliteSynchronous {
63
+ normal = "NORMAL",
64
+ full = "FULL",
65
+ off = "OFF"
66
+ }
67
+ export declare const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions>;
68
+ export {};
@@ -0,0 +1,37 @@
1
+ export var TemporaryStorageOption;
2
+ (function (TemporaryStorageOption) {
3
+ TemporaryStorageOption["MEMORY"] = "memory";
4
+ TemporaryStorageOption["FILESYSTEM"] = "file";
5
+ })(TemporaryStorageOption || (TemporaryStorageOption = {}));
6
+ // SQLite journal mode. Set on the primary connection.
7
+ // This library is written with WAL mode in mind - other modes may cause
8
+ // unexpected locking behavior.
9
+ var SqliteJournalMode;
10
+ (function (SqliteJournalMode) {
11
+ // Use a write-ahead log instead of a rollback journal.
12
+ // This provides good performance and concurrency.
13
+ SqliteJournalMode["wal"] = "WAL";
14
+ SqliteJournalMode["delete"] = "DELETE";
15
+ SqliteJournalMode["truncate"] = "TRUNCATE";
16
+ SqliteJournalMode["persist"] = "PERSIST";
17
+ SqliteJournalMode["memory"] = "MEMORY";
18
+ SqliteJournalMode["off"] = "OFF";
19
+ })(SqliteJournalMode || (SqliteJournalMode = {}));
20
+ // SQLite file commit mode.
21
+ var SqliteSynchronous;
22
+ (function (SqliteSynchronous) {
23
+ SqliteSynchronous["normal"] = "NORMAL";
24
+ SqliteSynchronous["full"] = "FULL";
25
+ SqliteSynchronous["off"] = "OFF";
26
+ })(SqliteSynchronous || (SqliteSynchronous = {}));
27
+ export const DEFAULT_SQLITE_OPTIONS = {
28
+ journalMode: SqliteJournalMode.wal,
29
+ synchronous: SqliteSynchronous.normal,
30
+ journalSizeLimit: 6 * 1024 * 1024,
31
+ cacheSizeKb: 50 * 1024,
32
+ temporaryStorage: TemporaryStorageOption.MEMORY,
33
+ lockTimeoutMs: 30000,
34
+ encryptionKey: null,
35
+ extensions: []
36
+ };
37
+ //# sourceMappingURL=SqliteOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteOptions.js","sourceRoot":"","sources":["../../../../src/db/adapters/op-sqlite/SqliteOptions.ts"],"names":[],"mappings":"AAyDA,MAAM,CAAN,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,6CAAmB,CAAA;AACrB,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,QAGjC;AAED,sDAAsD;AACtD,wEAAwE;AACxE,+BAA+B;AAC/B,IAAK,iBASJ;AATD,WAAK,iBAAiB;IACpB,uDAAuD;IACvD,kDAAkD;IAClD,gCAAW,CAAA;IACX,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,gCAAW,CAAA;AACb,CAAC,EATI,iBAAiB,KAAjB,iBAAiB,QASrB;AAED,2BAA2B;AAC3B,IAAK,iBAIJ;AAJD,WAAK,iBAAiB;IACpB,sCAAiB,CAAA;IACjB,kCAAa,CAAA;IACb,gCAAW,CAAA;AACb,CAAC,EAJI,iBAAiB,KAAjB,iBAAiB,QAIrB;AAED,MAAM,CAAC,MAAM,sBAAsB,GAA4B;IAC7D,WAAW,EAAE,iBAAiB,CAAC,GAAG;IAClC,WAAW,EAAE,iBAAiB,CAAC,MAAM;IACrC,gBAAgB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IACjC,WAAW,EAAE,EAAE,GAAG,IAAI;IACtB,gBAAgB,EAAE,sBAAsB,CAAC,MAAM;IAC/C,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,EAAE;CACf,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from '@powersync/common';
2
2
  export * from '@powersync/react';
3
3
  export * from './db/PowerSyncDatabase';
4
- export * from './db/adapters/react-native-quick-sqlite/RNQSDBAdapter';
5
- export * from './db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory';
4
+ export { PowerSyncFetchImplementation } from './sync/stream/fetch';
6
5
  export * from './sync/stream/ReactNativeRemote';
7
6
  export * from './sync/stream/ReactNativeStreamingSyncImplementation';
8
- export * from './db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
package/lib/index.js CHANGED
@@ -2,9 +2,6 @@
2
2
  export * from '@powersync/common';
3
3
  export * from '@powersync/react';
4
4
  export * from './db/PowerSyncDatabase';
5
- export * from './db/adapters/react-native-quick-sqlite/RNQSDBAdapter';
6
- export * from './db/adapters/react-native-quick-sqlite/RNQSDBOpenFactory';
7
5
  export * from './sync/stream/ReactNativeRemote';
8
6
  export * from './sync/stream/ReactNativeStreamingSyncImplementation';
9
- export * from './db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
10
7
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uDAAuD,CAAC;AACtE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,iCAAiC,CAAC;AAChD,cAAc,sDAAsD,CAAC;AACrE,cAAc,2EAA2E,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sDAAsD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { PowerSyncControlCommand, SqliteBucketStorage } from '@powersync/common';
1
+ import { PowerSyncControlCommand, SqliteBucketStorage } from '@powersync/shared-internals';
2
2
  export declare class ReactNativeBucketStorageAdapter extends SqliteBucketStorage {
3
3
  control(op: PowerSyncControlCommand, payload: string | Uint8Array | ArrayBuffer | null): Promise<string>;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { SqliteBucketStorage } from '@powersync/common';
1
+ import { SqliteBucketStorage } from '@powersync/shared-internals';
2
2
  export class ReactNativeBucketStorageAdapter extends SqliteBucketStorage {
3
3
  control(op, payload) {
4
4
  if (payload instanceof Uint8Array) {
@@ -1 +1 @@
1
- {"version":3,"file":"ReactNativeBucketStorageAdapter.js","sourceRoot":"","sources":["../../../src/sync/bucket/ReactNativeBucketStorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEjF,MAAM,OAAO,+BAAgC,SAAQ,mBAAmB;IACtE,OAAO,CAAC,EAA2B,EAAE,OAAiD;QACpF,IAAI,OAAO,YAAY,UAAU,EAAE,CAAC;YAClC,2EAA2E;YAC3E,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;CACF;AAED,SAAS,uBAAuB,CAAC,KAAiB;IAChD,mFAAmF;IACnF,MAAM,WAAW,GAAG,KAAK,CAAC,MAAqB,CAAC;IAChD,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;QACxE,gDAAgD;QAChD,OAAO,WAAW,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,sBAAsB;QACtB,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAClF,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"ReactNativeBucketStorageAdapter.js","sourceRoot":"","sources":["../../../src/sync/bucket/ReactNativeBucketStorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE3F,MAAM,OAAO,+BAAgC,SAAQ,mBAAmB;IACtE,OAAO,CAAC,EAA2B,EAAE,OAAiD;QACpF,IAAI,OAAO,YAAY,UAAU,EAAE,CAAC;YAClC,2EAA2E;YAC3E,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;CACF;AAED,SAAS,uBAAuB,CAAC,KAAiB;IAChD,mFAAmF;IACnF,MAAM,WAAW,GAAG,KAAK,CAAC,MAAqB,CAAC;IAChD,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;QACxE,gDAAgD;QAChD,OAAO,WAAW,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,sBAAsB;QACtB,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAClF,CAAC;AACH,CAAC"}
@@ -1,16 +1,16 @@
1
- import { AbstractRemote, AbstractRemoteOptions, FetchImplementation, ILogger, RemoteConnector, SyncStreamOptions } from '@powersync/common';
2
- import { TextDecoder } from 'text-encoding';
1
+ import { PowerSyncLogger } from '@powersync/common';
2
+ import { AbstractRemote, FetchOptions, RemoteConnector } from '@powersync/shared-internals';
3
+ import { WebSocketSupport, WebSocketSyncStreamPlatform } from '@powersync/shared-internals/websockets';
4
+ import { PowerSyncFetchImplementation } from './fetch';
3
5
  export declare const STREAMING_POST_TIMEOUT_MS = 30000;
6
+ export interface ReactNativeRemoteOptions {
7
+ fetchImplementation?: PowerSyncFetchImplementation;
8
+ }
4
9
  export declare class ReactNativeRemote extends AbstractRemote {
5
10
  protected connector: RemoteConnector;
6
- protected logger: ILogger;
7
- constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
8
- get fetch(): FetchImplementation;
11
+ readonly options?: ReactNativeRemoteOptions | undefined;
12
+ constructor(connector: RemoteConnector, logger: PowerSyncLogger, options?: ReactNativeRemoteOptions | undefined);
13
+ protected fetch(options: FetchOptions): Promise<Response>;
14
+ protected loadWebSocketSupport(platform: WebSocketSyncStreamPlatform): Promise<WebSocketSupport>;
9
15
  getUserAgent(): string;
10
- createTextDecoder(): TextDecoder;
11
- protected get supportsStreamingBinaryResponses(): boolean;
12
- protected fetchStreamRaw(options: SyncStreamOptions): Promise<{
13
- isBson: boolean;
14
- stream: import("@powersync/common").SimpleAsyncIterator<Uint8Array>;
15
- }>;
16
16
  }
@@ -1,41 +1,50 @@
1
- import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
1
+ import { LogLevels } from '@powersync/common';
2
+ import { AbstractRemote } from '@powersync/shared-internals';
2
3
  import { Platform } from 'react-native';
3
- import { TextDecoder } from 'text-encoding';
4
- import { fetch } from 'react-native-fetch-api';
4
+ import { WebSocketSupport } from '@powersync/shared-internals/websockets';
5
+ import { defaultFetchImplementation } from './fetch';
5
6
  export const STREAMING_POST_TIMEOUT_MS = 30_000;
6
- /**
7
- * Directly imports fetch implementation from react-native-fetch-api.
8
- * This removes the requirement for the global `fetch` to be overridden by
9
- * a polyfill.
10
- */
11
- class ReactNativeFetchProvider extends FetchImplementationProvider {
12
- getFetch() {
13
- return fetch.bind(globalThis);
14
- }
15
- }
16
7
  export class ReactNativeRemote extends AbstractRemote {
17
8
  connector;
18
- logger;
19
- constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
20
- super(connector, logger, {
21
- ...(options ?? {}),
22
- fetchImplementation: options?.fetchImplementation ?? new ReactNativeFetchProvider()
23
- });
9
+ options;
10
+ constructor(connector, logger, options) {
11
+ super(connector, logger);
24
12
  this.connector = connector;
25
- this.logger = logger;
13
+ this.options = options;
14
+ }
15
+ async fetch(options) {
16
+ let timeout = null;
17
+ const { expectStreamingResponse } = options;
18
+ if (expectStreamingResponse) {
19
+ timeout =
20
+ Platform.OS == 'android'
21
+ ? setTimeout(() => {
22
+ this.logger.log({
23
+ level: LogLevels.warn,
24
+ message: `HTTP Streaming POST is taking longer than ${Math.ceil(STREAMING_POST_TIMEOUT_MS / 1000)} seconds to resolve. If using a debug build, please ensure Flipper Network plugin is disabled.`
25
+ });
26
+ }, STREAMING_POST_TIMEOUT_MS)
27
+ : null;
28
+ }
29
+ try {
30
+ const fetchImpl = this.options?.fetchImplementation ?? defaultFetchImplementation(this.logger);
31
+ if (expectStreamingResponse && !fetchImpl.supportsStreams) {
32
+ // We can't fall back to the default fetch() implementation since we need a response stream.
33
+ const errorMessage = 'The PowerSync SDK requires a fetch() implementation capable of streaming responses, which React Native ' +
34
+ 'does not support natively. The SDK was unable to import `expo/fetch`. ' +
35
+ "If you're not using expo, consider passing a custom fetchImplementation via the remote option on " +
36
+ 'the PowerSyncDatabase constructor, or use `SyncStreamConnectionMethod.WEB_SOCKET` on your connect() call.';
37
+ throw new Error(errorMessage);
38
+ }
39
+ return fetchImpl.run(options);
40
+ }
41
+ finally {
42
+ if (timeout != null)
43
+ clearTimeout(timeout);
44
+ }
26
45
  }
27
- get fetch() {
28
- const fetchImplementation = super.fetch;
29
- return ((input, init) => {
30
- const options = (init ?? {});
31
- return fetchImplementation(input, {
32
- ...options,
33
- reactNative: {
34
- ...(options.reactNative ?? {}),
35
- textStreaming: true
36
- }
37
- });
38
- });
46
+ loadWebSocketSupport(platform) {
47
+ return Promise.resolve((websockets ??= new WebSocketSupport(platform)));
39
48
  }
40
49
  getUserAgent() {
41
50
  return [
@@ -45,39 +54,6 @@ export class ReactNativeRemote extends AbstractRemote {
45
54
  `${Platform.OS}/${Platform.Version}`
46
55
  ].join(' ');
47
56
  }
48
- createTextDecoder() {
49
- return new TextDecoder();
50
- }
51
- get supportsStreamingBinaryResponses() {
52
- // We have to pass textStreaming: true to get streamed responses at all, and those don't support binary data.
53
- return false;
54
- }
55
- async fetchStreamRaw(options) {
56
- const timeout = Platform.OS == 'android'
57
- ? setTimeout(() => {
58
- this.logger.warn(`HTTP Streaming POST is taking longer than ${Math.ceil(STREAMING_POST_TIMEOUT_MS / 1000)} seconds to resolve. If using a debug build, please ensure Flipper Network plugin is disabled.`);
59
- }, STREAMING_POST_TIMEOUT_MS)
60
- : null;
61
- try {
62
- return await super.fetchStreamRaw({
63
- ...options,
64
- fetchOptions: {
65
- ...options.fetchOptions,
66
- /**
67
- * The `react-native-fetch-api` polyfill provides streaming support via
68
- * this non-standard flag
69
- * https://github.com/react-native-community/fetch#enable-text-streaming
70
- */
71
- // @ts-expect-error https://github.com/react-native-community/fetch#enable-text-streaming
72
- reactNative: { textStreaming: true }
73
- }
74
- });
75
- }
76
- finally {
77
- if (timeout) {
78
- clearTimeout(timeout);
79
- }
80
- }
81
- }
82
57
  }
58
+ let websockets;
83
59
  //# sourceMappingURL=ReactNativeRemote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReactNativeRemote.js","sourceRoot":"","sources":["../../../src/sync/stream/React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AwE;oBACxE,mGAAmG;oBACnG,2GAA2G,CAAC;gBAE9G,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;YAChC,CAAC;YAED,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC;gBAAS,CAAC;YACT,IAAI,OAAO,IAAI,IAAI;gBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,QAAqC;QAClE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,KAAK,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,YAAY;QACV,OAAO;YACL,KAAK,CAAC,YAAY,EAAE;YACpB,wBAAwB;YACxB,gBAAgB,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,IAAI,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE;YAC5G,GAAG,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,OAAO,EAAE;SACrC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,CAAC;CACF;AAED,IAAI,UAAwC,CAAC"}
@@ -1,4 +1,5 @@
1
- import { AbstractStreamingSyncImplementation, AbstractStreamingSyncImplementationOptions, LockOptions, LockType, Mutex } from '@powersync/common';
1
+ import { AbstractStreamingSyncImplementation, AbstractStreamingSyncImplementationOptions, LockOptions, LockType } from '@powersync/shared-internals';
2
+ import { Mutex } from '@powersync/shared-internals';
2
3
  export declare class ReactNativeStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
3
4
  locks: Map<LockType, Mutex>;
4
5
  constructor(options: AbstractStreamingSyncImplementationOptions);
@@ -1,4 +1,5 @@
1
- import { AbstractStreamingSyncImplementation, LockType, Mutex } from '@powersync/common';
1
+ import { AbstractStreamingSyncImplementation, LockType } from '@powersync/shared-internals';
2
+ import { Mutex } from '@powersync/shared-internals';
2
3
  /**
3
4
  * Global locks which prevent multiple instances from syncing
4
5
  * concurrently.
@@ -1 +1 @@
1
- {"version":3,"file":"ReactNativeStreamingSyncImplementation.js","sourceRoot":"","sources":["../../../src/sync/stream/ReactNativeStreamingSyncImplementation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EAGnC,QAAQ,EACR,KAAK,EACN,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;AAEtD,MAAM,OAAO,sCAAuC,SAAQ,mCAAmC;IAC7F,KAAK,CAAuB;IAE5B,YAAY,OAAmD;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACpC,IAAI,UAAU,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;YACpC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC;QAE3C,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,UAAU,CAAI,WAA2B;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,aAAa,WAAW,CAAC,IAAI,YAAY,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;YAClC,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;CACF"}
1
+ {"version":3,"file":"ReactNativeStreamingSyncImplementation.js","sourceRoot":"","sources":["../../../src/sync/stream/ReactNativeStreamingSyncImplementation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EAGnC,QAAQ,EACT,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEpD;;;GAGG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;AAEtD,MAAM,OAAO,sCAAuC,SAAQ,mCAAmC;IAC7F,KAAK,CAAwB;IAE7B,YAAY,OAAmD;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACpC,IAAI,UAAU,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;YACpC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC;QAE3C,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,UAAU,CAAI,WAA2B;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,aAAa,WAAW,CAAC,IAAI,YAAY,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;YAClC,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { PowerSyncLogger } from '@powersync/common';
2
+ import { FetchOptions } from '@powersync/shared-internals';
3
+ export interface PowerSyncFetchImplementation {
4
+ /**
5
+ * Whether this fetch implementation supports streaming responses.
6
+ *
7
+ * The PowerSync service delivers sync data through a streaming (`Transfer-Encoding: chunked`) response, which is not
8
+ * supported by the default `fetch` polyfill on React Native.
9
+ */
10
+ readonly supportsStreams: boolean;
11
+ run(options: FetchOptions): Promise<Response>;
12
+ }
13
+ export declare function defaultFetchImplementation(logger: PowerSyncLogger): PowerSyncFetchImplementation;