import * as core from "../pkg/redis.js";
import { HttpClient } from "../pkg/http.js";
import { VERSION } from "../version.js";
/**
 * Serverless redis client for upstash.
 */
export class Redis extends core.Redis {
    /**
     * Create a new redis client
     *
     * @example
     * ```typescript
     *    const redis = new Redis({
     *        url: "<UPSTASH_REDIS_REST_URL>",
     *        token: "<UPSTASH_REDIS_REST_TOKEN>",
     *        backend: "upstash-db",
     *    });
     * ```
     */
    constructor(config) {
        if (config.url.startsWith(" ") ||
            config.url.endsWith(" ") ||
            /\r|\n/.test(config.url)) {
            console.warn("The redis url contains whitespace or newline, which can cause errors!");
        }
        if (config.token.startsWith(" ") ||
            config.token.endsWith(" ") ||
            /\r|\n/.test(config.token)) {
            console.warn("The redis token contains whitespace or newline, which can cause errors!");
        }
        const client = new HttpClient({
            baseUrl: config.url,
            retry: config.retry,
            headers: { authorization: `Bearer ${config.token}` },
            options: { backend: config.backend },
            responseEncoding: config.responseEncoding,
        });
        super(client, {
            automaticDeserialization: config.automaticDeserialization,
        });
        this.addTelemetry({
            sdk: `@upstash/redis@${VERSION}`,
            platform: "fastly",
        });
    }
}
