@pluv/platform-cloudflare 0.3.1 → 0.3.3
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 +9 -8
- package/CHANGELOG.md +21 -0
- package/dist/index.d.mts +54 -0
- package/dist/index.js +6 -0
- package/dist/index.mjs +6 -0
- package/package.json +9 -8
- package/src/CloudflarePlatform.ts +2 -2
- package/src/CloudflareWebSocket.ts +2 -2
- package/src/createPluvHandler.ts +26 -12
- package/src/platformCloudflare.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.3.
|
|
2
|
+
> @pluv/platform-cloudflare@0.3.3 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
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup
|
|
7
|
+
[34mCLI[39m tsup v7.1.0
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[32m6.
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m5.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m6.89 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 135ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m5.76 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 137ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 7862ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m2.90 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.90 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @pluv/platform-cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8fba48b: fix including incorrect dependency
|
|
8
|
+
- 8997c65: bumped dependencies
|
|
9
|
+
- Updated dependencies [8fba48b]
|
|
10
|
+
- Updated dependencies [8997c65]
|
|
11
|
+
- @pluv/types@0.2.2
|
|
12
|
+
- @pluv/io@0.7.1
|
|
13
|
+
|
|
14
|
+
## 0.3.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 8d11672: bumped dependencies to latest
|
|
19
|
+
- Updated dependencies [8d11672]
|
|
20
|
+
- Updated dependencies [829d31b]
|
|
21
|
+
- @pluv/types@0.2.1
|
|
22
|
+
- @pluv/io@0.7.0
|
|
23
|
+
|
|
3
24
|
## 0.3.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPlatform, PluvIO } from '@pluv/io';
|
|
2
|
+
import { MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
|
|
3
|
+
|
|
4
|
+
type CloudflareWebSocketConfig = AbstractWebSocketConfig;
|
|
5
|
+
declare class CloudflareWebSocket extends AbstractWebSocket {
|
|
6
|
+
webSocket: WebSocket;
|
|
7
|
+
get readyState(): 0 | 1 | 2 | 3;
|
|
8
|
+
constructor(webSocket: WebSocket, config: CloudflareWebSocketConfig);
|
|
9
|
+
addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
|
|
10
|
+
close(code?: number | undefined, reason?: string | undefined): void;
|
|
11
|
+
initialize(): Promise<() => undefined>;
|
|
12
|
+
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
13
|
+
terminate(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<WebSocket, {
|
|
17
|
+
env: TEnv;
|
|
18
|
+
}, {
|
|
19
|
+
request: Request;
|
|
20
|
+
}> {
|
|
21
|
+
convertWebSocket(webSocket: WebSocket, config: AbstractWebSocketConfig): CloudflareWebSocket;
|
|
22
|
+
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
23
|
+
randomUUID(): string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface AuthorizeFunctionContext {
|
|
27
|
+
request: Request<any, CfProperties<any>>;
|
|
28
|
+
roomId: string;
|
|
29
|
+
}
|
|
30
|
+
type AuthorizeFunction<TPluv extends PluvIO<CloudflarePlatform>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
|
|
31
|
+
type CreatePluvHandlerConfig<TPluv extends PluvIO<CloudflarePlatform>, TEnv extends Record<string, any>> = {
|
|
32
|
+
binding: string;
|
|
33
|
+
endpoint?: string;
|
|
34
|
+
modify?: (request: Request, response: Response, env: TEnv) => MaybePromise<Response>;
|
|
35
|
+
io: TPluv;
|
|
36
|
+
} & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true ? {
|
|
37
|
+
authorize: AuthorizeFunction<TPluv>;
|
|
38
|
+
} : {
|
|
39
|
+
authorize?: undefined;
|
|
40
|
+
});
|
|
41
|
+
type PluvHandlerFetch<TEnv extends Record<string, any> = {}> = (request: Request, env: TEnv) => Promise<Response | null>;
|
|
42
|
+
interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
|
|
43
|
+
DurableObject: {
|
|
44
|
+
new (state: DurableObjectState, env: TEnv): DurableObject;
|
|
45
|
+
};
|
|
46
|
+
fetch: PluvHandlerFetch<TEnv>;
|
|
47
|
+
handler: ExportedHandler<TEnv>;
|
|
48
|
+
}
|
|
49
|
+
type InferCloudflarePluvHandlerEnv<TPluv extends PluvIO<CloudflarePlatform, any, any, any, any, any, any>> = TPluv extends PluvIO<CloudflarePlatform<infer IEnv>, any, any, any, any, any, any> ? IEnv : {};
|
|
50
|
+
declare const createPluvHandler: <TPluv extends PluvIO<CloudflarePlatform<{}>, any, any, any, any, any, any>>(config: CreatePluvHandlerConfig<TPluv, Id<InferCloudflarePluvHandlerEnv<TPluv>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluv>>>;
|
|
51
|
+
|
|
52
|
+
declare const platformCloudflare: <TEnv extends Record<string, any> = {}>() => CloudflarePlatform<TEnv>;
|
|
53
|
+
|
|
54
|
+
export { AuthorizeFunction, AuthorizeFunctionContext, CreatePluvHandlerConfig, CreatePluvHandlerResult, PluvHandlerFetch, createPluvHandler, platformCloudflare };
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,12 @@ var createPluvHandler = (config) => {
|
|
|
54
54
|
this._env = env;
|
|
55
55
|
this._io = io.getRoom(state.id.toString(), { env });
|
|
56
56
|
}
|
|
57
|
+
webSocketClose(ws, code, reason, wasClean) {
|
|
58
|
+
}
|
|
59
|
+
webSocketError(ws, error) {
|
|
60
|
+
}
|
|
61
|
+
webSocketMessage(ws, message) {
|
|
62
|
+
}
|
|
57
63
|
fetch(request) {
|
|
58
64
|
return __async(this, null, function* () {
|
|
59
65
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,12 @@ var createPluvHandler = (config) => {
|
|
|
28
28
|
this._env = env;
|
|
29
29
|
this._io = io.getRoom(state.id.toString(), { env });
|
|
30
30
|
}
|
|
31
|
+
webSocketClose(ws, code, reason, wasClean) {
|
|
32
|
+
}
|
|
33
|
+
webSocketError(ws, error) {
|
|
34
|
+
}
|
|
35
|
+
webSocketMessage(ws, message) {
|
|
36
|
+
}
|
|
31
37
|
fetch(request) {
|
|
32
38
|
return __async(this, null, function* () {
|
|
33
39
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "@pluv/io adapter for cloudflare workers",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,16 +17,17 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@types/react": "^18.2.15",
|
|
20
21
|
"path-to-regexp": "^6.2.1",
|
|
21
|
-
"@pluv/io": "^0.
|
|
22
|
-
"@pluv/types": "^0.2.
|
|
22
|
+
"@pluv/io": "^0.7.1",
|
|
23
|
+
"@pluv/types": "^0.2.2"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@cloudflare/workers-types": "^4.
|
|
26
|
-
"tsup": "^
|
|
27
|
-
"typescript": "^5.
|
|
28
|
-
"@pluv/tsconfig": "^0.1.
|
|
29
|
-
"eslint-config-pluv": "^0.1.
|
|
26
|
+
"@cloudflare/workers-types": "^4.20230710.1",
|
|
27
|
+
"tsup": "^7.1.0",
|
|
28
|
+
"typescript": "^5.1.6",
|
|
29
|
+
"@pluv/tsconfig": "^0.1.8",
|
|
30
|
+
"eslint-config-pluv": "^0.1.14"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -3,11 +3,11 @@ import { AbstractPlatform } from "@pluv/io";
|
|
|
3
3
|
import { CloudflareWebSocket } from "./CloudflareWebSocket";
|
|
4
4
|
|
|
5
5
|
export class CloudflarePlatform<
|
|
6
|
-
TEnv extends Record<string, any> = {}
|
|
6
|
+
TEnv extends Record<string, any> = {},
|
|
7
7
|
> extends AbstractPlatform<WebSocket, { env: TEnv }, { request: Request }> {
|
|
8
8
|
public convertWebSocket(
|
|
9
9
|
webSocket: WebSocket,
|
|
10
|
-
config: AbstractWebSocketConfig
|
|
10
|
+
config: AbstractWebSocketConfig,
|
|
11
11
|
): CloudflareWebSocket {
|
|
12
12
|
return new CloudflareWebSocket(webSocket, config);
|
|
13
13
|
}
|
|
@@ -31,14 +31,14 @@ export class CloudflareWebSocket extends AbstractWebSocket {
|
|
|
31
31
|
|
|
32
32
|
public addEventListener<TType extends keyof AbstractEventMap>(
|
|
33
33
|
type: TType,
|
|
34
|
-
handler: AbstractListener<TType
|
|
34
|
+
handler: AbstractListener<TType>,
|
|
35
35
|
) {
|
|
36
36
|
this.webSocket.addEventListener(type, handler as any);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
public close(code?: number | undefined, reason?: string | undefined): void {
|
|
40
40
|
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
41
|
-
(readyState) => readyState === this.readyState
|
|
41
|
+
(readyState) => readyState === this.readyState,
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
if (!canClose) return;
|
package/src/createPluvHandler.ts
CHANGED
|
@@ -15,19 +15,19 @@ export interface AuthorizeFunctionContext {
|
|
|
15
15
|
roomId: string;
|
|
16
16
|
}
|
|
17
17
|
export type AuthorizeFunction<TPluv extends PluvIO<CloudflarePlatform>> = (
|
|
18
|
-
ctx: AuthorizeFunctionContext
|
|
18
|
+
ctx: AuthorizeFunctionContext,
|
|
19
19
|
) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
|
|
20
20
|
|
|
21
21
|
export type CreatePluvHandlerConfig<
|
|
22
22
|
TPluv extends PluvIO<CloudflarePlatform>,
|
|
23
|
-
TEnv extends Record<string, any
|
|
23
|
+
TEnv extends Record<string, any>,
|
|
24
24
|
> = {
|
|
25
25
|
binding: string;
|
|
26
26
|
endpoint?: string;
|
|
27
27
|
modify?: (
|
|
28
28
|
request: Request,
|
|
29
29
|
response: Response,
|
|
30
|
-
env: TEnv
|
|
30
|
+
env: TEnv,
|
|
31
31
|
) => MaybePromise<Response>;
|
|
32
32
|
io: TPluv;
|
|
33
33
|
} & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true
|
|
@@ -36,11 +36,11 @@ export type CreatePluvHandlerConfig<
|
|
|
36
36
|
|
|
37
37
|
export type PluvHandlerFetch<TEnv extends Record<string, any> = {}> = (
|
|
38
38
|
request: Request,
|
|
39
|
-
env: TEnv
|
|
39
|
+
env: TEnv,
|
|
40
40
|
) => Promise<Response | null>;
|
|
41
41
|
|
|
42
42
|
export interface CreatePluvHandlerResult<
|
|
43
|
-
TEnv extends Record<string, any> = {}
|
|
43
|
+
TEnv extends Record<string, any> = {},
|
|
44
44
|
> {
|
|
45
45
|
DurableObject: {
|
|
46
46
|
new (state: DurableObjectState, env: TEnv): DurableObject;
|
|
@@ -50,7 +50,7 @@ export interface CreatePluvHandlerResult<
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
type InferCloudflarePluvHandlerEnv<
|
|
53
|
-
TPluv extends PluvIO<CloudflarePlatform, any, any, any, any, any, any
|
|
53
|
+
TPluv extends PluvIO<CloudflarePlatform, any, any, any, any, any, any>,
|
|
54
54
|
> = TPluv extends PluvIO<
|
|
55
55
|
CloudflarePlatform<infer IEnv>,
|
|
56
56
|
any,
|
|
@@ -64,12 +64,12 @@ type InferCloudflarePluvHandlerEnv<
|
|
|
64
64
|
: {};
|
|
65
65
|
|
|
66
66
|
export const createPluvHandler = <
|
|
67
|
-
TPluv extends PluvIO<CloudflarePlatform, any, any, any, any, any, any
|
|
67
|
+
TPluv extends PluvIO<CloudflarePlatform, any, any, any, any, any, any>,
|
|
68
68
|
>(
|
|
69
69
|
config: CreatePluvHandlerConfig<
|
|
70
70
|
TPluv,
|
|
71
71
|
Id<InferCloudflarePluvHandlerEnv<TPluv>>
|
|
72
|
-
|
|
72
|
+
>,
|
|
73
73
|
): CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluv>>> => {
|
|
74
74
|
const { authorize, binding, endpoint = "/api/pluv", modify, io } = config;
|
|
75
75
|
|
|
@@ -79,14 +79,28 @@ export const createPluvHandler = <
|
|
|
79
79
|
|
|
80
80
|
constructor(
|
|
81
81
|
state: DurableObjectState,
|
|
82
|
-
env: Id<InferCloudflarePluvHandlerEnv<TPluv
|
|
82
|
+
env: Id<InferCloudflarePluvHandlerEnv<TPluv>>,
|
|
83
83
|
) {
|
|
84
84
|
this._env = env;
|
|
85
85
|
this._io = io.getRoom(state.id.toString(), { env });
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
webSocketClose(
|
|
89
|
+
ws: WebSocket,
|
|
90
|
+
code: number,
|
|
91
|
+
reason: string,
|
|
92
|
+
wasClean: boolean,
|
|
93
|
+
): void | Promise<void> {}
|
|
94
|
+
|
|
95
|
+
webSocketError(ws: WebSocket, error: unknown): void | Promise<void> {}
|
|
96
|
+
|
|
97
|
+
webSocketMessage(
|
|
98
|
+
ws: WebSocket,
|
|
99
|
+
message: string | ArrayBuffer,
|
|
100
|
+
): void | Promise<void> {}
|
|
101
|
+
|
|
88
102
|
async fetch(
|
|
89
|
-
request: Request<any, CfProperties<any
|
|
103
|
+
request: Request<any, CfProperties<any>>,
|
|
90
104
|
): Promise<Response> {
|
|
91
105
|
const isWSRequest = request.headers.get("Upgrade") === "websocket";
|
|
92
106
|
|
|
@@ -109,7 +123,7 @@ export const createPluvHandler = <
|
|
|
109
123
|
};
|
|
110
124
|
|
|
111
125
|
const getDurableObjectNamespace = (
|
|
112
|
-
env: Id<InferCloudflarePluvHandlerEnv<TPluv
|
|
126
|
+
env: Id<InferCloudflarePluvHandlerEnv<TPluv>>,
|
|
113
127
|
): DurableObjectNamespace => {
|
|
114
128
|
const namespace = env[
|
|
115
129
|
binding as keyof typeof env
|
|
@@ -165,7 +179,7 @@ export const createPluvHandler = <
|
|
|
165
179
|
{
|
|
166
180
|
headers: { "Content-Type": "text/plain" },
|
|
167
181
|
status: 403,
|
|
168
|
-
}
|
|
182
|
+
},
|
|
169
183
|
);
|
|
170
184
|
}
|
|
171
185
|
};
|