@archdoc/cli 0.0.0-stage → 0.1.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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin.d.ts +3 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +6 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/commands/check.d.ts +23 -0
  7. package/dist/commands/check.d.ts.map +1 -0
  8. package/dist/commands/check.js +58 -0
  9. package/dist/commands/check.js.map +1 -0
  10. package/dist/commands/code.d.ts +24 -0
  11. package/dist/commands/code.d.ts.map +1 -0
  12. package/dist/commands/code.js +92 -0
  13. package/dist/commands/code.js.map +1 -0
  14. package/dist/commands/context.d.ts +26 -0
  15. package/dist/commands/context.d.ts.map +1 -0
  16. package/dist/commands/context.js +117 -0
  17. package/dist/commands/context.js.map +1 -0
  18. package/dist/commands/data.d.ts +12 -0
  19. package/dist/commands/data.d.ts.map +1 -0
  20. package/dist/commands/data.js +63 -0
  21. package/dist/commands/data.js.map +1 -0
  22. package/dist/commands/diff.d.ts +17 -0
  23. package/dist/commands/diff.d.ts.map +1 -0
  24. package/dist/commands/diff.js +79 -0
  25. package/dist/commands/diff.js.map +1 -0
  26. package/dist/commands/federation.d.ts +20 -0
  27. package/dist/commands/federation.d.ts.map +1 -0
  28. package/dist/commands/federation.js +96 -0
  29. package/dist/commands/federation.js.map +1 -0
  30. package/dist/commands/init.d.ts +13 -0
  31. package/dist/commands/init.d.ts.map +1 -0
  32. package/dist/commands/init.js +24 -0
  33. package/dist/commands/init.js.map +1 -0
  34. package/dist/commands/landscape.d.ts +14 -0
  35. package/dist/commands/landscape.d.ts.map +1 -0
  36. package/dist/commands/landscape.js +52 -0
  37. package/dist/commands/landscape.js.map +1 -0
  38. package/dist/commands/migrate.d.ts +8 -0
  39. package/dist/commands/migrate.d.ts.map +1 -0
  40. package/dist/commands/migrate.js +38 -0
  41. package/dist/commands/migrate.js.map +1 -0
  42. package/dist/commands/report.d.ts +16 -0
  43. package/dist/commands/report.d.ts.map +1 -0
  44. package/dist/commands/report.js +77 -0
  45. package/dist/commands/report.js.map +1 -0
  46. package/dist/commands/schema.d.ts +5 -0
  47. package/dist/commands/schema.d.ts.map +1 -0
  48. package/dist/commands/schema.js +15 -0
  49. package/dist/commands/schema.js.map +1 -0
  50. package/dist/commands/seal.d.ts +25 -0
  51. package/dist/commands/seal.d.ts.map +1 -0
  52. package/dist/commands/seal.js +64 -0
  53. package/dist/commands/seal.js.map +1 -0
  54. package/dist/commands/site.d.ts +14 -0
  55. package/dist/commands/site.d.ts.map +1 -0
  56. package/dist/commands/site.js +42 -0
  57. package/dist/commands/site.js.map +1 -0
  58. package/dist/commands/trace.d.ts +5 -0
  59. package/dist/commands/trace.d.ts.map +1 -0
  60. package/dist/commands/trace.js +39 -0
  61. package/dist/commands/trace.js.map +1 -0
  62. package/dist/commands/validate.d.ts +8 -0
  63. package/dist/commands/validate.d.ts.map +1 -0
  64. package/dist/commands/validate.js +49 -0
  65. package/dist/commands/validate.js.map +1 -0
  66. package/dist/commands/view.d.ts +17 -0
  67. package/dist/commands/view.d.ts.map +1 -0
  68. package/dist/commands/view.js +50 -0
  69. package/dist/commands/view.js.map +1 -0
  70. package/dist/index.d.ts +4 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +4 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/io.d.ts +7 -0
  75. package/dist/io.d.ts.map +1 -0
  76. package/dist/io.js +6 -0
  77. package/dist/io.js.map +1 -0
  78. package/dist/landscape.d.ts +28 -0
  79. package/dist/landscape.d.ts.map +1 -0
  80. package/dist/landscape.js +34 -0
  81. package/dist/landscape.js.map +1 -0
  82. package/dist/model-path.d.ts +7 -0
  83. package/dist/model-path.d.ts.map +1 -0
  84. package/dist/model-path.js +17 -0
  85. package/dist/model-path.js.map +1 -0
  86. package/dist/program.d.ts +7 -0
  87. package/dist/program.d.ts.map +1 -0
  88. package/dist/program.js +197 -0
  89. package/dist/program.js.map +1 -0
  90. package/dist/server.d.ts +297 -0
  91. package/dist/server.d.ts.map +1 -0
  92. package/dist/server.js +348 -0
  93. package/dist/server.js.map +1 -0
  94. package/package.json +35 -3
  95. package/web/assets/index-CDAgYSBW.js +210 -0
  96. package/web/assets/index-k7lSjazl.css +1 -0
  97. package/web/favicon.svg +1 -0
  98. package/web/index.html +14 -0
  99. package/README.md +0 -3
