@geekmidas/constructs 10.0.0-alpha.146 → 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 (163) 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.cjs +222 -33
  152. package/dist/websocket-api.cjs.map +1 -1
  153. package/dist/websocket-api.d.cts +120 -7
  154. package/dist/websocket-api.d.cts.map +1 -1
  155. package/dist/websocket-api.d.mts +120 -7
  156. package/dist/websocket-api.d.mts.map +1 -1
  157. package/dist/websocket-api.mjs +219 -34
  158. package/dist/websocket-api.mjs.map +1 -1
  159. package/dist/worker.d.cts +8 -8
  160. package/dist/worker.d.mts +8 -8
  161. package/package.json +31 -31
  162. package/dist/Endpoint-BcUorcBa.cjs.map +0 -1
  163. 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"],"mappings":"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"}
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":"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"}
@@ -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 };
@@ -7,6 +7,172 @@ let _geekmidas_logger_console = require("@geekmidas/logger/console");
7
7
  let node_crypto = require("node:crypto");
8
8
  let _geekmidas_services = require("@geekmidas/services");
9
9
  let _geekmidas_errors = require("@geekmidas/errors");
10
+ let _geekmidas_schema_conversion = require("@geekmidas/schema/conversion");
11
+ //#region src/websocket/frame.ts
12
+ /**
13
+ * The shape a surface's frames take on the wire.
14
+ *
15
+ * By default a frame is `{ "action": …, "id"?: …, "data": … }` — API
16
+ * Gateway's shape. A surface that names a discriminator — `frame: {
17
+ * discriminator: 'type' }` — sends and reads flat frames instead: the action
18
+ * under that key, and the data's own fields beside it.
19
+ *
20
+ * ```json
21
+ * {"type":"chat.message.created","chatId":"c1","message":{…}}
22
+ * ```
23
+ *
24
+ * A flat frame has no `id` of its own: every field but the discriminator is
25
+ * the data, so a reply is paired by its action, not an echoed id.
26
+ */
27
+ /** A declared message whose schema does not describe an object. */
28
+ var WebSocketMessageNotAnObject = class extends Error {
29
+ surface;
30
+ action;
31
+ discriminator;
32
+ constructor(surface, action, discriminator) {
33
+ super(`${surface} sends flat frames, keyed by '${discriminator}', so each message's fields sit beside it — but '${action}' is not an object schema. Declare it as an object (z.object({ … })), or drop \`frame\` to send { action, data }.`);
34
+ this.surface = surface;
35
+ this.action = action;
36
+ this.discriminator = discriminator;
37
+ this.name = "WebSocketMessageNotAnObject";
38
+ }
39
+ };
40
+ /** A declared message whose schema has a field named the discriminator. */
41
+ var WebSocketMessageDeclaresDiscriminator = class extends Error {
42
+ surface;
43
+ action;
44
+ discriminator;
45
+ constructor(surface, action, discriminator) {
46
+ super(`${surface}'s '${action}' message declares a '${discriminator}' field, which is where its flat frames keep the action. Rename the field, or give \`frame.discriminator\` a key no message uses.`);
47
+ this.surface = surface;
48
+ this.action = action;
49
+ this.discriminator = discriminator;
50
+ this.name = "WebSocketMessageDeclaresDiscriminator";
51
+ }
52
+ };
53
+ /** Data sent in a flat frame that is not an object. */
54
+ var WebSocketDataNotAnObject = class extends Error {
55
+ surface;
56
+ action;
57
+ discriminator;
58
+ constructor(surface, action, discriminator) {
59
+ super(`${surface} sends flat frames, keyed by '${discriminator}', and '${action}''s data is not an object, so it has no fields to put beside it. Send an object. Nothing was sent.`);
60
+ this.surface = surface;
61
+ this.action = action;
62
+ this.discriminator = discriminator;
63
+ this.name = "WebSocketDataNotAnObject";
64
+ }
65
+ };
66
+ /** Data sent in a flat frame that carries the discriminator itself. */
67
+ var WebSocketDataHasDiscriminator = class extends Error {
68
+ surface;
69
+ action;
70
+ discriminator;
71
+ constructor(surface, action, discriminator) {
72
+ super(`'${action}''s data on ${surface} has a '${discriminator}' field, which is where its flat frames keep the action. Rename the field. Nothing was sent.`);
73
+ this.surface = surface;
74
+ this.action = action;
75
+ this.discriminator = discriminator;
76
+ this.name = "WebSocketDataHasDiscriminator";
77
+ }
78
+ };
79
+ /** How one surface writes and reads its frames. */
80
+ var FrameShape = class {
81
+ surface;
82
+ discriminator;
83
+ constructor(surface, discriminator) {
84
+ this.surface = surface;
85
+ this.discriminator = discriminator;
86
+ }
87
+ /** The key an inbound frame names its action under. */
88
+ get key() {
89
+ return this.discriminator ?? "action";
90
+ }
91
+ /**
92
+ * The frame for `action`'s `data`, serialised.
93
+ *
94
+ * @throws {WebSocketDataNotAnObject}, {WebSocketDataHasDiscriminator} for
95
+ * a flat frame whose data cannot sit beside the discriminator.
96
+ */
97
+ encode(action, data, id) {
98
+ const { discriminator } = this;
99
+ if (discriminator === void 0) return JSON.stringify({
100
+ action,
101
+ ...id !== void 0 ? { id } : {},
102
+ data
103
+ });
104
+ if (!isRecord(data)) throw new WebSocketDataNotAnObject(this.surface, action, discriminator);
105
+ if (Object.hasOwn(data, discriminator)) throw new WebSocketDataHasDiscriminator(this.surface, action, discriminator);
106
+ return JSON.stringify({
107
+ [discriminator]: action,
108
+ ...data
109
+ });
110
+ }
111
+ /** A parsed frame's action, id and data — `undefined` when it names none. */
112
+ decode(frame) {
113
+ if (!isRecord(frame)) return void 0;
114
+ const { discriminator } = this;
115
+ if (discriminator === void 0) {
116
+ if (typeof frame.action !== "string") return void 0;
117
+ return {
118
+ action: frame.action,
119
+ ...isId(frame.id) ? { id: frame.id } : {},
120
+ data: frame.data
121
+ };
122
+ }
123
+ const { [discriminator]: action, ...data } = frame;
124
+ if (typeof action !== "string") return void 0;
125
+ return {
126
+ action,
127
+ data
128
+ };
129
+ }
130
+ /** The id a frame that names no action carried, to echo on its error. */
131
+ idOf(frame) {
132
+ if (this.discriminator !== void 0 || !isRecord(frame)) return void 0;
133
+ return isId(frame.id) ? frame.id : void 0;
134
+ }
135
+ /**
136
+ * Refuse a declared message a flat frame cannot carry: one that is not an
137
+ * object, or that has a field named the discriminator.
138
+ *
139
+ * @throws {WebSocketMessageNotAnObject}, {WebSocketMessageDeclaresDiscriminator}
140
+ */
141
+ check(messages) {
142
+ const { discriminator } = this;
143
+ if (discriminator === void 0) return;
144
+ for (const [action, schema] of Object.entries(messages)) {
145
+ const shape = objectShape((0, _geekmidas_schema_conversion.toJsonSchema)(schema));
146
+ if (!shape) throw new WebSocketMessageNotAnObject(this.surface, action, discriminator);
147
+ if (shape.has(discriminator)) throw new WebSocketMessageDeclaresDiscriminator(this.surface, action, discriminator);
148
+ }
149
+ }
150
+ };
151
+ /**
152
+ * The fields a JSON Schema's object declares, or `undefined` when it is not
153
+ * an object. A union or intersection is one when each of its members is.
154
+ */
155
+ function objectShape(schema) {
156
+ if (!isRecord(schema)) return void 0;
157
+ const members = schema.anyOf ?? schema.oneOf ?? schema.allOf;
158
+ if (Array.isArray(members) && members.length > 0) {
159
+ const fields = /* @__PURE__ */ new Set();
160
+ for (const member of members) {
161
+ const shape = objectShape(member);
162
+ if (!shape) return void 0;
163
+ for (const field of shape) fields.add(field);
164
+ }
165
+ return fields;
166
+ }
167
+ if (schema.type !== "object") return void 0;
168
+ return new Set(isRecord(schema.properties) ? Object.keys(schema.properties) : []);
169
+ }
170
+ function isRecord(value) {
171
+ return typeof value === "object" && value !== null && !Array.isArray(value);
172
+ }
173
+ function isId(value) {
174
+ return typeof value === "string" || typeof value === "number";
175
+ }
10
176
  /** A connection string names no transport this package knows. */
