@pluv/types 3.2.1 → 4.0.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.
package/dist/index.d.mts CHANGED
@@ -1,379 +1,350 @@
1
- import { Subject } from 'wonka';
1
+ import { Subject } from "wonka";
2
2
 
3
+ //#region src/general.d.ts
3
4
  type Constructable = {
4
- new (...args: any[]): any;
5
+ new (...args: any[]): any;
5
6
  };
6
- type HasRequiredProperty<T> = {
7
- [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
8
- }[keyof T] extends never ? false : true;
7
+ type HasRequiredProperty<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T] extends never ? false : true;
9
8
  type Maybe<T> = T | Nil;
10
9
  type MaybePromise<T> = Promise<T> | T;
11
10
  type MaybeReadonlyArray<T> = T[] | readonly T[];
12
11
  type Nil = null | undefined;
13
- type OptionalPropertyNames<T> = {
14
- [K in keyof T]-?: {} extends {
15
- [P in K]: T[K];
16
- } ? K : never;
17
- }[keyof T];
18
- type SpreadProperties<L, R, K extends keyof L & keyof R> = {
19
- [P in K]: L[P] | Exclude<R[P], undefined>;
20
- };
21
- type Id<T> = T extends Nil ? T : T extends infer U ? U extends Constructable ? U : {
22
- [K in keyof U]: U[K];
23
- } : never;
12
+ type OptionalPropertyNames<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never }[keyof T];
13
+ type SpreadProperties<L, R, K extends keyof L & keyof R> = { [P in K]: L[P] | Exclude<R[P], undefined> };
14
+ type Id<T> = T extends Nil ? T : T extends infer U ? U extends Constructable ? U : { [K in keyof U]: U[K] } : never;
24
15
  type SpreadTwo<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>;
25
16
  type Spread<A extends readonly [...any]> = A extends [infer L, ...infer R] ? SpreadTwo<L, Spread<R>> : unknown;
26
- type DeepPartial<T> = {
27
- [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
28
- };
29
- type DeepWriteable<T> = {
30
- -readonly [P in keyof T]: DeepWriteable<T[P]>;
31
- };
32
- type UndefinedProps<T extends Record<string, any>, K extends keyof T = keyof T> = Id<{
33
- [P in K]?: undefined;
34
- } & {
35
- [P in Exclude<keyof T, K>]: T[P];
36
- }>;
17
+ type DeepPartial<T> = { [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]> };
18
+ type DeepWriteable<T> = { -readonly [P in keyof T]: DeepWriteable<T[P]> };
19
+ type UndefinedProps<T extends Record<string, any>, K extends keyof T = keyof T> = Id<{ [P in K]?: undefined } & { [P in Exclude<keyof T, K>]: T[P] }>;
37
20
  type OptionalProps<T extends Record<string, any>, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
38
- type NonNilProps<T extends Record<string, any>, K extends keyof T = keyof T> = Omit<T, K> & {
39
- [P in K]-?: NonNullable<T[P]>;
40
- };
21
+ type NonNilProps<T extends Record<string, any>, K extends keyof T = keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
41
22
  type JsonPrimitive = string | number | boolean | null;
42
23
  type Json = JsonPrimitive | Json[] | readonly Json[] | {
43
- [key: string]: Json;
24
+ [key: string]: Json;
44
25
  };
45
26
  type JsonObject = Record<string, Json>;
46
- type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
47
-
27
+ type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends ((arg: infer I) => void) ? I : never;
28
+ type AreAllOptional<T> = [T] extends [{}] ? keyof T extends never ? true : HasRequiredProperty<T> extends true ? false : true : false;
29
+ //#endregion
30
+ //#region src/pluv/crdt.d.ts
48
31
  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
- isEmpty(initialStorage: Maybe<string>): boolean;
32
+ _initialStorage: (builder: any) => TStorage;
33
+ getEmpty(): CrdtDocLike<TDoc, TStorage>;
34
+ getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
35
+ getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
36
+ isEmpty(initialStorage: Maybe<string>): boolean;
54
37
  }
55
38
  interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
56
- doc: (value: any) => TDoc;
57
- kind: "loro" | "yjs";
39
+ doc: (value: any) => TDoc;
40
+ kind: "loro" | "yjs";
58
41
  }
