# Configuration (https://survey.dimah.dev/docs/configuration)



Fill and editor have separate configuration types because they expose different
trust boundaries. Both require the same `database`; only fill accepts response
validation and only editor accepts publish hooks.

## Fill instance [#fill-instance]

```ts
import {
  dimahSurvey,
  guardAnonymous,
  memoryAdapter,
} from "@dimah-survey/server";

export const fill = dimahSurvey({
  audience: "fill",
  database: memoryAdapter(),
  guard: guardAnonymous(),
});
```

```ts
import type { DimahFillConfig } from "@dimah-survey/server";
```

<AutoTypeTable path="packages/server/src/dimah-survey.ts" name="DimahFillConfig" />

`checkSurveyResult` drops values that cannot be assigned, runs `validate`, and
returns the `survey.data` to persist. Questions with `choicesByUrl` keep their
posted value. The server does not fetch that list.

A custom `validateResult` receives `{ definition, data }`. Return the object to
store. Return nothing to keep `data`. Throw `APIError` with `VALIDATION_FAILED`
to reject the submit. See [Responses](https://survey.dimah.dev/docs/responses.md).

### guard [#guard]

```ts
import type { GuardContext } from "@dimah-survey/core";
```

<AutoTypeTable path="packages/core/src/types.ts" name="GuardContext" />

Returning nothing from a fill guard is forbidden. `guardRespondent(id)` returns
`{ respondentId }`. `guardAnonymous()` returns `{ anonymous: true }`.

### Lifecycle hooks [#lifecycle-hooks]

```ts
import type { FillHooks } from "@dimah-survey/server";
```

<AutoTypeTable path="packages/server/src/dimah-survey.ts" name="FillHooks" />

A start that returns an existing row does not call `onStart` or `afterStart`.
A replayed submit does not call `onSubmit` or `afterSubmit`. The HTTP body
cannot carry these hooks.

## Editor instance [#editor-instance]

```ts
import { dimahSurvey } from "@dimah-survey/server";

export const editor = dimahSurvey({
  audience: "editor",
  database,
});
```

```ts
import type { DimahEditorConfig } from "@dimah-survey/server";
```

<AutoTypeTable path="packages/server/src/dimah-survey.ts" name="DimahEditorConfig" />

```ts
import type { EditorHooks } from "@dimah-survey/server";
```

<AutoTypeTable path="packages/server/src/dimah-survey.ts" name="EditorHooks" />

## Browser clients [#browser-clients]

`createFillClient` and `createEditorClient` accept the same options. Only the
default `baseURL` differs.

```ts
import type { CreateSurveyClientOptions } from "@dimah-survey/react";
```

<AutoTypeTable path="packages/core/src/client.ts" name="CreateSurveyClientOptions" />

Browser methods take flat objects. `fill.api` and `editor.api` take `{ body }`
or `{ query }`, plus optional `headers` or `request` for guards. See
[Mount the server](https://survey.dimah.dev/docs/integration.md).

## React [#react]

```ts
import type { UseSurveyResponseOptions } from "@dimah-survey/react";
```

<AutoTypeTable path="packages/react/src/use-survey-response.ts" name="UseSurveyResponseOptions" />

Returned state is documented in [React](https://survey.dimah.dev/docs/react.md).

```ts
import type { UseSurveyDraftOptions } from "@dimah-survey/react";
```

<AutoTypeTable path="packages/react/src/use-survey-draft.ts" name="UseSurveyDraftOptions" />

The hook does not construct Creator. See [Creator](https://survey.dimah.dev/docs/creator.md).
