atom.io 0.46.12 → 0.46.14
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/eslint-plugin/index.js +1 -1
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/react-devtools/index.js +24 -5
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +17 -19
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +11 -14
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +3 -2
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +10 -10
- package/src/eslint-plugin/rules/exact-catch-types.ts +1 -1
- package/src/react-devtools/StateIndex.tsx +8 -1
- package/src/react-devtools/json-editor/editors-by-type/non-json.tsx +17 -10
- package/src/react-devtools/json-editor/json-editor-internal.tsx +8 -1
- package/src/realtime/employ-socket.ts +11 -14
- package/src/realtime/{cast-socket.ts → guard-socket.ts} +11 -11
- package/src/realtime/index.ts +1 -1
- package/src/realtime/shared-room-store.ts +1 -1
- package/src/realtime/socket-interface.ts +23 -10
- package/src/realtime-server/provide-rooms.ts +7 -6
- package/src/realtime-server/server-config.ts +7 -0
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Json } from "atom.io/json"
|
|
2
|
+
import type { EventsMap, GuardedSocket, Socket } from "atom.io/realtime"
|
|
3
3
|
|
|
4
4
|
export function employSocket<I extends EventsMap, K extends string & keyof I>(
|
|
5
|
-
socket:
|
|
5
|
+
socket: GuardedSocket<I>,
|
|
6
6
|
event: K,
|
|
7
7
|
handleEvent: (...data: Parameters<I[K]>) => void,
|
|
8
8
|
): () => void
|
|
9
|
-
export function employSocket
|
|
9
|
+
export function employSocket(
|
|
10
10
|
socket: Socket,
|
|
11
|
-
event:
|
|
12
|
-
handleEvent: (...data:
|
|
11
|
+
event: string,
|
|
12
|
+
handleEvent: (...data: Json.Serializable[]) => void,
|
|
13
13
|
): () => void
|
|
14
|
-
export function employSocket
|
|
15
|
-
socket:
|
|
16
|
-
event:
|
|
17
|
-
handleEvent: (...data:
|
|
14
|
+
export function employSocket(
|
|
15
|
+
socket: GuardedSocket<any> | Socket,
|
|
16
|
+
event: string,
|
|
17
|
+
handleEvent: (...data: Json.Serializable[]) => void,
|
|
18
18
|
): () => void {
|
|
19
19
|
socket.on(event, handleEvent)
|
|
20
|
-
|
|
21
|
-
socket.off(event, handleEvent)
|
|
22
|
-
}
|
|
23
|
-
return retireSocket
|
|
20
|
+
return socket.off.bind(socket, event, handleEvent)
|
|
24
21
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Loadable } from "atom.io"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { EventsMap,
|
|
4
|
+
import type { EventsMap, GuardedSocket, Socket } from "./socket-interface"
|
|
5
5
|
import type { StandardSchemaV1 } from "./standard-schema"
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export type SocketGuard<ListenEvents extends EventsMap> = {
|
|
8
|
+
[K in keyof ListenEvents]: StandardSchemaV1<
|
|
9
|
+
Json.Array,
|
|
10
|
+
Parameters<ListenEvents[K]>
|
|
11
|
+
>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type Loaded<L extends Loadable<any>> =
|
|
@@ -25,13 +25,13 @@ function onLoad<L extends Loadable<any>>(
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function
|
|
28
|
+
export function guardSocket<ListenEvents extends EventsMap>(
|
|
29
29
|
socket: Socket,
|
|
30
|
-
guard: SocketGuard<
|
|
30
|
+
guard: SocketGuard<ListenEvents> | `TRUST`,
|
|
31
31
|
logError?: (error: unknown) => void,
|
|
32
|
-
):
|
|
32
|
+
): GuardedSocket<ListenEvents> {
|
|
33
33
|
if (guard === `TRUST`) {
|
|
34
|
-
return socket as
|
|
34
|
+
return socket as GuardedSocket<ListenEvents>
|
|
35
35
|
}
|
|
36
36
|
const guardedSocket: Socket = {
|
|
37
37
|
id: socket.id,
|
|
@@ -66,5 +66,5 @@ export function castSocket<T extends TypedSocket>(
|
|
|
66
66
|
offAny: socket.offAny.bind(socket),
|
|
67
67
|
emit: socket.emit.bind(socket),
|
|
68
68
|
}
|
|
69
|
-
return guardedSocket as
|
|
69
|
+
return guardedSocket as GuardedSocket<ListenEvents>
|
|
70
70
|
}
|
package/src/realtime/index.ts
CHANGED
|
@@ -26,17 +26,30 @@ export type EventEmitter<EmitEvents extends EventsMap = EventsMap> = <
|
|
|
26
26
|
...args: Parameters<EmitEvents[E]>
|
|
27
27
|
) => void
|
|
28
28
|
|
|
29
|
-
export
|
|
30
|
-
ListenEvents extends EventsMap = EventsMap,
|
|
31
|
-
EmitEvents extends EventsMap = never,
|
|
32
|
-
> = {
|
|
29
|
+
export interface GuardedSocket<ListenEvents extends EventsMap> extends Socket {
|
|
33
30
|
id: string | undefined
|
|
34
|
-
on:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
on: <E extends string & keyof ListenEvents>(
|
|
32
|
+
event: E,
|
|
33
|
+
listener: ListenEvents[E],
|
|
34
|
+
) => void
|
|
35
|
+
onAny: (
|
|
36
|
+
listener: <E extends string & keyof ListenEvents>(
|
|
37
|
+
event: E,
|
|
38
|
+
...args: Parameters<ListenEvents[E]>
|
|
39
|
+
) => void,
|
|
40
|
+
) => void
|
|
41
|
+
onAnyOutgoing: (listener: AllEventsListener<EventsMap>) => void
|
|
42
|
+
off: <E extends string & keyof ListenEvents>(
|
|
43
|
+
event: E,
|
|
44
|
+
listener?: ListenEvents[E],
|
|
45
|
+
) => void
|
|
46
|
+
offAny: (
|
|
47
|
+
listener?: <E extends string & keyof ListenEvents>(
|
|
48
|
+
event: E,
|
|
49
|
+
...args: Parameters<ListenEvents[E]>
|
|
50
|
+
) => void,
|
|
51
|
+
) => void
|
|
52
|
+
emit: EventEmitter<EventsMap>
|
|
40
53
|
}
|
|
41
54
|
|
|
42
55
|
export type Socket = {
|
|
@@ -15,16 +15,16 @@ import type { Json } from "atom.io/json"
|
|
|
15
15
|
import type {
|
|
16
16
|
AllEventsListener,
|
|
17
17
|
EventsMap,
|
|
18
|
+
GuardedSocket,
|
|
18
19
|
RoomKey,
|
|
19
20
|
RoomSocketInterface,
|
|
20
21
|
Socket,
|
|
21
22
|
SocketGuard,
|
|
22
23
|
StandardSchemaV1,
|
|
23
|
-
TypedSocket,
|
|
24
24
|
UserKey,
|
|
25
25
|
} from "atom.io/realtime"
|
|
26
26
|
import {
|
|
27
|
-
|
|
27
|
+
guardSocket,
|
|
28
28
|
isRoomKey,
|
|
29
29
|
ownersOfRooms,
|
|
30
30
|
roomKeysAtom,
|
|
@@ -129,7 +129,7 @@ export function spawnRoom<RoomNames extends string>({
|
|
|
129
129
|
export type ProvideEnterAndExitConfig = {
|
|
130
130
|
store: RootStore
|
|
131
131
|
socket: Socket
|
|
132
|
-
roomSocket:
|
|
132
|
+
roomSocket: GuardedSocket<RoomSocketInterface<string>>
|
|
133
133
|
userKey: UserKey
|
|
134
134
|
}
|
|
135
135
|
export function provideEnterAndExit({
|
|
@@ -283,9 +283,10 @@ export function provideRooms<RoomNames extends string>({
|
|
|
283
283
|
roomNames,
|
|
284
284
|
userKey,
|
|
285
285
|
}: ProvideRoomsConfig<RoomNames>): () => void {
|
|
286
|
-
const roomSocket =
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
const roomSocket = guardSocket<RoomSocketInterface<RoomNames>>(
|
|
287
|
+
socket,
|
|
288
|
+
createRoomSocketGuard(roomNames),
|
|
289
|
+
)
|
|
289
290
|
const exposeMutable = realtimeMutableProvider({
|
|
290
291
|
socket,
|
|
291
292
|
store,
|
|
@@ -72,6 +72,13 @@ export function realtime(
|
|
|
72
72
|
.use(async (socket, next) => {
|
|
73
73
|
const result = await auth(socket.handshake)
|
|
74
74
|
if (result instanceof Error) {
|
|
75
|
+
store.logger.error(
|
|
76
|
+
`📡`,
|
|
77
|
+
`socket`,
|
|
78
|
+
socket.id,
|
|
79
|
+
`failed to authenticate`,
|
|
80
|
+
result.message,
|
|
81
|
+
)
|
|
75
82
|
next(result)
|
|
76
83
|
return
|
|
77
84
|
}
|