@drzl/cli 4.14.1 → 4.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,3 +56,7 @@ Notes
56
56
  DRZL uses whichever it finds in your project, with your config. With neither installed the
57
57
  generated files are written exactly as rendered, which is the same valid TypeScript with worse
58
58
  whitespace. Add `prettier` as a dev dependency if you want it formatted.
59
+ - Naming an engine instead, `format.engine: 'prettier'` or `'biome'`, is a request rather than a
60
+ preference, so an engine that cannot be loaded is reported on stderr with the reason. The files
61
+ are still written, unformatted; nothing fails. `'auto'` stays silent, because it asked for
62
+ whatever happened to be installed and no formatter is a legitimate answer to that.
package/dist/cli.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";var __drzlModuleUrl = require("node:url").pathToFileURL(__filename).href;
2
3
  "use strict";
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
@@ -55,6 +56,12 @@ function baseSchema(c, mode, target, checks, sets, lengths) {
55
56
  minItems: s.length,
56
57
  maxItems: s.length
57
58
  };
59
+ case "numberObject":
60
+ return {
61
+ type: "object",
62
+ properties: Object.fromEntries(s.fields.map((f) => [f, { type: "number" }])),
63
+ required: [...s.fields]
64
+ };
58
65
  case "numberVector":
59
66
  return {
60
67
  type: "array",
@@ -67,6 +74,8 @@ function baseSchema(c, mode, target, checks, sets, lengths) {
67
74
  pattern: "^[01]*$",
68
75
  ...s.length ? s.exact ? { minLength: s.length, maxLength: s.length } : { maxLength: s.length } : {}
69
76
  };
77
+ case "byteString":
78
+ return { type: "string", ...s.length ? { maxLength: s.length } : {} };
70
79
  }
71
80
  }
72
81
  const set = sets.find((x) => x.column === c.name);
@@ -81,6 +90,7 @@ function baseSchema(c, mode, target, checks, sets, lengths) {
81
90
  if (c.format === "uuid") out.format = UUID_FORMAT;
82
91
  else if (c.format && import_validation_core2.COLUMN_FORMATS[c.format]) out.pattern = import_validation_core2.COLUMN_FORMATS[c.format];
83
92
  if (c.maxLength !== void 0) out.maxLength = c.maxLength;
93
+ applyByteCap(out, c);
84
94
  applyLengths(out, c, lengths);
85
95
  return out;
86
96
  }
@@ -101,6 +111,11 @@ function baseSchema(c, mode, target, checks, sets, lengths) {
101
111
  return {};
102
112
  }
103
113
  }
