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 Operator from './operators';
|
||||||
import type * as AttributeUtils from '../attributes';
|
import type * as AttributeUtils from '../attributes';
|
||||||
|
import type Params from '../index';
|
||||||
|
|
||||||
export { Operator };
|
export { Operator };
|
||||||
|
|
||||||
|
type IDKey = 'id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter representation for nested attributes
|
* Filter representation for nested attributes
|
||||||
*/
|
*/
|
||||||
@ -20,11 +23,17 @@ type NestedAttributeCondition<
|
|||||||
*/
|
*/
|
||||||
type AttributeCondition<
|
type AttributeCondition<
|
||||||
TSchemaUID extends Common.UID.Schema,
|
TSchemaUID extends Common.UID.Schema,
|
||||||
TAttributeName extends Attribute.GetKeys<TSchemaUID>
|
TAttributeName extends IDKey | Attribute.GetKeys<TSchemaUID>
|
||||||
> = Utils.Expression.If<
|
> = Utils.Expression.MatchFirst<
|
||||||
Utils.Expression.IsNotNever<TAttributeName>,
|
[
|
||||||
// Get the filter attribute value for the given attribute
|
// Special catch for manually added ID attributes
|
||||||
AttributeUtils.GetValue<Attribute.Get<TSchemaUID, TAttributeName>>,
|
[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, Exclude<TAttributeName, IDKey>>>
|
||||||
|
]
|
||||||
|
],
|
||||||
// Fallback to the list of all possible scalar attributes' value if the attribute is not valid (never)
|
// Fallback to the list of all possible scalar attributes' value if the attribute is not valid (never)
|
||||||
AttributeUtils.ScalarValues
|
AttributeUtils.ScalarValues
|
||||||
> extends infer TAttributeValue
|
> extends infer TAttributeValue
|
||||||
@ -64,11 +73,17 @@ export type ObjectNotation<TSchemaUID extends Common.UID.Schema> = {
|
|||||||
Utils.Expression.IsNotNever<TNestedKeys>
|
Utils.Expression.IsNotNever<TNestedKeys>
|
||||||
>,
|
>,
|
||||||
// Strongly typed representation of the filter object tree
|
// 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
|
// 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);
|
: never);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user