@pluv/platform-node 3.2.2 → 4.0.0
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.
- package/.turbo/turbo-build.log +16 -16
- package/CHANGELOG.md +91 -0
- package/dist/index.d.mts +85 -78
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +186 -220
- package/dist/index.mjs.map +1 -0
- package/package.json +21 -17
- package/src/NodePlatform.ts +4 -2
- package/tsdown.config.ts +14 -0
- package/dist/index.d.ts +0 -106
- package/dist/index.js +0 -263
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-node@
|
|
3
|
-
>
|
|
2
|
+
> @pluv/platform-node@4.0.0 build /home/runner/work/pluv/pluv/packages/platform-node
|
|
3
|
+
> tsdown
|
|
4
4
|
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
[
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.20.0-beta.4[22m powered by rolldown [2mv1.0.0-beta.60[22m
|
|
6
|
+
[34mℹ[39m config file: [4m/home/runner/work/pluv/pluv/packages/platform-node/tsdown.config.ts[24m
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
|
+
[34mℹ[39m target: [34mesnext[39m
|
|
9
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
|
+
[34mℹ[39m Build start
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m 4.20 kB[22m [2m│ gzip: 1.43 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22mindex.mjs.map [2m14.07 kB[22m [2m│ gzip: 3.74 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22mindex.d.mts.map [2m 2.83 kB[22m [2m│ gzip: 0.96 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 5.49 kB[22m [2m│ gzip: 1.50 kB[22m
|
|
15
|
+
[34mℹ[39m 4 files, total: 26.59 kB
|
|
16
|
+
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
17
|
+
|
|
18
|
+
[32m✔[39m Build complete in [32m3705ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
1
|
# @pluv/platform-node
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- df5c39c: Update all packages to be ESM only.
|
|
8
|
+
- 07e2a1e: ### Breaking Changes
|
|
9
|
+
|
|
10
|
+
This release includes the following breaking changes:
|
|
11
|
+
1. **Removed `onDestroy` handler** (room-level only) - replaced with `onRoomDestroyed` and `onStorageDestroyed`
|
|
12
|
+
2. **Removed `onRoomDeleted` handler** (server-level) - replaced with `onRoomDestroyed` and `onStorageDestroyed`
|
|
13
|
+
3. **Listeners can no longer be configured at room-level** - all listeners must be configured at server-level via `io.server()`
|
|
14
|
+
4. **Event type changes** - `IORoomDestroyedEvent` no longer includes `encodedState`
|
|
15
|
+
|
|
16
|
+
#### Remove `onDestroy` and `onRoomDeleted` in favor of `onRoomDestroyed` and `onStorageDestroyed`
|
|
17
|
+
|
|
18
|
+
**BREAKING**: Two event handlers have been **removed** in favor of two separate handlers that provide better control over when storage is saved. This is a breaking change that requires code updates.
|
|
19
|
+
|
|
20
|
+
**New Handlers:**
|
|
21
|
+
- **`onRoomDestroyed`**: Fires whenever a room is destroyed. This event does NOT include `encodedState` to prevent accidentally saving empty or uninitialized storage data. **Available only at server-level** via `io.server()`.
|
|
22
|
+
- **`onStorageDestroyed`**: Only fires when the storage document is about to be destroyed after it has been initialized via `initializeSession`. This event includes `encodedState` and should be used for saving storage to your database. **Available only at server-level** via `io.server()`.
|
|
23
|
+
|
|
24
|
+
**Removed Handlers:**
|
|
25
|
+
- **`onDestroy`** (room-level only, via `createRoom`): **REMOVED**. Use `onRoomDestroyed` and `onStorageDestroyed` instead.
|
|
26
|
+
- **`onRoomDeleted`** (server-level): **REMOVED**. Use `onRoomDestroyed` and `onStorageDestroyed` instead.
|
|
27
|
+
|
|
28
|
+
**Migration Guide:**
|
|
29
|
+
|
|
30
|
+
**Old (no longer works):**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// Room-level onDestroy (removed)
|
|
34
|
+
const room = io.createRoom("room-id", {
|
|
35
|
+
onDestroy: async ({ encodedState, room }) => {
|
|
36
|
+
// This no longer works
|
|
37
|
+
await saveToDatabase(room, encodedState);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Server-level onRoomDeleted (removed)
|
|
42
|
+
io.server({
|
|
43
|
+
onRoomDeleted: async ({ encodedState, room }) => {
|
|
44
|
+
// This no longer works
|
|
45
|
+
await saveToDatabase(room, encodedState);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**New (recommended approach):**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Server-level handlers (recommended - all listeners are now server-level)
|
|
54
|
+
io.server({
|
|
55
|
+
onRoomDestroyed: async ({ room }) => {
|
|
56
|
+
// Room destroyed - use for cleanup if needed
|
|
57
|
+
await cleanupRoom(room);
|
|
58
|
+
},
|
|
59
|
+
onStorageDestroyed: async ({ encodedState, room }) => {
|
|
60
|
+
// Only fires when storage was initialized via initializeSession
|
|
61
|
+
// Safe to save to database
|
|
62
|
+
await saveToDatabase(room, encodedState);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Rooms are created without listener options
|
|
67
|
+
const room = io.createRoom("room-id");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Type Changes
|
|
71
|
+
|
|
72
|
+
**BREAKING**: The following type changes may require TypeScript code updates:
|
|
73
|
+
- **`IORoomDestroyedEvent`** no longer includes `encodedState` (breaking change if you were accessing `encodedState` from this event)
|
|
74
|
+
- **`IORoomListenerEvent`** includes `encodedState: string | null` (used by `onStorageDestroyed`)
|
|
75
|
+
- **All listeners must be configured at the server level** via `io.server()`, not at the room level via `createRoom()` (breaking change - room-level listener configuration is no longer supported)
|
|
76
|
+
- **`CreateRoomOptions`** now correctly requires platform-specific room context properties (e.g., `env` and `state` for Cloudflare) when they are required by the platform, while properly handling optional properties like `meta` (breaking change - TypeScript will now correctly enforce required properties)
|
|
77
|
+
|
|
78
|
+
### Minor Changes
|
|
79
|
+
|
|
80
|
+
- 037074e: Migrated build process from tsup to tsdown.
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- 2eb5def: Bumped dependencies.
|
|
85
|
+
- Updated dependencies [2eb5def]
|
|
86
|
+
- Updated dependencies [df5c39c]
|
|
87
|
+
- Updated dependencies [c142910]
|
|
88
|
+
- Updated dependencies [037074e]
|
|
89
|
+
- Updated dependencies [07e2a1e]
|
|
90
|
+
- @pluv/types@4.0.0
|
|
91
|
+
- @pluv/crdt@4.0.0
|
|
92
|
+
- @pluv/io@4.0.0
|
|
93
|
+
|
|
3
94
|
## 3.2.2
|
|
4
95
|
|
|
5
96
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,106 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { CrdtLibraryType, NoopCrdtDocFactory } from '@pluv/crdt';
|
|
1
|
+
import { AbstractEventMap, AbstractListener, AbstractPersistence, AbstractPlatform, AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, AbstractWebSocketConfig, ConvertWebSocketConfig, CreateIOParams, InferInitContextType, PluvContext, PluvIOAuthorize, WebSocketRegistrationMode, WebSocketSerializedState, WebSocketSession } from "@pluv/io";
|
|
2
|
+
import { WebSocket, WebSocket as WebSocket$1 } from "ws";
|
|
3
|
+
import { BaseUser, IOAuthorize, Id, InferIOAuthorizeUser, Json, JsonObject } from "@pluv/types";
|
|
4
|
+
import { IncomingMessage } from "node:http";
|
|
5
|
+
import { CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
7
6
|
|
|
7
|
+
//#region src/utils/identity.d.ts
|
|
8
8
|
declare const identity: <T extends unknown>(x: T) => T;
|
|
9
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/infer.d.ts
|
|
10
11
|
type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
|
|
11
|
-
|
|
12
|
+
meta?: (io: TMeta) => TMeta;
|
|
12
13
|
};
|
|
13
14
|
declare const infer: <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) => InferCallback<TMeta>;
|
|
14
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/NodeWebSocket.d.ts
|
|
15
17
|
type NodeWebSocketConfig = AbstractWebSocketConfig;
|
|
16
|
-
declare class NodeWebSocket<TAuthorize extends IOAuthorize<any, any> | null = null> extends AbstractWebSocket<WebSocket> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
declare class NodeWebSocket<TAuthorize extends IOAuthorize<any, any> | null = null> extends AbstractWebSocket<WebSocket$1> {
|
|
19
|
+
private _sessionId;
|
|
20
|
+
private _state;
|
|
21
|
+
private _user;
|
|
22
|
+
set presence(presence: JsonObject | null);
|
|
23
|
+
get readyState(): 0 | 1 | 2 | 3;
|
|
24
|
+
get session(): WebSocketSession<TAuthorize>;
|
|
25
|
+
get sessionId(): string;
|
|
26
|
+
get state(): WebSocketSerializedState;
|
|
27
|
+
set state(state: WebSocketSerializedState);
|
|
28
|
+
set user(user: InferIOAuthorizeUser<TAuthorize>);
|
|
29
|
+
constructor(webSocket: WebSocket$1, config: NodeWebSocketConfig);
|
|
30
|
+
addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
|
|
31
|
+
close(code?: number | undefined, reason?: string | undefined): void;
|
|
32
|
+
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
33
|
+
terminate(): void;
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/NodePlatform.d.ts
|
|
34
37
|
type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never ? {
|
|
35
|
-
|
|
38
|
+
meta?: undefined;
|
|
36
39
|
} : {
|
|
37
|
-
|
|
40
|
+
meta: TMeta;
|
|
38
41
|
};
|
|
39
42
|
type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
40
|
-
|
|
43
|
+
mode?: WebSocketRegistrationMode;
|
|
41
44
|
} & ({
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
persistence?: undefined;
|
|
46
|
+
pubSub?: undefined;
|
|
44
47
|
} | {
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
persistence: AbstractPersistence;
|
|
49
|
+
pubSub: AbstractPubSub;
|
|
47
50
|
}) & {
|
|
48
|
-
|
|
51
|
+
roomContext?: NodePlatformRoomContext<TMeta>;
|
|
49
52
|
};
|
|
50
53
|
declare class NodePlatform<TAuthorize extends IOAuthorize<any, any> | null = null, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket<TAuthorize>, {
|
|
51
|
-
|
|
54
|
+
req: IncomingMessage;
|
|
52
55
|
}, NodePlatformRoomContext<TMeta>, {
|
|
56
|
+
authorize: {
|
|
57
|
+
secret: true;
|
|
58
|
+
};
|
|
59
|
+
handleMode: "io";
|
|
60
|
+
requireAuth: false;
|
|
61
|
+
registrationMode: WebSocketRegistrationMode;
|
|
62
|
+
listeners: {
|
|
63
|
+
onRoomDestroyed: true;
|
|
64
|
+
onRoomMessage: true;
|
|
65
|
+
onStorageDestroyed: true;
|
|
66
|
+
onStorageUpdated: true;
|
|
67
|
+
onUserConnected: true;
|
|
68
|
+
onUserDisconnected: true;
|
|
69
|
+
};
|
|
70
|
+
router: true;
|
|
71
|
+
}> {
|
|
72
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
73
|
+
readonly _config: {
|
|
53
74
|
authorize: {
|
|
54
|
-
|
|
75
|
+
secret: true;
|
|
55
76
|
};
|
|
56
77
|
handleMode: "io";
|
|
57
|
-
requireAuth: false;
|
|
58
78
|
registrationMode: WebSocketRegistrationMode;
|
|
79
|
+
requireAuth: false;
|
|
59
80
|
listeners: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
onRoomDestroyed: true;
|
|
82
|
+
onRoomMessage: true;
|
|
83
|
+
onStorageDestroyed: true;
|
|
84
|
+
onStorageUpdated: true;
|
|
85
|
+
onUserConnected: true;
|
|
86
|
+
onUserDisconnected: true;
|
|
65
87
|
};
|
|
66
88
|
router: true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
onUserConnected: true;
|
|
81
|
-
onUserDisconnected: true;
|
|
82
|
-
};
|
|
83
|
-
router: true;
|
|
84
|
-
};
|
|
85
|
-
readonly _name = "platformNode";
|
|
86
|
-
constructor(config?: NodePlatformConfig<TMeta>);
|
|
87
|
-
acceptWebSocket(webSocket: NodeWebSocket<TAuthorize>): Promise<void>;
|
|
88
|
-
convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket<TAuthorize>;
|
|
89
|
-
getLastPing(webSocket: NodeWebSocket<TAuthorize>): number | null;
|
|
90
|
-
getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
|
|
91
|
-
getSessionId(webSocket: WebSocket): string | null;
|
|
92
|
-
getWebSockets(): readonly WebSocket[];
|
|
93
|
-
initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this;
|
|
94
|
-
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
95
|
-
randomUUID(): string;
|
|
96
|
-
setSerializedState(webSocket: NodeWebSocket<TAuthorize>, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
89
|
+
};
|
|
90
|
+
readonly _name = "platformNode";
|
|
91
|
+
constructor(config?: NodePlatformConfig<TMeta>);
|
|
92
|
+
acceptWebSocket(webSocket: NodeWebSocket<TAuthorize>): Promise<void>;
|
|
93
|
+
convertWebSocket(webSocket: WebSocket$1, config: ConvertWebSocketConfig): NodeWebSocket<TAuthorize>;
|
|
94
|
+
getLastPing(webSocket: NodeWebSocket<TAuthorize>): number | null;
|
|
95
|
+
getSerializedState(webSocket: WebSocket$1): WebSocketSerializedState | null;
|
|
96
|
+
getSessionId(webSocket: WebSocket$1): string | null;
|
|
97
|
+
getWebSockets(): readonly WebSocket$1[];
|
|
98
|
+
initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this;
|
|
99
|
+
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
100
|
+
randomUUID(): string;
|
|
101
|
+
setSerializedState(webSocket: NodeWebSocket<TAuthorize>, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
97
102
|
}
|
|
98
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/platformNode.d.ts
|
|
99
105
|
type PlatformNodeCreateIOParams<TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>> = Id<NodePlatformConfig<TMeta> & Omit<CreateIOParams<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TContext, TUser, TCrdt>, "authorize" | "context" | "platform"> & {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
authorize?: PluvIOAuthorize<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TUser, InferInitContextType<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>>>;
|
|
107
|
+
context?: PluvContext<NodePlatform<IOAuthorize<TUser, any>, TMeta>, TContext>;
|
|
108
|
+
types?: InferCallback<TMeta>;
|
|
103
109
|
}>;
|
|
104
110
|
declare const platformNode: <TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>>(config?: PlatformNodeCreateIOParams<TMeta, TContext, TUser, TCrdt>) => CreateIOParams<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TContext, TUser, TCrdt>;
|
|
105
|
-
|
|
106
|
-
export { type InferCallback, NodePlatform, type NodePlatformConfig, type PlatformNodeCreateIOParams, infer, platformNode };
|
|
111
|
+
//#endregion
|
|
112
|
+
export { type InferCallback, type NodePlatform, type NodePlatformConfig, type PlatformNodeCreateIOParams, type WebSocket, infer, platformNode };
|
|
113
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/identity.ts","../src/infer.ts","../src/NodeWebSocket.ts","../src/NodePlatform.ts","../src/platformNode.ts"],"mappings":"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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,228 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/infer.ts
|
|
42
|
-
var infer = (callback) => callback;
|
|
1
|
+
import { AbstractPlatform, AbstractWebSocket } from "@pluv/io";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import { TextDecoder } from "node:util";
|
|
43
4
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
import crypto2 from "crypto";
|
|
47
|
-
import { TextDecoder } from "util";
|
|
5
|
+
//#region src/infer.ts
|
|
6
|
+
const infer = (callback) => callback;
|
|
48
7
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import crypto from "crypto";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/NodeWebSocket.ts
|
|
52
10
|
var NodeWebSocket = class extends AbstractWebSocket {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
11
|
+
_sessionId = null;
|
|
12
|
+
_state;
|
|
13
|
+
_user = null;
|
|
14
|
+
set presence(presence) {
|
|
15
|
+
this._state.presence = presence;
|
|
16
|
+
}
|
|
17
|
+
get readyState() {
|
|
18
|
+
return this.webSocket.readyState;
|
|
19
|
+
}
|
|
20
|
+
get session() {
|
|
21
|
+
const sessionId = this.sessionId;
|
|
22
|
+
const state = this._state;
|
|
23
|
+
const user = this._user;
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
id: sessionId,
|
|
27
|
+
user,
|
|
28
|
+
webSocket: this
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
get sessionId() {
|
|
32
|
+
if (this._sessionId) return this._sessionId;
|
|
33
|
+
const sessionId = this._sessionId ?? `p_${crypto.randomUUID()}`;
|
|
34
|
+
this._sessionId = sessionId;
|
|
35
|
+
return sessionId;
|
|
36
|
+
}
|
|
37
|
+
get state() {
|
|
38
|
+
return this._state;
|
|
39
|
+
}
|
|
40
|
+
set state(state) {
|
|
41
|
+
this._state = state;
|
|
42
|
+
}
|
|
43
|
+
set user(user) {
|
|
44
|
+
this._user = user;
|
|
45
|
+
}
|
|
46
|
+
constructor(webSocket, config) {
|
|
47
|
+
const { room } = config;
|
|
48
|
+
super(webSocket, config);
|
|
49
|
+
this._state = {
|
|
50
|
+
presence: null,
|
|
51
|
+
quit: false,
|
|
52
|
+
room,
|
|
53
|
+
timers: {
|
|
54
|
+
ping: (/* @__PURE__ */ new Date()).getTime(),
|
|
55
|
+
presence: null
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
addEventListener(type, handler) {
|
|
60
|
+
switch (type) {
|
|
61
|
+
case "close":
|
|
62
|
+
this.webSocket.on("close", async (code, buffer) => {
|
|
63
|
+
const reason = buffer.toString("utf-8");
|
|
64
|
+
await Promise.resolve(handler({
|
|
65
|
+
code,
|
|
66
|
+
reason
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
case "error":
|
|
71
|
+
this.webSocket.on("error", async (error) => {
|
|
72
|
+
const message = error.message;
|
|
73
|
+
await Promise.resolve(handler({
|
|
74
|
+
error,
|
|
75
|
+
message
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
case "message":
|
|
80
|
+
this.webSocket.on("message", async (data) => {
|
|
81
|
+
await Promise.resolve(handler({ data }));
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
default:
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
close(code, reason) {
|
|
88
|
+
if (![this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState)) return;
|
|
89
|
+
this.webSocket.close(code, reason);
|
|
90
|
+
}
|
|
91
|
+
send(message) {
|
|
92
|
+
if (this.readyState !== this.OPEN) return;
|
|
93
|
+
this.webSocket.send(message, (error) => {
|
|
94
|
+
if (error) throw error;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
terminate() {
|
|
98
|
+
this.webSocket.terminate();
|
|
99
|
+
}
|
|
140
100
|
};
|
|
141
101
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/NodePlatform.ts
|
|
104
|
+
var NodePlatform = class NodePlatform extends AbstractPlatform {
|
|
105
|
+
id = crypto.randomUUID();
|
|
106
|
+
_config;
|
|
107
|
+
_name = "platformNode";
|
|
108
|
+
constructor(config = {}) {
|
|
109
|
+
const { roomContext, mode = "attached", persistence, pubSub } = config;
|
|
110
|
+
super({
|
|
111
|
+
roomContext,
|
|
112
|
+
...persistence && pubSub ? {
|
|
113
|
+
persistence,
|
|
114
|
+
pubSub
|
|
115
|
+
} : {}
|
|
116
|
+
});
|
|
117
|
+
this._config = {
|
|
118
|
+
authorize: { secret: true },
|
|
119
|
+
handleMode: "io",
|
|
120
|
+
registrationMode: mode,
|
|
121
|
+
requireAuth: false,
|
|
122
|
+
listeners: {
|
|
123
|
+
onRoomDestroyed: true,
|
|
124
|
+
onRoomMessage: true,
|
|
125
|
+
onStorageDestroyed: true,
|
|
126
|
+
onStorageUpdated: true,
|
|
127
|
+
onUserConnected: true,
|
|
128
|
+
onUserDisconnected: true
|
|
129
|
+
},
|
|
130
|
+
router: true
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
acceptWebSocket(webSocket) {
|
|
134
|
+
return Promise.resolve(void 0);
|
|
135
|
+
}
|
|
136
|
+
convertWebSocket(webSocket, config) {
|
|
137
|
+
const { room } = config;
|
|
138
|
+
return new NodeWebSocket(webSocket, {
|
|
139
|
+
persistence: this.persistence,
|
|
140
|
+
platform: this,
|
|
141
|
+
room
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
getLastPing(webSocket) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
getSerializedState(webSocket) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
getSessionId(webSocket) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
getWebSockets() {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
initialize(config) {
|
|
157
|
+
return new NodePlatform({
|
|
158
|
+
roomContext: config.roomContext,
|
|
159
|
+
mode: this._config.registrationMode,
|
|
160
|
+
persistence: this.persistence.initialize(config.roomContext),
|
|
161
|
+
pubSub: this.pubSub
|
|
162
|
+
})._initialize();
|
|
163
|
+
}
|
|
164
|
+
parseData(data) {
|
|
165
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
166
|
+
const decoder = new TextDecoder("utf8");
|
|
167
|
+
return JSON.parse(decoder.decode(data));
|
|
168
|
+
}
|
|
169
|
+
randomUUID() {
|
|
170
|
+
return crypto.randomUUID();
|
|
171
|
+
}
|
|
172
|
+
setSerializedState(webSocket, state) {
|
|
173
|
+
webSocket.state = state;
|
|
174
|
+
return webSocket.state;
|
|
175
|
+
}
|
|
211
176
|
};
|
|
212
177
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
};
|
|
225
|
-
export {
|
|
226
|
-
infer,
|
|
227
|
-
platformNode
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/platformNode.ts
|
|
180
|
+
const platformNode = (config = {}) => {
|
|
181
|
+
const { authorize, context, crdt, debug, limits } = config;
|
|
182
|
+
return {
|
|
183
|
+
authorize,
|
|
184
|
+
context,
|
|
185
|
+
crdt,
|
|
186
|
+
debug,
|
|
187
|
+
limits,
|
|
188
|
+
platform: () => new NodePlatform(config)
|
|
189
|
+
};
|
|
228
190
|
};
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { infer, platformNode };
|
|
194
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/infer.ts","../src/NodeWebSocket.ts","../src/NodePlatform.ts","../src/platformNode.ts"],"sourcesContent":["import type { Json } from \"@pluv/types\";\nimport type { identity } from \"./utils\";\n\nexport type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {\n meta?: (io: TMeta) => TMeta;\n};\n\nexport const infer = <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) =>\n callback;\n","import type {\n AbstractCloseEvent,\n AbstractErrorEvent,\n AbstractEventMap,\n AbstractListener,\n AbstractMessageEvent,\n AbstractWebSocketConfig,\n WebSocketSerializedState,\n WebSocketSession,\n} from \"@pluv/io\";\nimport { AbstractWebSocket } from \"@pluv/io\";\nimport type { InferIOAuthorizeUser, IOAuthorize, JsonObject } from \"@pluv/types\";\nimport crypto from \"node:crypto\";\nimport type { WebSocket } from \"ws\";\n\nexport interface NodeWebSocketEventMap {\n close: AbstractCloseEvent;\n message: AbstractMessageEvent;\n error: AbstractErrorEvent;\n}\n\nexport type NodeWebSocketConfig = AbstractWebSocketConfig;\n\nexport class NodeWebSocket<\n TAuthorize extends IOAuthorize<any, any> | null = null,\n> extends AbstractWebSocket<WebSocket> {\n private _sessionId: string | null = null;\n private _state: WebSocketSerializedState;\n private _user: InferIOAuthorizeUser<TAuthorize> = null as InferIOAuthorizeUser<TAuthorize>;\n\n public set presence(presence: JsonObject | null) {\n this._state.presence = presence;\n }\n\n public get readyState(): 0 | 1 | 2 | 3 {\n return this.webSocket.readyState;\n }\n\n public get session(): WebSocketSession<TAuthorize> {\n const sessionId = this.sessionId;\n const state = this._state;\n const user = this._user;\n\n return {\n ...state,\n id: sessionId,\n user,\n webSocket: this,\n };\n }\n\n public get sessionId(): string {\n if (this._sessionId) return this._sessionId;\n\n const sessionId = this._sessionId ?? `p_${crypto.randomUUID()}`;\n\n this._sessionId = sessionId;\n\n return sessionId;\n }\n\n public get state(): WebSocketSerializedState {\n return this._state;\n }\n\n public set state(state: WebSocketSerializedState) {\n this._state = state;\n }\n\n public set user(user: InferIOAuthorizeUser<TAuthorize>) {\n this._user = user;\n }\n\n constructor(webSocket: WebSocket, config: NodeWebSocketConfig) {\n const { room } = config;\n\n super(webSocket, config);\n\n this._state = {\n presence: null,\n quit: false,\n room,\n timers: {\n ping: new Date().getTime(),\n presence: null,\n },\n };\n }\n\n public addEventListener<TType extends keyof AbstractEventMap>(\n type: TType,\n handler: AbstractListener<TType>,\n ): void {\n switch (type) {\n case \"close\":\n this.webSocket.on(\"close\", async (code, buffer) => {\n const reason = buffer.toString(\"utf-8\");\n\n await Promise.resolve((handler as AbstractListener<\"close\">)({ code, reason }));\n });\n\n return;\n case \"error\":\n this.webSocket.on(\"error\", async (error) => {\n const message = error.message;\n\n await Promise.resolve(\n (handler as AbstractListener<\"error\">)({ error, message }),\n );\n });\n\n return;\n case \"message\":\n this.webSocket.on(\"message\", async (data) => {\n await Promise.resolve((handler as AbstractListener<\"message\">)({ data }));\n });\n\n return;\n default:\n }\n }\n\n public close(code?: number | undefined, reason?: string | undefined): void {\n const canClose = [this.CONNECTING, this.OPEN].some(\n (readyState) => readyState === this.readyState,\n );\n\n if (!canClose) return;\n\n this.webSocket.close(code, reason);\n }\n\n public send(message: string | ArrayBuffer | ArrayBufferView): void {\n if (this.readyState !== this.OPEN) return;\n\n this.webSocket.send(message, (error) => {\n if (error) throw error;\n });\n }\n\n public terminate(): void {\n this.webSocket.terminate();\n }\n}\n","import type {\n AbstractPersistence,\n AbstractPlatformConfig,\n AbstractPubSub,\n ConvertWebSocketConfig,\n WebSocketRegistrationMode,\n WebSocketSerializedState,\n} from \"@pluv/io\";\nimport { AbstractPlatform } from \"@pluv/io\";\nimport type { IOAuthorize, Json } from \"@pluv/types\";\nimport crypto from \"node:crypto\";\nimport type { IncomingMessage } from \"node:http\";\nimport { TextDecoder } from \"node:util\";\nimport type { WebSocket } from \"ws\";\nimport { NodeWebSocket } from \"./NodeWebSocket\";\n\nexport type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never\n ? { meta?: undefined }\n : { meta: TMeta };\n\nexport type NodePlatformConfig<TMeta extends Record<string, Json>> = {\n mode?: WebSocketRegistrationMode;\n} & (\n | { persistence?: undefined; pubSub?: undefined }\n | { persistence: AbstractPersistence; pubSub: AbstractPubSub }\n) & { roomContext?: NodePlatformRoomContext<TMeta> };\n\nexport class NodePlatform<\n TAuthorize extends IOAuthorize<any, any> | null = null,\n TMeta extends Record<string, Json> = {},\n> extends AbstractPlatform<\n NodeWebSocket<TAuthorize>,\n { req: IncomingMessage },\n NodePlatformRoomContext<TMeta>,\n {\n authorize: {\n secret: true;\n };\n handleMode: \"io\";\n requireAuth: false;\n registrationMode: WebSocketRegistrationMode;\n listeners: {\n onRoomDestroyed: true;\n onRoomMessage: true;\n onStorageDestroyed: true;\n onStorageUpdated: true;\n onUserConnected: true;\n onUserDisconnected: true;\n };\n router: true;\n }\n> {\n public readonly id = crypto.randomUUID();\n public readonly _config;\n public readonly _name = \"platformNode\";\n\n constructor(config: NodePlatformConfig<TMeta> = {}) {\n const { roomContext, mode = \"attached\", persistence, pubSub } = config;\n\n super({\n roomContext,\n ...(persistence && pubSub ? { persistence, pubSub } : {}),\n });\n\n this._config = {\n authorize: {\n secret: true as const,\n },\n handleMode: \"io\" as const,\n registrationMode: mode,\n requireAuth: false as const,\n listeners: {\n onRoomDestroyed: true as const,\n onRoomMessage: true as const,\n onStorageDestroyed: true as const,\n onStorageUpdated: true as const,\n onUserConnected: true as const,\n onUserDisconnected: true as const,\n },\n router: true as const,\n };\n }\n\n public acceptWebSocket(webSocket: NodeWebSocket<TAuthorize>): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n public convertWebSocket(\n webSocket: WebSocket,\n config: ConvertWebSocketConfig,\n ): NodeWebSocket<TAuthorize> {\n const { room } = config;\n\n return new NodeWebSocket<TAuthorize>(webSocket, {\n persistence: this.persistence,\n platform: this,\n room,\n });\n }\n\n public getLastPing(webSocket: NodeWebSocket<TAuthorize>): number | null {\n return null;\n }\n\n public getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null {\n return null;\n }\n\n public getSessionId(webSocket: WebSocket): string | null {\n return null;\n }\n\n public getWebSockets(): readonly WebSocket[] {\n return [];\n }\n\n public initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this {\n return new NodePlatform({\n roomContext: config.roomContext,\n mode: this._config.registrationMode,\n persistence: this.persistence.initialize(config.roomContext),\n pubSub: this.pubSub,\n } as NodePlatformConfig<TMeta>)._initialize() as this;\n }\n\n public parseData(data: string | ArrayBuffer): Record<string, any> {\n if (typeof data === \"string\") return JSON.parse(data);\n\n const decoder = new TextDecoder(\"utf8\");\n\n return JSON.parse(decoder.decode(data));\n }\n\n public randomUUID(): string {\n return crypto.randomUUID();\n }\n\n public setSerializedState(\n webSocket: NodeWebSocket<TAuthorize>,\n state: WebSocketSerializedState,\n ): WebSocketSerializedState {\n webSocket.state = state;\n\n return webSocket.state;\n }\n}\n","import type { CrdtLibraryType, NoopCrdtDocFactory } from \"@pluv/crdt\";\nimport type { CreateIOParams, InferInitContextType, PluvContext, PluvIOAuthorize } from \"@pluv/io\";\nimport type { BaseUser, Id, IOAuthorize, Json } from \"@pluv/types\";\nimport type { NodePlatformConfig } from \"./NodePlatform\";\nimport { NodePlatform } from \"./NodePlatform\";\nimport type { InferCallback } from \"./infer\";\n\nexport type PlatformNodeCreateIOParams<\n TMeta extends Record<string, Json> = {},\n TContext extends Record<string, any> = {},\n TUser extends BaseUser | null = null,\n TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,\n> = Id<\n NodePlatformConfig<TMeta> &\n Omit<\n CreateIOParams<\n NodePlatform<IOAuthorize<TUser, TContext>, TMeta>,\n TContext,\n TUser,\n TCrdt\n >,\n \"authorize\" | \"context\" | \"platform\"\n > & {\n authorize?: PluvIOAuthorize<\n NodePlatform<IOAuthorize<TUser, TContext>, TMeta>,\n TUser,\n InferInitContextType<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>>\n >;\n context?: PluvContext<NodePlatform<IOAuthorize<TUser, any>, TMeta>, TContext>;\n types?: InferCallback<TMeta>;\n }\n>;\n\nexport const platformNode = <\n TMeta extends Record<string, Json> = {},\n TContext extends Record<string, any> = {},\n TUser extends BaseUser | null = null,\n TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,\n>(\n config: PlatformNodeCreateIOParams<TMeta, TContext, TUser, TCrdt> = {},\n): CreateIOParams<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TContext, TUser, TCrdt> => {\n const { authorize, context, crdt, debug, limits } = config;\n\n return {\n authorize,\n context,\n crdt,\n debug,\n limits,\n platform: () => new NodePlatform<IOAuthorize<TUser, TContext>, TMeta>(config),\n };\n};\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "@pluv/io adapter for node.js",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "david@pluv.io",
|
|
@@ -14,35 +14,39 @@
|
|
|
14
14
|
"url": "git+https://github.com/pluv-io/pluv.git",
|
|
15
15
|
"directory": "packages/platform-node"
|
|
16
16
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
20
19
|
"publishConfig": {
|
|
21
20
|
"access": "public"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@types/node": "^
|
|
23
|
+
"@types/node": "^25.0.9",
|
|
25
24
|
"@types/ws": "^8.18.1",
|
|
26
|
-
"path-to-regexp": "^8.
|
|
27
|
-
"@pluv/
|
|
28
|
-
"@pluv/types": "^
|
|
29
|
-
"@pluv/
|
|
25
|
+
"path-to-regexp": "^8.3.0",
|
|
26
|
+
"@pluv/crdt": "^4.0.0",
|
|
27
|
+
"@pluv/types": "^4.0.0",
|
|
28
|
+
"@pluv/io": "^4.0.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"
|
|
34
|
-
"typescript": "^5.
|
|
35
|
-
"ws": "^8.
|
|
36
|
-
"@pluv/tsconfig": "^
|
|
37
|
-
"eslint-config-pluv": "^
|
|
31
|
+
"eslint": "^9.39.2",
|
|
32
|
+
"tsdown": "0.20.0-beta.4",
|
|
33
|
+
"typescript": "^5.9.3",
|
|
34
|
+
"ws": "^8.19.0",
|
|
35
|
+
"@pluv/tsconfig": "^4.0.0",
|
|
36
|
+
"eslint-config-pluv": "^4.0.0"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
40
39
|
"ws": "^8.0.0"
|
|
41
40
|
},
|
|
41
|
+
"exports": {
|
|
42
|
+
".": "./dist/index.mjs",
|
|
43
|
+
"./*": "./*"
|
|
44
|
+
},
|
|
42
45
|
"scripts": {
|
|
43
|
-
"build": "
|
|
44
|
-
"dev": "
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"dev": "tsdown --watch",
|
|
45
48
|
"lint": "eslint \"src/**/*.ts*\" --fix --max-warnings 0",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
46
50
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
47
51
|
}
|
|
48
52
|
}
|
package/src/NodePlatform.ts
CHANGED
|
@@ -40,8 +40,9 @@ export class NodePlatform<
|
|
|
40
40
|
requireAuth: false;
|
|
41
41
|
registrationMode: WebSocketRegistrationMode;
|
|
42
42
|
listeners: {
|
|
43
|
-
|
|
43
|
+
onRoomDestroyed: true;
|
|
44
44
|
onRoomMessage: true;
|
|
45
|
+
onStorageDestroyed: true;
|
|
45
46
|
onStorageUpdated: true;
|
|
46
47
|
onUserConnected: true;
|
|
47
48
|
onUserDisconnected: true;
|
|
@@ -69,8 +70,9 @@ export class NodePlatform<
|
|
|
69
70
|
registrationMode: mode,
|
|
70
71
|
requireAuth: false as const,
|
|
71
72
|
listeners: {
|
|
72
|
-
|
|
73
|
+
onRoomDestroyed: true as const,
|
|
73
74
|
onRoomMessage: true as const,
|
|
75
|
+
onStorageDestroyed: true as const,
|
|
74
76
|
onStorageUpdated: true as const,
|
|
75
77
|
onUserConnected: true as const,
|
|
76
78
|
onUserDisconnected: true as const,
|
package/tsdown.config.ts
ADDED
package/dist/index.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
export { WebSocket } from 'ws';
|
|
3
|
-
import { Json, IOAuthorize, JsonObject, InferIOAuthorizeUser, BaseUser, Id } from '@pluv/types';
|
|
4
|
-
import { AbstractWebSocket, WebSocketSession, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, ConvertWebSocketConfig, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
|
|
5
|
-
import { IncomingMessage } from 'node:http';
|
|
6
|
-
import { CrdtLibraryType, NoopCrdtDocFactory } from '@pluv/crdt';
|
|
7
|
-
|
|
8
|
-
declare const identity: <T extends unknown>(x: T) => T;
|
|
9
|
-
|
|
10
|
-
type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
|
|
11
|
-
meta?: (io: TMeta) => TMeta;
|
|
12
|
-
};
|
|
13
|
-
declare const infer: <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) => InferCallback<TMeta>;
|
|
14
|
-
|
|
15
|
-
type NodeWebSocketConfig = AbstractWebSocketConfig;
|
|
16
|
-
declare class NodeWebSocket<TAuthorize extends IOAuthorize<any, any> | null = null> extends AbstractWebSocket<WebSocket> {
|
|
17
|
-
private _sessionId;
|
|
18
|
-
private _state;
|
|
19
|
-
private _user;
|
|
20
|
-
set presence(presence: JsonObject | null);
|
|
21
|
-
get readyState(): 0 | 1 | 2 | 3;
|
|
22
|
-
get session(): WebSocketSession<TAuthorize>;
|
|
23
|
-
get sessionId(): string;
|
|
24
|
-
get state(): WebSocketSerializedState;
|
|
25
|
-
set state(state: WebSocketSerializedState);
|
|
26
|
-
set user(user: InferIOAuthorizeUser<TAuthorize>);
|
|
27
|
-
constructor(webSocket: WebSocket, config: NodeWebSocketConfig);
|
|
28
|
-
addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
|
|
29
|
-
close(code?: number | undefined, reason?: string | undefined): void;
|
|
30
|
-
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
31
|
-
terminate(): void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof TMeta extends never ? {
|
|
35
|
-
meta?: undefined;
|
|
36
|
-
} : {
|
|
37
|
-
meta: TMeta;
|
|
38
|
-
};
|
|
39
|
-
type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
40
|
-
mode?: WebSocketRegistrationMode;
|
|
41
|
-
} & ({
|
|
42
|
-
persistence?: undefined;
|
|
43
|
-
pubSub?: undefined;
|
|
44
|
-
} | {
|
|
45
|
-
persistence: AbstractPersistence;
|
|
46
|
-
pubSub: AbstractPubSub;
|
|
47
|
-
}) & {
|
|
48
|
-
roomContext?: NodePlatformRoomContext<TMeta>;
|
|
49
|
-
};
|
|
50
|
-
declare class NodePlatform<TAuthorize extends IOAuthorize<any, any> | null = null, TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket<TAuthorize>, {
|
|
51
|
-
req: IncomingMessage;
|
|
52
|
-
}, NodePlatformRoomContext<TMeta>, {
|
|
53
|
-
authorize: {
|
|
54
|
-
secret: true;
|
|
55
|
-
};
|
|
56
|
-
handleMode: "io";
|
|
57
|
-
requireAuth: false;
|
|
58
|
-
registrationMode: WebSocketRegistrationMode;
|
|
59
|
-
listeners: {
|
|
60
|
-
onRoomDeleted: true;
|
|
61
|
-
onRoomMessage: true;
|
|
62
|
-
onStorageUpdated: true;
|
|
63
|
-
onUserConnected: true;
|
|
64
|
-
onUserDisconnected: true;
|
|
65
|
-
};
|
|
66
|
-
router: true;
|
|
67
|
-
}> {
|
|
68
|
-
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
69
|
-
readonly _config: {
|
|
70
|
-
authorize: {
|
|
71
|
-
secret: true;
|
|
72
|
-
};
|
|
73
|
-
handleMode: "io";
|
|
74
|
-
registrationMode: WebSocketRegistrationMode;
|
|
75
|
-
requireAuth: false;
|
|
76
|
-
listeners: {
|
|
77
|
-
onRoomDeleted: true;
|
|
78
|
-
onRoomMessage: true;
|
|
79
|
-
onStorageUpdated: true;
|
|
80
|
-
onUserConnected: true;
|
|
81
|
-
onUserDisconnected: true;
|
|
82
|
-
};
|
|
83
|
-
router: true;
|
|
84
|
-
};
|
|
85
|
-
readonly _name = "platformNode";
|
|
86
|
-
constructor(config?: NodePlatformConfig<TMeta>);
|
|
87
|
-
acceptWebSocket(webSocket: NodeWebSocket<TAuthorize>): Promise<void>;
|
|
88
|
-
convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket<TAuthorize>;
|
|
89
|
-
getLastPing(webSocket: NodeWebSocket<TAuthorize>): number | null;
|
|
90
|
-
getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
|
|
91
|
-
getSessionId(webSocket: WebSocket): string | null;
|
|
92
|
-
getWebSockets(): readonly WebSocket[];
|
|
93
|
-
initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this;
|
|
94
|
-
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
95
|
-
randomUUID(): string;
|
|
96
|
-
setSerializedState(webSocket: NodeWebSocket<TAuthorize>, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
type PlatformNodeCreateIOParams<TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>> = Id<NodePlatformConfig<TMeta> & Omit<CreateIOParams<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TContext, TUser, TCrdt>, "authorize" | "context" | "platform"> & {
|
|
100
|
-
authorize?: PluvIOAuthorize<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TUser, InferInitContextType<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>>>;
|
|
101
|
-
context?: PluvContext<NodePlatform<IOAuthorize<TUser, any>, TMeta>, TContext>;
|
|
102
|
-
types?: InferCallback<TMeta>;
|
|
103
|
-
}>;
|
|
104
|
-
declare const platformNode: <TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>>(config?: PlatformNodeCreateIOParams<TMeta, TContext, TUser, TCrdt>) => CreateIOParams<NodePlatform<IOAuthorize<TUser, TContext>, TMeta>, TContext, TUser, TCrdt>;
|
|
105
|
-
|
|
106
|
-
export { type InferCallback, NodePlatform, type NodePlatformConfig, type PlatformNodeCreateIOParams, infer, platformNode };
|
package/dist/index.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __export = (target, all) => {
|
|
26
|
-
for (var name in all)
|
|
27
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
-
};
|
|
29
|
-
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (let key of __getOwnPropNames(from))
|
|
32
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
-
}
|
|
35
|
-
return to;
|
|
36
|
-
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __async = (__this, __arguments, generator) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
var fulfilled = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
step(generator.next(value));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var rejected = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.throw(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/index.ts
|
|
68
|
-
var index_exports = {};
|
|
69
|
-
__export(index_exports, {
|
|
70
|
-
infer: () => infer,
|
|
71
|
-
platformNode: () => platformNode
|
|
72
|
-
});
|
|
73
|
-
module.exports = __toCommonJS(index_exports);
|
|
74
|
-
|
|
75
|
-
// src/infer.ts
|
|
76
|
-
var infer = (callback) => callback;
|
|
77
|
-
|
|
78
|
-
// src/NodePlatform.ts
|
|
79
|
-
var import_io2 = require("@pluv/io");
|
|
80
|
-
var import_node_crypto2 = __toESM(require("crypto"));
|
|
81
|
-
var import_node_util = require("util");
|
|
82
|
-
|
|
83
|
-
// src/NodeWebSocket.ts
|
|
84
|
-
var import_io = require("@pluv/io");
|
|
85
|
-
var import_node_crypto = __toESM(require("crypto"));
|
|
86
|
-
var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
87
|
-
constructor(webSocket, config) {
|
|
88
|
-
const { room } = config;
|
|
89
|
-
super(webSocket, config);
|
|
90
|
-
this._sessionId = null;
|
|
91
|
-
this._user = null;
|
|
92
|
-
this._state = {
|
|
93
|
-
presence: null,
|
|
94
|
-
quit: false,
|
|
95
|
-
room,
|
|
96
|
-
timers: {
|
|
97
|
-
ping: (/* @__PURE__ */ new Date()).getTime(),
|
|
98
|
-
presence: null
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
set presence(presence) {
|
|
103
|
-
this._state.presence = presence;
|
|
104
|
-
}
|
|
105
|
-
get readyState() {
|
|
106
|
-
return this.webSocket.readyState;
|
|
107
|
-
}
|
|
108
|
-
get session() {
|
|
109
|
-
const sessionId = this.sessionId;
|
|
110
|
-
const state = this._state;
|
|
111
|
-
const user = this._user;
|
|
112
|
-
return __spreadProps(__spreadValues({}, state), {
|
|
113
|
-
id: sessionId,
|
|
114
|
-
user,
|
|
115
|
-
webSocket: this
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
get sessionId() {
|
|
119
|
-
var _a;
|
|
120
|
-
if (this._sessionId) return this._sessionId;
|
|
121
|
-
const sessionId = (_a = this._sessionId) != null ? _a : `p_${import_node_crypto.default.randomUUID()}`;
|
|
122
|
-
this._sessionId = sessionId;
|
|
123
|
-
return sessionId;
|
|
124
|
-
}
|
|
125
|
-
get state() {
|
|
126
|
-
return this._state;
|
|
127
|
-
}
|
|
128
|
-
set state(state) {
|
|
129
|
-
this._state = state;
|
|
130
|
-
}
|
|
131
|
-
set user(user) {
|
|
132
|
-
this._user = user;
|
|
133
|
-
}
|
|
134
|
-
addEventListener(type, handler) {
|
|
135
|
-
switch (type) {
|
|
136
|
-
case "close":
|
|
137
|
-
this.webSocket.on("close", (code, buffer) => __async(this, null, function* () {
|
|
138
|
-
const reason = buffer.toString("utf-8");
|
|
139
|
-
yield Promise.resolve(handler({ code, reason }));
|
|
140
|
-
}));
|
|
141
|
-
return;
|
|
142
|
-
case "error":
|
|
143
|
-
this.webSocket.on("error", (error) => __async(this, null, function* () {
|
|
144
|
-
const message = error.message;
|
|
145
|
-
yield Promise.resolve(
|
|
146
|
-
handler({ error, message })
|
|
147
|
-
);
|
|
148
|
-
}));
|
|
149
|
-
return;
|
|
150
|
-
case "message":
|
|
151
|
-
this.webSocket.on("message", (data) => __async(this, null, function* () {
|
|
152
|
-
yield Promise.resolve(handler({ data }));
|
|
153
|
-
}));
|
|
154
|
-
return;
|
|
155
|
-
default:
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
close(code, reason) {
|
|
159
|
-
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
160
|
-
(readyState) => readyState === this.readyState
|
|
161
|
-
);
|
|
162
|
-
if (!canClose) return;
|
|
163
|
-
this.webSocket.close(code, reason);
|
|
164
|
-
}
|
|
165
|
-
send(message) {
|
|
166
|
-
if (this.readyState !== this.OPEN) return;
|
|
167
|
-
this.webSocket.send(message, (error) => {
|
|
168
|
-
if (error) throw error;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
terminate() {
|
|
172
|
-
this.webSocket.terminate();
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// src/NodePlatform.ts
|
|
177
|
-
var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
178
|
-
constructor(config = {}) {
|
|
179
|
-
const { roomContext, mode = "attached", persistence, pubSub } = config;
|
|
180
|
-
super(__spreadValues({
|
|
181
|
-
roomContext
|
|
182
|
-
}, persistence && pubSub ? { persistence, pubSub } : {}));
|
|
183
|
-
this.id = import_node_crypto2.default.randomUUID();
|
|
184
|
-
this._name = "platformNode";
|
|
185
|
-
this._config = {
|
|
186
|
-
authorize: {
|
|
187
|
-
secret: true
|
|
188
|
-
},
|
|
189
|
-
handleMode: "io",
|
|
190
|
-
registrationMode: mode,
|
|
191
|
-
requireAuth: false,
|
|
192
|
-
listeners: {
|
|
193
|
-
onRoomDeleted: true,
|
|
194
|
-
onRoomMessage: true,
|
|
195
|
-
onStorageUpdated: true,
|
|
196
|
-
onUserConnected: true,
|
|
197
|
-
onUserDisconnected: true
|
|
198
|
-
},
|
|
199
|
-
router: true
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
acceptWebSocket(webSocket) {
|
|
203
|
-
return Promise.resolve(void 0);
|
|
204
|
-
}
|
|
205
|
-
convertWebSocket(webSocket, config) {
|
|
206
|
-
const { room } = config;
|
|
207
|
-
return new NodeWebSocket(webSocket, {
|
|
208
|
-
persistence: this.persistence,
|
|
209
|
-
platform: this,
|
|
210
|
-
room
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
getLastPing(webSocket) {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
getSerializedState(webSocket) {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
getSessionId(webSocket) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
getWebSockets() {
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
initialize(config) {
|
|
226
|
-
return new _NodePlatform({
|
|
227
|
-
roomContext: config.roomContext,
|
|
228
|
-
mode: this._config.registrationMode,
|
|
229
|
-
persistence: this.persistence.initialize(config.roomContext),
|
|
230
|
-
pubSub: this.pubSub
|
|
231
|
-
})._initialize();
|
|
232
|
-
}
|
|
233
|
-
parseData(data) {
|
|
234
|
-
if (typeof data === "string") return JSON.parse(data);
|
|
235
|
-
const decoder = new import_node_util.TextDecoder("utf8");
|
|
236
|
-
return JSON.parse(decoder.decode(data));
|
|
237
|
-
}
|
|
238
|
-
randomUUID() {
|
|
239
|
-
return import_node_crypto2.default.randomUUID();
|
|
240
|
-
}
|
|
241
|
-
setSerializedState(webSocket, state) {
|
|
242
|
-
webSocket.state = state;
|
|
243
|
-
return webSocket.state;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// src/platformNode.ts
|
|
248
|
-
var platformNode = (config = {}) => {
|
|
249
|
-
const { authorize, context, crdt, debug, limits } = config;
|
|
250
|
-
return {
|
|
251
|
-
authorize,
|
|
252
|
-
context,
|
|
253
|
-
crdt,
|
|
254
|
-
debug,
|
|
255
|
-
limits,
|
|
256
|
-
platform: () => new NodePlatform(config)
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
260
|
-
0 && (module.exports = {
|
|
261
|
-
infer,
|
|
262
|
-
platformNode
|
|
263
|
-
});
|