@okforest/okf 0.6.2 → 0.8.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/README.md CHANGED
@@ -34,6 +34,22 @@ const tree = parseTree([
34
34
  ])
35
35
  ```
36
36
 
37
+ A tree too large to hold parsed at once can be read one file at a time.
38
+ `outlineTree` works out the tree from its paths alone (and the texts of the
39
+ settings file and the type schemas); `read` then parses one of its markdown
40
+ files, with its links resolved against the whole tree, as `parseTree` would:
41
+
42
+ ```ts
43
+ import { outlineTree } from "@okforest/okf"
44
+
45
+ // .okforest/settings.yaml, if any, and .okforest/types/*.schema.json by path
46
+ const outline = outlineTree(paths, settingsText, typeTexts)
47
+ for (const path of outline.markdown) {
48
+ const file = outline.read(path, await textOf(path)) // a Concept or ReservedFile
49
+ // ...use it, and let it go
50
+ }
51
+ ```
52
+
37
53
  Parsing never throws on malformed content: problems are recorded on each file
38
54
  (`frontmatterError`) for [`@okforest/validate`](https://www.npmjs.com/package/@okforest/validate)
39
55
  to report.
package/dist/index.d.mts CHANGED
@@ -1,14 +1,9 @@
1
- import { a as KeyPath, c as Position, d as Status, f as Tree, g as Verification, h as TrustTier, i as FootnoteReference, l as ReservedFile, m as TreeSettings, n as Concept, o as Link, p as TreeFile, r as Diagnostic, s as MarkdownFile, t as CodeBlock, u as Source } from "./types-BLSTBXoj.mjs";
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
2
  import { Nodes, Root } from "mdast";
3
- //#region src/markdown.d.ts
4
3
  /** Depth-first, document-order walk over an mdast tree. */
5
4
  export declare function visit(node: Nodes, fn: (node: Nodes) => void): void;
6
- //#endregion
7
- //#region src/document.d.ts
8
5
  /** Strip a byte-order mark and normalize line endings to LF. */
9
6
  export declare function normalizeText(text: string): string;
10
- //#endregion
11
- //#region src/inventory.d.ts
12
7
  /** A value in use and how many concepts use it. */
13
8
  interface Count {
14
9
  value: string;
@@ -55,16 +50,18 @@ export declare function buildInventory(tree: Tree, options?: {
55
50
  export declare function findNearDuplicates(counts: readonly Count[], field: NearDuplicates["field"]): NearDuplicates[];
56
51
  /** Levenshtein distance, stopping early once it exceeds `limit`. */
57
52
  export declare function editDistance(a: string, b: string, limit: number): number;
58
- //#endregion
59
- //#region src/paths.d.ts
60
53
  /** Convert a glob (relative to the tree root) to a regular expression.
61
54
  * `*` and `?` stay within one path segment, `**` crosses segments, and a
62
55
  * trailing `/` matches everything under a directory. */
63
56
  export declare function globToRegExp(glob: string): RegExp;
64
- //#endregion
65
- //#region src/tree.d.ts
66
57
  /** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
67
58
  export declare const SETTINGS_PATH = ".okforest/settings.yaml";
59
+ /** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
60
+ * type (an OKForest convention, not OKF). */
61
+ export declare const TYPES_FOLDER = ".okforest/types/";
62
+ /** Whether a bundle path is a type schema: a `.schema.json` file in
63
+ * {@link TYPES_FOLDER}, the name editors check as a JSON Schema. */
64
+ export declare function isTypeSchemaPath(path: string): boolean;
68
65
  /**
69
66
  * Build a {@link Tree} from files. Pure: no file system access, so the same
70
67
  * code runs in Node, browsers, and Workers (see `@okforest/okf/node` for
@@ -75,8 +72,18 @@ export declare const SETTINGS_PATH = ".okforest/settings.yaml";
75
72
  * `.git/`, as OKF says; settings `ignore:` globs leave out others.
76
73
  */
77
74
  export declare function parseTree(input: Iterable<TreeFile>): Tree;
78
- //#endregion
79
- //#region src/trust.d.ts
75
+ /**
76
+ * Outline a tree from its file paths, the text of its settings file
77
+ * (`.okforest/settings.yaml`, when it has one), and the texts of its type
78
+ * schemas by path ({@link isTypeSchemaPath}), without reading its markdown:
79
+ * a tree too large to hold parsed at once is then read one file at a time
80
+ * with {@link TreeOutline.read}, each file as {@link parseTree} reads it.
81
+ */
82
+ export declare function outlineTree(paths: Iterable<string>, settingsText?: string, typeTexts?: ReadonlyMap<string, string>): TreeOutline;
83
+ /** A type schema file, read leniently: what the `okforest/type-schema` rule
84
+ * reports (text that isn't JSON) leaves `data` undefined. Keys are located
85
+ * by reading the text as YAML, which JSON is. */
86
+ export declare function readTypeSchema(path: string, text: string): TypeSchema;
80
87
  /** Lifecycle status (spec §5.4): absent, or not a recognized value, means `stable`. */
81
88
  export declare function deriveStatus(value: unknown): Status;
82
89
  export declare function isStatus(value: unknown): value is Status;
@@ -91,8 +98,5 @@ export declare function deriveTrustTier(verified: readonly Verification[]): Trus
91
98
  /** Whether `now >= staleAfter` (spec §5.5). Unparseable instants are never stale. */
92
99
  export declare function isStaleAt(staleAfter: string | undefined, now: Date): boolean;
93
100
  export declare function normalizeSources(value: unknown): Source[];
94
- //#endregion
95
- //#region src/yaml.d.ts
96
101
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
97
- //#endregion
98
- export type { CodeBlock, Concept, Count, Diagnostic, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, NearDuplicates, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeSettings, TrustTier, Verification };
102
+ export type { CodeBlock, Concept, Count, Diagnostic, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, NearDuplicates, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, TypeSchema, Verification };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as deriveStatus, c as isStatus, d as globToRegExp, f as normalizeText, l as normalizeSources, m as visit, o as deriveTrustTier, p as isRecord, r as parseTree, s as isStaleAt, t as SETTINGS_PATH, u as normalizeVerified } from "./tree-BDKSPhqD.mjs";
2
- //#region src/inventory.ts
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";
2
+ // src/inventory.ts
3
3
  /** Build the metadata inventory of a tree. Deterministic: no model calls. */
4
4
  function buildInventory(tree, options = {}) {
5
5
  const now = options.now ?? /* @__PURE__ */ new Date();
@@ -136,5 +136,4 @@ function editDistance(a, b, limit) {
136
136
  }
137
137
  return previous[b.length];
138
138
  }
139
- //#endregion
140
- export { SETTINGS_PATH, buildInventory, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isRecord, isStaleAt, isStatus, normalizeSources, normalizeText, normalizeVerified, parseTree, visit };
139
+ export { 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,12 +1,10 @@
1
- import { f as Tree, p as TreeFile } from "./types-BLSTBXoj.mjs";
2
- //#region src/node.d.ts
1
+ import { f as Tree, p as TreeFile } from "./types-D-Hs64kV.mjs";
3
2
  /**
4
3
  * Read a tree from disk and build its model with {@link parseTree}. Reads the
5
- * text of `.okforest/settings.yaml` and of markdown files its `ignore:` globs
6
- * don't leave out; other files are listed by path only, so links to them can
7
- * be checked. `.git/` is not walked, and symbolic links are not followed.
4
+ * text of `.okforest/settings.yaml`, of its type schemas, and of markdown
5
+ * files its `ignore:` globs don't leave out; other files are listed by path
6
+ * only, so links to them can be checked. `.git/` is not walked, and symbolic links are not followed.
8
7
  */
9
8
  export declare function readTree(root: string): Promise<Tree>;
10
9
  /** The files {@link readTree} would hand to `parseTree`. */
11
- export declare function readTreeFiles(root: string): Promise<TreeFile[]>;
12
- //#endregion
10
+ export declare function readTreeFiles(root: string): Promise<TreeFile[]>;
package/dist/node.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { i as readSettings, n as ignoreMatcher, r as parseTree, t as SETTINGS_PATH } from "./tree-BDKSPhqD.mjs";
1
+ import { i as isTypeSchemaPath, o as parseTree, r as ignoreMatcher, s as readSettings, t as SETTINGS_PATH } from "./tree-D9AvJ7fw.mjs";
2
2
  import { readFile, readdir } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
- //#region src/node.ts
4
+ // src/node.ts
5
5
  /**
6
6
  * Read a tree from disk and build its model with {@link parseTree}. Reads the
7
- * text of `.okforest/settings.yaml` and of markdown files its `ignore:` globs
8
- * don't leave out; other files are listed by path only, so links to them can
9
- * be checked. `.git/` is not walked, and symbolic links are not followed.
7
+ * text of `.okforest/settings.yaml`, of its type schemas, and of markdown
8
+ * files its `ignore:` globs don't leave out; other files are listed by path
9
+ * only, so links to them can be checked. `.git/` is not walked, and symbolic links are not followed.
10
10
  */
11
11
  async function readTree(root) {
12
12
  return parseTree(await readTreeFiles(root));
@@ -33,6 +33,10 @@ async function readTreeFiles(root) {
33
33
  path,
34
34
  text: settingsText
35
35
  });
36
+ else if (isTypeSchemaPath(path)) files.push({
37
+ path,
38
+ text: await read(path)
39
+ });
36
40
  else if (path.endsWith(".md") && !isIgnored(path)) files.push({
37
41
  path,
38
42
  text: await read(path)
@@ -40,5 +44,4 @@ async function readTreeFiles(root) {
40
44
  else files.push({ path });
41
45
  return files;
42
46
  }
43
- //#endregion
44
47
  export { readTree, readTreeFiles };
@@ -2,7 +2,7 @@ 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
4
  import { LineCounter, isMap, isScalar, isSeq, parseDocument } from "yaml";
5
- //#region src/markdown.ts
5
+ // src/markdown.ts
6
6
  /**
7
7
  * Parse markdown as CommonMark plus GFM footnotes, the one GitHub extension
8
8
  * OKF relies on (per-claim attribution, spec §5.1). Other GFM extensions
@@ -80,8 +80,7 @@ function visit(node, fn) {
80
80
  fn(node);
81
81
  if ("children" in node) for (const child of node.children) visit(child, fn);
82
82
  }
83
- //#endregion
84
- //#region src/yaml.ts
83
+ // src/yaml.ts
85
84
  /**
86
85
  * Parse YAML 1.2 (core schema), so unquoted timestamps such as
87
86
  * `2026-06-30T14:00:00Z` stay strings and can be checked as written, and
@@ -145,8 +144,7 @@ function parseYaml(source, firstLine) {
145
144
  function isRecord(value) {
146
145
  return typeof value === "object" && value !== null && !Array.isArray(value);
147
146
  }
148
- //#endregion
149
- //#region src/document.ts
147
+ // src/document.ts
150
148
  const DELIMITER = /^---[ \t]*$/;
151
149
  /** Strip a byte-order mark and normalize line endings to LF. */
152
150
  function normalizeText(text) {
@@ -207,8 +205,7 @@ function readMarkdownFile(path, rawText) {
207
205
  locate
208
206
  };
209
207
  }
210
- //#endregion
211
- //#region src/paths.ts
208
+ // src/paths.ts
212
209
  /** Bundle-relative POSIX path helpers. No `node:path`: this runs in browsers and Workers. */
213
210
  /** Directory of a bundle-relative path (`""` for the root). */
214
211
  function dirname(path) {
@@ -255,8 +252,7 @@ function globToRegExp(glob) {
255
252
  }
256
253
  return new RegExp(`^${source}$`);
257
254
  }
258
- //#endregion
259
- //#region src/trust.ts
255
+ // src/trust.ts
260
256
  const STATUSES = [
261
257
  "draft",
262
258
  "stable",
@@ -304,10 +300,17 @@ function normalizeSources(value) {
304
300
  return source;
305
301
  });
306
302
  }
307
- //#endregion
308
- //#region src/tree.ts
303
+ // src/tree.ts
309
304
  /** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
310
305
  const SETTINGS_PATH = ".okforest/settings.yaml";
306
+ /** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
307
+ * type (an OKForest convention, not OKF). */
308
+ const TYPES_FOLDER = ".okforest/types/";
309
+ /** Whether a bundle path is a type schema: a `.schema.json` file in
310
+ * {@link TYPES_FOLDER}, the name editors check as a JSON Schema. */
311
+ function isTypeSchemaPath(path) {
312
+ return path.startsWith(".okforest/types/") && path.endsWith(".schema.json");
313
+ }
311
314
  /** Folders never part of a tree: OKForest's own and version control's. */
312
315
  const SKIPPED_FOLDERS = /* @__PURE__ */ new Set([".okforest", ".git"]);
313
316
  const RESERVED = /* @__PURE__ */ new Set(["index.md", "log.md"]);
@@ -326,43 +329,15 @@ function parseTree(input) {
326
329
  const path = normalize(file.path.replaceAll("\\", "/"));
327
330
  if (path) texts.set(path, file.text);
328
331
  }
329
- const files = [...texts.keys()].sort();
330
- const fileSet = new Set(files);
331
- const directories = /* @__PURE__ */ new Set([""]);
332
- for (const path of files) for (let dir = dirname(path); dir !== ""; dir = dirname(dir)) directories.add(dir);
333
- const settings = readSettings(texts.get(SETTINGS_PATH));
334
- const isIgnored = ignoreMatcher(settings?.ignore ?? []);
335
- const ignored = [];
336
- const parsed = [];
337
- for (const path of files) {
338
- if (!path.endsWith(".md")) continue;
339
- if (path.split("/").some((s) => SKIPPED_FOLDERS.has(s))) continue;
340
- if (isIgnored(path)) {
341
- ignored.push(path);
342
- continue;
343
- }
344
- parsed.push({
345
- file: readMarkdownFile(path, texts.get(path) ?? ""),
346
- reserved: RESERVED.has(basename(path))
347
- });
348
- }
349
- const conceptIds = new Set(parsed.filter((p) => !p.reserved).map((p) => p.file.path.slice(0, -3)));
350
- const resolve = (raw, from) => resolveLink(raw, from, fileSet, directories, conceptIds);
332
+ const typeTexts = /* @__PURE__ */ new Map();
333
+ for (const [path, text] of texts) if (text !== void 0 && isTypeSchemaPath(path)) typeTexts.set(path, text);
334
+ const outline = outlineTree(texts.keys(), texts.get(SETTINGS_PATH), typeTexts);
351
335
  const concepts = [];
352
336
  const reserved = [];
353
- for (const { file, reserved: isReserved } of parsed) {
354
- const { rawLinks, ...rest } = file;
355
- const links = rawLinks.map((raw) => resolve(raw, file.path));
356
- if (isReserved) reserved.push({
357
- ...rest,
358
- links,
359
- kind: basename(file.path) === "index.md" ? "index" : "log",
360
- directory: dirname(file.path)
361
- });
362
- else concepts.push(buildConcept({
363
- ...rest,
364
- links
365
- }));
337
+ for (const path of outline.markdown) {
338
+ const file = outline.read(path, texts.get(path) ?? "");
339
+ if (file.kind === "concept") concepts.push(file);
340
+ else reserved.push(file);
366
341
  }
367
342
  const byId = new Map(concepts.map((c) => [c.id, c]));
368
343
  const backlinks = /* @__PURE__ */ new Map();
@@ -374,17 +349,76 @@ function parseTree(input) {
374
349
  }
375
350
  const rootIndex = reserved.find((r) => r.path === "index.md");
376
351
  return {
377
- files,
352
+ files: outline.files,
378
353
  concepts,
379
354
  reserved,
380
- ignored,
381
- ...settings ? { settings } : {},
355
+ ignored: outline.ignored,
356
+ ...outline.settings ? { settings: outline.settings } : {},
357
+ types: outline.types,
382
358
  ...rootIndex?.frontmatter && "okf_version" in rootIndex.frontmatter ? { okfVersion: rootIndex.frontmatter.okf_version } : {},
383
359
  links: [...concepts, ...reserved].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).flatMap((doc) => doc.links),
384
360
  concept: (id) => byId.get(id),
385
361
  backlinks: (id) => backlinks.get(id) ?? []
386
362
  };
387
363
  }
364
+ /**
365
+ * Outline a tree from its file paths, the text of its settings file
366
+ * (`.okforest/settings.yaml`, when it has one), and the texts of its type
367
+ * schemas by path ({@link isTypeSchemaPath}), without reading its markdown:
368
+ * a tree too large to hold parsed at once is then read one file at a time
369
+ * with {@link TreeOutline.read}, each file as {@link parseTree} reads it.
370
+ */
371
+ function outlineTree(paths, settingsText, typeTexts = /* @__PURE__ */ new Map()) {
372
+ const unique = /* @__PURE__ */ new Set();
373
+ for (const raw of paths) {
374
+ const path = normalize(raw.replaceAll("\\", "/"));
375
+ if (path) unique.add(path);
376
+ }
377
+ const files = [...unique].sort();
378
+ const fileSet = new Set(files);
379
+ const directories = /* @__PURE__ */ new Set([""]);
380
+ for (const path of files) for (let dir = dirname(path); dir !== ""; dir = dirname(dir)) directories.add(dir);
381
+ const settings = readSettings(settingsText);
382
+ const isIgnored = ignoreMatcher(settings?.ignore ?? []);
383
+ const ignored = [];
384
+ const markdown = [];
385
+ for (const path of files) {
386
+ if (!path.endsWith(".md")) continue;
387
+ if (path.split("/").some((s) => SKIPPED_FOLDERS.has(s))) continue;
388
+ if (isIgnored(path)) ignored.push(path);
389
+ else markdown.push(path);
390
+ }
391
+ const inTree = new Set(markdown);
392
+ const conceptIds = new Set(markdown.filter((path) => !RESERVED.has(basename(path))).map((path) => path.slice(0, -3)));
393
+ const typeTextOf = new Map([...typeTexts].map(([path, text]) => [normalize(path.replaceAll("\\", "/")), text]));
394
+ const types = files.flatMap((path) => {
395
+ const text = typeTextOf.get(path);
396
+ return text !== void 0 && isTypeSchemaPath(path) ? [readTypeSchema(path, text)] : [];
397
+ });
398
+ return {
399
+ files,
400
+ markdown,
401
+ ignored,
402
+ ...settings ? { settings } : {},
403
+ types,
404
+ read(path, text) {
405
+ if (!inTree.has(path)) throw new Error(`${path} is not one of the tree's markdown files.`);
406
+ const { rawLinks, ...rest } = readMarkdownFile(path, text);
407
+ const links = rawLinks.map((raw) => resolveLink(raw, path, fileSet, directories, conceptIds));
408
+ const name = basename(path);
409
+ if (!RESERVED.has(name)) return buildConcept({
410
+ ...rest,
411
+ links
412
+ });
413
+ return {
414
+ ...rest,
415
+ links,
416
+ kind: name === "index.md" ? "index" : "log",
417
+ directory: dirname(path)
418
+ };
419
+ }
420
+ };
421
+ }
388
422
  function buildConcept(file) {
389
423
  const fm = file.frontmatter ?? {};
390
424
  const str = (key) => {
@@ -502,5 +536,51 @@ function readSettings(text) {
502
536
  locate: parsed.locate
503
537
  };
504
538
  }
505
- //#endregion
506
- export { deriveStatus as a, isStatus as c, globToRegExp as d, normalizeText as f, readSettings as i, normalizeSources as l, visit as m, ignoreMatcher as n, deriveTrustTier as o, isRecord as p, parseTree as r, isStaleAt as s, SETTINGS_PATH as t, normalizeVerified as u };
539
+ /** A type schema file, read leniently: what the `okforest/type-schema` rule
540
+ * reports (text that isn't JSON) leaves `data` undefined. Keys are located
541
+ * by reading the text as YAML, which JSON is. */
542
+ function readTypeSchema(path, text) {
543
+ const source = text.replace(/^/, "");
544
+ const { locate } = parseYaml(source.replace(/\r\n?/g, "\n"), 1);
545
+ let data;
546
+ let error;
547
+ try {
548
+ data = JSON.parse(source);
549
+ } catch (cause) {
550
+ error = jsonError(source, cause);
551
+ }
552
+ const title = isRecord(data) ? data.title : void 0;
553
+ const name = typeof title === "string" && title.trim() !== "" ? title : void 0;
554
+ return {
555
+ path,
556
+ text,
557
+ data,
558
+ ...error ? { error } : {},
559
+ ...name !== void 0 ? { name } : {},
560
+ locate
561
+ };
562
+ }
563
+ /** Where `JSON.parse` stopped, from the offset in its message ("Expected ','
564
+ * after property value in JSON at position 42"); the start when it gives
565
+ * none ("Unexpected end of JSON input"). */
566
+ function jsonError(source, cause) {
567
+ const message = cause instanceof Error ? cause.message : String(cause);
568
+ const reason = message.replace(/\s+in JSON at position \d+.*$/, "").replace(/\.?$/, ".");
569
+ const offset = /at position (\d+)/.exec(message);
570
+ const at = offset ? positionAt(source, Number(offset[1])) : {
571
+ line: 1,
572
+ column: 1
573
+ };
574
+ return {
575
+ message: `Not valid JSON: ${reason}`,
576
+ ...at
577
+ };
578
+ }
579
+ function positionAt(source, offset) {
580
+ const before = source.slice(0, offset).split("\n");
581
+ return {
582
+ line: before.length,
583
+ column: (before.at(-1)?.length ?? 0) + 1
584
+ };
585
+ }
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 };
@@ -1,5 +1,4 @@
1
1
  import { Root } from "mdast";
