Grounds
    Preparing search index...

    Function RMap

    • Creates a schema for homogeneous maps with key type K and value type V.

      All keys and values must match their respective types. The wire format encodes key type (1 byte), value type (1 byte), then key-value pairs in sequence with a length prefix. Keys must be unique.

      Type Parameters

      • K extends TSchema
      • V extends TSchema

      Parameters

      • keySchema: K

        Schema defining the type of all keys

      • valueSchema: V

        Schema defining the type of all values

      Returns TRMap<K, V>

      A Relish schema for maps with keys of type K and values of type V

      import { RMap, RString, RU32, createCodec, type Static } from '@grounds/schema';

      const schema = RMap(RString(), RU32());
      type StringToNumber = Static<typeof schema>;
      const codec = createCodec(schema);

      codec.encode(new Map([['count', 42]])).match(
      (bytes) => console.log('Map encoded:', bytes),
      (error) => console.error(error)
      );

      TypeBox doesn't have native Map support, so Relish uses custom schema handling. Keys and value schemas are attached via symbol properties for codec use.

      • RArray for homogeneous collections without keys
      • RStruct for heterogeneous collections with string field names