@gnosticdev/hono-actions 2.0.10 → 2.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 CHANGED
@@ -5,10 +5,10 @@ Define server actions with built-in validation, error handling, and a pre-built
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @gnosticdev/hono-actions
9
- # or
10
- pnpm add @gnosticdev/hono-actions
11
- # or
8
+ # with astro cli
9
+ astro add @gnosticdev/hono-actions
10
+
11
+ # package manager (npm, pnpm, bun, etc.)
12
12
  bun add @gnosticdev/hono-actions
13
13
  ```
14
14
 
@@ -16,14 +16,17 @@ bun add @gnosticdev/hono-actions
16
16
 
17
17
  This package requires:
18
18
 
19
- - `astro`: ^5.13.0
19
+ - `astro`: ^5.13.0 or ^6.0.0
20
+
21
+ > [!IMPORTANT]
22
+ > For typescript, make sure you set `strictNullChecks` to `true`, or extend `astro/tsconfigs/strict(est)` in your `tsconfig.json`
20
23
 
21
24
  ## Supported Adapters
22
25
 
23
26
  This integration works with all supported Astro adapters:
24
27
 
25
28
  - `@astrojs/cloudflare`
26
- - `@astrojs/node`
29
+ - `@astrojs/node` (standalone mode only)
27
30
  - `@astrojs/vercel`
28
31
  - `@astrojs/netlify`
29
32
 
@@ -33,7 +36,7 @@ This integration works with all supported Astro adapters:
33
36
 
34
37
  The integration works with all Astro adapters. Here are examples for each:
35
38
 
36
- #### Cloudflare
39
+ #### Cloudflare/Vercel/Netlify Adapter
37
40
 
38
41
  ```typescript
39
42
  // astro.config.ts
@@ -43,7 +46,7 @@ import honoActions from '@gnosticdev/hono-actions'
43
46
 
44
47
  export default defineConfig({
45
48
  output: 'server',
46
- adapter: cloudflare(),
49
+ adapter: cloudflare() // vercel() or netlify(),
47
50
  integrations: [
48
51
  honoActions({
49
52
  basePath: '/api', // Optional: default is '/api'
@@ -53,7 +56,9 @@ export default defineConfig({
53
56
  })
54
57
  ```
55
58
 
56
- #### Node.js
59
+ #### Node.js Adapter
60
+
61
+ Node.js adapter only supports the 'standalone' mode.
57
62
 
58
63
  ```typescript
59
64
  // astro.config.ts
@@ -64,65 +69,23 @@ import honoActions from '@gnosticdev/hono-actions'
64
69
  export default defineConfig({
65
70
  output: 'server',
66
71
  adapter: node({
67
- mode: 'standalone' // or 'middleware'
72
+ mode: 'standalone'
68
73
  }),
69
74
  integrations: [
70
- honoActions({
71
- basePath: '/api', // Optional: default is '/api'
72
- actionsPath: 'src/server/actions.ts' // Optional: custom path to your actions file
73
- })
74
- ]
75
- })
76
- ```
77
-
78
- #### Vercel
79
-
80
- ```typescript
81
- // astro.config.ts
82
- import { defineConfig } from 'astro/config'
83
- import vercel from '@astrojs/vercel/serverless'
84
- import honoActions from '@gnosticdev/hono-actions'
85
-
86
- export default defineConfig({
87
- output: 'server',
88
- adapter: vercel(),
89
- integrations: [
90
- honoActions({
91
- basePath: '/api', // Optional: default is '/api'
92
- actionsPath: 'src/server/actions.ts' // Optional: custom path to your actions file
93
- })
94
- ]
95
- })
96
- ```
97
-
98
- #### Netlify
99
-
100
- ```typescript
101
- // astro.config.ts
102
- import { defineConfig } from 'astro/config'
103
- import netlify from '@astrojs/netlify'
104
- import honoActions from '@gnosticdev/hono-actions'
105
-
106
- export default defineConfig({
107
- output: 'server',
108
- adapter: netlify(),
109
- integrations: [
110
- honoActions({
111
- basePath: '/api', // Optional: default is '/api'
112
- actionsPath: 'src/server/actions.ts' // Optional: custom path to your actions file
113
- })
75
+ honoActions()
114
76
  ]
115
77
  })
116
78
  ```
117
79
 
118
80
  ### 2. Create your actions file
119
81
 
120
- If not using a custom actions path, create a file at one of these locations:
82
+ Create a file at one of these locations, or use the `actionsPath` option to specify a custom path:
121
83
 
122
84
  - `src/server/actions.ts`
123
85
  - `src/hono/actions.ts`
124
86
  - `src/hono/index.ts`
125
87
  - `src/hono.ts`
88
+ - `src/hono-actions.ts`
126
89
 
127
90
  ## Usage
128
91
 
@@ -132,7 +95,6 @@ import { defineHonoAction type HonoEnv } from '@gnosticdev/hono-actions/actions'
132
95
  import { z } from 'astro/zod'
133
96
  import { Hono } from 'hono'
134
97
 
135
- // Define a POST action with Zod validation (no `path` option is used anymore)
136
98
  export const myAction = defineHonoAction({
137
99
  schema: z.object({
138
100
  name: z.string()
@@ -239,12 +201,6 @@ const handleSubmit = async (formData: FormData) => {
239
201
  }
240
202
  ```
241
203
 
242
- ## Advanced Usage
243
-
244
- ### Using AsyncLocalStorage with Custom Hono Instances
245
-
246
- For advanced use cases involving request-scoped data and custom Hono instances, see [docs/async_hooks.md](./docs/async_hooks.md).
247
-
248
204
  ## Augmenting Type Interfaces
249
205
 
250
206
  When using this library, you may need to augment the type interfaces to add custom types for your environment bindings, Hono context variables, or Astro locals. This is especially important when using the Cloudflare adapter.
@@ -253,6 +209,8 @@ When using this library, you may need to augment the type interfaces to add cust
253
209
 
254
210
  When using the `@astrojs/cloudflare` adapter, the library automatically exports Cloudflare runtime types. However, it assumes that Cloudflare types have been generated by Wrangler via the `wrangler types` command, which creates an `Env` interface that is automatically added to `HonoEnv['Bindings']`.
255
211
 
212
+ For Astro 6 and newer, use the matching Astro 6 adapter majors (`@astrojs/cloudflare` v13+, `@astrojs/node` v10+, `@astrojs/vercel` v10+, `@astrojs/netlify` v7+).
213
+
256
214
  To generate Cloudflare types:
257
215
 
258
216
  ```bash
@@ -382,6 +340,12 @@ If you get module resolution errors during development:
382
340
  1. Try clearing your node_modules and reinstalling
383
341
  2. Make sure you're using compatible versions of the peer dependencies
384
342
 
343
+ ## Advanced Usage
344
+
345
+ ### Using AsyncLocalStorage with Custom Hono Instances
346
+
347
+ For advanced use cases involving request-scoped data and custom Hono instances, see [docs/async_hooks.md](./docs/async_hooks.md).
348
+
385
349
  ## License
386
350
 
387
351
  MIT