@pluv/platform-node 0.36.0 → 0.37.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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +66 -0
- package/dist/index.d.mts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +18 -5
- package/dist/index.mjs +17 -5
- package/package.json +7 -7
- package/src/NodePlatform.ts +6 -4
- package/src/index.ts +3 -0
- package/src/infer.ts +8 -0
- package/src/platformNode.ts +32 -5
- package/src/utils/identity.ts +1 -0
- package/src/utils/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-node@0.
|
|
2
|
+
> @pluv/platform-node@0.37.1 build /home/runner/work/pluv/pluv/packages/platform-node
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[32m10.
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m8.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m10.50 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 88ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m8.72 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 89ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5723ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m5.89 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.89 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @pluv/platform-node
|
|
2
2
|
|
|
3
|
+
## 0.37.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/io@0.37.1
|
|
8
|
+
- @pluv/types@0.37.1
|
|
9
|
+
|
|
10
|
+
## 0.37.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 5165be0: **BREAKING**
|
|
15
|
+
|
|
16
|
+
Updated the `platformNode` function to return an entire `createIO` input object. Now `createIO` must be called with `platformNode`'s return value as an input.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// Before
|
|
20
|
+
|
|
21
|
+
import { createIO } from "@pluv/io";
|
|
22
|
+
import { platformNode } from "@pluv/platform-node";
|
|
23
|
+
|
|
24
|
+
export const io = createIO({
|
|
25
|
+
authorize: {
|
|
26
|
+
// ...
|
|
27
|
+
},
|
|
28
|
+
context: {
|
|
29
|
+
// ...
|
|
30
|
+
},
|
|
31
|
+
platform: platformNode<Meta>({
|
|
32
|
+
// ...
|
|
33
|
+
}),
|
|
34
|
+
// ...
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// After
|
|
38
|
+
|
|
39
|
+
import { createIO } from "@pluv/io";
|
|
40
|
+
import { infer, platformNode } from "@pluv/platform-node";
|
|
41
|
+
|
|
42
|
+
// Types must now be inferred like so, due to TypeScript limitations around partial inferences
|
|
43
|
+
// Note that this types variable is defined outside of the `createIO` function
|
|
44
|
+
const types = infer((i) => ({
|
|
45
|
+
meta: i<Meta>,
|
|
46
|
+
}));
|
|
47
|
+
export const io = createIO(
|
|
48
|
+
platformNode({
|
|
49
|
+
authorize: {
|
|
50
|
+
// ...
|
|
51
|
+
},
|
|
52
|
+
context: {
|
|
53
|
+
// ...
|
|
54
|
+
},
|
|
55
|
+
// Optional: Pass inferred types here
|
|
56
|
+
types,
|
|
57
|
+
// ...
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- 9b74abb: Improved type inference when calling `PluvIO.server` to not include options that are always undefined (i.e. are not allowed by the specified platform).
|
|
65
|
+
- Updated dependencies [9b74abb]
|
|
66
|
+
- @pluv/io@0.37.0
|
|
67
|
+
- @pluv/types@0.37.0
|
|
68
|
+
|
|
3
69
|
## 0.36.0
|
|
4
70
|
|
|
5
71
|
### 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
|
-
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
4
|
-
import { JsonObject, Json, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, MaybePromise, Maybe } from '@pluv/types';
|
|
3
|
+
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType, CreateIOParams, PluvIOAuthorize, PluvContext } from '@pluv/io';
|
|
4
|
+
import { JsonObject, Json, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, MaybePromise, Maybe, Id } from '@pluv/types';
|
|
5
5
|
import { IncomingMessage, Server, ServerResponse } from 'node:http';
|
|
6
6
|
|
|
7
7
|
type NodeWebSocketConfig = AbstractWebSocketConfig;
|
|
@@ -34,7 +34,7 @@ type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
|
34
34
|
persistence: AbstractPersistence;
|
|
35
35
|
pubSub: AbstractPubSub;
|
|
36
36
|
}) & {
|
|
37
|
-
|
|
37
|
+
roomContext?: NodePlatformRoomContext<TMeta>;
|
|
38
38
|
};
|
|
39
39
|
declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket, {
|
|
40
40
|
req: IncomingMessage;
|
|
@@ -52,6 +52,7 @@ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abst
|
|
|
52
52
|
onUserConnected: true;
|
|
53
53
|
onUserDisconnected: true;
|
|
54
54
|
};
|
|
55
|
+
router: true;
|
|
55
56
|
}> {
|
|
56
57
|
readonly _config: {
|
|
57
58
|
authorize: {
|
|
@@ -67,6 +68,7 @@ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abst
|
|
|
67
68
|
onUserConnected: true;
|
|
68
69
|
onUserDisconnected: true;
|
|
69
70
|
};
|
|
71
|
+
router: true;
|
|
70
72
|
};
|
|
71
73
|
readonly _name = "platformNode";
|
|
72
74
|
constructor(config?: NodePlatformConfig<TMeta>);
|
|
@@ -107,6 +109,18 @@ interface CreatePluvHandlerResult {
|
|
|
107
109
|
}
|
|
108
110
|
declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
|
|
109
111
|
|
|
110
|
-
declare const
|
|
112
|
+
declare const identity: <T extends unknown>(x: T) => T;
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
|
|
115
|
+
meta?: (io: TMeta) => TMeta;
|
|
116
|
+
};
|
|
117
|
+
declare const infer: <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) => InferCallback<TMeta>;
|
|
118
|
+
|
|
119
|
+
type PlatformNodeCreateIOParams<TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = Id<NodePlatformConfig<TMeta> & Omit<CreateIOParams<NodePlatform<TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
|
|
120
|
+
authorize?: PluvIOAuthorize<NodePlatform<TMeta>, TUser, InferInitContextType<NodePlatform<TMeta>>>;
|
|
121
|
+
context?: PluvContext<NodePlatform<TMeta>, TContext>;
|
|
122
|
+
types?: InferCallback<TMeta>;
|
|
123
|
+
}>;
|
|
124
|
+
declare const platformNode: <TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(config?: PlatformNodeCreateIOParams<TMeta, TContext, TUser>) => CreateIOParams<NodePlatform<TMeta>, TContext, TUser>;
|
|
125
|
+
|
|
126
|
+
export { type AuthorizeFunction, type AuthorizeFunctionContext, type CreatePluvHandlerConfig, type InferCallback, NodePlatform, type NodePlatformConfig, type PlatformNodeCreateIOParams, createPluvHandler, infer, 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
|
-
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
4
|
-
import { JsonObject, Json, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, MaybePromise, Maybe } from '@pluv/types';
|
|
3
|
+
import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPersistence, AbstractPubSub, ConvertWebSocketConfig, AbstractPlatformConfig, PluvServer, InferInitContextType, CreateIOParams, PluvIOAuthorize, PluvContext } from '@pluv/io';
|
|
4
|
+
import { JsonObject, Json, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, MaybePromise, Maybe, Id } from '@pluv/types';
|
|
5
5
|
import { IncomingMessage, Server, ServerResponse } from 'node:http';
|
|
6
6
|
|
|
7
7
|
type NodeWebSocketConfig = AbstractWebSocketConfig;
|
|
@@ -34,7 +34,7 @@ type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
|
34
34
|
persistence: AbstractPersistence;
|
|
35
35
|
pubSub: AbstractPubSub;
|
|
36
36
|
}) & {
|
|
37
|
-
|
|
37
|
+
roomContext?: NodePlatformRoomContext<TMeta>;
|
|
38
38
|
};
|
|
39
39
|
declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<NodeWebSocket, {
|
|
40
40
|
req: IncomingMessage;
|
|
@@ -52,6 +52,7 @@ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abst
|
|
|
52
52
|
onUserConnected: true;
|
|
53
53
|
onUserDisconnected: true;
|
|
54
54
|
};
|
|
55
|
+
router: true;
|
|
55
56
|
}> {
|
|
56
57
|
readonly _config: {
|
|
57
58
|
authorize: {
|
|
@@ -67,6 +68,7 @@ declare class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abst
|
|
|
67
68
|
onUserConnected: true;
|
|
68
69
|
onUserDisconnected: true;
|
|
69
70
|
};
|
|
71
|
+
router: true;
|
|
70
72
|
};
|
|
71
73
|
readonly _name = "platformNode";
|
|
72
74
|
constructor(config?: NodePlatformConfig<TMeta>);
|
|
@@ -107,6 +109,18 @@ interface CreatePluvHandlerResult {
|
|
|
107
109
|
}
|
|
108
110
|
declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
|
|
109
111
|
|
|
110
|
-
declare const
|
|
112
|
+
declare const identity: <T extends unknown>(x: T) => T;
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
|
|
115
|
+
meta?: (io: TMeta) => TMeta;
|
|
116
|
+
};
|
|
117
|
+
declare const infer: <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) => InferCallback<TMeta>;
|
|
118
|
+
|
|
119
|
+
type PlatformNodeCreateIOParams<TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = Id<NodePlatformConfig<TMeta> & Omit<CreateIOParams<NodePlatform<TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
|
|
120
|
+
authorize?: PluvIOAuthorize<NodePlatform<TMeta>, TUser, InferInitContextType<NodePlatform<TMeta>>>;
|
|
121
|
+
context?: PluvContext<NodePlatform<TMeta>, TContext>;
|
|
122
|
+
types?: InferCallback<TMeta>;
|
|
123
|
+
}>;
|
|
124
|
+
declare const platformNode: <TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(config?: PlatformNodeCreateIOParams<TMeta, TContext, TUser>) => CreateIOParams<NodePlatform<TMeta>, TContext, TUser>;
|
|
125
|
+
|
|
126
|
+
export { type AuthorizeFunction, type AuthorizeFunctionContext, type CreatePluvHandlerConfig, type InferCallback, NodePlatform, type NodePlatformConfig, type PlatformNodeCreateIOParams, createPluvHandler, infer, platformNode };
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
65
65
|
var index_exports = {};
|
|
66
66
|
__export(index_exports, {
|
|
67
67
|
createPluvHandler: () => createPluvHandler,
|
|
68
|
+
infer: () => infer,
|
|
68
69
|
platformNode: () => platformNode
|
|
69
70
|
});
|
|
70
71
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -174,6 +175,9 @@ var createPluvHandler = (config) => {
|
|
|
174
175
|
};
|
|
175
176
|
};
|
|
176
177
|
|
|
178
|
+
// src/infer.ts
|
|
179
|
+
var infer = (callback) => callback;
|
|
180
|
+
|
|
177
181
|
// src/NodePlatform.ts
|
|
178
182
|
var import_io2 = require("@pluv/io");
|
|
179
183
|
var import_node_crypto2 = __toESM(require("crypto"));
|
|
@@ -250,9 +254,9 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
250
254
|
// src/NodePlatform.ts
|
|
251
255
|
var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
252
256
|
constructor(config = {}) {
|
|
253
|
-
const {
|
|
257
|
+
const { roomContext, mode = "attached", persistence, pubSub } = config;
|
|
254
258
|
super(__spreadValues({
|
|
255
|
-
|
|
259
|
+
roomContext
|
|
256
260
|
}, persistence && pubSub ? { persistence, pubSub } : {}));
|
|
257
261
|
this._name = "platformNode";
|
|
258
262
|
this._config = {
|
|
@@ -268,7 +272,8 @@ var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
|
268
272
|
onStorageUpdated: true,
|
|
269
273
|
onUserConnected: true,
|
|
270
274
|
onUserDisconnected: true
|
|
271
|
-
}
|
|
275
|
+
},
|
|
276
|
+
router: true
|
|
272
277
|
};
|
|
273
278
|
}
|
|
274
279
|
acceptWebSocket(webSocket) {
|
|
@@ -292,7 +297,7 @@ var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
|
292
297
|
}
|
|
293
298
|
initialize(config) {
|
|
294
299
|
return new _NodePlatform({
|
|
295
|
-
|
|
300
|
+
roomContext: config.roomContext,
|
|
296
301
|
mode: this._config.registrationMode,
|
|
297
302
|
persistence: this.persistence,
|
|
298
303
|
pubSub: this.pubSub
|
|
@@ -313,10 +318,18 @@ var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
|
313
318
|
|
|
314
319
|
// src/platformNode.ts
|
|
315
320
|
var platformNode = (config = {}) => {
|
|
316
|
-
|
|
321
|
+
const { authorize, context, crdt, debug } = config;
|
|
322
|
+
return {
|
|
323
|
+
authorize,
|
|
324
|
+
context,
|
|
325
|
+
crdt,
|
|
326
|
+
debug,
|
|
327
|
+
platform: new NodePlatform(config)
|
|
328
|
+
};
|
|
317
329
|
};
|
|
318
330
|
// Annotate the CommonJS export names for ESM import in node:
|
|
319
331
|
0 && (module.exports = {
|
|
320
332
|
createPluvHandler,
|
|
333
|
+
infer,
|
|
321
334
|
platformNode
|
|
322
335
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -140,6 +140,9 @@ var createPluvHandler = (config) => {
|
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
// src/infer.ts
|
|
144
|
+
var infer = (callback) => callback;
|
|
145
|
+
|
|
143
146
|
// src/NodePlatform.ts
|
|
144
147
|
import { AbstractPlatform } from "@pluv/io";
|
|
145
148
|
import crypto2 from "node:crypto";
|
|
@@ -216,9 +219,9 @@ var NodeWebSocket = class extends AbstractWebSocket {
|
|
|
216
219
|
// src/NodePlatform.ts
|
|
217
220
|
var NodePlatform = class _NodePlatform extends AbstractPlatform {
|
|
218
221
|
constructor(config = {}) {
|
|
219
|
-
const {
|
|
222
|
+
const { roomContext, mode = "attached", persistence, pubSub } = config;
|
|
220
223
|
super(__spreadValues({
|
|
221
|
-
|
|
224
|
+
roomContext
|
|
222
225
|
}, persistence && pubSub ? { persistence, pubSub } : {}));
|
|
223
226
|
this._name = "platformNode";
|
|
224
227
|
this._config = {
|
|
@@ -234,7 +237,8 @@ var NodePlatform = class _NodePlatform extends AbstractPlatform {
|
|
|
234
237
|
onStorageUpdated: true,
|
|
235
238
|
onUserConnected: true,
|
|
236
239
|
onUserDisconnected: true
|
|
237
|
-
}
|
|
240
|
+
},
|
|
241
|
+
router: true
|
|
238
242
|
};
|
|
239
243
|
}
|
|
240
244
|
acceptWebSocket(webSocket) {
|
|
@@ -258,7 +262,7 @@ var NodePlatform = class _NodePlatform extends AbstractPlatform {
|
|
|
258
262
|
}
|
|
259
263
|
initialize(config) {
|
|
260
264
|
return new _NodePlatform({
|
|
261
|
-
|
|
265
|
+
roomContext: config.roomContext,
|
|
262
266
|
mode: this._config.registrationMode,
|
|
263
267
|
persistence: this.persistence,
|
|
264
268
|
pubSub: this.pubSub
|
|
@@ -279,9 +283,17 @@ var NodePlatform = class _NodePlatform extends AbstractPlatform {
|
|
|
279
283
|
|
|
280
284
|
// src/platformNode.ts
|
|
281
285
|
var platformNode = (config = {}) => {
|
|
282
|
-
|
|
286
|
+
const { authorize, context, crdt, debug } = config;
|
|
287
|
+
return {
|
|
288
|
+
authorize,
|
|
289
|
+
context,
|
|
290
|
+
crdt,
|
|
291
|
+
debug,
|
|
292
|
+
platform: new NodePlatform(config)
|
|
293
|
+
};
|
|
283
294
|
};
|
|
284
295
|
export {
|
|
285
296
|
createPluvHandler,
|
|
297
|
+
infer,
|
|
286
298
|
platformNode
|
|
287
299
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.1",
|
|
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.13.
|
|
20
|
+
"@types/node": "^22.13.7",
|
|
21
21
|
"@types/ws": "^8.5.14",
|
|
22
22
|
"path-to-regexp": "^8.2.0",
|
|
23
|
-
"@pluv/io": "^0.
|
|
24
|
-
"@pluv/types": "^0.
|
|
23
|
+
"@pluv/io": "^0.37.1",
|
|
24
|
+
"@pluv/types": "^0.37.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"eslint": "^8.57.1",
|
|
28
28
|
"tsup": "^8.4.0",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.8.2",
|
|
30
30
|
"ws": "^8.18.1",
|
|
31
|
-
"@pluv/tsconfig": "^0.
|
|
32
|
-
"eslint-config-pluv": "^0.
|
|
31
|
+
"@pluv/tsconfig": "^0.37.1",
|
|
32
|
+
"eslint-config-pluv": "^0.37.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ws": "^8.0.0"
|
package/src/NodePlatform.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof
|
|
|
21
21
|
export type NodePlatformConfig<TMeta extends Record<string, Json>> = { mode?: WebSocketRegistrationMode } & (
|
|
22
22
|
| { persistence?: undefined; pubSub?: undefined }
|
|
23
23
|
| { persistence: AbstractPersistence; pubSub: AbstractPubSub }
|
|
24
|
-
) & {
|
|
24
|
+
) & { roomContext?: NodePlatformRoomContext<TMeta> };
|
|
25
25
|
|
|
26
26
|
export class NodePlatform<TMeta extends Record<string, Json> = {}> extends AbstractPlatform<
|
|
27
27
|
NodeWebSocket,
|
|
@@ -41,16 +41,17 @@ export class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abstr
|
|
|
41
41
|
onUserConnected: true;
|
|
42
42
|
onUserDisconnected: true;
|
|
43
43
|
};
|
|
44
|
+
router: true;
|
|
44
45
|
}
|
|
45
46
|
> {
|
|
46
47
|
public readonly _config;
|
|
47
48
|
public readonly _name = "platformNode";
|
|
48
49
|
|
|
49
50
|
constructor(config: NodePlatformConfig<TMeta> = {}) {
|
|
50
|
-
const {
|
|
51
|
+
const { roomContext, mode = "attached", persistence, pubSub } = config;
|
|
51
52
|
|
|
52
53
|
super({
|
|
53
|
-
|
|
54
|
+
roomContext,
|
|
54
55
|
...(persistence && pubSub ? { persistence, pubSub } : {}),
|
|
55
56
|
});
|
|
56
57
|
|
|
@@ -68,6 +69,7 @@ export class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abstr
|
|
|
68
69
|
onUserConnected: true as const,
|
|
69
70
|
onUserDisconnected: true as const,
|
|
70
71
|
},
|
|
72
|
+
router: true as const,
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -99,7 +101,7 @@ export class NodePlatform<TMeta extends Record<string, Json> = {}> extends Abstr
|
|
|
99
101
|
|
|
100
102
|
public initialize(config: AbstractPlatformConfig<NodePlatformRoomContext<TMeta>>): this {
|
|
101
103
|
return new NodePlatform({
|
|
102
|
-
|
|
104
|
+
roomContext: config.roomContext,
|
|
103
105
|
mode: this._config.registrationMode,
|
|
104
106
|
persistence: this.persistence,
|
|
105
107
|
pubSub: this.pubSub,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export type { WebSocket } from "ws";
|
|
2
2
|
export { createPluvHandler } from "./createPluvHandler";
|
|
3
3
|
export type { AuthorizeFunction, AuthorizeFunctionContext, CreatePluvHandlerConfig } from "./createPluvHandler";
|
|
4
|
+
export { infer } from "./infer";
|
|
5
|
+
export type { InferCallback } from "./infer";
|
|
4
6
|
export type { NodePlatform, NodePlatformConfig } from "./NodePlatform";
|
|
5
7
|
export { platformNode } from "./platformNode";
|
|
8
|
+
export type { PlatformNodeCreateIOParams } from "./platformNode";
|
package/src/infer.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Json } from "@pluv/types";
|
|
2
|
+
import type { identity } from "./utils";
|
|
3
|
+
|
|
4
|
+
export type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
|
|
5
|
+
meta?: (io: TMeta) => TMeta;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const infer = <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) => callback;
|
package/src/platformNode.ts
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreateIOParams, InferInitContextType, PluvContext, PluvIOAuthorize } from "@pluv/io";
|
|
2
|
+
import type { BaseUser, Id, Json } from "@pluv/types";
|
|
2
3
|
import type { NodePlatformConfig } from "./NodePlatform";
|
|
3
4
|
import { NodePlatform } from "./NodePlatform";
|
|
5
|
+
import type { InferCallback } from "./infer";
|
|
4
6
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export type PlatformNodeCreateIOParams<
|
|
8
|
+
TMeta extends Record<string, Json> = {},
|
|
9
|
+
TContext extends Record<string, any> = {},
|
|
10
|
+
TUser extends BaseUser | null = null,
|
|
11
|
+
> = Id<
|
|
12
|
+
NodePlatformConfig<TMeta> &
|
|
13
|
+
Omit<CreateIOParams<NodePlatform<TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
|
|
14
|
+
authorize?: PluvIOAuthorize<NodePlatform<TMeta>, TUser, InferInitContextType<NodePlatform<TMeta>>>;
|
|
15
|
+
context?: PluvContext<NodePlatform<TMeta>, TContext>;
|
|
16
|
+
types?: InferCallback<TMeta>;
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export const platformNode = <
|
|
21
|
+
TMeta extends Record<string, Json> = {},
|
|
22
|
+
TContext extends Record<string, any> = {},
|
|
23
|
+
TUser extends BaseUser | null = null,
|
|
24
|
+
>(
|
|
25
|
+
config: PlatformNodeCreateIOParams<TMeta, TContext, TUser> = {},
|
|
26
|
+
): CreateIOParams<NodePlatform<TMeta>, TContext, TUser> => {
|
|
27
|
+
const { authorize, context, crdt, debug } = config;
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
authorize,
|
|
31
|
+
context,
|
|
32
|
+
crdt,
|
|
33
|
+
debug,
|
|
34
|
+
platform: new NodePlatform<TMeta>(config),
|
|
35
|
+
};
|
|
9
36
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const identity = <T extends unknown>(x: T): T => x;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { identity } from "./identity";
|