@graphrefly/graphrefly 0.5.0 → 0.7.0

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.
Files changed (75) hide show
  1. package/README.md +30 -14
  2. package/dist/{chunk-5X3LAO3B.js → chunk-3EVXOI5C.js} +50 -5
  3. package/dist/chunk-3EVXOI5C.js.map +1 -0
  4. package/dist/chunk-47YJEZUJ.js +106 -0
  5. package/dist/chunk-47YJEZUJ.js.map +1 -0
  6. package/dist/{chunk-6W5SGIGB.js → chunk-BLCXEMAD.js} +129 -25
  7. package/dist/chunk-BLCXEMAD.js.map +1 -0
  8. package/dist/{chunk-QW7H3ICI.js → chunk-FGLZ5QID.js} +4 -4
  9. package/dist/{chunk-CP6MNKAA.js → chunk-ISGMZ2T3.js} +10 -4
  10. package/dist/{chunk-CP6MNKAA.js.map → chunk-ISGMZ2T3.js.map} +1 -1
  11. package/dist/{chunk-HP7OKEOE.js → chunk-L4J2K2RT.js} +3 -3
  12. package/dist/chunk-L4J2K2RT.js.map +1 -0
  13. package/dist/{chunk-ZERWUCGK.js → chunk-ONLYF6GA.js} +866 -206
  14. package/dist/chunk-ONLYF6GA.js.map +1 -0
  15. package/dist/{chunk-Z4Y4FMQN.js → chunk-OSR3G3DP.js} +7 -7
  16. package/dist/{chunk-KWXPDASV.js → chunk-PEBORXRA.js} +2 -2
  17. package/dist/chunk-WZ2Z2CRV.js +32 -0
  18. package/dist/chunk-WZ2Z2CRV.js.map +1 -0
  19. package/dist/compat/nestjs/index.cjs +226 -41
  20. package/dist/compat/nestjs/index.cjs.map +1 -1
  21. package/dist/compat/nestjs/index.d.cts +4 -4
  22. package/dist/compat/nestjs/index.d.ts +4 -4
  23. package/dist/compat/nestjs/index.js +8 -7
  24. package/dist/core/index.cjs +134 -20
  25. package/dist/core/index.cjs.map +1 -1
  26. package/dist/core/index.d.cts +2 -2
  27. package/dist/core/index.d.ts +2 -2
  28. package/dist/core/index.js +10 -4
  29. package/dist/extra/index.cjs +939 -209
  30. package/dist/extra/index.cjs.map +1 -1
  31. package/dist/extra/index.d.cts +4 -4
  32. package/dist/extra/index.d.ts +4 -4
  33. package/dist/extra/index.js +26 -3
  34. package/dist/graph/index.cjs +226 -41
  35. package/dist/graph/index.cjs.map +1 -1
  36. package/dist/graph/index.d.cts +3 -3
  37. package/dist/graph/index.d.ts +3 -3
  38. package/dist/graph/index.js +4 -4
  39. package/dist/{graph-CL_ZDAj9.d.cts → graph-B3BoJjcb.d.cts} +58 -7
  40. package/dist/{graph-D18qmsNm.d.ts → graph-CmiUuhaN.d.ts} +58 -7
  41. package/dist/{index-B7eOdgEx.d.ts → index-Bf2X1YSI.d.ts} +3 -3
  42. package/dist/{index-BvhgZRHK.d.cts → index-Bl7hJcc3.d.cts} +4 -2
  43. package/dist/{index-Bvy_6CaN.d.ts → index-BrgtEG-C.d.ts} +47 -4
  44. package/dist/{index-D_geH2Bm.d.cts → index-BsuKSs4L.d.cts} +3 -3
  45. package/dist/{index-BtK55IE2.d.ts → index-CsUq2rrK.d.ts} +4 -2
  46. package/dist/{index-C3BMRmmp.d.cts → index-D0cx-Yht.d.cts} +3 -3
  47. package/dist/{index-Cz8og7-L.d.cts → index-D1hgSTzr.d.cts} +488 -60
  48. package/dist/{index-C5mqLhMX.d.cts → index-D8NIq6om.d.cts} +47 -4
  49. package/dist/{index-CP_QvbWu.d.ts → index-DFFNKYig.d.ts} +3 -3
  50. package/dist/{index-C3LRU4jB.d.ts → index-Pm68AYPh.d.ts} +488 -60
  51. package/dist/index.cjs +3005 -1776
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +112 -14
  54. package/dist/index.d.ts +112 -14
  55. package/dist/index.js +396 -27
  56. package/dist/index.js.map +1 -1
  57. package/dist/{meta-BsF6Sag9.d.cts → meta-BJEU8fYz.d.cts} +31 -4
  58. package/dist/{meta-BsF6Sag9.d.ts → meta-BJEU8fYz.d.ts} +31 -4
  59. package/dist/patterns/reactive-layout/index.cjs +226 -41
  60. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  61. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  62. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  63. package/dist/patterns/reactive-layout/index.js +4 -4
  64. package/dist/{reactive-log-BfvfNWQh.d.cts → reactive-log-CAXzJ7hw.d.cts} +2 -2
  65. package/dist/{reactive-log-ohLmTXoZ.d.ts → reactive-log-DwNhOe0g.d.ts} +2 -2
  66. package/package.json +29 -18
  67. package/dist/chunk-5X3LAO3B.js.map +0 -1
  68. package/dist/chunk-6W5SGIGB.js.map +0 -1
  69. package/dist/chunk-HP7OKEOE.js.map +0 -1
  70. package/dist/chunk-O3PI7W45.js +0 -68
  71. package/dist/chunk-O3PI7W45.js.map +0 -1
  72. package/dist/chunk-ZERWUCGK.js.map +0 -1
  73. /package/dist/{chunk-QW7H3ICI.js.map → chunk-FGLZ5QID.js.map} +0 -0
  74. /package/dist/{chunk-Z4Y4FMQN.js.map → chunk-OSR3G3DP.js.map} +0 -0
  75. /package/dist/{chunk-KWXPDASV.js.map → chunk-PEBORXRA.js.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  import {
2
- describeNode
3
- } from "./chunk-O3PI7W45.js";
2
+ describeNode,
3
+ resolveDescribeFields
4
+ } from "./chunk-47YJEZUJ.js";
4
5
  import {
5
6
  COMPLETE,
6
7
  DATA,
@@ -15,7 +16,7 @@ import {
15
16
  messageTier,
16
17
  monotonicNs,
17
18
  state
18
- } from "./chunk-5X3LAO3B.js";
19
+ } from "./chunk-3EVXOI5C.js";
19
20
 
