# gizapp/pages

File-system routing: a folder of pages is a site. `giz` writes the module `PAGES/.routes` for it (a program imports `site` from it); this file serves what that module declares. A route file is a .ghtml file in lower case (index.ghtml, [slug].ghtml), a .md file (rendered by Markdown) or a .html file (sent as it is). `[name]` in a path is a parameter, `index` is its folder, `_layout.ghtml` wraps the pages of its folder and below, `404.*` is the not-found page.

```gizlang
import * as Pages from "gizapp/pages";
```

## Types

### `Props`

```gizlang
type Props = { params: Http.Params; request: Http.Request; context: Table.Context; form: Http.Params; locale: Locale; languages: Vec<Locale>; }
```

What a route file reads: `params` and `request` by name, `me` (who asks), the tables through `context`, the fields that the
page posted (`form`: the action, the state and the bound controls, written by the generated code of the page), and `locale`, the
language the page is answered in (app/i18n.giz), by which its text and its numbers and dates show, among the `languages` of the site (its
source language first; a language picker lists them).

- `params`: `gizlang_http.Params`
- `request`: `gizlang_http.Request`
- `context`: `M118.Context`
- `form`: `gizlang_http.Params`
- `locale`: `gizlang_locale.Locale`
- `languages`: `Vec<gizlang_locale.Locale>`

### `Route`

```gizlang
type Route = { pattern: string; kind: string; render: Render; text: string; style: string; run: Answer; place: string; methods?: Vec<string>; revision?: string; }
```

A page: how it renders, and the scoped style of its file. `kind` is "view" (a .ghtml file), "markdown", "file" or
"handler" (a .giz file, which `run` answers). `place` is its address with the groups of its folders
(`/(shop)/cart`), which the layouts cover; "" is its pattern.

- `pattern`: `string`
- `kind`: `string`
- `render`: `(arg0: M114.Props, arg1: gizlang_html.Html) => gizlang_html.Html`
- `text`: `string`
- `style`: `string`
- `run`: `(arg0: M114.Props) => gizlang_http.Response`
- `place`: `string`
- `methods`: `_gizlang_sdk_core.Option<Vec<string>>`
- `revision`: `_gizlang_sdk_core.Option<string>`

### `Layout`

```gizlang
type Layout = { prefix: string; render: Render; style: string; revision?: string; }
```

A layout wraps the pages whose pattern starts with `prefix`.

- `prefix`: `string`
- `render`: `(arg0: M114.Props, arg1: gizlang_html.Html) => gizlang_html.Html`
- `style`: `string`
- `revision`: `_gizlang_sdk_core.Option<string>`

### `Guard`

```gizlang
type Guard = { prefix: string; before: (props: Props) => Option<Http.Response>; }
```

What a folder's `_middleware.giz` runs before each route under PREFIX (its place, groups included): BEFORE answers in the
route's place (a redirect to sign in, a 403, a rewrite's answer) or lets it run. Outer folders run first.

- `prefix`: `string`
- `before`: `(arg0: M114.Props) => _gizlang_sdk_core.Option<gizlang_http.Response>`

### `Site`

```gizlang
type Site = { router: Http.Router<i64>; routes: Vec<Route>; layouts: Vec<Layout>; missing: Vec<Route>; speaking: I.Speaking; guards?: Vec<Guard>; }
```

A site: its routes, layouts and not-found page, and the languages it speaks (app/i18n.giz).

- `router`: `gizlang_http.Router<i64>`
- `routes`: `Vec<M114.Route>`
- `layouts`: `Vec<M114.Layout>`
- `missing`: `Vec<M114.Route>`
- `speaking`: `_gizlang_lib_app__i18n.Speaking`
- `guards`: `_gizlang_sdk_core.Option<Vec<M114.Guard>>` — The guards of its folders, outermost first.

### `Keeping`

```gizlang
type Keeping = (field: string, name: string, type: string, data: bytes) => string throws Model.Rejection
```

Keeps a file that a page's file input sent, in the app's own place: the input's state NAME, the file's name, its media
type and its bytes; the address a page reads it at.

### `Keeper`

```gizlang
type Keeper = () => Keeping effects {io, fail}
```

Makes the Keeping of one serving thread (Application.keeps): a thread makes its own, as it makes its mounts.

### `Host`

