@pluv/types 2.0.1 → 2.1.0

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/types@2.0.1 build /home/runner/work/pluv/pluv/packages/types
2
+ > @pluv/types@2.1.0 build /home/runner/work/pluv/pluv/packages/types
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
+ ESM dist/index.mjs 197.00 B
12
+ ESM ⚡️ Build success in 34ms
11
13
  CJS dist/index.js 1.21 KB
12
14
  CJS ⚡️ Build success in 35ms
13
- ESM dist/index.mjs 197.00 B
14
- ESM ⚡️ Build success in 36ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1251ms
17
- DTS dist/index.d.mts 14.71 KB
18
- DTS dist/index.d.ts 14.71 KB
16
+ DTS ⚡️ Build success in 1274ms
17
+ DTS dist/index.d.mts 18.11 KB
18
+ DTS dist/index.d.ts 18.11 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @pluv/types
2
2
 
3
+ ## 2.1.0
4
+
5
+ ## 2.0.2
6
+
3
7
  ## 2.0.1
4
8
 
5
9
  ## 2.0.0
package/dist/index.d.mts CHANGED
@@ -242,13 +242,30 @@ interface AuthorizationState<TIO extends IOLike> {
242
242
  token: string | null;
243
243
  user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
244
244
  }
245
- type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
246
- type OtherNotifierSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: Id<UserInfo<TIO, TPresence>> | null) => void;
245
+ type OtherSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: Id<UserInfo<TIO, TPresence>> | null) => void;
246
+ type OtherSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>) => () => void;
247
+ type OthersSubscriptionEvent<TIO extends IOLike, TPresence extends JsonObject> = {
248
+ kind: "clear";
249
+ } | {
250
+ kind: "enter";
251
+ user: Id<UserInfo<TIO, TPresence>>;
252
+ } | {
253
+ kind: "leave";
254
+ user: Id<UserInfo<TIO, TPresence>>;
255
+ } | {
256
+ kind: "sync";
257
+ users: readonly Id<UserInfo<TIO, TPresence>>[];
258
+ } | {
259
+ kind: "update";
260
+ user: Id<UserInfo<TIO, TPresence>>;
261
+ };
262
+ type OthersSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: readonly Id<UserInfo<TIO, TPresence>>[], event: OthersSubscriptionEvent<TIO, TPresence>) => void;
263
+ type OthersSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (callback: OthersSubscriptionCallback<TIO, TPresence>) => () => void;
247
264
  interface StateNotifierSubjects<TIO extends IOLike, TPresence extends JsonObject> {
248
265
  connection: Subject<Id<WebSocketState<TIO>>>;
249
266
  "my-presence": Subject<TPresence | null>;
250
- myself: Subject<Readonly<Id<UserInfo<TIO>>> | null>;
251
- others: Subject<readonly Id<UserInfo<TIO>>[]>;
267
+ myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
268
+ others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
252
269
  "storage-loaded": Subject<boolean>;
253
270
  }
254
271
  type InferSubjectValue<TIO extends IOLike, TPresence extends JsonObject, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = StateNotifierSubjects<TIO, TPresence>[TSubject] extends Subject<infer IValue> ? Id<IValue> : never;
@@ -282,14 +299,42 @@ interface WebSocketState<TIO extends IOLike> {
282
299
  connection: WebSocketConnection;
283
300
  webSocket: WebSocket | null;
284
301
  }
