@strapi/utils 5.5.2 → 5.6.0

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.mjs CHANGED
@@ -1113,7 +1113,7 @@ const createTransformer = ({ getModel }) => {
1113
1113
  query.where = convertFiltersQueryParams(filters2, schema);
1114
1114
  }
1115
1115
  if (fields2) {
1116
- query.select = convertFieldsQueryParams(fields2);
1116
+ query.select = convertFieldsQueryParams(fields2, schema);
1117
1117
  }
1118
1118
  if (populate2) {
1119
1119
  query.populate = convertPopulateQueryParams(populate2, schema);
@@ -1139,17 +1139,23 @@ const createTransformer = ({ getModel }) => {
1139
1139
  }
1140
1140
  return query;
1141
1141
  };
1142
- const convertFieldsQueryParams = (fields2, depth = 0) => {
1142
+ const convertFieldsQueryParams = (fields2, schema, depth = 0) => {
1143
1143
  if (depth === 0 && fields2 === "*") {
1144
1144
  return void 0;
1145
1145
  }
1146
1146
  if (typeof fields2 === "string") {
1147
1147
  const fieldsValues = fields2.split(",").map((value) => ___default.trim(value));
1148
- return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
1148
+ if (schema?.modelType === "contentType") {
1149
+ return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
1150
+ }
1151
+ return ___default.uniq([ID_ATTRIBUTE$3, ...fieldsValues]);
1149
1152
  }
1150
1153
  if (isStringArray$3(fields2)) {
1151
- const fieldsValues = fields2.flatMap((value) => convertFieldsQueryParams(value, depth + 1)).filter((v) => !isNil(v));
1152
- return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
1154
+ const fieldsValues = fields2.flatMap((value) => convertFieldsQueryParams(value, schema, depth + 1)).filter((v) => !isNil(v));
1155
+ if (schema?.modelType === "contentType") {
1156
+ return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
1157
+ }
1158
+ return ___default.uniq([ID_ATTRIBUTE$3, ...fieldsValues]);
1153
1159
  }
1154
1160
  throw new Error("Invalid fields parameter. Expected a string or an array of strings");
1155
1161
  };
@@ -1233,7 +1239,7 @@ const createTransformer = ({ getModel }) => {
1233
1239
  query.where = convertFiltersQueryParams(filters2, schema);
1234
1240
  }
1235
1241
  if (!isNil(fields2)) {
1236
- query.select = convertFieldsQueryParams(fields2);
1242
+ query.select = convertFieldsQueryParams(fields2, schema);
1237
1243
  }
1238
1244
  if (!isNil(populate2)) {
1239
1245
  query.populate = convertPopulateQueryParams(populate2, schema);