@nymphjs/pubsub 1.0.0-beta.13 → 1.0.0-beta.130

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/dist/PubSub.d.ts CHANGED
@@ -1,47 +1,110 @@
1
1
  import { Nymph } from '@nymphjs/nymph';
2
- import { request, server as WebSocketServer, connection, Message } from 'websocket';
3
- import { Config } from './conf';
4
- import type { QuerySubscriptionData } from './PubSub.types';
2
+ import ws from 'websocket';
3
+ import { Config } from './conf/index.js';
4
+ import type { QuerySubscriptionData, PublishEntityMessageData } from './PubSub.types.js';
5
+ /**
6
+ * A publish/subscribe server for Nymph.
7
+ *
8
+ * Written by Hunter Perrin for SciActive.
9
+ *
10
+ * @author Hunter Perrin <hperrin@port87.com>
11
+ * @copyright SciActive Inc
12
+ * @see http://nymph.io/
13
+ */
5
14
  export default class PubSub {
15
+ /**
16
+ * The Nymph instance.
17
+ */
6
18
  nymph: Nymph;
19
+ /**
20
+ * The PubSub config.
21
+ */
7
22
  config: Config;
8
- server: WebSocketServer;
23
+ /**
24
+ * The WebSocket server.
25
+ */
26
+ server: ws.server;
9
27
  private sessions;
10
28
  protected querySubs: {
11
29
  [etype: string]: {
12
- [query: string]: Map<connection, QuerySubscriptionData>;
30
+ [query: string]: Map<ws.connection, QuerySubscriptionData>;
13
31
  };
14
32
  };
15
33
  protected uidSubs: {
16
- [uidName: string]: Map<connection, {
34
+ [uidName: string]: Map<ws.connection, {
17
35
  count: boolean;
18
36
  }>;
19
37
  };
38
+ protected outgoingClientMessages: Map<ws.connection, {
39
+ subscription: QuerySubscriptionData;
40
+ publish: PublishEntityMessageData;
41
+ }[]>;
42
+ protected outgoingClientMessagesTimeout: NodeJS.Immediate | null;
20
43
  protected static transactionPublishes: {
21
44
  nymph: Nymph;
22
45
  payload: string;
23
46
  config: Config;
24
47
  }[];
25
- static initPublisher(config: Partial<Config>, nymph: Nymph): void;
48
+ static initPublisher(config: Partial<Config>, nymph: Nymph): () => void;
26
49
  private static publish;
27
- private static isOrIsDescendent;
50
+ private static isOrIsDescendant;
28
51
  private static publishTransactionPublishes;
29
52
  private static removeTransactionPublishes;
30
- constructor(config: Partial<Config>, nymph: Nymph, server: WebSocketServer);
53
+ /**
54
+ * Initialize Nymph PubSub.
55
+ *
56
+ * @param config The PubSub configuration.
57
+ */
58
+ constructor(config: Partial<Config>, nymph: Nymph, server: ws.server);
31
59
  close(): void;
32
- handleRequest(request: request): void;
33
- onMessage(from: connection, msg: Message): Promise<void>;
34
- onClose(conn: connection, description: string): void;
35
- onError(conn: connection, e: Error): void;
60
+ handleRequest(request: ws.request): void;
61
+ /**
62
+ * Handle a message from a client.
63
+ */
64
+ onMessage(from: ws.connection, msg: ws.Message): Promise<void>;
65
+ /**
66
+ * Clean up after users who leave.
67
+ */
68
+ onClose(conn: ws.connection, description: string): void;
69
+ onError(conn: ws.connection, e: Error): void;
70
+ /**
71
+ * Handle an authentication from a client.
72
+ */
36
73
  private handleAuthentication;
74
+ /**
75
+ * Handle a subscribe or unsubscribe from a client.
76
+ */
37
77
  private handleSubscription;
78
+ /**
79
+ * Handle a subscribe or unsubscribe for a query from a client.
80
+ */
38
81
  private handleSubscriptionQuery;
82
+ /**
83
+ * Handle a subscribe or unsubscribe for a UID from a client.
84
+ */
39
85
  private handleSubscriptionUid;
86
+ /**
87
+ * Handle a publish from a client.
88
+ */
40
89
  private handlePublish;
90
+ /**
91
+ * Handle an entity publish from a client.
92
+ */
41
93
  private handlePublishEntity;
42
- private updateClient;
94
+ private addOutgoingClientMessage;
95
+ private updateClients;
96
+ /**
97
+ * Handle a UID publish from a client.
98
+ */
43
99
  private handlePublishUid;
100
+ /**
101
+ * Relay publish data to other servers.
102
+ */
44
103
  private relay;
45
104
  private findQRefQueries;
105
+ /**
106
+ * This translates qref selectors into ref selectors using the "current" GUID
107
+ * list in the existing subscriptions.
108
+ */
46
109
  private translateQRefSelectors;
47
110
  }