@okforest/okf 0.16.0 → 0.17.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
@@ -36,20 +36,29 @@ const tree = parseTree([
36
36
 
37
37
  A tree too large to hold parsed at once can be read one file at a time.
38
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:
39
+ settings file, the type schemas, and the root `index.md`'s `okf_version`);
40
+ `read` then parses one of its markdown files, with its links resolved against
41
+ the whole tree, as `parseTree` would:
41
42
 
42
43
  ```ts
43
- import { outlineTree } from "@okforest/okf"
44
+ import { declaredOkfVersion, outlineTree } from "@okforest/okf"
44
45
 
45
46
  // .okforest/settings.yaml, if any, and .okforest/types/*.schema.json by path
46
- const outline = outlineTree(paths, settingsText, typeTexts)
47
+ const outline = outlineTree(paths, settingsText, typeTexts, {
48
+ okfVersion: declaredOkfVersion(rootIndexText),
49
+ })
47
50
  for (const path of outline.markdown) {
48
- const file = outline.read(path, await textOf(path)) // a Concept or ReservedFile
51
+ // A Concept, a ReservedMarkdown (index.md, log.md), or, under OKF 0.3, an
52
+ // OtherMarkdown: one without a `type`, which isn't a concept (§3.2).
53
+ const file = outline.read(path, await textOf(path))
49
54
  // ...use it, and let it go
50
55
  }
51
56
  ```
52
57
 
58
+ Read this way, a link's `concept` is the ID its target's path gives: under
59
+ OKF 0.3 that file may turn out to be an `OtherMarkdown` once it's read, which
60
+ `parseTree` accounts for and a reader going a file at a time has to.
61
+
53
62
  Parsing never throws on malformed content: problems are recorded on each file
54
63
  (`frontmatterError`) for [`@okforest/validate`](https://www.npmjs.com/package/@okforest/validate)
55
64
  to report.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as Verification, _ as TreeOutline, a as DiagramSettings, b as TypeSchema, c as Link, d as Position, f as ReservedFile, g as TreeFile, h as Tree, i as Diagnostic, l as MarkdownFile, m as Status, n as CodeBlock, o as FootnoteReference, p as Source, r as Concept, s as KeyPath, t as BundleMetadata, u as MermaidRenderer, v as TreeSettings, x as TypeTemplate, y as TrustTier } from "./types-CvO9HuOI.mjs";
1
+ import { C as Verification, S as TypeTemplate, _ as TreeFile, a as DiagramSettings, b as TrustTier, c as Link, d as OtherMarkdown, f as Position, g as Tree, h as Status, i as Diagnostic, l as MarkdownFile, m as Source, n as CodeBlock, o as FootnoteReference, p as ReservedMarkdown, r as Concept, s as KeyPath, t as BundleMetadata, u as MermaidRenderer, v as TreeOutline, x as TypeSchema, y as TreeSettings } from "./types-CVC2lqRM.mjs";
2
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;
@@ -189,4 +189,4 @@ export declare function parseOkfVersion(value: unknown): OkfVersion | undefined;
189
189
  * false for it. */
190
190
  export declare function okfVersionAtLeast(value: unknown, version: string): boolean;
191
191
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
192
- export type { BundleMetadata, CodeBlock, Concept, Count, Diagnostic, DiagramSettings, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, MermaidRenderer, NearDuplicates, OkfVersion, PageStart, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, TypeSchema, TypeTemplate, Verification };
192
+ export type { BundleMetadata, CodeBlock, Concept, Count, Diagnostic, DiagramSettings, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, MermaidRenderer, NearDuplicates, OkfVersion, OtherMarkdown, PageStart, Position, ReservedMarkdown, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, TypeSchema, TypeTemplate, Verification };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as visit, C as isStatus, D as globToRegExp, E as parseTimestamp, O as normalizeText, S as isStaleAt, T as normalizeVerified, _ as parseOkfVersion, b as deriveTrustTier, c as isTypeTemplatePath, d as readBundleMetadata, g as okfVersionAtLeast, h as LATEST_OKF_VERSION, i as declaredOkfVersion, k as isRecord, l as outlineTree, m as readTypeTemplate, n as SETTINGS_PATH, o as isTypeFilePath, p as readTypeSchema, r as TYPES_FOLDER, s as isTypeSchemaPath, t as MERMAID_RENDERERS, u as parseTree, v as currentVerifications, w as normalizeSources, x as isAbsent, y as deriveStatus } from "./tree-BYjzYhx7.mjs";
1
+ import { A as visit, C as isStatus, D as globToRegExp, E as parseTimestamp, O as normalizeText, S as isStaleAt, T as normalizeVerified, _ as parseOkfVersion, b as deriveTrustTier, c as isTypeTemplatePath, d as readBundleMetadata, g as okfVersionAtLeast, h as LATEST_OKF_VERSION, i as declaredOkfVersion, k as isRecord, l as outlineTree, m as readTypeTemplate, n as SETTINGS_PATH, o as isTypeFilePath, p as readTypeSchema, r as TYPES_FOLDER, s as isTypeSchemaPath, t as MERMAID_RENDERERS, u as parseTree, v as currentVerifications, w as normalizeSources, x as isAbsent, y as deriveStatus } from "./tree-V336pZZS.mjs";
2
2
  import { isMap, isScalar, parseDocument, stringify } from "yaml";
3
3
  // src/fields.ts
4
4
  /** The frontmatter keys OKF defines for a concept (§4.1, §5, §10.2). A
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { g as TreeFile, h as Tree } from "./types-CvO9HuOI.mjs";
1
+ import { _ as TreeFile, g as Tree } from "./types-CVC2lqRM.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 templates, and of markdown
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ignoreMatcher, f as readSettings, n as SETTINGS_PATH, o as isTypeFilePath, u as parseTree } from "./tree-BYjzYhx7.mjs";
1
+ import { a as ignoreMatcher, f as readSettings, n as SETTINGS_PATH, o as isTypeFilePath, u as parseTree } from "./tree-V336pZZS.mjs";
2
2
  import { readFile, readdir } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  // src/node.ts
@@ -420,12 +420,22 @@ function parseTree(input) {
420
420
  const outline = outlineTree(texts.keys(), texts.get(SETTINGS_PATH), typeTexts, { okfVersion });
421
421
  const concepts = [];
422
422
  const reserved = [];
423
+ const otherMarkdown = [];
423
424
  for (const path of outline.markdown) {
424
425
  const file = outline.read(path, texts.get(path) ?? "");
425
426
  if (file.kind === "concept") concepts.push(file);
427
+ else if (file.kind === "other") otherMarkdown.push(file);
426
428
  else reserved.push(file);
427
429
  }
428
430
  const byId = new Map(concepts.map((c) => [c.id, c]));
431
+ if (otherMarkdown.length > 0) for (const file of [
432
+ ...concepts,
433
+ ...reserved,
434
+ ...otherMarkdown
435
+ ]) {
436
+ const paths = file.kind === "concept" ? file.paths : [];
437
+ for (const link of [...file.links, ...paths]) if (link.concept !== void 0 && !byId.has(link.concept)) delete link.concept;
438
+ }
429
439
  const backlinks = /* @__PURE__ */ new Map();
430
440
  for (const concept of concepts) for (const link of [...concept.links, ...concept.paths]) {
431
441
  if (!link.concept) continue;
@@ -439,13 +449,18 @@ function parseTree(input) {
439
449
  files: outline.files,
440
450
  concepts,
441
451
  reserved,
452
+ otherMarkdown,
442
453
  ignored: outline.ignored,
443
454
  ...outline.settings ? { settings: outline.settings } : {},
444
455
  types: outline.types,
445
456
  templates: outline.templates,
446
457
  ...rootIndex?.frontmatter && "okf_version" in rootIndex.frontmatter ? { okfVersion: rootIndex.frontmatter.okf_version } : {},
447
458
  ...metadata ? { metadata } : {},
448
- links: [...concepts, ...reserved].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).flatMap((doc) => doc.links),
459
+ links: [
460
+ ...concepts,
461
+ ...reserved,
462
+ ...otherMarkdown
463
+ ].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).flatMap((doc) => doc.links),
449
464
  concept: (id) => byId.get(id),
450
465
  backlinks: (id) => backlinks.get(id) ?? []
451
466
  };
