handy-redis
Advanced tools
Comparing version 2.1.0 to 2.2.0
import * as nodeRedis from "redis"; | ||
import { Commands } from "../generated/interface"; | ||
import { Push } from "../push"; | ||
export declare type CommandResult<K extends keyof Commands> = ReturnType<Commands[K]> extends Promise<infer X> ? X : never; | ||
declare module "../generated/interface" { | ||
interface ResultTypes<Result, Context> { | ||
/** | ||
* This determines the correct type for a node_redis multi result. e.g. `multi.keys('foo:*')` should be a multi instance | ||
* which will include include a `string[]` value in the array eventually returned by `.exec()`. | ||
*/ | ||
node_redis_multi: WrappedNodeRedisMulti<Push<Extract<Context, { | ||
results: unknown[]; | ||
}>["results"], MultiResult<Result>>>; | ||
} | ||
} | ||
export declare type MultiResult<T> = T | nodeRedis.ReplyError; | ||
/** | ||
@@ -29,8 +40,10 @@ * types from multis depend on a bunch of type inference so in IDEs they can end up looking like: | ||
}; | ||
export declare type MultiCommands = Exclude<keyof Commands, "exec" | "exec_atomic">; | ||
export declare type WrappedNodeRedisMulti<Results extends unknown[] = []> = { | ||
[K in MultiCommands]: (...args: Parameters<Commands[K]>) => WrappedNodeRedisMulti<Push<Results, CommandResult<K> | nodeRedis.ReplyError>>; | ||
} & { | ||
exec: () => Promise<Results>; | ||
exec_atomic: () => Promise<Results>; | ||
}; | ||
export interface WrappedNodeRedisMulti<Results extends unknown[] = []> extends Omit<Commands<{ | ||
type: "node_redis_multi"; | ||
results: Results; | ||
}>, "exec"> { | ||
/** Execute all commands issued after multi */ | ||
exec(): Promise<Results>; | ||
/** Execute all commands issued after multi */ | ||
exec_atomic(): Promise<Results>; | ||
} |
{ | ||
"name": "handy-redis", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A redis client with first-class Promise and TypeScript support, and extensive documentation.", | ||
@@ -62,20 +62,21 @@ "keywords": [ | ||
"@types/eslint": "7.2.6", | ||
"@types/jest": "26.0.16", | ||
"@types/jest": "26.0.19", | ||
"@types/lodash": "4.14.165", | ||
"@types/node": "12.12.37", | ||
"@types/redis-mock": "0.17.0", | ||
"@typescript-eslint/eslint-plugin": "4.9.0", | ||
"@typescript-eslint/parser": "4.9.0", | ||
"@typescript-eslint/eslint-plugin": "4.11.0", | ||
"@typescript-eslint/parser": "4.11.0", | ||
"check-clean": "0.3.0", | ||
"del-cli": "3.0.1", | ||
"downlevel-dts": "0.7.0", | ||
"eslint": "7.15.0", | ||
"eslint": "7.16.0", | ||
"eslint-config-xo": "0.33.1", | ||
"eslint-config-xo-typescript": "0.36.0", | ||
"eslint-plugin-codegen": "0.14.3", | ||
"eslint-config-xo-typescript": "0.37.0", | ||
"eslint-plugin-codegen": "0.14.4", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jest": "24.1.3", | ||
"eslint-plugin-prettier": "3.2.0", | ||
"eslint-plugin-unicorn": "23.0.0", | ||
"expect-type": "0.10.0", | ||
"eslint-plugin-prettier": "3.3.0", | ||
"eslint-plugin-unicorn": "24.0.0", | ||
"expect-type": "0.11.0", | ||
"fs-syncer": "0.3.4-next.1", | ||
"jest": "26.6.3", | ||
@@ -86,8 +87,8 @@ "lodash": "4.17.20", | ||
"redis": "3.0.2", | ||
"redis-mock": "0.55.0", | ||
"redis-mock": "0.56.0", | ||
"semantic-release": "17.3.0", | ||
"string-argv": "0.3.1", | ||
"ts-jest": "26.4.4", | ||
"ts-node": "9.1.0", | ||
"typescript": "4.1.2" | ||
"ts-node": "9.1.1", | ||
"typescript": "4.1.3" | ||
}, | ||
@@ -94,0 +95,0 @@ "engines": { |
@@ -137,3 +137,4 @@ # handy-redis | ||
- `generate-client`: | ||
- the json-schema from the previous step is parsed and used to generate a [typescript interface of commands](./src/generated/interface.ts) | ||
- the json-schema from the previous step is parsed and used to generate a [typescript interface of commands](./src/generated/interface.ts). | ||
- Commands use a basic higher-kinded types implementation. The `Multi` interface requires a key pointing to a property on a `ResultTypes<Result, Context>` interface, with properties defined via module augmentation. By default, each command returns a promisified result type. See the [node_redis multi implementation](./src/node_redis/multi.ts) for an example which configures each command to return a chainable multi instance, using previous commands as the `Context`. | ||
- `generate-tests`: | ||
@@ -140,0 +141,0 @@ - the markdown docs for each command are parsed and transformed into typescript calls. e.g. `SET FOO BAR EX 60` is decoded into `client.set('foo', 'bar', ['EX', 60])` |
import * as nodeRedis from "redis"; | ||
import { Commands } from "../generated/interface"; | ||
import { Push } from "../push"; | ||
export declare type CommandResult<K extends keyof Commands> = ReturnType<Commands[K]> extends Promise<infer X> ? X : never; | ||
declare module "../generated/interface" { | ||
interface ResultTypes<Result, Context> { | ||
/** | ||
* This determines the correct type for a node_redis multi result. e.g. `multi.keys('foo:*')` should be a multi instance | ||
* which will include include a `string[]` value in the array eventually returned by `.exec()`. | ||
*/ | ||
node_redis_multi: WrappedNodeRedisMulti<Push<Extract<Context, { | ||
results: unknown[]; | ||
}>["results"], MultiResult<Result>>>; | ||
} | ||
} | ||
export declare type MultiResult<T> = T | nodeRedis.ReplyError; | ||
/** | ||
@@ -29,9 +40,14 @@ * types from multis depend on a bunch of type inference so in IDEs they can end up looking like: | ||
}; | ||
export declare type MultiCommands = Exclude<keyof Commands, "exec" | "exec_atomic">; | ||
export declare type WrappedNodeRedisMulti<Results extends unknown[] = [ | ||
]> = { | ||
[K in MultiCommands]: (...args: Parameters<Commands[K]>) => WrappedNodeRedisMulti<Push<Results, CommandResult<K> | nodeRedis.ReplyError>>; | ||
} & { | ||
exec: () => Promise<Results>; | ||
exec_atomic: () => Promise<Results>; | ||
}; | ||
export interface WrappedNodeRedisMulti<Results extends unknown[] = [ | ||
]> extends Pick<Commands<{ | ||
type: "node_redis_multi"; | ||
results: Results; | ||
}>, Exclude<keyof Commands<{ | ||
type: "node_redis_multi"; | ||
results: Results; | ||
}>, "exec">> { | ||
/** Execute all commands issued after multi */ | ||
exec(): Promise<Results>; | ||
/** Execute all commands issued after multi */ | ||
exec_atomic(): Promise<Results>; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2064412
38
41768
180
32