@geekmidas/cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +63 -13
  2. package/dist/{CronGenerator-Ctl4USy4.cjs → CronGenerator-1PflEYe2.cjs} +8 -7
  3. package/dist/CronGenerator-1PflEYe2.cjs.map +1 -0
  4. package/dist/{CronGenerator-ClbRcmz_.mjs → CronGenerator-DXRfHQcV.mjs} +6 -5
  5. package/dist/CronGenerator-DXRfHQcV.mjs.map +1 -0
  6. package/dist/{EndpointGenerator-Dj7AumHi.cjs → EndpointGenerator-BbGrDiCP.cjs} +134 -34
  7. package/dist/EndpointGenerator-BbGrDiCP.cjs.map +1 -0
  8. package/dist/{EndpointGenerator-uBA1ixUw.mjs → EndpointGenerator-BmZ9BxbO.mjs} +132 -32
  9. package/dist/EndpointGenerator-BmZ9BxbO.mjs.map +1 -0
  10. package/dist/{FunctionGenerator-DN681IUn.cjs → FunctionGenerator-Clw64SwQ.cjs} +8 -7
  11. package/dist/FunctionGenerator-Clw64SwQ.cjs.map +1 -0
  12. package/dist/{FunctionGenerator-crAa-JC7.mjs → FunctionGenerator-DOEB_yPh.mjs} +6 -5
  13. package/dist/FunctionGenerator-DOEB_yPh.mjs.map +1 -0
  14. package/dist/{Generator-C3tYSTQY.cjs → Generator-CDoEXCDg.cjs} +2 -2
  15. package/dist/Generator-CDoEXCDg.cjs.map +1 -0
  16. package/dist/{Generator-CDt4pB3W.mjs → Generator-UanJW0_V.mjs} +1 -1
  17. package/dist/Generator-UanJW0_V.mjs.map +1 -0
  18. package/dist/SubscriberGenerator-BfMZCVNy.cjs +204 -0
  19. package/dist/SubscriberGenerator-BfMZCVNy.cjs.map +1 -0
  20. package/dist/SubscriberGenerator-D2u00NI3.mjs +198 -0
  21. package/dist/SubscriberGenerator-D2u00NI3.mjs.map +1 -0
  22. package/dist/build/index.cjs +10 -9
  23. package/dist/build/index.mjs +8 -7
  24. package/dist/build/manifests.cjs +1 -1
  25. package/dist/build/manifests.mjs +1 -1
  26. package/dist/build/providerResolver.cjs +1 -1
  27. package/dist/build-BBhlEjf5.cjs +89 -0
  28. package/dist/build-BBhlEjf5.cjs.map +1 -0
  29. package/dist/build-kY-lG30Q.mjs +83 -0
  30. package/dist/build-kY-lG30Q.mjs.map +1 -0
  31. package/dist/{chunk-CsX-DzYB.cjs → chunk-CUT6urMc.cjs} +0 -12
  32. package/dist/{config-RcNESK0T.cjs → config-D1EpSGk6.cjs} +2 -2
  33. package/dist/{config-RcNESK0T.cjs.map → config-D1EpSGk6.cjs.map} +1 -1
  34. package/dist/{config-CXxYmz_o.mjs → config-U-mdW-7Y.mjs} +1 -1
  35. package/dist/{config-CXxYmz_o.mjs.map → config-U-mdW-7Y.mjs.map} +1 -1
  36. package/dist/config.cjs +1 -1
  37. package/dist/config.mjs +1 -1
  38. package/dist/generators/CronGenerator.cjs +2 -2
  39. package/dist/generators/CronGenerator.mjs +2 -2
  40. package/dist/generators/EndpointGenerator.cjs +2 -2
  41. package/dist/generators/EndpointGenerator.mjs +2 -2
  42. package/dist/generators/FunctionGenerator.cjs +2 -2
  43. package/dist/generators/FunctionGenerator.mjs +2 -2
  44. package/dist/generators/Generator.cjs +1 -1
  45. package/dist/generators/Generator.mjs +1 -1
  46. package/dist/generators/SubscriberGenerator.cjs +4 -0
  47. package/dist/generators/SubscriberGenerator.mjs +4 -0
  48. package/dist/generators/index.cjs +8 -6
  49. package/dist/generators/index.mjs +6 -5
  50. package/dist/index.cjs +18 -14
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.mjs +15 -11
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/{manifests-HX4z4kkz.mjs → manifests-BrJXpHrf.mjs} +5 -4
  55. package/dist/manifests-BrJXpHrf.mjs.map +1 -0
  56. package/dist/{manifests-BTtfDMX8.cjs → manifests-D0saShvH.cjs} +6 -5
  57. package/dist/manifests-D0saShvH.cjs.map +1 -0
  58. package/dist/{openapi-BivnatiC.mjs → openapi-BQx3_JbM.mjs} +4 -4
  59. package/dist/openapi-BQx3_JbM.mjs.map +1 -0
  60. package/dist/{openapi-DW-qF3oW.cjs → openapi-CMLr04cz.cjs} +6 -6
  61. package/dist/openapi-CMLr04cz.cjs.map +1 -0
  62. package/dist/{openapi-react-query-lgS7AVEz.mjs → openapi-react-query-DbrWwQzb.mjs} +3 -2
  63. package/dist/openapi-react-query-DbrWwQzb.mjs.map +1 -0
  64. package/dist/{openapi-react-query-J0BzBHhN.cjs → openapi-react-query-Dvjqx_Eo.cjs} +4 -3
  65. package/dist/openapi-react-query-Dvjqx_Eo.cjs.map +1 -0
  66. package/dist/openapi-react-query.cjs +1 -1
  67. package/dist/openapi-react-query.mjs +1 -1
  68. package/dist/openapi.cjs +4 -4
  69. package/dist/openapi.mjs +4 -4
  70. package/dist/{providerResolver-Cs-0YCaP.cjs → providerResolver-DgvzNfP4.cjs} +1 -1
  71. package/dist/{providerResolver-Cs-0YCaP.cjs.map → providerResolver-DgvzNfP4.cjs.map} +1 -1
  72. package/examples/cron-example.ts +1 -1
  73. package/examples/function-example.ts +1 -1
  74. package/examples/logger.ts +1 -1
  75. package/package.json +6 -3
  76. package/src/__tests__/openapi-react-query.spec.ts +506 -0
  77. package/src/__tests__/openapi.spec.ts +362 -0
  78. package/src/__tests__/test-helpers.ts +10 -8
  79. package/src/build/__tests__/index-new.spec.ts +41 -42
  80. package/src/build/index.ts +89 -28
  81. package/src/build/manifests.ts +4 -1
  82. package/src/build/types.ts +2 -2
  83. package/src/generators/CronGenerator.ts +3 -2
  84. package/src/generators/EndpointGenerator.ts +141 -42
  85. package/src/generators/FunctionGenerator.ts +3 -2
  86. package/src/generators/Generator.ts +1 -1
  87. package/src/generators/SubscriberGenerator.ts +271 -0
  88. package/src/generators/__tests__/CronGenerator.spec.ts +1 -1
  89. package/src/generators/__tests__/EndpointGenerator.spec.ts +33 -11
  90. package/src/generators/__tests__/FunctionGenerator.spec.ts +21 -22
  91. package/src/generators/__tests__/SubscriberGenerator.spec.ts +341 -0
  92. package/src/generators/index.ts +1 -0
  93. package/src/openapi-react-query.ts +2 -1
  94. package/src/openapi.ts +1 -1
  95. package/src/types.ts +18 -0
  96. package/dist/CronGenerator-ClbRcmz_.mjs.map +0 -1
  97. package/dist/CronGenerator-Ctl4USy4.cjs.map +0 -1
  98. package/dist/EndpointGenerator-Dj7AumHi.cjs.map +0 -1
  99. package/dist/EndpointGenerator-uBA1ixUw.mjs.map +0 -1
  100. package/dist/FunctionGenerator-DN681IUn.cjs.map +0 -1
  101. package/dist/FunctionGenerator-crAa-JC7.mjs.map +0 -1
  102. package/dist/Generator-C3tYSTQY.cjs.map +0 -1
  103. package/dist/Generator-CDt4pB3W.mjs.map +0 -1
  104. package/dist/__tests__/config.spec.cjs +0 -98
  105. package/dist/__tests__/config.spec.cjs.map +0 -1
  106. package/dist/__tests__/config.spec.mjs +0 -97
  107. package/dist/__tests__/config.spec.mjs.map +0 -1
  108. package/dist/__tests__/test-helpers.cjs +0 -14
  109. package/dist/__tests__/test-helpers.mjs +0 -4
  110. package/dist/build/__tests__/index-new.spec.cjs +0 -286
  111. package/dist/build/__tests__/index-new.spec.cjs.map +0 -1
  112. package/dist/build/__tests__/index-new.spec.mjs +0 -285
  113. package/dist/build/__tests__/index-new.spec.mjs.map +0 -1
  114. package/dist/build-BZdwxCLW.mjs +0 -64
  115. package/dist/build-BZdwxCLW.mjs.map +0 -1
  116. package/dist/build-BfQFnU5-.cjs +0 -70
  117. package/dist/build-BfQFnU5-.cjs.map +0 -1
  118. package/dist/esm-9eeZntth.mjs +0 -3777
  119. package/dist/esm-9eeZntth.mjs.map +0 -1
  120. package/dist/esm-Crmo4h9t.cjs +0 -4392
  121. package/dist/esm-Crmo4h9t.cjs.map +0 -1
  122. package/dist/esm-CsJbr7gi.mjs +0 -3
  123. package/dist/esm-w09tAC4l.cjs +0 -8
  124. package/dist/generators/__tests__/CronGenerator.spec.cjs +0 -216
  125. package/dist/generators/__tests__/CronGenerator.spec.cjs.map +0 -1
  126. package/dist/generators/__tests__/CronGenerator.spec.mjs +0 -215
  127. package/dist/generators/__tests__/CronGenerator.spec.mjs.map +0 -1
  128. package/dist/generators/__tests__/EndpointGenerator.spec.cjs +0 -182
  129. package/dist/generators/__tests__/EndpointGenerator.spec.cjs.map +0 -1
  130. package/dist/generators/__tests__/EndpointGenerator.spec.mjs +0 -181
  131. package/dist/generators/__tests__/EndpointGenerator.spec.mjs.map +0 -1
  132. package/dist/generators/__tests__/FunctionGenerator.spec.cjs +0 -152
  133. package/dist/generators/__tests__/FunctionGenerator.spec.cjs.map +0 -1
  134. package/dist/generators/__tests__/FunctionGenerator.spec.mjs +0 -151
  135. package/dist/generators/__tests__/FunctionGenerator.spec.mjs.map +0 -1
  136. package/dist/manifests-BTtfDMX8.cjs.map +0 -1
  137. package/dist/manifests-HX4z4kkz.mjs.map +0 -1
  138. package/dist/openapi-BivnatiC.mjs.map +0 -1
  139. package/dist/openapi-DW-qF3oW.cjs.map +0 -1
  140. package/dist/openapi-react-query-J0BzBHhN.cjs.map +0 -1
  141. package/dist/openapi-react-query-lgS7AVEz.mjs.map +0 -1
  142. package/dist/test-helpers-ARd8GDgx.cjs +0 -199
  143. package/dist/test-helpers-ARd8GDgx.cjs.map +0 -1
  144. package/dist/test-helpers-DdVBk23F.mjs +0 -133
  145. package/dist/test-helpers-DdVBk23F.mjs.map +0 -1
  146. /package/dist/{generators-_pY7sHy1.cjs → generators-CEKtVh81.cjs} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"FunctionGenerator.spec.cjs","names":["tempDir: string","outputDir: string","generator: FunctionGenerator","context: ReturnType<typeof createMockBuildContext>","FunctionGenerator","FunctionBuilder","key: string","timeout: number","construct: GeneratedConstruct<Function<any, any, any, any>>"],"sources":["../../../src/generators/__tests__/FunctionGenerator.spec.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { type Function, FunctionBuilder } from '@geekmidas/api/constructs';\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';\nimport {\n cleanupDir,\n createMockBuildContext,\n createTempDir,\n} from '../../__tests__/test-helpers';\nimport { FunctionGenerator } from '../FunctionGenerator';\nimport type { GeneratedConstruct } from '../Generator';\n\ndescribe('FunctionGenerator', () => {\n let tempDir: string;\n let outputDir: string;\n let generator: FunctionGenerator;\n let context: ReturnType<typeof createMockBuildContext>;\n\n beforeEach(async () => {\n tempDir = await createTempDir();\n outputDir = join(tempDir, 'output');\n generator = new FunctionGenerator();\n context = createMockBuildContext();\n });\n\n afterEach(async () => {\n await cleanupDir(tempDir);\n });\n\n describe('isConstruct', () => {\n it('should identify valid functions', async () => {\n // Import the actual FunctionBuilder to create a real Function instance\n\n const { z } = await import('zod');\n\n const testFunction = new FunctionBuilder()\n .input(z.object({ name: z.string() }))\n .output(z.object({ greeting: z.string() }))\n .timeout(30)\n .handle(async ({ input }: any) => ({\n greeting: `Hello, ${input.name}!`,\n }));\n\n expect(generator.isConstruct(testFunction)).toBe(true);\n });\n\n it('should reject invalid constructs', () => {\n expect(generator.isConstruct({})).toBe(false);\n expect(generator.isConstruct('string')).toBe(false);\n expect(generator.isConstruct(null)).toBe(false);\n });\n });\n\n describe('build', () => {\n const createTestFunctionConstruct = (\n key: string,\n timeout: number = 30,\n ): GeneratedConstruct<Function<any, any, any, any>> => ({\n key,\n name: key.toLowerCase(),\n construct: {\n __IS_FUNCTION__: true,\n type: 'dev.geekmidas.function.function',\n timeout,\n handle: async () => ({ greeting: 'Hello!' }),\n } as any,\n path: {\n absolute: join(tempDir, `${key}.ts`),\n relative: `${key}.ts`,\n },\n });\n\n describe('aws-lambda provider', () => {\n it('should generate function handlers', async () => {\n const constructs = [\n createTestFunctionConstruct('processData', 60),\n createTestFunctionConstruct('sendEmail', 30),\n ];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-lambda' },\n );\n\n expect(functionInfos).toHaveLength(2);\n expect(functionInfos[0]).toMatchObject({\n name: 'processData',\n handler: expect.stringContaining('functions/processData.handler'),\n timeout: 60,\n });\n expect(functionInfos[1]).toMatchObject({\n name: 'sendEmail',\n handler: expect.stringContaining('functions/sendEmail.handler'),\n timeout: 30,\n });\n\n // Check that handler files were created\n const processDataHandlerPath = join(\n outputDir,\n 'functions',\n 'processData.ts',\n );\n const processDataContent = await readFile(\n processDataHandlerPath,\n 'utf-8',\n );\n expect(processDataContent).toContain('AWSLambdaFunction');\n expect(processDataContent).toContain('import { processData }');\n expect(processDataContent).toContain('import envParser');\n expect(processDataContent).toContain('import logger');\n\n const sendEmailHandlerPath = join(\n outputDir,\n 'functions',\n 'sendEmail.ts',\n );\n const sendEmailContent = await readFile(sendEmailHandlerPath, 'utf-8');\n expect(sendEmailContent).toContain('AWSLambdaFunction');\n expect(sendEmailContent).toContain('import { sendEmail }');\n });\n\n it('should generate correct relative import paths', async () => {\n const construct: GeneratedConstruct<Function<any, any, any, any>> = {\n key: 'deepFunction',\n name: 'deep-function',\n construct: createTestFunctionConstruct('deepFunction', 45).construct,\n path: {\n absolute: join(tempDir, 'src/functions/deep/processor.ts'),\n relative: 'src/functions/deep/processor.ts',\n },\n };\n\n await generator.build(context, [construct], outputDir, {\n provider: 'aws-lambda',\n });\n\n const handlerPath = join(outputDir, 'functions', 'deepFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n\n // Check relative imports are correct - the path will be relative from outputDir\n expect(handlerContent).toMatch(\n /from ['\"].*src\\/functions\\/deep\\/processor\\.js['\"]/,\n );\n expect(handlerContent).toMatch(/from ['\"].*\\/env['\"]/);\n expect(handlerContent).toMatch(/from ['\"].*\\/logger['\"]/);\n });\n\n it('should log generation progress', async () => {\n const logSpy = vi.spyOn(console, 'log');\n\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n await generator.build(context, constructs, outputDir, {\n provider: 'aws-lambda',\n });\n\n expect(logSpy).toHaveBeenCalledWith(\n 'Generated function handler: testFunction',\n );\n\n logSpy.mockRestore();\n });\n });\n\n describe('non aws-lambda provider', () => {\n it('should return empty array for server provider', async () => {\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'server' },\n );\n\n expect(functionInfos).toEqual([]);\n });\n\n it('should return empty array for aws-apigatewayv1 provider', async () => {\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-apigatewayv1' },\n );\n\n expect(functionInfos).toEqual([]);\n });\n });\n\n it('should return empty array for empty constructs', async () => {\n const functionInfos = await generator.build(context, [], outputDir, {\n provider: 'aws-lambda',\n });\n expect(functionInfos).toEqual([]);\n });\n\n it('should use default provider when none specified', async () => {\n const constructs = [createTestFunctionConstruct('defaultFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n );\n\n expect(functionInfos).toHaveLength(1);\n expect(functionInfos[0].name).toBe('defaultFunction');\n\n // Check that handler was created (default is aws-lambda)\n const handlerPath = join(outputDir, 'functions', 'defaultFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n expect(handlerContent).toContain('AWSLambdaFunction');\n });\n\n it('should handle functions with different timeout values', async () => {\n const constructs = [\n createTestFunctionConstruct('quickFunction', 15),\n createTestFunctionConstruct('slowFunction', 300),\n ];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-lambda' },\n );\n\n expect(functionInfos[0].timeout).toBe(15);\n expect(functionInfos[1].timeout).toBe(300);\n });\n\n it('should handle functions with custom environment parser patterns', async () => {\n const customContext = {\n ...context,\n envParserImportPattern: '{ customParser as envParser }',\n loggerImportPattern: '{ customLogger as logger }',\n };\n\n const constructs = [createTestFunctionConstruct('customFunction', 30)];\n\n await generator.build(customContext, constructs, outputDir, {\n provider: 'aws-lambda',\n });\n\n const handlerPath = join(outputDir, 'functions', 'customFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n\n expect(handlerContent).toContain('import { customParser as envParser }');\n expect(handlerContent).toContain('import { customLogger as logger }');\n });\n });\n});\n"],"mappings":";;;;;;;;;;;AAYA,qBAAS,qBAAqB,MAAM;CAClC,IAAIA;CACJ,IAAIC;CACJ,IAAIC;CACJ,IAAIC;AAEJ,wBAAW,YAAY;AACrB,YAAU,MAAM,oCAAe;AAC/B,cAAY,oBAAK,SAAS,SAAS;AACnC,cAAY,IAAIC;AAChB,YAAU,6CAAwB;CACnC,EAAC;AAEF,uBAAU,YAAY;AACpB,QAAM,gCAAW,QAAQ;CAC1B,EAAC;AAEF,sBAAS,eAAe,MAAM;AAC5B,iBAAG,mCAAmC,YAAY;GAGhD,MAAM,EAAE,GAAG,GAAG,2CAAM;GAEpB,MAAM,eAAe,IAAIC,6CACtB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAE,EAAC,CAAC,CACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAE,EAAC,CAAC,CAC1C,QAAQ,GAAG,CACX,OAAO,OAAO,EAAE,OAAY,MAAM,EACjC,WAAW,SAAS,MAAM,KAAK,GAChC,GAAE;AAEL,sBAAO,UAAU,YAAY,aAAa,CAAC,CAAC,KAAK,KAAK;EACvD,EAAC;AAEF,iBAAG,oCAAoC,MAAM;AAC3C,sBAAO,UAAU,YAAY,CAAE,EAAC,CAAC,CAAC,KAAK,MAAM;AAC7C,sBAAO,UAAU,YAAY,SAAS,CAAC,CAAC,KAAK,MAAM;AACnD,sBAAO,UAAU,YAAY,KAAK,CAAC,CAAC,KAAK,MAAM;EAChD,EAAC;CACH,EAAC;AAEF,sBAAS,SAAS,MAAM;EACtB,MAAM,8BAA8B,CAClCC,KACAC,UAAkB,QACoC;GACtD;GACA,MAAM,IAAI,aAAa;GACvB,WAAW;IACT,iBAAiB;IACjB,MAAM;IACN;IACA,QAAQ,aAAa,EAAE,UAAU,SAAU;GAC5C;GACD,MAA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MAAM,gBAAgB,MAAM,UAAU,MACpC,SACA,YACA,UACD;AAED,sBAAO,cAAc,CAAC,aAAa,EAAE;AACrC,sBAAO,cAAc,GAAG,KAAK,CAAC,KAAK,kBAAkB;GAGrD,MAAM,cAAc,oBAAK,WAAW,aAAa,qBAAqB;GACtE,MAAM,iBAAiB,MAAM,+BAAS,aAAa,QAAQ;AAC3D,sBAAO,eAAe,CAAC,UAAU,oBAAoB;EACtD,EAAC;AAEF,iBAAG,yDAAyD,YAAY;GACtE,MAAM,aAAa,CACjB,4BAA4B,iBAAiB,GAAG,EAChD,4BAA4B,gBAAgB,IAAI,AACjD;GAED,MAAM,gBAAgB,MAAM,UAAU,MACpC,SACA,YACA,WACA,EAAE,UAAU,aAAc,EAC3B;AAED,sBAAO,cAAc,GAAG,QAAQ,CAAC,KAAK,GAAG;AACzC,sBAAO,cAAc,GAAG,QAAQ,CAAC,KAAK,IAAI;EAC3C,EAAC;AAEF,iBAAG,mEAAmE,YAAY;GAChF,MAAM,gBAAgB;IACpB,GAAG;IACH,wBAAwB;IACxB,qBAAqB;GACtB;GAED,MAAM,aAAa,CAAC,4BAA4B,kBAAkB,GAAG,AAAC;AAEtE,SAAM,UAAU,MAAM,eAAe,YAAY,WAAW,EAC1D,UAAU,aACX,EAAC;GAEF,MAAM,cAAc,oBAAK,WAAW,aAAa,oBAAoB;GACrE,MAAM,iBAAiB,MAAM,+BAAS,aAAa,QAAQ;AAE3D,sBAAO,eAAe,CAAC,UAAU,uCAAuC;AACxE,sBAAO,eAAe,CAAC,UAAU,oCAAoC;EACtE,EAAC;CACH,EAAC;AACH,EAAC"}
