@codenkay/questionbankextractor-question-schema 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ - Initial public package under `@codenkay/questionbankextractor-*`
6
+ - Renamed from private `@cwte/*` workspace scope
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # `@codenkay/questionbankextractor-question-schema`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Question JSON schema, Zod validators, and TypeScript types for Careerwill Question Extraction Studio exports.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @codenkay/questionbankextractor-question-schema zod
9
+ ```
10
+
11
+ Requires Node ≥ 20. Peer: `zod` ^3.25.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import {
17
+ parseQuestionDocument,
18
+ safeParseQuestionDocument,
19
+ QUESTION_SCHEMA_VERSION,
20
+ type QuestionDocument,
21
+ } from '@codenkay/questionbankextractor-question-schema';
22
+
23
+ const doc = parseQuestionDocument(json);
24
+ ```
25
+
26
+ ## Supported question types
27
+
28
+ - `scq` — single correct
29
+ - `mcq` — multi correct
30
+ - `numeric` — numeric answer with tolerance
31
+
32
+ Also validates media/charts manifests and export helpers (`toQuestionExportMode`).
33
+
34
+ ## Related
35
+
36
+ - [`@codenkay/questionbankextractor-document-ir`](../document-ir-schema)
37
+ - Sample: [questionbankextractor-sample-react](https://github.com/codenannu/questionbankextractor-sample-react)
package/dist/index.cjs ADDED
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ChartItemSchema: () => ChartItemSchema,
24
+ ChartSeriesSchema: () => ChartSeriesSchema,
25
+ ContentBlockSchema: () => ContentBlockSchema,
26
+ MediaItemSchema: () => MediaItemSchema,
27
+ NumericAnswerSchema: () => NumericAnswerSchema,
28
+ OptionSchema: () => OptionSchema,
29
+ ProcessingSchema: () => ProcessingSchema,
30
+ QUESTION_SCHEMA_VERSION: () => QUESTION_SCHEMA_VERSION,
31
+ QuestionDocumentSchema: () => QuestionDocumentSchema,
32
+ QuestionMetadataSchema: () => QuestionMetadataSchema,
33
+ QuestionSchema: () => QuestionSchema,
34
+ deriveAnswers: () => deriveAnswers,
35
+ parseQuestionDocument: () => parseQuestionDocument,
36
+ safeParseQuestionDocument: () => safeParseQuestionDocument,
37
+ toQuestionExportMode: () => toQuestionExportMode,
38
+ validateQuestionBusinessRules: () => validateQuestionBusinessRules
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+ var import_zod = require("zod");
42
+ var QUESTION_SCHEMA_VERSION = "1.0.0";
43
+ var ContentBlockSchema = import_zod.z.discriminatedUnion("type", [
44
+ import_zod.z.object({
45
+ id: import_zod.z.string(),
46
+ type: import_zod.z.literal("paragraph"),
47
+ html: import_zod.z.string().optional(),
48
+ text: import_zod.z.string().optional()
49
+ }),
50
+ import_zod.z.object({
51
+ id: import_zod.z.string(),
52
+ type: import_zod.z.literal("math"),
53
+ format: import_zod.z.enum(["latex", "mathml"]),
54
+ value: import_zod.z.string(),
55
+ fallbackMediaId: import_zod.z.string().optional()
56
+ }),
57
+ import_zod.z.object({
58
+ id: import_zod.z.string(),
59
+ type: import_zod.z.literal("image"),
60
+ mediaId: import_zod.z.string(),
61
+ alt: import_zod.z.string().optional()
62
+ }),
63
+ import_zod.z.object({
64
+ id: import_zod.z.string(),
65
+ type: import_zod.z.literal("table"),
66
+ tableId: import_zod.z.string()
67
+ }),
68
+ import_zod.z.object({
69
+ id: import_zod.z.string(),
70
+ type: import_zod.z.literal("chart"),
71
+ chartId: import_zod.z.string()
72
+ }),
73
+ import_zod.z.object({
74
+ id: import_zod.z.string(),
75
+ type: import_zod.z.literal("diagram"),
76
+ mediaId: import_zod.z.string(),
77
+ kind: import_zod.z.string().optional()
78
+ })
79
+ ]);
80
+ var NumericAnswerSchema = import_zod.z.object({
81
+ value: import_zod.z.number(),
82
+ acceptedValues: import_zod.z.array(import_zod.z.number()).optional(),
83
+ tolerance: import_zod.z.number().optional(),
84
+ relativeTolerance: import_zod.z.number().optional(),
85
+ precision: import_zod.z.number().optional(),
86
+ min: import_zod.z.number().optional(),
87
+ max: import_zod.z.number().optional(),
88
+ unit: import_zod.z.string().optional()
89
+ });
90
+ var OptionSchema = import_zod.z.object({
91
+ prompt: import_zod.z.string().regex(/^[a-e]$/i),
92
+ value: import_zod.z.string(),
93
+ iscorrect: import_zod.z.boolean(),
94
+ valueEn: import_zod.z.string().optional(),
95
+ valueHi: import_zod.z.string().optional()
96
+ });
97
+ var QuestionMetadataSchema = import_zod.z.object({
98
+ sourcePage: import_zod.z.number().int().positive().optional(),
99
+ confidence: import_zod.z.number().min(0).max(1).optional(),
100
+ confidenceBreakdown: import_zod.z.object({
101
+ text: import_zod.z.number().min(0).max(1).optional(),
102
+ options: import_zod.z.number().min(0).max(1).optional(),
103
+ answer: import_zod.z.number().min(0).max(1).optional(),
104
+ solution: import_zod.z.number().min(0).max(1).optional(),
105
+ math: import_zod.z.number().min(0).max(1).optional(),
106
+ ocr: import_zod.z.number().min(0).max(1).optional()
107
+ }).optional(),
108
+ warnings: import_zod.z.array(import_zod.z.string()).optional(),
109
+ errors: import_zod.z.array(import_zod.z.string()).optional(),
110
+ answerSources: import_zod.z.array(import_zod.z.enum(["star", "answer_field", "answer_key", "manual"])).optional(),
111
+ answerConflict: import_zod.z.boolean().optional(),
112
+ reviewStatus: import_zod.z.enum(["pending", "corrected", "approved", "rejected"]).optional(),
113
+ profile: import_zod.z.string().optional()
114
+ });
115
+ var QuestionSchema = import_zod.z.object({
116
+ no: import_zod.z.number().int().positive(),
117
+ type: import_zod.z.enum(["scq", "mcq", "numeric"]),
118
+ value: import_zod.z.string(),
119
+ options: import_zod.z.array(OptionSchema).default([]),
120
+ answers: import_zod.z.array(import_zod.z.string()).default([]),
121
+ solutions: import_zod.z.string().default(""),
122
+ valueEn: import_zod.z.string().optional(),
123
+ valueHi: import_zod.z.string().optional(),
124
+ solutionsEn: import_zod.z.string().optional(),
125
+ solutionsHi: import_zod.z.string().optional(),
126
+ numericAnswer: NumericAnswerSchema.optional(),
127
+ contentBlocks: import_zod.z.array(ContentBlockSchema).optional(),
128
+ metadata: QuestionMetadataSchema.optional()
129
+ });
130
+ var MediaItemSchema = import_zod.z.object({
131
+ id: import_zod.z.string(),
132
+ originalName: import_zod.z.string().optional(),
133
+ mimeType: import_zod.z.string(),
134
+ byteSize: import_zod.z.number().int().nonnegative(),
135
+ width: import_zod.z.number().optional(),
136
+ height: import_zod.z.number().optional(),
137
+ sha256: import_zod.z.string(),
138
+ category: import_zod.z.enum(["image", "math_fallback", "chart_fallback", "diagram", "other"]).default("image"),
139
+ storage: import_zod.z.enum(["base64", "local", "s3"]),
140
+ ref: import_zod.z.string()
141
+ });
142
+ var ChartSeriesSchema = import_zod.z.object({
143
+ name: import_zod.z.string(),
144
+ data: import_zod.z.array(import_zod.z.number())
145
+ });
146
+ var ChartItemSchema = import_zod.z.object({
147
+ id: import_zod.z.string(),
148
+ mimeType: import_zod.z.string().default("application/json"),
149
+ byteSize: import_zod.z.number().int().nonnegative().default(0),
150
+ sha256: import_zod.z.string().default(""),
151
+ storage: import_zod.z.enum(["base64", "local", "s3"]).default("local"),
152
+ ref: import_zod.z.string().default(""),
153
+ chartType: import_zod.z.string(),
154
+ title: import_zod.z.string().optional(),
155
+ categories: import_zod.z.array(import_zod.z.string()).default([]),
156
+ series: import_zod.z.array(ChartSeriesSchema).default([]),
157
+ fallbackMediaId: import_zod.z.string().optional(),
158
+ unsupportedFeatures: import_zod.z.array(import_zod.z.string()).optional()
159
+ });
160
+ var ProcessingSchema = import_zod.z.object({
161
+ status: import_zod.z.enum(["queued", "processing", "completed", "failed", "cancelled"]),
162
+ totalQuestions: import_zod.z.number().int().nonnegative(),
163
+ successfulQuestions: import_zod.z.number().int().nonnegative(),
164
+ failedQuestions: import_zod.z.number().int().nonnegative(),
165
+ warnings: import_zod.z.number().int().nonnegative(),
166
+ durationMs: import_zod.z.number().optional(),
167
+ stages: import_zod.z.array(
168
+ import_zod.z.object({
169
+ name: import_zod.z.string(),
170
+ status: import_zod.z.string(),
171
+ durationMs: import_zod.z.number().optional(),
172
+ message: import_zod.z.string().optional()
173
+ })
174
+ ).optional()
175
+ });
176
+ var QuestionDocumentSchema = import_zod.z.object({
177
+ schemaVersion: import_zod.z.literal(QUESTION_SCHEMA_VERSION),
178
+ document: import_zod.z.object({
179
+ fileName: import_zod.z.string(),
180
+ sourceFormat: import_zod.z.enum(["docx", "pdf"]),
181
+ language: import_zod.z.array(import_zod.z.enum(["en", "hi"])).default(["en"])
182
+ }),
183
+ questions: import_zod.z.array(QuestionSchema),
184
+ media: import_zod.z.array(MediaItemSchema).default([]),
185
+ charts: import_zod.z.array(ChartItemSchema).default([]),
186
+ processing: ProcessingSchema,
187
+ workingRevision: import_zod.z.number().int().nonnegative().optional()
188
+ });
189
+ function deriveAnswers(question) {
190
+ if (question.type === "numeric") return [];
191
+ return question.options.filter((o) => o.iscorrect).map((o) => o.prompt.toLowerCase());
192
+ }
193
+ function validateQuestionBusinessRules(question) {
194
+ const errors = [];
195
+ const prompts = question.options.map((o) => o.prompt.toLowerCase());
196
+ if (new Set(prompts).size !== prompts.length) {
197
+ errors.push("Option prompts must be unique");
198
+ }
199
+ if (question.type === "scq" || question.type === "mcq") {
200
+ if (question.options.length < 2 || question.options.length > 5) {
201
+ errors.push("Choice questions require 2\u20135 options");
202
+ }
203
+ const correct = question.options.filter((o) => o.iscorrect);
204
+ if (question.type === "scq" && correct.length !== 1) {
205
+ errors.push("scq requires exactly one correct option");
206
+ }
207
+ if (question.type === "mcq" && correct.length < 1) {
208
+ errors.push("mcq requires at least one correct option");
209
+ }
210
+ const derived = deriveAnswers(question);
211
+ const answers = question.answers.map((a) => a.toLowerCase()).sort();
212
+ if (JSON.stringify(derived.sort()) !== JSON.stringify(answers)) {
213
+ errors.push("answers must match options marked iscorrect");
214
+ }
215
+ }
216
+ if (question.type === "numeric") {
217
+ if (!question.numericAnswer) {
218
+ errors.push("numeric requires numericAnswer");
219
+ }
220
+ if (question.options.length > 0) {
221
+ errors.push("numeric must not use options");
222
+ }
223
+ }
224
+ return errors;
225
+ }
226
+ function parseQuestionDocument(input) {
227
+ const doc = QuestionDocumentSchema.parse(input);
228
+ const businessErrors = [];
229
+ for (const q of doc.questions) {
230
+ businessErrors.push(
231
+ ...validateQuestionBusinessRules(q).map((e) => `Q${q.no}: ${e}`)
232
+ );
233
+ }
234
+ if (businessErrors.length) {
235
+ throw new Error(businessErrors.join("; "));
236
+ }
237
+ return doc;
238
+ }
239
+ function safeParseQuestionDocument(input) {
240
+ const parsed = QuestionDocumentSchema.safeParse(input);
241
+ if (!parsed.success) return parsed;
242
+ const businessErrors = [];
243
+ for (const q of parsed.data.questions) {
244
+ businessErrors.push(
245
+ ...validateQuestionBusinessRules(q).map((e) => `Q${q.no}: ${e}`)
246
+ );
247
+ }
248
+ if (businessErrors.length) {
249
+ return {
250
+ success: false,
251
+ error: { issues: businessErrors.map((m) => ({ message: m })) }
252
+ };
253
+ }
254
+ return parsed;
255
+ }
256
+ function toQuestionExportMode(doc) {
257
+ return {
258
+ ...doc,
259
+ questions: doc.questions.map((q) => ({
260
+ ...q,
261
+ metadata: q.metadata ? {
262
+ sourcePage: q.metadata.sourcePage,
263
+ confidence: q.metadata.confidence,
264
+ warnings: q.metadata.warnings,
265
+ answerConflict: q.metadata.answerConflict,
266
+ reviewStatus: q.metadata.reviewStatus
267
+ } : void 0
268
+ })),
269
+ processing: {
270
+ status: doc.processing.status,
271
+ totalQuestions: doc.processing.totalQuestions,
272
+ successfulQuestions: doc.processing.successfulQuestions,
273
+ failedQuestions: doc.processing.failedQuestions,
274
+ warnings: doc.processing.warnings,
275
+ durationMs: doc.processing.durationMs
276
+ }
277
+ };
278
+ }
279
+ // Annotate the CommonJS export names for ESM import in node:
280
+ 0 && (module.exports = {
281
+ ChartItemSchema,
282
+ ChartSeriesSchema,
283
+ ContentBlockSchema,
284
+ MediaItemSchema,
285
+ NumericAnswerSchema,
286
+ OptionSchema,
287
+ ProcessingSchema,
288
+ QUESTION_SCHEMA_VERSION,
289
+ QuestionDocumentSchema,
290
+ QuestionMetadataSchema,
291
+ QuestionSchema,
292
+ deriveAnswers,
293
+ parseQuestionDocument,
294
+ safeParseQuestionDocument,
295
+ toQuestionExportMode,
296
+ validateQuestionBusinessRules
297
+ });
298
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const QUESTION_SCHEMA_VERSION = '1.0.0' as const;\n\nexport const ContentBlockSchema = z.discriminatedUnion('type', [\n z.object({\n id: z.string(),\n type: z.literal('paragraph'),\n html: z.string().optional(),\n text: z.string().optional(),\n }),\n z.object({\n id: z.string(),\n type: z.literal('math'),\n format: z.enum(['latex', 'mathml']),\n value: z.string(),\n fallbackMediaId: z.string().optional(),\n }),\n z.object({\n id: z.string(),\n type: z.literal('image'),\n mediaId: z.string(),\n alt: z.string().optional(),\n }),\n z.object({\n id: z.string(),\n type: z.literal('table'),\n tableId: z.string(),\n }),\n z.object({\n id: z.string(),\n type: z.literal('chart'),\n chartId: z.string(),\n }),\n z.object({\n id: z.string(),\n type: z.literal('diagram'),\n mediaId: z.string(),\n kind: z.string().optional(),\n }),\n]);\n\nexport const NumericAnswerSchema = z.object({\n value: z.number(),\n acceptedValues: z.array(z.number()).optional(),\n tolerance: z.number().optional(),\n relativeTolerance: z.number().optional(),\n precision: z.number().optional(),\n min: z.number().optional(),\n max: z.number().optional(),\n unit: z.string().optional(),\n});\n\nexport const OptionSchema = z.object({\n prompt: z.string().regex(/^[a-e]$/i),\n value: z.string(),\n iscorrect: z.boolean(),\n valueEn: z.string().optional(),\n valueHi: z.string().optional(),\n});\n\nexport const QuestionMetadataSchema = z.object({\n sourcePage: z.number().int().positive().optional(),\n confidence: z.number().min(0).max(1).optional(),\n confidenceBreakdown: z\n .object({\n text: z.number().min(0).max(1).optional(),\n options: z.number().min(0).max(1).optional(),\n answer: z.number().min(0).max(1).optional(),\n solution: z.number().min(0).max(1).optional(),\n math: z.number().min(0).max(1).optional(),\n ocr: z.number().min(0).max(1).optional(),\n })\n .optional(),\n warnings: z.array(z.string()).optional(),\n errors: z.array(z.string()).optional(),\n answerSources: z\n .array(z.enum(['star', 'answer_field', 'answer_key', 'manual']))\n .optional(),\n answerConflict: z.boolean().optional(),\n reviewStatus: z\n .enum(['pending', 'corrected', 'approved', 'rejected'])\n .optional(),\n profile: z.string().optional(),\n});\n\nexport const QuestionSchema = z.object({\n no: z.number().int().positive(),\n type: z.enum(['scq', 'mcq', 'numeric']),\n value: z.string(),\n options: z.array(OptionSchema).default([]),\n answers: z.array(z.string()).default([]),\n solutions: z.string().default(''),\n valueEn: z.string().optional(),\n valueHi: z.string().optional(),\n solutionsEn: z.string().optional(),\n solutionsHi: z.string().optional(),\n numericAnswer: NumericAnswerSchema.optional(),\n contentBlocks: z.array(ContentBlockSchema).optional(),\n metadata: QuestionMetadataSchema.optional(),\n});\n\nexport const MediaItemSchema = z.object({\n id: z.string(),\n originalName: z.string().optional(),\n mimeType: z.string(),\n byteSize: z.number().int().nonnegative(),\n width: z.number().optional(),\n height: z.number().optional(),\n sha256: z.string(),\n category: z\n .enum(['image', 'math_fallback', 'chart_fallback', 'diagram', 'other'])\n .default('image'),\n storage: z.enum(['base64', 'local', 's3']),\n ref: z.string(),\n});\n\nexport const ChartSeriesSchema = z.object({\n name: z.string(),\n data: z.array(z.number()),\n});\n\nexport const ChartItemSchema = z.object({\n id: z.string(),\n mimeType: z.string().default('application/json'),\n byteSize: z.number().int().nonnegative().default(0),\n sha256: z.string().default(''),\n storage: z.enum(['base64', 'local', 's3']).default('local'),\n ref: z.string().default(''),\n chartType: z.string(),\n title: z.string().optional(),\n categories: z.array(z.string()).default([]),\n series: z.array(ChartSeriesSchema).default([]),\n fallbackMediaId: z.string().optional(),\n unsupportedFeatures: z.array(z.string()).optional(),\n});\n\nexport const ProcessingSchema = z.object({\n status: z.enum(['queued', 'processing', 'completed', 'failed', 'cancelled']),\n totalQuestions: z.number().int().nonnegative(),\n successfulQuestions: z.number().int().nonnegative(),\n failedQuestions: z.number().int().nonnegative(),\n warnings: z.number().int().nonnegative(),\n durationMs: z.number().optional(),\n stages: z\n .array(\n z.object({\n name: z.string(),\n status: z.string(),\n durationMs: z.number().optional(),\n message: z.string().optional(),\n }),\n )\n .optional(),\n});\n\nexport const QuestionDocumentSchema = z.object({\n schemaVersion: z.literal(QUESTION_SCHEMA_VERSION),\n document: z.object({\n fileName: z.string(),\n sourceFormat: z.enum(['docx', 'pdf']),\n language: z.array(z.enum(['en', 'hi'])).default(['en']),\n }),\n questions: z.array(QuestionSchema),\n media: z.array(MediaItemSchema).default([]),\n charts: z.array(ChartItemSchema).default([]),\n processing: ProcessingSchema,\n workingRevision: z.number().int().nonnegative().optional(),\n});\n\nexport type ContentBlock = z.infer<typeof ContentBlockSchema>;\nexport type NumericAnswer = z.infer<typeof NumericAnswerSchema>;\nexport type QuestionOption = z.infer<typeof OptionSchema>;\nexport type Question = z.infer<typeof QuestionSchema>;\nexport type MediaItem = z.infer<typeof MediaItemSchema>;\nexport type ChartItem = z.infer<typeof ChartItemSchema>;\nexport type QuestionDocument = z.infer<typeof QuestionDocumentSchema>;\n\n/**\n * Synchronize answers from iscorrect flags and validate type rules.\n */\nexport function deriveAnswers(question: Question): string[] {\n if (question.type === 'numeric') return [];\n return question.options\n .filter((o) => o.iscorrect)\n .map((o) => o.prompt.toLowerCase());\n}\n\nexport function validateQuestionBusinessRules(question: Question): string[] {\n const errors: string[] = [];\n const prompts = question.options.map((o) => o.prompt.toLowerCase());\n if (new Set(prompts).size !== prompts.length) {\n errors.push('Option prompts must be unique');\n }\n if (question.type === 'scq' || question.type === 'mcq') {\n if (question.options.length < 2 || question.options.length > 5) {\n errors.push('Choice questions require 2–5 options');\n }\n const correct = question.options.filter((o) => o.iscorrect);\n if (question.type === 'scq' && correct.length !== 1) {\n errors.push('scq requires exactly one correct option');\n }\n if (question.type === 'mcq' && correct.length < 1) {\n errors.push('mcq requires at least one correct option');\n }\n const derived = deriveAnswers(question);\n const answers = question.answers.map((a) => a.toLowerCase()).sort();\n if (JSON.stringify(derived.sort()) !== JSON.stringify(answers)) {\n errors.push('answers must match options marked iscorrect');\n }\n }\n if (question.type === 'numeric') {\n if (!question.numericAnswer) {\n errors.push('numeric requires numericAnswer');\n }\n if (question.options.length > 0) {\n errors.push('numeric must not use options');\n }\n }\n return errors;\n}\n\nexport function parseQuestionDocument(input: unknown): QuestionDocument {\n const doc = QuestionDocumentSchema.parse(input);\n const businessErrors: string[] = [];\n for (const q of doc.questions) {\n businessErrors.push(\n ...validateQuestionBusinessRules(q).map((e) => `Q${q.no}: ${e}`),\n );\n }\n if (businessErrors.length) {\n throw new Error(businessErrors.join('; '));\n }\n return doc;\n}\n\nexport function safeParseQuestionDocument(input: unknown) {\n const parsed = QuestionDocumentSchema.safeParse(input);\n if (!parsed.success) return parsed;\n const businessErrors: string[] = [];\n for (const q of parsed.data.questions) {\n businessErrors.push(\n ...validateQuestionBusinessRules(q).map((e) => `Q${q.no}: ${e}`),\n );\n }\n if (businessErrors.length) {\n return {\n success: false as const,\n error: { issues: businessErrors.map((m) => ({ message: m })) },\n };\n }\n return parsed;\n}\n\n/** Strip heavy diagnostics for consumer Question JSON mode. */\nexport function toQuestionExportMode(doc: QuestionDocument): QuestionDocument {\n return {\n ...doc,\n questions: doc.questions.map((q) => ({\n ...q,\n metadata: q.metadata\n ? {\n sourcePage: q.metadata.sourcePage,\n confidence: q.metadata.confidence,\n warnings: q.metadata.warnings,\n answerConflict: q.metadata.answerConflict,\n reviewStatus: q.metadata.reviewStatus,\n }\n : undefined,\n })),\n processing: {\n status: doc.processing.status,\n totalQuestions: doc.processing.totalQuestions,\n successfulQuestions: doc.processing.successfulQuestions,\n failedQuestions: doc.processing.failedQuestions,\n warnings: doc.processing.warnings,\n durationMs: doc.processing.durationMs,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAEX,IAAM,0BAA0B;AAEhC,IAAM,qBAAqB,aAAE,mBAAmB,QAAQ;AAAA,EAC7D,aAAE,OAAO;AAAA,IACP,IAAI,aAAE,OAAO;AAAA,IACb,MAAM,aAAE,QAAQ,WAAW;AAAA,IAC3B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,IAAI,aAAE,OAAO;AAAA,IACb,MAAM,aAAE,QAAQ,MAAM;AAAA,IACtB,QAAQ,aAAE,KAAK,CAAC,SAAS,QAAQ,CAAC;AAAA,IAClC,OAAO,aAAE,OA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