Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK: Fix type arrays on filter #10133

Merged
merged 2 commits into from Dec 1, 2021
Merged

Conversation

joselcvarela
Copy link
Member

@joselcvarela joselcvarela commented Nov 29, 2021

Previously, only the same type as definition was accepted.
Screenshot 2021-11-29 at 14 25 39

Now accept both the type defined and and array of that type

@joselcvarela joselcvarela requested review from Oreilles and rijkvanzanten and removed request for Oreilles November 29, 2021 14:26
@joselcvarela joselcvarela self-assigned this Nov 29, 2021
@Oreilles
Copy link
Contributor

No good, since you'll now be able to do filter: { name: { _eq: ['aaa'] } };
Here's what I suggest:

export type FieldFilterOperator<T> = {
	_eq?: T;
	_neq?: T;
	_gt?: T;
	_gte?: T;
	_lt?: T;
	_lte?: T;
	_in?: T[];
	_nin?: T[];
	_between?: [T, T];
	_nbetween?: [T, T];
	_contains?: T;
	_ncontains?: T;
	_empty?: boolean;
	_nempty?: boolean;
	_nnull?: boolean;
	_null?: boolean;
	_intersects?: T;
	_nintersects?: T;
	_intersects_bbox?: T;
	_nintersects_bbox?: T;
};

export type FilterOperators = keyof FieldFilterOperator<any>;

export type FieldFilter<T> = {
	[K in keyof T]?: FieldFilterOperator<T[K]> | FieldFilter<T[K]>;
};

@joselcvarela
Copy link
Member Author

@Oreilles good one, much more reliable 👍

@rijkvanzanten rijkvanzanten added this to the v9-next milestone Dec 1, 2021
@rijkvanzanten rijkvanzanten merged commit 2fa2a75 into main Dec 1, 2021
@rijkvanzanten rijkvanzanten deleted the sdk/fix-filter-typescript branch December 1, 2021 19:04
rijkvanzanten pushed a commit that referenced this pull request Dec 1, 2021
* support arrays as types for _in, _nin, etc.

* improve type definition on filters
@nickrum nickrum mentioned this pull request Dec 3, 2021
3 tasks
@nickrum nickrum linked an issue Dec 3, 2021 that may be closed by this pull request
3 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken filter types in SDK
3 participants