@okfit/core 0.11.8 → 0.12.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/Bundle.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { Concept } from "./Concept.js";
2
- import { basename, dirname } from "./internal/posixPath.js";
3
2
  import { ConceptId } from "./ConceptId.js";
4
- import { toFileOffset } from "./internal/position.js";
5
3
  import { Diagnostic, DiagnosticRange } from "./Diagnostic.js";
6
4
  import { IndexDocument } from "./IndexDocument.js";
7
5
  import { detectFence } from "./internal/fence.js";
8
6
  import { decodeConcept } from "./internal/frontmatter.js";
9
- import { LogDocument } from "./LogDocument.js";
7
+ import { toFileOffset } from "./internal/position.js";
8
+ import { basename, dirname } from "./internal/posixPath.js";
10
9
  import { OPTIONS, parseIndex, parseLog } from "./internal/reserved.js";
11
10
  import { DEFAULT_PRUNE, walk } from "./internal/walk.js";
11
+ import { LogDocument } from "./LogDocument.js";
12
12
  import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
13
13
  import { FrontmatterDecodeError, MarkdownDocument, YamlFrontmatter } from "@effected/markdown";
14
14
  import { DescendError } from "@effected/walker";
package/Concept.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AttestedComputation } from "./AttestedComputation.js";
2
- import { Timestamp } from "./Timestamp.js";
3
2
  import { Generated } from "./Generated.js";
4
3
  import { Integrity } from "./Integrity.js";
5
4
  import { Source, UsageWindow } from "./Source.js";
6
5
  import { Status } from "./Status.js";
6
+ import { Timestamp } from "./Timestamp.js";
7
7
  import { Verification } from "./Verification.js";
8
8
  import { Schema } from "effect";
9
9
 
package/Derive.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Actor } from "./Actor.js";
2
- import { indexEntry, indexFrontmatter, indexSection, logEntry } from "./internal/templates.js";
2
+ import { indexDocument, logEntry } from "./internal/templates.js";
3
3
  import { DateTime, Schema } from "effect";
4
4
 
5
5
  // src/Derive.ts
@@ -73,19 +73,19 @@ var Derive = class Derive {
73
73
  });
74
74
  groups.set(concept.frontmatter.type, entries);
75
75
  }
76
- const sections = [...groups.keys()].sort(compare).map((type) => {
77
- const entries = (groups.get(type) ?? []).sort((a, b) => compare(a.title, b.title));
78
- return indexSection(type, entries.map(indexEntry));
79
- });
76
+ const sections = [...groups.keys()].sort(compare).map((type) => ({
77
+ heading: type,
78
+ entries: (groups.get(type) ?? []).sort((a, b) => compare(a.title, b.title))
79
+ }));
80
80
  const subdirectories = [...options.subdirectories ?? []].sort(compare);
81
- if (subdirectories.length > 0) {
82
- const entries = subdirectories.map((name) => indexEntry({
81
+ if (subdirectories.length > 0) sections.push({
82
+ heading: "Subdirectories",
83
+ entries: subdirectories.map((name) => ({
83
84
  title: name,
84
85
  target: `${name}/index.md`
85
- }));
86
- sections.push(indexSection("Subdirectories", entries));
87
- }
88
- return (options.okfVersion === void 0 ? "" : indexFrontmatter(options.okfVersion)) + sections.join("\n");
86
+ }))
87
+ });
88
+ return indexDocument(sections, options.okfVersion);
89
89
  };
90
90
  /** `## <date>` plus one `* <item>` line per item, newline-terminated (D-36). */
91
91
  static renderLogEntry = (entry) => logEntry(entry.date, entry.items);
