33 lines
867 B
TypeScript
33 lines
867 B
TypeScript
|
|
/**
|
||
|
|
* Completion index — orchestrates all registered completion sources.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { diceSource } from "./sources/dice.js";
|
||
|
|
import { linksSource } from "./sources/links.js";
|
||
|
|
import type { CompletionSource, CompletionsPayload } from "./types.js";
|
||
|
|
|
||
|
|
export type {
|
||
|
|
CompletionsPayload,
|
||
|
|
DiceCompletion,
|
||
|
|
LinkCompletion,
|
||
|
|
} from "./types.js";
|
||
|
|
|
||
|
|
/** Registered sources — open for extension */
|
||
|
|
const sources: CompletionSource[] = [diceSource, linksSource];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Scan the full content index and return structured completion data.
|
||
|
|
* Called at server startup and on any file change.
|
||
|
|
*/
|
||
|
|
export function scanCompletions(
|
||
|
|
index: Record<string, string>,
|
||
|
|
): CompletionsPayload {
|
||
|
|
const payload: Record<string, unknown[]> = {};
|
||
|
|
|
||
|
|
for (const source of sources) {
|
||
|
|
payload[source.key] = source.scan(index);
|
||
|
|
}
|
||
|
|
|
||
|
|
return payload as unknown as CompletionsPayload;
|
||
|
|
}
|