diff --git a/README.md b/README.md index 6a51293a..0630a807 100644 --- a/README.md +++ b/README.md @@ -98,13 +98,13 @@ executor. You can send raw redis commands and receive replies. ```ts { const reply = await redis.executor.exec("SET", "redis", "nice"); - assert(reply.type === SIMPLE_STRING_TYPE); + assert(reply.type === replyTypes.SimpleString); assert(reply.value() === "OK"); } { const reply = await redis.executor.exec("GET", "redis"); - assert(reply.type === BULK_STRING_TYPE); + assert(reply.type === replyTypes.BulkString); assert(reply.value() === "nice"); } ``` diff --git a/mod.ts b/mod.ts index 030fbc0a..4b756f00 100644 --- a/mod.ts +++ b/mod.ts @@ -1,10 +1,5 @@ // Generated by tools/make_mod.ts. Don't edit. -export { - ARRAY_TYPE, - BULK_STRING_TYPE, - INTEGER_TYPE, - SIMPLE_STRING_TYPE, -} from "./protocol/mod.ts"; +export { replyTypes } from "./protocol/mod.ts"; export { connect, parseURL } from "./redis.ts"; export { ConnectionClosedError, diff --git a/protocol/mod.ts b/protocol/mod.ts index 537dd20c..6f6ce365 100644 --- a/protocol/mod.ts +++ b/protocol/mod.ts @@ -17,13 +17,10 @@ export type { } from "./types.ts"; export { - ARRAY_TYPE, - BULK_STRING_TYPE, createSimpleStringReply, - INTEGER_TYPE, readArrayReply, readReply, - SIMPLE_STRING_TYPE, + replyTypes, unwrapReply, } from "./reply.ts"; diff --git a/protocol/reply.ts b/protocol/reply.ts index d8c00e35..70f614d9 100644 --- a/protocol/reply.ts +++ b/protocol/reply.ts @@ -9,10 +9,12 @@ const SimpleStringCode = "+".charCodeAt(0); const ArrayReplyCode = "*".charCodeAt(0); const ErrorReplyCode = "-".charCodeAt(0); -export const INTEGER_TYPE = "integer"; -export const SIMPLE_STRING_TYPE = "simple string"; -export const ARRAY_TYPE = "array"; -export const BULK_STRING_TYPE = "bulk string"; +export const replyTypes = { + Integer: "integer", + SimpleString: "simple string", + Array: "array", + BulkString: "bulk string", +} as const; export function unwrapReply( reply: types.RedisReplyOrError, @@ -72,7 +74,7 @@ class IntegerReply implements types.IntegerReply { } get type(): "integer" { - return INTEGER_TYPE; + return replyTypes.Integer; } value(): types.Integer { @@ -108,7 +110,7 @@ class BulkReply implements types.BulkReply { } get type(): "bulk string" { - return BULK_STRING_TYPE; + return replyTypes.BulkString; } value(): types.Bulk { @@ -138,7 +140,7 @@ class SimpleStringReply implements types.SimpleStringReply { } get type(): "simple string" { - return SIMPLE_STRING_TYPE; + return replyTypes.SimpleString; } value(): types.SimpleString { @@ -189,7 +191,7 @@ class ArrayReply implements types.ArrayReply { } get type(): "array" { - return ARRAY_TYPE; + return replyTypes.Array; } value() { diff --git a/tests/executor_test.ts b/tests/executor_test.ts index 2a7a9475..29524450 100644 --- a/tests/executor_test.ts +++ b/tests/executor_test.ts @@ -1,4 +1,4 @@ -import { BulkReply, ErrorReplyError, parseURL } from "../mod.ts"; +import { BulkReply, ErrorReplyError, parseURL, replyTypes } from "../mod.ts"; import { assert, assertEquals, @@ -20,21 +20,21 @@ suite.test("simple, string, and integer replies", async () => { // simple string { const reply = await client.executor.exec("SET", "key", "a"); - assertEquals(reply.type, "simple string"); + assertEquals(reply.type, replyTypes.SimpleString); assertEquals(reply.value(), "OK"); } // bulk string { const reply = await client.executor.exec("GET", "key"); - assertEquals(reply.type, "bulk string"); + assertEquals(reply.type, replyTypes.BulkString); assertEquals(reply.value(), "a"); } // integer { const reply = await client.executor.exec("EXISTS", "key"); - assertEquals(reply.type, "integer"); + assertEquals(reply.type, replyTypes.Integer); assertEquals(reply.value(), 1); } }); @@ -43,7 +43,7 @@ suite.test("get the raw data as Uint8Array", async () => { const encoder = new TextEncoder(); await client.set("key", encoder.encode("hello")); const reply = await client.executor.exec("GET", "key"); - assertEquals(reply.type, "bulk string"); + assertEquals(reply.type, replyTypes.BulkString); assertEquals((reply as BulkReply).buffer(), encoder.encode("hello")); });