@okfit/core 0.11.7 → 0.12.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/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/Diagnostic.js CHANGED
@@ -1,6 +1,6 @@
1
- import { lineCharacter } from "./internal/position.js";
2
1
  import { frontmatterPathSpan } from "./internal/yamlPathSpan.js";
3
2
  import { Option, Schema } from "effect";
3
+ import { LineIndex } from "@effected/source";
4
4
 
5
5
  // src/Diagnostic.ts
6
6
  /** @public */
@@ -61,9 +61,9 @@ var DiagnosticRange = class DiagnosticRange extends Schema.Class("DiagnosticRang
61
61
  line: Schema.Number,
62
62
  character: Schema.Number
63
63
  }) {
64
- /** Core's own offset-to-line/character helper over the file text (D-14, `internal/position.ts`). */
64
+ /** Builds a range from an offset over the file text; line breaks are the LSP rule (`\n`, `\r\n`, lone `\r`). */
65
65
  static fromOffset = (text, offset, length) => {
66
- const { line, character } = lineCharacter(text, offset);
66
+ const { line, character } = LineIndex.make(text).positionAt(offset);
67
67
  return DiagnosticRange.make({
68
68
  offset,
69
69
  length,
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/OkfitConfig.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Actor, ActorPattern } from "./Actor.js";
2
2
  import { Duration, Effect, Option, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
3
- import { ConfigFile } from "@effected/config-file";
3
+ import { ConfigFile, ConfigMerge } from "@effected/config-file";
4
4
  import { TomlCodec } from "@effected/config-file/toml";
5
5
  import { HostedSchema } from "@effected/schemastore";
6
6
 
@@ -420,37 +420,7 @@ const OkfitConfigWire = RawTable.pipe(Schema.decodeTo(okfitConfigFields, SchemaT
420
420
  };
421
421
  }
422
422
  })));
423
- const FORBIDDEN_KEYS = /* @__PURE__ */ new Set([
424
- "__proto__",
425
- "constructor",
426
- "prototype"
427
- ]);
428
- const isPlainObject = (value) => {
429
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
430
- const proto = Object.getPrototypeOf(value);
431
- return proto === Object.prototype || proto === null;
432
- };
433
- const define = (target, key, value) => {
434
- Object.defineProperty(target, key, {
435
- value,
436
- writable: true,
437
- enumerable: true,
438
- configurable: true
439
- });
440
- };
441
- const mergeRecords = (base, override) => {
442
- const result = {};
443
- for (const key of Object.keys(base)) if (!FORBIDDEN_KEYS.has(key)) define(result, key, base[key]);
444
- for (const key of Object.keys(override)) {
445
- if (FORBIDDEN_KEYS.has(key)) continue;
446
- const incoming = override[key];
447
- const current = result[key];
448
- if (Object.hasOwn(result, key) && isPlainObject(current) && isPlainObject(incoming)) define(result, key, mergeRecords(current, incoming));
449
- else define(result, key, incoming);
450
- }
451
- return result;
452
- };
453
- const merge = (base, override) => mergeRecords(base, override);
423
+ const merge = (base, override) => ConfigMerge.deep(base, override);
454
424
  const LINT_KEY = {
455
425
  "broken-links": "broken_links",
456
426
  "missing-index": "missing_index",
package/index.d.ts CHANGED
@@ -278,7 +278,7 @@ declare const DiagnosticRange_base: Schema.Class<DiagnosticRange, Schema.Struct<
278
278
  * @public
279
279
  */
280
280
  export declare class DiagnosticRange extends DiagnosticRange_base {
281
- /** Core's own offset-to-line/character helper over the file text (D-14, `internal/position.ts`). */
281
+ /** Builds a range from an offset over the file text; line breaks are the LSP rule (`\n`, `\r\n`, lone `\r`). */
282
282
  static readonly fromOffset: (text: string, offset: number, length: number) => DiagnosticRange;
283
283
  /**
284
284
  * Maps a frontmatter YAML path to the range of its own value inside `document.source`
@@ -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/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,27 +1,6 @@
1
1
  // src/internal/position.ts
2
2
  const LF = 10;
3
3
  const CR = 13;
4
- /** Line and character of `offset` within `text`; `\n`, `\r` and `\r\n` each count as one line break. @public */
5
- const lineCharacter = (text, offset) => {
6
- let line = 0;
7
- let lineStart = 0;
8
- const limit = Math.min(offset, text.length);
9
- for (let i = 0; i < limit; i++) {
10
- const code = text.charCodeAt(i);
11
- if (code === LF) {
12
- line++;
13
- lineStart = i + 1;
14
- } else if (code === CR) {
15
- if (i + 1 < text.length && text.charCodeAt(i + 1) === LF) i++;
16
- line++;
17
- lineStart = i + 1;
18
- }
19
- }
20
- return {
21
- line,
22
- character: offset - lineStart
23
- };
24
- };
25
4
  /**
26
5
  * File offset of the first frontmatter value character: the opening fence
27
6
  * plus its terminator (`\r\n` counts two, `\n` or `\r` one). Only meaningful
@@ -36,4 +15,4 @@ const frontmatterValueStart = (text) => {
36
15
  /** Map a `YamlDiagnostic.offset` or `YamlNode.offset` inside the frontmatter value to a whole-file offset. @public */
37
16
  const toFileOffset = (text, yamlOffset) => frontmatterValueStart(text) + yamlOffset;
38
17
 
39
- export { frontmatterValueStart, lineCharacter, toFileOffset };
18
+ export { frontmatterValueStart, toFileOffset };
@@ -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.7",
3
+ "version": "0.12.0",
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,15 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "peerDependencies": {
40
- "@effected/config-file": "^0.21.0",
41
- "@effected/glob": "^0.15.0",
42
- "@effected/jsonc": "^0.20.0",
43
- "@effected/markdown": "^0.23.0",
44
- "@effected/schemastore": "^0.26.0",
45
- "@effected/toml": "^0.16.0",
46
- "@effected/walker": "^0.21.0",
47
- "@effected/yaml": "^0.25.0",
48
- "effect": "^4.0.0"
40
+ "@effected/config-file": "^0.23.0",
41
+ "@effected/glob": "^0.17.0",
42
+ "@effected/jsonc": "^0.22.0",
43
+ "@effected/markdown": "^0.25.0",
44
+ "@effected/schemastore": "^0.28.0",
45
+ "@effected/source": "^0.2.0",
46
+ "@effected/toml": "^0.18.0",
47
+ "@effected/walker": "^0.24.0",
48
+ "@effected/yaml": "^0.27.0",
49
+ "effect": "~4.1.1"
49
50
  },
50
51
  "engines": {
51
52
  "node": ">=24.11.0"
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.4"
8
+ "packageVersion": "7.60.0"
9
9
  }
10
10
  ]
11
11
  }