@@ -0,0 +1,297 @@
1
+ import { type RepoInfo, type SourcesAtRef } from "@archdoc/core";
2
+ export interface ViewServerOptions {
3
+ /** Repository, .archdoc directory, or model file. */
4
+ target: string;
5
+ cwd: string;
6
+ /** 0 picks a free port. */
7
+ port?: number;
8
+ host?: string;
9
+ /** Watch the model files and tell the explorer to reload when they change. */
10
+ watch?: boolean;
11
+ /** Directory with the built explorer. Found automatically when omitted. */
12
+ webDir?: string;
13
+ /** Also send the model as it was at this ref, for the explorer's before/after view. */
14
+ base?: string;
15
+ /** Send the landscape: this model composed with every model it imports. */
16
+ landscape?: boolean;
17
+ }
18
+ export interface ViewServer {
19
+ url: string;
20
+ /** Absolute directory (or file) being served and watched. */
21
+ source?: string | undefined;
22
+ close(): Promise<void>;
23
+ }
24
+ /**
25
+ * Serves the explorer and the model to it. The browser builds the model from
26
+ * the raw files with @archdoc/core, so the CLI and the explorer always agree.
27
+ * Listens on localhost only.
28
+ */
29
+ export declare function startViewServer(options: ViewServerOptions): Promise<ViewServer>;
30
+ /**
31
+ * The built explorer: ARCHDOC_WEB_DIR, the workspace build (when running from a
32
+ * clone), or the copy that `prepack` puts next to the published CLI.
33
+ */
34
+ export declare function findWebDir(): string | undefined;
35
+ /**
36
+ * What /api/model sends, and what `archdoc site` writes: the working tree's
37
+ * model, and with `base`, the model at the merge base with it and the findings
38
+ * the change introduced, so the Changes tab shows what the PR comment says.
39
+ */
40
+ export declare function modelResponse(options: {
41
+ target: string;
42
+ cwd: string;
43
+ base?: string | undefined;
44
+ }): Promise<{
45
+ seals: {
46
+ file: string;
47
+ error: string | undefined;
48
+ total: number;
49
+ facts: {
50
+ key: string;
51
+ label: string;
52
+ state: import("@archdoc/core").SealState;
53
+ element: string | undefined;
54
+ refs: string[];
55
+ changes: string[];
56
+ location: import("@archdoc/core").SourceLocation | undefined;
57
+ }[];
58
+ } | undefined;
59
+ root: string;
60
+ sources: import("@archdoc/core").ModelSource[];
61
+ files: string[];
62
+ snippets: Record<string, import("@archdoc/core").SnippetPlace>;
63
+ federation: {
64
+ lockPath: string;
65
+ lock: {
66
+ lockfileVersion: 1;
67
+ imports: Record<string, {
68
+ source: string;
69
+ bundle: string;
70
+ integrity: string;
71
+ requested?: string | undefined;
72
+ version?: string | undefined;
73
+ ref?: string | undefined;
74
+ commit?: string | undefined;
75
+ }>;
76
+ landscape?: {
77
+ source: string;
78
+ bundle: string;
79
+ integrity: string;
80
+ namespace: string;
81
+ requested?: string | undefined;
82
+ version?: string | undefined;
83
+ ref?: string | undefined;
84
+ commit?: string | undefined;
85
+ } | undefined;
86
+ } | undefined;
87
+ lockError: string | undefined;
88
+ bundles: {
89
+ path: string;
90
+ text?: string | undefined;
91
+ integrity?: string | undefined;
92
+ key: string;
93
+ }[];
94
+ };
95
+ samples: {
96
+ path: string;
97
+ text: string;
98
+ }[];
99
+ traces: {
100
+ path: string;
101
+ text: string;
102
+ }[];
103
+ schemas: import("@archdoc/core").ImportedSchema[];
104
+ repo: RepoInfo & {
105
+ root?: string | undefined;
106
+ };
107
+ commit?: string | undefined;
108
+ } | {
109
+ base: SourcesAtRef;
110
+ seals: {
111
+ file: string;
112
+ error: string | undefined;
113
+ total: number;
114
+ facts: {
115
+ key: string;
116
+ label: string;
117
+ state: import("@archdoc/core").SealState;
118
+ element: string | undefined;
119
+ refs: string[];
120
+ changes: string[];
121
+ location: import("@archdoc/core").SourceLocation | undefined;
122
+ }[];
123
+ } | undefined;
124
+ root: string;
125
+ sources: import("@archdoc/core").ModelSource[];
126
+ files: string[];
127
+ snippets: Record<string, import("@archdoc/core").SnippetPlace>;
128
+ federation: {
129
+ lockPath: string;
130
+ lock: {
131
+ lockfileVersion: 1;
132
+ imports: Record<string, {
133
+ source: string;
134
+ bundle: string;
135
+ integrity: string;
136
+ requested?: string | undefined;
137
+ version?: string | undefined;
138
+ ref?: string | undefined;
139
+ commit?: string | undefined;
140
+ }>;
141
+ landscape?: {
142
+ source: string;
143
+ bundle: string;
144
+ integrity: string;
145
+ namespace: string;
146
+ requested?: string | undefined;
147
+ version?: string | undefined;
148
+ ref?: string | undefined;
149
+ commit?: string | undefined;
150
+ } | undefined;
151
+ } | undefined;
152
+ lockError: string | undefined;
153
+ bundles: {
154
+ path: string;
155
+ text?: string | undefined;
156
+ integrity?: string | undefined;
157
+ key: string;
158
+ }[];
159
+ };
160
+ samples: {
161
+ path: string;
162
+ text: string;
163
+ }[];
164
+ traces: {
165
+ path: string;
166
+ text: string;
167
+ }[];
168
+ schemas: import("@archdoc/core").ImportedSchema[];
169
+ repo: RepoInfo & {
170
+ root?: string | undefined;
171
+ };
172
+ commit?: string | undefined;
173
+ } | {
174
+ base: {
175
+ root: string;
176
+ sources: import("@archdoc/core").ModelSource[];
177
+ files: string[];
178
+ snippets: Record<string, import("@archdoc/core").SnippetPlace>;
179
+ federation: {
180
+ lockPath: string;
181
+ lock: {
182
+ lockfileVersion: 1;
183
+ imports: Record<string, {
184
+ source: string;
185
+ bundle: string;
186
+ integrity: string;
187
+ requested?: string | undefined;
188
+ version?: string | undefined;
189
+ ref?: string | undefined;
190
+ commit?: string | undefined;
191
+ }>;
192
+ landscape?: {
193
+ source: string;
194
+ bundle: string;
195
+ integrity: string;
196
+ namespace: string;
197
+ requested?: string | undefined;
198
+ version?: string | undefined;
199
+ ref?: string | undefined;
200
+ commit?: string | undefined;
201
+ } | undefined;
202
+ } | undefined;
203
+ lockError: string | undefined;
204
+ bundles: {
205
+ path: string;
206
+ text?: string | undefined;
207
+ integrity?: string | undefined;
208
+ key: string;
209
+ }[];
210
+ };
211
+ samples: {
212
+ path: string;
213
+ text: string;
214
+ }[];
215
+ traces: {
216
+ path: string;
217
+ text: string;
218
+ }[];
219
+ schemas: import("@archdoc/core").ImportedSchema[];
220
+ repo: RepoInfo & {
221
+ root?: string | undefined;
222
+ };
223
+ commit?: string | undefined;
224
+ ref: string;
225
+ };
226
+ change: {
227
+ base: string;
228
+ head: string | undefined;
229
+ commit: string;
230
+ findings: import("@archdoc/core").MarkedFinding[];
231
+ changedFiles: string[];
232
+ };
233
+ seals: {
234
+ file: string;
235
+ error: string | undefined;
236
+ total: number;
237
+ facts: {
238
+ key: string;
239
+ label: string;
240
+ state: import("@archdoc/core").SealState;
241
+ element: string | undefined;
242
+ refs: string[];
243
+ changes: string[];
244
+ location: import("@archdoc/core").SourceLocation | undefined;
245
+ }[];
246
+ } | undefined;
247
+ root: string;
248
+ sources: import("@archdoc/core").ModelSource[];
249
+ files: string[];
250
+ snippets: Record<string, import("@archdoc/core").SnippetPlace>;
251
+ federation: {
252
+ lockPath: string;
253
+ lock: {
254
+ lockfileVersion: 1;
255
+ imports: Record<string, {
256
+ source: string;
257
+ bundle: string;
258
+ integrity: string;
259
+ requested?: string | undefined;
260
+ version?: string | undefined;
261
+ ref?: string | undefined;
262
+ commit?: string | undefined;
263
+ }>;
264
+ landscape?: {
265
+ source: string;
266
+ bundle: string;
267
+ integrity: string;
268
+ namespace: string;
269
+ requested?: string | undefined;
270
+ version?: string | undefined;
271
+ ref?: string | undefined;
272
+ commit?: string | undefined;
273
+ } | undefined;
274
+ } | undefined;
275
+ lockError: string | undefined;
276
+ bundles: {
277
+ path: string;
278
+ text?: string | undefined;
279
+ integrity?: string | undefined;
280
+ key: string;
281
+ }[];
282
+ };
283
+ samples: {
284
+ path: string;
285
+ text: string;
286
+ }[];
287
+ traces: {
288
+ path: string;
289
+ text: string;
290
+ }[];
291
+ schemas: import("@archdoc/core").ImportedSchema[];
292
+ repo: RepoInfo & {
293
+ root?: string | undefined;
294
+ };
295
+ commit?: string | undefined;
296
+ } | undefined>;
297
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,QAAQ,EAMb,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uFAAuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAaD;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4HrF;AA2BD;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,SAAS,CAO/C;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmJkB,MAAM;cAAQ,MAAM;;;cA1BoB,MAAM;cAAQ,MAAM;;;;eA9CnD,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwE3B,MAAM;cAAQ,MAAM;;;cA1BoB,MAAM;cAAQ,MAAM;;;;eA9CnD,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAwE3B,MAAM;kBAAQ,MAAM;;;kBA1BoB,MAAM;kBAAQ,MAAM;;;;mBA9CnD,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwE3B,MAAM;cAAQ,MAAM;;;cA1BoB,MAAM;cAAQ,MAAM;;;;eA9CnD,MAAM,GAAG,SAAS;;;eA/D7C"}
package/dist/server.js ADDED
@@ -0,0 +1,348 @@
1
+ import { existsSync, watch } from "node:fs";
2
+ import { readFile, stat } from "node:fs/promises";
3
+ import { createServer } from "node:http";
4
+ import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { checkRepository, contextOf, importSchemas, sealReport, snapshot, } from "@archdoc/analyzers";
7
+ import { buildModel, isSnippet, listBranches, readFederationInput, readModelSources, repoInfo, resolveGitRef, resolveSnippets, } from "@archdoc/core";
8
+ import { landscapePayload, loadLandscape } from "./landscape.js";
9
+ import { isModelPath } from "./model-path.js";
10
+ const TYPES = {
11
+ ".html": "text/html; charset=utf-8",
12
+ ".js": "text/javascript; charset=utf-8",
13
+ ".css": "text/css; charset=utf-8",
14
+ ".svg": "image/svg+xml",
15
+ ".json": "application/json",
16
+ ".png": "image/png",
17
+ ".ico": "image/x-icon",
18
+ ".woff2": "font/woff2",
19
+ };
20
+ /**
21
+ * Serves the explorer and the model to it. The browser builds the model from
22
+ * the raw files with @archdoc/core, so the CLI and the explorer always agree.
23
+ * Listens on localhost only.
24
+ */
25
+ export async function startViewServer(options) {
26
+ const webDir = options.webDir ?? findWebDir();
27
+ const watching = options.watch === true;
28
+ const clients = new Set();
29
+ const initial = await readModelSources(options.target, { cwd: options.cwd });
30
+ const cwd = options.cwd;
31
+ if (options.base &&
32
+ !isModelPath(cwd, options.base) &&
33
+ !(await resolveGitRef(cwd, options.base))) {
34
+ throw new Error(`"${options.base}" is not a commit, branch, or tag in this repository.`);
35
+ }
36
+ const server = createServer(async (req, res) => {
37
+ const url = new URL(req.url ?? "/", "http://localhost");
38
+ try {
39
+ if (url.pathname === "/api/model" && options.landscape) {
40
+ const { model, composed } = await loadLandscape(options.target, options.cwd);
41
+ return json(res, 200, await landscapePayload(model, composed, watching));
42
+ }
43
+ if (url.pathname === "/api/model") {
44
+ const body = await modelResponse({ target: options.target, cwd, base: options.base });
45
+ if (!body) {
46
+ return json(res, 404, {
47
+ error: `No ArchDoc model found at ${options.target}. Expected .archdoc/archdoc.yaml. Run archdoc init to start one.`,
48
+ });
49
+ }
50
+ return json(res, 200, { ...body, watch: watching });
51
+ }
52
+ if (url.pathname === "/api/refs") {
53
+ const { current, branches } = await listBranches(options.cwd);
54
+ return json(res, 200, { current, branches, base: options.base });
55
+ }
56
+ if (url.pathname === "/api/compare") {
57
+ // Only branches (and the --base the server started with), never arbitrary git arguments.
58
+ const allowed = new Set((await listBranches(cwd)).branches);
59
+ if (options.base)
60
+ allowed.add(options.base);
61
+ const ref = (name) => {
62
+ const value = url.searchParams.get(name);
63
+ if (value === null || value === "")
64
+ return undefined;
65
+ if (!allowed.has(value))
66
+ throw new RangeError(`"${value}" is not a branch in this repository.`);
67
+ return value;
68
+ };
69
+ try {
70
+ const base = ref("base");
71
+ if (!base)
72
+ return json(res, 400, { error: "Pick a base branch to compare with." });
73
+ const head = ref("head");
74
+ // Both sides as the PR comment reads them: the merge base and the head, with
75
+ // schemas, other repos, files, and samples, and the findings the head introduced.
76
+ const compared = await comparison(options.target, cwd, base, head);
77
+ if (!compared)
78
+ return json(res, 404, { error: "No ArchDoc model here." });
79
+ return json(res, 200, compared);
80
+ }
81
+ catch (err) {
82
+ if (err instanceof RangeError)
83
+ return json(res, 400, { error: err.message });
84
+ throw err;
85
+ }
86
+ }
87
+ if (url.pathname === "/api/events") {
88
+ if (!watching)
89
+ return json(res, 404, { error: "Start with --watch for live reload." });
90
+ res.writeHead(200, {
91
+ "content-type": "text/event-stream",
92
+ "cache-control": "no-cache",
93
+ connection: "keep-alive",
94
+ });
95
+ res.write(": connected\n\n");
96
+ clients.add(res);
97
+ req.on("close", () => clients.delete(res));
98
+ return;
99
+ }
100
+ if (!webDir) {
101
+ res.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
102
+ return res.end("The explorer isn't built. In the ArchDoc repo, run `pnpm build`, or set ARCHDOC_WEB_DIR.");
103
+ }
104
+ return await serveStatic(webDir, url.pathname, res);
105
+ }
106
+ catch (err) {
107
+ if (!res.headersSent)
108
+ json(res, 500, { error: err instanceof Error ? err.message : String(err) });
109
+ else
110
+ res.end();
111
+ }
112
+ });
113
+ let watcher;
114
+ const heartbeat = setInterval(() => {
115
+ for (const c of clients)
116
+ c.write(": ping\n\n");
117
+ }, 25_000);
118
+ heartbeat.unref();
119
+ if (watching && initial) {
120
+ let timer;
121
+ const notify = () => {
122
+ clearTimeout(timer);
123
+ timer = setTimeout(() => {
124
+ for (const c of clients)
125
+ c.write("event: change\ndata: {}\n\n");
126
+ }, 80);
127
+ };
128
+ const isFile = (await stat(initial.source)).isFile();
129
+ const dir = isFile ? dirname(initial.source) : initial.source;
130
+ watcher = watch(dir, { recursive: !isFile }, (_event, name) => {
131
+ if (isFile && name !== basename(initial.source))
132
+ return;
133
+ if (name && !/\.ya?ml$/.test(String(name)))
134
+ return;
135
+ notify();
136
+ });
137
+ }
138
+ await new Promise((resolveListen, reject) => {
139
+ server.once("error", reject);
140
+ server.listen(options.port ?? 0, options.host ?? "127.0.0.1", () => resolveListen());
141
+ });
142
+ const { port } = server.address();
143
+ return {
144
+ url: `http://${options.host ?? "127.0.0.1"}:${port}`,
145
+ source: initial?.source,
146
+ close: async () => {
147
+ clearInterval(heartbeat);
148
+ watcher?.close();
149
+ for (const c of clients)
150
+ c.end();
151
+ await new Promise((r) => server.close(() => r()));
152
+ },
153
+ };
154
+ }
155
+ async function serveStatic(root, pathname, res) {
156
+ const base = resolve(root);
157
+ let file = resolve(base, `.${decodeURIComponent(pathname)}`);
158
+ if (file !== base && !file.startsWith(base + sep)) {
159
+ res.writeHead(403);
160
+ return res.end();
161
+ }
162
+ const info = await stat(file).catch(() => undefined);
163
+ // Unknown paths fall back to the app shell.
164
+ if (!info?.isFile())
165
+ file = join(base, "index.html");
166
+ const body = await readFile(file);
167
+ res.writeHead(200, {
168
+ "content-type": TYPES[extname(file)] ?? "application/octet-stream",
169
+ "cache-control": file.includes(`${sep}assets${sep}`)
170
+ ? "public, max-age=31536000, immutable"
171
+ : "no-cache",
172
+ });
173
+ res.end(body);
174
+ }
175
+ function json(res, status, body) {
176
+ res.writeHead(status, { "content-type": "application/json", "cache-control": "no-store" });
177
+ res.end(JSON.stringify(body));
178
+ }
179
+ /**
180
+ * The built explorer: ARCHDOC_WEB_DIR, the workspace build (when running from a
181
+ * clone), or the copy that `prepack` puts next to the published CLI.
182
+ */
183
+ export function findWebDir() {
184
+ const candidates = [
185
+ process.env.ARCHDOC_WEB_DIR,
186
+ fileURLToPath(new URL("../../../apps/web/dist/", import.meta.url)),
187
+ fileURLToPath(new URL("../web/", import.meta.url)),
188
+ ];
189
+ return candidates.find((d) => !!d && existsSync(join(d, "index.html")));
190
+ }
191
+ /**
192
+ * What /api/model sends, and what `archdoc site` writes: the working tree's
193
+ * model, and with `base`, the model at the merge base with it and the findings
194
+ * the change introduced, so the Changes tab shows what the PR comment says.
195
+ */
196
+ export async function modelResponse(options) {
197
+ const snap = await snapshot(options.target, { cwd: options.cwd });
198
+ if (!snap)
199
+ return undefined;
200
+ const repo = { ...(await repoInfo(snap.baseDir)), root: snap.baseDir };
201
+ const body = { ...(await payloadOf(snap, repo, options.cwd)), seals: await sealsOf(options) };
202
+ if (!options.base)
203
+ return body;
204
+ if (isModelPath(options.cwd, options.base)) {
205
+ // Another model file: only its files, compared with this one's.
206
+ return { ...body, base: await sourcesOfFile(options.base, options.cwd) };
207
+ }
208
+ const compared = await comparison(options.target, options.cwd, options.base, undefined);
209
+ return compared ? { ...body, base: compared.base, change: compared.change } : body;
210
+ }
211
+ /**
212
+ * The working tree's seals, for the explorer: the facts whose code changed
213
+ * since they were sealed, and the ones no one has sealed. Undefined when the
214
+ * repository doesn't keep an archdoc.sum.
215
+ */
216
+ async function sealsOf(options) {
217
+ const r = await sealReport(options.target, options.cwd).catch(() => undefined);
218
+ if (!r || (!r.recorded && !r.error))
219
+ return undefined;
220
+ return {
221
+ file: r.file,
222
+ error: r.error,
223
+ total: r.statuses.length,
224
+ facts: r.statuses
225
+ .filter((s) => s.state !== "sealed")
226
+ .map((s) => ({
227
+ key: s.fact.key,
228
+ label: s.fact.label,
229
+ state: s.state,
230
+ element: s.fact.element,
231
+ refs: s.fact.refs,
232
+ changes: s.changes,
233
+ location: s.fact.location,
234
+ })),
235
+ };
236
+ }
237
+ /** The merge base of `base` and `head` (or the working tree), as a payload, and the findings the head introduced. */
238
+ async function comparison(target, cwd, base, head) {
239
+ const checked = await checkRepository({ model: target, cwd, base, head });
240
+ if (!checked.base)
241
+ return undefined;
242
+ const merged = await snapshot(target, { cwd, ref: checked.base.commit });
243
+ if (!merged)
244
+ return undefined;
245
+ // Named after the branch it's the merge base with, as the comparison is.
246
+ const relabel = (p) => p.startsWith(`${checked.base?.commit}:`) ? `${base}:${p.slice(p.indexOf(":") + 1)}` : p;
247
+ const at = {
248
+ ...merged,
249
+ root: relabel(merged.root),
250
+ sources: merged.sources.map((x) => ({ ...x, path: relabel(x.path) })),
251
+ };
252
+ const linksAt = async (s) => ({
253
+ webUrl: (await repoInfo(s.baseDir)).webUrl,
254
+ commit: s.commit,
255
+ });
256
+ const headSnap = head ? await snapshot(target, { cwd, ref: head }) : undefined;
257
+ return {
258
+ base: { ref: base, ...(await payloadOf(at, await linksAt(at), cwd)) },
259
+ head: headSnap && { ref: head, ...(await payloadOf(headSnap, await linksAt(headSnap), cwd)) },
260
+ change: {
261
+ base,
262
+ head,
263
+ commit: checked.base.commit,
264
+ findings: checked.findings,
265
+ changedFiles: checked.base.changedFiles,
266
+ },
267
+ };
268
+ }
269
+ /** What the explorer needs to build and show one version of the model. */
270
+ async function payloadOf(snap, repo, cwd) {
271
+ const model = snap.sources.length
272
+ ? buildModel(snap.sources, { root: snap.root })
273
+ : buildModel([]);
274
+ const inRepo = new Set(snap.files);
275
+ const readRel = (path) => inRepo.has(path) ? snap.read(path) : Promise.resolve(undefined);
276
+ // Snippets are found synchronously, so read the files they're in first.
277
+ const snippetFiles = new Map();
278
+ for (const e of model.elements.values()) {
279
+ for (const ref of e.code) {
280
+ if (isSnippet(ref) && !snippetFiles.has(ref.path)) {
281
+ snippetFiles.set(ref.path, await readRel(ref.path));
282
+ }
283
+ }
284
+ }
285
+ const federation = await readFederationInput(snap.fedDir, cwd, (file) => {
286
+ const rel = relative(snap.baseDir, file).replace(/\\/g, "/");
287
+ return rel.startsWith("..") ? Promise.resolve(undefined) : snap.read(rel);
288
+ });
289
+ return {
290
+ ...(snap.commit ? { commit: snap.commit } : {}),
291
+ root: snap.root,
292
+ sources: snap.sources,
293
+ files: snap.files,
294
+ // Where each code snippet is, so the explorer links a symbol to its lines.
295
+ snippets: resolveSnippets(model, (path) => snippetFiles.get(path)),
296
+ // Other repos' models, so the explorer checks and simulates across repos like the CLI.
297
+ federation: {
298
+ lockPath: federation.lockPath,
299
+ lock: federation.lock,
300
+ lockError: federation.lockError,
301
+ bundles: [...federation.bundles].map(([key, b]) => ({ key, ...b })),
302
+ },
303
+ samples: await readSamples(snap.files, readRel),
304
+ // Bug traces beside the model, for the explorer's trace view. Never part of the model.
305
+ traces: await readTraces(snap),
306
+ // What data entries' schema sources say (types, values, foreign keys), as check reads them.
307
+ schemas: (await importSchemas(contextOf(snap), model)).filter((s) => !s.error),
308
+ repo,
309
+ };
310
+ }
311
+ /** The trace files in the model directory's traces/, as the snapshot has them. */
312
+ async function readTraces(snap) {
313
+ const dir = relative(snap.baseDir, join(snap.source, "traces")).replace(/\\/g, "/");
314
+ if (dir.startsWith(".."))
315
+ return [];
316
+ const out = [];
317
+ for (const path of snap.files.filter((f) => f.startsWith(`${dir}/`) && /\.ya?ml$/.test(f))) {
318
+ const text = await snap.read(path);
319
+ if (text !== undefined)
320
+ out.push({ path, text });
321
+ }
322
+ return out;
323
+ }
324
+ /** Another model on disk, as the base to compare with, in place of a git ref. */
325
+ async function sourcesOfFile(path, cwd) {
326
+ const read = await readModelSources(path, { cwd });
327
+ if (!read)
328
+ throw new Error(`No ArchDoc model at ${path}.`);
329
+ return { ref: path, commit: "", root: read.root, sources: read.sources };
330
+ }
331
+ /**
332
+ * Sample records for simulating journeys: JSON files in any samples/
333
+ * directory, and <journey>.sample.json files anywhere, such as next to a
334
+ * single-file model.
335
+ */
336
+ async function readSamples(files, read) {
337
+ const paths = files
338
+ .filter((f) => /(^|\/)samples\/[^/]+\.json$/.test(f) || /\.sample\.json$/.test(f))
339
+ .slice(0, 50);
340
+ const out = [];
341
+ for (const path of paths) {
342
+ const text = await read(path);
343
+ if (text !== undefined && text.length <= 256 * 1024)
344
+ out.push({ path, text });
345
+ }
346
+ return out;
347
+ }
348
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,KAAK,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAuB,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WA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