mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
Merge pull request #17937 from strapi/fix/missing-id-property-in-filters-object
This commit is contained in:
commit
deb0c4d12c
@ -2,9 +2,12 @@ import type { Attribute, Common, Utils } from '@strapi/strapi';
|
||||
|
||||
import type * as Operator from './operators';
|
||||
import type * as AttributeUtils from '../attributes';
|
||||
import type Params from '../index';
|
||||
|
||||
export { Operator };
|
||||
|
||||
type IDKey = 'id';
|
||||
|
||||
/**
|
||||
* Filter representation for nested attributes
|
||||
*/
|
||||
@ -20,11 +23,17 @@ type NestedAttributeCondition<
|
||||
*/
|
||||
type AttributeCondition<
|
||||
TSchemaUID extends Common.UID.Schema,
|
||||
TAttributeName extends Attribute.GetKeys<TSchemaUID>
|
||||
> = Utils.Expression.If<
|
||||
TAttributeName extends IDKey | Attribute.GetKeys<TSchemaUID>
|
||||
> = Utils.Expression.MatchFirst<
|
||||
[
|
||||
// Special catch for manually added ID attributes
|
||||
[Utils.Expression.StrictEqual<TAttributeName, IDKey>, Params.Attribute.ID],
|
||||
[
|
||||
Utils.Expression.IsNotNever<TAttributeName>,
|
||||
// Get the filter attribute value for the given attribute
|
||||
AttributeUtils.GetValue<Attribute.Get<TSchemaUID, TAttributeName>>,
|
||||
AttributeUtils.GetValue<Attribute.Get<TSchemaUID, Exclude<TAttributeName, IDKey>>>
|
||||
]
|
||||
],
|
||||
// Fallback to the list of all possible scalar attributes' value if the attribute is not valid (never)
|
||||
AttributeUtils.ScalarValues
|
||||
> extends infer TAttributeValue
|
||||
@ -64,11 +73,17 @@ export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = {
|
||||
Utils.Expression.IsNotNever<TNestedKeys>
|
||||
>,
|
||||
// Strongly typed representation of the filter object tree
|
||||
| { [TIter in TScalarKeys]?: AttributeCondition<TSchemaUID, TIter> }
|
||||
| { [TIter in TNestedKeys]?: NestedAttributeCondition<TSchemaUID, TIter> },
|
||||
{
|
||||
[TIter in IDKey | TScalarKeys]?: AttributeCondition<TSchemaUID, TIter>;
|
||||
} & {
|
||||
[TIter in TNestedKeys]?: NestedAttributeCondition<TSchemaUID, TIter>;
|
||||
},
|
||||
// Generic representation of the filter object tree in case we don't have access to the attributes' list
|
||||
| { [TKey in string]?: AttributeCondition<TSchemaUID, never> }
|
||||
| { [TKey in string]?: NestedAttributeCondition<TSchemaUID, never> }
|
||||
{
|
||||
[TKey in string]?:
|
||||
| AttributeCondition<TSchemaUID, never>
|
||||
| NestedAttributeCondition<TSchemaUID, never>;
|
||||
}
|
||||
>
|
||||
: never);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user