```gizlang
type Host = { context: (request: Http.Request) => Table.Context; db: Option<Data.Db>; shapes: Vec<Model.Shape>; files: string; keep: Option<Keeping>; presence: App.Presence; actions: Vec<Model.AnyAction<Table.Context>>; }
```

What a site runs on: the tables of a request as the person who asks may use them, and the database whose changes pages follow.

- `context`: `(arg0: gizlang_http.Request) => M118.Context`
- `db`: `_gizlang_sdk_core.Option<M139.Db>`
- `shapes`: `Vec<M141.Shape>`
- `files`: `string` — The folder that keeps the files a page's file input sends (served at /files/), or "": none.
- `keep`: `_gizlang_sdk_core.Option<(arg0: string, arg1: string, arg2: string, arg3: bytes) => string throws M141.Rejection>` — Where a file of a file input goes instead of that folder (Application.keeps): none keeps it there.
- `presence`: `_gizlang_lib_app__app.Presence` — Who has which view open (a grid shows the others).
- `actions`: `Vec<M141.AnyAction<M118.Context>>` — The actions an agent or a page calls at /_a/NAME and lists at /_tools: the tables' five, then the app's own.

### `Remote`

```gizlang
type Remote = { base: string; headers: Vec<Http.Header>; }
```

Another app that a remote action calls: its address and the headers that sign each call (its bearer).

- `base`: `string`
- `headers`: `Vec<gizlang_http.Header>`

### `File`

```gizlang
type File = { name: string; type: string; size: i64; url: string; }
```

A file that a page's file input sent: its name, media type, size, and its address here (/files/…).

- `name`: `string`
- `type`: `string`
- `size`: `i64`
- `url`: `string`

### `Served`

```gizlang
type Served = { db: Data.Db; people: Data.Db; folder: string; shell: App.Shell; }
```

What a handler of an Application gets in its serving thread: its System, the app's database there and the people's
(schema auth), the folder of its files and its page shell.

- `db`: `M139.Db`
- `people`: `M139.Db`
- `folder`: `string`
- `shell`: `_gizlang_lib_app__app.Shell`

### `People`

```gizlang
type People = { title: string; origin: string; password: bool; secret: bytes; owner: string; mail: (served: Served) => Mailing effects {io, fail}; providers?: Vec<OAuth.Provider>; sso?: bool; }
```

The people of an Application (Application.signIn): TITLE names the app on its sign-in page, ORIGIN is its address in a
mailed link, PASSWORD allows a password beside the link, SECRET signs sessions, OWNER (a person id) owns the tables (the
program's own writes are the owner's), and MAIL makes, on a serving thread, what sends a sign-in link.

- `title`: `string`
- `origin`: `string`
- `password`: `bool`
- `secret`: `bytes`
- `owner`: `string`
- `mail`: `(arg0: M114.Served) => M114.Mailing effects { fail, io }`
- `providers`: `_gizlang_sdk_core.Option<Vec<_gizlang_lib_app__auth__oauth.Provider>>` — The providers a person may also sign in with (OAuth.google, OAuth.github, OAuth.oidc), a button each.
- `sso`: `_gizlang_sdk_core.Option<bool>` — Teams may sign their people in with their own single sign-on (Auth.Site.sso).

### `Mailing`

```gizlang
type Mailing = { send: (to: string, link: string) => bool; }
```

What sends sign-in links on the serving thread that made it (People.mail): `send` says whether link `link` went to
`to`.

- `send`: `(arg0: string, arg1: string) => bool`

### `Person`

```gizlang
type Person = (served: Served) => Asking effects {alloc, fail}
```

Who asks in a request, made on each serving thread from what it serves with: the app's one owner (ME), the person of
a session of its people (Application.signIn, else the public), or what a host that keeps its own sessions gives.

### `HostedPerson`

```gizlang
type HostedPerson = (served: Served) => Asking effects {read, alloc, fail}
```

The rows of an app that one thread serves, its host's (Application.hosting): they may hold that thread's state.

### `HostedMounting`

```gizlang
type HostedMounting = (context: () => Table.Context, shell: App.Shell) => Mount effects {read, io, fail}
```

A mount of a hosted app (Hosting.mount): it may hold the thread's state.

### `Rows`

```gizlang
type Rows = { person: HostedPerson; mounts: Vec<HostedMounting>; custom: () => Vec<Model.AnyAction<Table.Context>> effects {read, fail, alloc}; }
```