302
+ type BroadcastProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = (<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(event: TEvent, data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>) => Promise<void>) & {
303
+ [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
304
+ };
305
+ type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
306
+ type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>) => () => void;
307
+ type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
308
+ [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
309
+ };
310
+ type StorageSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>, TKey extends keyof TStorage> = (value: InferCrdtJson<TStorage[TKey]>) => void;
311
+ type StorageSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = <TKey extends keyof TStorage>(key: TKey, fn: StorageSubscriptionCallback<TStorage, TKey>) => () => void;
312
+ type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> = (value: {
313
+ [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
314
+ }) => void;
315
+ type StorageRootSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = (callback: StorageRootSubscriptionCallback<TStorage>) => () => void;
316
+ type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> = StorageSubscriptionFn<TStorage> & StorageRootSubscriptionFn<TStorage> & {
317
+ [PKey in keyof TStorage]: (callback: StorageSubscriptionCallback<TStorage, PKey>) => () => void;
318
+ };
319
+ type SubscribeFn<TValue extends unknown> = (callback: (value: TValue) => void) => () => void;
320
+ type SubscribeProxy<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TEvents extends PluvRouterEventConfig> = (<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => () => void) & {
321
+ connection: SubscribeFn<Id<WebSocketState<TIO>>>;
322
+ event: EventProxy<TIO, TEvents>;
323
+ myPresence: SubscribeFn<TPresence | null>;
324
+ myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
325
+ other: OtherSubscriptionFn<TIO, TPresence>;
326
+ others: OthersSubscriptionFn<TIO, TPresence>;
327
+ storage: StorageProxy<TStorage>;
328
+ storageLoaded: SubscribeFn<boolean>;
329
+ };
285
330
  interface RoomLike<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig = {}> {
286
331
  id: string;
287
332
  storageLoaded: boolean;
288
- broadcast<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(event: TEvent, data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>): void;
333
+ broadcast: BroadcastProxy<TIO, TEvents>;
289
334
  canRedo(): boolean;
290
335
  canUndo(): boolean;
291
336
  getDoc(): CrdtDocLike<TStorage>;
292
- event<TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>): () => void;
337
+ event: EventProxy<TIO, TEvents>;
293
338
  getConnection(): WebSocketConnection;
294
339
  getMyPresence(): TPresence;
295
340
  getMyself(): Id<UserInfo<TIO, TPresence>> | null;
@@ -298,16 +343,16 @@ interface RoomLike<TIO extends IOLike, TPresence extends JsonObject = {}, TStora
298
343
  getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
299
344
  getStorageJson(): InferCrdtJson<TStorage> | null;
300
345
  getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
301
- other(connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO, TPresence>): () => void;
346
+ other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
302
347
  redo(): void;
303
- storage<TKey extends keyof TStorage>(key: TKey, fn: (value: InferCrdtJson<TStorage[TKey]>) => void): () => void;
348
+ storage: StorageProxy<TStorage>;
304
349
  storageRoot(fn: (value: {
305
350
  [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
306
351
  }) => void): () => void;
307
- subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>): () => void;
352
+ subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
308
353
  transact(fn: (storage: TStorage) => void, origin?: string): void;
309
354
  undo(): void;
310
355
  updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
311
356
  }
312
357
 
313
- export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, ConnectionState, type Constructable, type CrdtDocLike, type CrdtType, type DeepPartial, type DeepWriteable, type DocApplyEncodedStateParams, type DocBatchApplyEncodedStateParams, type DocSubscribeCallbackParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventRecord, type GetEventMessage, type IOAuthorize, type IOAuthorizeEventMessage, type IOEventMessage, type IOLike, type IORouterLike, type Id, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOInput, type InferIOOutput, type InputZodLike, type Json, type JsonObject, type JsonPrimitive, type Maybe, type MaybePromise, type MaybeReadonlyArray, type MergeEvents, type NonNilProps, type OptionalProps, type OtherNotifierSubscriptionCallback, type ProcedureLike, type RoomLike, type Spread, type SpreadProperties, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
358
+ export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, type BroadcastProxy, ConnectionState, type Constructable, type CrdtDocLike, type CrdtType, type DeepPartial, type DeepWriteable, type DocApplyEncodedStateParams, type DocBatchApplyEncodedStateParams, type DocSubscribeCallbackParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventProxy, type EventRecord, type GetEventMessage, type IOAuthorize, type IOAuthorizeEventMessage, type IOEventMessage, type IOLike, type IORouterLike, type Id, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOInput, type InferIOOutput, type InputZodLike, type Json, type JsonObject, type JsonPrimitive, type Maybe, type MaybePromise, type MaybeReadonlyArray, type MergeEvents, type NonNilProps, type OptionalProps, type OtherSubscriptionCallback, type OtherSubscriptionFn, type OthersSubscriptionCallback, type OthersSubscriptionEvent, type OthersSubscriptionFn, type ProcedureLike, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, type StorageSubscriptionCallback, type StorageSubscriptionFn, type SubscribeFn, type SubscribeProxy, type SubscriptionCallback, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
package/dist/index.d.ts CHANGED
@@ -242,13 +242,30 @@ interface AuthorizationState<TIO extends IOLike> {
242
242
  token: string | null;
243
243
  user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
244
244
  }
