@graphql-yoga/subscription 0.1.0-alpha.0 → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/createPubSub.d.ts CHANGED
@@ -25,11 +25,18 @@ export declare type ChannelPubSubConfig<TPubSubPublishArgsByKey extends PubSubPu
25
25
  */
26
26
  event?: EventAPI;
27
27
  };
28
+ export declare type PubSub<TPubSubPublishArgsByKey extends PubSubPublishArgsByKey> = {
29
+ /**
30
+ * Publish a value for a given topic.
31
+ */
32
+ publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]): void;
33
+ /**
34
+ * Subscribe to a topic.
35
+ */
36
+ 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]>;
37
+ };
28
38
  /**
29
39
  * Utility for publishing and subscribing to events.
30
40
  */
31
- export declare const createPubSub: <TPubSubPublishArgsByKey extends PubSubPublishArgsByKey>(config?: ChannelPubSubConfig<TPubSubPublishArgsByKey> | undefined) => {
32
- publish<TKey extends Extract<keyof TPubSubPublishArgsByKey, string>>(routingKey: TKey, ...args: TPubSubPublishArgsByKey[TKey]): void;
33
- 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>;
34
- };
41
+ export declare const createPubSub: <TPubSubPublishArgsByKey extends PubSubPublishArgsByKey>(config?: ChannelPubSubConfig<TPubSubPublishArgsByKey> | undefined) => PubSub<TPubSubPublishArgsByKey>;
35
42
  export {};
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { createPubSub } from './createPubSub';
1
+ export { Repeater } from '@repeaterjs/repeater';
2
+ export { createPubSub, PubSub } from './createPubSub';
2
3
  export type { PubSubEventTarget, PubSubEvent } from './createPubSub';
3
4
  export { map } from './operator/map';
4
5
  export { filter } from './operator/filter';
