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

Add Query Syntax support #30

Open
andreasciamanna opened this issue Jan 25, 2023 · 3 comments
Open

Add Query Syntax support #30

andreasciamanna opened this issue Jan 25, 2023 · 3 comments

Comments

@andreasciamanna
Copy link
Contributor

Like pagination options, a query parameter is accepted by many endpoints (see here.

I assume that where it is not accepted, it's ignored.

Adding a query parameter would improve the API by a good measure as, without it, in many cases, I'm resorting to calling some all method, dealing with pagination, and filtering the results.

I'd like to suggest the following (I'll try to work on a PR).

QueryOptions:

export interface QueryOptions {
    /**
     * Optional. Let's filter entities you receive from a server in response to your request.
     * For details about YouTrack search queries, refer to the 
     * [Search Query Reference](https://www.jetbrains.com/help/youtrack/cloud/Search-and-Command-Attributes.html).
     */
    $query?: Record<string, string>;
}

All methods that accept as PaginationOptions would gain an extra optional parameter. Example:

import { BaseEndpoint } from "./base";
import { ReducedUser, User } from "..";
import { PaginationOptions } from "../options/pagination_options";
import { QueryOptions } from "../options/query_options";
export declare const UserPaths: {
    current: string;
    users: string;
    user: string;
};
export declare class UserEndpoint extends BaseEndpoint {
    current(): Promise<User>;
    all(paginationOptions?: PaginationOptions, queryOptions?: QueryOptions): Promise<ReducedUser[]>;
    byId(userId: string): Promise<User>;
}

When building the request, that is, converting paginationOptions to query string parameters, the same will be done for queryOptions.

I didn't go deep enough in the source code to point to a specific file, but I'll soon clone the project and give it a shot.

This, of course, unless the feature is already implemented and I've completely missed it.

@shanehofstetter
Copy link
Owner

Hi @andreasciamanna,
you are right, the query param is mostly not supported at the moment (only on issues), and this would be a great addition.

As for implementation I think it would be most ergonomic if we'd extend the options type to include the query param, so in the end it would look something like this:

export declare class UserEndpoint extends BaseEndpoint {
    current(): Promise<User>;
    all(options?: RequestParams): Promise<ReducedUser[]>;
    byId(userId: string): Promise<User>;
}
export interface QueryOptions {
    query: string | Record<string, string>; // also maybe support strings as well
}

export interface RequestParams extends QueryOptions, PaginationOptions {
    
}

@andreasciamanna
Copy link
Contributor Author

Makes sense!

I'm working on a PR.

@udamir
Copy link

udamir commented Sep 16, 2024

Great project, but it lacks flexibility and seems like this project is not being developed anymore. So I made my own implementation Youtrack client, I hope it will be useful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants