@pluv/types 2.3.1 → 3.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.3.1 build /home/runner/work/pluv/pluv/packages/types
2
+ > @pluv/types@3.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 330.00 B
12
- ESM ⚡️ Build success in 46ms
13
11
  CJS dist/index.js 1.37 KB
14
- CJS ⚡️ Build success in 45ms
12
+ CJS ⚡️ Build success in 41ms
13
+ ESM dist/index.mjs 330.00 B
14
+ ESM ⚡️ Build success in 43ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1296ms
17
- DTS dist/index.d.mts 18.73 KB
18
- DTS dist/index.d.ts 18.73 KB
16
+ DTS ⚡️ Build success in 1332ms
17
+ DTS dist/index.d.mts 19.21 KB
18
+ DTS dist/index.d.ts 19.21 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @pluv/types
2
2
 
3
+ ## 3.1.0
4
+
5
+ ## 3.0.0
6
+
3
7
  ## 2.3.1
4
8
 
5
9
  ## 2.3.0
package/dist/index.d.mts CHANGED
@@ -42,6 +42,16 @@ type Json = JsonPrimitive | Json[] | readonly Json[] | {
42
42
  type JsonObject = Record<string, Json>;
43
43
  type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
44
44
 
45
+ interface CrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
46
+ _initialStorage: (builder: any) => TStorage;
47
+ getEmpty(): CrdtDocLike<TDoc, TStorage>;
48
+ getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
49
+ getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
50
+ }
51
+ interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
52
+ doc: (value: any) => TDoc;
53
+ kind: "loro" | "yjs";
54
+ }
45
55
  type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
46
56
  __pluvType: () => TJson;
47
57
  };
@@ -181,7 +191,7 @@ type EventRecord<TEvent extends string, TData extends JsonObject> = {
181
191
  [key in `${TEvent}`]: TData;
182
192
  };
183
193
  type GetEventMessage<T extends EventRecord<string, any>, TEvent extends keyof T> = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
184
- type InferIOAuthorize<TIO extends IOLike<any, any>> = TIO extends IOLike<infer IAuthorize> ? IAuthorize : never;
194
+ type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
185
195
  type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> = TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
186
196
  type InputZodLike<TData extends JsonObject> = {
187
197
  parse: (data: unknown) => TData;
@@ -217,12 +227,14 @@ interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> =
217
227
  events: TEvents;
218
228
  };
219
229
  }
220
- interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
230
+ interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
221
231
  _defs: {
222
232
  authorize: TAuthorize;
233
+ crdt: TCrdt;
223
234
  events: TEvents;
224
235
  };
225
236
  }
237
+ type InferIOCrdtKind<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt extends CrdtLibraryType<infer IDoc> ? IDoc : never : never;
226
238
  type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
227
239
  [P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
228
240
  };
@@ -234,13 +246,13 @@ type InferIOOutput<TRouter extends IORouterLike<any>> = TRouter extends IORouter
234
246
  type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? {
235
247
  [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
236
248
  }[TEvent] : never;
237
- type IOEventMessage<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
249
+ type IOEventMessage<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
238
250
  room: string;
239
251
  } & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error" ? Partial<IOAuthorizeEventMessage<TIO>> : IOAuthorizeEventMessage<TIO>)>;
240
252
  type PluvRouterEventConfig = {
241
253
  [P: string]: Pick<ProcedureLike<any, any>, "config">;
242
254
  };
