@powersync/nuxt 0.0.1 → 0.0.3

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
@@ -5,6 +5,11 @@
5
5
  <p>Effortless offline-first development with PowerSync integration for Nuxt applications.</p>
6
6
  </div>
7
7
 
8
+ > [!NOTE]
9
+ > The Nuxt package is currently in an **alpha** state, intended strictly for testing. Expect breaking changes and instability as development continues.
10
+ >
11
+ > Do not rely on this package for production use.
12
+
8
13
  [![npm version][npm-version-src]][npm-version-href]
9
14
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
10
15
  [![License][license-src]][license-href]
@@ -28,11 +33,9 @@ This module re-exports all `@powersync/vue` composables. With **npm** (v7+), ins
28
33
  ```bash
29
34
  # Using npm
30
35
  npm install @powersync/nuxt
31
- npm install --save-dev vite-plugin-top-level-await vite-plugin-wasm
32
36
 
33
37
  # Using pnpm (peer deps are not auto-installed)
34
38
  pnpm add @powersync/nuxt @powersync/vue @powersync/web
35
- pnpm add -D vite-plugin-top-level-await vite-plugin-wasm
36
39
  ```
37
40
 
38
41
  > [!NOTE]
@@ -45,21 +48,17 @@ For a complete working app, see the [Nuxt + Supabase Todo List demo](https://git
45
48
  1. Add `@powersync/nuxt` to the `modules` section of `nuxt.config.ts`:
46
49
 
47
50
  ```typescript
48
- import wasm from 'vite-plugin-wasm'
49
-
50
51
  export default defineNuxtConfig({
51
52
  modules: ['@powersync/nuxt'],
52
53
  vite: {
53
54
  optimizeDeps: {
54
- exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
55
- include: ['@powersync/web > js-logger'], // <-- Include `js-logger` when it isn't installed and imported.
55
+ exclude: ['@powersync/web']
56
56
  },
57
57
  worker: {
58
- format: 'es',
59
- plugins: () => [wasm()],
60
- },
61
- },
62
- })
58
+ format: 'es'
59
+ }
60
+ }
61
+ });
63
62
  ```
64
63
 
65
64
  > [!WARNING]
@@ -68,29 +67,29 @@ export default defineNuxtConfig({
68
67
  2. Create a PowerSync plugin (e.g., `plugins/powersync.client.ts`):
69
68
 
70
69
  ```typescript
71
- import { NuxtPowerSyncDatabase } from '@powersync/nuxt'
72
- import { createPowerSyncPlugin } from '@powersync/nuxt'
73
- import { AppSchema } from '~/powersync/AppSchema'
74
- import { PowerSyncConnector } from '~/powersync/PowerSyncConnector'
70
+ import { NuxtPowerSyncDatabase } from '@powersync/nuxt';
71
+ import { createPowerSyncPlugin } from '@powersync/nuxt';
72
+ import { AppSchema } from '~/powersync/AppSchema';
73
+ import { PowerSyncConnector } from '~/powersync/PowerSyncConnector';
75
74
 
76
75
  export default defineNuxtPlugin({
77
76
  async setup(nuxtApp) {
78
77
  const db = new NuxtPowerSyncDatabase({
79
78
  database: {
80
- dbFilename: 'your-db-filename.sqlite',
79
+ dbFilename: 'your-db-filename.sqlite'
81
80
  },
82
- schema: AppSchema,
83
- })
81
+ schema: AppSchema
82
+ });
84
83
 
85
- const connector = new PowerSyncConnector()
84
+ const connector = new PowerSyncConnector();
86
85
 
87
- await db.init()
88
- await db.connect(connector)
86
+ await db.init();
87
+ await db.connect(connector);
89
88
 
90
- const plugin = createPowerSyncPlugin({ database: db })
91
- nuxtApp.vueApp.use(plugin)
92
- },
93
- })
89
+ const plugin = createPowerSyncPlugin({ database: db });
90
+ nuxtApp.vueApp.use(plugin);
91
+ }
92
+ });
94
93
  ```
95
94
 
96
95
  At this point, you're all set to use the module composables. The module automatically exposes all `@powersync/vue` composables, so you can use them directly:
@@ -108,13 +107,13 @@ This guide will walk you through the steps to set up PowerSync in your Nuxt proj
108
107
  Create a file called `AppSchema.ts` and add your schema to it.
109
108
 
110
109
  ```typescript
111
- import { column, Schema, Table } from '@powersync/web'
110
+ import { column, Schema, Table } from '@powersync/web';
112
111
 
113
112
  const lists = new Table({
114
113
  created_at: column.text,
115
114
  name: column.text,
116
- owner_id: column.text,
117
- })
115
+ owner_id: column.text
116
+ });
118
117
 
119
118
  const todos = new Table(
120
119
  {
@@ -124,20 +123,20 @@ const todos = new Table(
124
123
  description: column.text,
125
124
  created_by: column.text,
126
125
  completed_by: column.text,
127
- completed: column.integer,
126
+ completed: column.integer
128
127
  },
129
- { indexes: { list: ['list_id'] } },
130
- )
128
+ { indexes: { list: ['list_id'] } }
129
+ );
131
130
 
132
131
  export const AppSchema = new Schema({
133
132
  todos,
134
- lists,
135
- })
133
+ lists
134
+ });
136
135
 
137
136
  // For types
138
- export type Database = (typeof AppSchema)['types']
139
- export type TodoRecord = Database['todos']
140
- export type ListRecord = Database['lists']
137
+ export type Database = (typeof AppSchema)['types'];
138
+ export type TodoRecord = Database['todos'];
139
+ export type ListRecord = Database['lists'];
141
140
  ```
142
141
 
143
142
  > **Tip**: Learn more about how to create your schema [here](https://docs.powersync.com/client-sdk-references/javascript-web#1-define-the-schema).
@@ -147,7 +146,7 @@ export type ListRecord = Database['lists']
147
146
  Create a file called `PowerSyncConnector.ts` and add your connector to it.
148
147
 
149
148
  ```typescript
150
- import { UpdateType, type PowerSyncBackendConnector } from '@powersync/web'
149
+ import { UpdateType, type PowerSyncBackendConnector } from '@powersync/web';
151
150
 
152
151
  export class PowerSyncConnector implements PowerSyncBackendConnector {
153
152
  async fetchCredentials() {
@@ -159,8 +158,8 @@ export class PowerSyncConnector implements PowerSyncBackendConnector {
159
158
  return {
160
159
  endpoint: '[Your PowerSync instance URL or self-hosted endpoint]',
161
160
  // Use a development token (see Authentication Setup https://docs.powersync.com/installation/authentication-setup/development-tokens) to get up and running quickly
162
- token: 'An authentication token',
163
- }
161
+ token: 'An authentication token'
162
+ };
164
163
  }
165
164
 
166
165
  async uploadData(db: any) {
@@ -169,7 +168,7 @@ export class PowerSyncConnector implements PowerSyncBackendConnector {
169
168
 
170
169
  // See example implementation here: https://docs.powersync.com/client-sdk-references/javascript-web#3-integrate-with-your-backend
171
170
  // see demos here: https://github.com/powersync-ja/powersync-js/tree/main/demos
172
- return
171
+ return;
173
172
  }
174
173
  }
175
174
  ```
@@ -181,30 +180,30 @@ export class PowerSyncConnector implements PowerSyncBackendConnector {
181
180
  Finally, putting everything together, create a [plugin](https://nuxt.com/docs/4.x/guide/directory-structure/app/plugins) called `powersync.client.ts` to setup PowerSync.
182
181
 
183
182
  ```typescript
184
- import { createPowerSyncPlugin } from '@powersync/nuxt'
185
- import { NuxtPowerSyncDatabase } from '@powersync/nuxt'
186
- import { AppSchema } from '~/powersync/AppSchema'
187
- import { PowerSyncConnector } from '~/powersync/PowerSyncConnector'
183
+ import { createPowerSyncPlugin } from '@powersync/nuxt';
184
+ import { NuxtPowerSyncDatabase } from '@powersync/nuxt';
185
+ import { AppSchema } from '~/powersync/AppSchema';
186
+ import { PowerSyncConnector } from '~/powersync/PowerSyncConnector';
188
187
 
189
188
  export default defineNuxtPlugin({
190
189
  async setup(nuxtApp) {
191
190
  const db = new NuxtPowerSyncDatabase({
192
191
  database: {
193
- dbFilename: 'a-db-name.sqlite',
192
+ dbFilename: 'a-db-name.sqlite'
194
193
  },
195
- schema: AppSchema,
196
- })
194
+ schema: AppSchema
195
+ });
197
196
 
198
- const connector = new PowerSyncConnector()
197
+ const connector = new PowerSyncConnector();
199
198
 
200
- await db.init()
201
- await db.connect(connector)
199
+ await db.init();
200
+ await db.connect(connector);
202
201
 
203
- const plugin = createPowerSyncPlugin({ database: db })
202
+ const plugin = createPowerSyncPlugin({ database: db });
204
203
 
205
- nuxtApp.vueApp.use(plugin)
206
- },
207
- })
204
+ nuxtApp.vueApp.use(plugin);
205
+ }
206
+ });
208
207
  ```
209
208
 
210
209
  ### Kysely ORM (Optional)
@@ -216,6 +215,7 @@ Install the driver:
216
215
  ```
217
216
  pnpm add @powersync/kysely-driver
218
217
  ```
218
+
219
219
  In your existing `nuxt.config.ts`, set:
220
220
 
221
221
  ```typescript
@@ -226,28 +226,26 @@ export default defineNuxtConfig({
226
226
  },
227
227
  vite: {
228
228
  optimizeDeps: {
229
- exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
230
- include: ['@powersync/web > js-logger'],
229
+ exclude: ['@powersync/web']
231
230
  },
232
231
  worker: {
233
- format: 'es',
234
- plugins: () => [wasm()],
235
- },
236
- },
237
- })
232
+ format: 'es'
233
+ }
234
+ }
235
+ });
238
236
  ```
239
237
 
240
238
  When enabled, the module exposes `usePowerSyncKysely`. Use your schema’s `Database` type to get proper typings:
241
239
 
242
240
  ```typescript
243
- import { usePowerSyncKysely } from '@powersync/nuxt'
244
- import { type Database } from '../powersync/AppSchema'
241
+ import { usePowerSyncKysely } from '@powersync/nuxt';
242
+ import { type Database } from '../powersync/AppSchema';
245
243
 
246
244
  // In your component or composable
247
- const db = usePowerSyncKysely<Database>()
245
+ const db = usePowerSyncKysely<Database>();
248
246
 
249
247
  // Use the db object to interact with the database
250
- const users = await db.selectFrom('users').selectAll().execute()
248
+ const users = await db.selectFrom('users').selectAll().execute();
251
249
  ```
252
250
 
253
251
  ### Enabling Diagnostics
@@ -260,28 +258,26 @@ To enable the PowerSync Inspector with diagnostics capabilities:
260
258
  export default defineNuxtConfig({
261
259
  modules: ['@powersync/nuxt'],
262
260
  powersync: {
263
- useDiagnostics: true, // <- Add this
261
+ useDiagnostics: true // <- Add this
264
262
  },
265
263
  vite: {
266
264
  optimizeDeps: {
267
- exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
268
- include: ['@powersync/web > js-logger'],
265
+ exclude: ['@powersync/web']
269
266
  },
270
267
  worker: {
271
- format: 'es',
272
- plugins: () => [wasm()],
273
- },
274
- },
275
- })
268
+ format: 'es'
269
+ }
270
+ }
271
+ });
276
272
  ```
277
273
 
278
274
  When `useDiagnostics: true` is set, `NuxtPowerSyncDatabase` automatically:
275
+
279
276
  - Extend your schema with diagnostics schema
280
277
  - Sets up diagnostics recording
281
278
  - Stores the connector internally (accessible via diagnostics)
282
279
  - Configures logging for diagnostics
283
280
 
284
-
285
281
  2. **Accessing PowerSync Inspector**:
286
282
 
287
283
  Once diagnostics are enabled, you can access the [PowerSync Inspector](#powersync-inspector):
@@ -289,8 +285,6 @@ Once diagnostics are enabled, you can access the [PowerSync Inspector](#powersyn
289
285
  - **Via Nuxt Devtools**: Open Devtools and look for the PowerSync tab
290
286
  - **Direct URL**: `http://localhost:3000/__powersync-inspector`
291
287
 
292
-
293
-
294
288
  ## PowerSync Inspector
295
289
 
296
290
  PowerSync Inspector is a tool that helps inspect and diagnose the state of your PowerSync client directly from your app in real-time.
@@ -310,6 +304,7 @@ Once setup, the inspector can be accessed on the `http://localhost:3000/__powers
310
304
  #### Sync Status
311
305
 
312
306
  The `Sync Status` tab provides a real-time view of the sync status of your PowerSync client, including:
307
+
313
308
  - Connection status
314
309
  - Sync progress
315
310
  - Upload queue statistics
@@ -341,8 +336,8 @@ To fix this, you can add the following to your `nuxt.config.ts`:
341
336
  export default defineNuxtConfig({
342
337
  unocss: {
343
338
  autoImport: false
344
- },
345
- })
339
+ }
340
+ });
346
341
  ```
347
342
 
348
343
  ## Development
@@ -368,23 +363,21 @@ Don't forget to add a watcher for the module for hot reloading.
368
363
  Example (in your nuxt app):
369
364
 
370
365
  ```typescript
371
- import { defineNuxtConfig } from 'nuxt/config'
366
+ import { defineNuxtConfig } from 'nuxt/config';
372
367
 
373
368
  export default defineNuxtConfig({
374
369
  modules: ['../../my-location/@powersync/nuxt/src/*'],
375
- watch: ['../../my-location/@powersync/nuxt/src/*'],
376
- })
370
+ watch: ['../../my-location/@powersync/nuxt/src/*']
371
+ });
377
372
  ```
378
373
 
379
374
  <!-- Badges -->
375
+
380
376
  [npm-version-src]: https://img.shields.io/npm/v/@powersync/nuxt/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
381
377
  [npm-version-href]: https://npmjs.com/package/@powersync/nuxt
382
-
383
378
  [npm-downloads-src]: https://img.shields.io/npm/dm/@powersync/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
384
379
  [npm-downloads-href]: https://npmjs.com/package/@powersync/nuxt
385
-
386
380
  [license-src]: https://img.shields.io/npm/l/@powersync/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
387
381
  [license-href]: https://npmjs.com/package/@powersync/nuxt
388
-
389
382
  [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
390
383
  [nuxt-href]: https://nuxt.com
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "powersync-nuxt",
3
3
  "configKey": "powersync",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -100,7 +100,12 @@ const module$1 = defineNuxtModule({
100
100
  "usePowerSyncWatchedQuery",
101
101
  "useQuery",
102
102
  "useStatus",
103
- "useWatchedQuerySubscription"
103
+ "useWatchedQuerySubscription",
104
+ "useSyncStream",
105
+ {
106
+ name: "AdditionalOptions",
107
+ type: true
108
+ }
104
109
  ],
105
110
  "@powersync/vue"
106
111
  );
@@ -1 +1,6 @@
1
- export declare const addImportsFrom: (names: string[], from: string) => void;
1
+ interface ImportDefinition {
2
+ name: string;
3
+ type: boolean;
4
+ }
5
+ export declare const addImportsFrom: (names: (string | ImportDefinition)[], from: string) => void;
6
+ export {};
@@ -1,4 +1,10 @@
1
1
  import { addImports } from "@nuxt/kit";
2
2
  export const addImportsFrom = (names, from) => {
3
- addImports(names.map((name) => ({ name, from })));
3
+ addImports(
4
+ names.map((name) => ({
5
+ name: typeof name === "string" ? name : name.name,
6
+ type: typeof name === "string" ? false : name.type,
7
+ from
8
+ }))
9
+ );
4
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/nuxt",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@journeyapps/wa-sqlite": "^1.2.6",
55
- "@powersync/kysely-driver": "1.3.3",
56
- "@powersync/vue": "0.4.2",
57
- "@powersync/web": "1.34.0"
55
+ "@powersync/kysely-driver": "^1.3.3",
56
+ "@powersync/vue": "^0.5.0",
57
+ "@powersync/web": "^1.34.0"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "@powersync/kysely-driver": {
@@ -75,7 +75,7 @@
75
75
  "vue-tsc": "^3.0.8",
76
76
  "@powersync/kysely-driver": "1.3.3",
77
77
  "@powersync/web": "1.34.0",
78
- "@powersync/vue": "0.4.2"
78
+ "@powersync/vue": "0.5.0"
79
79
  },
80
80
  "scripts": {
81
81
  "prebuild": "nuxt-module-build prepare",