Skip to main content

OperationContext

@webda/core


Class: OperationContext<Input, Parameters, Output>

Defined in: packages/core/src/contexts/operationcontext.ts:27

OperationContext is used when call to an operation

Param​

T

type of input for this context

Param​

U

type of output for this context

Param​

P

type of parameters for this context

Extends​

Extended by​

Type Parameters​

Input​

Input = any

Parameters​

Parameters = any

Output​

Output = any

Properties​

_body​

protected _body: string

Defined in: packages/core/src/contexts/operationcontext.ts:44

Output


_promises​

_promises: Promise<any>[]

Defined in: packages/core/src/contexts/icontext.ts:33

Contain all registered promises to this context

Inherited from​

IOperationContext._promises


_sanitized​

protected _sanitized: any

Defined in: packages/core/src/contexts/operationcontext.ts:39

Contain the sanitized request body if computed


_stream​

_stream: Writable

Defined in: packages/core/src/contexts/operationcontext.ts:80

Output stream


caches​

caches: any

Defined in: packages/core/src/contexts/icontext.ts:19

Get the caches linked to the context

Inherited from​

IOperationContext.caches


extensions​

protected extensions: object

Defined in: packages/core/src/contexts/icontext.ts:23

Allow extensions

Index Signature​

[key: string]: any

Inherited from​

IOperationContext.extensions


flushed​

protected flushed: boolean = false

Defined in: packages/core/src/contexts/icontext.ts:37

If the headers were flushed

Inherited from​

IOperationContext.flushed


parameters​

parameters: Parameters

Defined in: packages/core/src/contexts/operationcontext.ts:51


session​

protected session: Session

Defined in: packages/core/src/contexts/operationcontext.ts:35

Session

Methods​

addAsyncRequest()​

addAsyncRequest(promise): void

Defined in: packages/core/src/contexts/operationcontext.ts:131

Register a promise with the context

Parameters​

promise​

any

the promise to add

Returns​

void


clearInput()​

clearInput(): void

Defined in: packages/core/src/contexts/operationcontext.ts:156

Remove the input

Returns​

void

Overrides​

IOperationContext.clearInput


createStream()​

createStream(): void

Defined in: packages/core/src/contexts/operationcontext.ts:275

Create a buffer stream

Returns​

void


end()​

end(): Promise<void>

Defined in: packages/core/src/contexts/operationcontext.ts:149

Ensure the whole execution is finished

Returns​

Promise<void>

Overrides​

IOperationContext.end


flushHeaders()​

flushHeaders(): Promise<void>

Defined in: packages/core/src/contexts/icontext.ts:134

Send the headers to the client

Returns​

Promise<void>

Inherited from​

IOperationContext.flushHeaders


getCurrentUser()​

getCurrentUser<K>(refresh?): Promise<K>

Defined in: packages/core/src/contexts/operationcontext.ts:331

Get the current user from session

Type Parameters​

K​

K extends IUser

Parameters​

refresh?​

boolean = false

whether to refresh

Returns​

Promise<K>

the result

Overrides​

IOperationContext.getCurrentUser


getCurrentUserId()​

getCurrentUserId(): string

Defined in: packages/core/src/contexts/operationcontext.ts:351

Get the current user id from session

A session waiting for its second factor (mfa: "pending") is not logged: it has no current user. Code that needs the pending user reads getSession().userId.

Returns​

string

the result

Overrides​

IOperationContext.getCurrentUserId


getExtension()​

getExtension<K>(name): K

Defined in: packages/core/src/contexts/operationcontext.ts:86

Get an extension of the context

Type Parameters​

K​

K = any

Parameters​

name​

string

of the extension

Returns​

K

extension object

Overrides​

IOperationContext.getExtension


getInput()​

getInput(sanitizedOptions?): Promise<Input>

Defined in: packages/core/src/contexts/operationcontext.ts:165

Get the sanitized input body, caching the result after the first call

Parameters​

sanitizedOptions?​

IOptions & object = ...

the sanitized options

Returns​

Promise<Input>

the result

Overrides​

IOperationContext.getInput


getOutput()​

getOutput(): string

Defined in: packages/core/src/contexts/operationcontext.ts:139

Get output as string, if a OutputStream is provided it will returned null

Returns​

string

the result string


getOutputStream()​

getOutputStream(): Promise<Writable>

Defined in: packages/core/src/contexts/operationcontext.ts:240

Get the HTTP stream to output raw data

Returns​

Promise<Writable>

the result

Overrides​

IOperationContext.getOutputStream


getParameters()​

getParameters(): Parameters

Defined in: packages/core/src/contexts/operationcontext.ts:104

Get the parameters

Returns​

Parameters

the result

Overrides​

IOperationContext.getParameters


getRawInput()​

getRawInput(_limit?, _timeout?): Promise<Buffer<ArrayBufferLike>>

Defined in: packages/core/src/contexts/operationcontext.ts:225

