@pluv/types 3.0.0 → 3.1.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 +4 -0
- package/dist/index.d.mts +21 -6
- package/dist/index.d.ts +21 -6
- package/package.json +3 -3
- package/src/general.ts +6 -0
- package/src/index.ts +4 -0
- package/src/pluv/crdt.ts +15 -0
- package/src/pluv/room.ts +2 -2
- package/src/pluv/shared.ts +16 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/types@3.
|
|
2
|
+
> @pluv/types@3.1.1 build /home/runner/work/pluv/pluv/packages/types
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
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[32m1.37 KB[39m
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in 37ms
|
|
13
11
|
[32mESM[39m [1mdist/index.mjs [22m[32m330.00 B[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 41ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m1.37 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 42ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 1351ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m19.37 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m19.37 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,9 @@ import { Subject } from 'wonka';
|
|
|
3
3
|
type Constructable = {
|
|
4
4
|
new (...args: any[]): any;
|
|
5
5
|
};
|
|
6
|
+
type HasRequiredProperty<T> = {
|
|
7
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
8
|
+
}[keyof T] extends never ? false : true;
|
|
6
9
|
type Maybe<T> = T | Nil;
|
|
7
10
|
type MaybePromise<T> = Promise<T> | T;
|
|
8
11
|
type MaybeReadonlyArray<T> = T[] | readonly T[];
|
|
@@ -42,6 +45,16 @@ type Json = JsonPrimitive | Json[] | readonly Json[] | {
|
|
|
42
45
|
type JsonObject = Record<string, Json>;
|
|
43
46
|
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
|
|
44
47
|
|
|
48
|
+
interface CrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
|
|
49
|
+
_initialStorage: (builder: any) => TStorage;
|
|
50
|
+
getEmpty(): CrdtDocLike<TDoc, TStorage>;
|
|
51
|
+
getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
|
|
52
|
+
getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
|
|
53
|
+
}
|
|
54
|
+
interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
|
|
55
|
+
doc: (value: any) => TDoc;
|
|
56
|
+
kind: "loro" | "yjs";
|
|
57
|
+
}
|
|
45
58
|
type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
|
|
46
59
|
__pluvType: () => TJson;
|
|
47
60
|
};
|
|
@@ -181,7 +194,7 @@ type EventRecord<TEvent extends string, TData extends JsonObject> = {
|
|
|
181
194
|
[key in `${TEvent}`]: TData;
|
|
182
195
|
};
|
|
183
196
|
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;
|
|
197
|
+
type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
|
|
185
198
|
type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> = TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
|
|
186
199
|
type InputZodLike<TData extends JsonObject> = {
|
|
187
200
|
parse: (data: unknown) => TData;
|
|
@@ -217,12 +230,14 @@ interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> =
|
|
|
217
230
|
events: TEvents;
|
|
218
231
|
};
|
|
219
232
|
}
|
|
220
|
-
interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
|
|
233
|
+
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
234
|
_defs: {
|
|
222
235
|
authorize: TAuthorize;
|
|
236
|
+
crdt: TCrdt;
|
|
223
237
|
events: TEvents;
|
|
224
238
|
};
|
|
225
239
|
}
|
|
240
|
+
type InferIOCrdtKind<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt extends CrdtLibraryType<infer IDoc> ? IDoc : never : never;
|
|
226
241
|
type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
|
|
227
242
|
[P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
|
|
228
243
|
};
|
|
@@ -234,13 +249,13 @@ type InferIOOutput<TRouter extends IORouterLike<any>> = TRouter extends IORouter
|
|
|
234
249
|
type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? {
|
|
235
250
|
[P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
|
|
236
251
|
}[TEvent] : never;
|
|
237
|
-
type IOEventMessage<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
|
|
252
|
+
type IOEventMessage<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
|
|
238
253
|
room: string;
|
|
239
254
|
} & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error" ? Partial<IOAuthorizeEventMessage<TIO>> : IOAuthorizeEventMessage<TIO>)>;
|
|
240
255
|
type PluvRouterEventConfig = {
|
|
241
256
|
[P: string]: Pick<ProcedureLike<any, any>, "config">;
|
|
242
257
|
};
|
|
243
|
-
type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any>> = TServerIO extends IOLike<infer IAuthorize, infer IServerEvents> ? IOLike<IAuthorize, {
|
|
258
|
+
type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, {
|
|
244
259
|
[P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? {
|
|
245
260
|
[K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
|
|
246
261
|
}[keyof IClientOutput] : never;
|
|
@@ -306,7 +321,7 @@ interface WebSocketState<TIO extends IOLike> {
|
|
|
306
321
|
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
322
|
[PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
|
|
308
323
|
};
|
|
309
|
-
type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
324
|
+
type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
310
325
|
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
326
|
type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
|
|
312
327
|
[PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
|
|
@@ -360,4 +375,4 @@ interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Recor
|
|
|
360
375
|
updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
|
|
361
376
|
}
|
|
362
377
|
|
|
363
|
-
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 };
|
|
378
|
+
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 HasRequiredProperty, 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
|
@@ -3,6 +3,9 @@ import { Subject } from 'wonka';
|
|
|
3
3
|
type Constructable = {
|
|
4
4
|
new (...args: any[]): any;
|
|
5
5
|
};
|
|
6
|
+
type HasRequiredProperty<T> = {
|
|
7
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
8
|
+
}[keyof T] extends never ? false : true;
|
|
6
9
|
type Maybe<T> = T | Nil;
|
|
7
10
|
type MaybePromise<T> = Promise<T> | T;
|
|
8
11
|
type MaybeReadonlyArray<T> = T[] | readonly T[];
|
|
@@ -42,6 +45,16 @@ type Json = JsonPrimitive | Json[] | readonly Json[] | {
|
|
|
42
45
|
type JsonObject = Record<string, Json>;
|
|
43
46
|
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
|
|
44
47
|
|
|
48
|
+
interface CrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
|
|
49
|
+
_initialStorage: (builder: any) => TStorage;
|
|
50
|
+
getEmpty(): CrdtDocLike<TDoc, TStorage>;
|
|
51
|
+
getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
|
|
52
|
+
getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
|
|
53
|
+
}
|
|
54
|
+
interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
|
|
55
|
+
doc: (value: any) => TDoc;
|
|
56
|
+
kind: "loro" | "yjs";
|
|
57
|
+
}
|
|
45
58
|
type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
|
|
46
59
|
__pluvType: () => TJson;
|
|
47
60
|
};
|
|
@@ -181,7 +194,7 @@ type EventRecord<TEvent extends string, TData extends JsonObject> = {
|
|
|
181
194
|
[key in `${TEvent}`]: TData;
|
|
182
195
|
};
|
|
183
196
|
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;
|
|
197
|
+
type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
|
|
185
198
|
type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> = TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
|
|
186
199
|
type InputZodLike<TData extends JsonObject> = {
|
|
187
200
|
parse: (data: unknown) => TData;
|
|
@@ -217,12 +230,14 @@ interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> =
|
|
|
217
230
|
events: TEvents;
|
|
218
231
|
};
|
|
219
232
|
}
|
|
220
|
-
interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
|
|
233
|
+
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
234
|
_defs: {
|
|
222
235
|
authorize: TAuthorize;
|
|
236
|
+
crdt: TCrdt;
|
|
223
237
|
events: TEvents;
|
|
224
238
|
};
|
|
225
239
|
}
|
|
240
|
+
type InferIOCrdtKind<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt extends CrdtLibraryType<infer IDoc> ? IDoc : never : never;
|
|
226
241
|
type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
|
|
227
242
|
[P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
|
|
228
243
|
};
|
|
@@ -234,13 +249,13 @@ type InferIOOutput<TRouter extends IORouterLike<any>> = TRouter extends IORouter
|
|
|
234
249
|
type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? {
|
|
235
250
|
[P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
|
|
236
251
|
}[TEvent] : never;
|
|
237
|
-
type IOEventMessage<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
|
|
252
|
+
type IOEventMessage<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
|
|
238
253
|
room: string;
|
|
239
254
|
} & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error" ? Partial<IOAuthorizeEventMessage<TIO>> : IOAuthorizeEventMessage<TIO>)>;
|
|
240
255
|
type PluvRouterEventConfig = {
|
|
241
256
|
[P: string]: Pick<ProcedureLike<any, any>, "config">;
|
|
242
257
|
};
|
|
243
|
-
type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any>> = TServerIO extends IOLike<infer IAuthorize, infer IServerEvents> ? IOLike<IAuthorize, {
|
|
258
|
+
type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, {
|
|
244
259
|
[P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? {
|
|
245
260
|
[K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
|
|
246
261
|
}[keyof IClientOutput] : never;
|
|
@@ -306,7 +321,7 @@ interface WebSocketState<TIO extends IOLike> {
|
|
|
306
321
|
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
322
|
[PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
|
|
308
323
|
};
|
|
309
|
-
type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
324
|
+
type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
310
325
|
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
326
|
type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
|
|
312
327
|
[PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
|
|
@@ -360,4 +375,4 @@ interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Recor
|
|
|
360
375
|
updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
|
|
361
376
|
}
|
|
362
377
|
|
|
363
|
-
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 };
|
|
378
|
+
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 HasRequiredProperty, 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": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
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": "^3.
|
|
23
|
-
"eslint-config-pluv": "^3.
|
|
22
|
+
"@pluv/tsconfig": "^3.1.1",
|
|
23
|
+
"eslint-config-pluv": "^3.1.1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"wonka": "^6.3.5"
|
package/src/general.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export type Constructable = { new (...args: any[]): any };
|
|
2
2
|
|
|
3
|
+
export type HasRequiredProperty<T> = {
|
|
4
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
5
|
+
}[keyof T] extends never
|
|
6
|
+
? false
|
|
7
|
+
: true;
|
|
8
|
+
|
|
3
9
|
export type Maybe<T> = T | Nil;
|
|
4
10
|
export type MaybePromise<T> = Promise<T> | T;
|
|
5
11
|
export type MaybeReadonlyArray<T> = T[] | readonly T[];
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type {
|
|
|
2
2
|
Constructable,
|
|
3
3
|
DeepPartial,
|
|
4
4
|
DeepWriteable,
|
|
5
|
+
HasRequiredProperty,
|
|
5
6
|
Id,
|
|
6
7
|
Json,
|
|
7
8
|
JsonObject,
|
|
@@ -22,7 +23,9 @@ export type {
|
|
|
22
23
|
BaseIOEventRecord,
|
|
23
24
|
BaseUser,
|
|
24
25
|
BroadcastProxy,
|
|
26
|
+
CrdtDocFactory,
|
|
25
27
|
CrdtDocLike,
|
|
28
|
+
CrdtLibraryType,
|
|
26
29
|
CrdtType,
|
|
27
30
|
DocApplyEncodedStateParams,
|
|
28
31
|
DocBatchApplyEncodedStateParams,
|
|
@@ -38,6 +41,7 @@ export type {
|
|
|
38
41
|
InferEventsOutput,
|
|
39
42
|
InferIOAuthorize,
|
|
40
43
|
InferIOAuthorizeUser,
|
|
44
|
+
InferIOCrdtKind,
|
|
41
45
|
InferIOInput,
|
|
42
46
|
InferIOOutput,
|
|
43
47
|
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
|
|
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
|
|
package/src/pluv/shared.ts
CHANGED
|
@@ -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,
|