@zenstackhq/sdk 3.0.0-beta.18 → 3.0.0-beta.19

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/index.cjs CHANGED
@@ -1167,12 +1167,16 @@ var TsSchemaGenerator = class {
1167
1167
  relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
1168
1168
  }
1169
1169
  const relation = getAttribute(field, "@relation");
1170
+ const fkFields = [];
1170
1171
  if (relation) {
1171
1172
  for (const arg of relation.args) {
1172
1173
  const param = arg.$resolvedParam.name;
1173
1174
  if (param === "fields" || param === "references") {
1174
1175
  const fieldNames = this.getReferenceNames(arg.value);
1175
1176
  if (fieldNames) {
1177
+ if (param === "fields") {
1178
+ fkFields.push(...fieldNames);
1179
+ }
1176
1180
  relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
1177
1181
  }
1178
1182
  }
@@ -1182,6 +1186,15 @@ var TsSchemaGenerator = class {
1182
1186
  }
1183
1187
  }
1184
1188
  }
1189
+ if (fkFields.length > 0) {
1190
+ const allHaveDefault = fkFields.every((fieldName) => {
1191
+ const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
1192
+ return fieldDef && hasAttribute(fieldDef, "@default");
1193
+ });
1194
+ if (allHaveDefault) {
1195
+ relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
1196
+ }
1197
+ }
1185
1198
  return ts.factory.createObjectLiteralExpression(relationFields);
1186
1199
  }
1187
1200
  getReferenceNames(expr) {