@orizm/cli 2.2.1 → 2.2.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/dist/cli.cjs CHANGED
@@ -38,7 +38,7 @@ async function loadConfig(configFile) {
38
38
  bundle: true,
39
39
  write: false,
40
40
  format: "esm",
41
- target: "node16",
41
+ target: "node22",
42
42
  platform: "node"
43
43
  });
44
44
  const moduleURL = `data:text/javascript,${encodeURIComponent(
@@ -52,9 +52,9 @@ async function loadConfig(configFile) {
52
52
  var import_readline = __toESM(require("readline"), 1);
53
53
 
54
54
  // src/lib/cli-symbol.ts
55
- var import_cli_color = __toESM(require("cli-color"), 1);
56
- var success = import_cli_color.default.green("\u2713");
57
- var error = import_cli_color.default.red("\u2717");
55
+ var import_chalk = __toESM(require("chalk"), 1);
56
+ var success = import_chalk.default.green("\u2713");
57
+ var error = import_chalk.default.red("\u2717");
58
58
 
59
59
  // src/lib/cli-cursor.ts
60
60
  function hide() {
@@ -121,11 +121,11 @@ function createSpinner() {
121
121
 
122
122
  // src/lib/handle-error.ts
123
123
  var v3 = __toESM(require("valibot"), 1);
124
- var import_cli_color3 = __toESM(require("cli-color"), 1);
124
+ var import_chalk3 = __toESM(require("chalk"), 1);
125
125
 
126
126
  // src/lib/display-valibot-error.ts
127
127
  var v2 = __toESM(require("valibot"), 1);
128
- var import_cli_color2 = __toESM(require("cli-color"), 1);
128
+ var import_chalk2 = __toESM(require("chalk"), 1);
129
129
  function displayValibotError(error2) {
130
130
  if (!v2.isValiError(error2)) {
131
131
  return;
@@ -141,10 +141,10 @@ function buildValiErrorMessage(e, options) {
141
141
  }).join("\n");
142
142
  }
143
143
  function getIssueMessage(message, color) {
144
- return color ? import_cli_color2.default.red(message) : message;
144
+ return color ? import_chalk2.default.red(message) : message;
145
145
  }
146
146
  function getLocationPath(path3, color) {
147
- return color ? import_cli_color2.default.yellow(path3) : path3;
147
+ return color ? import_chalk2.default.yellow(path3) : path3;
148
148
  }
149
149
  function getPath(issue) {
150
150
  const issueDotPath = v2.getDotPath(issue);
@@ -188,7 +188,7 @@ function handleError(error2) {
188
188
  }
189
189
  console.error();
190
190
  console.error(
191
- import_cli_color3.default.red(
191
+ import_chalk3.default.red(
192
192
  "Something went wrong. Please check the error below for more details."
193
193
  )
194
194
  );
@@ -201,13 +201,6 @@ function handleError(error2) {
201
201
  // src/cms/generate/generator.ts
202
202
  var import_promises = require("fs/promises");
203
203
  var import_path = __toESM(require("path"), 1);
204
- var import_handlebars = __toESM(require("handlebars"), 1);
205
-
206
- // src/cms/templates/types.ts.hbr
207
- var types_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/cms-sdk/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n {{#unless this.isSubmissions}}\n group: string | null;\n publishedAt: string | null;\n _draft: boolean | null;\n _published: boolean | null;\n scheduledPublishAt: string | null;\n scheduledUnpublishAt: string | null;\n {{else}}\n _formId: string;\n _content: unknown;\n _formSchema: unknown;\n _attachments: StorageItemType[];\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}: {{typeName this}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}CreateInput = {\n {{#unless this.isSubmissions}}\n group?: string | null;\n publishedAt?: string | null;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this "CreateInput"}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}UpdateInput = {\n {{#each this.columns}}\n {{#unless this.readOnly}}{{this.name}}?: {{typeName this "UpdateInput"}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};{{/unless}}\n {{/each}}\n {{#unless this.isSubmissions}}\n publishedAt?: string | null;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\n{{/each}}\n\n\n// Module types\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n {{#each this.columns}}\n {{this.name}}: {{typeName this}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n};\n\nexport type {{toCodeTypeName this.name}}CreateInput = {\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this "CreateInput"}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n};\n\nexport type {{toCodeTypeName this.name}}UpdateInput = {\n id?: string;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n};\n\n{{/each}}\n\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n create: {{toCodeTypeName this.name}}CreateInput;\n update: {{toCodeTypeName this.name}}UpdateInput;\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}}{{#unless this.required}}{{#if ../this.nullsNotDistinct}} | null{{/if}}{{/unless}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n {{#if this.enableForm}}\n submissionDescriptor: {{toCodeTypeName this.name}}_Submission__Descriptor;\n {{else}}\n submissionDescriptor: never;\n {{/if}}\n};\n\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\n\ntype WebhookPayloadBase = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n};\n\n{{#if tables}}\nexport type WebhookPayload = WebhookPayloadBase & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n);\n{{else}}\nexport type WebhookPayload = WebhookPayloadBase;\n{{/if}}\n';
208
-
209
- // src/cms/templates/client.ts.hbr
210
- var client_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { OrizmCMSClient } from "@orizm/cms-sdk";\n\nimport * as Models from "./types";\n\nexport class CMSClient {\n constructor(protected client: OrizmCMSClient) {\n this.tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.client.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.buckets = {\n {{#each buckets}}\n {{toEndpointName this.name}}: this.client.getBucketClient("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.userManagement = this.client.userManagement;\n \n this.userinfo = this.client.userinfo;\n \n this.auth = this.client.auth;\n }\n\n readonly tables;\n readonly buckets;\n readonly userManagement;\n readonly userinfo;\n readonly auth;\n}\n';
211
204
 
212
205
  // src/lib/format-ts-with-prettier.ts
213
206
  var prettier = __toESM(require("prettier/standalone"), 1);
@@ -220,83 +213,150 @@ function formatTsWithPrettier(code) {
220
213
  });
221
214
  }
222
215
 
223
- // src/cms/generate/generator.ts
224
- var Handlebars = import_handlebars.default.create();
225
- Handlebars.registerHelper("toEndpointName", (str) => {
226
- return str;
227
- });
216
+ // src/lib/render-helpers.ts
228
217
  function toCodeTypeName(str) {
229
218
  str = str.charAt(0).toUpperCase() + str.slice(1);
230
219
  return str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
231
220
  }
232
- Handlebars.registerHelper("toCodeTypeName", toCodeTypeName);
233
- Handlebars.registerHelper(
234
- "typeName",
235
- (column, _moduleSuffix) => {
236
- const moduleSuffix = typeof _moduleSuffix === "string" ? _moduleSuffix : "";
237
- if (column.type === "reference") {
221
+ function typeName(column, moduleSuffix = "") {
222
+ switch (column.type) {
223
+ case "reference":
238
224
  return "string";
239
- } else if (column.type === "module") {
240
- return toCodeTypeName(column.moduleName) + moduleSuffix;
241
- } else if (column.type === "module-array") {
242
- return toCodeTypeName(column.moduleName) + moduleSuffix + "[]";
243
- } else if (column.type === "json") {
225
+ case "module":
226
+ return toCodeTypeName(column.moduleName ?? "") + moduleSuffix;
227
+ case "module-array":
228
+ return toCodeTypeName(column.moduleName ?? "") + moduleSuffix + "[]";
229
+ case "json":
244
230
  return "unknown";
245
- } else if (column.type === "storage") {
231
+ case "storage":
246
232
  return "StorageItemType";
247
- } else {
233
+ default:
248
234
  return column.type;
249
- }
250
235
  }
251
- );
252
- Handlebars.registerHelper(
253
- "filterRefColumn",
254
- (columns) => {
255
- return (columns ?? []).filter(
256
- (c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
257
- );
258
- }
259
- );
260
- Handlebars.registerHelper(
261
- "includeName",
262
- (column) => {
263
- return column.type === "reference" ? column.includeName : column.name;
236
+ }
237
+ function nullableSuffix(column) {
238
+ return !column.required && column.type !== "module-array" ? " | null" : "";
239
+ }
240
+ function filterRefColumns(columns) {
241
+ return columns.filter(
242
+ (c) => c.type === "reference" && c.tableName !== void 0 && c.includeName !== void 0 && c.includeName !== "" || c.type === "module" && c.moduleName !== void 0 || c.type === "module-array" && c.moduleName !== void 0
243
+ );
244
+ }
245
+ function getIncludeName(column) {
246
+ return column.type === "reference" ? column.includeName || column.name : column.name;
247
+ }
248
+ function getIncludeType(column) {
249
+ if (column.type === "reference" && column.tableName) {
250
+ return toCodeTypeName(column.tableName) + "__Descriptor";
264
251
  }
265
- );
266
- Handlebars.registerHelper(
267
- "includeType",
268
- (column) => {
269
- if (column.type === "reference")
270
- return toCodeTypeName(column.tableName) + "__Descriptor";
271
- if (column.type === "module")
272
- return `_ModuleRef<${toCodeTypeName(column.moduleName)}__Descriptor>`;
273
- if (column.type === "module-array")
274
- return `_ArrayModuleRef<${toCodeTypeName(
275
- column.moduleName
276
- )}__Descriptor>`;
252
+ if (column.type === "module" && column.moduleName) {
253
+ return `_ModuleRef<${toCodeTypeName(column.moduleName)}__Descriptor>`;
277
254
  }
278
- );
279
- Handlebars.registerHelper(
280
- "filterUniqueIndexes",
281
- (indexes) => {
282
- return (indexes ?? []).filter((i) => i.unique);
255
+ if (column.type === "module-array" && column.moduleName) {
256
+ return `_ArrayModuleRef<${toCodeTypeName(column.moduleName)}__Descriptor>`;
283
257
  }
284
- );
285
- Handlebars.registerHelper(
286
- "getIndexColumns",
287
- (table, index) => {
288
- return index.columns.map((i) => {
289
- const column = table.columns.find((c) => c.name === i);
290
- if (!column) {
291
- throw new Error(`column ${i} not found`);
292
- }
293
- return column;
258
+ return "";
259
+ }
260
+ function renderColumnField(col, options) {
261
+ const optional2 = options?.optional === true ? "?" : "";
262
+ const suffix = options?.suffix ?? "";
263
+ return `${col.name}${optional2}: ${typeName(col, suffix)}${nullableSuffix(col)};`;
264
+ }
265
+ function renderTypeBlock(name, fields) {
266
+ return `export type ${name} = {
267
+ ${fields.join("\n")}
268
+ };`;
269
+ }
270
+ function renderRefsFieldLines(columns) {
271
+ const refCols = filterRefColumns(columns);
272
+ if (refCols.length === 0) return ["refs: object;"];
273
+ return [
274
+ "refs: {",
275
+ ...refCols.map((c) => `${getIncludeName(c)}: ${getIncludeType(c)};`),
276
+ "}"
277
+ ];
278
+ }
279
+ function renderUniqueFieldLines(table) {
280
+ const uniqueIndexes = (table.indexes ?? []).filter((i) => i.unique);
281
+ if (uniqueIndexes.length === 0) return ["unique: [];"];
282
+ const entries = uniqueIndexes.map((index) => {
283
+ const cols = index.columns.map((colName) => {
284
+ const col = table.columns.find((c) => c.name === colName);
285
+ if (!col) throw new Error(`column ${colName} not found`);
286
+ const nullable = !col.required && index.nullsNotDistinct ? " | null" : "";
287
+ return `${col.name}:${typeName(col)}${nullable},`;
294
288
  });
289
+ return `{ ${cols.join("")} },`;
290
+ });
291
+ return ["unique: [", ...entries, "]"];
292
+ }
293
+ function renderModuleRowTypeBlock(mod) {
294
+ return renderTypeBlock(toCodeTypeName(mod.name), [
295
+ "id: string;",
296
+ ...mod.columns.map((col) => renderColumnField(col))
297
+ ]);
298
+ }
299
+ function renderModuleDescriptorBlock(mod) {
300
+ const name = toCodeTypeName(mod.name);
301
+ return renderTypeBlock(`${name}__Descriptor`, [
302
+ `row: ${name};`,
303
+ ...renderRefsFieldLines(mod.columns),
304
+ "unique: [];"
305
+ ]);
306
+ }
307
+ function renderPreamble(importFrom) {
308
+ return `// This file was automatically generated and should not be edited.
309
+
310
+ import { FormValidationRules, StorageItemType } from "${importFrom}";
311
+
312
+ // Utilities
313
+ type _ModuleRef<T> = T & _ModuleDescriptor;
314
+ type _ModuleDescriptor = {
315
+ isModule: true;
316
+ };
317
+ type _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;
318
+ type _ArrayModuleDescriptor = {
319
+ isModuleArray: true;
320
+ };`;
321
+ }
322
+ function renderSection(title, blocks) {
323
+ if (blocks.length === 0) return "";
324
+ return `// ${title}
325
+ ${blocks.join("\n\n")}`;
326
+ }
327
+ function renderWebhookTypesSection(tables) {
328
+ const lines = [
329
+ "// Webhook types",
330
+ 'export type WebhookEvent = "content.create" | "content.update" | "content.delete";',
331
+ "",
332
+ "type WebhookPayloadBase = {",
333
+ " event: WebhookEvent;",
334
+ " timestamp: string;",
335
+ " project: string;",
336
+ "};",
337
+ ""
338
+ ];
339
+ if (tables.length > 0) {
340
+ const unionMembers = tables.map((t) => {
341
+ const name = toCodeTypeName(t.name);
342
+ return `| {
343
+ table: "${t.name}";
344
+ content: ${name};
345
+ old?: ${name};
346
+ }`;
347
+ }).join("\n");
348
+ lines.push(
349
+ `export type WebhookPayload = WebhookPayloadBase & (
350
+ ${unionMembers}
351
+ );`
352
+ );
353
+ } else {
354
+ lines.push("export type WebhookPayload = WebhookPayloadBase;");
295
355
  }
296
- );
297
- Handlebars.registerHelper("if_equal", function(a, b, options) {
298
- return a === b ? options.fn(this) : options.inverse(this);
299
- });
356
+ return lines.join("\n");
357
+ }
358
+
359
+ // src/cms/generate/generator.ts
300
360
  async function generate(options) {
301
361
  const config = options.config;
302
362
  await (0, import_promises.mkdir)(options.output, { recursive: true });
@@ -316,19 +376,143 @@ async function generate(options) {
316
376
  async function renderTypes(config) {
317
377
  const submissionTables = config.tables.filter((t) => t.enableForm).map((t) => ({
318
378
  name: t.name + "__submission",
319
- columns: t.formOptions?.submissionColumns || [],
379
+ columns: t.formOptions?.submissionColumns ?? [],
320
380
  isSubmissions: true
321
381
  }));
322
- const renderParams = {
323
- ...config,
324
- tables: [...config.tables, ...submissionTables]
325
- };
326
- return await formatTsWithPrettier(
327
- Handlebars.compile(types_ts_default)(renderParams)
328
- );
382
+ const allTables = [...config.tables, ...submissionTables];
383
+ const modules = config.tableModules ?? [];
384
+ const source = [
385
+ renderPreamble("@orizm/cms-sdk/common"),
386
+ renderSection("Tables", allTables.map(renderTableTypes)),
387
+ renderSection("Module types", modules.map(renderModuleTypes)),
388
+ // CMS: モジュール descriptor 間は空行なし(スナップショット互換)
389
+ "// Descriptor types\n" + [
390
+ ...allTables.map(renderTableDescriptor),
391
+ modules.map(renderModuleDescriptorBlock).join("\n")
392
+ ].join("\n\n"),
393
+ renderWebhookTypesSection(allTables)
394
+ ].filter(Boolean).join("\n\n\n");
395
+ return await formatTsWithPrettier(source);
396
+ }
397
+ function renderTableTypes(table) {
398
+ const cols = table.columns;
399
+ const name = toCodeTypeName(table.name);
400
+ const rowType = renderTypeBlock(name, [
401
+ "id: string;",
402
+ "createdAt: string;",
403
+ "updatedAt: string;",
404
+ ...!table.isSubmissions ? [
405
+ "group: string | null;",
406
+ "publishedAt: string | null;",
407
+ "_draft: boolean | null;",
408
+ "_published: boolean | null;",
409
+ "scheduledPublishAt: string | null;",
410
+ "scheduledUnpublishAt: string | null;"
411
+ ] : [
412
+ "_formId: string;",
413
+ "_content: unknown;",
414
+ "_formSchema: unknown;",
415
+ "_attachments: StorageItemType[];"
416
+ ],
417
+ ...cols.map((col) => renderColumnField(col)),
418
+ ...table.enableForm ? ["formSchema: FormValidationRules;"] : []
419
+ ]);
420
+ const createType = renderTypeBlock(`${name}CreateInput`, [
421
+ ...!table.isSubmissions ? [
422
+ "group?: string | null;",
423
+ "publishedAt?: string | null;",
424
+ "scheduledPublishAt?: string | null;",
425
+ "scheduledUnpublishAt?: string | null;",
426
+ "createdAt?: string;"
427
+ ] : [],
428
+ ...cols.map(
429
+ (col) => renderColumnField(col, {
430
+ optional: !col.required,
431
+ suffix: "CreateInput"
432
+ })
433
+ ),
434
+ ...table.enableForm ? ["formSchema: FormValidationRules;"] : []
435
+ ]);
436
+ const updateType = renderTypeBlock(`${name}UpdateInput`, [
437
+ ...cols.filter((col) => !col.readOnly).map(
438
+ (col) => renderColumnField(col, { optional: true, suffix: "UpdateInput" })
439
+ ),
440
+ ...!table.isSubmissions ? [
441
+ "publishedAt?: string | null;",
442
+ "scheduledPublishAt?: string | null;",
443
+ "scheduledUnpublishAt?: string | null;",
444
+ "createdAt?: string;"
445
+ ] : [],
446
+ ...table.enableForm ? ["formSchema: FormValidationRules;"] : []
447
+ ]);
448
+ return [rowType, createType, updateType].join("\n\n");
449
+ }
450
+ function renderModuleTypes(mod) {
451
+ const name = toCodeTypeName(mod.name);
452
+ const cols = mod.columns;
453
+ const rowType = renderModuleRowTypeBlock(mod);
454
+ const createType = renderTypeBlock(`${name}CreateInput`, [
455
+ ...cols.map(
456
+ (col) => renderColumnField(col, {
457
+ optional: !col.required,
458
+ suffix: "CreateInput"
459
+ })
460
+ )
461
+ ]);
462
+ const updateType = renderTypeBlock(`${name}UpdateInput`, [
463
+ "id?: string;",
464
+ ...cols.map((col) => renderColumnField(col, { optional: !col.required }))
465
+ ]);
466
+ return [rowType, createType, updateType].join("\n\n");
467
+ }
468
+ function renderTableDescriptor(table) {
469
+ const name = toCodeTypeName(table.name);
470
+ return renderTypeBlock(`${name}__Descriptor`, [
471
+ `row: ${name};`,
472
+ `create: ${name}CreateInput;`,
473
+ `update: ${name}UpdateInput;`,
474
+ ...renderRefsFieldLines(table.columns),
475
+ ...renderUniqueFieldLines(table),
476
+ ...table.enableDrafts ? ["enableDrafts: true;"] : [],
477
+ ...table.enableForm ? [`submissionDescriptor: ${name}_Submission__Descriptor;`] : ["submissionDescriptor: never;"]
478
+ ]);
329
479
  }
330
480
  async function renderClient(config) {
331
- return await formatTsWithPrettier(Handlebars.compile(client_ts_default)(config));
481
+ const tableEntries = config.tables.map(
482
+ (t) => `${t.name}: this.client.getTableClient<Models.${toCodeTypeName(t.name)}__Descriptor>("${t.name}"),`
483
+ ).join("\n");
484
+ const bucketEntries = (config.buckets ?? []).map((b) => `${b.name}: this.client.getBucketClient("${b.name}"),`).join("\n");
485
+ const source = `// This file was automatically generated and should not be edited.
486
+
487
+ import { OrizmCMSClient } from "@orizm/cms-sdk";
488
+
489
+ import * as Models from "./types";
490
+
491
+ export class CMSClient {
492
+ constructor(protected client: OrizmCMSClient) {
493
+ this.tables = {
494
+ ${tableEntries}
495
+ };
496
+
497
+ this.buckets = {
498
+ ${bucketEntries}
499
+ };
500
+
501
+ this.userManagement = this.client.userManagement;
502
+
503
+ this.userinfo = this.client.userinfo;
504
+
505
+ this.auth = this.client.auth;
506
+ }
507
+
508
+ readonly tables;
509
+ readonly buckets;
510
+ readonly userManagement;
511
+ readonly userinfo;
512
+ readonly auth;
513
+ }
514
+ `;
515
+ return await formatTsWithPrettier(source);
332
516
  }
333
517
 
334
518
  // src/cms/generate/command.ts
@@ -360,7 +544,7 @@ function assertValidUrlOrigin(origin) {
360
544
  }
361
545
  }
362
546
 
363
- // ../../node_modules/.pnpm/openapi-fetch@0.13.5/node_modules/openapi-fetch/dist/index.js
547
+ // ../../node_modules/.pnpm/openapi-fetch@0.17.0/node_modules/openapi-fetch/dist/index.mjs
364
548
  var PATH_PARAM_RE = /\{[^{}]+\}/g;
365
549
  var supportsRequestInitExt = () => {
366
550
  return typeof process === "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
@@ -375,13 +559,14 @@ function createClient(clientOptions) {
375
559
  fetch: baseFetch = globalThis.fetch,
376
560
  querySerializer: globalQuerySerializer,
377
561
  bodySerializer: globalBodySerializer,
562
+ pathSerializer: globalPathSerializer,
378
563
  headers: baseHeaders,
379
564
  requestInitExt = void 0,
380
565
  ...baseOptions
381
566
  } = { ...clientOptions };
382
567
  requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
383
568
  baseUrl = removeTrailingSlash(baseUrl);
384
- const middlewares = [];
569
+ const globalMiddlewares = [];
385
570
  async function coreFetch(schemaPath, fetchOptions) {
386
571
  const {
387
572
  baseUrl: localBaseUrl,
@@ -392,11 +577,14 @@ function createClient(clientOptions) {
392
577
  parseAs = "json",
393
578
  querySerializer: requestQuerySerializer,
394
579
  bodySerializer = globalBodySerializer ?? defaultBodySerializer,
580
+ pathSerializer: requestPathSerializer,
395
581
  body,
582
+ middleware: requestMiddlewares = [],
396
583
  ...init
397
584
  } = fetchOptions || {};
585
+ let finalBaseUrl = baseUrl;
398
586
  if (localBaseUrl) {
399
- baseUrl = removeTrailingSlash(localBaseUrl);
587
+ finalBaseUrl = removeTrailingSlash(localBaseUrl) ?? baseUrl;
400
588
  }
401
589
  let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
402
590
  if (requestQuerySerializer) {
@@ -405,40 +593,57 @@ function createClient(clientOptions) {
405
593
  ...requestQuerySerializer
406
594
  });
407
595
  }
408
- const serializedBody = body === void 0 ? void 0 : bodySerializer(body);
409
- const defaultHeaders = (
596
+ const pathSerializer = requestPathSerializer || globalPathSerializer || defaultPathSerializer;
597
+ const serializedBody = body === void 0 ? void 0 : bodySerializer(
598
+ body,
599
+ // Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
600
+ // bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
601
+ // the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
602
+ // setting the content-type at the very beginning to be overwritten.
603
+ // Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
604
+ mergeHeaders(baseHeaders, headers, params.header)
605
+ );
606
+ const finalHeaders = mergeHeaders(
410
607
  // with no body, we should not to set Content-Type
411
608
  serializedBody === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
412
609
  serializedBody instanceof FormData ? {} : {
413
610
  "Content-Type": "application/json"
414
- }
611
+ },
612
+ baseHeaders,
613
+ headers,
614
+ params.header
415
615
  );
616
+ const finalMiddlewares = [...globalMiddlewares, ...requestMiddlewares];
416
617
  const requestInit = {
417
618
  redirect: "follow",
418
619
  ...baseOptions,
419
620
  ...init,
420
621
  body: serializedBody,
421
- headers: mergeHeaders(defaultHeaders, baseHeaders, headers, params.header)
622
+ headers: finalHeaders
422
623
  };
423
624
  let id;
424
625
  let options;
425
- let request = new CustomRequest(createFinalURL(schemaPath, { baseUrl, params, querySerializer }), requestInit);
626
+ let request = new Request(
627
+ createFinalURL(schemaPath, { baseUrl: finalBaseUrl, params, querySerializer, pathSerializer }),
628
+ requestInit
629
+ );
426
630
  let response;
427
631
  for (const key in init) {
428
632
  if (!(key in request)) {
429
633
  request[key] = init[key];
430
634
  }
431
635
  }
432
- if (middlewares.length) {
636
+ if (finalMiddlewares.length) {
433
637
  id = randomID();
434
638
  options = Object.freeze({
435
- baseUrl,
639
+ baseUrl: finalBaseUrl,
436
640
  fetch,
437
641
  parseAs,
438
642
  querySerializer,
439
- bodySerializer
643
+ bodySerializer,
644
+ pathSerializer
440
645
  });
441
- for (const m of middlewares) {
646
+ for (const m of finalMiddlewares) {
442
647
  if (m && typeof m === "object" && typeof m.onRequest === "function") {
443
648
  const result = await m.onRequest({
444
649
  request,
@@ -448,7 +653,7 @@ function createClient(clientOptions) {
448
653
  id
449
654
  });
450
655
  if (result) {
451
- if (result instanceof CustomRequest) {
656
+ if (result instanceof Request) {
452
657
  request = result;
453
658
  } else if (result instanceof Response) {
454
659
  response = result;
@@ -463,11 +668,11 @@ function createClient(clientOptions) {
463
668
  if (!response) {
464
669
  try {
465
670
  response = await fetch(request, requestInitExt);
466
- } catch (error3) {
467
- let errorAfterMiddleware = error3;
468
- if (middlewares.length) {
469
- for (let i = middlewares.length - 1; i >= 0; i--) {
470
- const m = middlewares[i];
671
+ } catch (error22) {
672
+ let errorAfterMiddleware = error22;
673
+ if (finalMiddlewares.length) {
674
+ for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
675
+ const m = finalMiddlewares[i];
471
676
  if (m && typeof m === "object" && typeof m.onError === "function") {
472
677
  const result = await m.onError({
473
678
  request,
@@ -496,9 +701,9 @@ function createClient(clientOptions) {
496
701
  throw errorAfterMiddleware;
497
702
  }
498
703
  }
499
- if (middlewares.length) {
500
- for (let i = middlewares.length - 1; i >= 0; i--) {
501
- const m = middlewares[i];
704
+ if (finalMiddlewares.length) {
705
+ for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
706
+ const m = finalMiddlewares[i];
502
707
  if (m && typeof m === "object" && typeof m.onResponse === "function") {
503
708
  const result = await m.onResponse({
504
709
  request,
@@ -518,14 +723,22 @@ function createClient(clientOptions) {
518
723
  }
519
724
  }
520
725
  }
521
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
726
+ const contentLength = response.headers.get("Content-Length");
727
+ if (response.status === 204 || request.method === "HEAD" || contentLength === "0" && !response.headers.get("Transfer-Encoding")?.includes("chunked")) {
522
728
  return response.ok ? { data: void 0, response } : { error: void 0, response };
523
729
  }
524
730
  if (response.ok) {
525
- if (parseAs === "stream") {
526
- return { data: response.body, response };
527
- }
528
- return { data: await response[parseAs](), response };
731
+ const getResponseData = async () => {
732
+ if (parseAs === "stream") {
733
+ return response.body;
734
+ }
735
+ if (parseAs === "json" && !contentLength) {
736
+ const raw = await response.text();
737
+ return raw ? JSON.parse(raw) : void 0;
738
+ }
739
+ return await response[parseAs]();
740
+ };
741
+ return { data: await getResponseData(), response };
529
742
  }
530
743
  let error2 = await response.text();
531
744
  try {
@@ -579,15 +792,15 @@ function createClient(clientOptions) {
579
792
  if (typeof m !== "object" || !("onRequest" in m || "onResponse" in m || "onError" in m)) {
580
793
  throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
581
794
  }
582
- middlewares.push(m);
795
+ globalMiddlewares.push(m);
583
796
  }
584
797
  },
585
798
  /** Unregister middleware */
586
799
  eject(...middleware) {
587
800
  for (const m of middleware) {
588
- const i = middlewares.indexOf(m);
801
+ const i = globalMiddlewares.indexOf(m);
589
802
  if (i !== -1) {
590
- middlewares.splice(i, 1);
803
+ globalMiddlewares.splice(i, 1);
591
804
  }
592
805
  }
593
806
  }
@@ -753,16 +966,22 @@ function defaultPathSerializer(pathname, pathParams) {
753
966
  }
754
967
  return nextURL;
755
968
  }
756
- function defaultBodySerializer(body) {
969
+ function defaultBodySerializer(body, headers) {
757
970
  if (body instanceof FormData) {
758
971
  return body;
759
972
  }
973
+ if (headers) {
974
+ const contentType = headers.get instanceof Function ? headers.get("Content-Type") ?? headers.get("content-type") : headers["Content-Type"] ?? headers["content-type"];
975
+ if (contentType === "application/x-www-form-urlencoded") {
976
+ return new URLSearchParams(body).toString();
977
+ }
978
+ }
760
979
  return JSON.stringify(body);
761
980
  }
762
981
  function createFinalURL(pathname, options) {
763
982
  let finalURL = `${options.baseUrl}${pathname}`;
764
983
  if (options.params?.path) {
765
- finalURL = defaultPathSerializer(finalURL, options.params.path);
984
+ finalURL = options.pathSerializer(finalURL, options.params.path);
766
985
  }
767
986
  let search = options.querySerializer(options.params.query ?? {});
768
987
  if (search.startsWith("?")) {
@@ -950,16 +1169,6 @@ var import_commander3 = require("commander");
950
1169
  // src/consumer/pull/generate.ts
951
1170
  var import_promises3 = require("fs/promises");
952
1171
  var import_path2 = __toESM(require("path"), 1);
953
- var import_handlebars2 = __toESM(require("handlebars"), 1);
954
-
955
- // src/consumer/templates/client.ts.hbr
956
- var client_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { ConsumerClientOptions, OrizmConsumerClientBase } from "@orizm/consumer-sdk";\nimport * as Models from "./types";\n\nexport class OrizmClient extends OrizmConsumerClientBase {\n constructor(options: ConsumerClientOptions) {\n super(options);\n }\n\n readonly tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n}\n';
957
-
958
- // src/consumer/templates/types.ts.hbr
959
- var types_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/consumer-sdk/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n group: string | null;\n publishedAt: string | null;\n _draft: boolean | null;\n _published: boolean | null;\n {{#each this.columns}}\n {{this.name}}: {{typeName this}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n}\n\n{{/each}}\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n {{#each this.columns}}\n {{this.name}}: {{typeName this}}{{#unless this.required}}{{#if_equal this.type "module-array"}}{{else}} | null{{/if_equal}}{{/unless}};\n {{/each}}\n};\n\n{{/each}}\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}}{{#unless this.required}}{{#if ../this.nullsNotDistinct}} | null{{/if}}{{/unless}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n};\n\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\n\ntype WebhookPayloadBase = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n};\n\n{{#if tables}}\nexport type WebhookPayload = WebhookPayloadBase & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n);\n{{else}}\nexport type WebhookPayload = WebhookPayloadBase;\n{{/if}}\n';
960
-
961
- // src/consumer/pull/generate.ts
962
- var Handlebars2 = import_handlebars2.default.create();
963
1172
  async function generate2(options) {
964
1173
  await (0, import_promises3.mkdir)(options.output, { recursive: true });
965
1174
  const renderedTypes = await renderTypes2(options.definition);
@@ -969,80 +1178,63 @@ async function generate2(options) {
969
1178
  const targetClientPath = import_path2.default.join(options.output, "client.ts");
970
1179
  await (0, import_promises3.writeFile)(targetClientPath, renderedClient, "utf-8");
971
1180
  }
972
- Handlebars2.registerHelper("toEndpointName", (str) => {
973
- return str;
974
- });
975
- function toCodeTypeName2(str) {
976
- str = str.charAt(0).toUpperCase() + str.slice(1);
977
- return str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
978
- }
979
- Handlebars2.registerHelper("toCodeTypeName", toCodeTypeName2);
980
- Handlebars2.registerHelper("typeName", (column) => {
981
- if (column.type === "reference") {
982
- return "string";
983
- } else if (column.type === "json") {
984
- return "unknown";
985
- } else if (column.type === "module") {
986
- if (!column.moduleName) {
987
- console.warn("moduleName is not defined", column.name);
988
- }
989
- return toCodeTypeName2(column.moduleName || "unknown");
990
- } else if (column.type === "module-array") {
991
- if (!column.moduleName) {
992
- console.warn("moduleName is not defined", column.name);
993
- }
994
- return toCodeTypeName2(column.moduleName || "unknown") + "[]";
995
- } else if (column.type === "storage") {
996
- return "StorageItemType";
997
- } else {
998
- return column.type;
999
- }
1000
- });
1001
- Handlebars2.registerHelper(
1002
- "filterRefColumn",
1003
- (columns) => {
1004
- return (columns ?? []).filter(
1005
- (c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
1006
- );
1007
- }
1008
- );
1009
- Handlebars2.registerHelper("includeName", (column) => {
1010
- return column.type === "reference" ? column.includeName : column.name;
1011
- });
1012
- Handlebars2.registerHelper("includeType", (column) => {
1013
- if (column.type === "reference" && column.tableName)
1014
- return toCodeTypeName2(column.tableName) + "__Descriptor";
1015
- if (column.type === "module" && column.moduleName)
1016
- return `_ModuleRef<${toCodeTypeName2(column.moduleName)}__Descriptor>`;
1017
- if (column.type === "module-array" && column.moduleName)
1018
- return `_ArrayModuleRef<${toCodeTypeName2(column.moduleName)}__Descriptor>`;
1019
- });
1020
- Handlebars2.registerHelper(
1021
- "filterUniqueIndexes",
1022
- (indexes) => {
1023
- return (indexes ?? []).filter((i) => i.unique);
1024
- }
1025
- );
1026
- Handlebars2.registerHelper(
1027
- "getIndexColumns",
1028
- (table, index) => {
1029
- return index.columns.map((i) => {
1030
- const column = table.columns.find((c) => c.name === i);
1031
- if (!column) {
1032
- throw new Error(`column ${i} not found`);
1033
- }
1034
- return column;
1035
- });
1036
- }
1037
- );
1038
- Handlebars2.registerHelper("if_equal", function(a, b, options) {
1039
- return a === b ? options.fn(this) : options.inverse(this);
1040
- });
1041
1181
  async function renderTypes2(config) {
1042
- return await formatTsWithPrettier(Handlebars2.compile(types_ts_default2)(config));
1182
+ const tables = config.tables;
1183
+ const modules = config.tableModules ?? [];
1184
+ const source = [
1185
+ renderPreamble("@orizm/consumer-sdk/common"),
1186
+ renderSection("Tables", tables.map(renderTableRowType)),
1187
+ modules.map(renderModuleRowTypeBlock).join("\n\n"),
1188
+ renderSection("Descriptor types", [
1189
+ ...tables.map(renderTableDescriptor2),
1190
+ ...modules.map(renderModuleDescriptorBlock)
1191
+ ]),
1192
+ renderWebhookTypesSection(tables)
1193
+ ].filter(Boolean).join("\n\n\n");
1194
+ return await formatTsWithPrettier(source);
1195
+ }
1196
+ function renderTableRowType(table) {
1197
+ return renderTypeBlock(toCodeTypeName(table.name), [
1198
+ "id: string;",
1199
+ "createdAt: string;",
1200
+ "updatedAt: string;",
1201
+ "group: string | null;",
1202
+ "publishedAt: string | null;",
1203
+ "_draft: boolean | null;",
1204
+ "_published: boolean | null;",
1205
+ ...table.columns.map((col) => renderColumnField(col)),
1206
+ ...table.enableForm ? ["formSchema: FormValidationRules;"] : []
1207
+ ]);
1208
+ }
1209
+ function renderTableDescriptor2(table) {
1210
+ const name = toCodeTypeName(table.name);
1211
+ return renderTypeBlock(`${name}__Descriptor`, [
1212
+ `row: ${name};`,
1213
+ ...renderRefsFieldLines(table.columns),
1214
+ ...renderUniqueFieldLines(table),
1215
+ ...table.enableDrafts ? ["enableDrafts: true;"] : []
1216
+ ]);
1043
1217
  }
1044
1218
  async function renderClient2(config) {
1045
- return await formatTsWithPrettier(Handlebars2.compile(client_ts_default2)(config));
1219
+ const tableEntries = config.tables.map(
1220
+ (t) => `${t.name}: this.getTableClient<Models.${toCodeTypeName(t.name)}__Descriptor>("${t.name}"),`
1221
+ ).join("\n");
1222
+ const source = `// This file was automatically generated and should not be edited.
1223
+
1224
+ import { ConsumerClientOptions, OrizmConsumerClientBase } from "@orizm/consumer-sdk";
1225
+ import * as Models from "./types";
1226
+
1227
+ export class OrizmClient extends OrizmConsumerClientBase {
1228
+ constructor(options: ConsumerClientOptions) {
1229
+ super(options);
1230
+ }
1231
+
1232
+ readonly tables = {
1233
+ ${tableEntries}
1234
+ };
1235
+ }
1236
+ `;
1237
+ return await formatTsWithPrettier(source);
1046
1238
  }
1047
1239
 
1048
1240
  // src/consumer/generate/action.ts
@@ -1106,10 +1298,10 @@ var consumerPullCommand = new import_commander4.Command("pull").description("pul
1106
1298
 
1107
1299
  // src/push/command.ts
1108
1300
  var import_commander5 = require("commander");
1109
- var import_cli_color6 = __toESM(require("cli-color"), 1);
1301
+ var import_chalk6 = __toESM(require("chalk"), 1);
1110
1302
 
1111
1303
  // src/lib/developer-api.ts
1112
- var import_cli_color4 = __toESM(require("cli-color"), 1);
1304
+ var import_chalk4 = __toESM(require("chalk"), 1);
1113
1305
  async function applyDefinition(env, projectDef) {
1114
1306
  const client = createDeveloperAPIv2Client({
1115
1307
  serverOrigin: env.ORIZM_BASE_URL,
@@ -1129,7 +1321,7 @@ async function applyDefinition(env, projectDef) {
1129
1321
  );
1130
1322
  }
1131
1323
  if (response.error.type === "bad-request") {
1132
- console.log(import_cli_color4.default.red(response.error.detail));
1324
+ console.log(import_chalk4.default.red(response.error.detail));
1133
1325
  process.exit(1);
1134
1326
  }
1135
1327
  throw new Error(
@@ -1167,7 +1359,7 @@ var getChangeEvents = async (env, projectDef) => {
1167
1359
  };
1168
1360
 
1169
1361
  // src/lib/display-change-events.ts
1170
- var import_cli_color5 = __toESM(require("cli-color"), 1);
1362
+ var import_chalk5 = __toESM(require("chalk"), 1);
1171
1363
 
1172
1364
  // src/lib/cli-table.ts
1173
1365
  var COLORS = {
@@ -1276,7 +1468,7 @@ function displayChangeEvents(changeEvents) {
1276
1468
  } = changeEvents;
1277
1469
  if (tableChangeEvents.length === 0 && bucketChangeEvents.length === 0 && authorityChangeEvents.length === 0) {
1278
1470
  console.log();
1279
- console.log(import_cli_color5.default.green("No changes."));
1471
+ console.log(import_chalk5.default.green("No changes."));
1280
1472
  return;
1281
1473
  }
1282
1474
  displayTableChangeEvents(tableChangeEvents);
@@ -1562,7 +1754,7 @@ var pushCommand = new import_commander5.Command("push").description("apply schem
1562
1754
  if (!options.yes) {
1563
1755
  const confirm = await input("Do you want to apply schema? (y/N): ");
1564
1756
  if (confirm !== "y") {
1565
- console.log(import_cli_color6.default.red("Canceled."));
1757
+ console.log(import_chalk6.default.red("Canceled."));
1566
1758
  return;
1567
1759
  }
1568
1760
  }
@@ -1577,7 +1769,7 @@ var pushCommand = new import_commander5.Command("push").description("apply schem
1577
1769
 
1578
1770
  // src/config/validate/command.ts
1579
1771
  var import_commander6 = require("commander");
1580
- var import_cli_color7 = __toESM(require("cli-color"), 1);
1772
+ var import_chalk7 = __toESM(require("chalk"), 1);
1581
1773
  var v5 = __toESM(require("valibot"), 1);
1582
1774
 
1583
1775
  // src/config/validate/watcher.ts
@@ -1633,10 +1825,10 @@ var validateConfigCommand = new import_commander6.Command("validate").descriptio
1633
1825
  console.log();
1634
1826
  }
1635
1827
  await loadConfig(options.config);
1636
- console.log(import_cli_color7.default.green("\u2705 Config is valid."));
1828
+ console.log(import_chalk7.default.green("\u2705 Config is valid."));
1637
1829
  } catch (error2) {
1638
1830
  if (v5.isValiError(error2)) {
1639
- console.error(import_cli_color7.default.red("\u274C Config validation failed:"));
1831
+ console.error(import_chalk7.default.red("\u274C Config validation failed:"));
1640
1832
  displayValibotError(error2);
1641
1833
  return;
1642
1834
  }
@@ -1656,16 +1848,27 @@ var validateConfigCommand = new import_commander6.Command("validate").descriptio
1656
1848
  var import_commander7 = require("commander");
1657
1849
 
1658
1850
  // src/config/generate-erd/generate.ts
1659
- var import_handlebars3 = __toESM(require("handlebars"), 1);
1851
+ function generate3(input2) {
1852
+ const tables = input2.tables.map((table) => {
1853
+ const columns = [
1854
+ " id string PK",
1855
+ ...table.columns.map(
1856
+ (col) => ` ${col.name} ${col.type}${col.isForeignKey ? " FK" : ""}`
1857
+ )
1858
+ ].join("\n");
1859
+ return ` ${table.name} {
1860
+ ${columns}
1861
+ }`;
1862
+ }).join("\n");
1863
+ const relations = input2.relations.map((rel) => ` ${rel.from} ${rel.type} ${rel.to} : ${rel.comment}`).join("\n");
1864
+ return `generated by @orizm/cli
1660
1865
 
1661
- // src/config/generate-erd/mermaid-erd.hbr
1662
- var mermaid_erd_default = "generated by @orizm/cli\n\n```mermaid\nerDiagram\n{{#each tables}}\n {{name}} {\n id string PK\n{{#each columns}}\n {{name}} {{type}}{{#if isForeignKey}} FK{{/if}}\n{{/each}}\n }\n{{/each}}\n\n{{#each relations}}\n {{from}} {{type}} {{to}} : {{comment}}\n{{/each}}\n```";
1866
+ \`\`\`mermaid
1867
+ erDiagram
1868
+ ${tables}
1663
1869
 
1664
- // src/config/generate-erd/generate.ts
1665
- var Handlebars3 = import_handlebars3.default.create();
1666
- function generate3(input2) {
1667
- const template = Handlebars3.compile(mermaid_erd_default);
1668
- return template(input2);
1870
+ ${relations}
1871
+ \`\`\``;
1669
1872
  }
1670
1873
 
1671
1874
  // src/config/generate-erd/convert-to-input.ts