@pluv/platform-cloudflare 0.3.2 → 0.3.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.
@@ -1,17 +1,18 @@
1
1
 
2
- > @pluv/platform-cloudflare@0.3.2 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.3.4 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v7.0.0
7
+ CLI tsup v7.1.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 5.63 KB
12
- ESM ⚡️ Build success in 141ms
13
- CJS dist/index.js 6.76 KB
14
- CJS ⚡️ Build success in 117ms
11
+ ESM dist/index.mjs 5.76 KB
12
+ ESM ⚡️ Build success in 120ms
13
+ CJS dist/index.js 6.89 KB
14
+ CJS ⚡️ Build success in 121ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 7749ms
17
- DTS dist/index.d.ts 2.90 KB
16
+ DTS ⚡️ Build success in 7077ms
17
+ DTS dist/index.d.mts 2.90 KB
18
+ DTS dist/index.d.ts 2.90 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/io@0.7.2
8
+
9
+ ## 0.3.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 8fba48b: fix including incorrect dependency
14
+ - 8997c65: bumped dependencies
15
+ - Updated dependencies [8fba48b]
16
+ - Updated dependencies [8997c65]
17
+ - @pluv/types@0.2.2
18
+ - @pluv/io@0.7.1
19
+
3
20
  ## 0.3.2
4
21
 
5
22
  ### Patch Changes
@@ -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.2",
3
+ "version": "0.3.4",
4
4
  "description": "@pluv/io adapter for cloudflare workers",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,18 +17,17 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@playwright/test": "^1.35.1",
21
- "@types/react": "^18.2.13",
20
+ "@types/react": "^18.2.15",
22
21
  "path-to-regexp": "^6.2.1",
23
- "@pluv/io": "^0.7.0",
24
- "@pluv/types": "^0.2.1"
22
+ "@pluv/io": "^0.7.2",
23
+ "@pluv/types": "^0.2.2"
25
24
  },
26
25
  "devDependencies": {
27
- "@cloudflare/workers-types": "^4.20230518.0",
28
- "tsup": "^7.0.0",
29
- "typescript": "^5.1.3",
30
- "@pluv/tsconfig": "^0.1.7",
31
- "eslint-config-pluv": "^0.1.13"
26
+ "@cloudflare/workers-types": "^4.20230717.1",
27
+ "tsup": "^7.1.0",
28
+ "typescript": "^5.1.6",
29
+ "@pluv/tsconfig": "^0.2.0",
30
+ "eslint-config-pluv": "^0.1.14"
32
31
  },
33
32
  "scripts": {
34
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;
@@ -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
  };
@@ -1,7 +1,7 @@
1
1
  import { CloudflarePlatform } from "./CloudflarePlatform";
2
2
 
3
3
  export const platformCloudflare = <
4
- TEnv extends Record<string, any> = {}
4
+ TEnv extends Record<string, any> = {},
5
5
  >(): CloudflarePlatform<TEnv> => {
6
6
  return new CloudflarePlatform<TEnv>();
7
7
  };