@okforest/okf 0.7.0 → 0.9.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 +5 -4
- package/dist/index.d.mts +20 -19
- package/dist/index.mjs +25 -4
- package/dist/node.d.mts +5 -7
- package/dist/node.mjs +9 -6
- package/dist/{tree-CRV8aRK6.mjs → tree-D9AvJ7fw.mjs} +76 -17
- package/dist/{types-BF5G8id_.d.mts → types-D-Hs64kV.d.mts} +20 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,14 +35,15 @@ const tree = parseTree([
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
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
|
|
39
|
-
file
|
|
40
|
-
resolved against the whole tree, as `parseTree` would:
|
|
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
41
|
|
|
42
42
|
```ts
|
|
43
43
|
import { outlineTree } from "@okforest/okf"
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
// .okforest/settings.yaml, if any, and .okforest/types/*.schema.json by path
|
|
46
|
+
const outline = outlineTree(paths, settingsText, typeTexts)
|
|
46
47
|
for (const path of outline.markdown) {
|
|
47
48
|
const file = outline.read(path, await textOf(path)) // a Concept or ReservedFile
|
|
48
49
|
// ...use it, and let it go
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { _ as
|
|
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
|
-
|
|
11
|
-
|
|
7
|
+
/** The frontmatter keys OKF defines (§4.1, §5, §10.2). A type's schema
|
|
8
|
+
* describes the type's own fields, so these are left out of it unless it
|
|
9
|
+
* names them. */
|
|
10
|
+
export declare const OKF_FIELDS: readonly string[];
|
|
12
11
|
/** A value in use and how many concepts use it. */
|
|
13
12
|
interface Count {
|
|
14
13
|
value: string;
|
|
@@ -55,16 +54,18 @@ export declare function buildInventory(tree: Tree, options?: {
|
|
|
55
54
|
export declare function findNearDuplicates(counts: readonly Count[], field: NearDuplicates["field"]): NearDuplicates[];
|
|
56
55
|
/** Levenshtein distance, stopping early once it exceeds `limit`. */
|
|
57
56
|
export declare function editDistance(a: string, b: string, limit: number): number;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/paths.d.ts
|
|
60
57
|
/** Convert a glob (relative to the tree root) to a regular expression.
|
|
61
58
|
* `*` and `?` stay within one path segment, `**` crosses segments, and a
|
|
62
59
|
* trailing `/` matches everything under a directory. */
|
|
63
60
|
export declare function globToRegExp(glob: string): RegExp;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/tree.d.ts
|
|
66
61
|
/** Where OKForest keeps a bundle's settings (an OKForest convention, not OKF). */
|
|
67
62
|
export declare const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
63
|
+
/** Where OKForest keeps a bundle's type schemas, one `<type>.schema.json` a
|
|
64
|
+
* type (an OKForest convention, not OKF). */
|
|
65
|
+
export declare const TYPES_FOLDER = ".okforest/types/";
|
|
66
|
+
/** Whether a bundle path is a type schema: a `.schema.json` file in
|
|
67
|
+
* {@link TYPES_FOLDER}, the name editors check as a JSON Schema. */
|
|
68
|
+
export declare function isTypeSchemaPath(path: string): boolean;
|
|
68
69
|
/**
|
|
69
70
|
* Build a {@link Tree} from files. Pure: no file system access, so the same
|
|
70
71
|
* code runs in Node, browsers, and Workers (see `@okforest/okf/node` for
|
|
@@ -76,14 +77,17 @@ export declare const SETTINGS_PATH = ".okforest/settings.yaml";
|
|
|
76
77
|
*/
|
|
77
78
|
export declare function parseTree(input: Iterable<TreeFile>): Tree;
|
|
78
79
|
/**
|
|
79
|
-
* Outline a tree from its file paths
|
|
80
|
-
* (`.okforest/settings.yaml`, when it has one),
|
|
80
|
+
* Outline a tree from its file paths, the text of its settings file
|
|
81
|
+
* (`.okforest/settings.yaml`, when it has one), and the texts of its type
|
|
82
|
+
* schemas by path ({@link isTypeSchemaPath}), without reading its markdown:
|
|
81
83
|
* a tree too large to hold parsed at once is then read one file at a time
|
|
82
84
|
* with {@link TreeOutline.read}, each file as {@link parseTree} reads it.
|
|
83
85
|
*/
|
|
84
|
-
export declare function outlineTree(paths: Iterable<string>, settingsText?: string): TreeOutline;
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
export declare function outlineTree(paths: Iterable<string>, settingsText?: string, typeTexts?: ReadonlyMap<string, string>): TreeOutline;
|
|
87
|
+
/** A type schema file, read leniently: what the `okforest/type-schema` rule
|
|
88
|
+
* reports (text that isn't JSON) leaves `data` undefined. Keys are located
|
|
89
|
+
* by reading the text as YAML, which JSON is. */
|
|
90
|
+
export declare function readTypeSchema(path: string, text: string): TypeSchema;
|
|
87
91
|
/** Lifecycle status (spec §5.4): absent, or not a recognized value, means `stable`. */
|
|
88
92
|
export declare function deriveStatus(value: unknown): Status;
|
|
89
93
|
export declare function isStatus(value: unknown): value is Status;
|
|
@@ -98,8 +102,5 @@ export declare function deriveTrustTier(verified: readonly Verification[]): Trus
|
|
|
98
102
|
/** Whether `now >= staleAfter` (spec §5.5). Unparseable instants are never stale. */
|
|
99
103
|
export declare function isStaleAt(staleAfter: string | undefined, now: Date): boolean;
|
|
100
104
|
export declare function normalizeSources(value: unknown): Source[];
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/yaml.d.ts
|
|
103
105
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
104
|
-
|
|
105
|
-
export type { CodeBlock, Concept, Count, Diagnostic, FootnoteReference, Inventory, KeyPath, Link, MarkdownFile, NearDuplicates, Position, ReservedFile, Source, Status, Tree, TreeFile, TreeOutline, TreeSettings, TrustTier, Verification };
|
|
106
|
+
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,27 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
|
|
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/fields.ts
|
|
3
|
+
/** The frontmatter keys OKF defines (§4.1, §5, §10.2). A type's schema
|
|
4
|
+
* describes the type's own fields, so these are left out of it unless it
|
|
5
|
+
* names them. */
|
|
6
|
+
const OKF_FIELDS = [
|
|
7
|
+
"type",
|
|
8
|
+
"title",
|
|
9
|
+
"description",
|
|
10
|
+
"resource",
|
|
11
|
+
"tags",
|
|
12
|
+
"sources",
|
|
13
|
+
"usage_window",
|
|
14
|
+
"generated",
|
|
15
|
+
"verified",
|
|
16
|
+
"status",
|
|
17
|
+
"stale_after",
|
|
18
|
+
"runtime",
|
|
19
|
+
"parameters",
|
|
20
|
+
"computation",
|
|
21
|
+
"executor",
|
|
22
|
+
"attester"
|
|
23
|
+
];
|
|
24
|
+
// src/inventory.ts
|
|
3
25
|
/** Build the metadata inventory of a tree. Deterministic: no model calls. */
|
|
4
26
|
function buildInventory(tree, options = {}) {
|
|
5
27
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
@@ -136,5 +158,4 @@ function editDistance(a, b, limit) {
|
|
|
136
158
|
}
|
|
137
159
|
return previous[b.length];
|
|
138
160
|
}
|
|
139
|
-
|
|
140
|
-
export { SETTINGS_PATH, buildInventory, deriveStatus, deriveTrustTier, editDistance, findNearDuplicates, globToRegExp, isRecord, isStaleAt, isStatus, normalizeSources, normalizeText, normalizeVerified, outlineTree, parseTree, visit };
|
|
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 };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { f as Tree, p as TreeFile } from "./types-
|
|
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
|
|
6
|
-
* don't leave out; other files are listed by path
|
|
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 {
|
|
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
|
-
|
|
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
|
|
8
|
-
* don't leave out; other files are listed by path
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,7 +329,9 @@ function parseTree(input) {
|
|
|
326
329
|
const path = normalize(file.path.replaceAll("\\", "/"));
|
|
327
330
|
if (path) texts.set(path, file.text);
|
|
328
331
|
}
|
|
329
|
-
const
|
|
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);
|
|
330
335
|
const concepts = [];
|
|
331
336
|
const reserved = [];
|
|
332
337
|
for (const path of outline.markdown) {
|
|
@@ -349,6 +354,7 @@ function parseTree(input) {
|
|
|
349
354
|
reserved,
|
|
350
355
|
ignored: outline.ignored,
|
|
351
356
|
...outline.settings ? { settings: outline.settings } : {},
|
|
357
|
+
types: outline.types,
|
|
352
358
|
...rootIndex?.frontmatter && "okf_version" in rootIndex.frontmatter ? { okfVersion: rootIndex.frontmatter.okf_version } : {},
|
|
353
359
|
links: [...concepts, ...reserved].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).flatMap((doc) => doc.links),
|
|
354
360
|
concept: (id) => byId.get(id),
|
|
@@ -356,12 +362,13 @@ function parseTree(input) {
|
|
|
356
362
|
};
|
|
357
363
|
}
|
|
358
364
|
/**
|
|
359
|
-
* Outline a tree from its file paths
|
|
360
|
-
* (`.okforest/settings.yaml`, when it has one),
|
|
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:
|
|
361
368
|
* a tree too large to hold parsed at once is then read one file at a time
|
|
362
369
|
* with {@link TreeOutline.read}, each file as {@link parseTree} reads it.
|
|
363
370
|
*/
|
|
364
|
-
function outlineTree(paths, settingsText) {
|
|
371
|
+
function outlineTree(paths, settingsText, typeTexts = /* @__PURE__ */ new Map()) {
|
|
365
372
|
const unique = /* @__PURE__ */ new Set();
|
|
366
373
|
for (const raw of paths) {
|
|
367
374
|
const path = normalize(raw.replaceAll("\\", "/"));
|
|
@@ -383,11 +390,17 @@ function outlineTree(paths, settingsText) {
|
|
|
383
390
|
}
|
|
384
391
|
const inTree = new Set(markdown);
|
|
385
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
|
+
});
|
|
386
398
|
return {
|
|
387
399
|
files,
|
|
388
400
|
markdown,
|
|
389
401
|
ignored,
|
|
390
402
|
...settings ? { settings } : {},
|
|
403
|
+
types,
|
|
391
404
|
read(path, text) {
|
|
392
405
|
if (!inTree.has(path)) throw new Error(`${path} is not one of the tree's markdown files.`);
|
|
393
406
|
const { rawLinks, ...rest } = readMarkdownFile(path, text);
|
|
@@ -523,5 +536,51 @@ function readSettings(text) {
|
|
|
523
536
|
locate: parsed.locate
|
|
524
537
|
};
|
|
525
538
|
}
|
|
526
|
-
|
|
527
|
-
|
|
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,10 +149,23 @@ 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
|
+
}
|
|
153
165
|
/**
|
|
154
166
|
* A tree without its documents: every path in it, the markdown files that are
|
|
155
|
-
* part of it, and its
|
|
156
|
-
*
|
|
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
|
|
157
169
|
* time with {@link TreeOutline.read}; {@link Tree} is the same, read whole.
|
|
158
170
|
*/
|
|
159
171
|
interface TreeOutline {
|
|
@@ -165,6 +177,8 @@ interface TreeOutline {
|
|
|
165
177
|
/** Markdown files left out by the settings' `ignore:` globs. */
|
|
166
178
|
ignored: string[];
|
|
167
179
|
settings?: TreeSettings;
|
|
180
|
+
/** Its type schemas whose text was given, sorted by path. */
|
|
181
|
+
types: TypeSchema[];
|
|
168
182
|
/** Read one of {@link markdown}, with its links resolved against the whole
|
|
169
183
|
* tree, as {@link Tree} holds it. Throws for any other path. */
|
|
170
184
|
read(path: string, text: string): Concept | ReservedFile;
|
|
@@ -180,6 +194,8 @@ interface Tree {
|
|
|
180
194
|
/** Markdown files left out by the settings' `ignore:` globs. */
|
|
181
195
|
ignored: string[];
|
|
182
196
|
settings?: TreeSettings;
|
|
197
|
+
/** Its type schemas, sorted by path. */
|
|
198
|
+
types: TypeSchema[];
|
|
183
199
|
/** The bundle-root `index.md` `okf_version` value, as written. */
|
|
184
200
|
okfVersion?: unknown;
|
|
185
201
|
/** Every link in every markdown file, in path and position order. */
|
|
@@ -189,5 +205,4 @@ interface Tree {
|
|
|
189
205
|
/** Links from concepts (not from `index.md` or `log.md`) to the given concept. */
|
|
190
206
|
backlinks(id: string): Link[];
|
|
191
207
|
}
|
|
192
|
-
|
|
193
|
-
export { Verification 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 };
|
|
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.
|
|
3
|
+
"version": "0.9.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.
|
|
51
|
+
"@types/node": "^26.6.6",
|
|
52
52
|
"@vitest/coverage-v8": "^5.0.5",
|
|
53
|
-
"tsdown": "^0.23.
|
|
53
|
+
"tsdown": "^0.23.4",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
55
|
"vitest": "^5.0.5"
|
|
56
56
|
},
|