@powersync/op-sqlite 0.2.1 → 0.3.0

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 (45) hide show
  1. package/README.md +36 -0
  2. package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +4 -8
  3. package/ios/PowerSyncOpSqlite.mm +0 -5
  4. package/lib/commonjs/db/OPSqliteAdapter.js +18 -10
  5. package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
  6. package/lib/commonjs/db/SqliteOptions.js +2 -1
  7. package/lib/commonjs/db/SqliteOptions.js.map +1 -1
  8. package/lib/commonjs/index.js +0 -16
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/module/db/OPSqliteAdapter.js +20 -12
  11. package/lib/module/db/OPSqliteAdapter.js.map +1 -1
  12. package/lib/module/db/SqliteOptions.js +2 -1
  13. package/lib/module/db/SqliteOptions.js.map +1 -1
  14. package/lib/module/index.js +0 -15
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +2 -1
  17. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
  18. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +9 -1
  19. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/src/index.d.ts +0 -1
  21. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
  23. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +2 -1
  24. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
  25. package/lib/typescript/module/src/db/SqliteOptions.d.ts +9 -1
  26. package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +1 -1
  27. package/lib/typescript/module/src/index.d.ts +0 -1
  28. package/lib/typescript/module/src/index.d.ts.map +1 -1
  29. package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
  30. package/package.json +1 -1
  31. package/src/db/OPSqliteAdapter.ts +35 -12
  32. package/src/db/SqliteOptions.ts +12 -2
  33. package/src/index.ts +4 -30
  34. package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqliteModule.kt +0 -25
  35. package/android/src/newarch/PowerSyncOpSqliteSpec.kt +0 -7
  36. package/android/src/oldarch/PowerSyncOpSqliteSpec.kt +0 -11
  37. package/lib/commonjs/NativePowerSyncOpSqlite.js +0 -9
  38. package/lib/commonjs/NativePowerSyncOpSqlite.js.map +0 -1
  39. package/lib/module/NativePowerSyncOpSqlite.js +0 -5
  40. package/lib/module/NativePowerSyncOpSqlite.js.map +0 -1
  41. package/lib/typescript/commonjs/src/NativePowerSyncOpSqlite.d.ts +0 -7
  42. package/lib/typescript/commonjs/src/NativePowerSyncOpSqlite.d.ts.map +0 -1
  43. package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts +0 -7
  44. package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts.map +0 -1
  45. package/src/NativePowerSyncOpSqlite.ts +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/op-sqlite",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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",