The rows of a hosted app (Hosting): who asks, what answers beside the pages, and its own actions.

- `person`: `(arg0: M114.Served) => ((arg0: gizlang_http.Request) => gizlang_security.Principal) effects { fail, read, alloc }`
- `mounts`: `Vec<(arg0: () => M118.Context, arg1: _gizlang_lib_app__app.Shell) => M114.Mount effects { fail, read, io }>`
- `custom`: `() => Vec<M141.AnyAction<M118.Context>> effects { fail, read, alloc }`

### `Asking`

```gizlang
type Asking = (request: Http.Request) => Security.Principal effects {io, fail, read, write, console}
```

Who asks in one request (Person).

### `Application`

```gizlang
type Application = { folder: string; store: Sql.Database; engine: Option<Data.Engine>; feed: Option<Relay.Relay>; db: Data.Db; site: () => Site effects {fail, alloc}; shapes: Vec<Model.Shape>; theme: string; elements: Vec<App.Element>; people: Option<People>; person: Person; ownerOnlyFiles: bool; mounts: Vec<Mounting>; keeping: Option<Keeper>; custom: Actions<Table.Context>; threads: i64; ready: App.Listening; socket?: string; }
```

A site of pages over its own GizDB with the tables of `shapes`, for one person. `listen` serves it; `each`, `rows`,
`save` and `file` are the program's side of the same tables, so a row that the program writes reaches each open page
by itself.

- `folder`: `string`
- `store`: `gizlang_sql.Database`
- `engine`: `_gizlang_sdk_core.Option<M135.Engine>` — The engine of its GizDB folder when this process serves it (gizdb/app store): pages then read it on each thread.
- `feed`: `_gizlang_sdk_core.Option<M144.Relay>` — The changes of a server's store (Relay), which pages follow; none on the engine this process serves.
- `db`: `M139.Db`
- `site`: `() => M114.Site effects { fail, alloc }`
- `shapes`: `Vec<M141.Shape>`
- `theme`: `string` — The sheet of tokens of its pages (Application.theme): "" for the default theme.
- `elements`: `Vec<_gizlang_lib_app__app.Element>` — The Web Components that `enhance` adds to the page shell (Application.look), beside the grid.
- `people`: `_gizlang_sdk_core.Option<M114.People>` — Its people, when it has more than its one owner (Application.signIn).
- `person`: `(arg0: M114.Served) => ((arg0: gizlang_http.Request) => gizlang_security.Principal) effects { fail, alloc }` — Who asks in a request (Application.person).
- `ownerOnlyFiles`: `bool` — Protect /files/NAME by requiring the authenticated application's owner.
- `mounts`: `Vec<(arg0: () => M118.Context, arg1: _gizlang_lib_app__app.Shell) => M114.Mount effects { fail, io }>` — What answers beside the pages (Application.mount).
- `keeping`: `_gizlang_sdk_core.Option<() => ((arg0: string, arg1: string, arg2: string, arg3: bytes) => string throws M141.Rejection) effects { fail, io }>` — Where the files of a file input go (Application.keeps): none keeps them in the app's folder, at /files/.
- `custom`: `() => Vec<M141.AnyAction<M118.Context>> effects { fail, alloc }` — The app's own actions (Application.actions), beside the five of each table.
- `threads`: `i64` — The threads that serve it (Application.threads): 0 is one for each core (App.serving).
- `ready`: `() => void` — What runs once its port listens (Application.listening).
- `socket`: `_gizlang_sdk_core.Option<string>` — The Unix socket it serves on instead of a port (Application.at).

### `Context`

```gizlang
type Context = Table.Context
```

What a page, an action and a mount run with: the scoped records of the person of the request (`me`), the System.

### `Mount`

```gizlang
type Mount = { answer: (request: Http.Request, owner: bool) => Option<Http.ReplyPlan>; upload: (request: Http.Request) => Option<Upload> effects {read, io, fail}; }
```

What answers beside the pages of an app: bytes of any size, sent and taken as they flow (a Drive, an object
store), so no answer or upload is held whole. `answer` gives the plan of a request it takes (none: the pages answer
it); `upload` takes, from its head, a request whose body it reads as it comes (none: the request is read whole), and
answers it on its exchange. `owner` says whether the request may act as the app's owner: always for an app without
sign-in, else the owner's session. A request that carries its own credential (a signature, a token, a link) is
answered without it; any other request of a mount for someone else is left to the pages, whose sign-in refuses it.

