@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.
@@ -26,7 +26,7 @@ export declare function cellLinks(cell: readonly InlineNode[]): readonly string[
26
26
  /**
27
27
  * Create a structured {@link GuideInterface} view over one guide's markdown
28
28
  * source — parses once and caches its `sections` / `surface` / `methods` /
29
- * `links` / `tests` / `patterns` projections.
29
+ * `links` / `tests` / `fences` projections.
30
30
  *
31
31
  * @param source - The guide's markdown source text
32
32
  * @returns A working {@link GuideInterface}
@@ -95,6 +95,26 @@ export declare function createMethodGroupContract(): ContractInterface<MethodGro
95
95
  */
96
96
  export declare function createSource(options: SourceOptions): SourceInterface;
97
97
 
98
+ /**
99
+ * Create a {@link SourceManagerInterface} that resolves the consumer's local
100
+ * import specifiers and shares one source view per module.
101
+ *
102
+ * @param options - The shared file inventory and specifier-to-module policy
103
+ * @returns A source manager over the supplied policy
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { createSourceManager } from '@orkestrel/guide'
108
+ *
109
+ * const sources = createSourceManager({
110
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
111
+ * modules: { '@scope/package': 'src/core' },
112
+ * })
113
+ * sources.source('@scope/package')?.surface()
114
+ * ```
115
+ */
116
+ export declare function createSourceManager(options: SourceManagerOptions): SourceManagerInterface;
117
+
98
118
  /**
99
119
  * Compile the {@link surfaceSymbolShape} into a {@link ContractInterface} for
100
120
  * {@link SurfaceSymbol} — a guard, coercing parser, JSON Schema, and seeded
@@ -235,6 +255,20 @@ export declare const EXTERNAL_SCHEMES: readonly string[];
235
255
  */
236
256
  export declare function extractExampleLines(lines: readonly SourceLine[]): readonly SourceLine[];
237
257
 
258
+ /**
259
+ * Every fenced code block anywhere in the guide document. A full AST walk
260
+ * includes fences nested inside blockquotes and lists.
261
+ *
262
+ * @param document - The parsed guide document
263
+ * @returns Every fence's language and verbatim code, in document order
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * extractFences(document) // [{ language: 'ts', code: "import { X } from './x.js'\nX()" }]
268
+ * ```
269
+ */
270
+ export declare function extractFences(document: MarkdownDocument): readonly GuideFence[];
271
+
238
272
  /**
239
273
  * Every link href in the guide document, including table cells — a full,
240
274
  * depth-first walk of the whole AST.
@@ -264,20 +298,6 @@ export declare function extractLinks(document: MarkdownDocument): readonly strin
264
298
  */
265
299
  export declare function extractMethods(document: MarkdownDocument): readonly MethodGroup[];
266
300
 
267
- /**
268
- * Every ```ts fenced code block's body text anywhere in the guide document —
269
- * a full AST walk so a fence nested inside a blockquote or list still counts.
270
- *
271
- * @param document - The parsed guide document
272
- * @returns Every `ts`-lang fence's verbatim code, in walk order
273
- *
274
- * @example
275
- * ```ts
276
- * extractPatterns(document) // ["import { X } from './x.js'\nX()"]
277
- * ```
278
- */
279
- export declare function extractPatterns(document: MarkdownDocument): readonly string[];
280
-
281
301
  /**
282
302
  * Extract aligned physical source-line records in one character traversal.
283
303
  * Real line and block comments and complete template tokens become spaces in
@@ -353,10 +373,10 @@ export declare function extractTests(document: MarkdownDocument): readonly strin
353
373
  * fenceImports("import { a, b as c } from 'x'\n") // [{ specifier: 'x', names: ['a', 'b'] }]
354
374
  * ```
355
375
  */
356
- export declare function fenceImports(fence: string): readonly {
376
+ export declare function fenceImports(fence: string): ReadonlyArray<{
357
377
  specifier: string;
358
378
  names: readonly string[];
359
- }[];
379
+ }>;
360
380
 
361
381
  /**
362
382
  * The names present in `names` but absent from `source` — the set-difference
@@ -391,6 +411,22 @@ export declare function findMissing(names: readonly string[], source: readonly s
391
411
  */
392
412
  export declare function findUnexampled(names: readonly string[], fences: readonly string[], examples: readonly string[]): readonly string[];
393
413
 
414
+ /**
415
+ * The fences whose language is absent from the caller's listed languages.
416
+ * Untagged fences are always returned because they have no language to list.
417
+ *
418
+ * @param fences - The guide fences to check
419
+ * @param languages - The listed language tags
420
+ * @returns The unlisted fences in input order
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * findUnlisted([{ language: 'typescript', code: 'walk()' }], ['ts'])
425
+ * // [{ language: 'typescript', code: 'walk()' }]
426
+ * ```
427
+ */
428
+ export declare function findUnlisted(fences: readonly GuideFence[], languages: readonly string[]): readonly GuideFence[];
429
+
394
430
  /**
395
431
  * The first code-span value found by descending an inline node list, following
396
432
  * into `emphasis` / `link` / `image` children — the extraction rule behind a
@@ -409,7 +445,7 @@ export declare function firstCode(nodes: readonly InlineNode[]): string | undefi
409
445
  /**
410
446
  * A stateful, structured view over one parsed guide — the six documented
411
447
  * projections (`sections` / `surface` / `methods` / `links` / `tests` /
412
- * `patterns`) are extracted once at construction and cached.
448
+ * `fences`) are extracted once at construction and cached.
413
449
  *
414
450
  * @remarks
415
451
  * Pure: parses `source` once via `@orkestrel/markdown` and never touches the
@@ -433,7 +469,15 @@ export declare class Guide implements GuideInterface {
433
469
  methods(): readonly MethodGroup[];
434
470
  links(): readonly string[];
435
471
  tests(): readonly string[];
436
- patterns(): readonly string[];
472
+ fences(): readonly GuideFence[];
473
+ }
474
+
475
+ /** One fenced code block projected from a guide document. */
476
+ export declare interface GuideFence {
477
+ /** The info-string language tag, or `undefined` when the fence is untagged. */
478
+ readonly language: string | undefined;
479
+ /** The fence's verbatim code body. */
480
+ readonly code: string;
437
481
  }
438
482
 
439
483
  /**
@@ -466,14 +510,15 @@ export declare interface GuideInterface {
466
510
  */
467
511
  tests(): readonly string[];
468
512
  /**
469
- * Every fenced `ts` code block's body text, whole document.
513
+ * Every fenced code block in the whole document, in document order — no
514
+ * language filter, so a consumer decides which languages its checks read.
470
515
  *
471
516
  * @example
472
517
  * ```ts
473
- * guide.patterns() // ["import { createGuide } from '@orkestrel/guide'"]
518
+ * guide.fences() // [{ language: 'ts', code: "import { createGuide } from '@orkestrel/guide'" }]
474
519
  * ```
475
520
  */
476
- patterns(): readonly string[];
521
+ fences(): readonly GuideFence[];
477
522
  }
