@catladder/cli 0.0.0-main-ddb8b249 → 0.0.0-main-eb79b9b1

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.
@@ -3015,12 +3015,15 @@ const getEnvConfig = (config, componentName, env) => {
3015
3015
  return defaultConfig;
3016
3016
  }
3017
3017
  /**
3018
- * env config is merged with default. Arrays are not merged.
3018
+ * env config is merged with default. Arrays are not merged.
3019
3019
  * you can customize this by providing a function that takes the default value as argument
3020
3020
  */
3021
- return (0, lodash_1.mergeWith)({}, defaultConfig, envCustomizations, (defaultValue, customValue) => {
3021
+ return (0, lodash_1.mergeWith)(
3022
+ // mergeWith unfortunatly mutates the first object, so we need to clone it.
3023
+ // Passing empty object also doesn't work for us, because that will mess with the customizer function (second argument isn't nessecary the customized value)
3024
+ (0, lodash_1.cloneDeep)(defaultConfig), envCustomizations, (defaultValue, customValue, key, obj, source) => {
3022
3025
  // check if custom value is a function (and default is not),
3023
- // we currently don't have config options that are functions, but we might in the future
3026
+ // we currently don't have config options, that are functions, but we might in the future (customJobs is an exception)
3024
3027
  if (typeof customValue === "function" &&
3025
3028
  typeof defaultValue !== "function") {
3026
3029
  return customValue(defaultValue);
@@ -5516,7 +5519,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
5516
5519
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
5517
5520
  };
5518
5521
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5519
- exports.isOfDeployType = void 0;
5522
+ exports.getDeployConfigType = exports.isOfDeployType = void 0;
5520
5523
  __exportStar(__nccwpck_require__(461), exports);
5521
5524
  __exportStar(__nccwpck_require__(6938), exports);
5522
5525
  __exportStar(__nccwpck_require__(8189), exports);
@@ -5525,6 +5528,12 @@ const isOfDeployType = (t, ...types) => {
5525
5528
  return t && types.includes(t.type) ? true : false;
5526
5529
  };
5527
5530
  exports.isOfDeployType = isOfDeployType;
5531
+ const getDeployConfigType = (t) => {
5532
+ if (!t)
5533
+ return undefined;
5534
+ return t.type;
5535
+ };
5536
+ exports.getDeployConfigType = getDeployConfigType;
5528
5537
  //# sourceMappingURL=index.js.map
5529
5538
 
5530
5539
  /***/ }),
@@ -6706,6 +6715,7 @@ __exportStar(__nccwpck_require__(688), exports);
6706
6715
  __exportStar(__nccwpck_require__(1724), exports);
6707
6716
  __exportStar(__nccwpck_require__(8207), exports);
6708
6717
  __exportStar(__nccwpck_require__(2074), exports);
6718
+ __exportStar(__nccwpck_require__(7432), exports);
6709
6719
  //# sourceMappingURL=index.js.map
6710
6720
 
6711
6721
  /***/ }),
@@ -982,61 +982,30 @@ exports["default"] = async (vorpal) => vorpal
982
982
  /***/ }),
983
983
 
984
984
  /***/ 102:
985
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
985
+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
986
986
 
987
987
  "use strict";
988
988
 
989
+ var __importDefault = (this && this.__importDefault) || function (mod) {
990
+ return (mod && mod.__esModule) ? mod : { "default": mod };
991
+ };
989
992
  Object.defineProperty(exports, "__esModule", ({ value: true }));
990
993
  const pipeline_1 = __nccwpck_require__(10603);
994
+ const clipboardy_1 = __importDefault(__nccwpck_require__(89881));
991
995
  const getProjectConfig_1 = __nccwpck_require__(12145);
992
996
  const autocompletions_1 = __nccwpck_require__(39855);
993
997
  const startProxy_1 = __nccwpck_require__(90742);
