@strapi2front/generators 0.3.0 → 0.3.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/index.js CHANGED
@@ -3275,7 +3275,9 @@ function generateUtilityTypesJSDoc(blocksRendererInstalled, strapiVersion) {
3275
3275
  * @returns {T}
3276
3276
  */
3277
3277
  function flattenV4Response(item) {
3278
- return { id: item.id, ...item.attributes };
3278
+ /** @type {any} */
3279
+ const merged = { id: item.id, ...item.attributes };
3280
+ return merged;
3279
3281
  }
3280
3282
 
3281
3283
  /**
@@ -3383,7 +3385,9 @@ const defaultPagination = {
3383
3385
  * @returns {T}
3384
3386
  */
3385
3387
  function flattenItem(item) {
3386
- return { id: item.id, ...item.attributes };
3388
+ /** @type {any} */
3389
+ const merged = { id: item.id, ...item.attributes };
3390
+ return merged;
3387
3391
  }
3388
3392
 
3389
3393
  /**
@@ -3395,22 +3399,26 @@ function flattenItem(item) {
3395
3399
  function flattenRelations(data) {
3396
3400
  if (data === null || data === undefined) return data;
3397
3401
  if (Array.isArray(data)) {
3398
- return /** @type {T} */ (data.map(item => flattenRelations(item)));
3402
+ /** @type {any} */
3403
+ const mapped = data.map(item => flattenRelations(item));
3404
+ return mapped;
3399
3405
  }
3400
3406
  if (typeof data === 'object') {
3401
3407
  /** @type {Record<string, unknown>} */
3402
3408
  const result = {};
3403
3409
  for (const [key, value] of Object.entries(data)) {
3404
3410
  if (value && typeof value === 'object' && 'data' in value) {
3405
- const relationData = /** @type {{ data: unknown }} */ (value).data;
3411
+ /** @type {any} */
3412
+ const wrapper = value;
3413
+ const relationData = wrapper.data;
3406
3414
  if (relationData === null) {
3407
3415
  result[key] = null;
3408
3416
  } else if (Array.isArray(relationData)) {
3409
3417
  result[key] = relationData.map((item) =>
3410
3418
  flattenRelations(flattenItem(item))
3411
3419
  );
3412
- } else if (typeof relationData === 'object' && 'id' in relationData && 'attributes' in relationData) {
3413
- result[key] = flattenRelations(flattenItem(/** @type {{ id: number, attributes: object }} */ (relationData)));
3420
+ } else if (typeof relationData === 'object' && relationData !== null && 'id' in relationData && 'attributes' in relationData) {
3421
+ result[key] = flattenRelations(flattenItem(relationData));
3414
3422
  } else {
3415
3423
  result[key] = flattenRelations(value);
3416
3424
  }
@@ -3418,7 +3426,9 @@ function flattenRelations(data) {
3418
3426
  result[key] = flattenRelations(value);
3419
3427
  }
3420
3428
  }
3421
- return /** @type {T} */ (result);
3429
+ /** @type {any} */
3430
+ const typed = result;
3431
+ return typed;
3422
3432
  }
3423
3433
  return data;
3424
3434
  }