@pluv/io 0.3.9 → 0.4.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 +7 -7
- package/CHANGELOG.md +28 -0
- package/dist/index.d.ts +33 -30
- package/dist/index.js +196 -189
- package/dist/index.mjs +196 -189
- package/package.json +9 -9
- package/src/IORoom.ts +242 -212
- package/src/PluvIO.ts +191 -61
- package/src/types.ts +38 -7
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
2
|
+
> @pluv/io@0.4.1 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,10 +8,10 @@
|
|
|
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[
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m27.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m30.01 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 89ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m27.95 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 93ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2921ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.84 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b85a232: bumped dependencies
|
|
8
|
+
- Updated dependencies [b85a232]
|
|
9
|
+
- @pluv/crdt-yjs@0.3.8
|
|
10
|
+
- @pluv/types@0.2.0
|
|
11
|
+
|
|
12
|
+
## 0.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- bb2886b: allow sending multiple output types (broadcast, self, sync) per event
|
|
17
|
+
- ae679a8: updated offline presence to be set when reconnecting to a room
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 41943cf: bumped dependencies
|
|
22
|
+
- 0dd847e: updated storage to be synced when reconnected to the room
|
|
23
|
+
- 3518a83: bumped dependencies
|
|
24
|
+
- Updated dependencies [0dd847e]
|
|
25
|
+
- Updated dependencies [bb2886b]
|
|
26
|
+
- Updated dependencies [ae679a8]
|
|
27
|
+
- Updated dependencies [3518a83]
|
|
28
|
+
- @pluv/crdt-yjs@0.3.7
|
|
29
|
+
- @pluv/types@0.2.0
|
|
30
|
+
|
|
3
31
|
## 0.3.9
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, BaseUser, IOAuthorize, BaseIOAuthorize, InferIOInput,
|
|
1
|
+
import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, BaseUser, IOAuthorize, BaseIOAuthorize, InferIOInput, InferIOAuthorizeUser, InferIOAuthorize, Spread, InferIOOutputBroadcast, InferIOOutputSelf, InferIOOutputSync, Maybe, BaseClientEventRecord, BaseIOEventRecord } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { YjsDoc } from '@pluv/crdt-yjs';
|
|
4
4
|
|
|
@@ -79,12 +79,11 @@ declare global {
|
|
|
79
79
|
log: (...data: any[]) => void;
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
interface EventConfig<TContext extends JsonObject = {}, TData extends JsonObject = {},
|
|
82
|
+
interface EventConfig<TContext extends JsonObject = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}> {
|
|
83
83
|
input?: InputZodLike<TData>;
|
|
84
|
-
|
|
85
|
-
resolver: EventResolver<TContext, TData, TResult>;
|
|
84
|
+
resolver: EventResolver<TContext, TData, TResultBroadcast> | EventResolverObject<TContext, TData, TResultBroadcast, TResultSelf, TResultSync>;
|
|
86
85
|
}
|
|
87
|
-
type EventResolver<TContext extends JsonObject = {}, TData extends JsonObject = {},
|
|
86
|
+
type EventResolver<TContext extends JsonObject = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResultBroadcast | void>;
|
|
88
87
|
interface EventResolverContext<TContext extends JsonObject = {}> {
|
|
89
88
|
context: TContext;
|
|
90
89
|
doc: YjsDoc<any>;
|
|
@@ -104,8 +103,13 @@ interface EventResolverContext<TContext extends JsonObject = {}> {
|
|
|
104
103
|
session: WebSocketSession | null;
|
|
105
104
|
sessions: Map<string, WebSocketSession>;
|
|
106
105
|
}
|
|
107
|
-
type
|
|
108
|
-
|
|
106
|
+
type EventResolverObject<TContext extends JsonObject = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}> = {
|
|
107
|
+
broadcast?: EventResolver<TContext, TData, TResultBroadcast>;
|
|
108
|
+
self?: EventResolver<TContext, TData, TResultSelf>;
|
|
109
|
+
sync?: EventResolver<TContext, TData, TResultSync>;
|
|
110
|
+
};
|
|
111
|
+
type InferEventConfig<TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = {
|
|
112
|
+
[P in keyof TInput]: P extends string ? Id<EventConfig<TContext, TInput[P], TOutputBroadcast, TOutputSelf, TOutputSync>> : never;
|
|
109
113
|
};
|
|
110
114
|
type SendMessageOptions = {
|
|
111
115
|
type?: "broadcast";
|
|
@@ -179,82 +183,81 @@ interface AuthorizeModule {
|
|
|
179
183
|
interface IORoomListeners {
|
|
180
184
|
onDestroy: (encodedState: string) => void;
|
|
181
185
|
}
|
|
182
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {},
|
|
186
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = Partial<IORoomListeners> & {
|
|
183
187
|
authorize?: TAuthorize;
|
|
184
188
|
context: TContext;
|
|
185
189
|
debug: boolean;
|
|
186
|
-
events: InferEventConfig<TContext, TInput,
|
|
187
|
-
initialStorage?: () => MaybePromise<Maybe<string>>;
|
|
190
|
+
events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
188
191
|
platform: TPlatform;
|
|
189
192
|
};
|
|
190
193
|
interface WebsocketRegisterOptions {
|
|
191
|
-
token?: string;
|
|
194
|
+
token?: string | null;
|
|
192
195
|
}
|
|
193
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {},
|
|
196
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync> {
|
|
194
197
|
private readonly _context;
|
|
195
198
|
private readonly _debug;
|
|
196
199
|
private readonly _platform;
|
|
197
200
|
private _doc;
|
|
198
|
-
private _initialStorage;
|
|
199
201
|
private _listeners;
|
|
200
202
|
private _sessions;
|
|
201
203
|
private _uninitialize;
|
|
202
204
|
readonly _authorize: TAuthorize | null;
|
|
203
|
-
readonly _events: InferEventConfig<TContext, TInput,
|
|
205
|
+
readonly _events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
204
206
|
readonly id: string;
|
|
205
|
-
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TInput,
|
|
207
|
+
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>);
|
|
206
208
|
broadcast<TEvent extends keyof InferIOInput<this>>(event: TEvent, data: Id<InferIOInput<this>[TEvent]>): Promise<void>;
|
|
207
209
|
getSize(): number;
|
|
208
210
|
register(webSocket: InferWebSocketType<TPlatform>, options?: WebsocketRegisterOptions): Promise<void>;
|
|
209
211
|
private _broadcast;
|
|
210
212
|
private _emitQuitters;
|
|
211
213
|
private _emitRegistered;
|
|
212
|
-
private _emitStorageReceived;
|
|
213
|
-
private _emitUserJoined;
|
|
214
214
|
private _getAuthorizedUser;
|
|
215
215
|
private _getEventConfig;
|
|
216
|
+
private _getEventInputs;
|
|
217
|
+
private _getEventResolverObject;
|
|
216
218
|
private _initialize;
|
|
217
219
|
private _logDebug;
|
|
220
|
+
private _onClose;
|
|
221
|
+
private _onMessage;
|
|
218
222
|
private _parseMessage;
|
|
219
|
-
private _resolveMessage;
|
|
220
223
|
private _sendMessage;
|
|
221
224
|
private _sendBroadcastMessage;
|
|
222
225
|
private _sendSelfMessage;
|
|
223
226
|
private _sendSyncMessage;
|
|
224
227
|
}
|
|
225
228
|
|
|
226
|
-
type InferIOContext<TIO extends PluvIO<any, any, any, any, any>> = TIO extends PluvIO<any, any, infer IContext, any, any> ? IContext : never;
|
|
227
|
-
type InferIOPlatform<TIO extends PluvIO<any, any, any, any>> = TIO extends PluvIO<infer IPlatform, any, any, any, any> ? IPlatform : never;
|
|
228
|
-
type InferIORoom<TIO extends PluvIO<any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer
|
|
229
|
+
type InferIOContext<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<any, any, infer IContext, any, any, any, any> ? IContext : never;
|
|
230
|
+
type InferIOPlatform<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, any, any, any, any, any, any> ? IPlatform : never;
|
|
231
|
+
type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer IOutputBroadcast, infer IOutputSelf, infer IOutputSync> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutputBroadcast, IOutputSelf, IOutputSync> : never;
|
|
229
232
|
interface PluvIOListeners {
|
|
230
233
|
onRoomDeleted: (room: string, encodedState: string) => void;
|
|
231
234
|
onStorageUpdated: (room: string, encodedState: string) => void;
|
|
232
235
|
}
|
|
233
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> | null = null, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {},
|
|
236
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> | null = null, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = Partial<PluvIOListeners> & {
|
|
234
237
|
authorize?: TAuthorize;
|
|
235
238
|
context?: TContext;
|
|
236
239
|
debug?: boolean;
|
|
237
|
-
events?: InferEventConfig<TContext, TInput,
|
|
240
|
+
events?: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
238
241
|
initialStorage?: (room: string) => MaybePromise<Maybe<string>>;
|
|
239
242
|
platform: TPlatform;
|
|
240
243
|
};
|
|
241
244
|
interface GetRoomOptions {
|
|
242
245
|
debug?: boolean;
|
|
243
246
|
}
|
|
244
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {},
|
|
247
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync> {
|
|
245
248
|
private _context;
|
|
246
249
|
private _initialStorage;
|
|
247
250
|
private _listeners;
|
|
248
251
|
private _rooms;
|
|
249
252
|
readonly _authorize: TAuthorize | null;
|
|
250
253
|
readonly _debug: boolean;
|
|
251
|
-
readonly _events: InferEventConfig<TContext, TInput,
|
|
254
|
+
readonly _events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
252
255
|
readonly _platform: TPlatform;
|
|
253
|
-
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TInput,
|
|
256
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>);
|
|
254
257
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>>): Promise<string>;
|
|
255
|
-
event<TEvent extends string, TData extends JsonObject = {},
|
|
256
|
-
getRoom(room: string, options?: GetRoomOptions): IORoom<TPlatform, TAuthorize, TContext, TInput,
|
|
257
|
-
static merge<TIO1 extends PluvIO, TIO2 extends PluvIO>(first: TIO1, second: TIO2): PluvIO<InferIOPlatform<TIO1>, InferIOAuthorize<TIO1>, InferIOContext<TIO1>, Spread<[InferIOInput<TIO1>, InferIOInput<TIO2>]>, Spread<[
|
|
258
|
+
event<TEvent extends string, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}>(event: TEvent, config: EventConfig<TContext, TData, TResultBroadcast, TResultSelf, TResultSync>): PluvIO<TPlatform, TAuthorize, TContext, Spread<[TInput, EventRecord<TEvent, TData>]>, Spread<[TOutputBroadcast, TResultBroadcast]>, Spread<[TOutputSelf, TResultSelf]>, Spread<[TOutputSync, TResultSync]>>;
|
|
259
|
+
getRoom(room: string, options?: GetRoomOptions): IORoom<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
260
|
+
static merge<TIO1 extends PluvIO, TIO2 extends PluvIO>(first: TIO1, second: TIO2): PluvIO<InferIOPlatform<TIO1>, InferIOAuthorize<TIO1>, InferIOContext<TIO1>, Spread<[InferIOInput<TIO1>, InferIOInput<TIO2>]>, Spread<[InferIOOutputBroadcast<TIO1>, InferIOOutputBroadcast<TIO2>]>, Spread<[InferIOOutputSelf<TIO1>, InferIOOutputSelf<TIO2>]>, Spread<[InferIOOutputSync<TIO1>, InferIOOutputSync<TIO2>]>>;
|
|
258
261
|
private _logDebug;
|
|
259
262
|
private _purgeEmptyRooms;
|
|
260
263
|
}
|
|
@@ -266,6 +269,6 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
266
269
|
initialStorage?: (room: string) => MaybePromise<Maybe<string>>;
|
|
267
270
|
platform: TPlatform;
|
|
268
271
|
};
|
|
269
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired>, TContext, BaseClientEventRecord, BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired
|
|
272
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired>, TContext, BaseClientEventRecord, BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired>>, {}, {}>;
|
|
270
273
|
|
|
271
274
|
export { AbstractCloseEvent, AbstractErrorEvent, AbstractEvent, AbstractEventMap, AbstractListener, AbstractMessageEvent, AbstractPersistance, AbstractPlatform, AbstractPubSub, AbstractWebSocket, AbstractWebSocketConfig, AbstractWebSocketHandleErrorParams, AuthorizeModule, AuthorizeParams, ConvertWebSocketConfig, CreateIOParams, GetRoomOptions, IOPubSubEventMessage, IORoom, InferIORoom, InferWebSocketType, JWT, JWTEncodeParams, PluvIO, createIO };
|