@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.d.cts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Z as ZenConfig } from './config-
|
|
2
|
+
import { Z as ZenConfig } from './config-rukOeRbn.cjs';
|
|
3
3
|
import 'drizzle-orm/pg-core';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface CodegenOptions {
|
|
6
|
+
/** SQL column names to ignore when matching composite FK signatures (e.g. 'app_slug' for RLS) */
|
|
7
|
+
ignoreCompositeFkColumns?: string[];
|
|
8
|
+
}
|
|
9
|
+
declare function runCodegen(config: ZenConfig, options?: CodegenOptions): Promise<void>;
|
|
6
10
|
|
|
7
|
-
export { runCodegen };
|
|
11
|
+
export { type CodegenOptions, runCodegen };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Z as ZenConfig } from './config-
|
|
2
|
+
import { Z as ZenConfig } from './config-rukOeRbn.js';
|
|
3
3
|
import 'drizzle-orm/pg-core';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface CodegenOptions {
|
|
6
|
+
/** SQL column names to ignore when matching composite FK signatures (e.g. 'app_slug' for RLS) */
|
|
7
|
+
ignoreCompositeFkColumns?: string[];
|
|
8
|
+
}
|
|
9
|
+
declare function runCodegen(config: ZenConfig, options?: CodegenOptions): Promise<void>;
|
|
6
10
|
|
|
7
|
-
export { runCodegen };
|
|
11
|
+
export { type CodegenOptions, runCodegen };
|
package/dist/cli.js
CHANGED
|
@@ -1962,7 +1962,7 @@ function unfoldRelationSelector(relation) {
|
|
|
1962
1962
|
return relationName;
|
|
1963
1963
|
}
|
|
1964
1964
|
__name(unfoldRelationSelector, "unfoldRelationSelector");
|
|
1965
|
-
function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}) {
|
|
1965
|
+
function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}, options = {}) {
|
|
1966
1966
|
const baseTables = tables.filter((table) => !table.derivedFrom);
|
|
1967
1967
|
const sqlToBaseTable = /* @__PURE__ */ new Map();
|
|
1968
1968
|
const modelToTable = /* @__PURE__ */ new Map();
|
|
@@ -2051,7 +2051,19 @@ function buildRelations(tables, relationTargets = {}, filteredRelations = {}, th
|
|
|
2051
2051
|
if (!targetTable) continue;
|
|
2052
2052
|
const signature = makePhysicalFKSignature(table, targetTable, fk);
|
|
2053
2053
|
if (declaredFKRelations.has(signature)) continue;
|
|
2054
|
-
|
|
2054
|
+
const ignoreCols = options.ignoreCompositeFkColumns ?? [];
|
|
2055
|
+
if (ignoreCols.length > 0 && fk.localColumns.length > 1) {
|
|
2056
|
+
const strippedFk = {
|
|
2057
|
+
...fk,
|
|
2058
|
+
localColumns: fk.localColumns.filter((c) => !ignoreCols.includes(c)),
|
|
2059
|
+
foreignColumns: fk.foreignColumns.filter((_, i) => !ignoreCols.includes(fk.localColumns[i]))
|
|
2060
|
+
};
|
|
2061
|
+
if (strippedFk.localColumns.length > 0) {
|
|
2062
|
+
const strippedSig = makePhysicalFKSignature(table, targetTable, strippedFk);
|
|
2063
|
+
if (declaredFKRelations.has(strippedSig)) continue;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
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.`);
|
|
2055
2067
|
}
|
|
2056
2068
|
}
|
|
2057
2069
|
const forwardByTarget = /* @__PURE__ */ new Map();
|
|
@@ -2477,7 +2489,7 @@ function resolveConfig(config) {
|
|
|
2477
2489
|
__name(resolveConfig, "resolveConfig");
|
|
2478
2490
|
|
|
2479
2491
|
// src/cli.ts
|
|
2480
|
-
async function runCodegen(config) {
|
|
2492
|
+
async function runCodegen(config, options = {}) {
|
|
2481
2493
|
const resolved = resolveConfig(config);
|
|
2482
2494
|
const outDir = path.resolve(process.cwd(), config.schema.output);
|
|
2483
2495
|
const enumMap = discoverEnums(config.schema.enums);
|
|
@@ -2493,7 +2505,9 @@ async function runCodegen(config) {
|
|
|
2493
2505
|
fieldToTypeDef = artifacts.fieldToTypeDef;
|
|
2494
2506
|
typedJsonFields = artifacts.typedJsonFields;
|
|
2495
2507
|
}
|
|
2496
|
-
const { modelRelations, inverseRelations } = buildRelations(tables, resolved.relationTargets, resolved.filteredRelations, resolved.throughRelations, resolved.fkRelations
|
|
2508
|
+
const { modelRelations, inverseRelations } = buildRelations(tables, resolved.relationTargets, resolved.filteredRelations, resolved.throughRelations, resolved.fkRelations, {
|
|
2509
|
+
ignoreCompositeFkColumns: options.ignoreCompositeFkColumns
|
|
2510
|
+
});
|
|
2497
2511
|
const schemaContent = emitSchemaTs({
|
|
2498
2512
|
tables,
|
|
2499
2513
|
enumMap,
|
|
@@ -2551,16 +2565,31 @@ async function runCodegen(config) {
|
|
|
2551
2565
|
}
|
|
2552
2566
|
__name(runCodegen, "runCodegen");
|
|
2553
2567
|
async function main() {
|
|
2554
|
-
const
|
|
2555
|
-
const
|
|
2568
|
+
const args = process.argv.slice(2);
|
|
2569
|
+
const flags = {};
|
|
2570
|
+
const positional = [];
|
|
2571
|
+
for (const arg of args) {
|
|
2572
|
+
if (arg.startsWith("--")) {
|
|
2573
|
+
const [key, ...rest] = arg.slice(2).split("=");
|
|
2574
|
+
flags[key] = rest.join("=") || "true";
|
|
2575
|
+
} else {
|
|
2576
|
+
positional.push(arg);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
const subcommand = positional[0];
|
|
2580
|
+
const filePath = positional[1];
|
|
2556
2581
|
if (subcommand !== "generate" || !filePath) {
|
|
2557
|
-
console.error("Usage: zenstack-custom generate <config-file>");
|
|
2582
|
+
console.error("Usage: zenstack-custom generate <config-file> [--ignore-cfk=col1,col2]");
|
|
2558
2583
|
process.exit(1);
|
|
2559
2584
|
}
|
|
2585
|
+
const codegenOptions = {};
|
|
2586
|
+
if (flags["ignore-cfk"]) {
|
|
2587
|
+
codegenOptions.ignoreCompositeFkColumns = flags["ignore-cfk"].split(",").map((s) => s.trim());
|
|
2588
|
+
}
|
|
2560
2589
|
const resolvedPath = path.resolve(process.cwd(), filePath);
|
|
2561
2590
|
const mod = await import(resolvedPath);
|
|
2562
2591
|
const config = mod.default ?? mod;
|
|
2563
|
-
await runCodegen(config);
|
|
2592
|
+
await runCodegen(config, codegenOptions);
|
|
2564
2593
|
}
|
|
2565
2594
|
__name(main, "main");
|
|
2566
2595
|
var isCLI = process.argv[1]?.endsWith("cli.js") || process.argv[1]?.endsWith("cli.cjs");
|