@orkestrel/guide 0.0.9 → 0.0.11

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.
@@ -29,6 +29,75 @@ var EXTERNAL_SCHEMES = Object.freeze([
29
29
  "tel:"
30
30
  ]);
31
31
  //#endregion
32
+ //#region src/core/validators.ts
33
+ /**
34
+ * Whether `value` is one of the five documented {@link ExportKind} literals — the
35
+ * guard behind extracting a Surface table's `Kind` cell into a typed symbol.
36
+ *
37
+ * @param value - The candidate value
38
+ * @returns `true` when `value` is a valid {@link ExportKind}
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * isExportKind('class') // true
43
+ * isExportKind('enum') // false
44
+ * ```
45
+ */
46
+ var isExportKind = literalOf("type", "interface", "const", "function", "class");
47
+ /**
48
+ * Whether `value` is a well-formed {@link SurfaceSymbol} — a `name` string
49
+ * paired with a valid {@link ExportKind}.
50
+ *
51
+ * @param value - The value to test
52
+ * @returns `true` when `value` is a well-formed {@link SurfaceSymbol}
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * isSurfaceSymbol({ name: 'Markdown', kind: 'class' }) // true
57
+ * isSurfaceSymbol({ name: 'Markdown', kind: 'enum' }) // false
58
+ * ```
59
+ */
60
+ var isSurfaceSymbol = recordOf({
61
+ name: isString,
62
+ kind: isExportKind
63
+ });
64
+ /**
65
+ * Whether `value` is a well-formed {@link MethodGroup} — a backticked
66
+ * `interface` name paired with its documented `methods`.
67
+ *
68
+ * @param value - The value to test
69
+ * @returns `true` when `value` is a well-formed {@link MethodGroup}
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * isMethodGroup({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
74
+ * isMethodGroup({ interface: 'MarkdownInterface', methods: [1] }) // false
75
+ * ```
76
+ */
77
+ var isMethodGroup = recordOf({
78
+ interface: isString,
79
+ methods: arrayOf(isString)
80
+ });
81
+ /**
82
+ * Whether `value` is a well-formed {@link ManifestEntry} — a `## By concept`
83
+ * manifest row, its `source` accepting either a single directory or several.
84
+ *
85
+ * @param value - The value to test
86
+ * @returns `true` when `value` is a well-formed {@link ManifestEntry}
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * isManifestEntry({ concept: 'Markdown', spec: 'guides/src/markdown.md', source: 'src/core', tests: 'tests/src/core' }) // true
91
+ * isManifestEntry({ concept: 1 }) // false
92
+ * ```
93
+ */
94
+ var isManifestEntry = recordOf({
95
+ concept: isString,
96
+ spec: isString,
97
+ source: unionOf(isString, arrayOf(isString)),
98
+ tests: isString
99
+ });
100
+ //#endregion
32
101
  //#region src/core/helpers.ts
