@thi.ng/rstream-dot 3.0.36 → 3.0.38

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-18T13:41:20Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -55,7 +55,7 @@ For Node.js REPL:
55
55
  const rstreamDot = await import("@thi.ng/rstream-dot");
56
56
  ```
57
57
 
58
- Package sizes (brotli'd, pre-treeshake): ESM: 807 bytes
58
+ Package sizes (brotli'd, pre-treeshake): ESM: 806 bytes
59
59
 
60
60
  ## Dependencies
61
61
 
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/index.js CHANGED
@@ -4,98 +4,88 @@ import { StreamSync } from "@thi.ng/rstream/sync";
4
4
  import { truncate } from "@thi.ng/strings/truncate";
5
5
  import { map } from "@thi.ng/transducers/map";
6
6
  export * from "./api.js";
7
- const getNodeType = (sub) => sub instanceof Stream
8
- ? "Stream"
9
- : sub instanceof StreamSync
10
- ? "StreamSync"
11
- : sub instanceof StreamMerge
12
- ? "StreamMerge"
13
- : undefined;
7
+ const getNodeType = (sub) => sub instanceof Stream ? "Stream" : sub instanceof StreamSync ? "StreamSync" : sub instanceof StreamMerge ? "StreamMerge" : void 0;
14
8
  const getChildren = (sub) => {
15
- let children = [];
16
- if (sub.subs)
17
- children.push(...sub.subs);
18
- if (sub.__owner)
19
- children.push(sub.__owner);
20
- if (sub.wrapped)
21
- children.push(...getChildren(sub.wrapped));
22
- return children;
9
+ let children = [];
10
+ if (sub.subs)
11
+ children.push(...sub.subs);
12
+ if (sub.__owner)
13
+ children.push(sub.__owner);
14
+ if (sub.wrapped)
15
+ children.push(...getChildren(sub.wrapped));
16
+ return children;
23
17
  };
24
18
  const dotNode = (s, opts) => {
25
- let res = `s${s.id}[label="`;
26
- res += s.type ? `${s.label}\\n(${s.type})` : `${s.label}`;
27
- if (s.body !== undefined) {
28
- res += `\\n${s.body.replace(/"/g, `'`).replace(/\n/g, "\\n")}`;
29
- }
30
- res += `", color="`;
31
- res +=
32
- (s.type && opts.color[s.type.toLowerCase()]) ||
33
- (s.label === "<noid>" ? opts.color.noid : opts.color.default);
34
- return res + `"];`;
19
+ let res = `s${s.id}[label="`;
20
+ res += s.type ? `${s.label}\\n(${s.type})` : `${s.label}`;
21
+ if (s.body !== void 0) {
22
+ res += `\\n${s.body.replace(/"/g, `'`).replace(/\n/g, "\\n")}`;
23
+ }
24
+ res += `", color="`;
25
+ res += s.type && opts.color[s.type.toLowerCase()] || (s.label === "<noid>" ? opts.color.noid : opts.color.default);
26
+ return res + `"];`;
35
27
  };
36
28
  const dotEdge = (a, b, _) => `s${a.id} -> s${b.id}${b.xform ? `[label="xform"]` : ""};`;
37
29
  const subValue = (sub) => {
38
- const res = JSON.stringify(sub.deref ? sub.deref() : undefined);
39
- return res ? truncate(64, "...")(res) : res;
30
+ const res = JSON.stringify(sub.deref ? sub.deref() : void 0);
31
+ return res ? truncate(64, "...")(res) : res;
40
32
  };