478
523
 
479
524
  /**
@@ -755,6 +800,22 @@ export declare const METHODS: string;
755
800
  */
756
801
  export declare function missingSymbols(symbols: readonly SurfaceSymbol[], source: readonly SurfaceSymbol[]): readonly string[];
757
802
 
803
+ /**
804
+ * The stable cache key for a {@link GuideModule}. Directories normalize before
805
+ * joining, so equivalent module spellings share one key. The NUL separator
806
+ * cannot occur in filesystem-backed canonical-segment inventory keys, so no
807
+ * directory boundary can collide with directory text.
808
+ *
809
+ * @param module - The module scope to key
810
+ * @returns The normalized directories joined by NUL
811
+ *
812
+ * @example
813
+ * ```ts
814
+ * moduleKey(['src/core', 'src/browser']) // 'src/core\0src/browser'
815
+ * ```
816
+ */
817
+ export declare function moduleKey(module: GuideModule): string;
818
+
758
819
  /**
759
820
  * A module scope normalized to its canonical directory list. `'.'` represents
760
821
  * workspace root; empty, trailing, and dot-segment spellings reduce through
@@ -1009,7 +1070,7 @@ export declare interface SourceInterface {
1009
1070
  *
1010
1071
  * @example
1011
1072
  * ```ts
1012
- * source.examples('GuideInterface') // ['links', 'tests', 'patterns']
1073
+ * source.examples('GuideInterface') // ['fences', 'links', 'tests']
1013
1074
  * ```
1014
1075
  */
1015
1076
  examples(name: string): readonly string[];
@@ -1030,6 +1091,50 @@ export declare interface SourceLine {
1030
1091
  readonly jsdoc: string | undefined;
1031
1092
  }
