use-convex 1.0.0 → 1.1.0
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 +38 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ export default defineNuxtConfig({
|
|
|
26
26
|
<script setup lang="ts">
|
|
27
27
|
import { api } from '~~/convex/_generated/api'
|
|
28
28
|
|
|
29
|
-
const { data, pending, error } = await useConvexQuery(api.tasks.list, {})
|
|
29
|
+
const { data, pending, error } = await useConvexQuery(api.tasks.list, {}, { authenticated: true })
|
|
30
30
|
</script>
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -58,6 +58,7 @@ Set `convex.server: false` to skip SSR snapshots globally, or pass `{ server: fa
|
|
|
58
58
|
const { data, pending, error, refresh } = await useConvexQuery(
|
|
59
59
|
api.tasks.list,
|
|
60
60
|
{}, // args, a ref / getter, or 'skip'
|
|
61
|
+
{ authenticated: true }, // wait for Convex auth before live subscribe
|
|
61
62
|
)
|
|
62
63
|
```
|
|
63
64
|
|
|
@@ -84,11 +85,14 @@ prewarmQuery(api.tasks.list, {})
|
|
|
84
85
|
|
|
85
86
|
### Several queries
|
|
86
87
|
|
|
88
|
+
Browser-only live map (no SSR). Each value is `data | undefined` (loading) | `Error`. Combine with `useConvexQuery` when you need an SSR snapshot for known queries.
|
|
89
|
+
|
|
87
90
|
```ts
|
|
88
91
|
const results = useConvexQueries(() => ({
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
tasks: { query: api.tasks.list, args: {} },
|
|
93
|
+
files: showFiles.value ? { query: api.files.list, args: {} } : 'skip',
|
|
91
94
|
}))
|
|
95
|
+
// results.value.tasks
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
### Pagination
|
|
@@ -97,8 +101,9 @@ const results = useConvexQueries(() => ({
|
|
|
97
101
|
const { results, status, isLoading, loadMore } = await useConvexPaginatedQuery(
|
|
98
102
|
api.tasks.listPaginated,
|
|
99
103
|
{},
|
|
100
|
-
{ initialNumItems: 20 },
|
|
104
|
+
{ initialNumItems: 20, authenticated: true },
|
|
101
105
|
)
|
|
106
|
+
// loadMore() when status === 'CanLoadMore'
|
|
102
107
|
```
|
|
103
108
|
|
|
104
109
|
The first page is SSR'd. On the browser, every loaded page stays live. `loadMore` fetches the next page.
|
|
@@ -115,10 +120,10 @@ const { mutate, pending, error } = useConvexMutation(api.tasks.create, {
|
|
|
115
120
|
])
|
|
116
121
|
},
|
|
117
122
|
})
|
|
118
|
-
await mutate({ text: 'Ship it' })
|
|
123
|
+
await mutate({ text: 'Ship it' }) // browser-only
|
|
119
124
|
|
|
120
|
-
const { run } = useConvexAction(api.
|
|
121
|
-
await run({ text: '
|
|
125
|
+
const { run, pending, error } = useConvexAction(api.tasks.shout)
|
|
126
|
+
const shouted = await run({ text: 'hello' }) // browser-only
|
|
122
127
|
```
|
|
123
128
|
|
|
124
129
|
For paginated lists:
|
|
@@ -133,7 +138,7 @@ insertAtTop({
|
|
|
133
138
|
|
|
134
139
|
Also available: `insertAtBottomIfLoaded`, `insertAtPosition`, `optimisticallyUpdateValueInPaginatedQuery`.
|
|
135
140
|
|
|
136
|
-
`useConvex()` returns the browser `ConvexClient` when you need an escape hatch. `useConvexConnectionState()` is a reactive WebSocket `
|
|
141
|
+
`useConvex()` returns the browser `ConvexClient` when you need an escape hatch. `useConvexConnectionState()` is a reactive `ShallowRef<ConnectionState | null>` (WebSocket status: `isWebSocketConnected`, `hasInflightRequests`, …).
|
|
137
142
|
|
|
138
143
|
## File uploads
|
|
139
144
|
|
|
@@ -145,7 +150,7 @@ const { upload, pending, error, progress } = useConvexFileUpload({
|
|
|
145
150
|
saveFile: api.files.save, // ({ storageId, name, contentType, size, ... }) => Id<"files">
|
|
146
151
|
})
|
|
147
152
|
|
|
148
|
-
await upload(file)
|
|
153
|
+
await upload(file) // progress: 0..1 while bytes fly
|
|
149
154
|
// optional extra save args: await upload(file, { caption: '…' })
|
|
150
155
|
```
|
|
151
156
|
|
|
@@ -169,8 +174,9 @@ export const { generateUploadUrl, syncMetadata } = r2.clientApi({
|
|
|
169
174
|
```
|
|
170
175
|
|
|
171
176
|
```ts
|
|
177
|
+
// Pass r2.clientApi() exports: { generateUploadUrl, syncMetadata }
|
|
172
178
|
const { upload, pending, error, progress } = useConvexR2Upload(api.r2)
|
|
173
|
-
const key = await upload(file)
|
|
179
|
+
const key = await upload(file) // R2 object key
|
|
174
180
|
```
|
|
175
181
|
|
|
176
182
|
That runs `generateUploadUrl` → `PUT` to the signed URL → `syncMetadata({ key })`, with XHR progress. Use built-in `useConvexFileUpload` for Convex storage; use this helper when you adopt the R2 component.
|
|
@@ -303,6 +309,15 @@ export default defineEventHandler(async (event) => {
|
|
|
303
309
|
})
|
|
304
310
|
```
|
|
305
311
|
|
|
312
|
+
```ts
|
|
313
|
+
// server/api/shout.post.ts
|
|
314
|
+
export default defineEventHandler(async (event) => {
|
|
315
|
+
requireConvexAuth(event)
|
|
316
|
+
const { text } = await readBody(event)
|
|
317
|
+
return await fetchAction(api.tasks.shout, { text }, { event })
|
|
318
|
+
})
|
|
319
|
+
```
|
|
320
|
+
|
|
306
321
|
`fetchAction` uses the same options. Each helper builds a fresh `ConvexHttpClient`. Override with `{ token }` when you already have a JWT. `getConvexToken(event)` reads the cookie without throwing.
|
|
307
322
|
|
|
308
323
|
## Config
|
|
@@ -353,7 +368,8 @@ pnpm run dev
|
|
|
353
368
|
|
|
354
369
|
| Route | What it shows |
|
|
355
370
|
| --------- | ----------------------------------------------------- |
|
|
356
|
-
| `/` |
|
|
371
|
+
| `/` | Shell session: features + composable call-shape demos |
|
|
372
|
+
| `/live` | SSR snapshot + live overlay (sign up, CRUD todos) |
|
|
357
373
|
| `/server` | Nitro `fetchQuery` / `fetchMutation` / `fetchAction` |
|
|
358
374
|
| `/files` | `useConvexFileUpload` (upload, list, preview, delete) |
|
|
359
375
|
| `/extras` | `live: false`, pagination, action, connection state |
|
|
@@ -362,17 +378,24 @@ On `/server`: `GET /api/health` is public; `GET`/`POST /api/tasks` use the cooki
|
|
|
362
378
|
|
|
363
379
|
## Releasing
|
|
364
380
|
|
|
365
|
-
Releases run from `.github/workflows/release.yml` when commits land on `main
|
|
381
|
+
Releases run from `.github/workflows/release.yml` when commits that touch `src/` land on `main` (or when the workflow is run manually). Version bumps follow [conventional commits](https://www.conventionalcommits.org/):
|
|
366
382
|
|
|
367
383
|
| Commit | Release |
|
|
368
384
|
| ------------------------------ | ------- |
|
|
369
|
-
| `fix:` | patch |
|
|
370
|
-
| `feat:` | minor |
|
|
371
385
|
| `feat!:` or `BREAKING CHANGE:` | major |
|
|
372
|
-
| `
|
|
386
|
+
| `feat:` | minor |
|
|
387
|
+
| anything else under `src/` | patch |
|
|
373
388
|
|
|
374
389
|
semantic-release publishes `use-convex` to npm, tags `vX.Y.Z`, and opens a GitHub Release. The repo `package.json` version is not committed back.
|
|
375
390
|
|
|
391
|
+
Publishing uses [npm trusted publishing](https://docs.npmjs.com/trusted-publishers) (OIDC), not an `NPM_TOKEN`. On [the `use-convex` package settings](https://www.npmjs.com/package/use-convex?activeTab=settings) add a GitHub Actions trusted publisher:
|
|
392
|
+
|
|
393
|
+
- **Organization or user:** `jrmybtlr`
|
|
394
|
+
- **Repository:** `convex-nuxt`
|
|
395
|
+
- **Workflow filename:** `release.yml`
|
|
396
|
+
- **Environment:** leave empty
|
|
397
|
+
- **Allowed actions:** include **`npm publish`** (new publishers default to staged publish only)
|
|
398
|
+
|
|
376
399
|
## License
|
|
377
400
|
|
|
378
401
|
MIT
|