41
- export const traverse = (subs, opts, state) => {
42
- opts || (opts = {});
43
- state || (state = { id: 0, subs: new Map(), rels: [] });
44
- for (let sub of subs) {
45
- if (state.subs.get(sub))
46
- return state;
47
- const id = state.id;
48
- const desc = {
49
- id,
50
- label: sub.id || "<noid>",
51
- type: getNodeType(sub),
52
- xform: !!sub.xform,
53
- body: opts.values ? subValue(sub) : undefined,
54
- };
55
- state.subs.set(sub, desc);
56
- state.id++;
57
- const children = getChildren(sub);
58
- if (children.length) {
59
- traverse(children, opts, state);
60
- for (let c of children) {
61
- const childNode = state.subs.get(c);
62
- childNode && state.rels.push([desc, childNode]);
63
- }
64
- }
33
+ const traverse = (subs, opts, state) => {
34
+ opts || (opts = {});
35
+ state || (state = { id: 0, subs: /* @__PURE__ */ new Map(), rels: [] });
36
+ for (let sub of subs) {
37
+ if (state.subs.get(sub))
38
+ return state;
39
+ const id = state.id;
40
+ const desc = {
41
+ id,
42
+ label: sub.id || "<noid>",
43
+ type: getNodeType(sub),
44
+ xform: !!sub.xform,
45
+ body: opts.values ? subValue(sub) : void 0
46
+ };
47
+ state.subs.set(sub, desc);
48
+ state.id++;
49
+ const children = getChildren(sub);
50
+ if (children.length) {
51
+ traverse(children, opts, state);
52
+ for (let c of children) {
53
+ const childNode = state.subs.get(c);
54
+ childNode && state.rels.push([desc, childNode]);
55
+ }
65
56
  }
66
- return state;
57
+ }
58
+ return state;
67
59
  };
68
- export const toDot = (state, opts) => {
69
- opts = {
70
- dir: "LR",
71
- font: "sans-serif",
72
- fontsize: 10,
73
- text: "white",
74
- ...opts,
75
- };
76
- opts.color = {
77
- default: "black",
78
- noid: "gray",
79
- stream: "blue",
80
- streammerge: "red",
81
- streamsync: "red",
82
- ...(opts.color || {}),
83
- };
84
- return [
85
- "digraph g {",
86
- `rankdir=${opts.dir};`,
87
- `node[fontname="${opts.font}",fontsize=${opts.fontsize},style=filled,fontcolor=${opts.text}];`,
88
- `edge[fontname="${opts.font}",fontsize=${opts.fontsize}];`,
89
- ...map((n) => dotNode(n, opts), state.subs.values()),
90
- ...map((r) => dotEdge(r[0], r[1], opts), state.rels),
91
- "}",
92
- ].join("\n");
60
+ const toDot = (state, opts) => {
61
+ opts = {
62
+ dir: "LR",
63
+ font: "sans-serif",
64
+ fontsize: 10,
65
+ text: "white",
66
+ ...opts
67
+ };
68
+ opts.color = {
69
+ default: "black",
70
+ noid: "gray",
71
+ stream: "blue",
72
+ streammerge: "red",
73
+ streamsync: "red",
74
+ ...opts.color || {}
75
+ };
76
+ return [
77
+ "digraph g {",
78
+ `rankdir=${opts.dir};`,
79
+ `node[fontname="${opts.font}",fontsize=${opts.fontsize},style=filled,fontcolor=${opts.text}];`,
80
+ `edge[fontname="${opts.font}",fontsize=${opts.fontsize}];`,
81
+ ...map((n) => dotNode(n, opts), state.subs.values()),
82
+ ...map((r) => dotEdge(r[0], r[1], opts), state.rels),
83
+ "}"
84
+ ].join("\n");
85
+ };
86
+ const serialize = (subs, opts) => toDot(traverse(subs, opts), opts);
87
+ export {
88
+ serialize,
89
+ toDot,
90
+ traverse
93
91
  };
94
- /**
95
- * Syntax sugar for the composition {@link traverse} and {@link toDot},
96
- * serializing the traversable graph topology to Graphviz DOT format.
97
- *
98
- * @param subs
99
- * @param opts
100
- */
101
- export const serialize = (subs, opts) => toDot(traverse(subs, opts), opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream-dot",
3
- "version": "3.0.36",
3
+ "version": "3.0.38",
4
4
  "description": "Graphviz DOT conversion of @thi.ng/rstream dataflow graph topologies",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,12 +35,13 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/rstream": "^8.2.13",
37
- "@thi.ng/strings": "^3.7.2",
38
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/rstream": "^8.2.15",
39
+ "@thi.ng/strings": "^3.7.4",
40
+ "@thi.ng/transducers": "^8.8.16"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@microsoft/api-extractor": "^7.38.3",
44
+ "esbuild": "^0.19.8",
42
45
  "rimraf": "^5.0.5",
43
46
  "tools": "^0.0.1",
44
47
  "typedoc": "^0.25.4",
@@ -61,7 +64,7 @@
61
64
  "access": "public"
62
65
  },
63
66
  "engines": {
64
- "node": ">=12.7"
67
+ "node": ">=18"
65
68
  },
66
69
  "files": [
67
70
  "./*.js",
@@ -83,5 +86,5 @@
83
86
  ],
84
87
  "year": 2018
85
88
  },
86
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
89
+ "gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
87
90
  }