@logtape/logtape 1.1.0-dev.315 → 1.1.0-dev.321
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.ts +1 -1
- package/deno.json +1 -1
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js.map +1 -1
- package/package.json +1 -1
package/context.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { LoggerImpl } from "./logger.ts";
|
|
|
3
3
|
/**
|
|
4
4
|
* A generic interface for a context-local storage. It resembles
|
|
5
5
|
* the {@link AsyncLocalStorage} API from Node.js.
|
|
6
|
-
* @
|
|
6
|
+
* @template T The type of the context-local store.
|
|
7
7
|
* @since 0.7.0
|
|
8
8
|
*/
|
|
9
9
|
export interface ContextLocalStorage<T> {
|
package/deno.json
CHANGED
package/dist/context.d.cts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* A generic interface for a context-local storage. It resembles
|
|
4
4
|
* the {@link AsyncLocalStorage} API from Node.js.
|
|
5
|
-
* @
|
|
5
|
+
* @template T The type of the context-local store.
|
|
6
6
|
* @since 0.7.0
|
|
7
7
|
*/
|
|
8
8
|
interface ContextLocalStorage<T> {
|
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* A generic interface for a context-local storage. It resembles
|
|
4
4
|
* the {@link AsyncLocalStorage} API from Node.js.
|
|
5
|
-
* @
|
|
5
|
+
* @template T The type of the context-local store.
|
|
6
6
|
* @since 0.7.0
|
|
7
7
|
*/
|
|
8
8
|
interface ContextLocalStorage<T> {
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["context: Record<string, unknown>","callback: () => T"],"sources":["../context.ts"],"sourcesContent":["import { LoggerImpl } from \"./logger.ts\";\n\n/**\n * A generic interface for a context-local storage. It resembles\n * the {@link AsyncLocalStorage} API from Node.js.\n * @
|
|
1
|
+
{"version":3,"file":"context.js","names":["context: Record<string, unknown>","callback: () => T"],"sources":["../context.ts"],"sourcesContent":["import { LoggerImpl } from \"./logger.ts\";\n\n/**\n * A generic interface for a context-local storage. It resembles\n * the {@link AsyncLocalStorage} API from Node.js.\n * @template T The type of the context-local store.\n * @since 0.7.0\n */\nexport interface ContextLocalStorage<T> {\n /**\n * Runs a callback with the given store as the context-local store.\n * @param store The store to use as the context-local store.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n */\n run<R>(store: T, callback: () => R): R;\n\n /**\n * Returns the current context-local store.\n * @returns The current context-local store, or `undefined` if there is no\n * store.\n */\n getStore(): T | undefined;\n}\n\n/**\n * Runs a callback with the given implicit context. Every single log record\n * in the callback will have the given context.\n *\n * If no `contextLocalStorage` is configured, this function does nothing and\n * just returns the return value of the callback. It also logs a warning to\n * the `[\"logtape\", \"meta\"]` logger in this case.\n * @param context The context to inject.\n * @param callback The callback to run.\n * @returns The return value of the callback.\n * @since 0.7.0\n */\nexport function withContext<T>(\n context: Record<string, unknown>,\n callback: () => T,\n): T {\n const rootLogger = LoggerImpl.getLogger();\n if (rootLogger.contextLocalStorage == null) {\n LoggerImpl.getLogger([\"logtape\", \"meta\"]).warn(\n \"Context-local storage is not configured. \" +\n \"Specify contextLocalStorage option in the configure() function.\",\n );\n return callback();\n }\n const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};\n return rootLogger.contextLocalStorage.run(\n { ...parentContext, ...context },\n callback,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,SAAgB,YACdA,SACAC,UACG;CACH,MAAM,aAAa,WAAW,WAAW;AACzC,KAAI,WAAW,uBAAuB,MAAM;AAC1C,aAAW,UAAU,CAAC,WAAW,MAAO,EAAC,CAAC,KACxC,4GAED;AACD,SAAO,UAAU;CAClB;CACD,MAAM,gBAAgB,WAAW,oBAAoB,UAAU,IAAI,CAAE;AACrE,QAAO,WAAW,oBAAoB,IACpC;EAAE,GAAG;EAAe,GAAG;CAAS,GAChC,SACD;AACF"}
|