@geekmidas/constructs 9.3.0 → 9.4.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 (164) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/{AWSScheduledFunction-CU7mMGFA.mjs → AWSScheduledFunction-BXmRm9W6.mjs} +4 -3
  3. package/dist/{AWSScheduledFunction-CU7mMGFA.mjs.map → AWSScheduledFunction-BXmRm9W6.mjs.map} +1 -1
  4. package/dist/{AWSScheduledFunction-CKhVurOa.cjs → AWSScheduledFunction-C-JBSNak.cjs} +6 -5
  5. package/dist/{AWSScheduledFunction-CKhVurOa.cjs.map → AWSScheduledFunction-C-JBSNak.cjs.map} +1 -1
  6. package/dist/{AWSScheduledFunction-Dg6TPIxn.d.mts → AWSScheduledFunction-DgQuL5kt.d.mts} +8 -2
  7. package/dist/AWSScheduledFunction-DgQuL5kt.d.mts.map +1 -0
  8. package/dist/{AWSScheduledFunction-DAGP_vz5.d.cts → AWSScheduledFunction-DoDZR8E6.d.cts} +8 -2
  9. package/dist/AWSScheduledFunction-DoDZR8E6.d.cts.map +1 -0
  10. package/dist/{Construct-D_3yZ9m5.d.cts → Construct-BEh2DSMe.d.cts} +7 -13
  11. package/dist/Construct-BEh2DSMe.d.cts.map +1 -0
  12. package/dist/{Construct-D09WUUOf.cjs → Construct-Cf_0pAvo.cjs} +2 -10
  13. package/dist/Construct-Cf_0pAvo.cjs.map +1 -0
  14. package/dist/{Construct-DsqpiAym.d.mts → Construct-CgluLUuF.d.mts} +7 -13
  15. package/dist/Construct-CgluLUuF.d.mts.map +1 -0
  16. package/dist/{Construct-D0uZvbr3.mjs → Construct-D5LZBFhb.mjs} +3 -11
  17. package/dist/Construct-D5LZBFhb.mjs.map +1 -0
  18. package/dist/{Endpoint-CxBdXNZm.d.cts → Endpoint-1u_i-nCT.d.cts} +2 -2
  19. package/dist/{Endpoint-CxBdXNZm.d.cts.map → Endpoint-1u_i-nCT.d.cts.map} +1 -1
  20. package/dist/{Endpoint-DEydLuBs.d.mts → Endpoint-CypDvYJW.d.mts} +3 -3
  21. package/dist/Endpoint-CypDvYJW.d.mts.map +1 -0
  22. package/dist/{HonoEndpointAdaptor-CJfFQ5KR.mjs → HonoEndpointAdaptor-C-mPVfwk.mjs} +11 -18
  23. package/dist/HonoEndpointAdaptor-C-mPVfwk.mjs.map +1 -0
  24. package/dist/{HonoEndpointAdaptor-DCD0rhFg.cjs → HonoEndpointAdaptor-D_2UDPNs.cjs} +12 -19
  25. package/dist/HonoEndpointAdaptor-D_2UDPNs.cjs.map +1 -0
  26. package/dist/{Queue-Brw--scg.d.cts → Queue-Bl87Atny.d.cts} +2 -2
  27. package/dist/{Queue-Brw--scg.d.cts.map → Queue-Bl87Atny.d.cts.map} +1 -1
  28. package/dist/{Queue-D5z1bwFu.d.mts → Queue-Dhl8bc45.d.mts} +2 -2
  29. package/dist/{Queue-D5z1bwFu.d.mts.map → Queue-Dhl8bc45.d.mts.map} +1 -1
  30. package/dist/{Subscriber-DvKSp0N4.d.cts → Subscriber-YwPpHrBc.d.cts} +2 -2
  31. package/dist/{Subscriber-DvKSp0N4.d.cts.map → Subscriber-YwPpHrBc.d.cts.map} +1 -1
  32. package/dist/{Subscriber-CJ22tp8r.d.mts → Subscriber-panMf5vp.d.mts} +2 -2
  33. package/dist/{Subscriber-CJ22tp8r.d.mts.map → Subscriber-panMf5vp.d.mts.map} +1 -1
  34. package/dist/{Topic-BMfrIFdX.d.cts → Topic-DGtlTlu5.d.mts} +3 -3
  35. package/dist/{Topic-B-fxOsR2.d.mts.map → Topic-DGtlTlu5.d.mts.map} +1 -1
  36. package/dist/{Topic-B-fxOsR2.d.mts → Topic-dIcPqSLa.d.cts} +3 -3
  37. package/dist/{Topic-BMfrIFdX.d.cts.map → Topic-dIcPqSLa.d.cts.map} +1 -1
  38. package/dist/adaptors/aws.cjs +9 -14
  39. package/dist/adaptors/aws.cjs.map +1 -1
  40. package/dist/adaptors/aws.d.cts +6 -6
  41. package/dist/adaptors/aws.d.cts.map +1 -1
  42. package/dist/adaptors/aws.d.mts +8 -8
  43. package/dist/adaptors/aws.d.mts.map +1 -1
  44. package/dist/adaptors/aws.mjs +9 -14
  45. package/dist/adaptors/aws.mjs.map +1 -1
  46. package/dist/adaptors/hono.cjs +7 -7
  47. package/dist/adaptors/hono.d.cts +3 -3
  48. package/dist/adaptors/hono.d.cts.map +1 -1
  49. package/dist/adaptors/hono.d.mts +4 -4
  50. package/dist/adaptors/hono.d.mts.map +1 -1
  51. package/dist/adaptors/hono.mjs +7 -7
  52. package/dist/adaptors/testing.cjs +22 -29
  53. package/dist/adaptors/testing.cjs.map +1 -1
  54. package/dist/adaptors/testing.d.cts +5 -5
  55. package/dist/adaptors/testing.d.cts.map +1 -1
  56. package/dist/adaptors/testing.d.mts +6 -6
  57. package/dist/adaptors/testing.d.mts.map +1 -1
  58. package/dist/adaptors/testing.mjs +22 -29
  59. package/dist/adaptors/testing.mjs.map +1 -1
  60. package/dist/{clone-I_WIpiFf.cjs → clone-BQnYiRgm.cjs} +1 -1
  61. package/dist/{clone-I_WIpiFf.cjs.map → clone-BQnYiRgm.cjs.map} +1 -1
  62. package/dist/{clone-pdXxc0t3.mjs → clone-BWIwx6vL.mjs} +1 -1
  63. package/dist/{clone-pdXxc0t3.mjs.map → clone-BWIwx6vL.mjs.map} +1 -1
  64. package/dist/crons/index.cjs +27 -6
  65. package/dist/crons/index.cjs.map +1 -1
  66. package/dist/crons/index.d.cts +17 -7
  67. package/dist/crons/index.d.cts.map +1 -1
  68. package/dist/crons/index.d.mts +13 -3
  69. package/dist/crons/index.d.mts.map +1 -1
  70. package/dist/crons/index.mjs +27 -6
  71. package/dist/crons/index.mjs.map +1 -1
  72. package/dist/endpoints/index.cjs +7 -32
  73. package/dist/endpoints/index.cjs.map +1 -1
  74. package/dist/endpoints/index.d.cts +6 -14
  75. package/dist/endpoints/index.d.cts.map +1 -1
  76. package/dist/endpoints/index.d.mts +5 -13
  77. package/dist/endpoints/index.d.mts.map +1 -1
  78. package/dist/endpoints/index.mjs +7 -32
  79. package/dist/endpoints/index.mjs.map +1 -1
  80. package/dist/functions/index.cjs +3 -3
  81. package/dist/functions/index.d.cts +2 -2
  82. package/dist/functions/index.d.mts +2 -2
  83. package/dist/functions/index.mjs +3 -3
  84. package/dist/{functions-DhkDodl0.mjs → functions-CNJbRq0O.mjs} +4 -89
  85. package/dist/functions-CNJbRq0O.mjs.map +1 -0
  86. package/dist/{functions-B3OFv3QV.cjs → functions-DzjxHo1V.cjs} +3 -100
  87. package/dist/functions-DzjxHo1V.cjs.map +1 -0
  88. package/dist/{index-B8LNLQXD.d.mts → index-BUNi5ldW.d.mts} +2 -8
  89. package/dist/index-BUNi5ldW.d.mts.map +1 -0
  90. package/dist/{index-CeoLMr7c.d.cts → index-zeG5G432.d.cts} +6 -12
  91. package/dist/index-zeG5G432.d.cts.map +1 -0
  92. package/dist/index.cjs +1 -1
  93. package/dist/index.d.cts +1 -1
  94. package/dist/index.d.mts +3 -3
  95. package/dist/index.mjs +1 -1
  96. package/dist/{lazyAccessors-C1n1QfEj.cjs → lazyAccessors-BZJl6bx_.cjs} +3 -3
  97. package/dist/{lazyAccessors-C1n1QfEj.cjs.map → lazyAccessors-BZJl6bx_.cjs.map} +1 -1
  98. package/dist/{lazyAccessors-fFIQrblM.mjs → lazyAccessors-BjAZqRqK.mjs} +3 -3
  99. package/dist/{lazyAccessors-fFIQrblM.mjs.map → lazyAccessors-BjAZqRqK.mjs.map} +1 -1
  100. package/dist/monitor-D3uHJ8DU.cjs +67 -0
  101. package/dist/monitor-D3uHJ8DU.cjs.map +1 -0
  102. package/dist/monitor-Dt7fiasS.mjs +61 -0
  103. package/dist/monitor-Dt7fiasS.mjs.map +1 -0
  104. package/dist/monitors/index.cjs +2 -2
  105. package/dist/monitors/index.cjs.map +1 -1
  106. package/dist/monitors/index.d.cts +2 -2
  107. package/dist/monitors/index.d.cts.map +1 -1
  108. package/dist/monitors/index.d.mts +2 -2
  109. package/dist/monitors/index.mjs +2 -2
  110. package/dist/monitors/index.mjs.map +1 -1
  111. package/dist/{processAudits-CwyaaSQc.mjs → processAudits-BEiSkgH3.mjs} +1 -1
  112. package/dist/{processAudits-CwyaaSQc.mjs.map → processAudits-BEiSkgH3.mjs.map} +1 -1
  113. package/dist/{processAudits-94Ar_EJF.cjs → processAudits-Cd912Eck.cjs} +2 -2
  114. package/dist/{processAudits-94Ar_EJF.cjs.map → processAudits-Cd912Eck.cjs.map} +1 -1
  115. package/dist/{publisher-BZgcrVPy.cjs → publisher-B6Wu-JNv.cjs} +1 -1
  116. package/dist/{publisher-BZgcrVPy.cjs.map → publisher-B6Wu-JNv.cjs.map} +1 -1
  117. package/dist/{publisher-CnpeMv-r.mjs → publisher-Cs7WcvJl.mjs} +1 -1
  118. package/dist/{publisher-CnpeMv-r.mjs.map → publisher-Cs7WcvJl.mjs.map} +1 -1
  119. package/dist/queue/index.cjs +2 -2
  120. package/dist/queue/index.d.cts +2 -2
  121. package/dist/queue/index.d.mts +2 -2
  122. package/dist/queue/index.mjs +2 -2
  123. package/dist/subscribers/index.cjs +2 -2
  124. package/dist/subscribers/index.d.cts +5 -5
  125. package/dist/subscribers/index.d.cts.map +1 -1
  126. package/dist/subscribers/index.d.mts +3 -3
  127. package/dist/subscribers/index.mjs +2 -2
  128. package/dist/{telemetry-C--EgYVr.d.mts → telemetry-Bp4DLvdQ.d.mts} +1 -1
  129. package/dist/{telemetry-C--EgYVr.d.mts.map → telemetry-Bp4DLvdQ.d.mts.map} +1 -1
  130. package/dist/topic/index.cjs +2 -2
  131. package/dist/topic/index.d.cts +2 -2
  132. package/dist/topic/index.d.mts +2 -2
  133. package/dist/topic/index.mjs +2 -2
  134. package/dist/{types-DNngH0fX.d.mts → types-j0ti0JTY.d.mts} +1 -1
  135. package/dist/{types-DNngH0fX.d.mts.map → types-j0ti0JTY.d.mts.map} +1 -1
  136. package/dist/types.d.mts +1 -1
  137. package/package.json +22 -22
  138. package/src/Construct.ts +2 -13
  139. package/src/__tests__/uptime.spec.ts +340 -0
  140. package/src/crons/Cron.ts +10 -0
  141. package/src/crons/CronBuilder.ts +15 -1
  142. package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +2 -23
  143. package/src/endpoints/EndpointBuilder.ts +1 -4
  144. package/src/endpoints/EndpointFactory.ts +0 -31
  145. package/src/endpoints/HonoEndpointAdaptor.ts +1 -16
  146. package/src/endpoints/TestEndpointAdaptor.ts +4 -20
  147. package/src/functions/BaseFunctionBuilder.ts +0 -10
  148. package/src/functions/FunctionBuilder.ts +0 -2
  149. package/src/monitor.ts +14 -55
  150. package/src/monitors/heartbeat.ts +4 -2
  151. package/dist/AWSScheduledFunction-DAGP_vz5.d.cts.map +0 -1
  152. package/dist/AWSScheduledFunction-Dg6TPIxn.d.mts.map +0 -1
  153. package/dist/Construct-D09WUUOf.cjs.map +0 -1
  154. package/dist/Construct-D0uZvbr3.mjs.map +0 -1
  155. package/dist/Construct-D_3yZ9m5.d.cts.map +0 -1
  156. package/dist/Construct-DsqpiAym.d.mts.map +0 -1
  157. package/dist/Endpoint-DEydLuBs.d.mts.map +0 -1
  158. package/dist/HonoEndpointAdaptor-CJfFQ5KR.mjs.map +0 -1
  159. package/dist/HonoEndpointAdaptor-DCD0rhFg.cjs.map +0 -1
  160. package/dist/functions-B3OFv3QV.cjs.map +0 -1
  161. package/dist/functions-DhkDodl0.mjs.map +0 -1
  162. package/dist/index-B8LNLQXD.d.mts.map +0 -1
  163. package/dist/index-CeoLMr7c.d.cts.map +0 -1
  164. package/src/__tests__/monitor.spec.ts +0 -696
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @geekmidas/constructs
2
2
 