114
+ function applyByteCap(out, c) {
115
+ if (!c.maxBytes) return;
116
+ out.maxLength = Math.min(Number(out.maxLength ?? Infinity), c.maxBytes);
117
+ out.description = `At most ${c.maxBytes} bytes of UTF-8, which JSON Schema has no keyword for. maxLength counts characters: it refuses nothing the column accepts, and a string of multi-byte characters can satisfy it and still be too long for the column.`;
118
+ }
104
119
  function applyLengths(out, c, lengths) {
105
120
  for (const k of lengths.filter((x) => x.column === c.name)) {
106
121
  const n = Number(k.value);
@@ -278,15 +293,15 @@ var init_dist = __esm({
278
293
  }
279
294
  async generate(opts) {
280
295
  const fs3 = await import("fs/promises");
281
- const path5 = await import("path");
282
- const out = path5.resolve(process.cwd(), opts.outDir);
296
+ const path6 = await import("path");
297
+ const out = path6.resolve(process.cwd(), opts.outDir);
283
298
  const files = [];
284
299
  await fs3.mkdir(out, { recursive: true });
285
300
  const affix = (0, import_validation_core2.resolveAffix)(opts);
286
301
  const fileSuffix = opts.fileSuffix ?? DEFAULT_FILE_SUFFIX;
287
302
  const target = opts.target ?? "draft-2020-12";
288
303
  for (const table of this.analysis.tables) {
289
- const filePath = path5.join(out, (0, import_validation_core2.moduleFileName)(table.tsName, fileSuffix));
304
+ const filePath = path6.join(out, (0, import_validation_core2.moduleFileName)(table.tsName, fileSuffix));
290
305
  const code = renderTableModule(table, affix, target, !!opts.applyDefaults);
291
306
  const formatted = await (0, import_validation_core2.formatCode)(
292
307
  buildHeader(opts.outputHeader) + code,
@@ -301,7 +316,7 @@ var init_dist = __esm({
301
316
  target,
302
317
  applyDefaults: !!opts.applyDefaults
303
318
  });
304
- const componentsPath = path5.join(out, "components.ts");
319
+ const componentsPath = path6.join(out, "components.ts");
305
320
  const code = `export const components = ${JSON.stringify(doc, null, 2)} as const;
306
321
  `;
307
322
  await fs3.writeFile(
@@ -311,7 +326,7 @@ var init_dist = __esm({
311
326
  );
312
327
  files.push(componentsPath);
313
328
  }
314
- const indexPath = path5.join(out, "index.ts");
329
+ const indexPath = path6.join(out, "index.ts");
315
330
  const index = this.analysis.tables.map((t) => `export * from '${(0, import_validation_core2.moduleSpecifier)(t.tsName, fileSuffix, opts.importExtension)}';`).concat(
316
331
  opts.components ? [`export * from './components${opts.importExtension === "none" ? "" : ".js"}';`] : []
317
332
  ).join("\n") + "\n";
@@ -344,7 +359,7 @@ var import_chalk2 = __toESM(require("chalk"), 1);
344
359
  var import_chokidar = __toESM(require("chokidar"), 1);
345
360
  var import_cli_progress = __toESM(require("cli-progress"), 1);
346
361
  var import_commander = require("commander");
347
- var path4 = __toESM(require("path"), 1);
362
+ var path5 = __toESM(require("path"), 1);
348
363
  var import_ora = __toESM(require("ora"), 1);
349
364
 
350
365
  // src/validation-options.ts
@@ -836,9 +851,42 @@ function writeCache(payload) {
836
851
  (0, import_node_fs2.writeFileSync)(CACHE_FILE, JSON.stringify(payload, null, 2), "utf8");
837
852
  }
838
853
 
854
+ // src/version.ts
855
+ var import_node_fs3 = require("fs");
856
+ var path4 = __toESM(require("path"), 1);
857
+ var import_node_url = require("url");
858
+ var PACKAGE_NAME = "@drzl/cli";
859
+ function moduleDir() {
860
+ return path4.dirname((0, import_node_url.fileURLToPath)(__drzlModuleUrl));
861
+ }
862
+ function readVersionFrom(manifestPath) {
863
+ let raw;
864
+ try {
865
+ raw = (0, import_node_fs3.readFileSync)(manifestPath, "utf8");
866
+ } catch (e) {
867
+ throw new Error(
868
+ `${PACKAGE_NAME} cannot read its own version: no manifest at ${manifestPath} (${e?.message ?? String(e)}).`
869
+ );
870
+ }
871
+ const manifest = JSON.parse(raw);
872
+ if (manifest.name !== PACKAGE_NAME) {
873
+ throw new Error(
874
+ `${PACKAGE_NAME} looked for its own version in ${manifestPath} and found ${JSON.stringify(manifest.name)}, so this build is not sitting where it thinks it is.`
875
+ );
876
+ }
877
+ if (typeof manifest.version !== "string" || manifest.version.length === 0) {
878
+ throw new Error(`${manifestPath} declares no version, so there is nothing to report.`);
879
+ }
880
+ return manifest.version;
881
+ }
882
+ function readCliVersion() {
883
+ return readVersionFrom(path4.join(moduleDir(), "..", "package.json"));
884
+ }
885
+ var CLI_VERSION = readCliVersion();
886
+
839
887
  // src/cli.ts
840
888
  var program = new import_commander.Command();
841
- program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version("0.0.1");
889
+ program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version(CLI_VERSION);
842
890
  program.addHelpText(
843
891
  "afterAll",
844
892
  `
@@ -1078,7 +1126,7 @@ Generated output is out of date (${drift.length} file(s)):`));
1078
1126
  for (const d of drift) {
1079
1127
  const mark = d.status === "added" ? "+" : d.status === "removed" ? "-" : "~";
1080
1128
  console.error(
1081
- ` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${path4.relative(process.cwd(), d.file)}`
1129
+ ` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${path5.relative(process.cwd(), d.file)}`
1082
1130
  );
1083
1131
  }
1084
1132
  console.error(
@@ -1130,10 +1178,10 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1130
1178
  process.exit(2);
1131
1179
  return;
1132
1180
  }
1133
- const abs = (p) => path4.resolve(process.cwd(), p);
1181
+ const abs = (p) => path5.resolve(process.cwd(), p);
1134
1182
  const isInside = (child, parent) => {
1135
- const rel = path4.relative(parent, child);
1136
- return !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
1183
+ const rel = path5.relative(parent, child);
1184
+ return !!rel && !rel.startsWith("..") && !path5.isAbsolute(rel);
1137
1185
  };
1138
1186
  const ignoredOutDirs = new Set(computeGeneratorOutputDirs(cfg).map(abs));
1139
1187
  const currentTargets = new Set(computeWatchTargets(cfg).map(abs));
@@ -1158,7 +1206,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1158
1206
  if (full === dir || isInside(full, dir)) return true;
1159
1207
  }
1160
1208
  if (stats?.isDirectory()) return false;
1161
- const ext = path4.extname(full);
1209
+ const ext = path5.extname(full);
1162
1210
  if (!ext) return false;
1163
1211
  return !WATCHED_EXTENSIONS.has(ext);
1164
1212
  };
@@ -1393,7 +1441,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1393
1441
  } else {
1394
1442
  console.log(
1395
1443
  import_chalk2.default.gray(
1396
- "Watching:\n " + Array.from(currentTargets).map((p) => path4.relative(process.cwd(), p)).join("\n ")
1444
+ "Watching:\n " + Array.from(currentTargets).map((p) => path5.relative(process.cwd(), p)).join("\n ")
1397
1445
  )
1398
1446
  );
1399
1447
  }
@@ -1402,8 +1450,8 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1402
1450
  });
1403
1451
  program.command("init").description("Scaffold a drzl.config.ts").option("-y, --yes", "accept defaults").action(async (_opts) => {
1404
1452
  const fs3 = await import("fs/promises");
1405
- const path5 = await import("path");
1406
- const target = path5.resolve(process.cwd(), "drzl.config.ts");
1453
+ const path6 = await import("path");
1454
+ const target = path6.resolve(process.cwd(), "drzl.config.ts");
1407
1455
  const template = `export default {
1408
1456
  schema: 'src/db/schema.ts',
1409
1457
  outDir: 'src/api',