@pluv/platform-cloudflare 0.18.0 → 0.20.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 +15 -15
- package/CHANGELOG.md +14 -0
- package/README.md +0 -50
- package/dist/index.js +7 -14
- package/dist/index.mjs +7 -14
- package/package.json +8 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.
|
|
2
|
+
> @pluv/platform-cloudflare@0.20.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
CLI Building entry: src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v8.1.0
|
|
8
|
+
CLI Target: es6
|
|
9
|
+
ESM Build start
|
|
10
|
+
CJS Build start
|
|
11
|
+
ESM dist/index.mjs 5.73 KB
|
|
12
|
+
ESM ⚡️ Build success in 78ms
|
|
13
|
+
CJS dist/index.js 6.86 KB
|
|
14
|
+
CJS ⚡️ Build success in 79ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 2841ms
|
|
17
|
+
DTS dist/index.d.mts 3.02 KB
|
|
18
|
+
DTS dist/index.d.ts 3.02 KB
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
> **Disclaimer:**
|
|
2
|
-
> This package is currently in preview and may have breaking changes between versions. Please wait for a `v1.0.0` stable release before using this in production.
|
|
3
|
-
|
|
4
|
-
<h1 align="center">
|
|
5
|
-
<br />
|
|
6
|
-
<img src="https://github.com/pluv-io/pluv/blob/master/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="180" style="border-radius:16px" />
|
|
7
|
-
<br />
|
|
8
|
-
<a href="https://pluv.io/docs/introduction">Pluv.IO (preview)</a>
|
|
9
|
-
<br />
|
|
10
|
-
</h1>
|
|
11
|
-
|
|
12
|
-
<h3 align="center">Multi-platform, E2E type-safe realtime packages</h3>
|
|
13
|
-
<h4 align="center">💕 Inspired by <a href="https://trpc.io">trpc</a> 💕 <a href="https://docs.yjs.dev/">yjs</a> 💕 and <a href="https://developers.cloudflare.com/">Cloudflare</a> 💕 </h4>
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a href="https://www.npmjs.com/package/@pluv/platform-cloudflare">
|
|
17
|
-
<img src="https://img.shields.io/npm/v/@pluv/platform-cloudflare" alt="npm @pluv/platform-cloudflare" />
|
|
18
|
-
</a>
|
|
19
|
-
<a href="https://github.com/pluv-io/pluv/blob/master/LICENSE">
|
|
20
|
-
<img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
|
|
21
|
-
</a>
|
|
22
|
-
<a href="https://commitizen.github.io/cz-cli/">
|
|
23
|
-
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" />
|
|
24
|
-
</a>
|
|
25
|
-
<img src="https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555" alt="TypeScript" />
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
1
|
## `@pluv/platform-cloudflare`
|
|
29
2
|
|
|
30
3
|
> Enables [@pluv/io](https://www.npmjs.com/package/@pluv/io) to run on [Cloudflare Workers](https://workers.cloudflare.com/).
|
|
@@ -43,26 +16,3 @@ yarn add @pluv/platform-cloudflare
|
|
|
43
16
|
# pnpm
|
|
44
17
|
pnpm add @pluv/platform-cloudflare
|
|
45
18
|
```
|
|
46
|
-
|
|
47
|
-
## Basic Example
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import { createIO } from "@pluv/io";
|
|
51
|
-
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
52
|
-
|
|
53
|
-
export const io = createIO({ platform: platformCloudflare() });
|
|
54
|
-
export const ioServer = io.server();
|
|
55
|
-
|
|
56
|
-
/* Somewhere in a Cloudflare worker durable object */
|
|
57
|
-
const { 0: client, 1: server } = new WebSocketPair();
|
|
58
|
-
|
|
59
|
-
const room = ioServer.getRoom(state.id.toString(), { env });
|
|
60
|
-
|
|
61
|
-
await room.register(server);
|
|
62
|
-
|
|
63
|
-
return new Response(null, { status: 101, webSocket: client });
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Reference
|
|
67
|
-
|
|
68
|
-
Check us out on [GitHub](https://github.com/pluv-io/pluv) for more information on how to use `@pluv/io`.
|
package/dist/index.js
CHANGED
|
@@ -85,13 +85,11 @@ var createPluvHandler = (config) => {
|
|
|
85
85
|
return namespace;
|
|
86
86
|
};
|
|
87
87
|
const authHandler = (request, env) => __async(void 0, null, function* () {
|
|
88
|
-
if (!authorize)
|
|
89
|
-
return null;
|
|
88
|
+
if (!authorize) return null;
|
|
90
89
|
const { pathname, searchParams } = new URL(request.url);
|
|
91
90
|
const matcher = (0, import_path_to_regexp.match)(`${endpoint}/authorize`);
|
|
92
91
|
const matched = matcher(pathname);
|
|
93
|
-
if (!matched)
|
|
94
|
-
return null;
|
|
92
|
+
if (!matched) return null;
|
|
95
93
|
const roomId = searchParams.get("room");
|
|
96
94
|
if (!roomId) {
|
|
97
95
|
return new Response("Not found", {
|
|
@@ -101,8 +99,7 @@ var createPluvHandler = (config) => {
|
|
|
101
99
|
}
|
|
102
100
|
try {
|
|
103
101
|
const user = yield authorize({ request, roomId });
|
|
104
|
-
if (!user)
|
|
105
|
-
throw new Error();
|
|
102
|
+
if (!user) throw new Error();
|
|
106
103
|
const namespace = getDurableObjectNamespace(env);
|
|
107
104
|
const durableObjectId = namespace.idFromName(roomId);
|
|
108
105
|
const token = yield io.createToken({
|
|
@@ -125,8 +122,7 @@ var createPluvHandler = (config) => {
|
|
|
125
122
|
const { pathname } = new URL(request.url);
|
|
126
123
|
const matcher = (0, import_path_to_regexp.match)(`${endpoint}/room/:roomId`);
|
|
127
124
|
const matched = matcher(pathname);
|
|
128
|
-
if (!matched)
|
|
129
|
-
return null;
|
|
125
|
+
if (!matched) return null;
|
|
130
126
|
const { roomId } = matched.params;
|
|
131
127
|
if (!roomId) {
|
|
132
128
|
return new Response("Not found", {
|
|
@@ -176,8 +172,7 @@ var CloudflareWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
176
172
|
}
|
|
177
173
|
close(code, reason) {
|
|
178
174
|
const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
|
|
179
|
-
if (!canClose)
|
|
180
|
-
return;
|
|
175
|
+
if (!canClose) return;
|
|
181
176
|
this.webSocket.close(code, reason);
|
|
182
177
|
}
|
|
183
178
|
initialize() {
|
|
@@ -185,8 +180,7 @@ var CloudflareWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
185
180
|
return Promise.resolve(() => void 0);
|
|
186
181
|
}
|
|
187
182
|
send(message) {
|
|
188
|
-
if (this.readyState !== this.OPEN)
|
|
189
|
-
return;
|
|
183
|
+
if (this.readyState !== this.OPEN) return;
|
|
190
184
|
this.webSocket.send(message);
|
|
191
185
|
}
|
|
192
186
|
terminate() {
|
|
@@ -200,8 +194,7 @@ var CloudflarePlatform = class extends import_io2.AbstractPlatform {
|
|
|
200
194
|
return new CloudflareWebSocket(webSocket, config);
|
|
201
195
|
}
|
|
202
196
|
parseData(data) {
|
|
203
|
-
if (typeof data === "string")
|
|
204
|
-
return JSON.parse(data);
|
|
197
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
205
198
|
const decoder = new TextDecoder("utf8");
|
|
206
199
|
return JSON.parse(decoder.decode(data));
|
|
207
200
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -59,13 +59,11 @@ var createPluvHandler = (config) => {
|
|
|
59
59
|
return namespace;
|
|
60
60
|
};
|
|
61
61
|
const authHandler = (request, env) => __async(void 0, null, function* () {
|
|
62
|
-
if (!authorize)
|
|
63
|
-
return null;
|
|
62
|
+
if (!authorize) return null;
|
|
64
63
|
const { pathname, searchParams } = new URL(request.url);
|
|
65
64
|
const matcher = match(`${endpoint}/authorize`);
|
|
66
65
|
const matched = matcher(pathname);
|
|
67
|
-
if (!matched)
|
|
68
|
-
return null;
|
|
66
|
+
if (!matched) return null;
|
|
69
67
|
const roomId = searchParams.get("room");
|
|
70
68
|
if (!roomId) {
|
|
71
69
|
return new Response("Not found", {
|
|
@@ -75,8 +73,7 @@ var createPluvHandler = (config) => {
|
|
|
75
73
|
}
|
|
76
74
|
try {
|
|
77
75
|
const user = yield authorize({ request, roomId });
|
|
78
|
-
if (!user)
|
|
79
|
-
throw new Error();
|
|
76
|
+
if (!user) throw new Error();
|
|
80
77
|
const namespace = getDurableObjectNamespace(env);
|
|
81
78
|
const durableObjectId = namespace.idFromName(roomId);
|
|
82
79
|
const token = yield io.createToken({
|
|
@@ -99,8 +96,7 @@ var createPluvHandler = (config) => {
|
|
|
99
96
|
const { pathname } = new URL(request.url);
|
|
100
97
|
const matcher = match(`${endpoint}/room/:roomId`);
|
|
101
98
|
const matched = matcher(pathname);
|
|
102
|
-
if (!matched)
|
|
103
|
-
return null;
|
|
99
|
+
if (!matched) return null;
|
|
104
100
|
const { roomId } = matched.params;
|
|
105
101
|
if (!roomId) {
|
|
106
102
|
return new Response("Not found", {
|
|
@@ -150,8 +146,7 @@ var CloudflareWebSocket = class extends AbstractWebSocket {
|
|
|
150
146
|
}
|
|
151
147
|
close(code, reason) {
|
|
152
148
|
const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
|
|
153
|
-
if (!canClose)
|
|
154
|
-
return;
|
|
149
|
+
if (!canClose) return;
|
|
155
150
|
this.webSocket.close(code, reason);
|
|
156
151
|
}
|
|
157
152
|
initialize() {
|
|
@@ -159,8 +154,7 @@ var CloudflareWebSocket = class extends AbstractWebSocket {
|
|
|
159
154
|
return Promise.resolve(() => void 0);
|
|
160
155
|
}
|
|
161
156
|
send(message) {
|
|
162
|
-
if (this.readyState !== this.OPEN)
|
|
163
|
-
return;
|
|
157
|
+
if (this.readyState !== this.OPEN) return;
|
|
164
158
|
this.webSocket.send(message);
|
|
165
159
|
}
|
|
166
160
|
terminate() {
|
|
@@ -174,8 +168,7 @@ var CloudflarePlatform = class extends AbstractPlatform {
|
|
|
174
168
|
return new CloudflareWebSocket(webSocket, config);
|
|
175
169
|
}
|
|
176
170
|
parseData(data) {
|
|
177
|
-
if (typeof data === "string")
|
|
178
|
-
return JSON.parse(data);
|
|
171
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
179
172
|
const decoder = new TextDecoder("utf8");
|
|
180
173
|
return JSON.parse(decoder.decode(data));
|
|
181
174
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "@pluv/io adapter for cloudflare workers",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"path-to-regexp": "^
|
|
21
|
-
"@pluv/io": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
20
|
+
"path-to-regexp": "^7.0.0",
|
|
21
|
+
"@pluv/io": "^0.20.0",
|
|
22
|
+
"@pluv/types": "^0.20.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@cloudflare/workers-types": "^4.
|
|
25
|
+
"@cloudflare/workers-types": "^4.20240620.0",
|
|
26
26
|
"eslint": "^8.57.0",
|
|
27
|
-
"tsup": "^8.0
|
|
27
|
+
"tsup": "^8.1.0",
|
|
28
28
|
"typescript": "^5.4.5",
|
|
29
|
-
"@pluv/tsconfig": "^0.
|
|
30
|
-
"eslint-config-pluv": "^0.
|
|
29
|
+
"@pluv/tsconfig": "^0.20.0",
|
|
30
|
+
"eslint-config-pluv": "^0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|