Parameters​

_limit?​

number = ...

_timeout?​

number = 60000

Returns​

Promise<Buffer<ArrayBufferLike>>

Overrides​

IOperationContext.getRawInput


getRawInputAsString()​

getRawInputAsString(limit?, timeout?, encoding?): Promise<string>

Defined in: packages/core/src/contexts/operationcontext.ts:214

By default empty

Parameters​

limit?​

number = ...

the maximum count

timeout?​

number = 60000

the timeout in milliseconds

encoding?​

BufferEncoding

the encoding to use

Returns​

Promise<string>

the result string


getRawStream()​

getRawStream(): Readable

Defined in: packages/core/src/contexts/operationcontext.ts:232

Returns​

Readable


getResponseHeaders()​

getResponseHeaders(): any

Defined in: packages/core/src/contexts/icontext.ts:127

Get current response headers

Returns​

any

the result

Inherited from​

IOperationContext.getResponseHeaders


getSession()​

getSession<K>(): K

Defined in: packages/core/src/contexts/operationcontext.ts:249

Get linked session

Type Parameters​

K​

K = Session

Returns​

K

the result

Overrides​

IOperationContext.getSession


init()​

init(): Promise<OperationContext<Input, Parameters, Output>>

Defined in: packages/core/src/contexts/operationcontext.ts:322

Initialize the operation context

Returns​

Promise<OperationContext<Input, Parameters, Output>>

this for chaining

Overrides​

IOperationContext.init


isGlobalContext()​

isGlobalContext(): boolean

Defined in: packages/core/src/contexts/icontext.ts:43

Whether this is the global (non-request-scoped) context

Returns​

boolean

true if the condition is met

Inherited from​

IOperationContext.isGlobalContext


newSession()​

newSession(): Session

Defined in: packages/core/src/contexts/operationcontext.ts:257

Create and assign a new empty session

Returns​

Session

the result

Overrides​

IOperationContext.newSession


parameter()​

parameter(name, defaultValue?): any

Defined in: packages/core/src/contexts/operationcontext.ts:96

Get one parameter

Parameters​

name​

string

the name to use

defaultValue?​

any = undefined

the default value

Returns​

any

the result

Overrides​

IOperationContext.parameter


pipeline()​

pipeline(stream1, ...streams): Promise<void>

Defined in: packages/core/src/contexts/icontext.ts:149

Pipeline streams into the output stream

Parameters​

stream1​

ReadableStream

the first stream

streams​

...(ReadWriteStream | PipelineOptions)[]

additional streams

Returns​

Promise<void>

See​

https://nodejs.org/api/stream.html#streampipelinestreams-options

Inherited from​

IOperationContext.pipeline


registerPromise()​

registerPromise(promise): void

Defined in: packages/core/src/contexts/icontext.ts:56

Register a promise with the context

Parameters​

promise​

any

the promise to add

Returns​

void

Inherited from​

IOperationContext.registerPromise


reinit()​

reinit(): void

Defined in: packages/core/src/contexts/operationcontext.ts:265

Remove sanitized body

Returns​

void


resetResponse()​

resetResponse(): void

Defined in: packages/core/src/contexts/operationcontext.ts:285

Remove everything that was about to be sent

Returns​

void


setExtension()​

setExtension(name, extension): this

Defined in: packages/core/src/contexts/operationcontext.ts:122

Parameters​

name​

string

to add

extension​

any

object to store

Returns​

this

this for chaining

Overrides​

IOperationContext.setExtension


setHeader()​

setHeader(name, value): void

Defined in: packages/core/src/contexts/icontext.ts:104

Set a header in the response

Parameters​

name​

string

the name to use

value​

string | number | string[]

the value to set

Returns​

void

Inherited from​

IOperationContext.setHeader


setParameters()​

setParameters(params): void

Defined in: packages/core/src/contexts/operationcontext.ts:112

Set the parameters

Parameters​

params​

Parameters

the service parameters

Returns​

void


setSession()​

setSession(session): void

Defined in: packages/core/src/contexts/operationcontext.ts:73

Set the session

Parameters​

session​

Session

the session object

Returns​

void

Overrides​

IOperationContext.setSession


write()​

write(output, _encoding?, _cb?): boolean

Defined in: packages/core/src/contexts/operationcontext.ts:301

Write data to the client

Parameters​

output​

Output

If it is an object it will be serialized with toPublicJSON, if it is a String it will be appended to the result, if it is a buffer it will replace the result

_encoding?​

string

the encoding to use

_cb?​

(error) => void

the callback function

Returns​

boolean

true if the condition is met

Overrides​

IOperationContext.write


writeHead()​

writeHead(_code, headers): void

Defined in: packages/core/src/contexts/icontext.ts:116

For easier compatibility with WebContext On OperationContext this call is simply ignored

Parameters​

_code​

number

the status code

headers​

Returns​

void

Inherited from​

IOperationContext.writeHead