import type { ActionTrackEntryPayload, DevToolsColor, DevToolsProperties, EntryMeta, MarkOptionsWithDevtools, MarkerPayload, MeasureOptionsWithDevtools, TrackEntryPayload } from './user-timing-extensibility-api.type.js'; /** * Merges DevTools properties with override priority. * @param baseProperties - Base properties array * @param overrideProperties - Override properties array * @returns Merged properties array */ export declare function mergePropertiesWithOverwrite(baseProperties: T, overrideProperties: U): (T[number] | U[number])[]; export declare function mergePropertiesWithOverwrite(baseProperties: T): T; /** * Creates a marker payload with default data type. * @param options - Marker options excluding dataType * @returns Complete marker payload * @example * const payload = markerPayload({ * color: 'primary', * tooltipText: 'User action completed', * properties: [['action', 'save'], ['duration', 150]] * }); * // { dataType: 'marker', color: 'primary', tooltipText: 'User action completed', ... } */ export declare function markerPayload(options?: Omit): { color?: DevToolsColor; tooltipText?: string; properties?: DevToolsProperties; dataType: "marker"; }; /** * Creates a track entry payload with default data type. * @param options - Track entry options excluding dataType * @returns Complete track entry payload * @example * const payload = trackEntryPayload({ * track: 'user-interactions', * trackGroup: 'frontend', * color: 'secondary', * tooltipText: 'Button click processed', * properties: [['element', 'save-button'], ['response-time', 200]] * }); * // { dataType: 'track-entry', track: 'user-interactions', ... } */ export declare function trackEntryPayload(options: Omit): { color?: DevToolsColor | undefined; tooltipText?: string | undefined; properties?: DevToolsProperties | undefined; trackGroup?: string | undefined; dataType: "track-entry"; track: string; }; /** * Creates an error marker payload with red color. * @param options - Marker options excluding dataType and color * @returns Error marker payload */ export declare function markerErrorPayload(options?: Omit): { tooltipText?: string; properties?: DevToolsProperties; dataType: "marker"; color: T; }; /** * Creates an error track entry payload with red color. * @param options - Track entry options excluding color and dataType * @returns Error track entry payload */ export declare function trackEntryErrorPayload(options: Omit & { track: T; }): { tooltipText?: string | undefined; properties?: DevToolsProperties | undefined; trackGroup?: string | undefined; dataType: "track-entry"; color: "error"; track: T; }; /** * Converts an error to DevTools properties array. * @param e - Error object or value * @returns Array of error properties for DevTools */ export declare function errorToDevToolsProperties(e: unknown): (["Error Type", string] | ["Error Message", string])[]; /** * Converts an error to entry metadata for DevTools. * @param e - Error object or value * @param options - Additional metadata options * @returns Entry metadata with error properties */ export declare function errorToEntryMeta(e: unknown, options?: { tooltipText?: string; properties?: DevToolsProperties; }): { tooltipText?: string | undefined; properties: ([key: string, value: string | number | boolean | object | undefined] | ["Error Type", string] | ["Error Message", string])[]; }; /** * Converts an error to a track entry payload with error styling. * @param error - Error object or value * @param detail - Track entry details excluding color and dataType * @returns Error track entry payload */ export declare function errorToTrackEntryPayload(error: unknown, detail: Omit & { track: T; }): { tooltipText?: string | undefined; properties: ([key: string, value: string | number | boolean | object | undefined] | ["Error Type", string] | ["Error Message", string])[]; track: T; trackGroup?: string | undefined; dataType: "track-entry"; color: "error"; }; /** * Converts an error to a marker payload with error styling. * @param error - Error object or value * @param detail - Marker details excluding color and dataType * @returns Error marker payload */ export declare function errorToMarkerPayload(error: unknown, detail?: Omit): { tooltipText?: string | undefined; properties: ([key: string, value: string | number | boolean | object | undefined] | ["Error Type", string] | ["Error Message", string])[]; dataType: "marker"; color: "error"; }; /** * Converts DevTools payload to performance API options format. * @param devtools - DevTools payload or null * @returns Performance API options with DevTools detail * @example * const marker = markerPayload({ color: 'primary', tooltipText: 'Start' }); * performance.mark('start', asOptions(marker)); * * const trackEntry = trackEntryPayload({ track: 'operations', color: 'tertiary' }); * performance.measure('operation', { * start: 'start', * end: 'end', * ...asOptions(trackEntry) * }); */ export declare function asOptions(devtools?: T | null): MarkOptionsWithDevtools; export declare function asOptions(devtools?: T | null): MeasureOptionsWithDevtools; /** * Generates start, end, and measure names for performance tracking. * @param base - Base name for the measurement * @returns Object with startName, endName, and measureName */ export type Names = { startName: `${N}:start`; endName: `${N}:end`; measureName: N; }; /** * Generates start, end, and measure names for performance tracking. * @param base - Base name for the measurement * @param prefix - Optional prefix for names * @returns Object with startName, endName, and measureName */ export declare function getNames(base: T): Names; export declare function getNames(base: T, prefix?: P): Names<`${P}:${T}`>; /** * Removes undefined from a type, effectively filtering out undefined values. */ type Defined = T extends undefined ? never : T; /** * Merges two objects with the specified overwrite semantics: * - If B[K] is undefined → keep A[K] * - If B[K] is defined → overwrite with Defined * - Keys only in A → keep A[K] * - Keys only in B → take Defined */ type MergeDefined = { [K in keyof A | keyof B]: K extends keyof B ? Defined extends never ? K extends keyof A ? A[K] : never : Defined : K extends keyof A ? A[K] : never; }; /** * Recursively merges an array of objects using MergeDefined semantics. * The first element is the base type, subsequent elements only overwrite with defined values. */ type MergeResult

