@geekmidas/constructs 7.0.1 → 10.0.0-alpha.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 (385) hide show
  1. package/README.md +71 -44
  2. package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts → AWSScheduledFunction-BvFvBsBN.d.cts} +10 -5
  3. package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts.map → AWSScheduledFunction-BvFvBsBN.d.cts.map} +1 -1
  4. package/dist/{AWSScheduledFunction-CTIa90EH.d.cts → AWSScheduledFunction-CVccZO-L.d.mts} +10 -5
  5. package/dist/{AWSScheduledFunction-CTIa90EH.d.cts.map → AWSScheduledFunction-CVccZO-L.d.mts.map} +1 -1
  6. package/dist/{AWSScheduledFunction-CufMMhGB.mjs → AWSScheduledFunction-Db1lttJH.mjs} +3 -3
  7. package/dist/{AWSScheduledFunction-CufMMhGB.mjs.map → AWSScheduledFunction-Db1lttJH.mjs.map} +1 -1
  8. package/dist/{AWSScheduledFunction-DbkDr8CA.cjs → AWSScheduledFunction-qu4ieRZR.cjs} +9 -9
  9. package/dist/{AWSScheduledFunction-DbkDr8CA.cjs.map → AWSScheduledFunction-qu4ieRZR.cjs.map} +1 -1
  10. package/dist/{Construct-_1wX7p_Y.d.cts → Construct-B-xc0SE9.d.mts} +27 -5
  11. package/dist/Construct-B-xc0SE9.d.mts.map +1 -0
  12. package/dist/{Construct-r0U2zBwW.mjs → Construct-HmWM6YYu.mjs} +4 -3
  13. package/dist/Construct-HmWM6YYu.mjs.map +1 -0
  14. package/dist/{Construct-DCMuYOox.d.mts → Construct-WhCXIOPV.d.cts} +29 -7
  15. package/dist/Construct-WhCXIOPV.d.cts.map +1 -0
  16. package/dist/{Construct-vXMZJgRp.cjs → Construct-roId57cU.cjs} +7 -43
  17. package/dist/Construct-roId57cU.cjs.map +1 -0
  18. package/dist/{lazyAccessors-DmTG8sQH.cjs → Endpoint-BBkV6l0k.cjs} +869 -1079
  19. package/dist/Endpoint-BBkV6l0k.cjs.map +1 -0
  20. package/dist/{lazyAccessors-DfqZR6C4.mjs → Endpoint-BGwpNEX4.mjs} +840 -1003
  21. package/dist/Endpoint-BGwpNEX4.mjs.map +1 -0
  22. package/dist/{Endpoint-CAzNbDEt.d.cts → Endpoint-BnxZqIX-.d.cts} +53 -4
  23. package/dist/Endpoint-BnxZqIX-.d.cts.map +1 -0
  24. package/dist/{Endpoint-CLPSIl6S.d.mts → Endpoint-ROcXU-eH.d.mts} +55 -6
  25. package/dist/Endpoint-ROcXU-eH.d.mts.map +1 -0
  26. package/dist/EndpointFactory-DYoGLaIT.cjs +850 -0
  27. package/dist/EndpointFactory-DYoGLaIT.cjs.map +1 -0
  28. package/dist/EndpointFactory-Di0X9AWp.mjs +808 -0
  29. package/dist/EndpointFactory-Di0X9AWp.mjs.map +1 -0
  30. package/dist/{HonoEndpointAdaptor-DJDT3PMx.mjs → HonoEndpointAdaptor-DFKIIG2o.mjs} +5 -4
  31. package/dist/HonoEndpointAdaptor-DFKIIG2o.mjs.map +1 -0
  32. package/dist/{HonoEndpointAdaptor-CkJENANP.cjs → HonoEndpointAdaptor-wMsCyMgt.cjs} +24 -23
  33. package/dist/HonoEndpointAdaptor-wMsCyMgt.cjs.map +1 -0
  34. package/dist/{Queue-DaxjwmOQ.d.cts → Queue-D6WeziRD.d.cts} +43 -4
  35. package/dist/Queue-D6WeziRD.d.cts.map +1 -0
  36. package/dist/{Queue-HBDf0fqz.d.mts → Queue-DpUeqdC8.d.mts} +43 -4
  37. package/dist/Queue-DpUeqdC8.d.mts.map +1 -0
  38. package/dist/{Subscriber-B69ngPwl.d.cts → Subscriber-4rBJgDKI.d.mts} +9 -4
  39. package/dist/{Subscriber-B69ngPwl.d.cts.map → Subscriber-4rBJgDKI.d.mts.map} +1 -1
  40. package/dist/{Subscriber-D8Xm-86W.d.mts → Subscriber-DVQowdyj.d.cts} +11 -6
  41. package/dist/Subscriber-DVQowdyj.d.cts.map +1 -0
  42. package/dist/{Topic-C5ZMfveW.d.cts → Topic-Ohx9dvWr.d.cts} +33 -2
  43. package/dist/Topic-Ohx9dvWr.d.cts.map +1 -0
  44. package/dist/{Topic-DT10AqHk.d.mts → Topic-cmy2jOUy.d.mts} +33 -2
  45. package/dist/Topic-cmy2jOUy.d.mts.map +1 -0
  46. package/dist/adaptors/aws.cjs +39 -26
  47. package/dist/adaptors/aws.cjs.map +1 -1
  48. package/dist/adaptors/aws.d.cts +24 -16
  49. package/dist/adaptors/aws.d.cts.map +1 -1
  50. package/dist/adaptors/aws.d.mts +25 -17
  51. package/dist/adaptors/aws.d.mts.map +1 -1
  52. package/dist/adaptors/aws.mjs +26 -14
  53. package/dist/adaptors/aws.mjs.map +1 -1
  54. package/dist/adaptors/hono.cjs +9 -6
  55. package/dist/adaptors/hono.d.cts +7 -6
  56. package/dist/adaptors/hono.d.cts.map +1 -1
  57. package/dist/adaptors/hono.d.mts +8 -7
  58. package/dist/adaptors/hono.d.mts.map +1 -1
  59. package/dist/adaptors/hono.mjs +9 -6
  60. package/dist/adaptors/testing.cjs +18 -14
  61. package/dist/adaptors/testing.cjs.map +1 -1
  62. package/dist/adaptors/testing.d.cts +7 -6
  63. package/dist/adaptors/testing.d.cts.map +1 -1
  64. package/dist/adaptors/testing.d.mts +11 -10
  65. package/dist/adaptors/testing.d.mts.map +1 -1
  66. package/dist/adaptors/testing.mjs +10 -7
  67. package/dist/adaptors/testing.mjs.map +1 -1
  68. package/dist/auth.cjs +165 -0
  69. package/dist/auth.cjs.map +1 -0
  70. package/dist/auth.d.cts +108 -0
  71. package/dist/auth.d.cts.map +1 -0
  72. package/dist/auth.d.mts +108 -0
  73. package/dist/auth.d.mts.map +1 -0
  74. package/dist/auth.mjs +164 -0
  75. package/dist/auth.mjs.map +1 -0
  76. package/dist/cache-0ANvRQnD.mjs +51 -0
  77. package/dist/cache-0ANvRQnD.mjs.map +1 -0
  78. package/dist/cache-3WSvAulx.cjs +57 -0
  79. package/dist/cache-3WSvAulx.cjs.map +1 -0
  80. package/dist/cache-CdQ7OLpR.d.cts +47 -0
  81. package/dist/cache-CdQ7OLpR.d.cts.map +1 -0
  82. package/dist/cache-DYoJFcfd.d.mts +47 -0
  83. package/dist/cache-DYoJFcfd.d.mts.map +1 -0
  84. package/dist/cache.cjs +3 -0
  85. package/dist/cache.d.cts +3 -0
  86. package/dist/cache.d.mts +3 -0
  87. package/dist/cache.mjs +3 -0
  88. package/dist/chunk-DWy1uDak.cjs +39 -0
  89. package/dist/clone-DblgEZZa.mjs +39 -0
  90. package/dist/clone-DblgEZZa.mjs.map +1 -0
  91. package/dist/clone-Dy0cR2SZ.cjs +45 -0
  92. package/dist/clone-Dy0cR2SZ.cjs.map +1 -0
  93. package/dist/construct-interface-BfjcOD_E.cjs +117 -0
  94. package/dist/construct-interface-BfjcOD_E.cjs.map +1 -0
  95. package/dist/construct-interface-BqwRNYA2.d.mts +131 -0
  96. package/dist/construct-interface-BqwRNYA2.d.mts.map +1 -0
  97. package/dist/construct-interface-D2nNkHUN.d.cts +131 -0
  98. package/dist/construct-interface-D2nNkHUN.d.cts.map +1 -0
  99. package/dist/construct-interface-Z4CpS8tK.mjs +81 -0
  100. package/dist/construct-interface-Z4CpS8tK.mjs.map +1 -0
  101. package/dist/construct-interface.cjs +8 -0
  102. package/dist/construct-interface.d.cts +2 -0
  103. package/dist/construct-interface.d.mts +2 -0
  104. package/dist/construct-interface.mjs +3 -0
  105. package/dist/credential.cjs +96 -0
  106. package/dist/credential.cjs.map +1 -0
  107. package/dist/credential.d.cts +61 -0
  108. package/dist/credential.d.cts.map +1 -0
  109. package/dist/credential.d.mts +61 -0
  110. package/dist/credential.d.mts.map +1 -0
  111. package/dist/credential.mjs +94 -0
  112. package/dist/credential.mjs.map +1 -0
  113. package/dist/crons/index.cjs +39 -37
  114. package/dist/crons/index.cjs.map +1 -1
  115. package/dist/crons/index.d.cts +21 -8
  116. package/dist/crons/index.d.cts.map +1 -1
  117. package/dist/crons/index.d.mts +29 -13
  118. package/dist/crons/index.d.mts.map +1 -1
  119. package/dist/crons/index.mjs +37 -36
  120. package/dist/crons/index.mjs.map +1 -1
  121. package/dist/database/kysely.cjs +181 -0
  122. package/dist/database/kysely.cjs.map +1 -0
  123. package/dist/database/kysely.d.cts +152 -0
  124. package/dist/database/kysely.d.cts.map +1 -0
  125. package/dist/database/kysely.d.mts +152 -0
  126. package/dist/database/kysely.d.mts.map +1 -0
  127. package/dist/database/kysely.mjs +180 -0
  128. package/dist/database/kysely.mjs.map +1 -0
  129. package/dist/email.cjs +59 -0
  130. package/dist/email.cjs.map +1 -0
  131. package/dist/email.d.cts +50 -0
  132. package/dist/email.d.cts.map +1 -0
  133. package/dist/email.d.mts +50 -0
  134. package/dist/email.d.mts.map +1 -0
  135. package/dist/email.mjs +58 -0
  136. package/dist/email.mjs.map +1 -0
  137. package/dist/endpoints/index.cjs +21 -747
  138. package/dist/endpoints/index.d.cts +7 -343
  139. package/dist/endpoints/index.d.mts +7 -342
  140. package/dist/endpoints/index.mjs +11 -738
  141. package/dist/file-server.cjs +154 -0
  142. package/dist/file-server.cjs.map +1 -0
  143. package/dist/file-server.d.cts +156 -0
  144. package/dist/file-server.d.cts.map +1 -0
  145. package/dist/file-server.d.mts +156 -0
  146. package/dist/file-server.d.mts.map +1 -0
  147. package/dist/file-server.mjs +152 -0
  148. package/dist/file-server.mjs.map +1 -0
  149. package/dist/functions/index.cjs +4 -2
  150. package/dist/functions/index.d.cts +3 -2
  151. package/dist/functions/index.d.mts +3 -2
  152. package/dist/functions/index.mjs +4 -2
  153. package/dist/{functions-B-qt91O7.mjs → functions-CvT_q7Y4.mjs} +55 -51
  154. package/dist/functions-CvT_q7Y4.mjs.map +1 -0
  155. package/dist/{functions-C8i1kCMM.cjs → functions-DukjG8ov.cjs} +62 -57
  156. package/dist/functions-DukjG8ov.cjs.map +1 -0
  157. package/dist/index-7OcOWe75.d.cts +419 -0
  158. package/dist/index-7OcOWe75.d.cts.map +1 -0
  159. package/dist/index-Bt-F7u8L.d.mts +419 -0
  160. package/dist/index-Bt-F7u8L.d.mts.map +1 -0
  161. package/dist/{index-DP6fqv0I.d.mts → index-CPeqtKgq.d.mts} +48 -19
  162. package/dist/index-CPeqtKgq.d.mts.map +1 -0
  163. package/dist/{index-BGeTScmi.d.cts → index-Dadljnh_.d.cts} +36 -9
  164. package/dist/index-Dadljnh_.d.cts.map +1 -0
  165. package/dist/index.cjs +1 -1
  166. package/dist/index.d.cts +3 -3
  167. package/dist/index.d.mts +3 -3
  168. package/dist/index.mjs +1 -1
  169. package/dist/lazyAccessors-DM6HcXQk.mjs +175 -0
  170. package/dist/lazyAccessors-DM6HcXQk.mjs.map +1 -0
  171. package/dist/lazyAccessors-DrJj8NpA.cjs +223 -0
  172. package/dist/lazyAccessors-DrJj8NpA.cjs.map +1 -0
  173. package/dist/object-storage.cjs +48 -0
  174. package/dist/object-storage.cjs.map +1 -0
  175. package/dist/object-storage.d.cts +36 -0
  176. package/dist/object-storage.d.cts.map +1 -0
  177. package/dist/object-storage.d.mts +36 -0
  178. package/dist/object-storage.d.mts.map +1 -0
  179. package/dist/object-storage.mjs +47 -0
  180. package/dist/object-storage.mjs.map +1 -0
  181. package/dist/{processAudits-CKjjivyz.cjs → processAudits-Bc8rz6Ev.cjs} +3 -3
  182. package/dist/{processAudits-CKjjivyz.cjs.map → processAudits-Bc8rz6Ev.cjs.map} +1 -1
  183. package/dist/{processAudits-ySnizdMG.mjs → processAudits-D89tICM4.mjs} +1 -1
  184. package/dist/{processAudits-ySnizdMG.mjs.map → processAudits-D89tICM4.mjs.map} +1 -1
  185. package/dist/{publisher-BrFOF847.mjs → publisher-CGEo8UKD.mjs} +1 -1
  186. package/dist/{publisher-BrFOF847.mjs.map → publisher-CGEo8UKD.mjs.map} +1 -1
  187. package/dist/{publisher-lFQleddL.cjs → publisher-CqGsXB2X.cjs} +1 -1
  188. package/dist/{publisher-lFQleddL.cjs.map → publisher-CqGsXB2X.cjs.map} +1 -1
  189. package/dist/queue/index.cjs +92 -30
  190. package/dist/queue/index.cjs.map +1 -1
  191. package/dist/queue/index.d.cts +19 -4
  192. package/dist/queue/index.d.cts.map +1 -1
  193. package/dist/queue/index.d.mts +22 -6
  194. package/dist/queue/index.d.mts.map +1 -1
  195. package/dist/queue/index.mjs +90 -29
  196. package/dist/queue/index.mjs.map +1 -1
  197. package/dist/rest-api.cjs +187 -0
  198. package/dist/rest-api.cjs.map +1 -0
  199. package/dist/rest-api.d.cts +221 -0
  200. package/dist/rest-api.d.cts.map +1 -0
  201. package/dist/rest-api.d.mts +221 -0
  202. package/dist/rest-api.d.mts.map +1 -0
  203. package/dist/rest-api.mjs +186 -0
  204. package/dist/rest-api.mjs.map +1 -0
  205. package/dist/site.cjs +48 -0
  206. package/dist/site.cjs.map +1 -0
  207. package/dist/site.d.cts +101 -0
  208. package/dist/site.d.cts.map +1 -0
  209. package/dist/site.d.mts +101 -0
  210. package/dist/site.d.mts.map +1 -0
  211. package/dist/site.mjs +47 -0
  212. package/dist/site.mjs.map +1 -0
  213. package/dist/subscribers/index.cjs +35 -27
  214. package/dist/subscribers/index.cjs.map +1 -1
  215. package/dist/subscribers/index.d.cts +20 -5
  216. package/dist/subscribers/index.d.cts.map +1 -1
  217. package/dist/subscribers/index.d.mts +23 -7
  218. package/dist/subscribers/index.d.mts.map +1 -1
  219. package/dist/subscribers/index.mjs +34 -27
  220. package/dist/subscribers/index.mjs.map +1 -1
  221. package/dist/surfaceEnv-BFXEms2f.cjs +39 -0
  222. package/dist/surfaceEnv-BFXEms2f.cjs.map +1 -0
  223. package/dist/surfaceEnv-C3Ktahea.mjs +27 -0
  224. package/dist/surfaceEnv-C3Ktahea.mjs.map +1 -0
  225. package/dist/{telemetry-3vdxGn4q.d.mts → telemetry-C3L0iS28.d.cts} +2 -2
  226. package/dist/{telemetry-3vdxGn4q.d.mts.map → telemetry-C3L0iS28.d.cts.map} +1 -1
  227. package/dist/{telemetry-Dqx-D3F7.d.cts → telemetry-D7bVFLGi.d.mts} +2 -2
  228. package/dist/{telemetry-Dqx-D3F7.d.cts.map → telemetry-D7bVFLGi.d.mts.map} +1 -1
  229. package/dist/topic/index.cjs +56 -13
  230. package/dist/topic/index.cjs.map +1 -1
  231. package/dist/topic/index.d.cts +2 -2
  232. package/dist/topic/index.d.cts.map +1 -1
  233. package/dist/topic/index.d.mts +2 -2
  234. package/dist/topic/index.d.mts.map +1 -1
  235. package/dist/topic/index.mjs +54 -12
  236. package/dist/topic/index.mjs.map +1 -1
  237. package/dist/{types-BDNGr7pv.d.mts → types-BlAkSuGI.d.cts} +1 -1
  238. package/dist/{types-BDNGr7pv.d.mts.map → types-BlAkSuGI.d.cts.map} +1 -1
  239. package/dist/{types-BdAaYDvd.d.cts → types-aKksMEWL.d.mts} +1 -1
  240. package/dist/{types-BdAaYDvd.d.cts.map → types-aKksMEWL.d.mts.map} +1 -1
  241. package/dist/types.d.cts +1 -1
  242. package/dist/types.d.mts +1 -1
  243. package/package.json +155 -23
  244. package/CHANGELOG.md +0 -366
  245. package/dist/Construct-DCMuYOox.d.mts.map +0 -1
  246. package/dist/Construct-_1wX7p_Y.d.cts.map +0 -1
  247. package/dist/Construct-r0U2zBwW.mjs.map +0 -1
  248. package/dist/Construct-vXMZJgRp.cjs.map +0 -1
  249. package/dist/Endpoint-CAzNbDEt.d.cts.map +0 -1
  250. package/dist/Endpoint-CLPSIl6S.d.mts.map +0 -1
  251. package/dist/HonoEndpointAdaptor-CkJENANP.cjs.map +0 -1
  252. package/dist/HonoEndpointAdaptor-DJDT3PMx.mjs.map +0 -1
  253. package/dist/Queue-DaxjwmOQ.d.cts.map +0 -1
  254. package/dist/Queue-HBDf0fqz.d.mts.map +0 -1
  255. package/dist/Subscriber-D8Xm-86W.d.mts.map +0 -1
  256. package/dist/Topic-C5ZMfveW.d.cts.map +0 -1
  257. package/dist/Topic-DT10AqHk.d.mts.map +0 -1
  258. package/dist/endpoints/index.cjs.map +0 -1
  259. package/dist/endpoints/index.d.cts.map +0 -1
  260. package/dist/endpoints/index.d.mts.map +0 -1
  261. package/dist/endpoints/index.mjs.map +0 -1
  262. package/dist/functions-B-qt91O7.mjs.map +0 -1
  263. package/dist/functions-C8i1kCMM.cjs.map +0 -1
  264. package/dist/index-BGeTScmi.d.cts.map +0 -1
  265. package/dist/index-DP6fqv0I.d.mts.map +0 -1
  266. package/dist/lazyAccessors-DfqZR6C4.mjs.map +0 -1
  267. package/dist/lazyAccessors-DmTG8sQH.cjs.map +0 -1
  268. package/src/Construct.ts +0 -204
  269. package/src/__benchmarks__/build-time-optimization.bench.ts +0 -274
  270. package/src/__benchmarks__/endpoint.bench.ts +0 -494
  271. package/src/__benchmarks__/fixtures.ts +0 -241
  272. package/src/__benchmarks__/hono-adaptor.bench.ts +0 -533
  273. package/src/__benchmarks__/hono-server.bench.ts +0 -249
  274. package/src/__benchmarks__/response-builder.bench.ts +0 -428
  275. package/src/__benchmarks__/strategies/strategy-a-lazy-services.ts +0 -319
  276. package/src/__benchmarks__/strategies/strategy-c-middleware.ts +0 -530
  277. package/src/__benchmarks__/strategies/strategy-d-opt-in-events.ts +0 -567
  278. package/src/__tests__/Construct.environment.spec.ts +0 -704
  279. package/src/__tests__/publisher.setting.spec.ts +0 -508
  280. package/src/__tests__/publisher.spec.ts +0 -452
  281. package/src/adaptors/aws.ts +0 -6
  282. package/src/adaptors/hono.ts +0 -1
  283. package/src/adaptors/testing.ts +0 -11
  284. package/src/crons/AWSScheduledFunction.ts +0 -73
  285. package/src/crons/Cron.ts +0 -149
  286. package/src/crons/CronBuilder.ts +0 -271
  287. package/src/crons/__tests__/AWSScheduledFunction.spec.ts +0 -152
  288. package/src/crons/__tests__/Cron.spec.ts +0 -464
  289. package/src/crons/__tests__/CronBuilder.state-isolation.spec.ts +0 -227
  290. package/src/crons/index.ts +0 -12
  291. package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +0 -677
  292. package/src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts +0 -105
  293. package/src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts +0 -97
  294. package/src/endpoints/Authorizer.ts +0 -152
  295. package/src/endpoints/Endpoint.ts +0 -1287
  296. package/src/endpoints/EndpointBuilder.ts +0 -758
  297. package/src/endpoints/EndpointFactory.ts +0 -1148
  298. package/src/endpoints/HonoEndpointAdaptor.ts +0 -677
  299. package/src/endpoints/MswEndpointAdaptor.ts +0 -226
  300. package/src/endpoints/TestEndpointAdaptor.ts +0 -422
  301. package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.audits.spec.ts +0 -499
  302. package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.events.spec.ts +0 -560
  303. package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.spec.ts +0 -1304
  304. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.audits.spec.ts +0 -626
  305. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.events.spec.ts +0 -732
  306. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.factory-publisher.spec.ts +0 -296
  307. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.kysely-audit.integration.spec.ts +0 -951
  308. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.responseType.spec.ts +0 -111
  309. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.rls.spec.ts +0 -307
  310. package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.spec.ts +0 -629
  311. package/src/endpoints/__tests__/Authorizer.spec.ts +0 -286
  312. package/src/endpoints/__tests__/Endpoint.cookies.spec.ts +0 -207
  313. package/src/endpoints/__tests__/Endpoint.headers.spec.ts +0 -187
  314. package/src/endpoints/__tests__/Endpoint.manifest.spec.ts +0 -175
  315. package/src/endpoints/__tests__/Endpoint.spec.ts +0 -857
  316. package/src/endpoints/__tests__/EndpointBuilder.audit.spec.ts +0 -448
  317. package/src/endpoints/__tests__/EndpointBuilder.responseType.spec.ts +0 -47
  318. package/src/endpoints/__tests__/EndpointBuilder.spec.ts +0 -523
  319. package/src/endpoints/__tests__/EndpointFactory.authorizers.spec.ts +0 -492
  320. package/src/endpoints/__tests__/EndpointFactory.database-auditor.spec.ts +0 -509
  321. package/src/endpoints/__tests__/EndpointFactory.reference-audit.spec.ts +0 -190
  322. package/src/endpoints/__tests__/EndpointFactory.spec.ts +0 -479
  323. package/src/endpoints/__tests__/EndpointFactory.state-isolation.spec.ts +0 -155
  324. package/src/endpoints/__tests__/HonoEndpointAdaptor.audit-transactions.spec.ts +0 -703
  325. package/src/endpoints/__tests__/HonoEndpointAdaptor.audits.spec.ts +0 -632
  326. package/src/endpoints/__tests__/HonoEndpointAdaptor.events.spec.ts +0 -577
  327. package/src/endpoints/__tests__/HonoEndpointAdaptor.kysely-audit.integration.spec.ts +0 -1067
  328. package/src/endpoints/__tests__/HonoEndpointAdaptor.openapi.spec.ts +0 -317
  329. package/src/endpoints/__tests__/HonoEndpointAdaptor.pgboss-publisher.spec.ts +0 -289
  330. package/src/endpoints/__tests__/HonoEndpointAdaptor.responseType.spec.ts +0 -128
  331. package/src/endpoints/__tests__/HonoEndpointAdaptor.spec.ts +0 -1207
  332. package/src/endpoints/__tests__/MswEndpointAdaptor.spec.ts +0 -211
  333. package/src/endpoints/__tests__/ResponseBuilder.spec.ts +0 -235
  334. package/src/endpoints/__tests__/TestEndpointAdaptor.audits.spec.ts +0 -602
  335. package/src/endpoints/__tests__/TestEndpointAdaptor.spec.ts +0 -1044
  336. package/src/endpoints/__tests__/__snapshots__/HonoEndpointAdaptor.spec.ts.snap +0 -54
  337. package/src/endpoints/__tests__/endpoint-types.test.ts +0 -88
  338. package/src/endpoints/__tests__/helpers.spec.ts +0 -37
  339. package/src/endpoints/__tests__/lazyAccessors.spec.ts +0 -330
  340. package/src/endpoints/__tests__/processAudits.spec.ts +0 -631
  341. package/src/endpoints/audit.ts +0 -87
  342. package/src/endpoints/helpers.ts +0 -98
  343. package/src/endpoints/index.ts +0 -42
  344. package/src/endpoints/lazyAccessors.ts +0 -241
  345. package/src/endpoints/parseHonoQuery.ts +0 -16
  346. package/src/endpoints/parseQueryParams.ts +0 -32
  347. package/src/endpoints/processAudits.ts +0 -371
  348. package/src/endpoints/rls.ts +0 -67
  349. package/src/functions/AWSLambdaFunction.ts +0 -348
  350. package/src/functions/BaseFunctionBuilder.ts +0 -201
  351. package/src/functions/Function.ts +0 -238
  352. package/src/functions/FunctionBuilder.ts +0 -391
  353. package/src/functions/FunctionExecutionWrapper.ts +0 -216
  354. package/src/functions/TestFunctionAdaptor.ts +0 -217
  355. package/src/functions/__tests__/AWSLambdaFunctionAdaptor.spec.ts +0 -513
  356. package/src/functions/__tests__/Function.audits.spec.ts +0 -393
  357. package/src/functions/__tests__/Function.spec.ts +0 -477
  358. package/src/functions/__tests__/FunctionBuilder.state-isolation.spec.ts +0 -207
  359. package/src/functions/__tests__/TestFunctionAdaptor.spec.ts +0 -480
  360. package/src/functions/index.ts +0 -12
  361. package/src/index.ts +0 -23
  362. package/src/publisher.ts +0 -93
  363. package/src/queue/AWSLambdaQueueAdaptor.ts +0 -162
  364. package/src/queue/Queue.ts +0 -128
  365. package/src/queue/QueueBuilder.ts +0 -115
  366. package/src/queue/TestQueueAdaptor.ts +0 -63
  367. package/src/queue/__tests__/QueueBuilder.spec.ts +0 -137
  368. package/src/queue/index.ts +0 -12
  369. package/src/subscribers/AWSLambdaSubscriberAdaptor.ts +0 -342
  370. package/src/subscribers/Subscriber.ts +0 -117
  371. package/src/subscribers/SubscriberBuilder.ts +0 -186
  372. package/src/subscribers/TestSubscriberAdaptor.ts +0 -133
  373. package/src/subscribers/__tests__/AWSLambdaSubscriberAdaptor.spec.ts +0 -1018
  374. package/src/subscribers/__tests__/Subscriber.spec.ts +0 -430
  375. package/src/subscribers/__tests__/TestSubscriberAdaptor.spec.ts +0 -652
  376. package/src/subscribers/index.ts +0 -6
  377. package/src/telemetry.ts +0 -103
  378. package/src/topic/Topic.ts +0 -103
  379. package/src/topic/TopicBuilder.ts +0 -51
  380. package/src/topic/__tests__/TopicBuilder.spec.ts +0 -82
  381. package/src/topic/index.ts +0 -11
  382. package/src/types.ts +0 -13
  383. package/test.ts +0 -91
  384. package/tsconfig.json +0 -9
  385. package/tsdown.config.ts +0 -34
