Skip to main content

GlobalOperationContext

@webda/core


Class: GlobalOperationContext

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

Operation context of the system

Unlike GlobalContext, it can be given to callOperation: the call gets input validation, authorizers and operation events. It has an empty session, getCurrentUserId() is "system", and the operation permission queries and the maxMfaAge check let it through. A canAct detects it with context.isGlobalContext().

Each call to useSystem or runAsSystem creates a new one: callOperation writes per-call state on it.

Extends​

Constructors​

Constructor​

new GlobalOperationContext(): GlobalOperationContext

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

Create a system context with an empty session and an empty input

Returns​

GlobalOperationContext

Overrides​

SimpleOperationContext.constructor

Properties​

_body​

protected _body: string

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

Output

Inherited from​

SimpleOperationContext._body


_modes​

protected _modes: string

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

The sanitization modes (path and mode) the cached body was sanitized with, null when the input was cleared

Inherited from​

SimpleOperationContext._modes


_promises​

_promises: Promise<any>[]

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

Contain all registered promises to this context

Inherited from​

SimpleOperationContext._promises


_sanitized​

protected _sanitized: any

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

Contain the sanitized request body if computed

Inherited from​

SimpleOperationContext._sanitized


_stream​

_stream: Writable

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

Output stream

Inherited from​

SimpleOperationContext._stream


caches​

caches: any

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

Get the caches linked to the context

Inherited from​

SimpleOperationContext.caches


extensions​

protected extensions: object

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

Allow extensions

Index Signature​

[key: string]: any

Inherited from​

SimpleOperationContext.extensions


flushed​

protected flushed: boolean = false

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

If the headers were flushed

Inherited from​

SimpleOperationContext.flushed


input​

input: Buffer

Defined in: packages/core/src/contexts/simplecontext.ts:12

Input

Inherited from​

SimpleOperationContext.input


parameters​

parameters: any

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

Parameters

Inherited from​

SimpleOperationContext.parameters


session​

protected session: Session

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

Session

Inherited from​

SimpleOperationContext.session

Methods​

addAsyncRequest()​

addAsyncRequest(promise): void

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

Register a promise with the context

Parameters​

promise​

any

the promise to add

Returns​

void

Inherited from​

SimpleOperationContext.addAsyncRequest


clearInput()​

clearInput(): void

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

Remove the input

Returns​

void

Inherited from​

SimpleOperationContext.clearInput


createStream()​

createStream(): void

Defined in: packages/core/src/contexts/globaloperationcontext.ts:29

Start with a small output buffer: runAsSystem runs on hot paths and rarely writes output

Returns​

void

Overrides​

SimpleOperationContext.createStream


drained()​

drained(): Promise<void>

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

Resolves when the client can take more streamed output. callOperation awaits it whenever write() returned false; transports with a real connection override it (backpressure, cancellation).

Returns​

Promise<void>

when more output can be written

Inherited from​

SimpleOperationContext.drained


end()​

end(): Promise<void>

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

Ensure the whole execution is finished

Returns​

Promise<void>

Inherited from​

SimpleOperationContext.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​

SimpleOperationContext.flushHeaders


getCurrentUser()​

getCurrentUser<K>(): Promise<K>

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

The system is not a user

Type Parameters​

K​

K

Returns​

Promise<K>

Overrides​

SimpleOperationContext.getCurrentUser


getCurrentUserId()​

getCurrentUserId(): string

Defined in: packages/core/src/contexts/globaloperationcontext.ts:36

Returns​

string

Overrides​

SimpleOperationContext.getCurrentUserId


getExtension()​

getExtension<K>(name): K

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

Get an extension of the context

Type Parameters​

K​

K = any

Parameters​

name​

string

of the extension

Returns​

K

extension object

Inherited from​

SimpleOperationContext.getExtension


getInput()​

getInput(sanitizedOptions?): Promise<any>

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

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

Every string is HTML-sanitized, except:

  • with raw: true, nothing is (the parsed body is returned as received, and not cached);
  • with raw: [paths], the values of these keys, whatever they hold;
  • with modes: { path: mode }, the strings at these paths (* for any array index or object key), sanitized with their mode (none, html, markdown): what an operation input schema declares with x-webda-sanitize.