- `answer`: `(arg0: gizlang_http.Request, arg1: bool) => _gizlang_sdk_core.Option<gizlang_http.ReplyPlan>`
- `upload`: `(arg0: gizlang_http.Request) => _gizlang_sdk_core.Option<(arg0: bool, arg1: mut gizlang_http.Exchange) => bool throws gizlang_http.HttpError> effects { fail, read, io }`

### `Upload`

```gizlang
type Upload = (owner: bool, exchange: mut Http.Exchange) => bool throws Http.HttpError
```

An upload that a mount took: it reads the body from `exchange` and answers there.

### `Mounting`

```gizlang
type Mounting = (context: () => Table.Context, shell: App.Shell) => Mount effects {io, fail}
```

Makes the mount of one serving thread from its own System and the program's tables, as the owner uses them, in the page
SHELL of the generation that serves (Application.look). CONTEXT
makes the owner's context of one request: a Gate scope is for one request, so a mount never keeps one.

### `Within`

```gizlang
type Within<S> = { open: (c: Table.Context) => S throws Model.Rejection; close: (s: S) => void; list: Vec<Model.AnyAction<S>>; }
```

The actions LIST on the context S, with what makes S for each call and what releases it after: OPEN builds S from the
request's context, and a Rejection from it is the call's answer (401, 403).

Opaque: create and use it through this module's functions.

### `Actions`

```gizlang
type Actions<C> = () => Vec<Model.AnyAction<C>> effects {fail, alloc}
```

What makes the actions of an app on each serving thread.

### `Viewing`

```gizlang
type Viewing = (context: Table.Context) => ((rest: string, request: Http.Request) => Views.Opened throws Model.Rejection) effects {io, fail}
```

Makes the views of one serving thread from its own System and the program's tables, as the owner uses them.

### `Hosted`

```gizlang
type Hosted = { answer: (request: Http.Request) => Http.ReplyPlan; uploads: Http.RequestHead; shell: App.Shell; }
```

An app that another server hosts (Application.hosted): that server owns the listener, its threads, limits and TLS.

- `answer`: `(arg0: gizlang_http.Request) => gizlang_http.ReplyPlan` — The plan of each request of the app's host, in the server's thread: its pages, mounts, actions, live polls and
the files of its shell. A test reads it whole: Http.whole(app.hosted().answer).
- `uploads`: `(arg0: gizlang_http.Request) => _gizlang_sdk_core.Option<(arg0: mut gizlang_http.Exchange) => bool throws gizlang_http.HttpError> effects { fail, read, io }` — The requests that a mount reads as they come (Mount.upload), for the server's uploads.
- `shell`: `_gizlang_lib_app__app.Shell` — The page shell whose version the app's pages carry: the server serves it for the app's host only.

### `Hosting`

```gizlang
type Hosting = { app: Application; rows: Rows; }
```

The app as one thread of its host serves it: its rows (`mount`, `person`, `actionsIn`) may then hold that thread's
state, which the rows of a threaded app may not. Set the rest before.

- `app`: `M114.Application`
- `rows`: `M114.Rows`

## Functions

### `standalone`

```gizlang
function standalone(): Host
```

A host with no database: a page that declares a table shows an empty one.

Effects: fail, write, alloc.

### `hosted`

```gizlang
function hosted(db: Data.Db, space: string, shapes: Vec<Model.Shape>, actor: Asking): Host
```

A host over the database DB of the Space SPACE: ACTOR names the person of a request, and the Gate judges every read and write of a page.
SHAPES are the tables of the pages (the ones the Space is provisioned with): the long poll of a page tells a person of the changes of rows that
the person may read, and of no other.

Effects: fail, write, alloc.

### `view`

```gizlang
function view(pattern: string, render: Render, style: string, place: string = "", revision: string = ""): Route
```

A page at PATTERN that RENDER draws, with its STYLE.

Effects: fail, alloc.

### `markdown`

```gizlang
function markdown(pattern: string, text: string, place: string = ""): Route
```

A page at PATTERN made from the Markdown TEXT.

Effects: fail, alloc.

### `file`

```gizlang
function file(pattern: string, text: string, place: string = ""): Route
```

A file at PATTERN that is served as TEXT.

Effects: fail, alloc.

### `endpoint`

