Infusion.Gen.Pagination (infusion v0.1.0)

Copy Markdown View Source

Works out how a list operation pages, from its parameters and response.

Specs don't say how an API paginates, but the shapes are recognisable:

styleseen inrecognised by
:cursor_afterOpenAI, Stripean after / starting_after parameter and a has_more field
:cursorCloudflare, Slacka cursor parameter and a cursor / next_cursor field in the response
:next_urlTwilioa next_page_uri / next_page_url field
:pageGitHub, Cloudflarea page parameter; GitHub's Link header is followed when sent
:offsetCloudflareoffset and limit parameters
:link_headerGitHubany other paging parameter (per_page, after): follows rel="next" in the Link header, if the API sends one

The result is data for the runtime: where the items are (items, a path into the response), how each item decodes (item, a schema), and what the style needs (parameter names, paths to fields).

Summary

Functions

The pagination of op, or nil if it doesn't page.

Functions

detect(op, ir)

@spec detect(
  %Infusion.IR.Operation{
    body: term(),
    cookie_params: term(),
    deprecated?: term(),
    description: term(),
    function: term(),
    header_params: term(),
    id: term(),
    method: term(),
    module: term(),
    naming: term(),
    path: term(),
    path_params: term(),
    query_params: term(),
    responses: term(),
    servers: term(),
    streaming?: term(),
    summary: term()
  },
  %Infusion.IR{
    auth: term(),
    operations: term(),
    schemas: term(),
    servers: term(),
    warnings: term()
  }
) :: map() | nil

The pagination of op, or nil if it doesn't page.