diff --git a/.changeset/eleven-falcons-return.md b/.changeset/eleven-falcons-return.md new file mode 100644 index 0000000000..612acc94f2 --- /dev/null +++ b/.changeset/eleven-falcons-return.md @@ -0,0 +1,6 @@ +--- +"@medusajs/modules-sdk": patch +"@medusajs/types": patch +--- + +fix: remote query types diff --git a/packages/core/modules-sdk/src/remote-query/query.ts b/packages/core/modules-sdk/src/remote-query/query.ts index 84885de48e..3be1be2391 100644 --- a/packages/core/modules-sdk/src/remote-query/query.ts +++ b/packages/core/modules-sdk/src/remote-query/query.ts @@ -155,7 +155,7 @@ export class Query { queryOptions: RemoteQueryInput, options?: RemoteJoinerOptions ): Promise> { - const normalizedQuery = toRemoteQuery( + const normalizedQuery = toRemoteQuery( queryOptions, this.#remoteQuery.getEntitiesMap() ) diff --git a/packages/core/modules-sdk/src/remote-query/to-remote-query.ts b/packages/core/modules-sdk/src/remote-query/to-remote-query.ts index 061f8a42b3..7ce9108e66 100644 --- a/packages/core/modules-sdk/src/remote-query/to-remote-query.ts +++ b/packages/core/modules-sdk/src/remote-query/to-remote-query.ts @@ -1,5 +1,4 @@ import { - RemoteQueryEntryPoints, RemoteQueryFilters, RemoteQueryGraph, RemoteQueryInput, @@ -31,7 +30,7 @@ const ARGUMENTS = "__args" export function toRemoteQuery( config: { - entity: TEntity | keyof RemoteQueryEntryPoints + entity: TEntity fields: RemoteQueryInput["fields"] filters?: RemoteQueryFilters pagination?: Partial["pagination"]> diff --git a/packages/core/types/src/modules-sdk/remote-query-object-from-string.ts b/packages/core/types/src/modules-sdk/remote-query-object-from-string.ts index 36bbf98022..9cf833c110 100644 --- a/packages/core/types/src/modules-sdk/remote-query-object-from-string.ts +++ b/packages/core/types/src/modules-sdk/remote-query-object-from-string.ts @@ -25,57 +25,102 @@ export type RemoteQueryObjectFromStringResult< __value: object } -export type RemoteQueryInput = { - /** - * The name of the entity to retrieve. For example, `product`. - */ - entity: TEntry | keyof RemoteQueryEntryPoints - /** - * The fields and relations to retrieve in the entity. - */ - fields: ObjectToRemoteQueryFields< - RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints] - > extends never - ? string[] - : - | ObjectToRemoteQueryFields< - RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints] - >[] - | string[] - /** - * Pagination configurations for the returned list of items. - */ - pagination?: { - /** - * The number of items to skip before retrieving the returned items. - */ - skip?: number - /** - * The maximum number of items to return. - */ - take?: number - /** - * Sort by field names in ascending or descending order. - */ - order?: IndexOrderBy - } - /** - * Filters to apply on the retrieved items. - */ - filters?: RemoteQueryFilters - /** - * Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context. - */ - context?: QueryContextType - /** - * Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items. - */ - withDeleted?: boolean - /** - * Strategy will be send to the entry module called method - */ - strategy?: "joined" | "select-in" -} +export type RemoteQueryInput = + TEntry extends keyof RemoteQueryEntryPoints + ? { + /** + * The name of the entity to retrieve. For example, `product`. + */ + entity: TEntry + /** + * The fields and relations to retrieve in the entity. + */ + fields: ObjectToRemoteQueryFields< + RemoteQueryEntryPoints[TEntry] + > extends never + ? string[] + : + | ObjectToRemoteQueryFields[] + | string[] + /** + * Pagination configurations for the returned list of items. + */ + pagination?: { + /** + * The number of items to skip before retrieving the returned items. + */ + skip?: number + /** + * The maximum number of items to return. + */ + take?: number + /** + * Sort by field names in ascending or descending order. + */ + order?: IndexOrderBy + } + /** + * Filters to apply on the retrieved items. + */ + filters?: RemoteQueryFilters + /** + * Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context. + */ + context?: QueryContextType + /** + * Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items. + */ + withDeleted?: boolean + /** + * Strategy will be send to the entry module called method + */ + strategy?: "joined" | "select-in" + } + : { + /** + * The name of the entity to retrieve. For example, `product`. + */ + entity: TEntry + /** + * The fields and relations to retrieve in the entity. + */ + fields: ObjectToRemoteQueryFields extends never + ? string[] + : ObjectToRemoteQueryFields[] | string[] + /** + * Pagination configurations for the returned list of items. + */ + pagination?: { + /** + * The number of items to skip before retrieving the returned items. + */ + skip?: number + /** + * The maximum number of items to return. + */ + take?: number + /** + * Sort by field names in ascending or descending order. + */ + order?: IndexOrderBy + } + /** + * Filters to apply on the retrieved items. + */ + filters?: RemoteQueryFilters + /** + * Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context. + */ + context?: QueryContextType + /** + * Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items. + */ + withDeleted?: boolean + /** + * Strategy will be send to the entry module called method + */ + strategy?: "joined" | "select-in" + } export type RemoteQueryGraph = { __TConfig: RemoteQueryObjectConfig diff --git a/packages/core/types/src/modules-sdk/to-remote-query.ts b/packages/core/types/src/modules-sdk/to-remote-query.ts index 48bdd91f60..dc78e0b7fc 100644 --- a/packages/core/types/src/modules-sdk/to-remote-query.ts +++ b/packages/core/types/src/modules-sdk/to-remote-query.ts @@ -20,7 +20,7 @@ type ExtractFiltersOperators< ? never : Key extends ExcludedProps ? never - : T[Key] extends string | number | boolean | Date + : NonNullable extends string | number | boolean | Date ? T[Key] | T[Key][] | OperatorMap : T[Key] extends Array ? TypeOnly extends { __typename: any }