Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streams] App plugin #200060

Merged
merged 99 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5fe1078
Initial setup for streams plugin
simianhacker Oct 31, 2024
6f940eb
migrating to the streams naming schema; adding an abstraction for the…
simianhacker Nov 1, 2024
9b33808
ensure forked streams are marked root:false
simianhacker Nov 1, 2024
c8cd0f7
Commit entities plugins
dgieselaar Nov 6, 2024
7e8f2d7
Move files into streams_*
dgieselaar Nov 6, 2024
999dfef
Rename stuff & remove stuff
dgieselaar Nov 6, 2024
d99a3ff
stream management
flash1293 Nov 8, 2024
0e89345
add delete and listing endpoint
flash1293 Nov 8, 2024
9dd5fde
cleanup
flash1293 Nov 8, 2024
7400a3b
add resync endpoint
flash1293 Nov 8, 2024
5140687
Remove cruft, handle package relocation
dgieselaar Nov 10, 2024
797c93d
Streams table
dgieselaar Nov 10, 2024
fcce628
Only fetch histogram when DS exists
dgieselaar Nov 10, 2024
9d37219
more fixes
flash1293 Nov 10, 2024
d622fa1
more adjustments
flash1293 Nov 11, 2024
fbc6c2a
some more fixes
flash1293 Nov 11, 2024
45787d0
Merge remote-tracking branch 'upstream/main' into init-streams-plugin
flash1293 Nov 12, 2024
e810f53
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Nov 12, 2024
e93ac17
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 12, 2024
cf9f349
add limits
flash1293 Nov 12, 2024
0d676ed
Merge branch 'init-streams-plugin' of github.com:simianhacker/kibana …
flash1293 Nov 12, 2024
7b0a4e5
Add streams to left nav
dgieselaar Nov 12, 2024
34f3c44
fix permissions
flash1293 Nov 12, 2024
0b7de24
remove feature completely
flash1293 Nov 12, 2024
76ed81d
cleanup
flash1293 Nov 12, 2024
2427d2e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 12, 2024
2ad08f4
Merge branch 'main' into init-streams-plugin
flash1293 Nov 12, 2024
c8d99ed
Merge branch 'main' into init-streams-plugin
flash1293 Nov 12, 2024
8c707d1
Merge commit '0d676edfc0681f18d3804e079bad09053bf32247' into init-str…
dgieselaar Nov 12, 2024
e6bb640
[Observability] Split up observability-utils package
dgieselaar Nov 12, 2024
421ea5b
Merge branch 'main' of github.com:elastic/kibana into observability-u…
dgieselaar Nov 12, 2024
7992539
Fix references
dgieselaar Nov 12, 2024
95ae9f8
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 12, 2024
7a88cc5
Fix issues in APM plugin
dgieselaar Nov 12, 2024
74f0678
Merge branch 'observability-utils-pkg-split' of github.com:dgieselaar…
dgieselaar Nov 12, 2024
dab77c1
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Nov 12, 2024
a60a165
Updating the owners and CODEOWNERS to @simianhacker @flash1293 @dgies…
simianhacker Nov 12, 2024
fc031f8
Merge branch 'main' of github.com:elastic/kibana into init-streams-pl…
simianhacker Nov 12, 2024
e9189e0
Merge branch 'main' of github.com:elastic/kibana into observability-u…
dgieselaar Nov 13, 2024
08aef83
Merge branch 'observability-utils-pkg-split' of github.com:dgieselaar…
dgieselaar Nov 13, 2024
2bef512
Fix references
dgieselaar Nov 13, 2024
5c10198
Option to unset value on error
dgieselaar Nov 13, 2024
5d40445
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
9ca2da2
Fix lingering import
dgieselaar Nov 13, 2024
8b0b51c
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
d655c0a
Clean up esql signature
dgieselaar Nov 13, 2024
8e0eba8
Handle sync callbacks in withSpan
dgieselaar Nov 13, 2024
eb61e23
Merge branch 'observability-utils-pkg-split' into init-streams-app-pl…
dgieselaar Nov 13, 2024
5e90008
Make APIs internal
dgieselaar Nov 13, 2024
dd55c3a
Merge branch 'init-streams-plugin' into init-streams-app-plugin
dgieselaar Nov 13, 2024
b9896ab
Merge remote-tracking branch 'upstream/main' into init-streams-app-pl…
dgieselaar Nov 13, 2024
377b365
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 13, 2024
b556194
Move to x-pack/plugins/streams_app
dgieselaar Nov 13, 2024
aa4a2e0
Improve types
dgieselaar Nov 13, 2024
f0276dc
Improve type strictness
dgieselaar Nov 13, 2024
adcd660
Update .i18nrc.json
dgieselaar Nov 14, 2024
224ffeb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 14, 2024
2edc694
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 14, 2024
bb4dc6e
Conditionally register items in side nav
dgieselaar Nov 14, 2024
2b74f6c
Clean up
dgieselaar Nov 14, 2024
46ffca7
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Nov 14, 2024
bd6f225
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 19, 2024
1ec3a20
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 19, 2024
922d1b4
Review feedback
dgieselaar Nov 19, 2024
d6ee23e
Remove unflattening/field resolution
dgieselaar Nov 19, 2024
ad2cc5e
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 19, 2024
26f5554
Update paths in jest.config.js
dgieselaar Nov 19, 2024
8dc61f3
Update i18n label
dgieselaar Nov 19, 2024
1fde5b4
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 19, 2024
3ffefbb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 19, 2024
f032b51
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 21, 2024
ac426f5
Add transform option
dgieselaar Nov 21, 2024
97510ca
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 21, 2024
a950210
Fix types in investigate_app
dgieselaar Nov 21, 2024
84e233e
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 21, 2024
d2ba657
Fix jest.config.js
dgieselaar Nov 21, 2024
c219042
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 22, 2024
1250723
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Nov 22, 2024
9a487e4
Use top-level security property
dgieselaar Nov 22, 2024
7452c8b
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 22, 2024
5245055
Fix types in onboarding
dgieselaar Nov 22, 2024
90389fc
Fix type issues in Streams app
dgieselaar Nov 22, 2024
0d8e0eb
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 23, 2024
76d2042
Add tests
dgieselaar Nov 23, 2024
e12aaec
Migrate options.security, fix issues with routing
dgieselaar Nov 23, 2024
1baac8f
Migrate options.security
dgieselaar Nov 23, 2024
3947668
Migrate options.security for entityManager
dgieselaar Nov 23, 2024
8ed5d23
Catch error in _status call
dgieselaar Nov 23, 2024
1ce43ab
Add streams to app usage schema
dgieselaar Nov 23, 2024
7065f3d
fix telemetry
dgieselaar Nov 23, 2024
ddaabc1
Type changes
dgieselaar Nov 24, 2024
a47ed43
Merge branch 'main' of github.com:elastic/kibana into init-streams-ap…
dgieselaar Nov 24, 2024
d57be23
Update CODEOWNERS
dgieselaar Nov 24, 2024
003c3e6
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 24, 2024
830fc5d
More flexible types
dgieselaar Nov 24, 2024
95440e2
Merge branch 'init-streams-app-plugin' of github.com:dgieselaar/kiban…
dgieselaar Nov 24, 2024
c46d94c
Properly pass plugins to routes
dgieselaar Nov 24, 2024
cebd9d0
Strip .text/.keyword suffixes
dgieselaar Nov 25, 2024
44d5b24
Set security for route registration in dataset_quality
dgieselaar Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,14 +952,15 @@ module.exports = {
{
files: [
'x-pack/plugins/observability_solution/**/*.{ts,tsx}',
'x-pack/plugins/{streams,streams_app}/**/*.{ts,tsx}',
'x-pack/packages/observability/**/*.{ts,tsx}',
],
rules: {
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks:
'^(useAbortableAsync|useMemoWithAbortSignal|useFetcher|useProgressiveFetcher|useBreadcrumb|useAsync|useTimeRangeAsync|useAutoAbortedHttpClient)$',
'^(useAbortableAsync|useMemoWithAbortSignal|useFetcher|useProgressiveFetcher|useBreadcrumb|useAsync|useTimeRangeAsync|useAutoAbortedHttpClient|use.*Fetch)$',
},
],
},
Expand All @@ -968,6 +969,7 @@ module.exports = {
files: [
'x-pack/plugins/aiops/**/*.tsx',
'x-pack/plugins/observability_solution/**/*.tsx',
'x-pack/plugins/{streams,streams_app}/**/*.{ts,tsx}',
'src/plugins/ai_assistant_management/**/*.tsx',
'x-pack/packages/observability/**/*.{ts,tsx}',
],
Expand All @@ -984,6 +986,7 @@ module.exports = {
{
files: [
'x-pack/plugins/observability_solution/**/!(*.stories.tsx|*.test.tsx|*.storybook_decorator.tsx|*.mock.tsx)',
'x-pack/plugins/{streams,streams_app}/**/!(*.stories.tsx|*.test.tsx|*.storybook_decorator.tsx|*.mock.tsx)',
'src/plugins/ai_assistant_management/**/!(*.stories.tsx|*.test.tsx|*.storybook_decorator.tsx|*.mock.tsx)',
'x-pack/packages/observability/logs_overview/**/!(*.stories.tsx|*.test.tsx|*.storybook_decorator.tsx|*.mock.tsx)',
],
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ x-pack/plugins/spaces @elastic/kibana-security
x-pack/plugins/stack_alerts @elastic/response-ops
x-pack/plugins/stack_connectors @elastic/response-ops
x-pack/plugins/streams @simianhacker @flash1293 @dgieselaar
x-pack/plugins/streams_app @elastic/observability-ui
x-pack/plugins/task_manager @elastic/response-ops
x-pack/plugins/telemetry_collection_xpack @elastic/kibana-core
x-pack/plugins/threat_intelligence @elastic/security-threat-hunting-investigations
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ routes, etc.
|This plugin provides an interface to manage streams


|{kib-repo}blob/{branch}/x-pack/plugins/streams_app/README.md[streamsApp]
|Home of the Streams app plugin, which allows users to manage Streams via the UI.


|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/synthetics/README.md[synthetics]
|The purpose of this plugin is to provide users of Heartbeat more visibility of what's happening
in their infrastructure.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@
"@kbn/status-plugin-a-plugin": "link:test/server_integration/plugins/status_plugin_a",
"@kbn/status-plugin-b-plugin": "link:test/server_integration/plugins/status_plugin_b",
"@kbn/std": "link:packages/kbn-std",
"@kbn/streams-app-plugin": "link:x-pack/plugins/streams_app",
"@kbn/streams-plugin": "link:x-pack/plugins/streams",
"@kbn/synthetics-plugin": "link:x-pack/plugins/observability_solution/synthetics",
"@kbn/synthetics-private-location": "link:x-pack/packages/kbn-synthetics-private-location",
Expand Down
2 changes: 2 additions & 0 deletions packages/deeplinks/observability/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export const OBLT_UX_APP_ID = 'ux';
export const OBLT_PROFILING_APP_ID = 'profiling';

export const INVENTORY_APP_ID = 'inventory';

export const STREAMS_APP_ID = 'streams';
13 changes: 10 additions & 3 deletions packages/deeplinks/observability/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
OBLT_UX_APP_ID,
OBLT_PROFILING_APP_ID,
INVENTORY_APP_ID,
STREAMS_APP_ID,
} from './constants';

type LogsApp = typeof LOGS_APP_ID;
Expand All @@ -36,6 +37,7 @@ type AiAssistantApp = typeof AI_ASSISTANT_APP_ID;
type ObltUxApp = typeof OBLT_UX_APP_ID;
type ObltProfilingApp = typeof OBLT_PROFILING_APP_ID;
type InventoryApp = typeof INVENTORY_APP_ID;
type StreamsApp = typeof STREAMS_APP_ID;

export type AppId =
| LogsApp
Expand All @@ -50,7 +52,8 @@ export type AppId =
| AiAssistantApp
| ObltUxApp
| ObltProfilingApp
| InventoryApp;
| InventoryApp
| StreamsApp;

export type LogsLinkId = 'log-categories' | 'settings' | 'anomalies' | 'stream';

Expand Down Expand Up @@ -83,13 +86,16 @@ export type SyntheticsLinkId = 'certificates' | 'overview';

export type ProfilingLinkId = 'stacktraces' | 'flamegraphs' | 'functions';

export type StreamsLinkId = 'overview';

export type LinkId =
| LogsLinkId
| ObservabilityOverviewLinkId
| MetricsLinkId
| ApmLinkId
| SyntheticsLinkId
| ProfilingLinkId;
| ProfilingLinkId
| StreamsLinkId;

export type DeepLinkId =
| AppId
Expand All @@ -99,4 +105,5 @@ export type DeepLinkId =
| `${ApmApp}:${ApmLinkId}`
| `${SyntheticsApp}:${SyntheticsLinkId}`
| `${ObltProfilingApp}:${ProfilingLinkId}`
| `${InventoryApp}:${InventoryLinkId}`;
| `${InventoryApp}:${InventoryLinkId}`
| `${StreamsApp}:${StreamsLinkId}`;
2 changes: 1 addition & 1 deletion packages/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,5 +695,5 @@ export interface ESQLSearchParams {
locale?: string;
include_ccs_metadata?: boolean;
dropNullColumns?: boolean;
params?: Array<Record<string, string | undefined>>;
params?: estypesWithoutBodyKey.ScalarValue[] | Array<Record<string, string | undefined>>;
}
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pageLoadAssetSize:
stackAlerts: 58316
stackConnectors: 67227
streams: 16742
streamsApp: 20537
synthetics: 55971
telemetry: 51957
telemetryManagementSection: 38586
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
} from '@kbn/server-route-repository-utils';
import { httpResponseIntoObservable } from '@kbn/sse-utils-client';
import { from } from 'rxjs';
import { HttpFetchOptions, HttpFetchQuery, HttpResponse } from '@kbn/core-http-browser';
import { HttpFetchQuery, HttpResponse } from '@kbn/core-http-browser';
import { omit } from 'lodash';

export function createRepositoryClient<
TRepository extends ServerRouteRepository,
TClientOptions extends HttpFetchOptions = {}
TClientOptions extends Record<string, any> = {}
>(core: CoreStart | CoreSetup): RouteRepositoryClient<TRepository, TClientOptions> {
const fetch = (
endpoint: string,
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-server-route-repository-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type {
EndpointOf,
ReturnOf,
RouteRepositoryClient,
RouteState,
ClientRequestParamsOf,
DecodedRequestParamsOf,
ServerRouteRepository,
Expand Down
12 changes: 5 additions & 7 deletions packages/kbn-server-route-repository-utils/src/parse_endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
import type { RouteMethod } from '@kbn/core-http-server';

const validMethods: RouteMethod[] = ['delete', 'get', 'patch', 'post', 'put'];

export function parseEndpoint(endpoint: string) {
const parts = endpoint.split(' ');

const method = parts[0].trim().toLowerCase() as Method;
const method = parts[0].trim().toLowerCase() as Exclude<RouteMethod, 'options'>;
const pathname = parts[1].trim();
const version = parts[2]?.trim();

if (!['get', 'post', 'put', 'patch', 'delete'].includes(method)) {
if (!validMethods.includes(method)) {
throw new Error(`Endpoint ${endpoint} was not prefixed with a valid HTTP method`);
}

if (!version && pathname.startsWith('/api')) {
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Missing version for public endpoint ${endpoint}`);
}

return { method, pathname, version };
}
94 changes: 54 additions & 40 deletions packages/kbn-server-route-repository-utils/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type { HttpFetchOptions } from '@kbn/core-http-browser';
import type { IKibanaResponse } from '@kbn/core-http-server';
import type { IKibanaResponse, RouteAccess, RouteSecurity } from '@kbn/core-http-server';
import type {
KibanaRequest,
KibanaResponseFactory,
Expand All @@ -22,7 +22,7 @@ import { z } from '@kbn/zod';
import * as t from 'io-ts';
import { Observable } from 'rxjs';
import { Readable } from 'stream';
import { RequiredKeys, ValuesType } from 'utility-types';
import { Required, RequiredKeys, ValuesType } from 'utility-types';

type MaybeOptional<T extends { params?: Record<string, any> }> = RequiredKeys<
T['params']
Expand Down Expand Up @@ -50,24 +50,37 @@ export type ZodParamsObject = z.ZodObject<{
export type IoTsParamsObject = WithoutIncompatibleMethods<t.Type<RouteParams>>;

export type RouteParamsRT = IoTsParamsObject | ZodParamsObject;
export type ServerRouteHandlerResources = Record<string, any>;

export interface RouteState {
[endpoint: string]: ServerRoute<any, any, any, any, any>;
export interface ServerRouteCreateOptions {
[x: string]: any;
}

export type ServerRouteHandlerResources = Record<string, any>;
export type ServerRouteCreateOptions = Record<string, any>;
type RouteMethodOf<TEndpoint extends string> = TEndpoint extends `${infer TRouteMethod} ${string}`
? Lowercase<TRouteMethod> extends RouteMethod
? Lowercase<TRouteMethod>
: never
: never;

type ValidateEndpoint<TEndpoint extends string> = string extends TEndpoint
type IsPublicEndpoint<
TEndpoint extends string,
TRouteAccess extends RouteAccess | undefined
> = TRouteAccess extends 'public'
? true
: TEndpoint extends `${string} ${string} ${string}`
: TRouteAccess extends 'internal'
? false
: TEndpoint extends `${string} /api${string}`
? true
: TEndpoint extends `${string} ${infer TPathname}`
? TPathname extends `/internal/${string}`
? true
: false
: false;

type IsVersionSpecified<TEndpoint extends string> =
TEndpoint extends `${string} ${string} ${string}` ? true : false;

type ValidateEndpoint<
TEndpoint extends string,
TRouteAccess extends RouteAccess | undefined
> = IsPublicEndpoint<TEndpoint, TRouteAccess> extends true ? IsVersionSpecified<TEndpoint> : true;

type IsAny<T> = 1 | 0 extends (T extends never ? 1 : 0) ? true : false;

// this ensures only plain objects can be returned, if it's not one
Expand Down Expand Up @@ -127,17 +140,27 @@ type ServerRouteHandler<

export type CreateServerRouteFactory<
TRouteHandlerResources extends ServerRouteHandlerResources,
TRouteCreateOptions extends ServerRouteCreateOptions
TRouteCreateOptions extends DefaultRouteCreateOptions | undefined
> = <
TEndpoint extends string,
TReturnType extends ServerRouteHandlerReturnType,
TRouteParamsRT extends RouteParamsRT | undefined = undefined
TRouteParamsRT extends RouteParamsRT | undefined = undefined,
TRouteAccess extends RouteAccess | undefined = undefined
>(
options: {
endpoint: ValidateEndpoint<TEndpoint> extends true ? TEndpoint : never;
endpoint: ValidateEndpoint<TEndpoint, TRouteAccess> extends true ? TEndpoint : never;
handler: ServerRouteHandler<TRouteHandlerResources, TRouteParamsRT, TReturnType>;
params?: TRouteParamsRT;
} & TRouteCreateOptions
security?: RouteSecurity;
} & Required<
{
options?: (TRouteCreateOptions extends DefaultRouteCreateOptions ? TRouteCreateOptions : {}) &
RouteConfigOptions<RouteMethodOf<TEndpoint>> & {
access?: TRouteAccess;
};
},
RequiredKeys<TRouteCreateOptions> extends never ? never : 'options'
>
) => Record<
TEndpoint,
ServerRoute<
Expand All @@ -154,16 +177,17 @@ export type ServerRoute<
TRouteParamsRT extends RouteParamsRT | undefined,
TRouteHandlerResources extends ServerRouteHandlerResources,
TReturnType extends ServerRouteHandlerReturnType,
TRouteCreateOptions extends ServerRouteCreateOptions
TRouteCreateOptions extends DefaultRouteCreateOptions | undefined
> = {
endpoint: TEndpoint;
handler: ServerRouteHandler<TRouteHandlerResources, TRouteParamsRT, TReturnType>;
} & TRouteCreateOptions &
(TRouteParamsRT extends RouteParamsRT ? { params: TRouteParamsRT } : {});
security?: RouteSecurity;
} & (TRouteParamsRT extends RouteParamsRT ? { params: TRouteParamsRT } : {}) &
(TRouteCreateOptions extends DefaultRouteCreateOptions ? { options: TRouteCreateOptions } : {});

export type ServerRouteRepository = Record<
string,
ServerRoute<string, RouteParamsRT | undefined, any, any, Record<string, any>>
ServerRoute<string, RouteParamsRT | undefined, any, any, ServerRouteCreateOptions | undefined>
>;

type ClientRequestParamsOfType<TRouteParamsRT extends RouteParamsRT> =
Expand Down Expand Up @@ -194,13 +218,7 @@ export type EndpointOf<TServerRouteRepository extends ServerRouteRepository> =
export type ReturnOf<
TServerRouteRepository extends ServerRouteRepository,
TEndpoint extends keyof TServerRouteRepository
> = TServerRouteRepository[TEndpoint] extends ServerRoute<
any,
any,
any,
infer TReturnType,
ServerRouteCreateOptions
>
> = TServerRouteRepository[TEndpoint] extends ServerRoute<any, any, any, infer TReturnType, any>
? TReturnType extends IKibanaResponse<infer TWrappedResponseType>
? TWrappedResponseType
: TReturnType
Expand All @@ -209,13 +227,7 @@ export type ReturnOf<
export type DecodedRequestParamsOf<
TServerRouteRepository extends ServerRouteRepository,
TEndpoint extends keyof TServerRouteRepository
> = TServerRouteRepository[TEndpoint] extends ServerRoute<
any,
infer TRouteParamsRT,
any,
any,
ServerRouteCreateOptions
>
> = TServerRouteRepository[TEndpoint] extends ServerRoute<any, infer TRouteParamsRT, any, any, any>
? TRouteParamsRT extends RouteParamsRT
? DecodedRequestParamsOfType<TRouteParamsRT>
: {}
Expand All @@ -229,7 +241,7 @@ export type ClientRequestParamsOf<
infer TRouteParamsRT,
any,
any,
ServerRouteCreateOptions
ServerRouteCreateOptions | undefined
>
? TRouteParamsRT extends RouteParamsRT
? ClientRequestParamsOfType<TRouteParamsRT>
Expand All @@ -249,13 +261,17 @@ export interface RouteRepositoryClient<
fetch<TEndpoint extends Extract<keyof TServerRouteRepository, string>>(
endpoint: TEndpoint,
...args: MaybeOptionalArgs<
ClientRequestParamsOf<TServerRouteRepository, TEndpoint> & TAdditionalClientOptions
ClientRequestParamsOf<TServerRouteRepository, TEndpoint> &
TAdditionalClientOptions &
HttpFetchOptions
>
): Promise<ReturnOf<TServerRouteRepository, TEndpoint>>;
stream<TEndpoint extends Extract<keyof TServerRouteRepository, string>>(
endpoint: TEndpoint,
...args: MaybeOptionalArgs<
ClientRequestParamsOf<TServerRouteRepository, TEndpoint> & TAdditionalClientOptions
ClientRequestParamsOf<TServerRouteRepository, TEndpoint> &
TAdditionalClientOptions &
HttpFetchOptions
>
): ReturnOf<TServerRouteRepository, TEndpoint> extends Observable<infer TReturnType>
? TReturnType extends ServerSentEvent
Expand All @@ -276,6 +292,4 @@ export interface DefaultRouteHandlerResources extends CoreRouteHandlerResources
logger: Logger;
}

export interface DefaultRouteCreateOptions {
options?: RouteConfigOptions<RouteMethod>;
}
export type DefaultRouteCreateOptions = RouteConfigOptions<Exclude<RouteMethod, 'options'>>;
1 change: 0 additions & 1 deletion packages/kbn-server-route-repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export type {
ServerRouteRepository,
ServerRoute,
RouteParamsRT,
RouteState,
DefaultRouteCreateOptions,
DefaultRouteHandlerResources,
IoTsParamsObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
*/

import type {
DefaultRouteCreateOptions,
DefaultRouteHandlerResources,
ServerRouteCreateOptions,
ServerRouteHandlerResources,
} from '@kbn/server-route-repository-utils';
import type { CreateServerRouteFactory } from '@kbn/server-route-repository-utils/src/typings';
import type {
CreateServerRouteFactory,
DefaultRouteCreateOptions,
} from '@kbn/server-route-repository-utils/src/typings';

export function createServerRouteFactory<
TRouteHandlerResources extends ServerRouteHandlerResources = DefaultRouteHandlerResources,
TRouteCreateOptions extends ServerRouteCreateOptions = DefaultRouteCreateOptions
TRouteCreateOptions extends DefaultRouteCreateOptions | undefined = undefined
>(): CreateServerRouteFactory<TRouteHandlerResources, TRouteCreateOptions> {
return (route) => ({ [route.endpoint]: route } as any);
}
Loading