ts-graphviz 1.5.5-dev.02afc3340 → 1.5.5-dev.27273c787

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.
@@ -1,20 +1,9 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * @module ts-graphviz/adapter
5
- * @beta
6
- */
7
- /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
8
3
  const ERROR_MESSAGE = 'This module cannot be run in a browser.';
9
- /**
10
- * Execute the Graphviz dot command and make a Stream of the results.
11
- */
12
4
  function toStream(dot, options) {
13
5
  throw new Error(ERROR_MESSAGE);
14
6
  }
15
- /**
16
- * Execute the Graphviz dot command and output the results to a file.
17
- */
18
7
  function toFile(dot, path, options) {
19
8
  throw new Error(ERROR_MESSAGE);
20
9
  }
@@ -1,18 +1,7 @@
1
- /**
2
- * @module ts-graphviz/adapter
3
- * @beta
4
- */
5
- /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
6
1
  const ERROR_MESSAGE = 'This module cannot be run in a browser.';
7
- /**
8
- * Execute the Graphviz dot command and make a Stream of the results.
9
- */
10
2
  function toStream(dot, options) {
11
3
  throw new Error(ERROR_MESSAGE);
12
4
  }
13
- /**
14
- * Execute the Graphviz dot command and output the results to a file.
15
- */
16
5
  function toFile(dot, path, options) {
17
6
  throw new Error(ERROR_MESSAGE);
18
7
  }
@@ -6,21 +6,12 @@ var index_js = require('../utils/index.cjs');
6
6
  var node_util = require('node:util');
7
7
  var node_fs = require('node:fs');
8
8
 
9
- /**
10
- * NOTE:
11
- * The node:stream/promises standard module is not provided in Node 14.
12
- * Fix Node 14 to use node:stream/promises after LTS ends.
13
- */
14
9
  const pipeline = node_util.promisify(node_stream.pipeline);
15
10
 
