191 lines
24 KiB
TypeScript
191 lines
24 KiB
TypeScript
export type SystemCategory = 'application' | 'service' | 'data' | 'human' | 'external'
|
|
|
|
export interface PortModel { id: string; name: string; description: string }
|
|
export interface ActionModel { id: string; name: string; description: string; payload: string }
|
|
export interface HumanActionModel extends ActionModel { connectionId: string }
|
|
export interface HumanDecisionModel { roleSystemId: string; task: string; receivedData: string; editableFields: Record<string, string>; actions: HumanActionModel[] }
|
|
export interface CapabilityModel { id: string; name: string; description: string; inputs: PortModel[]; outputs: PortModel[]; actions: ActionModel[]; payload: string }
|
|
export interface SystemPreset { id: string; name: string; description: string; category: SystemCategory; color: string; capabilities: CapabilityModel[] }
|
|
|
|
export interface SystemModel {
|
|
id: string
|
|
name: string
|
|
description: string
|
|
category: SystemCategory
|
|
color: string
|
|
position: [number, number]
|
|
presetId?: string
|
|
capabilities: CapabilityModel[]
|
|
}
|
|
|
|
export interface ConnectionModel {
|
|
id: string
|
|
sourceId: string
|
|
targetId: string
|
|
label: string
|
|
description: string
|
|
payload: string
|
|
transformation?: { incoming: string; outgoing: string; note: string }
|
|
protocol?: string
|
|
dataType?: string
|
|
deliveryMethod?: 'immediate' | 'scheduled' | 'manual'
|
|
showCableLabel?: boolean
|
|
}
|
|
|
|
export interface ScenarioStep {
|
|
id: string
|
|
connectionIds: string[]
|
|
explanation: string
|
|
payload: string
|
|
delayMs: number
|
|
outcome?: 'success' | 'rejected' | 'timeout'
|
|
retryStepId?: string
|
|
recoveryStepId?: string
|
|
humanDecision?: HumanDecisionModel
|
|
}
|
|
|
|
export interface ScenarioModel {
|
|
id: string
|
|
name: string
|
|
description: string
|
|
startSystemId: string
|
|
startActionId?: string
|
|
steps: ScenarioStep[]
|
|
}
|
|
|
|
export interface LandscapeModel {
|
|
version: 1
|
|
systems: SystemModel[]
|
|
connections: ConnectionModel[]
|
|
scenarios: ScenarioModel[]
|
|
}
|
|
|
|
export const uid = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 9)}`
|
|
|
|
const port = (id: string, name: string, description: string): PortModel => ({ id, name, description })
|
|
const action = (id: string, name: string, description: string, payload: string): ActionModel => ({ id, name, description, payload })
|
|
const capability = (id: string, name: string, description: string, inputs: PortModel[], outputs: PortModel[], actions: ActionModel[], payload: string): CapabilityModel => ({ id, name, description, inputs, outputs, actions, payload })
|
|
|
|
export const SYSTEM_PRESETS: SystemPreset[] = [
|
|
{ id: 'website', name: 'Website', description: 'Customer-facing storefront and account experience.', category: 'application', color: '#6d7cff', capabilities: [
|
|
capability('contact-forms', 'Contact forms', 'Collect a visitor message and route it to a service team.', [port('form-submit', 'Form submit', 'A visitor-submitted contact form.')], [port('contact-request', 'Contact request', 'Validated contact details and message.')], [action('submit-contact', 'Submit contact form', 'Create a fictional support request.', '{"requestId":"req_1001","email":"sam@example.test","message":"Please call me"}')], '{"requestId":"req_1001","email":"sam@example.test"}'),
|
|
capability('sample-ordering', 'Sample ordering', 'Allow visitors to request a product sample.', [port('sample-request', 'Sample request', 'A request for a product sample.')], [port('sample-order', 'Sample order', 'A created sample order.')], [action('place-sample', 'Place sample order', 'Create a fictional sample order.', '{"orderId":"smp_1042","sku":"sample-blue","quantity":1}')], '{"orderId":"smp_1042","sku":"sample-blue"}'),
|
|
capability('commercial-ordering', 'Commercial ordering', 'Accept a normal customer purchase.', [port('cart', 'Cart', 'A cart ready for checkout.')], [port('order-request', 'Order request', 'A submitted commercial order.')], [action('place-order', 'Place commercial order', 'Create a fictional commercial order.', '{"orderId":"ord_1042","total":129.5,"currency":"GBP"}')], '{"orderId":"ord_1042","total":129.5}'),
|
|
capability('analytics', 'Analytics', 'Emit behavioural and conversion events.', [port('page-event', 'Page event', 'A page-view or conversion event.')], [port('analytics-event', 'Analytics event', 'An event ready for analytics processing.')], [action('track-event', 'Track event', 'Send a fictional page event.', '{"event":"product_view","visitorId":"vis_204"}')], '{"event":"product_view","visitorId":"vis_204"}'),
|
|
capability('account-registration', 'Account registration', 'Create an account from a registration form.', [port('registration', 'Registration', 'New account details.')], [port('customer-registration', 'Customer registration', 'Validated customer registration.')], [action('register', 'Register account', 'Create a fictional customer registration.', '{"customerId":"cus_89","email":"sam@example.test"}')], '{"customerId":"cus_89","email":"sam@example.test"}')
|
|
]},
|
|
{ id: 'crm', name: 'CRM', description: 'Customer profile and lifecycle management.', category: 'data', color: '#dd6bca', capabilities: [capability('customer-records', 'Customer records', 'Create and update customer profiles.', [port('customer-update', 'Customer update', 'Customer data to store.')], [port('customer-record', 'Customer record', 'The stored customer profile.')], [action('upsert-customer', 'Upsert customer', 'Store a fictional customer record.', '{"customerId":"cus_89","status":"active"}')], '{"customerId":"cus_89","status":"active"}'), capability('lifecycle', 'Lifecycle messaging', 'Track customer lifecycle changes.', [port('lifecycle-event', 'Lifecycle event', 'A customer lifecycle event.')], [port('segment-event', 'Segment event', 'An event for downstream messaging.')], [action('mark-welcome', 'Mark welcome sent', 'Record a fictional welcome event.', '{"customerId":"cus_89","event":"welcome_sent"}')], '{"customerId":"cus_89","event":"welcome_sent"}') ]},
|
|
{ id: 'erp', name: 'ERP', description: 'Back-office fulfilment and inventory management.', category: 'data', color: '#f2a65a', capabilities: [capability('orders', 'Order management', 'Create and progress fulfilment orders.', [port('order-request', 'Order request', 'An order to fulfil.')], [port('order-status', 'Order status', 'Current fulfilment status.')], [action('create-order', 'Create order', 'Create a fictional ERP order.', '{"orderId":"ord_1042","status":"new"}')], '{"orderId":"ord_1042","status":"new"}'), capability('inventory', 'Inventory', 'Check and reserve fictional stock.', [port('stock-check', 'Stock check', 'A product stock request.')], [port('stock-result', 'Stock result', 'Available stock information.')], [action('reserve-stock', 'Reserve stock', 'Reserve fictional stock.', '{"sku":"sample-blue","available":24,"reserved":1}')], '{"sku":"sample-blue","available":24}') ]},
|
|
{ id: 'email', name: 'Email Platform', description: 'Transactional and lifecycle messaging.', category: 'external', color: '#4aa3df', capabilities: [capability('transactional-email', 'Transactional email', 'Send a message from a template.', [port('email-request', 'Email request', 'A message request.')], [port('delivery-event', 'Delivery event', 'Delivery status.')], [action('send-email', 'Send email', 'Send a fictional transactional email.', '{"messageId":"msg_44","template":"order-confirmation","to":"sam@example.test"}')], '{"template":"order-confirmation","to":"sam@example.test"}'), capability('campaigns', 'Campaigns', 'Send lifecycle or campaign messages.', [port('campaign-request', 'Campaign request', 'A campaign message request.')], [port('campaign-event', 'Campaign event', 'Campaign delivery status.')], [action('send-campaign', 'Send campaign', 'Send a fictional campaign message.', '{"campaign":"welcome","customerId":"cus_89"}')], '{"campaign":"welcome","customerId":"cus_89"}') ]},
|
|
{ id: 'analytics', name: 'Analytics', description: 'Collect and report product and business events.', category: 'data', color: '#8f7cf2', capabilities: [capability('event-collection', 'Event collection', 'Accept events from connected systems.', [port('event', 'Event', 'A product or business event.')], [port('accepted-event', 'Accepted event', 'An accepted analytics event.')], [action('capture-event', 'Capture event', 'Capture a fictional analytics event.', '{"event":"checkout_completed","visitorId":"vis_204"}')], '{"event":"checkout_completed","visitorId":"vis_204"}'), capability('reporting', 'Reporting', 'Produce a simple report payload.', [port('report-query', 'Report query', 'A report query.')], [port('report', 'Report', 'A generated report.')], [action('run-report', 'Run report', 'Generate a fictional report.', '{"report":"weekly-orders","orders":42}')], '{"report":"weekly-orders","orders":42}') ]},
|
|
{ id: 'api', name: 'API', description: 'Orchestrate requests between applications and services.', category: 'service', color: '#26c6a6', capabilities: [capability('http-api', 'HTTP API', 'Receive and route application requests.', [port('request', 'Request', 'An inbound API request.')], [port('response', 'Response', 'A response returned to the caller.')], [action('handle-request', 'Handle request', 'Handle a fictional API request.', '{"requestId":"req_1001","status":"accepted"}')], '{"requestId":"req_1001","status":"accepted"}'), capability('webhooks', 'Webhooks', 'Send outbound event notifications.', [port('event', 'Event', 'An event to publish.')], [port('webhook', 'Webhook', 'An outbound webhook delivery.')], [action('send-webhook', 'Send webhook', 'Send a fictional webhook.', '{"event":"order.created","id":"ord_1042"}')], '{"event":"order.created","id":"ord_1042"}') ]},
|
|
{ id: 'sales-review-role', name: 'Sales review', description: 'A sales team role that reviews sample requests.', category: 'human', color: '#f06ca9', capabilities: [capability('sales-review', 'Sales review', 'Review a sample request and choose the next action.', [port('review-request', 'Review request', 'Information waiting for a sales decision.')], [port('decision', 'Decision', 'The selected sales action.')], [action('approve', 'Approve', 'Approve a request for fulfilment.', '{"decision":"approved","reviewerRole":"sales"}'), action('reject', 'Reject', 'Reject a request and notify the customer.', '{"decision":"rejected","reviewerRole":"sales"}'), action('edit', 'Edit', 'Edit the request before forwarding.', '{"decision":"edited","reviewerRole":"sales"}'), action('forward', 'Forward', 'Forward the request for another review.', '{"decision":"forwarded","reviewerRole":"sales"}')], '{"decision":"pending","reviewerRole":"sales"}') ]}
|
|
]
|
|
|
|
export function getPreset(id: string) { return SYSTEM_PRESETS.find((preset) => preset.id === id) }
|
|
export function cloneCapabilities(capabilities: CapabilityModel[], selectedIds?: string[]) { return structuredClone(capabilities.filter((item) => !selectedIds || selectedIds.includes(item.id))) }
|
|
export function systemFromPreset(preset: SystemPreset, selectedCapabilityIds: string[], position: [number, number]): SystemModel { return { id: uid('system'), presetId: preset.id, name: preset.name, description: preset.description, category: preset.category, color: preset.color, position, capabilities: cloneCapabilities(preset.capabilities, selectedCapabilityIds) } }
|
|
|
|
export const demoLandscape = (): LandscapeModel => ({
|
|
version: 1,
|
|
systems: [
|
|
{ id: 'website', name: 'Website', description: 'Customer-facing storefront and account experience.', category: 'application', color: '#6d7cff', position: [80, 180], presetId: 'website', capabilities: cloneCapabilities(getPreset('website')!.capabilities) },
|
|
{ id: 'api', name: 'API', description: 'Order and customer orchestration service.', category: 'service', color: '#26c6a6', position: [360, 180], presetId: 'api', capabilities: cloneCapabilities(getPreset('api')!.capabilities) },
|
|
{ id: 'erp', name: 'ERP', description: 'Back-office order fulfilment and inventory system.', category: 'data', color: '#f2a65a', position: [650, 100], presetId: 'erp', capabilities: cloneCapabilities(getPreset('erp')!.capabilities) },
|
|
{ id: 'crm', name: 'CRM', description: 'Customer profile and lifecycle management.', category: 'data', color: '#dd6bca', position: [650, 290], presetId: 'crm', capabilities: cloneCapabilities(getPreset('crm')!.capabilities) },
|
|
{ id: 'email', name: 'Email Platform', description: 'Transactional and lifecycle messaging.', category: 'external', color: '#4aa3df', position: [930, 290], presetId: 'email', capabilities: cloneCapabilities(getPreset('email')!.capabilities) },
|
|
{ id: 'sales-review', name: 'Sales review', description: 'Sales team role that reviews sample requests.', category: 'human', color: '#f06ca9', position: [650, 480], presetId: 'sales-review-role', capabilities: cloneCapabilities(getPreset('sales-review-role')!.capabilities) }
|
|
],
|
|
connections: [
|
|
{ id: 'website-api', sourceId: 'website', targetId: 'api', label: 'Order request', description: 'Website submits a new order to the API.', payload: '{"orderId":"ord_1042","total":129.5}' },
|
|
{ id: 'api-erp', sourceId: 'api', targetId: 'erp', label: 'Create order', description: 'API creates the order in the ERP.', payload: '{"orderId":"ord_1042","status":"new"}' },
|
|
{ id: 'api-crm', sourceId: 'api', targetId: 'crm', label: 'Update customer', description: 'API updates the customer record.', payload: '{"customerId":"cus_88","lastOrder":"ord_1042"}' },
|
|
{ id: 'api-email', sourceId: 'api', targetId: 'email', label: 'Send confirmation', description: 'API asks the email platform to send a confirmation.', payload: '{"template":"order-confirmation","to":"alex@example.com"}' },
|
|
{ id: 'website-api-register', sourceId: 'website', targetId: 'api', label: 'Registration', description: 'Website submits a new customer registration.', payload: '{"email":"alex@example.com"}' },
|
|
{ id: 'api-crm-register', sourceId: 'api', targetId: 'crm', label: 'Create customer', description: 'API creates the customer profile.', payload: '{"customerId":"cus_89","status":"active"}' },
|
|
{ id: 'crm-email', sourceId: 'crm', targetId: 'email', label: 'Welcome email', description: 'CRM triggers the welcome message.', payload: '{"template":"welcome","customerId":"cus_89"}' },
|
|
{ id: 'website-api-contact', sourceId: 'website', targetId: 'api', label: 'Contact enquiry', description: 'Website sends a contact enquiry to the API.', payload: '{"requestId":"req_1001","topic":"sample enquiry"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', showCableLabel: true },
|
|
{ id: 'api-crm-contact', sourceId: 'api', targetId: 'crm', label: 'Store enquiry', description: 'API stores a contact enquiry in the CRM.', payload: '{"requestId":"req_1001","status":"open"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', showCableLabel: true },
|
|
{ id: 'website-api-sample', sourceId: 'website', targetId: 'api', label: 'Sample request', description: 'Website sends a product sample request.', payload: '{"orderId":"smp_1042","sku":"sample-blue"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', showCableLabel: true },
|
|
{ id: 'api-erp-sample', sourceId: 'api', targetId: 'erp', label: 'Reserve sample', description: 'API asks ERP to reserve sample stock.', payload: '{"sku":"sample-blue","quantity":1}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'scheduled', showCableLabel: true },
|
|
{ id: 'website-api-commercial', sourceId: 'website', targetId: 'api', label: 'Commercial order', description: 'Website submits a commercial order.', payload: '{"orderId":"ord_2048","total":249.0}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', showCableLabel: true },
|
|
{ id: 'api-erp-commercial', sourceId: 'api', targetId: 'erp', label: 'Fulfil commercial order', description: 'API creates the commercial order in ERP.', payload: '{"orderId":"ord_2048","status":"new"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'immediate', showCableLabel: true },
|
|
{ id: 'website-sales-review', sourceId: 'website', targetId: 'sales-review', label: 'Sample review', description: 'Website sends a sample request to Sales.', payload: '{"orderId":"smp_1042","sku":"sample-blue"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'manual', showCableLabel: true },
|
|
{ id: 'sales-erp', sourceId: 'sales-review', targetId: 'erp', label: 'Approved sample', description: 'Sales approves the sample for ERP fulfilment.', payload: '{"orderId":"smp_1042","decision":"approved"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'manual', showCableLabel: true },
|
|
{ id: 'sales-email', sourceId: 'sales-review', targetId: 'email', label: 'Rejected sample notice', description: 'Sales rejection triggers a customer notification.', payload: '{"template":"sample-rejected","orderId":"smp_1042"}', protocol: 'HTTPS', dataType: 'JSON', deliveryMethod: 'manual', showCableLabel: true }
|
|
],
|
|
scenarios: [
|
|
{
|
|
id: 'place-order', name: 'Place order', description: 'Fulfil an order and notify customer systems.', startSystemId: 'website',
|
|
steps: [
|
|
{ id: 'order-1', connectionIds: ['website-api'], explanation: 'The customer places an order on the website.', payload: '{"orderId":"ord_1042"}', delayMs: 800 },
|
|
{ id: 'order-2', connectionIds: ['api-erp'], explanation: 'The API forwards the order to the ERP for fulfilment.', payload: '{"status":"new"}', delayMs: 1200 },
|
|
{ id: 'order-3', connectionIds: ['api-crm', 'api-email'], explanation: 'The API updates the CRM and sends a confirmation in parallel.', payload: '{"orderId":"ord_1042","fanout":true}', delayMs: 1200 }
|
|
]
|
|
},
|
|
{
|
|
id: 'register-customer', name: 'Register customer', description: 'Create a profile and send a welcome email.', startSystemId: 'website',
|
|
steps: [
|
|
{ id: 'register-1', connectionIds: ['website-api-register'], explanation: 'The visitor submits the registration form.', payload: '{"email":"alex@example.com"}', delayMs: 800 },
|
|
{ id: 'register-2', connectionIds: ['api-crm-register'], explanation: 'The API creates the CRM customer record.', payload: '{"status":"active"}', delayMs: 1000 },
|
|
{ id: 'register-3', connectionIds: ['crm-email'], explanation: 'The CRM triggers a welcome email.', payload: '{"template":"welcome"}', delayMs: 1000 }
|
|
]
|
|
},
|
|
{
|
|
id: 'contact-enquiry', name: 'Contact enquiry', description: 'Route a visitor question into the CRM for follow-up.', startSystemId: 'website', startActionId: 'submit-contact',
|
|
steps: [
|
|
{ id: 'contact-1', connectionIds: ['website-api-contact'], explanation: 'A visitor submits a contact enquiry.', payload: '{"requestId":"req_1001","topic":"sample enquiry"}', delayMs: 700, outcome: 'success' },
|
|
{ id: 'contact-2', connectionIds: ['api-crm-contact'], explanation: 'The API stores the enquiry for a team member.', payload: '{"requestId":"req_1001","status":"open"}', delayMs: 900, outcome: 'success' }
|
|
]
|
|
},
|
|
{
|
|
id: 'sample-request', name: 'Sample request', description: 'Reserve a sample and demonstrate scheduled fulfilment.', startSystemId: 'website', startActionId: 'place-sample',
|
|
steps: [
|
|
{ id: 'sample-1', connectionIds: ['website-api-sample'], explanation: 'A visitor requests a product sample.', payload: '{"orderId":"smp_1042","sku":"sample-blue"}', delayMs: 700, outcome: 'success' },
|
|
{ id: 'sample-2', connectionIds: ['api-erp-sample'], explanation: 'The API schedules a stock reservation with the ERP.', payload: '{"sku":"sample-blue","quantity":1}', delayMs: 1100, outcome: 'success' }
|
|
]
|
|
},
|
|
{
|
|
id: 'commercial-order', name: 'Commercial order', description: 'Submit and fulfil a normal customer purchase.', startSystemId: 'website', startActionId: 'place-order',
|
|
steps: [
|
|
{ id: 'commercial-1', connectionIds: ['website-api-commercial'], explanation: 'The customer submits a commercial order.', payload: '{"orderId":"ord_2048","total":249.0}', delayMs: 700, outcome: 'success' },
|
|
{ id: 'commercial-2', connectionIds: ['api-erp-commercial'], explanation: 'The API creates the order for fulfilment.', payload: '{"orderId":"ord_2048","status":"new"}', delayMs: 1000, outcome: 'success' }
|
|
]
|
|
},
|
|
{
|
|
id: 'order-retry', name: 'Order retry and recovery', description: 'Show an ERP rejection, one retry and recovery.', startSystemId: 'website', startActionId: 'place-order',
|
|
steps: [
|
|
{ id: 'retry-1', connectionIds: ['website-api-commercial'], explanation: 'The website sends the order to the API.', payload: '{"orderId":"ord_3001","total":89.0}', delayMs: 650, outcome: 'success' },
|
|
{ id: 'retry-2', connectionIds: ['api-erp-commercial'], explanation: 'ERP rejects the first fulfilment request because stock is being reconciled.', payload: '{"orderId":"ord_3001","status":"rejected","reason":"stock_reconciliation"}', delayMs: 1000, outcome: 'rejected', retryStepId: 'retry-3', recoveryStepId: 'retry-4' },
|
|
{ id: 'retry-3', connectionIds: ['api-erp-commercial'], explanation: 'The API retries the fulfilment request after refreshing stock.', payload: '{"orderId":"ord_3001","status":"retry"}', delayMs: 900, outcome: 'success' },
|
|
{ id: 'retry-4', connectionIds: ['api-email'], explanation: 'The API sends a recovery confirmation to the customer.', payload: '{"template":"order-retry-recovered","orderId":"ord_3001"}', delayMs: 700, outcome: 'success' }
|
|
]
|
|
},
|
|
{
|
|
id: 'sample-sales-review', name: 'Sample request with Sales review', description: 'A human role decides whether a sample reaches ERP or the customer receives a rejection notice.', startSystemId: 'website', startActionId: 'place-sample',
|
|
steps: [
|
|
{ id: 'human-sample-1', connectionIds: ['website-sales-review'], explanation: 'The website sends a sample request to the Sales review role.', payload: '{"orderId":"smp_1042","sku":"sample-blue"}', delayMs: 800, outcome: 'success' },
|
|
{ id: 'human-sample-decision', connectionIds: [], explanation: 'Sales reviews the sample request and chooses what happens next.', payload: '{"decision":"pending","orderId":"smp_1042"}', delayMs: 500, humanDecision: { roleSystemId: 'sales-review', task: 'Review the sample request and decide whether Sales should approve fulfilment or notify the customer that the request cannot proceed.', receivedData: '{"orderId":"smp_1042","sku":"sample-blue","customer":"sam@example.test"}', editableFields: { customerNote: 'Please confirm the colour before fulfilment.' }, actions: [{ id: 'approve', name: 'Approve', description: 'Send the approved sample to ERP.', payload: '{"orderId":"smp_1042","decision":"approved"}', connectionId: 'sales-erp' }, { id: 'reject', name: 'Reject', description: 'Notify the customer that the sample was rejected.', payload: '{"orderId":"smp_1042","decision":"rejected"}', connectionId: 'sales-email' }, { id: 'edit', name: 'Edit', description: 'Edit the request and forward it to ERP.', payload: '{"orderId":"smp_1042","decision":"edited","note":"Please confirm the colour"}', connectionId: 'sales-erp' }, { id: 'forward', name: 'Forward', description: 'Forward the request to ERP for another review.', payload: '{"orderId":"smp_1042","decision":"forwarded"}', connectionId: 'sales-erp' }] } }
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
export function validateLandscape(value: unknown): LandscapeModel {
|
|
if (!value || typeof value !== 'object') throw new Error('Import must contain a JSON object.')
|
|
const landscape = value as Partial<LandscapeModel>
|
|
if (landscape.version !== 1 || !Array.isArray(landscape.systems) || !Array.isArray(landscape.connections) || !Array.isArray(landscape.scenarios)) {
|
|
throw new Error('Unsupported landscape format. Expected version 1 with systems, connections, and scenarios arrays.')
|
|
}
|
|
const systems = landscape.systems.map((item) => ({ ...item, capabilities: Array.isArray(item.capabilities) ? item.capabilities : [] }))
|
|
const systemIds = new Set(systems.map((item) => item.id))
|
|
for (const connection of landscape.connections) {
|
|
if (!systemIds.has(connection.sourceId) || !systemIds.has(connection.targetId)) throw new Error(`Connection “${connection.label}” references a missing system.`)
|
|
}
|
|
const connectionIds = new Set(landscape.connections.map((item) => item.id))
|
|
for (const scenario of landscape.scenarios) for (const step of scenario.steps) for (const connectionId of step.connectionIds) {
|
|
if (!connectionIds.has(connectionId)) throw new Error(`Scenario “${scenario.name}” references a deleted connection.`)
|
|
}
|
|
return structuredClone({ ...landscape, systems } as LandscapeModel)
|
|
}
|