@graffy/link 0.15.15-alpha.2 → 0.15.15-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 +14 -2
- package/index.mjs +11 -3
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -19,6 +19,11 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
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);
|
|
22
27
|
function linkGraph(rootGraph, defs) {
|
|
23
28
|
let version = rootGraph[0].version;
|
|
24
29
|
for (const { path, def } of defs) {
|
|
@@ -277,6 +282,7 @@ function prepareDef(def, vars) {
|
|
|
277
282
|
const ref = def.flatMap(replacePlaceholders);
|
|
278
283
|
return ref;
|
|
279
284
|
}
|
|
285
|
+
const log = debug__default["default"]("graffy:link");
|
|
280
286
|
var index = (defs) => (store) => {
|
|
281
287
|
const prefix = store.path;
|
|
282
288
|
const defEntries = Object.entries(defs).map(([prop, def]) => ({
|
|
@@ -286,10 +292,16 @@ var index = (defs) => (store) => {
|
|
|
286
292
|
store.on("read", async (query, options, next) => {
|
|
287
293
|
const unwrappedQuery = clone(common.unwrap(query, prefix));
|
|
288
294
|
const usedDefs = prepQueryLinks(unwrappedQuery, defEntries);
|
|
295
|
+
if (!usedDefs.length)
|
|
296
|
+
return next(query, options);
|
|
289
297
|
const result = await next(common.wrap(unwrappedQuery, prefix), options);
|
|
290
298
|
const unwrappedResult = common.unwrap(result, prefix);
|
|
291
|
-
|
|
292
|
-
|
|
299
|
+
common.add(unwrappedQuery, common.unwrap(query, prefix));
|
|
300
|
+
log("finalizing", prefix, unwrappedQuery);
|
|
301
|
+
const finalizedResult = common.finalize(unwrappedResult, unwrappedQuery);
|
|
302
|
+
log("beforeAddingLinks", prefix, unwrappedResult);
|
|
303
|
+
linkGraph(finalizedResult, usedDefs);
|
|
304
|
+
return common.wrap(finalizedResult, prefix);
|
|
293
305
|
});
|
|
294
306
|
};
|
|
295
307
|
function clone(tree) {
|
package/index.mjs
CHANGED
|
@@ -17,7 +17,8 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { encodePath, splitRef, findFirst, unwrap, merge, wrap, decodeArgs, isBranch, add, wrapValue } from "@graffy/common";
|
|
20
|
+
import { encodePath, splitRef, findFirst, unwrap, merge, wrap, decodeArgs, isBranch, add, wrapValue, finalize } from "@graffy/common";
|
|
21
|
+
import debug from "debug";
|
|
21
22
|
function linkGraph(rootGraph, defs) {
|
|
22
23
|
let version = rootGraph[0].version;
|
|
23
24
|
for (const { path, def } of defs) {
|
|
@@ -276,6 +277,7 @@ function prepareDef(def, vars) {
|
|
|
276
277
|
const ref = def.flatMap(replacePlaceholders);
|
|
277
278
|
return ref;
|
|
278
279
|
}
|
|
280
|
+
const log = debug("graffy:link");
|
|
279
281
|
var index = (defs) => (store) => {
|
|
280
282
|
const prefix = store.path;
|
|
281
283
|
const defEntries = Object.entries(defs).map(([prop, def]) => ({
|
|
@@ -285,10 +287,16 @@ var index = (defs) => (store) => {
|
|
|
285
287
|
store.on("read", async (query, options, next) => {
|
|
286
288
|
const unwrappedQuery = clone(unwrap(query, prefix));
|
|
287
289
|
const usedDefs = prepQueryLinks(unwrappedQuery, defEntries);
|
|
290
|
+
if (!usedDefs.length)
|
|
291
|
+
return next(query, options);
|
|
288
292
|
const result = await next(wrap(unwrappedQuery, prefix), options);
|
|
289
293
|
const unwrappedResult = unwrap(result, prefix);
|
|
290
|
-
|
|
291
|
-
|
|
294
|
+
add(unwrappedQuery, unwrap(query, prefix));
|
|
295
|
+
log("finalizing", prefix, unwrappedQuery);
|
|
296
|
+
const finalizedResult = finalize(unwrappedResult, unwrappedQuery);
|
|
297
|
+
log("beforeAddingLinks", prefix, unwrappedResult);
|
|
298
|
+
linkGraph(finalizedResult, usedDefs);
|
|
299
|
+
return wrap(finalizedResult, prefix);
|
|
292
300
|
});
|
|
293
301
|
};
|
|
294
302
|
function clone(tree) {
|
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.15-alpha.
|
|
5
|
+
"version": "0.15.15-alpha.3",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.15.15-alpha.
|
|
19
|
+
"@graffy/common": "0.15.15-alpha.3",
|
|
20
|
+
"debug": "^4.3.2"
|
|
20
21
|
}
|
|
21
22
|
}
|