@pluv/io 0.37.4 → 0.37.6

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,9 +1,9 @@
1
1
 
2
- > @pluv/io@0.37.4 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.37.6 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@0.37.4 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@0.37.6 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- ESM dist/index.mjs 43.58 KB
16
- ESM ⚡️ Build success in 130ms
17
- CJS dist/index.js 45.76 KB
18
- CJS ⚡️ Build success in 131ms
15
+ CJS dist/index.js 45.90 KB
16
+ CJS ⚡️ Build success in 145ms
17
+ ESM dist/index.mjs 43.72 KB
18
+ ESM ⚡️ Build success in 146ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 2811ms
21
- DTS dist/index.d.mts 30.77 KB
22
- DTS dist/index.d.ts 30.77 KB
20
+ DTS ⚡️ Build success in 2521ms
21
+ DTS dist/index.d.mts 30.92 KB
22
+ DTS dist/index.d.ts 30.92 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.37.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 3a874f1: Now logs errors to the console when errors on encountered on the `onUserConnected` and `onUserDisconnected` events.
8
+ - @pluv/crdt@0.37.6
9
+ - @pluv/types@0.37.6
10
+
11
+ ## 0.37.5
12
+
13
+ ### Patch Changes
14
+
15
+ - 9a9ecee: Fixed an issue where hibernated Cloudflare Worker websockets were not updating their last ping timer and causing them to be disconnected after some time.
16
+ - @pluv/crdt@0.37.5
17
+ - @pluv/types@0.37.5
18
+
3
19
  ## 0.37.4
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -42,6 +42,7 @@ type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEv
42
42
  type InferWebSocketSource<TAbstractWebSocket extends AbstractWebSocket> = TAbstractWebSocket extends AbstractWebSocket<infer IWebSocket> ? IWebSocket : never;
43
43
  interface AbstractWebSocketConfig {
44
44
  persistence: AbstractPersistence;
45
+ platform: AbstractPlatform<any>;
45
46
  room: string;
46
47
  }
47
48
  declare abstract class AbstractWebSocket<TWebSocket = any> {
@@ -57,6 +58,7 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
57
58
  readonly room: string;
58
59
  readonly webSocket: TWebSocket;
59
60
  private _user;
61
+ protected readonly _platform: AbstractPlatform<this>;
60
62
  abstract set presence(presence: JsonObject | null);
61
63
  abstract get readyState(): 0 | 1 | 2 | 3;
62
64
  abstract get sessionId(): string;
@@ -119,6 +121,7 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
119
121
 
120
122
  declare global {
121
123
  var console: {
124
+ error: (...data: any[]) => void;
122
125
  log: (...data: any[]) => void;
123
126
  };
124
127
  }
@@ -301,7 +304,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
301
304
  abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
302
305
  abstract parseData(data: string | ArrayBuffer): Record<string, any>;
303
306
  abstract randomUUID(): string;
304
- abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
307
+ abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
305
308
  validateConfig(config: any): void;
306
309
  protected _initialize(): this;
307
310
  }
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEv
42
42
  type InferWebSocketSource<TAbstractWebSocket extends AbstractWebSocket> = TAbstractWebSocket extends AbstractWebSocket<infer IWebSocket> ? IWebSocket : never;
43
43
  interface AbstractWebSocketConfig {
44
44
  persistence: AbstractPersistence;
45
+ platform: AbstractPlatform<any>;
45
46
  room: string;
46
47
  }
47
48
  declare abstract class AbstractWebSocket<TWebSocket = any> {
@@ -57,6 +58,7 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
57
58
  readonly room: string;
58
59
  readonly webSocket: TWebSocket;
59
60
  private _user;
61
+ protected readonly _platform: AbstractPlatform<this>;
60
62
  abstract set presence(presence: JsonObject | null);
61
63
  abstract get readyState(): 0 | 1 | 2 | 3;
62
64
  abstract get sessionId(): string;
@@ -119,6 +121,7 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
119
121
 
120
122
  declare global {
121
123
  var console: {
124
+ error: (...data: any[]) => void;
122
125
  log: (...data: any[]) => void;
123
126
  };
124
127
  }
@@ -301,7 +304,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
301
304
  abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
302
305
  abstract parseData(data: string | ArrayBuffer): Record<string, any>;
303
306
  abstract randomUUID(): string;
304
- abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
307
+ abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
305
308
  validateConfig(config: any): void;
306
309
  protected _initialize(): this;
307
310
  }
package/dist/index.js CHANGED
@@ -245,8 +245,9 @@ var AbstractWebSocket = class {
245
245
  /** The connection is closed. */
246
246
  this.CLOSED = 3;
247
247
  this._user = null;
248
- const { persistence, room } = config;
248
+ const { persistence, platform, room } = config;
249
249
  this.persistence = persistence;
250
+ this._platform = platform;
250
251
  this.room = room;
251
252
  this.webSocket = webSocket;
252
253
  }
