@pluv/io 0.37.4 → 0.37.5

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.5 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.5 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
+ ESM dist/index.mjs 43.66 KB
16
+ ESM ⚡️ Build success in 141ms
17
+ CJS dist/index.js 45.84 KB
18
+ CJS ⚡️ Build success in 141ms
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 2685ms
21
+ DTS dist/index.d.mts 30.88 KB
22
+ DTS dist/index.d.ts 30.88 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.37.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+ - @pluv/crdt@0.37.5
9
+ - @pluv/types@0.37.5
10
+
3
11
  ## 0.37.4
4
12
 
5
13
  ### 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;
@@ -301,7 +303,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
301
303
  abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
302
304
  abstract parseData(data: string | ArrayBuffer): Record<string, any>;
303
305
  abstract randomUUID(): string;
304
- abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
306
+ abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
305
307
  validateConfig(config: any): void;
306
308
  protected _initialize(): this;
307
309
  }
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;
@@ -301,7 +303,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
301
303
  abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
302
304
  abstract parseData(data: string | ArrayBuffer): Record<string, any>;
303
305
  abstract randomUUID(): string;
304
- abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
306
+ abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
305
307
  validateConfig(config: any): void;
306
308
  protected _initialize(): this;
307
309
  }
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
  }
@@ -700,9 +701,7 @@ var IORoom = class {
700
701
  });
701
702
  }
702
703
  _getIOAuthorize(options) {
703
- if (typeof this._authorize === "function") {
704
- return this._authorize(options);
705
- }
704
+ if (typeof this._authorize === "function") return this._authorize(options);
706
705
  return this._authorize;
707
706
  }
