@dogsbay/commands 0.2.0-beta.179 → 0.2.0-beta.181
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/commands/{topicmap-edit.d.ts → menu-edit.d.ts} +20 -23
- package/dist/commands/{topicmap-edit.js → menu-edit.js} +61 -53
- package/dist/commands/nav-resolve.d.ts +12 -0
- package/dist/commands/nav-resolve.js +51 -0
- package/dist/commands/refactor-files.js +6 -4
- package/dist/commands/refactor-keys.js +2 -2
- package/dist/commands/refactor-structure.js +9 -13
- package/dist/commands/validate.d.ts +2 -2
- package/dist/commands/validate.js +17 -15
- package/dist/commands/where-used.d.ts +1 -1
- package/dist/commands/where-used.js +1 -1
- package/dist/edits.d.ts +5 -1
- package/dist/edits.js +24 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/indexes-entry.d.ts +1 -1
- package/dist/indexes-entry.js +1 -1
- package/dist/indexes.d.ts +20 -12
- package/dist/indexes.js +53 -23
- package/package.json +6 -6
- package/dist/commands/topicmap.d.ts +0 -12
- package/dist/commands/topicmap.js +0 -68
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Structure verbs over
|
|
3
|
-
* `map-add-ref`, `map-move-ref`, `map-remove-ref`, `map-set-props`
|
|
4
|
-
*
|
|
2
|
+
* Structure verbs over a menu file (`nav.yml` / `nav.json`; docs/menu-file.md) — `map-list`,
|
|
3
|
+
* `map-add-ref`, `map-move-ref`, `map-remove-ref`, `map-set-props` (plans/agent-broker.md Phase 3;
|
|
4
|
+
* plans/one-menu-file.md step 3).
|
|
5
5
|
*
|
|
6
|
-
* Every edit goes through `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
* (`""` is the root) — or, where unambiguous, by `href`.
|
|
6
|
+
* Every edit goes through `applyMenuEdit` in `@dogsbay/format-topicmap` (`menu-edit.ts`): it is
|
|
7
|
+
* checked against the reader and replayed on the YAML document, so comments, unknown keys and the
|
|
8
|
+
* author's formatting survive (a minimal diff, not a canonical rewrite), and a `nav.json` is written
|
|
9
|
+
* back in its 2-space form. SHARED with the IDE's Structure panel and the playground: a dangling
|
|
10
|
+
* file, a self-include, moving an entry into its own subtree, or an unresolvable pointer is refused
|
|
11
|
+
* with an issue, not applied — identically for the agent and for a human. This module is the I/O
|
|
12
|
+
* shell: load, existence predicate, write, issue shaping. Entries are addressed by POINTER — a
|
|
13
|
+
* dotted index path like `0.2.1` (`""` is the root) — or, where unambiguous, by file, href, include
|
|
14
|
+
* or label.
|
|
16
15
|
*/
|
|
17
16
|
import { z } from "zod";
|
|
18
17
|
export declare const mapListCommand: import("../engine.js").CommandDef<z.ZodObject<{
|
|
@@ -20,15 +19,14 @@ export declare const mapListCommand: import("../engine.js").CommandDef<z.ZodObje
|
|
|
20
19
|
}, z.core.$strict>>;
|
|
21
20
|
export declare const mapAddRefCommand: import("../engine.js").CommandDef<z.ZodObject<{
|
|
22
21
|
map: z.ZodString;
|
|
22
|
+
label: z.ZodOptional<z.ZodString>;
|
|
23
|
+
file: z.ZodOptional<z.ZodString>;
|
|
23
24
|
href: z.ZodOptional<z.ZodString>;
|
|
24
|
-
|
|
25
|
+
include: z.ZodOptional<z.ZodString>;
|
|
25
26
|
parent: z.ZodDefault<z.ZodString>;
|
|
26
27
|
index: z.ZodOptional<z.ZodNumber>;
|
|
27
|
-
format: z.ZodOptional<z.ZodEnum<{
|
|
28
|
-
topicmap: "topicmap";
|
|
29
|
-
md: "md";
|
|
30
|
-
}>>;
|
|
31
28
|
toc: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
unlisted: z.ZodOptional<z.ZodBoolean>;
|
|
32
30
|
singlePage: z.ZodOptional<z.ZodEnum<{
|
|
33
31
|
yes: "yes";
|
|
34
32
|
no: "no";
|
|
@@ -49,13 +47,12 @@ export declare const mapRemoveRefCommand: import("../engine.js").CommandDef<z.Zo
|
|
|
49
47
|
export declare const mapSetPropsCommand: import("../engine.js").CommandDef<z.ZodObject<{
|
|
50
48
|
map: z.ZodString;
|
|
51
49
|
at: z.ZodString;
|
|
52
|
-
|
|
50
|
+
label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
51
|
+
file: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
53
52
|
href: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
-
|
|
55
|
-
topicmap: "topicmap";
|
|
56
|
-
md: "md";
|
|
57
|
-
}>>>;
|
|
53
|
+
include: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
54
|
toc: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
55
|
+
unlisted: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
59
56
|
singlePage: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
60
57
|
yes: "yes";
|
|
61
58
|
no: "no";
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Structure verbs over
|
|
3
|
-
* `map-add-ref`, `map-move-ref`, `map-remove-ref`, `map-set-props`
|
|
4
|
-
*
|
|
2
|
+
* Structure verbs over a menu file (`nav.yml` / `nav.json`; docs/menu-file.md) — `map-list`,
|
|
3
|
+
* `map-add-ref`, `map-move-ref`, `map-remove-ref`, `map-set-props` (plans/agent-broker.md Phase 3;
|
|
4
|
+
* plans/one-menu-file.md step 3).
|
|
5
5
|
*
|
|
6
|
-
* Every edit goes through `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
* (`""` is the root) — or, where unambiguous, by `href`.
|
|
6
|
+
* Every edit goes through `applyMenuEdit` in `@dogsbay/format-topicmap` (`menu-edit.ts`): it is
|
|
7
|
+
* checked against the reader and replayed on the YAML document, so comments, unknown keys and the
|
|
8
|
+
* author's formatting survive (a minimal diff, not a canonical rewrite), and a `nav.json` is written
|
|
9
|
+
* back in its 2-space form. SHARED with the IDE's Structure panel and the playground: a dangling
|
|
10
|
+
* file, a self-include, moving an entry into its own subtree, or an unresolvable pointer is refused
|
|
11
|
+
* with an issue, not applied — identically for the agent and for a human. This module is the I/O
|
|
12
|
+
* shell: load, existence predicate, write, issue shaping. Entries are addressed by POINTER — a
|
|
13
|
+
* dotted index path like `0.2.1` (`""` is the root) — or, where unambiguous, by file, href, include
|
|
14
|
+
* or label.
|
|
16
15
|
*/
|
|
17
16
|
import { z } from "zod";
|
|
18
|
-
import {
|
|
17
|
+
import { parseMenu, applyMenuEdit, flattenMenu, menuTarget, } from "@dogsbay/format-topicmap";
|
|
19
18
|
import { normalizeStoragePath } from "../storage.js";
|
|
20
19
|
import { defineCommand } from "../engine.js";
|
|
21
20
|
const fail = (code, message, file, extra = {}) => ({
|
|
@@ -31,25 +30,27 @@ const loadMap = async (ctx, rawFile) => {
|
|
|
31
30
|
if (!(await storage.exists(file)))
|
|
32
31
|
return fail("map-missing", `${file} does not exist`, file);
|
|
33
32
|
const source = await storage.read(file);
|
|
34
|
-
const {
|
|
35
|
-
|
|
33
|
+
const { entries, errors } = parseMenu(source, file);
|
|
34
|
+
const problems = errors.filter((e) => e.severity !== "warning");
|
|
35
|
+
if (problems.length) {
|
|
36
36
|
return {
|
|
37
37
|
data: { applied: false },
|
|
38
|
-
issues:
|
|
39
|
-
summary: `${file}: ${
|
|
38
|
+
issues: problems.map((e) => ({ severity: "error", code: e.code, message: e.message, file, ...(e.line ? { line: e.line } : {}) })),
|
|
39
|
+
summary: `${file}: ${problems[0].message}`,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
const existsFor = async (
|
|
42
|
+
const existsFor = async (paths) => {
|
|
43
43
|
const known = new Map();
|
|
44
|
-
for (const
|
|
45
|
-
const target =
|
|
44
|
+
for (const path of paths) {
|
|
45
|
+
const target = typeof path === "string" ? menuTarget(file, path) : undefined;
|
|
46
46
|
if (target !== undefined && !known.has(target))
|
|
47
47
|
known.set(target, await storage.exists(target));
|
|
48
48
|
}
|
|
49
49
|
return (p) => known.get(p) ?? false;
|
|
50
50
|
};
|
|
51
|
-
return { file,
|
|
51
|
+
return { file, entries, source, existsFor };
|
|
52
52
|
};
|
|
53
|
+
const nameOf = (e, fallback) => e.label ?? e.file ?? e.include ?? e.href ?? fallback;
|
|
53
54
|
const write = async (ctx, file, source) => {
|
|
54
55
|
await ctx.workspace.storage.write(file, source);
|
|
55
56
|
ctx.workspace.invalidate();
|
|
@@ -58,48 +59,50 @@ const write = async (ctx, file, source) => {
|
|
|
58
59
|
export const mapListCommand = defineCommand({
|
|
59
60
|
name: "map-list",
|
|
60
61
|
writes: "none",
|
|
61
|
-
description: "List a
|
|
62
|
-
input: z.object({ map: z.string().min(1).describe("Workspace-relative
|
|
62
|
+
description: "List a menu file's entries (nav.yml / nav.json, as written: includes not followed) with their pointers (dotted index paths), depth, label, file, href, include and flags",
|
|
63
|
+
input: z.object({ map: z.string().min(1).describe("Workspace-relative menu file (nav.yml / nav.json)") }).strict(),
|
|
63
64
|
positionals: ["map"],
|
|
64
65
|
async run(ctx, input) {
|
|
65
66
|
const loaded = await loadMap(ctx, input.map);
|
|
66
67
|
if (isOutput(loaded))
|
|
67
68
|
return loaded;
|
|
68
|
-
const entries =
|
|
69
|
-
return { data: { map: loaded.file,
|
|
69
|
+
const entries = flattenMenu(loaded.entries);
|
|
70
|
+
return { data: { map: loaded.file, entries }, summary: `${loaded.file}: ${entries.length} entr${entries.length === 1 ? "y" : "ies"}` };
|
|
70
71
|
},
|
|
71
72
|
});
|
|
72
73
|
// ─── map-add-ref ────────────────────────────────────────────────────────────
|
|
73
74
|
export const mapAddRefCommand = defineCommand({
|
|
74
75
|
name: "map-add-ref",
|
|
75
76
|
writes: "structure",
|
|
76
|
-
description: "Add
|
|
77
|
+
description: "Add an entry to a menu file under a parent (pointer or name; root by default) at an index (end by default): a page (file), a link (href) or another menu file (include). Refuses a dangling file, a self-include, two targets, or an entry with nothing to show",
|
|
77
78
|
input: z
|
|
78
79
|
.object({
|
|
79
|
-
map: z.string().min(1).describe("Workspace-relative
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
map: z.string().min(1).describe("Workspace-relative menu file (nav.yml / nav.json)"),
|
|
81
|
+
label: z.string().min(1).optional().describe("Menu text (optional with file: the page's title)"),
|
|
82
|
+
file: z.string().min(1).optional().describe("A page, relative to the menu file (/x.md from the content root)"),
|
|
83
|
+
href: z.string().min(1).optional().describe("A site path or URL"),
|
|
84
|
+
include: z.string().min(1).optional().describe("Another menu file put in here"),
|
|
85
|
+
parent: z.string().default("").describe('Parent pointer ("0.2") or name; "" = root'),
|
|
83
86
|
index: z.number().int().min(0).optional().describe("Position among siblings (default: append)"),
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
toc: z.boolean().optional().describe("false: built, not in the menu"),
|
|
88
|
+
unlisted: z.boolean().optional().describe("true: built, listed nowhere (with everything under it)"),
|
|
86
89
|
singlePage: z.enum(["yes", "no", "children"]).optional(),
|
|
87
90
|
})
|
|
88
91
|
.strict(),
|
|
89
|
-
// href is optional (title-only grouping entries), so it is not positional
|
|
90
92
|
positionals: ["map"],
|
|
91
93
|
async run(ctx, input) {
|
|
92
94
|
const loaded = await loadMap(ctx, input.map);
|
|
93
95
|
if (isOutput(loaded))
|
|
94
96
|
return loaded;
|
|
95
97
|
const { file, source } = loaded;
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
+
const { map: _m, ...op } = input;
|
|
99
|
+
const exists = await loaded.existsFor([input.file, input.include]);
|
|
100
|
+
const r = applyMenuEdit(source, file, { kind: "add", ...op }, exists);
|
|
98
101
|
if (!r.ok)
|
|
99
102
|
return refused(r, file);
|
|
100
103
|
await write(ctx, file, r.source);
|
|
101
104
|
const issues = [];
|
|
102
|
-
return { data: { applied: true, map: file, pointer: r.pointer, entry: r.entry, target: r.target }, issues, summary: `${file}: added ${
|
|
105
|
+
return { data: { applied: true, map: file, pointer: r.pointer, entry: r.entry, target: r.target }, issues, summary: `${file}: added ${nameOf(r.entry, "an entry")} at ${r.pointer || "root"}` };
|
|
103
106
|
},
|
|
104
107
|
});
|
|
105
108
|
// ─── map-move-ref ───────────────────────────────────────────────────────────
|
|
@@ -109,9 +112,9 @@ export const mapMoveRefCommand = defineCommand({
|
|
|
109
112
|
description: "Move an entry (with its subtree) to a new parent and/or index. Refuses moving into its own subtree",
|
|
110
113
|
input: z
|
|
111
114
|
.object({
|
|
112
|
-
map: z.string().min(1).describe("Workspace-relative
|
|
113
|
-
from: z.string().min(1).describe("Pointer or
|
|
114
|
-
toParent: z.string().optional().describe('New parent pointer
|
|
115
|
+
map: z.string().min(1).describe("Workspace-relative menu file (nav.yml / nav.json)"),
|
|
116
|
+
from: z.string().min(1).describe("Pointer or name of the entry to move"),
|
|
117
|
+
toParent: z.string().optional().describe('New parent pointer or name ("" = root); default: same parent'),
|
|
115
118
|
index: z.number().int().min(0).optional().describe("Position among the new siblings (default: append)"),
|
|
116
119
|
})
|
|
117
120
|
.strict(),
|
|
@@ -121,11 +124,12 @@ export const mapMoveRefCommand = defineCommand({
|
|
|
121
124
|
if (isOutput(loaded))
|
|
122
125
|
return loaded;
|
|
123
126
|
const { file, source } = loaded;
|
|
124
|
-
const
|
|
127
|
+
const { map: _m, ...op } = input;
|
|
128
|
+
const r = applyMenuEdit(source, file, { kind: "move", ...op });
|
|
125
129
|
if (!r.ok)
|
|
126
130
|
return refused(r, file);
|
|
127
131
|
await write(ctx, file, r.source);
|
|
128
|
-
return { data: { applied: true, map: file, from: r.from, to: r.pointer, entry: r.entry }, summary: `${file}: moved ${r.entry
|
|
132
|
+
return { data: { applied: true, map: file, from: r.from, to: r.pointer, entry: r.entry }, summary: `${file}: moved ${nameOf(r.entry, r.from ?? "")} → ${r.pointer}` };
|
|
129
133
|
},
|
|
130
134
|
});
|
|
131
135
|
// ─── map-remove-ref ─────────────────────────────────────────────────────────
|
|
@@ -135,8 +139,8 @@ export const mapRemoveRefCommand = defineCommand({
|
|
|
135
139
|
description: "Remove an entry. Its children go with it unless keepChildren=true (they are then hoisted into its place)",
|
|
136
140
|
input: z
|
|
137
141
|
.object({
|
|
138
|
-
map: z.string().min(1).describe("Workspace-relative
|
|
139
|
-
at: z.string().min(1).describe("Pointer or
|
|
142
|
+
map: z.string().min(1).describe("Workspace-relative menu file (nav.yml / nav.json)"),
|
|
143
|
+
at: z.string().min(1).describe("Pointer or name of the entry"),
|
|
140
144
|
keepChildren: z.boolean().default(false).describe("Hoist the entry's children into its position instead of removing them"),
|
|
141
145
|
})
|
|
142
146
|
.strict(),
|
|
@@ -146,7 +150,8 @@ export const mapRemoveRefCommand = defineCommand({
|
|
|
146
150
|
if (isOutput(loaded))
|
|
147
151
|
return loaded;
|
|
148
152
|
const { file, source } = loaded;
|
|
149
|
-
const
|
|
153
|
+
const { map: _m, ...op } = input;
|
|
154
|
+
const r = applyMenuEdit(source, file, { kind: "remove", ...op });
|
|
150
155
|
if (!r.ok)
|
|
151
156
|
return refused(r, file);
|
|
152
157
|
await write(ctx, file, r.source);
|
|
@@ -157,7 +162,7 @@ export const mapRemoveRefCommand = defineCommand({
|
|
|
157
162
|
return {
|
|
158
163
|
data: { applied: true, map: file, pointer: r.pointer, entry: r.entry, childrenRemoved: r.childrenRemoved, childrenHoisted: r.childrenHoisted },
|
|
159
164
|
issues,
|
|
160
|
-
summary: `${file}: removed ${r.entry
|
|
165
|
+
summary: `${file}: removed ${nameOf(r.entry, input.at)}${r.childrenHoisted ? ` (hoisted ${r.childrenHoisted} children)` : ""}`,
|
|
161
166
|
};
|
|
162
167
|
},
|
|
163
168
|
});
|
|
@@ -165,15 +170,17 @@ export const mapRemoveRefCommand = defineCommand({
|
|
|
165
170
|
export const mapSetPropsCommand = defineCommand({
|
|
166
171
|
name: "map-set-props",
|
|
167
172
|
writes: "structure",
|
|
168
|
-
description: "Set (or with null, unset) an entry's
|
|
173
|
+
description: "Set (or with null, unset) an entry's label, file, href, include, toc, unlisted, singlePage. A new file or include must resolve; a new target replaces the old one",
|
|
169
174
|
input: z
|
|
170
175
|
.object({
|
|
171
|
-
map: z.string().min(1).describe("Workspace-relative
|
|
172
|
-
at: z.string().min(1).describe("Pointer or
|
|
173
|
-
|
|
176
|
+
map: z.string().min(1).describe("Workspace-relative menu file (nav.yml / nav.json)"),
|
|
177
|
+
at: z.string().min(1).describe("Pointer or name of the entry"),
|
|
178
|
+
label: z.string().min(1).nullable().optional(),
|
|
179
|
+
file: z.string().min(1).nullable().optional(),
|
|
174
180
|
href: z.string().min(1).nullable().optional(),
|
|
175
|
-
|
|
181
|
+
include: z.string().min(1).nullable().optional(),
|
|
176
182
|
toc: z.boolean().nullable().optional(),
|
|
183
|
+
unlisted: z.boolean().nullable().optional(),
|
|
177
184
|
singlePage: z.enum(["yes", "no", "children"]).nullable().optional(),
|
|
178
185
|
})
|
|
179
186
|
.strict(),
|
|
@@ -183,8 +190,9 @@ export const mapSetPropsCommand = defineCommand({
|
|
|
183
190
|
if (isOutput(loaded))
|
|
184
191
|
return loaded;
|
|
185
192
|
const { file, source } = loaded;
|
|
186
|
-
const
|
|
187
|
-
const
|
|
193
|
+
const { map: _m, ...op } = input;
|
|
194
|
+
const exists = await loaded.existsFor([input.file, input.include]);
|
|
195
|
+
const r = applyMenuEdit(source, file, { kind: "set", ...op }, exists);
|
|
188
196
|
if (!r.ok)
|
|
189
197
|
return refused(r, file);
|
|
190
198
|
await write(ctx, file, r.source);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nav-resolve` — a menu file (nav.yml / nav.json) read through the engine: includes spliced,
|
|
3
|
+
* variables filled in, each problem at its file and line (docs/menu-file.md). The reader the site
|
|
4
|
+
* build uses (`resolveMenuFile`), over injected Storage, so it works headlessly against any
|
|
5
|
+
* workspace — memory, fs, or IPC-backed.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
export declare const navResolveCommand: import("../engine.js").CommandDef<z.ZodObject<{
|
|
9
|
+
map: z.ZodString;
|
|
10
|
+
content: z.ZodOptional<z.ZodString>;
|
|
11
|
+
variables: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
12
|
+
}, z.core.$strict>>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nav-resolve` — a menu file (nav.yml / nav.json) read through the engine: includes spliced,
|
|
3
|
+
* variables filled in, each problem at its file and line (docs/menu-file.md). The reader the site
|
|
4
|
+
* build uses (`resolveMenuFile`), over injected Storage, so it works headlessly against any
|
|
5
|
+
* workspace — memory, fs, or IPC-backed.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { resolveMenuFile, dirname } from "@dogsbay/format-topicmap";
|
|
9
|
+
import { normalizeStoragePath } from "../storage.js";
|
|
10
|
+
import { defineCommand } from "../engine.js";
|
|
11
|
+
export const navResolveCommand = defineCommand({
|
|
12
|
+
name: "nav-resolve",
|
|
13
|
+
writes: "none",
|
|
14
|
+
description: "Read a menu file (nav.yml / nav.json) with its includes and variables: the entry tree and every problem at its file and line",
|
|
15
|
+
input: z
|
|
16
|
+
.object({
|
|
17
|
+
map: z.string().min(1).describe("Workspace-relative menu file"),
|
|
18
|
+
content: z.string().optional().describe("The content folder file: paths are taken from (default: the menu file's folder)"),
|
|
19
|
+
variables: z.record(z.string(), z.string()).default({}).describe("Values for {{ var }} in labels and paths, as key=value"),
|
|
20
|
+
})
|
|
21
|
+
.strict(),
|
|
22
|
+
positionals: ["map"],
|
|
23
|
+
async run(ctx, { map, content, variables }) {
|
|
24
|
+
const file = normalizeStoragePath(map);
|
|
25
|
+
if (!(await ctx.workspace.storage.exists(file))) {
|
|
26
|
+
return {
|
|
27
|
+
data: { map: file, entries: null, nav: null, files: [], errors: [] },
|
|
28
|
+
issues: [{ severity: "error", code: "nav-load-failed", message: `menu file not found: ${file}`, file }],
|
|
29
|
+
summary: `menu file not found: ${file}`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const resolved = await resolveMenuFile(file, {
|
|
33
|
+
loader: (p) => ctx.workspace.storage.read(normalizeStoragePath(p)),
|
|
34
|
+
variables,
|
|
35
|
+
contentRoot: content !== undefined ? normalizeStoragePath(content) : dirname(file),
|
|
36
|
+
});
|
|
37
|
+
const count = (list) => list.reduce((n, e) => n + 1 + count((e.children ?? [])), 0);
|
|
38
|
+
const errors = resolved.errors.filter((e) => e.severity !== "warning");
|
|
39
|
+
return {
|
|
40
|
+
data: { map: file, entries: resolved.entries, nav: resolved.nav, files: resolved.files, errors: resolved.errors },
|
|
41
|
+
issues: resolved.errors.map((e) => ({
|
|
42
|
+
severity: e.severity === "warning" ? "warning" : "error",
|
|
43
|
+
code: `nav-${e.code}`,
|
|
44
|
+
message: e.message,
|
|
45
|
+
file: e.file || file,
|
|
46
|
+
...(e.line ? { line: e.line } : {}),
|
|
47
|
+
})),
|
|
48
|
+
summary: errors.length ? `${errors.length} problem(s) reading ${file}` : `${count(resolved.entries)} entries from ${file}`,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -39,7 +39,7 @@ const replaceMapHrefs = (source, pairs) => {
|
|
|
39
39
|
export const renameFileCommand = defineCommand({
|
|
40
40
|
name: "rename-file",
|
|
41
41
|
writes: "structure",
|
|
42
|
-
description: "Move/rename a file and rewrite every inbound reference (links, includes,
|
|
42
|
+
description: "Move/rename a file and rewrite every inbound reference (links, includes, menu files)",
|
|
43
43
|
input: z
|
|
44
44
|
.object({
|
|
45
45
|
from: z.string().min(1).describe("Current workspace-relative path"),
|
|
@@ -83,7 +83,7 @@ export const renameFileCommand = defineCommand({
|
|
|
83
83
|
}
|
|
84
84
|
content = replaceIncludePaths(content, includePairs);
|
|
85
85
|
}
|
|
86
|
-
// A moved
|
|
86
|
+
// A moved menu file or keys file must keep addressing ITS targets
|
|
87
87
|
// from the new location — rebase its own href entries too
|
|
88
88
|
const movedMap = index.maps.get(from);
|
|
89
89
|
if (movedMap && dirname(to) !== dirname(from)) {
|
|
@@ -91,7 +91,9 @@ export const renameFileCommand = defineCommand({
|
|
|
91
91
|
for (const ref of movedMap.refs) {
|
|
92
92
|
if (!ref.target)
|
|
93
93
|
continue;
|
|
94
|
-
|
|
94
|
+
// a link to part of a page keeps its fragment
|
|
95
|
+
const hash = ref.href.indexOf("#");
|
|
96
|
+
const newHref = relativeHref(dirname(to), ref.target) + (hash >= 0 ? ref.href.slice(hash) : "");
|
|
95
97
|
if (newHref !== ref.href)
|
|
96
98
|
pairs.set(ref.href, newHref);
|
|
97
99
|
}
|
|
@@ -154,7 +156,7 @@ export const renameFileCommand = defineCommand({
|
|
|
154
156
|
export const safeDeleteCommand = defineCommand({
|
|
155
157
|
name: "safe-delete",
|
|
156
158
|
writes: "structure",
|
|
157
|
-
description: "Delete a file only when nothing references it (links, includes,
|
|
159
|
+
description: "Delete a file only when nothing references it (links, includes, menu files, keys)",
|
|
158
160
|
input: z
|
|
159
161
|
.object({
|
|
160
162
|
file: z.string().min(1).describe("Workspace-relative path to delete"),
|
|
@@ -180,13 +180,13 @@ export const keyifyCommand = defineCommand({
|
|
|
180
180
|
await storage.write(keysFile, `keys:\n ${input.key}:\n href: ${keyHref}\n`);
|
|
181
181
|
}
|
|
182
182
|
// Inbound direct links become key: references. Fragment links and
|
|
183
|
-
// includes/
|
|
183
|
+
// includes/menu entries are left alone (keys address whole
|
|
184
184
|
// resources), each with a note so nothing is silently skipped.
|
|
185
185
|
const updatedDocs = [];
|
|
186
186
|
const byFile = new Map();
|
|
187
187
|
for (const ref of index.inbound.get(file) ?? []) {
|
|
188
188
|
if (ref.kind !== "link") {
|
|
189
|
-
continue; // images/includes/
|
|
189
|
+
continue; // images/includes/menu files keep direct paths
|
|
190
190
|
}
|
|
191
191
|
if (ref.fragment) {
|
|
192
192
|
issues.push({
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { fenceOpenBefore, slugifyHeadingText, transformProseLines } from "@dogsbay/format-dogsbay-md/browser";
|
|
11
|
-
import { dirname } from "@dogsbay/format-topicmap";
|
|
11
|
+
import { dirname, serializeMenu } from "@dogsbay/format-topicmap";
|
|
12
12
|
import { normalizeStoragePath } from "../storage.js";
|
|
13
13
|
import { relativeHref, replaceLinkHrefs, replaceIncludePaths, rewriteInboundRefs, splitFrontmatter, } from "../edits.js";
|
|
14
14
|
import { defineCommand } from "../engine.js";
|
|
@@ -63,7 +63,8 @@ export const splitTopicCommand = defineCommand({
|
|
|
63
63
|
}
|
|
64
64
|
const dir = dirname(file);
|
|
65
65
|
const stem = file.split("/").pop().replace(/\.md$/, "");
|
|
66
|
-
|
|
66
|
+
// a menu file for the pieces (docs/menu-file.md), beside them
|
|
67
|
+
const mapPath = dir ? `${dir}/${stem}.nav.yml` : `${stem}.nav.yml`;
|
|
67
68
|
if (await storage.exists(mapPath)) {
|
|
68
69
|
return fail("split-map-exists", `${mapPath} already exists`, mapPath);
|
|
69
70
|
}
|
|
@@ -94,15 +95,10 @@ export const splitTopicCommand = defineCommand({
|
|
|
94
95
|
await storage.write(section.path, section.body);
|
|
95
96
|
const preamble = lines.slice(0, h2Lines[0]).join("\n").replace(/\s+$/, "");
|
|
96
97
|
await storage.write(file, `${frontmatterBlock}${preamble}\n`);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
` - navtitle: ${JSON.stringify(section.title)}`,
|
|
102
|
-
` href: ${section.path.split("/").pop()}`,
|
|
103
|
-
]),
|
|
104
|
-
];
|
|
105
|
-
await storage.write(mapPath, `topics:\n${mapEntries.join("\n")}\n`);
|
|
98
|
+
await storage.write(mapPath, serializeMenu([
|
|
99
|
+
{ label: doc.title ?? stem, file: `${stem}.md` },
|
|
100
|
+
...sections.map((section) => ({ label: section.title, file: section.path.split("/").pop() })),
|
|
101
|
+
]));
|
|
106
102
|
// Anchor repair: fragments that moved into a section file get their
|
|
107
103
|
// inbound links re-pointed there (needs the POST-split index)
|
|
108
104
|
const newIndex = await ctx.workspace.reindex();
|
|
@@ -264,11 +260,11 @@ export const mergeTopicsCommand = defineCommand({
|
|
|
264
260
|
if (ref.from === into || sources.includes(ref.from))
|
|
265
261
|
return null; // gone or self
|
|
266
262
|
const base = relativeHref(dirname(ref.from), into);
|
|
267
|
-
if (ref.kind === "
|
|
263
|
+
if (ref.kind === "menu") {
|
|
268
264
|
issues.push({
|
|
269
265
|
severity: "warning",
|
|
270
266
|
code: "merge-map-entry",
|
|
271
|
-
message: `
|
|
267
|
+
message: `menu entry "${ref.raw}" now points at ${into} — review for duplicate entries`,
|
|
272
268
|
file: ref.from,
|
|
273
269
|
});
|
|
274
270
|
return base;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Every check is an index lookup: broken relative links, missing link
|
|
5
5
|
* anchors, missing include targets, undefined keys, conflicting key
|
|
6
|
-
* definitions, malformed keys files,
|
|
7
|
-
*
|
|
6
|
+
* definitions, malformed keys files, menu-file problems, and
|
|
7
|
+
* menu entries pointing at missing files. Docs that fail to parse
|
|
8
8
|
* are surfaced too — a doc the indexer can't read can hide any of the
|
|
9
9
|
* above.
|
|
10
10
|
*/
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Every check is an index lookup: broken relative links, missing link
|
|
5
5
|
* anchors, missing include targets, undefined keys, conflicting key
|
|
6
|
-
* definitions, malformed keys files,
|
|
7
|
-
*
|
|
6
|
+
* definitions, malformed keys files, menu-file problems, and
|
|
7
|
+
* menu entries pointing at missing files. Docs that fail to parse
|
|
8
8
|
* are surfaced too — a doc the indexer can't read can hide any of the
|
|
9
9
|
* above.
|
|
10
10
|
*/
|
|
@@ -165,7 +165,7 @@ function resolveSitePath(index, layout, sitePath) {
|
|
|
165
165
|
export const validateCommand = defineCommand({
|
|
166
166
|
name: "validate",
|
|
167
167
|
writes: "none",
|
|
168
|
-
description: "Validate the workspace: links, anchors, includes, keys, and
|
|
168
|
+
description: "Validate the workspace: links, anchors, includes, keys, and menu files (nav.yml / nav.json)",
|
|
169
169
|
input,
|
|
170
170
|
async run(ctx) {
|
|
171
171
|
const index = await ctx.workspace.index();
|
|
@@ -429,17 +429,18 @@ export const validateCommand = defineCommand({
|
|
|
429
429
|
for (const map of index.maps.values()) {
|
|
430
430
|
for (const err of map.errors) {
|
|
431
431
|
issues.push({
|
|
432
|
-
severity: "error",
|
|
433
|
-
code: `
|
|
432
|
+
severity: err.severity === "warning" ? "warning" : "error",
|
|
433
|
+
code: `menu-${err.code}`,
|
|
434
434
|
message: err.message,
|
|
435
|
-
file: err.
|
|
435
|
+
file: err.file || map.path,
|
|
436
|
+
...(err.line ? { line: err.line } : {}),
|
|
436
437
|
});
|
|
437
438
|
}
|
|
438
439
|
}
|
|
439
|
-
// Root-aware walk over the
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
//
|
|
440
|
+
// Root-aware walk over the menu include graph. A "/"-rooted file: is
|
|
441
|
+
// taken from the content folder — the ROOT menu's folder — so
|
|
442
|
+
// target-existence and cycle checks must carry the root dir through
|
|
443
|
+
// the graph; a per-file loop can't see them.
|
|
443
444
|
// Maps unreachable from any root still get their RELATIVE refs
|
|
444
445
|
// checked; their "/"-rooted refs are skipped (no root, no meaning).
|
|
445
446
|
const includedByRelative = new Set();
|
|
@@ -461,8 +462,8 @@ export const validateCommand = defineCommand({
|
|
|
461
462
|
reportedCycles.add(key);
|
|
462
463
|
issues.push({
|
|
463
464
|
severity: "error",
|
|
464
|
-
code: "
|
|
465
|
-
message: `
|
|
465
|
+
code: "menu-cycle",
|
|
466
|
+
message: `menu files include each other: ${cycle.join(" → ")}`,
|
|
466
467
|
file: path,
|
|
467
468
|
});
|
|
468
469
|
}
|
|
@@ -474,7 +475,7 @@ export const validateCommand = defineCommand({
|
|
|
474
475
|
for (const ref of entry?.refs ?? []) {
|
|
475
476
|
let target = ref.target;
|
|
476
477
|
if (!target && ref.rootRelative && resolveRootRelative) {
|
|
477
|
-
target = joinPath(rootDir, ref.href.replace(/^\/+/, ""));
|
|
478
|
+
target = joinPath(rootDir, ref.href.split("#")[0].replace(/^\/+/, ""));
|
|
478
479
|
}
|
|
479
480
|
if (!target)
|
|
480
481
|
continue; // external, or root-relative with no known root
|
|
@@ -485,9 +486,10 @@ export const validateCommand = defineCommand({
|
|
|
485
486
|
reportedMissing.add(missingKey);
|
|
486
487
|
issues.push({
|
|
487
488
|
severity: "error",
|
|
488
|
-
code: "
|
|
489
|
-
message:
|
|
489
|
+
code: "menu-target-missing",
|
|
490
|
+
message: `${ref.field}: "${ref.href}" → ${target} does not exist`,
|
|
490
491
|
file: path,
|
|
492
|
+
...(ref.line ? { line: ref.line } : {}),
|
|
491
493
|
});
|
|
492
494
|
}
|
|
493
495
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `where-used` — inbound references for a file, anchor, or key.
|
|
3
3
|
*
|
|
4
4
|
* Target forms:
|
|
5
|
-
* - `path/to/file.md` → links, images, includes,
|
|
5
|
+
* - `path/to/file.md` → links, images, includes, menu entries
|
|
6
6
|
* - `path/to/file.md#id` → only references targeting that anchor
|
|
7
7
|
* - `key:name` (or `name` when it matches no file) → key uses
|
|
8
8
|
*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `where-used` — inbound references for a file, anchor, or key.
|
|
3
3
|
*
|
|
4
4
|
* Target forms:
|
|
5
|
-
* - `path/to/file.md` → links, images, includes,
|
|
5
|
+
* - `path/to/file.md` → links, images, includes, menu entries
|
|
6
6
|
* - `path/to/file.md#id` → only references targeting that anchor
|
|
7
7
|
* - `key:name` (or `name` when it matches no file) → key uses
|
|
8
8
|
*
|
package/dist/edits.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ export declare const relativeHref: (fromDir: string, targetPath: string) => stri
|
|
|
20
20
|
export declare const replaceLinkHref: (source: string, oldHref: string, newHref: string) => string;
|
|
21
21
|
/** Replace the path inside `{% include "old" %}` directives in prose. */
|
|
22
22
|
export declare const replaceIncludePath: (source: string, oldPath: string, newPath: string) => string;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Rewrite a path in a menu file (docs/menu-file.md) or a keys file: a `key: path` line — `file:`,
|
|
25
|
+
* `include:`, `href:`, a short-form `- Label: path`, a JSON `"file": "path",` — or a bare `- path`.
|
|
26
|
+
* Only an exact, whole value is replaced; the key, quotes and a trailing comment are kept.
|
|
27
|
+
*/
|
|
24
28
|
export declare const replaceMapHref: (source: string, oldHref: string, newHref: string) => string;
|
|
25
29
|
export declare const replaceLinkHrefs: (source: string, pairs: Map<string, string>) => string;
|
|
26
30
|
export declare const replaceIncludePaths: (source: string, pairs: Map<string, string>) => string;
|
package/dist/edits.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Refactorings are index lookups + SURGICAL text edits: files are
|
|
5
5
|
* rewritten by replacing exactly the authored reference syntax (link
|
|
6
|
-
* hrefs, include paths,
|
|
6
|
+
* hrefs, include paths, menu-file path lines), never by re-serializing
|
|
7
7
|
* whole documents — authored formatting survives.
|
|
8
8
|
*/
|
|
9
9
|
import { includeDirectiveRe } from "@dogsbay/minja/browser";
|
|
@@ -52,10 +52,23 @@ export const replaceLinkHref = (source, oldHref, newHref) => {
|
|
|
52
52
|
export const replaceIncludePath = (source, oldPath, newPath) => editMarkdownProse(source, (prose) => prose.replace(includeDirectiveRe(), (match, path) => path === oldPath
|
|
53
53
|
? match.replace(`"${oldPath}"`, `"${newPath}"`).replace(`'${oldPath}'`, `'${newPath}'`)
|
|
54
54
|
: match));
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Rewrite a path in a menu file (docs/menu-file.md) or a keys file: a `key: path` line — `file:`,
|
|
57
|
+
* `include:`, `href:`, a short-form `- Label: path`, a JSON `"file": "path",` — or a bare `- path`.
|
|
58
|
+
* Only an exact, whole value is replaced; the key, quotes and a trailing comment are kept.
|
|
59
|
+
*/
|
|
56
60
|
export const replaceMapHref = (source, oldHref, newHref) => {
|
|
57
61
|
const old = escapeRegExp(oldHref);
|
|
58
|
-
|
|
62
|
+
// the value, quoted or not, then optional `,` (JSON) and a comment (YAML: after a space)
|
|
63
|
+
const value = `(["']?)${old}\\2([ \\t]*,?(?:[ \\t]+#.*)?[ \\t]*)$`;
|
|
64
|
+
// a path key (file / include / href, quoted for JSON) or a short-form `Label:` — never `label:` / `title:`
|
|
65
|
+
const keyed = new RegExp(`(^[ \\t]*(?:-[ \\t]+)?(?:["']?(?:file|include|href)["']?|(?!["']?(?:label|title)["']?[ \\t]*:)(?:"[^"\\n]*"|'[^'\\n]*'|[^\\s#"'\\-][^:#\\n]*?))[ \\t]*:[ \\t]*)${value}`, "gm");
|
|
66
|
+
// a bare `- path` (YAML) or a bare `"path",` in a JSON list
|
|
67
|
+
const bare = new RegExp(`(^[ \\t]*(?:-[ \\t]+)?)${value}`, "gm");
|
|
68
|
+
const swap = (_m, prefix, quote, suffix) => `${prefix}${quote}${newHref}${quote}${suffix}`;
|
|
69
|
+
return source.replace(keyed, swap).replace(bare, (m, prefix, quote, suffix) =>
|
|
70
|
+
// a bare value is a list item: a YAML `- x` or a quoted JSON string
|
|
71
|
+
/-[ \t]+$/.test(prefix) || quote === '"' ? swap(m, prefix, quote, suffix) : m);
|
|
59
72
|
};
|
|
60
73
|
/**
|
|
61
74
|
* Rewrite a batch of href replacements without cross-talk: pairs are
|
|
@@ -93,7 +106,7 @@ export const applyRefRewrite = (source, ref, newHref) => {
|
|
|
93
106
|
switch (ref.kind) {
|
|
94
107
|
case "include":
|
|
95
108
|
return replaceIncludePath(source, ref.raw, newHref);
|
|
96
|
-
case "
|
|
109
|
+
case "menu":
|
|
97
110
|
return replaceMapHref(source, ref.raw, newHref);
|
|
98
111
|
default:
|
|
99
112
|
return replaceLinkHref(source, ref.raw, newHref);
|
|
@@ -126,7 +139,14 @@ export async function rewriteInboundRefs(workspace, index, target, mapper) {
|
|
|
126
139
|
continue;
|
|
127
140
|
const original = await workspace.storage.read(file);
|
|
128
141
|
let source = original;
|
|
142
|
+
// one rewrite per (kind, path, new path): a rewrite replaces every occurrence in the file, so the
|
|
143
|
+
// same path written twice (a menu's page and its group, a page linked twice) is one rewrite
|
|
144
|
+
const seen = new Set();
|
|
129
145
|
for (const { ref, newHref } of rewrites) {
|
|
146
|
+
const key = `${ref.kind}\u0000${ref.raw}\u0000${newHref}`;
|
|
147
|
+
if (seen.has(key))
|
|
148
|
+
continue;
|
|
149
|
+
seen.add(key);
|
|
130
150
|
const before = source;
|
|
131
151
|
source = applyRefRewrite(source, ref, newHref);
|
|
132
152
|
if (source === before)
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
export { type Storage, MemoryStorage, normalizeStoragePath, } from "./storage.js";
|
|
13
13
|
export { NodeStorage, type NodeStorageOptions } from "./node-storage.js";
|
|
14
14
|
export { Workspace } from "./workspace.js";
|
|
15
|
-
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, type BuildIndexOptions, type WorkspaceIndex, type DocIndexEntry, type DocHeading, type DocLink, type DocInclude, type DocTarget, type TopicMapIndexEntry, type TopicMapRef, type KeyDefinition, type KeyFileError, type InboundRef, type RefKind, } from "./indexes.js";
|
|
15
|
+
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, type BuildIndexOptions, type WorkspaceIndex, type DocIndexEntry, type DocHeading, type DocLink, type DocInclude, type DocTarget, isMenuFilePath, type TopicMapIndexEntry, type TopicMapRef, type KeyDefinition, type KeyFileError, type InboundRef, type RefKind, } from "./indexes.js";
|
|
16
16
|
export { expressionNames, variableKey, type SymbolEntry, type SymbolDefinition, type SymbolUse, type SymbolRange, type SymbolCondition, type SymbolContext, type DefinitionVia, type UseForm, type FileVariables, type Variant, } from "./variables.js";
|
|
17
17
|
export { flagForField, FlagArgumentError, type FlagSpec } from "./flags.js";
|
|
18
18
|
export { commandInputJsonSchema, type CommandJsonSchema } from "./json-schema.js";
|
|
@@ -23,15 +23,15 @@ import { validateCommand } from "./commands/validate.js";
|
|
|
23
23
|
import { whereUsedCommand } from "./commands/where-used.js";
|
|
24
24
|
import { renderPageCommand } from "./commands/render-page.js";
|
|
25
25
|
import { keysListCommand, keysResolveCommand } from "./commands/keys.js";
|
|
26
|
-
import {
|
|
26
|
+
import { navResolveCommand } from "./commands/nav-resolve.js";
|
|
27
27
|
import { reindexCommand } from "./commands/reindex.js";
|
|
28
28
|
import { renameFileCommand, safeDeleteCommand, extractIncludeCommand } from "./commands/refactor-files.js";
|
|
29
29
|
import { renameKeyCommand, keyifyCommand } from "./commands/refactor-keys.js";
|
|
30
30
|
import { splitTopicCommand, mergeTopicsCommand } from "./commands/refactor-structure.js";
|
|
31
31
|
export { WELL_KNOWN_FIELDS, type FieldSpec, type FrontmatterPolicy, } from "@dogsbay/types";
|
|
32
32
|
export { linkRetargetCommand } from "./commands/link-retarget.js";
|
|
33
|
-
export { validateCommand, whereUsedCommand, renderPageCommand, keysListCommand, keysResolveCommand,
|
|
33
|
+
export { validateCommand, whereUsedCommand, renderPageCommand, keysListCommand, keysResolveCommand, navResolveCommand, reindexCommand, renameFileCommand, safeDeleteCommand, extractIncludeCommand, renameKeyCommand, keyifyCommand, splitTopicCommand, mergeTopicsCommand, };
|
|
34
34
|
export { contentHash } from "./sha256.js";
|
|
35
35
|
export { topicReadCommand, topicSetTitleCommand, sectionReplaceCommand, blockInsertCommand, blockDeleteCommand, propsGetCommand, propsSetCommand, } from "./commands/content.js";
|
|
36
|
-
export { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/
|
|
36
|
+
export { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/menu-edit.js";
|
|
37
37
|
export declare const createDefaultRegistry: () => CommandRegistry;
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
export { MemoryStorage, normalizeStoragePath, } from "./storage.js";
|
|
13
13
|
export { NodeStorage } from "./node-storage.js";
|
|
14
14
|
export { Workspace } from "./workspace.js";
|
|
15
|
-
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, } from "./indexes.js";
|
|
15
|
+
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, isMenuFilePath, } from "./indexes.js";
|
|
16
16
|
export { expressionNames, variableKey, } from "./variables.js";
|
|
17
17
|
export { flagForField, FlagArgumentError } from "./flags.js";
|
|
18
18
|
export { commandInputJsonSchema } from "./json-schema.js";
|
|
@@ -23,7 +23,7 @@ import { validateCommand } from "./commands/validate.js";
|
|
|
23
23
|
import { whereUsedCommand } from "./commands/where-used.js";
|
|
24
24
|
import { renderPageCommand } from "./commands/render-page.js";
|
|
25
25
|
import { keysListCommand, keysResolveCommand } from "./commands/keys.js";
|
|
26
|
-
import {
|
|
26
|
+
import { navResolveCommand } from "./commands/nav-resolve.js";
|
|
27
27
|
import { reindexCommand } from "./commands/reindex.js";
|
|
28
28
|
import { renameFileCommand, safeDeleteCommand, extractIncludeCommand, } from "./commands/refactor-files.js";
|
|
29
29
|
import { renameKeyCommand, keyifyCommand } from "./commands/refactor-keys.js";
|
|
@@ -31,11 +31,11 @@ import { splitTopicCommand, mergeTopicsCommand } from "./commands/refactor-struc
|
|
|
31
31
|
import { topicReadCommand, topicSetTitleCommand, sectionReplaceCommand, blockInsertCommand, blockDeleteCommand, propsGetCommand, propsSetCommand, } from "./commands/content.js";
|
|
32
32
|
export { WELL_KNOWN_FIELDS, } from "@dogsbay/types";
|
|
33
33
|
export { linkRetargetCommand } from "./commands/link-retarget.js";
|
|
34
|
-
import { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/
|
|
35
|
-
export { validateCommand, whereUsedCommand, renderPageCommand, keysListCommand, keysResolveCommand,
|
|
34
|
+
import { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/menu-edit.js";
|
|
35
|
+
export { validateCommand, whereUsedCommand, renderPageCommand, keysListCommand, keysResolveCommand, navResolveCommand, reindexCommand, renameFileCommand, safeDeleteCommand, extractIncludeCommand, renameKeyCommand, keyifyCommand, splitTopicCommand, mergeTopicsCommand, };
|
|
36
36
|
export { contentHash } from "./sha256.js";
|
|
37
37
|
export { topicReadCommand, topicSetTitleCommand, sectionReplaceCommand, blockInsertCommand, blockDeleteCommand, propsGetCommand, propsSetCommand, } from "./commands/content.js";
|
|
38
|
-
export { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/
|
|
38
|
+
export { mapListCommand, mapAddRefCommand, mapMoveRefCommand, mapRemoveRefCommand, mapSetPropsCommand, } from "./commands/menu-edit.js";
|
|
39
39
|
/** The standard registry with every built-in command registered. */
|
|
40
40
|
import { linkRetargetCommand } from "./commands/link-retarget.js";
|
|
41
41
|
export const createDefaultRegistry = () => {
|
|
@@ -44,7 +44,7 @@ export const createDefaultRegistry = () => {
|
|
|
44
44
|
registry.register(whereUsedCommand);
|
|
45
45
|
registry.register(keysListCommand);
|
|
46
46
|
registry.register(keysResolveCommand);
|
|
47
|
-
registry.register(
|
|
47
|
+
registry.register(navResolveCommand);
|
|
48
48
|
registry.register(reindexCommand);
|
|
49
49
|
registry.register(renameFileCommand);
|
|
50
50
|
registry.register(safeDeleteCommand);
|
package/dist/indexes-entry.d.ts
CHANGED
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
export { type Storage, MemoryStorage, normalizeStoragePath } from "./storage.js";
|
|
12
12
|
export { Workspace } from "./workspace.js";
|
|
13
13
|
export { contentHash } from "./sha256.js";
|
|
14
|
-
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, type BuildIndexOptions, type WorkspaceIndex, type DocIndexEntry, type DocHeading, type DocLink, type DocInclude, type DocTarget, type TopicMapIndexEntry, type TopicMapRef, type KeyDefinition, type KeyFileError, type InboundRef, type RefKind, } from "./indexes.js";
|
|
14
|
+
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, type BuildIndexOptions, type WorkspaceIndex, type DocIndexEntry, type DocHeading, type DocLink, type DocInclude, type DocTarget, isMenuFilePath, type TopicMapIndexEntry, type TopicMapRef, type KeyDefinition, type KeyFileError, type InboundRef, type RefKind, } from "./indexes.js";
|
|
15
15
|
export { expressionNames, variableKey, type SymbolEntry, type SymbolDefinition, type SymbolUse, type SymbolRange, type SymbolCondition, type SymbolContext, type DefinitionVia, type UseForm, type FileVariables, type Variant, } from "./variables.js";
|
package/dist/indexes-entry.js
CHANGED
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
export { MemoryStorage, normalizeStoragePath } from "./storage.js";
|
|
12
12
|
export { Workspace } from "./workspace.js";
|
|
13
13
|
export { contentHash } from "./sha256.js";
|
|
14
|
-
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, } from "./indexes.js";
|
|
14
|
+
export { buildWorkspaceIndex, anchorAliases, anchorAliasTargets, blankCodeRegions, isMenuFilePath, } from "./indexes.js";
|
|
15
15
|
export { expressionNames, variableKey, } from "./variables.js";
|
package/dist/indexes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { isMenuFilePath, type MenuError } from "@dogsbay/format-topicmap";
|
|
2
2
|
import type { Storage } from "./storage.js";
|
|
3
3
|
import { type FileVariables, type SymbolEntry, type Variant } from "./variables.js";
|
|
4
4
|
export interface DocHeading {
|
|
@@ -9,7 +9,7 @@ export interface DocHeading {
|
|
|
9
9
|
/** The anchor the SITE renders for this heading (renderer-parity slug), when it is a top-level heading. */
|
|
10
10
|
slug?: string;
|
|
11
11
|
}
|
|
12
|
-
export type RefKind = "link" | "image" | "include" | "
|
|
12
|
+
export type RefKind = "link" | "image" | "include" | "menu" | "key";
|
|
13
13
|
export interface DocLink {
|
|
14
14
|
/** The href exactly as authored. */
|
|
15
15
|
href: string;
|
|
@@ -97,26 +97,32 @@ export interface DocIndexEntry {
|
|
|
97
97
|
*/
|
|
98
98
|
hash: string;
|
|
99
99
|
}
|
|
100
|
+
/** One path in a menu file (docs/menu-file.md): a page (`file`), a link (`href`) or an included menu file. */
|
|
100
101
|
export interface TopicMapRef {
|
|
102
|
+
/** The path as written. */
|
|
101
103
|
href: string;
|
|
104
|
+
/** Which field holds it. */
|
|
105
|
+
field: "file" | "href" | "include";
|
|
102
106
|
/**
|
|
103
|
-
* Workspace-relative target — undefined for
|
|
104
|
-
* "/"-rooted
|
|
105
|
-
*
|
|
106
|
-
* root; see `rootRelative`).
|
|
107
|
+
* Workspace-relative target (fragment off) — undefined for a URL, a site path and a fragment, AND
|
|
108
|
+
* for a "/"-rooted `file:`, which is taken from the content folder (the ROOT menu's folder; only
|
|
109
|
+
* known when walking from a root; see `rootRelative`).
|
|
107
110
|
*/
|
|
108
111
|
target?: string;
|
|
109
|
-
/** True for "/"-rooted
|
|
112
|
+
/** True for a "/"-rooted `file:` / `include:` (content-folder-relative). */
|
|
110
113
|
rootRelative?: boolean;
|
|
111
|
-
/** True for
|
|
114
|
+
/** True for an `include:` (another menu file). */
|
|
112
115
|
isMap: boolean;
|
|
113
|
-
|
|
116
|
+
label?: string;
|
|
117
|
+
/** 1-based line in the menu file. */
|
|
118
|
+
line?: number;
|
|
114
119
|
}
|
|
120
|
+
/** A menu file in the workspace: `nav.yml` / `nav.json`, `*.nav.yml`, or one a menu file includes. */
|
|
115
121
|
export interface TopicMapIndexEntry {
|
|
116
122
|
path: string;
|
|
117
|
-
title?: string;
|
|
118
123
|
refs: TopicMapRef[];
|
|
119
|
-
|
|
124
|
+
/** Problems reading it (warnings carry `severity: "warning"`). */
|
|
125
|
+
errors: MenuError[];
|
|
120
126
|
}
|
|
121
127
|
export interface KeyDefinition {
|
|
122
128
|
name: string;
|
|
@@ -129,7 +135,7 @@ export interface KeyFileError {
|
|
|
129
135
|
message: string;
|
|
130
136
|
}
|
|
131
137
|
export interface InboundRef {
|
|
132
|
-
/** Referencing file (doc or
|
|
138
|
+
/** Referencing file (doc or menu file). */
|
|
133
139
|
from: string;
|
|
134
140
|
kind: RefKind;
|
|
135
141
|
/** The href/path exactly as authored in the referencing file. */
|
|
@@ -180,6 +186,8 @@ export interface WorkspaceIndex {
|
|
|
180
186
|
* so a directive inside one is real and must be visible to validation.
|
|
181
187
|
*/
|
|
182
188
|
export declare const blankCodeRegions: (source: string) => string;
|
|
189
|
+
/** A menu file by its name (`nav.yml`, `<name>.nav.yml`; format-topicmap's rule, re-exported). */
|
|
190
|
+
export { isMenuFilePath };
|
|
183
191
|
/**
|
|
184
192
|
* Anchors OTHER renderers would give a heading text — GitHub-slugger
|
|
185
193
|
* (lowercase, punctuation removed except `-`/space, spaces → `-`, no
|
package/dist/indexes.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Workspace indexes — first-class artifacts every command reads.
|
|
3
3
|
*
|
|
4
4
|
* One pass over the workspace builds: a per-document table (frontmatter,
|
|
5
|
-
* headings, anchors, links, includes, key uses), the
|
|
5
|
+
* headings, anchors, links, includes, key uses), the menu-file table
|
|
6
6
|
* (parsed maps + their entry refs), the key-definition table (from
|
|
7
7
|
* `*.keys.yaml`), and the inverted inbound-reference graph. Refactorings
|
|
8
8
|
* and queries become index lookups; `reindex` rebuilds.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { dogsbayMdToTree, headingIds, pageId, isMinjaProcessedFence, transformCodeRegions, authoredAnchor, authoredInlineAnchor, anchorLabel, findAnchorSpan } from "@dogsbay/format-dogsbay-md/browser";
|
|
13
13
|
import { includeDirectiveRe } from "@dogsbay/minja/browser";
|
|
14
|
-
import {
|
|
14
|
+
import { parseMenu, isExternalHref, normalizePath, dirname, joinPath, isMenuFilePath, } from "@dogsbay/format-topicmap";
|
|
15
15
|
import { load as loadYaml } from "js-yaml";
|
|
16
16
|
import { contentHash } from "./sha256.js";
|
|
17
17
|
import { appliesIn, scanFileVariables, scanParams, variableKey } from "./variables.js";
|
|
@@ -423,33 +423,37 @@ const indexDoc = (path, source, templateSource = false) => {
|
|
|
423
423
|
};
|
|
424
424
|
const collectMapRefs = (entries, mapPath, out) => {
|
|
425
425
|
for (const entry of entries) {
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
426
|
+
for (const field of ["file", "include", "href"]) {
|
|
427
|
+
const value = entry[field];
|
|
428
|
+
if (value === undefined || value === "")
|
|
429
|
+
continue;
|
|
430
|
+
const path = value.split("#")[0];
|
|
431
|
+
// a link (`href:`) is a site path or URL, never a workspace file
|
|
432
|
+
const local = field !== "href" && path !== "" && !isExternalHref(value) && !value.endsWith("/") && !value.includes("{{");
|
|
433
|
+
const rootRelative = local && path.startsWith("/");
|
|
429
434
|
out.push({
|
|
430
|
-
href:
|
|
431
|
-
|
|
435
|
+
href: value,
|
|
436
|
+
field,
|
|
437
|
+
...(local && !rootRelative ? { target: joinPath(dirname(mapPath), path) } : {}),
|
|
432
438
|
...(rootRelative ? { rootRelative: true } : {}),
|
|
433
|
-
isMap:
|
|
434
|
-
...(entry.
|
|
439
|
+
isMap: field === "include",
|
|
440
|
+
...(entry.label ? { label: entry.label } : {}),
|
|
441
|
+
...(entry.line ? { line: entry.line } : {}),
|
|
435
442
|
});
|
|
436
443
|
}
|
|
437
|
-
if (entry.
|
|
438
|
-
collectMapRefs(entry.
|
|
444
|
+
if (entry.children)
|
|
445
|
+
collectMapRefs(entry.children, mapPath, out);
|
|
439
446
|
}
|
|
440
447
|
};
|
|
441
448
|
const indexMap = (path, source) => {
|
|
442
|
-
const {
|
|
449
|
+
const { entries, errors } = parseMenu(source, path);
|
|
443
450
|
const refs = [];
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return {
|
|
447
|
-
path,
|
|
448
|
-
...(map?.title ? { title: map.title } : {}),
|
|
449
|
-
refs,
|
|
450
|
-
errors,
|
|
451
|
-
};
|
|
451
|
+
collectMapRefs(entries, path, refs);
|
|
452
|
+
return { path, refs, errors };
|
|
452
453
|
};
|
|
454
|
+
/** A menu file by its name (`nav.yml`, `<name>.nav.yml`; format-topicmap's rule, re-exported). */
|
|
455
|
+
export { isMenuFilePath };
|
|
456
|
+
const MENU_EXT = /\.(?:ya?ml|json)$/i;
|
|
453
457
|
const indexKeysFile = (path, source, keys, errors) => {
|
|
454
458
|
let raw;
|
|
455
459
|
try {
|
|
@@ -580,8 +584,10 @@ export async function buildWorkspaceIndex(storage, options = {}) {
|
|
|
580
584
|
for (const [path, doc] of options.previous.docs)
|
|
581
585
|
if (current.has(path) && !changed.has(path))
|
|
582
586
|
docs.set(path, doc);
|
|
587
|
+
// only the menu files found by name: one indexed because something included it is re-derived
|
|
588
|
+
// from the includes (it may no longer be included)
|
|
583
589
|
for (const [path, map] of options.previous.maps)
|
|
584
|
-
if (current.has(path) && !changed.has(path))
|
|
590
|
+
if (current.has(path) && !changed.has(path) && isMenuFilePath(path))
|
|
585
591
|
maps.set(path, map);
|
|
586
592
|
}
|
|
587
593
|
// the config first: its sources decide which pages are template pages
|
|
@@ -590,7 +596,7 @@ export async function buildWorkspaceIndex(storage, options = {}) {
|
|
|
590
596
|
const configChanged = changed !== null && CONFIG_FILES.some((f) => changed.has(f));
|
|
591
597
|
for (const path of files) {
|
|
592
598
|
const reuse = changed !== null && !changed.has(path) && !configChanged;
|
|
593
|
-
if (
|
|
599
|
+
if (isMenuFilePath(path)) {
|
|
594
600
|
if (!(reuse && maps.has(path)))
|
|
595
601
|
maps.set(path, indexMap(path, await storage.read(path)));
|
|
596
602
|
}
|
|
@@ -602,6 +608,29 @@ export async function buildWorkspaceIndex(storage, options = {}) {
|
|
|
602
608
|
docs.set(path, indexDoc(path, await storage.read(path), config.templateSources.some((dir) => inFolder(path, dir))));
|
|
603
609
|
}
|
|
604
610
|
}
|
|
611
|
+
// menu files reached only by an include (`api/part.yml`): indexed too, to a fixpoint. A "/"-rooted
|
|
612
|
+
// include is from the content folder: the folder of the menu file found by name it hangs from.
|
|
613
|
+
const rootOf = new Map();
|
|
614
|
+
for (const path of maps.keys())
|
|
615
|
+
rootOf.set(path, dirname(path));
|
|
616
|
+
for (let grew = true; grew;) {
|
|
617
|
+
grew = false;
|
|
618
|
+
for (const map of [...maps.values()]) {
|
|
619
|
+
for (const ref of map.refs) {
|
|
620
|
+
if (!ref.isMap)
|
|
621
|
+
continue;
|
|
622
|
+
const root = rootOf.get(map.path) ?? dirname(map.path);
|
|
623
|
+
const target = ref.target ?? (ref.rootRelative ? joinPath(root, ref.href.split("#")[0].replace(/^\/+/, "")) : undefined);
|
|
624
|
+
if (target && !rootOf.has(target))
|
|
625
|
+
rootOf.set(target, root);
|
|
626
|
+
if (target && !maps.has(target) && current.has(target) && MENU_EXT.test(target) && !isKeysFilePath(target)) {
|
|
627
|
+
const reuse = changed !== null && !changed.has(target) && !configChanged ? options.previous?.maps.get(target) : undefined;
|
|
628
|
+
maps.set(target, reuse ?? indexMap(target, await storage.read(target)));
|
|
629
|
+
grew = true;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
605
634
|
// ---- inverted graphs --------------------------------------------------
|
|
606
635
|
const inbound = new Map();
|
|
607
636
|
const keyUses = new Map();
|
|
@@ -638,7 +667,8 @@ export async function buildWorkspaceIndex(storage, options = {}) {
|
|
|
638
667
|
for (const map of maps.values()) {
|
|
639
668
|
for (const ref of map.refs) {
|
|
640
669
|
if (ref.target) {
|
|
641
|
-
|
|
670
|
+
const hash = ref.href.indexOf("#");
|
|
671
|
+
addInbound(ref.target, { from: map.path, kind: "menu", raw: ref.href, ...(hash >= 0 && hash < ref.href.length - 1 ? { fragment: ref.href.slice(hash + 1) } : {}) });
|
|
642
672
|
}
|
|
643
673
|
}
|
|
644
674
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/commands",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.181",
|
|
4
4
|
"description": "Typed, headless-first command engine for the Dogsbay platform — one zod-defined command yields CLI, JSON-RPC, and MCP surfaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"js-yaml": "^5.2.1",
|
|
32
32
|
"yaml": "^2.9.0",
|
|
33
33
|
"zod": "^4.4.3",
|
|
34
|
-
"@dogsbay/format-dogsbay-md": "0.2.0-beta.
|
|
35
|
-
"@dogsbay/format-topicmap": "0.2.0-beta.
|
|
36
|
-
"@dogsbay/minja": "0.2.0-beta.
|
|
37
|
-
"@dogsbay/render": "0.2.0-beta.
|
|
38
|
-
"@dogsbay/types": "0.2.0-beta.
|
|
34
|
+
"@dogsbay/format-dogsbay-md": "0.2.0-beta.181",
|
|
35
|
+
"@dogsbay/format-topicmap": "0.2.0-beta.181",
|
|
36
|
+
"@dogsbay/minja": "0.2.0-beta.181",
|
|
37
|
+
"@dogsbay/render": "0.2.0-beta.181",
|
|
38
|
+
"@dogsbay/types": "0.2.0-beta.181"
|
|
39
39
|
},
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"repository": {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `topicmap-resolve` — resolve a topic map through the engine.
|
|
3
|
-
*
|
|
4
|
-
* Same resolution the site build performs (recursive includes, minja
|
|
5
|
-
* variables, toc pruning) but over injected Storage, so it works
|
|
6
|
-
* headlessly against any workspace — memory, fs, or IPC-backed.
|
|
7
|
-
*/
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
export declare const topicmapResolveCommand: import("../engine.js").CommandDef<z.ZodObject<{
|
|
10
|
-
map: z.ZodString;
|
|
11
|
-
variables: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
12
|
-
}, z.core.$strict>>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `topicmap-resolve` — resolve a topic map through the engine.
|
|
3
|
-
*
|
|
4
|
-
* Same resolution the site build performs (recursive includes, minja
|
|
5
|
-
* variables, toc pruning) but over injected Storage, so it works
|
|
6
|
-
* headlessly against any workspace — memory, fs, or IPC-backed.
|
|
7
|
-
*/
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import { resolveTopicMap, normalizePath, dirname, joinPath } from "@dogsbay/format-topicmap";
|
|
10
|
-
import { normalizeStoragePath } from "../storage.js";
|
|
11
|
-
import { defineCommand } from "../engine.js";
|
|
12
|
-
export const topicmapResolveCommand = defineCommand({
|
|
13
|
-
name: "topicmap-resolve",
|
|
14
|
-
writes: "none",
|
|
15
|
-
description: "Resolve a topic map (includes + variables) to its final entry tree",
|
|
16
|
-
input: z
|
|
17
|
-
.object({
|
|
18
|
-
map: z.string().min(1).describe("Workspace-relative path to the *.topicmap.yml"),
|
|
19
|
-
variables: z
|
|
20
|
-
.record(z.string(), z.string())
|
|
21
|
-
.default({})
|
|
22
|
-
.describe("minja variables for {{ var }} entries, as key=value"),
|
|
23
|
-
})
|
|
24
|
-
.strict(),
|
|
25
|
-
positionals: ["map"],
|
|
26
|
-
async run(ctx, { map, variables }) {
|
|
27
|
-
const mapPath = normalizeStoragePath(map);
|
|
28
|
-
if (!(await ctx.workspace.storage.exists(mapPath))) {
|
|
29
|
-
return {
|
|
30
|
-
data: { map: mapPath, resolved: null, errors: [] },
|
|
31
|
-
issues: [
|
|
32
|
-
{
|
|
33
|
-
severity: "error",
|
|
34
|
-
code: "topicmap-load-failed",
|
|
35
|
-
message: `topic map not found: ${mapPath}`,
|
|
36
|
-
file: mapPath,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
summary: `topic map not found: ${mapPath}`,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// Loader semantics match the CLI's fs loader: relative paths resolve
|
|
43
|
-
// against the including map (resolveTopicMap pre-joins them), and a
|
|
44
|
-
// "/"-rooted path means "relative to the root map's directory".
|
|
45
|
-
const rootDir = dirname(mapPath);
|
|
46
|
-
const loader = async (path) => {
|
|
47
|
-
const normalized = normalizePath(path);
|
|
48
|
-
const workspacePath = normalized.startsWith("/")
|
|
49
|
-
? joinPath(rootDir, normalized.slice(1))
|
|
50
|
-
: normalized;
|
|
51
|
-
return ctx.workspace.storage.read(workspacePath);
|
|
52
|
-
};
|
|
53
|
-
const { map: resolved, errors } = await resolveTopicMap(mapPath, { loader, variables });
|
|
54
|
-
const countEntries = (topics) => topics.reduce((sum, entry) => sum + 1 + (Array.isArray(entry.topics) ? countEntries(entry.topics) : 0), 0);
|
|
55
|
-
return {
|
|
56
|
-
data: { map: mapPath, resolved, errors },
|
|
57
|
-
issues: errors.map((err) => ({
|
|
58
|
-
severity: "error",
|
|
59
|
-
code: `topicmap-${err.code}`,
|
|
60
|
-
message: err.message,
|
|
61
|
-
file: err.mapPath || mapPath,
|
|
62
|
-
})),
|
|
63
|
-
summary: errors.length > 0
|
|
64
|
-
? `${errors.length} error(s) resolving ${mapPath}`
|
|
65
|
-
: `${countEntries(resolved?.topics ?? [])} entries from ${mapPath}`,
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
});
|