@pluv/client 0.20.0 → 0.21.1

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.
@@ -1,18 +1,18 @@
1
1
 
2
- > @pluv/client@0.20.0 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@0.21.1 build /home/runner/work/pluv/pluv/packages/client
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.1.0
8
- CLI Target: es6
9
- ESM Build start
10
- CJS Build start
11
- ESM dist/index.mjs 41.48 KB
12
- ESM ⚡️ Build success in 74ms
13
- CJS dist/index.js 42.74 KB
14
- CJS ⚡️ Build success in 87ms
15
- DTS Build start
16
- DTS ⚡️ Build success in 3234ms
17
- DTS dist/index.d.mts 14.64 KB
18
- DTS dist/index.d.ts 14.64 KB
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.2.4
8
+ CLI Target: es6
9
+ ESM Build start
10
+ CJS Build start
11
+ ESM dist/index.mjs 41.89 KB
12
+ ESM ⚡️ Build success in 92ms
13
+ CJS dist/index.js 43.15 KB
14
+ CJS ⚡️ Build success in 93ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 2873ms
17
+ DTS dist/index.d.mts 14.60 KB
18
+ DTS dist/index.d.ts 14.60 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 0.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/crdt@0.21.1
8
+ - @pluv/types@0.21.1
9
+
10
+ ## 0.21.0
11
+
12
+ ### Minor Changes
13
+
14
+ - b98ab6b: Internal updates to platforms (i.e. `@pluv/platform-cloudflare` and `@pluv/platform-node`) to be able to support Cloudflare Worker Websocket Hibernation APIs.
15
+
16
+ ### Patch Changes
17
+
18
+ - @pluv/crdt@0.21.0
19
+ - @pluv/types@0.21.0
20
+
3
21
  ## 0.20.0
4
22
 
5
23
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -287,6 +287,6 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
287
287
  private _logDebug;
288
288
  }
289
289
 
290
- declare const createClient: <TIO extends IOLike<_pluv_types.IOAuthorize<any, any, any>, {}> = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
290
+ declare const createClient: <TIO extends IOLike = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
291
291
 
292
292
  export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient };
package/dist/index.d.ts CHANGED
@@ -287,6 +287,6 @@ declare class PluvClient<TIO extends IOLike = IOLike> {
287
287
  private _logDebug;
288
288
  }
289
289
 
290
- declare const createClient: <TIO extends IOLike<_pluv_types.IOAuthorize<any, any, any>, {}> = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
290
+ declare const createClient: <TIO extends IOLike = IOLike<_pluv_types.IOAuthorize<any, any, any>, {}>>(options: PluvClientOptions<TIO>) => PluvClient<TIO>;
291
291
 
292
292
  export { AbstractRoom, AbstractStorageStore, ConnectionState, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type UserInfo, type WebSocketConnection, type WebSocketState, createClient };
