ts-graphviz 1.5.5-dev.bdbba8a60 → 1.5.5
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.
- package/README.md +1 -0
- package/lib/adapter/browser/index.cjs +0 -11
- package/lib/adapter/browser/index.js +0 -11
- package/lib/adapter/deno/mod.js +2 -2
- package/lib/adapter/node/index.cjs +1 -13
- package/lib/adapter/node/index.js +2 -14
- package/lib/adapter/types/index.d.ts +15 -0
- package/lib/adapter/utils/index.cjs +5 -4
- package/lib/adapter/utils/index.d.ts +8 -2
- package/lib/adapter/utils/index.js +5 -4
- package/lib/ast/index.cjs +0 -47
- package/lib/ast/index.d.ts +328 -17
- package/lib/ast/index.js +0 -47
- package/lib/common/index.cjs +0 -17
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.js +0 -17
- package/lib/core/index.cjs +0 -75
- package/lib/core/index.d.ts +35 -9
- package/lib/core/index.js +0 -75
- package/package.json +120 -120
package/README.md
CHANGED
|
@@ -545,6 +545,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
545
545
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/murawakimitsuhiro"><img src="https://avatars.githubusercontent.com/u/13833242?v=4?s=100" width="100px;" alt="mrwk"/><br /><sub><b>mrwk</b></sub></a><br /><a href="#question-murawakimitsuhiro" title="Answering Questions">💬</a></td>
|
|
546
546
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/svdvonde"><img src="https://avatars.githubusercontent.com/u/2751783?v=4?s=100" width="100px;" alt="svdvonde"/><br /><sub><b>svdvonde</b></sub></a><br /><a href="#question-svdvonde" title="Answering Questions">💬</a></td>
|
|
547
547
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/seethroughdev"><img src="https://avatars.githubusercontent.com/u/203779?v=4?s=100" width="100px;" alt="Adam"/><br /><sub><b>Adam</b></sub></a><br /><a href="#question-seethroughdev" title="Answering Questions">💬</a></td>
|
|
548
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/trevor-scheer"><img src="https://avatars.githubusercontent.com/u/29644393?v=4?s=100" width="100px;" alt="Trevor Scheer"/><br /><sub><b>Trevor Scheer</b></sub></a><br /><a href="#a11y-trevor-scheer" title="Accessibility">️️️️♿️</a></td>
|
|
548
549
|
</tr>
|
|
549
550
|
</tbody>
|
|
550
551
|
</table>
|
|
@@ -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
|
}
|
package/lib/adapter/deno/mod.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createCommandAndArgs } from '../utils/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
4
4
|
*/
|
|
5
5
|
export async function toStream(dot, options) {
|
|
6
|
-
const [command, args] =
|
|
6
|
+
const [command, args] = createCommandAndArgs(options);
|
|
7
7
|
const cp = new Deno.Command(command, {
|
|
8
8
|
args: args,
|
|
9
9
|
stdin: 'piped',
|
|
@@ -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
|
-
const [command, args] = index_js.
|
|
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));
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { pipeline as pipeline$1, PassThrough, Readable } from 'node:stream';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
-
import {
|
|
3
|
+
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
|
-
const [command, args] =
|
|
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));
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
|
|
8
8
|
type Format = 'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json';
|
|
9
9
|
type Layout = 'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork';
|
|
10
|
+
/**
|
|
11
|
+
* NeatoOptions interface provides options for the neato layout.
|
|
12
|
+
*/
|
|
10
13
|
interface NeatoOptions {
|
|
11
14
|
layout: 'neato';
|
|
12
15
|
/**
|
|
@@ -18,6 +21,9 @@ interface NeatoOptions {
|
|
|
18
21
|
*/
|
|
19
22
|
reduce?: boolean;
|
|
20
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* FdpOptions interface provides options for the fdp layout.
|
|
26
|
+
*/
|
|
21
27
|
interface FdpOptions {
|
|
22
28
|
layout: 'fdp';
|
|
23
29
|
/**
|
|
@@ -49,6 +55,12 @@ interface FdpOptions {
|
|
|
49
55
|
*/
|
|
50
56
|
temperature?: number;
|
|
51
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @description
|
|
60
|
+
* This interface describes an optional parameter called "layout" which is used to set a layout engine.
|
|
61
|
+
* The default value for this parameter is 'dot', and it must be an option of the Layout type,
|
|
62
|
+
* excluding 'neato' and 'fdp'.
|
|
63
|
+
*/
|
|
52
64
|
interface OtherOptions {
|
|
53
65
|
/**
|
|
54
66
|
* Set layout engine.
|
|
@@ -57,6 +69,9 @@ interface OtherOptions {
|
|
|
57
69
|
*/
|
|
58
70
|
layout?: Exclude<Layout, 'neato' | 'fdp'>;
|
|
59
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* This interface represents the CommonOptions for setting output format.
|
|
74
|
+
*/
|
|
60
75
|
interface CommonOptions {
|
|
61
76
|
/**
|
|
62
77
|
* Set output format.
|
|
@@ -10,7 +10,7 @@ function escapeValue(value) {
|
|
|
10
10
|
}
|
|
11
11
|
return '';
|
|
12
12
|
}
|
|
13
|
-
function*
|
|
13
|
+
function* createCommandArgs(options) {
|
|
14
14
|
const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
|
|
15
15
|
if (suppressWarnings) yield '-q';
|
|
16
16
|
yield `-T${format}`;
|
|
@@ -50,8 +50,9 @@ function* args(options) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
|
|
54
|
+
function createCommandAndArgs(options) {
|
|
55
|
+
return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
exports.
|
|
58
|
+
exports.createCommandAndArgs = createCommandAndArgs;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Layout, Options } from '../types/index.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
|
|
5
|
+
*
|
|
6
|
+
* @param options Options to create the command and args from.
|
|
7
|
+
* @returns A tuple containing the command and an array of arguments.
|
|
8
|
+
*/
|
|
9
|
+
declare function createCommandAndArgs<T extends Layout>(options: Options<T>): [command: string, args: string[]];
|
|
4
10
|
|
|
5
|
-
export {
|
|
11
|
+
export { createCommandAndArgs };
|
|
@@ -8,7 +8,7 @@ function escapeValue(value) {
|
|
|
8
8
|
}
|
|
9
9
|
return '';
|
|
10
10
|
}
|
|
11
|
-
function*
|
|
11
|
+
function* createCommandArgs(options) {
|
|
12
12
|
const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
|
|
13
13
|
if (suppressWarnings) yield '-q';
|
|
14
14
|
yield `-T${format}`;
|
|
@@ -48,8 +48,9 @@ function* args(options) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
|
|
52
|
+
function createCommandAndArgs(options) {
|
|
53
|
+
return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
export {
|
|
56
|
+
export { createCommandAndArgs };
|
package/lib/ast/index.cjs
CHANGED
|
@@ -3,19 +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
|
-
* @group Create AST
|
|
8
|
-
*/
|
|
9
6
|
class Builder {
|
|
10
7
|
options;
|
|
11
|
-
/** @internal */
|
|
12
8
|
getLocation() {
|
|
13
9
|
return this.options?.locationFunction?.() ?? null;
|
|
14
10
|
}
|
|
15
11
|
constructor(options) {
|
|
16
12
|
this.options = options;
|
|
17
13
|
}
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
14
|
createElement(type, props, children) {
|
|
20
15
|
return {
|
|
21
16
|
...props,
|
|
@@ -26,9 +21,6 @@ class Builder {
|
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
/**
|
|
30
|
-
* @group Create AST
|
|
31
|
-
*/
|
|
32
24
|
const createElement = Builder.prototype.createElement.bind(new Builder());
|
|
33
25
|
|
|
34
26
|
const EOL = /\r?\n/;
|
|
@@ -265,12 +257,8 @@ const defaultPlugins$2 = [
|
|
|
265
257
|
SubgraphPrintPlugin,
|
|
266
258
|
];
|
|
267
259
|
|
|
268
|
-
/**
|
|
269
|
-
* @group Convert AST to DOT
|
|
270
|
-
*/
|
|
271
260
|
class Printer {
|
|
272
261
|
options;
|
|
273
|
-
/** @internal */
|
|
274
262
|
#plugins = [...defaultPlugins$2];
|
|
275
263
|
constructor(options = {}) {
|
|
276
264
|
this.options = options;
|
|
@@ -296,13 +284,6 @@ class Printer {
|
|
|
296
284
|
}
|
|
297
285
|
}
|
|
298
286
|
|
|
299
|
-
/**
|
|
300
|
-
* Stringify Graphviz AST Node.
|
|
301
|
-
*
|
|
302
|
-
* @param ast Graphviz AST node.
|
|
303
|
-
* @returns DOT language string.
|
|
304
|
-
* @group Convert AST to DOT
|
|
305
|
-
*/
|
|
306
287
|
function stringify(ast, options) {
|
|
307
288
|
const result = new Printer(options).print(ast);
|
|
308
289
|
if (!result) {
|
|
@@ -311,7 +292,6 @@ function stringify(ast, options) {
|
|
|
311
292
|
return result;
|
|
312
293
|
}
|
|
313
294
|
|
|
314
|
-
/* eslint-disable */
|
|
315
295
|
function peg$padEnd(str, targetLength, padString) {
|
|
316
296
|
padString = padString || ' ';
|
|
317
297
|
if (str.length > targetLength) {
|
|
@@ -541,9 +521,7 @@ function peg$parse(input, options) {
|
|
|
541
521
|
);
|
|
542
522
|
};
|
|
543
523
|
const peg$c21 = function (id, rhs, _children) {
|
|
544
|
-
// @ts-ignore
|
|
545
524
|
return b.createElement(
|
|
546
|
-
// @ts-ignore
|
|
547
525
|
'Edge',
|
|
548
526
|
{
|
|
549
527
|
targets: [id, ...rhs],
|
|
@@ -5254,9 +5232,6 @@ const parse$1 = peg$parse;
|
|
|
5254
5232
|
function parse(input, options) {
|
|
5255
5233
|
return parse$1(input, options);
|
|
5256
5234
|
}
|
|
5257
|
-
/**
|
|
5258
|
-
* @group Convert DOT to AST
|
|
5259
|
-
*/
|
|
5260
5235
|
const DotSyntaxError = DotSyntaxError$1;
|
|
5261
5236
|
|
|
5262
5237
|
function convertAttribute(key, value) {
|
|
@@ -5562,12 +5537,8 @@ const SubgraphPlugin$1 = {
|
|
|
5562
5537
|
|
|
5563
5538
|
const defaultPlugins$1 = [AttributeListPlugin, EdgePlugin$1, NodePlugin$1, GraphPlugin$1, SubgraphPlugin$1];
|
|
5564
5539
|
|
|
5565
|
-
/**
|
|
5566
|
-
* @group Convert Model to AST
|
|
5567
|
-
*/
|
|
5568
5540
|
class FromModelConverter {
|
|
5569
5541
|
options;
|
|
5570
|
-
/** @hidden */
|
|
5571
5542
|
#plugins = [...defaultPlugins$1];
|
|
5572
5543
|
constructor(options = {}) {
|
|
5573
5544
|
this.options = options;
|
|
@@ -5590,9 +5561,6 @@ class FromModelConverter {
|
|
|
5590
5561
|
}
|
|
5591
5562
|
}
|
|
5592
5563
|
|
|
5593
|
-
/**
|
|
5594
|
-
* @group Convert Model to AST
|
|
5595
|
-
*/
|
|
5596
5564
|
function fromModel(model, options) {
|
|
5597
5565
|
return new FromModelConverter(options).convert(model);
|
|
5598
5566
|
}
|
|
@@ -5768,23 +5736,12 @@ const NodePlugin = {
|
|
|
5768
5736
|
|
|
5769
5737
|
const defaultPlugins = [NodePlugin, EdgePlugin, SubgraphPlugin, GraphPlugin, DotPlugin];
|
|
5770
5738
|
|
|
5771
|
-
/**
|
|
5772
|
-
* @group Convert AST to Model
|
|
5773
|
-
* @alpha
|
|
5774
|
-
*/
|
|
5775
5739
|
class ToModelConverter {
|
|
5776
5740
|
options;
|
|
5777
|
-
/** @hidden */
|
|
5778
5741
|
plugins = [...defaultPlugins];
|
|
5779
5742
|
constructor(options = {}) {
|
|
5780
5743
|
this.options = options;
|
|
5781
5744
|
}
|
|
5782
|
-
/**
|
|
5783
|
-
* Convert AST to Model.
|
|
5784
|
-
*
|
|
5785
|
-
* @param ast AST node.
|
|
5786
|
-
* @alpha
|
|
5787
|
-
*/
|
|
5788
5745
|
convert(ast) {
|
|
5789
5746
|
const plugins = [...this.plugins];
|
|
5790
5747
|
const context = {
|
|
@@ -5802,10 +5759,6 @@ class ToModelConverter {
|
|
|
5802
5759
|
}
|
|
5803
5760
|
}
|
|
5804
5761
|
|
|
5805
|
-
/**
|
|
5806
|
-
* @group Convert AST to Model
|
|
5807
|
-
* @beta
|
|
5808
|
-
*/
|
|
5809
5762
|
function toModel(ast, options) {
|
|
5810
5763
|
return new ToModelConverter(options).convert(ast);
|
|
5811
5764
|
}
|