@zenstackhq/cli 3.3.1-beta.2 → 3.3.2-beta.1

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/index.cjs CHANGED
@@ -29,7 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
 
30
30
  // src/index.ts
31
31
  var import_config = require("dotenv/config");
32
- var import_language5 = require("@zenstackhq/language");
32
+ var import_language4 = require("@zenstackhq/language");
33
33
  var import_colors10 = __toESM(require("colors"), 1);
34
34
  var import_commander = require("commander");
35
35
 
@@ -931,7 +931,6 @@ function handleSubProcessError2(err) {
931
931
  __name(handleSubProcessError2, "handleSubProcessError");
932
932
 
933
933
  // src/actions/proxy.ts
934
- var import_language4 = require("@zenstackhq/language");
935
934
  var import_ast3 = require("@zenstackhq/language/ast");
936
935
  var import_utils2 = require("@zenstackhq/language/utils");
937
936
  var import_orm = require("@zenstackhq/orm");
@@ -1001,6 +1000,11 @@ __name(getLatestVersion, "getLatestVersion");
1001
1000
  // src/actions/proxy.ts
1002
1001
  var import_meta3 = {};
1003
1002
  async function run9(options) {
1003
+ const allowedLogLevels = [
1004
+ "error",
1005
+ "query"
1006
+ ];
1007
+ const log = options.logLevel?.filter((level) => allowedLogLevels.includes(level));
1004
1008
  const schemaFile = getSchemaFile(options.schema);
1005
1009
  console.log(import_colors9.default.gray(`Loading ZModel schema from: ${schemaFile}`));
1006
1010
  let outputPath = getOutputPath(options, schemaFile);
@@ -1015,19 +1019,12 @@ async function run9(options) {
1015
1019
  if (!schemaUrl) {
1016
1020
  throw new CliError(`The schema's "datasource" does not have a "url" field, please provide it with -d option.`);
1017
1021
  }
1018
- const zModelGenerator = new import_language4.ZModelCodeGenerator();
1019
- const url = zModelGenerator.generate(schemaUrl);
1020
- databaseUrl = evaluateUrl(url);
1022
+ databaseUrl = evaluateUrl(schemaUrl);
1021
1023
  }
1022
1024
  const provider = (0, import_utils2.getStringLiteral)(dataSource?.fields.find((f) => f.name === "provider")?.value);
1023
1025
  const dialect = createDialect(provider, databaseUrl, outputPath);
1024
1026
  const jiti = (0, import_jiti2.createJiti)(import_meta3.url);
1025
1027
  const schemaModule = await jiti.import(import_node_path9.default.join(outputPath, "schema"));
1026
- const allowedLogLevels = [
1027
- "error",
1028
- "query"
1029
- ];
1030
- const log = options.logLevel?.filter((level) => allowedLogLevels.includes(level));
1031
1028
  const db = new import_orm.ZenStackClient(schemaModule.schema, {
1032
1029
  dialect,
1033
1030
  log: log && log.length > 0 ? log : void 0
@@ -1040,17 +1037,19 @@ async function run9(options) {
1040
1037
  startServer(db, schemaModule.schema, options);
1041
1038
  }
1042
1039
  __name(run9, "run");
1043
- function evaluateUrl(value) {
1044
- const envMatch = value.trim().match(/^env\s*\(\s*['"]([^'"]+)['"]\s*\)$/);
1045
- if (envMatch) {
1046
- const varName = envMatch[1];
1047
- const envValue = process.env[varName];
1040
+ function evaluateUrl(schemaUrl) {
1041
+ if ((0, import_ast3.isLiteralExpr)(schemaUrl)) {
1042
+ return (0, import_utils2.getStringLiteral)(schemaUrl);
1043
+ } else if ((0, import_ast3.isInvocationExpr)(schemaUrl)) {
1044
+ const envFunction = schemaUrl;
1045
+ const envName = (0, import_utils2.getStringLiteral)(envFunction.args[0]?.value);
1046
+ const envValue = process.env[envName];
1048
1047
  if (!envValue) {
1049
- throw new CliError(`Environment variable ${varName} is not set`);
1048
+ throw new CliError(`Environment variable ${envName} is not set`);
1050
1049
  }
1051
1050
  return envValue;
1052
1051
  } else {
1053
- return value;
1052
+ throw new CliError(`Unable to resolve the "url" field value.`);
1054
1053
  }
1055
1054
  }
1056
1055
  __name(evaluateUrl, "evaluateUrl");
@@ -1422,7 +1421,7 @@ var proxyAction = /* @__PURE__ */ __name(async (options) => {
1422
1421
  }, "proxyAction");
1423
1422
  function createProgram() {
1424
1423
  const program = new import_commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
1425
- const schemaExtensions = import_language5.ZModelLanguageMetaData.fileExtensions.join(", ");
1424
+ const schemaExtensions = import_language4.ZModelLanguageMetaData.fileExtensions.join(", ");
1426
1425
  program.description(`${import_colors10.default.bold.blue("\u03B6")} ZenStack is the modern data layer for TypeScript apps.
1427
1426
 
1428
1427
  Documentation: https://zenstack.dev/docs`).showHelpAfterError().showSuggestionAfterError();