@@ -1,8 +1,21 @@
1
- import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
2
- import { ANDROID_DATABASE_PATH, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
1
+ import {
2
+ BaseObserver,
3
+ DBAdapter,
4
+ DBAdapterListener,
5
+ DBLockOptions,
6
+ QueryResult,
7
+ Transaction
8
+ } from '@powersync/common';
9
+ import {
10
+ ANDROID_DATABASE_PATH,
11
+ getDylibPath,
12
+ IOS_LIBRARY_PATH,
13
+ open,
14
+ type DB
15
+ } from '@op-engineering/op-sqlite';
3
16
  import Lock from 'async-lock';
4
17
  import { OPSQLiteConnection } from './OPSQLiteConnection';
5
- import { NativeModules, Platform } from 'react-native';
18
+ import { Platform } from 'react-native';
6
19
  import { SqliteOptions } from './SqliteOptions';
7
20
 
8
21
  /**
@@ -44,7 +57,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
44
57
  }
45
58
 
46
59
  protected async init() {
47
- const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous, encryptionKey } = this.options.sqliteOptions;
60
+ const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous } = this.options.sqliteOptions!;
48
61
  const dbFilename = this.options.name;
49
62
 
50
63
  this.writeConnection = await this.openConnection(dbFilename);
@@ -86,10 +99,11 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
86
99
 
87
100
  protected async openConnection(filenameOverride?: string): Promise<OPSQLiteConnection> {
88
101
  const dbFilename = filenameOverride ?? this.options.name;
89
- const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions.encryptionKey);
102
+ const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
90
103
 
91
- //Load extension for all connections
92
- this.loadExtension(DB);
104
+ //Load extensions for all connections
105
+ this.loadAdditionalExtensions(DB);
106
+ this.loadPowerSyncExtension(DB);
93
107
 
94
108
  await DB.execute('SELECT powersync_init()');
95
109
 
@@ -124,10 +138,17 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
124
138
  }
125
139
  }
126
140
 
127
- private loadExtension(DB: DB) {
141
+ private loadAdditionalExtensions(DB: DB) {
142
+ if (this.options.sqliteOptions?.extensions && this.options.sqliteOptions.extensions.length > 0) {
143
+ for (const extension of this.options.sqliteOptions.extensions) {
144
+ DB.loadExtension(extension.path, extension.entryPoint);
145
+ }
146
+ }
147
+ }
148
+
149
+ private async loadPowerSyncExtension(DB: DB) {
128
150
  if (Platform.OS === 'ios') {
129
- const bundlePath: string = NativeModules.PowerSyncOpSqlite.getBundlePath();
130
- const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
151
+ const libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
131
152
  DB.loadExtension(libPath, 'sqlite3_powersync_init');
132
153
  } else {
133
154
  DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
@@ -271,8 +292,10 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
271
292
  await this.initialized;
272
293
  await this.writeConnection!.refreshSchema();
273
294
 
274
- for (let readConnection of this.readConnections) {
275
- await readConnection.connection.refreshSchema();
295
+ if(this.readConnections) {
296
+ for (let readConnection of this.readConnections) {
297
+ await readConnection.connection.refreshSchema();
298
+ }
276
299
  }
277
300
  }
278
301
  }
@@ -28,7 +28,16 @@ export interface SqliteOptions {
28
28
  * Encryption key for the database.
29
29
  * If set, the database will be encrypted using SQLCipher.
30
30
  */
31
- encryptionKey?: string;
31
+ encryptionKey?: string | null;
32
+
33
+ /**
34
+ * Load extensions using the path and entryPoint.
35
+ * More info can be found here https://op-engineering.github.io/op-sqlite/docs/api#loading-extensions.
36
+ */
37
+ extensions?: Array<{
38
+ path: string;
39
+ entryPoint?: string;
40
+ }>;
32
41
  }
33
42
 
34
43
  // SQLite journal mode. Set on the primary connection.
@@ -57,5 +66,6 @@ export const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions> = {
57
66
  synchronous: SqliteSynchronous.normal,
58
67
  journalSizeLimit: 6 * 1024 * 1024,
59
68
  lockTimeoutMs: 30000,
60
- encryptionKey: null
69
+ encryptionKey: null,
70
+ extensions: []
61
71
  };