245
- type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
246
- type OtherNotifierSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: Id<UserInfo<TIO, TPresence>> | null) => void;
245
+ type OtherSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: Id<UserInfo<TIO, TPresence>> | null) => void;
246
+ type OtherSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>) => () => void;
247
+ type OthersSubscriptionEvent<TIO extends IOLike, TPresence extends JsonObject> = {
248
+ kind: "clear";
249
+ } | {
250
+ kind: "enter";
251
+ user: Id<UserInfo<TIO, TPresence>>;
252
+ } | {
253
+ kind: "leave";
254
+ user: Id<UserInfo<TIO, TPresence>>;
255
+ } | {
256
+ kind: "sync";
257
+ users: readonly Id<UserInfo<TIO, TPresence>>[];
258
+ } | {
259
+ kind: "update";
260
+ user: Id<UserInfo<TIO, TPresence>>;
261
+ };
262
+ type OthersSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (value: readonly Id<UserInfo<TIO, TPresence>>[], event: OthersSubscriptionEvent<TIO, TPresence>) => void;
263
+ type OthersSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (callback: OthersSubscriptionCallback<TIO, TPresence>) => () => void;
247
264
  interface StateNotifierSubjects<TIO extends IOLike, TPresence extends JsonObject> {
248
265
  connection: Subject<Id<WebSocketState<TIO>>>;
249
266
  "my-presence": Subject<TPresence | null>;
250
- myself: Subject<Readonly<Id<UserInfo<TIO>>> | null>;
251
- others: Subject<readonly Id<UserInfo<TIO>>[]>;
267
+ myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
268
+ others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
252
269
  "storage-loaded": Subject<boolean>;
253
270
  }
254
271
  type InferSubjectValue<TIO extends IOLike, TPresence extends JsonObject, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = StateNotifierSubjects<TIO, TPresence>[TSubject] extends Subject<infer IValue> ? Id<IValue> : never;
@@ -282,14 +299,42 @@ interface WebSocketState<TIO extends IOLike> {
282
299
  connection: WebSocketConnection;
283
300
  webSocket: WebSocket | null;
284
301
  }
302
+ type BroadcastProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = (<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(event: TEvent, data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>) => Promise<void>) & {
303
+ [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
304
+ };
305
+ type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
306
+ type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>) => () => void;
307
+ type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
308
+ [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
309
+ };
310
+ type StorageSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>, TKey extends keyof TStorage> = (value: InferCrdtJson<TStorage[TKey]>) => void;
311
+ type StorageSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = <TKey extends keyof TStorage>(key: TKey, fn: StorageSubscriptionCallback<TStorage, TKey>) => () => void;
312
+ type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> = (value: {
313
+ [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
314
+ }) => void;
315
+ type StorageRootSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = (callback: StorageRootSubscriptionCallback<TStorage>) => () => void;
316
+ type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> = StorageSubscriptionFn<TStorage> & StorageRootSubscriptionFn<TStorage> & {
317
+ [PKey in keyof TStorage]: (callback: StorageSubscriptionCallback<TStorage, PKey>) => () => void;
318
+ };
319
+ type SubscribeFn<TValue extends unknown> = (callback: (value: TValue) => void) => () => void;
320
+ type SubscribeProxy<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TEvents extends PluvRouterEventConfig> = (<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => () => void) & {
321
+ connection: SubscribeFn<Id<WebSocketState<TIO>>>;
322
+ event: EventProxy<TIO, TEvents>;
323
+ myPresence: SubscribeFn<TPresence | null>;
324
+ myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
325
+ other: OtherSubscriptionFn<TIO, TPresence>;
326
+ others: OthersSubscriptionFn<TIO, TPresence>;
327
+ storage: StorageProxy<TStorage>;
328
+ storageLoaded: SubscribeFn<boolean>;
329
+ };
285
330
  interface RoomLike<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig = {}> {
286
331
  id: string;
287
332
  storageLoaded: boolean;
288
- broadcast<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(event: TEvent, data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>): void;
333
+ broadcast: BroadcastProxy<TIO, TEvents>;
289
334
  canRedo(): boolean;
290
335
  canUndo(): boolean;
291
336
  getDoc(): CrdtDocLike<TStorage>;
292
- event<TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>): () => void;
337
+ event: EventProxy<TIO, TEvents>;
293
338
  getConnection(): WebSocketConnection;
294
339
  getMyPresence(): TPresence;
295
340
  getMyself(): Id<UserInfo<TIO, TPresence>> | null;
@@ -298,16 +343,16 @@ interface RoomLike<TIO extends IOLike, TPresence extends JsonObject = {}, TStora
298
343
  getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
299
344
  getStorageJson(): InferCrdtJson<TStorage> | null;
300
345
  getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
301
- other(connectionId: string, callback: OtherNotifierSubscriptionCallback<TIO, TPresence>): () => void;
346
+ other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
302
347
  redo(): void;
303
- storage<TKey extends keyof TStorage>(key: TKey, fn: (value: InferCrdtJson<TStorage[TKey]>) => void): () => void;
348
+ storage: StorageProxy<TStorage>;
304
349
  storageRoot(fn: (value: {
305
350
  [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
306
351
  }) => void): () => void;
307
- subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>): () => void;
352
+ subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
308
353
  transact(fn: (storage: TStorage) => void, origin?: string): void;
309
354
  undo(): void;
310
355
  updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
311
356
  }