16
- /**
17
- * Execute the Graphviz dot command and make a Stream of the results.
18
- */
19
11
  async function toStream(dot, options) {
20
12
  const [command, args] = index_js.createCommandAndArgs(options ?? {});
21
13
  return new Promise(async function toStreamInternal(resolve, reject) {
22
14
  const p = node_child_process.spawn(command, args, { stdio: 'pipe' });
23
- // error handling
24
15
  p.on('error', (e) => {
25
16
  reject(
26
17
  new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
@@ -45,9 +36,6 @@ async function toStream(dot, options) {
45
36
  });
46
37
  }
47
38
 
48
- /**
49
- * Execute the Graphviz dot command and output the results to a file.
50
- */
51
39
  async function toFile(dot, path, options) {
52
40
  const stream = await toStream(dot, options);
53
41
  await pipeline(stream, node_fs.createWriteStream(path));
@@ -4,21 +4,12 @@ import { createCommandAndArgs } from '../utils/index.js';
4
4
  import { promisify } from 'node:util';
5
5
  import { createWriteStream } from 'node:fs';
6
6
 
7
- /**
8
- * NOTE:
9
- * The node:stream/promises standard module is not provided in Node 14.
10
- * Fix Node 14 to use node:stream/promises after LTS ends.
11
- */
12
7
  const pipeline = promisify(pipeline$1);
13
8
 
14
- /**
15
- * Execute the Graphviz dot command and make a Stream of the results.
16
- */
17
9
  async function toStream(dot, options) {
18
10
  const [command, args] = createCommandAndArgs(options ?? {});
19
11
  return new Promise(async function toStreamInternal(resolve, reject) {
20
12
  const p = spawn(command, args, { stdio: 'pipe' });
21
- // error handling
22
13
  p.on('error', (e) => {
23
14
  reject(
24
15
  new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
@@ -43,9 +34,6 @@ async function toStream(dot, options) {
43
34
  });
44
35
  }
45
36
 
46
- /**
47
- * Execute the Graphviz dot command and output the results to a file.
48
- */
49
37
  async function toFile(dot, path, options) {
50
38
  const stream = await toStream(dot, options);
51
39
  await pipeline(stream, createWriteStream(path));
@@ -1,12 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * escapeValue is a function that escapes a given Attribute value of a given AttributeKey.
5
- * It checks the type of the value and adds quotes if the value is of type string and contains whitespace.
6
- *
7
- * @param value The value of an Attribute of type T that extends AttributeKey
8
- * @returns The escaped Attribute value
9
- */
10
3
  function escapeValue(value) {
11
4
  if (value !== true) {
12
5
  if (typeof value === 'string' && /\s/g.test(value)) {
@@ -17,13 +10,6 @@ function escapeValue(value) {
17
10
  }
18
11
  return '';
19
12
  }
20
- /**
21
- * createCommandArgs is a function that creates command arguments from a given Options object.
22
- * It reads the properties of the Options object and creates corresponding command line arguments accordingly.
23
- *
24
- * @param options The Options object used to create command arguments
25
- * @returns A generator that yields strings for command arguments
26
- */
27
13
  function* createCommandArgs(options) {
28
14
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
29
15
  if (suppressWarnings) yield '-q';
@@ -65,12 +51,6 @@ function* createCommandArgs(options) {
65
51
  }
66
52
  }
67
53
 
68
- /**
69
- * createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
70
- *
71
- * @param options Options to create the command and args from.
72
- * @returns A tuple containing the command and an array of arguments.
73
- */
74
54
  function createCommandAndArgs(options) {
75
55
  return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
76
56
  }
@@ -1,10 +1,3 @@
1
- /**
2
- * escapeValue is a function that escapes a given Attribute value of a given AttributeKey.
3
- * It checks the type of the value and adds quotes if the value is of type string and contains whitespace.
4
- *
5
- * @param value The value of an Attribute of type T that extends AttributeKey
6
- * @returns The escaped Attribute value
7
- */
8
1
  function escapeValue(value) {
9
2
  if (value !== true) {
10
3
  if (typeof value === 'string' && /\s/g.test(value)) {
@@ -15,13 +8,6 @@ function escapeValue(value) {
15
8
  }
16
9
  return '';
17
10
  }
18
- /**
19
- * createCommandArgs is a function that creates command arguments from a given Options object.
20
- * It reads the properties of the Options object and creates corresponding command line arguments accordingly.
21
- *
22
- * @param options The Options object used to create command arguments
23
- * @returns A generator that yields strings for command arguments
24
- */
25
11
  function* createCommandArgs(options) {
26
12
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
27
13
  if (suppressWarnings) yield '-q';
@@ -63,12 +49,6 @@ function* createCommandArgs(options) {
63
49
  }
64
50
  }
65
51
 
66
- /**
67
- * createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
68
- *
69
- * @param options Options to create the command and args from.
70
- * @returns A tuple containing the command and an array of arguments.
71
- */
72
52
  function createCommandAndArgs(options) {
73
53
  return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
74
54
  }
package/lib/ast/index.cjs CHANGED
@@ -3,36 +3,14 @@
3
3
  var index_js = require('../utils/index.cjs');
4
4
  var index_js$1 = require('../common/index.cjs');
5
5
 
6
- /**
7
- * Builder is an ASTBuilder that provides a method to create an ASTNode.
8
- *
9
- * @group Create AST
10
- */
11
6
  class Builder {
12
7
  options;
13
- /**
14
- * Get the current file range or null
15
- * @internal
16
- */
17
8
  getLocation() {
18
9
  return this.options?.locationFunction?.() ?? null;
19
10
  }
20
- /**
21
- * Constructor of Builder
22
- * @param options - Options to initialize Builder
23
- */
24
11
  constructor(options) {
25
12
  this.options = options;
26
13
  }
27
- /**
28
- * Create an {@link ASTNode} of the specified type
29
- *
30
- * @param type - Type of the {@link ASTNode}
31
- * @param props - Properties of the {@link ASTNode}
32
- * @param children - Children of the {@link ASTNode}
33
- * @returns An {@link ASTNode}
34
- */
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
14
  createElement(type, props, children) {
37
15
  return {
38
16
  ...props,
@@ -43,15 +21,6 @@ class Builder {
43
21
  }
44
22
  }
45
23
 
46
- /**
47
- * Create an {@link ASTNode} of the specified type
48
- *
49
- * @param type - Type of the {@link ASTNode}
50
- * @param props - Properties of the {@link ASTNode}
51
- * @param children - Children of the {@link ASTNode}
52
- * @group Create AST
53
- * @returns An {@link ASTNode}
54
- */
55
24
  const createElement = Builder.prototype.createElement.bind(new Builder());
56
25
 
57
26
  const EOL = /\r?\n/;
@@ -288,25 +257,12 @@ const defaultPlugins$2 = [
288
257
  SubgraphPrintPlugin,
289
258
  ];
290
259
 
291
- /**
292
- * Printer is a class responsible for converting an AST into a DOT string.
293
- * @group Convert AST to DOT
294
- */
295
260
  class Printer {
296
261
  options;
297
- /** @internal */
298
262
  #plugins = [...defaultPlugins$2];
299
- /**
300
- * @param options Options to be used when generating the DOT string.
301
- */
302
263
  constructor(options = {}) {
303
264
  this.options = options;
304
265
  }
305
- /**
306
- * Generates a DOT string from an ASTNode.
307
- * @param ast The ASTNode to be converted into a DOT string.
308
- * @returns The DOT string generated from the ASTNode.
309
- */
310
266
  print(ast) {
311
267
  const plugins = [...this.#plugins];
312
268
  const { indentSize = 2, indentStyle = 'space', endOfLine = 'lf' } = this.options;
@@ -328,14 +284,6 @@ class Printer {
328
284
  }
329
285
  }
330
286
 
331
- /**
332
- * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
333
- *
334
- * @param ast Graphviz AST node that is to be converted.
335
- * @param options PrintOptions object containing formatting options.
336
- * @returns A string in DOT language.
337
- * @group Convert AST to DOT
338
- */
339
287
  function stringify(ast, options) {
340
288
  const result = new Printer(options).print(ast);
341
289
  if (!result) {
@@ -344,7 +292,6 @@ function stringify(ast, options) {
344
292
  return result;
345
293
  }
346
294
 
347
- /* eslint-disable */
348
295
  function peg$padEnd(str, targetLength, padString) {
349
296
  padString = padString || ' ';
350
297
  if (str.length > targetLength) {
@@ -574,9 +521,7 @@ function peg$parse(input, options) {
574
521
  );
575
522
  };
576
523
  const peg$c21 = function (id, rhs, _children) {
577
- // @ts-ignore
578
524
  return b.createElement(
579
- // @ts-ignore
580
525
  'Edge',
581
526
  {
582
527
  targets: [id, ...rhs],
@@ -5287,9 +5232,6 @@ const parse$1 = peg$parse;
5287
5232
  function parse(input, options) {
5288
5233
  return parse$1(input, options);
5289
5234
  }
5290
- /**
5291
- * @group Convert DOT to AST
5292
- */
5293
5235
  const DotSyntaxError = DotSyntaxError$1;
5294
5236
 
5295
5237
  function convertAttribute(key, value) {
@@ -5595,24 +5537,12 @@ const SubgraphPlugin$1 = {
5595
5537
 
5596
5538
  const defaultPlugins$1 = [AttributeListPlugin, EdgePlugin$1, NodePlugin$1, GraphPlugin$1, SubgraphPlugin$1];
5597
5539
 
5598
- /**
5599
- * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
5600
- *
5601
- * @group Convert Model to AST
5602
- */
5603
5540
  class FromModelConverter {
5604
5541
  options;
5605
- /** @hidden */
5606
5542
  #plugins = [...defaultPlugins$1];
5607
5543
  constructor(options = {}) {
5608
5544
  this.options = options;
5609
5545
  }
5610
- /**
5611
- * Converts a DotObjectModel into an AST.
5612
- *
5613
- * @param model The {@link DotObjectModel} to be converted.
5614
- * @returns The AST generated from the model.
5615
- */
5616
5546
  convert(model) {
5617
5547
  const plugins = [...this.#plugins];
5618
5548
  const { commentKind = 'Slash' } = this.options;
@@ -5631,15 +5561,6 @@ class FromModelConverter {
5631
5561
  }
5632
5562
  }
5633
5563
 
5634
- /**
5635
- * A function used to convert a DotObjectModel into an AST.
5636
- *
5637
- * @param model - The {@link DotObjectModel} to be converted.
5638
- * @param options - An optional {@link ConvertFromModelOptions} object.
5639
- * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
5640
- *
5641
- * @group Convert Model to AST
5642
- */
5643
5564
  function fromModel(model, options) {
5644
5565
  return new FromModelConverter(options).convert(model);
5645
5566
  }
@@ -5815,23 +5736,12 @@ const NodePlugin = {
5815
5736
 
5816
5737
  const defaultPlugins = [NodePlugin, EdgePlugin, SubgraphPlugin, GraphPlugin, DotPlugin];
5817
5738
 
5818
- /**
5819
- * @group Convert AST to Model
5820
- * @alpha
5821
- */
5822
5739
  class ToModelConverter {
5823
5740
  options;
5824
- /** @hidden */
5825
5741
  plugins = [...defaultPlugins];
5826
5742
  constructor(options = {}) {
5827
5743
  this.options = options;
5828
5744
  }
5829
- /**
5830
- * Convert AST to Model.
5831
- *
5832
- * @param ast AST node.
5833
- * @alpha
5834
- */
5835
5745
  convert(ast) {
5836
5746
  const plugins = [...this.plugins];
5837
5747
  const context = {
@@ -5849,10 +5759,6 @@ class ToModelConverter {
5849
5759
  }
5850
5760
  }
5851
5761
 
5852
- /**
5853
- * @group Convert AST to Model
5854
- * @beta
5855
- */
5856
5762
  function toModel(ast, options) {
5857
5763
  return new ToModelConverter(options).convert(ast);
5858
5764
  }
package/lib/ast/index.js CHANGED
@@ -1,36 +1,14 @@
1
1
  import { pipe, map } from '../utils/index.js';
2
2
  import { isNodeModel, isForwardRefNode, createModelsContext } from '../common/index.js';
3
3
 
4
- /**
5
- * Builder is an ASTBuilder that provides a method to create an ASTNode.
6
- *
7
- * @group Create AST
8
- */
9
4
  class Builder {
10
5
  options;
11
- /**
12
- * Get the current file range or null
13
- * @internal
14
- */
15
6
  getLocation() {
16
7
  return this.options?.locationFunction?.() ?? null;
17
8
  }
18
- /**
19
- * Constructor of Builder
20
- * @param options - Options to initialize Builder
21
- */
22
9
  constructor(options) {
23
10
  this.options = options;
24
11
  }
25
- /**
26
- * Create an {@link ASTNode} of the specified type
27
- *
28
- * @param type - Type of the {@link ASTNode}
29
- * @param props - Properties of the {@link ASTNode}
30
- * @param children - Children of the {@link ASTNode}
31
- * @returns An {@link ASTNode}
32
- */
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
12
  createElement(type, props, children) {
35
13
  return {
36
14
  ...props,
@@ -41,15 +19,6 @@ class Builder {
41
19
  }
42
20
  }
43
21
 
44
- /**
45
- * Create an {@link ASTNode} of the specified type
46
- *
47
- * @param type - Type of the {@link ASTNode}
48
- * @param props - Properties of the {@link ASTNode}
49
- * @param children - Children of the {@link ASTNode}
50
- * @group Create AST
51
- * @returns An {@link ASTNode}
52
- */
53
22
  const createElement = Builder.prototype.createElement.bind(new Builder());
54
23
 
55
24
  const EOL = /\r?\n/;
@@ -281,25 +250,12 @@ const defaultPlugins$2 = [
281
250
  SubgraphPrintPlugin,
282
251
  ];
283
252
 
284
- /**
285
- * Printer is a class responsible for converting an AST into a DOT string.
286
- * @group Convert AST to DOT
287
- */
288
253
  class Printer {
289
254
  options;
290
- /** @internal */
291
255
  #plugins = [...defaultPlugins$2];
292
- /**
293
- * @param options Options to be used when generating the DOT string.
294
- */
295
256
  constructor(options = {}) {
296
257
  this.options = options;
297
258
  }
298
- /**
299
- * Generates a DOT string from an ASTNode.
300
- * @param ast The ASTNode to be converted into a DOT string.
301
- * @returns The DOT string generated from the ASTNode.
302
- */
303
259
  print(ast) {
304
260
  const plugins = [...this.#plugins];
305
261
  const { indentSize = 2, indentStyle = 'space', endOfLine = 'lf' } = this.options;
@@ -321,14 +277,6 @@ class Printer {
321
277
  }
322
278
  }
323
279
 
324
- /**
325
- * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
326
- *
327
- * @param ast Graphviz AST node that is to be converted.
328
- * @param options PrintOptions object containing formatting options.
329
- * @returns A string in DOT language.
330
- * @group Convert AST to DOT
331
- */
332
280
  function stringify(ast, options) {
333
281
  const result = new Printer(options).print(ast);
334
282
  if (!result) {
@@ -337,7 +285,6 @@ function stringify(ast, options) {
337
285
  return result;
338
286
  }
339
287
 
340
- /* eslint-disable */
341
288
  function peg$padEnd(str, targetLength, padString) {
342
289
  padString = padString || ' ';
343
290
  if (str.length > targetLength) {
@@ -567,9 +514,7 @@ function peg$parse(input, options) {
567
514
  );
568
515
  };
569
516
  const peg$c21 = function (id, rhs, _children) {
570
- // @ts-ignore
571
517
  return b.createElement(
572
- // @ts-ignore
573
518
  'Edge',
574
519
  {
575
520
  targets: [id, ...rhs],
@@ -5280,9 +5225,6 @@ const parse$1 = peg$parse;
5280
5225
  function parse(input, options) {
5281
5226
  return parse$1(input, options);
5282
5227
  }
5283
- /**
5284
- * @group Convert DOT to AST
5285
- */
5286
5228
  const DotSyntaxError = DotSyntaxError$1;
5287
5229
 
5288
5230
  function convertAttribute(key, value) {
@@ -5588,24 +5530,12 @@ const SubgraphPlugin$1 = {
5588
5530
 
5589
5531
  const defaultPlugins$1 = [AttributeListPlugin, EdgePlugin$1, NodePlugin$1, GraphPlugin$1, SubgraphPlugin$1];
5590
5532
 
5591
- /**
5592
- * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
5593
- *
5594
- * @group Convert Model to AST
5595
- */
5596
5533
  class FromModelConverter {
5597
5534
  options;
5598
- /** @hidden */
5599
5535
  #plugins = [...defaultPlugins$1];
5600
5536
  constructor(options = {}) {
5601
5537
  this.options = options;
5602
5538
  }
5603
- /**
5604
- * Converts a DotObjectModel into an AST.
5605
- *
5606
- * @param model The {@link DotObjectModel} to be converted.
5607
- * @returns The AST generated from the model.
5608
- */
5609
5539
  convert(model) {
5610
5540
  const plugins = [...this.#plugins];
5611
5541
  const { commentKind = 'Slash' } = this.options;
@@ -5624,15 +5554,6 @@ class FromModelConverter {
5624
5554
  }
5625
5555
  }
5626
5556
 
5627
- /**
5628
- * A function used to convert a DotObjectModel into an AST.
5629
- *
5630
- * @param model - The {@link DotObjectModel} to be converted.
5631
- * @param options - An optional {@link ConvertFromModelOptions} object.
5632
- * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
5633
- *
5634
- * @group Convert Model to AST
5635
- */
5636
5557
  function fromModel(model, options) {
5637
5558
  return new FromModelConverter(options).convert(model);
5638
5559
  }
@@ -5808,23 +5729,12 @@ const NodePlugin = {
5808
5729
 
5809
5730
  const defaultPlugins = [NodePlugin, EdgePlugin, SubgraphPlugin, GraphPlugin, DotPlugin];
5810
5731
 
5811
- /**
5812
- * @group Convert AST to Model
5813
- * @alpha
5814
- */
5815
5732
  class ToModelConverter {
5816
5733
  options;
5817
- /** @hidden */
5818
5734
  plugins = [...defaultPlugins];
5819
5735
  constructor(options = {}) {
5820
5736
  this.options = options;
5821
5737
  }
5822
- /**
5823
- * Convert AST to Model.
5824
- *
5825
- * @param ast AST node.
5826
- * @alpha
5827
- */
5828
5738
  convert(ast) {
5829
5739
  const plugins = [...this.plugins];
5830
5740
  const context = {
@@ -5842,10 +5752,6 @@ class ToModelConverter {
5842
5752
  }
5843
5753
  }
5844
5754
 
5845
- /**
5846
- * @group Convert AST to Model
5847
- * @beta
5848
- */
5849
5755
  function toModel(ast, options) {
5850
5756
  return new ToModelConverter(options).convert(ast);
5851
5757
  }
@@ -1,30 +1,23 @@
1
1
  'use strict';
2
2
 
3
- /** @hidden */
4
3
  function isForwardRefNode(object) {
5
4
  return typeof object === 'object' && object !== null && typeof object.id === 'string';
6
5
  }
7
- /** @hidden */
8
6
  function isNodeModel(object) {
9
7
  return typeof object === 'object' && object !== null && object.$$type === 'Node' && typeof object.id === 'string';
10
8
  }
11
- /** @hidden */
12
9
  function isNodeRef(node) {
13
10
  return isNodeModel(node) || isForwardRefNode(node);
14
11
  }
15
- /** @hidden */
16
12
  function isNodeRefLike(node) {
17
13
  return typeof node === 'string' || isNodeRef(node);
18
14
  }
19
- /** @hidden */
20
15
  function isNodeRefGroupLike(target) {
21
16
  return Array.isArray(target) && target.every(isNodeRefLike);
22
17
  }
23
- /** @hidden */
24
18
  function isCompass(c) {
25
19
  return ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'c'].includes(c);
26
20
  }
27
- /** @hidden */
28
21
  function toNodeRef(target) {
29
22
  if (isNodeRef(target)) {
30
23
  return target;
@@ -35,7 +28,6 @@ function toNodeRef(target) {
35
28
  }
36
29
  return { id, port };
37
30
  }
38
- /** @hidden */
39
31
  function toNodeRefGroup(targets) {
40
32
  if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
41
33
  throw Error('EdgeTargets must have at least 2 elements.');
@@ -43,22 +35,13 @@ function toNodeRefGroup(targets) {
43
35
  return targets.map((t) => toNodeRef(t));
44
36
  }
45
37
 
46
- /**
47
- * @group Models Context
48
- * @alpha
49
- */
50
38
  const RootModelsContext = Object.seal({
51
- // NOTE: RootModelsContext is also initialized after the model class is declared in the 'core/index.cjs' module.
52
39
  Graph: null,
53
40
  Digraph: null,
54
41
  Subgraph: null,
55
42
  Node: null,
56
43
  Edge: null,
57
44
  });
58
- /**
59
- * @group Models Context
60
- * @alpha
61
- */
62
45
  function createModelsContext(models) {
63
46
  return Object.assign(Object.seal(Object.assign({}, RootModelsContext)), models);
64
47
  }
@@ -1,28 +1,21 @@
1
- /** @hidden */
2
1
  function isForwardRefNode(object) {
3
2
  return typeof object === 'object' && object !== null && typeof object.id === 'string';
4
3
  }
5
- /** @hidden */
6
4
  function isNodeModel(object) {
7
5
  return typeof object === 'object' && object !== null && object.$$type === 'Node' && typeof object.id === 'string';
8
6
  }
9
- /** @hidden */
10
7
  function isNodeRef(node) {
11
8
  return isNodeModel(node) || isForwardRefNode(node);
12
9
  }
13
- /** @hidden */
14
10
  function isNodeRefLike(node) {
15
11
  return typeof node === 'string' || isNodeRef(node);
16
12
  }
17
- /** @hidden */
18
13
  function isNodeRefGroupLike(target) {
19
14
  return Array.isArray(target) && target.every(isNodeRefLike);
20
15
  }
21
- /** @hidden */
22
16
  function isCompass(c) {
23
17
  return ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'c'].includes(c);
24
18
  }
25
- /** @hidden */
26
19
  function toNodeRef(target) {
27
20
  if (isNodeRef(target)) {
28
21
  return target;
@@ -33,7 +26,6 @@ function toNodeRef(target) {
33
26
  }
34
27
  return { id, port };
35
28
  }
36
- /** @hidden */
37
29
  function toNodeRefGroup(targets) {
38
30
  if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
39
31
  throw Error('EdgeTargets must have at least 2 elements.');
@@ -41,22 +33,13 @@ function toNodeRefGroup(targets) {
41
33
  return targets.map((t) => toNodeRef(t));
42
34
  }
43
35
 
44
- /**
45
- * @group Models Context
46
- * @alpha
47
- */
48
36
  const RootModelsContext = Object.seal({
49
- // NOTE: RootModelsContext is also initialized after the model class is declared in the 'core/index.js' module.
50
37
  Graph: null,
51
38
  Digraph: null,
52
39
  Subgraph: null,
53
40
  Node: null,
54
41
  Edge: null,
55
42
  });
56
- /**
57
- * @group Models Context
58
- * @alpha
59
- */
60
43
  function createModelsContext(models) {
61
44
  return Object.assign(Object.seal(Object.assign({}, RootModelsContext)), models);
62
45
  }
@@ -3,25 +3,13 @@
3
3
  var index_js = require('../common/index.cjs');
4
4
  var index_js$1 = require('../ast/index.cjs');
5
5
 
6
- /**
7
- * @group Attribute
8
- */
9
6
  const attribute = new Proxy(Object.freeze({}), {
10
7
  get: (_, key) => key,
11
8
  });
12
9
 
13
- /**
14
- * Base class for DOT objects.
15
- * @group Models
16
- */
17
10
  class DotObject {}
18
11
 
19
- /**
20
- * Base class for DOT objects with attributes.
21
- * @group Models
22
- */
23
12
  class AttributesBase extends DotObject {
24
- /** @hidden */
25
13
  #attrs = new Map();
26
14
  constructor(attributes) {
27
15
  super();
@@ -57,10 +45,6 @@ class AttributesBase extends DotObject {
57
45
  }
58
46
  }
59
47
 
60
- /**
61
- * A set of attribute values for any object.
62
- * @group Models
63
- */
64
48
  class AttributeList extends AttributesBase {
65
49
  $$kind;
66
50
  get $$type() {
@@ -73,12 +57,7 @@ class AttributeList extends AttributesBase {
73
57
  }
74
58
  }
75
59
 
76
- /**
77
- * Base class for Graph objects.
78
- * @group Models
79
- */
80
60
  class GraphBase extends AttributesBase {
81
- /** @hidden */
82
61
  #models = index_js.RootModelsContext;
83
62
  id;
84
63
  comment;
@@ -96,7 +75,6 @@ class GraphBase extends AttributesBase {
96
75
  get subgraphs() {
97
76
  return Array.from(this.#objects.subgraphs.values());
98
77
  }
99
- /** @hidden */
100
78
  #objects = {
101
79
  nodes: new Map(),
102
80
  edges: new Set(),
@@ -208,10 +186,6 @@ class GraphBase extends AttributesBase {
208
186
  }
209
187
  }
210
188
 
211
- /**
212
- * Base class representing a root graph(digraph, graph).
213
- * @group Models
214
- */
215
189
  class RootGraph extends GraphBase {
216
190
  get $$type() {
217
191
  return 'Graph';
@@ -229,30 +203,18 @@ class RootGraph extends GraphBase {
229
203
  }
230
204
  }
231
205
 
232
- /**
233
- * DOT object class representing a digraph.
234
- * @group Models
235
- */
236
206
  class Digraph extends RootGraph {
237
207
  get directed() {
238
208
  return true;
239
209
  }
240
210
  }
241
211
 
242
- /**
243
- * DOT object class representing a graph.
244
- * @group Models
245
- */
246
212
  class Graph extends RootGraph {
247
213
  get directed() {
248
214
  return false;
249
215
  }
250
216
  }
251
217
 
252
- /**
253
- * DOT object class representing a subgraph.
254
- * @group Models
255
- */
256
218
  class Subgraph extends GraphBase {
257
219
  get $$type() {
258
220
  return 'Subgraph';
@@ -274,18 +236,10 @@ class Subgraph extends GraphBase {
274
236
  }
275
237
  }
276
238
 
277
- /**
278
- * A set of attribute values for any object.
279
- * @group Models
280
- */
281
239
  class AttributesGroup extends AttributesBase {
282
240
  comment;
283
241
  }
284
242
 
285
- /**
286
- * DOT object class representing a node.
287
- * @group Models
288
- */
289
243
  class Node extends DotObject {
290
244
  id;
291
245
  get $$type() {
@@ -306,10 +260,6 @@ class Node extends DotObject {
306
260
  }
307
261
  }
308
262
 
309
- /**
310
- * DOT object class representing a edge.
311
- * @group Models
312
- */
313
263
  class Edge extends DotObject {
314
264
  targets;
315
265
  get $$type() {
@@ -335,14 +285,6 @@ Object.assign(index_js.RootModelsContext, {
335
285
  Edge,
336
286
  });
337
287
 
338
- /**
339
- * ModelFactoryBuilder is a function that takes two parameters, directed and strictMode, and returns a ModelFactory.
340
- *
341
- * @param directed A boolean value indicating whether the graph should be directed or not.
342
- * @param strictMode A boolean value indicating whether the graph should be in strict mode or not.
343
- * @returns A ModelFactory that takes an array of unknowns as parameters and returns a RootGraphModel.
344
- * @hidden
345
- */
346
288
  function ModelFactoryBuilder(directed, strictMode) {
347
289
  return (...args) => {
348
290
  const G = directed ? this.Digraph : this.Graph;
@@ -357,13 +299,6 @@ function ModelFactoryBuilder(directed, strictMode) {
357
299
  return g;
358
300
  };
359
301
  }
360
- /**
361
- * createModelFactories is a function that takes a boolean value, strict, and an optional ModelsContext parameter, context, and returns an object containing two ModelFactories.
362
- *
363
- * @param strict A boolean value indicating whether the graph should be in strict mode or not.
364
- * @param context An optional ModelsContext parameter.
365
- * @returns An object containing two ModelFactories, one for directed graphs and one for undirected graphs.
366
- */
367
302
  function createModelFactories(strict, context = index_js.RootModelsContext) {
368
303
  return Object.freeze({
369
304
  digraph: ModelFactoryBuilder.call(context, true, strict),
@@ -372,28 +307,9 @@ function createModelFactories(strict, context = index_js.RootModelsContext) {
372
307
  }
373
308
 
374
309
  const noStrict = createModelFactories(false);
375
- /**
376
- * digraph is a factory for creating Digraph objects.
377
- * @group Model Factory
378
- */
379
310
  const digraph = noStrict.digraph;
380
- /**
381
- * graph is a factory for creating Graph objects.
382
- * @group Model Factory
383
- */
384
311
  const graph = noStrict.graph;
385
- /**
386
- * Provides a strict mode API.
387
- * @group Model Factory
388
- */
389
312
  const strict = createModelFactories(true);
390
- /**
391
- * withContext creates a {@link ModelFactoriesWithStrict} object with the given context.
392
- *
393
- * @param models - An object containing the models to be used in the context.
394
- *
395
- * @returns A ModelFactoriesWithStrict object containing the factories. * @group Model Factory
396
- */
397
313
  function withContext(models) {
398
314
  const context = index_js.createModelsContext(models);
399
315
  return Object.freeze({
@@ -402,15 +318,6 @@ function withContext(models) {
402
318
  });
403
319
  }
404
320
 
405
- /**
406
- * Convert Model to DOT string.
407
- *
408
- * @group Convert Model to DOT
409
- *
410
- * @param model Dot Object Model, like {@link Digraph}, {@link Graph}, {@link Subgraph}, {@link Node}, and {@link Edge}
411
- * @param options Optional options for the conversion.
412
- * @returns DOT string
413
- */
414
321
  function toDot(model, options) {
415
322
  const ast = index_js$1.fromModel(model, options?.convert);
416
323
  return index_js$1.stringify(ast, options?.print);
package/lib/core/index.js CHANGED
@@ -8,25 +8,13 @@ import {
8
8
  } from '../common/index.js';
9
9
  import { fromModel, stringify, parse, toModel } from '../ast/index.js';
10
10
 
11
- /**
12
- * @group Attribute
13
- */
14
11
  const attribute = new Proxy(Object.freeze({}), {
15
12
  get: (_, key) => key,
16
13
  });
17
14
 
18
- /**
19
- * Base class for DOT objects.
20
- * @group Models
21
- */
22
15
  class DotObject {}
23
16
 
24
- /**
25
- * Base class for DOT objects with attributes.
26
- * @group Models
27
- */
28
17
  class AttributesBase extends DotObject {
29
- /** @hidden */
30
18
  #attrs = new Map();
31
19
  constructor(attributes) {
32
20
  super();
@@ -62,10 +50,6 @@ class AttributesBase extends DotObject {
62
50
  }
63
51
  }
64
52
 
65
- /**
66
- * A set of attribute values for any object.
67
- * @group Models
68
- */
69
53
  class AttributeList extends AttributesBase {
70
54
  $$kind;
71
55
  get $$type() {
@@ -78,12 +62,7 @@ class AttributeList extends AttributesBase {
78
62
  }
79
63
  }
80
64
 
81
- /**
82
- * Base class for Graph objects.
83
- * @group Models
84
- */
85
65
  class GraphBase extends AttributesBase {
86
- /** @hidden */
87
66
  #models = RootModelsContext;
88
67
  id;
89
68
  comment;
@@ -101,7 +80,6 @@ class GraphBase extends AttributesBase {
101
80
  get subgraphs() {
102
81
  return Array.from(this.#objects.subgraphs.values());
103
82
  }
104
- /** @hidden */
105
83
  #objects = {
106
84
  nodes: new Map(),
107
85
  edges: new Set(),
@@ -211,10 +189,6 @@ class GraphBase extends AttributesBase {
211
189
  }
212
190
  }
213
191
 
214
- /**
215
- * Base class representing a root graph(digraph, graph).
216
- * @group Models
217
- */
218
192
  class RootGraph extends GraphBase {
219
193
  get $$type() {
220
194
  return 'Graph';
@@ -232,30 +206,18 @@ class RootGraph extends GraphBase {
232
206
  }
233
207
  }
234
208
 
235
- /**
236
- * DOT object class representing a digraph.
237
- * @group Models
238
- */
239
209
  class Digraph extends RootGraph {
240
210
  get directed() {
241
211
  return true;
242
212
  }
243
213
  }
244
214
 
245
- /**
246
- * DOT object class representing a graph.
247
- * @group Models
248
- */
249
215
  class Graph extends RootGraph {
250
216
  get directed() {
251
217
  return false;
252
218
  }
253
219
  }
254
220
 
255
- /**
256
- * DOT object class representing a subgraph.
257
- * @group Models
258
- */
259
221
  class Subgraph extends GraphBase {
260
222
  get $$type() {
261
223
  return 'Subgraph';
@@ -277,18 +239,10 @@ class Subgraph extends GraphBase {
277
239
  }
278
240
  }
279
241
 
280
- /**
281
- * A set of attribute values for any object.
282
- * @group Models
283
- */
284
242
  class AttributesGroup extends AttributesBase {
285
243
  comment;
286
244
  }
287
245
 
288
- /**
289
- * DOT object class representing a node.
290
- * @group Models
291
- */
292
246
  class Node extends DotObject {
293
247
  id;
294
248
  get $$type() {
@@ -309,10 +263,6 @@ class Node extends DotObject {
309
263
  }
310
264
  }
311
265
 
312
- /**
313
- * DOT object class representing a edge.
314
- * @group Models
315
- */
316
266
  class Edge extends DotObject {
317
267
  targets;
318
268
  get $$type() {
@@ -338,14 +288,6 @@ Object.assign(RootModelsContext, {
338
288
  Edge,
339
289
  });
340
290
 
341
- /**
342
- * ModelFactoryBuilder is a function that takes two parameters, directed and strictMode, and returns a ModelFactory.
343
- *
344
- * @param directed A boolean value indicating whether the graph should be directed or not.
345
- * @param strictMode A boolean value indicating whether the graph should be in strict mode or not.
346
- * @returns A ModelFactory that takes an array of unknowns as parameters and returns a RootGraphModel.
347
- * @hidden
348
- */
349
291
  function ModelFactoryBuilder(directed, strictMode) {
350
292
  return (...args) => {
351
293
  const G = directed ? this.Digraph : this.Graph;
@@ -360,13 +302,6 @@ function ModelFactoryBuilder(directed, strictMode) {
360
302
  return g;
361
303
  };
362
304
  }
363
- /**
364
- * createModelFactories is a function that takes a boolean value, strict, and an optional ModelsContext parameter, context, and returns an object containing two ModelFactories.
365
- *
366
- * @param strict A boolean value indicating whether the graph should be in strict mode or not.
367
- * @param context An optional ModelsContext parameter.
368
- * @returns An object containing two ModelFactories, one for directed graphs and one for undirected graphs.
369
- */
370
305
  function createModelFactories(strict, context = RootModelsContext) {
371
306
  return Object.freeze({
372
307
  digraph: ModelFactoryBuilder.call(context, true, strict),
@@ -375,28 +310,9 @@ function createModelFactories(strict, context = RootModelsContext) {
375
310
  }
376
311
 
377
312
  const noStrict = createModelFactories(false);
378
- /**
379
- * digraph is a factory for creating Digraph objects.
380
- * @group Model Factory
381
- */
382
313
  const digraph = noStrict.digraph;
383
- /**
384
- * graph is a factory for creating Graph objects.
385
- * @group Model Factory
386
- */
387
314
  const graph = noStrict.graph;
388
- /**
389
- * Provides a strict mode API.
390
- * @group Model Factory
391
- */
392
315
  const strict = createModelFactories(true);
393
- /**
394
- * withContext creates a {@link ModelFactoriesWithStrict} object with the given context.
395
- *
396
- * @param models - An object containing the models to be used in the context.
397
- *
398
- * @returns A ModelFactoriesWithStrict object containing the factories. * @group Model Factory
399
- */
400
316
  function withContext(models) {
401
317
  const context = createModelsContext(models);
402
318
  return Object.freeze({
@@ -405,15 +321,6 @@ function withContext(models) {
405
321
  });
406
322
  }
407
323
 
408
- /**
409
- * Convert Model to DOT string.
410
- *
411
- * @group Convert Model to DOT
412
- *
413
- * @param model Dot Object Model, like {@link Digraph}, {@link Graph}, {@link Subgraph}, {@link Node}, and {@link Edge}
414
- * @param options Optional options for the conversion.
415
- * @returns DOT string
416
- */
417
324
  function toDot(model, options) {
418
325
  const ast = fromModel(model, options?.convert);
419
326
  return stringify(ast, options?.print);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-graphviz",
3
- "version": "1.5.5-dev.02afc3340",
3
+ "version": "1.5.5-dev.27273c787",
4
4
  "author": "kamiazya <yuki@kamiazya.tech>",
5
5
  "description": "Graphviz library for TypeScript.",
6
6
  "homepage": "https://ts-graphviz.github.io/ts-graphviz/",
@@ -86,7 +86,7 @@
86
86
  "build:peggy": "peggy --plugin ts-pegjs --extra-options-file src/ast/dot-shim/parser/peggy.options.json -o src/ast/dot-shim/parser/_parse.ts src/ast/dot-shim/parser/dot.peggy",
87
87
  "prebuild": "yarn build:peggy",
88
88
  "build:deno": "mkdir -p lib/adapter/deno && cp -r src/adapter/deno/* lib/adapter/deno && sed -i \"s/index.ts/index.js/g\" lib/adapter/deno/mod.js && sed -i \"s/index.ts/index.d.ts/g\" lib/adapter/deno/mod.d.ts",
89
- "build:node": "tsc -p tsconfig.build.json && rollup -c",
89
+ "build:node": "tsc -p tsconfig.build.json --declaration && tsc -p tsconfig.build.json --removeComments && rollup -c",
90
90
  "build": "yarn build:node && yarn build:deno",
91
91
  "postbuild": "prettier --write ./lib/**/*.{js,cjs,d.ts}",
92
92
  "pretest": "yarn build:peggy",