package/src/index.ts CHANGED
@@ -1,30 +1,4 @@
1
- import { NativeModules, Platform } from 'react-native';
2
-
3
- const LINKING_ERROR =
4
- `The package '@powersync/op-sqlite' doesn't seem to be linked. Make sure: \n\n` +
5
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
- '- You rebuilt the app after installing the package\n' +
7
- '- You are not using Expo Go\n';
8
-
9
- const isTurboModuleEnabled = global.__turboModuleProxy != null;
10
-
11
- const PowerSyncOpSqliteModule = isTurboModuleEnabled
12
- ? require('./NativePowerSyncOpSqlite').default
13
- : NativeModules.PowerSyncOpSqlite;
14
-
15
- const PowerSyncOpSqlite = PowerSyncOpSqliteModule
16
- ? PowerSyncOpSqliteModule
17
- : new Proxy(
18
- {},
19
- {
20
- get() {
21
- throw new Error(LINKING_ERROR);
22
- }
23
- }
24
- );
25
-
26
- export function getBundlePath(): string {
27
- return PowerSyncOpSqlite.getBundlePath();
28
- }
29
-
30
- export { OPSqliteOpenFactory, OPSQLiteOpenFactoryOptions } from './db/OPSqliteDBOpenFactory';
1
+ export {
2
+ OPSqliteOpenFactory,
3
+ OPSQLiteOpenFactoryOptions
4
+ } from './db/OPSqliteDBOpenFactory';
@@ -1,25 +0,0 @@
1
- package com.powersync.opsqlite
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext
4
- import com.facebook.react.bridge.ReactMethod
5
- import com.facebook.react.bridge.Promise
6
-
7
- class PowerSyncOpSqliteModule internal constructor(context: ReactApplicationContext) :
8
- PowerSyncOpSqliteSpec(context) {
9
-
10
- @ReactMethod
11
- override fun getBundlePath(): String {
12
- //This method should only be used for iOS platforms
13
- //Ensure you wrap its usage with a (Platform.OS === 'ios') check
14
- //Returns an empty string for android
15
- return ""
16
- }
17
-
18
- override fun getName(): String {
19
- return NAME
20
- }
21
-
22
- companion object {
23
- const val NAME = "PowerSyncOpSqlite"
24
- }
25
- }
@@ -1,7 +0,0 @@
1
- package com.powersync.opsqlite
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext
4
-
5
- abstract class PowerSyncOpSqliteSpec internal constructor(context: ReactApplicationContext) :
6
- NativePowerSyncOpSqliteSpec(context) {
7
- }
@@ -1,11 +0,0 @@
1
- package com.powersync.opsqlite
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext
4
- import com.facebook.react.bridge.ReactContextBaseJavaModule
5
- import com.facebook.react.bridge.Promise
6
-
7
- abstract class PowerSyncOpSqliteSpec internal constructor(context: ReactApplicationContext) :
8
- ReactContextBaseJavaModule(context) {
9
-
10
- abstract fun getBundlePath(): String
11
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _reactNative = require("react-native");
8
- var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('PowerSyncOpSqlite');
9
- //# sourceMappingURL=NativePowerSyncOpSqlite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePowerSyncOpSqlite.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAMpCC,gCAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- import { TurboModuleRegistry } from 'react-native';
4
- export default TurboModuleRegistry.getEnforcing('PowerSyncOpSqlite');
5
- //# sourceMappingURL=NativePowerSyncOpSqlite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePowerSyncOpSqlite.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAMlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import type { TurboModule } from 'react-native';
2
- export interface Spec extends TurboModule {
3
- getBundlePath(): string;
4
- }
5
- declare const _default: Spec;
6
- export default _default;
7
- //# sourceMappingURL=NativePowerSyncOpSqlite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativePowerSyncOpSqlite.d.ts","sourceRoot":"","sources":["../../../../src/NativePowerSyncOpSqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,aAAa,IAAI,MAAM,CAAC;CACzB;;AAED,wBAA2E"}
@@ -1,7 +0,0 @@
1
- import type { TurboModule } from 'react-native';
2
- export interface Spec extends TurboModule {
3
- getBundlePath(): string;
4
- }
5
- declare const _default: Spec;
6
- export default _default;
7
- //# sourceMappingURL=NativePowerSyncOpSqlite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativePowerSyncOpSqlite.d.ts","sourceRoot":"","sources":["../../../../src/NativePowerSyncOpSqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,aAAa,IAAI,MAAM,CAAC;CACzB;;AAED,wBAA2E"}
@@ -1,8 +0,0 @@
1
- import type { TurboModule } from 'react-native';
2
- import { TurboModuleRegistry } from 'react-native';
3
-
4
- export interface Spec extends TurboModule {
5
- getBundlePath(): string;
6
- }
7
-
8
- export default TurboModuleRegistry.getEnforcing<Spec>('PowerSyncOpSqlite');