3
+ ## 9.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#334](https://github.com/geekmidas/toolbox/pull/334) [`b03c43d`](https://github.com/geekmidas/toolbox/commit/b03c43dfd2c86b1daa7f0a47f43e5fb2e518518b) Thanks [@geekmidas](https://github.com/geekmidas)! - Crons report to an uptime monitor with `.uptime()`, which replaces `.monitor()`
8
+
9
+ **Breaking:** `.monitor()` is removed from functions, crons, endpoints and `EndpointFactory`, along with the monitor hooks in the endpoint adaptors. The manifest's `monitoring` field is removed from routes, functions and crons.
10
+
11
+ A monitor only adds something a cron can't report itself: that it didn't run. A function or endpoint runs when it's called, so no ping is ever due, and its failures are already logged where they happen. So uptime is now set on crons alone:
12
+
13
+ ```ts
14
+ export const nightlyReport = c
15
+ .schedule("cron(0 8 * * MON-FRI)")
16
+ .uptime(heartbeat.betterStack("MONITORING_URL"))
17
+ .handle(async () => {});
18
+ ```
19
+
20
+ Calling `.uptime()` again replaces the monitor. `gkm build` records it on the cron's manifest entry as `uptime`, with the period the heartbeat should expect, derived from the schedule by `cronPeriod`:
21
+
22
+ ```ts
23
+ uptime: { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL', period: 259200 }
24
+ ```
25
+
26
+ `MonitorInfo` in `@geekmidas/manifest` is replaced by `UptimeInfo`.
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies []:
31
+ - @geekmidas/audit@9.4.0
32
+ - @geekmidas/cache@9.4.0
33
+ - @geekmidas/db@9.4.0
34
+ - @geekmidas/envkit@9.4.0
35
+ - @geekmidas/errors@9.4.0
36
+ - @geekmidas/events@9.4.0
37
+ - @geekmidas/logger@9.4.0
38
+ - @geekmidas/rate-limit@9.4.0
39
+ - @geekmidas/schema@9.4.0
40
+ - @geekmidas/services@9.4.0
41
+
3
42
  ## 9.3.0
4
43
 
5
44
  ### Minor Changes
@@ -1,5 +1,6 @@
1
- import { FunctionBuilder, startMonitors } from "./functions-DhkDodl0.mjs";
2
- import { publishEvents } from "./publisher-CnpeMv-r.mjs";
1
+ import { startMonitors } from "./monitor-Dt7fiasS.mjs";
2
+ import { FunctionBuilder } from "./functions-CNJbRq0O.mjs";
3
+ import { publishEvents } from "./publisher-Cs7WcvJl.mjs";
3
4
  import { wrapError } from "@geekmidas/errors";
4
5
  import { ServiceDiscovery, runWithRequestContext } from "@geekmidas/services";
5
6
  import middy from "@middy/core";
