@pluv/platform-cloudflare 0.33.0 → 0.34.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.33.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.34.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
- CJS dist/index.js 12.80 KB
12
- CJS ⚡️ Build success in 36ms
13
- ESM dist/index.mjs 11.70 KB
14
- ESM ⚡️ Build success in 44ms
11
+ CJS dist/index.js 13.20 KB
12
+ CJS ⚡️ Build success in 73ms
13
+ ESM dist/index.mjs 12.09 KB
14
+ ESM ⚡️ Build success in 74ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 850ms
17
- DTS dist/index.d.mts 4.67 KB
18
- DTS dist/index.d.ts 4.67 KB
16
+ DTS ⚡️ Build success in 811ms
17
+ DTS dist/index.d.mts 5.39 KB
18
+ DTS dist/index.d.ts 5.39 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.34.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d639427]
8
+ - @pluv/io@0.34.1
9
+ - @pluv/persistence-cloudflare-transactional-storage@0.34.1
10
+ - @pluv/types@0.34.1
11
+
12
+ ## 0.34.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 70af3b2: Updated `@pluv/io` to have a `handleMode` internally that determines if connections are handled by the `PluvServer` or by the platform itself (i.e. outside of the `PluvServer`). The internals of `@pluv/platform-node` and `@pluv/platform-cloudflare` have been updated with the required changes for this.
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [0c920ea]
21
+ - Updated dependencies [70af3b2]
22
+ - @pluv/io@0.34.0
23
+ - @pluv/persistence-cloudflare-transactional-storage@0.34.0
24
+ - @pluv/types@0.34.0
25
+
3
26
  ## 0.33.0
4
27
 
