@code-pushup/utils 0.101.0 → 0.102.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 +2 -2
- package/src/lib/clock-epoch.d.ts +44 -0
- package/src/lib/clock-epoch.js +36 -0
- package/src/lib/clock-epoch.js.map +1 -0
- package/src/lib/performance-observer.d.ts +18 -0
- package/src/lib/performance-observer.js +63 -0
- package/src/lib/performance-observer.js.map +1 -0
- package/src/lib/sink-source.types.d.ts +43 -0
- package/src/lib/sink-source.types.js +2 -0
- package/src/lib/sink-source.types.js.map +1 -0
- package/src/lib/user-timing-extensibility-api-utils.d.ts +72 -0
- package/src/lib/user-timing-extensibility-api-utils.js +80 -0
- package/src/lib/user-timing-extensibility-api-utils.js.map +1 -0
- package/src/lib/user-timing-extensibility-api.type.d.ts +128 -0
- package/src/lib/user-timing-extensibility-api.type.js +2 -0
- package/src/lib/user-timing-extensibility-api.type.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.102.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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"node": ">=17.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@code-pushup/models": "0.
|
|
30
|
+
"@code-pushup/models": "0.102.0",
|
|
31
31
|
"ansis": "^3.3.0",
|
|
32
32
|
"build-md": "^0.4.2",
|
|
33
33
|
"bundle-require": "^5.1.0",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Microseconds = number;
|
|
2
|
+
export type Milliseconds = number;
|
|
3
|
+
/**
|
|
4
|
+
* Defines clock utilities for time conversions.
|
|
5
|
+
* Handles time origins in NodeJS and the Browser
|
|
6
|
+
* Provides process and thread IDs.
|
|
7
|
+
* @param init
|
|
8
|
+
*/
|
|
9
|
+
export type EpochClockOptions = {
|
|
10
|
+
pid?: number;
|
|
11
|
+
tid?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates epoch-based clock utility.
|
|
15
|
+
* Epoch time has been the time since January 1, 1970 (UNIX epoch).
|
|
16
|
+
* Date.now gives epoch time in milliseconds.
|
|
17
|
+
* performance.now() + performance.timeOrigin when available is used for higher precision.
|
|
18
|
+
*/
|
|
19
|
+
export declare function epochClock(init?: EpochClockOptions): {
|
|
20
|
+
timeOriginMs: number;
|
|
21
|
+
pid: number;
|
|
22
|
+
tid: number;
|
|
23
|
+
epochNowUs: () => Microseconds;
|
|
24
|
+
msToUs: (ms: number) => Microseconds;
|
|
25
|
+
usToUs: (us: number) => Microseconds;
|
|
26
|
+
fromEpochMs: (ms: number) => Microseconds;
|
|
27
|
+
fromEpochUs: (us: number) => Microseconds;
|
|
28
|
+
fromPerfMs: (perfMs: Milliseconds) => Microseconds;
|
|
29
|
+
fromEntryStartTimeMs: (perfMs: Milliseconds) => Microseconds;
|
|
30
|
+
fromDateNowMs: (ms: number) => Microseconds;
|
|
31
|
+
};
|
|
32
|
+
export declare const defaultClock: {
|
|
33
|
+
timeOriginMs: number;
|
|
34
|
+
pid: number;
|
|
35
|
+
tid: number;
|
|
36
|
+
epochNowUs: () => Microseconds;
|
|
37
|
+
msToUs: (ms: number) => Microseconds;
|
|
38
|
+
usToUs: (us: number) => Microseconds;
|
|
39
|
+
fromEpochMs: (ms: number) => Microseconds;
|
|
40
|
+
fromEpochUs: (us: number) => Microseconds;
|
|
41
|
+
fromPerfMs: (perfMs: Milliseconds) => Microseconds;
|
|
42
|
+
fromEntryStartTimeMs: (perfMs: Milliseconds) => Microseconds;
|
|
43
|
+
fromDateNowMs: (ms: number) => Microseconds;
|
|
44
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { threadId } from 'node:worker_threads';
|
|
3
|
+
const msToUs = (ms) => Math.round(ms * 1000);
|
|
4
|
+
const usToUs = (us) => Math.round(us);
|
|
5
|
+
/**
|
|
6
|
+
* Creates epoch-based clock utility.
|
|
7
|
+
* Epoch time has been the time since January 1, 1970 (UNIX epoch).
|
|
8
|
+
* Date.now gives epoch time in milliseconds.
|
|
9
|
+
* performance.now() + performance.timeOrigin when available is used for higher precision.
|
|
10
|
+
*/
|
|
11
|
+
export function epochClock(init = {}) {
|
|
12
|
+
const pid = init.pid ?? process.pid;
|
|
13
|
+
const tid = init.tid ?? threadId;
|
|
14
|
+
const timeOriginMs = performance.timeOrigin;
|
|
15
|
+
const epochNowUs = () => msToUs(timeOriginMs + performance.now());
|
|
16
|
+
const fromEpochUs = usToUs;
|
|
17
|
+
const fromEpochMs = msToUs;
|
|
18
|
+
const fromPerfMs = (perfMs) => msToUs(timeOriginMs + perfMs);
|
|
19
|
+
const fromEntryStartTimeMs = fromPerfMs;
|
|
20
|
+
const fromDateNowMs = fromEpochMs;
|
|
21
|
+
return {
|
|
22
|
+
timeOriginMs,
|
|
23
|
+
pid,
|
|
24
|
+
tid,
|
|
25
|
+
epochNowUs,
|
|
26
|
+
msToUs,
|
|
27
|
+
usToUs,
|
|
28
|
+
fromEpochMs,
|
|
29
|
+
fromEpochUs,
|
|
30
|
+
fromPerfMs,
|
|
31
|
+
fromEntryStartTimeMs,
|
|
32
|
+
fromDateNowMs,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export const defaultClock = epochClock();
|
|
36
|
+
//# sourceMappingURL=clock-epoch.js.map
|
|
@@ -0,0 +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;AACnE,MAAM,MAAM,GAAG,CAAC,EAAU,EAAgB,EAAE,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,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,oBAAoB;QACpB,aAAa;KACd,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type PerformanceEntry } from 'node:perf_hooks';
|
|
2
|
+
import type { Buffered, Encoder, Observer, Sink } from './sink-source.types.js';
|
|
3
|
+
export declare const DEFAULT_FLUSH_THRESHOLD = 20;
|
|
4
|
+
export type PerformanceObserverOptions<T> = {
|
|
5
|
+
sink: Sink<T, unknown>;
|
|
6
|
+
encode: (entry: PerformanceEntry) => T[];
|
|
7
|
+
buffered?: boolean;
|
|
8
|
+
flushThreshold?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class PerformanceObserverSink<T> implements Observer, Buffered, Encoder<PerformanceEntry, T[]> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options: PerformanceObserverOptions<T>);
|
|
13
|
+
encode(entry: PerformanceEntry): T[];
|
|
14
|
+
subscribe(): void;
|
|
15
|
+
flush(entriesToProcess?: PerformanceEntry[]): void;
|
|
16
|
+
unsubscribe(): void;
|
|
17
|
+
isSubscribed(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PerformanceObserver, performance, } from 'node:perf_hooks';
|
|
2
|
+
export const DEFAULT_FLUSH_THRESHOLD = 20;
|
|
3
|
+
export class PerformanceObserverSink {
|
|
4
|
+
#encode;
|
|
5
|
+
#buffered;
|
|
6
|
+
#flushThreshold;
|
|
7
|
+
#sink;
|
|
8
|
+
#observer;
|
|
9
|
+
#observedTypes = ['mark', 'measure'];
|
|
10
|
+
#getEntries = (list) => this.#observedTypes.flatMap(t => list.getEntriesByType(t));
|
|
11
|
+
#observedCount = 0;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.#encode = options.encode;
|
|
14
|
+
this.#sink = options.sink;
|
|
15
|
+
this.#buffered = options.buffered ?? false;
|
|
16
|
+
this.#flushThreshold = options.flushThreshold ?? DEFAULT_FLUSH_THRESHOLD;
|
|
17
|
+
}
|
|
18
|
+
encode(entry) {
|
|
19
|
+
return this.#encode(entry);
|
|
20
|
+
}
|
|
21
|
+
subscribe() {
|
|
22
|
+
if (this.#observer) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.#observer = new PerformanceObserver(list => {
|
|
26
|
+
const entries = this.#getEntries(list);
|
|
27
|
+
this.#observedCount += entries.length;
|
|
28
|
+
if (this.#observedCount >= this.#flushThreshold) {
|
|
29
|
+
this.flush(entries);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
this.#observer.observe({
|
|
33
|
+
entryTypes: this.#observedTypes,
|
|
34
|
+
buffered: this.#buffered,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
flush(entriesToProcess) {
|
|
38
|
+
if (!this.#observer) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const entries = entriesToProcess || this.#getEntries(performance);
|
|
42
|
+
entries.forEach(entry => {
|
|
43
|
+
const encoded = this.encode(entry);
|
|
44
|
+
encoded.forEach(item => {
|
|
45
|
+
this.#sink.write(item);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
// In real PerformanceObserver, entries remain in the global buffer
|
|
49
|
+
// They are only cleared when explicitly requested via performance.clearMarks/clearMeasures
|
|
50
|
+
this.#observedCount = 0;
|
|
51
|
+
}
|
|
52
|
+
unsubscribe() {
|
|
53
|
+
if (!this.#observer) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.#observer?.disconnect();
|
|
57
|
+
this.#observer = undefined;
|
|
58
|
+
}
|
|
59
|
+
isSubscribed() {
|
|
60
|
+
return this.#observer !== undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=performance-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance-observer.js","sourceRoot":"","sources":["../../../src/lib/performance-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAEnB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAS1C,MAAM,OAAO,uBAAuB;IAGlC,OAAO,CAAmC;IAC1C,SAAS,CAAU;IACnB,eAAe,CAAS;IACxB,KAAK,CAAmB;IACxB,SAAS,CAAkC;IAC3C,cAAc,GAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,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MAAM,OAAO,GAAG,gBAAgB,IAAI,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAClE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACtB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACrB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,mEAAmE;QACnE,2FAA2F;QAE3F,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type Encoder<I, O> = {
|
|
2
|
+
encode: (input: I) => O;
|
|
3
|
+
};
|
|
4
|
+
export type Decoder<O, I> = {
|
|
5
|
+
decode: (output: O) => I;
|
|
6
|
+
};
|
|
7
|
+
export type Sink<I, O> = {
|
|
8
|
+
open: () => void;
|
|
9
|
+
write: (input: I) => void;
|
|
10
|
+
close: () => void;
|
|
11
|
+
isClosed: () => boolean;
|
|
12
|
+
} & Encoder<I, O>;
|
|
13
|
+
export type Buffered = {
|
|
14
|
+
flush: () => void;
|
|
15
|
+
};
|
|
16
|
+
export type BufferedSink<I, O> = Sink<I, O> & Buffered;
|
|
17
|
+
export type Source<I, O = unknown> = {
|
|
18
|
+
read?: () => O;
|
|
19
|
+
decode?: (input: I) => O;
|
|
20
|
+
};
|
|
21
|
+
export type Observer = {
|
|
22
|
+
subscribe: () => void;
|
|
23
|
+
unsubscribe: () => void;
|
|
24
|
+
isSubscribed: () => boolean;
|
|
25
|
+
};
|
|
26
|
+
export type Recoverable = {
|
|
27
|
+
recover: () => RecoverResult;
|
|
28
|
+
repack: () => void;
|
|
29
|
+
finalize: () => void;
|
|
30
|
+
};
|
|
31
|
+
export type RecoverResult<T = unknown> = {
|
|
32
|
+
records: T[];
|
|
33
|
+
errors: {
|
|
34
|
+
lineNo: number;
|
|
35
|
+
line: string;
|
|
36
|
+
error: Error;
|
|
37
|
+
}[];
|
|
38
|
+
partialTail: string | null;
|
|
39
|
+
};
|
|
40
|
+
export type RecoverOptions = {
|
|
41
|
+
keepInvalid?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type Output<I, O> = {} & BufferedSink<I, O>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink-source.types.js","sourceRoot":"","sources":["../../../src/lib/sink-source.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { DevToolsColor, DevToolsProperties, MarkOptionsWithDevtools, MarkerPayload, MeasureOptionsWithDevtools, TrackEntryPayload } from './user-timing-extensibility-api.type.js';
|
|
2
|
+
export declare function mergePropertiesWithOverwrite(baseProperties: DevToolsProperties | undefined, overrideProperties?: DevToolsProperties | undefined): [string, string | number | boolean | object | undefined][];
|
|
3
|
+
export declare function markerPayload(options?: Omit<MarkerPayload, 'dataType'>): {
|
|
4
|
+
color?: DevToolsColor;
|
|
5
|
+
tooltipText?: string;
|
|
6
|
+
properties?: DevToolsProperties;
|
|
7
|
+
dataType: "marker";
|
|
8
|
+
};
|
|
9
|
+
export declare function trackEntryPayload(options: Omit<TrackEntryPayload, 'dataType'>): {
|
|
10
|
+
color?: DevToolsColor | undefined;
|
|
11
|
+
tooltipText?: string | undefined;
|
|
12
|
+
properties?: DevToolsProperties | undefined;
|
|
13
|
+
trackGroup?: string | undefined;
|
|
14
|
+
dataType: "track-entry";
|
|
15
|
+
track: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function markerErrorPayload<T extends DevToolsColor>(options?: Omit<MarkerPayload, 'dataType' | 'color'>): {
|
|
18
|
+
tooltipText?: string;
|
|
19
|
+
properties?: DevToolsProperties;
|
|
20
|
+
dataType: "marker";
|
|
21
|
+
color: T;
|
|
22
|
+
};
|
|
23
|
+
export declare function trackEntryErrorPayload<T extends string, C extends DevToolsColor>(options: Omit<TrackEntryPayload, 'color' | 'dataType'> & {
|
|
24
|
+
track: T;
|
|
25
|
+
color?: C;
|
|
26
|
+
}): {
|
|
27
|
+
tooltipText?: string | undefined;
|
|
28
|
+
properties?: DevToolsProperties | undefined;
|
|
29
|
+
trackGroup?: string | undefined;
|
|
30
|
+
dataType: "track-entry";
|
|
31
|
+
color: DevToolsColor;
|
|
32
|
+
track: T;
|
|
33
|
+
};
|
|
34
|
+
export declare function errorToDevToolsProperties(e: unknown): (["Error Type", string] | ["Error Message", string])[];
|
|
35
|
+
export declare function errorToEntryMeta(e: unknown, options?: {
|
|
36
|
+
tooltipText?: string;
|
|
37
|
+
properties?: DevToolsProperties;
|
|
38
|
+
}): {
|
|
39
|
+
tooltipText?: string | undefined;
|
|
40
|
+
properties: [string, string | number | boolean | object | undefined][];
|
|
41
|
+
};
|
|
42
|
+
export declare function errorToTrackEntryPayload<T extends string>(error: unknown, detail: Omit<TrackEntryPayload, 'color' | 'dataType'> & {
|
|
43
|
+
track: T;
|
|
44
|
+
}): {
|
|
45
|
+
tooltipText?: string | undefined;
|
|
46
|
+
properties: [string, string | number | boolean | object | undefined][];
|
|
47
|
+
track: T;
|
|
48
|
+
trackGroup?: string | undefined;
|
|
49
|
+
dataType: "track-entry";
|
|
50
|
+
color: "error";
|
|
51
|
+
};
|
|
52
|
+
export declare function errorToMarkerPayload(error: unknown, detail?: Omit<MarkerPayload, 'color' | 'dataType'>): {
|
|
53
|
+
tooltipText?: string | undefined;
|
|
54
|
+
properties: [string, string | number | boolean | object | undefined][];
|
|
55
|
+
dataType: "marker";
|
|
56
|
+
color: "error";
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* asOptions wraps a DevTools payload into the `detail` property of User Timing entry options.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* profiler.mark('mark', asOptions({
|
|
63
|
+
* dataType: 'marker',
|
|
64
|
+
* color: 'error',
|
|
65
|
+
* tooltipText: 'This is a marker',
|
|
66
|
+
* properties: [
|
|
67
|
+
* ['str', 'This is a detail property']
|
|
68
|
+
* ],
|
|
69
|
+
* }));
|
|
70
|
+
*/
|
|
71
|
+
export declare function asOptions<T extends MarkerPayload>(devtools?: T | null): MarkOptionsWithDevtools<T>;
|
|
72
|
+
export declare function asOptions<T extends TrackEntryPayload>(devtools?: T | null): MeasureOptionsWithDevtools<T>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const dataTypeTrackEntry = 'track-entry';
|
|
2
|
+
const dataTypeMarker = 'marker';
|
|
3
|
+
export function mergePropertiesWithOverwrite(baseProperties, overrideProperties) {
|
|
4
|
+
return [
|
|
5
|
+
...new Map([...(baseProperties ?? []), ...(overrideProperties ?? [])]),
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
export function markerPayload(options) {
|
|
9
|
+
return {
|
|
10
|
+
dataType: dataTypeMarker,
|
|
11
|
+
...options,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function trackEntryPayload(options) {
|
|
15
|
+
const { track, ...rest } = options;
|
|
16
|
+
return {
|
|
17
|
+
dataType: dataTypeTrackEntry,
|
|
18
|
+
track,
|
|
19
|
+
...rest,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function markerErrorPayload(options) {
|
|
23
|
+
return {
|
|
24
|
+
dataType: dataTypeMarker,
|
|
25
|
+
color: 'error',
|
|
26
|
+
...options,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function trackEntryErrorPayload(options) {
|
|
30
|
+
const { track, color = 'error', ...restOptions } = options;
|
|
31
|
+
return {
|
|
32
|
+
dataType: dataTypeTrackEntry,
|
|
33
|
+
color,
|
|
34
|
+
track,
|
|
35
|
+
...restOptions,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function errorToDevToolsProperties(e) {
|
|
39
|
+
const name = e instanceof Error ? e.name : 'UnknownError';
|
|
40
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
41
|
+
return [
|
|
42
|
+
['Error Type', name],
|
|
43
|
+
['Error Message', message],
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
export function errorToEntryMeta(e, options) {
|
|
47
|
+
const { properties, tooltipText } = options ?? {};
|
|
48
|
+
const props = mergePropertiesWithOverwrite(errorToDevToolsProperties(e), properties);
|
|
49
|
+
return {
|
|
50
|
+
properties: props,
|
|
51
|
+
...(tooltipText ? { tooltipText } : {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function errorToTrackEntryPayload(error, detail) {
|
|
55
|
+
const { properties, tooltipText, ...trackPayload } = detail;
|
|
56
|
+
return {
|
|
57
|
+
dataType: dataTypeTrackEntry,
|
|
58
|
+
color: 'error',
|
|
59
|
+
...trackPayload,
|
|
60
|
+
...errorToEntryMeta(error, {
|
|
61
|
+
properties,
|
|
62
|
+
tooltipText,
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function errorToMarkerPayload(error, detail) {
|
|
67
|
+
const { properties, tooltipText } = detail ?? {};
|
|
68
|
+
return {
|
|
69
|
+
dataType: dataTypeMarker,
|
|
70
|
+
color: 'error',
|
|
71
|
+
...errorToEntryMeta(error, {
|
|
72
|
+
properties,
|
|
73
|
+
tooltipText,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function asOptions(devtools) {
|
|
78
|
+
return devtools == null ? { detail: {} } : { detail: { devtools } };
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=user-timing-extensibility-api-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-timing-extensibility-api-utils.js","sourceRoot":"","sources":["../../../src/lib/user-timing-extensibility-api-utils.ts"],"names":[],"mappings":"AAWA,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC,MAAM,UAAU,4BAA4B,CAC1C,cAA8C,EAC9C,kBAAmD;IAEnD,OAAO;QACL,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC;KAC1C,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAyC;IACrE,OAAO;QACL,QAAQ,EAAE,cAAc;QACxB,GAAG,OAAO;KACa,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAA4C;IAE5C,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACnC,OAAO;QACL,QAAQ,EAAE,kBAAkB;QAC5B,KAAK;QACL,GAAG,IAAI;KACoB,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAAmD;IAEnD,OAAO;QACL,QAAQ,EAAE,cAAc;QACxB,KAAK,EAAE,OAAY;QACnB,GAAG,OAAO;KACa,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAIpC,OAGC;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAgB,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IACpE,OAAO;QACL,QAAQ,EAAE,kBAAkB;QAC5B,KAAK;QACL,KAAK;QACL,GAAG,WAAW;KACa,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,CAAU;IAClD,MAAM,IAAI,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAA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M,UAAU,SAAS,CACvB,QAAmB;IAInB,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { MarkOptions, MeasureOptions } from 'node:perf_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Color options for feedback states in DevTools.
|
|
4
|
+
* Used for error and warning states on marker and track entries.
|
|
5
|
+
* @example
|
|
6
|
+
* - 'error' - red
|
|
7
|
+
* - 'warning' - yellow
|
|
8
|
+
*/
|
|
9
|
+
export type DevToolsFeedbackColor = 'error' | 'warning';
|
|
10
|
+
/**
|
|
11
|
+
* Color options for action states in DevTools.
|
|
12
|
+
* Used for valid states on marker and track entries.
|
|
13
|
+
* @example
|
|
14
|
+
* - 'primary' - blue (default)
|
|
15
|
+
* - 'primary-dark' - dark blue
|
|
16
|
+
* - 'primary-light' - light blue
|
|
17
|
+
* - 'secondary' - purple
|
|
18
|
+
* - 'secondary-dark' - dark purple
|
|
19
|
+
* - 'secondary-light' - light purple
|
|
20
|
+
* - 'tertiary' - green
|
|
21
|
+
* - 'tertiary-dark' - dark green
|
|
22
|
+
* - 'tertiary-light' - light green
|
|
23
|
+
*/
|
|
24
|
+
export type DevToolsActionColor = 'primary' | 'primary-dark' | 'primary-light' | 'secondary' | 'secondary-dark' | 'secondary-light' | 'tertiary' | 'tertiary-dark' | 'tertiary-light';
|
|
25
|
+
/**
|
|
26
|
+
* Union type of all available DevTools color options.
|
|
27
|
+
*/
|
|
28
|
+
export type DevToolsColor = DevToolsFeedbackColor | DevToolsActionColor;
|
|
29
|
+
/**
|
|
30
|
+
* Array of key-value pairs for detailed DevTools properties.
|
|
31
|
+
*/
|
|
32
|
+
export type DevToolsProperties = [
|
|
33
|
+
key: string,
|
|
34
|
+
value: string | number | boolean | object | undefined
|
|
35
|
+
][];
|
|
36
|
+
/**
|
|
37
|
+
* EntryMeta is used to store metadata about a track entry.
|
|
38
|
+
* @property {string} [tooltipText] - Short description for tooltip on hover
|
|
39
|
+
* @property {DevToolsProperties} [properties] - Key-value pairs for detailed view on click.
|
|
40
|
+
* It provides better styling of values including features like automatic links rendering.
|
|
41
|
+
*/
|
|
42
|
+
export type EntryMeta = {
|
|
43
|
+
tooltipText?: string;
|
|
44
|
+
properties?: DevToolsProperties;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Styling options for track entries in DevTools.
|
|
48
|
+
* @property {DevToolsColor} [color] - rendered color of background and border, defaults to "primary"
|
|
49
|
+
*/
|
|
50
|
+
export type TrackStyle = {
|
|
51
|
+
color?: DevToolsColor;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Metadata for organizing track entries in DevTools.
|
|
55
|
+
* @property {string} track - Name of the custom track
|
|
56
|
+
* @property {string} [trackGroup] - Group for organizing tracks
|
|
57
|
+
*/
|
|
58
|
+
export type TrackMeta = {
|
|
59
|
+
track: string;
|
|
60
|
+
trackGroup?: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Base type combining entry metadata and styling for DevTools tracks.
|
|
64
|
+
*/
|
|
65
|
+
export type TrackBase = EntryMeta & TrackStyle;
|
|
66
|
+
/**
|
|
67
|
+
* Payload for track entries in DevTools Performance panel.
|
|
68
|
+
* @property {'track-entry'} [dataType] - Defaults to "track-entry"
|
|
69
|
+
*
|
|
70
|
+
* This type is visible in a custom track with name defined in `track` property.
|
|
71
|
+
*/
|
|
72
|
+
export type TrackEntryPayload = {
|
|
73
|
+
dataType?: 'track-entry';
|
|
74
|
+
} & TrackBase & TrackMeta;
|
|
75
|
+
/**
|
|
76
|
+
* Payload for marker entries in DevTools Performance panel.
|
|
77
|
+
* @property {'marker'} dataType - Identifies as a marker
|
|
78
|
+
* This type is visible as a marker on top of all tracks and in addition creates a vertical line spanning all lanes in the performance palen.
|
|
79
|
+
*/
|
|
80
|
+
export type MarkerPayload = {
|
|
81
|
+
dataType: 'marker';
|
|
82
|
+
} & TrackBase;
|
|
83
|
+
/**
|
|
84
|
+
* Utility type that forces a color property to be 'error'.
|
|
85
|
+
*/
|
|
86
|
+
export type WithErrorColor<T extends {
|
|
87
|
+
color?: DevToolsColor;
|
|
88
|
+
}> = Omit<T, 'color'> & {
|
|
89
|
+
color: 'error';
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Utility type that adds an optional devtools payload property.
|
|
93
|
+
*/
|
|
94
|
+
export type WithDevToolsPayload<T extends TrackEntryPayload | MarkerPayload> = {
|
|
95
|
+
devtools?: T;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Extended MarkOptions that supports DevTools payload in detail.
|
|
99
|
+
* @example
|
|
100
|
+
* const options: MarkOptionsWithDevtools = {
|
|
101
|
+
* detail: {
|
|
102
|
+
* devtools: {
|
|
103
|
+
* dataType: 'marker',
|
|
104
|
+
* color: 'error',
|
|
105
|
+
* },
|
|
106
|
+
* },
|
|
107
|
+
* }
|
|
108
|
+
* profiler.mark('start-program', options);
|
|
109
|
+
*/
|
|
110
|
+
export type MarkOptionsWithDevtools<T extends TrackEntryPayload | MarkerPayload> = {
|
|
111
|
+
detail?: WithDevToolsPayload<T>;
|
|
112
|
+
} & Omit<MarkOptions, 'detail'>;
|
|
113
|
+
/**
|
|
114
|
+
* Extended MeasureOptions that supports DevTools payload in detail.
|
|
115
|
+
* @example
|
|
116
|
+
* const options: MeasureOptionsWithDevtools = {
|
|
117
|
+
* detail: {
|
|
118
|
+
* devtools: {
|
|
119
|
+
* dataType: 'track-entry',
|
|
120
|
+
* color: 'primary',
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
* profiler.measure('load-program', 'start-program', 'end-program', options);
|
|
125
|
+
*/
|
|
126
|
+
export type MeasureOptionsWithDevtools<T extends TrackEntryPayload> = {
|
|
127
|
+
detail?: WithDevToolsPayload<T>;
|
|
128
|
+
} & Omit<MeasureOptions, 'detail'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-timing-extensibility-api.type.js","sourceRoot":"","sources":["../../../src/lib/user-timing-extensibility-api.type.ts"],"names":[],"mappings":""}
|