@powersync/react-native 0.0.0-dev-20240722121738 → 0.0.0-dev-20240726145618

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.
package/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  # PowerSync SDK for React Native
6
6
 
7
- _[PowerSync](https://www.powersync.com) is a Postgres-SQLite sync layer, which helps developers to create local-first real-time reactive apps that work seamlessly both online and offline._
7
+ *[PowerSync](https://www.powersync.com) is a Postgres-SQLite sync layer, which helps developers to create local-first real-time reactive apps that work seamlessly both online and offline.*
8
8
 
9
- This package (`packages/react-native`) is the PowerSync SDK for React Native clients. It is an extension of `packages/common`. It connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets.
9
+ This package (`packages/react-native`) is the PowerSync SDK for React Native clients. It is an extension of `packages/common`.
10
10
 
11
11
  See a summary of features [here](https://docs.powersync.co/client-sdk-references/react-native-and-expo).
12
12
 
@@ -30,7 +30,68 @@ npx expo install @journeyapps/react-native-quick-sqlite
30
30
 
31
31
  ## Install Polyfills
32
32
 
33
- - Polyfills are required for [watched queries](#babel-plugins-watched-queries) using the Async Iterator response format.
33
+ This package connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets.
34
+ * Both connection methods require the [React Native Common Polyfills](#react-native-common-polyfills), as detailed below.
35
+ * The WebSocket method requires an [additional polyfill](#web-sockets-buffer) for the `Buffer` interface.
36
+ * Other polyfills are required for [watched queries](#babel-plugins-watched-queries) using the Async Iterator response format.
37
+
38
+ ### React Native Common Polyfills
39
+
40
+ This package requires polyfills for HTTP streaming and other text encoding functions. These functions can be provided with [react-native-polyfill-globals](https://www.npmjs.com/package/react-native-polyfill-globals).
41
+
42
+ Install the collection of polyfills with:
43
+
44
+ ```bash
45
+ npx expo install react-native-polyfill-globals
46
+ ```
47
+
48
+ The `react-native-polyfill-globals` package uses peer dependencies for individual functions. Most modern package managers install peer dependencies by default, however currently the peer dependency version ranges are quite broad and might result in certain packages being incompatible. Currently an [issue](https://github.com/acostalima/react-native-polyfill-globals/issues/6) is open for a breaking change in one of the dependencies. The best practice is to currently add the packages as explicit dependencies with version ranges to your project with the command below.
49
+
50
+ ```bash
51
+ npx expo install react-native-fetch-api@^3.0.0 react-native-url-polyfill@^2.0.0 text-encoding@^0.7.0 web-streams-polyfill@3.2.1 base-64@^1.0.0
52
+ ```
53
+
54
+ Enable the polyfills in React Native app by adding the following in your top level entry point
55
+
56
+ ```JavaScript
57
+ // App.js
58
+ import 'react-native-polyfill-globals/auto';
59
+ ```
60
+
61
+ ### HTTP Connections
62
+
63
+ HTTP connections require the HTTP streaming polyfills included in the [common section](#react-native-common-polyfills). See additional [setup](https://docs.powersync.com/client-sdk-references/react-native-and-expo#android-flipper-network-plugin) required for Android.
64
+
65
+ ### WebSocket Connections: Buffer
66
+
67
+ Note: Beta Release - WebSockets are currently in a beta release. It should be safe to use in production if sufficient testing is done on the client side.
68
+
69
+ Our WebSocket implementation supports binary payloads which are encoded as BSON documents.
70
+
71
+ This requires support for the `Buffer` interface.
72
+
73
+ Apply the `Buffer` polyfill
74
+
75
+ ```bash
76
+ npx expo install @craftzdog/react-native-buffer
77
+ ```
78
+
79
+ ```javascript
80
+ import { Buffer } from '@craftzdog/react-native-buffer';
81
+
82
+ if (typeof global.Buffer == 'undefined') {
83
+ // @ts-ignore If using TypeScript
84
+ global.Buffer = Buffer;
85
+ }
86
+ ```
87
+
88
+ This library uses `RSocket` for reactive WebSocket streams which requires `process.nextTick` to be available. Apply a polyfill if not available.
89
+
90
+ ```javascript
91
+ if (typeof process.nextTick == 'undefined') {
92
+ process.nextTick = setImmediate;
93
+ }
94
+ ```
34
95
 
35
96
  ### Babel Plugins: Watched Queries
36
97
 
@@ -1,4 +1,4 @@
1
- import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, PowerSyncBackendConnector, BucketStorageAdapter, DBAdapter, SQLOpenOptions } from '@powersync/common';
1
+ import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, BucketStorageAdapter, DBAdapter, PowerSyncBackendConnector, PowerSyncDatabaseOptionsWithSettings } from '@powersync/common';
2
2
  /**
3
3
  * A PowerSync database which provides SQLite functionality
4
4
  * which is automatically synced.
@@ -19,7 +19,7 @@ export declare class PowerSyncDatabase extends AbstractPowerSyncDatabase {
19
19
  * Opens a DBAdapter using React Native Quick SQLite as the
20
20
  * default SQLite open factory.
21
21
  */
22
- protected openDBAdapter(options: SQLOpenOptions): DBAdapter;
22
+ protected openDBAdapter(options: PowerSyncDatabaseOptionsWithSettings): DBAdapter;
23
23
  protected generateBucketStorageAdapter(): BucketStorageAdapter;
24
24
  protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector): AbstractStreamingSyncImplementation;
25
25
  }
@@ -23,7 +23,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
23
23
  * default SQLite open factory.
24
24
  */
25
25
  openDBAdapter(options) {
26
- const defaultFactory = new ReactNativeQuickSqliteOpenFactory(options);
26
+ const defaultFactory = new ReactNativeQuickSqliteOpenFactory(options.database);
27
27
  return defaultFactory.openDB();
28
28
  }
29
29
  generateBucketStorageAdapter() {
@@ -44,4 +44,3 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
44
44
  });
45
45
  }
46
46
  }
47
- //# sourceMappingURL=PowerSyncDatabase.js.map
@@ -98,4 +98,3 @@ export class RNQSDBAdapter extends BaseObserver {
98
98
  };
99
99
  }
100
100
  }
101
- //# sourceMappingURL=RNQSDBAdapter.js.map
@@ -31,4 +31,3 @@ export class RNQSPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseO
31
31
  return new PowerSyncDatabase(options);
32
32
  }
