@rc-ex/ws 1.3.5 → 1.3.7

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.
Files changed (41) hide show
  1. package/dist/cjs/exceptions/ConnectionException.d.ts +1 -1
  2. package/dist/cjs/exceptions/ConnectionException.js +2 -2
  3. package/dist/cjs/exceptions/ConnectionException.js.map +1 -1
  4. package/dist/cjs/index.d.ts +3 -3
  5. package/dist/cjs/index.js +10 -10
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/rest.d.ts +1 -1
  8. package/dist/cjs/rest.js +2 -2
  9. package/dist/cjs/rest.js.map +1 -1
  10. package/dist/cjs/subscription.d.ts +1 -1
  11. package/dist/cjs/subscription.js +2 -2
  12. package/dist/cjs/subscription.js.map +1 -1
  13. package/dist/cjs/utils.d.ts +1 -1
  14. package/dist/cjs/utils.js +4 -4
  15. package/dist/cjs/utils.js.map +1 -1
  16. package/dist/esm/exceptions/ConnectionException.d.ts +1 -1
  17. package/dist/esm/exceptions/ConnectionException.js +1 -1
  18. package/dist/esm/exceptions/ConnectionException.js.map +1 -1
  19. package/dist/esm/index.d.ts +3 -3
  20. package/dist/esm/index.js +4 -4
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/rest.d.ts +1 -1
  23. package/dist/esm/rest.js +1 -1
  24. package/dist/esm/rest.js.map +1 -1
  25. package/dist/esm/subscription.d.ts +1 -1
  26. package/dist/esm/subscription.js +1 -1
  27. package/dist/esm/subscription.js.map +1 -1
  28. package/dist/esm/utils.d.ts +1 -1
  29. package/dist/esm/utils.js +2 -2
  30. package/dist/esm/utils.js.map +1 -1
  31. package/package.json +6 -2
  32. package/src/exceptions/ClosedException.ts +0 -7
  33. package/src/exceptions/ConnectionException.ts +0 -17
  34. package/src/exceptions/TimeoutException.ts +0 -7
  35. package/src/index.ts +0 -421
  36. package/src/rest.ts +0 -71
  37. package/src/subscription.ts +0 -131
  38. package/src/types.ts +0 -85
  39. package/src/utils.ts +0 -82
  40. package/tsconfig.cjs.json +0 -28
  41. package/tsconfig.esm.json +0 -28
package/src/utils.ts DELETED
@@ -1,82 +0,0 @@
1
- import type { MessageEvent } from "isomorphic-ws";
2
- import type WS from "isomorphic-ws";
3
-
4
- import type { WsgEvent, WsgMeta } from "./types";
5
- import ClosedException from "./exceptions/ClosedException";
6
- import TimeoutException from "./exceptions/TimeoutException";
7
-
8
- class Utils {
9
- public static splitWsgData(wsgData: string): [WsgMeta, any] {
10
- if (wsgData.includes(",--Boundary")) {
11
- const index = wsgData.indexOf(",--Boundary");
12
- return [
13
- JSON.parse(wsgData.substring(1, index)),
14
- wsgData.substring(index + 1, wsgData.length - 1),
15
- ];
16
- }
17
- return JSON.parse(wsgData);
18
- }
19
-
20
- public static debugWebSocket(_ws: WS) {
21
- const ws = _ws;
22
- const send = ws.send.bind(ws);
23
- ws.send = async (str: string) => {
24
- await send(str);
25
- console.debug(
26
- `*** WebSocket outgoing message: ***
27
- ${JSON.stringify(JSON.parse(str), null, 2)}
28
- ******`,
29
- );
30
- };
31
- ws.addEventListener("message", (mEvent: MessageEvent) => {
32
- const event = mEvent as WsgEvent;
33
- console.debug(
34
- `*** WebSocket incoming message: ***
35
- ${JSON.stringify(JSON.parse(event.data), null, 2)}
36
- ******`,
37
- );
38
- });
39
- ws.addEventListener("open", (event) => {
40
- console.debug("WebSocket open event:", event);
41
- });
42
- ws.addEventListener("error", (event) => {
43
- console.debug("WebSocket error event:", event);
44
- });
45
- ws.addEventListener("close", (event) => {
46
- console.debug("WebSocket close event:", event);
47
- });
48
- }
49
-
50
- public static waitForWebSocketMessage(
51
- ws: WS,
52
- matchCondition: (meta: WsgMeta) => boolean,
53
- timeout = 60000,
54
- ) {
55
- return new Promise<[WsgMeta, any, WsgEvent]>((resolve, reject) => {
56
- const checkHandle = setInterval(() => {
57
- if (ws.readyState === ws.CLOSED) {
58
- clearInterval(checkHandle);
59
- reject(new ClosedException());
60
- }
61
- }, 1000);
62
- const timeoutHandle = setTimeout(() => {
63
- ws.removeEventListener("message", handler);
64
- clearInterval(checkHandle);
65
- reject(new TimeoutException());
66
- }, timeout);
67
- const handler = (mEvent: MessageEvent) => {
68
- const event = mEvent as WsgEvent;
69
- const [meta, body] = Utils.splitWsgData(event.data);
70
- if (matchCondition(meta)) {
71
- ws.removeEventListener("message", handler);
72
- clearInterval(checkHandle);
73
- clearTimeout(timeoutHandle);
74
- resolve([meta, body, event]);
75
- }
76
- };
77
- ws.addEventListener("message", handler);
78
- });
79
- }
80
- }
81
-
82
- export default Utils;
package/tsconfig.cjs.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist/cjs",
7
- "skipLibCheck": true,
8
- "sourceMap": true,
9
- "paths": {
10
- "@rc-ex/core/*": [
11
- "../../core/dist/cjs/*"
12
- ],
13
- "isomorphic-ws": [
14
- "../../../node_modules/isomorphic-ws/node.js"
15
- ],
16
- "wait-for-async": [
17
- "../../../node_modules/wait-for-async/dist/cjs/index.js"
18
- ],
19
- "hyperid": [
20
- "../../../node_modules/hyperid/hyperid.js"
21
- ],
22
- "http-status-codes": [
23
- "../../../node_modules/http-status-codes/build/cjs/index.js"
24
- ]
25
- }
26
- },
27
- "include": ["src/**/*.ts"]
28
- }
package/tsconfig.esm.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "module": "esnext",
5
- "declaration": true,
6
- "outDir": "./dist/esm",
7
- "skipLibCheck": true,
8
- "sourceMap": true,
9
- "paths": {
10
- "@rc-ex/core/*": [
11
- "../../core/dist/esm/*"
12
- ],
13
- "isomorphic-ws": [
14
- "../../../node_modules/isomorphic-ws/node.js"
15
- ],
16
- "wait-for-async": [
17
- "../../../node_modules/wait-for-async/dist/esm/index.js"
18
- ],
19
- "hyperid": [
20
- "../../../node_modules/hyperid/hyperid.js"
21
- ],
22
- "http-status-codes": [
23
- "../../../node_modules/http-status-codes/build/es/index.js"
24
- ]
25
- }
26
- },
27
- "include": ["src/**/*.ts"]
28
- }