From 0d00e885806d0c26024b27f3a7368306f24c65e5 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 2 Apr 2024 11:40:11 +0530 Subject: [PATCH] simplify message type from and to --- .../src/diagrams/sequence/sequenceDb.ts | 97 +------------------ .../mermaid/src/diagrams/sequence/types.ts | 4 +- 2 files changed, 7 insertions(+), 94 deletions(-) diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts index b40add8412..80638e1807 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts @@ -11,92 +11,7 @@ import { setDiagramTitle, } from '../common/commonDb.js'; import { ImperativeState } from '../../utils/imperativeState.js'; - -interface Box { - name: string; - wrap: boolean; - fill: string; - actorKeys: string[]; -} - -interface Actor { - box?: Box; - name: string; - description: string; - wrap: boolean; - prevActor?: string; - nextActor?: string; - links: Record; - properties: Record; - actorCnt: number | null; - rectData: unknown; - type: string; -} - -interface Message { - from?: { actor: string }; - to?: { actor: string }; - message: - | string - | { - start: number; - step: number; - visible: boolean; - }; - wrap: boolean; - answer?: unknown; - type?: number; - activate?: boolean; - placement?: string; -} - -interface AddMessageParams { - from: string; - to: string; - msg: string; - signalType: number; - type: - | 'addMessage' - | 'sequenceIndex' - | 'addParticipant' - | 'createParticipant' - | 'destroyParticipant' - | 'activeStart' - | 'activeEnd' - | 'addNote' - | 'addLinks' - | 'addALink' - | 'addProperties' - | 'addDetails' - | 'boxStart' - | 'boxEnd' - | 'loopStart' - | 'loopEnd' - | 'rectStart' - | 'rectEnd' - | 'optStart' - | 'optEnd' - | 'altStart' - | 'else' - | 'altEnd' - | 'setAccTitle' - | 'parStart' - | 'parAnd' - | 'parEnd' - | 'and' - | 'criticalStart' - | 'criticalOption' - | 'option' - | 'criticalEnd' - | 'breakStart' - | 'breakEnd' - | 'parOverStart' - | 'parOverEnd' - | 'parOverAnd' - | 'parOverEnd'; - - activate: boolean; -} +import type { Actor, AddMessageParams, Box, Message } from './types.js'; type State = { prevActor?: string; @@ -204,13 +119,13 @@ const activationCount = (part: string) => { for (i = 0; i < state.records.messages.length; i++) { if ( state.records.messages[i].type === LINETYPE.ACTIVE_START && - state.records.messages[i].from!.actor === part + state.records.messages[i].from === part ) { count++; } if ( state.records.messages[i].type === LINETYPE.ACTIVE_END && - state.records.messages[i].from!.actor === part + state.records.messages[i].from === part ) { count--; } @@ -241,12 +156,10 @@ export const addSignal = function ( activate: boolean = false ) { if (messageType === LINETYPE.ACTIVE_END) { - const cnt = activationCount(idFrom?.actor || ''); + const cnt = activationCount(idFrom || ''); if (cnt < 1) { // Bail out as there is an activation signal from an inactive participant - const error = new Error( - 'Trying to inactivate an inactive participant (' + idFrom?.actor + ')' - ); + const error = new Error('Trying to inactivate an inactive participant (' + idFrom + ')'); // @ts-ignore: we are passing hash param to the error object, however we should define our own custom error class to make it type safe error.hash = { diff --git a/packages/mermaid/src/diagrams/sequence/types.ts b/packages/mermaid/src/diagrams/sequence/types.ts index 83ef0fc67a..b307751601 100644 --- a/packages/mermaid/src/diagrams/sequence/types.ts +++ b/packages/mermaid/src/diagrams/sequence/types.ts @@ -20,8 +20,8 @@ export interface Actor { } export interface Message { - from?: { actor: string }; - to?: { actor: string }; + from?: string; + to?: string; message: | string | {