@@ -617,7 +618,8 @@ var IORoom = class {
617
618
  webSocket: pluvWs.webSocket
618
619
  })
619
620
  );
620
- } catch (e) {
621
+ } catch (err) {
622
+ console.error(err);
621
623
  }
622
624
  });
623
625
  }
@@ -646,7 +648,8 @@ var IORoom = class {
646
648
  user: session.user
647
649
  })
648
650
  );
649
- } catch (e) {
651
+ } catch (err) {
652
+ console.error(err);
650
653
  }
651
654
  });
652
655
  }
@@ -700,9 +703,7 @@ var IORoom = class {
700
703
  });
701
704
  }
702
705
  _getIOAuthorize(options) {
703
- if (typeof this._authorize === "function") {
704
- return this._authorize(options);
705
- }
706
+ if (typeof this._authorize === "function") return this._authorize(options);
706
707
  return this._authorize;
707
708
  }
708
709
  _getProcedure(message) {
@@ -731,7 +732,7 @@ var IORoom = class {
731
732
  }
732
733
  _initialize() {
733
734
  const promise = (() => __async(this, null, function* () {
734
- this._logDebug(`${import_kleur.default.blue(`Initializing room ${this.id}:`)}`);
735
+ this._logDebug(`${import_kleur.default.blue(`Initializing room: ${this.id}`)}`);
735
736
  if (!!this._uninitialize) {
736
737
  const uninitialize2 = (yield this._uninitialize).bind(this);
737
738
  yield uninitialize2();
@@ -741,6 +742,7 @@ var IORoom = class {
741
742
  this.id,
742
743
  (_a) => __async(this, null, function* () {
743
744
  var _b = _a, { options = {} } = _b, message = __objRest(_b, ["options"]);
745
+ yield promise;
744
746
  const sender = {
745
747
  sessionId: message.connectionId,
746
748
  user: message.user
@@ -998,7 +1000,7 @@ var IORoom = class {
998
1000
  };
999
1001
 
1000
1002
  // src/version.generated.ts
1001
- var version = "0.37.4";
1003
+ var version = "0.37.6";
1002
1004
 
1003
1005
  // src/PluvServer.ts
1004
1006
  var PluvServer = class {
@@ -1063,11 +1065,11 @@ var PluvServer = class {
1063
1065
  if (!session) return {};
1064
1066
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
1065
1067
  const prevState = session.webSocket.state;
1066
- session.webSocket.state = __spreadProps(__spreadValues({}, prevState), {
1068
+ this._platform.setSerializedState(session.webSocket, __spreadProps(__spreadValues({}, prevState), {
1067
1069
  timers: __spreadProps(__spreadValues({}, prevState.timers), {
1068
1070
  ping: currentTime
1069
1071
  })
1070
- });
1072
+ }));
1071
1073
  return { $PONG: {} };
1072
1074
  }),
1073
1075
  $UPDATE_PRESENCE: this._procedure.broadcast((data, { session }) => {
@@ -1148,7 +1150,7 @@ var PluvServer = class {
1148
1150
  var _a, _c;
1149
1151
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1150
1152
  if (this._platform._config.handleMode !== "io") {
1151
- throw new Error(`\`createRoom' is unsupported for \`${this._platform._name}\``);
1153
+ throw new Error(`\`createRoom\` is unsupported for \`${this._platform._name}\``);
1152
1154
  }
1153
1155
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1154
1156
  const roomContext = platformRoomContext;
package/dist/index.mjs CHANGED
@@ -203,8 +203,9 @@ var AbstractWebSocket = class {
203
203
  /** The connection is closed. */
204
204
  this.CLOSED = 3;
205
205
  this._user = null;
206
- const { persistence, room } = config;
206
+ const { persistence, platform, room } = config;
207
207
  this.persistence = persistence;
208
+ this._platform = platform;
208
209
  this.room = room;
209
210
  this.webSocket = webSocket;
210
211
  }
@@ -575,7 +576,8 @@ var IORoom = class {
575
576
  webSocket: pluvWs.webSocket
576
577
  })
577
578
  );
578
- } catch (e) {
579
+ } catch (err) {
580
+ console.error(err);
579
581
  }
580
582
  });
581
583
  }
@@ -604,7 +606,8 @@ var IORoom = class {
604
606
  user: session.user
605
607
  })
606
608
  );
607
- } catch (e) {
609
+ } catch (err) {
610
+ console.error(err);
608
611
  }
609
612
  });
610
613
  }
@@ -658,9 +661,7 @@ var IORoom = class {
658
661
  });
659
662
  }
