@code-pushup/utils 0.109.0 → 0.110.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/performance-observer.d.ts +3 -3
- package/src/lib/performance-observer.js +1 -1
- package/src/lib/performance-observer.js.map +1 -1
- package/src/lib/profiler/constants.d.ts +5 -0
- package/src/lib/profiler/constants.js +5 -0
- package/src/lib/profiler/constants.js.map +1 -1
- package/src/lib/profiler/profiler.d.ts +6 -0
- package/src/lib/profiler/profiler.js +10 -0
- package/src/lib/profiler/profiler.js.map +1 -1
- package/src/lib/{trace-file-utils.d.ts → profiler/trace-file-utils.d.ts} +52 -2
- package/src/lib/{trace-file-utils.js → profiler/trace-file-utils.js} +120 -9
- package/src/lib/profiler/trace-file-utils.js.map +1 -0
- package/src/lib/{trace-file.type.d.ts → profiler/trace-file.type.d.ts} +6 -2
- package/src/lib/profiler/trace-file.type.js.map +1 -0
- package/src/lib/profiler/wal-json-trace.d.ts +25 -0
- package/src/lib/profiler/wal-json-trace.js +77 -0
- package/src/lib/profiler/wal-json-trace.js.map +1 -0
- package/src/lib/wal.d.ts +236 -0
- package/src/lib/wal.js +411 -0
- package/src/lib/wal.js.map +1 -0
- package/src/lib/sink-source.type.d.ts +0 -43
- package/src/lib/sink-source.type.js +0 -2
- package/src/lib/sink-source.type.js.map +0 -1
- package/src/lib/trace-file-utils.js.map +0 -1
- package/src/lib/trace-file.type.js.map +0 -1
- /package/src/lib/{trace-file.type.js → profiler/trace-file.type.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.110.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": ">=18.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@code-pushup/models": "0.
|
|
30
|
+
"@code-pushup/models": "0.110.0",
|
|
31
31
|
"ansis": "^3.3.0",
|
|
32
32
|
"build-md": "^0.4.2",
|
|
33
33
|
"bundle-require": "^5.1.0",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type PerformanceEntry } from 'node:perf_hooks';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AppendableSink } from './wal.js';
|
|
3
3
|
export declare const DEFAULT_FLUSH_THRESHOLD = 20;
|
|
4
4
|
export type PerformanceObserverOptions<T> = {
|
|
5
|
-
sink:
|
|
5
|
+
sink: AppendableSink<T>;
|
|
6
6
|
encode: (entry: PerformanceEntry) => T[];
|
|
7
7
|
buffered?: boolean;
|
|
8
8
|
flushThreshold?: number;
|
|
9
9
|
};
|
|
10
|
-
export declare class PerformanceObserverSink<T>
|
|
10
|
+
export declare class PerformanceObserverSink<T> {
|
|
11
11
|
#private;
|
|
12
12
|
constructor(options: PerformanceObserverOptions<T>);
|
|
13
13
|
encode(entry: PerformanceEntry): T[];
|
|
@@ -48,7 +48,7 @@ export class PerformanceObserverSink {
|
|
|
48
48
|
try {
|
|
49
49
|
fresh
|
|
50
50
|
.flatMap(entry => this.encode(entry))
|
|
51
|
-
.forEach(item => this.#sink.
|
|
51
|
+
.forEach(item => this.#sink.append(item));
|
|
52
52
|
this.#written.set(t, written + fresh.length);
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performance-observer.js","sourceRoot":"","sources":["../../../src/lib/performance-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEnB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,SAAS,CAAU,CAAC;AAEpD,MAAM,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AE,KAAK,EAAE,CACjB,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IACzB,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"}
|
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare const PROFILER_ENABLED_ENV_VAR = "CP_PROFILING";
|
|
2
|
+
export declare const PROFILER_COORDINATOR_FLAG_ENV_VAR = "CP_PROFILER_COORDINATOR";
|
|
3
|
+
export declare const PROFILER_ORIGIN_PID_ENV_VAR = "CP_PROFILER_ORIGIN_PID";
|
|
4
|
+
export declare const PROFILER_DIRECTORY_ENV_VAR = "CP_PROFILER_DIR";
|
|
5
|
+
export declare const PROFILER_BASE_NAME = "trace";
|
|
6
|
+
export declare const PROFILER_DIRECTORY = "./tmp/profiles";
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export const PROFILER_ENABLED_ENV_VAR = 'CP_PROFILING';
|
|
2
|
+
export const PROFILER_COORDINATOR_FLAG_ENV_VAR = 'CP_PROFILER_COORDINATOR';
|
|
3
|
+
export const PROFILER_ORIGIN_PID_ENV_VAR = 'CP_PROFILER_ORIGIN_PID';
|
|
4
|
+
export const PROFILER_DIRECTORY_ENV_VAR = 'CP_PROFILER_DIR';
|
|
5
|
+
export const PROFILER_BASE_NAME = 'trace';
|
|
6
|
+
export const PROFILER_DIRECTORY = './tmp/profiles';
|
|
2
7
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/profiler/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/profiler/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,iCAAiC,GAAG,yBAAyB,CAAC;AAC3E,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,iBAAiB,CAAC;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type ActionTrackConfigs, type MeasureCtxOptions, type MeasureOptions } from '../user-timing-extensibility-api-utils.js';
|
|
2
2
|
import type { ActionTrackEntryPayload, DevToolsColor, EntryMeta } from '../user-timing-extensibility-api.type.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a unique profiler ID based on performance time origin, process ID, thread ID, and instance count.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getProfilerId(): string;
|
|
3
7
|
/**
|
|
4
8
|
* Configuration options for creating a Profiler instance.
|
|
5
9
|
*
|
|
@@ -41,6 +45,8 @@ export type ProfilerOptions<T extends ActionTrackConfigs = ActionTrackConfigs> =
|
|
|
41
45
|
*/
|
|
42
46
|
export declare class Profiler<T extends ActionTrackConfigs> {
|
|
43
47
|
#private;
|
|
48
|
+
static instanceCount: number;
|
|
49
|
+
readonly id: string;
|
|
44
50
|
readonly tracks: Record<keyof T, ActionTrackEntryPayload> | undefined;
|
|
45
51
|
/**
|
|
46
52
|
* Creates a new Profiler instance with the specified configuration.
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
+
import { threadId } from 'node:worker_threads';
|
|
2
3
|
import { isEnvVarEnabled } from '../env.js';
|
|
3
4
|
import { asOptions, markerPayload, measureCtx, setupTracks, } from '../user-timing-extensibility-api-utils.js';
|
|
4
5
|
import { PROFILER_ENABLED_ENV_VAR } from './constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generates a unique profiler ID based on performance time origin, process ID, thread ID, and instance count.
|
|
8
|
+
*/
|
|
9
|
+
export function getProfilerId() {
|
|
10
|
+
// eslint-disable-next-line functional/immutable-data
|
|
11
|
+
return `${Math.round(performance.timeOrigin)}.${process.pid}.${threadId}.${++Profiler.instanceCount}`;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Performance profiler that creates structured timing measurements with Chrome DevTools Extensibility API payloads.
|
|
7
15
|
*
|
|
@@ -10,6 +18,8 @@ import { PROFILER_ENABLED_ENV_VAR } from './constants.js';
|
|
|
10
18
|
*
|
|
11
19
|
*/
|
|
12
20
|
export class Profiler {
|
|
21
|
+
static instanceCount = 0;
|
|
22
|
+
id = getProfilerId();
|
|
13
23
|
#enabled;
|
|
14
24
|
#defaults;
|
|
15
25
|
tracks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../../../src/lib/profiler/profiler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAIL,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,2CAA2C,CAAC;AAMnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../../../src/lib/profiler/profiler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C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AI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,CAAC,CAAC;YACX,OAAO,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC;YACd,MAAM,MAAM,CAAC;QACf,CAAC;IACH,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { PerformanceMark, PerformanceMeasure } from 'node:perf_hooks';
|
|
2
|
-
import type {
|
|
1
|
+
import type { PerformanceEntry, PerformanceMark, PerformanceMeasure } from 'node:perf_hooks';
|
|
2
|
+
import type { UserTimingDetail } from '../user-timing-extensibility-api.type.js';
|
|
3
|
+
import type { BeginEvent, CompleteEvent, EndEvent, InstantEvent, InstantEventArgs, InstantEventTracingStartedInBrowser, SpanEventArgs, TraceEvent, TraceEventContainer, TraceEventRaw, TraceMetadata, UserTimingTraceEvent } from './trace-file.type.js';
|
|
3
4
|
/**
|
|
4
5
|
* Generates a unique ID for linking begin and end span events in Chrome traces.
|
|
5
6
|
* @returns Object with local ID string for the id2 field
|
|
@@ -121,6 +122,26 @@ export declare const measureToSpanEvents: (entry: PerformanceMeasure, opt?: {
|
|
|
121
122
|
pid?: number;
|
|
122
123
|
tid?: number;
|
|
123
124
|
}) => [BeginEvent, EndEvent];
|
|
125
|
+
/**
|
|
126
|
+
* Converts a PerformanceEntry to an array of UserTimingTraceEvents.
|
|
127
|
+
* A mark is converted to an instant event, and a measure is converted to a pair of span events.
|
|
128
|
+
* Other entry types are ignored.
|
|
129
|
+
* @param entry - Performance entry
|
|
130
|
+
* @returns UserTimingTraceEvent[]
|
|
131
|
+
*/
|
|
132
|
+
export declare function entryToTraceEvents(entry: PerformanceEntry): UserTimingTraceEvent[];
|
|
133
|
+
/**
|
|
134
|
+
* Creates trace metadata object with standard DevTools fields and custom metadata.
|
|
135
|
+
* @param startDate - Optional start date for the trace, defaults to current date
|
|
136
|
+
* @param metadata - Optional additional metadata to merge into the trace metadata
|
|
137
|
+
* @returns TraceMetadata object with source, startTime, and merged custom metadata
|
|
138
|
+
*/
|
|
139
|
+
export declare function getTraceMetadata(startDate?: Date, metadata?: Record<string, unknown>): {
|
|
140
|
+
source: string;
|
|
141
|
+
startTime: string;
|
|
142
|
+
hardwareConcurrency: number;
|
|
143
|
+
dataOrigin: string;
|
|
144
|
+
};
|
|
124
145
|
/**
|
|
125
146
|
* Creates a complete trace file container with metadata.
|
|
126
147
|
* @param opt - Trace file configuration
|
|
@@ -129,5 +150,34 @@ export declare const measureToSpanEvents: (entry: PerformanceMeasure, opt?: {
|
|
|
129
150
|
export declare const getTraceFile: (opt: {
|
|
130
151
|
traceEvents: TraceEvent[];
|
|
131
152
|
startTime?: string;
|
|
153
|
+
metadata?: Partial<TraceMetadata>;
|
|
132
154
|
}) => TraceEventContainer;
|
|
155
|
+
/**
|
|
156
|
+
* Decodes a JSON string detail property back to its original object form.
|
|
157
|
+
* @param target - Object containing a detail property as a JSON string
|
|
158
|
+
* @returns UserTimingDetail with the detail property parsed from JSON
|
|
159
|
+
*/
|
|
160
|
+
export declare function decodeDetail(target: {
|
|
161
|
+
detail: string;
|
|
162
|
+
}): UserTimingDetail;
|
|
163
|
+
/**
|
|
164
|
+
* Encodes object detail properties to JSON strings for storage/transmission.
|
|
165
|
+
* @param target - UserTimingDetail object with detail property to encode
|
|
166
|
+
* @returns UserTimingDetail with object details converted to JSON strings
|
|
167
|
+
*/
|
|
168
|
+
export declare function encodeDetail(target: UserTimingDetail): UserTimingDetail;
|
|
169
|
+
/**
|
|
170
|
+
* Decodes a raw trace event with JSON string details back to typed UserTimingTraceEvent.
|
|
171
|
+
* Parses detail properties from JSON strings to objects.
|
|
172
|
+
* @param event - Raw trace event with string-encoded details
|
|
173
|
+
* @returns UserTimingTraceEvent with parsed detail objects
|
|
174
|
+
*/
|
|
175
|
+
export declare function decodeTraceEvent({ args, ...rest }: TraceEventRaw): UserTimingTraceEvent;
|
|
176
|
+
/**
|
|
177
|
+
* Encodes a UserTimingTraceEvent to raw format with JSON string details.
|
|
178
|
+
* Converts object details to JSON strings for storage/transmission.
|
|
179
|
+
* @param event - UserTimingTraceEvent with object details
|
|
180
|
+
* @returns TraceEventRaw with string-encoded details
|
|
181
|
+
*/
|
|
182
|
+
export declare function encodeTraceEvent({ args, ...rest }: UserTimingTraceEvent): TraceEventRaw;
|
|
133
183
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
1
|
import { threadId } from 'node:worker_threads';
|
|
3
|
-
import { defaultClock } from '
|
|
2
|
+
import { defaultClock } from '../clock-epoch.js';
|
|
4
3
|
/** Global counter for generating unique span IDs within a trace */
|
|
5
4
|
// eslint-disable-next-line functional/no-let
|
|
6
5
|
let id2Count = 0;
|
|
@@ -11,8 +10,11 @@ let id2Count = 0;
|
|
|
11
10
|
export const nextId2 = () => ({ local: `0x${++id2Count}` });
|
|
12
11
|
/**
|
|
13
12
|
* Provides default values for trace event properties.
|
|
14
|
-
* @param opt - Optional overrides for
|
|
15
|
-
* @
|
|
13
|
+
* @param opt - Optional overrides for process ID, thread ID, and timestamp
|
|
14
|
+
* @param opt.pid - Process ID override, defaults to current process PID
|
|
15
|
+
* @param opt.tid - Thread ID override, defaults to current thread ID
|
|
16
|
+
* @param opt.ts - Timestamp override in microseconds, defaults to current epoch time
|
|
17
|
+
* @returns Object containing pid, tid, and ts with defaults applied
|
|
16
18
|
*/
|
|
17
19
|
const defaults = (opt) => ({
|
|
18
20
|
pid: opt?.pid ?? process.pid,
|
|
@@ -162,6 +164,37 @@ export const measureToSpanEvents = (entry, opt) => getSpan({
|
|
|
162
164
|
tsE: defaultClock.fromEntry(entry, true),
|
|
163
165
|
args: entry.detail ? { data: { detail: entry.detail } } : undefined,
|
|
164
166
|
});
|
|
167
|
+
/**
|
|
168
|
+
* Converts a PerformanceEntry to an array of UserTimingTraceEvents.
|
|
169
|
+
* A mark is converted to an instant event, and a measure is converted to a pair of span events.
|
|
170
|
+
* Other entry types are ignored.
|
|
171
|
+
* @param entry - Performance entry
|
|
172
|
+
* @returns UserTimingTraceEvent[]
|
|
173
|
+
*/
|
|
174
|
+
export function entryToTraceEvents(entry) {
|
|
175
|
+
if (entry.entryType === 'mark') {
|
|
176
|
+
return [markToInstantEvent(entry)];
|
|
177
|
+
}
|
|
178
|
+
if (entry.entryType === 'measure') {
|
|
179
|
+
return measureToSpanEvents(entry);
|
|
180
|
+
}
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Creates trace metadata object with standard DevTools fields and custom metadata.
|
|
185
|
+
* @param startDate - Optional start date for the trace, defaults to current date
|
|
186
|
+
* @param metadata - Optional additional metadata to merge into the trace metadata
|
|
187
|
+
* @returns TraceMetadata object with source, startTime, and merged custom metadata
|
|
188
|
+
*/
|
|
189
|
+
export function getTraceMetadata(startDate, metadata) {
|
|
190
|
+
return {
|
|
191
|
+
source: 'DevTools',
|
|
192
|
+
startTime: startDate?.toISOString() ?? new Date().toISOString(),
|
|
193
|
+
hardwareConcurrency: 1,
|
|
194
|
+
dataOrigin: 'TraceEvents',
|
|
195
|
+
...metadata,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
165
198
|
/**
|
|
166
199
|
* Creates a complete trace file container with metadata.
|
|
167
200
|
* @param opt - Trace file configuration
|
|
@@ -170,10 +203,88 @@ export const measureToSpanEvents = (entry, opt) => getSpan({
|
|
|
170
203
|
export const getTraceFile = (opt) => ({
|
|
171
204
|
traceEvents: opt.traceEvents,
|
|
172
205
|
displayTimeUnit: 'ms',
|
|
173
|
-
metadata:
|
|
174
|
-
source: 'Node.js UserTiming',
|
|
175
|
-
startTime: opt.startTime ?? new Date().toISOString(),
|
|
176
|
-
hardwareConcurrency: os.cpus().length,
|
|
177
|
-
},
|
|
206
|
+
metadata: getTraceMetadata(opt.startTime ? new Date(opt.startTime) : new Date(), opt.metadata),
|
|
178
207
|
});
|
|
208
|
+
/**
|
|
209
|
+
* Processes the detail property of an object using a custom processor function.
|
|
210
|
+
* @template T - Object type that may contain a detail property
|
|
211
|
+
* @param target - Object containing the detail property to process
|
|
212
|
+
* @param processor - Function to transform the detail value
|
|
213
|
+
* @returns New object with processed detail property, or original object if no detail
|
|
214
|
+
*/
|
|
215
|
+
function processDetail(target, processor) {
|
|
216
|
+
if (target.detail != null &&
|
|
217
|
+
(typeof target.detail === 'string' || typeof target.detail === 'object')) {
|
|
218
|
+
return { ...target, detail: processor(target.detail) };
|
|
219
|
+
}
|
|
220
|
+
return target;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Decodes a JSON string detail property back to its original object form.
|
|
224
|
+
* @param target - Object containing a detail property as a JSON string
|
|
225
|
+
* @returns UserTimingDetail with the detail property parsed from JSON
|
|
226
|
+
*/
|
|
227
|
+
export function decodeDetail(target) {
|
|
228
|
+
return processDetail(target, detail => typeof detail === 'string'
|
|
229
|
+
? JSON.parse(detail)
|
|
230
|
+
: detail);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Encodes object detail properties to JSON strings for storage/transmission.
|
|
234
|
+
* @param target - UserTimingDetail object with detail property to encode
|
|
235
|
+
* @returns UserTimingDetail with object details converted to JSON strings
|
|
236
|
+
*/
|
|
237
|
+
export function encodeDetail(target) {
|
|
238
|
+
return processDetail(target, (detail) => typeof detail === 'object'
|
|
239
|
+
? JSON.stringify(detail)
|
|
240
|
+
: detail);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Decodes a raw trace event with JSON string details back to typed UserTimingTraceEvent.
|
|
244
|
+
* Parses detail properties from JSON strings to objects.
|
|
245
|
+
* @param event - Raw trace event with string-encoded details
|
|
246
|
+
* @returns UserTimingTraceEvent with parsed detail objects
|
|
247
|
+
*/
|
|
248
|
+
export function decodeTraceEvent({ args, ...rest }) {
|
|
249
|
+
if (!args) {
|
|
250
|
+
return rest;
|
|
251
|
+
}
|
|
252
|
+
const processedArgs = decodeDetail(args);
|
|
253
|
+
if ('data' in args && args.data && typeof args.data === 'object') {
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
255
|
+
return {
|
|
256
|
+
...rest,
|
|
257
|
+
args: {
|
|
258
|
+
...processedArgs,
|
|
259
|
+
data: decodeDetail(args.data),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
264
|
+
return { ...rest, args: processedArgs };
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Encodes a UserTimingTraceEvent to raw format with JSON string details.
|
|
268
|
+
* Converts object details to JSON strings for storage/transmission.
|
|
269
|
+
* @param event - UserTimingTraceEvent with object details
|
|
270
|
+
* @returns TraceEventRaw with string-encoded details
|
|
271
|
+
*/
|
|
272
|
+
export function encodeTraceEvent({ args, ...rest }) {
|
|
273
|
+
if (!args) {
|
|
274
|
+
return rest;
|
|
275
|
+
}
|
|
276
|
+
const processedArgs = encodeDetail(args);
|
|
277
|
+
if ('data' in args && args.data && typeof args.data === 'object') {
|
|
278
|
+
const result = {
|
|
279
|
+
...rest,
|
|
280
|
+
args: {
|
|
281
|
+
...processedArgs,
|
|
282
|
+
data: encodeDetail(args.data),
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
const result = { ...rest, args: processedArgs };
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
179
290
|
//# sourceMappingURL=trace-file-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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I,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjE,yEAAyE;QACzE,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE;gBACJ,GAAG,aAAa;gBAChB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAA0B,CAAC;aACpD;SACsB,CAAC;IAC5B,CAAC;IACD,yEAAyE;IACzE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,aAAa,EAA0B,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,GAAG,IAAI,EACc;IACrB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAqB,CAAC;IAC/B,CAAC;IAED,MAAM,aAAa,GAAG,YAAY,CAAC,IAAwB,CAAC,CAAC;IAC7D,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjE,MAAM,MAAM,GAAkB;YAC5B,GAAG,IAAI;YACP,IAAI,EAAE;gBACJ,GAAG,aAAa;gBAChB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAAwB,CAAC;aAClD;SACF,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAkB,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UserTimingDetail } from '
|
|
1
|
+
import type { UserTimingDetail } from '../user-timing-extensibility-api.type.js';
|
|
2
2
|
/**
|
|
3
3
|
* Arguments for instant trace events.
|
|
4
4
|
* @property {UserTimingDetail} [detail] - Optional user timing detail with DevTools payload
|
|
@@ -139,7 +139,11 @@ export type SpanEvent = BeginEvent | EndEvent;
|
|
|
139
139
|
/**
|
|
140
140
|
* Union type of all trace event types.
|
|
141
141
|
*/
|
|
142
|
-
export type
|
|
142
|
+
export type UserTimingTraceEvent = InstantEvent | SpanEvent;
|
|
143
|
+
/**
|
|
144
|
+
* All trace events including system events added during finalization.
|
|
145
|
+
*/
|
|
146
|
+
export type TraceEvent = UserTimingTraceEvent | CompleteEvent | InstantEventTracingStartedInBrowser;
|
|
143
147
|
/**
|
|
144
148
|
* Raw arguments format for trace events before processing.
|
|
145
149
|
* Either contains a detail string directly or nested in a data object.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-file.type.js","sourceRoot":"","sources":["../../../../src/lib/profiler/trace-file.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InvalidEntry } from '../wal.js';
|
|
2
|
+
import type { UserTimingTraceEvent } from './trace-file.type.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a complete Chrome DevTools trace file content as JSON string.
|
|
5
|
+
* Adds margin events around the trace events and includes metadata.
|
|
6
|
+
* @param events - Array of user timing trace events to include
|
|
7
|
+
* @param metadata - Optional custom metadata to include in the trace file
|
|
8
|
+
* @returns JSON string representation of the complete trace file
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateTraceContent(events: UserTimingTraceEvent[], metadata?: Record<string, unknown>): string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a WAL (Write-Ahead Logging) format configuration for Chrome DevTools trace files.
|
|
13
|
+
* Automatically finalizes shards into complete trace files with proper metadata and margin events.
|
|
14
|
+
* @returns WalFormat configuration object with baseName, codec, extensions, and finalizer
|
|
15
|
+
*/
|
|
16
|
+
export declare function traceEventWalFormat(): {
|
|
17
|
+
baseName: string;
|
|
18
|
+
walExtension: string;
|
|
19
|
+
finalExtension: string;
|
|
20
|
+
codec: {
|
|
21
|
+
encode: (event: UserTimingTraceEvent) => string;
|
|
22
|
+
decode: (json: string) => UserTimingTraceEvent;
|
|
23
|
+
};
|
|
24
|
+
finalizer: (records: (UserTimingTraceEvent | InvalidEntry<string>)[], metadata?: Record<string, unknown>) => string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { defaultClock } from '../clock-epoch.js';
|
|
2
|
+
import { decodeTraceEvent, encodeTraceEvent, getCompleteEvent, getInstantEventTracingStartedInBrowser, getTraceFile, } from './trace-file-utils.js';
|
|
3
|
+
/** Name for the trace start margin event */
|
|
4
|
+
const TRACE_START_MARGIN_NAME = '[trace padding start]';
|
|
5
|
+
/** Name for the trace end margin event */
|
|
6
|
+
const TRACE_END_MARGIN_NAME = '[trace padding end]';
|
|
7
|
+
/** Microseconds of padding to add before/after trace events (1000ms = 1,000,000μs) */
|
|
8
|
+
const TRACE_MARGIN_US = 1_000_000;
|
|
9
|
+
/** Duration in microseconds for margin events (20ms = 20,000μs) */
|
|
10
|
+
const TRACE_MARGIN_DURATION_US = 20_000;
|
|
11
|
+
/**
|
|
12
|
+
* Generates a complete Chrome DevTools trace file content as JSON string.
|
|
13
|
+
* Adds margin events around the trace events and includes metadata.
|
|
14
|
+
* @param events - Array of user timing trace events to include
|
|
15
|
+
* @param metadata - Optional custom metadata to include in the trace file
|
|
16
|
+
* @returns JSON string representation of the complete trace file
|
|
17
|
+
*/
|
|
18
|
+
export function generateTraceContent(events, metadata) {
|
|
19
|
+
const traceContainer = getTraceFile({
|
|
20
|
+
traceEvents: events,
|
|
21
|
+
startTime: new Date().toISOString(),
|
|
22
|
+
metadata: {
|
|
23
|
+
...metadata,
|
|
24
|
+
generatedAt: new Date().toISOString(),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const marginUs = TRACE_MARGIN_US;
|
|
28
|
+
const marginDurUs = TRACE_MARGIN_DURATION_US;
|
|
29
|
+
const sortedEvents = [...events].sort((a, b) => a.ts - b.ts);
|
|
30
|
+
const fallbackTs = defaultClock.epochNowUs();
|
|
31
|
+
const firstTs = sortedEvents.at(0)?.ts ?? fallbackTs;
|
|
32
|
+
const lastTs = sortedEvents.at(-1)?.ts ?? fallbackTs;
|
|
33
|
+
const startTs = firstTs - marginUs;
|
|
34
|
+
const endTs = lastTs + marginUs;
|
|
35
|
+
const traceEvents = [
|
|
36
|
+
getInstantEventTracingStartedInBrowser({
|
|
37
|
+
ts: startTs,
|
|
38
|
+
url: events.length === 0 ? 'empty-trace' : 'generated-trace',
|
|
39
|
+
}),
|
|
40
|
+
getCompleteEvent({
|
|
41
|
+
name: TRACE_START_MARGIN_NAME,
|
|
42
|
+
ts: startTs,
|
|
43
|
+
dur: marginDurUs,
|
|
44
|
+
}),
|
|
45
|
+
...sortedEvents,
|
|
46
|
+
getCompleteEvent({
|
|
47
|
+
name: TRACE_END_MARGIN_NAME,
|
|
48
|
+
ts: endTs,
|
|
49
|
+
dur: marginDurUs,
|
|
50
|
+
}),
|
|
51
|
+
];
|
|
52
|
+
return JSON.stringify({ ...traceContainer, traceEvents });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a WAL (Write-Ahead Logging) format configuration for Chrome DevTools trace files.
|
|
56
|
+
* Automatically finalizes shards into complete trace files with proper metadata and margin events.
|
|
57
|
+
* @returns WalFormat configuration object with baseName, codec, extensions, and finalizer
|
|
58
|
+
*/
|
|
59
|
+
export function traceEventWalFormat() {
|
|
60
|
+
const baseName = 'trace';
|
|
61
|
+
const walExtension = '.jsonl';
|
|
62
|
+
const finalExtension = '.json';
|
|
63
|
+
return {
|
|
64
|
+
baseName,
|
|
65
|
+
walExtension,
|
|
66
|
+
finalExtension,
|
|
67
|
+
codec: {
|
|
68
|
+
encode: (event) => JSON.stringify(encodeTraceEvent(event)),
|
|
69
|
+
decode: (json) => decodeTraceEvent(JSON.parse(json)),
|
|
70
|
+
},
|
|
71
|
+
finalizer: (records, metadata) => {
|
|
72
|
+
const validRecords = records.filter((r) => !(typeof r === 'object' && r != null && '__invalid' in r));
|
|
73
|
+
return generateTraceContent(validRecords, metadata);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=wal-json-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wal-json-trace.js","sourceRoot":"","sources":["../../../../src/lib/profiler/wal-json-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,sCAAsC,EACtC,YAAY,GACb,MAAM,uBAAuB,CAAC;AAG/B,4CAA4C;AAC5C,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AACxD,0CAA0C;AAC1C,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AACpD,sFAAsF;AACtF,MAAM,eAAe,GAAG,SAAS,CAAC;AAClC,mEAAmE;AACnE,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA8B,EAC9B,QAAkC;IAElC,MAAM,cAAc,GAAG,YAAY,CAAC;QAClC,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ,EAAE;YACR,GAAG,QAAQ;YACX,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACtC;KACF,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,eAAe,CAAC;IACjC,MAAM,WAAW,GAAG,wBAAwB,CAAC;IAE7C,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAW,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,UAAU,C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AO,CAAC,MAAM,CACjC,CAAC,CAAC,EAA6B,EAAE,CAC/B,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,WAAW,IAAI,CAAC,CAAC,CAC5D,CAAC;YACF,OAAO,oBAAoB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC;KACwC,CAAC;AAC9C,CAAC"}
|
package/src/lib/wal.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codec for encoding/decoding values to/from strings for WAL storage.
|
|
3
|
+
* Used to serialize/deserialize records written to and read from WAL files.
|
|
4
|
+
*/
|
|
5
|
+
export type Codec<I, O = string> = {
|
|
6
|
+
/** Encode a value to a string for storage */
|
|
7
|
+
encode: (v: I) => O;
|
|
8
|
+
/** Decode a string back to the original value type */
|
|
9
|
+
decode: (data: O) => I;
|
|
10
|
+
};
|
|
11
|
+
export type InvalidEntry<O = string> = {
|
|
12
|
+
__invalid: true;
|
|
13
|
+
raw: O;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Interface for sinks that can append items.
|
|
17
|
+
* Allows for different types of appendable storage (WAL, in-memory, etc.)
|
|
18
|
+
*/
|
|
19
|
+
export type AppendableSink<T> = {
|
|
20
|
+
append: (item: T) => void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Result of recovering records from a WAL file.
|
|
24
|
+
* Contains successfully recovered records and any errors encountered during parsing.
|
|
25
|
+
*/
|
|
26
|
+
export type RecoverResult<T> = {
|
|
27
|
+
/** Successfully recovered records */
|
|
28
|
+
records: T[];
|
|
29
|
+
/** Errors encountered during recovery with line numbers and context */
|
|
30
|
+
errors: {
|
|
31
|
+
lineNo: number;
|
|
32
|
+
line: string;
|
|
33
|
+
error: Error;
|
|
34
|
+
}[];
|
|
35
|
+
/** Last incomplete line if file was truncated (null if clean) */
|
|
36
|
+
partialTail: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Statistics about the WAL file state and last recovery operation.
|
|
40
|
+
*/
|
|
41
|
+
export type WalStats<T> = {
|
|
42
|
+
/** File path for this WAL */
|
|
43
|
+
filePath: string;
|
|
44
|
+
/** Whether the WAL file is currently closed */
|
|
45
|
+
isClosed: boolean;
|
|
46
|
+
/** Whether the WAL file exists on disk */
|
|
47
|
+
fileExists: boolean;
|
|
48
|
+
/** File size in bytes (0 if file doesn't exist) */
|
|
49
|
+
fileSize: number;
|
|
50
|
+
/** Last recovery state from the most recent {@link recover} or {@link repack} operation */
|
|
51
|
+
lastRecovery: RecoverResult<T | InvalidEntry<string>> | null;
|
|
52
|
+
};
|
|
53
|
+
export declare const createTolerantCodec: <I, O = string>(codec: {
|
|
54
|
+
encode: (v: I) => O;
|
|
55
|
+
decode: (d: O) => I;
|
|
56
|
+
}) => Codec<I | InvalidEntry<O>, O>;
|
|
57
|
+
export declare function filterValidRecords<T>(records: (T | InvalidEntry<unknown>)[]): T[];
|
|
58
|
+
/**
|
|
59
|
+
* Pure helper function to recover records from WAL file content.
|
|
60
|
+
* @param content - Raw file content as string
|
|
61
|
+
* @param decode - function for decoding records
|
|
62
|
+
* @returns Recovery result with records, errors, and partial tail
|
|
63
|
+
*/
|
|
64
|
+
export declare function recoverFromContent<T>(content: string, decode: Codec<T>['decode']): RecoverResult<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Write-Ahead Log implementation for crash-safe append-only logging.
|
|
67
|
+
* Provides atomic operations for writing, recovering, and repacking log entries.
|
|
68
|
+
*/
|
|
69
|
+
export declare class WriteAheadLogFile<T> implements AppendableSink<T> {
|
|
70
|
+
#private;
|
|
71
|
+
/**
|
|
72
|
+
* Create a new WAL file instance.
|
|
73
|
+
* @param options - Configuration options
|
|
74
|
+
*/
|
|
75
|
+
constructor(options: {
|
|
76
|
+
file: string;
|
|
77
|
+
codec: Codec<T>;
|
|
78
|
+
});
|
|
79
|
+
/** Get the file path for this WAL */
|
|
80
|
+
getPath: () => string;
|
|
81
|
+
/** Open the WAL file for writing (creates directories if needed) */
|
|
82
|
+
open: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* Append a record to the WAL.
|
|
85
|
+
* @param v - Record to append
|
|
86
|
+
* @throws Error if WAL cannot be opened
|
|
87
|
+
*/
|
|
88
|
+
append: (v: T) => void;
|
|
89
|
+
/** Close the WAL file */
|
|
90
|
+
close: () => void;
|
|
91
|
+
isClosed: () => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Recover all records from the WAL file.
|
|
94
|
+
* Handles partial writes and decode errors gracefully.
|
|
95
|
+
* Updates the recovery state (accessible via {@link getStats}).
|
|
96
|
+
* @returns Recovery result with records, errors, and partial tail
|
|
97
|
+
*/
|
|
98
|
+
recover(): RecoverResult<T | InvalidEntry<string>>;
|
|
99
|
+
/**
|
|
100
|
+
* Repack the WAL by recovering all valid records and rewriting cleanly.
|
|
101
|
+
* Removes corrupted entries and ensures clean formatting.
|
|
102
|
+
* Updates the recovery state (accessible via {@link getStats}).
|
|
103
|
+
* @param out - Output path (defaults to current file)
|
|
104
|
+
*/
|
|
105
|
+
repack(out?: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Get comprehensive statistics about the WAL file state.
|
|
108
|
+
* Includes file information, open/close status, and last recovery state.
|
|
109
|
+
* @returns Statistics object with file info and last recovery state
|
|
110
|
+
*/
|
|
111
|
+
getStats(): WalStats<T>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Format descriptor that binds codec and file extension together.
|
|
115
|
+
* Prevents misconfiguration by keeping related concerns in one object.
|
|
116
|
+
*/
|
|
117
|
+
export type WalFormat<T extends object | string> = {
|
|
118
|
+
/** Base name for the WAL (e.g., "trace") */
|
|
119
|
+
baseName: string;
|
|
120
|
+
/** Shard file extension (e.g., ".jsonl") */
|
|
121
|
+
walExtension: string;
|
|
122
|
+
/** Final file extension (e.g., ".json", ".trace.json") falls back to walExtension if not provided */
|
|
123
|
+
finalExtension: string;
|
|
124
|
+
/** Codec for encoding/decoding records */
|
|
125
|
+
codec: Codec<T, string>;
|
|
126
|
+
/** Finalizer for converting records to a string */
|
|
127
|
+
finalizer: (records: (T | InvalidEntry<string>)[], opt?: Record<string, unknown>) => string;
|
|
128
|
+
};
|
|
129
|
+
export declare const stringCodec: <T extends string | object = string>() => Codec<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Parses a partial WalFormat configuration and returns a complete WalFormat object.
|
|
132
|
+
* All fallback values are targeting string types.
|
|
133
|
+
* - baseName defaults to 'wal'
|
|
134
|
+
* - walExtension defaults to '.log'
|
|
135
|
+
* - finalExtension defaults to '.log'
|
|
136
|
+
* - codec defaults to stringCodec<T>()
|
|
137
|
+
* - finalizer defaults to encoding each record using codec.encode() and joining with newlines.
|
|
138
|
+
* For object types, this properly JSON-stringifies them (not [object Object]).
|
|
139
|
+
* InvalidEntry records use their raw string value directly.
|
|
140
|
+
* @param format - Partial WalFormat configuration
|
|
141
|
+
* @returns Parsed WalFormat with defaults filled in
|
|
142
|
+
*/
|
|
143
|
+
export declare function parseWalFormat<T extends object | string = object>(format: Partial<WalFormat<T>>): WalFormat<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Determines if this process is the leader WAL process using the origin PID heuristic.
|
|
146
|
+
*
|
|
147
|
+
* The leader is the process that first enabled profiling (the one that set CP_PROFILER_ORIGIN_PID).
|
|
148
|
+
* All descendant processes inherit the environment but have different PIDs.
|
|
149
|
+
*
|
|
150
|
+
* @returns true if this is the leader WAL process, false otherwise
|
|
151
|
+
*/
|
|
152
|
+
export declare function isLeaderWal(envVarName: string, profilerID: string): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Initialize the origin PID environment variable if not already set.
|
|
155
|
+
* This must be done as early as possible before any user code runs.
|
|
156
|
+
* Sets envVarName to the current process ID if not already defined.
|
|
157
|
+
*/
|
|
158
|
+
export declare function setLeaderWal(envVarName: string, profilerID: string): void;
|
|
159
|
+
/**
|
|
160
|
+
* Generates a human-readable shard ID.
|
|
161
|
+
* This ID is unique per process/thread/shard combination and used in the file name.
|
|
162
|
+
* Format: readable-timestamp.pid.threadId.shardCount
|
|
163
|
+
* Example: "20240101-120000-000.12345.1.1"
|
|
164
|
+
* Becomes file: trace.20240101-120000-000.12345.1.1.log
|
|
165
|
+
*/
|
|
166
|
+
export declare function getShardId(): string;
|
|
167
|
+
/**
|
|
168
|
+
* Generates a human-readable sharded group ID.
|
|
169
|
+
* This ID is a globally unique, sortable, human-readable date string per run.
|
|
170
|
+
* Used directly as the folder name to group shards.
|
|
171
|
+
* Format: yyyymmdd-hhmmss-ms
|
|
172
|
+
* Example: "20240101-120000-000"
|
|
173
|
+
*/
|
|
174
|
+
export declare function getShardedGroupId(): string;
|
|
175
|
+
/**
|
|
176
|
+
* Regex patterns for validating WAL ID formats
|
|
177
|
+
*/
|
|
178
|
+
export declare const WAL_ID_PATTERNS: {
|
|
179
|
+
/** Readable date format: yyyymmdd-hhmmss-ms */
|
|
180
|
+
readonly READABLE_DATE: RegExp;
|
|
181
|
+
/** Group ID format: yyyymmdd-hhmmss-ms */
|
|
182
|
+
readonly GROUP_ID: RegExp;
|
|
183
|
+
/** Shard ID format: readable-date.pid.threadId.count */
|
|
184
|
+
readonly SHARD_ID: RegExp;
|
|
185
|
+
};
|
|
186
|
+
export declare function sortableReadableDateString(timestampMs: string): string;
|
|
187
|
+
/**
|
|
188
|
+
* Generates a path to a shard file using human-readable IDs.
|
|
189
|
+
* Both groupId and shardId are already in readable date format.
|
|
190
|
+
*
|
|
191
|
+
* Example with groupId "20240101-120000-000" and shardId "20240101-120000-000.12345.1.1":
|
|
192
|
+
* Full path: /base/20240101-120000-000/trace.20240101-120000-000.12345.1.1.log
|
|
193
|
+
*
|
|
194
|
+
* @param opt.dir - The directory to store the shard file
|
|
195
|
+
* @param opt.format - The WalFormat to use for the shard file
|
|
196
|
+
* @param opt.groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
|
|
197
|
+
* @param opt.shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
|
|
198
|
+
* @returns The path to the shard file
|
|
199
|
+
*/
|
|
200
|
+
export declare function getShardedPath<T extends object | string = object>(opt: {
|
|
201
|
+
dir?: string;
|
|
202
|
+
format: WalFormat<T>;
|
|
203
|
+
groupId: string;
|
|
204
|
+
shardId: string;
|
|
205
|
+
}): string;
|
|
206
|
+
export declare function getShardedFinalPath<T extends object | string = object>(opt: {
|
|
207
|
+
dir?: string;
|
|
208
|
+
format: WalFormat<T>;
|
|
209
|
+
groupId: string;
|
|
210
|
+
}): string;
|
|
211
|
+
/**
|
|
212
|
+
* Sharded Write-Ahead Log manager for coordinating multiple WAL shards.
|
|
213
|
+
* Handles distributed logging across multiple processes/files with atomic finalization.
|
|
214
|
+
*/
|
|
215
|
+
export declare class ShardedWal<T extends object | string = object> {
|
|
216
|
+
#private;
|
|
217
|
+
readonly groupId: string;
|
|
218
|
+
/**
|
|
219
|
+
* Create a sharded WAL manager.
|
|
220
|
+
*/
|
|
221
|
+
constructor(opt: {
|
|
222
|
+
dir?: string;
|
|
223
|
+
format: Partial<WalFormat<T>>;
|
|
224
|
+
groupId?: string;
|
|
225
|
+
});
|
|
226
|
+
shard(shardId?: string): WriteAheadLogFile<T>;
|
|
227
|
+
/** Get all shard file paths matching this WAL's base name */
|
|
228
|
+
private shardFiles;
|
|
229
|
+
/**
|
|
230
|
+
* Finalize all shards by merging them into a single output file.
|
|
231
|
+
* Recovers all records from all shards, validates no errors, and writes merged result.
|
|
232
|
+
* @throws Error if any shard contains decode errors
|
|
233
|
+
*/
|
|
234
|
+
finalize(opt?: Record<string, unknown>): void;
|
|
235
|
+
cleanup(): void;
|
|
236
|
+
}
|
package/src/lib/wal.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { threadId } from 'node:worker_threads';
|
|
6
|
+
export const createTolerantCodec = (codec) => {
|
|
7
|
+
const { encode, decode } = codec;
|
|
8
|
+
return {
|
|
9
|
+
encode: v => v && typeof v === 'object' && '__invalid' in v
|
|
10
|
+
? v.raw
|
|
11
|
+
: encode(v),
|
|
12
|
+
decode: d => {
|
|
13
|
+
try {
|
|
14
|
+
return decode(d);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return { __invalid: true, raw: d };
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export function filterValidRecords(records) {
|
|
23
|
+
return records
|
|
24
|
+
.filter((r) => !(typeof r === 'object' && r != null && '__invalid' in r))
|
|
25
|
+
.map(r => r);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Pure helper function to recover records from WAL file content.
|
|
29
|
+
* @param content - Raw file content as string
|
|
30
|
+
* @param decode - function for decoding records
|
|
31
|
+
* @returns Recovery result with records, errors, and partial tail
|
|
32
|
+
*/
|
|
33
|
+
export function recoverFromContent(content, decode) {
|
|
34
|
+
const lines = content.split('\n');
|
|
35
|
+
const clean = content.endsWith('\n');
|
|
36
|
+
const out = lines.slice(0, -1).reduce((a, l, i) => {
|
|
37
|
+
if (!l) {
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return {
|
|
42
|
+
...a,
|
|
43
|
+
records: [...a.records, decode(l)],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
...a,
|
|
49
|
+
errors: [
|
|
50
|
+
...a.errors,
|
|
51
|
+
{ lineNo: i + 1, line: l, error: error },
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, { records: [], errors: [] });
|
|
56
|
+
const tail = lines.at(-1);
|
|
57
|
+
return {
|
|
58
|
+
...out,
|
|
59
|
+
partialTail: clean || !tail ? null : tail,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Write-Ahead Log implementation for crash-safe append-only logging.
|
|
64
|
+
* Provides atomic operations for writing, recovering, and repacking log entries.
|
|
65
|
+
*/
|
|
66
|
+
export class WriteAheadLogFile {
|
|
67
|
+
#fd = null;
|
|
68
|
+
#file;
|
|
69
|
+
#decode;
|
|
70
|
+
#encode;
|
|
71
|
+
#lastRecoveryState = null;
|
|
72
|
+
/**
|
|
73
|
+
* Create a new WAL file instance.
|
|
74
|
+
* @param options - Configuration options
|
|
75
|
+
*/
|
|
76
|
+
constructor(options) {
|
|
77
|
+
this.#file = options.file;
|
|
78
|
+
const c = createTolerantCodec(options.codec);
|
|
79
|
+
this.#decode = c.decode;
|
|
80
|
+
this.#encode = c.encode;
|
|
81
|
+
}
|
|
82
|
+
/** Get the file path for this WAL */
|
|
83
|
+
getPath = () => this.#file;
|
|
84
|
+
/** Open the WAL file for writing (creates directories if needed) */
|
|
85
|
+
open = () => {
|
|
86
|
+
if (this.#fd) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
ensureDirectoryExistsSync(path.dirname(this.#file));
|
|
90
|
+
this.#fd = fs.openSync(this.#file, 'a');
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Append a record to the WAL.
|
|
94
|
+
* @param v - Record to append
|
|
95
|
+
* @throws Error if WAL cannot be opened
|
|
96
|
+
*/
|
|
97
|
+
append = (v) => {
|
|
98
|
+
if (!this.#fd) {
|
|
99
|
+
throw new Error('WAL not opened');
|
|
100
|
+
}
|
|
101
|
+
fs.writeSync(this.#fd, `${this.#encode(v)}\n`);
|
|
102
|
+
};
|
|
103
|
+
/** Close the WAL file */
|
|
104
|
+
close = () => {
|
|
105
|
+
if (this.#fd) {
|
|
106
|
+
fs.closeSync(this.#fd);
|
|
107
|
+
}
|
|
108
|
+
this.#fd = null;
|
|
109
|
+
};
|
|
110
|
+
isClosed = () => this.#fd == null;
|
|
111
|
+
/**
|
|
112
|
+
* Recover all records from the WAL file.
|
|
113
|
+
* Handles partial writes and decode errors gracefully.
|
|
114
|
+
* Updates the recovery state (accessible via {@link getStats}).
|
|
115
|
+
* @returns Recovery result with records, errors, and partial tail
|
|
116
|
+
*/
|
|
117
|
+
recover() {
|
|
118
|
+
if (!fs.existsSync(this.#file)) {
|
|
119
|
+
this.#lastRecoveryState = { records: [], errors: [], partialTail: null };
|
|
120
|
+
return this.#lastRecoveryState;
|
|
121
|
+
}
|
|
122
|
+
const txt = fs.readFileSync(this.#file, 'utf8');
|
|
123
|
+
this.#lastRecoveryState = recoverFromContent(txt, this.#decode);
|
|
124
|
+
return this.#lastRecoveryState;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Repack the WAL by recovering all valid records and rewriting cleanly.
|
|
128
|
+
* Removes corrupted entries and ensures clean formatting.
|
|
129
|
+
* Updates the recovery state (accessible via {@link getStats}).
|
|
130
|
+
* @param out - Output path (defaults to current file)
|
|
131
|
+
*/
|
|
132
|
+
repack(out = this.#file) {
|
|
133
|
+
this.close();
|
|
134
|
+
const r = this.recover();
|
|
135
|
+
if (r.errors.length > 0) {
|
|
136
|
+
// eslint-disable-next-line no-console
|
|
137
|
+
console.log('WAL repack encountered decode errors');
|
|
138
|
+
}
|
|
139
|
+
// Check if any records are invalid entries (from tolerant codec)
|
|
140
|
+
const hasInvalidEntries = r.records.some(rec => typeof rec === 'object' && rec != null && '__invalid' in rec);
|
|
141
|
+
if (hasInvalidEntries) {
|
|
142
|
+
// eslint-disable-next-line no-console
|
|
143
|
+
console.log('Found invalid entries during WAL repack');
|
|
144
|
+
}
|
|
145
|
+
const recordsToWrite = hasInvalidEntries
|
|
146
|
+
? r.records
|
|
147
|
+
: filterValidRecords(r.records);
|
|
148
|
+
ensureDirectoryExistsSync(path.dirname(out));
|
|
149
|
+
fs.writeFileSync(out, `${recordsToWrite.map(this.#encode).join('\n')}\n`);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get comprehensive statistics about the WAL file state.
|
|
153
|
+
* Includes file information, open/close status, and last recovery state.
|
|
154
|
+
* @returns Statistics object with file info and last recovery state
|
|
155
|
+
*/
|
|
156
|
+
getStats() {
|
|
157
|
+
const fileExists = fs.existsSync(this.#file);
|
|
158
|
+
return {
|
|
159
|
+
filePath: this.#file,
|
|
160
|
+
isClosed: this.#fd == null,
|
|
161
|
+
fileExists,
|
|
162
|
+
fileSize: fileExists ? fs.statSync(this.#file).size : 0,
|
|
163
|
+
lastRecovery: this.#lastRecoveryState,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export const stringCodec = () => ({
|
|
168
|
+
encode: v => (typeof v === 'string' ? v : JSON.stringify(v)),
|
|
169
|
+
decode: v => {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(v);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return v;
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
/**
|
|
179
|
+
* Parses a partial WalFormat configuration and returns a complete WalFormat object.
|
|
180
|
+
* All fallback values are targeting string types.
|
|
181
|
+
* - baseName defaults to 'wal'
|
|
182
|
+
* - walExtension defaults to '.log'
|
|
183
|
+
* - finalExtension defaults to '.log'
|
|
184
|
+
* - codec defaults to stringCodec<T>()
|
|
185
|
+
* - finalizer defaults to encoding each record using codec.encode() and joining with newlines.
|
|
186
|
+
* For object types, this properly JSON-stringifies them (not [object Object]).
|
|
187
|
+
* InvalidEntry records use their raw string value directly.
|
|
188
|
+
* @param format - Partial WalFormat configuration
|
|
189
|
+
* @returns Parsed WalFormat with defaults filled in
|
|
190
|
+
*/
|
|
191
|
+
export function parseWalFormat(format) {
|
|
192
|
+
const { baseName = 'wal', walExtension = '.log', finalExtension = walExtension, codec = stringCodec(), } = format;
|
|
193
|
+
const finalizer = format.finalizer ??
|
|
194
|
+
((records) => {
|
|
195
|
+
// Encode each record using the codec before joining.
|
|
196
|
+
// For object types, codec.encode() will JSON-stringify them properly.
|
|
197
|
+
// InvalidEntry records use their raw string value directly.
|
|
198
|
+
const encoded = records.map(record => typeof record === 'object' && record != null && '__invalid' in record
|
|
199
|
+
? record.raw
|
|
200
|
+
: codec.encode(record));
|
|
201
|
+
return `${encoded.join('\n')}\n`;
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
baseName,
|
|
205
|
+
walExtension,
|
|
206
|
+
finalExtension,
|
|
207
|
+
codec,
|
|
208
|
+
finalizer,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Determines if this process is the leader WAL process using the origin PID heuristic.
|
|
213
|
+
*
|
|
214
|
+
* The leader is the process that first enabled profiling (the one that set CP_PROFILER_ORIGIN_PID).
|
|
215
|
+
* All descendant processes inherit the environment but have different PIDs.
|
|
216
|
+
*
|
|
217
|
+
* @returns true if this is the leader WAL process, false otherwise
|
|
218
|
+
*/
|
|
219
|
+
export function isLeaderWal(envVarName, profilerID) {
|
|
220
|
+
return process.env[envVarName] === profilerID;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Initialize the origin PID environment variable if not already set.
|
|
224
|
+
* This must be done as early as possible before any user code runs.
|
|
225
|
+
* Sets envVarName to the current process ID if not already defined.
|
|
226
|
+
*/
|
|
227
|
+
export function setLeaderWal(envVarName, profilerID) {
|
|
228
|
+
if (!process.env[envVarName]) {
|
|
229
|
+
// eslint-disable-next-line functional/immutable-data
|
|
230
|
+
process.env[envVarName] = profilerID;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// eslint-disable-next-line functional/no-let
|
|
234
|
+
let shardCount = 0;
|
|
235
|
+
/**
|
|
236
|
+
* Generates a human-readable shard ID.
|
|
237
|
+
* This ID is unique per process/thread/shard combination and used in the file name.
|
|
238
|
+
* Format: readable-timestamp.pid.threadId.shardCount
|
|
239
|
+
* Example: "20240101-120000-000.12345.1.1"
|
|
240
|
+
* Becomes file: trace.20240101-120000-000.12345.1.1.log
|
|
241
|
+
*/
|
|
242
|
+
export function getShardId() {
|
|
243
|
+
const timestamp = Math.round(performance.timeOrigin + performance.now());
|
|
244
|
+
const readableTimestamp = sortableReadableDateString(`${timestamp}`);
|
|
245
|
+
return `${readableTimestamp}.${process.pid}.${threadId}.${++shardCount}`;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Generates a human-readable sharded group ID.
|
|
249
|
+
* This ID is a globally unique, sortable, human-readable date string per run.
|
|
250
|
+
* Used directly as the folder name to group shards.
|
|
251
|
+
* Format: yyyymmdd-hhmmss-ms
|
|
252
|
+
* Example: "20240101-120000-000"
|
|
253
|
+
*/
|
|
254
|
+
export function getShardedGroupId() {
|
|
255
|
+
return sortableReadableDateString(`${Math.round(performance.timeOrigin + performance.now())}`);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Regex patterns for validating WAL ID formats
|
|
259
|
+
*/
|
|
260
|
+
export const WAL_ID_PATTERNS = {
|
|
261
|
+
/** Readable date format: yyyymmdd-hhmmss-ms */
|
|
262
|
+
READABLE_DATE: /^\d{8}-\d{6}-\d{3}$/,
|
|
263
|
+
/** Group ID format: yyyymmdd-hhmmss-ms */
|
|
264
|
+
GROUP_ID: /^\d{8}-\d{6}-\d{3}$/,
|
|
265
|
+
/** Shard ID format: readable-date.pid.threadId.count */
|
|
266
|
+
SHARD_ID: /^\d{8}-\d{6}-\d{3}(?:\.\d+){3}$/,
|
|
267
|
+
};
|
|
268
|
+
export function sortableReadableDateString(timestampMs) {
|
|
269
|
+
const timestamp = Number.parseInt(timestampMs, 10);
|
|
270
|
+
const date = new Date(timestamp);
|
|
271
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
272
|
+
const yyyy = date.getFullYear();
|
|
273
|
+
const mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
274
|
+
const dd = String(date.getDate()).padStart(2, '0');
|
|
275
|
+
const hh = String(date.getHours()).padStart(2, '0');
|
|
276
|
+
const min = String(date.getMinutes()).padStart(2, '0');
|
|
277
|
+
const ss = String(date.getSeconds()).padStart(2, '0');
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
279
|
+
const ms = String(timestamp % MILLISECONDS_PER_SECOND).padStart(3, '0');
|
|
280
|
+
return `${yyyy}${mm}${dd}-${hh}${min}${ss}-${ms}`;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Ensures a directory exists, creating it recursively if necessary using sync methods.
|
|
284
|
+
* @param dirPath - The directory path to ensure exists
|
|
285
|
+
*/
|
|
286
|
+
function ensureDirectoryExistsSync(dirPath) {
|
|
287
|
+
if (!fs.existsSync(dirPath)) {
|
|
288
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Generates a path to a shard file using human-readable IDs.
|
|
293
|
+
* Both groupId and shardId are already in readable date format.
|
|
294
|
+
*
|
|
295
|
+
* Example with groupId "20240101-120000-000" and shardId "20240101-120000-000.12345.1.1":
|
|
296
|
+
* Full path: /base/20240101-120000-000/trace.20240101-120000-000.12345.1.1.log
|
|
297
|
+
*
|
|
298
|
+
* @param opt.dir - The directory to store the shard file
|
|
299
|
+
* @param opt.format - The WalFormat to use for the shard file
|
|
300
|
+
* @param opt.groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
|
|
301
|
+
* @param opt.shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
|
|
302
|
+
* @returns The path to the shard file
|
|
303
|
+
*/
|
|
304
|
+
export function getShardedPath(opt) {
|
|
305
|
+
const { dir = '', format, groupId, shardId } = opt;
|
|
306
|
+
const { baseName, walExtension } = format;
|
|
307
|
+
return path.join(dir, groupId, `${baseName}.${shardId}${walExtension}`);
|
|
308
|
+
}
|
|
309
|
+
export function getShardedFinalPath(opt) {
|
|
310
|
+
const { dir = '', format, groupId } = opt;
|
|
311
|
+
const { baseName, finalExtension } = format;
|
|
312
|
+
return path.join(dir, groupId, `${baseName}.${groupId}${finalExtension}`);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Sharded Write-Ahead Log manager for coordinating multiple WAL shards.
|
|
316
|
+
* Handles distributed logging across multiple processes/files with atomic finalization.
|
|
317
|
+
*/
|
|
318
|
+
export class ShardedWal {
|
|
319
|
+
groupId = getShardedGroupId();
|
|
320
|
+
#format;
|
|
321
|
+
#dir = process.cwd();
|
|
322
|
+
/**
|
|
323
|
+
* Create a sharded WAL manager.
|
|
324
|
+
*/
|
|
325
|
+
constructor(opt) {
|
|
326
|
+
const { dir, format, groupId } = opt;
|
|
327
|
+
this.groupId = groupId ?? getShardedGroupId();
|
|
328
|
+
if (dir) {
|
|
329
|
+
this.#dir = dir;
|
|
330
|
+
}
|
|
331
|
+
this.#format = parseWalFormat(format);
|
|
332
|
+
}
|
|
333
|
+
shard(shardId = getShardId()) {
|
|
334
|
+
return new WriteAheadLogFile({
|
|
335
|
+
file: getShardedPath({
|
|
336
|
+
dir: this.#dir,
|
|
337
|
+
format: this.#format,
|
|
338
|
+
groupId: this.groupId,
|
|
339
|
+
shardId,
|
|
340
|
+
}),
|
|
341
|
+
codec: this.#format.codec,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/** Get all shard file paths matching this WAL's base name */
|
|
345
|
+
shardFiles() {
|
|
346
|
+
if (!fs.existsSync(this.#dir)) {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
const groupIdDir = path.dirname(getShardedFinalPath({
|
|
350
|
+
dir: this.#dir,
|
|
351
|
+
format: this.#format,
|
|
352
|
+
groupId: this.groupId,
|
|
353
|
+
}));
|
|
354
|
+
// create dir if not existing
|
|
355
|
+
ensureDirectoryExistsSync(groupIdDir);
|
|
356
|
+
return fs
|
|
357
|
+
.readdirSync(groupIdDir)
|
|
358
|
+
.filter(entry => entry.endsWith(this.#format.walExtension))
|
|
359
|
+
.filter(entry => entry.startsWith(`${this.#format.baseName}`))
|
|
360
|
+
.map(entry => path.join(groupIdDir, entry));
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Finalize all shards by merging them into a single output file.
|
|
364
|
+
* Recovers all records from all shards, validates no errors, and writes merged result.
|
|
365
|
+
* @throws Error if any shard contains decode errors
|
|
366
|
+
*/
|
|
367
|
+
finalize(opt) {
|
|
368
|
+
const fileRecoveries = this.shardFiles().map(f => ({
|
|
369
|
+
file: f,
|
|
370
|
+
recovery: new WriteAheadLogFile({
|
|
371
|
+
file: f,
|
|
372
|
+
codec: this.#format.codec,
|
|
373
|
+
}).recover(),
|
|
374
|
+
}));
|
|
375
|
+
const records = fileRecoveries.flatMap(({ recovery }) => recovery.records);
|
|
376
|
+
// Check if any records are invalid entries (from tolerant codec)
|
|
377
|
+
const hasInvalidEntries = records.some(r => typeof r === 'object' && r != null && '__invalid' in r);
|
|
378
|
+
const recordsToFinalize = hasInvalidEntries
|
|
379
|
+
? records
|
|
380
|
+
: filterValidRecords(records);
|
|
381
|
+
const out = getShardedFinalPath({
|
|
382
|
+
dir: this.#dir,
|
|
383
|
+
format: this.#format,
|
|
384
|
+
groupId: this.groupId,
|
|
385
|
+
});
|
|
386
|
+
ensureDirectoryExistsSync(path.dirname(out));
|
|
387
|
+
fs.writeFileSync(out, this.#format.finalizer(recordsToFinalize, opt));
|
|
388
|
+
}
|
|
389
|
+
cleanup() {
|
|
390
|
+
this.shardFiles().forEach(f => {
|
|
391
|
+
// Remove the shard file
|
|
392
|
+
fs.unlinkSync(f);
|
|
393
|
+
// Remove the parent directory (shard group directory)
|
|
394
|
+
const shardDir = path.dirname(f);
|
|
395
|
+
try {
|
|
396
|
+
fs.rmdirSync(shardDir);
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
// Directory might not be empty or already removed, ignore
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
// Also try to remove the root directory if it becomes empty
|
|
403
|
+
try {
|
|
404
|
+
fs.rmdirSync(this.#dir);
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
// Directory might not be empty or already removed, ignore
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
//# sourceMappingURL=wal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wal.js","sourceRoot":"","sources":["../../../src/lib/wal.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAoD/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAgB,KAGlD,EAAiC,EAAE;IAClC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAEjC,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,EAAE,CACV,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,WAAW,IAAI,CAAC;YAC5C,CAAC,CAAE,CAAqB,CAAC,GAAG;YAC5B,CAAC,CAAC,MAAM,CAAC,CAAM,CAAC;QACpB,MAAM,EAAE,CAAC,CAAC,EAAE;YACV,IAAI,CAAC;gBACH,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YACrC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAChC,OAAsC;IAEtC,OAAO,OAAO;SACX,MAAM,CACL,CAAC,CAAC,EAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,WAAW,IAAI,CAAC,CAAC,CACzE;SACA,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAM,CAAC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AAO;YACpB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QACH,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7C,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YAC5B,wBAAwB;YACxB,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACjB,sDAAsD;YACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC;gBACH,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,0DAA0D;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,4DAA4D;QAC5D,IAAI,CAAC;YACH,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,0DAA0D;QAC5D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sink-source.type.js","sourceRoot":"","sources":["../../../src/lib/sink-source.type.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAchD,mEAAmE;AACnE,6CAA6C;AAC7C,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,GAAiD,EAAE,E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