@frt-platform/report-core 1.2.0 → 1.3.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 +255 -392
- package/dist/index.d.mts +127 -95
- package/dist/index.d.ts +127 -95
- package/dist/index.js +506 -398
- package/dist/index.mjs +508 -398
- package/package.json +7 -3
package/dist/index.d.mts
CHANGED
|
@@ -68,80 +68,36 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
68
68
|
}>;
|
|
69
69
|
type ReportTemplateSchema = z.infer<typeof ReportTemplateSchemaValidator>;
|
|
70
70
|
|
|
71
|
-
declare const DEFAULT_FIELD_LABEL = "Untitled question";
|
|
72
|
-
declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string, unknown>>;
|
|
73
|
-
|
|
74
|
-
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
75
|
-
|
|
76
71
|
declare function migrateLegacySchema(raw: unknown): unknown;
|
|
77
72
|
|
|
78
73
|
declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
|
|
79
74
|
declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
|
|
80
75
|
declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
code: FieldErrorCode;
|
|
98
|
-
/** human-readable message (already enriched with section / label) */
|
|
99
|
-
message: string;
|
|
100
|
-
/** original Zod issue (for debugging / logging) */
|
|
101
|
-
rawIssue?: ZodIssue;
|
|
76
|
+
interface SerializeOptions {
|
|
77
|
+
/**
|
|
78
|
+
* If true (default), output human-readable JSON with 2-space indentation.
|
|
79
|
+
* If false, output a compact single-line JSON string.
|
|
80
|
+
*/
|
|
81
|
+
pretty?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* If true, sections will be sorted by their `id` before serialization.
|
|
84
|
+
* This is useful for deterministic diffs across environments.
|
|
85
|
+
*/
|
|
86
|
+
sortSectionsById?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* If true, fields within each section will be sorted by their `id`
|
|
89
|
+
* before serialization. Also useful for stable diffs.
|
|
90
|
+
*/
|
|
91
|
+
sortFieldsById?: boolean;
|
|
102
92
|
}
|
|
103
93
|
/**
|
|
104
|
-
*
|
|
105
|
-
* returns a structured error object with:
|
|
106
|
-
* - section title
|
|
107
|
-
* - field label
|
|
108
|
-
* - normalized error code
|
|
94
|
+
* Serialize a template schema into JSON.
|
|
109
95
|
*
|
|
110
|
-
*
|
|
96
|
+
* - Optional pretty-printing (default: true)
|
|
97
|
+
* - Optional deterministic sorting of sections and fields by ID
|
|
98
|
+
* to make git diffs and code reviews cleaner.
|
|
111
99
|
*/
|
|
112
|
-
declare function
|
|
113
|
-
success: true;
|
|
114
|
-
value: Record<string, unknown>;
|
|
115
|
-
} | {
|
|
116
|
-
success: false;
|
|
117
|
-
errors: ResponseFieldError[];
|
|
118
|
-
};
|
|
119
|
-
type TemplateFieldUnion<TTemplate> = TTemplate extends {
|
|
120
|
-
sections: readonly (infer S)[];
|
|
121
|
-
} ? S extends {
|
|
122
|
-
fields: readonly (infer F)[];
|
|
123
|
-
} ? F : never : never;
|
|
124
|
-
type BaseFieldValue<TField extends {
|
|
125
|
-
type: ReportTemplateFieldType;
|
|
126
|
-
required?: boolean;
|
|
127
|
-
options?: readonly string[] | string[];
|
|
128
|
-
}> = TField["type"] extends "shortText" | "longText" ? string : TField["type"] extends "number" ? number : TField["type"] extends "date" ? string : TField["type"] extends "checkbox" ? boolean : TField["type"] extends "singleSelect" ? (TField["options"] extends readonly (infer O)[] ? O : TField["options"] extends (infer O)[] ? O : string) : TField["type"] extends "multiSelect" ? (TField["options"] extends readonly (infer O)[] ? O[] : TField["options"] extends (infer O)[] ? O[] : string[]) : unknown;
|
|
129
|
-
type FieldResponseValue<TField extends {
|
|
130
|
-
type: ReportTemplateFieldType;
|
|
131
|
-
required?: boolean;
|
|
132
|
-
}> = TField["required"] extends true ? BaseFieldValue<TField> : BaseFieldValue<TField> | undefined;
|
|
133
|
-
type InferResponse<TTemplate extends {
|
|
134
|
-
sections: readonly {
|
|
135
|
-
fields: readonly {
|
|
136
|
-
id: string;
|
|
137
|
-
type: ReportTemplateFieldType;
|
|
138
|
-
required?: boolean;
|
|
139
|
-
options?: readonly string[] | string[];
|
|
140
|
-
}[];
|
|
141
|
-
}[];
|
|
142
|
-
}> = {
|
|
143
|
-
[F in TemplateFieldUnion<TTemplate> as F["id"]]: FieldResponseValue<F>;
|
|
144
|
-
};
|
|
100
|
+
declare function serializeReportTemplateSchema(schema: ReportTemplateSchema, options?: SerializeOptions): string;
|
|
145
101
|
|
|
146
102
|
interface TemplateDiff {
|
|
147
103
|
addedSections: Array<{
|
|
@@ -201,6 +157,46 @@ interface TemplateDiff {
|
|
|
201
157
|
}
|
|
202
158
|
declare function diffTemplates(before: ReportTemplateSchema, after: ReportTemplateSchema): TemplateDiff;
|
|
203
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Minimal JSON Schema type for our purposes.
|
|
162
|
+
* Flexible, with an index signature to allow vendor extensions (x-frt-*).
|
|
163
|
+
*/
|
|
164
|
+
interface JSONSchema {
|
|
165
|
+
$schema?: string;
|
|
166
|
+
$id?: string;
|
|
167
|
+
type?: "object" | "string" | "number" | "boolean" | "array" | "null";
|
|
168
|
+
properties?: Record<string, JSONSchema>;
|
|
169
|
+
items?: JSONSchema;
|
|
170
|
+
required?: string[];
|
|
171
|
+
enum?: any[];
|
|
172
|
+
minLength?: number;
|
|
173
|
+
maxLength?: number;
|
|
174
|
+
minimum?: number;
|
|
175
|
+
maximum?: number;
|
|
176
|
+
minItems?: number;
|
|
177
|
+
maxItems?: number;
|
|
178
|
+
description?: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
default?: any;
|
|
181
|
+
format?: string;
|
|
182
|
+
additionalProperties?: boolean;
|
|
183
|
+
[key: string]: any;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Export a report template as a JSON Schema "object" definition.
|
|
187
|
+
*
|
|
188
|
+
* - Each field becomes a property keyed by its `id`
|
|
189
|
+
* - Unconditional `required: true` fields are added to the JSON Schema `required` array
|
|
190
|
+
* - Conditional logic is preserved via `x-frt-visibleIf` / `x-frt-requiredIf`
|
|
191
|
+
* but NOT enforced in the core JSON Schema (since it's beyond standard JSON Schema).
|
|
192
|
+
*/
|
|
193
|
+
declare function exportJSONSchema(template: ReportTemplateSchema): JSONSchema;
|
|
194
|
+
|
|
195
|
+
declare const DEFAULT_FIELD_LABEL = "Untitled question";
|
|
196
|
+
declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string, unknown>>;
|
|
197
|
+
|
|
198
|
+
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
199
|
+
|
|
204
200
|
/** -------------------------------------------------------------
|
|
205
201
|
* FieldRegistryEntry
|
|
206
202
|
* --------------------------------------------------------------
|
|
@@ -250,39 +246,75 @@ declare const FieldRegistry: FieldRegistryClass;
|
|
|
250
246
|
*/
|
|
251
247
|
declare function evaluateCondition(condition: SimpleCondition, response: Record<string, any>): boolean;
|
|
252
248
|
|
|
249
|
+
declare function buildBaseFieldSchema(field: ReportTemplateField): ZodTypeAny;
|
|
250
|
+
declare function buildResponseSchemaWithConditions(template: ReportTemplateSchema, response: Record<string, any>): z.ZodObject<Record<string, ZodTypeAny>>;
|
|
251
|
+
declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
|
|
252
|
+
type FieldErrorCode = "response.invalid_root" | "field.required" | "field.invalid_type" | "field.too_small" | "field.too_big" | "field.invalid_option" | "field.custom";
|
|
253
|
+
interface ResponseFieldError {
|
|
254
|
+
/** field id (template-level id) */
|
|
255
|
+
fieldId: string;
|
|
256
|
+
/** section id that owns this field (if known) */
|
|
257
|
+
sectionId?: string;
|
|
258
|
+
/** section title (if available in template) */
|
|
259
|
+
sectionTitle?: string;
|
|
260
|
+
/** human label of the field */
|
|
261
|
+
label?: string;
|
|
262
|
+
/** normalized error code */
|
|
263
|
+
code: FieldErrorCode;
|
|
264
|
+
/** human-readable message (already enriched with section / label) */
|
|
265
|
+
message: string;
|
|
266
|
+
/** original Zod issue (for debugging / logging) */
|
|
267
|
+
rawIssue?: ZodIssue;
|
|
268
|
+
}
|
|
253
269
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
270
|
+
* Validates a response against a template, but instead of throwing,
|
|
271
|
+
* returns a structured error object with:
|
|
272
|
+
* - section title
|
|
273
|
+
* - field label
|
|
274
|
+
* - normalized error code
|
|
275
|
+
*
|
|
276
|
+
* Ideal for UI error display.
|
|
256
277
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
enum?: any[];
|
|
265
|
-
minLength?: number;
|
|
266
|
-
maxLength?: number;
|
|
267
|
-
minimum?: number;
|
|
268
|
-
maximum?: number;
|
|
269
|
-
minItems?: number;
|
|
270
|
-
maxItems?: number;
|
|
271
|
-
description?: string;
|
|
272
|
-
title?: string;
|
|
273
|
-
default?: any;
|
|
274
|
-
format?: string;
|
|
275
|
-
additionalProperties?: boolean;
|
|
276
|
-
[key: string]: any;
|
|
277
|
-
}
|
|
278
|
+
declare function validateReportResponseDetailed(template: ReportTemplateSchema, data: unknown): {
|
|
279
|
+
success: true;
|
|
280
|
+
value: Record<string, unknown>;
|
|
281
|
+
} | {
|
|
282
|
+
success: false;
|
|
283
|
+
errors: ResponseFieldError[];
|
|
284
|
+
};
|
|
278
285
|
/**
|
|
279
|
-
*
|
|
286
|
+
* Helper to turn a thrown ZodError (e.g. from validateReportResponse)
|
|
287
|
+
* into the same ResponseFieldError[] shape used by
|
|
288
|
+
* validateReportResponseDetailed.
|
|
280
289
|
*
|
|
281
|
-
*
|
|
282
|
-
* - Unconditional `required: true` fields are added to the JSON Schema `required` array
|
|
283
|
-
* - Conditional logic is preserved via `x-frt-visibleIf` / `x-frt-requiredIf`
|
|
284
|
-
* but NOT enforced in the core JSON Schema (since it's beyond standard JSON Schema).
|
|
290
|
+
* Returns null if the error is not a ZodError.
|
|
285
291
|
*/
|
|
286
|
-
declare function
|
|
292
|
+
declare function explainValidationError(template: ReportTemplateSchema, error: unknown): ResponseFieldError[] | null;
|
|
293
|
+
type TemplateFieldUnion<TTemplate> = TTemplate extends {
|
|
294
|
+
sections: readonly (infer S)[];
|
|
295
|
+
} ? S extends {
|
|
296
|
+
fields: readonly (infer F)[];
|
|
297
|
+
} ? F : never : never;
|
|
298
|
+
type BaseFieldValue<TField extends {
|
|
299
|
+
type: ReportTemplateFieldType;
|
|
300
|
+
required?: boolean;
|
|
301
|
+
options?: readonly string[] | string[];
|
|
302
|
+
}> = TField["type"] extends "shortText" | "longText" ? string : TField["type"] extends "number" ? number : TField["type"] extends "date" ? string : TField["type"] extends "checkbox" ? boolean : TField["type"] extends "singleSelect" ? (TField["options"] extends readonly (infer O)[] ? O : TField["options"] extends (infer O)[] ? O : string) : TField["type"] extends "multiSelect" ? (TField["options"] extends readonly (infer O)[] ? O[] : TField["options"] extends (infer O)[] ? O[] : string[]) : TField["type"] extends "repeatGroup" ? Array<Record<string, unknown>> : unknown;
|
|
303
|
+
type FieldResponseValue<TField extends {
|
|
304
|
+
type: ReportTemplateFieldType;
|
|
305
|
+
required?: boolean;
|
|
306
|
+
}> = TField["required"] extends true ? BaseFieldValue<TField> : BaseFieldValue<TField> | undefined;
|
|
307
|
+
type InferResponse<TTemplate extends {
|
|
308
|
+
sections: readonly {
|
|
309
|
+
fields: readonly {
|
|
310
|
+
id: string;
|
|
311
|
+
type: ReportTemplateFieldType;
|
|
312
|
+
required?: boolean;
|
|
313
|
+
options?: readonly string[] | string[];
|
|
314
|
+
}[];
|
|
315
|
+
}[];
|
|
316
|
+
}> = {
|
|
317
|
+
[F in TemplateFieldUnion<TTemplate> as F["id"]]: FieldResponseValue<F>;
|
|
318
|
+
};
|
|
287
319
|
|
|
288
|
-
export { CORE_FIELD_DEFAULTS, Condition, DEFAULT_FIELD_LABEL, type FieldErrorCode, FieldRegistry, type FieldRegistryEntry, type InferResponse, type JSONSchema, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, RepeatGroupFieldSchema, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, type ResponseFieldError, type SimpleCondition, type TemplateDiff, buildBaseFieldSchema, buildResponseSchemaWithConditions, createUniqueId, diffTemplates, evaluateCondition, exportJSONSchema, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse, validateReportResponseDetailed };
|
|
320
|
+
export { CORE_FIELD_DEFAULTS, Condition, DEFAULT_FIELD_LABEL, type FieldErrorCode, FieldRegistry, type FieldRegistryEntry, type InferResponse, type JSONSchema, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, RepeatGroupFieldSchema, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, type ResponseFieldError, type SerializeOptions, type SimpleCondition, type TemplateDiff, buildBaseFieldSchema, buildResponseSchemaWithConditions, createUniqueId, diffTemplates, evaluateCondition, explainValidationError, exportJSONSchema, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse, validateReportResponseDetailed };
|
package/dist/index.d.ts
CHANGED
|
@@ -68,80 +68,36 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
68
68
|
}>;
|
|
69
69
|
type ReportTemplateSchema = z.infer<typeof ReportTemplateSchemaValidator>;
|
|
70
70
|
|
|
71
|
-
declare const DEFAULT_FIELD_LABEL = "Untitled question";
|
|
72
|
-
declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string, unknown>>;
|
|
73
|
-
|
|
74
|
-
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
75
|
-
|
|
76
71
|
declare function migrateLegacySchema(raw: unknown): unknown;
|
|
77
72
|
|
|
78
73
|
declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
|
|
79
74
|
declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
|
|
80
75
|
declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
code: FieldErrorCode;
|
|
98
|
-
/** human-readable message (already enriched with section / label) */
|
|
99
|
-
message: string;
|
|
100
|
-
/** original Zod issue (for debugging / logging) */
|
|
101
|
-
rawIssue?: ZodIssue;
|
|
76
|
+
interface SerializeOptions {
|
|
77
|
+
/**
|
|
78
|
+
* If true (default), output human-readable JSON with 2-space indentation.
|
|
79
|
+
* If false, output a compact single-line JSON string.
|
|
80
|
+
*/
|
|
81
|
+
pretty?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* If true, sections will be sorted by their `id` before serialization.
|
|
84
|
+
* This is useful for deterministic diffs across environments.
|
|
85
|
+
*/
|
|
86
|
+
sortSectionsById?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* If true, fields within each section will be sorted by their `id`
|
|
89
|
+
* before serialization. Also useful for stable diffs.
|
|
90
|
+
*/
|
|
91
|
+
sortFieldsById?: boolean;
|
|
102
92
|
}
|
|
103
93
|
/**
|
|
104
|
-
*
|
|
105
|
-
* returns a structured error object with:
|
|
106
|
-
* - section title
|
|
107
|
-
* - field label
|
|
108
|
-
* - normalized error code
|
|
94
|
+
* Serialize a template schema into JSON.
|
|
109
95
|
*
|
|
110
|
-
*
|
|
96
|
+
* - Optional pretty-printing (default: true)
|
|
97
|
+
* - Optional deterministic sorting of sections and fields by ID
|
|
98
|
+
* to make git diffs and code reviews cleaner.
|
|
111
99
|
*/
|
|
112
|
-
declare function
|
|
113
|
-
success: true;
|
|
114
|
-
value: Record<string, unknown>;
|
|
115
|
-
} | {
|
|
116
|
-
success: false;
|
|
117
|
-
errors: ResponseFieldError[];
|
|
118
|
-
};
|
|
119
|
-
type TemplateFieldUnion<TTemplate> = TTemplate extends {
|
|
120
|
-
sections: readonly (infer S)[];
|
|
121
|
-
} ? S extends {
|
|
122
|
-
fields: readonly (infer F)[];
|
|
123
|
-
} ? F : never : never;
|
|
124
|
-
type BaseFieldValue<TField extends {
|
|
125
|
-
type: ReportTemplateFieldType;
|
|
126
|
-
required?: boolean;
|
|
127
|
-
options?: readonly string[] | string[];
|
|
128
|
-
}> = TField["type"] extends "shortText" | "longText" ? string : TField["type"] extends "number" ? number : TField["type"] extends "date" ? string : TField["type"] extends "checkbox" ? boolean : TField["type"] extends "singleSelect" ? (TField["options"] extends readonly (infer O)[] ? O : TField["options"] extends (infer O)[] ? O : string) : TField["type"] extends "multiSelect" ? (TField["options"] extends readonly (infer O)[] ? O[] : TField["options"] extends (infer O)[] ? O[] : string[]) : unknown;
|
|
129
|
-
type FieldResponseValue<TField extends {
|
|
130
|
-
type: ReportTemplateFieldType;
|
|
131
|
-
required?: boolean;
|
|
132
|
-
}> = TField["required"] extends true ? BaseFieldValue<TField> : BaseFieldValue<TField> | undefined;
|
|
133
|
-
type InferResponse<TTemplate extends {
|
|
134
|
-
sections: readonly {
|
|
135
|
-
fields: readonly {
|
|
136
|
-
id: string;
|
|
137
|
-
type: ReportTemplateFieldType;
|
|
138
|
-
required?: boolean;
|
|
139
|
-
options?: readonly string[] | string[];
|
|
140
|
-
}[];
|
|
141
|
-
}[];
|
|
142
|
-
}> = {
|
|
143
|
-
[F in TemplateFieldUnion<TTemplate> as F["id"]]: FieldResponseValue<F>;
|
|
144
|
-
};
|
|
100
|
+
declare function serializeReportTemplateSchema(schema: ReportTemplateSchema, options?: SerializeOptions): string;
|
|
145
101
|
|
|
146
102
|
interface TemplateDiff {
|
|
147
103
|
addedSections: Array<{
|
|
@@ -201,6 +157,46 @@ interface TemplateDiff {
|
|
|
201
157
|
}
|
|
202
158
|
declare function diffTemplates(before: ReportTemplateSchema, after: ReportTemplateSchema): TemplateDiff;
|
|
203
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Minimal JSON Schema type for our purposes.
|
|
162
|
+
* Flexible, with an index signature to allow vendor extensions (x-frt-*).
|
|
163
|
+
*/
|
|
164
|
+
interface JSONSchema {
|
|
165
|
+
$schema?: string;
|
|
166
|
+
$id?: string;
|
|
167
|
+
type?: "object" | "string" | "number" | "boolean" | "array" | "null";
|
|
168
|
+
properties?: Record<string, JSONSchema>;
|
|
169
|
+
items?: JSONSchema;
|
|
170
|
+
required?: string[];
|
|
171
|
+
enum?: any[];
|
|
172
|
+
minLength?: number;
|
|
173
|
+
maxLength?: number;
|
|
174
|
+
minimum?: number;
|
|
175
|
+
maximum?: number;
|
|
176
|
+
minItems?: number;
|
|
177
|
+
maxItems?: number;
|
|
178
|
+
description?: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
default?: any;
|
|
181
|
+
format?: string;
|
|
182
|
+
additionalProperties?: boolean;
|
|
183
|
+
[key: string]: any;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Export a report template as a JSON Schema "object" definition.
|
|
187
|
+
*
|
|
188
|
+
* - Each field becomes a property keyed by its `id`
|
|
189
|
+
* - Unconditional `required: true` fields are added to the JSON Schema `required` array
|
|
190
|
+
* - Conditional logic is preserved via `x-frt-visibleIf` / `x-frt-requiredIf`
|
|
191
|
+
* but NOT enforced in the core JSON Schema (since it's beyond standard JSON Schema).
|
|
192
|
+
*/
|
|
193
|
+
declare function exportJSONSchema(template: ReportTemplateSchema): JSONSchema;
|
|
194
|
+
|
|
195
|
+
declare const DEFAULT_FIELD_LABEL = "Untitled question";
|
|
196
|
+
declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string, unknown>>;
|
|
197
|
+
|
|
198
|
+
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
199
|
+
|
|
204
200
|
/** -------------------------------------------------------------
|
|
205
201
|
* FieldRegistryEntry
|
|
206
202
|
* --------------------------------------------------------------
|
|
@@ -250,39 +246,75 @@ declare const FieldRegistry: FieldRegistryClass;
|
|
|
250
246
|
*/
|
|
251
247
|
declare function evaluateCondition(condition: SimpleCondition, response: Record<string, any>): boolean;
|
|
252
248
|
|
|
249
|
+
declare function buildBaseFieldSchema(field: ReportTemplateField): ZodTypeAny;
|
|
250
|
+
declare function buildResponseSchemaWithConditions(template: ReportTemplateSchema, response: Record<string, any>): z.ZodObject<Record<string, ZodTypeAny>>;
|
|
251
|
+
declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
|
|
252
|
+
type FieldErrorCode = "response.invalid_root" | "field.required" | "field.invalid_type" | "field.too_small" | "field.too_big" | "field.invalid_option" | "field.custom";
|
|
253
|
+
interface ResponseFieldError {
|
|
254
|
+
/** field id (template-level id) */
|
|
255
|
+
fieldId: string;
|
|
256
|
+
/** section id that owns this field (if known) */
|
|
257
|
+
sectionId?: string;
|
|
258
|
+
/** section title (if available in template) */
|
|
259
|
+
sectionTitle?: string;
|
|
260
|
+
/** human label of the field */
|
|
261
|
+
label?: string;
|
|
262
|
+
/** normalized error code */
|
|
263
|
+
code: FieldErrorCode;
|
|
264
|
+
/** human-readable message (already enriched with section / label) */
|
|
265
|
+
message: string;
|
|
266
|
+
/** original Zod issue (for debugging / logging) */
|
|
267
|
+
rawIssue?: ZodIssue;
|
|
268
|
+
}
|
|
253
269
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
270
|
+
* Validates a response against a template, but instead of throwing,
|
|
271
|
+
* returns a structured error object with:
|
|
272
|
+
* - section title
|
|
273
|
+
* - field label
|
|
274
|
+
* - normalized error code
|
|
275
|
+
*
|
|
276
|
+
* Ideal for UI error display.
|
|
256
277
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
enum?: any[];
|
|
265
|
-
minLength?: number;
|
|
266
|
-
maxLength?: number;
|
|
267
|
-
minimum?: number;
|
|
268
|
-
maximum?: number;
|
|
269
|
-
minItems?: number;
|
|
270
|
-
maxItems?: number;
|
|
271
|
-
description?: string;
|
|
272
|
-
title?: string;
|
|
273
|
-
default?: any;
|
|
274
|
-
format?: string;
|
|
275
|
-
additionalProperties?: boolean;
|
|
276
|
-
[key: string]: any;
|
|
277
|
-
}
|
|
278
|
+
declare function validateReportResponseDetailed(template: ReportTemplateSchema, data: unknown): {
|
|
279
|
+
success: true;
|
|
280
|
+
value: Record<string, unknown>;
|
|
281
|
+
} | {
|
|
282
|
+
success: false;
|
|
283
|
+
errors: ResponseFieldError[];
|
|
284
|
+
};
|
|
278
285
|
/**
|
|
279
|
-
*
|
|
286
|
+
* Helper to turn a thrown ZodError (e.g. from validateReportResponse)
|
|
287
|
+
* into the same ResponseFieldError[] shape used by
|
|
288
|
+
* validateReportResponseDetailed.
|
|
280
289
|
*
|
|
281
|
-
*
|
|
282
|
-
* - Unconditional `required: true` fields are added to the JSON Schema `required` array
|
|
283
|
-
* - Conditional logic is preserved via `x-frt-visibleIf` / `x-frt-requiredIf`
|
|
284
|
-
* but NOT enforced in the core JSON Schema (since it's beyond standard JSON Schema).
|
|
290
|
+
* Returns null if the error is not a ZodError.
|
|
285
291
|
*/
|
|
286
|
-
declare function
|
|
292
|
+
declare function explainValidationError(template: ReportTemplateSchema, error: unknown): ResponseFieldError[] | null;
|
|
293
|
+
type TemplateFieldUnion<TTemplate> = TTemplate extends {
|
|
294
|
+
sections: readonly (infer S)[];
|
|
295
|
+
} ? S extends {
|
|
296
|
+
fields: readonly (infer F)[];
|
|
297
|
+
} ? F : never : never;
|
|
298
|
+
type BaseFieldValue<TField extends {
|
|
299
|
+
type: ReportTemplateFieldType;
|
|
300
|
+
required?: boolean;
|
|
301
|
+
options?: readonly string[] | string[];
|
|
302
|
+
}> = TField["type"] extends "shortText" | "longText" ? string : TField["type"] extends "number" ? number : TField["type"] extends "date" ? string : TField["type"] extends "checkbox" ? boolean : TField["type"] extends "singleSelect" ? (TField["options"] extends readonly (infer O)[] ? O : TField["options"] extends (infer O)[] ? O : string) : TField["type"] extends "multiSelect" ? (TField["options"] extends readonly (infer O)[] ? O[] : TField["options"] extends (infer O)[] ? O[] : string[]) : TField["type"] extends "repeatGroup" ? Array<Record<string, unknown>> : unknown;
|
|
303
|
+
type FieldResponseValue<TField extends {
|
|
304
|
+
type: ReportTemplateFieldType;
|
|
305
|
+
required?: boolean;
|
|
306
|
+
}> = TField["required"] extends true ? BaseFieldValue<TField> : BaseFieldValue<TField> | undefined;
|
|
307
|
+
type InferResponse<TTemplate extends {
|
|
308
|
+
sections: readonly {
|
|
309
|
+
fields: readonly {
|
|
310
|
+
id: string;
|
|
311
|
+
type: ReportTemplateFieldType;
|
|
312
|
+
required?: boolean;
|
|
313
|
+
options?: readonly string[] | string[];
|
|
314
|
+
}[];
|
|
315
|
+
}[];
|
|
316
|
+
}> = {
|
|
317
|
+
[F in TemplateFieldUnion<TTemplate> as F["id"]]: FieldResponseValue<F>;
|
|
318
|
+
};
|
|
287
319
|
|
|
288
|
-
export { CORE_FIELD_DEFAULTS, Condition, DEFAULT_FIELD_LABEL, type FieldErrorCode, FieldRegistry, type FieldRegistryEntry, type InferResponse, type JSONSchema, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, RepeatGroupFieldSchema, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, type ResponseFieldError, type SimpleCondition, type TemplateDiff, buildBaseFieldSchema, buildResponseSchemaWithConditions, createUniqueId, diffTemplates, evaluateCondition, exportJSONSchema, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse, validateReportResponseDetailed };
|
|
320
|
+
export { CORE_FIELD_DEFAULTS, Condition, DEFAULT_FIELD_LABEL, type FieldErrorCode, FieldRegistry, type FieldRegistryEntry, type InferResponse, type JSONSchema, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, RepeatGroupFieldSchema, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, type ResponseFieldError, type SerializeOptions, type SimpleCondition, type TemplateDiff, buildBaseFieldSchema, buildResponseSchemaWithConditions, createUniqueId, diffTemplates, evaluateCondition, explainValidationError, exportJSONSchema, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse, validateReportResponseDetailed };
|