@gnosticdev/hono-actions 1.1.2 → 1.2.1
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 +20 -22
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -17
- package/package.json +1 -2
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
|
|
80
|
-
json?:
|
|
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:
|
|
83
|
-
}) ? {} : (undefined extends
|
|
84
|
-
json?:
|
|
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:
|
|
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
|
|
95
|
+
}[K] extends infer T ? T extends {
|
|
98
96
|
data: Awaited<TReturn>;
|
|
99
97
|
error: null;
|
|
100
|
-
}[K] ?
|
|
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
|
|
101
|
+
}[K] extends infer T_1 ? T_1 extends {
|
|
104
102
|
data: Awaited<TReturn>;
|
|
105
103
|
error: null;
|
|
106
|
-
}[K] ?
|
|
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
|
|
119
|
+
}[K] extends infer T ? T extends {
|
|
122
120
|
data: Awaited<TReturn>;
|
|
123
121
|
error: null;
|
|
124
|
-
}[K] ?
|
|
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
|
|
125
|
+
}[K] extends infer T_1 ? T_1 extends {
|
|
128
126
|
data: Awaited<TReturn>;
|
|
129
127
|
error: null;
|
|
130
|
-
}[K] ?
|
|
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
|
|
141
|
-
json?:
|
|
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:
|
|
144
|
-
}) ? {} : (undefined extends
|
|
145
|
-
json?:
|
|
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:
|
|
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.
|
|
28
|
+
type IntegrationOptions = z.output<typeof optionsSchema>;
|
|
29
29
|
/**
|
|
30
30
|
* Astro integration for Hono Actions
|
|
31
31
|
*
|
package/dist/index.js
CHANGED
|
@@ -2315,8 +2315,9 @@ 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
|
+
/// <reference types="./types.d.ts" />
|
|
2320
2321
|
// Generated by Hono Actions Integration
|
|
2321
2322
|
import router from './router.js'
|
|
2322
2323
|
import type { APIContext, APIRoute } from 'astro'
|
|
@@ -2354,7 +2355,7 @@ function getBaseUrl() {
|
|
|
2354
2355
|
// server side (production) needs full url
|
|
2355
2356
|
return import.meta.env.SITE ?? ''
|
|
2356
2357
|
}
|
|
2357
|
-
export { parseResponse }
|
|
2358
|
+
export { parseResponse, hc }
|
|
2358
2359
|
export const honoClient = hc<HonoRouter>(getBaseUrl())
|
|
2359
2360
|
`;
|
|
2360
2361
|
|
|
@@ -2388,6 +2389,10 @@ var ACTION_PATTERNS = [
|
|
|
2388
2389
|
"src/hono/index.ts",
|
|
2389
2390
|
"src/hono.ts"
|
|
2390
2391
|
];
|
|
2392
|
+
var SUPPORTED_ADAPTERS = ["@astrojs/cloudflare"];
|
|
2393
|
+
function isSupportedAdapter(adapter) {
|
|
2394
|
+
return SUPPORTED_ADAPTERS.includes(adapter);
|
|
2395
|
+
}
|
|
2391
2396
|
var integration_default = defineIntegration({
|
|
2392
2397
|
name: "@gnosticdev/hono-actions",
|
|
2393
2398
|
optionsSchema,
|
|
@@ -2438,9 +2443,20 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
2438
2443
|
codeGenDir.pathname,
|
|
2439
2444
|
"api.ts"
|
|
2440
2445
|
);
|
|
2441
|
-
|
|
2446
|
+
const adapter = params.config.adapter?.name;
|
|
2447
|
+
if (!adapter) {
|
|
2442
2448
|
throw new Error("No Astro adapter found");
|
|
2443
|
-
|
|
2449
|
+
}
|
|
2450
|
+
let astroHandlerContent;
|
|
2451
|
+
if (isSupportedAdapter(adapter)) {
|
|
2452
|
+
astroHandlerContent = getAstroHandler(adapter);
|
|
2453
|
+
} else {
|
|
2454
|
+
throw new Error(`Unsupported adapter: ${adapter}`, {
|
|
2455
|
+
cause: `Only ${SUPPORTED_ADAPTERS.join(
|
|
2456
|
+
", "
|
|
2457
|
+
)} are supported for now`
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2444
2460
|
await fs.writeFile(
|
|
2445
2461
|
astroHandlerPathAbs,
|
|
2446
2462
|
astroHandlerContent,
|
|
@@ -2469,27 +2485,48 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
2469
2485
|
`\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
|
|
2470
2486
|
);
|
|
2471
2487
|
},
|
|
2472
|
-
"astro:config:done": async ({
|
|
2488
|
+
"astro:config:done": async ({
|
|
2489
|
+
injectTypes,
|
|
2490
|
+
config,
|
|
2491
|
+
logger
|
|
2492
|
+
}) => {
|
|
2473
2493
|
injectTypes({
|
|
2474
2494
|
filename: "actions.d.ts",
|
|
2475
2495
|
content: `
|
|
2476
|
-
|
|
2496
|
+
// Generated by Hono Actions Integration
|
|
2497
|
+
// keeping separate from the main types.d.ts to avoid clobbering package exports
|
|
2498
|
+
declare module '@gnosticdev/hono-actions/actions' {
|
|
2477
2499
|
interface Bindings extends Env { ASTRO_LOCALS: App.Locals }
|
|
2478
2500
|
interface HonoEnv { Bindings: Bindings }
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2501
|
+
}
|
|
2502
|
+
export {}
|
|
2503
|
+
`
|
|
2482
2504
|
});
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
declare module '@gnosticdev/hono-actions/client' {
|
|
2505
|
+
let clientTypes = `
|
|
2506
|
+
// Generated by Hono Actions Integration
|
|
2507
|
+
// keeping separate from the main types.d.ts to avoid clobbering package exports
|
|
2508
|
+
declare module '@gnosticdev/hono-actions/client' {
|
|
2489
2509
|
export const honoClient: typeof import('./client').honoClient
|
|
2490
2510
|
export const parseResponse: typeof import('./client').parseResponse
|
|
2491
|
-
|
|
2492
|
-
|
|
2511
|
+
}
|
|
2512
|
+
`;
|
|
2513
|
+
if (!config.adapter?.name) {
|
|
2514
|
+
logger.warn("No adapter found...");
|
|
2515
|
+
return;
|
|
2516
|
+
}
|
|
2517
|
+
if (config.adapter.name !== "@astrojs/cloudflare") {
|
|
2518
|
+
logger.warn("Unsupported adapter...");
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
clientTypes += `
|
|
2522
|
+
type Runtime = import('@astrojs/cloudflare').Runtime<Env>
|
|
2523
|
+
declare namespace App {
|
|
2524
|
+
interface Locals extends Runtime {}
|
|
2525
|
+
}
|
|
2526
|
+
`;
|
|
2527
|
+
injectTypes({
|
|
2528
|
+
filename: "types.d.ts",
|
|
2529
|
+
content: clientTypes
|
|
2493
2530
|
});
|
|
2494
2531
|
}
|
|
2495
2532
|
}
|
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
|
|
56
|
+
"version": "1.2.1"
|
|
58
57
|
}
|