void 1.8.0 → 1.9.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/dist/{account-cmd-CZKntRH2.mjs → account-cmd-BEMOdwtl.mjs} +3 -3
- package/dist/{application-analysis-CyTagJQM.mjs → application-analysis-3VVsflWZ.mjs} +5 -5
- package/dist/{application-routing-BLrMVpqi.mjs → application-routing-CJRlXCc2.mjs} +1 -1
- package/dist/{auth-Bk9VGtQW.d.mts → auth-CV9kXHKe.d.mts} +3 -1
- package/dist/{auth-DyWp-fSo.mjs → auth-aMuFOZeI.mjs} +8 -2
- package/dist/{auth-link-BOaQWMKw.mjs → auth-link-B1IynRW5.mjs} +3 -3
- package/dist/{auth-router-D0-VcmDs.mjs → auth-router-DVaWJdRB.mjs} +2 -2
- package/dist/{better-auth-shared-CdVyCUou.mjs → better-auth-shared-C7LHvF4L.mjs} +1 -1
- package/dist/{better-auth-shared-CQFdtguU.d.mts → better-auth-shared-ajs3LNrY.d.mts} +1 -1
- package/dist/{build-cmd-JTsXXf2F.mjs → build-cmd-Dq8tdqQG.mjs} +1 -1
- package/dist/{cache-D0m3Z_Xf.mjs → cache-DGMnskX7.mjs} +1 -1
- package/dist/{cancel-deploy-Ce6Os4fa.mjs → cancel-deploy-96S5hD1E.mjs} +1 -1
- package/dist/cli/cli.mjs +1 -1
- package/dist/cli/env-schema-probe.mjs +3 -3
- package/dist/{cli-main-rkrJy2Ge.mjs → cli-main-CQRLxZAu.mjs} +28 -28
- package/dist/client-66c0RLDM.mjs +1 -0
- package/dist/{client-SZPyj4X_.mjs → client-D6w5x7hM.mjs} +7 -7
- package/dist/{cloudflare-auth-7jTqy9Bx.mjs → cloudflare-auth-pNvmT6kL.mjs} +1 -1
- package/dist/{cloudflare-cmd-ChPLQcTP.mjs → cloudflare-cmd-BuuHUM4z.mjs} +3 -3
- package/dist/{cloudflare-config-DtOGAbeB.mjs → cloudflare-config-PxbinLLE.mjs} +2 -2
- package/dist/{cloudflare-connect-Co93VYTo.mjs → cloudflare-connect-D1QOosLd.mjs} +2 -2
- package/dist/{cloudflare-operations-CXaDKYj2.mjs → cloudflare-operations-G5AObYzF.mjs} +5 -5
- package/dist/{cloudflare-operations-DATekLwI.mjs → cloudflare-operations-I4t3mt4R.mjs} +1 -1
- package/dist/{cloudflare-process-DmTxZR-N.mjs → cloudflare-process-wcnaQ5JG.mjs} +2 -2
- package/dist/{config-wo2EaH0X.mjs → config-C1DPf8EK.mjs} +1 -1
- package/dist/{config-CTlUaXWZ.d.mts → config-CCWVY7DY.d.mts} +1 -1
- package/dist/{config-5oSQhZNj.mjs → config-CzFdJYNA.mjs} +1 -1
- package/dist/{config-DcqUBGCb.mjs → config-DlWQ_hIJ.mjs} +3 -3
- package/dist/{config-eeDzKBS9.mjs → config-Do7gJI3T.mjs} +2 -2
- package/dist/config-entry.d.mts +1 -1
- package/dist/{connect-DlvXt1JR.mjs → connect-4uImOwut.mjs} +4 -4
- package/dist/{create-project-CC_7hmYJ.mjs → create-project-BaUzZnLZ.mjs} +1 -1
- package/dist/{create-project-DzY05xqC.mjs → create-project-CQMyzTvK.mjs} +1 -1
- package/dist/{db-FhyYGcJJ.mjs → db-DEpDeDsi.mjs} +19 -19
- package/dist/{db-types-sVwEpyPR.mjs → db-types-BpPYAx0B.mjs} +1 -1
- package/dist/{delete-CModjyOC.mjs → delete-BVD2kI82.mjs} +1 -1
- package/dist/deploy-Dr_Qamzw.mjs +2 -0
- package/dist/{deploy-Cz9TEzZy.mjs → deploy-Dyeo5soA.mjs} +24 -75
- package/dist/{deploy-managed-static-DlxxXkAM.mjs → deploy-managed-static-Kn73R83A.mjs} +20 -20
- package/dist/{deploy-transport-DUvm6-CR.mjs → deploy-transport-BpKBs_KR.mjs} +2 -2
- package/dist/deploy.mjs +6 -6
- package/dist/discover-Diq0l6TZ.mjs +1 -0
- package/dist/{discover-CVFCWU7W.mjs → discover-Vd18lHsj.mjs} +1 -1
- package/dist/{dispatch-CCiaAnSK.mjs → dispatch-BBfb519j.mjs} +5 -5
- package/dist/{domain-DvdZPA50.mjs → domain-BTIdyUVk.mjs} +2 -2
- package/dist/{email-ASpNrfLd.mjs → email-DvrS-I0U.mjs} +7 -7
- package/dist/{email-cloudflare-kqoN9jst.mjs → email-cloudflare-DAGpgzY1.mjs} +3 -3
- package/dist/{entry-BweGTCgj.mjs → entry-DMgR7XOf.mjs} +1 -1
- package/dist/{env-Bpkg3G5i.mjs → env-D7vORwpn.mjs} +4 -4
- package/dist/{env-types-Dz9qkiOn.mjs → env-types-WEZw5D-r.mjs} +1 -1
- package/dist/{env-validation-CN386Utu.mjs → env-validation-DKDcpxbt.mjs} +1 -1
- package/dist/{env-validation-BpCCQE_6.mjs → env-validation-DeYNRp1d.mjs} +3 -3
- package/dist/{gen-upKJChvd.mjs → gen-DimkGNve.mjs} +4 -4
- package/dist/gen-DmEeVEs4.mjs +1 -0
- package/dist/{github-cmd-BvMOlb8Z.mjs → github-cmd-D-zs6VQr.mjs} +1 -1
- package/dist/{handler-BO7Od-z9.d.mts → handler-6fzr_ikp.d.mts} +3 -3
- package/dist/{head-MeF_5M_3.d.mts → head-CVO92KEx.d.mts} +14 -3
- package/dist/{head-5XPcnG-j.mjs → head-CWJhfUwV.mjs} +62 -3
- package/dist/{headers-COGEDoMN.mjs → headers-Q0kZDpk8.mjs} +1 -1
- package/dist/{help-TPCjTu6e.mjs → help-Cgdcd-SG.mjs} +4 -4
- package/dist/help-Cp3K5m1w.mjs +1 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +23 -23
- package/dist/{info-EsDyihwf.mjs → info-BbxQ34kk.mjs} +4 -4
- package/dist/{init-a4lVagrb.mjs → init-zyRj3QRw.mjs} +14 -14
- package/dist/{link-CE55DDzS.mjs → link-DAFXuIER.mjs} +2 -2
- package/dist/{list-CxRthQks.mjs → list-BTIcC3W9.mjs} +2 -2
- package/dist/{live-Kc55iuOQ.d.mts → live-DBybyDt0.d.mts} +2 -2
- package/dist/{live-CYJ4KGoR.mjs → live-Dw7NF1t2.mjs} +1 -1
- package/dist/load-user-env-ztmIyiLx.mjs +34 -0
- package/dist/{local-d1-CFcH9Bx3.mjs → local-d1-BnVb7Fem.mjs} +1 -1
- package/dist/login-DBs8JuSl.mjs +1 -0
- package/dist/{login-AfcSGSmE.mjs → login-DOE-MkeK.mjs} +2 -2
- package/dist/{logs-BgRJuvb1.mjs → logs-CUsjihc3.mjs} +2 -2
- package/dist/migrate-BYhoIK9R.mjs +1 -0
- package/dist/{migrate-BNAh6m_C.mjs → migrate-DtoKdGas.mjs} +4 -4
- package/dist/nitro.mjs +3 -3
- package/dist/{node-CXFUw0Uz.mjs → node-D9dPyUr0.mjs} +2 -2
- package/dist/operator-ai-logging-DFTEp81Z.mjs +121 -0
- package/dist/{operator-args-DGTuCdSE.mjs → operator-args-BCCohcz3.mjs} +3 -2
- package/dist/{operator-cmd-C-viB7Si.mjs → operator-cmd-CQOQrUiO.mjs} +26 -6
- package/dist/operator-cmd-xCACDtT1.mjs +1 -0
- package/dist/pages/client.d.mts +1 -1
- package/dist/pages/client.mjs +15 -13
- package/dist/pages/head.d.mts +2 -2
- package/dist/pages/head.mjs +1 -1
- package/dist/pages/index.d.mts +2 -2
- package/dist/pages/index.mjs +5 -5
- package/dist/pages/islands-plugin.d.mts +5 -1
- package/dist/pages/islands-plugin.mjs +6 -2
- package/dist/pages/protocol.d.mts +2 -2
- package/dist/pages/protocol.mjs +1 -1
- package/dist/platform-args-DSi4_M8n.mjs +1 -0
- package/dist/{platform-args-CiYeZmc5.mjs → platform-args-DtpHS_75.mjs} +1 -1
- package/dist/{platform-auth-config-Dt2qEc2w.mjs → platform-auth-config-fLwIS5VG.mjs} +3 -3
- package/dist/{platform-auth-protection-B7TaF-PZ.mjs → platform-auth-protection-BTRI_YwD.mjs} +2 -2
- package/dist/{platform-auth-recovery-suXSteJ6.mjs → platform-auth-recovery-DPK2Mvmo.mjs} +2 -2
- package/dist/{platform-cmd-DuAsIxbU.mjs → platform-cmd-BLy5uCa-.mjs} +1 -1
- package/dist/{platform-cmd-9rvYBBtr.mjs → platform-cmd-HS_FSthn.mjs} +5 -5
- package/dist/{platform-domain-DhH_vDr6.mjs → platform-domain-CHpcq_qg.mjs} +2 -2
- package/dist/{platform-lifecycle-3uI-E2bF.mjs → platform-lifecycle-B6LUBwjS.mjs} +1 -1
- package/dist/{platform-lifecycle-CXmXe2xt.mjs → platform-lifecycle-D2RS7DE0.mjs} +236 -26
- package/dist/{platform-management-PdrgDQTe.mjs → platform-management-C-T0ch4y.mjs} +1 -1
- package/dist/{platform-management-BBCHfwji.mjs → platform-management-d3ETv3Dw.mjs} +14 -14
- package/dist/{platform-plans-config-BGwkXYDM.mjs → platform-plans-config-B7yJQKf7.mjs} +114 -30
- package/dist/{platform-recovery-C8NxXGRR.mjs → platform-recovery-DS5CAsly.mjs} +2 -2
- package/dist/{plugin-inference-CErfTgEx.mjs → plugin-inference-DZHmVe1f.mjs} +3 -3
- package/dist/{prepare-BDKWZgfL.mjs → prepare-AVM4Hj3T.mjs} +8 -8
- package/dist/prepare-BSXKz6m8.mjs +1 -0
- package/dist/{prepare-BLrzXjIl.mjs → prepare-DMk8NAO-.mjs} +1 -1
- package/dist/{project-cmd-DzGvxXKH.mjs → project-cmd-TQKAOTMV.mjs} +15 -15
- package/dist/{project-paths-G0yut6Zz.mjs → project-paths-CUhCPMpK.mjs} +33 -2
- package/dist/{project-team-C5XtHbZk.mjs → project-team-B1OKeb-T.mjs} +1 -1
- package/dist/{project-token-B4D5yhHQ.mjs → project-token-RW_wpmN-.mjs} +1 -1
- package/dist/{project-tsconfig-nhnTWO_Y.mjs → project-tsconfig-MyRJgufB.mjs} +1 -1
- package/dist/{project-zero-trust--0LvktDg.mjs → project-zero-trust-TNc66p0_.mjs} +1 -1
- package/dist/{protocol-B1Tvc9-x.mjs → protocol-IPSWHolJ.mjs} +54 -19
- package/dist/{protocol-Cg2I81NA.d.mts → protocol-YS3tbxWE.d.mts} +2 -2
- package/dist/{provision-CAcrauvr.mjs → provision-BLdkpFT4.mjs} +1 -1
- package/dist/{provision-C3yiHdld.mjs → provision-bgQTi5QZ.mjs} +2 -2
- package/dist/redirect-Dqb4fEc5.mjs +80 -0
- package/dist/{requests-CrRiTgQA.mjs → requests-Cj15-yrI.mjs} +1 -1
- package/dist/{rollback-BsmQyj-Q.mjs → rollback-CYnkng7B.mjs} +2 -2
- package/dist/{route-types-CgtlFCDz.mjs → route-types-C6eAOmOj.mjs} +1 -1
- package/dist/runtime/auth.d.mts +1 -1
- package/dist/runtime/auth.mjs +1 -1
- package/dist/runtime/better-auth-mysql.d.mts +1 -1
- package/dist/runtime/better-auth-mysql.mjs +1 -1
- package/dist/runtime/better-auth-pg.d.mts +1 -1
- package/dist/runtime/better-auth-pg.mjs +1 -1
- package/dist/runtime/better-auth.d.mts +1 -1
- package/dist/runtime/better-auth.mjs +1 -1
- package/dist/runtime/client-react.d.mts +1 -1
- package/dist/runtime/client-solid.d.mts +1 -1
- package/dist/runtime/client-svelte.d.mts +1 -1
- package/dist/runtime/client-vue.d.mts +1 -1
- package/dist/runtime/client.d.mts +1 -1
- package/dist/runtime/handler.d.mts +1 -1
- package/dist/runtime/live-client.d.mts +1 -1
- package/dist/runtime/live-server.mjs +1 -1
- package/dist/runtime/live.d.mts +1 -1
- package/dist/runtime/live.mjs +1 -1
- package/dist/runtime/routing.d.mts +2 -2
- package/dist/runtime/routing.mjs +6 -5
- package/dist/runtime/validator.d.mts +1 -1
- package/dist/runtime/ws-server.d.mts +3 -3
- package/dist/runtime/ws-server.mjs +1 -1
- package/dist/runtime/ws.d.mts +1 -1
- package/dist/{scan-BJ3bj6aP.mjs → scan-4YOxDaw2.mjs} +2 -2
- package/dist/{secret-D0g5oBsP.mjs → secret-BSf7dgg_.mjs} +3 -3
- package/dist/{action-key-ByZ6DDld.mjs → url-DaehRGKR.mjs} +43 -1
- package/dist/{version-metadata-eUd6Ar_U.mjs → version-metadata-CeftH0fQ.mjs} +1 -1
- package/dist/{wrangler-k40T7XTQ.mjs → wrangler-B1gkT_wC.mjs} +3 -3
- package/dist/wrangler-fNGvPTlO.mjs +1 -0
- package/dist/{wrapper-CVMZarxf.mjs → wrapper-xJ4LP5A7.mjs} +3 -3
- package/dist/{ws--U7QicYy.d.mts → ws-C2zy0QBf.d.mts} +2 -2
- package/docs/guide/ai.md +1 -1
- package/docs/guide/app-types.md +1 -1
- package/docs/guide/auth.md +22 -27
- package/docs/guide/database/d1.md +4 -2
- package/docs/guide/database.md +29 -27
- package/docs/guide/deployment.md +2 -2
- package/docs/guide/edge/headers.md +3 -3
- package/docs/guide/edge/prerendering.md +5 -5
- package/docs/guide/edge/redirects.md +1 -1
- package/docs/guide/edge/revalidation.md +4 -2
- package/docs/guide/edge/rewrites.md +1 -1
- package/docs/guide/edge/static-assets.md +4 -0
- package/docs/guide/email/sending.md +4 -2
- package/docs/guide/live.md +1 -1
- package/docs/guide/pages-routing/actions-and-forms.md +25 -7
- package/docs/guide/pages-routing/errors.md +17 -9
- package/docs/guide/pages-routing/head.md +44 -1
- package/docs/guide/pages-routing/islands.md +3 -1
- package/docs/guide/pages-routing/layouts.md +2 -2
- package/docs/guide/pages-routing/loaders.md +3 -1
- package/docs/guide/pages-routing/markdown.md +5 -3
- package/docs/guide/pages-routing/overview.md +14 -21
- package/docs/guide/platform/administration/connected-apps.md +10 -3
- package/docs/guide/platform/administration/email.md +1 -1
- package/docs/guide/platform/administration/plans.md +34 -1
- package/docs/guide/platform/administration/projects.md +6 -2
- package/docs/guide/platform/installation/credentials.md +12 -10
- package/docs/guide/platform/installation/maintenance.md +7 -1
- package/docs/guide/platform/installation/setup.md +8 -7
- package/docs/guide/queues.md +1 -1
- package/docs/guide/server-routing.md +2 -2
- package/docs/guide/sse.md +1 -1
- package/docs/guide/ssg.md +17 -6
- package/docs/guide/storage.md +1 -1
- package/docs/guide/testing.md +9 -7
- package/docs/guide/type-safety.md +23 -21
- package/docs/integrations/cloudflare.md +6 -2
- package/docs/integrations/frameworks/nuxt.md +1 -1
- package/docs/integrations/hono.md +21 -0
- package/docs/integrations/nodejs-bun-deno.md +4 -4
- package/docs/reference/api/auth.md +22 -4
- package/docs/reference/api/database.md +2 -2
- package/docs/reference/api/pages.md +17 -13
- package/docs/reference/api/resources.md +1 -1
- package/docs/reference/api/rewrites.md +8 -4
- package/docs/reference/api.md +1 -1
- package/docs/reference/cli/deploy.md +4 -2
- package/docs/reference/cli/platform-config.md +3 -3
- package/docs/reference/cli/platform-users.md +58 -11
- package/docs/reference/cli.md +1 -1
- package/docs/reference/config.md +7 -3
- package/package.json +7 -7
- package/skills/void/SKILL.md +1 -1
- package/dist/client-D1Vz1Zep.mjs +0 -1
- package/dist/deploy-DMieisRu.mjs +0 -2
- package/dist/discover-1DJD4YXD.mjs +0 -1
- package/dist/gen-M5fNQKfH.mjs +0 -1
- package/dist/help-CItQVDL4.mjs +0 -1
- package/dist/load-user-env-CSwdofj0.mjs +0 -48
- package/dist/login-ZHsAm-I6.mjs +0 -1
- package/dist/migrate-BflbbZQK.mjs +0 -1
- package/dist/operator-cmd-D6qNuJ_z.mjs +0 -1
- package/dist/platform-args-DJvF1-kl.mjs +0 -1
- package/dist/prepare-a1_5usAn.mjs +0 -1
- package/dist/url-CuoEn0o3.mjs +0 -43
- package/dist/wrangler-R3kMdJfw.mjs +0 -1
package/docs/guide/testing.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: '
|
|
2
|
+
description: 'Run tests with Vitest and Vite+, mock Cloudflare bindings, and test email with the built-in harnesses.'
|
|
3
3
|
outline: deep
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Testing
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Void apps use [Vitest](https://vitest.dev/). With Vite+, run your tests with:
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
11
|
vp test
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Import test APIs from `vite-plus/test`.
|
|
14
|
+
Import `it`, `expect`, and other test APIs from `vite-plus/test`. If you chose Vite instead of Vite+, install `vitest` as a dev dependency and use `vitest` for both the imports and command.
|
|
15
15
|
|
|
16
|
-
Vitest
|
|
16
|
+
Vitest uses your `vite.config.ts`. Imports such as `void/*` and `@schema` work without extra test configuration.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Put tests in `tests/` or beside the code they test in `src/`. Keep them out of [convention directories](../reference/structure.md) such as `routes/` and `pages/`, where Void would treat them as app routes.
|
|
19
19
|
|
|
20
20
|
## Bindings {#bindings}
|
|
21
21
|
|
|
22
|
-
Tests run in Node.js
|
|
22
|
+
Tests run in Node.js without starting a Worker or applying local migrations. To test code that uses D1, KV, R2, or another binding, mock the module with [`vi.mock()`](https://vitest.dev/api/vi#vi-mock).
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
For example, this function counts visits in KV:
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
27
|
// src/visits.ts
|
|
@@ -34,6 +34,8 @@ export async function countVisit(): Promise<number> {
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
Replace KV with an in-memory map in the test:
|
|
38
|
+
|
|
37
39
|
```ts
|
|
38
40
|
// src/visits.test.ts
|
|
39
41
|
import { expect, it, vi } from 'vite-plus/test';
|
|
@@ -137,7 +137,7 @@ The `action()` helper gets the same type checking. See [Actions & Forms](./pages
|
|
|
137
137
|
|
|
138
138
|
## Typed URLs and Navigation
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
To link to a user's profile, pass its route pattern and ID to `routeUrl()`:
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
143
|
import { routeUrl } from 'void/routes';
|
|
@@ -150,9 +150,11 @@ const url = routeUrl('/users/[id]', {
|
|
|
150
150
|
// /users/42?tab=activity#details
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
TypeScript checks the route and required parameter names. Patterns follow your filenames: `pages/users/[id].tsx`, `.vue`, or `.svelte` uses `/users/[id]`.
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
Parameters accept strings or numbers and are URL-encoded for you. Query values can be strings, numbers, booleans, or arrays. Arrays become repeated keys; `null` and `undefined` values are omitted.
|
|
156
|
+
|
|
157
|
+
The same bracket patterns work with typed `fetch()`, WebSocket `connect()`, page actions, and `useParams()`.
|
|
156
158
|
|
|
157
159
|
Pass the returned string to `Link`, a plain `<a>`, or `c.redirect()`. For programmatic navigation and `c.rewrite()`, you can pass a destination object directly:
|
|
158
160
|
|
|
@@ -167,7 +169,7 @@ const profile = {
|
|
|
167
169
|
} satisfies RouteDestination;
|
|
168
170
|
```
|
|
169
171
|
|
|
170
|
-
Destination objects
|
|
172
|
+
Destination objects check and encode parameters just like `routeUrl()`. See [Pages Routing](./pages-routing/overview.md#typed-navigation) for client navigation and [Rewrites](../reference/api/rewrites.md#c-rewrite-destination) for server navigation.
|
|
171
173
|
|
|
172
174
|
For a catch-all page such as `pages/files/[...path].tsx`, `.vue`, or `.svelte`, use `/files/[...path]` and pass the full path as one value:
|
|
173
175
|
|
|
@@ -185,7 +187,7 @@ routeUrl('/files/[...]', { params: { '*': 'docs/get started' } });
|
|
|
185
187
|
|
|
186
188
|
### Page params
|
|
187
189
|
|
|
188
|
-
Pass
|
|
190
|
+
Pass the current page's pattern to `useParams()` to get typed parameters:
|
|
189
191
|
|
|
190
192
|
::: code-group
|
|
191
193
|
|
|
@@ -230,9 +232,9 @@ useParams<'/userz/[id]'>(); // Type error: no page matches
|
|
|
230
232
|
|
|
231
233
|
:::
|
|
232
234
|
|
|
233
|
-
|
|
235
|
+
Use a page pattern, rather than an HTTP or WebSocket route. Named catch-alls such as `/files/[...path]` return `{ path: string }`; unnamed catch-alls have no named params.
|
|
234
236
|
|
|
235
|
-
The
|
|
237
|
+
The type argument doesn't change which page is read. Without it, `useParams()` returns `Record<string, string>`.
|
|
236
238
|
|
|
237
239
|
On the server, `c.req.param('slug')` accepts any name. Read the params object through `PageParams` so a missing or misspelled name is a type error:
|
|
238
240
|
|
|
@@ -244,7 +246,7 @@ const { slug } = c.req.param() as PageParams<'/posts/[slug]'>;
|
|
|
244
246
|
|
|
245
247
|
### Prerender paths
|
|
246
248
|
|
|
247
|
-
|
|
249
|
+
Annotate `getPrerenderPaths()` with `PageParams` to check that every path includes the page's required parameters:
|
|
248
250
|
|
|
249
251
|
```ts
|
|
250
252
|
// pages/blog/[slug].server.ts
|
|
@@ -255,9 +257,9 @@ export async function getPrerenderPaths(): Promise<PageParams<'/blog/[slug]'>[]>
|
|
|
255
257
|
}
|
|
256
258
|
```
|
|
257
259
|
|
|
258
|
-
|
|
260
|
+
Void doesn't infer this return type from the filename; include the annotation to catch missing or misspelled keys. Custom SSR returns full paths instead, typed as `Promise<string[]>`. See [Edge Prerendering](./edge/prerendering.md#dynamic-pages-with-params) and [Static Site Generation](./ssg.md#per-page-overrides).
|
|
259
261
|
|
|
260
|
-
`routing.prerender
|
|
262
|
+
For `routing.prerender`, use `satisfies RouteUrl[]` to check paths when [`routing.typedRoutes`](../reference/config.md#routing-typedroutes) is enabled:
|
|
261
263
|
|
|
262
264
|
```ts
|
|
263
265
|
// void.config.ts
|
|
@@ -271,7 +273,7 @@ export default defineConfig({
|
|
|
271
273
|
|
|
272
274
|
### Checked URL strings
|
|
273
275
|
|
|
274
|
-
[`routing.typedRoutes`](../reference/config.md#routing-typedroutes)
|
|
276
|
+
Enable [`routing.typedRoutes`](../reference/config.md#routing-typedroutes) to catch misspelled URLs in links, router calls, redirects, rewrites, cache revalidation, island forms, and stream clients. Apps created with `void init` already have it enabled. For an existing app:
|
|
275
277
|
|
|
276
278
|
```ts
|
|
277
279
|
// void.config.ts
|
|
@@ -336,11 +338,13 @@ import { routeUrl } from 'void/routes';
|
|
|
336
338
|
|
|
337
339
|
:::
|
|
338
340
|
|
|
339
|
-
Links
|
|
341
|
+
Links also accept same-page queries and hashes (`?page=2`, `#comments`), and `http://`, `https://`, `mailto:`, and `tel:` URLs. Use absolute paths within your app; relative paths such as `../settings` are rejected. Static path segments accept raw text such as `/café menu` or uppercase percent encoding such as `/caf%C3%A9%20menu`.
|
|
342
|
+
|
|
343
|
+
String checks use TypeScript patterns, which don't validate individual dynamic segments. For example, `/users/[id]` also accepts `/users/` and `/users/42/edit`. A root dynamic page can accept `//example.com`. Prefer `routeUrl()` to encode parameters, and validate untrusted URLs at runtime.
|
|
340
344
|
|
|
341
|
-
The [SSE](./sse.md#client) and [live stream](./live.md#subscribe-from-the-browser) clients
|
|
345
|
+
The [SSE](./sse.md#client) and [live stream](./live.md#subscribe-from-the-browser) clients accept route URLs and external `http://` or `https://` URLs. Same-page links, `mailto:`, `tel:`, and `ws://` aren't stream destinations.
|
|
342
346
|
|
|
343
|
-
`c.redirect()`
|
|
347
|
+
`c.redirect()` accepts the same strings as links, plus a `URL` or destination object. For a URL from a provider SDK, your CMS, or `public/`, use `as Href` to skip the type check:
|
|
344
348
|
|
|
345
349
|
```ts
|
|
346
350
|
import { routeUrl, type Href } from 'void/routes';
|
|
@@ -356,14 +360,14 @@ c.redirect(new URL('https://example.com/login'));
|
|
|
356
360
|
c.redirect(dynamic as Href);
|
|
357
361
|
```
|
|
358
362
|
|
|
359
|
-
|
|
363
|
+
Cast only URLs you trust. Validate request values such as `?redirectTo=` before redirecting; see [`c.redirect()`](../reference/api/rewrites.md#c-rewrite-destination) for an example.
|
|
360
364
|
|
|
361
365
|
`void/routes` exports two types for these strings:
|
|
362
366
|
|
|
363
367
|
- `RouteUrl`: the URL of one of your routes. `routeUrl()` returns it, and `c.rewrite()`, `useIslandForm()`, and `revalidate({ paths })` accept it. Annotate a `routing.prerender` list with it.
|
|
364
368
|
- `Href`: anything a link or `c.redirect()` can point to: a `RouteUrl`, a same-page query or hash, or an external URL.
|
|
365
369
|
|
|
366
|
-
|
|
370
|
+
Use these types for URLs you check at runtime:
|
|
367
371
|
|
|
368
372
|
::: code-group
|
|
369
373
|
|
|
@@ -413,9 +417,7 @@ import type { Href, RouteUrl } from 'void/routes';
|
|
|
413
417
|
|
|
414
418
|
:::
|
|
415
419
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
Route types update with the dev server. For CI or standalone typechecking, run `void prepare` and follow [Setup](#setup). The [API reference](../reference/api/types.md#void-routes) lists the URL helper and route types.
|
|
420
|
+
The dev server keeps route types up to date. After changing `routing.typedRoutes`, restart it or run `void prepare`. For CI and standalone typechecking, follow [Setup](#setup). See the [API reference](../reference/api/types.md#void-routes) for the URL helper and route types.
|
|
419
421
|
|
|
420
422
|
## What Gets Checked
|
|
421
423
|
|
|
@@ -469,7 +471,7 @@ Now `c.get("requestId")` returns `string` everywhere, with no assertion needed.
|
|
|
469
471
|
|
|
470
472
|
## Custom Binding Types
|
|
471
473
|
|
|
472
|
-
|
|
474
|
+
For native Cloudflare deployments, declare a binding in `void.config.ts` to give `c.env` its type. For example, add a [rate limiter](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/):
|
|
473
475
|
|
|
474
476
|
```ts
|
|
475
477
|
// void.config.ts
|
|
@@ -507,7 +509,7 @@ declare module 'void' {
|
|
|
507
509
|
}
|
|
508
510
|
```
|
|
509
511
|
|
|
510
|
-
|
|
512
|
+
Augmentation can refine a generated binding or add one you provide separately. Values declared in `env.ts` keep their schema types. These types apply to Void's `c.env`; for `cloudflare:workers`, use your framework's binding types.
|
|
511
513
|
|
|
512
514
|
## Setup
|
|
513
515
|
|
|
@@ -43,7 +43,7 @@ Add `void/env` to your TypeScript types:
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
This provides binding
|
|
46
|
+
This provides binding and Workers runtime types. For custom bindings in `void.config.ts`, run `void prepare` or start the dev server or build to type them on `c.env`. See [Custom Binding Types](../guide/type-safety.md#custom-binding-types) for RPC methods on service and Durable Object bindings.
|
|
47
47
|
|
|
48
48
|
### Available bindings
|
|
49
49
|
|
|
@@ -175,7 +175,11 @@ Set production server values with `void secret put <NAME>`. Void preserves exist
|
|
|
175
175
|
|
|
176
176
|
### Readiness and rollback
|
|
177
177
|
|
|
178
|
-
Void
|
|
178
|
+
Void checks an uploaded version before sending it traffic. If the Worker has no public URL, because workers.dev is off and no route or Custom Domain is configured, Void activates it without a readiness check.
|
|
179
|
+
|
|
180
|
+
If readiness or trigger updates fail, Void restores the previous deployment. If trigger updates fail and the previous triggers can't be restored, such as after another tool's deployment or from an empty draft, the new version stays live. The error names the version serving traffic.
|
|
181
|
+
|
|
182
|
+
Finish or cancel gradual rollouts in Cloudflare before deploying through Void.
|
|
179
183
|
|
|
180
184
|
For an existing Durable Object Worker that Cloudflare cannot stage, review the changes and use:
|
|
181
185
|
|
|
@@ -49,7 +49,7 @@ export default defineNuxtConfig({
|
|
|
49
49
|
|
|
50
50
|
The `void/nitro` module gives Nuxt server routes your app's `void/db` and `@schema`. The top-level `alias` lets `nuxi typecheck` resolve `@schema`, because Nuxt also checks server routes with the app's types. `cloudflare.dev` gives the development server the bindings from Void's generated Cloudflare config; Nuxt runs it in development when `compatibilityDate` is `2025-07-15` or later.
|
|
51
51
|
|
|
52
|
-
The database module supports Nitro 2 and Nitro 3 prereleases.
|
|
52
|
+
The database module supports Nitro 2 and Nitro 3 prereleases. Use the Cloudflare development configuration for your Nuxt version; Nitro 3 uses its own Worker runner.
|
|
53
53
|
|
|
54
54
|
### 4. Create `void.config.ts`
|
|
55
55
|
|
|
@@ -104,3 +104,24 @@ throw new HTTPException(404, { message: 'User not found' });
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
For the full list of built-in middleware, see the [Hono documentation](https://hono.dev/docs/middleware/builtin).
|
|
107
|
+
|
|
108
|
+
### Redirects
|
|
109
|
+
|
|
110
|
+
Return `c.redirect()` from a handler to redirect. From a shared helper, throw an `HTTPException` with the redirect response in `res`. This works in loaders, actions, and middleware, including client-side page visits:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// lib/require-page-user.ts
|
|
114
|
+
import { HTTPException } from 'hono/http-exception';
|
|
115
|
+
import type { CloudContext } from 'void';
|
|
116
|
+
import { getUser } from 'void/auth';
|
|
117
|
+
|
|
118
|
+
export function requirePageUser(c: CloudContext) {
|
|
119
|
+
const user = getUser();
|
|
120
|
+
if (!user) {
|
|
121
|
+
throw new HTTPException(302, { res: c.redirect('/login') });
|
|
122
|
+
}
|
|
123
|
+
return user;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
After a mutation, use `303` for both the exception and `c.redirect('/login', 303)` so the browser follows with a GET.
|
|
@@ -164,9 +164,9 @@ This is useful for testing, embedding in Express/Fastify, or running in serverle
|
|
|
164
164
|
|
|
165
165
|
### Serving the client build from somewhere else
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
To embed your app in a [single executable](https://nodejs.org/api/single-executable-applications.html), pass an `ASSETS` object with a `fetch(request)` method to `app.fetch()`. Void uses it for the client manifest, scripts, styles, and public files instead of reading `dist/client`.
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
For Node.js, store assets under their URL paths, including `/.vite/manifest.json`, `/assets/…`, and files copied from `public/`:
|
|
170
170
|
|
|
171
171
|
```ts
|
|
172
172
|
import { getAsset } from 'node:sea';
|
|
@@ -194,9 +194,9 @@ const ASSETS = {
|
|
|
194
194
|
serve({ fetch: (request, env) => app.fetch(request, { ...env, ASSETS }), port: 3000 });
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
Keep the env
|
|
197
|
+
Keep the server's existing `env` values when adding `ASSETS`, so `getConnInfo()` can read the incoming request.
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
For Bun, import each client file with `{ type: 'file' }` so `bun build --compile` embeds it as an asset. Generate this module after each `vite build`, since filenames change with the build. Don't list client scripts as build entry points; Bun would bundle them as executable code:
|
|
200
200
|
|
|
201
201
|
```ts
|
|
202
202
|
// client-files.ts, written after each `vite build`
|
|
@@ -69,7 +69,7 @@ import { getAuth } from 'void/auth';
|
|
|
69
69
|
export const GET = defineHandler((c) => getAuth(c).handler(c.req.raw));
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Enable [authentication](../../guide/auth.md) before calling this helper; it throws if no instance is available. Anonymous requests can use it too. Call `requireAuth(c)` separately to require a signed-in user.
|
|
73
73
|
|
|
74
74
|
**Signature:**
|
|
75
75
|
|
|
@@ -77,9 +77,11 @@ Requires [authentication](../../guide/auth.md) to be enabled. Throws if no insta
|
|
|
77
77
|
function getAuth(c: CloudContext): AuthInstance;
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
## `requireAuth(c)` {#requireauth-c}
|
|
80
|
+
## `requireAuth(c, options?)` {#requireauth-c}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
Returns the authenticated user from the request context. Without `throwRedirect`, throws a 401 `HTTPException` if no session is present.
|
|
83
|
+
|
|
84
|
+
Use it without options in route handlers or actions when you want a plain-text `401`, not an error page:
|
|
83
85
|
|
|
84
86
|
```ts
|
|
85
87
|
import { defineHandler } from 'void';
|
|
@@ -91,10 +93,26 @@ export const GET = defineHandler((c) => {
|
|
|
91
93
|
});
|
|
92
94
|
```
|
|
93
95
|
|
|
96
|
+
For protected pages, pass `throwRedirect` to [redirect unauthenticated visitors to login](../../guide/auth.md#protect-a-server-route):
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { defineHandler } from 'void';
|
|
100
|
+
import { requireAuth } from 'void/auth';
|
|
101
|
+
|
|
102
|
+
export const loader = defineHandler((c) => {
|
|
103
|
+
const user = requireAuth(c, { throwRedirect: '/login' });
|
|
104
|
+
return { email: user.email };
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`throwRedirect` works in loaders, actions, and middleware. When signed out, it throws a redirect with status `302` for GET/HEAD requests or `303` for other methods, stopping execution. When signed in, it returns the user normally.
|
|
109
|
+
|
|
110
|
+
The destination is application-controlled.
|
|
111
|
+
|
|
94
112
|
**Signature:**
|
|
95
113
|
|
|
96
114
|
```ts
|
|
97
|
-
function requireAuth(c: CloudContext): AuthUser;
|
|
115
|
+
function requireAuth(c: CloudContext, options?: { throwRedirect?: string }): AuthUser;
|
|
98
116
|
```
|
|
99
117
|
|
|
100
118
|
## `AuthUser` {#authuser}
|
|
@@ -37,7 +37,7 @@ import { createDb } from 'void/db';
|
|
|
37
37
|
const db = createDb(env.MY_OTHER_DB);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
For a fresh D1 read, pass `{ session: 'first-primary' }` and create the client inside the request. The default, `'first-unconstrained'`, allows the first query to use a replica. Both keep your schema and query types. See [Read replication](../../guide/database/d1.md#read-replication).
|
|
41
41
|
|
|
42
42
|
For PostgreSQL and MySQL projects, pass a connection string.
|
|
43
43
|
|
|
@@ -73,7 +73,7 @@ import { db, eq, and, or, desc, like, inArray, sql } from 'void/db';
|
|
|
73
73
|
|
|
74
74
|
**Full list:** `sql`, `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `and`, `or`, `not`, `desc`, `asc`, `like`, `ilike`, `notLike`, `inArray`, `notInArray`, `isNull`, `isNotNull`, `between`, `notBetween`, `exists`, `notExists`, `count`, `sum`, `avg`, `min`, `max`.
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
Use the exported Drizzle types `SQL`, `SQLWrapper`, `AnyColumn`, and `BatchItem` to type query helpers and batches:
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
79
|
import { posts } from '@schema';
|
|
@@ -20,7 +20,7 @@ import type { ErrorPageProps, PageError } from 'void/pages';
|
|
|
20
20
|
|
|
21
21
|
## Navigation destinations {#navigation-destinations}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Build a URL with [`routeUrl()`](./types.md#routeurl-path-options) and pass it to `Link`'s `href`. All four adapters use the [`Href`](./types.md#route-types) type for links.
|
|
24
24
|
|
|
25
25
|
The router's `visit(destination, options?)`, `prefetch(destination, options?)`, and `flush(destination, method?)` accept [`RouteUrlInput`](./types.md#route-types): a string, `URL`, or typed destination object.
|
|
26
26
|
|
|
@@ -44,9 +44,11 @@ type LinkPrefetchStrategy = 'hover' | 'click' | 'mount' | 'visible';
|
|
|
44
44
|
| `'visible'` | Once the link has stayed in view for 300 ms. Links scrolled quickly past are skipped |
|
|
45
45
|
| `false` | Never |
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Combine strategies with an array such as `['visible', 'hover']`. The first one triggered loads the page; later triggers reuse it.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
Only same-origin GET links prefetch. `Link` skips prefetching when Chromium reports data saver or a 2G connection. Calling `router.prefetch()` explicitly still loads the page.
|
|
50
|
+
|
|
51
|
+
Set `cacheFor` in milliseconds or as a duration such as `'5m'`. To show cached data while refreshing it in the background, use a pair such as `['30s', '5m']`: the page stays fresh for 30 seconds and can be reused for up to 5 minutes.
|
|
50
52
|
|
|
51
53
|
Each adapter plugin's `prefetch` option sets app-wide values:
|
|
52
54
|
|
|
@@ -103,8 +105,8 @@ Imported from `"@void/vue"`.
|
|
|
103
105
|
| `useForm(url, defaults, options?)` | Typed reactive form helper bound to a page action URL. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
|
|
104
106
|
| `useIslandForm(defaults)` | Form helper for island components. Same form state as `useForm()`, plus `submit(url, method)`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. With [`routing.typedRoutes`](../config.md#routing-typedroutes), the URL is a [`RouteUrl`](./types.md#route-types). |
|
|
105
107
|
| `action(url, options?)` | Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params, preserveScroll }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an [`ActionResult`](../../guide/pages-routing/actions-and-forms.md#action-helper). |
|
|
106
|
-
| `isVoidActionError(error)` |
|
|
107
|
-
| `isCallSiteActionError(error)` |
|
|
108
|
+
| `isVoidActionError(error)` | Checks and narrows `error` to `VoidActionError`, including thrown `401`, `403`, and `500` errors. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors). |
|
|
109
|
+
| `isCallSiteActionError(error)` | Recognizes the expected errors returned by `action()`, such as `409` or `422`. |
|
|
108
110
|
| `getValidationErrors(body)` | Returns the field-error map from a failed action's `error.body`, or `null` when the body has no field errors. Use it to show validation errors from `action()`. |
|
|
109
111
|
| `useShared()` | Returns shared data. Middleware sets it with `c.set("shared", {...})`; a loader or action can update it. See [Shared data](../../guide/pages-routing/layouts.md#shared-data). |
|
|
110
112
|
|
|
@@ -159,8 +161,8 @@ Imported from `"@void/react"`.
|
|
|
159
161
|
| `useForm(url, defaults, options?)` | Form helper hook. Returns `{ data, setData, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
|
|
160
162
|
| `useIslandForm(defaults)` | Form helper hook for island components. Same form state as `useForm()`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. With [`routing.typedRoutes`](../config.md#routing-typedroutes), the URL is a [`RouteUrl`](./types.md#route-types). |
|
|
161
163
|
| `action(url, options?)` | Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params, preserveScroll }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an [`ActionResult`](../../guide/pages-routing/actions-and-forms.md#action-helper). |
|
|
162
|
-
| `isVoidActionError(error)` |
|
|
163
|
-
| `isCallSiteActionError(error)` |
|
|
164
|
+
| `isVoidActionError(error)` | Checks and narrows `error` to `VoidActionError`, including thrown `401`, `403`, and `500` errors. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors). |
|
|
165
|
+
| `isCallSiteActionError(error)` | Recognizes the expected errors returned by `action()`, such as `409` or `422`. |
|
|
164
166
|
| `getValidationErrors(body)` | Returns the field-error map from a failed action's `error.body`, or `null` when the body has no field errors. Use it to show validation errors from `action()`. |
|
|
165
167
|
| `useShared()` | Returns shared data. Middleware sets it with `c.set("shared", {...})`; a loader or action can update it. See [Shared data](../../guide/pages-routing/layouts.md#shared-data). |
|
|
166
168
|
| `Deferred<T>` | React-only prop type for `defer()` results. It is `Promise<T>` and is consumed with React `use()`. |
|
|
@@ -193,7 +195,9 @@ startTransition(async () => {
|
|
|
193
195
|
await router.visit('/account', { resolveOn: 'data' });
|
|
194
196
|
```
|
|
195
197
|
|
|
196
|
-
With `'data'`, the promise resolves when
|
|
198
|
+
With `'data'`, the promise resolves when page data is ready, so the Action can finish before React commits. The transition can stay pending through Suspense.
|
|
199
|
+
|
|
200
|
+
The DOM and URL may still show the previous page after `await`. Use an effect or ref callback for work that needs the updated DOM.
|
|
197
201
|
|
|
198
202
|
## `@void/svelte` {#void-svelte}
|
|
199
203
|
|
|
@@ -239,8 +243,8 @@ Imported from `"@void/svelte"`.
|
|
|
239
243
|
| `useForm(url, defaults, options?)` | Form helper using Svelte 5 runes. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
|
|
240
244
|
| `useIslandForm(defaults)` | Form helper for island components. Same form state as `useForm()`, plus `submit(url, method)`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. With [`routing.typedRoutes`](../config.md#routing-typedroutes), the URL is a [`RouteUrl`](./types.md#route-types). |
|
|
241
245
|
| `action(url, options?)` | Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params, preserveScroll }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an [`ActionResult`](../../guide/pages-routing/actions-and-forms.md#action-helper). |
|
|
242
|
-
| `isVoidActionError(error)` |
|
|
243
|
-
| `isCallSiteActionError(error)` |
|
|
246
|
+
| `isVoidActionError(error)` | Checks and narrows `error` to `VoidActionError`, including thrown `401`, `403`, and `500` errors. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors). |
|
|
247
|
+
| `isCallSiteActionError(error)` | Recognizes the expected errors returned by `action()`, such as `409` or `422`. |
|
|
244
248
|
| `getValidationErrors(body)` | Returns the field-error map from a failed action's `error.body`, or `null` when the body has no field errors. Use it to show validation errors from `action()`. |
|
|
245
249
|
| `useShared()` | Returns shared data. Middleware sets it with `c.set("shared", {...})`; a loader or action can update it. See [Shared data](../../guide/pages-routing/layouts.md#shared-data). |
|
|
246
250
|
| `useRouter()` | Returns the Void Router with current route state (`url`, `path`, `query`, `params`) and navigation methods: `visit`, `refresh`, awaitable `prefetch`, `flush`, `flushAll`. |
|
|
@@ -293,8 +297,8 @@ Imported from `"@void/solid"`.
|
|
|
293
297
|
| `useForm(url, defaults, options?)` | Form helper using Solid stores. Returns `{ data, setData, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
|
|
294
298
|
| `useIslandForm(defaults)` | Form helper for island components. Same form state as `useForm()`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. With [`routing.typedRoutes`](../config.md#routing-typedroutes), the URL is a [`RouteUrl`](./types.md#route-types). |
|
|
295
299
|
| `action(url, options?)` | Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params, preserveScroll }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an [`ActionResult`](../../guide/pages-routing/actions-and-forms.md#action-helper). |
|
|
296
|
-
| `isVoidActionError(error)` |
|
|
297
|
-
| `isCallSiteActionError(error)` |
|
|
300
|
+
| `isVoidActionError(error)` | Checks and narrows `error` to `VoidActionError`, including thrown `401`, `403`, and `500` errors. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors). |
|
|
301
|
+
| `isCallSiteActionError(error)` | Recognizes the expected errors returned by `action()`, such as `409` or `422`. |
|
|
298
302
|
| `getValidationErrors(body)` | Returns the field-error map from a failed action's `error.body`, or `null` when the body has no field errors. Use it to show validation errors from `action()`. |
|
|
299
303
|
| `useShared()` | Returns shared data. Middleware sets it with `c.set("shared", {...})`; a loader or action can update it. See [Shared data](../../guide/pages-routing/layouts.md#shared-data). |
|
|
300
304
|
| `useRouter()` | Returns the Void Router with current route state (`url`, `path`, `query`, `params`) and navigation methods: `visit`, `refresh`, awaitable `prefetch`, `flush`, `flushAll`. |
|
|
@@ -333,4 +337,4 @@ See [Markdown Pages](../../guide/pages-routing/markdown.md) for setup and framew
|
|
|
333
337
|
|
|
334
338
|
Each Pages adapter exports `Form`. Pass the object returned by `useForm()` as `form`; `method` defaults to `post`. It renders validation and action errors, preserves controlled input, and respects known quota retry deadlines without submitting automatically. `renderError` customizes action-error presentation; Svelte uses a snippet. See [Actions and Forms](../../guide/pages-routing/actions-and-forms.md).
|
|
335
339
|
|
|
336
|
-
|
|
340
|
+
Pass `{ throwOnError: false }` as the third argument to `useForm()` to show HTTP failures inline. Validation errors populate `form.errors`; other HTTP failures populate `form.error`. React also calls `onError`. Unexpected failures still throw, and cancelled submissions don't set a form error. See [Handling action errors](../../guide/pages-routing/actions-and-forms.md#validation-errors).
|
|
@@ -110,7 +110,7 @@ await revalidate({ paths: ['/', '/blog/hello'] });
|
|
|
110
110
|
await revalidate({ all: true });
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
With [`routing.typedRoutes`](../config.md#routing-typedroutes)
|
|
113
|
+
With [`routing.typedRoutes`](../config.md#routing-typedroutes), each path must match one of your routes. Build paths with `routeUrl()`, or use `as RouteUrl` for paths you validate at runtime. Without this setting, `RouteUrl` is `string`.
|
|
114
114
|
|
|
115
115
|
**Signature:**
|
|
116
116
|
|
|
@@ -23,7 +23,9 @@ return c.rewrite({
|
|
|
23
23
|
|
|
24
24
|
With [`routing.typedRoutes`](../config.md#routing-typedroutes), a string destination must be a [`RouteUrl`](./types.md#route-types): a URL that matches one of your routes. Cast a path built at runtime, such as ``c.rewrite(`/${locale}${path}` as RouteUrl)``.
|
|
25
25
|
|
|
26
|
-
With [`routing.typedRoutes`](../config.md#routing-typedroutes), `c.redirect()` checks
|
|
26
|
+
With [`routing.typedRoutes`](../config.md#routing-typedroutes), `c.redirect()` checks strings like a link: route URLs, same-page queries and hashes, and `http://`, `https://`, `mailto:`, or `tel:` URLs. It also accepts a `URL` or typed destination object.
|
|
27
|
+
|
|
28
|
+
For a string TypeScript can't check, such as a payment provider's checkout URL, use `as Href`:
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
import { routeUrl, type Href } from 'void/routes';
|
|
@@ -36,16 +38,18 @@ return c.redirect('https://example.com/login');
|
|
|
36
38
|
return c.redirect(checkoutUrl as Href);
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
A cast skips the type check; Void doesn't validate redirect destinations at runtime. For request values such as `?redirectTo=`, check the origin before redirecting:
|
|
40
42
|
|
|
41
43
|
```ts
|
|
42
44
|
const requested = new URL(c.req.query('redirectTo') ?? '/', c.req.url);
|
|
43
45
|
return c.redirect(requested.origin === new URL(c.req.url).origin ? requested : '/');
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
`c.redirect()` sends the location
|
|
48
|
+
`c.redirect()` sends the location you provide without adding the request query. From `/sign-in?redirectTo=/notes`, `c.redirect('/notes')` goes to `/notes`. Configured [`routing.redirects`](../../guide/edge/redirects.md) merge query parameters instead.
|
|
49
|
+
|
|
50
|
+
A [named action](../../guide/pages-routing/actions-and-forms.md#named-actions) keeps its own query parameters. For example, `POST /users/42?delete&tab=profile` with `c.redirect('/users/42')` redirects to `/users/42?tab=profile`. The action key is removed when the redirect changes the method to GET.
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
Redirects that preserve the method keep the action key: `307` and `308`, or `301` and `302` after `PUT`, `PATCH`, or `DELETE`. Parameters added from the [current page's query](../../guide/pages-routing/actions-and-forms.md#query-parameters-after-submission) aren't carried into the redirect.
|
|
49
53
|
|
|
50
54
|
```ts
|
|
51
55
|
import { defineHandler } from 'void';
|
package/docs/reference/api.md
CHANGED
|
@@ -37,7 +37,7 @@ Import Void's app-facing APIs from these paths:
|
|
|
37
37
|
|
|
38
38
|
| Import path | Contents |
|
|
39
39
|
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
40
|
-
| `void` | `voidPlugin`, handler/type re-exports, `defer`, `Deferred`, `DeferredState`, `InferProps`, `HeadDescriptor`
|
|
40
|
+
| `void` | `voidPlugin`, handler/type re-exports, `defer`, `Deferred`, `DeferredState`, `InferProps`, `HeadConfig`, `HeadDescriptor` |
|
|
41
41
|
| `void/handler` | `defineHandler`, `defineMiddleware`, `basicAuth`, `defineScheduled`, `defineQueue`, `defineRender`, `defineHead`, types |
|
|
42
42
|
| `void/auth` | `defineAuth`, `getUser`, `getSession`, `requireAuth`, `AuthUser`, `AuthSession`, `AuthState` |
|
|
43
43
|
| `void/client` | `fetch`, `fetchStream`, `FetchError`, `auth`, `createAuthClient`, `AuthUser`, `AuthSession`, `AuthState` |
|
|
@@ -43,7 +43,9 @@ For Drizzle projects, deploy performs a read-only schema drift check. If a new m
|
|
|
43
43
|
|
|
44
44
|
`--atomic` applies to one deployment. For an existing Durable Object Worker that consistently cannot stage, set `deploy: { cloudflare: { mode: 'atomic' } }` in `void.config.ts` so plain `void deploy` uses atomic publication. The default is `staged`.
|
|
45
45
|
|
|
46
|
-
Use `--skip-migrations` when
|
|
46
|
+
Use `--skip-migrations` when you run migrations separately or share a database with a preview. The code must work with the database's current schema. The next deploy without this flag applies pending migrations.
|
|
47
|
+
|
|
48
|
+
Keep migration files and schema validation in place. This option skips application and authentication SQL; Durable Object class migrations still run when publishing code. If a Void platform doesn't support the flag, upgrade it first.
|
|
47
49
|
|
|
48
50
|
Every deploy writes a JSONL log to `~/.void/logs/`. Failures print the log path and relevant details. Use `--debug` or `VOID_DEPLOY_DEBUG=1` to mirror it to stderr.
|
|
49
51
|
|
|
@@ -102,7 +104,7 @@ Void signs you in through your browser when needed and saves the selected accoun
|
|
|
102
104
|
| `--require-email` | Fail instead of deploying without email when the email step cannot run, as in CI |
|
|
103
105
|
| `DATABASE_URL` | Required in the deploy environment for PostgreSQL or MySQL provisioning and migrations |
|
|
104
106
|
|
|
105
|
-
After `--skip-migrations`,
|
|
107
|
+
After `--skip-migrations`, direct Cloudflare deployment history shows the applied migration state as unknown. Rolling back code doesn't reverse database changes.
|
|
106
108
|
|
|
107
109
|
The token needs Workers Scripts: Edit, read access to bound resources, and edit access to products Void provisions. Commit `void.lock.json` after the first deploy before using other machines or CI.
|
|
108
110
|
|