@gnosticdev/hono-actions 2.0.9 → 2.0.11

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
 
@@ -18,12 +18,15 @@ This package requires:
18
18
 
19
19
  - `astro`: ^5.13.0
20
20
 
21
+ > [!IMPORTANT]
22
+ > For typescript, make sure you set `strictNullChecks` to `true`, or extend `astro/tsconfigs/strict(est)` in your `tsconfig.json`
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.
@@ -382,6 +338,12 @@ If you get module resolution errors during development:
382
338
  1. Try clearing your node_modules and reinstalling
383
339
  2. Make sure you're using compatible versions of the peer dependencies
384
340
 
341
+ ## Advanced Usage
342
+
343
+ ### Using AsyncLocalStorage with Custom Hono Instances
344
+
345
+ For advanced use cases involving request-scoped data and custom Hono instances, see [docs/async_hooks.md](./docs/async_hooks.md).
346
+
385
347
  ## License
386
348
 
387
349
  MIT
package/dist/actions.d.ts CHANGED
@@ -7,7 +7,7 @@ import { MergeSchemaPath } from 'hono/types';
7
7
  /**
8
8
  * Standard error codes for actions
9
9
  */
10
- type ActionErrorCode = 'INPUT_VALIDATION_ERROR' | 'EXTERNAL_API_ERROR' | 'INTERNAL_SERVER_ERROR' | 'UNKNOWN_ERROR' | 'LOCATION_NOT_FOUND' | 'SESSION_NOT_FOUND';
10
+ type ActionErrorCode = 'INPUT_VALIDATION_ERROR' | 'EXTERNAL_API_ERROR' | 'INTERNAL_SERVER_ERROR' | 'UNKNOWN_ERROR' | 'LOCATION_NOT_FOUND' | 'SESSION_NOT_FOUND' | (string & {});
11
11
  declare class HonoActionError<TMessage extends string, TCode extends ActionErrorCode, TIssue = any> extends Error {
12
12
  code: TCode;
13
13
  issue?: TIssue;
@@ -42,7 +42,7 @@ interface HonoEnv {
42
42
  Bindings: Bindings;
43
43
  Variables: Variables;
44
44
  }
45
- type HonoActionSchema = z.ZodTypeAny;
45
+ type HonoActionSchema = z.ZodType<any, z.ZodTypeDef, any>;
46
46
  /**
47
47
  * Merge each action key into its route path.
48
48
  *
package/dist/index.js CHANGED
@@ -241,19 +241,25 @@ var integration_default = defineIntegration({
241
241
  );
242
242
  }
243
243
  const { resolve } = createResolver(import.meta.url);
244
+ const IS_DEBUG = process.env.__DEBUG__ === "true";
244
245
  return {
245
246
  name,
246
247
  hooks: {
247
248
  "astro:config:setup": async (params) => {
248
249
  const { logger, injectRoute, createCodegenDir, config } = params;
249
250
  const root = config.root.pathname;
250
- const files = await glob(ACTION_PATTERNS, {
251
- cwd: root,
251
+ const absPatterns = ACTION_PATTERNS.map(
252
+ (p) => path.join(root, p)
253
+ );
254
+ const files = await glob(absPatterns, {
252
255
  expandDirectories: false,
253
256
  absolute: true
254
257
  });
258
+ if (IS_DEBUG) {
259
+ logger.info(`DEBUG: Found actions: ${files.join("\n")}`);
260
+ }
255
261
  const actionsPath = options.actionsPath ?? files[0];
256
- if (!actionsPath) {
262
+ if (!actionsPath || actionsPath.includes("node_modules")) {
257
263
  logger.warn(
258
264
  `No actions found. Create one of:
259
265
  ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
package/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  },
62
62
  "type": "module",
63
63
  "types": "./dist/index.d.ts",
64
- "version": "2.0.9"
64
+ "version": "2.0.11"
65
65
  }