Skip to content

Commit

Permalink
feat: 🎸 add and improve typings from DT (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
damusix authored Aug 4, 2023
1 parent 683998d commit 2888daa
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Type definitions for @hapi/catbox-redis 7.0
// Project: https://github.com/hapijs/catbox-redis
// Definitions by: Simon Schick <https://github.com/SimonSchick>
// Silas Rech <https://github.com/lenovouser>
// Danilo Alonso <https://github.com/damusix>
// 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<T> extends Client<T> {

constructor (opts: CatboxRedisOptions);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"node": ">=14.0.0"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
Expand Down
24 changes: 24 additions & 0 deletions test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Engine } from '..';
import Redis, { Cluster } from 'ioredis';

const cache = new Engine<string>({
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()])
});

0 comments on commit 2888daa

Please sign in to comment.