@zenstackhq/sdk 3.0.0-beta.17 → 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.js CHANGED
@@ -1134,12 +1134,16 @@ var TsSchemaGenerator = class {
1134
1134
  relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
1135
1135
  }
1136
1136
  const relation = getAttribute(field, "@relation");
1137
+ const fkFields = [];
1137
1138
  if (relation) {
1138
1139
  for (const arg of relation.args) {
1139
1140
  const param = arg.$resolvedParam.name;
1140
1141
  if (param === "fields" || param === "references") {
1141
1142
  const fieldNames = this.getReferenceNames(arg.value);
1142
1143
  if (fieldNames) {
1144
+ if (param === "fields") {
1145
+ fkFields.push(...fieldNames);
1146
+ }
1143
1147
  relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
1144
1148
  }
1145
1149
  }
@@ -1149,6 +1153,15 @@ var TsSchemaGenerator = class {
1149
1153
  }
1150
1154
  }
1151
1155
  }
1156
+ if (fkFields.length > 0) {
1157
+ const allHaveDefault = fkFields.every((fieldName) => {
1158
+ const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
1159
+ return fieldDef && hasAttribute(fieldDef, "@default");
1160
+ });
1161
+ if (allHaveDefault) {
1162
+ relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
1163
+ }
1164
+ }
1152
1165
  return ts.factory.createObjectLiteralExpression(relationFields);
1153
1166
  }
1154
1167
  getReferenceNames(expr) {