Skip to content

@studnicky/drilldown

Deterministic multi-level grouping, faceting, and sorting for arbitrary record data, with automatic property discovery and explicit rule-driven grouping.

Install

bash
pnpm add @studnicky/drilldown

Requires @studnicky:registry=https://npm.pkg.github.com in .npmrc.

Overview

DrillDown.group builds a hierarchical grouping tree from an array of records, either from explicit GroupRuleInterface rules (alphabetic, range, date, semver, CIDR, sequential, or string matchers) or from DataAnalyzer-recommended properties. FacetedDiscovery narrows a record set by concurrently-selectable facet dimensions. DrilldownRulesEntity and DrillDownConfigEntity are self-referential, schema-validated rule trees that can nest per-value grouping rules to unbounded depth.

Usage

propertyPriority fixes the drilldown order explicitly — each entry adds one level to the tree:

ts
import { OrdersFixture } from './fixtures/OrdersFixture.js';

class DrilldownDemo {
  static run(): { 'categoryGroupCount': number; 'regionGroupCount': number; 'statusGroupCount': number } {
    const drillDown = new DrillDown();

    // Three levels deep: region -> category -> status
    const tree = drillDown.group(OrdersFixture.orders, {
      'minimumGroupSize': 1,
      'propertyPriority': ['region', 'category', 'status']
    });

    console.log(`Root splits into ${tree.grouped?.length ?? 0} region groups`);

    const firstRegion = tree.grouped?.[0];
    console.log(`First region "${firstRegion?.value}" splits into ${firstRegion?.grouped?.length ?? 0} category groups`);

    const firstCategory = firstRegion?.grouped?.[0];
    console.log(`First category "${firstCategory?.value}" splits into ${firstCategory?.grouped?.length ?? 0} status groups`);

    return {
      'categoryGroupCount': firstRegion?.grouped?.length ?? 0,
      'regionGroupCount': tree.grouped?.length ?? 0,
      'statusGroupCount': firstCategory?.grouped?.length ?? 0
    };
  }
}

const results = DrilldownDemo.run();

Try it

Loading example…

Live demo

A synthetic dataset of orders, generated fresh each time with @faker-js/faker, drilled down four levels deep (region → category → status → brand) to demonstrate the module's core promise: recursion bounded only by how many properties are discoverable in the data, not by a fixed depth. Click a node to expand or collapse its children.

320 synthetic orders, drilled down by region → category → status → brand
  • All records320 records
    • region:North America93 records
    • region:Asia Pacific79 records
    • region:Europe74 records
    • region:Latin America74 records

Exports