33
102
  /**
34
103
  * Extract aligned physical source-line records in one character traversal.
@@ -562,6 +631,23 @@ function normalizeDirectories(module) {
562
631
  return directories;
563
632
  }
564
633
  /**
634
+ * The stable cache key for a {@link GuideModule}. Directories normalize before
635
+ * joining, so equivalent module spellings share one key. The NUL separator
636
+ * cannot occur in filesystem-backed canonical-segment inventory keys, so no
637
+ * directory boundary can collide with directory text.
638
+ *
639
+ * @param module - The module scope to key
640
+ * @returns The normalized directories joined by NUL
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * moduleKey(['src/core', 'src/browser']) // 'src/core\0src/browser'
645
+ * ```
646
+ */
647
+ function moduleKey(module) {
648
+ return normalizeDirectories(module).join("\0");
649
+ }
650
+ /**
565
651
  * The exact opaque file-inventory keys belonging under any canonical
566
652
  * {@link GuideModule} directory, sorted. `'.'` selects canonical root-relative
567
653
  * keys without accepting `/`, `./`, or `../` aliases. Every selected exact
@@ -622,6 +708,24 @@ function findMissing(names, source) {
622
708
  return names.filter((name) => !existing.has(name));
623
709
  }
624
710
  /**
711
+ * The fences whose language is absent from the caller's listed languages.
712
+ * Untagged fences are always returned because they have no language to list.
713
+ *
714
+ * @param fences - The guide fences to check
715
+ * @param languages - The listed language tags
716
+ * @returns The unlisted fences in input order
717
+ *
718
+ * @example
719
+ * ```ts
720
+ * findUnlisted([{ language: 'typescript', code: 'walk()' }], ['ts'])
721
+ * // [{ language: 'typescript', code: 'walk()' }]
722
+ * ```
723
+ */
724
+ function findUnlisted(fences, languages) {
725
+ const listed = new Set(languages);
726
+ return fences.filter((fence) => fence.language === void 0 || !listed.has(fence.language));
727
+ }
728
+ /**
625
729
  * The symbol-key set-difference between two symbol lists — `symbols` present but
626
730
  * absent from `source`, compared by {@link symbolKey} so a symbol can drift in
627
731
  * neither name nor kind.
@@ -844,77 +948,6 @@ function kindIndex(table) {
844
948
  }).trim() === "Kind") return index;
845
949
  }
846
950
  }
847
- //#endregion
848
- //#region src/core/validators.ts
849
- /**
850
- * Whether `value` is one of the five documented {@link ExportKind} literals — the
851
- * guard behind extracting a Surface table's `Kind` cell into a typed symbol.
852
- *
853
- * @param value - The candidate value
854
- * @returns `true` when `value` is a valid {@link ExportKind}
855
- *
856
- * @example
857
- * ```ts
858
- * isExportKind('class') // true
859
- * isExportKind('enum') // false
860
- * ```
861
- */
862
- var isExportKind = literalOf("type", "interface", "const", "function", "class");
863
- /**
864
- * Whether `value` is a well-formed {@link SurfaceSymbol} — a `name` string
865
- * paired with a valid {@link ExportKind}.
866
- *
867
- * @param value - The value to test
868
- * @returns `true` when `value` is a well-formed {@link SurfaceSymbol}
869
- *
870
- * @example
871
- * ```ts
872
- * isSurfaceSymbol({ name: 'Markdown', kind: 'class' }) // true
873
- * isSurfaceSymbol({ name: 'Markdown', kind: 'enum' }) // false
874
- * ```
875
- */
876
- var isSurfaceSymbol = recordOf({
877
- name: isString,
878
- kind: isExportKind
879
- });
880
- /**
881
- * Whether `value` is a well-formed {@link MethodGroup} — a backticked
882
- * `interface` name paired with its documented `methods`.
883
- *
884
- * @param value - The value to test
885
- * @returns `true` when `value` is a well-formed {@link MethodGroup}
886
- *
887
- * @example
888
- * ```ts
889
- * isMethodGroup({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
890
- * isMethodGroup({ interface: 'MarkdownInterface', methods: [1] }) // false
891
- * ```
892
- */
893
- var isMethodGroup = recordOf({
894
- interface: isString,
895
- methods: arrayOf(isString)
896
- });
897
- /**
898
- * Whether `value` is a well-formed {@link ManifestEntry} — a `## By concept`
899
- * manifest row, its `source` accepting either a single directory or several.
900
- *
901
- * @param value - The value to test
902
- * @returns `true` when `value` is a well-formed {@link ManifestEntry}
903
- *
904
- * @example
905
- * ```ts
906
- * isManifestEntry({ concept: 'Markdown', spec: 'guides/src/markdown.md', source: 'src/core', tests: 'tests/src/core' }) // true
907
- * isManifestEntry({ concept: 1 }) // false
908
- * ```
909
- */
910
- var isManifestEntry = recordOf({
911
- concept: isString,
912
- spec: isString,
913
- source: unionOf(isString, arrayOf(isString)),
914
- tests: isString
915
- });
916
- //#endregion
917
- //#region src/core/parsers.ts
918
951
  /**
919
952
  * The module-scope exports declared in one file's source text — matches
920
953
  * `export (async)? (function(\*)?|class|const|interface|type) Name`, deduped
@@ -1372,22 +1405,27 @@ function exampleMethods(lines) {
1372
1405
  return Array.from(new Set(methods)).sort();
1373
1406
  }
1374
1407
  /**
1375
- * Every ```ts fenced code block's body text anywhere in the guide document —
1376
- * a full AST walk so a fence nested inside a blockquote or list still counts.
1408
+ * Every fenced code block anywhere in the guide document. A full AST walk
1409
+ * includes fences nested inside blockquotes and lists.
1377
1410
  *
1378
1411
  * @param document - The parsed guide document
1379
- * @returns Every `ts`-lang fence's verbatim code, in walk order
1412
+ * @returns Every fence's language and verbatim code, in document order
1380
1413
  *
1381
1414
  * @example
1382
1415
  * ```ts
1383
- * extractPatterns(document) // ["import { X } from './x.js'\nX()"]
1416
+ * extractFences(document) // [{ language: 'ts', code: "import { X } from './x.js'\nX()" }]
1384
1417
  * ```
1385
1418
  */