59
42
  type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
60
- __pluvType: () => TJson;
43
+ __pluvType: () => TJson;
61
44
  };
62
- type InferCrdtJson<T extends unknown> = T extends CrdtType<any, infer IJson> ? InferCrdtJson<IJson> : T extends Record<string, any> ? {
63
- [P in keyof T]: InferCrdtJson<T[P]>;
64
- } : T extends (infer IJson)[] ? InferCrdtJson<IJson>[] : T extends readonly (infer IJson)[] ? readonly InferCrdtJson<IJson>[] : T extends Json ? T : string;
45
+ type InferCrdtJson<T extends unknown> = T extends CrdtType<any, infer IJson> ? InferCrdtJson<IJson> : T extends Record<string, any> ? { [P in keyof T]: InferCrdtJson<T[P]> } : T extends (infer IJson)[] ? InferCrdtJson<IJson>[] : T extends readonly (infer IJson)[] ? readonly InferCrdtJson<IJson>[] : T extends Json ? T : string;
65
46
  interface DocApplyEncodedStateParams {
66
- origin?: string;
67
- update?: Maybe<string | Uint8Array>;
47
+ origin?: string;
48
+ update?: Maybe<string | Uint8Array>;
68
49
  }
69
50
  interface DocBatchApplyEncodedStateParams {
70
- origin?: string;
71
- updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
51
+ origin?: string;
52
+ updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
72
53
  }
73
54
  interface DocSubscribeCallbackParams<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
74
- doc: CrdtDocLike<TDoc, TStorage>;
75
- local: boolean;
76
- origin?: string | null;
77
- update: string;
55
+ doc: CrdtDocLike<TDoc, TStorage>;
56
+ local: boolean;
57
+ origin?: string | null;
58
+ update: string;
78
59
  }
79
60
  interface CrdtDocLike<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
80
- value: TDoc;
81
- applyEncodedState(params: DocApplyEncodedStateParams): this;
82
- batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
83
- canRedo(): boolean;
84
- canUndo(): boolean;
85
- destroy(): void;
86
- get(key?: undefined): TStorage;
87
- get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
88
- getEncodedState(): string;
89
- isEmpty(): boolean;
90
- rebuildStorage(reference: TStorage): this;
91
- redo(): this;
92
- subscribe(listener: (params: DocSubscribeCallbackParams<TDoc, TStorage>) => void): () => void;
93
- toJson(): InferCrdtJson<TStorage>;
94
- toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
95
- track(): this;
96
- transact(fn: () => void, origin?: string): this;
97
- undo(): this;
61
+ value: TDoc;
62
+ applyEncodedState(params: DocApplyEncodedStateParams): this;
63
+ batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
64
+ canRedo(): boolean;
65
+ canUndo(): boolean;
66
+ destroy(): void;
67
+ get(key?: undefined): TStorage;
68
+ get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
69
+ getEncodedState(): string;
70
+ isEmpty(): boolean;
71
+ rebuildStorage(reference: TStorage): this;
72
+ redo(): this;
73
+ subscribe(listener: (params: DocSubscribeCallbackParams<TDoc, TStorage>) => void): () => void;
74
+ toJson(): InferCrdtJson<TStorage>;
75
+ toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
76
+ track(): this;
77
+ transact(fn: () => void, origin?: string): this;
78
+ undo(): this;
98
79
  }
99
-
80
+ //#endregion
81
+ //#region src/pluv/enums.d.ts
100
82
  declare const ConnectionState: {
101
- readonly Closed: "closed";
102
- readonly Connecting: "connecting";
103
- readonly Open: "open";
104
- readonly Unavailable: "unavailable";
105
- readonly Untouched: "untouched";
83
+ readonly Closed: "closed";
84
+ readonly Connecting: "connecting";
85
+ readonly Open: "open";
86
+ readonly Unavailable: "unavailable";
87
+ readonly Untouched: "untouched";
106
88
  };
107
89
  type ConnectionState = (typeof ConnectionState)[keyof typeof ConnectionState];
108
90
  declare const StorageState: {
109
- Loading: string;
110
- Offline: string;
111
- Synced: string;
112
- Unavailable: string;
91
+ Loading: string;
92
+ Offline: string;
93
+ Synced: string;
94
+ Unavailable: string;
113
95
  };
