Sanity Library Reference Docs
    Preparing search index...

    Type Alias StegaBranded<T, Key, ParentKey>Beta

    StegaBranded: 0 extends 1 & T
        ? T
        : T extends string
            ? T extends { " stegaBrand": string }
                ? T
                : Key extends `_${string}`
                | "slug"
                | symbol
                    ? T
                    : Key extends "current"
                        ? ParentKey extends "slug" ? T : StegaString<T>
                        : StegaString<T>
            : T extends number
            | bigint
            | boolean
            | null
            | undefined
                ? T
                : T extends Date
                | RegExp
                | ((...args: never[]) => unknown)
                    ? T
                    : T extends readonly unknown[]
                        ? { [Index in keyof T]: StegaBranded<T[Index], number, number> }
                        : T extends { _type: "block" }
                            ? {
                                [K in keyof T]: K extends "children"
                                    ? StegaBranded<T[K], K, Key>
                                    : T[K]
                            }
                            : T extends { _type: "span" }
                                ? {
                                    [K in keyof T]: K extends "text"
                                        ? StegaBranded<(...)[(...)], K, Key>
                                        : T[K]
                                }
                                : T extends object
                                    ? { [K in keyof T]: StegaBranded<(...)[(...)], K, Key> }
                                    : T

    Deeply brands the string properties of a query result as StegaString, marking them as potentially containing stega-encoded data.

    String properties that the stega encoder is guaranteed to never encode keep their plain type:

    • keys starting with _ (_id, _type, _createdAt, _updatedAt, _key, _ref, _rev and so on), which also preserves discriminated union narrowing on _type
    • slug.current patterns: a current key directly under a slug key, as well as string valued slug keys (covering "slug": slug.current projections)
    • Portable Text internals: the encoder only visits children of _type: 'block' objects and text of _type: 'span' objects, so properties like style, listItem and marks stay plain
    • symbol-keyed properties (like TypeGen's internalGroqTypeReferenceTo reference marker): JSON can't contain symbol keys, so they only exist in the type system and are never encoded

    Every other string is assumed to be "poisoned", even if the runtime filter happens to skip it (URLs, dates, keys ending in Id, denylisted keys). Being conservative is safe: the worst case is a redundant stegaClean() call, whereas under-branding would hide real bugs.

    The Key and ParentKey type parameters track the key the current value is found under, and the key of the object containing it, they're only used internally during recursion.

    Type Parameters

    • T
    • Key extends PropertyKey = number
    • ParentKey extends PropertyKey = number