@gnosticdev/hono-actions 1.1.2 → 1.2.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 CHANGED
@@ -1,7 +1,5 @@
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 zod_v4 from 'zod/v4';
4
- import * as zod_v4_core from 'zod/v4/core';
5
3
  import { z } from 'astro/zod';
6
4
  import { Hono, Context } from 'hono';
7
5
  import { MergeSchemaPath } from 'hono/types';
@@ -76,14 +74,14 @@ type HonoActionParams<TSchema extends HonoActionSchema, TReturn, TEnv extends Ho
76
74
  declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActionSchema, TReturn>({ schema, handler }: HonoActionParams<TSchema, TReturn, TEnv>): hono_hono_base.HonoBase<TEnv, {
77
75
  "/": {
78
76
  $post: {
79
- 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 ? {
80
- 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;
77
+ input: unknown extends ((undefined extends z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> ? true : false) extends true ? {
78
+ json?: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> | undefined;
81
79
  } : {
82
- 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);
83
- }) ? {} : (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 ? {
84
- 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;
80
+ json: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
81
+ }) ? {} : (undefined extends z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> ? true : false) extends true ? {
82
+ json?: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> | undefined;
85
83
  } : {
86
- 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);
84
+ json: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
87
85
  };
88
86
  output: unknown extends ({
89
87
  data: Awaited<TReturn>;
@@ -94,16 +92,16 @@ declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActi
94
92
  } as ({
95
93
  data: Awaited<TReturn>;
96
94
  error: null;
97
- }[K] extends infer T_4 ? T_4 extends {
95
+ }[K] extends infer T ? T extends {
98
96
  data: Awaited<TReturn>;
99
97
  error: null;
100
- }[K] ? T_4 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
98
+ }[K] ? T extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
101
99
  data: Awaited<TReturn>;
102
100
  error: null;
103
- }[K] extends infer T_5 ? T_5 extends {
101
+ }[K] extends infer T_1 ? T_1 extends {
104
102
  data: Awaited<TReturn>;
105
103
  error: null;
106
- }[K] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
104
+ }[K] ? T_1 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
107
105
  data: Awaited<TReturn>;
108
106
  error: null;
109
107
  }[K]> | undefined : hono_utils_types.JSONParsed<{
@@ -118,16 +116,16 @@ declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActi
118
116
  } as ({
119
117
  data: Awaited<TReturn>;
120
118
  error: null;
121
- }[K] extends infer T_4 ? T_4 extends {
119
+ }[K] extends infer T ? T extends {
122
120
  data: Awaited<TReturn>;
123
121
  error: null;
124
- }[K] ? T_4 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
122
+ }[K] ? T extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
125
123
  data: Awaited<TReturn>;
126
124
  error: null;
127
- }[K] extends infer T_5 ? T_5 extends {
125
+ }[K] extends infer T_1 ? T_1 extends {
128
126
  data: Awaited<TReturn>;
129
127
  error: null;
130
- }[K] ? T_5 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
128
+ }[K] ? T_1 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
131
129
  data: Awaited<TReturn>;
132
130
  error: null;
133
131
  }[K]> | undefined : hono_utils_types.JSONParsed<{
@@ -137,14 +135,14 @@ declare function defineHonoAction<TEnv extends HonoEnv, TSchema extends HonoActi
137
135
  outputFormat: "json";
138
136
  status: 200;
139
137
  } | {
140
- 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 ? {
141
- 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;
138
+ input: unknown extends ((undefined extends z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> ? true : false) extends true ? {
139
+ json?: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> | undefined;
142
140
  } : {
143
- 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);
144
- }) ? {} : (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 ? {
145
- 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;
141
+ json: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
142
+ }) ? {} : (undefined extends z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> ? true : false) extends true ? {
143
+ json?: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>> | undefined;
146
144
  } : {
147
- 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);
145
+ json: z.input<TSchema | z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
148
146
  };
