@strapi2front/generators 0.3.0 → 0.3.1

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