Skip to content

Taxum / @taxum/core / middleware/builder / ServiceBuilder

Class: ServiceBuilder<Out, In>

Defined in: middleware/builder.ts:35

Declaratively construct a Service values.

ServiceBuilder provides a builder-like interface for composing layers to be applied to a Service`.

Type Parameters

Out

Out extends AnyService

In

In extends AnyService

Implements

Methods

appendRequestHeader()

appendRequestHeader(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:234

Append a header into the request.

If previous values exist, the header will have multiple values.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpRequest>

Returns

ServiceBuilder<Out, HttpService>

See

SetRequestHeaderLayer


appendResponseHeader()

appendResponseHeader(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:278

Append a header into the response.

If previous values exist, the header will have multiple values.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpResponse>

Returns

ServiceBuilder<Out, HttpService>

See

SetResponseHeaderLayer


catchError()

catchError(this): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:90

Catches errors of the following services and produces HTTP responses.

Parameters

this

ServiceBuilder<Out, HttpService>

Returns

ServiceBuilder<Out, HttpService>

See

CatchErrorLayer


compression()

compression(this): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:124

Compress response bodies.

Parameters

this

ServiceBuilder<Out, AnyService>

Returns

ServiceBuilder<Out, HttpService>

See

ResponseCompressionLayer


decompression()

decompression(this): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:133

Decompress request bodies.

Parameters

this

ServiceBuilder<Out, AnyService>

Returns

ServiceBuilder<Out, HttpService>

See

RequestDecompressionLayer


fromFn()

fromFn<Next, Request, Response>(f): ServiceBuilder<Out, Next>

Defined in: middleware/builder.ts:77

Applies a middleware function to the next service.

Type Parameters

Next

Next extends AnyService

Request

Request extends any

Response

Response extends any

Parameters

f

FromFnClosure<Next, Request, Response>

Returns

ServiceBuilder<Out, Next>

See

FromFnLayer


insertRequestHeaderIfNotPresent()

insertRequestHeaderIfNotPresent(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:247

Insert a header into the request if the header is not already present.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpRequest>

Returns

ServiceBuilder<Out, HttpService>

See

SetRequestHeaderLayer


insertResponseHeaderIfNotPresent()

insertResponseHeaderIfNotPresent(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:291

Insert a header into the response if the header is not already present.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpResponse>

Returns

ServiceBuilder<Out, HttpService>

See

SetResponseHeaderLayer


layer()

layer(inner): Out

Defined in: middleware/builder.ts:301

Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.

Parameters

inner

In

Returns

Out

Implementation of

Layer.layer


mapToHttpResponse()

mapToHttpResponse(this): ServiceBuilder<Out, HttpService<HttpResponseLike>>

Defined in: middleware/builder.ts:99

Map HttpResponseLike of the next service to anHttpResponse.

Parameters

this

ServiceBuilder<Out, HttpService>

Returns

ServiceBuilder<Out, HttpService<HttpResponseLike>>

See

MapToHttpResponseLayer


overrideRequestHeader()

overrideRequestHeader(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:219

Insert a header into the request.

If a previous value exists for the same header, it is removed and replaced with a new header value.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpRequest>

Returns

ServiceBuilder<Out, HttpService>

See

SetRequestHeaderLayer


overrideResponseHeader()

overrideResponseHeader(this, headerName, make): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:263

Insert a header into the response.

If a previous value exists for the same header, it is removed and replaced with a new header value.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName

string

make

MakeHeaderValue<HttpResponse>

Returns

ServiceBuilder<Out, HttpService>

See

SetResponseHeaderLayer


propagateRequestId()

propagateRequestId(this, headerName?): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:155

Propagate request IDs from request to response.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName?

string

Returns

ServiceBuilder<Out, HttpService>

See

PropagateRequestIdLayer


requestBodyLimit()

requestBodyLimit(this, limit): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:177

Intercept requests with oversized payloads and convert them into 4013 Payload Too Large responses.

Parameters

this

ServiceBuilder<Out, HttpService>

limit

number

Returns

ServiceBuilder<Out, HttpService>

See

RequestBodyLimitLayer


sensitiveHeaders()

sensitiveHeaders(this, headers): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:189

Mark headers as sensitive on both requests and responses.

Parameters

this

ServiceBuilder<Out, HttpService>

headers

string[]

Returns

ServiceBuilder<Out, HttpService>

See

SetSensitiveHeadersLayer


sensitiveRequestHeaders()

sensitiveRequestHeaders(this, headers): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:198

Mark headers as sensitive on requests.

Parameters

this

ServiceBuilder<Out, HttpService>

headers

string[]

Returns

ServiceBuilder<Out, HttpService>

See

SetSensitiveRequestHeadersLayer


sensitiveResponseHeaders()

sensitiveResponseHeaders(this, headers): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:207

Mark headers as sensitive on responses.

Parameters

this

ServiceBuilder<Out, HttpService>

headers

string[]

Returns

ServiceBuilder<Out, HttpService>

See

SetSensitiveRequestHeadersLayer


setClientIp()

setClientIp(this, trustProxy): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:112

Set client IP from the request.

Parameters

this

ServiceBuilder<Out, AnyService>

trustProxy

boolean = false

Returns

ServiceBuilder<Out, HttpService>

See

SetClientIpLayer


setRequestId()

setRequestId(this, headerName?, makeRequestId?): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:142

Add request ID header and extension.

Parameters

this

ServiceBuilder<Out, HttpService>

headerName?

string

makeRequestId?

MakeRequestId

Returns

ServiceBuilder<Out, HttpService>

See

SetRequestIdLayer


traceHttp()

traceHttp(this): ServiceBuilder<Out, HttpService>

Defined in: middleware/builder.ts:167

Trace HTTP requests and responses.

Parameters

this

ServiceBuilder<Out, HttpService>

Returns

ServiceBuilder<Out, HttpService>

See

TraceLayer


withLayer()

withLayer<TOut, TIn>(layer): ServiceBuilder<Out, TIn>

Defined in: middleware/builder.ts:54

Applies a Layer to the next service.

Type Parameters

TOut

TOut extends AnyService

TIn

TIn extends AnyService

Parameters

layer

Layer<TOut, TIn>

Returns

ServiceBuilder<Out, TIn>


withOptionLayer()

withOptionLayer<TOut, TIn>(layer): ServiceBuilder<Out, TIn>

Defined in: middleware/builder.ts:66

Applies an optional Layer to the next service.

An optional layer is only possible when the consumed service equals the produced service.

Type Parameters

TOut

TOut extends AnyService

TIn

TIn extends AnyService

Parameters

layer

undefined | null | Layer<TOut, TIn>

Returns

ServiceBuilder<Out, TIn>


create()

static create(): ServiceBuilder<HttpService<HttpResponseLike>, HttpService>

Defined in: middleware/builder.ts:47

Creates a new ServiceBuilder.

Returns

ServiceBuilder<HttpService<HttpResponseLike>, HttpService>