feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
// npx -y node@22.14 -e 'const {constants}=require("perf_hooks");console.log(Object.entries(Object.getOwnPropertyDescriptors(constants)).map(([k,v]) => `export const ${k} = ${JSON.stringify(v.value)}`).join("\n"))'
export declare const NODE_PERFORMANCE_GC_MAJOR = 4;
export declare const NODE_PERFORMANCE_GC_MINOR = 1;
export declare const NODE_PERFORMANCE_GC_INCREMENTAL = 8;
export declare const NODE_PERFORMANCE_GC_WEAKCB = 16;
export declare const NODE_PERFORMANCE_GC_FLAGS_NO = 0;
export declare const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED = 2;
export declare const NODE_PERFORMANCE_GC_FLAGS_FORCED = 4;
export declare const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING = 8;
export declare const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE = 16;
export declare const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY = 32;
export declare const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE = 64;
export declare const NODE_PERFORMANCE_ENTRY_TYPE_GC = 0;
export declare const NODE_PERFORMANCE_ENTRY_TYPE_HTTP = 1;
export declare const NODE_PERFORMANCE_ENTRY_TYPE_HTTP2 = 2;
export declare const NODE_PERFORMANCE_ENTRY_TYPE_NET = 3;
export declare const NODE_PERFORMANCE_ENTRY_TYPE_DNS = 4;
export declare const NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP = 0;
export declare const NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN = 1;
export declare const NODE_PERFORMANCE_MILESTONE_ENVIRONMENT = 2;
export declare const NODE_PERFORMANCE_MILESTONE_NODE_START = 3;
export declare const NODE_PERFORMANCE_MILESTONE_V8_START = 4;
export declare const NODE_PERFORMANCE_MILESTONE_LOOP_START = 5;
export declare const NODE_PERFORMANCE_MILESTONE_LOOP_EXIT = 6;
export declare const NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE = 7;

View File

@@ -0,0 +1,25 @@
// npx -y node@22.14 -e 'const {constants}=require("perf_hooks");console.log(Object.entries(Object.getOwnPropertyDescriptors(constants)).map(([k,v]) => `export const ${k} = ${JSON.stringify(v.value)}`).join("\n"))'
export const NODE_PERFORMANCE_GC_MAJOR = 4;
export const NODE_PERFORMANCE_GC_MINOR = 1;
export const NODE_PERFORMANCE_GC_INCREMENTAL = 8;
export const NODE_PERFORMANCE_GC_WEAKCB = 16;
export const NODE_PERFORMANCE_GC_FLAGS_NO = 0;
export const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED = 2;
export const NODE_PERFORMANCE_GC_FLAGS_FORCED = 4;
export const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING = 8;
export const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE = 16;
export const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY = 32;
export const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE = 64;
export const NODE_PERFORMANCE_ENTRY_TYPE_GC = 0;
export const NODE_PERFORMANCE_ENTRY_TYPE_HTTP = 1;
export const NODE_PERFORMANCE_ENTRY_TYPE_HTTP2 = 2;
export const NODE_PERFORMANCE_ENTRY_TYPE_NET = 3;
export const NODE_PERFORMANCE_ENTRY_TYPE_DNS = 4;
export const NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP = 0;
export const NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN = 1;
export const NODE_PERFORMANCE_MILESTONE_ENVIRONMENT = 2;
export const NODE_PERFORMANCE_MILESTONE_NODE_START = 3;
export const NODE_PERFORMANCE_MILESTONE_V8_START = 4;
export const NODE_PERFORMANCE_MILESTONE_LOOP_START = 5;
export const NODE_PERFORMANCE_MILESTONE_LOOP_EXIT = 6;
export const NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE = 7;

View File