1386
- function extractPatterns(document) {
1387
- const patterns = [];
1388
- for (const node of walkNodes(document)) if (isCodeBlockNode(node) && node.lang === "ts") patterns.push(node.code);
1389
- return patterns;
1419
+ function extractFences(document) {
1420
+ const fences = [];
1421
+ for (const node of walkNodes(document)) if (isCodeBlockNode(node)) fences.push({
1422
+ language: node.lang,
1423
+ code: node.code
1424
+ });
1425
+ return fences;
1390
1426
  }
1427
+ //#endregion
1428
+ //#region src/core/parsers.ts
1391
1429
  /**
1392
1430
  * Parse a `## By concept` manifest table into its {@link ManifestEntry} rows —
1393
1431
  * each row's Concept cell (flattened text), Spec / Tests cells (a single link
@@ -1505,7 +1543,7 @@ var manifestEntryShape = objectShape({
1505
1543
  /**
1506
1544
  * A stateful, structured view over one parsed guide — the six documented
1507
1545
  * projections (`sections` / `surface` / `methods` / `links` / `tests` /
1508
- * `patterns`) are extracted once at construction and cached.
1546
+ * `fences`) are extracted once at construction and cached.
1509
1547
  *
1510
1548
  * @remarks
1511
1549
  * Pure: parses `source` once via `@orkestrel/markdown` and never touches the
@@ -1527,7 +1565,7 @@ var Guide = class {
1527
1565
  #methods;
1528
1566
  #links;
1529
1567
  #tests;
1530
- #patterns;
1568
+ #fences;
1531
1569
  constructor(source) {
1532
1570
  const document = createMarkdown(source).document;
1533
1571
  this.#sections = document.children.filter(isHeadingNode).filter((heading) => heading.level === 2).map((heading) => flattenText(heading).trim());
@@ -1535,7 +1573,7 @@ var Guide = class {
1535
1573
  this.#methods = extractMethods(document);
1536
1574
  this.#links = extractLinks(document);
1537
1575
  this.#tests = extractTests(document);
1538
- this.#patterns = extractPatterns(document);
1576
+ this.#fences = extractFences(document);
1539
1577
  }
1540
1578
  sections() {
1541
1579
  return this.#sections;
@@ -1552,12 +1590,12 @@ var Guide = class {
1552
1590
  tests() {
1553
1591
  return this.#tests;
1554
1592
  }
1555
- patterns() {
1556
- return this.#patterns;
1593
+ fences() {
1594
+ return this.#fences;
1557
1595
  }
1558
1596
  };
1559
1597
  //#endregion
1560
- //#region src/core/Source.ts
1598
+ //#region src/core/sources/Source.ts
1561
1599
  /**
1562
1600
  * A pure `SourceInterface` — reflects a module scope's intentional direct
1563
1601
  * declarations, conventional barrel-reachable surface, and member methods over
@@ -1716,11 +1754,52 @@ var Source = class {
1716
1754
  }
1717
1755
  };
1718
1756
  //#endregion
1757
+ //#region src/core/sources/SourceManager.ts
1758
+ /**
1759
+ * Resolves a consumer-owned import-specifier policy into pure source views and
1760
+ * caches those views by module, so aliases for one module share one entity.
1761
+ * Unmapped specifiers remain foreign to the consumer and return `undefined`.
1762
+ *
1763
+ * @example
1764
+ * ```ts
1765
+ * import { SourceManager } from '@orkestrel/guide'
1766
+ *
1767
+ * const sources = new SourceManager({
1768
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
1769
+ * modules: { '@scope/package': 'src/core' },
1770
+ * })
1771
+ * sources.source('@scope/package')?.surface()
1772
+ * ```
1773
+ */
1774
+ var SourceManager = class {
1775
+ #files;
1776
+ #modules;
1777
+ #sources = /* @__PURE__ */ new Map();
1778
+ constructor(options) {
1779
+ this.#files = options.files;
1780
+ this.#modules = options.modules;
1781
+ }
1782
+ source(specifier) {
1783
+ if (!Object.hasOwn(this.#modules, specifier)) return void 0;
1784
+ const module = this.#modules[specifier];
1785
+ if (module === void 0) return void 0;
1786
+ const key = moduleKey(module);
1787
+ const existing = this.#sources.get(key);
1788
+ if (existing !== void 0) return existing;
1789
+ const source = new Source({
1790
+ files: this.#files,
1791
+ module
1792
+ });
1793
+ this.#sources.set(key, source);
1794
+ return source;
1795
+ }
1796
+ };
1797
+ //#endregion
1719
1798
  //#region src/core/factories.ts
1720
1799
  /**
1721
1800
  * Create a structured {@link GuideInterface} view over one guide's markdown
1722
1801
  * source — parses once and caches its `sections` / `surface` / `methods` /
1723
- * `links` / `tests` / `patterns` projections.
1802
+ * `links` / `tests` / `fences` projections.
1724
1803
  *
1725
1804
  * @param source - The guide's markdown source text
1726
1805
  * @returns A working {@link GuideInterface}
@@ -1758,6 +1837,27 @@ function createSource(options) {
1758
1837
  return new Source(options);
1759
1838
  }
1760
1839
  /**
1840
+ * Create a {@link SourceManagerInterface} that resolves the consumer's local
1841
+ * import specifiers and shares one source view per module.
1842
+ *
1843
+ * @param options - The shared file inventory and specifier-to-module policy
1844
+ * @returns A source manager over the supplied policy
1845
+ *
1846
+ * @example
1847
+ * ```ts
1848
+ * import { createSourceManager } from '@orkestrel/guide'
1849
+ *
1850
+ * const sources = createSourceManager({
1851
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
1852
+ * modules: { '@scope/package': 'src/core' },
1853
+ * })
1854
+ * sources.source('@scope/package')?.surface()
1855
+ * ```
1856
+ */
1857
+ function createSourceManager(options) {
1858
+ return new SourceManager(options);
1859
+ }
1860
+ /**
1761
1861
  * Compile the {@link surfaceSymbolShape} into a {@link ContractInterface} for
1762
1862
  * {@link SurfaceSymbol} — a guard, coercing parser, JSON Schema, and seeded
1763
1863
  * generator from one shape declaration (AGENTS §14).
@@ -1812,6 +1912,6 @@ function createManifestEntryContract() {
1812
1912
  return createContract(manifestEntryShape);
1813
1913
  }
1814
1914
  //#endregion
1815
- export { EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, TESTS, cellLinks, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSurfaceSymbolContract, declarationBody, exampleMethods, examplesFrom, exportsFrom, extractExampleLines, extractLinks, extractMethods, extractPatterns, extractSourceLines, extractSurface, extractTests, fenceImports, findMissing, findUnexampled, firstCode, hasCanonicalSegments, hiddenFrom, identifierOf, isExportKind, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, kindIndex, manifestEntryShape, memberMethods, methodGroupShape, missingSymbols, normalizeDirectories, parseManifest, resolveLink, resolvePath, sectionBlocks, selectModuleKeys, surfaceSymbolShape, symbolKey };
1915
+ export { EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, SourceManager, TESTS, cellLinks, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSourceManager, createSurfaceSymbolContract, declarationBody, exampleMethods, examplesFrom, exportsFrom, extractExampleLines, extractFences, extractLinks, extractMethods, extractSourceLines, extractSurface, extractTests, fenceImports, findMissing, findUnexampled, findUnlisted, firstCode, hasCanonicalSegments, hiddenFrom, identifierOf, isExportKind, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, kindIndex, manifestEntryShape, memberMethods, methodGroupShape, missingSymbols, moduleKey, normalizeDirectories, parseManifest, resolveLink, resolvePath, sectionBlocks, selectModuleKeys, surfaceSymbolShape, symbolKey };
1816
1916
 
1817
1917
  //# sourceMappingURL=index.js.map