Skip to main content

Context

@webda/core


Abstract Class: Context

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

Context is the object that will be passed to the services

Extended by​

Constructors​

Constructor​

new Context(): Context

Returns​

Context

Properties​

_promises​

_promises: Promise<any>[]

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

Contain all registered promises to this context


caches​

caches: any

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

Get the caches linked to the context


extensions​

protected extensions: object

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

Allow extensions

Index Signature​

[key: string]: any


flushed​

protected flushed: boolean = false

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

If the headers were flushed

Methods​

end()​

end(): Promise<void>

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

Ensure the whole execution is finished

Returns​

Promise<void>


flushHeaders()​

flushHeaders(): Promise<void>

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

Send the headers to the client

Returns​

Promise<void>


getCurrentUser()​

abstract getCurrentUser(): Promise<any>

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

Return the user

This method is not typed to avoid circular dependencies

Returns​

Promise<any>


getCurrentUserId()​

abstract getCurrentUserId(): string

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

Get current user id

Returns​

string


getExtension()​

getExtension<K>(name): K

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

Get an extension of the context

Type Parameters​

K​

K = any

Parameters​

name​

string

of the extension

Returns​

K

extension object


getOutputStream()​

abstract getOutputStream(): Promise<Writable>

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

Returns​

Promise<Writable>


getResponseHeaders()​

getResponseHeaders(): any

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

Get current response headers

Returns​

any

the result


getSession()​

abstract getSession(): any

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

Get the session linked to the context if exists

Returns​

any


init()​

init(): Promise<Context>

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

Can be used to init the context if needed Reading from the input or reaching to a db

Returns​

Promise<Context>

this for chaining


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


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


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


setExtension()​

setExtension(name, extension): this

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

Parameters​

name​

string

to add

extension​

any

object to store

Returns​

this

this for chaining


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


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