ts-graphviz 1.8.2 → 2.0.0
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 +307 -0
- package/README.md +40 -13
- package/lib/adapter.cjs +1 -0
- package/lib/adapter.d.ts +1 -0
- package/lib/adapter.js +1 -0
- package/lib/ast.cjs +1 -0
- package/lib/ast.d.ts +1 -0
- package/lib/ast.js +1 -0
- package/lib/attribute.d.ts +2 -0
- package/lib/from-dot.d.ts +10 -0
- package/lib/model-factory-builder.d.ts +7 -0
- package/lib/model-factory.d.ts +6 -0
- package/lib/to-dot.d.ts +7 -0
- package/lib/ts-graphviz.cjs +1 -0
- package/lib/ts-graphviz.d.ts +7 -0
- package/lib/ts-graphviz.js +55 -0
- package/lib/types.d.ts +14 -0
- package/package.json +53 -96
- package/SECURITY.md +0 -5
- package/lib/adapter/browser/index.cjs +0 -12
- package/lib/adapter/browser/index.d.ts +0 -15
- package/lib/adapter/browser/index.js +0 -9
- package/lib/adapter/deno/mod.d.ts +0 -13
- package/lib/adapter/deno/mod.js +0 -36
- package/lib/adapter/node/index.cjs +0 -45
- package/lib/adapter/node/index.d.ts +0 -15
- package/lib/adapter/node/index.js +0 -42
- package/lib/adapter/types/index.cjs +0 -1
- package/lib/adapter/types/index.d.ts +0 -134
- package/lib/adapter/types/index.js +0 -0
- package/lib/adapter/utils/index.cjs +0 -58
- package/lib/adapter/utils/index.d.ts +0 -11
- package/lib/adapter/utils/index.js +0 -56
- package/lib/ast/index.cjs +0 -5775
- package/lib/ast/index.d.ts +0 -946
- package/lib/ast/index.js +0 -5770
- package/lib/common/index.cjs +0 -58
- package/lib/common/index.d.ts +0 -4981
- package/lib/common/index.js +0 -58
- package/lib/core/index.cjs +0 -359
- package/lib/core/index.d.ts +0 -347
- package/lib/core/index.js +0 -364
- package/lib/index.cjs +0 -23
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -2
- package/lib/utils/index.cjs +0 -41
- package/lib/utils/index.d.ts +0 -34
- package/lib/utils/index.js +0 -37
package/lib/common/index.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
function isForwardRefNode(object) {
|
|
2
|
-
return typeof object === 'object' && object !== null && typeof object.id === 'string';
|
|
3
|
-
}
|
|
4
|
-
function isNodeModel(object) {
|
|
5
|
-
return typeof object === 'object' && object !== null && object.$$type === 'Node' && typeof object.id === 'string';
|
|
6
|
-
}
|
|
7
|
-
function isNodeRef(node) {
|
|
8
|
-
return isNodeModel(node) || isForwardRefNode(node);
|
|
9
|
-
}
|
|
10
|
-
function isNodeRefLike(node) {
|
|
11
|
-
return typeof node === 'string' || isNodeRef(node);
|
|
12
|
-
}
|
|
13
|
-
function isNodeRefGroupLike(target) {
|
|
14
|
-
return Array.isArray(target) && target.every(isNodeRefLike);
|
|
15
|
-
}
|
|
16
|
-
function isCompass(c) {
|
|
17
|
-
return ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'c'].includes(c);
|
|
18
|
-
}
|
|
19
|
-
function toNodeRef(target) {
|
|
20
|
-
if (isNodeRef(target)) {
|
|
21
|
-
return target;
|
|
22
|
-
}
|
|
23
|
-
const [id, port, compass] = target.split(':');
|
|
24
|
-
if (isCompass(compass)) {
|
|
25
|
-
return { id, port, compass };
|
|
26
|
-
}
|
|
27
|
-
return { id, port };
|
|
28
|
-
}
|
|
29
|
-
function toNodeRefGroup(targets) {
|
|
30
|
-
if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
|
|
31
|
-
throw Error('EdgeTargets must have at least 2 elements.');
|
|
32
|
-
}
|
|
33
|
-
return targets.map((t) => toNodeRef(t));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const RootModelsContext = Object.seal({
|
|
37
|
-
Graph: null,
|
|
38
|
-
Digraph: null,
|
|
39
|
-
Subgraph: null,
|
|
40
|
-
Node: null,
|
|
41
|
-
Edge: null,
|
|
42
|
-
});
|
|
43
|
-
function createModelsContext(models) {
|
|
44
|
-
return Object.assign(Object.seal(Object.assign({}, RootModelsContext)), models);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
RootModelsContext,
|
|
49
|
-
createModelsContext,
|
|
50
|
-
isCompass,
|
|
51
|
-
isForwardRefNode,
|
|
52
|
-
isNodeModel,
|
|
53
|
-
isNodeRef,
|
|
54
|
-
isNodeRefGroupLike,
|
|
55
|
-
isNodeRefLike,
|
|
56
|
-
toNodeRef,
|
|
57
|
-
toNodeRefGroup,
|
|
58
|
-
};
|
package/lib/core/index.cjs
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index_js = require('../common/index.cjs');
|
|
4
|
-
var index_js$1 = require('../ast/index.cjs');
|
|
5
|
-
|
|
6
|
-
const attribute = new Proxy(Object.freeze({}), {
|
|
7
|
-
get: (_, key) => key,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
class DotObject {}
|
|
11
|
-
|
|
12
|
-
class AttributesBase extends DotObject {
|
|
13
|
-
#attrs = new Map();
|
|
14
|
-
constructor(attributes) {
|
|
15
|
-
super();
|
|
16
|
-
if (attributes !== undefined) {
|
|
17
|
-
this.apply(attributes);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
get values() {
|
|
21
|
-
return Array.from(this.#attrs.entries());
|
|
22
|
-
}
|
|
23
|
-
get size() {
|
|
24
|
-
return this.#attrs.size;
|
|
25
|
-
}
|
|
26
|
-
get(key) {
|
|
27
|
-
return this.#attrs.get(key);
|
|
28
|
-
}
|
|
29
|
-
set(key, value) {
|
|
30
|
-
if (value !== null && value !== undefined) {
|
|
31
|
-
this.#attrs.set(key, value);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
delete(key) {
|
|
35
|
-
this.#attrs.delete(key);
|
|
36
|
-
}
|
|
37
|
-
apply(attributes) {
|
|
38
|
-
const entries = Array.isArray(attributes) ? attributes : Object.entries(attributes);
|
|
39
|
-
for (const [key, value] of entries) {
|
|
40
|
-
this.set(key, value);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
clear() {
|
|
44
|
-
this.#attrs.clear();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class AttributeList extends AttributesBase {
|
|
49
|
-
$$kind;
|
|
50
|
-
get $$type() {
|
|
51
|
-
return 'AttributeList';
|
|
52
|
-
}
|
|
53
|
-
comment;
|
|
54
|
-
constructor($$kind, attributes) {
|
|
55
|
-
super(attributes);
|
|
56
|
-
this.$$kind = $$kind;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
class GraphBase extends AttributesBase {
|
|
61
|
-
#models = index_js.RootModelsContext;
|
|
62
|
-
id;
|
|
63
|
-
comment;
|
|
64
|
-
attributes = Object.freeze({
|
|
65
|
-
graph: new AttributeList('Graph'),
|
|
66
|
-
edge: new AttributeList('Edge'),
|
|
67
|
-
node: new AttributeList('Node'),
|
|
68
|
-
});
|
|
69
|
-
get nodes() {
|
|
70
|
-
return Array.from(this.#objects.nodes.values());
|
|
71
|
-
}
|
|
72
|
-
get edges() {
|
|
73
|
-
return Array.from(this.#objects.edges.values());
|
|
74
|
-
}
|
|
75
|
-
get subgraphs() {
|
|
76
|
-
return Array.from(this.#objects.subgraphs.values());
|
|
77
|
-
}
|
|
78
|
-
#objects = {
|
|
79
|
-
nodes: new Map(),
|
|
80
|
-
edges: new Set(),
|
|
81
|
-
subgraphs: new Set(),
|
|
82
|
-
};
|
|
83
|
-
with(models) {
|
|
84
|
-
this.#models = index_js.createModelsContext(models);
|
|
85
|
-
}
|
|
86
|
-
addNode(node) {
|
|
87
|
-
this.#objects.nodes.set(node.id, node);
|
|
88
|
-
}
|
|
89
|
-
addEdge(edge) {
|
|
90
|
-
this.#objects.edges.add(edge);
|
|
91
|
-
}
|
|
92
|
-
addSubgraph(subgraph) {
|
|
93
|
-
this.#objects.subgraphs.add(subgraph);
|
|
94
|
-
}
|
|
95
|
-
existNode(nodeId) {
|
|
96
|
-
return this.#objects.nodes.has(nodeId);
|
|
97
|
-
}
|
|
98
|
-
existEdge(edge) {
|
|
99
|
-
return this.#objects.edges.has(edge);
|
|
100
|
-
}
|
|
101
|
-
existSubgraph(subgraph) {
|
|
102
|
-
return this.#objects.subgraphs.has(subgraph);
|
|
103
|
-
}
|
|
104
|
-
createSubgraph(...args) {
|
|
105
|
-
const subgraph = new this.#models.Subgraph(...args);
|
|
106
|
-
subgraph.with(this.#models);
|
|
107
|
-
this.addSubgraph(subgraph);
|
|
108
|
-
return subgraph;
|
|
109
|
-
}
|
|
110
|
-
removeNode(node) {
|
|
111
|
-
this.#objects.nodes.delete(typeof node === 'string' ? node : node.id);
|
|
112
|
-
}
|
|
113
|
-
removeEdge(edge) {
|
|
114
|
-
this.#objects.edges.delete(edge);
|
|
115
|
-
}
|
|
116
|
-
removeSubgraph(subgraph) {
|
|
117
|
-
this.#objects.subgraphs.delete(subgraph);
|
|
118
|
-
}
|
|
119
|
-
createNode(id, attributes) {
|
|
120
|
-
const node = new this.#models.Node(id, attributes);
|
|
121
|
-
this.addNode(node);
|
|
122
|
-
return node;
|
|
123
|
-
}
|
|
124
|
-
getSubgraph(id) {
|
|
125
|
-
return Array.from(this.#objects.subgraphs.values()).find((subgraph) => subgraph.id === id);
|
|
126
|
-
}
|
|
127
|
-
getNode(id) {
|
|
128
|
-
return this.#objects.nodes.get(id);
|
|
129
|
-
}
|
|
130
|
-
createEdge(targets, attributes) {
|
|
131
|
-
const ts = targets.map((t) =>
|
|
132
|
-
index_js.isNodeRefGroupLike(t) ? index_js.toNodeRefGroup(t) : index_js.toNodeRef(t),
|
|
133
|
-
);
|
|
134
|
-
const edge = new this.#models.Edge(ts, attributes);
|
|
135
|
-
this.addEdge(edge);
|
|
136
|
-
return edge;
|
|
137
|
-
}
|
|
138
|
-
subgraph(...args) {
|
|
139
|
-
const id = args.find((arg) => typeof arg === 'string');
|
|
140
|
-
const attributes = args.find((arg) => typeof arg === 'object' && arg !== null);
|
|
141
|
-
const callback = args.find((arg) => typeof arg === 'function');
|
|
142
|
-
const subgraph = id ? this.getSubgraph(id) ?? this.createSubgraph(id) : this.createSubgraph();
|
|
143
|
-
if (attributes !== undefined) {
|
|
144
|
-
subgraph.apply(attributes);
|
|
145
|
-
}
|
|
146
|
-
if (callback !== undefined) {
|
|
147
|
-
callback(subgraph);
|
|
148
|
-
}
|
|
149
|
-
return subgraph;
|
|
150
|
-
}
|
|
151
|
-
node(firstArg, ...args) {
|
|
152
|
-
if (typeof firstArg === 'string') {
|
|
153
|
-
const id = firstArg;
|
|
154
|
-
const attributes = args.find((arg) => typeof arg === 'object' && arg !== null);
|
|
155
|
-
const callback = args.find((arg) => typeof arg === 'function');
|
|
156
|
-
const node = this.getNode(id) ?? this.createNode(id);
|
|
157
|
-
if (attributes !== undefined) {
|
|
158
|
-
node.attributes.apply(attributes);
|
|
159
|
-
}
|
|
160
|
-
if (callback !== undefined) {
|
|
161
|
-
callback(node);
|
|
162
|
-
}
|
|
163
|
-
return node;
|
|
164
|
-
}
|
|
165
|
-
if (typeof firstArg === 'object' && firstArg !== null) {
|
|
166
|
-
this.attributes.node.apply(firstArg);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
edge(firstArg, ...args) {
|
|
170
|
-
if (Array.isArray(firstArg)) {
|
|
171
|
-
const targets = firstArg;
|
|
172
|
-
const attributes = args.find((arg) => typeof arg === 'object');
|
|
173
|
-
const callback = args.find((arg) => typeof arg === 'function');
|
|
174
|
-
const edge = this.createEdge(targets, attributes);
|
|
175
|
-
if (callback !== undefined) {
|
|
176
|
-
callback(edge);
|
|
177
|
-
}
|
|
178
|
-
return edge;
|
|
179
|
-
}
|
|
180
|
-
if (typeof firstArg === 'object' && firstArg !== null) {
|
|
181
|
-
this.attributes.edge.apply(firstArg);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
graph(attributes) {
|
|
185
|
-
this.attributes.graph.apply(attributes);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
class RootGraph extends GraphBase {
|
|
190
|
-
get $$type() {
|
|
191
|
-
return 'Graph';
|
|
192
|
-
}
|
|
193
|
-
id;
|
|
194
|
-
strict;
|
|
195
|
-
constructor(...args) {
|
|
196
|
-
super();
|
|
197
|
-
this.id = args.find((arg) => typeof arg === 'string');
|
|
198
|
-
this.strict = args.find((arg) => typeof arg === 'boolean') ?? false;
|
|
199
|
-
const attributes = args.find((arg) => typeof arg === 'object' && arg !== null);
|
|
200
|
-
if (attributes !== undefined) {
|
|
201
|
-
this.apply(attributes);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
class Digraph extends RootGraph {
|
|
207
|
-
get directed() {
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
class Graph extends RootGraph {
|
|
213
|
-
get directed() {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class Subgraph extends GraphBase {
|
|
219
|
-
get $$type() {
|
|
220
|
-
return 'Subgraph';
|
|
221
|
-
}
|
|
222
|
-
id;
|
|
223
|
-
constructor(...args) {
|
|
224
|
-
super();
|
|
225
|
-
this.id = args.find((arg) => typeof arg === 'string');
|
|
226
|
-
const attributes = args.find((arg) => typeof arg === 'object' && arg !== null);
|
|
227
|
-
if (attributes !== undefined) {
|
|
228
|
-
this.apply(attributes);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
isSubgraphCluster() {
|
|
232
|
-
if (typeof this.id === 'string') {
|
|
233
|
-
return this.id.startsWith('cluster');
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
class AttributesGroup extends AttributesBase {
|
|
240
|
-
comment;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
class Node extends DotObject {
|
|
244
|
-
id;
|
|
245
|
-
get $$type() {
|
|
246
|
-
return 'Node';
|
|
247
|
-
}
|
|
248
|
-
comment;
|
|
249
|
-
attributes;
|
|
250
|
-
constructor(id, attributes) {
|
|
251
|
-
super();
|
|
252
|
-
this.id = id;
|
|
253
|
-
this.attributes = new AttributesGroup(attributes);
|
|
254
|
-
}
|
|
255
|
-
port(port) {
|
|
256
|
-
if (typeof port === 'string') {
|
|
257
|
-
return { id: this.id, port };
|
|
258
|
-
}
|
|
259
|
-
return { id: this.id, ...port };
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
class Edge extends DotObject {
|
|
264
|
-
targets;
|
|
265
|
-
get $$type() {
|
|
266
|
-
return 'Edge';
|
|
267
|
-
}
|
|
268
|
-
comment;
|
|
269
|
-
attributes;
|
|
270
|
-
constructor(targets, attributes) {
|
|
271
|
-
super();
|
|
272
|
-
this.targets = targets;
|
|
273
|
-
if (targets.length < 2 && (index_js.isNodeRefLike(targets[0]) && index_js.isNodeRefLike(targets[1])) === false) {
|
|
274
|
-
throw Error('The element of Edge target is missing or not satisfied as Edge target.');
|
|
275
|
-
}
|
|
276
|
-
this.attributes = new AttributesGroup(attributes);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
Object.assign(index_js.RootModelsContext, {
|
|
281
|
-
Graph,
|
|
282
|
-
Digraph,
|
|
283
|
-
Subgraph,
|
|
284
|
-
Node,
|
|
285
|
-
Edge,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
function ModelFactoryBuilder(directed, strictMode) {
|
|
289
|
-
return (...args) => {
|
|
290
|
-
const G = directed ? this.Digraph : this.Graph;
|
|
291
|
-
const id = args.find((arg) => typeof arg === 'string');
|
|
292
|
-
const attributes = args.find((arg) => typeof arg === 'object');
|
|
293
|
-
const callback = args.find((arg) => typeof arg === 'function');
|
|
294
|
-
const g = new G(id, strictMode, attributes);
|
|
295
|
-
g.with(this);
|
|
296
|
-
if (typeof callback === 'function') {
|
|
297
|
-
callback(g);
|
|
298
|
-
}
|
|
299
|
-
return g;
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
function createModelFactories(strict, context = index_js.RootModelsContext) {
|
|
303
|
-
return Object.freeze({
|
|
304
|
-
digraph: ModelFactoryBuilder.call(context, true, strict),
|
|
305
|
-
graph: ModelFactoryBuilder.call(context, false, strict),
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const noStrict = createModelFactories(false);
|
|
310
|
-
const digraph = noStrict.digraph;
|
|
311
|
-
const graph = noStrict.graph;
|
|
312
|
-
const strict = createModelFactories(true);
|
|
313
|
-
function withContext(models) {
|
|
314
|
-
const context = index_js.createModelsContext(models);
|
|
315
|
-
return Object.freeze({
|
|
316
|
-
...createModelFactories(false, context),
|
|
317
|
-
strict: createModelFactories(true, context),
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function toDot(model, options) {
|
|
322
|
-
const ast = index_js$1.fromModel(model, options?.convert);
|
|
323
|
-
return index_js$1.stringify(ast, options?.print);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function fromDot(dot, options) {
|
|
327
|
-
const ast = index_js$1.parse(dot, options?.parse);
|
|
328
|
-
if (
|
|
329
|
-
Array.isArray(ast) ||
|
|
330
|
-
ast.type === 'Attribute' ||
|
|
331
|
-
ast.type === 'AttributeList' ||
|
|
332
|
-
ast.type === 'Comment' ||
|
|
333
|
-
ast.type === 'NodeRef' ||
|
|
334
|
-
ast.type === 'NodeRefGroup' ||
|
|
335
|
-
ast.type === 'Literal'
|
|
336
|
-
) {
|
|
337
|
-
throw new Error();
|
|
338
|
-
}
|
|
339
|
-
return index_js$1.toModel(ast, options?.convert);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
exports.AttributeList = AttributeList;
|
|
343
|
-
exports.AttributesBase = AttributesBase;
|
|
344
|
-
exports.AttributesGroup = AttributesGroup;
|
|
345
|
-
exports.Digraph = Digraph;
|
|
346
|
-
exports.DotObject = DotObject;
|
|
347
|
-
exports.Edge = Edge;
|
|
348
|
-
exports.Graph = Graph;
|
|
349
|
-
exports.GraphBase = GraphBase;
|
|
350
|
-
exports.Node = Node;
|
|
351
|
-
exports.RootGraph = RootGraph;
|
|
352
|
-
exports.Subgraph = Subgraph;
|
|
353
|
-
exports.attribute = attribute;
|
|
354
|
-
exports.digraph = digraph;
|
|
355
|
-
exports.fromDot = fromDot;
|
|
356
|
-
exports.graph = graph;
|
|
357
|
-
exports.strict = strict;
|
|
358
|
-
exports.toDot = toDot;
|
|
359
|
-
exports.withContext = withContext;
|