# API reference

> Every import path and export of asasvirtuais, with props and return values of Form, ActionProvider, table forms, providers, hooks and the interface types.

Source: https://asasvirtuais.com/docs/api-reference

| Import | Exports |
|---|---|
| `asasvirtuais/form` | `Form`, `useForm` |
| `asasvirtuais/fields` | `FieldsProvider`, `useFields`, `useField` |
| `asasvirtuais/action` | `ActionProvider`, `useAction` |
| `asasvirtuais/forms` | `CreateForm`, `UpdateForm`, `FilterForm`, `useCreateForm`, `useUpdateForm`, `useFilterForm` |
| `asasvirtuais/context` | `InterfaceProvider`, `TablesProvider`, `useTable`, `useInterface` |
| `asasvirtuais/registry` | `TableProvider`, `SingleProvider`, `useSingle(schema, table)` |
| `asasvirtuais/single` | `SingleProvider`, `useSingle(schema)` |
| `asasvirtuais/interface` | `asasvirtuaisInterface`, `TableInterface`, `Query`, `TableSchema`, `DatabaseSchema`, `FindProps`, `ListProps`, `CreateProps`, `UpdateProps`, `RemoveProps` |
| `asasvirtuais/hooks` | `useAction`, `useIndex` |

## Form

```tsx
<Form defaults={...} action={async fields => result} onResult={result => ...} onError={error => ...} autoTrigger>
  {form => ...}
</Form>
```

Render props and `useForm()`: `fields`, `setField`, `setFields`, `submit`, `callback(params)`, `loading`, `result`,
`error`, `errors`.

## FieldsProvider

`<FieldsProvider defaults={...}>`. `useFields()` returns `fields`, `setField`, `setFields`, `defaults`.
`useField(key)` returns `{ value, setValue }`.

## ActionProvider

`<ActionProvider action={...} params={...} onResult onError autoTrigger>`. `useAction()` returns `loading`, `result`,
`error`, `errors`, `submit`, `callback`, `params`.

## Table forms

| Component | Props |
|---|---|
| `CreateForm` | `table`, `schema`, `defaults?`, `onSuccess?(row)` |
| `UpdateForm` | `table`, `schema`, `id`, `defaults?`, `onSuccess?(row)` |
| `FilterForm` | `table`, `schema`, `defaults?` (`{ query }`), `autoTrigger?`, `onSuccess?(rows)` |

## Providers

| Component | Props |
|---|---|
| `InterfaceProvider` | `find`, `list`, `create`, `update`, `remove` |
| `TableProvider` | `table`, `schema`, `asAbove?` (rows keyed by id) |
| `TablesProvider` | `tables` (schemas by table name), mounted without rows |
| `SingleProvider` | `id`, `table`, `schema`; children or a render prop `({ single }) => ...` |

`useTable(table, schema)` returns the table's index (`array`, `index`, `set`, `unset`, `setIndex`) and the operations
`find`, `list`, `create`, `update`, `remove`, each with `.trigger(props)`.

## Interface

```ts
interface TableInterface<Readable, Writable = Readable> {
  find(props: FindProps): Promise<Readable>
  list(props: ListProps<Readable>): Promise<Readable[]>
  create(props: CreateProps<Writable>): Promise<Readable>
  update(props: UpdateProps<Writable>): Promise<Readable>
  remove(props: RemoveProps): Promise<Readable>
}

interface FindProps   { table?: string, id: string }
interface ListProps   { table?: string, query?: Query }
interface CreateProps { table?: string, data: Writable }
interface UpdateProps { table?: string, id: string, data: Partial<Writable> }
interface RemoveProps { table?: string, id: string }
```

`asasvirtuaisInterface(schema, implementation)` types an implementation by one table's schema or by the whole database
schema.
