@graphql-yoga/subscription
Advanced tools
Comparing version 5.1.0-alpha-20241004071346-375af0c2 to 5.1.0-alpha-20241004073709-b5c42658
@@ -31,11 +31,21 @@ "use strict"; | ||
} | ||
function publish(...args) { | ||
let payload; | ||
let topic; | ||
if (typeof args[0] === 'string') { | ||
payload = args[2] ?? args[1] ?? null; | ||
topic = args[2] === undefined ? args[0] : `${args[0]}:${args[1]}`; | ||
} | ||
else { | ||
const arg = args[0]; | ||
payload = arg.payload; | ||
topic = arg.id === undefined ? arg.topic : `${arg.topic}:${arg.id}`; | ||
} | ||
const event = new events_1.CustomEvent(topic, { | ||
detail: payload, | ||
}); | ||
target.dispatchEvent(event); | ||
} | ||
return { | ||
publish(routingKey, ...args) { | ||
const payload = args[1] ?? args[0] ?? null; | ||
const topic = args[1] === undefined ? routingKey : `${routingKey}:${args[0]}`; | ||
const event = new events_1.CustomEvent(topic, { | ||
detail: payload, | ||
}); | ||
target.dispatchEvent(event); | ||
}, | ||
publish, | ||
subscribe, | ||
@@ -42,0 +52,0 @@ }; |
@@ -28,13 +28,23 @@ import { Repeater } from '@repeaterjs/repeater'; | ||
} | ||
function publish(...args) { | ||
let payload; | ||
let topic; | ||
if (typeof args[0] === 'string') { | ||
payload = args[2] ?? args[1] ?? null; | ||
topic = args[2] === undefined ? args[0] : `${args[0]}:${args[1]}`; | ||
} | ||
else { | ||
const arg = args[0]; | ||
payload = arg.payload; | ||
topic = arg.id === undefined ? arg.topic : `${arg.topic}:${arg.id}`; | ||
} | ||
const event = new CustomEvent(topic, { | ||
detail: payload, | ||
}); | ||
target.dispatchEvent(event); | ||
} | ||
return { | ||
publish(routingKey, ...args) { | ||
const payload = args[1] ?? args[0] ?? null; | ||
const topic = args[1] === undefined ? routingKey : `${routingKey}:${args[0]}`; | ||
const event = new CustomEvent(topic, { | ||
detail: payload, | ||
}); | ||
target.dispatchEvent(event); | ||
}, | ||
publish, | ||
subscribe, | ||
}; | ||
}; |
{ | ||
"name": "@graphql-yoga/subscription", | ||
"version": "5.1.0-alpha-20241004071346-375af0c2", | ||
"version": "5.1.0-alpha-20241004073709-b5c42658", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "sideEffects": true, |
@@ -22,3 +22,13 @@ import type { TypedEventTarget } from '@graphql-yoga/typed-event-target'; | ||
*/ | ||
publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]): void; | ||
publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(...args: [ | ||
args: { | ||
topic: TKey; | ||
} & (TPubSubPublishArgsByKey[TKey][1] extends undefined ? { | ||
id?: void; | ||
payload: TPubSubPublishArgsByKey[TKey][0]; | ||
} : { | ||
id: TPubSubPublishArgsByKey[TKey][0]; | ||
payload: TPubSubPublishArgsByKey[TKey][1]; | ||
}) | ||
] | [routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]]): void; | ||
/** | ||
@@ -25,0 +35,0 @@ * Subscribe to a topic. |
Sorry, the diff of this file is not supported yet
28387
350