StreamingOperationContext
Abstract Class: StreamingOperationContext
Defined in: packages/core/src/contexts/streamingcontext.ts:30
The shared part of a context serving a streaming operation over a transport (gRPC, WebSocket, GraphQL subscription, ...):
- a non-streamed result is buffered as usual (
writeResult()) - a streamed chunk is sent right away (
sendChunk()),write()returning false under backpressure drained()waits for the transport (waitForDrain()) without leaving listeners behind: the signal it gets is aborted once the wait is over- once cancelled (the client went away) or once the connection is over (
connectionEnded),write()anddrained()throwOperationCancelledError
The transport calls cancel() when the client leaves, and also ends the operation's input queue so its pending read
returns and its finally blocks run.
Extends
Extended by
Properties
_body
protected_body:string
Defined in: packages/core/src/contexts/operationcontext.ts:49
Output
Inherited from
_cookie
_cookie:
Map<string,Cookie>
Defined in: packages/core/src/contexts/webcontext.ts:38
Cookies to send back
Inherited from
_ended
_ended:
Promise<any> =undefined
Defined in: packages/core/src/contexts/webcontext.ts:45
Inherited from
_outputHeaders
protected_outputHeaders:OutgoingHttpHeaders
Defined in: packages/core/src/contexts/webcontext.ts:29
Contains the response headers
Inherited from
_promises
_promises:
Promise<any>[]
Defined in: packages/core/src/contexts/icontext.ts:33
Contain all registered promises to this context
Inherited from
_route
_route:
any
Defined in: packages/core/src/contexts/webcontext.ts:43
Inherited from
_sanitized
protected_sanitized:any
Defined in: packages/core/src/contexts/operationcontext.ts:44
Contain the sanitized request body if computed
Inherited from
_sessionSaved
protected_sessionSaved:boolean=false
Defined in: packages/core/src/contexts/webcontext.ts:49
Whether the session was already saved
Inherited from
_stream
_stream:
Writable
Defined in: packages/core/src/contexts/operationcontext.ts:85
Output stream
Inherited from
caches
caches:
any
Defined in: packages/core/src/contexts/icontext.ts:19
Get the caches linked to the context
Inherited from
extensions
protectedextensions:object
Defined in: packages/core/src/contexts/icontext.ts:23
Allow extensions
Index Signature
[key: string]: any
Inherited from
flushed
protectedflushed:boolean=false
Defined in: packages/core/src/contexts/icontext.ts:37
If the headers were flushed
Inherited from
headers
headers:
Map<string,string>
Defined in: packages/core/src/contexts/webcontext.ts:42
Inherited from
headersFlushed
protectedheadersFlushed:boolean
Defined in: packages/core/src/contexts/webcontext.ts:54
If headers were flushed
Inherited from
parameters
parameters:
any
Defined in: packages/core/src/contexts/operationcontext.ts:56
Inherited from
session
protectedsession:Session
Defined in: packages/core/src/contexts/operationcontext.ts:40
Session
Inherited from
statusCode
statusCode:
number
Defined in: packages/core/src/contexts/webcontext.ts:34
Current status code
Inherited from
Accessors
connectionEnded
Get Signature
get
abstractprotectedconnectionEnded():boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:48
Returns
boolean
true when nothing can be sent anymore although the context was not cancelled (response or socket over)
isCancelled
Get Signature
get isCancelled():
boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:36
Returns
boolean
whether the client went away
Methods
addAsyncRequest()
addAsyncRequest(
promise):void
Defined in: packages/core/src/contexts/operationcontext.ts:136
Register a promise with the context
Parameters
promise
any
the promise to add
Returns
void
Inherited from
assertAlive()
protectedassertAlive():void
Defined in: packages/core/src/contexts/streamingcontext.ts:78
Returns
void
Throws
OperationCancelledError when the client went away or the connection is over
cancel()
cancel():
void
Defined in: packages/core/src/contexts/streamingcontext.ts:41
The client went away: the next write or drain throws.
Returns
void
clearInput()
clearInput():
void
Defined in: packages/core/src/contexts/operationcontext.ts:161
Remove the input
Returns
void
Inherited from
cookie()
cookie(
param,value,options?):void
Defined in: packages/core/src/contexts/webcontext.ts:185
For compatibility reason
Parameters
param
any
the parameter name
value
any
the value to set
options?
any = undefined
the options
Returns
void
Inherited from
createStream()
createStream():
void
Defined in: packages/core/src/contexts/operationcontext.ts:286
Create a buffer stream
Returns
void
Inherited from
drained()
drained():
Promise<void>
Defined in: packages/core/src/contexts/streamingcontext.ts:101
Wait for the transport to take more output, without leaving listeners behind
Returns
Promise<void>
Throws
OperationCancelledError when the client went away, the connection is over or the transport failed
Overrides
end()
end():
Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:277
Flush the request
Returns
Promise<any>
the result
Emits
'finish' event
Throws
Error if the request was already ended
Inherited from
flushHeaders()
flushHeaders():
Promise<void>
Defined in: packages/core/src/contexts/webcontext.ts:406
Returns
Promise<void>
Inherited from
getCurrentUser()
getCurrentUser<
K>(refresh?):Promise<K>
Defined in: packages/core/src/contexts/operationcontext.ts:351
Get the current user from session
Type Parameters
K
K extends IUser
Parameters
refresh?
boolean = false
whether to refresh
Returns
Promise<K>
the result
Inherited from
getCurrentUserId()
getCurrentUserId():
string
Defined in: packages/core/src/contexts/operationcontext.ts:371
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
Inherited from
getExtension()
getExtension<
K>(name):K
Defined in: packages/core/src/contexts/operationcontext.ts:91
Get an extension of the context
Type Parameters
K
K = any
Parameters
name
string
of the extension
Returns
K
extension object
Inherited from
getHttpContext()
getHttpContext():
HttpContext
Defined in: packages/core/src/contexts/webcontext.ts:71
Get current http context
Returns
the result
Inherited from
getInput()
getInput(
sanitizedOptions?):Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:97
A multipart body (file upload) is never JSON: return the default value
instead of letting the parent try to JSON.parse it and log an error.
The raw body stays available to getRawInput()/getRawStream().
Parameters
sanitizedOptions?
IOptions & object
Returns
Promise<any>
Inherited from
getLocale()
getLocale():
string
Defined in: packages/core/src/contexts/webcontext.ts:359
Get the request locale if found
Returns
string
the result
Inherited from
getOutput()
getOutput():
string
Defined in: packages/core/src/contexts/operationcontext.ts:144
Get output as string, if a OutputStream is provided it will returned null
Returns
string
the result string
Inherited from
getOutputStream()
getOutputStream():
Promise<Writable>
Defined in: packages/core/src/contexts/operationcontext.ts:251
Get the HTTP stream to output raw data
Returns
Promise<Writable>
the result
Inherited from
getParameters()
getParameters():
any
Defined in: packages/core/src/contexts/operationcontext.ts:109
Get the parameters
Returns
any
the result
Inherited from
getRawInput()
getRawInput(
limit?,timeout?):Promise<Buffer<ArrayBufferLike>>
Defined in: packages/core/src/contexts/webcontext.ts:107
Parameters
limit?
number = ...
timeout?
number = 60000
Returns
Promise<Buffer<ArrayBufferLike>>
Inherited from
getRawInputAsString()
getRawInputAsString(
limit?,timeout?,encoding?):Promise<string>
Defined in: packages/core/src/contexts/webcontext.ts:83
Get the raw input as string
Any WHATWG Encoding Standard label is accepted as encoding (utf-8, iso-8859-1, shift_jis, ...) If no encoding is given, the charset of the Content-Type header is used, falling back to UTF-8
Parameters
limit?
number = ...
timeout?
number = 60000
encoding?
string
Returns
Promise<string>
Inherited from
WebContext.getRawInputAsString
getRawStream()
getRawStream():
Readable
Defined in: packages/core/src/contexts/webcontext.ts:114
Returns
Readable
Inherited from
getRequest()
getRequest():
IncomingMessage
Defined in: packages/core/src/contexts/webcontext.ts:333
Retrieve a http.IncomingMessage valid from Context
Need more testing
Returns
IncomingMessage
the result
Inherited from
getRequestBody()
getRequestBody(
sanitizedOptions?):Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:307
Alias to keep compatibility with WebContext
Parameters
sanitizedOptions?
any = ...
the sanitized options
Returns
Promise<any>
the result
Inherited from
getResponseBody()
getResponseBody():
any
Defined in: packages/core/src/contexts/webcontext.ts:320
Get request body
Returns
any
the result
Inherited from
getResponseCode()
getResponseCode():
number
Defined in: packages/core/src/contexts/webcontext.ts:168
Returns
number
the result
Inherited from
getResponseCookies()
getResponseCookies():
Map<string,Cookie>
Defined in: packages/core/src/contexts/webcontext.ts:197
Get all cookies set on the response
Returns
Map<string, Cookie>
the result map
Inherited from
getResponseHeaders()
getResponseHeaders():
OutgoingHttpHeaders
Defined in: packages/core/src/contexts/webcontext.ts:399
Return the merged response headers — defaults set by the constructor
(_outputHeaders) overlaid with any headers added via setHeader() /
writeHead(). Same merge order as flushHeaders writes to the wire,
so callers (logging, capture, transports) see exactly what the client
will receive.
Returns
OutgoingHttpHeaders
the merged response headers
Inherited from
getResponseSize()
getResponseSize():
number
Defined in: packages/core/src/contexts/webcontext.ts:248
Return the response size
Returns
number
the result
Inherited from
getSession()
getSession<
K>():K
Defined in: packages/core/src/contexts/operationcontext.ts:260
Get linked session
Type Parameters
K
K = Session
Returns
K
the result
Inherited from
getSetCookieHeaders()
getSetCookieHeaders():
string[]
Defined in: packages/core/src/contexts/webcontext.ts:205
The Set-Cookie header values of the response, one per cookie
Returns
string[]
the serialized cookies
Inherited from
WebContext.getSetCookieHeaders
hasFlushedHeaders()
hasFlushedHeaders():
boolean
Defined in: packages/core/src/contexts/webcontext.ts:373
Return true if Headers got flushed already
Returns
boolean
the result
Inherited from
init()
init(
force?):Promise<StreamingOperationContext>
Defined in: packages/core/src/contexts/webcontext.ts:454
Initialize the web context, loading session and setting up stream listeners
Parameters
force?
boolean = false
whether to force the operation
Returns
Promise<StreamingOperationContext>
this for chaining
Inherited from
isEnded()
isEnded():
Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:213
Whether the response has been ended
Returns
Promise<any>
the result
Inherited from
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
json()
json(
obj):this
Defined in: packages/core/src/contexts/webcontext.ts:239
Express response allow answer to be sent this way
Parameters
obj
any
the target object
Returns
this
this for chaining
Inherited from
newSession()
newSession():
Session
Defined in: packages/core/src/contexts/operationcontext.ts:268
Create and assign a new empty session
Returns
the result
Inherited from
parameter()
parameter(
name,defaultValue?):any
Defined in: packages/core/src/contexts/operationcontext.ts:101
Get one parameter
Parameters
name
string
the name to use
defaultValue?
any = undefined
the default value
Returns
any
the result
Inherited from
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
redirect()
redirect(
url):void
Defined in: packages/core/src/contexts/webcontext.ts:176
Redirect to another url
Parameters
url
string
the URL
Returns
void
Inherited from
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
reinit()
reinit():
void
Defined in: packages/core/src/contexts/operationcontext.ts:276
Remove sanitized body
Returns
void
Inherited from
resetResponse()
resetResponse():
void
Defined in: packages/core/src/contexts/webcontext.ts:121
Remove everything that was about to be sent
Returns
void
Inherited from
saveSession()
saveSession():
Promise<void>
Defined in: packages/core/src/contexts/webcontext.ts:257
Save the session through the SessionManager, once
The SessionManager writes the session cookie: call it before the headers are flushed
Returns
Promise<void>
Inherited from
sendChunk()
abstractprotectedsendChunk(chunk):boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:55
Send one streamed chunk now
Parameters
chunk
any
what the operation wrote
Returns
boolean
false when the transport asks the operation to wait for drained()
setExtension()
setExtension(
name,extension):this
Defined in: packages/core/src/contexts/operationcontext.ts:127
Parameters
name
string
to add
extension
any
object to store
Returns
this
this for chaining
Inherited from
setFlushedHeaders()
setFlushedHeaders(
status?):void
Defined in: packages/core/src/contexts/webcontext.ts:381
Set flushed header status
Parameters
status?
boolean = true
the HTTP status code
Returns
void
Inherited from
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
setHttpContext()
setHttpContext(
httpContext):void
Defined in: packages/core/src/contexts/webcontext.ts:62
Set current http context
Parameters
httpContext
current http context
Returns
void
Inherited from
setParameters()
setParameters(
params):void
Defined in: packages/core/src/contexts/operationcontext.ts:117
Set the parameters
Parameters
params
any
the service parameters
Returns
void
Inherited from
setSession()
setSession(
session):void
Defined in: packages/core/src/contexts/operationcontext.ts:78
Set the session
Parameters
session
the session object
Returns
void
Inherited from
status()
status(
code):this
Defined in: packages/core/src/contexts/webcontext.ts:228
Express response allow statusCode to be defined this way
Parameters
code
number
to return
Returns
this
this for chaining
Inherited from
waitForDrain()
abstractprotectedwaitForDrain(signal):Promise<void>
Defined in: packages/core/src/contexts/streamingcontext.ts:62
Wait until the transport can take more output
Parameters
signal
AbortSignal
aborted once the wait is over: listeners registered with it are removed
Returns
Promise<void>
Throws
any error when the transport failed or closed (reported as OperationCancelledError)
write()
write(
output,encoding?,cb?):boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:90
Streamed chunks go out immediately; a non-streamed result is buffered
Parameters
output
any
encoding?
string
cb?
(error) => void
Returns
boolean
Throws
OperationCancelledError when streaming and the client went away or the connection is over
Overrides
writeHead()
writeHead(
statusCode,headers?):this
Defined in: packages/core/src/contexts/webcontext.ts:154
Write the http return code and some headers Those headers are not flushed yet so can still be overwritten
Parameters
statusCode
number
to return to the client
headers?
OutgoingHttpHeaders = undefined
to add to the response
Returns
this
this for chaining
Inherited from
writeResult()
protectedwriteResult(output,encoding?,cb?):boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:71
Keep a non-streamed result
Parameters
output
any
the result
encoding?
string
the encoding to use
cb?
(error) => void
the callback function
Returns
boolean
true