@okforest/okf 0.16.1 → 0.18.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
|
|
40
|
-
files, with its links resolved against
|
|
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
|
-
|
|
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 {
|
|
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;
|
|
@@ -88,6 +88,10 @@ export declare const MERMAID_RENDERERS: readonly MermaidRenderer[];
|
|
|
88
88
|
/** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
|
|
89
89
|
* type (an OKForest convention, not OKF). */
|
|
90
90
|
export declare const TYPES_FOLDER = ".okforest/types/";
|
|
91
|
+
/** A type's name as its files in {@link TYPES_FOLDER} are named, before
|
|
92
|
+
* `.schema.json` and `.template.md`: `BigQuery Table` → `bigquery-table`,
|
|
93
|
+
* `顧客` → `顧客`; `type` when no letter or digit is left. */
|
|
94
|
+
export declare function typeSlug(type: string): string;
|
|
91
95
|
/** Whether a bundle path is a type schema: a `.schema.json` file in
|
|
92
96
|
* {@link TYPES_FOLDER}, the name editors check as a JSON Schema. */
|
|
93
97
|
export declare function isTypeSchemaPath(path: string): boolean;
|
|
@@ -189,4 +193,4 @@ export declare function parseOkfVersion(value: unknown): OkfVersion | undefined;
|
|
|
189
193
|
* false for it. */
|
|
190
194
|
export declare function okfVersionAtLeast(value: unknown, version: string): boolean;
|
|
191
195
|
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,
|
|
196
|
+
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
|
|
1
|
+
import { A as isRecord, C as isStaleAt, D as parseTimestamp, E as normalizeVerified, O as globToRegExp, S as isAbsent, T as normalizeSources, _ as okfVersionAtLeast, b as deriveStatus, c as isTypeTemplatePath, d as readBundleMetadata, g as LATEST_OKF_VERSION, h as typeSlug, i as declaredOkfVersion, j as visit, k as normalizeText, 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 parseOkfVersion, w as isStatus, x as deriveTrustTier, y as currentVerifications } from "./tree-BRMsNzzv.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
|
|
@@ -233,4 +233,4 @@ function topLevelPairs(yaml) {
|
|
|
233
233
|
function range(node) {
|
|
234
234
|
return node.range;
|
|
235
235
|
}
|
|
236
|
-
export { LATEST_OKF_VERSION, MERMAID_RENDERERS, OKF_FIELDS, SETTINGS_PATH, TYPES_FOLDER, buildInventory, currentVerifications, declaredOkfVersion, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isAbsent, isRecord, isStaleAt, isStatus, isTypeFilePath, isTypeSchemaPath, isTypeTemplatePath, normalizeSources, normalizeText, normalizeVerified, okfVersionAtLeast, outlineTree, parseOkfVersion, parseTimestamp, parseTree, readBundleMetadata, readTypeSchema, readTypeTemplate, startPage, visit };
|
|
236
|
+
export { LATEST_OKF_VERSION, MERMAID_RENDERERS, OKF_FIELDS, SETTINGS_PATH, TYPES_FOLDER, buildInventory, currentVerifications, declaredOkfVersion, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isAbsent, isRecord, isStaleAt, isStatus, isTypeFilePath, isTypeSchemaPath, isTypeTemplatePath, normalizeSources, normalizeText, normalizeVerified, okfVersionAtLeast, outlineTree, parseOkfVersion, parseTimestamp, parseTree, readBundleMetadata, readTypeSchema, readTypeTemplate, startPage, typeSlug, visit };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
1
|
+
import { a as ignoreMatcher, f as readSettings, n as SETTINGS_PATH, o as isTypeFilePath, u as parseTree } from "./tree-BRMsNzzv.mjs";
|
|
2
2
|
import { readFile, readdir } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
// src/node.ts
|
|
@@ -382,6 +382,12 @@ const MERMAID_RENDERERS = ["mermaid", "pele"];
|
|
|
382
382
|
/** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
|
|
383
383
|
* type (an OKForest convention, not OKF). */
|
|
384
384
|
const TYPES_FOLDER = ".okforest/types/";
|
|
385
|
+
/** A type's name as its files in {@link TYPES_FOLDER} are named, before
|
|
386
|
+
* `.schema.json` and `.template.md`: `BigQuery Table` → `bigquery-table`,
|
|
387
|
+
* `顧客` → `顧客`; `type` when no letter or digit is left. */
|
|
388
|
+
function typeSlug(type) {
|
|
389
|
+
return type.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "") || "type";
|
|
390
|
+
}
|
|
385
391
|
/** Whether a bundle path is a type schema: a `.schema.json` file in
|
|
386
392
|
* {@link TYPES_FOLDER}, the name editors check as a JSON Schema. */
|
|
387
393
|
function isTypeSchemaPath(path) {
|
|
@@ -420,12 +426,22 @@ function parseTree(input) {
|
|
|
420
426
|
const outline = outlineTree(texts.keys(), texts.get(SETTINGS_PATH), typeTexts, { okfVersion });
|
|
421
427
|
const concepts = [];
|
|
422
428
|
const reserved = [];
|
|
429
|
+
const otherMarkdown = [];
|
|
423
430
|
for (const path of outline.markdown) {
|
|
424
431
|
const file = outline.read(path, texts.get(path) ?? "");
|
|
425
432
|
if (file.kind === "concept") concepts.push(file);
|
|
433
|
+
else if (file.kind === "other") otherMarkdown.push(file);
|
|
426
434
|
else reserved.push(file);
|
|
427
435
|
}
|
|
428
436
|
const byId = new Map(concepts.map((c) => [c.id, c]));
|
|
437
|
+
if (otherMarkdown.length > 0) for (const file of [
|
|
438
|
+
...concepts,
|
|
439
|
+
...reserved,
|
|
440
|
+
...otherMarkdown
|
|
441
|
+
]) {
|
|
442
|
+
const paths = file.kind === "concept" ? file.paths : [];
|
|
443
|
+
for (const link of [...file.links, ...paths]) if (link.concept !== void 0 && !byId.has(link.concept)) delete link.concept;
|
|
444
|
+
}
|
|
429
445
|
const backlinks = /* @__PURE__ */ new Map();
|
|
430
446
|
for (const concept of concepts) for (const link of [...concept.links, ...concept.paths]) {
|
|
431
447
|
if (!link.concept) continue;
|
|
@@ -439,13 +455,18 @@ function parseTree(input) {
|
|
|
439
455
|
files: outline.files,
|
|
440
456
|
concepts,
|
|
441
457
|
reserved,
|
|
458
|
+
otherMarkdown,
|
|
442
459
|
ignored: outline.ignored,
|
|
443
460
|
...outline.settings ? { settings: outline.settings } : {},
|
|
444
461
|
types: outline.types,
|
|
445
462
|
templates: outline.templates,
|
|
446
463
|
...rootIndex?.frontmatter && "okf_version" in rootIndex.frontmatter ? { okfVersion: rootIndex.frontmatter.okf_version } : {},
|
|
447
464
|
...metadata ? { metadata } : {},
|
|
448
|
-
links: [
|
|
465
|
+
links: [
|
|
466
|
+
...concepts,
|
|
467
|
+
...reserved,
|
|
468
|
+
...otherMarkdown
|
|
469
|
+
].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).flatMap((doc) => doc.links),
|
|
449
470
|
concept: (id) => byId.get(id),
|
|
450
471
|
backlinks: (id) => backlinks.get(id) ?? []
|
|
451
472
|
};
|
|
@@ -506,6 +527,11 @@ function outlineTree(paths, settingsText, typeTexts = /* @__PURE__ */ new Map(),
|
|
|
506
527
|
const name = basename(path);
|
|
507
528
|
if (!RESERVED.has(name)) {
|
|
508
529
|
const legacy = !okfVersionAtLeast(options.okfVersion, "0.3");
|
|
530
|
+
if (!legacy && !hasType(rest.frontmatter)) return {
|
|
531
|
+
...rest,
|
|
532
|
+
links,
|
|
533
|
+
kind: "other"
|
|
534
|
+
};
|
|
509
535
|
return buildConcept({
|
|
510
536
|
...rest,
|
|
511
537
|
links
|
|
@@ -674,6 +700,11 @@ function resolveLink(raw, from, files, directories, conceptIds) {
|
|
|
674
700
|
...id !== void 0 && conceptIds.has(id) ? { concept: id } : {}
|
|
675
701
|
};
|
|
676
702
|
}
|
|
703
|
+
/** Whether frontmatter has the non-empty `type` that makes a file a concept
|
|
704
|
+
* under OKF 0.3 (spec §3.2). */
|
|
705
|
+
function hasType(frontmatter) {
|
|
706
|
+
return typeof frontmatter?.type === "string" && frontmatter.type.trim() !== "";
|
|
707
|
+
}
|
|
677
708
|
/** The `okf_version` a bundle-root `index.md`'s text declares, as written
|
|
678
709
|
* (spec §8.1), for {@link outlineTree}: undefined when it declares none. */
|
|
679
710
|
function declaredOkfVersion(rootIndexText) {
|
|
@@ -784,4 +815,4 @@ function positionAt(source, offset) {
|
|
|
784
815
|
column: (before.at(-1)?.length ?? 0) + 1
|
|
785
816
|
};
|
|
786
817
|
}
|
|
787
|
-
export {
|
|
818
|
+
export { isRecord as A, isStaleAt as C, parseTimestamp as D, normalizeVerified as E, globToRegExp as O, isAbsent as S, normalizeSources as T, okfVersionAtLeast as _, ignoreMatcher as a, deriveStatus as b, isTypeTemplatePath as c, readBundleMetadata as d, readSettings as f, LATEST_OKF_VERSION as g, typeSlug as h, declaredOkfVersion as i, visit as j, normalizeText as k, outlineTree as l, readTypeTemplate as m, SETTINGS_PATH as n, isTypeFilePath as o, readTypeSchema as p, TYPES_FOLDER as r, isTypeSchemaPath as s, MERMAID_RENDERERS as t, parseTree as u, parseOkfVersion as v, isStatus as w, deriveTrustTier as x, currentVerifications as y };
|
|
@@ -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:
|
|
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
|
|
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,
|
|
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.
|
|
254
|
-
|
|
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:
|
|
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,
|
|
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.
|
|
3
|
+
"version": "0.18.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",
|