package/dist/index.js CHANGED
@@ -1027,7 +1027,7 @@ var PluvRoom = class extends AbstractRoom {
1027
1027
  _heartbeat() {
1028
1028
  this._clearTimeout(this._timeouts.pong);
1029
1029
  this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
1030
- this._sendMessage({ type: "$PING", data: {} });
1030
+ this._sendMessage('{"type":"$PING","data":{}}');
1031
1031
  }
1032
1032
  _logDebug(...data) {
1033
1033
  var _a;
@@ -1205,11 +1205,20 @@ var PluvRoom = class extends AbstractRoom {
1205
1205
  _sendMessage(data) {
1206
1206
  const webSocket = this._state.webSocket;
1207
1207
  if ((webSocket == null ? void 0 : webSocket.readyState) !== WebSocket.OPEN) return;
1208
- const shouldLog = typeof this._debug === "boolean" ? this._debug : this._debug.input.find((value) => value === data.type);
1209
- if (shouldLog) {
1210
- this._logDebug("WebSocket event sent: ", data.type, data);
1211
- }
1212
- webSocket.send(JSON.stringify(data));
1208
+ const dataType = (() => {
1209
+ var _a, _b, _c;
1210
+ if (typeof data === "object") return (_a = data.type) != null ? _a : null;
1211
+ if (typeof data !== "string") return null;
1212
+ try {
1213
+ return (_c = (_b = JSON.parse(data)) == null ? void 0 : _b.type) != null ? _c : null;
1214
+ } catch (e) {
1215
+ return null;
1216
+ }
1217
+ })();
1218
+ const shouldLog = typeof this._debug === "boolean" ? this._debug : !dataType ? false : this._debug.input.some((value) => value === data.type);
1219
+ if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
1220
+ const message = typeof data === "string" ? data : JSON.stringify(data);
1221
+ webSocket.send(message);
1213
1222
  }
1214
1223
  _updateState(updater) {
1215
1224
  let authorization;
package/dist/index.mjs CHANGED
@@ -998,7 +998,7 @@ var PluvRoom = class extends AbstractRoom {
998
998
  _heartbeat() {
999
999
  this._clearTimeout(this._timeouts.pong);
1000
1000
  this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
1001
- this._sendMessage({ type: "$PING", data: {} });
1001
+ this._sendMessage('{"type":"$PING","data":{}}');
1002
1002
  }
1003
1003
  _logDebug(...data) {
1004
1004
  var _a;
@@ -1176,11 +1176,20 @@ var PluvRoom = class extends AbstractRoom {
1176
1176
  _sendMessage(data) {
1177
1177
  const webSocket = this._state.webSocket;
1178
1178
  if ((webSocket == null ? void 0 : webSocket.readyState) !== WebSocket.OPEN) return;
1179
- const shouldLog = typeof this._debug === "boolean" ? this._debug : this._debug.input.find((value) => value === data.type);
1180
- if (shouldLog) {
1181
- this._logDebug("WebSocket event sent: ", data.type, data);
1182
- }
1183
- webSocket.send(JSON.stringify(data));
1179
+ const dataType = (() => {
1180
+ var _a, _b, _c;
1181
+ if (typeof data === "object") return (_a = data.type) != null ? _a : null;
1182
+ if (typeof data !== "string") return null;
1183
+ try {
1184
+ return (_c = (_b = JSON.parse(data)) == null ? void 0 : _b.type) != null ? _c : null;
1185
+ } catch (e) {
1186
+ return null;
1187
+ }
1188
+ })();
1189
+ const shouldLog = typeof this._debug === "boolean" ? this._debug : !dataType ? false : this._debug.input.some((value) => value === data.type);
1190
+ if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
1191
+ const message = typeof data === "string" ? data : JSON.stringify(data);
1192
+ webSocket.send(message);
1184
1193
  }
1185
1194
  _updateState(updater) {
1186
1195
  let authorization;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "0.20.0",
3
+ "version": "0.21.1",
4
4
  "description": "@pluv/io frontend client",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "wonka": "^6.3.4",
21
- "@pluv/crdt": "^0.20.0",
22
- "@pluv/types": "^0.20.0"
21
+ "@pluv/crdt": "^0.21.1",
22
+ "@pluv/types": "^0.21.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^8.57.0",
26
- "tsup": "^8.1.0",
27
- "typescript": "^5.4.5",
28
- "@pluv/tsconfig": "^0.20.0",
29
- "eslint-config-pluv": "^0.20.0"
26
+ "tsup": "^8.2.4",
27
+ "typescript": "^5.5.4",
28
+ "@pluv/tsconfig": "^0.21.1",
29
+ "eslint-config-pluv": "^0.21.1"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvRoom.ts CHANGED
@@ -763,7 +763,7 @@ export class PluvRoom<
763
763
  this._stateNotifier.subjects["my-presence"].next(presence);
764
764
  this._stateNotifier.subjects["myself"].next(myself);
765
765
 
766
- const update = this._state.connection.count > 1 ? this._crdtManager.doc.getEncodedState() ?? null : null;
766
+ const update = this._state.connection.count > 1 ? (this._crdtManager.doc.getEncodedState() ?? null) : null;
767
767
 
768
768
  this._sendMessage({
769
769
  type: "$INITIALIZE_SESSION",
@@ -871,7 +871,13 @@ export class PluvRoom<
871
871
  this._clearTimeout(this._timeouts.pong);
872
872
  this._timeouts.pong = setTimeout(this._reconnect.bind(this), PONG_TIMEOUT_MS);
873
873
 
874
- this._sendMessage({ type: "$PING", data: {} });
874
+ /**
875
+ * !HACK
876
+ * @description Send data as a stable string so that the server can react to this in a
877
+ * consistent way.
878
+ * @date July 8, 2024
879
+ */
880
+ this._sendMessage('{"type":"$PING","data":{}}');
875
881
  }
876
882
 
877
883
  private _logDebug(...data: any[]): void {
@@ -1092,19 +1098,36 @@ export class PluvRoom<
1092
1098
  await this.connect();
1093
1099
  }
1094
1100
 
1095
- private _sendMessage<TMessage extends EventMessage<string, any> = EventMessage<string, any>>(data: TMessage): void {
1101
+ private _sendMessage(data: string): void;
1102
+ private _sendMessage<TMessage extends EventMessage<string, any> = EventMessage<string, any>>(data: TMessage): void;
1103
+ private _sendMessage(data: any): void {
1096
1104
  const webSocket = this._state.webSocket;
1097
1105
 
1098
1106
  if (webSocket?.readyState !== WebSocket.OPEN) return;
1099
1107
 
1100
- const shouldLog =
1101
- typeof this._debug === "boolean" ? this._debug : this._debug.input.find((value) => value === data.type);
1108
+ const dataType: string | null = ((): string | null => {
1109
+ if (typeof data === "object") return data.type ?? null;
1110
+ if (typeof data !== "string") return null;
1102
1111
 
1103
- if (shouldLog) {
1104
- this._logDebug("WebSocket event sent: ", data.type, data);
1105
- }
1112
+ try {
1113
+ return JSON.parse(data)?.type ?? null;
1114
+ } catch {
1115
+ return null;
1116
+ }
1117
+ })();
1118
+
1119
+ const shouldLog: boolean =
1120
+ typeof this._debug === "boolean"
1121
+ ? this._debug
1122
+ : !dataType
1123
+ ? false
1124
+ : this._debug.input.some((value) => value === data.type);
1125
+
1126
+ if (shouldLog) this._logDebug("WebSocket event sent: ", data.type, data);
1127
+
1128
+ const message = typeof data === "string" ? data : JSON.stringify(data);
1106
1129
 
1107
- webSocket.send(JSON.stringify(data));
1130
+ webSocket.send(message);
1108
1131
  }
1109
1132
 
1110
1133
  private _updateState(updater: (oldState: WebSocketState<TIO>) => WebSocketState<TIO>): WebSocketState<TIO> {