Skip to content

Commit

Permalink
Node: Rename ReturnType. (valkey-io#2241)
Browse files Browse the repository at this point in the history
Rename `ReturnType`.

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored Sep 10, 2024
1 parent 2af1e9b commit 6e32c83
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Renamed `ReturnType` to `GlideReturnType` ([#2241](https://github.com/valkey-io/valkey-glide/pull/2241))
* Node, Python: Rename `stop` to `end` in sorted set queries ([#2214](https://github.com/valkey-io/valkey-glide/pull/2214))
* Node: Added binary variant to sorted set commands - part 1 ([#2190](https://github.com/valkey-io/valkey-glide/pull/2190))
* Node: Added binary variant to HSCAN command ([#2240](https://github.com/valkey-io/valkey-glide/pull/2240))
Expand Down
4 changes: 2 additions & 2 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function initialize() {
ConfigurationError,
ExecAbortError,
RedisError,
ReturnType,
GlideReturnType,
StreamEntries,
ReturnTypeXinfoStream,
RequestError,
Expand Down Expand Up @@ -281,7 +281,7 @@ function initialize() {
ConfigurationError,
ExecAbortError,
RedisError,
ReturnType,
GlideReturnType,
RequestError,
TimeoutError,
ConnectionError,
Expand Down
26 changes: 14 additions & 12 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ import {
type PromiseFunction = (value?: any) => void;
type ErrorFunction = (error: RedisError) => void;
/* eslint @typescript-eslint/consistent-indexed-object-style: off, @typescript-eslint/consistent-type-definitions: off */
export type ReturnTypeRecord = { [key: string]: ReturnType };
export type ReturnTypeMap = Map<string, ReturnType>;
export type ReturnTypeRecord = { [key: string]: GlideReturnType };
export type ReturnTypeMap = Map<string, GlideReturnType>;
export interface ReturnTypeAttribute {
value: ReturnType;
value: GlideReturnType;
attributes: ReturnTypeRecord;
}
export enum ProtocolVersion {
Expand All @@ -263,19 +263,19 @@ export enum ProtocolVersion {
/** Use RESP3 to communicate with the server nodes. */
RESP3 = connection_request.ProtocolVersion.RESP3,
}
export type ReturnType =
export type GlideReturnType =
| "OK"
| string
| number
| null
| boolean
| bigint
| Buffer
| Set<ReturnType>
| Set<GlideReturnType>
| ReturnTypeRecord
| ReturnTypeMap
| ReturnTypeAttribute
| ReturnType[];
| GlideReturnType[];

/**
* Union type that can store either a valid UTF-8 string or array of bytes.
Expand Down Expand Up @@ -931,15 +931,17 @@ export class BaseClient {
* @internal
*/
protected processResultWithSetCommands(
result: ReturnType[] | null,
result: GlideReturnType[] | null,
setCommandsIndexes: number[],
): ReturnType[] | null {
): GlideReturnType[] | null {
if (result === null) {
return null;
}

for (const index of setCommandsIndexes) {
result[index] = new Set<ReturnType>(result[index] as ReturnType[]);
result[index] = new Set<GlideReturnType>(
result[index] as GlideReturnType[],
);
}

return result;
Expand Down Expand Up @@ -3582,7 +3584,7 @@ export class BaseClient {
public async invokeScript(
script: Script,
options?: ScriptOptions & DecoderOption,
): Promise<ReturnType> {
): Promise<GlideReturnType> {
const scriptInvocation = command_request.ScriptInvocation.create({
hash: script.getHash(),
keys: options?.keys?.map((item) => {
Expand Down Expand Up @@ -6109,7 +6111,7 @@ export class BaseClient {
keys: GlideString[],
args: GlideString[],
options?: DecoderOption,
): Promise<ReturnType> {
): Promise<GlideReturnType> {
return this.createWritePromise(createFCall(func, keys, args), options);
}

Expand Down Expand Up @@ -6139,7 +6141,7 @@ export class BaseClient {
keys: GlideString[],
args: GlideString[],
options?: DecoderOption,
): Promise<ReturnType> {
): Promise<GlideReturnType> {
return this.createWritePromise(
createFCallReadOnly(func, keys, args),
options,
Expand Down
10 changes: 5 additions & 5 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
BaseClient,
BaseClientConfiguration,
Decoder,
DecoderOption,
DecoderOption, // eslint-disable-line @typescript-eslint/no-unused-vars
GlideReturnType,
GlideString,
PubSubMsg,
ReadFrom, // eslint-disable-line @typescript-eslint/no-unused-vars
ReturnType,
} from "./BaseClient";
import {
FlushMode,
Expand Down Expand Up @@ -188,8 +188,8 @@ export class GlideClient extends BaseClient {
public async exec(
transaction: Transaction,
options?: DecoderOption,
): Promise<ReturnType[] | null> {
return this.createWritePromise<ReturnType[] | null>(
): Promise<GlideReturnType[] | null> {
return this.createWritePromise<GlideReturnType[] | null>(
transaction.commands,
options,
).then((result) =>
Expand Down Expand Up @@ -221,7 +221,7 @@ export class GlideClient extends BaseClient {
public async customCommand(
args: GlideString[],
options?: DecoderOption,
): Promise<ReturnType> {
): Promise<GlideReturnType> {
return this.createWritePromise(createCustomCommand(args), options);
}

Expand Down
14 changes: 7 additions & 7 deletions node/src/GlideClusterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
BaseClient,
BaseClientConfiguration,
Decoder,
DecoderOption,
DecoderOption, // eslint-disable-line @typescript-eslint/no-unused-vars
GlideReturnType,
GlideString,
PubSubMsg,
ReadFrom, // eslint-disable-line @typescript-eslint/no-unused-vars
ReturnType,
} from "./BaseClient";
import {
FlushMode,
Expand Down Expand Up @@ -303,7 +303,7 @@ export class GlideClusterClient extends BaseClient {
public async customCommand(
args: GlideString[],
options?: RouteOption & DecoderOption,
): Promise<ClusterResponse<ReturnType>> {
): Promise<ClusterResponse<GlideReturnType>> {
const command = createCustomCommand(args);
return super.createWritePromise(command, options);
}
Expand All @@ -330,8 +330,8 @@ export class GlideClusterClient extends BaseClient {
options?: {
route?: SingleNodeRoute;
} & DecoderOption,
): Promise<ReturnType[] | null> {
return this.createWritePromise<ReturnType[] | null>(
): Promise<GlideReturnType[] | null> {
return this.createWritePromise<GlideReturnType[] | null>(
transaction.commands,
options,
).then((result) =>
Expand Down Expand Up @@ -723,7 +723,7 @@ export class GlideClusterClient extends BaseClient {
func: GlideString,
args: GlideString[],
options?: RouteOption & DecoderOption,
): Promise<ClusterResponse<ReturnType>> {
): Promise<ClusterResponse<GlideReturnType>> {
return this.createWritePromise(createFCall(func, [], args), options);
}

Expand All @@ -749,7 +749,7 @@ export class GlideClusterClient extends BaseClient {
func: GlideString,
args: GlideString[],
options?: RouteOption & DecoderOption,
): Promise<ClusterResponse<ReturnType>> {
): Promise<ClusterResponse<GlideReturnType>> {
return this.createWritePromise(
createFCallReadOnly(func, [], args),
options,
Expand Down
8 changes: 4 additions & 4 deletions node/tests/GlideClientInternals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
InfoOptions,
Logger,
RequestError,
ReturnType,
GlideReturnType,
SlotKeyTypes,
TimeUnit,
} from "..";
Expand Down Expand Up @@ -59,7 +59,7 @@ enum ResponseType {
OK,
}

function createLeakedValue(value: ReturnType): Long {
function createLeakedValue(value: GlideReturnType): Long {
if (value == null) {
return new Long(0, 0);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ function sendResponse(
callbackIndex: number,
response_data?: {
message?: string;
value?: ReturnType;
value?: GlideReturnType;
requestErrorType?: response.RequestErrorType;
},
) {
Expand Down Expand Up @@ -289,7 +289,7 @@ describe("SocketConnectionInternals", () => {
});

describe("handling types", () => {
const test_receiving_value = async (expected: ReturnType) => {
const test_receiving_value = async (expected: GlideReturnType) => {
await testWithResources(async (connection, socket) => {
socket.once("data", (data) => {
const reader = Reader.create(data);
Expand Down
6 changes: 3 additions & 3 deletions node/tests/GlideClusterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
Decoder,
FunctionListResponse,
GlideClusterClient,
GlideReturnType,
InfoOptions,
ListDirection,
ProtocolVersion,
RequestError,
ReturnType,
Routes,
ScoreFilter,
SlotKeyTypes,
Expand Down Expand Up @@ -1461,7 +1461,7 @@ describe("GlideClusterClient", () => {
expect(res).toEqual("meow");
} else {
Object.values(
res as Record<string, ReturnType>,
res as Record<string, GlideReturnType>,
).forEach((r) => expect(r).toEqual("meow"));
}

Expand All @@ -1475,7 +1475,7 @@ describe("GlideClusterClient", () => {
expect(res).toEqual(2);
} else {
Object.values(
res as Record<string, ReturnType>,
res as Record<string, GlideReturnType>,
).forEach((r) => expect(r).toEqual(2));
}
} finally {
Expand Down
4 changes: 2 additions & 2 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import {
GeospatialData,
GlideClient,
GlideClusterClient,
GlideReturnType,
GlideString,
InfBoundary,
InfoOptions,
InsertPosition,
ListDirection,
ProtocolVersion,
RequestError,
ReturnType,
ScoreFilter,
Script,
SignedEncoding,
Expand Down Expand Up @@ -11494,7 +11494,7 @@ export function runBaseTests(config: {
mkStream: true,
});

const promiseList: [string, Promise<ReturnType>][] = [
const promiseList: [string, Promise<GlideReturnType>][] = [
["bzpopmax", client.bzpopmax(keyz, 0)],
["bzpopmin", client.bzpopmin(keyz, 0)],
["blpop", client.blpop(keyz, 0)],
Expand Down
30 changes: 15 additions & 15 deletions node/tests/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
InsertPosition,
ListDirection,
ProtocolVersion,
ReturnType,
GlideReturnType,
ReturnTypeMap,
ScoreFilter,
SignedEncoding,
Expand Down Expand Up @@ -222,7 +222,7 @@ export function getFirstResult(
/** Check a multi-node response from a cluster. */
export function checkClusterMultiNodeResponse(
res: object,
predicate: (value: ReturnType) => void,
predicate: (value: GlideReturnType) => void,
) {
for (const nodeResponse of Object.values(res)) {
predicate(nodeResponse);
Expand All @@ -233,9 +233,9 @@ export function checkClusterMultiNodeResponse(
export function checkClusterResponse(
res: object,
singleNodeRoute: boolean,
predicate: (value: ReturnType) => void,
predicate: (value: GlideReturnType) => void,
) {
if (singleNodeRoute) predicate(res as ReturnType);
if (singleNodeRoute) predicate(res as GlideReturnType);
else checkClusterMultiNodeResponse(res, predicate);
}

Expand Down Expand Up @@ -495,8 +495,8 @@ export function checkFunctionStatsResponse(
* @param expectedResponseData - Expected result data from {@link transactionTest}.
*/
export function validateTransactionResponse(
response: ReturnType[] | null,
expectedResponseData: [string, ReturnType][],
response: GlideReturnType[] | null,
expectedResponseData: [string, GlideReturnType][],
) {
const failedChecks: string[] = [];

Expand Down Expand Up @@ -540,12 +540,12 @@ export function validateTransactionResponse(
*/
export async function encodableTransactionTest(
baseTransaction: Transaction | ClusterTransaction,
valueEncodedResponse: ReturnType,
): Promise<[string, ReturnType][]> {
valueEncodedResponse: GlideReturnType,
): Promise<[string, GlideReturnType][]> {
const key = "{key}" + uuidv4(); // string
const value = "value";
// array of tuples - first element is test name/description, second - expected return value
const responseData: [string, ReturnType][] = [];
const responseData: [string, GlideReturnType][] = [];

baseTransaction.set(key, value);
responseData.push(["set(key, value)", "OK"]);
Expand All @@ -562,7 +562,7 @@ export async function encodableTransactionTest(
*/
export async function encodedTransactionTest(
baseTransaction: Transaction | ClusterTransaction,
): Promise<[string, ReturnType][]> {
): Promise<[string, GlideReturnType][]> {
const key1 = "{key}" + uuidv4(); // string
const key2 = "{key}" + uuidv4(); // string
const key = "dumpKey";
Expand All @@ -572,7 +572,7 @@ export async function encodedTransactionTest(
const value = "value";
const valueEncoded = Buffer.from(value);
// array of tuples - first element is test name/description, second - expected return value
const responseData: [string, ReturnType][] = [];
const responseData: [string, GlideReturnType][] = [];

baseTransaction.set(key1, value);
responseData.push(["set(key1, value)", "OK"]);
Expand Down Expand Up @@ -611,14 +611,14 @@ export async function encodedTransactionTest(
export async function DumpAndRestureTest(
baseTransaction: Transaction,
valueResponse: GlideString,
): Promise<[string, ReturnType][]> {
): Promise<[string, GlideReturnType][]> {
const key = "dumpKey";
const dumpResult = Buffer.from([
0, 5, 118, 97, 108, 117, 101, 11, 0, 232, 41, 124, 75, 60, 53, 114, 231,
]);
const value = "value";
// array of tuples - first element is test name/description, second - expected return value
const responseData: [string, ReturnType][] = [];
const responseData: [string, GlideReturnType][] = [];

baseTransaction.set(key, value);
responseData.push(["set(key, value)", "OK"]);
Expand Down Expand Up @@ -647,7 +647,7 @@ export async function DumpAndRestureTest(
export async function transactionTest(
baseTransaction: Transaction | ClusterTransaction,
version: string,
): Promise<[string, ReturnType][]> {
): Promise<[string, GlideReturnType][]> {
const key1 = "{key}" + uuidv4(); // string
const key2 = "{key}" + uuidv4(); // string
const key3 = "{key}" + uuidv4(); // string
Expand Down Expand Up @@ -681,7 +681,7 @@ export async function transactionTest(
const groupName2 = uuidv4();
const consumer = uuidv4();
// array of tuples - first element is test name/description, second - expected return value
const responseData: [string, ReturnType][] = [];
const responseData: [string, GlideReturnType][] = [];

baseTransaction.publish("test_message", key1);
responseData.push(['publish("test_message", key1)', 0]);
Expand Down

0 comments on commit 6e32c83

Please sign in to comment.