diff --git a/CHANGELOG.md b/CHANGELOG.md index b961a6c0a1..7361c001b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Node: Added binary variant to geo commands ([#2149](https://github.com/valkey-io/valkey-glide/pull/2149)) * Node: Added binary variant to HYPERLOGLOG commands ([#2176](https://github.com/valkey-io/valkey-glide/pull/2176)) * Node: Added FUNCTION DUMP and FUNCTION RESTORE commands ([#2129](https://github.com/valkey-io/valkey-glide/pull/2129), [#2173](https://github.com/valkey-io/valkey-glide/pull/2173)) +* Node: Added binary variant to FUNCTION commands ([#2172](https://github.com/valkey-io/valkey-glide/pull/2172)) * Node: Added ZUNIONSTORE command ([#2145](https://github.com/valkey-io/valkey-glide/pull/2145)) * Node: Added XREADGROUP command ([#2124](https://github.com/valkey-io/valkey-glide/pull/2124)) * Node: Added XINFO GROUPS command ([#2122](https://github.com/valkey-io/valkey-glide/pull/2122)) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 1617d7b707..5e8989e4c7 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -5682,6 +5682,8 @@ export class BaseClient { * @param keys - A list of `keys` accessed by the function. To ensure the correct execution of functions, * all names of keys that a function accesses must be explicitly provided as `keys`. * @param args - A list of `function` arguments and it should not represent names of keys. + * @param decoder - (Optional) {@link Decoder} type which defines how to handle the response. + * If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used. * @returns The invoked function's return value. * * @example @@ -5691,11 +5693,14 @@ export class BaseClient { * ``` */ public async fcall( - func: string, - keys: string[], - args: string[], - ): Promise { - return this.createWritePromise(createFCall(func, keys, args)); + func: GlideString, + keys: GlideString[], + args: GlideString[], + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createFCall(func, keys, args), { + decoder, + }); } /** @@ -5709,6 +5714,8 @@ export class BaseClient { * @param keys - A list of `keys` accessed by the function. To ensure the correct execution of functions, * all names of keys that a function accesses must be explicitly provided as `keys`. * @param args - A list of `function` arguments and it should not represent names of keys. + * @param decoder - (Optional) {@link Decoder} type which defines how to handle the response. + * If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used. * @returns The invoked function's return value. * * @example @@ -5719,11 +5726,14 @@ export class BaseClient { * ``` */ public async fcallReadonly( - func: string, - keys: string[], - args: string[], - ): Promise { - return this.createWritePromise(createFCallReadOnly(func, keys, args)); + func: GlideString, + keys: GlideString[], + args: GlideString[], + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createFCallReadOnly(func, keys, args), { + decoder, + }); } /** diff --git a/node/src/Commands.ts b/node/src/Commands.ts index d70338a349..a3ed23a5bd 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -2239,12 +2239,16 @@ export function createBLPop( * @internal */ export function createFCall( - func: string, - keys: string[], - args: string[], + func: GlideString, + keys: GlideString[], + args: GlideString[], ): command_request.Command { - let params: string[] = []; - params = params.concat(func, keys.length.toString(), keys, args); + const params: GlideString[] = [ + func, + keys.length.toString(), + ...keys, + ...args, + ]; return createCommand(RequestType.FCall, params); } @@ -2252,12 +2256,16 @@ export function createFCall( * @internal */ export function createFCallReadOnly( - func: string, - keys: string[], - args: string[], + func: GlideString, + keys: GlideString[], + args: GlideString[], ): command_request.Command { - let params: string[] = []; - params = params.concat(func, keys.length.toString(), keys, args); + const params: GlideString[] = [ + func, + keys.length.toString(), + ...keys, + ...args, + ]; return createCommand(RequestType.FCallReadOnly, params); } @@ -2265,7 +2273,7 @@ export function createFCallReadOnly( * @internal */ export function createFunctionDelete( - libraryCode: string, + libraryCode: GlideString, ): command_request.Command { return createCommand(RequestType.FunctionDelete, [libraryCode]); } @@ -2285,7 +2293,7 @@ export function createFunctionFlush(mode?: FlushMode): command_request.Command { * @internal */ export function createFunctionLoad( - libraryCode: string, + libraryCode: GlideString, replace?: boolean, ): command_request.Command { const args = replace ? ["REPLACE", libraryCode] : [libraryCode]; @@ -2295,7 +2303,7 @@ export function createFunctionLoad( /** Optional arguments for `FUNCTION LIST` command. */ export type FunctionListOptions = { /** A wildcard pattern for matching library names. */ - libNamePattern?: string; + libNamePattern?: GlideString; /** Specifies whether to request the library code from the server or not. */ withCode?: boolean; }; @@ -2303,7 +2311,7 @@ export type FunctionListOptions = { /** Type of the response of `FUNCTION LIST` command. */ export type FunctionListResponse = Record< string, - string | Record[] + GlideString | Record[] >[]; /** @@ -2312,7 +2320,7 @@ export type FunctionListResponse = Record< export function createFunctionList( options?: FunctionListOptions, ): command_request.Command { - const args: string[] = []; + const args: GlideString[] = []; if (options) { if (options.libNamePattern) { @@ -2335,7 +2343,7 @@ export function createFunctionList( export type FunctionStatsSingleResponse = Record< string, | null - | Record // Running function/script information + | Record // Running function/script information | Record> // Execution engines information >; diff --git a/node/src/GlideClient.ts b/node/src/GlideClient.ts index ef64b570a1..ccebc647a7 100644 --- a/node/src/GlideClient.ts +++ b/node/src/GlideClient.ts @@ -558,7 +558,7 @@ export class GlideClient extends BaseClient { * @remarks Since Valkey version 7.0.0. * * @param libraryCode - The library name to delete. - * @returns A simple OK response. + * @returns A simple `"OK"` response. * * @example * ```typescript @@ -566,8 +566,10 @@ export class GlideClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async functionDelete(libraryCode: string): Promise { - return this.createWritePromise(createFunctionDelete(libraryCode)); + public async functionDelete(libraryCode: GlideString): Promise<"OK"> { + return this.createWritePromise(createFunctionDelete(libraryCode), { + decoder: Decoder.String, + }); } /** @@ -577,8 +579,10 @@ export class GlideClient extends BaseClient { * @remarks Since Valkey version 7.0.0. * * @param libraryCode - The source code that implements the library. - * @param replace - Whether the given library should overwrite a library with the same name if it + * @param options - (Optional) Additional parameters: + * - (Optional) `replace`: Whether the given library should overwrite a library with the same name if it * already exists. + * - (Optional) `decoder`: see {@link DecoderOption}. * @returns The library name that was loaded. * * @example @@ -589,11 +593,12 @@ export class GlideClient extends BaseClient { * ``` */ public async functionLoad( - libraryCode: string, - replace?: boolean, - ): Promise { + libraryCode: GlideString, + options?: { replace?: boolean } & DecoderOption, + ): Promise { return this.createWritePromise( - createFunctionLoad(libraryCode, replace), + createFunctionLoad(libraryCode, options?.replace), + { decoder: options?.decoder }, ); } @@ -603,8 +608,8 @@ export class GlideClient extends BaseClient { * @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. - * @returns A simple OK response. + * @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * @returns A simple `"OK"` response. * * @example * ```typescript @@ -612,8 +617,10 @@ export class GlideClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async functionFlush(mode?: FlushMode): Promise { - return this.createWritePromise(createFunctionFlush(mode)); + public async functionFlush(mode?: FlushMode): Promise<"OK"> { + return this.createWritePromise(createFunctionFlush(mode), { + decoder: Decoder.String, + }); } /** @@ -622,7 +629,7 @@ export class GlideClient extends BaseClient { * @see {@link https://valkey.io/commands/function-list/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param options - Parameters to filter and request additional info. + * @param options - (Optional) See {@link FunctionListOptions} and {@link DecoderOption}. * @returns Info about all or selected libraries and their functions in {@link FunctionListResponse} format. * * @example @@ -645,9 +652,11 @@ export class GlideClient extends BaseClient { * ``` */ public async functionList( - options?: FunctionListOptions, + options?: FunctionListOptions & DecoderOption, ): Promise { - return this.createWritePromise(createFunctionList(options)); + return this.createWritePromise(createFunctionList(options), { + decoder: options?.decoder, + }); } /** @@ -660,6 +669,8 @@ export class GlideClient extends BaseClient { * @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * + * @param decoder - (Optional) {@link Decoder} type which defines how to handle the response. + * If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used. * @returns A Record where the key is the node address and the value is a Record with two keys: * - `"running_script"`: Information about the running script, or `null` if no script is running. * - `"engines"`: Information about available engines and their stats. @@ -694,8 +705,12 @@ export class GlideClient extends BaseClient { * // } * ``` */ - public async functionStats(): Promise { - return this.createWritePromise(createFunctionStats()); + public async functionStats( + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createFunctionStats(), { + decoder, + }); } /** @@ -706,14 +721,16 @@ export class GlideClient extends BaseClient { * @see {@link https://valkey.io/commands/function-kill/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @returns `OK` if function is terminated. Otherwise, throws an error. + * @returns `"OK"` if function is terminated. Otherwise, throws an error. * @example * ```typescript * await client.functionKill(); * ``` */ public async functionKill(): Promise<"OK"> { - return this.createWritePromise(createFunctionKill()); + return this.createWritePromise(createFunctionKill(), { + decoder: Decoder.String, + }); } /** diff --git a/node/src/GlideClusterClient.ts b/node/src/GlideClusterClient.ts index 193d49b7d5..967ea0e568 100644 --- a/node/src/GlideClusterClient.ts +++ b/node/src/GlideClusterClient.ts @@ -798,8 +798,7 @@ export class GlideClusterClient extends BaseClient { * * @param func - The function name. * @param args - A list of `function` arguments and it should not represent names of keys. - * @param route - The command will be routed to a random node, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. + * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}. * @returns The invoked function's return value. * * @example @@ -809,12 +808,13 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async fcallWithRoute( - func: string, - args: string[], - route?: Routes, + func: GlideString, + args: GlideString[], + options?: RouteOption & DecoderOption, ): Promise> { return this.createWritePromise(createFCall(func, [], args), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: options?.decoder, }); } @@ -826,8 +826,7 @@ export class GlideClusterClient extends BaseClient { * * @param func - The function name. * @param args - A list of `function` arguments and it should not represent names of keys. - * @param route - The command will be routed to a random node, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. + * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}. * @returns The invoked function's return value. * * @example @@ -838,12 +837,13 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async fcallReadonlyWithRoute( - func: string, - args: string[], - route?: Routes, + func: GlideString, + args: GlideString[], + options?: RouteOption & DecoderOption, ): Promise> { return this.createWritePromise(createFCallReadOnly(func, [], args), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: options?.decoder, }); } @@ -854,9 +854,9 @@ export class GlideClusterClient extends BaseClient { * @remarks Since Valkey version 7.0.0. * * @param libraryCode - The library name to delete. - * @param route - The command will be routed to all primary node, unless `route` is provided, in which + * @param route - (Optional) The command will be routed to all primary node, unless `route` is provided, in which * case the client will route the command to the nodes defined by `route`. - * @returns A simple OK response. + * @returns A simple `"OK"` response. * * @example * ```typescript @@ -865,11 +865,12 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async functionDelete( - libraryCode: string, + libraryCode: GlideString, route?: Routes, - ): Promise { + ): Promise<"OK"> { return this.createWritePromise(createFunctionDelete(libraryCode), { route: toProtobufRoute(route), + decoder: Decoder.String, }); } @@ -880,10 +881,11 @@ export class GlideClusterClient extends BaseClient { * @remarks Since Valkey version 7.0.0. * * @param libraryCode - The source code that implements the library. - * @param replace - Whether the given library should overwrite a library with the same name if it + * @param options - (Optional) Additional parameters: + * - (Optional) `replace`: whether the given library should overwrite a library with the same name if it * already exists. - * @param route - The command will be routed to a random node, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. + * - (Optional) `route`: see {@link RouteOption}. + * - (Optional) `decoder`: see {@link DecoderOption}. * @returns The library name that was loaded. * * @example @@ -894,13 +896,18 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async functionLoad( - libraryCode: string, - replace?: boolean, - route?: Routes, - ): Promise { + libraryCode: GlideString, + options?: { + replace?: boolean; + } & RouteOption & + DecoderOption, + ): Promise { return this.createWritePromise( - createFunctionLoad(libraryCode, replace), - { route: toProtobufRoute(route) }, + createFunctionLoad(libraryCode, options?.replace), + { + route: toProtobufRoute(options?.route), + decoder: options?.decoder, + }, ); } @@ -910,10 +917,10 @@ export class GlideClusterClient extends BaseClient { * @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. - * @param route - The command will be routed to all primary nodes, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. - * @returns A simple OK response. + * @param options - (Optional) Additional parameters: + * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * - (Optional) `route`: see {@link RouteOption}. + * @returns A simple `"OK"` response. * * @example * ```typescript @@ -922,11 +929,13 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async functionFlush( - mode?: FlushMode, - route?: Routes, - ): Promise { - return this.createWritePromise(createFunctionFlush(mode), { - route: toProtobufRoute(route), + options?: { + mode?: FlushMode; + } & RouteOption, + ): Promise<"OK"> { + return this.createWritePromise(createFunctionFlush(options?.mode), { + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } @@ -936,9 +945,7 @@ export class GlideClusterClient extends BaseClient { * @see {@link https://valkey.io/commands/function-list/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param options - Parameters to filter and request additional info. - * @param route - The client will route the command to the nodes defined by `route`. - * If not defined, the command will be routed to a random node. + * @param options - (Optional) See {@link FunctionListOptions}, {@link DecoderOption}, and {@link RouteOption}. * @returns Info about all or selected libraries and their functions in {@link FunctionListResponse} format. * * @example @@ -961,25 +968,22 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async functionList( - options?: FunctionListOptions, - route?: Routes, + options?: FunctionListOptions & DecoderOption & RouteOption, ): Promise> { return this.createWritePromise(createFunctionList(options), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: options?.decoder, }); } /** * Returns information about the function that's currently running and information about the * available execution engines. - * - * * @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param route - The command will be routed automatically to all nodes, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. + * @param options - (Optional) See {@link DecoderOption} and {@link RouteOption}. * @returns A `Record` with two keys: * - `"running_script"` with information about the running script. * - `"engines"` with information about available engines and their stats. @@ -1020,10 +1024,11 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async functionStats( - route?: Routes, + options?: RouteOption & DecoderOption, ): Promise> { return this.createWritePromise(createFunctionStats(), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: options?.decoder, }); } @@ -1036,7 +1041,7 @@ export class GlideClusterClient extends BaseClient { * * @param route - (Optional) The client will route the command to the nodes defined by `route`. * If not defined, the command will be routed to all nodes. - * @returns `OK` if function is terminated. Otherwise, throws an error. + * @returns `"OK"` if function is terminated. Otherwise, throws an error. * * @example * ```typescript @@ -1046,6 +1051,7 @@ export class GlideClusterClient extends BaseClient { public async functionKill(route?: Routes): Promise<"OK"> { return this.createWritePromise(createFunctionKill(), { route: toProtobufRoute(route), + decoder: Decoder.String, }); } @@ -1069,8 +1075,8 @@ export class GlideClusterClient extends BaseClient { route?: Routes, ): Promise> { return this.createWritePromise(createFunctionDump(), { - decoder: Decoder.Bytes, route: toProtobufRoute(route), + decoder: Decoder.Bytes, }); } @@ -1081,10 +1087,10 @@ export class GlideClusterClient extends BaseClient { * @remarks Since Valkey version 7.0.0. * * @param payload - The serialized data from {@link functionDump}. - * @param policy - (Optional) A policy for handling existing libraries, see {@link FunctionRestorePolicy}. + * @param options - (Optional) Additional parameters: + * - (Optional) `policy`: a policy for handling existing libraries, see {@link FunctionRestorePolicy}. * {@link FunctionRestorePolicy.APPEND} is used by default. - * @param route - (Optional) The client will route the command to the nodes defined by `route`. - * If not defined, the command will be routed all primary nodes. + * - (Optional) `route`: see {@link RouteOption}. * @returns `"OK"`. * * @example @@ -1094,11 +1100,14 @@ export class GlideClusterClient extends BaseClient { */ public async functionRestore( payload: Buffer, - options?: { policy?: FunctionRestorePolicy; route?: Routes }, + options?: { policy?: FunctionRestorePolicy } & RouteOption, ): Promise<"OK"> { return this.createWritePromise( createFunctionRestore(payload, options?.policy), - { decoder: Decoder.String, route: toProtobufRoute(options?.route) }, + { + route: toProtobufRoute(options?.route), + decoder: Decoder.String, + }, ); } diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 0b9765b281..ffbca862f9 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -3189,7 +3189,11 @@ export class BaseTransaction> { * * Command Response - The invoked function's return value. */ - public fcall(func: string, keys: string[], args: string[]): T { + public fcall( + func: GlideString, + keys: GlideString[], + args: GlideString[], + ): T { return this.addAndReturn(createFCall(func, keys, args)); } @@ -3206,7 +3210,11 @@ export class BaseTransaction> { * * Command Response - The invoked function's return value. */ - public fcallReadonly(func: string, keys: string[], args: string[]): T { + public fcallReadonly( + func: GlideString, + keys: GlideString[], + args: GlideString[], + ): T { return this.addAndReturn(createFCallReadOnly(func, keys, args)); } @@ -3218,9 +3226,9 @@ export class BaseTransaction> { * * @param libraryCode - The library name to delete. * - * Command Response - `OK`. + * Command Response - `"OK"`. */ - public functionDelete(libraryCode: string): T { + public functionDelete(libraryCode: GlideString): T { return this.addAndReturn(createFunctionDelete(libraryCode)); } @@ -3231,12 +3239,12 @@ export class BaseTransaction> { * @remarks Since Valkey version 7.0.0. * * @param libraryCode - The source code that implements the library. - * @param replace - Whether the given library should overwrite a library with the same name if it + * @param replace - (Optional) Whether the given library should overwrite a library with the same name if it * already exists. * * Command Response - The library name that was loaded. */ - public functionLoad(libraryCode: string, replace?: boolean): T { + public functionLoad(libraryCode: GlideString, replace?: boolean): T { return this.addAndReturn(createFunctionLoad(libraryCode, replace)); } @@ -3246,8 +3254,8 @@ export class BaseTransaction> { * @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. - * Command Response - `OK`. + * @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * Command Response - `"OK"`. */ public functionFlush(mode?: FlushMode): T { return this.addAndReturn(createFunctionFlush(mode)); @@ -3259,7 +3267,7 @@ export class BaseTransaction> { * @see {@link https://valkey.io/commands/function-list/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * - * @param options - Parameters to filter and request additional info. + * @param options - (Optional) Parameters to filter and request additional info. * * Command Response - Info about all or selected libraries and their functions in {@link FunctionListResponse} format. */ diff --git a/node/tests/GlideClient.test.ts b/node/tests/GlideClient.test.ts index f589f4d63f..f18624d261 100644 --- a/node/tests/GlideClient.test.ts +++ b/node/tests/GlideClient.test.ts @@ -661,14 +661,26 @@ describe("GlideClient", () => { ); expect(await client.functionList()).toEqual([]); - expect(await client.functionLoad(code)).toEqual(libName); + expect(await client.functionLoad(Buffer.from(code))).toEqual( + libName, + ); expect( - await client.fcall(funcName, [], ["one", "two"]), - ).toEqual("one"); + await client.fcall( + Buffer.from(funcName), + [], + [Buffer.from("one"), "two"], + Decoder.Bytes, + ), + ).toEqual(Buffer.from("one")); expect( - await client.fcallReadonly(funcName, [], ["one", "two"]), - ).toEqual("one"); + await client.fcallReadonly( + Buffer.from(funcName), + [], + ["one", Buffer.from("two")], + Decoder.Bytes, + ), + ).toEqual(Buffer.from("one")); let functionStats = await client.functionStats(); @@ -677,7 +689,7 @@ describe("GlideClient", () => { } let functionList = await client.functionList({ - libNamePattern: libName, + libNamePattern: Buffer.from(libName), }); let expectedDescription = new Map([ [funcName, null], @@ -694,13 +706,17 @@ describe("GlideClient", () => { ); // re-load library without replace - await expect(client.functionLoad(code)).rejects.toThrow( `Library '${libName}' already exists`, ); // re-load library with replace - expect(await client.functionLoad(code, true)).toEqual(libName); + expect( + await client.functionLoad(code, { + replace: true, + decoder: Decoder.Bytes, + }), + ).toEqual(Buffer.from(libName)); // overwrite lib with new code const func2Name = "myfunc2c" + uuidv4().replaceAll("-", ""); @@ -712,9 +728,9 @@ describe("GlideClient", () => { ]), true, ); - expect(await client.functionLoad(newCode, true)).toEqual( - libName, - ); + expect( + await client.functionLoad(newCode, { replace: true }), + ).toEqual(libName); functionList = await client.functionList({ withCode: true }); expectedDescription = new Map([ @@ -868,7 +884,9 @@ describe("GlideClient", () => { await expect(client.functionKill()).rejects.toThrow(/notbusy/i); // load the lib - expect(await client.functionLoad(code, true)).toEqual(libName); + expect( + await client.functionLoad(code, { replace: true }), + ).toEqual(libName); try { // call the function without await @@ -940,7 +958,9 @@ describe("GlideClient", () => { await expect(client.functionKill()).rejects.toThrow(/notbusy/i); // load the lib - expect(await client.functionLoad(code, true)).toEqual(libName); + expect( + await client.functionLoad(code, { replace: true }), + ).toEqual(libName); let promise = null; diff --git a/node/tests/GlideClusterClient.test.ts b/node/tests/GlideClusterClient.test.ts index 9d4687f69e..d938d20c2b 100644 --- a/node/tests/GlideClusterClient.test.ts +++ b/node/tests/GlideClusterClient.test.ts @@ -862,18 +862,19 @@ describe("GlideClusterClient", () => { ? { type: "primarySlotKey", key: "1" } : "allPrimaries"; - let functionList = await client.functionList( - { libNamePattern: libName }, - route, - ); + let functionList = await client.functionList({ + libNamePattern: libName, + route: route, + }); checkClusterResponse( functionList as object, singleNodeRoute, (value) => expect(value).toEqual([]), ); - let functionStats = - await client.functionStats(route); + let functionStats = await client.functionStats({ + route: route, + }); checkClusterResponse( functionStats as object, singleNodeRoute, @@ -891,10 +892,10 @@ describe("GlideClusterClient", () => { libName, ); - functionList = await client.functionList( - { libNamePattern: libName }, - route, - ); + functionList = await client.functionList({ + libNamePattern: libName, + route: route, + }); let expectedDescription = new Map< string, string | null @@ -914,8 +915,9 @@ describe("GlideClusterClient", () => { expectedFlags, ), ); - functionStats = - await client.functionStats(route); + functionStats = await client.functionStats({ + route: route, + }); checkClusterResponse( functionStats as object, singleNodeRoute, @@ -932,7 +934,7 @@ describe("GlideClusterClient", () => { let fcall = await client.fcallWithRoute( funcName, ["one", "two"], - route, + { route: route }, ); checkClusterResponse( fcall as object, @@ -942,7 +944,7 @@ describe("GlideClusterClient", () => { fcall = await client.fcallReadonlyWithRoute( funcName, ["one", "two"], - route, + { route: route }, ); checkClusterResponse( fcall as object, @@ -959,7 +961,9 @@ describe("GlideClusterClient", () => { // re-load library with replace expect( - await client.functionLoad(code, true), + await client.functionLoad(code, { + replace: true, + }), ).toEqual(libName); // overwrite lib with new code @@ -974,13 +978,16 @@ describe("GlideClusterClient", () => { true, ); expect( - await client.functionLoad(newCode, true), + await client.functionLoad(newCode, { + replace: true, + }), ).toEqual(libName); - functionList = await client.functionList( - { libNamePattern: libName, withCode: true }, - route, - ); + functionList = await client.functionList({ + libNamePattern: libName, + withCode: true, + route: route, + }); expectedDescription = new Map< string, string | null @@ -1005,8 +1012,9 @@ describe("GlideClusterClient", () => { newCode, ), ); - functionStats = - await client.functionStats(route); + functionStats = await client.functionStats({ + route: route, + }); checkClusterResponse( functionStats as object, singleNodeRoute, @@ -1022,7 +1030,7 @@ describe("GlideClusterClient", () => { fcall = await client.fcallWithRoute( func2Name, ["one", "two"], - route, + { route: route }, ); checkClusterResponse( fcall as object, @@ -1033,7 +1041,7 @@ describe("GlideClusterClient", () => { fcall = await client.fcallReadonlyWithRoute( func2Name, ["one", "two"], - route, + { route: route }, ); checkClusterResponse( fcall as object, @@ -1078,8 +1086,7 @@ describe("GlideClusterClient", () => { : "allPrimaries"; const functionList1 = await client.functionList( - {}, - route, + { route: route }, ); checkClusterResponse( functionList1 as object, @@ -1089,25 +1096,23 @@ describe("GlideClusterClient", () => { // load the library expect( - await client.functionLoad( - code, - undefined, - route, - ), + await client.functionLoad(code, { + route: route, + }), ).toEqual(libName); // flush functions expect( - await client.functionFlush( - FlushMode.SYNC, - route, - ), + await client.functionFlush({ + mode: FlushMode.SYNC, + route: route, + }), ).toEqual("OK"); expect( - await client.functionFlush( - FlushMode.ASYNC, - route, - ), + await client.functionFlush({ + mode: FlushMode.ASYNC, + route: route, + }), ).toEqual("OK"); const functionList2 = @@ -1120,11 +1125,9 @@ describe("GlideClusterClient", () => { // Attempt to re-load library without overwriting to ensure FLUSH was effective expect( - await client.functionLoad( - code, - undefined, - route, - ), + await client.functionLoad(code, { + route: route, + }), ).toEqual(libName); } finally { expect(await client.functionFlush()).toEqual( @@ -1162,10 +1165,9 @@ describe("GlideClusterClient", () => { const route: Routes = singleNodeRoute ? { type: "primarySlotKey", key: "1" } : "allPrimaries"; - let functionList = await client.functionList( - {}, - route, - ); + let functionList = await client.functionList({ + route: route, + }); checkClusterResponse( functionList as object, singleNodeRoute, @@ -1173,11 +1175,9 @@ describe("GlideClusterClient", () => { ); // load the library expect( - await client.functionLoad( - code, - undefined, - route, - ), + await client.functionLoad(code, { + route: route, + }), ).toEqual(libName); // Delete the function @@ -1185,10 +1185,11 @@ describe("GlideClusterClient", () => { await client.functionDelete(libName, route), ).toEqual("OK"); - functionList = await client.functionList( - { libNamePattern: libName, withCode: true }, - route, - ); + functionList = await client.functionList({ + libNamePattern: libName, + withCode: true, + route: route, + }); checkClusterResponse( functionList as object, singleNodeRoute, @@ -1251,17 +1252,18 @@ describe("GlideClusterClient", () => { // load the lib expect( - await client.functionLoad( - code, - true, - route, - ), + await client.functionLoad(code, { + replace: true, + route: route, + }), ).toEqual(libName); try { // call the function without await const promise = testClient - .fcallWithRoute(funcName, [], route) + .fcallWithRoute(funcName, [], { + route: route, + }) .catch((e) => expect( (e as Error).message, @@ -1323,7 +1325,10 @@ describe("GlideClusterClient", () => { ? { type: "primarySlotKey", key: "1" } : "allPrimaries"; expect( - await client.functionFlush(FlushMode.SYNC, route), + await client.functionFlush({ + mode: FlushMode.SYNC, + route: route, + }), ).toEqual("OK"); try { @@ -1351,17 +1356,15 @@ describe("GlideClusterClient", () => { false, ); expect( - await client.functionLoad( - code, - undefined, - route, - ), + await client.functionLoad(code, { + route: route, + }), ).toEqual(name1); - const flist = await client.functionList( - { withCode: true }, - route, - ); + const flist = await client.functionList({ + withCode: true, + route: route, + }); response = await client.functionDump(route); const dump = ( singleNodeRoute @@ -1395,18 +1398,18 @@ describe("GlideClusterClient", () => { ).toEqual("OK"); // but nothing changed - all code overwritten expect( - await client.functionList( - { withCode: true }, - route, - ), + await client.functionList({ + withCode: true, + route: route, + }), ).toEqual(flist); // create lib with another name, but with the same function names expect( - await client.functionFlush( - FlushMode.SYNC, - route, - ), + await client.functionFlush({ + mode: FlushMode.SYNC, + route: route, + }), ).toEqual("OK"); code = generateLuaLibCode( name2, @@ -1417,11 +1420,9 @@ describe("GlideClusterClient", () => { false, ); expect( - await client.functionLoad( - code, - undefined, - route, - ), + await client.functionLoad(code, { + route: route, + }), ).toEqual(name2); // REPLACE policy now fails due to a name collision @@ -1441,17 +1442,17 @@ describe("GlideClusterClient", () => { }), ).toEqual("OK"); expect( - await client.functionList( - { withCode: true }, - route, - ), + await client.functionList({ + withCode: true, + route: route, + }), ).toEqual(flist); // call restored functions let res = await client.fcallWithRoute( name1, ["meow", "woem"], - route, + { route: route }, ); if (singleNodeRoute) { @@ -1465,7 +1466,7 @@ describe("GlideClusterClient", () => { res = await client.fcallWithRoute( name2, ["meow", "woem"], - route, + { route: route }, ); if (singleNodeRoute) { @@ -1523,7 +1524,10 @@ describe("GlideClusterClient", () => { // load the lib expect( - await client.functionLoad(code, true, route), + await client.functionLoad(code, { + replace: true, + route: route, + }), ).toEqual(libName); let promise = null; @@ -1600,7 +1604,10 @@ describe("GlideClusterClient", () => { false, ); expect( - await client.functionLoad(code, true, route), + await client.functionLoad(code, { + replace: true, + route: route, + }), ).toEqual(name1); // Verify functionDump diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 0b177e62f0..ba8e185232 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -462,7 +462,7 @@ export function checkFunctionListResponse( */ export function checkFunctionStatsResponse( response: FunctionStatsSingleResponse, - runningFunction: string[], + runningFunction: GlideString[], libCount: number, functionCount: number, ) {