qri-io / qri

you're invited to a data party!
https://qri.io
GNU General Public License v3.0
1.11k stars 66 forks source link

listing discussion #1988

Open ramfox opened 2 years ago

ramfox commented 2 years ago

List Params

What is the best way to organize our list params, both below lib, as consumed by lib, and in the API

Needs:

discussion

Limit, offset

Filters

Sort

I think I personally like the first one since it seems easier to type for the user

params.List

Lib/http

Current endpoints that list & their associated parameters: Endpoint Param
list ListParams
activity ActivityParams
get GetParams
peer list PeerListParams
remote feeds EmptyParams
registry search SearchParams
registry follow list FollowGetParams
connections ConnectionsParams
qri connections ConnectionsParams
// ListParams is the general input for any sort of Paginated Request
// ListParams define limits & offsets, not pages & page sizes.
// TODO - rename this to PageParams.
type ListParams struct {
    // TODO(b5): what is this being used for?
    ProfileID profile.ID `json:"-" docs:"hidden"`
    // term to filter list by; e.g. "population"
    Term string `json:"term,omitempty"`
    // username to filter collection by; e.g. "ramfox"
    Username string `json:"username,omitempty"`
    // field name to order list by; e.g. "created"
    OrderBy string `json:"orderBy,omitempty"`
    // maximum number of datasets to use. use -1 to list all datasets; e.g. 50
    Limit int `json:"limit"`
    // number of items to skip; e.g. 0
    Offset int `json:"offset"`
    // Public only applies to listing datasets, shows only datasets that are
    // set to visible
    Public bool `json:"public,omitempty"`
}

// ActivityParams defines parameters for the Activity method
type ActivityParams struct {
    ListParams
    // Reference to data to fetch history for; e.g. "b5/world_bank_population"
    Ref string `json:"ref"`
    // if true, pull any datasets that aren't stored locally; e.g. false
    Pull bool `json:"pull"`
}

// GetParams defines parameters for looking up the head or body of a dataset
type GetParams struct {
    // dataset reference to fetch; e.g. "b5/world_bank_population"
    Ref string `json:"ref"`
    // a component or nested field names to extract from the dataset; e.g. "body"
    Selector string `json:"selector"`
    // number of results to limit to. only applies when selector is "body"
    Limit int `json:"limit"`
    // number of results to skip. only applies when selector is "body"
    Offset int `json:"offset"`
    // TODO(dustmop): Remove `All` once `Cursor` is in use. Instead, callers should
    // loop over their `Cursor` in order to get all rows.
    All bool `json:"all" docs:"hidden"`
}

// PeerListParams defines parameters for the List method
type PeerListParams struct {
    Limit  int `json:"limit"`
    Offset int `json:"offset"`
    // Cached == true will return offline peers from the repo
    // as well as online peers, default is to list connected peers only
    Cached bool `json:"cached"`
}

// SearchParams encapsulates parameters provided to Searchable.Search
type SearchParams struct {
    Q             string
    Limit, Offset int
}

// FollowGetParams encapsulates parameters provided to Follower.Get
type FollowGetParams struct {
    Username string `json:"username"`
    Limit    int    `json:"limit"`
    Offset   int    `json:"offset"`
    // TODO(arqu): order by fields are missing
}

// ConnectionsParams defines parameters for the Connections method
type ConnectionsParams struct {
    Limit  int `json:"limit"`
    Offset int `json:"offset"`
}
ramfox commented 2 years ago

filtering:

Avoid filtering for now! needs research (microsoft, open api, elasticsearch)

Note, by dustin, it is an anti-pattern to allow enormous limits for limit

KASEY REMEMBER TO ADD BREAKING CHANGE NOTES IN COMMIT WHEN YOU REMOVE PAGE/PAGESIZE