@geekmidas/constructs 10.0.0-alpha.147 → 10.0.0-alpha.148

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 (157) hide show
  1. package/dist/{Cron-CQoDSu-n.d.mts → Cron-D8mB_cPX.d.mts} +2 -2
  2. package/dist/{Cron-CFkpEys6.d.cts.map → Cron-D8mB_cPX.d.mts.map} +1 -1
  3. package/dist/{Cron-CFkpEys6.d.cts → Cron-D_sfaMGz.d.cts} +2 -2
  4. package/dist/{Cron-CQoDSu-n.d.mts.map → Cron-D_sfaMGz.d.cts.map} +1 -1
  5. package/dist/{CronBuilder-OaCRRFVk.d.cts → CronBuilder-C91MVLSr.d.cts} +4 -4
  6. package/dist/{CronBuilder-1W-G_i15.d.mts.map → CronBuilder-C91MVLSr.d.cts.map} +1 -1
  7. package/dist/{CronBuilder-1W-G_i15.d.mts → CronBuilder-Cmajva3g.d.mts} +4 -4
  8. package/dist/{CronBuilder-OaCRRFVk.d.cts.map → CronBuilder-Cmajva3g.d.mts.map} +1 -1
  9. package/dist/{Endpoint-BcUorcBa.cjs → Endpoint-52z1P0Ue.cjs} +9 -4
  10. package/dist/Endpoint-52z1P0Ue.cjs.map +1 -0
  11. package/dist/{Endpoint-DTXDggNl.d.mts → Endpoint-BbHh3Qoc.d.mts} +5 -5
  12. package/dist/{Endpoint-BEh-jW-f.d.cts.map → Endpoint-BbHh3Qoc.d.mts.map} +1 -1
  13. package/dist/{Endpoint-BEh-jW-f.d.cts → Endpoint-YYwjqtS1.d.cts} +5 -5
  14. package/dist/{Endpoint-DTXDggNl.d.mts.map → Endpoint-YYwjqtS1.d.cts.map} +1 -1
  15. package/dist/{Endpoint-BgvG36NO.mjs → Endpoint-sUOU7uLx.mjs} +9 -4
  16. package/dist/Endpoint-sUOU7uLx.mjs.map +1 -0
  17. package/dist/{EndpointFactory-C1NlpCAS.mjs → EndpointFactory-Bzi9Sl7r.mjs} +2 -2
  18. package/dist/{EndpointFactory-C1NlpCAS.mjs.map → EndpointFactory-Bzi9Sl7r.mjs.map} +1 -1
  19. package/dist/{EndpointFactory-gqmIRVWg.cjs → EndpointFactory-Cf_Cs1ym.cjs} +2 -2
  20. package/dist/{EndpointFactory-gqmIRVWg.cjs.map → EndpointFactory-Cf_Cs1ym.cjs.map} +1 -1
  21. package/dist/{EndpointFactory-B2dCS9dy.d.cts → EndpointFactory-Hh1r6J_C.d.cts} +5 -5
  22. package/dist/{EndpointFactory-B2dCS9dy.d.cts.map → EndpointFactory-Hh1r6J_C.d.cts.map} +1 -1
  23. package/dist/{EndpointFactory-D2HXcUrJ.d.mts → EndpointFactory-qcLzi4f-.d.mts} +5 -5
  24. package/dist/{EndpointFactory-D2HXcUrJ.d.mts.map → EndpointFactory-qcLzi4f-.d.mts.map} +1 -1
  25. package/dist/{HonoEndpointAdaptor-BJlj20fQ.cjs → HonoEndpointAdaptor-BXBdb2Bt.cjs} +2 -2
  26. package/dist/{HonoEndpointAdaptor-BJlj20fQ.cjs.map → HonoEndpointAdaptor-BXBdb2Bt.cjs.map} +1 -1
  27. package/dist/{HonoEndpointAdaptor-BlbkUDNo.mjs → HonoEndpointAdaptor-DR3j7S35.mjs} +2 -2
  28. package/dist/{HonoEndpointAdaptor-BlbkUDNo.mjs.map → HonoEndpointAdaptor-DR3j7S35.mjs.map} +1 -1
  29. package/dist/{ObjectSubscriberBuilder-CzgYmOUH.d.mts → ObjectSubscriberBuilder-Cv8C7yS1.d.mts} +2 -2
  30. package/dist/{ObjectSubscriberBuilder-BuuaYcrm.d.cts.map → ObjectSubscriberBuilder-Cv8C7yS1.d.mts.map} +1 -1
  31. package/dist/{ObjectSubscriberBuilder-BuuaYcrm.d.cts → ObjectSubscriberBuilder-LWkey_oq.d.cts} +2 -2
  32. package/dist/{ObjectSubscriberBuilder-CzgYmOUH.d.mts.map → ObjectSubscriberBuilder-LWkey_oq.d.cts.map} +1 -1
  33. package/dist/{ProcessorBuilder-B2_stA8f.d.mts → ProcessorBuilder-CwfP-M33.d.mts} +2 -2
  34. package/dist/{ProcessorBuilder-B2_stA8f.d.mts.map → ProcessorBuilder-CwfP-M33.d.mts.map} +1 -1
  35. package/dist/{ProcessorBuilder-C62bIOwj.d.cts → ProcessorBuilder-_jdZlbfW.d.cts} +2 -2
  36. package/dist/{ProcessorBuilder-C62bIOwj.d.cts.map → ProcessorBuilder-_jdZlbfW.d.cts.map} +1 -1
  37. package/dist/{QueueBuilder-B3vL1ED2.d.mts → QueueBuilder-DmwFtLzQ.d.mts} +2 -2
  38. package/dist/{QueueBuilder-B3vL1ED2.d.mts.map → QueueBuilder-DmwFtLzQ.d.mts.map} +1 -1
  39. package/dist/{QueueBuilder-BcPBQSSX.d.cts → QueueBuilder-SQli59An.d.cts} +2 -2
  40. package/dist/{QueueBuilder-BcPBQSSX.d.cts.map → QueueBuilder-SQli59An.d.cts.map} +1 -1
  41. package/dist/adaptors/aws.cjs +1 -1
  42. package/dist/adaptors/aws.d.cts +2 -2
  43. package/dist/adaptors/aws.d.mts +2 -2
  44. package/dist/adaptors/aws.mjs +1 -1
  45. package/dist/adaptors/hono.cjs +1 -1
  46. package/dist/adaptors/hono.d.cts +1 -1
  47. package/dist/adaptors/hono.d.mts +1 -1
  48. package/dist/adaptors/hono.mjs +1 -1
  49. package/dist/adaptors/testing.cjs +2 -2
  50. package/dist/adaptors/testing.d.cts +4 -4
  51. package/dist/adaptors/testing.d.mts +4 -4
  52. package/dist/adaptors/testing.mjs +2 -2
  53. package/dist/{auth-D_0788uW.d.mts → auth-BqWz2JxC.d.cts} +13 -7
  54. package/dist/{auth-BMCJN30Y.d.cts.map → auth-BqWz2JxC.d.cts.map} +1 -1
  55. package/dist/{auth-BMCJN30Y.d.cts → auth-DnB9H9KL.d.mts} +13 -7
  56. package/dist/{auth-D_0788uW.d.mts.map → auth-DnB9H9KL.d.mts.map} +1 -1
  57. package/dist/auth.cjs +70 -15
  58. package/dist/auth.cjs.map +1 -1
  59. package/dist/auth.d.cts +1 -1
  60. package/dist/auth.d.mts +1 -1
  61. package/dist/auth.mjs +71 -16
  62. package/dist/auth.mjs.map +1 -1
  63. package/dist/{cache-5QZzh5Er.d.mts → cache-CQjMNPrC.d.cts} +3 -3
  64. package/dist/{cache-5QZzh5Er.d.mts.map → cache-CQjMNPrC.d.cts.map} +1 -1
  65. package/dist/{cache-DnGDGly3.d.cts → cache-e3tfMQ9g.d.mts} +3 -3
  66. package/dist/{cache-DnGDGly3.d.cts.map → cache-e3tfMQ9g.d.mts.map} +1 -1
  67. package/dist/cache.d.cts +1 -1
  68. package/dist/cache.d.mts +1 -1
  69. package/dist/{construct-interface-B1AfqRl4.d.cts → construct-interface-CSA9VeWM.d.mts} +9 -4
  70. package/dist/{construct-interface-B1AfqRl4.d.cts.map → construct-interface-CSA9VeWM.d.mts.map} +1 -1
  71. package/dist/{construct-interface-ZvYQbivO.d.mts → construct-interface-DugP0E5q.d.cts} +9 -4
  72. package/dist/{construct-interface-ZvYQbivO.d.mts.map → construct-interface-DugP0E5q.d.cts.map} +1 -1
  73. package/dist/construct-interface.cjs +8 -0
  74. package/dist/construct-interface.cjs.map +1 -1
  75. package/dist/construct-interface.d.cts +2 -2
  76. package/dist/construct-interface.d.mts +2 -2
  77. package/dist/construct-interface.mjs +8 -1
  78. package/dist/construct-interface.mjs.map +1 -1
  79. package/dist/credential.d.cts +1 -1
  80. package/dist/credential.d.mts +1 -1
  81. package/dist/crons/index.d.cts +2 -2
  82. package/dist/crons/index.d.mts +2 -2
  83. package/dist/database/kysely.d.cts +1 -1
  84. package/dist/database/kysely.d.mts +1 -1
  85. package/dist/email.d.cts +1 -1
  86. package/dist/email.d.mts +1 -1
  87. package/dist/encryption.d.cts +1 -1
  88. package/dist/encryption.d.mts +1 -1
  89. package/dist/endpoints/index.cjs +2 -2
  90. package/dist/endpoints/index.d.cts +2 -2
  91. package/dist/endpoints/index.d.mts +2 -2
  92. package/dist/endpoints/index.mjs +2 -2
  93. package/dist/external-api.d.cts +1 -1
  94. package/dist/external-api.d.mts +1 -1
  95. package/dist/{fake-D472nkKb.d.mts → fake-BqhP8RRQ.d.mts} +2 -2
  96. package/dist/{fake-BUgcX2Dk.d.cts.map → fake-BqhP8RRQ.d.mts.map} +1 -1
  97. package/dist/{fake-BUgcX2Dk.d.cts → fake-DqieDYYA.d.cts} +2 -2
  98. package/dist/{fake-D472nkKb.d.mts.map → fake-DqieDYYA.d.cts.map} +1 -1
  99. package/dist/file-server.d.cts +3 -3
  100. package/dist/file-server.d.mts +3 -3
  101. package/dist/functions/index.d.cts +1 -1
  102. package/dist/functions/index.d.mts +1 -1
  103. package/dist/{inbox-DqaxrpEk.d.cts → inbox-CR3L1fOI.d.cts} +2 -2
  104. package/dist/{inbox-DZdICa8F.d.mts.map → inbox-CR3L1fOI.d.cts.map} +1 -1
  105. package/dist/{inbox-DZdICa8F.d.mts → inbox-CjxpLVkH.d.mts} +2 -2
  106. package/dist/{inbox-DqaxrpEk.d.cts.map → inbox-CjxpLVkH.d.mts.map} +1 -1
  107. package/dist/inbox.d.cts +1 -1
  108. package/dist/inbox.d.mts +1 -1
  109. package/dist/{index-DuriFjYD.d.mts → index-DCkDQkwj.d.mts} +2 -2
  110. package/dist/{index-BtzMzhMA.d.cts.map → index-DCkDQkwj.d.mts.map} +1 -1
  111. package/dist/{index-BtzMzhMA.d.cts → index-DPTHa6Ud.d.cts} +2 -2
  112. package/dist/{index-DuriFjYD.d.mts.map → index-DPTHa6Ud.d.cts.map} +1 -1
  113. package/dist/{kysely-BHYV-WC-.d.cts → kysely-CebjCWTl.d.cts} +3 -3
  114. package/dist/{kysely-BHYV-WC-.d.cts.map → kysely-CebjCWTl.d.cts.map} +1 -1
  115. package/dist/{kysely-CAW3QSqp.d.mts → kysely-DE4kADWD.d.mts} +3 -3
  116. package/dist/{kysely-CAW3QSqp.d.mts.map → kysely-DE4kADWD.d.mts.map} +1 -1
  117. package/dist/mobile-app.d.cts +1 -1
  118. package/dist/mobile-app.d.mts +1 -1
  119. package/dist/object-storage.d.cts +1 -1
  120. package/dist/object-storage.d.mts +1 -1
  121. package/dist/processors/index.d.cts +1 -1
  122. package/dist/processors/index.d.mts +1 -1
  123. package/dist/queue/index.d.cts +1 -1
  124. package/dist/queue/index.d.mts +1 -1
  125. package/dist/random-password.d.cts +1 -1
  126. package/dist/random-password.d.mts +1 -1
  127. package/dist/rest-api.cjs +12 -1
  128. package/dist/rest-api.cjs.map +1 -1
  129. package/dist/rest-api.d.cts +12 -5
  130. package/dist/rest-api.d.cts.map +1 -1
  131. package/dist/rest-api.d.mts +12 -5
  132. package/dist/rest-api.d.mts.map +1 -1
  133. package/dist/rest-api.mjs +14 -3
  134. package/dist/rest-api.mjs.map +1 -1
  135. package/dist/site.cjs +21 -4
  136. package/dist/site.cjs.map +1 -1
  137. package/dist/site.d.cts +10 -3
  138. package/dist/site.d.cts.map +1 -1
  139. package/dist/site.d.mts +10 -3
  140. package/dist/site.d.mts.map +1 -1
  141. package/dist/site.mjs +23 -6
  142. package/dist/site.mjs.map +1 -1
  143. package/dist/subscribers/index.d.cts +1 -1
  144. package/dist/subscribers/index.d.mts +1 -1
  145. package/dist/{telemetry-B48RLjyk.d.cts → telemetry-C1oqncFY.d.cts} +2 -2
  146. package/dist/{telemetry-B48RLjyk.d.cts.map → telemetry-C1oqncFY.d.cts.map} +1 -1
  147. package/dist/{telemetry-BEoBn6GO.d.mts → telemetry-CObow3Dn.d.mts} +2 -2
  148. package/dist/{telemetry-BEoBn6GO.d.mts.map → telemetry-CObow3Dn.d.mts.map} +1 -1
  149. package/dist/telemetry.d.cts +1 -1
  150. package/dist/telemetry.d.mts +1 -1
  151. package/dist/websocket-api.d.cts +2 -2
  152. package/dist/websocket-api.d.mts +2 -2
  153. package/dist/worker.d.cts +8 -8
  154. package/dist/worker.d.mts +8 -8
  155. package/package.json +31 -31
  156. package/dist/Endpoint-BcUorcBa.cjs.map +0 -1
  157. package/dist/Endpoint-BgvG36NO.mjs.map +0 -1
