@pluv/platform-cloudflare 0.32.3 → 0.32.5

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.32.3 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.32.5 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 11.66 KB
12
- ESM ⚡️ Build success in 73ms
13
- CJS dist/index.js 12.76 KB
14
- CJS ⚡️ Build success in 73ms
11
+ ESM dist/index.mjs 11.70 KB
12
+ ESM ⚡️ Build success in 62ms
13
+ CJS dist/index.js 12.80 KB
14
+ CJS ⚡️ Build success in 66ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 951ms
17
- DTS dist/index.d.mts 4.32 KB
18
- DTS dist/index.d.ts 4.32 KB
16
+ DTS ⚡️ Build success in 935ms
17
+ DTS dist/index.d.mts 4.67 KB
18
+ DTS dist/index.d.ts 4.67 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.32.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 98d7585: Update `meta` type on platform contexts to allow for nested json types.
8
+ - @pluv/io@0.32.5
9
+ - @pluv/persistence-cloudflare-transactional-storage@0.32.5
10
+ - @pluv/types@0.32.5
11
+
12
+ ## 0.32.4
13
+
14
+ ### Patch Changes
15
+
16
+ - fd054db: Add support for adding metadata to context when creating a room.
17
+
18
+ ```ts
19
+ import { createIO } from "@pluv/io";
20
+
21
+ // If using Cloudflare
22
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
23
+
24
+ const io = createIO({
25
+ // ...
26
+ platform: platformCloudflare<CloudflareEnv, { myCustomData: string }>(),
27
+ context: ({
28
+ env,
29
+ state,
30
+ // This is now available on the context function
31
+ meta,
32
+ }) => ({ env, state, meta }),
33
+ });
34
+
35
+ const ioServer = io.server();
36
+
37
+ ioServer.createRoom("my-room", {
38
+ // ...
39
+ // This will now be a required property when creating a room
40
+ meta: { myCustomData: "hello world" },
41
+ });
42
+
43
+ // If using Node.js
44
+ import { platformNode } from "@pluv/platform-node";
45
+
46
+ const io = createIO({
47
+ // ...
48
+ platform: platformNode<{ myCustomData: string }>(),
49
+ context: ({
50
+ // This is now available on the context function
51
+ meta,
52
+ }) => ({ env, state, meta }),
53
+ });
54
+
55
+ const ioServer = io.server();
56
+
57
+ ioServer.createRoom("my-room", {
58
+ // ...
59
+ // This will now be a required property when creating a room
60
+ meta: { myCustomData: "hello world" },
61
+ });
62
+ ```
63
+
64
+ - @pluv/io@0.32.4
65
+ - @pluv/persistence-cloudflare-transactional-storage@0.32.4
66
+ - @pluv/types@0.32.4
67
+
3
68
  ## 0.32.3
4
69
 
5
70
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPlatformConfig, WebSocketRegistrationMode, AbstractPlatform, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
2
- import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
2
+ import { JsonObject, Json, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
3
3
 
4
4
  type CloudflareWebSocketConfig = AbstractWebSocketConfig;
5
5
  declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
@@ -15,31 +15,30 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
15
15
  terminate(): void;
16
16
  }
17
17
 
