atom.io 0.40.6 → 0.40.8
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/README.md +1 -1
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.js +1 -2
- package/dist/data/index.js.map +1 -1
- package/dist/employ-socket-D6wgByWh.js +12 -0
- package/dist/employ-socket-D6wgByWh.js.map +1 -0
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/has-role-CMlaUlaf.js +1133 -0
- package/dist/has-role-CMlaUlaf.js.map +1 -0
- package/dist/internal/index.d.ts +248 -248
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +590 -1803
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +1 -1
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +13 -32
- package/dist/introspection/index.js.map +1 -1
- package/dist/is-fn-DY1wZ-md.js +10 -0
- package/dist/is-fn-DY1wZ-md.js.map +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +33 -33
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +3 -4
- package/dist/main/index.js.map +1 -1
- package/dist/mutex-store-CSvxY9i3.js +11 -0
- package/dist/mutex-store-CSvxY9i3.js.map +1 -0
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +9 -11
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +7 -15
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +4 -35
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +6 -9
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +96 -88
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +17 -13
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +39 -50
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +83 -84
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +604 -543
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +5 -4
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js +35 -22
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/shared-room-store-BfW3nWif.js +31 -0
- package/dist/shared-room-store-BfW3nWif.js.map +1 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +4 -8
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/web/index.d.ts +3 -3
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +4 -3
- package/dist/web/index.js.map +1 -1
- package/package.json +13 -13
- package/src/internal/atom/create-regular-atom.ts +5 -4
- package/src/internal/atom/dispose-atom.ts +7 -2
- package/src/internal/atom/has-role.ts +3 -3
- package/src/internal/caching.ts +4 -2
- package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
- package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
- package/src/internal/families/create-regular-atom-family.ts +2 -1
- package/src/internal/families/create-writable-held-selector-family.ts +2 -1
- package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
- package/src/internal/families/dispose-from-store.ts +4 -4
- package/src/internal/families/find-in-store.ts +10 -10
- package/src/internal/families/get-family-of-token.ts +2 -2
- package/src/internal/families/index.ts +1 -0
- package/src/internal/families/mint-in-store.ts +54 -19
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/get-fallback.ts +2 -2
- package/src/internal/get-state/get-from-store.ts +5 -5
- package/src/internal/get-state/read-or-compute-value.ts +1 -1
- package/src/internal/get-state/reduce-reference.ts +8 -6
- package/src/internal/index.ts +2 -220
- package/src/internal/molecule.ts +1 -2
- package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
- package/src/internal/mutable/create-mutable-atom.ts +4 -2
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +2 -1
- package/src/internal/mutable/tracker.ts +71 -59
- package/src/internal/safe-compute.ts +1 -1
- package/src/internal/selector/create-readonly-held-selector.ts +2 -1
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
- package/src/internal/selector/create-writable-held-selector.ts +2 -1
- package/src/internal/selector/create-writable-pure-selector.ts +2 -1
- package/src/internal/selector/dispose-selector.ts +3 -2
- package/src/internal/selector/register-selector.ts +8 -5
- package/src/internal/selector/trace-selector-atoms.ts +2 -1
- package/src/internal/set-state/dispatch-state-update.ts +3 -2
- package/src/internal/set-state/evict-downstream.ts +1 -1
- package/src/internal/set-state/operate-on-store.ts +16 -22
- package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
- package/src/internal/set-state/reset-in-store.ts +5 -5
- package/src/internal/set-state/set-atom-or-selector.ts +2 -2
- package/src/internal/set-state/set-atom.ts +4 -2
- package/src/internal/set-state/set-into-store.ts +21 -39
- package/src/internal/set-state/set-selector.ts +3 -2
- package/src/internal/state-types.ts +228 -0
- package/src/internal/store/deposit.ts +4 -4
- package/src/internal/store/index.ts +0 -1
- package/src/internal/store/store.ts +9 -9
- package/src/internal/store/withdraw.ts +4 -4
- package/src/internal/subscribe/recall-state.ts +1 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
- package/src/internal/subscribe/subscribe-to-state.ts +9 -0
- package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
- package/src/internal/transaction/build-transaction.ts +3 -2
- package/src/internal/transaction/index.ts +1 -23
- package/src/internal/transaction/is-root-store.ts +4 -1
- package/src/internal/transaction/transaction-meta-progress.ts +22 -0
- package/src/main/atom.ts +1 -2
- package/src/main/find-state.ts +5 -5
- package/src/main/get-state.ts +4 -4
- package/src/main/realm.ts +2 -2
- package/src/main/set-state.ts +10 -10
- package/src/react/parse-state-overloads.ts +3 -3
- package/src/react/use-i.ts +6 -4
- package/src/react/use-loadable.ts +4 -10
- package/src/react/use-o.ts +6 -4
- package/src/react-devtools/store.ts +6 -6
- package/src/realtime/index.ts +1 -0
- package/src/realtime/mutex-store.ts +11 -0
- package/src/realtime/realtime-continuity.ts +1 -5
- package/src/realtime-client/index.ts +0 -1
- package/src/realtime-client/pull-atom-family-member.ts +14 -17
- package/src/realtime-client/pull-atom.ts +1 -1
- package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
- package/src/realtime-client/pull-selector-family-member.ts +8 -35
- package/src/realtime-client/pull-selector-roots.ts +90 -0
- package/src/realtime-client/pull-selector.ts +2 -27
- package/src/realtime-client/push-state.ts +33 -5
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
- package/src/realtime-react/index.ts +2 -2
- package/src/realtime-react/realtime-context.tsx +9 -5
- package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
- package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
- package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
- package/src/realtime-react/use-push.ts +7 -3
- package/src/realtime-react/use-realtime-service.ts +11 -11
- package/src/realtime-react/use-single-effect.ts +11 -14
- package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
- package/src/realtime-server/continuity/provide-continuity.ts +50 -0
- package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
- package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
- package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
- package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
- package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
- package/src/realtime-server/employ-socket.ts +14 -0
- package/src/realtime-server/index.ts +3 -22
- package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
- package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
- package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
- package/src/realtime-server/realtime-family-provider.ts +78 -29
- package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
- package/src/realtime-server/realtime-mutable-provider.ts +30 -22
- package/src/realtime-server/realtime-server-stores/index.ts +0 -2
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
- package/src/realtime-server/realtime-state-provider.ts +30 -29
- package/src/realtime-server/realtime-state-receiver.ts +62 -16
- package/src/realtime-server/server-config.ts +8 -0
- package/src/realtime-server/socket-interface.ts +14 -0
- package/src/realtime-testing/setup-realtime-test.tsx +70 -31
- package/src/web/index.ts +1 -1
- package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
- package/src/internal/store/mint-or-counterfeit.ts +0 -108
- package/src/realtime-client/server-action.ts +0 -23
- package/src/realtime-react/on-mount.ts +0 -5
- package/src/realtime-react/use-server-action.ts +0 -19
- package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
- package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
- package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
- package/src/realtime-server/realtime-action-receiver.ts +0 -40
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type { Fn } from "atom.io/internal"
|
|
3
|
-
import { actUponStore, arbitrary } from "atom.io/internal"
|
|
4
|
-
import { StoreContext } from "atom.io/react"
|
|
5
|
-
import * as RTC from "atom.io/realtime-client"
|
|
6
|
-
import * as React from "react"
|
|
7
|
-
|
|
8
|
-
import { useRealtimeService } from "./use-realtime-service"
|
|
9
|
-
|
|
10
|
-
export function useServerAction<F extends Fn>(
|
|
11
|
-
token: AtomIO.TransactionToken<F>,
|
|
12
|
-
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
13
|
-
const store = React.useContext(StoreContext)
|
|
14
|
-
|
|
15
|
-
useRealtimeService(`tx:${token.key}`, (socket) =>
|
|
16
|
-
RTC.serverAction(store, socket, token),
|
|
17
|
-
)
|
|
18
|
-
return actUponStore(store, token, arbitrary())
|
|
19
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
|
|
2
|
-
import type { Store } from "atom.io/internal"
|
|
3
|
-
import { actUponStore } from "atom.io/internal"
|
|
4
|
-
import type { Json, JsonIO } from "atom.io/json"
|
|
5
|
-
import type { ContinuityToken } from "atom.io/realtime"
|
|
6
|
-
|
|
7
|
-
export function prepareToServeTransactionRequest(
|
|
8
|
-
store: Store,
|
|
9
|
-
continuity: ContinuityToken,
|
|
10
|
-
userKey: string,
|
|
11
|
-
): (
|
|
12
|
-
event: Json.Serializable &
|
|
13
|
-
Pick<
|
|
14
|
-
TransactionOutcomeEvent<TransactionToken<JsonIO>>,
|
|
15
|
-
`id` | `params` | `token`
|
|
16
|
-
>,
|
|
17
|
-
) => void {
|
|
18
|
-
const continuityKey = continuity.key
|
|
19
|
-
return function serveTransactionRequest(txOutcome) {
|
|
20
|
-
store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)
|
|
21
|
-
const transactionKey = txOutcome.token.key
|
|
22
|
-
const updateId = txOutcome.id
|
|
23
|
-
const performanceKey = `tx-run:${transactionKey}:${updateId}`
|
|
24
|
-
const performanceKeyStart = `${performanceKey}:start`
|
|
25
|
-
const performanceKeyEnd = `${performanceKey}:end`
|
|
26
|
-
performance.mark(performanceKeyStart)
|
|
27
|
-
try {
|
|
28
|
-
actUponStore(
|
|
29
|
-
store,
|
|
30
|
-
{ type: `transaction`, key: transactionKey },
|
|
31
|
-
updateId,
|
|
32
|
-
)(...txOutcome.params)
|
|
33
|
-
} catch (thrown) {
|
|
34
|
-
if (thrown instanceof Error) {
|
|
35
|
-
store.logger.error(
|
|
36
|
-
`❌`,
|
|
37
|
-
`continuity`,
|
|
38
|
-
continuityKey,
|
|
39
|
-
`failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`,
|
|
40
|
-
thrown.message,
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
performance.mark(performanceKeyEnd)
|
|
45
|
-
const metric = performance.measure(
|
|
46
|
-
performanceKey,
|
|
47
|
-
performanceKeyStart,
|
|
48
|
-
performanceKeyEnd,
|
|
49
|
-
)
|
|
50
|
-
store?.logger.info(
|
|
51
|
-
`🚀`,
|
|
52
|
-
`transaction`,
|
|
53
|
-
transactionKey,
|
|
54
|
-
updateId,
|
|
55
|
-
userKey,
|
|
56
|
-
metric.duration,
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findInStore,
|
|
3
|
-
findRelationsInStore,
|
|
4
|
-
getFromStore,
|
|
5
|
-
IMPLICIT,
|
|
6
|
-
subscribeToState,
|
|
7
|
-
} from "atom.io/internal"
|
|
8
|
-
import type { Json } from "atom.io/json"
|
|
9
|
-
import type { ContinuityToken } from "atom.io/realtime"
|
|
10
|
-
|
|
11
|
-
import type { ServerConfig, Socket } from ".."
|
|
12
|
-
import { socketAtoms, usersOfSockets } from ".."
|
|
13
|
-
import { userUnacknowledgedQueues } from "../realtime-server-stores"
|
|
14
|
-
import { prepareToSendInitialPayload } from "./prepare-to-send-initial-payload"
|
|
15
|
-
import { prepareToServeTransactionRequest } from "./prepare-to-serve-transaction-request"
|
|
16
|
-
import { prepareToTrackClientAcknowledgement } from "./prepare-to-track-client-acknowledgement"
|
|
17
|
-
import { subscribeToContinuityActions } from "./subscribe-to-continuity-actions"
|
|
18
|
-
import { subscribeToContinuityPerspectives } from "./subscribe-to-continuity-perpectives"
|
|
19
|
-
|
|
20
|
-
export type ExposeRealtimeContinuity = (
|
|
21
|
-
continuity: ContinuityToken,
|
|
22
|
-
) => () => void
|
|
23
|
-
export function prepareToExposeRealtimeContinuity({
|
|
24
|
-
socket: initialSocket,
|
|
25
|
-
store = IMPLICIT.STORE,
|
|
26
|
-
}: ServerConfig): ExposeRealtimeContinuity {
|
|
27
|
-
return function syncRealtimeContinuity(continuity) {
|
|
28
|
-
let socket: Socket | null = initialSocket
|
|
29
|
-
|
|
30
|
-
const continuityKey = continuity.key
|
|
31
|
-
const userKeyState = findRelationsInStore(
|
|
32
|
-
usersOfSockets,
|
|
33
|
-
`socket::${socket.id}`,
|
|
34
|
-
store,
|
|
35
|
-
).userKeyOfSocket
|
|
36
|
-
const userKey = getFromStore(store, userKeyState)
|
|
37
|
-
if (!userKey) {
|
|
38
|
-
store.logger.error(
|
|
39
|
-
`❌`,
|
|
40
|
-
`continuity`,
|
|
41
|
-
continuityKey,
|
|
42
|
-
`Tried to create a synchronizer for a socket (${socket.id}) that is not connected to a user.`,
|
|
43
|
-
)
|
|
44
|
-
return () => {}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const socketKeyState = findRelationsInStore(
|
|
48
|
-
usersOfSockets,
|
|
49
|
-
userKey,
|
|
50
|
-
store,
|
|
51
|
-
).socketKeyOfUser
|
|
52
|
-
const _unsubscribeFromSocketTracking = subscribeToState(
|
|
53
|
-
store,
|
|
54
|
-
socketKeyState,
|
|
55
|
-
`sync-continuity:${continuityKey}:${userKey}`,
|
|
56
|
-
({ newValue: newSocketKey }) => {
|
|
57
|
-
store.logger.info(
|
|
58
|
-
`👋`,
|
|
59
|
-
`continuity`,
|
|
60
|
-
continuityKey,
|
|
61
|
-
`seeing ${userKey} on new socket ${newSocketKey}`,
|
|
62
|
-
)
|
|
63
|
-
if (newSocketKey === null) {
|
|
64
|
-
store.logger.warn(
|
|
65
|
-
`❌`,
|
|
66
|
-
`continuity`,
|
|
67
|
-
continuityKey,
|
|
68
|
-
`User (${userKey}) is not connected to a socket, waiting for them to reappear.`,
|
|
69
|
-
)
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
const newSocketState = findInStore(store, socketAtoms, newSocketKey)
|
|
73
|
-
const newSocket = getFromStore(store, newSocketState)
|
|
74
|
-
socket = newSocket
|
|
75
|
-
for (const unacknowledgedUpdate of userUnacknowledgedUpdates) {
|
|
76
|
-
socket?.emit(
|
|
77
|
-
`tx-new:${continuityKey}`,
|
|
78
|
-
unacknowledgedUpdate as Json.Serializable,
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
const userUnacknowledgedUpdates = getFromStore(
|
|
85
|
-
store,
|
|
86
|
-
userUnacknowledgedQueues,
|
|
87
|
-
userKey,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
const unsubscribeFunctions: (() => void)[] = []
|
|
91
|
-
|
|
92
|
-
const unsubscribeFromPerspectives = subscribeToContinuityPerspectives(
|
|
93
|
-
store,
|
|
94
|
-
continuity,
|
|
95
|
-
userKey,
|
|
96
|
-
socket,
|
|
97
|
-
)
|
|
98
|
-
const unsubscribeFromTransactions = subscribeToContinuityActions(
|
|
99
|
-
store,
|
|
100
|
-
continuity,
|
|
101
|
-
userKey,
|
|
102
|
-
socket,
|
|
103
|
-
)
|
|
104
|
-
unsubscribeFunctions.push(
|
|
105
|
-
...unsubscribeFromPerspectives,
|
|
106
|
-
...unsubscribeFromTransactions,
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
const sendInitialPayload = prepareToSendInitialPayload(
|
|
110
|
-
store,
|
|
111
|
-
continuity,
|
|
112
|
-
userKey,
|
|
113
|
-
initialSocket,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
socket.off(`get:${continuityKey}`, sendInitialPayload)
|
|
117
|
-
socket.on(`get:${continuityKey}`, sendInitialPayload)
|
|
118
|
-
|
|
119
|
-
const fillTransactionRequest = prepareToServeTransactionRequest(
|
|
120
|
-
store,
|
|
121
|
-
continuity,
|
|
122
|
-
userKey,
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
socket.off(`tx-run:${continuityKey}`, fillTransactionRequest)
|
|
126
|
-
socket.on(`tx-run:${continuityKey}`, fillTransactionRequest)
|
|
127
|
-
|
|
128
|
-
const trackClientAcknowledgement = prepareToTrackClientAcknowledgement(
|
|
129
|
-
store,
|
|
130
|
-
continuity,
|
|
131
|
-
userKey,
|
|
132
|
-
userUnacknowledgedUpdates,
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
socket?.on(`ack:${continuityKey}`, trackClientAcknowledgement)
|
|
136
|
-
|
|
137
|
-
return () => {
|
|
138
|
-
// clearInterval(retryTimeout)
|
|
139
|
-
for (const unsubscribe of unsubscribeFunctions) unsubscribe()
|
|
140
|
-
socket?.off(`ack:${continuityKey}`, trackClientAcknowledgement)
|
|
141
|
-
socket?.off(`get:${continuityKey}`, sendInitialPayload)
|
|
142
|
-
socket?.off(`tx-run:${continuityKey}`, fillTransactionRequest)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Store } from "atom.io/internal"
|
|
2
|
-
import { setIntoStore } from "atom.io/internal"
|
|
3
|
-
import type { ContinuityToken } from "atom.io/realtime"
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
ContinuitySyncTransactionUpdate,
|
|
7
|
-
UserKey,
|
|
8
|
-
} from "../realtime-server-stores"
|
|
9
|
-
import { userUnacknowledgedQueues } from "../realtime-server-stores"
|
|
10
|
-
|
|
11
|
-
export function prepareToTrackClientAcknowledgement(
|
|
12
|
-
store: Store,
|
|
13
|
-
continuity: ContinuityToken,
|
|
14
|
-
userKey: UserKey,
|
|
15
|
-
userUnacknowledgedUpdates: ContinuitySyncTransactionUpdate[],
|
|
16
|
-
): (epoch: number) => void {
|
|
17
|
-
const continuityKey = continuity.key
|
|
18
|
-
return function trackClientAcknowledgement(epoch) {
|
|
19
|
-
store.logger.info(
|
|
20
|
-
`👍`,
|
|
21
|
-
`continuity`,
|
|
22
|
-
continuityKey,
|
|
23
|
-
`${userKey} acknowledged epoch ${epoch}`,
|
|
24
|
-
)
|
|
25
|
-
const isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch
|
|
26
|
-
if (isUnacknowledged) {
|
|
27
|
-
setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
|
|
28
|
-
updates.shift()
|
|
29
|
-
store.logger.info(
|
|
30
|
-
`👍`,
|
|
31
|
-
`continuity`,
|
|
32
|
-
continuityKey,
|
|
33
|
-
`${userKey} unacknowledged update queue now has`,
|
|
34
|
-
updates.length,
|
|
35
|
-
`items`,
|
|
36
|
-
)
|
|
37
|
-
return updates
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
|
|
2
|
-
import { actUponStore, IMPLICIT } from "atom.io/internal"
|
|
3
|
-
import type { JsonIO } from "atom.io/json"
|
|
4
|
-
|
|
5
|
-
import type { ServerConfig } from "."
|
|
6
|
-
|
|
7
|
-
export type ActionReceiver = ReturnType<typeof realtimeActionReceiver>
|
|
8
|
-
export function realtimeActionReceiver({
|
|
9
|
-
socket,
|
|
10
|
-
store = IMPLICIT.STORE,
|
|
11
|
-
}: ServerConfig) {
|
|
12
|
-
return function actionReceiver<F extends JsonIO>(
|
|
13
|
-
tx: TransactionToken<F>,
|
|
14
|
-
): () => void {
|
|
15
|
-
const fillTransactionRequest = (
|
|
16
|
-
update: Pick<
|
|
17
|
-
TransactionOutcomeEvent<TransactionToken<F>>,
|
|
18
|
-
`id` | `params`
|
|
19
|
-
>,
|
|
20
|
-
) => {
|
|
21
|
-
const performanceKey = `tx-run:${tx.key}:${update.id}`
|
|
22
|
-
const performanceKeyStart = `${performanceKey}:start`
|
|
23
|
-
const performanceKeyEnd = `${performanceKey}:end`
|
|
24
|
-
performance.mark(performanceKeyStart)
|
|
25
|
-
actUponStore<F>(store, tx, update.id)(...update.params)
|
|
26
|
-
performance.mark(performanceKeyEnd)
|
|
27
|
-
const metric = performance.measure(
|
|
28
|
-
performanceKey,
|
|
29
|
-
performanceKeyStart,
|
|
30
|
-
performanceKeyEnd,
|
|
31
|
-
)
|
|
32
|
-
store?.logger.info(`🚀`, `transaction`, tx.key, update.id, metric.duration)
|
|
33
|
-
}
|
|
34
|
-
socket.on(`tx-run:${tx.key}`, fillTransactionRequest)
|
|
35
|
-
|
|
36
|
-
return () => {
|
|
37
|
-
socket.off(`tx-run:${tx.key}`, fillTransactionRequest)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Loadable } from "atom.io"
|
|
2
|
-
import * as AtomIO from "atom.io"
|
|
3
|
-
import { editRelationsInStore } from "atom.io/internal"
|
|
4
|
-
import type { UserInRoomMeta } from "atom.io/realtime"
|
|
5
|
-
import { roomIndex, usersInRooms } from "atom.io/realtime"
|
|
6
|
-
|
|
7
|
-
import type { ChildSocket } from "../ipc-sockets"
|
|
8
|
-
import type { RoomArguments } from "./server-room-external-store"
|
|
9
|
-
import { roomArgumentsAtoms, roomSelectors } from "./server-room-external-store"
|
|
10
|
-
import type { RoomKey } from "./server-user-store"
|
|
11
|
-
|
|
12
|
-
export const createRoomTX: AtomIO.TransactionToken<
|
|
13
|
-
(
|
|
14
|
-
roomKey: RoomKey,
|
|
15
|
-
script: string,
|
|
16
|
-
options?: string[],
|
|
17
|
-
) => Loadable<ChildSocket<any, any>>
|
|
18
|
-
> = AtomIO.transaction({
|
|
19
|
-
key: `createRoom`,
|
|
20
|
-
do: ({ get, set, find }, roomId, script, options) => {
|
|
21
|
-
const args: RoomArguments = options ? [script, options] : [script]
|
|
22
|
-
const roomArgumentsState = find(roomArgumentsAtoms, roomId)
|
|
23
|
-
set(roomArgumentsState, args)
|
|
24
|
-
set(roomIndex, (s) => s.add(roomId))
|
|
25
|
-
const roomState = find(roomSelectors, roomId)
|
|
26
|
-
const room = get(roomState)
|
|
27
|
-
return room
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
export type CreateRoomIO = AtomIO.TransactionIO<typeof createRoomTX>
|
|
31
|
-
|
|
32
|
-
export const joinRoomTX: AtomIO.TransactionToken<
|
|
33
|
-
(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta
|
|
34
|
-
> = AtomIO.transaction({
|
|
35
|
-
key: `joinRoom`,
|
|
36
|
-
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
37
|
-
const meta = { enteredAtEpoch }
|
|
38
|
-
editRelationsInStore(
|
|
39
|
-
usersInRooms,
|
|
40
|
-
(relations) => {
|
|
41
|
-
relations.set({ room: roomId, user: userId }, meta)
|
|
42
|
-
},
|
|
43
|
-
tools.env().store,
|
|
44
|
-
)
|
|
45
|
-
return meta
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
export type JoinRoomIO = AtomIO.TransactionIO<typeof joinRoomTX>
|
|
49
|
-
|
|
50
|
-
export const leaveRoomTX: AtomIO.TransactionToken<
|
|
51
|
-
(roomId: string, userId: string) => void
|
|
52
|
-
> = AtomIO.transaction({
|
|
53
|
-
key: `leaveRoom`,
|
|
54
|
-
do: (tools, roomId, userId) => {
|
|
55
|
-
editRelationsInStore(
|
|
56
|
-
usersInRooms,
|
|
57
|
-
(relations) => {
|
|
58
|
-
relations.delete({ room: roomId, user: userId })
|
|
59
|
-
},
|
|
60
|
-
tools.env().store,
|
|
61
|
-
)
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
export type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>
|
|
65
|
-
|
|
66
|
-
export const destroyRoomTX: AtomIO.TransactionToken<(roomKey: RoomKey) => void> =
|
|
67
|
-
AtomIO.transaction({
|
|
68
|
-
key: `destroyRoom`,
|
|
69
|
-
do: (tools, roomKey) => {
|
|
70
|
-
editRelationsInStore(
|
|
71
|
-
usersInRooms,
|
|
72
|
-
(relations) => {
|
|
73
|
-
relations.delete({ room: roomKey })
|
|
74
|
-
},
|
|
75
|
-
tools.env().store,
|
|
76
|
-
)
|
|
77
|
-
tools.set(roomIndex, (s) => (s.delete(roomKey), s))
|
|
78
|
-
},
|
|
79
|
-
})
|