2
- //#region src/types.d.ts
3
2
  /** A 1-based line and column in a file. */
4
3
  interface Position {
5
4
  line: number;
@@ -150,6 +149,40 @@ interface TreeSettings {
150
149
  description?: string;
151
150
  locate(path: KeyPath): Position | undefined;
152
151
  }
152
+ /** A JSON Schema for the frontmatter of one type's concepts, at
153
+ * `.okforest/types/<type>.schema.json` (an OKForest convention, not OKF). */
154
+ interface TypeSchema {
155
+ path: string;
156
+ text: string;
157
+ /** The parsed JSON; `undefined` if it isn't valid JSON. */
158
+ data: unknown;
159
+ error?: Diagnostic;
160
+ /** The type it's for: its `title`, when that is non-blank text. */
161
+ name?: string;
162
+ /** Where a key of the schema is written, if present. */
163
+ locate(path: KeyPath): Position | undefined;
164
+ }
165
+ /**
166
+ * A tree without its documents: every path in it, the markdown files that are
167
+ * part of it, its settings and its type schemas, worked out from paths alone
168
+ * (and the text of those files). A tree too large to hold parsed at once is read one file at a
169
+ * time with {@link TreeOutline.read}; {@link Tree} is the same, read whole.
170
+ */
171
+ interface TreeOutline {
172
+ /** Every file path in the tree, sorted. */
173
+ files: string[];
174
+ /** The markdown files that are part of the tree, sorted: its concepts,
175
+ * `index.md`, and `log.md` files, without those the settings ignore. */
176
+ markdown: string[];
177
+ /** Markdown files left out by the settings' `ignore:` globs. */
178
+ ignored: string[];
179
+ settings?: TreeSettings;
180
+ /** Its type schemas whose text was given, sorted by path. */
181
+ types: TypeSchema[];
182
+ /** Read one of {@link markdown}, with its links resolved against the whole
183
+ * tree, as {@link Tree} holds it. Throws for any other path. */
184
+ read(path: string, text: string): Concept | ReservedFile;
185
+ }
153
186
  /** A tree (an OKF bundle) read into a model. */
154
187
  interface Tree {
155
188
  /** Every file path in the tree, sorted. */
@@ -161,6 +194,8 @@ interface Tree {
161
194
  /** Markdown files left out by the settings' `ignore:` globs. */
162
195
  ignored: string[];
163
196
  settings?: TreeSettings;
197
+ /** Its type schemas, sorted by path. */
198
+ types: TypeSchema[];
164
199
  /** The bundle-root `index.md` `okf_version` value, as written. */
165
200
  okfVersion?: unknown;
166
201
  /** Every link in every markdown file, in path and position order. */
@@ -170,5 +205,4 @@ interface Tree {
170
205
  /** Links from concepts (not from `index.md` or `log.md`) to the given concept. */
171
206
  backlinks(id: string): Link[];
172
207
  }
173
- //#endregion
174
- export { KeyPath as a, Position as c, Status as d, Tree as f, Verification as g, TrustTier as h, FootnoteReference as i, ReservedFile as l, TreeSettings as m, Concept as n, Link as o, TreeFile as p, Diagnostic as r, MarkdownFile as s, CodeBlock as t, Source as u };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okforest/okf",
3
- "version": "0.6.2",
3
+ "version": "0.8.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",
@@ -48,9 +48,9 @@
48
48
  "yaml": "^2.9.1"
49
49
  },
50
50
  "devDependencies": {
51
- "@types/node": "^26.6.5",
51
+ "@types/node": "^26.6.6",
52
52
  "@vitest/coverage-v8": "^5.0.5",
53
- "tsdown": "^0.23.0",
53
+ "tsdown": "^0.23.4",
54
54
  "typescript": "^7.0.2",
55
55
  "vitest": "^5.0.5"
56
56
  },