diff --git a/src/runtime/types/v4.ts b/src/runtime/types/v4.ts index b3ce7c31..45bb999c 100644 --- a/src/runtime/types/v4.ts +++ b/src/runtime/types/v4.ts @@ -23,7 +23,7 @@ export interface PaginationByOffset { export interface Strapi4RequestParams { fields?: Array> - populate?: '*' | StrapiRequestParamPopulate | Array> + populate?: Strapi4RequestPopulateParam sort?: StrapiRequestParamSort | Array> pagination?: PaginationByOffset | PaginationByPage filters?: Record @@ -31,6 +31,21 @@ export interface Strapi4RequestParams { locale?: StrapiLocale } +export type Strapi4RequestPopulateParams = Pick, 'fields' | 'sort' | 'populate' | 'filters'> + +// Unified type for Strapi populate, combining both string paths and nested objects. +export type Strapi4RequestPopulateParam = + | '*' // Populate all relations. + | { [K in keyof T]?: // Nested object population. + T[K] extends object + ? T[K] extends Array + ? Strapi4RequestPopulateParam | Strapi4RequestPopulateParams + : Strapi4RequestPopulateParam | Strapi4RequestPopulateParams + : never + } + | StrapiRequestParamPopulate // String paths like "field.subfield". + | Array> // Array of string paths. + export interface Strapi4ResponseData { id: number attributes: T diff --git a/src/runtime/types/v5.ts b/src/runtime/types/v5.ts index 8a8c651e..9d9a0bf4 100644 --- a/src/runtime/types/v5.ts +++ b/src/runtime/types/v5.ts @@ -11,7 +11,7 @@ export interface Strapi5Error { export interface Strapi5RequestParams { fields?: Array> - populate?: '*' | StrapiRequestParamPopulate | Array> + populate?: Strapi5RequestPopulateParam sort?: StrapiRequestParamSort | Array> pagination?: PaginationByOffset | PaginationByPage filters?: Record @@ -19,6 +19,21 @@ export interface Strapi5RequestParams { locale?: StrapiLocale | null } +export type Strapi5RequestPopulateParams = Pick, 'fields' | 'sort' | 'populate' | 'filters'> + +// Unified type for Strapi populate, combining both string paths and nested objects. +export type Strapi5RequestPopulateParam = + | '*' // Populate all relations. + | { [K in keyof T]?: // Nested object population. + T[K] extends object + ? T[K] extends Array + ? Strapi5RequestPopulateParam | Strapi5RequestPopulateParams + : Strapi5RequestPopulateParam | Strapi5RequestPopulateParams + : never + } + | StrapiRequestParamPopulate // String paths like "field.subfield". + | Array> // Array of string paths. + export interface StrapiSystemFields { documentId: string locale?: string