@akanjs/cli 3.1.2-rc.2 → 3.1.2-rc.4

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 (86) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-nkk70v5h.js → CodeAgent-z34p8m91.js} +2 -2
  3. package/{CodeTui-sdqz2gxb.js → CodeTui-nvd9fk3g.js} +1 -1
  4. package/TunnelShare-jwbb50kz.js +14 -0
  5. package/{agent.command-5gfrfh8d.js → agent.command-962mp3kg.js} +15 -15
  6. package/akanCode.js +2 -2
  7. package/{application.command-nd0fshsk.js → application.command-1nr0bqq1.js} +35 -11
  8. package/{applicationBuildRunner-s13x3zqb.js → applicationBuildRunner-xy7hnfzq.js} +7 -6
  9. package/buildBatch.proc.js +6 -6
  10. package/{cloud.command-8kbddsz9.js → cloud.command-cj7b3m6y.js} +15 -15
  11. package/cloud.script-8kr7qgfa.js +27 -0
  12. package/{code.command-5djp5c0n.js → code.command-asq7xrr6.js} +6 -6
  13. package/commandManifest.json +1 -1
  14. package/{context.command-5d0bscv6.js → context.command-fw4g2pw1.js} +18 -17
  15. package/context.runner-p6m5cxk3.js +28 -0
  16. package/{guideline.command-195g0h9a.js → guideline.command-43gfjsjv.js} +2 -2
  17. package/guidelines/conventions/rules/page.md +4 -2
  18. package/guidelines/conventions/rules/server.md +2 -0
  19. package/guidelines/conventions/rules/style.md +3 -1
  20. package/guidelines/conventions/rules/ts.md +2 -1
  21. package/guidelines/cssRule/cssRule.instruction.md +3 -1
  22. package/guidelines/pageRule/pageRule.instruction.md +3 -0
  23. package/incrementalBuilder.proc.js +52 -6
  24. package/{index-ms1am2wr.js → index-0tkj05cz.js} +3 -3
  25. package/{index-00a7j05x.js → index-2yan1ajk.js} +7 -7
  26. package/{index-g500c5j9.js → index-38by07nw.js} +1 -1
  27. package/{index-zttm13c3.js → index-38patcx6.js} +4 -4
  28. package/{index-f6zrhcnk.js → index-53h0053j.js} +23 -8
  29. package/{index-zbrwnmf1.js → index-6t7fkx73.js} +1 -1
  30. package/{index-pqdyyxz0.js → index-6zgt7zmx.js} +4 -4
  31. package/{index-y4kcmbt2.js → index-8d9r465x.js} +2 -2
  32. package/{index-yep9xcz0.js → index-90q0w90q.js} +1 -1
  33. package/{index-q9q6jjk1.js → index-ampz4vgv.js} +4 -4
  34. package/{index-chjaw222.js → index-ap6ac70m.js} +3 -3
  35. package/{index-dbxac7mz.js → index-ck64kxrn.js} +2 -2
  36. package/{index-p6x5b7hr.js → index-d894868w.js} +3 -0
  37. package/{index-sveq36gh.js → index-dcm66hss.js} +2 -2
  38. package/{index-84h43kg6.js → index-demt944k.js} +2 -2
  39. package/{index-0j1t1h2b.js → index-g0yds382.js} +1 -1
  40. package/{index-pnk67cqd.js → index-gfh90r3t.js} +2 -2
  41. package/{index-19cspack.js → index-hmj94es2.js} +4 -4
  42. package/{index-3q4kkyd4.js → index-jzpeny42.js} +3 -3
  43. package/{index-tw27n941.js → index-jzz6ye8x.js} +296 -24
  44. package/{index-2mwjshz5.js → index-kc6ffq0s.js} +16 -13
  45. package/{index-tp56652m.js → index-kc871vpc.js} +3 -3
  46. package/{index-1404hqcj.js → index-kdswbvys.js} +3 -3
  47. package/{index-defp4gmb.js → index-qev8p5wp.js} +1 -1
  48. package/{index-1h2jc0x3.js → index-qwe079ww.js} +4 -4
  49. package/{index-wwe9rsrx.js → index-r0a604h4.js} +12 -2
  50. package/{index-9zy8479y.js → index-r0q2ka2b.js} +1 -1
  51. package/{index-ewbmfarf.js → index-r8t5sq7z.js} +31 -8
  52. package/{index-gf4fcw1n.js → index-re2kfscb.js} +495 -8
  53. package/{index-gr9thy79.js → index-sra1a5f8.js} +2 -2
  54. package/{index-khk05tsf.js → index-t0hk1kxq.js} +1 -1
  55. package/index-vkpqe29t.js +267 -0
  56. package/{index-sp0qsr7a.js → index-w60zxxye.js} +3 -3
  57. package/{index-mzjwq4dd.js → index-wymcdsas.js} +8 -8
  58. package/{index-t78230d7.js → index-y0y0pnx8.js} +3 -2
  59. package/{index-tyt7cw99.js → index-z47rw9ez.js} +6 -6
  60. package/index.js +23 -23
  61. package/{library.command-63hgt9te.js → library.command-zh29tjdd.js} +3 -3
  62. package/{localRegistry.command-g3f8k25t.js → localRegistry.command-k9pn9ahj.js} +14 -14
  63. package/{module.command-myykfb6s.js → module.command-dgpqs9fz.js} +6 -6
  64. package/{package.command-96eheyvd.js → package.command-1je4hsca.js} +3 -3
  65. package/package.json +2 -2
  66. package/{page.command-gs6d841d.js → page.command-cgsasanh.js} +3 -3
  67. package/{pipeline.command-wdfvdbfj.js → pipeline.command-tb46sa8v.js} +2 -2
  68. package/{primitive.command-eg2c3m97.js → primitive.command-bzsy23x5.js} +7 -7
  69. package/{projectTypecheck-kqj1t6hb.js → projectTypecheck-h8rgaczy.js} +1 -1
  70. package/{quality.command-b840977n.js → quality.command-120m9h6v.js} +4 -4
  71. package/{repair.command-r7z709yf.js → repair.command-6m4wd0qv.js} +6 -6
  72. package/{scalar.command-t6hhty3f.js → scalar.command-3dn5hsc6.js} +5 -5
  73. package/skills/akan-page/SKILL.md +19 -0
  74. package/skills/akan-service/SKILL.md +47 -0
  75. package/{subspace.command-a1sf9n5a.js → subspace.command-s8nyfqbn.js} +8 -8
  76. package/{tunnel.command-dcb0wg93.js → tunnel.command-8mwrqkr3.js} +7 -7
  77. package/{typeChecker-j2jdnqsr.js → typeChecker-s640r6c0.js} +1 -1
  78. package/typecheck.proc.js +1 -1
  79. package/{verify.command-07fqhpak.js → verify.command-2pspfy7k.js} +12 -12
  80. package/{workflow.command-c2jhzf7v.js → workflow.command-7sy5vnsj.js} +11 -11
  81. package/{workspace.command-gv20zq1z.js → workspace.command-x518tdv4.js} +30 -29
  82. package/TunnelShare-hdq9h1hr.js +0 -14
  83. package/cloud.script-hgvvajm3.js +0 -27
  84. package/context.runner-2v5pq18d.js +0 -27
  85. package/templates/workspaceRoot/patches/zod@3.25.76.patch.template +0 -22
  86. package/templates/workspaceRoot/patches/zod@4.4.3.patch.template +0 -11
