@nymphjs/pubsub 1.0.0-beta.13 → 1.0.0-beta.131
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/CHANGELOG.md +538 -0
- package/README.md +12 -10
- package/dist/PubSub.d.ts +77 -14
- package/dist/PubSub.js +548 -213
- package/dist/PubSub.js.map +1 -1
- package/dist/PubSub.test.js +265 -81
- package/dist/PubSub.test.js.map +1 -1
- package/dist/PubSub.types.d.ts +11 -2
- package/dist/PubSub.types.js +1 -2
- package/dist/conf/defaults.d.ts +1 -1
- package/dist/conf/defaults.js +4 -4
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +31 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- package/dist/createServer.d.ts +2 -2
- package/dist/createServer.js +14 -15
- package/dist/createServer.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -27
- package/dist/index.js.map +1 -1
- package/jest.config.js +31 -5
- package/package.json +37 -28
- package/src/PubSub.test.ts +343 -137
- package/src/PubSub.ts +796 -481
- package/src/PubSub.types.ts +11 -6
- package/src/conf/defaults.ts +2 -2
- package/src/conf/index.ts +31 -2
- package/src/createServer.ts +8 -8
- package/src/index.ts +4 -4
- package/tsconfig.json +6 -3
- package/typedoc.json +4 -0
- package/dist/conf/d.d.ts +0 -7
- package/dist/conf/d.js +0 -3
- package/dist/conf/d.js.map +0 -1
- package/src/conf/d.ts +0 -30
package/dist/PubSub.d.ts
CHANGED
|
@@ -1,47 +1,110 @@
|
|
|
1
1
|
import { Nymph } from '@nymphjs/nymph';
|
|
2
|
-
import
|
|
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
|
-
|
|
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
|
|
50
|
+
private static isOrIsDescendant;
|
|
28
51
|
private static publishTransactionPublishes;
|
|
29
52
|
private static removeTransactionPublishes;
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
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
|
}
|