service-model
Version:
An object oriented web service framework inspired by Windows Communication Foundation.
99 lines (98 loc) • 2.94 kB
TypeScript
import { Url } from "./url";
/**
* A class that represents a template for matching and parsing urls. The template describes a relative URL and can only
* include path and query components. The path can include parameters. Only the path is used for matching (the query is
* ignored for matching.) The query can describe optional parameters. Duplicate parameter names are not allowed.
*
* ### Examples
* The following are examples of valid templates:
*
* ```
* "/blog"
* ```
* Matches "/blog". No parameters are assigned.
*
* ```
* "/blog/{blogId}"
* ```
* Matches "/blog/1". Assigns parameter `blogId` the value "1".
*
* ```
* "/blog/{blogId}/article/{articleId}"
* ```
* Matches "/blog/1/article/2". Assigns parameter `blogId` the value "1" and `articleId` the value "2".
*
* ```
* "/blog/{blogId}/article/{articleId}?page={pageNum}"
* ```
* Matches "/blog/1/article/2" and "/blog/1/article/2?page=3". Assigns parameter `blogId` the value "1" and
* `articleId` the value "2". If "page" is include in the query then assigns parameter `pageNum` the value "3".
*
* ```
* "/download/{file}.{ext}"
* ```
* Matches "/download/some-file.jpg". Assigns parameter `file` the value "some-file" and `ext` the value "jpg".
*/
export declare class UrlTemplate {
/**
* Regular expression used to match the pathname template.
* @hidden
*/
private _pattern;
/**
* List of parameters in the pathname.
* @hidden
*/
private _pathParams;
/**
* Map of parameters in the query.
* @hidden
*/
private _queryParams;
/**
* Constructs a url template.
* @param template The template.
*/
constructor(template: string);
/**
* Parses the template path.
* @param text The path to parse
* @hidden
*/
private _parsePath(text);
/**
* Parses the template query string
* @param text The query string to parse
* @hidden
*/
private _parseQuery(text);
/**
* Returns true if the url matches the template.
* @param baseAddress The base url.
* @param candidate The url to check.
*/
match(candidate: Url): boolean;
/**
* Parses parameter values from the given url and returns a map of parameter name to value.
* @param url The url to parse.
*/
parse(url: Url): Map<string, string>;
/**
* Returns a new UrlTemplate prefixed with the specified base address.
* @param address The base address.
*/
prefix(address: Url): UrlTemplate;
prefix(prefixTemplate: UrlTemplate): UrlTemplate;
private static _getTemplatePattern(prefixTemplate);
private static _getAddressPattern(address);
/**
* Decodes a parameter value from the pathname.
* @param val The value to decode.
* @hidden
*/
private _decodeParam(val);
}
export interface UrlArguments {
args: Map<string, string>;
errors: string[];
}