994
- exports["default"] = async (vorpal) => vorpal
995
- .command("project-cloud-sql-proxy <envComponent>", "proxy to cloud sql db")
996
- .autocomplete(await (0, autocompletions_1.envAndComponents)())
997
- .action(async function ({ envComponent }) {
998
- var _a, _b;
999
- const { env, componentName } = (0, getProjectConfig_1.parseChoice)(envComponent);
1000
- if (!componentName) {
1001
- this.log("need componentName");
1002
- return;
1003
- }
1004
- const context = await (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName);
1005
- let proxyInfo;
1006
- if (env === "review") {
1007
- vorpal.log("⚠️ connection string does not include mr information on review environments");
1008
- }
998
+ const log_1 = __nccwpck_require__(66921);
999
+ const getProxyInfo = (context) => {
1000
+ var _a, _b, _c, _d;
1009
1001
  if ((0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
1010
- proxyInfo = await getProxyInfoForKubernetes(this, context);
1002
+ return getProxyInfoForKubernetes(this, context);
1011
1003
  }
1012
1004
  else if ((0, pipeline_1.isOfDeployType)((_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config, "google-cloudrun")) {
1013
- proxyInfo = await getProxyInfoForCloudRun(this, context);
1014
- }
1015
- else {
1016
- throw new Error("unsupported environment");
1005
+ return getProxyInfoForCloudRun(this, context);
1017
1006
  }
1018
- // skynet-164509:europe-west6:pvl-cyclomania-review=tcp:5432
1019
- const { DB_PASSWORD, DB_NAME, DB_USER, instanceName } = proxyInfo;
1020
- const { localPort } = await this.prompt({
1021
- type: "number",
1022
- name: "localPort",
1023
- default: "54320",
1024
- message: "Local port: ",
1025
- });
1026
- this.log("");
1027
- this.log(`postgres-PW: ${DB_PASSWORD}`);
1028
- this.log("");
1029
- this.log("connection strings:");
1030
- this.log("");
1031
- this.log(`DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${localPort}/${DB_NAME}?schema=public`);
1032
- this.log("");
1033
- this.log(`DATABASE_JDBC_URL=jdbc:postgresql://localhost:${localPort}/${DB_NAME}?schema=public&user=${DB_USER}&password=${DB_PASSWORD}`);
1034
- this.log("");
1035
- await (0, startProxy_1.startCloudSqlProxyInCurrentShell)({
1036
- instanceName,
1037
- localPort,
1038
- });
1039
- });
1007
+ throw new Error(`unsupported environment: ${(_d = (_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.type}`);
1008
+ };
1040
1009
  const getProxyInfoForKubernetes = async (vorpal, context) => {
1041
1010
  var _a, _b;
1042
1011
  if (!(0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
@@ -1056,22 +1025,86 @@ const getProxyInfoForKubernetes = async (vorpal, context) => {
1056
1025
  };
1057
1026
  };
1058
1027
  const getProxyInfoForCloudRun = async (vorpal, context) => {
1059
- var _a, _b, _c, _d, _e;
1028
+ var _a, _b, _c, _d, _e, _f;
1060
1029
  if (!(0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "google-cloudrun") ||
1061
1030
  !((_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.cloudSql)) {
1062
- throw new Error("unsupported");
1031
+ const deployType = (0, pipeline_1.getDeployConfigType)((_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config);
1032
+ const errorMessage = deployType === "google-cloudrun"
1033
+ ? `DeployConfig is missing the cloudSql property`
1034
+ : `Unsupported DeployConfig type: ${deployType}`;
1035
+ (0, log_1.logError)(vorpal, errorMessage);
1036
+ throw new Error(errorMessage);
1063
1037
  }
1064
1038
  const envVars = await (0, getProjectConfig_1.getEnvVarsResolved)(vorpal, context.env, context.name);
1065
- const DB_PASSWORD = (_c = envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD) === null || _c === void 0 ? void 0 : _c.toString();
1066
- const DB_USER = (_d = envVars === null || envVars === void 0 ? void 0 : envVars.DB_USER) === null || _d === void 0 ? void 0 : _d.toString();
1067
- const DB_NAME = context.environment.envVars.DB_NAME.toString();
1068
1039
  return {
1069
- instanceName: (_e = context.deploy) === null || _e === void 0 ? void 0 : _e.config.cloudSql.instanceConnectionName,
1070
- DB_PASSWORD,
1071
- DB_NAME,
1072
- DB_USER,
1040
+ instanceName: (_d = context.deploy) === null || _d === void 0 ? void 0 : _d.config.cloudSql.instanceConnectionName,
1041
+ DB_PASSWORD: (_e = envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD) === null || _e === void 0 ? void 0 : _e.toString(),
1042
+ DB_NAME: context.environment.envVars.DB_NAME.toString(),
1043
+ DB_USER: (_f = envVars === null || envVars === void 0 ? void 0 : envVars.DB_USER) === null || _f === void 0 ? void 0 : _f.toString(),
1073
1044
  };
1074
1045
  };
1046
+ const getDbUrl = ({ DB_PASSWORD, DB_NAME, DB_USER }, localPort, additional = "") => `DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${localPort}/${DB_NAME}${additional}"`;
1047
+ const getJdbcUrl = ({ DB_PASSWORD, DB_NAME, DB_USER }, localPort) => `DATABASE_JDBC_URL="jdbc:postgresql://localhost:${localPort}/${DB_NAME}?schema=public&user=${DB_USER}&password=${DB_PASSWORD}"`;
1048
+ exports["default"] = async (vorpal) => vorpal
1049
+ .command("project-cloud-sql-proxy <envComponent>", "proxy to cloud sql db")
1050
+ .autocomplete(await (0, autocompletions_1.envAndComponents)())
1051
+ .action(async function ({ envComponent }) {
1052
+ const { env, componentName } = (0, getProjectConfig_1.parseChoice)(envComponent);
1053
+ if (!componentName) {
1054
+ (0, log_1.logWarning)(this, "need componentName");
1055
+ return;
1056
+ }
1057
+ const context = await (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName);
1058
+ if (env === "review") {
1059
+ (0, log_1.logWarning)(this, "connection string does not include mr information on review environments");
1060
+ }
1061
+ const { localPort } = await this.prompt({
1062
+ type: "number",
1063
+ name: "localPort",
1064
+ default: "54320",
1065
+ message: "Local port: ",
1066
+ });
1067
+ const proxyInfo = await getProxyInfo(context);
1068
+ /**
1069
+ * Env variables for libpq (e.g. psql client)
1070
+ * https://www.postgresql.org/docs/current/libpq-envars.html#LIBPQ-ENVARS
1071
+ */
1072
+ const psqlEnvVars = {
1073
+ PGPASSWORD: proxyInfo.DB_PASSWORD,
1074
+ PGUSER: proxyInfo.DB_USER,
1075
+ PGDATABASE: proxyInfo.DB_NAME,
1076
+ PGHOST: "localhost",
1077
+ PGPORT: localPort,
1078
+ };
1079
+ const lipbqEnvVarDeclarations = Object.entries(psqlEnvVars).map(([key, value]) => `${key}="${value}"`);
1080
+ const dbUrl = getDbUrl(proxyInfo, localPort);
1081
+ const jdbcUrl = getJdbcUrl(proxyInfo, localPort);
1082
+ clipboardy_1.default.writeSync([
1083
+ "",
1084
+ "## CloudSQL proxy connection .env variables",
1085
+ dbUrl,
1086
+ jdbcUrl,
1087
+ "## DATABASE_URL with schema=public parameter (e. g. Prisma requires this):",
1088
+ `# ${getDbUrl(proxyInfo, localPort, `?schema=public`)}`,
1089
+ "## Env variables for libpq (e.g. psql client https://www.postgresql.org/docs/current/libpq-envars.html#LIBPQ-ENVARS)",
1090
+ ...lipbqEnvVarDeclarations,
1091
+ "",
1092
+ ].join("\n"));
1093
+ (0, log_1.logLines)(this, null, "Connection strings env variables DATABASE_URL and those for the 'psql' client (copied to your clipboard for .env file):", dbUrl, jdbcUrl, ...lipbqEnvVarDeclarations, null, "DATABASE_URL with schema=public parameter (e. g. Prisma requires this):", getDbUrl(proxyInfo, localPort, `?schema=public`), null);
1094
+ try {
1095
+ await (0, startProxy_1.startCloudSqlProxyInCurrentShell)({
1096
+ instanceName: proxyInfo.instanceName,
1097
+ localPort,
1098
+ });
1099
+ }
1100
+ catch (error) {
1101
+ if (!(error instanceof Error))
1102
+ throw error;
1103
+ if (error.message !== startProxy_1.ERROR_NOT_INSTALLED)
1104
+ throw error;
1105
+ (0, log_1.logError)(this, error.message, null, "Please install the Cloud SQL Auth Proxy from:", `https://cloud.google.com/sql/docs/postgres/connect-auth-proxy#install`, null);
1106
+ }
1107
+ });
1075
1108
  //# sourceMappingURL=commandCloudSqlProxy.js.map
1076
1109
 
1077
1110
  /***/ }),
@@ -3528,17 +3561,71 @@ exports.upsertAllVariables = upsertAllVariables;
3528
3561
  "use strict";
3529
3562
 
3530
3563
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3531
- exports.logError = void 0;
3532
- const logError = (cmd, message, additionalMessage) => {
3533
- cmd.log("");
3534
- cmd.log(`[ERROR] 🙀 :${message}`);
3535
- cmd.log("");
3536
- if (additionalMessage) {
3537
- cmd.log(additionalMessage);
3538
- cmd.log("");
3564
+ exports.logWarning = exports.logError = exports.logLines = void 0;
3565
+ /**
3566
+ * Logs multiple lines using the log method of the provided {@link LoggerCmdInstance}.
3567
+ *
3568
+ * Line items that are `null` or `undefined` are logged as empty lines.
3569
+ *
3570
+ * @param cmd - The logger instance to use. If `null` or `undefined`, `console` will be used.
3571
+ *
3572
+ * @example
3573
+ * ```ts
3574
+ * logLines(cmd, "line 1", "line 2", null, "line 3");
3575
+ * logLines(cmd, ...linesArray); // arrays can be spread into the function
3576
+ * logLines(cmd, linesArray); // but it will flatten the plain array for convenience
3577
+ * ```
3578
+ */
3579
+ function logLines(cmd = console, ...lines) {
3580
+ for (const line of lines.flat()) {
3581
+ (cmd !== null && cmd !== void 0 ? cmd : console).log(`${line !== null && line !== void 0 ? line : ""}`);
3582
+ }
3583
+ }
3584
+ exports.logLines = logLines;
3585
+ /**
3586
+ * Logs an error message using the log method of the provided {@link LoggerCmdInstance}.
3587
+ *
3588
+ * Line items that are `null` or `undefined` are logged as empty lines.
3589
+ *
3590
+ * @example
3591
+ * ```ts
3592
+ * logError(cmd, "Message");
3593
+ * logError(cmd, "Message", "Additional message");
3594
+ * logError(cmd, "Message", "Additional message", "Another additional message line");
3595
+ * logError(cmd, "Message", ...additionalMessages); // arrays can be spread into the function
3596
+ * logError(cmd, "Message", additionalMessages); // but it will flatten the plain array for convenience
3597
+ * ```
3598
+ */
3599
+ const logError = (cmd = console, message, ...additionalMessages) => {
3600
+ logLines(cmd, "", `[ERROR] 🙀 :${message}`);
3601
+ if (additionalMessages === null || additionalMessages === void 0 ? void 0 : additionalMessages.length) {
3602
+ logLines(cmd, ...additionalMessages.flat());
3539
3603
  }
3604
+ logLines(cmd, "");
3540
3605
  };
3541
3606
  exports.logError = logError;
3607
+ /**
3608
+ * Logs a warning message using the log method of the provided {@link LoggerCmdInstance}.
3609
+ *
3610
+ * Line items that are `null` or `undefined` are logged as empty lines.
3611
+ *
3612
+ * @example
3613
+ * ```ts
3614
+ * logWarning(cmd, "Message");
3615
+ * logWarning(cmd, "Message", "Additional message");
3616
+ * logWarning(cmd, "Message", "Additional message", "Another additional message line");
3617
+ * logWarning(cmd, "Message", ...additionalMessages); // arrays can be spread into the function
3618
+ * logWarning(cmd, "Message", additionalMessages); // but it will flatten the plain array for convenience
3619
+ * ```
3620
+ */
3621
+ const logWarning = (cmd = console, message, ...additionalMessages) => {
3622
+ logLines(cmd, "", `[WARNING] ⚠️ : ${message}`);
3623
+ if (additionalMessages === null || additionalMessages === void 0 ? void 0 : additionalMessages.length) {
3624
+ logLines(cmd, ...additionalMessages.flat());
3625
+ }
3626
+ logLines(cmd, "");
3627
+ };
3628
+ exports.logWarning = logWarning;
3542
3629
  //# sourceMappingURL=log.js.map
3543
3630
 
3544
3631
  /***/ }),
@@ -5947,12 +6034,15 @@ const getEnvConfig = (config, componentName, env) => {
5947
6034
  return defaultConfig;
5948
6035
  }
5949
6036
  /**
5950
- * env config is merged with default. Arrays are not merged.
6037
+ * env config is merged with default. Arrays are not merged.
5951
6038
  * you can customize this by providing a function that takes the default value as argument
5952
6039
  */
5953
- return (0, lodash_1.mergeWith)({}, defaultConfig, envCustomizations, (defaultValue, customValue) => {
6040
+ return (0, lodash_1.mergeWith)(
6041
+ // mergeWith unfortunatly mutates the first object, so we need to clone it.
6042
+ // Passing empty object also doesn't work for us, because that will mess with the customizer function (second argument isn't nessecary the customized value)
6043
+ (0, lodash_1.cloneDeep)(defaultConfig), envCustomizations, (defaultValue, customValue, key, obj, source) => {
5954
6044
  // check if custom value is a function (and default is not),
5955
- // we currently don't have config options that are functions, but we might in the future
6045
+ // we currently don't have config options, that are functions, but we might in the future (customJobs is an exception)
5956
6046
  if (typeof customValue === "function" &&
5957
6047
  typeof defaultValue !== "function") {
5958
6048
  return customValue(defaultValue);
@@ -8448,7 +8538,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
8448
8538
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
8449
8539
  };
8450
8540
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8451
- exports.isOfDeployType = void 0;
8541
+ exports.getDeployConfigType = exports.isOfDeployType = void 0;
8452
8542
  __exportStar(__nccwpck_require__(30461), exports);
8453
8543
  __exportStar(__nccwpck_require__(66938), exports);
8454
8544
  __exportStar(__nccwpck_require__(60835), exports);
@@ -8457,6 +8547,12 @@ const isOfDeployType = (t, ...types) => {
8457
8547
  return t && types.includes(t.type) ? true : false;
8458
8548
  };
8459
8549
  exports.isOfDeployType = isOfDeployType;
8550
+ const getDeployConfigType = (t) => {
8551
+ if (!t)
8552
+ return undefined;
8553
+ return t.type;
8554
+ };
8555
+ exports.getDeployConfigType = getDeployConfigType;
8460
8556
  //# sourceMappingURL=index.js.map
8461
8557
 
8462
8558
  /***/ }),
@@ -9638,6 +9734,7 @@ __exportStar(__nccwpck_require__(30688), exports);
9638
9734
  __exportStar(__nccwpck_require__(61724), exports);
9639
9735
  __exportStar(__nccwpck_require__(28207), exports);
9640
9736
  __exportStar(__nccwpck_require__(32074), exports);
9737
+ __exportStar(__nccwpck_require__(17432), exports);
9641
9738
  //# sourceMappingURL=index.js.map
9642
9739
 
9643
9740
  /***/ }),
@@ -1,55 +1,24 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const pipeline_1 = require("../../../../../../pipeline/src/index.js");
7
+ const clipboardy_1 = __importDefault(require("clipboardy"));
4
8
  const getProjectConfig_1 = require("../../../../config/getProjectConfig");
5
9
  const autocompletions_1 = require("./utils/autocompletions");
6
10
  const startProxy_1 = require("../../../../gcloud/cloudSql/startProxy");
7
- exports.default = async (vorpal) => vorpal
8
- .command("project-cloud-sql-proxy <envComponent>", "proxy to cloud sql db")
9
- .autocomplete(await (0, autocompletions_1.envAndComponents)())
10
- .action(async function ({ envComponent }) {
11
- var _a, _b;
12
- const { env, componentName } = (0, getProjectConfig_1.parseChoice)(envComponent);
13
- if (!componentName) {
14
- this.log("need componentName");
15
- return;
16
- }
17
- const context = await (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName);
18
- let proxyInfo;
19
- if (env === "review") {
20
- vorpal.log("⚠️ connection string does not include mr information on review environments");
21
- }
11
+ const log_1 = require("../../../../utils/log");
12
+ const getProxyInfo = (context) => {
13
+ var _a, _b, _c, _d;
22
14
  if ((0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
23
- proxyInfo = await getProxyInfoForKubernetes(this, context);
15
+ return getProxyInfoForKubernetes(this, context);
24
16
  }
25
17
  else if ((0, pipeline_1.isOfDeployType)((_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config, "google-cloudrun")) {
26
- proxyInfo = await getProxyInfoForCloudRun(this, context);
27
- }
28
- else {
29
- throw new Error("unsupported environment");
18
+ return getProxyInfoForCloudRun(this, context);
30
19
  }
31
- // skynet-164509:europe-west6:pvl-cyclomania-review=tcp:5432
32
- const { DB_PASSWORD, DB_NAME, DB_USER, instanceName } = proxyInfo;
33
- const { localPort } = await this.prompt({
34
- type: "number",
35
- name: "localPort",
36
- default: "54320",
37
- message: "Local port: ",
38
- });
39
- this.log("");
40
- this.log(`postgres-PW: ${DB_PASSWORD}`);
41
- this.log("");
42
- this.log("connection strings:");
43
- this.log("");
44
- this.log(`DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${localPort}/${DB_NAME}?schema=public`);
45
- this.log("");
46
- this.log(`DATABASE_JDBC_URL=jdbc:postgresql://localhost:${localPort}/${DB_NAME}?schema=public&user=${DB_USER}&password=${DB_PASSWORD}`);
47
- this.log("");
48
- await (0, startProxy_1.startCloudSqlProxyInCurrentShell)({
49
- instanceName,
50
- localPort,
51
- });
52
- });
20
+ throw new Error(`unsupported environment: ${(_d = (_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.type}`);
21
+ };
53
22
  const getProxyInfoForKubernetes = async (vorpal, context) => {
54
23
  var _a, _b;
55
24
  if (!(0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
@@ -69,20 +38,84 @@ const getProxyInfoForKubernetes = async (vorpal, context) => {
69
38
  };
70
39
  };
71
40
  const getProxyInfoForCloudRun = async (vorpal, context) => {
72
- var _a, _b, _c, _d, _e;
41
+ var _a, _b, _c, _d, _e, _f;
73
42
  if (!(0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "google-cloudrun") ||
74
43
  !((_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.cloudSql)) {
75
- throw new Error("unsupported");
44
+ const deployType = (0, pipeline_1.getDeployConfigType)((_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config);
45
+ const errorMessage = deployType === "google-cloudrun"
46
+ ? `DeployConfig is missing the cloudSql property`
47
+ : `Unsupported DeployConfig type: ${deployType}`;
48
+ (0, log_1.logError)(vorpal, errorMessage);
49
+ throw new Error(errorMessage);
76
50
  }
77
51
  const envVars = await (0, getProjectConfig_1.getEnvVarsResolved)(vorpal, context.env, context.name);
78
- const DB_PASSWORD = (_c = envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD) === null || _c === void 0 ? void 0 : _c.toString();
79
- const DB_USER = (_d = envVars === null || envVars === void 0 ? void 0 : envVars.DB_USER) === null || _d === void 0 ? void 0 : _d.toString();
80
- const DB_NAME = context.environment.envVars.DB_NAME.toString();
81
52
  return {
82
- instanceName: (_e = context.deploy) === null || _e === void 0 ? void 0 : _e.config.cloudSql.instanceConnectionName,
83
- DB_PASSWORD,
84
- DB_NAME,
85
- DB_USER,
53
+ instanceName: (_d = context.deploy) === null || _d === void 0 ? void 0 : _d.config.cloudSql.instanceConnectionName,
54
+ DB_PASSWORD: (_e = envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD) === null || _e === void 0 ? void 0 : _e.toString(),
55
+ DB_NAME: context.environment.envVars.DB_NAME.toString(),
56
+ DB_USER: (_f = envVars === null || envVars === void 0 ? void 0 : envVars.DB_USER) === null || _f === void 0 ? void 0 : _f.toString(),
86
57
  };
87
58
  };
59
+ const getDbUrl = ({ DB_PASSWORD, DB_NAME, DB_USER }, localPort, additional = "") => `DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${localPort}/${DB_NAME}${additional}"`;
60
+ const getJdbcUrl = ({ DB_PASSWORD, DB_NAME, DB_USER }, localPort) => `DATABASE_JDBC_URL="jdbc:postgresql://localhost:${localPort}/${DB_NAME}?schema=public&user=${DB_USER}&password=${DB_PASSWORD}"`;
61
+ exports.default = async (vorpal) => vorpal
62
+ .command("project-cloud-sql-proxy <envComponent>", "proxy to cloud sql db")
63
+ .autocomplete(await (0, autocompletions_1.envAndComponents)())
64
+ .action(async function ({ envComponent }) {
65
+ const { env, componentName } = (0, getProjectConfig_1.parseChoice)(envComponent);
66
+ if (!componentName) {
67
+ (0, log_1.logWarning)(this, "need componentName");
68
+ return;
69
+ }
70
+ const context = await (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName);
71
+ if (env === "review") {
72
+ (0, log_1.logWarning)(this, "connection string does not include mr information on review environments");
73
+ }
74
+ const { localPort } = await this.prompt({
75
+ type: "number",
76
+ name: "localPort",
77
+ default: "54320",
78
+ message: "Local port: ",
79
+ });
80
+ const proxyInfo = await getProxyInfo(context);
81
+ /**
82
+ * Env variables for libpq (e.g. psql client)
83
+ * https://www.postgresql.org/docs/current/libpq-envars.html#LIBPQ-ENVARS
84
+ */
85
+ const psqlEnvVars = {
86
+ PGPASSWORD: proxyInfo.DB_PASSWORD,
87
+ PGUSER: proxyInfo.DB_USER,
88
+ PGDATABASE: proxyInfo.DB_NAME,
89
+ PGHOST: "localhost",
90
+ PGPORT: localPort,
91
+ };
92
+ const lipbqEnvVarDeclarations = Object.entries(psqlEnvVars).map(([key, value]) => `${key}="${value}"`);
93
+ const dbUrl = getDbUrl(proxyInfo, localPort);
94
+ const jdbcUrl = getJdbcUrl(proxyInfo, localPort);
95
+ clipboardy_1.default.writeSync([
96
+ "",
97
+ "## CloudSQL proxy connection .env variables",
98
+ dbUrl,
99
+ jdbcUrl,
100
+ "## DATABASE_URL with schema=public parameter (e. g. Prisma requires this):",
101
+ `# ${getDbUrl(proxyInfo, localPort, `?schema=public`)}`,
102
+ "## Env variables for libpq (e.g. psql client https://www.postgresql.org/docs/current/libpq-envars.html#LIBPQ-ENVARS)",
103
+ ...lipbqEnvVarDeclarations,
104
+ "",
105
+ ].join("\n"));
106
+ (0, log_1.logLines)(this, null, "Connection strings env variables DATABASE_URL and those for the 'psql' client (copied to your clipboard for .env file):", dbUrl, jdbcUrl, ...lipbqEnvVarDeclarations, null, "DATABASE_URL with schema=public parameter (e. g. Prisma requires this):", getDbUrl(proxyInfo, localPort, `?schema=public`), null);
107
+ try {
108
+ await (0, startProxy_1.startCloudSqlProxyInCurrentShell)({
109
+ instanceName: proxyInfo.instanceName,
110
+ localPort,
111
+ });
112
+ }
113
+ catch (error) {
114
+ if (!(error instanceof Error))
115
+ throw error;
116
+ if (error.message !== startProxy_1.ERROR_NOT_INSTALLED)
117
+ throw error;
118
+ (0, log_1.logError)(this, error.message, null, "Please install the Cloud SQL Auth Proxy from:", `https://cloud.google.com/sql/docs/postgres/connect-auth-proxy#install`, null);
119
+ }
120
+ });
88
121
  //# sourceMappingURL=commandCloudSqlProxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandCloudSqlProxy.js","sourceRoot":"","sources":["../../../../../../../src/apps/cli/commands/project/commandCloudSqlProxy.ts"],"names":[],"mappings":";;AACA,kDAG6B;AAG7B,0EAI6C;AAC7C,6DAA2D;AAC3D,uEAA0F;AAQ1F,kBAAe,KAAK,EAAE,MAAc,EAAE,EAAE,CACtC,MAAM;KACH,OAAO,CAAC,wCAAwC,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,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,IAAI,KAAK,CAAC,OAAO,KAAK,gCAAmB;YAAE,MAAM,KAAK,CAAC;QACvD,IAAA,cAAQ,EACN,IAAI,EACJ,KAAK,CAAC,OAAO,EACb,IAAI,EACJ,+CAA+C,EAC/C,uEAAuE,EACvE,IAAI,CACL,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1 +1,65 @@
1
- export declare const logError: (cmd: any, message: string, additionalMessage?: any) => void;
1
+ import type { CommandInstance } from "vorpal";
2
+ type AnyMessagesFn = (message?: any, ...optionalParams: any[]) => void;
3
+ type StringMessagesFn = (message?: string, ...optionalParams: string[]) => void;
4
+ type AnyMessageFn = (message?: any) => void;
5
+ type StringMessageFn = (message?: string) => void;
6
+ type StringMessageSpreadFn = (...message: string[]) => void;
7
+ type AnyMessageSpreadFn = (...message: any[]) => void;
8
+ type SomeKindOfLogFn = AnyMessagesFn | StringMessagesFn | AnyMessageFn | StringMessageFn | StringMessageSpreadFn | AnyMessageSpreadFn;
9
+ type HasSomeKindOfLogMethod = {
10
+ log: SomeKindOfLogFn;
11
+ };
12
+ /**
13
+ * Something that has a .log method taking a string argument.
14
+ *
15
+ * null and undefined will fall back to console.log.
16
+ */
17
+ export type LoggerCmdInstance = CommandInstance | Console | HasSomeKindOfLogMethod | null | undefined;
18
+ type LinesArgItem = string | number | boolean | Date | RegExp | null | undefined;
19
+ type LinesArg = LinesArgItem | LinesArgItem[];
20
+ /**
21
+ * Logs multiple lines using the log method of the provided {@link LoggerCmdInstance}.
22
+ *
23
+ * Line items that are `null` or `undefined` are logged as empty lines.
24
+ *
25
+ * @param cmd - The logger instance to use. If `null` or `undefined`, `console` will be used.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * logLines(cmd, "line 1", "line 2", null, "line 3");
30
+ * logLines(cmd, ...linesArray); // arrays can be spread into the function
31
+ * logLines(cmd, linesArray); // but it will flatten the plain array for convenience
32
+ * ```
33
+ */
34
+ export declare function logLines(cmd?: LoggerCmdInstance, ...lines: LinesArg[]): void;
35
+ /**
36
+ * Logs an error message using the log method of the provided {@link LoggerCmdInstance}.
37
+ *
38
+ * Line items that are `null` or `undefined` are logged as empty lines.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * logError(cmd, "Message");
43
+ * logError(cmd, "Message", "Additional message");
44
+ * logError(cmd, "Message", "Additional message", "Another additional message line");
45
+ * logError(cmd, "Message", ...additionalMessages); // arrays can be spread into the function
46
+ * logError(cmd, "Message", additionalMessages); // but it will flatten the plain array for convenience
47
+ * ```
48
+ */
49
+ export declare const logError: (cmd: LoggerCmdInstance, message: string, ...additionalMessages: LinesArg[]) => void;
50
+ /**
51
+ * Logs a warning message using the log method of the provided {@link LoggerCmdInstance}.
52
+ *
53
+ * Line items that are `null` or `undefined` are logged as empty lines.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * logWarning(cmd, "Message");
58
+ * logWarning(cmd, "Message", "Additional message");
59
+ * logWarning(cmd, "Message", "Additional message", "Another additional message line");
60
+ * logWarning(cmd, "Message", ...additionalMessages); // arrays can be spread into the function
61
+ * logWarning(cmd, "Message", additionalMessages); // but it will flatten the plain array for convenience
62
+ * ```
63
+ */
64
+ export declare const logWarning: (cmd: LoggerCmdInstance, message: string, ...additionalMessages: LinesArg[]) => void;
65
+ export {};