Skip to content

Commit

Permalink
cleanup polyfill dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Apr 11, 2024
1 parent 6fc7e8c commit 1a8a8aa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 113 deletions.
7 changes: 1 addition & 6 deletions demos/react-native-supabase-group-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@tamagui/font-inter": "1.79.6",
"@tamagui/lucide-icons": "1.79.6",
"@tamagui/theme-base": "1.79.6",
"base-64": "^1.0.0",
"date-fns": "^2.30.0",
"expo": "~50.0.6",
"expo-crypto": "~12.8.0",
Expand All @@ -47,9 +46,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.73.4",
"react-native-fetch-api": "^3.0.0",
"react-native-gesture-handler": "~2.14.1",
"react-native-get-random-values": "~1.8.0",
"react-native-pager-view": "6.2.3",
"react-native-polyfill-globals": "^3.1.0",
"react-native-reanimated": "~3.6.2",
Expand All @@ -58,9 +55,7 @@
"react-native-svg": "14.1.0",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "0.19.9",
"tamagui": "1.79.6",
"text-encoding": "^0.7.0",
"web-streams-polyfill": "^3.2.1"
"tamagui": "1.79.6"
},
"devDependencies": {
"@babel/core": "7.23.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@azure/core-asynciterator-polyfill';
import 'react-native-polyfill-globals/auto';
import 'react-native-get-random-values';
import { PowerSyncContext, RNQSPowerSyncDatabaseOpenFactory } from '@journeyapps/powersync-sdk-react-native';
import { ReactNode, useMemo } from 'react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@azure/core-asynciterator-polyfill';
import 'react-native-polyfill-globals/auto';
import 'react-native-get-random-values';
import React from 'react';
import { AbstractPowerSyncDatabase, RNQSPowerSyncDatabaseOpenFactory } from '@journeyapps/powersync-sdk-react-native';
import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter';
Expand Down
2 changes: 0 additions & 2 deletions demos/react-native-supabase-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"react-native-elements": "^3.4.3",
"react-native-encrypted-storage": "^4.0.3",
"react-native-gesture-handler": "~2.14.1",
"react-native-get-random-values": "~1.10.0",
"react-native-prompt-android": "^1.1.0",
"react-native-reanimated": "~3.6.2",
"react-native-reanimated-table": "^0.0.2",
Expand All @@ -50,7 +49,6 @@
"react-native-screens": "~3.29.0",
"react-native-vector-icons": "^10.0.0",
"react-navigation-stack": "^2.10.4",
"text-encoding": "^0.7.0",
"uuid": "3.4.0"
},
"devDependencies": {
Expand Down
49 changes: 24 additions & 25 deletions packages/powersync-sdk-react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,43 @@ npx expo install @journeyapps/react-native-quick-sqlite

This SDK can connect to a PowerSync instance via HTTP streams or Web sockets. Different polyfill configurations are required for each method.

### Common Polyfills
### React Native Common Polyfills

The following polyfills are required for general use of the SDK:
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).

- base-64
Install the collection of polyfills with:

- react-native-get-random-values
This is required for BSON and UUID generation
```bash
npx expo install react-native-polyfill-globals
```

- text-encoding
Required for BSON and NDJSON streaming of sync events
The `react-native-polyfill-globals` package includes peer dependencies for individual functions. Most modern package managers install peer dependencies by default. If peer dependencies are explicitly installed, install them manually with:

```bash
npx expo install react-native-polyfill-globals base-64 react-native-get-random-values text-encoding
npx expo install react-native-fetch-api react-native-polyfill-globals react-native-url-polyfill text-encoding web-streams-polyfill base-64 react-native-get-random-values
```

### HTTP Streams
Enable the polyfills in React Native app by adding the following in your top level entry point

The following `fetch` polyfills are required for the React Native implementation of `fetch`:
```JavaScript
// App.js
import 'react-native-polyfill-globals/auto';
```

### Random Values

- react-native-fetch-api
Required for live streaming of sync events
- react-native-url-polyfill
- web-streams-polyfill
This packages uses the `uuid` library for generating UUIDs. This requires `crypto.getRandomValues` to be available.

These are listed as peer dependencies and need to be added to the React Native project
Install [react-native-get-random-values](https://github.com/LinusU/react-native-get-random-values)

```bash
npx expo install react-native-fetch-api react-native-url-polyfill text-encoding web-streams-polyfill
npx expo install react-native-get-random-values
```

Import the polyfill in our app entry point

```javascript
import 'react-native-get-random-values'
```

### Web sockets
Expand Down Expand Up @@ -92,15 +100,6 @@ if (typeof process.nextTick == 'undefined') {
}
```

### Enable Global Polyfills

Enable the polyfills in React Native app with

```JavaScript
// App.js
import 'react-native-polyfill-globals/auto';
```

### Babel Plugins: Watched Queries

Watched queries require support for Async Iterators. Expo apps currently require polyfill and Babel plugins in order to use this functionality.
Expand Down
10 changes: 2 additions & 8 deletions packages/powersync-sdk-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@
"homepage": "https://docs.powersync.com/",
"peerDependencies": {
"@journeyapps/react-native-quick-sqlite": "^1.1.3",
"base-64": "^1.0.0",
"react": "*",
"react-native": "*",
"react-native-fetch-api": "^3.0.0",
"react-native-get-random-values": "^1.9.0",
"react-native-polyfill-globals": "^3.1.0",
"react-native-url-polyfill": "^2.0.0",
"text-encoding": "^0.7.0",
"web-streams-polyfill": "^3.2.1"

},
"dependencies": {
"@craftzdog/react-native-buffer": "^6.0.5",
"@journeyapps/powersync-react": "workspace:*",
"@journeyapps/powersync-sdk-common": "workspace:*",
"async-lock": "^1.4.0",
"react-native-quick-base64": "^2.0.8"
"async-lock": "^1.4.0"
},
"devDependencies": {
"@journeyapps/react-native-quick-sqlite": "^1.1.3",
Expand Down
72 changes: 0 additions & 72 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a8a8aa

Please sign in to comment.