5
28
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -29,8 +29,38 @@ type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta exten
29
29
  declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<CloudflareWebSocket, {
30
30
  env: TEnv;
31
31
  request: Request;
32
- }, CloudflarePlatformRoomContext<TEnv, TMeta>> {
33
- readonly _registrationMode: WebSocketRegistrationMode;
32
+ }, CloudflarePlatformRoomContext<TEnv, TMeta>, {
33
+ authorize: {
34
+ required: true;
35
+ };
36
+ handleMode: "io";
37
+ requireAuth: false;
38
+ registrationMode: WebSocketRegistrationMode;
39
+ listeners: {
40
+ onRoomDeleted: true;
41
+ onRoomMessage: true;
42
+ onStorageUpdated: true;
43
+ onUserConnected: true;
44
+ onUserDisconnected: true;
45
+ };
46
+ }> {
47
+ readonly _config: {
48
+ authorize: {
49
+ required: true;
50
+ secret: true;
51
+ };
52
+ handleMode: "io";
53
+ registrationMode: WebSocketRegistrationMode;
54
+ requireAuth: false;
55
+ listeners: {
56
+ onRoomDeleted: true;
57
+ onRoomMessage: true;
58
+ onStorageUpdated: true;
59
+ onUserConnected: true;
60
+ onUserDisconnected: true;
61
+ };
62
+ };
63
+ readonly _name = "platformCloudflare";
34
64
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
35
65
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
36
66
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
package/dist/index.d.ts CHANGED
@@ -29,8 +29,38 @@ type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta exten
29
29
  declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<CloudflareWebSocket, {
30
30
  env: TEnv;
31
31
  request: Request;
32
- }, CloudflarePlatformRoomContext<TEnv, TMeta>> {
33
- readonly _registrationMode: WebSocketRegistrationMode;
32
+ }, CloudflarePlatformRoomContext<TEnv, TMeta>, {
33
+ authorize: {
34
+ required: true;
35
+ };
36
+ handleMode: "io";
37
+ requireAuth: false;
38
+ registrationMode: WebSocketRegistrationMode;
39
+ listeners: {
40
+ onRoomDeleted: true;
41
+ onRoomMessage: true;
42
+ onStorageUpdated: true;
43
+ onUserConnected: true;
44
+ onUserDisconnected: true;
45
+ };
46
+ }> {
47
+ readonly _config: {
48
+ authorize: {
49
+ required: true;
50
+ secret: true;
51
+ };
52
+ handleMode: "io";
53
+ registrationMode: WebSocketRegistrationMode;
54
+ requireAuth: false;
55
+ listeners: {
56
+ onRoomDeleted: true;
57
+ onRoomMessage: true;
58
+ onStorageUpdated: true;
59
+ onUserConnected: true;
60
+ onUserDisconnected: true;
61
+ };
62
+ };
63
+ readonly _name = "platformCloudflare";
34
64
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
35
65
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
36
66
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
package/dist/index.js CHANGED
@@ -55,12 +55,12 @@ var __async = (__this, __arguments, generator) => {
55
55
  };
56
56
 
57
57
  // src/index.ts
58
- var src_exports = {};
59
- __export(src_exports, {
58
+ var index_exports = {};
59
+ __export(index_exports, {
60
60
  createPluvHandler: () => createPluvHandler,
61
61
  platformCloudflare: () => platformCloudflare
62
62
  });
63
- module.exports = __toCommonJS(src_exports);
63
+ module.exports = __toCommonJS(index_exports);
64
64
 
65
65
  // src/createPluvHandler.ts
66
66
  var import_path_to_regexp = require("path-to-regexp");
@@ -73,14 +73,14 @@ var createPluvHandler = (config) => {
73
73
  }
74
74
  webSocketClose(ws, code, reason, wasClean) {
75
75
  return __async(this, null, function* () {
76
- if (io._defs.platform._registrationMode !== "detached") return;
76
+ if (io._defs.platform._config.registrationMode !== "detached") return;
77
77
  const handler2 = this._room.onClose(ws);
78
78
  yield handler2({ code, reason });
79
79
  });
80
80
  }
81
81
  webSocketError(ws, error) {
82
82
  return __async(this, null, function* () {
83
- if (io._defs.platform._registrationMode !== "detached") return;
83
+ if (io._defs.platform._config.registrationMode !== "detached") return;
84
84
  const handler2 = this._room.onError(ws);
85
85
  const eventError = error instanceof Error ? error : new Error("Internal Error");
86
86
  yield handler2({ error: eventError, message: eventError.message });
@@ -88,7 +88,7 @@ var createPluvHandler = (config) => {
88
88
  }
89
89
  webSocketMessage(ws, message) {
90
90
  return __async(this, null, function* () {
91
- if (io._defs.platform._registrationMode !== "detached") return;
91
+ if (io._defs.platform._config.registrationMode !== "detached") return;
92
92
  const handler2 = this._room.onMessage(ws);
93
93
  yield handler2({ data: message });
94
94
  });
@@ -261,7 +261,23 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
261
261
  constructor(config) {
262
262
  var _a;
263
263
  super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new import_persistence_cloudflare_transactional_storage.PersistenceCloudflareTransactionalStorage(config.context) } : {}));
264
- this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
264
+ this._name = "platformCloudflare";
265
+ this._config = {
266
+ authorize: {
267
+ required: true,
268
+ secret: true
269
+ },
270
+ handleMode: "io",
271
+ registrationMode: (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE,
272
+ requireAuth: false,
273
+ listeners: {
274
+ onRoomDeleted: true,
275
+ onRoomMessage: true,
276
+ onStorageUpdated: true,
277
+ onUserConnected: true,
278
+ onUserDisconnected: true
279
+ }
280
+ };
265
281
  const detachedState = this._getDetachedState();
266
282
  if (!detachedState) return;
267
283
  detachedState.setWebSocketAutoResponse(
@@ -319,7 +335,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
319
335
  meta: context.meta,
320
336
  state: context.state
321
337
  },
322
- mode: this._registrationMode,
338
+ mode: this._config.registrationMode,
323
339
  persistence: this.persistence,
324
340
  pubSub: this.pubSub
325
341
  })._initialize();
@@ -339,7 +355,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
339
355
  }
340
356
  _getDetachedState() {
341
357
  var _a, _b;
342
- if (this._registrationMode !== "detached") return null;
358
+ if (this._config.registrationMode !== "detached") return null;
343
359
  return (_b = (_a = this._roomContext) == null ? void 0 : _a.state) != null ? _b : null;
344
360
  }
345
361
  };
package/dist/index.mjs CHANGED
@@ -49,14 +49,14 @@ var createPluvHandler = (config) => {
49
49
  }
50
50
  webSocketClose(ws, code, reason, wasClean) {
51
51
  return __async(this, null, function* () {
52
- if (io._defs.platform._registrationMode !== "detached") return;
52
+ if (io._defs.platform._config.registrationMode !== "detached") return;
53
53
  const handler2 = this._room.onClose(ws);
54
54
  yield handler2({ code, reason });
55
55
  });
56
56
  }
57
57
  webSocketError(ws, error) {
58
58
  return __async(this, null, function* () {
59
- if (io._defs.platform._registrationMode !== "detached") return;
59
+ if (io._defs.platform._config.registrationMode !== "detached") return;
60
60
  const handler2 = this._room.onError(ws);
61
61
  const eventError = error instanceof Error ? error : new Error("Internal Error");
62
62
  yield handler2({ error: eventError, message: eventError.message });
@@ -64,7 +64,7 @@ var createPluvHandler = (config) => {
64
64
  }
65
65
  webSocketMessage(ws, message) {
66
66
  return __async(this, null, function* () {
67
- if (io._defs.platform._registrationMode !== "detached") return;
67
+ if (io._defs.platform._config.registrationMode !== "detached") return;
68
68
  const handler2 = this._room.onMessage(ws);
69
69
  yield handler2({ data: message });
70
70
  });
@@ -237,7 +237,23 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
237
237
  constructor(config) {
238
238
  var _a;
239
239
  super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new PersistenceCloudflareTransactionalStorage(config.context) } : {}));
240
- this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
240
+ this._name = "platformCloudflare";
241
+ this._config = {
242
+ authorize: {
243
+ required: true,
244
+ secret: true
245
+ },
246
+ handleMode: "io",
247
+ registrationMode: (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE,
248
+ requireAuth: false,
249
+ listeners: {
250
+ onRoomDeleted: true,
251
+ onRoomMessage: true,
252
+ onStorageUpdated: true,
253
+ onUserConnected: true,
254
+ onUserDisconnected: true
255
+ }
256
+ };
241
257
  const detachedState = this._getDetachedState();
242
258
  if (!detachedState) return;
243
259
  detachedState.setWebSocketAutoResponse(
@@ -295,7 +311,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
295
311
  meta: context.meta,
296
312
  state: context.state
297
313
  },
298
- mode: this._registrationMode,
314
+ mode: this._config.registrationMode,
299
315
  persistence: this.persistence,
300
316
  pubSub: this.pubSub
301
317
  })._initialize();
@@ -315,7 +331,7 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
315
331
  }
316
332
  _getDetachedState() {
317
333
  var _a, _b;
318
- if (this._registrationMode !== "detached") return null;
334
+ if (this._config.registrationMode !== "detached") return null;
319
335
  return (_b = (_a = this._roomContext) == null ? void 0 : _a.state) != null ? _b : null;
320
336
  }
321
337
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-cloudflare",
3
- "version": "0.33.0",
3
+ "version": "0.34.1",
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.33.0",
22
- "@pluv/persistence-cloudflare-transactional-storage": "^0.33.0",
23
- "@pluv/types": "^0.33.0"
21
+ "@pluv/io": "^0.34.1",
22
+ "@pluv/persistence-cloudflare-transactional-storage": "^0.34.1",
23
+ "@pluv/types": "^0.34.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@cloudflare/workers-types": "^4.20241205.0",
26
+ "@cloudflare/workers-types": "^4.20241224.0",
27
27
  "eslint": "^8.57.1",
28
28
  "tsup": "^8.3.5",
29
29
  "typescript": "^5.7.2",
30
- "@pluv/tsconfig": "^0.33.0",
31
- "eslint-config-pluv": "^0.33.0"
30
+ "@pluv/tsconfig": "^0.34.1",
31
+ "eslint-config-pluv": "^0.34.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -26,9 +26,25 @@ export class CloudflarePlatform<
26
26
  > extends AbstractPlatform<
27
27
  CloudflareWebSocket,
28
28
  { env: TEnv; request: Request },
29
- CloudflarePlatformRoomContext<TEnv, TMeta>
29
+ CloudflarePlatformRoomContext<TEnv, TMeta>,
30
+ {
31
+ authorize: {
32
+ required: true;
33
+ };
34
+ handleMode: "io";
35
+ requireAuth: false;
36
+ registrationMode: WebSocketRegistrationMode;
37
+ listeners: {
38
+ onRoomDeleted: true;
39
+ onRoomMessage: true;
40
+ onStorageUpdated: true;
41
+ onUserConnected: true;
42
+ onUserDisconnected: true;
43
+ };
44
+ }
30
45
  > {
31
- readonly _registrationMode: WebSocketRegistrationMode;
46
+ public readonly _config;
47
+ public readonly _name = "platformCloudflare";
32
48
 
33
49
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>) {
34
50
  super({
@@ -38,7 +54,22 @@ export class CloudflarePlatform<
38
54
  : {}),
39
55
  });
40
56
 
41
- this._registrationMode = config.mode ?? DEFAULT_REGISTRATION_MODE;
57
+ this._config = {
58
+ authorize: {
59
+ required: true as const,
60
+ secret: true as const,
61
+ },
62
+ handleMode: "io" as const,
63
+ registrationMode: config.mode ?? DEFAULT_REGISTRATION_MODE,
64
+ requireAuth: false as const,
65
+ listeners: {
66
+ onRoomDeleted: true as const,
67
+ onRoomMessage: true as const,
68
+ onStorageUpdated: true as const,
69
+ onUserConnected: true as const,
70
+ onUserDisconnected: true as const,
71
+ },
72
+ };
42
73
 
43
74
  const detachedState = this._getDetachedState();
44
75
 
@@ -113,7 +144,7 @@ export class CloudflarePlatform<
113
144
  meta: context.meta,
114
145
  state: context.state,
115
146
  } as CloudflarePlatformRoomContext<TEnv, TMeta>,
116
- mode: this._registrationMode,
147
+ mode: this._config.registrationMode,
117
148
  persistence: this.persistence,
118
149
  pubSub: this.pubSub,
119
150
  })._initialize() as this;