@@ -0,0 +1,28 @@
import type nodePerfHooks from "node:perf_hooks";
declare class Histogram implements nodePerfHooks.Histogram {
min: number;
max: number;
mean;
exceeds: number;
stddev;
count: number;
countBigInt: bigint;
exceedsBigInt: bigint;
maxBigInt: number;
minBigInt: bigint;
percentiles: Map<number, number>;
percentilesBigInt: Map<bigint, bigint>;
percentileBigInt(_percentile: number): bigint;
percentile(percentile: number): number;
reset(): void;
}
export declare class IntervalHistogram extends Histogram implements nodePerfHooks.IntervalHistogram {
enable(): boolean;
disable(): boolean;
}
export declare class RecordableHistogram extends Histogram implements nodePerfHooks.RecordableHistogram {
record(val: number | bigint): void;
recordDelta(): void;
add(other: nodePerfHooks.RecordableHistogram): void;
}
export {};

View File

@@ -0,0 +1,43 @@
import { createNotImplementedError } from "../../../_internal/utils.mjs";
class Histogram {
min = 0x8000000000000000;
max = 0;
mean = Number.NaN;
exceeds = 0;
stddev = Number.NaN;
count = 0;
countBigInt = BigInt(0);
exceedsBigInt = BigInt(0);
maxBigInt = 0;
minBigInt = BigInt(9223372036854775807n);
percentiles = new Map();
percentilesBigInt = new Map();
percentileBigInt(_percentile) {
throw createNotImplementedError("Histogram.percentileBigInt");
}
percentile(percentile) {
return this.percentiles.get(percentile) ?? Number.NaN;
}
reset() {
throw createNotImplementedError("Histogram.reset");
}
}
export class IntervalHistogram extends Histogram {
enable() {
return true;
}
disable() {
return true;
}
}
export class RecordableHistogram extends Histogram {
record(val) {
throw createNotImplementedError("RecordableHistogram.record");
}
recordDelta() {
throw createNotImplementedError("RecordableHistogram.recordDelta");
}
add(other) {
throw createNotImplementedError("RecordableHistogram.add");
}
}

View File

