@plebeiantech/lat.md 0.12.3-fork.14 → 0.12.3-fork.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cli/checklist-menu.d.ts +2 -1
- package/dist/src/cli/checklist-menu.js +3 -2
- package/dist/src/cli/index.js +47 -10
- package/dist/src/cli/init-preferences.d.ts +4 -0
- package/dist/src/cli/init-preferences.js +35 -0
- package/dist/src/cli/init.js +7 -1
- package/dist/src/cli/search.js +2 -7
- package/dist/src/cli/ui-build-server.d.ts +12 -0
- package/dist/src/cli/ui-build-server.js +26 -0
- package/dist/src/cli/ui-build.js +1 -1
- package/dist/src/cli/ui.js +1 -1
- package/dist/src/search/query.d.ts +5 -2
- package/dist/src/search/query.js +25 -21
- package/dist/src/source-formats.d.ts +1 -1
- package/dist/src/source-formats.js +2 -0
- package/dist/src/source-parser.js +200 -0
- package/dist/src/view/client/assets/GraphView-BuZg_wrj.js +456 -0
- package/dist/src/view/client/assets/{MarkdownEditor-B7quqPb8.js → MarkdownEditor-BKqJtZYv.js} +8 -8
- package/dist/src/view/client/assets/_commonjsHelpers-CqkleIqs.js +1 -0
- package/dist/src/view/client/assets/abnfDiagram-VCTEODGH-CAu3KwfO.js +1 -0
- package/dist/src/view/client/assets/{arc-BnwR8Bu7.js → arc-CFnPZhKM.js} +1 -1
- package/dist/src/view/client/assets/architectureDiagram-5GKGNRK7-Cf9Kd0OA.js +36 -0
- package/dist/src/view/client/assets/{blockDiagram-I7D4REHJ-DETl8e_H.js → blockDiagram-I7D4REHJ-dPn7g_vm.js} +2 -2
- package/dist/src/view/client/assets/{c4Diagram-7LVT6UL2-DJRAT1Ve.js → c4Diagram-7LVT6UL2-DdZrwaPd.js} +2 -2
- package/dist/src/view/client/assets/channel-C-byJRR7.js +1 -0
- package/dist/src/view/client/assets/{chunk-2Q5K7J3B-C0TmOC1Q.js → chunk-2Q5K7J3B-C42JuteH.js} +1 -1
- package/dist/src/view/client/assets/{chunk-5VM5RSS4-dfBOrYE6.js → chunk-5VM5RSS4-BKK3z8Zy.js} +1 -1
- package/dist/src/view/client/assets/{chunk-F27PBJKO-DAnks99K.js → chunk-F27PBJKO-qZl_uKcW.js} +1 -1
- package/dist/src/view/client/assets/{chunk-IMKFNOWR-CPjB07if.js → chunk-IMKFNOWR-Bs4Rnoj_.js} +1 -1
- package/dist/src/view/client/assets/{chunk-JWPE2WC7-VvU_gZI6.js → chunk-JWPE2WC7-BpxgV2rA.js} +1 -1
- package/dist/src/view/client/assets/{chunk-POPQ4Y6H-DDUbVF55.js → chunk-POPQ4Y6H-hIynofdE.js} +1 -1
- package/dist/src/view/client/assets/{chunk-SVP7TREG-BHROkr6D.js → chunk-SVP7TREG-t3gKMqeu.js} +1 -1
- package/dist/src/view/client/assets/{chunk-TICWLB2K-95PzGIOg.js → chunk-TICWLB2K-B2x394mh.js} +1 -1
- package/dist/src/view/client/assets/{chunk-XXDRQBXY-MdmuLhIs.js → chunk-XXDRQBXY-CHaVKDsH.js} +1 -1
- package/dist/src/view/client/assets/classDiagram-ZZMXUADV-FlqGrEwv.js +1 -0
- package/dist/src/view/client/assets/classDiagram-v2-VYDZK3BY-FlqGrEwv.js +1 -0
- package/dist/src/view/client/assets/cose-bilkent-JH36ORCC-DE2-Jgqu.js +1 -0
- package/dist/src/view/client/assets/{cynefin-OW5HDTMX-CeA8IKWo.js → cynefin-OW5HDTMX-BsEtOvRy.js} +1 -1
- package/dist/src/view/client/assets/cynefinDiagram-5FMLGOSQ-BKYG1Xs8.js +62 -0
- package/dist/src/view/client/assets/{dagre-GXQ25YYZ-DLQwTa3H.js → dagre-GXQ25YYZ-hgrdNjl7.js} +2 -2
- package/dist/src/view/client/assets/{diagram-S7CK7UJ4-kbKdIyXG.js → diagram-S7CK7UJ4-VIx8zAxf.js} +2 -2
- package/dist/src/view/client/assets/diagram-UQ7AKVKN-yfloehRm.js +41 -0
- package/dist/src/view/client/assets/{diagram-VSXAHHWV-EXJTU8qq.js → diagram-VSXAHHWV-BT_dA4Q9.js} +2 -2
- package/dist/src/view/client/assets/diagram-VX7I27RA-Gfmwxx6u.js +24 -0
- package/dist/src/view/client/assets/diagram-Z3DM3KII-C2yM7EOo.js +24 -0
- package/dist/src/view/client/assets/ebnfDiagram-PWID7BFC-Bkb_Lj59.js +1 -0
- package/dist/src/view/client/assets/{erDiagram-RLTQ6QDP-C925J5A3.js → erDiagram-RLTQ6QDP-C7wQHPye.js} +2 -2
- package/dist/src/view/client/assets/{flowDiagram-HODETNUW-DzoCa-Nq.js → flowDiagram-HODETNUW-CXoKr3oI.js} +1 -1
- package/dist/src/view/client/assets/ganttDiagram-EL5Y4UJY-DqqXKgLa.js +292 -0
- package/dist/src/view/client/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/src/view/client/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/src/view/client/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/src/view/client/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/dist/src/view/client/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/dist/src/view/client/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/src/view/client/assets/gitGraphDiagram-WWUBYQGX-D_DAhSgZ.js +106 -0
- package/dist/src/view/client/assets/index-DAxFk0q-.css +1 -0
- package/dist/src/view/client/assets/index-DPuOWFj2.js +10 -0
- package/dist/src/view/client/assets/infoDiagram-27XIBGKW-B50EOats.js +2 -0
- package/dist/src/view/client/assets/{ishikawaDiagram-5VMMS53U-CW4mto2d.js → ishikawaDiagram-5VMMS53U-D1rny9gj.js} +2 -2
- package/dist/src/view/client/assets/{journeyDiagram-3NMN7TZE-8R4eacFW.js → journeyDiagram-3NMN7TZE-B5UD2Xo4.js} +2 -2
- package/dist/src/view/client/assets/{kanban-definition-UXKFOSKX-Cy9ioXEJ.js → kanban-definition-UXKFOSKX-CTgey9zw.js} +6 -6
- package/dist/src/view/client/assets/{layout-C0MFuhth.js → layout-4X2n4os-.js} +1 -1
- package/dist/src/view/client/assets/{linear-Dv3N4dQR.js → linear-D0RIBXsp.js} +1 -1
- package/dist/src/view/client/assets/{maplibre-gl-DnqZgfUS.js → maplibre-gl-CDX6Zuow.js} +1 -1
- package/dist/src/view/client/assets/{mermaid.core-bds9A7e2.js → mermaid.core-BAnH8y-D.js} +11 -11
- package/dist/src/view/client/assets/{mindmap-definition-YA3MSWOX-DjmGW355.js → mindmap-definition-YA3MSWOX-WiFsh3Jg.js} +2 -2
- package/dist/src/view/client/assets/pegDiagram-XKGWAZYB-DCJOrckP.js +1 -0
- package/dist/src/view/client/assets/{pieDiagram-E7YTZNPT-CCH2gGR-.js → pieDiagram-E7YTZNPT-C78IkUE2.js} +2 -2
- package/dist/src/view/client/assets/{quadrantDiagram-AXDQQJYC-CjocPJFz.js → quadrantDiagram-AXDQQJYC-xZ6guleB.js} +4 -4
- package/dist/src/view/client/assets/railroadDiagram-O6MQD6OU-D3PwmgX0.js +1 -0
- package/dist/src/view/client/assets/{requirementDiagram-BXWQKSXE-Ct6AoXRr.js → requirementDiagram-BXWQKSXE-v-I8wLGH.js} +2 -2
- package/dist/src/view/client/assets/{sankeyDiagram-P5KCCOFB-CIpgGN_w.js → sankeyDiagram-P5KCCOFB-DBY-sdO7.js} +2 -2
- package/dist/src/view/client/assets/{sequenceDiagram-WJ2MYXX4-DrmLFj6w.js → sequenceDiagram-WJ2MYXX4-D9HApBFi.js} +2 -2
- package/dist/src/view/client/assets/sizeCapture-INFHLROL-ERAytLnQ.js +1 -0
- package/dist/src/view/client/assets/stateDiagram-D77RDMKH-BKef_Qwv.js +1 -0
- package/dist/src/view/client/assets/stateDiagram-v2-MP3YSRHH-BePfayWI.js +1 -0
- package/dist/src/view/client/assets/swimlanes-42K2YHIH-D7dS_tnF.js +1 -0
- package/dist/src/view/client/assets/swimlanesDiagram-VR7AAH4N-DaqCEguT.js +8 -0
- package/dist/src/view/client/assets/{timeline-definition-24CTP7MA-BExPu6X5.js → timeline-definition-24CTP7MA-Di1UCseG.js} +2 -2
- package/dist/src/view/client/assets/{vennDiagram-4TSXK5OY-PC1MU3si.js → vennDiagram-4TSXK5OY-g7Je3H2H.js} +2 -2
- package/dist/src/view/client/assets/{wardleyDiagram-VM6X3IG4-DNWqU3fa.js → wardleyDiagram-VM6X3IG4-C_diPEka.js} +2 -2
- package/dist/src/view/client/assets/{xychartDiagram-S5SC5T6Z-E1uA28_D.js → xychartDiagram-S5SC5T6Z-C8uIQy_I.js} +2 -2
- package/dist/src/view/client/index.html +2 -2
- package/dist/src/view/document-route.d.ts +2 -0
- package/dist/src/view/document-route.js +40 -7
- package/dist/src/view/graph.d.ts +2 -2
- package/dist/src/view/graph.js +7 -3
- package/dist/src/view/highlight.js +205 -203
- package/dist/src/view/markdown.js +4 -0
- package/dist/src/view/preindexed-search.d.ts +15 -0
- package/dist/src/view/preindexed-search.js +25 -0
- package/dist/src/view/protocol.d.ts +3 -0
- package/dist/src/view/references.js +3 -4
- package/dist/src/view/search-result.d.ts +4 -0
- package/dist/src/view/search-result.js +20 -0
- package/dist/src/view/search.d.ts +7 -2
- package/dist/src/view/search.js +23 -30
- package/dist/src/view/server-build.d.ts +21 -0
- package/dist/src/view/server-build.js +145 -0
- package/dist/src/view/server-deployment.d.ts +32 -0
- package/dist/src/view/server-deployment.js +133 -0
- package/dist/src/view/server-index-worker.d.ts +6 -0
- package/dist/src/view/server-index-worker.js +14 -0
- package/dist/src/view/server.d.ts +1 -1
- package/dist/src/view/server.js +26 -8
- package/dist/src/view/static-build.d.ts +16 -1
- package/dist/src/view/static-build.js +187 -89
- package/dist/src/view/static-protocol.d.ts +7 -0
- package/dist/src/view/static-protocol.js +5 -0
- package/dist/src/view/store.js +14 -4
- package/dist/src/view/vercel-build.d.ts +24 -0
- package/dist/src/view/vercel-build.js +133 -0
- package/dist/src/view/vercel-server-build.d.ts +10 -0
- package/dist/src/view/vercel-server-build.js +61 -0
- package/dist/vendor/lat.md-server/cli.d.ts +2 -0
- package/dist/vendor/lat.md-server/cli.js +12 -0
- package/dist/vendor/lat.md-server/index.d.ts +38 -0
- package/dist/vendor/lat.md-server/index.js +128 -0
- package/package.json +19 -5
- package/dist/src/view/client/assets/abnfDiagram-VCTEODGH-V7-T6qsl.js +0 -1
- package/dist/src/view/client/assets/architectureDiagram-5GKGNRK7-u97vDna9.js +0 -36
- package/dist/src/view/client/assets/channel-BwQbnWCN.js +0 -1
- package/dist/src/view/client/assets/classDiagram-ZZMXUADV-HvQKkIS-.js +0 -1
- package/dist/src/view/client/assets/classDiagram-v2-VYDZK3BY-HvQKkIS-.js +0 -1
- package/dist/src/view/client/assets/cose-bilkent-JH36ORCC-CauUf_rN.js +0 -1
- package/dist/src/view/client/assets/cynefinDiagram-5FMLGOSQ-L1rtcT8l.js +0 -62
- package/dist/src/view/client/assets/diagram-UQ7AKVKN-kmzp92RC.js +0 -41
- package/dist/src/view/client/assets/diagram-VX7I27RA-DAiIyMCG.js +0 -24
- package/dist/src/view/client/assets/diagram-Z3DM3KII-G9wz50ZV.js +0 -24
- package/dist/src/view/client/assets/ebnfDiagram-PWID7BFC-D2tVRCNA.js +0 -1
- package/dist/src/view/client/assets/ganttDiagram-EL5Y4UJY-D2ebbg4p.js +0 -292
- package/dist/src/view/client/assets/gitGraphDiagram-WWUBYQGX-B4QratYy.js +0 -106
- package/dist/src/view/client/assets/index-D0ajr_Ja.css +0 -1
- package/dist/src/view/client/assets/index-KZcnpXJH.js +0 -321
- package/dist/src/view/client/assets/infoDiagram-27XIBGKW-DL4mtHkt.js +0 -2
- package/dist/src/view/client/assets/pegDiagram-XKGWAZYB-BWsZp0ab.js +0 -1
- package/dist/src/view/client/assets/railroadDiagram-O6MQD6OU-BjLeb2KF.js +0 -1
- package/dist/src/view/client/assets/sizeCapture-INFHLROL-BdFMe2Lr.js +0 -1
- package/dist/src/view/client/assets/stateDiagram-D77RDMKH-Zd9F1goW.js +0 -1
- package/dist/src/view/client/assets/stateDiagram-v2-MP3YSRHH-ByIKCftl.js +0 -1
- package/dist/src/view/client/assets/swimlanes-42K2YHIH-a7VFwi00.js +0 -1
- package/dist/src/view/client/assets/swimlanesDiagram-VR7AAH4N-CzxaUHB-.js +0 -8
- /package/dist/src/view/client/assets/{logo-small-RR_KBOAT.svg → logo-RR_KBOAT.svg} +0 -0
package/dist/src/view/store.js
CHANGED
|
@@ -99,8 +99,8 @@ async function scanCodeState(projectRoot, excludedPaths = []) {
|
|
|
99
99
|
scope,
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function viewIndex(latDir,
|
|
103
|
-
const files = [...
|
|
102
|
+
function viewIndex(latDir, markdownFiles, diagnostics, git, references, external) {
|
|
103
|
+
const files = [...markdownFiles.keys()].sort();
|
|
104
104
|
const externalFiles = new Map();
|
|
105
105
|
for (const target of references.externalByTarget.keys()) {
|
|
106
106
|
try {
|
|
@@ -123,8 +123,18 @@ function viewIndex(latDir, paths, diagnostics, git, references, external) {
|
|
|
123
123
|
const indexName = directoryName.endsWith('.md')
|
|
124
124
|
? directoryName
|
|
125
125
|
: `${directoryName}.md`;
|
|
126
|
+
const directoryOrder = Object.fromEntries([...markdownFiles].flatMap(([path, file]) => {
|
|
127
|
+
const separator = path.lastIndexOf('/');
|
|
128
|
+
const directory = separator === -1 ? '' : path.slice(0, separator);
|
|
129
|
+
const name = directory ? basename(directory) : directoryName;
|
|
130
|
+
const filename = name.endsWith('.md') ? name : `${name}.md`;
|
|
131
|
+
if (path.slice(separator + 1) !== filename)
|
|
132
|
+
return [];
|
|
133
|
+
return [[directory, file.indexEntries]];
|
|
134
|
+
}));
|
|
126
135
|
return {
|
|
127
136
|
files,
|
|
137
|
+
directoryOrder,
|
|
128
138
|
externalFiles: [...externalFiles.values()].sort((left, right) => left.handle.localeCompare(right.handle) ||
|
|
129
139
|
left.path.localeCompare(right.path)),
|
|
130
140
|
entry: files.includes(indexName) ? indexName : (files[0] ?? ''),
|
|
@@ -162,10 +172,10 @@ async function buildSnapshot(latDir, projectRoot, markdownFiles, codeFiles, git,
|
|
|
162
172
|
files,
|
|
163
173
|
allSections,
|
|
164
174
|
references,
|
|
165
|
-
graph: buildViewGraph(files.values(), codeFiles.values(), allSections, diagnostics, git, generation, external),
|
|
175
|
+
graph: buildViewGraph(files.values(), codeFiles.values(), allSections, diagnostics, git, generation, references, external),
|
|
166
176
|
diagnostics,
|
|
167
177
|
git,
|
|
168
|
-
index: viewIndex(latDir,
|
|
178
|
+
index: viewIndex(latDir, files, diagnostics, git, references, external),
|
|
169
179
|
external,
|
|
170
180
|
};
|
|
171
181
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type FileTraceResult = {
|
|
2
|
+
fileList: Set<string>;
|
|
3
|
+
warnings: Set<Error>;
|
|
4
|
+
};
|
|
5
|
+
export type VercelBuildDependencies = {
|
|
6
|
+
traceFiles: (files: string[], options: {
|
|
7
|
+
base: string;
|
|
8
|
+
conditions: string[];
|
|
9
|
+
exportsOnly: boolean;
|
|
10
|
+
processCwd: string;
|
|
11
|
+
}) => Promise<FileTraceResult>;
|
|
12
|
+
};
|
|
13
|
+
export type VercelBuildOptions = {
|
|
14
|
+
force?: boolean;
|
|
15
|
+
warn?: (message: string) => void;
|
|
16
|
+
};
|
|
17
|
+
export type VercelBuildResult = {
|
|
18
|
+
files: number;
|
|
19
|
+
functionPath: string;
|
|
20
|
+
outputDir: string;
|
|
21
|
+
};
|
|
22
|
+
/** Convert an installed portable Lat UI server into Vercel Build Output API v3. */
|
|
23
|
+
export declare function buildVercelOutput(requestedArtifact: string, requestedOutput?: string, options?: VercelBuildOptions, dependencies?: VercelBuildDependencies): Promise<VercelBuildResult>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { cp, lstat, mkdir, mkdtemp, readFile, rename, rm, writeFile, } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
3
|
+
import { nodeFileTrace } from '@vercel/nft';
|
|
4
|
+
import { LAT_UI_CONTENT_SECURITY_POLICY } from '../../vendor/lat.md-server/index.js';
|
|
5
|
+
const defaultDependencies = {
|
|
6
|
+
traceFiles: nodeFileTrace,
|
|
7
|
+
};
|
|
8
|
+
function json(value) {
|
|
9
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
10
|
+
}
|
|
11
|
+
function basePathSegments(basePath) {
|
|
12
|
+
const parsed = new URL(basePath, 'http://lat.local');
|
|
13
|
+
if (parsed.origin !== 'http://lat.local' ||
|
|
14
|
+
parsed.search ||
|
|
15
|
+
parsed.hash ||
|
|
16
|
+
!basePath.startsWith('/')) {
|
|
17
|
+
throw new Error(`Invalid Lat UI server base path: ${basePath}`);
|
|
18
|
+
}
|
|
19
|
+
return parsed.pathname
|
|
20
|
+
.split('/')
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.map((part) => {
|
|
23
|
+
const decoded = decodeURIComponent(part);
|
|
24
|
+
if (decoded === '.' ||
|
|
25
|
+
decoded === '..' ||
|
|
26
|
+
decoded.includes('/') ||
|
|
27
|
+
decoded.includes('\\')) {
|
|
28
|
+
throw new Error(`Invalid Lat UI server base path: ${basePath}`);
|
|
29
|
+
}
|
|
30
|
+
return decoded;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function safeTracePath(path) {
|
|
34
|
+
if (isAbsolute(path) ||
|
|
35
|
+
path === '..' ||
|
|
36
|
+
path.startsWith(`..${sep}`) ||
|
|
37
|
+
path.split(/[\\/]/).includes('..')) {
|
|
38
|
+
throw new Error(`Node file trace escaped the server artifact: ${path}`);
|
|
39
|
+
}
|
|
40
|
+
return path;
|
|
41
|
+
}
|
|
42
|
+
function outputConfig() {
|
|
43
|
+
const securityHeaders = {
|
|
44
|
+
'Content-Security-Policy': LAT_UI_CONTENT_SECURITY_POLICY,
|
|
45
|
+
'Referrer-Policy': 'no-referrer',
|
|
46
|
+
'X-Content-Type-Options': 'nosniff',
|
|
47
|
+
};
|
|
48
|
+
const immutableHeaders = {
|
|
49
|
+
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
version: 3,
|
|
53
|
+
routes: [
|
|
54
|
+
{ src: '/(.*)', headers: securityHeaders, continue: true },
|
|
55
|
+
{
|
|
56
|
+
src: '/(?:.*?/)?assets/.*',
|
|
57
|
+
headers: immutableHeaders,
|
|
58
|
+
continue: true,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
src: '/(?:.*?/)?data/[^/]+/[a-f0-9]{20}\\.json',
|
|
62
|
+
headers: immutableHeaders,
|
|
63
|
+
continue: true,
|
|
64
|
+
},
|
|
65
|
+
{ handle: 'filesystem' },
|
|
66
|
+
{ src: '/', dest: '/index.html' },
|
|
67
|
+
{ src: '/(.*)/', dest: '/$1/index.html' },
|
|
68
|
+
{ src: '/(.*)', dest: '/$1/index.html' },
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Convert an installed portable Lat UI server into Vercel Build Output API v3. */
|
|
73
|
+
export async function buildVercelOutput(requestedArtifact, requestedOutput = '.vercel/output', options = {}, dependencies = defaultDependencies) {
|
|
74
|
+
const artifactDir = resolve(requestedArtifact);
|
|
75
|
+
const outputDir = resolve(requestedOutput);
|
|
76
|
+
if (!options.force) {
|
|
77
|
+
try {
|
|
78
|
+
await lstat(outputDir);
|
|
79
|
+
throw new Error(`Vercel build output already exists: ${outputDir}. Use force to replace it.`);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code !== 'ENOENT')
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const manifestFile = join(artifactDir, 'server-data', 'server.json');
|
|
87
|
+
const manifest = JSON.parse(await readFile(manifestFile, 'utf8'));
|
|
88
|
+
if (typeof manifest.basePath !== 'string') {
|
|
89
|
+
throw new Error(`Invalid Lat UI server manifest: ${manifestFile}`);
|
|
90
|
+
}
|
|
91
|
+
const entrypoint = join(artifactDir, 'app.mjs');
|
|
92
|
+
const trace = await dependencies.traceFiles([entrypoint], {
|
|
93
|
+
base: artifactDir,
|
|
94
|
+
conditions: ['node', 'production'],
|
|
95
|
+
exportsOnly: true,
|
|
96
|
+
processCwd: artifactDir,
|
|
97
|
+
});
|
|
98
|
+
for (const warning of trace.warnings) {
|
|
99
|
+
options.warn?.(`Node file trace: ${warning.message}`);
|
|
100
|
+
}
|
|
101
|
+
await mkdir(dirname(outputDir), { recursive: true });
|
|
102
|
+
const stagingDir = await mkdtemp(join(dirname(outputDir), '.lat-vercel-staging-'));
|
|
103
|
+
try {
|
|
104
|
+
const staticDir = join(stagingDir, 'static');
|
|
105
|
+
const functionPath = join('functions', ...basePathSegments(manifest.basePath), 'api', 'search.func');
|
|
106
|
+
const functionDir = join(stagingDir, functionPath);
|
|
107
|
+
await cp(join(artifactDir, 'public'), staticDir, { recursive: true });
|
|
108
|
+
for (const traced of trace.fileList) {
|
|
109
|
+
const path = safeTracePath(traced);
|
|
110
|
+
const destination = join(functionDir, path);
|
|
111
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
112
|
+
await cp(join(artifactDir, path), destination, {
|
|
113
|
+
dereference: true,
|
|
114
|
+
recursive: true,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
await writeFile(join(functionDir, '.vc-config.json'), json({
|
|
118
|
+
runtime: 'nodejs22.x',
|
|
119
|
+
handler: 'app.mjs',
|
|
120
|
+
launcherType: 'Nodejs',
|
|
121
|
+
shouldAddHelpers: true,
|
|
122
|
+
}));
|
|
123
|
+
await writeFile(join(stagingDir, 'config.json'), json(outputConfig()));
|
|
124
|
+
if (options.force)
|
|
125
|
+
await rm(outputDir, { recursive: true, force: true });
|
|
126
|
+
await rename(stagingDir, outputDir);
|
|
127
|
+
return { files: trace.fileList.size, functionPath, outputDir };
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
await rm(stagingDir, { recursive: true, force: true });
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CmdContext } from '../context.js';
|
|
2
|
+
import { buildServerView, type ServerViewBuildOptions, type ServerViewBuildResult } from './server-build.js';
|
|
3
|
+
import { type VercelBuildOptions, type VercelBuildResult } from './vercel-build.js';
|
|
4
|
+
export type VercelServerBuildDependencies = {
|
|
5
|
+
buildNode: typeof buildServerView;
|
|
6
|
+
buildOutput: (artifact: string, output: string, options: VercelBuildOptions) => Promise<VercelBuildResult>;
|
|
7
|
+
installDependencies: (artifact: string) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
/** Build the portable server in staging, install it, then emit Vercel v3 output. */
|
|
10
|
+
export declare function buildVercelServerView(ctx: CmdContext, requestedOutput: string, options?: ServerViewBuildOptions, dependencies?: VercelServerBuildDependencies): Promise<ServerViewBuildResult>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { buildServerView, } from './server-build.js';
|
|
5
|
+
import { validateViewBuildOutput } from './static-build.js';
|
|
6
|
+
import { buildVercelOutput, } from './vercel-build.js';
|
|
7
|
+
function installServerDependencies(artifact) {
|
|
8
|
+
const executable = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
9
|
+
const args = [
|
|
10
|
+
'install',
|
|
11
|
+
'--ignore-scripts',
|
|
12
|
+
'--no-package-lock',
|
|
13
|
+
'--omit=dev',
|
|
14
|
+
'--no-audit',
|
|
15
|
+
'--no-fund',
|
|
16
|
+
];
|
|
17
|
+
return new Promise((resolveInstall, reject) => {
|
|
18
|
+
const child = spawn(executable, args, { cwd: artifact, stdio: 'inherit' });
|
|
19
|
+
child.once('error', reject);
|
|
20
|
+
child.once('exit', (code, signal) => {
|
|
21
|
+
if (code === 0) {
|
|
22
|
+
resolveInstall();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
reject(new Error(`npm install failed${signal ? ` with signal ${signal}` : ` with exit code ${code}`}`));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const defaultDependencies = {
|
|
30
|
+
buildNode: buildServerView,
|
|
31
|
+
buildOutput: buildVercelOutput,
|
|
32
|
+
installDependencies: installServerDependencies,
|
|
33
|
+
};
|
|
34
|
+
/** Build the portable server in staging, install it, then emit Vercel v3 output. */
|
|
35
|
+
export async function buildVercelServerView(ctx, requestedOutput, options = {}, dependencies = defaultDependencies) {
|
|
36
|
+
const outputDir = resolve(ctx.projectRoot, requestedOutput);
|
|
37
|
+
await validateViewBuildOutput(outputDir, ctx.projectRoot, 'Vercel', options.force);
|
|
38
|
+
await mkdir(dirname(outputDir), { recursive: true });
|
|
39
|
+
const stagingDir = await mkdtemp(join(dirname(outputDir), '.lat-vercel-server-'));
|
|
40
|
+
const nodeArtifact = join(stagingDir, 'node');
|
|
41
|
+
try {
|
|
42
|
+
const result = await dependencies.buildNode(ctx, nodeArtifact, {
|
|
43
|
+
...options,
|
|
44
|
+
force: false,
|
|
45
|
+
});
|
|
46
|
+
await dependencies.installDependencies(nodeArtifact);
|
|
47
|
+
await dependencies.buildOutput(nodeArtifact, outputDir, {
|
|
48
|
+
force: options.force,
|
|
49
|
+
warn: (message) => console.warn(message),
|
|
50
|
+
});
|
|
51
|
+
return { ...result, outputDir };
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await rm(stagingDir, {
|
|
55
|
+
recursive: true,
|
|
56
|
+
force: true,
|
|
57
|
+
maxRetries: 10,
|
|
58
|
+
retryDelay: 150,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { runLatServer } from './index.js';
|
|
5
|
+
const entry = process.argv[2];
|
|
6
|
+
if (!entry)
|
|
7
|
+
throw new Error('Usage: lat-ui-server <app-module>');
|
|
8
|
+
const module = (await import(pathToFileURL(resolve(entry)).href));
|
|
9
|
+
if (typeof module.default !== 'function') {
|
|
10
|
+
throw new Error(`${entry} must default-export an Express app`);
|
|
11
|
+
}
|
|
12
|
+
await runLatServer(module.default, { close: module.close });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type IncomingMessage, type RequestListener, type Server, type ServerResponse } from 'node:http';
|
|
2
|
+
import { type Express } from 'express';
|
|
3
|
+
export declare const LAT_UI_CONTENT_SECURITY_POLICY = "default-src 'self'; connect-src 'self' https://tiles.openfreemap.org; font-src 'self' data:; img-src 'self' data: https://github.com https://github.githubassets.com https://img.shields.io; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'";
|
|
4
|
+
export type LatServerAppOptions = {
|
|
5
|
+
/** Handle dynamic routes before immutable files and fallback handlers. */
|
|
6
|
+
handle?: LatServerRequestHandler;
|
|
7
|
+
/** Serve a completed Lat UI export after dynamic routes. */
|
|
8
|
+
publicDir?: string;
|
|
9
|
+
};
|
|
10
|
+
export type LatServerApp = RequestListener;
|
|
11
|
+
export type LatServerRequestHandler = (req: IncomingMessage, res: ServerResponse, next: (error?: unknown) => void) => void | Promise<void>;
|
|
12
|
+
export type ListenLatServerOptions = {
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
/** Advance through occupied ports. Explicit user ports should leave this off. */
|
|
16
|
+
findAvailablePort?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type RunningLatServer = {
|
|
19
|
+
server: Server;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
url: string;
|
|
23
|
+
close: () => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
/** Create the common Express stack used by live and exported Lat UI servers. */
|
|
26
|
+
export declare function createLatServerApp(options?: LatServerAppOptions, app?: Express): LatServerApp;
|
|
27
|
+
/** Listen with the same strict-or-next-port behavior in every Lat UI host. */
|
|
28
|
+
export declare function listenLatServer(app: LatServerApp, options: ListenLatServerOptions): Promise<RunningLatServer>;
|
|
29
|
+
export type RunLatServerOptions = {
|
|
30
|
+
host?: string;
|
|
31
|
+
port?: number;
|
|
32
|
+
close?: () => void | Promise<void>;
|
|
33
|
+
log?: (message: string) => void;
|
|
34
|
+
};
|
|
35
|
+
/** Run an exported Express app until the standalone process is terminated. */
|
|
36
|
+
export declare function runLatServer(app: LatServerApp, options?: RunLatServerOptions): Promise<RunningLatServer>;
|
|
37
|
+
/** Read this published package's exact version for generated artifacts. */
|
|
38
|
+
export declare function getLatServerVersion(): string;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createServer, } from 'node:http';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
export const LAT_UI_CONTENT_SECURITY_POLICY = "default-src 'self'; connect-src 'self' https://tiles.openfreemap.org; font-src 'self' data:; img-src 'self' data: https://github.com https://github.githubassets.com https://img.shields.io; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'";
|
|
5
|
+
function setSecurityHeaders(res) {
|
|
6
|
+
res.setHeader('Content-Security-Policy', LAT_UI_CONTENT_SECURITY_POLICY);
|
|
7
|
+
res.setHeader('Referrer-Policy', 'no-referrer');
|
|
8
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
9
|
+
}
|
|
10
|
+
function isImmutablePublicFile(path) {
|
|
11
|
+
const parts = path.split(/[/\\]/);
|
|
12
|
+
if (parts.includes('assets'))
|
|
13
|
+
return true;
|
|
14
|
+
return /[/\\]data[/\\][^/\\]+[/\\][a-f0-9]{20}\.json$/.test(path);
|
|
15
|
+
}
|
|
16
|
+
/** Create the common Express stack used by live and exported Lat UI servers. */
|
|
17
|
+
export function createLatServerApp(options = {}, app = express()) {
|
|
18
|
+
app.disable('x-powered-by');
|
|
19
|
+
app.use((_req, res, next) => {
|
|
20
|
+
setSecurityHeaders(res);
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
if (options.handle) {
|
|
24
|
+
app.use((req, res, next) => {
|
|
25
|
+
try {
|
|
26
|
+
void Promise.resolve(options.handle(req, res, next)).catch(next);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
next(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (options.publicDir) {
|
|
34
|
+
app.use(express.static(options.publicDir, {
|
|
35
|
+
setHeaders(res, path) {
|
|
36
|
+
res.setHeader('Cache-Control', isImmutablePublicFile(path)
|
|
37
|
+
? 'public, max-age=31536000, immutable'
|
|
38
|
+
: 'no-cache');
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
app.use((_req, res) => {
|
|
43
|
+
res.status(404).type('text/plain').send('Not found');
|
|
44
|
+
});
|
|
45
|
+
app.use((error, _req, res, _next) => {
|
|
46
|
+
console.error(error);
|
|
47
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
48
|
+
});
|
|
49
|
+
return app;
|
|
50
|
+
}
|
|
51
|
+
function listen(server, host, port) {
|
|
52
|
+
return new Promise((resolveListen, reject) => {
|
|
53
|
+
const onError = (error) => {
|
|
54
|
+
server.off('listening', onListening);
|
|
55
|
+
reject(error);
|
|
56
|
+
};
|
|
57
|
+
const onListening = () => {
|
|
58
|
+
server.off('error', onError);
|
|
59
|
+
resolveListen();
|
|
60
|
+
};
|
|
61
|
+
server.once('error', onError);
|
|
62
|
+
server.once('listening', onListening);
|
|
63
|
+
server.listen(port, host);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function closeServer(server) {
|
|
67
|
+
return new Promise((resolveClose, reject) => {
|
|
68
|
+
server.close((error) => (error ? reject(error) : resolveClose()));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Listen with the same strict-or-next-port behavior in every Lat UI host. */
|
|
72
|
+
export async function listenLatServer(app, options) {
|
|
73
|
+
const server = createServer(app);
|
|
74
|
+
let port = options.port;
|
|
75
|
+
while (true) {
|
|
76
|
+
try {
|
|
77
|
+
await listen(server, options.host, port);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (!options.findAvailablePort ||
|
|
82
|
+
error.code !== 'EADDRINUSE' ||
|
|
83
|
+
port === 65_535) {
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
port++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const address = server.address();
|
|
90
|
+
if (!address) {
|
|
91
|
+
await closeServer(server);
|
|
92
|
+
throw new Error('Could not determine Lat UI server address');
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
server,
|
|
96
|
+
host: options.host,
|
|
97
|
+
port: address.port,
|
|
98
|
+
url: `http://${options.host}:${address.port}/`,
|
|
99
|
+
close: () => closeServer(server),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Run an exported Express app until the standalone process is terminated. */
|
|
103
|
+
export async function runLatServer(app, options = {}) {
|
|
104
|
+
const host = options.host ?? process.env.HOST ?? '0.0.0.0';
|
|
105
|
+
const rawPort = options.port ?? Number(process.env.PORT ?? 3000);
|
|
106
|
+
if (!Number.isInteger(rawPort) || rawPort < 1 || rawPort > 65_535) {
|
|
107
|
+
throw new Error('PORT must be an integer from 1 to 65535');
|
|
108
|
+
}
|
|
109
|
+
const running = await listenLatServer(app, { host, port: rawPort });
|
|
110
|
+
(options.log ?? console.log)(`Lat UI listening on ${running.url}`);
|
|
111
|
+
let closing = false;
|
|
112
|
+
const shutdown = () => {
|
|
113
|
+
if (closing)
|
|
114
|
+
return;
|
|
115
|
+
closing = true;
|
|
116
|
+
void Promise.all([running.close(), options.close?.()]).catch((error) => {
|
|
117
|
+
console.error(error);
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
process.once('SIGINT', shutdown);
|
|
122
|
+
process.once('SIGTERM', shutdown);
|
|
123
|
+
return running;
|
|
124
|
+
}
|
|
125
|
+
/** Read this published package's exact version for generated artifacts. */
|
|
126
|
+
export function getLatServerVersion() {
|
|
127
|
+
return JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plebeiantech/lat.md",
|
|
3
|
-
"version": "0.12.3-fork.
|
|
3
|
+
"version": "0.12.3-fork.16",
|
|
4
4
|
"description": "A knowledge graph for your codebase, written in markdown",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,8 +22,15 @@
|
|
|
22
22
|
"bin": {
|
|
23
23
|
"lat": "./dist/src/cli/index.js"
|
|
24
24
|
},
|
|
25
|
+
"exports": {
|
|
26
|
+
"./server": {
|
|
27
|
+
"types": "./dist/src/view/server-deployment.d.ts",
|
|
28
|
+
"import": "./dist/src/view/server-deployment.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
25
31
|
"files": [
|
|
26
32
|
"dist/src",
|
|
33
|
+
"dist/vendor",
|
|
27
34
|
"templates",
|
|
28
35
|
"plugins"
|
|
29
36
|
],
|
|
@@ -34,6 +41,8 @@
|
|
|
34
41
|
"@codemirror/merge": "^6.12.2",
|
|
35
42
|
"@codemirror/state": "^6.7.1",
|
|
36
43
|
"@codemirror/view": "^6.43.9",
|
|
44
|
+
"@fontsource-variable/geist": "^5.3.0",
|
|
45
|
+
"@fontsource-variable/geist-mono": "^5.3.0",
|
|
37
46
|
"@lezer/highlight": "^1.2.3",
|
|
38
47
|
"@types/geojson": "^7946.0.16",
|
|
39
48
|
"@types/express": "^5.0.6",
|
|
@@ -64,7 +73,8 @@
|
|
|
64
73
|
"tsx": "^4.21.0",
|
|
65
74
|
"typescript": "^5.7.0",
|
|
66
75
|
"vite": "^7.0.0",
|
|
67
|
-
"vitest": "^3.0.0"
|
|
76
|
+
"vitest": "^3.0.0",
|
|
77
|
+
"@lat.md/server": "0.1.0"
|
|
68
78
|
},
|
|
69
79
|
"dependencies": {
|
|
70
80
|
"@asciidoctor/core": "4.0.6",
|
|
@@ -72,8 +82,10 @@
|
|
|
72
82
|
"@libsql/client": "^0.17.0",
|
|
73
83
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
74
84
|
"@repomix/tree-sitter-wasms": "^0.1.17",
|
|
85
|
+
"@vercel/nft": "^1.10.0",
|
|
75
86
|
"commander": "^14.0.3",
|
|
76
87
|
"diff": "^8.0.4",
|
|
88
|
+
"express": "^5.2.1",
|
|
77
89
|
"github-slugger": "^2.0.0",
|
|
78
90
|
"ignore-walk": "^8.0.0",
|
|
79
91
|
"mdast-util-gfm-autolink-literal": "^2.0.1",
|
|
@@ -104,17 +116,19 @@
|
|
|
104
116
|
"yaml": "^2.8.2",
|
|
105
117
|
"zod": "^4.3.6",
|
|
106
118
|
"@lat.md/embed": "0.2.0",
|
|
107
|
-
"@lat.md/server": "0.1.0",
|
|
108
119
|
"@lat.md/embed-minilm-fp16": "0.1.0"
|
|
109
120
|
},
|
|
110
121
|
"scripts": {
|
|
111
|
-
"build": "tsc && pnpm build:view",
|
|
122
|
+
"build": "tsc && tsx scripts/fork-vendor-ui-server.ts && pnpm build:view",
|
|
112
123
|
"build:view": "vite build --config view/vite.config.ts && vite build --config view/highlight.vite.config.ts",
|
|
124
|
+
"build:site": "pnpm --filter @lat.md/server build && node scripts/prepare-site-packages.mjs && pnpm build && node dist/src/cli/index.js ui build server --force",
|
|
125
|
+
"build:site:vercel": "pnpm build:site && node scripts/vendor-site-packages.mjs && npm install --prefix .lat-build/server --ignore-scripts --no-package-lock && node scripts/build-vercel-output.mjs",
|
|
126
|
+
"build:site:source": "pnpm buildall && node dist/src/cli/index.js ui build server --force",
|
|
113
127
|
"buildall": "pnpm build:packages && pnpm build",
|
|
114
128
|
"setup:rust": "pnpm --filter @lat.md/embed setup:rust",
|
|
115
129
|
"build:wasm": "pnpm --filter @lat.md/embed build:wasm",
|
|
116
130
|
"build:weights": "pnpm --filter @lat.md/embed-minilm-fp16 build:weights",
|
|
117
|
-
"build:packages": "pnpm --filter @lat.md/server build && pnpm --filter @lat.md/embed build && pnpm --filter @lat.md/embed-minilm-fp16 build",
|
|
131
|
+
"build:packages": "pnpm --filter @lat.md/server build && pnpm --filter @lat.md/stemmer build && pnpm --filter @lat.md/embed build && pnpm --filter @lat.md/embed-minilm-fp16 build",
|
|
118
132
|
"test": "vitest run",
|
|
119
133
|
"test:watch": "vitest",
|
|
120
134
|
"typecheck": "pnpm --filter @lat.md/server build && tsc --noEmit && tsc --noEmit -p view/tsconfig.json",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{g as p,r as u,d as a}from"./chunk-SVP7TREG-BHROkr6D.js";import{p as f}from"./chunk-JWPE2WC7-VvU_gZI6.js";import{_ as n,l as o}from"./mermaid.core-bds9A7e2.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-CeA8IKWo.js";import"./index-KZcnpXJH.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
|