From 2d87346bb24f3d2a0d63a8e3fcf56be1578ff938 Mon Sep 17 00:00:00 2001 From: Pedro Guzman Date: Sat, 14 Jun 2025 01:48:25 +0200 Subject: [PATCH 1/5] fix: add operators to RemoteQueryFilters --- .../types/src/modules-sdk/to-remote-query.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) 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 dc78e0b7fc..d81dae04c4 100644 --- a/packages/core/types/src/modules-sdk/to-remote-query.ts +++ b/packages/core/types/src/modules-sdk/to-remote-query.ts @@ -45,6 +45,34 @@ type ExtractFiltersOperators< : never } +type OperatorsOnlyFilters< + TEntry extends string, + RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, + Exclusion extends string[] = [], + Lim extends number = Depth[3] +> = Lim extends number + ? { + $or?: RemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Depth[Lim] + >[] + $and?: RemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Depth[Lim] + >[] + $not?: RemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Depth[Lim] + > + } + : never + /** * Extract all available filters from a remote entry point deeply */ @@ -53,7 +81,7 @@ export type RemoteQueryFilters< RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, Exclusion extends string[] = [], Lim extends number = Depth[3] -> = Lim extends number +> = (Lim extends number ? TEntry extends keyof RemoteQueryEntryPointsLevel ? TypeOnly extends Array ? Prettify< @@ -69,4 +97,5 @@ export type RemoteQueryFilters< > > : Record - : never + : never) & + OperatorsOnlyFilters From 8443d3727538fc656816203ee1f91d6667043372 Mon Sep 17 00:00:00 2001 From: Pedro Guzman Date: Sat, 14 Jun 2025 02:09:50 +0200 Subject: [PATCH 2/5] cast selector to RemoteQueryFilters --- .../workflows/update-stock-locations.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/core-flows/src/stock-location/workflows/update-stock-locations.ts b/packages/core/core-flows/src/stock-location/workflows/update-stock-locations.ts index a8cf12b4ce..4e368f0d90 100644 --- a/packages/core/core-flows/src/stock-location/workflows/update-stock-locations.ts +++ b/packages/core/core-flows/src/stock-location/workflows/update-stock-locations.ts @@ -1,5 +1,6 @@ import { FilterableStockLocationProps, + RemoteQueryFilters, StockLocationDTO, UpdateStockLocationInput, UpsertStockLocationAddressInput, @@ -32,10 +33,10 @@ export const updateStockLocationsWorkflowId = "update-stock-locations-workflow" /** * This workflow updates stock locations matching the specified filters. It's used by the * [Update Stock Location Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_poststocklocationsid). - * + * * You can use this workflow within your own customizations or custom workflows, allowing you * to update stock locations in your custom flows. - * + * * @example * const { result } = await updateStockLocationsWorkflow(container) * .run({ @@ -48,9 +49,9 @@ export const updateStockLocationsWorkflowId = "update-stock-locations-workflow" * } * } * }) - * + * * @summary - * + * * Update stock locations. */ export const updateStockLocationsWorkflow = createWorkflow( @@ -60,7 +61,7 @@ export const updateStockLocationsWorkflow = createWorkflow( ): WorkflowResponse => { const stockLocationsQuery = useQueryGraphStep({ entity: "stock_location", - filters: input.selector, + filters: input.selector as RemoteQueryFilters<"stock_location">, fields: ["id", "address.id"], }).config({ name: "get-stock-location" }) From 6e8b7c62627a72c1583ac422ed1dc6d819dd3e6b Mon Sep 17 00:00:00 2001 From: Pedro Guzman Date: Sat, 14 Jun 2025 02:38:31 +0200 Subject: [PATCH 3/5] remove depth limitation from OperatorsOnlyFilters to make it compatible with BaseFilterable --- .../types/src/modules-sdk/to-remote-query.ts | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) 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 d81dae04c4..a95a7d6912 100644 --- a/packages/core/types/src/modules-sdk/to-remote-query.ts +++ b/packages/core/types/src/modules-sdk/to-remote-query.ts @@ -50,28 +50,21 @@ type OperatorsOnlyFilters< RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, Exclusion extends string[] = [], Lim extends number = Depth[3] -> = Lim extends number - ? { - $or?: RemoteQueryFilters< - TEntry, - RemoteQueryEntryPointsLevel, - Exclusion, - Depth[Lim] - >[] - $and?: RemoteQueryFilters< - TEntry, - RemoteQueryEntryPointsLevel, - Exclusion, - Depth[Lim] - >[] - $not?: RemoteQueryFilters< - TEntry, - RemoteQueryEntryPointsLevel, - Exclusion, - Depth[Lim] - > - } - : never +> = { + $or?: RemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Lim + >[] + $and?: RemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Lim + >[] + $not?: RemoteQueryFilters +} /** * Extract all available filters from a remote entry point deeply From ebe02a3836399446430018cd59f147c2d44cea3f Mon Sep 17 00:00:00 2001 From: Pedro Guzman Date: Wed, 18 Jun 2025 13:31:56 +0200 Subject: [PATCH 4/5] simplify RemoteQueryFilterOperators --- .../types/src/modules-sdk/to-remote-query.ts | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) 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 a95a7d6912..fb63cc4ed2 100644 --- a/packages/core/types/src/modules-sdk/to-remote-query.ts +++ b/packages/core/types/src/modules-sdk/to-remote-query.ts @@ -45,36 +45,21 @@ type ExtractFiltersOperators< : never } -type OperatorsOnlyFilters< - TEntry extends string, - RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, - Exclusion extends string[] = [], - Lim extends number = Depth[3] -> = { - $or?: RemoteQueryFilters< - TEntry, - RemoteQueryEntryPointsLevel, - Exclusion, - Lim - >[] - $and?: RemoteQueryFilters< - TEntry, - RemoteQueryEntryPointsLevel, - Exclusion, - Lim - >[] - $not?: RemoteQueryFilters +type RemoteQueryFilterOperators = { + $or?: T[] + $and?: T[] + $not?: T } /** * Extract all available filters from a remote entry point deeply */ -export type RemoteQueryFilters< +export type InternalRemoteQueryFilters< TEntry extends string, RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, Exclusion extends string[] = [], Lim extends number = Depth[3] -> = (Lim extends number +> = Lim extends number ? TEntry extends keyof RemoteQueryEntryPointsLevel ? TypeOnly extends Array ? Prettify< @@ -90,5 +75,24 @@ export type RemoteQueryFilters< > > : Record - : never) & - OperatorsOnlyFilters + : never + +export type RemoteQueryFilters< + TEntry extends string, + RemoteQueryEntryPointsLevel = RemoteQueryEntryPoints, + Exclusion extends string[] = [], + Lim extends number = Depth[3] +> = RemoteQueryFilterOperators< + InternalRemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Lim + > +> & + InternalRemoteQueryFilters< + TEntry, + RemoteQueryEntryPointsLevel, + Exclusion, + Lim + > From 9043e534ceff8f44d356a6db19dd78f851b71cdc Mon Sep 17 00:00:00 2001 From: Pedro Guzman Date: Wed, 18 Jun 2025 15:37:26 +0200 Subject: [PATCH 5/5] make operators deep --- packages/core/types/src/modules-sdk/to-remote-query.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 fb63cc4ed2..18014a351e 100644 --- a/packages/core/types/src/modules-sdk/to-remote-query.ts +++ b/packages/core/types/src/modules-sdk/to-remote-query.ts @@ -46,9 +46,9 @@ type ExtractFiltersOperators< } type RemoteQueryFilterOperators = { - $or?: T[] - $and?: T[] - $not?: T + $or?: (T & RemoteQueryFilterOperators)[] + $and?: (T & RemoteQueryFilterOperators)[] + $not?: T & RemoteQueryFilterOperators } /**