Skip to content

Commit cadc7ee

Browse files
committed
refactor: fix targets
1 parent a952dfe commit cadc7ee

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

packages/utils/mocks/sink.mock.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { WriteAheadLogFile } from '../src/lib/wal.js';
2-
import type { Codec } from '../src/lib/wal.js';
1+
import type { AppendableSink, Codec } from '../src/lib/wal.js';
32

4-
export class MockFileSink implements WriteAheadLogFile<string> {
3+
export class MockFileSink implements AppendableSink<string> {
54
private writtenItems: string[] = [];
65
private closed = false;
76

packages/utils/src/lib/performance-observer.int.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { type PerformanceEntry, performance } from 'node:perf_hooks';
22
import type { MockedFunction } from 'vitest';
3-
import { MockSink } from '../../mocks/sink.mock';
3+
import { MockFileSink } from '../../mocks/sink.mock';
44
import {
55
type PerformanceObserverOptions,
66
PerformanceObserverSink,
77
} from './performance-observer.js';
88

99
describe('PerformanceObserverSink', () => {
1010
let encode: MockedFunction<(entry: PerformanceEntry) => string[]>;
11-
let sink: MockSink;
11+
let sink: MockFileSink;
1212
let options: PerformanceObserverOptions<string>;
1313

1414
const awaitObserverCallback = () =>
1515
new Promise(resolve => setTimeout(resolve, 10));
1616

1717
beforeEach(() => {
18-
sink = new MockSink();
18+
sink = new MockFileSink();
1919
encode = vi.fn((entry: PerformanceEntry) => [
2020
`${entry.name}:${entry.entryType}`,
2121
]);

packages/utils/src/lib/profiler/wal-json-trace.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ export function generateTraceContent(
7373
/**
7474
* Creates a WAL (Write-Ahead Logging) format configuration for Chrome DevTools trace files.
7575
* Automatically finalizes shards into complete trace files with proper metadata and margin events.
76-
* @template T - Type of trace events, defaults to UserTimingTraceEvent
7776
* @returns WalFormat configuration object with baseName, codec, extensions, and finalizer
7877
*/
79-
export const traceEventWalFormat = <
80-
T extends UserTimingTraceEvent = UserTimingTraceEvent,
81-
>() => {
78+
export function traceEventWalFormat() {
8279
const baseName = 'trace';
8380
const walExtension = '.jsonl';
8481
const finalExtension = '.json';
@@ -89,7 +86,8 @@ export const traceEventWalFormat = <
8986
codec: {
9087
encode: (event: UserTimingTraceEvent) =>
9188
JSON.stringify(encodeTraceEvent(event)),
92-
decode: (json: string) => decodeTraceEvent(JSON.parse(json)) as T,
89+
decode: (json: string) =>
90+
decodeTraceEvent(JSON.parse(json)) as UserTimingTraceEvent,
9391
},
9492
finalizer: (
9593
records: (UserTimingTraceEvent | InvalidEntry<string>)[],
@@ -101,5 +99,5 @@ export const traceEventWalFormat = <
10199
);
102100
return generateTraceContent(validRecords, metadata);
103101
},
104-
} satisfies WalFormat<T>;
105-
};
102+
} satisfies WalFormat<UserTimingTraceEvent>;
103+
}

packages/utils/src/lib/profiler/wal-json-trace.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe('traceEventWalFormat', () => {
288288
const parsed = JSON.parse(result);
289289
expect(parsed).toHaveProperty('traceEvents');
290290
expect(parsed).toHaveProperty('metadata');
291-
expect(Array.isArray(parsed.traceEvents)).toBe(true);
291+
expect(parsed.traceEvents).toBeArray();
292292
});
293293

294294
it('should include generatedAt in finalizer metadata', () => {

packages/utils/src/lib/wal.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ export class WriteAheadLogFile<T> implements AppendableSink<T> {
185185
* Repack the WAL by recovering all valid records and rewriting cleanly.
186186
* Removes corrupted entries and ensures clean formatting.
187187
* @param out - Output path (defaults to current file)
188-
* @throws Error if recovery encounters decode errors
189188
*/
190189
repack(out = this.#file) {
191190
this.close();
@@ -311,7 +310,7 @@ let shardCount = 0;
311310
*/
312311
export function getShardId(): string {
313312
const timestamp = Math.round(performance.timeOrigin + performance.now());
314-
const readableTimestamp = soratebleReadableDateString(`${timestamp}`);
313+
const readableTimestamp = sortableReadableDateString(`${timestamp}`);
315314
return `${readableTimestamp}.${process.pid}.${threadId}.${++shardCount}`;
316315
}
317316

@@ -323,7 +322,7 @@ export function getShardId(): string {
323322
* Example: "20240101-120000-000"
324323
*/
325324
export function getShardedGroupId(): string {
326-
return soratebleReadableDateString(
325+
return sortableReadableDateString(
327326
`${Math.round(performance.timeOrigin + performance.now())}`,
328327
);
329328
}
@@ -340,7 +339,7 @@ export const WAL_ID_PATTERNS = {
340339
SHARD_ID: /^\d{8}-\d{6}-\d{3}(?:\.\d+){3}$/,
341340
} as const;
342341

343-
export function soratebleReadableDateString(timestampMs: string): string {
342+
export function sortableReadableDateString(timestampMs: string): string {
344343
const timestamp = Number.parseInt(timestampMs, 10);
345344
const date = new Date(timestamp);
346345
const MILLISECONDS_PER_SECOND = 1000;

0 commit comments

Comments
 (0)