package/Graph.js CHANGED
@@ -20,7 +20,7 @@ const edgesOf = (concept, lookup) => {
20
20
  for (const ref of pathFieldsOf(concept.frontmatter)) {
21
21
  const resolved = resolvePathField(concept.path, ref.field, ref.raw, lookup);
22
22
  if (resolved._tag !== "node") continue;
23
- const span = frontmatterFieldSpan(concept.document, ref.raw);
23
+ const span = frontmatterFieldSpan(concept.document, ref);
24
24
  const position = span === void 0 ? {} : { position: DiagnosticRange.fromOffset(text, span.offset, span.length) };
25
25
  out.push({
26
26
  to: resolved.id,
package/Validate.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Diagnostic, LintCode } from "./Diagnostic.js";
2
2
  import { Graph as Graph$1 } from "./Graph.js";
3
- import { OkfitConfig } from "./OkfitConfig.js";
4
3
  import { LINT_RULES } from "./internal/lintRules.js";
4
+ import { OkfitConfig } from "./OkfitConfig.js";
5
5
  import { Schema } from "effect";
6
6
 
7
7
  // src/Validate.ts
package/index.d.ts CHANGED
@@ -511,7 +511,7 @@ interface StaleConcept {
511
511
  }
512
512
  /** Options for {@link Derive.renderIndex}. @public */
513
513
  interface RenderIndexOptions {
514
- /** Emits `---\nokf_version: "<v>"\n---\n\n` first; root index only (D-21). */
514
+ /** Emits a frontmatter block carrying only `okf_version` first; root index only (D-21). */
515
515
  readonly okfVersion?: string;
516
516
  /** Rendered as `* [name](name/index.md)` under a trailing `# Subdirectories` section. */
517
517
  readonly subdirectories?: ReadonlyArray<string>;
package/index.js CHANGED
@@ -1,21 +1,21 @@
1
1
  import { Actor, ActorPattern } from "./Actor.js";
2
2
  import { AttestedComputation, ComputationAttester, ComputationExecutor, ComputationParameter } from "./AttestedComputation.js";
3
- import { Timestamp } from "./Timestamp.js";
4
- import { Generated } from "./Generated.js";
5
- import { Digest, Integrity, IntegrityGenerated, IntegrityVerified } from "./Integrity.js";
6
- import { Source, UsageWindow } from "./Source.js";
7
- import { Status } from "./Status.js";
8
- import { Verification } from "./Verification.js";
3
+ import { Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, LoadedBundle, LoadedConcept } from "./Bundle.js";
9
4
  import { ATTESTED_COMPUTATION_TYPE, Concept } from "./Concept.js";
10
5
  import { ConceptId } from "./ConceptId.js";
6
+ import { Derive, Staleness, TrustTier } from "./Derive.js";
11
7
  import { ConformanceCode, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, LintCode } from "./Diagnostic.js";
8
+ import { Generated } from "./Generated.js";
9
+ import { Graph, GraphNodeKind, LinkGraph } from "./Graph.js";
12
10
  import { IndexDocument, IndexEntry, IndexSection } from "./IndexDocument.js";
11
+ import { Digest, Integrity, IntegrityGenerated, IntegrityVerified } from "./Integrity.js";
13
12
  import { LogDocument, LogGroup, LogItem } from "./LogDocument.js";
14
- import { Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, LoadedBundle, LoadedConcept } from "./Bundle.js";
15
- import { Derive, Staleness, TrustTier } from "./Derive.js";
16
- import { Graph, GraphNodeKind, LinkGraph } from "./Graph.js";
17
13
  import { CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigSchemaHost } from "./OkfitConfig.js";
14
+ import { Source, UsageWindow } from "./Source.js";
15
+ import { Status } from "./Status.js";
16
+ import { Timestamp } from "./Timestamp.js";
18
17
  import { Validate } from "./Validate.js";
18
+ import { Verification } from "./Verification.js";
19
19
 
20
20
  // src/index.ts
21
21
  /**
@@ -1,11 +1,11 @@
1
1
  import { AttestedComputation } from "../AttestedComputation.js";
2
- import { Timestamp } from "../Timestamp.js";
2
+ import { ATTESTED_COMPUTATION_TYPE, Concept } from "../Concept.js";
3
3
  import { Generated } from "../Generated.js";
4
4
  import { Integrity } from "../Integrity.js";
5
5
  import { Source, UsageWindow } from "../Source.js";
6
6
  import { Status } from "../Status.js";
7
+ import { Timestamp } from "../Timestamp.js";
7
8
  import { Verification } from "../Verification.js";
8
- import { ATTESTED_COMPUTATION_TYPE, Concept } from "../Concept.js";
9
9
  import { Result, Schema, SchemaIssue } from "effect";
10
10
 
11
11
  // src/internal/conceptDecode.ts
@@ -1,6 +1,6 @@
1
- import { frontmatterPathSpan } from "./yamlPathSpan.js";
2
1
  import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
3
2
  import { decodeConcept as decodeConcept$1 } from "./conceptDecode.js";
3
+ import { frontmatterPathSpan } from "./yamlPathSpan.js";
4
4
  import { Option } from "effect";
5
5
 
6
6
  // src/internal/frontmatter.ts
package/internal/links.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { basename, dirname, join, normalize } from "./posixPath.js";
2
+ import { findFrontmatterPathSpan } from "./yamlPathSpan.js";
2
3
  import { Option } from "effect";
3
4
 
4
5
  // src/internal/links.ts
@@ -94,39 +95,46 @@ const pathFieldsOf = (concept) => {
94
95
  const out = [];
95
96
  if (concept.resource !== void 0) out.push({
96
97
  field: "resource",
97
- raw: concept.resource
98
+ raw: concept.resource,
99
+ path: ["resource"]
98
100
  });
99
- for (const source of concept.sources ?? []) out.push({
101
+ for (const [index, source] of (concept.sources ?? []).entries()) out.push({
100
102
  field: "sources.resource",
101
- raw: source.resource
103
+ raw: source.resource,
104
+ path: [
105
+ "sources",
106
+ index,
107
+ "resource"
108
+ ]
102
109
  });
103
110
  const attested = concept.attested;
104
111
  if (attested?.computation !== void 0) out.push({
105
112
  field: "computation",
106
- raw: attested.computation
113
+ raw: attested.computation,
114
+ path: ["computation"]
107
115
  });
108
116
  if (attested?.executor !== void 0) out.push({
109
117
  field: "executor.resource",
110
- raw: attested.executor.resource
118
+ raw: attested.executor.resource,
119
+ path: ["executor", "resource"]
111
120
  });
112
121
  if (attested?.attester !== void 0) out.push({
113
122
  field: "attester.resource",
114
- raw: attested.attester.resource
123
+ raw: attested.attester.resource,
124
+ path: ["attester", "resource"]
115
125
  });
116
126
  return out;
117
127
  };
118
- /** File span of the first occurrence of `raw` in the frontmatter block: `fenceLine.length + terminator.length + indexInValue`. @internal */
119
- const frontmatterFieldSpan = (document, raw) => {
128
+ /**
129
+ * File span of a path-valued field's own YAML value, found by its YAML path rather than by searching
130
+ * the text, so a value repeated in another field or a comment ranges at the right place (okfit#353).
131
+ * `undefined` without frontmatter or when the path is absent.
132
+ *
133
+ * @internal
134
+ */
135
+ const frontmatterFieldSpan = (document, ref) => {
120
136
  const node = Option.getOrUndefined(document.frontmatter);
121
- if (node === void 0) return void 0;
122
- const at = node.value.indexOf(raw);
123
- if (at < 0) return void 0;
124
- const fence = node.format === "json" ? "---json" : node.format === "toml" ? "+++" : "---";
125
- const fenceEnd = node.position.start.offset + fence.length;
126
- return {
127
- offset: fenceEnd + (document.source.charCodeAt(fenceEnd) === 13 && document.source.charCodeAt(fenceEnd + 1) === 10 ? 2 : 1) + at,
128
- length: raw.length
129
- };
137
+ return node === void 0 ? void 0 : findFrontmatterPathSpan(document.source, node, ref.path);
130
138
  };
131
139
 
132
140
  export { frontmatterFieldSpan, isUrl, pathFieldsOf, resolvePathField, resolveTarget };
@@ -1,7 +1,7 @@
1
1
  import { Actor } from "../Actor.js";
2
+ import { Derive } from "../Derive.js";
2
3
  import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
3
4
  import { frontmatterPathRange } from "./frontmatter.js";
4
- import { Derive } from "../Derive.js";
5
5
  import { DateTime, Option } from "effect";
6
6
 
7
7
  // src/internal/lintRules.ts
@@ -1,18 +1,41 @@
1
+ import { Result } from "effect";
2
+ import { Frontmatter, Heading, Link, List, ListItem, Markdown, Paragraph, Root, Text } from "@effected/markdown";
3
+ import { Yaml } from "@effected/yaml";
4
+
1
5
  // src/internal/templates.ts
6
+ /** `* [Title](target) - description`, or without the tail when there is no description (D-36; spec §8). */
7
+ const entryNode = (entry) => ListItem.make({
8
+ spread: false,
9
+ children: [Paragraph.make({ children: [Link.make({
10
+ url: entry.target,
11
+ children: [Text.make({ value: entry.title })]
12
+ }), ...entry.description === void 0 || entry.description === "" ? [] : [Text.make({ value: ` - ${entry.description}` })]] })]
13
+ });
14
+ /** An H1 heading followed by a tight `*` list of its entries (the spec's own bullet). */
15
+ const sectionNodes = (section) => [Heading.make({
16
+ depth: 1,
17
+ children: [Text.make({ value: section.heading })]
18
+ }), List.make({
19
+ ordered: false,
20
+ spread: false,
21
+ bulletChar: "*",
22
+ children: section.entries.map(entryNode)
23
+ })];
2
24
  /**
3
- * Backslash-escape markdown-active characters (`\`, `<`, `>`, `*`, `_`, `` ` ``,
4
- * `[`, `]`) so plain text round-trips through a generated `index.md` as
5
- * literal text instead of being interpreted as inline HTML or emphasis
6
- * (issue #72). A single pass over the original text, so the backslashes it
7
- * inserts are never themselves re-escaped.
25
+ * A whole `index.md`: root frontmatter carrying only `okf_version` when given (D-21), then each section.
26
+ *
27
+ * Rendered by `@effected/markdown`'s emitter, so titles and descriptions are escaped only where markdown
28
+ * would otherwise read them as syntax and round-trip to the original text (issue #72), and a target the
29
+ * emitter cannot write bare (a space, for one) is written in angle brackets.
8
30
  */
9
- const escapeMarkdown = (text) => text.replace(/[\\<>*_`[\]]/g, (char) => `\\${char}`);
10
- /** `* [Title](target) - description`, or without the tail when there is no description (D-36; spec §8). */
11
- const indexEntry = (entry) => entry.description === void 0 || entry.description === "" ? `* [${escapeMarkdown(entry.title)}](${entry.target})` : `* [${escapeMarkdown(entry.title)}](${entry.target}) - ${escapeMarkdown(entry.description)}`;
12
- /** An H1 section: heading, blank line, entries, trailing newline. */
13
- const indexSection = (heading, entries) => `# ${heading}\n\n${entries.join("\n")}\n`;
14
- /** Root-index frontmatter carrying only `okf_version` (D-21). */
15
- const indexFrontmatter = (okfVersion) => `---\nokf_version: "${okfVersion}"\n---\n\n`;
31
+ const indexDocument = (sections, okfVersion) => {
32
+ const frontmatter = okfVersion === void 0 ? [] : [Frontmatter.make({
33
+ format: "yaml",
34
+ value: Result.getOrThrow(Yaml.stringifyResult({ okf_version: okfVersion })).replace(/\n$/, "")
35
+ })];
36
+ const root = Root.make({ children: [...frontmatter, ...sections.flatMap(sectionNodes)] });
37
+ return Result.getOrThrow(Markdown.stringifyResult(root));
38
+ };
16
39
  /** `## <date>`, a blank line, then one `* item` line per item (spec §9; S-32, MD022/MD032). */
17
40
  const logEntry = (date, items) => `${[
18
41
  `## ${date}`,
@@ -20,4 +43,4 @@ const logEntry = (date, items) => `${[
20
43
  ...items.map((item) => `* ${item}`)
21
44
  ].join("\n")}\n`;
22
45
 
23
- export { indexEntry, indexFrontmatter, indexSection, logEntry };
46
+ export { indexDocument, logEntry };
package/internal/walk.js CHANGED
@@ -18,7 +18,6 @@ const DEFAULT_PRUNE = ["node_modules", ".git"];
18
18
  * @public
19
19
  */
20
20
  const walk = (options) => Effect.gen(function* () {
21
- if (!Number.isInteger(options.maxDepth) || options.maxDepth < 1) return yield* Effect.die(/* @__PURE__ */ new Error(`walk: maxDepth must be a positive integer, received ${options.maxDepth}`));
22
21
  const pattern = yield* GlobPattern.compile("**/*", GlobPatternOptions.make({ dot: options.includeHidden })).pipe(Effect.orDie);
23
22
  const result = yield* descend(pattern, {
24
23
  cwd: options.root,
@@ -1,5 +1,5 @@
1
1
  import { toFileOffset } from "./position.js";
2
- import { Effect, Option, Result } from "effect";
2
+ import { Option, Result } from "effect";
3
3
  import { YamlDocument } from "@effected/yaml";
4
4
 
5
5
  // src/internal/yamlPathSpan.ts
@@ -17,7 +17,7 @@ const parsedCache = /* @__PURE__ */ new WeakMap();
17
17
  const parsedYamlOf = (node) => {
18
18
  const cached = parsedCache.get(node);
19
19
  if (cached !== void 0) return cached;
20
- const parsed = Effect.runSync(Effect.result(YamlDocument.parse(node.value)));
20
+ const parsed = YamlDocument.parseResult(node.value);
21
21
  parsedCache.set(node, parsed);
22
22
  return parsed;
23
23
  };
@@ -32,16 +32,23 @@ const parsedYamlOf = (node) => {
32
32
  *
33
33
  * @internal
34
34
  */
35
- const frontmatterPathSpan = (text, node, path) => {
36
- if (path.length === 0) return blockSpan(node);
35
+ const frontmatterPathSpan = (text, node, path) => path.length === 0 ? blockSpan(node) : findFrontmatterPathSpan(text, node, path) ?? blockSpan(node);
36
+ /**
37
+ * The file span of the YAML node at `path`, or `undefined` when there is none (or the re-parse is
38
+ * fatal): {@link frontmatterPathSpan} without its whole-block fallback, for a caller that would
39
+ * rather carry no range than a wrong one. Same quoting rule: a double-quoted scalar's span covers
40
+ * its quotes.
41
+ *
42
+ * @internal
43
+ */
44
+ const findFrontmatterPathSpan = (text, node, path) => {
37
45
  const parsed = parsedYamlOf(node);
38
- if (Result.isFailure(parsed) || parsed.success.contents === null) return blockSpan(node);
46
+ if (Result.isFailure(parsed) || parsed.success.contents === null) return void 0;
39
47
  const hit = parsed.success.contents.find(path);
40
- if (Option.isNone(hit)) return blockSpan(node);
41
- return {
48
+ return Option.isNone(hit) ? void 0 : {
42
49
  offset: toFileOffset(text, hit.value.offset),
43
50
  length: hit.value.length
44
51
  };
45
52
  };
46
53
 
47
- export { frontmatterPathSpan };
54
+ export { findFrontmatterPathSpan, frontmatterPathSpan };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okfit/core",
3
- "version": "0.11.8",
3
+ "version": "0.12.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,16 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "peerDependencies": {
40
- "@effected/config-file": "^0.22.0",
41
- "@effected/glob": "^0.16.0",
42
- "@effected/jsonc": "^0.21.0",
43
- "@effected/markdown": "^0.24.0",
44
- "@effected/schemastore": "^0.27.0",
45
- "@effected/source": "^0.1.0",
46
- "@effected/toml": "^0.17.0",
47
- "@effected/walker": "^0.22.0",
48
- "@effected/yaml": "^0.26.0",
49
- "effect": "^4.0.0"
40
+ "@effected/config-file": "^0.24.0",
41
+ "@effected/glob": "^0.18.0",
42
+ "@effected/jsonc": "^0.23.0",
43
+ "@effected/markdown": "^0.26.0",
44
+ "@effected/schemastore": "^0.29.0",
45
+ "@effected/source": "^0.3.0",
46
+ "@effected/toml": "^0.19.0",
47
+ "@effected/walker": "^0.25.0",
48
+ "@effected/yaml": "^0.28.0",
49
+ "effect": "~4.1.2"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=24.11.0"
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.60.0"
8
+ "packageVersion": "7.60.1"
9
9
  }
10
10
  ]
11
11
  }