@json-to-office/shared-docx 0.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/LICENSE +18 -0
- package/README.md +9 -0
- package/dist/chunk-5533WPL6.js +1895 -0
- package/dist/chunk-5533WPL6.js.map +1 -0
- package/dist/chunk-AA4HIXRG.js +34 -0
- package/dist/chunk-AA4HIXRG.js.map +1 -0
- package/dist/chunk-BEPLK76M.js +454 -0
- package/dist/chunk-BEPLK76M.js.map +1 -0
- package/dist/chunk-BOUURUYX.js +364 -0
- package/dist/chunk-BOUURUYX.js.map +1 -0
- package/dist/chunk-EKWM2CWA.js +97 -0
- package/dist/chunk-EKWM2CWA.js.map +1 -0
- package/dist/chunk-ET6YMNMF.js +35 -0
- package/dist/chunk-ET6YMNMF.js.map +1 -0
- package/dist/chunk-F5LVWDTY.js +57 -0
- package/dist/chunk-F5LVWDTY.js.map +1 -0
- package/dist/chunk-HHMK2RWF.js +274 -0
- package/dist/chunk-HHMK2RWF.js.map +1 -0
- package/dist/chunk-LOE6BZQG.js +750 -0
- package/dist/chunk-LOE6BZQG.js.map +1 -0
- package/dist/chunk-LWR4TFZ5.js +121 -0
- package/dist/chunk-LWR4TFZ5.js.map +1 -0
- package/dist/chunk-VP3X6DBP.js +44 -0
- package/dist/chunk-VP3X6DBP.js.map +1 -0
- package/dist/document-validator-CiaGiy1v.d.ts +119 -0
- package/dist/index.d.ts +938 -0
- package/dist/index.js +1129 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/api.d.ts +46 -0
- package/dist/schemas/api.js +16 -0
- package/dist/schemas/api.js.map +1 -0
- package/dist/schemas/component-registry.d.ts +90 -0
- package/dist/schemas/component-registry.js +24 -0
- package/dist/schemas/component-registry.js.map +1 -0
- package/dist/schemas/components.d.ts +755 -0
- package/dist/schemas/components.js +94 -0
- package/dist/schemas/components.js.map +1 -0
- package/dist/schemas/custom-components.d.ts +59 -0
- package/dist/schemas/custom-components.js +11 -0
- package/dist/schemas/custom-components.js.map +1 -0
- package/dist/schemas/document.d.ts +43 -0
- package/dist/schemas/document.js +19 -0
- package/dist/schemas/document.js.map +1 -0
- package/dist/schemas/export.d.ts +67 -0
- package/dist/schemas/export.js +19 -0
- package/dist/schemas/export.js.map +1 -0
- package/dist/schemas/font.d.ts +57 -0
- package/dist/schemas/font.js +11 -0
- package/dist/schemas/font.js.map +1 -0
- package/dist/schemas/generator.d.ts +80 -0
- package/dist/schemas/generator.js +9 -0
- package/dist/schemas/generator.js.map +1 -0
- package/dist/schemas/theme.d.ts +3354 -0
- package/dist/schemas/theme.js +42 -0
- package/dist/schemas/theme.js.map +1 -0
- package/dist/validation/unified/index.d.ts +720 -0
- package/dist/validation/unified/index.js +154 -0
- package/dist/validation/unified/index.js.map +1 -0
- package/package.json +80 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateUnifiedDocumentSchema
|
|
3
|
+
} from "./chunk-LWR4TFZ5.js";
|
|
4
|
+
import {
|
|
5
|
+
DOC_LINKS,
|
|
6
|
+
ERROR_TEMPLATES,
|
|
7
|
+
componentValidator,
|
|
8
|
+
createComponentValidator,
|
|
9
|
+
createThemeValidator,
|
|
10
|
+
getThemeName,
|
|
11
|
+
isColumnsProps,
|
|
12
|
+
isCustomComponentProps,
|
|
13
|
+
isFooterProps,
|
|
14
|
+
isHeaderProps,
|
|
15
|
+
isHeadingProps,
|
|
16
|
+
isImageProps,
|
|
17
|
+
isListProps,
|
|
18
|
+
isParagraphProps,
|
|
19
|
+
isReportProps,
|
|
20
|
+
isSectionProps,
|
|
21
|
+
isStandardComponentName,
|
|
22
|
+
isStatisticProps,
|
|
23
|
+
isTableProps,
|
|
24
|
+
isThemeConfig,
|
|
25
|
+
isValidTheme,
|
|
26
|
+
strictComponentValidator,
|
|
27
|
+
strictThemeValidator,
|
|
28
|
+
themeValidator,
|
|
29
|
+
validate,
|
|
30
|
+
validateComponent,
|
|
31
|
+
validateComponentDefinition,
|
|
32
|
+
validateCustomComponentProps,
|
|
33
|
+
validateStrict,
|
|
34
|
+
validateTheme,
|
|
35
|
+
validateThemeJson,
|
|
36
|
+
validateThemeWithEnhancement
|
|
37
|
+
} from "./chunk-BEPLK76M.js";
|
|
38
|
+
import {
|
|
39
|
+
ThemeConfigSchema,
|
|
40
|
+
isValidThemeConfig
|
|
41
|
+
} from "./chunk-BOUURUYX.js";
|
|
42
|
+
import {
|
|
43
|
+
GenerateDocumentRequestSchema,
|
|
44
|
+
GenerateDocumentResponseSchema,
|
|
45
|
+
ValidateDocumentRequestSchema,
|
|
46
|
+
ValidateDocumentResponseSchema
|
|
47
|
+
} from "./chunk-EKWM2CWA.js";
|
|
48
|
+
import {
|
|
49
|
+
JSON_SCHEMA_URLS,
|
|
50
|
+
JsonComponentDefinitionSchema
|
|
51
|
+
} from "./chunk-AA4HIXRG.js";
|
|
52
|
+
import {
|
|
53
|
+
comprehensiveValidateDocument,
|
|
54
|
+
createDocumentValidator,
|
|
55
|
+
createJsonValidator,
|
|
56
|
+
createValidator,
|
|
57
|
+
deepValidateDocument,
|
|
58
|
+
documentValidator,
|
|
59
|
+
getValidationSummary,
|
|
60
|
+
isValidDocument,
|
|
61
|
+
isValidationSuccess,
|
|
62
|
+
strictDocumentValidator,
|
|
63
|
+
transformValueError,
|
|
64
|
+
transformValueErrors,
|
|
65
|
+
validateAgainstSchema,
|
|
66
|
+
validateBatch,
|
|
67
|
+
validateDocument,
|
|
68
|
+
validateDocumentWithSchema,
|
|
69
|
+
validateJson,
|
|
70
|
+
validateJsonComponent,
|
|
71
|
+
validateJsonDocument,
|
|
72
|
+
validateWithEnhancement
|
|
73
|
+
} from "./chunk-LOE6BZQG.js";
|
|
74
|
+
import {
|
|
75
|
+
ComponentDefinitionSchema,
|
|
76
|
+
StandardComponentDefinitionSchema
|
|
77
|
+
} from "./chunk-ET6YMNMF.js";
|
|
78
|
+
import {
|
|
79
|
+
AlignmentSchema,
|
|
80
|
+
BaseComponentPropsSchema,
|
|
81
|
+
BorderSchema,
|
|
82
|
+
ColumnsPropsSchema,
|
|
83
|
+
FooterPropsSchema,
|
|
84
|
+
HeaderPropsSchema,
|
|
85
|
+
HeadingLevelSchema,
|
|
86
|
+
HeadingPropsSchema,
|
|
87
|
+
HighchartsPropsSchema,
|
|
88
|
+
ImagePropsSchema,
|
|
89
|
+
IndentSchema,
|
|
90
|
+
JustifiedAlignmentSchema,
|
|
91
|
+
LineSpacingSchema,
|
|
92
|
+
ListPropsSchema,
|
|
93
|
+
MarginsSchema,
|
|
94
|
+
NumberingSchema,
|
|
95
|
+
ParagraphPropsSchema,
|
|
96
|
+
ReportPropsSchema,
|
|
97
|
+
SectionPropsSchema,
|
|
98
|
+
SpacingSchema,
|
|
99
|
+
StatisticPropsSchema,
|
|
100
|
+
TablePropsSchema,
|
|
101
|
+
TextBoxPropsSchema,
|
|
102
|
+
TocPropsSchema
|
|
103
|
+
} from "./chunk-5533WPL6.js";
|
|
104
|
+
import {
|
|
105
|
+
CustomComponentDefinitionSchema,
|
|
106
|
+
TextSpaceAfterComponentSchema,
|
|
107
|
+
TextSpaceAfterPropsSchema
|
|
108
|
+
} from "./chunk-VP3X6DBP.js";
|
|
109
|
+
import {
|
|
110
|
+
BASE_SCHEMA_METADATA,
|
|
111
|
+
COMPONENT_METADATA,
|
|
112
|
+
THEME_SCHEMA_METADATA,
|
|
113
|
+
convertToJsonSchema,
|
|
114
|
+
createComponentSchema,
|
|
115
|
+
exportSchemaToFile,
|
|
116
|
+
fixSchemaReferences
|
|
117
|
+
} from "./chunk-HHMK2RWF.js";
|
|
118
|
+
import "./chunk-F5LVWDTY.js";
|
|
119
|
+
|
|
120
|
+
// src/index.ts
|
|
121
|
+
import {
|
|
122
|
+
fixSchemaReferences as fixSchemaReferences2,
|
|
123
|
+
convertToJsonSchema as convertToJsonSchema2,
|
|
124
|
+
createComponentSchema as createComponentSchema2,
|
|
125
|
+
createComponentSchemaObject,
|
|
126
|
+
exportSchemaToFile as exportSchemaToFile2
|
|
127
|
+
} from "@json-to-office/shared";
|
|
128
|
+
import {
|
|
129
|
+
transformValueError as transformValueError2,
|
|
130
|
+
transformValueErrors as transformValueErrors2,
|
|
131
|
+
formatErrorSummary,
|
|
132
|
+
groupErrorsByPath,
|
|
133
|
+
createJsonParseError,
|
|
134
|
+
calculatePosition
|
|
135
|
+
} from "@json-to-office/shared";
|
|
136
|
+
import {
|
|
137
|
+
DEFAULT_ERROR_CONFIG,
|
|
138
|
+
createErrorConfig,
|
|
139
|
+
ERROR_EMOJIS,
|
|
140
|
+
formatErrorMessage
|
|
141
|
+
} from "@json-to-office/shared";
|
|
142
|
+
import {
|
|
143
|
+
isUnionSchema,
|
|
144
|
+
isObjectSchema,
|
|
145
|
+
isLiteralSchema,
|
|
146
|
+
getObjectSchemaPropertyNames,
|
|
147
|
+
getLiteralValue,
|
|
148
|
+
extractStandardComponentNames,
|
|
149
|
+
clearComponentNamesCache,
|
|
150
|
+
getSchemaMetadata
|
|
151
|
+
} from "@json-to-office/shared";
|
|
152
|
+
import {
|
|
153
|
+
isValidSemver,
|
|
154
|
+
parseSemver,
|
|
155
|
+
compareSemver,
|
|
156
|
+
latestVersion
|
|
157
|
+
} from "@json-to-office/shared";
|
|
158
|
+
|
|
159
|
+
// src/validation/parsers/json.ts
|
|
160
|
+
import { Value } from "@sinclair/typebox/value";
|
|
161
|
+
import { FormatRegistry } from "@sinclair/typebox";
|
|
162
|
+
FormatRegistry.Set("uri", (value) => {
|
|
163
|
+
try {
|
|
164
|
+
new URL(value);
|
|
165
|
+
return true;
|
|
166
|
+
} catch {
|
|
167
|
+
if (value.includes(".json") || value.includes("/") || value.includes("\\")) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return /^https?:\/\/.+/.test(value);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
FormatRegistry.Set("date-time", (value) => {
|
|
174
|
+
const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
|
|
175
|
+
return dateTimeRegex.test(value) && !isNaN(Date.parse(value));
|
|
176
|
+
});
|
|
177
|
+
var JsonDocumentParser = class {
|
|
178
|
+
schema = ComponentDefinitionSchema;
|
|
179
|
+
constructor() {
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Parse JSON input (string or object) and validate against schema
|
|
183
|
+
* Only supports unified ComponentDefinition structure where document IS a report component
|
|
184
|
+
*/
|
|
185
|
+
parse(jsonInput) {
|
|
186
|
+
let parsedObject;
|
|
187
|
+
if (typeof jsonInput === "string") {
|
|
188
|
+
try {
|
|
189
|
+
parsedObject = JSON.parse(jsonInput);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw new JsonParsingError(
|
|
192
|
+
"Invalid JSON syntax",
|
|
193
|
+
this.extractJSONSyntaxError(error, jsonInput)
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
parsedObject = jsonInput;
|
|
198
|
+
}
|
|
199
|
+
if (typeof parsedObject !== "object" || parsedObject === null || !("name" in parsedObject) || parsedObject.name !== "docx") {
|
|
200
|
+
throw new JsonValidationError(
|
|
201
|
+
'Invalid document structure: Document must be a docx component with name="docx"',
|
|
202
|
+
[
|
|
203
|
+
{
|
|
204
|
+
path: "name",
|
|
205
|
+
message: 'Document must be a docx component with name="docx"',
|
|
206
|
+
code: "INVALID_STRUCTURE"
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (!Value.Check(this.schema, parsedObject)) {
|
|
212
|
+
const errors = [...Value.Errors(this.schema, parsedObject)];
|
|
213
|
+
throw new JsonValidationError(
|
|
214
|
+
"JSON validation failed",
|
|
215
|
+
this.formatTypeBoxErrors(
|
|
216
|
+
errors,
|
|
217
|
+
typeof jsonInput === "string" ? jsonInput : JSON.stringify(jsonInput, null, 2)
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
return parsedObject;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Validate JSON without throwing errors - returns ValidationResult
|
|
225
|
+
*/
|
|
226
|
+
validate(jsonInput) {
|
|
227
|
+
try {
|
|
228
|
+
this.parse(jsonInput);
|
|
229
|
+
return {
|
|
230
|
+
valid: true,
|
|
231
|
+
errors: [],
|
|
232
|
+
warnings: []
|
|
233
|
+
};
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (error instanceof JsonParsingError || error instanceof JsonValidationError) {
|
|
236
|
+
return {
|
|
237
|
+
valid: false,
|
|
238
|
+
errors: error.validationErrors,
|
|
239
|
+
warnings: []
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
valid: false,
|
|
244
|
+
errors: [
|
|
245
|
+
{
|
|
246
|
+
path: "",
|
|
247
|
+
message: error instanceof Error ? error.message : "Unknown validation error",
|
|
248
|
+
code: "UNEXPECTED_ERROR"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
warnings: []
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Parse JSON file content with line number tracking
|
|
257
|
+
*/
|
|
258
|
+
parseWithLineNumbers(jsonString) {
|
|
259
|
+
const lines = jsonString.split("\n");
|
|
260
|
+
try {
|
|
261
|
+
return this.parse(jsonString);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
if (error instanceof JsonParsingError || error instanceof JsonValidationError) {
|
|
264
|
+
const enhancedErrors = error.validationErrors.map((err) => ({
|
|
265
|
+
...err,
|
|
266
|
+
...this.findLineNumber(err.path, jsonString, lines)
|
|
267
|
+
}));
|
|
268
|
+
if (error instanceof JsonParsingError) {
|
|
269
|
+
throw new JsonParsingError(error.message, enhancedErrors);
|
|
270
|
+
} else {
|
|
271
|
+
throw new JsonValidationError(error.message, enhancedErrors);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Extract JSON syntax error information
|
|
279
|
+
*/
|
|
280
|
+
extractJSONSyntaxError(error, jsonString) {
|
|
281
|
+
const message = error.message;
|
|
282
|
+
const positionMatch = message.match(/position\s+(\d+)/i) || message.match(/at\s+(\d+)/i) || message.match(/character\s+(\d+)/i);
|
|
283
|
+
let line = 0;
|
|
284
|
+
let column = 0;
|
|
285
|
+
if (positionMatch) {
|
|
286
|
+
const position = parseInt(positionMatch[1], 10);
|
|
287
|
+
const lines = jsonString.substring(0, position).split("\n");
|
|
288
|
+
line = lines.length;
|
|
289
|
+
column = lines[lines.length - 1].length + 1;
|
|
290
|
+
}
|
|
291
|
+
return [
|
|
292
|
+
{
|
|
293
|
+
path: "",
|
|
294
|
+
message: `JSON syntax error: ${message}`,
|
|
295
|
+
code: "JSON_SYNTAX_ERROR",
|
|
296
|
+
line: line || void 0,
|
|
297
|
+
column: column || void 0,
|
|
298
|
+
suggestions: [
|
|
299
|
+
"Check for missing commas, brackets, or quotes",
|
|
300
|
+
"Validate JSON syntax using a JSON validator",
|
|
301
|
+
"Ensure all strings are properly quoted"
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Format TypeBox validation errors into ValidationError format
|
|
308
|
+
*/
|
|
309
|
+
formatTypeBoxErrors(errors, originalJson) {
|
|
310
|
+
return errors.map((error) => {
|
|
311
|
+
const path = error.path || "";
|
|
312
|
+
const lineInfo = this.findLineNumber(path, originalJson);
|
|
313
|
+
return {
|
|
314
|
+
path,
|
|
315
|
+
message: this.formatTypeBoxErrorMessage(error),
|
|
316
|
+
code: this.getErrorCode(error),
|
|
317
|
+
line: lineInfo.line,
|
|
318
|
+
column: lineInfo.column,
|
|
319
|
+
suggestions: this.generateSuggestions(error)
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Format individual TypeBox error message
|
|
325
|
+
*/
|
|
326
|
+
formatTypeBoxErrorMessage(error) {
|
|
327
|
+
const path = error.path ? `at "${error.path}"` : "";
|
|
328
|
+
const message = error.message;
|
|
329
|
+
if (message.includes("Expected")) {
|
|
330
|
+
return `${message} ${path}`;
|
|
331
|
+
} else if (message.includes("Required property")) {
|
|
332
|
+
return `${message} ${path}`;
|
|
333
|
+
} else if (message.includes("Unexpected property")) {
|
|
334
|
+
return `${message} ${path}`;
|
|
335
|
+
} else if (message.includes("minimum")) {
|
|
336
|
+
return `Value is too small ${path}. ${message}`;
|
|
337
|
+
} else if (message.includes("maximum")) {
|
|
338
|
+
return `Value is too big ${path}. ${message}`;
|
|
339
|
+
} else {
|
|
340
|
+
return `${message} ${path}`;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get error code from TypeBox error
|
|
345
|
+
*/
|
|
346
|
+
getErrorCode(error) {
|
|
347
|
+
const baseCode = String(error.type || "VALIDATION_ERROR").toUpperCase();
|
|
348
|
+
const path = error.path ? error.path.replace(/\//g, "_").toUpperCase() : "";
|
|
349
|
+
return path ? `${baseCode}_${path}` : baseCode;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Generate helpful suggestions based on error type
|
|
353
|
+
*/
|
|
354
|
+
generateSuggestions(error) {
|
|
355
|
+
const suggestions = [];
|
|
356
|
+
const message = error.message;
|
|
357
|
+
if (message.includes("Expected string")) {
|
|
358
|
+
suggestions.push("Ensure the value is wrapped in quotes");
|
|
359
|
+
} else if (message.includes("Expected number")) {
|
|
360
|
+
suggestions.push("Remove quotes around numeric values");
|
|
361
|
+
} else if (message.includes("Expected array")) {
|
|
362
|
+
suggestions.push("Use square brackets [] for arrays");
|
|
363
|
+
} else if (message.includes("Expected object")) {
|
|
364
|
+
suggestions.push("Use curly braces {} for objects");
|
|
365
|
+
} else if (message.includes("Expected literal")) {
|
|
366
|
+
const match = message.match(/Expected literal (.+)/);
|
|
367
|
+
if (match) {
|
|
368
|
+
suggestions.push(`Use the exact value: ${match[1]}`);
|
|
369
|
+
}
|
|
370
|
+
} else if (message.includes("Unexpected property")) {
|
|
371
|
+
suggestions.push("Remove unknown properties or check spelling");
|
|
372
|
+
suggestions.push(
|
|
373
|
+
"Refer to the JSON schema documentation for valid properties"
|
|
374
|
+
);
|
|
375
|
+
} else if (message.includes("Expected union")) {
|
|
376
|
+
suggestions.push(
|
|
377
|
+
"Check that the value matches one of the allowed formats"
|
|
378
|
+
);
|
|
379
|
+
suggestions.push("Verify the module type is spelled correctly");
|
|
380
|
+
} else if (message.includes("minimum")) {
|
|
381
|
+
const match = message.match(/minimum.*?(\d+)/);
|
|
382
|
+
if (match) {
|
|
383
|
+
if (message.includes("Array")) {
|
|
384
|
+
suggestions.push(`Array must have at least ${match[1]} items`);
|
|
385
|
+
} else {
|
|
386
|
+
suggestions.push(`Value must be at least ${match[1]}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} else if (message.includes("format") && message.includes("uri")) {
|
|
390
|
+
suggestions.push(
|
|
391
|
+
"Ensure the URL is valid and starts with http:// or https://"
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
if (suggestions.length === 0) {
|
|
395
|
+
suggestions.push("Check the JSON schema documentation for valid values");
|
|
396
|
+
suggestions.push("Verify the property name and value format");
|
|
397
|
+
}
|
|
398
|
+
return suggestions;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Find line and column number for a given JSON path
|
|
402
|
+
*/
|
|
403
|
+
findLineNumber(path, jsonString, lines) {
|
|
404
|
+
if (!path) {
|
|
405
|
+
return {};
|
|
406
|
+
}
|
|
407
|
+
const jsonLines = lines || jsonString.split("\n");
|
|
408
|
+
const pathParts = path.split(".");
|
|
409
|
+
for (let i = 0; i < jsonLines.length; i++) {
|
|
410
|
+
const line = jsonLines[i];
|
|
411
|
+
const lastPathPart = pathParts[pathParts.length - 1];
|
|
412
|
+
if (line.includes(`"${lastPathPart}"`)) {
|
|
413
|
+
const column = line.indexOf(`"${lastPathPart}"`) + 1;
|
|
414
|
+
return {
|
|
415
|
+
line: i + 1,
|
|
416
|
+
column
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var JsonParsingError = class extends Error {
|
|
424
|
+
validationErrors;
|
|
425
|
+
constructor(message, errors) {
|
|
426
|
+
super(message);
|
|
427
|
+
this.name = "JsonParsingError";
|
|
428
|
+
this.validationErrors = errors;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var JsonValidationError = class extends Error {
|
|
432
|
+
validationErrors;
|
|
433
|
+
constructor(message, errors) {
|
|
434
|
+
super(message);
|
|
435
|
+
this.name = "JsonValidationError";
|
|
436
|
+
this.validationErrors = errors;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
function parseJsonComponent(jsonInput) {
|
|
440
|
+
const parser = new JsonDocumentParser();
|
|
441
|
+
return parser.parse(jsonInput);
|
|
442
|
+
}
|
|
443
|
+
function parseJsonWithLineNumbers(jsonString) {
|
|
444
|
+
const parser = new JsonDocumentParser();
|
|
445
|
+
return parser.parseWithLineNumbers(jsonString);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// src/validation/validators/theme.ts
|
|
449
|
+
function formatValidationErrors(errors) {
|
|
450
|
+
if (!Array.isArray(errors)) return [];
|
|
451
|
+
return errors.map((error) => {
|
|
452
|
+
if (typeof error === "string") return error;
|
|
453
|
+
const path = error.path ? `${error.path}: ` : "";
|
|
454
|
+
const message = error.message || "Validation error";
|
|
455
|
+
return `${path}${message}`;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/validation/validators/component.ts
|
|
460
|
+
function safeValidateComponentProps(name, props) {
|
|
461
|
+
const componentName = isStandardComponentName(name) ? name : "custom";
|
|
462
|
+
const result = validateComponent(componentName, props);
|
|
463
|
+
if (result.valid) {
|
|
464
|
+
return { success: true, data: result.data };
|
|
465
|
+
}
|
|
466
|
+
return { success: false, error: result.errors || [] };
|
|
467
|
+
}
|
|
468
|
+
function safeValidateComponentDefinition(component) {
|
|
469
|
+
const result = validateComponentDefinition(component);
|
|
470
|
+
if (result.valid) {
|
|
471
|
+
return { success: true, data: result.data };
|
|
472
|
+
}
|
|
473
|
+
return { success: false, error: result.errors || [] };
|
|
474
|
+
}
|
|
475
|
+
function getValidationErrors(props, name) {
|
|
476
|
+
const componentName = name && isStandardComponentName(name) ? name : "custom";
|
|
477
|
+
const result = validateComponent(componentName, props);
|
|
478
|
+
if (result.valid) return [];
|
|
479
|
+
return (result.errors || []).map(
|
|
480
|
+
(e) => e.path ? `${e.path}: ${e.message}` : e.message
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/validation/core/validator.ts
|
|
485
|
+
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
486
|
+
|
|
487
|
+
// src/validation/core/errors.ts
|
|
488
|
+
function formatSingleIssue(issue) {
|
|
489
|
+
const path = issue.path || "root";
|
|
490
|
+
let message = issue.message;
|
|
491
|
+
let suggestion;
|
|
492
|
+
let expected;
|
|
493
|
+
let received;
|
|
494
|
+
let options;
|
|
495
|
+
if (message.includes("Expected")) {
|
|
496
|
+
const match = message.match(/Expected (.+) but received (.+)/);
|
|
497
|
+
if (match) {
|
|
498
|
+
expected = match[1];
|
|
499
|
+
received = match[2];
|
|
500
|
+
suggestion = getSuggestionForType(expected, received);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (message.includes("Required property")) {
|
|
504
|
+
const match = message.match(/Required property '(.+)'/);
|
|
505
|
+
if (match) {
|
|
506
|
+
message = `Missing required field: ${match[1]}`;
|
|
507
|
+
suggestion = `Add the required field: ${match[1]}`;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (message.includes("Unexpected property")) {
|
|
511
|
+
const match = message.match(/Unexpected property '(.+)'/);
|
|
512
|
+
if (match) {
|
|
513
|
+
message = `Unknown property: ${match[1]}`;
|
|
514
|
+
suggestion = `Remove the unknown property: ${match[1]}`;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (message.includes("Expected union")) {
|
|
518
|
+
message = "Value does not match any of the expected types";
|
|
519
|
+
suggestion = "Check the documentation for valid format options";
|
|
520
|
+
}
|
|
521
|
+
if (message.includes("Expected literal")) {
|
|
522
|
+
const match = message.match(/Expected literal (.+)/);
|
|
523
|
+
if (match) {
|
|
524
|
+
expected = match[1];
|
|
525
|
+
message = `Expected value: ${expected}`;
|
|
526
|
+
suggestion = `Use the exact value: ${expected}`;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (message.includes("String length")) {
|
|
530
|
+
const minMatch = message.match(/minimum length of (\d+)/);
|
|
531
|
+
const maxMatch = message.match(/maximum length of (\d+)/);
|
|
532
|
+
if (minMatch) {
|
|
533
|
+
message = `String must be at least ${minMatch[1]} characters long`;
|
|
534
|
+
suggestion = `Add more characters to meet the minimum length of ${minMatch[1]}`;
|
|
535
|
+
} else if (maxMatch) {
|
|
536
|
+
message = `String must be at most ${maxMatch[1]} characters long`;
|
|
537
|
+
suggestion = `Reduce to ${maxMatch[1]} characters or less`;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (message.includes("Expected number")) {
|
|
541
|
+
const minMatch = message.match(/minimum value of ([\d.]+)/);
|
|
542
|
+
const maxMatch = message.match(/maximum value of ([\d.]+)/);
|
|
543
|
+
if (minMatch) {
|
|
544
|
+
message = `Number must be greater than or equal to ${minMatch[1]}`;
|
|
545
|
+
suggestion = `Use a value of ${minMatch[1]} or higher`;
|
|
546
|
+
} else if (maxMatch) {
|
|
547
|
+
message = `Number must be less than or equal to ${maxMatch[1]}`;
|
|
548
|
+
suggestion = `Use a value of ${maxMatch[1]} or lower`;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (message.includes("Array length")) {
|
|
552
|
+
const minMatch = message.match(/minimum length of (\d+)/);
|
|
553
|
+
const maxMatch = message.match(/maximum length of (\d+)/);
|
|
554
|
+
if (minMatch) {
|
|
555
|
+
message = `Array must have at least ${minMatch[1]} items`;
|
|
556
|
+
suggestion = `Add more items to meet the minimum of ${minMatch[1]}`;
|
|
557
|
+
} else if (maxMatch) {
|
|
558
|
+
message = `Array must have at most ${maxMatch[1]} items`;
|
|
559
|
+
suggestion = `Remove items to meet the maximum of ${maxMatch[1]}`;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (message.includes("format")) {
|
|
563
|
+
if (message.includes("email")) {
|
|
564
|
+
message = "Invalid email address format";
|
|
565
|
+
suggestion = "Use a valid email format like user@example.com";
|
|
566
|
+
} else if (message.includes("uri") || message.includes("url")) {
|
|
567
|
+
message = "Invalid URL format";
|
|
568
|
+
suggestion = "Use a valid URL format like https://example.com";
|
|
569
|
+
} else if (message.includes("date-time")) {
|
|
570
|
+
message = "Invalid date-time format";
|
|
571
|
+
suggestion = "Use ISO 8601 format like 2024-01-01T00:00:00Z";
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (message.includes("pattern")) {
|
|
575
|
+
message = "String does not match the required pattern";
|
|
576
|
+
suggestion = "Check the format requirements for this field";
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
path,
|
|
580
|
+
message,
|
|
581
|
+
code: String(issue.type || "validation_error"),
|
|
582
|
+
suggestion,
|
|
583
|
+
expected,
|
|
584
|
+
received,
|
|
585
|
+
options
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function getSuggestionForType(expected, received) {
|
|
589
|
+
if (expected === "number" && received === "string") {
|
|
590
|
+
return "Remove quotes or convert the string to a number";
|
|
591
|
+
}
|
|
592
|
+
if (expected === "string" && received === "number") {
|
|
593
|
+
return "Add quotes or convert the number to a string";
|
|
594
|
+
}
|
|
595
|
+
if (expected === "boolean") {
|
|
596
|
+
return "Use true or false (without quotes)";
|
|
597
|
+
}
|
|
598
|
+
if (expected === "array" && received === "object") {
|
|
599
|
+
return "Use square brackets [] for arrays instead of curly braces {}";
|
|
600
|
+
}
|
|
601
|
+
if (expected === "object" && received === "array") {
|
|
602
|
+
return "Use curly braces {} for objects instead of square brackets []";
|
|
603
|
+
}
|
|
604
|
+
if (received === "null" || received === "undefined") {
|
|
605
|
+
return `Provide a valid ${expected} value or mark the field as optional`;
|
|
606
|
+
}
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
function formatTypeBoxError(errors) {
|
|
610
|
+
return errors.map(formatSingleIssue);
|
|
611
|
+
}
|
|
612
|
+
function formatTypeBoxErrorStrings(errors) {
|
|
613
|
+
return formatTypeBoxError(errors).map((err) => {
|
|
614
|
+
let msg = `${err.path}: ${err.message}`;
|
|
615
|
+
if (err.suggestion) {
|
|
616
|
+
msg += ` (Suggestion: ${err.suggestion})`;
|
|
617
|
+
}
|
|
618
|
+
return msg;
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
function getErrorSummary(errors) {
|
|
622
|
+
const summary = /* @__PURE__ */ new Map();
|
|
623
|
+
for (const formattedError of formatTypeBoxError(errors)) {
|
|
624
|
+
const existing = summary.get(formattedError.path) || [];
|
|
625
|
+
existing.push(formattedError);
|
|
626
|
+
summary.set(formattedError.path, existing);
|
|
627
|
+
}
|
|
628
|
+
return summary;
|
|
629
|
+
}
|
|
630
|
+
function formatErrorReport(errors) {
|
|
631
|
+
const formattedErrors = formatTypeBoxError(errors);
|
|
632
|
+
const summary = getErrorSummary(errors);
|
|
633
|
+
let report = `Validation failed with ${formattedErrors.length} error${formattedErrors.length > 1 ? "s" : ""}:
|
|
634
|
+
|
|
635
|
+
`;
|
|
636
|
+
for (const [path, pathErrors] of summary) {
|
|
637
|
+
report += `\u{1F4CD} ${path}:
|
|
638
|
+
`;
|
|
639
|
+
for (const err of pathErrors) {
|
|
640
|
+
report += ` \u274C ${err.message}
|
|
641
|
+
`;
|
|
642
|
+
if (err.suggestion) {
|
|
643
|
+
report += ` \u{1F4A1} ${err.suggestion}
|
|
644
|
+
`;
|
|
645
|
+
}
|
|
646
|
+
if (err.expected && err.received) {
|
|
647
|
+
report += ` \u{1F4CB} Expected: ${err.expected}, Received: ${err.received}
|
|
648
|
+
`;
|
|
649
|
+
}
|
|
650
|
+
if (err.options) {
|
|
651
|
+
report += ` \u{1F4CB} Valid options: ${err.options.join(", ")}
|
|
652
|
+
`;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
report += "\n";
|
|
656
|
+
}
|
|
657
|
+
return report;
|
|
658
|
+
}
|
|
659
|
+
function hasCriticalErrors(errors) {
|
|
660
|
+
return errors.some((issue) => {
|
|
661
|
+
if (issue.message.includes("Required property")) {
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
if (issue.path.includes("name") && issue.message.includes("Expected literal")) {
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
if (issue.message.includes("Expected union") || issue.message.includes("Never")) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
return false;
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
function getValidationContext(path) {
|
|
674
|
+
if (!path || path === "root") return "document root";
|
|
675
|
+
const pathParts = path.split(".");
|
|
676
|
+
if (pathParts.includes("children")) {
|
|
677
|
+
const childIndex = pathParts.indexOf("children");
|
|
678
|
+
if (pathParts.length > childIndex + 1) {
|
|
679
|
+
const index = pathParts[childIndex + 1];
|
|
680
|
+
return `component at index ${index}`;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (pathParts.includes("props")) {
|
|
684
|
+
return "props section";
|
|
685
|
+
}
|
|
686
|
+
if (pathParts.includes("theme")) {
|
|
687
|
+
return "theme configuration";
|
|
688
|
+
}
|
|
689
|
+
return pathParts.join(" > ");
|
|
690
|
+
}
|
|
691
|
+
var formatValidationError = formatTypeBoxError;
|
|
692
|
+
var formatValidationErrorStrings = formatTypeBoxErrorStrings;
|
|
693
|
+
|
|
694
|
+
// src/validation/core/validator.ts
|
|
695
|
+
var COMPONENT_SCHEMA_MAP = {
|
|
696
|
+
report: ReportPropsSchema,
|
|
697
|
+
section: SectionPropsSchema,
|
|
698
|
+
heading: HeadingPropsSchema,
|
|
699
|
+
paragraph: ParagraphPropsSchema,
|
|
700
|
+
columns: ColumnsPropsSchema,
|
|
701
|
+
image: ImagePropsSchema,
|
|
702
|
+
statistic: StatisticPropsSchema,
|
|
703
|
+
table: TablePropsSchema,
|
|
704
|
+
header: HeaderPropsSchema,
|
|
705
|
+
footer: FooterPropsSchema,
|
|
706
|
+
list: ListPropsSchema
|
|
707
|
+
};
|
|
708
|
+
function validateComponent2(name, props, options) {
|
|
709
|
+
const schema = COMPONENT_SCHEMA_MAP[name];
|
|
710
|
+
if (!schema) {
|
|
711
|
+
if (Value2.Check(CustomComponentDefinitionSchema, props)) {
|
|
712
|
+
return {
|
|
713
|
+
success: true,
|
|
714
|
+
data: props
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
const errors2 = [...Value2.Errors(CustomComponentDefinitionSchema, props)];
|
|
718
|
+
const formattedErrors2 = formatTypeBoxError(errors2);
|
|
719
|
+
return {
|
|
720
|
+
success: false,
|
|
721
|
+
errors: formattedErrors2,
|
|
722
|
+
errorStrings: formatTypeBoxErrorStrings(errors2),
|
|
723
|
+
report: options?.includeReport ? formatErrorReport(errors2) : void 0,
|
|
724
|
+
hasCriticalErrors: options?.checkCritical ? hasCriticalErrors(errors2) : void 0
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
if (Value2.Check(schema, props)) {
|
|
728
|
+
return {
|
|
729
|
+
success: true,
|
|
730
|
+
data: props
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
const errors = [...Value2.Errors(schema, props)];
|
|
734
|
+
const formattedErrors = formatTypeBoxError(errors);
|
|
735
|
+
return {
|
|
736
|
+
success: false,
|
|
737
|
+
errors: formattedErrors,
|
|
738
|
+
errorStrings: formatTypeBoxErrorStrings(errors),
|
|
739
|
+
report: options?.includeReport ? formatErrorReport(errors) : void 0,
|
|
740
|
+
hasCriticalErrors: options?.checkCritical ? hasCriticalErrors(errors) : void 0
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function validateComponentDefinition2(component, options) {
|
|
744
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
745
|
+
const currentDepth = options?.currentDepth ?? 0;
|
|
746
|
+
if (currentDepth > maxDepth) {
|
|
747
|
+
return {
|
|
748
|
+
success: false,
|
|
749
|
+
errors: [
|
|
750
|
+
{
|
|
751
|
+
path: "children",
|
|
752
|
+
message: `Maximum nesting depth (${maxDepth}) exceeded`,
|
|
753
|
+
code: "custom",
|
|
754
|
+
suggestion: "Reduce the nesting level of components"
|
|
755
|
+
}
|
|
756
|
+
],
|
|
757
|
+
errorStrings: [`Maximum nesting depth (${maxDepth}) exceeded`],
|
|
758
|
+
hasCriticalErrors: true
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
if (Value2.Check(ComponentDefinitionSchema, component)) {
|
|
762
|
+
const data = component;
|
|
763
|
+
const warnings = [];
|
|
764
|
+
if (data.children && Array.isArray(data.children)) {
|
|
765
|
+
for (let i = 0; i < data.children.length; i++) {
|
|
766
|
+
const nestedResult = validateComponentDefinition2(data.children[i], {
|
|
767
|
+
...options,
|
|
768
|
+
currentDepth: currentDepth + 1
|
|
769
|
+
});
|
|
770
|
+
if (!nestedResult.success) {
|
|
771
|
+
const nestedErrors = nestedResult.errors?.map((err) => ({
|
|
772
|
+
...err,
|
|
773
|
+
path: `children[${i}].${err.path}`
|
|
774
|
+
}));
|
|
775
|
+
return {
|
|
776
|
+
success: false,
|
|
777
|
+
errors: nestedErrors,
|
|
778
|
+
errorStrings: nestedErrors?.map(
|
|
779
|
+
(err) => `${err.path}: ${err.message}`
|
|
780
|
+
),
|
|
781
|
+
report: options?.includeReport ? `Validation failed in nested component at index ${i}:
|
|
782
|
+
${nestedResult.report}` : void 0,
|
|
783
|
+
hasCriticalErrors: nestedResult.hasCriticalErrors
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
if (nestedResult.warnings) {
|
|
787
|
+
warnings.push(
|
|
788
|
+
...nestedResult.warnings.map((w) => `children[${i}]: ${w}`)
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return {
|
|
794
|
+
success: true,
|
|
795
|
+
data: component,
|
|
796
|
+
warnings: warnings.length > 0 ? warnings : void 0
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
const errors = [...Value2.Errors(ComponentDefinitionSchema, component)];
|
|
800
|
+
const formattedErrors = formatTypeBoxError(errors);
|
|
801
|
+
return {
|
|
802
|
+
success: false,
|
|
803
|
+
errors: formattedErrors,
|
|
804
|
+
errorStrings: formatTypeBoxErrorStrings(errors),
|
|
805
|
+
report: options?.includeReport ? formatErrorReport(errors) : void 0,
|
|
806
|
+
hasCriticalErrors: options?.checkCritical ? hasCriticalErrors(errors) : void 0
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function validateComponents2(components, options) {
|
|
810
|
+
const results = [];
|
|
811
|
+
let criticalCount = 0;
|
|
812
|
+
for (const { name, props } of components) {
|
|
813
|
+
const result = name in COMPONENT_SCHEMA_MAP ? validateComponent2(name, props, options) : validateComponentDefinition2(props, options);
|
|
814
|
+
results.push(result);
|
|
815
|
+
if (result.hasCriticalErrors) {
|
|
816
|
+
criticalCount++;
|
|
817
|
+
}
|
|
818
|
+
if (!result.success && options?.stopOnFirst) {
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
const valid = results.filter((r) => r.success).length;
|
|
823
|
+
const invalid = results.length - valid;
|
|
824
|
+
return {
|
|
825
|
+
success: invalid === 0,
|
|
826
|
+
results,
|
|
827
|
+
summary: {
|
|
828
|
+
total: results.length,
|
|
829
|
+
valid,
|
|
830
|
+
invalid,
|
|
831
|
+
criticalErrors: criticalCount
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function transformAndValidate(name, data, transformer) {
|
|
836
|
+
try {
|
|
837
|
+
const transformed = transformer ? transformer(data) : data;
|
|
838
|
+
return validateComponent2(name, transformed, {
|
|
839
|
+
includeReport: true,
|
|
840
|
+
checkCritical: true
|
|
841
|
+
});
|
|
842
|
+
} catch (error) {
|
|
843
|
+
return {
|
|
844
|
+
success: false,
|
|
845
|
+
errors: [
|
|
846
|
+
{
|
|
847
|
+
path: "root",
|
|
848
|
+
message: `Transformation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
849
|
+
code: "custom"
|
|
850
|
+
}
|
|
851
|
+
],
|
|
852
|
+
errorStrings: [
|
|
853
|
+
`Transformation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
854
|
+
],
|
|
855
|
+
hasCriticalErrors: true
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function createValidatedComponent(name, partialConfig) {
|
|
860
|
+
const schema = COMPONENT_SCHEMA_MAP[name];
|
|
861
|
+
if (!schema) {
|
|
862
|
+
return {
|
|
863
|
+
success: false,
|
|
864
|
+
errors: [
|
|
865
|
+
{
|
|
866
|
+
path: "name",
|
|
867
|
+
message: `Unknown component name: ${name}`,
|
|
868
|
+
code: "custom",
|
|
869
|
+
suggestion: `Use one of: ${Object.keys(COMPONENT_SCHEMA_MAP).join(", ")}`
|
|
870
|
+
}
|
|
871
|
+
],
|
|
872
|
+
errorStrings: [`Unknown component name: ${name}`],
|
|
873
|
+
hasCriticalErrors: true
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
if (Value2.Check(schema, partialConfig)) {
|
|
877
|
+
return {
|
|
878
|
+
success: true,
|
|
879
|
+
data: partialConfig
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
const errors = [...Value2.Errors(schema, partialConfig)];
|
|
883
|
+
const formattedErrors = formatTypeBoxError(errors);
|
|
884
|
+
return {
|
|
885
|
+
success: false,
|
|
886
|
+
errors: formattedErrors,
|
|
887
|
+
errorStrings: formatTypeBoxErrorStrings(errors),
|
|
888
|
+
report: formatErrorReport(errors),
|
|
889
|
+
hasCriticalErrors: hasCriticalErrors(errors)
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function isValidComponent(name, props) {
|
|
893
|
+
const result = validateComponent2(name, props);
|
|
894
|
+
return result.success;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/types/components.ts
|
|
898
|
+
var STANDARD_COMPONENTS = [
|
|
899
|
+
"columns",
|
|
900
|
+
"footer",
|
|
901
|
+
"header",
|
|
902
|
+
"heading",
|
|
903
|
+
"highcharts",
|
|
904
|
+
"image",
|
|
905
|
+
"list",
|
|
906
|
+
"paragraph",
|
|
907
|
+
"docx",
|
|
908
|
+
"section",
|
|
909
|
+
"statistic",
|
|
910
|
+
"table",
|
|
911
|
+
"text-box",
|
|
912
|
+
"toc"
|
|
913
|
+
];
|
|
914
|
+
var STANDARD_COMPONENTS_SET = new Set(STANDARD_COMPONENTS);
|
|
915
|
+
function isReportComponent(component) {
|
|
916
|
+
return component.name === "docx";
|
|
917
|
+
}
|
|
918
|
+
function isSectionComponent(component) {
|
|
919
|
+
return component.name === "section";
|
|
920
|
+
}
|
|
921
|
+
function isColumnsComponent(component) {
|
|
922
|
+
return component.name === "columns";
|
|
923
|
+
}
|
|
924
|
+
function isHeadingComponent(component) {
|
|
925
|
+
return component.name === "heading";
|
|
926
|
+
}
|
|
927
|
+
function isParagraphComponent(component) {
|
|
928
|
+
return component.name === "paragraph";
|
|
929
|
+
}
|
|
930
|
+
function isImageComponent(component) {
|
|
931
|
+
return component.name === "image";
|
|
932
|
+
}
|
|
933
|
+
function isTextBoxComponent(component) {
|
|
934
|
+
return component.name === "text-box";
|
|
935
|
+
}
|
|
936
|
+
function isStatisticComponent(component) {
|
|
937
|
+
return component.name === "statistic";
|
|
938
|
+
}
|
|
939
|
+
function isTableComponent(component) {
|
|
940
|
+
return component.name === "table";
|
|
941
|
+
}
|
|
942
|
+
function isHeaderComponent(component) {
|
|
943
|
+
return component.name === "header";
|
|
944
|
+
}
|
|
945
|
+
function isFooterComponent(component) {
|
|
946
|
+
return component.name === "footer";
|
|
947
|
+
}
|
|
948
|
+
function isListComponent(component) {
|
|
949
|
+
return component.name === "list";
|
|
950
|
+
}
|
|
951
|
+
function isTocComponent(component) {
|
|
952
|
+
return component.name === "toc";
|
|
953
|
+
}
|
|
954
|
+
function isHighchartsComponent(component) {
|
|
955
|
+
return component.name === "highcharts";
|
|
956
|
+
}
|
|
957
|
+
function isTextSpaceAfterComponent(component) {
|
|
958
|
+
return component.name === "text-space-after";
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/index.ts
|
|
962
|
+
var SHARED_DOCX_VERSION = "1.0.0";
|
|
963
|
+
export {
|
|
964
|
+
AlignmentSchema,
|
|
965
|
+
BASE_SCHEMA_METADATA,
|
|
966
|
+
BaseComponentPropsSchema,
|
|
967
|
+
BorderSchema,
|
|
968
|
+
COMPONENT_METADATA,
|
|
969
|
+
ColumnsPropsSchema,
|
|
970
|
+
ComponentDefinitionSchema,
|
|
971
|
+
CustomComponentDefinitionSchema,
|
|
972
|
+
DEFAULT_ERROR_CONFIG,
|
|
973
|
+
DOC_LINKS,
|
|
974
|
+
ERROR_EMOJIS,
|
|
975
|
+
ERROR_TEMPLATES,
|
|
976
|
+
FooterPropsSchema,
|
|
977
|
+
GenerateDocumentRequestSchema,
|
|
978
|
+
GenerateDocumentResponseSchema,
|
|
979
|
+
HeaderPropsSchema,
|
|
980
|
+
HeadingLevelSchema,
|
|
981
|
+
HeadingPropsSchema,
|
|
982
|
+
HighchartsPropsSchema,
|
|
983
|
+
ImagePropsSchema,
|
|
984
|
+
IndentSchema,
|
|
985
|
+
JSON_SCHEMA_URLS,
|
|
986
|
+
JsonComponentDefinitionSchema,
|
|
987
|
+
JsonDocumentParser,
|
|
988
|
+
JsonParsingError,
|
|
989
|
+
JsonValidationError,
|
|
990
|
+
JustifiedAlignmentSchema,
|
|
991
|
+
LineSpacingSchema,
|
|
992
|
+
ListPropsSchema,
|
|
993
|
+
MarginsSchema,
|
|
994
|
+
NumberingSchema,
|
|
995
|
+
ParagraphPropsSchema,
|
|
996
|
+
ReportPropsSchema,
|
|
997
|
+
SHARED_DOCX_VERSION,
|
|
998
|
+
STANDARD_COMPONENTS,
|
|
999
|
+
STANDARD_COMPONENTS_SET,
|
|
1000
|
+
SectionPropsSchema,
|
|
1001
|
+
SpacingSchema,
|
|
1002
|
+
StandardComponentDefinitionSchema,
|
|
1003
|
+
StatisticPropsSchema,
|
|
1004
|
+
THEME_SCHEMA_METADATA,
|
|
1005
|
+
TablePropsSchema,
|
|
1006
|
+
TextBoxPropsSchema,
|
|
1007
|
+
TextSpaceAfterComponentSchema,
|
|
1008
|
+
TextSpaceAfterPropsSchema,
|
|
1009
|
+
ThemeConfigSchema,
|
|
1010
|
+
TocPropsSchema,
|
|
1011
|
+
ValidateDocumentRequestSchema,
|
|
1012
|
+
ValidateDocumentResponseSchema,
|
|
1013
|
+
calculatePosition,
|
|
1014
|
+
clearComponentNamesCache,
|
|
1015
|
+
compareSemver,
|
|
1016
|
+
componentValidator,
|
|
1017
|
+
comprehensiveValidateDocument,
|
|
1018
|
+
convertToJsonSchema as convertDocxToJsonSchema,
|
|
1019
|
+
convertToJsonSchema2 as convertToJsonSchema,
|
|
1020
|
+
createComponentSchema2 as createComponentSchema,
|
|
1021
|
+
createComponentValidator,
|
|
1022
|
+
createDocumentValidator,
|
|
1023
|
+
createComponentSchema as createDocxComponentSchema,
|
|
1024
|
+
createErrorConfig,
|
|
1025
|
+
createJsonParseError,
|
|
1026
|
+
createJsonValidator,
|
|
1027
|
+
createThemeValidator,
|
|
1028
|
+
createValidatedComponent,
|
|
1029
|
+
createValidator,
|
|
1030
|
+
deepValidateDocument,
|
|
1031
|
+
documentValidator,
|
|
1032
|
+
exportSchemaToFile as exportDocxSchemaToFile,
|
|
1033
|
+
exportSchemaToFile2 as exportSchemaToFile,
|
|
1034
|
+
extractStandardComponentNames,
|
|
1035
|
+
fixSchemaReferences as fixDocxSchemaReferences,
|
|
1036
|
+
fixSchemaReferences2 as fixSchemaReferences,
|
|
1037
|
+
formatErrorMessage,
|
|
1038
|
+
formatErrorReport,
|
|
1039
|
+
formatErrorSummary,
|
|
1040
|
+
formatValidationError,
|
|
1041
|
+
formatValidationErrorStrings,
|
|
1042
|
+
formatValidationErrors,
|
|
1043
|
+
generateUnifiedDocumentSchema,
|
|
1044
|
+
getErrorSummary,
|
|
1045
|
+
getLiteralValue,
|
|
1046
|
+
getObjectSchemaPropertyNames,
|
|
1047
|
+
getSchemaMetadata,
|
|
1048
|
+
getThemeName,
|
|
1049
|
+
getValidationContext,
|
|
1050
|
+
getValidationErrors,
|
|
1051
|
+
getValidationSummary,
|
|
1052
|
+
groupErrorsByPath,
|
|
1053
|
+
hasCriticalErrors,
|
|
1054
|
+
isColumnsComponent,
|
|
1055
|
+
isColumnsProps,
|
|
1056
|
+
isCustomComponentProps,
|
|
1057
|
+
isFooterComponent,
|
|
1058
|
+
isFooterProps,
|
|
1059
|
+
isHeaderComponent,
|
|
1060
|
+
isHeaderProps,
|
|
1061
|
+
isHeadingComponent,
|
|
1062
|
+
isHeadingProps,
|
|
1063
|
+
isHighchartsComponent,
|
|
1064
|
+
isImageComponent,
|
|
1065
|
+
isImageProps,
|
|
1066
|
+
isListComponent,
|
|
1067
|
+
isListProps,
|
|
1068
|
+
isLiteralSchema,
|
|
1069
|
+
isObjectSchema,
|
|
1070
|
+
isParagraphComponent,
|
|
1071
|
+
isParagraphProps,
|
|
1072
|
+
isReportComponent,
|
|
1073
|
+
isReportProps,
|
|
1074
|
+
isSectionComponent,
|
|
1075
|
+
isSectionProps,
|
|
1076
|
+
isStandardComponentName,
|
|
1077
|
+
isStatisticComponent,
|
|
1078
|
+
isStatisticProps,
|
|
1079
|
+
isTableComponent,
|
|
1080
|
+
isTableProps,
|
|
1081
|
+
isTextBoxComponent,
|
|
1082
|
+
isTextSpaceAfterComponent,
|
|
1083
|
+
isThemeConfig,
|
|
1084
|
+
isTocComponent,
|
|
1085
|
+
isUnionSchema,
|
|
1086
|
+
isValidComponent,
|
|
1087
|
+
isValidDocument,
|
|
1088
|
+
isValidSemver,
|
|
1089
|
+
isValidTheme,
|
|
1090
|
+
isValidThemeConfig,
|
|
1091
|
+
isValidTheme as isValidThemeJson,
|
|
1092
|
+
isValidationSuccess,
|
|
1093
|
+
latestVersion,
|
|
1094
|
+
parseJsonComponent,
|
|
1095
|
+
parseJsonWithLineNumbers,
|
|
1096
|
+
parseSemver,
|
|
1097
|
+
safeValidateComponentDefinition,
|
|
1098
|
+
safeValidateComponentProps,
|
|
1099
|
+
createComponentSchemaObject as sharedCreateComponentSchemaObject,
|
|
1100
|
+
strictComponentValidator,
|
|
1101
|
+
strictDocumentValidator,
|
|
1102
|
+
strictThemeValidator,
|
|
1103
|
+
themeValidator,
|
|
1104
|
+
transformAndValidate,
|
|
1105
|
+
transformValueError as transformDocxValueError,
|
|
1106
|
+
transformValueErrors as transformDocxValueErrors,
|
|
1107
|
+
transformValueError2 as transformValueError,
|
|
1108
|
+
transformValueErrors2 as transformValueErrors,
|
|
1109
|
+
validate,
|
|
1110
|
+
validateAgainstSchema,
|
|
1111
|
+
validateBatch,
|
|
1112
|
+
validateComponent2 as validateComponent,
|
|
1113
|
+
validateComponentDefinition2 as validateComponentDefinition,
|
|
1114
|
+
validateComponent as validateComponentProps,
|
|
1115
|
+
validateComponents2 as validateComponents,
|
|
1116
|
+
validateCustomComponentProps,
|
|
1117
|
+
validateDocument,
|
|
1118
|
+
validateDocumentWithSchema,
|
|
1119
|
+
validateJson,
|
|
1120
|
+
validateJsonDocument as validateJsonComponent,
|
|
1121
|
+
validateJsonComponent as validateJsonComponentDoc,
|
|
1122
|
+
validateJsonDocument,
|
|
1123
|
+
validateStrict,
|
|
1124
|
+
validateTheme,
|
|
1125
|
+
validateThemeJson,
|
|
1126
|
+
validateThemeWithEnhancement,
|
|
1127
|
+
validateWithEnhancement
|
|
1128
|
+
};
|
|
1129
|
+
//# sourceMappingURL=index.js.map
|