Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 add and improve typings from DT #126

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()])
});