The body is read again when raw is given, or when modes differs from the one of the cached body: a change made to a body read before is lost, so read it once with the options you need.

Parameters​

sanitizedOptions?​

IOptions & object & object = DEFAULT_SANITIZE_OPTIONS

the sanitized options

Returns​

Promise<any>

the result

Inherited from​

SimpleOperationContext.getInput


getOutput()​

getOutput(): string

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

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

Returns​

string

the result string

Inherited from​

SimpleOperationContext.getOutput


getOutputStream()​

getOutputStream(): Promise<Writable>

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

Get the HTTP stream to output raw data

Returns​

Promise<Writable>

the result

Inherited from​

SimpleOperationContext.getOutputStream


getParameters()​

getParameters(): any

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

Get the parameters

Returns​

any

the result

Inherited from​

SimpleOperationContext.getParameters


getRawInput()​

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

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

Parameters​

limit?​

number = ...

_timeout?​

number = 60000

Returns​

Promise<Buffer<ArrayBufferLike>>

Inherited from​

SimpleOperationContext.getRawInput


getRawInputAsString()​

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

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

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

Inherited from​

SimpleOperationContext.getRawInputAsString


getRawStream()​

getRawStream(): Readable

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

Returns​

Readable

Inherited from​

SimpleOperationContext.getRawStream


getResponseHeaders()​

getResponseHeaders(): any

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

Get current response headers

Returns​

any

the result

Inherited from​

SimpleOperationContext.getResponseHeaders


getSession()​

getSession<K>(): K

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

Get linked session

Type Parameters​

K​

K = Session

Returns​

K

the result

Inherited from​

SimpleOperationContext.getSession


init()​

init(): Promise<GlobalOperationContext>

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

Initialize the operation context

Returns​

Promise<GlobalOperationContext>

this for chaining

Inherited from​

SimpleOperationContext.init


isGlobalContext()​

isGlobalContext(): boolean

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

Returns​

boolean

Overrides​

SimpleOperationContext.isGlobalContext


newSession()​

newSession(): Session

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

Create and assign a new empty session

Returns​

Session

the result

Inherited from​

SimpleOperationContext.newSession


parameter()​

parameter(name, defaultValue?): any

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

Get one parameter

Parameters​

name​

string

the name to use

defaultValue?​

any = undefined

the default value

Returns​

any

the result

Inherited from​

SimpleOperationContext.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​

SimpleOperationContext.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​

SimpleOperationContext.registerPromise


reinit()​

reinit(): void

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

Remove sanitized body

Returns​

void

Inherited from​

SimpleOperationContext.reinit


resetResponse()​

resetResponse(): void

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

Remove everything that was about to be sent

Returns​

void

Inherited from​

SimpleOperationContext.resetResponse


setExtension()​

setExtension(name, extension): this

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

Set the extension

Parameters​

name​

string

to add

extension​

any

object to store

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.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​

SimpleOperationContext.setHeader


setInput()​

setInput(input): this

Defined in: packages/core/src/contexts/simplecontext.ts:32

Set the input

Parameters​

input​

Buffer

the input

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.setInput


setParameters()​

setParameters(params): void

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

Set the parameters

Parameters​

params​

any

the service parameters

Returns​

void

Inherited from​

SimpleOperationContext.setParameters


setSession()​

setSession(session): this

Defined in: packages/core/src/contexts/simplecontext.ts:42

Set the session

Parameters​

session​

Session

the session object

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.setSession


write()​

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

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

Write data to the client

Parameters​

output​

any

If it is an object it will be serialized as JSON without its __ keys (callOperation writes models as their DTO), 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

Inherited from​

SimpleOperationContext.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​

{[key: string]: string | number | string[]; }

Returns​

void

Inherited from​

SimpleOperationContext.writeHead


fromContext()​

static fromContext(context): Promise<SimpleOperationContext>

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

Create another context from an existing one

Parameters​

context​

OperationContext

the execution context

Returns​

Promise<SimpleOperationContext>

the result

Inherited from​

SimpleOperationContext.fromContext