SymbolPurposeImport path
DrillDownBuilds a hierarchical grouping tree from records, via explicit rules or auto-discovered properties.@studnicky/drilldown
DataAnalyzerDiscovers groupable properties across a dataset and recommends a grouping order.@studnicky/drilldown
FacetedDiscoveryNarrows a record set by concurrently-selectable, mutually-consistent facet dimensions.@studnicky/drilldown
ruleValidatorValidates a DrilldownRulesEntity.Type tree, reporting structural errors by path.@studnicky/drilldown
DrillDownConfigEntityTop-level schema-derived entity binding filter, group, and sort rules for one DrillDown.group call.@studnicky/drilldown
DrilldownRulesEntitySelf-referential, schema-validated rule tree (filter/group/sort), nestable per group value to unbounded depth.@studnicky/drilldown
AlphabeticRangeEntitySchema-derived alphabetic (lexicographic) range for string grouping.@studnicky/drilldown
AutoGroupingConfigEntityConfiguration for automatic rule generation from discovered property values.@studnicky/drilldown
CidrRangeEntitySchema-derived IPv4 CIDR block range for IP address grouping.@studnicky/drilldown
DateGranularityValueEntitySchema-derived temporal granularity value (day/week/month/quarter/year).@studnicky/drilldown
DateRangeEntitySchema-derived inclusive-after/exclusive-before epoch-ms date range.@studnicky/drilldown
DateRangeFilterRuleEntitySchema-derived filter rule matching a property against a date range.@studnicky/drilldown
DiscoverValuesOptionsEntityOptions controlling automatic value discovery during grouping.@studnicky/drilldown
DiscoveryStrategyEntitySchema-derived enum of value-discovery strategies (alphabetic/distributive/quantile/sequential).@studnicky/drilldown
FilterOperatorEntitySchema-derived enum of comparison operators for value filter rules.@studnicky/drilldown
FilterRuleEntitySchema-derived union of date-range, numeric-range, and value filter rules.@studnicky/drilldown
GranularityOptionsEntityOptions controlling automatic date-granularity selection.@studnicky/drilldown
GroupingOptionsEntityOptions controlling automatic property discovery and grouping, including property exclusions.@studnicky/drilldown
GroupNodeValueEntitySchema-derived value carried by a grouping tree node (the value the node's records share).@studnicky/drilldown
GroupSortPropertyEntitySchema-derived enum of properties a group level can be sorted by.@studnicky/drilldown
GroupValueDiscriminantEntitySchema-derived discriminant identifying which matcher/group-value variant a value is.@studnicky/drilldown
JsonPropertyTypeEntitySchema-derived runtime data-type classification for a discovered property's values.@studnicky/drilldown
NumericRangeFilterRuleEntitySchema-derived filter rule matching a property against a numeric range.@studnicky/drilldown
OutlierMarkerEntitySchema-derived marker identifying an outlier group produced during grouping.@studnicky/drilldown
PathSegmentEntitySchema-derived single segment (property + value) in a path from the tree root to a node.@studnicky/drilldown
ProcessOptionsEntityOptions controlling a single DrillDown.group invocation end to end.@studnicky/drilldown
PropertyBoundsEntitySchema-derived minimum/maximum bounds computed for a numeric or date property.@studnicky/drilldown
PropertyOrderEntitySchema-derived ordered list of property paths for progressive multi-level grouping.@studnicky/drilldown
PropertyPathEntitySchema-derived dot-delimited path identifying a discoverable property on a record.@studnicky/drilldown
RangeEntitySchema-derived inclusive-minimum/exclusive-maximum numeric range.@studnicky/drilldown
RangeIndicesEntitySchema-derived start/end indices identifying a numeric group's position.@studnicky/drilldown
SemverRangeEntitySchema-derived semantic-version range expressed as a caret/tilde/comparator string.@studnicky/drilldown
SequentialRangeEntitySchema-derived prefix/suffix/padding window for sequentially-numbered string values.@studnicky/drilldown
SortDirectionEntitySchema-derived enum of sort directions (asc/desc).@studnicky/drilldown
SortRuleEntitySchema-derived rule sorting group values by a named property and direction.@studnicky/drilldown
ValueFilterRuleEntitySchema-derived filter rule matching a property against an explicit value list.@studnicky/drilldown
DateGranularityTemporal granularity levels for grouping date values.@studnicky/drilldown
GroupingStrategyStrategies for partitioning numeric data into groups (distributive/quantile).@studnicky/drilldown
PropertyTypeEnumeration of value-shape classifications used by automatic value discovery.@studnicky/drilldown
DataAnalyzerInterfaceContract for discovering groupable properties and recommending a grouping order.@studnicky/drilldown
DrillDownInterfaceContract for building a grouping tree from records and rules.@studnicky/drilldown
MatcherHandlerInterfaceContract implemented by each matcher type: create, validate, compare, and match group values.@studnicky/drilldown
AlphabeticGroupValueInterfaceAlphabetic-range group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
CidrGroupValueInterfaceCIDR-range group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
DateGroupValueInterfaceDate-range group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
GroupRuleInterfaceExplicit grouping rule: a property and its ordered list of group value variants.@studnicky/drilldown
RangeGroupValueInterfaceNumeric-range group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
SemverGroupValueInterfaceSemver-range group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
SequentialGroupValueInterfaceSequential-pattern group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
StringGroupValueInterfaceExact-match string group value, with an optional nested rules tree for per-value grouping.@studnicky/drilldown
AlphabeticMatcherInterfaceMatcher for alphabetic range membership.@studnicky/drilldown
AnalysisResultInterfaceComplete analysis output for a dataset: discovered properties and a recommended grouping order.@studnicky/drilldown
CidrMatcherInterfaceMatcher for IP address CIDR block membership.@studnicky/drilldown
DataRecordInterfaceArbitrary record shape DrillDown/DataAnalyzer operate on.@studnicky/drilldown
DateMatcherInterfaceMatcher for date/time range membership.@studnicky/drilldown
DrillDownAnalysisInterfaceAnalysis the DrillDown engine uses to choose an automatic grouping order.@studnicky/drilldown
GroupNodeInterfaceTree node in the hierarchical grouping structure.@studnicky/drilldown
MatchContextInterfaceContext providing type-conversion utilities for matching operations.@studnicky/drilldown
NodePathIndexInterfaceBidirectional index for efficient node lookup in the grouping tree.@studnicky/drilldown
PartitionGroupInterfaceOne partitioned group of matched nodes and their shared group value.@studnicky/drilldown
PropertyInfoInterfaceStatistical profile of a single property across all records.@studnicky/drilldown
RangeMatcherInterfaceMatcher for numeric range membership.@studnicky/drilldown
SemverMatcherInterfaceMatcher for semantic version constraint satisfaction.@studnicky/drilldown
SequentialMatcherInterfaceMatcher for sequential string patterns.@studnicky/drilldown
StringMatcherInterfaceMatcher for exact string equality.@studnicky/drilldown
FacetAccessorMapTypeAccessor map reading one filterable string value per facet dimension from an arbitrary row shape.@studnicky/drilldown
FacetFilterStateTypeCurrent faceted-drilldown selection per dimension.@studnicky/drilldown
GroupValueUnionTypeUnion of all group-value shapes usable in a GroupRuleInterface.@studnicky/drilldown
MatcherUnionTypeUnion of all matcher shapes produced by matcherRegistry.@studnicky/drilldown