@gnosticdev/hono-actions 2.0.0 → 2.0.2
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 +19 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ The integration works with all Astro adapters. Here are examples for each:
|
|
|
39
39
|
// astro.config.ts
|
|
40
40
|
import { defineConfig } from 'astro/config'
|
|
41
41
|
import cloudflare from '@astrojs/cloudflare'
|
|
42
|
-
import honoActions from '@gnosticdev/hono-actions
|
|
42
|
+
import honoActions from '@gnosticdev/hono-actions'
|
|
43
43
|
|
|
44
44
|
export default defineConfig({
|
|
45
45
|
output: 'server',
|
|
@@ -59,7 +59,7 @@ export default defineConfig({
|
|
|
59
59
|
// astro.config.ts
|
|
60
60
|
import { defineConfig } from 'astro/config'
|
|
61
61
|
import node from '@astrojs/node'
|
|
62
|
-
import honoActions from '@gnosticdev/hono-actions
|
|
62
|
+
import honoActions from '@gnosticdev/hono-actions'
|
|
63
63
|
|
|
64
64
|
export default defineConfig({
|
|
65
65
|
output: 'server',
|
|
@@ -81,7 +81,7 @@ export default defineConfig({
|
|
|
81
81
|
// astro.config.ts
|
|
82
82
|
import { defineConfig } from 'astro/config'
|
|
83
83
|
import vercel from '@astrojs/vercel/serverless'
|
|
84
|
-
import honoActions from '@gnosticdev/hono-actions
|
|
84
|
+
import honoActions from '@gnosticdev/hono-actions'
|
|
85
85
|
|
|
86
86
|
export default defineConfig({
|
|
87
87
|
output: 'server',
|
|
@@ -101,7 +101,7 @@ export default defineConfig({
|
|
|
101
101
|
// astro.config.ts
|
|
102
102
|
import { defineConfig } from 'astro/config'
|
|
103
103
|
import netlify from '@astrojs/netlify'
|
|
104
|
-
import honoActions from '@gnosticdev/hono-actions
|
|
104
|
+
import honoActions from '@gnosticdev/hono-actions'
|
|
105
105
|
|
|
106
106
|
export default defineConfig({
|
|
107
107
|
output: 'server',
|
|
@@ -214,22 +214,28 @@ const { message } = await parseResponse(
|
|
|
214
214
|
```typescript
|
|
215
215
|
// In a client-side script or component
|
|
216
216
|
import { honoClient } from '@gnosticdev/hono-actions/client'
|
|
217
|
+
import type { DetailedError } from '@gnosticdev/hono-actions/client'
|
|
217
218
|
|
|
218
219
|
// Make requests from the browser
|
|
219
220
|
const handleSubmit = async (formData: FormData) => {
|
|
220
|
-
const
|
|
221
|
+
const { data, error } = await parseResponse(await honoClient.api.anotherAction.$post({
|
|
221
222
|
json: {
|
|
222
223
|
name2: formData.get('name') as string
|
|
223
224
|
}
|
|
225
|
+
}).catch((err: DetailedError) => {
|
|
226
|
+
console.error('Error:', err)
|
|
227
|
+
return {
|
|
228
|
+
data: null,
|
|
229
|
+
error: err
|
|
230
|
+
}
|
|
224
231
|
})
|
|
225
232
|
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
console.log('Success:', result)
|
|
229
|
-
} else {
|
|
230
|
-
const error = await response.text()
|
|
231
|
-
console.error('Error:', error)
|
|
233
|
+
if (error){
|
|
234
|
+
throw new Error(`Action failed: ${error.message}`)
|
|
232
235
|
}
|
|
236
|
+
|
|
237
|
+
// type safe access to the data
|
|
238
|
+
console.log('my name is ', data.name2)
|
|
233
239
|
}
|
|
234
240
|
```
|
|
235
241
|
|
|
@@ -237,11 +243,11 @@ const handleSubmit = async (formData: FormData) => {
|
|
|
237
243
|
|
|
238
244
|
This package provides these entry points:
|
|
239
245
|
|
|
240
|
-
- **`@gnosticdev/hono-actions/actions`**: Action definition utilities (`defineHonoAction`, `HonoActionError`, `HonoEnv`)
|
|
246
|
+
- **`@gnosticdev/hono-actions/actions`**: Action definition utilities (`defineHonoAction`, `HonoActionError`, `HonoEnv` (for cloudflare usage))
|
|
241
247
|
- Used in your actions file(s)
|
|
242
248
|
- **`@gnosticdev/hono-actions/client`**: Pre-built Hono client and helpers (`honoClient`, `parseResponse`)
|
|
243
249
|
- Safe for browser and server environments
|
|
244
|
-
- **`@gnosticdev/hono-actions
|
|
250
|
+
- **`@gnosticdev/hono-actions`**: Astro integration
|
|
245
251
|
- Uses Node.js built-ins (fs, path)
|
|
246
252
|
- Only used in `astro.config.ts`
|
|
247
253
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"@hono/standard-validator": "^0.2.0",
|
|
8
8
|
"@hono/zod-validator": "^0.2.2",
|
|
9
9
|
"astro-integration-kit": "^0.19.0",
|
|
10
|
-
"hono": "
|
|
10
|
+
"hono": "^4.10.6",
|
|
11
11
|
"tinyglobby": "^0.2.15"
|
|
12
12
|
},
|
|
13
13
|
"description": "Define server actions with built-in validation, error handling, and a pre-built hono client for calling the routes.",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"main": "./dist/index.js",
|
|
50
50
|
"name": "@gnosticdev/hono-actions",
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"astro": "
|
|
52
|
+
"astro": "^5.13.0"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
},
|
|
62
62
|
"type": "module",
|
|
63
63
|
"types": "./dist/index.d.ts",
|
|
64
|
-
"version": "2.0.
|
|
64
|
+
"version": "2.0.2"
|
|
65
65
|
}
|