149
147
  output: {
150
148
  data: null;
package/dist/index.d.ts CHANGED
@@ -25,7 +25,7 @@ declare const optionsSchema: z.ZodOptional<z.ZodObject<{
25
25
  basePath?: string | undefined;
26
26
  actionsPath?: string | undefined;
27
27
  }>>;
28
- type IntegrationOptions = z.infer<typeof optionsSchema>;
28
+ type IntegrationOptions = z.output<typeof optionsSchema>;
29
29
  /**
30
30
  * Astro integration for Hono Actions
31
31
  *
package/dist/index.js CHANGED
@@ -2315,7 +2315,7 @@ export default app`;
2315
2315
  }
2316
2316
  var getAstroHandler = (adapter) => {
2317
2317
  switch (adapter) {
2318
- case "cloudflare":
2318
+ case "@astrojs/cloudflare":
2319
2319
  return `
2320
2320
  // Generated by Hono Actions Integration
2321
2321
  import router from './router.js'
@@ -2388,6 +2388,10 @@ var ACTION_PATTERNS = [
2388
2388
  "src/hono/index.ts",
2389
2389
  "src/hono.ts"
2390
2390
  ];
2391
+ var SUPPORTED_ADAPTERS = ["@astrojs/cloudflare"];
2392
+ function isSupportedAdapter(adapter) {
2393
+ return SUPPORTED_ADAPTERS.includes(adapter);
2394
+ }
2391
2395
  var integration_default = defineIntegration({
2392
2396
  name: "@gnosticdev/hono-actions",
2393
2397
  optionsSchema,
@@ -2438,9 +2442,20 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
2438
2442
  codeGenDir.pathname,
2439
2443
  "api.ts"
2440
2444
  );
2441
- if (!params.config.adapter?.name)
2445
+ const adapter = params.config.adapter?.name;
2446
+ if (!adapter) {
2442
2447
  throw new Error("No Astro adapter found");
2443
- const astroHandlerContent = getAstroHandler("cloudflare");
2448
+ }
2449
+ let astroHandlerContent;
2450
+ if (isSupportedAdapter(adapter)) {
2451
+ astroHandlerContent = getAstroHandler(adapter);
2452
+ } else {
2453
+ throw new Error(`Unsupported adapter: ${adapter}`, {
2454
+ cause: `Only ${SUPPORTED_ADAPTERS.join(
2455
+ ", "
2456
+ )} are supported for now`
2457
+ });
2458
+ }
2444
2459
  await fs.writeFile(
2445
2460
  astroHandlerPathAbs,
2446
2461
  astroHandlerContent,
@@ -2469,27 +2484,48 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
2469
2484
  `\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
2470
2485
  );
2471
2486
  },
2472
- "astro:config:done": async ({ injectTypes }) => {
2487
+ "astro:config:done": async ({
2488
+ injectTypes,
2489
+ config,
2490
+ logger
2491
+ }) => {
2473
2492
  injectTypes({
2474
2493
  filename: "actions.d.ts",
2475
2494
  content: `
2476
- declare module '@gnosticdev/hono-actions/actions' {
2495
+ // Generated by Hono Actions Integration
2496
+ // keeping separate from the main types.d.ts to avoid clobbering package exports
2497
+ declare module '@gnosticdev/hono-actions/actions' {
2477
2498
  interface Bindings extends Env { ASTRO_LOCALS: App.Locals }
2478
2499
  interface HonoEnv { Bindings: Bindings }
2479
- }
2480
- export {}
2481
- `
2500
+ }
2501
+ export {}
2502
+ `
2482
2503
  });
2483
- injectTypes({
2484
- filename: "types.d.ts",
2485
- content: `
2486
- // Generated by Hono Actions Integration
2487
-
2488
- declare module '@gnosticdev/hono-actions/client' {
2504
+ let clientTypes = `
2505
+ // Generated by Hono Actions Integration
2506
+ // keeping separate from the main types.d.ts to avoid clobbering package exports
2507
+ declare module '@gnosticdev/hono-actions/client' {
2489
2508
  export const honoClient: typeof import('./client').honoClient
2490
2509
  export const parseResponse: typeof import('./client').parseResponse
2491
- }
2492
- `
2510
+ }
2511
+ `;
2512
+ if (!config.adapter?.name) {
2513
+ logger.warn("No adapter found...");
2514
+ return;
2515
+ }
2516
+ if (config.adapter.name !== "@astrojs/cloudflare") {
2517
+ logger.warn("Unsupported adapter...");
2518
+ return;
2519
+ }
2520
+ clientTypes += `
2521
+ type Runtime = import('@astrojs/cloudflare').Runtime<Env>
2522
+ declare namespace App {
2523
+ interface Locals extends Runtime {}
2524
+ }
2525
+ `;
2526
+ injectTypes({
2527
+ filename: "types.d.ts",
2528
+ content: clientTypes
2493
2529
  });
2494
2530
  }
2495
2531
  }
package/package.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "url": "https://github.com/gnosticdev"
6
6
  },
7
7
  "dependencies": {
8
- "@astrojs/cloudflare": "^12.6.7",
9
8
  "@hono/zod-validator": "^0.2.2",
10
9
  "astro-integration-kit": "^0.19.0",
11
10
  "hono": "^4.9.5",
@@ -54,5 +53,5 @@
54
53
  },
55
54
  "type": "module",
56
55
  "types": "./dist/index.d.ts",
57
- "version": "1.1.2"
56
+ "version": "1.2.0"
58
57
  }