@geekmidas/cli 0.6.2 → 0.7.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 +2561 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2556 -29
- package/dist/index.mjs.map +1 -1
- package/dist/openapi-Mwy2_R4W.mjs +957 -0
- package/dist/openapi-Mwy2_R4W.mjs.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-tAIbJJU_.cjs +993 -0
- package/dist/openapi-tAIbJJU_.cjs.map +1 -0
- 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-Bi7VzDUZ.d.mts → types-B3TXoj7v.d.mts} +21 -53
- package/dist/{types-KmjzMgu8.d.cts → types-C0hwnSjm.d.cts} +21 -53
- package/package.json +5 -5
- package/src/build/types.ts +13 -0
- package/src/dev/index.ts +71 -8
- package/src/generators/EndpointGenerator.ts +46 -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 +19 -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
|
@@ -289,12 +289,12 @@ const endpoints: Endpoint<any, any, any, any, any, any, any, any, any, any, any,
|
|
|
289
289
|
${allExportNames.join(',\n ')}
|
|
290
290
|
];
|
|
291
291
|
|
|
292
|
-
export function setupEndpoints(
|
|
292
|
+
export async function setupEndpoints(
|
|
293
293
|
app: Hono,
|
|
294
294
|
envParser: EnvironmentParser<any>,
|
|
295
295
|
logger: Logger,
|
|
296
296
|
enableOpenApi: boolean = true,
|
|
297
|
-
): void {
|
|
297
|
+
): Promise<void> {
|
|
298
298
|
const serviceDiscovery = ServiceDiscovery.getInstance(
|
|
299
299
|
logger,
|
|
300
300
|
envParser
|
|
@@ -302,7 +302,7 @@ export function setupEndpoints(
|
|
|
302
302
|
|
|
303
303
|
// Configure OpenAPI options based on enableOpenApi flag
|
|
304
304
|
const openApiOptions: any = enableOpenApi ? {
|
|
305
|
-
docsPath: '/
|
|
305
|
+
docsPath: '/__docs',
|
|
306
306
|
openApiOptions: {
|
|
307
307
|
title: 'API Documentation',
|
|
308
308
|
version: '1.0.0',
|
|
@@ -311,6 +311,16 @@ export function setupEndpoints(
|
|
|
311
311
|
} : { docsPath: false };
|
|
312
312
|
|
|
313
313
|
HonoEndpoint.addRoutes(endpoints, serviceDiscovery, app, openApiOptions);
|
|
314
|
+
|
|
315
|
+
// Add Swagger UI if OpenAPI is enabled
|
|
316
|
+
if (enableOpenApi) {
|
|
317
|
+
try {
|
|
318
|
+
const { swaggerUI } = await import('@hono/swagger-ui');
|
|
319
|
+
app.get('/__docs/ui', swaggerUI({ url: '/__docs' }));
|
|
320
|
+
} catch {
|
|
321
|
+
// @hono/swagger-ui not installed, skip Swagger UI
|
|
322
|
+
}
|
|
323
|
+
}
|
|
314
324
|
}
|
|
315
325
|
`;
|
|
316
326
|
|
|
@@ -338,6 +348,10 @@ export function setupEndpoints(
|
|
|
338
348
|
const telescopeWebSocketEnabled = context.telescope?.websocket;
|
|
339
349
|
const usesExternalTelescope = !!context.telescope?.telescopePath;
|
|
340
350
|
|
|
351
|
+
// Generate studio imports and setup if enabled
|
|
352
|
+
const studioEnabled = context.studio?.enabled;
|
|
353
|
+
const usesExternalStudio = !!context.studio?.studioPath;
|
|
354
|
+
|
|
341
355
|
// Generate imports based on whether telescope is external or inline
|
|
342
356
|
let telescopeImports = '';
|
|
343
357
|
if (telescopeEnabled) {
|
|
@@ -354,6 +368,22 @@ import { createMiddleware, createUI } from '@geekmidas/telescope/hono';`;
|
|
|
354
368
|
}
|
|
355
369
|
}
|
|
356
370
|
|
|
371
|
+
// Generate imports for studio
|
|
372
|
+
let studioImports = '';
|
|
373
|
+
if (studioEnabled) {
|
|
374
|
+
if (usesExternalStudio) {
|
|
375
|
+
const relativeStudioPath = relative(
|
|
376
|
+
dirname(appPath),
|
|
377
|
+
context.studio!.studioPath!,
|
|
378
|
+
);
|
|
379
|
+
studioImports = `import ${context.studio!.studioImportPattern} from '${relativeStudioPath}';
|
|
380
|
+
import { createStudioApp } from '@geekmidas/studio/server/hono';`;
|
|
381
|
+
} else {
|
|
382
|
+
studioImports = `// Studio requires a configured instance - use studio config path
|
|
383
|
+
// import { createStudioApp } from '@geekmidas/studio/server/hono';`;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
357
387
|
const telescopeWebSocketSetupCode = telescopeWebSocketEnabled
|
|
358
388
|
? `
|
|
359
389
|
// Setup WebSocket for real-time telescope updates
|
|
@@ -425,6 +455,16 @@ ${telescopeWebSocketSetupCode}
|
|
|
425
455
|
}
|
|
426
456
|
}
|
|
427
457
|
|
|
458
|
+
// Generate studio setup - requires external instance
|
|
459
|
+
let studioSetup = '';
|
|
460
|
+
if (studioEnabled && usesExternalStudio) {
|
|
461
|
+
studioSetup = `
|
|
462
|
+
// Mount Studio data browser UI
|
|
463
|
+
const studioApp = createStudioApp(studio);
|
|
464
|
+
honoApp.route('${context.studio!.path}', studioApp);
|
|
465
|
+
`;
|
|
466
|
+
}
|
|
467
|
+
|
|
428
468
|
const content = `/**
|
|
429
469
|
* Generated server application
|
|
430
470
|
*
|
|
@@ -439,6 +479,7 @@ import { setupSubscribers } from './subscribers.js';
|
|
|
439
479
|
import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
|
|
440
480
|
import ${context.loggerImportPattern} from '${relativeLoggerPath}';
|
|
441
481
|
${telescopeImports}
|
|
482
|
+
${studioImports}
|
|
442
483
|
|
|
443
484
|
export interface ServerApp {
|
|
444
485
|
app: HonoType;
|
|
@@ -484,9 +525,9 @@ export interface ServerApp {
|
|
|
484
525
|
*/
|
|
485
526
|
export async function createApp(app?: HonoType, enableOpenApi: boolean = true): Promise<ServerApp> {
|
|
486
527
|
const honoApp = app || new Hono();
|
|
487
|
-
${telescopeSetup}
|
|
528
|
+
${telescopeSetup}${studioSetup}
|
|
488
529
|
// Setup HTTP endpoints
|
|
489
|
-
setupEndpoints(honoApp, envParser, logger, enableOpenApi);
|
|
530
|
+
await setupEndpoints(honoApp, envParser, logger, enableOpenApi);
|
|
490
531
|
|
|
491
532
|
return {
|
|
492
533
|
app: honoApp,
|
|
@@ -111,7 +111,7 @@ describe('EndpointGenerator', () => {
|
|
|
111
111
|
// Function signature always defaults to true
|
|
112
112
|
expect(endpointsContent).toContain('enableOpenApi: boolean = true');
|
|
113
113
|
// OpenAPI options are configured based on the parameter
|
|
114
|
-
expect(endpointsContent).toContain("docsPath: '/
|
|
114
|
+
expect(endpointsContent).toContain("docsPath: '/__docs'");
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
itWithDir(
|
|
@@ -11,7 +11,7 @@ export function generateConfigFiles(
|
|
|
11
11
|
options: TemplateOptions,
|
|
12
12
|
template: TemplateConfig,
|
|
13
13
|
): GeneratedFile[] {
|
|
14
|
-
const { telescope, routesStructure } = options;
|
|
14
|
+
const { telescope, studio, routesStructure } = options;
|
|
15
15
|
const isServerless = template.name === 'serverless';
|
|
16
16
|
const hasWorker = template.name === 'worker';
|
|
17
17
|
|
|
@@ -54,6 +54,11 @@ export default defineConfig({
|
|
|
54
54
|
},`;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
if (studio) {
|
|
58
|
+
gkmConfig += `
|
|
59
|
+
studio: './src/config/studio#studio',`;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
// Always add openapi config (output path is fixed to .gkm/openapi.ts)
|
|
58
63
|
gkmConfig += `
|
|
59
64
|
openapi: {
|
|
@@ -12,7 +12,7 @@ export function generatePackageJson(
|
|
|
12
12
|
options: TemplateOptions,
|
|
13
13
|
template: TemplateConfig,
|
|
14
14
|
): GeneratedFile[] {
|
|
15
|
-
const { name, telescope, database, monorepo } = options;
|
|
15
|
+
const { name, telescope, database, studio, monorepo } = options;
|
|
16
16
|
|
|
17
17
|
// Start with template dependencies
|
|
18
18
|
const dependencies = { ...template.dependencies };
|
|
@@ -24,6 +24,10 @@ export function generatePackageJson(
|
|
|
24
24
|
dependencies['@geekmidas/telescope'] = 'workspace:*';
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
if (studio) {
|
|
28
|
+
dependencies['@geekmidas/studio'] = 'workspace:*';
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
if (database) {
|
|
28
32
|
dependencies['@geekmidas/db'] = 'workspace:*';
|
|
29
33
|
dependencies['kysely'] = '~0.28.2';
|
package/src/init/index.ts
CHANGED
|
@@ -84,6 +84,12 @@ export async function initCommand(
|
|
|
84
84
|
message: 'Include database support (Kysely)?',
|
|
85
85
|
initial: true,
|
|
86
86
|
},
|
|
87
|
+
{
|
|
88
|
+
type: (prev) => (options.yes ? null : prev ? 'confirm' : null),
|
|
89
|
+
name: 'studio',
|
|
90
|
+
message: 'Include Studio (database browser)?',
|
|
91
|
+
initial: true,
|
|
92
|
+
},
|
|
87
93
|
{
|
|
88
94
|
type: options.yes ? null : 'select',
|
|
89
95
|
name: 'loggerType',
|
|
@@ -140,11 +146,13 @@ export async function initCommand(
|
|
|
140
146
|
|
|
141
147
|
const monorepo =
|
|
142
148
|
options.monorepo ?? (options.yes ? false : (answers.monorepo ?? false));
|
|
149
|
+
const database = options.yes ? true : (answers.database ?? true);
|
|
143
150
|
const templateOptions: TemplateOptions = {
|
|
144
151
|
name,
|
|
145
152
|
template: options.template || answers.template || 'minimal',
|
|
146
153
|
telescope: options.yes ? true : (answers.telescope ?? true),
|
|
147
|
-
database
|
|
154
|
+
database,
|
|
155
|
+
studio: database && (options.yes ? true : (answers.studio ?? true)),
|
|
148
156
|
loggerType: options.yes ? 'pino' : (answers.loggerType ?? 'pino'),
|
|
149
157
|
routesStructure: options.yes
|
|
150
158
|
? 'centralized-endpoints'
|
|
@@ -195,6 +195,37 @@ export const telescope = new Telescope({
|
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// Add Studio config if enabled (requires database)
|
|
199
|
+
if (options.studio && options.database) {
|
|
200
|
+
files.push({
|
|
201
|
+
path: 'src/config/studio.ts',
|
|
202
|
+
content: `import { Direction, InMemoryMonitoringStorage, Studio } from '@geekmidas/studio';
|
|
203
|
+
import { Kysely, PostgresDialect } from 'kysely';
|
|
204
|
+
import pg from 'pg';
|
|
205
|
+
import type { Database } from '../services/database';
|
|
206
|
+
import { config } from './env';
|
|
207
|
+
|
|
208
|
+
// Create a Kysely instance for Studio
|
|
209
|
+
const db = new Kysely<Database>({
|
|
210
|
+
dialect: new PostgresDialect({
|
|
211
|
+
pool: new pg.Pool({ connectionString: config.database.url }),
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
export const studio = new Studio<Database>({
|
|
216
|
+
monitoring: {
|
|
217
|
+
storage: new InMemoryMonitoringStorage({ maxEntries: 100 }),
|
|
218
|
+
},
|
|
219
|
+
data: {
|
|
220
|
+
db,
|
|
221
|
+
cursor: { field: 'id', direction: Direction.Desc },
|
|
222
|
+
},
|
|
223
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
224
|
+
});
|
|
225
|
+
`,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
198
229
|
return files;
|
|
199
230
|
},
|
|
200
231
|
};
|
|
@@ -95,6 +95,58 @@ export default e
|
|
|
95
95
|
},
|
|
96
96
|
];
|
|
97
97
|
|
|
98
|
+
// Add database service if enabled
|
|
99
|
+
if (options.database) {
|
|
100
|
+
// Update env.ts to include database config
|
|
101
|
+
files[0] = {
|
|
102
|
+
path: 'src/config/env.ts',
|
|
103
|
+
content: `import { EnvironmentParser } from '@geekmidas/envkit';
|
|
104
|
+
|
|
105
|
+
export const envParser = new EnvironmentParser(process.env);
|
|
106
|
+
|
|
107
|
+
export const config = envParser
|
|
108
|
+
.create((get) => ({
|
|
109
|
+
port: get('PORT').string().transform(Number).default(3000),
|
|
110
|
+
nodeEnv: get('NODE_ENV').string().default('development'),
|
|
111
|
+
database: {
|
|
112
|
+
url: get('DATABASE_URL').string().default('postgresql://localhost:5432/mydb'),
|
|
113
|
+
},
|
|
114
|
+
}))
|
|
115
|
+
.parse();
|
|
116
|
+
`,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
files.push({
|
|
120
|
+
path: 'src/services/database.ts',
|
|
121
|
+
content: `import type { Service } from '@geekmidas/services';
|
|
122
|
+
import { Kysely, PostgresDialect } from 'kysely';
|
|
123
|
+
import pg from 'pg';
|
|
124
|
+
|
|
125
|
+
// Define your database schema
|
|
126
|
+
export interface Database {
|
|
127
|
+
// Add your tables here
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const databaseService = {
|
|
131
|
+
serviceName: 'database' as const,
|
|
132
|
+
async register(envParser) {
|
|
133
|
+
const config = envParser
|
|
134
|
+
.create((get) => ({
|
|
135
|
+
url: get('DATABASE_URL').string(),
|
|
136
|
+
}))
|
|
137
|
+
.parse();
|
|
138
|
+
|
|
139
|
+
return new Kysely<Database>({
|
|
140
|
+
dialect: new PostgresDialect({
|
|
141
|
+
pool: new pg.Pool({ connectionString: config.url }),
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
} satisfies Service<'database', Kysely<Database>>;
|
|
146
|
+
`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
98
150
|
// Add Telescope config if enabled
|
|
99
151
|
if (options.telescope) {
|
|
100
152
|
files.push({
|
|
@@ -110,6 +162,37 @@ export const telescope = new Telescope({
|
|
|
110
162
|
});
|
|
111
163
|
}
|
|
112
164
|
|
|
165
|
+
// Add Studio config if enabled (requires database)
|
|
166
|
+
if (options.studio && options.database) {
|
|
167
|
+
files.push({
|
|
168
|
+
path: 'src/config/studio.ts',
|
|
169
|
+
content: `import { Direction, InMemoryMonitoringStorage, Studio } from '@geekmidas/studio';
|
|
170
|
+
import { Kysely, PostgresDialect } from 'kysely';
|
|
171
|
+
import pg from 'pg';
|
|
172
|
+
import type { Database } from '../services/database';
|
|
173
|
+
import { config } from './env';
|
|
174
|
+
|
|
175
|
+
// Create a Kysely instance for Studio
|
|
176
|
+
const db = new Kysely<Database>({
|
|
177
|
+
dialect: new PostgresDialect({
|
|
178
|
+
pool: new pg.Pool({ connectionString: config.database.url }),
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const studio = new Studio<Database>({
|
|
183
|
+
monitoring: {
|
|
184
|
+
storage: new InMemoryMonitoringStorage({ maxEntries: 100 }),
|
|
185
|
+
},
|
|
186
|
+
data: {
|
|
187
|
+
db,
|
|
188
|
+
cursor: { field: 'id', direction: Direction.Desc },
|
|
189
|
+
},
|
|
190
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
191
|
+
});
|
|
192
|
+
`,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
113
196
|
return files;
|
|
114
197
|
},
|
|
115
198
|
};
|
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;
|
|
@@ -85,6 +94,16 @@ export interface GkmConfig {
|
|
|
85
94
|
* - A TelescopeConfig object for inline configuration
|
|
86
95
|
*/
|
|
87
96
|
telescope?: string | boolean | TelescopeConfig;
|
|
97
|
+
/**
|
|
98
|
+
* Studio configuration for database browsing.
|
|
99
|
+
* Can be:
|
|
100
|
+
* - A string path to a module that exports a Studio instance (recommended)
|
|
101
|
+
* - A boolean to enable/disable with defaults
|
|
102
|
+
* - A StudioConfig object for inline configuration
|
|
103
|
+
*
|
|
104
|
+
* Requires a database connection configured via services.
|
|
105
|
+
*/
|
|
106
|
+
studio?: string | boolean | StudioConfig;
|
|
88
107
|
/**
|
|
89
108
|
* OpenAPI generation configuration.
|
|
90
109
|
* 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,SACqB;EACrB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,YAAwB,CAAE;AAEhC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,WAAW,oBAAK,WAAW,QAAQ;AACzC,QAAM,4BAAM,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,wBAAS,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,kCAAK,OAAO,MAAM;CAC1B;CAED,MAAc,oBACZH,WACAI,YACAC,YACAP,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,oBAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,wBAAS,uBAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,wBAC5B,uBAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,wBACzB,uBAAQ,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,gCAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CronInfo } from "./types-KmjzMgu8.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
|