package/dist/site.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'domain'),\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"m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OAAO,MAAM,KACd;CAEF;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAI,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,MAAM,EAAE,UAAU,KAAK;EACvB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,GAAI,QACD,EACA,OAAO;IACN,SAAS,YAAY,MAAM,QAAQ,EAAE;IACrC,MAAM,MAAM;GACb,EACD,IACC,CAAC;GACJ,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,CACA,WAAW,KAAK,IAAI,QAAQ,GAC5B,WAAW,KAAK,IAAI,qBAAqB,CAC1C,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
1
+ {"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * A site consumes addresses, not connections: it is built, and the values it\n * needs are inlined or fetched by its own framework, so its own edges take any\n * {@link Declarable}. Its `.service` is its public address — what a worker's\n * cron or an endpoint that builds links to it reads:\n *\n * ```ts\n * export const digest = worker\n * .cron('rate(1 day)')\n * .dependsOn([web])\n * .handle(async ({ services }) => link(services.web, '/inbox'));\n * ```\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n\tserviceKey,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\nimport type { Service } from '@geekmidas/services';\nimport {\n\ttype Construct,\n\ttype Declarable,\n\tedgeTo,\n\tpublicUrl,\n} from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>, Construct<TName, string>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\t/**\n\t * Its public address, `https://web.example.com` — a string, no await. The\n\t * same `<ID>_URL` on every command and stage, so a link built from it opens\n\t * in a browser.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, string>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(this.id) as Uncapitalize<TName>,\n\t\t\tregister: (options) => publicUrl(options, this.keys.url),\n\t\t};\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'domain'),\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoKA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,+JAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,2HAER;EAJoB,KAAA,KAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,IACA,QACA,OACC;EACD,MACC,IAAI,GAAG,0BAA0B,OAAO,GAAG,MAAM,+BACpC,MAAM,wCACpB;EAPS,KAAA,KAAA;EACA,KAAA,SAAA;EACA,KAAA,QAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,2BAAb,cAA8C,MAAM;CAC9B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,sJAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,aAAb,MAAa,WAEb;CAamB;CAOA;CAnBlB;CACA;;;;;;CAOA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,KAAK,YAAY,EAAY;EAClC,KAAK,OAAO,EAAE,KAAK,WAAW,KAAK,IAAI,KAAK,EAAE;EAE9C,KAAK,UAAU;GACd,aAA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AAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,CACA,WAAW,KAAK,IAAI,QAAQ,GAC5B,WAAW,KAAK,IAAI,qBAAqB,CAC1C,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
@@ -1,5 +1,5 @@
1
1
  import { t as Subscriber } from "../Subscriber-5rCX1Nph.cjs";
2
- import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-BuuaYcrm.cjs";
2
+ import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-LWkey_oq.cjs";
3
3
  import { EnvironmentParser } from "@geekmidas/envkit";
4
4
  import { SnsHttpMessage } from "@geekmidas/events/sns";
5
5
  //#region src/subscribers/SnsPushSubscriberAdaptor.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as Subscriber } from "../Subscriber-CW_Dl-YR.mjs";
2
- import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-CzgYmOUH.mjs";
2
+ import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-Cv8C7yS1.mjs";
3
3
  import { EnvironmentParser } from "@geekmidas/envkit";
4
4
  import { SnsHttpMessage } from "@geekmidas/events/sns";
5
5
  //#region src/subscribers/SnsPushSubscriberAdaptor.d.ts
@@ -1,4 +1,4 @@
1
- import { i as Declarable } from "./construct-interface-B1AfqRl4.cjs";
1
+ import { i as Declarable } from "./construct-interface-DugP0E5q.cjs";
2
2
  import { ConstructName, Declaration } from "@geekmidas/manifest";
3
3
  //#region src/telemetry.d.ts
4
4
  interface TelemetryConfig {
@@ -37,4 +37,4 @@ interface EndpointTelemetry {
37
37
  }
38
38
  //#endregion
39
39
  export { Telemetry as n, TelemetryConfig as r, EndpointTelemetry as t };
40
- //# sourceMappingURL=telemetry-B48RLjyk.d.cts.map
40
+ //# sourceMappingURL=telemetry-C1oqncFY.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-B48RLjyk.d.cts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAkCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;cAGV,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;EAE9B,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;EAW9C,WAAW;;;UAgBK;;EAEhB;;EAEA,aAAa,SAAS"}
1
+ {"version":3,"file":"telemetry-C1oqncFY.d.cts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAkCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;cAGV,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;EAE9B,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;EAW9C,WAAW;;;UAgBK;;EAEhB;;EAEA,aAAa,SAAS"}
@@ -1,4 +1,4 @@
1
- import { i as Declarable } from "./construct-interface-ZvYQbivO.mjs";
1
+ import { i as Declarable } from "./construct-interface-CSA9VeWM.mjs";
2
2
  import { ConstructName, Declaration } from "@geekmidas/manifest";
3
3
  //#region src/telemetry.d.ts
4
4
  interface TelemetryConfig {
@@ -37,4 +37,4 @@ interface EndpointTelemetry {
37
37
  }
38
38
  //#endregion
39
39
  export { Telemetry as n, TelemetryConfig as r, EndpointTelemetry as t };
40
- //# sourceMappingURL=telemetry-BEoBn6GO.d.mts.map
40
+ //# sourceMappingURL=telemetry-CObow3Dn.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-BEoBn6GO.d.mts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAkCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;cAGV,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;EAE9B,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;EAW9C,WAAW;;;UAgBK;;EAEhB;;EAEA,aAAa,SAAS"}
1
+ {"version":3,"file":"telemetry-CObow3Dn.d.mts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAkCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;cAGV,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;EAE9B,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;EAW9C,WAAW;;;UAgBK;;EAEhB;;EAEA,aAAa,SAAS"}
@@ -1,2 +1,2 @@
1
- import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-B48RLjyk.cjs";
1
+ import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-C1oqncFY.cjs";
2
2
  export { EndpointTelemetry, Telemetry, TelemetryConfig };
@@ -1,2 +1,2 @@
1
- import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-BEoBn6GO.mjs";
1
+ import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-CObow3Dn.mjs";
2
2
  export { EndpointTelemetry, Telemetry, TelemetryConfig };
@@ -1,6 +1,6 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.cjs";
2
- import { c as ServicesOf, i as Declarable, r as Consumable, t as Authenticator } from "./construct-interface-B1AfqRl4.cjs";
3
- import { n as Telemetry } from "./telemetry-B48RLjyk.cjs";
2
+ import { c as ServicesOf, i as Declarable, r as Consumable, t as Authenticator } from "./construct-interface-DugP0E5q.cjs";
3
+ import { n as Telemetry } from "./telemetry-C1oqncFY.cjs";
4
4
  import { EnvironmentParser } from "@geekmidas/envkit";
5
5
  import { Logger } from "@geekmidas/logger";
6
6
  import { InferStandardSchema } from "@geekmidas/schema";
@@ -1,6 +1,6 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.mjs";
2
- import { c as ServicesOf, i as Declarable, r as Consumable, t as Authenticator } from "./construct-interface-ZvYQbivO.mjs";
3
- import { n as Telemetry } from "./telemetry-BEoBn6GO.mjs";
2
+ import { c as ServicesOf, i as Declarable, r as Consumable, t as Authenticator } from "./construct-interface-CSA9VeWM.mjs";
3
+ import { n as Telemetry } from "./telemetry-CObow3Dn.mjs";
4
4
  import { ConstructName, Declaration } from "@geekmidas/manifest";
5
5
  import { Service, ServiceRecord, ServiceRegisterOptions } from "@geekmidas/services";
6
6
  import { EnvironmentParser } from "@geekmidas/envkit";
package/dist/worker.d.cts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.cjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-127M7yrl.cjs";
3
3
  import { i as FunctionHandler, n as Function, t as DatabaseContext } from "./Function-BIEsY0Hm.cjs";
4
- import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-B1AfqRl4.cjs";
5
- import { t as FunctionBuilder } from "./index-BtzMzhMA.cjs";
6
- import { i as ScheduleExpression } from "./Cron-CFkpEys6.cjs";
7
- import { n as Telemetry } from "./telemetry-B48RLjyk.cjs";
4
+ import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-DugP0E5q.cjs";
5
+ import { t as FunctionBuilder } from "./index-DPTHa6Ud.cjs";
6
+ import { i as ScheduleExpression } from "./Cron-D_sfaMGz.cjs";
7
+ import { n as Telemetry } from "./telemetry-C1oqncFY.cjs";
8
8
  import { t as Subscriber } from "./Subscriber-5rCX1Nph.cjs";
9
- import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-DqaxrpEk.cjs";
10
- import { t as CronBuilder } from "./CronBuilder-OaCRRFVk.cjs";
9
+ import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-CR3L1fOI.cjs";
10
+ import { t as CronBuilder } from "./CronBuilder-C91MVLSr.cjs";
11
11
  import { ObjectStorage } from "./object-storage.cjs";
12
- import { t as QueueBuilder } from "./QueueBuilder-BcPBQSSX.cjs";
13
- import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-BuuaYcrm.cjs";
12
+ import { t as QueueBuilder } from "./QueueBuilder-SQli59An.cjs";
13
+ import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-LWkey_oq.cjs";
14
14
  import "./topic/index.cjs";
15
15
  import { EnvironmentParser } from "@geekmidas/envkit";
16
16
  import { Logger } from "@geekmidas/logger";
package/dist/worker.d.mts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.mjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-DySlwh8o.mjs";
3
3
  import { i as FunctionHandler, n as Function, t as DatabaseContext } from "./Function-DfMzTGS4.mjs";
4
- import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-ZvYQbivO.mjs";
5
- import { t as FunctionBuilder } from "./index-DuriFjYD.mjs";
6
- import { i as ScheduleExpression } from "./Cron-CQoDSu-n.mjs";
7
- import { n as Telemetry } from "./telemetry-BEoBn6GO.mjs";
4
+ import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-CSA9VeWM.mjs";
5
+ import { t as FunctionBuilder } from "./index-DCkDQkwj.mjs";
6
+ import { i as ScheduleExpression } from "./Cron-D8mB_cPX.mjs";
7
+ import { n as Telemetry } from "./telemetry-CObow3Dn.mjs";
8
8
  import { t as Subscriber } from "./Subscriber-CW_Dl-YR.mjs";
9
- import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-DZdICa8F.mjs";
10
- import { t as CronBuilder } from "./CronBuilder-1W-G_i15.mjs";
9
+ import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-CjxpLVkH.mjs";
10
+ import { t as CronBuilder } from "./CronBuilder-Cmajva3g.mjs";
11
11
  import { ObjectStorage } from "./object-storage.mjs";
12
- import { t as QueueBuilder } from "./QueueBuilder-B3vL1ED2.mjs";
13
- import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-CzgYmOUH.mjs";
12
+ import { t as QueueBuilder } from "./QueueBuilder-DmwFtLzQ.mjs";
13
+ import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-Cv8C7yS1.mjs";
14
14
  import "./topic/index.mjs";
15
15
  import { ConstructName, Declaration, Dependency, INBOX_EVENT } from "@geekmidas/manifest";
16
16
  import { EventPublisher as EventPublisher$1 } from "@geekmidas/events";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/constructs",
3
- "version": "10.0.0-alpha.147",
3
+ "version": "10.0.0-alpha.148",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -335,13 +335,13 @@
335
335
  "lodash.uniqby": "~4.7.0",
336
336
  "openapi-types": "~12.1.3",
337
337
  "qs": "~6.16.0",
338
- "@geekmidas/envkit": "^10.0.0-alpha.147",
339
- "@geekmidas/errors": "^10.0.0-alpha.147",
340
- "@geekmidas/events": "^10.0.0-alpha.147",
341
- "@geekmidas/logger": "^10.0.0-alpha.147",
342
- "@geekmidas/manifest": "^10.0.0-alpha.147",
343
- "@geekmidas/schema": "^10.0.0-alpha.147",
344
- "@geekmidas/services": "^10.0.0-alpha.147"
338
+ "@geekmidas/envkit": "^10.0.0-alpha.148",
339
+ "@geekmidas/errors": "^10.0.0-alpha.148",
340
+ "@geekmidas/events": "^10.0.0-alpha.148",
341
+ "@geekmidas/logger": "^10.0.0-alpha.148",
342
+ "@geekmidas/manifest": "^10.0.0-alpha.148",
343
+ "@geekmidas/schema": "^10.0.0-alpha.148",
344
+ "@geekmidas/services": "^10.0.0-alpha.148"
345
345
  },
346
346
  "devDependencies": {
347
347
  "@aws-sdk/client-kms": "~3.1136.0",
@@ -360,20 +360,20 @@
360
360
  "pg": "~8.23.0",
361
361
  "ws": "~8.22.0",
362
362
  "zod": "~4.6.5",
363
- "@geekmidas/audit": "^10.0.0-alpha.147",
364
- "@geekmidas/auth": "10.0.0-alpha.147",
365
- "@geekmidas/cache": "^10.0.0-alpha.147",
366
- "@geekmidas/db": "^10.0.0-alpha.147",
367
- "@geekmidas/emailkit": "^10.0.0-alpha.147",
368
- "@geekmidas/envkit": "^10.0.0-alpha.147",
369
- "@geekmidas/errors": "^10.0.0-alpha.147",
370
- "@geekmidas/events": "^10.0.0-alpha.147",
371
- "@geekmidas/logger": "^10.0.0-alpha.147",
372
- "@geekmidas/rate-limit": "^10.0.0-alpha.147",
373
- "@geekmidas/schema": "^10.0.0-alpha.147",
374
- "@geekmidas/services": "^10.0.0-alpha.147",
375
- "@geekmidas/telescope": "10.0.0-alpha.147",
376
- "@geekmidas/testkit": "^10.0.0-alpha.147"
363
+ "@geekmidas/audit": "^10.0.0-alpha.148",
364
+ "@geekmidas/auth": "10.0.0-alpha.148",
365
+ "@geekmidas/cache": "^10.0.0-alpha.148",
366
+ "@geekmidas/db": "^10.0.0-alpha.148",
367
+ "@geekmidas/emailkit": "^10.0.0-alpha.148",
368
+ "@geekmidas/envkit": "^10.0.0-alpha.148",
369
+ "@geekmidas/errors": "^10.0.0-alpha.148",
370
+ "@geekmidas/events": "^10.0.0-alpha.148",
371
+ "@geekmidas/logger": "^10.0.0-alpha.148",
372
+ "@geekmidas/rate-limit": "^10.0.0-alpha.148",
373
+ "@geekmidas/schema": "^10.0.0-alpha.148",
374
+ "@geekmidas/services": "^10.0.0-alpha.148",
375
+ "@geekmidas/telescope": "10.0.0-alpha.148",
376
+ "@geekmidas/testkit": "^10.0.0-alpha.148"
377
377
  },
378
378
  "peerDependencies": {
379
379
  "@aws-sdk/client-kms": ">=3.1136.0",
@@ -386,15 +386,15 @@
386
386
  "msw": ">=2.15.0",
387
387
  "pg": ">=8.23.0",
388
388
  "ws": ">=8.22.0",
389
- "@geekmidas/audit": "^10.0.0-alpha.147",
390
- "@geekmidas/auth": "10.0.0-alpha.147",
391
- "@geekmidas/cache": "^10.0.0-alpha.147",
392
- "@geekmidas/db": "^10.0.0-alpha.147",
393
- "@geekmidas/emailkit": "^10.0.0-alpha.147",
394
- "@geekmidas/rate-limit": "^10.0.0-alpha.147",
395
- "@geekmidas/storage": "^10.0.0-alpha.147",
396
- "@geekmidas/telescope": "10.0.0-alpha.147",
397
- "@geekmidas/testkit": "^10.0.0-alpha.147"
389
+ "@geekmidas/audit": "^10.0.0-alpha.148",
390
+ "@geekmidas/auth": "10.0.0-alpha.148",
391
+ "@geekmidas/cache": "^10.0.0-alpha.148",
392
+ "@geekmidas/db": "^10.0.0-alpha.148",
393
+ "@geekmidas/emailkit": "^10.0.0-alpha.148",
394
+ "@geekmidas/rate-limit": "^10.0.0-alpha.148",
395
+ "@geekmidas/storage": "^10.0.0-alpha.148",
396
+ "@geekmidas/telescope": "10.0.0-alpha.148",
397
+ "@geekmidas/testkit": "^10.0.0-alpha.148"
398
398
  },
399
399
  "peerDependenciesMeta": {
400
400
  "@aws-sdk/client-kms": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"Endpoint-BcUorcBa.cjs","names":["Function","buildOpenApiSchema","convertSchemaWithComponents","convertStandardSchemaToJsonSchema"],"sources":["../src/endpoints/sessionAuth.ts","../src/endpoints/Endpoint.ts"],"sourcesContent":["import type { AuthSession } from '../auth';\nimport { identifyUser } from '../tracing';\nimport type { EndpointSurface, HeaderFn } from './Endpoint';\n\n/**\n * The surface's authenticator, as a session callback sees it.\n *\n * Bound to the request being handled, so reading the session takes no\n * argument: `session(async ({ auth }) => auth.getSession())`.\n */\nexport interface SessionAuth {\n\t/** This request's session, verified by the `.auth()` construct — or `null`. */\n\tgetSession(): Promise<AuthSession | null>;\n}\n\n/**\n * What is forwarded to the auth server: the headers a session travels in, and\n * whose request it is — nothing else.\n *\n * The client's address goes with the session because the auth server\n * rate-limits by it, `/get-session` included. Without it every user's session\n * check arrived from the surface itself — one shared bucket, so enough\n * traffic from anyone turned every session check into a 429 — and in tests,\n * concurrent tests queued on the same rate-limit row.\n */\nconst SESSION_HEADERS = ['cookie', 'authorization', 'x-forwarded-for'] as const;\n\n/** `auth` for one request on one surface. */\nexport function sessionAuth(\n\tsurface: EndpointSurface | undefined,\n\theader: HeaderFn,\n): SessionAuth {\n\treturn {\n\t\tasync getSession() {\n\t\t\tconst authenticator = surface?.auth;\n\t\t\tif (!surface || !authenticator) {\n\t\t\t\tthrow new NoAuthenticator(surface?.id);\n\t\t\t}\n\n\t\t\tconst headers = new Headers();\n\t\t\tfor (const name of SESSION_HEADERS) {\n\t\t\t\tconst value = header(name);\n\t\t\t\tif (value) headers.set(name, value);\n\t\t\t}\n\n\t\t\tconst session = (await authenticator.verify(\n\t\t\t\theaders,\n\t\t\t\tsurface.envParser,\n\t\t\t)) as AuthSession | null;\n\n\t\t\t// Whose request this is, from here on: its logger, its services and\n\t\t\t// its trace all say so. Read defensively: an authenticator other than\n\t\t\t// Better Auth answers in its own shape, and one without a user id\n\t\t\t// identifies no one.\n\t\t\tconst identity = session as {\n\t\t\t\tuser?: { id?: unknown };\n\t\t\t\tsession?: { id?: unknown };\n\t\t\t} | null;\n\t\t\tif (typeof identity?.user?.id === 'string') {\n\t\t\t\tidentifyUser({\n\t\t\t\t\tid: identity.user.id,\n\t\t\t\t\t...(typeof identity.session?.id === 'string'\n\t\t\t\t\t\t? { sessionId: identity.session.id }\n\t\t\t\t\t\t: {}),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn session;\n\t\t},\n\t};\n}\n\n/** `auth.getSession()` was called on a surface that names no authenticator. */\nexport class NoAuthenticator extends Error {\n\tconstructor(readonly surface: string | undefined) {\n\t\tsuper(\n\t\t\t`auth.getSession() needs an authenticator, and ${\n\t\t\t\tsurface ? `the surface '${surface}'` : 'this endpoint'\n\t\t\t} declares none: declare one on the surface with .auth(construct).`,\n\t\t);\n\t\tthis.name = 'NoAuthenticator';\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport type { RateLimitConfig } from '@geekmidas/rate-limit';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n\tInferStandardSchemaInput,\n} from '@geekmidas/schema';\nimport {\n\tconvertSchemaWithComponents,\n\tconvertStandardSchemaToJsonSchema,\n} from '@geekmidas/schema/conversion';\nimport {\n\tbuildOpenApiSchema,\n\ttype ComponentCollector,\n\ttype OpenApiSchemaOptions,\n} from '@geekmidas/schema/openapi';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { OpenAPIV3_1 } from 'openapi-types';\nimport { ConstructType } from '../Construct';\nimport type { Authenticator } from '../construct-interface';\nimport { Function, type FunctionHandler } from '../functions';\nimport type { TopicEvent } from '../publisher';\nimport type { EndpointTelemetry } from '../telemetry';\nimport type { HttpMethod, LowerHttpMethod, RemoveUndefined } from '../types';\nimport type { Authorizer } from './Authorizer';\nimport type { ActorExtractor, MappedAudit } from './audit';\nimport type { RlsConfig } from './rls';\nimport { type SessionAuth, sessionAuth } from './sessionAuth';\n\n/**\n * Represents an HTTP endpoint that can handle requests with type-safe input/output validation,\n * dependency injection, session management, and authorization.\n *\n * @template TRoute - The route path string with parameter placeholders (e.g., '/users/:id')\n * @template TMethod - The HTTP method (GET, POST, PUT, DELETE, PATCH)\n * @template TInput - The input schema definition for body, query, and path parameters\n * @template OutSchema - The output schema for response validation\n * @template TServices - Array of service dependencies to inject\n * @template TLogger - The logger instance type\n * @template TSession - The session data type\n *\n * @extends Function - Base function construct for handler execution\n *\n * @example\n * ```typescript\n * const endpoint = new Endpoint({\n * route: '/users/:id',\n * method: 'GET',\n * input: { params: userIdSchema },\n * output: userSchema,\n * fn: async ({ params }) => getUserById(params.id)\n * });\n * ```\n */\nexport class Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends Function<\n\tTInput,\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction,\n\tFunctionHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>\n> {\n\toperationId?: string;\n\t/** The route path pattern with parameter placeholders */\n\troute: TRoute;\n\t/** The HTTP method for this endpoint */\n\tmethod: TMethod;\n\t/**\n\t * The surface that serves it, when it was built from one.\n\t *\n\t * Carries the env parser the adaptors need, so a generated handler needs no\n\t * import written for it — and the surface's id, so the build attributes the\n\t * route to the API that serves it rather than inferring it by exclusion.\n\t */\n\tsurface: EndpointSurface;\n\t/** Optional description for OpenAPI documentation */\n\tdescription?: string;\n\t/** Optional tags for OpenAPI documentation */\n\ttags?: string[];\n\t/** The HTTP status code to return (default: 200) */\n\tpublic readonly status: EndpointStatus;\n\t/**\n\t * Response content type for this endpoint. Defaults to `'application/json'`.\n\t * Non-JSON types cause adaptors to emit the body as-is with the declared\n\t * Content-Type header instead of JSON-serializing.\n\t */\n\tpublic readonly responseType: string;\n\n\t/**\n\t * This route's telemetry — `.telemetry({ ignore, attributes })` — read by\n\t * the build, which hands it to the request middleware.\n\t */\n\tpublic telemetry?: EndpointTelemetry;\n\t/** Default headers to apply to all responses */\n\tpublic readonly defaultHeaders: Record<string, string> = {};\n\t/** Function to extract session data from the request context */\n\tpublic getSession: SessionFn<TServices, TLogger, TSession, TDatabase> = () =>\n\t\t({}) as TSession;\n\t/**\n\t * Whether a session callback was given — `.session()` on the factory it was\n\t * built from. A generated handler reads the session only when it is, so\n\t * an endpoint with a session and no authorizer must say so: it used to be\n\t * handed `undefined` in a production build and its session in `gkm dev`.\n\t */\n\tpublic readonly hasSession: boolean = false;\n\t/** Function to determine if the request is authorized */\n\tpublic authorize: AuthorizeFn<\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTInput,\n\t\tTDatabase\n\t> = () => true;\n\t/** Optional rate limiting configuration */\n\tpublic rateLimit?: RateLimitConfig;\n\t/** Optional authorizer for this endpoint */\n\tpublic authorizer?: Authorizer;\n\t/** Optional actor extractor for audit records */\n\tpublic actorExtractor?: ActorExtractor<TServices, TSession, TLogger>;\n\t/** Declarative audit definitions */\n\tpublic audits: MappedAudit<TAuditAction, OutSchema>[] = [];\n\t/** Database service for this endpoint */\n\tpublic declare databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\t/** RLS configuration for this endpoint */\n\tpublic rlsConfig?: RlsConfig<TServices, TSession, TLogger>;\n\t/** Whether to bypass RLS for this endpoint */\n\tpublic rlsBypass?: boolean;\n\t/** The endpoint handler function */\n\tprivate endpointFn!: EndpointHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTSession,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>;\n\n\t/**\n\t * Builds a complete OpenAPI 3.1 schema from an array of endpoints.\n\t *\n\t * @param endpoints - Array of endpoint instances to document\n\t * @param options - Optional configuration for OpenAPI generation\n\t * @returns OpenAPI 3.1 specification object\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = await Endpoint.buildOpenApiSchema([\n\t * getUserEndpoint,\n\t * createUserEndpoint\n\t * ], {\n\t * title: 'User API',\n\t * version: '1.0.0'\n\t * });\n\t * ```\n\t */\n\tstatic async buildOpenApiSchema(\n\t\tendpoints: Endpoint<any, any, any, any, any, any>[],\n\t\toptions?: OpenApiSchemaOptions,\n\t) {\n\t\treturn buildOpenApiSchema(endpoints, options);\n\t}\n\n\t/**\n\t * Gets the full path including HTTP method and route.\n\t * @returns Formatted string like 'GET /users/{id}'\n\t */\n\tget fullPath() {\n\t\treturn `${this.method} ${this._path}` as const;\n\t}\n\n\t/**\n\t * Parses and validates input data for a specific input type (body, query, params).\n\t *\n\t * @param input - The raw input data to validate\n\t * @param key - The input type key ('body', 'query', or 'params')\n\t * @returns The validated input data for the specified key\n\t * @throws {UnprocessableEntityError} When validation fails\n\t */\n\tasync parseInput<K extends keyof TInput>(\n\t\tinput: unknown,\n\t\tkey: K,\n\t): Promise<InferComposableStandardSchema<TInput[K]>> {\n\t\tconst schema = this.input?.[key];\n\t\treturn Endpoint.parseSchema(schema as StandardSchemaV1, input) as Promise<\n\t\t\tInferComposableStandardSchema<TInput[K]>\n\t\t>;\n\t}\n\n\t/**\n\t * Parses and validates the request body against the body schema.\n\t *\n\t * @param body - The raw request body to validate\n\t * @returns The validated body data\n\t * @throws {UnprocessableEntityError} When body validation fails\n\t */\n\tasync parseBody(body: unknown): Promise<InferStandardSchema<TInput['body']>> {\n\t\treturn this.parseInput(body, 'body') as Promise<\n\t\t\tInferStandardSchema<TInput['body']>\n\t\t>;\n\t}\n\n\tstatic isSuccessStatus(status: number): boolean {\n\t\treturn status >= 200 && status < 300;\n\t}\n\n\t/**\n\t * Whether `status` sends the client elsewhere. A redirect has no body, so\n\t * its response is not checked against the output schema, and what is\n\t * derived from the output — declared events and audits — is not sent.\n\t */\n\tstatic isRedirectStatus(status: number | undefined): boolean {\n\t\treturn status !== undefined && status >= 300 && status < 400;\n\t}\n\n\t/**\n\t * Creates a case-insensitive header lookup function from a headers object.\n\t *\n\t * @param headers - Object containing header key-value pairs\n\t * @returns Function to retrieve header values by case-insensitive key, or all headers\n\t *\n\t * @example\n\t * ```typescript\n\t * const headerFn = Endpoint.createHeaders({ 'Content-Type': 'application/json' });\n\t * headerFn('content-type'); // Returns 'application/json'\n\t * headerFn(); // Returns { 'content-type': 'application/json' }\n\t * ```\n\t */\n\tstatic createHeaders(headers: Record<string, string>): HeaderFn {\n\t\tconst headerMap = new Map<string, string>();\n\t\tfor (const [k, v] of Object.entries(headers)) {\n\t\t\tconst key = k.toLowerCase();\n\t\t\theaderMap.set(key, v);\n\t\t}\n\n\t\tfunction get(): Record<string, string>;\n\t\tfunction get(key: string): string | undefined;\n\t\tfunction get(key?: string): string | undefined | Record<string, string> {\n\t\t\tif (key === undefined) {\n\t\t\t\t// Return all headers as plain object\n\t\t\t\treturn Object.fromEntries(headerMap.entries());\n\t\t\t}\n\t\t\treturn headerMap.get(key.toLowerCase());\n\t\t}\n\n\t\treturn get;\n\t}\n\n\t/**\n\t * Parses cookie string and creates a cookie lookup function.\n\t *\n\t * @param cookieHeader - The Cookie header value\n\t * @returns Function to retrieve cookie values by name, or all cookies\n\t *\n\t * @example\n\t * ```typescript\n\t * const cookieFn = Endpoint.createCookies('session=abc123; theme=dark');\n\t * cookieFn('session'); // Returns 'abc123'\n\t * cookieFn(); // Returns { session: 'abc123', theme: 'dark' }\n\t * ```\n\t */\n\tstatic createCookies(cookieHeader: string | undefined): CookieFn {\n\t\tconst cookieMap = new Map<string, string>();\n\n\t\tif (cookieHeader) {\n\t\t\t// Parse cookie string: \"name1=value1; name2=value2\"\n\t\t\tconst cookies = cookieHeader.split(';');\n\t\t\tfor (const cookie of cookies) {\n\t\t\t\tconst [name, ...valueParts] = cookie.trim().split('=');\n\t\t\t\tif (name) {\n\t\t\t\t\tconst value = valueParts.join('='); // Handle values with = in them\n\t\t\t\t\tcookieMap.set(name, decodeURIComponent(value));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction get(): Record<string, string>;\n\t\tfunction get(name: string): string | undefined;\n\t\tfunction get(name?: string): string | undefined | Record<string, string> {\n\t\t\tif (name === undefined) {\n\t\t\t\t// Return all cookies as plain object\n\t\t\t\treturn Object.fromEntries(cookieMap.entries());\n\t\t\t}\n\t\t\treturn cookieMap.get(name);\n\t\t}\n\n\t\treturn get;\n\t}\n\n\t/**\n\t * Formats a cookie as a Set-Cookie header string.\n\t *\n\t * @param name - Cookie name\n\t * @param value - Cookie value\n\t * @param options - Cookie options (httpOnly, secure, sameSite, etc.)\n\t * @returns Formatted Set-Cookie header string\n\t *\n\t * @example\n\t * ```typescript\n\t * const header = Endpoint.formatCookieHeader('session', 'abc123', {\n\t * httpOnly: true,\n\t * secure: true,\n\t * sameSite: 'strict',\n\t * maxAge: 3600\n\t * });\n\t * // Returns: \"session=abc123; Max-Age=3600; HttpOnly; Secure; SameSite=Strict\"\n\t * ```\n\t */\n\tstatic formatCookieHeader(\n\t\tname: string,\n\t\tvalue: string,\n\t\toptions?: CookieOptions,\n\t): string {\n\t\tlet cookie = `${name}=${value}`;\n\n\t\tif (options) {\n\t\t\tif (options.domain) cookie += `; Domain=${options.domain}`;\n\t\t\tif (options.path) cookie += `; Path=${options.path}`;\n\t\t\tif (options.expires)\n\t\t\t\tcookie += `; Expires=${options.expires.toUTCString()}`;\n\t\t\tif (options.maxAge !== undefined) cookie += `; Max-Age=${options.maxAge}`;\n\t\t\tif (options.httpOnly) cookie += '; HttpOnly';\n\t\t\tif (options.secure) cookie += '; Secure';\n\t\t\tif (options.sameSite) {\n\t\t\t\tcookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn cookie;\n\t}\n\n\t/**\n\t * Extracts and refines input data from the endpoint context.\n\t *\n\t * @param ctx - The endpoint execution context\n\t * @returns Object containing only the input data (body, query, params)\n\t * @internal\n\t */\n\trefineInput(\n\t\tctx: EndpointContext<TInput, TServices, TLogger, TSession>,\n\t): InferComposableStandardSchema<TInput> {\n\t\tconst input: Record<string, unknown> = {};\n\t\tfor (const key of ['body', 'query', 'params'] as const) {\n\t\t\tif (key in ctx) {\n\t\t\t\tinput[key] = (ctx as Record<string, unknown>)[key];\n\t\t\t}\n\t\t}\n\n\t\treturn input as InferComposableStandardSchema<TInput>;\n\t}\n\n\thandler = (\n\t\tctx: EndpointContext<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTAuditStorage\n\t\t>,\n\t\tresponse: ResponseBuilder,\n\t): OutSchema extends StandardSchemaV1\n\t\t? // Handler produces the output schema's INPUT type (the schema\n\t\t\t// may coerce it on the way out — see EndpointHandler).\n\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t\t| Promise<\n\t\t\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t\t >\n\t\t:\n\t\t\t\t| any\n\t\t\t\t| ResponseWithMetadata<any>\n\t\t\t\t| Promise<any>\n\t\t\t\t| Promise<ResponseWithMetadata<any>> => {\n\t\t// Apply default headers to response builder\n\t\tfor (const [key, value] of Object.entries(this.defaultHeaders)) {\n\t\t\tresponse.header(key, value);\n\t\t}\n\n\t\t// Build context object, conditionally including auditor and db\n\t\tconst handlerCtx = {\n\t\t\t...this.refineInput(ctx),\n\t\t\tservices: ctx.services,\n\t\t\tlogger: ctx.logger,\n\t\t\theader: ctx.header,\n\t\t\tcookie: ctx.cookie,\n\t\t\tsession: ctx.session,\n\t\t\t// These are conditionally present based on configuration\n\t\t\t...('auditor' in ctx && { auditor: ctx.auditor }),\n\t\t\t...('db' in ctx && { db: ctx.db }),\n\t\t} as EndpointContext<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTAuditStorage\n\t\t>;\n\n\t\treturn this.endpointFn(handlerCtx, response);\n\t};\n\n\t/**\n\t * Type guard to check if an object is an Endpoint instance.\n\t *\n\t * @param obj - The object to check\n\t * @returns True if the object is an Endpoint\n\t */\n\tstatic isEndpoint(obj: any): obj is Endpoint<any, any, any, any> {\n\t\treturn Boolean(\n\t\t\tobj &&\n\t\t\t\t(obj as Function).__IS_FUNCTION__ === true &&\n\t\t\t\tobj.type === ConstructType.Endpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Helper to check if response has metadata\n\t */\n\tstatic hasMetadata<T>(\n\t\tresponse: T | ResponseWithMetadata<T>,\n\t): response is ResponseWithMetadata<T> {\n\t\treturn (\n\t\t\tresponse !== null &&\n\t\t\ttypeof response === 'object' &&\n\t\t\t'data' in response &&\n\t\t\t'metadata' in response\n\t\t);\n\t}\n\n\t/**\n\t * Converts Express-style route params to OpenAPI format.\n\t * @returns Route with ':param' converted to '{param}'\n\t * @internal\n\t */\n\tget _path() {\n\t\treturn this.route.replace(/:(\\w+)/g, '{$1}') as ConvertRouteParams<TRoute>;\n\t}\n\n\t/**\n\t * Generates OpenAPI 3.1 schema for this endpoint.\n\t *\n\t * @returns OpenAPI route definition with operation details\n\t */\n\tasync toOpenApi3Route(\n\t\tcomponentCollector?: ComponentCollector,\n\t): Promise<EndpointOpenApiSchema<TRoute, TMethod>> {\n\t\t// The status the handler answers with — `.status(201)` is documented as\n\t\t// 201, not as the 200 every endpoint used to claim.\n\t\tconst status = String(this.status);\n\t\tconst operation: OpenAPIV3_1.OperationObject = {\n\t\t\toperationId: this.operationId,\n\t\t\t...(this.description && { description: this.description }),\n\t\t\t...(this.tags && this.tags.length > 0 && { tags: this.tags }),\n\t\t\tresponses: {\n\t\t\t\t[status]: {\n\t\t\t\t\tdescription: 'Successful response',\n\t\t\t\t} as OpenAPIV3_1.ResponseObject,\n\t\t\t},\n\t\t};\n\n\t\t// What protects it. Without this every endpoint read as public in the\n\t\t// document, including the ones an authorizer guards.\n\t\tconst scheme = this.authorizer?.securityScheme;\n\t\tif (this.authorizer && scheme && componentCollector) {\n\t\t\tcomponentCollector.addSecurityScheme(\n\t\t\t\tthis.authorizer.name,\n\t\t\t\tscheme as OpenAPIV3_1.SecuritySchemeObject,\n\t\t\t);\n\t\t\toperation.security = [{ [this.authorizer.name]: [] }];\n\t\t}\n\n\t\t// Add response schema\n\t\tif (this.outputSchema) {\n\t\t\tconst responseSchema = await convertSchemaWithComponents(\n\t\t\t\tthis.outputSchema,\n\t\t\t\tcomponentCollector,\n\t\t\t);\n\t\t\tif (responseSchema) {\n\t\t\t\t(operation.responses![status] as OpenAPIV3_1.ResponseObject).content = {\n\t\t\t\t\t[this.responseType]: { schema: responseSchema },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Separate path and query parameters\n\t\tconst pathParameters: OpenAPIV3_1.ParameterObject[] = [];\n\t\tconst queryParameters: OpenAPIV3_1.ParameterObject[] = [];\n\n\t\t// Since the EndpointBuilder doesn't have body/search/params methods yet,\n\t\t// and the input is a composite type, we need to check if input exists\n\t\t// and has the expected shape\n\t\tif (this.input && typeof this.input === 'object') {\n\t\t\t// Add request body for methods that support it\n\t\t\tif (\n\t\t\t\t['POST', 'PUT', 'PATCH'].includes(this.method) &&\n\t\t\t\t'body' in this.input &&\n\t\t\t\tthis.input.body\n\t\t\t) {\n\t\t\t\tconst bodySchema = await convertSchemaWithComponents(\n\t\t\t\t\tthis.input.body as StandardSchemaV1,\n\t\t\t\t\tcomponentCollector,\n\t\t\t\t);\n\t\t\t\tif (bodySchema) {\n\t\t\t\t\toperation.requestBody = {\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t'application/json': {\n\t\t\t\t\t\t\t\tschema: bodySchema,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add path parameters\n\t\t\tif ('params' in this.input && this.input.params) {\n\t\t\t\tconst paramsSchema = await convertStandardSchemaToJsonSchema(\n\t\t\t\t\tthis.input.params as StandardSchemaV1,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tparamsSchema &&\n\t\t\t\t\tparamsSchema.type === 'object' &&\n\t\t\t\t\tparamsSchema.properties\n\t\t\t\t) {\n\t\t\t\t\tfor (const [name, schema] of Object.entries(\n\t\t\t\t\t\tparamsSchema.properties,\n\t\t\t\t\t)) {\n\t\t\t\t\t\tpathParameters.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tin: 'path',\n\t\t\t\t\t\t\trequired: paramsSchema.required?.includes(name) ?? true,\n\t\t\t\t\t\t\tschema: schema as any,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add query parameters\n\t\t\tif ('query' in this.input && this.input.query) {\n\t\t\t\tconst querySchema = await convertStandardSchemaToJsonSchema(\n\t\t\t\t\tthis.input.query,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tquerySchema &&\n\t\t\t\t\tquerySchema.type === 'object' &&\n\t\t\t\t\tquerySchema.properties\n\t\t\t\t) {\n\t\t\t\t\tfor (const [name, schema] of Object.entries(querySchema.properties)) {\n\t\t\t\t\t\tqueryParameters.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tin: 'query',\n\t\t\t\t\t\t\trequired: querySchema.required?.includes(name) ?? false,\n\t\t\t\t\t\t\tschema: schema as any,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Only add query parameters to the operation\n\t\tif (queryParameters.length > 0) {\n\t\t\toperation.parameters = queryParameters;\n\t\t}\n\n\t\t// Build the route object with path parameters at the route level\n\t\tconst routeObject: any = {};\n\t\tif (pathParameters.length > 0) {\n\t\t\trouteObject.parameters = pathParameters;\n\t\t}\n\t\trouteObject[this.method.toLowerCase()] = operation;\n\n\t\treturn {\n\t\t\t[this._path]: routeObject,\n\t\t} as EndpointOpenApiSchema<TRoute, TMethod>;\n\t}\n\n\t/**\n\t * Creates a new Endpoint instance.\n\t *\n\t * @param options - Configuration options for the endpoint\n\t * @param options.fn - The handler function to execute\n\t * @param options.method - HTTP method\n\t * @param options.route - Route path with parameter placeholders\n\t * @param options.description - Optional description for documentation\n\t * @param options.input - Input schemas for validation\n\t * @param options.logger - Logger instance\n\t * @param options.output - Output schema for response validation\n\t * @param options.services - Service dependencies\n\t * @param options.timeout - Execution timeout in milliseconds\n\t * @param options.getSession - Session extraction function\n\t * @param options.authorize - Authorization check function\n\t * @param options.status - Success HTTP status code (default: 200)\n\t * @param options.authorizer - Optional authorizer configuration\n\t */\n\tconstructor({\n\t\tfn,\n\t\tmethod,\n\t\troute,\n\t\tdescription,\n\t\ttags,\n\t\tinput,\n\t\tlogger,\n\t\toutput: outputSchema,\n\t\tservices,\n\t\tconstructs,\n\t\ttimeout,\n\t\tmemorySize,\n\t\tgetSession,\n\t\tauthorize,\n\t\trateLimit,\n\t\tstatus = SuccessStatus.OK,\n\t\tevents,\n\t\tauthorizer,\n\t\tsurface,\n\t\tauditorStorageService,\n\t\tactorExtractor,\n\t\taudits,\n\t\tdatabaseService,\n\t\trlsConfig,\n\t\trlsBypass,\n\t\tresponseType,\n\t\ttelemetry,\n\t}: EndpointOptions<\n\t\tTRoute,\n\t\tTMethod,\n\t\tTInput,\n\t\tOutSchema,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tOutSchema,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t>) {\n\t\tsuper(\n\t\t\tfn as unknown as FunctionHandler<TInput, TServices, TLogger, OutSchema>,\n\t\t\ttimeout,\n\t\t\tConstructType.Endpoint,\n\t\t\tinput,\n\t\t\toutputSchema,\n\t\t\tservices,\n\t\t\tlogger,\n\t\t\tevents,\n\t\t\tmemorySize,\n\t\t\tauditorStorageService,\n\t\t\tundefined, // databaseService — assigned below, after the RLS wiring\n\t\t\tconstructs,\n\t\t);\n\n\t\tthis.route = route;\n\t\tthis.method = method;\n\t\tthis.description = description;\n\t\tthis.tags = tags;\n\t\tthis.status = status;\n\t\tthis.responseType = responseType ?? 'application/json';\n\t\tthis.endpointFn = fn;\n\t\tif (telemetry) this.telemetry = telemetry;\n\n\t\tif (getSession) {\n\t\t\tthis.hasSession = true;\n\t\t\t// `auth` is added here, once, rather than by each adaptor: every\n\t\t\t// adaptor calls this, so every one of them hands a session callback\n\t\t\t// the surface's authenticator bound to the request it is handling.\n\t\t\tthis.getSession = (ctx) =>\n\t\t\t\tgetSession({ ...ctx, auth: sessionAuth(surface, ctx.header) });\n\t\t}\n\n\t\tif (authorize) {\n\t\t\tthis.authorize = authorize;\n\t\t}\n\n\t\tif (rateLimit) {\n\t\t\tthis.rateLimit = rateLimit;\n\t\t}\n\n\t\tif (authorizer) {\n\t\t\tthis.authorizer = authorizer;\n\t\t}\n\n\t\tthis.surface = surface;\n\n\t\tif (actorExtractor) {\n\t\t\tthis.actorExtractor = actorExtractor;\n\t\t}\n\n\t\tif (audits) {\n\t\t\tthis.audits = audits;\n\t\t}\n\n\t\tif (databaseService) {\n\t\t\tthis.databaseService = databaseService;\n\t\t}\n\n\t\tif (rlsConfig) {\n\t\t\tthis.rlsConfig = rlsConfig;\n\t\t}\n\n\t\tif (rlsBypass) {\n\t\t\tthis.rlsBypass = rlsBypass;\n\t\t}\n\t}\n}\n\n/**\n * Defines the input schema structure for an endpoint.\n *\n * @template TBody - Schema for request body validation\n * @template TSearch - Schema for query string validation\n * @template TParams - Schema for URL path parameters validation\n *\n * @example\n * ```typescript\n * type UserInput = EndpointInput<\n * typeof createUserBodySchema,\n * typeof userQuerySchema,\n * typeof userParamsSchema\n * >;\n * ```\n */\nexport type EndpointInput<\n\tTBody extends StandardSchemaV1 | undefined = undefined,\n\tTSearch extends StandardSchemaV1 | undefined = undefined,\n\tTParams extends StandardSchemaV1 | undefined = undefined,\n> = RemoveUndefined<{\n\tbody: TBody;\n\tsearch: TSearch;\n\tparams: TParams;\n}>;\n\n/**\n * The surface an endpoint was built from.\n *\n * An endpoint created with `api.get('/users')` knows which API serves it, and\n * through that, the two things every handler needs and no handler should have\n * to name: the process's logger and its environment parser.\n *\n * This is what makes the generated code smaller than the thing it replaced. A\n * handler used to be wired by an import the build wrote for it —\n * `import { envParser } from '../../config/env'` — which meant the parser had\n * to be named in config as a module path, because a generator can print a\n * specifier and cannot print an object. Built from the surface, the endpoint\n * already carries it, so there is nothing to name and nothing to print.\n *\n * `id` is the surface's construct id, which is how the build attributes a route\n * to the API that serves it rather than guessing by exclusion.\n */\nexport interface EndpointSurface {\n\t/** The surface's construct id — `Api`, `Auth`. */\n\tid: string;\n\t/**\n\t * The environment parser every handler on this surface runs with.\n\t *\n\t * A value the surface holds, never a place to do work: constructs are\n\t * imported by discovery before any URL exists, so a parser that reads a\n\t * file or throws on a missing variable would do it at build time.\n\t */\n\tenvParser: EnvironmentParser<{}>;\n\t/**\n\t * What authenticates requests to this surface — the construct named in\n\t * `RestApi.auth()`, which session callbacks read from as `auth`.\n\t */\n\tauth?: Authenticator;\n}\n\n/**\n * Configuration options for creating an Endpoint instance.\n *\n * @template TRoute - The route path string\n * @template TMethod - The HTTP method\n * @template TInput - Input schema definitions\n * @template TOutput - Output schema definition\n * @template TServices - Service dependencies array\n * @template TLogger - Logger type\n * @template TSession - Session data type\n */\nexport interface EndpointOptions<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutput extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\t/** The route path with parameter placeholders */\n\troute: TRoute;\n\t/** The HTTP method for this endpoint */\n\tmethod: TMethod;\n\t/** The handler function that implements the endpoint logic */\n\tfn: EndpointHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutput,\n\t\tTSession,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>;\n\t/** Optional authorization check function */\n\tauthorize:\n\t\t| AuthorizeFn<TServices, TLogger, TSession, TInput, TDatabase>\n\t\t| undefined;\n\t/** Optional description for documentation */\n\tdescription: string | undefined;\n\t/** Optional tags for OpenAPI documentation */\n\ttags?: string[];\n\t/** Optional execution timeout in milliseconds */\n\ttimeout: number | undefined;\n\t/** Optional memory size in MB for serverless deployments */\n\tmemorySize: number | undefined;\n\t/** Input validation schemas */\n\tinput: TInput | undefined;\n\t/** Output validation schema */\n\toutput: TOutput | undefined;\n\t/** Service dependencies to inject */\n\tservices: TServices;\n\t/**\n\t * The ids of the constructs `.dependsOn()` named.\n\t *\n\t * The same edges as `services`, kept in the form the manifest records rather\n\t * than the form the handler runs with.\n\t */\n\tconstructs?: string[];\n\t/** Logger instance */\n\tlogger: TLogger;\n\t/** Optional session extraction function */\n\tgetSession: SessionFn<TServices, TLogger, TSession, TDatabase> | undefined;\n\t/** Optional rate limiting configuration */\n\trateLimit?: RateLimitConfig;\n\t/** Success HTTP status code */\n\tstatus: EndpointStatus | undefined;\n\t/** What it publishes once its handler succeeds, each to its own topic. */\n\tevents?: TopicEvent[];\n\t/** Optional authorizer configuration */\n\tauthorizer?: Authorizer;\n\t/** The surface this endpoint was built from. Every endpoint has one. */\n\tsurface: EndpointSurface;\n\t/**\n\t * Auditor storage service for persisting audit records from this endpoint\n\t */\n\tauditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>;\n\t/** Optional actor extractor function for audit records */\n\tactorExtractor?: ActorExtractor<TServices, TSession, TLogger>;\n\t/** Declarative audit definitions */\n\taudits?: MappedAudit<TAuditAction, OutSchema>[];\n\t/** Database service for this endpoint */\n\tdatabaseService?: Service<TDatabaseServiceName, TDatabase>;\n\t/** RLS configuration for this endpoint */\n\trlsConfig?: RlsConfig<TServices, TSession, TLogger>;\n\t/** Whether to bypass RLS for this endpoint */\n\trlsBypass?: boolean;\n\t/**\n\t * Response content type (e.g. `'application/json'`, `'text/html'`).\n\t * Defaults to `'application/json'` when omitted.\n\t */\n\tresponseType?: string;\n\t/** This route's telemetry — `.telemetry({ ignore, attributes })`. */\n\ttelemetry?: EndpointTelemetry;\n}\n\n/**\n * Defines the possible input schema types for an endpoint.\n * Each property represents a different part of the HTTP request.\n */\nexport type EndpointSchemas = Partial<{\n\t/** Schema for URL path parameters (e.g., /users/:id) */\n\tparams: StandardSchemaV1;\n\t/** Schema for query string parameters */\n\tquery: StandardSchemaV1;\n\t/** Schema for request body (POST, PUT, PATCH) */\n\tbody: StandardSchemaV1;\n}>;\n\nexport type AuthorizeContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTDatabase = undefined,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\tsession: TSession;\n} & InferComposableStandardSchema<TInput> &\n\tSessionDatabaseContext<TDatabase>;\n/**\n * Function type for endpoint authorization checks.\n *\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type\n *\n * @param ctx - Context containing services, logger, headers, and session\n * @returns Boolean indicating if the request is authorized\n *\n * @example\n * ```typescript\n * const authorize: AuthorizeFn = ({ session }) => {\n * return session.userId !== undefined;\n * };\n * ```\n */\nexport type AuthorizeFn<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: AuthorizeContext<TServices, TLogger, TSession, TInput, TDatabase>,\n) => Promise<boolean> | boolean;\n\n/**\n * Base session context without database\n */\ntype BaseSessionContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\t/**\n\t * The surface's authenticator — the construct named in `.auth()` — bound to\n\t * this request: `await auth.getSession()` is this request's session, or\n\t * `null`.\n\t */\n\tauth: SessionAuth;\n};\n\n/**\n * Conditional database context for session - only present when database service is configured\n */\ntype SessionDatabaseContext<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Database instance for session extraction.\n\t\t\t * Available when a database service is configured via `.database()`.\n\t\t\t * Useful for looking up user data from the database based on auth tokens.\n\t\t\t */\n\t\t\tdb: TDatabase;\n\t\t};\n\nexport type SessionContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = BaseSessionContext<TServices, TLogger> & SessionDatabaseContext<TDatabase>;\n/**\n * Function type for extracting session data from a request.\n *\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type to extract\n * @template TDatabase - Database type (when database service is configured)\n *\n * @param ctx - Context containing services, logger, headers, and optionally database\n * @returns The extracted session data\n *\n * @example\n * ```typescript\n * // Without database\n * const getSession: SessionFn<Services, Logger, UserSession> = async ({ header, services }) => {\n * const token = header('authorization');\n * return await services.auth.verifyToken(token);\n * };\n *\n * // With database\n * const getSession: SessionFn<Services, Logger, UserSession, Database> = async ({ header, db }) => {\n * const token = header('authorization');\n * const user = await db.selectFrom('users').where('token', '=', token).executeTakeFirst();\n * return { userId: user?.id };\n * };\n * ```\n */\nexport type SessionFn<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTDatabase = undefined,\n> = (\n\tctx: SessionContext<TServices, TLogger, TDatabase>,\n) => Promise<TSession> | TSession;\n\n/**\n * Utility type that converts Express-style route parameters to OpenAPI format.\n * Transforms ':param' syntax to '{param}' syntax.\n *\n * @template T - The route string to convert\n *\n * @example\n * ```typescript\n * type Route1 = ConvertRouteParams<'/users/:id'>; // '/users/{id}'\n * type Route2 = ConvertRouteParams<'/users/:userId/posts/:postId'>; // '/users/{userId}/posts/{postId}'\n * ```\n */\nexport type ConvertRouteParams<T extends string> =\n\tT extends `${infer Start}:${infer Param}/${infer Rest}`\n\t\t? `${Start}{${Param}}/${ConvertRouteParams<Rest>}`\n\t\t: T extends `${infer Start}:${infer Param}`\n\t\t\t? `${Start}{${Param}}`\n\t\t\t: T;\n\n/**\n * Type representing the OpenAPI schema structure for an endpoint.\n *\n * @template TRoute - The route path\n * @template TMethod - The HTTP method\n *\n * @example\n * ```typescript\n * type Schema = EndpointOpenApiSchema<'/users/:id', 'GET'>;\n * // Results in: { '/users/{id}': { get: OperationObject, parameters?: ParameterObject[] } }\n * ```\n */\nexport type EndpointOpenApiSchema<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n> = {\n\t[key in ConvertRouteParams<TRoute>]: {\n\t\t[key in LowerHttpMethod<TMethod>]: OpenAPIV3_1.OperationObject<{}>;\n\t} & {\n\t\tparameters?: OpenAPIV3_1.ParameterObject[];\n\t};\n};\n\nexport type SingleHeaderFn = (key: string) => string | undefined;\nexport type MultiHeaderFn = () => EndpointHeaders;\n/**\n * Type representing HTTP headers as a Map.\n */\nexport type EndpointHeaders = Map<string, string>;\n\n/**\n * Function type for retrieving HTTP header values.\n * Supports two calling patterns:\n * - `header(key)` - Get a single header value (case-insensitive)\n * - `header()` - Get all headers as a plain object\n *\n * @example\n * ```typescript\n * // Get single header\n * const contentType = header('content-type');\n *\n * // Get all headers\n * const allHeaders = header();\n * // { 'content-type': 'application/json', 'host': 'example.com', ... }\n * ```\n */\nexport interface HeaderFn {\n\t(): Record<string, string>;\n\t(key: string): string | undefined;\n}\n\n/**\n * Function type for retrieving cookie values.\n * Supports two calling patterns:\n * - `cookie(name)` - Get a single cookie value\n * - `cookie()` - Get all cookies as a plain object\n *\n * @example\n * ```typescript\n * // Get single cookie\n * const sessionId = cookie('session');\n *\n * // Get all cookies\n * const allCookies = cookie();\n * // { session: 'abc123', theme: 'dark', ... }\n * ```\n */\nexport interface CookieFn {\n\t(): Record<string, string>;\n\t(name: string): string | undefined;\n}\n\n/**\n * Cookie options matching standard Set-Cookie attributes\n */\nexport interface CookieOptions {\n\tdomain?: string;\n\tpath?: string;\n\texpires?: Date;\n\tmaxAge?: number;\n\thttpOnly?: boolean;\n\tsecure?: boolean;\n\tsameSite?: 'strict' | 'lax' | 'none';\n}\n\n/**\n * Response metadata that handlers can set\n */\nexport interface ResponseMetadata {\n\theaders?: Record<string, string>;\n\tcookies?: Map<string, { value: string; options?: CookieOptions }>;\n\tstatus?: EndpointStatus;\n}\n\n/**\n * Return type for handlers that want to set response metadata\n */\nexport interface ResponseWithMetadata<T> {\n\tdata: T;\n\tmetadata: ResponseMetadata;\n}\n\n/**\n * Response builder for fluent API in handlers\n */\nexport class ResponseBuilder {\n\tprivate metadata: ResponseMetadata = {\n\t\theaders: {},\n\t\tcookies: new Map(),\n\t};\n\n\theader(key: string, value: string): this {\n\t\tthis.metadata.headers![key] = value;\n\t\treturn this;\n\t}\n\n\tcookie(name: string, value: string, options?: CookieOptions): this {\n\t\tthis.metadata.cookies?.set(name, { value, options });\n\t\treturn this;\n\t}\n\n\tdeleteCookie(\n\t\tname: string,\n\t\toptions?: Pick<CookieOptions, 'domain' | 'path'>,\n\t): this {\n\t\tthis.metadata.cookies?.set(name, {\n\t\t\tvalue: '',\n\t\t\toptions: { ...options, maxAge: 0, expires: new Date(0) },\n\t\t});\n\t\treturn this;\n\t}\n\n\tstatus(code: EndpointStatus): this {\n\t\tthis.metadata.status = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Send the client to `url` — `Location` and a 3xx, with no body. 303 by\n\t * default: after a form post, the browser follows it with a GET, so a\n\t * reload does not post the form again.\n\t *\n\t * A redirect is not checked against the endpoint's `.output()` schema, so\n\t * an endpoint that renders a page can redirect instead.\n\t *\n\t * @example\n\t * ```typescript\n\t * return response.cookie('session', token).redirect('/dashboard');\n\t * ```\n\t */\n\tredirect(\n\t\turl: string,\n\t\tstatus: RedirectStatus = RedirectStatus.SeeOther,\n\t): ResponseWithMetadata<never> {\n\t\tthis.metadata.headers!.location = url;\n\t\tthis.metadata.status = status;\n\t\treturn { data: undefined as never, metadata: this.metadata };\n\t}\n\n\tsend<T>(data: T): ResponseWithMetadata<T> {\n\t\treturn { data, metadata: this.metadata };\n\t}\n\n\tgetMetadata(): ResponseMetadata {\n\t\treturn this.metadata;\n\t}\n}\n\n/**\n * Base context properties that are always available\n */\ntype BaseEndpointContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = {\n\t/** Injected service instances */\n\tservices: ServiceRecord<TServices>;\n\t/** Logger instance for this request */\n\tlogger: TLogger;\n\t/** Function to retrieve request headers */\n\theader: HeaderFn;\n\t/** Function to retrieve request cookies */\n\tcookie: CookieFn;\n\t/** Session data extracted by getSession */\n\tsession: TSession;\n};\n\n/**\n * Conditional auditor context - only present when audit storage is configured\n */\ntype AuditorContext<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTAuditStorage = undefined,\n> = TAuditStorage extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Auditor instance for recording audit events.\n\t\t\t * Only present when audit storage is configured on the endpoint.\n\t\t\t * When a transactional database is used for audit storage,\n\t\t\t * the auditor is pre-configured with the transaction context.\n\t\t\t */\n\t\t\tauditor: Auditor<TAuditAction>;\n\t\t};\n\n/**\n * Conditional database context - only present when database service is configured\n */\ntype DatabaseContext<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Database instance for this request.\n\t\t\t * When audit storage is configured and uses the same database,\n\t\t\t * this will be the transaction for ACID compliance.\n\t\t\t * Otherwise, it's the raw database connection.\n\t\t\t */\n\t\t\tdb: TDatabase;\n\t\t};\n\n/**\n * The execution context provided to endpoint handlers.\n * Contains all parsed input data, services, logger, headers, cookies, and session.\n *\n * @template Input - The input schemas (body, query, params)\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type\n * @template TAuditAction - Audit action types (when auditor is configured)\n * @template TDatabase - Database type (when database service is configured)\n * @template TAuditStorage - Audit storage type (determines if auditor is present)\n */\nexport type EndpointContext<\n\tInput extends EndpointSchemas | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTAuditStorage = undefined,\n> = BaseEndpointContext<TServices, TLogger, TSession> &\n\tInferComposableStandardSchema<Input> &\n\tAuditorContext<TAuditAction, TAuditStorage> &\n\tDatabaseContext<TDatabase>;\n\n/**\n * Handler function type for endpoint implementations.\n *\n * @template TInput - Input schemas for validation\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template OutSchema - Output schema for response validation\n * @template TSession - Session data type\n *\n * @param ctx - The endpoint execution context\n * @param response - Response builder for setting cookies, headers, and status\n * @returns The response data (validated if OutSchema is provided) or ResponseWithMetadata\n *\n * @example\n * ```typescript\n * // Simple response\n * const handler: EndpointHandler<Input, [UserService], Logger, UserSchema> =\n * async ({ params, services }) => {\n * return await services.users.findById(params.id);\n * };\n *\n * // With response builder\n * const handler: EndpointHandler<Input, [UserService], Logger, UserSchema> =\n * async ({ params, services }, response) => {\n * const user = await services.users.findById(params.id);\n * return response.header('X-User-Id', user.id).send(user);\n * };\n * ```\n */\nexport type EndpointHandler<\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTSession = unknown,\n\tTDatabase = undefined,\n\tTAuditStorage = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = (\n\tctx: EndpointContext<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTAuditStorage\n\t>,\n\tresponse: ResponseBuilder,\n) => OutSchema extends StandardSchemaV1\n\t? // The handler must produce the schema's INPUT type — the output\n\t\t// schema is allowed to coerce it (e.g. a `Date` → ISO `string`),\n\t\t// so the handler may return the looser input while consumers\n\t\t// (EndpointOutput / the generated client) still see the parsed\n\t\t// output type.\n\t\t// A handler that sometimes redirects returns either from one\n\t\t// promise, so the promise may hold either.\n\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t| Promise<\n\t\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t >\n\t:\n\t\t\t| unknown\n\t\t\t| ResponseWithMetadata<unknown>\n\t\t\t| Promise<unknown>\n\t\t\t| Promise<ResponseWithMetadata<unknown>>;\n\n/**\n * HTTP success status codes that can be returned by endpoints.\n */\nexport enum SuccessStatus {\n\t/** Standard response for successful HTTP requests */\n\tOK = 200,\n\t/** Request has been fulfilled and resulted in a new resource being created */\n\tCreated = 201,\n\t/** Request has been accepted for processing, but processing is not complete */\n\tAccepted = 202,\n\t/** Server successfully processed the request but is not returning any content */\n\tNoContent = 204,\n\t/** Server successfully processed the request and is not returning any content, client should reset the document view */\n\tResetContent = 205,\n\t/** Server is delivering only part of the resource due to a range header */\n\tPartialContent = 206,\n}\n\n/**\n * HTTP redirect status codes an endpoint can answer with —\n * `response.redirect(url, status)`, or `.status()` with a `Location` header.\n */\nexport enum RedirectStatus {\n\t/** The resource has moved for good; a POST may become a GET */\n\tMovedPermanently = 301,\n\t/** The resource is elsewhere for now; a POST may become a GET */\n\tFound = 302,\n\t/** See the resource elsewhere, with a GET — the answer to a form post */\n\tSeeOther = 303,\n\t/** The resource is elsewhere for now; the method and body are kept */\n\tTemporaryRedirect = 307,\n\t/** The resource has moved for good; the method and body are kept */\n\tPermanentRedirect = 308,\n}\n\n/** A status an endpoint answers with when its handler succeeds. */\nexport type EndpointStatus = SuccessStatus | RedirectStatus;\n\nexport type EndpointOutput<T> =\n\tT extends Endpoint<any, any, any, infer OutSchema, any, any, any, any>\n\t\t? InferStandardSchema<OutSchema>\n\t\t: never;\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAM,kBAAkB;CAAC;CAAU;CAAiB;AAAiB;;AAGrE,SAAgB,YACf,SACA,QACc;CACd,OAAO,EACN,MAAM,aAAa;EAClB,MAAM,gBAAgB,SAAS;EAC/B,IAAI,CAAC,WAAW,CAAC,eAChB,MAAM,IAAI,gBAAgB,SAAS,EAAE;EAGtC,MAAM,UAAU,IAAI,QAAQ;EAC5B,KAAK,MAAM,QAAQ,iBAAiB;GACnC,MAAM,QAAQ,OAAO,IAAI;GACzB,IAAI,OAAO,QAAQ,IAAI,MAAM,KAAK;EACnC;EAEA,MAAM,UAAW,MAAM,cAAc,OACpC,SACA,QAAQ,SACT;EAMA,MAAM,WAAW;EAIjB,IAAI,OAAO,UAAU,MAAM,OAAO,UACjC,gBAAA,aAAa;GACZ,IAAI,SAAS,KAAK;GAClB,GAAI,OAAO,SAAS,SAAS,OAAO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"],"sourcesContent":["import type { AuthSession } from '../auth';\nimport { identifyUser } from '../tracing';\nimport type { EndpointSurface, HeaderFn } from './Endpoint';\n\n/**\n * The surface's authenticator, as a session callback sees it.\n *\n * Bound to the request being handled, so reading the session takes no\n * argument: `session(async ({ auth }) => auth.getSession())`.\n */\nexport interface SessionAuth {\n\t/** This request's session, verified by the `.auth()` construct — or `null`. */\n\tgetSession(): Promise<AuthSession | null>;\n}\n\n/**\n * What is forwarded to the auth server: the headers a session travels in, and\n * whose request it is — nothing else.\n *\n * The client's address goes with the session because the auth server\n * rate-limits by it, `/get-session` included. Without it every user's session\n * check arrived from the surface itself — one shared bucket, so enough\n * traffic from anyone turned every session check into a 429 — and in tests,\n * concurrent tests queued on the same rate-limit row.\n */\nconst SESSION_HEADERS = ['cookie', 'authorization', 'x-forwarded-for'] as const;\n\n/** `auth` for one request on one surface. */\nexport function sessionAuth(\n\tsurface: EndpointSurface | undefined,\n\theader: HeaderFn,\n): SessionAuth {\n\treturn {\n\t\tasync getSession() {\n\t\t\tconst authenticator = surface?.auth;\n\t\t\tif (!surface || !authenticator) {\n\t\t\t\tthrow new NoAuthenticator(surface?.id);\n\t\t\t}\n\n\t\t\tconst headers = new Headers();\n\t\t\tfor (const name of SESSION_HEADERS) {\n\t\t\t\tconst value = header(name);\n\t\t\t\tif (value) headers.set(name, value);\n\t\t\t}\n\n\t\t\tconst session = (await authenticator.verify(\n\t\t\t\theaders,\n\t\t\t\tsurface.envParser,\n\t\t\t)) as AuthSession | null;\n\n\t\t\t// Whose request this is, from here on: its logger, its services and\n\t\t\t// its trace all say so. Read defensively: an authenticator other than\n\t\t\t// Better Auth answers in its own shape, and one without a user id\n\t\t\t// identifies no one.\n\t\t\tconst identity = session as {\n\t\t\t\tuser?: { id?: unknown };\n\t\t\t\tsession?: { id?: unknown };\n\t\t\t} | null;\n\t\t\tif (typeof identity?.user?.id === 'string') {\n\t\t\t\tidentifyUser({\n\t\t\t\t\tid: identity.user.id,\n\t\t\t\t\t...(typeof identity.session?.id === 'string'\n\t\t\t\t\t\t? { sessionId: identity.session.id }\n\t\t\t\t\t\t: {}),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn session;\n\t\t},\n\t};\n}\n\n/** `auth.getSession()` was called on a surface that names no authenticator. */\nexport class NoAuthenticator extends Error {\n\tconstructor(readonly surface: string | undefined) {\n\t\tsuper(\n\t\t\t`auth.getSession() needs an authenticator, and ${\n\t\t\t\tsurface ? `the surface '${surface}'` : 'this endpoint'\n\t\t\t} declares none: declare one on the surface with .auth(construct).`,\n\t\t);\n\t\tthis.name = 'NoAuthenticator';\n\t}\n}\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport type { RateLimitConfig } from '@geekmidas/rate-limit';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n\tInferStandardSchemaInput,\n} from '@geekmidas/schema';\nimport {\n\tconvertSchemaWithComponents,\n\tconvertStandardSchemaToJsonSchema,\n} from '@geekmidas/schema/conversion';\nimport {\n\tbuildOpenApiSchema,\n\ttype ComponentCollector,\n\ttype OpenApiSchemaOptions,\n} from '@geekmidas/schema/openapi';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { OpenAPIV3_1 } from 'openapi-types';\nimport { ConstructType } from '../Construct';\nimport type { Authenticator } from '../construct-interface';\nimport { Function, type FunctionHandler } from '../functions';\nimport type { TopicEvent } from '../publisher';\nimport type { EndpointTelemetry } from '../telemetry';\nimport type { HttpMethod, LowerHttpMethod, RemoveUndefined } from '../types';\nimport type { Authorizer } from './Authorizer';\nimport type { ActorExtractor, MappedAudit } from './audit';\nimport type { RlsConfig } from './rls';\nimport { type SessionAuth, sessionAuth } from './sessionAuth';\n\n/**\n * Represents an HTTP endpoint that can handle requests with type-safe input/output validation,\n * dependency injection, session management, and authorization.\n *\n * @template TRoute - The route path string with parameter placeholders (e.g., '/users/:id')\n * @template TMethod - The HTTP method (GET, POST, PUT, DELETE, PATCH)\n * @template TInput - The input schema definition for body, query, and path parameters\n * @template OutSchema - The output schema for response validation\n * @template TServices - Array of service dependencies to inject\n * @template TLogger - The logger instance type\n * @template TSession - The session data type\n *\n * @extends Function - Base function construct for handler execution\n *\n * @example\n * ```typescript\n * const endpoint = new Endpoint({\n * route: '/users/:id',\n * method: 'GET',\n * input: { params: userIdSchema },\n * output: userSchema,\n * fn: async ({ params }) => getUserById(params.id)\n * });\n * ```\n */\nexport class Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends Function<\n\tTInput,\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tTAuditStorage,\n\tTAuditStorageServiceName,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tTAuditAction,\n\tFunctionHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>\n> {\n\toperationId?: string;\n\t/** The route path pattern with parameter placeholders */\n\troute: TRoute;\n\t/** The HTTP method for this endpoint */\n\tmethod: TMethod;\n\t/**\n\t * The surface that serves it, when it was built from one.\n\t *\n\t * Carries the env parser the adaptors need, so a generated handler needs no\n\t * import written for it — and the surface's id, so the build attributes the\n\t * route to the API that serves it rather than inferring it by exclusion.\n\t */\n\tsurface: EndpointSurface;\n\t/** Optional description for OpenAPI documentation */\n\tdescription?: string;\n\t/** Optional tags for OpenAPI documentation */\n\ttags?: string[];\n\t/** The HTTP status code to return (default: 200) */\n\tpublic readonly status: EndpointStatus;\n\t/**\n\t * Response content type for this endpoint. Defaults to `'application/json'`.\n\t * Non-JSON types cause adaptors to emit the body as-is with the declared\n\t * Content-Type header instead of JSON-serializing.\n\t */\n\tpublic readonly responseType: string;\n\n\t/**\n\t * This route's telemetry — `.telemetry({ ignore, attributes })` — read by\n\t * the build, which hands it to the request middleware.\n\t */\n\tpublic telemetry?: EndpointTelemetry;\n\t/** Default headers to apply to all responses */\n\tpublic readonly defaultHeaders: Record<string, string> = {};\n\t/** Function to extract session data from the request context */\n\tpublic getSession: SessionFn<TServices, TLogger, TSession, TDatabase> = () =>\n\t\t({}) as TSession;\n\t/**\n\t * Whether a session callback was given — `.session()` on the factory it was\n\t * built from. A generated handler reads the session only when it is, so\n\t * an endpoint with a session and no authorizer must say so: it used to be\n\t * handed `undefined` in a production build and its session in `gkm dev`.\n\t */\n\tpublic readonly hasSession: boolean = false;\n\t/** Function to determine if the request is authorized */\n\tpublic authorize: AuthorizeFn<\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTInput,\n\t\tTDatabase\n\t> = () => true;\n\t/** Optional rate limiting configuration */\n\tpublic rateLimit?: RateLimitConfig;\n\t/** Optional authorizer for this endpoint */\n\tpublic authorizer?: Authorizer;\n\t/** Optional actor extractor for audit records */\n\tpublic actorExtractor?: ActorExtractor<TServices, TSession, TLogger>;\n\t/** Declarative audit definitions */\n\tpublic audits: MappedAudit<TAuditAction, OutSchema>[] = [];\n\t/** Database service for this endpoint */\n\tpublic declare databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\t/** RLS configuration for this endpoint */\n\tpublic rlsConfig?: RlsConfig<TServices, TSession, TLogger>;\n\t/** Whether to bypass RLS for this endpoint */\n\tpublic rlsBypass?: boolean;\n\t/** The endpoint handler function */\n\tprivate endpointFn!: EndpointHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTSession,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>;\n\n\t/**\n\t * Builds a complete OpenAPI 3.1 schema from an array of endpoints.\n\t *\n\t * @param endpoints - Array of endpoint instances to document\n\t * @param options - Optional configuration for OpenAPI generation\n\t * @returns OpenAPI 3.1 specification object\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = await Endpoint.buildOpenApiSchema([\n\t * getUserEndpoint,\n\t * createUserEndpoint\n\t * ], {\n\t * title: 'User API',\n\t * version: '1.0.0'\n\t * });\n\t * ```\n\t */\n\tstatic async buildOpenApiSchema(\n\t\tendpoints: Endpoint<any, any, any, any, any, any>[],\n\t\toptions?: OpenApiSchemaOptions,\n\t) {\n\t\treturn buildOpenApiSchema(endpoints, options);\n\t}\n\n\t/**\n\t * Gets the full path including HTTP method and route.\n\t * @returns Formatted string like 'GET /users/{id}'\n\t */\n\tget fullPath() {\n\t\treturn `${this.method} ${this._path}` as const;\n\t}\n\n\t/**\n\t * Parses and validates input data for a specific input type (body, query, params).\n\t *\n\t * @param input - The raw input data to validate\n\t * @param key - The input type key ('body', 'query', or 'params')\n\t * @returns The validated input data for the specified key\n\t * @throws {UnprocessableEntityError} When validation fails\n\t */\n\tasync parseInput<K extends keyof TInput>(\n\t\tinput: unknown,\n\t\tkey: K,\n\t): Promise<InferComposableStandardSchema<TInput[K]>> {\n\t\tconst schema = this.input?.[key];\n\t\treturn Endpoint.parseSchema(schema as StandardSchemaV1, input) as Promise<\n\t\t\tInferComposableStandardSchema<TInput[K]>\n\t\t>;\n\t}\n\n\t/**\n\t * Parses and validates the request body against the body schema.\n\t *\n\t * @param body - The raw request body to validate\n\t * @returns The validated body data\n\t * @throws {UnprocessableEntityError} When body validation fails\n\t */\n\tasync parseBody(body: unknown): Promise<InferStandardSchema<TInput['body']>> {\n\t\treturn this.parseInput(body, 'body') as Promise<\n\t\t\tInferStandardSchema<TInput['body']>\n\t\t>;\n\t}\n\n\tstatic isSuccessStatus(status: number): boolean {\n\t\treturn status >= 200 && status < 300;\n\t}\n\n\t/**\n\t * Whether `status` sends the client elsewhere. A redirect has no body, so\n\t * its response is not checked against the output schema, and what is\n\t * derived from the output — declared events and audits — is not sent.\n\t */\n\tstatic isRedirectStatus(status: number | undefined): boolean {\n\t\treturn status !== undefined && status >= 300 && status < 400;\n\t}\n\n\t/**\n\t * Creates a case-insensitive header lookup function from a headers object.\n\t *\n\t * @param headers - Object containing header key-value pairs\n\t * @returns Function to retrieve header values by case-insensitive key, or all headers\n\t *\n\t * @example\n\t * ```typescript\n\t * const headerFn = Endpoint.createHeaders({ 'Content-Type': 'application/json' });\n\t * headerFn('content-type'); // Returns 'application/json'\n\t * headerFn(); // Returns { 'content-type': 'application/json' }\n\t * ```\n\t */\n\tstatic createHeaders(headers: Record<string, string>): HeaderFn {\n\t\tconst headerMap = new Map<string, string>();\n\t\tfor (const [k, v] of Object.entries(headers)) {\n\t\t\tconst key = k.toLowerCase();\n\t\t\theaderMap.set(key, v);\n\t\t}\n\n\t\tfunction get(): Record<string, string>;\n\t\tfunction get(key: string): string | undefined;\n\t\tfunction get(key?: string): string | undefined | Record<string, string> {\n\t\t\tif (key === undefined) {\n\t\t\t\t// Return all headers as plain object\n\t\t\t\treturn Object.fromEntries(headerMap.entries());\n\t\t\t}\n\t\t\treturn headerMap.get(key.toLowerCase());\n\t\t}\n\n\t\treturn get;\n\t}\n\n\t/**\n\t * Parses cookie string and creates a cookie lookup function.\n\t *\n\t * @param cookieHeader - The Cookie header value\n\t * @returns Function to retrieve cookie values by name, or all cookies\n\t *\n\t * @example\n\t * ```typescript\n\t * const cookieFn = Endpoint.createCookies('session=abc123; theme=dark');\n\t * cookieFn('session'); // Returns 'abc123'\n\t * cookieFn(); // Returns { session: 'abc123', theme: 'dark' }\n\t * ```\n\t */\n\tstatic createCookies(cookieHeader: string | undefined): CookieFn {\n\t\tconst cookieMap = new Map<string, string>();\n\n\t\tif (cookieHeader) {\n\t\t\t// Parse cookie string: \"name1=value1; name2=value2\"\n\t\t\tconst cookies = cookieHeader.split(';');\n\t\t\tfor (const cookie of cookies) {\n\t\t\t\tconst [name, ...valueParts] = cookie.trim().split('=');\n\t\t\t\tif (name) {\n\t\t\t\t\tconst value = valueParts.join('='); // Handle values with = in them\n\t\t\t\t\tcookieMap.set(name, decodeURIComponent(value));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction get(): Record<string, string>;\n\t\tfunction get(name: string): string | undefined;\n\t\tfunction get(name?: string): string | undefined | Record<string, string> {\n\t\t\tif (name === undefined) {\n\t\t\t\t// Return all cookies as plain object\n\t\t\t\treturn Object.fromEntries(cookieMap.entries());\n\t\t\t}\n\t\t\treturn cookieMap.get(name);\n\t\t}\n\n\t\treturn get;\n\t}\n\n\t/**\n\t * Formats a cookie as a Set-Cookie header string.\n\t *\n\t * @param name - Cookie name\n\t * @param value - Cookie value\n\t * @param options - Cookie options (httpOnly, secure, sameSite, etc.)\n\t * @returns Formatted Set-Cookie header string\n\t *\n\t * @example\n\t * ```typescript\n\t * const header = Endpoint.formatCookieHeader('session', 'abc123', {\n\t * httpOnly: true,\n\t * secure: true,\n\t * sameSite: 'strict',\n\t * maxAge: 3600\n\t * });\n\t * // Returns: \"session=abc123; Max-Age=3600; HttpOnly; Secure; SameSite=Strict\"\n\t * ```\n\t */\n\tstatic formatCookieHeader(\n\t\tname: string,\n\t\tvalue: string,\n\t\toptions?: CookieOptions,\n\t): string {\n\t\tlet cookie = `${name}=${value}`;\n\n\t\tif (options) {\n\t\t\tif (options.domain) cookie += `; Domain=${options.domain}`;\n\t\t\tif (options.path) cookie += `; Path=${options.path}`;\n\t\t\tif (options.expires)\n\t\t\t\tcookie += `; Expires=${options.expires.toUTCString()}`;\n\t\t\tif (options.maxAge !== undefined) cookie += `; Max-Age=${options.maxAge}`;\n\t\t\tif (options.httpOnly) cookie += '; HttpOnly';\n\t\t\tif (options.secure) cookie += '; Secure';\n\t\t\tif (options.sameSite) {\n\t\t\t\tcookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;\n\t\t\t}\n\t\t}\n\n\t\treturn cookie;\n\t}\n\n\t/**\n\t * Extracts and refines input data from the endpoint context.\n\t *\n\t * @param ctx - The endpoint execution context\n\t * @returns Object containing only the input data (body, query, params)\n\t * @internal\n\t */\n\trefineInput(\n\t\tctx: EndpointContext<TInput, TServices, TLogger, TSession>,\n\t): InferComposableStandardSchema<TInput> {\n\t\tconst input: Record<string, unknown> = {};\n\t\tfor (const key of ['body', 'query', 'params'] as const) {\n\t\t\tif (key in ctx) {\n\t\t\t\tinput[key] = (ctx as Record<string, unknown>)[key];\n\t\t\t}\n\t\t}\n\n\t\treturn input as InferComposableStandardSchema<TInput>;\n\t}\n\n\thandler = (\n\t\tctx: EndpointContext<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTAuditStorage\n\t\t>,\n\t\tresponse: ResponseBuilder,\n\t): OutSchema extends StandardSchemaV1\n\t\t? // Handler produces the output schema's INPUT type (the schema\n\t\t\t// may coerce it on the way out — see EndpointHandler).\n\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t\t| Promise<\n\t\t\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t\t >\n\t\t:\n\t\t\t\t| any\n\t\t\t\t| ResponseWithMetadata<any>\n\t\t\t\t| Promise<any>\n\t\t\t\t| Promise<ResponseWithMetadata<any>> => {\n\t\t// Apply default headers to response builder\n\t\tfor (const [key, value] of Object.entries(this.defaultHeaders)) {\n\t\t\tresponse.header(key, value);\n\t\t}\n\n\t\t// Build context object, conditionally including auditor and db\n\t\tconst handlerCtx = {\n\t\t\t...this.refineInput(ctx),\n\t\t\tservices: ctx.services,\n\t\t\tlogger: ctx.logger,\n\t\t\theader: ctx.header,\n\t\t\tcookie: ctx.cookie,\n\t\t\tsession: ctx.session,\n\t\t\t// These are conditionally present based on configuration\n\t\t\t...('auditor' in ctx && { auditor: ctx.auditor }),\n\t\t\t...('db' in ctx && { db: ctx.db }),\n\t\t} as EndpointContext<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTAuditStorage\n\t\t>;\n\n\t\treturn this.endpointFn(handlerCtx, response);\n\t};\n\n\t/**\n\t * Type guard to check if an object is an Endpoint instance.\n\t *\n\t * @param obj - The object to check\n\t * @returns True if the object is an Endpoint\n\t */\n\tstatic isEndpoint(obj: any): obj is Endpoint<any, any, any, any> {\n\t\treturn Boolean(\n\t\t\tobj &&\n\t\t\t\t(obj as Function).__IS_FUNCTION__ === true &&\n\t\t\t\tobj.type === ConstructType.Endpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Helper to check if response has metadata\n\t */\n\tstatic hasMetadata<T>(\n\t\tresponse: T | ResponseWithMetadata<T>,\n\t): response is ResponseWithMetadata<T> {\n\t\treturn (\n\t\t\tresponse !== null &&\n\t\t\ttypeof response === 'object' &&\n\t\t\t'data' in response &&\n\t\t\t'metadata' in response\n\t\t);\n\t}\n\n\t/**\n\t * Converts Express-style route params to OpenAPI format.\n\t * @returns Route with ':param' converted to '{param}'\n\t * @internal\n\t */\n\tget _path() {\n\t\treturn this.route.replace(/:(\\w+)/g, '{$1}') as ConvertRouteParams<TRoute>;\n\t}\n\n\t/**\n\t * Generates OpenAPI 3.1 schema for this endpoint.\n\t *\n\t * @returns OpenAPI route definition with operation details\n\t */\n\tasync toOpenApi3Route(\n\t\tcomponentCollector?: ComponentCollector,\n\t): Promise<EndpointOpenApiSchema<TRoute, TMethod>> {\n\t\t// The status the handler answers with — `.status(201)` is documented as\n\t\t// 201, not as the 200 every endpoint used to claim.\n\t\tconst status = String(this.status);\n\t\tconst operation: OpenAPIV3_1.OperationObject = {\n\t\t\toperationId: this.operationId,\n\t\t\t...(this.description && { description: this.description }),\n\t\t\t...(this.tags && this.tags.length > 0 && { tags: this.tags }),\n\t\t\tresponses: {\n\t\t\t\t[status]: {\n\t\t\t\t\tdescription: 'Successful response',\n\t\t\t\t} as OpenAPIV3_1.ResponseObject,\n\t\t\t},\n\t\t};\n\n\t\t// What protects it. Without this every endpoint read as public in the\n\t\t// document, including the ones an authorizer guards.\n\t\tconst scheme = this.authorizer?.securityScheme;\n\t\tif (this.authorizer && scheme && componentCollector) {\n\t\t\tcomponentCollector.addSecurityScheme(\n\t\t\t\tthis.authorizer.name,\n\t\t\t\tscheme as OpenAPIV3_1.SecuritySchemeObject,\n\t\t\t);\n\t\t\toperation.security = [{ [this.authorizer.name]: [] }];\n\t\t}\n\n\t\t// Add response schema\n\t\tif (this.outputSchema) {\n\t\t\tconst responseSchema = await convertSchemaWithComponents(\n\t\t\t\tthis.outputSchema,\n\t\t\t\tcomponentCollector,\n\t\t\t);\n\t\t\tif (responseSchema) {\n\t\t\t\t(operation.responses![status] as OpenAPIV3_1.ResponseObject).content = {\n\t\t\t\t\t[this.responseType]: { schema: responseSchema },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Separate path and query parameters\n\t\tconst pathParameters: OpenAPIV3_1.ParameterObject[] = [];\n\t\tconst queryParameters: OpenAPIV3_1.ParameterObject[] = [];\n\n\t\t// Since the EndpointBuilder doesn't have body/search/params methods yet,\n\t\t// and the input is a composite type, we need to check if input exists\n\t\t// and has the expected shape\n\t\tif (this.input && typeof this.input === 'object') {\n\t\t\t// Add request body for methods that support it\n\t\t\tif (\n\t\t\t\t['POST', 'PUT', 'PATCH'].includes(this.method) &&\n\t\t\t\t'body' in this.input &&\n\t\t\t\tthis.input.body\n\t\t\t) {\n\t\t\t\tconst bodySchema = await convertSchemaWithComponents(\n\t\t\t\t\tthis.input.body as StandardSchemaV1,\n\t\t\t\t\tcomponentCollector,\n\t\t\t\t);\n\t\t\t\tif (bodySchema) {\n\t\t\t\t\toperation.requestBody = {\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t'application/json': {\n\t\t\t\t\t\t\t\tschema: bodySchema,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add path parameters\n\t\t\tif ('params' in this.input && this.input.params) {\n\t\t\t\tconst paramsSchema = await convertStandardSchemaToJsonSchema(\n\t\t\t\t\tthis.input.params as StandardSchemaV1,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tparamsSchema &&\n\t\t\t\t\tparamsSchema.type === 'object' &&\n\t\t\t\t\tparamsSchema.properties\n\t\t\t\t) {\n\t\t\t\t\tfor (const [name, schema] of Object.entries(\n\t\t\t\t\t\tparamsSchema.properties,\n\t\t\t\t\t)) {\n\t\t\t\t\t\tpathParameters.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tin: 'path',\n\t\t\t\t\t\t\trequired: paramsSchema.required?.includes(name) ?? true,\n\t\t\t\t\t\t\tschema: schema as any,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add query parameters\n\t\t\tif ('query' in this.input && this.input.query) {\n\t\t\t\tconst querySchema = await convertStandardSchemaToJsonSchema(\n\t\t\t\t\tthis.input.query,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tquerySchema &&\n\t\t\t\t\tquerySchema.type === 'object' &&\n\t\t\t\t\tquerySchema.properties\n\t\t\t\t) {\n\t\t\t\t\tfor (const [name, schema] of Object.entries(querySchema.properties)) {\n\t\t\t\t\t\tqueryParameters.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tin: 'query',\n\t\t\t\t\t\t\trequired: querySchema.required?.includes(name) ?? false,\n\t\t\t\t\t\t\tschema: schema as any,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Only add query parameters to the operation\n\t\tif (queryParameters.length > 0) {\n\t\t\toperation.parameters = queryParameters;\n\t\t}\n\n\t\t// Build the route object with path parameters at the route level\n\t\tconst routeObject: any = {};\n\t\tif (pathParameters.length > 0) {\n\t\t\trouteObject.parameters = pathParameters;\n\t\t}\n\t\trouteObject[this.method.toLowerCase()] = operation;\n\n\t\treturn {\n\t\t\t[this._path]: routeObject,\n\t\t} as EndpointOpenApiSchema<TRoute, TMethod>;\n\t}\n\n\t/**\n\t * Creates a new Endpoint instance.\n\t *\n\t * @param options - Configuration options for the endpoint\n\t * @param options.fn - The handler function to execute\n\t * @param options.method - HTTP method\n\t * @param options.route - Route path with parameter placeholders\n\t * @param options.description - Optional description for documentation\n\t * @param options.input - Input schemas for validation\n\t * @param options.logger - Logger instance\n\t * @param options.output - Output schema for response validation\n\t * @param options.services - Service dependencies\n\t * @param options.timeout - Execution timeout in milliseconds\n\t * @param options.getSession - Session extraction function\n\t * @param options.authorize - Authorization check function\n\t * @param options.status - Success HTTP status code (default: 200)\n\t * @param options.authorizer - Optional authorizer configuration\n\t */\n\tconstructor({\n\t\tfn,\n\t\tmethod,\n\t\troute,\n\t\tdescription,\n\t\ttags,\n\t\tinput,\n\t\tlogger,\n\t\toutput: outputSchema,\n\t\tservices,\n\t\tconstructs,\n\t\ttimeout,\n\t\tmemorySize,\n\t\tgetSession,\n\t\tauthorize,\n\t\trateLimit,\n\t\tstatus = SuccessStatus.OK,\n\t\tevents,\n\t\tauthorizer,\n\t\tsurface,\n\t\tauditorStorageService,\n\t\tactorExtractor,\n\t\taudits,\n\t\tdatabaseService,\n\t\trlsConfig,\n\t\trlsBypass,\n\t\tresponseType,\n\t\ttelemetry,\n\t}: EndpointOptions<\n\t\tTRoute,\n\t\tTMethod,\n\t\tTInput,\n\t\tOutSchema,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tOutSchema,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t>) {\n\t\tsuper(\n\t\t\tfn as unknown as FunctionHandler<TInput, TServices, TLogger, OutSchema>,\n\t\t\ttimeout,\n\t\t\tConstructType.Endpoint,\n\t\t\tinput,\n\t\t\toutputSchema,\n\t\t\tservices,\n\t\t\tlogger,\n\t\t\tevents,\n\t\t\tmemorySize,\n\t\t\tauditorStorageService,\n\t\t\tundefined, // databaseService — assigned below, after the RLS wiring\n\t\t\tconstructs,\n\t\t);\n\n\t\tthis.route = route;\n\t\tthis.method = method;\n\t\tthis.description = description;\n\t\tthis.tags = tags;\n\t\tthis.status = status;\n\t\tthis.responseType = responseType ?? 'application/json';\n\t\tthis.endpointFn = fn;\n\t\tif (telemetry) this.telemetry = telemetry;\n\n\t\tif (getSession) {\n\t\t\tthis.hasSession = true;\n\t\t\t// `auth` is added here, once, rather than by each adaptor: every\n\t\t\t// adaptor calls this, so every one of them hands a session callback\n\t\t\t// the surface's authenticator bound to the request it is handling.\n\t\t\tthis.getSession = (ctx) =>\n\t\t\t\tgetSession({ ...ctx, auth: sessionAuth(surface, ctx.header) });\n\t\t}\n\n\t\tif (authorize) {\n\t\t\tthis.authorize = authorize;\n\t\t}\n\n\t\tif (rateLimit) {\n\t\t\tthis.rateLimit = rateLimit;\n\t\t}\n\n\t\tif (authorizer) {\n\t\t\tthis.authorizer = authorizer;\n\t\t}\n\n\t\tthis.surface = surface;\n\n\t\tif (actorExtractor) {\n\t\t\tthis.actorExtractor = actorExtractor;\n\t\t}\n\n\t\tif (audits) {\n\t\t\tthis.audits = audits;\n\t\t}\n\n\t\tif (databaseService) {\n\t\t\tthis.databaseService = databaseService;\n\t\t}\n\n\t\tif (rlsConfig) {\n\t\t\tthis.rlsConfig = rlsConfig;\n\t\t}\n\n\t\tif (rlsBypass) {\n\t\t\tthis.rlsBypass = rlsBypass;\n\t\t}\n\t}\n}\n\n/**\n * Defines the input schema structure for an endpoint.\n *\n * @template TBody - Schema for request body validation\n * @template TSearch - Schema for query string validation\n * @template TParams - Schema for URL path parameters validation\n *\n * @example\n * ```typescript\n * type UserInput = EndpointInput<\n * typeof createUserBodySchema,\n * typeof userQuerySchema,\n * typeof userParamsSchema\n * >;\n * ```\n */\nexport type EndpointInput<\n\tTBody extends StandardSchemaV1 | undefined = undefined,\n\tTSearch extends StandardSchemaV1 | undefined = undefined,\n\tTParams extends StandardSchemaV1 | undefined = undefined,\n> = RemoveUndefined<{\n\tbody: TBody;\n\tsearch: TSearch;\n\tparams: TParams;\n}>;\n\n/**\n * The surface an endpoint was built from.\n *\n * An endpoint created with `api.get('/users')` knows which API serves it, and\n * through that, the two things every handler needs and no handler should have\n * to name: the process's logger and its environment parser.\n *\n * This is what makes the generated code smaller than the thing it replaced. A\n * handler used to be wired by an import the build wrote for it —\n * `import { envParser } from '../../config/env'` — which meant the parser had\n * to be named in config as a module path, because a generator can print a\n * specifier and cannot print an object. Built from the surface, the endpoint\n * already carries it, so there is nothing to name and nothing to print.\n *\n * `id` is the surface's construct id, which is how the build attributes a route\n * to the API that serves it rather than guessing by exclusion.\n */\nexport interface EndpointSurface {\n\t/** The surface's construct id — `Api`, `Auth`. */\n\tid: string;\n\t/**\n\t * The environment parser every handler on this surface runs with.\n\t *\n\t * A value the surface holds, never a place to do work: constructs are\n\t * imported by discovery before any URL exists, so a parser that reads a\n\t * file or throws on a missing variable would do it at build time.\n\t */\n\tenvParser: EnvironmentParser<{}>;\n\t/**\n\t * What authenticates requests to this surface — the construct named in\n\t * `RestApi.auth()`, which session callbacks read from as `auth`.\n\t */\n\tauth?: Authenticator;\n}\n\n/**\n * Configuration options for creating an Endpoint instance.\n *\n * @template TRoute - The route path string\n * @template TMethod - The HTTP method\n * @template TInput - Input schema definitions\n * @template TOutput - Output schema definition\n * @template TServices - Service dependencies array\n * @template TLogger - Logger type\n * @template TSession - Session data type\n */\nexport interface EndpointOptions<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutput extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\t/** The route path with parameter placeholders */\n\troute: TRoute;\n\t/** The HTTP method for this endpoint */\n\tmethod: TMethod;\n\t/** The handler function that implements the endpoint logic */\n\tfn: EndpointHandler<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTOutput,\n\t\tTSession,\n\t\tTDatabase,\n\t\tTAuditStorage,\n\t\tTAuditAction\n\t>;\n\t/** Optional authorization check function */\n\tauthorize:\n\t\t| AuthorizeFn<TServices, TLogger, TSession, TInput, TDatabase>\n\t\t| undefined;\n\t/** Optional description for documentation */\n\tdescription: string | undefined;\n\t/** Optional tags for OpenAPI documentation */\n\ttags?: string[];\n\t/** Optional execution timeout in milliseconds */\n\ttimeout: number | undefined;\n\t/** Optional memory size in MB for serverless deployments */\n\tmemorySize: number | undefined;\n\t/** Input validation schemas */\n\tinput: TInput | undefined;\n\t/** Output validation schema */\n\toutput: TOutput | undefined;\n\t/** Service dependencies to inject */\n\tservices: TServices;\n\t/**\n\t * The ids of the constructs `.dependsOn()` named.\n\t *\n\t * The same edges as `services`, kept in the form the manifest records rather\n\t * than the form the handler runs with.\n\t */\n\tconstructs?: string[];\n\t/** Logger instance */\n\tlogger: TLogger;\n\t/** Optional session extraction function */\n\tgetSession: SessionFn<TServices, TLogger, TSession, TDatabase> | undefined;\n\t/** Optional rate limiting configuration */\n\trateLimit?: RateLimitConfig;\n\t/** Success HTTP status code */\n\tstatus: EndpointStatus | undefined;\n\t/** What it publishes once its handler succeeds, each to its own topic. */\n\tevents?: TopicEvent[];\n\t/** Optional authorizer configuration */\n\tauthorizer?: Authorizer;\n\t/** The surface this endpoint was built from. Every endpoint has one. */\n\tsurface: EndpointSurface;\n\t/**\n\t * Auditor storage service for persisting audit records from this endpoint\n\t */\n\tauditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>;\n\t/** Optional actor extractor function for audit records */\n\tactorExtractor?: ActorExtractor<TServices, TSession, TLogger>;\n\t/** Declarative audit definitions */\n\taudits?: MappedAudit<TAuditAction, OutSchema>[];\n\t/** Database service for this endpoint */\n\tdatabaseService?: Service<TDatabaseServiceName, TDatabase>;\n\t/** RLS configuration for this endpoint */\n\trlsConfig?: RlsConfig<TServices, TSession, TLogger>;\n\t/** Whether to bypass RLS for this endpoint */\n\trlsBypass?: boolean;\n\t/**\n\t * Response content type (e.g. `'application/json'`, `'text/html'`).\n\t * Defaults to `'application/json'` when omitted.\n\t */\n\tresponseType?: string;\n\t/** This route's telemetry — `.telemetry({ ignore, attributes })`. */\n\ttelemetry?: EndpointTelemetry;\n}\n\n/**\n * Defines the possible input schema types for an endpoint.\n * Each property represents a different part of the HTTP request.\n */\nexport type EndpointSchemas = Partial<{\n\t/** Schema for URL path parameters (e.g., /users/:id) */\n\tparams: StandardSchemaV1;\n\t/** Schema for query string parameters */\n\tquery: StandardSchemaV1;\n\t/** Schema for request body (POST, PUT, PATCH) */\n\tbody: StandardSchemaV1;\n}>;\n\nexport type AuthorizeContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTDatabase = undefined,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\tsession: TSession;\n} & InferComposableStandardSchema<TInput> &\n\tSessionDatabaseContext<TDatabase>;\n/**\n * Function type for endpoint authorization checks.\n *\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type\n *\n * @param ctx - Context containing services, logger, headers, and session\n * @returns Boolean indicating if the request is authorized\n *\n * @example\n * ```typescript\n * const authorize: AuthorizeFn = ({ session }) => {\n * return session.userId !== undefined;\n * };\n * ```\n */\nexport type AuthorizeFn<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: AuthorizeContext<TServices, TLogger, TSession, TInput, TDatabase>,\n) => Promise<boolean> | boolean;\n\n/**\n * Base session context without database\n */\ntype BaseSessionContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\t/**\n\t * The surface's authenticator — the construct named in `.auth()` — bound to\n\t * this request: `await auth.getSession()` is this request's session, or\n\t * `null`.\n\t */\n\tauth: SessionAuth;\n};\n\n/**\n * Conditional database context for session - only present when database service is configured\n */\ntype SessionDatabaseContext<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Database instance for session extraction.\n\t\t\t * Available when a database service is configured via `.database()`.\n\t\t\t * Useful for looking up user data from the database based on auth tokens.\n\t\t\t */\n\t\t\tdb: TDatabase;\n\t\t};\n\nexport type SessionContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = BaseSessionContext<TServices, TLogger> & SessionDatabaseContext<TDatabase>;\n/**\n * Function type for extracting session data from a request.\n *\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type to extract\n * @template TDatabase - Database type (when database service is configured)\n *\n * @param ctx - Context containing services, logger, headers, and optionally database\n * @returns The extracted session data\n *\n * @example\n * ```typescript\n * // Without database\n * const getSession: SessionFn<Services, Logger, UserSession> = async ({ header, services }) => {\n * const token = header('authorization');\n * return await services.auth.verifyToken(token);\n * };\n *\n * // With database\n * const getSession: SessionFn<Services, Logger, UserSession, Database> = async ({ header, db }) => {\n * const token = header('authorization');\n * const user = await db.selectFrom('users').where('token', '=', token).executeTakeFirst();\n * return { userId: user?.id };\n * };\n * ```\n */\nexport type SessionFn<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTDatabase = undefined,\n> = (\n\tctx: SessionContext<TServices, TLogger, TDatabase>,\n) => Promise<TSession> | TSession;\n\n/**\n * Utility type that converts Express-style route parameters to OpenAPI format.\n * Transforms ':param' syntax to '{param}' syntax.\n *\n * @template T - The route string to convert\n *\n * @example\n * ```typescript\n * type Route1 = ConvertRouteParams<'/users/:id'>; // '/users/{id}'\n * type Route2 = ConvertRouteParams<'/users/:userId/posts/:postId'>; // '/users/{userId}/posts/{postId}'\n * ```\n */\nexport type ConvertRouteParams<T extends string> =\n\tT extends `${infer Start}:${infer Param}/${infer Rest}`\n\t\t? `${Start}{${Param}}/${ConvertRouteParams<Rest>}`\n\t\t: T extends `${infer Start}:${infer Param}`\n\t\t\t? `${Start}{${Param}}`\n\t\t\t: T;\n\n/**\n * Type representing the OpenAPI schema structure for an endpoint.\n *\n * @template TRoute - The route path\n * @template TMethod - The HTTP method\n *\n * @example\n * ```typescript\n * type Schema = EndpointOpenApiSchema<'/users/:id', 'GET'>;\n * // Results in: { '/users/{id}': { get: OperationObject, parameters?: ParameterObject[] } }\n * ```\n */\nexport type EndpointOpenApiSchema<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n> = {\n\t[key in ConvertRouteParams<TRoute>]: {\n\t\t[key in LowerHttpMethod<TMethod>]: OpenAPIV3_1.OperationObject<{}>;\n\t} & {\n\t\tparameters?: OpenAPIV3_1.ParameterObject[];\n\t};\n};\n\nexport type SingleHeaderFn = (key: string) => string | undefined;\nexport type MultiHeaderFn = () => EndpointHeaders;\n/**\n * Type representing HTTP headers as a Map.\n */\nexport type EndpointHeaders = Map<string, string>;\n\n/**\n * Function type for retrieving HTTP header values.\n * Supports two calling patterns:\n * - `header(key)` - Get a single header value (case-insensitive)\n * - `header()` - Get all headers as a plain object\n *\n * @example\n * ```typescript\n * // Get single header\n * const contentType = header('content-type');\n *\n * // Get all headers\n * const allHeaders = header();\n * // { 'content-type': 'application/json', 'host': 'example.com', ... }\n * ```\n */\nexport interface HeaderFn {\n\t(): Record<string, string>;\n\t(key: string): string | undefined;\n}\n\n/**\n * Function type for retrieving cookie values.\n * Supports two calling patterns:\n * - `cookie(name)` - Get a single cookie value\n * - `cookie()` - Get all cookies as a plain object\n *\n * @example\n * ```typescript\n * // Get single cookie\n * const sessionId = cookie('session');\n *\n * // Get all cookies\n * const allCookies = cookie();\n * // { session: 'abc123', theme: 'dark', ... }\n * ```\n */\nexport interface CookieFn {\n\t(): Record<string, string>;\n\t(name: string): string | undefined;\n}\n\n/**\n * Cookie options matching standard Set-Cookie attributes\n */\nexport interface CookieOptions {\n\tdomain?: string;\n\tpath?: string;\n\texpires?: Date;\n\tmaxAge?: number;\n\thttpOnly?: boolean;\n\tsecure?: boolean;\n\tsameSite?: 'strict' | 'lax' | 'none';\n}\n\n/**\n * Response metadata that handlers can set\n */\nexport interface ResponseMetadata {\n\theaders?: Record<string, string>;\n\tcookies?: Map<string, { value: string; options?: CookieOptions }>;\n\tstatus?: EndpointStatus;\n}\n\n/**\n * Return type for handlers that want to set response metadata\n */\nexport interface ResponseWithMetadata<T> {\n\tdata: T;\n\tmetadata: ResponseMetadata;\n}\n\n/**\n * Response builder for fluent API in handlers\n */\nexport class ResponseBuilder {\n\tprivate metadata: ResponseMetadata = {\n\t\theaders: {},\n\t\tcookies: new Map(),\n\t};\n\n\theader(key: string, value: string): this {\n\t\tthis.metadata.headers![key] = value;\n\t\treturn this;\n\t}\n\n\tcookie(name: string, value: string, options?: CookieOptions): this {\n\t\tthis.metadata.cookies?.set(name, { value, options });\n\t\treturn this;\n\t}\n\n\tdeleteCookie(\n\t\tname: string,\n\t\toptions?: Pick<CookieOptions, 'domain' | 'path'>,\n\t): this {\n\t\tthis.metadata.cookies?.set(name, {\n\t\t\tvalue: '',\n\t\t\toptions: { ...options, maxAge: 0, expires: new Date(0) },\n\t\t});\n\t\treturn this;\n\t}\n\n\tstatus(code: EndpointStatus): this {\n\t\tthis.metadata.status = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Send the client to `url` — `Location` and a 3xx, with no body. 303 by\n\t * default: after a form post, the browser follows it with a GET, so a\n\t * reload does not post the form again.\n\t *\n\t * A redirect is not checked against the endpoint's `.output()` schema, so\n\t * an endpoint that renders a page can redirect instead.\n\t *\n\t * @example\n\t * ```typescript\n\t * return response.cookie('session', token).redirect('/dashboard');\n\t * ```\n\t */\n\tredirect(\n\t\turl: string,\n\t\tstatus: RedirectStatus = RedirectStatus.SeeOther,\n\t): ResponseWithMetadata<never> {\n\t\tthis.metadata.headers!.location = url;\n\t\tthis.metadata.status = status;\n\t\treturn { data: undefined as never, metadata: this.metadata };\n\t}\n\n\tsend<T>(data: T): ResponseWithMetadata<T> {\n\t\treturn { data, metadata: this.metadata };\n\t}\n\n\tgetMetadata(): ResponseMetadata {\n\t\treturn this.metadata;\n\t}\n}\n\n/**\n * Base context properties that are always available\n */\ntype BaseEndpointContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = {\n\t/** Injected service instances */\n\tservices: ServiceRecord<TServices>;\n\t/** Logger instance for this request */\n\tlogger: TLogger;\n\t/** Function to retrieve request headers */\n\theader: HeaderFn;\n\t/** Function to retrieve request cookies */\n\tcookie: CookieFn;\n\t/** Session data extracted by getSession */\n\tsession: TSession;\n};\n\n/**\n * Conditional auditor context - only present when audit storage is configured\n */\ntype AuditorContext<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTAuditStorage = undefined,\n> = TAuditStorage extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Auditor instance for recording audit events.\n\t\t\t * Only present when audit storage is configured on the endpoint.\n\t\t\t * When a transactional database is used for audit storage,\n\t\t\t * the auditor is pre-configured with the transaction context.\n\t\t\t */\n\t\t\tauditor: Auditor<TAuditAction>;\n\t\t};\n\n/**\n * Conditional database context - only present when database service is configured\n */\ntype DatabaseContext<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/**\n\t\t\t * Database instance for this request.\n\t\t\t * When audit storage is configured and uses the same database,\n\t\t\t * this will be the transaction for ACID compliance.\n\t\t\t * Otherwise, it's the raw database connection.\n\t\t\t */\n\t\t\tdb: TDatabase;\n\t\t};\n\n/**\n * The execution context provided to endpoint handlers.\n * Contains all parsed input data, services, logger, headers, cookies, and session.\n *\n * @template Input - The input schemas (body, query, params)\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template TSession - Session data type\n * @template TAuditAction - Audit action types (when auditor is configured)\n * @template TDatabase - Database type (when database service is configured)\n * @template TAuditStorage - Audit storage type (determines if auditor is present)\n */\nexport type EndpointContext<\n\tInput extends EndpointSchemas | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTAuditStorage = undefined,\n> = BaseEndpointContext<TServices, TLogger, TSession> &\n\tInferComposableStandardSchema<Input> &\n\tAuditorContext<TAuditAction, TAuditStorage> &\n\tDatabaseContext<TDatabase>;\n\n/**\n * Handler function type for endpoint implementations.\n *\n * @template TInput - Input schemas for validation\n * @template TServices - Available service dependencies\n * @template TLogger - Logger type\n * @template OutSchema - Output schema for response validation\n * @template TSession - Session data type\n *\n * @param ctx - The endpoint execution context\n * @param response - Response builder for setting cookies, headers, and status\n * @returns The response data (validated if OutSchema is provided) or ResponseWithMetadata\n *\n * @example\n * ```typescript\n * // Simple response\n * const handler: EndpointHandler<Input, [UserService], Logger, UserSchema> =\n * async ({ params, services }) => {\n * return await services.users.findById(params.id);\n * };\n *\n * // With response builder\n * const handler: EndpointHandler<Input, [UserService], Logger, UserSchema> =\n * async ({ params, services }, response) => {\n * const user = await services.users.findById(params.id);\n * return response.header('X-User-Id', user.id).send(user);\n * };\n * ```\n */\nexport type EndpointHandler<\n\tTInput extends EndpointSchemas | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTSession = unknown,\n\tTDatabase = undefined,\n\tTAuditStorage = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = (\n\tctx: EndpointContext<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTAuditStorage\n\t>,\n\tresponse: ResponseBuilder,\n) => OutSchema extends StandardSchemaV1\n\t? // The handler must produce the schema's INPUT type — the output\n\t\t// schema is allowed to coerce it (e.g. a `Date` → ISO `string`),\n\t\t// so the handler may return the looser input while consumers\n\t\t// (EndpointOutput / the generated client) still see the parsed\n\t\t// output type.\n\t\t// A handler that sometimes redirects returns either from one\n\t\t// promise, so the promise may hold either.\n\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t| Promise<\n\t\t\t\t\t| InferStandardSchemaInput<OutSchema>\n\t\t\t\t\t| ResponseWithMetadata<InferStandardSchemaInput<OutSchema>>\n\t\t\t >\n\t:\n\t\t\t| unknown\n\t\t\t| ResponseWithMetadata<unknown>\n\t\t\t| Promise<unknown>\n\t\t\t| Promise<ResponseWithMetadata<unknown>>;\n\n/**\n * HTTP success status codes that can be returned by endpoints.\n */\nexport enum SuccessStatus {\n\t/** Standard response for successful HTTP requests */\n\tOK = 200,\n\t/** Request has been fulfilled and resulted in a new resource being created */\n\tCreated = 201,\n\t/** Request has been accepted for processing, but processing is not complete */\n\tAccepted = 202,\n\t/** Server successfully processed the request but is not returning any content */\n\tNoContent = 204,\n\t/** Server successfully processed the request and is not returning any content, client should reset the document view */\n\tResetContent = 205,\n\t/** Server is delivering only part of the resource due to a range header */\n\tPartialContent = 206,\n}\n\n/**\n * HTTP redirect status codes an endpoint can answer with —\n * `response.redirect(url, status)`, or `.status()` with a `Location` header.\n */\nexport enum RedirectStatus {\n\t/** The resource has moved for good; a POST may become a GET */\n\tMovedPermanently = 301,\n\t/** The resource is elsewhere for now; a POST may become a GET */\n\tFound = 302,\n\t/** See the resource elsewhere, with a GET — the answer to a form post */\n\tSeeOther = 303,\n\t/** The resource is elsewhere for now; the method and body are kept */\n\tTemporaryRedirect = 307,\n\t/** The resource has moved for good; the method and body are kept */\n\tPermanentRedirect = 308,\n}\n\n/** A status an endpoint answers with when its handler succeeds. */\nexport type EndpointStatus = SuccessStatus | RedirectStatus;\n\nexport type EndpointOutput<T> =\n\tT extends Endpoint<any, any, any, infer OutSchema, any, any, any, any>\n\t\t? InferStandardSchema<OutSchema>\n\t\t: never;\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAM,kBAAkB;CAAC;CAAU;CAAiB;AAAiB;;AAGrE,SAAgB,YACf,SACA,QACc;CACd,OAAO,EACN,MAAM,aAAa;EAClB,MAAM,gBAAgB,SAAS;EAC/B,IAAI,CAAC,WAAW,CAAC,eAChB,MAAM,IAAI,gBAAgB,SAAS,EAAE;EAGtC,MAAM,UAAU,IAAI,QAAQ;EAC5B,KAAK,MAAM,QAAQ,iBAAiB;GACnC,MAAM,QAAQ,OAAO,IAAI;GACzB,IAAI,OAAO,QAAQ,IAAI,MAAM,KAAK;EACnC;EAEA,MAAM,UAAW,MAAM,cAAc,OACpC,SACA,QAAQ,SACT;EAMA,MAAM,WAAW;EAIjB,IAAI,OAAO,UAAU,MAAM,OAAO,UACjC,aAAa;GACZ,I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