From b9c02d2b220fa3a6b56d087f4355a2f5cc715fe3 Mon Sep 17 00:00:00 2001 From: Stanislav Muhametsin <346799+stazz@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:32:57 +0200 Subject: [PATCH] #180 Fixing typings. --- .../src/endpoint-spec.ts | 34 +++++++++++++++++++ .../src/md-endpoint.ts | 10 +++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/code/backend-express-io-ts-openapi/src/endpoint-spec.ts b/code/backend-express-io-ts-openapi/src/endpoint-spec.ts index b22123f..61b6589 100644 --- a/code/backend-express-io-ts-openapi/src/endpoint-spec.ts +++ b/code/backend-express-io-ts-openapi/src/endpoint-spec.ts @@ -161,6 +161,40 @@ export type ApplicationBuilder< TAdditionalDataSpecHKT >; +/** + * This is helper type to have both {@link server.ServerContext} and `never` as context types of {@link ApplicationBuilder}. + */ +export type ApplicationBuilderAny< + TAuthenticatedState extends TStateSpecBase = typeof DEFAULT_AUTHENTICATED_STATE, + TOtherState extends TStateSpecBase = typeof DEFAULT_NOT_AUTHENTICATED_STATE, + TAllRequestBodyContentTypes extends string = typeof dataIO.CONTENT_TYPE, + TAllResponseBodyContentTypes extends string = typeof dataIO.CONTENT_TYPE, + TDefaultRequestBodyContentType extends TAllRequestBodyContentTypes = TAllRequestBodyContentTypes, + TDefaultResponseBodyContentType extends TAllResponseBodyContentTypes = TAllResponseBodyContentTypes, + // TMetadataProviders extends epSpec.TMetadataProvidersBase = MetadataProviders, + TAdditionalDataSpecHKT extends epSpec.EndpointSpecAdditionalDataHKTBase = epSpec.NoAdditionalSpecDataHKT, +> = + | ApplicationBuilder< + server.ServerContext, + TAuthenticatedState, + TOtherState, + TAllRequestBodyContentTypes, + TAllResponseBodyContentTypes, + TDefaultRequestBodyContentType, + TDefaultResponseBodyContentType, + TAdditionalDataSpecHKT + > + | ApplicationBuilder< + never, + TAuthenticatedState, + TOtherState, + TAllRequestBodyContentTypes, + TAllResponseBodyContentTypes, + TDefaultRequestBodyContentType, + TDefaultResponseBodyContentType, + TAdditionalDataSpecHKT + >; + /** * This is the {@link dataBE.MaterializeStateInfo} type for {@link DefaultStateHKT}. */ diff --git a/code/backend-express-io-ts-openapi/src/md-endpoint.ts b/code/backend-express-io-ts-openapi/src/md-endpoint.ts index c382387..31b13fb 100644 --- a/code/backend-express-io-ts-openapi/src/md-endpoint.ts +++ b/code/backend-express-io-ts-openapi/src/md-endpoint.ts @@ -23,7 +23,7 @@ import * as epSpec from "./endpoint-spec"; * @returns All of the endpoints of `creationResult` along with endpoints to serve the OpenAPI document. */ export function endpointsWithOpenAPI( - builder: epSpec.ApplicationBuilder, + builder: epSpec.ApplicationBuilderAny, creationResult: epSpecBase.EndpointsCreationResult< epSpec.MetadataProviders, server.ServerContext, @@ -58,8 +58,7 @@ export function endpointsWithOpenAPI< ...Array, ], >( - builder: epSpec.ApplicationBuilder< - server.ServerContext | never, + builder: epSpec.ApplicationBuilderAny< TAuthenticatedState, TOtherState, TAllRequestBodyContentTypes, @@ -112,8 +111,7 @@ export function endpointsWithOpenAPI< ...Array, ], >( - builder: epSpec.ApplicationBuilder< - server.ServerContext | never, + builder: epSpec.ApplicationBuilderAny< TAuthenticatedState, TOtherState, TAllRequestBodyContentTypes, @@ -140,7 +138,7 @@ export function endpointsWithOpenAPI< >, openAPIPath?: string, ): MutableServerEndpoints { - const noMD = builder.resetMetadataProviders(); + const noMD = builder.showContextToEndpoints().resetMetadataProviders(); const noURLParameters = noMD.url``({}); const params: ParametersValidation< TAuthenticatedState,