243
- type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any>> = TServerIO extends IOLike<infer IAuthorize, infer IServerEvents> ? IOLike<IAuthorize, {
255
+ type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, {
244
256
  [P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? {
245
257
  [K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
246
258
  }[keyof IClientOutput] : never;
@@ -306,7 +318,7 @@ interface WebSocketState<TIO extends IOLike> {
306
318
  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>) & {
307
319
  [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
308
320
  };
309
- type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
321
+ type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
310
322
  type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>) => () => void;
311
323
  type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
312
324
  [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
@@ -340,15 +352,10 @@ interface RoomEventListenerMap {
340
352
  interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Record<string, any> = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig = {}> {
341
353
  id: string;
342
354
  broadcast: BroadcastProxy<TIO, TEvents>;
343
- /**
344
- * @deprecated To be removed in v3. Use getStorageLoaded instead.
345
- */
346
- storageLoaded: boolean;
347
355
  addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
348
356
  canRedo(): boolean;
349
357
  canUndo(): boolean;
350
358
  getDoc(): CrdtDocLike<TDoc, TStorage>;
351
- event: EventProxy<TIO, TEvents>;
352
359
  getConnection(): WebSocketConnection;
353
360
  getMyPresence(): TPresence;
354
361
  getMyself(): Id<UserInfo<TIO, TPresence>> | null;
@@ -358,16 +365,11 @@ interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Recor
358
365
  getStorageJson(): InferCrdtJson<TStorage> | null;
359
366
  getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
360
367
  getStorageLoaded: () => boolean;
361
- other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
362
368
  redo(): void;
363
- storage: StorageProxy<TStorage>;
364
- storageRoot(fn: (value: {
365
- [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
366
- }) => void): () => void;
367
369
  subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
368
370
  transact(fn: (storage: TStorage) => void, origin?: string): void;
369
371
  undo(): void;
370
372
  updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
371
373
  }
372
374
 
373
- 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 InferCrdtJson, 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 PluvRouterEventConfig, type ProcedureLike, type RoomEventListenerMap, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageInfo, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, StorageState, type StorageSubscriptionCallback, type StorageSubscriptionFn, type SubscribeFn, type SubscribeProxy, type SubscriptionCallback, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
375
+ export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, type BroadcastProxy, ConnectionState, type Constructable, type CrdtDocFactory, type CrdtDocLike, type CrdtLibraryType, 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 InferCrdtJson, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOCrdtKind, 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 PluvRouterEventConfig, type ProcedureLike, type RoomEventListenerMap, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageInfo, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, StorageState, 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
@@ -42,6 +42,16 @@ type Json = JsonPrimitive | Json[] | readonly Json[] | {
42
42
  type JsonObject = Record<string, Json>;
43
43
  type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
44
44
 
45
+ interface CrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
46
+ _initialStorage: (builder: any) => TStorage;
47
+ getEmpty(): CrdtDocLike<TDoc, TStorage>;
48
+ getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
49
+ getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
50
+ }
51
+ interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
52
+ doc: (value: any) => TDoc;
53
+ kind: "loro" | "yjs";
54
+ }
45
55
  type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
46
56
  __pluvType: () => TJson;
47
57
  };
@@ -181,7 +191,7 @@ type EventRecord<TEvent extends string, TData extends JsonObject> = {
181
191
  [key in `${TEvent}`]: TData;
182
192
  };
183
193
  type GetEventMessage<T extends EventRecord<string, any>, TEvent extends keyof T> = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
184
- type InferIOAuthorize<TIO extends IOLike<any, any>> = TIO extends IOLike<infer IAuthorize> ? IAuthorize : never;
194
+ type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
185
195
  type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> = TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
186
196
  type InputZodLike<TData extends JsonObject> = {
187
197
  parse: (data: unknown) => TData;
@@ -217,12 +227,14 @@ interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> =
217
227
  events: TEvents;
218
228
  };
219
229
  }
220
- interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
230
+ interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
221
231
  _defs: {
222
232
  authorize: TAuthorize;
233
+ crdt: TCrdt;
223
234
  events: TEvents;
224
235
  };
225
236
  }
237
+ type InferIOCrdtKind<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt extends CrdtLibraryType<infer IDoc> ? IDoc : never : never;
226
238
  type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
227
239
  [P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
228
240
  };
@@ -234,13 +246,13 @@ type InferIOOutput<TRouter extends IORouterLike<any>> = TRouter extends IORouter
234
246
  type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? {
235
247
  [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
236
248
  }[TEvent] : never;
237
- type IOEventMessage<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
249
+ type IOEventMessage<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
238
250
  room: string;
239
251
  } & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error" ? Partial<IOAuthorizeEventMessage<TIO>> : IOAuthorizeEventMessage<TIO>)>;
240
252
  type PluvRouterEventConfig = {
241
253
  [P: string]: Pick<ProcedureLike<any, any>, "config">;
242
254
  };
243
- type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any>> = TServerIO extends IOLike<infer IAuthorize, infer IServerEvents> ? IOLike<IAuthorize, {
255
+ type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, {
244
256
  [P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? {
245
257
  [K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
246
258
  }[keyof IClientOutput] : never;
@@ -306,7 +318,7 @@ interface WebSocketState<TIO extends IOLike> {
306
318
  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>) & {
307
319
  [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
308
320
  };
309
- type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
321
+ type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
310
322
  type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>) => () => void;
311
323
  type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
312
324
  [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
@@ -340,15 +352,10 @@ interface RoomEventListenerMap {
340
352
  interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Record<string, any> = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig = {}> {
341
353
  id: string;
342
354
  broadcast: BroadcastProxy<TIO, TEvents>;
343
- /**
344
- * @deprecated To be removed in v3. Use getStorageLoaded instead.
345
- */
346
- storageLoaded: boolean;
347
355
  addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
348
356
  canRedo(): boolean;
349
357
  canUndo(): boolean;
350
358
  getDoc(): CrdtDocLike<TDoc, TStorage>;
351
- event: EventProxy<TIO, TEvents>;
352
359
  getConnection(): WebSocketConnection;
353
360
  getMyPresence(): TPresence;
354
361
  getMyself(): Id<UserInfo<TIO, TPresence>> | null;
@@ -358,16 +365,11 @@ interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Recor
358
365
  getStorageJson(): InferCrdtJson<TStorage> | null;
359
366
  getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
360
367
  getStorageLoaded: () => boolean;
361
- other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
362
368
  redo(): void;
363
- storage: StorageProxy<TStorage>;
364
- storageRoot(fn: (value: {
365
- [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
366
- }) => void): () => void;
367
369
  subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
368
370
  transact(fn: (storage: TStorage) => void, origin?: string): void;
369
371
  undo(): void;
370
372
  updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
371
373
  }
372
374
 
373
- 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 InferCrdtJson, 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 PluvRouterEventConfig, type ProcedureLike, type RoomEventListenerMap, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageInfo, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, StorageState, type StorageSubscriptionCallback, type StorageSubscriptionFn, type SubscribeFn, type SubscribeProxy, type SubscriptionCallback, type UndefinedProps, type UpdateMyPresenceAction, type UserInfo, type WebSocketConnection, type WebSocketState };
375
+ export { type BaseClientEventRecord, type BaseClientMessage, type BaseIOEventRecord, type BaseUser, type BroadcastProxy, ConnectionState, type Constructable, type CrdtDocFactory, type CrdtDocLike, type CrdtLibraryType, 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 InferCrdtJson, type InferEventMessage, type InferEventsInput, type InferEventsOutput, type InferIOAuthorize, type InferIOAuthorizeUser, type InferIOCrdtKind, 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 PluvRouterEventConfig, type ProcedureLike, type RoomEventListenerMap, type RoomLike, type Spread, type SpreadProperties, type StateNotifierSubjects, type StorageInfo, type StorageProxy, type StorageRootSubscriptionCallback, type StorageRootSubscriptionFn, StorageState, 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.3.1",
3
+ "version": "3.1.0",
4
4
  "description": "@pluv/io shared types",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  "eslint": "^9.27.0",
20
20
  "tsup": "^8.5.0",
21
21
  "typescript": "^5.8.3",
22
- "@pluv/tsconfig": "^2.3.1",
23
- "eslint-config-pluv": "^2.3.1"
22
+ "@pluv/tsconfig": "^3.1.0",
23
+ "eslint-config-pluv": "^3.1.0"
24
24
  },
25
25
  "dependencies": {
26
26
  "wonka": "^6.3.5"
package/src/index.ts CHANGED
@@ -22,7 +22,9 @@ export type {
22
22
  BaseIOEventRecord,
23
23
  BaseUser,
24
24
  BroadcastProxy,
25
+ CrdtDocFactory,
25
26
  CrdtDocLike,
27
+ CrdtLibraryType,
26
28
  CrdtType,
27
29
  DocApplyEncodedStateParams,
28
30
  DocBatchApplyEncodedStateParams,
@@ -38,6 +40,7 @@ export type {
38
40
  InferEventsOutput,
39
41
  InferIOAuthorize,
40
42
  InferIOAuthorizeUser,
43
+ InferIOCrdtKind,
41
44
  InferIOInput,
42
45
  InferIOOutput,
43
46
  InputZodLike,
package/src/pluv/crdt.ts CHANGED
@@ -1,5 +1,20 @@
1
1
  import type { Json, Maybe } from "../general";
2
2
 
3
+ export interface CrdtDocFactory<
4
+ TDoc extends any,
5
+ TStorage extends Record<string, CrdtType<any, any>>,
6
+ > {
7
+ _initialStorage: (builder: any) => TStorage;
8
+ getEmpty(): CrdtDocLike<TDoc, TStorage>;
9
+ getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
10
+ getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
11
+ }
12
+
13
+ export interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
14
+ doc: (value: any) => TDoc;
15
+ kind: "loro" | "yjs";
16
+ }
17
+
3
18
  export type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<
4
19
  TValue,
5
20
  "__pluvType"
package/src/pluv/room.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Subject } from "wonka";
2
- import type { Id, JsonObject } from "../general";
2
+ import type { Id } from "../general";
3
3
  import type { CrdtDocLike, CrdtType, InferCrdtJson } from "./crdt";
4
4
  import type { ConnectionState, StorageState } from "./enums";
5
5
  import type {
@@ -113,7 +113,7 @@ export type BroadcastProxy<TIO extends IOLike, TEvents extends PluvRouterEventCo
113
113
  };
114
114
 
115
115
  export type EventNotifierSubscriptionCallback<
116
- TIO extends IOLike<any, any>,
116
+ TIO extends IOLike<any, any, any>,
117
117
  TEvent extends keyof InferIOOutput<TIO>,
118
118
  > = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
119
119
 
@@ -197,10 +197,6 @@ export interface RoomLike<
197
197
  > {
198
198
  id: string;
199
199
  broadcast: BroadcastProxy<TIO, TEvents>;
200
- /**
201
- * @deprecated To be removed in v3. Use getStorageLoaded instead.
202
- */
203
- storageLoaded: boolean;
204
200
 
205
201
  addEventListener<TKind extends keyof RoomEventListenerMap>(
206
202
  kind: TKind,
@@ -213,8 +209,6 @@ export interface RoomLike<
213
209
 
214
210
  getDoc(): CrdtDocLike<TDoc, TStorage>;
215
211
 
216
- event: EventProxy<TIO, TEvents>;
217
-
218
212
  getConnection(): WebSocketConnection;
219
213
 
220
214
  getMyPresence(): TPresence;
@@ -232,18 +226,8 @@ export interface RoomLike<
232
226
 
233
227
  getStorageLoaded: () => boolean;
234
228
 
235
- other(connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>): () => void;
236
-
237
229
  redo(): void;
238
230
 
239
- storage: StorageProxy<TStorage>;
240
-
241
- storageRoot(
242
- fn: (value: {
243
- [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
244
- }) => void,
245
- ): () => void;
246
-
247
231
  subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
248
232
 
249
233
  transact(fn: (storage: TStorage) => void, origin?: string): void;
@@ -1,4 +1,5 @@
1
1
  import type { Id, JsonObject, MaybePromise, UnionToIntersection } from "../general";
2
+ import { CrdtLibraryType } from "./crdt";
2
3
 
3
4
  export type BaseUser = {
4
5
  id: string;
@@ -84,8 +85,8 @@ export type GetEventMessage<
84
85
  TEvent extends keyof T,
85
86
  > = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
86
87
 
87
- export type InferIOAuthorize<TIO extends IOLike<any, any>> =
88
- TIO extends IOLike<infer IAuthorize> ? IAuthorize : never;
88
+ export type InferIOAuthorize<TIO extends IOLike<any, any, any>> =
89
+ TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
89
90
 
90
91
  export type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> =
91
92
  TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
@@ -139,14 +140,23 @@ export interface IORouterLike<TEvents extends Record<string, ProcedureLike<any,
139
140
 
140
141
  export interface IOLike<
141
142
  TAuthorize extends IOAuthorize<any, any> | null = null,
143
+ TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
142
144
  TEvents extends Record<string, ProcedureLike<any, any>> = {},
143
145
  > extends IORouterLike<TEvents> {
144
146
  _defs: {
145
147
  authorize: TAuthorize;
148
+ crdt: TCrdt;
146
149
  events: TEvents;
147
150
  };
148
151
  }
149
152
 
153
+ export type InferIOCrdtKind<TIO extends IOLike<any, any, any>> =
154
+ TIO extends IOLike<any, infer ICrdt, any>
155
+ ? ICrdt extends CrdtLibraryType<infer IDoc>
156
+ ? IDoc
157
+ : never
158
+ : never;
159
+
150
160
  export type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
151
161
  [P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
152
162
  };
@@ -175,7 +185,7 @@ export type InferEventMessage<
175
185
  : never;
176
186
 
177
187
  export type IOEventMessage<
178
- TIO extends IOLike<any, any>,
188
+ TIO extends IOLike<any, any, any>,
179
189
  TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>,
180
190
  > = Id<
181
191
  { room: string } & InferEventMessage<InferIOOutput<TIO>, TEvent> &
@@ -188,11 +198,12 @@ export type PluvRouterEventConfig = { [P: string]: Pick<ProcedureLike<any, any>,
188
198
 
189
199
  export type MergeEvents<
190
200
  TClientEvents extends PluvRouterEventConfig,
191
- TServerIO extends IOLike<any, any>,
201
+ TServerIO extends IOLike<any, any, any>,
192
202
  > =
193
- TServerIO extends IOLike<infer IAuthorize, infer IServerEvents>
203
+ TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents>
194
204
  ? IOLike<
195
205
  IAuthorize,
206
+ ICrdt,
196
207
  {
197
208
  [P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<
198
209
  infer IClientInput,