@zenstackhq/cli 3.0.0-alpha.2 → 3.0.0-alpha.21

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.
@@ -1,23 +1,22 @@
1
-
2
- 
3
- > @zenstackhq/cli@3.0.0-alpha.1 build /Users/yiming/git/zenstack/zenstack-v3/packages/cli
4
- > tsup-node
5
-
6
- CLI Building entry: {"index":"src/index.ts"}
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.3.5
9
- CLI Using tsup config: /Users/yiming/git/zenstack/zenstack-v3/packages/cli/tsup.config.ts
10
- CLI Target: esnext
11
- CLI Cleaning output folder
12
- ESM Build start
13
- CJS Build start
14
- ESM dist/index.js 14.02 KB
15
- ESM dist/index.js.map 27.76 KB
16
- ESM ⚡️ Build success in 51ms
17
- CJS dist/index.cjs 15.95 KB
18
- CJS dist/index.cjs.map 27.84 KB
19
- CJS ⚡️ Build success in 51ms
20
- DTS Build start
21
- DTS ⚡️ Build success in 1226ms
22
- DTS dist/index.d.ts 108.00 B
23
- DTS dist/index.d.cts 108.00 B
1
+
2
+ > @zenstackhq/cli@3.0.0-alpha.21 build /home/runner/work/zenstack-v3/zenstack-v3/packages/cli
3
+ > tsup-node
4
+
5
+ CLI Building entry: {"index":"src/index.ts"}
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.0
8
+ CLI Using tsup config: /home/runner/work/zenstack-v3/zenstack-v3/packages/cli/tsup.config.ts
9
+ CLI Target: esnext
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.js 19.45 KB
14
+ ESM dist/index.js.map 41.10 KB
15
+ ESM ⚡️ Build success in 121ms
16
+ CJS dist/index.cjs 22.91 KB
17
+ CJS dist/index.cjs.map 41.35 KB
18
+ CJS ⚡️ Build success in 122ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 3231ms
21
+ DTS dist/index.d.ts 108.00 B
22
+ DTS dist/index.d.cts 108.00 B
package/bin/cli CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node --no-warnings
1
+ #!/usr/bin/env node
2
2
 
3
3
  import '../dist/index.js';
package/dist/index.cjs CHANGED
@@ -6,9 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __commonJS = (cb, mod) => function __require() {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
- };
12
9
  var __export = (target, all) => {
13
10
  for (var name in all)
14
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -31,69 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
28
  ));
32
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
30
 
34
- // package.json
35
- var require_package = __commonJS({
36
- "package.json"(exports2, module2) {
37
- module2.exports = {
38
- name: "@zenstackhq/cli",
39
- publisher: "zenstack",
40
- displayName: "ZenStack CLI",
41
- description: "FullStack database toolkit with built-in access control and automatic API generation.",
42
- version: "3.0.0-alpha.2",
43
- type: "module",
44
- author: {
45
- name: "ZenStack Team"
46
- },
47
- homepage: "https://zenstack.dev",
48
- license: "MIT",
49
- keywords: [
50
- "orm",
51
- "fullstack",
52
- "react",
53
- "typescript",
54
- "data modeling"
55
- ],
56
- bin: {
57
- zenstack: "bin/cli"
58
- },
59
- scripts: {
60
- build: "tsup-node",
61
- watch: "tsup-node --watch",
62
- lint: "eslint src --ext ts",
63
- test: "vitest",
64
- pack: "pnpm pack"
65
- },
66
- dependencies: {
67
- "@types/node": "^20.0.0",
68
- "@zenstackhq/language": "workspace:*",
69
- "@zenstackhq/sdk": "workspace:*",
70
- "async-exit-hook": "^2.0.1",
71
- colors: "1.4.0",
72
- commander: "^8.3.0",
73
- langium: "~3.3.0",
74
- ora: "^5.4.1",
75
- "package-manager-detector": "^1.3.0",
76
- "tiny-invariant": "^1.3.3",
77
- "ts-pattern": "^4.3.0"
78
- },
79
- peerDependencies: {
80
- prisma: "^6.0.0",
81
- typescript: "^5.0.0"
82
- },
83
- devDependencies: {
84
- "@types/async-exit-hook": "^2.0.0",
85
- "@types/better-sqlite3": "^7.6.13",
86
- "@types/semver": "^7.3.13",
87
- "@types/tmp": "^0.2.6",
88
- "@zenstackhq/runtime": "workspace:*",
89
- "@zenstackhq/testtools": "workspace:*",
90
- "better-sqlite3": "^11.8.1",
91
- tmp: "^0.2.3"
92
- }
93
- };
94
- }
95
- });
96
-
97
31
  // src/index.ts
