@ts-graphviz/ast 0.0.0-pr956-20240225073457 → 0.0.0-pr956-20240225160253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +291 -3
  2. package/lib/ast.cjs +25 -60
  3. package/lib/ast.js +25 -60
  4. package/package.json +43 -24
  5. package/src/ast.ts +0 -8
  6. package/src/builder/__snapshots__/create-element.test.ts.snap +0 -166
  7. package/src/builder/builder.test.ts +0 -36
  8. package/src/builder/builder.ts +0 -44
  9. package/src/builder/create-element.test.ts +0 -110
  10. package/src/builder/create-element.ts +0 -13
  11. package/src/builder/index.ts +0 -3
  12. package/src/builder/types.ts +0 -226
  13. package/src/dot-shim/index.ts +0 -2
  14. package/src/dot-shim/parser/__snapshots__/parse.test.ts.snap +0 -2613
  15. package/src/dot-shim/parser/dot.peggy +0 -396
  16. package/src/dot-shim/parser/index.ts +0 -1
  17. package/src/dot-shim/parser/parse.test.ts +0 -263
  18. package/src/dot-shim/parser/parse.ts +0 -121
  19. package/src/dot-shim/parser/peggy.options.json +0 -15
  20. package/src/dot-shim/printer/index.ts +0 -6
  21. package/src/dot-shim/printer/plugins/AttributeListPrintPlugin.ts +0 -22
  22. package/src/dot-shim/printer/plugins/AttributePrintPlugin.ts +0 -11
  23. package/src/dot-shim/printer/plugins/CommentPrintPlugin.ts +0 -40
  24. package/src/dot-shim/printer/plugins/DotPrintPlugin.ts +0 -12
  25. package/src/dot-shim/printer/plugins/EdgePrintPlugin.ts +0 -27
  26. package/src/dot-shim/printer/plugins/GraphPrintPlugin.ts +0 -32
  27. package/src/dot-shim/printer/plugins/LiteralPrintPlugin.ts +0 -24
  28. package/src/dot-shim/printer/plugins/NodePrintPlugin.ts +0 -24
  29. package/src/dot-shim/printer/plugins/NodeRefGroupPrintPlugin.ts +0 -17
  30. package/src/dot-shim/printer/plugins/NodeRefPrintPlugin.ts +0 -18
  31. package/src/dot-shim/printer/plugins/SubgraphPrintPlugin.ts +0 -27
  32. package/src/dot-shim/printer/plugins/index.ts +0 -26
  33. package/src/dot-shim/printer/plugins/utils/index.ts +0 -1
  34. package/src/dot-shim/printer/plugins/utils/tokens.ts +0 -51
  35. package/src/dot-shim/printer/printer.ts +0 -46
  36. package/src/dot-shim/printer/stringify.test.ts +0 -823
  37. package/src/dot-shim/printer/stringify.ts +0 -19
  38. package/src/dot-shim/printer/types.ts +0 -74
  39. package/src/model-shim/from-model/converter.ts +0 -43
  40. package/src/model-shim/from-model/from-model.ts +0 -19
  41. package/src/model-shim/from-model/index.ts +0 -3
  42. package/src/model-shim/from-model/plugins/AttributeListPlugin.ts +0 -19
  43. package/src/model-shim/from-model/plugins/EdgePlugin.ts +0 -140
  44. package/src/model-shim/from-model/plugins/GraphPlugin.ts +0 -36
  45. package/src/model-shim/from-model/plugins/NodePlugin.ts +0 -33
  46. package/src/model-shim/from-model/plugins/SubraphPlugin.ts +0 -28
  47. package/src/model-shim/from-model/plugins/index.ts +0 -13
  48. package/src/model-shim/from-model/plugins/utils/convert-attribute.ts +0 -47
  49. package/src/model-shim/from-model/plugins/utils/convert-cluster-children.ts +0 -44
  50. package/src/model-shim/from-model/plugins/utils/convert-comment.ts +0 -16
  51. package/src/model-shim/from-model/plugins/utils/index.ts +0 -3
  52. package/src/model-shim/from-model/types.ts +0 -62
  53. package/src/model-shim/index.ts +0 -2
  54. package/src/model-shim/to-model/converter.ts +0 -42
  55. package/src/model-shim/to-model/index.ts +0 -3
  56. package/src/model-shim/to-model/plugins/DotPlugin.ts +0 -25
  57. package/src/model-shim/to-model/plugins/EdgePlugin.ts +0 -26
  58. package/src/model-shim/to-model/plugins/GraphPlugin.ts +0 -15
  59. package/src/model-shim/to-model/plugins/NodePlugin.ts +0 -25
  60. package/src/model-shim/to-model/plugins/SubgraphPlugin.ts +0 -14
  61. package/src/model-shim/to-model/plugins/index.ts +0 -13
  62. package/src/model-shim/to-model/plugins/utils/apply-statments.ts +0 -96
  63. package/src/model-shim/to-model/plugins/utils/comment-holder.ts +0 -31
  64. package/src/model-shim/to-model/plugins/utils/convert-to-edge-target-tuple.ts +0 -21
  65. package/src/model-shim/to-model/to-model.test.ts +0 -34
  66. package/src/model-shim/to-model/to-model.ts +0 -16
  67. package/src/model-shim/to-model/types.ts +0 -71
  68. package/src/types.ts +0 -370
  69. package/tsconfig.json +0 -8
  70. package/typedoc.json +0 -4
  71. package/vite.config.ts +0 -22
