@graphql-yoga/subscription
Advanced tools
Comparing version 0.2.0-canary-36ad09f.0 to 0.2.0-canary-38b11e0.0
@@ -28,9 +28,16 @@ import { Repeater } from '@repeaterjs/repeater'; | ||
}; | ||
export declare type PubSub<TPubSubPublishArgsByKey extends PubSubPublishArgsByKey> = { | ||
/** | ||
* Publish a value for a given topic. | ||
*/ | ||
publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]): void; | ||
/** | ||
* Subscribe to a topic. | ||
*/ | ||
subscribe<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(...[routingKey, id]: TPubSubPublishArgsByKey[TKey][1] extends undefined ? [TKey] : [TKey, TPubSubPublishArgsByKey[TKey][0]]): Repeater<TPubSubPublishArgsByKey[TKey][1] extends undefined ? TPubSubPublishArgsByKey[TKey][0] : TPubSubPublishArgsByKey[TKey][1]>; | ||
}; | ||
/** | ||
* Utility for publishing and subscribing to events. | ||
*/ | ||
export declare const createPubSub: <TPubSubPublishArgsByKey extends PubSubPublishArgsByKey>(config?: ChannelPubSubConfig<TPubSubPublishArgsByKey> | undefined) => { | ||
publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]): void; | ||
subscribe<TKey_1 extends Extract<keyof TPubSubPublishArgsByKey, string>>(...[routingKey, id]: TPubSubPublishArgsByKey[TKey_1][1] extends undefined ? [TKey_1] : [TKey_1, TPubSubPublishArgsByKey[TKey_1][0]]): Repeater<TPubSubPublishArgsByKey[TKey_1][1] extends undefined ? TPubSubPublishArgsByKey[TKey_1][0] : TPubSubPublishArgsByKey[TKey_1][1], any, unknown>; | ||
}; | ||
export declare const createPubSub: <TPubSubPublishArgsByKey extends PubSubPublishArgsByKey>(config?: ChannelPubSubConfig<TPubSubPublishArgsByKey> | undefined) => PubSub<TPubSubPublishArgsByKey>; | ||
export {}; |
export { Repeater } from '@repeaterjs/repeater'; | ||
export { createPubSub } from './createPubSub'; | ||
export { createPubSub, PubSub } from './createPubSub'; | ||
export type { PubSubEventTarget, PubSubEvent } from './createPubSub'; | ||
@@ -4,0 +4,0 @@ export { map } from './operator/map'; |
24
index.js
@@ -12,3 +12,3 @@ 'use strict'; | ||
In modern JavaScript environments those are part of the global scope. However, if you are using an older version of Node.js (<= 16.x.x), those APIs must be polyfilled. | ||
In modern JavaScript environments those are part of the global scope. However, if you are using an older version of Node.js (< 16.x.x), those APIs must be polyfilled. | ||
You can provide polyfills to the 'createPubSub' function: | ||
@@ -64,8 +64,12 @@ | ||
const map = (mapper) => (source) => new repeater.Repeater(async (push, stop) => { | ||
const iterable = source[Symbol.asyncIterator](); | ||
stop.then(() => { | ||
source.return(); | ||
var _a; | ||
(_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable); | ||
}); | ||
for await (const value of source) { | ||
push(await mapper(value)); | ||
let latest; | ||
while ((latest = await iterable.next()).done === false) { | ||
await push(await mapper(latest.value)); | ||
} | ||
stop(); | ||
}); | ||
@@ -75,10 +79,14 @@ | ||
return (source) => new repeater.Repeater(async (push, stop) => { | ||
const iterable = source[Symbol.asyncIterator](); | ||
stop.then(() => { | ||
source.return(); | ||
var _a; | ||
(_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable); | ||
}); | ||
for await (const value of source) { | ||
if (filter(value)) { | ||
push(value); | ||
let latest; | ||
while ((latest = await iterable.next()).done === false) { | ||
if (filter(latest.value)) { | ||
await push(latest.value); | ||
} | ||
} | ||
stop(); | ||
}); | ||
@@ -85,0 +93,0 @@ } |
@@ -5,3 +5,3 @@ import { Repeater } from '@repeaterjs/repeater'; | ||
*/ | ||
export declare function filter<T, U extends T>(filter: (input: T) => input is U): (source: Repeater<T>) => Repeater<U, void, unknown>; | ||
export declare function filter<T>(filter: (input: T) => boolean): (source: Repeater<T>) => Repeater<T, void, unknown>; | ||
export declare function filter<T, U extends T>(filter: (input: T) => input is U): (source: AsyncIterable<T>) => Repeater<U, void, unknown>; | ||
export declare function filter<T>(filter: (input: T) => boolean): (source: AsyncIterable<T>) => Repeater<T, void, unknown>; |
@@ -5,2 +5,2 @@ import { Repeater } from '@repeaterjs/repeater'; | ||
*/ | ||
export declare const map: <T, O>(mapper: (input: T) => O | Promise<O>) => (source: Repeater<T, any, unknown>) => Repeater<O, any, unknown>; | ||
export declare const map: <T, O>(mapper: (input: T) => O | Promise<O>) => (source: AsyncIterable<T>) => Repeater<O, any, unknown>; |
{ | ||
"name": "@graphql-yoga/subscription", | ||
"version": "0.2.0-canary-36ad09f.0", | ||
"version": "0.2.0-canary-38b11e0.0", | ||
"description": "", | ||
@@ -35,4 +35,5 @@ "dependencies": { | ||
"import": "./*.mjs" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
17323
11
333