atom.io 0.40.7 → 0.40.9
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/{chunk-Cl8Af3a2.js → chunk-CTAAG5j7.js} +3 -1
- package/dist/data/index.js +1 -2
- package/dist/data/index.js.map +1 -1
- package/dist/eslint-plugin/index.js +2 -3
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -3
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1231 -176
- package/dist/internal/index.js.map +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/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +1 -2
- package/dist/main/index.js.map +1 -1
- 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 +2 -4
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +29 -5
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +47 -5
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +2 -6
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +6 -22
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +6 -9
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +4 -16
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +38 -57
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +128 -178
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +2 -0
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js +15 -9
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +5 -9
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/transceivers/u-list/index.d.ts +29 -0
- package/dist/transceivers/u-list/index.d.ts.map +1 -0
- package/dist/transceivers/u-list/index.js +87 -0
- package/dist/transceivers/u-list/index.js.map +1 -0
- package/dist/web/index.js.map +1 -1
- package/package.json +17 -13
- package/src/internal/mutable/tracker.ts +61 -46
- package/src/internal/mutable/transceiver.ts +4 -4
- package/src/internal/set-state/index.ts +1 -0
- package/src/internal/subscribe/subscribe-to-state.ts +9 -0
- package/src/{realtime-server → realtime}/employ-socket.ts +2 -2
- package/src/realtime/index.ts +2 -0
- package/src/realtime/shared-room-store.ts +12 -11
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +1 -1
- package/src/realtime-client/index.ts +0 -1
- package/src/realtime-client/push-state.ts +1 -2
- package/src/realtime-react/index.ts +0 -1
- package/src/realtime-react/use-single-effect.ts +1 -1
- package/src/realtime-server/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} +16 -14
- package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +11 -10
- package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +8 -6
- package/src/realtime-server/continuity/receive-action-requests.ts +66 -0
- package/src/realtime-server/continuity/{prepare-to-track-client-acknowledgement.ts → track-acknowledgements.ts} +15 -9
- package/src/realtime-server/index.ts +1 -3
- package/src/realtime-server/ipc-sockets/custom-socket.ts +4 -5
- package/src/realtime-server/ipc-sockets/parent-socket.ts +21 -17
- package/src/realtime-server/realtime-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-provider.ts +1 -1
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +2 -2
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -9
- package/src/realtime-server/realtime-state-provider.ts +1 -1
- package/src/realtime-server/realtime-state-receiver.ts +3 -6
- package/src/realtime-server/server-config.ts +1 -3
- package/src/realtime-testing/setup-realtime-test.tsx +23 -18
- package/src/transceivers/set-rtx/set-rtx.ts +3 -3
- package/src/transceivers/u-list/index.ts +1 -0
- package/src/transceivers/u-list/u-list.ts +123 -0
- package/dist/employ-socket-D6wgByWh.js +0 -12
- package/dist/employ-socket-D6wgByWh.js.map +0 -1
- package/dist/has-role-hv4-hJMw.js +0 -1149
- package/dist/has-role-hv4-hJMw.js.map +0 -1
- package/dist/is-fn-DY1wZ-md.js +0 -10
- package/dist/is-fn-DY1wZ-md.js.map +0 -1
- package/dist/mutex-store-CSvxY9i3.js +0 -11
- package/dist/mutex-store-CSvxY9i3.js.map +0 -1
- package/dist/shared-room-store-COGGKqes.js +0 -32
- package/dist/shared-room-store-COGGKqes.js.map +0 -1
- package/dist/shared-room-store-D2o4ZLjC.d.ts +0 -15
- package/dist/shared-room-store-D2o4ZLjC.d.ts.map +0 -1
- package/src/realtime-client/server-action.ts +0 -23
- 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/realtime-action-receiver.ts +0 -40
- /package/src/{realtime-server → realtime}/socket-interface.ts +0 -0
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import { UserInRoomMeta } from "../shared-room-store-D2o4ZLjC.js";
|
|
2
1
|
import { RootStore, Subject, Transceiver } from "atom.io/internal";
|
|
3
2
|
import * as AtomIO from "atom.io";
|
|
4
3
|
import { Hierarchy, JoinToken, MutableAtomToken, PureSelectorFamilyToken, RegularAtomFamilyToken, TransactionIO, TransactionToken, WritableToken } from "atom.io";
|
|
5
|
-
import { Canonical, Json,
|
|
6
|
-
import {
|
|
7
|
-
import { ContinuityToken } from "atom.io/realtime";
|
|
4
|
+
import { Canonical, Json, stringified } from "atom.io/json";
|
|
5
|
+
import { UList } from "atom.io/transceivers/u-list";
|
|
6
|
+
import { ContinuityToken, Socket, UserInRoomMeta } from "atom.io/realtime";
|
|
8
7
|
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
9
8
|
import { Readable, Writable } from "node:stream";
|
|
10
9
|
|
|
11
|
-
//#region src/realtime-server/continuity/
|
|
12
|
-
type
|
|
13
|
-
declare function
|
|
14
|
-
socket
|
|
10
|
+
//#region src/realtime-server/continuity/provide-continuity.d.ts
|
|
11
|
+
type ProvideContinuity = (continuity: ContinuityToken, userKey: UserKey) => () => void;
|
|
12
|
+
declare function prepareToProvideContinuity({
|
|
13
|
+
socket,
|
|
15
14
|
store
|
|
16
|
-
}: ServerConfig):
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/realtime-server/socket-interface.d.ts
|
|
19
|
-
type Socket = {
|
|
20
|
-
id: string | undefined;
|
|
21
|
-
on: (event: string, listener: (...args: Json.Serializable[]) => void) => void;
|
|
22
|
-
onAny: (listener: (event: string, ...args: Json.Serializable[]) => void) => void;
|
|
23
|
-
off: (event: string, listener: (...args: Json.Serializable[]) => void) => void;
|
|
24
|
-
offAny: (listener: (event: string, ...args: Json.Serializable[]) => void) => void;
|
|
25
|
-
emit: (event: string, ...args: Json.Serializable[]) => void;
|
|
26
|
-
};
|
|
15
|
+
}: ServerConfig): ProvideContinuity;
|
|
27
16
|
//#endregion
|
|
28
17
|
//#region src/realtime-server/ipc-sockets/custom-socket.d.ts
|
|
29
18
|
type Events = Json.Object<string, Json.Serializable[]>;
|
|
30
|
-
type EventPayload<
|
|
19
|
+
type EventPayload<receiveRelay extends Events, K extends string & keyof receiveRelay = string & keyof receiveRelay> = [string, ...receiveRelay[K]];
|
|
31
20
|
interface EventBuffer<E extends Events, K extends string & keyof E = string & keyof E> extends Buffer {
|
|
32
21
|
toString(): stringified<EventPayload<E, K>>;
|
|
33
22
|
}
|
|
@@ -65,6 +54,29 @@ declare class ChildSocket<I extends Events, O extends Events, P extends ChildPro
|
|
|
65
54
|
constructor(proc: P, key: string, logger?: Pick<Console, `error` | `info` | `warn`>);
|
|
66
55
|
}
|
|
67
56
|
//#endregion
|
|
57
|
+
//#region src/realtime-server/realtime-server-stores/server-user-store.d.ts
|
|
58
|
+
type SocketKey = `socket::${string}`;
|
|
59
|
+
type UserKey = `user::${string}`;
|
|
60
|
+
type RoomKey = `room::${string}`;
|
|
61
|
+
type SocketSystemHierarchy = Hierarchy<[{
|
|
62
|
+
above: `root`;
|
|
63
|
+
below: [UserKey, SocketKey, RoomKey];
|
|
64
|
+
}]>;
|
|
65
|
+
declare const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>;
|
|
66
|
+
declare const socketIndex: MutableAtomToken<UList<SocketKey>>;
|
|
67
|
+
declare const userIndex: MutableAtomToken<UList<UserKey>>;
|
|
68
|
+
declare const usersOfSockets: JoinToken<`user`, UserKey, `socket`, SocketKey, `1:1`>;
|
|
69
|
+
declare const userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<UserKey[], UserKey>;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/realtime-server/realtime-server-stores/server-room-external-store.d.ts
|
|
72
|
+
declare const ROOMS: Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
|
|
73
|
+
declare function spawnRoom(roomId: string, script: string, options: string[]): Promise<ChildSocket<any, any>>;
|
|
74
|
+
declare const joinRoomTX: TransactionToken<(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta>;
|
|
75
|
+
type JoinRoomIO = TransactionIO<typeof joinRoomTX>;
|
|
76
|
+
declare const leaveRoomTX: TransactionToken<(roomId: string, userId: string) => void>;
|
|
77
|
+
type LeaveRoomIO = TransactionIO<typeof leaveRoomTX>;
|
|
78
|
+
declare const destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>;
|
|
79
|
+
//#endregion
|
|
68
80
|
//#region src/realtime-server/ipc-sockets/parent-socket.d.ts
|
|
69
81
|
declare class SubjectSocket<I extends Events, O extends Events> extends CustomSocket<I, O> {
|
|
70
82
|
in: Subject<EventPayload<I>>;
|
|
@@ -81,14 +93,14 @@ type ParentProcess = {
|
|
|
81
93
|
stderr: Writable;
|
|
82
94
|
exit: (code?: number) => void;
|
|
83
95
|
};
|
|
84
|
-
declare class ParentSocket<I extends Events & { [id in string as `relay
|
|
85
|
-
"user-joins": [
|
|
86
|
-
"user-leaves": [
|
|
96
|
+
declare class ParentSocket<I extends Events & { [id in string as `relay::${id}`]: [string, ...Json.Array[]] }, O extends Events & { [id in string as `user::${id}`]: [string, ...Json.Array[]] } & {
|
|
97
|
+
"user-joins": [key: UserKey];
|
|
98
|
+
"user-leaves": [key: UserKey];
|
|
87
99
|
}, P extends ParentProcess = ParentProcess> extends CustomSocket<I, O> {
|
|
88
100
|
protected incompleteData: string;
|
|
89
101
|
protected unprocessedEvents: string[];
|
|
90
102
|
protected relays: Map<string, SubjectSocket<any, any>>;
|
|
91
|
-
protected relayServices: ((socket: SubjectSocket<any, any
|
|
103
|
+
protected relayServices: ((socket: SubjectSocket<any, any>, userKey: UserKey) => (() => void) | void)[];
|
|
92
104
|
proc: P;
|
|
93
105
|
id: string;
|
|
94
106
|
protected log(...args: StderrLog): void;
|
|
@@ -98,16 +110,9 @@ declare class ParentSocket<I extends Events & { [id in string as `relay:${id}`]:
|
|
|
98
110
|
error: (...args: Json.Array) => void;
|
|
99
111
|
};
|
|
100
112
|
constructor(proc: P);
|
|
101
|
-
|
|
113
|
+
receiveRelay(attachServices: (socket: SubjectSocket<any, any>, userKey: UserKey) => (() => void) | void): void;
|
|
102
114
|
}
|
|
103
115
|
//#endregion
|
|
104
|
-
//#region src/realtime-server/realtime-action-receiver.d.ts
|
|
105
|
-
type ActionReceiver = ReturnType<typeof realtimeActionReceiver>;
|
|
106
|
-
declare function realtimeActionReceiver({
|
|
107
|
-
socket,
|
|
108
|
-
store
|
|
109
|
-
}: ServerConfig): <F extends JsonIO>(tx: TransactionToken<F>) => () => void;
|
|
110
|
-
//#endregion
|
|
111
116
|
//#region src/realtime-server/realtime-family-provider.d.ts
|
|
112
117
|
type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>;
|
|
113
118
|
declare function realtimeAtomFamilyProvider({
|
|
@@ -129,29 +134,6 @@ declare function realtimeMutableProvider({
|
|
|
129
134
|
store
|
|
130
135
|
}: ServerConfig): <Core extends Transceiver<any, Json.Serializable, Json.Serializable>>(token: AtomIO.MutableAtomToken<Core>) => () => void;
|
|
131
136
|
//#endregion
|
|
132
|
-
//#region src/realtime-server/realtime-server-stores/server-user-store.d.ts
|
|
133
|
-
type SocketKey = `socket::${string}`;
|
|
134
|
-
type UserKey = `user::${string}`;
|
|
135
|
-
type RoomKey = `room::${string}`;
|
|
136
|
-
type SocketSystemHierarchy = Hierarchy<[{
|
|
137
|
-
above: `root`;
|
|
138
|
-
below: [UserKey, SocketKey, RoomKey];
|
|
139
|
-
}]>;
|
|
140
|
-
declare const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>;
|
|
141
|
-
declare const socketIndex: MutableAtomToken<SetRTX<SocketKey>>;
|
|
142
|
-
declare const userIndex: MutableAtomToken<SetRTX<UserKey>>;
|
|
143
|
-
declare const usersOfSockets: JoinToken<`user`, UserKey, `socket`, SocketKey, `1:1`>;
|
|
144
|
-
declare const userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<UserKey[], UserKey>;
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/realtime-server/realtime-server-stores/server-room-external-store.d.ts
|
|
147
|
-
declare const ROOMS: Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
|
|
148
|
-
declare function spawnRoom(roomId: string, script: string, options: string[]): Promise<ChildSocket<any, any>>;
|
|
149
|
-
declare const joinRoomTX: TransactionToken<(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta>;
|
|
150
|
-
type JoinRoomIO = TransactionIO<typeof joinRoomTX>;
|
|
151
|
-
declare const leaveRoomTX: TransactionToken<(roomId: string, userId: string) => void>;
|
|
152
|
-
type LeaveRoomIO = TransactionIO<typeof leaveRoomTX>;
|
|
153
|
-
declare const destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>;
|
|
154
|
-
//#endregion
|
|
155
137
|
//#region src/realtime-server/realtime-state-provider.d.ts
|
|
156
138
|
type StateProvider = ReturnType<typeof realtimeStateProvider>;
|
|
157
139
|
declare function realtimeStateProvider({
|
|
@@ -170,8 +152,7 @@ declare function realtimeStateReceiver({
|
|
|
170
152
|
type ServerConfig = {
|
|
171
153
|
socket: Socket;
|
|
172
154
|
store?: RootStore;
|
|
173
|
-
mutex?: Set<string>;
|
|
174
155
|
};
|
|
175
156
|
//#endregion
|
|
176
|
-
export {
|
|
157
|
+
export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, JoinRoomIO, LeaveRoomIO, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ROOMS, RoomKey, ServerConfig, SocketKey, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, UserKey, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
|
|
177
158
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<UList<SocketKey>>","userIndex: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<\n\tUserKey[],\n\tUserKey\n>","ROOMS: Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>","joinRoomTX: TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n>","leaveRoomTX: TransactionToken<\n\t(roomId: string, userId: string) => void\n>","destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>"],"sources":["../../src/realtime-server/continuity/provide-continuity.ts","../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts","../../src/realtime-server/server-config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAYY,iBAAA,gBACC,0BACH;iBAEM,0BAAA;;;GAGb,eAAe;;;KChBN,MAAA,GAAS,IAAA,CAAK,eAAe,IAAA,CAAK;KAElC,kCACU,iCACI,8BAA8B,4BACxC,aAAa;UAEZ,sBACN,iCACe,mBAAmB,EDA7C,SCCU,MDDE,CAAA;EAAA,QAAA,EAAA,ECEC,WDFD,CCEa,YDFb,CCE0B,CDF1B,ECE6B,CDF7B,CAAA,CAAA;;AAEF,uBCGY,YDHZ,CAAA,UCGmC,MDHnC,EAEV,UCC+D,MDD/C,CAAA,YCEJ,MDFI,CAAA;YACf,SAAA,ECGqB,GDHrB,CAAA,MCG+B,CDH/B,ECGkC,GDHlC,CAAA,CAAA,GAAA,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
-
import { roomIndex, usersInRooms } from "../shared-room-store-COGGKqes.js";
|
|
5
|
-
import { employSocket } from "../employ-socket-D6wgByWh.js";
|
|
6
|
-
import { IMPLICIT, Subject, actUponStore, editRelationsInStore, findInStore, findRelationsInStore, getFromStore, getJsonToken, getUpdateToken, isRootStore, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
|
|
1
|
+
import { IMPLICIT, OWN_OP, Subject, actUponStore, editRelationsInStore, findInStore, getFromStore, getJsonToken, getUpdateToken, isRootStore, operateOnStore, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
|
|
7
2
|
import { atomFamily, join, mutableAtom, selectorFamily, transaction } from "atom.io";
|
|
8
3
|
import { parseJson, stringifyJson } from "atom.io/json";
|
|
9
|
-
import {
|
|
4
|
+
import { UList } from "atom.io/transceivers/u-list";
|
|
5
|
+
import { employSocket, mutexAtoms, roomIndex, usersInRooms } from "atom.io/realtime";
|
|
10
6
|
import { spawn } from "node:child_process";
|
|
11
7
|
|
|
12
8
|
//#region src/realtime-server/continuity/continuity-store.ts
|
|
@@ -43,16 +39,92 @@ const redactorAtoms = atomFamily({
|
|
|
43
39
|
key: `redactor`,
|
|
44
40
|
default: { occlude: (updates) => updates }
|
|
45
41
|
});
|
|
46
|
-
const
|
|
42
|
+
const unacknowledgedUpdatesAtoms = atomFamily({
|
|
47
43
|
key: `unacknowledgedUpdates`,
|
|
48
44
|
default: () => []
|
|
49
45
|
});
|
|
50
46
|
|
|
51
47
|
//#endregion
|
|
52
|
-
//#region src/realtime-server/continuity/
|
|
53
|
-
function
|
|
48
|
+
//#region src/realtime-server/continuity/provide-outcomes.ts
|
|
49
|
+
function provideOutcomes(store, socket, continuity, userKey) {
|
|
54
50
|
const continuityKey = continuity.key;
|
|
55
|
-
|
|
51
|
+
const unsubscribeFunctions = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const transaction$1 of continuity.actions) {
|
|
53
|
+
const unsubscribeFromTransaction = subscribeToTransaction(store, transaction$1, `sync-continuity:${continuityKey}:${userKey}`, (outcomes) => {
|
|
54
|
+
try {
|
|
55
|
+
const visibleKeys = continuity.globals.map((atom) => {
|
|
56
|
+
if (atom.type === `atom`) return atom.key;
|
|
57
|
+
return getUpdateToken(atom).key;
|
|
58
|
+
}).concat(continuity.perspectives.flatMap((perspective) => {
|
|
59
|
+
const { viewAtoms } = perspective;
|
|
60
|
+
const userPerspectiveTokenState = findInStore(store, viewAtoms, userKey);
|
|
61
|
+
return getFromStore(store, userPerspectiveTokenState).map((token) => {
|
|
62
|
+
return token.type === `mutable_atom` ? `*` + token.key : token.key;
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
const redactedUpdates = redactTransactionUpdateContent(visibleKeys, outcomes.subEvents);
|
|
66
|
+
const redactedUpdate = {
|
|
67
|
+
...outcomes,
|
|
68
|
+
updates: redactedUpdates
|
|
69
|
+
};
|
|
70
|
+
setIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {
|
|
71
|
+
if (redactedUpdate) {
|
|
72
|
+
updates.push(redactedUpdate);
|
|
73
|
+
updates.sort((a, b) => a.epoch - b.epoch);
|
|
74
|
+
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
|
|
75
|
+
}
|
|
76
|
+
return updates;
|
|
77
|
+
});
|
|
78
|
+
socket.emit(`tx-new:${continuityKey}`, redactedUpdate);
|
|
79
|
+
} catch (thrown) {
|
|
80
|
+
if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction$1.key} to ${userKey}`, thrown.message);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
unsubscribeFunctions.add(unsubscribeFromTransaction);
|
|
84
|
+
}
|
|
85
|
+
return () => {
|
|
86
|
+
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/realtime-server/continuity/provide-perspectives.ts
|
|
92
|
+
function providePerspectives(store, socket, continuity, userKey) {
|
|
93
|
+
const continuityKey = continuity.key;
|
|
94
|
+
const unsubFns = /* @__PURE__ */ new Set();
|
|
95
|
+
for (const perspective of continuity.perspectives) {
|
|
96
|
+
const { viewAtoms } = perspective;
|
|
97
|
+
const userViewState = findInStore(store, viewAtoms, userKey);
|
|
98
|
+
const unsubscribeFromUserView = subscribeToState(store, userViewState, `sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`, ({ oldValue, newValue }) => {
|
|
99
|
+
const oldKeys = oldValue?.map((token) => token.key);
|
|
100
|
+
const newKeys = newValue.map((token) => token.key);
|
|
101
|
+
const concealed = oldValue?.filter((token) => !newKeys.includes(token.key));
|
|
102
|
+
const revealed = newValue.filter((token) => !oldKeys?.includes(token.key)).flatMap((token) => {
|
|
103
|
+
const resourceToken = token.type === `mutable_atom` ? getJsonToken(store, token) : token;
|
|
104
|
+
const resource = getFromStore(store, resourceToken);
|
|
105
|
+
return [resourceToken, resource];
|
|
106
|
+
});
|
|
107
|
+
store.logger.info(`👁`, `atom`, perspective.resourceAtoms.key, `${userKey} has a new perspective`, {
|
|
108
|
+
oldKeys,
|
|
109
|
+
newKeys,
|
|
110
|
+
revealed,
|
|
111
|
+
concealed
|
|
112
|
+
});
|
|
113
|
+
if (revealed.length > 0) socket.emit(`reveal:${continuityKey}`, revealed);
|
|
114
|
+
if (concealed && concealed.length > 0) socket.emit(`conceal:${continuityKey}`, concealed);
|
|
115
|
+
});
|
|
116
|
+
unsubFns.add(unsubscribeFromUserView);
|
|
117
|
+
}
|
|
118
|
+
return () => {
|
|
119
|
+
for (const unsubscribe of unsubFns) unsubscribe();
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/realtime-server/continuity/provide-startup-payloads.ts
|
|
125
|
+
function provideStartupPayloads(store, socket, continuity, userKey) {
|
|
126
|
+
const continuityKey = continuity.key;
|
|
127
|
+
function sendInitialPayload() {
|
|
56
128
|
const initialPayload = [];
|
|
57
129
|
for (const atom of continuity.globals) {
|
|
58
130
|
const resourceToken = atom.type === `mutable_atom` ? getJsonToken(store, atom) : atom;
|
|
@@ -75,15 +147,16 @@ function prepareToSendInitialPayload(store, continuity, userKey, socket) {
|
|
|
75
147
|
}
|
|
76
148
|
}
|
|
77
149
|
const epoch = isRootStore(store) ? store.transactionMeta.epoch.get(continuityKey) ?? null : null;
|
|
78
|
-
socket
|
|
79
|
-
}
|
|
150
|
+
socket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload);
|
|
151
|
+
}
|
|
152
|
+
return employSocket(socket, `get:${continuityKey}`, sendInitialPayload);
|
|
80
153
|
}
|
|
81
154
|
|
|
82
155
|
//#endregion
|
|
83
|
-
//#region src/realtime-server/continuity/
|
|
84
|
-
function
|
|
156
|
+
//#region src/realtime-server/continuity/receive-action-requests.ts
|
|
157
|
+
function receiveActionRequests(store, socket, continuity, userKey) {
|
|
85
158
|
const continuityKey = continuity.key;
|
|
86
|
-
return function serveTransactionRequest(txOutcome) {
|
|
159
|
+
return employSocket(socket, `tx-run:${continuityKey}`, function serveTransactionRequest(txOutcome) {
|
|
87
160
|
store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome);
|
|
88
161
|
const transactionKey = txOutcome.token.key;
|
|
89
162
|
const updateId = txOutcome.id;
|
|
@@ -101,142 +174,44 @@ function prepareToServeTransactionRequest(store, continuity, userKey) {
|
|
|
101
174
|
}
|
|
102
175
|
performance.mark(performanceKeyEnd);
|
|
103
176
|
const metric = performance.measure(performanceKey, performanceKeyStart, performanceKeyEnd);
|
|
104
|
-
store
|
|
105
|
-
};
|
|
177
|
+
store.logger.info(`🚀`, `transaction`, transactionKey, updateId, userKey, metric.duration);
|
|
178
|
+
});
|
|
106
179
|
}
|
|
107
180
|
|
|
108
181
|
//#endregion
|
|
109
|
-
//#region src/realtime-server/continuity/
|
|
110
|
-
function
|
|
182
|
+
//#region src/realtime-server/continuity/track-acknowledgements.ts
|
|
183
|
+
function trackAcknowledgements(store, socket, continuity, userKey) {
|
|
111
184
|
const continuityKey = continuity.key;
|
|
112
|
-
|
|
185
|
+
const userUnacknowledgedUpdates = getFromStore(store, unacknowledgedUpdatesAtoms, userKey);
|
|
186
|
+
function trackClientAcknowledgement(epoch) {
|
|
113
187
|
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} acknowledged epoch ${epoch}`);
|
|
114
|
-
|
|
115
|
-
if (isUnacknowledged) setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
|
|
188
|
+
if (userUnacknowledgedUpdates[0]?.epoch === epoch) setIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {
|
|
116
189
|
updates.shift();
|
|
117
190
|
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
|
|
118
191
|
return updates;
|
|
119
192
|
});
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/realtime-server/continuity/subscribe-to-continuity-actions.ts
|
|
125
|
-
function subscribeToContinuityActions(store, continuity, userKey, socket) {
|
|
126
|
-
const continuityKey = continuity.key;
|
|
127
|
-
const unsubscribeFunctions = [];
|
|
128
|
-
for (const transaction$1 of continuity.actions) {
|
|
129
|
-
const unsubscribeFromTransaction = subscribeToTransaction(store, transaction$1, `sync-continuity:${continuityKey}:${userKey}`, (update) => {
|
|
130
|
-
try {
|
|
131
|
-
const visibleKeys = continuity.globals.map((atom) => {
|
|
132
|
-
if (atom.type === `atom`) return atom.key;
|
|
133
|
-
return getUpdateToken(atom).key;
|
|
134
|
-
}).concat(continuity.perspectives.flatMap((perspective) => {
|
|
135
|
-
const { viewAtoms } = perspective;
|
|
136
|
-
const userPerspectiveTokenState = findInStore(store, viewAtoms, userKey);
|
|
137
|
-
const visibleTokens = getFromStore(store, userPerspectiveTokenState);
|
|
138
|
-
return visibleTokens.map((token) => {
|
|
139
|
-
const key = token.type === `mutable_atom` ? `*` + token.key : token.key;
|
|
140
|
-
return key;
|
|
141
|
-
});
|
|
142
|
-
}));
|
|
143
|
-
const redactedUpdates = redactTransactionUpdateContent(visibleKeys, update.subEvents);
|
|
144
|
-
const redactedUpdate = {
|
|
145
|
-
...update,
|
|
146
|
-
updates: redactedUpdates
|
|
147
|
-
};
|
|
148
|
-
setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
|
|
149
|
-
if (redactedUpdate) {
|
|
150
|
-
updates.push(redactedUpdate);
|
|
151
|
-
updates.sort((a, b) => a.epoch - b.epoch);
|
|
152
|
-
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
|
|
153
|
-
}
|
|
154
|
-
return updates;
|
|
155
|
-
});
|
|
156
|
-
socket?.emit(`tx-new:${continuityKey}`, redactedUpdate);
|
|
157
|
-
} catch (thrown) {
|
|
158
|
-
if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction$1.key} to ${userKey}`, thrown.message);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
unsubscribeFunctions.push(unsubscribeFromTransaction);
|
|
162
|
-
}
|
|
163
|
-
return unsubscribeFunctions;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/realtime-server/continuity/subscribe-to-continuity-perpectives.ts
|
|
168
|
-
function subscribeToContinuityPerspectives(store, continuity, userKey, socket) {
|
|
169
|
-
const continuityKey = continuity.key;
|
|
170
|
-
const unsubFns = [];
|
|
171
|
-
for (const perspective of continuity.perspectives) {
|
|
172
|
-
const { viewAtoms } = perspective;
|
|
173
|
-
const userViewState = findInStore(store, viewAtoms, userKey);
|
|
174
|
-
const unsubscribeFromUserView = subscribeToState(store, userViewState, `sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`, ({ oldValue, newValue }) => {
|
|
175
|
-
const oldKeys = oldValue?.map((token) => token.key);
|
|
176
|
-
const newKeys = newValue.map((token) => token.key);
|
|
177
|
-
const concealed = oldValue?.filter((token) => !newKeys.includes(token.key));
|
|
178
|
-
const revealed = newValue.filter((token) => !oldKeys?.includes(token.key)).flatMap((token) => {
|
|
179
|
-
const resourceToken = token.type === `mutable_atom` ? getJsonToken(store, token) : token;
|
|
180
|
-
const resource = getFromStore(store, resourceToken);
|
|
181
|
-
return [resourceToken, resource];
|
|
182
|
-
});
|
|
183
|
-
store.logger.info(`👁`, `atom`, perspective.resourceAtoms.key, `${userKey} has a new perspective`, {
|
|
184
|
-
oldKeys,
|
|
185
|
-
newKeys,
|
|
186
|
-
revealed,
|
|
187
|
-
concealed
|
|
188
|
-
});
|
|
189
|
-
if (revealed.length > 0) socket?.emit(`reveal:${continuityKey}`, revealed);
|
|
190
|
-
if (concealed && concealed.length > 0) socket?.emit(`conceal:${continuityKey}`, concealed);
|
|
191
|
-
});
|
|
192
|
-
unsubFns.push(unsubscribeFromUserView);
|
|
193
193
|
}
|
|
194
|
-
return
|
|
194
|
+
return employSocket(socket, `ack:${continuityKey}`, trackClientAcknowledgement);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
//#endregion
|
|
198
|
-
//#region src/realtime-server/continuity/
|
|
199
|
-
function
|
|
200
|
-
return function syncRealtimeContinuity(continuity) {
|
|
201
|
-
let socket = initialSocket;
|
|
198
|
+
//#region src/realtime-server/continuity/provide-continuity.ts
|
|
199
|
+
function prepareToProvideContinuity({ socket, store = IMPLICIT.STORE }) {
|
|
200
|
+
return function syncRealtimeContinuity(continuity, userKey) {
|
|
202
201
|
const continuityKey = continuity.key;
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const socketKeyState = findRelationsInStore(usersOfSockets, userKey, store).socketKeyOfUser;
|
|
210
|
-
subscribeToState(store, socketKeyState, `sync-continuity:${continuityKey}:${userKey}`, ({ newValue: newSocketKey }) => {
|
|
211
|
-
store.logger.info(`👋`, `continuity`, continuityKey, `seeing ${userKey} on new socket ${newSocketKey}`);
|
|
212
|
-
if (newSocketKey === null) {
|
|
213
|
-
store.logger.warn(`❌`, `continuity`, continuityKey, `User (${userKey}) is not connected to a socket, waiting for them to reappear.`);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const newSocketState = findInStore(store, socketAtoms, newSocketKey);
|
|
217
|
-
const newSocket = getFromStore(store, newSocketState);
|
|
218
|
-
socket = newSocket;
|
|
219
|
-
for (const unacknowledgedUpdate of userUnacknowledgedUpdates) socket?.emit(`tx-new:${continuityKey}`, unacknowledgedUpdate);
|
|
220
|
-
});
|
|
221
|
-
const userUnacknowledgedUpdates = getFromStore(store, userUnacknowledgedQueues, userKey);
|
|
222
|
-
const unsubscribeFunctions = [];
|
|
223
|
-
const unsubscribeFromPerspectives = subscribeToContinuityPerspectives(store, continuity, userKey, socket);
|
|
224
|
-
const unsubscribeFromTransactions = subscribeToContinuityActions(store, continuity, userKey, socket);
|
|
225
|
-
unsubscribeFunctions.push(...unsubscribeFromPerspectives, ...unsubscribeFromTransactions);
|
|
226
|
-
const sendInitialPayload = prepareToSendInitialPayload(store, continuity, userKey, initialSocket);
|
|
227
|
-
socket.off(`get:${continuityKey}`, sendInitialPayload);
|
|
228
|
-
socket.on(`get:${continuityKey}`, sendInitialPayload);
|
|
229
|
-
const fillTransactionRequest = prepareToServeTransactionRequest(store, continuity, userKey);
|
|
230
|
-
socket.off(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
231
|
-
socket.on(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
232
|
-
const trackClientAcknowledgement = prepareToTrackClientAcknowledgement(store, continuity, userKey, userUnacknowledgedUpdates);
|
|
233
|
-
socket?.on(`ack:${continuityKey}`, trackClientAcknowledgement);
|
|
234
|
-
return () => {
|
|
235
|
-
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
236
|
-
socket?.off(`ack:${continuityKey}`, trackClientAcknowledgement);
|
|
237
|
-
socket?.off(`get:${continuityKey}`, sendInitialPayload);
|
|
238
|
-
socket?.off(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
202
|
+
const unacknowledgedUpdates = getFromStore(store, unacknowledgedUpdatesAtoms, userKey);
|
|
203
|
+
for (const unacknowledgedUpdate of unacknowledgedUpdates) socket.emit(`tx-new:${continuityKey}`, unacknowledgedUpdate);
|
|
204
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
205
|
+
const clearSubscriptions = () => {
|
|
206
|
+
for (const unsubscribe of subscriptions) unsubscribe();
|
|
207
|
+
subscriptions.clear();
|
|
239
208
|
};
|
|
209
|
+
subscriptions.add(providePerspectives(store, socket, continuity, userKey));
|
|
210
|
+
subscriptions.add(provideOutcomes(store, socket, continuity, userKey));
|
|
211
|
+
subscriptions.add(provideStartupPayloads(store, socket, continuity, userKey));
|
|
212
|
+
subscriptions.add(receiveActionRequests(store, socket, continuity, userKey));
|
|
213
|
+
subscriptions.add(trackAcknowledgements(store, socket, continuity, userKey));
|
|
214
|
+
return clearSubscriptions;
|
|
240
215
|
};
|
|
241
216
|
}
|
|
242
217
|
|
|
@@ -376,8 +351,7 @@ var ChildSocket = class extends CustomSocket {
|
|
|
376
351
|
}
|
|
377
352
|
});
|
|
378
353
|
this.proc.stderr.on(`data`, (buffer) => {
|
|
379
|
-
const
|
|
380
|
-
const pieces = chunk.split(`\x03`);
|
|
354
|
+
const pieces = buffer.toString().split(`\x03`);
|
|
381
355
|
const initialMaybeWellFormed = pieces[0];
|
|
382
356
|
pieces[0] = this.incompleteData + initialMaybeWellFormed;
|
|
383
357
|
let idx = 0;
|
|
@@ -450,7 +424,7 @@ var ParentSocket = class extends CustomSocket {
|
|
|
450
424
|
proc;
|
|
451
425
|
id = `#####`;
|
|
452
426
|
log(...args) {
|
|
453
|
-
this.proc.stderr.write(stringifyJson(args.map((arg) => arg instanceof
|
|
427
|
+
this.proc.stderr.write(stringifyJson(args.map((arg) => arg instanceof UList ? `{ ${arg.toJSON().members.join(` | `)} }` : arg)) + `\x03`);
|
|
454
428
|
}
|
|
455
429
|
logger = {
|
|
456
430
|
info: (...args) => {
|
|
@@ -474,8 +448,7 @@ var ParentSocket = class extends CustomSocket {
|
|
|
474
448
|
this.relays = /* @__PURE__ */ new Map();
|
|
475
449
|
this.relayServices = [];
|
|
476
450
|
this.proc.stdin.on(`data`, (buffer) => {
|
|
477
|
-
const
|
|
478
|
-
const pieces = chunk.split(`\x03`);
|
|
451
|
+
const pieces = buffer.toString().split(`\x03`);
|
|
479
452
|
const initialMaybeWellFormed = pieces[0];
|
|
480
453
|
pieces[0] = this.incompleteData + initialMaybeWellFormed;
|
|
481
454
|
let idx = 0;
|
|
@@ -522,14 +495,15 @@ var ParentSocket = class extends CustomSocket {
|
|
|
522
495
|
if (this.proc.pid) this.id = this.proc.pid?.toString();
|
|
523
496
|
this.on(`user-joins`, (username) => {
|
|
524
497
|
this.logger.info(`👤`, `user`, username, `joined`);
|
|
525
|
-
const
|
|
498
|
+
const userKey = `user::${username}`;
|
|
499
|
+
const relay = new SubjectSocket(userKey);
|
|
526
500
|
this.relays.set(username, relay);
|
|
527
501
|
this.logger.info(`🔗`, `attaching services:`, `[${[...this.relayServices.keys()].join(`, `)}]`);
|
|
528
|
-
for (const
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
502
|
+
for (const attachRelay of this.relayServices) {
|
|
503
|
+
const cleanupRelay = attachRelay(relay, userKey);
|
|
504
|
+
if (cleanupRelay) relay.disposalFunctions.push(cleanupRelay);
|
|
531
505
|
}
|
|
532
|
-
this.on(
|
|
506
|
+
this.on(userKey, (...data) => {
|
|
533
507
|
relay.in.next(data);
|
|
534
508
|
});
|
|
535
509
|
relay.out.subscribe(`socket`, (data) => {
|
|
@@ -546,33 +520,12 @@ var ParentSocket = class extends CustomSocket {
|
|
|
546
520
|
});
|
|
547
521
|
this.proc.stdout.write(`ALIVE`);
|
|
548
522
|
}
|
|
549
|
-
|
|
523
|
+
receiveRelay(attachServices) {
|
|
550
524
|
this.logger.info(`🔗`, `running relay method`);
|
|
551
525
|
this.relayServices.push(attachServices);
|
|
552
526
|
}
|
|
553
527
|
};
|
|
554
528
|
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region src/realtime-server/realtime-action-receiver.ts
|
|
557
|
-
function realtimeActionReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
558
|
-
return function actionReceiver(tx) {
|
|
559
|
-
const fillTransactionRequest = (update) => {
|
|
560
|
-
const performanceKey = `tx-run:${tx.key}:${update.id}`;
|
|
561
|
-
const performanceKeyStart = `${performanceKey}:start`;
|
|
562
|
-
const performanceKeyEnd = `${performanceKey}:end`;
|
|
563
|
-
performance.mark(performanceKeyStart);
|
|
564
|
-
actUponStore(store, tx, update.id)(...update.params);
|
|
565
|
-
performance.mark(performanceKeyEnd);
|
|
566
|
-
const metric = performance.measure(performanceKey, performanceKeyStart, performanceKeyEnd);
|
|
567
|
-
store?.logger.info(`🚀`, `transaction`, tx.key, update.id, metric.duration);
|
|
568
|
-
};
|
|
569
|
-
socket.on(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
570
|
-
return () => {
|
|
571
|
-
socket.off(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
|
|
576
529
|
//#endregion
|
|
577
530
|
//#region src/realtime-server/realtime-family-provider.ts
|
|
578
531
|
function realtimeAtomFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
@@ -618,8 +571,7 @@ function realtimeAtomFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
|
618
571
|
const start = () => {
|
|
619
572
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
620
573
|
const exposedSubKeys = getFromStore(store, index);
|
|
621
|
-
|
|
622
|
-
if (shouldExpose) exposeFamilyMembers(subKey);
|
|
574
|
+
if (isAvailable(exposedSubKeys, subKey)) exposeFamilyMembers(subKey);
|
|
623
575
|
else {
|
|
624
576
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
625
577
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
@@ -684,8 +636,7 @@ function realtimeMutableFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
|
684
636
|
const start = () => {
|
|
685
637
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
686
638
|
const exposedSubKeys = getFromStore(store, index);
|
|
687
|
-
|
|
688
|
-
if (shouldExpose) exposeFamilyMembers(subKey);
|
|
639
|
+
if (isAvailable(exposedSubKeys, subKey)) exposeFamilyMembers(subKey);
|
|
689
640
|
else {
|
|
690
641
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
691
642
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
@@ -796,11 +747,11 @@ const socketAtoms = atomFamily({
|
|
|
796
747
|
});
|
|
797
748
|
const socketIndex = mutableAtom({
|
|
798
749
|
key: `socketsIndex`,
|
|
799
|
-
class:
|
|
750
|
+
class: UList
|
|
800
751
|
});
|
|
801
752
|
const userIndex = mutableAtom({
|
|
802
753
|
key: `usersIndex`,
|
|
803
|
-
class:
|
|
754
|
+
class: UList
|
|
804
755
|
});
|
|
805
756
|
const usersOfSockets = join({
|
|
806
757
|
key: `usersOfSockets`,
|
|
@@ -869,8 +820,7 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
869
820
|
if (getFromStore(store, mutexAtom)) {
|
|
870
821
|
clearSubscriptions();
|
|
871
822
|
subscriptions.add(subscribeToState(store, mutexAtom, socket.id, () => {
|
|
872
|
-
|
|
873
|
-
if (currentValue === false) {
|
|
823
|
+
if (getFromStore(store, mutexAtom) === false) {
|
|
874
824
|
operateOnStore(OWN_OP, store, mutexAtom, true);
|
|
875
825
|
permitPublish();
|
|
876
826
|
socket.emit(`claim-result:${clientToken.key}`, true);
|
|
@@ -890,5 +840,5 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
890
840
|
}
|
|
891
841
|
|
|
892
842
|
//#endregion
|
|
893
|
-
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoomTX, joinRoomTX, leaveRoomTX,
|
|
843
|
+
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
|
|
894
844
|
//# sourceMappingURL=index.js.map
|