```gizlang
function endpoint(pattern: string, run: Answer, place: string = "", methods: Vec<string> = []): Route
```

The handler RUN at PATTERN for every method (an API, a webhook: a .giz file of the folder that exports `handle`). It reads
the tables as the person who asks, and a request that writes is one transaction, as a page's action.

Effects: fail, alloc.

### `layout`

```gizlang
function layout(prefix: string, render: Render, style: string, revision: string = ""): Layout
```

A layout that RENDER draws around each page under PREFIX, with its STYLE.

### `guard`

```gizlang
function guard(prefix: string, before: (props: Props) => Option<Http.Response>): Guard
```

A guard that BEFORE is for each route under PREFIX (see Guard).

### `handlerMethods`

```gizlang
function handlerMethods(): Vec<string>
```

The page handler methods shared by standalone and platform routes.

Effects: fail, alloc.

### `site`

```gizlang
function site(routes: Vec<Route>, layouts: Vec<Layout>, missing: Vec<Route>, guards: Vec<Guard> = []): Site
```

The site of ROUTES. MISSING holds the not-found page, if the folder has one; GUARDS run before the routes they cover. A failing declaration (two files for one address) stops the program at start.

Effects: fail, alloc.

### `speaking`

```gizlang
function speaking(site: Site, source: string, tags: Vec<string>): Site
```

SITE in its source language SOURCE and the languages TAGS of its catalogs (`locales/ko.json` beside its pages; the `.routes` module
passes them), each at its own address (`/ko/…`).

Effects: fail, alloc.

### `byCookie`

```gizlang
function byCookie(site: Site): Site
```

SITE with its languages chosen by the person and the browser at every address, for an application behind a sign-in.

Effects: fail, alloc.

### `call`

```gizlang
function call<I, O>(context: Table.Context, name: string, input: I): O throws Model.Rejection
```

Runs the action NAME of the app that hosts the page with INPUT as the person of CONTEXT, and gives its answer: a page
calls an action by its contract (its name, input and answer types), and each app that hosts the page provides it, as
itself or as a call to another (remote). A refusal is thrown as it is; an action the app does not have is a 404.

### `remote`

```gizlang
function remote<I, O>(name: string, doc: string, at: () => Remote throws string): Model.AnyAction<Table.Context>
```

The action NAME (DOC says what it does) of the app at REMOTE (POST BASE/_a/NAME), as an action of this app: an app that
shows another's work forwards the calls of a page by the same contract (call), so the page runs in both. A refusal
comes back as the other app said it; one it cannot reach is a 503.

### `handle`

```gizlang
function handle(site: Site, shell: App.Shell, host: Host, request: Http.Request): Http.Response
```

The response for REQUEST: the page of its address, the not-found page for an address without one, and for SUBSCRIPTIONS the long poll of a
table that the page follows (`t` the table, `p` the position, `u` the address of the page): it answers the patches of the parts of the page that read
the table, after a change that the person may see.

Effects: fail, read, write, console, io, alloc.

### `shell`

```gizlang
function shell(theme: string): App.Shell
```

The page shell of a site of pages: the design system and the kernel. THEME is the site's sheet of tokens (empty: the default theme):
`Tokens.css([...uiTheme(), own overlays], false)`, or the sheet of `Tailwind.stylesheet`, whose `@theme` is the same tokens. The
components follow it in their `components` layer, so a utility class on an element beats the defaults of a component while the
component's own scoped `<style>` still beats the utility.

Effects: fail, read, write, console, io, alloc.

### `handler`

```gizlang
function handler(site: Site, shell: App.Shell, host: Host): (request: Http.Request) => Http.Response
```

The handler of SITE in SHELL on HOST, for a host of its own (the tests, a benchmark). An app serves with
`Local.app(site).listen(8080)` (gizdb/app), which gives the shell, ETags, compression, security headers and automatic HTTPS.

Effects: fail, alloc.

### `imports`

```gizlang
function imports(at: Host): Http.RequestHead
```

The streamed requests of a `handler` on HOST, for its listener's uploads (App.listenOn): the imports of its views, whose
body is read as it comes (Views.importing).

Effects: fail, alloc.

### `positionOf`

```gizlang
function positionOf(page: string): string
```

The follow id in `data-pos="…"` of the first watch of PAGE.

Effects: fail, alloc.

### `poll`