11
177
  var UnsupportedWebSocketTransport = class extends Error {
12
178
  connectionString;
@@ -158,7 +324,9 @@ var InvalidWebSocketMessage = class extends Error {
158
324
  * How anything reaches a socket — `services.realtime` in an endpoint, and
159
325
  * `sockets` in a route of the surface itself.
160
326
  *
161
- * A message is `{ action, data }`, the shape a client's frames arrive in.
327
+ * A message is `{ action, data }`, the shape a client's frames arrive in —
328
+ * or, where the surface names a `frame.discriminator`, flat: `{ [key]: action,
329
+ * ...data }`.
162
330
  * Where the surface declares its messages, `action` is one of them and
163
331
  * `data` is typed and checked by its schema before anything is sent; where it
164
332
  * declares none, any action and any JSON value go. A message is serialised
@@ -170,10 +338,12 @@ var WebSocketPublisher = class {
170
338
  transport;
171
339
  local;
172
340
  declared;
173
- constructor(transport, local, declared) {
341
+ frame;
342
+ constructor(transport, local, declared, frame = new FrameShape(declared?.surface ?? "")) {
174
343
  this.transport = transport;
175
344
  this.local = local;
176
345
  this.declared = declared;
346
+ this.frame = frame;
177
347
  }
178
348
  /** Send `action`'s message to each connection. */
179
349
  async send(ids, action, data) {
@@ -206,22 +376,17 @@ var WebSocketPublisher = class {
206
376
  * The frame, checked by the action's schema where the surface declares
207
377
  * its messages.
208
378
  *
209
- * @throws {UnknownWebSocketMessage}, {InvalidWebSocketMessage}
379
+ * @throws {UnknownWebSocketMessage}, {InvalidWebSocketMessage}, and for a
380
+ * flat frame {WebSocketDataNotAnObject}, {WebSocketDataHasDiscriminator}
210
381
  */
211
382
  async payload(action, data) {
212
- if (!this.declared) return JSON.stringify({
213
- action,
214
- data
215
- });
383
+ if (!this.declared) return this.frame.encode(action, data);
216
384
  const { surface, messages } = this.declared;
217
385
  const schema = messages[action];
218
386
  if (!schema) throw new UnknownWebSocketMessage(surface, action, Object.keys(messages));
219
387
  const result = await schema["~standard"].validate(data);
220
388
  if (result.issues) throw new InvalidWebSocketMessage(surface, action, result.issues);
221
- return JSON.stringify({
222
- action,
223
- data: result.value
224
- });
389
+ return this.frame.encode(action, result.value);
225
390
  }
226
391
  /** One delivery per process that holds any of `ids`. */
227
392
  async each(ids, delivery) {
@@ -340,6 +505,8 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
340
505
  routes = /* @__PURE__ */ new Map();
341
506
  lifecycle = {};
342
507
  heartbeat;
508
+ frame;
509
+ trusted;
343
510
  next = 0;
344
511
  closing = false;
345
512
  constructor(wss, options) {
@@ -355,13 +522,16 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
355
522
  this.lifecycle[route.kind] = route;
356
523
  }
357
524
  }
525
+ this.frame = new FrameShape(options.surface, options.frame?.discriminator);
526
+ if (options.messages) this.frame.check(options.messages);
527
+ this.trusted = [...options.trustedOrigins, ...ownOrigins(options.url)];
358
528
  this.publisher = new WebSocketPublisher(options.transport, {
359
529
  instance: this.instance,
360
530
  deliver: (delivery) => this.deliver(delivery)
361
531
  }, options.messages ? {
362
532
  surface: options.surface,
363
533
  messages: options.messages
364
- } : void 0);
534
+ } : void 0, this.frame);
365
535
  this.heartbeat = setInterval(() => this.beat(), options.heartbeatMs ?? 3e4);
366
536
  this.heartbeat.unref();
367
537
  }
@@ -391,7 +561,7 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
391
561
  async upgrade(request, socket, head) {
392
562
  if (this.closing) return refuse(socket, 503, "Service Unavailable");
393
563
  const origin = request.headers.origin;
394
- if (origin && !(0, _geekmidas_manifest.trustsOrigin)(origin, this.options.trustedOrigins)) return refuse(socket, 403, "Forbidden");
564
+ if (origin && !(0, _geekmidas_manifest.trustsOrigin)(origin, this.trusted)) return refuse(socket, 403, "Forbidden");
395
565
  const connectionId = `${this.instance}.${(this.next++).toString(36)}`;
396
566
  const headers = headersOf(request);
397
567
  let data = {};
@@ -453,13 +623,14 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
453
623
  }
454
624
  /** Parse, validate and run one frame. Errors go back as frames, not closes. */
455
625
  async dispatch(held, text) {
456
- let frame;
626
+ let parsed;
457
627
  try {
458
- frame = JSON.parse(text);
628
+ parsed = JSON.parse(text);
459
629
  } catch {
460
630
  return this.error(held, void 0, "Frames are JSON.");
461
631
  }
462
- if (!frame || typeof frame.action !== "string") return this.error(held, frame?.id, "A frame names its `action`.");
632
+ const frame = this.frame.decode(parsed);
633
+ if (!frame) return this.error(held, this.frame.idOf(parsed), `A frame names its \`${this.frame.key}\`.`);
463
634
  const route = this.routes.get(frame.action) ?? this.routes.get("$default");
464
635
  if (!route) return this.error(held, frame.id, `No route answers '${frame.action}'.`);
465
636
  let body = frame.data;
@@ -475,11 +646,7 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
475
646
  body,
476
647
  reply: (message) => this.write(held, JSON.stringify(message))
477
648
  }));
478
- if (returned !== void 0) this.write(held, JSON.stringify({
479
- action: frame.action,
480
- ...frame.id !== void 0 ? { id: frame.id } : {},
481
- data: returned
482
- }));
649
+ if (returned !== void 0) this.write(held, this.frame.encode(frame.action, returned, frame.id));
483
650
  } catch (error) {
484
651
  if (error instanceof _geekmidas_errors.HttpError) return this.error(held, frame.id, error.message);
485
652
  this.options.logger.error({
@@ -511,14 +678,10 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
511
678
  });
512
679
  }
