@pluv/platform-cloudflare 0.35.3 → 0.35.4
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 +5 -5
- package/CHANGELOG.md +10 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -12
- package/dist/index.mjs +10 -12
- package/package.json +7 -7
- package/src/createPluvHandler.ts +10 -12
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.35.
|
|
2
|
+
> @pluv/platform-cloudflare@0.35.4 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
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.12 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 71ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m13.22 KB[39m
|
|
12
14
|
[32mCJS[39m ⚡️ Build success in 72ms
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m12.07 KB[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in 74ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 1125ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m5.33 KB[39m
|
|
18
18
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.33 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @pluv/platform-cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.35.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5d3a56f: Fix error emitted about `platformCloudflare` not supporting `fetch` when deployed to Cloudflare Workers.
|
|
8
|
+
- Updated dependencies [5d3a56f]
|
|
9
|
+
- @pluv/io@0.35.4
|
|
10
|
+
- @pluv/persistence-cloudflare-transactional-storage@0.35.4
|
|
11
|
+
- @pluv/types@0.35.4
|
|
12
|
+
|
|
3
13
|
## 0.35.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener,
|
|
2
|
-
import { JsonObject, Json, MaybePromise,
|
|
1
|
+
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
2
|
+
import { JsonObject, Json, MaybePromise, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, Maybe, Id } from '@pluv/types';
|
|
3
3
|
|
|
4
4
|
type CloudflareWebSocketConfig = AbstractWebSocketConfig;
|
|
5
5
|
declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener,
|
|
2
|
-
import { JsonObject, Json, MaybePromise,
|
|
1
|
+
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
2
|
+
import { JsonObject, Json, MaybePromise, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, Maybe, Id } from '@pluv/types';
|
|
3
3
|
|
|
4
4
|
type CloudflareWebSocketConfig = AbstractWebSocketConfig;
|
|
5
5
|
declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
package/dist/index.js
CHANGED
|
@@ -74,31 +74,29 @@ var createPluvHandler = (config) => {
|
|
|
74
74
|
webSocketClose(ws, code, reason, wasClean) {
|
|
75
75
|
return __async(this, null, function* () {
|
|
76
76
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
77
|
-
const
|
|
78
|
-
yield
|
|
77
|
+
const onCloseHandler = this._room.onClose(ws);
|
|
78
|
+
yield onCloseHandler({ code, reason });
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
webSocketError(ws, error) {
|
|
82
82
|
return __async(this, null, function* () {
|
|
83
83
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
84
|
-
const
|
|
84
|
+
const onErrorHandler = this._room.onError(ws);
|
|
85
85
|
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
86
|
-
yield
|
|
86
|
+
yield onErrorHandler({ error: eventError, message: eventError.message });
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
webSocketMessage(ws, message) {
|
|
90
90
|
return __async(this, null, function* () {
|
|
91
91
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
92
|
-
const
|
|
93
|
-
yield
|
|
92
|
+
const onMessageHandler = this._room.onMessage(ws);
|
|
93
|
+
yield onMessageHandler({ data: message });
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
fetch(request) {
|
|
97
97
|
return __async(this, null, function* () {
|
|
98
98
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
|
99
|
-
if (!isWSRequest) {
|
|
100
|
-
return new Response("Expected websocket", { status: 400 });
|
|
101
|
-
}
|
|
99
|
+
if (!isWSRequest) return new Response("Expected websocket", { status: 400 });
|
|
102
100
|
const { 0: client, 1: server } = new WebSocketPair();
|
|
103
101
|
const token = new URL(request.url).searchParams.get("token");
|
|
104
102
|
yield this._room.register(server, { env: this._env, request, token });
|
|
@@ -165,7 +163,7 @@ var createPluvHandler = (config) => {
|
|
|
165
163
|
const room = namespace.get(durableObjectId);
|
|
166
164
|
return room.fetch(request);
|
|
167
165
|
});
|
|
168
|
-
const
|
|
166
|
+
const handlerFetch = (request, env) => __async(void 0, null, function* () {
|
|
169
167
|
return [authHandler, roomHandler].reduce((promise, current) => __async(void 0, null, function* () {
|
|
170
168
|
return yield promise.then((value) => __async(void 0, null, function* () {
|
|
171
169
|
return value != null ? value : yield current(request, env);
|
|
@@ -175,14 +173,14 @@ var createPluvHandler = (config) => {
|
|
|
175
173
|
const handler = {
|
|
176
174
|
fetch: (request, env) => __async(void 0, null, function* () {
|
|
177
175
|
var _a, _b;
|
|
178
|
-
const response = (_a = yield
|
|
176
|
+
const response = (_a = yield handlerFetch(request, env)) != null ? _a : new Response("Not Found", {
|
|
179
177
|
headers: { "Content-Type": "text/plain" },
|
|
180
178
|
status: 404
|
|
181
179
|
});
|
|
182
180
|
return (_b = modify == null ? void 0 : modify(request, response, env)) != null ? _b : response;
|
|
183
181
|
})
|
|
184
182
|
};
|
|
185
|
-
return { fetch, DurableObject, handler };
|
|
183
|
+
return { fetch: handlerFetch, DurableObject, handler };
|
|
186
184
|
};
|
|
187
185
|
|
|
188
186
|
// src/CloudflarePlatform.ts
|
package/dist/index.mjs
CHANGED
|
@@ -50,31 +50,29 @@ var createPluvHandler = (config) => {
|
|
|
50
50
|
webSocketClose(ws, code, reason, wasClean) {
|
|
51
51
|
return __async(this, null, function* () {
|
|
52
52
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
53
|
-
const
|
|
54
|
-
yield
|
|
53
|
+
const onCloseHandler = this._room.onClose(ws);
|
|
54
|
+
yield onCloseHandler({ code, reason });
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
webSocketError(ws, error) {
|
|
58
58
|
return __async(this, null, function* () {
|
|
59
59
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
60
|
-
const
|
|
60
|
+
const onErrorHandler = this._room.onError(ws);
|
|
61
61
|
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
62
|
-
yield
|
|
62
|
+
yield onErrorHandler({ error: eventError, message: eventError.message });
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
webSocketMessage(ws, message) {
|
|
66
66
|
return __async(this, null, function* () {
|
|
67
67
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
68
|
-
const
|
|
69
|
-
yield
|
|
68
|
+
const onMessageHandler = this._room.onMessage(ws);
|
|
69
|
+
yield onMessageHandler({ data: message });
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
fetch(request) {
|
|
73
73
|
return __async(this, null, function* () {
|
|
74
74
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
|
75
|
-
if (!isWSRequest) {
|
|
76
|
-
return new Response("Expected websocket", { status: 400 });
|
|
77
|
-
}
|
|
75
|
+
if (!isWSRequest) return new Response("Expected websocket", { status: 400 });
|
|
78
76
|
const { 0: client, 1: server } = new WebSocketPair();
|
|
79
77
|
const token = new URL(request.url).searchParams.get("token");
|
|
80
78
|
yield this._room.register(server, { env: this._env, request, token });
|
|
@@ -141,7 +139,7 @@ var createPluvHandler = (config) => {
|
|
|
141
139
|
const room = namespace.get(durableObjectId);
|
|
142
140
|
return room.fetch(request);
|
|
143
141
|
});
|
|
144
|
-
const
|
|
142
|
+
const handlerFetch = (request, env) => __async(void 0, null, function* () {
|
|
145
143
|
return [authHandler, roomHandler].reduce((promise, current) => __async(void 0, null, function* () {
|
|
146
144
|
return yield promise.then((value) => __async(void 0, null, function* () {
|
|
147
145
|
return value != null ? value : yield current(request, env);
|
|
@@ -151,14 +149,14 @@ var createPluvHandler = (config) => {
|
|
|
151
149
|
const handler = {
|
|
152
150
|
fetch: (request, env) => __async(void 0, null, function* () {
|
|
153
151
|
var _a, _b;
|
|
154
|
-
const response = (_a = yield
|
|
152
|
+
const response = (_a = yield handlerFetch(request, env)) != null ? _a : new Response("Not Found", {
|
|
155
153
|
headers: { "Content-Type": "text/plain" },
|
|
156
154
|
status: 404
|
|
157
155
|
});
|
|
158
156
|
return (_b = modify == null ? void 0 : modify(request, response, env)) != null ? _b : response;
|
|
159
157
|
})
|
|
160
158
|
};
|
|
161
|
-
return { fetch, DurableObject, handler };
|
|
159
|
+
return { fetch: handlerFetch, DurableObject, handler };
|
|
162
160
|
};
|
|
163
161
|
|
|
164
162
|
// src/CloudflarePlatform.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.4",
|
|
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.35.
|
|
22
|
-
"@pluv/persistence-cloudflare-transactional-storage": "^0.35.
|
|
23
|
-
"@pluv/types": "^0.35.
|
|
21
|
+
"@pluv/io": "^0.35.4",
|
|
22
|
+
"@pluv/persistence-cloudflare-transactional-storage": "^0.35.4",
|
|
23
|
+
"@pluv/types": "^0.35.4"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@cloudflare/workers-types": "^4.
|
|
26
|
+
"@cloudflare/workers-types": "^4.20250204.0",
|
|
27
27
|
"eslint": "^8.57.1",
|
|
28
28
|
"tsup": "^8.3.6",
|
|
29
29
|
"typescript": "^5.7.3",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"@pluv/tsconfig": "^0.35.4",
|
|
31
|
+
"eslint-config-pluv": "^0.35.4"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/createPluvHandler.ts
CHANGED
|
@@ -55,34 +55,32 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
55
55
|
public async webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void> {
|
|
56
56
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const onCloseHandler = this._room.onClose(ws);
|
|
59
59
|
|
|
60
|
-
await
|
|
60
|
+
await onCloseHandler({ code, reason });
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
public async webSocketError(ws: WebSocket, error: unknown): Promise<void> {
|
|
64
64
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
65
65
|
|
|
66
|
-
const
|
|
66
|
+
const onErrorHandler = this._room.onError(ws);
|
|
67
67
|
const eventError = error instanceof Error ? error : new Error("Internal Error");
|
|
68
68
|
|
|
69
|
-
await
|
|
69
|
+
await onErrorHandler({ error: eventError, message: eventError.message });
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
public async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void> {
|
|
73
73
|
if (io._defs.platform._config.registrationMode !== "detached") return;
|
|
74
74
|
|
|
75
|
-
const
|
|
75
|
+
const onMessageHandler = this._room.onMessage(ws);
|
|
76
76
|
|
|
77
|
-
await
|
|
77
|
+
await onMessageHandler({ data: message });
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async fetch(request: Request<any, CfProperties<any>>): Promise<Response> {
|
|
81
81
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
|
82
82
|
|
|
83
|
-
if (!isWSRequest) {
|
|
84
|
-
return new Response("Expected websocket", { status: 400 });
|
|
85
|
-
}
|
|
83
|
+
if (!isWSRequest) return new Response("Expected websocket", { status: 400 });
|
|
86
84
|
|
|
87
85
|
const { 0: client, 1: server } = new WebSocketPair();
|
|
88
86
|
const token = new URL(request.url).searchParams.get("token");
|
|
@@ -171,7 +169,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
171
169
|
return room.fetch(request);
|
|
172
170
|
};
|
|
173
171
|
|
|
174
|
-
const
|
|
172
|
+
const handlerFetch: PluvHandlerFetch<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>> = async (request, env) => {
|
|
175
173
|
return [authHandler, roomHandler].reduce(async (promise, current) => {
|
|
176
174
|
return await promise.then(async (value) => value ?? (await current(request, env)));
|
|
177
175
|
}, Promise.resolve<Response | null>(null));
|
|
@@ -180,7 +178,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
180
178
|
const handler: ExportedHandler<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>> = {
|
|
181
179
|
fetch: async (request, env) => {
|
|
182
180
|
const response =
|
|
183
|
-
(await
|
|
181
|
+
(await handlerFetch(request, env)) ??
|
|
184
182
|
new Response("Not Found", {
|
|
185
183
|
headers: { "Content-Type": "text/plain" },
|
|
186
184
|
status: 404,
|
|
@@ -190,5 +188,5 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
|
|
|
190
188
|
},
|
|
191
189
|
};
|
|
192
190
|
|
|
193
|
-
return { fetch, DurableObject, handler };
|
|
191
|
+
return { fetch: handlerFetch, DurableObject, handler };
|
|
194
192
|
};
|