@@ -506,6 +521,11 @@ function outlineTree(paths, settingsText, typeTexts = /* @__PURE__ */ new Map(),
506
521
  const name = basename(path);
507
522
  if (!RESERVED.has(name)) {
508
523
  const legacy = !okfVersionAtLeast(options.okfVersion, "0.3");
524
+ if (!legacy && !hasType(rest.frontmatter)) return {
525
+ ...rest,
526
+ links,
527
+ kind: "other"
528
+ };
509
529
  return buildConcept({
510
530
  ...rest,
511
531
  links
@@ -674,6 +694,11 @@ function resolveLink(raw, from, files, directories, conceptIds) {
674
694
  ...id !== void 0 && conceptIds.has(id) ? { concept: id } : {}
675
695
  };
676
696
  }
697
+ /** Whether frontmatter has the non-empty `type` that makes a file a concept
698
+ * under OKF 0.3 (spec §3.2). */
699
+ function hasType(frontmatter) {
700
+ return typeof frontmatter?.type === "string" && frontmatter.type.trim() !== "";
701
+ }
677
702
  /** The `okf_version` a bundle-root `index.md`'s text declares, as written
678
703
  * (spec §8.1), for {@link outlineTree}: undefined when it declares none. */
679
704
  function declaredOkfVersion(rootIndexText) {
@@ -47,7 +47,11 @@ interface Link {
47
47
  directory?: boolean;
48
48
  /** For internal links: the path climbs above the bundle root. */
49
49
  outside?: boolean;
50
- /** For internal links to a concept: its concept ID. */
50
+ /** For internal links to a concept: its concept ID. Read a file at a time
51
+ * ({@link TreeOutline.read}), it's the ID the target's path gives, since
52
+ * under OKF 0.3 whether that file is a concept isn't known until it's read
53
+ * (it may be an {@link OtherMarkdown}); a {@link Tree} keeps it only for
54
+ * concepts. */
51
55
  concept?: string;
52
56
  /** For a path field (spec §6.2) rather than a link in the body: the
53
57
  * frontmatter key it's written in, such as `superseded_by` or
@@ -116,7 +120,9 @@ interface BundleMetadata {
116
120
  /** An SPDX expression, or a path to a license file in the bundle. */
117
121
  license?: string;
118
122
  }
119
- /** A concept document: any non-reserved `.md` file. */
123
+ /** A concept document: a `.md` file other than `index.md` and `log.md`.
124
+ * Under OKF 0.3 only one whose frontmatter has a non-empty `type` is one
125
+ * (spec §3.2); the rest are {@link OtherMarkdown}. */
120
126
  interface Concept extends MarkdownFile {
121
127
  kind: "concept";
122
128
  /** Concept ID: the path without the `.md` suffix (spec §2). */
@@ -159,12 +165,20 @@ interface Concept extends MarkdownFile {
159
165
  * when it isn't a timestamp, which can't say the content is still current. */
160
166
  isStale(now?: Date): boolean;
161
167
  }
162
- /** A reserved file: `index.md` (spec §8) or `log.md` (spec §9). */
163
- interface ReservedFile extends MarkdownFile {
168
+ /** A reserved markdown file: `index.md` (spec §8) or `log.md` (spec §9). */
169
+ interface ReservedMarkdown extends MarkdownFile {
164
170
  kind: "index" | "log";
165
171
  /** Bundle-relative directory the file describes (`""` for the root). */
166
172
  directory: string;
167
173
  }
174
+ /** A markdown file that isn't a concept, `index.md`, or `log.md`: under OKF
175
+ * 0.3, one without frontmatter or a non-empty `type` (spec §3.2), such as a
176
+ * `README.md`. Consumers skip it: it isn't listed, searched, or linked to as
177
+ * a concept. Under OKF 0.2, or no version, every such file is a
178
+ * {@link Concept}. */
179
+ interface OtherMarkdown extends MarkdownFile {
180
+ kind: "other";
181
+ }
168
182
  /** `.okforest/settings.yaml`, OKForest's settings for a bundle (not part of OKF). */
169
183
  interface TreeSettings {
170
184
  path: string;
@@ -237,7 +251,8 @@ interface TreeOutline {
237
251
  /** Every file path in the tree, sorted. */
238
252
  files: string[];
239
253
  /** The markdown files that are part of the tree, sorted: its concepts,
240
- * `index.md`, and `log.md` files, without those the settings ignore. */
254
+ * `index.md`, and `log.md` files, and under OKF 0.3 those that aren't
255
+ * concepts ({@link OtherMarkdown}), without those the settings ignore. */
241
256
  markdown: string[];
242
257
  /** Markdown files left out by the settings' `ignore:` globs. */
243
258
  ignored: string[];
@@ -250,8 +265,9 @@ interface TreeOutline {
250
265
  * was given (spec §12): it decides which version's rules apply. */
251
266
  okfVersion?: unknown;
252
267
  /** Read one of {@link markdown}, with its links resolved against the whole
253
- * tree, as {@link Tree} holds it. Throws for any other path. */
254
- read(path: string, text: string): Concept | ReservedFile;
268
+ * tree, as {@link Tree} holds it: under OKF 0.3, a file without a `type`
269
+ * is an {@link OtherMarkdown}, which isn't a concept. Throws for any other path. */
270
+ read(path: string, text: string): Concept | ReservedMarkdown | OtherMarkdown;
255
271
  }
256
272
  /** A tree (an OKF bundle) read into a model. */
257
273
  interface Tree {
@@ -260,7 +276,10 @@ interface Tree {
260
276
  /** Concepts, sorted by path. */
261
277
  concepts: Concept[];
262
278
  /** `index.md` and `log.md` files, sorted by path. */
263
- reserved: ReservedFile[];
279
+ reserved: ReservedMarkdown[];
280
+ /** Markdown files that aren't concepts (OKF 0.3 §3.2: no frontmatter or
281
+ * no `type`), sorted by path; always empty under 0.2. */
282
+ otherMarkdown: OtherMarkdown[];
264
283
  /** Markdown files left out by the settings' `ignore:` globs. */
265
284
  ignored: string[];
266
285
  settings?: TreeSettings;
@@ -281,4 +300,4 @@ interface Tree {
281
300
  * to the given concept: its incoming edges in the bundle graph (spec §6.4). */
282
301
  backlinks(id: string): Link[];
283
302
  }
284
- export { Verification as S, TreeOutline as _, DiagramSettings as a, TypeSchema as b, Link as c, Position as d, ReservedFile as f, TreeFile as g, Tree as h, Diagnostic as i, MarkdownFile as l, Status as m, CodeBlock as n, FootnoteReference as o, Source as p, Concept as r, KeyPath as s, BundleMetadata as t, MermaidRenderer as u, TreeSettings as v, TypeTemplate as x, TrustTier as y };
303
+ export { Verification as C, TypeTemplate as S, TreeFile as _, DiagramSettings as a, TrustTier as b, Link as c, OtherMarkdown as d, Position as f, Tree as g, Status as h, Diagnostic as i, MarkdownFile as l, Source as m, CodeBlock as n, FootnoteReference as o, ReservedMarkdown as p, Concept as r, KeyPath as s, BundleMetadata as t, MermaidRenderer as u, TreeOutline as v, TypeSchema as x, TreeSettings as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okforest/okf",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Read an Open Knowledge Format (OKF) tree, 0.2 or 0.3, 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",