@@ -1,19 +0,0 @@
1
- import type { ASTNode } from '../../types.js';
2
- import { Printer } from './printer.js';
3
- import type { PrintOptions } from './types.js';
4
-
5
- /**
6
- * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
7
- *
8
- * @param ast Graphviz AST node that is to be converted.
9
- * @param options PrintOptions object containing formatting options.
10
- * @returns A string in DOT language.
11
- * @group Convert AST to DOT
12
- */
13
- export function stringify(ast: ASTNode, options?: PrintOptions): string {
14
- const result = new Printer(options).print(ast);
15
- if (!result) {
16
- throw new Error();
17
- }
18
- return result;
19
- }
@@ -1,74 +0,0 @@
1
- import { ASTNode } from '../../types.js';
2
-
3
- /**
4
- * The IndentStyle type represents an indentation style for text. It can either be a `"space"` or a `"tab"`.
5
- * @group Convert AST to DOT
6
- */
7
- export type IndentStyle = 'space' | 'tab';
8
-
9
- /**
10
- * This type represents the EndOfLine type which is used to determine the type of line ending to be used when writing to a file.
11
- * @group Convert AST to DOT
12
- */
13
- export type EndOfLine = 'lf' | 'crlf';
14
-
15
- /**
16
- * This interface provides options for converting an abstract syntax tree (AST) to a DOT representation.
17
- * @group Convert AST to DOT
18
- */
19
- export interface PrintOptions {
20
- /**
21
- * The style of indentation to use when printing the AST.
22
- *
23
- * @default "space"
24
- */
25
- indentStyle?: IndentStyle;
26
- /**
27
- * The size of the indentation to use when printing the AST.
28
- *
29
- * @default 2
30
- */
31
- indentSize?: number;
32
- /**
33
- * The type of line ending to use when printing the AST.
34
- *
35
- * @default lf
36
- */
37
- endOfLine?: EndOfLine;
38
- }
39
-
40
- /**
41
- * PrintContext interface provides an interface for printing an ASTNode with a set of options.
42
- * @group Convert AST to DOT
43
- */
44
- export interface PrintContext extends Required<PrintOptions> {
45
- /**
46
- * Indicates if the AST should be printed in a directed graph.
47
- */
48
- directed: boolean;
49
- /**
50
- * A function to print an ASTNode, taking in an ASTNode as an argument. Returns a string.
51
- */
52
- print(ast: ASTNode): string;
53
- }
54
-
55
- /**
56
- * PrintPlugin is an interface for plugins used for printing an {@link ASTNode}.
57
- * @template T T extends {@link ASTNode}
58
- * @group Convert AST to DOT
59
- */
60
- export interface PrintPlugin<T extends ASTNode = ASTNode> {
61
- /**
62
- * Checks if an ASTNode matches the plugin
63
- * @returns {boolean} true if the ASTNode matches the plugin
64
- */
65
- match(ast: ASTNode): boolean;
66
- /**
67
- * Prints an ASTNode
68
- * @param context PrintContext object
69
- * @param ast an ASTNode
70
- * @returns printed string
71
- * @memberof PrintPlugin
72
- */
73
- print(context: PrintContext, ast: T): string;
74
- }
@@ -1,43 +0,0 @@
1
- import { DotObjectModel } from '@ts-graphviz/common';
2
- import { defaultPlugins } from './plugins/index.js';
3
- import {
4
- ConvertFromModelContext,
5
- ConvertFromModelOptions,
6
- ConvertFromModelPlugin,
7
- } from './types.js';
8
- import { ModelToAST } from './types.js';
9
-
10
- /**
11
- * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
12
- *
13
- * @group Convert Model to AST
14
- */
15
- export class FromModelConverter {
16
- /** @hidden */
17
- #plugins: ConvertFromModelPlugin<DotObjectModel>[] = [...defaultPlugins];
18
-
19
- constructor(private options: ConvertFromModelOptions = {}) {}
20
-
21
- /**
22
- * Converts a DotObjectModel into an AST.
23
- *
24
- * @param model The {@link DotObjectModel} to be converted.
25
- * @returns The AST generated from the model.
26
- */
27
- public convert<T extends DotObjectModel>(model: T): ModelToAST<T> {
28
- const plugins = [...this.#plugins];
29
- const { commentKind = 'Slash' } = this.options;
30
- const context: ConvertFromModelContext = {
31
- commentKind,
32
- convert<U extends DotObjectModel>(m: U): ModelToAST<U> {
33
- for (const plugin of plugins) {
34
- if (plugin.match(m)) {
35
- return plugin.convert(context, m) as ModelToAST<U>;
36
- }
37
- }
38
- throw Error();
39
- },
40
- };
41
- return context.convert(model);
42
- }
43
- }
@@ -1,19 +0,0 @@
1
- import { DotObjectModel } from '@ts-graphviz/common';
2
- import { FromModelConverter } from './converter.js';
3
- import { ConvertFromModelOptions, ModelToAST } from './types.js';
4
-
5
- /**
6
- * A function used to convert a DotObjectModel into an AST.
7
- *
8
- * @param model - The {@link DotObjectModel} to be converted.
9
- * @param options - An optional {@link ConvertFromModelOptions} object.
10
- * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
11
- *
12
- * @group Convert Model to AST
13
- */
14
- export function fromModel<T extends DotObjectModel>(
15
- model: T,
16
- options?: ConvertFromModelOptions,
17
- ): ModelToAST<T> {
18
- return new FromModelConverter(options).convert(model);
19
- }
@@ -1,3 +0,0 @@
1
- export * from './types.js';
2
- export * from './converter.js';
3
- export * from './from-model.js';
@@ -1,19 +0,0 @@
1
- import { AttributeListModel } from '@ts-graphviz/common';
2
- import { createElement } from '../../../builder/create-element.js';
3
- import { ConvertFromModelPlugin } from '../types.js';
4
- import { convertAttribute } from './utils/index.js';
5
-
6
- export const AttributeListPlugin: ConvertFromModelPlugin<AttributeListModel> = {
7
- match(model) {
8
- return model.$$type === 'AttributeList';
9
- },
10
- convert(context, model) {
11
- return createElement(
12
- 'AttributeList',
13
- {
14
- kind: model.$$kind,
15
- },
16
- model.values.map(([key, value]) => convertAttribute(key, value)),
17
- );
18
- },
19
- };
@@ -1,140 +0,0 @@
1
- import { EdgeModel, isForwardRefNode, isNodeModel } from '@ts-graphviz/common';
2
- import { createElement } from '../../../builder/create-element.js';
3
- import { EdgeTargetASTNode } from '../../../types.js';
4
- import { ConvertFromModelPlugin } from '../types.js';
5
- import { convertAttribute, convertComment } from './utils/index.js';
6
-
7
- export const EdgePlugin: ConvertFromModelPlugin<EdgeModel> = {
8
- match(model) {
9
- return model.$$type === 'Edge';
10
- },
11
- convert(context, model) {
12
- return createElement(
13
- 'Edge',
14
- {
15
- targets: model.targets.map((target) => {
16
- if (isNodeModel(target)) {
17
- return createElement(
18
- 'NodeRef',
19
- {
20
- id: createElement(
21
- 'Literal',
22
- {
23
- value: target.id,
24
- quoted: true,
25
- },
26
- [],
27
- ),
28
- },
29
- [],
30
- );
31
- }
32
- if (isForwardRefNode(target)) {
33
- return createElement(
34
- 'NodeRef',
35
- {
36
- id: createElement(
37
- 'Literal',
38
- {
39
- value: target.id,
40
- quoted: true,
41
- },
42
- [],
43
- ),
44
- port: target.port
45
- ? createElement(
46
- 'Literal',
47
- {
48
- value: target.port,
49
- quoted: true,
50
- },
51
- [],
52
- )
53
- : undefined,
54
- compass: target.compass
55
- ? createElement(
56
- 'Literal',
57
- {
58
- value: target.compass,
59
- quoted: true,
60
- },
61
- [],
62
- )
63
- : undefined,
64
- },
65
- [],
66
- );
67
- }
68
- return createElement(
69
- 'NodeRefGroup',
70
- {},
71
- target.map((n) => {
72
- if (isNodeModel(n)) {
73
- return createElement(
74
- 'NodeRef',
75
- {
76
- id: createElement(
77
- 'Literal',
78
- {
79
- value: n.id,
80
- quoted: true,
81
- },
82
- [],
83
- ),
84
- },
85
- [],
86
- );
87
- }
88
- return createElement(
89
- 'NodeRef',
90
- {
91
- id: createElement(
92
- 'Literal',
93
- {
94
- value: n.id,
95
- quoted: true,
96
- },
97
- [],
98
- ),
99
- port: n.port
100
- ? createElement(
101
- 'Literal',
102
- {
103
- value: n.port,
104
- quoted: true,
105
- },
106
- [],
107
- )
108
- : undefined,
109
- compass: n.compass
110
- ? createElement(
111
- 'Literal',
112
- {
113
- value: n.compass,
114
- quoted: true,
115
- },
116
- [],
117
- )
118
- : undefined,
119
- },
120
- [],
121
- );
122
- }),
123
- );
124
- }) as [
125
- from: EdgeTargetASTNode,
126
- to: EdgeTargetASTNode,
127
- ...rest: EdgeTargetASTNode[],
128
- ],
129
- },
130
- [
131
- ...(model.attributes.comment
132
- ? [convertComment(model.attributes.comment, context.commentKind)]
133
- : []),
134
- ...model.attributes.values.map(([key, value]) =>
135
- convertAttribute(key, value),
136
- ),
137
- ],
138
- );
139
- },
140
- };
@@ -1,36 +0,0 @@
1
- import { RootGraphModel } from '@ts-graphviz/common';
2
- import { createElement } from '../../../builder/create-element.js';
3
- import { ConvertFromModelPlugin } from '../types.js';
4
- import { convertClusterChildren } from './utils/convert-cluster-children.js';
5
- import { convertComment } from './utils/convert-comment.js';
6
-
7
- export const GraphPlugin: ConvertFromModelPlugin<RootGraphModel> = {
8
- match(model) {
9
- return model.$$type === 'Graph';
10
- },
11
- convert(context, model) {
12
- return createElement('Dot', {}, [
13
- ...(model.comment
14
- ? [convertComment(model.comment, context.commentKind)]
15
- : []),
16
- createElement(
17
- 'Graph',
18
- {
19
- directed: model.directed,
20
- strict: model.strict,
21
- id: model.id
22
- ? createElement(
23
- 'Literal',
24
- {
25
- value: model.id,
26
- quoted: true,
27
- },
28
- [],
29
- )
30
- : undefined,
31
- },
32
- convertClusterChildren(context, model),
33
- ),
34
- ]);
35
- },
36
- };
@@ -1,33 +0,0 @@
1
- import { NodeModel } from '@ts-graphviz/common';
2
- import { createElement } from '../../../builder/create-element.js';
3
- import { ConvertFromModelPlugin } from '../types.js';
4
- import { convertAttribute, convertComment } from './utils/index.js';
5
-
6
- export const NodePlugin: ConvertFromModelPlugin<NodeModel> = {
7
- match(model) {
8
- return model.$$type === 'Node';
9
- },
10
- convert(context, model) {
11
- return createElement(
12
- 'Node',
13
- {
14
- id: createElement(
15
- 'Literal',
16
- {
17
- value: model.id,
18
- quoted: true,
19
- },
20
- [],
21
- ),
22
- },
23
- [
24
- ...(model.attributes.comment
25
- ? [convertComment(model.attributes.comment, context.commentKind)]
26
- : []),
27
- ...model.attributes.values.map(([key, value]) =>
28
- convertAttribute(key, value),
29
- ),
30
- ],
31
- );
32
- },
33
- };
@@ -1,28 +0,0 @@
1
- import { SubgraphModel } from '@ts-graphviz/common';
2
- import { createElement } from '../../../builder/create-element.js';
3
- import { ConvertFromModelPlugin } from '../types.js';
4
- import { convertClusterChildren } from './utils/convert-cluster-children.js';
5
-
6
- export const SubgraphPlugin: ConvertFromModelPlugin<SubgraphModel> = {
7
- match(model) {
8
- return model.$$type === 'Subgraph';
9
- },
10
- convert(context, model) {
11
- return createElement(
12
- 'Subgraph',
13
- {
14
- id: model.id
15
- ? createElement(
16
- 'Literal',
17
- {
18
- value: model.id,
19
- quoted: true,
20
- },
21
- [],
22
- )
23
- : undefined,
24
- },
25
- convertClusterChildren(context, model),
26
- );
27
- },
28
- };
@@ -1,13 +0,0 @@
1
- import { AttributeListPlugin } from './AttributeListPlugin.js';
2
- import { EdgePlugin } from './EdgePlugin.js';
3
- import { GraphPlugin } from './GraphPlugin.js';
4
- import { NodePlugin } from './NodePlugin.js';
5
- import { SubgraphPlugin } from './SubraphPlugin.js';
6
-
7
- export const defaultPlugins = [
8
- AttributeListPlugin,
9
- EdgePlugin,
10
- NodePlugin,
11
- GraphPlugin,
12
- SubgraphPlugin,
13
- ];
@@ -1,47 +0,0 @@
1
- import { Attribute, AttributeKey } from '@ts-graphviz/common';
2
- import { createElement } from '../../../../builder/create-element.js';
3
- import { AttributeASTNode } from '../../../../types.js';
4
-
5
- export function convertAttribute<K extends AttributeKey>(
6
- key: K,
7
- value: Attribute<K>,
8
- ): AttributeASTNode {
9
- if (typeof value === 'string') {
10
- const trimmed = value.trim();
11
- const isHTMLLike = /^<.+>$/ms.test(trimmed);
12
- if (isHTMLLike) {
13
- return createElement(
14
- 'Attribute',
15
- {
16
- key: createElement('Literal', { value: key, quoted: false }, []),
17
- value: createElement(
18
- 'Literal',
19
- { value: trimmed.slice(1, trimmed.length - 1), quoted: 'html' },
20
- [],
21
- ),
22
- },
23
- [],
24
- );
25
- }
26
- return createElement(
27
- 'Attribute',
28
- {
29
- key: createElement('Literal', { value: key, quoted: false }, []),
30
- value: createElement('Literal', { value: value, quoted: true }, []),
31
- },
32
- [],
33
- );
34
- }
35
- return createElement(
36
- 'Attribute',
37
- {
38
- key: createElement('Literal', { value: key, quoted: false }, []),
39
- value: createElement(
40
- 'Literal',
41
- { value: String(value), quoted: false },
42
- [],
43
- ),
44
- },
45
- [],
46
- );
47
- }
@@ -1,44 +0,0 @@
1
- import { GraphBaseModel } from '@ts-graphviz/common';
2
- import { ClusterStatementASTNode } from '../../../../types.js';
3
- import { ConvertFromModelContext } from '../../types.js';
4
- import { convertAttribute } from './convert-attribute.js';
5
- import { convertComment } from './convert-comment.js';
6
-
7
- export function convertClusterChildren(
8
- context: ConvertFromModelContext,
9
- model: GraphBaseModel,
10
- ) {
11
- return Array.from(
12
- (function* (): Generator<ClusterStatementASTNode> {
13
- for (const [key, value] of model.values) {
14
- yield convertAttribute(key, value);
15
- }
16
- for (const attrs of Object.values(model.attributes)) {
17
- if (attrs.size > 0) {
18
- if (attrs.comment) {
19
- yield convertComment(attrs.comment, context.commentKind);
20
- }
21
- yield context.convert(attrs);
22
- }
23
- }
24
- for (const node of model.nodes) {
25
- if (node.comment) {
26
- yield convertComment(node.comment, context.commentKind);
27
- }
28
- yield context.convert(node);
29
- }
30
- for (const subgraph of model.subgraphs) {
31
- if (subgraph.comment) {
32
- yield convertComment(subgraph.comment, context.commentKind);
33
- }
34
- yield context.convert(subgraph);
35
- }
36
- for (const edge of model.edges) {
37
- if (edge.comment) {
38
- yield convertComment(edge.comment, context.commentKind);
39
- }
40
- yield context.convert(edge);
41
- }
42
- })(),
43
- );
44
- }
@@ -1,16 +0,0 @@
1
- import { createElement } from '../../../../builder/create-element.js';
2
- import { CommentASTNode, CommentKind } from '../../../../types.js';
3
-
4
- export function convertComment(
5
- value: string,
6
- kind: CommentKind,
7
- ): CommentASTNode {
8
- return createElement(
9
- 'Comment',
10
- {
11
- kind: kind,
12
- value: value,
13
- },
14
- [],
15
- );
16
- }
@@ -1,3 +0,0 @@
1
- export * from './convert-attribute.js';
2
- export * from './convert-comment.js';
3
- export * from './convert-cluster-children.js';
@@ -1,62 +0,0 @@
1
- import { DotObjectModel } from '@ts-graphviz/common';
2
- import {
3
- AttributeListASTNode,
4
- CommentKind,
5
- DotASTNode,
6
- EdgeASTNode,
7
- GraphASTNode,
8
- NodeASTNode,
9
- SubgraphASTNode,
10
- } from '../../types.js';
11
-
12
- /**
13
- * ModelToAST is a type alias used to map a generic type T to a specific AST node type.
14
- *
15
- * If T is a DotObjectModel, the type U is inferred and used to determine which AST node type to map to.
16
- *
17
- * If U is 'Graph', the type is mapped to either a {@link GraphASTNode} or a {@link DotASTNode}.
18
- * If U is 'AttributeList', the type is mapped to an {@link AttributeListASTNode}.
19
- * If U is 'Edge', the type is mapped to an {@link EdgeASTNode}.
20
- * If U is 'Node', the type is mapped to a {@link NodeASTNode}.
21
- * If U is 'Subgraph', the type is mapped to a {@link SubgraphASTNode}.
22
- *
23
- * If T is not a DotObjectModel, the type is mapped to never.
24
- *
25
- * @group AST
26
- */
27
- export type ModelToAST<T> = T extends DotObjectModel<infer U>
28
- ? U extends 'Graph'
29
- ? GraphASTNode | DotASTNode
30
- : U extends 'AttributeList'
31
- ? AttributeListASTNode
32
- : U extends 'Edge'
33
- ? EdgeASTNode
34
- : U extends 'Node'
35
- ? NodeASTNode
36
- : U extends 'Subgraph'
37
- ? SubgraphASTNode
38
- : never
39
- : never;
40
-
41
- /**
42
- * @group Convert Model to AST
43
- */
44
- export interface ConvertFromModelOptions {
45
- commentKind?: CommentKind;
46
- }
47
-
48
- /**
49
- * @group Convert Model to AST
50
- */
51
- export interface ConvertFromModelContext
52
- extends Required<ConvertFromModelOptions> {
53
- convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
54
- }
55
-
56
- /**
57
- * @group Convert Model to AST
58
- */
59
- export interface ConvertFromModelPlugin<T extends DotObjectModel> {
60
- match(model: T): boolean;
61
- convert(context: ConvertFromModelContext, model: T): ModelToAST<T>;
62
- }
@@ -1,2 +0,0 @@
1
- export * from './from-model/index.js';
2
- export * from './to-model/index.js';
@@ -1,42 +0,0 @@
1
- import { createModelsContext } from '@ts-graphviz/common';
2
- import { defaultPlugins } from './plugins/index.js';
3
- import {
4
- ASTToModel,
5
- ConvertToModelContext,
6
- ConvertToModelOptions,
7
- ConvertToModelPlugin,
8
- ToModelConvertableASTNode,
9
- } from './types.js';
10
-
11
- /**
12
- * @group Convert AST to Model
13
- */
14
- export class ToModelConverter {
15
- /** @hidden */
16
- protected plugins: ConvertToModelPlugin<ToModelConvertableASTNode>[] = [
17
- ...defaultPlugins,
18
- ];
19
-
20
- constructor(private options: ConvertToModelOptions = {}) {}
21
-
22
- /**
23
- * Convert AST to Model.
24
- *
25
- * @param ast AST node.
26
- */
27
- public convert<T extends ToModelConvertableASTNode>(ast: T): ASTToModel<T> {
28
- const plugins = [...this.plugins];
29
- const context: ConvertToModelContext = {
30
- models: createModelsContext(this.options.models ?? {}),
31
- convert<U extends ToModelConvertableASTNode>(m: U): ASTToModel<U> {
32
- for (const plugin of plugins) {
33
- if (plugin.match(m)) {
34
- return plugin.convert(context, m) as ASTToModel<U>;
35
- }
36
- }
37
- throw Error();
38
- },
39
- };
40
- return context.convert(ast);
41
- }
42
- }
@@ -1,3 +0,0 @@
1
- export * from './types.js';
2
- export * from './converter.js';
3
- export * from './to-model.js';