= P extends readonly [ infer A, ...infer R ] ? MergeDefined> : object; /** * Merges multiple DevTools payloads into a single payload. * The first payload establishes the base type, subsequent payloads only overwrite with defined values. * @param parts - Array of payloads where first is complete and rest are partial * @returns Merged payload with combined properties * @example * const payload = mergeDevtoolsPayload( * trackEntryPayload({ track: 'user-interactions', color: 'secondary' }), * { color: 'primary', tooltipText: 'User action completed' }, * ); * // { track: 'user-interactions', color: 'primary', tooltipText: 'User action completed' } */ export declare function mergeDevtoolsPayload[] ]>(...parts: P): MergeResult

& { properties?: DevToolsProperties; }; export type ActionTrackConfigs = Record; /** * Sets up tracks with default values merged into each track. * This helps to avoid repetition when defining multiple tracks with common properties. * @param defaults - Default action track configuration * @param tracks - Track configurations to merge with defaults * @returns Record with merged track configurations */ export declare function setupTracks>, const D extends ActionTrackEntryPayload>(defaults: D, tracks: T): Record> & { properties?: DevToolsProperties; }>; /** * Options for customizing measurement behavior and callbacks. * Extends partial ActionTrackEntryPayload to allow overriding default track properties. */ export type MeasureOptions = Partial & { /** * Callback invoked when measurement completes successfully. * @param result - The successful result value * @returns Additional DevTools properties to merge for success state */ success?: (result: T) => EntryMeta; /** * Callback invoked when measurement fails with an error. * @param error - The error that occurred * @returns Additional DevTools properties to merge for error state */ error?: (error: unknown) => EntryMeta; }; /** * Configuration for creating a measurement context. * Defines default behavior and appearance for all measurements in this context. */ export type MeasureCtxOptions = ActionTrackEntryPayload & { /** * Optional prefix for all measurement names to avoid conflicts. * @example "api:" results in names like "api:request:start" */ prefix?: string; } & { /** * Global error handler for all measurements in this context. * Applied to all error states in addition to per-measurement error callbacks. * @param error - The error that occurred * @returns Additional DevTools metadata for error display */ error?: (error: unknown) => EntryMeta; }; /** * Creates a measurement context for tracking performance events with consistent DevTools visualization. * * This function returns a higher-order function that generates measurement controllers for individual events. * Each measurement creates start/end marks and a final measure in Chrome DevTools Performance panel. * * @param cfg - Configuration defining default track properties, optional prefix, and global error handling * @returns Function that creates measurement controllers for specific events * @example * // Basic usage with defaults * const measure = measureCtx({ * track: 'api-calls', * color: 'secondary', * trackGroup: 'backend' * }); * * const { start, success, error } = measure('fetch-user'); * start(); // Creates "fetch-user:start" mark * // ... async operation ... * success({ userCount: 42 }); // Creates "fetch-user:end" mark and "fetch-user" measure * @example * // Advanced usage with callbacks and error handling * const measure = measureCtx({ * track: 'user-actions', * color: 'primary', * error: (err) => ({ * properties: [['error-type', err.name], ['error-message', err.message]] * }) * }); * * const { start, success, error } = measure('save-form', { * success: (result) => ({ * properties: [['items-saved', result.count]], * tooltipText: `Saved ${result.count} items successfully` * }), * error: (err) => ({ * properties: [['validation-errors', err.errors?.length ?? 0]] * }) * }); * * start(); * try { * const result = await saveFormData(formData); * success(result); * } catch (err) { * error(err); // Applies both global and specific error metadata * } * @example * // onetime config of defaults * const apiMeasure = measureCtx({ * prefix: 'http:', * track: 'api', * }); * * const { start, success, error } = apiMeasure('login'); * * start(); * try { * const result = myWork(); * success(result); * return result; * } catch(err) { * error(err) * } * @returns Object with measurement control methods: * - `start()`: Marks the beginning of the measurement * - `success(result?)`: Completes successful measurement with optional result metadata * - `error(error)`: Completes failed measurement with error metadata */ export declare function measureCtx(cfg: MeasureCtxOptions): (event: string, opt?: MeasureOptions) => { start: () => import("perf_hooks").PerformanceMark; success: (r: T) => void; error: (err: unknown) => void; }; export {};