From ea667e0fcbf3db35549d58e1f5cb7e865f27d7ae Mon Sep 17 00:00:00 2001 From: Antoine LUCAS Date: Tue, 4 Oct 2016 02:34:10 +0800 Subject: [PATCH] Added the definition for the npm package simple-url-cache (#11296) * Added the definition for the npm package simple-url-cache https://www.npmjs.com/package/simple-url-cache * - Some problems with shells.js missing the touch fucntion deifnition * More details on the touch parameters - nice screenshot btw --- shelljs/shelljs-tests.ts | 15 ++++ shelljs/shelljs.d.ts | 25 +++++- simple-url-cache/simple-url-cache-tests.ts | 56 +++++++++++++ simple-url-cache/simple-url-cache.d.ts | 95 ++++++++++++++++++++++ 4 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 simple-url-cache/simple-url-cache-tests.ts create mode 100644 simple-url-cache/simple-url-cache.d.ts diff --git a/shelljs/shelljs-tests.ts b/shelljs/shelljs-tests.ts index 34292f8d8a..23dbdaf3f7 100644 --- a/shelljs/shelljs-tests.ts +++ b/shelljs/shelljs-tests.ts @@ -119,6 +119,21 @@ shell.chmod("u+x", "/Users/brandon"); shell.exit(0); +shell.touch('/Users/brandom/test1'); +shell.touch('/Users/brandom/test1', '/Users/brandom/test2'); + +shell.touch(['/Users/brandom/test1']); +shell.touch(['/Users/brandom/test1', '/Users/brandom/test2']); + +shell.touch('-c', '/Users/brandom/test1'); +shell.touch('-c', '/Users/brandom/test1', '/Users/brandom/test2'); +shell.touch('-c', ['/Users/brandom/test1', '/Users/brandom/test2']); + +shell.touch({ '-r': '/some/file.txt' }, '/Users/brandom/test1'); +shell.touch({ '-r': '/some/file.txt' }, '/Users/brandom/test1', '/Users/brandom/test2'); +shell.touch({ '-r': '/oome/file.txt' }, ['/Users/brandom/test1', '/Users/brandom/test2']); + + var tmp = shell.tempdir(); // "/tmp" for most *nix platforms var errorlol = shell.error(); diff --git a/shelljs/shelljs.d.ts b/shelljs/shelljs.d.ts index ac501e078c..5d33833e20 100644 --- a/shelljs/shelljs.d.ts +++ b/shelljs/shelljs.d.ts @@ -128,7 +128,7 @@ declare module "shelljs" * @param {string} dest The destination. */ export function mv(source: string, dest: string): void; - + /** * Moves files. The wildcard * is accepted. * @param {string[]} source The source. @@ -436,7 +436,7 @@ declare module "shelljs" * Object containing environment variables (both getter and setter). Shortcut to process.env. */ export var env: { [key: string]: string }; - + /** * Executes the given command synchronously. * @param {string} command The command to execute. @@ -511,6 +511,27 @@ declare module "shelljs" */ export function error(): string; + + + export function touch(...files: string[]): void; + export function touch(files: string[]): void; + + type TouchOptionsLiteral = "-a" | "-c" | "-m" | "-d" | "-r"; + + export function touch(options: TouchOptionsLiteral, ...files: string[]): void; + export function touch(options: TouchOptionsLiteral, files: string[]): void; + + /** + * Update the access and modification times of each FILE to the current time. A FILE argument that does not exist is created empty, unless -c is supplied + */ + type touchOptionsArray = { + '-d'?: string; + '-r'?: string; + }; + + export function touch(options: touchOptionsArray, ...files: string[]): void; + export function touch(options: touchOptionsArray, files: string[]): void; + // Configuration interface ShellConfig diff --git a/simple-url-cache/simple-url-cache-tests.ts b/simple-url-cache/simple-url-cache-tests.ts new file mode 100644 index 0000000000..d33a3a1846 --- /dev/null +++ b/simple-url-cache/simple-url-cache-tests.ts @@ -0,0 +1,56 @@ +/// + +import simpleUrlCache = require("simple-url-cache"); + +const fileStorageConfig = { + type: 'file', + dir: './cache' +}; + +const redisStorageConfig = { + type: 'redis', + host: '127.00.1', + port: 1234 +} + +const regexRules = { + cacheMaxAge: [ + { + regex: /.*/, + maxAge: 3600 + } + ], + cacheAlways: [ + { + regex: /always/ + } + ], + cacheNever: [ + { + regex: /never/ + } + ], + default: 'never' +}; + +const cacheEngine1 = new simpleUrlCache.CacheEngine(fileStorageConfig, regexRules); + +let url1 = cacheEngine1.url('/someUrl.html'); + +url1.cache('some HTML'); +url1.isCached(); +url1.getUrl(); +url1.removeUrl(); +url1.destroy(); + +const cacheEngine2 = new simpleUrlCache.CacheEngine(redisStorageConfig, regexRules); + +let url2 = cacheEngine2.url('/someUrl.html'); +url2.cache('some HTML'); +url2.isCached(); +url2.getUrl(); +url2.removeUrl(); +url2.destroy(); + + + diff --git a/simple-url-cache/simple-url-cache.d.ts b/simple-url-cache/simple-url-cache.d.ts new file mode 100644 index 0000000000..daa3b04d4e --- /dev/null +++ b/simple-url-cache/simple-url-cache.d.ts @@ -0,0 +1,95 @@ +// Type definitions for simple-url-cache +// Project: https://github.com/a-lucas/simple-url-cache +// Definitions by: Antoine LUCAS +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module 'simple-url-cache' { + import redis = require("redis"); + + export class CacheEngine { + constructor(storageConfig: FileStorageConfig, cacheRules: CacheRules); + constructor(storageConfig: RedisStorageConfig, cacheRules: CacheRules); + url(url: string): FileStorage; + url(url: string): RedisStorage; + } + + export interface RegexRule { + regex:RegExp + } + + export interface MaxAgeRegexRule extends RegexRule { + maxAge:number + } + + export interface CacheRules { + cacheMaxAge:MaxAgeRegexRule[], + cacheAlways:RegexRule[], + cacheNever:RegexRule[], + default:string + } + + export interface FileStorageConfig extends privateN.StorageConfig { + dir:string; + } + + export interface RedisStorageConfig extends privateN.StorageConfig { + host:string; + port:number; + path?:string; + url?:string; + socket_keepalive?:boolean; + password?:string; + db?:string; + } + + namespace privateN { + interface StorageConfig { + type:string + } + + interface CacheStorage { + isCached():Promise; + removeUrl():Promise; + getUrl():Promise; + cache(html:string):Promise; + cache(html:string, force:boolean):Promise; + destroy(): void; + } + + abstract class CacheCategory { + constructor(currentUrl:string, _config:CacheRules) ; + private getRegexTest(u:RegexRule):boolean; + private getCacheCategory():string; + public getCategory():string; + public getCurrentUrl():string; + } + + module RedisPool { + export function connect(config:RedisStorageConfig): redis.RedisClient; + export function isOnline():boolean; + export function kill():void; + } + } + + export class FileStorage extends privateN.CacheCategory implements privateN.CacheStorage { + constructor(_url:string, _storageConfig: FileStorageConfig, _regexRules: CacheRules); + isCached():Promise; + removeUrl():Promise; + getUrl():Promise; + cache(html:string):Promise + cache(html:string, force:boolean):Promise; + destroy(): void; + } + + export class RedisStorage extends privateN.CacheCategory implements privateN.CacheStorage { + constructor(_url:string, _storageConfig: RedisStorageConfig, _regexRules: CacheRules); + isCached():Promise; + removeUrl():Promise; + getUrl():Promise; + cache(html:string):Promise; + cache(html:string, force:boolean):Promise; + destroy(): void; + } +}