mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
* Improve schema setup and Notion ingest UX * Handle Postgres network scan failures * WIP: save local changes before main merge * Refine setup prompt choices * Tighten ingest reconciliation guidance * Commit setup config updates * Canonicalize unmapped fallback details * Count reconciliation actions in reports * Harden semantic layer source validation * Return wiki content after edits * Validate SL sources against manifests * Validate wiki refs before writes * Simplify CLI next steps * Clarify agent setup summary * Surface dbt target SL sources * Recover SL write fallbacks * Preserve failed context build metadata * Track raw paths for ingest actions * test(cli): update seeded demo expectations * fix(ingest): scope fallback recovery checks * fix(sl): tighten source validation guards * fix(wiki): ignore empty embedding vectors * Improve Notion ingest UX * Enforce flat wiki keys * test(context): update wiki key assertion --------- Co-authored-by: Andrey Avtomonov <andreybavt@gmail.com>
31 lines
1,005 B
TypeScript
31 lines
1,005 B
TypeScript
const FLAT_WIKI_KEY_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
|
|
export function suggestFlatWikiKey(key: string): string {
|
|
const suggested = key
|
|
.trim()
|
|
.replace(/[\\/]+/g, '-')
|
|
.replace(/[^a-zA-Z0-9_-]+/g, '-')
|
|
.replace(/-+/g, '-')
|
|
.replace(/^[-_]+|[-_]+$/g, '');
|
|
return suggested.length > 0 ? suggested : 'page-key';
|
|
}
|
|
|
|
export function invalidFlatWikiKeyMessage(key: string): string {
|
|
return `Invalid wiki key "${key}". Wiki keys must be flat; use "${suggestFlatWikiKey(key)}".`;
|
|
}
|
|
|
|
export function isFlatWikiKey(key: string): boolean {
|
|
return FLAT_WIKI_KEY_PATTERN.test(key);
|
|
}
|
|
|
|
export function validateFlatWikiKey(key: string): { ok: true; key: string } | { ok: false; error: string } {
|
|
return isFlatWikiKey(key) ? { ok: true, key } : { ok: false, error: invalidFlatWikiKeyMessage(key) };
|
|
}
|
|
|
|
export function assertFlatWikiKey(key: string): string {
|
|
const result = validateFlatWikiKey(key);
|
|
if (!result.ok) {
|
|
throw new Error(result.error);
|
|
}
|
|
return result.key;
|
|
}
|