312
357
 
313
- export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, ConnectionState, type Constructable, type CrdtDocLike, type CrdtType, type DeepPartial, type DeepWriteable, type DocApplyEncodedStateParams, type DocBatchApplyEncodedStateParams, type DocSubscribeCallbackParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventRecord, type GetEventMessage, type IOAuthorize, type IOAuthorizeEventMessage, type IOEventMessage, type IOLike, type IORouterLike, type Id, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOInput, type InferIOOutput, type InputZodLike, type Json, type JsonObject, type JsonPrimitive, type Maybe, type MaybePromise, type MaybeReadonlyArray, type MergeEvents, type NonNilProps, type OptionalProps, type OtherNotifierSubscriptionCallback, type ProcedureLike, type RoomLike, type Spread, type SpreadProperties, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
358
+ export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, type BroadcastProxy, ConnectionState, type Constructable, type CrdtDocLike, type CrdtType, type DeepPartial, type DeepWriteable, type DocApplyEncodedStateParams, type DocBatchApplyEncodedStateParams, type DocSubscribeCallbackParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventProxy, type EventRecord, type GetEventMessage, type IOAuthorize, type IOAuthorizeEventMessage, type IOEventMessage, type IOLike, type IORouterLike, type Id, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOInput, type InferIOOutput, type InputZodLike, type Json, type JsonObject, type JsonPrimitive, type Maybe, type MaybePromise, type MaybeReadonlyArray, type MergeEvents, type NonNilProps, type OptionalProps, type OtherSubscriptionCallback, type OtherSubscriptionFn, type OthersSubscriptionCallback, type OthersSubscriptionEvent, type OthersSubscriptionFn, type ProcedureLike, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, type StorageSubscriptionCallback, type StorageSubscriptionFn, type SubscribeFn, type SubscribeProxy, type SubscriptionCallback, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/types",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "@pluv/io shared types",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -16,11 +16,11 @@
16
16
  "access": "public"
17
17
  },
18
18
  "devDependencies": {
19
- "eslint": "^9.25.1",
19
+ "eslint": "^9.26.0",
20
20
  "tsup": "^8.4.0",
21
21
  "typescript": "^5.8.3",
22
- "@pluv/tsconfig": "^2.0.1",
23
- "eslint-config-pluv": "^2.0.1"
22
+ "@pluv/tsconfig": "^2.1.0",
23
+ "eslint-config-pluv": "^2.1.0"
24
24
  },
