@drzl/cli 4.21.0 → 4.24.0

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/config.cjs CHANGED
@@ -33,16 +33,28 @@ var config_exports = {};
33
33
  __export(config_exports, {
34
34
  AffixSchema: () => AffixSchema,
35
35
  AnalyzerSchema: () => AnalyzerSchema,
36
+ CONFIG_FILE_NAMES: () => CONFIG_FILE_NAMES,
37
+ CONFIG_SCHEMA_ID: () => CONFIG_SCHEMA_ID,
36
38
  ColumnRulesSchema: () => ColumnRulesSchema,
37
39
  ConfigSchema: () => ConfigSchema,
40
+ GENERATOR_KINDS: () => GENERATOR_KINDS,
41
+ GeneratorKindSchema: () => GeneratorKindSchema,
38
42
  GeneratorSchema: () => GeneratorSchema,
39
43
  ImportExtensionSchema: () => ImportExtensionSchema,
40
44
  NamingSchema: () => NamingSchema,
45
+ buildConfigJsonSchema: () => buildConfigJsonSchema,
41
46
  computeGeneratorOutputDirs: () => computeGeneratorOutputDirs,
42
47
  computeWatchTargets: () => computeWatchTargets,
48
+ configFromKinds: () => configFromKinds,
43
49
  defineConfig: () => defineConfig,
50
+ expressOutDir: () => expressOutDir,
51
+ fastifyOutDir: () => fastifyOutDir,
44
52
  filterTables: () => filterTables,
53
+ graphqlOutDir: () => graphqlOutDir,
54
+ honoOutDir: () => honoOutDir,
55
+ importFreshConfigModule: () => importFreshConfigModule,
45
56
  loadConfig: () => loadConfig,
57
+ nestjsOutDir: () => nestjsOutDir,
46
58
  resolveConfig: () => resolveConfig,
47
59
  resolveTemplateDirsSync: () => resolveTemplateDirsSync,
48
60
  tableFilterWarnings: () => tableFilterWarnings,
@@ -55,6 +67,207 @@ var import_node_module = require("module");
55
67
  var path = __toESM(require("path"), 1);
56
68
  var import_zod = require("zod");
57
69
 
70
+ // src/config-errors.ts
71
+ function hasOwn(object, key) {
72
+ return Object.prototype.hasOwnProperty.call(object, key);
73
+ }
74
+ var CONFIG_INVALID_CODE = "DRZL_CFG_002";
75
+ var ConfigValidationError = class extends Error {
76
+ constructor(message) {
77
+ super(message);
78
+ this.code = CONFIG_INVALID_CODE;
79
+ this.name = "ConfigValidationError";
80
+ }
81
+ };
82
+ var MAX_LISTED_PROBLEMS = 8;
83
+ var MAX_VALUE_CHARS = 60;
84
+ function renderConfigPath(segments) {
85
+ if (!segments.length) return "(root)";
86
+ let out = "";
87
+ for (const segment of segments) {
88
+ if (typeof segment === "number") {
89
+ out += `[${segment}]`;
90
+ continue;
91
+ }
92
+ const key = String(segment);
93
+ if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key)) out += out ? `.${key}` : key;
94
+ else out += `[${JSON.stringify(key)}]`;
95
+ }
96
+ return out;
97
+ }
98
+ function describeValue(value) {
99
+ if (value === void 0) return "undefined";
100
+ if (value === null) return "null";
101
+ switch (typeof value) {
102
+ case "boolean":
103
+ return String(value);
104
+ case "number":
105
+ return String(value);
106
+ case "bigint":
107
+ return `${value}n`;
108
+ case "function":
109
+ return "[function]";
110
+ case "symbol":
111
+ return String(value);
112
+ case "string":
113
+ return value.length <= MAX_VALUE_CHARS ? JSON.stringify(value) : `${JSON.stringify(value.slice(0, MAX_VALUE_CHARS))} ... (${value.length} characters)`;
114
+ }
115
+ let json;
116
+ try {
117
+ json = JSON.stringify(value);
118
+ } catch {
119
+ return null;
120
+ }
121
+ if (typeof json !== "string") return null;
122
+ return json.length <= MAX_VALUE_CHARS ? json : null;
123
+ }
124
+ function valueAt(raw, segments) {
125
+ let current = raw;
126
+ for (const segment of segments) {
127
+ if (current === null || typeof current !== "object") return { found: false, value: void 0 };
128
+ if (!hasOwn(current, String(segment))) return { found: false, value: void 0 };
129
+ current = current[segment];
130
+ }
131
+ return { found: true, value: current };
132
+ }
133
+ function editDistance(a, b) {
134
+ if (a === b) return 0;
135
+ if (!a.length) return b.length;
136
+ if (!b.length) return a.length;
137
+ let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
138
+ for (let i = 1; i <= a.length; i++) {
139
+ const current = new Array(b.length + 1);
140
+ current[0] = i;
141
+ for (let j = 1; j <= b.length; j++) {
142
+ const substitution = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
143
+ current[j] = Math.min(current[j - 1] + 1, previous[j] + 1, substitution);
144
+ }
145
+ previous = current;
146
+ }
147
+ return previous[b.length];
148
+ }
149
+ function nearestKey(key, known) {
150
+ const budget = key.length >= 5 ? 2 : 1;
151
+ let best;
152
+ let bestDistance = Number.POSITIVE_INFINITY;
153
+ for (const candidate of known) {
154
+ if (candidate === key) return void 0;
155
+ const distance = editDistance(key, candidate);
156
+ if (distance <= budget && distance < bestDistance) {
157
+ best = candidate;
158
+ bestDistance = distance;
159
+ }
160
+ }
161
+ return best;
162
+ }
163
+ function objectNodeFor(node) {
164
+ if (!node || typeof node !== "object") return void 0;
165
+ const record = node;
166
+ const anyOf = record.anyOf;
167
+ if (Array.isArray(anyOf)) {
168
+ const branches = anyOf.filter(
169
+ (branch) => branch && typeof branch === "object" && (branch.properties !== void 0 || typeof branch.additionalProperties === "object")
170
+ );
171
+ return branches.length === 1 ? branches[0] : void 0;
172
+ }
173
+ if (record.properties !== void 0 || record.additionalProperties !== void 0) return record;
174
+ return void 0;
175
+ }
176
+ function unknownConfigKeys(raw, schema) {
177
+ const found = [];
178
+ walkForUnknownKeys(raw, schema, [], found);
179
+ return found;
180
+ }
181
+ function walkForUnknownKeys(value, node, segments, found) {
182
+ if (value === null || typeof value !== "object") return;
183
+ if (Array.isArray(value)) {
184
+ const items = node?.items;
185
+ if (!items) return;
186
+ value.forEach((entry, index) => walkForUnknownKeys(entry, items, [...segments, index], found));
187
+ return;
188
+ }
189
+ const object = objectNodeFor(node);
190
+ if (!object) return;
191
+ const properties = object.properties;
192
+ const additional = object.additionalProperties;
193
+ if (!properties) {
194
+ if (additional && typeof additional === "object") {
195
+ for (const [key, entry] of Object.entries(value)) {
196
+ walkForUnknownKeys(entry, additional, [...segments, key], found);
197
+ }
198
+ }
199
+ return;
200
+ }
201
+ const known = Object.keys(properties);
202
+ for (const [key, entry] of Object.entries(value)) {
203
+ if (hasOwn(properties, key)) {
204
+ walkForUnknownKeys(entry, properties[key], [...segments, key], found);
205
+ continue;
206
+ }
207
+ if (additional === false) continue;
208
+ found.push({ path: [...segments], key, suggestion: nearestKey(key, known) });
209
+ }
210
+ }
211
+ function unknownKeyWarnings(raw, schema) {
212
+ return unknownConfigKeys(raw, schema).map((unknown) => {
213
+ const where = unknown.path.length ? `in ${renderConfigPath(unknown.path)}` : "at the top level";
214
+ const suggestion = unknown.suggestion ? ` Did you mean "${unknown.suggestion}"?` : "";
215
+ return `drzl config: unknown key "${unknown.key}" ${where}; it is ignored.${suggestion}`;
216
+ });
217
+ }
218
+ function nodeAt(schema, segments) {
219
+ let node = schema;
220
+ for (const segment of segments) {
221
+ if (typeof segment === "number") {
222
+ node = node?.items;
223
+ continue;
224
+ }
225
+ const object = objectNodeFor(node);
226
+ if (!object) return void 0;
227
+ const properties = object.properties;
228
+ if (properties && hasOwn(properties, String(segment))) {
229
+ node = properties[String(segment)];
230
+ continue;
231
+ }
232
+ const additional = object.additionalProperties;
233
+ if (additional && typeof additional === "object") {
234
+ node = additional;
235
+ continue;
236
+ }
237
+ return void 0;
238
+ }
239
+ return objectNodeFor(node);
240
+ }
241
+ function knownKeysAt(schema, segments) {
242
+ const node = nodeAt(schema, segments);
243
+ const properties = node?.properties;
244
+ return properties ? Object.keys(properties) : [];
245
+ }
246
+ function renderIssue(issue, raw, schema) {
247
+ const segments = issue.path ?? [];
248
+ const where = renderConfigPath(segments);
249
+ if (issue.code === "unrecognized_keys" && issue.keys?.length) {
250
+ const known = knownKeysAt(schema, segments);
251
+ return issue.keys.map((key) => {
252
+ const suggestion = nearestKey(key, known);
253
+ return `${where}: unrecognized key "${key}".${suggestion ? ` Did you mean "${suggestion}"?` : ""}`;
254
+ });
255
+ }
256
+ const what = String(issue.message ?? "is not valid").replace(/^Invalid input:\s*/, "");
257
+ const { found, value } = valueAt(raw, segments);
258
+ const shown = found ? describeValue(value) : null;
259
+ return [`${where}: ${what}${shown === null ? "" : ` (found ${shown})`}`];
260
+ }
261
+ function formatConfigProblems(file, issues, raw, schema) {
262
+ const lines = issues.flatMap((issue) => renderIssue(issue, raw, schema));
263
+ const shown = lines.slice(0, MAX_LISTED_PROBLEMS);
264
+ const rest = lines.length - shown.length;
265
+ const header = `${file} is not valid (${CONFIG_INVALID_CODE}). ${lines.length} problem${lines.length === 1 ? "" : "s"}:`;
266
+ const body = shown.map((line) => ` - ${line}`);
267
+ if (rest > 0) body.push(` ... and ${rest} more`);
268
+ return [header, ...body].join("\n");
269
+ }
270
+
58
271
  // src/patterns.ts
