@super-line/core 0.1.0 → 0.2.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.cts +125 -7
- package/dist/index.d.ts +125 -7
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -55,6 +55,71 @@ interface Adapter {
|
|
|
55
55
|
onMessage(handler: (channel: string, payload: string | Uint8Array) => void): void;
|
|
56
56
|
/** Optional teardown (e.g. close Redis connections). */
|
|
57
57
|
close?(): void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Optional cluster-wide presence directory. Powers `srv.cluster.*` and
|
|
60
|
+
* `srv.isOnline`. The in-memory and Redis adapters implement it; cluster
|
|
61
|
+
* queries throw a clear error on an adapter that doesn't.
|
|
62
|
+
*/
|
|
63
|
+
presence?: PresenceStore;
|
|
64
|
+
}
|
|
65
|
+
/** A serializable snapshot of a connection, shared cluster-wide via the {@link PresenceStore}. */
|
|
66
|
+
interface ConnDescriptor {
|
|
67
|
+
/** The connection's server-assigned id. */
|
|
68
|
+
id: string;
|
|
69
|
+
/** The connection's role. */
|
|
70
|
+
role: string;
|
|
71
|
+
/** The node that holds this connection. */
|
|
72
|
+
nodeId: string;
|
|
73
|
+
/** When the connection was accepted (`Date.now()`). */
|
|
74
|
+
connectedAt: number;
|
|
75
|
+
/** The stable user key from the server's `identify` hook, if any. */
|
|
76
|
+
userId?: string;
|
|
77
|
+
/** Room memberships (topics and node-local `lastPongAt` are not included). */
|
|
78
|
+
rooms: string[];
|
|
79
|
+
/** Extra fields contributed by the server's `describeConn` hook. */
|
|
80
|
+
[extra: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
/** Per-node aggregate, returned by {@link PresenceStore.topology}. */
|
|
83
|
+
interface NodeStat {
|
|
84
|
+
/** The node's id. */
|
|
85
|
+
nodeId: string;
|
|
86
|
+
/** Number of connections on the node. */
|
|
87
|
+
connections: number;
|
|
88
|
+
/** Number of distinct rooms with members on the node. */
|
|
89
|
+
rooms: number;
|
|
90
|
+
/** Whether the node is currently live (heartbeat fresh). */
|
|
91
|
+
alive: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Cluster-wide presence directory: a query/addressbook layer kept in the shared
|
|
95
|
+
* substrate (in-memory bus or Redis). Live message delivery does NOT read this —
|
|
96
|
+
* it exists only to answer `srv.cluster.*` / `srv.isOnline`.
|
|
97
|
+
*/
|
|
98
|
+
interface PresenceStore {
|
|
99
|
+
/** Record (or replace) a connection's descriptor. */
|
|
100
|
+
set(descriptor: ConnDescriptor): void | Promise<void>;
|
|
101
|
+
/** Remove a connection's descriptor. */
|
|
102
|
+
del(connId: string): void | Promise<void>;
|
|
103
|
+
/** Refresh this node's liveness (heartbeat). */
|
|
104
|
+
beat(nodeId: string): void | Promise<void>;
|
|
105
|
+
/** Remove all of a node's connections + liveness (graceful shutdown cleanup). */
|
|
106
|
+
clearNode(nodeId: string): void | Promise<void>;
|
|
107
|
+
/** Add a room to a connection's membership. */
|
|
108
|
+
addRoom(connId: string, room: string): void | Promise<void>;
|
|
109
|
+
/** Remove a room from a connection's membership. */
|
|
110
|
+
removeRoom(connId: string, room: string): void | Promise<void>;
|
|
111
|
+
/** All live connection descriptors across the cluster. */
|
|
112
|
+
list(): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
113
|
+
/** One connection's descriptor, if present. */
|
|
114
|
+
get(connId: string): (ConnDescriptor | undefined) | Promise<ConnDescriptor | undefined>;
|
|
115
|
+
/** Descriptors for a given user key. */
|
|
116
|
+
byUser(userId: string): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
117
|
+
/** Descriptors that are members of `room`. */
|
|
118
|
+
roomMembers(room: string): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
119
|
+
/** Total live connection count across the cluster. */
|
|
120
|
+
count(): number | Promise<number>;
|
|
121
|
+
/** Per-node aggregates. */
|
|
122
|
+
topology(): NodeStat[] | Promise<NodeStat[]>;
|
|
58
123
|
}
|
|
59
124
|
|
|
60
125
|
/** Any [Standard Schema](https://standardschema.dev) validator (Zod, Valibot, ArkType…). */
|
|
@@ -80,12 +145,30 @@ interface ServerMessageDef {
|
|
|
80
145
|
/** When `true`, clients opt in via `client.subscribe(...)` (a topic). Omit for a push event. */
|
|
81
146
|
subscribe?: boolean;
|
|
82
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A server→client request (request/response). The server sends `input`; the
|
|
150
|
+
* client's `implement` handler returns `output`. Lives in `serverToClient`
|
|
151
|
+
* alongside events and topics, distinguished by having `input`.
|
|
152
|
+
*/
|
|
153
|
+
interface ServerRequestDef {
|
|
154
|
+
/** Schema for the request payload the server sends. */
|
|
155
|
+
input: Schema;
|
|
156
|
+
/** Schema for the reply the client returns. */
|
|
157
|
+
output: Schema;
|
|
158
|
+
}
|
|
159
|
+
/** A `serverToClient` entry: a push event, a subscribable topic, or a server→client request. */
|
|
160
|
+
type ServerEntry = ServerMessageDef | ServerRequestDef;
|
|
83
161
|
/** The two directions within a `shared` or role block. */
|
|
84
162
|
interface Directional {
|
|
85
163
|
/** Requests this side may call (client→server). */
|
|
86
164
|
clientToServer?: Record<string, RequestDef>;
|
|
87
|
-
/** Events
|
|
88
|
-
serverToClient?: Record<string,
|
|
165
|
+
/** Events, topics, and server→client requests this side may receive. */
|
|
166
|
+
serverToClient?: Record<string, ServerEntry>;
|
|
167
|
+
}
|
|
168
|
+
/** A role block: its directions plus an optional `data` schema typing `conn.data`. */
|
|
169
|
+
interface RoleBlock extends Directional {
|
|
170
|
+
/** Schema for this role's mutable per-connection `conn.data` (server-side scratch state). */
|
|
171
|
+
data?: Schema;
|
|
89
172
|
}
|
|
90
173
|
/**
|
|
91
174
|
* The single source of truth, imported by both server and client. Split by
|
|
@@ -96,7 +179,7 @@ interface Contract {
|
|
|
96
179
|
/** Surface common to every role (merged into each role's effective surface). */
|
|
97
180
|
shared?: Directional;
|
|
98
181
|
/** Per-role surfaces. A connection's role selects which one (plus `shared`) it sees. */
|
|
99
|
-
roles: Record<string,
|
|
182
|
+
roles: Record<string, RoleBlock>;
|
|
100
183
|
/** Typed node-to-node event payloads, for {@link "@super-line/server"!}'s `emitServer`/`onServer`. */
|
|
101
184
|
serverToServer?: Record<string, Schema>;
|
|
102
185
|
}
|
|
@@ -129,10 +212,12 @@ type CtsOf<D> = D extends {
|
|
|
129
212
|
clientToServer: infer M extends Record<string, RequestDef>;
|
|
130
213
|
} ? M : {};
|
|
131
214
|
type StcOf<D> = D extends {
|
|
132
|
-
serverToClient: infer M extends Record<string,
|
|
215
|
+
serverToClient: infer M extends Record<string, ServerEntry>;
|
|
133
216
|
} ? M : {};
|
|
134
217
|
type EventsOf<M> = {
|
|
135
218
|
[K in keyof M as M[K] extends {
|
|
219
|
+
input: Schema;
|
|
220
|
+
} ? never : M[K] extends {
|
|
136
221
|
subscribe: true;
|
|
137
222
|
} ? never : K]: M[K];
|
|
138
223
|
};
|
|
@@ -141,6 +226,11 @@ type TopicsOf<M> = {
|
|
|
141
226
|
subscribe: true;
|
|
142
227
|
} ? K : never]: M[K];
|
|
143
228
|
};
|
|
229
|
+
type ServerReqOf<M> = {
|
|
230
|
+
[K in keyof M as M[K] extends {
|
|
231
|
+
input: Schema;
|
|
232
|
+
} ? K : never]: M[K];
|
|
233
|
+
};
|
|
144
234
|
/** A role's effective request map: `shared` ∪ `roles[R]` client→server requests. */
|
|
145
235
|
type Requests<C extends Contract, R extends RoleOf<C>> = CtsOf<C['shared']> & CtsOf<C['roles'][R]>;
|
|
146
236
|
/** A role's effective server→client map (events and topics combined). */
|
|
@@ -159,6 +249,16 @@ type SharedEvents<C extends Contract> = EventsOf<StcOf<C['shared']>>;
|
|
|
159
249
|
type SharedTopics<C extends Contract> = TopicsOf<StcOf<C['shared']>>;
|
|
160
250
|
/** Subscribable topics in one role's block (published via `srv.forRole(r).publish`). */
|
|
161
251
|
type RoleTopics<C extends Contract, R extends RoleOf<C>> = TopicsOf<StcOf<C['roles'][R]>>;
|
|
252
|
+
/** A role's effective server→client requests (`shared` ∪ `roles[R]`), answered by `client.implement`. */
|
|
253
|
+
type ServerRequests<C extends Contract, R extends RoleOf<C>> = ServerReqOf<ServerMessages<C, R>>;
|
|
254
|
+
/** Server→client requests in the `shared` block (the surface `srv.toConn(id).request` can call). */
|
|
255
|
+
type SharedServerRequests<C extends Contract> = ServerReqOf<StcOf<C['shared']>>;
|
|
256
|
+
/** The typed shape of `conn.data` for role `R` (its `data` schema, or an empty object). */
|
|
257
|
+
type DataOf<C extends Contract, R extends RoleOf<C>> = C['roles'][R] extends {
|
|
258
|
+
data: infer S extends Schema;
|
|
259
|
+
} ? InferOut<S> : Record<string, never>;
|
|
260
|
+
/** Union of every role's `conn.data` shape (used where the role isn't narrowed, e.g. shared handlers). */
|
|
261
|
+
type AnyData<C extends Contract> = DataOf<C, RoleOf<C>>;
|
|
162
262
|
/** The `serverToServer` map, or `{}` if the contract has none. */
|
|
163
263
|
type ServerEvents<C extends Contract> = C['serverToServer'] extends Record<string, Schema> ? C['serverToServer'] : {};
|
|
164
264
|
/** The input type a client passes for a request (pre-validation). */
|
|
@@ -219,7 +319,19 @@ interface UnsubFrame {
|
|
|
219
319
|
t: 'unsub';
|
|
220
320
|
c: string;
|
|
221
321
|
}
|
|
222
|
-
|
|
322
|
+
interface SResFrame {
|
|
323
|
+
t: 'sres';
|
|
324
|
+
i: number;
|
|
325
|
+
d: unknown;
|
|
326
|
+
}
|
|
327
|
+
interface SErrFrame {
|
|
328
|
+
t: 'serr';
|
|
329
|
+
i: number;
|
|
330
|
+
code: string;
|
|
331
|
+
m: string;
|
|
332
|
+
d?: unknown;
|
|
333
|
+
}
|
|
334
|
+
type ClientFrame = ReqFrame | SubFrame | UnsubFrame | SResFrame | SErrFrame;
|
|
223
335
|
interface ResFrame {
|
|
224
336
|
t: 'res';
|
|
225
337
|
i: number;
|
|
@@ -242,7 +354,13 @@ interface PubFrame {
|
|
|
242
354
|
c: string;
|
|
243
355
|
d: unknown;
|
|
244
356
|
}
|
|
245
|
-
|
|
357
|
+
interface SReqFrame {
|
|
358
|
+
t: 'sreq';
|
|
359
|
+
i: number;
|
|
360
|
+
m: string;
|
|
361
|
+
d: unknown;
|
|
362
|
+
}
|
|
363
|
+
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame;
|
|
246
364
|
type Frame = ClientFrame | ServerFrame;
|
|
247
365
|
|
|
248
|
-
export { type Adapter, type ClientFrame, type ClientInput, type Contract, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type InferIn, type InferOut, type Output, PROTOCOL, type PubFrame, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleOf, type RoleRequests, type RoleTopics, type Schema, type Serializer, type ServerData, type ServerEmit, type ServerEvents, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type SharedEvents, type SharedRequests, type SharedTopics, SocketError, type SocketErrorCode, type SubFrame, type Topics, type UnsubFrame, defineContract, jsonSerializer, validate, validateSync };
|
|
366
|
+
export { type Adapter, type AnyData, type ClientFrame, type ClientInput, type ConnDescriptor, type Contract, type DataOf, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type InferIn, type InferOut, type NodeStat, type Output, PROTOCOL, type PresenceStore, type PubFrame, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleBlock, type RoleOf, type RoleRequests, type RoleTopics, type SErrFrame, type SReqFrame, type SResFrame, type Schema, type Serializer, type ServerData, type ServerEmit, type ServerEntry, type ServerEvents, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type ServerRequestDef, type ServerRequests, type SharedEvents, type SharedRequests, type SharedServerRequests, type SharedTopics, SocketError, type SocketErrorCode, type SubFrame, type Topics, type UnsubFrame, defineContract, jsonSerializer, validate, validateSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,71 @@ interface Adapter {
|
|
|
55
55
|
onMessage(handler: (channel: string, payload: string | Uint8Array) => void): void;
|
|
56
56
|
/** Optional teardown (e.g. close Redis connections). */
|
|
57
57
|
close?(): void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Optional cluster-wide presence directory. Powers `srv.cluster.*` and
|
|
60
|
+
* `srv.isOnline`. The in-memory and Redis adapters implement it; cluster
|
|
61
|
+
* queries throw a clear error on an adapter that doesn't.
|
|
62
|
+
*/
|
|
63
|
+
presence?: PresenceStore;
|
|
64
|
+
}
|
|
65
|
+
/** A serializable snapshot of a connection, shared cluster-wide via the {@link PresenceStore}. */
|
|
66
|
+
interface ConnDescriptor {
|
|
67
|
+
/** The connection's server-assigned id. */
|
|
68
|
+
id: string;
|
|
69
|
+
/** The connection's role. */
|
|
70
|
+
role: string;
|
|
71
|
+
/** The node that holds this connection. */
|
|
72
|
+
nodeId: string;
|
|
73
|
+
/** When the connection was accepted (`Date.now()`). */
|
|
74
|
+
connectedAt: number;
|
|
75
|
+
/** The stable user key from the server's `identify` hook, if any. */
|
|
76
|
+
userId?: string;
|
|
77
|
+
/** Room memberships (topics and node-local `lastPongAt` are not included). */
|
|
78
|
+
rooms: string[];
|
|
79
|
+
/** Extra fields contributed by the server's `describeConn` hook. */
|
|
80
|
+
[extra: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
/** Per-node aggregate, returned by {@link PresenceStore.topology}. */
|
|
83
|
+
interface NodeStat {
|
|
84
|
+
/** The node's id. */
|
|
85
|
+
nodeId: string;
|
|
86
|
+
/** Number of connections on the node. */
|
|
87
|
+
connections: number;
|
|
88
|
+
/** Number of distinct rooms with members on the node. */
|
|
89
|
+
rooms: number;
|
|
90
|
+
/** Whether the node is currently live (heartbeat fresh). */
|
|
91
|
+
alive: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Cluster-wide presence directory: a query/addressbook layer kept in the shared
|
|
95
|
+
* substrate (in-memory bus or Redis). Live message delivery does NOT read this —
|
|
96
|
+
* it exists only to answer `srv.cluster.*` / `srv.isOnline`.
|
|
97
|
+
*/
|
|
98
|
+
interface PresenceStore {
|
|
99
|
+
/** Record (or replace) a connection's descriptor. */
|
|
100
|
+
set(descriptor: ConnDescriptor): void | Promise<void>;
|
|
101
|
+
/** Remove a connection's descriptor. */
|
|
102
|
+
del(connId: string): void | Promise<void>;
|
|
103
|
+
/** Refresh this node's liveness (heartbeat). */
|
|
104
|
+
beat(nodeId: string): void | Promise<void>;
|
|
105
|
+
/** Remove all of a node's connections + liveness (graceful shutdown cleanup). */
|
|
106
|
+
clearNode(nodeId: string): void | Promise<void>;
|
|
107
|
+
/** Add a room to a connection's membership. */
|
|
108
|
+
addRoom(connId: string, room: string): void | Promise<void>;
|
|
109
|
+
/** Remove a room from a connection's membership. */
|
|
110
|
+
removeRoom(connId: string, room: string): void | Promise<void>;
|
|
111
|
+
/** All live connection descriptors across the cluster. */
|
|
112
|
+
list(): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
113
|
+
/** One connection's descriptor, if present. */
|
|
114
|
+
get(connId: string): (ConnDescriptor | undefined) | Promise<ConnDescriptor | undefined>;
|
|
115
|
+
/** Descriptors for a given user key. */
|
|
116
|
+
byUser(userId: string): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
117
|
+
/** Descriptors that are members of `room`. */
|
|
118
|
+
roomMembers(room: string): ConnDescriptor[] | Promise<ConnDescriptor[]>;
|
|
119
|
+
/** Total live connection count across the cluster. */
|
|
120
|
+
count(): number | Promise<number>;
|
|
121
|
+
/** Per-node aggregates. */
|
|
122
|
+
topology(): NodeStat[] | Promise<NodeStat[]>;
|
|
58
123
|
}
|
|
59
124
|
|
|
60
125
|
/** Any [Standard Schema](https://standardschema.dev) validator (Zod, Valibot, ArkType…). */
|
|
@@ -80,12 +145,30 @@ interface ServerMessageDef {
|
|
|
80
145
|
/** When `true`, clients opt in via `client.subscribe(...)` (a topic). Omit for a push event. */
|
|
81
146
|
subscribe?: boolean;
|
|
82
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A server→client request (request/response). The server sends `input`; the
|
|
150
|
+
* client's `implement` handler returns `output`. Lives in `serverToClient`
|
|
151
|
+
* alongside events and topics, distinguished by having `input`.
|
|
152
|
+
*/
|
|
153
|
+
interface ServerRequestDef {
|
|
154
|
+
/** Schema for the request payload the server sends. */
|
|
155
|
+
input: Schema;
|
|
156
|
+
/** Schema for the reply the client returns. */
|
|
157
|
+
output: Schema;
|
|
158
|
+
}
|
|
159
|
+
/** A `serverToClient` entry: a push event, a subscribable topic, or a server→client request. */
|
|
160
|
+
type ServerEntry = ServerMessageDef | ServerRequestDef;
|
|
83
161
|
/** The two directions within a `shared` or role block. */
|
|
84
162
|
interface Directional {
|
|
85
163
|
/** Requests this side may call (client→server). */
|
|
86
164
|
clientToServer?: Record<string, RequestDef>;
|
|
87
|
-
/** Events
|
|
88
|
-
serverToClient?: Record<string,
|
|
165
|
+
/** Events, topics, and server→client requests this side may receive. */
|
|
166
|
+
serverToClient?: Record<string, ServerEntry>;
|
|
167
|
+
}
|
|
168
|
+
/** A role block: its directions plus an optional `data` schema typing `conn.data`. */
|
|
169
|
+
interface RoleBlock extends Directional {
|
|
170
|
+
/** Schema for this role's mutable per-connection `conn.data` (server-side scratch state). */
|
|
171
|
+
data?: Schema;
|
|
89
172
|
}
|
|
90
173
|
/**
|
|
91
174
|
* The single source of truth, imported by both server and client. Split by
|
|
@@ -96,7 +179,7 @@ interface Contract {
|
|
|
96
179
|
/** Surface common to every role (merged into each role's effective surface). */
|
|
97
180
|
shared?: Directional;
|
|
98
181
|
/** Per-role surfaces. A connection's role selects which one (plus `shared`) it sees. */
|
|
99
|
-
roles: Record<string,
|
|
182
|
+
roles: Record<string, RoleBlock>;
|
|
100
183
|
/** Typed node-to-node event payloads, for {@link "@super-line/server"!}'s `emitServer`/`onServer`. */
|
|
101
184
|
serverToServer?: Record<string, Schema>;
|
|
102
185
|
}
|
|
@@ -129,10 +212,12 @@ type CtsOf<D> = D extends {
|
|
|
129
212
|
clientToServer: infer M extends Record<string, RequestDef>;
|
|
130
213
|
} ? M : {};
|
|
131
214
|
type StcOf<D> = D extends {
|
|
132
|
-
serverToClient: infer M extends Record<string,
|
|
215
|
+
serverToClient: infer M extends Record<string, ServerEntry>;
|
|
133
216
|
} ? M : {};
|
|
134
217
|
type EventsOf<M> = {
|
|
135
218
|
[K in keyof M as M[K] extends {
|
|
219
|
+
input: Schema;
|
|
220
|
+
} ? never : M[K] extends {
|
|
136
221
|
subscribe: true;
|
|
137
222
|
} ? never : K]: M[K];
|
|
138
223
|
};
|
|
@@ -141,6 +226,11 @@ type TopicsOf<M> = {
|
|
|
141
226
|
subscribe: true;
|
|
142
227
|
} ? K : never]: M[K];
|
|
143
228
|
};
|
|
229
|
+
type ServerReqOf<M> = {
|
|
230
|
+
[K in keyof M as M[K] extends {
|
|
231
|
+
input: Schema;
|
|
232
|
+
} ? K : never]: M[K];
|
|
233
|
+
};
|
|
144
234
|
/** A role's effective request map: `shared` ∪ `roles[R]` client→server requests. */
|
|
145
235
|
type Requests<C extends Contract, R extends RoleOf<C>> = CtsOf<C['shared']> & CtsOf<C['roles'][R]>;
|
|
146
236
|
/** A role's effective server→client map (events and topics combined). */
|
|
@@ -159,6 +249,16 @@ type SharedEvents<C extends Contract> = EventsOf<StcOf<C['shared']>>;
|
|
|
159
249
|
type SharedTopics<C extends Contract> = TopicsOf<StcOf<C['shared']>>;
|
|
160
250
|
/** Subscribable topics in one role's block (published via `srv.forRole(r).publish`). */
|
|
161
251
|
type RoleTopics<C extends Contract, R extends RoleOf<C>> = TopicsOf<StcOf<C['roles'][R]>>;
|
|
252
|
+
/** A role's effective server→client requests (`shared` ∪ `roles[R]`), answered by `client.implement`. */
|
|
253
|
+
type ServerRequests<C extends Contract, R extends RoleOf<C>> = ServerReqOf<ServerMessages<C, R>>;
|
|
254
|
+
/** Server→client requests in the `shared` block (the surface `srv.toConn(id).request` can call). */
|
|
255
|
+
type SharedServerRequests<C extends Contract> = ServerReqOf<StcOf<C['shared']>>;
|
|
256
|
+
/** The typed shape of `conn.data` for role `R` (its `data` schema, or an empty object). */
|
|
257
|
+
type DataOf<C extends Contract, R extends RoleOf<C>> = C['roles'][R] extends {
|
|
258
|
+
data: infer S extends Schema;
|
|
259
|
+
} ? InferOut<S> : Record<string, never>;
|
|
260
|
+
/** Union of every role's `conn.data` shape (used where the role isn't narrowed, e.g. shared handlers). */
|
|
261
|
+
type AnyData<C extends Contract> = DataOf<C, RoleOf<C>>;
|
|
162
262
|
/** The `serverToServer` map, or `{}` if the contract has none. */
|
|
163
263
|
type ServerEvents<C extends Contract> = C['serverToServer'] extends Record<string, Schema> ? C['serverToServer'] : {};
|
|
164
264
|
/** The input type a client passes for a request (pre-validation). */
|
|
@@ -219,7 +319,19 @@ interface UnsubFrame {
|
|
|
219
319
|
t: 'unsub';
|
|
220
320
|
c: string;
|
|
221
321
|
}
|
|
222
|
-
|
|
322
|
+
interface SResFrame {
|
|
323
|
+
t: 'sres';
|
|
324
|
+
i: number;
|
|
325
|
+
d: unknown;
|
|
326
|
+
}
|
|
327
|
+
interface SErrFrame {
|
|
328
|
+
t: 'serr';
|
|
329
|
+
i: number;
|
|
330
|
+
code: string;
|
|
331
|
+
m: string;
|
|
332
|
+
d?: unknown;
|
|
333
|
+
}
|
|
334
|
+
type ClientFrame = ReqFrame | SubFrame | UnsubFrame | SResFrame | SErrFrame;
|
|
223
335
|
interface ResFrame {
|
|
224
336
|
t: 'res';
|
|
225
337
|
i: number;
|
|
@@ -242,7 +354,13 @@ interface PubFrame {
|
|
|
242
354
|
c: string;
|
|
243
355
|
d: unknown;
|
|
244
356
|
}
|
|
245
|
-
|
|
357
|
+
interface SReqFrame {
|
|
358
|
+
t: 'sreq';
|
|
359
|
+
i: number;
|
|
360
|
+
m: string;
|
|
361
|
+
d: unknown;
|
|
362
|
+
}
|
|
363
|
+
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame;
|
|
246
364
|
type Frame = ClientFrame | ServerFrame;
|
|
247
365
|
|
|
248
|
-
export { type Adapter, type ClientFrame, type ClientInput, type Contract, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type InferIn, type InferOut, type Output, PROTOCOL, type PubFrame, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleOf, type RoleRequests, type RoleTopics, type Schema, type Serializer, type ServerData, type ServerEmit, type ServerEvents, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type SharedEvents, type SharedRequests, type SharedTopics, SocketError, type SocketErrorCode, type SubFrame, type Topics, type UnsubFrame, defineContract, jsonSerializer, validate, validateSync };
|
|
366
|
+
export { type Adapter, type AnyData, type ClientFrame, type ClientInput, type ConnDescriptor, type Contract, type DataOf, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type InferIn, type InferOut, type NodeStat, type Output, PROTOCOL, type PresenceStore, type PubFrame, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleBlock, type RoleOf, type RoleRequests, type RoleTopics, type SErrFrame, type SReqFrame, type SResFrame, type Schema, type Serializer, type ServerData, type ServerEmit, type ServerEntry, type ServerEvents, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type ServerRequestDef, type ServerRequests, type SharedEvents, type SharedRequests, type SharedServerRequests, type SharedTopics, SocketError, type SocketErrorCode, type SubFrame, type Topics, type UnsubFrame, defineContract, jsonSerializer, validate, validateSync };
|