@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/.turbo/turbo-build.log +14 -16
- package/CHANGELOG.md +20 -0
- package/dist/index.d.mts +240 -269
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +16 -16
- package/dist/index.mjs.map +1 -0
- package/package.json +15 -10
- package/src/general.ts +12 -0
- package/src/index.ts +5 -0
- package/src/pluv/shared.ts +28 -5
- package/tsdown.config.ts +14 -0
- package/dist/index.d.ts +0 -379
- package/dist/index.js +0 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,379 +1,350 @@
|
|
|
1
|
-
import { Subject } from
|
|
1
|
+
import { Subject } from "wonka";
|
|
2
2
|
|
|
3
|
+
//#region src/general.d.ts
|
|
3
4
|
type Constructable = {
|
|
4
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
47
|
+
origin?: string;
|
|
48
|
+
update?: Maybe<string | Uint8Array>;
|
|
68
49
|
}
|
|
69
50
|
interface DocBatchApplyEncodedStateParams {
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
100
|
+
id: string;
|
|
118
101
|
};
|
|
119
102
|
interface BaseClientEventRecord {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
166
|
-
state: string | null;
|
|
131
|
+
room: string | null;
|
|
167
132
|
timers: {
|
|
168
|
-
|
|
133
|
+
presence: number | null;
|
|
169
134
|
};
|
|
135
|
+
user: Id<InferIOAuthorizeUser<TAuthorize>>;
|
|
136
|
+
};
|
|
170
137
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
138
|
+
};
|
|
139
|
+
$pong: {};
|
|
140
|
+
$presenceUpdated: {
|
|
141
|
+
presence: JsonObject;
|
|
142
|
+
timers: {
|
|
143
|
+
presence: number | null;
|
|
177
144
|
};
|
|
178
|
-
|
|
179
|
-
|
|
145
|
+
};
|
|
146
|
+
$registered: {
|
|
147
|
+
presence: JsonObject | null;
|
|
148
|
+
sessionId: string;
|
|
149
|
+
state: string | null;
|
|
150
|
+
timers: {
|
|
151
|
+
presence: number | null;
|
|
180
152
|
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
192
|
-
|
|
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
|
|
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
|
-
|
|
184
|
+
parse: (data: unknown) => TData;
|
|
202
185
|
} & ({
|
|
203
|
-
|
|
186
|
+
_input: TData;
|
|
204
187
|
} | {
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
211
|
-
|
|
193
|
+
secret?: string;
|
|
194
|
+
user: InputZodLike<TUser>;
|
|
212
195
|
} : null) | ((context: TContext) => TUser extends BaseUser ? {
|
|
213
|
-
|
|
214
|
-
|
|
196
|
+
secret?: string;
|
|
197
|
+
user: InputZodLike<TUser>;
|
|
215
198
|
} : null);
|
|
216
199
|
type IOAuthorizeEventMessage<TIO extends IOLike> = {
|
|
217
|
-
|
|
218
|
-
|
|
200
|
+
connectionId: string;
|
|
201
|
+
user: InferIOAuthorizeUser<InferIOAuthorize<TIO>>;
|
|
219
202
|
};
|
|
220
|
-
type ProcedureLike<TInput extends
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
231
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
type
|
|
246
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
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
|
-
|
|
267
|
-
|
|
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
|
-
|
|
250
|
+
kind: "clear";
|
|
273
251
|
} | {
|
|
274
|
-
|
|
275
|
-
|
|
252
|
+
kind: "enter";
|
|
253
|
+
user: Id<UserInfo<TIO, TPresence>>;
|
|
276
254
|
} | {
|
|
277
|
-
|
|
278
|
-
|
|
255
|
+
kind: "leave";
|
|
256
|
+
user: Id<UserInfo<TIO, TPresence>>;
|
|
279
257
|
} | {
|
|
280
|
-
|
|
281
|
-
|
|
258
|
+
kind: "sync";
|
|
259
|
+
users: readonly Id<UserInfo<TIO, TPresence>>[];
|
|
282
260
|
} | {
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
277
|
+
connectionId: string;
|
|
278
|
+
presence: TPresence;
|
|
279
|
+
user: Id<InferIOAuthorizeUser<InferIOAuthorize<TIO>>>;
|
|
302
280
|
}
|
|
303
281
|
interface WebSocketConnection {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
292
|
+
state: StorageState;
|
|
315
293
|
}
|
|
316
294
|
interface WebSocketState<TIO extends IOLike> {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|