From ba67bffd31f7073cf1cb5348e2312141803dce55 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 7 Aug 2018 01:26:39 +0200 Subject: [PATCH] feat(catbox-redis): add typings --- types/catbox-redis/catbox-redis-tests.ts | 12 +++++ types/catbox-redis/index.d.ts | 60 ++++++++++++++++++++++++ types/catbox-redis/tsconfig.json | 23 +++++++++ types/catbox-redis/tslint.json | 1 + types/catbox/index.d.ts | 3 ++ 5 files changed, 99 insertions(+) create mode 100644 types/catbox-redis/catbox-redis-tests.ts create mode 100644 types/catbox-redis/index.d.ts create mode 100644 types/catbox-redis/tsconfig.json create mode 100644 types/catbox-redis/tslint.json diff --git a/types/catbox-redis/catbox-redis-tests.ts b/types/catbox-redis/catbox-redis-tests.ts new file mode 100644 index 0000000000..d7fb5eb701 --- /dev/null +++ b/types/catbox-redis/catbox-redis-tests.ts @@ -0,0 +1,12 @@ +import * as CatbotRedis from 'catbox-redis'; + +const cache = new CatbotRedis({ + host: 'localhost', + partition: 'test', + port: 2018, +}); + +cache.get({ + segment: 'test', + id: 'test', +}); diff --git a/types/catbox-redis/index.d.ts b/types/catbox-redis/index.d.ts new file mode 100644 index 0000000000..a0d3590953 --- /dev/null +++ b/types/catbox-redis/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for catbox-redis 4.1 +// Project: https://github.com/hapijs/catbox-redis#readme +// Definitions by: Simon Schick +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +// tslint:disable-next-line +declare module 'catbox-redis' { + import { Redis } from 'ioredis'; + import { EnginePrototype, ClientOptions, Client } from 'catbox'; + namespace CatboxRedis { + interface CatboxRedisOptions extends ClientOptions { + /** + * Raw client. + */ + client?: Redis; + /** + * the Redis server URL (if url is provided, host, port, and socket are ignored) + */ + url?: string; + /** + * the Redis server hostname. + * Defaults to '127.0.0.1'. + */ + host?: string; + /** + * the Redis server port or unix domain socket path. + * Defaults to 6379. + */ + port?: number; + /** + * the unix socket string to connect to (if socket is provided, host and port are ignored) + */ + socket?: string; + /** + * the Redis authentication password when required. + */ + password?: string; + /** + * the Redis database. + */ + database?: string; + /** + * an array of redis sentinel addresses to connect to. + */ + sentinels?: Array<{ + host: string; + }>; + /** + * the name of the sentinel master. + * (Only needed when sentinels is specified) + */ + sentinelName?: string; + } + } + class CatboxRedis extends Client { + constructor(options: CatboxRedis.CatboxRedisOptions); + } + export = CatboxRedis; + } diff --git a/types/catbox-redis/tsconfig.json b/types/catbox-redis/tsconfig.json new file mode 100644 index 0000000000..2d31a4bc59 --- /dev/null +++ b/types/catbox-redis/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "catbox-redis-tests.ts" + ] +} diff --git a/types/catbox-redis/tslint.json b/types/catbox-redis/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/catbox-redis/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/catbox/index.d.ts b/types/catbox/index.d.ts index 6d51e48696..f6881b1aef 100644 --- a/types/catbox/index.d.ts +++ b/types/catbox/index.d.ts @@ -112,6 +112,9 @@ export interface CachedObject { export type CacheItem = any; export interface ClientOptions { + /** + * this will store items under keys that start with this value. + */ partition: string; }