Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,19 @@ generate surveys rather than convert them:
import { QUESTION_TYPES, APPEARANCES, TYPE_MAPPINGS } from '@correlaid/formtransform';

QUESTION_TYPES.select_one.label; // "Select One"
QUESTION_TYPES.select_one.labels.de; // "Einfachauswahl"
QUESTION_TYPES.select_one.useWhen; // when to reach for this type
QUESTION_TYPES.select_one_other.base; // "select_one" — a variant of it
QUESTION_TYPES.select_one_other.presentation; // { withOther: true, withLongList: false }
QUESTION_TYPES.grid.bases; // composites span several types
QUESTION_TYPES.select_one.constraints; // name/choice-code limits
APPEARANCES.label.carriesData; // false — a matrix header stores no answer
TYPE_MAPPINGS.select_one.limeSurveyType; // "L" — how it converts
```

`QUESTION_TYPES` is keyed by registry slug and answers *what a row can be*
(label, guidance, variant → base, authoring constraints, metadata rows);
(labels in English and German, guidance, variant → base and presentation,
authoring constraints, metadata rows);
`TYPE_MAPPINGS` answers *how it converts*. Both are generated from `registry/` —
never hardcode a type list or a label in a consumer.

Expand Down
25 changes: 24 additions & 1 deletion codegen/emit_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,16 @@ def _entry_lines(
is_composite: bool,
aliases: list[str] | None = None,
constraints: dict[str, Any] | None = None,
label_de: str | None = None,
presentation: dict[str, Any] | None = None,
) -> list[str]:
"""One `QUESTION_TYPES` record entry."""
labels = {"en": label, **({"de": label_de} if label_de else {})}
lines = [
f" {_ts_key(key)}: {{",
f" id: {json.dumps(entry_id)},",
f" label: {json.dumps(label, ensure_ascii=False)},",
f" labels: {json.dumps(labels, ensure_ascii=False)},",
f" kind: {json.dumps(kind)},",
f" useWhen: {json.dumps(use_when, ensure_ascii=False)},",
f" isVariant: {'true' if is_variant else 'false'},",
Expand All @@ -442,6 +446,8 @@ def _entry_lines(
lines.append(f" aliases: {json.dumps(aliases)},")
if constraints:
lines.append(f" constraints: {json.dumps(constraints, ensure_ascii=False)},")
if presentation:
lines.append(f" presentation: {json.dumps(presentation, ensure_ascii=False)},")
lines.append(" },")
return lines

Expand Down Expand Up @@ -490,8 +496,13 @@ def generate_question_types(registry: dict[str, Any], output: Path):
" * a composite spans several rows, so it has no single type cell.",
" */",
" typeString?: string;",
" /** Display label, from `skos:prefLabel`. */",
" /** Display label in English, from `skos:prefLabel`. */",
" label: string;",
" /**",
" * Display label per language: `en` (`label`) and, where the registry",
" * has one, `de` (`skos:prefLabel@de`, the `prefLabelDe` term).",
" */",
" labels: { readonly en: string; readonly de?: string };",
" /** Methodology guidance, from `useWhen`. Empty for structural rows. */",
" useWhen: string;",
" kind: 'question' | 'metadata' | 'structural';",
Expand All @@ -504,6 +515,15 @@ def generate_question_types(registry: dict[str, Any], output: Path):
" /** Accepted alternative `type` strings (e.g. `string` for `text`). */",
" aliases?: readonly string[];",
" constraints?: QuestionTypeConstraints;",
" /**",
" * A variant's modifiers, from the registry's `presentation`: an \"other\"",
" * answer with a text field, a long list (and its appearance).",
" */",
" presentation?: {",
" readonly withOther: boolean;",
" readonly withLongList: boolean;",
" readonly appearanceString?: string;",
" };",
"}",
"",
"/**",
Expand Down Expand Up @@ -531,6 +551,7 @@ def broader_slugs(data: dict[str, Any]) -> list[str]:
entry_id=type_id,
type_string=data["xlsform"]["typeString"],
label=data.get("skos:prefLabel", slug),
label_de=data.get("prefLabelDe"),
kind=kinds[t],
use_when=data.get("useWhen", ""),
bases=[],
Expand All @@ -552,11 +573,13 @@ def broader_slugs(data: dict[str, Any]) -> list[str]:
entry_id=type_id,
type_string=type_string,
label=data.get("skos:prefLabel", slug),
label_de=data.get("prefLabelDe"),
kind="question",
use_when=data.get("useWhen", ""),
bases=bases,
is_variant=is_variant,
is_composite=not is_variant,
presentation=data.get("presentation"),
)

# Metadata rows are not registry entities — they come from the
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/date/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:date",
"@type": "QuestionType",
"skos:prefLabel": "Date",
"prefLabelDe": "Datum",
"xlsform": {
"typeString": "date"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/decimal/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:decimal",
"@type": "QuestionType",
"skos:prefLabel": "Decimal/Float",
"prefLabelDe": "Dezimalzahl",
"xlsform": {
"typeString": "decimal"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/grid/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "composite:grid",
"@type": "Composite",
"skos:prefLabel": "Grid / Matrix Group",
"prefLabelDe": "Matrix-Gruppe",
"skos:broader": [
{
"@id": "type:begin_group"
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/integer/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:integer",
"@type": "QuestionType",
"skos:prefLabel": "Integer",
"prefLabelDe": "Ganzzahl",
"xlsform": {
"typeString": "integer",
"aliases": [
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/note/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:note",
"@type": "QuestionType",
"skos:prefLabel": "Note (Display Text)",
"prefLabelDe": "Hinweis (Anzeigetext)",
"xlsform": {
"typeString": "note"
},
Expand Down
10 changes: 9 additions & 1 deletion registry/entities/range/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:range",
"@type": "QuestionType",
"skos:prefLabel": "Range",
"prefLabelDe": "Schieberegler",
"xlsform": {
"typeString": "range",
"parameters": {
Expand All @@ -30,7 +35,10 @@
},
"integerOnly": {
"attribute": "num_value_int_only",
"whenWhole": ["start", "step"]
"whenWhole": [
"start",
"step"
]
}
},
"ddi": {
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_multiple/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:select_multiple",
"@type": "QuestionType",
"skos:prefLabel": "Select Multiple",
"prefLabelDe": "Mehrfachauswahl",
"xlsform": {
"typeString": "select_multiple",
"requiresListName": true
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_multiple_long_list/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "variant:select_multiple_long_list",
"@type": "QuestionTypeVariant",
"skos:prefLabel": "Select Multiple (Long List)",
"prefLabelDe": "Mehrfachauswahl (lange Liste)",
"skos:broader": {
"@id": "type:select_multiple"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_multiple_other/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "variant:select_multiple_other",
"@type": "QuestionTypeVariant",
"skos:prefLabel": "Select Multiple with Other",
"prefLabelDe": "Mehrfachauswahl mit „Sonstiges“",
"skos:broader": {
"@id": "type:select_multiple"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_one/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:select_one",
"@type": "QuestionType",
"skos:prefLabel": "Select One",
"prefLabelDe": "Einfachauswahl",
"xlsform": {
"typeString": "select_one",
"requiresListName": true
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_one_long_list/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "variant:select_one_long_list",
"@type": "QuestionTypeVariant",
"skos:prefLabel": "Select One (Long List)",
"prefLabelDe": "Einfachauswahl (lange Liste)",
"skos:broader": {
"@id": "type:select_one"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/select_one_other/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "variant:select_one_other",
"@type": "QuestionTypeVariant",
"skos:prefLabel": "Select One with Other",
"prefLabelDe": "Einfachauswahl mit „Sonstiges“",
"skos:broader": {
"@id": "type:select_one"
},
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/text/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:text",
"@type": "QuestionType",
"skos:prefLabel": "Text (Short Free Text)",
"prefLabelDe": "Text (kurze Freitextantwort)",
"xlsform": {
"typeString": "text",
"aliases": [
Expand Down
5 changes: 5 additions & 0 deletions registry/entities/time/definition.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"@version": 1.1,
"@vocab": "https://civic-data.de/survey/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabelDe": {
"@id": "skos:prefLabel",
"@language": "de"
},
"type": "https://civic-data.de/survey/type/",
"variant": "https://civic-data.de/survey/variant/",
"composite": "https://civic-data.de/survey/composite/"
Expand All @@ -12,6 +16,7 @@
"@id": "type:time",
"@type": "QuestionType",
"skos:prefLabel": "Time",
"prefLabelDe": "Uhrzeit",
"xlsform": {
"typeString": "time"
},
Expand Down
Loading
Loading