/** * RFC 6570 URI Template utilities. * * Implements: * - Level 1 simple string expansion (`{var}`) — value is percent-encoded, * stops at `/`. * - Level 2 reserved expansion (`{+var}`) — value passes reserved characters * (including `/`) through unencoded, so a single template variable can * span multiple path segments (e.g. `skill://{+skillPath}/SKILL.md` * matches `skill://acme/billing/refunds/SKILL.md`). * * Other RFC 6570 operators (`{#frag}`, `{?query}`, `{&qcont}`, `{;path}`, * `{.label}`, `{/path}`) are not supported. */ /** * Parsed URI template information. */ export interface ParsedUriTemplate { /** Compiled regex pattern for matching URIs */ pattern: RegExp; /** Ordered list of parameter names extracted from template */ paramNames: string[]; } /** * Parse a URI template (RFC 6570 Level 1 + reserved expansion) into a regex * pattern and parameter names. * * @param template - The URI template to parse * @returns Parsed template with pattern and parameter names * @throws Error if template is too long (>1000 chars) or has too many parameters (>50) * * @example * parseUriTemplate("file:///{path}") * // { pattern: /^file:\/\/\/([^/]+)$/, paramNames: ["path"] } * * parseUriTemplate("users/{userId}/posts/{postId}") * // { pattern: /^users\/([^/]+)\/posts\/([^/]+)$/, paramNames: ["userId", "postId"] } * * parseUriTemplate("skill://{+skillPath}/SKILL.md") * // { pattern: /^skill:\/\/(.+?)\/SKILL\.md$/, paramNames: ["skillPath"] } */ export declare function parseUriTemplate(template: string): ParsedUriTemplate; /** * Match a URI against a URI template and extract parameters. * Returns null if no match, or an object with extracted parameters. * * @param template - The URI template * @param uri - The URI to match against the template * @returns Object with extracted parameters, or null if no match * * @example * matchUriTemplate("file:///{path}", "file:///documents") * // { path: "documents" } * * matchUriTemplate("users/{userId}/posts/{postId}", "users/123/posts/456") * // { userId: "123", postId: "456" } * * matchUriTemplate("users/{id}", "products/123") * // null (no match) */ export declare function matchUriTemplate(template: string, uri: string): Record | null; /** * Expand a URI template with the given parameters. * * Encoding depends on the operator: * - `{var}` (simple expansion): value is percent-encoded via * `encodeURIComponent()` so `/`, `:`, etc. become `%2F`, `%3A`. * - `{+var}` (reserved expansion): unreserved + reserved characters * (per RFC 3986) pass through unencoded — only characters outside * that set are percent-encoded. This lets a single variable carry * a multi-segment path. * * Use {@link matchUriTemplate} to decode them back. * * @param template - The URI template * @param params - Object with parameter values (raw, unencoded) * @returns Expanded URI with parameters substituted (encoding depends on operator) * @throws Error if a required parameter is missing * * @example * expandUriTemplate("file:///{path}", { path: "documents" }) * // "file:///documents" * * expandUriTemplate("users/{userId}/posts/{postId}", { userId: "123", postId: "456" }) * // "users/123/posts/456" * * // Simple expansion percent-encodes reserved chars: * expandUriTemplate("notes://{id}", { id: "x-coredata://ABC/Note/1" }) * // "notes://x-coredata%3A%2F%2FABC%2FNote%2F1" * * // Reserved expansion preserves them: * expandUriTemplate("skill://{+skillPath}/SKILL.md", { skillPath: "acme/billing" }) * // "skill://acme/billing/SKILL.md" */ export declare function expandUriTemplate(template: string, params: Record): string; /** * Extract parameter names from a URI template. * * @param template - The URI template * @returns Array of parameter names in order of appearance * * @example * extractTemplateParams("users/{userId}/posts/{postId}") * // ["userId", "postId"] * * extractTemplateParams("file:///static/path") * // [] */ export declare function extractTemplateParams(template: string): string[]; /** * Check if a string is a URI template (contains {param} placeholders). * * @param uri - The string to check * @returns true if the string contains template placeholders * * @example * isUriTemplate("users/{userId}") // true * isUriTemplate("users/123") // false */ export declare function isUriTemplate(uri: string): boolean;