Skip to content

Commit 51bf0a3

Browse files
committed
chore: type fixes
1 parent 93bed96 commit 51bf0a3

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,19 @@ export type * from './v3/hooksTypes'
5656
// eslint-disable-next-line import/first, import/newline-after-import
5757
import * as match from './v3/matchSpan'
5858
export { match }
59+
export type {
60+
Context,
61+
NameMatcher,
62+
SpanMatch,
63+
SpanMatchDefinition,
64+
SpanMatcherFn,
65+
SpanMatcherTags,
66+
} from './v3/matchSpan'
5967
export * from './v3/observePerformanceWithTraceManager'
6068
export * from './v3/recordingComputeUtils'
6169
export type * from './v3/spanAnnotationTypes'
6270
export type * from './v3/spanTypes'
6371
export * from './v3/traceManager'
6472
export type * from './v3/traceRecordingTypes'
6573
export type * from './v3/types'
74+
export type * from './v3/typeUtils'

src/v3/convertToRum.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { Context, SpanMatcherFn } from './matchSpan'
44
import { SpanAndAnnotation } from './spanAnnotationTypes'
55
import { ComponentRenderSpan, Span } from './spanTypes'
66
import { TraceRecording, TraceRecordingBase } from './traceRecordingTypes'
7+
import type { SelectScopeByKey } from './types'
8+
import type { KeysOfUnion } from './typeUtils'
79

810
export interface EmbeddedEntry {
911
count: number
@@ -87,14 +89,17 @@ export const defaultEmbedSpanSelector = <ScopeT>(
8789
return isRenderEntry(span)
8890
}
8991

90-
export function convertTraceToRUM<TracerScopeT, AllPossibleScopesT>(
91-
traceRecording: TraceRecording<TracerScopeT, AllPossibleScopesT>,
92-
context: Context<TracerScopeT, AllPossibleScopesT>,
92+
export function convertTraceToRUM<
93+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
94+
AllPossibleScopesT,
95+
>(
96+
traceRecording: TraceRecording<TracerScopeKeysT, AllPossibleScopesT>,
97+
context: Context<TracerScopeKeysT, AllPossibleScopesT>,
9398
embedSpanSelector: SpanMatcherFn<
94-
TracerScopeT,
99+
TracerScopeKeysT,
95100
AllPossibleScopesT
96101
> = defaultEmbedSpanSelector,
97-
): RumTraceRecording<TracerScopeT> {
102+
): RumTraceRecording<SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>> {
98103
const { entries, ...otherTraceRecordingAttributes } = traceRecording
99104
const embeddedEntries: SpanAndAnnotation<AllPossibleScopesT>[] = []
100105
const nonEmbeddedSpans = new Set<string>()

src/v3/matchSpan.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface SpanMatcherFn<
3838
): boolean
3939
}
4040

41-
type NameMatcher<TracerScopeT> =
41+
export type NameMatcher<TracerScopeT> =
4242
| string
4343
| RegExp
4444
| ((name: string, scope: TracerScopeT) => boolean)
@@ -83,9 +83,10 @@ export function withName<
8383
}
8484
}
8585

86-
export function withLabel<TracerScopeT, AllPossibleScopesT>(
87-
value: string,
88-
): SpanMatcherFn<TracerScopeT, AllPossibleScopesT> {
86+
export function withLabel<
87+
const TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
88+
const AllPossibleScopesT,
89+
>(value: string): SpanMatcherFn<TracerScopeKeysT, AllPossibleScopesT> {
8990
return ({ annotation }) => annotation.labels?.includes(value) ?? false
9091
}
9192

src/v3/test/fixtures/ticket.activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const TICKET_DISPOSE_EVENT_NAME = `ticket.dispose`
1313
const TICKET_NAVIGATED_AWAY_EVENT_NAME = `ticket.navigated-away`
1414

1515
export const ticketActivationDefinition: TraceDefinition<
16-
TicketIdScope,
16+
'ticketId',
1717
FixtureAllPossibleScopes
1818
> = {
1919
name: 'ticket.activation',

src/v3/typeUtils.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ export type UnionToIntersection<U> = (
2727
: never
2828

2929
type HandlerToPayloadTuples<
30-
TracerScopeT,
30+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
3131
AllPossibleScopesT,
3232
State extends TraceStates = TraceStates,
3333
> = State extends State
3434
? {
35-
[K in keyof States<TracerScopeT, AllPossibleScopesT>[State]]: States<
36-
TracerScopeT,
35+
[K in keyof States<TracerScopeKeysT, AllPossibleScopesT>[State]]: States<
36+
TracerScopeKeysT,
3737
AllPossibleScopesT
3838
>[State][K] extends (...args: infer ArgsT) => infer ReturnT
3939
? [K, ArgsT[0], ReturnT]
4040
: never
41-
}[keyof States<TracerScopeT, AllPossibleScopesT>[State]]
41+
}[keyof States<TracerScopeKeysT, AllPossibleScopesT>[State]]
4242
: never
4343

4444
type TupleToObject<T extends [PropertyKey, any, any]> = Prettify<{
@@ -49,16 +49,23 @@ type TupleToObject2<T extends [PropertyKey, any, any]> = Prettify<{
4949
[K in T[0]]: T extends [K, any, infer V] ? V : never
5050
}>
5151

52-
export type StateHandlerPayloads<TracerScopeT, AllPossibleScopesT> =
53-
TupleToObject<HandlerToPayloadTuples<TracerScopeT, AllPossibleScopesT>>
52+
export type StateHandlerPayloads<
53+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
54+
AllPossibleScopesT,
55+
> = TupleToObject<HandlerToPayloadTuples<TracerScopeKeysT, AllPossibleScopesT>>
5456

55-
export type StateHandlerReturnTypes<TracerScopeT, AllPossibleScopesT> =
56-
TupleToObject2<HandlerToPayloadTuples<TracerScopeT, AllPossibleScopesT>>
57+
export type StateHandlerReturnTypes<
58+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
59+
AllPossibleScopesT,
60+
> = TupleToObject2<HandlerToPayloadTuples<TracerScopeKeysT, AllPossibleScopesT>>
5761

58-
export type MergedStateHandlerMethods<TracerScopeT, AllPossibleScopesT> = {
59-
[K in keyof StateHandlerPayloads<TracerScopeT, AllPossibleScopesT>]: (
60-
payload: StateHandlerPayloads<TracerScopeT, AllPossibleScopesT>[K],
61-
) => StateHandlerReturnTypes<TracerScopeT, AllPossibleScopesT>[K]
62+
export type MergedStateHandlerMethods<
63+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
64+
AllPossibleScopesT,
65+
> = {
66+
[K in keyof StateHandlerPayloads<TracerScopeKeysT, AllPossibleScopesT>]: (
67+
payload: StateHandlerPayloads<TracerScopeKeysT, AllPossibleScopesT>[K],
68+
) => StateHandlerReturnTypes<TracerScopeKeysT, AllPossibleScopesT>[K]
6269
}
6370
export type ArrayWithAtLeastOneElement<T> = readonly [T, ...T[]]
6471
export type MapTuple<KeysTuple extends readonly unknown[], MapToValue> = {

0 commit comments

Comments
 (0)