@pluv/platform-node 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-node@0.32.3 build /home/runner/work/pluv/pluv/packages/platform-node
2
+ > @pluv/platform-node@0.32.5 build /home/runner/work/pluv/pluv/packages/platform-node
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 7.41 KB
12
- ESM ⚡️ Build success in 104ms
13
- CJS dist/index.js 9.26 KB
14
- CJS ⚡️ Build success in 114ms
11
+ ESM dist/index.mjs 8.13 KB
12
+ ESM ⚡️ Build success in 80ms
13
+ CJS dist/index.js 9.89 KB
14
+ CJS ⚡️ Build success in 88ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5599ms
17
- DTS dist/index.d.mts 3.78 KB
18
- DTS dist/index.d.ts 3.78 KB
16
+ DTS ⚡️ Build success in 5166ms
17
+ DTS dist/index.d.mts 4.17 KB
18
+ DTS dist/index.d.ts 4.17 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
1
1
  # @pluv/platform-node
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/types@0.32.5
10
+
11
+ ## 0.32.4
12
+
13
+ ### Patch Changes
14
+
15
+ - fd054db: Add support for adding metadata to context when creating a room.
16
+
17
+ ```ts
18
+ import { createIO } from "@pluv/io";
19
+
20
+ // If using Cloudflare
21
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
22
+
23
+ const io = createIO({
24
+ // ...
25
+ platform: platformCloudflare<CloudflareEnv, { myCustomData: string }>(),
26
+ context: ({
27
+ env,
28
+ state,
29
+ // This is now available on the context function
30
+ meta,
31
+ }) => ({ env, state, meta }),
32
+ });
33
+
34
+ const ioServer = io.server();
35
+
36
+ ioServer.createRoom("my-room", {
37
+ // ...
38
+ // This will now be a required property when creating a room
39
+ meta: { myCustomData: "hello world" },
40
+ });
41
+
42
+ // If using Node.js
43
+ import { platformNode } from "@pluv/platform-node";
44
+
45
+ const io = createIO({
46
+ // ...
47
+ platform: platformNode<{ myCustomData: string }>(),
48
+ context: ({
49
+ // This is now available on the context function
50
+ meta,
51
+ }) => ({ env, state, meta }),
52
+ });
53
+
54
+ const ioServer = io.server();
55
+
56
+ ioServer.createRoom("my-room", {
57
+ // ...
58
+ // This will now be a required property when creating a room
59
+ meta: { myCustomData: "hello world" },
60
+ });
61
+ ```
62
+
63
+ - @pluv/io@0.32.4
64
+ - @pluv/types@0.32.4
65
+
3
66
  ## 0.32.3
4
67
 
5
68
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WebSocket, Server as Server$1 } from 'ws';
2
2
  export { WebSocket } from 'ws';
3
3
  import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType } from '@pluv/io';
