dyna-record
    Preparing search index...

    Type Alias ExtractEntityFromSK<T, SK>

    ExtractEntityFromSK: SK extends { $beginsWith: infer V extends string }
        ? EntityNamesStartingWith<T, V>
        : SK extends PartitionEntityNames<T> ? SK : never

    Extracts entity names from a typed sort key condition for return type narrowing.

    Narrows when:

    • SK is an exact entity name: "Order" → "Order"
    • SK is { $beginsWith: "Order" } → "Order"
    • SK is { $beginsWith: "Inv" } → "Invoice" | "Inventory" (prefix matches multiple)
    • SK is { $beginsWith: "PaymentMethod" } → "PaymentMethod" | "PaymentMethodProvider" (when one entity name is a prefix of another)

    Does not narrow when:

    • SK is a prefixed string like "Order#123" (can't parse the delimiter at type level)
    • SK is { $beginsWith: "Order#" } (a prefix past the entity name's boundary)
    • SK is a comparison or a $between range

    The table's delimiter is configurable and is not visible to the types, so they cannot tell where an entity name ends inside a longer value. Narrowing on a name or a prefix of one assumes that no entity's sort key starts with another entity's name followed by the delimiter. That always holds with the default # delimiter, and with any delimiter whose first character cannot appear in a class name.

    Type Parameters

    • T extends default

      The entity type being queried.

    • SK

      The inferred sort key condition literal type.

    type One = ExtractEntityFromSK<Customer, "Order">; // "Order"
    type Prefix = ExtractEntityFromSK<Customer, { $beginsWith: "C" }>; // "Customer" | "ContactInformation"
    type None = ExtractEntityFromSK<Customer, { $beginsWith: "Order#" }>; // never: no narrowing