@graffy/link 0.16.1 → 0.16.2
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 +6 -8
- package/index.mjs +5 -5
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const common = require("@graffy/common");
|
|
3
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);
|
|
6
4
|
function linkGraph(rootGraph, defs) {
|
|
7
5
|
let version = rootGraph[0].version;
|
|
8
6
|
for (const { path, def } of defs) {
|
|
@@ -91,7 +89,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
91
89
|
if (Array.isArray(linked))
|
|
92
90
|
return lookupValues(linked, path, vars);
|
|
93
91
|
}
|
|
94
|
-
throw Error(
|
|
92
|
+
throw Error(`link.no_children ${JSON.stringify(node)}`);
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
function unbraid(braid) {
|
|
@@ -148,9 +146,9 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
148
146
|
const [range, filter] = common.splitRef(def);
|
|
149
147
|
if (range && subQuery.length) {
|
|
150
148
|
return subQuery.map((node) => {
|
|
151
|
-
if (!node.prefix
|
|
149
|
+
if (!(node.prefix || node.end)) {
|
|
152
150
|
throw Error(
|
|
153
|
-
|
|
151
|
+
`link.range_expected: ${path.concat(node.key).join(".")}`
|
|
154
152
|
);
|
|
155
153
|
}
|
|
156
154
|
return {
|
|
@@ -175,7 +173,7 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
175
173
|
def: def2
|
|
176
174
|
}));
|
|
177
175
|
}
|
|
178
|
-
if (!Array.isArray(query)
|
|
176
|
+
if (!(Array.isArray(query) && query.length))
|
|
179
177
|
return [];
|
|
180
178
|
const [key, ...rest] = path;
|
|
181
179
|
const encodedKey = common.encodeArgs(key).key;
|
|
@@ -292,7 +290,7 @@ function prepareDef(def, vars) {
|
|
|
292
290
|
}
|
|
293
291
|
function replacePlaceholders(key) {
|
|
294
292
|
if (typeof key === "string" && key[0] === "$" && key[1] === "$") {
|
|
295
|
-
return
|
|
293
|
+
return `$$${key.slice(2).split(".").flatMap(getValue).join(".")}`;
|
|
296
294
|
}
|
|
297
295
|
if (Array.isArray(key)) {
|
|
298
296
|
return key.map(replacePlaceholders);
|
|
@@ -309,7 +307,7 @@ function prepareDef(def, vars) {
|
|
|
309
307
|
const ref = def.map(replacePlaceholders);
|
|
310
308
|
return ref;
|
|
311
309
|
}
|
|
312
|
-
const log =
|
|
310
|
+
const log = debug("graffy:link");
|
|
313
311
|
const index = (defs) => (store) => {
|
|
314
312
|
const prefix = common.encodePath(store.path);
|
|
315
313
|
const defEntries = Object.entries(defs).map(([prop, def]) => ({
|
package/index.mjs
CHANGED
|
@@ -88,7 +88,7 @@ function linkGraph(rootGraph, defs) {
|
|
|
88
88
|
if (Array.isArray(linked))
|
|
89
89
|
return lookupValues(linked, path, vars);
|
|
90
90
|
}
|
|
91
|
-
throw Error(
|
|
91
|
+
throw Error(`link.no_children ${JSON.stringify(node)}`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
function unbraid(braid) {
|
|
@@ -145,9 +145,9 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
145
145
|
const [range, filter] = splitRef(def);
|
|
146
146
|
if (range && subQuery.length) {
|
|
147
147
|
return subQuery.map((node) => {
|
|
148
|
-
if (!node.prefix
|
|
148
|
+
if (!(node.prefix || node.end)) {
|
|
149
149
|
throw Error(
|
|
150
|
-
|
|
150
|
+
`link.range_expected: ${path.concat(node.key).join(".")}`
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
return {
|
|
@@ -172,7 +172,7 @@ function prepQueryLinks(rootQuery, defs) {
|
|
|
172
172
|
def: def2
|
|
173
173
|
}));
|
|
174
174
|
}
|
|
175
|
-
if (!Array.isArray(query)
|
|
175
|
+
if (!(Array.isArray(query) && query.length))
|
|
176
176
|
return [];
|
|
177
177
|
const [key, ...rest] = path;
|
|
178
178
|
const encodedKey = encodeArgs(key).key;
|
|
@@ -289,7 +289,7 @@ function prepareDef(def, vars) {
|
|
|
289
289
|
}
|
|
290
290
|
function replacePlaceholders(key) {
|
|
291
291
|
if (typeof key === "string" && key[0] === "$" && key[1] === "$") {
|
|
292
|
-
return
|
|
292
|
+
return `$$${key.slice(2).split(".").flatMap(getValue).join(".")}`;
|
|
293
293
|
}
|
|
294
294
|
if (Array.isArray(key)) {
|
|
295
295
|
return key.map(replacePlaceholders);
|
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.16.
|
|
5
|
+
"version": "0.16.2",
|
|
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.16.
|
|
19
|
+
"@graffy/common": "0.16.2",
|
|
20
20
|
"debug": "^4.3.3"
|
|
21
21
|
}
|
|
22
22
|
}
|