@okforest/okf 0.10.0 → 0.11.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 TypeSchema, a as KeyPath, c as Position, d as Status, f as Tree, g as TrustTier, h as TreeSettings, i as FootnoteReference, l as ReservedFile, m as TreeOutline, n as Concept, o as Link, p as TreeFile, r as Diagnostic, s as MarkdownFile, t as CodeBlock, u as Source, v as Verification } from "./types-D-Hs64kV.mjs";
2
- import { Nodes, Root } from "mdast";
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. */
@@ -60,6 +60,9 @@ export declare function editDistance(a: string, b: string, limit: number): numbe
60
60
  export declare function globToRegExp(glob: string): RegExp;
61
61
  /** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
62
62
  export declare const SETTINGS_PATH = ".okforest/settings.yaml";
63
+ /** What may draw a bundle's ```mermaid blocks (`diagrams.mermaid.renderer`
64
+ * in its settings). */
65
+ export declare const MERMAID_RENDERERS: readonly MermaidRenderer[];
63
66
  /** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
64
67
  * type (an OKForest convention, not OKF). */
65
68
  export declare const TYPES_FOLDER = ".okforest/types/";
@@ -103,4 +106,4 @@ export declare function deriveTrustTier(verified: readonly Verification[]): Trus
103
106
  export declare function isStaleAt(staleAfter: string | undefined, now: Date): boolean;
104
107
  export declare function normalizeSources(value: unknown): Source[];
105
108
  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 };
109
+ 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 isRecord, a as outlineTree, c as readTypeSchema, d as isStaleAt, f as isStatus, g as normalizeText, h as globToRegExp, i as isTypeSchemaPath, l as deriveStatus, m as normalizeVerified, n as TYPES_FOLDER, o as parseTree, p as normalizeSources, t as SETTINGS_PATH, u as deriveTrustTier, v as visit } from "./tree-D9AvJ7fw.mjs";
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
@@ -158,4 +158,4 @@ function editDistance(a, b, limit) {
158
158
  }
159
159
  return previous[b.length];
160
160
  }
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 };
161
+ 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 { f as Tree, p as TreeFile } from "./types-D-Hs64kV.mjs";
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 { i as isTypeSchemaPath, o as parseTree, r as ignoreMatcher, s as readSettings, t as SETTINGS_PATH } from "./tree-D9AvJ7fw.mjs";
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`, and
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 { isRecord as _, outlineTree as a, readTypeSchema as c, isStaleAt as d, isStatus as f, normalizeText as g, globToRegExp as h, isTypeSchemaPath as i, deriveStatus as l, normalizeVerified as m, TYPES_FOLDER as n, parseTree as o, normalizeSources as p, ignoreMatcher as r, readSettings as s, SETTINGS_PATH as t, deriveTrustTier as u, visit as v };
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 { TypeSchema as _, KeyPath as a, Position as c, Status as d, Tree as f, TrustTier as g, TreeSettings as h, FootnoteReference as i, ReservedFile as l, TreeOutline as m, Concept as n, Link as o, TreeFile as p, Diagnostic as r, MarkdownFile as s, CodeBlock as t, Source as u, Verification as v };
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.10.0",
3
+ "version": "0.11.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.5",
53
- "tsdown": "^0.23.4",
52
+ "@vitest/coverage-v8": "^5.1.0",
53
+ "tsdown": "^0.23.7",
54
54
  "typescript": "^7.0.2",
55
- "vitest": "^5.0.5"
55
+ "vitest": "^5.1.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",