1032
1093
 
1094
+ /**
1095
+ * Resolves a consumer-owned import-specifier policy into pure source views and
1096
+ * caches those views by module, so aliases for one module share one entity.
1097
+ * Unmapped specifiers remain foreign to the consumer and return `undefined`.
1098
+ *
1099
+ * @example
1100
+ * ```ts
1101
+ * import { SourceManager } from '@orkestrel/guide'
1102
+ *
1103
+ * const sources = new SourceManager({
1104
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
1105
+ * modules: { '@scope/package': 'src/core' },
1106
+ * })
1107
+ * sources.source('@scope/package')?.surface()
1108
+ * ```
1109
+ */
1110
+ export declare class SourceManager implements SourceManagerInterface {
1111
+ #private;
1112
+ constructor(options: SourceManagerOptions);
1113
+ source(specifier: string): SourceInterface | undefined;
1114
+ }
1115
+
1116
+ /** A specifier resolver that shares one {@link SourceInterface} per module. */
1117
+ export declare interface SourceManagerInterface {
1118
+ /**
1119
+ * Resolve a mapped specifier to its shared source view.
1120
+ *
1121
+ * @param specifier - The import specifier to resolve
1122
+ * @returns Its source view, or `undefined` when the specifier is not mapped
1123
+ */
1124
+ source(specifier: string): SourceInterface | undefined;
1125
+ }
1126
+
1127
+ /**
1128
+ * The construction input for a {@link SourceManager}: one shared file inventory
1129
+ * plus the consumer's specifier-to-module policy.
1130
+ */
1131
+ export declare interface SourceManagerOptions {
1132
+ /** The workspace's exact canonical-segment opaque inventory keys, root-relative path → text. */
1133
+ readonly files: Readonly<Record<string, string>>;
1134
+ /** Each local import specifier mapped to the source module it exposes. */
1135
+ readonly modules: Readonly<Record<string, GuideModule>>;
1136
+ }
1137
+
1033
1138
  /**
1034
1139
  * The construction input for a {@link Source} — a consumer-supplied file
1035
1140
  * inventory (root-relative path → file text) plus the module scope to
@@ -26,7 +26,7 @@ export declare function cellLinks(cell: readonly InlineNode[]): readonly string[
26
26
  /**
27
27
  * Create a structured {@link GuideInterface} view over one guide's markdown
28
28
  * source — parses once and caches its `sections` / `surface` / `methods` /
29
- * `links` / `tests` / `patterns` projections.
29
+ * `links` / `tests` / `fences` projections.
30
30
  *
31
31
  * @param source - The guide's markdown source text
32
32
  * @returns A working {@link GuideInterface}
@@ -95,6 +95,26 @@ export declare function createMethodGroupContract(): ContractInterface<MethodGro
95
95
  */
96
96
  export declare function createSource(options: SourceOptions): SourceInterface;
97
97
 
98
+ /**
99
+ * Create a {@link SourceManagerInterface} that resolves the consumer's local
100
+ * import specifiers and shares one source view per module.
101
+ *
102
+ * @param options - The shared file inventory and specifier-to-module policy
103
+ * @returns A source manager over the supplied policy
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { createSourceManager } from '@orkestrel/guide'
108
+ *
109
+ * const sources = createSourceManager({
110
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
111
+ * modules: { '@scope/package': 'src/core' },
112
+ * })
113
+ * sources.source('@scope/package')?.surface()
114
+ * ```
115
+ */
116
+ export declare function createSourceManager(options: SourceManagerOptions): SourceManagerInterface;
117
+
98
118
  /**
99
119
  * Compile the {@link surfaceSymbolShape} into a {@link ContractInterface} for
100
120
  * {@link SurfaceSymbol} — a guard, coercing parser, JSON Schema, and seeded
@@ -235,6 +255,20 @@ export declare const EXTERNAL_SCHEMES: readonly string[];
235
255
  */
236
256
  export declare function extractExampleLines(lines: readonly SourceLine[]): readonly SourceLine[];
237
257
 
