okf-core 0.0.0-bootstrap → 1.0.0-rc.1
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/LICENSE +203 -0
- package/README.md +40 -4
- package/dist/analyze.d.ts +6 -0
- package/dist/analyze.d.ts.map +1 -0
- package/dist/analyze.js +218 -0
- package/dist/analyze.js.map +1 -0
- package/dist/changes.d.ts +6 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +81 -0
- package/dist/changes.js.map +1 -0
- package/dist/conformance.d.ts +5 -0
- package/dist/conformance.d.ts.map +1 -0
- package/dist/conformance.js +103 -0
- package/dist/conformance.js.map +1 -0
- package/dist/derive.d.ts +7 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +199 -0
- package/dist/derive.js.map +1 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +19 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/diff.d.ts +2 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +76 -0
- package/dist/diff.js.map +1 -0
- package/dist/frontmatter.d.ts +12 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +110 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/graph.d.ts +3 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +42 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/links.d.ts +10 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +104 -0
- package/dist/links.js.map +1 -0
- package/dist/markdown.d.ts +18 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +22 -0
- package/dist/markdown.js.map +1 -0
- package/dist/paths.d.ts +35 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +103 -0
- package/dist/paths.js.map +1 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +122 -0
- package/dist/search.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -5
package/dist/graph.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { byCodePoint } from "./paths.js";
|
|
2
|
+
export function buildGraph(documents) {
|
|
3
|
+
const concepts = documents
|
|
4
|
+
.filter((document) => document.kind === "concept")
|
|
5
|
+
.sort((left, right) => byCodePoint(left.path, right.path));
|
|
6
|
+
const known = new Set(concepts.map((document) => document.path));
|
|
7
|
+
const nodes = concepts.map((document) => ({
|
|
8
|
+
id: document.path,
|
|
9
|
+
path: document.path,
|
|
10
|
+
title: document.derived.title,
|
|
11
|
+
type: document.derived.type ?? "Concept",
|
|
12
|
+
description: document.derived.description,
|
|
13
|
+
status: document.derived.status,
|
|
14
|
+
trustTier: document.derived.trustTier,
|
|
15
|
+
stale: document.derived.stale,
|
|
16
|
+
tags: document.derived.tags,
|
|
17
|
+
}));
|
|
18
|
+
const relations = new Map();
|
|
19
|
+
for (const document of concepts) {
|
|
20
|
+
for (const link of document.links) {
|
|
21
|
+
if (link.kind !== "internal" || link.resolvedPath === null || !known.has(link.resolvedPath)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const key = `${document.path}\u0000${link.resolvedPath}\u0000link`;
|
|
25
|
+
relations.set(key, { source: document.path, target: link.resolvedPath, relation: "link" });
|
|
26
|
+
}
|
|
27
|
+
for (const source of document.derived.sources) {
|
|
28
|
+
if (source.resolvedPath === null || !known.has(source.resolvedPath)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const key = `${document.path}\u0000${source.resolvedPath}\u0000source`;
|
|
32
|
+
relations.set(key, { source: document.path, target: source.resolvedPath, relation: "source" });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const edges = [...relations.values()]
|
|
36
|
+
.sort((left, right) => byCodePoint(left.source, right.source) ||
|
|
37
|
+
byCodePoint(left.target, right.target) ||
|
|
38
|
+
byCodePoint(left.relation, right.relation))
|
|
39
|
+
.map((edge, index) => ({ id: `e${index}`, ...edge }));
|
|
40
|
+
return { nodes, edges };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,UAAU,UAAU,CAAC,SAAsC;IAC/D,MAAM,QAAQ,GAAG,SAAS;SACvB,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;SACjD,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,MAAM,KAAK,GAAsB,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC3D,EAAE,EAAE,QAAQ,CAAC,IAAI;QACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK;QAC7B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,SAAS;QACxC,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW;QACzC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM;QAC/B,SAAS,EAAE,QAAQ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AM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;SAClC,IAAI,CACH,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;QACtC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;QACtC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAC7C;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;IACzE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { analyzeBundle, parseBundleDocument } from "./analyze.js";
|
|
2
|
+
export { canonicalChangeJson, parseChange } from "./changes.js";
|
|
3
|
+
export { buildGraph } from "./graph.js";
|
|
4
|
+
export { extractMarkdownLinks } from "./links.js";
|
|
5
|
+
export type { ExtractLinksOptions } from "./links.js";
|
|
6
|
+
export { byCodePoint, canonicalizeBundlePath, canonicalizeOperationPath, InvalidBundlePathError, resolveWithinBundle, validateBundlePath, } from "./paths.js";
|
|
7
|
+
export type { PathResolution } from "./paths.js";
|
|
8
|
+
export { queryTerms, searchBundle } from "./search.js";
|
|
9
|
+
export { unifiedDiff } from "./diff.js";
|
|
10
|
+
export type { AnalyzeBundleOptions, ParsedDocumentResult, ParseDocumentOptions, ProfileDiagnostic, SearchPassage, SearchResult, ValidationProfile, ValidationProfileContext, } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { analyzeBundle, parseBundleDocument } from "./analyze.js";
|
|
2
|
+
export { canonicalChangeJson, parseChange } from "./changes.js";
|
|
3
|
+
export { buildGraph } from "./graph.js";
|
|
4
|
+
export { extractMarkdownLinks } from "./links.js";
|
|
5
|
+
export { byCodePoint, canonicalizeBundlePath, canonicalizeOperationPath, InvalidBundlePathError, resolveWithinBundle, validateBundlePath, } from "./paths.js";
|
|
6
|
+
export { queryTerms, searchBundle } from "./search.js";
|
|
7
|
+
export { unifiedDiff } from "./diff.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/links.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnalyzedLink } from "okf-contracts";
|
|
2
|
+
export interface ExtractLinksOptions {
|
|
3
|
+
readonly sourcePath: string;
|
|
4
|
+
readonly knownPaths?: ReadonlySet<string>;
|
|
5
|
+
readonly lineOffset?: number;
|
|
6
|
+
readonly offsetOffset?: number;
|
|
7
|
+
}
|
|
8
|
+
/** Extract CommonMark links, including reference links, from the Markdown AST. */
|
|
9
|
+
export declare function extractMarkdownLinks(markdown: string, options: ExtractLinksOptions): readonly AnalyzedLink[];
|
|
10
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAoB/D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AA2CD,kFAAkF;AAClF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,mBAAmB,GAC3B,SAAS,YAAY,EAAE,CAgEzB"}
|
package/dist/links.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
+
import { resolveWithinBundle } from "./paths.js";
|
|
3
|
+
function normalizeIdentifier(value) {
|
|
4
|
+
return value.trim().replace(/\s+/g, " ").toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
function textOf(node) {
|
|
7
|
+
if (node.type === "text" || node.type === "inlineCode") {
|
|
8
|
+
return node.value ?? "";
|
|
9
|
+
}
|
|
10
|
+
if (node.type === "image") {
|
|
11
|
+
return node.alt ?? "";
|
|
12
|
+
}
|
|
13
|
+
return (node.children ?? []).map(textOf).join("");
|
|
14
|
+
}
|
|
15
|
+
function rangeOf(node, lineOffset, offsetOffset) {
|
|
16
|
+
const start = node.position?.start;
|
|
17
|
+
const end = node.position?.end;
|
|
18
|
+
if (start?.line === undefined ||
|
|
19
|
+
start.column === undefined ||
|
|
20
|
+
start.offset === undefined ||
|
|
21
|
+
end?.line === undefined ||
|
|
22
|
+
end.column === undefined ||
|
|
23
|
+
end.offset === undefined) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
start: {
|
|
28
|
+
line: start.line + lineOffset,
|
|
29
|
+
column: start.column,
|
|
30
|
+
offset: start.offset + offsetOffset,
|
|
31
|
+
},
|
|
32
|
+
end: {
|
|
33
|
+
line: end.line + lineOffset,
|
|
34
|
+
column: end.column,
|
|
35
|
+
offset: end.offset + offsetOffset,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Extract CommonMark links, including reference links, from the Markdown AST. */
|
|
40
|
+
export function extractMarkdownLinks(markdown, options) {
|
|
41
|
+
const root = fromMarkdown(markdown);
|
|
42
|
+
const definitions = new Map();
|
|
43
|
+
const collectDefinitions = (node) => {
|
|
44
|
+
if (node.type === "definition" && node.identifier && typeof node.url === "string") {
|
|
45
|
+
definitions.set(normalizeIdentifier(node.identifier), node.url);
|
|
46
|
+
}
|
|
47
|
+
for (const child of node.children ?? []) {
|
|
48
|
+
collectDefinitions(child);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
collectDefinitions(root);
|
|
52
|
+
const result = [];
|
|
53
|
+
const visit = (node) => {
|
|
54
|
+
let href = null;
|
|
55
|
+
if (node.type === "link" && typeof node.url === "string") {
|
|
56
|
+
href = node.url;
|
|
57
|
+
}
|
|
58
|
+
else if (node.type === "linkReference" && node.identifier) {
|
|
59
|
+
href = definitions.get(normalizeIdentifier(node.identifier)) ?? null;
|
|
60
|
+
}
|
|
61
|
+
if (href !== null) {
|
|
62
|
+
const resolution = resolveWithinBundle(options.sourcePath, href);
|
|
63
|
+
const base = {
|
|
64
|
+
href,
|
|
65
|
+
text: textOf(node),
|
|
66
|
+
range: rangeOf(node, options.lineOffset ?? 0, options.offsetOffset ?? 0),
|
|
67
|
+
};
|
|
68
|
+
if (resolution.kind === "internal") {
|
|
69
|
+
result.push({
|
|
70
|
+
...base,
|
|
71
|
+
kind: "internal",
|
|
72
|
+
resolvedPath: resolution.path,
|
|
73
|
+
fragment: resolution.fragment,
|
|
74
|
+
exists: options.knownPaths?.has(resolution.path) ?? null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (resolution.kind === "fragment") {
|
|
78
|
+
result.push({
|
|
79
|
+
...base,
|
|
80
|
+
kind: "fragment",
|
|
81
|
+
resolvedPath: options.sourcePath,
|
|
82
|
+
fragment: resolution.fragment,
|
|
83
|
+
exists: true,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
result.push({
|
|
88
|
+
...base,
|
|
89
|
+
kind: resolution.kind,
|
|
90
|
+
resolvedPath: null,
|
|
91
|
+
fragment: null,
|
|
92
|
+
exists: null,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const child of node.children ?? []) {
|
|
98
|
+
visit(child);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
visit(root);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAIxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAyBjD,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AACzD,CAAC;AAED,SAAS,MAAM,CAAC,IAAe;IAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC1B,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,OAAO,CAAC,IAAe,EAAE,UAAkB,EAAE,YAAoB;IACxE,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;IAC/B,IACE,KAAK,EAAE,IAAI,KAAK,SAAS;QACzB,KAAK,CAAC,MAAM,KAAK,SAAS;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CAAC,UAAU;oBAChC,QAAQ,EAAE,UAAU,CAAC,QAAQ;oBAC7B,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC;oBACV,GAAG,IAAI;oBACP,IAAI,EAAE,UAAU,CAAC,IAAI;oBACrB,YAAY,EAAE,IAAI;oBAClB,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;iBACb,CAAC,CAAC;YACL,CAAC;YACD,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YACxC,KAAK,CAAC,KAAK,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface MarkdownHeading {
|
|
2
|
+
readonly depth: number;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
}
|
|
5
|
+
export type MarkdownBlock = {
|
|
6
|
+
readonly type: "heading";
|
|
7
|
+
readonly depth: number;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "list";
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: "other";
|
|
13
|
+
};
|
|
14
|
+
/** Return actual top-level CommonMark blocks, excluding syntax nested in code. */
|
|
15
|
+
export declare function markdownBlocks(markdown: string): readonly MarkdownBlock[];
|
|
16
|
+
/** Return actual CommonMark heading blocks, excluding fenced and indented code. */
|
|
17
|
+
export declare function markdownHeadings(markdown: string): readonly MarkdownHeading[];
|
|
18
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAS/B,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,aAAa,EAAE,CAQzE;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAE7E"}
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
+
function nodeText(node) {
|
|
3
|
+
if (node.type === "text" || node.type === "inlineCode") {
|
|
4
|
+
return node.value ?? "";
|
|
5
|
+
}
|
|
6
|
+
return (node.children ?? []).map(nodeText).join("");
|
|
7
|
+
}
|
|
8
|
+
/** Return actual top-level CommonMark blocks, excluding syntax nested in code. */
|
|
9
|
+
export function markdownBlocks(markdown) {
|
|
10
|
+
const root = fromMarkdown(markdown);
|
|
11
|
+
return (root.children ?? []).map((node) => {
|
|
12
|
+
if (node.type === "heading" && typeof node.depth === "number") {
|
|
13
|
+
return { type: "heading", depth: node.depth, text: nodeText(node) };
|
|
14
|
+
}
|
|
15
|
+
return node.type === "list" ? { type: "list" } : { type: "other" };
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Return actual CommonMark heading blocks, excluding fenced and indented code. */
|
|
19
|
+
export function markdownHeadings(markdown) {
|
|
20
|
+
return markdownBlocks(markdown).flatMap((block) => block.type === "heading" ? [block] : []);
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CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class InvalidBundlePathError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export type PathResolution = {
|
|
5
|
+
readonly kind: "fragment";
|
|
6
|
+
readonly fragment: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "external";
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "escape";
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "invalid";
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "internal";
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly fragment: string | null;
|
|
17
|
+
};
|
|
18
|
+
/** Code-point ordering is stable across runtimes and locales. */
|
|
19
|
+
export declare function byCodePoint(left: string, right: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Validate one confined Bundle-relative path and return its exact authored bytes.
|
|
22
|
+
*
|
|
23
|
+
* Unicode and whitespace are storage-key data, so this function never trims or
|
|
24
|
+
* normalizes them. Storage adapters decide separately whether a particular
|
|
25
|
+
* operation requires a `.md` suffix.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateBundlePath(value: string): string;
|
|
28
|
+
/** Alias that emphasizes that the validated storage key is the canonical value. */
|
|
29
|
+
export declare function canonicalizeBundlePath(value: string): string;
|
|
30
|
+
/** Validate a change target, preserving its exact key and requiring the OKF suffix. */
|
|
31
|
+
export declare function canonicalizeOperationPath(value: string): string;
|
|
32
|
+
export declare function isSafeMarkdownPath(path: string): boolean;
|
|
33
|
+
/** Resolve an authored Markdown destination without ever addressing outside one bundle. */
|
|
34
|
+
export declare function resolveWithinBundle(source: string, href: string): PathResolution;
|
|
35
|
+
//#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EME = /^[A-Za-z][A-Za-z0-9+.-]*:/;
|
|
2
|
+
const WINDOWS_ABSOLUTE = /^[A-Za-z]:\//;
|
|
3
|
+
export class InvalidBundlePathError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "InvalidBundlePathError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Code-point ordering is stable across runtimes and locales. */
|
|
10
|
+
export function byCodePoint(left, right) {
|
|
11
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Validate one confined Bundle-relative path and return its exact authored bytes.
|
|
15
|
+
*
|
|
16
|
+
* Unicode and whitespace are storage-key data, so this function never trims or
|
|
17
|
+
* normalizes them. Storage adapters decide separately whether a particular
|
|
18
|
+
* operation requires a `.md` suffix.
|
|
19
|
+
*/
|
|
20
|
+
export function validateBundlePath(value) {
|
|
21
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
22
|
+
throw new InvalidBundlePathError("bundle path must not be empty");
|
|
23
|
+
}
|
|
24
|
+
if (value.includes("\0") || value.includes("\\")) {
|
|
25
|
+
throw new InvalidBundlePathError(`unsafe bundle path: ${value}`);
|
|
26
|
+
}
|
|
27
|
+
if (value.startsWith("/") || WINDOWS_ABSOLUTE.test(value)) {
|
|
28
|
+
throw new InvalidBundlePathError(`bundle path must be relative: ${value}`);
|
|
29
|
+
}
|
|
30
|
+
const segments = value.split("/");
|
|
31
|
+
if (segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
32
|
+
throw new InvalidBundlePathError(`unsafe bundle path: ${value}`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
/** Alias that emphasizes that the validated storage key is the canonical value. */
|
|
37
|
+
export function canonicalizeBundlePath(value) {
|
|
38
|
+
return validateBundlePath(value);
|
|
39
|
+
}
|
|
40
|
+
/** Validate a change target, preserving its exact key and requiring the OKF suffix. */
|
|
41
|
+
export function canonicalizeOperationPath(value) {
|
|
42
|
+
const path = validateBundlePath(value);
|
|
43
|
+
if (!path.endsWith(".md")) {
|
|
44
|
+
throw new InvalidBundlePathError(`OKF operation path must end in .md: ${path}`);
|
|
45
|
+
}
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
export function isSafeMarkdownPath(path) {
|
|
49
|
+
try {
|
|
50
|
+
return canonicalizeOperationPath(path) === path;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Resolve an authored Markdown destination without ever addressing outside one bundle. */
|
|
57
|
+
export function resolveWithinBundle(source, href) {
|
|
58
|
+
let value = href.trim();
|
|
59
|
+
if (!value) {
|
|
60
|
+
return { kind: "invalid" };
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
value = decodeURIComponent(value);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { kind: "invalid" };
|
|
67
|
+
}
|
|
68
|
+
if (value.startsWith("#")) {
|
|
69
|
+
return { kind: "fragment", fragment: value.slice(1) };
|
|
70
|
+
}
|
|
71
|
+
if (SCHEME.test(value) || value.startsWith("//")) {
|
|
72
|
+
return { kind: "external" };
|
|
73
|
+
}
|
|
74
|
+
const hash = value.indexOf("#");
|
|
75
|
+
const query = value.indexOf("?");
|
|
76
|
+
const end = [hash, query].filter((index) => index >= 0).reduce((a, b) => Math.min(a, b), value.length);
|
|
77
|
+
const clean = value.slice(0, end);
|
|
78
|
+
const fragment = hash >= 0 ? value.slice(hash + 1) : null;
|
|
79
|
+
if (!clean) {
|
|
80
|
+
return fragment === null ? { kind: "invalid" } : { kind: "fragment", fragment };
|
|
81
|
+
}
|
|
82
|
+
const base = clean.startsWith("/") ? [] : source.split("/").slice(0, -1);
|
|
83
|
+
const resolved = [];
|
|
84
|
+
for (const segment of [...base, ...clean.replace(/^\/+/, "").split("/")]) {
|
|
85
|
+
if (!segment || segment === ".") {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (segment === "..") {
|
|
89
|
+
if (resolved.length === 0) {
|
|
90
|
+
return { kind: "escape" };
|
|
91
|
+
}
|
|
92
|
+
resolved.pop();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (segment.includes("\\")) {
|
|
96
|
+
return { kind: "invalid" };
|
|
97
|
+
}
|
|
98
|
+
resolved.push(segment);
|
|
99
|
+
}
|
|
100
|
+
const path = resolved.join("/");
|
|
101
|
+
return path ? { kind: "internal", path, fragment } : { kind: "invalid" };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAC3C,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AASD,iEAAiE;AACjE,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,sBAAsB,CAAC,+BAA+B,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,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AAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC3E,CAAC"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BundleAnalysis } from "okf-contracts";
|
|
2
|
+
import type { SearchResult } from "./types.js";
|
|
3
|
+
export declare function queryTerms(query: string): readonly string[];
|
|
4
|
+
export declare function searchBundle(analysis: BundleAnalysis, query: string, limit?: number): SearchResult;
|
|
5
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAC;AA8B9D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAI3D;AA6CD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,YAAY,CAyD9F"}
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { markdownHeadings } from "./markdown.js";
|
|
2
|
+
import { byCodePoint } from "./paths.js";
|
|
3
|
+
const TOKEN = /[0-9a-z]+/g;
|
|
4
|
+
const FRONTMATTER = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
5
|
+
const FRONTMATTER_FIELD = /^(?:title|description)[ \t]*:[ \t]*(.+?)[ \t]*$/gm;
|
|
6
|
+
const STOPWORDS = new Set("a an and are as at be by for from how in is it its of on or that the this to was what when where which why with".split(" "));
|
|
7
|
+
const EMPHASIS_WEIGHT = 3;
|
|
8
|
+
const PHRASE_WEIGHT = 8;
|
|
9
|
+
const MAX_PASSAGES_PER_DOCUMENT = 3;
|
|
10
|
+
function tokenize(text) {
|
|
11
|
+
return text.toLowerCase().match(TOKEN) ?? [];
|
|
12
|
+
}
|
|
13
|
+
function normalize(text) {
|
|
14
|
+
return text.toLowerCase().split(/\s+/).filter(Boolean).join(" ");
|
|
15
|
+
}
|
|
16
|
+
function counts(tokens) {
|
|
17
|
+
const result = new Map();
|
|
18
|
+
for (const token of tokens) {
|
|
19
|
+
result.set(token, (result.get(token) ?? 0) + 1);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
export function queryTerms(query) {
|
|
24
|
+
const tokens = tokenize(query);
|
|
25
|
+
const meaningful = tokens.filter((token) => !STOPWORDS.has(token));
|
|
26
|
+
return meaningful.length > 0 ? meaningful : tokens;
|
|
27
|
+
}
|
|
28
|
+
function analyze(text, path) {
|
|
29
|
+
const emphasisSource = [path.replace(/[/-]/g, " ")];
|
|
30
|
+
let body = text;
|
|
31
|
+
const frontmatter = FRONTMATTER.exec(text);
|
|
32
|
+
if (frontmatter) {
|
|
33
|
+
for (const field of (frontmatter[1] ?? "").matchAll(FRONTMATTER_FIELD)) {
|
|
34
|
+
emphasisSource.push(field[1] ?? "");
|
|
35
|
+
}
|
|
36
|
+
body = text.slice(frontmatter[0].length);
|
|
37
|
+
}
|
|
38
|
+
for (const heading of markdownHeadings(body)) {
|
|
39
|
+
emphasisSource.push(heading.text);
|
|
40
|
+
}
|
|
41
|
+
return { emphasis: counts(tokenize(emphasisSource.join(" "))), body: counts(tokenize(body)) };
|
|
42
|
+
}
|
|
43
|
+
function passagesFor(text, terms, phrase, limit) {
|
|
44
|
+
const lines = text.split(/\r?\n/);
|
|
45
|
+
const scored = [];
|
|
46
|
+
lines.forEach((line, index) => {
|
|
47
|
+
const stripped = line.trim();
|
|
48
|
+
if (!stripped)
|
|
49
|
+
return;
|
|
50
|
+
const present = new Set(tokenize(stripped));
|
|
51
|
+
let hits = 0;
|
|
52
|
+
for (const term of terms)
|
|
53
|
+
if (present.has(term))
|
|
54
|
+
hits += 1;
|
|
55
|
+
const exact = phrase.length > 0 && normalize(stripped).includes(phrase);
|
|
56
|
+
if (hits > 0 || exact) {
|
|
57
|
+
scored.push({ weight: hits + (exact ? PHRASE_WEIGHT : 0), line: index + 1, snippet: stripped.slice(0, 500) });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (scored.length === 0) {
|
|
61
|
+
const first = lines.findIndex((line) => line.trim().length > 0);
|
|
62
|
+
return first < 0 ? [] : [{ line: first + 1, snippet: (lines[first] ?? "").trim().slice(0, 500) }];
|
|
63
|
+
}
|
|
64
|
+
scored.sort((left, right) => right.weight - left.weight || left.line - right.line);
|
|
65
|
+
return scored.slice(0, limit).map(({ line, snippet }) => ({ line, snippet }));
|
|
66
|
+
}
|
|
67
|
+
export function searchBundle(analysis, query, limit = 20) {
|
|
68
|
+
const safeLimit = Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 20;
|
|
69
|
+
const terms = queryTerms(query);
|
|
70
|
+
const distinct = new Set(terms);
|
|
71
|
+
const phrase = distinct.size > 1 ? normalize(query) : "";
|
|
72
|
+
const entries = analysis.documents.map((document) => ({
|
|
73
|
+
document,
|
|
74
|
+
analysis: analyze(document.content, document.path),
|
|
75
|
+
phraseHits: phrase ? normalize(document.content).split(phrase).length - 1 : 0,
|
|
76
|
+
}));
|
|
77
|
+
const frequency = new Map();
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
for (const token of new Set([...entry.analysis.emphasis.keys(), ...entry.analysis.body.keys()])) {
|
|
80
|
+
frequency.set(token, (frequency.get(token) ?? 0) + 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const idf = new Map();
|
|
84
|
+
for (const term of distinct) {
|
|
85
|
+
idf.set(term, Math.log(1 + entries.length / (1 + (frequency.get(term) ?? 0))));
|
|
86
|
+
}
|
|
87
|
+
const ranked = entries
|
|
88
|
+
.map((entry) => {
|
|
89
|
+
let total = 0;
|
|
90
|
+
let matched = 0;
|
|
91
|
+
for (const term of distinct) {
|
|
92
|
+
const amount = (entry.analysis.body.get(term) ?? 0) + EMPHASIS_WEIGHT * (entry.analysis.emphasis.get(term) ?? 0);
|
|
93
|
+
if (amount > 0) {
|
|
94
|
+
matched += 1;
|
|
95
|
+
total += (idf.get(term) ?? 0) * (1 + Math.log(amount));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const coverage = distinct.size === 0 ? 0 : matched / distinct.size;
|
|
99
|
+
return { ...entry, score: total * coverage * coverage + PHRASE_WEIGHT * entry.phraseHits };
|
|
100
|
+
})
|
|
101
|
+
.filter((entry) => entry.score > 0)
|
|
102
|
+
.sort((left, right) => right.score - left.score || byCodePoint(left.document.path, right.document.path));
|
|
103
|
+
const matches = [];
|
|
104
|
+
let truncated = false;
|
|
105
|
+
for (const entry of ranked) {
|
|
106
|
+
if (matches.length >= safeLimit) {
|
|
107
|
+
truncated = true;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
const budget = Math.min(MAX_PASSAGES_PER_DOCUMENT, safeLimit - matches.length);
|
|
111
|
+
for (const passage of passagesFor(entry.document.content, distinct, phrase, budget)) {
|
|
112
|
+
matches.push({
|
|
113
|
+
path: entry.document.path,
|
|
114
|
+
line: passage.line,
|
|
115
|
+
snippet: passage.snippet,
|
|
116
|
+
score: Math.round(entry.score * 10_000) / 10_000,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { terms: [...terms], matches, truncated };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,MAAM,KA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AE,KAAK,CAAC,QAAQ,CAAC,IAAI;gBACzB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,MAAM;aACjD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AnalyzedDocument, BundleGraph, Diagnostic, DiagnosticGroups } from "okf-contracts";
|
|
2
|
+
export interface ProfileDiagnostic {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly severity?: "error" | "warning" | "info";
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly range?: Diagnostic["range"];
|
|
8
|
+
}
|
|
9
|
+
export interface ValidationProfileContext {
|
|
10
|
+
readonly okfVersion: string | null;
|
|
11
|
+
readonly documents: readonly AnalyzedDocument[];
|
|
12
|
+
readonly graph: BundleGraph;
|
|
13
|
+
readonly diagnostics: Pick<DiagnosticGroups, "core" | "guidance">;
|
|
14
|
+
readonly today: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface ValidationProfile {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
validate(context: ValidationProfileContext): readonly ProfileDiagnostic[];
|
|
19
|
+
}
|
|
20
|
+
export interface AnalyzeBundleOptions {
|
|
21
|
+
/** Deterministic ISO date used for staleness. Omit rather than consulting the clock. */
|
|
22
|
+
readonly today?: string;
|
|
23
|
+
readonly profile?: ValidationProfile;
|
|
24
|
+
}
|
|
25
|
+
export interface ParsedDocumentResult {
|
|
26
|
+
readonly document: AnalyzedDocument;
|
|
27
|
+
readonly diagnostics: Pick<DiagnosticGroups, "core" | "guidance">;
|
|
28
|
+
}
|
|
29
|
+
export interface ParseDocumentOptions {
|
|
30
|
+
readonly knownPaths?: ReadonlySet<string>;
|
|
31
|
+
readonly today?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SearchPassage {
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly line: number;
|
|
36
|
+
readonly snippet: string;
|
|
37
|
+
readonly score: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SearchResult {
|
|
40
|
+
readonly terms: readonly string[];
|
|
41
|
+
readonly matches: readonly SearchPassage[];
|
|
42
|
+
readonly truncated: boolean;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CA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