Skip to content

Commit e27e12d

Browse files
authored
fix: Introduce replyTypes namespace (#215)
1 parent a9518b1 commit e27e12d

5 files changed

Lines changed: 19 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ executor. You can send raw redis commands and receive replies.
9898
```ts
9999
{
100100
const reply = await redis.executor.exec("SET", "redis", "nice");
101-
assert(reply.type === SIMPLE_STRING_TYPE);
101+
assert(reply.type === replyTypes.SimpleString);
102102
assert(reply.value() === "OK");
103103
}
104104

105105
{
106106
const reply = await redis.executor.exec("GET", "redis");
107-
assert(reply.type === BULK_STRING_TYPE);
107+
assert(reply.type === replyTypes.BulkString);
108108
assert(reply.value() === "nice");
109109
}
110110
```

mod.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
// Generated by tools/make_mod.ts. Don't edit.
2-
export {
3-
ARRAY_TYPE,
4-
BULK_STRING_TYPE,
5-
INTEGER_TYPE,
6-
SIMPLE_STRING_TYPE,
7-
} from "./protocol/mod.ts";
2+
export { replyTypes } from "./protocol/mod.ts";
83
export { connect, parseURL } from "./redis.ts";
94
export {
105
ConnectionClosedError,

protocol/mod.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ export type {
1717
} from "./types.ts";
1818

1919
export {
20-
ARRAY_TYPE,
21-
BULK_STRING_TYPE,
2220
createSimpleStringReply,
23-
INTEGER_TYPE,
2421
readArrayReply,
2522
readReply,
26-
SIMPLE_STRING_TYPE,
23+
replyTypes,
2724
unwrapReply,
2825
} from "./reply.ts";
2926

protocol/reply.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ const SimpleStringCode = "+".charCodeAt(0);
99
const ArrayReplyCode = "*".charCodeAt(0);
1010
const ErrorReplyCode = "-".charCodeAt(0);
1111

12-
export const INTEGER_TYPE = "integer";
13-
export const SIMPLE_STRING_TYPE = "simple string";
14-
export const ARRAY_TYPE = "array";
15-
export const BULK_STRING_TYPE = "bulk string";
12+
export const replyTypes = {
13+
Integer: "integer",
14+
SimpleString: "simple string",
15+
Array: "array",
16+
BulkString: "bulk string",
17+
} as const;
1618

1719
export function unwrapReply(
1820
reply: types.RedisReplyOrError,
@@ -72,7 +74,7 @@ class IntegerReply implements types.IntegerReply {
7274
}
7375

7476
get type(): "integer" {
75-
return INTEGER_TYPE;
77+
return replyTypes.Integer;
7678
}
7779

7880
value(): types.Integer {
@@ -108,7 +110,7 @@ class BulkReply implements types.BulkReply {
108110
}
109111

110112
get type(): "bulk string" {
111-
return BULK_STRING_TYPE;
113+
return replyTypes.BulkString;
112114
}
113115

114116
value(): types.Bulk {
@@ -138,7 +140,7 @@ class SimpleStringReply implements types.SimpleStringReply {
138140
}
139141

140142
get type(): "simple string" {
141-
return SIMPLE_STRING_TYPE;
143+
return replyTypes.SimpleString;
142144
}
143145

144146
value(): types.SimpleString {
@@ -189,7 +191,7 @@ class ArrayReply implements types.ArrayReply {
189191
}
190192

191193
get type(): "array" {
192-
return ARRAY_TYPE;
194+
return replyTypes.Array;
193195
}
194196

195197
value() {

tests/executor_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BulkReply, ErrorReplyError, parseURL } from "../mod.ts";
1+
import { BulkReply, ErrorReplyError, parseURL, replyTypes } from "../mod.ts";
22
import {
33
assert,
44
assertEquals,
@@ -20,21 +20,21 @@ suite.test("simple, string, and integer replies", async () => {
2020
// simple string
2121
{
2222
const reply = await client.executor.exec("SET", "key", "a");
23-
assertEquals(reply.type, "simple string");
23+
assertEquals(reply.type, replyTypes.SimpleString);
2424
assertEquals(reply.value(), "OK");
2525
}
2626

2727
// bulk string
2828
{
2929
const reply = await client.executor.exec("GET", "key");
30-
assertEquals(reply.type, "bulk string");
30+
assertEquals(reply.type, replyTypes.BulkString);
3131
assertEquals(reply.value(), "a");
3232
}
3333

3434
// integer
3535
{
3636
const reply = await client.executor.exec("EXISTS", "key");
37-
assertEquals(reply.type, "integer");
37+
assertEquals(reply.type, replyTypes.Integer);
3838
assertEquals(reply.value(), 1);
3939
}
4040
});
@@ -43,7 +43,7 @@ suite.test("get the raw data as Uint8Array", async () => {
4343
const encoder = new TextEncoder();
4444
await client.set("key", encoder.encode("hello"));
4545
const reply = await client.executor.exec("GET", "key");
46-
assertEquals(reply.type, "bulk string");
46+
assertEquals(reply.type, replyTypes.BulkString);
4747
assertEquals((reply as BulkReply).buffer(), encoder.encode("hello"));
4848
});
4949

0 commit comments

Comments
 (0)