@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.
@@ -17,7 +17,8 @@ export type QuerySubscriptionData = {
17
17
 
18
18
  export type AuthenticateMessageData = {
19
19
  action: 'authenticate';
20
- token: string;
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
- | QuerySubscribeMessageData
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
- | PublishEntityMessageData
58
- | PublishUidMessageData;
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;
@@ -1,9 +1,9 @@
1
- import { Config } from './d';
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
- export { Config } from './d';
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 };
@@ -1,14 +1,14 @@
1
- import type { Nymph, TilmeldInterface } from '@nymphjs/nymph';
2
- import http from 'http';
3
- import { server as WebSocketServer } from 'websocket';
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 WebSocketServer({
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
- "lib": ["ES2021"],
6
- "target": "ES2021",
5
+ "types": ["node", "jest"],
6
+ "module": "nodenext",
7
+ "moduleResolution": "nodenext",
8
+ "lib": ["es2024"],
9
+ "target": "es2024",
7
10
  "noImplicitAny": true,
8
- "removeComments": true,
11
+ "removeComments": false,
9
12
  "sourceMap": true,
10
13
  "outDir": "dist",
11
14
  "resolveJsonModule": true,
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../../typedoc.base.json"],
3
+ "entryPoints": ["src/index.ts"]
4
+ }
package/dist/conf/d.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface Config {
2
- originIsAllowed: (origin: string) => boolean;
3
- entries: string[];
4
- relays: string[];
5
- broadcastCounts: boolean;
6
- logger: (...args: any[]) => void;
7
- }
package/dist/conf/d.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=d.js.map
@@ -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
- }