From 16a54daf6a3e687d54fda4065a349f30931498f4 Mon Sep 17 00:00:00 2001 From: Convly Date: Mon, 18 Dec 2023 17:36:58 +0100 Subject: [PATCH] fix: refactor object notation type in entity-service sort --- .../src/modules/entity-service/params/sort.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/core/types/src/modules/entity-service/params/sort.ts b/packages/core/types/src/modules/entity-service/params/sort.ts index f9df4b82c8..4d8f60171e 100644 --- a/packages/core/types/src/modules/entity-service/params/sort.ts +++ b/packages/core/types/src/modules/entity-service/params/sort.ts @@ -75,16 +75,24 @@ export type ArrayNotation = Any = { - // First level sort - [key in SingleAttribute]?: OrderKind.Any; -} & { - // Deep sort, only add populatable keys that have a - // target (remove dynamic zones and other polymorphic links) - [key in Attribute.GetKeysWithTarget]?: ObjectNotation< - Attribute.GetTarget - >; + [key in ObjectNotationKeys]?: key extends SingleAttribute + ? // First level sort (scalar attributes, id, ...) + OrderKind.Any + : // Deep sort (relations with a target, components, media, ...) + ObjectNotation>; }; +/** + * Represents the keys of an object notation for a sort + * - SingleAttribute represents a union of every non-populatable attribute based on the passed schema UID + * - Attribute.GetKeysWithTarget provides keys with a target from the passed schema UID. + * + * This means that every member of ObjectNotationKeys can represent either a single non-populatable attribute or an attribute with a target. + */ +type ObjectNotationKeys = + | SingleAttribute + | Attribute.GetKeysWithTarget; + /** * Represents any notation for a sort (string, array, object) *