kysely-gen 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/cli.js +33 -22
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -45874,7 +45874,7 @@ function detectDialect(connectionString) {
45874
45874
 
45875
45875
  // src/cli.ts
45876
45876
  var program2 = new Command;
45877
- program2.name("kysely-gen").description("Generate Kysely types from your database").version("0.1.0").option("-o, --out <path>", "Output file path", "./db.d.ts").option("-s, --schema <name>", "Schema to introspect (can be specified multiple times)", collect, []).option("--url <connection-string>", "Database connection string (overrides DATABASE_URL env)").option("-d, --dialect <name>", "Database dialect (postgres, mysql, sqlite). Auto-detected from URL if not specified").option("--camel-case", "Convert column and table names to camelCase (use with Kysely CamelCasePlugin)").option("--include-pattern <pattern>", "Only include tables matching glob pattern (schema.table format)", collect, []).option("--exclude-pattern <pattern>", "Exclude tables matching glob pattern (schema.table format)", collect, []).action(async (options) => {
45877
+ program2.name("kysely-gen").description("Generate Kysely types from your database").version("0.1.0").option("-o, --out <path>", "Output file path", "./db.d.ts").option("-s, --schema <name>", "Schema to introspect (can be specified multiple times)", collect, []).option("--url <connection-string>", "Database connection string (overrides DATABASE_URL env)").option("-d, --dialect <name>", "Database dialect (postgres, mysql, sqlite). Auto-detected from URL if not specified").option("--camel-case", "Convert column and table names to camelCase (use with Kysely CamelCasePlugin)").option("--include-pattern <pattern>", "Only include tables matching glob pattern (schema.table format)", collect, []).option("--exclude-pattern <pattern>", "Exclude tables matching glob pattern (schema.table format)", collect, []).option("--print", "Output to stdout instead of writing to file").action(async (options) => {
45878
45878
  try {
45879
45879
  await generate(options);
45880
45880
  } catch (error2) {
@@ -45891,6 +45891,8 @@ function collect(value, previous) {
45891
45891
  return previous.concat([value]);
45892
45892
  }
45893
45893
  async function generate(options) {
45894
+ const printMode = options.print === true;
45895
+ const log = printMode ? (...args) => console.error(...args) : (...args) => console.log(...args);
45894
45896
  const databaseUrl = options.url || process.env.DATABASE_URL;
45895
45897
  if (!databaseUrl) {
45896
45898
  console.error(source_default.red("Error: DATABASE_URL environment variable is required"));
@@ -45921,15 +45923,17 @@ async function generate(options) {
45921
45923
  const outputPath = options.out;
45922
45924
  const defaultSchema = dialectName === "sqlite" ? "main" : "public";
45923
45925
  const schemas = options.schema.length > 0 ? options.schema : [defaultSchema];
45924
- console.log("");
45925
- console.log(source_default.bold("kysely-gen") + source_default.dim(" v0.1.0"));
45926
- console.log("");
45927
- console.log(source_default.dim("Dialect:"), dialectName);
45928
- console.log(source_default.dim("Connection:"), maskPassword(databaseUrl));
45929
- console.log(source_default.dim("Schemas:"), schemas.join(", "));
45930
- console.log(source_default.dim("Output:"), resolve(outputPath));
45931
- console.log("");
45932
- const spinner = ora("Connecting to database...").start();
45926
+ log("");
45927
+ log(source_default.bold("kysely-gen") + source_default.dim(" v0.1.0"));
45928
+ log("");
45929
+ log(source_default.dim("Dialect:"), dialectName);
45930
+ log(source_default.dim("Connection:"), maskPassword(databaseUrl));
45931
+ log(source_default.dim("Schemas:"), schemas.join(", "));
45932
+ if (!printMode) {
45933
+ log(source_default.dim("Output:"), resolve(outputPath));
45934
+ }
45935
+ log("");
45936
+ const spinner = ora({ text: "Connecting to database...", stream: printMode ? process.stderr : process.stdout }).start();
45933
45937
  let db;
45934
45938
  try {
45935
45939
  const kyselyDialect = await dialect.createKyselyDialect(databaseUrl);
@@ -45945,9 +45949,9 @@ async function generate(options) {
45945
45949
  const enumCount = metadata.enums.length;
45946
45950
  if (tableCount === 0 && enumCount === 0) {
45947
45951
  spinner.warn("No tables or enums found");
45948
- console.log("");
45949
- console.log(source_default.yellow("\u26A0 Warning: No tables or enums found in the specified schemas."));
45950
- console.log(source_default.dim(" Make sure the schema names are correct and contain tables."));
45952
+ log("");
45953
+ log(source_default.yellow("Warning: No tables or enums found in the specified schemas."));
45954
+ log(source_default.dim(" Make sure the schema names are correct and contain tables."));
45951
45955
  await db.destroy();
45952
45956
  return;
45953
45957
  }
@@ -45960,20 +45964,27 @@ async function generate(options) {
45960
45964
  excludePattern: options.excludePattern.length > 0 ? options.excludePattern : undefined
45961
45965
  });
45962
45966
  const code = serialize(astProgram);
45963
- const absolutePath = resolve(outputPath);
45964
- await writeFile(absolutePath, code, "utf-8");
45965
- spinner.succeed(`Types written to ${source_default.cyan(absolutePath)}`);
45967
+ if (printMode) {
45968
+ spinner.succeed("Types generated");
45969
+ process.stdout.write(code);
45970
+ } else {
45971
+ const absolutePath = resolve(outputPath);
45972
+ await writeFile(absolutePath, code, "utf-8");
45973
+ spinner.succeed(`Types written to ${source_default.cyan(absolutePath)}`);
45974
+ }
45966
45975
  if (warnings.length > 0) {
45967
- console.log("");
45968
- console.log(source_default.yellow("Warnings:"));
45976
+ log("");
45977
+ log(source_default.yellow("Warnings:"));
45969
45978
  for (const w of warnings) {
45970
- console.log(source_default.dim(` Unknown type '${w.pgType}' mapped to 'unknown'`));
45979
+ log(source_default.dim(` Unknown type '${w.pgType}' mapped to 'unknown'`));
45971
45980
  }
45972
45981
  }
45973
45982
  await db.destroy();
45974
- console.log("");
45975
- console.log(source_default.green("Done!"));
45976
- console.log("");
45983
+ if (!printMode) {
45984
+ log("");
45985
+ log(source_default.green("Done!"));
45986
+ log("");
45987
+ }
45977
45988
  }
45978
45989
  function maskPassword(connectionString) {
45979
45990
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely-gen",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Database type generator for Kysely - Supports PostgreSQL, MySQL, and SQLite",
5
5
  "type": "module",
6
6
  "license": "MIT",