@geekmidas/constructs 10.0.0-alpha.15 → 10.0.0-alpha.150

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 (454) hide show
  1. package/README.md +222 -158
  2. package/dist/Construct-127M7yrl.d.cts +231 -0
  3. package/dist/Construct-127M7yrl.d.cts.map +1 -0
  4. package/dist/{Construct-BeYVu_QF.mjs → Construct-CGuc_Ijk.mjs} +8 -9
  5. package/dist/Construct-CGuc_Ijk.mjs.map +1 -0
  6. package/dist/{Construct-DqdlARxq.cjs → Construct-DorKS0Ua.cjs} +8 -9
  7. package/dist/Construct-DorKS0Ua.cjs.map +1 -0
  8. package/dist/Construct-DySlwh8o.d.mts +231 -0
  9. package/dist/Construct-DySlwh8o.d.mts.map +1 -0
  10. package/dist/{Cron-DKqnnTdH.d.cts → Cron-D8mB_cPX.d.mts} +16 -9
  11. package/dist/Cron-D8mB_cPX.d.mts.map +1 -0
  12. package/dist/{Cron-SyqS5oWJ.d.mts → Cron-D_sfaMGz.d.cts} +16 -9
  13. package/dist/Cron-D_sfaMGz.d.cts.map +1 -0
  14. package/dist/{CronBuilder-D_0HNBTr.mjs → CronBuilder-BJ5LoadF.mjs} +28 -11
  15. package/dist/CronBuilder-BJ5LoadF.mjs.map +1 -0
  16. package/dist/{CronBuilder-BdnI6lxF.cjs → CronBuilder-B_NSP-Y5.cjs} +27 -10
  17. package/dist/CronBuilder-B_NSP-Y5.cjs.map +1 -0
  18. package/dist/CronBuilder-C91MVLSr.d.cts +47 -0
  19. package/dist/CronBuilder-C91MVLSr.d.cts.map +1 -0
  20. package/dist/CronBuilder-Cmajva3g.d.mts +47 -0
  21. package/dist/CronBuilder-Cmajva3g.d.mts.map +1 -0
  22. package/dist/Endpoint-52z1P0Ue.cjs +581 -0
  23. package/dist/Endpoint-52z1P0Ue.cjs.map +1 -0
  24. package/dist/{Endpoint-DuT4TEEq.d.mts → Endpoint-BbHh3Qoc.d.mts} +124 -43
  25. package/dist/Endpoint-BbHh3Qoc.d.mts.map +1 -0
  26. package/dist/{Endpoint-C6yyHpRS.d.cts → Endpoint-YYwjqtS1.d.cts} +122 -41
  27. package/dist/Endpoint-YYwjqtS1.d.cts.map +1 -0
  28. package/dist/Endpoint-sUOU7uLx.mjs +552 -0
  29. package/dist/Endpoint-sUOU7uLx.mjs.map +1 -0
  30. package/dist/{EndpointFactory-Bm3aKRdV.mjs → EndpointFactory-Bzi9Sl7r.mjs} +269 -53
  31. package/dist/EndpointFactory-Bzi9Sl7r.mjs.map +1 -0
  32. package/dist/{EndpointFactory-CLvWuHyt.cjs → EndpointFactory-Cf_Cs1ym.cjs} +309 -51
  33. package/dist/EndpointFactory-Cf_Cs1ym.cjs.map +1 -0
  34. package/dist/{index-BPSZ_Lp_.d.cts → EndpointFactory-Hh1r6J_C.d.cts} +187 -104
  35. package/dist/EndpointFactory-Hh1r6J_C.d.cts.map +1 -0
  36. package/dist/{index-BoZ-iisU.d.mts → EndpointFactory-qcLzi4f-.d.mts} +188 -105
  37. package/dist/EndpointFactory-qcLzi4f-.d.mts.map +1 -0
  38. package/dist/Function-BIEsY0Hm.d.cts +76 -0
  39. package/dist/Function-BIEsY0Hm.d.cts.map +1 -0
  40. package/dist/Function-DfMzTGS4.d.mts +76 -0
  41. package/dist/Function-DfMzTGS4.d.mts.map +1 -0
  42. package/dist/{HonoEndpointAdaptor-92zavCsV.cjs → HonoEndpointAdaptor-BXBdb2Bt.cjs} +79 -31
  43. package/dist/HonoEndpointAdaptor-BXBdb2Bt.cjs.map +1 -0
  44. package/dist/{HonoEndpointAdaptor-yYaU7jVJ.mjs → HonoEndpointAdaptor-DR3j7S35.mjs} +76 -28
  45. package/dist/HonoEndpointAdaptor-DR3j7S35.mjs.map +1 -0
  46. package/dist/ObjectSubscriberBuilder-Cv8C7yS1.d.mts +129 -0
  47. package/dist/ObjectSubscriberBuilder-Cv8C7yS1.d.mts.map +1 -0
  48. package/dist/ObjectSubscriberBuilder-LWkey_oq.d.cts +129 -0
  49. package/dist/ObjectSubscriberBuilder-LWkey_oq.d.cts.map +1 -0
  50. package/dist/ProcessorBuilder-CwfP-M33.d.mts +216 -0
  51. package/dist/ProcessorBuilder-CwfP-M33.d.mts.map +1 -0
  52. package/dist/ProcessorBuilder-_jdZlbfW.d.cts +216 -0
  53. package/dist/ProcessorBuilder-_jdZlbfW.d.cts.map +1 -0
  54. package/dist/{Queue-D9X6OoON.d.mts → Queue-BnK3UH8r.d.mts} +42 -41
  55. package/dist/Queue-BnK3UH8r.d.mts.map +1 -0
  56. package/dist/{Queue-DYPB2KWL.d.cts → Queue-C4rijiM7.d.cts} +43 -42
  57. package/dist/Queue-C4rijiM7.d.cts.map +1 -0
  58. package/dist/Queue-D4Iaidrs.cjs +109 -0
  59. package/dist/Queue-D4Iaidrs.cjs.map +1 -0
  60. package/dist/Queue-u8w8_HpE.mjs +104 -0
  61. package/dist/Queue-u8w8_HpE.mjs.map +1 -0
  62. package/dist/QueueBuilder-2wP5lEC8.mjs +118 -0
  63. package/dist/QueueBuilder-2wP5lEC8.mjs.map +1 -0
  64. package/dist/QueueBuilder-BxsZ9o5z.cjs +135 -0
  65. package/dist/QueueBuilder-BxsZ9o5z.cjs.map +1 -0
  66. package/dist/QueueBuilder-DmwFtLzQ.d.mts +75 -0
  67. package/dist/QueueBuilder-DmwFtLzQ.d.mts.map +1 -0
  68. package/dist/QueueBuilder-SQli59An.d.cts +75 -0
  69. package/dist/QueueBuilder-SQli59An.d.cts.map +1 -0
  70. package/dist/Subscriber-5rCX1Nph.d.cts +83 -0
  71. package/dist/Subscriber-5rCX1Nph.d.cts.map +1 -0
  72. package/dist/Subscriber-CW_Dl-YR.d.mts +83 -0
  73. package/dist/Subscriber-CW_Dl-YR.d.mts.map +1 -0
  74. package/dist/SubscriberBuilder-BL_GTcwh.mjs +237 -0
  75. package/dist/SubscriberBuilder-BL_GTcwh.mjs.map +1 -0
  76. package/dist/SubscriberBuilder-CWzKwX1p.cjs +260 -0
  77. package/dist/SubscriberBuilder-CWzKwX1p.cjs.map +1 -0
  78. package/dist/Topic-DN2gYJ-p.mjs +99 -0
  79. package/dist/Topic-DN2gYJ-p.mjs.map +1 -0
  80. package/dist/Topic-Dp9Q7Lj2.cjs +104 -0
  81. package/dist/Topic-Dp9Q7Lj2.cjs.map +1 -0
  82. package/dist/adaptors/aws.cjs +134 -160
  83. package/dist/adaptors/aws.cjs.map +1 -1
  84. package/dist/adaptors/aws.d.cts +57 -48
  85. package/dist/adaptors/aws.d.cts.map +1 -1
  86. package/dist/adaptors/aws.d.mts +58 -49
  87. package/dist/adaptors/aws.d.mts.map +1 -1
  88. package/dist/adaptors/aws.mjs +130 -157
  89. package/dist/adaptors/aws.mjs.map +1 -1
  90. package/dist/adaptors/hono.cjs +1 -1
  91. package/dist/adaptors/hono.d.cts +5 -6
  92. package/dist/adaptors/hono.d.cts.map +1 -1
  93. package/dist/adaptors/hono.d.mts +6 -7
  94. package/dist/adaptors/hono.d.mts.map +1 -1
  95. package/dist/adaptors/hono.mjs +1 -1
  96. package/dist/adaptors/testing.cjs +955 -38
  97. package/dist/adaptors/testing.cjs.map +1 -1
  98. package/dist/adaptors/testing.d.cts +437 -39
  99. package/dist/adaptors/testing.d.cts.map +1 -1
  100. package/dist/adaptors/testing.d.mts +436 -38
  101. package/dist/adaptors/testing.d.mts.map +1 -1
  102. package/dist/adaptors/testing.mjs +929 -34
  103. package/dist/adaptors/testing.mjs.map +1 -1
  104. package/dist/auth-BqWz2JxC.d.cts +274 -0
  105. package/dist/auth-BqWz2JxC.d.cts.map +1 -0
  106. package/dist/auth-DnB9H9KL.d.mts +274 -0
  107. package/dist/auth-DnB9H9KL.d.mts.map +1 -0
  108. package/dist/auth.cjs +320 -21
  109. package/dist/auth.cjs.map +1 -1
  110. package/dist/auth.d.cts +2 -104
  111. package/dist/auth.d.mts +2 -104
  112. package/dist/auth.mjs +316 -23
  113. package/dist/auth.mjs.map +1 -1
  114. package/dist/cache-CQjMNPrC.d.cts +44 -0
  115. package/dist/cache-CQjMNPrC.d.cts.map +1 -0
  116. package/dist/cache-e3tfMQ9g.d.mts +44 -0
  117. package/dist/cache-e3tfMQ9g.d.mts.map +1 -0
  118. package/dist/cache.d.cts +2 -43
  119. package/dist/cache.d.mts +2 -43
  120. package/dist/cipher-C1lEFX63.mjs +225 -0
  121. package/dist/cipher-C1lEFX63.mjs.map +1 -0
  122. package/dist/cipher-CVxfwLjk.cjs +332 -0
  123. package/dist/cipher-CVxfwLjk.cjs.map +1 -0
  124. package/dist/cipher-DSDxPRIp.d.cts +106 -0
  125. package/dist/cipher-DSDxPRIp.d.cts.map +1 -0
  126. package/dist/cipher-DSDxPRIp.d.mts +106 -0
  127. package/dist/cipher-DSDxPRIp.d.mts.map +1 -0
  128. package/dist/{construct-interface-DPlxfpoS.d.mts → construct-interface-CSA9VeWM.d.mts} +47 -8
  129. package/dist/construct-interface-CSA9VeWM.d.mts.map +1 -0
  130. package/dist/{construct-interface-DgXTJcOD.d.cts → construct-interface-DugP0E5q.d.cts} +47 -8
  131. package/dist/construct-interface-DugP0E5q.d.cts.map +1 -0
  132. package/dist/construct-interface.cjs +38 -4
  133. package/dist/construct-interface.cjs.map +1 -1
  134. package/dist/construct-interface.d.cts +2 -2
  135. package/dist/construct-interface.d.mts +2 -2
  136. package/dist/construct-interface.mjs +37 -5
  137. package/dist/construct-interface.mjs.map +1 -1
  138. package/dist/credential-DYymbp_7.cjs +257 -0
  139. package/dist/credential-DYymbp_7.cjs.map +1 -0
  140. package/dist/credential-DfSAOOdY.mjs +222 -0
  141. package/dist/credential-DfSAOOdY.mjs.map +1 -0
  142. package/dist/credential.cjs +7 -129
  143. package/dist/credential.d.cts +2 -58
  144. package/dist/credential.d.mts +2 -58
  145. package/dist/credential.mjs +2 -128
  146. package/dist/crons/index.cjs +126 -1
  147. package/dist/crons/index.cjs.map +1 -1
  148. package/dist/crons/index.d.cts +43 -3
  149. package/dist/crons/index.d.cts.map +1 -1
  150. package/dist/crons/index.d.mts +43 -3
  151. package/dist/crons/index.d.mts.map +1 -1
  152. package/dist/crons/index.mjs +125 -2
  153. package/dist/crons/index.mjs.map +1 -1
  154. package/dist/database/kysely.cjs +3 -194
  155. package/dist/database/kysely.d.cts +2 -149
  156. package/dist/database/kysely.d.mts +2 -149
  157. package/dist/database/kysely.mjs +2 -192
  158. package/dist/email.d.cts +1 -1
  159. package/dist/email.d.cts.map +1 -1
  160. package/dist/email.d.mts +2 -2
  161. package/dist/email.d.mts.map +1 -1
  162. package/dist/encryption/kms.cjs +95 -0
  163. package/dist/encryption/kms.cjs.map +1 -0
  164. package/dist/encryption/kms.d.cts +7 -0
  165. package/dist/encryption/kms.d.cts.map +1 -0
  166. package/dist/encryption/kms.d.mts +7 -0
  167. package/dist/encryption/kms.d.mts.map +1 -0
  168. package/dist/encryption/kms.mjs +93 -0
  169. package/dist/encryption/kms.mjs.map +1 -0
  170. package/dist/encryption.cjs +116 -0
  171. package/dist/encryption.cjs.map +1 -0
  172. package/dist/encryption.d.cts +37 -0
  173. package/dist/encryption.d.cts.map +1 -0
  174. package/dist/encryption.d.mts +37 -0
  175. package/dist/encryption.d.mts.map +1 -0
  176. package/dist/encryption.mjs +101 -0
  177. package/dist/encryption.mjs.map +1 -0
  178. package/dist/endpoints/index.cjs +32 -10
  179. package/dist/endpoints/index.d.cts +106 -3
  180. package/dist/endpoints/index.d.cts.map +1 -0
  181. package/dist/endpoints/index.d.mts +106 -3
  182. package/dist/endpoints/index.d.mts.map +1 -0
  183. package/dist/endpoints/index.mjs +6 -4
  184. package/dist/expire-C586zznE.d.cts +38 -0
  185. package/dist/expire-C586zznE.d.cts.map +1 -0
  186. package/dist/expire-C586zznE.d.mts +38 -0
  187. package/dist/expire-C586zznE.d.mts.map +1 -0
  188. package/dist/expire-CieftS01.cjs +67 -0
  189. package/dist/expire-CieftS01.cjs.map +1 -0
  190. package/dist/expire-CpzUAfr9.mjs +50 -0
  191. package/dist/expire-CpzUAfr9.mjs.map +1 -0
  192. package/dist/external-api.cjs +106 -0
  193. package/dist/external-api.cjs.map +1 -0
  194. package/dist/external-api.d.cts +2 -0
  195. package/dist/external-api.d.mts +2 -0
  196. package/dist/external-api.mjs +103 -0
  197. package/dist/external-api.mjs.map +1 -0
  198. package/dist/fake-BqhP8RRQ.d.mts +201 -0
  199. package/dist/fake-BqhP8RRQ.d.mts.map +1 -0
  200. package/dist/fake-DqieDYYA.d.cts +201 -0
  201. package/dist/fake-DqieDYYA.d.cts.map +1 -0
  202. package/dist/file-server.cjs +123 -30
  203. package/dist/file-server.cjs.map +1 -1
  204. package/dist/file-server.d.cts +115 -1
  205. package/dist/file-server.d.cts.map +1 -1
  206. package/dist/file-server.d.mts +115 -1
  207. package/dist/file-server.d.mts.map +1 -1
  208. package/dist/file-server.mjs +122 -32
  209. package/dist/file-server.mjs.map +1 -1
  210. package/dist/functions/index.cjs +1 -1
  211. package/dist/functions/index.d.cts +2 -1
  212. package/dist/functions/index.d.mts +2 -1
  213. package/dist/functions/index.mjs +1 -1
  214. package/dist/{functions-C53GW2eQ.mjs → functions-BvIDQKAA.mjs} +117 -22
  215. package/dist/functions-BvIDQKAA.mjs.map +1 -0
  216. package/dist/{functions-B6qCvfmy.cjs → functions-DLF6-IK8.cjs} +122 -18
  217. package/dist/functions-DLF6-IK8.cjs.map +1 -0
  218. package/dist/inbox-CR3L1fOI.d.cts +195 -0
  219. package/dist/inbox-CR3L1fOI.d.cts.map +1 -0
  220. package/dist/inbox-CjxpLVkH.d.mts +195 -0
  221. package/dist/inbox-CjxpLVkH.d.mts.map +1 -0
  222. package/dist/inbox.cjs +291 -0
  223. package/dist/inbox.cjs.map +1 -0
  224. package/dist/inbox.d.cts +2 -0
  225. package/dist/inbox.d.mts +2 -0
  226. package/dist/inbox.mjs +283 -0
  227. package/dist/inbox.mjs.map +1 -0
  228. package/dist/index-DCkDQkwj.d.mts +115 -0
  229. package/dist/index-DCkDQkwj.d.mts.map +1 -0
  230. package/dist/index-DPTHa6Ud.d.cts +115 -0
  231. package/dist/index-DPTHa6Ud.d.cts.map +1 -0
  232. package/dist/{index-CeEtxDmK.d.cts → index-DdRjYhiJ.d.cts} +42 -2
  233. package/dist/{index-CeEtxDmK.d.cts.map → index-DdRjYhiJ.d.cts.map} +1 -1
  234. package/dist/{index-CeEtxDmK.d.mts → index-DdRjYhiJ.d.mts} +42 -2
  235. package/dist/{index-CeEtxDmK.d.mts.map → index-DdRjYhiJ.d.mts.map} +1 -1
  236. package/dist/index.cjs +4 -1
  237. package/dist/index.d.cts +26 -3
  238. package/dist/index.d.cts.map +1 -0
  239. package/dist/index.d.mts +26 -3
  240. package/dist/index.d.mts.map +1 -0
  241. package/dist/index.mjs +3 -2
  242. package/dist/kysely-CebjCWTl.d.cts +216 -0
  243. package/dist/kysely-CebjCWTl.d.cts.map +1 -0
  244. package/dist/kysely-Cs4uPO8k.mjs +371 -0
  245. package/dist/kysely-Cs4uPO8k.mjs.map +1 -0
  246. package/dist/kysely-CukArHJ0.cjs +384 -0
  247. package/dist/kysely-CukArHJ0.cjs.map +1 -0
  248. package/dist/kysely-DE4kADWD.d.mts +216 -0
  249. package/dist/kysely-DE4kADWD.d.mts.map +1 -0
  250. package/dist/{telemetry-DGcFlVpB.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +2 -2
  251. package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
  252. package/dist/{telemetry-DGcFlVpB.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +2 -2
  253. package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
  254. package/dist/mobile-app.cjs +74 -0
  255. package/dist/mobile-app.cjs.map +1 -0
  256. package/dist/mobile-app.d.cts +73 -0
  257. package/dist/mobile-app.d.cts.map +1 -0
  258. package/dist/mobile-app.d.mts +73 -0
  259. package/dist/mobile-app.d.mts.map +1 -0
  260. package/dist/mobile-app.mjs +73 -0
  261. package/dist/mobile-app.mjs.map +1 -0
  262. package/dist/object-storage.cjs +8 -1
  263. package/dist/object-storage.cjs.map +1 -1
  264. package/dist/object-storage.d.cts +10 -1
  265. package/dist/object-storage.d.cts.map +1 -1
  266. package/dist/object-storage.d.mts +10 -1
  267. package/dist/object-storage.d.mts.map +1 -1
  268. package/dist/object-storage.mjs +7 -2
  269. package/dist/object-storage.mjs.map +1 -1
  270. package/dist/pattern-C1CEcglD.mjs +241 -0
  271. package/dist/pattern-C1CEcglD.mjs.map +1 -0
  272. package/dist/pattern-QFaUIr77.cjs +288 -0
  273. package/dist/pattern-QFaUIr77.cjs.map +1 -0
  274. package/dist/processors/index.cjs +214 -0
  275. package/dist/processors/index.cjs.map +1 -0
  276. package/dist/processors/index.d.cts +78 -0
  277. package/dist/processors/index.d.cts.map +1 -0
  278. package/dist/processors/index.d.mts +78 -0
  279. package/dist/processors/index.d.mts.map +1 -0
  280. package/dist/processors/index.mjs +193 -0
  281. package/dist/processors/index.mjs.map +1 -0
  282. package/dist/queue/index.cjs +5 -192
  283. package/dist/queue/index.d.cts +3 -53
  284. package/dist/queue/index.d.mts +3 -53
  285. package/dist/queue/index.mjs +3 -190
  286. package/dist/random-password.cjs +86 -0
  287. package/dist/random-password.cjs.map +1 -0
  288. package/dist/random-password.d.cts +30 -0
  289. package/dist/random-password.d.cts.map +1 -0
  290. package/dist/random-password.d.mts +30 -0
  291. package/dist/random-password.d.mts.map +1 -0
  292. package/dist/random-password.mjs +84 -0
  293. package/dist/random-password.mjs.map +1 -0
  294. package/dist/{lazyAccessors-BHtcqgz2.mjs → readRequestBody-BTIl3k-D.mjs} +99 -39
  295. package/dist/readRequestBody-BTIl3k-D.mjs.map +1 -0
  296. package/dist/{lazyAccessors-Dx9NLwJZ.cjs → readRequestBody-Dej_L3c4.cjs} +118 -46
  297. package/dist/readRequestBody-Dej_L3c4.cjs.map +1 -0
  298. package/dist/requestLogger-BZcXwdBs.cjs +207 -0
  299. package/dist/requestLogger-BZcXwdBs.cjs.map +1 -0
  300. package/dist/requestLogger-pA4gi3E1.mjs +178 -0
  301. package/dist/requestLogger-pA4gi3E1.mjs.map +1 -0
  302. package/dist/rest-api.cjs +85 -70
  303. package/dist/rest-api.cjs.map +1 -1
  304. package/dist/rest-api.d.cts +77 -59
  305. package/dist/rest-api.d.cts.map +1 -1
  306. package/dist/rest-api.d.mts +77 -59
  307. package/dist/rest-api.d.mts.map +1 -1
  308. package/dist/rest-api.mjs +87 -72
  309. package/dist/rest-api.mjs.map +1 -1
  310. package/dist/runSubscriber-CC_2C9F2.cjs +133 -0
  311. package/dist/runSubscriber-CC_2C9F2.cjs.map +1 -0
  312. package/dist/runSubscriber-DyHWp_Lf.mjs +116 -0
  313. package/dist/runSubscriber-DyHWp_Lf.mjs.map +1 -0
  314. package/dist/shutdown-BMJmAhSt.cjs +38 -0
  315. package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
  316. package/dist/shutdown-C7xa8x9S.mjs +27 -0
  317. package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
  318. package/dist/site.cjs +85 -8
  319. package/dist/site.cjs.map +1 -1
  320. package/dist/site.d.cts +98 -2
  321. package/dist/site.d.cts.map +1 -1
  322. package/dist/site.d.mts +98 -2
  323. package/dist/site.d.mts.map +1 -1
  324. package/dist/site.mjs +84 -11
  325. package/dist/site.mjs.map +1 -1
  326. package/dist/stages-DaTaoQei.d.cts +73 -0
  327. package/dist/stages-DaTaoQei.d.cts.map +1 -0
  328. package/dist/stages-DaTaoQei.d.mts +73 -0
  329. package/dist/stages-DaTaoQei.d.mts.map +1 -0
  330. package/dist/subscribers/index.cjs +134 -1
  331. package/dist/subscribers/index.cjs.map +1 -0
  332. package/dist/subscribers/index.d.cts +74 -3
  333. package/dist/subscribers/index.d.cts.map +1 -0
  334. package/dist/subscribers/index.d.mts +74 -3
  335. package/dist/subscribers/index.d.mts.map +1 -0
  336. package/dist/subscribers/index.mjs +132 -2
  337. package/dist/subscribers/index.mjs.map +1 -0
  338. package/dist/telemetry-C1oqncFY.d.cts +40 -0
  339. package/dist/telemetry-C1oqncFY.d.cts.map +1 -0
  340. package/dist/telemetry-CObow3Dn.d.mts +40 -0
  341. package/dist/telemetry-CObow3Dn.d.mts.map +1 -0
  342. package/dist/telemetry.cjs +56 -0
  343. package/dist/telemetry.cjs.map +1 -0
  344. package/dist/telemetry.d.cts +2 -0
  345. package/dist/telemetry.d.mts +2 -0
  346. package/dist/telemetry.mjs +55 -0
  347. package/dist/telemetry.mjs.map +1 -0
  348. package/dist/topic/index.cjs +2 -134
  349. package/dist/topic/index.d.cts +2 -3
  350. package/dist/topic/index.d.mts +2 -3
  351. package/dist/topic/index.mjs +2 -132
  352. package/dist/tracing-Bbj1uoFJ.mjs +127 -0
  353. package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
  354. package/dist/tracing-C0ooU0V2.cjs +150 -0
  355. package/dist/tracing-C0ooU0V2.cjs.map +1 -0
  356. package/dist/websocket-api.cjs +951 -0
  357. package/dist/websocket-api.cjs.map +1 -0
  358. package/dist/websocket-api.d.cts +556 -0
  359. package/dist/websocket-api.d.cts.map +1 -0
  360. package/dist/websocket-api.d.mts +556 -0
  361. package/dist/websocket-api.d.mts.map +1 -0
  362. package/dist/websocket-api.mjs +933 -0
  363. package/dist/websocket-api.mjs.map +1 -0
  364. package/dist/worker.cjs +174 -32
  365. package/dist/worker.cjs.map +1 -1
  366. package/dist/worker.d.cts +147 -47
  367. package/dist/worker.d.cts.map +1 -1
  368. package/dist/worker.d.mts +147 -47
  369. package/dist/worker.d.mts.map +1 -1
  370. package/dist/worker.mjs +175 -33
  371. package/dist/worker.mjs.map +1 -1
  372. package/package.json +155 -44
  373. package/dist/Construct-BeYVu_QF.mjs.map +0 -1
  374. package/dist/Construct-DfbwIntp.d.cts +0 -115
  375. package/dist/Construct-DfbwIntp.d.cts.map +0 -1
  376. package/dist/Construct-DqdlARxq.cjs.map +0 -1
  377. package/dist/Construct-l5aOn_jv.d.mts +0 -115
  378. package/dist/Construct-l5aOn_jv.d.mts.map +0 -1
  379. package/dist/Cron-DKqnnTdH.d.cts.map +0 -1
  380. package/dist/Cron-SyqS5oWJ.d.mts.map +0 -1
  381. package/dist/CronBuilder-BdnI6lxF.cjs.map +0 -1
  382. package/dist/CronBuilder-CRGnDfTq.d.mts +0 -41
  383. package/dist/CronBuilder-CRGnDfTq.d.mts.map +0 -1
  384. package/dist/CronBuilder-D_0HNBTr.mjs.map +0 -1
  385. package/dist/CronBuilder-Df1q9PNy.d.cts +0 -41
  386. package/dist/CronBuilder-Df1q9PNy.d.cts.map +0 -1
  387. package/dist/Endpoint-BpZHtJ2W.cjs +0 -1689
  388. package/dist/Endpoint-BpZHtJ2W.cjs.map +0 -1
  389. package/dist/Endpoint-C6yyHpRS.d.cts.map +0 -1
  390. package/dist/Endpoint-DuT4TEEq.d.mts.map +0 -1
  391. package/dist/Endpoint-ONsly_dq.mjs +0 -1671
  392. package/dist/Endpoint-ONsly_dq.mjs.map +0 -1
  393. package/dist/EndpointFactory-Bm3aKRdV.mjs.map +0 -1
  394. package/dist/EndpointFactory-CLvWuHyt.cjs.map +0 -1
  395. package/dist/HonoEndpointAdaptor-92zavCsV.cjs.map +0 -1
  396. package/dist/HonoEndpointAdaptor-yYaU7jVJ.mjs.map +0 -1
  397. package/dist/Queue-D9X6OoON.d.mts.map +0 -1
  398. package/dist/Queue-DYPB2KWL.d.cts.map +0 -1
  399. package/dist/Subscriber-C4heaAyO.d.mts +0 -51
  400. package/dist/Subscriber-C4heaAyO.d.mts.map +0 -1
  401. package/dist/Subscriber-CotDUELC.d.cts +0 -51
  402. package/dist/Subscriber-CotDUELC.d.cts.map +0 -1
  403. package/dist/SubscriberBuilder-BEv0eoHy.d.cts +0 -59
  404. package/dist/SubscriberBuilder-BEv0eoHy.d.cts.map +0 -1
  405. package/dist/SubscriberBuilder-C0ZEtGDI.cjs +0 -125
  406. package/dist/SubscriberBuilder-C0ZEtGDI.cjs.map +0 -1
  407. package/dist/SubscriberBuilder-h7B_cHMr.mjs +0 -114
  408. package/dist/SubscriberBuilder-h7B_cHMr.mjs.map +0 -1
  409. package/dist/SubscriberBuilder-tyH5yTk5.d.mts +0 -59
  410. package/dist/SubscriberBuilder-tyH5yTk5.d.mts.map +0 -1
  411. package/dist/Topic-DEVGo0Dm.d.cts +0 -89
  412. package/dist/Topic-DEVGo0Dm.d.cts.map +0 -1
  413. package/dist/Topic-zk_6Gthr.d.mts +0 -89
  414. package/dist/Topic-zk_6Gthr.d.mts.map +0 -1
  415. package/dist/auth.d.cts.map +0 -1
  416. package/dist/auth.d.mts.map +0 -1
  417. package/dist/cache.d.cts.map +0 -1
  418. package/dist/cache.d.mts.map +0 -1
  419. package/dist/construct-interface-DPlxfpoS.d.mts.map +0 -1
  420. package/dist/construct-interface-DgXTJcOD.d.cts.map +0 -1
  421. package/dist/credential.cjs.map +0 -1
  422. package/dist/credential.d.cts.map +0 -1
  423. package/dist/credential.d.mts.map +0 -1
  424. package/dist/credential.mjs.map +0 -1
  425. package/dist/database/kysely.cjs.map +0 -1
  426. package/dist/database/kysely.d.cts.map +0 -1
  427. package/dist/database/kysely.d.mts.map +0 -1
  428. package/dist/database/kysely.mjs.map +0 -1
  429. package/dist/functions-B6qCvfmy.cjs.map +0 -1
  430. package/dist/functions-C53GW2eQ.mjs.map +0 -1
  431. package/dist/index-B2urf3YI.d.cts +0 -26
  432. package/dist/index-B2urf3YI.d.cts.map +0 -1
  433. package/dist/index-BPSZ_Lp_.d.cts.map +0 -1
  434. package/dist/index-BoZ-iisU.d.mts.map +0 -1
  435. package/dist/index-CdaU--_B.d.cts +0 -165
  436. package/dist/index-CdaU--_B.d.cts.map +0 -1
  437. package/dist/index-DMCDvnsM.d.mts +0 -26
  438. package/dist/index-DMCDvnsM.d.mts.map +0 -1
  439. package/dist/index-PQRWOQj4.d.mts +0 -165
  440. package/dist/index-PQRWOQj4.d.mts.map +0 -1
  441. package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
  442. package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
  443. package/dist/processAudits-BpRlPQMW.mjs +0 -77
  444. package/dist/processAudits-BpRlPQMW.mjs.map +0 -1
  445. package/dist/processAudits-D_2W5x8k.cjs +0 -88
  446. package/dist/processAudits-D_2W5x8k.cjs.map +0 -1
  447. package/dist/queue/index.cjs.map +0 -1
  448. package/dist/queue/index.d.cts.map +0 -1
  449. package/dist/queue/index.d.mts.map +0 -1
  450. package/dist/queue/index.mjs.map +0 -1
  451. package/dist/telemetry-DGcFlVpB.d.cts.map +0 -1
  452. package/dist/telemetry-DGcFlVpB.d.mts.map +0 -1
  453. package/dist/topic/index.cjs.map +0 -1
  454. package/dist/topic/index.mjs.map +0 -1
@@ -0,0 +1,133 @@
1
+ let _geekmidas_manifest = require("@geekmidas/manifest");
2
+ let _geekmidas_services = require("@geekmidas/services");
3
+ //#region src/subscribers/runSubscriber.ts
4
+ /** The subscriber's output did not match its `.output()` schema. */
5
+ var SubscriberOutputInvalid = class extends Error {
6
+ issues;
7
+ constructor(issues) {
8
+ super("Subscriber output validation failed: the handler's result does not match its .output() schema.");
9
+ this.issues = issues;
10
+ this.name = "SubscriberOutputInvalid";
11
+ }
12
+ };
13
+ /** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */
14
+ async function subscribedEvents(subscriber, rawEvent, logger) {
15
+ const events = [];
16
+ const records = rawEvent.Records ?? [];
17
+ const first = records[0];
18
+ const parse = first?.eventSource === "aws:sqs" ? (record) => parseSQSRecord(record) : first?.EventSource === "aws:sns" ? (record) => parseSNSRecord(record) : void 0;
19
+ if (!parse) return events;
20
+ const toObjectEvents = subscriber.bucketName ? (await import("@geekmidas/storage/events")).toObjectEvents : void 0;
21
+ for (const record of records) try {
22
+ const event = parse(record);
23
+ const untyped = !(typeof event === "object" && event?.type);
24
+ const parsed = subscriber.inboxName && untyped ? [{
25
+ type: _geekmidas_manifest.INBOX_EVENT,
26
+ payload: event
27
+ }] : toObjectEvents && untyped ? toObjectEvents(event) : [event];
28
+ for (const one of parsed) if (isSubscribed(subscriber, one)) events.push(one);
29
+ } catch (error) {
30
+ logger.error({
31
+ err: error,
32
+ record
33
+ }, "Failed to parse record");
34
+ }
35
+ return events;
36
+ }
37
+ /** The subscriber's services and database, registered as functions do. */
38
+ async function subscriberContext(subscriber, envParser) {
39
+ const discovery = _geekmidas_services.ServiceDiscovery.getInstance(envParser);
40
+ const services = subscriber.services.length > 0 ? await discovery.register(subscriber.services) : {};
41
+ const service = subscriber.databaseService;
42
+ return {
43
+ services,
44
+ db: service ? (await discovery.register([service]))[service.serviceName] : void 0
45
+ };
46
+ }
47
+ /** Runs the handler on `events`, and checks its output against its schema. */
48
+ async function runSubscriber(subscriber, context) {
49
+ if (context.events.length === 0) {
50
+ context.logger.info("No subscribed events to process");
51
+ return { batchItemFailures: [] };
52
+ }
53
+ const { events, services, db, logger } = context;
54
+ const result = await subscriber.handler({
55
+ events,
56
+ services,
57
+ logger,
58
+ db
59
+ });
60
+ if (subscriber.outputSchema && result) {
61
+ const validation = await subscriber.outputSchema["~standard"].validate(result);
62
+ if (validation.issues) {
63
+ context.logger.error({ issues: validation.issues }, "Subscriber output validation failed");
64
+ throw new SubscriberOutputInvalid(validation.issues);
65
+ }
66
+ return validation.value;
67
+ }
68
+ return result;
69
+ }
70
+ function isSubscribed(subscriber, event) {
71
+ if (typeof event !== "object" || !event?.type) return true;
72
+ if (!subscriber.subscribedEvents) return true;
73
+ return subscriber.subscribedEvents.includes(event.type);
74
+ }
75
+ function parseSNSRecord(record) {
76
+ const message = safeJsonParse(record.Sns.Message);
77
+ const messageType = record.Sns.MessageAttributes?.type?.Value;
78
+ if (message === null) return messageType ? {
79
+ type: messageType,
80
+ payload: record.Sns.Message
81
+ } : record.Sns.Message;
82
+ if (message.type) return message;
83
+ return messageType ? {
84
+ type: messageType,
85
+ payload: message
86
+ } : message;
87
+ }
88
+ function parseSQSRecord(record) {
89
+ const body = safeJsonParse(record.body);
90
+ if (body === null) return record.body;
91
+ if (body.Type === "Notification" && body.Message) {
92
+ const snsMessage = safeJsonParse(body.Message);
93
+ const messageType = body.MessageAttributes?.type?.Value;
94
+ if (snsMessage === null) return messageType ? {
95
+ type: messageType,
96
+ payload: body.Message
97
+ } : body.Message;
98
+ if (snsMessage.type) return snsMessage;
99
+ return messageType ? {
100
+ type: messageType,
101
+ payload: snsMessage
102
+ } : snsMessage;
103
+ }
104
+ return body;
105
+ }
106
+ function safeJsonParse(value) {
107
+ try {
108
+ return JSON.parse(value);
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ //#endregion
114
+ Object.defineProperty(exports, "runSubscriber", {
115
+ enumerable: true,
116
+ get: function() {
117
+ return runSubscriber;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "subscribedEvents", {
121
+ enumerable: true,
122
+ get: function() {
123
+ return subscribedEvents;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "subscriberContext", {
127
+ enumerable: true,
128
+ get: function() {
129
+ return subscriberContext;
130
+ }
131
+ });
132
+
133
+ //# sourceMappingURL=runSubscriber-CC_2C9F2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runSubscriber-CC_2C9F2.cjs","names":["INBOX_EVENT","ServiceDiscovery"],"sources":["../src/subscribers/runSubscriber.ts"],"sourcesContent":["/**\n * What a subscriber does with a batch of records, however they arrived: parse\n * them into events, keep the ones it subscribed to, and run its handler with\n * its services and database.\n *\n * Shared by the Lambda adaptor, which wraps it in middy, and the SNS push\n * adaptor, which a server runs and which must not need middy to load.\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT } from '@geekmidas/manifest';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport type { SNSEvent, SNSEventRecord, SQSEvent, SQSRecord } from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\ntype AnySubscriber = Subscriber<any, any, any, any, any, any, any>;\n\n/** The subscriber's output did not match its `.output()` schema. */\nexport class SubscriberOutputInvalid extends Error {\n\tconstructor(readonly issues: ReadonlyArray<unknown>) {\n\t\tsuper(\n\t\t\t\"Subscriber output validation failed: the handler's result does not match its .output() schema.\",\n\t\t);\n\t\tthis.name = 'SubscriberOutputInvalid';\n\t}\n}\n\n/** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */\nexport async function subscribedEvents(\n\tsubscriber: AnySubscriber,\n\trawEvent: { Records?: readonly unknown[] },\n\tlogger: Logger,\n): Promise<any[]> {\n\tconst events: any[] = [];\n\tconst records = rawEvent.Records ?? [];\n\tconst first = records[0] as any;\n\tconst parse =\n\t\tfirst?.eventSource === 'aws:sqs'\n\t\t\t? (record: any) => parseSQSRecord(record)\n\t\t\t: first?.EventSource === 'aws:sns'\n\t\t\t\t? (record: any) => parseSNSRecord(record)\n\t\t\t\t: undefined;\n\tif (!parse) return events;\n\n\t// A bucket's subscriber is sent what the storage sends — a notification\n\t// of records — and reads it as object events. Loaded only then: an app\n\t// with no bucket never installs the storage package.\n\tconst toObjectEvents = subscriber.bucketName\n\t\t? (await import('@geekmidas/storage/events')).toObjectEvents\n\t\t: undefined;\n\n\tfor (const record of records) {\n\t\ttry {\n\t\t\tconst event = parse(record);\n\t\t\tconst untyped = !(typeof event === 'object' && event?.type);\n\t\t\t// An inbox's subscriber is sent SES's receipt notification as SES\n\t\t\t// wrote it, with no type of ours on it.\n\t\t\tconst parsed =\n\t\t\t\tsubscriber.inboxName && untyped\n\t\t\t\t\t? [{ type: INBOX_EVENT, payload: event }]\n\t\t\t\t\t: toObjectEvents && untyped\n\t\t\t\t\t\t? toObjectEvents(event)\n\t\t\t\t\t\t: [event];\n\t\t\tfor (const one of parsed) {\n\t\t\t\tif (isSubscribed(subscriber, one)) events.push(one);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error({ err: error, record }, 'Failed to parse record');\n\t\t}\n\t}\n\treturn events;\n}\n\n/** The subscriber's services and database, registered as functions do. */\nexport async function subscriberContext(\n\tsubscriber: AnySubscriber,\n\tenvParser: EnvironmentParser<{}>,\n): Promise<{ services: Record<string, unknown>; db: unknown }> {\n\tconst discovery = ServiceDiscovery.getInstance(envParser);\n\tconst services =\n\t\tsubscriber.services.length > 0\n\t\t\t? await discovery.register(subscriber.services)\n\t\t\t: {};\n\tconst service = subscriber.databaseService;\n\tconst db = service\n\t\t? (await discovery.register([service]))[service.serviceName]\n\t\t: undefined;\n\treturn { services, db };\n}\n\n/** Runs the handler on `events`, and checks its output against its schema. */\nexport async function runSubscriber(\n\tsubscriber: AnySubscriber,\n\tcontext: {\n\t\tevents: any[];\n\t\tservices: Record<string, unknown>;\n\t\tdb: unknown;\n\t\tlogger: Logger;\n\t},\n): Promise<unknown> {\n\tif (context.events.length === 0) {\n\t\tcontext.logger.info('No subscribed events to process');\n\t\treturn { batchItemFailures: [] };\n\t}\n\n\tconst { events, services, db, logger } = context;\n\tconst result = await subscriber.handler({\n\t\tevents,\n\t\tservices,\n\t\tlogger,\n\t\tdb,\n\t} as any);\n\n\tif (subscriber.outputSchema && result) {\n\t\tconst validation =\n\t\t\tawait subscriber.outputSchema['~standard'].validate(result);\n\t\tif (validation.issues) {\n\t\t\tcontext.logger.error(\n\t\t\t\t{ issues: validation.issues },\n\t\t\t\t'Subscriber output validation failed',\n\t\t\t);\n\t\t\tthrow new SubscriberOutputInvalid(validation.issues);\n\t\t}\n\t\treturn validation.value;\n\t}\n\n\treturn result;\n}\n\nfunction isSubscribed(subscriber: AnySubscriber, event: any): boolean {\n\t// No event type (raw string/non-object) — always include\n\tif (typeof event !== 'object' || !event?.type) return true;\n\t// No filter configured — accept all\n\tif (!subscriber.subscribedEvents) return true;\n\treturn subscriber.subscribedEvents.includes(event.type);\n}\n\nfunction parseSNSRecord(record: SNSEventRecord): any {\n\tconst message = safeJsonParse(record.Sns.Message);\n\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\tif (message === null) {\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t: record.Sns.Message;\n\t}\n\n\tif (message.type) {\n\t\treturn message; // Full event format: { type, payload }\n\t}\n\n\t// Payload-only format: type is in MessageAttributes\n\treturn messageType ? { type: messageType, payload: message } : message;\n}\n\nfunction parseSQSRecord(record: SQSRecord): any {\n\tconst body = safeJsonParse(record.body);\n\n\t// Not JSON — return raw body as-is\n\tif (body === null) {\n\t\treturn record.body;\n\t}\n\n\t// Check if this is an SNS message wrapped in SQS\n\tif (body.Type === 'Notification' && body.Message) {\n\t\tconst snsMessage = safeJsonParse(body.Message);\n\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\tif (snsMessage === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t: body.Message;\n\t\t}\n\n\t\tif (snsMessage.type) {\n\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: snsMessage }\n\t\t\t: snsMessage;\n\t}\n\n\t// Direct SQS message\n\treturn body;\n}\n\nfunction safeJsonParse(value: string): any | null {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;AAmBA,IAAa,0BAAb,cAA6C,MAAM;CAC7B;CAArB,YAAY,QAAyC;EACpD,MACC,gGACD;EAHoB,KAAA,SAAA;EAIpB,KAAK,OAAO;CACb;AACD;;AAGA,eAAsB,iBACrB,YACA,UACA,QACiB;CACjB,MAAM,SAAgB,CAAC;CACvB,MAAM,UAAU,SAAS,WAAW,CAAC;CACrC,MAAM,QAAQ,QAAQ;CACtB,MAAM,QACL,OAAO,gBAAgB,aACnB,WAAgB,eAAe,MAAM,IACtC,OAAO,gBAAgB,aACrB,WAAgB,eAAe,MAAM,IACtC,KAAA;CACL,IAAI,CAAC,OAAO,OAAO;CAKnB,MAAM,iBAAiB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D;GACA,MAAM,IAAI,wBAAwB,WAAW,MAAM;EACpD;EACA,OAAO,WAAW;CACnB;CAEA,OAAO;AACR;AAEA,SAAS,aAAa,YAA2B,OAAqB;CAErE,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,OAAO;CAEtD,IAAI,CAAC,WAAW,kBAAkB,OAAO;CACzC,OAAO,WAAW,iBAAiB,SAAS,MAAM,IAAI;AACvD;AAEA,SAAS,eAAe,QAA6B;CACpD,MAAM,UAAU,cAAc,OAAO,IAAI,OAAO;CAChD,MAAM,cAAc,OAAO,IAAI,mBAAmB,MAAM;CAGxD,IAAI,YAAY,MACf,OAAO,cACJ;EAAE,MAAM;EAAa,SAAS,OAAO,IAAI;CAAQ,IACjD,OAAO,IAAI;CAGf,IAAI,QAAQ,MACX,OAAO;CAIR,OAAO,cAAc;EAAE,MAAM;EAAa,SAAS;CAAQ,IAAI;AAChE;AAEA,SAAS,eAAe,QAAwB;CAC/C,MAAM,OAAO,cAAc,OAAO,IAAI;CAGtC,IAAI,SAAS,MACZ,OAAO,OAAO;CAIf,IAAI,KAAK,SAAS,kBAAkB,KAAK,SAAS;EACjD,MAAM,aAAa,cAAc,KAAK,OAAO;EAC7C,MAAM,cAAc,KAAK,mBAAmB,MAAM;EAGlD,IAAI,eAAe,MAClB,OAAO,cACJ;GAAE,MAAM;GAAa,SAAS,KAAK;EAAQ,IAC3C,KAAK;EAGT,IAAI,WAAW,MACd,OAAO;EAIR,OAAO,cACJ;GAAE,MAAM;GAAa,SAAS;EAAW,IACzC;CACJ;CAGA,OAAO;AACR;AAEA,SAAS,cAAc,OAA2B;CACjD,IAAI;EACH,OAAO,KAAK,MAAM,KAAK;CACxB,QAAQ;EACP,OAAO;CACR;AACD"}
@@ -0,0 +1,116 @@
1
+ import { INBOX_EVENT } from "@geekmidas/manifest";
2
+ import { ServiceDiscovery } from "@geekmidas/services";
3
+ //#region src/subscribers/runSubscriber.ts
4
+ /** The subscriber's output did not match its `.output()` schema. */
5
+ var SubscriberOutputInvalid = class extends Error {
6
+ issues;
7
+ constructor(issues) {
8
+ super("Subscriber output validation failed: the handler's result does not match its .output() schema.");
9
+ this.issues = issues;
10
+ this.name = "SubscriberOutputInvalid";
11
+ }
12
+ };
13
+ /** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */
14
+ async function subscribedEvents(subscriber, rawEvent, logger) {
15
+ const events = [];
16
+ const records = rawEvent.Records ?? [];
17
+ const first = records[0];
18
+ const parse = first?.eventSource === "aws:sqs" ? (record) => parseSQSRecord(record) : first?.EventSource === "aws:sns" ? (record) => parseSNSRecord(record) : void 0;
19
+ if (!parse) return events;
20
+ const toObjectEvents = subscriber.bucketName ? (await import("@geekmidas/storage/events")).toObjectEvents : void 0;
21
+ for (const record of records) try {
22
+ const event = parse(record);
23
+ const untyped = !(typeof event === "object" && event?.type);
24
+ const parsed = subscriber.inboxName && untyped ? [{
25
+ type: INBOX_EVENT,
26
+ payload: event
27
+ }] : toObjectEvents && untyped ? toObjectEvents(event) : [event];
28
+ for (const one of parsed) if (isSubscribed(subscriber, one)) events.push(one);
29
+ } catch (error) {
30
+ logger.error({
31
+ err: error,
32
+ record
33
+ }, "Failed to parse record");
34
+ }
35
+ return events;
36
+ }
37
+ /** The subscriber's services and database, registered as functions do. */
38
+ async function subscriberContext(subscriber, envParser) {
39
+ const discovery = ServiceDiscovery.getInstance(envParser);
40
+ const services = subscriber.services.length > 0 ? await discovery.register(subscriber.services) : {};
41
+ const service = subscriber.databaseService;
42
+ return {
43
+ services,
44
+ db: service ? (await discovery.register([service]))[service.serviceName] : void 0
45
+ };
46
+ }
47
+ /** Runs the handler on `events`, and checks its output against its schema. */
48
+ async function runSubscriber(subscriber, context) {
49
+ if (context.events.length === 0) {
50
+ context.logger.info("No subscribed events to process");
51
+ return { batchItemFailures: [] };
52
+ }
53
+ const { events, services, db, logger } = context;
54
+ const result = await subscriber.handler({
55
+ events,
56
+ services,
57
+ logger,
58
+ db
59
+ });
60
+ if (subscriber.outputSchema && result) {
61
+ const validation = await subscriber.outputSchema["~standard"].validate(result);
62
+ if (validation.issues) {
63
+ context.logger.error({ issues: validation.issues }, "Subscriber output validation failed");
64
+ throw new SubscriberOutputInvalid(validation.issues);
65
+ }
66
+ return validation.value;
67
+ }
68
+ return result;
69
+ }
70
+ function isSubscribed(subscriber, event) {
71
+ if (typeof event !== "object" || !event?.type) return true;
72
+ if (!subscriber.subscribedEvents) return true;
73
+ return subscriber.subscribedEvents.includes(event.type);
74
+ }
75
+ function parseSNSRecord(record) {
76
+ const message = safeJsonParse(record.Sns.Message);
77
+ const messageType = record.Sns.MessageAttributes?.type?.Value;
78
+ if (message === null) return messageType ? {
79
+ type: messageType,
80
+ payload: record.Sns.Message
81
+ } : record.Sns.Message;
82
+ if (message.type) return message;
83
+ return messageType ? {
84
+ type: messageType,
85
+ payload: message
86
+ } : message;
87
+ }
88
+ function parseSQSRecord(record) {
89
+ const body = safeJsonParse(record.body);
90
+ if (body === null) return record.body;
91
+ if (body.Type === "Notification" && body.Message) {
92
+ const snsMessage = safeJsonParse(body.Message);
93
+ const messageType = body.MessageAttributes?.type?.Value;
94
+ if (snsMessage === null) return messageType ? {
95
+ type: messageType,
96
+ payload: body.Message
97
+ } : body.Message;
98
+ if (snsMessage.type) return snsMessage;
99
+ return messageType ? {
100
+ type: messageType,
101
+ payload: snsMessage
102
+ } : snsMessage;
103
+ }
104
+ return body;
105
+ }
106
+ function safeJsonParse(value) {
107
+ try {
108
+ return JSON.parse(value);
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ //#endregion
114
+ export { subscribedEvents as n, subscriberContext as r, runSubscriber as t };
115
+
116
+ //# sourceMappingURL=runSubscriber-DyHWp_Lf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runSubscriber-DyHWp_Lf.mjs","names":[],"sources":["../src/subscribers/runSubscriber.ts"],"sourcesContent":["/**\n * What a subscriber does with a batch of records, however they arrived: parse\n * them into events, keep the ones it subscribed to, and run its handler with\n * its services and database.\n *\n * Shared by the Lambda adaptor, which wraps it in middy, and the SNS push\n * adaptor, which a server runs and which must not need middy to load.\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT } from '@geekmidas/manifest';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport type { SNSEvent, SNSEventRecord, SQSEvent, SQSRecord } from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\ntype AnySubscriber = Subscriber<any, any, any, any, any, any, any>;\n\n/** The subscriber's output did not match its `.output()` schema. */\nexport class SubscriberOutputInvalid extends Error {\n\tconstructor(readonly issues: ReadonlyArray<unknown>) {\n\t\tsuper(\n\t\t\t\"Subscriber output validation failed: the handler's result does not match its .output() schema.\",\n\t\t);\n\t\tthis.name = 'SubscriberOutputInvalid';\n\t}\n}\n\n/** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */\nexport async function subscribedEvents(\n\tsubscriber: AnySubscriber,\n\trawEvent: { Records?: readonly unknown[] },\n\tlogger: Logger,\n): Promise<any[]> {\n\tconst events: any[] = [];\n\tconst records = rawEvent.Records ?? [];\n\tconst first = records[0] as any;\n\tconst parse =\n\t\tfirst?.eventSource === 'aws:sqs'\n\t\t\t? (record: any) => parseSQSRecord(record)\n\t\t\t: first?.EventSource === 'aws:sns'\n\t\t\t\t? (record: any) => parseSNSRecord(record)\n\t\t\t\t: undefined;\n\tif (!parse) return events;\n\n\t// A bucket's subscriber is sent what the storage sends — a notification\n\t// of records — and reads it as object events. Loaded only then: an app\n\t// with no bucket never installs the storage package.\n\tconst toObjectEvents = subscriber.bucketName\n\t\t? (await import('@geekmidas/storage/events')).toObjectEvents\n\t\t: undefined;\n\n\tfor (const record of records) {\n\t\ttry {\n\t\t\tconst event = parse(record);\n\t\t\tconst untyped = !(typeof event === 'object' && event?.type);\n\t\t\t// An inbox's subscriber is sent SES's receipt notification as SES\n\t\t\t// wrote it, with no type of ours on it.\n\t\t\tconst parsed =\n\t\t\t\tsubscriber.inboxName && untyped\n\t\t\t\t\t? [{ type: INBOX_EVENT, payload: event }]\n\t\t\t\t\t: toObjectEvents && untyped\n\t\t\t\t\t\t? toObjectEvents(event)\n\t\t\t\t\t\t: [event];\n\t\t\tfor (const one of parsed) {\n\t\t\t\tif (isSubscribed(subscriber, one)) events.push(one);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error({ err: error, record }, 'Failed to parse record');\n\t\t}\n\t}\n\treturn events;\n}\n\n/** The subscriber's services and database, registered as functions do. */\nexport async function subscriberContext(\n\tsubscriber: AnySubscriber,\n\tenvParser: EnvironmentParser<{}>,\n): Promise<{ services: Record<string, unknown>; db: unknown }> {\n\tconst discovery = ServiceDiscovery.getInstance(envParser);\n\tconst services =\n\t\tsubscriber.services.length > 0\n\t\t\t? await discovery.register(subscriber.services)\n\t\t\t: {};\n\tconst service = subscriber.databaseService;\n\tconst db = service\n\t\t? (await discovery.register([service]))[service.serviceName]\n\t\t: undefined;\n\treturn { services, db };\n}\n\n/** Runs the handler on `events`, and checks its output against its schema. */\nexport async function runSubscriber(\n\tsubscriber: AnySubscriber,\n\tcontext: {\n\t\tevents: any[];\n\t\tservices: Record<string, unknown>;\n\t\tdb: unknown;\n\t\tlogger: Logger;\n\t},\n): Promise<unknown> {\n\tif (context.events.length === 0) {\n\t\tcontext.logger.info('No subscribed events to process');\n\t\treturn { batchItemFailures: [] };\n\t}\n\n\tconst { events, services, db, logger } = context;\n\tconst result = await subscriber.handler({\n\t\tevents,\n\t\tservices,\n\t\tlogger,\n\t\tdb,\n\t} as any);\n\n\tif (subscriber.outputSchema && result) {\n\t\tconst validation =\n\t\t\tawait subscriber.outputSchema['~standard'].validate(result);\n\t\tif (validation.issues) {\n\t\t\tcontext.logger.error(\n\t\t\t\t{ issues: validation.issues },\n\t\t\t\t'Subscriber output validation failed',\n\t\t\t);\n\t\t\tthrow new SubscriberOutputInvalid(validation.issues);\n\t\t}\n\t\treturn validation.value;\n\t}\n\n\treturn result;\n}\n\nfunction isSubscribed(subscriber: AnySubscriber, event: any): boolean {\n\t// No event type (raw string/non-object) — always include\n\tif (typeof event !== 'object' || !event?.type) return true;\n\t// No filter configured — accept all\n\tif (!subscriber.subscribedEvents) return true;\n\treturn subscriber.subscribedEvents.includes(event.type);\n}\n\nfunction parseSNSRecord(record: SNSEventRecord): any {\n\tconst message = safeJsonParse(record.Sns.Message);\n\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\tif (message === null) {\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t: record.Sns.Message;\n\t}\n\n\tif (message.type) {\n\t\treturn message; // Full event format: { type, payload }\n\t}\n\n\t// Payload-only format: type is in MessageAttributes\n\treturn messageType ? { type: messageType, payload: message } : message;\n}\n\nfunction parseSQSRecord(record: SQSRecord): any {\n\tconst body = safeJsonParse(record.body);\n\n\t// Not JSON — return raw body as-is\n\tif (body === null) {\n\t\treturn record.body;\n\t}\n\n\t// Check if this is an SNS message wrapped in SQS\n\tif (body.Type === 'Notification' && body.Message) {\n\t\tconst snsMessage = safeJsonParse(body.Message);\n\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\tif (snsMessage === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t: body.Message;\n\t\t}\n\n\t\tif (snsMessage.type) {\n\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: snsMessage }\n\t\t\t: snsMessage;\n\t}\n\n\t// Direct SQS message\n\treturn body;\n}\n\nfunction safeJsonParse(value: string): any | null {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;AA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AAS,KAAK;EAAQ,IAC3C,KAAK;EAGT,IAAI,WAAW,MACd,OAAO;EAIR,OAAO,cACJ;GAAE,MAAM;GAAa,SAAS;EAAW,IACzC;CACJ;CAGA,OAAO;AACR;AAEA,SAAS,cAAc,OAA2B;CACjD,IAAI;EACH,OAAO,KAAK,MAAM,KAAK;CACxB,QAAQ;EACP,OAAO;CACR;AACD"}
@@ -0,0 +1,38 @@
1
+ //#region src/shutdown.ts
2
+ const key = Symbol.for("@geekmidas/constructs/shutdown");
3
+ const registry = globalThis;
4
+ registry[key] ??= /* @__PURE__ */ new Set();
5
+ const hooks = registry[key];
6
+ /** Run `hook` when the server shuts down. Returns a function that removes it. */
7
+ function onShutdown(hook) {
8
+ hooks.add(hook);
9
+ return () => hooks.delete(hook);
10
+ }
11
+ /**
12
+ * Run every registered hook, together, and wait for them. A hook that fails is
13
+ * reported to `onError` and does not stop the others.
14
+ */
15
+ async function runShutdownHooks(onError = () => {}) {
16
+ await Promise.all([...hooks].map(async (hook) => {
17
+ try {
18
+ await hook();
19
+ } catch (error) {
20
+ onError(error);
21
+ }
22
+ }));
23
+ }
24
+ //#endregion
25
+ Object.defineProperty(exports, "onShutdown", {
26
+ enumerable: true,
27
+ get: function() {
28
+ return onShutdown;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "runShutdownHooks", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return runShutdownHooks;
35
+ }
36
+ });
37
+
38
+ //# sourceMappingURL=shutdown-BMJmAhSt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown-BMJmAhSt.cjs","names":[],"sources":["../src/shutdown.ts"],"sourcesContent":["/**\n * What a server releases when it stops: the connections constructs opened.\n *\n * A construct that holds something open — a database's pool — registers how to\n * close it here, and the generated server runs every hook once it has stopped\n * taking requests. Without that, a rolling deploy has the old task and the new\n * one both holding connections until the old process dies.\n *\n * Kept free of any driver import so the server entry can always import it,\n * whether or not the app has a database.\n */\n\ntype ShutdownHook = () => Promise<void> | void;\n\n// On globalThis, as Credentials are: a package loaded twice (ESM and CJS)\n// would otherwise keep two registries, and the server would run the empty one.\nconst key = Symbol.for('@geekmidas/constructs/shutdown');\nconst registry = globalThis as Record<symbol, Set<ShutdownHook> | undefined>;\nregistry[key] ??= new Set<ShutdownHook>();\nconst hooks = registry[key];\n\n/** Run `hook` when the server shuts down. Returns a function that removes it. */\nexport function onShutdown(hook: ShutdownHook): () => void {\n\thooks.add(hook);\n\treturn () => hooks.delete(hook);\n}\n\n/**\n * Run every registered hook, together, and wait for them. A hook that fails is\n * reported to `onError` and does not stop the others.\n */\nexport async function runShutdownHooks(\n\tonError: (error: unknown) => void = () => {},\n): Promise<void> {\n\tawait Promise.all(\n\t\t[...hooks].map(async (hook) => {\n\t\t\ttry {\n\t\t\t\tawait hook();\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"mappings":";AAgBA,MAAM,MAAM,OAAO,IAAI,gCAAgC;AACvD,MAAM,WAAW;AACjB,SAAS,yBAAS,IAAI,IAAkB;AACxC,MAAM,QAAQ,SAAS;;AAGvB,SAAgB,WAAW,MAAgC;CAC1D,MAAM,IAAI,IAAI;CACd,aAAa,MAAM,OAAO,IAAI;AAC/B;;;;;AAMA,eAAsB,iBACrB,gBAA0C,CAAC,GAC3B;CAChB,MAAM,QAAQ,IACb,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,OAAO,SAAS;EAC9B,IAAI;GACH,MAAM,KAAK;EACZ,SAAS,OAAO;GACf,QAAQ,KAAK;EACd;CACD,CAAC,CACF;AACD"}
@@ -0,0 +1,27 @@
1
+ //#region src/shutdown.ts
2
+ const key = Symbol.for("@geekmidas/constructs/shutdown");
3
+ const registry = globalThis;
4
+ registry[key] ??= /* @__PURE__ */ new Set();
5
+ const hooks = registry[key];
6
+ /** Run `hook` when the server shuts down. Returns a function that removes it. */
7
+ function onShutdown(hook) {
8
+ hooks.add(hook);
9
+ return () => hooks.delete(hook);
10
+ }
11
+ /**
12
+ * Run every registered hook, together, and wait for them. A hook that fails is
13
+ * reported to `onError` and does not stop the others.
14
+ */
15
+ async function runShutdownHooks(onError = () => {}) {
16
+ await Promise.all([...hooks].map(async (hook) => {
17
+ try {
18
+ await hook();
19
+ } catch (error) {
20
+ onError(error);
21
+ }
22
+ }));
23
+ }
24
+ //#endregion
25
+ export { runShutdownHooks as n, onShutdown as t };
26
+
27
+ //# sourceMappingURL=shutdown-C7xa8x9S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown-C7xa8x9S.mjs","names":[],"sources":["../src/shutdown.ts"],"sourcesContent":["/**\n * What a server releases when it stops: the connections constructs opened.\n *\n * A construct that holds something open — a database's pool — registers how to\n * close it here, and the generated server runs every hook once it has stopped\n * taking requests. Without that, a rolling deploy has the old task and the new\n * one both holding connections until the old process dies.\n *\n * Kept free of any driver import so the server entry can always import it,\n * whether or not the app has a database.\n */\n\ntype ShutdownHook = () => Promise<void> | void;\n\n// On globalThis, as Credentials are: a package loaded twice (ESM and CJS)\n// would otherwise keep two registries, and the server would run the empty one.\nconst key = Symbol.for('@geekmidas/constructs/shutdown');\nconst registry = globalThis as Record<symbol, Set<ShutdownHook> | undefined>;\nregistry[key] ??= new Set<ShutdownHook>();\nconst hooks = registry[key];\n\n/** Run `hook` when the server shuts down. Returns a function that removes it. */\nexport function onShutdown(hook: ShutdownHook): () => void {\n\thooks.add(hook);\n\treturn () => hooks.delete(hook);\n}\n\n/**\n * Run every registered hook, together, and wait for them. A hook that fails is\n * reported to `onError` and does not stop the others.\n */\nexport async function runShutdownHooks(\n\tonError: (error: unknown) => void = () => {},\n): Promise<void> {\n\tawait Promise.all(\n\t\t[...hooks].map(async (hook) => {\n\t\t\ttry {\n\t\t\t\tawait hook();\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"mappings":";AAgBA,MAAM,MAAM,OAAO,IAAI,gCAAgC;AACvD,MAAM,WAAW;AACjB,SAAS,yBAAS,IAAI,IAAkB;AACxC,MAAM,QAAQ,SAAS;;AAGvB,SAAgB,WAAW,MAAgC;CAC1D,MAAM,IAAI,IAAI;CACd,aAAa,MAAM,OAAO,IAAI;AAC/B;;;;;AAMA,eAAsB,iBACrB,gBAA0C,CAAC,GAC3B;CAChB,MAAM,QAAQ,IACb,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,OAAO,SAAS;EAC9B,IAAI;GACH,MAAM,KAAK;EACZ,SAAS,OAAO;GACf,QAAQ,KAAK;EACd;CACD,CAAC,CACF;AACD"}
package/dist/site.cjs CHANGED
@@ -15,26 +15,88 @@ let _geekmidas_manifest = require("@geekmidas/manifest");
15
15
  * .dependsOn([api, auth]);
16
16
  * ```
17
17
  *
18
- * It has no `.service`. A site is not a process that registers clients — it is
19
- * built, and the values it needs are inlined or fetched by its own framework —
20
- * so the edge is {@link Declarable} rather than {@link Consumable}, and the
21
- * asymmetry is the honest one: a site consumes addresses, not connections.
18
+ * A site consumes addresses, not connections: it is built, and the values it
19
+ * needs are inlined or fetched by its own framework, so its own edges take any
20
+ * {@link Declarable}. Its `.service` is its public address — what a worker's
21
+ * cron or an endpoint that builds links to it reads:
22
+ *
23
+ * ```ts
24
+ * export const digest = worker
25
+ * .cron('rate(1 day)')
26
+ * .dependsOn([web])
27
+ * .handle(async ({ services }) => link(services.web, '/inbox'));
28
+ * ```
22
29
  *
23
30
  * Only the static variant ships. SSR deploy shapes are unstable and each one is
24
- * its own maintenance, so they follow rather than arrive together; Expo and
25
- * mobile are out of scope entirely, because an app store is not infrastructure
26
- * and there is no URL to hand anyone.
31
+ * its own maintenance, so they follow rather than arrive together. A mobile app
32
+ * is not a site — it is reached by a scheme, not a URL — and is its own
33
+ * construct: see `MobileApp`.
27
34
  */
35
+ /** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */
36
+ var WildcardSiteNeedsHosts = class extends Error {
37
+ id;
38
+ constructor(id) {
39
+ super(`'${id}' answers on every subdomain, so it has to say which of them are tenants: pass \`hosts\`, a GET endpoint answering 200 for a host it serves and 404 otherwise.`);
40
+ this.id = id;
41
+ this.name = "WildcardSiteNeedsHosts";
42
+ }
43
+ };
44
+ /** `hosts` on a site with one host, where there is nothing to check. */
45
+ var SiteHostsNeedsWildcard = class extends Error {
46
+ id;
47
+ constructor(id) {
48
+ super(`'${id}' names a \`hosts\` check but answers on one host. Declare \`subdomain: '*'\` to serve every subdomain, or drop \`hosts\`.`);
49
+ this.id = id;
50
+ this.name = "SiteHostsNeedsWildcard";
51
+ }
52
+ };
53
+ /** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */
54
+ var SiteHostsNotGet = class extends Error {
55
+ id;
56
+ method;
57
+ route;
58
+ constructor(id, method, route) {
59
+ super(`'${id}' checks its hosts with ${method} ${route}, but the edge asks with GET ${route}?domain=<host>. Make it a GET endpoint.`);
60
+ this.id = id;
61
+ this.method = method;
62
+ this.route = route;
63
+ this.name = "SiteHostsNotGet";
64
+ }
65
+ };
66
+ /** A wildcard site that says it holds the base domain. */
67
+ var WildcardSiteCannotBeRoot = class extends Error {
68
+ id;
69
+ constructor(id) {
70
+ super(`'${id}' answers on every subdomain, so it cannot also hold the base domain. Drop \`root: true\`, and declare the site the base domain points at separately.`);
71
+ this.id = id;
72
+ this.name = "WildcardSiteCannotBeRoot";
73
+ }
74
+ };
28
75
  var StaticSite = class StaticSite {
29
76
  config;
30
77
  dependencies;
31
78
  id;
32
79
  keys;
80
+ /**
81
+ * Its public address, `https://web.example.com` — a string, no await. The
82
+ * same `<ID>_URL` on every command and stage, so a link built from it opens
83
+ * in a browser.
84
+ */
85
+ service;
33
86
  constructor(id, config, dependencies = []) {
34
87
  this.config = config;
35
88
  this.dependencies = dependencies;
36
89
  this.id = (0, _geekmidas_manifest.canonicalId)(id);
37
90
  this.keys = { url: (0, _geekmidas_manifest.provideKey)(this.id, "url") };
91
+ this.service = {
92
+ serviceName: (0, _geekmidas_manifest.serviceKey)(this.id),
93
+ register: (options) => require_construct_interface.publicUrl(options, this.keys.url)
94
+ };
95
+ const wildcard = config.subdomain === _geekmidas_manifest.WILDCARD_SUBDOMAIN;
96
+ if (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);
97
+ if (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);
98
+ if (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);
99
+ if (config.hosts && config.hosts.method.toUpperCase() !== "GET") throw new SiteHostsNotGet(this.id, config.hosts.method, config.hosts.route);
38
100
  }
39
101
  /**
40
102
  * What this site calls.
@@ -51,10 +113,16 @@ var StaticSite = class StaticSite {
51
113
  return new StaticSite(this.id, this.config, [...this.dependencies, ...constructs.map(require_construct_interface.edgeTo)]);
52
114
  }
53
115
  declare() {
116
+ const { hosts } = this.config;
54
117
  return [{
55
118
  kind: "site",
56
119
  id: this.id,
57
120
  variant: this.config.variant ?? "static",
121
+ ...this.config.subdomain ? { subdomain: this.config.subdomain } : {},
122
+ ...hosts ? { hosts: {
123
+ surface: (0, _geekmidas_manifest.canonicalId)(hosts.surface.id),
124
+ path: hosts.route
125
+ } } : {},
58
126
  app: {
59
127
  path: this.config.path,
60
128
  ...this.config.port ? { port: this.config.port } : {},
@@ -62,11 +130,20 @@ var StaticSite = class StaticSite {
62
130
  },
63
131
  ...this.config.root ? { root: true } : {},
64
132
  dependencies: this.dependencies,
65
- provides: [this.keys.url]
133
+ ...this.config.telemetry ? { telemetry: this.config.telemetry.id } : {},
134
+ ...this.config.password ? { password: {
135
+ secret: this.config.password.secret.id,
136
+ stages: [...this.config.password.stages]
137
+ } } : {},
138
+ provides: [this.keys.url, ...hosts ? [(0, _geekmidas_manifest.provideKey)(this.id, "domain"), (0, _geekmidas_manifest.provideKey)(this.id, "protectedSubdomains")] : []]
66
139
  }];
67
140
  }
68
141
  };
69
142
  //#endregion
143
+ exports.SiteHostsNeedsWildcard = SiteHostsNeedsWildcard;
144
+ exports.SiteHostsNotGet = SiteHostsNotGet;
70
145
  exports.StaticSite = StaticSite;
146
+ exports.WildcardSiteCannotBeRoot = WildcardSiteCannotBeRoot;
147
+ exports.WildcardSiteNeedsHosts = WildcardSiteNeedsHosts;
71
148
 
72
149
  //# sourceMappingURL=site.cjs.map
package/dist/site.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"site.cjs","names":["canonicalId","provideKey","edgeTo"],"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; Expo and\n * mobile are out of scope entirely, because an app store is not infrastructure\n * and there is no URL to hand anyone.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\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 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}\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\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\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\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\tprovides: [this.keys.url],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,IAAa,aAAb,MAAa,WAEb;CAMmB;CAOA;CAZlB;CACA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,MAAA,GAAKA,oBAAAA,YAAAA,CAAY,EAAY;EAClC,KAAK,OAAO,EAAE,MAAA,GAAKC,oBAAAA,WAAAA,CAAW,KAAK,IAAI,KAAK,EAAE;CAC/C;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAIC,4BAAAA,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,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,UAAU,CAAC,KAAK,KAAK,GAAG;EACzB,CACD;CACD;AACD"}
1
+ {"version":3,"file":"site.cjs","names":["canonicalId","provideKey","serviceKey","publicUrl","WILDCARD_SUBDOMAIN","edgeTo"],"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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