@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/src/PubSub.types.ts
CHANGED
|
@@ -17,7 +17,8 @@ export type QuerySubscriptionData = {
|
|
|
17
17
|
|
|
18
18
|
export type AuthenticateMessageData = {
|
|
19
19
|
action: 'authenticate';
|
|
20
|
-
|
|
20
|
+
authToken: string;
|
|
21
|
+
switchToken?: string;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export type QuerySubscribeMessageData = {
|
|
@@ -33,8 +34,7 @@ export type UidSubscribeMessageData = {
|
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
export type SubscribeMessageData =
|
|
36
|
-
|
|
|
37
|
-
| UidSubscribeMessageData;
|
|
37
|
+
QuerySubscribeMessageData | UidSubscribeMessageData;
|
|
38
38
|
|
|
39
39
|
export type PublishEntityMessageData = {
|
|
40
40
|
action: 'publish';
|
|
@@ -54,13 +54,18 @@ export type PublishUidMessageData = {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export type PublishMessageData =
|
|
57
|
-
|
|
|
58
|
-
|
|
57
|
+
PublishEntityMessageData | PublishUidMessageData;
|
|
58
|
+
|
|
59
|
+
export type MultipleMessageData = {
|
|
60
|
+
action: 'multiple';
|
|
61
|
+
messages: MessageData[];
|
|
62
|
+
};
|
|
59
63
|
|
|
60
64
|
export type MessageData =
|
|
61
65
|
| AuthenticateMessageData
|
|
62
66
|
| SubscribeMessageData
|
|
63
|
-
| PublishMessageData
|
|
67
|
+
| PublishMessageData
|
|
68
|
+
| MultipleMessageData;
|
|
64
69
|
|
|
65
70
|
export type MessageOptions = Options & {
|
|
66
71
|
class: string;
|
package/src/conf/defaults.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Config } from './
|
|
1
|
+
import type { Config } from './index.js';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
originIsAllowed: () => {
|
|
5
5
|
throw new Error(
|
|
6
|
-
'You must provide a "originIsAllowed" function to PubSub config to determine if client origin is allowed.'
|
|
6
|
+
'You must provide a "originIsAllowed" function to PubSub config to determine if client origin is allowed.',
|
|
7
7
|
);
|
|
8
8
|
},
|
|
9
9
|
entries: ['ws://127.0.0.1:8080/'],
|
package/src/conf/index.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Nymph PubSub Config
|
|
3
|
+
*/
|
|
4
|
+
export interface Config {
|
|
5
|
+
/**
|
|
6
|
+
* Determine whether a client's origin is allowed to connect.
|
|
7
|
+
*/
|
|
8
|
+
originIsAllowed: (origin: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The URLs of the Nymph-PubSub servers to directly publish to. These servers
|
|
11
|
+
* are how this host will enter the PubSub network. If you only have one
|
|
12
|
+
* PubSub server, it needs to be listed here.
|
|
13
|
+
*/
|
|
14
|
+
entries: string[];
|
|
15
|
+
/**
|
|
16
|
+
* The URLs of additional Nymph-PubSub servers to relay publishes to. If this
|
|
17
|
+
* host is a PubSub server, these servers are how it will continue into your
|
|
18
|
+
* PubSub network.
|
|
19
|
+
*/
|
|
20
|
+
relays: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Allow clients to request to be notified when other clients subscribe to the
|
|
23
|
+
* same queries.
|
|
24
|
+
*/
|
|
25
|
+
broadcastCounts: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Function to log PubSub info/error messages.
|
|
28
|
+
*/
|
|
29
|
+
logger: (...args: any[]) => void;
|
|
30
|
+
}
|
|
2
31
|
|
|
3
|
-
import defaults from './defaults';
|
|
32
|
+
import defaults from './defaults.js';
|
|
4
33
|
export { defaults as ConfigDefaults };
|
package/src/createServer.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import type { Nymph } from '@nymphjs/nymph';
|
|
3
|
+
import ws from 'websocket';
|
|
4
4
|
|
|
5
|
-
import { Config, ConfigDefaults as defaults } from './conf';
|
|
6
|
-
import PubSub from './PubSub';
|
|
5
|
+
import { Config, ConfigDefaults as defaults } from './conf/index.js';
|
|
6
|
+
import PubSub from './PubSub.js';
|
|
7
7
|
|
|
8
8
|
export default function createServer(
|
|
9
9
|
port = 8080,
|
|
10
10
|
config: Partial<Config> = {},
|
|
11
|
-
nymph: Nymph
|
|
11
|
+
nymph: Nymph,
|
|
12
12
|
) {
|
|
13
13
|
const server = http.createServer((_request, response) => {
|
|
14
14
|
response.writeHead(404);
|
|
@@ -19,11 +19,11 @@ export default function createServer(
|
|
|
19
19
|
(config.logger ?? defaults.logger)(
|
|
20
20
|
'log',
|
|
21
21
|
new Date().toISOString(),
|
|
22
|
-
`Nymph-PubSub server started listening on port ${port}
|
|
22
|
+
`Nymph-PubSub server started listening on port ${port}.`,
|
|
23
23
|
);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
const wsServer = new
|
|
26
|
+
const wsServer = new ws.server({
|
|
27
27
|
httpServer: listener,
|
|
28
28
|
// You should not use autoAcceptConnections for production
|
|
29
29
|
// applications, as it defeats all standard cross-origin protection
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './conf';
|
|
1
|
+
export * from './conf/index.js';
|
|
2
2
|
|
|
3
|
-
import PubSub from './PubSub';
|
|
3
|
+
import PubSub from './PubSub.js';
|
|
4
4
|
export { PubSub };
|
|
5
5
|
|
|
6
|
-
export * from './PubSub.types';
|
|
6
|
+
export * from './PubSub.types.js';
|
|
7
7
|
|
|
8
|
-
import createServer from './createServer';
|
|
8
|
+
import createServer from './createServer.js';
|
|
9
9
|
export { createServer };
|
|
10
10
|
export default createServer;
|
package/tsconfig.json
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
"extends": "@tsconfig/recommended/tsconfig.json",
|
|
3
3
|
|
|
4
4
|
"compilerOptions": {
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"types": ["node", "jest"],
|
|
6
|
+
"module": "nodenext",
|
|
7
|
+
"moduleResolution": "nodenext",
|
|
8
|
+
"lib": ["es2024"],
|
|
9
|
+
"target": "es2024",
|
|
7
10
|
"noImplicitAny": true,
|
|
8
|
-
"removeComments":
|
|
11
|
+
"removeComments": false,
|
|
9
12
|
"sourceMap": true,
|
|
10
13
|
"outDir": "dist",
|
|
11
14
|
"resolveJsonModule": true,
|
package/typedoc.json
ADDED
package/dist/conf/d.d.ts
DELETED
package/dist/conf/d.js
DELETED
package/dist/conf/d.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"d.js","sourceRoot":"","sources":["../../src/conf/d.ts"],"names":[],"mappings":""}
|
package/src/conf/d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nymph PubSub Config
|
|
3
|
-
*/
|
|
4
|
-
export interface Config {
|
|
5
|
-
/**
|
|
6
|
-
* Determine whether a client's origin is allowed to connect.
|
|
7
|
-
*/
|
|
8
|
-
originIsAllowed: (origin: string) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* The URLs of the Nymph-PubSub servers to directly publish to. These servers
|
|
11
|
-
* are how this host will enter the PubSub network. If you only have one
|
|
12
|
-
* PubSub server, it needs to be listed here.
|
|
13
|
-
*/
|
|
14
|
-
entries: string[];
|
|
15
|
-
/**
|
|
16
|
-
* The URLs of additional Nymph-PubSub servers to relay publishes to. If this
|
|
17
|
-
* host is a PubSub server, these servers are how it will continue into your
|
|
18
|
-
* PubSub network.
|
|
19
|
-
*/
|
|
20
|
-
relays: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Allow clients to request to be notified when other clients subscribe to the
|
|
23
|
-
* same queries.
|
|
24
|
-
*/
|
|
25
|
-
broadcastCounts: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Function to log PubSub info/error messages.
|
|
28
|
-
*/
|
|
29
|
-
logger: (...args: any[]) => void;
|
|
30
|
-
}
|