@@ -138,7 +169,7 @@ export class CloudflarePlatform<
138
169
  }
139
170
 
140
171
  private _getDetachedState(): DurableObjectState | null {
141
- if (this._registrationMode !== "detached") return null;
172
+ if (this._config.registrationMode !== "detached") return null;
142
173
 
143
174
  return this._roomContext?.state ?? null;
144
175
  }
@@ -60,7 +60,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
60
60
  }
61
61
 
62
62
  public async webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void> {
63
- if (io._defs.platform._registrationMode !== "detached") return;
63
+ if (io._defs.platform._config.registrationMode !== "detached") return;
64
64
 
65
65
  const handler = this._room.onClose(ws);
66
66
 
@@ -68,7 +68,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
68
68
  }
69
69
 
70
70
  public async webSocketError(ws: WebSocket, error: unknown): Promise<void> {
71
- if (io._defs.platform._registrationMode !== "detached") return;
71
+ if (io._defs.platform._config.registrationMode !== "detached") return;
72
72
 
73
73
  const handler = this._room.onError(ws);
74
74
  const eventError = error instanceof Error ? error : new Error("Internal Error");
@@ -77,7 +77,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<CloudflarePlatf
77
77
  }
78
78
 
79
79
  public async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void> {
80
- if (io._defs.platform._registrationMode !== "detached") return;
80
+ if (io._defs.platform._config.registrationMode !== "detached") return;
81
81
 
82
82
  const handler = this._room.onMessage(ws);
83
83