@@ -1,28 +1,28 @@
1
1
  // @bun
2
2
  import {
3
3
  ApplicationBuildReporter
4
- } from "./index-p6x5b7hr.js";
4
+ } from "./index-d894868w.js";
5
5
  import {
6
6
  script,
7
7
  ExitCodeError,
8
8
  markCliErrorPrinted,
9
9
  assertPromptable
10
- } from "./index-9zy8479y.js";
10
+ } from "./index-r0q2ka2b.js";
11
11
  import {
12
12
  AppExecutor,
13
13
  LibExecutor,
14
14
  PkgExecutor
15
- } from "./index-g500c5j9.js";
15
+ } from "./index-38by07nw.js";
16
16
  import {
17
17
  DesktopServerStage
18
- } from "./index-0j1t1h2b.js";
18
+ } from "./index-g0yds382.js";
19
19
  import {
20
20
  LibraryScript
21
- } from "./index-y4kcmbt2.js";
21
+ } from "./index-8d9r465x.js";
22
22
  import {
23
23
  ApplicationRunner,
24
24
  VerifyScope
25
- } from "./index-2mwjshz5.js";
25
+ } from "./index-kc6ffq0s.js";
26
26
  import {
27
27
  PreviewChrome2,
28
28
  PreviewView2,
@@ -30,7 +30,7 @@ import {
30
30
  } from "./index-tenw3mah.js";
31
31
  import {
32
32
  formatSlicePlan
33
- } from "./index-defp4gmb.js";
33
+ } from "./index-qev8p5wp.js";
34
34
  import {
35
35
  openBrowser
36
36
  } from "./index-9dp031by.js";
@@ -1278,6 +1278,29 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1278
1278
  markCliErrorPrinted(failure);
1279
1279
  throw failure;
1280
1280
  }
1281
+ async studio(app, {
1282
+ module,
1283
+ view,
1284
+ since = null,
1285
+ editor,
1286
+ open,
1287
+ format
1288
+ }) {
1289
+ if (since && view !== "changes")
1290
+ throw new Error("`--since` picks what the Change Map compares with; pass `--view changes` with it.");
1291
+ const origin = `http://localhost:${await app.getDevPort()}`;
1292
+ if (!await ApplicationRunner.answers(origin, app.name, app.workspace.workspaceRoot))
1293
+ throw new Error(`No dev server answers ${origin}. Run \`akan start ${app.name}\` first.`);
1294
+ const search = new URLSearchParams({ view, editor });
1295
+ if (module)
1296
+ search.set("module", module);
1297
+ if (since)
1298
+ search.set("since", since);
1299
+ const url = `${origin}/_akan/studio?${search.toString()}`;
1300
+ if (open)
1301
+ await openBrowser(url);
1302
+ Logger3.rawLog(format === "json" ? JSON.stringify({ url }) : url);
1303
+ }
1281
1304
  async build(app, {
1282
1305
  write = true,
1283
1306
  fast = false,
@@ -1577,7 +1600,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1577
1600
  await Promise.all(shares.map(async (share) => await share.close()));
1578
1601
  }, "Abandoning the tunnel release; the shares expire on their own.");
