Add restricted middleware transformation pipelines

This commit is contained in:
2026-11-05 23:07:36 +00:00
parent 163f99be54
commit f7a06f487c
5 changed files with 88 additions and 11 deletions
+12 -3
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import { LGraph, LGraphCanvas, LiteGraph } from 'litegraph.js'
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ComponentRole, type ConnectionModel, type DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type EnvironmentModel, type InfrastructureComponent, type LandscapeModel, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
import { cloneCapabilities, demoLandscape, executePipeline, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ComponentRole, type ConnectionModel, type DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type EnvironmentModel, type InfrastructureComponent, type LandscapeModel, type PipelineTrace, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
const STORAGE_KEY = 'dumas-system-landscape-v1'
const PRESET_STORAGE_KEY = 'dumas-system-presets-v1'
@@ -42,6 +42,7 @@ type TransferKind = 'received' | 'sent' | 'stored'
interface TransferChange { key: string; status: 'added' | 'removed' | 'changed' | 'same'; incoming?: unknown; outgoing?: unknown }
interface TransferRecord { id: string; kind: TransferKind; scenarioName: string; stepNumber: number; stepExplanation: string; senderId: string; destinationId: string; payload: string; incoming: string; outgoing: string; changes: TransferChange[]; timestamp: string }
const transferHistory = ref<TransferRecord[]>([])
const pipelineTrace = ref<PipelineTrace[]>([])
const dataTab = ref<TransferKind>('received')
const selectedContainerId = ref('')
const selectedContainer = computed(() => landscape.value.containers.find((item) => item.id === selectedContainerId.value))
@@ -84,6 +85,8 @@ function saveSelectedAsPreset() { if (!selectedSystem.value) return; saveCustomP
function newCustomAction(): DefinitionActionModel { return { id: uid('action'), name: 'New action', description: 'Describe the simulated action.', trigger: 'button', input: '{}', outputs: [{ id: uid('output'), name: 'Output', payload: '{}', parallel: false }] } }
function newCustomEndpoint(): EndpointModel { return { id: uid('endpoint'), name: 'New endpoint', protocol: 'HTTPS', method: 'POST', path: '/example', request: '{}', responses: [{ id: uid('response'), status: 200, body: '{}', delayMs: 300 }] } }
function newCustomResponse(): EndpointResponseModel { return { id: uid('response'), status: 200, body: '{}', delayMs: 300 } }
function attachPipeline(action: DefinitionActionModel) { action.pipeline ||= { id: uid('pipeline'), name: `${action.name} pipeline`, references: {}, steps: [{ id: uid('step'), type: 'receive', name: 'Receive', description: 'Receive the incoming payload.', mappings: [] }, { id: uid('step'), type: 'validate', name: 'Validate', description: 'Validate the required fields.', mappings: [], condition: '' }, { id: uid('step'), type: 'transform', name: 'Transform', description: 'Apply restricted mapping rules.', mappings: [] }, { id: uid('step'), type: 'route', name: 'Route', description: 'Choose the destination.', mappings: [], condition: '' }, { id: uid('step'), type: 'send', name: 'Send', description: 'Send the resulting payload.', mappings: [] }] } }
function updatePipeline(action: DefinitionActionModel, event: Event) { const value = (event.target as HTMLTextAreaElement).value; try { action.pipeline = JSON.parse(value); importError.value = '' } catch { importError.value = 'Pipeline JSON must be valid before saving.' } }
function openCustomBuilder() { customDraft.value = { name: 'Custom system', description: 'Describe this reusable system.', category: 'service', color: '#6d7cff', definition: { actions: [newCustomAction()], endpoints: [newCustomEndpoint()] } }; customBuilderOpen.value = true }
function saveCustomBuilder() { const draft = structuredClone(customDraft.value); const preset: SystemPreset = { id: `custom-${uid('preset')}`, name: draft.name || 'Custom system', description: draft.description, category: draft.category, color: draft.color, capabilities: definitionCapabilities(draft.definition), definition: draft.definition }; saveCustomPreset(preset); customBuilderOpen.value = false }
function addCustomAction() { customDraft.value.definition.actions.push(newCustomAction()) }
@@ -120,7 +123,7 @@ function addStep() {
}
function deleteStep(index: number) { selectedScenario.value?.steps.splice(index, 1); persist() }
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; failureState.value = 'none'; retryAttempts.value = {}; pendingDecision.value = null; runtimeConnectionIds.value = []; runtimePayload.value = ''; stopAnimation() }
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; pipelineTrace.value = []; failureState.value = 'none'; retryAttempts.value = {}; pendingDecision.value = null; runtimeConnectionIds.value = []; runtimePayload.value = ''; stopAnimation() }
function startScenario(systemId?: string) {
if (systemId) {
const candidate = landscape.value.scenarios.find((scenario) => scenario.startSystemId === systemId)
@@ -148,7 +151,11 @@ function recordTransfers(step: ScenarioModel['steps'][number], selectedConnectio
const connection = landscape.value.connections.find((item) => item.id === connectionId)
if (!connection) continue
const incoming = connection.transformation?.incoming || selectedPayload || step.payload || connection.payload
const outgoing = selectedPayload || connection.transformation?.outgoing || incoming
const sourceSystem = landscape.value.systems.find((item) => item.id === connection.sourceId)
const pipelineAction = sourceSystem?.definition?.actions.find((action) => action.pipeline)
const pipelineRun = pipelineAction?.pipeline ? executePipeline(selectedPayload || step.payload || connection.payload, pipelineAction.pipeline) : undefined
if (pipelineRun) pipelineTrace.value = pipelineRun.trace
const outgoing = pipelineRun ? (pipelineRun.ok ? pipelineRun.payload : connection.payload || pipelineRun.payload) : selectedPayload || connection.transformation?.outgoing || incoming
const changes = comparePayloads(incoming, outgoing)
const payload = outgoing
transferHistory.value.push(
@@ -284,5 +291,7 @@ onUnmounted(stopAnimation)
<section class="category-panel panel"><label>Filter by category<select v-model="categoryFilter"><option value="all">All categories</option><option value="application">Application</option><option value="saas-service">SaaS Service</option><option value="cloud-service">Cloud Service</option><option value="development-tool">Development Tool</option><option value="data-store">Data Store</option><option value="service">Service</option><option value="data">Data</option><option value="human">Human</option><option value="external">External</option></select></label><label>Filter connections<select v-model="connectionTypeFilter" @change="rebuildGraph"><option value="all">All relationship types</option><option value="data-flow">Data Flow</option><option value="deployment">Deployment</option><option value="dependency">Dependency</option><option value="source-repository">Source Repository</option></select></label><label v-if="selectedConnection">Selected relationship type<select v-model="selectedConnection.connectionType"><option value="data-flow">Data Flow</option><option value="deployment">Deployment</option><option value="dependency">Dependency</option><option value="source-repository">Source Repository</option></select></label></section>
<section v-if="selectedSystem && (selectedSystem.environments?.length || activeTab === 'systems')" class="environment-panel panel"><div class="environment-header"><div><span class="eyebrow">INFRASTRUCTURE DRILL-DOWN</span><strong>{{ selectedSystem.name }} environments</strong></div><div class="environment-actions"><button class="ghost" @click="addEnvironment">+ Environment</button><button v-if="selectedEnvironment" class="ghost" @click="cloneEnvironment(selectedEnvironment)">Clone environment</button></div></div><div class="environment-tabs"><button v-for="environment in (selectedSystem.environments || [])" :key="environment.id" :class="{active: selectedEnvironment?.id === environment.id}" @click="selectEnvironment(environment.id)">{{ environment.name }}</button><span v-if="!selectedSystem.environments?.length" class="muted">No environments yet. Add Dev, QA, UAT or Prod.</span></div><div v-if="selectedEnvironment" class="environment-detail"><div class="environment-config"><label>Name<input v-model="selectedEnvironment.name" /></label><label>Hosting location<input v-model="selectedEnvironment.configuration.hostingLocation" placeholder="Azure, on-prem, etc." /></label><label>Software/version<input v-model="selectedEnvironment.configuration.softwareVersion" /></label><label>Example configuration<input :value="selectedEnvironment.exampleConfiguration ? 'Yes — fictional values' : 'No'" readonly /></label><label>Properties JSON<textarea :value="JSON.stringify(selectedEnvironment.configuration.properties, null, 2)" @change="(event) => { try { selectedEnvironment.configuration.properties = JSON.parse(event.target.value); persist() } catch { importError = 'Environment properties must be valid JSON.' } }" rows="3" class="code"></textarea></label></div><div class="environment-components"><div class="steps-head"><span>Components and instances</span><button class="icon-button" @click="addComponent">+</button></div><article v-for="component in selectedEnvironment.components" :key="component.id" class="component-card"><div class="component-head"><strong>{{ component.name }}</strong><small>{{ component.role }} · {{ component.instanceName }}</small><button class="text-danger" @click="deleteComponent(component.id)">Remove</button></div><div class="definition-grid"><label>Name<input v-model="component.name" /></label><label>Instance<input v-model="component.instanceName" /></label><label>Role<select v-model="component.role"><option value="web-application">Web Application</option><option value="content-management">Content Management</option><option value="content-delivery">Content Delivery</option><option value="database-server">Database Server</option><option value="database">Database</option><option value="search-service">Search Service</option></select></label><label>Hosting location<input v-model="component.configuration.hostingLocation" /></label><label>Hostname<input v-model="component.configuration.hostname" /></label><label>URL<input v-model="component.configuration.url" /></label><label>Software/version<input v-model="component.configuration.softwareVersion" /></label><label>Properties JSON<textarea :value="JSON.stringify(component.configuration.properties, null, 2)" @change="(event) => { try { component.configuration.properties = JSON.parse(event.target.value); persist() } catch { importError = 'Component properties must be valid JSON.' } }" rows="2" class="code"></textarea></label></div></article></div><div class="environment-topology"><div class="steps-head"><span>Internal topology</span><small>Editable example connections</small></div><div v-for="link in selectedEnvironment.connections" :key="link.id" class="topology-row"><select v-model="link.sourceComponentId"><option v-for="component in selectedEnvironment.components" :key="component.id" :value="component.id">{{ component.name }}</option></select><input v-model="link.label" /><select v-model="link.targetComponentId"><option v-for="component in selectedEnvironment.components" :key="component.id" :value="component.id">{{ component.name }}</option></select></div></div></div></section>
<section v-if="selectedScenario" class="scenario-environment panel"><span class="eyebrow">SCENARIO ENVIRONMENT</span><label>Environment<select v-model="selectedScenario.environmentId"><option value="">Logical system view</option><option v-for="system in landscape.systems" :key="system.id" :value="system.environments?.[0]?.id" :disabled="!system.environments?.length">{{ system.name }} · {{ system.environments?.[0]?.name || 'No environment' }}</option></select></label><label class="checkbox-label"><input v-model="selectedScenario.traceInternal" type="checkbox" /> Trace internal component connections when available</label></section>
<section v-if="pipelineTrace.length" class="pipeline-inspector panel"><div class="steps-head"><span>Middleware pipeline trace</span><small>Simulated restricted mappings</small></div><article v-for="trace in pipelineTrace" :key="trace.stepId" class="pipeline-trace-row"><div><b>{{ trace.name }}</b><small>{{ trace.type.toUpperCase() }} · {{ trace.explanation }}</small></div><div class="json-columns"><pre>{{ trace.input }}</pre><span>→</span><pre>{{ trace.output }}</pre></div><p v-if="trace.changedFields.length" class="changed-fields">Changed: {{ trace.changedFields.join(', ') }}</p></article></section>
<section v-if="customBuilderOpen" class="pipeline-builder-overlay"><div class="pipeline-builder panel"><div class="inspector-header"><div><span class="eyebrow">ACTION PIPELINES</span><h2>Middleware mapping editor</h2><p class="muted">Optional restricted pipelines are saved inside each action definition. No arbitrary JavaScript is executed.</p></div><button class="danger-icon" @click="customBuilderOpen = false">×</button></div><article v-for="action in customDraft.definition.actions" :key="action.id" class="definition-card"><div class="steps-head"><span>{{ action.name }}</span><button v-if="!action.pipeline" class="ghost" @click="attachPipeline(action)">Add pipeline</button></div><p v-if="!action.pipeline" class="muted">Add Receive, Validate, Transform, Route and Send stages to this action.</p><div v-else><label>Pipeline name<input v-model="action.pipeline.name" /></label><label>Pipeline JSON<textarea :value="JSON.stringify(action.pipeline, null, 2)" @change="updatePipeline(action, $event)" rows="14" class="code"></textarea></label><small class="muted">Mapping ops: copy, rename, fixed, default, type-conversion, object-construction and array-item-mapping. Use <code>$ref:key</code> in a fixed value for a reference lookup.</small></div></article><div class="modal-actions"><button class="ghost" @click="customBuilderOpen = false">Continue editing</button><button class="primary" @click="saveCustomBuilder">Save reusable preset</button></div></div></section>
</main>
</template>