@@ -0,0 +1,103 @@
import type nodePerfHooks from "node:perf_hooks";
// PerformanceEntry
export declare class PerformanceEntry implements nodePerfHooks.PerformanceEntry {
readonly __unenv__: true;
detail: any | undefined;
entryType: any;
name: string;
startTime: number;
constructor(name: string, options?: PerformanceMarkOptions);
get duration(): number;
toJSON(): {};
}
// PerformanceMark
export declare const PerformanceMark: typeof nodePerfHooks.PerformanceMark;
// PerformanceMark
export declare class PerformanceMeasure extends PerformanceEntry implements globalThis.PerformanceMeasure {
entryType: "measure";
}
// PerformanceResourceTiming
export declare class PerformanceResourceTiming extends PerformanceEntry implements globalThis.PerformanceResourceTiming {
entryType: "resource";
serverTiming: readonly PerformanceServerTiming[];
connectEnd: number;
connectStart: number;
decodedBodySize: number;
domainLookupEnd: number;
domainLookupStart: number;
encodedBodySize: number;
fetchStart: number;
initiatorType: string;
name: string;
nextHopProtocol: string;
redirectEnd: number;
redirectStart: number;
requestStart: number;
responseEnd: number;
responseStart: number;
secureConnectionStart: number;
startTime: number;
transferSize: number;
workerStart: number;
responseStatus: number;
}
// PerformanceObserverEntryList
export declare class PerformanceObserverEntryList implements globalThis.PerformanceObserverEntryList {
readonly __unenv__: true;
getEntries(): PerformanceEntryList;
getEntriesByName(_name: string, _type?: string | undefined): PerformanceEntryList;
getEntriesByType(type: string): PerformanceEntryList;
}
// Performance
export declare class Performance implements nodePerfHooks.Performance {
readonly __unenv__: true;
timeOrigin: number;
eventCounts: EventCounts;
_entries: PerformanceEntry[];
_resourceTimingBufferSize: number;
navigation: any;
timing: any;
timerify<T extends (...params: any[]) => any>(_fn: T, _options?: nodePerfHooks.TimerifyOptions | undefined): T;
get nodeTiming(): nodePerfHooks.PerformanceNodeTiming;
eventLoopUtilization(): nodePerfHooks.EventLoopUtilization;
markResourceTiming(): nodePerfHooks.PerformanceResourceTiming;
onresourcetimingbufferfull: ((this: Performance, ev: Event) => any) | null;
now(): number;
clearMarks(markName?: string | undefined): void;
clearMeasures(measureName?: string | undefined): void;
clearResourceTimings(): void;
getEntries(): any;
getEntriesByName(name: string, type?: string | undefined): any;
getEntriesByType(type: string): any[];
mark(name: string, options?: PerformanceMarkOptions | undefined): any;
measure(measureName: string, startOrMeasureOptions?: string | PerformanceMeasureOptions, endMark?: string);
setResourceTimingBufferSize(maxSize: number): void;
addEventListener<K extends "resourcetimingbufferfull">(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
removeEventListener<K extends "resourcetimingbufferfull">(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
toJSON();
}
// PerformanceObserver
export declare class PerformanceObserver implements nodePerfHooks.PerformanceObserver {
readonly __unenv__: true;
static supportedEntryTypes: ReadonlyArray<string>;
_callback: PerformanceObserverCallback | null;
constructor(callback: PerformanceObserverCallback);
takeRecords(): unknown;
disconnect(): void;
observe(options: any);
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
runInAsyncScope<
This,
Result
>(fn: (this: This, ...args: any[]) => Result, thisArg?: This | undefined, ...args: any[]);
asyncId(): number;
triggerAsyncId(): number;
emitDestroy(): this;
}
// workerd implements a subset of globalThis.performance (as of last check, only timeOrigin set to 0 + now() implemented)
// We already use performance.now() from globalThis.performance, if provided (see top of this file)
// If we detect this condition, we can just use polyfill instead.
export declare const performance: unknown;

View File

@@ -0,0 +1,232 @@
import { createNotImplementedError } from "../../../_internal/utils.mjs";
const _timeOrigin = globalThis.performance?.timeOrigin ?? Date.now();
const _performanceNow = globalThis.performance?.now ? globalThis.performance.now.bind(globalThis.performance) : () => Date.now() - _timeOrigin;
const nodeTiming = {
name: "node",
entryType: "node",
startTime: 0,
duration: 0,
nodeStart: 0,
v8Start: 0,
bootstrapComplete: 0,
environment: 0,
loopStart: 0,
loopExit: 0,
idleTime: 0,
uvMetricsInfo: {
loopCount: 0,
events: 0,
eventsWaiting: 0
},
detail: undefined,
toJSON() {
return this;
}
};
// PerformanceEntry
export class PerformanceEntry {
__unenv__ = true;
detail;
entryType = "event";
name;
startTime;
constructor(name, options) {
this.name = name;
this.startTime = options?.startTime || _performanceNow();
this.detail = options?.detail;
}
get duration() {
return _performanceNow() - this.startTime;
}
toJSON() {
return {
name: this.name,
entryType: this.entryType,
startTime: this.startTime,
duration: this.duration,
detail: this.detail
};
}
}
// PerformanceMark
export const PerformanceMark = class PerformanceMark extends PerformanceEntry {
entryType = "mark";
constructor() {
// @ts-ignore
super(...arguments);
}
get duration() {
return 0;
}
};
// PerformanceMark
export class PerformanceMeasure extends PerformanceEntry {
entryType = "measure";
}
// PerformanceResourceTiming
export class PerformanceResourceTiming extends PerformanceEntry {
entryType = "resource";
serverTiming = [];
connectEnd = 0;
connectStart = 0;
decodedBodySize = 0;
domainLookupEnd = 0;
domainLookupStart = 0;
encodedBodySize = 0;
fetchStart = 0;
initiatorType = "";
name = "";
nextHopProtocol = "";
redirectEnd = 0;
redirectStart = 0;
requestStart = 0;
responseEnd = 0;
responseStart = 0;
secureConnectionStart = 0;
startTime = 0;
transferSize = 0;
workerStart = 0;
responseStatus = 0;
}
// PerformanceObserverEntryList
export class PerformanceObserverEntryList {
__unenv__ = true;
getEntries() {
return [];
}
getEntriesByName(_name, _type) {
return [];
}
getEntriesByType(type) {
return [];
}
}
// Performance
export class Performance {
__unenv__ = true;
timeOrigin = _timeOrigin;
eventCounts = new Map();
_entries = [];
_resourceTimingBufferSize = 0;
navigation = undefined;
timing = undefined;
timerify(_fn, _options) {
throw createNotImplementedError("Performance.timerify");
}
get nodeTiming() {
return nodeTiming;
}
eventLoopUtilization() {
return {};
}
markResourceTiming() {
// TODO: create a new PerformanceResourceTiming entry
// so that performance.getEntries, getEntriesByName, and getEntriesByType return it
// see: https://nodejs.org/api/perf_hooks.html#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode-bodyinfo-responsestatus-deliverytype
return new PerformanceResourceTiming("");
}
onresourcetimingbufferfull = null;
now() {
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
if (this.timeOrigin === _timeOrigin) {
return _performanceNow();
}
return Date.now() - this.timeOrigin;
}
clearMarks(markName) {
this._entries = markName ? this._entries.filter((e) => e.name !== markName) : this._entries.filter((e) => e.entryType !== "mark");
}
clearMeasures(measureName) {
this._entries = measureName ? this._entries.filter((e) => e.name !== measureName) : this._entries.filter((e) => e.entryType !== "measure");
}
clearResourceTimings() {
this._entries = this._entries.filter((e) => e.entryType !== "resource" || e.entryType !== "navigation");
}
getEntries() {
return this._entries;
}
getEntriesByName(name, type) {
return this._entries.filter((e) => e.name === name && (!type || e.entryType === type));
}
getEntriesByType(type) {
return this._entries.filter((e) => e.entryType === type);
}
mark(name, options) {
// @ts-expect-error constructor is not protected
const entry = new PerformanceMark(name, options);
this._entries.push(entry);
return entry;
}
measure(measureName, startOrMeasureOptions, endMark) {
let start;
let end;
if (typeof startOrMeasureOptions === "string") {
start = this.getEntriesByName(startOrMeasureOptions, "mark")[0]?.startTime;
end = this.getEntriesByName(endMark, "mark")[0]?.startTime;
} else {
start = Number.parseFloat(startOrMeasureOptions?.start) || this.now();
end = Number.parseFloat(startOrMeasureOptions?.end) || this.now();
}
const entry = new PerformanceMeasure(measureName, {
startTime: start,
detail: {
start,
end
}
});
this._entries.push(entry);
return entry;
}
setResourceTimingBufferSize(maxSize) {
this._resourceTimingBufferSize = maxSize;
}
addEventListener(type, listener, options) {
throw createNotImplementedError("Performance.addEventListener");
}
removeEventListener(type, listener, options) {
throw createNotImplementedError("Performance.removeEventListener");
}
dispatchEvent(event) {
throw createNotImplementedError("Performance.dispatchEvent");
}
toJSON() {
return this;
}
}
// PerformanceObserver
export class PerformanceObserver {
__unenv__ = true;
static supportedEntryTypes = [];
_callback = null;
constructor(callback) {
this._callback = callback;
}
takeRecords() {
return [];
}
disconnect() {
throw createNotImplementedError("PerformanceObserver.disconnect");
}
observe(options) {
throw createNotImplementedError("PerformanceObserver.observe");
}
bind(fn) {
return fn;
}
runInAsyncScope(fn, thisArg, ...args) {
return fn.call(thisArg, ...args);
}
asyncId() {
return 0;
}
triggerAsyncId() {
return 0;
}
emitDestroy() {
return this;
}
}
// workerd implements a subset of globalThis.performance (as of last check, only timeOrigin set to 0 + now() implemented)
// We already use performance.now() from globalThis.performance, if provided (see top of this file)
// If we detect this condition, we can just use polyfill instead.
export const performance = globalThis.performance && "addEventListener" in globalThis.performance ? globalThis.performance : new Performance();