MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / compactEventProperties

Function compactEventProperties

apps/api/src/agents/tools/helpers.ts:125–156  ·  view source on GitHub ↗
(
  raw: {
    columns: readonly string[];
    properties: Array<{ property_key: string; event_name: string }>;
  },
  options: { eventName?: string; max?: number } = {},
)

Source from the content-addressed store, hash-verified

123 * "how prominent is this property" signal), and caps the list.
124 */
125export function compactEventProperties(
126 raw: {
127 columns: readonly string[];
128 properties: Array<{ property_key: string; event_name: string }>;
129 },
130 options: { eventName?: string; max?: number } = {},
131): {
132 event_name?: string;
133 columns: readonly string[];
134 properties: string[];
135 total: number;
136 _truncated: boolean;
137} {
138 const { eventName, max = 50 } = options;
139 const counts = new Map<string, number>();
140 for (const row of raw.properties) {
141 const dot = row.property_key.indexOf('.');
142 const root = dot >= 0 ? row.property_key.slice(0, dot) : row.property_key;
143 counts.set(root, (counts.get(root) ?? 0) + 1);
144 }
145 const sorted = Array.from(counts.entries())
146 .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
147 .map(([key]) => key);
148 const truncated = sorted.length > max;
149 return {
150 ...(eventName ? { event_name: eventName } : {}),
151 columns: raw.columns,
152 properties: truncated ? sorted.slice(0, max) : sorted,
153 total: sorted.length,
154 _truncated: truncated,
155 };
156}
157
158/**
159 * Known range presets that map to date windows via `getDatesFromRange`.

Callers 2

base.tsFile · 0.90
events.tsFile · 0.90

Calls 4

setMethod · 0.45
getMethod · 0.45
mapMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected