@ts-graphviz/common 0.0.0-next-20240301111950
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 +295 -0
- package/LICENSE +22 -0
- package/README.md +47 -0
- package/lib/common.cjs +94 -0
- package/lib/common.d.ts +3916 -0
- package/lib/common.js +94 -0
- package/package.json +62 -0
package/lib/common.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
function _pipe(...args) {
|
|
2
|
+
const [o1, ...operations] = args;
|
|
3
|
+
return (...t) => operations.reduce((acc, f) => f(acc), o1(...t));
|
|
4
|
+
}
|
|
5
|
+
function pipe(o1, ...operations) {
|
|
6
|
+
return _pipe(o1, ...operations);
|
|
7
|
+
}
|
|
8
|
+
const defer = (fn) => (...args) => (src) => fn(src, ...args);
|
|
9
|
+
const toIterable = (f) => ({
|
|
10
|
+
[Symbol.iterator]: f
|
|
11
|
+
});
|
|
12
|
+
const map = defer(
|
|
13
|
+
(src, selector) => Array.from(
|
|
14
|
+
toIterable(function* () {
|
|
15
|
+
for (const v of src) {
|
|
16
|
+
yield selector(v);
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
const filter = defer(
|
|
22
|
+
(src, pred) => Array.from(
|
|
23
|
+
toIterable(function* () {
|
|
24
|
+
for (const x of src) {
|
|
25
|
+
if (pred(x)) {
|
|
26
|
+
yield x;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
const RootModelsContext = Object.seal({
|
|
33
|
+
// NOTE: RootModelsContext is also initialized after the model class is declared in the '@ts-graphviz/core/register-default' module.
|
|
34
|
+
Graph: null,
|
|
35
|
+
Digraph: null,
|
|
36
|
+
Subgraph: null,
|
|
37
|
+
Node: null,
|
|
38
|
+
Edge: null
|
|
39
|
+
});
|
|
40
|
+
function createModelsContext(models) {
|
|
41
|
+
return Object.assign(
|
|
42
|
+
Object.seal(Object.assign({}, RootModelsContext)),
|
|
43
|
+
models
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function isForwardRefNode(object) {
|
|
47
|
+
return typeof object === "object" && object !== null && typeof object.id === "string";
|
|
48
|
+
}
|
|
49
|
+
function isNodeModel(object) {
|
|
50
|
+
return typeof object === "object" && object !== null && object.$$type === "Node" && typeof object.id === "string";
|
|
51
|
+
}
|
|
52
|
+
function isNodeRef(node) {
|
|
53
|
+
return isNodeModel(node) || isForwardRefNode(node);
|
|
54
|
+
}
|
|
55
|
+
function isNodeRefLike(node) {
|
|
56
|
+
return typeof node === "string" || isNodeRef(node);
|
|
57
|
+
}
|
|
58
|
+
function isNodeRefGroupLike(target) {
|
|
59
|
+
return Array.isArray(target) && target.every(isNodeRefLike);
|
|
60
|
+
}
|
|
61
|
+
function isCompass(c) {
|
|
62
|
+
return ["n", "ne", "e", "se", "s", "sw", "w", "nw", "c"].includes(c);
|
|
63
|
+
}
|
|
64
|
+
function toNodeRef(target) {
|
|
65
|
+
if (isNodeRef(target)) {
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
const [id, port, compass] = target.split(":");
|
|
69
|
+
if (isCompass(compass)) {
|
|
70
|
+
return { id, port, compass };
|
|
71
|
+
}
|
|
72
|
+
return { id, port };
|
|
73
|
+
}
|
|
74
|
+
function toNodeRefGroup(targets) {
|
|
75
|
+
if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
|
|
76
|
+
throw Error("EdgeTargets must have at least 2 elements.");
|
|
77
|
+
}
|
|
78
|
+
return targets.map((t) => toNodeRef(t));
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
RootModelsContext,
|
|
82
|
+
createModelsContext,
|
|
83
|
+
filter,
|
|
84
|
+
isCompass,
|
|
85
|
+
isForwardRefNode,
|
|
86
|
+
isNodeModel,
|
|
87
|
+
isNodeRef,
|
|
88
|
+
isNodeRefGroupLike,
|
|
89
|
+
isNodeRefLike,
|
|
90
|
+
map,
|
|
91
|
+
pipe,
|
|
92
|
+
toNodeRef,
|
|
93
|
+
toNodeRefGroup
|
|
94
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-graphviz/common",
|
|
3
|
+
"version": "0.0.0-next-20240301111950",
|
|
4
|
+
"description": "Graphviz Types and Utilities",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"graphviz",
|
|
7
|
+
"dot"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/ts-graphviz/ts-graphviz#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/ts-graphviz/ts-graphviz/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/ts-graphviz/ts-graphviz.git",
|
|
16
|
+
"directory": "packages/common"
|
|
17
|
+
},
|
|
18
|
+
"funding": [
|
|
19
|
+
{
|
|
20
|
+
"type": "github",
|
|
21
|
+
"url": "https://github.com/sponsors/ts-graphviz"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "opencollective",
|
|
25
|
+
"url": "https://opencollective.com/ts-graphviz"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Yuki Yamazaki <yuki@kamiazya.tech>",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./lib/common.d.ts",
|
|
35
|
+
"default": "./lib/common.cjs"
|
|
36
|
+
},
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./lib/common.d.ts",
|
|
39
|
+
"default": "./lib/common.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"main": "lib/common.cjs",
|
|
45
|
+
"module": "lib/common.js",
|
|
46
|
+
"types": "lib/common.d.ts",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"typescript": "^5.3.3",
|
|
49
|
+
"vite": "^5.1.3",
|
|
50
|
+
"vite-plugin-dts": "^3.7.2"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "vite build"
|
|
61
|
+
}
|
|
62
|
+
}
|