@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.
@@ -92,7 +92,9 @@ declare function defineConfig<T extends Record<string, PgTable>, D extends Recor
92
92
  derived?: D;
93
93
  models: (orm: T & {
94
94
  [K in keyof D]: D[K] extends DerivedModelDescriptor<infer TBase> ? TBase & D[K] : D[K];
95
- }) => Record<string, ModelConfig>;
95
+ }) => {
96
+ [K in keyof T]: ModelConfig;
97
+ };
96
98
  }): ZenConfig;
97
99
 
98
100
  export { type AnyRelation as A, type DerivedField as D, type ExtendedSchema as E, type GlobalConfig as G, type ManyRelation as M, type OneRelation as O, type SchemaConfig as S, type ThroughPath as T, type ZenConfig as Z, type DerivedModelDescriptor as a, type ModelConfig as b, type ModelsOutput as c, type SearchField as d, type SearchProfile as e, type ThroughRelation as f, defineConfig as g };
@@ -92,7 +92,9 @@ declare function defineConfig<T extends Record<string, PgTable>, D extends Recor
92
92
  derived?: D;
93
93
  models: (orm: T & {
94
94
  [K in keyof D]: D[K] extends DerivedModelDescriptor<infer TBase> ? TBase & D[K] : D[K];
95
- }) => Record<string, ModelConfig>;
95
+ }) => {
96
+ [K in keyof T]: ModelConfig;
97
+ };
96
98
  }): ZenConfig;
97
99
 
98
100
  export { type AnyRelation as A, type DerivedField as D, type ExtendedSchema as E, type GlobalConfig as G, type ManyRelation as M, type OneRelation as O, type SchemaConfig as S, type ThroughPath as T, type ZenConfig as Z, type DerivedModelDescriptor as a, type ModelConfig as b, type ModelsOutput as c, type SearchField as d, type SearchProfile as e, type ThroughRelation as f, defineConfig as g };
package/dist/index.cjs CHANGED
@@ -1213,7 +1213,7 @@ function unfoldRelationSelector(relation) {
1213
1213
  return relationName;
1214
1214
  }
1215
1215
  __name(unfoldRelationSelector, "unfoldRelationSelector");
1216
- function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}) {
1216
+ function buildRelations(tables, relationTargets = {}, filteredRelations = {}, throughRelations = {}, fkRelations = {}, options = {}) {
1217
1217
  const baseTables = tables.filter((table) => !table.derivedFrom);
1218
1218
  const sqlToBaseTable = /* @__PURE__ */ new Map();
1219
1219
  const modelToTable = /* @__PURE__ */ new Map();
@@ -1302,7 +1302,19 @@ function buildRelations(tables, relationTargets = {}, filteredRelations = {}, th
1302
1302
  if (!targetTable) continue;
1303
1303
  const signature = makePhysicalFKSignature(table, targetTable, fk);
1304
1304
  if (declaredFKRelations.has(signature)) continue;
1305
- throw new Error(`Missing explicit relation in supabase/schema/relations.ts for "${table.exportName}": [${fk.localColumns.join(", ")}] -> ${targetTable.exportName}([${fk.foreignColumns.join(", ")}]).`);
1305
+ const ignoreCols = options.ignoreCompositeFkColumns ?? [];
1306
+ if (ignoreCols.length > 0 && fk.localColumns.length > 1) {
1307
+ const strippedFk = {
1308
+ ...fk,
1309
+ localColumns: fk.localColumns.filter((c) => !ignoreCols.includes(c)),
1310
+ foreignColumns: fk.foreignColumns.filter((_, i) => !ignoreCols.includes(fk.localColumns[i]))
1311
+ };
1312
+ if (strippedFk.localColumns.length > 0) {
1313
+ const strippedSig = makePhysicalFKSignature(table, targetTable, strippedFk);
1314
+ if (declaredFKRelations.has(strippedSig)) continue;
1315
+ }
1316
+ }
1317
+ 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.`);
1306
1318
  }
1307
1319
  }
1308
1320
  const forwardByTarget = /* @__PURE__ */ new Map();