dimah-survey
API reference

Configuration

Configure server audiences, browser clients, validation, hooks, and React bindings.

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

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

export const fill = dimahSurvey({
  audience: "fill",
  database: memoryAdapter(),
  guard: guardAnonymous(),
});
import type { DimahFillConfig } from "@dimah-survey/server";

Prop

Type

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.

guard

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

Prop

Type

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

Lifecycle hooks

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

Prop

Type

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

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

export const editor = dimahSurvey({
  audience: "editor",
  database,
});
import type { DimahEditorConfig } from "@dimah-survey/server";

Prop

Type

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

Prop

Type

Browser clients

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

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

Prop

Type

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.

React

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

Prop

Type

Returned state is documented in React.

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

Prop

Type

The hook does not construct Creator. See Creator.

On this page