4
- import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
4
+ import { JsonObject, Json, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
5
5
  import { IncomingMessage, Server, ServerResponse } from 'node:http';
6
6
 
7
7
  type NodeWebSocketConfig = AbstractWebSocketConfig;
@@ -20,7 +20,12 @@ declare class NodeWebSocket extends AbstractWebSocket<WebSocket> {
20
20
  terminate(): void;
21
21
  }
22
22
 
23
- type NodePlatformConfig = {
23
+ type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never ? {
24
+ meta?: undefined;
25
+ } : {
26
+ meta: TMeta;
27
+ };
28
+ type NodePlatformConfig<TMeta extends Record<string, Json>> = {
24
29
  mode?: WebSocketRegistrationMode;
25
30
  } & ({
26
31
  persistence?: undefined;
@@ -28,19 +33,21 @@ type NodePlatformConfig = {
28
33
  } | {
29
34
  persistence: AbstractPersistence;
30
35
  pubSub: AbstractPubSub;
31
- });
32
- declare class NodePlatform extends AbstractPlatform<NodeWebSocket, {
36
+ }) & {
37
+ context?: NodePlatformRoomContext<TMeta>;
38
+ };
39
+ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket, {
33
40
  req: IncomingMessage;
34
- }, {}> {
41
+ }, NodePlatformRoomContext<TMeta>> {
35
42
  readonly _registrationMode: WebSocketRegistrationMode;
36
- constructor(config?: NodePlatformConfig);
43
+ constructor(config?: NodePlatformConfig<TMeta>);
37
44
  acceptWebSocket(webSocket: NodeWebSocket): Promise<void>;
38
45
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket;
39
46
  getLastPing(webSocket: NodeWebSocket): number | null;
40
47
  getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
41
48
  getSessionId(webSocket: WebSocket): string | null;
42
49
  getWebSockets(): readonly WebSocket[];
43
- initialize(config: AbstractPlatformConfig<{}>): this;
50
+ initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this;
44
51
  parseData(data: string | ArrayBuffer): Record<string, any>;
45
52
  randomUUID(): string;
46
53
  setSerializedState(webSocket: NodeWebSocket, state: WebSocketSerializedState): void;
@@ -71,6 +78,6 @@ interface CreatePluvHandlerResult {
71
78
  }
72
79
  declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
73
80
 
74
- declare const platformNode: (config?: NodePlatformConfig) => NodePlatform;
81
+ declare const platformNode: <TMeta extends Record<string, Json> = {}>(config?: NodePlatformConfig<TMeta>) => NodePlatform<TMeta>;
75
82
 
76
83
  export { type AuthorizeFunction, type AuthorizeFunctionContext, type CreatePluvHandlerConfig, NodePlatform, type NodePlatformConfig, createPluvHandler, platformNode };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WebSocket, Server as Server$1 } from 'ws';
2
2
  export { WebSocket } from 'ws';
3
3
  import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType } from '@pluv/io';
4
- import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
4
+ import { JsonObject, Json, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
5
5
  import { IncomingMessage, Server, ServerResponse } from 'node:http';
6
6
 
7
7
  type NodeWebSocketConfig = AbstractWebSocketConfig;
@@ -20,7 +20,12 @@ declare class NodeWebSocket extends AbstractWebSocket<WebSocket> {
20
20
  terminate(): void;
21
21
  }
22
22
 
23
- type NodePlatformConfig = {
23
+ type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never ? {
24
+ meta?: undefined;
25
+ } : {
26
+ meta: TMeta;
27
+ };
28
+ type NodePlatformConfig<TMeta extends Record<string, Json>> = {
24
29
  mode?: WebSocketRegistrationMode;
25
30
  } & ({
26
31
  persistence?: undefined;
@@ -28,19 +33,21 @@ type NodePlatformConfig = {
28
33
  } | {
29
34
  persistence: AbstractPersistence;
30
35
  pubSub: AbstractPubSub;
31
- });
32
- declare class NodePlatform extends AbstractPlatform<NodeWebSocket, {
36
+ }) & {
37
+ context?: NodePlatformRoomContext<TMeta>;
38
+ };
39
+ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket, {
33
40
  req: IncomingMessage;
34
- }, {}> {
41
+ }, NodePlatformRoomContext<TMeta>> {
35
42
  readonly _registrationMode: WebSocketRegistrationMode;
36
- constructor(config?: NodePlatformConfig);
43
+ constructor(config?: NodePlatformConfig<TMeta>);
37
44
  acceptWebSocket(webSocket: NodeWebSocket): Promise<void>;
38
45
  convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket;
39
46
  getLastPing(webSocket: NodeWebSocket): number | null;
40
47
  getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
41
48
  getSessionId(webSocket: WebSocket): string | null;
42
49
  getWebSockets(): readonly WebSocket[];
43
- initialize(config: AbstractPlatformConfig<{}>): this;
50
+ initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this;
44
51
  parseData(data: string | ArrayBuffer): Record<string, any>;
45
52
  randomUUID(): string;
46
53
  setSerializedState(webSocket: NodeWebSocket, state: WebSocketSerializedState): void;
@@ -71,6 +78,6 @@ interface CreatePluvHandlerResult {
71
78
  }
72
79
  declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
73
80
 
74
- declare const platformNode: (config?: NodePlatformConfig) => NodePlatform;
81
+ declare const platformNode: <TMeta extends Record<string, Json> = {}>(config?: NodePlatformConfig<TMeta>) => NodePlatform<TMeta>;
75
82
 
76
83
  export { type AuthorizeFunction, type AuthorizeFunctionContext, type CreatePluvHandlerConfig, NodePlatform, type NodePlatformConfig, createPluvHandler, platformNode };
package/dist/index.js CHANGED
@@ -3,8 +3,22 @@ var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
8
22
  var __export = (target, all) => {
9
23
  for (var name in all)
10
24
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -232,8 +246,10 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
232
246
  // src/NodePlatform.ts
233
247
  var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
234
248
  constructor(config = {}) {
235
- const { mode = "attached", persistence, pubSub } = config;
236
- super(persistence && pubSub ? { persistence, pubSub } : {});
249
+ const { context, mode = "attached", persistence, pubSub } = config;
250
+ super(__spreadValues({
251
+ context
252
+ }, persistence && pubSub ? { persistence, pubSub } : {}));
237
253
  this._registrationMode = mode;
238
254
  }
239
255
  acceptWebSocket(webSocket) {
package/dist/index.mjs CHANGED
@@ -1,3 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
1
17
  var __async = (__this, __arguments, generator) => {
2
18
  return new Promise((resolve, reject) => {
3
19
  var fulfilled = (value) => {
@@ -196,8 +212,10 @@ var NodeWebSocket = class extends AbstractWebSocket {
196
212
  // src/NodePlatform.ts
197
213
  var NodePlatform = class _NodePlatform extends AbstractPlatform {
198
214
  constructor(config = {}) {
199
- const { mode = "attached", persistence, pubSub } = config;
200
- super(persistence && pubSub ? { persistence, pubSub } : {});
215
+ const { context, mode = "attached", persistence, pubSub } = config;
216
+ super(__spreadValues({
217
+ context
218
+ }, persistence && pubSub ? { persistence, pubSub } : {}));
201
219
  this._registrationMode = mode;
202
220
  }
203
221
  acceptWebSocket(webSocket) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-node",
3
- "version": "0.32.3",
3
+ "version": "0.32.5",
4
4
  "description": "@pluv/io adapter for node.js",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,19 +17,19 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@types/node": "^22.7.5",
20
+ "@types/node": "^22.7.8",
21
21
  "@types/ws": "^8.5.12",
22
22
  "path-to-regexp": "^8.2.0",
23
- "@pluv/io": "^0.32.3",
24
- "@pluv/types": "^0.32.3"
23
+ "@pluv/io": "^0.32.5",
24
+ "@pluv/types": "^0.32.5"
25
25
  },
26
26
  "devDependencies": {
27
27
  "eslint": "^8.57.0",
28
28
  "tsup": "^8.3.0",
29
29
  "typescript": "^5.6.3",
30
30
  "ws": "^8.18.0",
31
- "@pluv/tsconfig": "^0.32.3",
32
- "eslint-config-pluv": "^0.32.3"
31
+ "@pluv/tsconfig": "^0.32.5",
32
+ "eslint-config-pluv": "^0.32.5"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "ws": "^8.0.0"
@@ -7,24 +7,36 @@ import type {
7
7
  WebSocketSerializedState,
8
8
  } from "@pluv/io";
9
9
  import { AbstractPlatform } from "@pluv/io";
10
+ import type { Json } from "@pluv/types";
10
11
  import crypto from "node:crypto";
11
12
  import type { IncomingMessage } from "node:http";
12
13
  import { TextDecoder } from "node:util";
13
14
  import type { WebSocket } from "ws";
14
15
  import { NodeWebSocket } from "./NodeWebSocket";
15
16
 
16
- export type NodePlatformConfig = { mode?: WebSocketRegistrationMode } & (
17
+ export type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never
18
+ ? { meta?: undefined }
19
+ : { meta: TMeta };
20
+
21
+ export type NodePlatformConfig<TMeta extends Record<string, Json>> = { mode?: WebSocketRegistrationMode } & (
17
22
  | { persistence?: undefined; pubSub?: undefined }
18
23
  | { persistence: AbstractPersistence; pubSub: AbstractPubSub }
19
- );
24
+ ) & { context?: NodePlatformRoomContext<TMeta> };
20
25
 
21
- export class NodePlatform extends AbstractPlatform<NodeWebSocket, { req: IncomingMessage }, {}> {
26
+ export class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<
27
+ NodeWebSocket,
28
+ { req: IncomingMessage },
29
+ NodePlatformRoomContext<TMeta>
30
+ > {
22
31
  readonly _registrationMode: WebSocketRegistrationMode;
23
32
 
24
- constructor(config: NodePlatformConfig = {}) {
25
- const { mode = "attached", persistence, pubSub } = config;
33
+ constructor(config: NodePlatformConfig<TMeta> = {}) {
34
+ const { context, mode = "attached", persistence, pubSub } = config;
26
35
 
27
- super(persistence && pubSub ? { persistence, pubSub } : {});
36
+ super({
37
+ context,
38
+ ...(persistence && pubSub ? { persistence, pubSub } : {}),
39
+ });
28
40
 
29
41
  this._registrationMode = mode;
30
42
  }
@@ -55,13 +67,13 @@ export class NodePlatform extends AbstractPlatform<NodeWebSocket, { req: Incomin
55
67
  return [];
56
68
  }
57
69
 
58
- public initialize(config: AbstractPlatformConfig<{}>): this {
70
+ public initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this {
59
71
  return new NodePlatform({
60
72
  context: config.context,
61
73
  mode: this._registrationMode,
62
74
  persistence: this.persistence,
63
75
  pubSub: this.pubSub,
64
- } as NodePlatformConfig)._initialize() as this;
76
+ } as NodePlatformConfig<TMeta>)._initialize() as this;
65
77
  }
66
78
 
67
79
  public parseData(data: string | ArrayBuffer): Record<string, any> {
@@ -1,6 +1,9 @@
1
+ import type { Json } from "@pluv/types";
1
2
  import type { NodePlatformConfig } from "./NodePlatform";
2
3
  import { NodePlatform } from "./NodePlatform";
3
4
 
4
- export const platformNode = (config: NodePlatformConfig = {}): NodePlatform => {
5
- return new NodePlatform(config);
5
+ export const platformNode = <TMeta extends Record<string, Json> = {}>(
6
+ config: NodePlatformConfig<TMeta> = {},
7
+ ): NodePlatform<TMeta> => {
8
+ return new NodePlatform<TMeta>(config);
6
9
  };