From 5ab955b6b311023dafa0f785fa301aa06ae2134b Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 10 Sep 2024 14:18:34 +0530 Subject: [PATCH] fix: Change return type from parse --- packages/mermaid/src/mermaid.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index fa5ac2427..0d1a765fc 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -2,18 +2,18 @@ * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid * functionality and to render the diagrams to svg code! */ -import { registerIconPacks } from './rendering-util/icons.js'; import { dedent } from 'ts-dedent'; import type { MermaidConfig } from './config.type.js'; import { detectType, registerLazyLoadedDiagrams } from './diagram-api/detectType.js'; import { addDiagrams } from './diagram-api/diagram-orchestration.js'; import { loadRegisteredDiagrams } from './diagram-api/loadDiagram.js'; import type { ExternalDiagramDefinition, SVG, SVGGroup } from './diagram-api/types.js'; -import type { Diagram, ParseErrorFunction } from './Diagram.js'; +import type { ParseErrorFunction } from './Diagram.js'; import type { UnknownDiagramError } from './errors.js'; import type { InternalHelpers } from './internals.js'; import { log } from './logger.js'; import { mermaidAPI } from './mermaidAPI.js'; +import { registerIconPacks } from './rendering-util/icons.js'; import type { LayoutLoaderDefinition, RenderOptions } from './rendering-util/render.js'; import { registerLayoutLoaders } from './rendering-util/render.js'; import type { LayoutData } from './rendering-util/types.js'; @@ -321,7 +321,9 @@ const executeQueue = async () => { executionQueueRunning = false; }; -interface ConfigTuple { +interface ParseResultWithConfigs extends Omit { + /** Config the user has defined in the text as frontmatter or directives */ + userConfig: MermaidConfig; defaultConfig: MermaidConfig; config: MermaidConfig; } @@ -347,7 +349,7 @@ interface ConfigTuple { const parse = async ( text: string, parseOptions?: ParseOptions -): Promise => { +): Promise => { return new Promise((resolve, reject) => { // This promise will resolve when the render call is done. // It will be queued first and will be executed when it is first in line @@ -355,9 +357,12 @@ const parse = async ( new Promise((res, rej) => { mermaidAPI.parse(text, parseOptions).then( (r) => { - const result = r as Diagram & ConfigTuple; - result.defaultConfig = mermaidAPI.defaultConfig; - result.config = mermaidAPI.getConfig(); + const result = { + diagram: r.diagram, + userConfig: r.config, + defaultConfig: mermaidAPI.defaultConfig, + config: mermaidAPI.getConfig(), + } satisfies ParseResultWithConfigs; // This resolves for the promise for the queue handling res(result); // This fulfills the promise sent to the value back to the original caller