```gizlang
function poll(site: Site, shell: App.Shell, host: Host, headers: Vec<Http.Header>, table: string, id: string, address: string, state: string): string
```

The answer of the long poll of the page ADDRESS (a path, no `&`) for TABLE after the follow ID, with the state STATE (the fields of `#_g`) that the page posts;
HEADERS are the headers of the person (its session). It waits for a change.

Effects: fail, read, write, console, io, alloc.

### `nextOf`

```gizlang
function nextOf(told: string): string
```

The follow id that an answer of the poll gives for the next one.

Effects: fail, alloc.

### `fileName`

```gizlang
function fileName(f: File): string
```

The last part of the name of file F: its name without folders.

Effects: fail, alloc.

### `fileBadge`

```gizlang
function fileBadge(f: File): string
```

The short kind of file F for its card: its extension ("PDF", "PNG"), else "Text" or "File".

Effects: fail, alloc.

### `fileKind`

```gizlang
function fileKind(f: File): string
```

What file F holds, by its type (else its name): "image", "video", "audio", or "" another kind.

Effects: fail, alloc.

### `files`

```gizlang
function files(text: string): Vec<File>
```

The files that the state TEXT of a file input lists (`<input type="file" value={files}>`), oldest first.

Effects: fail, alloc.

### `frame`

```gizlang
function frame(request: Http.Request): string
```