1579
1602
  await Promise.all(apps.map(async (app) => {
1580
- const { TunnelShare } = await import("./TunnelShare-hdq9h1hr.js");
1603
+ const { TunnelShare } = await import("./TunnelShare-jwbb50kz.js");
1581
1604
  const share = await TunnelShare.open(app, { workspace: app.workspace });
1582
1605
  shares.push(share);
1583
1606
  urls.set(app.name, share.url);
@@ -1,4 +1,423 @@
1
1
  // @bun
2
+ // pkgs/@akanjs/language/akanGraphDiff.ts
3
+ var edgeKeyOf = ({ from, to, kind, label }) => `${from}
4
+ ${to}
5
+ ${kind}
6
+ ${label ?? ""}`;
7
+ var shapeOf = ({ type, array, optional, declaredIn }) => `${type ?? ""}${array ? "[]" : ""}${optional ? "?" : ""} ${declaredIn}`;
8
+ var isEdited = (before, after) => before.digest !== undefined && after.digest !== undefined && before.digest !== after.digest;
9
+ var byId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
10
+
11
+ class AkanGraphDiff {
12
+ static between(base, head) {
13
+ const baseNodes = new Map(base.nodes.map((node) => [node.id, node]));
14
+ const headNodes = new Map(head.nodes.map((node) => [node.id, node]));
15
+ const marked = new Map;
16
+ for (const node of head.nodes) {
17
+ const before = baseNodes.get(node.id);
18
+ const next = before ? AkanGraphDiff.#compare(before, node) : AkanGraphDiff.#mark(node, "added");
19
+ if (next)
20
+ marked.set(node.id, next);
21
+ }
22
+ for (const node of base.nodes)
23
+ if (!headNodes.has(node.id))
24
+ marked.set(node.id, AkanGraphDiff.#mark(node, "removed"));
25
+ const baseKeys = new Set(base.edges.map(edgeKeyOf));
26
+ const headKeys = new Set(head.edges.map(edgeKeyOf));
27
+ const edges = [
28
+ ...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
29
+ ...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
30
+ ];
31
+ const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
32
+ const node = headNodes.get(id) ?? baseNodes.get(id);
33
+ return node ? [node] : [];
34
+ });
35
+ const nodes = [...new Map([...marked.values(), ...context].map((node) => [node.id, node])).values()].map(AkanGraphDiff.#withoutDigest).sort(byId);
36
+ const summary = { added: 0, removed: 0, changed: 0 };
37
+ for (const node of marked.values())
38
+ if (node.change)
39
+ summary[node.change] += 1;
40
+ return { version: 1, nodes, edges, summary };
41
+ }
42
+ static #mark(node, change) {
43
+ return node.fields ? { ...node, change, fields: node.fields.map((field) => ({ ...field, change })) } : { ...node, change };
44
+ }
45
+ static #compare(before, after) {
46
+ const fields = AkanGraphDiff.#fieldsBetween(before.fields, after.fields);
47
+ const isChanged = isEdited(before, after) || before.label !== after.label || before.detail.join(`
48
+ `) !== after.detail.join(`
49
+ `) || (before.values ?? []).join(`
50
+ `) !== (after.values ?? []).join(`
51
+ `) || !!fields?.some((field) => field.change);
52
+ if (!isChanged)
53
+ return null;
54
+ return fields ? { ...after, change: "changed", fields } : { ...after, change: "changed" };
55
+ }
56
+ static #fieldsBetween(before, after) {
57
+ if (!before && !after)
58
+ return;
59
+ const previous = new Map((before ?? []).map((field) => [field.name, field]));
60
+ const names = new Set((after ?? []).map((field) => field.name));
61
+ return [
62
+ ...(after ?? []).map((field) => {
63
+ const old = previous.get(field.name);
64
+ if (!old)
65
+ return { ...field, change: "added" };
66
+ return shapeOf(old) === shapeOf(field) && !isEdited(old, field) ? field : { ...field, change: "changed" };
67
+ }),
68
+ ...(before ?? []).filter((field) => !names.has(field.name)).map((field) => ({ ...field, change: "removed" }))
69
+ ];
70
+ }
71
+ static #withoutDigest({ digest: _digest, ...node }) {
72
+ return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
73
+ }
74
+ }
75
+ // pkgs/@akanjs/language/akanGraph.ts
76
+ var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
77
+ var lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
78
+ var memberSourcePattern = /\.(signal|service|store)\.ts$/;
79
+ var skippedPattern = /(?:\.(?:constant|document|dictionary|test|spec)\.tsx?|\/lib\/(?:cnst|db|dict|sig|srv|st|useClient|useServer)\.ts|\/index\.tsx?|^(?:apps|libs)\/[^/]+\/(?:client|server)\.ts)$/;
80
+ var scalarPattern = /\/lib\/__scalar\/([^/]+)\/[^/]+\.constant\.ts$/;
81
+ var moduleDirPattern = /\/lib\/([^/]+)\//;
82
+ var typeKinds = new Set(["model", "scalar", "enum"]);
83
+ var clientRoots = new Set(["fetch", "st", "sig"]);
84
+
85
+ class GraphBuilder {
86
+ #source;
87
+ #nodes = new Map;
88
+ #edges = new Map;
89
+ #contexts = new Map;
90
+ #members = new Map;
91
+ constructor(source) {
92
+ this.#source = source;
93
+ }
94
+ build() {
95
+ const { facts } = this.#source;
96
+ const constantsByOwner = new Map;
97
+ for (const file of facts)
98
+ constantsByOwner.set(file.owner, [...constantsByOwner.get(file.owner) ?? [], ...file.constants]);
99
+ const scopeOf = (owner) => [
100
+ ...constantsByOwner.get(owner) ?? [],
101
+ ...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
102
+ ];
103
+ const typed = [];
104
+ for (const file of facts) {
105
+ const { owner } = file;
106
+ const scalar = this.#source.relative(file.fileName).match(scalarPattern)?.[1];
107
+ const scalarClass = scalar ? file.constants.find((constant) => constant.name === capitalize(scalar)) : undefined;
108
+ if (scalar && scalarClass) {
109
+ const id = this.#key("scalar", owner, scalar);
110
+ const node = this.#addNode(id, "scalar", owner, scalar, scalarClass.name, scalarClass.span);
111
+ node.fields = this.#fieldsOf(scalarClass, scopeOf(owner));
112
+ typed.push(node);
113
+ }
114
+ for (const item of file.enums) {
115
+ const id = this.#key("enum", owner, item.name);
116
+ this.#addNode(id, "enum", owner, this.#moduleDirOf(file.fileName), item.name, item.span).values = item.values;
117
+ }
118
+ }
119
+ for (const file of facts) {
120
+ const { owner } = file;
121
+ for (const service of file.services) {
122
+ const refName = service.model;
123
+ if (!refName)
124
+ continue;
125
+ const modelId = this.#key("model", owner, refName);
126
+ const modelClass = constantsByOwner.get(owner)?.find((constant) => constant.name === capitalize(refName));
127
+ if (modelClass && !this.#nodes.has(modelId)) {
128
+ const node = this.#addNode(modelId, "model", owner, refName, modelClass.name, modelClass.span);
129
+ node.fields = this.#fieldsOf(modelClass, scopeOf(owner));
130
+ typed.push(node);
131
+ }
132
+ for (const method of service.methods)
133
+ this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
134
+ }
135
+ for (const filter of file.filters) {
136
+ if (!filter.name.endsWith("Filter"))
137
+ continue;
138
+ const refName = lowerFirst(filter.name.slice(0, -"Filter".length));
139
+ this.#addNode(this.#key("query", owner, refName), "query", owner, refName, "", filter.span);
140
+ for (const query of filter.queries)
141
+ this.#digest(this.#addNode(this.#key("query", owner, refName, query.name), "query", owner, refName, query.name, query.span), this.#source.readText(file.fileName), query.extent);
142
+ }
143
+ for (const slice of file.slices) {
144
+ const refName = slice.model;
145
+ if (!refName)
146
+ continue;
147
+ const fallback = this.#addNode(this.#key("slice", owner, refName), "slice", owner, refName, "", slice.span, slice.guards);
148
+ for (const guard of slice.guards)
149
+ this.#guard(fallback, guard);
150
+ for (const key of slice.keys) {
151
+ const detail = [...key.guards, ...key.live ? ["live"] : []];
152
+ const node = this.#addMember("slice", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
153
+ for (const guard of key.guards)
154
+ this.#guard(node, guard);
155
+ }
156
+ }
157
+ for (const endpoint of file.endpoints) {
158
+ const refName = endpoint.model;
159
+ if (!refName)
160
+ continue;
161
+ for (const key of endpoint.keys) {
162
+ const detail = [...key.verb ? [key.verb] : [], ...key.guards];
163
+ const node = this.#addMember("endpoint", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
164
+ for (const guard of key.guards)
165
+ this.#guard(node, guard);
166
+ }
167
+ }
168
+ for (const store of file.stores)
169
+ if (store.model)
170
+ for (const action of store.actions)
171
+ this.#addMember("action", owner, store.model, action, `${store.name}.${action.name}`, file.fileName);
172
+ }
173
+ const types = new Map;
174
+ for (const node of this.#nodes.values())
175
+ if (typeKinds.has(node.kind))
176
+ types.set(node.label, [...types.get(node.label) ?? [], node]);
177
+ for (const node of typed)
178
+ for (const field of node.fields ?? []) {
179
+ const candidates = (field.type ? types.get(field.type) ?? [] : []).filter((type) => this.#visible(type.owner, node.owner));
180
+ field.ref = (candidates.find((type) => type.owner === node.owner) ?? candidates[0])?.id ?? null;
181
+ if (field.ref)
182
+ this.#addEdge(node.id, field.ref, "field", `${field.name}${field.array ? "[]" : ""}`, field.at);
183
+ }
184
+ for (const [fileName, words] of this.#source.files)
185
+ this.#walk(fileName, words);
186
+ return {
187
+ version: 1,
188
+ nodes: [...this.#nodes.values()].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
189
+ edges: [...this.#edges.values()]
190
+ };
191
+ }
192
+ #key(kind, owner, scope, name = "") {
193
+ return `${kind}:${owner ?? ""}:${scope}${name ? `.${name}` : ""}`;
194
+ }
195
+ #location(span) {
196
+ return { file: this.#source.relative(span.fileName), line: span.line + 1, column: span.character + 1 };
197
+ }
198
+ #addNode(id, kind, owner, module, name, span, detail = [], label = (kind === "query" || kind === "slice") && module ? `${module}${name ? `.${name}` : " (default)"}` : name) {
199
+ const existing = this.#nodes.get(id);
200
+ if (existing)
201
+ return existing;
202
+ const node = {
203
+ id,
204
+ kind,
205
+ name,
206
+ label,
207
+ owner,
208
+ module,
209
+ detail,
210
+ at: span ? this.#location(span) : null
211
+ };
212
+ this.#nodes.set(id, node);
213
+ return node;
214
+ }
215
+ #addMember(kind, owner, refName, member, label, fileName, detail = []) {
216
+ const id = this.#key(kind, owner, refName, member.name);
217
+ const node = this.#addNode(id, kind, owner, refName, member.name, member.span, detail, label);
218
+ this.#digest(node, this.#source.readText(fileName), member.extent);
219
+ this.#contexts.set(fileName, [
220
+ ...this.#contexts.get(fileName) ?? [],
221
+ { id, kind, owner, module: refName, extent: member.extent }
222
+ ]);
223
+ const byName = `${kind}:${member.name}`;
224
+ this.#members.set(byName, [...this.#members.get(byName) ?? [], node]);
225
+ return node;
226
+ }
227
+ #hashOf(text, { start, end }) {
228
+ if (!this.#source.digests || text === undefined)
229
+ return null;
230
+ let hash = 2166136261;
231
+ for (let idx = start;idx < end; idx++) {
232
+ const code = text.charCodeAt(idx);
233
+ if (code !== 13)
234
+ hash = Math.imul(hash ^ code, 16777619);
235
+ }
236
+ return (hash >>> 0).toString(16).padStart(8, "0");
237
+ }
238
+ #digest(node, text, extent) {
239
+ const digest = node.digest ? null : this.#hashOf(text, extent);
240
+ if (digest)
241
+ node.digest = digest;
242
+ }
243
+ #addEdge(from, to, kind, label, at) {
244
+ if (from === to)
245
+ return;
246
+ const key = `${from}
247
+ ${to}
248
+ ${kind}
249
+ ${label ?? ""}`;
250
+ const existing = this.#edges.get(key);
251
+ if (existing)
252
+ existing.count += 1;
253
+ else
254
+ this.#edges.set(key, { from, to, kind, label, count: 1, at });
255
+ }
256
+ #guard(node, guard) {
257
+ const [role, name] = guard.includes(" ") ? guard.split(" ") : [null, guard];
258
+ if (!name || name === "?")
259
+ return;
260
+ const id = `guard:${name}`;
261
+ if (!this.#nodes.has(id))
262
+ this.#nodes.set(id, { id, kind: "guard", name, label: name, owner: null, module: null, detail: [], at: null });
263
+ this.#addEdge(node.id, id, "guard", role, node.at);
264
+ }
265
+ #moduleDirOf(fileName) {
266
+ const dir = this.#source.relative(fileName).match(moduleDirPattern)?.[1] ?? null;
267
+ return dir?.startsWith("_") && !dir.startsWith("__") ? dir.slice(1) : dir;
268
+ }
269
+ #fieldsOf(constant, scope) {
270
+ const fields = new Map;
271
+ const seen = new Set;
272
+ const visit = (current) => {
273
+ if (seen.has(current))
274
+ return;
275
+ seen.add(current);
276
+ for (const parent of current.parents) {
277
+ const parentClass = scope.find((other) => other.name === parent && other.span.fileName === current.span.fileName) ?? scope.find((other) => other.name === parent);
278
+ if (parentClass)
279
+ visit(parentClass);
280
+ }
281
+ for (const field of current.fields) {
282
+ if (fields.has(field.name))
283
+ continue;
284
+ const digest = this.#hashOf(this.#source.readText(field.span.fileName), field.extent);
285
+ fields.set(field.name, {
286
+ name: field.name,
287
+ type: field.type,
288
+ array: field.array,
289
+ optional: field.optional,
290
+ ref: null,
291
+ declaredIn: current.name,
292
+ at: this.#location(field.span),
293
+ ...digest ? { digest } : {}
294
+ });
295
+ }
296
+ };
297
+ visit(constant);
298
+ return [...fields.values()];
299
+ }
300
+ #visible(target, from) {
301
+ return !from || !target || target === from || target.startsWith("libs/");
302
+ }
303
+ #targetNodeOf({ family, owner, refName, sourceKey }) {
304
+ const isDefault = /^[A-Z]/.test(sourceKey);
305
+ const id = family === "slice" || family === "query" ? this.#key(family, owner, refName, isDefault ? "" : sourceKey) : family === "model" || family === "formSetter" ? this.#key("model", owner, refName) : family === "endpoint" ? this.#key("endpoint", owner, refName, sourceKey) : null;
306
+ return id && this.#nodes.has(id) ? id : null;
307
+ }
308
+ #membersNamed(kind, name, owner, refName) {
309
+ const nodes = (this.#members.get(`${kind}:${name}`) ?? []).filter((node) => (!refName || node.module === refName) && this.#visible(node.owner, owner));
310
+ const own = nodes.filter((node) => node.owner === owner);
311
+ return (own.length ? own : nodes).map((node) => node.id);
312
+ }
313
+ #plainTargetsOf(chain, name, context, owner) {
314
+ const [head, second] = chain ?? [];
315
+ if (chain?.length === 1 && head === "fetch")
316
+ return this.#membersNamed("endpoint", name, owner);
317
+ if (chain?.length === 2 && head === "st" && second === "do")
318
+ return this.#membersNamed("action", name, owner);
319
+ if (chain?.length === 1 && head === "this" && (context.kind === "method" || context.kind === "action"))
320
+ return this.#membersNamed(context.kind, name, context.owner, context.module).filter((id) => id.startsWith(`${context.kind}:${context.owner ?? ""}:`));
321
+ if (chain?.length === 2 && head === "this" && second && /.Service$/.test(second))
322
+ return this.#membersNamed("method", name, owner, second.slice(0, -"Service".length));
323
+ return [];
324
+ }
325
+ #walk(fileName, words) {
326
+ const relative = this.#source.relative(fileName);
327
+ const contexts = this.#contexts.get(fileName);
328
+ const isComponentFile = !memberSourcePattern.test(fileName) && !skippedPattern.test(relative) && (words.includes(`
329
+ fetch
330
+ `) || words.includes(`
331
+ st
332
+ `));
333
+ if (!contexts && !isComponentFile)
334
+ return;
335
+ const text = this.#source.readText(fileName);
336
+ if (text === undefined)
337
+ return;
338
+ const { ts } = this.#source;
339
+ const owner = this.#source.ownerOf(fileName);
340
+ const source = this.#source.parse(fileName, text);
341
+ const visit = (node) => {
342
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
343
+ const start = node.name.getStart(source);
344
+ const chain = this.#chainOf(node.expression);
345
+ const context = contexts ? contexts.find(({ extent }) => extent.start <= start && start < extent.end) : chain && clientRoots.has(chain[0]) ? this.#componentOf(source, node) : undefined;
346
+ if (context)
347
+ this.#link(fileName, source, node.name, chain, context, owner);
348
+ }
349
+ ts.forEachChild(node, visit);
350
+ };
351
+ visit(source);
352
+ }
353
+ #link(fileName, source, identifier, chain, context, owner) {
354
+ const resolved = this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
355
+ const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
356
+ if (!targets.length)
357
+ return;
358
+ if (context.pending && !this.#nodes.has(context.id)) {
359
+ this.#nodes.set(context.id, context.pending);
360
+ this.#digest(context.pending, source.text, context.extent);
361
+ }
362
+ const own = targets.filter((id) => this.#nodes.get(id)?.owner === owner);
363
+ const kind = context.kind === "component" ? "uses" : chain?.[0] === "fetch" ? "fetches" : "calls";
364
+ const position = source.getLineAndCharacterOfPosition(identifier.getStart(source));
365
+ const at = { file: this.#source.relative(fileName), line: position.line + 1, column: position.character + 1 };
366
+ for (const target of new Set(own.length ? own : targets))
367
+ this.#addEdge(context.id, target, kind, identifier.text, at);
368
+ }
369
+ #chainOf(expression) {
370
+ const { ts } = this.#source;
371
+ if (ts.isNonNullExpression(expression) || ts.isParenthesizedExpression(expression))
372
+ return this.#chainOf(expression.expression);
373
+ if (ts.isIdentifier(expression))
374
+ return [expression.text];
375
+ if (expression.kind === ts.SyntaxKind.ThisKeyword)
376
+ return ["this"];
377
+ if (!ts.isPropertyAccessExpression(expression))
378
+ return null;
379
+ const head = this.#chainOf(expression.expression);
380
+ return head ? [...head, expression.name.text] : null;
381
+ }
382
+ #componentOf(source, node) {
383
+ const { ts } = this.#source;
384
+ let top = node;
385
+ while (top.parent && !ts.isSourceFile(top.parent))
386
+ top = top.parent;
387
+ const declared = ts.isVariableStatement(top) ? top.declarationList.declarations[0]?.name : ts.isFunctionDeclaration(top) || ts.isClassDeclaration(top) ? top.name : undefined;
388
+ const isDefaultExport = ts.canHaveModifiers(top) && !!ts.getModifiers(top)?.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword);
389
+ const name = declared && ts.isIdentifier(declared) && !isDefaultExport ? declared.text : "default";
390
+ const relative = this.#source.relative(source.fileName);
391
+ const owner = this.#source.ownerOf(source.fileName);
392
+ const id = `component:${relative}#${name}`;
393
+ const context = {
394
+ id,
395
+ kind: "component",
396
+ owner,
397
+ module: null,
398
+ extent: { start: top.getStart(source), end: top.getEnd() }
399
+ };
400
+ if (this.#nodes.has(id))
401
+ return context;
402
+ const pagePrefix = owner ? `${owner}/page/` : null;
403
+ const route = pagePrefix && relative.startsWith(pagePrefix) ? relative.slice(pagePrefix.length).replace(/\.tsx?$/, "") : null;
404
+ const base = relative.slice(relative.lastIndexOf("/") + 1).replace(/\.tsx?$/, "");
405
+ const label = route ? `${route}${name === "default" ? "" : `#${name}`}` : name === "default" ? base : `${base}.${name}`;
406
+ const position = source.getLineAndCharacterOfPosition((declared ?? top).getStart(source));
407
+ context.pending = {
408
+ id,
409
+ kind: "component",
410
+ name,
411
+ label,
412
+ owner,
413
+ module: this.#moduleDirOf(source.fileName),
414
+ detail: route ? ["page"] : [],
415
+ at: { file: relative, line: position.line + 1, column: position.character + 1 }
416
+ };
417
+ return context;
418
+ }
419
+ }
420
+
2
421
  // pkgs/@akanjs/language/ast.ts