98
32
  var src_exports = {};
99
33
  __export(src_exports, {
@@ -101,11 +35,11 @@ __export(src_exports, {
101
35
  });
102
36
  module.exports = __toCommonJS(src_exports);
103
37
  var import_language2 = require("@zenstackhq/language");
104
- var import_colors5 = __toESM(require("colors"), 1);
38
+ var import_colors6 = __toESM(require("colors"), 1);
105
39
  var import_commander = require("commander");
106
40
 
107
41
  // src/actions/db.ts
108
- var import_node_path2 = __toESM(require("path"), 1);
42
+ var import_node_fs2 = __toESM(require("fs"), 1);
109
43
 
110
44
  // src/utils/exec-utils.ts
111
45
  var import_child_process = require("child_process");
@@ -130,7 +64,12 @@ function execPackage(cmd, options) {
130
64
  __name(execPackage, "execPackage");
131
65
 
132
66
  // src/actions/action-utils.ts
67
+ var import_language = require("@zenstackhq/language");
68
+ var import_ast = require("@zenstackhq/language/ast");
69
+ var import_sdk = require("@zenstackhq/sdk");
70
+ var import_colors = __toESM(require("colors"), 1);
133
71
  var import_node_fs = __toESM(require("fs"), 1);
72
+ var import_node_path = __toESM(require("path"), 1);
134
73
 
135
74
  // src/cli-error.ts
136
75
  var CliError = class extends Error {
@@ -140,8 +79,6 @@ var CliError = class extends Error {
140
79
  };
141
80
 
142
81
  // src/actions/action-utils.ts
143
- var import_language = require("@zenstackhq/language");
144
- var import_colors = __toESM(require("colors"), 1);
145
82
  function getSchemaFile(file) {
146
83
  if (file) {
147
84
  if (!import_node_fs.default.existsSync(file)) {
@@ -149,6 +86,13 @@ function getSchemaFile(file) {
149
86
  }
150
87
  return file;
151
88
  }
89
+ const pkgJsonConfig = getPkgJsonConfig(process.cwd());
90
+ if (pkgJsonConfig.schema) {
91
+ if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
92
+ throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
93
+ }
94
+ return pkgJsonConfig.schema;
95
+ }
152
96
  if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
153
97
  return "./zenstack/schema.zmodel";
154
98
  } else if (import_node_fs.default.existsSync("./schema.zmodel")) {
@@ -161,12 +105,14 @@ __name(getSchemaFile, "getSchemaFile");
161
105
  async function loadSchemaDocument(schemaFile) {
162
106
  const loadResult = await (0, import_language.loadDocument)(schemaFile);
163
107
  if (!loadResult.success) {
164
- console.error(import_colors.default.red("Error loading schema:"));
165
108
  loadResult.errors.forEach((err) => {
166
109
  console.error(import_colors.default.red(err));
167
110
  });
168
- throw new CliError("Failed to load schema");
111
+ throw new CliError("Schema contains errors. See above for details.");
169
112
  }
113
+ loadResult.warnings.forEach((warn) => {
114
+ console.warn(import_colors.default.yellow(warn));
115
+ });
170
116
  return loadResult.model;
171
117
  }
172
118
  __name(loadSchemaDocument, "loadSchemaDocument");
@@ -178,42 +124,154 @@ function handleSubProcessError(err) {
178
124
  }
179
125
  }
180
126
  __name(handleSubProcessError, "handleSubProcessError");
127
+ async function generateTempPrismaSchema(zmodelPath, folder) {
128
+ const model = await loadSchemaDocument(zmodelPath);
129
+ if (!model.declarations.some(import_ast.isDataSource)) {
130
+ throw new CliError("Schema must define a datasource");
131
+ }
132
+ const prismaSchema = await new import_sdk.PrismaSchemaGenerator(model).generate();
133
+ if (!folder) {
134
+ folder = import_node_path.default.dirname(zmodelPath);
135
+ }
136
+ const prismaSchemaFile = import_node_path.default.resolve(folder, "~schema.prisma");
137
+ import_node_fs.default.writeFileSync(prismaSchemaFile, prismaSchema);
138
+ return prismaSchemaFile;
139
+ }
140
+ __name(generateTempPrismaSchema, "generateTempPrismaSchema");
141
+ function getPkgJsonConfig(startPath) {
142
+ const result = {
143
+ schema: void 0,
144
+ output: void 0
145
+ };
146
+ const pkgJsonFile = findUp([
147
+ "package.json"
148
+ ], startPath, false);
149
+ if (!pkgJsonFile) {
150
+ return result;
151
+ }
152
+ let pkgJson = void 0;
153
+ try {
154
+ pkgJson = JSON.parse(import_node_fs.default.readFileSync(pkgJsonFile, "utf8"));
155
+ } catch {
156
+ return result;
157
+ }
158
+ if (pkgJson.zenstack && typeof pkgJson.zenstack === "object") {
159
+ result.schema = pkgJson.zenstack.schema && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema);
160
+ result.output = pkgJson.zenstack.output && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output);
161
+ }
162
+ return result;
163
+ }
164
+ __name(getPkgJsonConfig, "getPkgJsonConfig");
165
+ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
166
+ if (!names.some((name) => !!name)) {
167
+ return void 0;
168
+ }
169
+ const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
170
+ if (multiple === false && target) {
171
+ return import_node_path.default.join(cwd, target);
172
+ }
173
+ if (target) {
174
+ result.push(import_node_path.default.join(cwd, target));
175
+ }
176
+ const up = import_node_path.default.resolve(cwd, "..");
177
+ if (up === cwd) {
178
+ return multiple && result.length > 0 ? result : void 0;
179
+ }
180
+ return findUp(names, up, multiple, result);
181
+ }
182
+ __name(findUp, "findUp");
183
+
184
+ // src/actions/db.ts
185
+ async function run(command, options) {
186
+ switch (command) {
187
+ case "push":
188
+ await runPush(options);
189
+ break;
190
+ }
191
+ }
192
+ __name(run, "run");
193
+ async function runPush(options) {
194
+ const schemaFile = getSchemaFile(options.schema);
195
+ const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
196
+ try {
197
+ const cmd = [
198
+ "prisma db push",
199
+ ` --schema "${prismaSchemaFile}"`,
200
+ options.acceptDataLoss ? " --accept-data-loss" : "",
201
+ options.forceReset ? " --force-reset" : "",
202
+ " --skip-generate"
203
+ ].join("");
204
+ try {
205
+ await execPackage(cmd);
206
+ } catch (err) {
207
+ handleSubProcessError(err);
208
+ }
209
+ } finally {
210
+ if (import_node_fs2.default.existsSync(prismaSchemaFile)) {
211
+ import_node_fs2.default.unlinkSync(prismaSchemaFile);
212
+ }
213
+ }
214
+ }
215
+ __name(runPush, "runPush");
181
216
 
182
217
  // src/actions/generate.ts
183
- var import_ast = require("@zenstackhq/language/ast");
184
- var import_sdk = require("@zenstackhq/sdk");
218
+ var import_common_helpers = require("@zenstackhq/common-helpers");
219
+ var import_ast2 = require("@zenstackhq/language/ast");
220
+ var import_sdk2 = require("@zenstackhq/sdk");
185
221
  var import_colors2 = __toESM(require("colors"), 1);
186
- var import_node_fs2 = __toESM(require("fs"), 1);
187
- var import_node_path = __toESM(require("path"), 1);
188
- var import_tiny_invariant = __toESM(require("tiny-invariant"), 1);
189
- async function run(options) {
222
+ var import_node_fs3 = __toESM(require("fs"), 1);
223
+ var import_node_path2 = __toESM(require("path"), 1);
224
+ async function run2(options) {
225
+ const start = Date.now();
190
226
  const schemaFile = getSchemaFile(options.schema);
191
227
  const model = await loadSchemaDocument(schemaFile);
192
- const outputPath = options.output ?? import_node_path.default.dirname(schemaFile);
193
- const tsSchemaFile = import_node_path.default.join(outputPath, "schema.ts");
194
- await new import_sdk.TsSchemaGenerator().generate(schemaFile, [], tsSchemaFile);
228
+ const outputPath = getOutputPath(options, schemaFile);
229
+ const tsSchemaFile = import_node_path2.default.join(outputPath, "schema.ts");
230
+ await new import_sdk2.TsSchemaGenerator().generate(schemaFile, [], outputPath);
195
231
  await runPlugins(model, outputPath, tsSchemaFile);
196
- const prismaSchema = await new import_sdk.PrismaSchemaGenerator(model).generate();
197
- import_node_fs2.default.writeFileSync(import_node_path.default.join(outputPath, "schema.prisma"), prismaSchema);
232
+ if (options.savePrismaSchema) {
233
+ const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
234
+ let prismaSchemaFile = import_node_path2.default.join(outputPath, "schema.prisma");
235
+ if (typeof options.savePrismaSchema === "string") {
236
+ prismaSchemaFile = import_node_path2.default.resolve(outputPath, options.savePrismaSchema);
237
+ import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(prismaSchemaFile), {
238
+ recursive: true
239
+ });
240
+ }
241
+ import_node_fs3.default.writeFileSync(prismaSchemaFile, prismaSchema);
242
+ }
198
243
  if (!options.silent) {
199
- console.log(import_colors2.default.green("Generation completed successfully."));
244
+ console.log(import_colors2.default.green(`Generation completed successfully in ${Date.now() - start}ms.`));
200
245
  console.log(`You can now create a ZenStack client with it.
201
246
 
202
- \`\`\`
247
+ \`\`\`ts
203
248
  import { ZenStackClient } from '@zenstackhq/runtime';
204
249
  import { schema } from '${outputPath}/schema';
205
250
 
206
- const client = new ZenStackClient(schema);
207
- \`\`\`
208
- `);
251
+ const client = new ZenStackClient(schema, {
252
+ dialect: { ... }
253
+ });
254
+ \`\`\``);
209
255
  }
210
256
  }
