atom.io 0.46.5 → 0.46.6
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/realtime/index.d.ts +7 -6
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +19 -10
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +13 -13
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +10 -3
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +49 -41
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +123 -92
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.js +2 -2
- package/dist/realtime-testing/index.js.map +1 -1
- package/package.json +17 -16
- package/src/realtime/realtime-continuity.ts +2 -2
- package/src/realtime/shared-room-store.ts +38 -17
- package/src/realtime/socket-interface.ts +1 -1
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +3 -1
- package/src/realtime-client/continuity/use-conceal-state.ts +2 -1
- package/src/realtime-client/pull-atom-family-member.ts +1 -1
- package/src/realtime-client/pull-atom.ts +1 -1
- package/src/realtime-client/pull-mutable-atom-family-member.ts +1 -1
- package/src/realtime-client/pull-mutable-atom.ts +1 -1
- package/src/realtime-client/pull-selector-family-member.ts +1 -1
- package/src/realtime-client/pull-selector-roots.ts +1 -1
- package/src/realtime-client/pull-selector.ts +1 -1
- package/src/realtime-client/push-state.ts +1 -1
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +16 -3
- package/src/realtime-client/sync-continuity.ts +1 -2
- package/src/realtime-server/continuity/provide-outcomes.ts +1 -1
- package/src/realtime-server/ipc-sockets/parent-socket.ts +1 -8
- package/src/realtime-server/provide-rooms.ts +64 -16
- package/src/realtime-server/realtime-family-provider.ts +51 -35
- package/src/realtime-server/realtime-mutable-family-provider.ts +50 -34
- package/src/realtime-server/realtime-mutable-provider.ts +4 -4
- package/src/realtime-server/realtime-state-provider.ts +7 -7
- package/src/realtime-server/realtime-state-receiver.ts +2 -2
- package/src/realtime-server/server-config.ts +20 -13
- package/src/realtime-server/server-socket-state.ts +3 -3
- package/src/realtime-testing/setup-realtime-test.tsx +2 -2
|
@@ -31,7 +31,7 @@ export type MutableFamilyProvider = ReturnType<
|
|
|
31
31
|
>
|
|
32
32
|
export function realtimeMutableFamilyProvider({
|
|
33
33
|
socket,
|
|
34
|
-
|
|
34
|
+
consumer,
|
|
35
35
|
store = IMPLICIT.STORE,
|
|
36
36
|
}: ServerConfig) {
|
|
37
37
|
return function mutableFamilyProvider<
|
|
@@ -39,8 +39,17 @@ export function realtimeMutableFamilyProvider({
|
|
|
39
39
|
K extends Canonical,
|
|
40
40
|
>(
|
|
41
41
|
family: AtomIO.MutableAtomFamilyToken<T, K>,
|
|
42
|
-
index: AtomIO.ReadableToken<Iterable<NoInfer<K
|
|
42
|
+
index: AtomIO.ReadableToken<Iterable<NoInfer<K>>> | Iterable<NoInfer<K>>,
|
|
43
43
|
): () => void {
|
|
44
|
+
const [dynamicIndex, staticIndex]:
|
|
45
|
+
| [AtomIO.ReadableToken<Iterable<NoInfer<K>>>, undefined]
|
|
46
|
+
| [undefined, Iterable<NoInfer<K>>] = (() => {
|
|
47
|
+
if (typeof index === `object` && `key` in index && `type` in index) {
|
|
48
|
+
return [index, undefined] as const
|
|
49
|
+
}
|
|
50
|
+
return [undefined, index] as const
|
|
51
|
+
})()
|
|
52
|
+
|
|
44
53
|
const coreSubscriptions = new Set<() => void>()
|
|
45
54
|
const clearCoreSubscriptions = () => {
|
|
46
55
|
for (const unsub of coreSubscriptions) unsub()
|
|
@@ -95,18 +104,23 @@ export function realtimeMutableFamilyProvider({
|
|
|
95
104
|
store.logger.info(
|
|
96
105
|
`👀`,
|
|
97
106
|
`user`,
|
|
98
|
-
|
|
107
|
+
consumer,
|
|
99
108
|
`can subscribe to family "${family.key}"`,
|
|
100
109
|
)
|
|
101
110
|
coreSubscriptions.add(
|
|
102
111
|
employSocket(socket, `sub:${family.key}`, (subKey: K) => {
|
|
103
|
-
|
|
112
|
+
let exposedSubKeys: Iterable<K>
|
|
113
|
+
if (dynamicIndex) {
|
|
114
|
+
exposedSubKeys = getFromStore(store, dynamicIndex)
|
|
115
|
+
} else {
|
|
116
|
+
exposedSubKeys = staticIndex
|
|
117
|
+
}
|
|
104
118
|
const shouldExpose = isAvailable(exposedSubKeys, subKey)
|
|
105
119
|
if (shouldExpose) {
|
|
106
120
|
store.logger.info(
|
|
107
121
|
`👀`,
|
|
108
122
|
`user`,
|
|
109
|
-
|
|
123
|
+
consumer,
|
|
110
124
|
`is approved for a subscription to`,
|
|
111
125
|
subKey,
|
|
112
126
|
`in family "${family.key}"`,
|
|
@@ -116,7 +130,7 @@ export function realtimeMutableFamilyProvider({
|
|
|
116
130
|
store.logger.info(
|
|
117
131
|
`❌`,
|
|
118
132
|
`user`,
|
|
119
|
-
|
|
133
|
+
consumer,
|
|
120
134
|
`is denied for a subscription to`,
|
|
121
135
|
subKey,
|
|
122
136
|
`in family "${family.key}"`,
|
|
@@ -126,35 +140,37 @@ export function realtimeMutableFamilyProvider({
|
|
|
126
140
|
}
|
|
127
141
|
}),
|
|
128
142
|
)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
143
|
+
if (dynamicIndex) {
|
|
144
|
+
coreSubscriptions.add(
|
|
145
|
+
subscribeToState(
|
|
146
|
+
store,
|
|
147
|
+
dynamicIndex,
|
|
148
|
+
`expose-family:${family.key}:${socket.id}`,
|
|
149
|
+
({ newValue: newExposedSubKeys }) => {
|
|
150
|
+
store.logger.info(
|
|
151
|
+
`👀`,
|
|
152
|
+
`user`,
|
|
153
|
+
consumer,
|
|
154
|
+
`has the following keys available for family "${family.key}"`,
|
|
155
|
+
newExposedSubKeys,
|
|
156
|
+
)
|
|
157
|
+
for (const subKey of newExposedSubKeys) {
|
|
158
|
+
if (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {
|
|
159
|
+
store.logger.info(
|
|
160
|
+
`👀`,
|
|
161
|
+
`user`,
|
|
162
|
+
consumer,
|
|
163
|
+
`is retroactively approved for a subscription to`,
|
|
164
|
+
subKey,
|
|
165
|
+
`in family "${family.key}"`,
|
|
166
|
+
)
|
|
167
|
+
exposeFamilyMembers(subKey)
|
|
168
|
+
}
|
|
153
169
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
)
|
|
157
|
-
|
|
170
|
+
},
|
|
171
|
+
),
|
|
172
|
+
)
|
|
173
|
+
}
|
|
158
174
|
}
|
|
159
175
|
|
|
160
176
|
start()
|
|
@@ -15,7 +15,7 @@ import type { ServerConfig } from "."
|
|
|
15
15
|
export type MutableProvider = ReturnType<typeof realtimeMutableProvider>
|
|
16
16
|
export function realtimeMutableProvider({
|
|
17
17
|
socket,
|
|
18
|
-
|
|
18
|
+
consumer,
|
|
19
19
|
store = IMPLICIT.STORE,
|
|
20
20
|
}: ServerConfig) {
|
|
21
21
|
return function mutableProvider<
|
|
@@ -34,7 +34,7 @@ export function realtimeMutableProvider({
|
|
|
34
34
|
store.logger.info(
|
|
35
35
|
`👀`,
|
|
36
36
|
`user`,
|
|
37
|
-
|
|
37
|
+
consumer,
|
|
38
38
|
`can subscribe to state "${token.key}"`,
|
|
39
39
|
)
|
|
40
40
|
subscriptions.add(
|
|
@@ -42,7 +42,7 @@ export function realtimeMutableProvider({
|
|
|
42
42
|
store.logger.info(
|
|
43
43
|
`👀`,
|
|
44
44
|
`user`,
|
|
45
|
-
|
|
45
|
+
consumer,
|
|
46
46
|
`subscribes to state "${token.key}"`,
|
|
47
47
|
)
|
|
48
48
|
clearSubscriptions()
|
|
@@ -62,7 +62,7 @@ export function realtimeMutableProvider({
|
|
|
62
62
|
store.logger.info(
|
|
63
63
|
`🙈`,
|
|
64
64
|
`user`,
|
|
65
|
-
|
|
65
|
+
consumer,
|
|
66
66
|
`unsubscribes from state "${token.key}"`,
|
|
67
67
|
)
|
|
68
68
|
clearSubscriptions()
|
|
@@ -17,10 +17,10 @@ function isReadableToken(input: unknown): input is AtomIO.ReadableToken<any> {
|
|
|
17
17
|
export type StateProvider = ReturnType<typeof realtimeStateProvider>
|
|
18
18
|
export function realtimeStateProvider({
|
|
19
19
|
socket,
|
|
20
|
-
|
|
20
|
+
consumer,
|
|
21
21
|
store = IMPLICIT.STORE,
|
|
22
22
|
}: ServerConfig) {
|
|
23
|
-
store.logger.info(`🔌`, `user`,
|
|
23
|
+
store.logger.info(`🔌`, `user`, consumer, `initialized state provider`)
|
|
24
24
|
return function stateProvider<C extends Json.Serializable, S extends C>(
|
|
25
25
|
clientToken: AtomIO.WritableToken<C>,
|
|
26
26
|
serverData:
|
|
@@ -40,7 +40,7 @@ export function realtimeStateProvider({
|
|
|
40
40
|
store.logger.info(
|
|
41
41
|
`👀`,
|
|
42
42
|
`user`,
|
|
43
|
-
|
|
43
|
+
consumer,
|
|
44
44
|
`will be served`,
|
|
45
45
|
serverData,
|
|
46
46
|
`as "${clientToken.key}"`,
|
|
@@ -49,7 +49,7 @@ export function realtimeStateProvider({
|
|
|
49
49
|
store.logger.info(
|
|
50
50
|
`👀`,
|
|
51
51
|
`user`,
|
|
52
|
-
|
|
52
|
+
consumer,
|
|
53
53
|
`can subscribe to state "${serverData.key}" as "${clientToken.key}"`,
|
|
54
54
|
)
|
|
55
55
|
}
|
|
@@ -59,7 +59,7 @@ export function realtimeStateProvider({
|
|
|
59
59
|
store.logger.info(
|
|
60
60
|
`👀`,
|
|
61
61
|
`user`,
|
|
62
|
-
|
|
62
|
+
consumer,
|
|
63
63
|
`requests`,
|
|
64
64
|
`"${clientToken.key}"`,
|
|
65
65
|
)
|
|
@@ -68,7 +68,7 @@ export function realtimeStateProvider({
|
|
|
68
68
|
store.logger.info(
|
|
69
69
|
`👀`,
|
|
70
70
|
`user`,
|
|
71
|
-
|
|
71
|
+
consumer,
|
|
72
72
|
`subscribes to state "${serverData.key}"`,
|
|
73
73
|
clientToken === serverData
|
|
74
74
|
? `directly`
|
|
@@ -94,7 +94,7 @@ export function realtimeStateProvider({
|
|
|
94
94
|
store.logger.info(
|
|
95
95
|
`🙈`,
|
|
96
96
|
`user`,
|
|
97
|
-
|
|
97
|
+
consumer,
|
|
98
98
|
`unsubscribes from state "${serverData.key}", served`,
|
|
99
99
|
clientToken === serverData
|
|
100
100
|
? `directly`
|
|
@@ -17,7 +17,7 @@ import type { ServerConfig } from "."
|
|
|
17
17
|
export type StateReceiver = ReturnType<typeof realtimeStateReceiver>
|
|
18
18
|
export function realtimeStateReceiver({
|
|
19
19
|
socket,
|
|
20
|
-
|
|
20
|
+
consumer,
|
|
21
21
|
store = IMPLICIT.STORE,
|
|
22
22
|
}: ServerConfig) {
|
|
23
23
|
return function stateReceiver<S extends Json.Serializable, C extends S>(
|
|
@@ -43,7 +43,7 @@ export function realtimeStateReceiver({
|
|
|
43
43
|
store.logger.error(
|
|
44
44
|
`❌`,
|
|
45
45
|
`user`,
|
|
46
|
-
|
|
46
|
+
consumer,
|
|
47
47
|
`attempted to publish invalid value`,
|
|
48
48
|
newValue,
|
|
49
49
|
`to state "${serverToken.key}"`,
|
|
@@ -12,21 +12,27 @@ import {
|
|
|
12
12
|
IMPLICIT,
|
|
13
13
|
setIntoStore,
|
|
14
14
|
} from "atom.io/internal"
|
|
15
|
-
import type { Socket, SocketKey, UserKey } from "atom.io/realtime"
|
|
15
|
+
import type { RoomKey, Socket, SocketKey, UserKey } from "atom.io/realtime"
|
|
16
|
+
import { myUserKeyAtom } from "atom.io/realtime-client"
|
|
16
17
|
import type { Server } from "socket.io"
|
|
17
18
|
|
|
18
19
|
import { realtimeStateProvider } from "./realtime-state-provider"
|
|
19
20
|
import type { SocketSystemHierarchy } from "./server-socket-state"
|
|
20
21
|
import {
|
|
22
|
+
onlineUsersAtom,
|
|
21
23
|
socketAtoms,
|
|
22
24
|
socketKeysAtom,
|
|
23
|
-
userKeysAtom,
|
|
24
25
|
usersOfSockets,
|
|
25
26
|
} from "./server-socket-state"
|
|
26
27
|
|
|
27
28
|
export type ServerConfig = {
|
|
28
29
|
socket: Socket
|
|
29
|
-
|
|
30
|
+
consumer: RoomKey | UserKey
|
|
31
|
+
store?: RootStore
|
|
32
|
+
}
|
|
33
|
+
export type UserServerConfig = {
|
|
34
|
+
socket: Socket
|
|
35
|
+
consumer: UserKey
|
|
30
36
|
store?: RootStore
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -57,7 +63,7 @@ export type Handshake = {
|
|
|
57
63
|
export function realtime(
|
|
58
64
|
server: Server,
|
|
59
65
|
auth: (handshake: Handshake) => Loadable<Error | UserKey>,
|
|
60
|
-
onConnect: (config:
|
|
66
|
+
onConnect: (config: UserServerConfig) => Loadable<() => Loadable<void>>,
|
|
61
67
|
store: RootStore = IMPLICIT.STORE,
|
|
62
68
|
): () => Promise<void> {
|
|
63
69
|
const socketRealm = new Realm<SocketSystemHierarchy>(store)
|
|
@@ -76,24 +82,21 @@ export function realtime(
|
|
|
76
82
|
editRelationsInStore(store, usersOfSockets, (relations) => {
|
|
77
83
|
relations.set(userClaim, socketClaim)
|
|
78
84
|
})
|
|
79
|
-
setIntoStore(store,
|
|
85
|
+
setIntoStore(store, onlineUsersAtom, (index) => index.add(userClaim))
|
|
80
86
|
setIntoStore(store, socketKeysAtom, (index) => index.add(socketClaim))
|
|
81
87
|
next()
|
|
82
88
|
})
|
|
83
89
|
.on(`connection`, async (socket) => {
|
|
84
90
|
const socketKey = `socket::${socket.id}` satisfies SocketKey
|
|
85
|
-
const
|
|
91
|
+
const userKeySelector = findRelationsInStore(
|
|
86
92
|
store,
|
|
87
93
|
usersOfSockets,
|
|
88
94
|
socketKey,
|
|
89
95
|
).userKeyOfSocket
|
|
90
|
-
const userKey = getFromStore(store,
|
|
91
|
-
const serverConfig:
|
|
96
|
+
const userKey = getFromStore(store, userKeySelector)!
|
|
97
|
+
const serverConfig: UserServerConfig = { store, socket, consumer: userKey }
|
|
92
98
|
const provideState = realtimeStateProvider(serverConfig)
|
|
93
|
-
const unsubFromMyUserKey = provideState(
|
|
94
|
-
{ key: `myUserKey`, type: `atom` },
|
|
95
|
-
userKey,
|
|
96
|
-
)
|
|
99
|
+
const unsubFromMyUserKey = provideState(myUserKeyAtom, userKey)
|
|
97
100
|
|
|
98
101
|
const disposeServices = await onConnect(serverConfig)
|
|
99
102
|
|
|
@@ -104,7 +107,11 @@ export function realtime(
|
|
|
104
107
|
editRelationsInStore(store, usersOfSockets, (rel) =>
|
|
105
108
|
rel.delete(socketKey),
|
|
106
109
|
)
|
|
107
|
-
setIntoStore(
|
|
110
|
+
setIntoStore(
|
|
111
|
+
store,
|
|
112
|
+
onlineUsersAtom,
|
|
113
|
+
(keys) => (keys.delete(userKey), keys),
|
|
114
|
+
)
|
|
108
115
|
setIntoStore(
|
|
109
116
|
store,
|
|
110
117
|
socketKeysAtom,
|
|
@@ -25,11 +25,11 @@ export const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =
|
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
export const socketKeysAtom: MutableAtomToken<UList<SocketKey>> = mutableAtom({
|
|
28
|
-
key: `
|
|
28
|
+
key: `socketKeys`,
|
|
29
29
|
class: UList,
|
|
30
30
|
})
|
|
31
|
-
export const
|
|
32
|
-
key: `
|
|
31
|
+
export const onlineUsersAtom: MutableAtomToken<UList<UserKey>> = mutableAtom({
|
|
32
|
+
key: `onlineUsers`,
|
|
33
33
|
class: UList,
|
|
34
34
|
})
|
|
35
35
|
export const usersOfSockets: JoinToken<
|
|
@@ -133,7 +133,7 @@ export const setupRealtimeTestServer = (
|
|
|
133
133
|
return new Error(`Authentication error`)
|
|
134
134
|
},
|
|
135
135
|
(config) => {
|
|
136
|
-
const { socket, userKey } = config
|
|
136
|
+
const { socket, consumer: userKey } = config
|
|
137
137
|
function enableLogging() {
|
|
138
138
|
prefixLogger(silo.store, `server`)
|
|
139
139
|
socket.onAny((event, ...args) => {
|
|
@@ -148,7 +148,7 @@ export const setupRealtimeTestServer = (
|
|
|
148
148
|
}
|
|
149
149
|
const disposeServices = options.server({
|
|
150
150
|
socket: config.socket,
|
|
151
|
-
userKey: config.
|
|
151
|
+
userKey: config.consumer,
|
|
152
152
|
enableLogging,
|
|
153
153
|
silo,
|
|
154
154
|
})
|