513
680
  error(held, id, message, issues) {
514
- this.write(held, JSON.stringify({
515
- action: "$error",
516
- ...id !== void 0 ? { id } : {},
517
- data: {
518
- message,
519
- ...issues ? { issues } : {}
520
- }
521
- }));
681
+ this.write(held, this.frame.encode("$error", {
682
+ message,
683
+ ...issues ? { issues } : {}
684
+ }, id));
522
685
  }
523
686
  /** Write, unless the socket has stopped reading and its queue is full. */
524
687
  write(held, payload) {
@@ -584,6 +747,16 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
584
747
  this.wss.close();
585
748
  }
586
749
  };
750
+ /**
751
+ * The origins a client of the surface's own address sends: the `https://`
752
+ * one a native socket derives from `wss://`, and the address's own.
753
+ */
754
+ function ownOrigins(url) {
755
+ if (!url || !URL.canParse(url)) return [];
756
+ const own = new URL(url);
757
+ const web = new URL(url.replace(/^ws(s?):/i, "http$1:"));
758
+ return [.../* @__PURE__ */ new Set([`${own.protocol}//${own.host}`, web.origin])];
759
+ }
587
760
  function headersOf(request) {
588
761
  const headers = new Headers();
589
762
  for (const [name, value] of Object.entries(request.headers)) {
@@ -617,6 +790,11 @@ var WebSocketApi = class WebSocketApi {
617
790
  envParser;
618
791
  telemetry;
619
792
  /**
793
+ * The shape its frames take — `{ action, data }`, or flat under
794
+ * `discriminator`. What a client of the surface decodes by.
795
+ */
796
+ frame;
797
+ /**
620
798
  * The surface as a dependency: `services.<id>` is its publisher, so an
621
799
  * endpoint sends to a socket the way a route beside it does.
622
800
  */
@@ -628,6 +806,9 @@ var WebSocketApi = class WebSocketApi {
628
806
  this.id = canonical;
629
807
  const replicas = config.replicas ?? 1;
630
808
  if (!Number.isInteger(replicas) || replicas < 1) throw new InvalidReplicaCount(canonical, replicas);
809
+ const frame = new FrameShape(canonical, config.frame?.discriminator);
810
+ if (config.messages) frame.check(config.messages);
811
+ this.frame = config.frame ? { discriminator: config.frame.discriminator } : {};
631
812
  this.keys = {
632
813
  url: (0, _geekmidas_manifest.provideKey)(canonical, "url"),
633
814
  trustedOrigins: (0, _geekmidas_manifest.provideKey)(canonical, "trustedOrigins"),
@@ -648,7 +829,7 @@ var WebSocketApi = class WebSocketApi {
648
829
  const { connectionString } = envParser.create((get) => ({ connectionString: get(envVar).string() })).parse();
649
830
  const transport = await transportFromConnectionString(connectionString, channel);
650
831
  require_shutdown.onShutdown(() => transport.close());
651
- return new WebSocketPublisher(transport, void 0, declared);
832
+ return new WebSocketPublisher(transport, void 0, declared, frame);
652
833
  }
653
834
  };
654
835
  }
@@ -661,7 +842,8 @@ var WebSocketApi = class WebSocketApi {
661
842
  return new WebSocketRouteBuilder("disconnect", "$disconnect", { id: this.id });
662
843
  }
663
844
  /**
664
- * The handler for frames whose `action` is `action`. `$default` answers
845
+ * The handler for frames whose `action` — or, for flat frames, whose
846
+ * discriminator — is `action`. `$default` answers
665
847
  * any action nothing else does.
666
848
  */
667
849
  route(action) {
@@ -682,9 +864,10 @@ var WebSocketApi = class WebSocketApi {
682
864
  async server(options) {
683
865
  const { Hono } = await import("hono");
684
866
  const routes = (options.modules ?? []).flatMap((module) => Object.values(module).filter(WebSocketRoute.isRoute));
685
- const { connectionString, origins } = options.envParser.create((get) => ({
867
+ const { connectionString, origins, url } = options.envParser.create((get) => ({
686
868
  connectionString: get(this.keys.publisherConnectionString).string().default(`memory://${channelOf(this.id)}`),
687
- origins: get(this.keys.trustedOrigins).string().default("").transform((value) => value.split(",").map((origin) => origin.trim()).filter(Boolean))
869
+ origins: get(this.keys.trustedOrigins).string().default("").transform((value) => value.split(",").map((origin) => origin.trim()).filter(Boolean)),
870
+ url: get(this.keys.url).string().optional()
688
871
  })).parse();
689
872
  const server = await WebSocketSurfaceServer.start({
690
873
  surface: this.id,
@@ -693,6 +876,8 @@ var WebSocketApi = class WebSocketApi {
693
876
  envParser: options.envParser,
694
877
  logger: this.logger,
695
878
  trustedOrigins: origins,
879
+ ...url ? { url } : {},
880
+ ...this.config.frame ? { frame: this.config.frame } : {},
696
881
  ...this.declared ? { messages: this.declared.messages } : {},
697
882
  ...this.authenticator ? { authenticator: this.authenticator } : {},
698
883
  ...this.config.heartbeat ? { heartbeatMs: this.config.heartbeat * 1e3 } : {},
@@ -753,6 +938,10 @@ exports.RedisTransport = RedisTransport;
753
938
  exports.UnknownWebSocketMessage = UnknownWebSocketMessage;
754
939
  exports.UnsupportedWebSocketTransport = UnsupportedWebSocketTransport;
755
940
  exports.WebSocketApi = WebSocketApi;
941
+ exports.WebSocketDataHasDiscriminator = WebSocketDataHasDiscriminator;
942
+ exports.WebSocketDataNotAnObject = WebSocketDataNotAnObject;
943
+ exports.WebSocketMessageDeclaresDiscriminator = WebSocketMessageDeclaresDiscriminator;
944
+ exports.WebSocketMessageNotAnObject = WebSocketMessageNotAnObject;
756
945
  exports.WebSocketPublisher = WebSocketPublisher;
757
946
  exports.WebSocketRoute = WebSocketRoute;
758
947
  exports.WebSocketRouteBuilder = WebSocketRouteBuilder;