protocat
Enumerations
Classes
Interfaces
Type Aliases
Middleware
Ƭ Middleware<Extension
>: (call
: ProtoCatAnyCall
<Extension
>, next
: NextFn
) => any
Type parameters
Name | Type |
---|---|
Extension | unknown |
Type declaration
▸ (call
, next
): any
Application generic middleware
Parameters
Name | Type |
---|---|
call | ProtoCatAnyCall <Extension > |
next | NextFn |
Returns
any
Defined in
ProtoCatCall
Ƭ ProtoCatCall<Extension
, Req
, Res
, Type
>: { bufferedResponse?
: Buffer
; flushInitialMetadata
: () => void
; initialMetadata
: grpc.Metadata
; meta
: Record
<string
, string
> ; metadata
: grpc.Metadata
; method
: string
; package
: string
; path
: string
; request?
: Req
; response?
: Res
; responseSerialize
: Serialize
<Res
> ; service
: string
; trailingMetadata
: grpc.Metadata
; type
: Type
} & Extension
& Type
extends Unary
? grpc.ServerUnaryCall
<Req
, Res
> & { response
: Res
} : unknown
& Type
extends ClientStream
? TypedOnData
<grpc.ServerReadableStream
<Req
, Res
>, Req
> & { response
: Res
} : unknown
& Type
extends ServerStream
? grpc.ServerWritableStream
<Req
, Res
> : unknown
& Type
extends Bidi
? TypedOnData
<grpc.ServerDuplexStream
<Req
, Res
>, Req
> : unknown
Extended gRPC call
Type parameters
Name | Type |
---|---|
Extension | unknown |
Req | Message |
Res | Message |
Type | extends CallType = CallType |
Defined in
ServiceImplementation
Ƭ ServiceImplementation<T
, Extension
>: RemoveIdxSgn
<{ [M in keyof T]: MethodDef2ServiceHandler<T[M], Extension> }>
Create service handler type for whole client definition.
Useful for better code-splitting
const unaryHandler: ServiceImplementation<
IGreetingService,
MyContext
>['unary'] = call => call.uid
Type parameters
Name | Type |
---|---|
T | T |
Extension | unknown |
Defined in
Functions
accessLogInterceptor
▸ accessLogInterceptor(fn
): Interceptor
Parameters
Name | Type |
---|---|
fn | (context : { metadata : Metadata ; options : InterceptorOptions }, next : () => Promise <StatusObject >) => any |
Returns
Interceptor
Defined in
lib/client/interceptors/access-log-interceptor.ts:4
createCache
▸ createCache<E
>(cache
, cb?
): Middleware
<E
>
Type parameters
Name | Type |
---|---|
E | unknown |
Parameters
Name | Type | Description |
---|---|---|
cache | CacheImplementation <E > | Response binary cache implementation |
cb? | (call : ProtoCatCall <E , Message , Message , Unary >, hit : boolean , hash : string ) => any | Optional callback to react on cache miss/hit. Called once per request ASAP after cache retrieval |
Returns
Middleware
<E
>
Defined in
lib/server/middleware/cache.ts:28
createClient
▸ createClient<D
>(clientDef
, address
, creds?
, options?
): D
extends (...args
: any
[]) => C
? UpdatedClient_
<C
> : { [K in string | number | symbol]: D[K] extends Function ? UpdatedClient_<C_> : never }
Type parameters
Name | Type |
---|---|
D | extends Record <string , (...args : any []) => Client > | (...args : any []) => Client |
Parameters
Name | Type |
---|---|
clientDef | D |
address | string |
creds? | ChannelCredentials |
options? | Partial <ClientOptions > |
Returns
D
extends (...args
: any
[]) => C
? UpdatedClient_
<C
> : { [K in string | number | symbol]: D[K] extends Function ? UpdatedClient_<C_> : never }
Defined in
metadataInterceptor
▸ metadataInterceptor(fn
): Interceptor
Parameters
Name | Type |
---|---|
fn | (metadata : Metadata , options : InterceptorOptions ) => any |
Returns
Interceptor
Defined in
lib/client/interceptors/metadata-interceptor.ts:4
onError
▸ onError(handler
): Middleware
<unknown
>
onError creates a ProtoCat middleware that can be used to intercept errors from various origins, either from:
- sync throws (or async rejects) from the following middlewares (or handlers) in the call stack (chain of next functions)
- error emits on streamed calls
No error is ever send to client
app.use(onError(() => {}))
Errors are logged and rethrown without stack trace
app.use(onError((e, call) => {
console.log(e, call)
e.stack = undefined
throw e
}))
Parameters
Name | Type | Description |
---|---|---|
handler | ErrorHandler | Custom error handler for re-throwing errors and error emits. Result is awaited. |
Returns
Middleware
<unknown
>