@form-engine-ts/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/index.cjs +790 -0
- package/dist/index.d.cts +211 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.js +749 -0
- package/package.json +47 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "number" | "rating" | "select" | "multi-select" | "checkbox" | "radio";
|
|
2
|
+
type ConditionOperator = "equals" | "not_equals" | "contains" | "not_empty";
|
|
3
|
+
type ConditionValue = string | number | boolean;
|
|
4
|
+
interface DisplayCondition {
|
|
5
|
+
readonly questionId: string;
|
|
6
|
+
readonly operator: ConditionOperator;
|
|
7
|
+
readonly value?: ConditionValue;
|
|
8
|
+
}
|
|
9
|
+
type ValidationCode = "required" | "invalid_type" | "min_length" | "max_length" | "pattern" | "min" | "max" | "step" | "invalid_option" | "min_selections" | "max_selections" | "unknown_field";
|
|
10
|
+
interface FieldOption {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
}
|
|
14
|
+
interface BaseField {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly type: FieldType;
|
|
17
|
+
readonly title: string;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly translationKey?: string;
|
|
20
|
+
readonly required: boolean;
|
|
21
|
+
readonly messages?: Partial<Record<ValidationCode, string>>;
|
|
22
|
+
readonly displayCondition?: DisplayCondition;
|
|
23
|
+
}
|
|
24
|
+
interface TextField extends BaseField {
|
|
25
|
+
readonly type: "text" | "textarea";
|
|
26
|
+
readonly placeholderKey?: string;
|
|
27
|
+
readonly minLength?: number;
|
|
28
|
+
readonly maxLength?: number;
|
|
29
|
+
readonly pattern?: string;
|
|
30
|
+
}
|
|
31
|
+
interface NumberField extends BaseField {
|
|
32
|
+
readonly type: "number";
|
|
33
|
+
readonly placeholderKey?: string;
|
|
34
|
+
readonly min?: number;
|
|
35
|
+
readonly max?: number;
|
|
36
|
+
readonly step?: number;
|
|
37
|
+
}
|
|
38
|
+
interface RatingField extends BaseField {
|
|
39
|
+
readonly type: "rating";
|
|
40
|
+
readonly min?: number;
|
|
41
|
+
readonly max?: number;
|
|
42
|
+
}
|
|
43
|
+
interface SelectField extends BaseField {
|
|
44
|
+
readonly type: "select" | "radio";
|
|
45
|
+
readonly options: readonly FieldOption[];
|
|
46
|
+
}
|
|
47
|
+
interface MultiSelectField extends BaseField {
|
|
48
|
+
readonly type: "multi-select";
|
|
49
|
+
readonly options: readonly FieldOption[];
|
|
50
|
+
readonly minSelections?: number;
|
|
51
|
+
readonly maxSelections?: number;
|
|
52
|
+
}
|
|
53
|
+
interface CheckboxField extends BaseField {
|
|
54
|
+
readonly type: "checkbox";
|
|
55
|
+
}
|
|
56
|
+
type FormField = TextField | NumberField | RatingField | SelectField | MultiSelectField | CheckboxField;
|
|
57
|
+
interface FormSchema {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly version: number;
|
|
60
|
+
readonly title: string;
|
|
61
|
+
readonly description?: string;
|
|
62
|
+
readonly submitLabelKey?: string;
|
|
63
|
+
readonly fields: readonly FormField[];
|
|
64
|
+
}
|
|
65
|
+
type FormValue = string | number | boolean | readonly string[] | undefined;
|
|
66
|
+
type FormValues = Readonly<Record<string, FormValue>>;
|
|
67
|
+
interface SchemaIssue {
|
|
68
|
+
readonly path: string;
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly message: string;
|
|
71
|
+
}
|
|
72
|
+
type SchemaValidationResult = {
|
|
73
|
+
readonly valid: true;
|
|
74
|
+
readonly value: FormSchema;
|
|
75
|
+
readonly issues: readonly [];
|
|
76
|
+
} | {
|
|
77
|
+
readonly valid: false;
|
|
78
|
+
readonly issues: readonly SchemaIssue[];
|
|
79
|
+
};
|
|
80
|
+
interface ValidationIssue {
|
|
81
|
+
readonly fieldId: string;
|
|
82
|
+
readonly code: ValidationCode;
|
|
83
|
+
readonly messageKey: string;
|
|
84
|
+
readonly params: Readonly<Record<string, string | number>>;
|
|
85
|
+
}
|
|
86
|
+
type AnswerValidationResult = {
|
|
87
|
+
readonly valid: true;
|
|
88
|
+
readonly issues: readonly [];
|
|
89
|
+
} | {
|
|
90
|
+
readonly valid: false;
|
|
91
|
+
readonly issues: readonly ValidationIssue[];
|
|
92
|
+
};
|
|
93
|
+
interface FormSubmission {
|
|
94
|
+
readonly id: string;
|
|
95
|
+
readonly formId: string;
|
|
96
|
+
readonly formVersion: number;
|
|
97
|
+
readonly locale: string;
|
|
98
|
+
readonly values: FormValues;
|
|
99
|
+
readonly submittedAt: string;
|
|
100
|
+
}
|
|
101
|
+
interface TranslationAdapter {
|
|
102
|
+
translate(key: string, locale: string, params?: Readonly<Record<string, string | number>>): string;
|
|
103
|
+
}
|
|
104
|
+
interface AsyncTranslationAdapter {
|
|
105
|
+
translateText(text: string, targetLocale: string, sourceLocale?: string): Promise<string>;
|
|
106
|
+
translateBatch(texts: readonly string[], targetLocale: string, sourceLocale?: string): Promise<readonly string[]>;
|
|
107
|
+
}
|
|
108
|
+
interface StorageAdapter {
|
|
109
|
+
saveSubmission(submission: FormSubmission): Promise<void>;
|
|
110
|
+
listSubmissions(formId: string, formVersion?: number): Promise<readonly FormSubmission[]>;
|
|
111
|
+
clearResponses?(formId: string): Promise<void>;
|
|
112
|
+
clear(): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
interface FormStorageAdapter extends StorageAdapter {
|
|
115
|
+
saveSchema(schema: FormSchema): Promise<void>;
|
|
116
|
+
getSchema(formId: string, formVersion: number): Promise<FormSchema | null>;
|
|
117
|
+
listSchemas(): Promise<readonly FormSchema[]>;
|
|
118
|
+
deleteSchema(formId: string, formVersion: number): Promise<void>;
|
|
119
|
+
deleteSubmission(submissionId: string): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
interface BaseQuestionAggregate {
|
|
122
|
+
readonly fieldId: string;
|
|
123
|
+
readonly answeredCount: number;
|
|
124
|
+
readonly unansweredCount: number;
|
|
125
|
+
}
|
|
126
|
+
interface TextQuestionAggregate extends BaseQuestionAggregate {
|
|
127
|
+
readonly kind: "text" | "textarea";
|
|
128
|
+
}
|
|
129
|
+
interface NumberQuestionAggregate extends BaseQuestionAggregate {
|
|
130
|
+
readonly kind: "number" | "rating";
|
|
131
|
+
readonly minimum: number | null;
|
|
132
|
+
readonly maximum: number | null;
|
|
133
|
+
readonly average: number | null;
|
|
134
|
+
readonly total: number;
|
|
135
|
+
}
|
|
136
|
+
interface OptionAggregate {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly count: number;
|
|
139
|
+
readonly percentageOfSubmissions: number;
|
|
140
|
+
}
|
|
141
|
+
interface ChoiceQuestionAggregate extends BaseQuestionAggregate {
|
|
142
|
+
readonly kind: "select" | "radio" | "multi-select";
|
|
143
|
+
readonly options: readonly OptionAggregate[];
|
|
144
|
+
}
|
|
145
|
+
interface CheckboxQuestionAggregate extends BaseQuestionAggregate {
|
|
146
|
+
readonly kind: "checkbox";
|
|
147
|
+
readonly trueCount: number;
|
|
148
|
+
readonly falseCount: number;
|
|
149
|
+
readonly truePercentageOfSubmissions: number;
|
|
150
|
+
readonly falsePercentageOfSubmissions: number;
|
|
151
|
+
}
|
|
152
|
+
type QuestionAggregate = TextQuestionAggregate | NumberQuestionAggregate | ChoiceQuestionAggregate | CheckboxQuestionAggregate;
|
|
153
|
+
interface FormAnalytics {
|
|
154
|
+
readonly formId: string;
|
|
155
|
+
readonly formVersion: number;
|
|
156
|
+
readonly submissionCount: number;
|
|
157
|
+
readonly questions: readonly QuestionAggregate[];
|
|
158
|
+
}
|
|
159
|
+
type Question = FormField;
|
|
160
|
+
type QuestionType = FieldType;
|
|
161
|
+
type ChoiceOption = FieldOption;
|
|
162
|
+
type FormResponse = FormSubmission;
|
|
163
|
+
|
|
164
|
+
interface ChoiceDistributionEntry {
|
|
165
|
+
readonly count: number;
|
|
166
|
+
readonly percentage: number;
|
|
167
|
+
}
|
|
168
|
+
interface NumericSummary {
|
|
169
|
+
readonly average: number | null;
|
|
170
|
+
readonly min: number | null;
|
|
171
|
+
readonly max: number | null;
|
|
172
|
+
readonly total: number;
|
|
173
|
+
}
|
|
174
|
+
declare function calculateChoiceDistribution(responses: readonly FormSubmission[], questionId: string): Record<string, ChoiceDistributionEntry>;
|
|
175
|
+
declare function calculateNumericSummary(responses: readonly FormSubmission[], questionId: string): NumericSummary;
|
|
176
|
+
declare function aggregateResponses(schema: FormSchema, submissions: readonly FormSubmission[]): FormAnalytics;
|
|
177
|
+
declare function escapeCsvCell(value: string | number | null | undefined): string;
|
|
178
|
+
interface CsvExportOptions {
|
|
179
|
+
readonly withBom?: boolean;
|
|
180
|
+
}
|
|
181
|
+
declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
|
|
182
|
+
|
|
183
|
+
type SchemaStructureIssueType = "dangling_condition_reference" | "duplicate_question_id" | "duplicate_choice_id" | "self_condition_reference" | "cyclic_condition_reference";
|
|
184
|
+
interface SchemaStructureIssue {
|
|
185
|
+
readonly type: SchemaStructureIssueType;
|
|
186
|
+
readonly questionId: string;
|
|
187
|
+
readonly choiceId?: string;
|
|
188
|
+
readonly message: string;
|
|
189
|
+
}
|
|
190
|
+
declare function validateSchemaStructure(schema: FormSchema): SchemaStructureIssue[];
|
|
191
|
+
declare function sanitizeSchema(schema: FormSchema): FormSchema;
|
|
192
|
+
|
|
193
|
+
declare function validateFormSchema(input: unknown): SchemaValidationResult;
|
|
194
|
+
declare function assertValidFormSchema(input: unknown): asserts input is FormSchema;
|
|
195
|
+
|
|
196
|
+
interface CreateSubmissionOptions {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly locale: string;
|
|
199
|
+
readonly submittedAt: string;
|
|
200
|
+
}
|
|
201
|
+
declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
|
|
202
|
+
|
|
203
|
+
declare function resolveFormTranslation(schema: FormSchema, adapter: AsyncTranslationAdapter, targetLocale: string, sourceLocale?: string): Promise<FormSchema>;
|
|
204
|
+
|
|
205
|
+
declare function validateAnswers(schema: FormSchema, values: FormValues): AnswerValidationResult;
|
|
206
|
+
|
|
207
|
+
declare function isQuestionVisible(question: FormField, currentAnswers: Readonly<Record<string, unknown>>): boolean;
|
|
208
|
+
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
209
|
+
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
210
|
+
|
|
211
|
+
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CsvExportOptions, type DisplayCondition, type FieldOption, type FieldType, type FormAnalytics, type FormField, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type MultiSelectField, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type Question, type QuestionAggregate, type QuestionType, type RatingField, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaValidationResult, type SelectField, type StorageAdapter, type TextField, type TextQuestionAggregate, type TranslationAdapter, type ValidationCode, type ValidationIssue, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateFieldVisibility, calculateNumericSummary, createSubmission, escapeCsvCell, exportResponsesToCsv, isQuestionVisible, resolveFormTranslation, sanitizeSchema, selectVisibleAnswers, validateAnswers, validateFormSchema, validateSchemaStructure };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "number" | "rating" | "select" | "multi-select" | "checkbox" | "radio";
|
|
2
|
+
type ConditionOperator = "equals" | "not_equals" | "contains" | "not_empty";
|
|
3
|
+
type ConditionValue = string | number | boolean;
|
|
4
|
+
interface DisplayCondition {
|
|
5
|
+
readonly questionId: string;
|
|
6
|
+
readonly operator: ConditionOperator;
|
|
7
|
+
readonly value?: ConditionValue;
|
|
8
|
+
}
|
|
9
|
+
type ValidationCode = "required" | "invalid_type" | "min_length" | "max_length" | "pattern" | "min" | "max" | "step" | "invalid_option" | "min_selections" | "max_selections" | "unknown_field";
|
|
10
|
+
interface FieldOption {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
}
|
|
14
|
+
interface BaseField {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly type: FieldType;
|
|
17
|
+
readonly title: string;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly translationKey?: string;
|
|
20
|
+
readonly required: boolean;
|
|
21
|
+
readonly messages?: Partial<Record<ValidationCode, string>>;
|
|
22
|
+
readonly displayCondition?: DisplayCondition;
|
|
23
|
+
}
|
|
24
|
+
interface TextField extends BaseField {
|
|
25
|
+
readonly type: "text" | "textarea";
|
|
26
|
+
readonly placeholderKey?: string;
|
|
27
|
+
readonly minLength?: number;
|
|
28
|
+
readonly maxLength?: number;
|
|
29
|
+
readonly pattern?: string;
|
|
30
|
+
}
|
|
31
|
+
interface NumberField extends BaseField {
|
|
32
|
+
readonly type: "number";
|
|
33
|
+
readonly placeholderKey?: string;
|
|
34
|
+
readonly min?: number;
|
|
35
|
+
readonly max?: number;
|
|
36
|
+
readonly step?: number;
|
|
37
|
+
}
|
|
38
|
+
interface RatingField extends BaseField {
|
|
39
|
+
readonly type: "rating";
|
|
40
|
+
readonly min?: number;
|
|
41
|
+
readonly max?: number;
|
|
42
|
+
}
|
|
43
|
+
interface SelectField extends BaseField {
|
|
44
|
+
readonly type: "select" | "radio";
|
|
45
|
+
readonly options: readonly FieldOption[];
|
|
46
|
+
}
|
|
47
|
+
interface MultiSelectField extends BaseField {
|
|
48
|
+
readonly type: "multi-select";
|
|
49
|
+
readonly options: readonly FieldOption[];
|
|
50
|
+
readonly minSelections?: number;
|
|
51
|
+
readonly maxSelections?: number;
|
|
52
|
+
}
|
|
53
|
+
interface CheckboxField extends BaseField {
|
|
54
|
+
readonly type: "checkbox";
|
|
55
|
+
}
|
|
56
|
+
type FormField = TextField | NumberField | RatingField | SelectField | MultiSelectField | CheckboxField;
|
|
57
|
+
interface FormSchema {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly version: number;
|
|
60
|
+
readonly title: string;
|
|
61
|
+
readonly description?: string;
|
|
62
|
+
readonly submitLabelKey?: string;
|
|
63
|
+
readonly fields: readonly FormField[];
|
|
64
|
+
}
|
|
65
|
+
type FormValue = string | number | boolean | readonly string[] | undefined;
|
|
66
|
+
type FormValues = Readonly<Record<string, FormValue>>;
|
|
67
|
+
interface SchemaIssue {
|
|
68
|
+
readonly path: string;
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly message: string;
|
|
71
|
+
}
|
|
72
|
+
type SchemaValidationResult = {
|
|
73
|
+
readonly valid: true;
|
|
74
|
+
readonly value: FormSchema;
|
|
75
|
+
readonly issues: readonly [];
|
|
76
|
+
} | {
|
|
77
|
+
readonly valid: false;
|
|
78
|
+
readonly issues: readonly SchemaIssue[];
|
|
79
|
+
};
|
|
80
|
+
interface ValidationIssue {
|
|
81
|
+
readonly fieldId: string;
|
|
82
|
+
readonly code: ValidationCode;
|
|
83
|
+
readonly messageKey: string;
|
|
84
|
+
readonly params: Readonly<Record<string, string | number>>;
|
|
85
|
+
}
|
|
86
|
+
type AnswerValidationResult = {
|
|
87
|
+
readonly valid: true;
|
|
88
|
+
readonly issues: readonly [];
|
|
89
|
+
} | {
|
|
90
|
+
readonly valid: false;
|
|
91
|
+
readonly issues: readonly ValidationIssue[];
|
|
92
|
+
};
|
|
93
|
+
interface FormSubmission {
|
|
94
|
+
readonly id: string;
|
|
95
|
+
readonly formId: string;
|
|
96
|
+
readonly formVersion: number;
|
|
97
|
+
readonly locale: string;
|
|
98
|
+
readonly values: FormValues;
|
|
99
|
+
readonly submittedAt: string;
|
|
100
|
+
}
|
|
101
|
+
interface TranslationAdapter {
|
|
102
|
+
translate(key: string, locale: string, params?: Readonly<Record<string, string | number>>): string;
|
|
103
|
+
}
|
|
104
|
+
interface AsyncTranslationAdapter {
|
|
105
|
+
translateText(text: string, targetLocale: string, sourceLocale?: string): Promise<string>;
|
|
106
|
+
translateBatch(texts: readonly string[], targetLocale: string, sourceLocale?: string): Promise<readonly string[]>;
|
|
107
|
+
}
|
|
108
|
+
interface StorageAdapter {
|
|
109
|
+
saveSubmission(submission: FormSubmission): Promise<void>;
|
|
110
|
+
listSubmissions(formId: string, formVersion?: number): Promise<readonly FormSubmission[]>;
|
|
111
|
+
clearResponses?(formId: string): Promise<void>;
|
|
112
|
+
clear(): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
interface FormStorageAdapter extends StorageAdapter {
|
|
115
|
+
saveSchema(schema: FormSchema): Promise<void>;
|
|
116
|
+
getSchema(formId: string, formVersion: number): Promise<FormSchema | null>;
|
|
117
|
+
listSchemas(): Promise<readonly FormSchema[]>;
|
|
118
|
+
deleteSchema(formId: string, formVersion: number): Promise<void>;
|
|
119
|
+
deleteSubmission(submissionId: string): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
interface BaseQuestionAggregate {
|
|
122
|
+
readonly fieldId: string;
|
|
123
|
+
readonly answeredCount: number;
|
|
124
|
+
readonly unansweredCount: number;
|
|
125
|
+
}
|
|
126
|
+
interface TextQuestionAggregate extends BaseQuestionAggregate {
|
|
127
|
+
readonly kind: "text" | "textarea";
|
|
128
|
+
}
|
|
129
|
+
interface NumberQuestionAggregate extends BaseQuestionAggregate {
|
|
130
|
+
readonly kind: "number" | "rating";
|
|
131
|
+
readonly minimum: number | null;
|
|
132
|
+
readonly maximum: number | null;
|
|
133
|
+
readonly average: number | null;
|
|
134
|
+
readonly total: number;
|
|
135
|
+
}
|
|
136
|
+
interface OptionAggregate {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly count: number;
|
|
139
|
+
readonly percentageOfSubmissions: number;
|
|
140
|
+
}
|
|
141
|
+
interface ChoiceQuestionAggregate extends BaseQuestionAggregate {
|
|
142
|
+
readonly kind: "select" | "radio" | "multi-select";
|
|
143
|
+
readonly options: readonly OptionAggregate[];
|
|
144
|
+
}
|
|
145
|
+
interface CheckboxQuestionAggregate extends BaseQuestionAggregate {
|
|
146
|
+
readonly kind: "checkbox";
|
|
147
|
+
readonly trueCount: number;
|
|
148
|
+
readonly falseCount: number;
|
|
149
|
+
readonly truePercentageOfSubmissions: number;
|
|
150
|
+
readonly falsePercentageOfSubmissions: number;
|
|
151
|
+
}
|
|
152
|
+
type QuestionAggregate = TextQuestionAggregate | NumberQuestionAggregate | ChoiceQuestionAggregate | CheckboxQuestionAggregate;
|
|
153
|
+
interface FormAnalytics {
|
|
154
|
+
readonly formId: string;
|
|
155
|
+
readonly formVersion: number;
|
|
156
|
+
readonly submissionCount: number;
|
|
157
|
+
readonly questions: readonly QuestionAggregate[];
|
|
158
|
+
}
|
|
159
|
+
type Question = FormField;
|
|
160
|
+
type QuestionType = FieldType;
|
|
161
|
+
type ChoiceOption = FieldOption;
|
|
162
|
+
type FormResponse = FormSubmission;
|
|
163
|
+
|
|
164
|
+
interface ChoiceDistributionEntry {
|
|
165
|
+
readonly count: number;
|
|
166
|
+
readonly percentage: number;
|
|
167
|
+
}
|
|
168
|
+
interface NumericSummary {
|
|
169
|
+
readonly average: number | null;
|
|
170
|
+
readonly min: number | null;
|
|
171
|
+
readonly max: number | null;
|
|
172
|
+
readonly total: number;
|
|
173
|
+
}
|
|
174
|
+
declare function calculateChoiceDistribution(responses: readonly FormSubmission[], questionId: string): Record<string, ChoiceDistributionEntry>;
|
|
175
|
+
declare function calculateNumericSummary(responses: readonly FormSubmission[], questionId: string): NumericSummary;
|
|
176
|
+
declare function aggregateResponses(schema: FormSchema, submissions: readonly FormSubmission[]): FormAnalytics;
|
|
177
|
+
declare function escapeCsvCell(value: string | number | null | undefined): string;
|
|
178
|
+
interface CsvExportOptions {
|
|
179
|
+
readonly withBom?: boolean;
|
|
180
|
+
}
|
|
181
|
+
declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
|
|
182
|
+
|
|
183
|
+
type SchemaStructureIssueType = "dangling_condition_reference" | "duplicate_question_id" | "duplicate_choice_id" | "self_condition_reference" | "cyclic_condition_reference";
|
|
184
|
+
interface SchemaStructureIssue {
|
|
185
|
+
readonly type: SchemaStructureIssueType;
|
|
186
|
+
readonly questionId: string;
|
|
187
|
+
readonly choiceId?: string;
|
|
188
|
+
readonly message: string;
|
|
189
|
+
}
|
|
190
|
+
declare function validateSchemaStructure(schema: FormSchema): SchemaStructureIssue[];
|
|
191
|
+
declare function sanitizeSchema(schema: FormSchema): FormSchema;
|
|
192
|
+
|
|
193
|
+
declare function validateFormSchema(input: unknown): SchemaValidationResult;
|
|
194
|
+
declare function assertValidFormSchema(input: unknown): asserts input is FormSchema;
|
|
195
|
+
|
|
196
|
+
interface CreateSubmissionOptions {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly locale: string;
|
|
199
|
+
readonly submittedAt: string;
|
|
200
|
+
}
|
|
201
|
+
declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
|
|
202
|
+
|
|
203
|
+
declare function resolveFormTranslation(schema: FormSchema, adapter: AsyncTranslationAdapter, targetLocale: string, sourceLocale?: string): Promise<FormSchema>;
|
|
204
|
+
|
|
205
|
+
declare function validateAnswers(schema: FormSchema, values: FormValues): AnswerValidationResult;
|
|
206
|
+
|
|
207
|
+
declare function isQuestionVisible(question: FormField, currentAnswers: Readonly<Record<string, unknown>>): boolean;
|
|
208
|
+
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
209
|
+
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
210
|
+
|
|
211
|
+
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CsvExportOptions, type DisplayCondition, type FieldOption, type FieldType, type FormAnalytics, type FormField, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type MultiSelectField, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type Question, type QuestionAggregate, type QuestionType, type RatingField, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaValidationResult, type SelectField, type StorageAdapter, type TextField, type TextQuestionAggregate, type TranslationAdapter, type ValidationCode, type ValidationIssue, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateFieldVisibility, calculateNumericSummary, createSubmission, escapeCsvCell, exportResponsesToCsv, isQuestionVisible, resolveFormTranslation, sanitizeSchema, selectVisibleAnswers, validateAnswers, validateFormSchema, validateSchemaStructure };
|