@couch-kit/display 0.1.0 → 0.1.2

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @couch-kit/display
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#136](https://github.com/faluciano/react-native-couch-kit/pull/136) [`973805a`](https://github.com/faluciano/react-native-couch-kit/commit/973805af754a8e22c1c6c81de4c858ffa353556c) Thanks [@faluciano](https://github.com/faluciano)! - **Bundle & tree-shaking**
8
+
9
+ - Fix `RelayDisplayHost` resolving as "not exported" for consumers on
10
+ `moduleResolution: NodeNext`/`Node16`. The package is `type: module`, so the
11
+ emitted `.d.ts` is read in strict-ESM mode where an extensionless relative
12
+ re-export (`export * from "./relay-display-host"`) is not resolved. Add the
13
+ `.js` extension to the barrel specifier, matching the other ESM packages.
14
+
15
+ ## 0.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#134](https://github.com/faluciano/react-native-couch-kit/pull/134) [`2b29581`](https://github.com/faluciano/react-native-couch-kit/commit/2b29581a8c4eddee4d4131030c375fcf1f0f4f98) Thanks [@faluciano](https://github.com/faluciano)! - **Bundle & tree-shaking**
20
+
21
+ - Fix an empty published `dist/index.js`. With `sideEffects: false`, a named
22
+ re-export barrel (`export { RelayDisplayHost } from …`) let bun's bundler
23
+ tree-shake the sole class out of the built entry, so `0.1.0` shipped a bundle
24
+ with no implementation. Use an `export *` barrel and add a post-build guard
25
+ that fails if `RelayDisplayHost` is missing from the output.
26
+
3
27
  ## 0.1.0
4
28
 
5
29
  ### Minor Changes
package/dist/index.js CHANGED
@@ -1,3 +1,93 @@
1
+ // src/relay-display-host.ts
2
+ import {
3
+ GameHostRuntime,
4
+ frameByteLength,
5
+ DEFAULT_MAX_MESSAGE_BYTES
6
+ } from "@couch-kit/runtime";
7
+ import {
8
+ RelayMessageTypes
9
+ } from "@couch-kit/client";
10
+
11
+ class RelayDisplayHost {
12
+ runtime;
13
+ ws;
14
+ roomId;
15
+ peers = new Set;
16
+ constructor(options) {
17
+ const { url, roomId, ...runtimeConfig } = options;
18
+ this.roomId = roomId;
19
+ this.runtime = new GameHostRuntime(runtimeConfig);
20
+ this.ws = new WebSocket(url);
21
+ this.ws.onopen = () => {
22
+ this.ws.send(JSON.stringify({
23
+ type: RelayMessageTypes.CREATE_ROOM,
24
+ roomId: this.roomId
25
+ }));
26
+ };
27
+ this.ws.onmessage = (event) => {
28
+ let msg;
29
+ try {
30
+ msg = JSON.parse(event.data);
31
+ } catch {
32
+ return;
33
+ }
34
+ this.handleRelayMessage(msg);
35
+ };
36
+ this.ws.onerror = (event) => this.runtime.handleError(event instanceof Error ? event : new Error("Relay socket error"));
37
+ const transport = {
38
+ send: (connectionId, message) => this.sendEnvelope(message, connectionId),
39
+ broadcast: (message) => this.sendEnvelope(message)
40
+ };
41
+ this.runtime.setTransport(transport);
42
+ }
43
+ getState = () => this.runtime.getState();
44
+ subscribe = (listener) => this.runtime.subscribe(listener);
45
+ dispatch = (action) => this.runtime.dispatch(action);
46
+ stop() {
47
+ this.runtime.setTransport(null);
48
+ this.runtime.stop();
49
+ this.ws.close();
50
+ }
51
+ sendEnvelope(message, to) {
52
+ const envelope = {
53
+ type: RelayMessageTypes.DATA,
54
+ roomId: this.roomId,
55
+ data: JSON.stringify(message)
56
+ };
57
+ if (to !== undefined)
58
+ envelope.to = to;
59
+ this.ws.send(JSON.stringify(envelope));
60
+ }
61
+ handleRelayMessage(msg) {
62
+ switch (msg.type) {
63
+ case RelayMessageTypes.PEER_JOINED:
64
+ this.peers.add(msg.peerId);
65
+ this.runtime.handleConnection(msg.peerId);
66
+ break;
67
+ case RelayMessageTypes.PEER_LEFT:
68
+ this.peers.delete(msg.peerId);
69
+ this.runtime.handleDisconnect(msg.peerId);
70
+ break;
71
+ case RelayMessageTypes.DATA: {
72
+ if (!msg.from)
73
+ break;
74
+ if (frameByteLength(msg.data) > DEFAULT_MAX_MESSAGE_BYTES)
75
+ break;
76
+ let parsed;
77
+ try {
78
+ parsed = JSON.parse(msg.data);
79
+ } catch {
80
+ break;
81
+ }
82
+ this.runtime.handleMessage(msg.from, parsed).catch((err) => this.runtime.handleError(err instanceof Error ? err : new Error(String(err))));
83
+ break;
84
+ }
85
+ case RelayMessageTypes.ERROR:
86
+ this.runtime.handleError(new Error(msg.message));
87
+ break;
88
+ }
89
+ }
90
+ }
1
91
  export {
2
92
  RelayDisplayHost
3
93
  };
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { RelayDisplayHost, type RelayDisplayHostOptions, } from "./relay-display-host";
1
+ export * from "./relay-display-host.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/display",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -43,7 +43,8 @@
43
43
  ],
44
44
  "sideEffects": false,
45
45
  "scripts": {
46
- "build": "bun build ./src/index.ts --outdir ./dist --target browser --external @couch-kit/core --external @couch-kit/runtime --external @couch-kit/client && tsc -p tsconfig.build.json",
46
+ "build": "bun build ./src/index.ts --outdir ./dist --target browser --external @couch-kit/core --external @couch-kit/runtime --external @couch-kit/client && tsc -p tsconfig.build.json && bun run verify-build",
47
+ "verify-build": "node -e \"if(!require('fs').readFileSync('./dist/index.js','utf8').includes('class RelayDisplayHost'))throw new Error('dist/index.js is missing RelayDisplayHost — empty bundle');\"",
47
48
  "prepublishOnly": "bun run build",
48
49
  "test": "bun test",
49
50
  "lint": "eslint src/",
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export {
2
- RelayDisplayHost,
3
- type RelayDisplayHostOptions,
4
- } from "./relay-display-host";
1
+ // Use an `export *` barrel (a named `export { X } from` lets bun tree-shake the
2
+ // sole class out under `sideEffects: false`, publishing an empty bundle) AND a
3
+ // `.js` extension on the specifier: the package is `type: module`, so consumers
4
+ // on `moduleResolution: NodeNext` resolve the emitted `.d.ts` in strict-ESM mode
5
+ // and an extensionless re-export fails to find `relay-display-host.d.ts`.
6
+ export * from "./relay-display-host.js";