20
21
  // src/graph/graph.ts
21
22
  var PATH_SEP = "::";
@@ -203,6 +204,23 @@ function resolveSpyTheme(theme) {
203
204
  reset: theme.reset ?? ""
204
205
  };
205
206
  }
207
+ function resolveObserveDetail(opts) {
208
+ if (opts == null) return {};
209
+ const detail = opts.detail;
210
+ if (detail === "full") {
211
+ return {
212
+ ...opts,
213
+ structured: opts.structured ?? true,
214
+ timeline: opts.timeline ?? true,
215
+ causal: opts.causal ?? true,
216
+ derived: opts.derived ?? true
217
+ };
218
+ }
219
+ if (detail === "minimal") {
220
+ return { ...opts, structured: opts.structured ?? true };
221
+ }
222
+ return opts;
223
+ }
206
224
  function assertLocalName(name, graphName, label) {
207
225
  if (name === "") {
208
226
  throw new Error(`Graph "${graphName}": ${label} name must be non-empty`);
@@ -400,6 +418,22 @@ var Graph = class _Graph {
400
418
  if (this._defaultVersioningLevel != null) {
401
419
  node._applyVersioning(this._defaultVersioningLevel);
402
420
  }
421
+ if (node._deps.length > 0) {
422
+ for (const dep of node._deps) {
423
+ for (const [depName, depNode] of this._nodes) {
424
+ if (depNode === dep) {
425
+ this._edges.add(edgeKey(depName, name));
426
+ break;
427
+ }
428
+ }
429
+ }
430
+ }
431
+ for (const [otherName, otherNode] of this._nodes) {
432
+ if (otherName === name) continue;
433
+ if (otherNode instanceof NodeImpl && otherNode._deps.includes(node)) {
434
+ this._edges.add(edgeKey(name, otherName));
435
+ }
436
+ }
403
437
  }
404
438
  }
405
439
  /**
@@ -786,6 +820,9 @@ var Graph = class _Graph {
786
820
  describe(options) {
787
821
  const actor = options?.actor;
788
822
  const filter = options?.filter;
823
+ const includeFields = resolveDescribeFields(options?.detail, options?.fields);
824
+ const isSpec = options?.format === "spec";
825
+ const effectiveFields = isSpec ? resolveDescribeFields("minimal") : includeFields;
789
826
  const targets = [];
790
827
  this._collectObserveTargets("", targets);
791
828
  const nodeToPath = /* @__PURE__ */ new Map();
@@ -795,7 +832,7 @@ var Graph = class _Graph {
795
832
  const nodes = {};
796
833
  for (const [p, n] of targets) {
797
834
  if (actor != null && !n.allowsObserve(actor)) continue;
798
- const raw = describeNode(n);
835
+ const raw = describeNode(n, effectiveFields);
799
836
  const deps = n instanceof NodeImpl ? n._deps.map((d) => nodeToPath.get(d) ?? d.name ?? "") : [];
800
837
  const { name: _name, ...rest } = raw;
801
838
  const entry = { ...rest, deps };
@@ -816,7 +853,7 @@ var Graph = class _Graph {
816
853
  continue;
817
854
  }
818
855
  if (normalizedKey === "metaHas") {
819
- if (!Object.hasOwn(entry.meta, String(fv))) {
856
+ if (!Object.hasOwn(entry.meta ?? {}, String(fv))) {
820
857
  match = false;
821
858
  break;
822
859
  }
@@ -849,11 +886,24 @@ var Graph = class _Graph {
849
886
  const prefix = `${sg}${PATH_SEP}`;
850
887
  return [...nodeKeys].some((k) => k === sg || k.startsWith(prefix));
851
888
  }) : allSubgraphs;
889
+ const graph = this;
890
+ const baseOpts = options;
852
891
  return {
853
892
  name: this.name,
854
893
  nodes,
855
894
  edges,
856
- subgraphs
895
+ subgraphs,
896
+ expand(detailOrFields) {
897
+ const merged = { ...baseOpts, format: void 0 };
898
+ if (Array.isArray(detailOrFields)) {
899
+ merged.fields = detailOrFields;
900
+ merged.detail = void 0;
901
+ } else {
902
+ merged.detail = detailOrFields;
903
+ merged.fields = void 0;
904
+ }
905
+ return graph.describe(merged);
906
+ }
857
907
  };
858
908
  }
859
909
  _collectSubgraphs(prefix) {
@@ -906,14 +956,15 @@ var Graph = class _Graph {
906
956
  observe(pathOrOpts, options) {
907
957
  if (typeof pathOrOpts === "string") {
908
958
  const path = pathOrOpts;
909
- const actor2 = options?.actor;
959
+ const resolved = resolveObserveDetail(options);
960
+ const actor2 = resolved.actor;
910
961
  const target = this.resolve(path);
911
962
  if (actor2 != null && !target.allowsObserve(actor2)) {
912
963
  throw new GuardDenied({ actor: actor2, action: "observe", nodeName: path });
913
964
  }
914
- const wantsStructured2 = options?.structured === true || options?.timeline === true || options?.causal === true || options?.derived === true;
965
+ const wantsStructured2 = resolved.structured === true || resolved.timeline === true || resolved.causal === true || resolved.derived === true || resolved.detail === "minimal" || resolved.detail === "full";
915
966
  if (wantsStructured2 && _Graph.inspectorEnabled) {
916
- return this._createObserveResult(path, target, options);
967
+ return this._createObserveResult(path, target, resolved);
917
968
  }
918
969
  return {
919
970
  subscribe(sink) {
@@ -929,11 +980,11 @@ var Graph = class _Graph {
929
980
  }
930
981
  };
931
982
  }
932
- const opts = pathOrOpts;
933
- const actor = opts?.actor;
934
- const wantsStructured = opts?.structured === true || opts?.timeline === true || opts?.causal === true || opts?.derived === true;
983
+ const opts = resolveObserveDetail(pathOrOpts);
984
+ const actor = opts.actor;
985
+ const wantsStructured = opts.structured === true || opts.timeline === true || opts.causal === true || opts.derived === true || opts.detail === "minimal" || opts.detail === "full";
935
986
  if (wantsStructured && _Graph.inspectorEnabled) {
936
- return this._createObserveResultForAll(opts ?? {});
987
+ return this._createObserveResultForAll(opts);
937
988
  }
938
989
  return {
939
990
  subscribe: (sink) => {
@@ -965,6 +1016,7 @@ var Graph = class _Graph {
965
1016
  const timeline = options.timeline === true;
966
1017
  const causal = options.causal === true;
967
1018
  const derived = options.derived === true;
1019
+ const minimal = options.detail === "minimal";
968
1020
  const result = {
969
1021
  values: {},
970
1022
  dirtyCount: 0,
@@ -1010,6 +1062,11 @@ var Graph = class _Graph {
1010
1062
  if (t === DATA) {
1011
1063
  result.values[path] = m[1];
1012
1064
  result.events.push({ type: "data", path, data: m[1], ...base, ...withCausal });
1065
+ } else if (minimal) {
1066
+ if (t === DIRTY) result.dirtyCount++;
1067
+ else if (t === RESOLVED) result.resolvedCount++;
1068
+ else if (t === COMPLETE && !result.errored) result.completedCleanly = true;
1069
+ else if (t === ERROR) result.errored = true;
1013
1070
  } else if (t === DIRTY) {
1014
1071
  result.dirtyCount++;
1015
1072
  result.events.push({ type: "dirty", path, ...base });
@@ -1025,6 +1082,8 @@ var Graph = class _Graph {
1025
1082
  }
1026
1083
  }
1027
1084
  });
1085
+ const graph = this;
1086
+ const basePath = path;
1028
1087
  return {
1029
1088
  get values() {
1030
1089
  return result.values;
@@ -1047,11 +1106,28 @@ var Graph = class _Graph {
1047
1106
  dispose() {
1048
1107
  unsub();
1049
1108
  detachInspectorHook?.();
1109
+ },
1110
+ expand(extra) {
1111
+ unsub();
1112
+ detachInspectorHook?.();
1113
+ const merged = { ...options };
1114
+ if (typeof extra === "string") {
1115
+ merged.detail = extra;
1116
+ } else {
1117
+ Object.assign(merged, extra);
1118
+ }
1119
+ const resolvedTarget = graph.resolve(basePath);
1120
+ return graph._createObserveResult(
1121
+ basePath,
1122
+ resolvedTarget,
1123
+ resolveObserveDetail(merged)
1124
+ );
1050
1125
  }
1051
1126
  };
1052
1127
  }
1053
1128
  _createObserveResultForAll(options) {
1054
1129
  const timeline = options.timeline === true;
1130
+ const minimal = options.detail === "minimal";
1055
1131
  const result = {
1056
1132
  values: {},
1057
1133
  dirtyCount: 0,
@@ -1073,6 +1149,11 @@ var Graph = class _Graph {
1073
1149
  if (t === DATA) {
1074
1150
  result.values[path] = m[1];
1075
1151
  result.events.push({ type: "data", path, data: m[1], ...base });
1152
+ } else if (minimal) {
1153
+ if (t === DIRTY) result.dirtyCount++;
1154
+ else if (t === RESOLVED) result.resolvedCount++;
1155
+ else if (t === COMPLETE && !result.errored) result.completedCleanly = true;
1156
+ else if (t === ERROR) result.errored = true;
1076
1157
  } else if (t === DIRTY) {
1077
1158
  result.dirtyCount++;
1078
1159
  result.events.push({ type: "dirty", path, ...base });
@@ -1089,6 +1170,7 @@ var Graph = class _Graph {
1089
1170
  }
1090
1171
  })
1091
1172
  );
1173
+ const graph = this;
1092
1174
  return {
1093
1175
  get values() {
1094
1176
  return result.values;
@@ -1110,6 +1192,16 @@ var Graph = class _Graph {
1110
1192
  },
1111
1193
  dispose() {
1112
1194
  for (const u of unsubs) u();
1195
+ },
1196
+ expand(extra) {
1197
+ for (const u of unsubs) u();
1198
+ const merged = { ...options };
1199
+ if (typeof extra === "string") {
1200
+ merged.detail = extra;
1201
+ } else {
1202
+ Object.assign(merged, extra);
1203
+ }
1204
+ return graph._createObserveResultForAll(resolveObserveDetail(merged));
1113
1205
  }
1114
1206
  };
1115
1207
  }
@@ -1185,6 +1277,9 @@ var Graph = class _Graph {
1185
1277
  },
1186
1278
  dispose() {
1187
1279
  stop2();
1280
+ },
1281
+ expand() {
1282
+ throw new Error("expand() requires inspector mode (Graph.inspectorEnabled = true)");
1188
1283
  }
1189
1284
  };
1190
1285
  const pushEvent = (path, message) => {
@@ -1285,16 +1380,16 @@ var Graph = class _Graph {
1285
1380
  * @returns Rendered graph text.
1286
1381
  */
1287
1382
  dumpGraph(options = {}) {
1288
- const described = this.describe({
1383
+ const { expand: _, ...described } = this.describe({
1289
1384
  actor: options.actor,
1290
- filter: options.filter
1385
+ filter: options.filter,
1386
+ detail: "standard"
1291
1387
  });
1292
1388
  const includeEdges = options.includeEdges ?? true;
1293
1389
  const includeSubgraphs = options.includeSubgraphs ?? true;
1294
1390
  if (options.format === "json") {
1295
1391
  const payload = {
1296
- name: described.name,
1297
- nodes: described.nodes,
1392
+ ...described,
1298
1393
  edges: includeEdges ? described.edges : [],
1299
1394
  subgraphs: includeSubgraphs ? described.subgraphs : []
1300
1395
  };
@@ -1364,10 +1459,11 @@ var Graph = class _Graph {
1364
1459
  * @returns Persistable snapshot with sorted keys.
1365
1460
  */
1366
1461
  snapshot() {
1367
- const d = this.describe();
1462
+ const { expand: _, ...d } = this.describe({ detail: "full" });
1368
1463
  const sortedNodes = {};
1369
1464
  for (const key of Object.keys(d.nodes).sort()) {
1370
- sortedNodes[key] = d.nodes[key];
1465
+ const { lastMutation: _lm, guard: _g, ...node } = d.nodes[key];
1466
+ sortedNodes[key] = node;
1371
1467
  }
1372
1468
  const sortedSubgraphs = [...d.subgraphs].sort();
1373
1469
  return { ...d, version: 1, nodes: sortedNodes, subgraphs: sortedSubgraphs };
@@ -1521,16 +1617,22 @@ var Graph = class _Graph {
1521
1617
  if (!pending) return;
1522
1618
  pending = false;
1523
1619
  try {
1524
- const described = this.describe();
1620
+ const { expand: _expand, ...raw } = this.describe({ detail: "full" });
1621
+ const cleanNodes = {};
1622
+ for (const [p, n] of Object.entries(raw.nodes)) {
1623
+ const { lastMutation: _lm, guard: _g, ...node } = n;
1624
+ cleanNodes[p] = node;
1625
+ }
1626
+ const described = { ...raw, nodes: cleanNodes };
1525
1627
  const snapshot = { ...described, version: SNAPSHOT_VERSION };
1526
1628
  seq += 1;
1527
1629
  const shouldCompact = lastDescribe == null || seq % compactEvery === 0;
1528
1630
  if (shouldCompact) {
1529
- adapter.save({ mode: "full", snapshot, seq });
1631
+ adapter.save(this.name, { mode: "full", snapshot, seq });
1530
1632
  } else {
1531
1633
  const previous = lastDescribe;
1532
1634
  if (previous == null) return;
1533
- adapter.save({
1635
+ adapter.save(this.name, {
1534
1636
  mode: "diff",
1535
1637
  diff: _Graph.diff(previous, described),
1536
1638
  snapshot,
@@ -1551,8 +1653,10 @@ var Graph = class _Graph {
1551
1653
  const triggeredByTier = messages.some((m) => messageTier(m[0]) >= 2);
1552
1654
  if (!triggeredByTier) return;
1553
1655
  if (options.filter) {
1554
- const described = this.describe().nodes[path];
1555
- if (described == null || !options.filter(path, described)) return;
1656
+ const nd = this.resolve(path);
1657
+ if (nd == null) return;
1658
+ const described = describeNode(nd, resolveDescribeFields("standard"));
1659
+ if (!options.filter(path, described)) return;
1556
1660
  }
1557
1661
  schedule();
1558
1662
  });
@@ -1790,4 +1894,4 @@ export {
1790
1894
  Graph,
1791
1895
  reachable
1792
1896
  };
1793
- //# sourceMappingURL=chunk-6W5SGIGB.js.map
1897
+ //# sourceMappingURL=chunk-BLCXEMAD.js.map