@geekmidas/constructs 10.0.0-alpha.9 → 10.0.0-alpha.91
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-BD5neF7w.mjs → Construct-B1vGBPme.mjs} +33 -34
- package/dist/Construct-B1vGBPme.mjs.map +1 -0
- package/dist/Construct-BQALFCh2.d.cts +230 -0
- package/dist/Construct-BQALFCh2.d.cts.map +1 -0
- package/dist/{Construct-CyS3RpTL.cjs → Construct-DUSXuTHP.cjs} +53 -48
- package/dist/Construct-DUSXuTHP.cjs.map +1 -0
- package/dist/Construct-QXnl3VqT.d.mts +230 -0
- package/dist/Construct-QXnl3VqT.d.mts.map +1 -0
- package/dist/{Cron-DmQ8vQ4b.d.cts → Cron-DI3nKoic.d.cts} +15 -9
- package/dist/Cron-DI3nKoic.d.cts.map +1 -0
- package/dist/{Cron-dh4rUgib.d.mts → Cron-uYAHPnp7.d.mts} +15 -9
- package/dist/Cron-uYAHPnp7.d.mts.map +1 -0
- package/dist/{CronBuilder-Da0C0edR.cjs → CronBuilder-C0Ek1-RA.cjs} +47 -31
- package/dist/CronBuilder-C0Ek1-RA.cjs.map +1 -0
- package/dist/CronBuilder-DaSUm2Na.d.mts +47 -0
- package/dist/CronBuilder-DaSUm2Na.d.mts.map +1 -0
- package/dist/{CronBuilder-CYKT5RiO.mjs → CronBuilder-Dmix_Pen.mjs} +37 -21
- package/dist/CronBuilder-Dmix_Pen.mjs.map +1 -0
- package/dist/CronBuilder-g1lZLWyG.d.cts +47 -0
- package/dist/CronBuilder-g1lZLWyG.d.cts.map +1 -0
- package/dist/{Endpoint-DCQPMdUX.mjs → Endpoint-BG4UJ9oA.mjs} +146 -109
- package/dist/Endpoint-BG4UJ9oA.mjs.map +1 -0
- package/dist/{Endpoint-DcWXE-SZ.cjs → Endpoint-BoUg8ocM.cjs} +174 -131
- package/dist/Endpoint-BoUg8ocM.cjs.map +1 -0
- package/dist/{Endpoint-BjWKinFA.d.mts → Endpoint-Du-NwPX2.d.mts} +83 -91
- package/dist/Endpoint-Du-NwPX2.d.mts.map +1 -0
- package/dist/{Endpoint-dav89W6-.d.cts → Endpoint-aCvBMPoH.d.cts} +82 -90
- package/dist/Endpoint-aCvBMPoH.d.cts.map +1 -0
- package/dist/{EndpointFactory-CjV8F_lJ.mjs → EndpointFactory-BDtsrEvJ.mjs} +57 -76
- package/dist/EndpointFactory-BDtsrEvJ.mjs.map +1 -0
- package/dist/{EndpointFactory-CdWB7wPw.cjs → EndpointFactory-DJ7gXLpR.cjs} +93 -112
- package/dist/EndpointFactory-DJ7gXLpR.cjs.map +1 -0
- package/dist/{index-Bd5FqCoe.d.cts → EndpointFactory-DMYdJCOj.d.mts} +78 -134
- package/dist/EndpointFactory-DMYdJCOj.d.mts.map +1 -0
- package/dist/{index-lAO9egTb.d.mts → EndpointFactory-I7s1co3Y.d.cts} +79 -135
- package/dist/EndpointFactory-I7s1co3Y.d.cts.map +1 -0
- package/dist/Function-DuqGcbOI.d.mts +76 -0
- package/dist/Function-DuqGcbOI.d.mts.map +1 -0
- package/dist/Function-Pu-1kKZz.d.cts +76 -0
- package/dist/Function-Pu-1kKZz.d.cts.map +1 -0
- package/dist/{HonoEndpointAdaptor-P1ahhZHu.mjs → HonoEndpointAdaptor-PtPlbeKY.mjs} +75 -56
- package/dist/HonoEndpointAdaptor-PtPlbeKY.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DtL9j19R.cjs → HonoEndpointAdaptor-zVzVLJEO.cjs} +83 -61
- package/dist/HonoEndpointAdaptor-zVzVLJEO.cjs.map +1 -0
- package/dist/Queue-A3wfD0it.cjs +109 -0
- package/dist/Queue-A3wfD0it.cjs.map +1 -0
- package/dist/Queue-D6USGS4q.mjs +104 -0
- package/dist/Queue-D6USGS4q.mjs.map +1 -0
- package/dist/{Queue-D7ZuwBhy.d.cts → Queue-DlsHRzUp.d.mts} +48 -48
- package/dist/Queue-DlsHRzUp.d.mts.map +1 -0
- package/dist/{Queue-gVGfi2Yk.d.mts → Queue-HPyi0e1i.d.cts} +49 -49
- package/dist/Queue-HPyi0e1i.d.cts.map +1 -0
- package/dist/QueueBuilder-BjuF0UBl.cjs +135 -0
- package/dist/QueueBuilder-BjuF0UBl.cjs.map +1 -0
- package/dist/QueueBuilder-Cue73M4t.mjs +118 -0
- package/dist/QueueBuilder-Cue73M4t.mjs.map +1 -0
- package/dist/QueueBuilder-OSi6LkV9.d.cts +75 -0
- package/dist/QueueBuilder-OSi6LkV9.d.cts.map +1 -0
- package/dist/QueueBuilder-QHsnVt1P.d.mts +75 -0
- package/dist/QueueBuilder-QHsnVt1P.d.mts.map +1 -0
- package/dist/{Subscriber-2mEi0ImH.d.cts → Subscriber-Bpp02cGr.d.cts} +29 -20
- package/dist/Subscriber-Bpp02cGr.d.cts.map +1 -0
- package/dist/{Subscriber-xTJ9ayPN.d.mts → Subscriber-CtN9R48-.d.mts} +29 -20
- package/dist/Subscriber-CtN9R48-.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-BjkbeT9l.mjs → SubscriberBuilder-CDy4nHCz.mjs} +50 -24
- package/dist/SubscriberBuilder-CDy4nHCz.mjs.map +1 -0
- package/dist/SubscriberBuilder-CuCMFpYW.d.mts +67 -0
- package/dist/SubscriberBuilder-CuCMFpYW.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-4OPehf2R.cjs → SubscriberBuilder-D_owVoHo.cjs} +61 -36
- package/dist/SubscriberBuilder-D_owVoHo.cjs.map +1 -0
- package/dist/SubscriberBuilder-g3fAVWgs.d.cts +67 -0
- package/dist/SubscriberBuilder-g3fAVWgs.d.cts.map +1 -0
- package/dist/Topic-D74b5cgs.mjs +99 -0
- package/dist/Topic-D74b5cgs.mjs.map +1 -0
- package/dist/Topic-GHxcU8AG.cjs +104 -0
- package/dist/Topic-GHxcU8AG.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +131 -220
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +34 -53
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +34 -53
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +102 -193
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +3 -10
- package/dist/adaptors/hono.d.cts +7 -16
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +8 -17
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +2 -10
- package/dist/adaptors/testing.cjs +743 -89
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +351 -54
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +351 -54
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +706 -70
- 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-CcuceLYo.d.mts +268 -0
- package/dist/auth-CcuceLYo.d.mts.map +1 -0
- package/dist/auth.cjs +301 -33
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -108
- package/dist/auth.d.mts +2 -108
- package/dist/auth.mjs +289 -27
- package/dist/auth.mjs.map +1 -1
- package/dist/{cache-BrRz3fEB.d.mts → cache-CXh6GIgb.d.mts} +3 -6
- package/dist/cache-CXh6GIgb.d.mts.map +1 -0
- package/dist/{cache-BtZY_tHe.d.cts → cache-DnGDGly3.d.cts} +3 -6
- package/dist/cache-DnGDGly3.d.cts.map +1 -0
- package/dist/cache.cjs +68 -2
- package/dist/cache.cjs.map +1 -0
- package/dist/cache.d.cts +1 -2
- package/dist/cache.d.mts +1 -2
- package/dist/cache.mjs +67 -2
- package/dist/cache.mjs.map +1 -0
- 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/{clone-DblgEZZa.mjs → clone-EKNovYHu.mjs} +3 -3
- package/dist/clone-EKNovYHu.mjs.map +1 -0
- package/dist/{clone-Dy0cR2SZ.cjs → clone-UGJpvQnL.cjs} +7 -8
- package/dist/clone-UGJpvQnL.cjs.map +1 -0
- package/dist/{construct-interface-D9d4Gm4p.d.cts → construct-interface-B1AfqRl4.d.cts} +42 -11
- package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
- package/dist/{construct-interface-g5GM5pwR.d.mts → construct-interface-DluK3_da.d.mts} +42 -11
- package/dist/construct-interface-DluK3_da.d.mts.map +1 -0
- package/dist/construct-interface.cjs +113 -7
- package/dist/construct-interface.cjs.map +1 -0
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +106 -2
- package/dist/construct-interface.mjs.map +1 -0
- package/dist/credential.cjs +77 -17
- package/dist/credential.cjs.map +1 -1
- package/dist/credential.d.cts +34 -9
- package/dist/credential.d.cts.map +1 -1
- package/dist/credential.d.mts +34 -9
- package/dist/credential.d.mts.map +1 -1
- package/dist/credential.mjs +71 -13
- package/dist/credential.mjs.map +1 -1
- package/dist/crons/index.cjs +129 -7
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +45 -11
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +45 -11
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +127 -8
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +4 -181
- package/dist/database/kysely.d.cts +2 -152
- package/dist/database/kysely.d.mts +2 -152
- package/dist/database/kysely.mjs +2 -180
- package/dist/email.cjs +25 -12
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +3 -7
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts +3 -7
- package/dist/email.d.mts.map +1 -1
- package/dist/email.mjs +16 -3
- package/dist/email.mjs.map +1 -1
- package/dist/encryption.cjs +96 -0
- package/dist/encryption.cjs.map +1 -0
- package/dist/encryption.d.cts +117 -0
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +117 -0
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +83 -0
- package/dist/encryption.mjs.map +1 -0
- package/dist/endpoints/index.cjs +8 -10
- package/dist/endpoints/index.d.cts +51 -7
- package/dist/endpoints/index.d.cts.map +1 -0
- package/dist/endpoints/index.d.mts +51 -7
- package/dist/endpoints/index.d.mts.map +1 -0
- package/dist/endpoints/index.mjs +6 -10
- package/dist/external-api-MJ8id87V.d.mts +105 -0
- package/dist/external-api-MJ8id87V.d.mts.map +1 -0
- package/dist/external-api-O107yzZJ.d.cts +105 -0
- package/dist/external-api-O107yzZJ.d.cts.map +1 -0
- package/dist/external-api.cjs +142 -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 +139 -0
- package/dist/external-api.mjs.map +1 -0
- package/dist/file-server.cjs +42 -10
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +6 -10
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +6 -10
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +34 -2
- package/dist/file-server.mjs.map +1 -1
- package/dist/functions/index.cjs +3 -6
- package/dist/functions/index.d.cts +3 -4
- package/dist/functions/index.d.mts +3 -4
- package/dist/functions/index.mjs +2 -6
- package/dist/{functions-14lpEFL4.mjs → functions-BFizikJU.mjs} +376 -238
- package/dist/{functions-14lpEFL4.mjs.map → functions-BFizikJU.mjs.map} +1 -1
- package/dist/{functions-i_la-N5r.cjs → functions-CfzJG9hK.cjs} +414 -264
- package/dist/functions-CfzJG9hK.cjs.map +1 -0
- package/dist/index-BuzRvKOQ.d.cts +115 -0
- package/dist/index-BuzRvKOQ.d.cts.map +1 -0
- package/dist/index-CTkKOer4.d.mts +115 -0
- package/dist/index-CTkKOer4.d.mts.map +1 -0
- package/dist/index-CeEtxDmK.d.cts +79 -0
- package/dist/index-CeEtxDmK.d.cts.map +1 -0
- package/dist/index-CeEtxDmK.d.mts +79 -0
- package/dist/index-CeEtxDmK.d.mts.map +1 -0
- package/dist/index.cjs +6 -3
- package/dist/index.d.cts +27 -4
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +27 -4
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -3
- package/dist/kms-B-Hm3d5r.cjs +85 -0
- package/dist/kms-B-Hm3d5r.cjs.map +1 -0
- package/dist/kms-BdUlMJEZ.mjs +85 -0
- package/dist/kms-BdUlMJEZ.mjs.map +1 -0
- package/dist/kysely-Bii4l6eP.mjs +370 -0
- package/dist/kysely-Bii4l6eP.mjs.map +1 -0
- package/dist/kysely-CO_Dk43W.cjs +383 -0
- package/dist/kysely-CO_Dk43W.cjs.map +1 -0
- package/dist/kysely-D0bpzgPs.d.cts +175 -0
- package/dist/kysely-D0bpzgPs.d.cts.map +1 -0
- package/dist/kysely-DUqC3Ie0.d.mts +175 -0
- package/dist/kysely-DUqC3Ie0.d.mts.map +1 -0
- package/dist/{telemetry-C3L0iS28.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +3 -6
- package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
- package/dist/{telemetry-D7bVFLGi.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +3 -6
- package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
- package/dist/{lazyAccessors-BoJN3SMd.mjs → lazyAccessors-CFanua0O.mjs} +20 -60
- package/dist/lazyAccessors-CFanua0O.mjs.map +1 -0
- package/dist/{lazyAccessors-e3j2oE2m.cjs → lazyAccessors-hJKGv8Ay.cjs} +60 -113
- package/dist/lazyAccessors-hJKGv8Ay.cjs.map +1 -0
- package/dist/mobile-app.cjs +73 -0
- package/dist/mobile-app.cjs.map +1 -0
- package/dist/mobile-app.d.cts +61 -0
- package/dist/mobile-app.d.cts.map +1 -0
- package/dist/mobile-app.d.mts +61 -0
- package/dist/mobile-app.d.mts.map +1 -0
- package/dist/mobile-app.mjs +72 -0
- package/dist/mobile-app.mjs.map +1 -0
- package/dist/object-storage.cjs +18 -10
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +3 -7
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +3 -7
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +11 -3
- package/dist/object-storage.mjs.map +1 -1
- package/dist/processAudits-BRRVVHUB.mjs +131 -0
- package/dist/processAudits-BRRVVHUB.mjs.map +1 -0
- package/dist/processAudits-DasOZjPl.cjs +154 -0
- package/dist/processAudits-DasOZjPl.cjs.map +1 -0
- package/dist/queue/index.cjs +6 -189
- package/dist/queue/index.d.cts +3 -60
- package/dist/queue/index.d.mts +3 -60
- package/dist/queue/index.mjs +3 -186
- package/dist/rest-api.cjs +90 -59
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +70 -42
- package/dist/rest-api.d.cts.map +1 -1
- package/dist/rest-api.d.mts +70 -42
- package/dist/rest-api.d.mts.map +1 -1
- package/dist/rest-api.mjs +82 -51
- package/dist/rest-api.mjs.map +1 -1
- package/dist/{chunk-DWy1uDak.cjs → rolldown-runtime-y5ARvAq5.cjs} +14 -18
- package/dist/runSubscriber-BHvJ8POr.mjs +109 -0
- package/dist/runSubscriber-BHvJ8POr.mjs.map +1 -0
- package/dist/runSubscriber-D8nLXIv1.cjs +126 -0
- package/dist/runSubscriber-D8nLXIv1.cjs.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 +33 -7
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +17 -7
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +17 -7
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +29 -3
- package/dist/site.mjs.map +1 -1
- package/dist/stages-BSCF19o2.d.cts +56 -0
- package/dist/stages-BSCF19o2.d.cts.map +1 -0
- package/dist/stages-BSCF19o2.d.mts +56 -0
- package/dist/stages-BSCF19o2.d.mts.map +1 -0
- package/dist/subscribers/index.cjs +118 -6
- package/dist/subscribers/index.cjs.map +1 -0
- package/dist/subscribers/index.d.cts +51 -6
- package/dist/subscribers/index.d.cts.map +1 -0
- package/dist/subscribers/index.d.mts +51 -6
- package/dist/subscribers/index.d.mts.map +1 -0
- package/dist/subscribers/index.mjs +115 -5
- package/dist/subscribers/index.mjs.map +1 -0
- package/dist/surfaceEnv-CNimK76p.cjs +56 -0
- package/dist/surfaceEnv-CNimK76p.cjs.map +1 -0
- package/dist/surfaceEnv-wMT5QzgZ.mjs +45 -0
- package/dist/surfaceEnv-wMT5QzgZ.mjs.map +1 -0
- package/dist/telemetry-B48RLjyk.d.cts +40 -0
- package/dist/telemetry-B48RLjyk.d.cts.map +1 -0
- package/dist/telemetry-DRtT1_0A.d.mts +40 -0
- package/dist/telemetry-DRtT1_0A.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 +3 -137
- package/dist/topic/index.d.cts +2 -4
- package/dist/topic/index.d.mts +2 -4
- package/dist/topic/index.mjs +2 -134
- package/dist/tracing-CxaZ98IB.mjs +110 -0
- package/dist/tracing-CxaZ98IB.mjs.map +1 -0
- package/dist/tracing-DPMidF_r.cjs +127 -0
- package/dist/tracing-DPMidF_r.cjs.map +1 -0
- package/dist/{types-BlAkSuGI.d.cts → types-DMuSQeLL.d.cts} +3 -5
- package/dist/types-DMuSQeLL.d.cts.map +1 -0
- package/dist/{types-aKksMEWL.d.mts → types-DMuSQeLL.d.mts} +3 -5
- package/dist/types-DMuSQeLL.d.mts.map +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -0
- package/dist/worker.cjs +59 -34
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +70 -45
- package/dist/worker.d.cts.map +1 -1
- package/dist/worker.d.mts +70 -44
- package/dist/worker.d.mts.map +1 -1
- package/dist/worker.mjs +54 -29
- package/dist/worker.mjs.map +1 -1
- package/package.json +96 -42
- package/dist/Construct-BD5neF7w.mjs.map +0 -1
- package/dist/Construct-C0ijr2qp.d.cts +0 -117
- package/dist/Construct-C0ijr2qp.d.cts.map +0 -1
- package/dist/Construct-Ct8nalEi.d.mts +0 -117
- package/dist/Construct-Ct8nalEi.d.mts.map +0 -1
- package/dist/Construct-CyS3RpTL.cjs.map +0 -1
- package/dist/Cron-DmQ8vQ4b.d.cts.map +0 -1
- package/dist/Cron-dh4rUgib.d.mts.map +0 -1
- package/dist/CronBuilder-BquXDbDI.d.cts +0 -44
- package/dist/CronBuilder-BquXDbDI.d.cts.map +0 -1
- package/dist/CronBuilder-CGgY2080.d.mts +0 -44
- package/dist/CronBuilder-CGgY2080.d.mts.map +0 -1
- package/dist/CronBuilder-CYKT5RiO.mjs.map +0 -1
- package/dist/CronBuilder-Da0C0edR.cjs.map +0 -1
- package/dist/Endpoint-BjWKinFA.d.mts.map +0 -1
- package/dist/Endpoint-DCQPMdUX.mjs.map +0 -1
- package/dist/Endpoint-DcWXE-SZ.cjs.map +0 -1
- package/dist/Endpoint-dav89W6-.d.cts.map +0 -1
- package/dist/EndpointFactory-CdWB7wPw.cjs.map +0 -1
- package/dist/EndpointFactory-CjV8F_lJ.mjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DtL9j19R.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-P1ahhZHu.mjs.map +0 -1
- package/dist/Queue-D7ZuwBhy.d.cts.map +0 -1
- package/dist/Queue-gVGfi2Yk.d.mts.map +0 -1
- package/dist/Subscriber-2mEi0ImH.d.cts.map +0 -1
- package/dist/Subscriber-xTJ9ayPN.d.mts.map +0 -1
- package/dist/SubscriberBuilder-4OPehf2R.cjs.map +0 -1
- package/dist/SubscriberBuilder-BjkbeT9l.mjs.map +0 -1
- package/dist/SubscriberBuilder-Dptmo-1A.d.mts +0 -62
- package/dist/SubscriberBuilder-Dptmo-1A.d.mts.map +0 -1
- package/dist/SubscriberBuilder-waNhzjSM.d.cts +0 -62
- package/dist/SubscriberBuilder-waNhzjSM.d.cts.map +0 -1
- package/dist/Topic-19QeHBIR.d.cts +0 -91
- package/dist/Topic-19QeHBIR.d.cts.map +0 -1
- package/dist/Topic-DuFeqkBh.d.mts +0 -91
- package/dist/Topic-DuFeqkBh.d.mts.map +0 -1
- package/dist/auth.d.cts.map +0 -1
- package/dist/auth.d.mts.map +0 -1
- package/dist/cache-0ANvRQnD.mjs +0 -51
- package/dist/cache-0ANvRQnD.mjs.map +0 -1
- package/dist/cache-3WSvAulx.cjs +0 -57
- package/dist/cache-3WSvAulx.cjs.map +0 -1
- package/dist/cache-BrRz3fEB.d.mts.map +0 -1
- package/dist/cache-BtZY_tHe.d.cts.map +0 -1
- package/dist/clone-DblgEZZa.mjs.map +0 -1
- package/dist/clone-Dy0cR2SZ.cjs.map +0 -1
- package/dist/construct-interface-BfjcOD_E.cjs +0 -117
- package/dist/construct-interface-BfjcOD_E.cjs.map +0 -1
- package/dist/construct-interface-D9d4Gm4p.d.cts.map +0 -1
- package/dist/construct-interface-Z4CpS8tK.mjs +0 -81
- package/dist/construct-interface-Z4CpS8tK.mjs.map +0 -1
- package/dist/construct-interface-g5GM5pwR.d.mts.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-i_la-N5r.cjs.map +0 -1
- package/dist/index-Bd5FqCoe.d.cts.map +0 -1
- package/dist/index-BknhM6Ux.d.mts +0 -31
- package/dist/index-BknhM6Ux.d.mts.map +0 -1
- package/dist/index-CBSfrowv.d.cts +0 -31
- package/dist/index-CBSfrowv.d.cts.map +0 -1
- package/dist/index-D24Xm79M.d.cts +0 -171
- package/dist/index-D24Xm79M.d.cts.map +0 -1
- package/dist/index-_ajboYxK.d.mts +0 -171
- package/dist/index-_ajboYxK.d.mts.map +0 -1
- package/dist/index-lAO9egTb.d.mts.map +0 -1
- package/dist/lazyAccessors-BoJN3SMd.mjs.map +0 -1
- package/dist/lazyAccessors-e3j2oE2m.cjs.map +0 -1
- package/dist/processAudits-CGqttuXm.cjs +0 -92
- package/dist/processAudits-CGqttuXm.cjs.map +0 -1
- package/dist/processAudits-Dmts9H_b.mjs +0 -80
- package/dist/processAudits-Dmts9H_b.mjs.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/surfaceEnv-BFXEms2f.cjs +0 -39
- package/dist/surfaceEnv-BFXEms2f.cjs.map +0 -1
- package/dist/surfaceEnv-C3Ktahea.mjs +0 -27
- package/dist/surfaceEnv-C3Ktahea.mjs.map +0 -1
- package/dist/telemetry-C3L0iS28.d.cts.map +0 -1
- package/dist/telemetry-D7bVFLGi.d.mts.map +0 -1
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.mjs.map +0 -1
- package/dist/types-BlAkSuGI.d.cts.map +0 -1
- package/dist/types-aKksMEWL.d.mts.map +0 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-y5ARvAq5.cjs");
|
|
2
|
+
const require_shutdown = require("./shutdown-BMJmAhSt.cjs");
|
|
3
|
+
const require_cache = require("./cache.cjs");
|
|
4
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
5
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
|
+
let kysely = require("kysely");
|
|
7
|
+
let _geekmidas_services = require("@geekmidas/services");
|
|
8
|
+
let pg = require("pg");
|
|
9
|
+
pg = require_rolldown_runtime.__toESM(pg, 1);
|
|
10
|
+
/** Every pool opened and not yet closed, so a shutdown can end them all. */
|
|
11
|
+
const open = /* @__PURE__ */ new Set();
|
|
12
|
+
require_shutdown.onShutdown(() => closeDatabasePools());
|
|
13
|
+
/**
|
|
14
|
+
* A pool for one URL, with its schema actually on the search path.
|
|
15
|
+
*
|
|
16
|
+
* `?search_path=` is not a libpq parameter — a URL carrying it connects
|
|
17
|
+
* happily and then resolves every unqualified name against `public`, which is
|
|
18
|
+
* how a schema tenant silently writes its tables into the database it was
|
|
19
|
+
* separated from. Postgres takes it as a startup option instead, so the URL
|
|
20
|
+
* keeps the readable form the target derives and this turns it into the thing
|
|
21
|
+
* the server understands.
|
|
22
|
+
*/
|
|
23
|
+
function openPool(url, options = {}) {
|
|
24
|
+
const parsed = new URL(url);
|
|
25
|
+
const searchPath = parsed.searchParams.get("search_path");
|
|
26
|
+
parsed.searchParams.delete("search_path");
|
|
27
|
+
const pool = new pg.default.Pool({
|
|
28
|
+
connectionString: parsed.toString(),
|
|
29
|
+
...searchPath ? { options: `-c search_path=${searchPath}` } : {},
|
|
30
|
+
fallback_application_name: applicationName()
|
|
31
|
+
});
|
|
32
|
+
pool.on("error", (error) => {
|
|
33
|
+
const logger = (0, _geekmidas_services.currentRequestContext)()?.logger;
|
|
34
|
+
if (logger) logger.warn({ err: error }, "Idle database connection lost");
|
|
35
|
+
else console.warn("Idle database connection lost:", error.message);
|
|
36
|
+
});
|
|
37
|
+
const target = connectionAttributes(parsed);
|
|
38
|
+
pool.on("connect", (client) => {
|
|
39
|
+
if (options.queryTags !== false) tagQueries(client);
|
|
40
|
+
traceQueries(client, target);
|
|
41
|
+
});
|
|
42
|
+
open.add(pool);
|
|
43
|
+
const end = pool.end.bind(pool);
|
|
44
|
+
pool.end = (async () => {
|
|
45
|
+
open.delete(pool);
|
|
46
|
+
await end();
|
|
47
|
+
});
|
|
48
|
+
return pool;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* End every pool opened, waiting for checked-out connections to come back.
|
|
52
|
+
* For a server's shutdown, after it has stopped taking requests.
|
|
53
|
+
*/
|
|
54
|
+
async function closeDatabasePools() {
|
|
55
|
+
await Promise.all([...open].map((pool) => pool.end()));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Who this process is, as Postgres will show it: the Lambda function, else the
|
|
59
|
+
* app — `GKM_APP_NAME` where an entry sets it, `gkm dev`'s app tag otherwise.
|
|
60
|
+
* Postgres keeps 63 bytes of it.
|
|
61
|
+
*/
|
|
62
|
+
function applicationName(env = process.env) {
|
|
63
|
+
return env.AWS_LAMBDA_FUNCTION_NAME || env.GKM_APP_NAME || env.GKM_DEV_APP?.split("#").pop() || void 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The comment that says what ran a query: the request's operation and id, and
|
|
67
|
+
* the active span as a W3C `traceparent` — the query's own span when it runs
|
|
68
|
+
* through a traced client, since the span wraps the tagging. '' with neither.
|
|
69
|
+
*
|
|
70
|
+
* The keys are in sqlcommenter's sorted order. Values keep only characters
|
|
71
|
+
* that cannot end a comment or a quoted value — `*` and `'` among those
|
|
72
|
+
* dropped — so a route cannot inject SQL through it.
|
|
73
|
+
*/
|
|
74
|
+
function queryTag() {
|
|
75
|
+
const request = (0, _geekmidas_services.currentRequestContext)();
|
|
76
|
+
const span = _opentelemetry_api.trace.getActiveSpan()?.spanContext();
|
|
77
|
+
const tags = [
|
|
78
|
+
["operation", request?.operation],
|
|
79
|
+
["request_id", request?.requestId],
|
|
80
|
+
["traceparent", span && (0, _opentelemetry_api.isSpanContextValid)(span) ? traceparent(span) : ""]
|
|
81
|
+
].filter((tag) => Boolean(tag[1]));
|
|
82
|
+
if (tags.length === 0) return "";
|
|
83
|
+
const clean = (value) => value.replace(/[^\w ./:{}@-]/g, "");
|
|
84
|
+
return ` /*${tags.map(([key, value]) => `${key}='${clean(value)}'`).join(",")}*/`;
|
|
85
|
+
}
|
|
86
|
+
/** A span as W3C trace context's `traceparent`, version 00. */
|
|
87
|
+
function traceparent(span) {
|
|
88
|
+
const flags = (span.traceFlags & 255).toString(16).padStart(2, "0");
|
|
89
|
+
return `00-${span.traceId}-${span.spanId}-${flags}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Append {@link queryTag} to everything `client` runs: a SQL string — what
|
|
93
|
+
* Kysely sends — or a query object such as a cursor's.
|
|
94
|
+
*/
|
|
95
|
+
function tagQueries(client) {
|
|
96
|
+
const query = client.query.bind(client);
|
|
97
|
+
client.query = ((first, ...rest) => {
|
|
98
|
+
const tag = queryTag();
|
|
99
|
+
if (tag && typeof first === "string") return query(first + tag, ...rest);
|
|
100
|
+
if (tag && first && typeof first === "object" && typeof first.text === "string") {
|
|
101
|
+
const config = first;
|
|
102
|
+
config.text += tag;
|
|
103
|
+
}
|
|
104
|
+
return query(first, ...rest);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** What every span of one pool says about where it connects. */
|
|
108
|
+
function connectionAttributes(url) {
|
|
109
|
+
const name = decodeURIComponent(url.pathname.slice(1));
|
|
110
|
+
return {
|
|
111
|
+
"db.system": "postgresql",
|
|
112
|
+
...name && { "db.name": name },
|
|
113
|
+
"server.address": url.hostname,
|
|
114
|
+
"server.port": Number(url.port || 5432)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const TRACER = "@geekmidas/constructs";
|
|
118
|
+
/** `select`, `insert`, … — the first keyword, or `with`'s main statement. */
|
|
119
|
+
const OPERATION = /^\s*(?:\/\*.*?\*\/\s*)?(\w+)/s;
|
|
120
|
+
/** The table a statement is about, when it names one where it usually does. */
|
|
121
|
+
const TABLE = /\b(?:from|into|update|join)\s+((?:"[^"]+"|[\w$]+)(?:\.(?:"[^"]+"|[\w$]+))?)/i;
|
|
122
|
+
/**
|
|
123
|
+
* What a statement does and to which table, parsed cheaply from its first
|
|
124
|
+
* characters: `select "orders"`, `insert "public"."users"`. A statement the
|
|
125
|
+
* patterns cannot read leaves `table` unset.
|
|
126
|
+
*/
|
|
127
|
+
function describeStatement(text) {
|
|
128
|
+
const head = text.length > 512 ? text.slice(0, 512) : text;
|
|
129
|
+
const operation = OPERATION.exec(head)?.[1]?.toLowerCase();
|
|
130
|
+
const table = TABLE.exec(head)?.[1]?.replace(/"/g, "");
|
|
131
|
+
return {
|
|
132
|
+
...operation && { operation },
|
|
133
|
+
...table && { table }
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A span around everything `client` runs — `<operation> <table>`, or
|
|
138
|
+
* `db.query` when the statement does not say.
|
|
139
|
+
*
|
|
140
|
+
* The statement text goes on the span only for a parameterized query — values
|
|
141
|
+
* passed separately, as Kysely always does — and truncated. Parameter values
|
|
142
|
+
* never do. A bare string with no values could hold anything a caller
|
|
143
|
+
* concatenated into it, so it gets no text at all.
|
|
144
|
+
*/
|
|
145
|
+
function traceQueries(client, connection) {
|
|
146
|
+
const query = client.query.bind(client);
|
|
147
|
+
client.query = ((first, ...rest) => {
|
|
148
|
+
const config = first && typeof first === "object" ? first : void 0;
|
|
149
|
+
const text = typeof first === "string" ? first : typeof config?.text === "string" ? config.text : void 0;
|
|
150
|
+
const values = typeof first === "string" ? rest[0] : config?.values;
|
|
151
|
+
const { operation, table } = text ? describeStatement(text) : {};
|
|
152
|
+
const span = _opentelemetry_api.trace.getTracer(TRACER).startSpan(operation && table ? `${operation} ${table}` : "db.query", {
|
|
153
|
+
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
154
|
+
attributes: {
|
|
155
|
+
...connection,
|
|
156
|
+
...operation && { "db.operation": operation },
|
|
157
|
+
...table && { "db.sql.table": table },
|
|
158
|
+
...text && Array.isArray(values) && { "db.statement": text.length > 2048 ? text.slice(0, 2048) : text }
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const end = (error) => {
|
|
162
|
+
if (error) {
|
|
163
|
+
if (error instanceof Error) span.recordException(error);
|
|
164
|
+
span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
165
|
+
}
|
|
166
|
+
span.end();
|
|
167
|
+
};
|
|
168
|
+
const last = rest[rest.length - 1];
|
|
169
|
+
if (typeof last === "function") {
|
|
170
|
+
const args = [...rest];
|
|
171
|
+
args[args.length - 1] = (error, ...result) => {
|
|
172
|
+
end(error);
|
|
173
|
+
return last(error, ...result);
|
|
174
|
+
};
|
|
175
|
+
return _opentelemetry_api.context.with(_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), span), () => query(first, ...args));
|
|
176
|
+
}
|
|
177
|
+
let result;
|
|
178
|
+
try {
|
|
179
|
+
result = _opentelemetry_api.context.with(_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), span), () => query(first, ...rest));
|
|
180
|
+
} catch (error) {
|
|
181
|
+
end(error);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
if (result && typeof result.then === "function") result.then(() => end(), (error) => end(error));
|
|
185
|
+
else if (result && typeof result.once === "function") {
|
|
186
|
+
const emitter = result;
|
|
187
|
+
emitter.once("end", () => end());
|
|
188
|
+
emitter.once("error", (error) => end(error));
|
|
189
|
+
} else end();
|
|
190
|
+
return result;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/database/kysely.ts
|
|
195
|
+
/**
|
|
196
|
+
* `KyselyDatabase` — a declared Postgres database, typed by its schema.
|
|
197
|
+
*
|
|
198
|
+
* It declares a logical database, a schema, and the roles that reach it, and
|
|
199
|
+
* hands back a Kysely client built from the one URL the adapter supplied. It
|
|
200
|
+
* names no cloud: `--target=aws` fills that URL from RDS, local dev from the
|
|
201
|
+
* Postgres container.
|
|
202
|
+
*
|
|
203
|
+
* Transactions and RLS context are the execution wrapper's job — it opens the
|
|
204
|
+
* transaction and puts it in `ctx.db`. This construct does not resolve
|
|
205
|
+
* connections per request.
|
|
206
|
+
*/
|
|
207
|
+
/** The schema a database uses when it does not say otherwise. */
|
|
208
|
+
const DEFAULT_SCHEMA = "app";
|
|
209
|
+
/**
|
|
210
|
+
* @typeParam DB - the database's schema.
|
|
211
|
+
* @typeParam TName - the canonical id. TypeScript has no partial
|
|
212
|
+
* type-argument inference, so `new KyselyDatabase<OrdersDB>('orders')` leaves
|
|
213
|
+
* this at its default and the service key widens to `string`. `db` still types
|
|
214
|
+
* through `.database()`, which infers from the service.
|
|
215
|
+
*/
|
|
216
|
+
var KyselyDatabase = class KyselyDatabase {
|
|
217
|
+
options;
|
|
218
|
+
id;
|
|
219
|
+
service;
|
|
220
|
+
/**
|
|
221
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
222
|
+
* build publishes and the key the client reads cannot drift.
|
|
223
|
+
*/
|
|
224
|
+
config;
|
|
225
|
+
schemaName;
|
|
226
|
+
roles;
|
|
227
|
+
version;
|
|
228
|
+
derivedFrom;
|
|
229
|
+
constructor(id, options = {}, derivedFrom) {
|
|
230
|
+
this.options = options;
|
|
231
|
+
const canonical = (0, _geekmidas_manifest.canonicalId)(id);
|
|
232
|
+
this.id = canonical;
|
|
233
|
+
this.config = {
|
|
234
|
+
url: (0, _geekmidas_manifest.provideKey)(canonical, "url"),
|
|
235
|
+
ownerUrl: (0, _geekmidas_manifest.provideKey)(canonical, "ownerUrl")
|
|
236
|
+
};
|
|
237
|
+
this.schemaName = options.schema ?? DEFAULT_SCHEMA;
|
|
238
|
+
this.roles = options.roles ?? true;
|
|
239
|
+
this.version = options.version ?? _geekmidas_manifest.DEFAULT_POSTGRES_VERSION;
|
|
240
|
+
this.derivedFrom = derivedFrom;
|
|
241
|
+
this.service = {
|
|
242
|
+
serviceName: (0, _geekmidas_manifest.serviceKey)(canonical),
|
|
243
|
+
register: (registerOptions) => this.connect(registerOptions)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
declare() {
|
|
247
|
+
if (this.derivedFrom) {
|
|
248
|
+
const { kind, of, schema } = this.derivedFrom;
|
|
249
|
+
return [kind === "database-schema" ? {
|
|
250
|
+
kind,
|
|
251
|
+
id: this.id,
|
|
252
|
+
of,
|
|
253
|
+
schema: schema ?? this.schemaName,
|
|
254
|
+
provides: [this.config.url]
|
|
255
|
+
} : {
|
|
256
|
+
kind,
|
|
257
|
+
id: this.id,
|
|
258
|
+
of,
|
|
259
|
+
provides: [this.config.url]
|
|
260
|
+
}];
|
|
261
|
+
}
|
|
262
|
+
return [{
|
|
263
|
+
kind: "database",
|
|
264
|
+
id: this.id,
|
|
265
|
+
engine: "postgres",
|
|
266
|
+
schema: this.schemaName,
|
|
267
|
+
version: this.version,
|
|
268
|
+
provides: [this.config.url],
|
|
269
|
+
...this.roles ? {} : { roles: false }
|
|
270
|
+
}];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* A read-only endpoint on this database.
|
|
274
|
+
*
|
|
275
|
+
* Read-only is enforced by the reader role's grants rather than by which
|
|
276
|
+
* endpoint it resolves to, so falling back to the writer where no replica
|
|
277
|
+
* exists is safe rather than a silently writable connection behind a name
|
|
278
|
+
* that says reader. There is no `writer()`: the database *is* the writer, so
|
|
279
|
+
* a replica can never be reached by accident.
|
|
280
|
+
*
|
|
281
|
+
* The return type is narrower than this class on purpose — see
|
|
282
|
+
* {@link ReadOnlyDatabase}.
|
|
283
|
+
*/
|
|
284
|
+
reader() {
|
|
285
|
+
return new KyselyDatabase(`${this.id}Reader`, this.options, {
|
|
286
|
+
kind: "database-reader",
|
|
287
|
+
of: this.id
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* A cache that lives in this database.
|
|
292
|
+
*
|
|
293
|
+
* The same strengthening `schema()` is over a second database: `new
|
|
294
|
+
* Cache('Sessions')` says the app caches and leaves where to the deployment,
|
|
295
|
+
* while this says it caches *here* — which is a fact about the application
|
|
296
|
+
* and so belongs in its code.
|
|
297
|
+
*
|
|
298
|
+
* What it buys beyond being explicit: the table's schema and the role that
|
|
299
|
+
* reaches it come from this database rather than from a second convention,
|
|
300
|
+
* and the backend no longer has to guess which database "the database" meant
|
|
301
|
+
* when an app declares two.
|
|
302
|
+
*
|
|
303
|
+
* A cache is not a `KyselyDatabase`, so this returns a `Cache` — the client
|
|
304
|
+
* is a key/value store, not a query builder, and typing it as the parent
|
|
305
|
+
* would be a convenience that lies.
|
|
306
|
+
*/
|
|
307
|
+
cache(id = `${this.id}Cache`, options = {}) {
|
|
308
|
+
return new require_cache.Cache(id, {
|
|
309
|
+
of: this.id,
|
|
310
|
+
...options.table ? { table: options.table } : {}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* A second schema in this database, with its own role(s) and its own URL —
|
|
315
|
+
* so this database's role holds no grant on those tables at all.
|
|
316
|
+
*
|
|
317
|
+
* Typed separately because a tenant has its own tables: the point is that
|
|
318
|
+
* `auth.selectFrom('sessions')` type-checks and
|
|
319
|
+
* `orders.selectFrom('sessions')` does not.
|
|
320
|
+
*/
|
|
321
|
+
schema(id, options = {}) {
|
|
322
|
+
return new KyselyDatabase(id, options, {
|
|
323
|
+
kind: "database-schema",
|
|
324
|
+
of: this.id,
|
|
325
|
+
schema: options.schema ?? id.toLowerCase()
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* A connection as the *owner* role — the one that may create, alter and drop.
|
|
330
|
+
*
|
|
331
|
+
* A `Service` rather than part of the construct, and deliberately so: a
|
|
332
|
+
* construct is what `.dependsOn()` accepts, and nothing should be able to
|
|
333
|
+
* depend on this. A migrator asks for it by name; a handler cannot ask at
|
|
334
|
+
* all, which is the security property the role split exists for.
|
|
335
|
+
*
|
|
336
|
+
* Falls back to the runtime URL where no owner URL was published — the
|
|
337
|
+
* `roles: false` downgrade, where there is only one credential and it is the
|
|
338
|
+
* cluster master's.
|
|
339
|
+
*/
|
|
340
|
+
get owner() {
|
|
341
|
+
return {
|
|
342
|
+
serviceName: `${(0, _geekmidas_manifest.serviceKey)(this.id)}Owner`,
|
|
343
|
+
register: (options) => this.connect(options, { owner: true })
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* What this database's clients are built with besides a dialect — the
|
|
348
|
+
* plugins and logging it was declared with.
|
|
349
|
+
*
|
|
350
|
+
* Public so that whatever opens a connection to it outside \`connect()\` —
|
|
351
|
+
* a test's transaction — builds the same client. A test that dropped the
|
|
352
|
+
* plugins would write \`createdAt\` where production writes \`created_at\`.
|
|
353
|
+
*/
|
|
354
|
+
get clientConfig() {
|
|
355
|
+
const { schema: _schema, roles: _roles, version: _version, queryTags: _queryTags, ...kysely$1 } = this.options;
|
|
356
|
+
return kysely$1;
|
|
357
|
+
}
|
|
358
|
+
async connect(options, as = {}) {
|
|
359
|
+
const { url, ownerUrl } = options.envParser.create((get) => ({
|
|
360
|
+
url: get(this.config.url).string(),
|
|
361
|
+
ownerUrl: get(this.config.ownerUrl).string().optional()
|
|
362
|
+
})).parse();
|
|
363
|
+
return new kysely.Kysely({
|
|
364
|
+
...this.clientConfig,
|
|
365
|
+
dialect: new kysely.PostgresDialect({ pool: openPool(as.owner ? ownerUrl ?? url : url, { queryTags: this.options.queryTags }) })
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
//#endregion
|
|
370
|
+
Object.defineProperty(exports, "KyselyDatabase", {
|
|
371
|
+
enumerable: true,
|
|
372
|
+
get: function() {
|
|
373
|
+
return KyselyDatabase;
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
Object.defineProperty(exports, "closeDatabasePools", {
|
|
377
|
+
enumerable: true,
|
|
378
|
+
get: function() {
|
|
379
|
+
return closeDatabasePools;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
//# sourceMappingURL=kysely-CO_Dk43W.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-CO_Dk43W.cjs","names":["onShutdown","currentRequestContext","trace","isSpanContextValid","SpanKind","SpanStatusCode","context","canonicalId","provideKey","DEFAULT_POSTGRES_VERSION","serviceKey","Cache","kysely","Kysely","PostgresDialect"],"sources":["../src/database/pool.ts","../src/database/kysely.ts"],"sourcesContent":["/**\n * The `pg` pools a database construct opens, and what every one of them gets:\n *\n * - **A name.** `application_name` is what `pg_stat_activity` shows beside a\n * connection. Without one, a database at `max_connections` cannot say who\n * holds them. It is a *fallback*, so `PGAPPNAME` or `?application_name=` in\n * the URL still win.\n * - **Tagged queries.** Inside a request, each query ends in a comment naming\n * what ran it — `/*operation='POST /orders',request_id='…'*\\/` — in the\n * sqlcommenter form, and inside a trace the query's own span as\n * `traceparent='00-<trace>-<span>-<flags>'`. It shows in\n * `pg_stat_activity.query`, in the server's slow-query and `auto_explain`\n * logs, and costs no round trip; `pg_stat_statements` ignores comments, so\n * its grouping is unchanged.\n * - **A listener for idle-client errors.** When the server ends an idle\n * connection (`idle_session_timeout`, a failover, an admin), the pool emits\n * `'error'`. With no listener that is an uncaught exception that kills the\n * process — for a client the pool has already discarded.\n * - **A span per query.** Through the global OpenTelemetry tracer, so a no-op\n * without a provider. `pg` is bundled into a production entry, where no\n * instrumentation can hook its module load — so the client is wrapped here,\n * as the tags are. See {@link traceQueries}.\n * - **A way to close.** {@link closeDatabasePools} ends every pool opened, so a\n * server shutting down releases its connections instead of holding them\n * until the process dies.\n */\n\nimport { currentRequestContext } from '@geekmidas/services';\nimport {\n\ttype Attributes,\n\tcontext,\n\tisSpanContextValid,\n\tSpanKind,\n\tSpanStatusCode,\n\ttrace,\n} from '@opentelemetry/api';\nimport pg from 'pg';\nimport { onShutdown } from '../shutdown';\n\nexport interface DatabasePoolOptions {\n\t/** Tag queries with what ran them and the trace they ran in. Default true. */\n\tqueryTags?: boolean;\n}\n\n/** The longest statement text a query span carries. */\nexport const MAX_STATEMENT_LENGTH = 2048;\n\n/** Every pool opened and not yet closed, so a shutdown can end them all. */\nconst open = new Set<pg.Pool>();\nonShutdown(() => closeDatabasePools());\n\n/**\n * A pool for one URL, with its schema actually on the search path.\n *\n * `?search_path=` is not a libpq parameter — a URL carrying it connects\n * happily and then resolves every unqualified name against `public`, which is\n * how a schema tenant silently writes its tables into the database it was\n * separated from. Postgres takes it as a startup option instead, so the URL\n * keeps the readable form the target derives and this turns it into the thing\n * the server understands.\n */\nexport function openPool(\n\turl: string,\n\toptions: DatabasePoolOptions = {},\n): pg.Pool {\n\tconst parsed = new URL(url);\n\tconst searchPath = parsed.searchParams.get('search_path');\n\tparsed.searchParams.delete('search_path');\n\n\tconst pool = new pg.Pool({\n\t\tconnectionString: parsed.toString(),\n\t\t...(searchPath ? { options: `-c search_path=${searchPath}` } : {}),\n\t\tfallback_application_name: applicationName(),\n\t});\n\n\tpool.on('error', (error) => {\n\t\tconst logger = currentRequestContext()?.logger;\n\t\tif (logger) logger.warn({ err: error }, 'Idle database connection lost');\n\t\telse console.warn('Idle database connection lost:', error.message);\n\t});\n\tconst target = connectionAttributes(parsed);\n\tpool.on('connect', (client) => {\n\t\t// Tags first, so the span wraps them: it records the statement as the\n\t\t// application wrote it rather than with the comment on the end, and it\n\t\t// is the active span when the tag is written — so the `traceparent` a\n\t\t// query carries names the query's own span.\n\t\tif (options.queryTags !== false) tagQueries(client);\n\t\ttraceQueries(client, target);\n\t});\n\n\topen.add(pool);\n\tconst end = pool.end.bind(pool);\n\tpool.end = (async () => {\n\t\topen.delete(pool);\n\t\tawait end();\n\t}) as typeof pool.end;\n\n\treturn pool;\n}\n\n/**\n * End every pool opened, waiting for checked-out connections to come back.\n * For a server's shutdown, after it has stopped taking requests.\n */\nexport async function closeDatabasePools(): Promise<void> {\n\tawait Promise.all([...open].map((pool) => pool.end()));\n}\n\n/**\n * Who this process is, as Postgres will show it: the Lambda function, else the\n * app — `GKM_APP_NAME` where an entry sets it, `gkm dev`'s app tag otherwise.\n * Postgres keeps 63 bytes of it.\n */\nexport function applicationName(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\treturn (\n\t\tenv.AWS_LAMBDA_FUNCTION_NAME ||\n\t\tenv.GKM_APP_NAME ||\n\t\tenv.GKM_DEV_APP?.split('#').pop() ||\n\t\tundefined\n\t);\n}\n\n/**\n * The comment that says what ran a query: the request's operation and id, and\n * the active span as a W3C `traceparent` — the query's own span when it runs\n * through a traced client, since the span wraps the tagging. '' with neither.\n *\n * The keys are in sqlcommenter's sorted order. Values keep only characters\n * that cannot end a comment or a quoted value — `*` and `'` among those\n * dropped — so a route cannot inject SQL through it.\n */\nexport function queryTag(): string {\n\tconst request = currentRequestContext();\n\tconst span = trace.getActiveSpan()?.spanContext();\n\n\tconst tags = [\n\t\t['operation', request?.operation],\n\t\t['request_id', request?.requestId],\n\t\t['traceparent', span && isSpanContextValid(span) ? traceparent(span) : ''],\n\t].filter((tag): tag is [string, string] => Boolean(tag[1]));\n\tif (tags.length === 0) return '';\n\n\tconst clean = (value: string) => value.replace(/[^\\w ./:{}@-]/g, '');\n\treturn ` /*${tags.map(([key, value]) => `${key}='${clean(value)}'`).join(',')}*/`;\n}\n\n/** A span as W3C trace context's `traceparent`, version 00. */\nfunction traceparent(span: {\n\ttraceId: string;\n\tspanId: string;\n\ttraceFlags: number;\n}): string {\n\tconst flags = (span.traceFlags & 0xff).toString(16).padStart(2, '0');\n\treturn `00-${span.traceId}-${span.spanId}-${flags}`;\n}\n\n/**\n * Append {@link queryTag} to everything `client` runs: a SQL string — what\n * Kysely sends — or a query object such as a cursor's.\n */\nfunction tagQueries(client: pg.PoolClient): void {\n\tconst query = client.query.bind(client) as (...args: unknown[]) => unknown;\n\tclient.query = ((first: unknown, ...rest: unknown[]) => {\n\t\tconst tag = queryTag();\n\t\tif (tag && typeof first === 'string') return query(first + tag, ...rest);\n\t\tif (\n\t\t\ttag &&\n\t\t\tfirst &&\n\t\t\ttypeof first === 'object' &&\n\t\t\ttypeof (first as { text?: unknown }).text === 'string'\n\t\t) {\n\t\t\tconst config = first as { text: string };\n\t\t\tconfig.text += tag;\n\t\t}\n\t\treturn query(first, ...rest);\n\t}) as typeof client.query;\n}\n\n/** What every span of one pool says about where it connects. */\nfunction connectionAttributes(url: URL): Attributes {\n\tconst name = decodeURIComponent(url.pathname.slice(1));\n\treturn {\n\t\t'db.system': 'postgresql',\n\t\t...(name && { 'db.name': name }),\n\t\t'server.address': url.hostname,\n\t\t'server.port': Number(url.port || 5432),\n\t};\n}\n\nconst TRACER = '@geekmidas/constructs';\n\n/** `select`, `insert`, … — the first keyword, or `with`'s main statement. */\nconst OPERATION = /^\\s*(?:\\/\\*.*?\\*\\/\\s*)?(\\w+)/s;\n/** The table a statement is about, when it names one where it usually does. */\nconst TABLE =\n\t/\\b(?:from|into|update|join)\\s+((?:\"[^\"]+\"|[\\w$]+)(?:\\.(?:\"[^\"]+\"|[\\w$]+))?)/i;\n\n/**\n * What a statement does and to which table, parsed cheaply from its first\n * characters: `select \"orders\"`, `insert \"public\".\"users\"`. A statement the\n * patterns cannot read leaves `table` unset.\n */\nexport function describeStatement(text: string): {\n\toperation?: string;\n\ttable?: string;\n} {\n\tconst head = text.length > 512 ? text.slice(0, 512) : text;\n\tconst operation = OPERATION.exec(head)?.[1]?.toLowerCase();\n\tconst table = TABLE.exec(head)?.[1]?.replace(/\"/g, '');\n\treturn {\n\t\t...(operation && { operation }),\n\t\t...(table && { table }),\n\t};\n}\n\n/**\n * A span around everything `client` runs — `<operation> <table>`, or\n * `db.query` when the statement does not say.\n *\n * The statement text goes on the span only for a parameterized query — values\n * passed separately, as Kysely always does — and truncated. Parameter values\n * never do. A bare string with no values could hold anything a caller\n * concatenated into it, so it gets no text at all.\n */\nfunction traceQueries(client: pg.PoolClient, connection: Attributes): void {\n\tconst query = client.query.bind(client) as (...args: unknown[]) => unknown;\n\tclient.query = ((first: unknown, ...rest: unknown[]) => {\n\t\tconst config =\n\t\t\tfirst && typeof first === 'object'\n\t\t\t\t? (first as { text?: unknown; values?: unknown })\n\t\t\t\t: undefined;\n\t\tconst text =\n\t\t\ttypeof first === 'string'\n\t\t\t\t? first\n\t\t\t\t: typeof config?.text === 'string'\n\t\t\t\t\t? config.text\n\t\t\t\t\t: undefined;\n\t\tconst values = typeof first === 'string' ? rest[0] : config?.values;\n\t\tconst { operation, table } = text ? describeStatement(text) : {};\n\n\t\tconst span = trace\n\t\t\t.getTracer(TRACER)\n\t\t\t.startSpan(operation && table ? `${operation} ${table}` : 'db.query', {\n\t\t\t\tkind: SpanKind.CLIENT,\n\t\t\t\tattributes: {\n\t\t\t\t\t...connection,\n\t\t\t\t\t...(operation && { 'db.operation': operation }),\n\t\t\t\t\t...(table && { 'db.sql.table': table }),\n\t\t\t\t\t...(text &&\n\t\t\t\t\t\tArray.isArray(values) && {\n\t\t\t\t\t\t\t'db.statement':\n\t\t\t\t\t\t\t\ttext.length > MAX_STATEMENT_LENGTH\n\t\t\t\t\t\t\t\t\t? text.slice(0, MAX_STATEMENT_LENGTH)\n\t\t\t\t\t\t\t\t\t: text,\n\t\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t});\n\t\tconst end = (error?: unknown) => {\n\t\t\tif (error) {\n\t\t\t\tif (error instanceof Error) span.recordException(error);\n\t\t\t\tspan.setStatus({ code: SpanStatusCode.ERROR });\n\t\t\t}\n\t\t\tspan.end();\n\t\t};\n\n\t\t// A callback, as `pg`'s own callback form takes it.\n\t\tconst last = rest[rest.length - 1];\n\t\tif (typeof last === 'function') {\n\t\t\tconst args = [...rest];\n\t\t\targs[args.length - 1] = (error: unknown, ...result: unknown[]) => {\n\t\t\t\tend(error);\n\t\t\t\treturn (last as (...a: unknown[]) => unknown)(error, ...result);\n\t\t\t};\n\t\t\treturn context.with(trace.setSpan(context.active(), span), () =>\n\t\t\t\tquery(first, ...args),\n\t\t\t);\n\t\t}\n\n\t\tlet result: unknown;\n\t\ttry {\n\t\t\tresult = context.with(trace.setSpan(context.active(), span), () =>\n\t\t\t\tquery(first, ...rest),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tend(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (result && typeof (result as Promise<unknown>).then === 'function') {\n\t\t\t(result as Promise<unknown>).then(\n\t\t\t\t() => end(),\n\t\t\t\t(error) => end(error),\n\t\t\t);\n\t\t} else if (\n\t\t\tresult &&\n\t\t\ttypeof (result as { once?: unknown }).once === 'function'\n\t\t) {\n\t\t\t// A submittable — a cursor or a stream — ends when it says so.\n\t\t\tconst emitter = result as {\n\t\t\t\tonce(event: string, fn: (e?: unknown) => void): void;\n\t\t\t};\n\t\t\temitter.once('end', () => end());\n\t\t\temitter.once('error', (error) => end(error));\n\t\t} else {\n\t\t\tend();\n\t\t}\n\t\treturn result;\n\t}) as typeof client.query;\n}\n","/**\n * `KyselyDatabase` — a declared Postgres database, typed by its schema.\n *\n * It declares a logical database, a schema, and the roles that reach it, and\n * hands back a Kysely client built from the one URL the adapter supplied. It\n * names no cloud: `--target=aws` fills that URL from RDS, local dev from the\n * Postgres container.\n *\n * Transactions and RLS context are the execution wrapper's job — it opens the\n * transaction and puts it in `ctx.db`. This construct does not resolve\n * connections per request.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\tDEFAULT_POSTGRES_VERSION,\n\ttype Declaration,\n\ttype PostgresVersion,\n\tprovideKey,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport { Kysely, type KyselyConfig, PostgresDialect } from 'kysely';\nimport { Cache } from '../cache';\nimport type { Construct } from '../construct-interface';\nimport { openPool } from './pool';\n\n/** The schema a database uses when it does not say otherwise. */\nconst DEFAULT_SCHEMA = 'app';\n\n/**\n * Everything Kysely takes, plus what this construct declares.\n *\n * `dialect` is omitted because the construct owns it — it is built from the one\n * URL the adapter supplied, which is the whole point of the construct. The rest\n * of `KyselyConfig` (`plugins`, `log`) is the app's business and passes\n * straight through, so anything Kysely adds later arrives without being\n * tracked here.\n */\nexport interface KyselyDatabaseOptions extends Omit<KyselyConfig, 'dialect'> {\n\t/**\n\t * The schema, pinned on both roles' `search_path`.\n\t *\n\t * Defaults to `app` — the role the schema plays, rather than a restatement\n\t * of the database's own name, which reads correctly beside `auth` and\n\t * `pgboss` and keeps the application off `public`.\n\t */\n\tschema?: string;\n\t/**\n\t * Provision the owner/runtime role split. Defaults to on.\n\t *\n\t * Off falls back to the cluster's master credential in both URLs, giving up\n\t * the DDL/DML split and putting credentials that can drop a table into the\n\t * function's environment. A deliberate downgrade, not a default.\n\t */\n\troles?: boolean;\n\t/**\n\t * The Postgres major version to provision.\n\t *\n\t * Declared here so one statement reaches both targets. It was previously\n\t * set in two unrelated places — a container tag locally, nothing at all on\n\t * AWS (so Aurora chose) — which is how local came to run 18 while deployed\n\t * ran 17.7 with nothing recording the difference.\n\t *\n\t * Defaults to {@link DEFAULT_POSTGRES_VERSION}.\n\t */\n\tversion?: PostgresVersion;\n\t/**\n\t * End each query run inside a request with a comment naming what ran it —\n\t * `/*operation='POST /orders',request_id='…'*\\/` — so `pg_stat_activity`\n\t * and the server's logs can tie a query to its endpoint — and, inside a\n\t * trace, with the query span's `traceparent='00-…'` (sqlcommenter), so\n\t * they can tie it to the trace too. Defaults to on.\n\t */\n\tqueryTags?: boolean;\n}\n\n/** What makes a construct derived rather than a database in its own right. */\ninterface DerivedFrom {\n\tkind: 'database-reader' | 'database-schema';\n\tof: string;\n\tschema?: string;\n}\n\n/**\n * @typeParam DB - the database's schema.\n * @typeParam TName - the canonical id. TypeScript has no partial\n * type-argument inference, so `new KyselyDatabase<OrdersDB>('orders')` leaves\n * this at its default and the service key widens to `string`. `db` still types\n * through `.database()`, which infers from the service.\n */\nexport class KyselyDatabase<DB = unknown, TName extends string = string>\n\timplements Construct<TName, Kysely<DB>>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, Kysely<DB>>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * build publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly config: { url: string; ownerUrl: string };\n\tprivate readonly schemaName: string;\n\tprivate readonly roles: boolean;\n\tprivate readonly version: PostgresVersion;\n\tprivate readonly derivedFrom?: DerivedFrom;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly options: KyselyDatabaseOptions = {},\n\t\tderivedFrom?: DerivedFrom,\n\t) {\n\t\t// Canonicalises, so `orders` and `Orders` are one construct rather than\n\t\t// two that collide. Throws on anything that cannot become a valid id.\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.config = {\n\t\t\turl: provideKey(canonical, 'url'),\n\t\t\townerUrl: provideKey(canonical, 'ownerUrl'),\n\t\t};\n\t\tthis.schemaName = options.schema ?? DEFAULT_SCHEMA;\n\t\tthis.roles = options.roles ?? true;\n\t\tthis.version = options.version ?? DEFAULT_POSTGRES_VERSION;\n\t\tthis.derivedFrom = derivedFrom;\n\n\t\t// A field, not a getter: service discovery caches by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\t// Forwards the whole options object — cherry-picking `envParser` strips\n\t\t\t// `context` and with it the request-scoped logger.\n\t\t\tregister: (registerOptions) => this.connect(registerOptions),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tif (this.derivedFrom) {\n\t\t\tconst { kind, of, schema } = this.derivedFrom;\n\n\t\t\treturn [\n\t\t\t\tkind === 'database-schema'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tid: this.id,\n\t\t\t\t\t\t\tof,\n\t\t\t\t\t\t\tschema: schema ?? this.schemaName,\n\t\t\t\t\t\t\t// The runtime key alone — see the note below on the parent.\n\t\t\t\t\t\t\tprovides: [this.config.url],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tid: this.id,\n\t\t\t\t\t\t\tof,\n\t\t\t\t\t\t\t// A reader has no owner URL of its own — nothing migrates\n\t\t\t\t\t\t\t// through a read-only endpoint — so this is the one key.\n\t\t\t\t\t\t\tprovides: [this.config.url],\n\t\t\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'database',\n\t\t\t\tid: this.id,\n\t\t\t\tengine: 'postgres',\n\t\t\t\tschema: this.schemaName,\n\t\t\t\tversion: this.version,\n\t\t\t\t// One key, the runtime role's. `config` also holds the owner key and\n\t\t\t\t// it is deliberately absent here: a key in `provides` is a key an\n\t\t\t\t// edge can name, and nothing should be able to depend on DDL rights.\n\t\t\t\tprovides: [this.config.url],\n\t\t\t\t...(this.roles ? {} : { roles: false }),\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * A read-only endpoint on this database.\n\t *\n\t * Read-only is enforced by the reader role's grants rather than by which\n\t * endpoint it resolves to, so falling back to the writer where no replica\n\t * exists is safe rather than a silently writable connection behind a name\n\t * that says reader. There is no `writer()`: the database *is* the writer, so\n\t * a replica can never be reached by accident.\n\t *\n\t * The return type is narrower than this class on purpose — see\n\t * {@link ReadOnlyDatabase}.\n\t */\n\treader(): ReadOnlyDatabase<DB, `${TName}Reader`> {\n\t\treturn new KyselyDatabase<DB, `${TName}Reader`>(\n\t\t\t`${this.id}Reader` as ConstructName<`${TName}Reader`>,\n\t\t\tthis.options,\n\t\t\t{ kind: 'database-reader', of: this.id },\n\t\t);\n\t}\n\n\t/**\n\t * A cache that lives in this database.\n\t *\n\t * The same strengthening `schema()` is over a second database: `new\n\t * Cache('Sessions')` says the app caches and leaves where to the deployment,\n\t * while this says it caches *here* — which is a fact about the application\n\t * and so belongs in its code.\n\t *\n\t * What it buys beyond being explicit: the table's schema and the role that\n\t * reaches it come from this database rather than from a second convention,\n\t * and the backend no longer has to guess which database \"the database\" meant\n\t * when an app declares two.\n\t *\n\t * A cache is not a `KyselyDatabase`, so this returns a `Cache` — the client\n\t * is a key/value store, not a query builder, and typing it as the parent\n\t * would be a convenience that lies.\n\t */\n\tcache<TCache extends string = `${TName}Cache`>(\n\t\tid: ConstructName<TCache> = `${this.id}Cache` as ConstructName<TCache>,\n\t\toptions: { table?: string } = {},\n\t): Cache<TCache> {\n\t\treturn new Cache<TCache>(id, {\n\t\t\tof: this.id,\n\t\t\t...(options.table ? { table: options.table } : {}),\n\t\t});\n\t}\n\n\t/**\n\t * A second schema in this database, with its own role(s) and its own URL —\n\t * so this database's role holds no grant on those tables at all.\n\t *\n\t * Typed separately because a tenant has its own tables: the point is that\n\t * `auth.selectFrom('sessions')` type-checks and\n\t * `orders.selectFrom('sessions')` does not.\n\t */\n\tschema<TenantDB, TTenant extends string>(\n\t\tid: ConstructName<TTenant>,\n\t\toptions: KyselyDatabaseOptions = {},\n\t): KyselyDatabase<TenantDB, TTenant> {\n\t\treturn new KyselyDatabase<TenantDB, TTenant>(id, options, {\n\t\t\tkind: 'database-schema',\n\t\t\tof: this.id,\n\t\t\tschema: options.schema ?? (id as string).toLowerCase(),\n\t\t});\n\t}\n\n\t/**\n\t * A connection as the *owner* role — the one that may create, alter and drop.\n\t *\n\t * A `Service` rather than part of the construct, and deliberately so: a\n\t * construct is what `.dependsOn()` accepts, and nothing should be able to\n\t * depend on this. A migrator asks for it by name; a handler cannot ask at\n\t * all, which is the security property the role split exists for.\n\t *\n\t * Falls back to the runtime URL where no owner URL was published — the\n\t * `roles: false` downgrade, where there is only one credential and it is the\n\t * cluster master's.\n\t */\n\tget owner(): Service<`${Uncapitalize<TName>}Owner`, Kysely<DB>> {\n\t\treturn {\n\t\t\tserviceName:\n\t\t\t\t`${serviceKey(this.id)}Owner` as `${Uncapitalize<TName>}Owner`,\n\t\t\tregister: (options) => this.connect(options, { owner: true }),\n\t\t};\n\t}\n\n\t/**\n\t * What this database's clients are built with besides a dialect — the\n\t * plugins and logging it was declared with.\n\t *\n\t * Public so that whatever opens a connection to it outside \\`connect()\\` —\n\t * a test's transaction — builds the same client. A test that dropped the\n\t * plugins would write \\`createdAt\\` where production writes \\`created_at\\`.\n\t */\n\tget clientConfig(): Omit<KyselyConfig, 'dialect'> {\n\t\t// Split what the manifest declared from what Kysely takes, so neither\n\t\t// leaks into the other: \\`schema\\`, \\`roles\\` and \\`version\\` describe\n\t\t// infrastructure and mean nothing to a client.\n\t\tconst {\n\t\t\tschema: _schema,\n\t\t\troles: _roles,\n\t\t\tversion: _version,\n\t\t\tqueryTags: _queryTags,\n\t\t\t...kysely\n\t\t} = this.options;\n\t\treturn kysely;\n\t}\n\n\tprivate async connect(\n\t\toptions: ServiceRegisterOptions,\n\t\tas: { owner?: boolean } = {},\n\t): Promise<Kysely<DB>> {\n\t\tconst { url, ownerUrl } = options.envParser\n\t\t\t.create((get) => ({\n\t\t\t\turl: get(this.config.url).string(),\n\t\t\t\townerUrl: get(this.config.ownerUrl).string().optional(),\n\t\t\t}))\n\t\t\t.parse();\n\n\t\treturn new Kysely<DB>({\n\t\t\t...this.clientConfig,\n\t\t\tdialect: new PostgresDialect({\n\t\t\t\tpool: openPool(as.owner ? (ownerUrl ?? url) : url, {\n\t\t\t\t\tqueryTags: this.options.queryTags,\n\t\t\t\t}),\n\t\t\t}),\n\t\t});\n\t}\n}\n\n/**\n * A database you may read through, and derive nothing from.\n *\n * A reader is terminal in the graph, and this is that fact in the type system.\n * `DERIVES_FROM` gives `cache` and `database-schema` no `database-reader`\n * parent, and there is no reader of a reader — so `orders.reader().cache(…)`\n * has always been illegal, but it type-checked and failed later at\n * `assertDerivations`. That is a long way round to learn that a read-only\n * endpoint cannot own a table something writes to.\n *\n * Omitting the three deriving methods rather than making them throw keeps the\n * failure where it costs least: the editor, on the line that wrote it.\n *\n * The result is deliberately not assignable back to `KyselyDatabase` — a\n * reader is not one, and anything that genuinely needs the writer should say\n * so.\n */\nexport type ReadOnlyDatabase<DB, TName extends string> = Omit<\n\tKyselyDatabase<DB, TName>,\n\t'reader' | 'cache' | 'schema'\n>;\nexport { closeDatabasePools } from './pool';\n"],"mappings":"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"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { n as Construct } from "./construct-interface-B1AfqRl4.cjs";
|
|
2
|
+
import { t as Cache } from "./cache-DnGDGly3.cjs";
|
|
3
|
+
import { Service } from "@geekmidas/services";
|
|
4
|
+
import { ConstructName, Declaration, PostgresVersion } from "@geekmidas/manifest";
|
|
5
|
+
import { Kysely, KyselyConfig } from "kysely";
|
|
6
|
+
import "pg";
|
|
7
|
+
//#region src/database/pool.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* End every pool opened, waiting for checked-out connections to come back.
|
|
10
|
+
* For a server's shutdown, after it has stopped taking requests.
|
|
11
|
+
*/
|
|
12
|
+
declare function closeDatabasePools(): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/database/kysely.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Everything Kysely takes, plus what this construct declares.
|
|
17
|
+
*
|
|
18
|
+
* `dialect` is omitted because the construct owns it — it is built from the one
|
|
19
|
+
* URL the adapter supplied, which is the whole point of the construct. The rest
|
|
20
|
+
* of `KyselyConfig` (`plugins`, `log`) is the app's business and passes
|
|
21
|
+
* straight through, so anything Kysely adds later arrives without being
|
|
22
|
+
* tracked here.
|
|
23
|
+
*/
|
|
24
|
+
interface KyselyDatabaseOptions extends Omit<KyselyConfig, 'dialect'> {
|
|
25
|
+
/**
|
|
26
|
+
* The schema, pinned on both roles' `search_path`.
|
|
27
|
+
*
|
|
28
|
+
* Defaults to `app` — the role the schema plays, rather than a restatement
|
|
29
|
+
* of the database's own name, which reads correctly beside `auth` and
|
|
30
|
+
* `pgboss` and keeps the application off `public`.
|
|
31
|
+
*/
|
|
32
|
+
schema?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Provision the owner/runtime role split. Defaults to on.
|
|
35
|
+
*
|
|
36
|
+
* Off falls back to the cluster's master credential in both URLs, giving up
|
|
37
|
+
* the DDL/DML split and putting credentials that can drop a table into the
|
|
38
|
+
* function's environment. A deliberate downgrade, not a default.
|
|
39
|
+
*/
|
|
40
|
+
roles?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The Postgres major version to provision.
|
|
43
|
+
*
|
|
44
|
+
* Declared here so one statement reaches both targets. It was previously
|
|
45
|
+
* set in two unrelated places — a container tag locally, nothing at all on
|
|
46
|
+
* AWS (so Aurora chose) — which is how local came to run 18 while deployed
|
|
47
|
+
* ran 17.7 with nothing recording the difference.
|
|
48
|
+
*
|
|
49
|
+
* Defaults to {@link DEFAULT_POSTGRES_VERSION}.
|
|
50
|
+
*/
|
|
51
|
+
version?: PostgresVersion;
|
|
52
|
+
/**
|
|
53
|
+
* End each query run inside a request with a comment naming what ran it —
|
|
54
|
+
* `/*operation='POST /orders',request_id='…'*\/` — so `pg_stat_activity`
|
|
55
|
+
* and the server's logs can tie a query to its endpoint — and, inside a
|
|
56
|
+
* trace, with the query span's `traceparent='00-…'` (sqlcommenter), so
|
|
57
|
+
* they can tie it to the trace too. Defaults to on.
|
|
58
|
+
*/
|
|
59
|
+
queryTags?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** What makes a construct derived rather than a database in its own right. */
|
|
62
|
+
interface DerivedFrom {
|
|
63
|
+
kind: 'database-reader' | 'database-schema';
|
|
64
|
+
of: string;
|
|
65
|
+
schema?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @typeParam DB - the database's schema.
|
|
69
|
+
* @typeParam TName - the canonical id. TypeScript has no partial
|
|
70
|
+
* type-argument inference, so `new KyselyDatabase<OrdersDB>('orders')` leaves
|
|
71
|
+
* this at its default and the service key widens to `string`. `db` still types
|
|
72
|
+
* through `.database()`, which infers from the service.
|
|
73
|
+
*/
|
|
74
|
+
declare class KyselyDatabase<DB = unknown, TName extends string = string> implements Construct<TName, Kysely<DB>> {
|
|
75
|
+
private readonly options;
|
|
76
|
+
readonly id: TName;
|
|
77
|
+
readonly service: Service<Uncapitalize<TName>, Kysely<DB>>;
|
|
78
|
+
/**
|
|
79
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
80
|
+
* build publishes and the key the client reads cannot drift.
|
|
81
|
+
*/
|
|
82
|
+
private readonly config;
|
|
83
|
+
private readonly schemaName;
|
|
84
|
+
private readonly roles;
|
|
85
|
+
private readonly version;
|
|
86
|
+
private readonly derivedFrom?;
|
|
87
|
+
constructor(id: ConstructName<TName>, options?: KyselyDatabaseOptions, derivedFrom?: DerivedFrom);
|
|
88
|
+
declare(): Declaration[];
|
|
89
|
+
/**
|
|
90
|
+
* A read-only endpoint on this database.
|
|
91
|
+
*
|
|
92
|
+
* Read-only is enforced by the reader role's grants rather than by which
|
|
93
|
+
* endpoint it resolves to, so falling back to the writer where no replica
|
|
94
|
+
* exists is safe rather than a silently writable connection behind a name
|
|
95
|
+
* that says reader. There is no `writer()`: the database *is* the writer, so
|
|
96
|
+
* a replica can never be reached by accident.
|
|
97
|
+
*
|
|
98
|
+
* The return type is narrower than this class on purpose — see
|
|
99
|
+
* {@link ReadOnlyDatabase}.
|
|
100
|
+
*/
|
|
101
|
+
reader(): ReadOnlyDatabase<DB, `${TName}Reader`>;
|
|
102
|
+
/**
|
|
103
|
+
* A cache that lives in this database.
|
|
104
|
+
*
|
|
105
|
+
* The same strengthening `schema()` is over a second database: `new
|
|
106
|
+
* Cache('Sessions')` says the app caches and leaves where to the deployment,
|
|
107
|
+
* while this says it caches *here* — which is a fact about the application
|
|
108
|
+
* and so belongs in its code.
|
|
109
|
+
*
|
|
110
|
+
* What it buys beyond being explicit: the table's schema and the role that
|
|
111
|
+
* reaches it come from this database rather than from a second convention,
|
|
112
|
+
* and the backend no longer has to guess which database "the database" meant
|
|
113
|
+
* when an app declares two.
|
|
114
|
+
*
|
|
115
|
+
* A cache is not a `KyselyDatabase`, so this returns a `Cache` — the client
|
|
116
|
+
* is a key/value store, not a query builder, and typing it as the parent
|
|
117
|
+
* would be a convenience that lies.
|
|
118
|
+
*/
|
|
119
|
+
cache<TCache extends string = `${TName}Cache`>(id?: ConstructName<TCache>, options?: {
|
|
120
|
+
table?: string;
|
|
121
|
+
}): Cache<TCache>;
|
|
122
|
+
/**
|
|
123
|
+
* A second schema in this database, with its own role(s) and its own URL —
|
|
124
|
+
* so this database's role holds no grant on those tables at all.
|
|
125
|
+
*
|
|
126
|
+
* Typed separately because a tenant has its own tables: the point is that
|
|
127
|
+
* `auth.selectFrom('sessions')` type-checks and
|
|
128
|
+
* `orders.selectFrom('sessions')` does not.
|
|
129
|
+
*/
|
|
130
|
+
schema<TenantDB, TTenant extends string>(id: ConstructName<TTenant>, options?: KyselyDatabaseOptions): KyselyDatabase<TenantDB, TTenant>;
|
|
131
|
+
/**
|
|
132
|
+
* A connection as the *owner* role — the one that may create, alter and drop.
|
|
133
|
+
*
|
|
134
|
+
* A `Service` rather than part of the construct, and deliberately so: a
|
|
135
|
+
* construct is what `.dependsOn()` accepts, and nothing should be able to
|
|
136
|
+
* depend on this. A migrator asks for it by name; a handler cannot ask at
|
|
137
|
+
* all, which is the security property the role split exists for.
|
|
138
|
+
*
|
|
139
|
+
* Falls back to the runtime URL where no owner URL was published — the
|
|
140
|
+
* `roles: false` downgrade, where there is only one credential and it is the
|
|
141
|
+
* cluster master's.
|
|
142
|
+
*/
|
|
143
|
+
get owner(): Service<`${Uncapitalize<TName>}Owner`, Kysely<DB>>;
|
|
144
|
+
/**
|
|
145
|
+
* What this database's clients are built with besides a dialect — the
|
|
146
|
+
* plugins and logging it was declared with.
|
|
147
|
+
*
|
|
148
|
+
* Public so that whatever opens a connection to it outside \`connect()\` —
|
|
149
|
+
* a test's transaction — builds the same client. A test that dropped the
|
|
150
|
+
* plugins would write \`createdAt\` where production writes \`created_at\`.
|
|
151
|
+
*/
|
|
152
|
+
get clientConfig(): Omit<KyselyConfig, 'dialect'>;
|
|
153
|
+
private connect;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A database you may read through, and derive nothing from.
|
|
157
|
+
*
|
|
158
|
+
* A reader is terminal in the graph, and this is that fact in the type system.
|
|
159
|
+
* `DERIVES_FROM` gives `cache` and `database-schema` no `database-reader`
|
|
160
|
+
* parent, and there is no reader of a reader — so `orders.reader().cache(…)`
|
|
161
|
+
* has always been illegal, but it type-checked and failed later at
|
|
162
|
+
* `assertDerivations`. That is a long way round to learn that a read-only
|
|
163
|
+
* endpoint cannot own a table something writes to.
|
|
164
|
+
*
|
|
165
|
+
* Omitting the three deriving methods rather than making them throw keeps the
|
|
166
|
+
* failure where it costs least: the editor, on the line that wrote it.
|
|
167
|
+
*
|
|
168
|
+
* The result is deliberately not assignable back to `KyselyDatabase` — a
|
|
169
|
+
* reader is not one, and anything that genuinely needs the writer should say
|
|
170
|
+
* so.
|
|
171
|
+
*/
|
|
172
|
+
type ReadOnlyDatabase<DB, TName extends string> = Omit<KyselyDatabase<DB, TName>, 'reader' | 'cache' | 'schema'>;
|
|
173
|
+
//#endregion
|
|
174
|
+
export { closeDatabasePools as i, KyselyDatabaseOptions as n, ReadOnlyDatabase as r, KyselyDatabase as t };
|
|
175
|
+
//# sourceMappingURL=kysely-D0bpzgPs.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-D0bpzgPs.d.cts","names":[],"sources":["../src/database/pool.ts","../src/database/kysely.ts"],"mappings":";;;;;;;;;;;iBAwGsB,sBAAsB;;;;;;;;;;;;UChE3B,8BAA8B,KAAK;;;;;;;;EAQnD;;;;;;;;EAQA;;;;;;;;;;;EAWA,UAAU;;;;;;;;EAQV;;;UAIS;EACT;EACA;EACA;;;;;;;;;cAUY,eAAe,cAAc,0CAC9B,UAAU,OAAO,OAAO;mBAiBjB;WAfT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ,OAAO;;;;;mBAMrC;mBACA;mBACA;mBACA;mBACA;EAEjB,YACC,IAAI,cAAc,QACD,UAAS,uBAC1B,cAAc;EAyBf,WAAW;;;;;;;;;;;;;EAqDX,UAAU,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;EAyBlC,MAAM,2BAA2B,cAChC,KAAI,cAAc,SAClB;IAAW;MACT,MAAM;;;;;;;;;EAeT,OAAO,UAAU,wBAChB,IAAI,cAAc,UAClB,UAAS,wBACP,eAAe,UAAU;;;;;;;;;;;;;MAoBxB,SAAS,WAAW,aAAa,eAAe,OAAO;;;;;;;;;MAgBvD,gBAAgB,KAAK;UAcX;;;;;;;;;;;;;;;;;;;KAuCH,iBAAiB,IAAI,wBAAwB,KACxD,eAAe,IAAI"}
|