@graffy/link 0.15.21-alpha.2 → 0.15.21
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/index.cjs +34 -46
- package/index.mjs +34 -46
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -29,38 +29,27 @@ function linkGraph(rootGraph, defs) {
|
|
|
29
29
|
for (const { path, def } of defs) {
|
|
30
30
|
const braid = def.map(getChoices);
|
|
31
31
|
const strands = unbraid(braid);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const nextTarget = target[common.findFirst(target, key)];
|
|
54
|
-
if (!nextTarget || nextTarget.key !== key || nextTarget.end) {
|
|
55
|
-
realPath.unshift(key);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
target = nextTarget.path ? common.unwrap(rootGraph, nextTarget.path) : nextTarget.children;
|
|
59
|
-
} while (target && realPath.length);
|
|
60
|
-
if (!target)
|
|
61
|
-
return;
|
|
62
|
-
common.merge(target, realPath.length ? common.wrap([node], realPath, version) : [node]);
|
|
63
|
-
}
|
|
32
|
+
for (const { value, vars } of strands) {
|
|
33
|
+
const realPath = makeRef(path, vars);
|
|
34
|
+
const realRef = makeRef(value, vars);
|
|
35
|
+
const node = { key: realPath.pop(), path: common.encodePath(realRef), version };
|
|
36
|
+
const [range] = common.splitRef(realRef);
|
|
37
|
+
if (range)
|
|
38
|
+
node.prefix = true;
|
|
39
|
+
let target = rootGraph;
|
|
40
|
+
do {
|
|
41
|
+
const key = realPath.shift();
|
|
42
|
+
const nextTarget = target[common.findFirst(target, key)];
|
|
43
|
+
if (!nextTarget || nextTarget.key !== key || nextTarget.end) {
|
|
44
|
+
realPath.unshift(key);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
target = nextTarget.path ? common.unwrap(rootGraph, nextTarget.path) : nextTarget.children;
|
|
48
|
+
} while (target && realPath.length);
|
|
49
|
+
if (!target)
|
|
50
|
+
return;
|
|
51
|
+
common.merge(target, realPath.length ? common.wrap([node], realPath, version) : [node]);
|
|
52
|
+
}
|
|
64
53
|
}
|
|
65
54
|
return rootGraph;
|
|
66
55
|
function getChoices(key) {
|
|
@@ -68,12 +57,17 @@ function linkGraph(rootGraph, defs) {
|
|
|
68
57
|
return lookupValues(rootGraph, key.slice(2).split("."));
|
|
69
58
|
}
|
|
70
59
|
if (Array.isArray(key)) {
|
|
60
|
+
if (!key.length)
|
|
61
|
+
return [{ value: [], vars: {} }];
|
|
71
62
|
return unbraid(key.map(getChoices));
|
|
72
63
|
}
|
|
73
64
|
if (typeof key === "object" && key) {
|
|
74
|
-
const [range = {}, filter] = common.splitArgs(key);
|
|
75
|
-
const entries =
|
|
76
|
-
|
|
65
|
+
const [range = {}, filter = {}] = common.splitArgs(key);
|
|
66
|
+
const entries = Object.entries(filter).flat();
|
|
67
|
+
if (!entries.length)
|
|
68
|
+
return [{ value: {}, vars: {} }];
|
|
69
|
+
const strands = unbraid(entries.map(getChoices));
|
|
70
|
+
return strands.map(({ value, vars }) => ({
|
|
77
71
|
value: __spreadValues(__spreadValues({}, range), Object.fromEntries(value.reduce((acc, item, i) => {
|
|
78
72
|
if (i % 2) {
|
|
79
73
|
acc[acc.length - 1].push(item);
|
|
@@ -82,14 +76,10 @@ function linkGraph(rootGraph, defs) {
|
|
|
82
76
|
}
|
|
83
77
|
return acc;
|
|
84
78
|
}, []))),
|
|
85
|
-
vars
|
|
86
|
-
reqs
|
|
79
|
+
vars
|
|
87
80
|
}));
|
|
88
81
|
}
|
|
89
|
-
|
|
90
|
-
return [{ value: key, vars: {}, reqs: { [key.slice(1)]: true } }];
|
|
91
|
-
}
|
|
92
|
-
return [{ value: key, vars: {}, reqs: {} }];
|
|
82
|
+
return [{ value: key, vars: {} }];
|
|
93
83
|
}
|
|
94
84
|
function lookupValues(graph, path, vars = {}) {
|
|
95
85
|
const [key, ...rest] = path;
|
|
@@ -108,7 +98,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
108
98
|
}
|
|
109
99
|
function recurse(node, path, vars) {
|
|
110
100
|
if (!path.length)
|
|
111
|
-
return [{ value: node.value, vars
|
|
101
|
+
return [{ value: node.value, vars }];
|
|
112
102
|
if (node.children)
|
|
113
103
|
return lookupValues(node.children, path, vars);
|
|
114
104
|
if (node.path) {
|
|
@@ -126,15 +116,13 @@ function unbraid(braid) {
|
|
|
126
116
|
if (!rest.length) {
|
|
127
117
|
return options.map((option) => ({
|
|
128
118
|
value: [option.value],
|
|
129
|
-
vars: option.vars
|
|
130
|
-
reqs: option.reqs
|
|
119
|
+
vars: option.vars
|
|
131
120
|
}));
|
|
132
121
|
}
|
|
133
122
|
const strands = unbraid(rest);
|
|
134
123
|
return options.flatMap((option) => strands.filter((strand) => isCompatible(option.vars, strand.vars)).map((strand) => ({
|
|
135
124
|
value: [option.value, ...strand.value],
|
|
136
|
-
vars: __spreadValues(__spreadValues({}, option.vars), strand.vars)
|
|
137
|
-
reqs: __spreadValues(__spreadValues({}, option.reqs), strand.reqs)
|
|
125
|
+
vars: __spreadValues(__spreadValues({}, option.vars), strand.vars)
|
|
138
126
|
})));
|
|
139
127
|
}
|
|
140
128
|
function isCompatible(oVars, sVars) {
|
package/index.mjs
CHANGED
|
@@ -24,38 +24,27 @@ function linkGraph(rootGraph, defs) {
|
|
|
24
24
|
for (const { path, def } of defs) {
|
|
25
25
|
const braid = def.map(getChoices);
|
|
26
26
|
const strands = unbraid(braid);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const nextTarget = target[findFirst(target, key)];
|
|
49
|
-
if (!nextTarget || nextTarget.key !== key || nextTarget.end) {
|
|
50
|
-
realPath.unshift(key);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
target = nextTarget.path ? unwrap(rootGraph, nextTarget.path) : nextTarget.children;
|
|
54
|
-
} while (target && realPath.length);
|
|
55
|
-
if (!target)
|
|
56
|
-
return;
|
|
57
|
-
merge(target, realPath.length ? wrap([node], realPath, version) : [node]);
|
|
58
|
-
}
|
|
27
|
+
for (const { value, vars } of strands) {
|
|
28
|
+
const realPath = makeRef(path, vars);
|
|
29
|
+
const realRef = makeRef(value, vars);
|
|
30
|
+
const node = { key: realPath.pop(), path: encodePath(realRef), version };
|
|
31
|
+
const [range] = splitRef(realRef);
|
|
32
|
+
if (range)
|
|
33
|
+
node.prefix = true;
|
|
34
|
+
let target = rootGraph;
|
|
35
|
+
do {
|
|
36
|
+
const key = realPath.shift();
|
|
37
|
+
const nextTarget = target[findFirst(target, key)];
|
|
38
|
+
if (!nextTarget || nextTarget.key !== key || nextTarget.end) {
|
|
39
|
+
realPath.unshift(key);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
target = nextTarget.path ? unwrap(rootGraph, nextTarget.path) : nextTarget.children;
|
|
43
|
+
} while (target && realPath.length);
|
|
44
|
+
if (!target)
|
|
45
|
+
return;
|
|
46
|
+
merge(target, realPath.length ? wrap([node], realPath, version) : [node]);
|
|
47
|
+
}
|
|
59
48
|
}
|
|
60
49
|
return rootGraph;
|
|
61
50
|
function getChoices(key) {
|
|
@@ -63,12 +52,17 @@ function linkGraph(rootGraph, defs) {
|
|
|
63
52
|
return lookupValues(rootGraph, key.slice(2).split("."));
|
|
64
53
|
}
|
|
65
54
|
if (Array.isArray(key)) {
|
|
55
|
+
if (!key.length)
|
|
56
|
+
return [{ value: [], vars: {} }];
|
|
66
57
|
return unbraid(key.map(getChoices));
|
|
67
58
|
}
|
|
68
59
|
if (typeof key === "object" && key) {
|
|
69
|
-
const [range = {}, filter] = splitArgs(key);
|
|
70
|
-
const entries =
|
|
71
|
-
|
|
60
|
+
const [range = {}, filter = {}] = splitArgs(key);
|
|
61
|
+
const entries = Object.entries(filter).flat();
|
|
62
|
+
if (!entries.length)
|
|
63
|
+
return [{ value: {}, vars: {} }];
|
|
64
|
+
const strands = unbraid(entries.map(getChoices));
|
|
65
|
+
return strands.map(({ value, vars }) => ({
|
|
72
66
|
value: __spreadValues(__spreadValues({}, range), Object.fromEntries(value.reduce((acc, item, i) => {
|
|
73
67
|
if (i % 2) {
|
|
74
68
|
acc[acc.length - 1].push(item);
|
|
@@ -77,14 +71,10 @@ function linkGraph(rootGraph, defs) {
|
|
|
77
71
|
}
|
|
78
72
|
return acc;
|
|
79
73
|
}, []))),
|
|
80
|
-
vars
|
|
81
|
-
reqs
|
|
74
|
+
vars
|
|
82
75
|
}));
|
|
83
76
|
}
|
|
84
|
-
|
|
85
|
-
return [{ value: key, vars: {}, reqs: { [key.slice(1)]: true } }];
|
|
86
|
-
}
|
|
87
|
-
return [{ value: key, vars: {}, reqs: {} }];
|
|
77
|
+
return [{ value: key, vars: {} }];
|
|
88
78
|
}
|
|
89
79
|
function lookupValues(graph, path, vars = {}) {
|
|
90
80
|
const [key, ...rest] = path;
|
|
@@ -103,7 +93,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
103
93
|
}
|
|
104
94
|
function recurse(node, path, vars) {
|
|
105
95
|
if (!path.length)
|
|
106
|
-
return [{ value: node.value, vars
|
|
96
|
+
return [{ value: node.value, vars }];
|
|
107
97
|
if (node.children)
|
|
108
98
|
return lookupValues(node.children, path, vars);
|
|
109
99
|
if (node.path) {
|
|
@@ -121,15 +111,13 @@ function unbraid(braid) {
|
|
|
121
111
|
if (!rest.length) {
|
|
122
112
|
return options.map((option) => ({
|
|
123
113
|
value: [option.value],
|
|
124
|
-
vars: option.vars
|
|
125
|
-
reqs: option.reqs
|
|
114
|
+
vars: option.vars
|
|
126
115
|
}));
|
|
127
116
|
}
|
|
128
117
|
const strands = unbraid(rest);
|
|
129
118
|
return options.flatMap((option) => strands.filter((strand) => isCompatible(option.vars, strand.vars)).map((strand) => ({
|
|
130
119
|
value: [option.value, ...strand.value],
|
|
131
|
-
vars: __spreadValues(__spreadValues({}, option.vars), strand.vars)
|
|
132
|
-
reqs: __spreadValues(__spreadValues({}, option.reqs), strand.reqs)
|
|
120
|
+
vars: __spreadValues(__spreadValues({}, option.vars), strand.vars)
|
|
133
121
|
})));
|
|
134
122
|
}
|
|
135
123
|
function isCompatible(oVars, sVars) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graffy/link",
|
|
3
3
|
"description": "Graffy module for constructing links using an intuitive, declarative notation.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.15.21
|
|
5
|
+
"version": "0.15.21",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.15.21
|
|
19
|
+
"@graffy/common": "0.15.21",
|
|
20
20
|
"debug": "^4.3.3"
|
|
21
21
|
}
|
|
22
22
|
}
|