@geekmidas/constructs 10.0.0-alpha.14 → 10.0.0-alpha.140
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.
- package/README.md +222 -158
- package/dist/Construct-127M7yrl.d.cts +231 -0
- package/dist/Construct-127M7yrl.d.cts.map +1 -0
- package/dist/{Construct-BeYVu_QF.mjs → Construct-CGuc_Ijk.mjs} +8 -9
- package/dist/Construct-CGuc_Ijk.mjs.map +1 -0
- package/dist/{Construct-DqdlARxq.cjs → Construct-DorKS0Ua.cjs} +8 -9
- package/dist/Construct-DorKS0Ua.cjs.map +1 -0
- package/dist/Construct-DySlwh8o.d.mts +231 -0
- package/dist/Construct-DySlwh8o.d.mts.map +1 -0
- package/dist/{Cron-DKqnnTdH.d.cts → Cron-CFkpEys6.d.cts} +14 -7
- package/dist/Cron-CFkpEys6.d.cts.map +1 -0
- package/dist/{Cron-SyqS5oWJ.d.mts → Cron-CQoDSu-n.d.mts} +14 -7
- package/dist/Cron-CQoDSu-n.d.mts.map +1 -0
- package/dist/CronBuilder-1W-G_i15.d.mts +47 -0
- package/dist/CronBuilder-1W-G_i15.d.mts.map +1 -0
- package/dist/{CronBuilder-D_0HNBTr.mjs → CronBuilder-BJ5LoadF.mjs} +28 -11
- package/dist/CronBuilder-BJ5LoadF.mjs.map +1 -0
- package/dist/{CronBuilder-BdnI6lxF.cjs → CronBuilder-B_NSP-Y5.cjs} +27 -10
- package/dist/CronBuilder-B_NSP-Y5.cjs.map +1 -0
- package/dist/CronBuilder-OaCRRFVk.d.cts +47 -0
- package/dist/CronBuilder-OaCRRFVk.d.cts.map +1 -0
- package/dist/{Endpoint-C6yyHpRS.d.cts → Endpoint-BEh-jW-f.d.cts} +122 -41
- package/dist/Endpoint-BEh-jW-f.d.cts.map +1 -0
- package/dist/Endpoint-BcUorcBa.cjs +576 -0
- package/dist/Endpoint-BcUorcBa.cjs.map +1 -0
- package/dist/Endpoint-BgvG36NO.mjs +547 -0
- package/dist/Endpoint-BgvG36NO.mjs.map +1 -0
- package/dist/{Endpoint-DuT4TEEq.d.mts → Endpoint-DTXDggNl.d.mts} +124 -43
- package/dist/Endpoint-DTXDggNl.d.mts.map +1 -0
- package/dist/{index-BPSZ_Lp_.d.cts → EndpointFactory-B2dCS9dy.d.cts} +187 -104
- package/dist/EndpointFactory-B2dCS9dy.d.cts.map +1 -0
- package/dist/{EndpointFactory-Bm3aKRdV.mjs → EndpointFactory-C1NlpCAS.mjs} +269 -53
- package/dist/EndpointFactory-C1NlpCAS.mjs.map +1 -0
- package/dist/{index-BoZ-iisU.d.mts → EndpointFactory-D2HXcUrJ.d.mts} +188 -105
- package/dist/EndpointFactory-D2HXcUrJ.d.mts.map +1 -0
- package/dist/{EndpointFactory-CLvWuHyt.cjs → EndpointFactory-gqmIRVWg.cjs} +309 -51
- package/dist/EndpointFactory-gqmIRVWg.cjs.map +1 -0
- package/dist/Function-BIEsY0Hm.d.cts +76 -0
- package/dist/Function-BIEsY0Hm.d.cts.map +1 -0
- package/dist/Function-DfMzTGS4.d.mts +76 -0
- package/dist/Function-DfMzTGS4.d.mts.map +1 -0
- package/dist/{HonoEndpointAdaptor-92zavCsV.cjs → HonoEndpointAdaptor-BJlj20fQ.cjs} +79 -31
- package/dist/HonoEndpointAdaptor-BJlj20fQ.cjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-yYaU7jVJ.mjs → HonoEndpointAdaptor-BlbkUDNo.mjs} +76 -28
- package/dist/HonoEndpointAdaptor-BlbkUDNo.mjs.map +1 -0
- package/dist/ObjectSubscriberBuilder-BuuaYcrm.d.cts +129 -0
- package/dist/ObjectSubscriberBuilder-BuuaYcrm.d.cts.map +1 -0
- package/dist/ObjectSubscriberBuilder-CzgYmOUH.d.mts +129 -0
- package/dist/ObjectSubscriberBuilder-CzgYmOUH.d.mts.map +1 -0
- package/dist/ProcessorBuilder-B2_stA8f.d.mts +216 -0
- package/dist/ProcessorBuilder-B2_stA8f.d.mts.map +1 -0
- package/dist/ProcessorBuilder-C62bIOwj.d.cts +216 -0
- package/dist/ProcessorBuilder-C62bIOwj.d.cts.map +1 -0
- package/dist/{Queue-D9X6OoON.d.mts → Queue-BnK3UH8r.d.mts} +42 -41
- package/dist/Queue-BnK3UH8r.d.mts.map +1 -0
- package/dist/{Queue-DYPB2KWL.d.cts → Queue-C4rijiM7.d.cts} +43 -42
- package/dist/Queue-C4rijiM7.d.cts.map +1 -0
- package/dist/Queue-D4Iaidrs.cjs +109 -0
- package/dist/Queue-D4Iaidrs.cjs.map +1 -0
- package/dist/Queue-u8w8_HpE.mjs +104 -0
- package/dist/Queue-u8w8_HpE.mjs.map +1 -0
- package/dist/QueueBuilder-2wP5lEC8.mjs +118 -0
- package/dist/QueueBuilder-2wP5lEC8.mjs.map +1 -0
- package/dist/QueueBuilder-B3vL1ED2.d.mts +75 -0
- package/dist/QueueBuilder-B3vL1ED2.d.mts.map +1 -0
- package/dist/QueueBuilder-BcPBQSSX.d.cts +75 -0
- package/dist/QueueBuilder-BcPBQSSX.d.cts.map +1 -0
- package/dist/QueueBuilder-BxsZ9o5z.cjs +135 -0
- package/dist/QueueBuilder-BxsZ9o5z.cjs.map +1 -0
- package/dist/Subscriber-5rCX1Nph.d.cts +83 -0
- package/dist/Subscriber-5rCX1Nph.d.cts.map +1 -0
- package/dist/Subscriber-CW_Dl-YR.d.mts +83 -0
- package/dist/Subscriber-CW_Dl-YR.d.mts.map +1 -0
- package/dist/SubscriberBuilder-BL_GTcwh.mjs +237 -0
- package/dist/SubscriberBuilder-BL_GTcwh.mjs.map +1 -0
- package/dist/SubscriberBuilder-CWzKwX1p.cjs +260 -0
- package/dist/SubscriberBuilder-CWzKwX1p.cjs.map +1 -0
- package/dist/Topic-DN2gYJ-p.mjs +99 -0
- package/dist/Topic-DN2gYJ-p.mjs.map +1 -0
- package/dist/Topic-Dp9Q7Lj2.cjs +104 -0
- package/dist/Topic-Dp9Q7Lj2.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +134 -160
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +57 -48
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +58 -49
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +130 -157
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +1 -1
- package/dist/adaptors/hono.d.cts +5 -6
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +6 -7
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +1 -1
- package/dist/adaptors/testing.cjs +955 -38
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +437 -39
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +436 -38
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +929 -34
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth-BMCJN30Y.d.cts +268 -0
- package/dist/auth-BMCJN30Y.d.cts.map +1 -0
- package/dist/auth-D_0788uW.d.mts +268 -0
- package/dist/auth-D_0788uW.d.mts.map +1 -0
- package/dist/auth.cjs +290 -46
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -104
- package/dist/auth.d.mts +2 -104
- package/dist/auth.mjs +286 -48
- package/dist/auth.mjs.map +1 -1
- package/dist/cache-5QZzh5Er.d.mts +44 -0
- package/dist/cache-5QZzh5Er.d.mts.map +1 -0
- package/dist/cache-DnGDGly3.d.cts +44 -0
- package/dist/cache-DnGDGly3.d.cts.map +1 -0
- package/dist/cache.d.cts +2 -43
- package/dist/cache.d.mts +2 -43
- package/dist/cipher-C1lEFX63.mjs +225 -0
- package/dist/cipher-C1lEFX63.mjs.map +1 -0
- package/dist/cipher-CVxfwLjk.cjs +332 -0
- package/dist/cipher-CVxfwLjk.cjs.map +1 -0
- package/dist/cipher-DSDxPRIp.d.cts +106 -0
- package/dist/cipher-DSDxPRIp.d.cts.map +1 -0
- package/dist/cipher-DSDxPRIp.d.mts +106 -0
- package/dist/cipher-DSDxPRIp.d.mts.map +1 -0
- package/dist/{construct-interface-DPlxfpoS.d.mts → construct-interface-B1AfqRl4.d.cts} +42 -8
- package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
- package/dist/{construct-interface-DgXTJcOD.d.cts → construct-interface-ZvYQbivO.d.mts} +42 -8
- package/dist/construct-interface-ZvYQbivO.d.mts.map +1 -0
- package/dist/construct-interface.cjs +30 -4
- package/dist/construct-interface.cjs.map +1 -1
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +30 -5
- package/dist/construct-interface.mjs.map +1 -1
- package/dist/credential-DYymbp_7.cjs +257 -0
- package/dist/credential-DYymbp_7.cjs.map +1 -0
- package/dist/credential-DfSAOOdY.mjs +222 -0
- package/dist/credential-DfSAOOdY.mjs.map +1 -0
- package/dist/credential.cjs +7 -129
- package/dist/credential.d.cts +2 -58
- package/dist/credential.d.mts +2 -58
- package/dist/credential.mjs +2 -128
- package/dist/crons/index.cjs +126 -1
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +43 -3
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +43 -3
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +125 -2
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +3 -194
- package/dist/database/kysely.d.cts +2 -149
- package/dist/database/kysely.d.mts +2 -149
- package/dist/database/kysely.mjs +2 -192
- package/dist/email.d.cts +1 -1
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts +2 -2
- package/dist/email.d.mts.map +1 -1
- package/dist/encryption/kms.cjs +95 -0
- package/dist/encryption/kms.cjs.map +1 -0
- package/dist/encryption/kms.d.cts +7 -0
- package/dist/encryption/kms.d.cts.map +1 -0
- package/dist/encryption/kms.d.mts +7 -0
- package/dist/encryption/kms.d.mts.map +1 -0
- package/dist/encryption/kms.mjs +93 -0
- package/dist/encryption/kms.mjs.map +1 -0
- package/dist/encryption.cjs +116 -0
- package/dist/encryption.cjs.map +1 -0
- package/dist/encryption.d.cts +37 -0
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +37 -0
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +101 -0
- package/dist/encryption.mjs.map +1 -0
- package/dist/endpoints/index.cjs +32 -10
- package/dist/endpoints/index.d.cts +106 -3
- package/dist/endpoints/index.d.cts.map +1 -0
- package/dist/endpoints/index.d.mts +106 -3
- package/dist/endpoints/index.d.mts.map +1 -0
- package/dist/endpoints/index.mjs +6 -4
- package/dist/expire-C586zznE.d.cts +38 -0
- package/dist/expire-C586zznE.d.cts.map +1 -0
- package/dist/expire-C586zznE.d.mts +38 -0
- package/dist/expire-C586zznE.d.mts.map +1 -0
- package/dist/expire-CieftS01.cjs +67 -0
- package/dist/expire-CieftS01.cjs.map +1 -0
- package/dist/expire-CpzUAfr9.mjs +50 -0
- package/dist/expire-CpzUAfr9.mjs.map +1 -0
- package/dist/external-api.cjs +106 -0
- package/dist/external-api.cjs.map +1 -0
- package/dist/external-api.d.cts +2 -0
- package/dist/external-api.d.mts +2 -0
- package/dist/external-api.mjs +103 -0
- package/dist/external-api.mjs.map +1 -0
- package/dist/fake-BUgcX2Dk.d.cts +201 -0
- package/dist/fake-BUgcX2Dk.d.cts.map +1 -0
- package/dist/fake-D472nkKb.d.mts +201 -0
- package/dist/fake-D472nkKb.d.mts.map +1 -0
- package/dist/file-server.cjs +123 -30
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +115 -1
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +115 -1
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +122 -32
- package/dist/file-server.mjs.map +1 -1
- package/dist/functions/index.cjs +1 -1
- package/dist/functions/index.d.cts +2 -1
- package/dist/functions/index.d.mts +2 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/{functions-C53GW2eQ.mjs → functions-BvIDQKAA.mjs} +117 -22
- package/dist/functions-BvIDQKAA.mjs.map +1 -0
- package/dist/{functions-B6qCvfmy.cjs → functions-DLF6-IK8.cjs} +122 -18
- package/dist/functions-DLF6-IK8.cjs.map +1 -0
- package/dist/inbox-DZdICa8F.d.mts +195 -0
- package/dist/inbox-DZdICa8F.d.mts.map +1 -0
- package/dist/inbox-DqaxrpEk.d.cts +195 -0
- package/dist/inbox-DqaxrpEk.d.cts.map +1 -0
- package/dist/inbox.cjs +291 -0
- package/dist/inbox.cjs.map +1 -0
- package/dist/inbox.d.cts +2 -0
- package/dist/inbox.d.mts +2 -0
- package/dist/inbox.mjs +283 -0
- package/dist/inbox.mjs.map +1 -0
- package/dist/index-BtzMzhMA.d.cts +115 -0
- package/dist/index-BtzMzhMA.d.cts.map +1 -0
- package/dist/{index-CeEtxDmK.d.cts → index-DdRjYhiJ.d.cts} +42 -2
- package/dist/{index-CeEtxDmK.d.cts.map → index-DdRjYhiJ.d.cts.map} +1 -1
- package/dist/{index-CeEtxDmK.d.mts → index-DdRjYhiJ.d.mts} +42 -2
- package/dist/{index-CeEtxDmK.d.mts.map → index-DdRjYhiJ.d.mts.map} +1 -1
- package/dist/index-DuriFjYD.d.mts +115 -0
- package/dist/index-DuriFjYD.d.mts.map +1 -0
- package/dist/index.cjs +4 -1
- package/dist/index.d.cts +26 -3
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +26 -3
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -2
- package/dist/kysely-BHYV-WC-.d.cts +216 -0
- package/dist/kysely-BHYV-WC-.d.cts.map +1 -0
- package/dist/kysely-CAW3QSqp.d.mts +216 -0
- package/dist/kysely-CAW3QSqp.d.mts.map +1 -0
- package/dist/kysely-Cs4uPO8k.mjs +371 -0
- package/dist/kysely-Cs4uPO8k.mjs.map +1 -0
- package/dist/kysely-CukArHJ0.cjs +384 -0
- package/dist/kysely-CukArHJ0.cjs.map +1 -0
- package/dist/{telemetry-DGcFlVpB.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +2 -2
- package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
- package/dist/{telemetry-DGcFlVpB.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +2 -2
- package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
- package/dist/mobile-app.cjs +74 -0
- package/dist/mobile-app.cjs.map +1 -0
- package/dist/mobile-app.d.cts +73 -0
- package/dist/mobile-app.d.cts.map +1 -0
- package/dist/mobile-app.d.mts +73 -0
- package/dist/mobile-app.d.mts.map +1 -0
- package/dist/mobile-app.mjs +73 -0
- package/dist/mobile-app.mjs.map +1 -0
- package/dist/object-storage.cjs +8 -1
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +10 -1
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +10 -1
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +7 -2
- package/dist/object-storage.mjs.map +1 -1
- package/dist/pattern-C1CEcglD.mjs +241 -0
- package/dist/pattern-C1CEcglD.mjs.map +1 -0
- package/dist/pattern-QFaUIr77.cjs +288 -0
- package/dist/pattern-QFaUIr77.cjs.map +1 -0
- package/dist/processors/index.cjs +214 -0
- package/dist/processors/index.cjs.map +1 -0
- package/dist/processors/index.d.cts +78 -0
- package/dist/processors/index.d.cts.map +1 -0
- package/dist/processors/index.d.mts +78 -0
- package/dist/processors/index.d.mts.map +1 -0
- package/dist/processors/index.mjs +193 -0
- package/dist/processors/index.mjs.map +1 -0
- package/dist/queue/index.cjs +5 -192
- package/dist/queue/index.d.cts +3 -53
- package/dist/queue/index.d.mts +3 -53
- package/dist/queue/index.mjs +3 -190
- package/dist/random-password.cjs +86 -0
- package/dist/random-password.cjs.map +1 -0
- package/dist/random-password.d.cts +30 -0
- package/dist/random-password.d.cts.map +1 -0
- package/dist/random-password.d.mts +30 -0
- package/dist/random-password.d.mts.map +1 -0
- package/dist/random-password.mjs +84 -0
- package/dist/random-password.mjs.map +1 -0
- package/dist/{lazyAccessors-BHtcqgz2.mjs → readRequestBody-BTIl3k-D.mjs} +99 -39
- package/dist/readRequestBody-BTIl3k-D.mjs.map +1 -0
- package/dist/{lazyAccessors-Dx9NLwJZ.cjs → readRequestBody-Dej_L3c4.cjs} +118 -46
- package/dist/readRequestBody-Dej_L3c4.cjs.map +1 -0
- package/dist/requestLogger-BZcXwdBs.cjs +207 -0
- package/dist/requestLogger-BZcXwdBs.cjs.map +1 -0
- package/dist/requestLogger-pA4gi3E1.mjs +178 -0
- package/dist/requestLogger-pA4gi3E1.mjs.map +1 -0
- package/dist/rest-api.cjs +74 -70
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +69 -58
- package/dist/rest-api.d.cts.map +1 -1
- package/dist/rest-api.d.mts +69 -58
- package/dist/rest-api.d.mts.map +1 -1
- package/dist/rest-api.mjs +74 -70
- package/dist/rest-api.mjs.map +1 -1
- package/dist/runSubscriber-CC_2C9F2.cjs +133 -0
- package/dist/runSubscriber-CC_2C9F2.cjs.map +1 -0
- package/dist/runSubscriber-DyHWp_Lf.mjs +116 -0
- package/dist/runSubscriber-DyHWp_Lf.mjs.map +1 -0
- package/dist/shutdown-BMJmAhSt.cjs +38 -0
- package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
- package/dist/shutdown-C7xa8x9S.mjs +27 -0
- package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
- package/dist/site.cjs +64 -4
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +90 -1
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +90 -1
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +62 -6
- package/dist/site.mjs.map +1 -1
- package/dist/stages-DaTaoQei.d.cts +73 -0
- package/dist/stages-DaTaoQei.d.cts.map +1 -0
- package/dist/stages-DaTaoQei.d.mts +73 -0
- package/dist/stages-DaTaoQei.d.mts.map +1 -0
- package/dist/subscribers/index.cjs +134 -1
- package/dist/subscribers/index.cjs.map +1 -0
- package/dist/subscribers/index.d.cts +74 -3
- package/dist/subscribers/index.d.cts.map +1 -0
- package/dist/subscribers/index.d.mts +74 -3
- package/dist/subscribers/index.d.mts.map +1 -0
- package/dist/subscribers/index.mjs +132 -2
- package/dist/subscribers/index.mjs.map +1 -0
- package/dist/telemetry-B48RLjyk.d.cts +40 -0
- package/dist/telemetry-B48RLjyk.d.cts.map +1 -0
- package/dist/telemetry-BEoBn6GO.d.mts +40 -0
- package/dist/telemetry-BEoBn6GO.d.mts.map +1 -0
- package/dist/telemetry.cjs +56 -0
- package/dist/telemetry.cjs.map +1 -0
- package/dist/telemetry.d.cts +2 -0
- package/dist/telemetry.d.mts +2 -0
- package/dist/telemetry.mjs +55 -0
- package/dist/telemetry.mjs.map +1 -0
- package/dist/topic/index.cjs +2 -134
- package/dist/topic/index.d.cts +2 -3
- package/dist/topic/index.d.mts +2 -3
- package/dist/topic/index.mjs +2 -132
- package/dist/tracing-Bbj1uoFJ.mjs +127 -0
- package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
- package/dist/tracing-C0ooU0V2.cjs +150 -0
- package/dist/tracing-C0ooU0V2.cjs.map +1 -0
- package/dist/websocket-api.cjs +762 -0
- package/dist/websocket-api.cjs.map +1 -0
- package/dist/websocket-api.d.cts +443 -0
- package/dist/websocket-api.d.cts.map +1 -0
- package/dist/websocket-api.d.mts +443 -0
- package/dist/websocket-api.d.mts.map +1 -0
- package/dist/websocket-api.mjs +748 -0
- package/dist/websocket-api.mjs.map +1 -0
- package/dist/worker.cjs +140 -32
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +139 -47
- package/dist/worker.d.cts.map +1 -1
- package/dist/worker.d.mts +139 -47
- package/dist/worker.d.mts.map +1 -1
- package/dist/worker.mjs +141 -33
- package/dist/worker.mjs.map +1 -1
- package/package.json +155 -44
- package/dist/Construct-BeYVu_QF.mjs.map +0 -1
- package/dist/Construct-DfbwIntp.d.cts +0 -115
- package/dist/Construct-DfbwIntp.d.cts.map +0 -1
- package/dist/Construct-DqdlARxq.cjs.map +0 -1
- package/dist/Construct-l5aOn_jv.d.mts +0 -115
- package/dist/Construct-l5aOn_jv.d.mts.map +0 -1
- package/dist/Cron-DKqnnTdH.d.cts.map +0 -1
- package/dist/Cron-SyqS5oWJ.d.mts.map +0 -1
- package/dist/CronBuilder-BdnI6lxF.cjs.map +0 -1
- package/dist/CronBuilder-CRGnDfTq.d.mts +0 -41
- package/dist/CronBuilder-CRGnDfTq.d.mts.map +0 -1
- package/dist/CronBuilder-D_0HNBTr.mjs.map +0 -1
- package/dist/CronBuilder-Df1q9PNy.d.cts +0 -41
- package/dist/CronBuilder-Df1q9PNy.d.cts.map +0 -1
- package/dist/Endpoint-BpZHtJ2W.cjs +0 -1689
- package/dist/Endpoint-BpZHtJ2W.cjs.map +0 -1
- package/dist/Endpoint-C6yyHpRS.d.cts.map +0 -1
- package/dist/Endpoint-DuT4TEEq.d.mts.map +0 -1
- package/dist/Endpoint-ONsly_dq.mjs +0 -1671
- package/dist/Endpoint-ONsly_dq.mjs.map +0 -1
- package/dist/EndpointFactory-Bm3aKRdV.mjs.map +0 -1
- package/dist/EndpointFactory-CLvWuHyt.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-92zavCsV.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-yYaU7jVJ.mjs.map +0 -1
- package/dist/Queue-D9X6OoON.d.mts.map +0 -1
- package/dist/Queue-DYPB2KWL.d.cts.map +0 -1
- package/dist/Subscriber-C4heaAyO.d.mts +0 -51
- package/dist/Subscriber-C4heaAyO.d.mts.map +0 -1
- package/dist/Subscriber-CotDUELC.d.cts +0 -51
- package/dist/Subscriber-CotDUELC.d.cts.map +0 -1
- package/dist/SubscriberBuilder-BEv0eoHy.d.cts +0 -59
- package/dist/SubscriberBuilder-BEv0eoHy.d.cts.map +0 -1
- package/dist/SubscriberBuilder-C0ZEtGDI.cjs +0 -125
- package/dist/SubscriberBuilder-C0ZEtGDI.cjs.map +0 -1
- package/dist/SubscriberBuilder-h7B_cHMr.mjs +0 -114
- package/dist/SubscriberBuilder-h7B_cHMr.mjs.map +0 -1
- package/dist/SubscriberBuilder-tyH5yTk5.d.mts +0 -59
- package/dist/SubscriberBuilder-tyH5yTk5.d.mts.map +0 -1
- package/dist/Topic-DEVGo0Dm.d.cts +0 -89
- package/dist/Topic-DEVGo0Dm.d.cts.map +0 -1
- package/dist/Topic-zk_6Gthr.d.mts +0 -89
- package/dist/Topic-zk_6Gthr.d.mts.map +0 -1
- package/dist/auth.d.cts.map +0 -1
- package/dist/auth.d.mts.map +0 -1
- package/dist/cache.d.cts.map +0 -1
- package/dist/cache.d.mts.map +0 -1
- package/dist/construct-interface-DPlxfpoS.d.mts.map +0 -1
- package/dist/construct-interface-DgXTJcOD.d.cts.map +0 -1
- package/dist/credential.cjs.map +0 -1
- package/dist/credential.d.cts.map +0 -1
- package/dist/credential.d.mts.map +0 -1
- package/dist/credential.mjs.map +0 -1
- package/dist/database/kysely.cjs.map +0 -1
- package/dist/database/kysely.d.cts.map +0 -1
- package/dist/database/kysely.d.mts.map +0 -1
- package/dist/database/kysely.mjs.map +0 -1
- package/dist/functions-B6qCvfmy.cjs.map +0 -1
- package/dist/functions-C53GW2eQ.mjs.map +0 -1
- package/dist/index-B2urf3YI.d.cts +0 -26
- package/dist/index-B2urf3YI.d.cts.map +0 -1
- package/dist/index-BPSZ_Lp_.d.cts.map +0 -1
- package/dist/index-BoZ-iisU.d.mts.map +0 -1
- package/dist/index-CdaU--_B.d.cts +0 -165
- package/dist/index-CdaU--_B.d.cts.map +0 -1
- package/dist/index-DMCDvnsM.d.mts +0 -26
- package/dist/index-DMCDvnsM.d.mts.map +0 -1
- package/dist/index-PQRWOQj4.d.mts +0 -165
- package/dist/index-PQRWOQj4.d.mts.map +0 -1
- package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
- package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
- package/dist/processAudits-BpRlPQMW.mjs +0 -77
- package/dist/processAudits-BpRlPQMW.mjs.map +0 -1
- package/dist/processAudits-D_2W5x8k.cjs +0 -88
- package/dist/processAudits-D_2W5x8k.cjs.map +0 -1
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts.map +0 -1
- package/dist/queue/index.d.mts.map +0 -1
- package/dist/queue/index.mjs.map +0 -1
- package/dist/telemetry-DGcFlVpB.d.cts.map +0 -1
- package/dist/telemetry-DGcFlVpB.d.mts.map +0 -1
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-api.mjs","names":[],"sources":["../src/websocket/transport.ts","../src/websocket/publisher.ts","../src/websocket/route.ts","../src/websocket/server.ts","../src/websocket-api.ts"],"sourcesContent":["/**\n * How a send reaches the process holding the socket.\n *\n * A connection id names the process it lives on — `<instance>.<n>` — so a send\n * needs no registry: it is published to that instance's channel and nowhere\n * else. A broadcast goes to every instance. On a stack the channels are Redis\n * pub/sub, so an endpoint in another container reaches a socket the same way a\n * route beside it does; in one process (a test, a single dev server) they are\n * a map.\n */\n\n/** What one process is asked to do with the sockets it holds. */\nexport type Delivery =\n\t| { kind: 'send'; ids: readonly string[]; payload: string }\n\t| { kind: 'broadcast'; payload: string; except?: readonly string[] }\n\t| { kind: 'close'; ids: readonly string[]; code: number; reason: string };\n\nexport interface WebSocketTransport {\n\t/** Deliver to one instance, or to every instance when it is `'*'`. */\n\tpublish(instance: string, delivery: Delivery): Promise<void>;\n\t/** Receive what is published to `instance`, and every broadcast. */\n\tsubscribe(\n\t\tinstance: string,\n\t\treceive: (delivery: Delivery) => void,\n\t): Promise<void>;\n\tclose(): Promise<void>;\n}\n\n/** Every instance — what a broadcast is published to. */\nexport const EVERY_INSTANCE = '*';\n\n/** A connection string names no transport this package knows. */\nexport class UnsupportedWebSocketTransport extends Error {\n\tconstructor(readonly connectionString: string) {\n\t\tsuper(\n\t\t\t`'${redact(connectionString)}' is not a WebSocket publisher connection string. ` +\n\t\t\t\t'Use redis://, rediss:// or memory:// — gkm composes it as <ID>_PUBLISHER_CONNECTION_STRING.',\n\t\t);\n\t\tthis.name = 'UnsupportedWebSocketTransport';\n\t}\n}\n\n/** The scheme alone, so an error never prints a password. */\nfunction redact(connectionString: string): string {\n\tconst scheme = connectionString.split('://')[0];\n\treturn scheme && scheme !== connectionString\n\t\t? `${scheme}://…`\n\t\t: connectionString.slice(0, 12);\n}\n\n// On globalThis, as the shutdown hooks are: a package loaded as ESM and CJS\n// would otherwise hold two maps, and a publisher would talk to the empty one.\nconst key = Symbol.for('@geekmidas/constructs/websocket/memory');\nconst registry = globalThis as Record<\n\tsymbol,\n\tMap<string, Map<string, (delivery: Delivery) => void>> | undefined\n>;\nregistry[key] ??= new Map();\nconst channels = registry[key];\n\n/**\n * In one process: the server and whoever sends meet in a map, keyed by the\n * channel the connection string names.\n */\nexport class MemoryTransport implements WebSocketTransport {\n\tprivate readonly subscribed = new Set<string>();\n\n\tconstructor(private readonly channel: string) {}\n\n\tasync publish(instance: string, delivery: Delivery): Promise<void> {\n\t\tconst instances = channels.get(this.channel);\n\t\tif (!instances) return;\n\t\tif (instance === EVERY_INSTANCE) {\n\t\t\tfor (const receive of instances.values()) receive(delivery);\n\t\t\treturn;\n\t\t}\n\t\tinstances.get(instance)?.(delivery);\n\t}\n\n\tasync subscribe(\n\t\tinstance: string,\n\t\treceive: (delivery: Delivery) => void,\n\t): Promise<void> {\n\t\tlet instances = channels.get(this.channel);\n\t\tif (!instances) {\n\t\t\tinstances = new Map();\n\t\t\tchannels.set(this.channel, instances);\n\t\t}\n\t\tinstances.set(instance, receive);\n\t\tthis.subscribed.add(instance);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst instances = channels.get(this.channel);\n\t\tfor (const instance of this.subscribed) instances?.delete(instance);\n\t\tthis.subscribed.clear();\n\t}\n}\n\n/** The subset of an ioredis client the transport uses. */\ninterface RedisClient {\n\tpublish(channel: string, message: string): Promise<number>;\n\tsubscribe(...channels: string[]): Promise<unknown>;\n\ton(\n\t\tevent: 'message',\n\t\tlistener: (channel: string, message: string) => void,\n\t): unknown;\n\tduplicate(): RedisClient;\n\tquit(): Promise<unknown>;\n}\n\n/**\n * Over Redis pub/sub: one channel per instance and one for broadcasts, under\n * a prefix that keeps two surfaces — or two projects on one Redis — apart.\n * Channels are not scoped by database index, so the prefix is what does it.\n *\n * Publishing and subscribing take separate connections, because a connection\n * that has subscribed can do nothing else.\n */\nexport class RedisTransport implements WebSocketTransport {\n\tprivate subscriber?: RedisClient;\n\tprivate closed?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly client: RedisClient,\n\t\tprivate readonly prefix: string,\n\t) {}\n\n\tprivate channel(instance: string): string {\n\t\treturn `${this.prefix}:${instance}`;\n\t}\n\n\tasync publish(instance: string, delivery: Delivery): Promise<void> {\n\t\tawait this.client.publish(this.channel(instance), JSON.stringify(delivery));\n\t}\n\n\tasync subscribe(\n\t\tinstance: string,\n\t\treceive: (delivery: Delivery) => void,\n\t): Promise<void> {\n\t\tconst subscriber = this.client.duplicate();\n\t\tthis.subscriber = subscriber;\n\t\tconst own = this.channel(instance);\n\t\tconst every = this.channel(EVERY_INSTANCE);\n\t\tsubscriber.on('message', (channel, message) => {\n\t\t\tif (channel !== own && channel !== every) return;\n\t\t\treceive(JSON.parse(message) as Delivery);\n\t\t});\n\t\tawait subscriber.subscribe(own, every);\n\t}\n\n\t/** Idempotent: the server and a shutdown hook may both close it. */\n\tclose(): Promise<void> {\n\t\tthis.closed ??= Promise.all([\n\t\t\tthis.subscriber?.quit(),\n\t\t\tthis.client.quit(),\n\t\t]).then(() => undefined);\n\t\treturn this.closed;\n\t}\n}\n\n/**\n * The transport a connection string names.\n *\n * `redis://` and `rediss://` take an optional `channel` query parameter, the\n * prefix every channel is named under; `memory://<channel>` is in-process.\n * Absent, the channel is `fallback` — the surface's own.\n */\nexport async function transportFromConnectionString(\n\tconnectionString: string,\n\tfallback: string,\n): Promise<WebSocketTransport> {\n\t// Not parsed as a URL: a channel is `gkm:ws:<id>`, colons and all.\n\tif (connectionString.startsWith('memory://')) {\n\t\treturn new MemoryTransport(\n\t\t\tconnectionString.slice('memory://'.length) || fallback,\n\t\t);\n\t}\n\n\tconst url = URL.canParse(connectionString)\n\t\t? new URL(connectionString)\n\t\t: undefined;\n\tif (!url) throw new UnsupportedWebSocketTransport(connectionString);\n\n\tif (url.protocol === 'redis:' || url.protocol === 'rediss:') {\n\t\tconst channel = url.searchParams.get('channel') || fallback;\n\t\turl.searchParams.delete('channel');\n\t\tconst { Redis } = await import('ioredis');\n\t\tconst client = new Redis(url.toString(), {\n\t\t\t// A publish while Redis restarts waits for it rather than failing the\n\t\t\t// request that sent it.\n\t\t\tmaxRetriesPerRequest: null,\n\t\t\tlazyConnect: false,\n\t\t});\n\t\treturn new RedisTransport(client as unknown as RedisClient, channel);\n\t}\n\n\tthrow new UnsupportedWebSocketTransport(connectionString);\n}\n","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Delivery,\n\tEVERY_INSTANCE,\n\ttype WebSocketTransport,\n} from './transport';\n\n/** The instance a connection id was issued by: everything before its dot. */\nexport function instanceOf(connectionId: string): string | undefined {\n\tconst dot = connectionId.indexOf('.');\n\treturn dot > 0 ? connectionId.slice(0, dot) : undefined;\n}\n\n/**\n * What a surface sends its sockets, by action — `WebSocketApiConfig.messages`.\n */\nexport type WebSocketMessages = Record<string, StandardSchemaV1>;\n\n/** A surface that declares no messages: any action, any data. */\nexport type NoMessages = Record<never, never>;\n\n/** The actions a publisher sends: the declared ones, or any. */\nexport type MessageAction<TMessages extends WebSocketMessages> = [\n\tkeyof TMessages,\n] extends [never]\n\t? string\n\t: keyof TMessages & string;\n\n/** What `action`'s data is, as its schema takes it. */\nexport type MessageData<\n\tTMessages extends WebSocketMessages,\n\tTAction extends string,\n> = TAction extends keyof TMessages\n\t? StandardSchemaV1.InferInput<TMessages[TAction]>\n\t: unknown;\n\n/** A message sent on an action the surface does not declare. */\nexport class UnknownWebSocketMessage extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly action: string,\n\t\treadonly declared: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`${surface} sends no '${action}' message. It declares ${declared\n\t\t\t\t.map((a) => `'${a}'`)\n\t\t\t\t.join(', ')} — send one of them, or add '${action}' to its messages.`,\n\t\t);\n\t\tthis.name = 'UnknownWebSocketMessage';\n\t}\n}\n\n/** A message whose data its action's schema refused. */\nexport class InvalidWebSocketMessage extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly action: string,\n\t\treadonly issues: readonly StandardSchemaV1.Issue[],\n\t) {\n\t\tsuper(\n\t\t\t`${surface}'s '${action}' message was refused by its schema: ${issues\n\t\t\t\t.map((issue) => issue.message)\n\t\t\t\t.join('; ')}. Nothing was sent.`,\n\t\t);\n\t\tthis.name = 'InvalidWebSocketMessage';\n\t}\n}\n\n/**\n * How anything reaches a socket — `services.realtime` in an endpoint, and\n * `sockets` in a route of the surface itself.\n *\n * A message is `{ action, data }`, the shape a client's frames arrive in.\n * Where the surface declares its messages, `action` is one of them and\n * `data` is typed and checked by its schema before anything is sent; where it\n * declares none, any action and any JSON value go. A message is serialised\n * once, whatever the number of sockets it goes to. An id whose process has\n * gone is dropped silently, as API Gateway's `postToConnection` to a closed\n * connection is a no-op the sender rarely wants to handle.\n */\nexport class WebSocketPublisher<\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\tconstructor(\n\t\tprivate readonly transport: WebSocketTransport,\n\t\t/**\n\t\t * Delivers to this process's own sockets without a round trip through\n\t\t * the transport — set on the server's own publisher.\n\t\t */\n\t\tprivate readonly local?: {\n\t\t\tinstance: string;\n\t\t\tdeliver(delivery: Delivery): void;\n\t\t},\n\t\t/** The surface's declared messages, which every send is checked by. */\n\t\tprivate readonly declared?: { surface: string; messages: TMessages },\n\t) {}\n\n\t/** Send `action`'s message to each connection. */\n\tasync send<TAction extends MessageAction<TMessages>>(\n\t\tids: string | readonly string[],\n\t\taction: TAction,\n\t\tdata: MessageData<TMessages, TAction>,\n\t): Promise<void> {\n\t\tconst payload = await this.payload(action, data);\n\t\tawait this.each(ids, (group) => ({ kind: 'send', ids: group, payload }));\n\t}\n\n\t/** Send `action`'s message to every open connection, on every process. */\n\tasync broadcast<TAction extends MessageAction<TMessages>>(\n\t\taction: TAction,\n\t\tdata: MessageData<TMessages, TAction>,\n\t\toptions: { except?: readonly string[] } = {},\n\t): Promise<void> {\n\t\tconst payload = await this.payload(action, data);\n\t\tawait this.transport.publish(EVERY_INSTANCE, {\n\t\t\tkind: 'broadcast',\n\t\t\tpayload,\n\t\t\t...(options.except?.length ? { except: options.except } : {}),\n\t\t});\n\t}\n\n\t/** Close each connection, with a close code and reason its client sees. */\n\tasync close(\n\t\tids: string | readonly string[],\n\t\tcode = 1000,\n\t\treason = '',\n\t): Promise<void> {\n\t\tawait this.each(ids, (group) => ({\n\t\t\tkind: 'close',\n\t\t\tids: group,\n\t\t\tcode,\n\t\t\treason,\n\t\t}));\n\t}\n\n\t/**\n\t * The frame, checked by the action's schema where the surface declares\n\t * its messages.\n\t *\n\t * @throws {UnknownWebSocketMessage}, {InvalidWebSocketMessage}\n\t */\n\tprivate async payload(action: string, data: unknown): Promise<string> {\n\t\tif (!this.declared) return JSON.stringify({ action, data });\n\n\t\tconst { surface, messages } = this.declared;\n\t\tconst schema = messages[action];\n\t\tif (!schema) {\n\t\t\tthrow new UnknownWebSocketMessage(surface, action, Object.keys(messages));\n\t\t}\n\t\tconst result = await schema['~standard'].validate(data);\n\t\tif (result.issues) {\n\t\t\tthrow new InvalidWebSocketMessage(surface, action, result.issues);\n\t\t}\n\t\treturn JSON.stringify({ action, data: result.value });\n\t}\n\n\t/** One delivery per process that holds any of `ids`. */\n\tprivate async each(\n\t\tids: string | readonly string[],\n\t\tdelivery: (group: string[]) => Delivery,\n\t): Promise<void> {\n\t\tconst byInstance = new Map<string, string[]>();\n\t\tfor (const id of typeof ids === 'string' ? [ids] : ids) {\n\t\t\tconst instance = instanceOf(id);\n\t\t\tif (!instance) continue;\n\t\t\tconst group = byInstance.get(instance) ?? [];\n\t\t\tgroup.push(id);\n\t\t\tbyInstance.set(instance, group);\n\t\t}\n\n\t\tawait Promise.all(\n\t\t\t[...byInstance].map(([instance, group]) =>\n\t\t\t\tthis.local?.instance === instance\n\t\t\t\t\t? this.local.deliver(delivery(group))\n\t\t\t\t\t: this.transport.publish(instance, delivery(group)),\n\t\t\t),\n\t\t);\n\t}\n}\n","import type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\tidsOf,\n\ttype ServicesOf,\n\tservicesOf,\n} from '../construct-interface';\nimport type {\n\tNoMessages,\n\tWebSocketMessages,\n\tWebSocketPublisher,\n} from './publisher';\n\n/** One open connection, as a handler sees it. */\nexport interface Connection {\n\treadonly id: string;\n\t/**\n\t * What the connect handler returned — who the connection is for, the room\n\t * it joined. `{}` when it returned nothing.\n\t */\n\treadonly data: Record<string, unknown>;\n}\n\ninterface BaseContext<\n\tTServices extends Service[],\n\tTMessages extends WebSocketMessages,\n> {\n\tservices: ServiceRecord<TServices>;\n\tlogger: Logger;\n\t/** Every socket this surface holds, on whichever process holds it. */\n\tsockets: WebSocketPublisher<TMessages>;\n}\n\nexport interface ConnectContext<\n\tTServices extends Service[],\n\tTMessages extends WebSocketMessages = NoMessages,\n> extends BaseContext<TServices, TMessages> {\n\tconnectionId: string;\n\theaders: Headers;\n\tquery: URLSearchParams;\n\t/**\n\t * Whose connection it is, from the surface's `.auth()` — `null` when the\n\t * upgrade carried no session, and when the surface names no authenticator.\n\t * Throw an `UnauthorizedError` to refuse it.\n\t */\n\tsession: unknown;\n}\n\nexport interface MessageContext<\n\tTBody,\n\tTServices extends Service[],\n\tTMessages extends WebSocketMessages = NoMessages,\n> extends BaseContext<TServices, TMessages> {\n\tconnection: Connection;\n\tbody: TBody;\n\t/** Send to this connection alone. */\n\treply(message: unknown): void;\n}\n\nexport interface DisconnectContext<\n\tTServices extends Service[],\n\tTMessages extends WebSocketMessages = NoMessages,\n> extends BaseContext<TServices, TMessages> {\n\tconnection: Connection;\n\tcode: number;\n\treason: string;\n}\n\n/** What a frame is dispatched on: an action, or the connection's lifecycle. */\nexport type RouteKind = 'connect' | 'disconnect' | 'message';\n\n/**\n * A handler bound to a WebSocket surface — what `realtime.route('chat.send')\n * …handle()` returns, and what a file exports.\n *\n * Carries `surface` and `constructs` the way an endpoint does, so discovery\n * records what its process reaches without knowing what a route is.\n */\nexport class WebSocketRoute {\n\treadonly __IS_WEBSOCKET_ROUTE__ = true;\n\n\tstatic isRoute(value: unknown): value is WebSocketRoute {\n\t\treturn Boolean(\n\t\t\tvalue &&\n\t\t\t\t(value as { __IS_WEBSOCKET_ROUTE__?: unknown })\n\t\t\t\t\t.__IS_WEBSOCKET_ROUTE__ === true,\n\t\t);\n\t}\n\n\tconstructor(\n\t\treadonly kind: RouteKind,\n\t\t/** The `action` it answers; `$connect` and `$disconnect` for the lifecycle. */\n\t\treadonly action: string,\n\t\treadonly surface: { id: string },\n\t\treadonly services: readonly Service[],\n\t\t/** Construct ids it depends on — its edges in the manifest. */\n\t\treadonly constructs: readonly string[],\n\t\treadonly handler: (context: never) => unknown,\n\t\treadonly schema?: StandardSchemaV1,\n\t) {}\n}\n\n/** The builder `connect()`, `disconnect()` and `route()` start. */\nexport class WebSocketRouteBuilder<\n\tTKind extends RouteKind,\n\tTSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\t/** The surface's declared messages, which `sockets` sends. */\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\tconstructor(\n\t\tprivate readonly kind: TKind,\n\t\tprivate readonly action: string,\n\t\tprivate readonly surface: { id: string },\n\t\tprivate readonly _services: readonly Service[] = [],\n\t\tprivate readonly _constructs: readonly string[] = [],\n\t\tprivate readonly schema?: TSchema,\n\t) {}\n\n\t/** The schema a frame's `data` must satisfy before the handler runs. */\n\tbody<S extends StandardSchemaV1>(\n\t\tschema: S,\n\t): WebSocketRouteBuilder<TKind, S, TServices, TMessages> {\n\t\treturn new WebSocketRouteBuilder(\n\t\t\tthis.kind,\n\t\t\tthis.action,\n\t\t\tthis.surface,\n\t\t\tthis._services,\n\t\t\tthis._constructs,\n\t\t\tschema,\n\t\t);\n\t}\n\n\t/** What the handler reaches, as `services.<id>` — per route, as an endpoint's. */\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): WebSocketRouteBuilder<\n\t\tTKind,\n\t\tTSchema,\n\t\t[...TServices, ...(ServicesOf<T> extends Service[] ? ServicesOf<T> : [])],\n\t\tTMessages\n\t> {\n\t\treturn new WebSocketRouteBuilder(\n\t\t\tthis.kind,\n\t\t\tthis.action,\n\t\t\tthis.surface,\n\t\t\t[...this._services, ...(servicesOf(constructs) as Service[])],\n\t\t\tidsOf(constructs, this._constructs),\n\t\t\tthis.schema,\n\t\t) as never;\n\t}\n\n\t/**\n\t * The handler. A message handler's return value, when there is one, is\n\t * sent back to the connection as the reply to that frame; a connect\n\t * handler's is kept as the connection's `data`.\n\t */\n\thandle(\n\t\thandler: TKind extends 'connect'\n\t\t\t? (\n\t\t\t\t\tcontext: ConnectContext<TServices, TMessages>,\n\t\t\t\t) =>\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined\n\t\t\t\t\t| Promise<Record<string, unknown> | undefined>\n\t\t\t: TKind extends 'disconnect'\n\t\t\t\t? (context: DisconnectContext<TServices, TMessages>) => unknown\n\t\t\t\t: (\n\t\t\t\t\t\tcontext: MessageContext<\n\t\t\t\t\t\t\tTSchema extends StandardSchemaV1\n\t\t\t\t\t\t\t\t? InferStandardSchema<TSchema>\n\t\t\t\t\t\t\t\t: unknown,\n\t\t\t\t\t\t\tTServices,\n\t\t\t\t\t\t\tTMessages\n\t\t\t\t\t\t>,\n\t\t\t\t\t) => unknown,\n\t): WebSocketRoute {\n\t\treturn new WebSocketRoute(\n\t\t\tthis.kind,\n\t\t\tthis.action,\n\t\t\tthis.surface,\n\t\t\tthis._services,\n\t\t\tthis._constructs,\n\t\t\thandler as (context: never) => unknown,\n\t\t\tthis.schema,\n\t\t);\n\t}\n}\n","/**\n * The process that holds a WebSocket surface's sockets.\n *\n * Node's own `http` server and `ws`, nothing between them: a frame is parsed,\n * validated and handed to its route, and that is the whole hot path. The HTTP\n * server is whatever the entry started — the generated one serves `/health`\n * on the same port — and this attaches to its `upgrade` event.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport type { IncomingMessage, Server } from 'node:http';\nimport type { Duplex } from 'node:stream';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport { HttpError } from '@geekmidas/errors';\nimport type { Logger } from '@geekmidas/logger';\nimport { trustsOrigin } from '@geekmidas/manifest';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport type { WebSocket, WebSocketServer } from 'ws';\nimport type { Authenticator } from '../construct-interface';\nimport {\n\ttype NoMessages,\n\ttype WebSocketMessages,\n\tWebSocketPublisher,\n} from './publisher';\nimport type { Connection, WebSocketRoute } from './route';\nimport type { Delivery, WebSocketTransport } from './transport';\n\n/** Close codes a client sees. */\nexport const CLOSE = {\n\tnormal: 1000,\n\t/** The process is stopping; reconnect and land on another. */\n\tserviceRestart: 1012,\n\t/** It stopped reading, and what was queued for it passed the limit. */\n\ttooSlow: 1013,\n} as const;\n\n/** A frame a client sends: `{ \"action\": \"chat.send\", \"id\": 1, \"data\": … }`. */\ninterface InboundFrame {\n\taction: string;\n\t/** Echoed on the reply, so a client can pair them. */\n\tid?: string | number;\n\tdata?: unknown;\n}\n\n/** Two routes answer one action. */\nexport class DuplicateWebSocketRoute extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly action: string,\n\t) {\n\t\tsuper(\n\t\t\t`Two routes on ${surface} answer '${action}'. Each action has one handler — rename one of them.`,\n\t\t);\n\t\tthis.name = 'DuplicateWebSocketRoute';\n\t}\n}\n\nexport interface WebSocketServerOptions<\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\tsurface: string;\n\t/** What the surface sends its sockets — see `WebSocketApiConfig.messages`. */\n\tmessages?: TMessages;\n\troutes: readonly WebSocketRoute[];\n\ttransport: WebSocketTransport;\n\tenvParser: EnvironmentParser<{}>;\n\tlogger: Logger;\n\tauthenticator?: Authenticator;\n\t/**\n\t * Origins a browser may open a socket from. A request with an `Origin`\n\t * not in the list is refused with 403; one with none — a server, a load\n\t * generator — is not a browser, and is let through.\n\t */\n\ttrustedOrigins: readonly string[];\n\t/** How often each socket is pinged; one that missed the last is dropped. */\n\theartbeatMs?: number;\n\t/** The largest frame accepted, in bytes. */\n\tmaxPayload?: number;\n\t/** Queued bytes a socket may hold before it is closed as too slow. */\n\tmaxBufferedBytes?: number;\n}\n\ninterface Held {\n\tsocket: WebSocket;\n\tconnection: Connection;\n\talive: boolean;\n}\n\nexport class WebSocketSurfaceServer<\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\t/** This process, as connection ids name it. */\n\treadonly instance = randomBytes(6).toString('hex');\n\t/** `sockets` in a route: local sends skip the transport. */\n\treadonly publisher: WebSocketPublisher<TMessages>;\n\n\tprivate readonly held = new Map<string, Held>();\n\tprivate readonly routes = new Map<string, WebSocketRoute>();\n\tprivate readonly lifecycle: {\n\t\tconnect?: WebSocketRoute;\n\t\tdisconnect?: WebSocketRoute;\n\t} = {};\n\tprivate readonly heartbeat: NodeJS.Timeout;\n\tprivate next = 0;\n\tprivate closing = false;\n\n\tprivate constructor(\n\t\tprivate readonly wss: WebSocketServer,\n\t\tprivate readonly options: WebSocketServerOptions<TMessages>,\n\t) {\n\t\tfor (const route of options.routes) {\n\t\t\tif (route.surface.id !== options.surface) continue;\n\t\t\tif (route.kind === 'message') {\n\t\t\t\tif (this.routes.has(route.action)) {\n\t\t\t\t\tthrow new DuplicateWebSocketRoute(options.surface, route.action);\n\t\t\t\t}\n\t\t\t\tthis.routes.set(route.action, route);\n\t\t\t} else {\n\t\t\t\tif (this.lifecycle[route.kind]) {\n\t\t\t\t\tthrow new DuplicateWebSocketRoute(options.surface, route.action);\n\t\t\t\t}\n\t\t\t\tthis.lifecycle[route.kind] = route;\n\t\t\t}\n\t\t}\n\n\t\tthis.publisher = new WebSocketPublisher<TMessages>(\n\t\t\toptions.transport,\n\t\t\t{\n\t\t\t\tinstance: this.instance,\n\t\t\t\tdeliver: (delivery) => this.deliver(delivery),\n\t\t\t},\n\t\t\toptions.messages\n\t\t\t\t? { surface: options.surface, messages: options.messages }\n\t\t\t\t: undefined,\n\t\t);\n\n\t\tthis.heartbeat = setInterval(\n\t\t\t() => this.beat(),\n\t\t\toptions.heartbeatMs ?? 30_000,\n\t\t);\n\t\tthis.heartbeat.unref();\n\t}\n\n\tstatic async start<TMessages extends WebSocketMessages = NoMessages>(\n\t\toptions: WebSocketServerOptions<TMessages>,\n\t): Promise<WebSocketSurfaceServer<TMessages>> {\n\t\tconst { WebSocketServer } = await import('ws');\n\t\tconst wss = new WebSocketServer({\n\t\t\tnoServer: true,\n\t\t\tmaxPayload: options.maxPayload ?? 1024 * 1024,\n\t\t\t// Compression costs a zlib context per socket — tens of KB each,\n\t\t\t// the largest share of a connection's memory — for frames that are\n\t\t\t// mostly small JSON.\n\t\t\tperMessageDeflate: false,\n\t\t\tclientTracking: false,\n\t\t});\n\t\tconst server = new WebSocketSurfaceServer<TMessages>(wss, options);\n\t\tawait options.transport.subscribe(server.instance, (delivery) =>\n\t\t\tserver.deliver(delivery),\n\t\t);\n\t\treturn server;\n\t}\n\n\t/** How many sockets this process holds. */\n\tget size(): number {\n\t\treturn this.held.size;\n\t}\n\n\t/** Take over `server`'s upgrades. */\n\tattach(server: Server): void {\n\t\tserver.on('upgrade', (request, socket, head) => {\n\t\t\tvoid this.upgrade(request, socket, head);\n\t\t});\n\t}\n\n\t/** Upgrade one request, or refuse it with a status line. */\n\tasync upgrade(\n\t\trequest: IncomingMessage,\n\t\tsocket: Duplex,\n\t\thead: Buffer,\n\t): Promise<void> {\n\t\tif (this.closing) return refuse(socket, 503, 'Service Unavailable');\n\n\t\tconst origin = request.headers.origin;\n\t\tif (origin && !trustsOrigin(origin, this.options.trustedOrigins)) {\n\t\t\treturn refuse(socket, 403, 'Forbidden');\n\t\t}\n\n\t\tconst connectionId = `${this.instance}.${(this.next++).toString(36)}`;\n\t\tconst headers = headersOf(request);\n\t\tlet data: Record<string, unknown> = {};\n\n\t\tconst connect = this.lifecycle.connect;\n\t\tif (connect) {\n\t\t\ttry {\n\t\t\t\tconst session = this.options.authenticator\n\t\t\t\t\t? await this.options.authenticator.verify(\n\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\tthis.options.envParser,\n\t\t\t\t\t\t)\n\t\t\t\t\t: null;\n\t\t\t\tconst returned = await this.run(connect, connectionId, (base) => ({\n\t\t\t\t\t...base,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\theaders,\n\t\t\t\t\tquery: new URL(request.url ?? '/', 'http://localhost').searchParams,\n\t\t\t\t\tsession,\n\t\t\t\t}));\n\t\t\t\tif (returned && typeof returned === 'object') {\n\t\t\t\t\tdata = returned as Record<string, unknown>;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof HttpError) {\n\t\t\t\t\treturn refuse(socket, error.statusCode, error.statusMessage);\n\t\t\t\t}\n\t\t\t\tthis.options.logger.error(\n\t\t\t\t\t{ err: error, connectionId },\n\t\t\t\t\t'WebSocket connect handler failed',\n\t\t\t\t);\n\t\t\t\treturn refuse(socket, 500, 'Internal Server Error');\n\t\t\t}\n\t\t}\n\n\t\t// The client may have gone while the connect handler ran.\n\t\tif (socket.destroyed) return;\n\n\t\tthis.wss.handleUpgrade(request, socket, head, (ws) =>\n\t\t\tthis.open(ws, { id: connectionId, data }),\n\t\t);\n\t}\n\n\tprivate open(socket: WebSocket, connection: Connection): void {\n\t\tconst held: Held = { socket, connection, alive: true };\n\t\tthis.held.set(connection.id, held);\n\n\t\tsocket.on('pong', () => {\n\t\t\theld.alive = true;\n\t\t});\n\t\tsocket.on('message', (raw, isBinary) => {\n\t\t\theld.alive = true;\n\t\t\tif (isBinary) {\n\t\t\t\treturn this.error(held, undefined, 'Frames are JSON text.');\n\t\t\t}\n\t\t\tvoid this.dispatch(held, raw.toString());\n\t\t});\n\t\tsocket.on('error', () => socket.terminate());\n\t\tsocket.on('close', (code, reason) => {\n\t\t\tthis.held.delete(connection.id);\n\t\t\tconst disconnect = this.lifecycle.disconnect;\n\t\t\tif (!disconnect) return;\n\t\t\tvoid this.run(disconnect, connection.id, (base) => ({\n\t\t\t\t...base,\n\t\t\t\tconnection,\n\t\t\t\tcode,\n\t\t\t\treason: reason.toString(),\n\t\t\t})).catch((error) =>\n\t\t\t\tthis.options.logger.error(\n\t\t\t\t\t{ err: error, connectionId: connection.id },\n\t\t\t\t\t'WebSocket disconnect handler failed',\n\t\t\t\t),\n\t\t\t);\n\t\t});\n\t}\n\n\t/** Parse, validate and run one frame. Errors go back as frames, not closes. */\n\tprivate async dispatch(held: Held, text: string): Promise<void> {\n\t\tlet frame: InboundFrame;\n\t\ttry {\n\t\t\tframe = JSON.parse(text);\n\t\t} catch {\n\t\t\treturn this.error(held, undefined, 'Frames are JSON.');\n\t\t}\n\t\tif (!frame || typeof frame.action !== 'string') {\n\t\t\treturn this.error(held, frame?.id, 'A frame names its `action`.');\n\t\t}\n\n\t\tconst route = this.routes.get(frame.action) ?? this.routes.get('$default');\n\t\tif (!route) {\n\t\t\treturn this.error(held, frame.id, `No route answers '${frame.action}'.`);\n\t\t}\n\n\t\tlet body = frame.data;\n\t\tif (route.schema) {\n\t\t\tconst result = await route.schema['~standard'].validate(frame.data);\n\t\t\tif (result.issues) {\n\t\t\t\treturn this.error(\n\t\t\t\t\theld,\n\t\t\t\t\tframe.id,\n\t\t\t\t\t'The frame was invalid.',\n\t\t\t\t\tresult.issues,\n\t\t\t\t);\n\t\t\t}\n\t\t\tbody = result.value;\n\t\t}\n\n\t\ttry {\n\t\t\tconst returned = await this.run(route, held.connection.id, (base) => ({\n\t\t\t\t...base,\n\t\t\t\tconnection: held.connection,\n\t\t\t\tbody,\n\t\t\t\treply: (message: unknown) => this.write(held, JSON.stringify(message)),\n\t\t\t}));\n\t\t\tif (returned !== undefined) {\n\t\t\t\tthis.write(\n\t\t\t\t\theld,\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\taction: frame.action,\n\t\t\t\t\t\t...(frame.id !== undefined ? { id: frame.id } : {}),\n\t\t\t\t\t\tdata: returned,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof HttpError) {\n\t\t\t\treturn this.error(held, frame.id, error.message);\n\t\t\t}\n\t\t\tthis.options.logger.error(\n\t\t\t\t{ err: error, connectionId: held.connection.id, action: frame.action },\n\t\t\t\t'WebSocket route failed',\n\t\t\t);\n\t\t\tthis.error(held, frame.id, 'The route failed.');\n\t\t}\n\t}\n\n\t/** Run a handler with its services, inside a request context of its own. */\n\tprivate async run(\n\t\troute: WebSocketRoute,\n\t\tconnectionId: string,\n\t\tcontext: (base: {\n\t\t\tservices: unknown;\n\t\t\tlogger: Logger;\n\t\t\tsockets: WebSocketPublisher<TMessages>;\n\t\t}) => object,\n\t): Promise<unknown> {\n\t\tconst logger = this.options.logger.child({\n\t\t\tconnectionId,\n\t\t\taction: route.action,\n\t\t});\n\t\treturn runWithRequestContext(\n\t\t\t{\n\t\t\t\tlogger,\n\t\t\t\trequestId: connectionId,\n\t\t\t\tstartTime: Date.now(),\n\t\t\t\toperation: `ws ${route.action}`,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst services = route.services.length\n\t\t\t\t\t? await ServiceDiscovery.getInstance(this.options.envParser).register(\n\t\t\t\t\t\t\t[...route.services],\n\t\t\t\t\t\t)\n\t\t\t\t\t: {};\n\t\t\t\treturn (route.handler as (context: object) => unknown)(\n\t\t\t\t\tcontext({ services, logger, sockets: this.publisher }),\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate error(\n\t\theld: Held,\n\t\tid: InboundFrame['id'],\n\t\tmessage: string,\n\t\tissues?: unknown,\n\t): void {\n\t\tthis.write(\n\t\t\theld,\n\t\t\tJSON.stringify({\n\t\t\t\taction: '$error',\n\t\t\t\t...(id !== undefined ? { id } : {}),\n\t\t\t\tdata: { message, ...(issues ? { issues } : {}) },\n\t\t\t}),\n\t\t);\n\t}\n\n\t/** Write, unless the socket has stopped reading and its queue is full. */\n\tprivate write(held: Held, payload: string): void {\n\t\tconst { socket } = held;\n\t\tif (socket.readyState !== socket.OPEN) return;\n\t\tif (\n\t\t\tsocket.bufferedAmount > (this.options.maxBufferedBytes ?? 4 * 1024 * 1024)\n\t\t) {\n\t\t\tsocket.close(CLOSE.tooSlow, 'Too slow');\n\t\t\treturn;\n\t\t}\n\t\tsocket.send(payload);\n\t}\n\n\t/** What the transport, or a local publisher, asked of this process. */\n\tprivate deliver(delivery: Delivery): void {\n\t\tswitch (delivery.kind) {\n\t\t\tcase 'send':\n\t\t\t\tfor (const id of delivery.ids) {\n\t\t\t\t\tconst held = this.held.get(id);\n\t\t\t\t\tif (held) this.write(held, delivery.payload);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\tcase 'broadcast': {\n\t\t\t\tconst except = delivery.except ? new Set(delivery.except) : undefined;\n\t\t\t\tfor (const [id, held] of this.held) {\n\t\t\t\t\tif (!except?.has(id)) this.write(held, delivery.payload);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'close':\n\t\t\t\tfor (const id of delivery.ids) {\n\t\t\t\t\tthis.held.get(id)?.socket.close(delivery.code, delivery.reason);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Drop every socket that missed the last ping, and ping the rest. */\n\tprivate beat(): void {\n\t\tfor (const [id, held] of this.held) {\n\t\t\tif (!held.alive) {\n\t\t\t\theld.socket.terminate();\n\t\t\t\tthis.held.delete(id);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\theld.alive = false;\n\t\t\theld.socket.ping();\n\t\t}\n\t}\n\n\t/**\n\t * Stop: refuse new upgrades, close every socket with `code` — 1012 tells\n\t * a client to reconnect, and it lands on a process that is still up — and\n\t * leave the transport.\n\t */\n\tasync close(\n\t\tcode: number = CLOSE.serviceRestart,\n\t\treason = 'Restarting',\n\t): Promise<void> {\n\t\tif (this.closing) return;\n\t\tthis.closing = true;\n\t\tclearInterval(this.heartbeat);\n\n\t\tconst closed = [...this.held.values()].map(\n\t\t\t({ socket }) =>\n\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\tif (socket.readyState === socket.CLOSED) return resolve();\n\t\t\t\t\tsocket.once('close', () => resolve());\n\t\t\t\t\tsocket.close(code, reason);\n\t\t\t\t\t// A client that never answers the close is cut off.\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tsocket.terminate();\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t}, 2_000).unref();\n\t\t\t\t}),\n\t\t);\n\t\tawait Promise.all(closed);\n\t\tawait this.options.transport.close();\n\t\tthis.wss.close();\n\t}\n}\n\nfunction headersOf(request: IncomingMessage): Headers {\n\tconst headers = new Headers();\n\tfor (const [name, value] of Object.entries(request.headers)) {\n\t\tif (value === undefined) continue;\n\t\tfor (const one of Array.isArray(value) ? value : [value]) {\n\t\t\theaders.append(name, one);\n\t\t}\n\t}\n\treturn headers;\n}\n\nfunction refuse(socket: Duplex, status: number, message: string): void {\n\tif (!socket.destroyed) {\n\t\tsocket.end(\n\t\t\t`HTTP/1.1 ${status} ${message}\\r\\nConnection: close\\r\\nContent-Length: 0\\r\\n\\r\\n`,\n\t\t);\n\t}\n}\n","/**\n * `WebSocketApi` — a surface that holds long-lived connections.\n *\n * A process of its own, like a `RestApi`: it owns an address, its routes are\n * built from it, and they run in its container and nowhere else. A frame is\n * routed on its `action` — `{ \"action\": \"chat.send\", \"data\": … }`, API\n * Gateway's shape — and the connection's lifecycle on `$connect` and\n * `$disconnect`.\n *\n * Anything else reaches a socket through the surface's publisher:\n * `.dependsOn([realtime])` puts `services.realtime` in an endpoint, a cron or\n * a subscriber, and whichever replica holds the socket delivers. What it\n * sends is declared in `messages`, which the publisher is typed by.\n *\n * ```ts\n * export const realtime = new WebSocketApi('Realtime', {\n * path: 'apps/realtime',\n * messages: { 'chat.sent': z.object({ text: z.string() }) },\n * logger,\n * });\n *\n * export const send = realtime\n * .route('chat.send')\n * .body(z.object({ text: z.string() }))\n * .handle(async ({ body, sockets }) => sockets.broadcast('chat.sent', body));\n * ```\n */\n\nimport type { Server } from 'node:http';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tprovideKey,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Hono } from 'hono';\nimport {\n\ttype Authenticator,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { onShutdown } from './shutdown';\nimport type { Telemetry } from './telemetry';\nimport {\n\ttype NoMessages,\n\ttype WebSocketMessages,\n\tWebSocketPublisher,\n} from './websocket/publisher';\nimport { WebSocketRoute, WebSocketRouteBuilder } from './websocket/route';\nimport { WebSocketSurfaceServer } from './websocket/server';\nimport { transportFromConnectionString } from './websocket/transport';\n\nexport {\n\tInvalidWebSocketMessage,\n\ttype MessageAction,\n\ttype MessageData,\n\ttype NoMessages,\n\tUnknownWebSocketMessage,\n\ttype WebSocketMessages,\n\tWebSocketPublisher,\n} from './websocket/publisher';\nexport type {\n\tConnectContext,\n\tConnection,\n\tDisconnectContext,\n\tMessageContext,\n\tRouteKind,\n} from './websocket/route';\nexport { WebSocketRoute, WebSocketRouteBuilder } from './websocket/route';\nexport {\n\tCLOSE,\n\tDuplicateWebSocketRoute,\n\ttype WebSocketServerOptions,\n\tWebSocketSurfaceServer,\n} from './websocket/server';\nexport {\n\ttype Delivery,\n\tMemoryTransport,\n\tRedisTransport,\n\ttransportFromConnectionString,\n\tUnsupportedWebSocketTransport,\n\ttype WebSocketTransport,\n} from './websocket/transport';\n\nexport interface WebSocketApiConfig<\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\t/** The app that serves it, relative to the workspace root. */\n\tpath: string;\n\t/**\n\t * What it sends its sockets, by action — each with the schema its `data`\n\t * is checked by before it is sent.\n\t *\n\t * ```ts\n\t * messages: {\n\t * announcement: z.object({ text: z.string() }),\n\t * 'chat.said': z.object({ from: z.string(), text: z.string() }),\n\t * }\n\t * ```\n\t *\n\t * The publisher is typed by it — `services.realtime.broadcast(\n\t * 'announcement', { text })` — in an endpoint and in a route's `sockets`\n\t * alike. Absent, any action and any data go, unchecked.\n\t */\n\tmessages?: TMessages;\n\t/** The label it answers on. Absent, its id kebab-cased. */\n\tsubdomain?: string;\n\t/** How many processes serve it on one machine. Default 1. */\n\treplicas?: number;\n\tlogger?: Logger;\n\tenvParser?: EnvironmentParser<{}>;\n\ttelemetry?: Telemetry;\n\t/** Seconds between pings; a socket that misses one is dropped. Default 30. */\n\theartbeat?: number;\n\t/** The largest frame accepted, in bytes. Default 1 MiB. */\n\tmaxPayload?: number;\n}\n\n/** A replica count that is not a whole number of at least one. */\nexport class InvalidReplicaCount extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly replicas: number,\n\t) {\n\t\tsuper(\n\t\t\t`${id} asks for ${replicas} replicas. A surface runs on at least one process — give a whole number of 1 or more.`,\n\t\t);\n\t\tthis.name = 'InvalidReplicaCount';\n\t}\n}\n\nexport class WebSocketApi<\n\tTName extends string = string,\n\tTMessages extends WebSocketMessages = NoMessages,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\treadonly keys: {\n\t\turl: string;\n\t\ttrustedOrigins: string;\n\t\tpublisherConnectionString: string;\n\t};\n\n\treadonly logger: Logger;\n\treadonly envParser: EnvironmentParser<{}>;\n\treadonly telemetry?: Telemetry;\n\n\t/**\n\t * The surface as a dependency: `services.<id>` is its publisher, so an\n\t * endpoint sends to a socket the way a route beside it does.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, WebSocketPublisher<TMessages>>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WebSocketApiConfig<TMessages>,\n\t\t/** Internal: how `.auth()` carries the authenticator into its copy. */\n\t\treadonly authenticator?: Authenticator,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\t\tthis.id = canonical as TName;\n\n\t\tconst replicas = config.replicas ?? 1;\n\t\tif (!Number.isInteger(replicas) || replicas < 1) {\n\t\t\tthrow new InvalidReplicaCount(canonical, replicas);\n\t\t}\n\n\t\tthis.keys = {\n\t\t\turl: provideKey(canonical, 'url'),\n\t\t\ttrustedOrigins: provideKey(canonical, 'trustedOrigins'),\n\t\t\tpublisherConnectionString: provideKey(\n\t\t\t\tcanonical,\n\t\t\t\t'publisherConnectionString',\n\t\t\t),\n\t\t};\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.telemetry = config.telemetry;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\n\t\tconst envVar = this.keys.publisherConnectionString;\n\t\tconst channel = channelOf(canonical);\n\t\tconst declared = this.declared;\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tasync register({ envParser }) {\n\t\t\t\tconst { connectionString } = envParser\n\t\t\t\t\t.create((get) => ({ connectionString: get(envVar).string() }))\n\t\t\t\t\t.parse();\n\t\t\t\tconst transport = await transportFromConnectionString(\n\t\t\t\t\tconnectionString,\n\t\t\t\t\tchannel,\n\t\t\t\t);\n\t\t\t\tonShutdown(() => transport.close());\n\t\t\t\treturn new WebSocketPublisher<TMessages>(\n\t\t\t\t\ttransport,\n\t\t\t\t\tundefined,\n\t\t\t\t\tdeclared,\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** The handler a connection's upgrade runs: refuse it, or say who it is. */\n\tconnect(): WebSocketRouteBuilder<'connect', undefined, [], TMessages> {\n\t\treturn new WebSocketRouteBuilder('connect', '$connect', { id: this.id });\n\t}\n\n\t/** The handler a closed connection runs. */\n\tdisconnect(): WebSocketRouteBuilder<'disconnect', undefined, [], TMessages> {\n\t\treturn new WebSocketRouteBuilder('disconnect', '$disconnect', {\n\t\t\tid: this.id,\n\t\t});\n\t}\n\n\t/**\n\t * The handler for frames whose `action` is `action`. `$default` answers\n\t * any action nothing else does.\n\t */\n\troute(\n\t\taction: string,\n\t): WebSocketRouteBuilder<'message', undefined, [], TMessages> {\n\t\treturn new WebSocketRouteBuilder('message', action, { id: this.id });\n\t}\n\n\t/** What authenticates a connection — its session reaches `connect()`. */\n\tauth(construct: Authenticator): WebSocketApi<TName, TMessages> {\n\t\treturn new WebSocketApi<TName, TMessages>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\tconstruct,\n\t\t);\n\t}\n\n\t/**\n\t * Serve it: the routes exported by `modules` that were built from this\n\t * surface, on whatever HTTP server `attach` is handed.\n\t *\n\t * `app` answers plain HTTP — the generated entry puts `/health` in front\n\t * of it — and `attach` takes over the server's upgrades. The sockets are\n\t * closed with 1012 when the server shuts down.\n\t */\n\tasync server(\n\t\toptions: ServiceRegisterOptions & { modules?: readonly object[] },\n\t): Promise<{\n\t\tapp: Hono;\n\t\tattach(server: Server): void;\n\t\t/** Close every socket with 1012, so the HTTP server can close. */\n\t\trelease(): Promise<void>;\n\t\tserver: WebSocketSurfaceServer<TMessages>;\n\t}> {\n\t\tconst { Hono } = await import('hono');\n\t\tconst routes = (options.modules ?? []).flatMap((module) =>\n\t\t\tObject.values(module).filter(WebSocketRoute.isRoute),\n\t\t);\n\n\t\tconst { connectionString, origins } = options.envParser\n\t\t\t.create((get) => ({\n\t\t\t\tconnectionString: get(this.keys.publisherConnectionString)\n\t\t\t\t\t.string()\n\t\t\t\t\t// One process with nobody else sending: the sockets and the\n\t\t\t\t\t// routes meet in memory.\n\t\t\t\t\t.default(`memory://${channelOf(this.id)}`),\n\t\t\t\torigins: get(this.keys.trustedOrigins)\n\t\t\t\t\t.string()\n\t\t\t\t\t.default('')\n\t\t\t\t\t.transform((value: string) =>\n\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t\t.map((origin) => origin.trim())\n\t\t\t\t\t\t\t.filter(Boolean),\n\t\t\t\t\t),\n\t\t\t}))\n\t\t\t.parse();\n\n\t\tconst server = await WebSocketSurfaceServer.start<TMessages>({\n\t\t\tsurface: this.id,\n\t\t\troutes,\n\t\t\ttransport: await transportFromConnectionString(\n\t\t\t\tconnectionString,\n\t\t\t\tchannelOf(this.id),\n\t\t\t),\n\t\t\tenvParser: options.envParser,\n\t\t\tlogger: this.logger,\n\t\t\ttrustedOrigins: origins,\n\t\t\t...(this.declared ? { messages: this.declared.messages } : {}),\n\t\t\t...(this.authenticator ? { authenticator: this.authenticator } : {}),\n\t\t\t...(this.config.heartbeat\n\t\t\t\t? { heartbeatMs: this.config.heartbeat * 1000 }\n\t\t\t\t: {}),\n\t\t\t...(this.config.maxPayload ? { maxPayload: this.config.maxPayload } : {}),\n\t\t});\n\t\tonShutdown(() => server.close());\n\n\t\tconst app = new Hono();\n\t\t// Its own, so a process with nothing in front of it — `gkm dev`'s —\n\t\t// answers a probe too. A production entry puts one before it anyway.\n\t\tapp.get('/health', (c) =>\n\t\t\tc.json({ status: 'ok', connections: server.size }),\n\t\t);\n\t\tapp.get('/', (c) =>\n\t\t\tc.json({ surface: this.id, connections: server.size }, 426, {\n\t\t\t\tUpgrade: 'websocket',\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\tapp,\n\t\t\tattach: (http) => server.attach(http),\n\t\t\trelease: () => server.close(),\n\t\t\tserver,\n\t\t};\n\t}\n\n\t/** The declared messages, with the surface they are checked for. */\n\tprivate get declared(): { surface: string; messages: TMessages } | undefined {\n\t\treturn this.config.messages\n\t\t\t? { surface: this.id, messages: this.config.messages }\n\t\t\t: undefined;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'websocket-api',\n\t\t\t\tid: this.id,\n\t\t\t\tpath: this.config.path,\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.authenticator ? { auth: edgeTo(this.authenticator) } : {}),\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.replicas && this.config.replicas > 1\n\t\t\t\t\t? { replicas: this.config.replicas }\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\tthis.keys.trustedOrigins,\n\t\t\t\t\tthis.keys.publisherConnectionString,\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n\n/** The prefix a surface's channels are named under. */\nfunction channelOf(id: string): string {\n\treturn `gkm:ws:${id}`;\n}\n"],"mappings":";;;;;;;;;AAgCA,IAAa,gCAAb,cAAmD,MAAM;CACnC;CAArB,YAAY,kBAAmC;EAC9C,MACC,IAAI,OAAO,gBAAgB,EAAE,8IAE9B;EAJoB,KAAA,mBAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,SAAS,OAAO,kBAAkC;CACj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IAAI,KAAK;GACT,MAAM,KAAK,OAAO;GAClB,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,GAAI,KAAK,gBAAgB,EAAE,MAAM,OAAO,KAAK,aAAa,EAAE,IAAI,CAAC;GACjE,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,YAAY,KAAK,OAAO,WAAW,IAChD,EAAE,UAAU,KAAK,OAAO,SAAS,IACjC,CAAC;GACJ,UAAU;IACT,KAAK,KAAK;IACV,KAAK,KAAK;IACV,KAAK,KAAK;GACX;EACD,CACD;CACD;AACD;;AAGA,SAAS,UAAU,IAAoB;CACtC,OAAO,UAAU;AAClB"}
|
package/dist/worker.cjs
CHANGED
|
@@ -1,11 +1,62 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_construct_interface = require("./construct-interface.cjs");
|
|
3
|
-
const require_functions = require("./functions-
|
|
3
|
+
const require_functions = require("./functions-DLF6-IK8.cjs");
|
|
4
4
|
const require_surfaceEnv = require("./surfaceEnv-CNimK76p.cjs");
|
|
5
|
-
const require_CronBuilder = require("./CronBuilder-
|
|
6
|
-
const
|
|
5
|
+
const require_CronBuilder = require("./CronBuilder-B_NSP-Y5.cjs");
|
|
6
|
+
const require_QueueBuilder = require("./QueueBuilder-BxsZ9o5z.cjs");
|
|
7
|
+
const require_SubscriberBuilder = require("./SubscriberBuilder-CWzKwX1p.cjs");
|
|
7
8
|
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
8
9
|
let _geekmidas_logger_console = require("@geekmidas/logger/console");
|
|
10
|
+
//#region src/subscribers/InboxSubscriberBuilder.ts
|
|
11
|
+
var InboxSubscriberBuilder = class InboxSubscriberBuilder {
|
|
12
|
+
inner;
|
|
13
|
+
inbox;
|
|
14
|
+
constructor(inner, inbox) {
|
|
15
|
+
this.inner = inner;
|
|
16
|
+
this.inbox = inbox;
|
|
17
|
+
}
|
|
18
|
+
dependsOn(constructs) {
|
|
19
|
+
return this.with(this.inner.dependsOn(constructs));
|
|
20
|
+
}
|
|
21
|
+
services(services) {
|
|
22
|
+
return this.with(this.inner.services(services));
|
|
23
|
+
}
|
|
24
|
+
database(source) {
|
|
25
|
+
return this.with(this.inner.database(source));
|
|
26
|
+
}
|
|
27
|
+
timeout(timeout) {
|
|
28
|
+
return this.with(this.inner.timeout(timeout));
|
|
29
|
+
}
|
|
30
|
+
output(schema) {
|
|
31
|
+
return this.with(this.inner.output(schema));
|
|
32
|
+
}
|
|
33
|
+
logger(logger) {
|
|
34
|
+
return this.with(this.inner.logger(logger));
|
|
35
|
+
}
|
|
36
|
+
handle(fn) {
|
|
37
|
+
const key = (0, _geekmidas_manifest.serviceKey)(this.inbox.id);
|
|
38
|
+
const handler = async (ctx) => {
|
|
39
|
+
const inbox = ctx.services[key];
|
|
40
|
+
const notifications = ctx.events.filter((event) => event?.type === _geekmidas_manifest.INBOX_EVENT);
|
|
41
|
+
const messages = [];
|
|
42
|
+
for (const { payload } of notifications) messages.push(...await inbox.messages(payload));
|
|
43
|
+
if (messages.length === 0) return void 0;
|
|
44
|
+
return fn({
|
|
45
|
+
...ctx,
|
|
46
|
+
messages,
|
|
47
|
+
inbox
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const subscriber = this.inner.subscribe([_geekmidas_manifest.INBOX_EVENT]).handle(handler);
|
|
51
|
+
subscriber.inboxName = this.inbox.id;
|
|
52
|
+
subscriber.inboxAddressing = this.inbox.addressing;
|
|
53
|
+
return subscriber;
|
|
54
|
+
}
|
|
55
|
+
with(inner) {
|
|
56
|
+
return new InboxSubscriberBuilder(inner, this.inbox);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
9
60
|
//#region src/worker.ts
|
|
10
61
|
var Worker = class Worker {
|
|
11
62
|
config;
|
|
@@ -17,7 +68,8 @@ var Worker = class Worker {
|
|
|
17
68
|
envParser;
|
|
18
69
|
/**
|
|
19
70
|
* Where this worker's schedules live, when it has crons and a server runs
|
|
20
|
-
* them
|
|
71
|
+
* them — and the database everything built from it receives as `db`.
|
|
72
|
+
* `undefined` until `.database(…)` says.
|
|
21
73
|
*/
|
|
22
74
|
scheduleStore;
|
|
23
75
|
constructor(id, config = {}, dependencies = [], scheduleStore) {
|
|
@@ -33,7 +85,10 @@ var Worker = class Worker {
|
|
|
33
85
|
this.scheduleStore = scheduleStore;
|
|
34
86
|
}
|
|
35
87
|
/**
|
|
36
|
-
* The database this worker keeps its schedules in
|
|
88
|
+
* The database this worker keeps its schedules in, and the one everything
|
|
89
|
+
* built from it — crons, queues, subscribers, functions — receives as `db`.
|
|
90
|
+
* One of them that works against another database names it with its own
|
|
91
|
+
* `.database(other)`, which replaces this one for that runnable alone.
|
|
37
92
|
*
|
|
38
93
|
* Only a server target uses it. On AWS a cron is an EventBridge rule
|
|
39
94
|
* invoking a Lambda and nothing here is consulted — but a server has nothing
|
|
@@ -50,6 +105,10 @@ var Worker = class Worker {
|
|
|
50
105
|
* @example
|
|
51
106
|
* ```ts
|
|
52
107
|
* export const jobs = new Worker('Jobs', { logger }).database(database);
|
|
108
|
+
*
|
|
109
|
+
* export const sweep = jobs
|
|
110
|
+
* .cron('rate(1 hour)')
|
|
111
|
+
* .handle(async ({ db }) => db.deleteFrom('sessions').execute());
|
|
53
112
|
* ```
|
|
54
113
|
*/
|
|
55
114
|
database(source) {
|
|
@@ -64,12 +123,72 @@ var Worker = class Worker {
|
|
|
64
123
|
return this.own(new require_CronBuilder.CronBuilder().logger(this.logger)).schedule(schedule);
|
|
65
124
|
}
|
|
66
125
|
/**
|
|
126
|
+
* A queue and its one consumer, run by this worker.
|
|
127
|
+
*
|
|
128
|
+
* One construct, because a queue has exactly one consumer: nothing else can
|
|
129
|
+
* attach a second, or forget to attach the first. Producers send to it by
|
|
130
|
+
* depending on it — `.dependsOn([emails])` makes `services.emails` the
|
|
131
|
+
* publisher.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* export const emails = worker
|
|
136
|
+
* .queue('Emails')
|
|
137
|
+
* .message(z.object({ userId: z.uuid(), template: z.string() }))
|
|
138
|
+
* .handle(async ({ messages, services }) => { … });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
queue(name) {
|
|
142
|
+
return this.own(new require_QueueBuilder.QueueBuilder().logger(this.logger)).queue(name);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A runnable that reacts to a bucket's objects changing.
|
|
146
|
+
*
|
|
147
|
+
* A bucket is a topic whose publisher is the storage: the binding is the
|
|
148
|
+
* same as {@link Worker.topic}'s, and so is everything after it — the
|
|
149
|
+
* services, the database, how it is delivered. The handler is handed the
|
|
150
|
+
* objects; reading one still means depending on the bucket,
|
|
151
|
+
* `.dependsOn([uploads])`.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* export const onAvatar = worker
|
|
156
|
+
* .objects(uploads)
|
|
157
|
+
* .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })
|
|
158
|
+
* .handle(async ({ objects }) => { … });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
objects(bucket) {
|
|
162
|
+
const inner = this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger));
|
|
163
|
+
return new require_SubscriberBuilder.ObjectSubscriberBuilder(inner, bucket.id);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A runnable handed the mail an {@link Inbox} receives.
|
|
167
|
+
*
|
|
168
|
+
* Bound, as a topic subscriber is: the inbox's topic is what it consumes,
|
|
169
|
+
* and what it is handed is the messages on it, parsed — one per envelope
|
|
170
|
+
* recipient the inbox receives at. It reads its inbox's raw messages
|
|
171
|
+
* without depending on it; anything else it uses it names, as ever.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* export const onRequest = worker
|
|
176
|
+
* .inbox(requests)
|
|
177
|
+
* .handle(async ({ messages, db }) => {
|
|
178
|
+
* for (const message of messages) message.recipient.subdomain;
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
inbox(inbox) {
|
|
183
|
+
return new InboxSubscriberBuilder(this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger)).topic(inbox.topic).dependsOn([inbox]), inbox);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
67
186
|
* A runnable that consumes a topic.
|
|
68
187
|
*
|
|
69
188
|
* Binding is not publishing: a consumer is handed the topic's event types
|
|
70
|
-
* and no connection string it could publish with.
|
|
71
|
-
*
|
|
72
|
-
* one.
|
|
189
|
+
* and no connection string it could publish with. A handler that emits
|
|
190
|
+
* follow-up events depends on the topic it emits to —
|
|
191
|
+
* `.dependsOn([orders])` — which is the only reason it would need one.
|
|
73
192
|
*
|
|
74
193
|
* @example `worker.topic(users).subscribe(['user.created']).handle(…)`
|
|
75
194
|
*/
|
|
@@ -77,17 +196,6 @@ var Worker = class Worker {
|
|
|
77
196
|
return this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger)).topic(topic);
|
|
78
197
|
}
|
|
79
198
|
/**
|
|
80
|
-
* A runnable that consumes events typed from a publisher service.
|
|
81
|
-
*
|
|
82
|
-
* The older of the two ways to bind a subscriber, kept for a project whose
|
|
83
|
-
* events come from a hand-written publisher rather than a `Topic`
|
|
84
|
-
* construct. `topic()` is the one to reach for: it types the events the same
|
|
85
|
-
* way and hands the consumer no connection string it could publish with.
|
|
86
|
-
*/
|
|
87
|
-
publisher(service) {
|
|
88
|
-
return this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger)).publisher(service);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
199
|
* Everything below builds a function — the runnable with no schedule and no
|
|
92
200
|
* topic, invoked by something else.
|
|
93
201
|
*
|
|
@@ -133,28 +241,28 @@ var Worker = class Worker {
|
|
|
133
241
|
return this.own(new require_functions.FunctionBuilder().logger(this.logger));
|
|
134
242
|
}
|
|
135
243
|
/**
|
|
136
|
-
* Resources and surfaces this worker calls.
|
|
137
|
-
*
|
|
138
|
-
* Not `.dependsOn()`: this records the edge that derives the worker's
|
|
139
|
-
* environment and its access, the same distinction `RestApi.calls()` draws.
|
|
140
|
-
*/
|
|
141
|
-
calls(constructs) {
|
|
142
|
-
return new Worker(this.id, this.config, [...this.dependencies, ...constructs.map(require_construct_interface.edgeTo)], this.scheduleStore);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
244
|
* Stamps this worker's id onto a builder, so everything built from it says
|
|
146
|
-
* which process runs it.
|
|
245
|
+
* which process runs it — and hands it the worker's database.
|
|
246
|
+
*
|
|
247
|
+
* The database goes through the builder's own `.database()` rather than
|
|
248
|
+
* being written into its fields, so the default is recorded exactly as an
|
|
249
|
+
* explicit one would be: the client the handler gets, and the edge the
|
|
250
|
+
* manifest reads. That is also what lets a later `.database(other)` replace
|
|
251
|
+
* it outright. The builder arrives already typed with this worker's
|
|
252
|
+
* database; this is the runtime half of that.
|
|
147
253
|
*/
|
|
148
254
|
own(builder) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
255
|
+
const owned = this.scheduleStore ? builder.database(this.scheduleStore) : builder;
|
|
256
|
+
owned._owner = this.id;
|
|
257
|
+
owned._scheduleStore = this.scheduleStore;
|
|
258
|
+
return owned;
|
|
152
259
|
}
|
|
153
260
|
declare() {
|
|
154
261
|
return [{
|
|
155
262
|
kind: "worker",
|
|
156
263
|
id: this.id,
|
|
157
264
|
...this.dependencies.length ? { dependencies: this.dependencies } : {},
|
|
265
|
+
...this.config.telemetry ? { telemetry: this.config.telemetry.id } : {},
|
|
158
266
|
provides: []
|
|
159
267
|
}];
|
|
160
268
|
}
|
package/dist/worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.cjs","names":["canonicalId","DEFAULT_LOGGER","envParserFor","edgeTo","CronBuilder","SubscriberBuilder","FunctionBuilder"],"sources":["../src/worker.ts"],"sourcesContent":["/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * It is not an app. A worker names the process that runs its crons and\n * subscribers, and that process is the app's server — the same one the\n * endpoints run in, minus the HTTP surface. Giving a worker a container of its\n * own made a second thing to build, deploy and keep alive for work that was\n * always going to run somewhere already. Declare as many as the shape of the\n * work wants: they are groupings, not deployments.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).calls([database]);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ logger }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n}\n\nexport class Worker<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them. `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.calls()` carries edges into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName> {\n\t\treturn new Worker<TName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(new CronBuilder().logger(this.logger)).schedule(schedule);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. Chain `.publishes(…)` when\n\t * the handler emits follow-up events, which is the only reason it would need\n\t * one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(new SubscriberBuilder().logger(this.logger)).topic(topic);\n\t}\n\n\t/**\n\t * A runnable that consumes events typed from a publisher service.\n\t *\n\t * The older of the two ways to bind a subscriber, kept for a project whose\n\t * events come from a hand-written publisher rather than a `Topic`\n\t * construct. `topic()` is the one to reach for: it types the events the same\n\t * way and hands the consumer no connection string it could publish with.\n\t */\n\tpublisher<T extends EventPublisher<any>, TPubName extends string>(\n\t\tservice: Service<TPubName, T> | Consumable<TPubName, T>,\n\t) {\n\t\treturn this.own(new SubscriberBuilder().logger(this.logger)).publisher(\n\t\t\tservice as never,\n\t\t);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<Worker<TName>['schemalessFunction']>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(new FunctionBuilder().logger(this.logger));\n\t}\n\n\t/**\n\t * Resources and surfaces this worker calls.\n\t *\n\t * Not `.dependsOn()`: this records the edge that derives the worker's\n\t * environment and its access, the same distinction `RestApi.calls()` draws.\n\t */\n\tcalls(constructs: readonly Declarable[]): Worker<TName> {\n\t\treturn new Worker<TName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, ...constructs.map(edgeTo)],\n\t\t\tthis.scheduleStore,\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it.\n\t */\n\tprivate own<T extends { _owner?: string; _scheduleStore?: unknown }>(\n\t\tbuilder: T,\n\t): T {\n\t\tbuilder._owner = this.id;\n\t\tbuilder._scheduleStore = this.scheduleStore;\n\n\t\treturn builder;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;AAoGA,IAAa,SAAb,MAAa,OAEb;CAiBmB;CAEA;CAlBlB;;CAGA;;CAGA;;;;;CAMA;CAEA,YACC,IACA,SAAwC,CAAC,GAEzC,eAAuD,CAAC,GACxD,eACC;EAJgB,KAAA,SAAA;EAEA,KAAA,eAAA;EAGjB,MAAM,aAAA,GAAYA,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,K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B;EAC5B,OAAO,KAAK;CACb;;CAGA,IAAY,YAAY;EACvB,OAAO,KAAK,IAAI,IAAIC,kBAAAA,gBAAgB,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC;CAC1D;;;;;;;CAQA,MAAM,YAAkD;EACvD,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,GAAG,WAAW,IAAIH,4BAAAA,MAAM,CAAC,GAChD,KAAK,aACN;CACD;;;;;CAMA,IACC,SACI;EACJ,QAAQ,SAAS,KAAK;EACtB,QAAQ,iBAAiB,KAAK;EAE9B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"worker.cjs","names":["serviceKey","INBOX_EVENT","canonicalId","DEFAULT_LOGGER","envParserFor","edgeTo","CronBuilder","QueueBuilder","SubscriberBuilder","ObjectSubscriberBuilder","FunctionBuilder"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"sourcesContent":["/**\n * A subscriber bound to an inbox: a topic subscriber whose topic the inbox\n * declares and the provider publishes to, so it runs through the same adaptors\n * — Lambda, SNS push, a polled broker, a feature test.\n *\n * What it is delivered is a receipt notification; what its handler is handed\n * is the messages, parsed, one per envelope recipient the inbox receives at.\n * The inbox's own client does that, which is also why the handler can read\n * its inbox's raw messages without naming it in `.dependsOn`.\n */\n\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT, serviceKey } from '@geekmidas/manifest';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type {\n\tInbox,\n\tInboxClient,\n\tInboxMessage,\n\tReceiptNotification,\n} from '../inbox';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\nexport type InboxSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<{ type: typeof INBOX_EVENT; payload: ReceiptNotification }>,\n\t[typeof INBOX_EVENT],\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\nexport type InboxSubscriberContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** The messages received, one per envelope recipient the inbox takes. */\n\tmessages: InboxMessage[];\n\t/** The inbox, under its own id too: its domain and its raw messages. */\n\tinbox: InboxClient;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type InboxSubscriberHandler<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: InboxSubscriberContext<TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\nexport class InboxSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\n\t\tprivate readonly inner: SubscriberBuilder<\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany\n\t\t>,\n\t\tprivate readonly inbox: Inbox<string>,\n\t) {}\n\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.dependsOn(constructs));\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName> {\n\t\treturn this.with(this.inner.database(source));\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn this.with(this.inner.timeout(timeout)) as this;\n\t}\n\n\toutput<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.output(schema));\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.logger(logger));\n\t}\n\n\thandle(\n\t\tfn: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>,\n\t): InboxSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst key = serviceKey(this.inbox.id);\n\n\t\t// Every adaptor hands the handler `{ type, payload }` messages; each\n\t\t// payload here is a receipt notification, and the inbox's client turns\n\t\t// it into the messages for the recipients it receives at.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst inbox = ctx.services[key] as InboxClient;\n\t\t\tconst notifications = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is { type: string; payload: ReceiptNotification } =>\n\t\t\t\t\t(event as { type?: string })?.type === INBOX_EVENT,\n\t\t\t);\n\t\t\tconst messages: InboxMessage[] = [];\n\t\t\tfor (const { payload } of notifications) {\n\t\t\t\tmessages.push(...(await inbox.messages(payload)));\n\t\t\t}\n\t\t\tif (messages.length === 0) return undefined;\n\t\t\treturn fn({\n\t\t\t\t...ctx,\n\t\t\t\tmessages,\n\t\t\t\tinbox,\n\t\t\t} as unknown as InboxSubscriberContext<TServices, TLogger, TDatabase>);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe([INBOX_EVENT] as never)\n\t\t\t.handle(handler as never) as unknown as InboxSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.inboxName = this.inbox.id;\n\t\tsubscriber.inboxAddressing = this.inbox.addressing;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.inbox,\n\t\t);\n\t}\n}\n","/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app: it declares no path, and its code lives in an app's\n * directory. But it is a process of its own. On a server target each worker\n * with work to do is built — from the app that holds that work — into an image\n * that runs its crons, consumers and subscribers and answers only a health\n * check, so a slow queue never shares a process with the requests an API\n * serves. `gkm dev` still runs everything in one process. Declare as many as\n * the shape of the work wants: each is one container.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport type { Inbox } from './inbox';\nimport type { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { InboxSubscriberBuilder } from './subscribers/InboxSubscriberBuilder';\nimport { ObjectSubscriberBuilder } from './subscribers/ObjectSubscriberBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Telemetry } from './telemetry';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * What the worker's process emits — the `Telemetry` construct, passed like\n\t * the logger. An edge to the node: the deploy hands the process the\n\t * `OTEL_*` keys its stage resolves.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.database()` carries its edge into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that reacts to a bucket's objects changing.\n\t *\n\t * A bucket is a topic whose publisher is the storage: the binding is the\n\t * same as {@link Worker.topic}'s, and so is everything after it — the\n\t * services, the database, how it is delivered. The handler is handed the\n\t * objects; reading one still means depending on the bucket,\n\t * `.dependsOn([uploads])`.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onAvatar = worker\n\t * .objects(uploads)\n\t * .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })\n\t * .handle(async ({ objects }) => { … });\n\t * ```\n\t */\n\tobjects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t\treturn new ObjectSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\t[],\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, bucket.id);\n\t}\n\n\t/**\n\t * A runnable handed the mail an {@link Inbox} receives.\n\t *\n\t * Bound, as a topic subscriber is: the inbox's topic is what it consumes,\n\t * and what it is handed is the messages on it, parsed — one per envelope\n\t * recipient the inbox receives at. It reads its inbox's raw messages\n\t * without depending on it; anything else it uses it names, as ever.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onRequest = worker\n\t * .inbox(requests)\n\t * .handle(async ({ messages, db }) => {\n\t * for (const message of messages) message.recipient.subdomain;\n\t * });\n\t * ```\n\t */\n\tinbox<TInboxName extends string>(inbox: Inbox<TInboxName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t)\n\t\t\t.topic(inbox.topic)\n\t\t\t// The inbox itself: its client reads the raw messages from the\n\t\t\t// inbox's own bucket, which is what the edge grants — and nothing\n\t\t\t// the handler did not name besides.\n\t\t\t.dependsOn([inbox]);\n\t\treturn new InboxSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, inbox);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\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// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\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