114
96
  type StorageState = (typeof StorageState)[keyof typeof StorageState];
115
-
97
+ //#endregion
98
+ //#region src/pluv/shared.d.ts
116
99
  type BaseUser = {
117
- id: string;
100
+ id: string;
118
101
  };
119
102
  interface BaseClientEventRecord {
120
- $getOthers: {};
121
- $initializeSession: {
122
- presence: JsonObject;
123
- update: string | null;
124
- };
125
- $ping: {};
126
- $updatePresence: {
127
- presence: JsonObject;
128
- };
129
- $updateStorage: {
130
- origin: string | null;
131
- update: string;
132
- };
103
+ $getOthers: {};
104
+ $initializeSession: {
105
+ presence: JsonObject;
106
+ update: string | null;
107
+ };
108
+ $ping: {};
109
+ $updatePresence: {
110
+ presence: JsonObject;
111
+ };
112
+ $updateStorage: {
113
+ origin: string | null;
114
+ update: string;
115
+ };
133
116
  }
134
117
  type BaseClientMessage = InferEventMessage<BaseClientEventRecord>;
135
118
  type BaseIOEventRecord<TAuthorize extends IOAuthorize<any, any>> = {
136
- $error: {
137
- message: string;
138
- stack?: string | null;
139
- };
140
- $exit: {
141
- sessionId: string;
142
- };
143
- $othersReceived: {
144
- others: {
145
- [connectionId: string]: {
146
- connectionId: string;
147
- presence: JsonObject | null;
148
- room: string | null;
149
- timers: {
150
- presence: number | null;
151
- };
152
- user: Id<InferIOAuthorizeUser<TAuthorize>>;
153
- };
154
- };
155
- };
156
- $pong: {};
157
- $presenceUpdated: {
158
- presence: JsonObject;
159
- timers: {
160
- presence: number | null;
161
- };
162
- };
163
- $registered: {
119
+ $error: {
120
+ message: string;
121
+ stack?: string | null;
122
+ };
123
+ $exit: {
124
+ sessionId: string;
125
+ };
126
+ $othersReceived: {
127
+ others: {
128
+ [connectionId: string]: {
129
+ connectionId: string;
164
130
  presence: JsonObject | null;
165
- sessionId: string;
166
- state: string | null;
131
+ room: string | null;
167
132
  timers: {
168
- presence: number | null;
133
+ presence: number | null;
169
134
  };
135
+ user: Id<InferIOAuthorizeUser<TAuthorize>>;
136
+ };
170
137
  };
171
- $storageReceived: {
172
- changeKind: "empty" | "initialized" | "unchanged";
173
- state: string;
174
- };
175
- $storageUpdated: {
176
- state: string;
138
+ };
139
+ $pong: {};
140
+ $presenceUpdated: {
141
+ presence: JsonObject;
142
+ timers: {
143
+ presence: number | null;
177
144
  };
178
- $syncStateReceived: {
179
- connectionIds: readonly string[];
145
+ };
146
+ $registered: {
147
+ presence: JsonObject | null;
148
+ sessionId: string;
149
+ state: string | null;
150
+ timers: {
151
+ presence: number | null;
180
152
  };
181
- $userJoined: {
182
- connectionId: string;
183
- presence: JsonObject;
184
- timers: {
185
- presence: number | null;
186
- };
187
- user: NonNullable<Id<InferIOAuthorizeUser<TAuthorize>>>;
153
+ };
154
+ $storageReceived: {
155
+ changeKind: "empty" | "initialized" | "unchanged";
156
+ state: string;
157
+ };
158
+ $storageUpdated: {
159
+ state: string;
160
+ };
161
+ $syncStateReceived: {
162
+ connectionIds: readonly string[];
163
+ };
164
+ $userJoined: {
165
+ connectionId: string;
166
+ presence: JsonObject;
167
+ timers: {
168
+ presence: number | null;
188
169
  };
170
+ user: NonNullable<Id<InferIOAuthorizeUser<TAuthorize>>>;
171
+ };
189
172
  };
190
173
  interface EventMessage<TEvent extends string, TData extends JsonObject = {}> {
191
- data: TData;
192
- type: TEvent;
174
+ data: TData;
175
+ type: TEvent;
193
176
  }
194
- type EventRecord<TEvent extends string, TData extends JsonObject> = {
195
- [key in `${TEvent}`]: TData;
196
- };
177
+ type EventRecord<TEvent extends string, TData extends JsonObject> = { [key in `${TEvent}`]: TData };
197
178
  type GetEventMessage<T extends EventRecord<string, any>, TEvent extends keyof T> = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
198
- type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? IAuthorize : never;
179
+ type InferIOAuthorize<TIO extends IOLike<any, any, any>> = TIO extends IOLike<infer IAuthorize, any, any> ? InferIOAuthorizeUser<IAuthorize> extends BaseUser ? {
180
+ user: InputZodLike<InferIOAuthorizeUser<IAuthorize>>;
181
+ } : null : never;
199
182
  type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> = TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
200
183
  type InputZodLike<TData extends JsonObject> = {
201
- parse: (data: unknown) => TData;
184
+ parse: (data: unknown) => TData;
202
185
  } & ({
203
- _input: TData;
186
+ _input: TData;
204
187
  } | {
205
- _zod: {
206
- input: TData;
207
- };
188
+ _zod: {
189
+ input: TData;
190
+ };
208
191
  });
209
192
  type IOAuthorize<TUser extends BaseUser | null = any, TContext extends Record<string, unknown> = {}> = (TUser extends BaseUser ? {
210
- secret?: string;
211
- user: InputZodLike<TUser>;
193
+ secret?: string;
194
+ user: InputZodLike<TUser>;
212
195
  } : null) | ((context: TContext) => TUser extends BaseUser ? {
213
- secret?: string;
214
- user: TUser extends BaseUser ? InputZodLike<TUser> : null;
196
+ secret?: string;
197
+ user: InputZodLike<TUser>;
215
198
  } : null);
216
199
  type IOAuthorizeEventMessage<TIO extends IOLike> = {
217
- connectionId: string;
218
- user: InferIOAuthorizeUser<InferIOAuthorize<TIO>>;
200
+ connectionId: string;
201
+ user: InferIOAuthorizeUser<InferIOAuthorize<TIO>>;
219
202
  };
220
- type ProcedureLike<TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = {
221
- config: {
222
- broadcast?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
223
- input?: InputZodLike<TInput> | null;
224
- resolver: (data: TInput, ...args: any[]) => MaybePromise<TOutput>;
225
- self?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
226
- sync?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
227
- };
203
+ type ProcedureLike<TInput extends Record<string, any> = {}, TOutput extends EventRecord<string, any> = {}> = {
204
+ config: {
205
+ broadcast?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
206
+ input?: InputZodLike<TInput> | null;
207
+ resolver: (data: TInput, ...args: any[]) => MaybePromise<TOutput>;
208
+ self?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
209
+ sync?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
210
+ };
228
211
  };
229
212
  interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> = {}> {
230
- _defs: {
231
- events: TEvents;
232
- };
213
+ _defs: {
214
+ events: TEvents;
215
+ };
233
216
  }
234
217
  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> {
235
- _defs: {
236
- authorize: TAuthorize;
237
- crdt: TCrdt;
238
- events: TEvents;
239
- };
218
+ _defs: {
219
+ authorize: TAuthorize;
220
+ crdt: TCrdt;
221
+ events: TEvents;
222
+ };
240
223
  }
241
224
  type InferIOCrdtKind<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt extends CrdtLibraryType<infer IDoc> ? IDoc : never : never;
242
- type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
243
- [P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? IInput : never;
244
- };
245
- type InferEventsOutput<TEvents extends Record<string, ProcedureLike<any, any>>> = UnionToIntersection<{
246
- [P in keyof TEvents]: TEvents[P] extends ProcedureLike<any, infer IOutput> ? IOutput : never;
247
- }[keyof TEvents]>;
225
+ type InferIOCrdt<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, infer ICrdt, any> ? ICrdt : never;
226
+ type InferIOEvents<TIO extends IOLike<any, any, any>> = TIO extends IOLike<any, any, infer IEvents> ? { [P in keyof IEvents]: ProcedureLike<InferIOProcedureInput<IEvents[P]>, InferIOProcedureOutput<IEvents[P]>> } : never;
227
+ type InferIOProcedureInput<TProcedure extends ProcedureLike<any, any>> = TProcedure extends ProcedureLike<infer IInput, any> ? Id<IInput> : never;
228
+ type InferIOProcedureOutput<TProcedure extends ProcedureLike<any, any>> = TProcedure extends ProcedureLike<any, infer IOutput> ? Id<IOutput> : never;
229
+ type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = { [P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? Id<IInput> : never };
230
+ type InferEventsOutput<TEvents extends Record<string, ProcedureLike<any, any>>> = UnionToIntersection<{ [P in keyof TEvents]: TEvents[P] extends ProcedureLike<any, infer IOutput> ? Id<IOutput> : never }[keyof TEvents]>;
248
231
  type InferIOInput<TRouter extends IORouterLike<any>> = TRouter extends IORouterLike<infer IEvents> ? InferEventsInput<IEvents> : never;
249
232
  type InferIOOutput<TRouter extends IORouterLike<any>> = TRouter extends IORouterLike<infer IEvents> ? InferEventsOutput<IEvents> : never;
250
- type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? {
251
- [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
252
- }[TEvent] : never;
233
+ type InferEventMessage<TEvents = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = TEvents extends EventRecord<string, any> ? { [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never }[TEvent] : never;
253
234
  type IOEventMessage<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
254
- room: string;
235
+ room: string;
255
236
  } & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error" ? Partial<IOAuthorizeEventMessage<TIO>> : IOAuthorizeEventMessage<TIO>)>;
256
237
  type PluvRouterEventConfig = {
257
- [P: string]: Pick<ProcedureLike<any, any>, "config">;
238
+ [P: string]: Pick<ProcedureLike<any, any>, "config">;
258
239
  };
259
- type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, {
260
- [P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? {
261
- [K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
262
- }[keyof IClientOutput] : never;
263
- } & IServerEvents> : never;
264
-
240
+ type MergeEvents<TClientEvents extends PluvRouterEventConfig, TServerIO extends IOLike<any, any, any>> = TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents> ? IOLike<IAuthorize, ICrdt, { [P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<infer IClientInput, infer IClientOutput> ? { [K in keyof IClientOutput]: K extends keyof IServerEvents ? IServerEvents[K] : ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>> }[keyof IClientOutput] : never } & IServerEvents> : never;
241
+ //#endregion
242
+ //#region src/pluv/room.d.ts
265
243
  interface AuthorizationState<TIO extends IOLike> {
266
- token: string | null;
267
- user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
244
+ token: string | null;
245
+ user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
268
246
  }
269
247
  type OtherSubscriptionCallback<TIO extends IOLike, TPresence extends Record<string, any>> = (value: Id<UserInfo<TIO, TPresence>> | null) => void;
270
248
  type OtherSubscriptionFn<TIO extends IOLike, TPresence extends Record<string, any>> = (connectionId: string, callback: OtherSubscriptionCallback<TIO, TPresence>) => () => void;
271
249
  type OthersSubscriptionEvent<TIO extends IOLike, TPresence extends Record<string, any>> = {
272
- kind: "clear";
250
+ kind: "clear";
273
251
  } | {
274
- kind: "enter";
275
- user: Id<UserInfo<TIO, TPresence>>;
252
+ kind: "enter";
253
+ user: Id<UserInfo<TIO, TPresence>>;
276
254
  } | {
277
- kind: "leave";
278
- user: Id<UserInfo<TIO, TPresence>>;
255
+ kind: "leave";
256
+ user: Id<UserInfo<TIO, TPresence>>;
279
257
  } | {
280
- kind: "sync";
281
- users: readonly Id<UserInfo<TIO, TPresence>>[];
258
+ kind: "sync";
259
+ users: readonly Id<UserInfo<TIO, TPresence>>[];
282
260
  } | {
283
- kind: "update";
284
- user: Id<UserInfo<TIO, TPresence>>;
261
+ kind: "update";
262
+ user: Id<UserInfo<TIO, TPresence>>;
285
263
  };
286
264
  type OthersSubscriptionCallback<TIO extends IOLike, TPresence extends Record<string, any>> = (value: readonly Id<UserInfo<TIO, TPresence>>[], event: OthersSubscriptionEvent<TIO, TPresence>) => void;
287
265
  type OthersSubscriptionFn<TIO extends IOLike, TPresence extends Record<string, any>> = (callback: OthersSubscriptionCallback<TIO, TPresence>) => () => void;
288
266
  interface StateNotifierSubjects<TIO extends IOLike, TPresence extends Record<string, any>> {
289
- connection: Subject<Id<WebSocketState<TIO>>>;
290
- "my-presence": Subject<TPresence | null>;
291
- myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
292
- others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
293
- "storage-loaded": Subject<boolean>;
267
+ connection: Subject<Id<WebSocketState<TIO>>>;
268
+ "my-presence": Subject<TPresence | null>;
269
+ myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
270
+ others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
271
+ "storage-loaded": Subject<boolean>;
294
272
  }
295
273
  type InferSubjectValue<TIO extends IOLike, TPresence extends Record<string, any>, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = StateNotifierSubjects<TIO, TPresence>[TSubject] extends Subject<infer IValue> ? Id<IValue> : never;
296
274
  type SubscriptionCallback<TIO extends IOLike, TPresence extends Record<string, any>, TSubject extends keyof StateNotifierSubjects<TIO, TPresence>> = (value: InferSubjectValue<TIO, TPresence, TSubject>) => void;
297
275
  type UpdateMyPresenceAction<TPresence extends Record<string, any>> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
298
276
  interface UserInfo<TIO extends IOLike, TPresence extends Record<string, any> = {}> {
299
- connectionId: string;
300
- presence: TPresence;
301
- user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
277
+ connectionId: string;
278
+ presence: TPresence;
279
+ user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
302
280
  }
303
281
  interface WebSocketConnection {
304
- /**
305
- * @description How many times a connection attempt was made. This will increment upon each
306
- * unsuccessful attempt, and will reset upon a successful connection.
307
- * @date April 13, 2025
308
- */
309
- attempts: number;
310
- id: string | null;
311
- state: ConnectionState;
282
+ /**
283
+ * @description How many times a connection attempt was made. This will increment upon each
284
+ * unsuccessful attempt, and will reset upon a successful connection.
285
+ * @date April 13, 2025
286
+ */
287
+ attempts: number;
288
+ id: string | null;
289
+ state: ConnectionState;
312
290
  }
313
291
  interface StorageInfo {
314
- state: StorageState;
292
+ state: StorageState;
315
293
  }
316
294
  interface WebSocketState<TIO extends IOLike> {
317
- authorization: AuthorizationState<TIO>;
318
- connection: WebSocketConnection;
319
- storage: StorageInfo;
320
- webSocket: WebSocket | null;
295
+ authorization: AuthorizationState<TIO>;
296
+ connection: WebSocketConnection;
297
+ storage: StorageInfo;
298
+ webSocket: WebSocket | null;
321
299
  }
322
- 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>) & {
323
- [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void>;
324
- };
300
+ 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>) & { [PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>) => Promise<void> };
325
301
  type EventNotifierSubscriptionCallback<TIO extends IOLike<any, any, any>, TEvent extends keyof InferIOOutput<TIO>> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
326
302
  type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(event: TEvent, callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>) => () => void;
327
- type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & {
328
- [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void;
329
- };
303
+ type EventProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = EventSubscriptionFn<TIO, TEvents> & { [PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>) => () => void };
330
304
  type StorageSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>, TKey extends keyof TStorage> = (value: InferCrdtJson<TStorage[TKey]>) => void;
331
305
  type StorageSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = <TKey extends keyof TStorage>(key: TKey, fn: StorageSubscriptionCallback<TStorage, TKey>) => () => void;
332
- type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> = (value: {
333
- [P in keyof TStorage]: InferCrdtJson<TStorage[P]>;
334
- }) => void;
306
+ type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> = (value: { [P in keyof TStorage]: InferCrdtJson<TStorage[P]> }) => void;
335
307
  type StorageRootSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = (callback: StorageRootSubscriptionCallback<TStorage>) => () => void;
336
- type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> = StorageSubscriptionFn<TStorage> & StorageRootSubscriptionFn<TStorage> & {
337
- [PKey in keyof TStorage]: (callback: StorageSubscriptionCallback<TStorage, PKey>) => () => void;
338
- };
308
+ type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> = StorageSubscriptionFn<TStorage> & StorageRootSubscriptionFn<TStorage> & { [PKey in keyof TStorage]: (callback: StorageSubscriptionCallback<TStorage, PKey>) => () => void };
339
309
  type SubscribeFn<TValue extends unknown> = (callback: (value: TValue) => void) => () => void;
340
310
  type SubscribeProxy<TIO extends IOLike, TPresence extends Record<string, any>, TStorage extends Record<string, CrdtType<any, any>>, TEvents extends PluvRouterEventConfig> = (<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(name: TSubject, callback: SubscriptionCallback<TIO, TPresence, TSubject>) => () => void) & {
341
- connection: SubscribeFn<Id<WebSocketState<TIO>>>;
342
- event: EventProxy<TIO, TEvents>;
343
- myPresence: SubscribeFn<TPresence | null>;
344
- myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
345
- other: OtherSubscriptionFn<TIO, TPresence>;
346
- others: OthersSubscriptionFn<TIO, TPresence>;
347
- storage: StorageProxy<TStorage>;
348
- storageLoaded: SubscribeFn<boolean>;
311
+ connection: SubscribeFn<Id<WebSocketState<TIO>>>;
312
+ event: EventProxy<TIO, TEvents>;
313
+ myPresence: SubscribeFn<TPresence | null>;
314
+ myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
315
+ other: OtherSubscriptionFn<TIO, TPresence>;
316
+ others: OthersSubscriptionFn<TIO, TPresence>;
317
+ storage: StorageProxy<TStorage>;
318
+ storageLoaded: SubscribeFn<boolean>;
349
319
  };
350
320
  interface RoomEventListenerMap {
351
- close: (event: CloseEvent | null) => void;
352
- error: (event: Event) => void;
353
- message: (event: MessageEvent<any>) => void;
354
- open: (event: Event) => void;
321
+ close: (event: CloseEvent | null) => void;
322
+ error: (event: Event) => void;
323
+ message: (event: MessageEvent<any>) => void;
324
+ open: (event: Event) => void;
355
325
  }
356
326
  interface RoomLike<TIO extends IOLike, TDoc extends any, TPresence extends Record<string, any> = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig = {}> {
357
- id: string;
358
- broadcast: BroadcastProxy<TIO, TEvents>;
359
- addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
360
- canRedo(): boolean;
361
- canUndo(): boolean;
362
- getDoc(): CrdtDocLike<TDoc, TStorage>;
363
- getConnection(): WebSocketConnection;
364
- getMyPresence(): TPresence;
365
- getMyself(): Id<UserInfo<TIO, TPresence>> | null;
366
- getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
367
- getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
368
- getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
369
- getStorageJson(): InferCrdtJson<TStorage> | null;
370
- getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
371
- getStorageLoaded: () => boolean;
372
- redo(): void;
373
- subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
374
- transact(fn: (storage: TStorage) => void, origin?: string): void;
375
- undo(): void;
376
- updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
327
+ id: string;
328
+ broadcast: BroadcastProxy<TIO, TEvents>;
329
+ addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
330
+ canRedo(): boolean;
331
+ canUndo(): boolean;
332
+ getDoc(): CrdtDocLike<TDoc, TStorage>;
333
+ getConnection(): WebSocketConnection;
334
+ getMyPresence(): TPresence;
335
+ getMyself(): Id<UserInfo<TIO, TPresence>> | null;
336
+ getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
337
+ getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
338
+ getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
339
+ getStorageJson(): InferCrdtJson<TStorage> | null;
340
+ getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
341
+ getStorageLoaded: () => boolean;
342
+ redo(): void;
343
+ subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
344
+ transact(fn: (storage: TStorage) => void, origin?: string): void;
345
+ undo(): void;
346
+ updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
377
347
  }
378
-
379
- 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 };
348
+ //#endregion
349
+ export { type AreAllOptional, 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 InferIOCrdt, type InferIOCrdtKind, type InferIOEvents, type InferIOInput, type InferIOOutput, type InferIOProcedureInput, type InferIOProcedureOutput, 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 };
350
+ //# sourceMappingURL=index.d.mts.map