33
33
  }
34
- //# sourceMappingURL=RNQSDBOpenFactory.js.map
@@ -36,4 +36,3 @@ export class ReactNativeQuickSqliteOpenFactory {
36
36
  return new RNQSDBAdapter(DB, this.options.dbFilename);
37
37
  }
38
38
  }
39
- //# sourceMappingURL=ReactNativeQuickSQLiteOpenFactory.js.map
package/lib/index.js CHANGED
@@ -7,4 +7,3 @@ export * from './db/adapters/react-native-quick-sqlite//RNQSDBOpenFactory';
7
7
  export * from './sync/stream/ReactNativeRemote';
8
8
  export * from './sync/stream/ReactNativeStreamingSyncImplementation';
9
9
  export * from './db/adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
10
- //# sourceMappingURL=index.js.map
@@ -14,6 +14,44 @@ class ReactNativeFetchProvider extends FetchImplementationProvider {
14
14
  return fetch.bind(globalThis);
15
15
  }
16
16
  }
17
+ const CommonPolyfills = [
18
+ {
19
+ name: 'TextEncoder',
20
+ test: () => typeof TextEncoder == 'undefined'
21
+ }
22
+ ];
23
+ const SocketPolyfillTests = [
24
+ ...CommonPolyfills,
25
+ {
26
+ name: 'nextTick',
27
+ test: () => typeof process.nextTick == 'undefined'
28
+ },
29
+ {
30
+ name: 'Buffer',
31
+ test: () => typeof global.Buffer == 'undefined'
32
+ }
33
+ ];
34
+ const HttpPolyfillTests = [
35
+ ...CommonPolyfills,
36
+ {
37
+ name: 'TextDecoder',
38
+ test: () => typeof TextDecoder == 'undefined'
39
+ },
40
+ {
41
+ name: 'ReadableStream',
42
+ test: () => typeof ReadableStream == 'undefined'
43
+ }
44
+ ];
45
+ const validatePolyfills = (tests) => {
46
+ const missingPolyfills = tests.filter((t) => t.test()).map((t) => t.name);
47
+ if (missingPolyfills.length) {
48
+ throw new Error(`
49
+ Polyfills are undefined. Please ensure React Native polyfills are installed and imported in the app entrypoint.
50
+ See package README for detailed instructions.
51
+ The following polyfills appear to be missing:
52
+ ${missingPolyfills.join('\n')}`);
53
+ }
54
+ };
17
55
  export class ReactNativeRemote extends AbstractRemote {
18
56
  connector;
19
57
  logger;
@@ -29,9 +67,11 @@ export class ReactNativeRemote extends AbstractRemote {
29
67
  return BSON;
30
68
  }
31
69
  async socketStream(options) {
70
+ validatePolyfills(SocketPolyfillTests);
32
71
  return super.socketStream(options);
33
72
  }
34
73
  async postStream(options) {
74
+ validatePolyfills(HttpPolyfillTests);
35
75
  const timeout = Platform.OS == 'android'
36
76
  ? setTimeout(() => {
37
77
  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.`);
@@ -56,4 +96,3 @@ export class ReactNativeRemote extends AbstractRemote {
56
96
  return result;
57
97
  }
58
98
  }
59
- //# sourceMappingURL=ReactNativeRemote.js.map
@@ -40,4 +40,3 @@ export class ReactNativeStreamingSyncImplementation extends AbstractStreamingSyn
40
40
  });
41
41
  }
42
42
  }
43
- //# sourceMappingURL=ReactNativeStreamingSyncImplementation.js.map
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@powersync/react-native",
3
- "version": "0.0.0-dev-20240722121738",
3
+ "version": "0.0.0-dev-20240726145618",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
7
7
  },
8
8
  "description": "PowerSync - sync Postgres with SQLite in your React Native app for offline-first and real-time data",
9
- "main": "./dist/index.js",
9
+ "main": "./lib/index.js",
10
10
  "types": "./lib/index.d.ts",
11
11
  "files": [
12
- "lib",
13
- "dist"
12
+ "lib"
14
13
  ],
15
14
  "repository": {
16
15
  "type": "git",
@@ -26,32 +25,22 @@
26
25
  "@journeyapps/react-native-quick-sqlite": "^1.1.8",
27
26
  "react": "*",
28
27
  "react-native": "*",
29
- "@powersync/common": "^0.0.0-dev-20240722121738"
28
+ "react-native-polyfill-globals": "^3.1.0",
29
+ "@powersync/common": "0.0.0-dev-20240726145618"
30
30
  },
31
31
  "dependencies": {
32
- "@powersync/common": "0.0.0-dev-20240722121738",
33
- "@powersync/react": "0.0.0-dev-20240722121738"
32
+ "async-lock": "^1.4.0",
33
+ "bson": "^6.6.0",
34
+ "react-native-fetch-api": "^3.0.0",
35
+ "@powersync/react": "1.3.8",
36
+ "@powersync/common": "0.0.0-dev-20240726145618"
34
37
  },
35
38
  "devDependencies": {
36
- "@craftzdog/react-native-buffer": "^6.0.5",
37
39
  "@journeyapps/react-native-quick-sqlite": "^1.1.8",
38
- "@rollup/plugin-alias": "^5.1.0",
39
- "@rollup/plugin-commonjs": "^25.0.7",
40
- "@rollup/plugin-inject": "^5.0.5",
41
- "@rollup/plugin-json": "^6.1.0",
42
- "@rollup/plugin-node-resolve": "15.2.3",
43
- "@rollup/plugin-replace": "^5.0.7",
44
40
  "@types/async-lock": "^1.4.0",
45
- "async-lock": "^1.4.0",
46
- "bson": "^6.6.0",
47
- "fast-base64-decode": "^1.0.0",
48
41
  "react": "18.2.0",
49
42
  "react-native": "0.72.4",
50
- "react-native-fetch-api": "^3.0.0",
51
- "rollup": "4.14.3",
52
- "text-encoding": "^0.7.0",
53
- "typescript": "^5.5.3",
54
- "web-streams-polyfill": "3.2.1"
43
+ "typescript": "^5.5.3"
55
44
  },
56
45
  "keywords": [
57
46
  "data sync",
@@ -61,7 +50,7 @@
61
50
  "live data"
62
51
  ],
63
52
  "scripts": {
64
- "build": "tsc -b && rollup -c rollup.config.mjs",
53
+ "build": "tsc -b",
65
54
  "clean": "rm -rf lib tsconfig.tsbuildinfo",
66
55
  "watch": "tsc -b -w"
67
56
  }