@pluv/platform-cloudflare 0.23.0 → 0.24.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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +9 -0
- package/dist/index.js +24 -18
- package/dist/index.mjs +24 -18
- package/package.json +5 -5
- package/src/CloudflarePlatform.ts +1 -3
- package/src/CloudflareWebSocket.ts +1 -1
- package/src/createPluvHandler.ts +9 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.
|
|
2
|
+
> @pluv/platform-cloudflare@0.24.0 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
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m14.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m15.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m14.43 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 82ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m15.47 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 88ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3446ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.15 KB[39m
|
|
18
18
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.15 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -68,23 +68,29 @@ var createPluvHandler = (config) => {
|
|
|
68
68
|
const { authorize, binding, endpoint = "/api/pluv", modify, io } = config;
|
|
69
69
|
const DurableObject = class {
|
|
70
70
|
constructor(state, env) {
|
|
71
|
-
this._room = io.
|
|
71
|
+
this._room = io.createRoom(state.id.toString(), { env, state });
|
|
72
72
|
}
|
|
73
73
|
webSocketClose(ws, code, reason, wasClean) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
return __async(this, null, function* () {
|
|
75
|
+
if (io._registrationMode !== "detached") return;
|
|
76
|
+
const handler2 = this._room.onClose(ws);
|
|
77
|
+
yield handler2({ code, reason });
|
|
78
|
+
});
|
|
77
79
|
}
|
|
78
80
|
webSocketError(ws, error) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
return __async(this, null, function* () {
|
|
82
|
+
if (io._registrationMode !== "detached") return;
|
|
83
|
+
const handler2 = this._room.onError(ws);
|
|
84
|
+
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
85
|
+
yield handler2({ error: eventError, message: eventError.message });
|
|
86
|
+
});
|
|
83
87
|
}
|
|
84
88
|
webSocketMessage(ws, message) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
return __async(this, null, function* () {
|
|
90
|
+
if (io._registrationMode !== "detached") return;
|
|
91
|
+
const handler2 = this._room.onMessage(ws);
|
|
92
|
+
yield handler2({ data: message });
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
fetch(request) {
|
|
90
96
|
return __async(this, null, function* () {
|
|
@@ -158,9 +164,11 @@ var createPluvHandler = (config) => {
|
|
|
158
164
|
return room.fetch(request);
|
|
159
165
|
});
|
|
160
166
|
const fetch = (request, env) => __async(void 0, null, function* () {
|
|
161
|
-
return [authHandler, roomHandler].reduce((promise, current) => {
|
|
162
|
-
return promise.then((value) =>
|
|
163
|
-
|
|
167
|
+
return [authHandler, roomHandler].reduce((promise, current) => __async(void 0, null, function* () {
|
|
168
|
+
return yield promise.then((value) => __async(void 0, null, function* () {
|
|
169
|
+
return value != null ? value : yield current(request, env);
|
|
170
|
+
}));
|
|
171
|
+
}), Promise.resolve(null));
|
|
164
172
|
});
|
|
165
173
|
const handler = {
|
|
166
174
|
fetch: (request, env) => __async(void 0, null, function* () {
|
|
@@ -203,7 +211,7 @@ var CloudflareWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
203
211
|
get state() {
|
|
204
212
|
var _a;
|
|
205
213
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
206
|
-
const state = (_a = deserialized.state) != null ? _a : null;
|
|
214
|
+
const state = (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
|
|
207
215
|
if (!state) throw new Error("Could not get websocket state");
|
|
208
216
|
return state;
|
|
209
217
|
}
|
|
@@ -381,9 +389,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io3.AbstractPl
|
|
|
381
389
|
var _a;
|
|
382
390
|
const deserialized = (_a = webSocket.deserializeAttachment()) != null ? _a : {};
|
|
383
391
|
const sessionId = deserialized.sessionId;
|
|
384
|
-
if (typeof sessionId !== "string")
|
|
385
|
-
throw new Error("This websocket was not registered");
|
|
386
|
-
}
|
|
392
|
+
if (typeof sessionId !== "string") return null;
|
|
387
393
|
return sessionId;
|
|
388
394
|
}
|
|
389
395
|
getWebSockets() {
|
package/dist/index.mjs
CHANGED
|
@@ -44,23 +44,29 @@ var createPluvHandler = (config) => {
|
|
|
44
44
|
const { authorize, binding, endpoint = "/api/pluv", modify, io } = config;
|
|
45
45
|
const DurableObject = class {
|
|
46
46
|
constructor(state, env) {
|
|
47
|
-
this._room = io.
|
|
47
|
+
this._room = io.createRoom(state.id.toString(), { env, state });
|
|
48
48
|
}
|
|
49
49
|
webSocketClose(ws, code, reason, wasClean) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
return __async(this, null, function* () {
|
|
51
|
+
if (io._registrationMode !== "detached") return;
|
|
52
|
+
const handler2 = this._room.onClose(ws);
|
|
53
|
+
yield handler2({ code, reason });
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
56
|
webSocketError(ws, error) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
return __async(this, null, function* () {
|
|
58
|
+
if (io._registrationMode !== "detached") return;
|
|
59
|
+
const handler2 = this._room.onError(ws);
|
|
60
|
+
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
61
|
+
yield handler2({ error: eventError, message: eventError.message });
|
|
62
|
+
});
|
|
59
63
|
}
|
|
60
64
|
webSocketMessage(ws, message) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
return __async(this, null, function* () {
|
|
66
|
+
if (io._registrationMode !== "detached") return;
|
|
67
|
+
const handler2 = this._room.onMessage(ws);
|
|
68
|
+
yield handler2({ data: message });
|
|
69
|
+
});
|
|
64
70
|
}
|
|
65
71
|
fetch(request) {
|
|
66
72
|
return __async(this, null, function* () {
|
|
@@ -134,9 +140,11 @@ var createPluvHandler = (config) => {
|
|
|
134
140
|
return room.fetch(request);
|
|
135
141
|
});
|
|
136
142
|
const fetch = (request, env) => __async(void 0, null, function* () {
|
|
137
|
-
return [authHandler, roomHandler].reduce((promise, current) => {
|
|
138
|
-
return promise.then((value) =>
|
|
139
|
-
|
|
143
|
+
return [authHandler, roomHandler].reduce((promise, current) => __async(void 0, null, function* () {
|
|
144
|
+
return yield promise.then((value) => __async(void 0, null, function* () {
|
|
145
|
+
return value != null ? value : yield current(request, env);
|
|
146
|
+
}));
|
|
147
|
+
}), Promise.resolve(null));
|
|
140
148
|
});
|
|
141
149
|
const handler = {
|
|
142
150
|
fetch: (request, env) => __async(void 0, null, function* () {
|
|
@@ -179,7 +187,7 @@ var CloudflareWebSocket = class extends AbstractWebSocket {
|
|
|
179
187
|
get state() {
|
|
180
188
|
var _a;
|
|
181
189
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
182
|
-
const state = (_a = deserialized.state) != null ? _a : null;
|
|
190
|
+
const state = (_a = deserialized == null ? void 0 : deserialized.state) != null ? _a : null;
|
|
183
191
|
if (!state) throw new Error("Could not get websocket state");
|
|
184
192
|
return state;
|
|
185
193
|
}
|
|
@@ -357,9 +365,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
|
357
365
|
var _a;
|
|
358
366
|
const deserialized = (_a = webSocket.deserializeAttachment()) != null ? _a : {};
|
|
359
367
|
const sessionId = deserialized.sessionId;
|
|
360
|
-
if (typeof sessionId !== "string")
|
|
361
|
-
throw new Error("This websocket was not registered");
|
|
362
|
-
}
|
|
368
|
+
if (typeof sessionId !== "string") return null;
|
|
363
369
|
return sessionId;
|
|
364
370
|
}
|
|
365
371
|
getWebSockets() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/io": "^0.24.0",
|
|
22
|
+
"@pluv/types": "^0.24.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@cloudflare/workers-types": "^4.20240815.0",
|
|
26
26
|
"eslint": "^8.57.0",
|
|
27
27
|
"tsup": "^8.2.4",
|
|
28
28
|
"typescript": "^5.5.4",
|
|
29
|
-
"@pluv/tsconfig": "^0.
|
|
30
|
-
"eslint-config-pluv": "^0.
|
|
29
|
+
"@pluv/tsconfig": "^0.24.0",
|
|
30
|
+
"eslint-config-pluv": "^0.24.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -78,9 +78,7 @@ export class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends A
|
|
|
78
78
|
const deserialized = webSocket.deserializeAttachment() ?? {};
|
|
79
79
|
const sessionId = deserialized.sessionId;
|
|
80
80
|
|
|
81
|
-
if (typeof sessionId !== "string")
|
|
82
|
-
throw new Error("This websocket was not registered");
|
|
83
|
-
}
|
|
81
|
+
if (typeof sessionId !== "string") return null;
|
|
84
82
|
|
|
85
83
|
return sessionId;
|
|
86
84
|
}
|
|
@@ -39,7 +39,7 @@ export class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
|
39
39
|
|
|
40
40
|
public get state(): WebSocketSerializedState {
|
|
41
41
|
const deserialized = this.webSocket.deserializeAttachment();
|
|
42
|
-
const state = deserialized
|
|
42
|
+
const state = deserialized?.state ?? null;
|
|
43
43
|
|
|
44
44
|
if (!state) throw new Error("Could not get websocket state");
|
|
45
45
|
|
package/src/createPluvHandler.ts
CHANGED
|
@@ -55,32 +55,32 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
55
55
|
private _room: IORoom<CloudflarePlatform>;
|
|
56
56
|
|
|
57
57
|
constructor(state: DurableObjectState, env: Id<InferCloudflarePluvHandlerEnv<TPluvServer>>) {
|
|
58
|
-
this._room = io.
|
|
58
|
+
this._room = io.createRoom(state.id.toString(), { env, state });
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
public webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean):
|
|
61
|
+
public async webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void> {
|
|
62
62
|
if (io._registrationMode !== "detached") return;
|
|
63
63
|
|
|
64
64
|
const handler = this._room.onClose(ws);
|
|
65
65
|
|
|
66
|
-
handler({ code, reason });
|
|
66
|
+
await handler({ code, reason });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
public webSocketError(ws: WebSocket, error: unknown):
|
|
69
|
+
public async webSocketError(ws: WebSocket, error: unknown): Promise<void> {
|
|
70
70
|
if (io._registrationMode !== "detached") return;
|
|
71
71
|
|
|
72
72
|
const handler = this._room.onError(ws);
|
|
73
73
|
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
74
74
|
|
|
75
|
-
handler({ error: eventError, message: eventError.message });
|
|
75
|
+
await handler({ error: eventError, message: eventError.message });
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
public webSocketMessage(ws: WebSocket, message: string | ArrayBuffer):
|
|
78
|
+
public async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void> {
|
|
79
79
|
if (io._registrationMode !== "detached") return;
|
|
80
80
|
|
|
81
81
|
const handler = this._room.onMessage(ws);
|
|
82
82
|
|
|
83
|
-
handler({ data: message });
|
|
83
|
+
await handler({ data: message });
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
async fetch(request: Request<any, CfProperties<any>>): Promise<Response> {
|
|
@@ -177,8 +177,8 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
const fetch: PluvHandlerFetch<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>> = async (request, env) => {
|
|
180
|
-
return [authHandler, roomHandler].reduce((promise, current) => {
|
|
181
|
-
return promise.then((value) => value ?? current(request, env));
|
|
180
|
+
return [authHandler, roomHandler].reduce(async (promise, current) => {
|
|
181
|
+
return await promise.then(async (value) => value ?? (await current(request, env)));
|
|
182
182
|
}, Promise.resolve<Response | null>(null));
|
|
183
183
|
};
|
|
184
184
|
|