MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / validateComponentConfig

Function validateComponentConfig

static/components.ts:1159–1186  ·  view source on GitHub ↗

* Validates a component configuration

(config: any, location: string)

Source from the content-addressed store, hash-verified

1157 * Validates a component configuration
1158 */
1159function validateComponentConfig(config: any, location: string): AnyComponentConfig {
1160 if (!config.componentName) {
1161 throw new Error(`Invalid ${location}: missing 'componentName' property`);
1162 }
1163
1164 if (typeof config.componentName !== 'string') {
1165 throw new Error(`Invalid ${location}: 'componentName' must be a string`);
1166 }
1167
1168 // Validate that the component state matches the expected type for this component
1169 if (!validateComponentState(config.componentName, config.componentState)) {
1170 throw new Error(
1171 `Invalid ${location}: invalid component state for component '${config.componentName}'. ` +
1172 `State: ${JSON.stringify(config.componentState, null, 2)}`,
1173 );
1174 }
1175
1176 return {
1177 type: 'component',
1178 componentName: config.componentName,
1179 componentState: config.componentState,
1180 title: config.title,
1181 isClosable: config.isClosable,
1182 reorderEnabled: config.reorderEnabled,
1183 width: config.width,
1184 height: config.height,
1185 };
1186}
1187
1188/**
1189 * Validates a layout item (row, column, stack)

Callers 1

validateItemConfigFunction · 0.85

Calls 1

validateComponentStateFunction · 0.85

Tested by

no test coverage detected