@powersync/op-sqlite 0.0.0-dev-20250604135557 → 0.0.0-dev-20250609122429

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 (31) hide show
  1. package/README.md +0 -9
  2. package/lib/commonjs/db/OPSqliteAdapter.js +9 -45
  3. package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
  4. package/lib/commonjs/db/SqliteOptions.js +1 -8
  5. package/lib/commonjs/db/SqliteOptions.js.map +1 -1
  6. package/lib/commonjs/index.js +0 -16
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/module/db/OPSqliteAdapter.js +9 -45
  9. package/lib/module/db/OPSqliteAdapter.js.map +1 -1
  10. package/lib/module/db/SqliteOptions.js +0 -7
  11. package/lib/module/db/SqliteOptions.js.map +1 -1
  12. package/lib/module/index.js +0 -1
  13. package/lib/module/index.js.map +1 -1
  14. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +1 -9
  15. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
  16. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +0 -16
  17. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +1 -1
  18. package/lib/typescript/commonjs/src/index.d.ts +0 -1
  19. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
  21. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +1 -9
  22. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
  23. package/lib/typescript/module/src/db/SqliteOptions.d.ts +0 -16
  24. package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +1 -1
  25. package/lib/typescript/module/src/index.d.ts +0 -1
  26. package/lib/typescript/module/src/index.d.ts.map +1 -1
  27. package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
  28. package/package.json +3 -3
  29. package/src/db/OPSqliteAdapter.ts +10 -61
  30. package/src/db/SqliteOptions.ts +0 -19
  31. package/src/index.ts +4 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/op-sqlite",
3
- "version": "0.0.0-dev-20250604135557",
3
+ "version": "0.0.0-dev-20250609122429",
4
4
  "description": "PowerSync - sync Postgres or MongoDB with SQLite in your React Native app for offline-first and real-time data",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
@@ -59,13 +59,13 @@
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@op-engineering/op-sqlite": "^13.0.0 || ^14.0.0",
62
- "@powersync/common": "^1.31.1",
62
+ "@powersync/common": "0.0.0-dev-20250609122429",
63
63
  "react": "*",
64
64
  "react-native": "*"
65
65
  },
