Grounds
    Preparing search index...

    Function ROptional

    • Creates a schema for optional values (value or null).

      Wraps any schema to allow null in addition to the normal type. The codec uses the wrapped schema's type code and handles null encoding/decoding.

      Type Parameters

      • T extends TSchema

      Parameters

      • schema: T

        The schema to make optional

      Returns TROptional<T>

      A Relish schema accepting T or null

      import { ROptional, RString, createCodec } from '@grounds/schema';

      const schema = ROptional(RString());
      const codec = createCodec(schema);

      codec.encode('hello').match(
      (bytes) => console.log('Encoded string:', bytes),
      (error) => console.error(error)
      );

      codec.encode(null).match(
      (bytes) => console.log('Encoded null:', bytes),
      (error) => console.error(error)
      );

      Preserves the wrapped schema's type code for efficient encoding.

      • RNull for null-only values
      • field for optional struct fields