The schema to make optional
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)
);
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.