Skip to content

Commit

Permalink
[APM] TypeScript performance fix (#120754)
Browse files Browse the repository at this point in the history
* [APM] TypeScript performance fix

* Clarify use_apm_params split with comments

* Remove ts-expect-error for security plugin

* Fix type error in searchtypes
  • Loading branch information
dgieselaar authored Dec 9, 2021
1 parent c3d9c0c commit 5b359a9
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 578 deletions.
169 changes: 71 additions & 98 deletions packages/kbn-typed-react-router-config/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,13 @@ import { RequiredKeys, ValuesType } from 'utility-types';
// import { unconst } from '../unconst';
import { NormalizePath } from './utils';

type PathsOfRoute<TRoute extends Route> =
| TRoute['path']
| (TRoute extends { children: Route[] }
? AppendPath<TRoute['path'], '/*'> | PathsOf<TRoute['children']>
: never);

export type PathsOf<TRoutes extends Route[]> = TRoutes extends []
? never
: TRoutes extends [Route]
? PathsOfRoute<TRoutes[0]>
: TRoutes extends [Route, Route]
? PathsOfRoute<TRoutes[0]> | PathsOfRoute<TRoutes[1]>
: TRoutes extends [Route, Route, Route]
? PathsOfRoute<TRoutes[0]> | PathsOfRoute<TRoutes[1]> | PathsOfRoute<TRoutes[2]>
: TRoutes extends [Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
: TRoutes extends [Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
: TRoutes extends [Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
: TRoutes extends [Route, Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
| PathsOfRoute<TRoutes[6]>
: TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
| PathsOfRoute<TRoutes[6]>
| PathsOfRoute<TRoutes[7]>
: TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
| PathsOfRoute<TRoutes[6]>
| PathsOfRoute<TRoutes[7]>
| PathsOfRoute<TRoutes[8]>
: TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
| PathsOfRoute<TRoutes[6]>
| PathsOfRoute<TRoutes[7]>
| PathsOfRoute<TRoutes[8]>
| PathsOfRoute<TRoutes[9]>
: TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route, Route, Route]
?
| PathsOfRoute<TRoutes[0]>
| PathsOfRoute<TRoutes[1]>
| PathsOfRoute<TRoutes[2]>
| PathsOfRoute<TRoutes[3]>
| PathsOfRoute<TRoutes[4]>
| PathsOfRoute<TRoutes[5]>
| PathsOfRoute<TRoutes[6]>
| PathsOfRoute<TRoutes[7]>
| PathsOfRoute<TRoutes[8]>
| PathsOfRoute<TRoutes[9]>
| PathsOfRoute<TRoutes[10]>
: string;
// type PathsOfRoute<TRoute extends Route> =
// | TRoute['path']
// | (TRoute extends { children: Route[] }
// ? AppendPath<TRoute['path'], '/*'> | PathsOf<TRoute['children']>
// : never);

export type PathsOf<TRoutes extends Route[]> = keyof MapRoutes<TRoutes> & string;

export interface RouteMatch<TRoute extends Route = Route> {
route: TRoute;
Expand Down Expand Up @@ -347,6 +263,14 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]

// const routes = unconst([
// {
// path: '/link-to/transaction/{transactionId}',
// element,
// },
// {
// path: '/link-to/trace/{traceId}',
// element,
// },
// {
// path: '/',
// element,
// children: [
Expand Down Expand Up @@ -393,6 +317,10 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// element,
// },
// {
// path: '/settings/agent-keys',
// element,
// },
// {
// path: '/settings',
// element,
// },
Expand Down Expand Up @@ -430,11 +358,19 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// element,
// },
// {
// path: '/services/:serviceName/transactions/view',
// element,
// },
// {
// path: '/services/:serviceName/dependencies',
// element,
// },
// {
// path: '/services/:serviceName/errors',
// element,
// children: [
// {
// path: '/:groupId',
// path: '/services/:serviceName/errors/:groupId',
// element,
// params: t.type({
// path: t.type({
Expand All @@ -443,7 +379,7 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// }),
// },
// {
// path: '/services/:serviceName',
// path: '/services/:serviceName/errors',
// element,
// params: t.partial({
// query: t.partial({
Expand All @@ -457,15 +393,33 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// ],
// },
// {
// path: '/services/:serviceName/foo',
// path: '/services/:serviceName/metrics',
// element,
// },
// {
// path: '/services/:serviceName/nodes',
// element,
// children: [
// {
// path: '/services/{serviceName}/nodes/{serviceNodeName}/metrics',
// element,
// },
// {
// path: '/services/:serviceName/nodes',
// element,
// },
// ],
// },
// {
// path: '/services/:serviceName/service-map',
// element,
// },
// {
// path: '/services/:serviceName/bar',
// path: '/services/:serviceName/logs',
// element,
// },
// {
// path: '/services/:serviceName/baz',
// path: '/services/:serviceName/profiling',
// element,
// },
// {
Expand Down Expand Up @@ -497,6 +451,24 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// element,
// },
// {
// path: '/backends',
// element,
// children: [
// {
// path: '/backends/{backendName}/overview',
// element,
// },
// {
// path: '/backends/overview',
// element,
// },
// {
// path: '/backends',
// element,
// },
// ],
// },
// {
// path: '/',
// element,
// },
Expand All @@ -509,15 +481,16 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
// type Routes = typeof routes;

// type Mapped = keyof MapRoutes<Routes>;
// type Paths = PathsOf<Routes>;

// type Bar = ValuesType<Match<Routes, '/*'>>['route']['path'];
// type Foo = OutputOf<Routes, '/*'>;
// type Baz = OutputOf<Routes, '/services/:serviceName/baz'>;
// // type Baz = OutputOf<Routes, '/services/:serviceName/errors'>;

// const { path }: Foo = {} as any;

// function _useApmParams<TPath extends PathsOf<Routes>>(p: TPath): OutputOf<Routes, TPath> {
// return {} as any;
// }

// const params = _useApmParams('/*');
// // const params = _useApmParams('/services/:serviceName/nodes/*');
Loading

0 comments on commit 5b359a9

Please sign in to comment.