@earth-app/collegedb
    Preparing search index...

    Interface KVStorage

    Provider-agnostic key-value storage contract.

    This interface is implemented by Cloudflare KV, Redis/Valkey adapters, and any custom KV backend supported by CollegeDB.

    interface KVStorage {
        delete(key: string): Promise<void>;
        deleteMany?(keys: string[]): Promise<void>;
        get<T = unknown>(key: string, type: "json"): Promise<T | null>;
        get(key: string, type?: "text"): Promise<string | null>;
        getMany?<T = unknown>(keys: string[], type: "json"): Promise<(T | null)[]>;
        getMany?(keys: string[], type?: "text"): Promise<(string | null)[]>;
        list(
            options?: { cursor?: string; limit?: number; prefix?: string },
        ): Promise<KVListResult>;
        put(key: string, value: string): Promise<void>;
        putMany?(entries: { key: string; value: string }[]): Promise<void>;
    }

    Implemented by

    Index
    • Deletes a key.

      Parameters

      • key: string

      Returns Promise<void>

    • Deletes several keys in one round trip.

      Optional, with the same fallback contract as KVStorage.getMany.

      Parameters

      • keys: string[]

      Returns Promise<void>

      1.4.0

    • Retrieves a value by key. When type is json, the value should be parsed.

      Type Parameters

      • T = unknown

      Parameters

      • key: string
      • type: "json"

      Returns Promise<T | null>

    • Parameters

      • key: string
      • Optionaltype: "text"

      Returns Promise<string | null>

    • Reads several keys in one round trip, returning results positionally.

      Optional. Backends with a native multi-get (Redis/Valkey MGET) implement it; CollegeDB falls back to concurrent single reads when it is absent, so callers never need to check for it.

      Type Parameters

      • T = unknown

      Parameters

      • keys: string[]
      • type: "json"

      Returns Promise<(T | null)[]>

      1.4.0

    • Parameters

      • keys: string[]
      • Optionaltype: "text"

      Returns Promise<(string | null)[]>

    • Lists keys, optionally filtered by prefix.

      Parameters

      • Optionaloptions: { cursor?: string; limit?: number; prefix?: string }

      Returns Promise<KVListResult>

    • Stores a value by key.

      Parameters

      • key: string
      • value: string

      Returns Promise<void>

    • Writes several key/value pairs in one round trip.

      Optional, with the same fallback contract as KVStorage.getMany. A multi-key shard mapping otherwise costs one round trip per lookup key.

      Parameters

      • entries: { key: string; value: string }[]

      Returns Promise<void>

      1.4.0