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
| Status | Meaning | Can start a response? |
|---|---|---|
draft | Nothing has been published | No; NOT_PUBLISHED |
active | The published survey is open | Yes, while policy allows |
archived | Collection is stopped; the publish is kept | No; 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
| Operation | Effect |
|---|---|
saveSurvey | Create the survey or replace draftJson. Default settings are inserted once |
publishSurvey | Publish the draft, set active, and update publishedAt |
archiveSurvey | Set archived. The draft and the published document stay |
resumeSurvey | Make an archived survey active again |
saveSurveySettings | Replace 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.