diff --git a/packages/backend-openapi-utils/report.api.md b/packages/backend-openapi-utils/report.api.md index 2f660cd0d6..372bdafd19 100644 --- a/packages/backend-openapi-utils/report.api.md +++ b/packages/backend-openapi-utils/report.api.md @@ -102,12 +102,45 @@ export function createValidatedOpenApiRouter( }, ): ApiRouter; +// @public +export function createValidatedOpenApiRouterFromGeneratedEndpointMap< + T extends EndpointMap, +>( + spec: RequiredDoc, + options?: { + validatorOptions?: Partial['0']>; + middleware?: RequestHandler[]; + }, +): TypedRouter; + // @public (undocumented) type DiscriminateUnion = Extract< T, Record >; +// @public (undocumented) +type DocEndpoint = ValueOf<{ + [Template in keyof Doc]: Template extends `#${string}|${infer Endpoint}` + ? Endpoint + : never; +}>; + +// @public (undocumented) +type DocEndpointMethod< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, +> = ValueOf<{ + [Template in keyof Doc]: Template extends `#${infer Method}|${Endpoint}` + ? Method + : never; +}>; + +// @public (undocumented) +type DocEndpointTemplate = PathTemplate< + DocEndpoint +>; + // @public (undocumented) type DocOperation< Doc extends RequiredDoc, @@ -239,6 +272,85 @@ interface DocRequestMatcher< ): T; } +// @public (undocumented) +type EndpointMap = Record< + string, + { + query?: object; + body?: object; + response?: object; + path?: object; + } +>; + +// @public +type EndpointMapRequestHandler< + Doc extends EndpointMap, + Path extends DocEndpoint, + Method extends DocEndpointMethod, +> = core.RequestHandler< + StaticPathParamsSchema, + StaticResponseSchema, + StaticRequestBodySchema, + StaticQueryParamsSchema, + Record +>; + +// @public +type EndpointMapRequestHandlerParams< + Doc extends EndpointMap, + Path extends DocEndpoint, + Method extends DocEndpointMethod, +> = core.RequestHandlerParams< + StaticPathParamsSchema, + StaticResponseSchema, + StaticRequestBodySchema, + StaticQueryParamsSchema, + Record +>; + +// @public +interface EndpointMapRequestMatcher< + Doc extends EndpointMap, + T, + Method extends HttpMethods, +> { + // (undocumented) + < + TPath extends MethodAwareDocEndpoints< + Doc, + DocEndpoint, + Method & DocEndpointMethod> + >, + TMethod extends Method & + DocEndpointMethod>, + >( + path: TPath, + ...handlers: Array< + EndpointMapRequestHandler, TMethod> + > + ): T; + // (undocumented) + < + TPath extends MethodAwareDocEndpoints< + Doc, + DocEndpoint, + Method & DocEndpointMethod> + >, + TMethod extends Method & + DocEndpointMethod>, + >( + path: TPath, + ...handlers: Array< + EndpointMapRequestHandlerParams< + Doc, + TemplateToDocEndpoint, + TMethod + > + > + ): T; +} + // @public (undocumented) type Filter = T extends U ? T : never; @@ -278,6 +390,9 @@ type HeaderSchema< Method extends DocPathMethod, > = ParametersSchema; +// @public (undocumented) +type HttpMethods = 'all' | 'put' | 'get' | 'post' | '_delete'; + // @public type Immutable = T extends | Function @@ -401,6 +516,21 @@ declare namespace internal { Response_3 as Response, ResponseSchemas, ResponseBodyToJsonSchema, + EndpointMap, + HttpMethods, + StaticPathParamsSchema, + StaticRequestBodySchema, + StaticResponseSchema, + StaticQueryParamsSchema, + EndpointMapRequestHandler, + EndpointMapRequestHandlerParams, + DocEndpoint, + DocEndpointMethod, + MethodAwareDocEndpoints, + DocEndpointTemplate, + TemplateToDocEndpoint, + EndpointMapRequestMatcher, + TypedRouter, }; } export { internal }; @@ -427,6 +557,19 @@ type MapToSchema< : never; }; +// @public (undocumented) +type MethodAwareDocEndpoints< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, + Method extends DocEndpointMethod, +> = ValueOf<{ + [Template in keyof Doc]: Template extends `#${Method}|${infer E}` + ? E extends DocEndpoint + ? PathTemplate + : never + : never; +}>; + // @public (undocumented) type MethodAwareDocPath< Doc extends PathDoc, @@ -513,7 +656,7 @@ type PathSchema< > = ParametersSchema; // @public -type PathTemplate = +export type PathTemplate = Path extends `${infer Prefix}{${infer PathName}}${infer Suffix}` ? `${Prefix}:${PathName}${PathTemplate}` : Path; @@ -684,6 +827,60 @@ type SchemaRef = Schema extends { [Key in keyof Schema]: SchemaRef; }; +// @public (undocumented) +type StaticPathParamsSchema< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, + Method extends DocEndpointMethod, +> = `#${Method}|${Endpoint}` extends keyof Doc + ? 'path' extends keyof Doc[`#${Method}|${Endpoint}`] + ? Doc[`#${Method}|${Endpoint}`]['path'] + : never + : never; + +// @public (undocumented) +type StaticQueryParamsSchema< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, + Method extends DocEndpointMethod, +> = `#${Method}|${Endpoint}` extends keyof Doc + ? 'query' extends keyof Doc[`#${Method}|${Endpoint}`] + ? Doc[`#${Method}|${Endpoint}`]['query'] + : never + : never; + +// @public (undocumented) +type StaticRequestBodySchema< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, + Method extends DocEndpointMethod, +> = `#${Method}|${Endpoint}` extends keyof Doc + ? 'body' extends keyof Doc[`#${Method}|${Endpoint}`] + ? Doc[`#${Method}|${Endpoint}`]['body'] + : unknown + : unknown; + +// @public (undocumented) +type StaticResponseSchema< + Doc extends EndpointMap, + Endpoint extends DocEndpoint, + Method extends DocEndpointMethod, +> = `#${Method}|${Endpoint}` extends keyof Doc + ? 'response' extends keyof Doc[`#${Method}|${Endpoint}`] + ? Doc[`#${Method}|${Endpoint}`]['response'] + : unknown + : unknown; + +// @public (undocumented) +type TemplateToDocEndpoint< + Doc extends EndpointMap, + Path extends DocEndpointTemplate, +> = ValueOf<{ + [Template in DocEndpoint]: Path extends PathTemplate