258
+ /**
259
+ * Every fenced code block anywhere in the guide document. A full AST walk
260
+ * includes fences nested inside blockquotes and lists.
261
+ *
262
+ * @param document - The parsed guide document
263
+ * @returns Every fence's language and verbatim code, in document order
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * extractFences(document) // [{ language: 'ts', code: "import { X } from './x.js'\nX()" }]
268
+ * ```
269
+ */
270
+ export declare function extractFences(document: MarkdownDocument): readonly GuideFence[];
271
+
238
272
  /**
239
273
  * Every link href in the guide document, including table cells — a full,
240
274
  * depth-first walk of the whole AST.
@@ -264,20 +298,6 @@ export declare function extractLinks(document: MarkdownDocument): readonly strin
264
298
  */
265
299
  export declare function extractMethods(document: MarkdownDocument): readonly MethodGroup[];
266
300
 
267
- /**
268
- * Every ```ts fenced code block's body text anywhere in the guide document —
269
- * a full AST walk so a fence nested inside a blockquote or list still counts.
270
- *
271
- * @param document - The parsed guide document
272
- * @returns Every `ts`-lang fence's verbatim code, in walk order
273
- *
274
- * @example
275
- * ```ts
276
- * extractPatterns(document) // ["import { X } from './x.js'\nX()"]
277
- * ```
278
- */
279
- export declare function extractPatterns(document: MarkdownDocument): readonly string[];
280
-
281
301
  /**
282
302
  * Extract aligned physical source-line records in one character traversal.
283
303
  * Real line and block comments and complete template tokens become spaces in
@@ -353,10 +373,10 @@ export declare function extractTests(document: MarkdownDocument): readonly strin
353
373
  * fenceImports("import { a, b as c } from 'x'\n") // [{ specifier: 'x', names: ['a', 'b'] }]
354
374
  * ```
355
375
  */
356
- export declare function fenceImports(fence: string): readonly {
376
+ export declare function fenceImports(fence: string): ReadonlyArray<{
357
377
  specifier: string;
358
378
  names: readonly string[];
359
- }[];
379
+ }>;
360
380
 
361
381
  /**
362
382
  * The names present in `names` but absent from `source` — the set-difference
@@ -391,6 +411,22 @@ export declare function findMissing(names: readonly string[], source: readonly s
391
411
  */
392
412
  export declare function findUnexampled(names: readonly string[], fences: readonly string[], examples: readonly string[]): readonly string[];
393
413
 
414
+ /**
415
+ * The fences whose language is absent from the caller's listed languages.
416
+ * Untagged fences are always returned because they have no language to list.
417
+ *
418
+ * @param fences - The guide fences to check
419
+ * @param languages - The listed language tags
420
+ * @returns The unlisted fences in input order
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * findUnlisted([{ language: 'typescript', code: 'walk()' }], ['ts'])
425
+ * // [{ language: 'typescript', code: 'walk()' }]
426
+ * ```
427
+ */
428
+ export declare function findUnlisted(fences: readonly GuideFence[], languages: readonly string[]): readonly GuideFence[];
429
+
394
430
  /**
395
431
  * The first code-span value found by descending an inline node list, following
396
432
  * into `emphasis` / `link` / `image` children — the extraction rule behind a
@@ -409,7 +445,7 @@ export declare function firstCode(nodes: readonly InlineNode[]): string | undefi
409
445
  /**
410
446
  * A stateful, structured view over one parsed guide — the six documented
411
447
  * projections (`sections` / `surface` / `methods` / `links` / `tests` /
412
- * `patterns`) are extracted once at construction and cached.
448
+ * `fences`) are extracted once at construction and cached.
413
449
  *
414
450
  * @remarks
415
451
  * Pure: parses `source` once via `@orkestrel/markdown` and never touches the
@@ -433,7 +469,15 @@ export declare class Guide implements GuideInterface {
433
469
  methods(): readonly MethodGroup[];
434
470
  links(): readonly string[];
435
471
  tests(): readonly string[];
436
- patterns(): readonly string[];
472
+ fences(): readonly GuideFence[];
473
+ }
474
+
475
+ /** One fenced code block projected from a guide document. */
476
+ export declare interface GuideFence {
477
+ /** The info-string language tag, or `undefined` when the fence is untagged. */
478
+ readonly language: string | undefined;
479
+ /** The fence's verbatim code body. */
480
+ readonly code: string;
437
481
  }
438
482
 
439
483
  /**
@@ -466,14 +510,15 @@ export declare interface GuideInterface {
466
510
  */
467
511
  tests(): readonly string[];
