0.4.1 • Published 4 years ago

operation-context v0.4.1

Weekly downloads
202
License
MIT
Repository
-
Last release
4 years ago

Operation context NPM version codecov

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.
0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago