diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..f394ffb --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for @hapi/catbox-redis 7.0 +// Project: https://github.com/hapijs/catbox-redis +// Definitions by: Simon Schick +// Silas Rech +// Danilo Alonso +// TypeScript Version: 5 + +import { EnginePrototype, ClientOptions, Client } from '@hapi/catbox'; +import Redis, { Cluster } from 'ioredis'; + +export interface CatboxRedisOptions extends ClientOptions { + + /** + * Raw client. + */ + client?: Redis | Cluster | undefined; + /** + * the Redis server URL (if url is provided, host, port, and socket are ignored) + */ + url?: string | undefined; + /** + * the Redis server hostname. + * Defaults to '127.0.0.1'. + */ + host?: string | undefined; + /** + * the Redis server port or unix domain socket path. + * Defaults to 6379. + */ + port?: number | undefined; + /** + * the unix socket string to connect to (if socket is provided, host and port are ignored) + */ + socket?: string | undefined; + /** + * the Redis authentication password when required. + */ + password?: string | undefined; + /** + * the Redis database. + */ + database?: string | undefined; + /** + * an array of redis sentinel addresses to connect to. + */ + sentinels?: Array<{ + host: string; + }> | undefined; + /** + * the name of the sentinel master. + * (Only needed when sentinels is specified) + */ + sentinelName?: string | undefined; +} + +export class Engine extends Client { + + constructor (opts: CatboxRedisOptions); +} diff --git a/package.json b/package.json index db42faf..bb20b61 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "node": ">=14.0.0" }, "main": "lib/index.js", + "types": "lib/index.d.ts", "files": [ "lib" ], diff --git a/test/types.ts b/test/types.ts new file mode 100644 index 0000000..8f19f65 --- /dev/null +++ b/test/types.ts @@ -0,0 +1,24 @@ +import { Engine } from '..'; +import Redis, { Cluster } from 'ioredis'; + +const cache = new Engine({ + client: new Redis(), + host: 'localhost', + partition: 'test', + port: 2018, +}); + +cache.get({ + segment: 'test', + id: 'test', +}); + +cache.set({ + segment: 'test', + id: 'test', +}, 'test', 123); + + +new Engine({ + client: new Cluster([new Redis(), new Redis()]) +});