UNPKG

@solid/community-server

Version:

Community Solid Server: an open and modular implementation of the Solid specifications

186 lines (185 loc) 7.21 kB
import urljoin from 'url-join'; import type { TargetExtractor } from '../http/input/identifier/TargetExtractor'; import type { ResourceIdentifier } from '../http/representation/ResourceIdentifier'; import type { HttpRequest } from '../server/HttpRequest'; import type { Json } from './Json'; /** * Resolves relative segments in the path. * * @param path - Path to check (POSIX or Windows). * * @returns The potentially changed path (POSIX). */ export declare function normalizeFilePath(path: string): string; /** * Adds the paths to the base path. * * @param basePath - The base path (POSIX or Windows). * @param paths - Subpaths to attach (POSIX). * * @returns The potentially changed path (POSIX). */ export declare function joinFilePath(basePath: string, ...paths: string[]): string; /** * Resolves a path to its absolute form. * Absolute inputs will not be changed (except changing Windows to POSIX). * Relative inputs will be interpreted relative to process.cwd(). * * @param path - Path to check (POSIX or Windows). * * @returns The potentially changed path (POSIX). */ export declare function absoluteFilePath(path: string): string; /** * Makes sure the input path has exactly 1 slash at the end. * Multiple slashes will get merged into one. * If there is no slash it will be added. * * @param path - Path to check. * * @returns The potentially changed path. */ export declare function ensureTrailingSlash(path: string): string; /** * Makes sure the input path has no slashes at the end. * * @param path - Path to check. * * @returns The potentially changed path. */ export declare function trimTrailingSlashes(path: string): string; /** * Makes sure the input path has exactly 1 slash at the beginning. * Multiple slashes will get merged into one. * If there is no slash it will be added. * * @param path - Path to check. * * @returns The potentially changed path. */ export declare function ensureLeadingSlash(path: string): string; /** * Makes sure the input path has no slashes at the beginning. * * @param path - Path to check. * * @returns The potentially changed path. */ export declare function trimLeadingSlashes(path: string): string; /** * Extracts the extension (without dot) from a path. * Custom function since `path.extname` does not work on all cases (e.g. ".acl") * * @param path - Input path to parse. */ export declare function getExtension(path: string): string; /** * Converts a URI path to the canonical version by splitting on slashes, * decoding any percent-based encodings, and then encoding any special characters. * This function is used to clean unwanted characters in the components of * the provided path. * * @param path - The path to convert to its canonical URI path form. * * @returns The canonical URI path form of the provided path. */ export declare function toCanonicalUriPath(path: string): string; /** * This function is used when converting a URI to a file path. Decodes all components of a URI path, * with the exception of encoded slash characters, as this would lead to unexpected file locations * being targeted (resulting in erroneous behaviour of the file based backend). * Characters that would result in an illegal file path remain percent encoded. * * @param path - The path to decode the URI path components of. * * @returns A decoded copy of the provided URI path (ignoring encoded slash characters). */ export declare function decodeUriPathComponents(path: string): string; /** * This function is used in the process of converting a file path to a URI. Encodes all (non-slash) * special characters in a URI path, with the exception of encoded slash characters, as this would * lead to unnecessary double encoding, resulting in a URI that differs from the expected result. * * @param path - The path to encode the URI path components of. * * @returns An encoded copy of the provided URI path (ignoring encoded slash characters). */ export declare function encodeUriPathComponents(path: string): string; /** * Checks whether the path corresponds to a container path (ending in a /). * * @param path - Path to check. */ export declare function isContainerPath(path: string): boolean; /** * Checks whether the identifier corresponds to a container identifier. * * @param identifier - Identifier to check. */ export declare function isContainerIdentifier(identifier: ResourceIdentifier): boolean; /** * Splits a URL (or similar) string into a part containing its scheme and one containing the rest. * E.g., `http://test.com/` results in `{ scheme: 'http://', rest: 'test.com/' }`. * * @param url - String to parse. */ export declare function extractScheme(url: string): { scheme: string; rest: string; }; /** * Creates a relative URL by removing the base URL. * Will throw an error in case the resulting target is not withing the base URL scope. * * @param baseUrl - Base URL. * @param request - Incoming request of which the target needs to be extracted. * @param targetExtractor - Will extract the target from the request. */ export declare function getRelativeUrl(baseUrl: string, request: HttpRequest, targetExtractor: TargetExtractor): Promise<string>; /** * Creates a regular expression that matches URLs containing the given baseUrl, or a subdomain of the given baseUrl. * In case there is a subdomain, the first match of the regular expression will be that subdomain. * * Examples with baseUrl `http://test.com/foo/`: * - Will match `http://test.com/foo/` * - Will match `http://test.com/foo/bar/baz` * - Will match `http://alice.bob.test.com/foo/bar/baz`, first match result will be `alice.bob` * - Will not match `http://test.com/` * - Will not match `http://alicetest.com/foo/` * * @param baseUrl - Base URL for the regular expression. */ export declare function createSubdomainRegexp(baseUrl: string): RegExp; /** * Returns the folder corresponding to the root of the Community Solid Server module */ export declare function getModuleRoot(): string; /** * A placeholder for the path to the `@solid/community-server` module root. * The `resolveAssetPath` function will replace this string with the actual path. */ export declare const modulePathPlaceholder = "@css:"; /** * Creates a path starting from the `@solid/community-server` module root, * to be resolved by the `resolveAssetPath` function. */ export declare function modulePath(relativePath?: string): string; /** * Creates an absolute path starting from the `@solid/community-server` module root. */ export declare function resolveModulePath(relativePath?: string): string; /** * Converts file path inputs into absolute paths. * Works similar to `absoluteFilePath` but paths that start with the `modulePathPlaceholder` * will be relative to the module directory instead of the cwd. */ export declare function resolveAssetPath(path?: string): string; /** * Reads the project package.json and returns it. */ export declare function readPackageJson(): Promise<Record<string, Json>>; /** * Concatenates all the given strings into a normalized URL. * Will place slashes between input strings if necessary. */ export declare const joinUrl: typeof urljoin;