@code-pushup/utils 0.104.0 → 0.106.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.104.0",
3
+ "version": "0.106.0",
4
4
  "description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/code-pushup/cli/tree/main/packages/utils#readme",
@@ -24,10 +24,10 @@
24
24
  },
25
25
  "type": "module",
26
26
  "engines": {
27
- "node": ">=17.0.0"
27
+ "node": ">=18.2.0"
28
28
  },
29
29
  "dependencies": {
30
- "@code-pushup/models": "0.104.0",
30
+ "@code-pushup/models": "0.106.0",
31
31
  "ansis": "^3.3.0",
32
32
  "build-md": "^0.4.2",
33
33
  "bundle-require": "^5.1.0",
package/src/index.d.ts CHANGED
@@ -17,8 +17,8 @@ export { hasNoNullableProps, isPromiseFulfilledResult, isPromiseRejectedResult,
17
17
  export { interpolate } from './lib/interpolate.js';
18
18
  export { Logger, logger } from './lib/logger.js';
19
19
  export { mergeConfigs } from './lib/merge-configs.js';
20
- export { addIndex, ContextValidationError, createCategoryRefs, expandAuditsForUrls, expandCategoryRefs, expandGroupsForUrls, removeIndex, shouldExpandForUrls, validateUrlContext, } from './lib/plugin-url-aggregation.js';
21
- export { getUrlIdentifier, normalizeUrlInput, type PluginUrlContext, } from './lib/plugin-url-config.js';
20
+ export { addIndex, expandAuditsForUrls, expandCategoryRefs, expandGroupsForUrls, extractGroupSlugs, shouldExpandForUrls, } from './lib/plugin-url-aggregation.js';
21
+ export { getUrlIdentifier, normalizeUrlInput, pluginUrlContextSchema, type PluginUrlContext, } from './lib/plugin-url-config.js';
22
22
  export { asyncSequential, groupByStatus, settlePromise, } from './lib/promises.js';
23
23
  export { generateRandomId } from './lib/random.js';
24
24
  export { CODE_PUSHUP_DOMAIN, CODE_PUSHUP_UNICODE_LOGO, FOOTER_PREFIX, README_LINK, } from './lib/reports/constants.js';
package/src/index.js CHANGED
@@ -17,8 +17,8 @@ export { hasNoNullableProps, isPromiseFulfilledResult, isPromiseRejectedResult,
17
17
  export { interpolate } from './lib/interpolate.js';
18
18
  export { Logger, logger } from './lib/logger.js';
19
19
  export { mergeConfigs } from './lib/merge-configs.js';
20
- export { addIndex, ContextValidationError, createCategoryRefs, expandAuditsForUrls, expandCategoryRefs, expandGroupsForUrls, removeIndex, shouldExpandForUrls, validateUrlContext, } from './lib/plugin-url-aggregation.js';
21
- export { getUrlIdentifier, normalizeUrlInput, } from './lib/plugin-url-config.js';
20
+ export { addIndex, expandAuditsForUrls, expandCategoryRefs, expandGroupsForUrls, extractGroupSlugs, shouldExpandForUrls, } from './lib/plugin-url-aggregation.js';
21
+ export { getUrlIdentifier, normalizeUrlInput, pluginUrlContextSchema, } from './lib/plugin-url-config.js';
22
22
  export { asyncSequential, groupByStatus, settlePromise, } from './lib/promises.js';
23
23
  export { generateRandomId } from './lib/random.js';
24
24
  export { CODE_PUSHUP_DOMAIN, CODE_PUSHUP_UNICODE_LOGO, FOOTER_PREFIX, README_LINK, } from './lib/reports/constants.js';
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,WAAW,EACX,SAAS,GACV,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CA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MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,4BAA4B,EAC5B,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,UAAU,GAEX,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,WAAW,EACX,SAAS,GACV,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAa,MAAM,eAAe,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,cAAc,EACd,YAAY,GAIb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ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EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAMtD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,4BAA4B,EAC5B,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,UAAU,GAEX,MAAM,oBAAoB,CAAC"}
@@ -26,6 +26,11 @@ export declare function epochClock(init?: EpochClockOptions): {
26
26
  fromEpochMs: (ms: number) => Microseconds;
27
27
  fromEpochUs: (us: number) => Microseconds;
28
28
  fromPerfMs: (perfMs: Milliseconds) => Microseconds;
29
+ fromEntry: (entry: {
30
+ startTime: Milliseconds;
31
+ entryType: string;
32
+ duration: Milliseconds;
33
+ }, useEndTime?: boolean) => number;
29
34
  fromEntryStartTimeMs: (perfMs: Milliseconds) => Microseconds;
30
35
  fromDateNowMs: (ms: number) => Microseconds;
31
36
  };
@@ -39,6 +44,11 @@ export declare const defaultClock: {
39
44
  fromEpochMs: (ms: number) => Microseconds;
40
45
  fromEpochUs: (us: number) => Microseconds;
41
46
  fromPerfMs: (perfMs: Milliseconds) => Microseconds;
47
+ fromEntry: (entry: {
48
+ startTime: Milliseconds;
49
+ entryType: string;
50
+ duration: Milliseconds;
51
+ }, useEndTime?: boolean) => number;
42
52
  fromEntryStartTimeMs: (perfMs: Milliseconds) => Microseconds;
43
53
  fromDateNowMs: (ms: number) => Microseconds;
44
54
  };
@@ -17,6 +17,8 @@ export function epochClock(init = {}) {
17
17
  const fromEpochMs = msToUs;
18
18
  const fromPerfMs = (perfMs) => msToUs(timeOriginMs + perfMs);
19
19
  const fromEntryStartTimeMs = fromPerfMs;
20
+ const fromEntry = (entry, useEndTime = false) => fromPerfMs(entry.startTime +
21
+ (entry.entryType === 'measure' && useEndTime ? entry.duration : 0));
20
22
  const fromDateNowMs = fromEpochMs;
21
23
  return {
22
24
  timeOriginMs,
@@ -28,6 +30,7 @@ export function epochClock(init = {}) {
28
30
  fromEpochMs,
29
31
  fromEpochUs,
30
32
  fromPerfMs,
33
+ fromEntry,
31
34
  fromEntryStartTimeMs,
32
35
  fromDateNowMs,
33
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"clock-epoch.js","sourceRoot":"","sources":["../../../src/lib/clock-epoch.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAK/C,MAAM,MAAM,GAAG,CAAC,EAAU,EAAgB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC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AAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAa5D;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B,EAAE;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC;IAEjC,MAAM,YAAY,GAAG,WAAW,CAAC,UAAU,CAAC;IAE5C,MAAM,UAAU,GAAG,GAAiB,EAAE,CACpC,MAAM,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC;IAE3C,MAAM,WAAW,GAAG,MAAM,CAAC;IAE3B,MAAM,WAAW,GAAG,MAAM,CAAC;IAE3B,MAAM,UAAU,GAAG,CAAC,MAAoB,EAAgB,EAAE,CACxD,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC;IAEhC,MAAM,oBAAoB,GAAG,UAAU,CAAC;IACxC,MAAM,SAAS,GAAG,CAChB,KAIC,EACD,UAAU,GAAG,KAAK,EAClB,EAAE,CACF,UAAU,CACR,KAAK,CAAC,SAAS;QACb,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CACrE,CAAC;IACJ,MAAM,aAAa,GAAG,WAAW,CAAC;IAElC,OAAO;QACL,YAAY;QACZ,GAAG;QACH,GAAG;QAEH,UAAU;QACV,MAAM;QACN,MAAM;QAEN,WAAW;QACX,WAAW;QACX,UAAU;QACV,SAAS;QACT,oBAAoB;QACpB,aAAa;KACd,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,EAAE,CAAC"}
@@ -1,14 +1,14 @@
1
- import type { Audit, CategoryRef, Group, PluginConfig } from '@code-pushup/models';
1
+ import type { Audit, CategoryRef, Group } from '@code-pushup/models';
2
2
  import { type PluginUrlContext } from './plugin-url-config.js';
3
3
  export declare function shouldExpandForUrls(urlCount: number): boolean;
4
4
  export declare function addIndex(slug: string, index: number): string;
5
5
  export declare function removeIndex(slug: string): string;
6
+ export declare function extractGroupSlugs(groups: Group[]): string[];
6
7
  export declare function resolveUrlWeight(weights: PluginUrlContext['weights'], index: number, userDefinedWeight?: number): number;
7
8
  export declare function expandAuditsForUrls(audits: Audit[], urls: string[]): Audit[];
8
9
  export declare function expandGroupsForUrls(groups: Group[], urls: string[]): Group[];
9
- export declare function createCategoryRefs(groupSlug: string, pluginSlug: string, context: PluginUrlContext): CategoryRef[];
10
- export declare function expandCategoryRefs(ref: CategoryRef, context: PluginUrlContext): CategoryRef[];
11
- export declare class ContextValidationError extends Error {
12
- constructor(message: string);
13
- }
14
- export declare function validateUrlContext(context: PluginConfig['context']): asserts context is PluginUrlContext;
10
+ type CategoryRefInput = Omit<CategoryRef, 'weight'> & {
11
+ weight?: number;
12
+ };
13
+ export declare function expandCategoryRefs(ref: CategoryRefInput, context: PluginUrlContext): CategoryRef[];
14
+ export {};
@@ -8,8 +8,16 @@ export function addIndex(slug, index) {
8
8
  export function removeIndex(slug) {
9
9
  return slug.replace(/-\d+$/, '');
10
10
  }
11
+ export function extractGroupSlugs(groups) {
12
+ const slugs = groups.map(({ slug }) => removeIndex(slug));
13
+ return [...new Set(slugs)];
14
+ }
11
15
  export function resolveUrlWeight(weights, index, userDefinedWeight) {
12
- return weights[index + 1] ?? userDefinedWeight ?? 1;
16
+ const urlWeight = weights[index + 1] ?? 1;
17
+ if (userDefinedWeight == null) {
18
+ return urlWeight;
19
+ }
20
+ return (urlWeight + userDefinedWeight) / 2;
13
21
  }
14
22
  export function expandAuditsForUrls(audits, urls) {
15
23
  return urls.flatMap((url, index) => audits.map(audit => ({
@@ -29,16 +37,6 @@ export function expandGroupsForUrls(groups, urls) {
29
37
  })),
30
38
  })));
31
39
  }
32
- export function createCategoryRefs(groupSlug, pluginSlug, context) {
33
- return Array.from({ length: context.urlCount }, (_, i) => ({
34
- plugin: pluginSlug,
35
- slug: shouldExpandForUrls(context.urlCount)
36
- ? addIndex(groupSlug, i)
37
- : groupSlug,
38
- type: 'group',
39
- weight: resolveUrlWeight(context.weights, i),
40
- }));
41
- }
42
40
  export function expandCategoryRefs(ref, context) {
43
41
  return Array.from({ length: context.urlCount }, (_, i) => ({
44
42
  ...ref,
@@ -48,24 +46,4 @@ export function expandCategoryRefs(ref, context) {
48
46
  weight: resolveUrlWeight(context.weights, i, ref.weight),
49
47
  }));
50
48
  }
51
- export class ContextValidationError extends Error {
52
- constructor(message) {
53
- super(`Invalid plugin context: ${message}`);
54
- }
55
- }
56
- export function validateUrlContext(context) {
57
- if (!context || typeof context !== 'object') {
58
- throw new ContextValidationError('must be an object');
59
- }
60
- const { urlCount, weights } = context;
61
- if (typeof urlCount !== 'number' || urlCount < 0) {
62
- throw new ContextValidationError('urlCount must be a non-negative number');
63
- }
64
- if (!weights || typeof weights !== 'object') {
65
- throw new ContextValidationError('weights must be an object');
66
- }
67
- if (Object.keys(weights).length !== urlCount) {
68
- throw new ContextValidationError('weights count must match urlCount');
69
- }
70
- }
71
49
  //# sourceMappingURL=plugin-url-aggregation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-url-aggregation.js","sourceRoot":"","sources":["../../../src/lib/plugin-url-aggregation.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO,QAAQ,GAAG,oBAAoB,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAa;IAClD,OAAO,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;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kB,CAChC,GAAqB,EACrB,OAAyB;IAEzB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACzD,GAAG,GAAG;QACN,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC;YACzC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACvB,CAAC,CAAC,GAAG,CAAC,IAAI;QACZ,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;KACzD,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -1,8 +1,10 @@
1
- import type { PluginUrls } from '@code-pushup/models';
2
- export type PluginUrlContext = {
3
- urlCount: number;
4
- weights: Record<string, number>;
5
- };
1
+ import { z } from 'zod';
2
+ import { type PluginUrls } from '@code-pushup/models';
3
+ export declare const pluginUrlContextSchema: z.ZodObject<{
4
+ urlCount: z.ZodNumber;
5
+ weights: z.ZodRecord<z.ZodString, z.ZodNumber>;
6
+ }, z.core.$strip>;
7
+ export type PluginUrlContext = z.infer<typeof pluginUrlContextSchema>;
6
8
  export declare const SINGLE_URL_THRESHOLD = 1;
7
9
  export declare function normalizeUrlInput(input: PluginUrls): {
8
10
  urls: string[];
@@ -1,3 +1,14 @@
1
+ import { z } from 'zod';
2
+ import { nonnegativeNumberSchema, weightSchema, } from '@code-pushup/models';
3
+ export const pluginUrlContextSchema = z
4
+ .object({
5
+ urlCount: nonnegativeNumberSchema,
6
+ weights: z.record(z.string(), weightSchema),
7
+ })
8
+ .refine(({ urlCount, weights }) => Object.keys(weights).length === urlCount, {
9
+ message: 'weights count must match urlCount',
10
+ })
11
+ .meta({ title: 'PluginUrlContext' });
1
12
  export const SINGLE_URL_THRESHOLD = 1;
2
13
  export function normalizeUrlInput(input) {
3
14
  if (typeof input === 'string') {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-url-config.js","sourceRoot":"","sources":["../../../src/lib/plugin-url-config.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAIjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,CAAC,KAAK,CAAC;YACb,OAAO,EAAE;gBACP,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;aAClB;SACF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,KAAK;YACX,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK,CAAC,MAAM;gBACtB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;aAC7D;SACF,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;QACjC,OAAO,EAAE;YACP,QAAQ,EAAE,OAAO,CAAC,MAAM;YACxB,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAChD;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC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ks';
2
+ import type { BeginEvent, CompleteEvent, EndEvent, InstantEvent, InstantEventArgs, InstantEventTracingStartedInBrowser, SpanEventArgs, TraceEvent, TraceEventContainer } from './trace-file.type.js';
3
+ /**
4
+ * Generates a unique ID for linking begin and end span events in Chrome traces.
5
+ * @returns Object with local ID string for the id2 field
6
+ */
7
+ export declare const nextId2: () => {
8
+ local: string;
9
+ };
10
+ /**
11
+ * Generates a unique frame tree node ID from process and thread IDs.
12
+ * @param pid - Process ID
13
+ * @param tid - Thread ID
14
+ * @returns Combined numeric ID
15
+ */
16
+ export declare const frameTreeNodeId: (pid: number, tid: number) => number;
17
+ /**
18
+ * Generates a frame name string from process and thread IDs.
19
+ * @param pid - Process ID
20
+ * @param tid - Thread ID
21
+ * @returns Formatted frame name
22
+ */
23
+ export declare const frameName: (pid: number, tid: number) => string;
24
+ /**
25
+ * Creates an instant trace event for marking a point in time.
26
+ * @param opt - Event configuration options
27
+ * @returns InstantEvent object
28
+ */
29
+ export declare const getInstantEvent: (opt: {
30
+ name: string;
31
+ ts?: number;
32
+ pid?: number;
33
+ tid?: number;
34
+ args?: InstantEventArgs;
35
+ }) => InstantEvent;
36
+ /**
37
+ * Creates a start tracing event with frame information.
38
+ * This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
39
+ * @param opt - Tracing configuration options
40
+ * @returns StartTracingEvent object
41
+ */
42
+ export declare const getInstantEventTracingStartedInBrowser: (opt: {
43
+ url: string;
44
+ ts?: number;
45
+ pid?: number;
46
+ tid?: number;
47
+ }) => InstantEventTracingStartedInBrowser;
48
+ /**
49
+ * Creates a complete trace event with duration.
50
+ * @param opt - Event configuration with name and duration
51
+ * @returns CompleteEvent object
52
+ */
53
+ export declare const getCompleteEvent: (opt: {
54
+ name: string;
55
+ dur: number;
56
+ ts?: number;
57
+ pid?: number;
58
+ tid?: number;
59
+ }) => CompleteEvent;
60
+ /** Options for creating span events */
61
+ type SpanOpt = {
62
+ name: string;
63
+ id2: {
64
+ local: string;
65
+ };
66
+ ts?: number;
67
+ pid?: number;
68
+ tid?: number;
69
+ args?: SpanEventArgs;
70
+ };
71
+ /**
72
+ * Creates a begin span event.
73
+ * @param ph - Phase ('b' for begin)
74
+ * @param opt - Span event options
75
+ * @returns BeginEvent object
76
+ */
77
+ export declare function getSpanEvent(ph: 'b', opt: SpanOpt): BeginEvent;
78
+ /**
79
+ * Creates an end span event.
80
+ * @param ph - Phase ('e' for end)
81
+ * @param opt - Span event options
82
+ * @returns EndEvent object
83
+ */
84
+ export declare function getSpanEvent(ph: 'e', opt: SpanOpt): EndEvent;
85
+ /**
86
+ * Creates a pair of begin and end span events.
87
+ * @param opt - Span configuration with start/end timestamps
88
+ * @returns Tuple of BeginEvent and EndEvent
89
+ */
90
+ export declare const getSpan: (opt: {
91
+ name: string;
92
+ tsB: number;
93
+ tsE: number;
94
+ id2?: {
95
+ local: string;
96
+ };
97
+ pid?: number;
98
+ tid?: number;
99
+ args?: SpanEventArgs;
100
+ tsMarkerPadding?: number;
101
+ }) => [BeginEvent, EndEvent];
102
+ /**
103
+ * Converts a PerformanceMark to an instant trace event.
104
+ * @param entry - Performance mark entry
105
+ * @param opt - Optional overrides for name, pid, and tid
106
+ * @returns InstantEvent object
107
+ */
108
+ export declare const markToInstantEvent: (entry: PerformanceMark, opt?: {
109
+ name?: string;
110
+ pid?: number;
111
+ tid?: number;
112
+ }) => InstantEvent;
113
+ /**
114
+ * Converts a PerformanceMeasure to a pair of span events.
115
+ * @param entry - Performance measure entry
116
+ * @param opt - Optional overrides for name, pid, and tid
117
+ * @returns Tuple of BeginEvent and EndEvent
118
+ */
119
+ export declare const measureToSpanEvents: (entry: PerformanceMeasure, opt?: {
120
+ name?: string;
121
+ pid?: number;
122
+ tid?: number;
123
+ }) => [BeginEvent, EndEvent];
124
+ /**
125
+ * Creates a complete trace file container with metadata.
126
+ * @param opt - Trace file configuration
127
+ * @returns TraceEventContainer with events and metadata
128
+ */
129
+ export declare const getTraceFile: (opt: {
130
+ traceEvents: TraceEvent[];
131
+ startTime?: string;
132
+ }) => TraceEventContainer;
133
+ export {};
@@ -0,0 +1,179 @@
1
+ import os from 'node:os';
2
+ import { threadId } from 'node:worker_threads';
3
+ import { defaultClock } from './clock-epoch.js';
4
+ /** Global counter for generating unique span IDs within a trace */
5
+ // eslint-disable-next-line functional/no-let
6
+ let id2Count = 0;
7
+ /**
8
+ * Generates a unique ID for linking begin and end span events in Chrome traces.
9
+ * @returns Object with local ID string for the id2 field
10
+ */
11
+ export const nextId2 = () => ({ local: `0x${++id2Count}` });
12
+ /**
13
+ * Provides default values for trace event properties.
14
+ * @param opt - Optional overrides for pid, tid, and timestamp
15
+ * @returns Object with pid, tid, and timestamp
16
+ */
17
+ const defaults = (opt) => ({
18
+ pid: opt?.pid ?? process.pid,
19
+ tid: opt?.tid ?? threadId,
20
+ ts: opt?.ts ?? defaultClock.epochNowUs(),
21
+ });
22
+ /**
23
+ * Generates a unique frame tree node ID from process and thread IDs.
24
+ * @param pid - Process ID
25
+ * @param tid - Thread ID
26
+ * @returns Combined numeric ID
27
+ */
28
+ export const frameTreeNodeId = (pid, tid) => Number.parseInt(`${pid}0${tid}`, 10);
29
+ /**
30
+ * Generates a frame name string from process and thread IDs.
31
+ * @param pid - Process ID
32
+ * @param tid - Thread ID
33
+ * @returns Formatted frame name
34
+ */
35
+ export const frameName = (pid, tid) => `FRAME0P${pid}T${tid}`;
36
+ /**
37
+ * Creates an instant trace event for marking a point in time.
38
+ * @param opt - Event configuration options
39
+ * @returns InstantEvent object
40
+ */
41
+ export const getInstantEvent = (opt) => ({
42
+ cat: 'blink.user_timing',
43
+ ph: 'i',
44
+ name: opt.name,
45
+ ...defaults(opt),
46
+ args: opt.args ?? {},
47
+ });
48
+ /**
49
+ * Creates a start tracing event with frame information.
50
+ * This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
51
+ * @param opt - Tracing configuration options
52
+ * @returns StartTracingEvent object
53
+ */
54
+ export const getInstantEventTracingStartedInBrowser = (opt) => {
55
+ const { pid, tid, ts } = defaults(opt);
56
+ const id = frameTreeNodeId(pid, tid);
57
+ return {
58
+ cat: 'devtools.timeline',
59
+ ph: 'i',
60
+ name: 'TracingStartedInBrowser',
61
+ pid,
62
+ tid,
63
+ ts,
64
+ args: {
65
+ data: {
66
+ frameTreeNodeId: id,
67
+ frames: [
68
+ {
69
+ frame: frameName(pid, tid),
70
+ isInPrimaryMainFrame: true,
71
+ isOutermostMainFrame: true,
72
+ name: '',
73
+ processId: pid,
74
+ url: opt.url,
75
+ },
76
+ ],
77
+ persistentIds: true,
78
+ },
79
+ },
80
+ };
81
+ };
82
+ /**
83
+ * Creates a complete trace event with duration.
84
+ * @param opt - Event configuration with name and duration
85
+ * @returns CompleteEvent object
86
+ */
87
+ export const getCompleteEvent = (opt) => ({
88
+ cat: 'devtools.timeline',
89
+ ph: 'X',
90
+ name: opt.name,
91
+ dur: opt.dur,
92
+ ...defaults(opt),
93
+ args: {},
94
+ });
95
+ /**
96
+ * Creates a span event (begin or end).
97
+ * @param ph - Phase ('b' or 'e')
98
+ * @param opt - Span event options
99
+ * @returns SpanEvent object
100
+ */
101
+ export function getSpanEvent(ph, opt) {
102
+ return {
103
+ cat: 'blink.user_timing',
104
+ ph,
105
+ name: opt.name,
106
+ id2: opt.id2,
107
+ ...defaults(opt),
108
+ args: opt.args?.data?.detail
109
+ ? { data: { detail: opt.args.data.detail } }
110
+ : {},
111
+ };
112
+ }
113
+ /**
114
+ * Creates a pair of begin and end span events.
115
+ * @param opt - Span configuration with start/end timestamps
116
+ * @returns Tuple of BeginEvent and EndEvent
117
+ */
118
+ export const getSpan = (opt) => {
119
+ // tsMarkerPadding is here to make the measure slightly smaller so the markers align perfectly.
120
+ // Otherwise, the marker is visible at the start of the measure below the frame
121
+ // No padding Padding
122
+ // spans: ======== |======|
123
+ // marks: | |
124
+ const pad = opt.tsMarkerPadding ?? 1;
125
+ // b|e need to share the same id2
126
+ const id2 = opt.id2 ?? nextId2();
127
+ return [
128
+ getSpanEvent('b', {
129
+ ...opt,
130
+ id2,
131
+ ts: opt.tsB + pad,
132
+ }),
133
+ getSpanEvent('e', {
134
+ ...opt,
135
+ id2,
136
+ ts: opt.tsE - pad,
137
+ }),
138
+ ];
139
+ };
140
+ /**
141
+ * Converts a PerformanceMark to an instant trace event.
142
+ * @param entry - Performance mark entry
143
+ * @param opt - Optional overrides for name, pid, and tid
144
+ * @returns InstantEvent object
145
+ */
146
+ export const markToInstantEvent = (entry, opt) => getInstantEvent({
147
+ ...opt,
148
+ name: opt?.name ?? entry.name,
149
+ ts: defaultClock.fromEntry(entry),
150
+ args: entry.detail ? { detail: entry.detail } : undefined,
151
+ });
152
+ /**
153
+ * Converts a PerformanceMeasure to a pair of span events.
154
+ * @param entry - Performance measure entry
155
+ * @param opt - Optional overrides for name, pid, and tid
156
+ * @returns Tuple of BeginEvent and EndEvent
157
+ */
158
+ export const measureToSpanEvents = (entry, opt) => getSpan({
159
+ ...opt,
160
+ name: opt?.name ?? entry.name,
161
+ tsB: defaultClock.fromEntry(entry),
162
+ tsE: defaultClock.fromEntry(entry, true),
163
+ args: entry.detail ? { data: { detail: entry.detail } } : undefined,
164
+ });
165
+ /**
166
+ * Creates a complete trace file container with metadata.
167
+ * @param opt - Trace file configuration
168
+ * @returns TraceEventContainer with events and metadata
169
+ */
170
+ export const getTraceFile = (opt) => ({
171
+ traceEvents: opt.traceEvents,
172
+ displayTimeUnit: 'ms',
173
+ metadata: {
174
+ source: 'Node.js UserTiming',
175
+ startTime: opt.startTime ?? new Date().toISOString(),
176
+ hardwareConcurrency: os.cpus().length,
177
+ },
178
+ });
179
+ //# sourceMappingURL=trace-file-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-file-utils.js","sourceRoot":"","sources":["../../../src/lib/trace-file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,C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C,IAAI;IAC7B,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC;IAClC,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;IACxC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;CACpE,CAAC,CAAC;AAEL;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAG5B,EAAuB,EAAE,CAAC,CAAC;IAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,eAAe,EAAE,IAAI;IACrB,QAAQ,EAAE;QACR,MAAM,EAAE,oBAAoB;QAC5B,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpD,mBAAmB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM;KACtC;CACF,CAAC,CAAC"}
@@ -0,0 +1,279 @@
1
+ import type { UserTimingDetail } from './user-timing-extensibility-api.type.js';
2
+ /**
3
+ * Arguments for instant trace events.
4
+ * @property {UserTimingDetail} [detail] - Optional user timing detail with DevTools payload
5
+ */
6
+ export type InstantEventArgs = {
7
+ detail?: UserTimingDetail;
8
+ } & {
9
+ [key: string]: unknown;
10
+ };
11
+ /**
12
+ * Arguments for span trace events (begin/end events).
13
+ * @property {object} [data] - Optional data object
14
+ * @property {UserTimingDetail} [data.detail] - Optional user timing detail with DevTools payload
15
+ */
16
+ export type SpanEventArgs = {
17
+ data?: {
18
+ detail?: UserTimingDetail;
19
+ };
20
+ } & {
21
+ [key: string]: unknown;
22
+ };
23
+ /**
24
+ * Arguments for complete trace events.
25
+ * @property {Record<string, unknown>} [detail] - Optional detail object with arbitrary properties
26
+ */
27
+ export type CompleteEventArgs = {
28
+ detail?: Record<string, unknown>;
29
+ };
30
+ /**
31
+ * Arguments for start tracing events.
32
+ * @property {object} data - Tracing initialization data
33
+ * @property {number} data.frameTreeNodeId - Frame tree node identifier
34
+ * @property {Array} data.frames - Array of frame information
35
+ * @property {boolean} data.persistentIds - Whether IDs are persistent
36
+ */
37
+ export type InstantEventTracingStartedInBrowserArgs = {
38
+ data: {
39
+ frameTreeNodeId: number;
40
+ frames: {
41
+ frame: string;
42
+ isInPrimaryMainFrame: boolean;
43
+ isOutermostMainFrame: boolean;
44
+ name: string;
45
+ processId: number;
46
+ url: string;
47
+ }[];
48
+ persistentIds: boolean;
49
+ };
50
+ };
51
+ /**
52
+ * Union type of all possible trace event arguments.
53
+ */
54
+ export type TraceArgs = InstantEventArgs | SpanEventArgs | CompleteEventArgs | InstantEventTracingStartedInBrowserArgs;
55
+ /**
56
+ * Base properties shared by all trace events.
57
+ * @property {string} cat - Event category
58
+ * @property {string} name - Event name
59
+ * @property {number} pid - Process ID
60
+ * @property {number} tid - Thread ID
61
+ * @property {number} ts - Timestamp in epoch microseconds
62
+ * @property {TraceArgs} [args] - Optional event arguments
63
+ */
64
+ export type BaseTraceEvent = {
65
+ cat: string;
66
+ name: string;
67
+ pid: number;
68
+ tid: number;
69
+ ts: number;
70
+ args: TraceArgs;
71
+ };
72
+ /**
73
+ * Start tracing event for Chrome DevTools tracing.
74
+ */
75
+ export type InstantEventTracingStartedInBrowser = BaseTraceEvent & {
76
+ cat: 'devtools.timeline';
77
+ ph: 'i';
78
+ name: 'TracingStartedInBrowser';
79
+ args: InstantEventTracingStartedInBrowserArgs;
80
+ };
81
+ /**
82
+ * Complete trace event with duration.
83
+ * Represents a complete operation with start time and duration.
84
+ * @property {'X'} ph - Phase indicator for complete events
85
+ * @property {number} dur - Duration in microseconds
86
+ */
87
+ export type CompleteEvent = BaseTraceEvent & {
88
+ ph: 'X';
89
+ dur: number;
90
+ };
91
+ /**
92
+ * Instant trace event representing a single point in time.
93
+ * Used for user timing marks and other instantaneous events.
94
+ * @property {'blink.user_timing'} cat - Fixed category for user timing events
95
+ * @property {'i'} ph - Phase indicator for instant events
96
+ * @property {never} [dur] - Duration is not applicable for instant events
97
+ * @property {InstantEventArgs} [args] - Optional event arguments
98
+ */
99
+ export type InstantEvent = Omit<BaseTraceEvent, 'cat' | 'args'> & {
100
+ cat: 'blink.user_timing';
101
+ ph: 'i';
102
+ dur?: never;
103
+ args: InstantEventArgs;
104
+ };
105
+ /**
106
+ * Core properties for span trace events (begin/end pairs).
107
+ * @property {object} id2 - Span identifier
108
+ * @property {string} id2.local - Local span ID (unique to the process, same for b and e events)
109
+ * @property {SpanEventArgs} [args] - Optional event arguments
110
+ */
111
+ type SpanCore = Omit<BaseTraceEvent, 'args'> & {
112
+ id2: {
113
+ local: string;
114
+ };
115
+ args: SpanEventArgs;
116
+ };
117
+ /**
118
+ * Begin event for a span (paired with an end event).
119
+ * @property {'b'} ph - Phase indicator for begin events
120
+ * @property {never} [dur] - Duration is not applicable for begin events
121
+ */
122
+ export type BeginEvent = SpanCore & {
123
+ ph: 'b';
124
+ dur?: never;
125
+ };
126
+ /**
127
+ * End event for a span (paired with a begin event).
128
+ * @property {'e'} ph - Phase indicator for end events
129
+ * @property {never} [dur] - Duration is not applicable for end events
130
+ */
131
+ export type EndEvent = SpanCore & {
132
+ ph: 'e';
133
+ dur?: never;
134
+ };
135
+ /**
136
+ * Union type for span events (begin or end).
137
+ */
138
+ export type SpanEvent = BeginEvent | EndEvent;
139
+ /**
140
+ * Union type of all trace event types.
141
+ */
142
+ export type TraceEvent = InstantEvent | CompleteEvent | SpanEvent | InstantEventTracingStartedInBrowser;
143
+ /**
144
+ * Raw arguments format for trace events before processing.
145
+ * Either contains a detail string directly or nested in a data object.
146
+ */
147
+ type RawArgs = {
148
+ detail?: string;
149
+ [key: string]: unknown;
150
+ } | {
151
+ data?: {
152
+ detail?: string;
153
+ };
154
+ [key: string]: unknown;
155
+ };
156
+ /**
157
+ * Raw trace event format before type conversion.
158
+ * Similar to TraceEvent but with unprocessed arguments.
159
+ */
160
+ export type TraceEventRaw = Omit<TraceEvent, 'args'> & {
161
+ args: RawArgs;
162
+ };
163
+ /**
164
+ * Time window bounds (min, max) in trace time units (e.g. microseconds).
165
+ * @property {number} min - Minimum timestamp in the window
166
+ * @property {number} max - Maximum timestamp in the window
167
+ * @property {number} range - Calculated range (max - min)
168
+ */
169
+ export type BreadcrumbWindow = {
170
+ min: number;
171
+ max: number;
172
+ range: number;
173
+ };
174
+ /**
175
+ * Custom label for a specific trace entry.
176
+ * @property {number | string} entryId - ID or index of the trace entry
177
+ * @property {string} label - Label text for the entry
178
+ * @property {string} [color] - Optional display color for the label
179
+ */
180
+ export type EntryLabel = {
181
+ entryId: number | string;
182
+ label: string;
183
+ color?: string;
184
+ };
185
+ /**
186
+ * Link or relation between two trace entries.
187
+ * @property {number | string} fromEntryId - Source entry ID for the link
188
+ * @property {number | string} toEntryId - Target entry ID for the link
189
+ * @property {string} [linkType] - Optional type or description of the link
190
+ */
191
+ export type EntryLink = {
192
+ fromEntryId: number | string;
193
+ toEntryId: number | string;
194
+ linkType?: string;
195
+ };
196
+ /**
197
+ * A time range annotated with a label.
198
+ * @property {number} startTime - Start timestamp of the range (microseconds)
199
+ * @property {number} endTime - End timestamp of the range (microseconds)
200
+ * @property {string} label - Annotation label for the time range
201
+ * @property {string} [color] - Optional display color for the range
202
+ */
203
+ export type LabelledTimeRange = {
204
+ startTime: number;
205
+ endTime: number;
206
+ label: string;
207
+ color?: string;
208
+ };
209
+ /**
210
+ * Hidden or expandable entries information.
211
+ * @property {unknown[]} hiddenEntries - IDs or indexes of hidden entries
212
+ * @property {unknown[]} expandableEntries - IDs or indexes of expandable entries
213
+ */
214
+ export type EntriesModifications = {
215
+ hiddenEntries: unknown[];
216
+ expandableEntries: unknown[];
217
+ };
218
+ /**
219
+ * Initial breadcrumb information for time ranges and window.
220
+ * @property {BreadcrumbWindow} window - Time window bounds
221
+ * @property {unknown | null} child - Child breadcrumb or null
222
+ */
223
+ export type InitialBreadcrumb = {
224
+ window: BreadcrumbWindow;
225
+ child: unknown | null;
226
+ };
227
+ /**
228
+ * Annotations such as labels and links between entries.
229
+ * @property {EntryLabel[]} entryLabels - Custom labels for entries
230
+ * @property {LabelledTimeRange[]} labelledTimeRanges - Time ranges annotated with labels
231
+ * @property {EntryLink[]} linksBetweenEntries - Links or relations between entries
232
+ */
233
+ export type Annotations = {
234
+ entryLabels: EntryLabel[];
235
+ labelledTimeRanges: LabelledTimeRange[];
236
+ linksBetweenEntries: EntryLink[];
237
+ };
238
+ /**
239
+ * Modifications made to trace data or UI in DevTools export
240
+ */
241
+ export type Modifications = {
242
+ entriesModifications: EntriesModifications;
243
+ initialBreadcrumb: InitialBreadcrumb;
244
+ annotations: Annotations;
245
+ };
246
+ /**
247
+ * Top-level metadata for a trace file exported by Chrome DevTools.
248
+ * DevTools may add new fields over time.
249
+ */
250
+ export type TraceMetadata = {
251
+ /** Usually "DevTools" for exports from the Performance panel */
252
+ source: string;
253
+ /** ISO timestamp when trace was recorded */
254
+ startTime: string;
255
+ /** May be present when recorded with throttling settings */
256
+ hardwareConcurrency?: number;
257
+ /** Common fields found in DevTools traces */
258
+ cpuThrottling?: number;
259
+ networkThrottling?: string;
260
+ enhancedTraceVersion?: number;
261
+ /** Allow additional custom metadata properties */
262
+ [key: string]: unknown;
263
+ };
264
+ /**
265
+ * Structured container for trace events with metadata.
266
+ * @property {TraceEvent[]} traceEvents - Array of trace events
267
+ * @property {'ms' | 'ns'} [displayTimeUnit] - Time unit for display (milliseconds or nanoseconds)
268
+ * @property {TraceMetadata} [metadata] - Optional metadata about the trace
269
+ */
270
+ export type TraceEventContainer = {
271
+ traceEvents: TraceEvent[];
272
+ displayTimeUnit?: 'ms' | 'ns';
273
+ metadata?: TraceMetadata;
274
+ };
275
+ /**
276
+ * Trace file format - either an array of events or a structured container.
277
+ */
278
+ export type TraceFile = TraceEvent[] | TraceEventContainer;
279
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=trace-file.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-file.type.js","sourceRoot":"","sources":["../../../src/lib/trace-file.type.ts"],"names":[],"mappings":""}
@@ -141,3 +141,9 @@ export type MarkOptionsWithDevtools<T extends TrackEntryPayload | MarkerPayload>
141
141
  export type MeasureOptionsWithDevtools<T extends TrackEntryPayload> = {
142
142
  detail?: WithDevToolsPayload<T>;
143
143
  } & Omit<MeasureOptions, 'detail'>;
144
+ /**
145
+ * Detail object containing DevTools payload for user timing events.
146
+ * Extends WithDevToolsPayload to include track entry or marker payload.
147
+ * This can be used in trace event arguments to provide additional context in DevTools.
148
+ */
149
+ export type UserTimingDetail = WithDevToolsPayload<TrackEntryPayload | MarkerPayload>;