Skip to content

expandFilterNode

function expandFilterNode(input): object;

Defined in: filters/url.ts:603

Decode a compact tree back to a FilterNode, restoring kind from kinds (a field → kind allow-list, e.g. from _metadata). Returns null if nothing allow-listed survives.

keepEmptyGroups (default false) controls whether an and/or container that decodes to zero children survives. The default prunes empty groups (defensive — a stale/hand-edited URL collapses to a valid subset). Set it true when the URL is the source of truth for a tree being edited in an interactive filter-builder, so a just-added still-empty group (the “Add group” → empty box pattern) survives the encode→URL→decode round-trip instead of vanishing before you can fill it. Invalid LEAVES (non-allow-listed field, unknown operator, bad value) are still dropped in both modes, and not is resolved the same way — only the empty-container collapse changes. A vs list with even one wrong-typed element counts as a bad value, so { o: "iA", vs: ["1", 2] } on a number field drops the whole leaf.

Parameter Type
input { compact: unknown; keepEmptyGroups?: boolean; kinds: FieldKindSpec; }
input.compact unknown
input.keepEmptyGroups? boolean
input.kinds FieldKindSpec

object

Name Type Defined in
node FilterNode | null filters/url.ts:608
import { expandFilterNode } from "@xtandard/lib/filters";
const kinds = { title: "text", status: "enum", priority: "number" } as const;
expandFilterNode({
compact: { or: [{ f: "secret", o: "eq", v: "x" }, { f: "priority", o: "ge", v: 2 }] },
kinds,
});
// → { node: { type: "or", nodes: [
// { type: "column", field: "priority", filter: { kind: "number", operator: "gte", value: 2 } },
// ] } } ("secret" isn't in `kinds`, so it is dropped)
expandFilterNode({ compact: { and: [] }, kinds }); // → { node: null }
expandFilterNode({ compact: { and: [] }, kinds, keepEmptyGroups: true });
// → { node: { type: "and", nodes: [] } }