@geekmidas/cli 0.6.2 → 0.8.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/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/index.cjs +2583 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2578 -29
- package/dist/index.mjs.map +1 -1
- package/dist/openapi--vOy9mo4.mjs +978 -0
- package/dist/openapi--vOy9mo4.mjs.map +1 -0
- package/dist/openapi-CHhTPief.cjs +1014 -0
- package/dist/openapi-CHhTPief.cjs.map +1 -0
- package/dist/{openapi-react-query-_-B3s8v_.mjs → openapi-react-query-CcciaVu5.mjs} +1 -1
- package/dist/{openapi-react-query-_-B3s8v_.mjs.map → openapi-react-query-CcciaVu5.mjs.map} +1 -1
- package/dist/{openapi-react-query-Cp-w8_05.cjs → openapi-react-query-o5iMi8tz.cjs} +1 -1
- package/dist/{openapi-react-query-Cp-w8_05.cjs.map → openapi-react-query-o5iMi8tz.cjs.map} +1 -1
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +1 -4
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +1 -4
- package/dist/{types-KmjzMgu8.d.cts → types-DXgiA1sF.d.mts} +58 -53
- package/dist/{types-Bi7VzDUZ.d.mts → types-b-vwGpqc.d.cts} +58 -53
- package/package.json +6 -6
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +204 -0
- package/src/__tests__/normalizeHooksConfig.spec.ts +63 -0
- package/src/build/index.ts +8 -1
- package/src/build/types.ts +19 -0
- package/src/dev/index.ts +153 -37
- package/src/generators/EndpointGenerator.ts +72 -5
- package/src/generators/__tests__/EndpointGenerator.spec.ts +1 -1
- package/src/init/generators/config.ts +6 -1
- package/src/init/generators/package.ts +5 -1
- package/src/init/index.ts +9 -1
- package/src/init/templates/api.ts +31 -0
- package/src/init/templates/index.ts +1 -0
- package/src/init/templates/minimal.ts +83 -0
- package/src/types.ts +57 -0
- package/tsdown.config.ts +6 -0
- package/dist/CronGenerator-CCRYptuT.mjs +0 -55
- package/dist/CronGenerator-CCRYptuT.mjs.map +0 -1
- package/dist/CronGenerator-D4TWXQbh.cjs +0 -61
- package/dist/CronGenerator-D4TWXQbh.cjs.map +0 -1
- package/dist/CronGenerator-DWS3CCZt.d.cts +0 -14
- package/dist/CronGenerator-DZjdkEjI.d.mts +0 -14
- package/dist/EndpointGenerator-DGivkPLT.mjs +0 -335
- package/dist/EndpointGenerator-DGivkPLT.mjs.map +0 -1
- package/dist/EndpointGenerator-Dh7kMtuL.d.mts +0 -19
- package/dist/EndpointGenerator-npWEDoK2.cjs +0 -341
- package/dist/EndpointGenerator-npWEDoK2.cjs.map +0 -1
- package/dist/EndpointGenerator-zBsie_7s.d.cts +0 -19
- package/dist/FunctionGenerator-BmDHo27U.d.mts +0 -14
- package/dist/FunctionGenerator-CVk0h8tO.mjs +0 -54
- package/dist/FunctionGenerator-CVk0h8tO.mjs.map +0 -1
- package/dist/FunctionGenerator-DXjXBxUd.d.cts +0 -14
- package/dist/FunctionGenerator-DYTnyr4c.cjs +0 -60
- package/dist/FunctionGenerator-DYTnyr4c.cjs.map +0 -1
- package/dist/Generator-BGY-2dgI.d.cts +0 -27
- package/dist/Generator-CDt4pB3W.mjs +0 -41
- package/dist/Generator-CDt4pB3W.mjs.map +0 -1
- package/dist/Generator-CLVplqm2.cjs +0 -47
- package/dist/Generator-CLVplqm2.cjs.map +0 -1
- package/dist/Generator-yi9DH5TN.d.mts +0 -27
- package/dist/OpenApiTsGenerator-BVS4pOH7.mjs +0 -495
- package/dist/OpenApiTsGenerator-BVS4pOH7.mjs.map +0 -1
- package/dist/OpenApiTsGenerator-gPIIyppX.cjs +0 -501
- package/dist/OpenApiTsGenerator-gPIIyppX.cjs.map +0 -1
- package/dist/SubscriberGenerator-Bb-z3Kvx.d.cts +0 -15
- package/dist/SubscriberGenerator-CwsXqCpS.d.mts +0 -15
- package/dist/SubscriberGenerator-DABaJXML.mjs +0 -200
- package/dist/SubscriberGenerator-DABaJXML.mjs.map +0 -1
- package/dist/SubscriberGenerator-D_zpNGFr.cjs +0 -206
- package/dist/SubscriberGenerator-D_zpNGFr.cjs.map +0 -1
- package/dist/api-Bp5TIl1R.mjs +0 -167
- package/dist/api-Bp5TIl1R.mjs.map +0 -1
- package/dist/api-D4W9-tdZ.cjs +0 -173
- package/dist/api-D4W9-tdZ.cjs.map +0 -1
- package/dist/build/index.cjs +0 -15
- package/dist/build/index.d.cts +0 -7
- package/dist/build/index.d.mts +0 -7
- package/dist/build/index.mjs +0 -15
- package/dist/build/manifests.cjs +0 -4
- package/dist/build/manifests.d.cts +0 -13
- package/dist/build/manifests.d.mts +0 -13
- package/dist/build/manifests.mjs +0 -3
- package/dist/build/providerResolver.cjs +0 -5
- package/dist/build/providerResolver.d.cts +0 -23
- package/dist/build/providerResolver.d.mts +0 -23
- package/dist/build/providerResolver.mjs +0 -3
- package/dist/build/types.cjs +0 -0
- package/dist/build/types.d.cts +0 -3
- package/dist/build/types.d.mts +0 -3
- package/dist/build/types.mjs +0 -0
- package/dist/build-Cu6Mi0Lf.mjs +0 -87
- package/dist/build-Cu6Mi0Lf.mjs.map +0 -1
- package/dist/build-wmt8ZcmA.cjs +0 -93
- package/dist/build-wmt8ZcmA.cjs.map +0 -1
- package/dist/config-BP1IZynR.cjs +0 -168
- package/dist/config-BP1IZynR.cjs.map +0 -1
- package/dist/config-CIzRhm_D.d.mts +0 -11
- package/dist/config-CvehIYsb.d.cts +0 -11
- package/dist/config-UCK12Lrr.mjs +0 -162
- package/dist/config-UCK12Lrr.mjs.map +0 -1
- package/dist/dev/index.cjs +0 -17
- package/dist/dev/index.d.cts +0 -36
- package/dist/dev/index.d.mts +0 -36
- package/dist/dev/index.mjs +0 -13
- package/dist/dev-BBPWSllq.mjs +0 -348
- package/dist/dev-BBPWSllq.mjs.map +0 -1
- package/dist/dev-C2lCgE53.cjs +0 -378
- package/dist/dev-C2lCgE53.cjs.map +0 -1
- package/dist/docker-2-ipZDOJ.cjs +0 -119
- package/dist/docker-2-ipZDOJ.cjs.map +0 -1
- package/dist/docker-31GNwU3F.mjs +0 -113
- package/dist/docker-31GNwU3F.mjs.map +0 -1
- package/dist/env-CQ3hXAAW.d.mts +0 -11
- package/dist/env-CS0jvg7k.cjs +0 -144
- package/dist/env-CS0jvg7k.cjs.map +0 -1
- package/dist/env-D4YFgMqo.d.cts +0 -11
- package/dist/env-DEeVOvVu.mjs +0 -138
- package/dist/env-DEeVOvVu.mjs.map +0 -1
- package/dist/generators/CronGenerator.cjs +0 -4
- package/dist/generators/CronGenerator.d.cts +0 -5
- package/dist/generators/CronGenerator.d.mts +0 -5
- package/dist/generators/CronGenerator.mjs +0 -4
- package/dist/generators/EndpointGenerator.cjs +0 -4
- package/dist/generators/EndpointGenerator.d.cts +0 -5
- package/dist/generators/EndpointGenerator.d.mts +0 -5
- package/dist/generators/EndpointGenerator.mjs +0 -4
- package/dist/generators/FunctionGenerator.cjs +0 -4
- package/dist/generators/FunctionGenerator.d.cts +0 -5
- package/dist/generators/FunctionGenerator.d.mts +0 -5
- package/dist/generators/FunctionGenerator.mjs +0 -4
- package/dist/generators/Generator.cjs +0 -3
- package/dist/generators/Generator.d.cts +0 -4
- package/dist/generators/Generator.d.mts +0 -4
- package/dist/generators/Generator.mjs +0 -3
- package/dist/generators/OpenApiTsGenerator.cjs +0 -3
- package/dist/generators/OpenApiTsGenerator.d.cts +0 -44
- package/dist/generators/OpenApiTsGenerator.d.mts +0 -44
- package/dist/generators/OpenApiTsGenerator.mjs +0 -3
- package/dist/generators/SubscriberGenerator.cjs +0 -4
- package/dist/generators/SubscriberGenerator.d.cts +0 -5
- package/dist/generators/SubscriberGenerator.d.mts +0 -5
- package/dist/generators/SubscriberGenerator.mjs +0 -4
- package/dist/generators/index.cjs +0 -12
- package/dist/generators/index.d.cts +0 -8
- package/dist/generators/index.d.mts +0 -8
- package/dist/generators/index.mjs +0 -8
- package/dist/generators-3IemvCLk.cjs +0 -0
- package/dist/generators-FNpdfN6J.mjs +0 -0
- package/dist/index-DG6xNQMH.d.cts +0 -81
- package/dist/index-DZgrOOOW.d.mts +0 -81
- package/dist/init/generators/config.cjs +0 -3
- package/dist/init/generators/config.d.cts +0 -3
- package/dist/init/generators/config.d.mts +0 -3
- package/dist/init/generators/config.mjs +0 -3
- package/dist/init/generators/docker.cjs +0 -3
- package/dist/init/generators/docker.d.cts +0 -11
- package/dist/init/generators/docker.d.mts +0 -11
- package/dist/init/generators/docker.mjs +0 -3
- package/dist/init/generators/env.cjs +0 -3
- package/dist/init/generators/env.d.cts +0 -3
- package/dist/init/generators/env.d.mts +0 -3
- package/dist/init/generators/env.mjs +0 -3
- package/dist/init/generators/index.cjs +0 -14
- package/dist/init/generators/index.d.cts +0 -6
- package/dist/init/generators/index.d.mts +0 -6
- package/dist/init/generators/index.mjs +0 -11
- package/dist/init/generators/models.cjs +0 -3
- package/dist/init/generators/models.d.cts +0 -11
- package/dist/init/generators/models.d.mts +0 -11
- package/dist/init/generators/models.mjs +0 -3
- package/dist/init/generators/monorepo.cjs +0 -3
- package/dist/init/generators/monorepo.d.cts +0 -11
- package/dist/init/generators/monorepo.d.mts +0 -11
- package/dist/init/generators/monorepo.mjs +0 -3
- package/dist/init/generators/package.cjs +0 -8
- package/dist/init/generators/package.d.cts +0 -3
- package/dist/init/generators/package.d.mts +0 -3
- package/dist/init/generators/package.mjs +0 -8
- package/dist/init/generators/source.cjs +0 -3
- package/dist/init/generators/source.d.cts +0 -3
- package/dist/init/generators/source.d.mts +0 -3
- package/dist/init/generators/source.mjs +0 -3
- package/dist/init/index.cjs +0 -16
- package/dist/init/index.d.cts +0 -17
- package/dist/init/index.d.mts +0 -17
- package/dist/init/index.mjs +0 -16
- package/dist/init/templates/api.cjs +0 -3
- package/dist/init/templates/api.d.cts +0 -7
- package/dist/init/templates/api.d.mts +0 -7
- package/dist/init/templates/api.mjs +0 -3
- package/dist/init/templates/index.cjs +0 -12
- package/dist/init/templates/index.d.cts +0 -2
- package/dist/init/templates/index.d.mts +0 -2
- package/dist/init/templates/index.mjs +0 -7
- package/dist/init/templates/minimal.cjs +0 -3
- package/dist/init/templates/minimal.d.cts +0 -7
- package/dist/init/templates/minimal.d.mts +0 -7
- package/dist/init/templates/minimal.mjs +0 -3
- package/dist/init/templates/serverless.cjs +0 -3
- package/dist/init/templates/serverless.d.cts +0 -7
- package/dist/init/templates/serverless.d.mts +0 -7
- package/dist/init/templates/serverless.mjs +0 -3
- package/dist/init/templates/worker.cjs +0 -3
- package/dist/init/templates/worker.d.cts +0 -7
- package/dist/init/templates/worker.d.mts +0 -7
- package/dist/init/templates/worker.mjs +0 -3
- package/dist/init/utils.cjs +0 -7
- package/dist/init/utils.d.cts +0 -25
- package/dist/init/utils.d.mts +0 -25
- package/dist/init/utils.mjs +0 -3
- package/dist/init-BMA7xi8r.mjs +0 -161
- package/dist/init-BMA7xi8r.mjs.map +0 -1
- package/dist/init-D-7WEk-b.cjs +0 -167
- package/dist/init-D-7WEk-b.cjs.map +0 -1
- package/dist/manifests-BNKG6AXf.mjs +0 -68
- package/dist/manifests-BNKG6AXf.mjs.map +0 -1
- package/dist/manifests-D13Ej8AE.cjs +0 -80
- package/dist/manifests-D13Ej8AE.cjs.map +0 -1
- package/dist/minimal-BkyASH_C.mjs +0 -93
- package/dist/minimal-BkyASH_C.mjs.map +0 -1
- package/dist/minimal-CSFggzdH.cjs +0 -99
- package/dist/minimal-CSFggzdH.cjs.map +0 -1
- package/dist/models-BWlDfviw.mjs +0 -115
- package/dist/models-BWlDfviw.mjs.map +0 -1
- package/dist/models-BapGSoHC.cjs +0 -121
- package/dist/models-BapGSoHC.cjs.map +0 -1
- package/dist/monorepo-BBOWhkcd.mjs +0 -184
- package/dist/monorepo-BBOWhkcd.mjs.map +0 -1
- package/dist/monorepo-CFtxHeDh.cjs +0 -190
- package/dist/monorepo-CFtxHeDh.cjs.map +0 -1
- package/dist/openapi-DA9RkPJl.mjs +0 -74
- package/dist/openapi-DA9RkPJl.mjs.map +0 -1
- package/dist/openapi-DZH6RQHk.cjs +0 -98
- package/dist/openapi-DZH6RQHk.cjs.map +0 -1
- package/dist/package-6h-7QfJZ.d.cts +0 -11
- package/dist/package-BCe_KvGv.d.mts +0 -11
- package/dist/package-C3If80n1.mjs +0 -57
- package/dist/package-C3If80n1.mjs.map +0 -1
- package/dist/package-Dk8IMBOB.cjs +0 -62
- package/dist/package-Dk8IMBOB.cjs.map +0 -1
- package/dist/providerResolver-DEVKngbC.mjs +0 -96
- package/dist/providerResolver-DEVKngbC.mjs.map +0 -1
- package/dist/providerResolver-DOTbN9jo.cjs +0 -114
- package/dist/providerResolver-DOTbN9jo.cjs.map +0 -1
- package/dist/serverless-AGOS-l3G.cjs +0 -119
- package/dist/serverless-AGOS-l3G.cjs.map +0 -1
- package/dist/serverless-D5HjJByU.mjs +0 -113
- package/dist/serverless-D5HjJByU.mjs.map +0 -1
- package/dist/source-C1cyfHcF.cjs +0 -17
- package/dist/source-C1cyfHcF.cjs.map +0 -1
- package/dist/source-C3LiNUV9.d.mts +0 -11
- package/dist/source-CkQHBpwu.mjs +0 -11
- package/dist/source-CkQHBpwu.mjs.map +0 -1
- package/dist/source-Dtcjbokc.d.cts +0 -11
- package/dist/templates-C0EMmhwb.mjs +0 -88
- package/dist/templates-C0EMmhwb.mjs.map +0 -1
- package/dist/templates-CbgQ9dw0.cjs +0 -123
- package/dist/templates-CbgQ9dw0.cjs.map +0 -1
- package/dist/types-D2xYkOal.d.mts +0 -51
- package/dist/types-DA-r8HWZ.d.cts +0 -51
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +0 -2
- package/dist/types.d.mts +0 -2
- package/dist/types.mjs +0 -0
- package/dist/utils-CKEzCxc1.mjs +0 -69
- package/dist/utils-CKEzCxc1.mjs.map +0 -1
- package/dist/utils-DSdN2MTt.cjs +0 -99
- package/dist/utils-DSdN2MTt.cjs.map +0 -1
- package/dist/worker-CGhlqNH-.cjs +0 -156
- package/dist/worker-CGhlqNH-.cjs.map +0 -1
- package/dist/worker-CiP420As.mjs +0 -150
- package/dist/worker-CiP420As.mjs.map +0 -1
package/src/types.ts
CHANGED
|
@@ -44,6 +44,15 @@ export interface TelescopeConfig {
|
|
|
44
44
|
websocket?: boolean;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export interface StudioConfig {
|
|
48
|
+
/** Enable/disable studio (default: true in development) */
|
|
49
|
+
enabled?: boolean;
|
|
50
|
+
/** Path prefix for studio UI (default: /__studio) */
|
|
51
|
+
path?: string;
|
|
52
|
+
/** Schema to introspect (default: 'public') */
|
|
53
|
+
schema?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
export interface OpenApiConfig {
|
|
48
57
|
/** Enable OpenAPI generation (default: true) */
|
|
49
58
|
enabled?: boolean;
|
|
@@ -55,6 +64,34 @@ export interface OpenApiConfig {
|
|
|
55
64
|
description?: string;
|
|
56
65
|
}
|
|
57
66
|
|
|
67
|
+
export interface HooksConfig {
|
|
68
|
+
/**
|
|
69
|
+
* Path to a module exporting server lifecycle hooks.
|
|
70
|
+
* The module should export `beforeSetup` and/or `afterSetup` functions.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // src/config/hooks.ts
|
|
75
|
+
* import type { Hono } from 'hono';
|
|
76
|
+
* import type { Logger } from '@geekmidas/logger';
|
|
77
|
+
* import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
78
|
+
*
|
|
79
|
+
* // Called BEFORE gkm endpoints are registered
|
|
80
|
+
* export function beforeSetup(app: Hono, ctx: { envParser: EnvironmentParser; logger: Logger }) {
|
|
81
|
+
* app.use('*', cors());
|
|
82
|
+
* app.get('/custom/health', (c) => c.json({ status: 'ok' }));
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // Called AFTER gkm endpoints are registered
|
|
86
|
+
* export function afterSetup(app: Hono, ctx: { envParser: EnvironmentParser; logger: Logger }) {
|
|
87
|
+
* app.notFound((c) => c.json({ error: 'Not found' }, 404));
|
|
88
|
+
* app.onError((err, c) => c.json({ error: err.message }, 500));
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
server?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
58
95
|
export interface ProvidersConfig {
|
|
59
96
|
aws?: {
|
|
60
97
|
apiGateway?: {
|
|
@@ -77,6 +114,16 @@ export interface GkmConfig {
|
|
|
77
114
|
envParser: string;
|
|
78
115
|
logger: string;
|
|
79
116
|
providers?: ProvidersConfig;
|
|
117
|
+
/**
|
|
118
|
+
* Server lifecycle hooks for customizing the Hono app.
|
|
119
|
+
* Allows adding custom routes, middleware, error handlers, etc.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* hooks: {
|
|
123
|
+
* server: './src/config/hooks'
|
|
124
|
+
* }
|
|
125
|
+
*/
|
|
126
|
+
hooks?: HooksConfig;
|
|
80
127
|
/**
|
|
81
128
|
* Telescope configuration for debugging/monitoring.
|
|
82
129
|
* Can be:
|
|
@@ -85,6 +132,16 @@ export interface GkmConfig {
|
|
|
85
132
|
* - A TelescopeConfig object for inline configuration
|
|
86
133
|
*/
|
|
87
134
|
telescope?: string | boolean | TelescopeConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Studio configuration for database browsing.
|
|
137
|
+
* Can be:
|
|
138
|
+
* - A string path to a module that exports a Studio instance (recommended)
|
|
139
|
+
* - A boolean to enable/disable with defaults
|
|
140
|
+
* - A StudioConfig object for inline configuration
|
|
141
|
+
*
|
|
142
|
+
* Requires a database connection configured via services.
|
|
143
|
+
*/
|
|
144
|
+
studio?: string | boolean | StudioConfig;
|
|
88
145
|
/**
|
|
89
146
|
* OpenAPI generation configuration.
|
|
90
147
|
* Can be:
|
package/tsdown.config.ts
CHANGED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ConstructGenerator } from "./Generator-CDt4pB3W.mjs";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, join, relative } from "node:path";
|
|
4
|
-
import { Cron } from "@geekmidas/constructs/crons";
|
|
5
|
-
|
|
6
|
-
//#region src/generators/CronGenerator.ts
|
|
7
|
-
var CronGenerator = class extends ConstructGenerator {
|
|
8
|
-
async build(context, constructs, outputDir, options) {
|
|
9
|
-
const provider = options?.provider || "aws-lambda";
|
|
10
|
-
const logger = console;
|
|
11
|
-
const cronInfos = [];
|
|
12
|
-
if (constructs.length === 0 || provider !== "aws-lambda") return cronInfos;
|
|
13
|
-
const cronsDir = join(outputDir, "crons");
|
|
14
|
-
await mkdir(cronsDir, { recursive: true });
|
|
15
|
-
for (const { key, construct, path } of constructs) {
|
|
16
|
-
const handlerFile = await this.generateCronHandler(cronsDir, path.relative, key, context);
|
|
17
|
-
cronInfos.push({
|
|
18
|
-
name: key,
|
|
19
|
-
handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
20
|
-
schedule: construct.schedule || "rate(1 hour)",
|
|
21
|
-
timeout: construct.timeout,
|
|
22
|
-
memorySize: construct.memorySize,
|
|
23
|
-
environment: await construct.getEnvironment()
|
|
24
|
-
});
|
|
25
|
-
logger.log(`Generated cron handler: ${key}`);
|
|
26
|
-
}
|
|
27
|
-
return cronInfos;
|
|
28
|
-
}
|
|
29
|
-
isConstruct(value) {
|
|
30
|
-
return Cron.isCron(value);
|
|
31
|
-
}
|
|
32
|
-
async generateCronHandler(outputDir, sourceFile, exportName, context) {
|
|
33
|
-
const handlerFileName = `${exportName}.ts`;
|
|
34
|
-
const handlerPath = join(outputDir, handlerFileName);
|
|
35
|
-
const relativePath = relative(dirname(handlerPath), sourceFile);
|
|
36
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
37
|
-
const relativeEnvParserPath = relative(dirname(handlerPath), context.envParserPath);
|
|
38
|
-
const relativeLoggerPath = relative(dirname(handlerPath), context.loggerPath);
|
|
39
|
-
const content = `import { AWSScheduledFunction } from '@geekmidas/constructs/crons';
|
|
40
|
-
import { ${exportName} } from '${importPath}';
|
|
41
|
-
import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
|
|
42
|
-
import ${context.loggerImportPattern} from '${relativeLoggerPath}';
|
|
43
|
-
|
|
44
|
-
const adapter = new AWSScheduledFunction(envParser, ${exportName});
|
|
45
|
-
|
|
46
|
-
export const handler = adapter.handler;
|
|
47
|
-
`;
|
|
48
|
-
await writeFile(handlerPath, content);
|
|
49
|
-
return handlerPath;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
export { CronGenerator };
|
|
55
|
-
//# sourceMappingURL=CronGenerator-CCRYptuT.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CronGenerator-CCRYptuT.mjs","names":["context: BuildContext","constructs: GeneratedConstruct<\n Cron<any, any, any, any, any, any, any, any>\n >[]","outputDir: string","options?: GeneratorOptions","cronInfos: CronInfo[]","value: any","sourceFile: string","exportName: string"],"sources":["../src/generators/CronGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Cron } from '@geekmidas/constructs/crons';\nimport type { BuildContext } from '../build/types';\nimport type { CronInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class CronGenerator extends ConstructGenerator<\n Cron<any, any, any, any, any, any, any, any>,\n CronInfo[]\n> {\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<\n Cron<any, any, any, any, any, any, any, any>\n >[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<CronInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const cronInfos: CronInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return cronInfos;\n }\n\n // Create crons subdirectory\n const cronsDir = join(outputDir, 'crons');\n await mkdir(cronsDir, { recursive: true });\n\n // Generate cron handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateCronHandler(\n cronsDir,\n path.relative,\n key,\n context,\n );\n\n cronInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n schedule: construct.schedule || 'rate(1 hour)',\n timeout: construct.timeout,\n memorySize: construct.memorySize,\n environment: await construct.getEnvironment(),\n });\n\n logger.log(`Generated cron handler: ${key}`);\n }\n\n return cronInfos;\n }\n\n isConstruct(\n value: any,\n ): value is Cron<any, any, any, any, any, any, any, any> {\n return Cron.isCron(value);\n }\n\n private async generateCronHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSScheduledFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,gBAAb,cAAmC,mBAGjC;CACA,MAAM,MACJA,SACAC,YAGAC,WACAC,SACqB;EACrB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,YAAwB,CAAE;AAEhC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,WAAW,KAAK,WAAW,QAAQ;AACzC,QAAM,MAAM,UAAU,EAAE,WAAW,KAAM,EAAC;AAG1C,OAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;GACjD,MAAM,cAAc,MAAM,KAAK,oBAC7B,UACA,KAAK,UACL,KACA,QACD;AAED,aAAU,KAAK;IACb,MAAM;IACN,SAAS,SAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,WACD;IACD,UAAU,UAAU,YAAY;IAChC,SAAS,UAAU;IACnB,YAAY,UAAU;IACtB,aAAa,MAAM,UAAU,gBAAgB;GAC9C,EAAC;AAEF,UAAO,KAAK,0BAA0B,IAAI,EAAE;EAC7C;AAED,SAAO;CACR;CAED,YACEC,OACuD;AACvD,SAAO,KAAK,OAAO,MAAM;CAC1B;CAED,MAAc,oBACZH,WACAI,YACAC,YACAP,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,KAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,SAAS,QAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,SAC5B,QAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,SACzB,QAAQ,YAAY,EACpB,QAAQ,WACT;EAED,MAAM,WAAW;WACV,WAAW,WAAW,WAAW;SACnC,QAAQ,uBAAuB,SAAS,sBAAsB;SAC9D,QAAQ,oBAAoB,SAAS,mBAAmB;;sDAEX,WAAW;;;;AAK7D,QAAM,UAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_Generator = require('./Generator-CLVplqm2.cjs');
|
|
3
|
-
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
4
|
-
const node_path = require_chunk.__toESM(require("node:path"));
|
|
5
|
-
const __geekmidas_constructs_crons = require_chunk.__toESM(require("@geekmidas/constructs/crons"));
|
|
6
|
-
|
|
7
|
-
//#region src/generators/CronGenerator.ts
|
|
8
|
-
var CronGenerator = class extends require_Generator.ConstructGenerator {
|
|
9
|
-
async build(context, constructs, outputDir, options) {
|
|
10
|
-
const provider = options?.provider || "aws-lambda";
|
|
11
|
-
const logger = console;
|
|
12
|
-
const cronInfos = [];
|
|
13
|
-
if (constructs.length === 0 || provider !== "aws-lambda") return cronInfos;
|
|
14
|
-
const cronsDir = (0, node_path.join)(outputDir, "crons");
|
|
15
|
-
await (0, node_fs_promises.mkdir)(cronsDir, { recursive: true });
|
|
16
|
-
for (const { key, construct, path } of constructs) {
|
|
17
|
-
const handlerFile = await this.generateCronHandler(cronsDir, path.relative, key, context);
|
|
18
|
-
cronInfos.push({
|
|
19
|
-
name: key,
|
|
20
|
-
handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
21
|
-
schedule: construct.schedule || "rate(1 hour)",
|
|
22
|
-
timeout: construct.timeout,
|
|
23
|
-
memorySize: construct.memorySize,
|
|
24
|
-
environment: await construct.getEnvironment()
|
|
25
|
-
});
|
|
26
|
-
logger.log(`Generated cron handler: ${key}`);
|
|
27
|
-
}
|
|
28
|
-
return cronInfos;
|
|
29
|
-
}
|
|
30
|
-
isConstruct(value) {
|
|
31
|
-
return __geekmidas_constructs_crons.Cron.isCron(value);
|
|
32
|
-
}
|
|
33
|
-
async generateCronHandler(outputDir, sourceFile, exportName, context) {
|
|
34
|
-
const handlerFileName = `${exportName}.ts`;
|
|
35
|
-
const handlerPath = (0, node_path.join)(outputDir, handlerFileName);
|
|
36
|
-
const relativePath = (0, node_path.relative)((0, node_path.dirname)(handlerPath), sourceFile);
|
|
37
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
38
|
-
const relativeEnvParserPath = (0, node_path.relative)((0, node_path.dirname)(handlerPath), context.envParserPath);
|
|
39
|
-
const relativeLoggerPath = (0, node_path.relative)((0, node_path.dirname)(handlerPath), context.loggerPath);
|
|
40
|
-
const content = `import { AWSScheduledFunction } from '@geekmidas/constructs/crons';
|
|
41
|
-
import { ${exportName} } from '${importPath}';
|
|
42
|
-
import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
|
|
43
|
-
import ${context.loggerImportPattern} from '${relativeLoggerPath}';
|
|
44
|
-
|
|
45
|
-
const adapter = new AWSScheduledFunction(envParser, ${exportName});
|
|
46
|
-
|
|
47
|
-
export const handler = adapter.handler;
|
|
48
|
-
`;
|
|
49
|
-
await (0, node_fs_promises.writeFile)(handlerPath, content);
|
|
50
|
-
return handlerPath;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
Object.defineProperty(exports, 'CronGenerator', {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () {
|
|
58
|
-
return CronGenerator;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
//# sourceMappingURL=CronGenerator-D4TWXQbh.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CronGenerator-D4TWXQbh.cjs","names":["ConstructGenerator","context: BuildContext","constructs: GeneratedConstruct<\n Cron<any, any, any, any, any, any, any, any>\n >[]","outputDir: string","options?: GeneratorOptions","cronInfos: CronInfo[]","value: any","sourceFile: string","exportName: string"],"sources":["../src/generators/CronGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Cron } from '@geekmidas/constructs/crons';\nimport type { BuildContext } from '../build/types';\nimport type { CronInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class CronGenerator extends ConstructGenerator<\n Cron<any, any, any, any, any, any, any, any>,\n CronInfo[]\n> {\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<\n Cron<any, any, any, any, any, any, any, any>\n >[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<CronInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const cronInfos: CronInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return cronInfos;\n }\n\n // Create crons subdirectory\n const cronsDir = join(outputDir, 'crons');\n await mkdir(cronsDir, { recursive: true });\n\n // Generate cron handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateCronHandler(\n cronsDir,\n path.relative,\n key,\n context,\n );\n\n cronInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n schedule: construct.schedule || 'rate(1 hour)',\n timeout: construct.timeout,\n memorySize: construct.memorySize,\n environment: await construct.getEnvironment(),\n });\n\n logger.log(`Generated cron handler: ${key}`);\n }\n\n return cronInfos;\n }\n\n isConstruct(\n value: any,\n ): value is Cron<any, any, any, any, any, any, any, any> {\n return Cron.isCron(value);\n }\n\n private async generateCronHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSScheduledFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,gBAAb,cAAmCA,qCAGjC;CACA,MAAM,MACJC,SACAC,YAGAC,WACAC,SAC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gu8.cjs";
|
|
2
|
-
import { BuildContext } from "./types-DA-r8HWZ.cjs";
|
|
3
|
-
import { ConstructGenerator, GeneratedConstruct, GeneratorOptions } from "./Generator-BGY-2dgI.cjs";
|
|
4
|
-
import { Cron } from "@geekmidas/constructs/crons";
|
|
5
|
-
|
|
6
|
-
//#region src/generators/CronGenerator.d.ts
|
|
7
|
-
declare class CronGenerator extends ConstructGenerator<Cron<any, any, any, any, any, any, any, any>, CronInfo[]> {
|
|
8
|
-
build(context: BuildContext, constructs: GeneratedConstruct<Cron<any, any, any, any, any, any, any, any>>[], outputDir: string, options?: GeneratorOptions): Promise<CronInfo[]>;
|
|
9
|
-
isConstruct(value: any): value is Cron<any, any, any, any, any, any, any, any>;
|
|
10
|
-
private generateCronHandler;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { CronGenerator };
|
|
14
|
-
//# sourceMappingURL=CronGenerator-DWS3CCZt.d.cts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CronInfo } from "./types-Bi7VzDUZ.mjs";
|
|
2
|
-
import { BuildContext } from "./types-D2xYkOal.mjs";
|
|
3
|
-
import { ConstructGenerator, GeneratedConstruct, GeneratorOptions } from "./Generator-yi9DH5TN.mjs";
|
|
4
|
-
import { Cron } from "@geekmidas/constructs/crons";
|
|
5
|
-
|
|
6
|
-
//#region src/generators/CronGenerator.d.ts
|
|
7
|
-
declare class CronGenerator extends ConstructGenerator<Cron<any, any, any, any, any, any, any, any>, CronInfo[]> {
|
|
8
|
-
build(context: BuildContext, constructs: GeneratedConstruct<Cron<any, any, any, any, any, any, any, any>>[], outputDir: string, options?: GeneratorOptions): Promise<CronInfo[]>;
|
|
9
|
-
isConstruct(value: any): value is Cron<any, any, any, any, any, any, any, any>;
|
|
10
|
-
private generateCronHandler;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { CronGenerator };
|
|
14
|
-
//# sourceMappingURL=CronGenerator-DZjdkEjI.d.mts.map
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import { ConstructGenerator } from "./Generator-CDt4pB3W.mjs";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, join, relative } from "node:path";
|
|
4
|
-
import { Endpoint } from "@geekmidas/constructs/endpoints";
|
|
5
|
-
|
|
6
|
-
//#region src/generators/EndpointGenerator.ts
|
|
7
|
-
var EndpointGenerator = class extends ConstructGenerator {
|
|
8
|
-
isConstruct(value) {
|
|
9
|
-
return Endpoint.isEndpoint(value);
|
|
10
|
-
}
|
|
11
|
-
async build(context, constructs, outputDir, options) {
|
|
12
|
-
const provider = options?.provider || "aws-apigatewayv2";
|
|
13
|
-
const enableOpenApi = options?.enableOpenApi || false;
|
|
14
|
-
const logger = console;
|
|
15
|
-
const routes = [];
|
|
16
|
-
if (constructs.length === 0) return routes;
|
|
17
|
-
if (provider === "server") {
|
|
18
|
-
await this.generateEndpointsFile(outputDir, constructs, context);
|
|
19
|
-
const appFile = await this.generateAppFile(outputDir, context);
|
|
20
|
-
routes.push({
|
|
21
|
-
path: "*",
|
|
22
|
-
method: "ALL",
|
|
23
|
-
handler: relative(process.cwd(), appFile),
|
|
24
|
-
authorizer: "none"
|
|
25
|
-
});
|
|
26
|
-
logger.log(`Generated server with ${constructs.length} endpoints${enableOpenApi ? " (OpenAPI enabled)" : ""}`);
|
|
27
|
-
} else if (provider === "aws-lambda") {
|
|
28
|
-
const routesDir = join(outputDir, "routes");
|
|
29
|
-
await mkdir(routesDir, { recursive: true });
|
|
30
|
-
for (const { key, construct, path } of constructs) {
|
|
31
|
-
const handlerFile = await this.generateHandlerFile(routesDir, path.relative, key, "aws-apigatewayv2", construct, context);
|
|
32
|
-
const routeInfo = {
|
|
33
|
-
path: construct._path,
|
|
34
|
-
method: construct.method,
|
|
35
|
-
handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
36
|
-
timeout: construct.timeout,
|
|
37
|
-
memorySize: construct.memorySize,
|
|
38
|
-
environment: await construct.getEnvironment(),
|
|
39
|
-
authorizer: construct.authorizer?.name ?? "none"
|
|
40
|
-
};
|
|
41
|
-
routes.push(routeInfo);
|
|
42
|
-
logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
|
|
43
|
-
}
|
|
44
|
-
} else for (const { key, construct, path } of constructs) {
|
|
45
|
-
const handlerFile = await this.generateHandlerFile(outputDir, path.relative, key, provider, construct, context);
|
|
46
|
-
const routeInfo = {
|
|
47
|
-
path: construct._path,
|
|
48
|
-
method: construct.method,
|
|
49
|
-
handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
50
|
-
timeout: construct.timeout,
|
|
51
|
-
memorySize: construct.memorySize,
|
|
52
|
-
environment: await construct.getEnvironment(),
|
|
53
|
-
authorizer: construct.authorizer?.name ?? "none"
|
|
54
|
-
};
|
|
55
|
-
routes.push(routeInfo);
|
|
56
|
-
logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
|
|
57
|
-
}
|
|
58
|
-
return routes;
|
|
59
|
-
}
|
|
60
|
-
async generateHandlerFile(outputDir, sourceFile, exportName, provider, _endpoint, context) {
|
|
61
|
-
const handlerFileName = `${exportName}.ts`;
|
|
62
|
-
const handlerPath = join(outputDir, handlerFileName);
|
|
63
|
-
const relativePath = relative(dirname(handlerPath), sourceFile);
|
|
64
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
65
|
-
const relativeEnvParserPath = relative(dirname(handlerPath), context.envParserPath);
|
|
66
|
-
let content;
|
|
67
|
-
switch (provider) {
|
|
68
|
-
case "aws-apigatewayv1":
|
|
69
|
-
content = this.generateAWSApiGatewayV1Handler(importPath, exportName, relativeEnvParserPath, context.envParserImportPattern);
|
|
70
|
-
break;
|
|
71
|
-
case "aws-apigatewayv2":
|
|
72
|
-
content = this.generateAWSApiGatewayV2Handler(importPath, exportName, relativeEnvParserPath, context.envParserImportPattern);
|
|
73
|
-
break;
|
|
74
|
-
case "server":
|
|
75
|
-
content = this.generateServerHandler(importPath, exportName);
|
|
76
|
-
break;
|
|
77
|
-
default: throw new Error(`Unsupported provider: ${provider}`);
|
|
78
|
-
}
|
|
79
|
-
await writeFile(handlerPath, content);
|
|
80
|
-
return handlerPath;
|
|
81
|
-
}
|
|
82
|
-
async generateEndpointsFile(outputDir, endpoints, _context) {
|
|
83
|
-
const endpointsFileName = "endpoints.ts";
|
|
84
|
-
const endpointsPath = join(outputDir, endpointsFileName);
|
|
85
|
-
const importsByFile = /* @__PURE__ */ new Map();
|
|
86
|
-
for (const { path, key } of endpoints) {
|
|
87
|
-
const relativePath = relative(dirname(endpointsPath), path.relative);
|
|
88
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
89
|
-
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
90
|
-
importsByFile.get(importPath).push(key);
|
|
91
|
-
}
|
|
92
|
-
const imports = Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n");
|
|
93
|
-
const allExportNames = endpoints.map(({ key }) => key);
|
|
94
|
-
const content = `import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
95
|
-
import type { Logger } from '@geekmidas/logger';
|
|
96
|
-
import { HonoEndpoint } from '@geekmidas/constructs/hono';
|
|
97
|
-
import { Endpoint } from '@geekmidas/constructs/endpoints';
|
|
98
|
-
import { ServiceDiscovery } from '@geekmidas/services';
|
|
99
|
-
import type { Hono } from 'hono';
|
|
100
|
-
${imports}
|
|
101
|
-
|
|
102
|
-
const endpoints: Endpoint<any, any, any, any, any, any, any, any, any, any, any, any, any, any>[] = [
|
|
103
|
-
${allExportNames.join(",\n ")}
|
|
104
|
-
];
|
|
105
|
-
|
|
106
|
-
export function setupEndpoints(
|
|
107
|
-
app: Hono,
|
|
108
|
-
envParser: EnvironmentParser<any>,
|
|
109
|
-
logger: Logger,
|
|
110
|
-
enableOpenApi: boolean = true,
|
|
111
|
-
): void {
|
|
112
|
-
const serviceDiscovery = ServiceDiscovery.getInstance(
|
|
113
|
-
logger,
|
|
114
|
-
envParser
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
// Configure OpenAPI options based on enableOpenApi flag
|
|
118
|
-
const openApiOptions: any = enableOpenApi ? {
|
|
119
|
-
docsPath: '/docs',
|
|
120
|
-
openApiOptions: {
|
|
121
|
-
title: 'API Documentation',
|
|
122
|
-
version: '1.0.0',
|
|
123
|
-
description: 'Generated API documentation'
|
|
124
|
-
}
|
|
125
|
-
} : { docsPath: false };
|
|
126
|
-
|
|
127
|
-
HonoEndpoint.addRoutes(endpoints, serviceDiscovery, app, openApiOptions);
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
await writeFile(endpointsPath, content);
|
|
131
|
-
return endpointsPath;
|
|
132
|
-
}
|
|
133
|
-
async generateAppFile(outputDir, context) {
|
|
134
|
-
const appFileName = "app.ts";
|
|
135
|
-
const appPath = join(outputDir, appFileName);
|
|
136
|
-
const relativeLoggerPath = relative(dirname(appPath), context.loggerPath);
|
|
137
|
-
const relativeEnvParserPath = relative(dirname(appPath), context.envParserPath);
|
|
138
|
-
const telescopeEnabled = context.telescope?.enabled;
|
|
139
|
-
const telescopeWebSocketEnabled = context.telescope?.websocket;
|
|
140
|
-
const usesExternalTelescope = !!context.telescope?.telescopePath;
|
|
141
|
-
let telescopeImports = "";
|
|
142
|
-
if (telescopeEnabled) if (usesExternalTelescope) {
|
|
143
|
-
const relativeTelescopePath = relative(dirname(appPath), context.telescope.telescopePath);
|
|
144
|
-
telescopeImports = `import ${context.telescope.telescopeImportPattern} from '${relativeTelescopePath}';
|
|
145
|
-
import { createMiddleware, createUI } from '@geekmidas/telescope/hono';`;
|
|
146
|
-
} else telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
|
|
147
|
-
import { createMiddleware, createUI } from '@geekmidas/telescope/hono';`;
|
|
148
|
-
const telescopeWebSocketSetupCode = telescopeWebSocketEnabled ? `
|
|
149
|
-
// Setup WebSocket for real-time telescope updates
|
|
150
|
-
try {
|
|
151
|
-
const { createNodeWebSocket } = await import('@hono/node-ws');
|
|
152
|
-
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app: honoApp });
|
|
153
|
-
// Add WebSocket route directly to main app (sub-app routes don't support WS upgrade)
|
|
154
|
-
honoApp.get('${context.telescope.path}/ws', upgradeWebSocket(() => ({
|
|
155
|
-
onOpen: (_event: Event, ws: any) => {
|
|
156
|
-
telescope.addWsClient(ws);
|
|
157
|
-
},
|
|
158
|
-
onClose: (_event: Event, ws: any) => {
|
|
159
|
-
telescope.removeWsClient(ws);
|
|
160
|
-
},
|
|
161
|
-
onMessage: (event: MessageEvent, ws: any) => {
|
|
162
|
-
try {
|
|
163
|
-
const data = JSON.parse(event.data);
|
|
164
|
-
if (data.type === 'ping') {
|
|
165
|
-
ws.send(JSON.stringify({ type: 'pong' }));
|
|
166
|
-
}
|
|
167
|
-
} catch {
|
|
168
|
-
// Ignore invalid messages
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
})));
|
|
172
|
-
// Store injectWebSocket for server entry to call after serve()
|
|
173
|
-
(honoApp as any).__injectWebSocket = injectWebSocket;
|
|
174
|
-
logger.info('Telescope WebSocket enabled');
|
|
175
|
-
} catch (e) {
|
|
176
|
-
logger.warn({ error: e }, 'WebSocket support not available - install @hono/node-ws for real-time updates');
|
|
177
|
-
}
|
|
178
|
-
` : "";
|
|
179
|
-
let telescopeSetup = "";
|
|
180
|
-
if (telescopeEnabled) if (usesExternalTelescope) telescopeSetup = `
|
|
181
|
-
${telescopeWebSocketSetupCode}
|
|
182
|
-
// Add telescope middleware (before endpoints to capture all requests)
|
|
183
|
-
honoApp.use('*', createMiddleware(telescope));
|
|
184
|
-
|
|
185
|
-
// Mount telescope UI
|
|
186
|
-
const telescopeUI = createUI(telescope);
|
|
187
|
-
honoApp.route('${context.telescope.path}', telescopeUI);
|
|
188
|
-
`;
|
|
189
|
-
else telescopeSetup = `
|
|
190
|
-
// Setup Telescope for debugging/monitoring
|
|
191
|
-
const telescopeStorage = new InMemoryStorage({ maxEntries: ${context.telescope.maxEntries} });
|
|
192
|
-
const telescope = new Telescope({
|
|
193
|
-
enabled: true,
|
|
194
|
-
path: '${context.telescope.path}',
|
|
195
|
-
ignorePatterns: ${JSON.stringify(context.telescope.ignore)},
|
|
196
|
-
recordBody: ${context.telescope.recordBody},
|
|
197
|
-
storage: telescopeStorage,
|
|
198
|
-
});
|
|
199
|
-
${telescopeWebSocketSetupCode}
|
|
200
|
-
// Add telescope middleware (before endpoints to capture all requests)
|
|
201
|
-
honoApp.use('*', createMiddleware(telescope));
|
|
202
|
-
|
|
203
|
-
// Mount telescope UI
|
|
204
|
-
const telescopeUI = createUI(telescope);
|
|
205
|
-
honoApp.route('${context.telescope.path}', telescopeUI);
|
|
206
|
-
`;
|
|
207
|
-
const content = `/**
|
|
208
|
-
* Generated server application
|
|
209
|
-
*
|
|
210
|
-
* ⚠️ WARNING: This is for LOCAL DEVELOPMENT ONLY
|
|
211
|
-
* The subscriber polling mechanism is not production-ready.
|
|
212
|
-
* For production, use AWS Lambda with SQS/SNS event sources.
|
|
213
|
-
*/
|
|
214
|
-
import { Hono } from 'hono';
|
|
215
|
-
import type { Hono as HonoType } from 'hono';
|
|
216
|
-
import { setupEndpoints } from './endpoints.js';
|
|
217
|
-
import { setupSubscribers } from './subscribers.js';
|
|
218
|
-
import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
|
|
219
|
-
import ${context.loggerImportPattern} from '${relativeLoggerPath}';
|
|
220
|
-
${telescopeImports}
|
|
221
|
-
|
|
222
|
-
export interface ServerApp {
|
|
223
|
-
app: HonoType;
|
|
224
|
-
start: (options?: {
|
|
225
|
-
port?: number;
|
|
226
|
-
serve: (app: HonoType, port: number) => void | Promise<void>;
|
|
227
|
-
}) => Promise<void>;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Create and configure the Hono application
|
|
232
|
-
*
|
|
233
|
-
* @param app - Optional Hono app instance to configure (creates new one if not provided)
|
|
234
|
-
* @param enableOpenApi - Enable OpenAPI documentation (default: true)
|
|
235
|
-
* @returns Server app with configured Hono app and start function
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* // With Bun
|
|
239
|
-
* import { createApp } from './.gkm/server/app.js';
|
|
240
|
-
*
|
|
241
|
-
* const { app, start } = await createApp();
|
|
242
|
-
*
|
|
243
|
-
* await start({
|
|
244
|
-
* port: 3000,
|
|
245
|
-
* serve: (app, port) => {
|
|
246
|
-
* Bun.serve({ port, fetch: app.fetch });
|
|
247
|
-
* }
|
|
248
|
-
* });
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* // With Node.js (using @hono/node-server)
|
|
252
|
-
* import { serve } from '@hono/node-server';
|
|
253
|
-
* import { createApp } from './.gkm/server/app.js';
|
|
254
|
-
*
|
|
255
|
-
* const { app, start } = await createApp();
|
|
256
|
-
*
|
|
257
|
-
* await start({
|
|
258
|
-
* port: 3000,
|
|
259
|
-
* serve: (app, port) => {
|
|
260
|
-
* serve({ fetch: app.fetch, port });
|
|
261
|
-
* }
|
|
262
|
-
* });
|
|
263
|
-
*/
|
|
264
|
-
export async function createApp(app?: HonoType, enableOpenApi: boolean = true): Promise<ServerApp> {
|
|
265
|
-
const honoApp = app || new Hono();
|
|
266
|
-
${telescopeSetup}
|
|
267
|
-
// Setup HTTP endpoints
|
|
268
|
-
setupEndpoints(honoApp, envParser, logger, enableOpenApi);
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
app: honoApp,
|
|
272
|
-
async start(options) {
|
|
273
|
-
if (!options?.serve) {
|
|
274
|
-
throw new Error(
|
|
275
|
-
'serve function is required. Pass a serve function for your runtime:\\n' +
|
|
276
|
-
' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\n' +
|
|
277
|
-
' - Node: (app, port) => serve({ fetch: app.fetch, port })'
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const port = options.port ?? 3000;
|
|
282
|
-
|
|
283
|
-
// Start subscribers in background (non-blocking, local development only)
|
|
284
|
-
await setupSubscribers(envParser, logger).catch((error) => {
|
|
285
|
-
logger.error({ error }, 'Failed to start subscribers');
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
logger.info({ port }, 'Starting server');
|
|
289
|
-
|
|
290
|
-
// Start HTTP server using provided serve function
|
|
291
|
-
await options.serve(honoApp, port);
|
|
292
|
-
|
|
293
|
-
logger.info({ port }, 'Server started');
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Default export for convenience
|
|
299
|
-
export default createApp;
|
|
300
|
-
`;
|
|
301
|
-
await writeFile(appPath, content);
|
|
302
|
-
return appPath;
|
|
303
|
-
}
|
|
304
|
-
generateAWSApiGatewayV1Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
305
|
-
return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/constructs/aws';
|
|
306
|
-
import { ${exportName} } from '${importPath}';
|
|
307
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
308
|
-
|
|
309
|
-
const adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});
|
|
310
|
-
|
|
311
|
-
export const handler = adapter.handler;
|
|
312
|
-
`;
|
|
313
|
-
}
|
|
314
|
-
generateAWSApiGatewayV2Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
315
|
-
return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/constructs/aws';
|
|
316
|
-
import { ${exportName} } from '${importPath}';
|
|
317
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
318
|
-
|
|
319
|
-
const adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});
|
|
320
|
-
|
|
321
|
-
export const handler = adapter.handler;
|
|
322
|
-
`;
|
|
323
|
-
}
|
|
324
|
-
generateServerHandler(importPath, exportName) {
|
|
325
|
-
return `import { ${exportName} } from '${importPath}';
|
|
326
|
-
|
|
327
|
-
// Server handler - implement based on your server framework
|
|
328
|
-
export const handler = ${exportName};
|
|
329
|
-
`;
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
//#endregion
|
|
334
|
-
export { EndpointGenerator };
|
|
335
|
-
//# sourceMappingURL=EndpointGenerator-DGivkPLT.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointGenerator-DGivkPLT.mjs","names":["value: any","context: BuildContext","constructs: GeneratedConstruct<\n Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n >[]","outputDir: string","options?: GeneratorOptions","routes: RouteInfo[]","routeInfo: RouteInfo","sourceFile: string","exportName: string","provider: LegacyProvider","_endpoint: Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >","content: string","endpoints: GeneratedConstruct<\n Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n >[]","_context: BuildContext","importPath: string","envParserPath: string","envParserImportPattern: string"],"sources":["../src/generators/EndpointGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Endpoint } from '@geekmidas/constructs/endpoints';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, RouteInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class EndpointGenerator extends ConstructGenerator<\n Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n RouteInfo[]\n> {\n isConstruct(\n value: any,\n ): value is Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {\n return Endpoint.isEndpoint(value);\n }\n\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<\n Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n >[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<RouteInfo[]> {\n const provider = options?.provider || 'aws-apigatewayv2';\n const enableOpenApi = options?.enableOpenApi || false;\n const logger = console;\n const routes: RouteInfo[] = [];\n\n if (constructs.length === 0) {\n return routes;\n }\n\n if (provider === 'server') {\n // Generate endpoints.ts and app.ts\n await this.generateEndpointsFile(outputDir, constructs, context);\n const appFile = await this.generateAppFile(outputDir, context);\n\n routes.push({\n path: '*',\n method: 'ALL',\n handler: relative(process.cwd(), appFile),\n authorizer: 'none',\n });\n\n logger.log(\n `Generated server with ${constructs.length} endpoints${enableOpenApi ? ' (OpenAPI enabled)' : ''}`,\n );\n } else if (provider === 'aws-lambda') {\n // For aws-lambda, create routes subdirectory\n const routesDir = join(outputDir, 'routes');\n await mkdir(routesDir, { recursive: true });\n\n // Generate individual handlers for API Gateway routes\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n routesDir,\n path.relative,\n key,\n 'aws-apigatewayv2',\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n timeout: construct.timeout,\n memorySize: construct.memorySize,\n environment: await construct.getEnvironment(),\n authorizer: construct.authorizer?.name ?? 'none',\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n } else {\n // Generate individual handler files for AWS API Gateway providers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n outputDir,\n path.relative,\n key,\n provider,\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n timeout: construct.timeout,\n memorySize: construct.memorySize,\n environment: await construct.getEnvironment(),\n authorizer: construct.authorizer?.name ?? 'none',\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n }\n\n return routes;\n }\n\n private async generateHandlerFile(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n provider: LegacyProvider,\n _endpoint: Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n\n let content: string;\n\n switch (provider) {\n case 'aws-apigatewayv1':\n content = this.generateAWSApiGatewayV1Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'aws-apigatewayv2':\n content = this.generateAWSApiGatewayV2Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'server':\n content = this.generateServerHandler(importPath, exportName);\n break;\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n\n private async generateEndpointsFile(\n outputDir: string,\n endpoints: GeneratedConstruct<\n Endpoint<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n >[],\n _context: BuildContext,\n ): Promise<string> {\n const endpointsFileName = 'endpoints.ts';\n const endpointsPath = join(outputDir, endpointsFileName);\n\n // Group imports by file\n const importsByFile = new Map<string, string[]>();\n\n for (const { path, key } of endpoints) {\n const relativePath = relative(dirname(endpointsPath), path.relative);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n if (!importsByFile.has(importPath)) {\n importsByFile.set(importPath, []);\n }\n importsByFile.get(importPath)!.push(key);\n }\n\n // Generate import statements\n const imports = Array.from(importsByFile.entries())\n .map(\n ([importPath, exports]) =>\n `import { ${exports.join(', ')} } from '${importPath}';`,\n )\n .join('\\n');\n\n const allExportNames = endpoints.map(({ key }) => key);\n\n const content = `import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { HonoEndpoint } from '@geekmidas/constructs/hono';\nimport { Endpoint } from '@geekmidas/constructs/endpoints';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport type { Hono } from 'hono';\n${imports}\n\nconst endpoints: Endpoint<any, any, any, any, any, any, any, any, any, any, any, any, any, any>[] = [\n ${allExportNames.join(',\\n ')}\n];\n\nexport function setupEndpoints(\n app: Hono,\n envParser: EnvironmentParser<any>,\n logger: Logger,\n enableOpenApi: boolean = true,\n): void {\n const serviceDiscovery = ServiceDiscovery.getInstance(\n logger,\n envParser\n );\n\n // Configure OpenAPI options based on enableOpenApi flag\n const openApiOptions: any = enableOpenApi ? {\n docsPath: '/docs',\n openApiOptions: {\n title: 'API Documentation',\n version: '1.0.0',\n description: 'Generated API documentation'\n }\n } : { docsPath: false };\n\n HonoEndpoint.addRoutes(endpoints, serviceDiscovery, app, openApiOptions);\n}\n`;\n\n await writeFile(endpointsPath, content);\n\n return endpointsPath;\n }\n\n private async generateAppFile(\n outputDir: string,\n context: BuildContext,\n ): Promise<string> {\n const appFileName = 'app.ts';\n const appPath = join(outputDir, appFileName);\n\n const relativeLoggerPath = relative(dirname(appPath), context.loggerPath);\n\n const relativeEnvParserPath = relative(\n dirname(appPath),\n context.envParserPath,\n );\n\n // Generate telescope imports and setup if enabled\n const telescopeEnabled = context.telescope?.enabled;\n const telescopeWebSocketEnabled = context.telescope?.websocket;\n const usesExternalTelescope = !!context.telescope?.telescopePath;\n\n // Generate imports based on whether telescope is external or inline\n let telescopeImports = '';\n if (telescopeEnabled) {\n if (usesExternalTelescope) {\n const relativeTelescopePath = relative(\n dirname(appPath),\n context.telescope!.telescopePath!,\n );\n telescopeImports = `import ${context.telescope!.telescopeImportPattern} from '${relativeTelescopePath}';\nimport { createMiddleware, createUI } from '@geekmidas/telescope/hono';`;\n } else {\n telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';\nimport { createMiddleware, createUI } from '@geekmidas/telescope/hono';`;\n }\n }\n\n const telescopeWebSocketSetupCode = telescopeWebSocketEnabled\n ? `\n // Setup WebSocket for real-time telescope updates\n try {\n const { createNodeWebSocket } = await import('@hono/node-ws');\n const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app: honoApp });\n // Add WebSocket route directly to main app (sub-app routes don't support WS upgrade)\n honoApp.get('${context.telescope!.path}/ws', upgradeWebSocket(() => ({\n onOpen: (_event: Event, ws: any) => {\n telescope.addWsClient(ws);\n },\n onClose: (_event: Event, ws: any) => {\n telescope.removeWsClient(ws);\n },\n onMessage: (event: MessageEvent, ws: any) => {\n try {\n const data = JSON.parse(event.data);\n if (data.type === 'ping') {\n ws.send(JSON.stringify({ type: 'pong' }));\n }\n } catch {\n // Ignore invalid messages\n }\n },\n })));\n // Store injectWebSocket for server entry to call after serve()\n (honoApp as any).__injectWebSocket = injectWebSocket;\n logger.info('Telescope WebSocket enabled');\n } catch (e) {\n logger.warn({ error: e }, 'WebSocket support not available - install @hono/node-ws for real-time updates');\n }\n`\n : '';\n\n // Generate telescope setup - either use external instance or create inline\n let telescopeSetup = '';\n if (telescopeEnabled) {\n if (usesExternalTelescope) {\n // Use external telescope instance - no need to create one\n telescopeSetup = `\n${telescopeWebSocketSetupCode}\n // Add telescope middleware (before endpoints to capture all requests)\n honoApp.use('*', createMiddleware(telescope));\n\n // Mount telescope UI\n const telescopeUI = createUI(telescope);\n honoApp.route('${context.telescope!.path}', telescopeUI);\n`;\n } else {\n // Create inline telescope instance\n telescopeSetup = `\n // Setup Telescope for debugging/monitoring\n const telescopeStorage = new InMemoryStorage({ maxEntries: ${context.telescope!.maxEntries} });\n const telescope = new Telescope({\n enabled: true,\n path: '${context.telescope!.path}',\n ignorePatterns: ${JSON.stringify(context.telescope!.ignore)},\n recordBody: ${context.telescope!.recordBody},\n storage: telescopeStorage,\n });\n${telescopeWebSocketSetupCode}\n // Add telescope middleware (before endpoints to capture all requests)\n honoApp.use('*', createMiddleware(telescope));\n\n // Mount telescope UI\n const telescopeUI = createUI(telescope);\n honoApp.route('${context.telescope!.path}', telescopeUI);\n`;\n }\n }\n\n const content = `/**\n * Generated server application\n *\n * ⚠️ WARNING: This is for LOCAL DEVELOPMENT ONLY\n * The subscriber polling mechanism is not production-ready.\n * For production, use AWS Lambda with SQS/SNS event sources.\n */\nimport { Hono } from 'hono';\nimport type { Hono as HonoType } from 'hono';\nimport { setupEndpoints } from './endpoints.js';\nimport { setupSubscribers } from './subscribers.js';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n${telescopeImports}\n\nexport interface ServerApp {\n app: HonoType;\n start: (options?: {\n port?: number;\n serve: (app: HonoType, port: number) => void | Promise<void>;\n }) => Promise<void>;\n}\n\n/**\n * Create and configure the Hono application\n *\n * @param app - Optional Hono app instance to configure (creates new one if not provided)\n * @param enableOpenApi - Enable OpenAPI documentation (default: true)\n * @returns Server app with configured Hono app and start function\n *\n * @example\n * // With Bun\n * import { createApp } from './.gkm/server/app.js';\n *\n * const { app, start } = await createApp();\n *\n * await start({\n * port: 3000,\n * serve: (app, port) => {\n * Bun.serve({ port, fetch: app.fetch });\n * }\n * });\n *\n * @example\n * // With Node.js (using @hono/node-server)\n * import { serve } from '@hono/node-server';\n * import { createApp } from './.gkm/server/app.js';\n *\n * const { app, start } = await createApp();\n *\n * await start({\n * port: 3000,\n * serve: (app, port) => {\n * serve({ fetch: app.fetch, port });\n * }\n * });\n */\nexport async function createApp(app?: HonoType, enableOpenApi: boolean = true): Promise<ServerApp> {\n const honoApp = app || new Hono();\n${telescopeSetup}\n // Setup HTTP endpoints\n setupEndpoints(honoApp, envParser, logger, enableOpenApi);\n\n return {\n app: honoApp,\n async start(options) {\n if (!options?.serve) {\n throw new Error(\n 'serve function is required. Pass a serve function for your runtime:\\\\n' +\n ' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\\\n' +\n ' - Node: (app, port) => serve({ fetch: app.fetch, port })'\n );\n }\n\n const port = options.port ?? 3000;\n\n // Start subscribers in background (non-blocking, local development only)\n await setupSubscribers(envParser, logger).catch((error) => {\n logger.error({ error }, 'Failed to start subscribers');\n });\n\n logger.info({ port }, 'Starting server');\n\n // Start HTTP server using provided serve function\n await options.serve(honoApp, port);\n\n logger.info({ port }, 'Server started');\n }\n };\n}\n\n// Default export for convenience\nexport default createApp;\n`;\n\n await writeFile(appPath, content);\n\n return appPath;\n }\n\n private generateAWSApiGatewayV1Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/constructs/aws';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateAWSApiGatewayV2Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/constructs/aws';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateServerHandler(\n importPath: string,\n exportName: string,\n ): string {\n return `import { ${exportName} } from '${importPath}';\n\n// Server handler - implement based on your server framework\nexport const handler = ${exportName};\n`;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,oBAAb,cAAuC,mB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