interface RequiredStringOptions { allowEmpty?: boolean; } function labelComponent(componentType: string, component: Record): string { const id = component['api_name'] ?? component['layout_id'] ?? component['view_id'] ?? component['rule_id'] ?? component['flow_id'] ?? component['sdui_page_id'] ?? component['field_api_name'] ?? component['section_id'] ?? 'unknown'; return `${componentType}:${String(id)}`; } function requiredFieldError(componentType: string, component: Record, key: string): Error { return new Error( `${labelComponent(componentType, component)} is missing required field "${key}". ` + 'Pass the full existing component extraction to ManifestBuilder.loadFromExistingJson(...).', ); } export function requireStringComponentField( component: Record, key: string, componentType: string, options: RequiredStringOptions = {}, ): string { const value = component[key]; if (typeof value !== 'string' || (!options.allowEmpty && value.length === 0)) { throw requiredFieldError(componentType, component, key); } return value; } export function optionalStringComponentField( component: Record, key: string, defaultValue = '', ): string { const value = component[key]; return typeof value === 'string' ? value : defaultValue; } export function requireBooleanComponentField( component: Record, key: string, componentType: string, ): boolean { const value = component[key]; if (typeof value !== 'boolean') { throw requiredFieldError(componentType, component, key); } return value; } export function requireArrayComponentField( component: Record, key: string, componentType: string, ): T[] { const value = component[key]; if (!Array.isArray(value)) { throw requiredFieldError(componentType, component, key); } return value as T[]; } export function requireObjectComponentField( component: Record, key: string, componentType: string, ): Record { const value = component[key]; if (value == null || typeof value !== 'object' || Array.isArray(value)) { throw requiredFieldError(componentType, component, key); } return value as Record; }