@geekmidas/cli 10.0.0-alpha.18 → 10.0.0-alpha.181
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 +323 -380
- package/bin/adjacent-tsconfig.mjs +46 -8
- package/bin/gkm.mjs +11 -3
- package/bin/owning-tsconfig-jsx-register.mjs +18 -0
- package/bin/owning-tsconfig-jsx.mjs +108 -0
- package/dist/EndpointGenerator-CBKH87_b.mjs +1043 -0
- package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
- package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
- package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
- package/dist/LegacyStateStore-DvufVJjQ.cjs +124 -0
- package/dist/LegacyStateStore-DvufVJjQ.cjs.map +1 -0
- package/dist/LegacyStateStore-p-_Z8ucw.mjs +124 -0
- package/dist/LegacyStateStore-p-_Z8ucw.mjs.map +1 -0
- package/dist/LocalStateStore-BKAi5XsN.mjs +167 -0
- package/dist/LocalStateStore-BKAi5XsN.mjs.map +1 -0
- package/dist/LocalStateStore-DLDD6udB.cjs +178 -0
- package/dist/LocalStateStore-DLDD6udB.cjs.map +1 -0
- package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
- package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
- package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
- package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
- package/dist/S3StateStore-C8thID2w.mjs +223 -0
- package/dist/S3StateStore-C8thID2w.mjs.map +1 -0
- package/dist/S3StateStore-J3FztlVC.cjs +222 -0
- package/dist/S3StateStore-J3FztlVC.cjs.map +1 -0
- package/dist/SSMStateStore-0TQsme40.mjs +205 -0
- package/dist/SSMStateStore-0TQsme40.mjs.map +1 -0
- package/dist/SSMStateStore-DhkkSF1D.cjs +204 -0
- package/dist/SSMStateStore-DhkkSF1D.cjs.map +1 -0
- package/dist/SubscriberGenerator-B3jHf26s.mjs +787 -0
- package/dist/SubscriberGenerator-B3jHf26s.mjs.map +1 -0
- package/dist/SubscriberGenerator-JhwVlWBS.cjs +852 -0
- package/dist/SubscriberGenerator-JhwVlWBS.cjs.map +1 -0
- package/dist/add-DWCzdPLz.mjs +711 -0
- package/dist/add-DWCzdPLz.mjs.map +1 -0
- package/dist/add-gs34ewLG.cjs +713 -0
- package/dist/add-gs34ewLG.cjs.map +1 -0
- package/dist/appPorts-BoXMwolc.mjs +249 -0
- package/dist/appPorts-BoXMwolc.mjs.map +1 -0
- package/dist/appPorts-IW-OZmRi.cjs +296 -0
- package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
- package/dist/apps-C27qrbEe.cjs +5174 -0
- package/dist/apps-C27qrbEe.cjs.map +1 -0
- package/dist/apps-D2oTQasd.mjs +4650 -0
- package/dist/apps-D2oTQasd.mjs.map +1 -0
- package/dist/aws-BXfiWNbi.cjs +108 -0
- package/dist/aws-BXfiWNbi.cjs.map +1 -0
- package/dist/aws-BjvSTTcE.mjs +97 -0
- package/dist/aws-BjvSTTcE.mjs.map +1 -0
- package/dist/awsStore-BYYCmXiq.mjs +121 -0
- package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
- package/dist/awsStore-DKQUElJL.cjs +138 -0
- package/dist/awsStore-DKQUElJL.cjs.map +1 -0
- package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
- package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
- package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
- package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
- package/dist/backups/runner.cjs +519 -0
- package/dist/backups/runner.cjs.map +1 -0
- package/dist/backups/runner.d.cts +102 -0
- package/dist/backups/runner.d.cts.map +1 -0
- package/dist/backups/runner.d.mts +102 -0
- package/dist/backups/runner.d.mts.map +1 -0
- package/dist/backups/runner.mjs +506 -0
- package/dist/backups/runner.mjs.map +1 -0
- package/dist/{bundler-mwH7WOb1.mjs → bundler-CbT4y4H_.mjs} +68 -15
- package/dist/bundler-CbT4y4H_.mjs.map +1 -0
- package/dist/{bundler-mjqGAvu1.cjs → bundler-DGeOugof.cjs} +67 -14
- package/dist/bundler-DGeOugof.cjs.map +1 -0
- package/dist/cli-C-jUNT69.cjs +80 -0
- package/dist/cli-C-jUNT69.cjs.map +1 -0
- package/dist/cli-DKEJryS7.mjs +80 -0
- package/dist/cli-DKEJryS7.mjs.map +1 -0
- package/dist/clientTelemetry-BAwj6MOf.d.cts +10 -0
- package/dist/clientTelemetry-BAwj6MOf.d.cts.map +1 -0
- package/dist/clientTelemetry-CvamPJj_.d.mts +10 -0
- package/dist/clientTelemetry-CvamPJj_.d.mts.map +1 -0
- package/dist/compose-BpnSP2x7.mjs +2434 -0
- package/dist/compose-BpnSP2x7.mjs.map +1 -0
- package/dist/compose-DJAaJEqL.cjs +2925 -0
- package/dist/compose-DJAaJEqL.cjs.map +1 -0
- package/dist/compose-DmtR2f0l.cjs +3564 -0
- package/dist/compose-DmtR2f0l.cjs.map +1 -0
- package/dist/compose-Glqs13is.mjs +3451 -0
- package/dist/compose-Glqs13is.mjs.map +1 -0
- package/dist/config-BODxZemw.d.mts +291 -0
- package/dist/config-BODxZemw.d.mts.map +1 -0
- package/dist/config-C3U5HulX.d.cts +291 -0
- package/dist/config-C3U5HulX.d.cts.map +1 -0
- package/dist/config.cjs +457 -9
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +4 -117
- package/dist/config.d.mts +4 -117
- package/dist/config.mjs +441 -3
- package/dist/config.mjs.map +1 -0
- package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
- package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
- package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
- package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
- package/dist/databases-CV22HzrI.mjs +588 -0
- package/dist/databases-CV22HzrI.mjs.map +1 -0
- package/dist/databases-DwYYH2mX.cjs +703 -0
- package/dist/databases-DwYYH2mX.cjs.map +1 -0
- package/dist/dbTunnel-DUudiQWj.cjs +154 -0
- package/dist/dbTunnel-DUudiQWj.cjs.map +1 -0
- package/dist/dbTunnel-KgbAh2v1.mjs +154 -0
- package/dist/dbTunnel-KgbAh2v1.mjs.map +1 -0
- package/dist/define-BfrNaY82.mjs +106 -0
- package/dist/define-BfrNaY82.mjs.map +1 -0
- package/dist/define-zKgLY65H.cjs +153 -0
- package/dist/define-zKgLY65H.cjs.map +1 -0
- package/dist/deploy/public.cjs +211 -0
- package/dist/deploy/public.cjs.map +1 -0
- package/dist/deploy/public.d.cts +659 -0
- package/dist/deploy/public.d.cts.map +1 -0
- package/dist/deploy/public.d.mts +659 -0
- package/dist/deploy/public.d.mts.map +1 -0
- package/dist/deploy/public.mjs +144 -0
- package/dist/deploy/public.mjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
- package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
- package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
- package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
- package/dist/deploy/sniffer-hooks.cjs +1 -1
- package/dist/deploy/sniffer-hooks.mjs +1 -1
- package/dist/deploy/sniffer-loader.cjs +2 -2
- package/dist/deploy/sniffer-loader.mjs +1 -1
- package/dist/deploy/sniffer-routes-worker.cjs +2 -2
- package/dist/deploy/sniffer-routes-worker.mjs +1 -1
- package/dist/deploy-UkAiPzTp.mjs +3838 -0
- package/dist/deploy-UkAiPzTp.mjs.map +1 -0
- package/dist/deploy-ycRCutW9.cjs +3894 -0
- package/dist/deploy-ycRCutW9.cjs.map +1 -0
- package/dist/destroy-Cq5Un0kf.mjs +789 -0
- package/dist/destroy-Cq5Un0kf.mjs.map +1 -0
- package/dist/destroy-DzRzQcAR.cjs +790 -0
- package/dist/destroy-DzRzQcAR.cjs.map +1 -0
- package/dist/discover-Dfmn6HQ7.mjs +940 -0
- package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
- package/dist/discover-OXczlq08.cjs +1085 -0
- package/dist/discover-OXczlq08.cjs.map +1 -0
- package/dist/dns-7zc-Mc9k.cjs +2257 -0
- package/dist/dns-7zc-Mc9k.cjs.map +1 -0
- package/dist/dns-dl7WUWmB.mjs +1820 -0
- package/dist/dns-dl7WUWmB.mjs.map +1 -0
- package/dist/docker-BDqp9Pfn.cjs +1798 -0
- package/dist/docker-BDqp9Pfn.cjs.map +1 -0
- package/dist/docker-MjMWQSEN.mjs +1649 -0
- package/dist/docker-MjMWQSEN.mjs.map +1 -0
- package/dist/dokploy-B0xtYCzY.mjs +38 -0
- package/dist/dokploy-B0xtYCzY.mjs.map +1 -0
- package/dist/dokploy-D-pBRnSV.cjs +38 -0
- package/dist/dokploy-D-pBRnSV.cjs.map +1 -0
- package/dist/drivers-BQRb3KsL.mjs +294 -0
- package/dist/drivers-BQRb3KsL.mjs.map +1 -0
- package/dist/drivers-DP7__dJX.cjs +377 -0
- package/dist/drivers-DP7__dJX.cjs.map +1 -0
- package/dist/eas-9danFNrJ.mjs +334 -0
- package/dist/eas-9danFNrJ.mjs.map +1 -0
- package/dist/eas-BJRA27vb.cjs +337 -0
- package/dist/eas-BJRA27vb.cjs.map +1 -0
- package/dist/emit-C4KSXOeS.mjs +153 -0
- package/dist/emit-C4KSXOeS.mjs.map +1 -0
- package/dist/emit-DiW0kbue.cjs +164 -0
- package/dist/emit-DiW0kbue.cjs.map +1 -0
- package/dist/encryption-0IiNCA3O.cjs +90 -0
- package/dist/encryption-0IiNCA3O.cjs.map +1 -0
- package/dist/encryption-ZDhvgGvu.mjs +89 -0
- package/dist/encryption-ZDhvgGvu.mjs.map +1 -0
- package/dist/engine-Csnr6XDu.mjs +3217 -0
- package/dist/engine-Csnr6XDu.mjs.map +1 -0
- package/dist/engine-DpjIgsGn.cjs +3330 -0
- package/dist/engine-DpjIgsGn.cjs.map +1 -0
- package/dist/errors-C9uIyIDt.mjs +27 -0
- package/dist/errors-C9uIyIDt.mjs.map +1 -0
- package/dist/errors-D1x8duqI.cjs +38 -0
- package/dist/errors-D1x8duqI.cjs.map +1 -0
- package/dist/github-Dej8EWxH.mjs +986 -0
- package/dist/github-Dej8EWxH.mjs.map +1 -0
- package/dist/github-HHxVur1m.cjs +987 -0
- package/dist/github-HHxVur1m.cjs.map +1 -0
- package/dist/googlePlay-DNrD-67X.mjs +931 -0
- package/dist/googlePlay-DNrD-67X.mjs.map +1 -0
- package/dist/googlePlay-NK1zgJJm.cjs +931 -0
- package/dist/googlePlay-NK1zgJJm.cjs.map +1 -0
- package/dist/iam-BzFyFf7T.mjs +442 -0
- package/dist/iam-BzFyFf7T.mjs.map +1 -0
- package/dist/iam-WIoKnLBp.cjs +521 -0
- package/dist/iam-WIoKnLBp.cjs.map +1 -0
- package/dist/{index-RCUizGxL.d.cts → index-BKgOlfK2.d.mts} +38 -14
- package/dist/index-BKgOlfK2.d.mts.map +1 -0
- package/dist/{index-B4H4XF7A.d.mts → index-zPzigXh-.d.cts} +38 -14
- package/dist/index-zPzigXh-.d.cts.map +1 -0
- package/dist/index.cjs +14502 -12767
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15137 -13400
- package/dist/index.mjs.map +1 -1
- package/dist/local-BW_VIsx0.cjs +241 -0
- package/dist/local-BW_VIsx0.cjs.map +1 -0
- package/dist/local-CVp-4wDb.mjs +224 -0
- package/dist/local-CVp-4wDb.mjs.map +1 -0
- package/dist/migrate-B8fq5egU.cjs +272 -0
- package/dist/migrate-B8fq5egU.cjs.map +1 -0
- package/dist/migrate-C8yCZ5P3.mjs +181 -0
- package/dist/migrate-C8yCZ5P3.mjs.map +1 -0
- package/dist/migrate-CkSq2f7k.mjs +267 -0
- package/dist/migrate-CkSq2f7k.mjs.map +1 -0
- package/dist/migrate-FOc2erAl.cjs +181 -0
- package/dist/migrate-FOc2erAl.cjs.map +1 -0
- package/dist/next.cjs +59 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +44 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.mts +44 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +58 -0
- package/dist/next.mjs.map +1 -0
- package/dist/notes--JQyDHim.cjs +510 -0
- package/dist/notes--JQyDHim.cjs.map +1 -0
- package/dist/notes-DXl9qERh.mjs +409 -0
- package/dist/notes-DXl9qERh.mjs.map +1 -0
- package/dist/openapi.cjs +213 -7
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +27 -8
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +27 -8
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +208 -2
- package/dist/openapi.mjs.map +1 -0
- package/dist/projectBucket-CGpcWqyY.cjs +263 -0
- package/dist/projectBucket-CGpcWqyY.cjs.map +1 -0
- package/dist/projectBucket-TigJy25c.mjs +222 -0
- package/dist/projectBucket-TigJy25c.mjs.map +1 -0
- package/dist/provider-BvjDbsTR.mjs +46 -0
- package/dist/provider-BvjDbsTR.mjs.map +1 -0
- package/dist/provider-DLhgo-mB.cjs +57 -0
- package/dist/provider-DLhgo-mB.cjs.map +1 -0
- package/dist/publish-BPfW3DWi.mjs +123 -0
- package/dist/publish-BPfW3DWi.mjs.map +1 -0
- package/dist/publish-D4pC6_G0.cjs +124 -0
- package/dist/publish-D4pC6_G0.cjs.map +1 -0
- package/dist/ready-BcV28QoW.mjs +375 -0
- package/dist/ready-BcV28QoW.mjs.map +1 -0
- package/dist/ready-ByQvw4-W.cjs +404 -0
- package/dist/ready-ByQvw4-W.cjs.map +1 -0
- package/dist/reconcile/public.cjs +3 -5
- package/dist/reconcile/public.d.cts +33 -89
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +33 -89
- package/dist/reconcile/public.d.mts.map +1 -1
- package/dist/reconcile/public.mjs +3 -3
- package/dist/reconcile--I7V4Klj.mjs +34 -0
- package/dist/reconcile--I7V4Klj.mjs.map +1 -0
- package/dist/reconcile-CuCQBa5-.cjs +34 -0
- package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
- package/dist/resolve-BmBR1vBr.cjs +316 -0
- package/dist/resolve-BmBR1vBr.cjs.map +1 -0
- package/dist/resolve-DA1kORng.mjs +263 -0
- package/dist/resolve-DA1kORng.mjs.map +1 -0
- package/dist/rollback-DlgQDX8m.mjs +136 -0
- package/dist/rollback-DlgQDX8m.mjs.map +1 -0
- package/dist/rollback-tsy4pyEp.cjs +165 -0
- package/dist/rollback-tsy4pyEp.cjs.map +1 -0
- package/dist/runtime-CaejlcZt.d.mts +82 -0
- package/dist/runtime-CaejlcZt.d.mts.map +1 -0
- package/dist/runtime-D3jD4Dvn.d.cts +82 -0
- package/dist/runtime-D3jD4Dvn.d.cts.map +1 -0
- package/dist/s3-BLEF-PQU.cjs +240 -0
- package/dist/s3-BLEF-PQU.cjs.map +1 -0
- package/dist/s3-DVYiOqWs.mjs +240 -0
- package/dist/s3-DVYiOqWs.mjs.map +1 -0
- package/dist/sandbox/config-worker.cjs +43 -0
- package/dist/sandbox/config-worker.cjs.map +1 -0
- package/dist/sandbox/config-worker.d.cts +1 -0
- package/dist/sandbox/config-worker.d.mts +1 -0
- package/dist/sandbox/config-worker.mjs +44 -0
- package/dist/sandbox/config-worker.mjs.map +1 -0
- package/dist/sandbox/credentials-worker.cjs +53 -0
- package/dist/sandbox/credentials-worker.cjs.map +1 -0
- package/dist/sandbox/credentials-worker.d.cts +1 -0
- package/dist/sandbox/credentials-worker.d.mts +1 -0
- package/dist/sandbox/credentials-worker.mjs +54 -0
- package/dist/sandbox/credentials-worker.mjs.map +1 -0
- package/dist/sandbox/discover-worker.cjs +47 -0
- package/dist/sandbox/discover-worker.cjs.map +1 -0
- package/dist/sandbox/discover-worker.d.cts +1 -0
- package/dist/sandbox/discover-worker.d.mts +1 -0
- package/dist/sandbox/discover-worker.mjs +48 -0
- package/dist/sandbox/discover-worker.mjs.map +1 -0
- package/dist/sandbox/migrate-worker.cjs +75 -0
- package/dist/sandbox/migrate-worker.cjs.map +1 -0
- package/dist/sandbox/migrate-worker.d.cts +1 -0
- package/dist/sandbox/migrate-worker.d.mts +1 -0
- package/dist/sandbox/migrate-worker.mjs +76 -0
- package/dist/sandbox/migrate-worker.mjs.map +1 -0
- package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
- package/dist/schemas-BCwKKA42.mjs.map +1 -0
- package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
- package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
- package/dist/secretsManager-CjTo6CRq.mjs +113 -0
- package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
- package/dist/secretsManager-CvmBGjdM.cjs +124 -0
- package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
- package/dist/seeds-Bc3niNVb.cjs +382 -0
- package/dist/seeds-Bc3niNVb.cjs.map +1 -0
- package/dist/seeds-Ccn0Ru2T.mjs +299 -0
- package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
- package/dist/serverSetup-B_O65wLb.cjs +685 -0
- package/dist/serverSetup-B_O65wLb.cjs.map +1 -0
- package/dist/serverSetup-Dsy8drIb.mjs +685 -0
- package/dist/serverSetup-Dsy8drIb.mjs.map +1 -0
- package/dist/sniffer-Ckx4cr-o.cjs +1997 -0
- package/dist/sniffer-Ckx4cr-o.cjs.map +1 -0
- package/dist/sniffer-fBefNUuJ.mjs +1824 -0
- package/dist/sniffer-fBefNUuJ.mjs.map +1 -0
- package/dist/snsSubscriptions-BJ0LErGk.mjs +1010 -0
- package/dist/snsSubscriptions-BJ0LErGk.mjs.map +1 -0
- package/dist/snsSubscriptions-ChbFp-QP.cjs +1135 -0
- package/dist/snsSubscriptions-ChbFp-QP.cjs.map +1 -0
- package/dist/sst-BnuPeGyy.cjs +501 -0
- package/dist/sst-BnuPeGyy.cjs.map +1 -0
- package/dist/sst-Y7H_zaEZ.mjs +478 -0
- package/dist/sst-Y7H_zaEZ.mjs.map +1 -0
- package/dist/stack-BAipv5Js.cjs +1887 -0
- package/dist/stack-BAipv5Js.cjs.map +1 -0
- package/dist/stack-BHrGbsGA.mjs +1777 -0
- package/dist/stack-BHrGbsGA.mjs.map +1 -0
- package/dist/stage-BSZ9890H.mjs +303 -0
- package/dist/stage-BSZ9890H.mjs.map +1 -0
- package/dist/stage-D7vBtLXL.cjs +332 -0
- package/dist/stage-D7vBtLXL.cjs.map +1 -0
- package/dist/stages-BeSQQQ4z.cjs +190 -0
- package/dist/stages-BeSQQQ4z.cjs.map +1 -0
- package/dist/stages-DjFKQv08.mjs +190 -0
- package/dist/stages-DjFKQv08.mjs.map +1 -0
- package/dist/target/public.cjs +15 -0
- package/dist/target/public.d.cts +28 -0
- package/dist/target/public.d.cts.map +1 -0
- package/dist/target/public.d.mts +28 -0
- package/dist/target/public.d.mts.map +1 -0
- package/dist/target/public.mjs +4 -0
- package/dist/terminal-B7G-FtkD.cjs +85 -0
- package/dist/terminal-B7G-FtkD.cjs.map +1 -0
- package/dist/terminal-lp8RwHdX.mjs +85 -0
- package/dist/terminal-lp8RwHdX.mjs.map +1 -0
- package/dist/{types-7R81hu0i.d.mts → types-CLxsw-QY.d.cts} +2135 -428
- package/dist/types-CLxsw-QY.d.cts.map +1 -0
- package/dist/{types-N7c2O2m7.d.cts → types-wLlwkSib.d.mts} +2133 -428
- package/dist/types-wLlwkSib.d.mts.map +1 -0
- package/dist/utils-D2Nk1Nv2.cjs +205 -0
- package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
- package/dist/utils-D_fxUqvU.mjs +156 -0
- package/dist/utils-D_fxUqvU.mjs.map +1 -0
- package/dist/vitest.cjs +65 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +29 -0
- package/dist/vitest.d.cts.map +1 -0
- package/dist/vitest.d.mts +29 -0
- package/dist/vitest.d.mts.map +1 -0
- package/dist/vitest.mjs +65 -0
- package/dist/vitest.mjs.map +1 -0
- package/dist/workerRuntime-BXfhbe13.cjs +108 -0
- package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
- package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
- package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
- package/dist/workspace/index.cjs +6 -2
- package/dist/workspace/index.d.cts +3 -3
- package/dist/workspace/index.d.mts +3 -3
- package/dist/workspace/index.mjs +2 -2
- package/dist/workspace-DJjhfAGf.mjs +3027 -0
- package/dist/workspace-DJjhfAGf.mjs.map +1 -0
- package/dist/workspace-wTLnc1Ef.cjs +3577 -0
- package/dist/workspace-wTLnc1Ef.cjs.map +1 -0
- package/package.json +76 -13
- package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
- package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
- package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
- package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
- package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
- package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
- package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
- package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
- package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
- package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
- package/dist/Route53Provider-DVILBsvV.cjs +0 -209
- package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
- package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
- package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
- package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
- package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
- package/dist/bundler-mjqGAvu1.cjs.map +0 -1
- package/dist/bundler-mwH7WOb1.mjs.map +0 -1
- package/dist/config-DSXI480r.cjs +0 -467
- package/dist/config-DSXI480r.cjs.map +0 -1
- package/dist/config-DdKkoUE1.mjs +0 -414
- package/dist/config-DdKkoUE1.mjs.map +0 -1
- package/dist/config.d.cts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/credentials-C6Pfn6GY.cjs +0 -2939
- package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
- package/dist/credentials-lbv-j0Be.mjs +0 -2802
- package/dist/credentials-lbv-j0Be.mjs.map +0 -1
- package/dist/discover-BERGFg8v.cjs +0 -288
- package/dist/discover-BERGFg8v.cjs.map +0 -1
- package/dist/discover-CK-n3w6b.mjs +0 -244
- package/dist/discover-CK-n3w6b.mjs.map +0 -1
- package/dist/emit-BdoPFjZf.cjs +0 -253
- package/dist/emit-BdoPFjZf.cjs.map +0 -1
- package/dist/emit-Bzq7JsMP.mjs +0 -224
- package/dist/emit-Bzq7JsMP.mjs.map +0 -1
- package/dist/generator-LfZU7NlU.mjs +0 -247
- package/dist/generator-LfZU7NlU.mjs.map +0 -1
- package/dist/generator-Wdfp0jCS.cjs +0 -282
- package/dist/generator-Wdfp0jCS.cjs.map +0 -1
- package/dist/github-DlIrXPee.mjs +0 -216
- package/dist/github-DlIrXPee.mjs.map +0 -1
- package/dist/github-n7N9yOff.cjs +0 -216
- package/dist/github-n7N9yOff.cjs.map +0 -1
- package/dist/index-B4H4XF7A.d.mts.map +0 -1
- package/dist/index-RCUizGxL.d.cts.map +0 -1
- package/dist/openapi-B8bu_OXN.cjs +0 -2038
- package/dist/openapi-B8bu_OXN.cjs.map +0 -1
- package/dist/openapi-DfjbhrsM.mjs +0 -1991
- package/dist/openapi-DfjbhrsM.mjs.map +0 -1
- package/dist/reconcile-Cq4cO83R.cjs +0 -136
- package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
- package/dist/reconcile-fmoluZmZ.mjs +0 -113
- package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
- package/dist/ssm-BKN1Cg4z.mjs +0 -60
- package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
- package/dist/ssm-FxeSAt35.cjs +0 -60
- package/dist/ssm-FxeSAt35.cjs.map +0 -1
- package/dist/storage-DgypfSD6.cjs +0 -351
- package/dist/storage-DgypfSD6.cjs.map +0 -1
- package/dist/storage-TP0x118M.mjs +0 -304
- package/dist/storage-TP0x118M.mjs.map +0 -1
- package/dist/transfer-2aRVVJ6I.mjs +0 -122
- package/dist/transfer-2aRVVJ6I.mjs.map +0 -1
- package/dist/transfer-C3WZVmj_.cjs +0 -151
- package/dist/transfer-C3WZVmj_.cjs.map +0 -1
- package/dist/types-7R81hu0i.d.mts.map +0 -1
- package/dist/types-N7c2O2m7.d.cts.map +0 -1
- package/dist/workspace-Bu3xNCej.mjs.map +0 -1
- package/dist/workspace-CRD9YinV.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"databases-DwYYH2mX.cjs","names":["GkmError","readdir","extname","join","pathToFileURL","stat","readFile","GkmError","driversFor","cacheBackendsIn","eventsBackendsIn","join","mkdir","writeFile","pathToFileURL","createHash","GkmError","join","migrationTargets","MIGRATIONS_ROOT","canonicalId","readdir","DATABASE_FOLDERS","providedKeyFor","require","createRequire","pathToFileURL"],"sources":["../src/migrate/provider.ts","../src/migrate/seedDrivers.ts","../src/migrate/databases.ts"],"sourcesContent":["/**\n * One construct's migrations and seeds, read from its folders.\n *\n * Two kinds of file, told apart by extension rather than by configuration: a\n * script exports `up` (and may export `down`) — or `seed(db, { stage })`, in\n * `seeds/` — and a\n * `.sql` file is run whole. The second is what makes a folder independent of\n * the client the app uses — Better Auth's schema is SQL whatever the\n * application queries with.\n */\n\nimport { readdir, readFile, stat } from 'node:fs/promises';\nimport { extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { SeedContext } from '@geekmidas/constructs';\nimport type { Kysely, sql } from 'kysely';\nimport type { Migration, MigrationProvider } from 'kysely/migration';\nimport { GkmError } from '../errors';\n\nconst SCRIPTS = new Set(['.ts', '.mts', '.js', '.mjs']);\n\n/** Two files in one folder that would be one migration. */\nexport class DuplicateMigration extends GkmError {\n\tconstructor(\n\t\treadonly folder: string,\n\t\treadonly migration: string,\n\t) {\n\t\tsuper(\n\t\t\t`${folder} has two migrations named '${migration}' — a script and a .sql file ` +\n\t\t\t\t`with the same name. A migration is recorded by name, so only one of ` +\n\t\t\t\t`them could ever run; rename or remove the other.`,\n\t\t);\n\t\tthis.name = 'DuplicateMigration';\n\t}\n}\n\n/** A script in a migrations folder that exports no `up`. */\nexport class MigrationHasNoUp extends GkmError {\n\tconstructor(readonly file: string) {\n\t\tsuper(\n\t\t\t`${file} is in a migrations folder but exports no \\`up\\` function. ` +\n\t\t\t\t`Export \\`async function up(db: Kysely<unknown>)\\`, or move the file ` +\n\t\t\t\t`out of the folder if it is not a migration.`,\n\t\t);\n\t\tthis.name = 'MigrationHasNoUp';\n\t}\n}\n\n/** A script in a seeds folder that exports no `seed`. */\nexport class SeedHasNoSeed extends GkmError {\n\tconstructor(readonly file: string) {\n\t\tsuper(\n\t\t\t`${file} is in a seeds folder but exports no \\`seed\\` function. ` +\n\t\t\t\t`Export \\`async function seed(db, { stage })\\`, or move the ` +\n\t\t\t\t`file out of the folder if it is not a seed.`,\n\t\t);\n\t\tthis.name = 'SeedHasNoSeed';\n\t}\n}\n\n/**\n * What a seed is handed beside its database — `@geekmidas/constructs`'\n * `SeedContext`, whose `stage` is the union of the declared stages once\n * `.gkm/stages.d.ts` is generated.\n */\nexport type { SeedContext };\n\n/** One seed: what it is called, and what it does. */\nexport interface Seed {\n\tname: string;\n\trun: (db: Kysely<unknown>, context: SeedContext) => Promise<void>;\n}\n\n/**\n * The migration files in a folder, by name, without reading them.\n *\n * Also what `gkm dev` compares against a construct's history to report what\n * is pending, which is why it is separate from loading them.\n */\nexport async function migrationFiles(\n\tfolder: string,\n): Promise<Map<string, string>> {\n\tconst entries = await readdir(folder, { withFileTypes: true }).catch(\n\t\t(error: NodeJS.ErrnoException) => {\n\t\t\tif (error.code === 'ENOENT') return [];\n\t\t\tthrow error;\n\t\t},\n\t);\n\n\tconst files = new Map<string, string>();\n\tfor (const entry of entries) {\n\t\tif (!entry.isFile() || !isMigration(entry.name)) continue;\n\n\t\tconst name = entry.name.slice(0, -extname(entry.name).length);\n\t\tif (files.has(name)) throw new DuplicateMigration(folder, name);\n\n\t\tfiles.set(name, join(folder, entry.name));\n\t}\n\n\treturn files;\n}\n\n/** A Kysely provider over one construct's folder. */\nexport function folderProvider(\n\tfolder: string,\n\traw: typeof sql,\n): MigrationProvider {\n\treturn {\n\t\tasync getMigrations() {\n\t\t\tconst migrations: Record<string, Migration> = {};\n\n\t\t\tfor (const [name, file] of await migrationFiles(folder)) {\n\t\t\t\tmigrations[name] =\n\t\t\t\t\textname(file) === '.sql'\n\t\t\t\t\t\t? await sqlMigration(file, raw)\n\t\t\t\t\t\t: await scriptMigration(file);\n\t\t\t}\n\n\t\t\treturn migrations;\n\t\t},\n\t};\n}\n\n/**\n * The seeds in a folder, loaded, in name order.\n *\n * Every one runs on every pass — there is no history to consult — so the order\n * is the only thing between two seeds where one reads what another writes.\n * Name them to sort that way.\n */\nexport async function loadSeeds(\n\tfolder: string,\n\traw: typeof sql,\n): Promise<Seed[]> {\n\tconst files = [...(await migrationFiles(folder))].sort(([a], [b]) =>\n\t\ta < b ? -1 : a > b ? 1 : 0,\n\t);\n\n\tconst seeds: Seed[] = [];\n\tfor (const [name, file] of files) {\n\t\tseeds.push({\n\t\t\tname,\n\t\t\trun:\n\t\t\t\textname(file) === '.sql'\n\t\t\t\t\t? (await sqlMigration(file, raw)).up\n\t\t\t\t\t: await scriptSeed(file),\n\t\t});\n\t}\n\n\treturn seeds;\n}\n\n/**\n * A seed script, imported as it is on disk now.\n *\n * Keyed by its modification time: a seed is run again after it is edited, and\n * a process that has imported it once would otherwise run the old one.\n */\nasync function scriptSeed(file: string): Promise<Seed['run']> {\n\tconst url = pathToFileURL(file);\n\turl.searchParams.set('mtime', String((await stat(file)).mtimeMs));\n\tconst module = (await import(url.href)) as { seed?: unknown };\n\tif (typeof module.seed !== 'function') throw new SeedHasNoSeed(file);\n\n\treturn module.seed as Seed['run'];\n}\n\nfunction isMigration(file: string): boolean {\n\tif (file.endsWith('.d.ts')) return false;\n\tif (/\\.(spec|test)\\.[cm]?[jt]s$/.test(file)) return false;\n\n\tconst extension = extname(file);\n\treturn extension === '.sql' || SCRIPTS.has(extension);\n}\n\nasync function scriptMigration(file: string): Promise<Migration> {\n\tconst module = (await import(pathToFileURL(file).href)) as Partial<Migration>;\n\tif (typeof module.up !== 'function') throw new MigrationHasNoUp(file);\n\n\treturn {\n\t\tup: module.up,\n\t\t...(typeof module.down === 'function' ? { down: module.down } : {}),\n\t};\n}\n\n/**\n * A `.sql` file, run whole.\n *\n * One query rather than split on `;`: with no parameters, Postgres takes\n * several statements in one message, and splitting by hand breaks on the first\n * `;` inside a string or a function body. There is no `down` — a generated\n * schema is rolled back by a migration that says how, not by guessing.\n */\nasync function sqlMigration(file: string, raw: typeof sql): Promise<Migration> {\n\tconst statements = await readFile(file, 'utf-8');\n\n\treturn {\n\t\tup: async (db: Kysely<unknown>) => {\n\t\t\tawait raw.raw(statements).execute(db);\n\t\t},\n\t};\n}\n","/**\n * The drivers a seed run registers before any seed runs.\n *\n * The seed runner is an entry point gkm owns, like the generated server and\n * the test harness, so it registers what they register — from the same\n * {@link driversFor}, so the two cannot drift. A seed then reaches a bucket or\n * a cache through the construct's service, exactly as a handler does, and no\n * application code names a provider.\n *\n * The registrations are written to a module under `.gkm/` and imported from\n * there, rather than imported by gkm itself: a registry is a module-level map,\n * so it has to be the copy the app's constructs resolve — which is the one a\n * bare specifier finds from the project root, not the one beside gkm.\n */\n\nimport { createHash } from 'node:crypto';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { GkmError } from '../errors';\nimport {\n\tcacheBackendsIn,\n\tdriversFor,\n\teventsBackendsIn,\n} from '../generators/drivers';\nimport type { CacheBackend, EventsBackend } from '../types';\n\n/** Which backends the stage being seeded resolves its declarations to. */\nexport interface SeedBackends {\n\tcache: CacheBackend;\n\tevents: EventsBackend;\n}\n\n/** The drivers a seed run needs could not be loaded from the project. */\nexport class SeedDriversUnresolved extends GkmError {\n\tconstructor(\n\t\treadonly root: string,\n\t\toverride readonly cause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`Could not load the drivers seeds run with from ${root} — ` +\n\t\t\t\t`${cause instanceof Error ? cause.message : String(cause)}. ` +\n\t\t\t\t`They are the ones the app's own entry registers; install the ` +\n\t\t\t\t`package it names where the project's constructs are declared.`,\n\t\t);\n\t\tthis.name = 'SeedDriversUnresolved';\n\t}\n}\n\n/**\n * Register the drivers a generated entry for this project would: storage when\n * it installs `@geekmidas/storage`, the cache backend its caches resolve to,\n * and the broker its topics and queues do. Nothing when it declares none.\n */\nexport async function registerSeedDrivers(options: {\n\troot: string;\n\tmanifest: ConstructManifest;\n\tbackends: SeedBackends;\n}): Promise<void> {\n\tconst drivers = driversFor({\n\t\tappRoot: options.root,\n\t\tcache: cacheBackendsIn(options.manifest, options.backends.cache),\n\t\tevents: eventsBackendsIn(options.manifest, options.backends.events),\n\t});\n\tif (!drivers.setup) return;\n\n\tconst content = `${drivers.imports}\\n\\n${drivers.setup}\\n`;\n\tconst dir = join(options.root, '.gkm');\n\tconst file = join(dir, 'seed-drivers.mjs');\n\tawait mkdir(dir, { recursive: true });\n\tawait writeFile(file, content);\n\n\t// Keyed by content: registration is idempotent, but a process seeding\n\t// twice after the declarations changed must load the new set.\n\tconst url = pathToFileURL(file);\n\turl.searchParams.set(\n\t\t'v',\n\t\tcreateHash('sha256').update(content).digest('hex').slice(0, 12),\n\t);\n\n\ttry {\n\t\tawait import(url.href);\n\t} catch (error) {\n\t\tthrow new SeedDriversUnresolved(options.root, error);\n\t}\n}\n","/**\n * Bring each construct's schema up to its migrations folder.\n *\n * Which constructs, in what order, from which folder, is `migrationTargets`'\n * answer and nobody else's. What is decided here is only how one target is\n * run: as its owner, in its own schema, with a history of its own.\n */\n\nimport { readdir } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n\ttype ConstructManifest,\n\tcanonicalId,\n\tDATABASE_FOLDERS,\n\tMIGRATIONS_ROOT,\n\ttype MigrationTarget,\n\tmigrationTargets,\n\tprovidedKeyFor,\n} from '@geekmidas/manifest';\nimport type { Kysely, KyselyConfig } from 'kysely';\nimport type { Migrator } from 'kysely/migration';\nimport pg from 'pg';\nimport { GkmError } from '../errors';\nimport type { ConstructSource } from '../reconcile/discover';\nimport { folderProvider, loadSeeds, migrationFiles } from './provider';\nimport { registerSeedDrivers, type SeedBackends } from './seedDrivers';\n\nexport interface DatabasesOptions {\n\t/** The project root — where `db/` lives. */\n\troot: string;\n\tmanifest: ConstructManifest;\n\t/**\n\t * Where each construct was declared. A construct's migrations run with the\n\t * Kysely its own file resolves, which is the one its migrations import.\n\t */\n\tsources?: Readonly<Record<string, ConstructSource>>;\n\t/** The resolved environment: each construct's owner URL is read from it. */\n\tenv: Readonly<Record<string, string | undefined>>;\n\t/** One construct, by name. All of them when absent. */\n\tonly?: string;\n}\n\nexport interface MigrationRun {\n\ttarget: MigrationTarget;\n\t/** The migrations this run applied, in order. */\n\tapplied: string[];\n}\n\nexport interface SeedOptions extends DatabasesOptions {\n\t/** The stage being seeded, handed to every seed. */\n\tstage: string;\n\t/**\n\t * What the stage's caches and topics resolve to — which drivers a seed is\n\t * run with, as the stage's own entry would register them.\n\t */\n\tbackends: SeedBackends;\n}\n\nexport interface SeedRun {\n\ttarget: MigrationTarget;\n\t/** The seeds this run ran, in order — every one, every time. */\n\tseeded: string[];\n}\n\n/** The seeds a run would run for one construct, read without connecting. */\nexport interface PlannedSeeds {\n\ttarget: MigrationTarget;\n\t/** In the order they would run. */\n\tseeds: string[];\n}\n\nexport interface PendingMigrations {\n\ttarget: MigrationTarget;\n\tpending: string[];\n}\n\n/** A folder under `db/` that names no construct. */\nexport class UnknownMigrationFolder extends GkmError {\n\tconstructor(\n\t\treadonly folder: string,\n\t\treadonly known: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`${folder} names no database construct, so its migrations would never ` +\n\t\t\t\t`run. ${known.length > 0 ? `The folders that do: ${known.join(', ')}.` : 'This project declares no database.'} ` +\n\t\t\t\t`Rename the folder after the construct it belongs to.`,\n\t\t);\n\t\tthis.name = 'UnknownMigrationFolder';\n\t}\n}\n\n/** A construct was asked for by a name that takes no migrations. */\nexport class NoSuchMigrationTarget extends GkmError {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly known: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${construct}' is not a database construct. ` +\n\t\t\t\t(known.length > 0\n\t\t\t\t\t? `The ones with migrations: ${known.join(', ')}.`\n\t\t\t\t\t: 'This project declares no database.'),\n\t\t);\n\t\tthis.name = 'NoSuchMigrationTarget';\n\t}\n}\n\n/**\n * A migration left directly in a construct's folder, where nothing reads it.\n *\n * Migrations moved into `migrations/` so seeds could sit beside them. A file\n * still at the old level would otherwise never run, and nothing would say so.\n */\nexport class MigrationsOutsideFolder extends GkmError {\n\tconstructor(\n\t\treadonly folder: string,\n\t\treadonly files: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`${folder} has ${files.join(', ')} directly inside it, where nothing ` +\n\t\t\t\t`runs them. Migrations live in ${folder}/migrations/ and seeds in ` +\n\t\t\t\t`${folder}/seeds/ — move ${files.length === 1 ? 'it' : 'them'} there.`,\n\t\t);\n\t\tthis.name = 'MigrationsOutsideFolder';\n\t}\n}\n\n/** A folder inside a construct's folder that is neither `migrations` nor `seeds`. */\nexport class UnknownDatabaseFolder extends GkmError {\n\tconstructor(readonly folder: string) {\n\t\tsuper(\n\t\t\t`${folder} is neither migrations/ nor seeds/, so nothing in it would ` +\n\t\t\t\t`ever run. A construct's folder holds those two; rename or remove it.`,\n\t\t);\n\t\tthis.name = 'UnknownDatabaseFolder';\n\t}\n}\n\n/** A seed failed; its own writes are rolled back, the ones before it stay. */\nexport class SeedFailed extends Error {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly seed: string,\n\t\toverride readonly cause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${construct}: seed '${seed}' failed — ` +\n\t\t\t\t`${cause instanceof Error ? cause.message : String(cause)}. ` +\n\t\t\t\t`Its writes were rolled back; fix it and run it again.`,\n\t\t);\n\t\tthis.name = 'SeedFailed';\n\t}\n}\n\n/** A construct with roles has no owner URL to migrate with. */\nexport class NoOwnerCredential extends GkmError {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`${construct} has no ${key} to migrate with. Migrations run as the owner ` +\n\t\t\t\t`role — the runtime one cannot create a table — and nothing ` +\n\t\t\t\t`resolved its URL. Is the stage reconciled?`,\n\t\t);\n\t\tthis.name = 'NoOwnerCredential';\n\t}\n}\n\n/** A migration failed; the ones before it in the run stay applied. */\nexport class MigrationFailed extends Error {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly migration: string | undefined,\n\t\toverride readonly cause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${construct}: migration ${migration ? `'${migration}' ` : ''}failed — ` +\n\t\t\t\t`${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t);\n\t\tthis.name = 'MigrationFailed';\n\t}\n}\n\n/** The project's Kysely could not be found from where a database is declared. */\nexport class KyselyNotFound extends GkmError {\n\tconstructor(readonly from: string) {\n\t\tsuper(\n\t\t\t`Could not resolve 'kysely' from ${from}. Migrations run with the ` +\n\t\t\t\t`project's own Kysely — install it where the database is declared.`,\n\t\t);\n\t\tthis.name = 'KyselyNotFound';\n\t}\n}\n\n/** Apply every pending migration, construct by construct, parents first. */\nexport async function migrateDatabases(\n\toptions: DatabasesOptions,\n): Promise<MigrationRun[]> {\n\tconst runs: MigrationRun[] = [];\n\n\tfor (const target of await targetsFor(options)) {\n\t\t// No folder, or an empty one, is nothing to do — and no reason to\n\t\t// connect, which a construct nobody has written a migration for yet\n\t\t// should not need.\n\t\tconst files = await migrationFiles(join(options.root, target.migrations));\n\t\tif (files.size === 0) {\n\t\t\truns.push({ target, applied: [] });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst applied = await withMigrator(options, target, async (migrator) => {\n\t\t\tconst { error, results = [] } = await migrator.migrateToLatest();\n\t\t\tif (error) {\n\t\t\t\tconst failed = results.find((result) => result.status === 'Error');\n\t\t\t\tthrow new MigrationFailed(target.id, failed?.migrationName, error);\n\t\t\t}\n\n\t\t\treturn results\n\t\t\t\t.filter((result) => result.status === 'Success')\n\t\t\t\t.map((result) => result.migrationName);\n\t\t});\n\n\t\truns.push({ target, applied });\n\t}\n\n\treturn runs;\n}\n\n/**\n * Run every construct's seeds, parents first — each one, every time, on every\n * stage, production included. Each is handed the stage, so a seed decides\n * what belongs where.\n *\n * Seeds are reference data kept up to date by being run again, so there is no\n * history: a seed is an upsert, and a changed one is applied by the next run.\n * Each runs in its own transaction, as the construct's owner, so a failure\n * leaves nothing half-written. Assumes the schema is migrated —\n * {@link migrateAndSeed} is what makes that true.\n *\n * A seed is handed the client the app gets — the construct's `clientConfig`,\n * plugins included — on the owner's connection. One written against\n * `Kysely<DB>` with a `CamelCasePlugin` writes `isEditable` here as it does in\n * a handler or a test.\n *\n * And with the drivers the stage's entry registers, and the stage's `env`, so\n * a seed reaching a bucket or a cache through its construct gets the client a\n * handler would.\n */\nexport async function seedDatabases(options: SeedOptions): Promise<SeedRun[]> {\n\tconst runs: SeedRun[] = [];\n\tlet registered = false;\n\n\tfor (const target of await targetsFor(options)) {\n\t\tconst folder = join(options.root, target.seeds);\n\t\tif ((await migrationFiles(folder)).size === 0) {\n\t\t\truns.push({ target, seeded: [] });\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!registered) {\n\t\t\tawait registerSeedDrivers(options);\n\t\t\tregistered = true;\n\t\t}\n\n\t\tconst config = clientConfigOf(options, target);\n\t\tconst seeded = await withOwner(\n\t\t\toptions,\n\t\t\ttarget,\n\t\t\tconfig,\n\t\t\tasync (db, kysely) => {\n\t\t\t\tconst names: string[] = [];\n\t\t\t\tfor (const seed of await loadSeeds(folder, kysely.sql)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait db\n\t\t\t\t\t\t\t.transaction()\n\t\t\t\t\t\t\t.execute((trx) =>\n\t\t\t\t\t\t\t\tseed.run(trx, { stage: options.stage, env: options.env }),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow new SeedFailed(target.id, seed.name, error);\n\t\t\t\t\t}\n\t\t\t\t\tnames.push(seed.name);\n\t\t\t\t}\n\t\t\t\treturn names;\n\t\t\t},\n\t\t);\n\n\t\truns.push({ target, seeded });\n\t}\n\n\treturn runs;\n}\n\n/**\n * The seeds {@link seedDatabases} would run, construct by construct, parents\n * first, in the order it would run them — read from the folders alone, with\n * no connection. What a dry run lists. Constructs with none are left out.\n */\nexport async function plannedSeeds(\n\toptions: Pick<DatabasesOptions, 'root' | 'manifest' | 'only'>,\n): Promise<PlannedSeeds[]> {\n\tconst planned: PlannedSeeds[] = [];\n\tfor (const target of await targetsFor(options)) {\n\t\tconst files = await migrationFiles(join(options.root, target.seeds));\n\t\tif (files.size === 0) continue;\n\t\tplanned.push({ target, seeds: [...files.keys()].sort() });\n\t}\n\treturn planned;\n}\n\n/**\n * Migrate, then seed: a seed only ever runs against the schema it was written\n * for.\n *\n * With `only`, the constructs it lives in are migrated too — a tenant's seed\n * cannot run before the database that owns its schema exists — and only it is\n * seeded.\n */\nexport async function migrateAndSeed(options: SeedOptions): Promise<{\n\tmigrations: MigrationRun[];\n\tseeds: SeedRun[];\n}> {\n\tconst migrations: MigrationRun[] = [];\n\tfor (const target of await withParents(options)) {\n\t\tmigrations.push(\n\t\t\t...(await migrateDatabases({ ...options, only: target.id })),\n\t\t);\n\t}\n\n\treturn { migrations, seeds: await seedDatabases(options) };\n}\n\n/** The targets `only` names, after the ones it lives in; all without it. */\nasync function withParents(\n\toptions: DatabasesOptions,\n): Promise<MigrationTarget[]> {\n\tconst chosen = await targetsFor(options);\n\tif (!options.only) return chosen;\n\n\tconst all = migrationTargets(options.manifest);\n\tconst ids = new Set<string>();\n\tfor (const target of chosen) {\n\t\tlet current: MigrationTarget | undefined = target;\n\t\twhile (current) {\n\t\t\tids.add(current.id);\n\t\t\tconst parent: string | undefined = current.of;\n\t\t\tcurrent = parent ? all.find((t) => t.id === parent) : undefined;\n\t\t}\n\t}\n\n\treturn all.filter((target) => ids.has(target.id));\n}\n\n/**\n * What each construct's folder has that its history does not — without\n * applying any of it. What `gkm dev` reports.\n */\nexport async function pendingMigrations(\n\toptions: DatabasesOptions,\n): Promise<PendingMigrations[]> {\n\tconst found: PendingMigrations[] = [];\n\n\tfor (const target of await targetsFor(options)) {\n\t\tconst files = await migrationFiles(join(options.root, target.migrations));\n\t\tif (files.size === 0) continue;\n\n\t\tconst pending = await withMigrator(options, target, async (migrator) =>\n\t\t\t(await migrator.getMigrations())\n\t\t\t\t.filter((migration) => migration.executedAt === undefined)\n\t\t\t\t.map((migration) => migration.name),\n\t\t);\n\n\t\tif (pending.length > 0) found.push({ target, pending });\n\t}\n\n\treturn found;\n}\n\n/**\n * The targets this run covers, with every folder under `db/` accounted for.\n *\n * A folder that names no construct is an error rather than something to skip:\n * a typo in its name is otherwise a migration that silently never runs.\n */\nasync function targetsFor(\n\toptions: Pick<DatabasesOptions, 'root' | 'manifest' | 'only'>,\n): Promise<MigrationTarget[]> {\n\tconst targets = migrationTargets(options.manifest);\n\tconst folders = targets.map((target) => target.folder);\n\n\tfor (const folder of await foldersIn(join(options.root, MIGRATIONS_ROOT))) {\n\t\tconst relative = `${MIGRATIONS_ROOT}/${folder}`;\n\t\tif (!folders.includes(relative)) {\n\t\t\tthrow new UnknownMigrationFolder(relative, folders);\n\t\t}\n\t\tawait checkLayout(options.root, relative);\n\t}\n\n\tif (!options.only) return targets;\n\n\tconst id = canonicalId(options.only);\n\tconst chosen = targets.filter((target) => target.id === id);\n\tif (chosen.length === 0) {\n\t\tthrow new NoSuchMigrationTarget(\n\t\t\toptions.only,\n\t\t\ttargets.map((target) => target.id),\n\t\t);\n\t}\n\n\treturn chosen;\n}\n\n/**\n * A construct's folder holds `migrations/` and `seeds/`, and nothing else —\n * anything beside them is a file or folder nothing would ever run.\n */\nasync function checkLayout(root: string, folder: string): Promise<void> {\n\tconst entries = await readdir(join(root, folder), { withFileTypes: true });\n\n\tconst loose = entries\n\t\t.filter((entry) => entry.isFile() && !entry.name.startsWith('.'))\n\t\t.map((entry) => entry.name);\n\tif (loose.length > 0) throw new MigrationsOutsideFolder(folder, loose);\n\n\tfor (const entry of entries) {\n\t\tif (\n\t\t\tentry.isDirectory() &&\n\t\t\t!(DATABASE_FOLDERS as readonly string[]).includes(entry.name)\n\t\t) {\n\t\t\tthrow new UnknownDatabaseFolder(`${folder}/${entry.name}`);\n\t\t}\n\t}\n}\n\nasync function foldersIn(dir: string): Promise<string[]> {\n\tconst entries = await readdir(dir, { withFileTypes: true }).catch(\n\t\t(error: NodeJS.ErrnoException) => {\n\t\t\tif (error.code === 'ENOENT') return [];\n\t\t\tthrow error;\n\t\t},\n\t);\n\n\treturn entries\n\t\t.filter((entry) => entry.isDirectory())\n\t\t.map((entry) => entry.name);\n}\n\n/**\n * A migrator for one target, connected as its owner.\n *\n * No `migrationTableSchema`: the owner role's `search_path` is pinned to the\n * construct's schema, so the history lands there — `app.kysely_migration` for\n * the database, `auth_database.kysely_migration` for its tenant — and two\n * constructs in one Postgres never share one.\n *\n * Unordered migrations are allowed. Files are timestamped, so a branch merged\n * after another's migration ran carries an older one; refusing it would make\n * every such merge a manual repair.\n *\n * The client is bare — none of the construct's plugins. A casing plugin\n * rewrites identifiers in schema-builder DDL too, and a migration must do the\n * same thing forever after it has run, so it cannot depend on configuration\n * that may change.\n */\nasync function withMigrator<T>(\n\toptions: DatabasesOptions,\n\ttarget: MigrationTarget,\n\trun: (migrator: Migrator) => Promise<T>,\n): Promise<T> {\n\treturn withOwner(options, target, {}, (db, { Migrator, sql }) =>\n\t\trun(\n\t\t\tnew Migrator({\n\t\t\t\tdb,\n\t\t\t\tprovider: folderProvider(join(options.root, target.migrations), sql),\n\t\t\t\tallowUnorderedMigrations: true,\n\t\t\t}),\n\t\t),\n\t);\n}\n\n/**\n * One target's database, connected as its owner and closed afterwards — what\n * migrations and seeds both run as, each with the client config it needs.\n */\nasync function withOwner<T>(\n\toptions: DatabasesOptions,\n\ttarget: MigrationTarget,\n\tconfig: Omit<KyselyConfig, 'dialect'>,\n\trun: (\n\t\tdb: Kysely<unknown>,\n\t\tkysely: Awaited<ReturnType<typeof kyselyFrom>>,\n\t) => Promise<T>,\n): Promise<T> {\n\tconst from =\n\t\toptions.sources?.[target.id]?.file ??\n\t\t(target.of ? options.sources?.[target.of]?.file : undefined) ??\n\t\tjoin(options.root, 'package.json');\n\tconst kysely = await kyselyFrom(from);\n\n\tconst db: Kysely<unknown> = new kysely.Kysely<unknown>({\n\t\t...config,\n\t\tdialect: new kysely.PostgresDialect({\n\t\t\tpool: new pg.Pool(poolConfig(ownerUrl(options, target))),\n\t\t}),\n\t});\n\n\ttry {\n\t\treturn await run(db, kysely);\n\t} finally {\n\t\tawait db.destroy();\n\t}\n}\n\n/**\n * What the construct builds its clients with besides a dialect — its plugins\n * and logging — read from the construct discovery already imported.\n *\n * A tenant's is its own: `database.schema('Auth', { plugins })` declares the\n * client for its tables, not the parent's. With no construct to ask (a\n * manifest without sources), the client is bare.\n */\nfunction clientConfigOf(\n\toptions: DatabasesOptions,\n\ttarget: MigrationTarget,\n): Omit<KyselyConfig, 'dialect'> {\n\tconst construct = options.sources?.[target.id]?.construct;\n\tif (typeof construct !== 'object' || construct === null) return {};\n\tif (!('clientConfig' in construct)) return {};\n\treturn (construct.clientConfig as Omit<KyselyConfig, 'dialect'>) ?? {};\n}\n\n/**\n * The owner's URL, with no fallback to the runtime one.\n *\n * The runtime role can create nothing, so falling back would only move the\n * failure to the first `CREATE TABLE` and make it read like a permissions\n * bug. The one exception is a database declared `roles: false`, where there is\n * no owner — both URLs are the master credential by design.\n */\nfunction ownerUrl(options: DatabasesOptions, target: MigrationTarget): string {\n\tconst key = providedKeyFor(target.id, 'database', 'ownerUrl');\n\tconst owner = options.env[key];\n\tif (owner) return owner;\n\n\tconst database = options.manifest[target.of ?? target.id];\n\tif (database?.kind === 'database' && database.roles === false) {\n\t\tconst url = options.env[providedKeyFor(target.id, 'database', 'url')];\n\t\tif (url) return url;\n\t}\n\n\tthrow new NoOwnerCredential(target.id, key);\n}\n\n/**\n * Pool settings for a URL, with `?search_path=` as the startup option Postgres\n * reads. Only a `roles: false` URL carries it — a role pins its own.\n */\nfunction poolConfig(url: string): pg.PoolConfig {\n\tconst parsed = new URL(url);\n\tconst searchPath = parsed.searchParams.get('search_path');\n\tif (!searchPath) return { connectionString: url };\n\n\tparsed.searchParams.delete('search_path');\n\treturn {\n\t\tconnectionString: parsed.toString(),\n\t\toptions: `-c search_path=${searchPath}`,\n\t};\n}\n\n/** Kysely as the project resolves it from `from`. */\nasync function kyselyFrom(from: string) {\n\tconst require = createRequire(from);\n\n\ttry {\n\t\tconst [main, migration] = await Promise.all([\n\t\t\timport(pathToFileURL(require.resolve('kysely')).href),\n\t\t\timport(pathToFileURL(require.resolve('kysely/migration')).href),\n\t\t]);\n\n\t\treturn {\n\t\t\tKysely: main.Kysely as typeof import('kysely').Kysely,\n\t\t\tPostgresDialect:\n\t\t\t\tmain.PostgresDialect as typeof import('kysely').PostgresDialect,\n\t\t\tsql: main.sql as typeof import('kysely').sql,\n\t\t\tMigrator:\n\t\t\t\tmigration.Migrator as typeof import('k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3C,QAAA,GAAOC,SAAAA,cAAAA,CAAcF,UAAQ,QAAQ,QAAQ,CAAC,CAAC,CAAC,OAChD,QAAA,GAAOE,SAAAA,cAAAA,CAAcF,UAAQ,QAAQ,kBAAkB,CAAC,CAAC,CAAC,KAC3D,CAAC;EAED,OAAO;GACN,QAAQ,KAAK;GACb,iBACC,KAAK;GACN,KAAK,KAAK;GACV,UACC,UAAU;EACZ;CACD,QAAQ;EACP,MAAM,IAAI,eAAe,IAAI;CAC9B;AACD"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
2
|
+
const require_compose = require("./compose-DmtR2f0l.cjs");
|
|
3
|
+
const require_apps = require("./apps-C27qrbEe.cjs");
|
|
4
|
+
const require_compose$1 = require("./compose-DJAaJEqL.cjs");
|
|
5
|
+
const require_stack = require("./stack-BAipv5Js.cjs");
|
|
6
|
+
const require_stage = require("./stage-D7vBtLXL.cjs");
|
|
7
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
8
|
+
//#region src/exec/dbTunnel.ts
|
|
9
|
+
/**
|
|
10
|
+
* `gkm db:tunnel --stage <stage> [construct]`: a deployed compose stage's
|
|
11
|
+
* Postgres, on this machine's loopback, and each database's owner login to
|
|
12
|
+
* sign in to it with — for a SQL client, a one-off fix, a look at the data.
|
|
13
|
+
*
|
|
14
|
+
* The tunnel is the deploy's own: SSH on the deploy's login to the port the
|
|
15
|
+
* server publishes Postgres on, its loopback alone. The owner URL is the one
|
|
16
|
+
* the deploy migrates with, derived from the stage's secrets the way the
|
|
17
|
+
* deploy derives it — nothing is stored, and nothing is written to disk.
|
|
18
|
+
*
|
|
19
|
+
* It is the owner, not the app's login, because that is what a person
|
|
20
|
+
* changing the schema or its data by hand needs; it is printed, not injected,
|
|
21
|
+
* because a GUI client is not a process gkm starts. `gkm exec --stage` stays
|
|
22
|
+
* the app's login: what a script runs as is what the app runs as.
|
|
23
|
+
*/
|
|
24
|
+
const logger = console;
|
|
25
|
+
/** The stage's stack runs no Postgres: there is nothing to tunnel to. */
|
|
26
|
+
var StageHasNoDatabase = class extends require_errors.GkmError {
|
|
27
|
+
stage;
|
|
28
|
+
constructor(stage) {
|
|
29
|
+
super(`'${stage}' runs no Postgres, so there is no database to tunnel to. Declare a Database construct and deploy the stage.`);
|
|
30
|
+
this.stage = stage;
|
|
31
|
+
this.name = "StageHasNoDatabase";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** The construct asked for is not one of the stage's databases. */
|
|
35
|
+
var DatabaseNotInStage = class extends require_errors.GkmError {
|
|
36
|
+
stage;
|
|
37
|
+
construct;
|
|
38
|
+
databases;
|
|
39
|
+
constructor(stage, construct, databases) {
|
|
40
|
+
super(`'${construct}' is not a database '${stage}' runs. Its databases are ${databases.join(", ")}: gkm db:tunnel --stage ${stage} ${databases[0] ?? "<construct>"}.`);
|
|
41
|
+
this.stage = stage;
|
|
42
|
+
this.construct = construct;
|
|
43
|
+
this.databases = databases;
|
|
44
|
+
this.name = "DatabaseNotInStage";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** The server publishes no Postgres: the stack is not running there. */
|
|
48
|
+
var DatabaseNotPublished = class extends require_errors.GkmError {
|
|
49
|
+
stage;
|
|
50
|
+
project;
|
|
51
|
+
constructor(stage, project) {
|
|
52
|
+
super(`No running ${project} postgres publishes ${require_stack.LOOPBACK_SERVICES.postgres} on '${stage}'s server, so there is nothing to tunnel to. Deploy the stage (gkm deploy --stage ${stage}), then run this again.`);
|
|
53
|
+
this.stage = stage;
|
|
54
|
+
this.project = project;
|
|
55
|
+
this.name = "DatabaseNotPublished";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/** A login's URL as a SQL client's form asks for it, field by field. */
|
|
59
|
+
function loginFields(url) {
|
|
60
|
+
const parsed = new URL(url);
|
|
61
|
+
return [
|
|
62
|
+
["host", parsed.hostname],
|
|
63
|
+
["port", parsed.port],
|
|
64
|
+
["database", decodeURIComponent(parsed.pathname.slice(1))],
|
|
65
|
+
["user", decodeURIComponent(parsed.username)],
|
|
66
|
+
["password", decodeURIComponent(parsed.password)]
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Each database's owner URL — every one, or the construct asked for — on
|
|
71
|
+
* the port this machine reaches the stack's Postgres by: the same values the
|
|
72
|
+
* deploy's migrations connect with (`migrateAndSeed`), from the same
|
|
73
|
+
* derivation.
|
|
74
|
+
*
|
|
75
|
+
* @throws {DatabaseNotInStage}
|
|
76
|
+
*/
|
|
77
|
+
function ownerLogins(stack, port, construct) {
|
|
78
|
+
const env = require_apps.envFor(stack.plan, {
|
|
79
|
+
...stack.resolution,
|
|
80
|
+
ports: { [require_compose$1.primaryPortKey("postgres")]: port }
|
|
81
|
+
});
|
|
82
|
+
const logins = stack.plan.resources.filter((resource) => require_apps.isDatabase(resource.kind)).map((resource) => {
|
|
83
|
+
const key = (0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "ownerUrl");
|
|
84
|
+
const url = env[key] ?? env[resource.envKey];
|
|
85
|
+
return url ? {
|
|
86
|
+
construct: resource.id,
|
|
87
|
+
key,
|
|
88
|
+
url
|
|
89
|
+
} : void 0;
|
|
90
|
+
}).filter((login) => login !== void 0);
|
|
91
|
+
if (construct === void 0) return logins;
|
|
92
|
+
const asked = logins.filter((login) => login.construct === construct);
|
|
93
|
+
if (asked.length === 0) throw new DatabaseNotInStage(stack.stage, construct, logins.map((login) => login.construct));
|
|
94
|
+
return asked;
|
|
95
|
+
}
|
|
96
|
+
/** Until the person presses Ctrl-C, or the process is told to stop. */
|
|
97
|
+
function untilInterrupted() {
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
const stop = () => {
|
|
100
|
+
process.off("SIGINT", stop);
|
|
101
|
+
process.off("SIGTERM", stop);
|
|
102
|
+
resolve();
|
|
103
|
+
};
|
|
104
|
+
process.on("SIGINT", stop);
|
|
105
|
+
process.on("SIGTERM", stop);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const defaultDbTunnelDeps = {
|
|
109
|
+
...require_stage.defaultStageExecDeps,
|
|
110
|
+
held: untilInterrupted
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Open a tunnel to the stage's Postgres, print each database's owner URL
|
|
114
|
+
* through it, and hold it open until `deps.held` resolves. The tunnel is
|
|
115
|
+
* closed however that ends.
|
|
116
|
+
*
|
|
117
|
+
* @throws {StageHasNoDatabase}, {DatabaseNotInStage}, {DatabaseNotPublished},
|
|
118
|
+
* {ExecNotConfirmed}, {ExecStageNotComposed}, {ExecStageNotDeployed},
|
|
119
|
+
* {ComposeServerUnreachable}
|
|
120
|
+
*/
|
|
121
|
+
async function dbTunnel(options, deps = defaultDbTunnelDeps) {
|
|
122
|
+
const { stage } = options;
|
|
123
|
+
const loaded = await require_stage.loadStage(options, deps.env);
|
|
124
|
+
const { stack } = loaded;
|
|
125
|
+
if (!stack.infra.includes("postgres")) throw new StageHasNoDatabase(stage);
|
|
126
|
+
ownerLogins(stack, require_stack.LOOPBACK_SERVICES.postgres, options.construct);
|
|
127
|
+
if (loaded.protectedStage && !options.yes) {
|
|
128
|
+
const question = `'${stage}' is a protected stage. Open a tunnel to its database as its owner?`;
|
|
129
|
+
if (!await deps.confirm(question)) throw new require_stage.ExecNotConfirmed(stage);
|
|
130
|
+
}
|
|
131
|
+
const server = require_stage.stageServer(loaded, options);
|
|
132
|
+
await deps.server.check(server);
|
|
133
|
+
const published = await deps.docker.published({ host: require_compose.dockerHost(server) }, stack.project, "postgres", require_stack.LOOPBACK_SERVICES.postgres);
|
|
134
|
+
if (published === void 0) throw new DatabaseNotPublished(stage, stack.project);
|
|
135
|
+
const tunnel = await deps.server.tunnel(server, published);
|
|
136
|
+
try {
|
|
137
|
+
const logins = ownerLogins(stack, tunnel.port, options.construct);
|
|
138
|
+
logger.log(`🚇 '${stage}' postgres → 127.0.0.1:${tunnel.port} (over SSH to ${server.host})`);
|
|
139
|
+
for (const login of logins) {
|
|
140
|
+
logger.log(`\n🔑 ${login.construct} (${login.key})`);
|
|
141
|
+
logger.log(` ${login.url}`);
|
|
142
|
+
for (const [field, value] of loginFields(login.url)) logger.log(` ${`${field}:`.padEnd(10)}${value}`);
|
|
143
|
+
}
|
|
144
|
+
logger.log("\nThe tunnel is open. Press Ctrl-C to close it.");
|
|
145
|
+
await deps.held();
|
|
146
|
+
return logins;
|
|
147
|
+
} finally {
|
|
148
|
+
await tunnel.close();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
exports.dbTunnel = dbTunnel;
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=dbTunnel-DUudiQWj.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTunnel-DUudiQWj.cjs","names":["GkmError","LOOPBACK_SERVICES","envFor","primaryPortKey","isDatabase","providedKeyFor","defaultStageExecDeps","loadStage","ExecNotConfirmed","stageServer","dockerHost"],"sources":["../src/exec/dbTunnel.ts"],"sourcesContent":["/**\n * `gkm db:tunnel --stage <stage> [construct]`: a deployed compose stage's\n * Postgres, on this machine's loopback, and each database's owner login to\n * sign in to it with — for a SQL client, a one-off fix, a look at the data.\n *\n * The tunnel is the deploy's own: SSH on the deploy's login to the port the\n * server publishes Postgres on, its loopback alone. The owner URL is the one\n * the deploy migrates with, derived from the stage's secrets the way the\n * deploy derives it — nothing is stored, and nothing is written to disk.\n *\n * It is the owner, not the app's login, because that is what a person\n * changing the schema or its data by hand needs; it is printed, not injected,\n * because a GUI client is not a process gkm starts. `gkm exec --stage` stays\n * the app's login: what a script runs as is what the app runs as.\n */\n\nimport { providedKeyFor } from '@geekmidas/manifest';\nimport { dockerHost } from '../compose/server.js';\nimport type { ComposeStack } from '../compose/stack.js';\nimport { LOOPBACK_SERVICES } from '../compose/stack.js';\nimport { GkmError } from '../errors';\nimport { primaryPortKey } from '../reconcile/containers.js';\nimport { envFor, isDatabase } from '../reconcile/env.js';\nimport {\n\tdefaultStageExecDeps,\n\tExecNotConfirmed,\n\tloadStage,\n\ttype StageExecDeps,\n\ttype StageExecOptions,\n\tstageServer,\n} from './stage.js';\n\nconst logger = console;\n\n/** The stage's stack runs no Postgres: there is nothing to tunnel to. */\nexport class StageHasNoDatabase extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`'${stage}' runs no Postgres, so there is no database to tunnel to. ` +\n\t\t\t\t'Declare a Database construct and deploy the stage.',\n\t\t);\n\t\tthis.name = 'StageHasNoDatabase';\n\t}\n}\n\n/** The construct asked for is not one of the stage's databases. */\nexport class DatabaseNotInStage extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly construct: string,\n\t\treadonly databases: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${construct}' is not a database '${stage}' runs. Its databases are ` +\n\t\t\t\t`${databases.join(', ')}: gkm db:tunnel --stage ${stage} ` +\n\t\t\t\t`${databases[0] ?? '<construct>'}.`,\n\t\t);\n\t\tthis.name = 'DatabaseNotInStage';\n\t}\n}\n\n/** The server publishes no Postgres: the stack is not running there. */\nexport class DatabaseNotPublished extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`No running ${project} postgres publishes ${LOOPBACK_SERVICES.postgres} ` +\n\t\t\t\t`on '${stage}'s server, so there is nothing to tunnel to. Deploy the ` +\n\t\t\t\t`stage (gkm deploy --stage ${stage}), then run this again.`,\n\t\t);\n\t\tthis.name = 'DatabaseNotPublished';\n\t}\n}\n\n/** A database's owner login, as this machine reaches it. */\nexport interface OwnerLogin {\n\t/** The construct's id. */\n\tconstruct: string;\n\t/** The key the deploy's migrations read it from. */\n\tkey: string;\n\turl: string;\n}\n\n/** A login's URL as a SQL client's form asks for it, field by field. */\nexport function loginFields(url: string): [string, string][] {\n\tconst parsed = new URL(url);\n\treturn [\n\t\t['host', parsed.hostname],\n\t\t['port', parsed.port],\n\t\t['database', decodeURIComponent(parsed.pathname.slice(1))],\n\t\t['user', decodeURIComponent(parsed.username)],\n\t\t['password', decodeURIComponent(parsed.password)],\n\t];\n}\n\n/**\n * Each database's owner URL — every one, or the construct asked for — on\n * the port this machine reaches the stack's Postgres by: the same values the\n * deploy's migrations connect with (`migrateAndSeed`), from the same\n * derivation.\n *\n * @throws {DatabaseNotInStage}\n */\nexport function ownerLogins(\n\tstack: Pick<ComposeStack, 'stage' | 'plan' | 'resolution'>,\n\tport: number,\n\tconstruct?: string,\n): OwnerLogin[] {\n\tconst env = envFor(stack.plan, {\n\t\t...stack.resolution,\n\t\tports: { [primaryPortKey('postgres')]: port },\n\t});\n\tconst logins = stack.plan.resources\n\t\t.filter((resource) => isDatabase(resource.kind))\n\t\t.map((resource) => {\n\t\t\tconst key = providedKeyFor(resource.id, resource.kind, 'ownerUrl');\n\t\t\t// A database whose roles are not split has no owner: its one login\n\t\t\t// is the URL itself, and that is the one to sign in with.\n\t\t\tconst url = env[key] ?? env[resource.envKey];\n\t\t\treturn url ? { construct: resource.id, key, url } : undefined;\n\t\t})\n\t\t.filter((login): login is OwnerLogin => login !== undefined);\n\n\tif (construct === undefined) return logins;\n\tconst asked = logins.filter((login) => login.construct === construct);\n\tif (asked.length === 0) {\n\t\tthrow new DatabaseNotInStage(\n\t\t\tstack.stage,\n\t\t\tconstruct,\n\t\t\tlogins.map((login) => login.construct),\n\t\t);\n\t}\n\treturn asked;\n}\n\nexport interface DbTunnelOptions\n\textends Pick<\n\t\tStageExecOptions,\n\t\t'stage' | 'profile' | 'sshUser' | 'yes' | 'cwd'\n\t> {\n\t/** One database construct, by id. Every one when absent. */\n\tconstruct?: string;\n}\n\nexport interface DbTunnelDeps extends StageExecDeps {\n\t/** Resolves when the tunnel should close: Ctrl-C, by default. */\n\theld: () => Promise<void>;\n}\n\n/** Until the person presses Ctrl-C, or the process is told to stop. */\nfunction untilInterrupted(): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tconst stop = () => {\n\t\t\tprocess.off('SIGINT', stop);\n\t\t\tprocess.off('SIGTERM', stop);\n\t\t\tresolve();\n\t\t};\n\t\tprocess.on('SIGINT', stop);\n\t\tprocess.on('SIGTERM', stop);\n\t});\n}\n\nexport const defaultDbTunnelDeps: DbTunnelDeps = {\n\t...defaultStageExecDeps,\n\theld: untilInterrupted,\n};\n\n/**\n * Open a tunnel to the stage's Postgres, print each database's owner URL\n * through it, and hold it open until `deps.held` resolves. The tunnel is\n * closed however that ends.\n *\n * @throws {StageHasNoDatabase}, {DatabaseNotInStage}, {DatabaseNotPublished},\n * {ExecNotConfirmed}, {ExecStageNotComposed}, {ExecStageNotDeployed},\n * {ComposeServerUnreachable}\n */\nexport async function dbTunnel(\n\toptions: DbTunnelOptions,\n\tdeps: DbTunnelDeps = defaultDbTunnelDeps,\n): Promise<OwnerLogin[]> {\n\tconst { stage } = options;\n\tconst loaded = await loadStage(options, deps.env);\n\tconst { stack } = loaded;\n\tif (!stack.infra.includes('postgres')) throw new StageHasNoDatabase(stage);\n\t// Asked here, before anything is reached: an unknown construct is said\n\t// without an SSH login. The port is a placeholder until the tunnel opens.\n\townerLogins(stack, LOOPBACK_SERVICES.postgres, options.construct);\n\n\tif (loaded.protectedStage && !options.yes) {\n\t\tconst question = `'${stage}' is a protected stage. Open a tunnel to its database as its owner?`;\n\t\tif (!(await deps.confirm(question))) throw new ExecNotConfirmed(stage);\n\t}\n\n\tconst server = stageServer(loaded, options);\n\tawait deps.server.check(server);\n\n\tconst published = await deps.docker.published(\n\t\t{ host: dockerHost(server) },\n\t\tstack.project,\n\t\t'postgres',\n\t\tLOOPBACK_SERVICES.postgres,\n\t);\n\tif (published === undefined) {\n\t\tthrow new DatabaseNotPublished(stage, stack.project);\n\t}\n\n\tconst tunnel = await deps.server.tunnel(server, published);\n\ttry {\n\t\tconst logins = ownerLogins(stack, tunnel.port, options.construct);\n\t\tlogger.log(\n\t\t\t`🚇 '${stage}' postgres → 127.0.0.1:${tunnel.port} (over SSH to ${server.host})`,\n\t\t);\n\t\tfor (const login of logins) {\n\t\t\tlogger.log(`\\n🔑 ${login.construct} (${login.key})`);\n\t\t\tlogger.log(` ${login.url}`);\n\t\t\tfor (const [field, value] of loginFields(login.url)) {\n\t\t\t\tlogger.log(` ${`${field}:`.padEnd(10)}${value}`);\n\t\t\t}\n\t\t}\n\t\tlogger.log('\\nThe tunnel is open. Press Ctrl-C to close it.');\n\t\tawait deps.held();\n\t\treturn logins;\n\t} finally {\n\t\tawait tunnel.close();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,SAAS;;AAGf,IAAa,qBAAb,cAAwCA,eAAAA,SAAS;CAC3B;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,6GAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwCA,eAAAA,SAAS;CAEtC;CACA;CACA;CAHV,YACC,OACA,WACA,WACC;EACD,MACC,IAAI,UAAU,uBAAuB,MAAM,4BACvC,UAAU,KAAK,IAAI,EAAE,0BAA0B,MAAM,GACrD,UAAU,MAAM,cAAc,EACnC;EARS,KAAA,QAAA;EACA,KAAA,YAAA;EACA,KAAA,YAAA;EAOT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,uBAAb,cAA0CA,eAAAA,SAAS;CAExC;CACA;CAFV,YACC,OACA,SACC;EACD,MACC,cAAc,QAAQ,sBAAsBC,cAAAA,kBAAkB,SAAS,OAC/D,MAAM,oFACgB,MAAM,wBACrC;EAPS,KAAA,QAAA;EACA,KAAA,UAAA;EAOT,KAAK,OAAO;CACb;AACD;;AAYA,SAAgB,YAAY,KAAiC;CAC5D,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,OAAO;EACN,CAAC,QAAQ,OAAO,QAAQ;EACxB,CAAC,QAAQ,OAAO,IAAI;EACpB,CAAC,YAAY,mBAAmB,OAAO,SAAS,M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@@
|
|
|
1
|
+
import { t as GkmError } from "./errors-C9uIyIDt.mjs";
|
|
2
|
+
import { p as dockerHost } from "./compose-Glqs13is.mjs";
|
|
3
|
+
import { Ct as isDatabase, St as envFor } from "./apps-D2oTQasd.mjs";
|
|
4
|
+
import { ut as primaryPortKey } from "./compose-BpnSP2x7.mjs";
|
|
5
|
+
import { i as LOOPBACK_SERVICES } from "./stack-BHrGbsGA.mjs";
|
|
6
|
+
import { i as stageServer, n as defaultStageExecDeps, r as loadStage, t as ExecNotConfirmed } from "./stage-BSZ9890H.mjs";
|
|
7
|
+
import { providedKeyFor } from "@geekmidas/manifest";
|
|
8
|
+
//#region src/exec/dbTunnel.ts
|
|
9
|
+
/**
|
|
10
|
+
* `gkm db:tunnel --stage <stage> [construct]`: a deployed compose stage's
|
|
11
|
+
* Postgres, on this machine's loopback, and each database's owner login to
|
|
12
|
+
* sign in to it with — for a SQL client, a one-off fix, a look at the data.
|
|
13
|
+
*
|
|
14
|
+
* The tunnel is the deploy's own: SSH on the deploy's login to the port the
|
|
15
|
+
* server publishes Postgres on, its loopback alone. The owner URL is the one
|
|
16
|
+
* the deploy migrates with, derived from the stage's secrets the way the
|
|
17
|
+
* deploy derives it — nothing is stored, and nothing is written to disk.
|
|
18
|
+
*
|
|
19
|
+
* It is the owner, not the app's login, because that is what a person
|
|
20
|
+
* changing the schema or its data by hand needs; it is printed, not injected,
|
|
21
|
+
* because a GUI client is not a process gkm starts. `gkm exec --stage` stays
|
|
22
|
+
* the app's login: what a script runs as is what the app runs as.
|
|
23
|
+
*/
|
|
24
|
+
const logger = console;
|
|
25
|
+
/** The stage's stack runs no Postgres: there is nothing to tunnel to. */
|
|
26
|
+
var StageHasNoDatabase = class extends GkmError {
|
|
27
|
+
stage;
|
|
28
|
+
constructor(stage) {
|
|
29
|
+
super(`'${stage}' runs no Postgres, so there is no database to tunnel to. Declare a Database construct and deploy the stage.`);
|
|
30
|
+
this.stage = stage;
|
|
31
|
+
this.name = "StageHasNoDatabase";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** The construct asked for is not one of the stage's databases. */
|
|
35
|
+
var DatabaseNotInStage = class extends GkmError {
|
|
36
|
+
stage;
|
|
37
|
+
construct;
|
|
38
|
+
databases;
|
|
39
|
+
constructor(stage, construct, databases) {
|
|
40
|
+
super(`'${construct}' is not a database '${stage}' runs. Its databases are ${databases.join(", ")}: gkm db:tunnel --stage ${stage} ${databases[0] ?? "<construct>"}.`);
|
|
41
|
+
this.stage = stage;
|
|
42
|
+
this.construct = construct;
|
|
43
|
+
this.databases = databases;
|
|
44
|
+
this.name = "DatabaseNotInStage";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** The server publishes no Postgres: the stack is not running there. */
|
|
48
|
+
var DatabaseNotPublished = class extends GkmError {
|
|
49
|
+
stage;
|
|
50
|
+
project;
|
|
51
|
+
constructor(stage, project) {
|
|
52
|
+
super(`No running ${project} postgres publishes ${LOOPBACK_SERVICES.postgres} on '${stage}'s server, so there is nothing to tunnel to. Deploy the stage (gkm deploy --stage ${stage}), then run this again.`);
|
|
53
|
+
this.stage = stage;
|
|
54
|
+
this.project = project;
|
|
55
|
+
this.name = "DatabaseNotPublished";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/** A login's URL as a SQL client's form asks for it, field by field. */
|
|
59
|
+
function loginFields(url) {
|
|
60
|
+
const parsed = new URL(url);
|
|
61
|
+
return [
|
|
62
|
+
["host", parsed.hostname],
|
|
63
|
+
["port", parsed.port],
|
|
64
|
+
["database", decodeURIComponent(parsed.pathname.slice(1))],
|
|
65
|
+
["user", decodeURIComponent(parsed.username)],
|
|
66
|
+
["password", decodeURIComponent(parsed.password)]
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Each database's owner URL — every one, or the construct asked for — on
|
|
71
|
+
* the port this machine reaches the stack's Postgres by: the same values the
|
|
72
|
+
* deploy's migrations connect with (`migrateAndSeed`), from the same
|
|
73
|
+
* derivation.
|
|
74
|
+
*
|
|
75
|
+
* @throws {DatabaseNotInStage}
|
|
76
|
+
*/
|
|
77
|
+
function ownerLogins(stack, port, construct) {
|
|
78
|
+
const env = envFor(stack.plan, {
|
|
79
|
+
...stack.resolution,
|
|
80
|
+
ports: { [primaryPortKey("postgres")]: port }
|
|
81
|
+
});
|
|
82
|
+
const logins = stack.plan.resources.filter((resource) => isDatabase(resource.kind)).map((resource) => {
|
|
83
|
+
const key = providedKeyFor(resource.id, resource.kind, "ownerUrl");
|
|
84
|
+
const url = env[key] ?? env[resource.envKey];
|
|
85
|
+
return url ? {
|
|
86
|
+
construct: resource.id,
|
|
87
|
+
key,
|
|
88
|
+
url
|
|
89
|
+
} : void 0;
|
|
90
|
+
}).filter((login) => login !== void 0);
|
|
91
|
+
if (construct === void 0) return logins;
|
|
92
|
+
const asked = logins.filter((login) => login.construct === construct);
|
|
93
|
+
if (asked.length === 0) throw new DatabaseNotInStage(stack.stage, construct, logins.map((login) => login.construct));
|
|
94
|
+
return asked;
|
|
95
|
+
}
|
|
96
|
+
/** Until the person presses Ctrl-C, or the process is told to stop. */
|
|
97
|
+
function untilInterrupted() {
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
const stop = () => {
|
|
100
|
+
process.off("SIGINT", stop);
|
|
101
|
+
process.off("SIGTERM", stop);
|
|
102
|
+
resolve();
|
|
103
|
+
};
|
|
104
|
+
process.on("SIGINT", stop);
|
|
105
|
+
process.on("SIGTERM", stop);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const defaultDbTunnelDeps = {
|
|
109
|
+
...defaultStageExecDeps,
|
|
110
|
+
held: untilInterrupted
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Open a tunnel to the stage's Postgres, print each database's owner URL
|
|
114
|
+
* through it, and hold it open until `deps.held` resolves. The tunnel is
|
|
115
|
+
* closed however that ends.
|
|
116
|
+
*
|
|
117
|
+
* @throws {StageHasNoDatabase}, {DatabaseNotInStage}, {DatabaseNotPublished},
|
|
118
|
+
* {ExecNotConfirmed}, {ExecStageNotComposed}, {ExecStageNotDeployed},
|
|
119
|
+
* {ComposeServerUnreachable}
|
|
120
|
+
*/
|
|
121
|
+
async function dbTunnel(options, deps = defaultDbTunnelDeps) {
|
|
122
|
+
const { stage } = options;
|
|
123
|
+
const loaded = await loadStage(options, deps.env);
|
|
124
|
+
const { stack } = loaded;
|
|
125
|
+
if (!stack.infra.includes("postgres")) throw new StageHasNoDatabase(stage);
|
|
126
|
+
ownerLogins(stack, LOOPBACK_SERVICES.postgres, options.construct);
|
|
127
|
+
if (loaded.protectedStage && !options.yes) {
|
|
128
|
+
const question = `'${stage}' is a protected stage. Open a tunnel to its database as its owner?`;
|
|
129
|
+
if (!await deps.confirm(question)) throw new ExecNotConfirmed(stage);
|
|
130
|
+
}
|
|
131
|
+
const server = stageServer(loaded, options);
|
|
132
|
+
await deps.server.check(server);
|
|
133
|
+
const published = await deps.docker.published({ host: dockerHost(server) }, stack.project, "postgres", LOOPBACK_SERVICES.postgres);
|
|
134
|
+
if (published === void 0) throw new DatabaseNotPublished(stage, stack.project);
|
|
135
|
+
const tunnel = await deps.server.tunnel(server, published);
|
|
136
|
+
try {
|
|
137
|
+
const logins = ownerLogins(stack, tunnel.port, options.construct);
|
|
138
|
+
logger.log(`🚇 '${stage}' postgres → 127.0.0.1:${tunnel.port} (over SSH to ${server.host})`);
|
|
139
|
+
for (const login of logins) {
|
|
140
|
+
logger.log(`\n🔑 ${login.construct} (${login.key})`);
|
|
141
|
+
logger.log(` ${login.url}`);
|
|
142
|
+
for (const [field, value] of loginFields(login.url)) logger.log(` ${`${field}:`.padEnd(10)}${value}`);
|
|
143
|
+
}
|
|
144
|
+
logger.log("\nThe tunnel is open. Press Ctrl-C to close it.");
|
|
145
|
+
await deps.held();
|
|
146
|
+
return logins;
|
|
147
|
+
} finally {
|
|
148
|
+
await tunnel.close();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { dbTunnel };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=dbTunnel-KgbAh2v1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTunnel-KgbAh2v1.mjs","names":[],"sources":["../src/exec/dbTunnel.ts"],"sourcesContent":["/**\n * `gkm db:tunnel --stage <stage> [construct]`: a deployed compose stage's\n * Postgres, on this machine's loopback, and each database's owner login to\n * sign in to it with — for a SQL client, a one-off fix, a look at the data.\n *\n * The tunnel is the deploy's own: SSH on the deploy's login to the port the\n * server publishes Postgres on, its loopback alone. The owner URL is the one\n * the deploy migrates with, derived from the stage's secrets the way the\n * deploy derives it — nothing is stored, and nothing is written to disk.\n *\n * It is the owner, not the app's login, because that is what a person\n * changing the schema or its data by hand needs; it is printed, not injected,\n * because a GUI client is not a process gkm starts. `gkm exec --stage` stays\n * the app's login: what a script runs as is what the app runs as.\n */\n\nimport { providedKeyFor } from '@geekmidas/manifest';\nimport { dockerHost } from '../compose/server.js';\nimport type { ComposeStack } from '../compose/stack.js';\nimport { LOOPBACK_SERVICES } from '../compose/stack.js';\nimport { GkmError } from '../errors';\nimport { primaryPortKey } from '../reconcile/containers.js';\nimport { envFor, isDatabase } from '../reconcile/env.js';\nimport {\n\tdefaultStageExecDeps,\n\tExecNotConfirmed,\n\tloadStage,\n\ttype StageExecDeps,\n\ttype StageExecOptions,\n\tstageServer,\n} from './stage.js';\n\nconst logger = console;\n\n/** The stage's stack runs no Postgres: there is nothing to tunnel to. */\nexport class StageHasNoDatabase extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`'${stage}' runs no Postgres, so there is no database to tunnel to. ` +\n\t\t\t\t'Declare a Database construct and deploy the stage.',\n\t\t);\n\t\tthis.name = 'StageHasNoDatabase';\n\t}\n}\n\n/** The construct asked for is not one of the stage's databases. */\nexport class DatabaseNotInStage extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly construct: string,\n\t\treadonly databases: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${construct}' is not a database '${stage}' runs. Its databases are ` +\n\t\t\t\t`${databases.join(', ')}: gkm db:tunnel --stage ${stage} ` +\n\t\t\t\t`${databases[0] ?? '<construct>'}.`,\n\t\t);\n\t\tthis.name = 'DatabaseNotInStage';\n\t}\n}\n\n/** The server publishes no Postgres: the stack is not running there. */\nexport class DatabaseNotPublished extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`No running ${project} postgres publishes ${LOOPBACK_SERVICES.postgres} ` +\n\t\t\t\t`on '${stage}'s server, so there is nothing to tunnel to. Deploy the ` +\n\t\t\t\t`stage (gkm deploy --stage ${stage}), then run this again.`,\n\t\t);\n\t\tthis.name = 'DatabaseNotPublished';\n\t}\n}\n\n/** A database's owner login, as this machine reaches it. */\nexport interface OwnerLogin {\n\t/** The construct's id. */\n\tconstruct: string;\n\t/** The key the deploy's migrations read it from. */\n\tkey: string;\n\turl: string;\n}\n\n/** A login's URL as a SQL client's form asks for it, field by field. */\nexport function loginFields(url: string): [string, string][] {\n\tconst parsed = new URL(url);\n\treturn [\n\t\t['host', parsed.hostname],\n\t\t['port', parsed.port],\n\t\t['database', decodeURIComponent(parsed.pathname.slice(1))],\n\t\t['user', decodeURIComponent(parsed.username)],\n\t\t['password', decodeURIComponent(parsed.password)],\n\t];\n}\n\n/**\n * Each database's owner URL — every one, or the construct asked for — on\n * the port this machine reaches the stack's Postgres by: the same values the\n * deploy's migrations connect with (`migrateAndSeed`), from the same\n * derivation.\n *\n * @throws {DatabaseNotInStage}\n */\nexport function ownerLogins(\n\tstack: Pick<ComposeStack, 'stage' | 'plan' | 'resolution'>,\n\tport: number,\n\tconstruct?: string,\n): OwnerLogin[] {\n\tconst env = envFor(stack.plan, {\n\t\t...stack.resolution,\n\t\tports: { [primaryPortKey('postgres')]: port },\n\t});\n\tconst logins = stack.plan.resources\n\t\t.filter((resource) => isDatabase(resource.kind))\n\t\t.map((resource) => {\n\t\t\tconst key = providedKeyFor(resource.id, resource.kind, 'ownerUrl');\n\t\t\t// A database whose roles are not split has no owner: its one login\n\t\t\t// is the URL itself, and that is the one to sign in with.\n\t\t\tconst url = env[key] ?? env[resource.envKey];\n\t\t\treturn url ? { construct: resource.id, key, url } : undefined;\n\t\t})\n\t\t.filter((login): login is OwnerLogin => login !== undefined);\n\n\tif (construct === undefined) return logins;\n\tconst asked = logins.filter((login) => login.construct === construct);\n\tif (asked.length === 0) {\n\t\tthrow new DatabaseNotInStage(\n\t\t\tstack.stage,\n\t\t\tconstruct,\n\t\t\tlogins.map((login) => login.construct),\n\t\t);\n\t}\n\treturn asked;\n}\n\nexport interface DbTunnelOptions\n\textends Pick<\n\t\tStageExecOptions,\n\t\t'stage' | 'profile' | 'sshUser' | 'yes' | 'cwd'\n\t> {\n\t/** One database construct, by id. Every one when absent. */\n\tconstruct?: string;\n}\n\nexport interface DbTunnelDeps extends StageExecDeps {\n\t/** Resolves when the tunnel should close: Ctrl-C, by default. */\n\theld: () => Promise<void>;\n}\n\n/** Until the person presses Ctrl-C, or the process is told to stop. */\nfunction untilInterrupted(): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tconst stop = () => {\n\t\t\tprocess.off('SIGINT', stop);\n\t\t\tprocess.off('SIGTERM', stop);\n\t\t\tresolve();\n\t\t};\n\t\tprocess.on('SIGINT', stop);\n\t\tprocess.on('SIGTERM', stop);\n\t});\n}\n\nexport const defaultDbTunnelDeps: DbTunnelDeps = {\n\t...defaultStageExecDeps,\n\theld: untilInterrupted,\n};\n\n/**\n * Open a tunnel to the stage's Postgres, print each database's owner URL\n * through it, and hold it open until `deps.held` resolves. The tunnel is\n * closed however that ends.\n *\n * @throws {StageHasNoDatabase}, {DatabaseNotInStage}, {DatabaseNotPublished},\n * {ExecNotConfirmed}, {ExecStageNotComposed}, {ExecStageNotDeployed},\n * {ComposeServerUnreachable}\n */\nexport async function dbTunnel(\n\toptions: DbTunnelOptions,\n\tdeps: DbTunnelDeps = defaultDbTunnelDeps,\n): Promise<OwnerLogin[]> {\n\tconst { stage } = options;\n\tconst loaded = await loadStage(options, deps.env);\n\tconst { stack } = loaded;\n\tif (!stack.infra.includes('postgres')) throw new StageHasNoDatabase(stage);\n\t// Asked here, before anything is reached: an unknown construct is said\n\t// without an SSH login. The port is a placeholder until the tunnel opens.\n\townerLogins(stack, LOOPBACK_SERVICES.postgres, options.construct);\n\n\tif (loaded.protectedStage && !options.yes) {\n\t\tconst question = `'${stage}' is a protected stage. Open a tunnel to its database as its owner?`;\n\t\tif (!(await deps.confirm(question))) throw new ExecNotConfirmed(stage);\n\t}\n\n\tconst server = stageServer(loaded, options);\n\tawait deps.server.check(server);\n\n\tconst published = await deps.docker.published(\n\t\t{ host: dockerHost(server) },\n\t\tstack.project,\n\t\t'postgres',\n\t\tLOOPBACK_SERVICES.postgres,\n\t);\n\tif (published === undefined) {\n\t\tthrow new DatabaseNotPublished(stage, stack.project);\n\t}\n\n\tconst tunnel = await deps.server.tunnel(server, published);\n\ttry {\n\t\tconst logins = ownerLogins(stack, tunnel.port, options.construct);\n\t\tlogger.log(\n\t\t\t`🚇 '${stage}' postgres → 127.0.0.1:${tunnel.port} (over SSH to ${server.host})`,\n\t\t);\n\t\tfor (const login of logins) {\n\t\t\tlogger.log(`\\n🔑 ${login.construct} (${login.key})`);\n\t\t\tlogger.log(` ${login.url}`);\n\t\t\tfor (const [field, value] of loginFields(login.url)) {\n\t\t\t\tlogger.log(` ${`${field}:`.padEnd(10)}${value}`);\n\t\t\t}\n\t\t}\n\t\tlogger.log('\\nThe tunnel is open. Press Ctrl-C to close it.');\n\t\tawait deps.held();\n\t\treturn logins;\n\t} finally {\n\t\tawait tunnel.close();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,SAAS;;AAGf,IAAa,qBAAb,cAAwC,SAAS;CAC3B;CAArB,YAAY,OAA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B,MAAM,IAAI,qBAAqB,OAAO,MAAM,OAAO;CAGpD,MAAM,SAAS,MAAM,KAAK,OAAO,OAAO,QAAQ,SAAS;CACzD,IAAI;EACH,MAAM,SAAS,YAAY,OAAO,OAAO,MAAM,QAAQ,SAAS;EAChE,OAAO,IACN,OAAO,MAAM,yBAAyB,OAAO,KAAK,gBAAgB,OAAO,KAAK,EAC/E;EACA,KAAK,MAAM,SAAS,QAAQ;GAC3B,OAAO,IAAI,QAAQ,MAAM,UAAU,IAAI,MAAM,IAAI,EAAE;GACnD,OAAO,IAAI,MAAM,MAAM,KAAK;GAC5B,KAAK,MAAM,CAAC,OAAO,UAAU,YAAY,MAAM,GAAG,GACjD,OAAO,IAAI,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,IAAI,OAAO;EAEnD;EACA,OAAO,IAAI,iDAAiD;EAC5D,MAAM,KAAK,KAAK;EAChB,OAAO;CACR,UAAU;EACT,MAAM,OAAO,MAAM;CACpB;AACD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { t as GkmError } from "./errors-C9uIyIDt.mjs";
|
|
2
|
+
//#region src/target/builtins.ts
|
|
3
|
+
/**
|
|
4
|
+
* The target names the CLI knows without being told, and how a name is
|
|
5
|
+
* looked up.
|
|
6
|
+
*
|
|
7
|
+
* Plain data, so the config schema and `providerOf` — which `gkm dev` and
|
|
8
|
+
* `gkm build` call synchronously on every start — can ask what a name means
|
|
9
|
+
* without importing a deploy engine.
|
|
10
|
+
*/
|
|
11
|
+
const BUILTIN_TARGETS = {
|
|
12
|
+
dokploy: {
|
|
13
|
+
runtime: "server",
|
|
14
|
+
status: "available"
|
|
15
|
+
},
|
|
16
|
+
compose: {
|
|
17
|
+
runtime: "server",
|
|
18
|
+
status: "available"
|
|
19
|
+
},
|
|
20
|
+
sst: {
|
|
21
|
+
runtime: "aws",
|
|
22
|
+
status: "available"
|
|
23
|
+
},
|
|
24
|
+
vercel: {
|
|
25
|
+
runtime: "aws",
|
|
26
|
+
status: "planned"
|
|
27
|
+
},
|
|
28
|
+
cloudflare: {
|
|
29
|
+
runtime: "aws",
|
|
30
|
+
status: "planned"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** The built-in target called `name`, if one is. */
|
|
34
|
+
function builtinTarget(name) {
|
|
35
|
+
return Object.hasOwn(BUILTIN_TARGETS, name) ? BUILTIN_TARGETS[name] : void 0;
|
|
36
|
+
}
|
|
37
|
+
/** Built-in names a config may use. */
|
|
38
|
+
function configurableBuiltins() {
|
|
39
|
+
return Object.entries(BUILTIN_TARGETS).filter(([, target]) => target.status !== "planned").map(([name]) => name);
|
|
40
|
+
}
|
|
41
|
+
/** The `deploy.targets` entry called `name`, if the config has one. */
|
|
42
|
+
function configuredTarget(deploy, name) {
|
|
43
|
+
const targets = deploy?.targets;
|
|
44
|
+
return targets && Object.hasOwn(targets, name) ? targets[name] : void 0;
|
|
45
|
+
}
|
|
46
|
+
/** A target name that is neither built in nor in `deploy.targets`. */
|
|
47
|
+
var UnknownDeployTarget = class extends GkmError {
|
|
48
|
+
target;
|
|
49
|
+
known;
|
|
50
|
+
constructor(target, known) {
|
|
51
|
+
super(`Unknown deploy target "${target}". Use one of ${known.join(", ")}, or name the package that provides it in gkm.config.ts: deploy: { targets: { ${JSON.stringify(target)}: '<package>' } }.`);
|
|
52
|
+
this.target = target;
|
|
53
|
+
this.known = known;
|
|
54
|
+
this.name = "UnknownDeployTarget";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/** A built-in target `gkm deploy` cannot deploy through yet. */
|
|
58
|
+
var DeployTargetNotYetSupported = class extends GkmError {
|
|
59
|
+
target;
|
|
60
|
+
instead;
|
|
61
|
+
constructor(target, instead) {
|
|
62
|
+
super(instead ? `gkm deploy cannot deploy through "${target}" yet: ${instead}.` : `Deploy target "${target}" is not supported yet. Deploy with dokploy, or name a target package in deploy.targets.`);
|
|
63
|
+
this.target = target;
|
|
64
|
+
this.instead = instead;
|
|
65
|
+
this.name = "DeployTargetNotYetSupported";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/target/define.ts
|
|
70
|
+
/**
|
|
71
|
+
* A deploy target, typed from what it is written with: the options from its
|
|
72
|
+
* `options` schema, the run state from what `validate` returns. Nothing
|
|
73
|
+
* happens at runtime — it returns the target as given.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* export default defineTarget({
|
|
77
|
+
* name: 'fly',
|
|
78
|
+
* runtime: 'server',
|
|
79
|
+
* capabilities: { rollback: true, migrations: 'target', images: true },
|
|
80
|
+
* options: z.object({ org: z.string() }),
|
|
81
|
+
* async validate(ctx) {
|
|
82
|
+
* return { org: ctx.options.org }; // ctx.options: { org: string }
|
|
83
|
+
* },
|
|
84
|
+
* async release(ctx, run) { … }, // run: { org: string }
|
|
85
|
+
* …
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
function defineTarget(target) {
|
|
90
|
+
return target;
|
|
91
|
+
}
|
|
92
|
+
/** Whether `value` has the shape of a target. */
|
|
93
|
+
function isDeployTarget(value) {
|
|
94
|
+
if (!value || typeof value !== "object") return false;
|
|
95
|
+
const candidate = value;
|
|
96
|
+
return typeof candidate.name === "string" && (candidate.runtime === "server" || candidate.runtime === "aws") && typeof candidate.capabilities === "object" && candidate.capabilities !== null && [
|
|
97
|
+
"validate",
|
|
98
|
+
"plan",
|
|
99
|
+
"release",
|
|
100
|
+
"result"
|
|
101
|
+
].every((phase) => typeof candidate[phase] === "function");
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { UnknownDeployTarget as a, configuredTarget as c, DeployTargetNotYetSupported as i, isDeployTarget as n, builtinTarget as o, BUILTIN_TARGETS as r, configurableBuiltins as s, defineTarget as t };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=define-BfrNaY82.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-BfrNaY82.mjs","names":[],"sources":["../src/target/builtins.ts","../src/target/define.ts"],"sourcesContent":["/**\n * The target names the CLI knows without being told, and how a name is\n * looked up.\n *\n * Plain data, so the config schema and `providerOf` — which `gkm dev` and\n * `gkm build` call synchronously on every start — can ask what a name means\n * without importing a deploy engine.\n */\n\nimport { GkmError } from '../errors';\nimport type { DeployRuntime, DeployTargetEntry } from './types';\n\n/**\n * - `available`: `gkm deploy` deploys through it.\n * - `external`: a valid `deploy.default` that builds and runs locally, but is\n * deployed by its own tool — `gkm deploy` refuses it and says which.\n * - `planned`: reserved, and refused everywhere.\n */\nexport type BuiltinStatus = 'available' | 'external' | 'planned';\n\nexport interface BuiltinTarget {\n\treadonly runtime: DeployRuntime;\n\treadonly status: BuiltinStatus;\n\t/** What to do instead, for a target `gkm deploy` cannot deploy through yet. */\n\treadonly instead?: (stage: string) => string;\n}\n\nexport const BUILTIN_TARGETS = {\n\tdokploy: { runtime: 'server', status: 'available' },\n\t// One Docker Compose stack behind Caddy, on the machine that runs it.\n\tcompose: { runtime: 'server', status: 'available' },\n\tsst: { runtime: 'aws', status: 'available' },\n\t// Neither runs containers the project controls, so both take the managed\n\t// defaults when they arrive.\n\tvercel: { runtime: 'aws', status: 'planned' },\n\tcloudflare: { runtime: 'aws', status: 'planned' },\n} as const satisfies Record<string, BuiltinTarget>;\n\nexport type BuiltinTargetName = keyof typeof BUILTIN_TARGETS;\n\n/** The built-in target called `name`, if one is. */\nexport function builtinTarget(name: string): BuiltinTarget | undefined {\n\treturn Object.hasOwn(BUILTIN_TARGETS, name)\n\t\t? BUILTIN_TARGETS[name as BuiltinTargetName]\n\t\t: undefined;\n}\n\n/** Built-in names a config may use. */\nexport function configurableBuiltins(): string[] {\n\treturn Object.entries(BUILTIN_TARGETS)\n\t\t.filter(([, target]) => target.status !== 'planned')\n\t\t.map(([name]) => name);\n}\n\n/** The `deploy.targets` entry called `name`, if the config has one. */\nexport function configuredTarget(\n\tdeploy: { targets?: Record<string, DeployTargetEntry> } | undefined,\n\tname: string,\n): DeployTargetEntry | undefined {\n\tconst targets = deploy?.targets;\n\treturn targets && Object.hasOwn(targets, name) ? targets[name] : undefined;\n}\n\n/** A target name that is neither built in nor in `deploy.targets`. */\nexport class UnknownDeployTarget extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\t/** The names that would have resolved. */\n\t\treadonly known: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Unknown deploy target \"${target}\". Use one of ${known.join(', ')}, or name the package that provides it in gkm.config.ts: deploy: { targets: { ${JSON.stringify(target)}: '<package>' } }.`,\n\t\t);\n\t\tthis.name = 'UnknownDeployTarget';\n\t}\n}\n\n/** A built-in target `gkm deploy` cannot deploy through yet. */\nexport class DeployTargetNotYetSupported extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\t/** What to do instead, when there is something. */\n\t\treadonly instead?: string,\n\t) {\n\t\tsuper(\n\t\t\tinstead\n\t\t\t\t? `gkm deploy cannot deploy through \"${target}\" yet: ${instead}.`\n\t\t\t\t: `Deploy target \"${target}\" is not supported yet. Deploy with dokploy, or name a target package in deploy.targets.`,\n\t\t);\n\t\tthis.name = 'DeployTargetNotYetSupported';\n\t}\n}\n","import type { AnyDeployTarget, DeployTarget } from './types';\n\n/**\n * A deploy target, typed from what it is written with: the options from its\n * `options` schema, the run state from what `validate` returns. Nothing\n * happens at runtime — it returns the target as given.\n *\n * ```ts\n * export default defineTarget({\n * name: 'fly',\n * runtime: 'server',\n * capabilities: { rollback: true, migrations: 'target', images: true },\n * options: z.object({ org: z.string() }),\n * async validate(ctx) {\n * return { org: ctx.options.org }; // ctx.options: { org: string }\n * },\n * async release(ctx, run) { … }, // run: { org: string }\n * …\n * });\n * ```\n */\nexport function defineTarget<Options = undefined, Run = void>(\n\ttarget: DeployTarget<Options, Run>,\n): DeployTarget<Options, Run> {\n\treturn target;\n}\n\n/** Whether `value` has the shape of a target. */\nexport function isDeployTarget(value: unknown): value is AnyDeployTarget {\n\tif (!value || typeof value !== 'object') return false;\n\tconst candidate = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof candidate.name === 'string' &&\n\t\t(candidate.runtime === 'server' || candidate.runtime === 'aws') &&\n\t\ttypeof candidate.capabilities === 'object' &&\n\t\tcandidate.capabilities !== null &&\n\t\t['validate', 'plan', 'release', 'result'].every(\n\t\t\t(phase) => typeof candidate[phase] === 'function',\n\t\t)\n\t);\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAa,kBAAkB;CAC9B,SAAS;EAAE,SAAS;EAAU,QAAQ;CAAY;CAElD,SAAS;EAAE,SAAS;EAAU,QAAQ;CAAY;CAClD,KAAK;EAAE,SAAS;EAAO,QAAQ;CAAY;CAG3C,QAAQ;EAAE,SAAS;EAAO,QAAQ;CAAU;CAC5C,YAAY;EAAE,SAAS;EAAO,QAAQ;CAAU;AACjD;;AAKA,SAAgB,cAAc,MAAyC;CACtE,OAAO,OAAO,OAAO,iBAAiB,IAAI,IACvC,gBAAgB,QAChB,KAAA;AACJ;;AAGA,SAAgB,uBAAiC;CAChD,OAAO,OAAO,QAAQ,eAAe,CAAC,CACpC,QAAQ,GAAG,YAAY,OAAO,WAAW,SAAS,CAAC,CACnD,KAAK,CAAC,UAAU,IAAI;AACvB;;AAGA,SAAgB,iBACf,QACA,MACgC;CAChC,MAAM,UAAU,QAAQ;CACxB,OAAO,WAAW,OAAO,OAAO,SAAS,IAAI,IAAI,QAAQ,QAAQ,KAAA;AAClE;;AAGA,IAAa,sBAAb,cAAyC,SAAS;CAEvC;CAEA;CAHV,YACC,QAEA,OACC;EACD,MACC,0BAA0B,OAAO,gBAAgB,MAAM,KAAK,IAAI,EAAE,gFAAgF,KAAK,UAAU,MAAM,EAAE,mBAC1K;EANS,KAAA,SAAA;EAEA,KAAA,QAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,8BAAb,cAAiD,SAAS;CAE/C;CAEA;CAHV,YACC,QAEA,SACC;EACD,MACC,UACG,qCAAqC,OAAO,S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