@gnosticdev/hono-actions 1.0.19 → 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 -27
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -7
- package/package.json +3 -3
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,32 +19,28 @@ var HonoActionError = class extends Error {
|
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
// src/actions.ts
|
|
23
|
-
import "
|
|
24
|
-
function defineHonoAction({
|
|
25
|
-
const
|
|
26
|
-
const app = factory.createApp();
|
|
22
|
+
import { Hono } from "hono/quick";
|
|
23
|
+
function defineHonoAction({ schema, handler }) {
|
|
24
|
+
const app = new Hono();
|
|
27
25
|
const route = app.post(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
400
|
|
45
|
-
);
|
|
46
|
-
}
|
|
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
|
+
);
|
|
47
42
|
}
|
|
48
|
-
),
|
|
43
|
+
}),
|
|
49
44
|
async (c) => {
|
|
50
45
|
try {
|
|
51
46
|
const json = c.req.valid("json");
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ declare const optionsSchema: z.ZodOptional<z.ZodObject<{
|
|
|
8
8
|
* @default '/api'
|
|
9
9
|
*/
|
|
10
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
|
+
*/
|
|
11
20
|
actionsPath: z.ZodOptional<z.ZodString>;
|
|
12
21
|
}, "strip", z.ZodTypeAny, {
|
|
13
22
|
basePath?: string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -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,7 +2353,7 @@ 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
|
|
|
@@ -2368,7 +2368,6 @@ var optionsSchema = z.object({
|
|
|
2368
2368
|
* @default '/api'
|
|
2369
2369
|
*/
|
|
2370
2370
|
basePath: z.string().optional(),
|
|
2371
|
-
actionsPath: z.string().optional()
|
|
2372
2371
|
/**
|
|
2373
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:
|
|
2374
2373
|
* - `src/server/actions.ts`
|
|
@@ -2378,6 +2377,7 @@ var optionsSchema = z.object({
|
|
|
2378
2377
|
*
|
|
2379
2378
|
* @default 'src/server/actions.ts'
|
|
2380
2379
|
*/
|
|
2380
|
+
actionsPath: z.string().optional()
|
|
2381
2381
|
}).optional();
|
|
2382
2382
|
var VIRTUAL_MODULE_ID_CLIENT = "@gnosticdev/hono-actions/client";
|
|
2383
2383
|
var VIRTUAL_MODULE_ID_ROUTER = "virtual:hono-actions/router";
|
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": {
|
|
@@ -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
|
}
|