@rotorsoft/act-diagram 0.1.1 → 0.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"build-model.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/build-model.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAGV,WAAW,EAEX,OAAO,EAGR,MAAM,mBAAmB,CAAC;AAqF3B,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAIF,wBAAgB,UAAU,CACxB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,OAAO,EAAE,EAChB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAyNxC"}
1
+ {"version":3,"file":"build-model.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/build-model.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAGV,WAAW,EAEX,OAAO,EAGR,MAAM,mBAAmB,CAAC;AAqF3B,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAIF,wBAAgB,UAAU,CACxB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,OAAO,EAAE,EAChB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAqQxC"}
@@ -1,4 +1,8 @@
1
1
  import type { DomainModel, FileTab } from "../types/index.js";
2
+ /** Replace non-executable content with same-length whitespace (preserving offsets).
3
+ * `level: "full"` strips comments + strings + template literals (for scanning).
4
+ * `level: "nav"` strips comments + template literals only (for navigation). */
5
+ export declare const stripNonCode: (src: string, level?: "full" | "nav") => string;
2
6
  export declare function extractModel(files: FileTab[]): {
3
7
  model: DomainModel;
4
8
  error?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAmN9D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAsBA"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK9D;;gFAEgF;AAChF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,QAAO,MAAM,GAAG,KAAc,WAYvE,CAAC;AA8NF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAGA"}
@@ -1 +1 @@
1
- {"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAkIjD,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,GAAG,SAAS,CAqJ5B"}
1
+ {"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAoFjD,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,GAAG,SAAS,CA8J5B"}
package/dist/index.cjs CHANGED
@@ -247,11 +247,40 @@ function buildModel(result, files, expectedSlices) {
247
247
  model.reactions.push(r);
248
248
  }
249
249
  const entryPath = a._sourceFile ?? "app.ts";
250
+ const actSliceNames = new Set(
251
+ (a.slices ?? []).filter((s) => s != null).map((s) => s._varName ?? "").filter(Boolean)
252
+ );
253
+ for (const sl of model.slices) {
254
+ if (sl.error && !actSliceNames.has(sl.name)) {
255
+ const actSrc = files.find((f) => f.path === entryPath)?.content ?? "";
256
+ if (actSrc.includes(sl.name)) {
257
+ actSliceNames.add(sl.name);
258
+ }
259
+ }
260
+ }
261
+ const entrySlices = model.slices.filter((s) => actSliceNames.has(s.name));
262
+ const sliceStateKeys = new Set(entrySlices.flatMap((s) => s.states));
263
+ const actStateKeys = /* @__PURE__ */ new Set();
264
+ for (const s of a.states ?? []) {
265
+ try {
266
+ if (s && s._tag === "State") {
267
+ actStateKeys.add(s._modelKey ?? s.name);
268
+ }
269
+ } catch {
270
+ }
271
+ }
272
+ const allStateKeys = /* @__PURE__ */ new Set([...actStateKeys, ...sliceStateKeys]);
273
+ const actProjNames = new Set(
274
+ (a.projections ?? []).filter((p) => p && p._tag === "Projection").map((p) => p.target)
275
+ );
276
+ for (const sl of entrySlices) {
277
+ for (const pn of sl.projections) actProjNames.add(pn);
278
+ }
250
279
  model.entries.push({
251
280
  path: entryPath,
252
- states: model.states,
253
- slices: model.slices,
254
- projections: model.projections,
281
+ states: model.states.filter((s) => allStateKeys.has(s.varName)),
282
+ slices: entrySlices,
283
+ projections: model.projections.filter((p) => actProjNames.has(p.name)),
255
284
  reactions: a.reactions ?? []
256
285
  });
257
286
  }
@@ -681,6 +710,15 @@ function resolve(imp, fromPath, byKey) {
681
710
  }
682
711
 
683
712
  // src/client/lib/evaluate.ts
