This is a Node.js module, which extends session with conversation scope - concept from JBoss. It is session agnostic, so it can be integrated with any session module, no matter if it uses database to store data or just memory.
The conversation scope is a bit like the traditional session scope in that it holds state associated with a user of the system, and spans multiple requests to the server. However, unlike the session scope, the conversation scope:
- is demarcated explicitly by the application, and
- holds state associated with a particular web browser tab in a web application (browsers tend to share domain cookies, and hence the session cookie, between tabs, so this is not the case for the session scope).
A conversation represents a task — a unit of work from the point of view of the user. The conversation context holds state associated with what the user is currently working on. If the user is doing multiple things at the same time, there are multiple conversations.
The conversation context is active during any request. Most conversations are destroyed at the end of the request. If a conversation should hold state across multiple requests, it must be explicitly promoted to a long-running conversation.
Examples of conversation scopes
Conversation lasting two requests
Conversation lasting two requests with nested conversation
Conversation lasting two requests with many nested conversations
There is always a conversation context active during the request lifecycle. At the start, module attempts to restore any previous long-running conversation context. If no
cidparameter was provided, conversation-scope creates a new temporary conversation context.
begin()method is encountered, the temporary conversation context is promoted to a long running conversation.
end()method is encountered, any long-running conversation context is demoted to a temporary conversation.
At the end of the render response phase of request lifecycle, module stores the contents of a long running conversation context or destroys the contents of a temporary conversation context.
By default, conversation context is not propagated, so every request will be processed in a new temporary conversation. If you want to propagate it, you need to explicitly code the conversation id as a request parameter:Continue session
You can download module source from GitLab or install it with Node Package Manager (npm):
$ npm install conversation-scope
Express + NodeSession
See examples for reference.
var ConversationScope =
new ConversationScope(req, res, options)
Run module as middleware with the given
options. It generally loads conversation, adds
cs property to request, then calls
conversation-scope accepts these properties in the options object.
Function in form of
fn(key), which will be used internally by module in order to get data.
Function in form of
fn(key, value), which will be used internally by module in order to save data.
Specifies the keys which should be excluded from conversation scope and treated like normal data in session.
Stores in conversation data specified with
Retrieves data from session, which was stored with provided
Returns current conversation ID.
Specifies that a long-running conversation begins.
Specifies that if a long-running conversation is already in progress, the conversation context is simply propagated.
Specifies that if a long-running conversation is already in progress, a new nested conversation context begins. The nested conversation will end when the next
end() is encountered, and the outer conversation will resume.
It is perfectly legal for multiple nested conversations to exist concurrently in the same outer conversation.
Specifies that a long-running conversation ends. Ending a nested conversation simply pops the conversation stack and resumes the outer conversation.
Specifies that the root conversation should be destroyed which effectively destroys the entire conversation stack. If the conversation is not nested, the current conversation is simply ended.