@graphql-yoga/subscription 2.1.0 → 2.2.0-canary-24a04de.0

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.
@@ -2,41 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPubSub = void 0;
4
4
  const repeater_1 = require("@repeaterjs/repeater");
5
- const resolveGlobalConfig = (api = globalThis) => {
6
- if (!api.Event || !api.EventTarget) {
7
- throw new Error(`
8
- [@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs.
9
-
10
- 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.
11
- You can provide polyfills to the 'createPubSub' function:
12
-
13
- \`\`\`
14
- // yarn install --exact event-target-polyfill@0.0.3
15
- import 'event-target-polyfill'
16
-
17
- const pubSub = createPubSub()
18
- \`\`\`
19
-
20
- Alternatively, you can provide your own custom implementation.
21
-
22
- \`\`\`
23
- const pubSub = createPubSub({
24
- event: {
25
- Event,
26
- EventTarget,
27
- }
28
- })
29
- \`\`\`
30
- `);
31
- }
32
- return globalThis;
33
- };
5
+ const typed_event_target_1 = require("@graphql-yoga/typed-event-target");
34
6
  /**
35
7
  * Utility for publishing and subscribing to events.
36
8
  */
37
9
  const createPubSub = (config) => {
38
10
  var _a;
39
- const { Event, EventTarget } = resolveGlobalConfig(config === null || config === void 0 ? void 0 : config.event);
11
+ const { Event, EventTarget } = (0, typed_event_target_1.resolveGlobalConfig)(config === null || config === void 0 ? void 0 : config.event);
40
12
  const target = (_a = config === null || config === void 0 ? void 0 : config.eventTarget) !== null && _a !== void 0 ? _a : new EventTarget();
41
13
  return {
42
14
  publish(routingKey, ...args) {
@@ -1,33 +1,5 @@
1
1
  import { Repeater } from '@repeaterjs/repeater';
2
- const resolveGlobalConfig = (api = globalThis) => {
3
- if (!api.Event || !api.EventTarget) {
4
- throw new Error(`
5
- [@graphql-yoga/subscription] 'createPubSub' uses the Event and EventTarget APIs.
6
-
7
- 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.
8
- You can provide polyfills to the 'createPubSub' function:
9
-
10
- \`\`\`
11
- // yarn install --exact event-target-polyfill@0.0.3
12
- import 'event-target-polyfill'
13
-
14
- const pubSub = createPubSub()
15
- \`\`\`
16
-
17
- Alternatively, you can provide your own custom implementation.
18
-
19
- \`\`\`
20
- const pubSub = createPubSub({
21
- event: {
22
- Event,
23
- EventTarget,
24
- }
25
- })
26
- \`\`\`
27
- `);
28
- }
29
- return globalThis;
30
- };
2
+ import { resolveGlobalConfig, } from '@graphql-yoga/typed-event-target';
31
3
  /**
32
4
  * Utility for publishing and subscribing to events.
33
5
  */
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@graphql-yoga/subscription",
3
- "version": "2.1.0",
3
+ "version": "2.2.0-canary-24a04de.0",
4
4
  "description": "",
5
5
  "dependencies": {
6
+ "@graphql-yoga/typed-event-target": "0.1.0-canary-24a04de.0",
6
7
  "@repeaterjs/repeater": "^3.0.4",
7
8
  "tslib": "^2.3.1"
8
9
  },
@@ -1,12 +1,8 @@
1
1
  import { Repeater } from '@repeaterjs/repeater';
2
- import { TypedEventTarget } from './typed-event-target.js';
2
+ import { type TypedEventTarget, type EventAPI } from '@graphql-yoga/typed-event-target';
3
3
  declare type PubSubPublishArgsByKey = {
4
4
  [key: string]: [] | [any] | [number | string, any];
5
5
  };
6
- declare type EventAPI = {
7
- Event: typeof Event;
8
- EventTarget: typeof EventTarget;
9
- };
10
6
  export declare type PubSubEvent<TPubSubPublishArgsByKey extends PubSubPublishArgsByKey, TKey extends Extract<keyof TPubSubPublishArgsByKey, string>> = Event & {
11
7
  data?: TPubSubPublishArgsByKey[TKey][1] extends undefined ? TPubSubPublishArgsByKey[TKey][0] : TPubSubPublishArgsByKey[TKey][1];
12
8
  };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // extends EventTarget types and adds typed Events
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- // extends EventTarget types and adds typed Events
2
- export {};
@@ -1,12 +0,0 @@
1
- export interface TypedEventListener<TEvent extends Event> extends EventListener {
2
- (evt: TEvent): void;
3
- }
4
- export interface TypedEventListenerObject<TEvent extends Event> extends EventListener {
5
- handleEvent(object: TEvent): void;
6
- }
7
- export declare type TypedEventListenerOrEventListenerObject<TEvent extends Event> = TypedEventListener<TEvent> | TypedEventListenerObject<TEvent> | null;
8
- export interface TypedEventTarget<TEvent extends Event> extends EventTarget {
9
- addEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent>, options?: AddEventListenerOptions | boolean): void;
10
- dispatchEvent(event: TEvent): boolean;
11
- removeEventListener(type: string, callback: TypedEventListenerOrEventListenerObject<TEvent>, options?: EventListenerOptions | boolean): void;
12
- }