@okforest/okf 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { Nodes
|
|
1
|
+
import { _ as TreeSettings, a as FootnoteReference, b as Verification, c as MarkdownFile, d as ReservedFile, f as Source, g as TreeOutline, h as TreeFile, i as DiagramSettings, l as MermaidRenderer, m as Tree, n as Concept, o as KeyPath, p as Status, r as Diagnostic, s as Link, t as CodeBlock, u as Position, v as TrustTier, y as TypeSchema } from "./types-4j7GeRZ-.mjs";
|
|
2
|
+
import { Nodes } from "mdast";
|
|
3
3
|
/** Depth-first, document-order walk over an mdast tree. */
|
|
4
4
|
export declare function visit(node: Nodes, fn: (node: Nodes) => void): void;
|
|
5
5
|
/** Strip a byte-order mark and normalize line endings to LF. */
|
|
@@ -49,10 +49,17 @@ export declare function buildInventory(tree: Tree, options?: {
|
|
|
49
49
|
* - case and punctuation: `SaaS Application`, `saas-application`;
|
|
50
50
|
* - singular and plural: `Policy`, `Policies`;
|
|
51
51
|
* - spelling: an edit distance of 1 (values of 5+ characters) or 2 (10+),
|
|
52
|
-
*
|
|
52
|
+
* two letters swapped counting as one (`Metirc`), unless one value
|
|
53
|
+
* contains the other, or their digits differ (`q1-goals`, `q2-goals`).
|
|
53
54
|
*/
|
|
54
55
|
export declare function findNearDuplicates(counts: readonly Count[], field: NearDuplicates["field"]): NearDuplicates[];
|
|
55
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Edit distance: insertions, deletions, substitutions, and swaps of two
|
|
58
|
+
* neighbouring characters (`Metirc`, `Metric`), each one edit (optimal
|
|
59
|
+
* string alignment). Stops early once it exceeds `limit`: a row's smallest
|
|
60
|
+
* value is at most one more than the row before's, so once a row passes the
|
|
61
|
+
* limit, no later row, swaps included, comes back under it.
|
|
62
|
+
*/
|
|
56
63
|
export declare function editDistance(a: string, b: string, limit: number): number;
|
|
57
64
|
/** Convert a glob (relative to the tree root) to a regular expression.
|
|
58
65
|
* `*` and `?` stay within one path segment, `**` crosses segments, and a
|
|
@@ -60,6 +67,9 @@ export declare function editDistance(a: string, b: string, limit: number): numbe
|
|
|
60
67
|
export declare function globToRegExp(glob: string): RegExp;
|
|
61
68
|
/** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
|
|
62
69
|
export declare const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
70
|
+
/** What may draw a bundle's ```mermaid blocks (`diagrams.mermaid.renderer`
|
|
71
|
+
* in its settings). */
|
|
72
|
+
export declare const MERMAID_RENDERERS: readonly MermaidRenderer[];
|
|
63
73
|
/** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
|
|
64
74
|
* type (an OKForest convention, not OKF). */
|
|
65
75
|
export declare const TYPES_FOLDER = ".okforest/types/";
|
|
@@ -103,4 +113,4 @@ export declare function deriveTrustTier(verified: readonly Verification[]): Trus
|
|
|
103
113
|
export declare function isStaleAt(staleAfter: string | undefined, now: Date): boolean;
|
|
104
114
|
export declare function normalizeSources(value: unknown): Source[];
|
|
105
115
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
106
|
-
export type { CodeBlock, Concept, Count, Diagnostic, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, NearDuplicates, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, TypeSchema, Verification };
|
|
116
|
+
export type { CodeBlock, Concept, Count, Diagnostic, DiagramSettings, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, MermaidRenderer, NearDuplicates, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, TypeSchema, Verification };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as normalizeText, a as isTypeSchemaPath, d as deriveTrustTier, f as isStaleAt, g as globToRegExp, h as normalizeVerified, l as readTypeSchema, m as normalizeSources, n as SETTINGS_PATH, o as outlineTree, p as isStatus, r as TYPES_FOLDER, s as parseTree, t as MERMAID_RENDERERS, u as deriveStatus, v as isRecord, y as visit } from "./tree-cHPdftiv.mjs";
|
|
2
2
|
// src/fields.ts
|
|
3
3
|
/** The frontmatter keys OKF defines (§4.1, §5, §10.2). A type's schema
|
|
4
4
|
* describes the type's own fields, so these are left out of it unless it
|
|
@@ -84,7 +84,8 @@ function sorted(map) {
|
|
|
84
84
|
* - case and punctuation: `SaaS Application`, `saas-application`;
|
|
85
85
|
* - singular and plural: `Policy`, `Policies`;
|
|
86
86
|
* - spelling: an edit distance of 1 (values of 5+ characters) or 2 (10+),
|
|
87
|
-
*
|
|
87
|
+
* two letters swapped counting as one (`Metirc`), unless one value
|
|
88
|
+
* contains the other, or their digits differ (`q1-goals`, `q2-goals`).
|
|
88
89
|
*/
|
|
89
90
|
function findNearDuplicates(counts, field) {
|
|
90
91
|
const parent = counts.map((_, i) => i);
|
|
@@ -112,7 +113,7 @@ function findNearDuplicates(counts, field) {
|
|
|
112
113
|
if (a === "" || b === "") continue;
|
|
113
114
|
if (a === b) union(i, j, "case-or-punctuation");
|
|
114
115
|
else if (singular[i] === singular[j]) union(i, j, "plural");
|
|
115
|
-
else if (!a.includes(b) && !b.includes(a)) {
|
|
116
|
+
else if (!a.includes(b) && !b.includes(a) && digits(a) === digits(b)) {
|
|
116
117
|
const shortest = Math.min(a.length, b.length);
|
|
117
118
|
const allowed = shortest >= 10 ? 2 : shortest >= 5 ? 1 : 0;
|
|
118
119
|
if (allowed > 0 && editDistance(a, b, allowed) <= allowed) union(i, j, "spelling");
|
|
@@ -134,28 +135,38 @@ function findNearDuplicates(counts, field) {
|
|
|
134
135
|
reasons: order.filter((r) => reasons.get(root)?.has(r))
|
|
135
136
|
}));
|
|
136
137
|
}
|
|
138
|
+
const digits = (value) => value.replace(/\D/g, "");
|
|
137
139
|
function singularize(word) {
|
|
138
140
|
if (word.endsWith("ies") && word.length > 4) return `${word.slice(0, -3)}y`;
|
|
139
141
|
if (/(?:ses|xes|zes|ches|shes)$/.test(word)) return word.slice(0, -2);
|
|
140
142
|
if (word.endsWith("s") && !word.endsWith("ss") && word.length > 3) return word.slice(0, -1);
|
|
141
143
|
return word;
|
|
142
144
|
}
|
|
143
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Edit distance: insertions, deletions, substitutions, and swaps of two
|
|
147
|
+
* neighbouring characters (`Metirc`, `Metric`), each one edit (optimal
|
|
148
|
+
* string alignment). Stops early once it exceeds `limit`: a row's smallest
|
|
149
|
+
* value is at most one more than the row before's, so once a row passes the
|
|
150
|
+
* limit, no later row, swaps included, comes back under it.
|
|
151
|
+
*/
|
|
144
152
|
function editDistance(a, b, limit) {
|
|
145
153
|
if (Math.abs(a.length - b.length) > limit) return limit + 1;
|
|
154
|
+
let before = [];
|
|
146
155
|
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
147
156
|
for (let i = 1; i <= a.length; i++) {
|
|
148
157
|
const current = [i];
|
|
149
158
|
let rowMin = i;
|
|
150
159
|
for (let j = 1; j <= b.length; j++) {
|
|
151
160
|
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
152
|
-
|
|
161
|
+
let value = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + cost);
|
|
162
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) value = Math.min(value, before[j - 2] + 1);
|
|
153
163
|
current.push(value);
|
|
154
164
|
rowMin = Math.min(rowMin, value);
|
|
155
165
|
}
|
|
156
166
|
if (rowMin > limit) return limit + 1;
|
|
167
|
+
before = previous;
|
|
157
168
|
previous = current;
|
|
158
169
|
}
|
|
159
170
|
return previous[b.length];
|
|
160
171
|
}
|
|
161
|
-
export { OKF_FIELDS, SETTINGS_PATH, TYPES_FOLDER, buildInventory, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isRecord, isStaleAt, isStatus, isTypeSchemaPath, normalizeSources, normalizeText, normalizeVerified, outlineTree, parseTree, readTypeSchema, visit };
|
|
172
|
+
export { MERMAID_RENDERERS, OKF_FIELDS, SETTINGS_PATH, TYPES_FOLDER, buildInventory, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isRecord, isStaleAt, isStatus, isTypeSchemaPath, normalizeSources, normalizeText, normalizeVerified, outlineTree, parseTree, readTypeSchema, visit };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as TreeFile, m as Tree } from "./types-4j7GeRZ-.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Read a tree from disk and build its model with {@link parseTree}. Reads the
|
|
4
4
|
* text of `.okforest/settings.yaml`, of its type schemas, and of markdown
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as isTypeSchemaPath, c as readSettings, i as ignoreMatcher, n as SETTINGS_PATH, s as parseTree } from "./tree-cHPdftiv.mjs";
|
|
2
2
|
import { readFile, readdir } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
// src/node.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
2
|
import { gfmFootnoteFromMarkdown } from "mdast-util-gfm-footnote";
|
|
3
3
|
import { gfmFootnote } from "micromark-extension-gfm-footnote";
|
|
4
|
-
import { LineCounter, isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
4
|
+
import { LineCounter, isAlias, isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
5
5
|
// src/markdown.ts
|
|
6
6
|
/**
|
|
7
7
|
* Parse markdown as CommonMark plus GFM footnotes, the one GitHub extension
|
|
@@ -110,11 +110,12 @@ function parseYaml(source, firstLine) {
|
|
|
110
110
|
let node = doc.contents;
|
|
111
111
|
let offset;
|
|
112
112
|
for (const segment of path) {
|
|
113
|
+
if (isAlias(node)) node = node.resolve(doc);
|
|
113
114
|
if (typeof segment === "number" && isSeq(node)) {
|
|
114
115
|
node = node.items[segment];
|
|
115
116
|
offset = node?.range?.[0];
|
|
116
117
|
} else if (isMap(node)) {
|
|
117
|
-
const pair = node.items.find((p) => isScalar(p.key) && p.key.value === segment);
|
|
118
|
+
const pair = node.items.find((p) => isScalar(p.key) && String(p.key.value) === String(segment));
|
|
118
119
|
if (!pair) return void 0;
|
|
119
120
|
offset = pair.key.range?.[0];
|
|
120
121
|
node = pair.value;
|
|
@@ -303,6 +304,9 @@ function normalizeSources(value) {
|
|
|
303
304
|
// src/tree.ts
|
|
304
305
|
/** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
|
|
305
306
|
const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
307
|
+
/** What may draw a bundle's ```mermaid blocks (`diagrams.mermaid.renderer`
|
|
308
|
+
* in its settings). */
|
|
309
|
+
const MERMAID_RENDERERS = ["mermaid", "pele"];
|
|
306
310
|
/** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
|
|
307
311
|
* type (an OKForest convention, not OKF). */
|
|
308
312
|
const TYPES_FOLDER = ".okforest/types/";
|
|
@@ -507,8 +511,8 @@ function ignoreMatcher(globs) {
|
|
|
507
511
|
return (path) => patterns.some((pattern) => pattern.test(path));
|
|
508
512
|
}
|
|
509
513
|
/** `.okforest/settings.yaml`, read leniently: what the `okforest/settings`
|
|
510
|
-
* rule reports as malformed is left out of `ignore`, `name`,
|
|
511
|
-
* `description`. */
|
|
514
|
+
* rule reports as malformed is left out of `ignore`, `name`,
|
|
515
|
+
* `description`, and `diagrams`. */
|
|
512
516
|
function readSettings(text) {
|
|
513
517
|
if (text === void 0) return void 0;
|
|
514
518
|
const parsed = parseYaml(text.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n"), 1);
|
|
@@ -520,6 +524,7 @@ function readSettings(text) {
|
|
|
520
524
|
};
|
|
521
525
|
const name = nonBlank("name");
|
|
522
526
|
const description = nonBlank("description");
|
|
527
|
+
const diagrams = readDiagrams(data?.diagrams);
|
|
523
528
|
const error = parsed.error ?? (data === void 0 ? {
|
|
524
529
|
message: "Settings must be a YAML mapping.",
|
|
525
530
|
line: 1,
|
|
@@ -533,9 +538,17 @@ function readSettings(text) {
|
|
|
533
538
|
ignore,
|
|
534
539
|
...name !== void 0 ? { name } : {},
|
|
535
540
|
...description !== void 0 ? { description } : {},
|
|
541
|
+
...diagrams ? { diagrams } : {},
|
|
536
542
|
locate: parsed.locate
|
|
537
543
|
};
|
|
538
544
|
}
|
|
545
|
+
/** `diagrams:`, keeping only what's well formed; undefined when that's
|
|
546
|
+
* nothing. */
|
|
547
|
+
function readDiagrams(value) {
|
|
548
|
+
const mermaid = isRecord(value) ? value.mermaid : void 0;
|
|
549
|
+
const renderer = isRecord(mermaid) ? mermaid.renderer : void 0;
|
|
550
|
+
return MERMAID_RENDERERS.includes(renderer) ? { mermaid: { renderer } } : void 0;
|
|
551
|
+
}
|
|
539
552
|
/** A type schema file, read leniently: what the `okforest/type-schema` rule
|
|
540
553
|
* reports (text that isn't JSON) leaves `data` undefined. Keys are located
|
|
541
554
|
* by reading the text as YAML, which JSON is. */
|
|
@@ -583,4 +596,4 @@ function positionAt(source, offset) {
|
|
|
583
596
|
column: (before.at(-1)?.length ?? 0) + 1
|
|
584
597
|
};
|
|
585
598
|
}
|
|
586
|
-
export {
|
|
599
|
+
export { normalizeText as _, isTypeSchemaPath as a, readSettings as c, deriveTrustTier as d, isStaleAt as f, globToRegExp as g, normalizeVerified as h, ignoreMatcher as i, readTypeSchema as l, normalizeSources as m, SETTINGS_PATH as n, outlineTree as o, isStatus as p, TYPES_FOLDER as r, parseTree as s, MERMAID_RENDERERS as t, deriveStatus as u, isRecord as v, visit as y };
|
|
@@ -147,8 +147,23 @@ interface TreeSettings {
|
|
|
147
147
|
name?: string;
|
|
148
148
|
/** What the bundle covers (`description:`), when it is non-blank text. */
|
|
149
149
|
description?: string;
|
|
150
|
+
/** How OKForest draws the bundle's diagrams (`diagrams:`): the settings
|
|
151
|
+
* that are well formed, when there are any. */
|
|
152
|
+
diagrams?: DiagramSettings;
|
|
150
153
|
locate(path: KeyPath): Position | undefined;
|
|
151
154
|
}
|
|
155
|
+
/** `diagrams:` in `.okforest/settings.yaml`: a section per diagram
|
|
156
|
+
* language. */
|
|
157
|
+
interface DiagramSettings {
|
|
158
|
+
mermaid?: {
|
|
159
|
+
/** What draws ```mermaid blocks: Mermaid itself, or Pele
|
|
160
|
+
* (https://pele.run), a Mermaid renderer of its own. OKForest uses
|
|
161
|
+
* Mermaid when unset. */
|
|
162
|
+
renderer?: MermaidRenderer;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** A `diagrams.mermaid.renderer` (MERMAID_RENDERERS). */
|
|
166
|
+
type MermaidRenderer = "mermaid" | "pele";
|
|
152
167
|
/** A JSON Schema for the frontmatter of one type's concepts, at
|
|
153
168
|
* `.okforest/types/<type>.schema.json` (an OKForest convention, not OKF). */
|
|
154
169
|
interface TypeSchema {
|
|
@@ -205,4 +220,4 @@ interface Tree {
|
|
|
205
220
|
/** Links from concepts (not from `index.md` or `log.md`) to the given concept. */
|
|
206
221
|
backlinks(id: string): Link[];
|
|
207
222
|
}
|
|
208
|
-
export {
|
|
223
|
+
export { TreeSettings as _, FootnoteReference as a, Verification as b, MarkdownFile as c, ReservedFile as d, Source as f, TreeOutline as g, TreeFile as h, DiagramSettings as i, MermaidRenderer as l, Tree as m, Concept as n, KeyPath as o, Status as p, Diagnostic as r, Link as s, CodeBlock as t, Position as u, TrustTier as v, TypeSchema as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okforest/okf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Read an Open Knowledge Format (OKF) v0.2 tree into a model: concepts, frontmatter, links, backlinks, trust tiers, staleness, and a metadata inventory. No SDKs or frameworks; runs in Node, browsers, and Workers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"okf",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^26.6.6",
|
|
52
|
-
"@vitest/coverage-v8": "^5.0
|
|
53
|
-
"tsdown": "^0.23.
|
|
52
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
53
|
+
"tsdown": "^0.23.7",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
|
-
"vitest": "^5.0
|
|
55
|
+
"vitest": "^5.1.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|