@pluv/io 3.2.2 → 4.0.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 +15 -17
- package/CHANGELOG.md +99 -0
- package/dist/index.d.mts +427 -423
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1390 -1476
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -14
- package/src/IORoom.ts +65 -17
- package/src/PluvIO.ts +4 -16
- package/src/PluvRouter.ts +3 -10
- package/src/PluvServer.ts +31 -22
- package/src/index.ts +1 -0
- package/src/types.ts +13 -2
- package/src/version.generated.ts +1 -1
- package/tsdown.config.ts +14 -0
- package/dist/index.d.ts +0 -539
- package/dist/index.js +0 -1575
package/src/PluvRouter.ts
CHANGED
|
@@ -5,11 +5,8 @@ import type { PluvIOAuthorize } from "./types";
|
|
|
5
5
|
|
|
6
6
|
export type PluvRouterEventConfig<
|
|
7
7
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
8
|
-
TAuthorize extends PluvIOAuthorize<
|
|
9
|
-
TPlatform,
|
|
8
|
+
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null =
|
|
10
9
|
any,
|
|
11
|
-
InferInitContextType<TPlatform>
|
|
12
|
-
> | null = any,
|
|
13
10
|
TContext extends Record<string, any> = {},
|
|
14
11
|
> = { [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config"> };
|
|
15
12
|
|
|
@@ -28,15 +25,11 @@ export type MergedRouter<
|
|
|
28
25
|
|
|
29
26
|
export class PluvRouter<
|
|
30
27
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
31
|
-
TAuthorize extends PluvIOAuthorize<
|
|
32
|
-
TPlatform,
|
|
28
|
+
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null =
|
|
33
29
|
any,
|
|
34
|
-
InferInitContextType<TPlatform>
|
|
35
|
-
> | null = any,
|
|
36
30
|
TContext extends Record<string, any> = {},
|
|
37
31
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
38
|
-
> implements IORouterLike<TEvents>
|
|
39
|
-
{
|
|
32
|
+
> implements IORouterLike<TEvents> {
|
|
40
33
|
readonly _defs: { events: TEvents } = { events: {} as TEvents };
|
|
41
34
|
|
|
42
35
|
constructor(events: TEvents) {
|
package/src/PluvServer.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbstractCrdtDocFactory, CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type {
|
|
4
|
+
AreAllOptional,
|
|
4
5
|
IOLike,
|
|
5
6
|
Id,
|
|
6
7
|
InferIOAuthorize,
|
|
@@ -15,7 +16,6 @@ import type {
|
|
|
15
16
|
InferInitContextType,
|
|
16
17
|
InferRoomContextType,
|
|
17
18
|
} from "./AbstractPlatform";
|
|
18
|
-
import type { IORoomListeners } from "./IORoom";
|
|
19
19
|
import { IORoom } from "./IORoom";
|
|
20
20
|
import type { PluvIO } from "./PluvIO";
|
|
21
21
|
import { PluvProcedure } from "./PluvProcedure";
|
|
@@ -47,11 +47,8 @@ export type InferIORoom<TServer extends PluvServer<any, any, any, any, any>> =
|
|
|
47
47
|
|
|
48
48
|
export type PluvServerConfig<
|
|
49
49
|
TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>,
|
|
50
|
-
TAuthorize extends PluvIOAuthorize<
|
|
51
|
-
TPlatform,
|
|
50
|
+
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null =
|
|
52
51
|
any,
|
|
53
|
-
InferInitContextType<TPlatform>
|
|
54
|
-
> | null = any,
|
|
55
52
|
TContext extends Record<string, any> = {},
|
|
56
53
|
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
57
54
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
@@ -73,7 +70,7 @@ type BaseCreateRoomOptions<
|
|
|
73
70
|
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
74
71
|
TContext extends Record<string, any>,
|
|
75
72
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
76
|
-
> =
|
|
73
|
+
> = {
|
|
77
74
|
debug?: boolean;
|
|
78
75
|
};
|
|
79
76
|
|
|
@@ -82,7 +79,7 @@ export type CreateRoomOptions<
|
|
|
82
79
|
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
83
80
|
TContext extends Record<string, any>,
|
|
84
81
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
85
|
-
> = keyof InferRoomContextType<TPlatform> extends never
|
|
82
|
+
> = keyof Omit<InferRoomContextType<TPlatform>, "meta"> extends never
|
|
86
83
|
? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | []
|
|
87
84
|
: [
|
|
88
85
|
Id<
|
|
@@ -93,16 +90,12 @@ export type CreateRoomOptions<
|
|
|
93
90
|
|
|
94
91
|
export class PluvServer<
|
|
95
92
|
TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>,
|
|
96
|
-
TAuthorize extends PluvIOAuthorize<
|
|
97
|
-
TPlatform,
|
|
93
|
+
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null =
|
|
98
94
|
any,
|
|
99
|
-
InferInitContextType<TPlatform>
|
|
100
|
-
> | null = any,
|
|
101
95
|
TContext extends Record<string, any> = {},
|
|
102
96
|
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
103
97
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
104
|
-
> implements IOLike<TAuthorize, TCrdt, TEvents>
|
|
105
|
-
{
|
|
98
|
+
> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
106
99
|
public readonly version: string = __PLUV_VERSION as any;
|
|
107
100
|
|
|
108
101
|
private readonly _config: NonNilProps<
|
|
@@ -377,8 +370,9 @@ export class PluvServer<
|
|
|
377
370
|
} as NonNilProps<PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>>;
|
|
378
371
|
|
|
379
372
|
const {
|
|
380
|
-
|
|
373
|
+
onRoomDestroyed,
|
|
381
374
|
onRoomMessage,
|
|
375
|
+
onStorageDestroyed,
|
|
382
376
|
onStorageUpdated,
|
|
383
377
|
onUserConnected,
|
|
384
378
|
onUserDisconnected,
|
|
@@ -386,8 +380,9 @@ export class PluvServer<
|
|
|
386
380
|
|
|
387
381
|
this._docFactory = this._config.crdt.doc(() => ({}));
|
|
388
382
|
(this as any)._listeners = {
|
|
389
|
-
|
|
383
|
+
onRoomDestroyed: (event) => onRoomDestroyed?.(event),
|
|
390
384
|
onRoomMessage: (event) => onRoomMessage?.(event),
|
|
385
|
+
onStorageDestroyed: (event) => onStorageDestroyed?.(event),
|
|
391
386
|
onStorageUpdated: (event) => onStorageUpdated?.(event),
|
|
392
387
|
onUserConnected: (event) => onUserConnected?.(event),
|
|
393
388
|
onUserDisconnected: (event) => onUserDisconnected?.(event),
|
|
@@ -398,8 +393,14 @@ export class PluvServer<
|
|
|
398
393
|
room: string,
|
|
399
394
|
...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>
|
|
400
395
|
): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents> {
|
|
401
|
-
const { _meta, debug,
|
|
402
|
-
|
|
396
|
+
const { _meta, debug, ...platformRoomContext } = (options[0] ?? {}) as CreateRoomOptions<
|
|
397
|
+
TPlatform,
|
|
398
|
+
TAuthorize,
|
|
399
|
+
TContext,
|
|
400
|
+
TEvents
|
|
401
|
+
>[0] & {
|
|
402
|
+
_meta?: any;
|
|
403
|
+
};
|
|
403
404
|
|
|
404
405
|
const platform = this._config.platform();
|
|
405
406
|
|
|
@@ -423,17 +424,25 @@ export class PluvServer<
|
|
|
423
424
|
crdt: this._config.crdt,
|
|
424
425
|
debug: debug ?? this._config.debug,
|
|
425
426
|
getInitialStorage: this._getInitialStorage,
|
|
426
|
-
async
|
|
427
|
+
async onRoomDestroyed(event) {
|
|
427
428
|
logDebug(`${colors.blue("Deleting empty room:")} ${room}`);
|
|
428
429
|
|
|
429
|
-
|
|
430
|
-
await Promise.resolve(listeners.
|
|
431
|
-
await event.platform.persistence.deleteStorageState(room);
|
|
430
|
+
// Always fire server-level onRoomDestroyed
|
|
431
|
+
await Promise.resolve(listeners.onRoomDestroyed(event));
|
|
432
432
|
|
|
433
433
|
logDebug(`${colors.blue("Deleted room:")} ${room}`);
|
|
434
434
|
},
|
|
435
|
+
async onStorageDestroyed(event) {
|
|
436
|
+
logDebug(`${colors.blue("Destroying storage for room:")} ${room}`);
|
|
437
|
+
|
|
438
|
+
// Always fire server-level onStorageDestroyed
|
|
439
|
+
await Promise.resolve(listeners.onStorageDestroyed(event));
|
|
440
|
+
|
|
441
|
+
await event.platform.persistence.deleteStorageState(room);
|
|
442
|
+
|
|
443
|
+
logDebug(`${colors.blue("Destroyed storage for room:")} ${room}`);
|
|
444
|
+
},
|
|
435
445
|
async onMessage(event) {
|
|
436
|
-
await Promise.resolve(onMessage?.(event));
|
|
437
446
|
await Promise.resolve(listeners.onRoomMessage(event));
|
|
438
447
|
},
|
|
439
448
|
async onUserConnected(event) {
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -120,8 +120,9 @@ export interface PlatformConfig {
|
|
|
120
120
|
handleMode: HandleMode;
|
|
121
121
|
registrationMode: WebSocketRegistrationMode;
|
|
122
122
|
listeners: {
|
|
123
|
-
|
|
123
|
+
onRoomDestroyed?: boolean;
|
|
124
124
|
onRoomMessage?: boolean;
|
|
125
|
+
onStorageDestroyed?: boolean;
|
|
125
126
|
onStorageUpdated?: boolean;
|
|
126
127
|
onUserConnected?: boolean;
|
|
127
128
|
onUserDisconnected?: boolean;
|
|
@@ -172,8 +173,9 @@ export type BasePluvIOListeners<
|
|
|
172
173
|
TContext extends Record<string, any>,
|
|
173
174
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
174
175
|
> = {
|
|
175
|
-
|
|
176
|
+
onRoomDestroyed: (event: IORoomDestroyedEvent<TPlatform, TContext>) => void;
|
|
176
177
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
178
|
+
onStorageDestroyed: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
177
179
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
178
180
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
179
181
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -236,6 +238,15 @@ export type IORoomListenerEvent<
|
|
|
236
238
|
room: string;
|
|
237
239
|
};
|
|
238
240
|
|
|
241
|
+
export type IORoomDestroyedEvent<
|
|
242
|
+
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
243
|
+
TContext extends Record<string, any>,
|
|
244
|
+
> = {
|
|
245
|
+
context: TContext;
|
|
246
|
+
platform: TPlatform;
|
|
247
|
+
room: string;
|
|
248
|
+
};
|
|
249
|
+
|
|
239
250
|
export type IORoomMessageEvent<
|
|
240
251
|
TPlatform extends AbstractPlatform<any>,
|
|
241
252
|
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '4.0.1'
|
package/tsdown.config.ts
ADDED