25
25
  "dependencies": {
26
26
  "wonka": "^6.3.5"
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ export type {
21
21
  BaseClientMessage,
22
22
  BaseIOEventRecord,
23
23
  BaseUser,
24
+ BroadcastProxy,
24
25
  CrdtDocLike,
25
26
  CrdtType,
26
27
  DocApplyEncodedStateParams,
@@ -28,6 +29,7 @@ export type {
28
29
  DocSubscribeCallbackParams,
29
30
  EventMessage,
30
31
  EventNotifierSubscriptionCallback,
32
+ EventProxy,
31
33
  EventRecord,
32
34
  GetEventMessage,
33
35
  InferEventMessage,
@@ -44,9 +46,22 @@ export type {
44
46
  IOLike,
45
47
  IORouterLike,
46
48
  MergeEvents,
47
- OtherNotifierSubscriptionCallback,
49
+ OthersSubscriptionCallback,
50
+ OthersSubscriptionEvent,
51
+ OthersSubscriptionFn,
52
+ OtherSubscriptionCallback,
53
+ OtherSubscriptionFn,
48
54
  ProcedureLike,
49
55
  RoomLike,
56
+ StateNotifierSubjects,
57
+ StorageProxy,
58
+ StorageRootSubscriptionCallback,
59
+ StorageRootSubscriptionFn,
60
+ StorageSubscriptionCallback,
61
+ StorageSubscriptionFn,
62
+ SubscribeFn,
63
+ SubscribeProxy,
64
+ SubscriptionCallback,
50
65
  UpdateMyPresenceAction,
51
66
  UserInfo,
52
67
  WebSocketConnection,
package/src/pluv/room.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Subject } from "wonka";
2
- import type { ConnectionState } from "./enums";
3
2
  import type { Id, JsonObject } from "../general";
4
3
  import type { CrdtDocLike, CrdtType, InferCrdtJson } from "./crdt";
4
+ import type { ConnectionState } from "./enums";
5
5
  import type {
6
6
  InferIOAuthorize,
7
7
  InferIOAuthorizeUser,
@@ -18,20 +18,36 @@ export interface AuthorizationState<TIO extends IOLike> {
18
18
  user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
19
19
  }
20
20
 
21
- export type EventNotifierSubscriptionCallback<
22
- TIO extends IOLike<any, any>,
23
- TEvent extends keyof InferIOOutput<TIO>,
24
- > = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
25
-
26
- export type OtherNotifierSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (
21
+ export type OtherSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (
27
22
  value: Id<UserInfo<TIO, TPresence>> | null,
28
23
  ) => void;
29
24
 
25
+ export type OtherSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (
26
+ connectionId: string,
27
+ callback: OtherSubscriptionCallback<TIO, TPresence>,
28
+ ) => () => void;
29
+
30
+ export type OthersSubscriptionEvent<TIO extends IOLike, TPresence extends JsonObject> =
31
+ | { kind: "clear" }
32
+ | { kind: "enter"; user: Id<UserInfo<TIO, TPresence>> }
33
+ | { kind: "leave"; user: Id<UserInfo<TIO, TPresence>> }
34
+ | { kind: "sync"; users: readonly Id<UserInfo<TIO, TPresence>>[] }
35
+ | { kind: "update"; user: Id<UserInfo<TIO, TPresence>> };
36
+
37
+ export type OthersSubscriptionCallback<TIO extends IOLike, TPresence extends JsonObject> = (
38
+ value: readonly Id<UserInfo<TIO, TPresence>>[],
39
+ event: OthersSubscriptionEvent<TIO, TPresence>,
40
+ ) => void;
41
+
42
+ export type OthersSubscriptionFn<TIO extends IOLike, TPresence extends JsonObject> = (
43
+ callback: OthersSubscriptionCallback<TIO, TPresence>,
44
+ ) => () => void;
45
+
30
46
  export interface StateNotifierSubjects<TIO extends IOLike, TPresence extends JsonObject> {
31
47
  connection: Subject<Id<WebSocketState<TIO>>>;
32
48
  "my-presence": Subject<TPresence | null>;
33
- myself: Subject<Readonly<Id<UserInfo<TIO>>> | null>;
34
- others: Subject<readonly Id<UserInfo<TIO>>[]>;
49
+ myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
50
+ others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
35
51
  "storage-loaded": Subject<boolean>;
36
52
  }
37
53
 
@@ -85,6 +101,86 @@ export interface WebSocketState<TIO extends IOLike> {
85
101
  webSocket: WebSocket | null;
86
102
  }
87
103
 
104
+ export type BroadcastProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = (<
105
+ TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>,
106
+ >(
107
+ event: TEvent,
108
+ data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>,
109
+ ) => Promise<void>) & {
110
+ [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (
111
+ data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>,
112
+ ) => Promise<void>;
113
+ };
114
+
115
+ export type EventNotifierSubscriptionCallback<
116
+ TIO extends IOLike<any, any>,
117
+ TEvent extends keyof InferIOOutput<TIO>,
118
+ > = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
119
+
120
+ export type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <
121
+ TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>,
122
+ >(
123
+ event: TEvent,
124
+ callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>,
125
+ ) => () => void;
126
+
127
+ export type EventProxy<
128
+ TIO extends IOLike,
129
+ TEvents extends PluvRouterEventConfig,
130
+ > = EventSubscriptionFn<TIO, TEvents> & {
131
+ [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (
132
+ callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>,
133
+ ) => () => void;
134
+ };
135
+
136
+ export type StorageSubscriptionCallback<
137
+ TStorage extends Record<string, CrdtType<any, any>>,
138
+ TKey extends keyof TStorage,
139
+ > = (value: InferCrdtJson<TStorage[TKey]>) => void;
140
+
141
+ export type StorageSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = <
142
+ TKey extends keyof TStorage,
143
+ >(
144
+ key: TKey,
145
+ fn: StorageSubscriptionCallback<TStorage, TKey>,
146
+ ) => () => void;
147
+
148
+ export type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> =
149
+ (value: { [P in keyof TStorage]: InferCrdtJson<TStorage[P]> }) => void;
150
+
151
+ export type StorageRootSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = (
152
+ callback: StorageRootSubscriptionCallback<TStorage>,
153
+ ) => () => void;
154
+
155
+ export type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> =
156
+ StorageSubscriptionFn<TStorage> &
157
+ StorageRootSubscriptionFn<TStorage> & {
158
+ [PKey in keyof TStorage]: (
159
+ callback: StorageSubscriptionCallback<TStorage, PKey>,
160
+ ) => () => void;
161
+ };
162
+
163
+ export type SubscribeFn<TValue extends unknown> = (callback: (value: TValue) => void) => () => void;
164
+
165
+ export type SubscribeProxy<
166
+ TIO extends IOLike,
167
+ TPresence extends JsonObject,
168
+ TStorage extends Record<string, CrdtType<any, any>>,
169
+ TEvents extends PluvRouterEventConfig,
170
+ > = (<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(
171
+ name: TSubject,
172
+ callback: SubscriptionCallback<TIO, TPresence, TSubject>,
173
+ ) => () => void) & {
174
+ connection: SubscribeFn<Id<WebSocketState<TIO>>>;
175
+ event: EventProxy<TIO, TEvents>;
176
+ myPresence: SubscribeFn<TPresence | null>;
177
+ myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
178
+ other: OtherSubscriptionFn<TIO, TPresence>;
179
+ others: OthersSubscriptionFn<TIO, TPresence>;
180
+ storage: StorageProxy<TStorage>;
181
+ storageLoaded: SubscribeFn<boolean>;
182
+ };
183
+
88
184
  export interface RoomLike<
89
185
  TIO extends IOLike,
90
186
  TPresence extends JsonObject = {},
@@ -94,10 +190,7 @@ export interface RoomLike<
94
190
  id: string;
95
191
  storageLoaded: boolean;
96
192
 
97
- broadcast<TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>>(
98
- event: TEvent,
99
- data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>,
100
- ): void;
193
+ broadcast: BroadcastProxy<TIO, TEvents>;
101
194
 
102
195
  canRedo(): boolean;
103
196
 
@@ -105,10 +198,7 @@ export interface RoomLike<
105
198
 
106
199
  getDoc(): CrdtDocLike<TStorage>;
107
200
 
108
- event<TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(
109
- event: TEvent,
110
- callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>,
111
- ): () => void;
201
+ event: EventProxy<TIO, TEvents>;
112
202
 
113
203
  getConnection(): WebSocketConnection;
114
204
 
@@ -125,17 +215,11 @@ export interface RoomLike<
125
215
  getStorageJson(): InferCrdtJson<TStorage> | null;
126
216
  getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
127
217
 
128
- other(
129
- connectionId: string,
130
- callback: OtherNotifierSubscriptionCallback<TIO, TPresence>,
131
- ): () => void;
218
+ other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
132
219
 
133
220
  redo(): void;
134
221
 
135
- storage<TKey extends keyof TStorage>(
136
- key: TKey,
137
- fn: (value: InferCrdtJson<TStorage[TKey]>) => void,
138
- ): () => void;
222
+ storage: StorageProxy<TStorage>;
139
223
 
140
224
  storageRoot(
141
225
  fn: (value: {
@@ -143,10 +227,7 @@ export interface RoomLike<
143
227
  }) => void,
144
228
  ): () => void;
145
229
 
146
- subscribe<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(
147
- name: TSubject,
148
- callback: SubscriptionCallback<TIO, TPresence, TSubject>,
149
- ): () => void;
230
+ subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
150
231
 
151
232
  transact(fn: (storage: TStorage) => void, origin?: string): void;
152
233