@pluv/io 5.0.1 → 5.0.3
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/README.md +38 -42
- package/dist/index.d.mts +542 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1427 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +8 -8
- package/CHANGELOG.md +0 -2353
- package/eslint.config.mjs +0 -4
- package/src/AbstractPersistence.ts +0 -29
- package/src/AbstractPlatform.ts +0 -105
- package/src/AbstractPubSub.ts +0 -20
- package/src/AbstractWebSocket.ts +0 -134
- package/src/IORoom.ts +0 -1245
- package/src/Persistence.ts +0 -81
- package/src/PluvIO.ts +0 -239
- package/src/PluvProcedure.ts +0 -203
- package/src/PluvRouter.ts +0 -61
- package/src/PluvServer.ts +0 -487
- package/src/PubSub.ts +0 -70
- package/src/authorize.ts +0 -76
- package/src/constants.ts +0 -6
- package/src/createIO.ts +0 -55
- package/src/index.ts +0 -55
- package/src/types.ts +0 -287
- package/src/utils/index.ts +0 -2
- package/src/utils/oneLine.ts +0 -7
- package/src/utils/pickBy.ts +0 -16
- package/src/version.ts +0 -3
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -14
package/src/index.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export type { CrdtLibraryType } from "@pluv/crdt";
|
|
2
|
-
export type { BaseUser, EventMessage, EventRecord, IOEventMessage } from "@pluv/types";
|
|
3
|
-
export { AbstractPersistence } from "./AbstractPersistence";
|
|
4
|
-
export { AbstractPlatform } from "./AbstractPlatform";
|
|
5
|
-
export type {
|
|
6
|
-
AbstractPlatformConfig,
|
|
7
|
-
ConvertWebSocketConfig,
|
|
8
|
-
InferInitContextType,
|
|
9
|
-
InferPlatformWebSocketType,
|
|
10
|
-
InferRoomContextType,
|
|
11
|
-
} from "./AbstractPlatform";
|
|
12
|
-
export { AbstractPubSub } from "./AbstractPubSub";
|
|
13
|
-
export type { IOPubSubEventMessage } from "./AbstractPubSub";
|
|
14
|
-
export { AbstractWebSocket } from "./AbstractWebSocket";
|
|
15
|
-
export type {
|
|
16
|
-
AbstractCloseEvent,
|
|
17
|
-
AbstractErrorEvent,
|
|
18
|
-
AbstractEvent,
|
|
19
|
-
AbstractEventMap,
|
|
20
|
-
AbstractListener,
|
|
21
|
-
AbstractMessageEvent,
|
|
22
|
-
AbstractWebSocketConfig,
|
|
23
|
-
AbstractWebSocketHandleErrorParams,
|
|
24
|
-
} from "./AbstractWebSocket";
|
|
25
|
-
export { authorize } from "./authorize";
|
|
26
|
-
export type { AuthorizeModule, AuthorizeParams, JWT, JWTEncodeParams } from "./authorize";
|
|
27
|
-
export { createIO } from "./createIO";
|
|
28
|
-
export type { CreateIOParams } from "./createIO";
|
|
29
|
-
export type { IORoom } from "./IORoom";
|
|
30
|
-
export { PluvIO } from "./PluvIO";
|
|
31
|
-
export type { PluvIOConfig, ServerConfig } from "./PluvIO";
|
|
32
|
-
export { PluvProcedure } from "./PluvProcedure";
|
|
33
|
-
export type { PluvProcedureConfig } from "./PluvProcedure";
|
|
34
|
-
export { PluvRouter } from "./PluvRouter";
|
|
35
|
-
export type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
36
|
-
export { PluvServer } from "./PluvServer";
|
|
37
|
-
export type { CreateRoomOptions, InferIORoom, PluvServerConfig } from "./PluvServer";
|
|
38
|
-
export type {
|
|
39
|
-
GetInitialStorageFn,
|
|
40
|
-
HandleMode,
|
|
41
|
-
IORoomDestroyedEvent,
|
|
42
|
-
IORoomListenerEvent,
|
|
43
|
-
IORoomMessageEvent,
|
|
44
|
-
IOStorageUpdatedEvent,
|
|
45
|
-
IOUserConnectedEvent,
|
|
46
|
-
IOUserDisconnectedEvent,
|
|
47
|
-
PlatformConfig,
|
|
48
|
-
PluvContext,
|
|
49
|
-
PluvIOAuthorize,
|
|
50
|
-
PluvIOLimits,
|
|
51
|
-
PluvIOListeners,
|
|
52
|
-
WebSocketRegistrationMode,
|
|
53
|
-
WebSocketSerializedState,
|
|
54
|
-
WebSocketSession,
|
|
55
|
-
} from "./types";
|
package/src/types.ts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
|
-
import type {
|
|
3
|
-
BaseUser,
|
|
4
|
-
CrdtDocLike,
|
|
5
|
-
EventRecord,
|
|
6
|
-
IOAuthorize,
|
|
7
|
-
Id,
|
|
8
|
-
InferEventMessage,
|
|
9
|
-
InferEventsOutput,
|
|
10
|
-
InferIOAuthorizeUser,
|
|
11
|
-
InputZodLike,
|
|
12
|
-
JsonObject,
|
|
13
|
-
Maybe,
|
|
14
|
-
MaybePromise,
|
|
15
|
-
UndefinedProps,
|
|
16
|
-
} from "@pluv/types";
|
|
17
|
-
import type {
|
|
18
|
-
AbstractPlatform,
|
|
19
|
-
InferInitContextType,
|
|
20
|
-
InferPlatformWebSocketSource,
|
|
21
|
-
InferPlatformWebSocketType,
|
|
22
|
-
InferRoomContextType,
|
|
23
|
-
} from "./AbstractPlatform";
|
|
24
|
-
import type { AbstractWebSocket } from "./AbstractWebSocket";
|
|
25
|
-
import type { PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
26
|
-
|
|
27
|
-
export type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> =
|
|
28
|
-
MaybePromise<TContext> | ((params: InferRoomContextType<TPlatform>) => MaybePromise<TContext>);
|
|
29
|
-
|
|
30
|
-
export type EventResolverKind = "broadcast" | "self" | "sync";
|
|
31
|
-
|
|
32
|
-
export type EventResolver<
|
|
33
|
-
TKind extends EventResolverKind = EventResolverKind,
|
|
34
|
-
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
35
|
-
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null,
|
|
36
|
-
TContext extends Record<string, any> = {},
|
|
37
|
-
TInput extends JsonObject = {},
|
|
38
|
-
TOutput extends EventRecord<string, any> = {},
|
|
39
|
-
> = (
|
|
40
|
-
data: TInput,
|
|
41
|
-
context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>,
|
|
42
|
-
) => MaybePromise<TOutput | void>;
|
|
43
|
-
|
|
44
|
-
export interface EventResolverContext<
|
|
45
|
-
TKind extends EventResolverKind = EventResolverKind,
|
|
46
|
-
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
47
|
-
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null,
|
|
48
|
-
TContext extends Record<string, any> = {},
|
|
49
|
-
> {
|
|
50
|
-
context: TContext;
|
|
51
|
-
doc: CrdtDocLike<any, any>;
|
|
52
|
-
garbageCollect: () => Promise<void>;
|
|
53
|
-
platform: TPlatform;
|
|
54
|
-
presence: JsonObject | null;
|
|
55
|
-
room: string;
|
|
56
|
-
session: TKind extends "sync"
|
|
57
|
-
? WebSocketSession<TAuthorize> | null
|
|
58
|
-
: WebSocketSession<TAuthorize>;
|
|
59
|
-
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
60
|
-
time: number;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type SendMessageOptions =
|
|
64
|
-
{ type?: "broadcast"; sessionIds?: readonly string[] } | { type: "self" } | { type: "sync" };
|
|
65
|
-
|
|
66
|
-
export interface WebSocketSessionTimers {
|
|
67
|
-
ping: number;
|
|
68
|
-
presence: number | null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface WebSocketSerializedState {
|
|
72
|
-
presence: JsonObject | null;
|
|
73
|
-
quit: boolean;
|
|
74
|
-
room: string;
|
|
75
|
-
timers: WebSocketSessionTimers;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type WebSocketSession<TAuthorize extends IOAuthorize<any, any> | null = null> =
|
|
79
|
-
WebSocketSerializedState & {
|
|
80
|
-
id: string;
|
|
81
|
-
user: InferIOAuthorizeUser<TAuthorize>;
|
|
82
|
-
webSocket: AbstractWebSocket;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export type MergeEventRecords<
|
|
86
|
-
TEventRecords extends EventRecord<string, any>[],
|
|
87
|
-
TRoot extends EventRecord<string, any> = {},
|
|
88
|
-
> = TEventRecords extends [
|
|
89
|
-
infer IHead extends EventRecord<string, any>,
|
|
90
|
-
...infer ITail extends EventRecord<string, any>[],
|
|
91
|
-
]
|
|
92
|
-
? MergeEventRecords<
|
|
93
|
-
ITail,
|
|
94
|
-
Omit<TRoot, keyof IHead> & {
|
|
95
|
-
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
96
|
-
}
|
|
97
|
-
>
|
|
98
|
-
: Id<TRoot>;
|
|
99
|
-
|
|
100
|
-
export type GetInitialStorageEvent<TContext extends Record<string, any>> = {
|
|
101
|
-
context: TContext;
|
|
102
|
-
room: string;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export type GetInitialStorageFn<TContext extends Record<string, any>> = (
|
|
106
|
-
event: GetInitialStorageEvent<TContext>,
|
|
107
|
-
) => MaybePromise<Maybe<string>>;
|
|
108
|
-
|
|
109
|
-
export type HandleMode = "io" | "fetch";
|
|
110
|
-
export type WebSocketRegistrationMode = "attached" | "detached";
|
|
111
|
-
|
|
112
|
-
export interface PlatformConfig {
|
|
113
|
-
authorize: {
|
|
114
|
-
secret?: boolean;
|
|
115
|
-
};
|
|
116
|
-
requireAuth?: boolean;
|
|
117
|
-
handleMode: HandleMode;
|
|
118
|
-
registrationMode: WebSocketRegistrationMode;
|
|
119
|
-
listeners: {
|
|
120
|
-
onRoomDestroyed?: boolean;
|
|
121
|
-
onRoomMessage?: boolean;
|
|
122
|
-
onStorageDestroyed?: boolean;
|
|
123
|
-
onStorageUpdated?: boolean;
|
|
124
|
-
onUserConnected?: boolean;
|
|
125
|
-
onUserDisconnected?: boolean;
|
|
126
|
-
};
|
|
127
|
-
router?: boolean;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type ResolvedPluvIOAuthorize<
|
|
131
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
132
|
-
TUser extends BaseUser = any,
|
|
133
|
-
> = { user: InputZodLike<TUser> } & UndefinedProps<
|
|
134
|
-
{ secret?: string },
|
|
135
|
-
Exclude<"secret", InferPlatformAuthorizeProperties<TPlatform>>
|
|
136
|
-
>;
|
|
137
|
-
|
|
138
|
-
export type PluvIOAuthorize<
|
|
139
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
140
|
-
TUser extends BaseUser | null = any,
|
|
141
|
-
TContext extends Record<string, unknown> = {},
|
|
142
|
-
> =
|
|
143
|
-
| (TUser extends BaseUser ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null)
|
|
144
|
-
| ((
|
|
145
|
-
context: TContext,
|
|
146
|
-
) => TUser extends BaseUser ? ResolvedPluvIOAuthorize<TPlatform, TUser> : null);
|
|
147
|
-
|
|
148
|
-
export interface PluvIOLimits {
|
|
149
|
-
/**
|
|
150
|
-
* @description Maximum size of presence object in bytes
|
|
151
|
-
*/
|
|
152
|
-
presenceMaxSize?: number | null;
|
|
153
|
-
/**
|
|
154
|
-
* @description Maximum size of storage state in bytes
|
|
155
|
-
*/
|
|
156
|
-
storageMaxSize?: number | null;
|
|
157
|
-
/**
|
|
158
|
-
* @description Maximum length of user id in characters
|
|
159
|
-
*/
|
|
160
|
-
userIdMaxLength?: number | null;
|
|
161
|
-
/**
|
|
162
|
-
* @description Maximum size of user object in bytes
|
|
163
|
-
*/
|
|
164
|
-
userMaxSize?: number | null;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export type BasePluvIOListeners<
|
|
168
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
169
|
-
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
170
|
-
TContext extends Record<string, any>,
|
|
171
|
-
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
172
|
-
> = {
|
|
173
|
-
onRoomDestroyed: (event: IORoomDestroyedEvent<TPlatform, TContext>) => void;
|
|
174
|
-
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
175
|
-
onStorageDestroyed: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
176
|
-
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
177
|
-
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
178
|
-
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export type PluvIOListeners<
|
|
182
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
183
|
-
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
184
|
-
TContext extends Record<string, any>,
|
|
185
|
-
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
186
|
-
> = UndefinedProps<
|
|
187
|
-
BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>,
|
|
188
|
-
Exclude<
|
|
189
|
-
keyof BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>,
|
|
190
|
-
InferPlatformListeners<TPlatform>
|
|
191
|
-
>
|
|
192
|
-
>;
|
|
193
|
-
|
|
194
|
-
export type PluvIORouter<
|
|
195
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
196
|
-
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
197
|
-
TContext extends Record<string, any>,
|
|
198
|
-
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
199
|
-
> =
|
|
200
|
-
InferPlatformRouter<TPlatform> extends true
|
|
201
|
-
? { router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents> }
|
|
202
|
-
: { router?: undefined };
|
|
203
|
-
|
|
204
|
-
export type InferPlatformConfig<TPlatform extends AbstractPlatform<any, any, any, any>> =
|
|
205
|
-
TPlatform extends AbstractPlatform<any, any, any, infer IConfig> ? IConfig : never;
|
|
206
|
-
|
|
207
|
-
export type InferPlatformAuthorizeProperties<
|
|
208
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
209
|
-
> = keyof {
|
|
210
|
-
[
|
|
211
|
-
P in keyof PlatformConfig["authorize"] as InferPlatformConfig<TPlatform>["authorize"][P] extends
|
|
212
|
-
true | undefined
|
|
213
|
-
? P
|
|
214
|
-
: never
|
|
215
|
-
]: true;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
219
|
-
[
|
|
220
|
-
P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends
|
|
221
|
-
true | undefined
|
|
222
|
-
? P
|
|
223
|
-
: never
|
|
224
|
-
]: true;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export type InferPlatformRouter<TPlatform extends AbstractPlatform<any, any, any, any>> =
|
|
228
|
-
InferPlatformConfig<TPlatform>["router"];
|
|
229
|
-
|
|
230
|
-
export type IORoomListenerEvent<
|
|
231
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
232
|
-
TContext extends Record<string, any>,
|
|
233
|
-
> = {
|
|
234
|
-
context: TContext;
|
|
235
|
-
encodedState: string | null;
|
|
236
|
-
platform: TPlatform;
|
|
237
|
-
room: string;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
export type IORoomDestroyedEvent<
|
|
241
|
-
TPlatform extends AbstractPlatform<any, any, any, any>,
|
|
242
|
-
TContext extends Record<string, any>,
|
|
243
|
-
> = {
|
|
244
|
-
context: TContext;
|
|
245
|
-
platform: TPlatform;
|
|
246
|
-
room: string;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
export type IORoomMessageEvent<
|
|
250
|
-
TPlatform extends AbstractPlatform<any>,
|
|
251
|
-
TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null,
|
|
252
|
-
TContext extends Record<string, any>,
|
|
253
|
-
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
254
|
-
> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
255
|
-
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
256
|
-
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
257
|
-
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
export type IOStorageUpdatedEvent<
|
|
261
|
-
TPlatform extends AbstractPlatform<any>,
|
|
262
|
-
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null,
|
|
263
|
-
TContext extends Record<string, any>,
|
|
264
|
-
> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
265
|
-
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
266
|
-
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export type IOUserConnectedEvent<
|
|
270
|
-
TPlatform extends AbstractPlatform<any>,
|
|
271
|
-
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null,
|
|
272
|
-
TContext extends Record<string, any>,
|
|
273
|
-
> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
274
|
-
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
275
|
-
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export type IOUserDisconnectedEvent<
|
|
279
|
-
TPlatform extends AbstractPlatform<any>,
|
|
280
|
-
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null,
|
|
281
|
-
TContext extends Record<string, any>,
|
|
282
|
-
> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
283
|
-
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
export type WebSocketType<TPlatform extends AbstractPlatform> =
|
|
287
|
-
InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
package/src/utils/index.ts
DELETED
package/src/utils/oneLine.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const oneLine = (strings: TemplateStringsArray, ...values: unknown[]): string => {
|
|
2
|
-
return strings
|
|
3
|
-
.map((str) => str.replace(/\s+/g, " "))
|
|
4
|
-
.reduce((acc, str, i) => acc + str + (i < values.length ? values[i] : ""), "")
|
|
5
|
-
.replace(/\s+/g, " ")
|
|
6
|
-
.trim();
|
|
7
|
-
};
|
package/src/utils/pickBy.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const pickBy = <T extends Record<string, any>>(
|
|
2
|
-
obj: T,
|
|
3
|
-
by: (value: T[keyof T]) => boolean,
|
|
4
|
-
): Partial<T> => {
|
|
5
|
-
const result: Partial<T> = {};
|
|
6
|
-
const keys: (keyof T)[] = Object.keys(obj);
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < keys.length; ++i) {
|
|
9
|
-
const key = keys[i];
|
|
10
|
-
const value = obj[key];
|
|
11
|
-
|
|
12
|
-
if (by(value)) result[key] = value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return result;
|
|
16
|
-
};
|
package/src/version.ts
DELETED
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED