git-documentdb
Version:
Offline-first database that syncs with Git
119 lines • 4.49 kB
TypeScript
/**
* GitDocumentDB
* Copyright (c) Hidekazu Kubota
*
* This source code is licensed under the Mozilla Public License Version 2.0
* found in the LICENSE file in the root directory of this source tree.
*/
import { CollectionPath, JsonDoc } from './types';
/**
* Validator Class
*
* @public
*/
export declare class Validator {
private _workingDirectory;
constructor(workingDir: string);
static byteLengthOf: (str: string) => number;
/**
* Normalized collectionPath is '' or path strings that have a trailing slash and no heading slash.
* Root ('/') is not allowed.
* Backslash \\ or yen ¥ is replaced with slash /.
*/
static normalizeCollectionPath(collectionPath: CollectionPath | undefined): CollectionPath;
/**
* Return the max length of working directory path
*/
static maxWorkingDirectoryLength(): number;
/**
* Return the max length of collectionPath
*/
maxCollectionPathLength(): number;
/**
* Return the max length of _id
*
* @remarks
* _id means `${collectionPath}/${shortId}`
*/
maxIdLength(): number;
/**
* Return false if the given name equals Windows reserved filename
*/
testWindowsReservedFileName(name: string, options?: {
allowDirectoryDot?: boolean;
}): boolean;
/**
* Return false if the given name includes Windows invalid filename character
*/
testWindowsInvalidFileNameCharacter(name: string, options?: {
allowSlash?: boolean;
allowDriveLetter?: boolean;
allowDirectoryDot?: boolean;
allowDot?: boolean;
allowLastSpace?: boolean;
}): boolean;
/**
* Validate localDir
*
* @remarks
*```
* - A directory name allows Unicode characters except for OS reserved filenames and the following characters: \< \> : " | ? * \\0
* - A colon is generally disallowed, but a drive letter followed by a colon is allowed.
* - A directory name cannot end with a period or a white space but the current directory . and the parent directory .. are allowed.
* - A trailing slash could be omitted.
*```
* @throws {@link Err.InvalidLocalDirCharacterError}
*/
validateLocalDir(localDir: string): void;
/**
* Validate dbName
*
* @remarks
*```
* - dbName allows Unicode characters except for OS reserved filenames and the following characters: \< \> : " ¥ / \\ | ? * \\0
* - dbName cannot end with a period or a white space.
* - dbName does not allow '.' and '..'.
*```
* @throws {@link Err.InvalidDbNameCharacterError}
*/
validateDbName(dbName: string): void;
/**
* Validate collectionPath
*
* @remarks CollectionPath must be NULL string or paths that match the following conditions:
*```
* - CollectionPath can include paths separated by slashes.
* - A directory name in paths allows Unicode characters except for OS reserved filenames and the following characters: \< \> : " | ? * \\0
* - **It is recommended to use ASCII characters and case-insensitive names for cross-platform.**
* - A directory name in paths cannot end with a period or a white space.
* - A directory name in paths does not allow '.' and '..'.
* - CollectionPath cannot start with a slash.
* - Trailing slash could be omitted. e.g.) 'pages' and 'pages/' show the same CollectionPath.
*```
*
* @throws {@link Err.InvalidCollectionPathCharacterError}
* @throws {@link Err.InvalidCollectionPathLengthError}
*/
validateCollectionPath(collectionPath: string): void;
/**
* Validate _id
*
* _id = collectionPath + shortId (not including postfix '.json')
*
* @remarks Spec of _id is described at {@link JsonDoc}.
* @throws {@link Err.InvalidIdCharacterError}
* @throws {@link Err.InvalidCollectionPathCharacterError}
* @throws {@link Err.InvalidCollectionPathLengthError}
* @throws {@link Err.InvalidIdLengthError}
*/
validateId(_id: string): void;
/**
* Validate document
*
* @throws {@link Err.UndefinedDocumentIdError}
* @throws {@link Err.InvalidIdCharacterError}
* @throws {@link Err.InvalidIdLengthError}
*/
validateDocument(doc: JsonDoc): void;
}
//# sourceMappingURL=validator.d.ts.map