3
422
  var createAst = (ts) => {
4
423
  const sourceFileFor = (fileName, content, scriptKind = ts.ScriptKind.TS) => ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, scriptKind);
@@ -65,7 +484,7 @@ var createAst = (ts) => {
65
484
  };
66
485
 
67
486
  // pkgs/@akanjs/language/moduleFacts.ts
68
- var moduleCallees = new Set(["via", "from", "into", "serve", "slice", "endpoint", "store"]);
487
+ var moduleCallees = new Set(["via", "from", "into", "serve", "slice", "endpoint", "store", "enumOf"]);
69
488
  var argMethods = new Set(["param", "body", "search", "room", "msg"]);
70
489
  var ownerOf = (relativePath) => {
71
490
  const [root, name] = relativePath.split("/");
@@ -87,6 +506,10 @@ var createFactReader = (ts, ast) => {
87
506
  endCharacter: tail.character
88
507
  };
89
508
  };
509
+ const extentOf = (source, node) => ({
510
+ start: node.getStart(source),
511
+ end: node.getEnd()
512
+ });
90
513
  const unwrap = (expression) => {
91
514
  let current = expression;
92
515
  while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current))
@@ -130,7 +553,7 @@ var createFactReader = (ts, ast) => {
130
553
  const objectKeys = (source, object) => (object?.properties ?? []).flatMap((property) => {
131
554
  const name = ast.propertyName(property);
132
555
  const node = keyName(property);
133
- return name && node ? [{ name, span: spanOf(source, node) }] : [];
556
+ return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
134
557
  });
135
558
  const sliceKeysOf = (source, builder) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
136
559
  if (!ts.isPropertyAssignment(property))
@@ -143,6 +566,7 @@ var createFactReader = (ts, ast) => {
143
566
  {
144
567
  name,
145
568
  span: spanOf(source, property.name),
569
+ extent: extentOf(source, property),
146
570
  guards: root ? guardsIn(optionObjectOf(root)) : [],
147
571
  live: methods.includes("live"),
148
572
  argCount: methods.filter((method) => argMethods.has(method)).length
@@ -179,6 +603,7 @@ var createFactReader = (ts, ast) => {
179
603
  {
180
604
  name,
181
605
  span: spanOf(source, property.name),
606
+ extent: extentOf(source, property),
182
607
  verb: root ? verbOf(root.expression) : null,
183
608
  guards: root ? guardsIn(optionObjectOf(root)) : [],
184
609
  argCount: methods.filter((method) => argMethods.has(method)).length
@@ -190,17 +615,54 @@ var createFactReader = (ts, ast) => {
190
615
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
191
616
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
192
617
  };
618
+ const typeOf = (expression) => {
619
+ const value = expression && unwrap(expression);
620
+ if (value && ts.isArrayLiteralExpression(value))
621
+ return { type: typeOf(value.elements[0]).type, array: true };
622
+ return { type: value ? ast.expressionName(value) : null, array: false };
623
+ };
624
+ const fieldsOf = (source, object) => (object?.properties ?? []).flatMap((property) => {
625
+ const name = ast.propertyName(property);
626
+ const node = keyName(property);
627
+ if (!name || !node)
628
+ return [];
629
+ const { root, methods } = ts.isPropertyAssignment(property) ? chainOf(property.initializer) : { root: null, methods: [] };
630
+ return [
631
+ {
632
+ name,
633
+ span: spanOf(source, node),
634
+ extent: extentOf(source, property),
635
+ ...typeOf(root?.arguments[0]),
636
+ optional: methods.includes("optional")
637
+ }
638
+ ];
639
+ });
193
640
  const constantOf = (source, name, call) => {
194
641
  const parents = call.arguments.map(unwrap).filter((arg) => ts.isIdentifier(arg) || ts.isPropertyAccessExpression(arg)).map((arg) => ast.expressionName(arg)).filter((parent) => parent !== null);
195
- const fields = call.arguments.flatMap((arg) => objectKeys(source, ast.firstObjectReturnedByArrow(arg)));
642
+ const fields = call.arguments.flatMap((arg) => fieldsOf(source, ast.firstObjectReturnedByArrow(arg)));
196
643
  return { ...name, parents, fields };
197
644
  };
645
+ const enumValuesOf = (call) => {
646
+ const list = call.arguments[1] && unwrap(call.arguments[1]);
647
+ if (!list || !ts.isArrayLiteralExpression(list))
648
+ return [];
649
+ return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
650
+ };
651
+ const methodsOf = (source, statement) => statement.members.flatMap((member) => {
652
+ if (!ts.isMethodDeclaration(member) || !member.body)
653
+ return [];
654
+ const name = ast.nodeName(member.name);
655
+ if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
656
+ return [];
657
+ return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
658
+ });
198
659
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
199
660
  const read = (source, owner) => {
200
661
  const facts = {
201
662
  fileName: source.fileName,
202
663
  owner,
203
664
  constants: [],
665
+ enums: [],
204
666
  filters: [],
205
667
  models: [],
206
668
  services: [],
@@ -219,12 +681,18 @@ var createFactReader = (ts, ast) => {
219
681
  const builder = builderOf(call);
220
682
  if (callee === "via")
221
683
  facts.constants.push(constantOf(source, name, call));
684
+ else if (callee === "enumOf")
685
+ facts.enums.push({ ...name, values: enumValuesOf(call) });
222
686
  else if (callee === "from")
223
687
  facts.filters.push({ ...name, queries: filterQueriesOf(source, builder) });
224
688
  else if (callee === "into")
225
689
  facts.models.push({ ...name, model: name.name.endsWith("Model") ? lowerFirst(name.name.slice(0, -5)) : null });
226
690
  else if (callee === "serve")
227
- facts.services.push({ ...name, model: moduleRefOf(call.arguments[0], "db") });
691
+ facts.services.push({
692
+ ...name,
693
+ model: moduleRefOf(call.arguments[0], "db"),
694
+ methods: methodsOf(source, statement)
695
+ });
228
696
  else if (callee === "slice")
229
697
  facts.slices.push({
230
698
  ...name,
@@ -242,7 +710,8 @@ var createFactReader = (ts, ast) => {
242
710
  facts.stores.push({
243
711
  ...name,
244
712
  model: moduleRefOf(call.arguments[0], "sig"),
245
- stateKeys: objectKeys(source, returnedObject(builder))
713
+ stateKeys: objectKeys(source, returnedObject(builder)),
714
+ actions: methodsOf(source, statement)
246
715
  });
247
716
  }
248
717
  return facts;
@@ -261,7 +730,7 @@ import {
261
730
  sliceNames,
262
731
  stateSetterName
263
732
  } from "akanjs/common/akanNames.ts";
264
- var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
733
+ var capitalize2 = (text) => text.charAt(0).toUpperCase() + text.slice(1);
265
734
 
266
735
  class NameTable {
267
736
  #byName = new Map;
@@ -336,7 +805,7 @@ class NameTable {
336
805
  }
337
806
  #addGroup(group, constants) {
338
807
  const { owner, refName } = group;
339
- const Model = capitalize(refName);
808
+ const Model = capitalize2(refName);
340
809
  const base = { owner, refName };
341
810
  const modelClass = group.constants.find((constant) => constant.name === Model);
342
811
  const facts = group.facts;
@@ -629,6 +1098,24 @@ ${[...new Set(text.match(wordPattern))].join(`
629
1098
  referencesAt(givenName, offset, readText) {
630
1099
  return this.#usesOf(this.#sourceEntriesAt(pathOf(givenName), offset), readText).map((use) => use.span);
631
1100
  }
1101
+ graph(readText, { digests = false } = {}) {
1102
+ return new GraphBuilder({
1103
+ digests,
1104
+ ts: this.#ts,
1105
+ facts: [...this.#facts].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, facts]) => facts),
1106
+ files: [...this.#fileWords].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0),
1107
+ readText,
1108
+ parse: (fileName, text) => this.#parse(fileName, text),
1109
+ resolve: (fileName, identifier) => {
1110
+ if (!this.#nameTable().lookup(identifier.text).length)
1111
+ return [];
1112
+ const site = this.#siteOf(identifier);
1113
+ return site ? this.#resolve(fileName, site) : [];
1114
+ },
1115
+ relative: (fileName) => this.#relative(fileName),
1116
+ ownerOf: (fileName) => this.#ownerOf(fileName)
1117
+ }).build();
1118
+ }
632
1119
  renameTargetAt(givenName, offset) {
633
1120
  const source = this.#sourceEntriesAt(pathOf(givenName), offset).find((entry) => entry.renamed);
634
1121
  return source ? { family: source.family, sourceKey: source.sourceKey, span: source.span } : null;
@@ -873,4 +1360,4 @@ ${dictionary.className}
873
1360
  })).sort((a, b) => Number(b.owner === owner) - Number(a.owner === owner));
874
1361
  }
875
1362
  }
876
- export { createAst, createFactReader, AkanIndex };
1363
+ export { AkanGraphDiff, createAst, createFactReader, AkanIndex };