@gnosticdev/hono-actions 1.0.18 → 1.1.0
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 +94 -94
- package/dist/actions.js +22 -26
- package/dist/index.d.ts +18 -0
- package/dist/index.js +30 -12
- package/package.json +7 -7
package/dist/actions.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as hono_hono_base from 'hono/hono-base';
|
|
2
2
|
import * as hono_utils_types from 'hono/utils/types';
|
|
3
|
-
import * as
|
|
3
|
+
import * as zod_v4 from 'zod/v4';
|
|
4
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
5
|
+
import { z } from 'astro/zod';
|
|
4
6
|
import { Context } from 'hono';
|
|
5
|
-
import * as v from 'valibot';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Standard error codes for actions
|
|
9
10
|
*/
|
|
10
11
|
type ActionErrorCode = 'INPUT_VALIDATION_ERROR' | 'EXTERNAL_API_ERROR' | 'INTERNAL_SERVER_ERROR' | 'UNKNOWN_ERROR' | 'LOCATION_NOT_FOUND' | 'SESSION_NOT_FOUND';
|
|
11
|
-
declare class HonoActionError<
|
|
12
|
+
declare class HonoActionError<TMessage extends string, TCode extends ActionErrorCode, TIssue = any> extends Error {
|
|
12
13
|
code: TCode;
|
|
13
14
|
issue?: TIssue;
|
|
14
15
|
constructor({ message, code, issue, }: {
|
|
@@ -29,110 +30,109 @@ interface HonoEnv {
|
|
|
29
30
|
Bindings: Bindings;
|
|
30
31
|
Variables: Record<string, unknown>;
|
|
31
32
|
}
|
|
32
|
-
type HonoActionSchema =
|
|
33
|
-
interface HonoActionContext<TEnv extends HonoEnv,
|
|
34
|
-
input:
|
|
35
|
-
output:
|
|
33
|
+
type HonoActionSchema = z.ZodTypeAny;
|
|
34
|
+
interface HonoActionContext<TEnv extends HonoEnv, TSchema extends HonoActionSchema> extends Context<TEnv, '/', {
|
|
35
|
+
input: z.input<TSchema>;
|
|
36
|
+
output: z.output<TSchema>;
|
|
36
37
|
outputFormat: 'json';
|
|
37
38
|
}> {
|
|
38
39
|
env: TEnv['Bindings'];
|
|
39
40
|
}
|
|
40
|
-
type HonoActionParams<
|
|
41
|
-
path: TPath;
|
|
41
|
+
type HonoActionParams<TSchema extends HonoActionSchema, TReturn, TEnv extends HonoEnv = HonoEnv> = {
|
|
42
42
|
schema?: TSchema;
|
|
43
|
-
handler: (params:
|
|
43
|
+
handler: (params: z.output<TSchema>, context: HonoActionContext<TEnv, TSchema>) => Promise<TReturn>;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
* Defines a type-safe Hono action using
|
|
46
|
+
* Defines a type-safe Hono action using Zod for input validation.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @param schema - The object schema for Valibot validation.
|
|
50
|
-
* @default never
|
|
48
|
+
* @param schema - The Zod schema for validation (optional).
|
|
51
49
|
* @param handler - The handler function for the action.
|
|
52
50
|
* @returns A Hono app instance with the defined route
|
|
53
51
|
*/
|
|
54
|
-
declare function defineHonoAction<TEnv extends HonoEnv,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
output: unknown extends ({
|
|
66
|
-
data: Awaited<TReturn>;
|
|
67
|
-
error: null;
|
|
68
|
-
} extends hono_utils_types.JSONValue ? { [K_2 in keyof {
|
|
69
|
-
data: Awaited<TReturn>;
|
|
70
|
-
error: null;
|
|
71
|
-
} as ({
|
|
72
|
-
data: Awaited<TReturn>;
|
|
73
|
-
error: null;
|
|
74
|
-
}[K_2] extends infer T_5 ? T_5 extends {
|
|
75
|
-
data: Awaited<TReturn>;
|
|
76
|
-
error: null;
|
|
77
|
-
}[K_2] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K_2]: boolean extends ({
|
|
78
|
-
data: Awaited<TReturn>;
|
|
79
|
-
error: null;
|
|
80
|
-
}[K_2] extends infer T_6 ? T_6 extends {
|
|
81
|
-
data: Awaited<TReturn>;
|
|
82
|
-
error: null;
|
|
83
|
-
}[K_2] ? T_6 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
84
|
-
data: Awaited<TReturn>;
|
|
85
|
-
error: null;
|
|
86
|
-
}[K_2]> | undefined : hono_utils_types.JSONParsed<{
|
|
87
|
-
data: Awaited<TReturn>;
|
|
88
|
-
error: null;
|
|
89
|
-
}[K_2]>; } : never) ? {} : {
|
|
90
|
-
data: Awaited<TReturn>;
|
|
91
|
-
error: null;
|
|
92
|
-
} extends hono_utils_types.JSONValue ? { [K_2 in keyof {
|
|
93
|
-
data: Awaited<TReturn>;
|
|
94
|
-
error: null;
|
|
95
|
-
} as ({
|
|
96
|
-
data: Awaited<TReturn>;
|
|
97
|
-
error: null;
|
|
98
|
-
}[K_2] extends infer T_5 ? T_5 extends {
|
|
99
|
-
data: Awaited<TReturn>;
|
|
100
|
-
error: null;
|
|
101
|
-
}[K_2] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K_2]: boolean extends ({
|
|
102
|
-
data: Awaited<TReturn>;
|
|
103
|
-
error: null;
|
|
104
|
-
}[K_2] extends infer T_6 ? T_6 extends {
|
|
105
|
-
data: Awaited<TReturn>;
|
|
106
|
-
error: null;
|
|
107
|
-
}[K_2] ? T_6 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
108
|
-
data: Awaited<TReturn>;
|
|
109
|
-
error: null;
|
|
110
|
-
}[K_2]> | undefined : hono_utils_types.JSONParsed<{
|
|
111
|
-
data: Awaited<TReturn>;
|
|
112
|
-
error: null;
|
|
113
|
-
}[K_2]>; } : never;
|
|
114
|
-
outputFormat: "json";
|
|
115
|
-
status: 200;
|
|
116
|
-
} | {
|
|
117
|
-
input: hono_types.AddParam<unknown extends ((undefined extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? true : false) extends true ? {
|
|
118
|
-
json?: (v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> extends infer T_5 ? T_5 extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? T_5 extends any ? T_5 : { [K2_4 in keyof T_5]?: any; } : never : never) | undefined;
|
|
119
|
-
} : {
|
|
120
|
-
json: v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> extends infer T_6 ? T_6 extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? T_6 extends any ? T_6 : { [K2_5 in keyof T_6]: any; } : never : never;
|
|
121
|
-
}) ? {} : (undefined extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? true : false) extends true ? {
|
|
122
|
-
json?: (v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> extends infer T_7 ? T_7 extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? T_7 extends any ? T_7 : { [K2_6 in keyof T_7]?: any; } : never : never) | undefined;
|
|
123
|
-
} : {
|
|
124
|
-
json: v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> extends infer T_8 ? T_8 extends v.InferInput<TSchema | v.UnionSchema<[v.NeverSchema<undefined>, v.ObjectSchema<{}, undefined>], undefined>> ? T_8 extends any ? T_8 : { [K2_7 in keyof T_8]: any; } : never : never;
|
|
125
|
-
}, hono_types.MergePath<"/", TPath>>;
|
|
126
|
-
output: {
|
|
127
|
-
data: null;
|
|
128
|
-
error: {
|
|
129
|
-
message: string;
|
|
130
|
-
code: string;
|
|
52
|
+
declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActionSchema, TReturn>({ schema, handler }: HonoActionParams<TSchema, TReturn, TEnv>): hono_hono_base.HonoBase<TEnv, {
|
|
53
|
+
"/": {
|
|
54
|
+
$post: {
|
|
55
|
+
input: unknown extends ((undefined extends {} | (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? true : false) extends true ? {
|
|
56
|
+
json?: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T ? T extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T extends any ? T : { [K2 in keyof T]?: any; } : never : never) | undefined;
|
|
57
|
+
} : {
|
|
58
|
+
json: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_1 ? T_1 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_1 extends any ? T_1 : { [K2_1 in keyof T_1]: any; } : never : never);
|
|
59
|
+
}) ? {} : (undefined extends {} | (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? true : false) extends true ? {
|
|
60
|
+
json?: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_2 ? T_2 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_2 extends any ? T_2 : { [K2_2 in keyof T_2]?: any; } : never : never) | undefined;
|
|
61
|
+
} : {
|
|
62
|
+
json: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_3 ? T_3 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_3 extends any ? T_3 : { [K2_3 in keyof T_3]: any; } : never : never);
|
|
131
63
|
};
|
|
64
|
+
output: unknown extends ({
|
|
65
|
+
data: Awaited<TReturn>;
|
|
66
|
+
error: null;
|
|
67
|
+
} extends hono_utils_types.JSONValue ? { [K in keyof {
|
|
68
|
+
data: Awaited<TReturn>;
|
|
69
|
+
error: null;
|
|
70
|
+
} as ({
|
|
71
|
+
data: Awaited<TReturn>;
|
|
72
|
+
error: null;
|
|
73
|
+
}[K] extends infer T_4 ? T_4 extends {
|
|
74
|
+
data: Awaited<TReturn>;
|
|
75
|
+
error: null;
|
|
76
|
+
}[K] ? T_4 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
77
|
+
data: Awaited<TReturn>;
|
|
78
|
+
error: null;
|
|
79
|
+
}[K] extends infer T_5 ? T_5 extends {
|
|
80
|
+
data: Awaited<TReturn>;
|
|
81
|
+
error: null;
|
|
82
|
+
}[K] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
83
|
+
data: Awaited<TReturn>;
|
|
84
|
+
error: null;
|
|
85
|
+
}[K]> | undefined : hono_utils_types.JSONParsed<{
|
|
86
|
+
data: Awaited<TReturn>;
|
|
87
|
+
error: null;
|
|
88
|
+
}[K]>; } : never) ? {} : {
|
|
89
|
+
data: Awaited<TReturn>;
|
|
90
|
+
error: null;
|
|
91
|
+
} extends hono_utils_types.JSONValue ? { [K in keyof {
|
|
92
|
+
data: Awaited<TReturn>;
|
|
93
|
+
error: null;
|
|
94
|
+
} as ({
|
|
95
|
+
data: Awaited<TReturn>;
|
|
96
|
+
error: null;
|
|
97
|
+
}[K] extends infer T_4 ? T_4 extends {
|
|
98
|
+
data: Awaited<TReturn>;
|
|
99
|
+
error: null;
|
|
100
|
+
}[K] ? T_4 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
101
|
+
data: Awaited<TReturn>;
|
|
102
|
+
error: null;
|
|
103
|
+
}[K] extends infer T_5 ? T_5 extends {
|
|
104
|
+
data: Awaited<TReturn>;
|
|
105
|
+
error: null;
|
|
106
|
+
}[K] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
107
|
+
data: Awaited<TReturn>;
|
|
108
|
+
error: null;
|
|
109
|
+
}[K]> | undefined : hono_utils_types.JSONParsed<{
|
|
110
|
+
data: Awaited<TReturn>;
|
|
111
|
+
error: null;
|
|
112
|
+
}[K]>; } : never;
|
|
113
|
+
outputFormat: "json";
|
|
114
|
+
status: 200;
|
|
115
|
+
} | {
|
|
116
|
+
input: unknown extends ((undefined extends {} | (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? true : false) extends true ? {
|
|
117
|
+
json?: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_4 ? T_4 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_4 extends any ? T_4 : { [K2_4 in keyof T_4]?: any; } : never : never) | undefined;
|
|
118
|
+
} : {
|
|
119
|
+
json: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_5 ? T_5 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_5 extends any ? T_5 : { [K2_5 in keyof T_5]: any; } : never : never);
|
|
120
|
+
}) ? {} : (undefined extends {} | (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? true : false) extends true ? {
|
|
121
|
+
json?: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_6 ? T_6 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_6 extends any ? T_6 : { [K2_6 in keyof T_6]?: any; } : never : never) | undefined;
|
|
122
|
+
} : {
|
|
123
|
+
json: {} | ((TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) extends infer T_7 ? T_7 extends (TSchema extends z.ZodType<any, z.ZodTypeDef, any> ? z.input<TSchema> : TSchema extends zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>> ? zod_v4.input<TSchema> : never) ? T_7 extends any ? T_7 : { [K2_7 in keyof T_7]: any; } : never : never);
|
|
124
|
+
};
|
|
125
|
+
output: {
|
|
126
|
+
data: null;
|
|
127
|
+
error: {
|
|
128
|
+
message: string;
|
|
129
|
+
code: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
outputFormat: "json";
|
|
133
|
+
status: 500;
|
|
132
134
|
};
|
|
133
|
-
outputFormat: "json";
|
|
134
|
-
status: 500;
|
|
135
135
|
};
|
|
136
|
-
}
|
|
136
|
+
}, "/">;
|
|
137
137
|
|
|
138
138
|
export { type Bindings, HonoActionError, type HonoEnv, defineHonoAction };
|
package/dist/actions.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/actions.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import * as v from "valibot";
|
|
2
|
+
import { zValidator } from "@hono/zod-validator";
|
|
3
|
+
import { z } from "astro/zod";
|
|
5
4
|
|
|
6
5
|
// src/error.ts
|
|
7
6
|
var HonoActionError = class extends Error {
|
|
@@ -20,31 +19,28 @@ var HonoActionError = class extends Error {
|
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
// src/actions.ts
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const app =
|
|
22
|
+
import { Hono } from "hono/quick";
|
|
23
|
+
function defineHonoAction({ schema, handler }) {
|
|
24
|
+
const app = new Hono();
|
|
26
25
|
const route = app.post(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
400
|
|
44
|
-
);
|
|
45
|
-
}
|
|
26
|
+
"/",
|
|
27
|
+
zValidator("json", schema ?? z.object({}), async (result, c) => {
|
|
28
|
+
if (!result.success) {
|
|
29
|
+
console.error(result.error.issues);
|
|
30
|
+
const firstIssue = result.error.issues[0];
|
|
31
|
+
return c.json(
|
|
32
|
+
{
|
|
33
|
+
data: null,
|
|
34
|
+
error: new HonoActionError({
|
|
35
|
+
message: firstIssue?.message || "Validation error",
|
|
36
|
+
code: "INPUT_VALIDATION_ERROR",
|
|
37
|
+
issue: firstIssue
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
400
|
|
41
|
+
);
|
|
46
42
|
}
|
|
47
|
-
),
|
|
43
|
+
}),
|
|
48
44
|
async (c) => {
|
|
49
45
|
try {
|
|
50
46
|
const json = c.req.valid("json");
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,21 @@ import * as astro from 'astro';
|
|
|
2
2
|
import { z } from 'astro/zod';
|
|
3
3
|
|
|
4
4
|
declare const optionsSchema: z.ZodOptional<z.ZodObject<{
|
|
5
|
+
/**
|
|
6
|
+
* The base path for the API routes
|
|
7
|
+
*
|
|
8
|
+
* @default '/api'
|
|
9
|
+
*/
|
|
5
10
|
basePath: z.ZodOptional<z.ZodString>;
|
|
11
|
+
/**
|
|
12
|
+
* The path to the actions file. If not provided, the integration will automatically discover the actions file by searching for one of the following patterns:
|
|
13
|
+
* - `src/server/actions.ts`
|
|
14
|
+
* - `src/hono/actions.ts`
|
|
15
|
+
* - `src/hono/index.ts`
|
|
16
|
+
* - `src/hono.ts`
|
|
17
|
+
*
|
|
18
|
+
* @default 'src/server/actions.ts'
|
|
19
|
+
*/
|
|
6
20
|
actionsPath: z.ZodOptional<z.ZodString>;
|
|
7
21
|
}, "strip", z.ZodTypeAny, {
|
|
8
22
|
basePath?: string | undefined;
|
|
@@ -18,6 +32,10 @@ type IntegrationOptions = z.infer<typeof optionsSchema>;
|
|
|
18
32
|
* This integration automatically discovers action files in your project,
|
|
19
33
|
* generates type-safe client code, and sets up API routes.
|
|
20
34
|
*
|
|
35
|
+
* Supprted Adapters:
|
|
36
|
+
* - Cloudflare
|
|
37
|
+
* - (more to come)
|
|
38
|
+
*
|
|
21
39
|
* @param options - Configuration options for the integration
|
|
22
40
|
* @param options.basePath - Base path for API routes (default: '/api')
|
|
23
41
|
* @param options.actionsPath - Custom path to actions file (optional, auto-discovered by default)
|
package/dist/index.js
CHANGED
|
@@ -1542,7 +1542,7 @@ var require_picomatch2 = __commonJS({
|
|
|
1542
1542
|
}
|
|
1543
1543
|
});
|
|
1544
1544
|
|
|
1545
|
-
// src/
|
|
1545
|
+
// src/integration.ts
|
|
1546
1546
|
import {
|
|
1547
1547
|
addVirtualImports,
|
|
1548
1548
|
createResolver,
|
|
@@ -2290,15 +2290,15 @@ import { logger } from 'hono/logger'
|
|
|
2290
2290
|
import { prettyJSON } from 'hono/pretty-json'
|
|
2291
2291
|
import type { ExtractSchema, MergeSchemaPath } from 'hono/types'
|
|
2292
2292
|
|
|
2293
|
-
|
|
2293
|
+
async function buildRouter(){
|
|
2294
2294
|
type ActionSchema = ExtractSchema<typeof honoActions[keyof typeof honoActions]>
|
|
2295
2295
|
const { honoActions} = await import('${relativeActionsPath}')
|
|
2296
2296
|
const app = new Hono<HonoEnv, MergeSchemaPath<ActionSchema, '${basePath}'>>().basePath('${basePath}')
|
|
2297
2297
|
|
|
2298
2298
|
app.use('*', cors(), logger(), prettyJSON())
|
|
2299
2299
|
|
|
2300
|
-
for (const action of Object.
|
|
2301
|
-
app.route(
|
|
2300
|
+
for (const [routeName, action] of Object.entries(honoActions)) {
|
|
2301
|
+
app.route(\`/\${routeName}\`, action)
|
|
2302
2302
|
}
|
|
2303
2303
|
|
|
2304
2304
|
return app
|
|
@@ -2337,9 +2337,9 @@ export { handler as ALL }
|
|
|
2337
2337
|
var getHonoClient = (port) => `
|
|
2338
2338
|
// Generated by Hono Actions Integration
|
|
2339
2339
|
import type { HonoRouter } from './router.js'
|
|
2340
|
-
import { hc } from 'hono/client'
|
|
2340
|
+
import { hc, parseResponse } from 'hono/client'
|
|
2341
2341
|
|
|
2342
|
-
|
|
2342
|
+
function getBaseUrl() {
|
|
2343
2343
|
// client side can just use the base path
|
|
2344
2344
|
if (typeof window !== 'undefined') {
|
|
2345
2345
|
return '/'
|
|
@@ -2353,16 +2353,30 @@ export function getBaseUrl() {
|
|
|
2353
2353
|
// server side (production) needs full url
|
|
2354
2354
|
return import.meta.env.SITE ?? ''
|
|
2355
2355
|
}
|
|
2356
|
-
|
|
2356
|
+
export { parseResponse }
|
|
2357
2357
|
export const honoClient = hc<HonoRouter>(getBaseUrl())
|
|
2358
2358
|
`;
|
|
2359
2359
|
|
|
2360
2360
|
// src/lib/utils.ts
|
|
2361
2361
|
var reservedRoutes = ["_astro", "_actions", "_server_islands"];
|
|
2362
2362
|
|
|
2363
|
-
// src/
|
|
2363
|
+
// src/integration.ts
|
|
2364
2364
|
var optionsSchema = z.object({
|
|
2365
|
+
/**
|
|
2366
|
+
* The base path for the API routes
|
|
2367
|
+
*
|
|
2368
|
+
* @default '/api'
|
|
2369
|
+
*/
|
|
2365
2370
|
basePath: z.string().optional(),
|
|
2371
|
+
/**
|
|
2372
|
+
* The path to the actions file. If not provided, the integration will automatically discover the actions file by searching for one of the following patterns:
|
|
2373
|
+
* - `src/server/actions.ts`
|
|
2374
|
+
* - `src/hono/actions.ts`
|
|
2375
|
+
* - `src/hono/index.ts`
|
|
2376
|
+
* - `src/hono.ts`
|
|
2377
|
+
*
|
|
2378
|
+
* @default 'src/server/actions.ts'
|
|
2379
|
+
*/
|
|
2366
2380
|
actionsPath: z.string().optional()
|
|
2367
2381
|
}).optional();
|
|
2368
2382
|
var VIRTUAL_MODULE_ID_CLIENT = "@gnosticdev/hono-actions/client";
|
|
@@ -2373,7 +2387,7 @@ var ACTION_PATTERNS = [
|
|
|
2373
2387
|
"src/hono/index.ts",
|
|
2374
2388
|
"src/hono.ts"
|
|
2375
2389
|
];
|
|
2376
|
-
var
|
|
2390
|
+
var integration_default = defineIntegration({
|
|
2377
2391
|
name: "@gnosticdev/hono-actions",
|
|
2378
2392
|
optionsSchema,
|
|
2379
2393
|
setup: ({ options = {}, name }) => {
|
|
@@ -2383,7 +2397,7 @@ var src_default = defineIntegration({
|
|
|
2383
2397
|
`Base path ${basePath} is reserved by Astro; pick another (e.g. /api2).`
|
|
2384
2398
|
);
|
|
2385
2399
|
}
|
|
2386
|
-
createResolver(import.meta.url);
|
|
2400
|
+
const baseResolver = createResolver(import.meta.url);
|
|
2387
2401
|
return {
|
|
2388
2402
|
name,
|
|
2389
2403
|
hooks: {
|
|
@@ -2397,12 +2411,13 @@ var src_default = defineIntegration({
|
|
|
2397
2411
|
});
|
|
2398
2412
|
const actionsPath = options.actionsPath ?? files[0];
|
|
2399
2413
|
if (!actionsPath) {
|
|
2400
|
-
|
|
2414
|
+
logger.warn(
|
|
2401
2415
|
`No actions found. Create one of:
|
|
2402
2416
|
${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
2403
2417
|
);
|
|
2418
|
+
return;
|
|
2404
2419
|
}
|
|
2405
|
-
const resolvedActionsPath =
|
|
2420
|
+
const resolvedActionsPath = baseResolver.resolve(actionsPath);
|
|
2406
2421
|
params.addWatchFile(resolvedActionsPath);
|
|
2407
2422
|
logger.info(
|
|
2408
2423
|
`Found actions: ${path2.relative(root, resolvedActionsPath)}`
|
|
@@ -2485,6 +2500,9 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
2485
2500
|
};
|
|
2486
2501
|
}
|
|
2487
2502
|
});
|
|
2503
|
+
|
|
2504
|
+
// src/index.ts
|
|
2505
|
+
var src_default = integration_default;
|
|
2488
2506
|
export {
|
|
2489
2507
|
src_default as default
|
|
2490
2508
|
};
|
package/package.json
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@astrojs/cloudflare": "^12.6.7",
|
|
9
|
-
"@hono/
|
|
9
|
+
"@hono/zod-validator": "^0.2.2",
|
|
10
10
|
"astro-integration-kit": "^0.19.0",
|
|
11
11
|
"hono": "^4.9.5",
|
|
12
|
-
"
|
|
12
|
+
"zod": "^3.23.8"
|
|
13
13
|
},
|
|
14
14
|
"description": "Define server actions with built-in validation, error handling, and a pre-built hono client for calling the routes.",
|
|
15
15
|
"devDependencies": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
24
|
},
|
|
25
25
|
"./*": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"types": "./dist/*.d.ts",
|
|
27
|
+
"default": "./dist/*.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
},
|
|
55
55
|
"type": "module",
|
|
56
56
|
"types": "./dist/index.d.ts",
|
|
57
|
-
"version": "1.0
|
|
57
|
+
"version": "1.1.0"
|
|
58
58
|
}
|