@graphql-yoga/subscription
Advanced tools
Comparing version 0.0.0 to 0.0.1-beta.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 {}; |
@@ -1,4 +0,6 @@ | ||
export { createPubSub } from './createPubSub'; | ||
export { Repeater } from '@repeaterjs/repeater'; | ||
export { createPubSub, PubSub } from './createPubSub'; | ||
export type { PubSubEventTarget, PubSubEvent } from './createPubSub'; | ||
export { map } from './operator/map'; | ||
export { filter } from './operator/filter'; | ||
export { pipe } from './utils/pipe'; |
60
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,15 +79,55 @@ | ||
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(); | ||
}); | ||
} | ||
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) { | ||
switch (arguments.length) { | ||
case 1: | ||
return a; | ||
case 2: | ||
return ab(a); | ||
case 3: | ||
return bc(ab(a)); | ||
case 4: | ||
return cd(bc(ab(a))); | ||
case 5: | ||
return de(cd(bc(ab(a)))); | ||
case 6: | ||
return ef(de(cd(bc(ab(a))))); | ||
case 7: | ||
return fg(ef(de(cd(bc(ab(a)))))); | ||
case 8: | ||
return gh(fg(ef(de(cd(bc(ab(a))))))); | ||
case 9: | ||
return hi(gh(fg(ef(de(cd(bc(ab(a)))))))); | ||
default: | ||
let ret = arguments[0]; | ||
for (let i = 1; i < arguments.length; i++) { | ||
ret = arguments[i](ret); | ||
} | ||
return ret; | ||
} | ||
} | ||
Object.defineProperty(exports, 'Repeater', { | ||
enumerable: true, | ||
get: function () { | ||
return repeater.Repeater; | ||
} | ||
}); | ||
exports.createPubSub = createPubSub; | ||
exports.filter = filter; | ||
exports.map = map; | ||
exports.pipe = pipe; |
@@ -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.0.0", | ||
"version": "0.0.1-beta.0", | ||
"description": "", | ||
"dependencies": { | ||
"@repeaterjs/repeater": "^3.0.4" | ||
"@repeaterjs/repeater": "^3.0.4", | ||
"tslib": "^2.3.1" | ||
}, | ||
@@ -35,4 +36,5 @@ "repository": { | ||
"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
17336
11
333
2
3
+ Addedtslib@^2.3.1
+ Addedtslib@2.8.1(transitive)