All files / src/resp/protocol redis-token.ts

93.75% Statements 15/16
0% Branches 0/2
87.5% Functions 7/8
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 531x 1x 1x   1x 1x           1x   8x       15x       3x       56x                   28x       17x       18x     1x   1x        
import {ArrayRedisToken} from "./array-redis-token";
import {ErrorRedisToken} from "./error-redis-token";
import {NumberRedisToken} from "./number-redis-token";
import {RedisTokenType} from "./redis-token-type";
import {StatusRedisToken} from "./status-redis-token";
import {StringRedisToken} from "./string-redis-token";
 
/**
 * An abstract wrapper for RESP Protocol messages.
 * See {@link RedisTokenType}
 */
export abstract class RedisToken {
    public static nullString(): RedisToken {
        return RedisToken.NULL_STRING;
    }
 
    public static responseOk(): RedisToken {
        return RedisToken.RESPONSE_OK;
    }
 
    public static status(str: string): RedisToken {
        return new StatusRedisToken(str);
    }
 
    public static string(str: string): RedisToken {
        return new StringRedisToken(str);
    }
 
    public static boolean(tf: boolean): RedisToken {
        return new NumberRedisToken(tf
            ? 1
            : 0);
    }
 
    public static integer(i: number): RedisToken {
        return new NumberRedisToken(i);
    }
 
    public static array(redisTokens: any[]): RedisToken {
        return new ArrayRedisToken(redisTokens);
    }
 
    public static error(str: string): RedisToken {
        return new ErrorRedisToken(str);
    }
 
  private static NULL_STRING: RedisToken = RedisToken.string("");
 
  private static RESPONSE_OK: RedisToken = RedisToken.status("OK");
 
  public abstract getType(): RedisTokenType;
}