kysely-gen 0.5.1 → 0.6.1
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.js +58 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -44402,7 +44402,7 @@ function canMap(obj, opt) {
|
|
|
44402
44402
|
}
|
|
44403
44403
|
|
|
44404
44404
|
// src/cli.ts
|
|
44405
|
-
import { writeFile } from "fs/promises";
|
|
44405
|
+
import { readFile, writeFile } from "fs/promises";
|
|
44406
44406
|
import { resolve } from "path";
|
|
44407
44407
|
|
|
44408
44408
|
// src/ast/serialize.ts
|
|
@@ -44615,10 +44615,11 @@ function serialize(program2) {
|
|
|
44615
44615
|
// src/transform/filter.ts
|
|
44616
44616
|
var import_micromatch = __toESM(require_micromatch(), 1);
|
|
44617
44617
|
function filterTables(tables, options) {
|
|
44618
|
+
const nonPartitionTables = tables.filter((t) => !t.isPartition);
|
|
44618
44619
|
if (!options || !options.includePattern && !options.excludePattern) {
|
|
44619
|
-
return
|
|
44620
|
+
return nonPartitionTables;
|
|
44620
44621
|
}
|
|
44621
|
-
return
|
|
44622
|
+
return nonPartitionTables.filter((table) => {
|
|
44622
44623
|
const tablePattern = `${table.schema}.${table.name}`;
|
|
44623
44624
|
if (options.excludePattern && options.excludePattern.length > 0) {
|
|
44624
44625
|
if (import_micromatch.default.isMatch(tablePattern, options.excludePattern)) {
|
|
@@ -45095,10 +45096,13 @@ function mapPostgresType(dataType, options) {
|
|
|
45095
45096
|
if (isArray || dataType.endsWith("[]")) {
|
|
45096
45097
|
const baseTypeName = dataType.endsWith("[]") ? dataType.slice(0, -2) : dataType;
|
|
45097
45098
|
const elementType = mapPostgresType(baseTypeName, { isNullable: false, isArray: false, unknownTypes });
|
|
45098
|
-
const
|
|
45099
|
-
|
|
45100
|
-
|
|
45101
|
-
|
|
45099
|
+
const isSimple = elementType.kind === "primitive" && ["boolean", "number", "string"].includes(elementType.value);
|
|
45100
|
+
let arrayType;
|
|
45101
|
+
if (isSimple) {
|
|
45102
|
+
arrayType = { kind: "array", elementType };
|
|
45103
|
+
} else {
|
|
45104
|
+
arrayType = { kind: "generic", name: "ArrayType", typeArguments: [elementType] };
|
|
45105
|
+
}
|
|
45102
45106
|
if (isNullable) {
|
|
45103
45107
|
return {
|
|
45104
45108
|
kind: "union",
|
|
@@ -45760,6 +45764,28 @@ function transformDatabase(metadata, options) {
|
|
|
45760
45764
|
},
|
|
45761
45765
|
exported: true
|
|
45762
45766
|
});
|
|
45767
|
+
declarations.push({
|
|
45768
|
+
kind: "typeAlias",
|
|
45769
|
+
name: "ArrayType<T>",
|
|
45770
|
+
type: {
|
|
45771
|
+
kind: "raw",
|
|
45772
|
+
value: `ArrayTypeImpl<T> extends (infer U)[]
|
|
45773
|
+
? U[]
|
|
45774
|
+
: ArrayTypeImpl<T>`
|
|
45775
|
+
},
|
|
45776
|
+
exported: true
|
|
45777
|
+
});
|
|
45778
|
+
declarations.push({
|
|
45779
|
+
kind: "typeAlias",
|
|
45780
|
+
name: "ArrayTypeImpl<T>",
|
|
45781
|
+
type: {
|
|
45782
|
+
kind: "raw",
|
|
45783
|
+
value: `T extends ColumnType<infer S, infer I, infer U>
|
|
45784
|
+
? ColumnType<S[], I[], U[]>
|
|
45785
|
+
: T[]`
|
|
45786
|
+
},
|
|
45787
|
+
exported: true
|
|
45788
|
+
});
|
|
45763
45789
|
declarations.push({
|
|
45764
45790
|
kind: "typeAlias",
|
|
45765
45791
|
name: "JsonPrimitive",
|
|
@@ -45912,7 +45938,7 @@ function detectDialect(connectionString) {
|
|
|
45912
45938
|
|
|
45913
45939
|
// src/cli.ts
|
|
45914
45940
|
var program2 = new Command;
|
|
45915
|
-
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) => {
|
|
45941
|
+
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").option("--verify", "Verify types match existing file (exit 1 if different)").action(async (options) => {
|
|
45916
45942
|
try {
|
|
45917
45943
|
await generate(options);
|
|
45918
45944
|
} catch (error2) {
|
|
@@ -45931,6 +45957,10 @@ function collect(value, previous) {
|
|
|
45931
45957
|
async function generate(options) {
|
|
45932
45958
|
const printMode = options.print === true;
|
|
45933
45959
|
const log = printMode ? (...args) => console.error(...args) : (...args) => console.log(...args);
|
|
45960
|
+
if (options.verify && options.print) {
|
|
45961
|
+
console.error(source_default.red("Error: Cannot use --verify with --print"));
|
|
45962
|
+
process.exit(1);
|
|
45963
|
+
}
|
|
45934
45964
|
const databaseUrl = options.url || process.env.DATABASE_URL;
|
|
45935
45965
|
if (!databaseUrl) {
|
|
45936
45966
|
console.error(source_default.red("Error: DATABASE_URL environment variable is required"));
|
|
@@ -46002,6 +46032,26 @@ async function generate(options) {
|
|
|
46002
46032
|
excludePattern: options.excludePattern.length > 0 ? options.excludePattern : undefined
|
|
46003
46033
|
});
|
|
46004
46034
|
const code = serialize(astProgram);
|
|
46035
|
+
if (options.verify) {
|
|
46036
|
+
const absolutePath = resolve(outputPath);
|
|
46037
|
+
const existing = await readFile(absolutePath, "utf-8").catch(() => null);
|
|
46038
|
+
if (existing === null) {
|
|
46039
|
+
spinner.fail(`File not found: ${source_default.cyan(absolutePath)}`);
|
|
46040
|
+
await db.destroy();
|
|
46041
|
+
process.exit(1);
|
|
46042
|
+
}
|
|
46043
|
+
if (existing === code) {
|
|
46044
|
+
spinner.succeed("Types are up-to-date");
|
|
46045
|
+
await db.destroy();
|
|
46046
|
+
process.exit(0);
|
|
46047
|
+
}
|
|
46048
|
+
spinner.fail("Types are out of date");
|
|
46049
|
+
log("");
|
|
46050
|
+
log(source_default.yellow("Generated types differ from existing file."));
|
|
46051
|
+
log(source_default.dim("Run kysely-gen to update."));
|
|
46052
|
+
await db.destroy();
|
|
46053
|
+
process.exit(1);
|
|
46054
|
+
}
|
|
46005
46055
|
if (printMode) {
|
|
46006
46056
|
spinner.succeed("Types generated");
|
|
46007
46057
|
process.stdout.write(code);
|