211
- __name(run, "run");
257
+ __name(run2, "run");
258
+ function getOutputPath(options, schemaFile) {
259
+ if (options.output) {
260
+ return options.output;
261
+ }
262
+ const pkgJsonConfig = getPkgJsonConfig(process.cwd());
263
+ if (pkgJsonConfig.output) {
264
+ return pkgJsonConfig.output;
265
+ } else {
266
+ return import_node_path2.default.dirname(schemaFile);
267
+ }
268
+ }
269
+ __name(getOutputPath, "getOutputPath");
212
270
  async function runPlugins(model, outputPath, tsSchemaFile) {
213
- const plugins = model.declarations.filter(import_ast.isPlugin);
271
+ const plugins = model.declarations.filter(import_ast2.isPlugin);
214
272
  for (const plugin of plugins) {
215
273
  const providerField = plugin.fields.find((f) => f.name === "provider");
216
- (0, import_tiny_invariant.default)(providerField, `Plugin ${plugin.name} does not have a provider field`);
274
+ (0, import_common_helpers.invariant)(providerField, `Plugin ${plugin.name} does not have a provider field`);
217
275
  const provider = providerField.value.value;
218
276
  let useProvider = provider;
219
277
  if (useProvider.startsWith("@core/")) {
@@ -230,33 +288,6 @@ async function runPlugins(model, outputPath, tsSchemaFile) {
230
288
  }
231
289
  __name(runPlugins, "runPlugins");
232
290
 
233
- // src/actions/db.ts
234
- async function run2(command, options) {
235
- const schemaFile = getSchemaFile(options.schema);
236
- await run({
237
- schema: schemaFile,
238
- silent: true
239
- });
240
- const prismaSchemaFile = import_node_path2.default.join(import_node_path2.default.dirname(schemaFile), "schema.prisma");
241
- switch (command) {
242
- case "push":
243
- await runPush(prismaSchemaFile, options);
244
- break;
245
- }
246
- }
247
- __name(run2, "run");
248
- async function runPush(prismaSchemaFile, options) {
249
- const cmd = `prisma db push --schema "${prismaSchemaFile}"${options.acceptDataLoss ? " --accept-data-loss" : ""}${options.forceReset ? " --force-reset" : ""} --skip-generate`;
250
- try {
251
- await execPackage(cmd, {
252
- stdio: "inherit"
253
- });
254
- } catch (err) {
255
- handleSubProcessError(err);
256
- }
257
- }
258
- __name(runPush, "runPush");
259
-
260
291
  // src/actions/info.ts
261
292
  var import_colors3 = __toESM(require("colors"), 1);
262
293
  var import_node_path3 = __toESM(require("path"), 1);
@@ -288,7 +319,7 @@ async function getZenStackPackages(projectPath) {
288
319
  type: "json"
289
320
  }
290
321
  })).default;