59
272
  function patternToRegExp(pattern) {
60
273
  return new RegExp(
@@ -93,13 +306,13 @@ var NamingSchema = import_zod.z.object({
93
306
  routerSuffix: import_zod.z.string().default("Router"),
94
307
  procedureCase: import_zod.z.enum(["camel", "kebab", "snake"]).default("camel")
95
308
  }).partial();
96
- var AffixValueSchema = import_zod.z.union(
309
+ var affixValueSchema = (pattern) => import_zod.z.union(
97
310
  [
98
- import_zod.z.string(),
311
+ import_zod.z.string().meta({ pattern }),
99
312
  import_zod.z.object({
100
- insert: import_zod.z.string().optional(),
101
- update: import_zod.z.string().optional(),
102
- select: import_zod.z.string().optional()
313
+ insert: import_zod.z.string().meta({ pattern }).optional(),
314
+ update: import_zod.z.string().meta({ pattern }).optional(),
315
+ select: import_zod.z.string().meta({ pattern }).optional()
103
316
  }).strict()
104
317
  ],
105
318
  {
@@ -107,8 +320,8 @@ var AffixValueSchema = import_zod.z.union(
107
320
  }
108
321
  );
109
322
  var AffixPartSchema = import_zod.z.object({
110
- prefix: AffixValueSchema.optional(),
111
- suffix: AffixValueSchema.optional()
323
+ prefix: affixValueSchema(import_validation_core.AFFIX_PREFIX_PATTERN).optional(),
324
+ suffix: affixValueSchema(import_validation_core.AFFIX_SUFFIX_PATTERN).optional()
112
325
  }).strict();
113
326
  var AffixSchema = import_zod.z.object({
114
327
  /**
@@ -121,18 +334,34 @@ var AffixSchema = import_zod.z.object({
121
334
  type: AffixPartSchema.optional()
122
335
  }).strict();
123
336
  var ImportExtensionSchema = import_zod.z.enum(import_validation_core.IMPORT_EXTENSIONS);
337
+ var GeneratorKindSchema = import_zod.z.enum([
338
+ "orpc",
339
+ "trpc",
340
+ "hono",
341
+ "express",
342
+ "fastify",
343
+ "nestjs",
344
+ "graphql",
345
+ "service",
346
+ "zod",
347
+ "valibot",
348
+ "arktype",
349
+ "typebox",
350
+ "effect",
351
+ "json-schema"
352
+ ]);
353
+ var GENERATOR_KINDS = GeneratorKindSchema.options;
124
354
  var GeneratorSchema = import_zod.z.object({
125
- kind: import_zod.z.enum([
126
- "orpc",
127
- "trpc",
128
- "service",
129
- "zod",
130
- "valibot",
131
- "arktype",
132
- "typebox",
133
- "effect",
134
- "json-schema"
135
- ]),
355
+ kind: GeneratorKindSchema,
356
+ /**
357
+ * Which of Hono's two official validator middlewares the emitted routes carry, and therefore
358
+ * which package they import. `hono` only.
359
+ *
360
+ * `standard` is `sValidator` from `@hono/standard-validator`, which takes any Standard Schema
361
+ * and so works with every library `validation.library` can name. `zod` is `zValidator` from
362
+ * `@hono/zod-validator`, which is zod-specific.
363
+ */
364
+ validator: import_zod.z.enum(["standard", "zod"]).optional(),
136
365
  /**
137
366
  * Overrides the top-level `importExtension` for this generator alone, for a project whose
138
367
  * generated directories are compiled by different tsconfigs.
@@ -140,6 +369,17 @@ var GeneratorSchema = import_zod.z.object({
140
369
  importExtension: ImportExtensionSchema.optional(),
141
370
  template: import_zod.z.string().optional(),
142
371
  includeRelations: import_zod.z.boolean().optional(),
372
+ /**
373
+ * Write an enum used by two or more columns once under `$defs` in the `json-schema` per-table
374
+ * modules, and `$ref` it at each use.
375
+ *
376
+ * Off by default, and the reason is a consumer pattern rather than a doubt about the keyword. A
377
+ * per-table schema is used whole and one property at a time, and a `$ref` cannot survive being
378
+ * pulled out with its property: `properties[col]` compiled on its own is a dangling reference
379
+ * that ajv refuses outright. The OpenAPI document shares regardless, because a document is only
380
+ * ever read whole.
381
+ */
382
+ sharedEnums: import_zod.z.boolean().optional(),
143
383
  /**
144
384
  * Type `json` and `jsonb` columns from the schema rather than leaving them wide.
145
385
  *
@@ -168,6 +408,27 @@ var GeneratorSchema = import_zod.z.object({
168
408
  * fact about the table rather than the row. This checks the half that needs no database.
169
409
  */
170
410
  duplicateFinder: import_zod.z.boolean().optional(),
411
+ /**
412
+ * zod and valibot. Also emit `constraints.ts`: every CHECK, unique constraint, primary and
413
+ * foreign key on each table as plain data, plus `constraintForIssue`, which maps a validation
414
+ * issue back to the constraint that caused it.
415
+ *
416
+ * For building forms. A schema states what a value must look like and never says which
417
+ * constraint said so, so a failed parse hands a form a message and no way to attribute it; and
418
+ * uniqueness and foreign keys, the two constraints no per-row schema can check, are absent from
419
+ * the emitted schemas in every form.
420
+ *
421
+ * Not `meta` written to a second file. `meta` describes a *field* and travels with the schema
422
+ * into `z.toJSONSchema`; this describes the table's *constraints*, carries their names, states
423
+ * each operand as data rather than inside a sentence, and is read without holding a schema.
424
+ *
425
+ * `true` is the shorthand for `{ enabled: true }`. `{ errorMap: false }` emits the data alone,
426
+ * without the matcher.
427
+ */
428
+ constraints: import_zod.z.union([
429
+ import_zod.z.boolean(),
430
+ import_zod.z.object({ enabled: import_zod.z.boolean().optional(), errorMap: import_zod.z.boolean().optional() }).strict()
431
+ ]).optional(),
171
432
  /**
172
433
  * zod only. Attach the facts the analyzer knows and a zod schema cannot state, as `.meta()` on
173
434
  * every field and every table schema: the declared SQL type, the primary key, the unique
@@ -341,7 +602,31 @@ var AnalyzerSchema = import_zod.z.object({
341
602
  includeHeuristicRelations: import_zod.z.boolean().default(false)
342
603
  });
343
604
  var ConfigSchema = import_zod.z.object({
344
- schema: import_zod.z.string(),
605
+ /**
606
+ * Path to the Drizzle schema module. Optional since drizzle-kit interop: a project that
607
+ * already names its schema in `drizzle.config.ts` should not have to say it twice, so an
608
+ * omitted `schema` falls back to reading the drizzle-kit config (see `drizzleKit`). The
609
+ * "neither file names a schema" error is raised at resolution time, where it can name both
610
+ * files, rather than here, where "Required" could name only this one.
611
+ */
612
+ schema: import_zod.z.string().optional(),
613
+ /**
614
+ * Read the schema path from drizzle-kit's own config instead of `schema`.
615
+ *
616
+ * `true` reads `drizzle.config.ts`, then `.js`, then `.json`, the same candidates in the
617
+ * same order drizzle-kit's CLI uses (measured on drizzle-kit 0.31.10). A string reads that
618
+ * file, wherever it is, like kit's own `--config` flag. `false` disables the fallback, so
619
+ * an omitted `schema` is an error even beside a drizzle.config. Unset behaves like `true`
620
+ * whenever `schema` is omitted, and does nothing when `schema` is set: `schema` always
621
+ * wins, with a warning when both are stated.
622
+ *
623
+ * Only kit's `schema` (string or array, entries may be globs) and `dialect` (cross-checked
624
+ * against what the analyzer detects) are read. Everything else in that file describes
625
+ * migrations and database credentials, which DRZL has no use for.
626
+ */
627
+ drizzleKit: import_zod.z.union([import_zod.z.boolean(), import_zod.z.string()], {
628
+ error: "Expected true (read drizzle.config.ts/.js/.json, the same candidates drizzle-kit uses), false (never read one), or a path to the drizzle-kit config file."
629
+ }).optional(),
345
630
  outDir: import_zod.z.string().default("src/api"),
346
631
  /**
347
632
  * Which tables to generate for, matched against the database table name.
@@ -426,10 +711,58 @@ var ConfigSchema = import_zod.z.object({
426
711
  function defineConfig(cfg) {
427
712
  return cfg;
428
713
  }
429
- var ROUTER_KINDS = /* @__PURE__ */ new Set(["orpc", "trpc"]);
714
+ var CONFIG_FILE_NAMES = [
715
+ "drzl.config.ts",
716
+ "drzl.config.mjs",
717
+ "drzl.config.js",
718
+ "drzl.config.cjs",
719
+ "drzl.config.json"
720
+ ];
721
+ var CONFIG_SCHEMA_ID = "https://use-drzl.github.io/drzl/drzl.config.schema.json";
722
+ function buildConfigJsonSchema() {
723
+ const generated = import_zod.z.toJSONSchema(ConfigSchema, {
724
+ io: "input",
725
+ target: "draft-7"
726
+ });
727
+ const properties = {
728
+ // Declared so an editor suggests it and does not report the pointer a reader was told to
729
+ // add as an unknown key. `ConfigSchema` is not strict, so the CLI strips it and never sees it.
730
+ $schema: {
731
+ type: "string",
732
+ description: "Path or URL of this schema, for editor completion. Ignored by drzl."
733
+ },
734
+ ...generated.properties
735
+ };
736
+ const { $schema, properties: _dropped, ...rest } = generated;
737
+ return {
738
+ $schema,
739
+ $id: CONFIG_SCHEMA_ID,
740
+ title: "DRZL configuration",
741
+ description: "Configuration for the drzl CLI. Also describes drzl.config.ts, which gets the same shape from the defineConfig export of @drzl/cli/config.",
742
+ ...rest,
743
+ properties
744
+ };
745
+ }
746
+ var ROUTER_KINDS = /* @__PURE__ */ new Set(["orpc", "trpc", "hono", "express"]);
747
+ var INJECTION_KINDS = /* @__PURE__ */ new Set(["orpc", "trpc"]);
430
748
  function trpcOutDir(g, cfg) {
431
749
  return g.path ?? cfg.outDir;
432
750
  }
751
+ function honoOutDir(g, cfg) {
752
+ return g.path ?? cfg.outDir;
753
+ }
754
+ function expressOutDir(g, cfg) {
755
+ return g.path ?? cfg.outDir;
756
+ }
757
+ function fastifyOutDir(g, cfg) {
758
+ return g.path ?? cfg.outDir;
759
+ }
760
+ function nestjsOutDir(g, cfg) {
761
+ return g.path ?? cfg.outDir;
762
+ }
763
+ function graphqlOutDir(g, cfg) {
764
+ return g.path ?? cfg.outDir;
765
+ }
433
766
  function sharedSchemaNames(opts) {
434
767
  const resolved = (0, import_validation_core.resolveAffix)(opts);
435
768
  return import_validation_core.NAME_MODES.map((mode) => (0, import_validation_core.schemaName)(mode, import_validation_core.AFFIX_PROBE_TABLE, resolved));
@@ -441,8 +774,66 @@ function resolveConfig(cfg) {
441
774
  importExtension: g.importExtension ?? cfg.importExtension
442
775
  }));
443
776
  for (const g of generators) {
777
+ if (g.kind === "fastify") {
778
+ if (g.databaseInjection?.enabled) {
779
+ warnings.push(
780
+ `drzl config: the "fastify" generator sets databaseInjection.enabled, which it does not support. Its handlers are stubs and never call a service, so nothing reads the injected handle. Reach your database from inside the handler bodies you fill in, or use the "trpc" or "orpc" generator, which do delegate to @drzl/generator-service.`
781
+ );
782
+ }
783
+ if (g.validation) {
784
+ warnings.push(
785
+ `drzl config: the "fastify" generator sets "validation", which it does not read. Its route schemas are JSON Schema produced by the same builder as the "json-schema" generator and inlined into the routes, so there is no library to choose and no shared schema module to import. Remove the block.`
786
+ );
787
+ }
788
+ continue;
789
+ }
790
+ if (g.kind === "nestjs") {
791
+ if (g.databaseInjection?.enabled) {
792
+ warnings.push(
793
+ `drzl config: the "nestjs" generator sets databaseInjection.enabled, which it does not support. It emits DTO classes with no handlers at all, so nothing reads the injected handle. Reach your database from the controllers you write around these DTOs, or use the "trpc" or "orpc" generator, which do delegate to @drzl/generator-service.`
794
+ );
795
+ }
796
+ if (g.includeRelations) {
797
+ warnings.push(
798
+ `drzl config: the "nestjs" generator sets includeRelations, which it does not read. Relation lookups are routes, and this generator emits DTO classes for your own controllers rather than routes. Remove the flag.`
799
+ );
800
+ }
801
+ if (g.validation?.useShared || g.validation?.importPath) {
802
+ warnings.push(
803
+ `drzl config: the "nestjs" generator sets validation.useShared or validation.importPath, which it does not read. Its DTO modules are self-contained: the class fields and the schema are generated from the same columns, and wrapping a schema another generator wrote would let the two drift. Only validation.library is read on this kind.`
804
+ );
805
+ }
806
+ if (g.validation?.schemaSuffix || g.validation?.affix) {
807
+ warnings.push(
808
+ `drzl config: the "nestjs" generator sets validation.schemaSuffix or validation.affix, which it does not read. Those options spell the names of shared schema modules, and this generator imports none. Only validation.library is read on this kind.`
809
+ );
810
+ }
811
+ continue;
812
+ }
813
+ if (g.kind === "graphql") {
814
+ if (g.databaseInjection?.enabled) {
815
+ warnings.push(
816
+ `drzl config: the "graphql" generator sets databaseInjection.enabled, which it does not support. It emits SDL and resolver stubs with no handlers at all, so nothing reads the injected handle. Reach your database from the resolvers you write in place of the stubs, or use the "trpc" or "orpc" generator, which do delegate to @drzl/generator-service.`
817
+ );
818
+ }
819
+ if (g.includeRelations) {
820
+ warnings.push(
821
+ `drzl config: the "graphql" generator sets includeRelations, which it does not read. Relation lookups are routes on the router generators, and relation fields on a GraphQL type are resolvers you write against your own data layer. Remove the flag.`
822
+ );
823
+ }
824
+ if (g.validation) {
825
+ warnings.push(
826
+ `drzl config: the "graphql" generator sets "validation", which it does not read. Its schema is GraphQL SDL, GraphQL's own type language, so there is no library to choose and no shared schema module to import. Remove the block.`
827
+ );
828
+ }
829
+ continue;
830
+ }
444
831
  if (!ROUTER_KINDS.has(g.kind)) continue;
445
- if (g.databaseInjection?.enabled) {
832
+ if (g.databaseInjection?.enabled && !INJECTION_KINDS.has(g.kind)) {
833
+ warnings.push(
834
+ `drzl config: the "${g.kind}" generator sets databaseInjection.enabled, which it does not support. Its handlers are stubs and never call a service, so nothing reads the injected handle. Reach your database from inside the handler bodies you fill in, or use the "trpc" or "orpc" generator, which do delegate to @drzl/generator-service.`
835
+ );
836
+ } else if (g.databaseInjection?.enabled) {
446
837
  for (const s of generators.filter((x) => x.kind === "service")) {
447
838
  if (!s.databaseInjection) {
448
839
  s.databaseInjection = g.databaseInjection;
@@ -499,20 +890,58 @@ function resolveConfig(cfg) {
499
890
  }
500
891
  return { config: { ...cfg, generators }, warnings };
501
892
  }
502
- function finalize(raw) {
503
- const { config, warnings } = resolveConfig(ConfigSchema.parse(raw));
504
- for (const w of warnings) console.warn(w);
893
+ var configShape = null;
894
+ function configShapeForReading() {
895
+ return configShape ??= buildConfigJsonSchema();
896
+ }
897
+ function displayConfigPath(file, cwd = process.cwd()) {
898
+ const relative2 = path.relative(cwd, file);
899
+ return relative2 && !relative2.startsWith("..") ? relative2 : file;
900
+ }
901
+ function finalize(raw, file, onWarn) {
902
+ const parsed = ConfigSchema.safeParse(raw);
903
+ if (!parsed.success) {
904
+ throw new ConfigValidationError(
905
+ formatConfigProblems(
906
+ displayConfigPath(file),
907
+ parsed.error.issues,
908
+ raw,
909
+ configShapeForReading()
910
+ )
911
+ );
912
+ }
913
+ for (const w of unknownKeyWarnings(raw, configShapeForReading())) onWarn(w);
914
+ const { config, warnings } = resolveConfig(parsed.data);
915
+ for (const w of warnings) onWarn(w);
505
916
  return config;
506
917
  }
507
- async function loadConfig(customPath) {
918
+ async function importFreshConfigModule(p) {
508
919
  const fsp = await import("fs/promises");
509
- const candidates = customPath ? [customPath] : [
510
- "drzl.config.ts",
511
- "drzl.config.mjs",
512
- "drzl.config.js",
513
- "drzl.config.cjs",
514
- "drzl.config.json"
515
- ];
920
+ const ext = path.extname(p).toLowerCase();
921
+ if (ext === ".json") {
922
+ return JSON.parse(await fsp.readFile(p, "utf8"));
923
+ }
924
+ const { createJiti } = await import("jiti");
925
+ const stat = await fsp.stat(p);
926
+ const base = typeof __filename !== "undefined" ? __filename : path.join(process.cwd(), "index.js");
927
+ const jiti = createJiti(base, {
928
+ moduleCache: false,
929
+ // re-evaluate each time
930
+ fsCache: true,
931
+ // keep transform cache
932
+ cacheVersion: String(stat.mtimeMs),
933
+ // bump on edit
934
+ interopDefault: true,
935
+ tryNative: false
936
+ // <-- prevent native import of .ts
937
+ // debug: true,
938
+ });
939
+ const mod = await jiti.import(p);
940
+ return mod?.default ?? mod;
941
+ }
942
+ async function loadConfig(customPath, onWarn = (warning) => console.warn(warning)) {
943
+ const fsp = await import("fs/promises");
944
+ const candidates = customPath ? [customPath] : [...CONFIG_FILE_NAMES];
516
945
  for (const c of candidates) {
517
946
  const p = path.resolve(process.cwd(), c);
518
947
  try {
@@ -520,38 +949,31 @@ async function loadConfig(customPath) {
520
949
  } catch {
521
950
  continue;
522
951
  }
523
- const ext = path.extname(p).toLowerCase();
524
- if (ext === ".json") {
525
- const raw2 = JSON.parse(await fsp.readFile(p, "utf8"));
526
- return finalize(raw2);
527
- }
528
- const { createJiti } = await import("jiti");
529
- const stat = await fsp.stat(p);
530
- const base = typeof __filename !== "undefined" ? __filename : path.join(process.cwd(), "index.js");
531
- const jiti = createJiti(base, {
532
- moduleCache: false,
533
- // re-evaluate each time
534
- fsCache: true,
535
- // keep transform cache
536
- cacheVersion: String(stat.mtimeMs),
537
- // bump on edit
538
- interopDefault: true,
539
- tryNative: false
540
- // <-- prevent native import of .ts
541
- // debug: true,
542
- });
543
- const mod = await jiti.import(p);
544
- const raw = mod?.default ?? mod;
545
- return finalize(raw);
952
+ return finalize(await importFreshConfigModule(p), p, onWarn);
546
953
  }
547
954
  return null;
548
955
  }
956
+ function configFromKinds(kinds, schema, onWarn = () => {
957
+ }) {
958
+ const parsed = ConfigSchema.parse({
959
+ ...schema ? { schema } : {},
960
+ generators: kinds.map((kind) => ({ kind }))
961
+ });
962
+ const { config, warnings } = resolveConfig(parsed);
963
+ for (const w of warnings) onWarn(w);
964
+ return config;
965
+ }
549
966
  function computeGeneratorOutputDirs(cfg, cwd = process.cwd()) {
550
967
  const abs = (p) => path.resolve(cwd, p);
551
968
  const dirs = /* @__PURE__ */ new Set();
552
969
  dirs.add(abs(cfg.outDir));
553
970
  for (const g of cfg.generators) {
554
971
  if (g.kind === "trpc") dirs.add(abs(trpcOutDir(g, cfg)));
972
+ if (g.kind === "hono") dirs.add(abs(honoOutDir(g, cfg)));
973
+ if (g.kind === "express") dirs.add(abs(expressOutDir(g, cfg)));
974
+ if (g.kind === "fastify") dirs.add(abs(fastifyOutDir(g, cfg)));
975
+ if (g.kind === "nestjs") dirs.add(abs(nestjsOutDir(g, cfg)));
976
+ if (g.kind === "graphql") dirs.add(abs(graphqlOutDir(g, cfg)));
555
977
  if (g.kind === "service") dirs.add(abs(g.path ?? "src/services"));
556
978
  if (g.kind === "zod") dirs.add(abs(g.path ?? "src/validators/zod"));
557
979
  if (g.kind === "valibot") dirs.add(abs(g.path ?? "src/validators/valibot"));
@@ -599,16 +1021,15 @@ function tableFilterWarnings(tables, opts) {
599
1021
  ...ambiguousPatternWarnings(opts.exclude ?? [], tables, "exclude")
600
1022
  ];
601
1023
  }
602
- function computeWatchTargets(cfg, cwd = process.cwd()) {
1024
+ function computeWatchTargets(cfg, cwd = process.cwd(), source) {
603
1025
  const abs = (p) => path.resolve(cwd, p);
604
- const schemaAbs = abs(cfg.schema);
605
- const targets = /* @__PURE__ */ new Set([
606
- path.dirname(schemaAbs),
607
- abs("drzl.config.ts"),
608
- abs("drzl.config.js"),
609
- abs("drzl.config.mjs"),
610
- abs("drzl.config.cjs")
611
- ]);
1026
+ const targets = new Set(CONFIG_FILE_NAMES.map(abs));
1027
+ if (source) {
1028
+ for (const d of source.watchDirs) targets.add(abs(d));
1029
+ if (source.drizzleKitConfigPath) targets.add(abs(source.drizzleKitConfigPath));
1030
+ } else if (cfg.schema) {
1031
+ targets.add(path.dirname(abs(cfg.schema)));
1032
+ }
612
1033
  for (const t of resolveTemplateDirsSync(cfg, cwd)) targets.add(t);
613
1034
  return [...targets];
614
1035
  }
@@ -616,16 +1037,28 @@ function computeWatchTargets(cfg, cwd = process.cwd()) {
616
1037
  0 && (module.exports = {
617
1038
  AffixSchema,
618
1039
  AnalyzerSchema,
1040
+ CONFIG_FILE_NAMES,
1041
+ CONFIG_SCHEMA_ID,
619
1042
  ColumnRulesSchema,
620
1043
  ConfigSchema,
1044
+ GENERATOR_KINDS,
1045
+ GeneratorKindSchema,
621
1046
  GeneratorSchema,
622
1047
  ImportExtensionSchema,
623
1048
  NamingSchema,
1049
+ buildConfigJsonSchema,
624
1050
  computeGeneratorOutputDirs,
625
1051
  computeWatchTargets,
1052
+ configFromKinds,
626
1053
  defineConfig,
1054
+ expressOutDir,
1055
+ fastifyOutDir,
627
1056
  filterTables,
1057
+ graphqlOutDir,
1058
+ honoOutDir,
1059
+ importFreshConfigModule,
628
1060
  loadConfig,
1061
+ nestjsOutDir,
629
1062
  resolveConfig,
630
1063
  resolveTemplateDirsSync,
631
1064
  tableFilterWarnings,