Skip to content

Commit ef19be3

Browse files
Merge pull request #53 from powersync-community/staging
chore: Add OPFS & Rust Sync Client
2 parents baa4ca8 + c84b42a commit ef19be3

File tree

5 files changed

+96
-65
lines changed

5 files changed

+96
-65
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
A templated Vite, TS, React, PowerSync and Supabase project to get you started quickly with building offline-first applications with PowerSync and Supabase.
66

7+
🚀 [Live Demo](https://vite-react-ts-powersync-supabase.up.railway.app/) 🚀
8+
79
# Usage
810

911
## Install dependencies

eslint.config.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ import globals from 'globals'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
55
import tseslint from 'typescript-eslint'
6-
import { globalIgnores } from 'eslint/config'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
77

8-
export default tseslint.config([
8+
export default defineConfig([
99
globalIgnores(['dist']),
10+
js.configs.recommended,
11+
...tseslint.configs.recommended,
1012
{
1113
files: ['**/*.{ts,tsx}'],
12-
extends: [
13-
js.configs.recommended,
14-
tseslint.configs.recommended,
15-
reactHooks.configs['recommended-latest'],
16-
reactRefresh.configs.vite,
17-
],
14+
plugins: {
15+
'react-hooks': reactHooks,
16+
'react-refresh': reactRefresh,
17+
},
1818
languageOptions: {
1919
ecmaVersion: 2020,
2020
globals: globals.browser,
2121
},
22+
rules: {
23+
...reactHooks.configs.recommended.rules,
24+
'react-refresh/only-export-components': [
25+
'warn',
26+
{ allowConstantExport: true },
27+
],
28+
},
2229
},
2330
])

package-lock.json

Lines changed: 46 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"type-check": "tsc --noEmit"
1414
},
1515
"dependencies": {
16-
"@journeyapps/wa-sqlite": "^1.3.2",
17-
"@powersync/react": "^1.8.1",
18-
"@powersync/web": "^1.27.1",
16+
"@journeyapps/wa-sqlite": "^1.3.3",
17+
"@powersync/react": "^1.8.2",
18+
"@powersync/web": "^1.29.0",
1919
"@supabase/supabase-js": "^2.76.1",
2020
"react": "^19.2.0",
2121
"react-dom": "^19.2.0",

src/powersync/System.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {
22
createBaseLogger,
33
LogLevel,
44
PowerSyncDatabase,
5+
SyncClientImplementation,
6+
WASQLiteOpenFactory,
7+
WASQLiteVFS
58
} from "@powersync/web";
69
import { AppSchema } from "./AppSchema";
710
import { connector } from "./SupabaseConnector";
@@ -11,17 +14,17 @@ logger.useDefaults();
1114
logger.setLevel(LogLevel.DEBUG);
1215

1316
/**
14-
* Default configuration - uses IndexedDB storage
17+
* Default configuration AccessHandlePoolVFS - uses IndexedDB
1518
* ✅ Use this for: Simple setup, most browsers
1619
* ❌ Avoid if: You need Safari support or have stability issues
1720
*/
18-
export const powerSync = new PowerSyncDatabase({
19-
schema: AppSchema,
20-
database: {
21-
dbFilename: 'example.db'
22-
},
23-
logger: logger
24-
});
21+
// export const powerSync = new PowerSyncDatabase({
22+
// schema: AppSchema,
23+
// database: {
24+
// dbFilename: 'example.db'
25+
// },
26+
// logger: logger
27+
// });
2528

2629
/**
2730
* Alternative configuration with OPFS storage (Origin Private File System)
@@ -41,20 +44,20 @@ export const powerSync = new PowerSyncDatabase({
4144
*
4245
* 📚 Learn more: https://docs.powersync.com/client-sdk-references/javascript-web#sqlite-virtual-file-systems
4346
*/
44-
// export const powerSync = new PowerSyncDatabase({
45-
// database: new WASQLiteOpenFactory({
46-
// dbFilename: "exampleVFS.db",
47-
// vfs: WASQLiteVFS.OPFSCoopSyncVFS, // Use AccessHandlePoolVFS for single-tab only
48-
// flags: {
49-
// enableMultiTabs: typeof SharedWorker !== "undefined",
50-
// },
51-
// }),
52-
// flags: {
53-
// enableMultiTabs: typeof SharedWorker !== "undefined",
54-
// },
55-
// schema: AppSchema,
56-
// logger: logger,
57-
// });
47+
export const powerSync = new PowerSyncDatabase({
48+
database: new WASQLiteOpenFactory({
49+
dbFilename: "exampleVFS.db",
50+
vfs: WASQLiteVFS.OPFSCoopSyncVFS, // Use AccessHandlePoolVFS for single-tab only
51+
flags: {
52+
enableMultiTabs: typeof SharedWorker !== "undefined",
53+
},
54+
}),
55+
flags: {
56+
enableMultiTabs: typeof SharedWorker !== "undefined",
57+
},
58+
schema: AppSchema,
59+
logger: logger,
60+
});
5861

5962
/**
6063
* Quick Decision Guide:
@@ -69,4 +72,8 @@ export const powerSync = new PowerSyncDatabase({
6972
await connector.signInAnonymously();
7073

7174
// Establish connection between PowerSync and the Supabase connector
72-
powerSync.connect(connector);
75+
powerSync.connect(connector, {
76+
// Rust based implementation is more efficient and faster than the JavaScript implementation
77+
clientImplementation: SyncClientImplementation.RUST,
78+
crudUploadThrottleMs: 5000
79+
});

0 commit comments

Comments
 (0)