18
- type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}> = AbstractPlatformConfig<{
18
+ type CloudflarePlatformRoomContext<TEnv extends Record<string, any>, TMeta extends Record<string, Json>> = {
19
19
  env: TEnv;
20
20
  state: DurableObjectState;
21
- }> & {
21
+ } & (keyof TMeta extends never ? {
22
+ meta?: undefined;
23
+ } : {
24
+ meta: TMeta;
25
+ });
26
+ type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & {
22
27
  mode?: WebSocketRegistrationMode;
23
28
  };
24
- declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<CloudflareWebSocket, {
29
+ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<CloudflareWebSocket, {
25
30
  env: TEnv;
26
31
  request: Request;
27
- }, {
28
- env: TEnv;
29
- state: DurableObjectState;
30
- }> {
32
+ }, CloudflarePlatformRoomContext<TEnv, TMeta>> {
31
33
  readonly _registrationMode: WebSocketRegistrationMode;
32
- constructor(config?: CloudflarePlatformConfig<TEnv>);
34
+ constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
33
35
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
34
36
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
35
37
  getLastPing(webSocket: CloudflareWebSocket): number | null;
36
38
  getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
37
39
  getSessionId(webSocket: WebSocket): string | null;
38
40
  getWebSockets(): readonly WebSocket[];
39
- initialize(config: AbstractPlatformConfig<{
40
- env: TEnv;
41
- state: DurableObjectState;
42
- }>): this;
41
+ initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
43
42
  parseData(data: string | ArrayBuffer): Record<string, any>;
44
43
  randomUUID(): string;
45
44
  setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): void;
@@ -71,6 +70,6 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
71
70
  type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
72
71
  declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
73
72
 
74
- declare const platformCloudflare: <TEnv extends Record<string, any> = {}>(config?: CloudflarePlatformConfig<TEnv>) => CloudflarePlatform<TEnv>;
73
+ declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
75
74
 
76
75
  export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPlatformConfig, WebSocketRegistrationMode, AbstractPlatform, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
2
- import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
2
+ import { JsonObject, Json, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
3
3
 
4
4
  type CloudflareWebSocketConfig = AbstractWebSocketConfig;
5
5
  declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
@@ -15,31 +15,30 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
15
15
  terminate(): void;
16
16
  }
17
17
 
18
- type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}> = AbstractPlatformConfig<{
18
+ type CloudflarePlatformRoomContext<TEnv extends Record<string, any>, TMeta extends Record<string, Json>> = {
19
19
  env: TEnv;
20
20
  state: DurableObjectState;
21
- }> & {
21
+ } & (keyof TMeta extends never ? {
22
+ meta?: undefined;
23
+ } : {
24
+ meta: TMeta;
25
+ });
26
+ type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & {
22
27
  mode?: WebSocketRegistrationMode;
23
28
  };
24
- declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<CloudflareWebSocket, {
29
+ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<CloudflareWebSocket, {
25
30
  env: TEnv;
26
31
  request: Request;
27
- }, {
28
- env: TEnv;
29
- state: DurableObjectState;
30
- }> {
32
+ }, CloudflarePlatformRoomContext<TEnv, TMeta>> {
31
33
  readonly _registrationMode: WebSocketRegistrationMode;
32
- constructor(config?: CloudflarePlatformConfig<TEnv>);
34
+ constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
33
35
  acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
34
36
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
35
37
  getLastPing(webSocket: CloudflareWebSocket): number | null;
36
38
  getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
37
39
  getSessionId(webSocket: WebSocket): string | null;
38
40
  getWebSockets(): readonly WebSocket[];
39
- initialize(config: AbstractPlatformConfig<{
40
- env: TEnv;
41
- state: DurableObjectState;
42
- }>): this;
41
+ initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
43
42
  parseData(data: string | ArrayBuffer): Record<string, any>;
44
43
  randomUUID(): string;
45
44
  setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): void;
@@ -71,6 +70,6 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
71
70
  type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
72
71
  declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
73
72
 
74
- declare const platformCloudflare: <TEnv extends Record<string, any> = {}>(config?: CloudflarePlatformConfig<TEnv>) => CloudflarePlatform<TEnv>;
73
+ declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
75
74
 
76
75
  export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
package/dist/index.js CHANGED
@@ -258,7 +258,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
258
258
 
259
259
  // src/CloudflarePlatform.ts
260
260
  var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPlatform {
261
- constructor(config = {}) {
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
264
  this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
@@ -314,7 +314,11 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
314
314
  throw new Error("Could not derive platform context");
315
315
  }
316
316
  return new _CloudflarePlatform({
317
- context: { env: context.env, state: context.state },
317
+ context: {
318
+ env: context.env,
319
+ meta: context.meta,
320
+ state: context.state
321
+ },
318
322
  mode: this._registrationMode,
319
323
  persistence: this.persistence,
320
324
  pubSub: this.pubSub
package/dist/index.mjs CHANGED
@@ -234,7 +234,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
234
234
 
235
235
  // src/CloudflarePlatform.ts
236
236
  var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
237
- constructor(config = {}) {
237
+ constructor(config) {
238
238
  var _a;
239
239
  super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new PersistenceCloudflareTransactionalStorage(config.context) } : {}));
240
240
  this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
@@ -290,7 +290,11 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
290
290
  throw new Error("Could not derive platform context");
291
291
  }
292
292
  return new _CloudflarePlatform({
293
- context: { env: context.env, state: context.state },
293
+ context: {
294
+ env: context.env,
295
+ meta: context.meta,
296
+ state: context.state
297
+ },
294
298
  mode: this._registrationMode,
295
299
  persistence: this.persistence,
296
300
  pubSub: this.pubSub
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-cloudflare",
3
- "version": "0.32.3",
3
+ "version": "0.32.5",
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.32.3",
22
- "@pluv/persistence-cloudflare-transactional-storage": "^0.32.3",
23
- "@pluv/types": "^0.32.3"
21
+ "@pluv/io": "^0.32.5",
22
+ "@pluv/persistence-cloudflare-transactional-storage": "^0.32.5",
23
+ "@pluv/types": "^0.32.5"
24
24
  },
25
25
  "devDependencies": {
26
- "@cloudflare/workers-types": "^4.20241011.0",
26
+ "@cloudflare/workers-types": "^4.20241018.0",
27
27
  "eslint": "^8.57.0",
28
28
  "tsup": "^8.3.0",
29
29
  "typescript": "^5.6.3",
30
- "@pluv/tsconfig": "^0.32.3",
31
- "eslint-config-pluv": "^0.32.3"
30
+ "@pluv/tsconfig": "^0.32.5",
31
+ "eslint-config-pluv": "^0.32.5"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,28 +1,36 @@
1
1
  import type {
2
2
  AbstractPlatformConfig,
3
3
  ConvertWebSocketConfig,
4
- InferInitContextType,
5
4
  WebSocketRegistrationMode,
6
5
  WebSocketSerializedState,
7
6
  } from "@pluv/io";
8
7
  import { AbstractPlatform } from "@pluv/io";
9
8
  import { PersistenceCloudflareTransactionalStorage } from "@pluv/persistence-cloudflare-transactional-storage";
9
+ import type { Json } from "@pluv/types";
10
10
  import { CloudflareWebSocket } from "./CloudflareWebSocket";
11
11
  import { DEFAULT_REGISTRATION_MODE } from "./constants";
12
12
 
13
- export type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}> = AbstractPlatformConfig<{
13
+ export type CloudflarePlatformRoomContext<TEnv extends Record<string, any>, TMeta extends Record<string, Json>> = {
14
14
  env: TEnv;
15
15
  state: DurableObjectState;
16
- }> & { mode?: WebSocketRegistrationMode };
16
+ } & (keyof TMeta extends never ? { meta?: undefined } : { meta: TMeta });
17
17
 
18
- export class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<
18
+ export type CloudflarePlatformConfig<
19
+ TEnv extends Record<string, any> = {},
20
+ TMeta extends Record<string, Json> = {},
21
+ > = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & { mode?: WebSocketRegistrationMode };
22
+
23
+ export class CloudflarePlatform<
24
+ TEnv extends Record<string, any> = {},
25
+ TMeta extends Record<string, Json> = {},
26
+ > extends AbstractPlatform<
19
27
  CloudflareWebSocket,
20
28
  { env: TEnv; request: Request },
21
- { env: TEnv; state: DurableObjectState }
29
+ CloudflarePlatformRoomContext<TEnv, TMeta>
22
30
  > {
23
31
  readonly _registrationMode: WebSocketRegistrationMode;
24
32
 
25
- constructor(config: CloudflarePlatformConfig<TEnv> = {}) {
33
+ constructor(config: CloudflarePlatformConfig<TEnv, TMeta>) {
26
34
  super({
27
35
  ...config,
28
36
  ...(config.context && config.mode === "detached"
@@ -92,15 +100,19 @@ export class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends A
92
100
  return detachedState.getWebSockets() ?? [];
93
101
  }
94
102
 
95
- public initialize(config: AbstractPlatformConfig<{ env: TEnv; state: DurableObjectState }>): this {
103
+ public initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this {
96
104
  const context = config.context ?? { ...this._roomContext };
97
105
 
98
106
  if (!context.env || !context.state) {
99
107
  throw new Error("Could not derive platform context");
100
108
  }
101
109
 
102
- return new CloudflarePlatform<TEnv>({
103
- context: { env: context.env, state: context.state },
110
+ return new CloudflarePlatform<TEnv, TMeta>({
111
+ context: {
112
+ env: context.env,
113
+ meta: context.meta,
114
+ state: context.state,
115
+ } as CloudflarePlatformRoomContext<TEnv, TMeta>,
104
116
  mode: this._registrationMode,
105
117
  persistence: this.persistence,
106
118
  pubSub: this.pubSub,
@@ -1,8 +1,9 @@
1
+ import type { Json } from "@pluv/types";
1
2
  import type { CloudflarePlatformConfig } from "./CloudflarePlatform";
2
3
  import { CloudflarePlatform } from "./CloudflarePlatform";
3
4
 
4
- export const platformCloudflare = <TEnv extends Record<string, any> = {}>(
5
- config: CloudflarePlatformConfig<TEnv> = {},
6
- ): CloudflarePlatform<TEnv> => {
7
- return new CloudflarePlatform<TEnv>(config);
5
+ export const platformCloudflare = <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(
6
+ config: CloudflarePlatformConfig<TEnv, TMeta> = {},
7
+ ): CloudflarePlatform<TEnv, TMeta> => {
8
+ return new CloudflarePlatform<TEnv, TMeta>(config);
8
9
  };