diff --git a/src/runtime/composables-v4/useStrapi.ts b/src/runtime/composables-v4/useStrapi.ts index 50c6767c..5b41c7b1 100644 --- a/src/runtime/composables-v4/useStrapi.ts +++ b/src/runtime/composables-v4/useStrapi.ts @@ -3,8 +3,8 @@ import type { Strapi4ResponseSingle, Strapi4RequestParams, Strapi4ResponseMany } import { useStrapiClient } from '#imports' interface StrapiV4Client { - find(contentType: string, params?: Strapi4RequestParams): Promise> - findOne(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise> + find(contentType: string, params?: Strapi4RequestParams): Promise> + findOne(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise> create(contentType: string, data: Partial): Promise> update(contentType: string, id: string | number | Partial, data?: Partial): Promise> delete(contentType: string, id?: string | number): Promise> @@ -20,7 +20,7 @@ export const useStrapi = (): StrapiV4Client => { * @param {Strapi4RequestParams} [params] - Query parameters * @returns Promise */ - const find = (contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise> => { + const find = (contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise> => { return client(`/${contentType}`, { method: 'GET', params, ...fetchOptions }) } @@ -32,7 +32,7 @@ export const useStrapi = (): StrapiV4Client => { * @param {Strapi4RequestParams} [params] - Query parameters * @returns Promise */ - const findOne = (contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise> => { + const findOne = (contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise> => { if (typeof id === 'object') { params = id id = undefined diff --git a/src/runtime/types/index.ts b/src/runtime/types/index.ts index 57a49876..cea49a97 100644 --- a/src/runtime/types/index.ts +++ b/src/runtime/types/index.ts @@ -570,6 +570,22 @@ export interface StrapiGraphqlVariables { [variable: string]: unknown } +export type StrapiRequestParamField = { + [K in keyof T]: T[K] extends object + ? never + : K; +}[keyof T] + +export type StrapiRequestParamSort = `${Exclude}${':asc' | ':desc' | ''}` + +export type StrapiRequestParamPopulate = { + [K in keyof T]: T[K] extends object + ? T[K] extends Array + ? `${Exclude}` | `${Exclude}.${StrapiRequestParamPopulate}` + : `${Exclude}` | `${Exclude}.${StrapiRequestParamPopulate}` + : never; +}[keyof T] + export * from './v3' export * from './v4' export * from './v5' diff --git a/src/runtime/types/v4.ts b/src/runtime/types/v4.ts index 4a7864ac..b3ce7c31 100644 --- a/src/runtime/types/v4.ts +++ b/src/runtime/types/v4.ts @@ -1,4 +1,4 @@ -import type { StrapiLocale } from '.' +import type { StrapiLocale, StrapiRequestParamField, StrapiRequestParamPopulate, StrapiRequestParamSort } from '.' export interface Strapi4Error { error: { @@ -21,10 +21,10 @@ export interface PaginationByOffset { withCount?: boolean } -export interface Strapi4RequestParams { - fields?: Array - populate?: string | Array | object - sort?: string | Array +export interface Strapi4RequestParams { + fields?: Array> + populate?: '*' | StrapiRequestParamPopulate | Array> + sort?: StrapiRequestParamSort | Array> pagination?: PaginationByOffset | PaginationByPage filters?: Record publicationState?: 'live' | 'preview' diff --git a/src/runtime/types/v5.ts b/src/runtime/types/v5.ts index 3959d45c..5599bfcc 100644 --- a/src/runtime/types/v5.ts +++ b/src/runtime/types/v5.ts @@ -1,4 +1,4 @@ -import type { MetaResponsePaginationByOffset, MetaResponsePaginationByPage, PaginationByOffset, PaginationByPage, StrapiLocale } from '.' +import type { MetaResponsePaginationByOffset, MetaResponsePaginationByPage, PaginationByOffset, PaginationByPage, StrapiLocale, StrapiRequestParamField, StrapiRequestParamPopulate, StrapiRequestParamSort } from '.' export interface Strapi5Error { error: { @@ -9,26 +9,10 @@ export interface Strapi5Error { } } -type Strapi5RequestParamField = { - [K in keyof T]: T[K] extends object - ? never - : K; -}[keyof T] - -type Strapi5RequestParamSort = `${Exclude}${':asc' | ':desc' | ''}` - -type Strapi5RequestParamPopulate = { - [K in keyof T]: T[K] extends object - ? T[K] extends Array - ? `${Exclude}` | `${Exclude}.${Strapi5RequestParamPopulate}` - : `${Exclude}` | `${Exclude}.${Strapi5RequestParamPopulate}` - : never; -}[keyof T] - export interface Strapi5RequestParams { - fields?: Array> - populate?: '*' | Strapi5RequestParamPopulate | Array> - sort?: Strapi5RequestParamSort | Array> + fields?: Array> + populate?: '*' | StrapiRequestParamPopulate | Array> + sort?: StrapiRequestParamSort | Array> pagination?: PaginationByOffset | PaginationByPage filters?: Record publicationState?: 'live' | 'preview'