@ts-graphviz/adapter 0.0.0-pr956-20240225073457
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/CHANGELOG.md +12 -0
- package/LICENSE +22 -0
- package/README.md +37 -0
- package/lib/browser.cjs +14 -0
- package/lib/browser.d.ts +12 -0
- package/lib/browser.js +9 -0
- package/lib/create-command-and-args.cjs +87 -0
- package/lib/create-command-and-args.d.ts +8 -0
- package/lib/create-command-and-args.js +83 -0
- package/lib/create-command-args.d.ts +18 -0
- package/lib/deno.d.ts +12 -0
- package/lib/deno.js +31 -0
- package/lib/node.cjs +55 -0
- package/lib/node.d.ts +6 -0
- package/lib/node.js +50 -0
- package/lib/to-file.node.d.ts +5 -0
- package/lib/to-stream.node.d.ts +6 -0
- package/lib/types.d.ts +127 -0
- package/package.json +56 -0
- package/src/browser.ts +19 -0
- package/src/create-command-and-args.test.ts +63 -0
- package/src/create-command-and-args.ts +14 -0
- package/src/create-command-args.test.ts +100 -0
- package/src/create-command-args.ts +90 -0
- package/src/deno.ts +49 -0
- package/src/node.ts +6 -0
- package/src/to-file.node.ts +16 -0
- package/src/to-stream.node.ts +50 -0
- package/src/types.ts +166 -0
- package/tsconfig.browser.json +13 -0
- package/tsconfig.deno.json +13 -0
- package/tsconfig.node.json +13 -0
- package/typedoc.json +4 -0
- package/types/deno.d.ts +20 -0
- package/vite.config.ts +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @ts-graphviz/adapter
|
|
2
|
+
|
|
3
|
+
## 0.0.0-pr956-20240225073457
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24) Thanks [@kamiazya](https://github.com/kamiazya)! - Release v2.0.0
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24)]:
|
|
12
|
+
- @ts-graphviz/common@0.0.0-pr956-20240225073457
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2019-2024 Yuki Yamazaki
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @ts-graphviz/adapter
|
|
2
|
+
|
|
3
|
+
This package contains runtime-dependent processing for the ts-graphviz library, such as I/O processing.
|
|
4
|
+
|
|
5
|
+
It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Runtime-specific I/O processing
|
|
10
|
+
- Adapter function implementations for various environments, such as Node.js, Deno and browser(not implemented)
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
Import the necessary classes and functions from the @ts-graphviz/adapter package:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { } from '@ts-graphviz/adapter';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use the imported items in your project to work with ts-graphviz in different runtime environments:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// TODO
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For more examples and usage details, please refer to the ts-graphviz documentation.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
Contributions to the ts-graphviz project are welcome.
|
|
32
|
+
|
|
33
|
+
Please refer to the main ts-graphviz repository for guidelines on how to contribute.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
This package is released under the MIT License.
|
package/lib/browser.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const ERROR_MESSAGE = "This module cannot be run in a browser.";
|
|
6
|
+
function toStream(dot, options) {
|
|
7
|
+
throw new Error(ERROR_MESSAGE);
|
|
8
|
+
}
|
|
9
|
+
function toFile(dot, path, options) {
|
|
10
|
+
throw new Error(ERROR_MESSAGE);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.toFile = toFile;
|
|
14
|
+
exports.toStream = toStream;
|
package/lib/browser.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @ts-graphviz/adapter
|
|
3
|
+
*/
|
|
4
|
+
export type Options = any;
|
|
5
|
+
/**
|
|
6
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toStream(dot: string, options?: Options): never;
|
|
9
|
+
/**
|
|
10
|
+
* Execute the Graphviz dot command and output the results to a file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toFile(dot: string, path: string, options?: Options): never;
|
package/lib/browser.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
function escapeValue(value) {
|
|
6
|
+
if (value !== true) {
|
|
7
|
+
if (typeof value === "string" && /\s/g.test(value)) {
|
|
8
|
+
return `="${value}"`;
|
|
9
|
+
}
|
|
10
|
+
return `=${value}`;
|
|
11
|
+
}
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
function* createCommandArgs(options) {
|
|
15
|
+
const {
|
|
16
|
+
suppressWarnings = true,
|
|
17
|
+
format = "svg",
|
|
18
|
+
attributes = {},
|
|
19
|
+
library = [],
|
|
20
|
+
y = false,
|
|
21
|
+
scale
|
|
22
|
+
} = options;
|
|
23
|
+
if (suppressWarnings)
|
|
24
|
+
yield "-q";
|
|
25
|
+
yield `-T${format}`;
|
|
26
|
+
if (attributes.graph) {
|
|
27
|
+
for (const [key, value] of Object.entries(attributes.graph)) {
|
|
28
|
+
yield `-G${key}${escapeValue(value)}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (attributes.node) {
|
|
32
|
+
for (const [key, value] of Object.entries(attributes.node)) {
|
|
33
|
+
yield `-N${key}${escapeValue(value)}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (attributes.edge) {
|
|
37
|
+
for (const [key, value] of Object.entries(attributes.edge)) {
|
|
38
|
+
yield `-E${key}${escapeValue(value)}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (typeof scale === "number" && !Number.isNaN(scale))
|
|
42
|
+
yield `-s${scale}`;
|
|
43
|
+
if (Array.isArray(library))
|
|
44
|
+
for (const lib of library)
|
|
45
|
+
yield `-l${lib}`;
|
|
46
|
+
if (y === true)
|
|
47
|
+
yield "-y";
|
|
48
|
+
if (typeof options.layout === "string") {
|
|
49
|
+
yield `-K${options.layout}`;
|
|
50
|
+
switch (options.layout) {
|
|
51
|
+
case "neato": {
|
|
52
|
+
const { reduce, noop } = options;
|
|
53
|
+
if (reduce === true)
|
|
54
|
+
yield "-x";
|
|
55
|
+
if (typeof noop === "number")
|
|
56
|
+
yield `-n${noop}`;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "fdp": {
|
|
60
|
+
const {
|
|
61
|
+
grid,
|
|
62
|
+
oldAttractive,
|
|
63
|
+
iterations,
|
|
64
|
+
unscaledFactor,
|
|
65
|
+
overlapExpansionFactor,
|
|
66
|
+
temperature
|
|
67
|
+
} = options;
|
|
68
|
+
yield ["-L", grid ? "" : "g", oldAttractive ? "O" : ""].join("");
|
|
69
|
+
if (typeof iterations === "number")
|
|
70
|
+
yield `-Ln${iterations}`;
|
|
71
|
+
if (typeof unscaledFactor === "number")
|
|
72
|
+
yield `-LU${unscaledFactor}`;
|
|
73
|
+
if (typeof overlapExpansionFactor === "number")
|
|
74
|
+
yield `-LC${overlapExpansionFactor}`;
|
|
75
|
+
if (typeof temperature === "number")
|
|
76
|
+
yield `-LT${temperature}`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function createCommandAndArgs(options) {
|
|
84
|
+
return [options.dotCommand ?? "dot", Array.from(createCommandArgs(options))];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.createCommandAndArgs = createCommandAndArgs;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Layout, Options } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
|
|
4
|
+
*
|
|
5
|
+
* @param options Options to create the command and args from.
|
|
6
|
+
* @returns A tuple containing the command and an array of arguments.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createCommandAndArgs<T extends Layout>(options: Options<T>): [command: string, args: string[]];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
function escapeValue(value) {
|
|
2
|
+
if (value !== true) {
|
|
3
|
+
if (typeof value === "string" && /\s/g.test(value)) {
|
|
4
|
+
return `="${value}"`;
|
|
5
|
+
}
|
|
6
|
+
return `=${value}`;
|
|
7
|
+
}
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
function* createCommandArgs(options) {
|
|
11
|
+
const {
|
|
12
|
+
suppressWarnings = true,
|
|
13
|
+
format = "svg",
|
|
14
|
+
attributes = {},
|
|
15
|
+
library = [],
|
|
16
|
+
y = false,
|
|
17
|
+
scale
|
|
18
|
+
} = options;
|
|
19
|
+
if (suppressWarnings)
|
|
20
|
+
yield "-q";
|
|
21
|
+
yield `-T${format}`;
|
|
22
|
+
if (attributes.graph) {
|
|
23
|
+
for (const [key, value] of Object.entries(attributes.graph)) {
|
|
24
|
+
yield `-G${key}${escapeValue(value)}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (attributes.node) {
|
|
28
|
+
for (const [key, value] of Object.entries(attributes.node)) {
|
|
29
|
+
yield `-N${key}${escapeValue(value)}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (attributes.edge) {
|
|
33
|
+
for (const [key, value] of Object.entries(attributes.edge)) {
|
|
34
|
+
yield `-E${key}${escapeValue(value)}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (typeof scale === "number" && !Number.isNaN(scale))
|
|
38
|
+
yield `-s${scale}`;
|
|
39
|
+
if (Array.isArray(library))
|
|
40
|
+
for (const lib of library)
|
|
41
|
+
yield `-l${lib}`;
|
|
42
|
+
if (y === true)
|
|
43
|
+
yield "-y";
|
|
44
|
+
if (typeof options.layout === "string") {
|
|
45
|
+
yield `-K${options.layout}`;
|
|
46
|
+
switch (options.layout) {
|
|
47
|
+
case "neato": {
|
|
48
|
+
const { reduce, noop } = options;
|
|
49
|
+
if (reduce === true)
|
|
50
|
+
yield "-x";
|
|
51
|
+
if (typeof noop === "number")
|
|
52
|
+
yield `-n${noop}`;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "fdp": {
|
|
56
|
+
const {
|
|
57
|
+
grid,
|
|
58
|
+
oldAttractive,
|
|
59
|
+
iterations,
|
|
60
|
+
unscaledFactor,
|
|
61
|
+
overlapExpansionFactor,
|
|
62
|
+
temperature
|
|
63
|
+
} = options;
|
|
64
|
+
yield ["-L", grid ? "" : "g", oldAttractive ? "O" : ""].join("");
|
|
65
|
+
if (typeof iterations === "number")
|
|
66
|
+
yield `-Ln${iterations}`;
|
|
67
|
+
if (typeof unscaledFactor === "number")
|
|
68
|
+
yield `-LU${unscaledFactor}`;
|
|
69
|
+
if (typeof overlapExpansionFactor === "number")
|
|
70
|
+
yield `-LC${overlapExpansionFactor}`;
|
|
71
|
+
if (typeof temperature === "number")
|
|
72
|
+
yield `-LT${temperature}`;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createCommandAndArgs(options) {
|
|
80
|
+
return [options.dotCommand ?? "dot", Array.from(createCommandArgs(options))];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { createCommandAndArgs };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Attribute, AttributeKey } from '@ts-graphviz/common';
|
|
2
|
+
import { Layout, Options } from './types.js';
|
|
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
|
+
export declare function escapeValue<T extends AttributeKey>(value: Attribute<T>): string;
|
|
11
|
+
/**
|
|
12
|
+
* createCommandArgs is a function that creates command arguments from a given Options object.
|
|
13
|
+
* It reads the properties of the Options object and creates corresponding command line arguments accordingly.
|
|
14
|
+
*
|
|
15
|
+
* @param options The Options object used to create command arguments
|
|
16
|
+
* @returns A generator that yields strings for command arguments
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCommandArgs<T extends Layout>(options: Options<T>): Generator<string>;
|
package/lib/deno.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @ts-graphviz/adapter
|
|
3
|
+
*/
|
|
4
|
+
import { Layout, Options } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<ReadableStream<Uint8Array>>;
|
|
9
|
+
/**
|
|
10
|
+
* Execute the Graphviz dot command and output the results to a file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toFile<T extends Layout>(dot: string, path: string, options?: Options<T>): Promise<void>;
|
package/lib/deno.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createCommandAndArgs } from './create-command-and-args.js';
|
|
2
|
+
|
|
3
|
+
async function toStream(dot, options) {
|
|
4
|
+
const [command, args] = createCommandAndArgs(options ?? {});
|
|
5
|
+
const cp = new Deno.Command(command, {
|
|
6
|
+
args,
|
|
7
|
+
stdin: "piped",
|
|
8
|
+
stdout: "piped"
|
|
9
|
+
}).spawn();
|
|
10
|
+
const stdin = cp.stdin.getWriter();
|
|
11
|
+
await stdin.write(new TextEncoder().encode(dot));
|
|
12
|
+
await stdin.close();
|
|
13
|
+
return cp.stdout;
|
|
14
|
+
}
|
|
15
|
+
function open(path) {
|
|
16
|
+
try {
|
|
17
|
+
return Deno.open(path, { write: true });
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e instanceof Deno.errors.NotFound) {
|
|
20
|
+
return Deno.open(path, { createNew: true, write: true });
|
|
21
|
+
}
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function toFile(dot, path, options) {
|
|
26
|
+
const output = await open(path);
|
|
27
|
+
const stream = await toStream(dot, options);
|
|
28
|
+
await stream.pipeTo(output.writable);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { toFile, toStream };
|
package/lib/node.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const node_child_process = require('node:child_process');
|
|
6
|
+
const node_stream = require('node:stream');
|
|
7
|
+
const promises = require('node:stream/promises');
|
|
8
|
+
const createCommandAndArgs = require('./create-command-and-args.cjs');
|
|
9
|
+
const node_fs = require('node:fs');
|
|
10
|
+
|
|
11
|
+
async function toStream(dot, options) {
|
|
12
|
+
const [command, args] = createCommandAndArgs.createCommandAndArgs(options ?? {});
|
|
13
|
+
return new Promise(function toStreamInternal(resolve, reject) {
|
|
14
|
+
const p = node_child_process.spawn(command, args, { stdio: "pipe" });
|
|
15
|
+
p.on("error", (e) => {
|
|
16
|
+
reject(
|
|
17
|
+
new Error(`Command "${command}" failed.
|
|
18
|
+
MESSAGE:${e.message}`, {
|
|
19
|
+
cause: e
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
const stderrChunks = [];
|
|
24
|
+
p.stdout.on("pause", () => p.stdout.resume());
|
|
25
|
+
p.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
26
|
+
p.stderr.on("pause", () => p.stderr.resume());
|
|
27
|
+
const dist = p.stdout.pipe(new node_stream.PassThrough());
|
|
28
|
+
p.on("close", async (code, signal) => {
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
resolve(dist);
|
|
31
|
+
} else {
|
|
32
|
+
const message = Buffer.concat(
|
|
33
|
+
stderrChunks
|
|
34
|
+
).toString();
|
|
35
|
+
reject(
|
|
36
|
+
new Error(
|
|
37
|
+
`Command "${command}" failed.
|
|
38
|
+
CODE: ${code}
|
|
39
|
+
SIGNAL: ${signal}
|
|
40
|
+
MESSAGE: ${message}`
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
promises.pipeline(node_stream.Readable.from([dot]), p.stdin);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function toFile(dot, path, options) {
|
|
50
|
+
const stream = await toStream(dot, options);
|
|
51
|
+
await promises.pipeline(stream, node_fs.createWriteStream(path));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.toFile = toFile;
|
|
55
|
+
exports.toStream = toStream;
|
package/lib/node.d.ts
ADDED
package/lib/node.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
3
|
+
import { pipeline } from 'node:stream/promises';
|
|
4
|
+
import { createCommandAndArgs } from './create-command-and-args.js';
|
|
5
|
+
import { createWriteStream } from 'node:fs';
|
|
6
|
+
|
|
7
|
+
async function toStream(dot, options) {
|
|
8
|
+
const [command, args] = createCommandAndArgs(options ?? {});
|
|
9
|
+
return new Promise(function toStreamInternal(resolve, reject) {
|
|
10
|
+
const p = spawn(command, args, { stdio: "pipe" });
|
|
11
|
+
p.on("error", (e) => {
|
|
12
|
+
reject(
|
|
13
|
+
new Error(`Command "${command}" failed.
|
|
14
|
+
MESSAGE:${e.message}`, {
|
|
15
|
+
cause: e
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
const stderrChunks = [];
|
|
20
|
+
p.stdout.on("pause", () => p.stdout.resume());
|
|
21
|
+
p.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
22
|
+
p.stderr.on("pause", () => p.stderr.resume());
|
|
23
|
+
const dist = p.stdout.pipe(new PassThrough());
|
|
24
|
+
p.on("close", async (code, signal) => {
|
|
25
|
+
if (code === 0) {
|
|
26
|
+
resolve(dist);
|
|
27
|
+
} else {
|
|
28
|
+
const message = Buffer.concat(
|
|
29
|
+
stderrChunks
|
|
30
|
+
).toString();
|
|
31
|
+
reject(
|
|
32
|
+
new Error(
|
|
33
|
+
`Command "${command}" failed.
|
|
34
|
+
CODE: ${code}
|
|
35
|
+
SIGNAL: ${signal}
|
|
36
|
+
MESSAGE: ${message}`
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
pipeline(Readable.from([dot]), p.stdin);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function toFile(dot, path, options) {
|
|
46
|
+
const stream = await toStream(dot, options);
|
|
47
|
+
await pipeline(stream, createWriteStream(path));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { toFile, toStream };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Layout, Options } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<NodeJS.ReadableStream>;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { $keywords, $keywordsValidation, EdgeAttributesObject, GraphAttributesObject, NodeAttributesObject, SubgraphAttributesObject } from '@ts-graphviz/common';
|
|
2
|
+
export type Format = Format.values;
|
|
3
|
+
export declare namespace Format {
|
|
4
|
+
type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
|
|
5
|
+
interface $values extends $keywords<'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json'> {
|
|
6
|
+
}
|
|
7
|
+
interface $exclude extends $keywordsValidation {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export type Layout = Layout.values;
|
|
11
|
+
export declare namespace Layout {
|
|
12
|
+
type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
|
|
13
|
+
interface $values extends $keywords<'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork'> {
|
|
14
|
+
}
|
|
15
|
+
interface $exclude extends $keywordsValidation {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* NeatoOptions interface provides options for the neato layout.
|
|
20
|
+
*/
|
|
21
|
+
export interface NeatoOptions {
|
|
22
|
+
layout: 'neato';
|
|
23
|
+
/**
|
|
24
|
+
* Sets no-op flag in neato.
|
|
25
|
+
*/
|
|
26
|
+
noop?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Reduce graph.
|
|
29
|
+
*/
|
|
30
|
+
reduce?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* FdpOptions interface provides options for the fdp layout.
|
|
34
|
+
*/
|
|
35
|
+
export interface FdpOptions {
|
|
36
|
+
layout: 'fdp';
|
|
37
|
+
/**
|
|
38
|
+
* Use grid.
|
|
39
|
+
*
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
grid?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Use old attractive force
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
oldAttractive?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Set number of iterations.
|
|
51
|
+
*/
|
|
52
|
+
iterations?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Set unscaled factor
|
|
55
|
+
*/
|
|
56
|
+
unscaledFactor?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Set overlap expansion factor.
|
|
59
|
+
*/
|
|
60
|
+
overlapExpansionFactor?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Set temperature.
|
|
63
|
+
*/
|
|
64
|
+
temperature?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @description
|
|
68
|
+
* This interface describes an optional parameter called "layout" which is used to set a layout engine.
|
|
69
|
+
* The default value for this parameter is 'dot', and it must be an option of the Layout type,
|
|
70
|
+
* excluding 'neato' and 'fdp'.
|
|
71
|
+
*/
|
|
72
|
+
export interface OtherOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Set layout engine.
|
|
75
|
+
*
|
|
76
|
+
* @default 'dot'
|
|
77
|
+
*/
|
|
78
|
+
layout?: Exclude<Layout, 'neato' | 'fdp'>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* This interface represents the CommonOptions for setting output format.
|
|
82
|
+
*/
|
|
83
|
+
export interface CommonOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Set output format.
|
|
86
|
+
*
|
|
87
|
+
* @default 'svg'
|
|
88
|
+
*/
|
|
89
|
+
format?: Format;
|
|
90
|
+
/**
|
|
91
|
+
* If true, set level of message suppression (=1).
|
|
92
|
+
*
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
suppressWarnings?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Path of graphviz dot command.
|
|
98
|
+
*/
|
|
99
|
+
dotCommand?: string;
|
|
100
|
+
attributes?: {
|
|
101
|
+
/**
|
|
102
|
+
* Set edge attribute.
|
|
103
|
+
*/
|
|
104
|
+
edge?: EdgeAttributesObject;
|
|
105
|
+
/**
|
|
106
|
+
* Set node attribute.
|
|
107
|
+
*/
|
|
108
|
+
node?: NodeAttributesObject;
|
|
109
|
+
/**
|
|
110
|
+
* Set graph attribute.
|
|
111
|
+
*/
|
|
112
|
+
graph?: GraphAttributesObject & SubgraphAttributesObject;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Scale input
|
|
116
|
+
*/
|
|
117
|
+
scale?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Use external library.
|
|
120
|
+
*/
|
|
121
|
+
library?: string[];
|
|
122
|
+
/**
|
|
123
|
+
* Invert y coordinate in output.
|
|
124
|
+
*/
|
|
125
|
+
y?: boolean;
|
|
126
|
+
}
|
|
127
|
+
export type Options<T extends Layout = Layout> = CommonOptions & (T extends 'neato' ? NeatoOptions : T extends 'fdp' ? FdpOptions : OtherOptions);
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-graphviz/adapter",
|
|
3
|
+
"version": "0.0.0-pr956-20240225073457",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/node.cjs",
|
|
7
|
+
"module": "./lib/node.js",
|
|
8
|
+
"types": "./lib/node.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": {
|
|
12
|
+
"types": "./lib/browser.d.ts",
|
|
13
|
+
"require": "./lib/browser.cjs",
|
|
14
|
+
"default": "./lib/browser.js"
|
|
15
|
+
},
|
|
16
|
+
"deno": {
|
|
17
|
+
"types": "./lib/deno.d.ts",
|
|
18
|
+
"default": "./lib/deno.js"
|
|
19
|
+
},
|
|
20
|
+
"default": {
|
|
21
|
+
"types": "./lib/node.d.ts",
|
|
22
|
+
"require": "./lib/node.cjs",
|
|
23
|
+
"default": "./lib/node.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ts-graphviz/ts-graphviz.git",
|
|
31
|
+
"directory": "packages/adapter"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true
|
|
36
|
+
},
|
|
37
|
+
"author": "Yuki Yamazaki <yuki@kamiazya.tech>",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/ts-graphviz/ts-graphviz/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/ts-graphviz/ts-graphviz#readme",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@ts-graphviz/common": "^0.0.0-pr956-20240225073457"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@deno/shim-deno": "^0.19.1",
|
|
48
|
+
"@types/node": "^20.2.1",
|
|
49
|
+
"typescript": "^5.3.3",
|
|
50
|
+
"vite": "^5.1.3",
|
|
51
|
+
"vite-plugin-dts": "^3.7.2"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "vite build && rm ./lib/deno.cjs "
|
|
55
|
+
}
|
|
56
|
+
}
|