291
- } catch (err) {
322
+ } catch {
292
323
  return [];
293
324
  }
294
325
  const packages = Array.from(new Set([
@@ -319,7 +350,7 @@ __name(getZenStackPackages, "getZenStackPackages");
319
350
 
320
351
  // src/actions/init.ts
321
352
  var import_colors4 = __toESM(require("colors"), 1);
322
- var import_node_fs3 = __toESM(require("fs"), 1);
353
+ var import_node_fs4 = __toESM(require("fs"), 1);
323
354
  var import_node_path4 = __toESM(require("path"), 1);
324
355
  var import_ora = __toESM(require("ora"), 1);
325
356
  var import_package_manager_detector = require("package-manager-detector");
@@ -395,11 +426,11 @@ async function run4(projectPath) {
395
426
  }
396
427
  }
397
428
  const generationFolder = "zenstack";
398
- if (!import_node_fs3.default.existsSync(import_node_path4.default.join(projectPath, generationFolder))) {
399
- import_node_fs3.default.mkdirSync(import_node_path4.default.join(projectPath, generationFolder));
429
+ if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder))) {
430
+ import_node_fs4.default.mkdirSync(import_node_path4.default.join(projectPath, generationFolder));
400
431
  }
401
- if (!import_node_fs3.default.existsSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"))) {
402
- import_node_fs3.default.writeFileSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
432
+ if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"))) {
433
+ import_node_fs4.default.writeFileSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
403
434
  } else {
404
435
  console.log(import_colors4.default.yellow("Schema file already exists. Skipping generation of sample."));
405
436
  }
