@graffy/link 0.15.25-alpha.1 → 0.15.25-alpha.3
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 +54 -44
- package/index.mjs +52 -38
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var common = require("@graffy/common");
|
|
22
|
-
var debug = require("debug");
|
|
23
|
-
function _interopDefaultLegacy(e) {
|
|
24
|
-
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
25
|
-
}
|
|
26
|
-
var debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
|
|
2
|
+
const common = require("@graffy/common");
|
|
3
|
+
const debug = require("debug");
|
|
4
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
5
|
+
const debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
|
|
27
6
|
function linkGraph(rootGraph, defs) {
|
|
28
7
|
let version = rootGraph[0].version;
|
|
29
8
|
for (const { path, def } of defs) {
|
|
@@ -68,14 +47,19 @@ function linkGraph(rootGraph, defs) {
|
|
|
68
47
|
return [{ value: {}, vars: {} }];
|
|
69
48
|
const strands = unbraid(entries.map(getChoices));
|
|
70
49
|
return strands.map(({ value, vars }) => ({
|
|
71
|
-
value:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
50
|
+
value: {
|
|
51
|
+
...range,
|
|
52
|
+
...Object.fromEntries(
|
|
53
|
+
value.reduce((acc, item, i) => {
|
|
54
|
+
if (i % 2) {
|
|
55
|
+
acc[acc.length - 1].push(item);
|
|
56
|
+
} else {
|
|
57
|
+
acc.push([item]);
|
|
58
|
+
}
|
|
59
|
+
return acc;
|
|
60
|
+
}, [])
|
|
61
|
+
)
|
|
62
|
+
},
|
|
79
63
|
vars
|
|
80
64
|
}));
|
|
81
65
|
}
|
|
@@ -87,7 +71,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
87
71
|
return graph.flatMap((node2) => {
|
|
88
72
|
if (node2.end)
|
|
89
73
|
return [];
|
|
90
|
-
const newVars =
|
|
74
|
+
const newVars = { ...vars, [key.slice(1)]: node2.key };
|
|
91
75
|
return recurse(node2, rest, newVars);
|
|
92
76
|
});
|
|
93
77
|
}
|
|
@@ -120,10 +104,12 @@ function unbraid(braid) {
|
|
|
120
104
|
}));
|
|
121
105
|
}
|
|
122
106
|
const strands = unbraid(rest);
|
|
123
|
-
return options.flatMap(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
return options.flatMap(
|
|
108
|
+
(option) => strands.filter((strand) => isCompatible(option.vars, strand.vars)).map((strand) => ({
|
|
109
|
+
value: [option.value, ...strand.value],
|
|
110
|
+
vars: { ...option.vars, ...strand.vars }
|
|
111
|
+
}))
|
|
112
|
+
);
|
|
127
113
|
}
|
|
128
114
|
function isCompatible(oVars, sVars) {
|
|
129
115
|
for (const name in oVars) {
|
|
@@ -164,11 +150,20 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
164
150
|
if (range && subQuery.length) {
|
|
165
151
|
return subQuery.map((node) => {
|
|
166
152
|
if (!node.prefix && !node.end) {
|
|
167
|
-
throw Error(
|
|
153
|
+
throw Error(
|
|
154
|
+
"link.range_expected: " + path.concat(node.key).join(".")
|
|
155
|
+
);
|
|
168
156
|
}
|
|
169
157
|
return {
|
|
170
158
|
path: path.concat(node.key),
|
|
171
|
-
def: prepareDef(
|
|
159
|
+
def: prepareDef(
|
|
160
|
+
def.slice(0, -1).concat({
|
|
161
|
+
...filter,
|
|
162
|
+
...node.prefix ? common.decodeArgs(node) : {},
|
|
163
|
+
...range
|
|
164
|
+
}),
|
|
165
|
+
vars
|
|
166
|
+
)
|
|
172
167
|
};
|
|
173
168
|
});
|
|
174
169
|
} else {
|
|
@@ -211,10 +206,25 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
211
206
|
if (node.prefix) {
|
|
212
207
|
usedHere = node.children.flatMap((subNode) => {
|
|
213
208
|
const pager = makePager(common.decodeArgs(subNode));
|
|
214
|
-
return prefixKey(
|
|
209
|
+
return prefixKey(
|
|
210
|
+
prepQueryDef(
|
|
211
|
+
subNode.children,
|
|
212
|
+
rest,
|
|
213
|
+
def,
|
|
214
|
+
{ ...vars, [key.slice(1)]: [node.key, pager] },
|
|
215
|
+
node.version
|
|
216
|
+
),
|
|
217
|
+
key
|
|
218
|
+
);
|
|
215
219
|
});
|
|
216
220
|
} else {
|
|
217
|
-
usedHere = prepQueryDef(
|
|
221
|
+
usedHere = prepQueryDef(
|
|
222
|
+
node.children,
|
|
223
|
+
rest,
|
|
224
|
+
def,
|
|
225
|
+
{ ...vars, [key.slice(1)]: node.key },
|
|
226
|
+
node.version
|
|
227
|
+
);
|
|
218
228
|
}
|
|
219
229
|
usedHere = prefixKey(usedHere, node.key);
|
|
220
230
|
used = used.concat(usedHere);
|
|
@@ -285,8 +295,8 @@ function prepareDef(def, vars) {
|
|
|
285
295
|
const ref = def.map(replacePlaceholders);
|
|
286
296
|
return ref;
|
|
287
297
|
}
|
|
288
|
-
const log = debug__default
|
|
289
|
-
|
|
298
|
+
const log = debug__default.default("graffy:link");
|
|
299
|
+
const index = (defs) => (store) => {
|
|
290
300
|
const prefix = store.path;
|
|
291
301
|
const defEntries = Object.entries(defs).map(([prop, def]) => ({
|
|
292
302
|
path: prop.split("."),
|
package/index.mjs
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
1
|
import { encodePath, splitRef, findFirst, unwrap, merge, wrap, splitArgs, decodeArgs, isBranch, add, wrapValue, finalize } from "@graffy/common";
|
|
21
2
|
import debug from "debug";
|
|
22
3
|
function linkGraph(rootGraph, defs) {
|
|
@@ -63,14 +44,19 @@ function linkGraph(rootGraph, defs) {
|
|
|
63
44
|
return [{ value: {}, vars: {} }];
|
|
64
45
|
const strands = unbraid(entries.map(getChoices));
|
|
65
46
|
return strands.map(({ value, vars }) => ({
|
|
66
|
-
value:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
value: {
|
|
48
|
+
...range,
|
|
49
|
+
...Object.fromEntries(
|
|
50
|
+
value.reduce((acc, item, i) => {
|
|
51
|
+
if (i % 2) {
|
|
52
|
+
acc[acc.length - 1].push(item);
|
|
53
|
+
} else {
|
|
54
|
+
acc.push([item]);
|
|
55
|
+
}
|
|
56
|
+
return acc;
|
|
57
|
+
}, [])
|
|
58
|
+
)
|
|
59
|
+
},
|
|
74
60
|
vars
|
|
75
61
|
}));
|
|
76
62
|
}
|
|
@@ -82,7 +68,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
82
68
|
return graph.flatMap((node2) => {
|
|
83
69
|
if (node2.end)
|
|
84
70
|
return [];
|
|
85
|
-
const newVars =
|
|
71
|
+
const newVars = { ...vars, [key.slice(1)]: node2.key };
|
|
86
72
|
return recurse(node2, rest, newVars);
|
|
87
73
|
});
|
|
88
74
|
}
|
|
@@ -115,10 +101,12 @@ function unbraid(braid) {
|
|
|
115
101
|
}));
|
|
116
102
|
}
|
|
117
103
|
const strands = unbraid(rest);
|
|
118
|
-
return options.flatMap(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
104
|
+
return options.flatMap(
|
|
105
|
+
(option) => strands.filter((strand) => isCompatible(option.vars, strand.vars)).map((strand) => ({
|
|
106
|
+
value: [option.value, ...strand.value],
|
|
107
|
+
vars: { ...option.vars, ...strand.vars }
|
|
108
|
+
}))
|
|
109
|
+
);
|
|
122
110
|
}
|
|
123
111
|
function isCompatible(oVars, sVars) {
|
|
124
112
|
for (const name in oVars) {
|
|
@@ -159,11 +147,20 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
159
147
|
if (range && subQuery.length) {
|
|
160
148
|
return subQuery.map((node) => {
|
|
161
149
|
if (!node.prefix && !node.end) {
|
|
162
|
-
throw Error(
|
|
150
|
+
throw Error(
|
|
151
|
+
"link.range_expected: " + path.concat(node.key).join(".")
|
|
152
|
+
);
|
|
163
153
|
}
|
|
164
154
|
return {
|
|
165
155
|
path: path.concat(node.key),
|
|
166
|
-
def: prepareDef(
|
|
156
|
+
def: prepareDef(
|
|
157
|
+
def.slice(0, -1).concat({
|
|
158
|
+
...filter,
|
|
159
|
+
...node.prefix ? decodeArgs(node) : {},
|
|
160
|
+
...range
|
|
161
|
+
}),
|
|
162
|
+
vars
|
|
163
|
+
)
|
|
167
164
|
};
|
|
168
165
|
});
|
|
169
166
|
} else {
|
|
@@ -206,10 +203,25 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
206
203
|
if (node.prefix) {
|
|
207
204
|
usedHere = node.children.flatMap((subNode) => {
|
|
208
205
|
const pager = makePager(decodeArgs(subNode));
|
|
209
|
-
return prefixKey(
|
|
206
|
+
return prefixKey(
|
|
207
|
+
prepQueryDef(
|
|
208
|
+
subNode.children,
|
|
209
|
+
rest,
|
|
210
|
+
def,
|
|
211
|
+
{ ...vars, [key.slice(1)]: [node.key, pager] },
|
|
212
|
+
node.version
|
|
213
|
+
),
|
|
214
|
+
key
|
|
215
|
+
);
|
|
210
216
|
});
|
|
211
217
|
} else {
|
|
212
|
-
usedHere = prepQueryDef(
|
|
218
|
+
usedHere = prepQueryDef(
|
|
219
|
+
node.children,
|
|
220
|
+
rest,
|
|
221
|
+
def,
|
|
222
|
+
{ ...vars, [key.slice(1)]: node.key },
|
|
223
|
+
node.version
|
|
224
|
+
);
|
|
213
225
|
}
|
|
214
226
|
usedHere = prefixKey(usedHere, node.key);
|
|
215
227
|
used = used.concat(usedHere);
|
|
@@ -281,7 +293,7 @@ function prepareDef(def, vars) {
|
|
|
281
293
|
return ref;
|
|
282
294
|
}
|
|
283
295
|
const log = debug("graffy:link");
|
|
284
|
-
|
|
296
|
+
const index = (defs) => (store) => {
|
|
285
297
|
const prefix = store.path;
|
|
286
298
|
const defEntries = Object.entries(defs).map(([prop, def]) => ({
|
|
287
299
|
path: prop.split("."),
|
|
@@ -307,4 +319,6 @@ var index = (defs) => (store) => {
|
|
|
307
319
|
function clone(tree) {
|
|
308
320
|
return JSON.parse(JSON.stringify(tree));
|
|
309
321
|
}
|
|
310
|
-
export {
|
|
322
|
+
export {
|
|
323
|
+
index as default
|
|
324
|
+
};
|
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.25-alpha.
|
|
5
|
+
"version": "0.15.25-alpha.3",
|
|
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.25-alpha.
|
|
19
|
+
"@graffy/common": "0.15.25-alpha.3",
|
|
20
20
|
"debug": "^4.3.3"
|
|
21
21
|
}
|
|
22
22
|
}
|