-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add redisConfig method to infer types from config
- Loading branch information
1 parent
b29be63
commit abc1ce3
Showing
5 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* @adonisjs/redis | ||
* | ||
* (c) Harminder Virk <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { RedisConnectionConfig, RedisClusterConfig } from '@ioc:Adonis/Addons/Redis' | ||
|
||
/** | ||
* Expected shape of the config accepted by the "redisConfig" | ||
* method | ||
*/ | ||
type RedisConfig = { | ||
connections: { | ||
[name: string]: RedisConnectionConfig | RedisClusterConfig | ||
} | ||
} | ||
|
||
/** | ||
* Define config for redis | ||
*/ | ||
export function redisConfig<T extends RedisConfig & { connection: keyof T['connections'] }>( | ||
config: T | ||
): T { | ||
return config | ||
} | ||
|
||
/** | ||
* Pull connections from the config defined inside the "config/redis.ts" | ||
* file | ||
*/ | ||
export type InferConnectionsFromConfig<T extends RedisConfig> = { | ||
[K in keyof T['connections']]: T['connections'][K] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters