@graffy/link 0.15.15-alpha.2 → 0.15.17
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 +16 -2
- package/index.mjs +13 -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,18 @@ 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);
|
|
298
|
+
const version = result[0].version;
|
|
290
299
|
const unwrappedResult = common.unwrap(result, prefix);
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
common.add(unwrappedQuery, common.unwrap(query, prefix));
|
|
301
|
+
log("finalizing", prefix, unwrappedQuery);
|
|
302
|
+
const finalizedResult = common.finalize(unwrappedResult, unwrappedQuery, version);
|
|
303
|
+
log("beforeAddingLinks", prefix, finalizedResult);
|
|
304
|
+
linkGraph(finalizedResult, usedDefs);
|
|
305
|
+
log("afterAddingLinks", prefix, finalizedResult);
|
|
306
|
+
return common.wrap(finalizedResult, prefix, version);
|
|
293
307
|
});
|
|
294
308
|
};
|
|
295
309
|
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,18 @@ 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);
|
|
293
|
+
const version = result[0].version;
|
|
289
294
|
const unwrappedResult = unwrap(result, prefix);
|
|
290
|
-
|
|
291
|
-
|
|
295
|
+
add(unwrappedQuery, unwrap(query, prefix));
|
|
296
|
+
log("finalizing", prefix, unwrappedQuery);
|
|
297
|
+
const finalizedResult = finalize(unwrappedResult, unwrappedQuery, version);
|
|
298
|
+
log("beforeAddingLinks", prefix, finalizedResult);
|
|
299
|
+
linkGraph(finalizedResult, usedDefs);
|
|
300
|
+
log("afterAddingLinks", prefix, finalizedResult);
|
|
301
|
+
return wrap(finalizedResult, prefix, version);
|
|
292
302
|
});
|
|
293
303
|
};
|
|
294
304
|
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.
|
|
5
|
+
"version": "0.15.17",
|
|
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.
|
|
19
|
+
"@graffy/common": "0.15.17",
|
|
20
|
+
"debug": "^4.3.3"
|
|
20
21
|
}
|
|
21
22
|
}
|