713
+ var stripNonCode = (src, level = "full") => {
714
+ const blank = (m) => m.replace(/[^\n]/g, " ");
715
+ let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`])*`/g, blank);
716
+ if (level === "full") {
717
+ result = result.replace(/"(?:\\[\s\S]|[^"])*"/g, blank).replace(/'(?:\\[\s\S]|[^'])*'/g, blank);
718
+ }
719
+ return result;
720
+ };
721
+ var isSourceFile = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
684
722
  function transpile(code) {
685
723
  try {
686
724
  const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
@@ -702,7 +740,8 @@ function execute(files) {
702
740
  projections: [],
703
741
  acts: [],
704
742
  error: void 0,
705
- fileErrors: /* @__PURE__ */ new Map()
743
+ fileErrors: /* @__PURE__ */ new Map(),
744
+ expectedSlices: /* @__PURE__ */ new Map()
706
745
  };
707
746
  try {
708
747
  const __built__ = {
@@ -754,11 +793,7 @@ function execute(files) {
754
793
  }
755
794
  return unknownModuleProxy();
756
795
  };
757
- const sorted = topoSort(
758
- files.filter(
759
- (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/")
760
- )
761
- );
796
+ const sorted = topoSort(files.filter(isSourceFile));
762
797
  for (const file of sorted) {
763
798
  _currentFile = file.path;
764
799
  const js = transpile(file.content);
@@ -768,10 +803,19 @@ function execute(files) {
768
803
  const sliceNamesInAct = [];
769
804
  const wsRe = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
770
805
  let wsm;
771
- while ((wsm = wsRe.exec(js)) !== null) {
806
+ const codeOnly = stripNonCode(js);
807
+ while ((wsm = wsRe.exec(codeOnly)) !== null) {
772
808
  if (!sliceNamesInAct.includes(wsm[1])) sliceNamesInAct.push(wsm[1]);
773
809
  }
774
- const fileRequire = (mod) => resolveModule(mod, key);
810
+ for (const m of codeOnly.matchAll(
811
+ /(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
812
+ )) {
813
+ result.expectedSlices.set(m[1], file.path);
814
+ }
815
+ const fileRequire = Object.assign(
816
+ (mod) => resolveModule(mod, key),
817
+ { resolve: (mod) => mod, cache: {}, main: void 0 }
818
+ );
775
819
  try {
776
820
  const cleanJs = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
777
821
  const fn = new Function(
@@ -817,48 +861,10 @@ function execute(files) {
817
861
  }
818
862
  function extractModel(files) {
819
863
  const result = execute(files);
820
- const expectedSlices = /* @__PURE__ */ new Map();
821
- for (const file of files) {
822
- if (!file.path.endsWith(".ts") || file.path.endsWith(".d.ts") || file.path.endsWith(".spec.ts") || file.path.endsWith(".test.ts") || file.path.includes("node_modules/"))
823
- continue;
824
- for (const m of file.content.matchAll(
825
- /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*slice\s*\(\s*\)/g
826
- )) {
827
- expectedSlices.set(m[1], file.path);
828
- }
829
- }
830
- return buildModel(result, files, expectedSlices);
864
+ return buildModel(result, files, result.expectedSlices);
831
865
  }
832
866
 
833
867
  // src/client/lib/navigate.ts
834
- function isInsideComment(content, matchIndex) {
835
- const before = content.slice(0, matchIndex);
836
- const lastNl = before.lastIndexOf("\n");
837
- const lineStart = lastNl >= 0 ? lastNl + 1 : 0;
838
- const lineEnd = content.indexOf("\n", matchIndex);
839
- const lineText = content.slice(lineStart, lineEnd >= 0 ? lineEnd : content.length).trimStart();
840
- if (lineText.startsWith("//") || lineText.startsWith("*") || lineText.startsWith("/*")) {
841
- return true;
842
- }
843
- const lastBlockOpen = before.lastIndexOf("/*");
844
- if (lastBlockOpen >= 0) {
845
- const lastBlockClose = before.lastIndexOf("*/");
846
- if (lastBlockClose < lastBlockOpen) return true;
847
- }
848
- return false;
849
- }
850
- function findNonCommentMatch(content, re, startFrom = 0) {
851
- const globalRe = new RegExp(
852
- re.source,
853
- re.flags.includes("g") ? re.flags : re.flags + "g"
854
- );
855
- globalRe.lastIndex = startFrom;
856
- let match;
857
- while ((match = globalRe.exec(content)) !== null) {
858
- if (!isInsideComment(content, match.index)) return match.index;
859
- }
860
- return -1;
861
- }
862
868
  function positionAt(content, index) {
863
869
  const before = content.slice(0, index);
864
870
  const line = before.split("\n").length;
@@ -934,10 +940,19 @@ function buildPatterns(esc, type) {
934
940
  }
935
941
  }
936
942
  function navigateToCode(files, name, type, targetFile) {
943
+ const stripped = /* @__PURE__ */ new Map();
944
+ const code = (f) => {
945
+ let c = stripped.get(f.path);
946
+ if (c === void 0) {
947
+ c = stripNonCode(f.content, "nav");
948
+ stripped.set(f.path, c);
949
+ }
950
+ return c;
951
+ };
937
952
  if (type === "file") {
938
953
  const file = files.find((f) => f.path === name || f.path.endsWith(name));
939
954
  if (file) {
940
- const actMatch = /\bact\s*\(\s*\)/.exec(file.content);
955
+ const actMatch = /\bact\s*\(\s*\)/.exec(code(file));
941
956
  if (actMatch) {
942
957
  const { line, col } = positionAt(file.content, actMatch.index);
943
958
  return { file: file.path, line, col };
@@ -949,31 +964,35 @@ function navigateToCode(files, name, type, targetFile) {
949
964
  if (targetFile) {
950
965
  const file = files.find((f) => f.path === targetFile);
951
966
  if (file) {
967
+ const c = code(file);
952
968
  const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
953
969
  if (type === "event") {
954
970
  const emitsBlockRe = new RegExp(
955
971
  `\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
956
972
  );
957
- const blockMatch = emitsBlockRe.exec(file.content);
973
+ const blockMatch = emitsBlockRe.exec(c);
958
974
  if (blockMatch) {
959
975
  const nameIdx = blockMatch.index + blockMatch[0].lastIndexOf(name);
960
976
  const { line, col } = positionAt(file.content, nameIdx);
961
977
  return { file: file.path, line, col };
962
978
  }
963
979
  const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
964
- if (findNonCommentMatch(file.content, nameRe2) >= 0) {
965
- const emitsIdx = findNonCommentMatch(file.content, /\.emits\s*\(/);
966
- if (emitsIdx >= 0) {
967
- const { line, col } = positionAt(file.content, emitsIdx + 1);
980
+ if (nameRe2.exec(c)) {
981
+ const emitsMatch = /\.emits\s*\(/.exec(c);
982
+ if (emitsMatch) {
983
+ const { line, col } = positionAt(
984
+ file.content,
985
+ emitsMatch.index + 1
986
+ );
968
987
  return { file: file.path, line, col };
969
988
  }
970
989
  }
971
990
  }
972
991
  if (type === "guard") {
973
992
  const descRe = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
974
- const descMatch = descRe.exec(file.content);
993
+ const descMatch = descRe.exec(c);
975
994
  if (descMatch) {
976
- const before = file.content.slice(0, descMatch.index);
995
+ const before = c.slice(0, descMatch.index);
977
996
  const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
978
997
  let lastDecl = null;
979
998
  let m;
@@ -991,19 +1010,20 @@ function navigateToCode(files, name, type, targetFile) {
991
1010
  }
992
1011
  if (type === "action") {
993
1012
  const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
994
- const blockStart = file.content.indexOf(".on(");
1013
+ const blockStart = c.indexOf(".on(");
995
1014
  if (blockStart >= 0) {
996
- const idx2 = findNonCommentMatch(file.content, nameRe2, blockStart);
997
- if (idx2 >= 0) {
998
- const { line, col } = positionAt(file.content, idx2);
1015
+ nameRe2.lastIndex = blockStart;
1016
+ const match2 = nameRe2.exec(c);
1017
+ if (match2) {
1018
+ const { line, col } = positionAt(file.content, match2.index);
999
1019
  return { file: file.path, line, col };
1000
1020
  }
1001
1021
  }
1002
1022
  }
1003
- const nameRe = new RegExp(`\\b${esc2}\\b`, "g");
1004
- const idx = findNonCommentMatch(file.content, nameRe);
1005
- if (idx >= 0) {
1006
- const { line, col } = positionAt(file.content, idx);
1023
+ const nameRe = new RegExp(`\\b${esc2}\\b`);
1024
+ const match = nameRe.exec(c);
1025
+ if (match) {
1026
+ const { line, col } = positionAt(file.content, match.index);
1007
1027
  return { file: file.path, line, col };
1008
1028
  }
1009
1029
  }
@@ -1018,9 +1038,10 @@ function navigateToCode(files, name, type, targetFile) {
1018
1038
  const descRe = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
1019
1039
  for (const f of sortedFiles) {
1020
1040
  if (!/\.tsx?$/.test(f.path)) continue;
1021
- const descMatch = descRe.exec(f.content);
1022
- if (descMatch && !isInsideComment(f.content, descMatch.index)) {
1023
- const before = f.content.slice(0, descMatch.index);
1041
+ const c = code(f);
1042
+ const descMatch = descRe.exec(c);
1043
+ if (descMatch) {
1044
+ const before = c.slice(0, descMatch.index);
1024
1045
  const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1025
1046
  let lastDecl = null;
1026
1047
  let m;
@@ -1037,18 +1058,17 @@ function navigateToCode(files, name, type, targetFile) {
1037
1058
  }
1038
1059
  const patterns = buildPatterns(esc, type);
1039
1060
  for (const re of patterns) {
1040
- for (let i = 0; i < sortedFiles.length; i++) {
1041
- if (!/\.tsx?$/.test(sortedFiles[i].path)) continue;
1042
- const content = sortedFiles[i].content;
1061
+ for (const f of sortedFiles) {
1062
+ if (!/\.tsx?$/.test(f.path)) continue;
1063
+ const c = code(f);
1043
1064
  const globalRe = new RegExp(re.source, re.flags + "g");
1044
1065
  let match;
1045
- while ((match = globalRe.exec(content)) !== null) {
1046
- if (isInsideComment(content, match.index)) continue;
1066
+ while ((match = globalRe.exec(c)) !== null) {
1047
1067
  const matchText = match[0];
1048
1068
  const nameOffsetInMatch = matchText.lastIndexOf(name);
1049
1069
  const nameStart = match.index + Math.max(0, nameOffsetInMatch);
1050
- const { line, col } = positionAt(content, nameStart);
1051
- return { file: sortedFiles[i].path, line, col };
1070
+ const { line, col } = positionAt(f.content, nameStart);
1071
+ return { file: f.path, line, col };
1052
1072
  }
1053
1073
  }
1054
1074
  }