README
Operation context
Quickstart
$ npm i operation-context
Basic usage
import {defaultContext} from 'operation-context';
// Background context, typically useful for global logging.
export const bg = defaultContext('bg');
Type-safe state handling
For example, to assign session data to a context:
import {ContextToken} from 'operation-context';
// App-specific session data.
interface Session { /* ... */ }
// Unique state key used to store the session.
const sessionToken = new ContextToken<Session>('session');
// Once, typically close to session creation.
oc.values.register(sessionToken, sess); // Assign the session.
// Later...
const sess = oc.values.take(sessionToken); // Retrieve the session.
Integrations
pino-pretty
We recommend the following .pino-prettyrc.json
configuration:
{
"colorize": true,
"ignore": "hostname,op",
"translateTime": "SYS:standard"
}
Developing
$ npm i
$ npx husky install # Set up git hooks, only needed once.