Skip to content

Commit 7ed2fad

Browse files
authored
Merge pull request #848 from powersync-ja/sync-streams-vue
(feat): [Vue/Nuxt] Added Sync Streams support and improved overall feature parity with the React SDK.
2 parents aa3d3d6 + e7f9716 commit 7ed2fad

19 files changed

Lines changed: 1528 additions & 706 deletions

.changeset/friendly-points-ring.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
'@powersync/vue': minor
3+
---
4+
5+
Add support for Sync Streams for Vue
6+
7+
Subscribing to a sync stream and using its status:
8+
9+
```
10+
<script setup>
11+
import { useSyncStream } from '@powersync/vue';
12+
13+
14+
const { status } = useSyncStream('my-stream', { parameters: { userId: 'user-123' } });
15+
16+
// both the name and parameters can be reactive
17+
const streamName = ref('my-stream')
18+
const streamOptions = ref({ parameters: { userId: 'user-123' } })
19+
20+
useSyncStream(streamName, streamOptions);
21+
</script>
22+
23+
<template>
24+
<div v-if="status">
25+
<span v-if="status.hasSynced">Stream synced</span>
26+
<span v-else>Syncing...</span>
27+
</div>
28+
</template>
29+
```
30+
31+
Running a query backed by sync streams:
32+
33+
```
34+
<script setup>
35+
import { useQuery } from '@powersync/vue';
36+
37+
// Subscribe to streams; query runs immediately
38+
const { data } = useQuery('SELECT * FROM lists', [], {
39+
streams: [{ name: 'lists-stream' }]
40+
});
41+
42+
// Or wait for the stream to sync before showing results
43+
const { data: lists, isLoading } = useQuery('SELECT * FROM lists', [], {
44+
streams: [{ name: 'lists-stream', waitForStream: true }]
45+
});
46+
</script>
47+
```

.changeset/light-dingos-stare.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@powersync/nuxt': minor
3+
---
4+
5+
Expose Sync Streams comosable to use in Nuxt with auto-imports
6+
7+
Example:
8+
9+
```
10+
<script setup lang="ts">
11+
// useSyncStream is auto-imported in Nuxt
12+
const streamName = ref('my-stream');
13+
const { status } = useSyncStream(streamName, { parameters: { id: 'abc' } });
14+
</script>
15+
16+
<template>
17+
<div v-if="status?.hasSynced">Stream ready</div>
18+
<div v-else>Syncing...</div>
19+
</template>
20+
```
Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
export default defineNuxtConfig({
2-
3-
modules: [
4-
'@powersync/nuxt',
5-
'@nuxt/eslint',
6-
'@nuxt/ui',
7-
'@nuxtjs/supabase',
8-
],
2+
modules: ['@powersync/nuxt', '@nuxt/eslint', '@nuxt/ui', '@nuxtjs/supabase'],
93
ssr: false,
104

115
devtools: {
12-
enabled: true,
6+
enabled: true
137
},
148

159
css: ['~/assets/css/main.css'],
1610

1711
runtimeConfig: {
1812
public: {
19-
powersyncUrl: process.env.NUXT_PUBLIC_POWERSYNC_URL,
20-
},
13+
powersyncUrl: process.env.NUXT_PUBLIC_POWERSYNC_URL
14+
}
2115
},
2216

2317
// enable hot reloading when we make changes to our module
@@ -27,30 +21,28 @@ export default defineNuxtConfig({
2721

2822
vite: {
2923
optimizeDeps: {
30-
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
31-
include: [
32-
'@supabase/postgrest-js',
33-
],
24+
exclude: ['@powersync/web'],
25+
include: ['@supabase/postgrest-js']
3426
},
3527

3628
worker: {
37-
format: 'es',
38-
},
29+
format: 'es'
30+
}
3931
},
4032

4133
unocss: {
42-
autoImport: false,
34+
autoImport: false
4335
},
4436

4537
eslint: {
4638
config: {
47-
stylistic: true,
48-
},
39+
stylistic: true
40+
}
4941
},
5042

5143
powersync: {
5244
useDiagnostics: true,
53-
kysely: true,
45+
kysely: true
5446
},
5547

5648
supabase: {
@@ -59,12 +51,12 @@ export default defineNuxtConfig({
5951
redirectOptions: {
6052
login: '/login',
6153
callback: '/confirm',
62-
exclude: ['/unprotected', '/public/*'],
54+
exclude: ['/unprotected', '/public/*']
6355
},
6456
clientOptions: {
6557
auth: {
66-
persistSession: true,
67-
},
68-
},
69-
},
70-
})
58+
persistSession: true
59+
}
60+
}
61+
}
62+
});

0 commit comments

Comments
 (0)