Grounds
    Preparing search index...

    Function fromRelish

    • Converts Relish binary bytes to a JavaScript value using a schema.

      Decodes bytes from Relish wire format and converts to the schema's JavaScript type in a single operation.

      Type Parameters

      • T

      Parameters

      • bytes: Uint8Array

        Binary data in Relish wire format

      • schema: TRelishSchema

        Relish schema defining the expected structure

      Returns Result<T, DecodeError>

      Result containing decoded value, or DecodeError on failure

      import { fromRelish, RArray, RU32 } from '@grounds/schema';

      const schema = RArray(RU32());
      const bytes = new Uint8Array([...]); // from network or storage

      fromRelish<Array<number>>(bytes, schema).match(
      (value) => {
      // value: Array<number> ready to use
      console.log('Decoded array:', value);
      },
      (error) => {
      if (error.code === 'UNEXPECTED_EOF') {
      console.error('Incomplete data');
      }
      }
      );

      This function provides true API symmetry with toRelish per ADR 0001:

      • toRelish: JS value → bytes
      • fromRelish: bytes → JS value

      The symmetry simplifies reasoning about the API and enables clean composition with streaming operations in @grounds/stream.

      Internally decodes to raw JavaScript values (not wrapped RelishValue), then validates against the schema to ensure type safety.

      • toRelish for the inverse operation (value → bytes)
      • createCodec for a wrapped API with type inference