@pluv/platform-cloudflare 0.21.1 → 0.22.0

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,5 +1,5 @@
1
1
 
2
- > @pluv/platform-cloudflare@0.21.1 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.22.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 15.00 KB
12
- CJS ⚡️ Build success in 118ms
13
- ESM dist/index.mjs 13.96 KB
14
- ESM ⚡️ Build success in 122ms
11
+ ESM dist/index.mjs 14.13 KB
12
+ ESM ⚡️ Build success in 95ms
13
+ CJS dist/index.js 15.18 KB
14
+ CJS ⚡️ Build success in 96ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 2904ms
17
- DTS dist/index.d.mts 4.11 KB
18
- DTS dist/index.d.ts 4.11 KB
16
+ DTS ⚡️ Build success in 3405ms
17
+ DTS dist/index.d.mts 4.15 KB
18
+ DTS dist/index.d.ts 4.15 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 650e577: \* Fix `@pluv/platform-cloudflare` causing frequent disconnects due to incorrect heartbeat handling.
8
+ - Updated default `mode` of `@pluv/platform-cloudflare` back to `"detached"` (i.e. use Cloudflare Worker Hibernation API by default).
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [650e577]
13
+ - @pluv/io@0.22.0
14
+ - @pluv/types@0.22.0
15
+
3
16
  ## 0.21.1
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -7,6 +7,7 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
7
7
  get readyState(): 0 | 1 | 2 | 3;
8
8
  get sessionId(): string;
9
9
  get state(): WebSocketSerializedState;
10
+ set state(state: WebSocketSerializedState);
10
11
  constructor(webSocket: WebSocket, config: CloudflareWebSocketConfig);
11
12
  addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
12
13
  close(code?: number | undefined, reason?: string | undefined): void;
@@ -31,7 +32,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends
31
32
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
32
33
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
33
34
  getLastPing(webSocket: CloudflareWebSocket): number | null;
34
- getSerializedState(webSocket: CloudflareWebSocket): WebSocketSerializedState | null;
35
+ getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
35
36
  getSessionId(webSocket: WebSocket): string | null;
36
37
  getWebSockets(): readonly WebSocket[];
