@rse/specbook 1.2.3 → 1.2.5
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/README.md +124 -204
- package/dst/specbook-cmd-export.js +4 -1
- package/dst/specbook-config.js +6 -6
- package/dst/specbook-diagram.js +154 -22
- package/dst/specbook-export-ast.js +1 -1
- package/dst/specbook-export-common.js +1 -1
- package/dst/specbook-export-html.css +178 -5
- package/dst/specbook-export-html.d.ts +1 -1
- package/dst/specbook-export-html.js +304 -42
- package/dst/specbook-export-md.js +9 -9
- package/dst/specbook-export-pdf.js +37 -13
- package/dst/specbook-format-schema.d.ts +11 -1
- package/dst/specbook-format-schema.js +12 -2
- package/dst/specbook-format-spec.d.ts +1 -1
- package/dst/specbook-format-spec.js +2 -2
- package/dst/specbook-format.md +80 -9
- package/dst/specbook-format.yaml +294 -197
- package/dst/specbook-link.js +2 -2
- package/dst/specbook-parse-semantic.js +22 -22
- package/dst/specbook-parse-syntax.js +5 -5
- package/dst/specbook-parse.js +1 -1
- package/package.json +6 -6
package/dst/specbook-link.js
CHANGED
|
@@ -55,7 +55,7 @@ export const buildLinkIndex = (specification) => {
|
|
|
55
55
|
const walk = (object, parent) => {
|
|
56
56
|
const node = { object, parent, pos: index.length, name: plainText(object.name) };
|
|
57
57
|
index.push(node);
|
|
58
|
-
for (const child of object.
|
|
58
|
+
for (const child of object.children)
|
|
59
59
|
walk(child, node);
|
|
60
60
|
};
|
|
61
61
|
for (const artifact of specification.artifacts)
|
|
@@ -173,7 +173,7 @@ export const resolveUnique = (index, reference, from) => {
|
|
|
173
173
|
};
|
|
174
174
|
/* derive the fully-qualified anchor path of every object: the
|
|
175
175
|
"<kind>-<id>" segments (whitespace in kinds dashed) of the ancestor
|
|
176
|
-
chain joined with "." (the index lists parents before
|
|
176
|
+
chain joined with "." (the index lists parents before children) */
|
|
177
177
|
export const anchorPaths = (index) => {
|
|
178
178
|
const paths = new Map();
|
|
179
179
|
for (const node of index) {
|
|
@@ -129,11 +129,11 @@ const parenProp = (object, props) => {
|
|
|
129
129
|
values matching the regexp or enum expression of the flag), where
|
|
130
130
|
a kind without any sibling fails a present flag, too, but only for
|
|
131
131
|
an optional kind, as the missing-kind check reports a required one */
|
|
132
|
-
const checkSiblingFlags = (ctx, object,
|
|
132
|
+
const checkSiblingFlags = (ctx, object, children, meta) => {
|
|
133
133
|
const marker = (flag) => flag === undefined || flag === false ? undefined :
|
|
134
134
|
{ filter: typeof flag === "string" ? compileValueExpr(flag) : undefined };
|
|
135
|
-
for (const child of
|
|
136
|
-
const siblings = object.
|
|
135
|
+
for (const child of children) {
|
|
136
|
+
const siblings = object.children.filter((c) => c.kind === child.kind);
|
|
137
137
|
for (const prop of child.props ?? []) {
|
|
138
138
|
const unique = marker(prop.unique);
|
|
139
139
|
const present = marker(prop.present);
|
|
@@ -165,7 +165,7 @@ const checkSiblingFlags = (ctx, object, childs, meta) => {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
/* validate a single object (and recursively its
|
|
168
|
+
/* validate a single object (and recursively its children) against its schema */
|
|
169
169
|
const validateObject = (ctx, object, schema, level) => {
|
|
170
170
|
const meta = ctx.metaOf(object);
|
|
171
171
|
const props = schema.props ?? [];
|
|
@@ -199,10 +199,10 @@ const validateObject = (ctx, object, schema, level) => {
|
|
|
199
199
|
if (!props.some((p) => p.name === property.key))
|
|
200
200
|
ctx.diagnose(meta.file, ctx.propMeta.get(property)?.line ?? meta.line, `unknown property "${property.key}" on ${object.kind} "${object.name}"`);
|
|
201
201
|
/* check the configured child objects */
|
|
202
|
-
const
|
|
203
|
-
for (const child of object.
|
|
202
|
+
const children = schema.children ?? [];
|
|
203
|
+
for (const child of object.children) {
|
|
204
204
|
const childMeta = ctx.metaOf(child);
|
|
205
|
-
const childSchema =
|
|
205
|
+
const childSchema = children.find((c) => c.kind === child.kind);
|
|
206
206
|
if (childSchema === undefined) {
|
|
207
207
|
ctx.diagnose(childMeta.file, childMeta.line, `unknown object kind "${child.kind}" below ${object.kind} "${object.name}"`);
|
|
208
208
|
continue;
|
|
@@ -210,20 +210,20 @@ const validateObject = (ctx, object, schema, level) => {
|
|
|
210
210
|
validateObject(ctx, child, childSchema, level + 1);
|
|
211
211
|
}
|
|
212
212
|
/* check the sibling-scoped property flags of the child kinds */
|
|
213
|
-
checkSiblingFlags(ctx, object,
|
|
213
|
+
checkSiblingFlags(ctx, object, children, meta);
|
|
214
214
|
/* report the configured child object kinds which are missing */
|
|
215
|
-
for (const child of
|
|
215
|
+
for (const child of children)
|
|
216
216
|
if (child.optional !== true
|
|
217
|
-
&& !object.
|
|
217
|
+
&& !object.children.some((c) => c.kind === child.kind))
|
|
218
218
|
ctx.diagnose(meta.file, meta.line, `required object kind "${child.kind}" missing below ${object.kind} "${object.name}"`);
|
|
219
|
-
/* order the
|
|
219
|
+
/* order the children and properties exactly along the schema
|
|
220
220
|
definition (the sort is stable, so objects of the same kind
|
|
221
221
|
and unknown items keep their document order) */
|
|
222
222
|
const kindPos = (kind) => {
|
|
223
|
-
const i =
|
|
224
|
-
return i >= 0 ? i :
|
|
223
|
+
const i = children.findIndex((c) => c.kind === kind);
|
|
224
|
+
return i >= 0 ? i : children.length;
|
|
225
225
|
};
|
|
226
|
-
object.
|
|
226
|
+
object.children.sort((a, b) => kindPos(a.kind) - kindPos(b.kind));
|
|
227
227
|
const propPos = (key) => {
|
|
228
228
|
const i = props.findIndex((p) => p.name === key);
|
|
229
229
|
return i >= 0 ? i : props.length;
|
|
@@ -242,8 +242,8 @@ export const collectSchemas = (specification, config) => {
|
|
|
242
242
|
const schemas = new Map();
|
|
243
243
|
const walk = (object, schema) => {
|
|
244
244
|
schemas.set(object, schema);
|
|
245
|
-
for (const child of object.
|
|
246
|
-
const childSchema = (schema.
|
|
245
|
+
for (const child of object.children) {
|
|
246
|
+
const childSchema = (schema.children ?? []).find((c) => c.kind === child.kind);
|
|
247
247
|
if (childSchema !== undefined)
|
|
248
248
|
walk(child, childSchema);
|
|
249
249
|
}
|
|
@@ -284,7 +284,7 @@ const checkIds = (ctx, objects) => {
|
|
|
284
284
|
const meta = ctx.metaOf(object);
|
|
285
285
|
ctx.diagnose(meta.file, meta.line, `id "${object.id}" of ${object.kind} "${object.name}" collides with preceding ${object.kind} "${first.name}"`);
|
|
286
286
|
}
|
|
287
|
-
checkIds(ctx, object.
|
|
287
|
+
checkIds(ctx, object.children);
|
|
288
288
|
}
|
|
289
289
|
};
|
|
290
290
|
/* the objects a property of an object references (resolved and
|
|
@@ -317,7 +317,7 @@ const checkAutomata = (ctx, schemas) => {
|
|
|
317
317
|
const automaton = schema.automaton;
|
|
318
318
|
if (automaton === undefined)
|
|
319
319
|
continue;
|
|
320
|
-
const nodes = object.
|
|
320
|
+
const nodes = object.children.filter((child) => child.kind === automaton.nodes);
|
|
321
321
|
const nodeSet = new Set(nodes);
|
|
322
322
|
const flagged = (node, name) => {
|
|
323
323
|
const property = findProp(ctx, node, name);
|
|
@@ -329,7 +329,7 @@ const checkAutomata = (ctx, schemas) => {
|
|
|
329
329
|
the node set is skipped, as the property checks report it) */
|
|
330
330
|
const succs = new Map(nodes.map((node) => [node, new Set()]));
|
|
331
331
|
const preds = new Map(nodes.map((node) => [node, new Set()]));
|
|
332
|
-
for (const edge of object.
|
|
332
|
+
for (const edge of object.children.filter((child) => child.kind === automaton.edges)) {
|
|
333
333
|
const source = referencedObjects(ctx, edge, automaton.source)[0];
|
|
334
334
|
const target = referencedObjects(ctx, edge, automaton.target)[0];
|
|
335
335
|
if (source !== undefined && target !== undefined && nodeSet.has(source) && nodeSet.has(target)) {
|
|
@@ -446,7 +446,7 @@ const checkReferenced = (ctx, specification, schemas) => {
|
|
|
446
446
|
if (target !== undefined && !chain.includes(target))
|
|
447
447
|
referrers.set(target, (referrers.get(target) ?? new Set()).add(object));
|
|
448
448
|
}
|
|
449
|
-
object.
|
|
449
|
+
object.children.forEach(walk);
|
|
450
450
|
};
|
|
451
451
|
for (const artifact of specification.artifacts)
|
|
452
452
|
artifact.objects.forEach(walk);
|
|
@@ -494,7 +494,7 @@ export const validate = (ctx, specification, config) => {
|
|
|
494
494
|
references all over the corpus */
|
|
495
495
|
if (object.paren !== undefined && object.anchor === undefined && !ctx.parenProps.has(object))
|
|
496
496
|
assignId(ctx.linkIndex, object, object.paren);
|
|
497
|
-
object.
|
|
497
|
+
object.children.forEach(promote);
|
|
498
498
|
};
|
|
499
499
|
for (const artifact of specification.artifacts)
|
|
500
500
|
artifact.objects.forEach(promote);
|
|
@@ -554,7 +554,7 @@ export const validateReferences = (ctx, specification) => {
|
|
|
554
554
|
if (object.description.rationale !== undefined)
|
|
555
555
|
check(object, object.description.rationale, meta.file, meta.line);
|
|
556
556
|
}
|
|
557
|
-
object.
|
|
557
|
+
object.children.forEach(walk);
|
|
558
558
|
};
|
|
559
559
|
for (const artifact of specification.artifacts)
|
|
560
560
|
artifact.objects.forEach(walk);
|
|
@@ -150,7 +150,7 @@ const embed = (ctx, object, file) => {
|
|
|
150
150
|
load(object.description, object.description.description, line);
|
|
151
151
|
for (const property of object.properties)
|
|
152
152
|
load(property, property.value, ctx.propMeta.get(property)?.line ?? line);
|
|
153
|
-
for (const child of object.
|
|
153
|
+
for (const child of object.children)
|
|
154
154
|
embed(ctx, child, file);
|
|
155
155
|
};
|
|
156
156
|
/* parse an unordered list of key-values and/or concise-format objects */
|
|
@@ -229,7 +229,7 @@ const parseConcise = (ctx, item, parent, file, line, group) => {
|
|
|
229
229
|
id: anchor ?? slugify(name),
|
|
230
230
|
name,
|
|
231
231
|
properties: [],
|
|
232
|
-
|
|
232
|
+
children: []
|
|
233
233
|
};
|
|
234
234
|
if (anchor !== undefined)
|
|
235
235
|
object.anchor = anchor;
|
|
@@ -267,7 +267,7 @@ const parseConcise = (ctx, item, parent, file, line, group) => {
|
|
|
267
267
|
ctx.diagnose(file, subLine, `nested ordered list below ${kind} "${name}" ignored`);
|
|
268
268
|
subLine += (sub.raw.match(/\n/g) ?? []).length;
|
|
269
269
|
}
|
|
270
|
-
parent.
|
|
270
|
+
parent.children.push(object);
|
|
271
271
|
};
|
|
272
272
|
/* parse a heading token into either a grouping container (e.g. "### STATE",
|
|
273
273
|
collecting objects of its kind below the parent object) or a new object
|
|
@@ -298,7 +298,7 @@ const parseHeading = (ctx, token, state, stamps, file, line) => {
|
|
|
298
298
|
id: heading.id ?? (depth === 1 ? heading.paren : undefined) ?? slugify(heading.name),
|
|
299
299
|
name: heading.name,
|
|
300
300
|
properties: [],
|
|
301
|
-
|
|
301
|
+
children: []
|
|
302
302
|
};
|
|
303
303
|
if (heading.id !== undefined)
|
|
304
304
|
object.anchor = heading.id;
|
|
@@ -310,7 +310,7 @@ const parseHeading = (ctx, token, state, stamps, file, line) => {
|
|
|
310
310
|
if (parent === undefined)
|
|
311
311
|
state.artifacts.push({ ...stamps, objects: [object] });
|
|
312
312
|
else
|
|
313
|
-
parent.
|
|
313
|
+
parent.children.push(object);
|
|
314
314
|
state.stack.length = depth - 1;
|
|
315
315
|
state.stack[depth - 1] = object;
|
|
316
316
|
state.current = object;
|
package/dst/specbook-parse.js
CHANGED
|
@@ -51,7 +51,7 @@ export const specStatistics = (specification) => {
|
|
|
51
51
|
texts.push(object.description.description, object.description.rationale ?? "");
|
|
52
52
|
for (const text of texts)
|
|
53
53
|
links += (plainText(text).match(referenceRegex) ?? []).length;
|
|
54
|
-
object.
|
|
54
|
+
object.children.forEach(walk);
|
|
55
55
|
};
|
|
56
56
|
for (const artifact of specification.artifacts)
|
|
57
57
|
artifact.objects.forEach(walk);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rse/specbook",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"publishConfig": { "access": "public" },
|
|
5
5
|
"description": "Markdown-based Specification Format (API, CLI and MCP service)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"pdf-lib": "1.17.1",
|
|
25
25
|
"subset-font": "2.7.0",
|
|
26
26
|
"@rse/mrcs": "0.9.2",
|
|
27
|
-
"@rse/gradia": "1.1
|
|
27
|
+
"@rse/gradia": "1.2.1",
|
|
28
28
|
"@toon-format/toon": "4.1.1",
|
|
29
29
|
"valibot": "1.4.2",
|
|
30
30
|
"nunjucks": "3.2.4",
|
|
31
31
|
"@rse/nunjucks-addons": "2.2.0",
|
|
32
32
|
"textframe": "1.2.1",
|
|
33
|
-
"@swc/html": "1.16.
|
|
33
|
+
"@swc/html": "1.16.2",
|
|
34
34
|
"tokenizr": "2.2.1",
|
|
35
|
-
"playwright": "1.
|
|
35
|
+
"playwright": "1.63.0",
|
|
36
36
|
"source-code-error": "1.2.0",
|
|
37
37
|
"commander": "15.0.0",
|
|
38
38
|
"chalk": "6.0.0",
|
|
39
|
-
"
|
|
39
|
+
"chokidar5": "npm:chokidar@5.0.0",
|
|
40
40
|
"glob": "13.0.6",
|
|
41
41
|
"es-toolkit": "1.52.0",
|
|
42
42
|
"fastify": "5.12.3",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"source-code-pro": "2.42.0",
|
|
65
65
|
"@fontsource/noto-sans-symbols": "5.3.0",
|
|
66
66
|
"postcss": "8.5.28",
|
|
67
|
-
"postcss-cli": "
|
|
67
|
+
"postcss-cli": "12.0.0",
|
|
68
68
|
"postcss-url": "10.1.4",
|
|
69
69
|
"stylus": "0.64.0",
|
|
70
70
|
"@rse/stx": "1.1.6",
|