dimah-surveyv0.5.0
Surveys

Draft and publish

Save an editor draft, publish it, and leave responses already started unchanged.

A survey keeps three things separate: the editor draft (draftJson), the published document, and settings. Creator writes the draft. Respondents see a survey only after you publish it.

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

Prop

Type

saveSurvey replaces draftJson. It does not publish, change settings, or update a response.

Status

StatusMeaningCan start a response?
draftNothing has been publishedNo; NOT_PUBLISHED
activeThe published survey is openYes, while policy allows
archivedCollection is stopped; the publish is keptNo; NOT_PUBLISHED

Fill can read publishedJson and settings for an active survey. It never returns draftJson. The read stays available outside the collection window, so the app can show that the survey is closed. Start and writes then fail with SURVEY_CLOSED.

Operations

OperationEffect
saveSurveyCreate the survey or replace draftJson. Default settings are inserted once
publishSurveyPublish the draft, set active, and update publishedAt
archiveSurveySet archived. The draft and the published document stay
resumeSurveyMake an archived survey active again
saveSurveySettingsReplace settings. The draft and the published document stay

resumeSurvey restores the last published document. It does not publish the current draft. An active survey comes back unchanged. An archived survey that was never published fails with NOT_PUBLISHED.

onPublish runs before the write and may abort it. afterPublish runs after the row is stored; a failure there leaves the publish in place. See Configuration.

IDs and slugs

You choose id. On create, slug defaults to that id and must be unique. A conflict throws SLUG_TAKEN.

getSurvey, getPublishedSurvey, and startResponse accept an id or a slug.

Concurrent edits

Draft, publish, archive, settings, and resume accept expectedUpdatedAt from the last read. The store compares it inside the write and rejects a stale request with STALE_UPDATE.

Omit the token only when the last write should win. A create that includes expectedUpdatedAt fails with STALE_UPDATE, because there is no row to compare.

useSurveyDraft sends the token it last read. See Creator.

The published survey

Publishing stores the current draft. The same stored document is reused when nothing changed; any change stores a new one. Responses already started keep the survey they began with. Only a new response uses the latest publish.

listSurveyVersions returns that history, newest first. listResponses with include: "full" returns answer data and each referenced document once.

On this page