UNPKG

@agility/cli

Version:

Agility CLI for working with your content. (Public Beta)

156 lines 6.35 kB
"use strict"; /** * Link Type Detection Service * * Detects Agility CMS link types from model field configurations to enable * proper handling of different content linking patterns and eliminate false * broken chain reports from field configuration misinterpretation. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.LinkTypeDetector = void 0; var LinkTypeDetector = /** @class */ (function () { function LinkTypeDetector() { } /** * Detect link type from a Content field's settings */ LinkTypeDetector.prototype.detectLinkType = function (field) { if (field.type !== 'Content') { return { type: 'unknown', strategy: 'not-content-field', requiresMapping: false, followDependencies: false }; } var settings = field.settings; var renderAs = settings.RenderAs || ''; var nestedTypeID = settings.LinkedContentNestedTypeID || ''; var sharedContent = settings.SharedContent || ''; var contentView = settings.ContentView || ''; // 1. DROPDOWN LINKS (Shared Content) if (renderAs === 'dropdown' && sharedContent !== '_newcontent_agility_') { return { type: 'dropdown', strategy: 'Use ID mapping only, don\'t follow dependencies', requiresMapping: true, followDependencies: false }; } // 2. SEARCHLISTBOX LINKS (Filtered Selection) if (renderAs === 'searchlistbox') { return { type: 'searchlistbox', strategy: 'Reference via contentID in separate field with remapping', requiresMapping: true, followDependencies: true }; } // 3. GRID LINKS (Multi-item Lists) if (renderAs === 'grid' && nestedTypeID === '1') { return { type: 'grid', strategy: 'Link to shared list with mapping + optional sorting', requiresMapping: true, followDependencies: true }; } // 4. NESTED LINKS (Single Item Containers) if (renderAs === '' && nestedTypeID === '0') { return { type: 'nested', strategy: 'Create container if missing, link locally', requiresMapping: true, followDependencies: true }; } // 5. SHARED CONTENT (Specific View Names) if (contentView !== '_newcontent_agility_' && sharedContent !== '_newcontent_agility_') { return { type: 'shared', strategy: 'Treat as shared, use content view metadata for context', requiresMapping: true, followDependencies: false }; } return { type: 'unknown', strategy: 'unhandled-pattern', requiresMapping: false, followDependencies: false }; }; /** * Analyze all Content fields in a model and extract real references vs field settings */ LinkTypeDetector.prototype.analyzeModelContentFields = function (model) { var _this = this; if (!model.fields) return []; return model.fields .filter(function (field) { return field.type === 'Content'; }) .map(function (field) { var linkType = _this.detectLinkType(field); var settings = field.settings; // Identify field configuration strings (NOT content references) var fieldConfigurationStrings = []; if (settings.LinkeContentDropdownValueField) { fieldConfigurationStrings.push(settings.LinkeContentDropdownValueField); } if (settings.LinkeContentDropdownTextField) { fieldConfigurationStrings.push(settings.LinkeContentDropdownTextField); } // Extract actual content references (depend on link type) var actualContentReferences = []; if (settings.ContentDefinition) { actualContentReferences.push(settings.ContentDefinition); } return { fieldName: field.name, linkType: linkType, contentDefinition: settings.ContentDefinition || '', actualContentReferences: actualContentReferences, fieldConfigurationStrings: fieldConfigurationStrings }; }); }; /** * Check if a reference string is a field configuration (should be ignored) */ LinkTypeDetector.prototype.isFieldConfigurationString = function (referenceString, model) { var analysis = this.analyzeModelContentFields(model); return analysis.some(function (fieldAnalysis) { return fieldAnalysis.fieldConfigurationStrings.includes(referenceString); }); }; /** * Extract only real content references from a model (filter out field settings) */ LinkTypeDetector.prototype.extractRealContentReferences = function (model) { var analysis = this.analyzeModelContentFields(model); return analysis .filter(function (fieldAnalysis) { return fieldAnalysis.actualContentReferences.length > 0; }) .map(function (fieldAnalysis) { return ({ fieldName: fieldAnalysis.fieldName, contentDefinition: fieldAnalysis.contentDefinition, linkType: fieldAnalysis.linkType }); }); }; /** * Get human-readable description of link type */ LinkTypeDetector.prototype.getLinkTypeDescription = function (linkType) { var typeDescriptions = { dropdown: '🔽 Dropdown (Shared Content)', searchlistbox: '🔍 SearchListBox (Filtered Selection)', grid: '📋 Grid (Multi-item List)', nested: '📦 Nested (Single Container)', shared: '🔗 Shared (Content View)', unknown: '❓ Unknown Pattern' }; return typeDescriptions[linkType.type] || '❓ Unknown'; }; return LinkTypeDetector; }()); exports.LinkTypeDetector = LinkTypeDetector; //# sourceMappingURL=link-type-detector.js.map