@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
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { relative } from "path";
|
|
2
|
-
import fg from "fast-glob";
|
|
3
|
-
import kebabCase from "lodash.kebabcase";
|
|
4
|
-
|
|
5
|
-
//#region src/generators/Generator.ts
|
|
6
|
-
var ConstructGenerator = class {
|
|
7
|
-
static async build(context, outputDir, generator, patterns, options) {
|
|
8
|
-
const constructs = await generator.load(patterns);
|
|
9
|
-
return generator.build(context, constructs, outputDir, options);
|
|
10
|
-
}
|
|
11
|
-
async load(patterns, cwd = process.cwd()) {
|
|
12
|
-
const logger = console;
|
|
13
|
-
const globPatterns = Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
|
|
14
|
-
const files = fg.stream(globPatterns, {
|
|
15
|
-
cwd,
|
|
16
|
-
absolute: true
|
|
17
|
-
});
|
|
18
|
-
const constructs = [];
|
|
19
|
-
for await (const f of files) try {
|
|
20
|
-
const file = f.toString();
|
|
21
|
-
const module = await import(file);
|
|
22
|
-
for (const [key, construct] of Object.entries(module)) if (this.isConstruct(construct)) constructs.push({
|
|
23
|
-
key,
|
|
24
|
-
name: kebabCase(key),
|
|
25
|
-
construct,
|
|
26
|
-
path: {
|
|
27
|
-
absolute: file,
|
|
28
|
-
relative: relative(process.cwd(), file)
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
} catch (error) {
|
|
32
|
-
logger.warn(`Failed to load ${f}:`, error.message);
|
|
33
|
-
throw new Error("Failed to load constructs. Please check the logs for details.");
|
|
34
|
-
}
|
|
35
|
-
return constructs;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { ConstructGenerator };
|
|
41
|
-
//# sourceMappingURL=Generator-CDt4pB3W.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Generator-CDt4pB3W.mjs","names":["context: BuildContext","outputDir: string","generator: ConstructGenerator<T, R>","patterns?: Routes","options?: GeneratorOptions","constructs: GeneratedConstruct<T>[]"],"sources":["../src/generators/Generator.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { Construct } from '@geekmidas/constructs';\nimport fg from 'fast-glob';\nimport kebabCase from 'lodash.kebabcase';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, Routes } from '../types';\n\nexport interface GeneratorOptions {\n provider?: LegacyProvider;\n [key: string]: any;\n}\n\nexport abstract class ConstructGenerator<T extends Construct, R = void> {\n abstract isConstruct(value: any): value is T;\n\n static async build<T extends Construct, R = void>(\n context: BuildContext,\n outputDir: string,\n generator: ConstructGenerator<T, R>,\n patterns?: Routes,\n options?: GeneratorOptions,\n ): Promise<R> {\n const constructs = await generator.load(patterns);\n return generator.build(context, constructs, outputDir, options);\n }\n\n abstract build(\n context: BuildContext,\n constructs: GeneratedConstruct<T>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<R>;\n\n async load(\n patterns?: Routes,\n cwd = process.cwd(),\n ): Promise<GeneratedConstruct<T>[]> {\n const logger = console;\n\n // Normalize patterns to array\n const globPatterns = Array.isArray(patterns)\n ? patterns\n : patterns\n ? [patterns]\n : [];\n\n // Find all files\n const files = fg.stream(globPatterns, {\n cwd,\n absolute: true,\n });\n\n // Load constructs\n const constructs: GeneratedConstruct<T>[] = [];\n\n for await (const f of files) {\n try {\n const file = f.toString();\n const module = await import(file);\n\n // Check all exports for constructs\n for (const [key, construct] of Object.entries(module)) {\n if (this.isConstruct(construct)) {\n constructs.push({\n key,\n name: kebabCase(key),\n construct,\n path: {\n absolute: file,\n relative: relative(process.cwd(), file),\n },\n });\n }\n }\n } catch (error) {\n logger.warn(`Failed to load ${f}:`, (error as Error).message);\n throw new Error(\n 'Failed to load constructs. Please check the logs for details.',\n );\n }\n }\n\n return constructs;\n }\n}\n\nexport interface GeneratedConstruct<T extends Construct> {\n key: string;\n name: string;\n construct: T;\n path: {\n absolute: string;\n relative: string;\n };\n}\n"],"mappings":";;;;;AAYA,IAAsB,qBAAtB,MAAwE;CAGtE,aAAa,MACXA,SACAC,WACAC,WACAC,UACAC,SACY;EACZ,MAAM,aAAa,MAAM,UAAU,KAAK,SAAS;AACjD,SAAO,UAAU,MAAM,SAAS,YAAY,WAAW,QAAQ;CAChE;CASD,MAAM,KACJD,UACA,MAAM,QAAQ,KAAK,EACe;EAClC,MAAM,SAAS;EAGf,MAAM,eAAe,MAAM,QAAQ,SAAS,GACxC,WACA,WACE,CAAC,QAAS,IACV,CAAE;EAGR,MAAM,QAAQ,GAAG,OAAO,cAAc;GACpC;GACA,UAAU;EACX,EAAC;EAGF,MAAME,aAAsC,CAAE;AAE9C,aAAW,MAAM,KAAK,MACpB,KAAI;GACF,MAAM,OAAO,EAAE,UAAU;GACzB,MAAM,SAAS,MAAM,OAAO;AAG5B,QAAK,MAAM,CAAC,KAAK,UAAU,IAAI,OAAO,QAAQ,OAAO,CACnD,KAAI,KAAK,YAAY,UAAU,CAC7B,YAAW,KAAK;IACd;IACA,MAAM,UAAU,IAAI;IACpB;IACA,MAAM;KACJ,UAAU;KACV,UAAU,SAAS,QAAQ,KAAK,EAAE,KAAK;IACxC;GACF,EAAC;EAGP,SAAQ,OAAO;AACd,UAAO,MAAM,iBAAiB,EAAE,IAAK,MAAgB,QAAQ;AAC7D,SAAM,IAAI,MACR;EAEH;AAGH,SAAO;CACR;AACF"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const path = require_chunk.__toESM(require("path"));
|
|
3
|
-
const fast_glob = require_chunk.__toESM(require("fast-glob"));
|
|
4
|
-
const lodash_kebabcase = require_chunk.__toESM(require("lodash.kebabcase"));
|
|
5
|
-
|
|
6
|
-
//#region src/generators/Generator.ts
|
|
7
|
-
var ConstructGenerator = class {
|
|
8
|
-
static async build(context, outputDir, generator, patterns, options) {
|
|
9
|
-
const constructs = await generator.load(patterns);
|
|
10
|
-
return generator.build(context, constructs, outputDir, options);
|
|
11
|
-
}
|
|
12
|
-
async load(patterns, cwd = process.cwd()) {
|
|
13
|
-
const logger = console;
|
|
14
|
-
const globPatterns = Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
|
|
15
|
-
const files = fast_glob.default.stream(globPatterns, {
|
|
16
|
-
cwd,
|
|
17
|
-
absolute: true
|
|
18
|
-
});
|
|
19
|
-
const constructs = [];
|
|
20
|
-
for await (const f of files) try {
|
|
21
|
-
const file = f.toString();
|
|
22
|
-
const module$1 = await import(file);
|
|
23
|
-
for (const [key, construct] of Object.entries(module$1)) if (this.isConstruct(construct)) constructs.push({
|
|
24
|
-
key,
|
|
25
|
-
name: (0, lodash_kebabcase.default)(key),
|
|
26
|
-
construct,
|
|
27
|
-
path: {
|
|
28
|
-
absolute: file,
|
|
29
|
-
relative: (0, path.relative)(process.cwd(), file)
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
} catch (error) {
|
|
33
|
-
logger.warn(`Failed to load ${f}:`, error.message);
|
|
34
|
-
throw new Error("Failed to load constructs. Please check the logs for details.");
|
|
35
|
-
}
|
|
36
|
-
return constructs;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
Object.defineProperty(exports, 'ConstructGenerator', {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return ConstructGenerator;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
//# sourceMappingURL=Generator-CLVplqm2.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Generator-CLVplqm2.cjs","names":["context: BuildContext","outputDir: string","generator: ConstructGenerator<T, R>","patterns?: Routes","options?: GeneratorOptions","constructs: GeneratedConstruct<T>[]","module"],"sources":["../src/generators/Generator.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { Construct } from '@geekmidas/constructs';\nimport fg from 'fast-glob';\nimport kebabCase from 'lodash.kebabcase';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, Routes } from '../types';\n\nexport interface GeneratorOptions {\n provider?: LegacyProvider;\n [key: string]: any;\n}\n\nexport abstract class ConstructGenerator<T extends Construct, R = void> {\n abstract isConstruct(value: any): value is T;\n\n static async build<T extends Construct, R = void>(\n context: BuildContext,\n outputDir: string,\n generator: ConstructGenerator<T, R>,\n patterns?: Routes,\n options?: GeneratorOptions,\n ): Promise<R> {\n const constructs = await generator.load(patterns);\n return generator.build(context, constructs, outputDir, options);\n }\n\n abstract build(\n context: BuildContext,\n constructs: GeneratedConstruct<T>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<R>;\n\n async load(\n patterns?: Routes,\n cwd = process.cwd(),\n ): Promise<GeneratedConstruct<T>[]> {\n const logger = console;\n\n // Normalize patterns to array\n const globPatterns = Array.isArray(patterns)\n ? patterns\n : patterns\n ? [patterns]\n : [];\n\n // Find all files\n const files = fg.stream(globPatterns, {\n cwd,\n absolute: true,\n });\n\n // Load constructs\n const constructs: GeneratedConstruct<T>[] = [];\n\n for await (const f of files) {\n try {\n const file = f.toString();\n const module = await import(file);\n\n // Check all exports for constructs\n for (const [key, construct] of Object.entries(module)) {\n if (this.isConstruct(construct)) {\n constructs.push({\n key,\n name: kebabCase(key),\n construct,\n path: {\n absolute: file,\n relative: relative(process.cwd(), file),\n },\n });\n }\n }\n } catch (error) {\n logger.warn(`Failed to load ${f}:`, (error as Error).message);\n throw new Error(\n 'Failed to load constructs. Please check the logs for details.',\n );\n }\n }\n\n return constructs;\n }\n}\n\nexport interface GeneratedConstruct<T extends Construct> {\n key: string;\n name: string;\n construct: T;\n path: {\n absolute: string;\n relative: string;\n };\n}\n"],"mappings":";;;;;;AAYA,IAAsB,qBAAtB,MAAwE;CAGtE,aAAa,MACXA,SACAC,WACAC,WACAC,UACAC,SACY;EACZ,MAAM,aAAa,MAAM,UAAU,KAAK,SAAS;AACjD,SAAO,UAAU,MAAM,SAAS,YAAY,WAAW,QAAQ;CAChE;CASD,MAAM,KACJD,UACA,MAAM,QAAQ,KAAK,EACe;EAClC,MAAM,SAAS;EAGf,MAAM,eAAe,MAAM,QAAQ,SAAS,GACxC,WACA,WACE,CAAC,QAAS,IACV,CAAE;EAGR,MAAM,QAAQ,kBAAG,OAAO,cAAc;GACpC;GACA,UAAU;EACX,EAAC;EAGF,MAAME,aAAsC,CAAE;AAE9C,aAAW,MAAM,KAAK,MACpB,KAAI;GACF,MAAM,OAAO,EAAE,UAAU;GACzB,MAAMC,WAAS,MAAM,OAAO;AAG5B,QAAK,MAAM,CAAC,KAAK,UAAU,IAAI,OAAO,QAAQA,SAAO,CACnD,KAAI,KAAK,YAAY,UAAU,CAC7B,YAAW,KAAK;IACd;IACA,MAAM,8BAAU,IAAI;IACpB;IACA,MAAM;KACJ,UAAU;KACV,UAAU,mBAAS,QAAQ,KAAK,EAAE,KAAK;IACxC;GACF,EAAC;EAGP,SAAQ,OAAO;AACd,UAAO,MAAM,iBAAiB,EAAE,IAAK,MAAgB,QAAQ;AAC7D,SAAM,IAAI,MACR;EAEH;AAGH,SAAO;CACR;AACF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { LegacyProvider, Routes } from "./types-Bi7VzDUZ.mjs";
|
|
2
|
-
import { BuildContext } from "./types-D2xYkOal.mjs";
|
|
3
|
-
import { Construct } from "@geekmidas/constructs";
|
|
4
|
-
|
|
5
|
-
//#region src/generators/Generator.d.ts
|
|
6
|
-
interface GeneratorOptions {
|
|
7
|
-
provider?: LegacyProvider;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
declare abstract class ConstructGenerator<T extends Construct, R = void> {
|
|
11
|
-
abstract isConstruct(value: any): value is T;
|
|
12
|
-
static build<T extends Construct, R = void>(context: BuildContext, outputDir: string, generator: ConstructGenerator<T, R>, patterns?: Routes, options?: GeneratorOptions): Promise<R>;
|
|
13
|
-
abstract build(context: BuildContext, constructs: GeneratedConstruct<T>[], outputDir: string, options?: GeneratorOptions): Promise<R>;
|
|
14
|
-
load(patterns?: Routes, cwd?: string): Promise<GeneratedConstruct<T>[]>;
|
|
15
|
-
}
|
|
16
|
-
interface GeneratedConstruct<T extends Construct> {
|
|
17
|
-
key: string;
|
|
18
|
-
name: string;
|
|
19
|
-
construct: T;
|
|
20
|
-
path: {
|
|
21
|
-
absolute: string;
|
|
22
|
-
relative: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { ConstructGenerator, GeneratedConstruct, GeneratorOptions };
|
|
27
|
-
//# sourceMappingURL=Generator-yi9DH5TN.d.mts.map
|
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import { StandardSchemaJsonSchema, getSchemaMetadata } from "@geekmidas/schema/conversion";
|
|
2
|
-
|
|
3
|
-
//#region src/generators/OpenApiTsGenerator.ts
|
|
4
|
-
/**
|
|
5
|
-
* Generates TypeScript OpenAPI module from endpoints.
|
|
6
|
-
* Outputs:
|
|
7
|
-
* - securitySchemes: typed security scheme definitions
|
|
8
|
-
* - endpointAuth: runtime map of endpoints to auth requirements
|
|
9
|
-
* - paths: TypeScript interface for type-safe fetcher
|
|
10
|
-
* - schema interfaces: reusable TypeScript types from Zod/Valibot schemas
|
|
11
|
-
*/
|
|
12
|
-
var OpenApiTsGenerator = class {
|
|
13
|
-
async generate(endpoints, options = {}) {
|
|
14
|
-
const { title = "API", version = "1.0.0", description } = options;
|
|
15
|
-
const endpointInfos = await this.extractEndpointInfos(endpoints);
|
|
16
|
-
const securitySchemes = this.collectSecuritySchemes(endpointInfos);
|
|
17
|
-
const endpointAuth = this.buildEndpointAuthMap(endpointInfos);
|
|
18
|
-
const schemaInterfaces = await this.generateSchemaInterfaces(endpointInfos);
|
|
19
|
-
const pathsInterface = await this.generatePathsInterface(endpointInfos);
|
|
20
|
-
return this.buildModule({
|
|
21
|
-
title,
|
|
22
|
-
version,
|
|
23
|
-
description,
|
|
24
|
-
securitySchemes,
|
|
25
|
-
endpointAuth,
|
|
26
|
-
schemaInterfaces,
|
|
27
|
-
pathsInterface
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async extractEndpointInfos(endpoints) {
|
|
31
|
-
return endpoints.map((ep) => {
|
|
32
|
-
const route = ep.route.replace(/:(\w+)/g, "{$1}");
|
|
33
|
-
const method = ep.method.toUpperCase();
|
|
34
|
-
const securityScheme = ep.authorizer?.securityScheme;
|
|
35
|
-
return {
|
|
36
|
-
endpoint: `${method} ${route}`,
|
|
37
|
-
route,
|
|
38
|
-
method,
|
|
39
|
-
authorizerName: ep.authorizer?.name ?? null,
|
|
40
|
-
authorizerType: ep.authorizer?.type ?? null,
|
|
41
|
-
securityScheme: securityScheme ?? null,
|
|
42
|
-
input: ep.input,
|
|
43
|
-
output: ep.outputSchema,
|
|
44
|
-
description: ep.description,
|
|
45
|
-
tags: ep.tags,
|
|
46
|
-
operationId: ep.operationId
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
collectSecuritySchemes(endpointInfos) {
|
|
51
|
-
const schemes = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const info of endpointInfos) if (info.authorizerName && !schemes.has(info.authorizerName)) {
|
|
53
|
-
const scheme = info.securityScheme ?? (info.authorizerType ? this.mapAuthorizerToSecurityScheme(info.authorizerType, info.authorizerName) : null);
|
|
54
|
-
if (scheme) schemes.set(info.authorizerName, {
|
|
55
|
-
name: info.authorizerName,
|
|
56
|
-
type: scheme.type,
|
|
57
|
-
scheme
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return Array.from(schemes.values());
|
|
61
|
-
}
|
|
62
|
-
mapAuthorizerToSecurityScheme(type, _name) {
|
|
63
|
-
switch (type.toLowerCase()) {
|
|
64
|
-
case "jwt":
|
|
65
|
-
case "bearer": return {
|
|
66
|
-
type: "http",
|
|
67
|
-
scheme: "bearer",
|
|
68
|
-
bearerFormat: "JWT"
|
|
69
|
-
};
|
|
70
|
-
case "iam":
|
|
71
|
-
case "aws-sigv4":
|
|
72
|
-
case "sigv4": return {
|
|
73
|
-
type: "apiKey",
|
|
74
|
-
in: "header",
|
|
75
|
-
name: "Authorization",
|
|
76
|
-
"x-amazon-apigateway-authtype": "awsSigv4"
|
|
77
|
-
};
|
|
78
|
-
case "apikey":
|
|
79
|
-
case "api-key": return {
|
|
80
|
-
type: "apiKey",
|
|
81
|
-
in: "header",
|
|
82
|
-
name: "X-API-Key"
|
|
83
|
-
};
|
|
84
|
-
case "oauth2": return {
|
|
85
|
-
type: "oauth2",
|
|
86
|
-
flows: {}
|
|
87
|
-
};
|
|
88
|
-
case "oidc":
|
|
89
|
-
case "openidconnect": return {
|
|
90
|
-
type: "openIdConnect",
|
|
91
|
-
openIdConnectUrl: ""
|
|
92
|
-
};
|
|
93
|
-
default: return {
|
|
94
|
-
type: "http",
|
|
95
|
-
scheme: "bearer"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
buildEndpointAuthMap(endpointInfos) {
|
|
100
|
-
const authMap = {};
|
|
101
|
-
for (const info of endpointInfos) authMap[info.endpoint] = info.authorizerName;
|
|
102
|
-
return authMap;
|
|
103
|
-
}
|
|
104
|
-
async generateSchemaInterfaces(endpointInfos) {
|
|
105
|
-
const interfaces = [];
|
|
106
|
-
const generatedNames = /* @__PURE__ */ new Set();
|
|
107
|
-
const collectedDefs = /* @__PURE__ */ new Map();
|
|
108
|
-
for (const info of endpointInfos) {
|
|
109
|
-
const baseName = this.getSchemaBaseName(info);
|
|
110
|
-
if (info.input?.body) {
|
|
111
|
-
const name = await this.getSchemaName(info.input.body, `${baseName}Input`);
|
|
112
|
-
if (!generatedNames.has(name)) {
|
|
113
|
-
const schema = await this.schemaToInterfaceWithDefs(info.input.body, name, collectedDefs);
|
|
114
|
-
if (schema) {
|
|
115
|
-
interfaces.push(schema);
|
|
116
|
-
generatedNames.add(name);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (info.input?.params) {
|
|
121
|
-
const name = await this.getSchemaName(info.input.params, `${baseName}Params`);
|
|
122
|
-
if (!generatedNames.has(name)) {
|
|
123
|
-
const schema = await this.schemaToInterfaceWithDefs(info.input.params, name, collectedDefs);
|
|
124
|
-
if (schema) {
|
|
125
|
-
interfaces.push(schema);
|
|
126
|
-
generatedNames.add(name);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (info.input?.query) {
|
|
131
|
-
const name = await this.getSchemaName(info.input.query, `${baseName}Query`);
|
|
132
|
-
if (!generatedNames.has(name)) {
|
|
133
|
-
const schema = await this.schemaToInterfaceWithDefs(info.input.query, name, collectedDefs);
|
|
134
|
-
if (schema) {
|
|
135
|
-
interfaces.push(schema);
|
|
136
|
-
generatedNames.add(name);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (info.output) {
|
|
141
|
-
const name = await this.getSchemaName(info.output, `${baseName}Output`);
|
|
142
|
-
if (!generatedNames.has(name)) {
|
|
143
|
-
const schema = await this.schemaToInterfaceWithDefs(info.output, name, collectedDefs);
|
|
144
|
-
if (schema) {
|
|
145
|
-
interfaces.push(schema);
|
|
146
|
-
generatedNames.add(name);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
for (const [defName, defSchema] of collectedDefs) if (!generatedNames.has(defName)) {
|
|
152
|
-
const interfaceStr = this.jsonSchemaToInterface(defSchema, defName);
|
|
153
|
-
interfaces.push(interfaceStr);
|
|
154
|
-
generatedNames.add(defName);
|
|
155
|
-
}
|
|
156
|
-
return interfaces.join("\n\n");
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get the name for a schema, using metadata `id` if available,
|
|
160
|
-
* otherwise falling back to the provided default name.
|
|
161
|
-
*/
|
|
162
|
-
async getSchemaName(schema, defaultName) {
|
|
163
|
-
try {
|
|
164
|
-
const metadata = await getSchemaMetadata(schema);
|
|
165
|
-
if (metadata?.id) return this.pascalCase(metadata.id);
|
|
166
|
-
} catch {}
|
|
167
|
-
return defaultName;
|
|
168
|
-
}
|
|
169
|
-
getSchemaBaseName(info) {
|
|
170
|
-
if (info.operationId) return this.pascalCase(info.operationId);
|
|
171
|
-
const routeParts = info.route.replace(/[{}]/g, "").split("/").filter(Boolean).map((part) => this.pascalCase(part));
|
|
172
|
-
return `${this.pascalCase(info.method.toLowerCase())}${routeParts.join("")}`;
|
|
173
|
-
}
|
|
174
|
-
pascalCase(str) {
|
|
175
|
-
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^./, (c) => c.toUpperCase());
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Convert schema to interface while collecting $defs for nested schemas
|
|
179
|
-
* with .meta({ id: 'X' }).
|
|
180
|
-
*/
|
|
181
|
-
async schemaToInterfaceWithDefs(schema, name, collectedDefs) {
|
|
182
|
-
try {
|
|
183
|
-
const vendor = schema["~standard"]?.vendor;
|
|
184
|
-
if (!vendor || !(vendor in StandardSchemaJsonSchema)) return null;
|
|
185
|
-
const toJsonSchema = StandardSchemaJsonSchema[vendor];
|
|
186
|
-
const jsonSchema = await toJsonSchema(schema);
|
|
187
|
-
if (!jsonSchema) return null;
|
|
188
|
-
if (jsonSchema.$defs && typeof jsonSchema.$defs === "object") {
|
|
189
|
-
for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) if (!collectedDefs.has(defName)) {
|
|
190
|
-
const { id,...schemaWithoutId } = defSchema;
|
|
191
|
-
collectedDefs.set(defName, schemaWithoutId);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const { $defs,...schemaWithoutDefs } = jsonSchema;
|
|
195
|
-
return this.jsonSchemaToInterface(schemaWithoutDefs, name);
|
|
196
|
-
} catch {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
jsonSchemaToInterface(schema, name) {
|
|
201
|
-
if (schema.type !== "object" || !schema.properties) {
|
|
202
|
-
const typeStr = this.jsonSchemaTypeToTs(schema);
|
|
203
|
-
return `export type ${name} = ${typeStr};`;
|
|
204
|
-
}
|
|
205
|
-
const props = [];
|
|
206
|
-
const required = new Set(schema.required || []);
|
|
207
|
-
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
208
|
-
const isRequired = required.has(propName);
|
|
209
|
-
const typeStr = this.jsonSchemaTypeToTs(propSchema);
|
|
210
|
-
const optionalMark = isRequired ? "" : "?";
|
|
211
|
-
props.push(` ${propName}${optionalMark}: ${typeStr};`);
|
|
212
|
-
}
|
|
213
|
-
return `export interface ${name} {\n${props.join("\n")}\n}`;
|
|
214
|
-
}
|
|
215
|
-
jsonSchemaTypeToTs(schema) {
|
|
216
|
-
if (!schema) return "unknown";
|
|
217
|
-
if (schema.$ref) {
|
|
218
|
-
const refName = schema.$ref.split("/").pop() || "unknown";
|
|
219
|
-
return refName;
|
|
220
|
-
}
|
|
221
|
-
if (schema.anyOf) return schema.anyOf.map((s) => this.jsonSchemaTypeToTs(s)).join(" | ");
|
|
222
|
-
if (schema.oneOf) return schema.oneOf.map((s) => this.jsonSchemaTypeToTs(s)).join(" | ");
|
|
223
|
-
if (schema.allOf) return schema.allOf.map((s) => this.jsonSchemaTypeToTs(s)).join(" & ");
|
|
224
|
-
switch (schema.type) {
|
|
225
|
-
case "string":
|
|
226
|
-
if (schema.enum) return schema.enum.map((e) => `'${e}'`).join(" | ");
|
|
227
|
-
return "string";
|
|
228
|
-
case "number":
|
|
229
|
-
case "integer": return "number";
|
|
230
|
-
case "boolean": return "boolean";
|
|
231
|
-
case "null": return "null";
|
|
232
|
-
case "array":
|
|
233
|
-
if (schema.items) return `Array<${this.jsonSchemaTypeToTs(schema.items)}>`;
|
|
234
|
-
return "Array<unknown>";
|
|
235
|
-
case "object":
|
|
236
|
-
if (schema.properties) {
|
|
237
|
-
const props = [];
|
|
238
|
-
const required = new Set(schema.required || []);
|
|
239
|
-
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
240
|
-
const isRequired = required.has(propName);
|
|
241
|
-
const typeStr = this.jsonSchemaTypeToTs(propSchema);
|
|
242
|
-
const optionalMark = isRequired ? "" : "?";
|
|
243
|
-
props.push(`${propName}${optionalMark}: ${typeStr}`);
|
|
244
|
-
}
|
|
245
|
-
return `{ ${props.join("; ")} }`;
|
|
246
|
-
}
|
|
247
|
-
if (schema.additionalProperties) {
|
|
248
|
-
const valueType = this.jsonSchemaTypeToTs(schema.additionalProperties);
|
|
249
|
-
return `Record<string, ${valueType}>`;
|
|
250
|
-
}
|
|
251
|
-
return "Record<string, unknown>";
|
|
252
|
-
default: return "unknown";
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
async generatePathsInterface(endpointInfos) {
|
|
256
|
-
const pathGroups = /* @__PURE__ */ new Map();
|
|
257
|
-
for (const info of endpointInfos) {
|
|
258
|
-
const existing = pathGroups.get(info.route) || [];
|
|
259
|
-
existing.push(info);
|
|
260
|
-
pathGroups.set(info.route, existing);
|
|
261
|
-
}
|
|
262
|
-
const pathEntries = [];
|
|
263
|
-
for (const [route, infos] of pathGroups) {
|
|
264
|
-
const methodEntries = [];
|
|
265
|
-
for (const info of infos) {
|
|
266
|
-
const methodDef = await this.generateMethodDefinition(info);
|
|
267
|
-
methodEntries.push(` ${info.method.toLowerCase()}: ${methodDef};`);
|
|
268
|
-
}
|
|
269
|
-
const firstWithParams = infos.find((i) => i.input?.params);
|
|
270
|
-
let paramsEntry = "";
|
|
271
|
-
if (firstWithParams?.input?.params) {
|
|
272
|
-
const paramsName = await this.getSchemaName(firstWithParams.input.params, `${this.getSchemaBaseName(firstWithParams)}Params`);
|
|
273
|
-
paramsEntry = `\n parameters: {\n path: ${paramsName};\n };`;
|
|
274
|
-
}
|
|
275
|
-
pathEntries.push(` '${route}': {${paramsEntry}\n${methodEntries.join("\n")}\n };`);
|
|
276
|
-
}
|
|
277
|
-
return `export interface paths {\n${pathEntries.join("\n")}\n}`;
|
|
278
|
-
}
|
|
279
|
-
async generateMethodDefinition(info) {
|
|
280
|
-
const parts = [];
|
|
281
|
-
const baseName = this.getSchemaBaseName(info);
|
|
282
|
-
if (info.input?.body) {
|
|
283
|
-
const bodyName = await this.getSchemaName(info.input.body, `${baseName}Input`);
|
|
284
|
-
parts.push(`requestBody: {
|
|
285
|
-
content: {
|
|
286
|
-
'application/json': ${bodyName};
|
|
287
|
-
};
|
|
288
|
-
}`);
|
|
289
|
-
}
|
|
290
|
-
if (info.input?.query) {
|
|
291
|
-
const queryName = await this.getSchemaName(info.input.query, `${baseName}Query`);
|
|
292
|
-
parts.push(`parameters: {
|
|
293
|
-
query: ${queryName};
|
|
294
|
-
}`);
|
|
295
|
-
}
|
|
296
|
-
const outputName = info.output ? await this.getSchemaName(info.output, `${baseName}Output`) : "unknown";
|
|
297
|
-
parts.push(`responses: {
|
|
298
|
-
200: {
|
|
299
|
-
content: {
|
|
300
|
-
'application/json': ${outputName};
|
|
301
|
-
};
|
|
302
|
-
};
|
|
303
|
-
}`);
|
|
304
|
-
return `{\n ${parts.join(";\n ")};\n }`;
|
|
305
|
-
}
|
|
306
|
-
buildModule(params) {
|
|
307
|
-
const { title, version, description, securitySchemes, endpointAuth, schemaInterfaces, pathsInterface } = params;
|
|
308
|
-
const securitySchemesObj = securitySchemes.reduce((acc, s) => {
|
|
309
|
-
acc[s.name] = s.scheme;
|
|
310
|
-
return acc;
|
|
311
|
-
}, {});
|
|
312
|
-
const schemeNames = securitySchemes.map((s) => `'${s.name}'`).join(" | ");
|
|
313
|
-
const hasSecuritySchemes = schemeNames.length > 0;
|
|
314
|
-
const createApiSection = hasSecuritySchemes ? `
|
|
315
|
-
// ============================================================
|
|
316
|
-
// API Client Factory
|
|
317
|
-
// ============================================================
|
|
318
|
-
|
|
319
|
-
import {
|
|
320
|
-
createAuthAwareFetcher,
|
|
321
|
-
type AuthStrategy,
|
|
322
|
-
} from '@geekmidas/client/auth-fetcher';
|
|
323
|
-
import { createEndpointHooks } from '@geekmidas/client/endpoint-hooks';
|
|
324
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Options for creating the API client.
|
|
328
|
-
*/
|
|
329
|
-
export interface CreateApiOptions {
|
|
330
|
-
/** Base URL for all API requests (required) */
|
|
331
|
-
baseURL: string;
|
|
332
|
-
/** Auth strategies for each security scheme used in this API */
|
|
333
|
-
authStrategies: Record<SecuritySchemeId, AuthStrategy>;
|
|
334
|
-
/** Optional React Query client instance */
|
|
335
|
-
queryClient?: QueryClient;
|
|
336
|
-
/** Optional request interceptor */
|
|
337
|
-
onRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Create a type-safe API client with authentication and React Query hooks.
|
|
342
|
-
*
|
|
343
|
-
* @example
|
|
344
|
-
* \`\`\`typescript
|
|
345
|
-
* const api = createApi({
|
|
346
|
-
* baseURL: 'https://api.example.com',
|
|
347
|
-
* authStrategies: {
|
|
348
|
-
* jwt: { type: 'bearer', tokenProvider },
|
|
349
|
-
* },
|
|
350
|
-
* });
|
|
351
|
-
*
|
|
352
|
-
* // Imperative fetch
|
|
353
|
-
* const user = await api('GET /users/{id}', { params: { id: '123' } });
|
|
354
|
-
*
|
|
355
|
-
* // React Query hooks
|
|
356
|
-
* const { data } = api.useQuery('GET /users/{id}', { params: { id: '123' } });
|
|
357
|
-
* const mutation = api.useMutation('POST /users');
|
|
358
|
-
* \`\`\`
|
|
359
|
-
*/
|
|
360
|
-
export function createApi(options: CreateApiOptions) {
|
|
361
|
-
const fetcher = createAuthAwareFetcher<paths, typeof endpointAuth, typeof securitySchemes>({
|
|
362
|
-
baseURL: options.baseURL,
|
|
363
|
-
endpointAuth,
|
|
364
|
-
securitySchemes,
|
|
365
|
-
authStrategies: options.authStrategies,
|
|
366
|
-
onRequest: options.onRequest,
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const hooks = createEndpointHooks<paths>(fetcher, { queryClient: options.queryClient });
|
|
370
|
-
|
|
371
|
-
return Object.assign(fetcher, hooks);
|
|
372
|
-
}
|
|
373
|
-
` : `
|
|
374
|
-
// ============================================================
|
|
375
|
-
// API Client Factory
|
|
376
|
-
// ============================================================
|
|
377
|
-
|
|
378
|
-
import { TypedFetcher, type FetcherOptions } from '@geekmidas/client/fetcher';
|
|
379
|
-
import { createEndpointHooks } from '@geekmidas/client/endpoint-hooks';
|
|
380
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Options for creating the API client.
|
|
384
|
-
*/
|
|
385
|
-
export interface CreateApiOptions extends Omit<FetcherOptions, 'baseURL'> {
|
|
386
|
-
/** Base URL for all API requests (required) */
|
|
387
|
-
baseURL: string;
|
|
388
|
-
/** Optional React Query client instance */
|
|
389
|
-
queryClient?: QueryClient;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Create a type-safe API client with React Query hooks.
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* \`\`\`typescript
|
|
397
|
-
* const api = createApi({
|
|
398
|
-
* baseURL: 'https://api.example.com',
|
|
399
|
-
* });
|
|
400
|
-
*
|
|
401
|
-
* // Imperative fetch
|
|
402
|
-
* const data = await api('GET /health');
|
|
403
|
-
*
|
|
404
|
-
* // React Query hooks
|
|
405
|
-
* const { data } = api.useQuery('GET /health');
|
|
406
|
-
* \`\`\`
|
|
407
|
-
*/
|
|
408
|
-
export function createApi(options: CreateApiOptions) {
|
|
409
|
-
const { queryClient, ...fetcherOptions } = options;
|
|
410
|
-
const fetcher = new TypedFetcher<paths>(fetcherOptions);
|
|
411
|
-
|
|
412
|
-
const hooks = createEndpointHooks<paths>(fetcher.request.bind(fetcher), { queryClient });
|
|
413
|
-
|
|
414
|
-
return Object.assign(fetcher.request.bind(fetcher), hooks);
|
|
415
|
-
}
|
|
416
|
-
`;
|
|
417
|
-
return `// Auto-generated by @geekmidas/cli - DO NOT EDIT
|
|
418
|
-
// Generated: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
419
|
-
|
|
420
|
-
// ============================================================
|
|
421
|
-
// Security Scheme Type
|
|
422
|
-
// ============================================================
|
|
423
|
-
|
|
424
|
-
interface SecuritySchemeObject {
|
|
425
|
-
type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
|
|
426
|
-
description?: string;
|
|
427
|
-
name?: string;
|
|
428
|
-
in?: 'query' | 'header' | 'cookie';
|
|
429
|
-
scheme?: string;
|
|
430
|
-
bearerFormat?: string;
|
|
431
|
-
flows?: Record<string, unknown>;
|
|
432
|
-
openIdConnectUrl?: string;
|
|
433
|
-
[key: string]: unknown;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// ============================================================
|
|
437
|
-
// API Info
|
|
438
|
-
// ============================================================
|
|
439
|
-
|
|
440
|
-
export const apiInfo = {
|
|
441
|
-
title: '${title}',
|
|
442
|
-
version: '${version}',${description ? `\n description: '${description.replace(/'/g, "\\'")}',` : ""}
|
|
443
|
-
} as const;
|
|
444
|
-
|
|
445
|
-
// ============================================================
|
|
446
|
-
// Security Schemes
|
|
447
|
-
// ============================================================
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Available security schemes for this API.
|
|
451
|
-
* Maps authorizer names to OpenAPI security scheme definitions.
|
|
452
|
-
*/
|
|
453
|
-
export const securitySchemes = ${JSON.stringify(securitySchemesObj, null, 2).replace(/"([a-zA-Z_$][a-zA-Z0-9_$]*)":/g, "$1:")} as const satisfies Record<string, SecuritySchemeObject>;
|
|
454
|
-
|
|
455
|
-
export type SecuritySchemeId = ${schemeNames || "never"};
|
|
456
|
-
|
|
457
|
-
// ============================================================
|
|
458
|
-
// Endpoint Authentication Map
|
|
459
|
-
// ============================================================
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Runtime map of endpoints to their required authentication scheme.
|
|
463
|
-
* \`null\` indicates a public endpoint (no auth required).
|
|
464
|
-
*/
|
|
465
|
-
export const endpointAuth = ${JSON.stringify(endpointAuth, null, 2).replace(/"([^"]+)":/g, "'$1':")} as const satisfies Record<string, SecuritySchemeId | null>;
|
|
466
|
-
|
|
467
|
-
export type EndpointString = keyof typeof endpointAuth;
|
|
468
|
-
|
|
469
|
-
export type AuthenticatedEndpoint = {
|
|
470
|
-
[K in EndpointString]: typeof endpointAuth[K] extends null ? never : K;
|
|
471
|
-
}[EndpointString];
|
|
472
|
-
|
|
473
|
-
export type PublicEndpoint = {
|
|
474
|
-
[K in EndpointString]: typeof endpointAuth[K] extends null ? K : never;
|
|
475
|
-
}[EndpointString];
|
|
476
|
-
|
|
477
|
-
// ============================================================
|
|
478
|
-
// Schema Definitions
|
|
479
|
-
// ============================================================
|
|
480
|
-
|
|
481
|
-
${schemaInterfaces}
|
|
482
|
-
|
|
483
|
-
// ============================================================
|
|
484
|
-
// OpenAPI Paths
|
|
485
|
-
// ============================================================
|
|
486
|
-
|
|
487
|
-
${pathsInterface}
|
|
488
|
-
${createApiSection}
|
|
489
|
-
`;
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
export { OpenApiTsGenerator };
|
|
495
|
-
//# sourceMappingURL=OpenApiTsGenerator-BVS4pOH7.mjs.map
|