@okforest/okf 0.3.0 → 0.5.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,4 +1,4 @@
|
|
|
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-
|
|
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";
|
|
2
2
|
import { Nodes, Root } from "mdast";
|
|
3
3
|
//#region src/markdown.d.ts
|
|
4
4
|
/** Depth-first, document-order walk over an mdast tree. */
|
|
@@ -53,6 +53,8 @@ export declare function buildInventory(tree: Tree, options?: {
|
|
|
53
53
|
* unless one value contains the other.
|
|
54
54
|
*/
|
|
55
55
|
export declare function findNearDuplicates(counts: readonly Count[], field: NearDuplicates["field"]): NearDuplicates[];
|
|
56
|
+
/** Levenshtein distance, stopping early once it exceeds `limit`. */
|
|
57
|
+
export declare function editDistance(a: string, b: string, limit: number): number;
|
|
56
58
|
//#endregion
|
|
57
59
|
//#region src/paths.d.ts
|
|
58
60
|
/** Convert a glob (relative to the tree root) to a regular expression.
|
|
@@ -61,22 +63,16 @@ export declare function findNearDuplicates(counts: readonly Count[], field: Near
|
|
|
61
63
|
export declare function globToRegExp(glob: string): RegExp;
|
|
62
64
|
//#endregion
|
|
63
65
|
//#region src/tree.d.ts
|
|
64
|
-
/** Where OKForest keeps
|
|
65
|
-
export declare const SETTINGS_PATH = ".okforest/
|
|
66
|
-
/**
|
|
67
|
-
* Repository files at the tree root that are not concepts, though the OKF
|
|
68
|
-
* spec letter would make them so. Matched case-insensitively. Extend per tree
|
|
69
|
-
* with `ignore:` globs in `.okforest/tree.yaml`.
|
|
70
|
-
*/
|
|
71
|
-
export declare const DEFAULT_IGNORED: readonly string[];
|
|
66
|
+
/** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
|
|
67
|
+
export declare const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
72
68
|
/**
|
|
73
69
|
* Build a {@link Tree} from files. Pure: no file system access, so the same
|
|
74
70
|
* code runs in Node, browsers, and Workers (see `@okforest/okf/node` for
|
|
75
71
|
* reading a directory). Never throws on malformed content; problems are
|
|
76
72
|
* recorded on the files for `@okforest/validate` to report.
|
|
77
73
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
74
|
+
* Every markdown file is part of the tree except those under `.okforest/` and
|
|
75
|
+
* `.git/`, as OKF says; settings `ignore:` globs leave out others.
|
|
80
76
|
*/
|
|
81
77
|
export declare function parseTree(input: Iterable<TreeFile>): Tree;
|
|
82
78
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
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
2
|
//#region src/inventory.ts
|
|
3
3
|
/** Build the metadata inventory of a tree. Deterministic: no model calls. */
|
|
4
4
|
function buildInventory(tree, options = {}) {
|
|
@@ -137,4 +137,4 @@ function editDistance(a, b, limit) {
|
|
|
137
137
|
return previous[b.length];
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
|
-
export {
|
|
140
|
+
export { SETTINGS_PATH, buildInventory, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isRecord, isStaleAt, isStatus, normalizeSources, normalizeText, normalizeVerified, parseTree, visit };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { f as Tree, p as TreeFile } from "./types-
|
|
1
|
+
import { f as Tree, p as TreeFile } from "./types-BLSTBXoj.mjs";
|
|
2
2
|
//#region src/node.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Read a tree from disk and build its model with {@link parseTree}. Reads the
|
|
5
|
-
* text of
|
|
6
|
-
* path only, so links to them can
|
|
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.
|
|
7
8
|
*/
|
|
8
9
|
export declare function readTree(root: string): Promise<Tree>;
|
|
9
10
|
/** The files {@link readTree} would hand to `parseTree`. */
|
package/dist/node.mjs
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
import { r as parseTree } from "./tree-
|
|
1
|
+
import { i as readSettings, n as ignoreMatcher, r as parseTree, t as SETTINGS_PATH } from "./tree-BDKSPhqD.mjs";
|
|
2
2
|
import { readFile, readdir } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
//#region src/node.ts
|
|
5
|
-
/** Directories never walked: version control and installed packages. */
|
|
6
|
-
const SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
7
5
|
/**
|
|
8
6
|
* Read a tree from disk and build its model with {@link parseTree}. Reads the
|
|
9
|
-
* text of
|
|
10
|
-
* path only, so links to them can
|
|
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.
|
|
11
10
|
*/
|
|
12
11
|
async function readTree(root) {
|
|
13
12
|
return parseTree(await readTreeFiles(root));
|
|
14
13
|
}
|
|
15
14
|
/** The files {@link readTree} would hand to `parseTree`. */
|
|
16
15
|
async function readTreeFiles(root) {
|
|
17
|
-
const
|
|
16
|
+
const paths = [];
|
|
18
17
|
const walk = async (dir, prefix) => {
|
|
19
18
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
20
19
|
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
21
20
|
for (const entry of entries) {
|
|
22
21
|
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
23
22
|
if (entry.isDirectory()) {
|
|
24
|
-
if (
|
|
25
|
-
} else if (entry.isFile())
|
|
26
|
-
const needsText = path.endsWith(".md") || path === ".okforest/tree.yaml";
|
|
27
|
-
files.push(needsText ? {
|
|
28
|
-
path,
|
|
29
|
-
text: await readFile(join(dir, entry.name), "utf8")
|
|
30
|
-
} : { path });
|
|
31
|
-
}
|
|
23
|
+
if (entry.name !== ".git") await walk(join(dir, entry.name), path);
|
|
24
|
+
} else if (entry.isFile()) paths.push(path);
|
|
32
25
|
}
|
|
33
26
|
};
|
|
34
27
|
await walk(root, "");
|
|
28
|
+
const read = (path) => readFile(join(root, path), "utf8");
|
|
29
|
+
const settingsText = paths.includes(".okforest/settings.yaml") ? await read(SETTINGS_PATH) : void 0;
|
|
30
|
+
const isIgnored = ignoreMatcher(readSettings(settingsText)?.ignore ?? []);
|
|
31
|
+
const files = [];
|
|
32
|
+
for (const path of paths) if (path === ".okforest/settings.yaml") files.push({
|
|
33
|
+
path,
|
|
34
|
+
text: settingsText
|
|
35
|
+
});
|
|
36
|
+
else if (path.endsWith(".md") && !isIgnored(path)) files.push({
|
|
37
|
+
path,
|
|
38
|
+
text: await read(path)
|
|
39
|
+
});
|
|
40
|
+
else files.push({ path });
|
|
35
41
|
return files;
|
|
36
42
|
}
|
|
37
43
|
//#endregion
|
|
@@ -306,21 +306,10 @@ function normalizeSources(value) {
|
|
|
306
306
|
}
|
|
307
307
|
//#endregion
|
|
308
308
|
//#region src/tree.ts
|
|
309
|
-
/** Where OKForest keeps
|
|
310
|
-
const SETTINGS_PATH = ".okforest/
|
|
311
|
-
/**
|
|
312
|
-
|
|
313
|
-
* spec letter would make them so. Matched case-insensitively. Extend per tree
|
|
314
|
-
* with `ignore:` globs in `.okforest/tree.yaml`.
|
|
315
|
-
*/
|
|
316
|
-
const DEFAULT_IGNORED = [
|
|
317
|
-
"README.md",
|
|
318
|
-
"LICENSE.md",
|
|
319
|
-
"CONTRIBUTING.md",
|
|
320
|
-
"CHANGELOG.md",
|
|
321
|
-
"SECURITY.md",
|
|
322
|
-
"CODE_OF_CONDUCT.md"
|
|
323
|
-
];
|
|
309
|
+
/** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
|
|
310
|
+
const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
311
|
+
/** Folders never part of a tree: OKForest's own and version control's. */
|
|
312
|
+
const SKIPPED_FOLDERS = /* @__PURE__ */ new Set([".okforest", ".git"]);
|
|
324
313
|
const RESERVED = /* @__PURE__ */ new Set(["index.md", "log.md"]);
|
|
325
314
|
/**
|
|
326
315
|
* Build a {@link Tree} from files. Pure: no file system access, so the same
|
|
@@ -328,8 +317,8 @@ const RESERVED = /* @__PURE__ */ new Set(["index.md", "log.md"]);
|
|
|
328
317
|
* reading a directory). Never throws on malformed content; problems are
|
|
329
318
|
* recorded on the files for `@okforest/validate` to report.
|
|
330
319
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
320
|
+
* Every markdown file is part of the tree except those under `.okforest/` and
|
|
321
|
+
* `.git/`, as OKF says; settings `ignore:` globs leave out others.
|
|
333
322
|
*/
|
|
334
323
|
function parseTree(input) {
|
|
335
324
|
const texts = /* @__PURE__ */ new Map();
|
|
@@ -342,15 +331,13 @@ function parseTree(input) {
|
|
|
342
331
|
const directories = /* @__PURE__ */ new Set([""]);
|
|
343
332
|
for (const path of files) for (let dir = dirname(path); dir !== ""; dir = dirname(dir)) directories.add(dir);
|
|
344
333
|
const settings = readSettings(texts.get(SETTINGS_PATH));
|
|
345
|
-
const
|
|
346
|
-
const defaultIgnored = new Set(DEFAULT_IGNORED.map((name) => name.toLowerCase()));
|
|
334
|
+
const isIgnored = ignoreMatcher(settings?.ignore ?? []);
|
|
347
335
|
const ignored = [];
|
|
348
336
|
const parsed = [];
|
|
349
337
|
for (const path of files) {
|
|
350
338
|
if (!path.endsWith(".md")) continue;
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
if (segments.length === 1 && defaultIgnored.has(path.toLowerCase()) || ignorePatterns.some((pattern) => pattern.test(path))) {
|
|
339
|
+
if (path.split("/").some((s) => SKIPPED_FOLDERS.has(s))) continue;
|
|
340
|
+
if (isIgnored(path)) {
|
|
354
341
|
ignored.push(path);
|
|
355
342
|
continue;
|
|
356
343
|
}
|
|
@@ -480,11 +467,25 @@ function resolveLink(raw, from, files, directories, conceptIds) {
|
|
|
480
467
|
...id !== void 0 && conceptIds.has(id) ? { concept: id } : {}
|
|
481
468
|
};
|
|
482
469
|
}
|
|
470
|
+
/** Whether a bundle path matches one of the settings' `ignore:` globs. */
|
|
471
|
+
function ignoreMatcher(globs) {
|
|
472
|
+
const patterns = globs.map(globToRegExp);
|
|
473
|
+
return (path) => patterns.some((pattern) => pattern.test(path));
|
|
474
|
+
}
|
|
475
|
+
/** `.okforest/settings.yaml`, read leniently: what the `okforest/settings`
|
|
476
|
+
* rule reports as malformed is left out of `ignore`, `name`, and
|
|
477
|
+
* `description`. */
|
|
483
478
|
function readSettings(text) {
|
|
484
479
|
if (text === void 0) return void 0;
|
|
485
|
-
const parsed = parseYaml(text.replace(
|
|
480
|
+
const parsed = parseYaml(text.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n"), 1);
|
|
486
481
|
const data = parsed.value === null ? {} : isRecord(parsed.value) ? parsed.value : void 0;
|
|
487
482
|
const ignore = Array.isArray(data?.ignore) ? data.ignore.filter((g) => typeof g === "string" && g.trim() !== "") : [];
|
|
483
|
+
const nonBlank = (key) => {
|
|
484
|
+
const value = data?.[key];
|
|
485
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
486
|
+
};
|
|
487
|
+
const name = nonBlank("name");
|
|
488
|
+
const description = nonBlank("description");
|
|
488
489
|
const error = parsed.error ?? (data === void 0 ? {
|
|
489
490
|
message: "Settings must be a YAML mapping.",
|
|
490
491
|
line: 1,
|
|
@@ -496,8 +497,10 @@ function readSettings(text) {
|
|
|
496
497
|
data,
|
|
497
498
|
...error ? { error } : {},
|
|
498
499
|
ignore,
|
|
500
|
+
...name !== void 0 ? { name } : {},
|
|
501
|
+
...description !== void 0 ? { description } : {},
|
|
499
502
|
locate: parsed.locate
|
|
500
503
|
};
|
|
501
504
|
}
|
|
502
505
|
//#endregion
|
|
503
|
-
export {
|
|
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 };
|
|
@@ -135,7 +135,7 @@ interface ReservedFile extends MarkdownFile {
|
|
|
135
135
|
/** Bundle-relative directory the file describes (`""` for the root). */
|
|
136
136
|
directory: string;
|
|
137
137
|
}
|
|
138
|
-
/** `.okforest/
|
|
138
|
+
/** `.okforest/settings.yaml`, OKForest's settings for a bundle (not part of OKF). */
|
|
139
139
|
interface TreeSettings {
|
|
140
140
|
path: string;
|
|
141
141
|
text: string;
|
|
@@ -144,6 +144,10 @@ interface TreeSettings {
|
|
|
144
144
|
error?: Diagnostic;
|
|
145
145
|
/** Validation ignore globs (`ignore:`), when well-formed. */
|
|
146
146
|
ignore: string[];
|
|
147
|
+
/** The bundle's name (`name:`), when it is non-blank text. */
|
|
148
|
+
name?: string;
|
|
149
|
+
/** What the bundle covers (`description:`), when it is non-blank text. */
|
|
150
|
+
description?: string;
|
|
147
151
|
locate(path: KeyPath): Position | undefined;
|
|
148
152
|
}
|
|
149
153
|
/** A tree (an OKF bundle) read into a model. */
|
|
@@ -154,7 +158,7 @@ interface Tree {
|
|
|
154
158
|
concepts: Concept[];
|
|
155
159
|
/** `index.md` and `log.md` files, sorted by path. */
|
|
156
160
|
reserved: ReservedFile[];
|
|
157
|
-
/** Markdown files
|
|
161
|
+
/** Markdown files left out by the settings' `ignore:` globs. */
|
|
158
162
|
ignored: string[];
|
|
159
163
|
settings?: TreeSettings;
|
|
160
164
|
/** The bundle-root `index.md` `okf_version` value, as written. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okforest/okf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.5",
|
|
52
|
-
"@vitest/coverage-v8": "^5.0.
|
|
52
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
53
53
|
"tsdown": "^0.23.0",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
|
-
"vitest": "^5.0.
|
|
55
|
+
"vitest": "^5.0.5"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|