660
663
  _getIOAuthorize(options) {
661
- if (typeof this._authorize === "function") {
662
- return this._authorize(options);
663
- }
664
+ if (typeof this._authorize === "function") return this._authorize(options);
664
665
  return this._authorize;
665
666
  }
666
667
  _getProcedure(message) {
@@ -689,7 +690,7 @@ var IORoom = class {
689
690
  }
690
691
  _initialize() {
691
692
  const promise = (() => __async(this, null, function* () {
692
- this._logDebug(`${colors.blue(`Initializing room ${this.id}:`)}`);
693
+ this._logDebug(`${colors.blue(`Initializing room: ${this.id}`)}`);
693
694
  if (!!this._uninitialize) {
694
695
  const uninitialize2 = (yield this._uninitialize).bind(this);
695
696
  yield uninitialize2();
@@ -699,6 +700,7 @@ var IORoom = class {
699
700
  this.id,
700
701
  (_a) => __async(this, null, function* () {
701
702
  var _b = _a, { options = {} } = _b, message = __objRest(_b, ["options"]);
703
+ yield promise;
702
704
  const sender = {
703
705
  sessionId: message.connectionId,
704
706
  user: message.user
@@ -956,7 +958,7 @@ var IORoom = class {
956
958
  };
957
959
 
958
960
  // src/version.generated.ts
959
- var version = "0.37.4";
961
+ var version = "0.37.6";
960
962
 
961
963
  // src/PluvServer.ts
962
964
  var PluvServer = class {
@@ -1021,11 +1023,11 @@ var PluvServer = class {
1021
1023
  if (!session) return {};
1022
1024
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
1023
1025
  const prevState = session.webSocket.state;
1024
- session.webSocket.state = __spreadProps(__spreadValues({}, prevState), {
1026
+ this._platform.setSerializedState(session.webSocket, __spreadProps(__spreadValues({}, prevState), {
1025
1027
  timers: __spreadProps(__spreadValues({}, prevState.timers), {
1026
1028
  ping: currentTime
1027
1029
  })
1028
- });
1030
+ }));
1029
1031
  return { $PONG: {} };
1030
1032
  }),
1031
1033
  $UPDATE_PRESENCE: this._procedure.broadcast((data, { session }) => {
@@ -1106,7 +1108,7 @@ var PluvServer = class {
1106
1108
  var _a, _c;
1107
1109
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1108
1110
  if (this._platform._config.handleMode !== "io") {
1109
- throw new Error(`\`createRoom' is unsupported for \`${this._platform._name}\``);
1111
+ throw new Error(`\`createRoom\` is unsupported for \`${this._platform._name}\``);
1110
1112
  }
1111
1113
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1112
1114
  const roomContext = platformRoomContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.37.4",
3
+ "version": "0.37.6",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "jose": "^5.10.0",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.5",
24
- "@pluv/crdt": "^0.37.4",
25
- "@pluv/types": "^0.37.4"
24
+ "@pluv/crdt": "^0.37.6",
25
+ "@pluv/types": "^0.37.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.1",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.2",
32
- "@pluv/tsconfig": "^0.37.4",
33
- "eslint-config-pluv": "^0.37.4"
32
+ "@pluv/tsconfig": "^0.37.6",
33
+ "eslint-config-pluv": "^0.37.6"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
@@ -78,7 +78,10 @@ export abstract class AbstractPlatform<
78
78
 
79
79
  public abstract randomUUID(): string;
80
80
 
81
- public abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
81
+ public abstract setSerializedState(
82
+ webSocket: AbstractWebSocket,
83
+ state: WebSocketSerializedState,
84
+ ): WebSocketSerializedState;
82
85
 
83
86
  public validateConfig(config: any): void {}
84
87
 
@@ -7,6 +7,7 @@ import type {
7
7
  MaybePromise,
8
8
  } from "@pluv/types";
9
9
  import type { AbstractPersistence } from "./AbstractPersistence";
10
+ import type { AbstractPlatform } from "./AbstractPlatform";
10
11
  import type { WebSocketSerializedState, WebSocketSession } from "./types";
11
12
 
12
13
  export type AbstractEvent = {};
@@ -49,6 +50,7 @@ export type InferWebSocketSource<TAbstractWebSocket extends AbstractWebSocket> =
49
50
 
50
51
  export interface AbstractWebSocketConfig {
51
52
  persistence: AbstractPersistence;
53
+ platform: AbstractPlatform<any>;
52
54
  room: string;
53
55
  }
54
56
 
@@ -68,6 +70,8 @@ export abstract class AbstractWebSocket<TWebSocket = any> {
68
70
 
69
71
  private _user: BaseUser | null = null;
70
72
 
73
+ protected readonly _platform: AbstractPlatform<this>;
74
+
71
75
  public abstract set presence(presence: JsonObject | null);
72
76
  public abstract get readyState(): 0 | 1 | 2 | 3;
73
77
  public abstract get sessionId(): string;
@@ -75,9 +79,10 @@ export abstract class AbstractWebSocket<TWebSocket = any> {
75
79
  public abstract set state(state: WebSocketSerializedState);
76
80
 
77
81
  constructor(webSocket: TWebSocket, config: AbstractWebSocketConfig) {
78
- const { persistence, room } = config;
82
+ const { persistence, platform, room } = config;
79
83
 
80
84
  this.persistence = persistence;
85
+ this._platform = platform;
81
86
  this.room = room;
82
87
  this.webSocket = webSocket;
83
88
  }
package/src/IORoom.ts CHANGED
@@ -398,7 +398,9 @@ export class IORoom<
398
398
  webSocket: pluvWs.webSocket,
399
399
  }),
400
400
  );
401
- } catch {}
401
+ } catch (err) {
402
+ console.error(err);
403
+ }
402
404
  }
403
405
 
404
406
  private _ensureDetached(): void {
@@ -430,7 +432,9 @@ export class IORoom<
430
432
  user: session.user,
431
433
  }),
432
434
  );
433
- } catch {}
435
+ } catch (err) {
436
+ console.error(err);
437
+ }
434
438
  }
435
439
 
436
440
  private _getAbstractWs(webSocket: WebSocketType<TPlatform>): AbstractWebSocket | null {
@@ -499,9 +503,7 @@ export class IORoom<
499
503
  }
500
504
 
501
505
  private _getIOAuthorize(options: WebsocketRegisterConfig<TPlatform>): ResolvedPluvIOAuthorize<any, any> | null {
502
- if (typeof this._authorize === "function") {
503
- return this._authorize(options);
504
- }
506
+ if (typeof this._authorize === "function") return this._authorize(options);
505
507
 
506
508
  return this._authorize as ResolvedPluvIOAuthorize<any, any> | null;
507
509
  }
@@ -536,7 +538,7 @@ export class IORoom<
536
538
 
537
539
  private _initialize() {
538
540
  const promise = (async () => {
539
- this._logDebug(`${colors.blue(`Initializing room ${this.id}:`)}`);
541
+ this._logDebug(`${colors.blue(`Initializing room: ${this.id}`)}`);
540
542
 
541
543
  if (!!this._uninitialize) {
542
544
  const uninitialize = (await this._uninitialize).bind(this);
@@ -548,6 +550,8 @@ export class IORoom<
548
550
  const pubSubId = await this._platform.pubSub.subscribe(
549
551
  this.id,
550
552
  async ({ options = {}, ...message }): Promise<void> => {
553
+ await promise;
554
+
551
555
  const sender: SendMessageSender = {
552
556
  sessionId: message.connectionId,
553
557
  user: message.user,
package/src/PluvServer.ts CHANGED
@@ -151,13 +151,13 @@ export class PluvServer<
151
151
  const currentTime = new Date().getTime();
152
152
  const prevState = session.webSocket.state;
153
153
 
154
- session.webSocket.state = {
154
+ this._platform.setSerializedState(session.webSocket, {
155
155
  ...prevState,
156
156
  timers: {
157
157
  ...prevState.timers,
158
158
  ping: currentTime,
159
159
  },
160
- };
160
+ });
161
161
 
162
162
  return { $PONG: {} };
163
163
  }),
@@ -237,7 +237,6 @@ export class PluvServer<
237
237
  crdt = noop,
238
238
  debug = false,
239
239
  getInitialStorage,
240
-
241
240
  platform,
242
241
  router = new PluvRouter<TPlatform, TAuthorize, TContext, TEvents>({} as TEvents),
243
242
  } = options;
@@ -282,7 +281,7 @@ export class PluvServer<
282
281
  >[0] & { _meta?: any };
283
282
 
284
283
  if (this._platform._config.handleMode !== "io") {
285
- throw new Error(`\`createRoom\' is unsupported for \`${this._platform._name}\``);
284
+ throw new Error(`\`createRoom\` is unsupported for \`${this._platform._name}\``);
286
285
  }
287
286
 
288
287
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
package/src/types.ts CHANGED
@@ -25,6 +25,7 @@ import type { PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
25
25
 
26
26
  declare global {
27
27
  var console: {
28
+ error: (...data: any[]) => void;
28
29
  log: (...data: any[]) => void;
29
30
  };
30
31
  }
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.37.4'
2
+ export const version = '0.37.6'
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "@pluv/tsconfig/library.json",
3
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
3
+ "include": ["next-env.d.ts", "src/*.ts"],
4
4
  "exclude": ["node_modules"]
5
5
  }