708
707
  _getProcedure(message) {
@@ -731,7 +730,7 @@ var IORoom = class {
731
730
  }
732
731
  _initialize() {
733
732
  const promise = (() => __async(this, null, function* () {
734
- this._logDebug(`${import_kleur.default.blue(`Initializing room ${this.id}:`)}`);
733
+ this._logDebug(`${import_kleur.default.blue(`Initializing room: ${this.id}`)}`);
735
734
  if (!!this._uninitialize) {
736
735
  const uninitialize2 = (yield this._uninitialize).bind(this);
737
736
  yield uninitialize2();
@@ -741,6 +740,7 @@ var IORoom = class {
741
740
  this.id,
742
741
  (_a) => __async(this, null, function* () {
743
742
  var _b = _a, { options = {} } = _b, message = __objRest(_b, ["options"]);
743
+ yield promise;
744
744
  const sender = {
745
745
  sessionId: message.connectionId,
746
746
  user: message.user
@@ -998,7 +998,7 @@ var IORoom = class {
998
998
  };
999
999
 
1000
1000
  // src/version.generated.ts
1001
- var version = "0.37.4";
1001
+ var version = "0.37.5";
1002
1002
 
1003
1003
  // src/PluvServer.ts
1004
1004
  var PluvServer = class {
@@ -1063,11 +1063,11 @@ var PluvServer = class {
1063
1063
  if (!session) return {};
1064
1064
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
1065
1065
  const prevState = session.webSocket.state;
1066
- session.webSocket.state = __spreadProps(__spreadValues({}, prevState), {
1066
+ this._platform.setSerializedState(session.webSocket, __spreadProps(__spreadValues({}, prevState), {
1067
1067
  timers: __spreadProps(__spreadValues({}, prevState.timers), {
1068
1068
  ping: currentTime
1069
1069
  })
1070
- });
1070
+ }));
1071
1071
  return { $PONG: {} };
1072
1072
  }),
1073
1073
  $UPDATE_PRESENCE: this._procedure.broadcast((data, { session }) => {
@@ -1148,7 +1148,7 @@ var PluvServer = class {
1148
1148
  var _a, _c;
1149
1149
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1150
1150
  if (this._platform._config.handleMode !== "io") {
1151
- throw new Error(`\`createRoom' is unsupported for \`${this._platform._name}\``);
1151
+ throw new Error(`\`createRoom\` is unsupported for \`${this._platform._name}\``);
1152
1152
  }
1153
1153
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1154
1154
  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
  }
@@ -658,9 +659,7 @@ var IORoom = class {
658
659
  });
659
660
  }
660
661
  _getIOAuthorize(options) {
661
- if (typeof this._authorize === "function") {
662
- return this._authorize(options);
663
- }
662
+ if (typeof this._authorize === "function") return this._authorize(options);
664
663
  return this._authorize;
665
664
  }
666
665
  _getProcedure(message) {
@@ -689,7 +688,7 @@ var IORoom = class {
689
688
  }
690
689
  _initialize() {
691
690
  const promise = (() => __async(this, null, function* () {
692
- this._logDebug(`${colors.blue(`Initializing room ${this.id}:`)}`);
691
+ this._logDebug(`${colors.blue(`Initializing room: ${this.id}`)}`);
693
692
  if (!!this._uninitialize) {
694
693
  const uninitialize2 = (yield this._uninitialize).bind(this);
695
694
  yield uninitialize2();
@@ -699,6 +698,7 @@ var IORoom = class {
699
698
  this.id,
700
699
  (_a) => __async(this, null, function* () {
701
700
  var _b = _a, { options = {} } = _b, message = __objRest(_b, ["options"]);
701
+ yield promise;
702
702
  const sender = {
703
703
  sessionId: message.connectionId,
704
704
  user: message.user
@@ -956,7 +956,7 @@ var IORoom = class {
956
956
  };
957
957
 
958
958
  // src/version.generated.ts
959
- var version = "0.37.4";
959
+ var version = "0.37.5";
960
960
 
961
961
  // src/PluvServer.ts
962
962
  var PluvServer = class {
@@ -1021,11 +1021,11 @@ var PluvServer = class {
1021
1021
  if (!session) return {};
1022
1022
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
1023
1023
  const prevState = session.webSocket.state;
1024
- session.webSocket.state = __spreadProps(__spreadValues({}, prevState), {
1024
+ this._platform.setSerializedState(session.webSocket, __spreadProps(__spreadValues({}, prevState), {
1025
1025
  timers: __spreadProps(__spreadValues({}, prevState.timers), {
1026
1026
  ping: currentTime
1027
1027
  })
1028
- });
1028
+ }));
1029
1029
  return { $PONG: {} };
1030
1030
  }),
1031
1031
  $UPDATE_PRESENCE: this._procedure.broadcast((data, { session }) => {
@@ -1106,7 +1106,7 @@ var PluvServer = class {
1106
1106
  var _a, _c;
1107
1107
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1108
1108
  if (this._platform._config.handleMode !== "io") {
1109
- throw new Error(`\`createRoom' is unsupported for \`${this._platform._name}\``);
1109
+ throw new Error(`\`createRoom\` is unsupported for \`${this._platform._name}\``);
1110
1110
  }
1111
1111
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1112
1112
  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.5",
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.5",
25
+ "@pluv/types": "^0.37.5"
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.5",
33
+ "eslint-config-pluv": "^0.37.5"
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
@@ -499,9 +499,7 @@ export class IORoom<
499
499
  }
500
500
 
501
501
  private _getIOAuthorize(options: WebsocketRegisterConfig<TPlatform>): ResolvedPluvIOAuthorize<any, any> | null {
502
- if (typeof this._authorize === "function") {
503
- return this._authorize(options);
504
- }
502
+ if (typeof this._authorize === "function") return this._authorize(options);
505
503
 
506
504
  return this._authorize as ResolvedPluvIOAuthorize<any, any> | null;
507
505
  }
@@ -536,7 +534,7 @@ export class IORoom<
536
534
 
537
535
  private _initialize() {
538
536
  const promise = (async () => {
539
- this._logDebug(`${colors.blue(`Initializing room ${this.id}:`)}`);
537
+ this._logDebug(`${colors.blue(`Initializing room: ${this.id}`)}`);
540
538
 
541
539
  if (!!this._uninitialize) {
542
540
  const uninitialize = (await this._uninitialize).bind(this);
@@ -548,6 +546,8 @@ export class IORoom<
548
546
  const pubSubId = await this._platform.pubSub.subscribe(
549
547
  this.id,
550
548
  async ({ options = {}, ...message }): Promise<void> => {
549
+ await promise;
550
+
551
551
  const sender: SendMessageSender = {
552
552
  sessionId: message.connectionId,
553
553
  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");
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.37.4'
2
+ export const version = '0.37.5'