66
66
  "dependencies": {
67
67
  "async-lock": "^1.4.0",
68
- "@powersync/common": "1.31.1"
68
+ "@powersync/common": "0.0.0-dev-20250609122429"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@op-engineering/op-sqlite": "^14.0.2",
@@ -3,7 +3,7 @@ import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult,
3
3
  import Lock from 'async-lock';
4
4
  import { Platform } from 'react-native';
5
5
  import { OPSQLiteConnection } from './OPSQLiteConnection';
6
- import { CipherVersion, SqliteOptions } from './SqliteOptions';
6
+ import { SqliteOptions } from './SqliteOptions';
7
7
 
8
8
  /**
9
9
  * Adapter for React Native Quick SQLite
@@ -50,7 +50,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
50
50
  this.options.sqliteOptions!;
51
51
  const dbFilename = this.options.name;
52
52
 
53
- this.writeConnection = await this.openConnection(dbFilename, true);
53
+ this.writeConnection = await this.openConnection(dbFilename);
54
54
 
55
55
  const baseStatements = [
56
56
  `PRAGMA busy_timeout = ${lockTimeoutMs}`,
@@ -97,13 +97,9 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
97
97
  }
98
98
  }
99
99
 
100
- protected async openConnection(filenameOverride?: string, writeConnection?: boolean): Promise<OPSQLiteConnection> {
100
+ protected async openConnection(filenameOverride?: string): Promise<OPSQLiteConnection> {
101
101
  const dbFilename = filenameOverride ?? this.options.name;
102
- const DB: DB = await this.openDatabase(
103
- dbFilename,
104
- this.options.sqliteOptions?.encryptionKey ?? undefined,
105
- writeConnection
106
- );
102
+ const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
107
103
 
108
104
  //Load extensions for all connections
109
105
  this.loadAdditionalExtensions(DB);
@@ -124,69 +120,22 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
124
120
  }
125
121
  }
126
122
 
127
- private async openDatabase(dbFilename: string, encryptionKey?: string, writeConnection?: boolean): Promise<DB> {
123
+ private openDatabase(dbFilename: string, encryptionKey?: string): DB {
128
124
  //This is needed because an undefined/null dbLocation will cause the open function to fail
129
125
  const location = this.getDbLocation(this.options.dbLocation);
130
126
  //Simarlily if the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
131
127
  if (encryptionKey) {
132
- return await this.openSQLCipher(dbFilename, location, encryptionKey, writeConnection);
133
- } else {
134
128
  return open({
135
- name: dbFilename,
136
- location: location
137
- });
138
- }
139
- }
140
-
141
- /**
142
- * We set up SQLCipher compatibility here.
143
- *
144
- * - For compability with SQLCipher 3 databases, we set the cipher_compatibility pragma to 3 for all connections.
145
- * - For upgrading SQLCipher 3 databases to version 4, we do the migration on the write connection.
146
- * - For SQLCipher 4 databases, we do not need to set the cipher_compatibility pragma, as it is the default.
147
- */
148
- private async openSQLCipher(
149
- dbFilename: string,
150
- location: string,
151
- encryptionKey?: string,
152
- writeConnection?: boolean
153
- ): Promise<DB> {
154
- const openDb = () =>
155
- open({
156
129
  name: dbFilename,
157
130
  location: location,
158
131
  encryptionKey: encryptionKey
159
132
  });
160
- const db = openDb();
161
-
162
- const cipherVersion = this.options.sqliteOptions?.cipherVersion;
163
-
164
- if (cipherVersion == CipherVersion.VERSION_3) {
165
- await db.execute('PRAGMA cipher_compatibility = 3;');
166
- return db;
167
- } else if (cipherVersion == CipherVersion.UPGRADE_3_TO_4 && writeConnection) {
168
- // Based on steps described at https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_migrate
169
- try {
170
- // Valid version agnostic query to confirm SQLCipher version
171
- await db.execute('SELECT count(*) FROM sqlite_master;');
172
- // Query succeeded, so we are on SQLCipher 4 and don't have to do anything
173
- console.log('SQLCipher 4 database detected, no migration needed.');
174
- return db;
175
- } catch (e: any) {
176
- // Query failed, assuming we are on SQLCipher 3 and need to upgrade
177
- // Catch any error
178
- }
179
-
180
- db.close();
181
- const reopenedDB = openDb();
182
-
183
- const migrationResult = await reopenedDB.execute('PRAGMA cipher_migrate;');
184
- console.log('SQLCipher migration result:', migrationResult);
185
-
186
- return reopenedDB;
133
+ } else {
134
+ return open({
135
+ name: dbFilename,
136
+ location: location
137
+ });
187
138
  }
188
-
189
- return db;
190
139
  }
191
140
 
192
141
  private loadAdditionalExtensions(DB: DB) {
@@ -30,18 +30,6 @@ export interface SqliteOptions {
30
30
  */
31
31
  encryptionKey?: string | null;
32
32
 
33
- /**
34
- * SQLCipher version compatibility option. Only applicable when encryptionKey is set.
35
- *
36
- * - '4': Use SQLCipher 4 format (recommended for new databases)
37
- * - 'upgrade3to4': Automatically attempt to upgrade SQLCipher 3 databases to version 4
38
- * - '3': Use SQLCipher 3 compatibility mode for existing databases (used by default)
39
- *
40
- * Note: The 'upgrade3to4' option will attempt migration only when needed and may
41
- * be expensive on first run. Migration requires the correct encryption key.
42
- */
43
- cipherVersion?: CipherVersion | null;
44
-
45
33
  /**
46
34
  * Where to store SQLite temporary files. Defaults to 'MEMORY'.
47
35
  * Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
@@ -67,12 +55,6 @@ export interface SqliteOptions {
67
55
  }>;
68
56
  }
69
57
 
70
- export enum CipherVersion {
71
- VERSION_4 = '4',
72
- UPGRADE_3_TO_4 = 'upgrade3to4',
73
- VERSION_3 = '3'
74
- }
75
-
76
58
  export enum TemporaryStorageOption {
77
59
  MEMORY = 'memory',
78
60
  FILESYSTEM = 'file'
@@ -107,6 +89,5 @@ export const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions> = {
107
89
  temporaryStorage: TemporaryStorageOption.MEMORY,
108
90
  lockTimeoutMs: 30000,
109
91
  encryptionKey: null,
110
- cipherVersion: CipherVersion.VERSION_3,
111
92
  extensions: []
112
93
  };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { OPSqliteOpenFactory, OPSQLiteOpenFactoryOptions } from './db/OPSqliteDBOpenFactory';
2
-
3
- export * from './db/SqliteOptions';
1
+ export {
2
+ OPSqliteOpenFactory,
3
+ OPSQLiteOpenFactoryOptions
4
+ } from './db/OPSqliteDBOpenFactory';