Skip to content

Commit

Permalink
🤖 Merge PR #63116 fix(node): support for symbol type in `diagnostic…
Browse files Browse the repository at this point in the history
…_channel` by @peterblazejewicz

Adds support for Symbol type, as per current Node JS implementation:

https://nodejs.org/docs/latest-v18.x/api/diagnostics_channel.html#diagnostics_channelchannelname
(and e.t.c.)

Thanks!

/cc @destumme

Fixes #63098
  • Loading branch information
peterblazejewicz committed Dec 5, 2022
1 parent 45eb3c5 commit 24fe3a3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions types/node/diagnostics_channel.d.ts
Expand Up @@ -41,7 +41,7 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return If there are active subscribers
*/
function hasSubscribers(name: string): boolean;
function hasSubscribers(name: string | symbol): boolean;
/**
* This is the primary entry-point for anyone wanting to interact with a named
* channel. It produces a channel object which is optimized to reduce overhead at
Expand All @@ -56,8 +56,8 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return The named channel object
*/
function channel(name: string): Channel;
type ChannelListener = (message: unknown, name: string) => void;
function channel(name: string | symbol): Channel;
type ChannelListener = (message: unknown, name: string | symbol) => void;
/**
* The class `Channel` represents an individual named channel within the data
* pipeline. It is use to track subscribers and to publish messages when there
Expand All @@ -68,7 +68,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
class Channel {
readonly name: string;
readonly name: string | symbol;
/**
* Check if there are active subscribers to this channel. This is helpful if
* the message you want to send might be expensive to prepare.
Expand All @@ -88,7 +88,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
readonly hasSubscribers: boolean;
private constructor(name: string);
private constructor(name: string | symbol);
/**
* Publish a message to any subscribers to the channel. This will
* trigger message handlers synchronously so they will execute within
Expand Down
6 changes: 3 additions & 3 deletions types/node/test/diagnostics_channel.ts
@@ -1,11 +1,11 @@
import { Channel, channel, hasSubscribers } from 'node:diagnostics_channel';

const ch1: Channel = channel('test');
const ch1: Channel = channel(Symbol.for('test'));
function listener(data: unknown) {}
function anotherListener(data: unknown, name: string) {}
function anotherListener(data: unknown, name: string | symbol) {}

const active: boolean = ch1.hasSubscribers;
const name: string = ch1.name;
const name: string | symbol = ch1.name;

ch1.publish({ some: 'message' });

Expand Down
10 changes: 5 additions & 5 deletions types/node/ts4.8/diagnostics_channel.d.ts
Expand Up @@ -41,7 +41,7 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return If there are active subscribers
*/
function hasSubscribers(name: string): boolean;
function hasSubscribers(name: string | symbol): boolean;
/**
* This is the primary entry-point for anyone wanting to interact with a named
* channel. It produces a channel object which is optimized to reduce overhead at
Expand All @@ -56,8 +56,8 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return The named channel object
*/
function channel(name: string): Channel;
type ChannelListener = (message: unknown, name: string) => void;
function channel(name: string | symbol): Channel;
type ChannelListener = (message: unknown, name: string | symbol) => void;
/**
* The class `Channel` represents an individual named channel within the data
* pipeline. It is use to track subscribers and to publish messages when there
Expand All @@ -68,7 +68,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
class Channel {
readonly name: string;
readonly name: string | symbol;
/**
* Check if there are active subscribers to this channel. This is helpful if
* the message you want to send might be expensive to prepare.
Expand All @@ -88,7 +88,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
readonly hasSubscribers: boolean;
private constructor(name: string);
private constructor(name: string | symbol);
/**
* Publish a message to any subscribers to the channel. This will
* trigger message handlers synchronously so they will execute within
Expand Down
6 changes: 3 additions & 3 deletions types/node/ts4.8/test/diagnostics_channel.ts
@@ -1,11 +1,11 @@
import { Channel, channel, hasSubscribers } from 'node:diagnostics_channel';

const ch1: Channel = channel('test');
const ch1: Channel = channel(Symbol.for('test'));
function listener(data: unknown) {}
function anotherListener(data: unknown, name: string) {}
function anotherListener(data: unknown, name: string | symbol) {}

const active: boolean = ch1.hasSubscribers;
const name: string = ch1.name;
const name: string | symbol = ch1.name;

ch1.publish({ some: 'message' });

Expand Down
10 changes: 5 additions & 5 deletions types/node/v16/diagnostics_channel.d.ts
Expand Up @@ -41,7 +41,7 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return If there are active subscribers
*/
function hasSubscribers(name: string): boolean;
function hasSubscribers(name: string | symbol): boolean;
/**
* This is the primary entry-point for anyone wanting to interact with a named
* channel. It produces a channel object which is optimized to reduce overhead at
Expand All @@ -56,8 +56,8 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return The named channel object
*/
function channel(name: string): Channel;
type ChannelListener = (message: unknown, name: string) => void;
function channel(name: string | symbol): Channel;
type ChannelListener = (message: unknown, name: string | symbol) => void;
/**
* The class `Channel` represents an individual named channel within the data
* pipeline. It is use to track subscribers and to publish messages when there
Expand All @@ -68,7 +68,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
class Channel {
readonly name: string;
readonly name: string | symbol;
/**
* Check if there are active subscribers to this channel. This is helpful if
* the message you want to send might be expensive to prepare.
Expand All @@ -88,7 +88,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
readonly hasSubscribers: boolean;
private constructor(name: string);
private constructor(name: string | symbol);
/**
* Publish a message to any subscribers to the channel. This will
* trigger message handlers synchronously so they will execute within
Expand Down
6 changes: 3 additions & 3 deletions types/node/v16/test/diagnostics_channel.ts
@@ -1,11 +1,11 @@
import { Channel, channel, hasSubscribers } from 'node:diagnostics_channel';

const ch1: Channel = channel('test');
const ch1: Channel = channel(Symbol.for('test'));
function listener(data: unknown) {}
function anotherListener(data: unknown, name: string) {}
function anotherListener(data: unknown, name: string | symbol) {}

const active: boolean = ch1.hasSubscribers;
const name: string = ch1.name;
const name: string | symbol = ch1.name;

ch1.publish({ some: 'message' });

Expand Down
10 changes: 5 additions & 5 deletions types/node/v16/ts4.8/diagnostics_channel.d.ts
Expand Up @@ -41,7 +41,7 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return If there are active subscribers
*/
function hasSubscribers(name: string): boolean;
function hasSubscribers(name: string | symbol): boolean;
/**
* This is the primary entry-point for anyone wanting to interact with a named
* channel. It produces a channel object which is optimized to reduce overhead at
Expand All @@ -56,8 +56,8 @@ declare module 'diagnostics_channel' {
* @param name The channel name
* @return The named channel object
*/
function channel(name: string): Channel;
type ChannelListener = (message: unknown, name: string) => void;
function channel(name: string | symbol): Channel;
type ChannelListener = (message: unknown, name: string | symbol) => void;
/**
* The class `Channel` represents an individual named channel within the data
* pipeline. It is use to track subscribers and to publish messages when there
Expand All @@ -68,7 +68,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
class Channel {
readonly name: string;
readonly name: string | symbol;
/**
* Check if there are active subscribers to this channel. This is helpful if
* the message you want to send might be expensive to prepare.
Expand All @@ -88,7 +88,7 @@ declare module 'diagnostics_channel' {
* @since v15.1.0, v14.17.0
*/
readonly hasSubscribers: boolean;
private constructor(name: string);
private constructor(name: string | symbol);
/**
* Publish a message to any subscribers to the channel. This will
* trigger message handlers synchronously so they will execute within
Expand Down
6 changes: 3 additions & 3 deletions types/node/v16/ts4.8/test/diagnostics_channel.ts
@@ -1,11 +1,11 @@
import { Channel, channel, hasSubscribers } from 'node:diagnostics_channel';

const ch1: Channel = channel('test');
const ch1: Channel = channel(Symbol.for('test'));
function listener(data: unknown) {}
function anotherListener(data: unknown, name: string) {}
function anotherListener(data: unknown, name: string | symbol) {}

const active: boolean = ch1.hasSubscribers;
const name: string = ch1.name;
const name: string | symbol = ch1.name;

ch1.publish({ some: 'message' });

Expand Down

0 comments on commit 24fe3a3

Please sign in to comment.