@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/dist/index.d.mts
CHANGED
|
@@ -1,539 +1,543 @@
|
|
|
1
|
-
import { AbstractCrdtDocFactory, CrdtLibraryType as CrdtLibraryType$1, NoopCrdtDocFactory } from
|
|
2
|
-
|
|
3
|
-
import { JsonObject, IOAuthorize, InferIOAuthorizeUser, MaybePromise, IOEventMessage, EventRecord, ProcedureLike, InputZodLike, IORouterLike, BaseUser, UndefinedProps, CrdtDocLike, Id, InferEventMessage, InferEventsOutput, Maybe, IOLike, InferIOOutput, CrdtLibraryType, InferIOInput, InferIOAuthorize, HasRequiredProperty } from '@pluv/types';
|
|
4
|
-
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
1
|
+
import { AbstractCrdtDocFactory, CrdtLibraryType, CrdtLibraryType as CrdtLibraryType$1, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
2
|
+
import { BaseUser, BaseUser as BaseUser$1, CrdtDocLike, CrdtLibraryType as CrdtLibraryType$2, EventMessage, EventRecord, EventRecord as EventRecord$1, HasRequiredProperty, IOAuthorize, IOEventMessage, IOEventMessage as IOEventMessage$1, IOLike, IORouterLike, Id, InferEventMessage, InferEventsOutput, InferIOAuthorize, InferIOAuthorizeUser, InferIOInput, InferIOOutput, InputZodLike, JsonObject, Maybe, MaybePromise, ProcedureLike, UndefinedProps } from "@pluv/types";
|
|
5
3
|
|
|
4
|
+
//#region src/AbstractPersistence.d.ts
|
|
6
5
|
declare abstract class AbstractPersistence {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
|
|
7
|
+
abstract deleteStorageState(room: string): Promise<void>;
|
|
8
|
+
abstract deleteUser(room: string, connectionId: string): Promise<void>;
|
|
9
|
+
abstract deleteUsers(room: string): Promise<void>;
|
|
10
|
+
abstract getStorageState(room: string): Promise<string | null>;
|
|
11
|
+
abstract getUser(room: string, connectionId: string): Promise<JsonObject | null>;
|
|
12
|
+
abstract getUsers(room: string): Promise<Map<[connectionId: string][0], JsonObject | null>>;
|
|
13
|
+
abstract getUsersSize(room: string): Promise<number>;
|
|
14
|
+
abstract initialize(roomContext: any): typeof this;
|
|
15
|
+
abstract setStorageState(room: string, state: string): Promise<void>;
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/AbstractWebSocket.d.ts
|
|
19
19
|
type AbstractEvent = {};
|
|
20
20
|
type AbstractCloseEvent = AbstractEvent & {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
readonly code: number;
|
|
22
|
+
readonly reason: string;
|
|
23
23
|
};
|
|
24
24
|
type AbstractMessageEvent<T = any> = AbstractEvent & {
|
|
25
|
-
|
|
25
|
+
readonly data: T;
|
|
26
26
|
};
|
|
27
27
|
type AbstractErrorEvent = AbstractEvent & {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
error: unknown;
|
|
29
|
+
message?: string;
|
|
30
30
|
};
|
|
31
31
|
interface AbstractEventMap {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
close: AbstractCloseEvent;
|
|
33
|
+
message: AbstractMessageEvent;
|
|
34
|
+
error: AbstractErrorEvent;
|
|
35
35
|
}
|
|
36
36
|
type EventType = keyof AbstractEventMap;
|
|
37
37
|
interface AbstractWebSocketHandleErrorParams {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
error: unknown;
|
|
39
|
+
message?: string;
|
|
40
|
+
room: string;
|
|
41
|
+
session?: WebSocketSession<any>;
|
|
42
42
|
}
|
|
43
43
|
type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
|
|
44
44
|
type InferWebSocketSource<TAbstractWebSocket extends AbstractWebSocket> = TAbstractWebSocket extends AbstractWebSocket<infer IWebSocket> ? IWebSocket : never;
|
|
45
45
|
interface AbstractWebSocketConfig {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
persistence: AbstractPersistence;
|
|
47
|
+
platform: AbstractPlatform<any>;
|
|
48
|
+
room: string;
|
|
49
49
|
}
|
|
50
50
|
declare abstract class AbstractWebSocket<TWebSocket = any, TAuthorize extends IOAuthorize<any, any> | null = null> {
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
51
|
+
/** The connection is not yet open. */
|
|
52
|
+
readonly CONNECTING = 0;
|
|
53
|
+
/** The connection is open and ready to communicate. */
|
|
54
|
+
readonly OPEN = 1;
|
|
55
|
+
/** The connection is in the process of closing. */
|
|
56
|
+
readonly CLOSING = 2;
|
|
57
|
+
/** The connection is closed. */
|
|
58
|
+
readonly CLOSED = 3;
|
|
59
|
+
readonly persistence: AbstractPersistence;
|
|
60
|
+
readonly room: string;
|
|
61
|
+
readonly webSocket: TWebSocket;
|
|
62
|
+
protected readonly _platform: AbstractPlatform<this>;
|
|
63
|
+
abstract set presence(presence: JsonObject | null);
|
|
64
|
+
abstract get readyState(): 0 | 1 | 2 | 3;
|
|
65
|
+
abstract get session(): WebSocketSession<TAuthorize>;
|
|
66
|
+
abstract get sessionId(): string;
|
|
67
|
+
abstract get state(): WebSocketSerializedState;
|
|
68
|
+
abstract set state(state: WebSocketSerializedState);
|
|
69
|
+
abstract set user(user: InferIOAuthorizeUser<TAuthorize>);
|
|
70
|
+
constructor(webSocket: TWebSocket, config: AbstractWebSocketConfig);
|
|
71
|
+
/**
|
|
72
|
+
* TODO
|
|
73
|
+
* @description Return an unsubscribe method to remove the event-listener.
|
|
74
|
+
* This is preferred over adding an explicit abstract removeEventListener
|
|
75
|
+
* method, because the implementing class might have to transform the
|
|
76
|
+
* listener, and removing the same listener might be complicated as a
|
|
77
|
+
* result.
|
|
78
|
+
* @date August 28, 2022
|
|
79
|
+
*/
|
|
80
|
+
abstract addEventListener<TType extends EventType>(type: TType, handler: AbstractListener<TType>): void;
|
|
81
|
+
abstract close(code?: number | undefined, reason?: string | undefined): void;
|
|
82
|
+
abstract send(message: ArrayBuffer | ArrayBufferView | string): void;
|
|
83
|
+
abstract terminate(): void;
|
|
84
|
+
handleError(params: AbstractWebSocketHandleErrorParams): void;
|
|
85
|
+
sendMessage<TMessage extends IOEventMessage$1<any> = IOEventMessage$1<any>>(data: TMessage): void;
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/PluvProcedure.d.ts
|
|
89
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord$1<string, any> = {}> {
|
|
90
|
+
broadcast?: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
91
|
+
input?: InputZodLike<TInput>;
|
|
92
|
+
self?: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
93
|
+
sync?: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
93
94
|
}
|
|
94
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord$1<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
96
|
+
private _broadcast;
|
|
97
|
+
private _input;
|
|
98
|
+
private _self;
|
|
99
|
+
private _sync;
|
|
100
|
+
get config(): ProcedureLike<TInput, TOutput>["config"];
|
|
101
|
+
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
102
|
+
broadcast<TResult extends EventRecord$1<string, any> = {}>(resolver: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
103
|
+
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
104
|
+
self<TResult extends EventRecord$1<string, any> = {}>(resolver: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
105
|
+
sync<TResult extends EventRecord$1<string, any> = {}>(resolver: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
106
|
+
private _resolver;
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/PluvRouter.d.ts
|
|
108
110
|
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}> = {
|
|
109
|
-
|
|
111
|
+
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
110
112
|
};
|
|
111
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
|
|
112
|
-
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
113
|
-
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
114
|
-
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
113
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>, ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
115
114
|
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
readonly _defs: {
|
|
116
|
+
events: TEvents;
|
|
117
|
+
};
|
|
118
|
+
constructor(events: TEvents);
|
|
119
|
+
static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
120
|
+
private _isValidEventName;
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/types.d.ts
|
|
124
124
|
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = MaybePromise<TContext> | ((params: InferRoomContextType<TPlatform>) => MaybePromise<TContext>);
|
|
125
125
|
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
126
|
-
type EventResolver<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
126
|
+
type EventResolver<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord$1<string, any> = {}> = (data: TInput, context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
127
127
|
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
context: TContext;
|
|
129
|
+
doc: CrdtDocLike<any, any>;
|
|
130
|
+
garbageCollect: () => Promise<void>;
|
|
131
|
+
platform: TPlatform;
|
|
132
|
+
presence: JsonObject | null;
|
|
133
|
+
room: string;
|
|
134
|
+
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
135
|
+
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
136
|
+
time: number;
|
|
137
137
|
}
|
|
138
138
|
type SendMessageOptions = {
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
type?: "broadcast";
|
|
140
|
+
sessionIds?: readonly string[];
|
|
141
141
|
} | {
|
|
142
|
-
|
|
142
|
+
type: "self";
|
|
143
143
|
} | {
|
|
144
|
-
|
|
144
|
+
type: "sync";
|
|
145
145
|
};
|
|
146
146
|
interface WebSocketSessionTimers {
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
ping: number;
|
|
148
|
+
presence: number | null;
|
|
149
149
|
}
|
|
150
150
|
interface WebSocketSerializedState {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
presence: JsonObject | null;
|
|
152
|
+
quit: boolean;
|
|
153
|
+
room: string;
|
|
154
|
+
timers: WebSocketSessionTimers;
|
|
155
155
|
}
|
|
156
156
|
type WebSocketSession<TAuthorize extends IOAuthorize<any, any> | null = null> = WebSocketSerializedState & {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
id: string;
|
|
158
|
+
user: InferIOAuthorizeUser<TAuthorize>;
|
|
159
|
+
webSocket: AbstractWebSocket;
|
|
160
160
|
};
|
|
161
|
-
type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot extends EventRecord<string, any> = {}> = TEventRecords extends [
|
|
162
|
-
infer IHead extends EventRecord<string, any>,
|
|
163
|
-
...infer ITail extends EventRecord<string, any>[]
|
|
164
|
-
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
165
|
-
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
166
|
-
}> : Id<TRoot>;
|
|
161
|
+
type MergeEventRecords<TEventRecords extends EventRecord$1<string, any>[], TRoot extends EventRecord$1<string, any> = {}> = TEventRecords extends [infer IHead extends EventRecord$1<string, any>, ...infer ITail extends EventRecord$1<string, any>[]] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & { [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P] }> : Id<TRoot>;
|
|
167
162
|
type GetInitialStorageEvent<TContext extends Record<string, any>> = {
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
context: TContext;
|
|
164
|
+
room: string;
|
|
170
165
|
};
|
|
171
166
|
type GetInitialStorageFn<TContext extends Record<string, any>> = (event: GetInitialStorageEvent<TContext>) => MaybePromise<Maybe<string>>;
|
|
172
167
|
type HandleMode = "io" | "fetch";
|
|
173
168
|
type WebSocketRegistrationMode = "attached" | "detached";
|
|
174
169
|
interface PlatformConfig {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
170
|
+
authorize: {
|
|
171
|
+
secret?: boolean;
|
|
172
|
+
};
|
|
173
|
+
requireAuth?: boolean;
|
|
174
|
+
handleMode: HandleMode;
|
|
175
|
+
registrationMode: WebSocketRegistrationMode;
|
|
176
|
+
listeners: {
|
|
177
|
+
onRoomDestroyed?: boolean;
|
|
178
|
+
onRoomMessage?: boolean;
|
|
179
|
+
onStorageDestroyed?: boolean;
|
|
180
|
+
onStorageUpdated?: boolean;
|
|
181
|
+
onUserConnected?: boolean;
|
|
182
|
+
onUserDisconnected?: boolean;
|
|
183
|
+
};
|
|
184
|
+
router?: boolean;
|
|
189
185
|
}
|
|
190
|
-
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any> = {
|
|
191
|
-
|
|
186
|
+
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser$1 = any> = {
|
|
187
|
+
user: InputZodLike<TUser>;
|
|
192
188
|
} & UndefinedProps<{
|
|
193
|
-
|
|
189
|
+
secret?: string;
|
|
194
190
|
}, Exclude<"secret", InferPlatformAuthorizeProperties<TPlatform>>>;
|
|
195
|
-
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser | null = any, TContext extends Record<string, unknown> = {}> = (TUser extends BaseUser ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null) | ((context: TContext) => TUser extends BaseUser ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null);
|
|
191
|
+
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser$1 | null = any, TContext extends Record<string, unknown> = {}> = (TUser extends BaseUser$1 ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null) | ((context: TContext) => TUser extends BaseUser$1 ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null);
|
|
196
192
|
interface PluvIOLimits {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
193
|
+
/**
|
|
194
|
+
* @description Maximum size of presence object in bytes
|
|
195
|
+
*/
|
|
196
|
+
presenceMaxSize?: number | null;
|
|
197
|
+
/**
|
|
198
|
+
* @description Maximum size of storage state in bytes
|
|
199
|
+
*/
|
|
200
|
+
storageMaxSize?: number | null;
|
|
201
|
+
/**
|
|
202
|
+
* @description Maximum length of user id in characters
|
|
203
|
+
*/
|
|
204
|
+
userIdMaxLength?: number | null;
|
|
205
|
+
/**
|
|
206
|
+
* @description Maximum size of user object in bytes
|
|
207
|
+
*/
|
|
208
|
+
userMaxSize?: number | null;
|
|
213
209
|
}
|
|
214
210
|
type BasePluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
onRoomDestroyed: (event: IORoomDestroyedEvent<TPlatform, TContext>) => void;
|
|
212
|
+
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
213
|
+
onStorageDestroyed: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
214
|
+
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
215
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
216
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
220
217
|
};
|
|
221
218
|
type PluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = UndefinedProps<BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, Exclude<keyof BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, InferPlatformListeners<TPlatform>>>;
|
|
222
219
|
type PluvIORouter<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = InferPlatformRouter<TPlatform> extends true ? {
|
|
223
|
-
|
|
220
|
+
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
224
221
|
} : {
|
|
225
|
-
|
|
222
|
+
router?: undefined;
|
|
226
223
|
};
|
|
227
224
|
type InferPlatformConfig<TPlatform extends AbstractPlatform<any, any, any, any>> = TPlatform extends AbstractPlatform<any, any, any, infer IConfig> ? IConfig : never;
|
|
228
|
-
type InferPlatformAuthorizeProperties<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
232
|
-
[P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true;
|
|
233
|
-
};
|
|
225
|
+
type InferPlatformAuthorizeProperties<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof { [P in keyof PlatformConfig["authorize"] as InferPlatformConfig<TPlatform>["authorize"][P] extends true | undefined ? P : never]: true };
|
|
226
|
+
type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof { [P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true };
|
|
234
227
|
type InferPlatformRouter<TPlatform extends AbstractPlatform<any, any, any, any>> = InferPlatformConfig<TPlatform>["router"];
|
|
235
228
|
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any, any, any, any>, TContext extends Record<string, any>> = {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
229
|
+
context: TContext;
|
|
230
|
+
encodedState: string | null;
|
|
231
|
+
platform: TPlatform;
|
|
232
|
+
room: string;
|
|
233
|
+
};
|
|
234
|
+
type IORoomDestroyedEvent<TPlatform extends AbstractPlatform<any, any, any, any>, TContext extends Record<string, any>> = {
|
|
235
|
+
context: TContext;
|
|
236
|
+
platform: TPlatform;
|
|
237
|
+
room: string;
|
|
240
238
|
};
|
|
241
239
|
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
241
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
242
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
245
243
|
};
|
|
246
244
|
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
246
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
249
247
|
};
|
|
250
248
|
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
250
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
253
251
|
};
|
|
254
252
|
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
255
|
-
|
|
253
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
256
254
|
};
|
|
257
255
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/AbstractPubSub.d.ts
|
|
258
|
+
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage$1<TIO, TEvent> & {
|
|
259
|
+
options?: SendMessageOptions;
|
|
261
260
|
};
|
|
262
261
|
declare abstract class AbstractPubSub {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
abstract publish(roomName: string, payload: IOPubSubEventMessage<any>): Promise<void>;
|
|
263
|
+
abstract subscribe(roomName: string, onMessage: (message: IOPubSubEventMessage<any>) => void): Promise<number>;
|
|
264
|
+
abstract unsubscribe(subscriptionId: number): void;
|
|
266
265
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/authorize.d.ts
|
|
268
|
+
interface JWT<TUser extends BaseUser$1> {
|
|
269
|
+
room: string;
|
|
270
|
+
sub: string;
|
|
271
|
+
user: TUser;
|
|
272
272
|
}
|
|
273
|
-
type JWTEncodeParams<TUser extends BaseUser | null, TPlatform extends AbstractPlatform<any, any>> = {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
273
|
+
type JWTEncodeParams<TUser extends BaseUser$1 | null, TPlatform extends AbstractPlatform<any, any>> = {
|
|
274
|
+
maxAge?: number;
|
|
275
|
+
room: string;
|
|
276
|
+
user: TUser extends BaseUser$1 ? TUser : "Error: Cannot create token without authorization!";
|
|
277
277
|
} & InferInitContextType<TPlatform>;
|
|
278
278
|
interface AuthorizeParams {
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
platform: AbstractPlatform<any, any>;
|
|
280
|
+
secret: string;
|
|
281
281
|
}
|
|
282
282
|
interface AuthorizeModule {
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
decode: <TUser extends BaseUser$1>(jwt: string) => Promise<TUser | null>;
|
|
284
|
+
encode: <TUser extends BaseUser$1, TPlatform extends AbstractPlatform<any, any>>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
285
285
|
}
|
|
286
286
|
declare const authorize: (params: AuthorizeParams) => {
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
decode: <TUser extends BaseUser$1>(jwt: string) => Promise<JWT<TUser> | null>;
|
|
288
|
+
encode: <TUser extends BaseUser$1, TPlatform extends AbstractPlatform<any, any>>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
289
289
|
};
|
|
290
|
-
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/AbstractPlatform.d.ts
|
|
291
292
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
292
293
|
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
293
294
|
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
294
295
|
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
|
|
295
296
|
type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
persistence?: AbstractPersistence;
|
|
298
|
+
pubSub?: AbstractPubSub;
|
|
299
|
+
roomContext?: TRoomContext;
|
|
299
300
|
};
|
|
300
301
|
interface ConvertWebSocketConfig {
|
|
301
|
-
|
|
302
|
+
room: string;
|
|
302
303
|
}
|
|
303
304
|
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket<any, any> = AbstractWebSocket<any, any>, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}, TConfig extends PlatformConfig = PlatformConfig> {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
305
|
+
protected readonly _initContext: TInitContext | undefined;
|
|
306
|
+
protected readonly _roomContext: TRoomContext | undefined;
|
|
307
|
+
private _initialized;
|
|
308
|
+
persistence: AbstractPersistence;
|
|
309
|
+
pubSub: AbstractPubSub;
|
|
310
|
+
abstract readonly id: string;
|
|
311
|
+
readonly _createToken?: (params: JWTEncodeParams<any, any> & {
|
|
312
|
+
authorize: Maybe<ResolvedPluvIOAuthorize<any, any>>;
|
|
313
|
+
}) => Promise<string>;
|
|
314
|
+
_fetch?: (...args: any[]) => Promise<any>;
|
|
315
|
+
abstract readonly _config: TConfig;
|
|
316
|
+
abstract readonly _name: string;
|
|
317
|
+
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
318
|
+
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
319
|
+
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket<any, any>;
|
|
320
|
+
abstract getLastPing(webSocket: AbstractWebSocket<any, any>): number | null;
|
|
321
|
+
abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
|
|
322
|
+
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
323
|
+
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
324
|
+
abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
|
|
325
|
+
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
326
|
+
abstract randomUUID(): string;
|
|
327
|
+
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
|
|
328
|
+
validateConfig(config: any): void;
|
|
329
|
+
protected _initialize(): typeof this;
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/IORoom.d.ts
|
|
331
333
|
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
onRoomDestroyed: (event: IORoomDestroyedEvent<TPlatform, TContext>) => void;
|
|
335
|
+
onStorageDestroyed: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
336
|
+
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
337
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
338
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
336
339
|
}
|
|
337
|
-
type BroadcastProxy<TIO extends IORoom<any, any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
338
|
-
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
339
|
-
};
|
|
340
|
+
type BroadcastProxy<TIO extends IORoom<any, any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & { [event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void> };
|
|
340
341
|
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
342
|
+
authorize?: TAuthorize;
|
|
343
|
+
context: PluvContext<TPlatform, TContext>;
|
|
344
|
+
crdt?: {
|
|
345
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
346
|
+
};
|
|
347
|
+
debug: boolean;
|
|
348
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
349
|
+
platform: TPlatform;
|
|
350
|
+
roomContext: InferRoomContextType<TPlatform>;
|
|
351
|
+
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
351
352
|
};
|
|
352
353
|
type WebSocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
353
|
-
|
|
354
|
+
token?: string | null;
|
|
354
355
|
} & InferInitContextType<TPlatform>;
|
|
355
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
356
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$2<any> = CrdtLibraryType$2<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
357
|
+
readonly id: string;
|
|
358
|
+
private _doc;
|
|
359
|
+
private _lastGarbageCollectMs;
|
|
360
|
+
private _uninitialize;
|
|
361
|
+
private readonly _authorize;
|
|
362
|
+
private readonly _context;
|
|
363
|
+
private readonly _crdt;
|
|
364
|
+
private readonly _debug;
|
|
365
|
+
private readonly _docFactory;
|
|
366
|
+
private readonly _getInitialStorage;
|
|
367
|
+
private readonly _listeners;
|
|
368
|
+
private readonly _platform;
|
|
369
|
+
private readonly _roomContext;
|
|
370
|
+
private readonly _router;
|
|
371
|
+
private readonly _sessions;
|
|
372
|
+
private readonly _userSessionss;
|
|
373
|
+
private _wasDocEmptyOnInit;
|
|
374
|
+
private _storageInitializedViaSession;
|
|
375
|
+
/**
|
|
376
|
+
* @ignore
|
|
377
|
+
* @readonly
|
|
378
|
+
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
379
|
+
*/
|
|
380
|
+
get _defs(): {
|
|
381
|
+
authorize: TAuthorize;
|
|
382
|
+
context: TContext;
|
|
383
|
+
crdt: TCrdt;
|
|
384
|
+
events: TEvents;
|
|
385
|
+
platform: TPlatform;
|
|
386
|
+
};
|
|
387
|
+
get broadcast(): BroadcastProxy<this>;
|
|
388
|
+
private get _initialized();
|
|
389
|
+
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
390
|
+
/**
|
|
391
|
+
* @description Closes a connection with the specified sessionId
|
|
392
|
+
* @param sessionId The session id of the connection to close
|
|
393
|
+
*/
|
|
394
|
+
evict(sessionId: string): Promise<void>;
|
|
395
|
+
/**
|
|
396
|
+
* @description Closes all connections to this room, effectively destroying
|
|
397
|
+
* the room
|
|
398
|
+
*/
|
|
399
|
+
evictAll(): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* @description The IORoom will garbage collect occasionally as connections ping/pong the
|
|
402
|
+
* server
|
|
403
|
+
*/
|
|
404
|
+
garbageCollect(): Promise<void>;
|
|
405
|
+
getSize(): number;
|
|
406
|
+
onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
|
|
407
|
+
onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
|
|
408
|
+
onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
|
|
409
|
+
register(webSocket: InferPlatformWebSocketSource<TPlatform>, ...options: keyof InferInitContextType<TPlatform> extends never ? [{
|
|
410
|
+
token?: string;
|
|
411
|
+
}?] : [WebSocketRegisterConfig<TPlatform>]): Promise<void>;
|
|
412
|
+
private _addUserSession;
|
|
413
|
+
private _broadcast;
|
|
414
|
+
private _closeWebSockets;
|
|
415
|
+
private _emitQuitters;
|
|
416
|
+
private _emitRegistered;
|
|
417
|
+
private _emitSyncState;
|
|
418
|
+
private _ensureDetached;
|
|
419
|
+
private _getAbstractWs;
|
|
420
|
+
/**
|
|
421
|
+
* TODO
|
|
422
|
+
* @description Revisit any cast types
|
|
423
|
+
* @date July 17, 2025
|
|
424
|
+
*/
|
|
425
|
+
private _getAuthorizedUser;
|
|
426
|
+
private _getContext;
|
|
427
|
+
private _getInitialDoc;
|
|
428
|
+
private _getIOAuthorize;
|
|
429
|
+
private _getLatestPresence;
|
|
430
|
+
private _getProcedure;
|
|
431
|
+
private _getProcedureInputs;
|
|
432
|
+
private _getSession;
|
|
433
|
+
private _getSessions;
|
|
434
|
+
private _initialize;
|
|
435
|
+
private _logDebug;
|
|
436
|
+
private _onClose;
|
|
437
|
+
private _onMessage;
|
|
438
|
+
private _parseMessage;
|
|
439
|
+
private _setPresence;
|
|
440
|
+
private _removeUserSession;
|
|
441
|
+
private _checkStorageInitializedViaSession;
|
|
442
|
+
private _sendMessage;
|
|
443
|
+
private _sendBroadcastMessage;
|
|
444
|
+
private _sendSelfMessage;
|
|
445
|
+
private _sendSyncMessage;
|
|
442
446
|
}
|
|
443
|
-
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/PluvServer.d.ts
|
|
444
449
|
type InferIORoom<TServer extends PluvServer<any, any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer ICrdt, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, ICrdt, IEvents> : never;
|
|
445
450
|
type PluvServerConfig<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
451
|
+
authorize?: TAuthorize;
|
|
452
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
453
|
+
crdt?: {
|
|
454
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
455
|
+
};
|
|
456
|
+
debug?: boolean;
|
|
457
|
+
limits: PluvIOLimits;
|
|
458
|
+
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
459
|
+
platform: () => TPlatform;
|
|
460
|
+
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
456
461
|
} & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
457
|
-
|
|
462
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
458
463
|
} : {
|
|
459
|
-
|
|
464
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
460
465
|
});
|
|
461
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> =
|
|
462
|
-
|
|
466
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
467
|
+
debug?: boolean;
|
|
463
468
|
};
|
|
464
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [
|
|
465
|
-
Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>
|
|
466
|
-
];
|
|
469
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof Omit<InferRoomContextType<TPlatform>, "meta"> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
|
|
467
470
|
declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
471
|
+
readonly version: string;
|
|
472
|
+
private readonly _config;
|
|
473
|
+
private readonly _docFactory;
|
|
474
|
+
get fetch(): (...args: any[]) => Promise<any>;
|
|
475
|
+
/**
|
|
476
|
+
* @ignore
|
|
477
|
+
* @readonly
|
|
478
|
+
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
479
|
+
*/
|
|
480
|
+
get _defs(): {
|
|
481
|
+
authorize: TAuthorize;
|
|
482
|
+
context: PluvContext<TPlatform, TContext>;
|
|
483
|
+
crdt: TCrdt;
|
|
484
|
+
events: TEvents;
|
|
485
|
+
platform: TPlatform;
|
|
486
|
+
};
|
|
487
|
+
private get _baseRouter();
|
|
488
|
+
private get _procedure();
|
|
489
|
+
private get _router();
|
|
490
|
+
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
491
|
+
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
492
|
+
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
493
|
+
private _getInitialStorage;
|
|
494
|
+
private _getListeners;
|
|
495
|
+
private _logDebug;
|
|
493
496
|
}
|
|
494
|
-
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/PluvIO.d.ts
|
|
495
499
|
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> = {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
500
|
+
authorize?: TAuthorize;
|
|
501
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
502
|
+
crdt?: TCrdt;
|
|
503
|
+
debug?: boolean;
|
|
504
|
+
limits?: PluvIOLimits;
|
|
505
|
+
platform: () => TPlatform;
|
|
502
506
|
};
|
|
503
507
|
type ResolvedServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
504
|
-
|
|
508
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
505
509
|
} : {
|
|
506
|
-
|
|
510
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
507
511
|
});
|
|
508
|
-
type BaseServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = {
|
|
509
|
-
[P in keyof ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] extends undefined ? never : P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P];
|
|
510
|
-
};
|
|
512
|
+
type BaseServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = { [P in keyof ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] extends undefined ? never : P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] };
|
|
511
513
|
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = HasRequiredProperty<BaseServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>> extends true ? [BaseServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>] : [BaseServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>?];
|
|
512
514
|
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
515
|
+
readonly version: string;
|
|
516
|
+
private readonly _authorize;
|
|
517
|
+
private readonly _context;
|
|
518
|
+
private readonly _crdt;
|
|
519
|
+
private readonly _debug;
|
|
520
|
+
private readonly _limits;
|
|
521
|
+
private readonly _platform;
|
|
522
|
+
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
523
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TCrdt>);
|
|
524
|
+
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<TAuthorize>, TPlatform>): Promise<string>;
|
|
525
|
+
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
526
|
+
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
527
|
+
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(...config: ServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
528
|
+
private _getIOAuthorize;
|
|
527
529
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/createIO.d.ts
|
|
532
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser$1 | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>> = {
|
|
533
|
+
authorize?: PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>;
|
|
534
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
535
|
+
crdt?: TCrdt;
|
|
536
|
+
debug?: boolean;
|
|
537
|
+
limits?: PluvIOLimits;
|
|
538
|
+
platform: () => TPlatform;
|
|
536
539
|
};
|
|
537
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>>(params: CreateIOParams<TPlatform, TContext, TUser, TCrdt>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext, TCrdt>;
|
|
538
|
-
|
|
539
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, type PluvContext, PluvIO, type PluvIOAuthorize, type PluvIOConfig, type PluvIOLimits, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
540
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser$1 | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>>(params: CreateIOParams<TPlatform, TContext, TUser, TCrdt>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext, TCrdt>;
|
|
541
|
+
//#endregion
|
|
542
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type BaseUser, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type EventMessage, type EventRecord, type GetInitialStorageFn, type HandleMode, type IOEventMessage, type IOPubSubEventMessage, type IORoom, type IORoomDestroyedEvent, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, type PluvContext, PluvIO, type PluvIOAuthorize, type PluvIOConfig, type PluvIOLimits, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
543
|
+
//# sourceMappingURL=index.d.mts.map
|