@powersync/react-native 1.7.1 → 1.8.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.
@@ -1,6 +1,25 @@
1
- import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, PowerSyncBackendConnector, BucketStorageAdapter } from '@powersync/common';
1
+ import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, PowerSyncBackendConnector, BucketStorageAdapter, DBAdapter, SQLOpenOptions } from '@powersync/common';
2
+ /**
3
+ * A PowerSync database which provides SQLite functionality
4
+ * which is automatically synced.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * export const db = new PowerSyncDatabase({
9
+ * schema: AppSchema,
10
+ * database: {
11
+ * dbFilename: 'example.db'
12
+ * }
13
+ * });
14
+ * ```
15
+ */
2
16
  export declare class PowerSyncDatabase extends AbstractPowerSyncDatabase {
3
17
  _initialize(): Promise<void>;
18
+ /**
19
+ * Opens a DBAdapter using React Native Quick SQLite as the
20
+ * default SQLite open factory.
21
+ */
22
+ protected openDBAdapter(options: SQLOpenOptions): DBAdapter;
4
23
  protected generateBucketStorageAdapter(): BucketStorageAdapter;
5
24
  protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector): AbstractStreamingSyncImplementation;
6
25
  }
@@ -1,8 +1,31 @@
1
1
  import { AbstractPowerSyncDatabase, SqliteBucketStorage } from '@powersync/common';
2
2
  import { ReactNativeRemote } from '../sync/stream/ReactNativeRemote';
3
3
  import { ReactNativeStreamingSyncImplementation } from '../sync/stream/ReactNativeStreamingSyncImplementation';
4
+ import { ReactNativeQuickSqliteOpenFactory } from './adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
5
+ /**
6
+ * A PowerSync database which provides SQLite functionality
7
+ * which is automatically synced.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * export const db = new PowerSyncDatabase({
12
+ * schema: AppSchema,
13
+ * database: {
14
+ * dbFilename: 'example.db'
15
+ * }
16
+ * });
17
+ * ```
18
+ */
4
19
  export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
5
20
  async _initialize() { }
21
+ /**
22
+ * Opens a DBAdapter using React Native Quick SQLite as the
23
+ * default SQLite open factory.
24
+ */
25
+ openDBAdapter(options) {
26
+ const defaultFactory = new ReactNativeQuickSqliteOpenFactory(options);
27
+ return defaultFactory.openDB();
28
+ }
6
29
  generateBucketStorageAdapter() {
7
30
  return new SqliteBucketStorage(this.database, AbstractPowerSyncDatabase.transactionMutex);
8
31
  }
@@ -17,7 +40,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
17
40
  },
18
41
  retryDelayMs: this.options.retryDelay,
19
42
  crudUploadThrottleMs: this.options.crudUploadThrottleMs,
20
- identifier: this.options.database.name
43
+ identifier: this.database.name
21
44
  });
22
45
  }
23
46
  }
