@gnosticdev/hono-actions 1.1.0 → 1.1.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/dist/actions.d.ts +26 -2
- package/dist/actions.js +1 -1
- package/dist/index.js +5 -9
- package/package.json +1 -1
package/dist/actions.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import * as hono_utils_types from 'hono/utils/types';
|
|
|
3
3
|
import * as zod_v4 from 'zod/v4';
|
|
4
4
|
import * as zod_v4_core from 'zod/v4/core';
|
|
5
5
|
import { z } from 'astro/zod';
|
|
6
|
-
import { Context } from 'hono';
|
|
6
|
+
import { Hono, Context } from 'hono';
|
|
7
|
+
import { MergeSchemaPath } from 'hono/types';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Standard error codes for actions
|
|
@@ -31,6 +32,29 @@ interface HonoEnv {
|
|
|
31
32
|
Variables: Record<string, unknown>;
|
|
32
33
|
}
|
|
33
34
|
type HonoActionSchema = z.ZodTypeAny;
|
|
35
|
+
/**
|
|
36
|
+
* Merge each action key into its route path.
|
|
37
|
+
*
|
|
38
|
+
* Given a map of actions where each `Hono` app defines handlers at `"/"`, this
|
|
39
|
+
* transforms the schema so each action's path becomes `"/${key}"`.
|
|
40
|
+
*
|
|
41
|
+
* Example:
|
|
42
|
+
* ```ts
|
|
43
|
+
* declare const honoActions: {
|
|
44
|
+
* myAction: Hono<HonoEnv, { '/': { $post: any } }, '/'>
|
|
45
|
+
* anotherAction: Hono<HonoEnv, { '/': { $post: any } }, '/'>
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* type ActionsWithKeyedPaths = MergeActionKeyIntoPath<typeof honoActions>
|
|
49
|
+
* // => {
|
|
50
|
+
* // myAction: Hono<HonoEnv, { '/myAction': { $post: any } }, '/'>
|
|
51
|
+
* // anotherAction: Hono<HonoEnv, { '/anotherAction': { $post: any } }, '/'>
|
|
52
|
+
* // }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
type MergeActionKeyIntoPath<TActions extends Record<string, Hono<any, any, any>>> = {
|
|
56
|
+
[K in keyof TActions]: TActions[K] extends Hono<infer TEnv, infer TSchema, infer TBase> ? Hono<TEnv, MergeSchemaPath<TSchema, `/${Extract<K, string>}`>, TBase> : never;
|
|
57
|
+
};
|
|
34
58
|
interface HonoActionContext<TEnv extends HonoEnv, TSchema extends HonoActionSchema> extends Context<TEnv, '/', {
|
|
35
59
|
input: z.input<TSchema>;
|
|
36
60
|
output: z.output<TSchema>;
|
|
@@ -135,4 +159,4 @@ declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActi
|
|
|
135
159
|
};
|
|
136
160
|
}, "/">;
|
|
137
161
|
|
|
138
|
-
export { type Bindings, HonoActionError, type HonoEnv, defineHonoAction };
|
|
162
|
+
export { type Bindings, HonoActionError, type HonoEnv, type MergeActionKeyIntoPath, defineHonoAction };
|
package/dist/actions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/actions.ts
|
|
2
2
|
import { zValidator } from "@hono/zod-validator";
|
|
3
3
|
import { z } from "astro/zod";
|
|
4
|
+
import { Hono } from "hono/quick";
|
|
4
5
|
|
|
5
6
|
// src/error.ts
|
|
6
7
|
var HonoActionError = class extends Error {
|
|
@@ -19,7 +20,6 @@ var HonoActionError = class extends Error {
|
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
// src/actions.ts
|
|
22
|
-
import { Hono } from "hono/quick";
|
|
23
23
|
function defineHonoAction({ schema, handler }) {
|
|
24
24
|
const app = new Hono();
|
|
25
25
|
const route = app.post(
|
package/dist/index.js
CHANGED
|
@@ -2282,7 +2282,7 @@ async function glob(patternsOrOptions, options) {
|
|
|
2282
2282
|
// src/integration-files.ts
|
|
2283
2283
|
function generateRouter(opts) {
|
|
2284
2284
|
const { basePath, relativeActionsPath } = opts;
|
|
2285
|
-
return `import type { HonoEnv } from '@gnosticdev/hono-actions/actions'
|
|
2285
|
+
return `import type { HonoEnv, MergeActionKeyIntoPath } from '@gnosticdev/hono-actions/actions'
|
|
2286
2286
|
import { Hono } from 'hono'
|
|
2287
2287
|
import { cors } from 'hono/cors'
|
|
2288
2288
|
import { showRoutes } from 'hono/dev'
|
|
@@ -2291,9 +2291,10 @@ import { prettyJSON } from 'hono/pretty-json'
|
|
|
2291
2291
|
import type { ExtractSchema, MergeSchemaPath } from 'hono/types'
|
|
2292
2292
|
|
|
2293
2293
|
async function buildRouter(){
|
|
2294
|
-
type
|
|
2294
|
+
type ActionsWithKeyedPaths = MergeActionKeyIntoPath<typeof honoActions>
|
|
2295
|
+
type ActionSchema = ExtractSchema<ActionsWithKeyedPaths[keyof ActionsWithKeyedPaths]>
|
|
2295
2296
|
const { honoActions} = await import('${relativeActionsPath}')
|
|
2296
|
-
const app = new Hono<HonoEnv, MergeSchemaPath<ActionSchema,
|
|
2297
|
+
const app = new Hono<HonoEnv, MergeSchemaPath<ActionSchema, \`${basePath}\`>>().basePath('${basePath}')
|
|
2297
2298
|
|
|
2298
2299
|
app.use('*', cors(), logger(), prettyJSON())
|
|
2299
2300
|
|
|
@@ -2484,14 +2485,9 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
2484
2485
|
content: `
|
|
2485
2486
|
// Generated by Hono Actions Integration
|
|
2486
2487
|
|
|
2487
|
-
declare module 'virtual:hono-actions/router' {
|
|
2488
|
-
export type HonoRouter = import('./router.ts').HonoRouter
|
|
2489
|
-
const app: typeof import('./router.ts').default
|
|
2490
|
-
export default app
|
|
2491
|
-
}
|
|
2492
|
-
|
|
2493
2488
|
declare module '@gnosticdev/hono-actions/client' {
|
|
2494
2489
|
export const honoClient: typeof import('./client').honoClient
|
|
2490
|
+
export const parseResponse: typeof import('./client').parseResponse
|
|
2495
2491
|
}
|
|
2496
2492
|
`
|
|
2497
2493
|
});
|
package/package.json
CHANGED