@types/node
Advanced tools
Comparing version 20.10.7 to 20.10.8
@@ -26,2 +26,3 @@ /** | ||
declare module "diagnostics_channel" { | ||
import { AsyncLocalStorage } from "node:async_hooks"; | ||
/** | ||
@@ -100,2 +101,32 @@ * Check if there are active subscribers to the named channel. This is helpful if | ||
/** | ||
* Creates a `TracingChannel` wrapper for the given `TracingChannel Channels`. If a name is given, the corresponding tracing | ||
* channels will be created in the form of `tracing:${name}:${eventType}` where`eventType` corresponds to the types of `TracingChannel Channels`. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channelsByName = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* // or... | ||
* | ||
* const channelsByCollection = diagnostics_channel.tracingChannel({ | ||
* start: diagnostics_channel.channel('tracing:my-channel:start'), | ||
* end: diagnostics_channel.channel('tracing:my-channel:end'), | ||
* asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'), | ||
* asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'), | ||
* error: diagnostics_channel.channel('tracing:my-channel:error'), | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param nameOrChannels Channel name or object containing all the `TracingChannel Channels` | ||
* @return Collection of channels to trace with | ||
*/ | ||
function tracingChannel< | ||
StoreType = unknown, | ||
ContextType extends object = StoreType extends object ? StoreType : object, | ||
>( | ||
nameOrChannels: string | TracingChannelCollection<StoreType, ContextType>, | ||
): TracingChannel<StoreType, ContextType>; | ||
/** | ||
* The class `Channel` represents an individual named channel within the data | ||
@@ -109,3 +140,3 @@ * pipeline. It is used to track subscribers and to publish messages when there | ||
*/ | ||
class Channel { | ||
class Channel<StoreType = unknown, ContextType = StoreType> { | ||
readonly name: string | symbol; | ||
@@ -190,3 +221,326 @@ /** | ||
unsubscribe(onMessage: ChannelListener): void; | ||
/** | ||
* When `channel.runStores(context, ...)` is called, the given context data | ||
* will be applied to any store bound to the channel. If the store has already been | ||
* bound the previous `transform` function will be replaced with the new one. | ||
* The `transform` function may be omitted to set the given context data as the | ||
* context directly. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store, (data) => { | ||
* return { data }; | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param store The store to which to bind the context data | ||
* @param transform Transform context data before setting the store context | ||
*/ | ||
bindStore(store: AsyncLocalStorage<StoreType>, transform?: (context: ContextType) => StoreType): void; | ||
/** | ||
* Remove a message handler previously registered to this channel with `channel.bindStore(store)`. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store); | ||
* channel.unbindStore(store); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param store The store to unbind from the channel. | ||
* @return `true` if the store was found, `false` otherwise. | ||
*/ | ||
unbindStore(store: any): void; | ||
/** | ||
* Applies the given data to any AsyncLocalStorage instances bound to the channel | ||
* for the duration of the given function, then publishes to the channel within | ||
* the scope of that data is applied to the stores. | ||
* | ||
* If a transform function was given to `channel.bindStore(store)` it will be | ||
* applied to transform the message data before it becomes the context value for | ||
* the store. The prior storage context is accessible from within the transform | ||
* function in cases where context linking is required. | ||
* | ||
* The context applied to the store should be accessible in any async code which | ||
* continues from execution which began during the given function, however | ||
* there are some situations in which `context loss` may occur. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store, (message) => { | ||
* const parent = store.getStore(); | ||
* return new Span(message, parent); | ||
* }); | ||
* channel.runStores({ some: 'message' }, () => { | ||
* store.getStore(); // Span({ some: 'message' }) | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param context Message to send to subscribers and bind to stores | ||
* @param fn Handler to run within the entered storage context | ||
* @param thisArg The receiver to be used for the function call. | ||
* @param args Optional arguments to pass to the function. | ||
*/ | ||
runStores(): void; | ||
} | ||
interface TracingChannelSubscribers<ContextType extends object> { | ||
start: (message: ContextType) => void; | ||
end: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
asyncStart: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
asyncEnd: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
error: ( | ||
message: ContextType & { | ||
error: unknown; | ||
}, | ||
) => void; | ||
} | ||
interface TracingChannelCollection<StoreType = unknown, ContextType = StoreType> { | ||
start: Channel<StoreType, ContextType>; | ||
end: Channel<StoreType, ContextType>; | ||
asyncStart: Channel<StoreType, ContextType>; | ||
asyncEnd: Channel<StoreType, ContextType>; | ||
error: Channel<StoreType, ContextType>; | ||
} | ||
/** | ||
* The class `TracingChannel` is a collection of `TracingChannel Channels` which | ||
* together express a single traceable action. It is used to formalize and | ||
* simplify the process of producing events for tracing application flow.{@link tracingChannel} is used to construct a`TracingChannel`. As with `Channel` it is recommended to create and reuse a | ||
* single `TracingChannel` at the top-level of the file rather than creating them | ||
* dynamically. | ||
* @since v19.9.0 | ||
* @experimental | ||
*/ | ||
class TracingChannel<StoreType = unknown, ContextType extends object = {}> implements TracingChannelCollection { | ||
start: Channel<StoreType, ContextType>; | ||
end: Channel<StoreType, ContextType>; | ||
asyncStart: Channel<StoreType, ContextType>; | ||
asyncEnd: Channel<StoreType, ContextType>; | ||
error: Channel<StoreType, ContextType>; | ||
/** | ||
* Helper to subscribe a collection of functions to the corresponding channels. | ||
* This is the same as calling `channel.subscribe(onMessage)` on each channel | ||
* individually. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.subscribe({ | ||
* start(message) { | ||
* // Handle start message | ||
* }, | ||
* end(message) { | ||
* // Handle end message | ||
* }, | ||
* asyncStart(message) { | ||
* // Handle asyncStart message | ||
* }, | ||
* asyncEnd(message) { | ||
* // Handle asyncEnd message | ||
* }, | ||
* error(message) { | ||
* // Handle error message | ||
* }, | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param subscribers Set of `TracingChannel Channels` subscribers | ||
*/ | ||
subscribe(subscribers: TracingChannelSubscribers<ContextType>): void; | ||
/** | ||
* Helper to unsubscribe a collection of functions from the corresponding channels. | ||
* This is the same as calling `channel.unsubscribe(onMessage)` on each channel | ||
* individually. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.unsubscribe({ | ||
* start(message) { | ||
* // Handle start message | ||
* }, | ||
* end(message) { | ||
* // Handle end message | ||
* }, | ||
* asyncStart(message) { | ||
* // Handle asyncStart message | ||
* }, | ||
* asyncEnd(message) { | ||
* // Handle asyncEnd message | ||
* }, | ||
* error(message) { | ||
* // Handle error message | ||
* }, | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param subscribers Set of `TracingChannel Channels` subscribers | ||
* @return `true` if all handlers were successfully unsubscribed, and `false` otherwise. | ||
*/ | ||
unsubscribe(subscribers: TracingChannelSubscribers<ContextType>): void; | ||
/** | ||
* Trace a synchronous function call. This will always produce a `start event` and `end event` around the execution and may produce an `error event` if the given function throws an error. | ||
* This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.traceSync(() => { | ||
* // Do something | ||
* }, { | ||
* some: 'thing', | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn Function to wrap a trace around | ||
* @param context Shared object to correlate events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return The return value of the given function | ||
*/ | ||
traceSync<ThisArg = any, Args extends any[] = any[]>( | ||
fn: (this: ThisArg, ...args: Args) => any, | ||
context?: ContextType, | ||
thisArg?: ThisArg, | ||
...args: Args | ||
): void; | ||
/** | ||
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the | ||
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also | ||
* produce an `error event` if the given function throws an error or the | ||
* returned promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.tracePromise(async () => { | ||
* // Do something | ||
* }, { | ||
* some: 'thing', | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn Promise-returning function to wrap a trace around | ||
* @param context Shared object to correlate trace events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return Chained from promise returned by the given function | ||
*/ | ||
tracePromise<ThisArg = any, Args extends any[] = any[]>( | ||
fn: (this: ThisArg, ...args: Args) => Promise<any>, | ||
context?: ContextType, | ||
thisArg?: ThisArg, | ||
...args: Args | ||
): void; | ||
/** | ||
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the | ||
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or | ||
* the returned | ||
* promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* The `position` will be -1 by default to indicate the final argument should | ||
* be used as the callback. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.traceCallback((arg1, callback) => { | ||
* // Do something | ||
* callback(null, 'result'); | ||
* }, 1, { | ||
* some: 'thing', | ||
* }, thisArg, arg1, callback); | ||
* ``` | ||
* | ||
* The callback will also be run with `channel.runStores(context, ...)` which | ||
* enables context loss recovery in some cases. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* const myStore = new AsyncLocalStorage(); | ||
* | ||
* // The start channel sets the initial store data to something | ||
* // and stores that store data value on the trace context object | ||
* channels.start.bindStore(myStore, (data) => { | ||
* const span = new Span(data); | ||
* data.span = span; | ||
* return span; | ||
* }); | ||
* | ||
* // Then asyncStart can restore from that data it stored previously | ||
* channels.asyncStart.bindStore(myStore, (data) => { | ||
* return data.span; | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn callback using function to wrap a trace around | ||
* @param position Zero-indexed argument position of expected callback | ||
* @param context Shared object to correlate trace events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return The return value of the given function | ||
*/ | ||
traceCallback<Fn extends (this: any, ...args: any) => any>( | ||
fn: Fn, | ||
position: number | undefined, | ||
context: ContextType | undefined, | ||
thisArg: any, | ||
...args: Parameters<Fn> | ||
): void; | ||
} | ||
} | ||
@@ -193,0 +547,0 @@ declare module "node:diagnostics_channel" { |
{ | ||
"name": "@types/node", | ||
"version": "20.10.7", | ||
"version": "20.10.8", | ||
"description": "TypeScript definitions for node", | ||
@@ -227,5 +227,5 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node", | ||
}, | ||
"typesPublisherContentHash": "046bda929132f3b0ea734f317866954dfaa9a3eb325f8ac0f45460b1e007a9e2", | ||
"typesPublisherContentHash": "81a6ffec7851a9499bdc79517eb318d5db43383eae84c65f2509a4319d302d31", | ||
"typeScriptVersion": "4.6", | ||
"nonNpm": true | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
### Additional Details | ||
* Last updated: Sun, 07 Jan 2024 15:35:36 GMT | ||
* Last updated: Tue, 09 Jan 2024 15:35:40 GMT | ||
* Dependencies: [undici-types](https://npmjs.com/package/undici-types) | ||
@@ -14,0 +14,0 @@ |
@@ -26,2 +26,3 @@ /** | ||
declare module "diagnostics_channel" { | ||
import { AsyncLocalStorage } from "node:async_hooks"; | ||
/** | ||
@@ -100,2 +101,32 @@ * Check if there are active subscribers to the named channel. This is helpful if | ||
/** | ||
* Creates a `TracingChannel` wrapper for the given `TracingChannel Channels`. If a name is given, the corresponding tracing | ||
* channels will be created in the form of `tracing:${name}:${eventType}` where`eventType` corresponds to the types of `TracingChannel Channels`. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channelsByName = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* // or... | ||
* | ||
* const channelsByCollection = diagnostics_channel.tracingChannel({ | ||
* start: diagnostics_channel.channel('tracing:my-channel:start'), | ||
* end: diagnostics_channel.channel('tracing:my-channel:end'), | ||
* asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'), | ||
* asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'), | ||
* error: diagnostics_channel.channel('tracing:my-channel:error'), | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param nameOrChannels Channel name or object containing all the `TracingChannel Channels` | ||
* @return Collection of channels to trace with | ||
*/ | ||
function tracingChannel< | ||
StoreType = unknown, | ||
ContextType extends object = StoreType extends object ? StoreType : object, | ||
>( | ||
nameOrChannels: string | TracingChannelCollection<StoreType, ContextType>, | ||
): TracingChannel<StoreType, ContextType>; | ||
/** | ||
* The class `Channel` represents an individual named channel within the data | ||
@@ -109,3 +140,3 @@ * pipeline. It is used to track subscribers and to publish messages when there | ||
*/ | ||
class Channel { | ||
class Channel<StoreType = unknown, ContextType = StoreType> { | ||
readonly name: string | symbol; | ||
@@ -190,3 +221,326 @@ /** | ||
unsubscribe(onMessage: ChannelListener): void; | ||
/** | ||
* When `channel.runStores(context, ...)` is called, the given context data | ||
* will be applied to any store bound to the channel. If the store has already been | ||
* bound the previous `transform` function will be replaced with the new one. | ||
* The `transform` function may be omitted to set the given context data as the | ||
* context directly. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store, (data) => { | ||
* return { data }; | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param store The store to which to bind the context data | ||
* @param transform Transform context data before setting the store context | ||
*/ | ||
bindStore(store: AsyncLocalStorage<StoreType>, transform?: (context: ContextType) => StoreType): void; | ||
/** | ||
* Remove a message handler previously registered to this channel with `channel.bindStore(store)`. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store); | ||
* channel.unbindStore(store); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param store The store to unbind from the channel. | ||
* @return `true` if the store was found, `false` otherwise. | ||
*/ | ||
unbindStore(store: any): void; | ||
/** | ||
* Applies the given data to any AsyncLocalStorage instances bound to the channel | ||
* for the duration of the given function, then publishes to the channel within | ||
* the scope of that data is applied to the stores. | ||
* | ||
* If a transform function was given to `channel.bindStore(store)` it will be | ||
* applied to transform the message data before it becomes the context value for | ||
* the store. The prior storage context is accessible from within the transform | ||
* function in cases where context linking is required. | ||
* | ||
* The context applied to the store should be accessible in any async code which | ||
* continues from execution which began during the given function, however | ||
* there are some situations in which `context loss` may occur. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const store = new AsyncLocalStorage(); | ||
* | ||
* const channel = diagnostics_channel.channel('my-channel'); | ||
* | ||
* channel.bindStore(store, (message) => { | ||
* const parent = store.getStore(); | ||
* return new Span(message, parent); | ||
* }); | ||
* channel.runStores({ some: 'message' }, () => { | ||
* store.getStore(); // Span({ some: 'message' }) | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param context Message to send to subscribers and bind to stores | ||
* @param fn Handler to run within the entered storage context | ||
* @param thisArg The receiver to be used for the function call. | ||
* @param args Optional arguments to pass to the function. | ||
*/ | ||
runStores(): void; | ||
} | ||
interface TracingChannelSubscribers<ContextType extends object> { | ||
start: (message: ContextType) => void; | ||
end: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
asyncStart: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
asyncEnd: ( | ||
message: ContextType & { | ||
error?: unknown; | ||
result?: unknown; | ||
}, | ||
) => void; | ||
error: ( | ||
message: ContextType & { | ||
error: unknown; | ||
}, | ||
) => void; | ||
} | ||
interface TracingChannelCollection<StoreType = unknown, ContextType = StoreType> { | ||
start: Channel<StoreType, ContextType>; | ||
end: Channel<StoreType, ContextType>; | ||
asyncStart: Channel<StoreType, ContextType>; | ||
asyncEnd: Channel<StoreType, ContextType>; | ||
error: Channel<StoreType, ContextType>; | ||
} | ||
/** | ||
* The class `TracingChannel` is a collection of `TracingChannel Channels` which | ||
* together express a single traceable action. It is used to formalize and | ||
* simplify the process of producing events for tracing application flow.{@link tracingChannel} is used to construct a`TracingChannel`. As with `Channel` it is recommended to create and reuse a | ||
* single `TracingChannel` at the top-level of the file rather than creating them | ||
* dynamically. | ||
* @since v19.9.0 | ||
* @experimental | ||
*/ | ||
class TracingChannel<StoreType = unknown, ContextType extends object = {}> implements TracingChannelCollection { | ||
start: Channel<StoreType, ContextType>; | ||
end: Channel<StoreType, ContextType>; | ||
asyncStart: Channel<StoreType, ContextType>; | ||
asyncEnd: Channel<StoreType, ContextType>; | ||
error: Channel<StoreType, ContextType>; | ||
/** | ||
* Helper to subscribe a collection of functions to the corresponding channels. | ||
* This is the same as calling `channel.subscribe(onMessage)` on each channel | ||
* individually. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.subscribe({ | ||
* start(message) { | ||
* // Handle start message | ||
* }, | ||
* end(message) { | ||
* // Handle end message | ||
* }, | ||
* asyncStart(message) { | ||
* // Handle asyncStart message | ||
* }, | ||
* asyncEnd(message) { | ||
* // Handle asyncEnd message | ||
* }, | ||
* error(message) { | ||
* // Handle error message | ||
* }, | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param subscribers Set of `TracingChannel Channels` subscribers | ||
*/ | ||
subscribe(subscribers: TracingChannelSubscribers<ContextType>): void; | ||
/** | ||
* Helper to unsubscribe a collection of functions from the corresponding channels. | ||
* This is the same as calling `channel.unsubscribe(onMessage)` on each channel | ||
* individually. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.unsubscribe({ | ||
* start(message) { | ||
* // Handle start message | ||
* }, | ||
* end(message) { | ||
* // Handle end message | ||
* }, | ||
* asyncStart(message) { | ||
* // Handle asyncStart message | ||
* }, | ||
* asyncEnd(message) { | ||
* // Handle asyncEnd message | ||
* }, | ||
* error(message) { | ||
* // Handle error message | ||
* }, | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param subscribers Set of `TracingChannel Channels` subscribers | ||
* @return `true` if all handlers were successfully unsubscribed, and `false` otherwise. | ||
*/ | ||
unsubscribe(subscribers: TracingChannelSubscribers<ContextType>): void; | ||
/** | ||
* Trace a synchronous function call. This will always produce a `start event` and `end event` around the execution and may produce an `error event` if the given function throws an error. | ||
* This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.traceSync(() => { | ||
* // Do something | ||
* }, { | ||
* some: 'thing', | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn Function to wrap a trace around | ||
* @param context Shared object to correlate events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return The return value of the given function | ||
*/ | ||
traceSync<ThisArg = any, Args extends any[] = any[]>( | ||
fn: (this: ThisArg, ...args: Args) => any, | ||
context?: ContextType, | ||
thisArg?: ThisArg, | ||
...args: Args | ||
): void; | ||
/** | ||
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the | ||
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also | ||
* produce an `error event` if the given function throws an error or the | ||
* returned promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.tracePromise(async () => { | ||
* // Do something | ||
* }, { | ||
* some: 'thing', | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn Promise-returning function to wrap a trace around | ||
* @param context Shared object to correlate trace events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return Chained from promise returned by the given function | ||
*/ | ||
tracePromise<ThisArg = any, Args extends any[] = any[]>( | ||
fn: (this: ThisArg, ...args: Args) => Promise<any>, | ||
context?: ContextType, | ||
thisArg?: ThisArg, | ||
...args: Args | ||
): void; | ||
/** | ||
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the | ||
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or | ||
* the returned | ||
* promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all | ||
* events should have any bound stores set to match this trace context. | ||
* | ||
* The `position` will be -1 by default to indicate the final argument should | ||
* be used as the callback. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* | ||
* channels.traceCallback((arg1, callback) => { | ||
* // Do something | ||
* callback(null, 'result'); | ||
* }, 1, { | ||
* some: 'thing', | ||
* }, thisArg, arg1, callback); | ||
* ``` | ||
* | ||
* The callback will also be run with `channel.runStores(context, ...)` which | ||
* enables context loss recovery in some cases. | ||
* | ||
* ```js | ||
* import diagnostics_channel from 'node:diagnostics_channel'; | ||
* import { AsyncLocalStorage } from 'node:async_hooks'; | ||
* | ||
* const channels = diagnostics_channel.tracingChannel('my-channel'); | ||
* const myStore = new AsyncLocalStorage(); | ||
* | ||
* // The start channel sets the initial store data to something | ||
* // and stores that store data value on the trace context object | ||
* channels.start.bindStore(myStore, (data) => { | ||
* const span = new Span(data); | ||
* data.span = span; | ||
* return span; | ||
* }); | ||
* | ||
* // Then asyncStart can restore from that data it stored previously | ||
* channels.asyncStart.bindStore(myStore, (data) => { | ||
* return data.span; | ||
* }); | ||
* ``` | ||
* @since v19.9.0 | ||
* @experimental | ||
* @param fn callback using function to wrap a trace around | ||
* @param position Zero-indexed argument position of expected callback | ||
* @param context Shared object to correlate trace events through | ||
* @param thisArg The receiver to be used for the function call | ||
* @param args Optional arguments to pass to the function | ||
* @return The return value of the given function | ||
*/ | ||
traceCallback<Fn extends (this: any, ...args: any) => any>( | ||
fn: Fn, | ||
position: number | undefined, | ||
context: ContextType | undefined, | ||
thisArg: any, | ||
...args: Parameters<Fn> | ||
): void; | ||
} | ||
} | ||
@@ -193,0 +547,0 @@ declare module "node:diagnostics_channel" { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3966013
89645