@gnosticdev/hono-actions 2.0.10 → 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
@@ -248,7 +248,9 @@ var integration_default = defineIntegration({
248
248
  "astro:config:setup": async (params) => {
249
249
  const { logger, injectRoute, createCodegenDir, config } = params;
250
250
  const root = config.root.pathname;
251
- const absPatterns = ACTION_PATTERNS.map((p) => path.join(root, p));
251
+ const absPatterns = ACTION_PATTERNS.map(
252
+ (p) => path.join(root, p)
253
+ );
252
254
  const files = await glob(absPatterns, {
253
255
  expandDirectories: false,
254
256
  absolute: true
@@ -270,7 +272,10 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
270
272
  `Found actions: ${path.relative(root, resolvedActionsPath)}`
271
273
  );
272
274
  const codeGenDir = createCodegenDir();
273
- const routerPathAbs = path.join(codeGenDir.pathname, "router.ts");
275
+ const routerPathAbs = path.join(
276
+ codeGenDir.pathname,
277
+ "router.ts"
278
+ );
274
279
  const relFromGenToActions = path.relative(codeGenDir.pathname, resolvedActionsPath).split(path.sep).join("/");
275
280
  const adapter = params.config.adapter?.name;
276
281
  if (!adapter) {
@@ -292,10 +297,20 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
292
297
  adapter
293
298
  });
294
299
  await fs.writeFile(routerPathAbs, routerContent, "utf-8");
295
- const astroHandlerPathAbs = path.join(codeGenDir.pathname, "api.ts");
300
+ const astroHandlerPathAbs = path.join(
301
+ codeGenDir.pathname,
302
+ "api.ts"
303
+ );
296
304
  const astroHandlerContent = generateAstroHandler(adapter);
297
- await fs.writeFile(astroHandlerPathAbs, astroHandlerContent, "utf-8");
298
- const clientPathAbs = path.join(codeGenDir.pathname, "client.ts");
305
+ await fs.writeFile(
306
+ astroHandlerPathAbs,
307
+ astroHandlerContent,
308
+ "utf-8"
309
+ );
310
+ const clientPathAbs = path.join(
311
+ codeGenDir.pathname,
312
+ "client.ts"
313
+ );
299
314
  if (!config.site) {
300
315
  logger.warn(
301
316
  "No site url found in astro config, add one if you want to use the hono client with SSR"
@@ -316,9 +331,15 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
316
331
  entrypoint: astroHandlerPathAbs,
317
332
  prerender: false
318
333
  });
319
- logger.info(`\u2705 Hono Actions route mounted at ${basePath}/[...slug]`);
334
+ logger.info(
335
+ `\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
336
+ );
320
337
  },
321
- "astro:config:done": async ({ injectTypes, config, logger }) => {
338
+ "astro:config:done": async ({
339
+ injectTypes,
340
+ config,
341
+ logger
342
+ }) => {
322
343
  const adapter = config.adapter?.name;
323
344
  if (!adapter) {
324
345
  logger.warn("No adapter found...");
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.10"
64
+ "version": "2.0.11"
65
65
  }