Skip to content

Commit

Permalink
Started updating dependencies and polyfills.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriztiaan committed Jul 17, 2024
1 parent c84ac1c commit d9ccb77
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 276 deletions.
10 changes: 0 additions & 10 deletions demos/django-react-native-todolist/library/stores/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@ import '@azure/core-asynciterator-polyfill';
import 'react-native-polyfill-globals/auto';
import React from 'react';
import { AbstractPowerSyncDatabase, PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/react-native';
import { Buffer } from '@craftzdog/react-native-buffer';
import { AppSchema } from '../powersync/AppSchema';
import { DjangoConnector } from '../django/DjangoConnector';

if (typeof process.nextTick == 'undefined') {
process.nextTick = setImmediate;
}

if (typeof global.Buffer == 'undefined') {
// @ts-ignore
global.Buffer = Buffer;
}

export class System {
djangoConnector: DjangoConnector;
powersync: AbstractPowerSyncDatabase;
Expand Down
1 change: 0 additions & 1 deletion demos/django-react-native-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"dependencies": {
"@azure/core-asynciterator-polyfill": "^1.0.2",
"@craftzdog/react-native-buffer": "^6.0.5",
"@expo/vector-icons": "^14.0.0",
"@journeyapps/react-native-quick-sqlite": "^1.1.7",
"@powersync/common": "workspace:*",
Expand Down
9 changes: 1 addition & 8 deletions demos/example-capacitor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > uuid',
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [wasm(), topLevelAwait()],
worker: {
Expand Down
12 changes: 1 addition & 11 deletions demos/example-electron/vite.renderer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ export default defineConfig((env) => {
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [
// @ts-expect-error there is TS issue that doesn't actually affect the runtime
Expand Down
1 change: 0 additions & 1 deletion demos/example-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@mui/material": "^5.15.18",
"@powersync/react": "workspace:*",
"@powersync/web": "workspace:*",
"buffer": "^6.0.3",
"js-logger": "^1.6.1",
"lato-font": "^3.0.0",
"lexical": "^0.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import { CircularProgress } from '@mui/material';
import Logger from 'js-logger';
import React, { Suspense } from 'react';

import { Buffer } from 'buffer';

// Polyfill for WebSockets
if (typeof self.Buffer == 'undefined') {
self.Buffer = Buffer;
}

// eslint-disable-next-line react-hooks/rules-of-hooks
Logger.useDefaults();
Logger.setLevel(Logger.DEBUG);
Expand Down
12 changes: 1 addition & 11 deletions demos/example-vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [wasm(), topLevelAwait()],
worker: {
Expand Down
12 changes: 1 addition & 11 deletions demos/react-multi-client/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [
wasm(),
Expand Down
20 changes: 10 additions & 10 deletions demos/react-native-supabase-todolist/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ PODS:
- ExpoModulesCore
- ExpoAsset (10.0.10):
- ExpoModulesCore
- ExpoCamera (15.0.12):
- ExpoCamera (15.0.14):
- ExpoModulesCore
- ZXingObjC/OneD
- ZXingObjC/PDF417
- ExpoCrypto (13.0.2):
- ExpoModulesCore
- ExpoFileSystem (17.0.1):
- ExpoModulesCore
- ExpoFont (12.0.7):
- ExpoFont (12.0.9):
- ExpoModulesCore
- ExpoHead (3.5.15):
- ExpoModulesCore
Expand Down Expand Up @@ -1005,7 +1005,7 @@ PODS:
- React-debug
- react-native-encrypted-storage (4.0.3):
- React-Core
- react-native-quick-sqlite (1.1.7):
- react-native-quick-sqlite (1.1.8):
- powersync-sqlite-core (~> 0.1.6)
- React
- React-callinvoker
Expand Down Expand Up @@ -1340,15 +1340,15 @@ DEPENDENCIES:
- boost (from `../../../node_modules/react-native/third-party-podspecs/boost.podspec`)
- DoubleConversion (from `../../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- EXConstants (from `../../../node_modules/expo-constants/ios`)
- Expo (from `../../../node_modules/expo`)
- Expo (from `../node_modules/expo`)
- ExpoAsset (from `../../../node_modules/expo-asset/ios`)
- ExpoCamera (from `../../../node_modules/expo-camera/ios`)
- ExpoCrypto (from `../../../node_modules/expo-crypto/ios`)
- ExpoFileSystem (from `../../../node_modules/expo-file-system/ios`)
- ExpoFont (from `../../../node_modules/expo-font/ios`)
- ExpoHead (from `../../../node_modules/expo-router/ios`)
- ExpoKeepAwake (from `../../../node_modules/expo-keep-awake/ios`)
- ExpoModulesCore (from `../../../node_modules/expo-modules-core`)
- ExpoModulesCore (from `../node_modules/expo-modules-core`)
- ExpoSecureStore (from `../../../node_modules/expo-secure-store/ios`)
- EXSplashScreen (from `../../../node_modules/expo-splash-screen/ios`)
- FBLazyVector (from `../../../node_modules/react-native/Libraries/FBLazyVector`)
Expand Down Expand Up @@ -1428,7 +1428,7 @@ EXTERNAL SOURCES:
EXConstants:
:path: "../../../node_modules/expo-constants/ios"
Expo:
:path: "../../../node_modules/expo"
:path: "../node_modules/expo"
ExpoAsset:
:path: "../../../node_modules/expo-asset/ios"
ExpoCamera:
Expand All @@ -1444,7 +1444,7 @@ EXTERNAL SOURCES:
ExpoKeepAwake:
:path: "../../../node_modules/expo-keep-awake/ios"
ExpoModulesCore:
:path: "../../../node_modules/expo-modules-core"
:path: "../node_modules/expo-modules-core"
ExpoSecureStore:
:path: "../../../node_modules/expo-secure-store/ios"
EXSplashScreen:
Expand Down Expand Up @@ -1577,10 +1577,10 @@ SPEC CHECKSUMS:
EXConstants: 409690fbfd5afea964e5e9d6c4eb2c2b59222c59
Expo: 3bc69739da02780763c1fd66dde56f84fc46d0d8
ExpoAsset: 323700f291684f110fb55f0d4022a3362ea9f875
ExpoCamera: 7ab9e10ffef972d5bdb0f1a815ba19f86a6284ed
ExpoCamera: a5d000b22cd7dfd2c5904ed960e549de42c96da0
ExpoCrypto: 156078f266bf28f80ecf5e2a9c3a0d6ffce07a1c
ExpoFileSystem: 80bfe850b1f9922c16905822ecbf97acd711dc51
ExpoFont: 43b69559cef3d773db57c7ae7edd3cb0aa0dc610
ExpoFont: e7f2275c10ca8573c991e007329ad6bf98086485
ExpoHead: 8eb4deb289c2fdd8bb624f996cd31414cd07f38a
ExpoKeepAwake: 3b8815d9dd1d419ee474df004021c69fdd316d08
ExpoModulesCore: a4b45b5f081f5fe9b8e87667906d180cd52f32d7
Expand Down Expand Up @@ -1616,7 +1616,7 @@ SPEC CHECKSUMS:
React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce
React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-quick-sqlite: e563f1ed38b4064be3cb61366bf1c7560f9581dc
react-native-quick-sqlite: 7ad498d81c8506803da2e1c2b64c8cb7758e04cb
react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d
React-nativeconfig: b0073a590774e8b35192fead188a36d1dca23dec
React-NativeModulesApple: df46ff3e3de5b842b30b4ca8a6caae6d7c8ab09f
Expand Down
1 change: 0 additions & 1 deletion demos/react-native-supabase-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"dependencies": {
"@azure/core-asynciterator-polyfill": "^1.0.2",
"@craftzdog/react-native-buffer": "^6.0.5",
"@expo/vector-icons": "^14.0.0",
"@journeyapps/react-native-quick-sqlite": "^1.1.7",
"@powersync/attachments": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion demos/react-supabase-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@mui/material": "^5.15.12",
"@mui/x-data-grid": "^6.19.6",
"@supabase/supabase-js": "^2.39.7",
"buffer": "^6.0.3",
"formik": "^2.4.6",
"js-logger": "^1.6.1",
"lodash": "^4.17.21",
Expand Down
12 changes: 1 addition & 11 deletions demos/react-supabase-todolist/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite']
// include: [
// '@powersync/web > event-iterator',
// '@powersync/web > js-logger',
// '@powersync/web > lodash/throttle',
// '@powersync/web > can-ndjson-stream',
// '@powersync/web > buffer',
// '@powersync/web > rsocket-core',
// '@powersync/web > rsocket-websocket-client',
// '@powersync/web > cross-fetch'
// ]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [
wasm(),
Expand Down
12 changes: 1 addition & 11 deletions demos/vue-supabase-todolist/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
worker: {
format: 'es',
Expand Down
12 changes: 1 addition & 11 deletions demos/yjs-react-supabase-text-collab/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ export default defineConfig({
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
exclude: ['@journeyapps/wa-sqlite', '@powersync/web']
},
plugins: [
wasm(),
Expand Down
40 changes: 6 additions & 34 deletions packages/react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# PowerSync SDK for React Native

*[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.*
_[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._

This package (`packages/react-native`) is the PowerSync SDK for React Native clients. It is an extension of `packages/common`.

Expand All @@ -30,10 +30,11 @@ npx expo install @journeyapps/react-native-quick-sqlite

## Install Polyfills

This package connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets.
* Both connection methods require the [React Native Common Polyfills](#react-native-common-polyfills), as detailed below.
* The WebSocket method requires an [additional polyfill](#web-sockets-buffer) for the `Buffer` interface.
* Other polyfills are required for [watched queries](#babel-plugins-watched-queries) using the Async Iterator response format.
This package connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets.

- Both connection methods require the [React Native Common Polyfills](#react-native-common-polyfills), as detailed below.
- The WebSocket method requires an [additional polyfill](#web-sockets-buffer) for the `Buffer` interface.
- Other polyfills are required for [watched queries](#babel-plugins-watched-queries) using the Async Iterator response format.

### React Native Common Polyfills

Expand Down Expand Up @@ -62,37 +63,8 @@ import 'react-native-polyfill-globals/auto';

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.

### WebSocket Connections: Buffer

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.

Our WebSocket implementation supports binary payloads which are encoded as BSON documents.

This requires support for the `Buffer` interface.

Apply the `Buffer` polyfill

```bash
npx expo install @craftzdog/react-native-buffer
```

```javascript
import { Buffer } from '@craftzdog/react-native-buffer';

if (typeof global.Buffer == 'undefined') {
// @ts-ignore If using TypeScript
global.Buffer = Buffer;
}
```

This library uses `RSocket` for reactive WebSocket streams which requires `process.nextTick` to be available. Apply a polyfill if not available.

```javascript
if (typeof process.nextTick == 'undefined') {
process.nextTick = setImmediate;
}
```

### Babel Plugins: Watched Queries

Watched queries can be used with either a callback response or Async Iterator response.
Expand Down
26 changes: 1 addition & 25 deletions packages/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# PowerSync SDK for Web

*[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.*
_[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._

This package (`packages/web`) is the PowerSync SDK for JavaScript Web clients. It is an extension of `packages/common`.

Expand All @@ -28,30 +28,6 @@ Install it in your app with:
npm install @journeyapps/wa-sqlite
```

## Polyfills

### WebSocket Connections: Buffer

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.

This SDK connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets. The WebSocket connection method requires `Buffer` to be available in the global scope. When multiple tabs are used the shared web worker will apply a polyfill in its own scope, but the `Buffer` class should be polyfills in the application for cases where multiple tabs are not supported.

Install a suitable Buffer implementation

```bash
npm install buffer
```

Apply it in your application if not yet provided

```Javascript
import { Buffer } from 'buffer';

if (typeof self.Buffer == 'undefined') {
self.Buffer = Buffer;
}
```

## Webpack

See the [example Webpack config](https://github.com/powersync-ja/powersync-js/blob/main/demos/example-webpack/webpack.config.js) for details on polyfills and requirements.
Expand Down
2 changes: 0 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
"@types/uuid": "^9.0.6",
"@vitest/browser": "^1.3.1",
"rollup": "4.14.3",
"rollup-plugin-web-worker-loader": "^1.6.1",
"rollup-plugin-workers": "^2.1.1",
"typescript": "^5.2.2",
"uuid": "^9.0.1",
"vite": "^5.1.1",
Expand Down
Loading

0 comments on commit d9ccb77

Please sign in to comment.