@@ -251,4 +252,4 @@ var AWSScheduledFunction = class extends AWSLambdaFunction {
251
252
 
252
253
  //#endregion
253
254
  export { AWSLambdaFunction, AWSScheduledFunction };
254
- //# sourceMappingURL=AWSScheduledFunction-CU7mMGFA.mjs.map
255
+ //# sourceMappingURL=AWSScheduledFunction-BXmRm9W6.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AWSScheduledFunction-CU7mMGFA.mjs","names":["envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","handler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>","db","response","event: TEvent","response: InferStandardSchema<TOutSchema>","data: unknown","schema: T","envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","event: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","event: unknown","context: Context","envParser: EnvironmentParser<{}>","cron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>"],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":["import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { withAuditableTransaction } from '@geekmidas/audit/kysely';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport abstract class FunctionExecutionWrapper<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {}\n\n\tprotected _logger?: TLogger;\n\n\tget logger(): TLogger {\n\t\treturn this._logger || this.fn.logger;\n\t}\n\n\tget serviceDiscovery(): ServiceDiscovery<ServiceRecord<TServices>> {\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\treturn serviceDiscovery;\n\t}\n\n\tgetServices(): Promise<ServiceRecord<TServices>> {\n\t\treturn this.serviceDiscovery.register(this.fn.services);\n\t}\n\n\tasync getDatabase(): Promise<TDatabase | undefined> {\n\t\tif (!this.fn.databaseService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.databaseService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.databaseService.serviceName as keyof typeof services\n\t\t] as TDatabase;\n\t}\n\n\t/**\n\t * Get the audit storage service if configured.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync getAuditStorage(): Promise<TAuditStorage | undefined> {\n\t\tif (!this.fn.auditorStorageService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.auditorStorageService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof services\n\t\t] as TAuditStorage;\n\t}\n\n\t/**\n\t * Create an auditor instance for the function.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync createAuditor(): Promise<Auditor<TAuditAction> | undefined> {\n\t\tconst storage = await this.getAuditStorage();\n\t\tif (!storage) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new DefaultAuditor<TAuditAction>({\n\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\tstorage: storage as AuditStorage,\n\t\t\tmetadata: {\n\t\t\t\tfunction: this.fn.type,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Execute handler with audit transaction support.\n\t * If the audit storage has a database (via getDatabase()), wraps execution\n\t * in a transaction so audits are atomic with handler's database operations.\n\t *\n\t * @param handler - The handler function to execute (receives auditor and db)\n\t * @returns The handler result\n\t */\n\tasync executeWithAudit<T>(\n\t\thandler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>,\n\t): Promise<T> {\n\t\tconst auditor = await this.createAuditor();\n\t\tconst storage = await this.getAuditStorage();\n\n\t\t// No audit context - just run handler with regular db\n\t\tif (!auditor || !storage) {\n\t\t\tconst db = await this.getDatabase();\n\t\t\treturn handler({ db });\n\t\t}\n\n\t\t// Check if storage has a database and db service names match\n\t\tconst storageDb = (storage as AuditStorage).getDatabase?.();\n\t\tconst databaseServiceName = this.fn.databaseService?.serviceName;\n\t\tconst auditDbServiceName = this.fn.auditorStorageService?.serviceName;\n\n\t\t// If the audit storage has a database and we're using the same database service\n\t\t// (or the audit storage provides the database), use transactional execution\n\t\tif (storageDb && databaseServiceName && auditDbServiceName) {\n\t\t\treturn withAuditableTransaction(\n\t\t\t\tstorageDb as any,\n\t\t\t\tauditor as any,\n\t\t\t\tasync (trx) => {\n\t\t\t\t\t// Use transaction as db\n\t\t\t\t\tconst response = await handler({\n\t\t\t\t\t\tauditor,\n\t\t\t\t\t\tdb: trx as TDatabase,\n\t\t\t\t\t});\n\t\t\t\t\t// Audits are flushed by withAuditableTransaction before commit\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// No database on storage or service names don't match - run handler and flush audits after\n\t\tconst db = await this.getDatabase();\n\t\tconst response = await handler({ auditor, db });\n\n\t\t// Flush audits (no transaction)\n\t\tawait auditor.flush();\n\n\t\treturn response;\n\t}\n\n\tasync getFunctionInput<TEvent>(\n\t\tevent: TEvent,\n\t): Promise<InferComposableStandardSchema<TInput>> {\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tevent,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\treturn parsedInput as InferComposableStandardSchema<TInput>;\n\t}\n\n\tasync publishEvents(response: InferStandardSchema<TOutSchema>) {\n\t\tawait publishEvents(\n\t\t\tthis.logger,\n\t\t\tthis.serviceDiscovery,\n\t\t\tthis.fn.events,\n\t\t\tresponse,\n\t\t\tthis.fn.publisherService,\n\t\t);\n\t}\n\n\tasync parseComposableStandardSchema<T extends ComposableStandardSchema>(\n\t\tdata: unknown,\n\t\tschema: T,\n\t): Promise<InferComposableStandardSchema<T>> {\n\t\treturn FunctionBuilder.parseComposableStandardSchema(data, schema);\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Context, Handler } from 'aws-lambda';\nimport { startMonitors } from '../monitor';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\nimport { FunctionExecutionWrapper } from './FunctionExecutionWrapper';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype FunctionEvent<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = TEvent & {\n\tparsedInput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\tdb: TDatabase | undefined;\n\tauditor: Auditor<TAuditAction> | undefined;\n};\n\ntype Middleware<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = MiddlewareObj<\n\tFunctionEvent<TEvent, TInput, TServices, TLogger, TDatabase, TAuditAction>,\n\tInferComposableStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends FunctionExecutionWrapper<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction\n> {\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\toverride readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {\n\t\tsuper(envParser, fn);\n\t}\n\n\tprivate error<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.fn.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing function');\n\t\t\t\t// Kept for the monitors, which otherwise only see the wrapped error.\n\t\t\t\tif (req.event) {\n\t\t\t\t\t(req.event as any).__error = req.error;\n\t\t\t\t}\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate baseInput<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (_req) => {},\n\t\t};\n\t}\n\n\tprivate input<\n\t\tTEvent extends { input: InferComposableStandardSchema<TInput> },\n\t>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\t// Parse input if schema is provided\n\t\t\t\t\tif (this.fn.input) {\n\t\t\t\t\t\tconst parsedInput =\n\t\t\t\t\t\t\tawait FunctionBuilder.parseComposableStandardSchema(\n\t\t\t\t\t\t\t\treq.event,\n\t\t\t\t\t\t\t\tthis.fn.input,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\treq.event.parsedInput =\n\t\t\t\t\t\t\tparsedInput as InferComposableStandardSchema<TInput>;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If no schema, pass the event as-is\n\t\t\t\t\t\treq.event.parsedInput = req.event as any;\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t{ error, event: req.event },\n\t\t\t\t\t\t'Failed to parse input',\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.fn.logger.child({\n\t\t\t\t\tfn: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.db = await this.getDatabase();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate auditor<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.auditor = await this.createAuditor();\n\t\t\t},\n\t\t\tafter: async (req) => {\n\t\t\t\t// Flush any pending audits after successful execution\n\t\t\t\tif (req.event.auditor) {\n\t\t\t\t\tconst records = req.event.auditor.getRecords();\n\t\t\t\t\tif (records.length > 0) {\n\t\t\t\t\t\tthis.logger.debug(\n\t\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait req.event.auditor.flush();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst response = (req.response ||\n\t\t\t\t\tundefined) as InferStandardSchema<TOutSchema>;\n\t\t\t\tawait this.publishEvents(response);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler<TEvent>(\n\t\tevent: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t) {\n\t\t// Execute the function with the parsed context\n\t\tconst result = await this.fn.fn({\n\t\t\tinput: event.parsedInput,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t\tdb: event.db,\n\t\t\tauditor: event.auditor,\n\t\t} as any);\n\n\t\t// Parse output if schema is provided\n\t\tconst output = await this.fn.parseOutput(result);\n\n\t\treturn output;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.baseInput())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.database())\n\t\t\t.use(this.auditor())\n\t\t\t.use(this.input())\n\t\t\t.use(this.events());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.fn.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\t// Around the whole chain, not as a middleware: a middleware's\n\t\t\t\t\t// `after` runs before audits flush and events publish, and its\n\t\t\t\t\t// `onError` never runs once `error()` rethrows.\n\t\t\t\t\tconst monitor = await startMonitors(\n\t\t\t\t\t\tthis.fn,\n\t\t\t\t\t\tthis.serviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain(\n\t\t\t\t\t\t\tevent as Parameters<typeof chain>[0],\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait monitor.success(output);\n\t\t\t\t\t\treturn output;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait monitor.failure((event as any)?.__error ?? error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { AWSLambdaFunction } from '../functions/AWSLambdaFunction';\nimport type { Cron } from './Cron';\n\n/**\n * AWS Lambda adaptor for {@link Cron} constructs.\n *\n * A `Cron` is a {@link import('../functions').Function} that is invoked on a\n * schedule (an EventBridge rule) rather than by an API request. Because of\n * that, the runtime execution pipeline is identical to a regular Lambda\n * function: input parsing, service/database/auditor wiring, event publishing,\n * error handling, and the `runWithRequestContext` wrapper that powers\n * request-scoped logging via `serviceContext.getLogger()`.\n *\n * This adaptor therefore reuses {@link AWSLambdaFunction} wholesale and only\n * narrows the constructor to accept a `Cron`. The schedule expression itself\n * (`cron.schedule`) is **deploy-time** infrastructure consumed by the CLI to\n * provision the EventBridge rule — it is not needed at runtime.\n *\n * @example\n * ```typescript\n * import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\n * import { cancelPastBookings } from '../../../src/crons/cancelPastBookings.js';\n * import { envParser } from '../../../src/env';\n *\n * const adapter = new AWSScheduledFunction(envParser, cancelPastBookings);\n *\n * export const handler = adapter.handler;\n * ```\n */\nexport class AWSScheduledFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends AWSLambdaFunction<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName\n> {\n\t// biome-ignore lint/complexity/noUselessConstructor: narrows the inherited `Function` parameter to `Cron` for a clearer public API\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\tcron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\tsuper(envParser, cron);\n\t}\n}\n"],"mappings":";;;;;;;;;AAqBA,IAAsB,2BAAtB,MAeE;CACD,YACWA,WACSC,IAsBlB;EAvBS;EACS;CAsBhB;CAEJ,AAAU;CAEV,IAAI,SAAkB;AACrB,SAAO,KAAK,WAAW,KAAK,GAAG;CAC/B;CAED,IAAI,mBAA+D;EAClE,MAAM,mBAAmB,iBAAiB,YAExC,KAAK,UAAU;AAEjB,SAAO;CACP;CAED,cAAiD;AAChD,SAAO,KAAK,iBAAiB,SAAS,KAAK,GAAG,SAAS;CACvD;CAED,MAAM,cAA8C;AACnD,OAAK,KAAK,GAAG,gBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,eACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,gBAAgB;CAEzB;;;;;CAMD,MAAM,kBAAsD;AAC3D,OAAK,KAAK,GAAG,sBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,qBACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,sBAAsB;CAE/B;;;;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AAM,cACrB,KAAK,IACL,KAAK,kBACL,OACA;AACD,QAAI;KACH,MAAM,SAAS,MAAM,MACpB,OACA,QACA;AACD,WAAM,QAAQ,QAAQ,OAAO;AAC7B,YAAO;IACP,SAAQ,OAAO;AACf,WAAM,QAAQ,QAAS,OAAe,WAAW,MAAM;AACvD,WAAM;IACN;GACD,EACD;EACD;AAED,SAAO;CACP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClVD,IAAa,uBAAb,cASU,kBAWR;CAED,YACCC,WACAC,MAUC;AACD,QAAM,WAAW,KAAK;CACtB;AACD"}
1
+ {"version":3,"file":"AWSScheduledFunction-BXmRm9W6.mjs","names":["envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","handler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>","db","response","event: TEvent","response: InferStandardSchema<TOutSchema>","data: unknown","schema: T","envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","event: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","event: unknown","context: Context","envParser: EnvironmentParser<{}>","cron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>"],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":["import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { withAuditableTransaction } from '@geekmidas/audit/kysely';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport abstract class FunctionExecutionWrapper<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {}\n\n\tprotected _logger?: TLogger;\n\n\tget logger(): TLogger {\n\t\treturn this._logger || this.fn.logger;\n\t}\n\n\tget serviceDiscovery(): ServiceDiscovery<ServiceRecord<TServices>> {\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\treturn serviceDiscovery;\n\t}\n\n\tgetServices(): Promise<ServiceRecord<TServices>> {\n\t\treturn this.serviceDiscovery.register(this.fn.services);\n\t}\n\n\tasync getDatabase(): Promise<TDatabase | undefined> {\n\t\tif (!this.fn.databaseService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.databaseService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.databaseService.serviceName as keyof typeof services\n\t\t] as TDatabase;\n\t}\n\n\t/**\n\t * Get the audit storage service if configured.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync getAuditStorage(): Promise<TAuditStorage | undefined> {\n\t\tif (!this.fn.auditorStorageService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.auditorStorageService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof services\n\t\t] as TAuditStorage;\n\t}\n\n\t/**\n\t * Create an auditor instance for the function.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync createAuditor(): Promise<Auditor<TAuditAction> | undefined> {\n\t\tconst storage = await this.getAuditStorage();\n\t\tif (!storage) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new DefaultAuditor<TAuditAction>({\n\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\tstorage: storage as AuditStorage,\n\t\t\tmetadata: {\n\t\t\t\tfunction: this.fn.type,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Execute handler with audit transaction support.\n\t * If the audit storage has a database (via getDatabase()), wraps execution\n\t * in a transaction so audits are atomic with handler's database operations.\n\t *\n\t * @param handler - The handler function to execute (receives auditor and db)\n\t * @returns The handler result\n\t */\n\tasync executeWithAudit<T>(\n\t\thandler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>,\n\t): Promise<T> {\n\t\tconst auditor = await this.createAuditor();\n\t\tconst storage = await this.getAuditStorage();\n\n\t\t// No audit context - just run handler with regular db\n\t\tif (!auditor || !storage) {\n\t\t\tconst db = await this.getDatabase();\n\t\t\treturn handler({ db });\n\t\t}\n\n\t\t// Check if storage has a database and db service names match\n\t\tconst storageDb = (storage as AuditStorage).getDatabase?.();\n\t\tconst databaseServiceName = this.fn.databaseService?.serviceName;\n\t\tconst auditDbServiceName = this.fn.auditorStorageService?.serviceName;\n\n\t\t// If the audit storage has a database and we're using the same database service\n\t\t// (or the audit storage provides the database), use transactional execution\n\t\tif (storageDb && databaseServiceName && auditDbServiceName) {\n\t\t\treturn withAuditableTransaction(\n\t\t\t\tstorageDb as any,\n\t\t\t\tauditor as any,\n\t\t\t\tasync (trx) => {\n\t\t\t\t\t// Use transaction as db\n\t\t\t\t\tconst response = await handler({\n\t\t\t\t\t\tauditor,\n\t\t\t\t\t\tdb: trx as TDatabase,\n\t\t\t\t\t});\n\t\t\t\t\t// Audits are flushed by withAuditableTransaction before commit\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// No database on storage or service names don't match - run handler and flush audits after\n\t\tconst db = await this.getDatabase();\n\t\tconst response = await handler({ auditor, db });\n\n\t\t// Flush audits (no transaction)\n\t\tawait auditor.flush();\n\n\t\treturn response;\n\t}\n\n\tasync getFunctionInput<TEvent>(\n\t\tevent: TEvent,\n\t): Promise<InferComposableStandardSchema<TInput>> {\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tevent,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\treturn parsedInput as InferComposableStandardSchema<TInput>;\n\t}\n\n\tasync publishEvents(response: InferStandardSchema<TOutSchema>) {\n\t\tawait publishEvents(\n\t\t\tthis.logger,\n\t\t\tthis.serviceDiscovery,\n\t\t\tthis.fn.events,\n\t\t\tresponse,\n\t\t\tthis.fn.publisherService,\n\t\t);\n\t}\n\n\tasync parseComposableStandardSchema<T extends ComposableStandardSchema>(\n\t\tdata: unknown,\n\t\tschema: T,\n\t): Promise<InferComposableStandardSchema<T>> {\n\t\treturn FunctionBuilder.parseComposableStandardSchema(data, schema);\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Context, Handler } from 'aws-lambda';\nimport { startMonitors } from '../monitor';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\nimport { FunctionExecutionWrapper } from './FunctionExecutionWrapper';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype FunctionEvent<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = TEvent & {\n\tparsedInput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\tdb: TDatabase | undefined;\n\tauditor: Auditor<TAuditAction> | undefined;\n};\n\ntype Middleware<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = MiddlewareObj<\n\tFunctionEvent<TEvent, TInput, TServices, TLogger, TDatabase, TAuditAction>,\n\tInferComposableStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends FunctionExecutionWrapper<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction\n> {\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\toverride readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {\n\t\tsuper(envParser, fn);\n\t}\n\n\tprivate error<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.fn.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing function');\n\t\t\t\t// Kept for the monitors, which otherwise only see the wrapped error.\n\t\t\t\tif (req.event) {\n\t\t\t\t\t(req.event as any).__error = req.error;\n\t\t\t\t}\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate baseInput<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (_req) => {},\n\t\t};\n\t}\n\n\tprivate input<\n\t\tTEvent extends { input: InferComposableStandardSchema<TInput> },\n\t>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\t// Parse input if schema is provided\n\t\t\t\t\tif (this.fn.input) {\n\t\t\t\t\t\tconst parsedInput =\n\t\t\t\t\t\t\tawait FunctionBuilder.parseComposableStandardSchema(\n\t\t\t\t\t\t\t\treq.event,\n\t\t\t\t\t\t\t\tthis.fn.input,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\treq.event.parsedInput =\n\t\t\t\t\t\t\tparsedInput as InferComposableStandardSchema<TInput>;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If no schema, pass the event as-is\n\t\t\t\t\t\treq.event.parsedInput = req.event as any;\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t{ error, event: req.event },\n\t\t\t\t\t\t'Failed to parse input',\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.fn.logger.child({\n\t\t\t\t\tfn: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.db = await this.getDatabase();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate auditor<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.auditor = await this.createAuditor();\n\t\t\t},\n\t\t\tafter: async (req) => {\n\t\t\t\t// Flush any pending audits after successful execution\n\t\t\t\tif (req.event.auditor) {\n\t\t\t\t\tconst records = req.event.auditor.getRecords();\n\t\t\t\t\tif (records.length > 0) {\n\t\t\t\t\t\tthis.logger.debug(\n\t\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait req.event.auditor.flush();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst response = (req.response ||\n\t\t\t\t\tundefined) as InferStandardSchema<TOutSchema>;\n\t\t\t\tawait this.publishEvents(response);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler<TEvent>(\n\t\tevent: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t) {\n\t\t// Execute the function with the parsed context\n\t\tconst result = await this.fn.fn({\n\t\t\tinput: event.parsedInput,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t\tdb: event.db,\n\t\t\tauditor: event.auditor,\n\t\t} as any);\n\n\t\t// Parse output if schema is provided\n\t\tconst output = await this.fn.parseOutput(result);\n\n\t\treturn output;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.baseInput())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.database())\n\t\t\t.use(this.auditor())\n\t\t\t.use(this.input())\n\t\t\t.use(this.events());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.fn.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\t// Around the whole chain, not as a middleware: a middleware's\n\t\t\t\t\t// `after` runs before audits flush and events publish, and its\n\t\t\t\t\t// `onError` never runs once `error()` rethrows.\n\t\t\t\t\tconst monitor = await startMonitors(\n\t\t\t\t\t\tthis.fn,\n\t\t\t\t\t\tthis.serviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain(\n\t\t\t\t\t\t\tevent as Parameters<typeof chain>[0],\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait monitor.success(output);\n\t\t\t\t\t\treturn output;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait monitor.failure((event as any)?.__error ?? error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { AWSLambdaFunction } from '../functions/AWSLambdaFunction';\nimport type { Cron } from './Cron';\n\n/**\n * AWS Lambda adaptor for {@link Cron} constructs.\n *\n * A `Cron` is a {@link import('../functions').Function} that is invoked on a\n * schedule (an EventBridge rule) rather than by an API request. Because of\n * that, the runtime execution pipeline is identical to a regular Lambda\n * function: input parsing, service/database/auditor wiring, event publishing,\n * error handling, and the `runWithRequestContext` wrapper that powers\n * request-scoped logging via `serviceContext.getLogger()`.\n *\n * This adaptor therefore reuses {@link AWSLambdaFunction} wholesale and only\n * narrows the constructor to accept a `Cron`. The schedule expression itself\n * (`cron.schedule`) is **deploy-time** infrastructure consumed by the CLI to\n * provision the EventBridge rule — it is not needed at runtime.\n *\n * @example\n * ```typescript\n * import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\n * import { cancelPastBookings } from '../../../src/crons/cancelPastBookings.js';\n * import { envParser } from '../../../src/env';\n *\n * const adapter = new AWSScheduledFunction(envParser, cancelPastBookings);\n *\n * export const handler = adapter.handler;\n * ```\n */\nexport class AWSScheduledFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends AWSLambdaFunction<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName\n> {\n\t// biome-ignore lint/complexity/noUselessConstructor: narrows the inherited `Function` parameter to `Cron` for a clearer public API\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\tcron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\tsuper(envParser, cron);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAqBA,IAAsB,2BAAtB,MAeE;CACD,YACWA,WACSC,IAsBlB;EAvBS;EACS;CAsBhB;CAEJ,AAAU;CAEV,IAAI,SAAkB;AACrB,SAAO,KAAK,WAAW,KAAK,GAAG;CAC/B;CAED,IAAI,mBAA+D;EAClE,MAAM,mBAAmB,iBAAiB,YAExC,KAAK,UAAU;AAEjB,SAAO;CACP;CAED,cAAiD;AAChD,SAAO,KAAK,iBAAiB,SAAS,KAAK,GAAG,SAAS;CACvD;CAED,MAAM,cAA8C;AACnD,OAAK,KAAK,GAAG,gBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,eACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,gBAAgB;CAEzB;;;;;CAMD,MAAM,kBAAsD;AAC3D,OAAK,KAAK,GAAG,sBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,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AC;AAElD,UAAO,sBACN;IAAE;IAAQ;IAAW;GAAW,GAChC,YAAY;IAIX,MAAM,UAAU,MAAM,cACrB,KAAK,IACL,KAAK,kBACL,OACA;AACD,QAAI;KACH,MAAM,SAAS,MAAM,MACpB,OACA,QACA;AACD,WAAM,QAAQ,QAAQ,OAAO;AAC7B,YAAO;IACP,SAAQ,OAAO;AACf,WAAM,QAAQ,QAAS,OAAe,WAAW,MAAM;AACvD,WAAM;IACN;GACD,EACD;EACD;AAED,SAAO;CACP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClVD,IAAa,uBAAb,cASU,kBAWR;CAED,YACCC,WACAC,MAUC;AACD,QAAM,WAAW,KAAK;CACtB;AACD"}
@@ -1,6 +1,7 @@
1
- const require_Construct = require('./Construct-D09WUUOf.cjs');
2
- const require_functions = require('./functions-B3OFv3QV.cjs');
3
- const require_publisher = require('./publisher-BZgcrVPy.cjs');
1
+ const require_Construct = require('./Construct-Cf_0pAvo.cjs');
2
+ const require_monitor = require('./monitor-D3uHJ8DU.cjs');
3
+ const require_functions = require('./functions-DzjxHo1V.cjs');
4
+ const require_publisher = require('./publisher-B6Wu-JNv.cjs');
4
5
  const __geekmidas_errors = require_Construct.__toESM(require("@geekmidas/errors"));
5
6
  const __geekmidas_services = require_Construct.__toESM(require("@geekmidas/services"));
6
7
  const __middy_core = require_Construct.__toESM(require("@middy/core"));
@@ -201,7 +202,7 @@ var AWSLambdaFunction = class extends FunctionExecutionWrapper {
201
202
  requestId,
202
203
  startTime
203
204
  }, async () => {
204
- const monitor = await require_functions.startMonitors(this.fn, this.serviceDiscovery, logger);
205
+ const monitor = await require_monitor.startMonitors(this.fn, this.serviceDiscovery, logger);
205
206
  try {
206
207
  const output = await chain(event, context);
207
208
  await monitor.success(output);
@@ -263,4 +264,4 @@ Object.defineProperty(exports, 'AWSScheduledFunction', {
263
264
  return AWSScheduledFunction;
264
265
  }
265
266
  });
266
- //# sourceMappingURL=AWSScheduledFunction-CKhVurOa.cjs.map
267
+ //# sourceMappingURL=AWSScheduledFunction-C-JBSNak.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AWSScheduledFunction-CKhVurOa.cjs","names":["envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","DefaultAuditor","handler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>","db","response","event: TEvent","response: InferStandardSchema<TOutSchema>","data: unknown","schema: T","envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","event: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","event: unknown","context: Context","envParser: EnvironmentParser<{}>","cron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>"],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":["import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { withAuditableTransaction } from '@geekmidas/audit/kysely';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport abstract class FunctionExecutionWrapper<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {}\n\n\tprotected _logger?: TLogger;\n\n\tget logger(): TLogger {\n\t\treturn this._logger || this.fn.logger;\n\t}\n\n\tget serviceDiscovery(): ServiceDiscovery<ServiceRecord<TServices>> {\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\treturn serviceDiscovery;\n\t}\n\n\tgetServices(): Promise<ServiceRecord<TServices>> {\n\t\treturn this.serviceDiscovery.register(this.fn.services);\n\t}\n\n\tasync getDatabase(): Promise<TDatabase | undefined> {\n\t\tif (!this.fn.databaseService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.databaseService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.databaseService.serviceName as keyof typeof services\n\t\t] as TDatabase;\n\t}\n\n\t/**\n\t * Get the audit storage service if configured.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync getAuditStorage(): Promise<TAuditStorage | undefined> {\n\t\tif (!this.fn.auditorStorageService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.auditorStorageService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof services\n\t\t] as TAuditStorage;\n\t}\n\n\t/**\n\t * Create an auditor instance for the function.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync createAuditor(): Promise<Auditor<TAuditAction> | undefined> {\n\t\tconst storage = await this.getAuditStorage();\n\t\tif (!storage) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new DefaultAuditor<TAuditAction>({\n\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\tstorage: storage as AuditStorage,\n\t\t\tmetadata: {\n\t\t\t\tfunction: this.fn.type,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Execute handler with audit transaction support.\n\t * If the audit storage has a database (via getDatabase()), wraps execution\n\t * in a transaction so audits are atomic with handler's database operations.\n\t *\n\t * @param handler - The handler function to execute (receives auditor and db)\n\t * @returns The handler result\n\t */\n\tasync executeWithAudit<T>(\n\t\thandler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>,\n\t): Promise<T> {\n\t\tconst auditor = await this.createAuditor();\n\t\tconst storage = await this.getAuditStorage();\n\n\t\t// No audit context - just run handler with regular db\n\t\tif (!auditor || !storage) {\n\t\t\tconst db = await this.getDatabase();\n\t\t\treturn handler({ db });\n\t\t}\n\n\t\t// Check if storage has a database and db service names match\n\t\tconst storageDb = (storage as AuditStorage).getDatabase?.();\n\t\tconst databaseServiceName = this.fn.databaseService?.serviceName;\n\t\tconst auditDbServiceName = this.fn.auditorStorageService?.serviceName;\n\n\t\t// If the audit storage has a database and we're using the same database service\n\t\t// (or the audit storage provides the database), use transactional execution\n\t\tif (storageDb && databaseServiceName && auditDbServiceName) {\n\t\t\treturn withAuditableTransaction(\n\t\t\t\tstorageDb as any,\n\t\t\t\tauditor as any,\n\t\t\t\tasync (trx) => {\n\t\t\t\t\t// Use transaction as db\n\t\t\t\t\tconst response = await handler({\n\t\t\t\t\t\tauditor,\n\t\t\t\t\t\tdb: trx as TDatabase,\n\t\t\t\t\t});\n\t\t\t\t\t// Audits are flushed by withAuditableTransaction before commit\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// No database on storage or service names don't match - run handler and flush audits after\n\t\tconst db = await this.getDatabase();\n\t\tconst response = await handler({ auditor, db });\n\n\t\t// Flush audits (no transaction)\n\t\tawait auditor.flush();\n\n\t\treturn response;\n\t}\n\n\tasync getFunctionInput<TEvent>(\n\t\tevent: TEvent,\n\t): Promise<InferComposableStandardSchema<TInput>> {\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tevent,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\treturn parsedInput as InferComposableStandardSchema<TInput>;\n\t}\n\n\tasync publishEvents(response: InferStandardSchema<TOutSchema>) {\n\t\tawait publishEvents(\n\t\t\tthis.logger,\n\t\t\tthis.serviceDiscovery,\n\t\t\tthis.fn.events,\n\t\t\tresponse,\n\t\t\tthis.fn.publisherService,\n\t\t);\n\t}\n\n\tasync parseComposableStandardSchema<T extends ComposableStandardSchema>(\n\t\tdata: unknown,\n\t\tschema: T,\n\t): Promise<InferComposableStandardSchema<T>> {\n\t\treturn FunctionBuilder.parseComposableStandardSchema(data, schema);\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Context, Handler } from 'aws-lambda';\nimport { startMonitors } from '../monitor';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\nimport { FunctionExecutionWrapper } from './FunctionExecutionWrapper';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype FunctionEvent<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = TEvent & {\n\tparsedInput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\tdb: TDatabase | undefined;\n\tauditor: Auditor<TAuditAction> | undefined;\n};\n\ntype Middleware<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = MiddlewareObj<\n\tFunctionEvent<TEvent, TInput, TServices, TLogger, TDatabase, TAuditAction>,\n\tInferComposableStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends FunctionExecutionWrapper<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction\n> {\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\toverride readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {\n\t\tsuper(envParser, fn);\n\t}\n\n\tprivate error<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.fn.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing function');\n\t\t\t\t// Kept for the monitors, which otherwise only see the wrapped error.\n\t\t\t\tif (req.event) {\n\t\t\t\t\t(req.event as any).__error = req.error;\n\t\t\t\t}\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate baseInput<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (_req) => {},\n\t\t};\n\t}\n\n\tprivate input<\n\t\tTEvent extends { input: InferComposableStandardSchema<TInput> },\n\t>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\t// Parse input if schema is provided\n\t\t\t\t\tif (this.fn.input) {\n\t\t\t\t\t\tconst parsedInput =\n\t\t\t\t\t\t\tawait FunctionBuilder.parseComposableStandardSchema(\n\t\t\t\t\t\t\t\treq.event,\n\t\t\t\t\t\t\t\tthis.fn.input,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\treq.event.parsedInput =\n\t\t\t\t\t\t\tparsedInput as InferComposableStandardSchema<TInput>;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If no schema, pass the event as-is\n\t\t\t\t\t\treq.event.parsedInput = req.event as any;\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t{ error, event: req.event },\n\t\t\t\t\t\t'Failed to parse input',\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.fn.logger.child({\n\t\t\t\t\tfn: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.db = await this.getDatabase();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate auditor<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.auditor = await this.createAuditor();\n\t\t\t},\n\t\t\tafter: async (req) => {\n\t\t\t\t// Flush any pending audits after successful execution\n\t\t\t\tif (req.event.auditor) {\n\t\t\t\t\tconst records = req.event.auditor.getRecords();\n\t\t\t\t\tif (records.length > 0) {\n\t\t\t\t\t\tthis.logger.debug(\n\t\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait req.event.auditor.flush();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst response = (req.response ||\n\t\t\t\t\tundefined) as InferStandardSchema<TOutSchema>;\n\t\t\t\tawait this.publishEvents(response);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler<TEvent>(\n\t\tevent: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t) {\n\t\t// Execute the function with the parsed context\n\t\tconst result = await this.fn.fn({\n\t\t\tinput: event.parsedInput,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t\tdb: event.db,\n\t\t\tauditor: event.auditor,\n\t\t} as any);\n\n\t\t// Parse output if schema is provided\n\t\tconst output = await this.fn.parseOutput(result);\n\n\t\treturn output;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.baseInput())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.database())\n\t\t\t.use(this.auditor())\n\t\t\t.use(this.input())\n\t\t\t.use(this.events());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.fn.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\t// Around the whole chain, not as a middleware: a middleware's\n\t\t\t\t\t// `after` runs before audits flush and events publish, and its\n\t\t\t\t\t// `onError` never runs once `error()` rethrows.\n\t\t\t\t\tconst monitor = await startMonitors(\n\t\t\t\t\t\tthis.fn,\n\t\t\t\t\t\tthis.serviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain(\n\t\t\t\t\t\t\tevent as Parameters<typeof chain>[0],\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait monitor.success(output);\n\t\t\t\t\t\treturn output;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait monitor.failure((event as any)?.__error ?? error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { AWSLambdaFunction } from '../functions/AWSLambdaFunction';\nimport type { Cron } from './Cron';\n\n/**\n * AWS Lambda adaptor for {@link Cron} constructs.\n *\n * A `Cron` is a {@link import('../functions').Function} that is invoked on a\n * schedule (an EventBridge rule) rather than by an API request. Because of\n * that, the runtime execution pipeline is identical to a regular Lambda\n * function: input parsing, service/database/auditor wiring, event publishing,\n * error handling, and the `runWithRequestContext` wrapper that powers\n * request-scoped logging via `serviceContext.getLogger()`.\n *\n * This adaptor therefore reuses {@link AWSLambdaFunction} wholesale and only\n * narrows the constructor to accept a `Cron`. The schedule expression itself\n * (`cron.schedule`) is **deploy-time** infrastructure consumed by the CLI to\n * provision the EventBridge rule — it is not needed at runtime.\n *\n * @example\n * ```typescript\n * import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\n * import { cancelPastBookings } from '../../../src/crons/cancelPastBookings.js';\n * import { envParser } from '../../../src/env';\n *\n * const adapter = new AWSScheduledFunction(envParser, cancelPastBookings);\n *\n * export const handler = adapter.handler;\n * ```\n */\nexport class AWSScheduledFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends AWSLambdaFunction<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName\n> {\n\t// biome-ignore lint/complexity/noUselessConstructor: narrows the inherited `Function` parameter to `Cron` for a clearer public API\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\tcron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\tsuper(envParser, cron);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAqBA,IAAsB,2BAAtB,MAeE;CACD,YACWA,WACSC,IAsBlB;EAvBS;EACS;CAsBhB;CAEJ,AAAU;CAEV,IAAI,SAAkB;AACrB,SAAO,KAAK,WAAW,KAAK,GAAG;CAC/B;CAED,IAAI,mBAA+D;EAClE,MAAM,mBAAmB,sCAAiB,YAExC,KAAK,UAAU;AAEjB,SAAO;CACP;CAED,cAAiD;AAChD,SAAO,KAAK,iBAAiB,SAAS,KAAK,GAAG,SAAS;CACvD;CAED,MAAM,cAA8C;AACnD,OAAK,KAAK,GAAG,gBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,eACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,gBAAgB;CAEzB;;;;;CAMD,MAAM,kBAAsD;AAC3D,OAAK,KAAK,GAAG,sBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,qBACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,sBAAsB;CAE/B;;;;;CAMD,MAAM,gBAA4D;EACjE,MAAM,UAAU,MAAM,KAAK,iBAAiB;AAC5C,OAAK,QACJ;AAGD,SAAO,IAAIC,iCAA6B;GACvC,OAAO;IAAE,IAAI;IAAU,MAAM;GAAU;GAC9B;GACT,UAAU,EACT,UAAU,KAAK,GAAG,KAClB;EACD;CACD;;;;;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;IACN;GACD,EACD;EACD;AAED,SAAO;CACP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClVD,IAAa,uBAAb,cASU,kBAWR;CAED,YACCC,WACAC,MAUC;AACD,QAAM,WAAW,KAAK;CACtB;AACD"}
1
+ {"version":3,"file":"AWSScheduledFunction-C-JBSNak.cjs","names":["envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","DefaultAuditor","handler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>","db","response","event: TEvent","response: InferStandardSchema<TOutSchema>","data: unknown","schema: T","envParser: EnvironmentParser<{}>","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>","event: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","event: unknown","context: Context","envParser: EnvironmentParser<{}>","cron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>"],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":["import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { withAuditableTransaction } from '@geekmidas/audit/kysely';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport abstract class FunctionExecutionWrapper<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {}\n\n\tprotected _logger?: TLogger;\n\n\tget logger(): TLogger {\n\t\treturn this._logger || this.fn.logger;\n\t}\n\n\tget serviceDiscovery(): ServiceDiscovery<ServiceRecord<TServices>> {\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\treturn serviceDiscovery;\n\t}\n\n\tgetServices(): Promise<ServiceRecord<TServices>> {\n\t\treturn this.serviceDiscovery.register(this.fn.services);\n\t}\n\n\tasync getDatabase(): Promise<TDatabase | undefined> {\n\t\tif (!this.fn.databaseService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.databaseService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.databaseService.serviceName as keyof typeof services\n\t\t] as TDatabase;\n\t}\n\n\t/**\n\t * Get the audit storage service if configured.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync getAuditStorage(): Promise<TAuditStorage | undefined> {\n\t\tif (!this.fn.auditorStorageService) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst services = await this.serviceDiscovery.register([\n\t\t\tthis.fn.auditorStorageService,\n\t\t]);\n\n\t\treturn services[\n\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof services\n\t\t] as TAuditStorage;\n\t}\n\n\t/**\n\t * Create an auditor instance for the function.\n\t * Returns undefined if no auditor storage is configured.\n\t */\n\tasync createAuditor(): Promise<Auditor<TAuditAction> | undefined> {\n\t\tconst storage = await this.getAuditStorage();\n\t\tif (!storage) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn new DefaultAuditor<TAuditAction>({\n\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\tstorage: storage as AuditStorage,\n\t\t\tmetadata: {\n\t\t\t\tfunction: this.fn.type,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Execute handler with audit transaction support.\n\t * If the audit storage has a database (via getDatabase()), wraps execution\n\t * in a transaction so audits are atomic with handler's database operations.\n\t *\n\t * @param handler - The handler function to execute (receives auditor and db)\n\t * @returns The handler result\n\t */\n\tasync executeWithAudit<T>(\n\t\thandler: (ctx: {\n\t\t\tauditor?: Auditor<TAuditAction>;\n\t\t\tdb?: TDatabase;\n\t\t}) => Promise<T>,\n\t): Promise<T> {\n\t\tconst auditor = await this.createAuditor();\n\t\tconst storage = await this.getAuditStorage();\n\n\t\t// No audit context - just run handler with regular db\n\t\tif (!auditor || !storage) {\n\t\t\tconst db = await this.getDatabase();\n\t\t\treturn handler({ db });\n\t\t}\n\n\t\t// Check if storage has a database and db service names match\n\t\tconst storageDb = (storage as AuditStorage).getDatabase?.();\n\t\tconst databaseServiceName = this.fn.databaseService?.serviceName;\n\t\tconst auditDbServiceName = this.fn.auditorStorageService?.serviceName;\n\n\t\t// If the audit storage has a database and we're using the same database service\n\t\t// (or the audit storage provides the database), use transactional execution\n\t\tif (storageDb && databaseServiceName && auditDbServiceName) {\n\t\t\treturn withAuditableTransaction(\n\t\t\t\tstorageDb as any,\n\t\t\t\tauditor as any,\n\t\t\t\tasync (trx) => {\n\t\t\t\t\t// Use transaction as db\n\t\t\t\t\tconst response = await handler({\n\t\t\t\t\t\tauditor,\n\t\t\t\t\t\tdb: trx as TDatabase,\n\t\t\t\t\t});\n\t\t\t\t\t// Audits are flushed by withAuditableTransaction before commit\n\t\t\t\t\treturn response;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// No database on storage or service names don't match - run handler and flush audits after\n\t\tconst db = await this.getDatabase();\n\t\tconst response = await handler({ auditor, db });\n\n\t\t// Flush audits (no transaction)\n\t\tawait auditor.flush();\n\n\t\treturn response;\n\t}\n\n\tasync getFunctionInput<TEvent>(\n\t\tevent: TEvent,\n\t): Promise<InferComposableStandardSchema<TInput>> {\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tevent,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\treturn parsedInput as InferComposableStandardSchema<TInput>;\n\t}\n\n\tasync publishEvents(response: InferStandardSchema<TOutSchema>) {\n\t\tawait publishEvents(\n\t\t\tthis.logger,\n\t\t\tthis.serviceDiscovery,\n\t\t\tthis.fn.events,\n\t\t\tresponse,\n\t\t\tthis.fn.publisherService,\n\t\t);\n\t}\n\n\tasync parseComposableStandardSchema<T extends ComposableStandardSchema>(\n\t\tdata: unknown,\n\t\tschema: T,\n\t): Promise<InferComposableStandardSchema<T>> {\n\t\treturn FunctionBuilder.parseComposableStandardSchema(data, schema);\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Context, Handler } from 'aws-lambda';\nimport { startMonitors } from '../monitor';\nimport type { Function, FunctionHandler } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\nimport { FunctionExecutionWrapper } from './FunctionExecutionWrapper';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype FunctionEvent<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = TEvent & {\n\tparsedInput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\tdb: TDatabase | undefined;\n\tauditor: Auditor<TAuditAction> | undefined;\n};\n\ntype Middleware<\n\tTEvent,\n\tTInput extends ComposableStandardSchema | undefined,\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = MiddlewareObj<\n\tFunctionEvent<TEvent, TInput, TServices, TLogger, TDatabase, TAuditAction>,\n\tInferComposableStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends FunctionExecutionWrapper<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction\n> {\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\toverride readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tFunctionHandler<\n\t\t\t\tTInput,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTOutSchema,\n\t\t\t\tTDatabase,\n\t\t\t\tTAuditStorage,\n\t\t\t\tTAuditAction\n\t\t\t>\n\t\t>,\n\t) {\n\t\tsuper(envParser, fn);\n\t}\n\n\tprivate error<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.fn.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing function');\n\t\t\t\t// Kept for the monitors, which otherwise only see the wrapped error.\n\t\t\t\tif (req.event) {\n\t\t\t\t\t(req.event as any).__error = req.error;\n\t\t\t\t}\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate baseInput<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (_req) => {},\n\t\t};\n\t}\n\n\tprivate input<\n\t\tTEvent extends { input: InferComposableStandardSchema<TInput> },\n\t>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\t// Parse input if schema is provided\n\t\t\t\t\tif (this.fn.input) {\n\t\t\t\t\t\tconst parsedInput =\n\t\t\t\t\t\t\tawait FunctionBuilder.parseComposableStandardSchema(\n\t\t\t\t\t\t\t\treq.event,\n\t\t\t\t\t\t\t\tthis.fn.input,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\treq.event.parsedInput =\n\t\t\t\t\t\t\tparsedInput as InferComposableStandardSchema<TInput>;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If no schema, pass the event as-is\n\t\t\t\t\t\treq.event.parsedInput = req.event as any;\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t{ error, event: req.event },\n\t\t\t\t\t\t'Failed to parse input',\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.fn.logger.child({\n\t\t\t\t\tfn: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.db = await this.getDatabase();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate auditor<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.auditor = await this.createAuditor();\n\t\t\t},\n\t\t\tafter: async (req) => {\n\t\t\t\t// Flush any pending audits after successful execution\n\t\t\t\tif (req.event.auditor) {\n\t\t\t\t\tconst records = req.event.auditor.getRecords();\n\t\t\t\t\tif (records.length > 0) {\n\t\t\t\t\t\tthis.logger.debug(\n\t\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait req.event.auditor.flush();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events<TEvent>(): Middleware<\n\t\tTEvent,\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutSchema,\n\t\tTDatabase,\n\t\tTAuditAction\n\t> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst response = (req.response ||\n\t\t\t\t\tundefined) as InferStandardSchema<TOutSchema>;\n\t\t\t\tawait this.publishEvents(response);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler<TEvent>(\n\t\tevent: FunctionEvent<\n\t\t\tTEvent,\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t) {\n\t\t// Execute the function with the parsed context\n\t\tconst result = await this.fn.fn({\n\t\t\tinput: event.parsedInput,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t\tdb: event.db,\n\t\t\tauditor: event.auditor,\n\t\t} as any);\n\n\t\t// Parse output if schema is provided\n\t\tconst output = await this.fn.parseOutput(result);\n\n\t\treturn output;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.baseInput())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.database())\n\t\t\t.use(this.auditor())\n\t\t\t.use(this.input())\n\t\t\t.use(this.events());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.fn.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\t// Around the whole chain, not as a middleware: a middleware's\n\t\t\t\t\t// `after` runs before audits flush and events publish, and its\n\t\t\t\t\t// `onError` never runs once `error()` rethrows.\n\t\t\t\t\tconst monitor = await startMonitors(\n\t\t\t\t\t\tthis.fn,\n\t\t\t\t\t\tthis.serviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain(\n\t\t\t\t\t\t\tevent as Parameters<typeof chain>[0],\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait monitor.success(output);\n\t\t\t\t\t\treturn output;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait monitor.failure((event as any)?.__error ?? error);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { AWSLambdaFunction } from '../functions/AWSLambdaFunction';\nimport type { Cron } from './Cron';\n\n/**\n * AWS Lambda adaptor for {@link Cron} constructs.\n *\n * A `Cron` is a {@link import('../functions').Function} that is invoked on a\n * schedule (an EventBridge rule) rather than by an API request. Because of\n * that, the runtime execution pipeline is identical to a regular Lambda\n * function: input parsing, service/database/auditor wiring, event publishing,\n * error handling, and the `runWithRequestContext` wrapper that powers\n * request-scoped logging via `serviceContext.getLogger()`.\n *\n * This adaptor therefore reuses {@link AWSLambdaFunction} wholesale and only\n * narrows the constructor to accept a `Cron`. The schedule expression itself\n * (`cron.schedule`) is **deploy-time** infrastructure consumed by the CLI to\n * provision the EventBridge rule — it is not needed at runtime.\n *\n * @example\n * ```typescript\n * import { AWSScheduledFunction } from '@geekmidas/constructs/crons';\n * import { cancelPastBookings } from '../../../src/crons/cancelPastBookings.js';\n * import { envParser } from '../../../src/env';\n *\n * const adapter = new AWSScheduledFunction(envParser, cancelPastBookings);\n *\n * export const handler = adapter.handler;\n * ```\n */\nexport class AWSScheduledFunction<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends AWSLambdaFunction<\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTEventPublisher,\n\tTEventPublisherServiceName,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName\n> {\n\t// biome-ignore lint/complexity/noUselessConstructor: narrows the inherited `Function` parameter to `Cron` for a clearer public API\n\tconstructor(\n\t\tenvParser: EnvironmentParser<{}>,\n\t\tcron: Cron<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\tsuper(envParser, cron);\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAsB,2BAAtB,MAeE;CACD,YACWA,WACSC,IAsBlB;EAvBS;EACS;CAsBhB;CAEJ,AAAU;CAEV,IAAI,SAAkB;AACrB,SAAO,KAAK,WAAW,KAAK,GAAG;CAC/B;CAED,IAAI,mBAA+D;EAClE,MAAM,mBAAmB,sCAAiB,YAExC,KAAK,UAAU;AAEjB,SAAO;CACP;CAED,cAAiD;AAChD,SAAO,KAAK,iBAAiB,SAAS,KAAK,GAAG,SAAS;CACvD;CAED,MAAM,cAA8C;AACnD,OAAK,KAAK,GAAG,gBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,eACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,gBAAgB;CAEzB;;;;;CAMD,MAAM,kBAAsD;AAC3D,OAAK,KAAK,GAAG,sBACZ;EAGD,MAAM,WAAW,MAAM,KAAK,iBAAiB,SAAS,CACrD,KAAK,GAAG,qBACR,EAAC;AAEF,SAAO,SACN,KAAK,GAAG,sBAAsB;CAE/B;;;;;CAMD,MAAM,gBAA4D;EACjE,MAAM,UAAU,MAAM,KAAK,iBAAiB;AAC5C,OAAK,QACJ;AAGD,SAAO,IAAIC,iCAA6B;GACvC,O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AAQ,OAAO;AAC7B,YAAO;IACP,SAAQ,OAAO;AACf,WAAM,QAAQ,QAAS,OAAe,WAAW,MAAM;AACvD,WAAM;IACN;GACD,EACD;EACD;AAED,SAAO;CACP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClVD,IAAa,uBAAb,cASU,kBAWR;CAED,YACCC,WACAC,MAUC;AACD,QAAM,WAAW,KAAK;CACtB;AACD"}
@@ -1,4 +1,5 @@
1
- import { Function, FunctionHandler } from "./index-B8LNLQXD.mjs";
1
+ import { MonitorInfo } from "./Construct-CgluLUuF.mjs";
2
+ import { Function, FunctionHandler } from "./index-BUNi5ldW.mjs";
2
3
  import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
3
4
  import { AuditStorage, AuditableAction, Auditor } from "@geekmidas/audit";
4
5
  import { EnvironmentParser } from "@geekmidas/envkit";
@@ -70,6 +71,11 @@ declare class Cron<TInput extends ComposableStandardSchema | undefined = undefin
70
71
  static isCron(obj: any): obj is Cron<any, any, any, any>;
71
72
  constructor(fn: FunctionHandler<TInput, TServices, TLogger, OutSchema, TDatabase>, timeout?: number, _schedule?: ScheduleExpression | undefined, input?: TInput, outputSchema?: OutSchema, services?: TServices, logger?: TLogger, publisherService?: Service<TEventPublisherServiceName, TEventPublisher>, events?: any[], memorySize?: number, databaseService?: Service<TDatabaseServiceName, TDatabase>);
72
73
  get schedule(): ScheduleExpression | undefined;
74
+ /**
75
+ * The monitor set with `.uptime()` as the build manifest records it, or
76
+ * nothing when the cron has none.
77
+ */
78
+ getUptime(): MonitorInfo | undefined;
73
79
  }
74
80
  type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
75
81
  /** `'0'`…`'99'`, with an optional leading zero (`'08'`). */
@@ -146,4 +152,4 @@ declare class AWSScheduledFunction<TInput extends ComposableStandardSchema | und
146
152
 
147
153
  //#endregion
148
154
  export { AWSLambdaFunction, AWSScheduledFunction, AwsCronExpression, Cron, CronExpression, ScheduleExpression, UnixCronExpression };
149
- //# sourceMappingURL=AWSScheduledFunction-Dg6TPIxn.d.mts.map
155
+ //# sourceMappingURL=AWSScheduledFunction-DgQuL5kt.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AWSScheduledFunction-DgQuL5kt.d.mts","names":[],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/Cron.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;uBAqBsB,wCACN,qEACI,4DACD,gCACF,SAAS,gCACD,uHAEF,kLAID,mCAAmC;uBAMlC;yBACE,SACtB,QACA,WACA,SACA,YACA,iBACA,4BACA,eACA,0BACA,WACA,sBACA,cACA,gBACC,QACA,WACA,SACA,YACA,WACA,eACA;yBApBmB,2BACE,SACtB,QACA,WACA,SACA,YACA,iBACA,4BACA,eACA,0BACA,WACA,sBACA,cACA,gBACC,QACA,WACA,SACA,YACA,WACA,eACA;EArCkB,UAAA,OAAA,CAAA,EA0CD,OA1CyB;EAAA,IAAA,MAAA,CAAA,CAAA,EA4C/B,OA5C+B;EAAA,IAC9B,gBAAA,CAAA,CAAA,EA+CS,gBA/CT,CA+C0B,aA/C1B,CA+CwC,SA/CxC,CAAA,CAAA;EAAwB,WACpB,CAAA,CAAA,EAsDJ,OAtDI,CAsDI,aAtDJ,CAsDkB,SAtDlB,CAAA,CAAA;EAAgB,WACjB,CAAA,CAAA,EAyDG,OAzDH,CAyDW,SAzDX,GAAA,SAAA,CAAA;EAAO;;;;EAIS,eAIb,CAAA,CAAA,EAmEI,OAnEJ,CAmEY,aAnEZ,GAAA,SAAA,CAAA;EAAe;;;;EASzB,aACT,CAAA,CAAA,EA2EqB,OA3ErB,CA2E6B,OA3E7B,CA2EqC,YA3ErC,CAAA,GAAA,SAAA,CAAA;EAAO;;;;;;;;EAQK,gBAEX,CAAA,CAAA,CAAA,CAAA,OAAA,EAAA,CAAA,GAAA,EAAA;IACA,OAAA,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EAAA,6BAAA,MAAA,GAAA,MAAA,CAAA,SGNO,iBHMP,CGLF,MHKE,EGJF,UHIE,EGHF,SHGE,EGFF,OHEE,EGDF,eHCE,EGAF,0BHAE,EAAA,SAAA,EAAA,MAAA,EGGF,SHHE,EGIF,oBHJE,CAAA,CAAA;EAAY,WAEX,CAAA,SAAA,EGMS,iBHNT,CAAA,CAAA,CAAA,CAAA,EAAA,IAAA,EGOI,IHPJ,CGQD,MHRC,EGSD,SHTC,EGUD,OHVC,EGWD,UHXC,EGYD,eHZC,EGaD,0BHbC,EGcD,SHdC,EGeD,oBHfC,CAAA"}
@@ -1,4 +1,5 @@
1
- import { Function, FunctionHandler } from "./index-CeoLMr7c.cjs";
1
+ import { MonitorInfo } from "./Construct-BEh2DSMe.cjs";
2
+ import { Function, FunctionHandler } from "./index-zeG5G432.cjs";
2
3
  import { EnvironmentParser } from "@geekmidas/envkit";
3
4
  import { EventPublisher } from "@geekmidas/events";
4
5
  import { Logger } from "@geekmidas/logger";
@@ -70,6 +71,11 @@ declare class Cron<TInput extends ComposableStandardSchema | undefined = undefin
70
71
  static isCron(obj: any): obj is Cron<any, any, any, any>;
71
72
  constructor(fn: FunctionHandler<TInput, TServices, TLogger, OutSchema, TDatabase>, timeout?: number, _schedule?: ScheduleExpression | undefined, input?: TInput, outputSchema?: OutSchema, services?: TServices, logger?: TLogger, publisherService?: Service<TEventPublisherServiceName, TEventPublisher>, events?: any[], memorySize?: number, databaseService?: Service<TDatabaseServiceName, TDatabase>);
72
73
  get schedule(): ScheduleExpression | undefined;
74
+ /**
75
+ * The monitor set with `.uptime()` as the build manifest records it, or
76
+ * nothing when the cron has none.
77
+ */
78
+ getUptime(): MonitorInfo | undefined;
73
79
  }
74
80
  type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
75
81
  /** `'0'`…`'99'`, with an optional leading zero (`'08'`). */
@@ -146,4 +152,4 @@ declare class AWSScheduledFunction<TInput extends ComposableStandardSchema | und
146
152
 
147
153
  //#endregion
148
154
  export { AWSLambdaFunction, AWSScheduledFunction, AwsCronExpression, Cron, CronExpression, ScheduleExpression, UnixCronExpression };
149
- //# sourceMappingURL=AWSScheduledFunction-DAGP_vz5.d.cts.map
155
+ //# sourceMappingURL=AWSScheduledFunction-DoDZR8E6.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AWSScheduledFunction-DoDZR8E6.d.cts","names":[],"sources":["../src/functions/FunctionExecutionWrapper.ts","../src/functions/AWSLambdaFunction.ts","../src/crons/Cron.ts","../src/crons/AWSScheduledFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;uBAqBsB,wCACN,qEACI,4DACD,gCACF,SAAS,gCACD,uHAEF,kLAID,mCAAmC;uBAMlC;yBACE,SACtB,QACA,WACA,SACA,YACA,iBACA,4BACA,eACA,0BACA,WACA,sBACA,cACA,gBACC,QACA,WACA,SACA,YACA,WACA,eACA;yBApBmB,2BACE,SACtB,QACA,WACA,SACA,YACA,iBACA,4BACA,eACA,0BACA,WACA,sBACA,cACA,gBACC,QACA,WACA,SACA,YACA,WACA,eACA;EArCkB,UAAA,OAAA,CAAA,EA0CD,OA1CyB;EAAA,IAAA,MAAA,CAAA,CAAA,EA4C/B,OA5C+B;EAAA,IAC9B,gBAAA,CAAA,CAAA,EA+CS,gBA/CT,CA+C0B,aA/C1B,CA+CwC,SA/CxC,CAAA,CAAA;EAAwB,WACpB,CAAA,CAAA,EAsDJ,OAtDI,CAsDI,aAtDJ,CAsDkB,SAtDlB,CAAA,CAAA;EAAgB,WACjB,CAAA,CAAA,EAyDG,OAzDH,CAyDW,SAzDX,GAAA,SAAA,CAAA;EAAO;;;;EAIS,eAIb,CAAA,CAAA,EAmEI,OAnEJ,CAmEY,aAnEZ,GAAA,SAAA,CAAA;EAAe;;;;EASzB,aACT,CAAA,CAAA,EA2EqB,OA3ErB,CA2E6B,OA3E7B,CA2EqC,YA3ErC,CAAA,GAAA,SAAA,CAAA;EAAO;;;;;;;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CAAA,GAAA,SAAA,GAAA,SAAA,EAAA,mCAAA,MAAA,GAAA,MAAA,EAAA,YAAA,SAAA,EAAA,6BAAA,MAAA,GAAA,MAAA,CAAA,SGNO,iBHMP,CGLF,MHKE,EGJF,UHIE,EGHF,SHGE,EGFF,OHEE,EGDF,eHCE,EGAF,0BHAE,EAAA,SAAA,EAAA,MAAA,EGGF,SHHE,EGIF,oBHJE,CAAA,CAAA;EAAY,WAEX,CAAA,SAAA,EGMS,iBHNT,CAAA,CAAA,CAAA,CAAA,EAAA,IAAA,EGOI,IHPJ,CGQD,MHRC,EGSD,SHTC,EGUD,OHVC,EGWD,UHXC,EGYD,eHZC,EGaD,0BHbC,EGcD,SHdC,EGeD,oBHfC,CAAA"}
@@ -7,16 +7,17 @@ import { SniffResult } from "@geekmidas/envkit/sniffer";
7
7
 
8
8
  //#region src/monitor.d.ts
9
9
  /**
10
- * What a monitor is told about the construct whose run it is reporting.
10
+ * What a monitor is told about the cron whose run it is reporting.
11
11
  */
12
12
  interface MonitorContext {
13
- /** The kind of construct: function, cron or endpoint. */
13
+ /** The kind of construct, always a cron. */
14
14
  type: ConstructType;
15
15
  logger: Logger;
16
16
  }
17
17
  /**
18
- * Reports a construct's runs to an outside service — a heartbeat, an uptime
19
- * check, an error tracker.
18
+ * Reports a cron's runs to an uptime service, set with `.uptime()`, so a cron
19
+ * that stops running is noticed. A failure is already logged where it
20
+ * happens; what only a monitor can report is a run that never happened.
20
21
  *
21
22
  * `start` runs before the handler and whatever it returns is handed back to
22
23
  * `success` or `failure`, so a provider that pairs the two (a check-in id) can.
@@ -28,12 +29,10 @@ interface ConstructMonitor<TRun = unknown> {
28
29
  success(ctx: MonitorContext & {
29
30
  run: TRun;
30
31
  output: unknown;
31
- status?: number;
32
32
  }): Promise<void>;
33
33
  failure(ctx: MonitorContext & {
34
34
  run: TRun;
35
35
  error: unknown;
36
- status?: number;
37
36
  }): Promise<void>;
38
37
  }
39
38
  /**
@@ -74,14 +73,9 @@ declare abstract class Construct<TLogger extends Logger = Logger, TServiceName e
74
73
  readonly auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage> | undefined;
75
74
  /** Database service for this construct (used by Endpoint for RLS/audit context) */
76
75
  databaseService?: Service<TDatabaseServiceName, TDatabase>;
77
- /** Monitors told about each run of this construct (see `.monitor()`). */
76
+ /** Monitors told about each run: a cron's `.uptime()`, if it has one. */
78
77
  monitors: MonitorService[];
79
78
  constructor(type: ConstructType, logger: TLogger, services: TServices, events?: MappedEvent<T, any>[], publisherService?: Service<TServiceName, T> | undefined, outputSchema?: OutSchema | undefined, timeout?: number | undefined, memorySize?: number | undefined, auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage> | undefined);
80
- /**
81
- * This construct's monitors as the build manifest records them, or nothing
82
- * when it has none.
83
- */
84
- getMonitoring(): MonitorInfo[] | undefined;
85
79
  /**
86
80
  * Returns an array of environment variable names required by this construct's services.
87
81
  * This is determined by running a "sniffer" EnvironmentParser through each service's
@@ -134,4 +128,4 @@ declare enum ConstructType {
134
128
  declare function sniffService(service: Service): Promise<SniffResult>;
135
129
  //#endregion
136
130
  export { Construct, ConstructMonitor, ConstructType, MonitorContext, MonitorInfo, MonitorService, sniffService, snifferContext };
137
- //# sourceMappingURL=Construct-D_3yZ9m5.d.cts.map
131
+ //# sourceMappingURL=Construct-BEh2DSMe.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Construct-BEh2DSMe.d.cts","names":[],"sources":["../src/monitor.ts","../src/Construct.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAOiB,cAAA;;EAAA,IAAA,EAEV,aAFwB;EAAA,MAAA,EAGtB,MAHsB;;;AAGhB;AAaf;;;;;;;;AAGc,UAHG,gBAGH,CAAA,OAAA,OAAA,CAAA,CAAA;EAAc,KAAU,EAAA,GAAA,EAFzB,cAEyB,CAAA,EAFR,OAEQ,CAFA,IAEA,CAAA;EAAI,OAAqB,CAAA,GAAA,EADjD,cACiD,GAAA;IAAO,G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BA;;;AAA8D,iBAAxC,YAAA,CAAwC,OAAA,EAAlB,OAAkB,CAAA,EAAR,OAAQ,CAAA,WAAA,CAAA"}
@@ -94,7 +94,7 @@ const snifferContext = {
94
94
  var Construct = class {
95
95
  /** Database service for this construct (used by Endpoint for RLS/audit context) */
96
96
  databaseService;
97
- /** Monitors told about each run of this construct (see `.monitor()`). */
97
+ /** Monitors told about each run: a cron's `.uptime()`, if it has one. */
98
98
  monitors = [];
99
99
  constructor(type, logger, services, events = [], publisherService, outputSchema, timeout, memorySize, auditorStorageService) {
100
100
  this.type = type;
@@ -108,14 +108,6 @@ var Construct = class {
108
108
  this.auditorStorageService = auditorStorageService;
109
109
  }
110
110
  /**
111
- * This construct's monitors as the build manifest records them, or nothing
112
- * when it has none.
113
- */
114
- getMonitoring() {
115
- if (!this.monitors.length) return void 0;
116
- return this.monitors.map((monitor) => monitor.monitor ?? { type: monitor.serviceName });
117
- }
118
- /**
119
111
  * Returns an array of environment variable names required by this construct's services.
120
112
  * This is determined by running a "sniffer" EnvironmentParser through each service's
121
113
  * register method to track which environment variables are accessed.
@@ -251,4 +243,4 @@ Object.defineProperty(exports, 'snifferContext', {
251
243
  return snifferContext;
252
244
  }
253
245
  });
254
- //# sourceMappingURL=Construct-D09WUUOf.cjs.map
246
+ //# sourceMappingURL=Construct-Cf_0pAvo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Construct-Cf_0pAvo.cjs","names":["compact","snifferContext: ServiceContext","type: ConstructType","logger: TLogger","services: TServices","events: MappedEvent<T, any>[]","publisherService?: Service<TServiceName, T>","outputSchema?: OutSchema","timeout?: number","memorySize?: number","auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>","opts: { markOptional?: boolean }","services: Service[]","service: Service","SnifferEnvironmentParser"],"sources":["../../../node_modules/.pnpm/lodash.compact@3.0.1/node_modules/lodash.compact/index.js","../src/Construct.ts"],"sourcesContent":["/**\n * lodash 3.0.1 (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <https://lodash.com/license>\n */\n\n/**\n * Creates an array with all falsey values removed. The values `false`, `null`,\n * `0`, `\"\"`, `undefined`, and `NaN` are falsey.\n *\n * @static\n * @memberOf _\n * @category Array\n * @param {Array} array The array to compact.\n * @returns {Array} Returns the new array of filtered values.\n * @example\n *\n * _.compact([0, 1, false, 2, '', 3]);\n * // => [1, 2, 3]\n */\nfunction compact(array) {\n var index = -1,\n length = array ? array.length : 0,\n resIndex = 0,\n result = [];\n\n while (++index < length) {\n var value = array[index];\n if (value) {\n result[resIndex++] = value;\n }\n }\n return result;\n}\n\nmodule.exports = compact;\n","import type { AuditStorage } from '@geekmidas/audit';\nimport {\n\tSnifferEnvironmentParser,\n\ttype SniffResult,\n\tsniffWithFireAndForget,\n} from '@geekmidas/envkit/sniffer';\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service, ServiceContext } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport compact from 'lodash.compact';\nimport type { MonitorService } from './monitor';\n\n// Cache for service environment variables to handle singleton services\n// Stores both the full list and the optional subset so the same sniff result\n// can satisfy both getEnvironment() and getEnvironment({ markOptional: true }).\nconst serviceEnvCache = new Map<\n\tService,\n\t{ envVars: string[]; optionalEnvVars: string[] }\n>();\n\n/**\n * Noop context for environment sniffing.\n * Used when calling service.register() to detect env vars without a real request.\n * Returns dummy values since services should only use context in instance methods,\n * not during registration.\n */\nconst snifferContext: ServiceContext = {\n\tgetLogger() {\n\t\t// Return a noop logger for sniffing - services shouldn't log during registration\n\t\treturn {\n\t\t\tdebug: () => {},\n\t\t\tinfo: () => {},\n\t\t\twarn: () => {},\n\t\t\terror: () => {},\n\t\t\tchild: () => snifferContext.getLogger(),\n\t\t} as unknown as Logger;\n\t},\n\tgetRequestId() {\n\t\treturn 'sniffer-context';\n\t},\n\tgetRequestStartTime() {\n\t\treturn Date.now();\n\t},\n\thasContext() {\n\t\treturn false;\n\t},\n};\n\nexport abstract class Construct<\n\tTLogger extends Logger = Logger,\n\tTServiceName extends string = string,\n\tT extends EventPublisher<any> | undefined = undefined,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTAuditStorageServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTDatabase = unknown,\n> {\n\t/** Database service for this construct (used by Endpoint for RLS/audit context) */\n\tpublic databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\n\t/** Monitors told about each run: a cron's `.uptime()`, if it has one. */\n\tpublic monitors: MonitorService[] = [];\n\n\tconstructor(\n\t\tpublic readonly type: ConstructType,\n\t\tpublic readonly logger: TLogger,\n\t\tpublic readonly services: TServices,\n\t\tpublic readonly events: MappedEvent<T, any>[] = [],\n\n\t\tpublic readonly publisherService?: Service<TServiceName, T>,\n\t\tpublic outputSchema?: OutSchema,\n\t\tpublic readonly timeout?: number,\n\t\tpublic readonly memorySize?: number,\n\t\tpublic readonly auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>,\n\t) {}\n\n\t/**\n\t * Returns an array of environment variable names required by this construct's services.\n\t * This is determined by running a \"sniffer\" EnvironmentParser through each service's\n\t * register method to track which environment variables are accessed.\n\t *\n\t * Results are cached per service class to handle singleton patterns where\n\t * subsequent register() calls may short-circuit and not access env vars.\n\t *\n\t * @param markOptional - When true, optional vars (those accessed via `.optional()` or\n\t * `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).\n\t * @returns Promise that resolves to array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const endpoint = e\n\t * .services([databaseService, authService])\n\t * .get('/users')\n\t * .handle(async () => []);\n\t *\n\t * await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']\n\t * await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']\n\t * ```\n\t */\n\tasync getEnvironment(\n\t\topts: { markOptional?: boolean } = {},\n\t): Promise<string[]> {\n\t\tconst { markOptional = false } = opts;\n\t\tconst envVars = new Set<string>();\n\t\tconst optionalVars = new Set<string>();\n\t\tconst services: Service[] = compact([\n\t\t\t...this.services,\n\t\t\tthis.publisherService,\n\t\t\tthis.publisherService,\n\t\t\tthis.auditorStorageService,\n\t\t\tthis.databaseService,\n\t\t\t...this.monitors,\n\t\t]);\n\n\t\ttry {\n\t\t\tfor (const service of services) {\n\t\t\t\t// Check cache first - handles singleton services that short-circuit\n\t\t\t\tif (serviceEnvCache.has(service)) {\n\t\t\t\t\tconst cached = serviceEnvCache.get(service)!;\n\t\t\t\t\tcached.envVars.forEach((v) => envVars.add(v));\n\t\t\t\t\tcached.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Use sniffService to properly handle all error scenarios\n\t\t\t\tconst result = await sniffService(service);\n\n\t\t\t\t// Log any issues for debugging\n\t\t\t\tif (result.error) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{ error: result.error.message, service: service.serviceName },\n\t\t\t\t\t\t'Service threw error during env sniffing (env vars still captured)',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (result.unhandledRejections.length > 0) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\terrors: result.unhandledRejections.map((e) => e.message),\n\t\t\t\t\t\t\tservice: service.serviceName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'Fire-and-forget rejections during env sniffing (suppressed)',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Cache and collect env vars (both required and optional)\n\t\t\t\tserviceEnvCache.set(service, {\n\t\t\t\t\tenvVars: result.envVars,\n\t\t\t\t\toptionalEnvVars: result.optionalEnvVars,\n\t\t\t\t});\n\t\t\t\tresult.envVars.forEach((v) => envVars.add(v));\n\t\t\t\tresult.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t}\n\n\t\t\tconst sorted = Array.from(envVars).sort();\n\t\t\tif (!markOptional || optionalVars.size === 0) return sorted;\n\t\t\treturn sorted.map((v) => (optionalVars.has(v) ? `${v}?` : v));\n\t\t} catch (error) {\n\t\t\tthis.logger.error(\n\t\t\t\t{ error },\n\t\t\t\t'Error determining environment variables for construct',\n\t\t\t);\n\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nexport enum ConstructType {\n\tCron = 'dev.geekmidas.function.cron',\n\tEndpoint = 'dev.geekmidas.function.endpoint',\n\tFunction = 'dev.geekmidas.function.function',\n\tSubscriber = 'dev.geekmidas.function.subscriber',\n\tQueue = 'dev.geekmidas.function.queue',\n\tTopic = 'dev.geekmidas.resource.topic',\n}\n\n/**\n * Utility to test sniffing a service for environment variables.\n * Useful for debugging services that throw errors during sniffing.\n *\n * @example\n * ```typescript\n * import { sniffService } from '@geekmidas/constructs';\n * import { authService } from './services/AuthService';\n *\n * const result = await sniffService(authService);\n * console.log('Env vars:', result.envVars);\n * console.log('Error:', result.error);\n * ```\n */\nexport async function sniffService(service: Service): Promise<SniffResult> {\n\tconst sniffer = new SnifferEnvironmentParser();\n\n\treturn sniffWithFireAndForget(sniffer, () =>\n\t\tservice.register({\n\t\t\tenvParser: sniffer as any,\n\t\t\tcontext: snifferContext,\n\t\t}),\n\t);\n}\n\n// Export for testing\nexport { snifferContext };\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBA,SAASA,UAAQ,OAAO;EACtB,IAAI,QAAQ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