@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/io@0.3.9 build /home/runner/work/pluv/pluv/packages/io
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
  CLI Building entry: src/index.ts
@@ -8,10 +8,10 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 29.45 KB
12
- CJS ⚡️ Build success in 105ms
13
- ESM dist/index.mjs 27.39 KB
14
- ESM ⚡️ Build success in 107ms
11
+ CJS dist/index.js 30.01 KB
12
+ CJS ⚡️ Build success in 89ms
13
+ ESM dist/index.mjs 27.95 KB
14
+ ESM ⚡️ Build success in 93ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 2633ms
17
- DTS dist/index.d.ts 12.84 KB
16
+ DTS ⚡️ Build success in 2921ms
17
+ DTS dist/index.d.ts 14.84 KB
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, Maybe, InferIOAuthorizeUser, InferIOAuthorize, Spread, BaseClientEventRecord, BaseIOEventRecord } from '@pluv/types';
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 = {}, TResult extends EventRecord<string, any> = {}> {
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
- options?: SendMessageOptions;
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 = {}, TResult extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResult | void>;
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 InferEventConfig<TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutput extends EventRecord<string, any> = {}> = {
108
- [P in keyof TInput]: P extends string ? Id<EventConfig<TContext, TInput[P], TOutput>> : never;
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> = {}, TOutput extends EventRecord<string, any> = {}> = Partial<IORoomListeners> & {
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, TOutput>;
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> = {}, TOutput extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutput> {
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, TOutput>;
205
+ readonly _events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
204
206
  readonly id: string;
205
- constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
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 IOutput> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutput> : never;
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> = {}, TOutput extends EventRecord<string, any> = {}> = Partial<PluvIOListeners> & {
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, TOutput>;
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> = {}, TOutput extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutput> {
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, TOutput>;
254
+ readonly _events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
252
255
  readonly _platform: TPlatform;
253
- constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
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 = {}, TResult extends EventRecord<string, any> = {}>(event: TEvent, config: EventConfig<TContext, TData, TResult>): PluvIO<TPlatform, TAuthorize, TContext, Spread<[TInput, EventRecord<TEvent, TData>]>, Spread<[TOutput, TResult]>>;
256
- getRoom(room: string, options?: GetRoomOptions): IORoom<TPlatform, TAuthorize, TContext, TInput, TOutput>;
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<[InferIOOutput<TIO1>, InferIOOutput<TIO2>]>>;
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 };