@form-engine-ts/core 1.1.0 → 2.1.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/README.md +19 -1
- package/dist/index.cjs +432 -89
- package/dist/index.d.cts +71 -11
- package/dist/index.d.ts +71 -11
- package/dist/index.js +431 -89
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
type FieldType = "text" | "textarea" | "number" | "rating" | "select" | "multi-select" | "checkbox" | "radio";
|
|
2
|
+
interface FormPolicy {
|
|
3
|
+
readonly allowedFieldTypes?: readonly FieldType[];
|
|
4
|
+
readonly maxFields?: number;
|
|
5
|
+
readonly maxOptionsPerField?: number;
|
|
6
|
+
readonly requiredLocales?: readonly string[];
|
|
7
|
+
readonly maxTextLength?: number;
|
|
8
|
+
readonly maxSchemaBytes?: number;
|
|
9
|
+
}
|
|
2
10
|
type ConditionOperator = "equals" | "not_equals" | "contains" | "not_empty";
|
|
3
11
|
type ConditionValue = string | number | boolean;
|
|
12
|
+
type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
13
|
+
readonly [key: string]: JsonValue;
|
|
14
|
+
};
|
|
15
|
+
/** Arbitrary, JSON-serializable data preserved by every form-engine operation. */
|
|
16
|
+
interface ExtensibleNode {
|
|
17
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
18
|
+
/** Locale -> translated property -> metadata created for that translation. */
|
|
19
|
+
readonly translationMetadata?: Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, JsonValue>>>>>>;
|
|
20
|
+
}
|
|
4
21
|
interface DisplayCondition {
|
|
5
22
|
readonly questionId: string;
|
|
6
23
|
readonly operator: ConditionOperator;
|
|
@@ -9,15 +26,16 @@ interface DisplayCondition {
|
|
|
9
26
|
interface LocalizedText {
|
|
10
27
|
readonly title?: string;
|
|
11
28
|
readonly description?: string;
|
|
29
|
+
readonly completionMessage?: string;
|
|
12
30
|
}
|
|
13
31
|
type SchemaTranslations = Readonly<Record<string, LocalizedText>>;
|
|
14
32
|
type ValidationCode = "required" | "invalid_type" | "min_length" | "max_length" | "pattern" | "min" | "max" | "step" | "invalid_option" | "min_selections" | "max_selections" | "unknown_field";
|
|
15
|
-
interface FieldOption {
|
|
33
|
+
interface FieldOption extends ExtensibleNode {
|
|
16
34
|
readonly id: string;
|
|
17
35
|
readonly label: string;
|
|
18
36
|
readonly translations?: Readonly<Record<string, string>>;
|
|
19
37
|
}
|
|
20
|
-
interface BaseField {
|
|
38
|
+
interface BaseField extends ExtensibleNode {
|
|
21
39
|
readonly id: string;
|
|
22
40
|
readonly type: FieldType;
|
|
23
41
|
readonly title: string;
|
|
@@ -61,7 +79,7 @@ interface CheckboxField extends BaseField {
|
|
|
61
79
|
readonly type: "checkbox";
|
|
62
80
|
}
|
|
63
81
|
type FormField = TextField | NumberField | RatingField | SelectField | MultiSelectField | CheckboxField;
|
|
64
|
-
interface FormPage {
|
|
82
|
+
interface FormPage extends ExtensibleNode {
|
|
65
83
|
readonly id: string;
|
|
66
84
|
readonly title?: string;
|
|
67
85
|
readonly description?: string;
|
|
@@ -69,11 +87,12 @@ interface FormPage {
|
|
|
69
87
|
readonly displayCondition?: DisplayCondition;
|
|
70
88
|
readonly translations?: SchemaTranslations;
|
|
71
89
|
}
|
|
72
|
-
interface FormSchema {
|
|
90
|
+
interface FormSchema extends ExtensibleNode {
|
|
73
91
|
readonly id: string;
|
|
74
92
|
readonly version: number;
|
|
75
93
|
readonly title: string;
|
|
76
94
|
readonly description?: string;
|
|
95
|
+
readonly completionMessage?: string;
|
|
77
96
|
readonly submitLabelKey?: string;
|
|
78
97
|
readonly defaultLocale?: string;
|
|
79
98
|
readonly supportedLocales?: readonly string[];
|
|
@@ -102,6 +121,7 @@ interface ValidationIssue {
|
|
|
102
121
|
readonly messageKey: string;
|
|
103
122
|
readonly params: Readonly<Record<string, string | number>>;
|
|
104
123
|
}
|
|
124
|
+
type ValidationError = ValidationIssue;
|
|
105
125
|
type AnswerValidationResult = {
|
|
106
126
|
readonly valid: true;
|
|
107
127
|
readonly issues: readonly [];
|
|
@@ -109,7 +129,7 @@ type AnswerValidationResult = {
|
|
|
109
129
|
readonly valid: false;
|
|
110
130
|
readonly issues: readonly ValidationIssue[];
|
|
111
131
|
};
|
|
112
|
-
interface FormSubmission {
|
|
132
|
+
interface FormSubmission extends ExtensibleNode {
|
|
113
133
|
readonly id: string;
|
|
114
134
|
readonly formId: string;
|
|
115
135
|
readonly formVersion: number;
|
|
@@ -182,7 +202,13 @@ interface FormAnalytics {
|
|
|
182
202
|
type Question = FormField;
|
|
183
203
|
type QuestionType = FieldType;
|
|
184
204
|
type ChoiceOption = FieldOption;
|
|
185
|
-
|
|
205
|
+
interface FormResponse extends ExtensibleNode {
|
|
206
|
+
readonly responseId: string;
|
|
207
|
+
readonly formId: string;
|
|
208
|
+
readonly sourceLocale?: string;
|
|
209
|
+
readonly answers: Readonly<Record<string, unknown>>;
|
|
210
|
+
readonly submittedAt: string;
|
|
211
|
+
}
|
|
186
212
|
interface CrossTabulationResult {
|
|
187
213
|
readonly rowQuestionId: string;
|
|
188
214
|
readonly colQuestionId: string;
|
|
@@ -206,9 +232,10 @@ declare function calculateChoiceDistribution(responses: readonly FormSubmission[
|
|
|
206
232
|
declare function calculateNumericSummary(responses: readonly FormSubmission[], questionId: string): NumericSummary;
|
|
207
233
|
declare function calculateCrossTabulation(responses: readonly FormSubmission[], rowQuestionId: string, colQuestionId: string): CrossTabulationResult;
|
|
208
234
|
declare function aggregateResponses(schema: FormSchema, submissions: readonly FormSubmission[]): FormAnalytics;
|
|
209
|
-
declare function escapeCsvCell(value: string | number | null | undefined): string;
|
|
235
|
+
declare function escapeCsvCell(value: string | number | boolean | null | undefined, neutralizeFormulas?: boolean): string;
|
|
210
236
|
interface CsvExportOptions {
|
|
211
237
|
readonly withBom?: boolean;
|
|
238
|
+
readonly neutralizeFormulas?: boolean;
|
|
212
239
|
}
|
|
213
240
|
declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
|
|
214
241
|
|
|
@@ -233,6 +260,12 @@ interface WebhookDispatchResult {
|
|
|
233
260
|
}
|
|
234
261
|
declare function dispatchWebhook<T>(event: FormEvent<T>, config: WebhookConfig, fetchImpl?: typeof fetch): Promise<WebhookDispatchResult>;
|
|
235
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Changes only the type-specific shape of a field. Authoring content and extension
|
|
265
|
+
* data are deliberately retained so UI adapters cannot accidentally discard them.
|
|
266
|
+
*/
|
|
267
|
+
declare function transformFieldType(field: FormField, nextType: QuestionType): FormField;
|
|
268
|
+
|
|
236
269
|
type SchemaStructureIssueType = "dangling_condition_reference" | "duplicate_question_id" | "duplicate_choice_id" | "self_condition_reference" | "cyclic_condition_reference";
|
|
237
270
|
interface SchemaStructureIssue {
|
|
238
271
|
readonly type: SchemaStructureIssueType;
|
|
@@ -243,18 +276,45 @@ interface SchemaStructureIssue {
|
|
|
243
276
|
declare function validateSchemaStructure(schema: FormSchema): SchemaStructureIssue[];
|
|
244
277
|
declare function sanitizeSchema(schema: FormSchema): FormSchema;
|
|
245
278
|
|
|
246
|
-
|
|
279
|
+
interface ValidateFormSchemaOptions {
|
|
280
|
+
readonly policy?: FormPolicy;
|
|
281
|
+
}
|
|
282
|
+
declare function validateFormSchema(input: unknown, options?: ValidateFormSchemaOptions): SchemaValidationResult;
|
|
247
283
|
declare function assertValidFormSchema(input: unknown): asserts input is FormSchema;
|
|
248
284
|
|
|
249
|
-
interface CreateSubmissionOptions {
|
|
285
|
+
interface CreateSubmissionOptions extends ExtensibleNode {
|
|
250
286
|
readonly id: string;
|
|
251
287
|
readonly locale: string;
|
|
252
288
|
readonly submittedAt: string;
|
|
253
289
|
}
|
|
254
290
|
declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
|
|
255
291
|
|
|
292
|
+
interface TranslationSlot {
|
|
293
|
+
readonly kind: "form" | "page" | "field" | "option";
|
|
294
|
+
readonly nodeId: string;
|
|
295
|
+
readonly property: "title" | "description" | "label" | "completionMessage";
|
|
296
|
+
readonly locale: string;
|
|
297
|
+
readonly sourceText: string;
|
|
298
|
+
readonly existingText?: string;
|
|
299
|
+
readonly nodeMetadata?: Readonly<Record<string, JsonValue>>;
|
|
300
|
+
readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
|
|
301
|
+
/** @deprecated Use nodeMetadata instead. */
|
|
302
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
303
|
+
}
|
|
304
|
+
interface PopulateTranslationOptions {
|
|
305
|
+
readonly overwrite?: "missing-only" | "all";
|
|
306
|
+
readonly shouldOverwrite?: (slot: TranslationSlot) => boolean;
|
|
307
|
+
readonly createMetadata?: (slot: TranslationSlot, translatedText: string) => Readonly<Record<string, JsonValue>>;
|
|
308
|
+
}
|
|
309
|
+
interface TranslationReport {
|
|
310
|
+
readonly updatedSlots: readonly TranslationSlot[];
|
|
311
|
+
readonly skippedSlots: readonly TranslationSlot[];
|
|
312
|
+
}
|
|
256
313
|
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale: string): FormSchema;
|
|
257
|
-
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter): Promise<
|
|
314
|
+
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter, options?: PopulateTranslationOptions): Promise<{
|
|
315
|
+
readonly schema: FormSchema;
|
|
316
|
+
readonly report: TranslationReport;
|
|
317
|
+
}>;
|
|
258
318
|
declare function resolveFormTranslation(schema: FormSchema, adapter: AsyncTranslationAdapter, targetLocale: string, sourceLocale?: string): Promise<FormSchema>;
|
|
259
319
|
|
|
260
320
|
declare function validateAnswers(schema: FormSchema, values: FormValues): AnswerValidationResult;
|
|
@@ -266,4 +326,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
266
326
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
267
327
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
268
328
|
|
|
269
|
-
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvExportOptions, type DisplayCondition, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type LocalizedText, 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 SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type SubmissionQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type ValidationCode, type ValidationIssue, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, createSubmission, dispatchWebhook, escapeCsvCell, exportResponsesToCsv, isDisplayConditionSatisfied, isQuestionVisible, populateSchemaTranslations, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
329
|
+
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvExportOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type JsonValue, type LocalizedText, type MultiSelectField, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PopulateTranslationOptions, type Question, type QuestionAggregate, type QuestionType, type RatingField, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type SubmissionQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, createSubmission, dispatchWebhook, escapeCsvCell, exportResponsesToCsv, isDisplayConditionSatisfied, isQuestionVisible, populateSchemaTranslations, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
type FieldType = "text" | "textarea" | "number" | "rating" | "select" | "multi-select" | "checkbox" | "radio";
|
|
2
|
+
interface FormPolicy {
|
|
3
|
+
readonly allowedFieldTypes?: readonly FieldType[];
|
|
4
|
+
readonly maxFields?: number;
|
|
5
|
+
readonly maxOptionsPerField?: number;
|
|
6
|
+
readonly requiredLocales?: readonly string[];
|
|
7
|
+
readonly maxTextLength?: number;
|
|
8
|
+
readonly maxSchemaBytes?: number;
|
|
9
|
+
}
|
|
2
10
|
type ConditionOperator = "equals" | "not_equals" | "contains" | "not_empty";
|
|
3
11
|
type ConditionValue = string | number | boolean;
|
|
12
|
+
type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
13
|
+
readonly [key: string]: JsonValue;
|
|
14
|
+
};
|
|
15
|
+
/** Arbitrary, JSON-serializable data preserved by every form-engine operation. */
|
|
16
|
+
interface ExtensibleNode {
|
|
17
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
18
|
+
/** Locale -> translated property -> metadata created for that translation. */
|
|
19
|
+
readonly translationMetadata?: Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, JsonValue>>>>>>;
|
|
20
|
+
}
|
|
4
21
|
interface DisplayCondition {
|
|
5
22
|
readonly questionId: string;
|
|
6
23
|
readonly operator: ConditionOperator;
|
|
@@ -9,15 +26,16 @@ interface DisplayCondition {
|
|
|
9
26
|
interface LocalizedText {
|
|
10
27
|
readonly title?: string;
|
|
11
28
|
readonly description?: string;
|
|
29
|
+
readonly completionMessage?: string;
|
|
12
30
|
}
|
|
13
31
|
type SchemaTranslations = Readonly<Record<string, LocalizedText>>;
|
|
14
32
|
type ValidationCode = "required" | "invalid_type" | "min_length" | "max_length" | "pattern" | "min" | "max" | "step" | "invalid_option" | "min_selections" | "max_selections" | "unknown_field";
|
|
15
|
-
interface FieldOption {
|
|
33
|
+
interface FieldOption extends ExtensibleNode {
|
|
16
34
|
readonly id: string;
|
|
17
35
|
readonly label: string;
|
|
18
36
|
readonly translations?: Readonly<Record<string, string>>;
|
|
19
37
|
}
|
|
20
|
-
interface BaseField {
|
|
38
|
+
interface BaseField extends ExtensibleNode {
|
|
21
39
|
readonly id: string;
|
|
22
40
|
readonly type: FieldType;
|
|
23
41
|
readonly title: string;
|
|
@@ -61,7 +79,7 @@ interface CheckboxField extends BaseField {
|
|
|
61
79
|
readonly type: "checkbox";
|
|
62
80
|
}
|
|
63
81
|
type FormField = TextField | NumberField | RatingField | SelectField | MultiSelectField | CheckboxField;
|
|
64
|
-
interface FormPage {
|
|
82
|
+
interface FormPage extends ExtensibleNode {
|
|
65
83
|
readonly id: string;
|
|
66
84
|
readonly title?: string;
|
|
67
85
|
readonly description?: string;
|
|
@@ -69,11 +87,12 @@ interface FormPage {
|
|
|
69
87
|
readonly displayCondition?: DisplayCondition;
|
|
70
88
|
readonly translations?: SchemaTranslations;
|
|
71
89
|
}
|
|
72
|
-
interface FormSchema {
|
|
90
|
+
interface FormSchema extends ExtensibleNode {
|
|
73
91
|
readonly id: string;
|
|
74
92
|
readonly version: number;
|
|
75
93
|
readonly title: string;
|
|
76
94
|
readonly description?: string;
|
|
95
|
+
readonly completionMessage?: string;
|
|
77
96
|
readonly submitLabelKey?: string;
|
|
78
97
|
readonly defaultLocale?: string;
|
|
79
98
|
readonly supportedLocales?: readonly string[];
|
|
@@ -102,6 +121,7 @@ interface ValidationIssue {
|
|
|
102
121
|
readonly messageKey: string;
|
|
103
122
|
readonly params: Readonly<Record<string, string | number>>;
|
|
104
123
|
}
|
|
124
|
+
type ValidationError = ValidationIssue;
|
|
105
125
|
type AnswerValidationResult = {
|
|
106
126
|
readonly valid: true;
|
|
107
127
|
readonly issues: readonly [];
|
|
@@ -109,7 +129,7 @@ type AnswerValidationResult = {
|
|
|
109
129
|
readonly valid: false;
|
|
110
130
|
readonly issues: readonly ValidationIssue[];
|
|
111
131
|
};
|
|
112
|
-
interface FormSubmission {
|
|
132
|
+
interface FormSubmission extends ExtensibleNode {
|
|
113
133
|
readonly id: string;
|
|
114
134
|
readonly formId: string;
|
|
115
135
|
readonly formVersion: number;
|
|
@@ -182,7 +202,13 @@ interface FormAnalytics {
|
|
|
182
202
|
type Question = FormField;
|
|
183
203
|
type QuestionType = FieldType;
|
|
184
204
|
type ChoiceOption = FieldOption;
|
|
185
|
-
|
|
205
|
+
interface FormResponse extends ExtensibleNode {
|
|
206
|
+
readonly responseId: string;
|
|
207
|
+
readonly formId: string;
|
|
208
|
+
readonly sourceLocale?: string;
|
|
209
|
+
readonly answers: Readonly<Record<string, unknown>>;
|
|
210
|
+
readonly submittedAt: string;
|
|
211
|
+
}
|
|
186
212
|
interface CrossTabulationResult {
|
|
187
213
|
readonly rowQuestionId: string;
|
|
188
214
|
readonly colQuestionId: string;
|
|
@@ -206,9 +232,10 @@ declare function calculateChoiceDistribution(responses: readonly FormSubmission[
|
|
|
206
232
|
declare function calculateNumericSummary(responses: readonly FormSubmission[], questionId: string): NumericSummary;
|
|
207
233
|
declare function calculateCrossTabulation(responses: readonly FormSubmission[], rowQuestionId: string, colQuestionId: string): CrossTabulationResult;
|
|
208
234
|
declare function aggregateResponses(schema: FormSchema, submissions: readonly FormSubmission[]): FormAnalytics;
|
|
209
|
-
declare function escapeCsvCell(value: string | number | null | undefined): string;
|
|
235
|
+
declare function escapeCsvCell(value: string | number | boolean | null | undefined, neutralizeFormulas?: boolean): string;
|
|
210
236
|
interface CsvExportOptions {
|
|
211
237
|
readonly withBom?: boolean;
|
|
238
|
+
readonly neutralizeFormulas?: boolean;
|
|
212
239
|
}
|
|
213
240
|
declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
|
|
214
241
|
|
|
@@ -233,6 +260,12 @@ interface WebhookDispatchResult {
|
|
|
233
260
|
}
|
|
234
261
|
declare function dispatchWebhook<T>(event: FormEvent<T>, config: WebhookConfig, fetchImpl?: typeof fetch): Promise<WebhookDispatchResult>;
|
|
235
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Changes only the type-specific shape of a field. Authoring content and extension
|
|
265
|
+
* data are deliberately retained so UI adapters cannot accidentally discard them.
|
|
266
|
+
*/
|
|
267
|
+
declare function transformFieldType(field: FormField, nextType: QuestionType): FormField;
|
|
268
|
+
|
|
236
269
|
type SchemaStructureIssueType = "dangling_condition_reference" | "duplicate_question_id" | "duplicate_choice_id" | "self_condition_reference" | "cyclic_condition_reference";
|
|
237
270
|
interface SchemaStructureIssue {
|
|
238
271
|
readonly type: SchemaStructureIssueType;
|
|
@@ -243,18 +276,45 @@ interface SchemaStructureIssue {
|
|
|
243
276
|
declare function validateSchemaStructure(schema: FormSchema): SchemaStructureIssue[];
|
|
244
277
|
declare function sanitizeSchema(schema: FormSchema): FormSchema;
|
|
245
278
|
|
|
246
|
-
|
|
279
|
+
interface ValidateFormSchemaOptions {
|
|
280
|
+
readonly policy?: FormPolicy;
|
|
281
|
+
}
|
|
282
|
+
declare function validateFormSchema(input: unknown, options?: ValidateFormSchemaOptions): SchemaValidationResult;
|
|
247
283
|
declare function assertValidFormSchema(input: unknown): asserts input is FormSchema;
|
|
248
284
|
|
|
249
|
-
interface CreateSubmissionOptions {
|
|
285
|
+
interface CreateSubmissionOptions extends ExtensibleNode {
|
|
250
286
|
readonly id: string;
|
|
251
287
|
readonly locale: string;
|
|
252
288
|
readonly submittedAt: string;
|
|
253
289
|
}
|
|
254
290
|
declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
|
|
255
291
|
|
|
292
|
+
interface TranslationSlot {
|
|
293
|
+
readonly kind: "form" | "page" | "field" | "option";
|
|
294
|
+
readonly nodeId: string;
|
|
295
|
+
readonly property: "title" | "description" | "label" | "completionMessage";
|
|
296
|
+
readonly locale: string;
|
|
297
|
+
readonly sourceText: string;
|
|
298
|
+
readonly existingText?: string;
|
|
299
|
+
readonly nodeMetadata?: Readonly<Record<string, JsonValue>>;
|
|
300
|
+
readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
|
|
301
|
+
/** @deprecated Use nodeMetadata instead. */
|
|
302
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
303
|
+
}
|
|
304
|
+
interface PopulateTranslationOptions {
|
|
305
|
+
readonly overwrite?: "missing-only" | "all";
|
|
306
|
+
readonly shouldOverwrite?: (slot: TranslationSlot) => boolean;
|
|
307
|
+
readonly createMetadata?: (slot: TranslationSlot, translatedText: string) => Readonly<Record<string, JsonValue>>;
|
|
308
|
+
}
|
|
309
|
+
interface TranslationReport {
|
|
310
|
+
readonly updatedSlots: readonly TranslationSlot[];
|
|
311
|
+
readonly skippedSlots: readonly TranslationSlot[];
|
|
312
|
+
}
|
|
256
313
|
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale: string): FormSchema;
|
|
257
|
-
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter): Promise<
|
|
314
|
+
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter, options?: PopulateTranslationOptions): Promise<{
|
|
315
|
+
readonly schema: FormSchema;
|
|
316
|
+
readonly report: TranslationReport;
|
|
317
|
+
}>;
|
|
258
318
|
declare function resolveFormTranslation(schema: FormSchema, adapter: AsyncTranslationAdapter, targetLocale: string, sourceLocale?: string): Promise<FormSchema>;
|
|
259
319
|
|
|
260
320
|
declare function validateAnswers(schema: FormSchema, values: FormValues): AnswerValidationResult;
|
|
@@ -266,4 +326,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
266
326
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
267
327
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
268
328
|
|
|
269
|
-
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvExportOptions, type DisplayCondition, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type LocalizedText, 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 SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type SubmissionQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type ValidationCode, type ValidationIssue, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, createSubmission, dispatchWebhook, escapeCsvCell, exportResponsesToCsv, isDisplayConditionSatisfied, isQuestionVisible, populateSchemaTranslations, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
329
|
+
export { type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvExportOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type JsonValue, type LocalizedText, type MultiSelectField, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PopulateTranslationOptions, type Question, type QuestionAggregate, type QuestionType, type RatingField, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type SubmissionQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, createSubmission, dispatchWebhook, escapeCsvCell, exportResponsesToCsv, isDisplayConditionSatisfied, isQuestionVisible, populateSchemaTranslations, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|