@nats-io/kv
    Preparing search index...

    Type Alias KvKeyCodec

    A key codec is used to encode and decode keys before they are stored or returned to the client in a Key-Value store.

    The codec transforms each token (part between dots) in a key string, allowing for custom encoding/decoding while preserving the hierarchical structure of NATS subjects.

    • Enables custom encoding of keys (e.g., base64, encryption, or custom mappings)
    • Preserves the ability to use NATS subject wildcards for filtering
    • Ensures proper storage and retrieval of keys with special characters
    1. Must preserve the dot-delimited structure of NATS subjects
    2. Must handle wildcard tokens (* and >) without modification
    3. Must be able to properly encode/decode each token independently
    4. Must be deterministic (same input always produces same output)
    // Original key: "users.john.profile"
    // Encoded key: "dXNlcnM=.am9obg==.cHJvZmlsZQ=="

    // With wildcards (these remain unchanged):
    // Original key: "users.*.profile"
    // Encoded key: "dXNlcnM=.*.cHJvZmlsZQ=="

    Note: This codec is specifically for subject-compatible transformations of keys, not for general data transformation or serialization. It operates at the token level to preserve NATS subject semantics, ensuring that filtering, watches, and other subject-based operations continue to work properly.

    type KvKeyCodec = {
        decode(k: string): string;
        encode(k: string): string;
    }
    Index

    Methods

    Methods

    • Decodes a key or key token after retrieval

      Parameters

      • k: string

      Returns string

    • Encodes a key or key token before storage

      Parameters

      • k: string

      Returns string