6
+ export { pipe } from './utils/pipe';
package/index.js CHANGED
@@ -9,7 +9,7 @@ const resolveGlobalConfig = (api = globalThis) => {
9
9
  throw new Error(`
10
10
  [@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs.
11
11
 
12
- 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.
12
+ 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.
13
13
  You can provide polyfills to the 'createPubSub' function:
14
14
 
15
15
  \`\`\`
@@ -60,27 +60,71 @@ const createPubSub = (config) => {
60
60
  * Utility for mapping an event stream.
61
61
  */
62
62
  const map = (mapper) => (source) => new repeater.Repeater(async (push, stop) => {
63
+ const iterable = source[Symbol.asyncIterator]();
63
64
  stop.then(() => {
64
- source.return();
65
+ var _a;
66
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
65
67
  });
66
- for await (const value of source) {
67
- push(await mapper(value));
68
+ let latest;
69
+ while ((latest = await iterable.next()).done === false) {
70
+ await push(await mapper(latest.value));
68
71
  }
72
+ stop();
69
73
  });
70
74
 
71
75
  function filter(filter) {
72
76
  return (source) => new repeater.Repeater(async (push, stop) => {
77
+ const iterable = source[Symbol.asyncIterator]();
73
78
  stop.then(() => {
74
- source.return();
79
+ var _a;
80
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
75
81
  });
76
- for await (const value of source) {
77
- if (filter(value)) {
78
- push(value);
82
+ let latest;
83
+ while ((latest = await iterable.next()).done === false) {
84
+ if (filter(latest.value)) {
85
+ await push(latest.value);
79
86
  }
80
87
  }
88
+ stop();
81
89
  });
82
90
  }
83
91
 
92
+ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
93
+ switch (arguments.length) {
94
+ case 1:
95
+ return a;
96
+ case 2:
97
+ return ab(a);
98
+ case 3:
99
+ return bc(ab(a));
100
+ case 4:
101
+ return cd(bc(ab(a)));
102
+ case 5:
103
+ return de(cd(bc(ab(a))));
104
+ case 6:
105
+ return ef(de(cd(bc(ab(a)))));
106
+ case 7:
107
+ return fg(ef(de(cd(bc(ab(a))))));
108
+ case 8:
109
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
110
+ case 9:
111
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
112
+ default:
113
+ let ret = arguments[0];
114
+ for (let i = 1; i < arguments.length; i++) {
115
+ ret = arguments[i](ret);
116
+ }
117
+ return ret;
118
+ }
119
+ }
120
+
121
+ Object.defineProperty(exports, 'Repeater', {
122
+ enumerable: true,
123
+ get: function () {
124
+ return repeater.Repeater;
125
+ }
126
+ });
84
127
  exports.createPubSub = createPubSub;
85
128
  exports.filter = filter;
86
129
  exports.map = map;
130
+ exports.pipe = pipe;
package/index.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Repeater } from '@repeaterjs/repeater';
2
+ export { Repeater } from '@repeaterjs/repeater';
2
3
 
3
4
  const resolveGlobalConfig = (api = globalThis) => {
4
5
  if (!api.Event || !api.EventTarget) {
5
6
  throw new Error(`
6
7
  [@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs.
7
8
 
8
- 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.
9
+ 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.
9
10
  You can provide polyfills to the 'createPubSub' function:
10
11
 
11
12
  \`\`\`
@@ -56,25 +57,62 @@ const createPubSub = (config) => {
56
57
  * Utility for mapping an event stream.
57
58
  */
58
59
  const map = (mapper) => (source) => new Repeater(async (push, stop) => {
60
+ const iterable = source[Symbol.asyncIterator]();
59
61
  stop.then(() => {
60
- source.return();
62
+ var _a;
63
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
61
64
  });
62
- for await (const value of source) {
63
- push(await mapper(value));
65
+ let latest;
66
+ while ((latest = await iterable.next()).done === false) {
67
+ await push(await mapper(latest.value));
64
68
  }
69
+ stop();
65
70
  });
66
71
 
67
72
  function filter(filter) {
68
73
  return (source) => new Repeater(async (push, stop) => {
74
+ const iterable = source[Symbol.asyncIterator]();
69
75
  stop.then(() => {
70
- source.return();
76
+ var _a;
77
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
71
78
  });
72
- for await (const value of source) {
73
- if (filter(value)) {
74
- push(value);
79
+ let latest;
80
+ while ((latest = await iterable.next()).done === false) {
81
+ if (filter(latest.value)) {
82
+ await push(latest.value);
75
83
  }
76
84
  }
85
+ stop();
77
86
  });
78
87
  }
79
88
 
80
- export { createPubSub, filter, map };
89
+ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
90
+ switch (arguments.length) {
91
+ case 1:
92
+ return a;
93
+ case 2:
94
+ return ab(a);
95
+ case 3:
96
+ return bc(ab(a));
97
+ case 4:
98
+ return cd(bc(ab(a)));
99
+ case 5:
100
+ return de(cd(bc(ab(a))));
101
+ case 6:
102
+ return ef(de(cd(bc(ab(a)))));
103
+ case 7:
104
+ return fg(ef(de(cd(bc(ab(a))))));
105
+ case 8:
106
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
107
+ case 9:
108
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
109
+ default:
110
+ let ret = arguments[0];
111
+ for (let i = 1; i < arguments.length; i++) {
112
+ ret = arguments[i](ret);
113
+ }
114
+ return ret;
115
+ }
116
+ }
117
+
118
+ export { createPubSub, filter, map, pipe };
@@ -2,5 +2,5 @@ import { Repeater } from '@repeaterjs/repeater';
2
2
  /**
3
3
  * Utility for filtering an event stream.
4
4
  */
5
- export declare function filter<T, U extends T>(filter: (input: T) => input is U): (source: Repeater<T>) => Repeater<U, void, unknown>;
6
- export declare function filter<T>(filter: (input: T) => boolean): (source: Repeater<T>) => Repeater<T, void, unknown>;
5
+ export declare function filter<T, U extends T>(filter: (input: T) => input is U): (source: AsyncIterable<T>) => Repeater<U, void, unknown>;
6
+ export declare function filter<T>(filter: (input: T) => boolean): (source: AsyncIterable<T>) => Repeater<T, void, unknown>;
@@ -0,0 +1 @@
1
+ export {};
package/operator/map.d.ts CHANGED
@@ -2,4 +2,4 @@ import { Repeater } from '@repeaterjs/repeater';
2
2
  /**
3
3
  * Utility for mapping an event stream.
4
4
  */
5
- export declare const map: <T, O>(mapper: (input: T) => O | Promise<O>) => (source: Repeater<T, any, unknown>) => Repeater<O, any, unknown>;
5
+ export declare const map: <T, O>(mapper: (input: T) => O | Promise<O>) => (source: AsyncIterable<T>) => Repeater<O, any, unknown>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-yoga/subscription",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0-alpha.1",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "@repeaterjs/repeater": "^3.0.4"
@@ -32,6 +32,7 @@
32
32
  "./*": {
33
33
  "require": "./*.js",
34
34
  "import": "./*.mjs"
35
- }
35
+ },
36
+ "./package.json": "./package.json"
36
37
  }
37
38
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pipes the value of an expression into a pipeline of functions.
3
+ *
4
+ * @source https://github.com/gcanti/fp-ts/blob/b442f0967b002b88eb2649ba38d95ec5ad2ab576/src/function.ts#L391-L682
5
+ */
6
+ export declare function pipe<A>(a: A): A;
7
+ export declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
8
+ export declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
9
+ export declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
10
+ export declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
11
+ export declare function pipe<A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
12
+ export declare function pipe<A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G;
13
+ export declare function pipe<A, B, C, D, E, F, G, H>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): H;
14
+ export declare function pipe<A, B, C, D, E, F, G, H, I>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): I;
15
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): J;
16
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): K;
17
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L): L;
18
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M): M;
19
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N): N;
20
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O): O;
21
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P): P;
22
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q): Q;
23
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R): R;
24
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S): S;
25
+ export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T): T;