@okfit/core 0.10.0 → 0.11.1
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/Derive.js +13 -0
- package/Graph.js +20 -0
- package/index.d.ts +32 -1
- package/internal/links.js +16 -13
- package/internal/lintRules.js +1 -1
- package/package.json +9 -9
package/Derive.js
CHANGED
|
@@ -102,6 +102,19 @@ var Derive = class Derive {
|
|
|
102
102
|
if (groups.length === 0) return `# ${title}\n`;
|
|
103
103
|
return `# ${title}\n\n${groups.map(Derive.renderLogEntry).join("\n")}`;
|
|
104
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Every directory that owes an `index.md`: each directory holding a concept, plus its ancestors up to
|
|
107
|
+
* (not including) the bundle root, which a parent index links to even when it holds no concept itself.
|
|
108
|
+
* The root (`""`) is included only when it holds a concept. Sorted.
|
|
109
|
+
*/
|
|
110
|
+
static indexDirectories = (bundle) => {
|
|
111
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
112
|
+
for (const dir of bundle.directories) {
|
|
113
|
+
dirs.add(dir);
|
|
114
|
+
for (let ancestor = dirnameOf(dir); ancestor !== ""; ancestor = dirnameOf(ancestor)) dirs.add(ancestor);
|
|
115
|
+
}
|
|
116
|
+
return [...dirs].sort();
|
|
117
|
+
};
|
|
105
118
|
/** Index text for `dir` from the concepts directly in it plus its immediate child directories; no frontmatter. */
|
|
106
119
|
static synthesizeIndex = (bundle, dir) => {
|
|
107
120
|
const prefix = dir === "" ? "" : `${dir}/`;
|
package/Graph.js
CHANGED
|
@@ -116,6 +116,18 @@ var LinkGraph = class LinkGraph {
|
|
|
116
116
|
return [...new Set(pick(this.graph, at))].flatMap((next) => Option.toArray(Graph.getNode(this.graph, next)));
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
|
+
const indexes = /* @__PURE__ */ new WeakMap();
|
|
120
|
+
/** The lookup sets for one loaded bundle, built once: a bundle is immutable after load. */
|
|
121
|
+
const indexOf = (bundle) => {
|
|
122
|
+
const cached = indexes.get(bundle);
|
|
123
|
+
if (cached !== void 0) return cached;
|
|
124
|
+
const built = {
|
|
125
|
+
files: new Set(bundle.files),
|
|
126
|
+
concepts: new Set(bundle.concepts.keys())
|
|
127
|
+
};
|
|
128
|
+
indexes.set(bundle, built);
|
|
129
|
+
return built;
|
|
130
|
+
};
|
|
119
131
|
/**
|
|
120
132
|
* Static facade building a {@link LinkGraph} from a loaded bundle (D-6).
|
|
121
133
|
*
|
|
@@ -124,6 +136,14 @@ var LinkGraph = class LinkGraph {
|
|
|
124
136
|
var Graph$1 = class {
|
|
125
137
|
constructor() {}
|
|
126
138
|
/**
|
|
139
|
+
* Pure. Resolve `raw`, written in the file at bundle-relative `from`, the way the graph does; `field`
|
|
140
|
+
* applies the path-field rules (a `sources.resource` descriptor).
|
|
141
|
+
*/
|
|
142
|
+
static resolve = (bundle, from, raw, field) => {
|
|
143
|
+
const lookup = indexOf(bundle);
|
|
144
|
+
return field === void 0 ? resolveTarget(from, raw, lookup) : resolvePathField(from, field, raw, lookup);
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
127
147
|
* Pure. Body links come from `document.links`, path fields from the frontmatter (D-23, D-24).
|
|
128
148
|
* Placeholder `missing` nodes are added before their edge because `Graph.addEdge` throws on an absent endpoint.
|
|
129
149
|
*/
|
package/index.d.ts
CHANGED
|
@@ -577,6 +577,12 @@ export declare class Derive {
|
|
|
577
577
|
static readonly renderLog: (groups: ReadonlyArray<LogEntry>, options?: {
|
|
578
578
|
readonly title?: string;
|
|
579
579
|
}) => string;
|
|
580
|
+
/**
|
|
581
|
+
* Every directory that owes an `index.md`: each directory holding a concept, plus its ancestors up to
|
|
582
|
+
* (not including) the bundle root, which a parent index links to even when it holds no concept itself.
|
|
583
|
+
* The root (`""`) is included only when it holds a concept. Sorted.
|
|
584
|
+
*/
|
|
585
|
+
static readonly indexDirectories: (bundle: LoadedBundle) => ReadonlyArray<string>;
|
|
580
586
|
/** Index text for `dir` from the concepts directly in it plus its immediate child directories; no frontmatter. */
|
|
581
587
|
static readonly synthesizeIndex: (bundle: LoadedBundle, dir: string) => string;
|
|
582
588
|
}
|
|
@@ -593,6 +599,26 @@ export declare const GraphNodeKind: Schema.Literals<readonly ["concept", "file",
|
|
|
593
599
|
export type GraphNodeKind = typeof GraphNodeKind.Type;
|
|
594
600
|
/** Frontmatter fields whose value is a bundle path (D-23). @public */
|
|
595
601
|
type PathField = "resource" | "sources.resource" | "computation" | "executor.resource" | "attester.resource";
|
|
602
|
+
/**
|
|
603
|
+
* How one reference resolved (D-23, D-24); `via` says which D-23 branch produced a node: `rooted` (a leading
|
|
604
|
+
* `/`), `file` (against the linking file's directory) or `root` (a bare path against the bundle root).
|
|
605
|
+
*
|
|
606
|
+
* @public
|
|
607
|
+
*/
|
|
608
|
+
type LinkResolution = {
|
|
609
|
+
readonly _tag: "url";
|
|
610
|
+
} | {
|
|
611
|
+
readonly _tag: "self";
|
|
612
|
+
} | {
|
|
613
|
+
readonly _tag: "external";
|
|
614
|
+
} | {
|
|
615
|
+
readonly _tag: "descriptor";
|
|
616
|
+
} | {
|
|
617
|
+
readonly _tag: "node";
|
|
618
|
+
readonly id: string;
|
|
619
|
+
readonly kind: GraphNodeKind;
|
|
620
|
+
readonly via: "rooted" | "file" | "root";
|
|
621
|
+
};
|
|
596
622
|
/** A node: a concept id, or a bundle-relative path with extension for `file` and `missing` nodes. @public */
|
|
597
623
|
interface GraphNode {
|
|
598
624
|
readonly id: string;
|
|
@@ -646,6 +672,11 @@ export declare class LinkGraph {
|
|
|
646
672
|
*/
|
|
647
673
|
export declare class Graph {
|
|
648
674
|
private constructor();
|
|
675
|
+
/**
|
|
676
|
+
* Pure. Resolve `raw`, written in the file at bundle-relative `from`, the way the graph does; `field`
|
|
677
|
+
* applies the path-field rules (a `sources.resource` descriptor).
|
|
678
|
+
*/
|
|
679
|
+
static readonly resolve: (bundle: LoadedBundle, from: string, raw: string, field?: PathField) => LinkResolution;
|
|
649
680
|
/**
|
|
650
681
|
* Pure. Body links come from `document.links`, path fields from the frontmatter (D-23, D-24).
|
|
651
682
|
* Placeholder `missing` nodes are added before their edge because `Graph.addEdge` throws on an absent endpoint.
|
|
@@ -1078,5 +1109,5 @@ export declare class Validate {
|
|
|
1078
1109
|
*/
|
|
1079
1110
|
export declare const OKF_SPEC_VERSION: "0.2";
|
|
1080
1111
|
//#endregion
|
|
1081
|
-
export type { ActorForm, BundleLoadError, BundleLoadOptions, GraphEdge, GraphLink, GraphNode, LogEntry, OkfitConfigFields, PathField, RenderIndexOptions, StaleConcept, ValidateOptions, ValidationReport };
|
|
1112
|
+
export type { ActorForm, BundleLoadError, BundleLoadOptions, GraphEdge, GraphLink, GraphNode, LinkResolution, LogEntry, OkfitConfigFields, PathField, RenderIndexOptions, StaleConcept, ValidateOptions, ValidationReport };
|
|
1082
1113
|
//# sourceMappingURL=index.d.ts.map
|
package/internal/links.js
CHANGED
|
@@ -23,33 +23,36 @@ const isReserved = (path) => {
|
|
|
23
23
|
};
|
|
24
24
|
const escapes = (path) => path === ".." || path.startsWith("../");
|
|
25
25
|
const withIndex = (candidate) => candidate.endsWith("/") ? `${candidate}index.md` : candidate;
|
|
26
|
-
const existing = (path, index) => {
|
|
26
|
+
const existing = (path, index, via) => {
|
|
27
27
|
if (!index.files.has(path)) return void 0;
|
|
28
28
|
if (path.endsWith(".md") && !isReserved(path)) {
|
|
29
29
|
const id = path.slice(0, -3);
|
|
30
30
|
if (index.concepts.has(id)) return {
|
|
31
31
|
_tag: "node",
|
|
32
32
|
id,
|
|
33
|
-
kind: "concept"
|
|
33
|
+
kind: "concept",
|
|
34
|
+
via
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
return {
|
|
37
38
|
_tag: "node",
|
|
38
39
|
id: path,
|
|
39
|
-
kind: "file"
|
|
40
|
+
kind: "file",
|
|
41
|
+
via
|
|
40
42
|
};
|
|
41
43
|
};
|
|
42
|
-
const lookup = (candidate, index) => {
|
|
44
|
+
const lookup = (candidate, index, via) => {
|
|
43
45
|
const path = withIndex(candidate);
|
|
44
46
|
if (path === "." || path === "") return void 0;
|
|
45
|
-
const direct = existing(path, index);
|
|
47
|
+
const direct = existing(path, index, via);
|
|
46
48
|
if (direct !== void 0) return direct;
|
|
47
|
-
return basename(path).includes(".") ? void 0 : existing(`${path}.md`, index);
|
|
49
|
+
return basename(path).includes(".") ? void 0 : existing(`${path}.md`, index, via);
|
|
48
50
|
};
|
|
49
|
-
const missing = (candidate) => ({
|
|
51
|
+
const missing = (candidate, via) => ({
|
|
50
52
|
_tag: "node",
|
|
51
53
|
id: withIndex(candidate),
|
|
52
|
-
kind: "missing"
|
|
54
|
+
kind: "missing",
|
|
55
|
+
via
|
|
53
56
|
});
|
|
54
57
|
/** Resolve a body link or path field from `from` (the linking file's bundle-relative path), order A-D (D-23). @internal */
|
|
55
58
|
const resolveTarget = (from, raw, index) => {
|
|
@@ -61,21 +64,21 @@ const resolveTarget = (from, raw, index) => {
|
|
|
61
64
|
const rooted = target.slice(1);
|
|
62
65
|
const candidate = rooted === "" ? "index.md" : normalize(rooted);
|
|
63
66
|
if (escapes(candidate)) return { _tag: "external" };
|
|
64
|
-
return lookup(candidate, index) ?? missing(candidate);
|
|
67
|
+
return lookup(candidate, index, "rooted") ?? missing(candidate, "rooted");
|
|
65
68
|
}
|
|
66
69
|
const relative = target.startsWith("./") || target.startsWith("../");
|
|
67
70
|
const fileRelative = join(dirname(from), target);
|
|
68
71
|
if (escapes(fileRelative)) return { _tag: "external" };
|
|
69
|
-
const hitB = lookup(fileRelative, index);
|
|
72
|
+
const hitB = lookup(fileRelative, index, "file");
|
|
70
73
|
if (hitB !== void 0) return hitB;
|
|
71
74
|
if (!relative) {
|
|
72
75
|
const rootRelative = normalize(target);
|
|
73
76
|
if (escapes(rootRelative)) return { _tag: "external" };
|
|
74
|
-
const hitC = lookup(rootRelative, index);
|
|
77
|
+
const hitC = lookup(rootRelative, index, "root");
|
|
75
78
|
if (hitC !== void 0) return hitC;
|
|
76
|
-
if (target.includes("/")) return missing(rootRelative);
|
|
79
|
+
if (target.includes("/")) return missing(rootRelative, "root");
|
|
77
80
|
}
|
|
78
|
-
return missing(fileRelative);
|
|
81
|
+
return missing(fileRelative, "file");
|
|
79
82
|
};
|
|
80
83
|
/** Field-aware resolution (D-24): a `sources.resource` with whitespace, or that resolves to nothing, is a descriptor. @internal */
|
|
81
84
|
const resolvePathField = (from, field, raw, index) => {
|
package/internal/lintRules.js
CHANGED
|
@@ -257,7 +257,7 @@ const brokenLinks = rule("broken-links", (context, severity) => {
|
|
|
257
257
|
}
|
|
258
258
|
return [...dangling, ...anchors];
|
|
259
259
|
});
|
|
260
|
-
const missingIndex = rule("missing-index", (context, severity) => context.bundle.
|
|
260
|
+
const missingIndex = rule("missing-index", (context, severity) => Derive.indexDirectories(context.bundle).filter((dir) => !context.bundle.indexes.has(dir)).map((dir) => {
|
|
261
261
|
const message = `Directory "${dir === "" ? "." : dir}" has no index.md`;
|
|
262
262
|
return diagnostic(dir === "" ? "index.md" : `${dir}/index.md`, "missing-index", severity, message, void 0);
|
|
263
263
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Spec-level Open Knowledge Format (OKF) v0.2 schemas, bundle loading, graph, derivation, and validation for Effect.",
|
|
6
6
|
"keywords": [
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@effected/config-file": "^0.
|
|
41
|
-
"@effected/glob": "^0.
|
|
42
|
-
"@effected/jsonc": "^0.
|
|
43
|
-
"@effected/markdown": "^0.
|
|
44
|
-
"@effected/schemastore": "^0.
|
|
45
|
-
"@effected/toml": "^0.
|
|
46
|
-
"@effected/walker": "^0.
|
|
47
|
-
"@effected/yaml": "^0.
|
|
40
|
+
"@effected/config-file": "^0.16.0",
|
|
41
|
+
"@effected/glob": "^0.12.0",
|
|
42
|
+
"@effected/jsonc": "^0.17.0",
|
|
43
|
+
"@effected/markdown": "^0.17.0",
|
|
44
|
+
"@effected/schemastore": "^0.23.0",
|
|
45
|
+
"@effected/toml": "^0.13.0",
|
|
46
|
+
"@effected/walker": "^0.17.0",
|
|
47
|
+
"@effected/yaml": "^0.21.0",
|
|
48
48
|
"effect": "^4.0.0"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|