@@ -1,6 +1,18 @@
1
- import { AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, DBAdapter, PowerSyncDatabaseOptions, PowerSyncOpenFactoryOptions } from '@powersync/common';
1
+ import { AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, DBAdapter, PowerSyncDatabaseOptions, PowerSyncOpenFactoryOptions, SQLOpenFactory } from '@powersync/common';
2
+ /**
3
+ * @deprecated {@link PowerSyncDatabase} can now be constructed directly
4
+ * @example
5
+ * ```typescript
6
+ * const powersync = new PowerSyncDatabase({
7
+ * database: {
8
+ * dbFileName: 'powersync.db'
9
+ * }
10
+ * });
11
+ * ```
12
+ */
2
13
  export declare class RNQSPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseOpenFactory {
3
14
  protected instanceGenerated: boolean;
15
+ protected sqlOpenFactory: SQLOpenFactory;
4
16
  constructor(options: PowerSyncOpenFactoryOptions);
5
17
  protected openDB(): DBAdapter;
6
18
  generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase;
@@ -1,39 +1,27 @@
1
- import { open, QuickSQLite } from '@journeyapps/react-native-quick-sqlite';
2
1
  import { AbstractPowerSyncDatabaseOpenFactory } from '@powersync/common';
3
2
  import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase';
4
- import { RNQSDBAdapter } from './RNQSDBAdapter';
3
+ import { ReactNativeQuickSqliteOpenFactory } from './ReactNativeQuickSQLiteOpenFactory';
4
+ /**
5
+ * @deprecated {@link PowerSyncDatabase} can now be constructed directly
6
+ * @example
7
+ * ```typescript
8
+ * const powersync = new PowerSyncDatabase({
9
+ * database: {
10
+ * dbFileName: 'powersync.db'
11
+ * }
12
+ * });
13
+ * ```
14
+ */
5
15
  export class RNQSPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseOpenFactory {
6
16
  instanceGenerated;
17
+ sqlOpenFactory;
7
18
  constructor(options) {
8
19
  super(options);
9
20
  this.instanceGenerated = false;
21
+ this.sqlOpenFactory = new ReactNativeQuickSqliteOpenFactory(options);
10
22
  }
11
23
  openDB() {
12
- /**
13
- * React Native Quick SQLite opens files relative to the `Documents`dir on iOS and the `Files`
14
- * dir on Android. Locations need to be relative to those dirs using with dot ("../") notation
15
- * to navigate up the directory tree.
16
- * This simple adapter assumes any platform specific relative directory is already catered for
17
- * in the options (if provided)
18
- * https://github.com/margelo/react-native-quick-sqlite/blob/main/README.md#loading-existing-dbs
19
- */
20
- const { dbFilename } = this.options;
21
- const openOptions = { location: this.options.dbLocation };
22
- let DB;
23
- try {
24
- // Hot reloads can sometimes clear global JS state, but not close DB on native side
25
- DB = open(dbFilename, openOptions);
26
- }
27
- catch (ex) {
28
- if (ex.message.includes('already open')) {
29
- QuickSQLite.close(dbFilename);
30
- DB = open(dbFilename, openOptions);
31
- }
32
- else {
33
- throw ex;
34
- }
35
- }
36
- return new RNQSDBAdapter(DB, this.options.dbFilename);
24
+ return this.sqlOpenFactory.openDB();
37
25
  }
38
26
  generateInstance(options) {
39
27
  if (this.instanceGenerated) {
@@ -0,0 +1,9 @@
1
+ import { DBAdapter, SQLOpenOptions, SQLOpenFactory } from '@powersync/common';
2
+ /**
3
+ * Opens a SQLite connection using React Native Quick SQLite
4
+ */
5
+ export declare class ReactNativeQuickSqliteOpenFactory implements SQLOpenFactory {
6
+ protected options: SQLOpenOptions;
7
+ constructor(options: SQLOpenOptions);
8
+ openDB(): DBAdapter;
9
+ }
@@ -0,0 +1,38 @@
1
+ import { open, QuickSQLite } from '@journeyapps/react-native-quick-sqlite';
2
+ import { RNQSDBAdapter } from './RNQSDBAdapter';
3
+ /**
4
+ * Opens a SQLite connection using React Native Quick SQLite
5
+ */
6
+ export class ReactNativeQuickSqliteOpenFactory {
7
+ options;
8
+ constructor(options) {
9
+ this.options = options;
10
+ }
11
+ openDB() {
12
+ /**
13
+ * React Native Quick SQLite opens files relative to the `Documents`dir on iOS and the `Files`
14
+ * dir on Android. Locations need to be relative to those dirs using with dot ("../") notation
15
+ * to navigate up the directory tree.
16
+ * This simple adapter assumes any platform specific relative directory is already catered for
17
+ * in the options (if provided)
18
+ * https://github.com/margelo/react-native-quick-sqlite/blob/main/README.md#loading-existing-dbs
19
+ */
20
+ const { dbFilename } = this.options;
21
+ const openOptions = { location: this.options.dbLocation };
22
+ let DB;
23
+ try {
24
+ // Hot reloads can sometimes clear global JS state, but not close DB on native side
25
+ DB = open(dbFilename, openOptions);
26
+ }
27
+ catch (ex) {
28
+ if (ex.message.includes('already open')) {
29
+ QuickSQLite.close(dbFilename);
30
+ DB = open(dbFilename, openOptions);
31
+ }
32
+ else {
33
+ throw ex;
34
+ }
35
+ }
36
+ return new RNQSDBAdapter(DB, this.options.dbFilename);
37
+ }
38
+ }
package/lib/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './db/adapters/react-native-quick-sqlite/RNQSDBAdapter';
5
5
  export * from './db/adapters/react-native-quick-sqlite//RNQSDBOpenFactory';
6
6
  export * from './sync/stream/ReactNativeRemote';
7
7
  export * from './sync/stream/ReactNativeStreamingSyncImplementation';
8
+ export * from './db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
package/lib/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './db/adapters/react-native-quick-sqlite/RNQSDBAdapter';
6
6
  export * from './db/adapters/react-native-quick-sqlite//RNQSDBOpenFactory';
7
7
  export * from './sync/stream/ReactNativeRemote';
8
8
  export * from './sync/stream/ReactNativeStreamingSyncImplementation';
9
+ export * from './db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/react-native",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -26,14 +26,14 @@
26
26
  "react": "*",
27
27
  "react-native": "*",
28
28
  "react-native-polyfill-globals": "^3.1.0",
29
- "@powersync/common": "^1.11.1"
29
+ "@powersync/common": "^1.13.01.13.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "async-lock": "^1.4.0",
33
33
  "bson": "^6.6.0",
34
34
  "react-native-fetch-api": "^3.0.0",
35
35
  "@powersync/react": "1.3.5",
36
- "@powersync/common": "1.11.1"
36
+ "@powersync/common": "1.13.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@journeyapps/react-native-quick-sqlite": "^1.1.6",