The lazy part of its page that REQUEST asks for (the kernel's ?_frame=KEY when the part is shown), "" for the whole
page: a page renders a long part (a ModelPicker's list, `lazy`) in full only for it.

Effects: fail, alloc.

### `address`

```gizlang
function address(request: Http.Request, names: Vec<string>, values: Vec<string>, initials: Vec<string>): string
```

The address of the page for the state NAMES = VALUES: its path, and `?name=value` for each state that is not its INITIAL.

Effects: fail, alloc.

### `field`

```gizlang
function field(form: Http.Params, name: string): string
```

The last value posted under NAME, or empty.

Effects: fail.

### `text`

```gizlang
function text(form: Http.Params, name: string, initial: string): string
```

The state NAME of a page: what the form posted, else INITIAL. The state is in the page (hidden fields and bound controls), not in the server.

Effects: fail, alloc.

### `integer`

```gizlang
function integer(form: Http.Params, name: string, initial: i64): i64
```

The integer state NAME of a page: what the form posted, else INITIAL (also when the posted text is not an integer).

Effects: fail, alloc.

### `number`

```gizlang
function number(form: Http.Params, name: string, initial: f64): f64
```

The number state NAME of a page: what the form posted, else INITIAL (also when the posted text is not a number).

Effects: fail, alloc.

### `flag`

```gizlang
function flag(form: Http.Params, name: string, initial: bool): bool
```

The flag state NAME of a page: what the form posted, else INITIAL.

Effects: fail, alloc.

### `appOn`

```gizlang
function appOn(site: () => Site effects {fail, alloc}, shapes: Vec<Model.Shape>, folder: string, store: Sql.Database, engine: Option<Data.Engine>, follows: Option<Relay.Relay> = undefined): Application
```

The app of `site` (the `site` of a folder's `.routes`) in `folder` over STORE, with the tables of `shapes` made when they
are missing, and its files in `FOLDER/files`. ENGINE is STORE's GizDB engine when this process serves it (gizdb/app
app), and its pages then read it on each thread; on any other store they follow its changes through a Relay (FOLLOWS:
the host's own, one for each store), and `listen` serves on one thread. A .ts app (app/start.giz) gives its SQLite or PostgreSQL store and no engine.

    const app = Local.app(site, [Model.shape<Turn>()]);
    app.each(Query.from<Turn>().filter((it) => it.done === false), (t: Turn) => { app.save({ ...t, answer: "…", done: true }); });
    return app.listen(8080);

Effects: fail, read, write, console, io, alloc.

### `act`

```gizlang
function act<I, O>(action: Model.Action<Table.Context, I, O>, context: Table.Context, posted: Http.Params, prefix: string, controls: (input: I) => Vec<bool>): string
```

A form's action (GHTML `<form action={a}>`, and `<form create={table}>` with `adding`): A runs as the person of CONTEXT
with the fields of POSTED that begin with PREFIX, through the handler of its tool. "" when it is done, else the reason,
which the form shows as a refused write. CONTROLS names each control of the form as a field of I, so the compiler checks
the names and kinds; it never runs.

### `adding`

```gizlang
function adding<T>(table: Table.Table<T>): Model.Action<Table.Context, T, T>
```

The add tool of TABLE (add_T) as a typed Action: a `<form create={table}>` calls it as an action form calls its Action.

## Methods

### `Application.threads`

```gizlang
function Application.threads(self: Application, count: i64): Application
```

The app served on COUNT threads, not one for each core: an app of one person (GizDesk) makes each thread's handlers
and state at its start for nothing. Each thread still serves many requests at once, as tasks.

### `Application.listening`

```gizlang
function Application.listening(self: Application, run: App.Listening): Application
```

The app with RUN, which runs once its port listens and before its first request: a program that opens a window on its
own server waits for nothing.

### `Application.at`

```gizlang
function Application.at(self: Application, path: string): Application
```

The app served on the Unix socket PATH instead of a port: a program's own front end reaches it there (gizapp/host),
and no other program sees a port. Call it before `listen`.

### `Application.protectFiles`

```gizlang
function Application.protectFiles(self: Application): Application
```

Reject all file downloads except those requested by the authenticated owner.
For collaborative files, use a dedicated resource-aware policy instead of sharing a raw URL.

### `Application.keeps`

```gizlang
function Application.keeps(self: Application, keep: Keeper): Application
```

The app whose file inputs give their files to what KEEP makes (a store of its own, such as a drive) instead of the app's folder:
it answers the address a page reads the file at. Call it before `listen`.

### `Application.signIn`

```gizlang
function Application.signIn(self: Application, people: People): Application
```

The app with many PEOPLE, each signed in by gizapp Auth (its tables in schema auth): /auth/sign-in, /auth/link and
/auth/sign-out (Auth.routes), and on each page the person of the session, whose reads and writes the Gate judges; a
visitor who is not signed in is the public. PEOPLE.owner owns the tables. Call it before `listen`.

Effects: fail, read, write, console, io, alloc.

### `Application.person`

```gizlang
function Application.person(self: Application, person: Person): Application
```

The app whose requests ask as PERSON gives (a host's own sessions); its pages, actions and mounts see that person.
Its owner is the one of signIn, else ME.

### `Application.actions`

```gizlang
function Application.actions(self: Application, made: Actions<Table.Context>): Application
```

The app with its own actions (Model.action) beside the five of each table: each is listed at GET /_tools and runs at
POST /_a/NAME, and a page's form or data-a calls it by its id. MADE makes them on each serving thread, so it holds no
state of the caller's thread. Call it before `listen`.

Effects: fail, alloc.

### `Application.actionsIn`

```gizlang
function Application.actionsIn<S>(self: Application, made: () => Within<S> effects {fail, alloc}): Application
```

The app with its own actions on the app's own context S (Model.action<S, I, O>), which MADE makes on each serving
thread with their OPEN and CLOSE (Within), after the ones it has. Agents, the JSON API and the pages call the actions
alike.

### `Application.theme`

```gizlang
function Application.theme(self: Application, theme: string): Application
```

The app in the theme THEME, a sheet of tokens (Pages.shell): `Tokens.css([...Web.uiTheme(), brand], false)` or the sheet of
`Tailwind.stylesheet`. Call it before `listen`.

### `Application.admin`

```gizlang
function Application.admin(self: Application, prefix: string): Application
```

The app with the admin screens of its tables under PREFIX ("/admin"): a list, a record and a new record of each
(gizapp/admin), in the page shell of the app; their forms post to the tables' tools. They answer the owner only. Call
it before `listen`.

Effects: fail, io, alloc.

### `Application.account`

```gizlang
function Application.account(self: Application, email: string, name: string, password: string): string throws string
```

The id of the account EMAIL among the app's people (schema auth): signed in with PASSWORD, or made with NAME on the first
run, for `People.owner`. An account that exists with another password is refused, never overwritten.

Effects: fail, read, write, console, io, alloc.

### `Application.mount`

```gizlang
function Application.mount(self: Application, mounting: Mounting): Application
```

The app with `mounting` answering beside its pages (Mount). Call it before `listen`.

Effects: fail, alloc.

### `Application.view`

```gizlang
function Application.view(self: Application, name: string, viewing: Viewing): Application
```

The app with the views of `viewing` at `/_view/NAME/REST`, beside its tables at `/_view/TABLE`: one protocol and one element
(`<giz-grid>`, `<giz-chart>`) for every relation. They answer the owner only, since `viewing` opens them as the owner. NAME is
not a table's name. Call it before `listen`.

Effects: fail, alloc.

### `Application.context`

```gizlang
function Application.context(self: Application): Table.Context
```

The program's table context, under the same owner and Gate as add/save.

Effects: fail, read, write, console, io, alloc.

### `Application.listen`

```gizlang
function Application.listen(self: Application, port: i64): i64
```

Serves the pages on `port` (Web.listen: a thread for each CPU, one on a server's store, and HTTPS with HTTP/2 and
HTTP/3 when TLS_DOMAINS names the site), and the files of `file` at /files/NAME; the exit status.

Effects: fail, read, write, console, io, alloc.

### `Application.enhance`

```gizlang
function Application.enhance(self: Application, tag: string, script: bytes, style: bytes): Application throws string
```

The app with the Web Component TAG (App.enhancement): its ES module SCRIPT and its STYLE, which a page loads only when it
holds the tag. Call it before `listen`.

Effects: fail, alloc.

### `Application.built`

```gizlang
function Application.built(self: Application, dist: string, names: Vec<string>): Application throws string
```

The app with the elements NAMES that app/components builds into DIST (App.elements). Call it before `listen`.

Effects: fail, io, alloc.

### `Application.components`

```gizlang
function Application.components(self: Application, names: Vec<string>): Application throws string
```

The app with the components NAMES that app/components builds into `app/components/dist` (chart, desktop, terminal):
from the first built folder of the working folder's, the one beside the program (an app shipped with its components)
and the toolchain's checkout's (GIZLANG_ROOT).

Effects: fail, io, alloc.

### `Application.hosted`

```gizlang
function Application.hosted(self: Application): Hosted
```

The app hosted in another server's thread, its System there (Hosting.hosted).

Effects: fail, read, write, console, io, alloc.

### `Application.hosting`

```gizlang
function Application.hosting(self: Application): Hosting
```

The app with its rows set so far, as one thread of its host serves it (Hosting).

Effects: fail, alloc.

### `Hosting.mount`

```gizlang
function Hosting.mount(self: Hosting, mounting: HostedMounting): Hosting
```

The hosted app with `mounting` answering beside its pages (Application.mount).

Effects: fail, alloc.

### `Hosting.person`

```gizlang
function Hosting.person(self: Hosting, person: HostedPerson): Hosting
```

The hosted app whose requests ask as PERSON gives (Application.person).

### `Hosting.actionsIn`

```gizlang
function Hosting.actionsIn<S>(self: Hosting, w: Within<S>): Hosting
```

The hosted app with its own actions on the context S that W gives, after the ones it has (Application.actionsIn).

### `Hosting.hosted`

```gizlang
function Hosting.hosted(self: Hosting): Hosted
```

The app hosted in another server's thread with OWN, its System there. A known limit: `giz live` does not renew a
hosted app's pages; the server makes it again.

Effects: fail, read, write, console, io, alloc.

### `Application.from`

```gizlang
function Application.from<T>(self: Application): Query.Query<T>
```

Every row of the table of T, as a Query that the app's database runs: `app.from<Task>().filter((t) => !t.done).rows()!`.

### `Application.add`

```gizlang
function Application.add<T>(self: Application, v: T): T throws Model.Rejection
```

Adds the row V to the table of T, and gives it as added: an empty text key is made, and sorts by time. A row the
database refuses (its Gate, a missing or doubled key) throws its Rejection, with the status and the reason.

### `Application.save`

```gizlang
function Application.save<T>(self: Application, v: T): void throws Model.Rejection
```

Writes the row V of the table of T: each page that shows it changes by itself. A refusal throws, as `add`.

### `Application.remove`

```gizlang
function Application.remove<T>(self: Application, v: T): void throws Model.Rejection
```

Deletes the row V of the table of T: each page that shows it drops it. A refusal throws, as `add`.

### `Application.each`

```gizlang
function Application.each<T>(self: Application, find: Query.Query<T>, handle: (v: T) => void): void
```

Calls `handle` for each row of T that FIND selects, now and whenever one comes or changes, one at a time, from a task
of its own: a queue of work in a table. `handle` saves the row so that FIND no longer selects it (`done = true`), else
it is handled again.

