@gnosticdev/hono-actions 1.0.0 → 1.0.1
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 +9 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hono Actions for Astro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Astro Actions with Hono and Valibot. Define server actions with built-in validation, error handling, and a pre-built hono client for calling the routes.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @gnosticdev/
|
|
8
|
+
npm install @gnosticdev/hono-actions
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Peer Dependencies
|
|
@@ -19,14 +19,18 @@ This package requires the following peer dependencies:
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { defineHonoAction, ActionError } from '@gnosticdev/
|
|
22
|
+
import { defineHonoAction, ActionError } from '@gnosticdev/hono-actions'
|
|
23
23
|
import * as v from 'valibot'
|
|
24
24
|
|
|
25
25
|
// Define a simple action
|
|
26
26
|
export const simpleAction = defineHonoAction({
|
|
27
27
|
path: '/simple',
|
|
28
|
+
schema: v.object({
|
|
29
|
+
name: v.string()
|
|
30
|
+
}),
|
|
28
31
|
handler: async (input, ctx) => {
|
|
29
|
-
|
|
32
|
+
// input is automatically typed based on schema
|
|
33
|
+
return { message: `Hello ${input.name}!` }
|
|
30
34
|
}
|
|
31
35
|
})
|
|
32
36
|
|
|
@@ -65,25 +69,6 @@ export const honoActions = {
|
|
|
65
69
|
}
|
|
66
70
|
```
|
|
67
71
|
|
|
68
|
-
## Types
|
|
69
|
-
|
|
70
|
-
The package exports the following types:
|
|
71
|
-
|
|
72
|
-
- `ActionErrorCode`: Union type of possible error codes
|
|
73
|
-
- `ActionError`: Custom error class for action errors
|
|
74
|
-
- `HonoActions`: Type for collections of actions
|
|
75
|
-
|
|
76
|
-
## Error Codes
|
|
77
|
-
|
|
78
|
-
Available error codes:
|
|
79
|
-
|
|
80
|
-
- `INPUT_VALIDATION_ERROR`: Validation failed for input data
|
|
81
|
-
- `EXTERNAL_API_ERROR`: Error calling external API
|
|
82
|
-
- `INTERNAL_SERVER_ERROR`: Internal server error
|
|
83
|
-
- `UNKNOWN_ERROR`: Unknown error occurred
|
|
84
|
-
- `LOCATION_NOT_FOUND`: Location not found
|
|
85
|
-
- `SESSION_NOT_FOUND`: Session not found
|
|
86
|
-
|
|
87
72
|
## License
|
|
88
73
|
|
|
89
74
|
MIT
|
package/package.json
CHANGED