@pluv/types 5.0.0 → 5.0.2
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 +19 -20
- package/dist/index.d.mts.map +1 -1
- package/package.json +9 -6
- package/.turbo/turbo-build.log +0 -13
- package/CHANGELOG.md +0 -542
- package/eslint.config.mjs +0 -4
- package/src/general.ts +0 -90
- package/src/index.ts +0 -82
- package/src/pluv/crdt.ts +0 -82
- package/src/pluv/enums.ts +0 -18
- package/src/pluv/index.ts +0 -4
- package/src/pluv/room.ts +0 -238
- package/src/pluv/shared.ts +0 -243
- package/tsconfig.json +0 -10
- package/tsdown.config.ts +0 -14
package/src/pluv/crdt.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Json, Maybe } from "../general";
|
|
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
|
-
isEmpty(initialStorage: Maybe<string>): boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
|
|
15
|
-
doc: (value: any) => TDoc;
|
|
16
|
-
kind: "loro" | "yjs";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<
|
|
20
|
-
TValue,
|
|
21
|
-
"__pluvType"
|
|
22
|
-
> & {
|
|
23
|
-
__pluvType: () => TJson;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type InferCrdtJson<T extends unknown> =
|
|
27
|
-
T extends CrdtType<any, infer IJson>
|
|
28
|
-
? InferCrdtJson<IJson>
|
|
29
|
-
: T extends Record<string, any>
|
|
30
|
-
? { [P in keyof T]: InferCrdtJson<T[P]> }
|
|
31
|
-
: T extends (infer IJson)[]
|
|
32
|
-
? InferCrdtJson<IJson>[]
|
|
33
|
-
: T extends readonly (infer IJson)[]
|
|
34
|
-
? readonly InferCrdtJson<IJson>[]
|
|
35
|
-
: T extends Json
|
|
36
|
-
? T
|
|
37
|
-
: string;
|
|
38
|
-
|
|
39
|
-
export interface DocApplyEncodedStateParams {
|
|
40
|
-
origin?: string;
|
|
41
|
-
update?: Maybe<string | Uint8Array>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface DocBatchApplyEncodedStateParams {
|
|
45
|
-
origin?: string;
|
|
46
|
-
updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface DocSubscribeCallbackParams<
|
|
50
|
-
TDoc extends any,
|
|
51
|
-
TStorage extends Record<string, CrdtType<any, any>>,
|
|
52
|
-
> {
|
|
53
|
-
doc: CrdtDocLike<TDoc, TStorage>;
|
|
54
|
-
local: boolean;
|
|
55
|
-
origin?: string | null;
|
|
56
|
-
update: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface CrdtDocLike<
|
|
60
|
-
TDoc extends any,
|
|
61
|
-
TStorage extends Record<string, CrdtType<any, any>>,
|
|
62
|
-
> {
|
|
63
|
-
value: TDoc;
|
|
64
|
-
|
|
65
|
-
applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
66
|
-
batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
67
|
-
canRedo(): boolean;
|
|
68
|
-
canUndo(): boolean;
|
|
69
|
-
destroy(): void;
|
|
70
|
-
get(key?: undefined): TStorage;
|
|
71
|
-
get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
72
|
-
getEncodedState(): string;
|
|
73
|
-
isEmpty(): boolean;
|
|
74
|
-
rebuildStorage(reference: TStorage): this;
|
|
75
|
-
redo(): this;
|
|
76
|
-
subscribe(listener: (params: DocSubscribeCallbackParams<TDoc, TStorage>) => void): () => void;
|
|
77
|
-
toJson(): InferCrdtJson<TStorage>;
|
|
78
|
-
toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
79
|
-
track(): this;
|
|
80
|
-
transact(fn: () => void, origin?: string): this;
|
|
81
|
-
undo(): this;
|
|
82
|
-
}
|
package/src/pluv/enums.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const ConnectionState = {
|
|
2
|
-
Closed: "closed",
|
|
3
|
-
Connecting: "connecting",
|
|
4
|
-
Open: "open",
|
|
5
|
-
Unavailable: "unavailable",
|
|
6
|
-
Untouched: "untouched",
|
|
7
|
-
} as const;
|
|
8
|
-
|
|
9
|
-
export type ConnectionState = (typeof ConnectionState)[keyof typeof ConnectionState];
|
|
10
|
-
|
|
11
|
-
export const StorageState = {
|
|
12
|
-
Loading: "loading",
|
|
13
|
-
Offline: "offline",
|
|
14
|
-
Synced: "synced",
|
|
15
|
-
Unavailable: "unavailable",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type StorageState = (typeof StorageState)[keyof typeof StorageState];
|
package/src/pluv/index.ts
DELETED
package/src/pluv/room.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "wonka";
|
|
2
|
-
import type { Id } from "../general";
|
|
3
|
-
import type { CrdtDocLike, CrdtType, InferCrdtJson } from "./crdt";
|
|
4
|
-
import type { ConnectionState, StorageState } from "./enums";
|
|
5
|
-
import type {
|
|
6
|
-
InferIOAuthorize,
|
|
7
|
-
InferIOAuthorizeUser,
|
|
8
|
-
InferIOInput,
|
|
9
|
-
InferIOOutput,
|
|
10
|
-
IOEventMessage,
|
|
11
|
-
IOLike,
|
|
12
|
-
MergeEvents,
|
|
13
|
-
PluvRouterEventConfig,
|
|
14
|
-
} from "./shared";
|
|
15
|
-
|
|
16
|
-
export interface AuthorizationState<TIO extends IOLike> {
|
|
17
|
-
token: string | null;
|
|
18
|
-
user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>> | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type OtherSubscriptionCallback<TIO extends IOLike, TPresence extends Record<string, any>> = (
|
|
22
|
-
value: Id<UserInfo<TIO, TPresence>> | null,
|
|
23
|
-
) => void;
|
|
24
|
-
|
|
25
|
-
export type OtherSubscriptionFn<TIO extends IOLike, TPresence extends Record<string, any>> = (
|
|
26
|
-
connectionId: string,
|
|
27
|
-
callback: OtherSubscriptionCallback<TIO, TPresence>,
|
|
28
|
-
) => () => void;
|
|
29
|
-
|
|
30
|
-
export type OthersSubscriptionEvent<TIO extends IOLike, TPresence extends Record<string, any>> =
|
|
31
|
-
| { kind: "clear" }
|
|
32
|
-
| { kind: "enter"; user: Id<UserInfo<TIO, TPresence>> }
|
|
33
|
-
| { kind: "leave"; user: Id<UserInfo<TIO, TPresence>> }
|
|
34
|
-
| { kind: "sync"; users: readonly Id<UserInfo<TIO, TPresence>>[] }
|
|
35
|
-
| { kind: "update"; user: Id<UserInfo<TIO, TPresence>> };
|
|
36
|
-
|
|
37
|
-
export type OthersSubscriptionCallback<
|
|
38
|
-
TIO extends IOLike,
|
|
39
|
-
TPresence extends Record<string, any>,
|
|
40
|
-
> = (
|
|
41
|
-
value: readonly Id<UserInfo<TIO, TPresence>>[],
|
|
42
|
-
event: OthersSubscriptionEvent<TIO, TPresence>,
|
|
43
|
-
) => void;
|
|
44
|
-
|
|
45
|
-
export type OthersSubscriptionFn<TIO extends IOLike, TPresence extends Record<string, any>> = (
|
|
46
|
-
callback: OthersSubscriptionCallback<TIO, TPresence>,
|
|
47
|
-
) => () => void;
|
|
48
|
-
|
|
49
|
-
export interface StateNotifierSubjects<TIO extends IOLike, TPresence extends Record<string, any>> {
|
|
50
|
-
connection: Subject<Id<WebSocketState<TIO>>>;
|
|
51
|
-
"my-presence": Subject<TPresence | null>;
|
|
52
|
-
myself: Subject<Readonly<Id<UserInfo<TIO, TPresence>>> | null>;
|
|
53
|
-
others: Subject<readonly Id<UserInfo<TIO, TPresence>>[]>;
|
|
54
|
-
"storage-loaded": Subject<boolean>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type InferSubjectValue<
|
|
58
|
-
TIO extends IOLike,
|
|
59
|
-
TPresence extends Record<string, any>,
|
|
60
|
-
TSubject extends keyof StateNotifierSubjects<TIO, TPresence>,
|
|
61
|
-
> =
|
|
62
|
-
StateNotifierSubjects<TIO, TPresence>[TSubject] extends Subject<infer IValue>
|
|
63
|
-
? Id<IValue>
|
|
64
|
-
: never;
|
|
65
|
-
|
|
66
|
-
export type SubscriptionCallback<
|
|
67
|
-
TIO extends IOLike,
|
|
68
|
-
TPresence extends Record<string, any>,
|
|
69
|
-
TSubject extends keyof StateNotifierSubjects<TIO, TPresence>,
|
|
70
|
-
> = (value: InferSubjectValue<TIO, TPresence, TSubject>) => void;
|
|
71
|
-
|
|
72
|
-
export type UpdateMyPresenceAction<TPresence extends Record<string, any>> =
|
|
73
|
-
| Partial<TPresence>
|
|
74
|
-
| ((oldPresence: TPresence | null) => Partial<TPresence>);
|
|
75
|
-
|
|
76
|
-
export interface UserInfo<TIO extends IOLike, TPresence extends Record<string, any> = {}> {
|
|
77
|
-
connectionId: string;
|
|
78
|
-
presence: TPresence;
|
|
79
|
-
user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface WebSocketConnection {
|
|
83
|
-
/**
|
|
84
|
-
* @description How many times a connection attempt was made. This will increment upon each
|
|
85
|
-
* unsuccessful attempt, and will reset upon a successful connection.
|
|
86
|
-
* @date April 13, 2025
|
|
87
|
-
*/
|
|
88
|
-
attempts: number;
|
|
89
|
-
id: string | null;
|
|
90
|
-
state: ConnectionState;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface StorageInfo {
|
|
94
|
-
state: StorageState;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface WebSocketState<TIO extends IOLike> {
|
|
98
|
-
authorization: AuthorizationState<TIO>;
|
|
99
|
-
connection: WebSocketConnection;
|
|
100
|
-
storage: StorageInfo;
|
|
101
|
-
webSocket: WebSocket | null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type BroadcastProxy<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = (<
|
|
105
|
-
TEvent extends keyof InferIOInput<MergeEvents<TEvents, TIO>>,
|
|
106
|
-
>(
|
|
107
|
-
event: TEvent,
|
|
108
|
-
data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[TEvent]>,
|
|
109
|
-
) => Promise<void>) & {
|
|
110
|
-
[PEvent in keyof InferIOInput<MergeEvents<TEvents, TIO>>]: (
|
|
111
|
-
data: Id<InferIOInput<MergeEvents<TEvents, TIO>>[PEvent]>,
|
|
112
|
-
) => Promise<void>;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export type EventNotifierSubscriptionCallback<
|
|
116
|
-
TIO extends IOLike<any, any, any>,
|
|
117
|
-
TEvent extends keyof InferIOOutput<TIO>,
|
|
118
|
-
> = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
|
|
119
|
-
|
|
120
|
-
export type EventSubscriptionFn<TIO extends IOLike, TEvents extends PluvRouterEventConfig> = <
|
|
121
|
-
TEvent extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>,
|
|
122
|
-
>(
|
|
123
|
-
event: TEvent,
|
|
124
|
-
callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, TEvent>,
|
|
125
|
-
) => () => void;
|
|
126
|
-
|
|
127
|
-
export type EventProxy<
|
|
128
|
-
TIO extends IOLike,
|
|
129
|
-
TEvents extends PluvRouterEventConfig,
|
|
130
|
-
> = EventSubscriptionFn<TIO, TEvents> & {
|
|
131
|
-
[PEvent in keyof InferIOOutput<MergeEvents<TEvents, TIO>>]: (
|
|
132
|
-
callback: EventNotifierSubscriptionCallback<MergeEvents<TEvents, TIO>, PEvent>,
|
|
133
|
-
) => () => void;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export type StorageSubscriptionCallback<
|
|
137
|
-
TStorage extends Record<string, CrdtType<any, any>>,
|
|
138
|
-
TKey extends keyof TStorage,
|
|
139
|
-
> = (value: InferCrdtJson<TStorage[TKey]>) => void;
|
|
140
|
-
|
|
141
|
-
export type StorageSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = <
|
|
142
|
-
TKey extends keyof TStorage,
|
|
143
|
-
>(
|
|
144
|
-
key: TKey,
|
|
145
|
-
fn: StorageSubscriptionCallback<TStorage, TKey>,
|
|
146
|
-
) => () => void;
|
|
147
|
-
|
|
148
|
-
export type StorageRootSubscriptionCallback<TStorage extends Record<string, CrdtType<any, any>>> =
|
|
149
|
-
(value: { [P in keyof TStorage]: InferCrdtJson<TStorage[P]> }) => void;
|
|
150
|
-
|
|
151
|
-
export type StorageRootSubscriptionFn<TStorage extends Record<string, CrdtType<any, any>>> = (
|
|
152
|
-
callback: StorageRootSubscriptionCallback<TStorage>,
|
|
153
|
-
) => () => void;
|
|
154
|
-
|
|
155
|
-
export type StorageProxy<TStorage extends Record<string, CrdtType<any, any>>> =
|
|
156
|
-
StorageSubscriptionFn<TStorage> &
|
|
157
|
-
StorageRootSubscriptionFn<TStorage> & {
|
|
158
|
-
[PKey in keyof TStorage]: (
|
|
159
|
-
callback: StorageSubscriptionCallback<TStorage, PKey>,
|
|
160
|
-
) => () => void;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export type SubscribeFn<TValue extends unknown> = (callback: (value: TValue) => void) => () => void;
|
|
164
|
-
|
|
165
|
-
export type SubscribeProxy<
|
|
166
|
-
TIO extends IOLike,
|
|
167
|
-
TPresence extends Record<string, any>,
|
|
168
|
-
TStorage extends Record<string, CrdtType<any, any>>,
|
|
169
|
-
TEvents extends PluvRouterEventConfig,
|
|
170
|
-
> = (<TSubject extends keyof StateNotifierSubjects<TIO, TPresence>>(
|
|
171
|
-
name: TSubject,
|
|
172
|
-
callback: SubscriptionCallback<TIO, TPresence, TSubject>,
|
|
173
|
-
) => () => void) & {
|
|
174
|
-
connection: SubscribeFn<Id<WebSocketState<TIO>>>;
|
|
175
|
-
event: EventProxy<TIO, TEvents>;
|
|
176
|
-
myPresence: SubscribeFn<TPresence | null>;
|
|
177
|
-
myself: SubscribeFn<Id<UserInfo<TIO>> | null>;
|
|
178
|
-
other: OtherSubscriptionFn<TIO, TPresence>;
|
|
179
|
-
others: OthersSubscriptionFn<TIO, TPresence>;
|
|
180
|
-
storage: StorageProxy<TStorage>;
|
|
181
|
-
storageLoaded: SubscribeFn<boolean>;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export interface RoomEventListenerMap {
|
|
185
|
-
close: (event: CloseEvent | null) => void;
|
|
186
|
-
error: (event: Event) => void;
|
|
187
|
-
message: (event: MessageEvent<any>) => void;
|
|
188
|
-
open: (event: Event) => void;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export interface RoomLike<
|
|
192
|
-
TIO extends IOLike,
|
|
193
|
-
TDoc extends any,
|
|
194
|
-
TPresence extends Record<string, any> = {},
|
|
195
|
-
TStorage extends Record<string, CrdtType<any, any>> = {},
|
|
196
|
-
TEvents extends PluvRouterEventConfig = {},
|
|
197
|
-
> {
|
|
198
|
-
id: string;
|
|
199
|
-
broadcast: BroadcastProxy<TIO, TEvents>;
|
|
200
|
-
|
|
201
|
-
addEventListener<TKind extends keyof RoomEventListenerMap>(
|
|
202
|
-
kind: TKind,
|
|
203
|
-
handler: RoomEventListenerMap[TKind],
|
|
204
|
-
): () => void;
|
|
205
|
-
|
|
206
|
-
canRedo(): boolean;
|
|
207
|
-
|
|
208
|
-
canUndo(): boolean;
|
|
209
|
-
|
|
210
|
-
getDoc(): CrdtDocLike<TDoc, TStorage>;
|
|
211
|
-
|
|
212
|
-
getConnection(): WebSocketConnection;
|
|
213
|
-
|
|
214
|
-
getMyPresence(): TPresence;
|
|
215
|
-
|
|
216
|
-
getMyself(): Id<UserInfo<TIO, TPresence>> | null;
|
|
217
|
-
|
|
218
|
-
getOther(connectionId: string): Id<UserInfo<TIO, TPresence>> | null;
|
|
219
|
-
|
|
220
|
-
getOthers(): readonly Id<UserInfo<TIO, TPresence>>[];
|
|
221
|
-
|
|
222
|
-
getStorage<TKey extends keyof TStorage>(type: TKey): TStorage[TKey] | null;
|
|
223
|
-
|
|
224
|
-
getStorageJson(): InferCrdtJson<TStorage> | null;
|
|
225
|
-
getStorageJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]> | null;
|
|
226
|
-
|
|
227
|
-
getStorageLoaded: () => boolean;
|
|
228
|
-
|
|
229
|
-
redo(): void;
|
|
230
|
-
|
|
231
|
-
subscribe: SubscribeProxy<TIO, TPresence, TStorage, TEvents>;
|
|
232
|
-
|
|
233
|
-
transact(fn: (storage: TStorage) => void, origin?: string): void;
|
|
234
|
-
|
|
235
|
-
undo(): void;
|
|
236
|
-
|
|
237
|
-
updateMyPresence(presence: UpdateMyPresenceAction<TPresence>): void;
|
|
238
|
-
}
|
package/src/pluv/shared.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import type { Id, JsonObject, MaybePromise, UnionToIntersection } from "../general";
|
|
2
|
-
import { CrdtLibraryType } from "./crdt";
|
|
3
|
-
|
|
4
|
-
export type BaseUser = {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export interface BaseClientEventRecord {
|
|
9
|
-
$getOthers: {};
|
|
10
|
-
$initializeSession: {
|
|
11
|
-
presence: JsonObject;
|
|
12
|
-
update: string | null;
|
|
13
|
-
};
|
|
14
|
-
$ping: {};
|
|
15
|
-
$updatePresence: {
|
|
16
|
-
presence: JsonObject;
|
|
17
|
-
};
|
|
18
|
-
$updateStorage: {
|
|
19
|
-
origin: string | null;
|
|
20
|
-
update: string;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type BaseClientMessage = InferEventMessage<BaseClientEventRecord>;
|
|
25
|
-
|
|
26
|
-
export type BaseIOEventRecord<TAuthorize extends IOAuthorize<any, any>> = {
|
|
27
|
-
$error: {
|
|
28
|
-
message: string;
|
|
29
|
-
stack?: string | null;
|
|
30
|
-
};
|
|
31
|
-
$exit: {
|
|
32
|
-
sessionId: string;
|
|
33
|
-
};
|
|
34
|
-
$othersReceived: {
|
|
35
|
-
others: {
|
|
36
|
-
[connectionId: string]: {
|
|
37
|
-
connectionId: string;
|
|
38
|
-
presence: JsonObject | null;
|
|
39
|
-
room: string | null;
|
|
40
|
-
timers: { presence: number | null };
|
|
41
|
-
user: Id<InferIOAuthorizeUser<TAuthorize>>;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
$pong: {};
|
|
46
|
-
$presenceUpdated: {
|
|
47
|
-
presence: JsonObject;
|
|
48
|
-
timers: { presence: number | null };
|
|
49
|
-
};
|
|
50
|
-
$registered: {
|
|
51
|
-
presence: JsonObject | null;
|
|
52
|
-
sessionId: string;
|
|
53
|
-
state: string | null;
|
|
54
|
-
timers: { presence: number | null };
|
|
55
|
-
};
|
|
56
|
-
$storageReceived: {
|
|
57
|
-
changeKind: "empty" | "initialized" | "unchanged";
|
|
58
|
-
state: string;
|
|
59
|
-
};
|
|
60
|
-
$storageUpdated: {
|
|
61
|
-
state: string;
|
|
62
|
-
};
|
|
63
|
-
$syncStateReceived: {
|
|
64
|
-
connectionIds: readonly string[];
|
|
65
|
-
};
|
|
66
|
-
$userJoined: {
|
|
67
|
-
connectionId: string;
|
|
68
|
-
presence: JsonObject;
|
|
69
|
-
timers: { presence: number | null };
|
|
70
|
-
user: NonNullable<Id<InferIOAuthorizeUser<TAuthorize>>>;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export interface EventMessage<TEvent extends string, TData extends JsonObject = {}> {
|
|
75
|
-
data: TData;
|
|
76
|
-
type: TEvent;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type EventRecord<TEvent extends string, TData extends JsonObject> = {
|
|
80
|
-
[key in `${TEvent}`]: TData;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type GetEventMessage<
|
|
84
|
-
T extends EventRecord<string, any>,
|
|
85
|
-
TEvent extends keyof T,
|
|
86
|
-
> = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
|
|
87
|
-
|
|
88
|
-
export type InferIOAuthorize<TIO extends IOLike<any, any, any>> =
|
|
89
|
-
TIO extends IOLike<infer IAuthorize, any, any>
|
|
90
|
-
? InferIOAuthorizeUser<IAuthorize> extends BaseUser
|
|
91
|
-
? { user: InputZodLike<InferIOAuthorizeUser<IAuthorize>> }
|
|
92
|
-
: null
|
|
93
|
-
: never;
|
|
94
|
-
|
|
95
|
-
export type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any> | null> =
|
|
96
|
-
TAuthorize extends IOAuthorize<infer IUser, any> ? IUser : null;
|
|
97
|
-
|
|
98
|
-
export type InputZodLike<TData extends JsonObject> = {
|
|
99
|
-
parse: (data: unknown) => TData;
|
|
100
|
-
} & ({ _input: TData } | { _zod: { input: TData } });
|
|
101
|
-
|
|
102
|
-
export type IOAuthorize<
|
|
103
|
-
TUser extends BaseUser | null = any,
|
|
104
|
-
TContext extends Record<string, unknown> = {},
|
|
105
|
-
> =
|
|
106
|
-
| (TUser extends BaseUser
|
|
107
|
-
? {
|
|
108
|
-
secret?: string;
|
|
109
|
-
user: InputZodLike<TUser>;
|
|
110
|
-
}
|
|
111
|
-
: null)
|
|
112
|
-
| ((context: TContext) => TUser extends BaseUser
|
|
113
|
-
? {
|
|
114
|
-
secret?: string;
|
|
115
|
-
user: InputZodLike<TUser>;
|
|
116
|
-
}
|
|
117
|
-
: null);
|
|
118
|
-
|
|
119
|
-
export type IOAuthorizeEventMessage<TIO extends IOLike> = {
|
|
120
|
-
connectionId: string;
|
|
121
|
-
user: InferIOAuthorizeUser<InferIOAuthorize<TIO>>;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export type ProcedureLike<
|
|
125
|
-
TInput extends Record<string, any> = {},
|
|
126
|
-
TOutput extends EventRecord<string, any> = {},
|
|
127
|
-
> = {
|
|
128
|
-
config: {
|
|
129
|
-
broadcast?:
|
|
130
|
-
| ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>)
|
|
131
|
-
| null;
|
|
132
|
-
input?: InputZodLike<TInput> | null;
|
|
133
|
-
resolver: (data: TInput, ...args: any[]) => MaybePromise<TOutput>;
|
|
134
|
-
self?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
|
|
135
|
-
sync?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> = {}> {
|
|
140
|
-
_defs: {
|
|
141
|
-
events: TEvents;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface IOLike<
|
|
146
|
-
TAuthorize extends IOAuthorize<any, any> | null = null,
|
|
147
|
-
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
148
|
-
TEvents extends Record<string, ProcedureLike<any, any>> = {},
|
|
149
|
-
> extends IORouterLike<TEvents> {
|
|
150
|
-
_defs: {
|
|
151
|
-
authorize: TAuthorize;
|
|
152
|
-
crdt: TCrdt;
|
|
153
|
-
events: TEvents;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type InferIOCrdtKind<TIO extends IOLike<any, any, any>> =
|
|
158
|
-
TIO extends IOLike<any, infer ICrdt, any>
|
|
159
|
-
? ICrdt extends CrdtLibraryType<infer IDoc>
|
|
160
|
-
? IDoc
|
|
161
|
-
: never
|
|
162
|
-
: never;
|
|
163
|
-
|
|
164
|
-
export type InferIOCrdt<TIO extends IOLike<any, any, any>> =
|
|
165
|
-
TIO extends IOLike<any, infer ICrdt, any> ? ICrdt : never;
|
|
166
|
-
|
|
167
|
-
export type InferIOEvents<TIO extends IOLike<any, any, any>> =
|
|
168
|
-
TIO extends IOLike<any, any, infer IEvents>
|
|
169
|
-
? {
|
|
170
|
-
[P in keyof IEvents]: ProcedureLike<
|
|
171
|
-
InferIOProcedureInput<IEvents[P]>,
|
|
172
|
-
InferIOProcedureOutput<IEvents[P]>
|
|
173
|
-
>;
|
|
174
|
-
}
|
|
175
|
-
: never;
|
|
176
|
-
|
|
177
|
-
export type InferIOProcedureInput<TProcedure extends ProcedureLike<any, any>> =
|
|
178
|
-
TProcedure extends ProcedureLike<infer IInput, any> ? Id<IInput> : never;
|
|
179
|
-
|
|
180
|
-
export type InferIOProcedureOutput<TProcedure extends ProcedureLike<any, any>> =
|
|
181
|
-
TProcedure extends ProcedureLike<any, infer IOutput> ? Id<IOutput> : never;
|
|
182
|
-
|
|
183
|
-
export type InferEventsInput<TEvents extends Record<string, ProcedureLike<any, any>>> = {
|
|
184
|
-
[P in keyof TEvents]: TEvents[P] extends ProcedureLike<infer IInput, any> ? Id<IInput> : never;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export type InferEventsOutput<TEvents extends Record<string, ProcedureLike<any, any>>> =
|
|
188
|
-
UnionToIntersection<
|
|
189
|
-
{
|
|
190
|
-
[P in keyof TEvents]: TEvents[P] extends ProcedureLike<any, infer IOutput>
|
|
191
|
-
? Id<IOutput>
|
|
192
|
-
: never;
|
|
193
|
-
}[keyof TEvents]
|
|
194
|
-
>;
|
|
195
|
-
|
|
196
|
-
export type InferIOInput<TRouter extends IORouterLike<any>> =
|
|
197
|
-
TRouter extends IORouterLike<infer IEvents> ? InferEventsInput<IEvents> : never;
|
|
198
|
-
|
|
199
|
-
export type InferIOOutput<TRouter extends IORouterLike<any>> =
|
|
200
|
-
TRouter extends IORouterLike<infer IEvents> ? InferEventsOutput<IEvents> : never;
|
|
201
|
-
|
|
202
|
-
export type InferEventMessage<
|
|
203
|
-
TEvents = EventRecord<string, any>,
|
|
204
|
-
TEvent extends keyof TEvents = keyof TEvents,
|
|
205
|
-
> =
|
|
206
|
-
TEvents extends EventRecord<string, any>
|
|
207
|
-
? { [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never }[TEvent]
|
|
208
|
-
: never;
|
|
209
|
-
|
|
210
|
-
export type IOEventMessage<
|
|
211
|
-
TIO extends IOLike<any, any, any>,
|
|
212
|
-
TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>,
|
|
213
|
-
> = Id<
|
|
214
|
-
{ room: string } & InferEventMessage<InferIOOutput<TIO>, TEvent> &
|
|
215
|
-
(InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$error"
|
|
216
|
-
? Partial<IOAuthorizeEventMessage<TIO>>
|
|
217
|
-
: IOAuthorizeEventMessage<TIO>)
|
|
218
|
-
>;
|
|
219
|
-
|
|
220
|
-
export type PluvRouterEventConfig = { [P: string]: Pick<ProcedureLike<any, any>, "config"> };
|
|
221
|
-
|
|
222
|
-
export type MergeEvents<
|
|
223
|
-
TClientEvents extends PluvRouterEventConfig,
|
|
224
|
-
TServerIO extends IOLike<any, any, any>,
|
|
225
|
-
> =
|
|
226
|
-
TServerIO extends IOLike<infer IAuthorize, infer ICrdt, infer IServerEvents>
|
|
227
|
-
? IOLike<
|
|
228
|
-
IAuthorize,
|
|
229
|
-
ICrdt,
|
|
230
|
-
{
|
|
231
|
-
[P in keyof TClientEvents]: TClientEvents[P] extends ProcedureLike<
|
|
232
|
-
infer IClientInput,
|
|
233
|
-
infer IClientOutput
|
|
234
|
-
>
|
|
235
|
-
? {
|
|
236
|
-
[K in keyof IClientOutput]: K extends keyof IServerEvents
|
|
237
|
-
? IServerEvents[K]
|
|
238
|
-
: ProcedureLike<IClientInput, Id<Pick<IClientOutput, K>>>;
|
|
239
|
-
}[keyof IClientOutput]
|
|
240
|
-
: never;
|
|
241
|
-
} & IServerEvents
|
|
242
|
-
>
|
|
243
|
-
: never;
|
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED