Skip to content

Commit

Permalink
Node: Use options for options. (valkey-io#2287)
Browse files Browse the repository at this point in the history
* Use `options` for options.

* Signed-off-by: Yury-Fridlyand <[email protected]>

---------

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored Sep 13, 2024
1 parent e782355 commit d4803a4
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 215 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: Use `options` struct for all optional arguments ([#2287](https://github.com/valkey-io/valkey-glide/pull/2287))
* Node: Added `invokeScript` API with routing for cluster client ([#2284](https://github.com/valkey-io/valkey-glide/pull/2284))
* Java: Expanded tests for converting non UTF-8 bytes to Strings ([#2286](https://github.com/valkey-io/valkey-glide/pull/2286))
* Python: Replace instances of Redis with Valkey ([#2266](https://github.com/valkey-io/valkey-glide/pull/2266))
Expand Down
145 changes: 79 additions & 66 deletions node/src/BaseClient.ts

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ export function createXAdd(
*/
export function createXDel(
key: GlideString,
ids: GlideString[],
ids: string[],
): command_request.Command {
return createCommand(RequestType.XDel, [key, ...ids]);
}
Expand Down Expand Up @@ -2582,8 +2582,8 @@ export enum FlushMode {
* @returns same data in GlideRecord type.
*/
export function convertKeysAndEntries(
record: Record<string, GlideString> | GlideRecord<GlideString>,
): GlideRecord<GlideString> {
record: Record<string, string> | GlideRecord<string>,
): GlideRecord<string> {
if (!Array.isArray(record)) {
return convertRecordToGlideRecord(record);
}
Expand Down Expand Up @@ -2633,7 +2633,7 @@ function addReadOptions(options?: StreamReadOptions): GlideString[] {
}

/** @internal */
function addStreamsArgs(keys_and_ids: GlideRecord<GlideString>): GlideString[] {
function addStreamsArgs(keys_and_ids: GlideRecord<string>): GlideString[] {
return [
"STREAMS",
...keys_and_ids.map((e) => e.key),
Expand All @@ -2645,7 +2645,7 @@ function addStreamsArgs(keys_and_ids: GlideRecord<GlideString>): GlideString[] {
* @internal
*/
export function createXRead(
keys_and_ids: GlideRecord<GlideString>,
keys_and_ids: GlideRecord<string>,
options?: StreamReadOptions,
): command_request.Command {
const args = addReadOptions(options);
Expand All @@ -2657,7 +2657,7 @@ export function createXRead(
export function createXReadGroup(
group: GlideString,
consumer: GlideString,
keys_and_ids: GlideRecord<GlideString>,
keys_and_ids: GlideRecord<string>,
options?: StreamReadGroupOptions,
): command_request.Command {
const args: GlideString[] = ["GROUP", group, consumer];
Expand Down Expand Up @@ -2788,7 +2788,7 @@ export function createXClaim(
group: GlideString,
consumer: GlideString,
minIdleTime: number,
ids: GlideString[],
ids: string[],
options?: StreamClaimOptions,
justId?: boolean,
): command_request.Command {
Expand Down Expand Up @@ -2856,7 +2856,7 @@ export interface StreamGroupOptions {
export function createXGroupCreate(
key: GlideString,
groupName: GlideString,
id: GlideString,
id: string,
options?: StreamGroupOptions,
): command_request.Command {
const args: GlideString[] = [key, groupName, id];
Expand Down Expand Up @@ -4093,7 +4093,7 @@ export function createGetEx(
export function createXAck(
key: GlideString,
group: GlideString,
ids: GlideString[],
ids: string[],
): command_request.Command {
return createCommand(RequestType.XAck, [key, group, ...ids]);
}
Expand All @@ -4104,7 +4104,7 @@ export function createXAck(
export function createXGroupSetid(
key: GlideString,
groupName: GlideString,
id: GlideString,
id: string,
entriesRead?: number,
): command_request.Command {
const args = [key, groupName, id];
Expand Down
5 changes: 3 additions & 2 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,10 @@ export class GlideClient extends BaseClient {
*
* @param source - The key to the source value.
* @param destination - The key where the value should be copied to.
* @param destinationDB - (Optional) The alternative logical database index for the destination key.
* @param options - (Optional) Additional parameters:
* - (Optional) `destinationDB`: the alternative logical database index for the destination key.
* If not provided, the current database will be used.
* @param replace - (Optional) If `true`, the `destination` key should be removed before copying the
* - (Optional) `replace`: if `true`, the `destination` key should be removed before copying the
* value to it. If not provided, no action will be performed if the key already exists.
* @returns `true` if `source` was copied, `false` if the `source` was not copied.
*
Expand Down
9 changes: 5 additions & 4 deletions node/src/GlideClusterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,23 +805,24 @@ export class GlideClusterClient extends BaseClient {
*
* @param source - The key to the source value.
* @param destination - The key where the value should be copied to.
* @param replace - (Optional) If `true`, the `destination` key should be removed before copying the
* @param options - (Optional) Additional parameters:
* - (Optional) `replace`: if `true`, the `destination` key should be removed before copying the
* value to it. If not provided, no action will be performed if the key already exists.
* @returns `true` if `source` was copied, `false` if the `source` was not copied.
*
* @example
* ```typescript
* const result = await client.copy("set1", "set2", true);
* const result = await client.copy("set1", "set2", { replace: true });
* console.log(result); // Output: true - "set1" was copied to "set2".
* ```
*/
public async copy(
source: GlideString,
destination: GlideString,
replace?: boolean,
options?: { replace?: boolean },
): Promise<boolean> {
return this.createWritePromise(
createCopy(source, destination, { replace: replace }),
createCopy(source, destination, options),
);
}

Expand Down
Loading

0 comments on commit d4803a4

Please sign in to comment.