468
512
  /**
469
- * Every fenced `ts` code block's body text, whole document.
513
+ * Every fenced code block in the whole document, in document order — no
514
+ * language filter, so a consumer decides which languages its checks read.
470
515
  *
471
516
  * @example
472
517
  * ```ts
473
- * guide.patterns() // ["import { createGuide } from '@orkestrel/guide'"]
518
+ * guide.fences() // [{ language: 'ts', code: "import { createGuide } from '@orkestrel/guide'" }]
474
519
  * ```
475
520
  */
476
- patterns(): readonly string[];
521
+ fences(): readonly GuideFence[];
477
522
  }
478
523
 
479
524
  /**
@@ -755,6 +800,22 @@ export declare const METHODS: string;
755
800
  */
756
801
  export declare function missingSymbols(symbols: readonly SurfaceSymbol[], source: readonly SurfaceSymbol[]): readonly string[];
757
802
 
803
+ /**
804
+ * The stable cache key for a {@link GuideModule}. Directories normalize before
805
+ * joining, so equivalent module spellings share one key. The NUL separator
806
+ * cannot occur in filesystem-backed canonical-segment inventory keys, so no
807
+ * directory boundary can collide with directory text.
808
+ *
809
+ * @param module - The module scope to key
810
+ * @returns The normalized directories joined by NUL
811
+ *
812
+ * @example
813
+ * ```ts
814
+ * moduleKey(['src/core', 'src/browser']) // 'src/core\0src/browser'
815
+ * ```
816
+ */
817
+ export declare function moduleKey(module: GuideModule): string;
818
+
758
819
  /**
759
820
  * A module scope normalized to its canonical directory list. `'.'` represents
760
821
  * workspace root; empty, trailing, and dot-segment spellings reduce through
@@ -1009,7 +1070,7 @@ export declare interface SourceInterface {
1009
1070
  *
1010
1071
  * @example
1011
1072
  * ```ts
1012
- * source.examples('GuideInterface') // ['links', 'tests', 'patterns']
1073
+ * source.examples('GuideInterface') // ['fences', 'links', 'tests']
1013
1074
  * ```
1014
1075
  */
1015
1076
  examples(name: string): readonly string[];
@@ -1030,6 +1091,50 @@ export declare interface SourceLine {
1030
1091
  readonly jsdoc: string | undefined;
1031
1092
  }
1032
1093
 
1094
+ /**
1095
+ * Resolves a consumer-owned import-specifier policy into pure source views and
1096
+ * caches those views by module, so aliases for one module share one entity.
1097
+ * Unmapped specifiers remain foreign to the consumer and return `undefined`.
1098
+ *
1099
+ * @example
1100
+ * ```ts
1101
+ * import { SourceManager } from '@orkestrel/guide'
1102
+ *
1103
+ * const sources = new SourceManager({
1104
+ * files: { 'src/core/index.ts': "export * from './types.js'" },
1105
+ * modules: { '@scope/package': 'src/core' },
1106
+ * })
1107
+ * sources.source('@scope/package')?.surface()
1108
+ * ```
1109
+ */
1110
+ export declare class SourceManager implements SourceManagerInterface {
1111
+ #private;
1112
+ constructor(options: SourceManagerOptions);
1113
+ source(specifier: string): SourceInterface | undefined;
1114
+ }
1115
+
1116
+ /** A specifier resolver that shares one {@link SourceInterface} per module. */
1117
+ export declare interface SourceManagerInterface {
1118
+ /**
1119
+ * Resolve a mapped specifier to its shared source view.
1120
+ *
1121
+ * @param specifier - The import specifier to resolve
1122
+ * @returns Its source view, or `undefined` when the specifier is not mapped
1123
+ */
1124
+ source(specifier: string): SourceInterface | undefined;
1125
+ }
1126
+
1127
+ /**
1128
+ * The construction input for a {@link SourceManager}: one shared file inventory
1129
+ * plus the consumer's specifier-to-module policy.
1130
+ */
1131
+ export declare interface SourceManagerOptions {
1132
+ /** The workspace's exact canonical-segment opaque inventory keys, root-relative path → text. */
1133
+ readonly files: Readonly<Record<string, string>>;
1134
+ /** Each local import specifier mapped to the source module it exposes. */
1135
+ readonly modules: Readonly<Record<string, GuideModule>>;
1136
+ }
1137
+
1033
1138
  /**
1034
1139
  * The construction input for a {@link Source} — a consumer-supplied file
1035
1140
  * inventory (root-relative path → file text) plus the module scope to