@@ -1,151 +0,0 @@
1
- import "../../esm-9eeZntth.mjs";
2
- import "../../Generator-CDt4pB3W.mjs";
3
- import { FunctionGenerator } from "../../FunctionGenerator-crAa-JC7.mjs";
4
- import { cleanupDir, createMockBuildContext, createTempDir } from "../../test-helpers-DdVBk23F.mjs";
5
- import { readFile } from "node:fs/promises";
6
- import { join } from "node:path";
7
- import { FunctionBuilder } from "@geekmidas/api/constructs";
8
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
9
-
10
- //#region src/generators/__tests__/FunctionGenerator.spec.ts
11
- describe("FunctionGenerator", () => {
12
- let tempDir;
13
- let outputDir;
14
- let generator;
15
- let context;
16
- beforeEach(async () => {
17
- tempDir = await createTempDir();
18
- outputDir = join(tempDir, "output");
19
- generator = new FunctionGenerator();
20
- context = createMockBuildContext();
21
- });
22
- afterEach(async () => {
23
- await cleanupDir(tempDir);
24
- });
25
- describe("isConstruct", () => {
26
- it("should identify valid functions", async () => {
27
- const { z } = await import("../../esm-CsJbr7gi.mjs");
28
- const testFunction = new FunctionBuilder().input(z.object({ name: z.string() })).output(z.object({ greeting: z.string() })).timeout(30).handle(async ({ input }) => ({ greeting: `Hello, ${input.name}!` }));
29
- expect(generator.isConstruct(testFunction)).toBe(true);
30
- });
31
- it("should reject invalid constructs", () => {
32
- expect(generator.isConstruct({})).toBe(false);
33
- expect(generator.isConstruct("string")).toBe(false);
34
- expect(generator.isConstruct(null)).toBe(false);
35
- });
36
- });
37
- describe("build", () => {
38
- const createTestFunctionConstruct = (key, timeout = 30) => ({
39
- key,
40
- name: key.toLowerCase(),
41
- construct: {
42
- __IS_FUNCTION__: true,
43
- type: "dev.geekmidas.function.function",
44
- timeout,
45
- handle: async () => ({ greeting: "Hello!" })
46
- },
47
- path: {
48
- absolute: join(tempDir, `${key}.ts`),
49
- relative: `${key}.ts`
50
- }
51
- });
52
- describe("aws-lambda provider", () => {
53
- it("should generate function handlers", async () => {
54
- const constructs = [createTestFunctionConstruct("processData", 60), createTestFunctionConstruct("sendEmail", 30)];
55
- const functionInfos = await generator.build(context, constructs, outputDir, { provider: "aws-lambda" });
56
- expect(functionInfos).toHaveLength(2);
57
- expect(functionInfos[0]).toMatchObject({
58
- name: "processData",
59
- handler: expect.stringContaining("functions/processData.handler"),
60
- timeout: 60
61
- });
62
- expect(functionInfos[1]).toMatchObject({
63
- name: "sendEmail",
64
- handler: expect.stringContaining("functions/sendEmail.handler"),
65
- timeout: 30
66
- });
67
- const processDataHandlerPath = join(outputDir, "functions", "processData.ts");
68
- const processDataContent = await readFile(processDataHandlerPath, "utf-8");
69
- expect(processDataContent).toContain("AWSLambdaFunction");
70
- expect(processDataContent).toContain("import { processData }");
71
- expect(processDataContent).toContain("import envParser");
72
- expect(processDataContent).toContain("import logger");
73
- const sendEmailHandlerPath = join(outputDir, "functions", "sendEmail.ts");
74
- const sendEmailContent = await readFile(sendEmailHandlerPath, "utf-8");
75
- expect(sendEmailContent).toContain("AWSLambdaFunction");
76
- expect(sendEmailContent).toContain("import { sendEmail }");
77
- });
78
- it("should generate correct relative import paths", async () => {
79
- const construct = {
80
- key: "deepFunction",
81
- name: "deep-function",
82
- construct: createTestFunctionConstruct("deepFunction", 45).construct,
83
- path: {
84
- absolute: join(tempDir, "src/functions/deep/processor.ts"),
85
- relative: "src/functions/deep/processor.ts"
86
- }
87
- };
88
- await generator.build(context, [construct], outputDir, { provider: "aws-lambda" });
89
- const handlerPath = join(outputDir, "functions", "deepFunction.ts");
90
- const handlerContent = await readFile(handlerPath, "utf-8");
91
- expect(handlerContent).toMatch(/from ['"].*src\/functions\/deep\/processor\.js['"]/);
92
- expect(handlerContent).toMatch(/from ['"].*\/env['"]/);
93
- expect(handlerContent).toMatch(/from ['"].*\/logger['"]/);
94
- });
95
- it("should log generation progress", async () => {
96
- const logSpy = vi.spyOn(console, "log");
97
- const constructs = [createTestFunctionConstruct("testFunction", 30)];
98
- await generator.build(context, constructs, outputDir, { provider: "aws-lambda" });
99
- expect(logSpy).toHaveBeenCalledWith("Generated function handler: testFunction");
100
- logSpy.mockRestore();
101
- });
102
- });
103
- describe("non aws-lambda provider", () => {
104
- it("should return empty array for server provider", async () => {
105
- const constructs = [createTestFunctionConstruct("testFunction", 30)];
106
- const functionInfos = await generator.build(context, constructs, outputDir, { provider: "server" });
107
- expect(functionInfos).toEqual([]);
108
- });
109
- it("should return empty array for aws-apigatewayv1 provider", async () => {
110
- const constructs = [createTestFunctionConstruct("testFunction", 30)];
111
- const functionInfos = await generator.build(context, constructs, outputDir, { provider: "aws-apigatewayv1" });
112
- expect(functionInfos).toEqual([]);
113
- });
114
- });
115
- it("should return empty array for empty constructs", async () => {
116
- const functionInfos = await generator.build(context, [], outputDir, { provider: "aws-lambda" });
117
- expect(functionInfos).toEqual([]);
118
- });
119
- it("should use default provider when none specified", async () => {
120
- const constructs = [createTestFunctionConstruct("defaultFunction", 30)];
121
- const functionInfos = await generator.build(context, constructs, outputDir);
122
- expect(functionInfos).toHaveLength(1);
123
- expect(functionInfos[0].name).toBe("defaultFunction");
124
- const handlerPath = join(outputDir, "functions", "defaultFunction.ts");
125
- const handlerContent = await readFile(handlerPath, "utf-8");
126
- expect(handlerContent).toContain("AWSLambdaFunction");
127
- });
128
- it("should handle functions with different timeout values", async () => {
129
- const constructs = [createTestFunctionConstruct("quickFunction", 15), createTestFunctionConstruct("slowFunction", 300)];
130
- const functionInfos = await generator.build(context, constructs, outputDir, { provider: "aws-lambda" });
131
- expect(functionInfos[0].timeout).toBe(15);
132
- expect(functionInfos[1].timeout).toBe(300);
133
- });
134
- it("should handle functions with custom environment parser patterns", async () => {
135
- const customContext = {
136
- ...context,
137
- envParserImportPattern: "{ customParser as envParser }",
138
- loggerImportPattern: "{ customLogger as logger }"
139
- };
140
- const constructs = [createTestFunctionConstruct("customFunction", 30)];
141
- await generator.build(customContext, constructs, outputDir, { provider: "aws-lambda" });
142
- const handlerPath = join(outputDir, "functions", "customFunction.ts");
143
- const handlerContent = await readFile(handlerPath, "utf-8");
144
- expect(handlerContent).toContain("import { customParser as envParser }");
145
- expect(handlerContent).toContain("import { customLogger as logger }");
146
- });
147
- });
148
- });
149
-
150
- //#endregion
151
- //# sourceMappingURL=FunctionGenerator.spec.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FunctionGenerator.spec.mjs","names":["tempDir: string","outputDir: string","generator: FunctionGenerator","context: ReturnType<typeof createMockBuildContext>","key: string","timeout: number","construct: GeneratedConstruct<Function<any, any, any, any>>"],"sources":["../../../src/generators/__tests__/FunctionGenerator.spec.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { type Function, FunctionBuilder } from '@geekmidas/api/constructs';\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';\nimport {\n cleanupDir,\n createMockBuildContext,\n createTempDir,\n} from '../../__tests__/test-helpers';\nimport { FunctionGenerator } from '../FunctionGenerator';\nimport type { GeneratedConstruct } from '../Generator';\n\ndescribe('FunctionGenerator', () => {\n let tempDir: string;\n let outputDir: string;\n let generator: FunctionGenerator;\n let context: ReturnType<typeof createMockBuildContext>;\n\n beforeEach(async () => {\n tempDir = await createTempDir();\n outputDir = join(tempDir, 'output');\n generator = new FunctionGenerator();\n context = createMockBuildContext();\n });\n\n afterEach(async () => {\n await cleanupDir(tempDir);\n });\n\n describe('isConstruct', () => {\n it('should identify valid functions', async () => {\n // Import the actual FunctionBuilder to create a real Function instance\n\n const { z } = await import('zod');\n\n const testFunction = new FunctionBuilder()\n .input(z.object({ name: z.string() }))\n .output(z.object({ greeting: z.string() }))\n .timeout(30)\n .handle(async ({ input }: any) => ({\n greeting: `Hello, ${input.name}!`,\n }));\n\n expect(generator.isConstruct(testFunction)).toBe(true);\n });\n\n it('should reject invalid constructs', () => {\n expect(generator.isConstruct({})).toBe(false);\n expect(generator.isConstruct('string')).toBe(false);\n expect(generator.isConstruct(null)).toBe(false);\n });\n });\n\n describe('build', () => {\n const createTestFunctionConstruct = (\n key: string,\n timeout: number = 30,\n ): GeneratedConstruct<Function<any, any, any, any>> => ({\n key,\n name: key.toLowerCase(),\n construct: {\n __IS_FUNCTION__: true,\n type: 'dev.geekmidas.function.function',\n timeout,\n handle: async () => ({ greeting: 'Hello!' }),\n } as any,\n path: {\n absolute: join(tempDir, `${key}.ts`),\n relative: `${key}.ts`,\n },\n });\n\n describe('aws-lambda provider', () => {\n it('should generate function handlers', async () => {\n const constructs = [\n createTestFunctionConstruct('processData', 60),\n createTestFunctionConstruct('sendEmail', 30),\n ];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-lambda' },\n );\n\n expect(functionInfos).toHaveLength(2);\n expect(functionInfos[0]).toMatchObject({\n name: 'processData',\n handler: expect.stringContaining('functions/processData.handler'),\n timeout: 60,\n });\n expect(functionInfos[1]).toMatchObject({\n name: 'sendEmail',\n handler: expect.stringContaining('functions/sendEmail.handler'),\n timeout: 30,\n });\n\n // Check that handler files were created\n const processDataHandlerPath = join(\n outputDir,\n 'functions',\n 'processData.ts',\n );\n const processDataContent = await readFile(\n processDataHandlerPath,\n 'utf-8',\n );\n expect(processDataContent).toContain('AWSLambdaFunction');\n expect(processDataContent).toContain('import { processData }');\n expect(processDataContent).toContain('import envParser');\n expect(processDataContent).toContain('import logger');\n\n const sendEmailHandlerPath = join(\n outputDir,\n 'functions',\n 'sendEmail.ts',\n );\n const sendEmailContent = await readFile(sendEmailHandlerPath, 'utf-8');\n expect(sendEmailContent).toContain('AWSLambdaFunction');\n expect(sendEmailContent).toContain('import { sendEmail }');\n });\n\n it('should generate correct relative import paths', async () => {\n const construct: GeneratedConstruct<Function<any, any, any, any>> = {\n key: 'deepFunction',\n name: 'deep-function',\n construct: createTestFunctionConstruct('deepFunction', 45).construct,\n path: {\n absolute: join(tempDir, 'src/functions/deep/processor.ts'),\n relative: 'src/functions/deep/processor.ts',\n },\n };\n\n await generator.build(context, [construct], outputDir, {\n provider: 'aws-lambda',\n });\n\n const handlerPath = join(outputDir, 'functions', 'deepFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n\n // Check relative imports are correct - the path will be relative from outputDir\n expect(handlerContent).toMatch(\n /from ['\"].*src\\/functions\\/deep\\/processor\\.js['\"]/,\n );\n expect(handlerContent).toMatch(/from ['\"].*\\/env['\"]/);\n expect(handlerContent).toMatch(/from ['\"].*\\/logger['\"]/);\n });\n\n it('should log generation progress', async () => {\n const logSpy = vi.spyOn(console, 'log');\n\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n await generator.build(context, constructs, outputDir, {\n provider: 'aws-lambda',\n });\n\n expect(logSpy).toHaveBeenCalledWith(\n 'Generated function handler: testFunction',\n );\n\n logSpy.mockRestore();\n });\n });\n\n describe('non aws-lambda provider', () => {\n it('should return empty array for server provider', async () => {\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'server' },\n );\n\n expect(functionInfos).toEqual([]);\n });\n\n it('should return empty array for aws-apigatewayv1 provider', async () => {\n const constructs = [createTestFunctionConstruct('testFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-apigatewayv1' },\n );\n\n expect(functionInfos).toEqual([]);\n });\n });\n\n it('should return empty array for empty constructs', async () => {\n const functionInfos = await generator.build(context, [], outputDir, {\n provider: 'aws-lambda',\n });\n expect(functionInfos).toEqual([]);\n });\n\n it('should use default provider when none specified', async () => {\n const constructs = [createTestFunctionConstruct('defaultFunction', 30)];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n );\n\n expect(functionInfos).toHaveLength(1);\n expect(functionInfos[0].name).toBe('defaultFunction');\n\n // Check that handler was created (default is aws-lambda)\n const handlerPath = join(outputDir, 'functions', 'defaultFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n expect(handlerContent).toContain('AWSLambdaFunction');\n });\n\n it('should handle functions with different timeout values', async () => {\n const constructs = [\n createTestFunctionConstruct('quickFunction', 15),\n createTestFunctionConstruct('slowFunction', 300),\n ];\n\n const functionInfos = await generator.build(\n context,\n constructs,\n outputDir,\n { provider: 'aws-lambda' },\n );\n\n expect(functionInfos[0].timeout).toBe(15);\n expect(functionInfos[1].timeout).toBe(300);\n });\n\n it('should handle functions with custom environment parser patterns', async () => {\n const customContext = {\n ...context,\n envParserImportPattern: '{ customParser as envParser }',\n loggerImportPattern: '{ customLogger as logger }',\n };\n\n const constructs = [createTestFunctionConstruct('customFunction', 30)];\n\n await generator.build(customContext, constructs, outputDir, {\n provider: 'aws-lambda',\n });\n\n const handlerPath = join(outputDir, 'functions', 'customFunction.ts');\n const handlerContent = await readFile(handlerPath, 'utf-8');\n\n expect(handlerContent).toContain('import { customParser as envParser }');\n expect(handlerContent).toContain('import { customLogger as logger }');\n });\n });\n});\n"],"mappings":";;;;;;;;;;AAYA,SAAS,qBAAqB,MAAM;CAClC,IAAIA;CACJ,IAAIC;CACJ,IAAIC;CACJ,IAAIC;AAEJ,YAAW,YAAY;AACrB,YAAU,MAAM,eAAe;AAC/B,cAAY,KAAK,SAAS,SAAS;AACnC,cAAY,IAAI;AAChB,YAAU,wBAAwB;CACnC,EAAC;AAEF,WAAU,YAAY;AACpB,QAAM,WAAW,QAAQ;CAC1B,EAAC;AAEF,UAAS,eAAe,MAAM;AAC5B,KAAG,mCAAmC,YAAY;GAGhD,MAAM,EAAE,GAAG,GAAG,MAAM,OAAO;GAE3B,MAAM,eAAe,IAAI,kBACtB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAE,EAAC,CAAC,CACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAE,EAAC,CAAC,CAC1C,QAAQ,GAAG,CACX,OAAO,OAAO,EAAE,OAAY,MAAM,EACjC,WAAW,SAAS,MAAM,KAAK,GAChC,GAAE;AAEL,UAAO,UAAU,YAAY,aAAa,CAAC,CAAC,KAAK,KAAK;EACvD,EAAC;AAEF,KAAG,oCAAoC,MAAM;AAC3C,UAAO,UAAU,YAAY,CAAE,EAAC,CAAC,CAAC,KAAK,MAAM;AAC7C,UAAO,UAAU,YAAY,SAAS,CAAC,CAAC,KAAK,MAAM;AACnD,UAAO,UAAU,YAAY,KAAK,CAAC,CAAC,KAAK,MAAM;EAChD,EAAC;CACH,EAAC;AAEF,UAAS,SAAS,MAAM;EACtB,MAAM,8BAA8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,CAAE,EAAC;EAClC,EAAC;AAEF,KAAG,mDAAmD,YAAY;GAChE,MAAM,aAAa,CAAC,4BAA4B,mBAAmB,GAAG,AAAC;GAEvE,MAAM,gBAAgB,MAAM,UAAU,MACpC,SACA,YACA,UACD;AAED,UAAO,cAAc,CAAC,aAAa,EAAE;AACrC,UAAO,cAAc,GAAG,KAAK,CAAC,KAAK,kBAAkB;GAGrD,MAAM,cAAc,KAAK,WAAW,aAAa,qBAAqB;GACtE,MAAM,iBAAiB,MAAM,SAAS,aAAa,QAAQ;AAC3D,UAAO,eAAe,CAAC,UAAU,oBAAoB;EACtD,EAAC;AAEF,KAAG,yDAAyD,YAAY;GACtE,MAAM,aAAa,CACjB,4BAA4B,iBAAiB,GAAG,EAChD,4BAA4B,gBAAgB,IAAI,AACjD;GAED,MAAM,gBAAgB,MAAM,UAAU,MACpC,SACA,YACA,WACA,EAAE,UAAU,aAAc,EAC3B;AAED,UAAO,cAAc,GAAG,QAAQ,CAAC,KAAK,GAAG;AACzC,UAAO,cAAc,GAAG,QAAQ,CAAC,KAAK,IAAI;EAC3C,EAAC;AAEF,KAAG,mEAAmE,YAAY;GAChF,MAAM,gBAAgB;IACpB,GAAG;IACH,wBAAwB;IACxB,qBAAqB;GACtB;GAED,MAAM,aAAa,CAAC,4BAA4B,kBAAkB,GAAG,AAAC;AAEtE,SAAM,UAAU,MAAM,eAAe,YAAY,WAAW,EAC1D,UAAU,aACX,EAAC;GAEF,MAAM,cAAc,KAAK,WAAW,aAAa,oBAAoB;GACrE,MAAM,iBAAiB,MAAM,SAAS,aAAa,QAAQ;AAE3D,UAAO,eAAe,CAAC,UAAU,uCAAuC;AACxE,UAAO,eAAe,CAAC,UAAU,oCAAoC;EACtE,EAAC;CACH,EAAC;AACH,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifests-BTtfDMX8.cjs","names":["outputDir: string","routes: RouteInfo[]","functions: FunctionInfo[]","crons: CronInfo[]","manifest: BuildManifest"],"sources":["../src/build/manifests.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'path';\nimport type {\n BuildManifest,\n CronInfo,\n FunctionInfo,\n RouteInfo,\n} from '../types';\n\nconst logger = console;\n\nexport async function generateManifests(\n outputDir: string,\n routes: RouteInfo[],\n functions: FunctionInfo[],\n crons: CronInfo[],\n): Promise<void> {\n // Generate unified manifest for all providers\n const manifest: BuildManifest = {\n routes,\n functions,\n crons,\n };\n\n const manifestPath = join(outputDir, 'manifest.json');\n await writeFile(manifestPath, JSON.stringify(manifest, null, 2));\n\n logger.log(\n `Generated ${routes.length} routes, ${functions.length} functions, ${crons.length} crons in ${relative(process.cwd(), outputDir)}`,\n );\n logger.log(`Manifest: ${relative(process.cwd(), manifestPath)}`);\n}\n"],"mappings":";;;;;AASA,MAAM,SAAS;AAEf,eAAsB,kBACpBA,WACAC,QACAC,WACAC,OACe;CAEf,MAAMC,WAA0B;EAC9B;EACA;EACA;CACD;CAED,MAAM,eAAe,eAAK,WAAW,gBAAgB;AACrD,OAAM,gCAAU,cAAc,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC;AAEhE,QAAO,KACJ,YAAY,OAAO,OAAO,WAAW,UAAU,OAAO,cAAc,MAAM,OAAO,YAAY,mBAAS,QAAQ,KAAK,EAAE,UAAU,CAAC,EAClI;AACD,QAAO,KAAK,YAAY,mBAAS,QAAQ,KAAK,EAAE,aAAa,CAAC,EAAE;AACjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifests-HX4z4kkz.mjs","names":["outputDir: string","routes: RouteInfo[]","functions: FunctionInfo[]","crons: CronInfo[]","manifest: BuildManifest"],"sources":["../src/build/manifests.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'path';\nimport type {\n BuildManifest,\n CronInfo,\n FunctionInfo,\n RouteInfo,\n} from '../types';\n\nconst logger = console;\n\nexport async function generateManifests(\n outputDir: string,\n routes: RouteInfo[],\n functions: FunctionInfo[],\n crons: CronInfo[],\n): Promise<void> {\n // Generate unified manifest for all providers\n const manifest: BuildManifest = {\n routes,\n functions,\n crons,\n };\n\n const manifestPath = join(outputDir, 'manifest.json');\n await writeFile(manifestPath, JSON.stringify(manifest, null, 2));\n\n logger.log(\n `Generated ${routes.length} routes, ${functions.length} functions, ${crons.length} crons in ${relative(process.cwd(), outputDir)}`,\n );\n logger.log(`Manifest: ${relative(process.cwd(), manifestPath)}`);\n}\n"],"mappings":";;;;AASA,MAAM,SAAS;AAEf,eAAsB,kBACpBA,WACAC,QACAC,WACAC,OACe;CAEf,MAAMC,WAA0B;EAC9B;EACA;EACA;CACD;CAED,MAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,OAAM,UAAU,cAAc,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC;AAEhE,QAAO,KACJ,YAAY,OAAO,OAAO,WAAW,UAAU,OAAO,cAAc,MAAM,OAAO,YAAY,SAAS,QAAQ,KAAK,EAAE,UAAU,CAAC,EAClI;AACD,QAAO,KAAK,YAAY,SAAS,QAAQ,KAAK,EAAE,aAAa,CAAC,EAAE;AACjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi-BivnatiC.mjs","names":["options: OpenAPIOptions"],"sources":["../src/openapi.ts"],"sourcesContent":["#!/usr/bin/env -S npx tsx\n\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { Endpoint } from '@geekmidas/api/server';\nimport { loadConfig } from './config.js';\nimport { EndpointGenerator } from './generators/EndpointGenerator.js';\n\ninterface OpenAPIOptions {\n output?: string;\n}\n\nexport async function openapiCommand(\n options: OpenAPIOptions = {},\n): Promise<void> {\n const logger = console;\n\n try {\n // Load config using existing function\n const config = await loadConfig();\n const generator = new EndpointGenerator();\n\n // Load all endpoints using the refactored function\n const loadedEndpoints = await generator.load(config.routes);\n\n if (loadedEndpoints.length === 0) {\n logger.log('No valid endpoints found');\n return;\n }\n\n // Extract just the endpoint instances for OpenAPI generation\n const endpoints = loadedEndpoints.map(({ construct }) => construct);\n\n // Generate OpenAPI spec using built-in method\n const spec = await Endpoint.buildOpenApiSchema(endpoints, {\n title: 'API Documentation',\n version: '1.0.0',\n description: 'Auto-generated API documentation from endpoints',\n });\n\n // Write output\n const outputPath = options.output || join(process.cwd(), 'openapi.json');\n await mkdir(join(outputPath, '..'), { recursive: true });\n await writeFile(outputPath, JSON.stringify(spec, null, 2));\n\n logger.log(`OpenAPI spec generated: ${outputPath}`);\n logger.log(`Found ${endpoints.length} endpoints`);\n } catch (error) {\n throw new Error(`OpenAPI generation failed: ${(error as Error).message}`);\n }\n}\n"],"mappings":";;;;;;;AAYA,eAAsB,eACpBA,UAA0B,CAAE,GACb;CACf,MAAM,SAAS;AAEf,KAAI;EAEF,MAAM,SAAS,MAAM,YAAY;EACjC,MAAM,YAAY,IAAI;EAGtB,MAAM,kBAAkB,MAAM,UAAU,KAAK,OAAO,OAAO;AAE3D,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAO,IAAI,2BAA2B;AACtC;EACD;EAGD,MAAM,YAAY,gBAAgB,IAAI,CAAC,EAAE,WAAW,KAAK,UAAU;EAGnE,MAAM,OAAO,MAAM,SAAS,mBAAmB,WAAW;GACxD,OAAO;GACP,SAAS;GACT,aAAa;EACd,EAAC;EAGF,MAAM,aAAa,QAAQ,UAAU,KAAK,QAAQ,KAAK,EAAE,eAAe;AACxE,QAAM,MAAM,KAAK,YAAY,KAAK,EAAE,EAAE,WAAW,KAAM,EAAC;AACxD,QAAM,UAAU,YAAY,KAAK,UAAU,MAAM,MAAM,EAAE,CAAC;AAE1D,SAAO,KAAK,0BAA0B,WAAW,EAAE;AACnD,SAAO,KAAK,QAAQ,UAAU,OAAO,YAAY;CAClD,SAAQ,OAAO;AACd,QAAM,IAAI,OAAO,6BAA8B,MAAgB,QAAQ;CACxE;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi-DW-qF3oW.cjs","names":["options: OpenAPIOptions","EndpointGenerator"],"sources":["../src/openapi.ts"],"sourcesContent":["#!/usr/bin/env -S npx tsx\n\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { Endpoint } from '@geekmidas/api/server';\nimport { loadConfig } from './config.js';\nimport { EndpointGenerator } from './generators/EndpointGenerator.js';\n\ninterface OpenAPIOptions {\n output?: string;\n}\n\nexport async function openapiCommand(\n options: OpenAPIOptions = {},\n): Promise<void> {\n const logger = console;\n\n try {\n // Load config using existing function\n const config = await loadConfig();\n const generator = new EndpointGenerator();\n\n // Load all endpoints using the refactored function\n const loadedEndpoints = await generator.load(config.routes);\n\n if (loadedEndpoints.length === 0) {\n logger.log('No valid endpoints found');\n return;\n }\n\n // Extract just the endpoint instances for OpenAPI generation\n const endpoints = loadedEndpoints.map(({ construct }) => construct);\n\n // Generate OpenAPI spec using built-in method\n const spec = await Endpoint.buildOpenApiSchema(endpoints, {\n title: 'API Documentation',\n version: '1.0.0',\n description: 'Auto-generated API documentation from endpoints',\n });\n\n // Write output\n const outputPath = options.output || join(process.cwd(), 'openapi.json');\n await mkdir(join(outputPath, '..'), { recursive: true });\n await writeFile(outputPath, JSON.stringify(spec, null, 2));\n\n logger.log(`OpenAPI spec generated: ${outputPath}`);\n logger.log(`Found ${endpoints.length} endpoints`);\n } catch (error) {\n throw new Error(`OpenAPI generation failed: ${(error as Error).message}`);\n }\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,eACpBA,UAA0B,CAAE,GACb;CACf,MAAM,SAAS;AAEf,KAAI;EAEF,MAAM,SAAS,MAAM,2BAAY;EACjC,MAAM,YAAY,IAAIC;EAGtB,MAAM,kBAAkB,MAAM,UAAU,KAAK,OAAO,OAAO;AAE3D,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAO,IAAI,2BAA2B;AACtC;EACD;EAGD,MAAM,YAAY,gBAAgB,IAAI,CAAC,EAAE,WAAW,KAAK,UAAU;EAGnE,MAAM,OAAO,MAAM,gCAAS,mBAAmB,WAAW;GACxD,OAAO;GACP,SAAS;GACT,aAAa;EACd,EAAC;EAGF,MAAM,aAAa,QAAQ,UAAU,oBAAK,QAAQ,KAAK,EAAE,eAAe;AACxE,QAAM,4BAAM,oBAAK,YAAY,KAAK,EAAE,EAAE,WAAW,KAAM,EAAC;AACxD,QAAM,gCAAU,YAAY,KAAK,UAAU,MAAM,MAAM,EAAE,CAAC;AAE1D,SAAO,KAAK,0BAA0B,WAAW,EAAE;AACnD,SAAO,KAAK,QAAQ,UAAU,OAAO,YAAY;CAClD,SAAQ,OAAO;AACd,QAAM,IAAI,OAAO,6BAA8B,MAAgB,QAAQ;CACxE;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi-react-query-J0BzBHhN.cjs","names":["exec","options: ReactQueryOptions","spec: OpenAPISpec","operations: OperationInfo[]","operation: any","schema: any","apiName: string","op: OperationInfo","paramParts: string[]","exports","str: string"],"sources":["../src/openapi-react-query.ts"],"sourcesContent":["#!/usr/bin/env -S npx tsx\n\nimport { exec } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { promisify } from 'node:util';\n\nconst execAsync = promisify(exec);\n\ninterface ReactQueryOptions {\n input?: string;\n output?: string;\n name?: string;\n}\n\ninterface OpenAPISpec {\n openapi: string;\n info?: {\n title?: string;\n version?: string;\n };\n paths: Record<string, Record<string, any>>;\n}\n\nexport async function generateReactQueryCommand(\n options: ReactQueryOptions = {},\n): Promise<void> {\n const logger = console;\n\n try {\n // Read OpenAPI spec\n const inputPath = options.input || join(process.cwd(), 'openapi.json');\n\n if (!existsSync(inputPath)) {\n throw new Error(\n `OpenAPI spec not found at ${inputPath}. Run 'npx @geekmidas/cli openapi' first.`,\n );\n }\n\n const specContent = await readFile(inputPath, 'utf-8');\n const spec: OpenAPISpec = JSON.parse(specContent);\n\n // Generate TypeScript types from OpenAPI spec\n const outputDir = dirname(\n options.output || join(process.cwd(), 'src', 'api', 'hooks.ts'),\n );\n const typesPath = join(outputDir, 'openapi-types.d.ts');\n\n logger.log('Generating TypeScript types from OpenAPI spec...');\n\n try {\n // Use npx to run openapi-typescript\n await execAsync(\n `npx openapi-typescript \"${inputPath}\" -o \"${typesPath}\"`,\n { cwd: process.cwd() },\n );\n logger.log(`TypeScript types generated: ${typesPath}`);\n } catch (error) {\n logger.warn(\n 'Could not generate types with openapi-typescript. Install it for better type inference.',\n );\n logger.warn('Run: npm install -D openapi-typescript');\n\n // Generate basic types file\n await writeFile(\n typesPath,\n `// Auto-generated placeholder types\nexport interface paths {\n [path: string]: {\n [method: string]: {\n operationId?: string;\n parameters?: any;\n requestBody?: any;\n responses?: any;\n };\n };\n}\n`,\n );\n }\n\n // Extract operation info\n const operations = extractOperations(spec);\n\n // Generate TypeScript code\n const code = generateReactQueryCode(\n spec,\n operations,\n options.name || 'API',\n );\n\n // Write output\n const outputPath =\n options.output || join(process.cwd(), 'src', 'api', 'hooks.ts');\n await mkdir(dirname(outputPath), { recursive: true });\n await writeFile(outputPath, code);\n\n logger.log(`React Query hooks generated: ${outputPath}`);\n logger.log(`Generated ${operations.length} hooks`);\n } catch (error) {\n throw new Error(\n `React Query generation failed: ${(error as Error).message}`,\n );\n }\n}\n\ninterface OperationInfo {\n operationId: string;\n path: string;\n method: string;\n endpoint: string; // Full endpoint like 'GET /users/{id}'\n parameters?: Array<{ name: string; in: string; required?: boolean }>;\n requestBody?: boolean;\n responseType?: string;\n}\n\nfunction extractOperations(spec: OpenAPISpec): OperationInfo[] {\n const operations: OperationInfo[] = [];\n\n Object.entries(spec.paths).forEach(([path, methods]) => {\n Object.entries(methods).forEach(([method, operation]) => {\n if (operation.operationId) {\n operations.push({\n operationId: operation.operationId,\n path,\n method: method.toUpperCase(),\n endpoint: `${method.toUpperCase()} ${path}`,\n parameters: operation.parameters,\n requestBody: !!operation.requestBody,\n responseType: extractResponseType(operation),\n });\n }\n });\n });\n\n return operations;\n}\n\nfunction extractResponseType(operation: any): string {\n const responses = operation.responses;\n if (!responses) return 'unknown';\n\n const successResponse = responses['200'] || responses['201'];\n if (!successResponse?.content?.['application/json']?.schema) {\n return 'unknown';\n }\n\n // Basic type inference from schema\n const schema = successResponse.content['application/json'].schema;\n return schemaToTypeString(schema);\n}\n\nfunction schemaToTypeString(schema: any): string {\n if (!schema) return 'unknown';\n\n switch (schema.type) {\n case 'string':\n return 'string';\n case 'number':\n case 'integer':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'array':\n return `Array<${schemaToTypeString(schema.items)}>`;\n case 'object':\n if (schema.properties) {\n const props = Object.entries(schema.properties)\n .map(\n ([key, value]: [string, any]) =>\n `${key}: ${schemaToTypeString(value)}`,\n )\n .join('; ');\n return `{ ${props} }`;\n }\n return 'Record<string, unknown>';\n default:\n return 'unknown';\n }\n}\n\nfunction generateReactQueryCode(\n spec: OpenAPISpec,\n operations: OperationInfo[],\n apiName: string,\n): string {\n const imports = `import { createTypedQueryClient } from '@geekmidas/api/client';\nimport type { paths } from './openapi-types';\n\n// Create typed query client\nexport const ${apiName.toLowerCase()} = createTypedQueryClient<paths>({\n baseURL: process.env.NEXT_PUBLIC_API_URL || '/api',\n});\n\n// Export individual hooks for better DX\n`;\n\n const queryHooks = operations\n .filter((op) => op.method === 'GET')\n .map((op) => generateQueryHook(op, apiName))\n .join('\\n\\n');\n\n const mutationHooks = operations\n .filter((op) => op.method !== 'GET')\n .map((op) => generateMutationHook(op, apiName))\n .join('\\n\\n');\n\n const typeExports = generateTypeExports(operations);\n\n return `${imports}\n// Query Hooks\n${queryHooks}\n\n// Mutation Hooks\n${mutationHooks}\n\n// Type exports for convenience\n${typeExports}\n\n// Re-export the api for advanced usage\nexport { ${apiName.toLowerCase()} };\n`;\n}\n\nfunction generateQueryHook(op: OperationInfo, apiName: string): string {\n const hookName = `use${capitalize(op.operationId)}`;\n const endpoint = op.endpoint;\n const hasParams = op.parameters?.some((p) => p.in === 'path');\n const hasQuery = op.parameters?.some((p) => p.in === 'query');\n\n // Generate properly typed hook\n let params = '';\n let args = '';\n\n if (hasParams || hasQuery) {\n const paramParts: string[] = [];\n if (hasParams) {\n const pathParams =\n op.parameters?.filter((p) => p.in === 'path').map((p) => p.name) || [];\n paramParts.push(\n `params: { ${pathParams.map((p) => `${p}: string`).join('; ')} }`,\n );\n }\n if (hasQuery) {\n paramParts.push(`query?: Record<string, any>`);\n }\n params = `config: { ${paramParts.join('; ')} }, `;\n args = ', config';\n }\n\n return `export const ${hookName} = (\n ${params}options?: Parameters<typeof ${apiName.toLowerCase()}.useQuery>[2]\n) => {\n return ${apiName.toLowerCase()}.useQuery('${endpoint}' as any${args}, options);\n};`;\n}\n\nfunction generateMutationHook(op: OperationInfo, apiName: string): string {\n const hookName = `use${capitalize(op.operationId)}`;\n const endpoint = op.endpoint;\n\n return `export const ${hookName} = (\n options?: Parameters<typeof ${apiName.toLowerCase()}.useMutation>[1]\n) => {\n return ${apiName.toLowerCase()}.useMutation('${endpoint}' as any, options);\n};`;\n}\n\nfunction generateTypeExports(operations: OperationInfo[]): string {\n const exports = operations.map((op) => {\n const typeName = capitalize(op.operationId);\n const isQuery = op.method === 'GET';\n\n if (isQuery) {\n return `export type ${typeName}Response = Awaited<ReturnType<ReturnType<typeof use${typeName}>['data']>>;`;\n } else {\n return `export type ${typeName}Response = Awaited<ReturnType<ReturnType<typeof use${typeName}>['mutateAsync']>>;`;\n }\n });\n\n return exports.join('\\n');\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,YAAY,yBAAUA,wBAAK;AAiBjC,eAAsB,0BACpBC,UAA6B,CAAE,GAChB;CACf,MAAM,SAAS;AAEf,KAAI;EAEF,MAAM,YAAY,QAAQ,SAAS,oBAAK,QAAQ,KAAK,EAAE,eAAe;AAEtE,OAAK,wBAAW,UAAU,CACxB,OAAM,IAAI,OACP,4BAA4B,UAAU;EAI3C,MAAM,cAAc,MAAM,+BAAS,WAAW,QAAQ;E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;MAE7F,SAAQ,cAAc,SAAS,qDAAqD,SAAS;CAEhG,EAAC;AAEF,QAAO,UAAQ,KAAK,KAAK;AAC1B;AAED,SAAS,WAAWC,KAAqB;AACvC,QAAO,IAAI,OAAO,EAAE,CAAC,aAAa,GAAG,IAAI,MAAM,EAAE;AAClD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"openapi-react-query-lgS7AVEz.mjs","names":["options: ReactQueryOptions","spec: OpenAPISpec","operations: OperationInfo[]","operation: any","schema: any","apiName: string","op: OperationInfo","paramParts: string[]","str: string"],"sources":["../src/openapi-react-query.ts"],"sourcesContent":["#!/usr/bin/env -S npx tsx\n\nimport { exec } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { promisify } from 'node:util';\n\nconst execAsync = promisify(exec);\n\ninterface ReactQueryOptions {\n input?: string;\n output?: string;\n name?: string;\n}\n\ninterface OpenAPISpec {\n openapi: string;\n info?: {\n title?: string;\n version?: string;\n };\n paths: Record<string, Record<string, any>>;\n}\n\nexport async function generateReactQueryCommand(\n options: ReactQueryOptions = {},\n): Promise<void> {\n const logger = console;\n\n try {\n // Read OpenAPI spec\n const inputPath = options.input || join(process.cwd(), 'openapi.json');\n\n if (!existsSync(inputPath)) {\n throw new Error(\n `OpenAPI spec not found at ${inputPath}. Run 'npx @geekmidas/cli openapi' first.`,\n );\n }\n\n const specContent = await readFile(inputPath, 'utf-8');\n const spec: OpenAPISpec = JSON.parse(specContent);\n\n // Generate TypeScript types from OpenAPI spec\n const outputDir = dirname(\n options.output || join(process.cwd(), 'src', 'api', 'hooks.ts'),\n );\n const typesPath = join(outputDir, 'openapi-types.d.ts');\n\n logger.log('Generating TypeScript types from OpenAPI spec...');\n\n try {\n // Use npx to run openapi-typescript\n await execAsync(\n `npx openapi-typescript \"${inputPath}\" -o \"${typesPath}\"`,\n { cwd: process.cwd() },\n );\n logger.log(`TypeScript types generated: ${typesPath}`);\n } catch (error) {\n logger.warn(\n 'Could not generate types with openapi-typescript. Install it for better type inference.',\n );\n logger.warn('Run: npm install -D openapi-typescript');\n\n // Generate basic types file\n await writeFile(\n typesPath,\n `// Auto-generated placeholder types\nexport interface paths {\n [path: string]: {\n [method: string]: {\n operationId?: string;\n parameters?: any;\n requestBody?: any;\n responses?: any;\n };\n };\n}\n`,\n );\n }\n\n // Extract operation info\n const operations = extractOperations(spec);\n\n // Generate TypeScript code\n const code = generateReactQueryCode(\n spec,\n operations,\n options.name || 'API',\n );\n\n // Write output\n const outputPath =\n options.output || join(process.cwd(), 'src', 'api', 'hooks.ts');\n await mkdir(dirname(outputPath), { recursive: true });\n await writeFile(outputPath, code);\n\n logger.log(`React Query hooks generated: ${outputPath}`);\n logger.log(`Generated ${operations.length} hooks`);\n } catch (error) {\n throw new Error(\n `React Query generation failed: ${(error as Error).message}`,\n );\n }\n}\n\ninterface OperationInfo {\n operationId: string;\n path: string;\n method: string;\n endpoint: string; // Full endpoint like 'GET /users/{id}'\n parameters?: Array<{ name: string; in: string; required?: boolean }>;\n requestBody?: boolean;\n responseType?: string;\n}\n\nfunction extractOperations(spec: OpenAPISpec): OperationInfo[] {\n const operations: OperationInfo[] = [];\n\n Object.entries(spec.paths).forEach(([path, methods]) => {\n Object.entries(methods).forEach(([method, operation]) => {\n if (operation.operationId) {\n operations.push({\n operationId: operation.operationId,\n path,\n method: method.toUpperCase(),\n endpoint: `${method.toUpperCase()} ${path}`,\n parameters: operation.parameters,\n requestBody: !!operation.requestBody,\n responseType: extractResponseType(operation),\n });\n }\n });\n });\n\n return operations;\n}\n\nfunction extractResponseType(operation: any): string {\n const responses = operation.responses;\n if (!responses) return 'unknown';\n\n const successResponse = responses['200'] || responses['201'];\n if (!successResponse?.content?.['application/json']?.schema) {\n return 'unknown';\n }\n\n // Basic type inference from schema\n const schema = successResponse.content['application/json'].schema;\n return schemaToTypeString(schema);\n}\n\nfunction schemaToTypeString(schema: any): string {\n if (!schema) return 'unknown';\n\n switch (schema.type) {\n case 'string':\n return 'string';\n case 'number':\n case 'integer':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'array':\n return `Array<${schemaToTypeString(schema.items)}>`;\n case 'object':\n if (schema.properties) {\n const props = Object.entries(schema.properties)\n .map(\n ([key, value]: [string, any]) =>\n `${key}: ${schemaToTypeString(value)}`,\n )\n .join('; ');\n return `{ ${props} }`;\n }\n return 'Record<string, unknown>';\n default:\n return 'unknown';\n }\n}\n\nfunction generateReactQueryCode(\n spec: OpenAPISpec,\n operations: OperationInfo[],\n apiName: string,\n): string {\n const imports = `import { createTypedQueryClient } from '@geekmidas/api/client';\nimport type { paths } from './openapi-types';\n\n// Create typed query client\nexport const ${apiName.toLowerCase()} = createTypedQueryClient<paths>({\n baseURL: process.env.NEXT_PUBLIC_API_URL || '/api',\n});\n\n// Export individual hooks for better DX\n`;\n\n const queryHooks = operations\n .filter((op) => op.method === 'GET')\n .map((op) => generateQueryHook(op, apiName))\n .join('\\n\\n');\n\n const mutationHooks = operations\n .filter((op) => op.method !== 'GET')\n .map((op) => generateMutationHook(op, apiName))\n .join('\\n\\n');\n\n const typeExports = generateTypeExports(operations);\n\n return `${imports}\n// Query Hooks\n${queryHooks}\n\n// Mutation Hooks\n${mutationHooks}\n\n// Type exports for convenience\n${typeExports}\n\n// Re-export the api for advanced usage\nexport { ${apiName.toLowerCase()} };\n`;\n}\n\nfunction generateQueryHook(op: OperationInfo, apiName: string): string {\n const hookName = `use${capitalize(op.operationId)}`;\n const endpoint = op.endpoint;\n const hasParams = op.parameters?.some((p) => p.in === 'path');\n const hasQuery = op.parameters?.some((p) => p.in === 'query');\n\n // Generate properly typed hook\n let params = '';\n let args = '';\n\n if (hasParams || hasQuery) {\n const paramParts: string[] = [];\n if (hasParams) {\n const pathParams =\n op.parameters?.filter((p) => p.in === 'path').map((p) => p.name) || [];\n paramParts.push(\n `params: { ${pathParams.map((p) => `${p}: string`).join('; ')} }`,\n );\n }\n if (hasQuery) {\n paramParts.push(`query?: Record<string, any>`);\n }\n params = `config: { ${paramParts.join('; ')} }, `;\n args = ', config';\n }\n\n return `export const ${hookName} = (\n ${params}options?: Parameters<typeof ${apiName.toLowerCase()}.useQuery>[2]\n) => {\n return ${apiName.toLowerCase()}.useQuery('${endpoint}' as any${args}, options);\n};`;\n}\n\nfunction generateMutationHook(op: OperationInfo, apiName: string): string {\n const hookName = `use${capitalize(op.operationId)}`;\n const endpoint = op.endpoint;\n\n return `export const ${hookName} = (\n options?: Parameters<typeof ${apiName.toLowerCase()}.useMutation>[1]\n) => {\n return ${apiName.toLowerCase()}.useMutation('${endpoint}' as any, options);\n};`;\n}\n\nfunction generateTypeExports(operations: OperationInfo[]): string {\n const exports = operations.map((op) => {\n const typeName = capitalize(op.operationId);\n const isQuery = op.method === 'GET';\n\n if (isQuery) {\n return `export type ${typeName}Response = Awaited<ReturnType<ReturnType<typeof use${typeName}>['data']>>;`;\n } else {\n return `export type ${typeName}Response = Awaited<ReturnType<ReturnType<typeof use${typeName}>['mutateAsync']>>;`;\n }\n });\n\n return exports.join('\\n');\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"],"mappings":";;;;;;;AAQA,MAAM,YAAY,UAAU,KAAK;AAiBjC,eAAsB,0BACpBA,UAA6B,CAAE,GAChB;CACf,MAAM,SAAS;AAEf,KAAI;EAEF,MAAM,YAAY,QAAQ,SAAS,KAAK,QAAQ,KAAK,EAAE,eAAe;AAEtE,OAAK,WAAW,UAAU,CACxB,OAAM,IAAI,OACP,4BAA4B,UAAU;EAI3C,MAAM,cAAc,MAAM,SAAS,WAAW,QAAQ;EACtD,MAAMC,OAAoB,KAAK,MAAM,YAAY;EAGjD,MAAM,YAAY,QAChB,QAAQ,UAAU,KAAK,QAAQ,KAAK,EAAE,OAAO,OAAO,WAAW,CAChE;EACD,MAAM,YAAY,KAAK,WAAW,qBAAqB;AAEvD,SAAO,IAAI,mDAAmD;AAE9D,MAAI;AA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const require_chunk = require('./chunk-CsX-DzYB.cjs');
2
- const require_esm = require('./esm-Crmo4h9t.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_api_constructs = require_chunk.__toESM(require("@geekmidas/api/constructs"));
6
- const __geekmidas_api_server = require_chunk.__toESM(require("@geekmidas/api/server"));
7
- const node_os = require_chunk.__toESM(require("node:os"));
8
-
9
- //#region src/__tests__/test-helpers.ts
10
- /**
11
- * Creates a temporary directory for testing
12
- */
13
- async function createTempDir(prefix = "cli-test-") {
14
- const tempPath = (0, node_path.join)((0, node_os.tmpdir)(), `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`);
15
- await (0, node_fs_promises.mkdir)(tempPath, { recursive: true });
16
- return tempPath;
17
- }
18
- /**
19
- * Cleans up a directory
20
- */
21
- async function cleanupDir(path) {
22
- try {
23
- await (0, node_fs_promises.rm)(path, {
24
- recursive: true,
25
- force: true
26
- });
27
- } catch (error) {}
28
- }
29
- /**
30
- * Creates a test file with content
31
- */
32
- async function createTestFile(dir, filename, content) {
33
- const filePath = (0, node_path.join)(dir, filename);
34
- await (0, node_fs_promises.mkdir)((0, node_path.dirname)(filePath), { recursive: true });
35
- await (0, node_fs_promises.writeFile)(filePath, content);
36
- return filePath;
37
- }
38
- /**
39
- * Creates a mock endpoint file with real endpoint construct
40
- */
41
- async function createMockEndpointFile(dir, filename, exportName, path = "/test", method = "GET") {
42
- const content = `
43
- import { e } from '@geekmidas/api/server';
44
- import { z } from 'zod';
45
-
46
- export const ${exportName} = e
47
- .${method.toLowerCase()}('${path}')
48
- .output(z.object({ message: z.string() }))
49
- .handle(async () => ({ message: 'Hello from ${exportName}' }));
50
- `;
51
- return createTestFile(dir, filename, content);
52
- }
53
- /**
54
- * Creates a mock function file with real function construct
55
- */
56
- async function createMockFunctionFile(dir, filename, exportName, timeout = 30) {
57
- const content = `
58
- import { FunctionBuilder } from '@geekmidas/api/constructs';
59
- import { z } from 'zod';
60
-
61
- export const ${exportName} = new FunctionBuilder()
62
- .input(z.object({ name: z.string() }))
63
- .output(z.object({ greeting: z.string() }))
64
- .timeout(${timeout})
65
- .handle(async ({ input }) => ({ greeting: \`Hello, \${input.name}!\` }));
66
- `;
67
- return createTestFile(dir, filename, content);
68
- }
69
- /**
70
- * Creates a mock cron file with real cron construct
71
- */
72
- async function createMockCronFile(dir, filename, exportName, schedule = "rate(1 hour)") {
73
- const content = `
74
- import { CronBuilder } from '@geekmidas/api/constructs';
75
- import { z } from 'zod';
76
-
77
- export const ${exportName} = new CronBuilder()
78
- .schedule('${schedule}')
79
- .output(z.object({ processed: z.number() }))
80
- .handle(async () => {
81
- console.log('Running cron job: ${exportName}');
82
- return { processed: 10 };
83
- });
84
- `;
85
- return createTestFile(dir, filename, content);
86
- }
87
- /**
88
- * Helper functions to create real constructs for testing
89
- */
90
- function createTestEndpoint(path, method = "GET") {
91
- const m = method.toLowerCase();
92
- const builder = __geekmidas_api_server.e[m](path);
93
- builder.output(require_esm.objectType({ message: require_esm.stringType() }));
94
- return builder.handle(async () => ({ message: `Hello from ${path}` }));
95
- }
96
- function createTestFunction(timeout = 30) {
97
- const builder = new __geekmidas_api_constructs.FunctionBuilder();
98
- builder.input(require_esm.objectType({ name: require_esm.stringType() }));
99
- builder.output(require_esm.objectType({ greeting: require_esm.stringType() }));
100
- builder.timeout(timeout);
101
- return builder.handle(async ({ input }) => ({ greeting: `Hello, ${input.name}!` }));
102
- }
103
- function createTestCron(schedule = "rate(1 hour)", timeout = 30) {
104
- const builder = new __geekmidas_api_constructs.CronBuilder();
105
- builder.schedule(schedule);
106
- builder.output(require_esm.objectType({ processed: require_esm.numberType() }));
107
- builder.timeout(timeout);
108
- return builder.handle(async () => {
109
- return { processed: 10 };
110
- });
111
- }
112
- /**
113
- * Creates a mock build context
114
- */
115
- function createMockBuildContext() {
116
- return {
117
- envParserPath: "./env",
118
- envParserImportPattern: "envParser",
119
- loggerPath: "./logger",
120
- loggerImportPattern: "logger"
121
- };
122
- }
123
- /**
124
- * Waits for a condition to be true
125
- */
126
- async function waitFor(condition, timeout = 5e3, interval = 100) {
127
- const start = Date.now();
128
- while (!condition() && Date.now() - start < timeout) await new Promise((resolve) => setTimeout(resolve, interval));
129
- if (!condition()) throw new Error("Timeout waiting for condition");
130
- }
131
-
132
- //#endregion
133
- Object.defineProperty(exports, 'cleanupDir', {
134
- enumerable: true,
135
- get: function () {
136
- return cleanupDir;
137
- }
138
- });
139
- Object.defineProperty(exports, 'createMockBuildContext', {
140
- enumerable: true,
141
- get: function () {
142
- return createMockBuildContext;
143
- }
144
- });
145
- Object.defineProperty(exports, 'createMockCronFile', {
146
- enumerable: true,
147
- get: function () {
148
- return createMockCronFile;
149
- }
150
- });
151
- Object.defineProperty(exports, 'createMockEndpointFile', {
152
- enumerable: true,
153
- get: function () {
154
- return createMockEndpointFile;
155
- }
156
- });
157
- Object.defineProperty(exports, 'createMockFunctionFile', {
158
- enumerable: true,
159
- get: function () {
160
- return createMockFunctionFile;
161
- }
162
- });
163
- Object.defineProperty(exports, 'createTempDir', {
164
- enumerable: true,
165
- get: function () {
166
- return createTempDir;
167
- }
168
- });
169
- Object.defineProperty(exports, 'createTestCron', {
170
- enumerable: true,
171
- get: function () {
172
- return createTestCron;
173
- }
174
- });
175
- Object.defineProperty(exports, 'createTestEndpoint', {
176
- enumerable: true,
177
- get: function () {
178
- return createTestEndpoint;
179
- }
180
- });
181
- Object.defineProperty(exports, 'createTestFile', {
182
- enumerable: true,
183
- get: function () {
184
- return createTestFile;
185
- }
186
- });
187
- Object.defineProperty(exports, 'createTestFunction', {
188
- enumerable: true,
189
- get: function () {
190
- return createTestFunction;
191
- }
192
- });
193
- Object.defineProperty(exports, 'waitFor', {
194
- enumerable: true,
195
- get: function () {
196
- return waitFor;
197
- }
198
- });
199
- //# sourceMappingURL=test-helpers-ARd8GDgx.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-helpers-ARd8GDgx.cjs","names":["path: string","dir: string","filename: string","content: string","exportName: string","method: string","method: HttpMethod","timeout: number","FunctionBuilder","schedule: ScheduleExpression","CronBuilder","condition: () => boolean"],"sources":["../src/__tests__/test-helpers.ts"],"sourcesContent":["import { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport {\n CronBuilder,\n FunctionBuilder,\n type ScheduleExpression,\n} from '@geekmidas/api/constructs';\nimport { e } from '@geekmidas/api/server';\nimport { z } from 'zod';\n\n/**\n * Creates a temporary directory for testing\n */\nexport async function createTempDir(prefix = 'cli-test-'): Promise<string> {\n const tempPath = join(\n tmpdir(),\n `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`,\n );\n await mkdir(tempPath, { recursive: true });\n return tempPath;\n}\n\n/**\n * Cleans up a directory\n */\nexport async function cleanupDir(path: string): Promise<void> {\n try {\n await rm(path, { recursive: true, force: true });\n } catch (error) {\n // Ignore errors during cleanup\n }\n}\n\n/**\n * Creates a test file with content\n */\nexport async function createTestFile(\n dir: string,\n filename: string,\n content: string,\n): Promise<string> {\n const filePath = join(dir, filename);\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(filePath, content);\n return filePath;\n}\n\n/**\n * Creates a mock endpoint file with real endpoint construct\n */\nexport async function createMockEndpointFile(\n dir: string,\n filename: string,\n exportName: string,\n path: string = '/test',\n method: string = 'GET',\n): Promise<string> {\n const content = `\nimport { e } from '@geekmidas/api/server';\nimport { z } from 'zod';\n\nexport const ${exportName} = e\n .${method.toLowerCase()}('${path}')\n .output(z.object({ message: z.string() }))\n .handle(async () => ({ message: 'Hello from ${exportName}' }));\n`;\n return createTestFile(dir, filename, content);\n}\n\n/**\n * Creates a mock function file with real function construct\n */\nexport async function createMockFunctionFile(\n dir: string,\n filename: string,\n exportName: string,\n timeout = 30,\n): Promise<string> {\n const content = `\nimport { FunctionBuilder } from '@geekmidas/api/constructs';\nimport { z } from 'zod';\n\nexport const ${exportName} = new FunctionBuilder()\n .input(z.object({ name: z.string() }))\n .output(z.object({ greeting: z.string() }))\n .timeout(${timeout})\n .handle(async ({ input }) => ({ greeting: \\`Hello, \\${input.name}!\\` }));\n`;\n return createTestFile(dir, filename, content);\n}\n\n/**\n * Creates a mock cron file with real cron construct\n */\nexport async function createMockCronFile(\n dir: string,\n filename: string,\n exportName: string,\n schedule = 'rate(1 hour)',\n): Promise<string> {\n const content = `\nimport { CronBuilder } from '@geekmidas/api/constructs';\nimport { z } from 'zod';\n\nexport const ${exportName} = new CronBuilder()\n .schedule('${schedule}')\n .output(z.object({ processed: z.number() }))\n .handle(async () => {\n console.log('Running cron job: ${exportName}');\n return { processed: 10 };\n });\n`;\n return createTestFile(dir, filename, content);\n}\n\n/**\n * Helper functions to create real constructs for testing\n */\nexport function createTestEndpoint(path: string, method: HttpMethod = 'GET') {\n const m = method.toLowerCase() as Lowercase<HttpMethod>;\n const builder = e[m](path);\n builder.output(z.object({ message: z.string() }));\n return builder.handle(async () => ({ message: `Hello from ${path}` }));\n}\n\nexport function createTestFunction(timeout: number = 30) {\n const builder = new FunctionBuilder();\n builder.input(z.object({ name: z.string() }));\n builder.output(z.object({ greeting: z.string() }));\n builder.timeout(timeout);\n return builder.handle(async ({ input }: any) => ({ greeting: `Hello, ${input.name}!` }));\n}\n\nexport function createTestCron(\n schedule: ScheduleExpression = 'rate(1 hour)',\n timeout: number = 30,\n) {\n const builder = new CronBuilder();\n builder.schedule(schedule);\n builder.output(z.object({ processed: z.number() }));\n builder.timeout(timeout);\n return builder.handle(async () => {\n return { processed: 10 };\n });\n}\n\n/**\n * Creates a mock build context\n */\nexport function createMockBuildContext() {\n return {\n envParserPath: './env',\n envParserImportPattern: 'envParser',\n loggerPath: './logger',\n loggerImportPattern: 'logger',\n };\n}\n\n/**\n * Waits for a condition to be true\n */\nexport async function waitFor(\n condition: () => boolean,\n timeout = 5000,\n interval = 100,\n): Promise<void> {\n const start = Date.now();\n while (!condition() && Date.now() - start < timeout) {\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n if (!condition()) {\n throw new Error('Timeout waiting for condition');\n }\n}\n\nimport { dirname } from 'node:path';\nimport type { HttpMethod } from '../../../api/src/constructs/types';\n"],"mappings":";;;;;;;;;;;;AAcA,eAAsB,cAAc,SAAS,aAA8B;CACzE,MAAM,WAAW,oBACf,qBAAQ,GACP,EAAE,OAAO,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC,EAC/D;AACD,OAAM,4BAAM,UAAU,EAAE,WAAW,KAAM,EAAC;AAC1C,QAAO;AACR;;;;AAKD,eAAsB,WAAWA,MAA6B;AAC5D,KAAI;AACF,QAAM,yBAAG,MAAM;GAAE,WAAW;GAAM,OAAO;EAAM,EAAC;CACjD,SAAQ,OAAO,CAEf;AACF;;;;AAKD,eAAsB,eACpBC,KACAC,UACAC,SACiB;CACjB,MAAM,WAAW,oBAAK,KAAK,SAAS;AACpC,OAAM,4BAAM,uBAAQ,SAAS,EAAE,EAAE,WAAW,KAAM,EAAC;AACnD,OAAM,gCAAU,UAAU,QAAQ;AAClC,QAAO;AACR;;;;AAKD,eAAsB,uBACpBF,KACAC,UACAE,YACAJ,OAAe,SACfK,SAAiB,OACA;CACjB,MAAM,WAAW;;;;eAIJ,WAAW;KACrB,OAAO,aAAa,CAAC,IAAI,KAAK;;gDAEa,WAAW;;AAEzD,QAAO,eAAe,KAAK,UAAU,QAAQ;AAC9C;;;;AAKD,eAAsB,uBACpBJ,KACAC,UACAE,YACA,UAAU,IACO;CACjB,MAAM,WAAW;;;;eAIJ,WAAW;;;aAGb,QAAQ;;;AAGnB,QAAO,eAAe,KAAK,UAAU,QAAQ;AAC9C;;;;AAKD,eAAsB,mBACpBH,KACAC,UACAE,YACA,WAAW,gBACM;CACjB,MAAM,WAAW;;;;eAIJ,WAAW;eACX,SAAS;;;qCAGa,WAAW;;;;AAI9C,QAAO,eAAe,KAAK,UAAU,QAA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