@pluv/platform-cloudflare 0.37.3 → 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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +18 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -7
- package/dist/index.mjs +15 -7
- package/package.json +6 -6
- package/src/CloudflarePlatform.ts +14 -7
- package/src/CloudflareWebSocket.ts +12 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.37.
|
|
2
|
+
> @pluv/platform-cloudflare@0.37.5 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m13.95 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 41ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.82 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 42ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m6.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m6.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 968ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m6.63 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m6.63 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @pluv/platform-cloudflare
|
|
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
|
+
- Updated dependencies [9a9ecee]
|
|
9
|
+
- @pluv/io@0.37.5
|
|
10
|
+
- @pluv/persistence-cloudflare-transactional-storage@0.37.5
|
|
11
|
+
- @pluv/types@0.37.5
|
|
12
|
+
|
|
13
|
+
## 0.37.4
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @pluv/io@0.37.4
|
|
18
|
+
- @pluv/persistence-cloudflare-transactional-storage@0.37.4
|
|
19
|
+
- @pluv/types@0.37.4
|
|
20
|
+
|
|
3
21
|
## 0.37.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -72,7 +72,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
|
|
|
72
72
|
initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
|
|
73
73
|
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
74
74
|
randomUUID(): string;
|
|
75
|
-
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState):
|
|
75
|
+
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
76
76
|
private _getDetachedState;
|
|
77
77
|
}
|
|
78
78
|
|
package/dist/index.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
|
|
|
72
72
|
initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
|
|
73
73
|
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
74
74
|
randomUUID(): string;
|
|
75
|
-
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState):
|
|
75
|
+
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
76
76
|
private _getDetachedState;
|
|
77
77
|
}
|
|
78
78
|
|
package/dist/index.js
CHANGED
|
@@ -218,7 +218,14 @@ var CloudflareWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
218
218
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
219
219
|
const state = (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
|
|
220
220
|
if (!state) throw new Error("Could not get websocket state");
|
|
221
|
-
|
|
221
|
+
const currentPing = state.timers.ping;
|
|
222
|
+
const lastPing = this._platform.getLastPing(this);
|
|
223
|
+
if (!lastPing) return state;
|
|
224
|
+
if (currentPing >= lastPing) return state;
|
|
225
|
+
const newState = __spreadProps(__spreadValues({}, state), {
|
|
226
|
+
timers: __spreadProps(__spreadValues({}, state.timers), { ping: lastPing })
|
|
227
|
+
});
|
|
228
|
+
return this._platform.setSerializedState(this, newState);
|
|
222
229
|
}
|
|
223
230
|
set state(state) {
|
|
224
231
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
@@ -298,7 +305,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
|
|
|
298
305
|
}
|
|
299
306
|
convertWebSocket(webSocket, config) {
|
|
300
307
|
const { room } = config;
|
|
301
|
-
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, room });
|
|
308
|
+
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, platform: this, room });
|
|
302
309
|
}
|
|
303
310
|
getLastPing(webSocket) {
|
|
304
311
|
var _a;
|
|
@@ -323,14 +330,13 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
|
|
|
323
330
|
var _a;
|
|
324
331
|
const detachedState = this._getDetachedState();
|
|
325
332
|
if (!detachedState) return [];
|
|
326
|
-
|
|
333
|
+
const webSockets = (_a = detachedState.getWebSockets()) != null ? _a : [];
|
|
334
|
+
return webSockets;
|
|
327
335
|
}
|
|
328
336
|
initialize(config) {
|
|
329
337
|
var _a;
|
|
330
338
|
const roomContext = (_a = config.roomContext) != null ? _a : __spreadValues({}, this._roomContext);
|
|
331
|
-
if (!roomContext.env || !roomContext.state)
|
|
332
|
-
throw new Error("Could not derive platform roomContext");
|
|
333
|
-
}
|
|
339
|
+
if (!roomContext.env || !roomContext.state) throw new Error("Could not derive platform roomContext");
|
|
334
340
|
return new _CloudflarePlatform({
|
|
335
341
|
roomContext: {
|
|
336
342
|
env: roomContext.env,
|
|
@@ -354,11 +360,13 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
|
|
|
354
360
|
var _a;
|
|
355
361
|
const deserialized = (_a = webSocket.webSocket.deserializeAttachment()) != null ? _a : {};
|
|
356
362
|
webSocket.webSocket.serializeAttachment(__spreadProps(__spreadValues({}, deserialized), { state }));
|
|
363
|
+
return state;
|
|
357
364
|
}
|
|
358
365
|
_getDetachedState() {
|
|
359
366
|
var _a, _b;
|
|
360
367
|
if (this._config.registrationMode !== "detached") return null;
|
|
361
|
-
|
|
368
|
+
const detachedState = (_b = (_a = this._roomContext) == null ? void 0 : _a.state) != null ? _b : null;
|
|
369
|
+
return detachedState;
|
|
362
370
|
}
|
|
363
371
|
};
|
|
364
372
|
|
package/dist/index.mjs
CHANGED
|
@@ -193,7 +193,14 @@ var CloudflareWebSocket = class extends AbstractWebSocket {
|
|
|
193
193
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
194
194
|
const state = (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
|
|
195
195
|
if (!state) throw new Error("Could not get websocket state");
|
|
196
|
-
|
|
196
|
+
const currentPing = state.timers.ping;
|
|
197
|
+
const lastPing = this._platform.getLastPing(this);
|
|
198
|
+
if (!lastPing) return state;
|
|
199
|
+
if (currentPing >= lastPing) return state;
|
|
200
|
+
const newState = __spreadProps(__spreadValues({}, state), {
|
|
201
|
+
timers: __spreadProps(__spreadValues({}, state.timers), { ping: lastPing })
|
|
202
|
+
});
|
|
203
|
+
return this._platform.setSerializedState(this, newState);
|
|
197
204
|
}
|
|
198
205
|
set state(state) {
|
|
199
206
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
@@ -273,7 +280,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
|
273
280
|
}
|
|
274
281
|
convertWebSocket(webSocket, config) {
|
|
275
282
|
const { room } = config;
|
|
276
|
-
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, room });
|
|
283
|
+
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, platform: this, room });
|
|
277
284
|
}
|
|
278
285
|
getLastPing(webSocket) {
|
|
279
286
|
var _a;
|
|
@@ -298,14 +305,13 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
|
298
305
|
var _a;
|
|
299
306
|
const detachedState = this._getDetachedState();
|
|
300
307
|
if (!detachedState) return [];
|
|
301
|
-
|
|
308
|
+
const webSockets = (_a = detachedState.getWebSockets()) != null ? _a : [];
|
|
309
|
+
return webSockets;
|
|
302
310
|
}
|
|
303
311
|
initialize(config) {
|
|
304
312
|
var _a;
|
|
305
313
|
const roomContext = (_a = config.roomContext) != null ? _a : __spreadValues({}, this._roomContext);
|
|
306
|
-
if (!roomContext.env || !roomContext.state)
|
|
307
|
-
throw new Error("Could not derive platform roomContext");
|
|
308
|
-
}
|
|
314
|
+
if (!roomContext.env || !roomContext.state) throw new Error("Could not derive platform roomContext");
|
|
309
315
|
return new _CloudflarePlatform({
|
|
310
316
|
roomContext: {
|
|
311
317
|
env: roomContext.env,
|
|
@@ -329,11 +335,13 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
|
329
335
|
var _a;
|
|
330
336
|
const deserialized = (_a = webSocket.webSocket.deserializeAttachment()) != null ? _a : {};
|
|
331
337
|
webSocket.webSocket.serializeAttachment(__spreadProps(__spreadValues({}, deserialized), { state }));
|
|
338
|
+
return state;
|
|
332
339
|
}
|
|
333
340
|
_getDetachedState() {
|
|
334
341
|
var _a, _b;
|
|
335
342
|
if (this._config.registrationMode !== "detached") return null;
|
|
336
|
-
|
|
343
|
+
const detachedState = (_b = (_a = this._roomContext) == null ? void 0 : _a.state) != null ? _b : null;
|
|
344
|
+
return detachedState;
|
|
337
345
|
}
|
|
338
346
|
};
|
|
339
347
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.5",
|
|
4
4
|
"description": "@pluv/io adapter for cloudflare workers",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"path-to-regexp": "^8.2.0",
|
|
21
|
-
"@pluv/io": "^0.37.
|
|
22
|
-
"@pluv/persistence-cloudflare-transactional-storage": "^0.37.
|
|
23
|
-
"@pluv/types": "^0.37.
|
|
21
|
+
"@pluv/io": "^0.37.5",
|
|
22
|
+
"@pluv/persistence-cloudflare-transactional-storage": "^0.37.5",
|
|
23
|
+
"@pluv/types": "^0.37.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@cloudflare/workers-types": "^4.20250303.0",
|
|
27
27
|
"eslint": "^8.57.1",
|
|
28
28
|
"tsup": "^8.4.0",
|
|
29
29
|
"typescript": "^5.8.2",
|
|
30
|
-
"@pluv/tsconfig": "^0.37.
|
|
31
|
-
"eslint-config-pluv": "^0.37.
|
|
30
|
+
"@pluv/tsconfig": "^0.37.5",
|
|
31
|
+
"eslint-config-pluv": "^0.37.5"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -96,7 +96,7 @@ export class CloudflarePlatform<
|
|
|
96
96
|
public convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket {
|
|
97
97
|
const { room } = config;
|
|
98
98
|
|
|
99
|
-
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, room });
|
|
99
|
+
return new CloudflareWebSocket(webSocket, { persistence: this.persistence, platform: this, room });
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
public getLastPing(webSocket: CloudflareWebSocket): number | null {
|
|
@@ -129,15 +129,15 @@ export class CloudflarePlatform<
|
|
|
129
129
|
|
|
130
130
|
if (!detachedState) return [];
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
const webSockets = detachedState.getWebSockets() ?? [];
|
|
133
|
+
|
|
134
|
+
return webSockets;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
public initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this {
|
|
136
138
|
const roomContext = config.roomContext ?? { ...this._roomContext };
|
|
137
139
|
|
|
138
|
-
if (!roomContext.env || !roomContext.state)
|
|
139
|
-
throw new Error("Could not derive platform roomContext");
|
|
140
|
-
}
|
|
140
|
+
if (!roomContext.env || !roomContext.state) throw new Error("Could not derive platform roomContext");
|
|
141
141
|
|
|
142
142
|
return new CloudflarePlatform<TEnv, TMeta>({
|
|
143
143
|
roomContext: {
|
|
@@ -163,15 +163,22 @@ export class CloudflarePlatform<
|
|
|
163
163
|
return crypto.randomUUID();
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
public setSerializedState(
|
|
166
|
+
public setSerializedState(
|
|
167
|
+
webSocket: CloudflareWebSocket,
|
|
168
|
+
state: WebSocketSerializedState,
|
|
169
|
+
): WebSocketSerializedState {
|
|
167
170
|
const deserialized = webSocket.webSocket.deserializeAttachment() ?? {};
|
|
168
171
|
|
|
169
172
|
webSocket.webSocket.serializeAttachment({ ...deserialized, state });
|
|
173
|
+
|
|
174
|
+
return state;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
private _getDetachedState(): DurableObjectState | null {
|
|
173
178
|
if (this._config.registrationMode !== "detached") return null;
|
|
174
179
|
|
|
175
|
-
|
|
180
|
+
const detachedState = this._roomContext?.state ?? null;
|
|
181
|
+
|
|
182
|
+
return detachedState;
|
|
176
183
|
}
|
|
177
184
|
}
|
|
@@ -43,7 +43,18 @@ export class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
|
43
43
|
|
|
44
44
|
if (!state) throw new Error("Could not get websocket state");
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
const currentPing = state.timers.ping;
|
|
47
|
+
const lastPing = this._platform.getLastPing(this);
|
|
48
|
+
|
|
49
|
+
if (!lastPing) return state;
|
|
50
|
+
if (currentPing >= lastPing) return state;
|
|
51
|
+
|
|
52
|
+
const newState: WebSocketSerializedState = {
|
|
53
|
+
...state,
|
|
54
|
+
timers: { ...state.timers, ping: lastPing },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return this._platform.setSerializedState(this, newState);
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
public set state(state: WebSocketSerializedState) {
|