Skip to content

Commit

Permalink
simplify message type from and to
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1992 committed Apr 2, 2024
1 parent 8792e0a commit 0d00e88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 94 deletions.
97 changes: 5 additions & 92 deletions packages/mermaid/src/diagrams/sequence/sequenceDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
properties: Record<string, unknown>;
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;
Expand Down Expand Up @@ -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--;
}
Expand Down Expand Up @@ -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 + ')');

Check failure on line 162 in packages/mermaid/src/diagrams/sequence/sequenceDb.ts

View workflow job for this annotation

GitHub Actions / unit-test

packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js > when parsing a sequenceDiagram > should handle actor activation

Error: Trying to inactivate an inactive participant ([object Object]) ❯ addSignal packages/mermaid/src/diagrams/sequence/sequenceDb.ts:162:21 ❯ apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:520:9 ❯ packages/mermaid/src/diagrams/sequence/sequenceDb.ts:482:7 ❯ Object.apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:481:11 ❯ Object.anonymous packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:87:5 ❯ Parser.parse packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:435:36 ❯ Function.fromText packages/mermaid/src/Diagram.ts:43:18 ❯ getDiagramFromText packages/mermaid/src/mermaidAPI.ts:550:18 ❯ Object.parse packages/mermaid/src/mermaidAPI.ts:120:27 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { hash: { text: '->>-', token: '->>-', line: '1', loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: [ '\'ACTIVE_PARTICIPANT\'' ] } }

Check failure on line 162 in packages/mermaid/src/diagrams/sequence/sequenceDb.ts

View workflow job for this annotation

GitHub Actions / unit-test

packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js > when parsing a sequenceDiagram > should handle actor one line notation activation

Error: Trying to inactivate an inactive participant ([object Object]) ❯ addSignal packages/mermaid/src/diagrams/sequence/sequenceDb.ts:162:21 ❯ apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:520:9 ❯ packages/mermaid/src/diagrams/sequence/sequenceDb.ts:482:7 ❯ apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:481:11 ❯ packages/mermaid/src/diagrams/sequence/sequenceDb.ts:482:7 ❯ Object.apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:481:11 ❯ Object.anonymous packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:87:5 ❯ Parser.parse packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:435:36 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { hash: { text: '->>-', token: '->>-', line: '1', loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: [ '\'ACTIVE_PARTICIPANT\'' ] } }

Check failure on line 162 in packages/mermaid/src/diagrams/sequence/sequenceDb.ts

View workflow job for this annotation

GitHub Actions / unit-test

packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js > when parsing a sequenceDiagram > should handle stacked activations

Error: Trying to inactivate an inactive participant ([object Object]) ❯ addSignal packages/mermaid/src/diagrams/sequence/sequenceDb.ts:162:21 ❯ apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:520:9 ❯ packages/mermaid/src/diagrams/sequence/sequenceDb.ts:482:7 ❯ apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:481:11 ❯ packages/mermaid/src/diagrams/sequence/sequenceDb.ts:482:7 ❯ Object.apply packages/mermaid/src/diagrams/sequence/sequenceDb.ts:481:11 ❯ Object.anonymous packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:87:5 ❯ Parser.parse packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison:435:36 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { hash: { text: '->>-', token: '->>-', line: '1', loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: [ '\'ACTIVE_PARTICIPANT\'' ] } }

// @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 = {
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/sequence/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export interface Actor {
}

export interface Message {
from?: { actor: string };
to?: { actor: string };
from?: string;
to?: string;
message:
| string
| {
Expand Down

0 comments on commit 0d00e88

Please sign in to comment.