@@ -410,35 +441,44 @@ async function run4(projectPath) {
410
441
  __name(run4, "run");
411
442
 
412
443
  // src/actions/migrate.ts
444
+ var import_node_fs5 = __toESM(require("fs"), 1);
413
445
  var import_node_path5 = __toESM(require("path"), 1);
414
446
  async function run5(command, options) {
415
447
  const schemaFile = getSchemaFile(options.schema);
416
- await run({
417
- schema: schemaFile,
418
- silent: true
419
- });
420
- const prismaSchemaFile = import_node_path5.default.join(import_node_path5.default.dirname(schemaFile), "schema.prisma");
421
- switch (command) {
422
- case "dev":
423
- await runDev(prismaSchemaFile, options);
424
- break;
425
- case "reset":
426
- await runReset(prismaSchemaFile, options);
427
- break;
428
- case "deploy":
429
- await runDeploy(prismaSchemaFile, options);
430
- break;
431
- case "status":
432
- await runStatus(prismaSchemaFile, options);
433
- break;
448
+ const prismaSchemaDir = options.migrations ? import_node_path5.default.dirname(options.migrations) : void 0;
449
+ const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
450
+ try {
451
+ switch (command) {
452
+ case "dev":
453
+ await runDev(prismaSchemaFile, options);
454
+ break;
455
+ case "reset":
456
+ await runReset(prismaSchemaFile, options);
457
+ break;
458
+ case "deploy":
459
+ await runDeploy(prismaSchemaFile, options);
460
+ break;
461
+ case "status":
462
+ await runStatus(prismaSchemaFile, options);
463
+ break;
464
+ }
465
+ } finally {
466
+ if (import_node_fs5.default.existsSync(prismaSchemaFile)) {
467
+ import_node_fs5.default.unlinkSync(prismaSchemaFile);
468
+ }
434
469
  }
435
470
  }
436
471
  __name(run5, "run");
437
- async function runDev(prismaSchemaFile, _options) {
472
+ async function runDev(prismaSchemaFile, options) {
438
473
  try {
439
- await execPackage(`prisma migrate dev --schema "${prismaSchemaFile}" --skip-generate`, {
440
- stdio: "inherit"
441
- });
474
+ const cmd = [
475
+ "prisma migrate dev",
476
+ ` --schema "${prismaSchemaFile}"`,
477
+ " --skip-generate",
478
+ options.name ? ` --name ${options.name}` : "",
479
+ options.createOnly ? " --create-only" : ""
480
+ ].join("");
481
+ await execPackage(cmd);
442
482
  } catch (err) {
443
483
  handleSubProcessError2(err);
444
484
  }
@@ -446,9 +486,12 @@ async function runDev(prismaSchemaFile, _options) {
446
486
  __name(runDev, "runDev");
447
487
  async function runReset(prismaSchemaFile, options) {
448
488
  try {
449
- await execPackage(`prisma migrate reset --schema "${prismaSchemaFile}"${options.force ? " --force" : ""}`, {
450
- stdio: "inherit"
451
- });
489
+ const cmd = [
490
+ "prisma migrate reset",
491
+ ` --schema "${prismaSchemaFile}"`,
492
+ options.force ? " --force" : ""
493
+ ].join("");
494
+ await execPackage(cmd);
452
495
  } catch (err) {
453
496
  handleSubProcessError2(err);
454
497
  }
@@ -456,9 +499,11 @@ async function runReset(prismaSchemaFile, options) {
456
499
  __name(runReset, "runReset");
457
500
  async function runDeploy(prismaSchemaFile, _options) {
458
501
  try {
459
- await execPackage(`prisma migrate deploy --schema "${prismaSchemaFile}"`, {
460
- stdio: "inherit"
461
- });
502
+ const cmd = [
503
+ "prisma migrate deploy",
504
+ ` --schema "${prismaSchemaFile}"`
505
+ ].join("");
506
+ await execPackage(cmd);
462
507
  } catch (err) {
463
508
  handleSubProcessError2(err);
464
509
  }
@@ -466,9 +511,7 @@ async function runDeploy(prismaSchemaFile, _options) {
466
511
  __name(runDeploy, "runDeploy");
467
512
  async function runStatus(prismaSchemaFile, _options) {
468
513
  try {
469
- await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`, {
470
- stdio: "inherit"
471
- });
514
+ await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`);
472
515
  } catch (err) {
473
516
  handleSubProcessError2(err);
474
517
  }
@@ -483,29 +526,44 @@ function handleSubProcessError2(err) {
483
526
  }
484
527
  __name(handleSubProcessError2, "handleSubProcessError");
485
528
 
529
+ // src/actions/validate.ts
530
+ var import_colors5 = __toESM(require("colors"), 1);
531
+ async function run6(options) {
532
+ const schemaFile = getSchemaFile(options.schema);
533
+ try {
534
+ await loadSchemaDocument(schemaFile);
535
+ console.log(import_colors5.default.green("\u2713 Schema validation completed successfully."));
536
+ } catch (error) {
537
+ console.error(import_colors5.default.red("\u2717 Schema validation failed."));
538
+ throw error;
539
+ }
540
+ }
541
+ __name(run6, "run");
542
+
486
543
  // src/utils/version-utils.ts
544
+ var import_node_fs6 = __toESM(require("fs"), 1);
545
+ var import_node_path6 = __toESM(require("path"), 1);
546
+ var import_node_url = require("url");
547
+ var import_meta = {};
487
548
  function getVersion() {
488
549
  try {
489
- return require("../package.json").version;
550
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path6.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
551
+ return JSON.parse(import_node_fs6.default.readFileSync(import_node_path6.default.join(_dirname, "../package.json"), "utf8")).version;
490
552
  } catch {
491
- try {
492
- return require_package().version;
493
- } catch {
494
- return void 0;
495
- }
553
+ return void 0;
496
554
  }
497
555
  }
498
556
  __name(getVersion, "getVersion");
499
557
 
500
558
  // src/index.ts
501
559
  var generateAction = /* @__PURE__ */ __name(async (options) => {
502
- await run(options);
560
+ await run2(options);
503
561
  }, "generateAction");
504
562
  var migrateAction = /* @__PURE__ */ __name(async (command, options) => {
505
563
  await run5(command, options);
506
564
  }, "migrateAction");
507
565
  var dbAction = /* @__PURE__ */ __name(async (command, options) => {
508
- await run2(command, options);
566
+ await run(command, options);
509
567
  }, "dbAction");
510
568
  var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
511
569
  await run3(projectPath);
@@ -513,29 +571,45 @@ var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
513
571
  var initAction = /* @__PURE__ */ __name(async (projectPath) => {
514
572
  await run4(projectPath);
515
573
  }, "initAction");
574
+ var validateAction = /* @__PURE__ */ __name(async (options) => {
575
+ await run6(options);
576
+ }, "validateAction");
516
577
  function createProgram() {
517
578
  const program2 = new import_commander.Command("zenstack");
518
579
  program2.version(getVersion(), "-v --version", "display CLI version");
519
580
  const schemaExtensions = import_language2.ZModelLanguageMetaData.fileExtensions.join(", ");
520
- program2.description(`${import_colors5.default.bold.blue("\u03B6")} ZenStack is a Prisma power pack for building full-stack apps.
581
+ program2.description(`${import_colors6.default.bold.blue("\u03B6")} ZenStack is a database access toolkit for TypeScript apps.
521
582
 
522
583
  Documentation: https://zenstack.dev.`).showHelpAfterError().showSuggestionAfterError();
523
584
  const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "schema.zmodel" unless specified in package.json.`);
524
- program2.command("generate").description("Run code generation.").addOption(schemaOption).addOption(new import_commander.Option("-o, --output <path>", "default output directory for core plugins")).action(generateAction);
585
+ program2.command("generate").description("Run code generation.").addOption(schemaOption).addOption(new import_commander.Option("--silent", "do not print any output")).addOption(new import_commander.Option("--save-prisma-schema [path]", "save a Prisma schema file, by default into the output directory")).addOption(new import_commander.Option("-o, --output <path>", "default output directory for core plugins")).action(generateAction);
525
586
  const migrateCommand = program2.command("migrate").description("Update the database schema with migrations.");
526
- migrateCommand.command("dev").addOption(schemaOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
527
- migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
528
- migrateCommand.command("deploy").addOption(schemaOption).description("Deploy your pending migrations to your production/staging database.").action((options) => migrateAction("deploy", options));
529
- migrateCommand.command("status").addOption(schemaOption).description("check the status of your database migrations.").action((options) => migrateAction("status", options));
587
+ const migrationsOption = new import_commander.Option("--migrations <path>", "path for migrations");
588
+ migrateCommand.command("dev").addOption(schemaOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).addOption(migrationsOption).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
589
+ migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
590
+ migrateCommand.command("deploy").addOption(schemaOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database.").action((options) => migrateAction("deploy", options));
591
+ migrateCommand.command("status").addOption(schemaOption).addOption(migrationsOption).description("check the status of your database migrations.").action((options) => migrateAction("status", options));
530
592
  const dbCommand = program2.command("db").description("Manage your database schema during development.");
531
593
  dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(new import_commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new import_commander.Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
532
594
  program2.command("info").description("Get information of installed ZenStack and related packages.").argument("[path]", "project path", ".").action(infoAction);
533
595
  program2.command("init").description("Initialize an existing project for ZenStack.").argument("[path]", "project path", ".").action(initAction);
596
+ program2.command("validate").description("Validate a ZModel schema.").addOption(schemaOption).action(validateAction);
534
597
  return program2;
535
598
  }
536
599
  __name(createProgram, "createProgram");
537
600
  var program = createProgram();
538
- program.parse(process.argv);
601
+ program.parseAsync().catch((err) => {
602
+ if (err instanceof CliError) {
603
+ console.error(import_colors6.default.red(err.message));
604
+ process.exit(1);
605
+ } else if (err instanceof import_commander.CommanderError) {
606
+ process.exit(err.exitCode);
607
+ } else {
608
+ console.error(import_colors6.default.red("An unexpected error occurred:"));
609
+ console.error(err);
610
+ process.exit(1);
611
+ }
612
+ });
539
613
  // Annotate the CommonJS export names for ESM import in node:
540
614
  0 && (module.exports = {
541
615
  createProgram