-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow 'SpanMatchDefinition' in computed spans/values
- Loading branch information
Showing
3 changed files
with
89 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
type SpanMatch, | ||
type SpanMatchDefinition, | ||
type SpanMatcherFn, | ||
fromDefinition, | ||
} from './matchSpan' | ||
import type { ScopeBase } from './types' | ||
import type { ArrayWithAtLeastOneElement } from './typeUtils' | ||
|
||
export function ensureMatcherFn< | ||
ScopeT extends ScopeBase, | ||
MatcherInputT extends | ||
| SpanMatcherFn<ScopeT> | ||
| SpanMatchDefinition<ScopeT> | ||
| string, | ||
>( | ||
matcherFnOrDefinition: MatcherInputT, | ||
): MatcherInputT extends string ? MatcherInputT : SpanMatcherFn<ScopeT> { | ||
return ( | ||
typeof matcherFnOrDefinition === 'function' || | ||
typeof matcherFnOrDefinition === 'string' | ||
? matcherFnOrDefinition | ||
: fromDefinition(matcherFnOrDefinition) | ||
) as MatcherInputT extends string ? MatcherInputT : SpanMatcherFn<ScopeT> | ||
} | ||
export function convertMatchersToFns<ScopeT extends ScopeBase>( | ||
matchers: SpanMatch<ScopeT>[] | undefined, | ||
): ArrayWithAtLeastOneElement<SpanMatcherFn<ScopeT>> | undefined { | ||
return matchers && matchers.length > 0 | ||
? (matchers.map((m) => ensureMatcherFn(m)) as ArrayWithAtLeastOneElement< | ||
SpanMatcherFn<ScopeT> | ||
>) | ||
: undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters