atom.io 0.40.7 → 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/dist/data/index.js +1 -2
- package/dist/data/index.js.map +1 -1
- package/dist/employ-socket-D6wgByWh.js.map +1 -1
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/{has-role-hv4-hJMw.js → has-role-CMlaUlaf.js} +30 -46
- package/dist/has-role-CMlaUlaf.js.map +1 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +103 -174
- 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/is-fn-DY1wZ-md.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/mutex-store-CSvxY9i3.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.map +1 -1
- package/dist/realtime/index.js +2 -3
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +1 -4
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +5 -20
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +2 -5
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +4 -15
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +36 -44
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +125 -171
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +4 -2
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js +13 -7
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/{shared-room-store-COGGKqes.js → shared-room-store-BfW3nWif.js} +2 -3
- package/dist/{shared-room-store-COGGKqes.js.map → shared-room-store-BfW3nWif.js.map} +1 -1
- package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -1
- 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.js.map +1 -1
- package/package.json +11 -11
- package/src/internal/mutable/tracker.ts +66 -51
- package/src/internal/subscribe/subscribe-to-state.ts +9 -0
- package/src/realtime-client/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -1
- package/src/realtime-server/continuity/continuity-store.ts +1 -26
- package/src/realtime-server/continuity/provide-continuity.ts +50 -0
- package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +14 -12
- 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/{prepare-to-track-client-acknowledgement.ts → track-acknowledgements.ts} +15 -8
- package/src/realtime-server/index.ts +1 -2
- package/src/realtime-server/ipc-sockets/custom-socket.ts +3 -3
- package/src/realtime-server/ipc-sockets/parent-socket.ts +19 -13
- package/src/realtime-server/server-config.ts +0 -1
- package/src/realtime-testing/setup-realtime-test.tsx +20 -14
- package/dist/has-role-hv4-hJMw.js.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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<SetRTX<SocketKey>>","userIndex: MutableAtomToken<SetRTX<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/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<SetRTX<SocketKey>>","userIndex: MutableAtomToken<SetRTX<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/socket-interface.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;;;KCjBN,MAAA;;0CAE6B,IAAA,CAAK;6CAET,IAAA,CAAK;2CAEA,IAAA,CAAK;8CAEV,IAAA,CAAK;iCAEV,IAAA,CAAK;;;;KCRzB,MAAA,GAAS,IAAA,CAAK,eAAe,IAAA,CAAK;KAElC,kCACU,iCACI,8BAA8B,4BACxC,aAAa;UAEZ,sBACN,iCACe,mBAAmB,WACnC;EFFV,QAAY,EAAA,EEGC,WFHD,CEGa,YFHb,CEG0B,CFH1B,EEG6B,CFH7B,CAAA,CAAA;;AACC,uBEKS,YFLT,WEKgC,MFJnC,EAAA,UEIqD,MFJrD,CAEV,YEGY,MFHI,CAAA;EAAA,UAAA,SAAA,EEKM,GFLN,CAAA,MEKgB,CFLhB,EEKmB,GFLnB,CAAA,CAAA,GAAA,IAAA,EEKiC,IAAA,CAAK,KFLtC,EAAA,GAAA,IAAA,CAAA,CAAA;YACf,eAAA,EEK2B,GFL3B,CAAA,CAAA,KAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EEKwD,IAAA,CAAK,KFL7D,EAAA,GAAA,IAAA,CAAA;YACA,WAAA,CAAA,UAAA,MAAA,GAAA,MEK+C,CFL/C,CAAA,CAAA,GAAA,IAAA,EEMU,YFNV,CEMuB,CFNvB,EEM0B,CFN1B,CAAA,CAAA,EAAA,IAAA;YACE;QAAe,CAAA,cAAA,MEoBiB,CFpBjB,CAAA,CAAA,KAAA,EEqBT,KFrBS,EAAA,GAAA,IAAA,EEsBP,CFtBO,CEsBL,KFtBK,CAAA,EAAA,GEuBZ,YFv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K,wBAAwB,gBACvD,cAAc,kBACd,cAAc;;;KCrBjB,YAAA;UACH;UACA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { OWN_OP, operateOnStore } from "../has-role-
|
|
1
|
+
import { OWN_OP, operateOnStore } from "../has-role-CMlaUlaf.js";
|
|
2
2
|
import "../is-fn-DY1wZ-md.js";
|
|
3
3
|
import { mutexAtoms } from "../mutex-store-CSvxY9i3.js";
|
|
4
|
-
import { roomIndex, usersInRooms } from "../shared-room-store-
|
|
4
|
+
import { roomIndex, usersInRooms } from "../shared-room-store-BfW3nWif.js";
|
|
5
5
|
import { employSocket } from "../employ-socket-D6wgByWh.js";
|
|
6
|
-
import { IMPLICIT, Subject, actUponStore, editRelationsInStore, findInStore,
|
|
6
|
+
import { IMPLICIT, Subject, actUponStore, editRelationsInStore, findInStore, getFromStore, getJsonToken, getUpdateToken, isRootStore, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
|
|
7
7
|
import { atomFamily, join, mutableAtom, selectorFamily, transaction } from "atom.io";
|
|
8
8
|
import { parseJson, stringifyJson } from "atom.io/json";
|
|
9
9
|
import { SetRTX } from "atom.io/transceivers/set-rtx";
|
|
@@ -43,16 +43,92 @@ const redactorAtoms = atomFamily({
|
|
|
43
43
|
key: `redactor`,
|
|
44
44
|
default: { occlude: (updates) => updates }
|
|
45
45
|
});
|
|
46
|
-
const
|
|
46
|
+
const unacknowledgedUpdatesAtoms = atomFamily({
|
|
47
47
|
key: `unacknowledgedUpdates`,
|
|
48
48
|
default: () => []
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
//#endregion
|
|
52
|
-
//#region src/realtime-server/continuity/
|
|
53
|
-
function
|
|
52
|
+
//#region src/realtime-server/continuity/provide-outcomes.ts
|
|
53
|
+
function provideOutcomes(store, socket, continuity, userKey) {
|
|
54
54
|
const continuityKey = continuity.key;
|
|
55
|
-
|
|
55
|
+
const unsubscribeFunctions = /* @__PURE__ */ new Set();
|
|
56
|
+
for (const transaction$1 of continuity.actions) {
|
|
57
|
+
const unsubscribeFromTransaction = subscribeToTransaction(store, transaction$1, `sync-continuity:${continuityKey}:${userKey}`, (outcomes) => {
|
|
58
|
+
try {
|
|
59
|
+
const visibleKeys = continuity.globals.map((atom) => {
|
|
60
|
+
if (atom.type === `atom`) return atom.key;
|
|
61
|
+
return getUpdateToken(atom).key;
|
|
62
|
+
}).concat(continuity.perspectives.flatMap((perspective) => {
|
|
63
|
+
const { viewAtoms } = perspective;
|
|
64
|
+
const userPerspectiveTokenState = findInStore(store, viewAtoms, userKey);
|
|
65
|
+
return getFromStore(store, userPerspectiveTokenState).map((token) => {
|
|
66
|
+
return token.type === `mutable_atom` ? `*` + token.key : token.key;
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
const redactedUpdates = redactTransactionUpdateContent(visibleKeys, outcomes.subEvents);
|
|
70
|
+
const redactedUpdate = {
|
|
71
|
+
...outcomes,
|
|
72
|
+
updates: redactedUpdates
|
|
73
|
+
};
|
|
74
|
+
setIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {
|
|
75
|
+
if (redactedUpdate) {
|
|
76
|
+
updates.push(redactedUpdate);
|
|
77
|
+
updates.sort((a, b) => a.epoch - b.epoch);
|
|
78
|
+
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
|
|
79
|
+
}
|
|
80
|
+
return updates;
|
|
81
|
+
});
|
|
82
|
+
socket.emit(`tx-new:${continuityKey}`, redactedUpdate);
|
|
83
|
+
} catch (thrown) {
|
|
84
|
+
if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction$1.key} to ${userKey}`, thrown.message);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
unsubscribeFunctions.add(unsubscribeFromTransaction);
|
|
88
|
+
}
|
|
89
|
+
return () => {
|
|
90
|
+
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/realtime-server/continuity/provide-perspectives.ts
|
|
96
|
+
function providePerspectives(store, socket, continuity, userKey) {
|
|
97
|
+
const continuityKey = continuity.key;
|
|
98
|
+
const unsubFns = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const perspective of continuity.perspectives) {
|
|
100
|
+
const { viewAtoms } = perspective;
|
|
101
|
+
const userViewState = findInStore(store, viewAtoms, userKey);
|
|
102
|
+
const unsubscribeFromUserView = subscribeToState(store, userViewState, `sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`, ({ oldValue, newValue }) => {
|
|
103
|
+
const oldKeys = oldValue?.map((token) => token.key);
|
|
104
|
+
const newKeys = newValue.map((token) => token.key);
|
|
105
|
+
const concealed = oldValue?.filter((token) => !newKeys.includes(token.key));
|
|
106
|
+
const revealed = newValue.filter((token) => !oldKeys?.includes(token.key)).flatMap((token) => {
|
|
107
|
+
const resourceToken = token.type === `mutable_atom` ? getJsonToken(store, token) : token;
|
|
108
|
+
const resource = getFromStore(store, resourceToken);
|
|
109
|
+
return [resourceToken, resource];
|
|
110
|
+
});
|
|
111
|
+
store.logger.info(`👁`, `atom`, perspective.resourceAtoms.key, `${userKey} has a new perspective`, {
|
|
112
|
+
oldKeys,
|
|
113
|
+
newKeys,
|
|
114
|
+
revealed,
|
|
115
|
+
concealed
|
|
116
|
+
});
|
|
117
|
+
if (revealed.length > 0) socket.emit(`reveal:${continuityKey}`, revealed);
|
|
118
|
+
if (concealed && concealed.length > 0) socket.emit(`conceal:${continuityKey}`, concealed);
|
|
119
|
+
});
|
|
120
|
+
unsubFns.add(unsubscribeFromUserView);
|
|
121
|
+
}
|
|
122
|
+
return () => {
|
|
123
|
+
for (const unsubscribe of unsubFns) unsubscribe();
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/realtime-server/continuity/provide-startup-payloads.ts
|
|
129
|
+
function provideStartupPayloads(store, socket, continuity, userKey) {
|
|
130
|
+
const continuityKey = continuity.key;
|
|
131
|
+
function sendInitialPayload() {
|
|
56
132
|
const initialPayload = [];
|
|
57
133
|
for (const atom of continuity.globals) {
|
|
58
134
|
const resourceToken = atom.type === `mutable_atom` ? getJsonToken(store, atom) : atom;
|
|
@@ -75,15 +151,16 @@ function prepareToSendInitialPayload(store, continuity, userKey, socket) {
|
|
|
75
151
|
}
|
|
76
152
|
}
|
|
77
153
|
const epoch = isRootStore(store) ? store.transactionMeta.epoch.get(continuityKey) ?? null : null;
|
|
78
|
-
socket
|
|
79
|
-
}
|
|
154
|
+
socket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload);
|
|
155
|
+
}
|
|
156
|
+
return employSocket(socket, `get:${continuityKey}`, sendInitialPayload);
|
|
80
157
|
}
|
|
81
158
|
|
|
82
159
|
//#endregion
|
|
83
|
-
//#region src/realtime-server/continuity/
|
|
84
|
-
function
|
|
160
|
+
//#region src/realtime-server/continuity/receive-action-requests.ts
|
|
161
|
+
function receiveActionRequests(store, socket, continuity, userKey) {
|
|
85
162
|
const continuityKey = continuity.key;
|
|
86
|
-
return function serveTransactionRequest(txOutcome) {
|
|
163
|
+
return employSocket(socket, `tx-run:${continuityKey}`, function serveTransactionRequest(txOutcome) {
|
|
87
164
|
store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome);
|
|
88
165
|
const transactionKey = txOutcome.token.key;
|
|
89
166
|
const updateId = txOutcome.id;
|
|
@@ -101,142 +178,44 @@ function prepareToServeTransactionRequest(store, continuity, userKey) {
|
|
|
101
178
|
}
|
|
102
179
|
performance.mark(performanceKeyEnd);
|
|
103
180
|
const metric = performance.measure(performanceKey, performanceKeyStart, performanceKeyEnd);
|
|
104
|
-
store
|
|
105
|
-
};
|
|
181
|
+
store.logger.info(`🚀`, `transaction`, transactionKey, updateId, userKey, metric.duration);
|
|
182
|
+
});
|
|
106
183
|
}
|
|
107
184
|
|
|
108
185
|
//#endregion
|
|
109
|
-
//#region src/realtime-server/continuity/
|
|
110
|
-
function
|
|
186
|
+
//#region src/realtime-server/continuity/track-acknowledgements.ts
|
|
187
|
+
function trackAcknowledgements(store, socket, continuity, userKey) {
|
|
111
188
|
const continuityKey = continuity.key;
|
|
112
|
-
|
|
189
|
+
const userUnacknowledgedUpdates = getFromStore(store, unacknowledgedUpdatesAtoms, userKey);
|
|
190
|
+
function trackClientAcknowledgement(epoch) {
|
|
113
191
|
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} acknowledged epoch ${epoch}`);
|
|
114
|
-
|
|
115
|
-
if (isUnacknowledged) setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
|
|
192
|
+
if (userUnacknowledgedUpdates[0]?.epoch === epoch) setIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {
|
|
116
193
|
updates.shift();
|
|
117
194
|
store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
|
|
118
195
|
return updates;
|
|
119
196
|
});
|
|
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
197
|
}
|
|
194
|
-
return
|
|
198
|
+
return employSocket(socket, `ack:${continuityKey}`, trackClientAcknowledgement);
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
//#endregion
|
|
198
|
-
//#region src/realtime-server/continuity/
|
|
199
|
-
function
|
|
200
|
-
return function syncRealtimeContinuity(continuity) {
|
|
201
|
-
let socket = initialSocket;
|
|
202
|
+
//#region src/realtime-server/continuity/provide-continuity.ts
|
|
203
|
+
function prepareToProvideContinuity({ socket, store = IMPLICIT.STORE }) {
|
|
204
|
+
return function syncRealtimeContinuity(continuity, userKey) {
|
|
202
205
|
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);
|
|
206
|
+
const unacknowledgedUpdates = getFromStore(store, unacknowledgedUpdatesAtoms, userKey);
|
|
207
|
+
for (const unacknowledgedUpdate of unacknowledgedUpdates) socket.emit(`tx-new:${continuityKey}`, unacknowledgedUpdate);
|
|
208
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
209
|
+
const clearSubscriptions = () => {
|
|
210
|
+
for (const unsubscribe of subscriptions) unsubscribe();
|
|
211
|
+
subscriptions.clear();
|
|
239
212
|
};
|
|
213
|
+
subscriptions.add(providePerspectives(store, socket, continuity, userKey));
|
|
214
|
+
subscriptions.add(provideOutcomes(store, socket, continuity, userKey));
|
|
215
|
+
subscriptions.add(provideStartupPayloads(store, socket, continuity, userKey));
|
|
216
|
+
subscriptions.add(receiveActionRequests(store, socket, continuity, userKey));
|
|
217
|
+
subscriptions.add(trackAcknowledgements(store, socket, continuity, userKey));
|
|
218
|
+
return clearSubscriptions;
|
|
240
219
|
};
|
|
241
220
|
}
|
|
242
221
|
|
|
@@ -376,8 +355,7 @@ var ChildSocket = class extends CustomSocket {
|
|
|
376
355
|
}
|
|
377
356
|
});
|
|
378
357
|
this.proc.stderr.on(`data`, (buffer) => {
|
|
379
|
-
const
|
|
380
|
-
const pieces = chunk.split(`\x03`);
|
|
358
|
+
const pieces = buffer.toString().split(`\x03`);
|
|
381
359
|
const initialMaybeWellFormed = pieces[0];
|
|
382
360
|
pieces[0] = this.incompleteData + initialMaybeWellFormed;
|
|
383
361
|
let idx = 0;
|
|
@@ -474,8 +452,7 @@ var ParentSocket = class extends CustomSocket {
|
|
|
474
452
|
this.relays = /* @__PURE__ */ new Map();
|
|
475
453
|
this.relayServices = [];
|
|
476
454
|
this.proc.stdin.on(`data`, (buffer) => {
|
|
477
|
-
const
|
|
478
|
-
const pieces = chunk.split(`\x03`);
|
|
455
|
+
const pieces = buffer.toString().split(`\x03`);
|
|
479
456
|
const initialMaybeWellFormed = pieces[0];
|
|
480
457
|
pieces[0] = this.incompleteData + initialMaybeWellFormed;
|
|
481
458
|
let idx = 0;
|
|
@@ -522,14 +499,15 @@ var ParentSocket = class extends CustomSocket {
|
|
|
522
499
|
if (this.proc.pid) this.id = this.proc.pid?.toString();
|
|
523
500
|
this.on(`user-joins`, (username) => {
|
|
524
501
|
this.logger.info(`👤`, `user`, username, `joined`);
|
|
525
|
-
const
|
|
502
|
+
const userKey = `user::${username}`;
|
|
503
|
+
const relay = new SubjectSocket(userKey);
|
|
526
504
|
this.relays.set(username, relay);
|
|
527
505
|
this.logger.info(`🔗`, `attaching services:`, `[${[...this.relayServices.keys()].join(`, `)}]`);
|
|
528
|
-
for (const
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
506
|
+
for (const attachRelay of this.relayServices) {
|
|
507
|
+
const cleanupRelay = attachRelay(relay, userKey);
|
|
508
|
+
if (cleanupRelay) relay.disposalFunctions.push(cleanupRelay);
|
|
531
509
|
}
|
|
532
|
-
this.on(
|
|
510
|
+
this.on(userKey, (...data) => {
|
|
533
511
|
relay.in.next(data);
|
|
534
512
|
});
|
|
535
513
|
relay.out.subscribe(`socket`, (data) => {
|
|
@@ -546,33 +524,12 @@ var ParentSocket = class extends CustomSocket {
|
|
|
546
524
|
});
|
|
547
525
|
this.proc.stdout.write(`ALIVE`);
|
|
548
526
|
}
|
|
549
|
-
|
|
527
|
+
receiveRelay(attachServices) {
|
|
550
528
|
this.logger.info(`🔗`, `running relay method`);
|
|
551
529
|
this.relayServices.push(attachServices);
|
|
552
530
|
}
|
|
553
531
|
};
|
|
554
532
|
|
|
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
533
|
//#endregion
|
|
577
534
|
//#region src/realtime-server/realtime-family-provider.ts
|
|
578
535
|
function realtimeAtomFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
@@ -618,8 +575,7 @@ function realtimeAtomFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
|
618
575
|
const start = () => {
|
|
619
576
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
620
577
|
const exposedSubKeys = getFromStore(store, index);
|
|
621
|
-
|
|
622
|
-
if (shouldExpose) exposeFamilyMembers(subKey);
|
|
578
|
+
if (isAvailable(exposedSubKeys, subKey)) exposeFamilyMembers(subKey);
|
|
623
579
|
else {
|
|
624
580
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
625
581
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
@@ -684,8 +640,7 @@ function realtimeMutableFamilyProvider({ socket, store = IMPLICIT.STORE }) {
|
|
|
684
640
|
const start = () => {
|
|
685
641
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
686
642
|
const exposedSubKeys = getFromStore(store, index);
|
|
687
|
-
|
|
688
|
-
if (shouldExpose) exposeFamilyMembers(subKey);
|
|
643
|
+
if (isAvailable(exposedSubKeys, subKey)) exposeFamilyMembers(subKey);
|
|
689
644
|
else {
|
|
690
645
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
691
646
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
@@ -869,8 +824,7 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
869
824
|
if (getFromStore(store, mutexAtom)) {
|
|
870
825
|
clearSubscriptions();
|
|
871
826
|
subscriptions.add(subscribeToState(store, mutexAtom, socket.id, () => {
|
|
872
|
-
|
|
873
|
-
if (currentValue === false) {
|
|
827
|
+
if (getFromStore(store, mutexAtom) === false) {
|
|
874
828
|
operateOnStore(OWN_OP, store, mutexAtom, true);
|
|
875
829
|
permitPublish();
|
|
876
830
|
socket.emit(`claim-result:${clientToken.key}`, true);
|
|
@@ -890,5 +844,5 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
890
844
|
}
|
|
891
845
|
|
|
892
846
|
//#endregion
|
|
893
|
-
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoomTX, joinRoomTX, leaveRoomTX,
|
|
847
|
+
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
|
|
894
848
|
//# sourceMappingURL=index.js.map
|