37
38
  initialize(config: AbstractPlatformConfig<{
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
7
7
  get readyState(): 0 | 1 | 2 | 3;
8
8
  get sessionId(): string;
9
9
  get state(): WebSocketSerializedState;
10
+ set state(state: WebSocketSerializedState);
10
11
  constructor(webSocket: WebSocket, config: CloudflareWebSocketConfig);
11
12
  addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
12
13
  close(code?: number | undefined, reason?: string | undefined): void;
@@ -31,7 +32,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends
31
32
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
32
33
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
33
34
  getLastPing(webSocket: CloudflareWebSocket): number | null;
34
- getSerializedState(webSocket: CloudflareWebSocket): WebSocketSerializedState | null;
35
+ getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
35
36
  getSessionId(webSocket: WebSocket): string | null;
36
37
  getWebSockets(): readonly WebSocket[];
37
38
  initialize(config: AbstractPlatformConfig<{
package/dist/index.js CHANGED
@@ -207,6 +207,10 @@ var CloudflareWebSocket = class extends import_io.AbstractWebSocket {
207
207
  if (!state) throw new Error("Could not get websocket state");
208
208
  return state;
209
209
  }
210
+ set state(state) {
211
+ const deserialized = this.webSocket.deserializeAttachment();
212
+ this.webSocket.serializeAttachment(__spreadProps(__spreadValues({}, deserialized), { state }));
213
+ }
210
214
  constructor(webSocket, config) {
211
215
  const { room } = config;
212
216
  super(webSocket, config);
@@ -333,7 +337,7 @@ var PersistanceCloudflare = class extends import_io2.AbstractPersistance {
333
337
  };
334
338
 
335
339
  // src/constants.ts
336
- var DEFAULT_REGISTRATION_MODE = "attached";
340
+ var DEFAULT_REGISTRATION_MODE = "detached";
337
341
 
338
342
  // src/CloudflarePlatform.ts
339
343
  var CloudflarePlatform = class _CloudflarePlatform extends import_io3.AbstractPlatform {
@@ -370,7 +374,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io3.AbstractPl
370
374
  }
371
375
  getSerializedState(webSocket) {
372
376
  var _a;
373
- const deserialized = webSocket.webSocket.deserializeAttachment();
377
+ const deserialized = webSocket.deserializeAttachment();
374
378
  return (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
375
379
  }
376
380
  getSessionId(webSocket) {
package/dist/index.mjs CHANGED
@@ -183,6 +183,10 @@ var CloudflareWebSocket = class extends AbstractWebSocket {
183
183
  if (!state) throw new Error("Could not get websocket state");
184
184
  return state;
185
185
  }
186
+ set state(state) {
187
+ const deserialized = this.webSocket.deserializeAttachment();
188
+ this.webSocket.serializeAttachment(__spreadProps(__spreadValues({}, deserialized), { state }));
189
+ }
186
190
  constructor(webSocket, config) {
187
191
  const { room } = config;
188
192
  super(webSocket, config);
@@ -309,7 +313,7 @@ var PersistanceCloudflare = class extends AbstractPersistance {
309
313
  };
310
314
 
311
315
  // src/constants.ts
312
- var DEFAULT_REGISTRATION_MODE = "attached";
316
+ var DEFAULT_REGISTRATION_MODE = "detached";
313
317
 
314
318
  // src/CloudflarePlatform.ts
315
319
  var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
@@ -346,7 +350,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
346
350
  }
347
351
  getSerializedState(webSocket) {
348
352
  var _a;
349
- const deserialized = webSocket.webSocket.deserializeAttachment();
353
+ const deserialized = webSocket.deserializeAttachment();
350
354
  return (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
351
355
  }
352
356
  getSessionId(webSocket) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-cloudflare",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "description": "@pluv/io adapter for cloudflare workers",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,16 +18,16 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "path-to-regexp": "^7.1.0",
21
- "@pluv/io": "^0.21.1",
22
- "@pluv/types": "^0.21.1"
21
+ "@pluv/io": "^0.22.0",
22
+ "@pluv/types": "^0.22.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@cloudflare/workers-types": "^4.20240806.0",
26
26
  "eslint": "^8.57.0",
27
27
  "tsup": "^8.2.4",
28
28
  "typescript": "^5.5.4",
29
- "@pluv/tsconfig": "^0.21.1",
30
- "eslint-config-pluv": "^0.21.1"
29
+ "@pluv/tsconfig": "^0.22.0",
30
+ "eslint-config-pluv": "^0.22.0"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -68,8 +68,8 @@ export class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends A
68
68
  return timestamp?.getTime() ?? null;
69
69
  }
70
70
 
71
- public getSerializedState(webSocket: CloudflareWebSocket): WebSocketSerializedState | null {
72
- const deserialized = webSocket.webSocket.deserializeAttachment();
71
+ public getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null {
72
+ const deserialized = webSocket.deserializeAttachment();
73
73
 
74
74
  return deserialized?.state ?? null;
75
75
  }
@@ -46,6 +46,12 @@ export class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
46
46
  return state;
47
47
  }
48
48
 
49
+ public set state(state: WebSocketSerializedState) {
50
+ const deserialized = this.webSocket.deserializeAttachment();
51
+
52
+ this.webSocket.serializeAttachment({ ...deserialized, state });
53
+ }
54
+
49
55
  constructor(webSocket: WebSocket, config: CloudflareWebSocketConfig) {
50
56
  const { room } = config;
51
57
 
package/src/constants.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { WebSocketRegistrationMode } from "@pluv/io";
2
2
 
3
- export const DEFAULT_REGISTRATION_MODE: WebSocketRegistrationMode = "attached";
3
+ export const DEFAULT_REGISTRATION_MODE: WebSocketRegistrationMode = "detached";
@@ -1,6 +1,8 @@
1
1
  import type { CloudflarePlatformConfig } from "./CloudflarePlatform";
2
2
  import { CloudflarePlatform } from "./CloudflarePlatform";
3
3
 
4
- export const platformCloudflare = <TEnv extends Record<string, any> = {}>(config: CloudflarePlatformConfig<TEnv> = {}): CloudflarePlatform<TEnv> => {
4
+ export const platformCloudflare = <TEnv extends Record<string, any> = {}>(
5
+ config: CloudflarePlatformConfig<TEnv> = {},
6
+ ): CloudflarePlatform<TEnv> => {
5
7
  return new CloudflarePlatform<TEnv>(config);
6
8
  };