@geekmidas/cli 10.0.0-alpha.180 → 10.0.0-alpha.182
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/dist/{LegacyStateStore-l0hBdv-E.cjs → LegacyStateStore-BRP6O9rR.cjs} +2 -2
- package/dist/{LegacyStateStore-l0hBdv-E.cjs.map → LegacyStateStore-BRP6O9rR.cjs.map} +1 -1
- package/dist/{LegacyStateStore-B7pQA25B.mjs → LegacyStateStore-CicrAWKh.mjs} +2 -2
- package/dist/{LegacyStateStore-B7pQA25B.mjs.map → LegacyStateStore-CicrAWKh.mjs.map} +1 -1
- package/dist/{LocalStateStore-DEE0Kc_s.cjs → LocalStateStore-BeEftmvd.cjs} +2 -2
- package/dist/{LocalStateStore-DEE0Kc_s.cjs.map → LocalStateStore-BeEftmvd.cjs.map} +1 -1
- package/dist/{LocalStateStore-CP0UHL85.mjs → LocalStateStore-n8BSxbT3.mjs} +2 -2
- package/dist/{LocalStateStore-CP0UHL85.mjs.map → LocalStateStore-n8BSxbT3.mjs.map} +1 -1
- package/dist/{S3StateStore-vmxZWMKh.mjs → S3StateStore-Csz1OtTD.mjs} +4 -4
- package/dist/{S3StateStore-vmxZWMKh.mjs.map → S3StateStore-Csz1OtTD.mjs.map} +1 -1
- package/dist/{S3StateStore-DE0BNuXc.cjs → S3StateStore-DJHzMqUg.cjs} +4 -4
- package/dist/{S3StateStore-DE0BNuXc.cjs.map → S3StateStore-DJHzMqUg.cjs.map} +1 -1
- package/dist/{SSMStateStore-DQyXnX2M.mjs → SSMStateStore-BmjXQQwi.mjs} +2 -2
- package/dist/{SSMStateStore-DQyXnX2M.mjs.map → SSMStateStore-BmjXQQwi.mjs.map} +1 -1
- package/dist/{SSMStateStore-p4hBdTg3.cjs → SSMStateStore-FH5SxNud.cjs} +2 -2
- package/dist/{SSMStateStore-p4hBdTg3.cjs.map → SSMStateStore-FH5SxNud.cjs.map} +1 -1
- package/dist/{add-DEdpKya-.cjs → add-B0U_pQSW.cjs} +4 -4
- package/dist/{add-DEdpKya-.cjs.map → add-B0U_pQSW.cjs.map} +1 -1
- package/dist/{add-QBvDmVA-.mjs → add-CI9ffZN7.mjs} +4 -4
- package/dist/{add-QBvDmVA-.mjs.map → add-CI9ffZN7.mjs.map} +1 -1
- package/dist/{apps-D0LULFmU.mjs → apps-BlwS8CjS.mjs} +3 -3
- package/dist/{apps-D0LULFmU.mjs.map → apps-BlwS8CjS.mjs.map} +1 -1
- package/dist/{apps-qJ5FPJGQ.cjs → apps-_6kKM67e.cjs} +3 -3
- package/dist/{apps-qJ5FPJGQ.cjs.map → apps-_6kKM67e.cjs.map} +1 -1
- package/dist/{bundler-BuBCXA0t.cjs → bundler--KfgyGP8.cjs} +6 -6
- package/dist/{bundler-BuBCXA0t.cjs.map → bundler--KfgyGP8.cjs.map} +1 -1
- package/dist/{bundler-DZKdVVKZ.mjs → bundler-DhIA5K-G.mjs} +6 -6
- package/dist/{bundler-DZKdVVKZ.mjs.map → bundler-DhIA5K-G.mjs.map} +1 -1
- package/dist/{cli-CgEbT00Q.mjs → cli-CS6ecPI1.mjs} +4 -4
- package/dist/{cli-CgEbT00Q.mjs.map → cli-CS6ecPI1.mjs.map} +1 -1
- package/dist/{cli-BCGkzaR1.cjs → cli-rfpwJQbd.cjs} +4 -4
- package/dist/{cli-BCGkzaR1.cjs.map → cli-rfpwJQbd.cjs.map} +1 -1
- package/dist/{compose-C-yjexqX.cjs → compose-BzFV_0Q9.cjs} +4 -4
- package/dist/{compose-C-yjexqX.cjs.map → compose-BzFV_0Q9.cjs.map} +1 -1
- package/dist/{compose-AO8u4mBI.cjs → compose-CdVh0nqk.cjs} +91 -15
- package/dist/compose-CdVh0nqk.cjs.map +1 -0
- package/dist/{compose-C23RpAaF.mjs → compose-TWiIQaA5.mjs} +91 -15
- package/dist/compose-TWiIQaA5.mjs.map +1 -0
- package/dist/{compose-DtfoUChm.mjs → compose-afWlhnJ2.mjs} +4 -4
- package/dist/{compose-DtfoUChm.mjs.map → compose-afWlhnJ2.mjs.map} +1 -1
- package/dist/{dbTunnel-Bve0zBqT.cjs → dbTunnel-BX6c-a7j.cjs} +6 -6
- package/dist/{dbTunnel-Bve0zBqT.cjs.map → dbTunnel-BX6c-a7j.cjs.map} +1 -1
- package/dist/{dbTunnel-CnubkLBa.mjs → dbTunnel-C7nukvfw.mjs} +6 -6
- package/dist/{dbTunnel-CnubkLBa.mjs.map → dbTunnel-C7nukvfw.mjs.map} +1 -1
- package/dist/deploy/public.cjs +10 -10
- package/dist/deploy/public.mjs +10 -10
- package/dist/{deploy-C2MKxzm9.cjs → deploy-CsA10pJq.cjs} +11 -11
- package/dist/{deploy-C2MKxzm9.cjs.map → deploy-CsA10pJq.cjs.map} +1 -1
- package/dist/{deploy-Qq41vtpm.mjs → deploy-qacf9be0.mjs} +11 -11
- package/dist/{deploy-Qq41vtpm.mjs.map → deploy-qacf9be0.mjs.map} +1 -1
- package/dist/{destroy-Bg4IUf_Z.mjs → destroy-DLiq343o.mjs} +7 -7
- package/dist/{destroy-Bg4IUf_Z.mjs.map → destroy-DLiq343o.mjs.map} +1 -1
- package/dist/{destroy-CCpnHI2v.cjs → destroy-ngZALiav.cjs} +7 -7
- package/dist/{destroy-CCpnHI2v.cjs.map → destroy-ngZALiav.cjs.map} +1 -1
- package/dist/{dns-BAM8VH1v.mjs → dns-Clnn8_Da.mjs} +3 -3
- package/dist/{dns-BAM8VH1v.mjs.map → dns-Clnn8_Da.mjs.map} +1 -1
- package/dist/{dns-D_0z9Tm1.cjs → dns-DHyogtOl.cjs} +3 -3
- package/dist/{dns-D_0z9Tm1.cjs.map → dns-DHyogtOl.cjs.map} +1 -1
- package/dist/{docker-DQoE3Fr7.mjs → docker-8jRkfK5W.mjs} +4 -4
- package/dist/{docker-DQoE3Fr7.mjs.map → docker-8jRkfK5W.mjs.map} +1 -1
- package/dist/{docker-6EUbKrEl.cjs → docker-CvDjL4Ar.cjs} +4 -4
- package/dist/{docker-6EUbKrEl.cjs.map → docker-CvDjL4Ar.cjs.map} +1 -1
- package/dist/{dokploy-CU9iuc35.mjs → dokploy-C-uuNLDW.mjs} +2 -2
- package/dist/{dokploy-CU9iuc35.mjs.map → dokploy-C-uuNLDW.mjs.map} +1 -1
- package/dist/{dokploy-BD8NXy8y.cjs → dokploy-DMkSjuui.cjs} +2 -2
- package/dist/{dokploy-BD8NXy8y.cjs.map → dokploy-DMkSjuui.cjs.map} +1 -1
- package/dist/{eas-BhTOdQrE.cjs → eas-BoQZarqG.cjs} +2 -2
- package/dist/{eas-BhTOdQrE.cjs.map → eas-BoQZarqG.cjs.map} +1 -1
- package/dist/{eas-iYyg7Xjy.mjs → eas-DJ72jimW.mjs} +2 -2
- package/dist/{eas-iYyg7Xjy.mjs.map → eas-DJ72jimW.mjs.map} +1 -1
- package/dist/{encryption-yROMpM67.cjs → encryption-DV_CquCK.cjs} +2 -2
- package/dist/{encryption-yROMpM67.cjs.map → encryption-DV_CquCK.cjs.map} +1 -1
- package/dist/{encryption-hgmnMZw0.mjs → encryption-kkNdsOGW.mjs} +2 -2
- package/dist/{encryption-hgmnMZw0.mjs.map → encryption-kkNdsOGW.mjs.map} +1 -1
- package/dist/{engine-B4whsrrE.mjs → engine-Cd3bKbRY.mjs} +8 -8
- package/dist/{engine-B4whsrrE.mjs.map → engine-Cd3bKbRY.mjs.map} +1 -1
- package/dist/{engine-D0XYdIiE.cjs → engine-CmXDgdiq.cjs} +8 -8
- package/dist/{engine-D0XYdIiE.cjs.map → engine-CmXDgdiq.cjs.map} +1 -1
- package/dist/{github-D1-_OnGL.cjs → github-C704AJDB.cjs} +6 -6
- package/dist/{github-D1-_OnGL.cjs.map → github-C704AJDB.cjs.map} +1 -1
- package/dist/{github-CBkZF4PS.mjs → github-CroZXJ4R.mjs} +6 -6
- package/dist/{github-CBkZF4PS.mjs.map → github-CroZXJ4R.mjs.map} +1 -1
- package/dist/{googlePlay-s9dGfrrb.cjs → googlePlay-BQE1HTmv.cjs} +4 -4
- package/dist/{googlePlay-s9dGfrrb.cjs.map → googlePlay-BQE1HTmv.cjs.map} +1 -1
- package/dist/{googlePlay-Bwv8TVi8.mjs → googlePlay-Bzxp4zQ3.mjs} +4 -4
- package/dist/{googlePlay-Bwv8TVi8.mjs.map → googlePlay-Bzxp4zQ3.mjs.map} +1 -1
- package/dist/index.cjs +61 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +61 -61
- package/dist/index.mjs.map +1 -1
- package/dist/{local-JOnTFJA5.mjs → local-BYjJ4cw5.mjs} +2 -2
- package/dist/{local-JOnTFJA5.mjs.map → local-BYjJ4cw5.mjs.map} +1 -1
- package/dist/{local-CFnHQgWC.cjs → local-CxTYQed-.cjs} +2 -2
- package/dist/{local-CFnHQgWC.cjs.map → local-CxTYQed-.cjs.map} +1 -1
- package/dist/{migrate-BtnpQocG.mjs → migrate-CsJrcPmW.mjs} +2 -2
- package/dist/{migrate-BtnpQocG.mjs.map → migrate-CsJrcPmW.mjs.map} +1 -1
- package/dist/{migrate-CGXrmZyV.cjs → migrate-Cv1Wj_hS.cjs} +4 -4
- package/dist/{migrate-CGXrmZyV.cjs.map → migrate-Cv1Wj_hS.cjs.map} +1 -1
- package/dist/{migrate-CxWXW-Lw.cjs → migrate-LiP3lxDP.cjs} +2 -2
- package/dist/{migrate-CxWXW-Lw.cjs.map → migrate-LiP3lxDP.cjs.map} +1 -1
- package/dist/{migrate-fLIgSpPB.mjs → migrate-X9wfAInp.mjs} +4 -4
- package/dist/{migrate-fLIgSpPB.mjs.map → migrate-X9wfAInp.mjs.map} +1 -1
- package/dist/{notes-ChYPaRLu.cjs → notes-C1yLF-KM.cjs} +2 -2
- package/dist/{notes-ChYPaRLu.cjs.map → notes-C1yLF-KM.cjs.map} +1 -1
- package/dist/{notes-LATU2vLI.mjs → notes-CbRe1mqV.mjs} +2 -2
- package/dist/{notes-LATU2vLI.mjs.map → notes-CbRe1mqV.mjs.map} +1 -1
- package/dist/{projectBucket-BIeh2HTj.cjs → projectBucket-Bk2KbOkD.cjs} +2 -2
- package/dist/{projectBucket-BIeh2HTj.cjs.map → projectBucket-Bk2KbOkD.cjs.map} +1 -1
- package/dist/{projectBucket-D_4zb_oh.mjs → projectBucket-Diqy2tAk.mjs} +2 -2
- package/dist/{projectBucket-D_4zb_oh.mjs.map → projectBucket-Diqy2tAk.mjs.map} +1 -1
- package/dist/{publish-Dc-1GQp8.cjs → publish-BNNQepSY.cjs} +2 -2
- package/dist/{publish-Dc-1GQp8.cjs.map → publish-BNNQepSY.cjs.map} +1 -1
- package/dist/{publish-DhzRYhVZ.mjs → publish-Cs09Fa7P.mjs} +2 -2
- package/dist/{publish-DhzRYhVZ.mjs.map → publish-Cs09Fa7P.mjs.map} +1 -1
- package/dist/{resolve-CJvM2bUx.mjs → resolve-BW8-rZMG.mjs} +4 -4
- package/dist/{resolve-CJvM2bUx.mjs.map → resolve-BW8-rZMG.mjs.map} +1 -1
- package/dist/{resolve-DyUXmA0z.cjs → resolve-L5P6IrY3.cjs} +4 -4
- package/dist/{resolve-DyUXmA0z.cjs.map → resolve-L5P6IrY3.cjs.map} +1 -1
- package/dist/{rollback-BO1asWkd.mjs → rollback-CIYpO8Zx.mjs} +5 -5
- package/dist/{rollback-BO1asWkd.mjs.map → rollback-CIYpO8Zx.mjs.map} +1 -1
- package/dist/{rollback-Op8Tc5N-.cjs → rollback-CIfOaM8X.cjs} +5 -5
- package/dist/{rollback-Op8Tc5N-.cjs.map → rollback-CIfOaM8X.cjs.map} +1 -1
- package/dist/{s3-BbtwHSod.mjs → s3-BdC1c-oO.mjs} +2 -2
- package/dist/{s3-BbtwHSod.mjs.map → s3-BdC1c-oO.mjs.map} +1 -1
- package/dist/{s3-CwacPd8J.cjs → s3-D623r4M6.cjs} +2 -2
- package/dist/{s3-CwacPd8J.cjs.map → s3-D623r4M6.cjs.map} +1 -1
- package/dist/{serverSetup-BFdzPTIT.cjs → serverSetup-Cb6JQ7ak.cjs} +5 -5
- package/dist/{serverSetup-BFdzPTIT.cjs.map → serverSetup-Cb6JQ7ak.cjs.map} +1 -1
- package/dist/{serverSetup-CSxaZ7ha.mjs → serverSetup-DH_PUrdN.mjs} +5 -5
- package/dist/{serverSetup-CSxaZ7ha.mjs.map → serverSetup-DH_PUrdN.mjs.map} +1 -1
- package/dist/{sniffer-D3gH7aJT.cjs → sniffer-5cFiLD6z.cjs} +6 -6
- package/dist/{sniffer-D3gH7aJT.cjs.map → sniffer-5cFiLD6z.cjs.map} +1 -1
- package/dist/{sniffer-CwxpsSez.mjs → sniffer-Bm-W3u1a.mjs} +6 -6
- package/dist/{sniffer-CwxpsSez.mjs.map → sniffer-Bm-W3u1a.mjs.map} +1 -1
- package/dist/{snsSubscriptions-n3sjbrRM.mjs → snsSubscriptions-DO3vC1GH.mjs} +3 -3
- package/dist/{snsSubscriptions-n3sjbrRM.mjs.map → snsSubscriptions-DO3vC1GH.mjs.map} +1 -1
- package/dist/{snsSubscriptions-B8tGxND5.cjs → snsSubscriptions-Dw3bd8dx.cjs} +3 -3
- package/dist/{snsSubscriptions-B8tGxND5.cjs.map → snsSubscriptions-Dw3bd8dx.cjs.map} +1 -1
- package/dist/{sst-Cjocp7gi.cjs → sst-CKlqKTem.cjs} +4 -4
- package/dist/{sst-Cjocp7gi.cjs.map → sst-CKlqKTem.cjs.map} +1 -1
- package/dist/{sst-DeF0BfDA.mjs → sst-OLcmeSkm.mjs} +4 -4
- package/dist/{sst-DeF0BfDA.mjs.map → sst-OLcmeSkm.mjs.map} +1 -1
- package/dist/{stack-CyoRqyPt.mjs → stack-B8_fOPGr.mjs} +6 -6
- package/dist/{stack-CyoRqyPt.mjs.map → stack-B8_fOPGr.mjs.map} +1 -1
- package/dist/{stack-Dr2FSxGm.cjs → stack-DqgW5sRK.cjs} +6 -6
- package/dist/{stack-Dr2FSxGm.cjs.map → stack-DqgW5sRK.cjs.map} +1 -1
- package/dist/{stage-TAx0Gcq8.mjs → stage-96X0rmps.mjs} +5 -5
- package/dist/{stage-TAx0Gcq8.mjs.map → stage-96X0rmps.mjs.map} +1 -1
- package/dist/{stage-aTBLKonw.cjs → stage-9zaZLwpP.cjs} +5 -5
- package/dist/{stage-aTBLKonw.cjs.map → stage-9zaZLwpP.cjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-DPf137EJ.cjs → terminal-BrPWJ-AN.cjs} +2 -2
- package/dist/{terminal-DPf137EJ.cjs.map → terminal-BrPWJ-AN.cjs.map} +1 -1
- package/dist/{terminal-Bk4PjXWY.mjs → terminal-Ci8NTLD0.mjs} +2 -2
- package/dist/{terminal-Bk4PjXWY.mjs.map → terminal-Ci8NTLD0.mjs.map} +1 -1
- package/package.json +16 -16
- package/dist/compose-AO8u4mBI.cjs.map +0 -1
- package/dist/compose-C23RpAaF.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
2
|
-
const require_compose = require("./compose-
|
|
3
|
-
const require_apps = require("./apps-
|
|
4
|
-
const require_compose$1 = require("./compose-
|
|
5
|
-
const require_stack = require("./stack-
|
|
6
|
-
const require_stage = require("./stage-
|
|
2
|
+
const require_compose = require("./compose-CdVh0nqk.cjs");
|
|
3
|
+
const require_apps = require("./apps-_6kKM67e.cjs");
|
|
4
|
+
const require_compose$1 = require("./compose-BzFV_0Q9.cjs");
|
|
5
|
+
const require_stack = require("./stack-DqgW5sRK.cjs");
|
|
6
|
+
const require_stage = require("./stage-9zaZLwpP.cjs");
|
|
7
7
|
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
8
8
|
//#region src/exec/dbTunnel.ts
|
|
9
9
|
/**
|
|
@@ -151,4 +151,4 @@ async function dbTunnel(options, deps = defaultDbTunnelDeps) {
|
|
|
151
151
|
//#endregion
|
|
152
152
|
exports.dbTunnel = dbTunnel;
|
|
153
153
|
|
|
154
|
-
//# sourceMappingURL=dbTunnel-
|
|
154
|
+
//# sourceMappingURL=dbTunnel-BX6c-a7j.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbTunnel-Bve0zBqT.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,cAAw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AAO,MAAM,MAAM;CAE9B,MAAM,YAAY,MAAM,KAAK,OAAO,UACnC,EAAE,MAAMC,gBAAAA,WAAW,MAAM,EAAE,GAC3B,MAAM,SACN,YACAT,cAAAA,kBAAkB,QACnB;CACA,IAAI,cAAc,KAAA,GACjB,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"}
|
|
1
|
+
{"version":3,"file":"dbTunnel-BX6c-a7j.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,cA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;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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as GkmError } from "./errors-C9uIyIDt.mjs";
|
|
2
|
-
import { p as dockerHost } from "./compose-
|
|
3
|
-
import { Ct as isDatabase, St as envFor } from "./apps-
|
|
4
|
-
import { ut as primaryPortKey } from "./compose-
|
|
5
|
-
import { i as LOOPBACK_SERVICES } from "./stack-
|
|
6
|
-
import { i as stageServer, n as defaultStageExecDeps, r as loadStage, t as ExecNotConfirmed } from "./stage-
|
|
2
|
+
import { p as dockerHost } from "./compose-TWiIQaA5.mjs";
|
|
3
|
+
import { Ct as isDatabase, St as envFor } from "./apps-BlwS8CjS.mjs";
|
|
4
|
+
import { ut as primaryPortKey } from "./compose-afWlhnJ2.mjs";
|
|
5
|
+
import { i as LOOPBACK_SERVICES } from "./stack-B8_fOPGr.mjs";
|
|
6
|
+
import { i as stageServer, n as defaultStageExecDeps, r as loadStage, t as ExecNotConfirmed } from "./stage-96X0rmps.mjs";
|
|
7
7
|
import { providedKeyFor } from "@geekmidas/manifest";
|
|
8
8
|
//#region src/exec/dbTunnel.ts
|
|
9
9
|
/**
|
|
@@ -151,4 +151,4 @@ async function dbTunnel(options, deps = defaultDbTunnelDeps) {
|
|
|
151
151
|
//#endregion
|
|
152
152
|
export { dbTunnel };
|
|
153
153
|
|
|
154
|
-
//# sourceMappingURL=dbTunnel-
|
|
154
|
+
//# sourceMappingURL=dbTunnel-C7nukvfw.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbTunnel-CnubkLBa.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,OAAwB;EACnC,MACC,IAAI,MAAM,6GAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwC,SAAS;CAEtC;CACA;CACA;CAHV,YACC,OACA,WACA,WACC;EACD,MACC,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E,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"}
|
|
1
|
+
{"version":3,"file":"dbTunnel-C7nukvfw.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,OAAwB;EACnC,MACC,IAAI,MAAM,6GAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwC,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,cAA0C,SAAS;CAExC;CACA;CAFV,YACC,OACA,SACC;EACD,MACC,cAAc,QAAQ,sBAAsB,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,MAAM,CAAC,CAAC,CAAC;EACzD,CAAC,QAAQ,mBAAmB,OAAO,QAAQ,CAAC;EAC5C,CAAC,YAAY,mBAAmB,OAAO,QAAQ,CAAC;CACjD;AACD;;;;;;;;;AAUA,SAAgB,YACf,OACA,MACA,WACe;CACf,MAA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AAM,WAAW,IAAI,MAAM;EAC3B,IAAI,CAAE,MAAM,KAAK,QAAQ,QAAQ,GAAI,MAAM,IAAI,iBAAiB,KAAK;CACtE;CAEA,MAAM,SAAS,YAAY,QAAQ,OAAO;CAC1C,MAAM,KAAK,OAAO,MAAM,MAAM;CAE9B,MAAM,YAAY,MAAM,KAAK,OAAO,UACnC,EAAE,MAAM,WAAW,MAAM,EAAE,GAC3B,MAAM,SACN,YACA,kBAAkB,QACnB;CACA,IAAI,cAAc,KAAA,GACjB,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"}
|
package/dist/deploy/public.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_errors = require("../errors-D1x8duqI.cjs");
|
|
3
|
-
const require_dns = require("../dns-
|
|
3
|
+
const require_dns = require("../dns-DHyogtOl.cjs");
|
|
4
4
|
const require_workspace = require("../workspace-wTLnc1Ef.cjs");
|
|
5
|
-
const require_apps = require("../apps-
|
|
5
|
+
const require_apps = require("../apps-_6kKM67e.cjs");
|
|
6
6
|
const require_define = require("../define-zKgLY65H.cjs");
|
|
7
7
|
const require_discover = require("../discover-OXczlq08.cjs");
|
|
8
8
|
const require_config = require("../config.cjs");
|
|
9
|
-
const require_resolve = require("../resolve-
|
|
10
|
-
const require_notes = require("../notes-
|
|
11
|
-
const require_local = require("../local-
|
|
12
|
-
const require_sniffer = require("../sniffer-
|
|
13
|
-
const require_deploy = require("../deploy-
|
|
9
|
+
const require_resolve = require("../resolve-L5P6IrY3.cjs");
|
|
10
|
+
const require_notes = require("../notes-C1yLF-KM.cjs");
|
|
11
|
+
const require_local = require("../local-CxTYQed-.cjs");
|
|
12
|
+
const require_sniffer = require("../sniffer-5cFiLD6z.cjs");
|
|
13
|
+
const require_deploy = require("../deploy-CsA10pJq.cjs");
|
|
14
14
|
const require_seeds = require("../seeds-Bc3niNVb.cjs");
|
|
15
|
-
const require_engine = require("../engine-
|
|
16
|
-
const require_rollback = require("../rollback-
|
|
15
|
+
const require_engine = require("../engine-CmXDgdiq.cjs");
|
|
16
|
+
const require_rollback = require("../rollback-CIfOaM8X.cjs");
|
|
17
17
|
const require_provider = require("../provider-DLhgo-mB.cjs");
|
|
18
|
-
const require_sst = require("../sst-
|
|
18
|
+
const require_sst = require("../sst-CKlqKTem.cjs");
|
|
19
19
|
let node_path = require("node:path");
|
|
20
20
|
let node_fs = require("node:fs");
|
|
21
21
|
//#region src/sandbox/install.ts
|
package/dist/deploy/public.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { t as GkmError } from "../errors-C9uIyIDt.mjs";
|
|
2
|
-
import { _t as gkmHome, c as chainCredentials, gt as GKM_HOME_ENV, l as storedCredentials, nt as CommandTimedOut, q as deployIdentity, s as MissingCredential, tt as CommandFailed } from "../dns-
|
|
2
|
+
import { _t as gkmHome, c as chainCredentials, gt as GKM_HOME_ENV, l as storedCredentials, nt as CommandTimedOut, q as deployIdentity, s as MissingCredential, tt as CommandFailed } from "../dns-Clnn8_Da.mjs";
|
|
3
3
|
import { V as UnknownStageProvider, wt as ProvisionedBucketUnreachable } from "../workspace-DJjhfAGf.mjs";
|
|
4
|
-
import { I as detectPackageManager } from "../apps-
|
|
4
|
+
import { I as detectPackageManager } from "../apps-BlwS8CjS.mjs";
|
|
5
5
|
import { a as UnknownDeployTarget, i as DeployTargetNotYetSupported } from "../define-BfrNaY82.mjs";
|
|
6
6
|
import { d as SECRETS_DIR_ENV, f as SandboxCwdEscape, g as confineCwd, n as ConstructsNotSerializable, p as SecretNameInvalid, s as SandboxWorkerFailed, t as ConstructDiscoveryFailed } from "../discover-Dfmn6HQ7.mjs";
|
|
7
7
|
import { ConfigLoadFailed, ConfigObjectNotSerializable } from "../config.mjs";
|
|
8
|
-
import { i as TargetRuntimeMismatch, l as TargetPackageNotFound, n as TargetEntryInvalid, r as TargetPackageInvalid, s as TargetRuntimeUndeclared, t as InvalidTargetOptions } from "../resolve-
|
|
9
|
-
import { c as DevServicesNeedServerTarget, l as ExternalServicesNotConfigured, o as AllowDevServicesTakesNoValue, s as DEV_SERVICES, t as StageProviderDisabled } from "../notes-
|
|
10
|
-
import { n as SANDBOX_ENV_ALLOWLIST, r as allowlistedEnv, t as LocalSandbox } from "../local-
|
|
11
|
-
import { a as DeploymentTimedOut, f as StateLocked, g as StateVersionConflict, i as DeploymentFailed, u as LocalStateInCi } from "../sniffer-
|
|
12
|
-
import { a as UnknownDeployApps, i as TargetBuildsNothing, n as NoDeployableApps, r as RollbackFailed, t as deploy } from "../deploy-
|
|
8
|
+
import { i as TargetRuntimeMismatch, l as TargetPackageNotFound, n as TargetEntryInvalid, r as TargetPackageInvalid, s as TargetRuntimeUndeclared, t as InvalidTargetOptions } from "../resolve-BW8-rZMG.mjs";
|
|
9
|
+
import { c as DevServicesNeedServerTarget, l as ExternalServicesNotConfigured, o as AllowDevServicesTakesNoValue, s as DEV_SERVICES, t as StageProviderDisabled } from "../notes-CbRe1mqV.mjs";
|
|
10
|
+
import { n as SANDBOX_ENV_ALLOWLIST, r as allowlistedEnv, t as LocalSandbox } from "../local-BYjJ4cw5.mjs";
|
|
11
|
+
import { a as DeploymentTimedOut, f as StateLocked, g as StateVersionConflict, i as DeploymentFailed, u as LocalStateInCi } from "../sniffer-Bm-W3u1a.mjs";
|
|
12
|
+
import { a as UnknownDeployApps, i as TargetBuildsNothing, n as NoDeployableApps, r as RollbackFailed, t as deploy } from "../deploy-qacf9be0.mjs";
|
|
13
13
|
import { t as DeploySeedsFailed } from "../seeds-Ccn0Ru2T.mjs";
|
|
14
|
-
import { _ as RegistryNotConfigured, g as RegistryAmbiguous, h as HealthCheckTimedOut, m as DeployMigrationsFailed, n as FrontendDeployFailed, r as MissingEnvVars, t as BackendDeployFailed, v as RegistryNotFound, y as ProjectNotOwned } from "../engine-
|
|
15
|
-
import { i as rollbackStage, n as RollbackNeedsApp, r as StageNeverDeployed, t as NothingToRollBack } from "../rollback-
|
|
14
|
+
import { _ as RegistryNotConfigured, g as RegistryAmbiguous, h as HealthCheckTimedOut, m as DeployMigrationsFailed, n as FrontendDeployFailed, r as MissingEnvVars, t as BackendDeployFailed, v as RegistryNotFound, y as ProjectNotOwned } from "../engine-Cd3bKbRY.mjs";
|
|
15
|
+
import { i as rollbackStage, n as RollbackNeedsApp, r as StageNeverDeployed, t as NothingToRollBack } from "../rollback-CIYpO8Zx.mjs";
|
|
16
16
|
import { t as ProviderRemoved } from "../provider-BvjDbsTR.mjs";
|
|
17
|
-
import { i as SurfacesUnhealthy, r as SstOutputsUnreadable, t as SstConfigNotFound } from "../sst-
|
|
17
|
+
import { i as SurfacesUnhealthy, r as SstOutputsUnreadable, t as SstConfigNotFound } from "../sst-OLcmeSkm.mjs";
|
|
18
18
|
import { join, resolve } from "node:path";
|
|
19
19
|
import { existsSync } from "node:fs";
|
|
20
20
|
//#region src/sandbox/install.ts
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
2
|
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
3
|
-
const require_dns = require("./dns-
|
|
3
|
+
const require_dns = require("./dns-DHyogtOl.cjs");
|
|
4
4
|
const require_workspace = require("./workspace-wTLnc1Ef.cjs");
|
|
5
|
-
const require_apps = require("./apps-
|
|
5
|
+
const require_apps = require("./apps-_6kKM67e.cjs");
|
|
6
6
|
const require_define = require("./define-zKgLY65H.cjs");
|
|
7
|
-
const require_compose = require("./compose-
|
|
7
|
+
const require_compose = require("./compose-BzFV_0Q9.cjs");
|
|
8
8
|
const require_SubscriberGenerator = require("./SubscriberGenerator-JhwVlWBS.cjs");
|
|
9
9
|
const require_discover = require("./discover-OXczlq08.cjs");
|
|
10
10
|
const require_config = require("./config.cjs");
|
|
11
|
-
const require_resolve = require("./resolve-
|
|
12
|
-
const require_notes = require("./notes-
|
|
13
|
-
const require_stack = require("./stack-
|
|
14
|
-
const require_local = require("./local-
|
|
15
|
-
const require_sniffer = require("./sniffer-
|
|
16
|
-
const require_snsSubscriptions = require("./snsSubscriptions-
|
|
11
|
+
const require_resolve = require("./resolve-L5P6IrY3.cjs");
|
|
12
|
+
const require_notes = require("./notes-C1yLF-KM.cjs");
|
|
13
|
+
const require_stack = require("./stack-DqgW5sRK.cjs");
|
|
14
|
+
const require_local = require("./local-CxTYQed-.cjs");
|
|
15
|
+
const require_sniffer = require("./sniffer-5cFiLD6z.cjs");
|
|
16
|
+
const require_snsSubscriptions = require("./snsSubscriptions-Dw3bd8dx.cjs");
|
|
17
17
|
const require_iam = require("./iam-WIoKnLBp.cjs");
|
|
18
|
-
const require_projectBucket = require("./projectBucket-
|
|
18
|
+
const require_projectBucket = require("./projectBucket-Bk2KbOkD.cjs");
|
|
19
19
|
const require_seeds = require("./seeds-Bc3niNVb.cjs");
|
|
20
20
|
const require_credentialSchemas = require("./credentialSchemas-DjK6xKMk.cjs");
|
|
21
21
|
let node_path = require("node:path");
|
|
@@ -3891,4 +3891,4 @@ Object.defineProperty(exports, "deploy", {
|
|
|
3891
3891
|
}
|
|
3892
3892
|
});
|
|
3893
3893
|
|
|
3894
|
-
//# sourceMappingURL=deploy-
|
|
3894
|
+
//# sourceMappingURL=deploy-CsA10pJq.cjs.map
|