@gnosticdev/hono-actions 1.0.5 → 1.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/package.json CHANGED
@@ -1,57 +1,47 @@
1
1
  {
2
2
  "author": {
3
+ "email": "nynxaconsulting@gmail.com",
3
4
  "name": "gnosticdev",
4
5
  "url": "https://github.com/gnosticdev"
5
6
  },
6
7
  "dependencies": {
7
- "@hono/valibot-validator": "0.5.3",
8
+ "@astrojs/cloudflare": "^12.6.7",
9
+ "@hono/valibot-validator": "^0.5.3",
8
10
  "astro-integration-kit": "^0.19.0",
9
- "fast-glob": "^3.3.3",
10
- "hono": "^4.9.4",
11
+ "hono": "^4.9.5",
11
12
  "valibot": "^1.1.0"
12
13
  },
13
- "description": "Type-safe Hono server actions with build-in validation",
14
+ "description": "Define server actions with built-in validation, error handling, and a pre-built hono client for calling the routes.",
14
15
  "devDependencies": {
15
- "@biomejs/biome": "^2.2.2",
16
- "@types/bun": "^1.2.20",
17
- "release-it": "^19.0.4",
18
16
  "tsup": "^8.5.0",
19
- "typescript": "5.9.2"
17
+ "typescript": "^5.9.2"
20
18
  },
21
- "engines": {
22
- "node": ">=22.0.0"
23
- },
24
- "engineStrict": true,
25
19
  "exports": {
26
20
  ".": {
27
- "types": "./dist/actions.d.ts",
28
- "default": "./dist/actions.js"
29
- },
30
- "./integration": {
31
- "types": "./dist/integration.d.ts",
32
- "default": "./dist/integration.js"
21
+ "default": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
33
23
  },
34
24
  "./*": {
35
- "types": "./dist/*.d.ts",
36
- "default": "./dist/*.js"
25
+ "default": "./dist/*.js",
26
+ "types": "./dist/*.d.ts"
37
27
  }
38
28
  },
39
29
  "files": [
40
30
  "dist"
41
31
  ],
32
+ "homepage": "https://github.com/gnosticdev/hono-actions",
42
33
  "keywords": [
43
- "hono",
44
- "actions",
34
+ "astro-integration",
35
+ "astro-component",
36
+ "withastro",
45
37
  "astro",
46
- "validation",
47
- "server actions"
38
+ "hono-actions"
48
39
  ],
49
40
  "license": "MIT",
50
- "main": "dist/actions.js",
41
+ "main": "./dist/index.js",
51
42
  "name": "@gnosticdev/hono-actions",
52
- "packageManager": "bun@1.2.21",
53
43
  "peerDependencies": {
54
- "astro": "^5.13.3"
44
+ "astro": "^5.1.3"
55
45
  },
56
46
  "publishConfig": {
57
47
  "access": "public"
@@ -59,14 +49,9 @@
59
49
  "scripts": {
60
50
  "build": "tsup",
61
51
  "dev": "tsup --watch",
62
- "prepublishOnly": "bun run build",
63
- "publish": "bun run release",
64
- "release": "release-it",
65
- "release:major": "release-it major",
66
- "release:minor": "release-it minor",
67
- "release:patch": "release-it patch"
52
+ "typecheck": "tsc --noEmit"
68
53
  },
69
54
  "type": "module",
70
- "types": "dist/actions.d.ts",
71
- "version": "1.0.5"
55
+ "types": "./dist/index.d.ts",
56
+ "version": "1.0.11"
72
57
  }
@@ -1,20 +0,0 @@
1
- import * as astro from 'astro';
2
- import { z } from 'astro/zod';
3
-
4
- declare const optionsSchema: z.ZodOptional<z.ZodObject<{
5
- basePath: z.ZodOptional<z.ZodString>;
6
- actionsPath: z.ZodOptional<z.ZodString>;
7
- }, "strip", z.ZodTypeAny, {
8
- basePath?: string | undefined;
9
- actionsPath?: string | undefined;
10
- }, {
11
- basePath?: string | undefined;
12
- actionsPath?: string | undefined;
13
- }>>;
14
- type IntegrationOptions = z.infer<typeof optionsSchema>;
15
- declare const _default: (options?: {
16
- basePath?: string | undefined;
17
- actionsPath?: string | undefined;
18
- } | undefined) => astro.AstroIntegration & {};
19
-
20
- export { type IntegrationOptions, _default as default };
@@ -1,216 +0,0 @@
1
- // src/integration.ts
2
- import fs from "fs/promises";
3
- import path from "path";
4
- import { z } from "astro/zod";
5
- import {
6
- addVirtualImports,
7
- createResolver,
8
- defineIntegration
9
- } from "astro-integration-kit";
10
- import fg from "fast-glob";
11
-
12
- // src/integration-files.ts
13
- function generateRouter(opts) {
14
- const { basePath, relativeActionsPath } = opts;
15
- return `import type { HonoEnv } from '@gnosticdev/hono-actions'
16
- import { Hono } from 'hono'
17
- import { cors } from 'hono/cors'
18
- import { showRoutes } from 'hono/dev'
19
- import { logger } from 'hono/logger'
20
- import { prettyJSON } from 'hono/pretty-json'
21
- import type { ExtractSchema, MergeSchemaPath } from 'hono/types'
22
-
23
- export async function buildRouter(){
24
- type ActionSchema = ExtractSchema<typeof honoActions[keyof typeof honoActions]>
25
- const { honoActions} = await import('${relativeActionsPath}')
26
- const app = new Hono<HonoEnv, MergeSchemaPath<ActionSchema, '${basePath}'>>().basePath('${basePath}')
27
-
28
- app.use('*', cors(), logger(), prettyJSON())
29
-
30
- for (const [path, action] of Object.entries(honoActions)) {
31
- app.route(path, action)
32
- }
33
-
34
- showRoutes(app)
35
- return app
36
- }
37
-
38
- export type HonoRouter = Awaited<ReturnType<typeof buildRouter>>
39
-
40
- const app = await buildRouter()
41
- export default app`;
42
- }
43
- var getAstroHandler = (adapter) => {
44
- switch (adapter) {
45
- case "cloudflare":
46
- return `
47
- // Generated by Hono Actions Integration
48
- import router from './router.js'
49
- import type { APIContext, APIRoute } from 'astro'
50
-
51
- const handler: APIRoute<APIContext> = async (ctx) => {
52
- return router.fetch(
53
- ctx.request,
54
- ctx.locals.runtime.env,
55
- ctx.locals.runtime.ctx,
56
- )
57
- }
58
-
59
- export { handler as ALL }
60
- `;
61
- default:
62
- throw new Error(`Unsupported adapter: ${adapter}`);
63
- }
64
- };
65
- var getHonoClient = (port) => `
66
- // Generated by Hono Actions Integration
67
- import type { HonoRouter } from './router.js'
68
- import { hc } from 'hono/client'
69
-
70
- export function getBaseUrl() {
71
- // client side can just use the base path
72
- if (typeof window !== 'undefined') {
73
- return '/'
74
- }
75
-
76
- // dev server (dev server) needs to know the port
77
- if (import.meta.env.DEV) {
78
- return \`http://localhost:\${${port}}\`
79
- }
80
-
81
- // server side (production) needs full url
82
- return import.meta.env.SITE
83
- }
84
-
85
- export const honoClient = hc<HonoRouter>(getBaseUrl())
86
- `;
87
-
88
- // src/lib/utils.ts
89
- var reservedRoutes = ["_astro", "_actions", "_server_islands"];
90
-
91
- // src/integration.ts
92
- var optionsSchema = z.object({
93
- basePath: z.string().optional(),
94
- actionsPath: z.string().optional()
95
- }).optional();
96
- var VIRTUAL_MODULE_ID_CLIENT = "@gnostic/hono-actions/client";
97
- var VIRTUAL_MODULE_ID_ROUTER = "virtual:hono-actions/router";
98
- var ACTION_PATTERNS = [
99
- "src/**/server/actions.ts",
100
- "src/**/hono/actions.ts",
101
- "src/**/hono/index.ts",
102
- "src/**/hono.ts"
103
- ];
104
- var integration_default = defineIntegration({
105
- name: "@gnostic/hono-actions",
106
- optionsSchema,
107
- setup: ({ options = {}, name }) => {
108
- const basePath = options.basePath ?? "/api";
109
- if (reservedRoutes.includes(basePath)) {
110
- throw new Error(
111
- `Base path ${basePath} is reserved by Astro; pick another (e.g. /api2).`
112
- );
113
- }
114
- const { resolve } = createResolver(import.meta.url);
115
- return {
116
- name,
117
- hooks: {
118
- "astro:config:setup": async (params) => {
119
- const { logger, injectRoute, createCodegenDir, config } = params;
120
- const root = config.root.pathname;
121
- const files = await fg(ACTION_PATTERNS, {
122
- cwd: root,
123
- absolute: true
124
- });
125
- const actionsPath = options.actionsPath ?? files[0];
126
- if (!actionsPath) {
127
- throw new Error(
128
- `No actions found. Create one of:
129
- ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
130
- );
131
- }
132
- const resolvedActionsPath = path.isAbsolute(actionsPath) ? actionsPath : path.join(root, actionsPath);
133
- params.addWatchFile(resolvedActionsPath);
134
- logger.info(
135
- `Found actions: ${path.relative(root, resolvedActionsPath)}`
136
- );
137
- const codeGenDir = createCodegenDir();
138
- const routerPathAbs = path.join(
139
- codeGenDir.pathname,
140
- "router.ts"
141
- );
142
- const relFromGenToActions = path.relative(codeGenDir.pathname, resolvedActionsPath).split(path.sep).join("/");
143
- const routerContent = generateRouter({
144
- basePath,
145
- relativeActionsPath: relFromGenToActions
146
- });
147
- await fs.writeFile(routerPathAbs, routerContent, "utf-8");
148
- const astroHandlerPathAbs = path.join(
149
- codeGenDir.pathname,
150
- "api.ts"
151
- );
152
- if (!params.config.adapter?.name)
153
- throw new Error("No Astro adapter found");
154
- const astroHandlerContent = getAstroHandler("cloudflare");
155
- await fs.writeFile(
156
- astroHandlerPathAbs,
157
- astroHandlerContent,
158
- "utf-8"
159
- );
160
- const clientPathAbs = path.join(
161
- codeGenDir.pathname,
162
- "client.ts"
163
- );
164
- const clientContent = getHonoClient(config.server.port);
165
- await fs.writeFile(clientPathAbs, clientContent, "utf-8");
166
- addVirtualImports(params, {
167
- name,
168
- imports: {
169
- [VIRTUAL_MODULE_ID_CLIENT]: `export * from '${clientPathAbs}';`,
170
- [VIRTUAL_MODULE_ID_ROUTER]: `export * from '${routerPathAbs}';`
171
- }
172
- });
173
- injectRoute({
174
- pattern: `${basePath}/[...slug]`,
175
- entrypoint: astroHandlerPathAbs,
176
- prerender: false
177
- });
178
- logger.info(
179
- `\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
180
- );
181
- },
182
- "astro:config:done": async ({ injectTypes }) => {
183
- injectTypes({
184
- filename: "actions.d.ts",
185
- content: `
186
- declare module '@gnosticdev/hono-actions' {
187
- interface Bindings extends Env { ASTRO_LOCALS: App.Locals }
188
- interface HonoEnv { Bindings: Bindings }
189
- }
190
- export {}
191
- `
192
- });
193
- injectTypes({
194
- filename: "types.d.ts",
195
- content: `
196
- // Generated by Hono Actions Integration
197
-
198
- declare module 'virtual:hono-actions/router' {
199
- export type HonoRouter = import('./router.ts').HonoRouter
200
- const app: typeof import('./router.ts').default
201
- export default app
202
- }
203
-
204
- declare module '@gnostic/hono-actions/client' {
205
- export const honoClient: typeof import('./client').honoClient
206
- }
207
- `
208
- });
209
- }
210
- }
211
- };
212
- }
213
- });
214
- export {
215
- integration_default as default
216
- };