@danielhritcu/zenstack-custom 1.2.0 → 1.2.2
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 +37 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +7 -3
- package/dist/cli.d.ts +7 -3
- package/dist/cli.js +37 -8
- package/dist/cli.js.map +1 -1
- package/dist/codegen/index.cjs +14 -2
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.d.cts +5 -3
- package/dist/codegen/index.d.ts +5 -3
- package/dist/codegen/index.js +14 -2
- package/dist/codegen/index.js.map +1 -1
- package/dist/{config-CRQer7hw.d.cts → config-rukOeRbn.d.cts} +3 -1
- package/dist/{config-CRQer7hw.d.ts → config-rukOeRbn.d.ts} +3 -1
- package/dist/index.cjs +14 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1994,7 +1994,7 @@ function unfoldRelationSelector(relation) {
|
|
|
1994
1994
|
return relationName;
|
|
1995
1995
|
}
|
|
1996
1996
|
__name(unfoldRelationSelector, "unfoldRelationSelector");
|
|
1997
|
-
function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}) {
|
|
1997
|
+
function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}, options = {}) {
|
|
1998
1998
|
const baseTables = tables.filter((table) => !table.derivedFrom);
|
|
1999
1999
|
const sqlToBaseTable = /* @__PURE__ */ new Map();
|
|
2000
2000
|
const modelToTable = /* @__PURE__ */ new Map();
|
|
@@ -2083,7 +2083,19 @@ function buildRelations(tables, relationTargets = {}, filteredRelations = {}, th
|
|
|
2083
2083
|
if (!targetTable) continue;
|
|
2084
2084
|
const signature = makePhysicalFKSignature(table, targetTable, fk);
|
|
2085
2085
|
if (declaredFKRelations.has(signature)) continue;
|
|
2086
|
-
|
|
2086
|
+
const ignoreCols = options.ignoreCompositeFkColumns ?? [];
|
|
2087
|
+
if (ignoreCols.length > 0 && fk.localColumns.length > 1) {
|
|
2088
|
+
const strippedFk = {
|
|
2089
|
+
...fk,
|
|
2090
|
+
localColumns: fk.localColumns.filter((c) => !ignoreCols.includes(c)),
|
|
2091
|
+
foreignColumns: fk.foreignColumns.filter((_, i) => !ignoreCols.includes(fk.localColumns[i]))
|
|
2092
|
+
};
|
|
2093
|
+
if (strippedFk.localColumns.length > 0) {
|
|
2094
|
+
const strippedSig = makePhysicalFKSignature(table, targetTable, strippedFk);
|
|
2095
|
+
if (declaredFKRelations.has(strippedSig)) continue;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
console.warn(`Warning: undeclared FK "${table.exportName}": [${fk.localColumns.join(", ")}] -> ${targetTable.exportName}([${fk.foreignColumns.join(", ")}]). Add a relation in orm.config.ts or it will be auto-generated.`);
|
|
2087
2099
|
}
|
|
2088
2100
|
}
|
|
2089
2101
|
const forwardByTarget = /* @__PURE__ */ new Map();
|
|
@@ -2509,7 +2521,7 @@ function resolveConfig(config) {
|
|
|
2509
2521
|
__name(resolveConfig, "resolveConfig");
|
|
2510
2522
|
|
|
2511
2523
|
// src/cli.ts
|
|
2512
|
-
async function runCodegen(config) {
|
|
2524
|
+
async function runCodegen(config, options = {}) {
|
|
2513
2525
|
const resolved = resolveConfig(config);
|
|
2514
2526
|
const outDir = path.resolve(process.cwd(), config.schema.output);
|
|
2515
2527
|
const enumMap = discoverEnums(config.schema.enums);
|
|
@@ -2525,7 +2537,9 @@ async function runCodegen(config) {
|
|
|
2525
2537
|
fieldToTypeDef = artifacts.fieldToTypeDef;
|
|
2526
2538
|
typedJsonFields = artifacts.typedJsonFields;
|
|
2527
2539
|
}
|
|
2528
|
-
const { modelRelations, inverseRelations } = buildRelations(tables, resolved.relationTargets, resolved.filteredRelations, resolved.throughRelations, resolved.fkRelations
|
|
2540
|
+
const { modelRelations, inverseRelations } = buildRelations(tables, resolved.relationTargets, resolved.filteredRelations, resolved.throughRelations, resolved.fkRelations, {
|
|
2541
|
+
ignoreCompositeFkColumns: options.ignoreCompositeFkColumns
|
|
2542
|
+
});
|
|
2529
2543
|
const schemaContent = emitSchemaTs({
|
|
2530
2544
|
tables,
|
|
2531
2545
|
enumMap,
|
|
@@ -2583,16 +2597,31 @@ async function runCodegen(config) {
|
|
|
2583
2597
|
}
|
|
2584
2598
|
__name(runCodegen, "runCodegen");
|
|
2585
2599
|
async function main() {
|
|
2586
|
-
const
|
|
2587
|
-
const
|
|
2600
|
+
const args = process.argv.slice(2);
|
|
2601
|
+
const flags = {};
|
|
2602
|
+
const positional = [];
|
|
2603
|
+
for (const arg of args) {
|
|
2604
|
+
if (arg.startsWith("--")) {
|
|
2605
|
+
const [key, ...rest] = arg.slice(2).split("=");
|
|
2606
|
+
flags[key] = rest.join("=") || "true";
|
|
2607
|
+
} else {
|
|
2608
|
+
positional.push(arg);
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
const subcommand = positional[0];
|
|
2612
|
+
const filePath = positional[1];
|
|
2588
2613
|
if (subcommand !== "generate" || !filePath) {
|
|
2589
|
-
console.error("Usage: zenstack-custom generate <config-file>");
|
|
2614
|
+
console.error("Usage: zenstack-custom generate <config-file> [--ignore-cfk=col1,col2]");
|
|
2590
2615
|
process.exit(1);
|
|
2591
2616
|
}
|
|
2617
|
+
const codegenOptions = {};
|
|
2618
|
+
if (flags["ignore-cfk"]) {
|
|
2619
|
+
codegenOptions.ignoreCompositeFkColumns = flags["ignore-cfk"].split(",").map((s) => s.trim());
|
|
2620
|
+
}
|
|
2592
2621
|
const resolvedPath = path.resolve(process.cwd(), filePath);
|
|
2593
2622
|
const mod = await import(resolvedPath);
|
|
2594
2623
|
const config = mod.default ?? mod;
|
|
2595
|
-
await runCodegen(config);
|
|
2624
|
+
await runCodegen(config, codegenOptions);
|
|
2596
2625
|
}
|
|
2597
2626
|
__name(main, "main");
|
|
2598
2627
|
var isCLI = process.argv[1]?.endsWith("cli.js") || process.argv[1]?.endsWith("cli.cjs");
|