@pluv/platform-cloudflare 0.23.0 → 0.24.1

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,5 +1,5 @@
1
1
 
2
- > @pluv/platform-cloudflare@0.23.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.24.1 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
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 14.13 KB
12
- ESM ⚡️ Build success in 95ms
13
- CJS dist/index.js 15.18 KB
14
- CJS ⚡️ Build success in 96ms
11
+ ESM dist/index.mjs 14.43 KB
12
+ ESM ⚡️ Build success in 61ms
13
+ CJS dist/index.js 15.47 KB
14
+ CJS ⚡️ Build success in 64ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3590ms
16
+ DTS ⚡️ Build success in 2870ms
17
17
  DTS dist/index.d.mts 4.15 KB
18
18
  DTS dist/index.d.ts 4.15 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.24.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/io@0.24.1
8
+ - @pluv/types@0.24.1
9
+
10
+ ## 0.24.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [6ac8a46]
15
+ - Updated dependencies [c26986d]
16
+ - @pluv/io@0.24.0
17
+ - @pluv/types@0.24.0
18
+
3
19
  ## 0.23.0
4
20
 
5
21
  ### Patch Changes
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.getRoom(state.id.toString(), { env, state });
71
+ this._room = io.createRoom(state.id.toString(), { env, state });
72
72
  }
73
73
  webSocketClose(ws, code, reason, wasClean) {
74
- if (io._registrationMode !== "detached") return;
75
- const handler2 = this._room.onClose(ws);
76
- handler2({ code, reason });
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
- if (io._registrationMode !== "detached") return;
80
- const handler2 = this._room.onError(ws);
81
- const eventError = error instanceof Error ? error : new Error("Internal Error");
82
- handler2({ error: eventError, message: eventError.message });
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
- if (io._registrationMode !== "detached") return;
86
- const handler2 = this._room.onMessage(ws);
87
- handler2({ data: message });
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) => value != null ? value : current(request, env));
163
- }, Promise.resolve(null));
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.getRoom(state.id.toString(), { env, state });
47
+ this._room = io.createRoom(state.id.toString(), { env, state });
48
48
  }
49
49
  webSocketClose(ws, code, reason, wasClean) {
50
- if (io._registrationMode !== "detached") return;
51
- const handler2 = this._room.onClose(ws);
52
- handler2({ code, reason });
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
- if (io._registrationMode !== "detached") return;
56
- const handler2 = this._room.onError(ws);
57
- const eventError = error instanceof Error ? error : new Error("Internal Error");
58
- handler2({ error: eventError, message: eventError.message });
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
- if (io._registrationMode !== "detached") return;
62
- const handler2 = this._room.onMessage(ws);
63
- handler2({ data: message });
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) => value != null ? value : current(request, env));
139
- }, Promise.resolve(null));
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.23.0",
3
+ "version": "0.24.1",
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.23.0",
22
- "@pluv/types": "^0.23.0"
21
+ "@pluv/io": "^0.24.1",
22
+ "@pluv/types": "^0.24.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@cloudflare/workers-types": "^4.20240815.0",
25
+ "@cloudflare/workers-types": "^4.20240821.1",
26
26
  "eslint": "^8.57.0",
27
27
  "tsup": "^8.2.4",
28
28
  "typescript": "^5.5.4",
29
- "@pluv/tsconfig": "^0.23.0",
30
- "eslint-config-pluv": "^0.23.0"
29
+ "@pluv/tsconfig": "^0.24.1",
30
+ "eslint-config-pluv": "^0.24.1"
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.state ?? null;
42
+ const state = deserialized?.state ?? null;
43
43
 
44
44
  if (!state) throw new Error("Could not get websocket state");
45
45
 
@@ -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.getRoom(state.id.toString(), { env, state });
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): void | Promise<void> {
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): void | Promise<void> {
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): void | Promise<void> {
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