@curveball/browser
Version:
Automatic API browser generator. A middleware that turns your JSON responses into HTML if accessed by a browser.
51 lines (50 loc) • 1.88 kB
TypeScript
import { Link } from 'ketting';
import { NavigationLink, NavigationPosition, Options, Theme } from './types.js';
import { State } from 'ketting';
import { Context } from '@curveball/kernel';
/**
* Returns the list of links for a section.
*
* This function sorts and normalizes the link.
*/
export declare function getNavLinks(links: Link[], options: Options, position: NavigationPosition): Array<Link & NavigationLink>;
/**
* We use Ketting for a lot of the parsing.
*
* The main object that contains a response in Ketting is a 'State' object,
* to get a State, we need a Response object, as it's part of the fetch()
* specification.
*
* So we go from ctx.response, to Response, to State.
*/
export declare function contextToState(ctx: Context): Promise<State>;
/**
* This is a very rudimentary Templated URI parser.
*
* Currently we don't parse the entire syntax, because we are using templated
* URIs to generate Javascript-free standard HTML forms.
*
* In these HTML forms, we can only let users define things in the 'query'
* part of the URI.
*
* If the parser encounters a templated URI that's not parsable, it returns
* null, otherwise it returns a tuple with three elements:
*
* 1. The URI that's the target of the form (without query params)
* 2. An object containing values that should be added as hidden fields and
* values.
* 3. An array with field names that should be rendered as input fields.
*
* Examples of supported formats:
* http://example/?foo={bar}
* http://example/{?foo}
* http://example/?foo=bar{&bar}
* http://example/?foo=1{&bar,baz,zim}
*/
export declare function getFieldsFromTemplatedUri(input: string): null | [string, Record<string, string>, string[]];
/**
* Returns the default theme
*
* This might alternate depending on the time of the year.
*/
export declare function getDefaultTheme(): Theme;