@@ -1,677 +0,0 @@
1
- import type { AuditableAction, AuditStorage } from '@geekmidas/audit';
2
- import { withRlsContext } from '@geekmidas/db/rls';
3
- import type { EnvironmentParser } from '@geekmidas/envkit';
4
- import type { Logger } from '@geekmidas/logger';
5
- import middy, { type MiddlewareObj } from '@middy/core';
6
- import type { StandardSchemaV1 } from '@standard-schema/spec';
7
- import type {
8
- APIGatewayProxyEvent,
9
- APIGatewayProxyEventV2,
10
- Context,
11
- } from 'aws-lambda';
12
- import set from 'lodash.set';
13
- import type { Telemetry } from '../telemetry';
14
- import type { HttpMethod } from '../types';
15
- import { Endpoint, type EndpointSchemas, ResponseBuilder } from './Endpoint';
16
-
17
- /**
18
- * Telescope integration for request recording.
19
- * Uses Middy middleware pattern for compatibility with existing telescope package.
20
- */
21
- export interface TelescopeIntegration {
22
- middleware: MiddlewareObj<any, any, Error, Context>;
23
- }
24
-
25
- import {
26
- ForbiddenError,
27
- UnprocessableEntityError,
28
- wrapError,
29
- } from '@geekmidas/errors';
30
- import type { EventPublisher } from '@geekmidas/events';
31
- import type {
32
- InferComposableStandardSchema,
33
- InferStandardSchema,
34
- } from '@geekmidas/schema';
35
- import {
36
- runWithRequestContext,
37
- type Service,
38
- ServiceDiscovery,
39
- type ServiceRecord,
40
- } from '@geekmidas/services';
41
- import { publishConstructEvents } from '../publisher';
42
- import type { MappedAudit } from './audit';
43
- import type { CookieFn, HeaderFn } from './Endpoint';
44
- import {
45
- createAuditContext,
46
- executeWithAuditTransaction,
47
- } from './processAudits';
48
-
49
- // Helper function to publish events
50
-
51
- /**
52
- * Options for Amazon API Gateway endpoint adaptors
53
- */
54
- export interface AmazonApiGatewayEndpointOptions {
55
- /**
56
- * Telescope integration for request recording and monitoring.
57
- *
58
- * @example
59
- * ```typescript
60
- * import { telescopeMiddleware } from '@geekmidas/telescope/lambda';
61
- *
62
- * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {
63
- * telescope: { middleware: telescopeMiddleware(telescope) },
64
- * });
65
- * ```
66
- */
67
- telescope?: TelescopeIntegration;
68
-
69
- /**
70
- * Telemetry integration for distributed tracing.
71
- * Works with any OpenTelemetry-compatible backend.
72
- *
73
- * @example
74
- * ```typescript
75
- * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';
76
- *
77
- * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {
78
- * telemetry: new OTelTelemetry(),
79
- * });
80
- * ```
81
- */
82
- telemetry?: Telemetry;
83
- }
84
-
85
- export abstract class AmazonApiGatewayEndpoint<
86
- THandler extends
87
- | AmazonApiGatewayV1EndpointHandler
88
- | AmazonApiGatewayV2EndpointHandler,
89
- TEvent extends HandlerEvent<THandler>,
90
- TRoute extends string,
91
- TMethod extends HttpMethod,
92
- TInput extends EndpointSchemas = {},
93
- TOutSchema extends StandardSchemaV1 | undefined = undefined,
94
- TServices extends Service[] = [],
95
- TLogger extends Logger = Logger,
96
- TSession = unknown,
97
- TEventPublisher extends EventPublisher<any> | undefined = undefined,
98
- TEventPublisherServiceName extends string = string,
99
- TAuditStorage extends AuditStorage | undefined = undefined,
100
- TAuditStorageServiceName extends string = string,
101
- TAuditAction extends AuditableAction<string, unknown> = AuditableAction<
102
- string,
103
- unknown
104
- >,
105
- > {
106
- protected options: AmazonApiGatewayEndpointOptions;
107
-
108
- constructor(
109
- protected envParser: EnvironmentParser<{}>,
110
- protected readonly endpoint: Endpoint<
111
- TRoute,
112
- TMethod,
113
- TInput,
114
- TOutSchema,
115
- TServices,
116
- TLogger,
117
- TSession,
118
- TEventPublisher,
119
- TEventPublisherServiceName,
120
- TAuditStorage,
121
- TAuditStorageServiceName,
122
- TAuditAction
123
- >,
124
- options: AmazonApiGatewayEndpointOptions = {},
125
- ) {
126
- this.options = options;
127
- }
128
-
129
- private error(): Middleware<TEvent, TInput, TServices, TLogger> {
130
- return {
131
- onError: (req) => {
132
- (req.event.logger || this.endpoint.logger).error(
133
- req.error || {},
134
- 'Error processing request',
135
- );
136
- const wrappedError = wrapError(req.error);
137
-
138
- // Set the response with the proper status code from the HttpError
139
- req.response = {
140
- statusCode: wrappedError.statusCode,
141
- body: wrappedError.body,
142
- };
143
- },
144
- };
145
- }
146
- abstract getInput(e: TEvent): GetInputResponse;
147
-
148
- /**
149
- * Decodes the raw body from an API Gateway event.
150
- * Uses Content-Type to decide parsing strategy (like Express/Fastify/Hono):
151
- * - `application/json` (or missing) → JSON.parse the decoded string
152
- * - Anything else → return decoded string as-is, let the schema handle it
153
- *
154
- * Defaults to JSON when no Content-Type is provided for backwards compatibility.
155
- */
156
- static decodeBody(
157
- body: string | undefined | null,
158
- isBase64Encoded: boolean | undefined,
159
- contentType: string | undefined,
160
- ): any {
161
- if (!body) return undefined;
162
-
163
- const raw = isBase64Encoded
164
- ? Buffer.from(body, 'base64').toString('utf-8')
165
- : body;
166
-
167
- const isJson =
168
- !contentType || contentType.toLowerCase().includes('application/json');
169
- if (isJson) {
170
- return JSON.parse(raw);
171
- }
172
-
173
- return raw;
174
- }
175
-
176
- protected getCookies(e: TEvent): CookieFn {
177
- const headers = e.headers as Record<string, string>;
178
- return Endpoint.createCookies(headers?.cookie);
179
- }
180
-
181
- private input(): Middleware<TEvent, TInput, TServices, TLogger> {
182
- return {
183
- before: async (req) => {
184
- try {
185
- const { body, query, params } = this.getInput(req.event);
186
- const headers = req.event.headers as Record<string, string>;
187
- const header = Endpoint.createHeaders(headers);
188
- const cookie = this.getCookies(req.event);
189
-
190
- set(req.event, 'body', await this.endpoint.parseInput(body, 'body'));
191
-
192
- set(
193
- req.event,
194
- 'query',
195
- await this.endpoint.parseInput(query, 'query'),
196
- );
197
- set(
198
- req.event,
199
- 'params',
200
- await this.endpoint.parseInput(params, 'params'),
201
- );
202
- set(req.event, 'header', header);
203
- set(req.event, 'cookie', cookie);
204
- } catch (error) {
205
- // Convert validation errors to 422 Unprocessable Entity
206
- if (error && typeof error === 'object' && Array.isArray(error)) {
207
- throw new UnprocessableEntityError('Validation failed', error);
208
- }
209
- throw error;
210
- }
211
- },
212
- };
213
- }
214
-
215
- abstract getLoggerContext(data: TEvent, context: Context): LoggerContext;
216
-
217
- private logger(): Middleware<TEvent, TInput, TServices, TLogger> {
218
- return {
219
- before: (req) => {
220
- req.event.logger = this.endpoint.logger.child({
221
- route: this.endpoint.route,
222
- host: req.event.headers?.host,
223
- method: this.endpoint.method,
224
- ...this.getLoggerContext(req.event, req.context),
225
- }) as TLogger;
226
- },
227
- };
228
- }
229
- private services(): Middleware<TEvent, TInput, TServices, TLogger> {
230
- return {
231
- before: async (req) => {
232
- const _logger = req.event.logger as TLogger;
233
- const serviceDiscovery = ServiceDiscovery.getInstance<
234
- ServiceRecord<TServices>
235
- >(this.envParser);
236
-
237
- const services = await serviceDiscovery.register(
238
- this.endpoint.services,
239
- );
240
-
241
- req.event.services = services;
242
- },
243
- };
244
- }
245
-
246
- private authorize(): Middleware<TEvent, TInput, TServices, TLogger> {
247
- return {
248
- before: async (req) => {
249
- const logger = req.event.logger as TLogger;
250
- const services = req.event.services;
251
- const header = req.event.header;
252
- const cookie = req.event.cookie;
253
- const session = req.event.session as TSession;
254
-
255
- const isAuthorized = await this.endpoint.authorize({
256
- header,
257
- cookie,
258
- services,
259
- logger,
260
- session,
261
- ...((req.event as any).db !== undefined && {
262
- db: (req.event as any).db,
263
- }),
264
- body: (req.event as any).body,
265
- query: (req.event as any).query,
266
- params: (req.event as any).params,
267
- } as any);
268
-
269
- if (!isAuthorized) {
270
- logger.warn('Forbidden access attempt');
271
- throw new ForbiddenError(
272
- 'Forbidden access to the endpoint',
273
- 'You do not have permission to access this resource.',
274
- );
275
- }
276
- },
277
- };
278
- }
279
-
280
- private database(): Middleware<TEvent, TInput, TServices, TLogger> {
281
- return {
282
- before: async (req) => {
283
- if (!this.endpoint.databaseService) {
284
- return;
285
- }
286
-
287
- const _logger = req.event.logger as TLogger;
288
- const serviceDiscovery = ServiceDiscovery.getInstance<
289
- ServiceRecord<TServices>
290
- >(this.envParser);
291
-
292
- const db = await serviceDiscovery
293
- .register([this.endpoint.databaseService])
294
- .then(
295
- (s) =>
296
- s[this.endpoint.databaseService?.serviceName as keyof typeof s],
297
- );
298
-
299
- (req.event as any).db = db;
300
- },
301
- };
302
- }
303
-
304
- private session(): Middleware<TEvent, TInput, TServices, TLogger> {
305
- return {
306
- before: async (req) => {
307
- const logger = req.event.logger as TLogger;
308
- const services = req.event.services;
309
- const db = (req.event as any).db;
310
- req.event.session = (await this.endpoint.getSession({
311
- logger,
312
- services,
313
- header: req.event.header,
314
- cookie: req.event.cookie,
315
- ...(db !== undefined && { db }),
316
- } as any)) as TSession;
317
- },
318
- };
319
- }
320
-
321
- private events(): Middleware<TEvent, TInput, TServices, TLogger> {
322
- return {
323
- after: async (req) => {
324
- const event = req.event;
325
- const response = (event as any)
326
- .__response as InferStandardSchema<TOutSchema>;
327
- const statusCode = req.response?.statusCode ?? this.endpoint.status;
328
-
329
- // Only publish events on successful responses (2xx status codes)
330
- // Note: Audits are processed inside the handler's transaction
331
- if (Endpoint.isSuccessStatus(statusCode)) {
332
- const logger = event.logger as TLogger;
333
- const serviceDiscovery = ServiceDiscovery.getInstance<
334
- ServiceRecord<TServices>
335
- >(this.envParser);
336
-
337
- // Publish events
338
- await publishConstructEvents(
339
- this.endpoint,
340
- response,
341
- serviceDiscovery,
342
- logger,
343
- );
344
- }
345
- },
346
- };
347
- }
348
-
349
- private async _handler(
350
- event: Event<TEvent, TInput, TServices, TLogger, TSession>,
351
- ) {
352
- const input = this.endpoint.refineInput(event);
353
- const logger = event.logger as TLogger;
354
- const serviceDiscovery = ServiceDiscovery.getInstance<
355
- ServiceRecord<TServices>
356
- >(this.envParser);
357
-
358
- // Create audit context if audit storage is configured
359
- const auditContext = await createAuditContext(
360
- this.endpoint,
361
- serviceDiscovery,
362
- logger,
363
- {
364
- session: event.session,
365
- header: event.header,
366
- cookie: event.cookie,
367
- services: event.services as Record<string, unknown>,
368
- },
369
- );
370
-
371
- // Warn if declarative audits are configured but no audit storage
372
- const audits = this.endpoint.audits as MappedAudit<
373
- TAuditAction,
374
- TOutSchema
375
- >[];
376
- if (!auditContext && audits?.length) {
377
- logger.warn('No auditor storage service available');
378
- }
379
-
380
- // Get pre-resolved database from middleware
381
- const rawDb = (event as any).db;
382
-
383
- // Extract RLS context if configured and not bypassed
384
- const rlsActive =
385
- this.endpoint.rlsConfig &&
386
- !this.endpoint.rlsBypass &&
387
- rawDb !== undefined;
388
- const rlsContext = rlsActive
389
- ? await this.endpoint.rlsConfig?.extractor({
390
- services: event.services as ServiceRecord<TServices>,
391
- session: event.session,
392
- header: event.header,
393
- cookie: event.cookie,
394
- logger,
395
- })
396
- : undefined;
397
-
398
- // Execute handler with automatic audit transaction support
399
- const result = await executeWithAuditTransaction(
400
- auditContext,
401
- async (auditor) => {
402
- // Use audit transaction as db only if the storage uses the same database service
403
- const sameDatabase =
404
- auditContext?.storage?.databaseServiceName &&
405
- auditContext.storage.databaseServiceName ===
406
- this.endpoint.databaseService?.serviceName;
407
- const baseDb = sameDatabase
408
- ? (auditor?.getTransaction?.() ?? rawDb)
409
- : rawDb;
410
-
411
- // Helper to execute handler with given db
412
- const executeHandler = async (db: any) => {
413
- const responseBuilder = new ResponseBuilder();
414
- const response = await this.endpoint.handler(
415
- {
416
- header: event.header,
417
- cookie: event.cookie,
418
- logger: event.logger,
419
- services: event.services,
420
- session: event.session,
421
- auditor,
422
- db,
423
- ...input,
424
- } as any,
425
- responseBuilder,
426
- );
427
-
428
- // Check if response has metadata
429
- let data = response;
430
- let metadata = responseBuilder.getMetadata();
431
-
432
- if (Endpoint.hasMetadata(response)) {
433
- data = response.data;
434
- metadata = response.metadata;
435
- }
436
-
437
- const output = this.endpoint.outputSchema
438
- ? await this.endpoint.parseOutput(data)
439
- : undefined;
440
-
441
- return { output, metadata, responseBuilder };
442
- };
443
-
444
- // If RLS is active, wrap handler with RLS context
445
- if (rlsActive && rlsContext && baseDb) {
446
- return withRlsContext(
447
- baseDb,
448
- rlsContext,
449
- async (trx: any) => executeHandler(trx),
450
- { prefix: this.endpoint.rlsConfig?.prefix },
451
- );
452
- }
453
-
454
- return executeHandler(baseDb);
455
- },
456
- // Process declarative audits after handler (inside transaction)
457
- async (result, auditor) => {
458
- if (!audits?.length) return;
459
-
460
- for (const audit of audits) {
461
- if (audit.when && !audit.when(result.output as any)) {
462
- continue;
463
- }
464
- const payload = audit.payload(result.output as any);
465
- const entityId = audit.entityId?.(result.output as any);
466
- auditor.audit(audit.type as any, payload as any, {
467
- table: audit.table,
468
- entityId,
469
- });
470
- }
471
- },
472
- // Pass rawDb so storage can reuse existing transactions
473
- { db: rawDb },
474
- );
475
-
476
- const { output, metadata } = result;
477
- const isJsonResponse = this.endpoint.responseType === 'application/json';
478
- const body =
479
- output === undefined
480
- ? undefined
481
- : isJsonResponse
482
- ? JSON.stringify(output)
483
- : typeof output === 'string'
484
- ? output
485
- : String(output);
486
-
487
- // Store response for middleware access
488
- (event as any).__response = output;
489
-
490
- // Build response with metadata
491
- const lambdaResponse: AmazonApiGatewayEndpointHandlerResponse = {
492
- statusCode: metadata.status ?? this.endpoint.status,
493
- body,
494
- };
495
-
496
- // Compose headers. For non-JSON responseType, emit a default
497
- // Content-Type header which metadata.headers (r.header()) can override.
498
- const baseHeaders: Record<string, string> | undefined = isJsonResponse
499
- ? undefined
500
- : { 'content-type': this.endpoint.responseType };
501
-
502
- if (
503
- baseHeaders ||
504
- (metadata.headers && Object.keys(metadata.headers).length > 0)
505
- ) {
506
- lambdaResponse.headers = {
507
- ...(baseHeaders ?? {}),
508
- ...(metadata.headers ?? {}),
509
- };
510
- }
511
-
512
- // Format cookies as Set-Cookie headers
513
- if (metadata.cookies && metadata.cookies.size > 0) {
514
- const setCookieHeaders: string[] = [];
515
- for (const [name, { value, options }] of metadata.cookies) {
516
- setCookieHeaders.push(
517
- Endpoint.formatCookieHeader(name, value, options),
518
- );
519
- }
520
-
521
- if (setCookieHeaders.length > 0) {
522
- lambdaResponse.multiValueHeaders = {
523
- ...lambdaResponse.multiValueHeaders,
524
- 'Set-Cookie': setCookieHeaders,
525
- };
526
- }
527
- }
528
-
529
- return lambdaResponse;
530
- }
531
-
532
- /**
533
- * Convert Telemetry interface to Middy middleware
534
- */
535
- private telemetry(): Middleware<TEvent, TInput, TServices, TLogger> | null {
536
- if (!this.options.telemetry) {
537
- return null;
538
- }
539
-
540
- const telemetry = this.options.telemetry;
541
- let ctx: any;
542
-
543
- return {
544
- before: (request) => {
545
- ctx = telemetry.onRequestStart({
546
- event: request.event,
547
- context: request.context,
548
- });
549
- },
550
- after: (request) => {
551
- if (ctx) {
552
- telemetry.onRequestEnd(ctx, {
553
- statusCode: request.response?.statusCode ?? 200,
554
- body: request.response?.body,
555
- headers: request.response?.headers,
556
- });
557
- }
558
- },
559
- onError: (request) => {
560
- if (ctx && request.error) {
561
- telemetry.onRequestError(
562
- ctx,
563
- request.error instanceof Error
564
- ? request.error
565
- : new Error(String(request.error)),
566
- );
567
- }
568
- },
569
- };
570
- }
571
-
572
- get handler() {
573
- const handler = this._handler.bind(this);
574
- let chain = middy(handler)
575
- .use(this.logger())
576
- .use(this.error())
577
- .use(this.services())
578
- .use(this.input())
579
- .use(this.database())
580
- .use(this.session())
581
- .use(this.authorize())
582
- .use(this.events());
583
-
584
- // Add telemetry middleware if configured (runs early for span creation)
585
- const telemetryMiddleware = this.telemetry();
586
- if (telemetryMiddleware) {
587
- chain = chain.use(telemetryMiddleware);
588
- }
589
-
590
- // Add Telescope middleware if configured (runs first/last in chain)
591
- if (this.options.telescope?.middleware) {
592
- chain = chain.use(this.options.telescope.middleware);
593
- }
594
-
595
- // Wrap entire Middy chain in request context for service access
596
- const wrappedHandler = async (event: TEvent, context: Context) => {
597
- const startTime = Date.now();
598
- const requestId = context.awsRequestId;
599
- const logger = this.endpoint.logger.child({ requestId }) as TLogger;
600
-
601
- // Cast event to any since Middy middlewares enrich the event with
602
- // services, logger, session, etc. during the middleware chain execution
603
- return runWithRequestContext({ logger, requestId, startTime }, () =>
604
- chain(event as unknown as Parameters<typeof chain>[0], context),
605
- );
606
- };
607
-
608
- return wrappedHandler as unknown as THandler;
609
- }
610
- }
611
-
612
- export type Event<
613
- TEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,
614
- TInput extends EndpointSchemas = {},
615
- TServices extends Service[] = [],
616
- TLogger extends Logger = Logger,
617
- TSession = unknown,
618
- > = {
619
- services: ServiceRecord<TServices>;
620
- logger: TLogger;
621
- header: HeaderFn;
622
- cookie: CookieFn;
623
- session: TSession;
624
- } & TEvent &
625
- InferComposableStandardSchema<TInput>;
626
-
627
- type Middleware<
628
- TEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,
629
- TInput extends EndpointSchemas = {},
630
- TServices extends Service[] = [],
631
- TLogger extends Logger = Logger,
632
- TSession = unknown,
633
- > = MiddlewareObj<Event<TEvent, TInput, TServices, TLogger, TSession>>;
634
-
635
- export type AmazonApiGatewayEndpointHandlerResponse = {
636
- statusCode: number;
637
- body: string | undefined;
638
- headers?: Record<string, string>;
639
- multiValueHeaders?: Record<string, string[]>;
640
- };
641
-
642
- export type LoggerContext = {
643
- fn: {
644
- name: string;
645
- version: string;
646
- };
647
- req: {
648
- id: string | undefined;
649
- awsRequestId: string;
650
- path: string;
651
- ip: string | undefined;
652
- userAgent: string | undefined;
653
- };
654
- };
655
-
656
- export type GetInputResponse = {
657
- body: any;
658
- query: any;
659
- params: any;
660
- };
661
-
662
- export type AmazonApiGatewayV1EndpointHandler = (
663
- event: APIGatewayProxyEvent,
664
- context: Context,
665
- ) => Promise<AmazonApiGatewayEndpointHandlerResponse>;
666
-
667
- export type AmazonApiGatewayV2EndpointHandler = (
668
- event: APIGatewayProxyEventV2,
669
- context: Context,
670
- ) => Promise<AmazonApiGatewayEndpointHandlerResponse>;
671
-
672
- export type HandlerEvent<T extends Function> = T extends (
673
- event: infer E,
674
- context: Context,
675
- ) => any
676
- ? E
677
- : never;