ts-graphviz 1.5.6-dev.ef6c929b6 → 1.6.1-dev.39dd9d4de
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 +80 -2
- package/lib/adapter/node/index.d.ts +1 -1
- package/lib/adapter/types/index.d.ts +12 -2
- package/lib/ast/index.cjs +2 -2
- package/lib/ast/index.d.ts +18 -13
- package/lib/ast/index.js +2 -2
- package/lib/common/index.d.ts +3861 -1281
- package/lib/core/index.d.ts +5 -2482
- package/lib/index.d.ts +1 -0
- package/lib/utils/index.d.ts +8 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -503,6 +503,80 @@ const ast = parse(`
|
|
|
503
503
|
|
|
504
504
|
</details>
|
|
505
505
|
|
|
506
|
+
### Extending the Type System 🧰
|
|
507
|
+
|
|
508
|
+
> The status of this feature is .
|
|
509
|
+
|
|
510
|
+
With ts-graphviz, you can extend the library's type system to customize graph visualization solutions to meet specific needs.
|
|
511
|
+
|
|
512
|
+
> **Note** To allow for customization, types are named with the `$` symbol.
|
|
513
|
+
>
|
|
514
|
+
> If you want to extend a type definition in cases not listed below, check the source code to see if you can extend it with `$...`.
|
|
515
|
+
>
|
|
516
|
+
> If not, please create an issue or pull request.
|
|
517
|
+
|
|
518
|
+
#### Use Case: Specifying Custom Graph Layout and Output Formats
|
|
519
|
+
|
|
520
|
+
```ts
|
|
521
|
+
import { $keywords } from 'ts-graphviz';
|
|
522
|
+
import { toFile } from 'ts-graphviz/adapter';
|
|
523
|
+
|
|
524
|
+
// 1. Declare the 'ts-graphviz/adapter' module.
|
|
525
|
+
declare module 'ts-graphviz/adapter' {
|
|
526
|
+
export namespace Layout {
|
|
527
|
+
// 2. Define the $values interface in the Layout namespace.
|
|
528
|
+
// 3. Inherit from $keywords<'my-custom-algorithm'> and specify the name of the new layout engine in <...>.
|
|
529
|
+
export interface $values extends $keywords<'my-custom-algorithm'> {}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export namespace Format {
|
|
533
|
+
// 4. Define the $values interface in the Format namespace.
|
|
534
|
+
// 5. Inherit from $keywords<'mp4'> and specify the name of the new output format in <...>.
|
|
535
|
+
export interface $values extends $keywords<'mp4'> {}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
toFile('digraph { a -> b }', '/path/to/file', {
|
|
540
|
+
layout: 'my-custom-algorithm',
|
|
541
|
+
format: 'mp4',
|
|
542
|
+
});
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
#### Use Case: Adding Custom Attributes
|
|
546
|
+
|
|
547
|
+
```ts
|
|
548
|
+
import { digraph, toDot, attribute as _, $keywords } from 'ts-graphviz';
|
|
549
|
+
|
|
550
|
+
// 1. Declare the 'ts-graphviz' module.
|
|
551
|
+
declare module 'ts-graphviz' {
|
|
552
|
+
export namespace GraphAttributeKey {
|
|
553
|
+
// 2. Define the $values interface in the GraphAttributeKey namespace.
|
|
554
|
+
// 3. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
|
|
555
|
+
export interface $values extends $keywords<'hoge'> {}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export namespace Attribute {
|
|
559
|
+
// 4. Define the $keys interface in the Attribute namespace.
|
|
560
|
+
// 5. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
|
|
561
|
+
export interface $keys extends $keywords<'hoge'> {}
|
|
562
|
+
|
|
563
|
+
// 6. Define the $types interface in the Attribute namespace.
|
|
564
|
+
// 7. Specify the new attribute in the key and define its corresponding value in the value.
|
|
565
|
+
export interface $types {
|
|
566
|
+
hoge: string;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
console.log(
|
|
572
|
+
toDot(
|
|
573
|
+
digraph((g) => {
|
|
574
|
+
g.set(_.hoge, 'fuga');
|
|
575
|
+
}),
|
|
576
|
+
),
|
|
577
|
+
);
|
|
578
|
+
```
|
|
579
|
+
|
|
506
580
|
## Who's using `ts-graphviz` 📜
|
|
507
581
|
|
|
508
582
|
- [Apollo GraphQL](https://github.com/apollographql)
|
|
@@ -576,9 +650,13 @@ See [CONTRIBUTING.md](https://github.com/ts-graphviz/ts-graphviz/blob/main/CONTR
|
|
|
576
650
|
|
|
577
651
|
### Financial Support 💸
|
|
578
652
|
|
|
579
|
-
Please support
|
|
653
|
+
Please support [ts-graphviz](https://github.com/sponsors/ts-graphviz).
|
|
654
|
+
|
|
655
|
+
Our goal for ts-graphviz is to attract 10 sponsors who can provide ongoing support to help cover development and maintenance costs,
|
|
656
|
+
and help us continue expanding and improving the library. By achieving this goal, we can ensure that ts-graphviz remains a valuable resource
|
|
657
|
+
for developers who need to analyze and visualize complex graph structures, while also fostering a strong and supportive community of users and sponsors.
|
|
580
658
|
|
|
581
|
-
> **Note** Even just a dollar is enough motivation
|
|
659
|
+
> **Note** Even just a dollar is enough motivation to develop 😊
|
|
582
660
|
|
|
583
661
|
## License ⚖️
|
|
584
662
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Layout, Options } from '../types/index.js';
|
|
3
|
-
export { Format, Options } from '../types/index.js';
|
|
3
|
+
export { Format, Layout, Options } from '../types/index.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
@@ -4,9 +4,19 @@ import {
|
|
|
4
4
|
GraphAttributesObject,
|
|
5
5
|
SubgraphAttributesObject,
|
|
6
6
|
} from '../../common/index.js';
|
|
7
|
+
import { $keywords } from '../../utils/index.js';
|
|
7
8
|
|
|
8
|
-
type Format =
|
|
9
|
-
|
|
9
|
+
type Format = Format.values;
|
|
10
|
+
declare namespace Format {
|
|
11
|
+
type values = keyof $values;
|
|
12
|
+
interface $values extends $keywords<'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json'> {}
|
|
13
|
+
}
|
|
14
|
+
type Layout = Layout.values;
|
|
15
|
+
declare namespace Layout {
|
|
16
|
+
type values = keyof $values;
|
|
17
|
+
interface $values
|
|
18
|
+
extends $keywords<'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork'> {}
|
|
19
|
+
}
|
|
10
20
|
/**
|
|
11
21
|
* NeatoOptions interface provides options for the neato layout.
|
|
12
22
|
*/
|
package/lib/ast/index.cjs
CHANGED
|
@@ -11,11 +11,11 @@ class Builder {
|
|
|
11
11
|
constructor(options) {
|
|
12
12
|
this.options = options;
|
|
13
13
|
}
|
|
14
|
-
createElement(type, props, children) {
|
|
14
|
+
createElement(type, props, children = []) {
|
|
15
15
|
return {
|
|
16
|
+
location: this.getLocation(),
|
|
16
17
|
...props,
|
|
17
18
|
type,
|
|
18
|
-
location: this.getLocation(),
|
|
19
19
|
children,
|
|
20
20
|
};
|
|
21
21
|
}
|
package/lib/ast/index.d.ts
CHANGED
|
@@ -351,7 +351,7 @@ interface CreateElement {
|
|
|
351
351
|
<T extends string>(
|
|
352
352
|
type: 'Literal',
|
|
353
353
|
props: LiteralASTPropaties<T>,
|
|
354
|
-
children
|
|
354
|
+
children?: ASTChildNode<LiteralASTNode>[],
|
|
355
355
|
): LiteralASTNode<T>;
|
|
356
356
|
/**
|
|
357
357
|
* Creates a LiteralASTNode with the given type, properties, and children.
|
|
@@ -361,7 +361,7 @@ interface CreateElement {
|
|
|
361
361
|
* @param children The children of the AST node.
|
|
362
362
|
* @returns A {@link LiteralASTNode} with the given type, properties, and children.
|
|
363
363
|
*/
|
|
364
|
-
(type: 'Literal', props: LiteralASTPropaties, children
|
|
364
|
+
(type: 'Literal', props: LiteralASTPropaties, children?: ASTChildNode<LiteralASTNode>[]): LiteralASTNode;
|
|
365
365
|
/**
|
|
366
366
|
* Creates a {@link DotASTNode} with the given type, properties, and children.
|
|
367
367
|
*
|
|
@@ -370,7 +370,7 @@ interface CreateElement {
|
|
|
370
370
|
* @param children The children of the AST node.
|
|
371
371
|
* @returns A {@link DotASTNode} with the given type, properties, and children.
|
|
372
372
|
*/
|
|
373
|
-
(type: 'Dot', props: DotASTPropaties, children
|
|
373
|
+
(type: 'Dot', props: DotASTPropaties, children?: ASTChildNode<DotASTNode>[]): DotASTNode;
|
|
374
374
|
/**
|
|
375
375
|
* Creates a {@link GraphASTNode} with the given type, properties, and children.
|
|
376
376
|
*
|
|
@@ -379,7 +379,7 @@ interface CreateElement {
|
|
|
379
379
|
* @param children The children of the AST node.
|
|
380
380
|
* @returns A {GraphASTNode} with the given type, properties, and children.
|
|
381
381
|
*/
|
|
382
|
-
(type: 'Graph', props: GraphASTPropaties, children
|
|
382
|
+
(type: 'Graph', props: GraphASTPropaties, children?: ASTChildNode<GraphASTNode>[]): GraphASTNode;
|
|
383
383
|
/**
|
|
384
384
|
* Creates an {@link AttributeASTNode} with the given type, properties, and children.
|
|
385
385
|
*
|
|
@@ -388,7 +388,12 @@ interface CreateElement {
|
|
|
388
388
|
* @param children The children of the AST node.
|
|
389
389
|
* @returns An {@link AttributeASTNode} with the given type, properties, and children.
|
|
390
390
|
*/
|
|
391
|
-
|
|
391
|
+
<T extends AttributeKey>(
|
|
392
|
+
type: 'Attribute',
|
|
393
|
+
props: AttributeASTPropaties<T>,
|
|
394
|
+
children?: ASTChildNode<AttributeASTNode>[],
|
|
395
|
+
): AttributeASTNode<T>;
|
|
396
|
+
(type: 'Attribute', props: AttributeASTPropaties, children?: ASTChildNode<AttributeASTNode>[]): AttributeASTNode;
|
|
392
397
|
/**
|
|
393
398
|
* Creates a {@link CommentASTNode} with the given type, properties, and children.
|
|
394
399
|
*
|
|
@@ -397,7 +402,7 @@ interface CreateElement {
|
|
|
397
402
|
* @param children The children of the AST node.
|
|
398
403
|
* @returns A {@link CommentASTNode} with the given type, properties, and children.
|
|
399
404
|
*/
|
|
400
|
-
(type: 'Comment', props: CommentASTPropaties, children
|
|
405
|
+
(type: 'Comment', props: CommentASTPropaties, children?: ASTChildNode<CommentASTNode>[]): CommentASTNode;
|
|
401
406
|
/**
|
|
402
407
|
* Creates an {@link AttributeListASTNode} with the given type, properties, and children.
|
|
403
408
|
*
|
|
@@ -409,7 +414,7 @@ interface CreateElement {
|
|
|
409
414
|
(
|
|
410
415
|
type: 'AttributeList',
|
|
411
416
|
props: AttributeListASTPropaties,
|
|
412
|
-
children
|
|
417
|
+
children?: ASTChildNode<AttributeListASTNode>[],
|
|
413
418
|
): AttributeListASTNode;
|
|
414
419
|
/**
|
|
415
420
|
* Creates a {@link NodeRefASTNode} with the given type, properties, and children.
|
|
@@ -419,7 +424,7 @@ interface CreateElement {
|
|
|
419
424
|
* @param children The children of the AST node.
|
|
420
425
|
* @returns A {@link NodeRefASTNode} with the given type, properties, and children.
|
|
421
426
|
*/
|
|
422
|
-
(type: 'NodeRef', props: NodeRefASTPropaties, children
|
|
427
|
+
(type: 'NodeRef', props: NodeRefASTPropaties, children?: ASTChildNode<NodeRefASTNode>[]): NodeRefASTNode;
|
|
423
428
|
/**
|
|
424
429
|
* Creates a {@link NodeRefGroupASTNode} with the given type, properties, and children.
|
|
425
430
|
*
|
|
@@ -431,7 +436,7 @@ interface CreateElement {
|
|
|
431
436
|
(
|
|
432
437
|
type: 'NodeRefGroup',
|
|
433
438
|
props: NodeRefGroupASTPropaties,
|
|
434
|
-
children
|
|
439
|
+
children?: ASTChildNode<NodeRefGroupASTNode>[],
|
|
435
440
|
): NodeRefGroupASTNode;
|
|
436
441
|
/**
|
|
437
442
|
* Creates an {@link EdgeASTNode} with the given type, properties, and children.
|
|
@@ -441,7 +446,7 @@ interface CreateElement {
|
|
|
441
446
|
* @param children The children of the AST node.
|
|
442
447
|
* @returns An {@link EdgeASTNode} with the given type, properties, and children.
|
|
443
448
|
*/
|
|
444
|
-
(type: 'Edge', props: EdgeASTPropaties, children
|
|
449
|
+
(type: 'Edge', props: EdgeASTPropaties, children?: ASTChildNode<EdgeASTNode>[]): EdgeASTNode;
|
|
445
450
|
/**
|
|
446
451
|
* Creates a {@link NodeASTNode} with the given type, properties, and children.
|
|
447
452
|
*
|
|
@@ -450,7 +455,7 @@ interface CreateElement {
|
|
|
450
455
|
* @param children The children of the AST node.
|
|
451
456
|
* @returns A {@link NodeASTNode} with the given type, properties, and children.
|
|
452
457
|
*/
|
|
453
|
-
(type: 'Node', props: NodeASTPropaties, children
|
|
458
|
+
(type: 'Node', props: NodeASTPropaties, children?: ASTChildNode<NodeASTNode>[]): NodeASTNode;
|
|
454
459
|
/**
|
|
455
460
|
* Creates a {@link SubgraphASTNode} with the given type, properties, and children.
|
|
456
461
|
*
|
|
@@ -459,7 +464,7 @@ interface CreateElement {
|
|
|
459
464
|
* @param children The children of the AST node.
|
|
460
465
|
* @returns A {@link SubgraphASTNode} with the given type, properties, and children.
|
|
461
466
|
*/
|
|
462
|
-
(type: 'Subgraph', props: SubgraphASTPropaties, children
|
|
467
|
+
(type: 'Subgraph', props: SubgraphASTPropaties, children?: ASTChildNode<SubgraphASTNode>[]): SubgraphASTNode;
|
|
463
468
|
}
|
|
464
469
|
/**
|
|
465
470
|
* This interface provides an ASTBuilder object with a createElement function.
|
|
@@ -495,7 +500,7 @@ declare class Builder implements ASTBuilder {
|
|
|
495
500
|
* @param children - Children of the {@link ASTNode}
|
|
496
501
|
* @returns An {@link ASTNode}
|
|
497
502
|
*/
|
|
498
|
-
createElement<T extends ASTNode>(type: T['type'], props: any, children
|
|
503
|
+
createElement<T extends ASTNode>(type: T['type'], props: any, children?: ASTChildNode<T>[]): T;
|
|
499
504
|
}
|
|
500
505
|
|
|
501
506
|
/**
|
package/lib/ast/index.js
CHANGED
|
@@ -9,11 +9,11 @@ class Builder {
|
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.options = options;
|
|
11
11
|
}
|
|
12
|
-
createElement(type, props, children) {
|
|
12
|
+
createElement(type, props, children = []) {
|
|
13
13
|
return {
|
|
14
|
+
location: this.getLocation(),
|
|
14
15
|
...props,
|
|
15
16
|
type,
|
|
16
|
-
location: this.getLocation(),
|
|
17
17
|
children,
|
|
18
18
|
};
|
|
19
19
|
}
|