atom.io 0.44.11 → 0.44.12
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/introspection/index.d.ts.map +1 -1
- package/dist/realtime/index.d.ts +21 -5
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +8 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +13 -9
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +82 -68
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +3 -3
- package/src/realtime/shared-room-store.ts +14 -4
- package/src/realtime/socket-interface.ts +38 -0
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +104 -84
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["primitiveRefinery: Refinery<{\n\tnumber: (input: unknown) => input is number\n\tstring: (input: unknown) => input is string\n\tboolean: (input: unknown) => input is boolean\n\tnull: (input: unknown) => input is null\n}>","jsonTreeRefinery: Refinery<{\n\tobject: (input: unknown) => input is Json.Tree.Object\n\tarray: (input: unknown) => input is Json.Tree.Array\n}>","jsonRefinery: Refinery<{\n\tobject: (input: unknown) => input is Json.Tree.Object\n\tarray: (input: unknown) => input is Json.Tree.Array\n\tnumber: (input: unknown) => input is number\n\tstring: (input: unknown) => input is string\n\tboolean: (input: unknown) => input is boolean\n\tnull: (input: unknown) => input is null\n}>","prettyJson: Differ<\n\t{\n\t\tnumber: (input: unknown) => input is number\n\t\tstring: (input: unknown) => input is string\n\t\tboolean: (input: unknown) => input is boolean\n\t\tnull: (input: unknown) => input is null\n\t},\n\t{\n\t\tobject: (input: unknown) => input is Json.Tree.Object\n\t\tarray: (input: unknown) => input is Json.Tree.Array\n\t}\n>"],"sources":["../../src/introspection/attach-atom-index.ts","../../src/introspection/attach-selector-index.ts","../../src/introspection/attach-introspection-states.ts","../../src/introspection/auditor.ts","../../src/introspection/refinery.ts","../../src/introsp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AA,GAAA,KAAA,IE6DV,IAAA,CAAK,IAAA,CAAK,MF7DA;EAAhC,KAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IE8DqB,IAAA,CAAK,IAAA,CAAK,KF9D/B;EAAA,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IAAA,MAAA;EAGhB,MAAa,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAEV,IAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["primitiveRefinery: Refinery<{\n\tnumber: (input: unknown) => input is number\n\tstring: (input: unknown) => input is string\n\tboolean: (input: unknown) => input is boolean\n\tnull: (input: unknown) => input is null\n}>","jsonTreeRefinery: Refinery<{\n\tobject: (input: unknown) => input is Json.Tree.Object\n\tarray: (input: unknown) => input is Json.Tree.Array\n}>","jsonRefinery: Refinery<{\n\tobject: (input: unknown) => input is Json.Tree.Object\n\tarray: (input: unknown) => input is Json.Tree.Array\n\tnumber: (input: unknown) => input is number\n\tstring: (input: unknown) => input is string\n\tboolean: (input: unknown) => input is boolean\n\tnull: (input: unknown) => input is null\n}>","prettyJson: Differ<\n\t{\n\t\tnumber: (input: unknown) => input is number\n\t\tstring: (input: unknown) => input is string\n\t\tboolean: (input: unknown) => input is boolean\n\t\tnull: (input: unknown) => input is null\n\t},\n\t{\n\t\tobject: (input: unknown) => input is Json.Tree.Object\n\t\tarray: (input: unknown) => input is Json.Tree.Array\n\t}\n>"],"sources":["../../src/introspection/attach-atom-index.ts","../../src/introspection/attach-selector-index.ts","../../src/introspection/attach-introspection-states.ts","../../src/introspection/auditor.ts","../../src/introspection/refinery.ts","../../src/introspection/differ.ts","../../src/introspection/sprawl.ts","../../src/introspection/index.ts"],"sourcesContent":[],"mappings":";;;;;KAUY,cAAA,GAAiB,mBAAmB;;;KCApC,kBAAA,GAAqB,mBAChC;;;KCQW,mBAAA;EFTZ,SAAY,EEUA,SFVA,CEUU,cFV0B,CAAA;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,CAAK,IAAA,CAAK,MHtIzC;sCGuI8B,IAAA,CAAK,IAAA,CAAK;;;;KCrKpC,gBAAA,GAAmB;;;;KAInB,WAAA,sCAGP;ANAO,cMEC,MNFD,EAAA,CAAA,IAAoC,EMGzC,KNHyC,CAAA,OAAnB,CAAA,GAAA,MAAA,EAAA,SAAA,EMIjB,WNJiB,EAAA,GAAA,IAAA;;;KOFjB,yBAAyB;;iBAErB,YAAY;ANA5B,CAAA;KMGY,iCAAiC,oCAC5C,YAAY,WAAW,SAAS"}
|
package/dist/realtime/index.d.ts
CHANGED
|
@@ -56,19 +56,35 @@ declare function continuity(options: ContinuityOptions): ContinuityToken;
|
|
|
56
56
|
//#region src/realtime/shared-room-store.d.ts
|
|
57
57
|
type RoomSocketInterface<RoomNames extends string> = {
|
|
58
58
|
createRoom: (roomName: RoomNames) => void;
|
|
59
|
-
joinRoom: (roomKey:
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
joinRoom: (roomKey: RoomKey) => void;
|
|
60
|
+
deleteRoom: (roomKey: RoomKey) => void;
|
|
61
|
+
leaveRoom: () => void;
|
|
62
62
|
};
|
|
63
|
-
declare const roomKeysAtom: MutableAtomToken<UList<
|
|
63
|
+
declare const roomKeysAtom: MutableAtomToken<UList<RoomKey>>;
|
|
64
64
|
type UserInRoomMeta = {
|
|
65
65
|
enteredAtEpoch: number;
|
|
66
66
|
};
|
|
67
67
|
declare const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta;
|
|
68
68
|
declare const usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`>;
|
|
69
|
+
declare const ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`>;
|
|
69
70
|
declare const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<MutableAtomToken<UList<RoomKey>>[], UserKey>;
|
|
70
71
|
//#endregion
|
|
71
72
|
//#region src/realtime/socket-interface.d.ts
|
|
73
|
+
type EventListener = (...args: Json.Serializable[]) => void;
|
|
74
|
+
type EventsMap = {
|
|
75
|
+
[event: string]: EventListener;
|
|
76
|
+
};
|
|
77
|
+
type ParticularEventListener<ListenEvents extends EventsMap = EventsMap> = <E extends string & keyof ListenEvents>(event: E, listener: ListenEvents[E]) => void;
|
|
78
|
+
type AllEventsListener<ListenEvents extends EventsMap = EventsMap> = <E extends string & keyof ListenEvents>(event: E, ...args: Parameters<ListenEvents[E]>) => void;
|
|
79
|
+
type EventEmitter<EmitEvents extends EventsMap = EventsMap> = <E extends keyof EmitEvents>(event: E, ...args: Parameters<EmitEvents[E]>) => void;
|
|
80
|
+
type TypedSocket<ListenEvents extends EventsMap = EventsMap, EmitEvents extends EventsMap = EventsMap> = {
|
|
81
|
+
id: string | undefined;
|
|
82
|
+
on: ParticularEventListener<ListenEvents>;
|
|
83
|
+
onAny: (listener: AllEventsListener<ListenEvents>) => void;
|
|
84
|
+
off: ParticularEventListener<ListenEvents>;
|
|
85
|
+
offAny: (listener: AllEventsListener<ListenEvents>) => void;
|
|
86
|
+
emit: EventEmitter<EmitEvents>;
|
|
87
|
+
};
|
|
72
88
|
type Socket = {
|
|
73
89
|
id: string | undefined;
|
|
74
90
|
on: (event: string, listener: (...args: Json.Serializable[]) => void) => void;
|
|
@@ -78,5 +94,5 @@ type Socket = {
|
|
|
78
94
|
emit: (event: string, ...args: Json.Serializable[]) => void;
|
|
79
95
|
};
|
|
80
96
|
//#endregion
|
|
81
|
-
export { ContinuityOptions, ContinuityToken, DEFAULT_USER_IN_ROOM_META, InvariantMap, PerspectiveToken, RoomKey, RoomSocketInterface, Socket, SocketKey, SyncGroup, UserInRoomMeta, UserKey, continuity, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, roomKeysAtom, usersInMyRoomView, usersInRooms };
|
|
97
|
+
export { AllEventsListener, ContinuityOptions, ContinuityToken, DEFAULT_USER_IN_ROOM_META, EventEmitter, EventListener, EventsMap, InvariantMap, ParticularEventListener, PerspectiveToken, RoomKey, RoomSocketInterface, Socket, SocketKey, SyncGroup, TypedSocket, UserInRoomMeta, UserKey, continuity, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, ownersOfRooms, roomKeysAtom, usersInMyRoomView, usersInRooms };
|
|
82
98
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["mutexAtoms: AtomFamilyToken<boolean, Canonical>","roomKeysAtom: MutableAtomToken<UList<
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["mutexAtoms: AtomFamilyToken<boolean, Canonical>","roomKeysAtom: MutableAtomToken<UList<RoomKey>>","DEFAULT_USER_IN_ROOM_META: UserInRoomMeta","usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`>","ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`>","usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<UList<RoomKey>>[],\n\tUserKey\n>"],"sources":["../../src/realtime/employ-socket.ts","../../src/realtime/mutex-store.ts","../../src/realtime/realtime-key-types.ts","../../src/realtime/realtime-continuity.ts","../../src/realtime/shared-room-store.ts","../../src/realtime/socket-interface.ts"],"sourcesContent":[],"mappings":";;;;;;;iBAGgB,uBAAuB,iCAAiC,WAC/D,iBACD,0BACgB,EAAE;;;cCFbA,YAAY,yBAAyB;;;KCJtC,SAAA;cACC,qCAAoC;KAGrC,OAAA;cACC,mCAAkC;KAGnC,OAAA;cACC,mCAAkC;;;cCUlC,2BAA2B,IAAI,GAAG,cAAc,YAAY,GAAG;EHhB5E,GAAgB,CAAA,GAAA,EGiBC,CHjBD,EAAA,KAAA,EGiBW,CHjBX,CAAA,EAAA,IAAA;;AAAwD,KG6B5D,gBH7B4D,CAAA,UG6BjC,eH7BiC,CAAA,GAAA,CAAA,CAAA,GAAA;EAC/D,IAAA,EAAA,sBAAA;EACD,aAAA,EG6BQ,CH7BR;EACgB,SAAA,EG6BZ,mBH7BY,CG6BQ,aH7BR,CG6BsB,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,KAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EG4CyB,IAAA,CAAK,YH5C9B,EAAA,EAAA,GAAA,IAAA,EAAA,GAAA,IAAA;EACZ,GAAa,EAAA,CAAA,KAAA,EAAA,MAAoC,EAAA,QAAA,EAAA,CAAA,GAAA,IAAA,EG6CP,IAAA,CAAK,YH7CE,EAAA,EAAA,GAAA,IAAA,EAAA,GAAA,IAAA;EAGjD,MAAY,EAAA,CAAA,QAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EG4CyB,IAAA,CAAK,YH5C9B,EAAA,EAAA,GAAA,IAAA,EAAA,GAAA,IAAA;EACZ,IAAa,EAAA,CAAA,KAAA,EAAA,MAAkC,EAAA,GAAA,IAAA,EG6Cf,IAAA,CAAK,YH7CU,EAAA,EAAA,GAAA,IAAA;AAG/C,CAAA"}
|
package/dist/realtime/index.js
CHANGED
|
@@ -107,6 +107,13 @@ const usersInRooms = join({
|
|
|
107
107
|
isAType: isRoomKey,
|
|
108
108
|
isBType: isUserKey
|
|
109
109
|
});
|
|
110
|
+
const ownersOfRooms = join({
|
|
111
|
+
key: `ownersOfRooms`,
|
|
112
|
+
between: [`user`, `room`],
|
|
113
|
+
cardinality: `1:n`,
|
|
114
|
+
isAType: isUserKey,
|
|
115
|
+
isBType: isRoomKey
|
|
116
|
+
});
|
|
110
117
|
const usersInMyRoomView = selectorFamily({
|
|
111
118
|
key: `usersInMyRoomView`,
|
|
112
119
|
get: (myUsername) => ({ find }) => {
|
|
@@ -116,5 +123,5 @@ const usersInMyRoomView = selectorFamily({
|
|
|
116
123
|
});
|
|
117
124
|
|
|
118
125
|
//#endregion
|
|
119
|
-
export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, roomKeysAtom, usersInMyRoomView, usersInRooms };
|
|
126
|
+
export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, ownersOfRooms, roomKeysAtom, usersInMyRoomView, usersInRooms };
|
|
120
127
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["mutexAtoms: AtomFamilyToken<boolean, Canonical>","roomKeysAtom: MutableAtomToken<UList<
|
|
1
|
+
{"version":3,"file":"index.js","names":["mutexAtoms: AtomFamilyToken<boolean, Canonical>","roomKeysAtom: MutableAtomToken<UList<RoomKey>>","DEFAULT_USER_IN_ROOM_META: UserInRoomMeta","usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`>","ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`>","usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<UList<RoomKey>>[],\n\tUserKey\n>"],"sources":["../../src/realtime/employ-socket.ts","../../src/realtime/mutex-store.ts","../../src/realtime/realtime-continuity.ts","../../src/realtime/realtime-key-types.ts","../../src/realtime/shared-room-store.ts"],"sourcesContent":["import type { Socket } from \"atom.io/realtime\"\nimport type { Events } from \"atom.io/realtime-server\"\n\nexport function employSocket<I extends Events, K extends string & keyof I>(\n\tsocket: Socket,\n\tevent: K,\n\thandleEvent: (...data: I[K]) => void,\n): () => void {\n\tsocket.on(event, handleEvent)\n\tconst retireSocket = () => {\n\t\tsocket.off(event, handleEvent)\n\t}\n\treturn retireSocket\n}\n","import type { AtomFamilyToken } from \"atom.io\"\nimport { atomFamily } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nexport const mutexAtoms: AtomFamilyToken<boolean, Canonical> = atomFamily({\n\tkey: `mutex`,\n\tdefault: false,\n})\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tTokenType,\n\tTransactionToken,\n} from \"atom.io\"\nimport {\n\tassignTransactionToContinuity,\n\tIMPLICIT,\n\tsetEpochNumberOfContinuity,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { UserKey } from \"./realtime-key-types\"\n\n/* eslint-disable no-console */\n\nexport class InvariantMap<K, V> extends Map<K, V> implements ReadonlyMap<K, V> {\n\tpublic set(key: K, value: V): this {\n\t\tif (this.has(key)) {\n\t\t\tconsole.warn(`Tried to set a key that already exists in an InvariantMap`, {\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t})\n\t\t\treturn this\n\t\t}\n\t\treturn super.set(key, value)\n\t}\n}\n\nexport type PerspectiveToken<F extends AtomFamilyToken<any>> = {\n\ttype: `realtime_perspective`\n\tresourceAtoms: F\n\tviewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], UserKey>\n}\n\nexport type ContinuityToken = {\n\treadonly type: `continuity`\n\treadonly key: string\n\treadonly globals: AtomToken<any>[]\n\treadonly actions: TransactionToken<any>[]\n\treadonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[]\n}\n\nexport class SyncGroup {\n\tpublic type = `continuity` as const\n\n\tprotected globals: AtomToken<any>[] = []\n\tprotected actions: TransactionToken<any>[] = []\n\tprotected perspectives: PerspectiveToken<any>[] = []\n\tprotected readonly key: string\n\n\tprotected constructor(key: string) {\n\t\tthis.key = key\n\t}\n\n\tpublic static existing: InvariantMap<string, ContinuityToken> =\n\t\tnew InvariantMap()\n\tpublic static create(\n\t\tkey: string,\n\t\tbuilder: (group: SyncGroup) => SyncGroup,\n\t): ContinuityToken {\n\t\tconst group = new SyncGroup(key)\n\t\tconst { type, globals, actions, perspectives } = builder(group)\n\t\tconst token = { type, key, globals, actions, perspectives }\n\t\tSyncGroup.existing.set(key, token)\n\t\treturn token\n\t}\n\n\tpublic add(...atoms: AtomToken<any>[]): SyncGroup\n\tpublic add(...args: TransactionToken<any>[]): SyncGroup\n\tpublic add<\n\t\tF extends AtomFamilyToken<any>,\n\t\tT extends F extends AtomFamilyToken<infer U> ? U : never,\n\t>(\n\t\tfamily: AtomFamilyToken<T, any>,\n\t\tindex: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,\n\t): SyncGroup\n\tpublic add(\n\t\t...args:\n\t\t\t| readonly AtomToken<any>[]\n\t\t\t| readonly TransactionToken<any>[]\n\t\t\t| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]\n\t): this {\n\t\tconst zeroth = args[0]\n\t\tswitch (zeroth.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\tthis.globals.push(...(args as AtomToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\tthis.actions.push(...(args as TransactionToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\t{\n\t\t\t\t\tconst [family, index] = args as [\n\t\t\t\t\t\tAtomFamilyToken<any, any>,\n\t\t\t\t\t\tReadableFamilyToken<ReadableToken<any>[], UserKey>,\n\t\t\t\t\t]\n\t\t\t\t\tthis.perspectives.push({\n\t\t\t\t\t\ttype: `realtime_perspective`,\n\t\t\t\t\t\tresourceAtoms: family,\n\t\t\t\t\t\tviewAtoms: index,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\treturn this\n\t}\n}\n\nexport type ContinuityOptions = {\n\tkey: string\n\tconfig: (group: SyncGroup) => SyncGroup\n}\n\nexport function continuity(options: ContinuityOptions): ContinuityToken {\n\tconst { key, config } = options\n\tconst token = SyncGroup.create(key, config)\n\tconst { actions } = token\n\tfor (const action of actions) {\n\t\tassignTransactionToContinuity(IMPLICIT.STORE, key, action.key)\n\t}\n\tsetEpochNumberOfContinuity(IMPLICIT.STORE, key, -1)\n\treturn token\n}\n\n// const counterStates = atomFamily<number, { c: string }>({\n// \tkey: `counter`,\n// \tdefault: 0,\n// })\n// const counterIndices = atomFamily<{ c: string }[], string>({\n// \tkey: `counterIndex`,\n// \tdefault: [],\n// })\n// const nameStates = atomFamily<number, { n: string }>({\n// \tkey: `name`,\n// \tdefault: 0,\n// })\n// const nameIndices = atomFamily<{ n: string }[], string>({\n// \tkey: `nameIndex`,\n// \tdefault: [],\n// })\n\n// const counterContinuity = continuity({\n// \tkey: `counter`,\n// \tconfig: (group) =>\n// \t\tgroup\n// \t\t\t.add(counterStates, counterIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices),\n// })\n","export type SocketKey = `socket::${string}`\nexport const isSocketKey = (key: string): key is SocketKey =>\n\tkey.startsWith(`socket::`)\n\nexport type UserKey = `user::${string}`\nexport const isUserKey = (key: string): key is UserKey =>\n\tkey.startsWith(`user::`)\n\nexport type RoomKey = `room::${string}`\nexport const isRoomKey = (key: string): key is RoomKey =>\n\tkey.startsWith(`room::`)\n","import type {\n\tJoinToken,\n\tMutableAtomToken,\n\tReadonlyPureSelectorFamilyToken,\n} from \"atom.io\"\nimport { getInternalRelations, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nimport {\n\tisRoomKey,\n\tisUserKey,\n\ttype RoomKey,\n\ttype UserKey,\n} from \"./realtime-key-types\"\n\nexport type RoomSocketInterface<RoomNames extends string> = {\n\tcreateRoom: (roomName: RoomNames) => void\n\tjoinRoom: (roomKey: RoomKey) => void\n\tdeleteRoom: (roomKey: RoomKey) => void\n\tleaveRoom: () => void\n\t// [leaveRoom: `leaveRoom:${string}`]: () => void\n}\n\nexport const roomKeysAtom: MutableAtomToken<UList<RoomKey>> = mutableAtom({\n\tkey: `roomIndex`,\n\tclass: UList,\n})\n\nexport type UserInRoomMeta = {\n\tenteredAtEpoch: number\n}\nexport const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {\n\tenteredAtEpoch: 0,\n}\nexport const usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`> =\n\tjoin({\n\t\tkey: `usersInRooms`,\n\t\tbetween: [`room`, `user`],\n\t\tcardinality: `1:n`,\n\t\tisAType: isRoomKey,\n\t\tisBType: isUserKey,\n\t})\n\nexport const ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`> =\n\tjoin({\n\t\tkey: `ownersOfRooms`,\n\t\tbetween: [`user`, `room`],\n\t\tcardinality: `1:n`,\n\t\tisAType: isUserKey,\n\t\tisBType: isRoomKey,\n\t})\n\nexport const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<UList<RoomKey>>[],\n\tUserKey\n> = selectorFamily({\n\tkey: `usersInMyRoomView`,\n\tget:\n\t\t(myUsername) =>\n\t\t({ find }) => {\n\t\t\tconst [, roomsOfUsersAtoms] = getInternalRelations(usersInRooms, `split`)\n\t\t\tconst myRoomIndex = find(roomsOfUsersAtoms, myUsername)\n\t\t\treturn [myRoomIndex]\n\t\t},\n})\n"],"mappings":";;;;;AAGA,SAAgB,aACf,QACA,OACA,aACa;AACb,QAAO,GAAG,OAAO,YAAY;CAC7B,MAAM,qBAAqB;AAC1B,SAAO,IAAI,OAAO,YAAY;;AAE/B,QAAO;;;;;ACRR,MAAaA,aAAkD,WAAW;CACzE,KAAK;CACL,SAAS;CACT,CAAC;;;;ACYF,IAAa,eAAb,cAAwC,IAAuC;CAC9E,AAAO,IAAI,KAAQ,OAAgB;AAClC,MAAI,KAAK,IAAI,IAAI,EAAE;AAClB,WAAQ,KAAK,6DAA6D;IACzE;IACA;IACA,CAAC;AACF,UAAO;;AAER,SAAO,MAAM,IAAI,KAAK,MAAM;;;AAkB9B,IAAa,YAAb,MAAa,UAAU;CACtB,AAAO,OAAO;CAEd,AAAU,UAA4B,EAAE;CACxC,AAAU,UAAmC,EAAE;CAC/C,AAAU,eAAwC,EAAE;CACpD,AAAmB;CAEnB,AAAU,YAAY,KAAa;AAClC,OAAK,MAAM;;CAGZ,OAAc,WACb,IAAI,cAAc;CACnB,OAAc,OACb,KACA,SACkB;EAElB,MAAM,EAAE,MAAM,SAAS,SAA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E,gBACA,EAAE,WAAW;EACb,MAAM,GAAG,qBAAqB,qBAAqB,cAAc,QAAQ;AAEzE,SAAO,CADa,KAAK,mBAAmB,WAAW,CACnC;;CAEtB,CAAC"}
|
|
@@ -126,17 +126,21 @@ declare const ROOMS: RoomMap;
|
|
|
126
126
|
declare const roomMeta: {
|
|
127
127
|
count: number;
|
|
128
128
|
};
|
|
129
|
-
declare function spawnRoom(store: Store, roomKey: RoomKey, command: string, args: string[]): Promise<ChildSocket<any, any>>;
|
|
130
|
-
declare function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
} | null;
|
|
129
|
+
declare function spawnRoom(store: Store, userKey: UserKey, roomKey: RoomKey, command: string, args: string[]): Promise<ChildSocket<any, any>>;
|
|
130
|
+
declare function provideEnterAndExit(store: Store, userKey: UserKey, socket: Socket): {
|
|
131
|
+
enterRoom: (roomKey: RoomKey) => void;
|
|
132
|
+
};
|
|
134
133
|
declare function leaveRoom(store: Store, roomKey: RoomKey, userKey: UserKey): void;
|
|
135
|
-
declare function destroyRoom(store: Store
|
|
134
|
+
declare function destroyRoom(store: Store): (roomKey: RoomKey) => void;
|
|
135
|
+
type ProvideRoomsConfig = {
|
|
136
|
+
resolveRoomScript: (path: string) => [string, string[]];
|
|
137
|
+
roomTimeLimit?: number;
|
|
138
|
+
};
|
|
136
139
|
declare function provideRooms<RoomNames extends string>({
|
|
137
140
|
store,
|
|
138
|
-
socket
|
|
139
|
-
|
|
141
|
+
socket,
|
|
142
|
+
resolveRoomScript
|
|
143
|
+
}: ProvideRoomsConfig & ServerConfig): void;
|
|
140
144
|
//#endregion
|
|
141
145
|
//#region src/realtime-server/realtime-server-stores/server-user-store.d.ts
|
|
142
146
|
type SocketSystemHierarchy = Hierarchy<[{
|
|
@@ -163,5 +167,5 @@ declare function realtimeStateReceiver({
|
|
|
163
167
|
store
|
|
164
168
|
}: ServerConfig): <S extends Json.Serializable, C extends S>(clientToken: WritableToken<C>, serverToken?: WritableToken<S>) => () => void;
|
|
165
169
|
//#endregion
|
|
166
|
-
export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, destroyRoom,
|
|
170
|
+
export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ProvideRoomsConfig, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, destroyRoom, leaveRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, selfListSelectors, socketAtoms, socketKeysAtom, spawnRoom, userKeysAtom, usersOfSockets };
|
|
167
171
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap","ROOMS: RoomMap","roomMeta: { count: number }","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","userKeysAtom: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey>"],"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/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/server-config.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.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;EAIZ,QAAgB,EAAA,ECFH,WDEG,CCFS,YDET,CCFsB,CDEtB,ECFyB,CDEzB,CAAA,CAAA;;AAEf,uBCDqB,YDCrB,CACE,UCF0C,MDE1C,EAAe,UCF6C,MDE7C,CAAA,YCDN,MDCM,CAAA;uBCCI,UAAU,GAAG,cAAc,IAAA,CAAK;6BAC1B,6BAA6B,IAAA,CAAK;iDACd,YACrC,aAAa,GAAG;EApB3B,EAAA,EAAY,MAAA;EAEZ,IAAY,EAAA,CAAA,cAAA,MAiCuB,CAjCvB,CAAA,CAAA,KAAA,EAkCH,KAlCG,EAAA,GAAA,IAAA,EAmCD,CAnCC,CAmCC,KAnCD,CAAA,EAAA,GAoCN,YApCM,CAoCO,CApCP,EAoCU,CApCV,CAAA;EACU,WAAA,CAAA,IAAA,EAAA,CAAA,cAAA,MAsCO,CAtCP,CAAA,CAAA,KAAA,EAuCZ,KAvCY,EAAA,GAAA,IAAA,EAwCV,CAxCU,CAwCR,KAxCQ,CAAA,EAAA,GAyCf,YAzCe,CAyCF,CAzCE,EAyCC,CAzCD,CAAA;EACI,EAAA,CAAA,cAAA,MA+CK,CA/CL,CAAA,CAAA,KAAA,EAgDjB,KAhDiB,EAAA,QAAA,EAAA,CAAA,GAAA,IAAA,EAiDJ,CAjDI,CAiDF,KAjDE,CAAA,EAAA,GAAA,IAAA,CAAA,EAAA,IAAA;EAA8B,KAAA,CAAA,QAAA,EAAA,CAA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Token<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","userKeysAtom: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey>"],"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/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/server-config.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.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;EAIZ,QAAgB,EAAA,ECFH,WDEG,CCFS,YDET,CCFsB,CDEtB,ECFyB,CDEzB,CAAA,CAAA;;AAEf,uBCDqB,YDCrB,CACE,UCF0C,MDE1C,EAAe,UCF6C,MDE7C,CAAA,YCDN,MDCM,CAAA;uBCCI,UAAU,GAAG,cAAc,IAAA,CAAK;6BAC1B,6BAA6B,IAAA,CAAK;iDACd,YACrC,aAAa,GAAG;EApB3B,EAAA,EAAY,MAAA;EAEZ,IAAY,EAAA,CAAA,cAAA,MAiCuB,CAjCvB,CAAA,CAAA,KAAA,EAkCH,KAlCG,EAAA,GAAA,IAAA,EAmCD,CAnCC,CAmCC,KAnCD,CAAA,EAAA,GAoCN,YApCM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,SAAS,WAAW;;cAKlBC,aAAa,uBAAuB,eAAe;cAMnDC,gBAAgB,iBAAiB,MAAM;cAIvCC,cAAc,iBAAiB,MAAM;ATnBtC,cSuBCC,cTvBD,ESuBiB,STtBhB,CAAA,MAAA,ESwBZ,OTvBS,EAAA,QAAA,ESyBT,STzBS,EAAA,KAAA,CAAA;AAEM,cSiCHC,iBTjCG,ESiCgB,uBTjChB,CSiCwC,OTjCxC,EAAA,ESiCmD,OTjCnD,CAAA;;;KUTJ,aAAA,GAAgB,kBAAkB;iBAC9B,qBAAA;;;GAGb,0BACsC,IAAA,CAAK,qBACrC,MAAA,CAAO,cAAc;;;KCElB,aAAA,GAAgB,kBAAkB;iBAC9B,qBAAA;;;GAGb,0BACsC,IAAA,CAAK,wBAAwB,gBACvD,cAAc,kBACd,cAAc"}
|
|
@@ -2,7 +2,7 @@ import { IMPLICIT, OWN_OP, Subject, actUponStore, editRelationsInStore, findInSt
|
|
|
2
2
|
import { atomFamily, join, mutableAtom, selectorFamily } from "atom.io";
|
|
3
3
|
import { parseJson, stringifyJson } from "atom.io/json";
|
|
4
4
|
import { UList } from "atom.io/transceivers/u-list";
|
|
5
|
-
import { employSocket, isSocketKey, isUserKey, mutexAtoms, roomKeysAtom, usersInRooms } from "atom.io/realtime";
|
|
5
|
+
import { employSocket, isSocketKey, isUserKey, mutexAtoms, ownersOfRooms, roomKeysAtom, usersInRooms } from "atom.io/realtime";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
|
|
8
8
|
//#region src/realtime-server/continuity/continuity-store.ts
|
|
@@ -706,7 +706,7 @@ const selfListSelectors = selectorFamily({
|
|
|
706
706
|
//#region src/realtime-server/realtime-server-stores/server-room-external-store.ts
|
|
707
707
|
const ROOMS = globalThis.ATOM_IO_REALTIME_SERVER_ROOMS ?? (globalThis.ATOM_IO_REALTIME_SERVER_ROOMS = /* @__PURE__ */ new Map());
|
|
708
708
|
const roomMeta = { count: 0 };
|
|
709
|
-
async function spawnRoom(store, roomKey, command, args) {
|
|
709
|
+
async function spawnRoom(store, userKey, roomKey, command, args) {
|
|
710
710
|
const roomSocket = new ChildSocket(await new Promise((resolve) => {
|
|
711
711
|
const room = spawn(command, args, { env: process.env });
|
|
712
712
|
const resolver = (data) => {
|
|
@@ -719,52 +719,62 @@ async function spawnRoom(store, roomKey, command, args) {
|
|
|
719
719
|
}), roomKey);
|
|
720
720
|
ROOMS.set(roomKey, roomSocket);
|
|
721
721
|
setIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index));
|
|
722
|
-
|
|
723
|
-
destroyRoom(store, roomKey);
|
|
724
|
-
});
|
|
725
|
-
return roomSocket;
|
|
726
|
-
}
|
|
727
|
-
function joinRoom(store, roomKey, userKey, socket) {
|
|
728
|
-
const roomQueue = [];
|
|
729
|
-
const pushToRoomQueue = (payload) => {
|
|
730
|
-
roomQueue.push(payload);
|
|
731
|
-
};
|
|
732
|
-
let toRoom = pushToRoomQueue;
|
|
733
|
-
const forward = (...payload) => {
|
|
734
|
-
toRoom(payload);
|
|
735
|
-
};
|
|
736
|
-
socket.onAny(forward);
|
|
737
|
-
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
722
|
+
editRelationsInStore(store, ownersOfRooms, (relations) => {
|
|
738
723
|
relations.set({
|
|
739
724
|
room: roomKey,
|
|
740
725
|
user: userKey
|
|
741
726
|
});
|
|
742
727
|
});
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`);
|
|
746
|
-
return null;
|
|
747
|
-
}
|
|
748
|
-
roomSocket.onAny((...payload) => {
|
|
749
|
-
socket.emit(...payload);
|
|
728
|
+
roomSocket.on(`close`, () => {
|
|
729
|
+
destroyRoom(store)(roomKey);
|
|
750
730
|
});
|
|
751
|
-
roomSocket
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
leaveRoom
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
731
|
+
return roomSocket;
|
|
732
|
+
}
|
|
733
|
+
function provideEnterAndExit(store, userKey, socket) {
|
|
734
|
+
const enterRoom = (roomKey) => {
|
|
735
|
+
const exitRoom = () => {
|
|
736
|
+
socket.offAny(forward);
|
|
737
|
+
toRoom([`user-leaves`]);
|
|
738
|
+
leaveRoom(store, roomKey, userKey);
|
|
739
|
+
socket.off(`leaveRoom`, exitRoom);
|
|
740
|
+
socket.on(`joinRoom`, enterRoom);
|
|
741
|
+
};
|
|
742
|
+
socket.on(`leaveRoom`, exitRoom);
|
|
743
|
+
socket.off(`joinRoom`, enterRoom);
|
|
744
|
+
const roomQueue = [];
|
|
745
|
+
const pushToRoomQueue = (payload) => {
|
|
746
|
+
roomQueue.push(payload);
|
|
747
|
+
};
|
|
748
|
+
let toRoom = pushToRoomQueue;
|
|
749
|
+
const forward = (...payload) => {
|
|
750
|
+
toRoom(payload);
|
|
751
|
+
};
|
|
752
|
+
socket.onAny(forward);
|
|
753
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
754
|
+
relations.set({
|
|
755
|
+
room: roomKey,
|
|
756
|
+
user: userKey
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
const roomSocket = ROOMS.get(roomKey);
|
|
760
|
+
if (!roomSocket) {
|
|
761
|
+
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`);
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
roomSocket.onAny((...payload) => {
|
|
765
|
+
socket.emit(...payload);
|
|
766
|
+
});
|
|
767
|
+
roomSocket.emit(`user-joins`, userKey);
|
|
768
|
+
toRoom = (payload) => {
|
|
769
|
+
roomSocket.emit(`user::${userKey}`, ...payload);
|
|
770
|
+
};
|
|
771
|
+
while (roomQueue.length > 0) {
|
|
772
|
+
const payload = roomQueue.shift();
|
|
773
|
+
if (payload) toRoom(payload);
|
|
774
|
+
}
|
|
767
775
|
};
|
|
776
|
+
socket.on(`joinRoom`, enterRoom);
|
|
777
|
+
return { enterRoom };
|
|
768
778
|
}
|
|
769
779
|
function leaveRoom(store, roomKey, userKey) {
|
|
770
780
|
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
@@ -774,20 +784,23 @@ function leaveRoom(store, roomKey, userKey) {
|
|
|
774
784
|
});
|
|
775
785
|
});
|
|
776
786
|
}
|
|
777
|
-
function destroyRoom(store
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
room
|
|
785
|
-
|
|
786
|
-
|
|
787
|
+
function destroyRoom(store) {
|
|
788
|
+
return (roomKey) => {
|
|
789
|
+
setIntoStore(store, roomKeysAtom, (s) => (s.delete(roomKey), s));
|
|
790
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
791
|
+
relations.delete({ room: roomKey });
|
|
792
|
+
});
|
|
793
|
+
const room = ROOMS.get(roomKey);
|
|
794
|
+
if (room) {
|
|
795
|
+
room.emit(`exit`);
|
|
796
|
+
ROOMS.delete(roomKey);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
787
799
|
}
|
|
788
|
-
function provideRooms({ store = IMPLICIT.STORE, socket
|
|
800
|
+
function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript }) {
|
|
789
801
|
const socketKey = `socket::${socket.id}`;
|
|
790
802
|
const userKey = getFromStore(store, findRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket);
|
|
803
|
+
const roomSocket = socket;
|
|
791
804
|
const exposeMutable = realtimeMutableProvider({
|
|
792
805
|
socket,
|
|
793
806
|
store
|
|
@@ -797,23 +810,24 @@ function provideRooms({ store = IMPLICIT.STORE, socket }, resolveRoomScript) {
|
|
|
797
810
|
store
|
|
798
811
|
});
|
|
799
812
|
exposeMutable(roomKeysAtom);
|
|
800
|
-
|
|
813
|
+
const [, usersInRoomsAtoms] = getInternalRelationsFromStore(store, usersInRooms, `split`);
|
|
814
|
+
exposeMutableFamily(usersInRoomsAtoms, findInStore(store, selfListSelectors, userKey));
|
|
801
815
|
exposeMutableFamily(getInternalRelationsFromStore(store, usersOfSockets), socketKeysAtom);
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
816
|
+
const createRoom = async (roomName) => {
|
|
817
|
+
await spawnRoom(store, userKey, `room::${roomMeta.count++}`, ...resolveRoomScript(roomName));
|
|
818
|
+
};
|
|
819
|
+
const { enterRoom } = provideEnterAndExit(store, userKey, roomSocket);
|
|
820
|
+
const userRoomSet = getFromStore(store, usersInRoomsAtoms, userKey);
|
|
821
|
+
for (const userRoomKey of userRoomSet) {
|
|
822
|
+
enterRoom(userRoomKey);
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
roomSocket.on(`createRoom`, createRoom);
|
|
826
|
+
roomSocket.on(`deleteRoom`, destroyRoom(store));
|
|
813
827
|
socket.on(`disconnect`, () => {
|
|
814
|
-
editRelationsInStore(store, usersOfSockets, (
|
|
815
|
-
|
|
816
|
-
setIntoStore(store, socketKeysAtom, (
|
|
828
|
+
editRelationsInStore(store, usersOfSockets, (rel) => rel.delete(socketKey));
|
|
829
|
+
setIntoStore(store, userKeysAtom, (keys) => (keys.delete(userKey), keys));
|
|
830
|
+
setIntoStore(store, socketKeysAtom, (keys) => (keys.delete(socketKey), keys));
|
|
817
831
|
});
|
|
818
832
|
}
|
|
819
833
|
|
|
@@ -890,5 +904,5 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
890
904
|
}
|
|
891
905
|
|
|
892
906
|
//#endregion
|
|
893
|
-
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoom,
|
|
907
|
+
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoom, leaveRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, selfListSelectors, socketAtoms, socketKeysAtom, spawnRoom, userKeysAtom, usersOfSockets };
|
|
894
908
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>","unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n>","initialPayload: Json.Serializable[]","isAvailable","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","userKeysAtom: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey>","ROOMS: RoomMap","roomMeta: { count: number }","roomQueue: [string, ...Json.Array][]"],"sources":["../../src/realtime-server/continuity/continuity-store.ts","../../src/realtime-server/continuity/provide-outcomes.ts","../../src/realtime-server/continuity/provide-perspectives.ts","../../src/realtime-server/continuity/provide-startup-payloads.ts","../../src/realtime-server/continuity/receive-action-requests.ts","../../src/realtime-server/continuity/track-acknowledgements.ts","../../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/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-server-stores/server-user-store.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts"],"sourcesContent":["import type {\n\tRegularAtomFamilyToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n} from \"atom.io\"\nimport { atomFamily } from \"atom.io\"\nimport type { UserKey } from \"atom.io/realtime\"\n\nexport function redactTransactionUpdateContent(\n\tvisibleStateKeys: string[],\n\tupdates: TransactionSubEvent[],\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.map((update): TransactionSubEvent => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `transaction_outcome`: {\n\t\t\t\t\tconst redacted = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleStateKeys,\n\t\t\t\t\t\tupdate.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\treturn { ...update, subEvents: redacted }\n\t\t\t\t}\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn update\n\t\t\t}\n\t\t})\n\t\t.filter((update) => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn visibleStateKeys.includes(update.token.key)\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `transaction_outcome`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true\n\t\t\t}\n\t\t})\n}\n\nexport const redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n> = atomFamily({\n\tkey: `redactor`,\n\tdefault: { occlude: (updates) => updates },\n})\n\nexport type ContinuitySyncTransactionUpdate = Pick<\n\tTransactionOutcomeEvent<any>,\n\t`epoch` | `id` | `output` | `subEvents` | `token`\n>\nexport const unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n> = atomFamily({\n\tkey: `unacknowledgedUpdates`,\n\tdefault: () => [],\n})\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetUpdateToken,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\n\nimport {\n\tredactTransactionUpdateContent,\n\tunacknowledgedUpdatesAtoms,\n} from \"./continuity-store\"\n\nexport function provideOutcomes(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubscribeFunctions = new Set<() => void>()\n\n\tfor (const transaction of continuity.actions) {\n\t\tconst unsubscribeFromTransaction = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}`,\n\t\t\t(outcomes) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst visibleKeys = continuity.globals\n\t\t\t\t\t\t.map((atom) => {\n\t\t\t\t\t\t\tif (atom.type === `atom`) {\n\t\t\t\t\t\t\t\treturn atom.key\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn getUpdateToken(atom).key\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.concat(\n\t\t\t\t\t\t\tcontinuity.perspectives.flatMap((perspective) => {\n\t\t\t\t\t\t\t\tconst { viewAtoms } = perspective\n\t\t\t\t\t\t\t\tconst userPerspectiveTokenState = findInStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tviewAtoms,\n\t\t\t\t\t\t\t\t\tuserKey,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst visibleTokens = getFromStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tuserPerspectiveTokenState,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn visibleTokens.map((token) => {\n\t\t\t\t\t\t\t\t\tconst key =\n\t\t\t\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? `*` + token.key : token.key\n\t\t\t\t\t\t\t\t\treturn key\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdates = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleKeys,\n\t\t\t\t\t\toutcomes.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdate = {\n\t\t\t\t\t\t...outcomes,\n\t\t\t\t\t\tupdates: redactedUpdates,\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\t\t\tif (redactedUpdate) {\n\t\t\t\t\t\t\tupdates.push(redactedUpdate)\n\t\t\t\t\t\t\tupdates.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\t\t\t\tupdates.length,\n\t\t\t\t\t\t\t\t`items`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn updates\n\t\t\t\t\t})\n\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\t\t\tredactedUpdate as Json.Serializable,\n\t\t\t\t\t)\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t`${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`,\n\t\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubscribeFunctions.add(unsubscribeFromTransaction)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\n\nexport function providePerspectives(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubFns = new Set<() => void>()\n\tfor (const perspective of continuity.perspectives) {\n\t\tconst { viewAtoms } = perspective\n\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\tconst unsubscribeFromUserView = subscribeToState(\n\t\t\tstore,\n\t\t\tuserViewState,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,\n\t\t\t({ oldValue, newValue }) => {\n\t\t\t\tconst oldKeys = oldValue?.map((token) => token.key)\n\t\t\t\tconst newKeys = newValue.map((token) => token.key)\n\t\t\t\tconst concealed = oldValue?.filter(\n\t\t\t\t\t(token) => !newKeys.includes(token.key),\n\t\t\t\t)\n\t\t\t\tconst revealed = newValue\n\t\t\t\t\t.filter((token) => !oldKeys?.includes(token.key))\n\t\t\t\t\t.flatMap((token) => {\n\t\t\t\t\t\tconst resourceToken =\n\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? getJsonToken(store, token) : token\n\t\t\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\t\t\t\treturn [resourceToken, resource]\n\t\t\t\t\t})\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👁`,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tperspective.resourceAtoms.key,\n\t\t\t\t\t`${userKey} has a new perspective`,\n\t\t\t\t\t{ oldKeys, newKeys, revealed, concealed },\n\t\t\t\t)\n\t\t\t\tif (revealed.length > 0) {\n\t\t\t\t\tsocket.emit(`reveal:${continuityKey}`, revealed)\n\t\t\t\t}\n\t\t\t\tif (concealed && concealed.length > 0) {\n\t\t\t\t\tsocket.emit(`conceal:${continuityKey}`, concealed)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubFns.add(unsubscribeFromUserView)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubFns) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tisRootStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nexport function provideStartupPayloads(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tfunction sendInitialPayload(): void {\n\t\tconst initialPayload: Json.Serializable[] = []\n\t\tfor (const atom of continuity.globals) {\n\t\t\tconst resourceToken =\n\t\t\t\tatom.type === `mutable_atom` ? getJsonToken(store, atom) : atom\n\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t}\n\t\tfor (const perspective of continuity.perspectives) {\n\t\t\tconst { viewAtoms, resourceAtoms } = perspective\n\t\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\t\tconst userView = getFromStore(store, userViewState)\n\t\t\tstore.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {\n\t\t\t\tviewAtoms,\n\t\t\t\tresourceAtoms,\n\t\t\t\tuserView,\n\t\t\t})\n\t\t\tfor (const visibleToken of userView) {\n\t\t\t\tconst resourceToken =\n\t\t\t\t\tvisibleToken.type === `mutable_atom`\n\t\t\t\t\t\t? getJsonToken(store, visibleToken)\n\t\t\t\t\t\t: visibleToken\n\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\n\t\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t\t}\n\t\t}\n\n\t\tconst epoch = isRootStore(store)\n\t\t\t? (store.transactionMeta.epoch.get(continuityKey) ?? null)\n\t\t\t: null\n\n\t\tsocket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload)\n\t}\n\treturn employSocket(socket, `get:${continuityKey}`, sendInitialPayload)\n}\n","import type { TransactionOutcomeEvent, TransactionToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { actUponStore } from \"atom.io/internal\"\nimport type { Json, JsonIO } from \"atom.io/json\"\nimport type { ContinuityToken, Socket } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nexport function receiveActionRequests(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: string,\n): () => void {\n\tconst continuityKey = continuity.key\n\n\treturn employSocket(\n\t\tsocket,\n\t\t`tx-run:${continuityKey}`,\n\t\tfunction serveTransactionRequest(\n\t\t\ttxOutcome: Json.Serializable &\n\t\t\t\tPick<\n\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<JsonIO>>,\n\t\t\t\t\t`id` | `params` | `token`\n\t\t\t\t>,\n\t\t) {\n\t\t\tstore.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)\n\t\t\tconst transactionKey = txOutcome.token.key\n\t\t\tconst updateId = txOutcome.id\n\t\t\tconst performanceKey = `tx-run:${transactionKey}:${updateId}`\n\t\t\tconst performanceKeyStart = `${performanceKey}:start`\n\t\t\tconst performanceKeyEnd = `${performanceKey}:end`\n\t\t\tperformance.mark(performanceKeyStart)\n\t\t\ttry {\n\t\t\t\tactUponStore(\n\t\t\t\t\tstore,\n\t\t\t\t\t{ type: `transaction`, key: transactionKey },\n\t\t\t\t\tupdateId,\n\t\t\t\t)(...txOutcome.params)\n\t\t\t} catch (thrown) {\n\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`,\n\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\tperformance.mark(performanceKeyEnd)\n\t\t\tconst metric = performance.measure(\n\t\t\t\tperformanceKey,\n\t\t\t\tperformanceKeyStart,\n\t\t\t\tperformanceKeyEnd,\n\t\t\t)\n\t\t\tstore.logger.info(\n\t\t\t\t`🚀`,\n\t\t\t\t`transaction`,\n\t\t\t\ttransactionKey,\n\t\t\t\tupdateId,\n\t\t\t\tuserKey,\n\t\t\t\tmetric.duration,\n\t\t\t)\n\t\t},\n\t)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { getFromStore, setIntoStore } from \"atom.io/internal\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\n\nexport function trackAcknowledgements(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst userUnacknowledgedUpdates = getFromStore(\n\t\tstore,\n\t\tunacknowledgedUpdatesAtoms,\n\t\tuserKey,\n\t)\n\tfunction trackClientAcknowledgement(epoch: number): void {\n\t\tstore.logger.info(\n\t\t\t`👍`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`${userKey} acknowledged epoch ${epoch}`,\n\t\t)\n\t\tconst isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch\n\t\tif (isUnacknowledged) {\n\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\tupdates.shift()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👍`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\tupdates.length,\n\t\t\t\t\t`items`,\n\t\t\t\t)\n\t\t\t\treturn updates\n\t\t\t})\n\t\t}\n\t}\n\treturn employSocket(socket, `ack:${continuityKey}`, trackClientAcknowledgement)\n}\n","import { getFromStore, IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, UserKey } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \"..\"\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\nimport { provideOutcomes } from \"./provide-outcomes\"\nimport { providePerspectives } from \"./provide-perspectives\"\nimport { provideStartupPayloads } from \"./provide-startup-payloads\"\nimport { receiveActionRequests } from \"./receive-action-requests\"\nimport { trackAcknowledgements } from \"./track-acknowledgements\"\n\nexport type ProvideContinuity = (\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n) => () => void\nexport function prepareToProvideContinuity({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig): ProvideContinuity {\n\treturn function syncRealtimeContinuity(continuity, userKey) {\n\t\tconst continuityKey = continuity.key\n\n\t\tconst unacknowledgedUpdates = getFromStore(\n\t\t\tstore,\n\t\t\tunacknowledgedUpdatesAtoms,\n\t\t\tuserKey,\n\t\t)\n\t\tfor (const unacknowledgedUpdate of unacknowledgedUpdates) {\n\t\t\tsocket.emit(\n\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\tunacknowledgedUpdate as Json.Serializable,\n\t\t\t)\n\t\t}\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsubscribe of subscriptions) unsubscribe()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tsubscriptions.add(providePerspectives(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideOutcomes(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideStartupPayloads(store, socket, continuity, userKey))\n\t\tsubscriptions.add(receiveActionRequests(store, socket, continuity, userKey))\n\t\tsubscriptions.add(trackAcknowledgements(store, socket, continuity, userKey))\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { Json, stringified } from \"atom.io/json\"\nimport type { Socket } from \"atom.io/realtime\"\n\nexport type Events = Json.Object<string, Json.Serializable[]>\n\nexport type EventPayload<\n\treceiveRelay extends Events,\n\tK extends string & keyof receiveRelay = string & keyof receiveRelay,\n> = [string, ...receiveRelay[K]]\n\nexport interface EventBuffer<\n\tE extends Events,\n\tK extends string & keyof E = string & keyof E,\n> extends Buffer {\n\ttoString(): stringified<EventPayload<E, K>>\n}\n\nexport abstract class CustomSocket<I extends Events, O extends Events>\n\timplements Socket\n{\n\tprotected listeners: Map<keyof O, Set<(...args: Json.Array) => void>>\n\tprotected globalListeners: Set<(event: string, ...args: Json.Array) => void>\n\tprotected handleEvent<K extends string & keyof I>(\n\t\t...args: EventPayload<I, K>\n\t): void {\n\t\tconst [event, ...rest] = args\n\t\tfor (const listener of this.globalListeners) {\n\t\t\tlistener(event, ...rest)\n\t\t}\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\tlistener(...rest)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic id = `no_id_retrieved`\n\tpublic emit: <Event extends keyof I>(\n\t\tevent: Event,\n\t\t...args: I[Event]\n\t) => CustomSocket<I, O>\n\n\tpublic constructor(\n\t\temit: <Event extends keyof I>(\n\t\t\tevent: Event,\n\t\t\t...args: I[Event]\n\t\t) => CustomSocket<I, O>,\n\t) {\n\t\tthis.emit = emit\n\t\tthis.listeners = new Map()\n\t\tthis.globalListeners = new Set()\n\t}\n\n\tpublic on<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tlisteners.add(listener)\n\t\t} else {\n\t\t\tthis.listeners.set(event, new Set([listener]))\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic onAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.add(listener)\n\t\treturn this\n\t}\n\n\tpublic off<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener?: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tif (listener) {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t} else {\n\t\t\t\tthis.listeners.delete(event)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic offAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.delete(listener)\n\t\treturn this\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport type { Json, stringified } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\n/* eslint-disable no-console */\n\nexport type ChildProcess = {\n\tpid?: number | undefined\n\tstdin: Writable\n\tstdout: Readable\n\tstderr: Readable\n}\n\nexport type StderrLog = [`e` | `i` | `w`, ...Json.Array]\n\nexport class ChildSocket<\n\tI extends Events,\n\tO extends Events,\n\tP extends ChildProcess = ChildProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected incompleteLog = ``\n\tprotected unprocessedLogs: string[] = []\n\n\tpublic id = `#####`\n\n\tpublic proc: P\n\tpublic key: string\n\tpublic logger: Pick<Console, `error` | `info` | `warn`>\n\n\tprotected handleLog(log: StderrLog): void {\n\t\tif (Array.isArray(log)) {\n\t\t\tconst [level, ...rest] = log\n\t\t\tswitch (level) {\n\t\t\t\tcase `i`:\n\t\t\t\t\tthis.logger.info(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `w`:\n\t\t\t\t\tthis.logger.warn(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `e`:\n\t\t\t\t\tthis.logger.error(...rest)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic constructor(\n\t\tproc: P,\n\t\tkey: string,\n\t\tlogger?: Pick<Console, `error` | `info` | `warn`>,\n\t) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args]) + `\\x03`\n\t\t\tconst errorHandler = (err: { code: string }) => {\n\t\t\t\tif (err.code === `EPIPE`) {\n\t\t\t\t\tconsole.error(`EPIPE error during write`, this.proc.stdin)\n\t\t\t\t}\n\t\t\t\tthis.proc.stdin.removeListener(`error`, errorHandler)\n\t\t\t}\n\n\t\t\tthis.proc.stdin.once(`error`, errorHandler)\n\t\t\tthis.proc.stdin.write(stringifiedEvent)\n\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.key = key\n\t\tthis.logger = logger ?? {\n\t\t\tinfo: (...args: unknown[]) => {\n\t\t\t\tconsole.info(this.id, this.key, ...args)\n\t\t\t},\n\t\t\twarn: (...args: unknown[]) => {\n\t\t\t\tconsole.warn(this.id, this.key, ...args)\n\t\t\t},\n\t\t\terror: (...args: unknown[]) => {\n\t\t\t\tconsole.error(this.id, this.key, ...args)\n\t\t\t},\n\t\t}\n\t\tthis.proc.stdout.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\n\t\t\t\tif (chunk === `ALIVE`) {\n\t\t\t\t\tthis.logger.info(chunk)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<EventPayload<I, K>>)\n\t\t\t\t\t\tthis.handleEvent(...jsonPiece)\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<EventPayload<I, K>>,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tthis.handleEvent(...maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.proc.stderr.on(`data`, (buffer: Buffer) => {\n\t\t\tconst chunk = buffer.toString()\n\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\tlet idx = 0\n\t\t\tfor (const piece of pieces) {\n\t\t\t\tif (piece === ``) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<StderrLog>)\n\t\t\t\t\tthis.handleLog(jsonPiece)\n\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t} catch (thrown0) {\n\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t`❌ Malformed log received from child process`,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<StderrLog>,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.handleLog(maybeActualJsonPiece)\n\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed log received from child process...`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++idx\n\t\t\t}\n\t\t})\n\t\tif (proc.pid) {\n\t\t\tthis.id = proc.pid.toString()\n\t\t}\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport { Subject } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\nimport type { UserKey } from \"atom.io/realtime\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nimport type { StderrLog } from \"./child-socket\"\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\nexport class SubjectSocket<\n\tI extends Events,\n\tO extends Events,\n> extends CustomSocket<I, O> {\n\tpublic in: Subject<EventPayload<I>>\n\tpublic out: Subject<EventPayload<O>>\n\tpublic id = `no_id_retrieved`\n\tpublic disposalFunctions: (() => void)[] = []\n\n\tpublic constructor(id: string) {\n\t\tsuper((...args) => {\n\t\t\tthis.out.next(args as any)\n\t\t\treturn this\n\t\t})\n\t\tthis.id = id\n\t\tthis.in = new Subject()\n\t\tthis.out = new Subject()\n\t\tthis.in.subscribe(`socket`, (event) => {\n\t\t\tthis.handleEvent(...event)\n\t\t})\n\t}\n\n\tpublic dispose(): void {\n\t\tfor (const dispose of this.disposalFunctions) {\n\t\t\tdispose()\n\t\t}\n\t}\n}\n\nexport type ParentProcess = {\n\tpid?: number | undefined\n\tstdin: Readable\n\tstdout: Writable\n\tstderr: Writable\n\texit: (code?: number) => void\n}\n\nexport class ParentSocket<\n\tI extends Events & {\n\t\t[id in string as `relay::${id}`]: [string, ...Json.Array[]]\n\t},\n\tO extends Events & {\n\t\t[id in string as `user::${id}`]: [string, ...Json.Array[]]\n\t} & {\n\t\t/* eslint-disable quotes */\n\t\t\"user-joins\": [key: UserKey]\n\t\t\"user-leaves\": [key: UserKey]\n\t\t/* eslint-enable quotes */\n\t},\n\tP extends ParentProcess = ParentProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected relays: Map<string, SubjectSocket<any, any>>\n\tprotected relayServices: ((\n\t\tsocket: SubjectSocket<any, any>,\n\t\tuserKey: UserKey,\n\t) => (() => void) | void)[]\n\tpublic proc: P\n\n\tpublic id = `#####`\n\n\tprotected log(...args: StderrLog): void {\n\t\tthis.proc.stderr.write(\n\t\t\tstringifyJson(\n\t\t\t\targs.map((arg) =>\n\t\t\t\t\targ instanceof UList ? `{ ${arg.toJSON().join(` | `)} }` : arg,\n\t\t\t\t),\n\t\t\t) + `\\x03`,\n\t\t)\n\t}\n\tpublic logger = {\n\t\tinfo: (...args: Json.Array): void => {\n\t\t\tthis.log(`i`, ...args)\n\t\t},\n\t\twarn: (...args: Json.Array): void => {\n\t\t\tthis.log(`w`, ...args)\n\t\t},\n\t\terror: (...args: Json.Array): void => {\n\t\t\tthis.log(`e`, ...args)\n\t\t},\n\t}\n\n\tpublic constructor(proc: P) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args])\n\t\t\tthis.proc.stdout.write(stringifiedEvent + `\\x03`)\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.proc.stdin.resume()\n\t\tthis.relays = new Map()\n\t\tthis.relayServices = []\n\n\t\tthis.proc.stdin.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece)\n\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, jsonPiece)\n\t\t\t\t\t\tthis.handleEvent(...(jsonPiece as EventPayload<I>))\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(initialMaybeWellFormed)\n\t\t\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.handleEvent(...(maybeActualJsonPiece as EventPayload<I>))\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\n\t\tthis.on(`exit`, () => {\n\t\t\tthis.logger.info(`🔥`, this.id, `received \"exit\"`)\n\t\t\tthis.proc.exit(0)\n\t\t})\n\n\t\tif (this.proc.pid) {\n\t\t\tthis.id = this.proc.pid?.toString()\n\t\t}\n\n\t\tthis.on(`user-joins`, (username: string) => {\n\t\t\tthis.logger.info(`👤`, `user`, username, `joined`)\n\t\t\tconst userKey = `user::${username}` satisfies UserKey\n\t\t\tconst relay = new SubjectSocket(userKey)\n\t\t\tthis.relays.set(username, relay)\n\t\t\tthis.logger.info(\n\t\t\t\t`🔗`,\n\t\t\t\t`attaching services:`,\n\t\t\t\t`[${[...this.relayServices.keys()].join(`, `)}]`,\n\t\t\t)\n\t\t\tfor (const attachRelay of this.relayServices) {\n\t\t\t\tconst cleanupRelay = attachRelay(relay, userKey)\n\t\t\t\tif (cleanupRelay) {\n\t\t\t\t\trelay.disposalFunctions.push(cleanupRelay)\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.on(userKey, (...data) => {\n\t\t\t\trelay.in.next(data)\n\t\t\t})\n\t\t\trelay.out.subscribe(`socket`, (data) => {\n\t\t\t\tthis.emit(...(data as [string, ...I[keyof I]]))\n\t\t\t})\n\t\t})\n\n\t\tthis.on(`user-leaves`, (username) => {\n\t\t\tconst relay = this.relays.get(username)\n\t\t\tthis.off(`relay:${username}`)\n\t\t\tif (relay) {\n\t\t\t\trelay.dispose()\n\t\t\t\tthis.relays.delete(username)\n\t\t\t}\n\t\t})\n\n\t\tthis.proc.stdout.write(`ALIVE`)\n\t}\n\n\tpublic receiveRelay(\n\t\tattachServices: (\n\t\t\tsocket: SubjectSocket<any, any>,\n\t\t\tuserKey: UserKey,\n\t\t) => (() => void) | void,\n\t): void {\n\t\tthis.logger.info(`🔗`, `running relay method`)\n\t\tthis.relayServices.push(attachServices)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, Json, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>\nexport function realtimeAtomFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function familyProvider<\n\t\tJ extends Json.Serializable,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.RegularAtomFamilyToken<J, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\ttoken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst isAvailable = (exposedSubKeys: Iterable<K>, subKey: K): boolean => {\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nconst isAvailable = <K extends Canonical>(\n\texposedSubKeys: Iterable<K>,\n\tsubKey: K,\n): boolean => {\n\tfor (const exposedSubKey of exposedSubKeys) {\n\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nexport type MutableFamilyProvider = ReturnType<\n\ttypeof realtimeMutableFamilyProvider\n>\nexport function realtimeMutableFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableFamilyProvider<\n\t\tT extends Transceiver<any, any, any>,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tconst jsonToken = getJsonToken(store, token)\n\t\t\tconst updateToken = getUpdateToken(token)\n\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tupdateToken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type MutableProvider = ReturnType<typeof realtimeMutableProvider>\nexport function realtimeMutableProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableProvider<\n\t\tCore extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\t>(token: AtomIO.MutableAtomToken<Core>): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tconst trackerToken = getUpdateToken(token)\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttrackerToken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type {\n\tHierarchy,\n\tJoinToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport { atomFamily, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport type { RoomKey, Socket, SocketKey, UserKey } from \"atom.io/realtime\"\nimport { isSocketKey, isUserKey } from \"atom.io/realtime\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nexport type SocketSystemHierarchy = Hierarchy<\n\t[\n\t\t{\n\t\t\tabove: `root`\n\t\t\tbelow: [UserKey, SocketKey, RoomKey]\n\t\t},\n\t]\n>\n\nexport const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =\n\tatomFamily({\n\t\tkey: `sockets`,\n\t\tdefault: null,\n\t})\n\nexport const socketKeysAtom: MutableAtomToken<UList<SocketKey>> = mutableAtom({\n\tkey: `socketsIndex`,\n\tclass: UList,\n})\nexport const userKeysAtom: MutableAtomToken<UList<UserKey>> = mutableAtom({\n\tkey: `usersIndex`,\n\tclass: UList,\n})\nexport const usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n> = join({\n\tkey: `usersOfSockets`,\n\tbetween: [`user`, `socket`],\n\tcardinality: `1:1`,\n\tisAType: isUserKey,\n\tisBType: isSocketKey,\n})\n\nexport const selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey> =\n\tselectorFamily({\n\t\tkey: `selfList`,\n\t\tget: (userId) => () => [userId],\n\t})\n","import type { ChildProcessWithoutNullStreams } from \"node:child_process\"\nimport { spawn } from \"node:child_process\"\n\nimport type { Store } from \"atom.io/internal\"\nimport {\n\teditRelationsInStore,\n\tfindInStore,\n\tfindRelationsInStore,\n\tgetFromStore,\n\tgetInternalRelationsFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { RoomKey, Socket, SocketKey, UserKey } from \"atom.io/realtime\"\nimport { roomKeysAtom, usersInRooms } from \"atom.io/realtime\"\n\nimport { ChildSocket } from \"../ipc-sockets\"\nimport { realtimeMutableFamilyProvider } from \"../realtime-mutable-family-provider\"\nimport { realtimeMutableProvider } from \"../realtime-mutable-provider\"\nimport type { ServerConfig } from \"../server-config\"\nimport {\n\tselfListSelectors,\n\tsocketKeysAtom,\n\tuserKeysAtom,\n\tusersOfSockets,\n} from \"./server-user-store\"\n\nexport type RoomMap = Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>\n\ndeclare global {\n\tvar ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap\n}\n\nexport const ROOMS: RoomMap =\n\tglobalThis.ATOM_IO_REALTIME_SERVER_ROOMS ??\n\t(globalThis.ATOM_IO_REALTIME_SERVER_ROOMS = new Map())\n\nexport const roomMeta: { count: number } = { count: 0 }\n\nexport async function spawnRoom(\n\tstore: Store,\n\troomKey: RoomKey,\n\tcommand: string,\n\targs: string[],\n): Promise<ChildSocket<any, any>> {\n\tconst child = await new Promise<ChildProcessWithoutNullStreams>((resolve) => {\n\t\tconst room = spawn(command, args, { env: process.env })\n\t\tconst resolver = (data: Buffer) => {\n\t\t\tif (data.toString() === `ALIVE`) {\n\t\t\t\troom.stdout.off(`data`, resolver)\n\t\t\t\tresolve(room)\n\t\t\t}\n\t\t}\n\t\troom.stdout.on(`data`, resolver)\n\t})\n\tconst roomSocket = new ChildSocket(child, roomKey)\n\tROOMS.set(roomKey, roomSocket)\n\tsetIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index))\n\n\troomSocket.on(`close`, () => {\n\t\tdestroyRoom(store, roomKey)\n\t})\n\n\treturn roomSocket\n}\n\nexport function joinRoom(\n\tstore: Store,\n\troomKey: RoomKey,\n\tuserKey: UserKey,\n\tsocket: Socket,\n): {\n\tleave: () => void\n\troomSocket: ChildSocket<any, any, ChildProcessWithoutNullStreams>\n} | null {\n\tconst roomQueue: [string, ...Json.Array][] = []\n\tconst pushToRoomQueue = (payload: [string, ...Json.Array]): void => {\n\t\troomQueue.push(payload)\n\t}\n\tlet toRoom = pushToRoomQueue\n\tconst forward = (...payload: [string, ...Json.Array]) => {\n\t\ttoRoom(payload)\n\t}\n\tsocket.onAny(forward)\n\n\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\trelations.set({ room: roomKey, user: userKey })\n\t})\n\tconst roomSocket = ROOMS.get(roomKey)\n\tif (!roomSocket) {\n\t\tstore.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`)\n\t\treturn null\n\t}\n\troomSocket.onAny((...payload) => {\n\t\tsocket.emit(...payload)\n\t})\n\troomSocket.emit(`user-joins`, userKey)\n\n\ttoRoom = (payload) => {\n\t\troomSocket.emit(`user::${userKey}`, ...payload)\n\t}\n\twhile (roomQueue.length > 0) {\n\t\tconst payload = roomQueue.shift()\n\t\tif (payload) toRoom(payload)\n\t}\n\n\tconst leave = () => {\n\t\tsocket.offAny(forward)\n\t\ttoRoom([`user-leaves`])\n\t\tleaveRoom(store, roomKey, userKey)\n\t}\n\n\treturn { leave, roomSocket }\n}\n\nexport function leaveRoom(\n\tstore: Store,\n\troomKey: RoomKey,\n\tuserKey: UserKey,\n): void {\n\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\trelations.delete({ room: roomKey, user: userKey })\n\t})\n}\n\nexport function destroyRoom(store: Store, roomKey: RoomKey): void {\n\tsetIntoStore(store, roomKeysAtom, (s) => (s.delete(roomKey), s))\n\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\trelations.delete({ room: roomKey })\n\t})\n\tconst room = ROOMS.get(roomKey)\n\tif (room) {\n\t\troom.emit(`exit`)\n\t\tROOMS.delete(roomKey)\n\t}\n}\n\nexport function provideRooms<RoomNames extends string>(\n\t{ store = IMPLICIT.STORE, socket }: ServerConfig,\n\tresolveRoomScript: (path: string) => [string, string[]],\n): void {\n\tconst socketKey = `socket::${socket.id}` satisfies SocketKey\n\tconst userKey = getFromStore(\n\t\tstore,\n\t\tfindRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket,\n\t)!\n\n\tconst exposeMutable = realtimeMutableProvider({ socket, store })\n\tconst exposeMutableFamily = realtimeMutableFamilyProvider({\n\t\tsocket,\n\t\tstore,\n\t})\n\n\texposeMutable(roomKeysAtom)\n\n\tconst usersInRoomsAtoms = getInternalRelationsFromStore(store, usersInRooms)\n\tconst usersWhoseRoomsCanBeSeenSelector = findInStore(\n\t\tstore,\n\t\tselfListSelectors,\n\t\tuserKey,\n\t)\n\texposeMutableFamily(usersInRoomsAtoms, usersWhoseRoomsCanBeSeenSelector)\n\tconst usersOfSocketsAtoms = getInternalRelationsFromStore(\n\t\tstore,\n\t\tusersOfSockets,\n\t)\n\texposeMutableFamily(usersOfSocketsAtoms, socketKeysAtom)\n\n\tsocket.on(`createRoom`, async (roomName: RoomNames) => {\n\t\t// logger.info(`[${shortId}]:${username}`, `creating room \"${roomId}\"`)\n\t\tconst roomId = `room::${roomMeta.count++}` satisfies RoomKey\n\t\tawait spawnRoom(store, roomId, ...resolveRoomScript(roomName))\n\t\tsocket.on(`deleteRoom:${roomId}`, () => {\n\t\t\t// logger.info(`[${shortId}]:${username}`, `deleting room \"${roomId}\"`)\n\t\t\tdestroyRoom(store, roomId)\n\t\t})\n\t})\n\n\tsocket.on(`joinRoom`, (roomKey: RoomKey) => {\n\t\t// logger.info(`[${shortId}]:${username}`, `joining room \"${roomId}\"`)\n\t\tconst { leave } = joinRoom(store, roomKey, userKey, socket)!\n\t\tsocket.on(`leaveRoom:${roomKey}`, leave)\n\t})\n\n\tsocket.on(`disconnect`, () => {\n\t\teditRelationsInStore(store, usersOfSockets, (relations) =>\n\t\t\trelations.delete(socketKey),\n\t\t)\n\t\tif (userKey) {\n\t\t\tsetIntoStore(\n\t\t\t\tstore,\n\t\t\t\tuserKeysAtom,\n\t\t\t\t(index) => (index.delete(userKey), index),\n\t\t\t)\n\t\t}\n\t\tsetIntoStore(\n\t\t\tstore,\n\t\t\tsocketKeysAtom,\n\t\t\t(index) => (index.delete(socketKey), index),\n\t\t)\n\t\t// logger.info(`${socket.id} disconnected`)\n\t})\n}\n","import type * as AtomIO from \"atom.io\"\nimport { getFromStore, IMPLICIT, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateProvider = ReturnType<typeof realtimeStateProvider>\nexport function realtimeStateProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateProvider<J extends Json.Serializable>(\n\t\ttoken: AtomIO.WritableToken<J>,\n\t): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { WritableToken } from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\toperateOnStore,\n\tOWN_OP,\n\tsetIntoStore,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket, mutexAtoms } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateReceiver = ReturnType<typeof realtimeStateReceiver>\nexport function realtimeStateReceiver({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateReceiver<S extends Json.Serializable, C extends S>(\n\t\tclientToken: WritableToken<C>,\n\t\tserverToken: WritableToken<S> = clientToken,\n\t): () => void {\n\t\tconst mutexAtom = findInStore(store, mutexAtoms, serverToken.key)\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst permitPublish = () => {\n\t\t\tclearSubscriptions()\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `pub:${clientToken.key}`, (newValue) => {\n\t\t\t\t\tsetIntoStore(store, serverToken, newValue as C)\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `unclaim:${clientToken.key}`, () => {\n\t\t\t\t\tsetIntoStore(store, mutexAtom, false)\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tstart()\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `claim:${clientToken.key}`, () => {\n\t\t\t\t\tif (getFromStore(store, mutexAtom)) {\n\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\t\tsubscribeToState(store, mutexAtom, socket.id!, () => {\n\t\t\t\t\t\t\t\tconst currentValue = getFromStore(store, mutexAtom)\n\t\t\t\t\t\t\t\tif (currentValue === false) {\n\t\t\t\t\t\t\t\t\toperateOnStore(OWN_OP, store, mutexAtom, true)\n\t\t\t\t\t\t\t\t\tpermitPublish()\n\t\t\t\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, false)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, mutexAtom, true)\n\t\t\t\t\tpermitPublish()\n\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,+BACf,kBACA,SACwB;AACxB,QAAO,QACL,KAAK,WAAgC;AACrC,UAAQ,OAAO,MAAf;GACC,KAAK,uBAAuB;IAC3B,MAAM,WAAW,+BAChB,kBACA,OAAO,UACP;AACD,WAAO;KAAE,GAAG;KAAQ,WAAW;KAAU;;GAE1C,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK,iBACJ,QAAO;;GAER,CACD,QAAQ,WAAW;AACnB,UAAQ,OAAO,MAAf;GACC,KAAK;GACL,KAAK;GACL,KAAK,iBACJ,QAAO,iBAAiB,SAAS,OAAO,MAAM,IAAI;GACnD,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK,oBACJ,QAAO;;GAER;;AAGJ,MAAaA,gBAKT,WAAW;CACd,KAAK;CACL,SAAS,EAAE,UAAU,YAAY,SAAS;CAC1C,CAAC;AAMF,MAAaC,6BAGT,WAAW;CACd,KAAK;CACL,eAAe,EAAE;CACjB,CAAC;;;;AClDF,SAAgB,gBACf,OACA,QACA,YACA,SACa;CACb,MAAM,gBAAgB,WAAW;CACjC,MAAM,uCAAuB,IAAI,KAAiB;AAElD,MAAK,MAAM,eAAe,WAAW,SAAS;EAC7C,MAAM,6BAA6B,uBAClC,OACA,aACA,mBAAmB,cAAc,GAAG,YACnC,aAAa;AACb,OAAI;IA2BH,MAAM,kBAAkB,+BA1BJ,WAAW,QAC7B,KAAK,SAAS;AACd,SAAI,KAAK,SAAS,OACjB,QAAO,KAAK;AAE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AW,OAAO,UAAW;AAEpD,UADqB,aAAa,OAAO,UAAU,KAC9B,OAAO;AAC3B,sBAAe,QAAQ,OAAO,WAAW,KAAK;AAC9C,sBAAe;AACf,cAAO,KAAK,gBAAgB,YAAY,OAAO,KAAK;;OAEpD,CACF;AACD,YAAO,KAAK,gBAAgB,YAAY,OAAO,MAAM;AACrD;;AAED,iBAAa,OAAO,WAAW,KAAK;AACpC,mBAAe;AACf,WAAO,KAAK,gBAAgB,YAAY,OAAO,KAAK;KACnD,CACF;;AAGF,SAAO;AAEP,SAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>","unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n>","initialPayload: Json.Serializable[]","isAvailable","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","userKeysAtom: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey>","ROOMS: RoomMap","roomMeta: { count: number }","roomQueue: [string, ...Json.Array][]","forward: AllEventsListener<EventsMap>"],"sources":["../../src/realtime-server/continuity/continuity-store.ts","../../src/realtime-server/continuity/provide-outcomes.ts","../../src/realtime-server/continuity/provide-perspectives.ts","../../src/realtime-server/continuity/provide-startup-payloads.ts","../../src/realtime-server/continuity/receive-action-requests.ts","../../src/realtime-server/continuity/track-acknowledgements.ts","../../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/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-server-stores/server-user-store.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts"],"sourcesContent":["import type {\n\tRegularAtomFamilyToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n} from \"atom.io\"\nimport { atomFamily } from \"atom.io\"\nimport type { UserKey } from \"atom.io/realtime\"\n\nexport function redactTransactionUpdateContent(\n\tvisibleStateKeys: string[],\n\tupdates: TransactionSubEvent[],\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.map((update): TransactionSubEvent => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `transaction_outcome`: {\n\t\t\t\t\tconst redacted = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleStateKeys,\n\t\t\t\t\t\tupdate.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\treturn { ...update, subEvents: redacted }\n\t\t\t\t}\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn update\n\t\t\t}\n\t\t})\n\t\t.filter((update) => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn visibleStateKeys.includes(update.token.key)\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `transaction_outcome`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true\n\t\t\t}\n\t\t})\n}\n\nexport const redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n> = atomFamily({\n\tkey: `redactor`,\n\tdefault: { occlude: (updates) => updates },\n})\n\nexport type ContinuitySyncTransactionUpdate = Pick<\n\tTransactionOutcomeEvent<any>,\n\t`epoch` | `id` | `output` | `subEvents` | `token`\n>\nexport const unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n> = atomFamily({\n\tkey: `unacknowledgedUpdates`,\n\tdefault: () => [],\n})\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetUpdateToken,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\n\nimport {\n\tredactTransactionUpdateContent,\n\tunacknowledgedUpdatesAtoms,\n} from \"./continuity-store\"\n\nexport function provideOutcomes(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubscribeFunctions = new Set<() => void>()\n\n\tfor (const transaction of continuity.actions) {\n\t\tconst unsubscribeFromTransaction = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}`,\n\t\t\t(outcomes) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst visibleKeys = continuity.globals\n\t\t\t\t\t\t.map((atom) => {\n\t\t\t\t\t\t\tif (atom.type === `atom`) {\n\t\t\t\t\t\t\t\treturn atom.key\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn getUpdateToken(atom).key\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.concat(\n\t\t\t\t\t\t\tcontinuity.perspectives.flatMap((perspective) => {\n\t\t\t\t\t\t\t\tconst { viewAtoms } = perspective\n\t\t\t\t\t\t\t\tconst userPerspectiveTokenState = findInStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tviewAtoms,\n\t\t\t\t\t\t\t\t\tuserKey,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst visibleTokens = getFromStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tuserPerspectiveTokenState,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn visibleTokens.map((token) => {\n\t\t\t\t\t\t\t\t\tconst key =\n\t\t\t\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? `*` + token.key : token.key\n\t\t\t\t\t\t\t\t\treturn key\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdates = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleKeys,\n\t\t\t\t\t\toutcomes.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdate = {\n\t\t\t\t\t\t...outcomes,\n\t\t\t\t\t\tupdates: redactedUpdates,\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\t\t\tif (redactedUpdate) {\n\t\t\t\t\t\t\tupdates.push(redactedUpdate)\n\t\t\t\t\t\t\tupdates.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\t\t\t\tupdates.length,\n\t\t\t\t\t\t\t\t`items`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn updates\n\t\t\t\t\t})\n\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\t\t\tredactedUpdate as Json.Serializable,\n\t\t\t\t\t)\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t`${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`,\n\t\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubscribeFunctions.add(unsubscribeFromTransaction)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\n\nexport function providePerspectives(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubFns = new Set<() => void>()\n\tfor (const perspective of continuity.perspectives) {\n\t\tconst { viewAtoms } = perspective\n\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\tconst unsubscribeFromUserView = subscribeToState(\n\t\t\tstore,\n\t\t\tuserViewState,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,\n\t\t\t({ oldValue, newValue }) => {\n\t\t\t\tconst oldKeys = oldValue?.map((token) => token.key)\n\t\t\t\tconst newKeys = newValue.map((token) => token.key)\n\t\t\t\tconst concealed = oldValue?.filter(\n\t\t\t\t\t(token) => !newKeys.includes(token.key),\n\t\t\t\t)\n\t\t\t\tconst revealed = newValue\n\t\t\t\t\t.filter((token) => !oldKeys?.includes(token.key))\n\t\t\t\t\t.flatMap((token) => {\n\t\t\t\t\t\tconst resourceToken =\n\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? getJsonToken(store, token) : token\n\t\t\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\t\t\t\treturn [resourceToken, resource]\n\t\t\t\t\t})\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👁`,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tperspective.resourceAtoms.key,\n\t\t\t\t\t`${userKey} has a new perspective`,\n\t\t\t\t\t{ oldKeys, newKeys, revealed, concealed },\n\t\t\t\t)\n\t\t\t\tif (revealed.length > 0) {\n\t\t\t\t\tsocket.emit(`reveal:${continuityKey}`, revealed)\n\t\t\t\t}\n\t\t\t\tif (concealed && concealed.length > 0) {\n\t\t\t\t\tsocket.emit(`conceal:${continuityKey}`, concealed)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubFns.add(unsubscribeFromUserView)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubFns) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tisRootStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nexport function provideStartupPayloads(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tfunction sendInitialPayload(): void {\n\t\tconst initialPayload: Json.Serializable[] = []\n\t\tfor (const atom of continuity.globals) {\n\t\t\tconst resourceToken =\n\t\t\t\tatom.type === `mutable_atom` ? getJsonToken(store, atom) : atom\n\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t}\n\t\tfor (const perspective of continuity.perspectives) {\n\t\t\tconst { viewAtoms, resourceAtoms } = perspective\n\t\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\t\tconst userView = getFromStore(store, userViewState)\n\t\t\tstore.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {\n\t\t\t\tviewAtoms,\n\t\t\t\tresourceAtoms,\n\t\t\t\tuserView,\n\t\t\t})\n\t\t\tfor (const visibleToken of userView) {\n\t\t\t\tconst resourceToken =\n\t\t\t\t\tvisibleToken.type === `mutable_atom`\n\t\t\t\t\t\t? getJsonToken(store, visibleToken)\n\t\t\t\t\t\t: visibleToken\n\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\n\t\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t\t}\n\t\t}\n\n\t\tconst epoch = isRootStore(store)\n\t\t\t? (store.transactionMeta.epoch.get(continuityKey) ?? null)\n\t\t\t: null\n\n\t\tsocket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload)\n\t}\n\treturn employSocket(socket, `get:${continuityKey}`, sendInitialPayload)\n}\n","import type { TransactionOutcomeEvent, TransactionToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { actUponStore } from \"atom.io/internal\"\nimport type { Json, JsonIO } from \"atom.io/json\"\nimport type { ContinuityToken, Socket } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nexport function receiveActionRequests(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: string,\n): () => void {\n\tconst continuityKey = continuity.key\n\n\treturn employSocket(\n\t\tsocket,\n\t\t`tx-run:${continuityKey}`,\n\t\tfunction serveTransactionRequest(\n\t\t\ttxOutcome: Json.Serializable &\n\t\t\t\tPick<\n\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<JsonIO>>,\n\t\t\t\t\t`id` | `params` | `token`\n\t\t\t\t>,\n\t\t) {\n\t\t\tstore.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)\n\t\t\tconst transactionKey = txOutcome.token.key\n\t\t\tconst updateId = txOutcome.id\n\t\t\tconst performanceKey = `tx-run:${transactionKey}:${updateId}`\n\t\t\tconst performanceKeyStart = `${performanceKey}:start`\n\t\t\tconst performanceKeyEnd = `${performanceKey}:end`\n\t\t\tperformance.mark(performanceKeyStart)\n\t\t\ttry {\n\t\t\t\tactUponStore(\n\t\t\t\t\tstore,\n\t\t\t\t\t{ type: `transaction`, key: transactionKey },\n\t\t\t\t\tupdateId,\n\t\t\t\t)(...txOutcome.params)\n\t\t\t} catch (thrown) {\n\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`,\n\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\tperformance.mark(performanceKeyEnd)\n\t\t\tconst metric = performance.measure(\n\t\t\t\tperformanceKey,\n\t\t\t\tperformanceKeyStart,\n\t\t\t\tperformanceKeyEnd,\n\t\t\t)\n\t\t\tstore.logger.info(\n\t\t\t\t`🚀`,\n\t\t\t\t`transaction`,\n\t\t\t\ttransactionKey,\n\t\t\t\tupdateId,\n\t\t\t\tuserKey,\n\t\t\t\tmetric.duration,\n\t\t\t)\n\t\t},\n\t)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { getFromStore, setIntoStore } from \"atom.io/internal\"\nimport type { ContinuityToken, Socket, UserKey } from \"atom.io/realtime\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\n\nexport function trackAcknowledgements(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst userUnacknowledgedUpdates = getFromStore(\n\t\tstore,\n\t\tunacknowledgedUpdatesAtoms,\n\t\tuserKey,\n\t)\n\tfunction trackClientAcknowledgement(epoch: number): void {\n\t\tstore.logger.info(\n\t\t\t`👍`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`${userKey} acknowledged epoch ${epoch}`,\n\t\t)\n\t\tconst isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch\n\t\tif (isUnacknowledged) {\n\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\tupdates.shift()\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👍`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\tupdates.length,\n\t\t\t\t\t`items`,\n\t\t\t\t)\n\t\t\t\treturn updates\n\t\t\t})\n\t\t}\n\t}\n\treturn employSocket(socket, `ack:${continuityKey}`, trackClientAcknowledgement)\n}\n","import { getFromStore, IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken, UserKey } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \"..\"\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\nimport { provideOutcomes } from \"./provide-outcomes\"\nimport { providePerspectives } from \"./provide-perspectives\"\nimport { provideStartupPayloads } from \"./provide-startup-payloads\"\nimport { receiveActionRequests } from \"./receive-action-requests\"\nimport { trackAcknowledgements } from \"./track-acknowledgements\"\n\nexport type ProvideContinuity = (\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n) => () => void\nexport function prepareToProvideContinuity({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig): ProvideContinuity {\n\treturn function syncRealtimeContinuity(continuity, userKey) {\n\t\tconst continuityKey = continuity.key\n\n\t\tconst unacknowledgedUpdates = getFromStore(\n\t\t\tstore,\n\t\t\tunacknowledgedUpdatesAtoms,\n\t\t\tuserKey,\n\t\t)\n\t\tfor (const unacknowledgedUpdate of unacknowledgedUpdates) {\n\t\t\tsocket.emit(\n\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\tunacknowledgedUpdate as Json.Serializable,\n\t\t\t)\n\t\t}\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsubscribe of subscriptions) unsubscribe()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tsubscriptions.add(providePerspectives(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideOutcomes(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideStartupPayloads(store, socket, continuity, userKey))\n\t\tsubscriptions.add(receiveActionRequests(store, socket, continuity, userKey))\n\t\tsubscriptions.add(trackAcknowledgements(store, socket, continuity, userKey))\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { Json, stringified } from \"atom.io/json\"\nimport type { Socket } from \"atom.io/realtime\"\n\nexport type Events = Json.Object<string, Json.Serializable[]>\n\nexport type EventPayload<\n\treceiveRelay extends Events,\n\tK extends string & keyof receiveRelay = string & keyof receiveRelay,\n> = [string, ...receiveRelay[K]]\n\nexport interface EventBuffer<\n\tE extends Events,\n\tK extends string & keyof E = string & keyof E,\n> extends Buffer {\n\ttoString(): stringified<EventPayload<E, K>>\n}\n\nexport abstract class CustomSocket<I extends Events, O extends Events>\n\timplements Socket\n{\n\tprotected listeners: Map<keyof O, Set<(...args: Json.Array) => void>>\n\tprotected globalListeners: Set<(event: string, ...args: Json.Array) => void>\n\tprotected handleEvent<K extends string & keyof I>(\n\t\t...args: EventPayload<I, K>\n\t): void {\n\t\tconst [event, ...rest] = args\n\t\tfor (const listener of this.globalListeners) {\n\t\t\tlistener(event, ...rest)\n\t\t}\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\tlistener(...rest)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic id = `no_id_retrieved`\n\tpublic emit: <Event extends keyof I>(\n\t\tevent: Event,\n\t\t...args: I[Event]\n\t) => CustomSocket<I, O>\n\n\tpublic constructor(\n\t\temit: <Event extends keyof I>(\n\t\t\tevent: Event,\n\t\t\t...args: I[Event]\n\t\t) => CustomSocket<I, O>,\n\t) {\n\t\tthis.emit = emit\n\t\tthis.listeners = new Map()\n\t\tthis.globalListeners = new Set()\n\t}\n\n\tpublic on<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tlisteners.add(listener)\n\t\t} else {\n\t\t\tthis.listeners.set(event, new Set([listener]))\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic onAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.add(listener)\n\t\treturn this\n\t}\n\n\tpublic off<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener?: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tif (listener) {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t} else {\n\t\t\t\tthis.listeners.delete(event)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic offAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.delete(listener)\n\t\treturn this\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport type { Json, stringified } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\n/* eslint-disable no-console */\n\nexport type ChildProcess = {\n\tpid?: number | undefined\n\tstdin: Writable\n\tstdout: Readable\n\tstderr: Readable\n}\n\nexport type StderrLog = [`e` | `i` | `w`, ...Json.Array]\n\nexport class ChildSocket<\n\tI extends Events,\n\tO extends Events,\n\tP extends ChildProcess = ChildProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected incompleteLog = ``\n\tprotected unprocessedLogs: string[] = []\n\n\tpublic id = `#####`\n\n\tpublic proc: P\n\tpublic key: string\n\tpublic logger: Pick<Console, `error` | `info` | `warn`>\n\n\tprotected handleLog(log: StderrLog): void {\n\t\tif (Array.isArray(log)) {\n\t\t\tconst [level, ...rest] = log\n\t\t\tswitch (level) {\n\t\t\t\tcase `i`:\n\t\t\t\t\tthis.logger.info(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `w`:\n\t\t\t\t\tthis.logger.warn(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `e`:\n\t\t\t\t\tthis.logger.error(...rest)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic constructor(\n\t\tproc: P,\n\t\tkey: string,\n\t\tlogger?: Pick<Console, `error` | `info` | `warn`>,\n\t) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args]) + `\\x03`\n\t\t\tconst errorHandler = (err: { code: string }) => {\n\t\t\t\tif (err.code === `EPIPE`) {\n\t\t\t\t\tconsole.error(`EPIPE error during write`, this.proc.stdin)\n\t\t\t\t}\n\t\t\t\tthis.proc.stdin.removeListener(`error`, errorHandler)\n\t\t\t}\n\n\t\t\tthis.proc.stdin.once(`error`, errorHandler)\n\t\t\tthis.proc.stdin.write(stringifiedEvent)\n\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.key = key\n\t\tthis.logger = logger ?? {\n\t\t\tinfo: (...args: unknown[]) => {\n\t\t\t\tconsole.info(this.id, this.key, ...args)\n\t\t\t},\n\t\t\twarn: (...args: unknown[]) => {\n\t\t\t\tconsole.warn(this.id, this.key, ...args)\n\t\t\t},\n\t\t\terror: (...args: unknown[]) => {\n\t\t\t\tconsole.error(this.id, this.key, ...args)\n\t\t\t},\n\t\t}\n\t\tthis.proc.stdout.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\n\t\t\t\tif (chunk === `ALIVE`) {\n\t\t\t\t\tthis.logger.info(chunk)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<EventPayload<I, K>>)\n\t\t\t\t\t\tthis.handleEvent(...jsonPiece)\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<EventPayload<I, K>>,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tthis.handleEvent(...maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.proc.stderr.on(`data`, (buffer: Buffer) => {\n\t\t\tconst chunk = buffer.toString()\n\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\tlet idx = 0\n\t\t\tfor (const piece of pieces) {\n\t\t\t\tif (piece === ``) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<StderrLog>)\n\t\t\t\t\tthis.handleLog(jsonPiece)\n\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t} catch (thrown0) {\n\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t`❌ Malformed log received from child process`,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<StderrLog>,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.handleLog(maybeActualJsonPiece)\n\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed log received from child process...`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++idx\n\t\t\t}\n\t\t})\n\t\tif (proc.pid) {\n\t\t\tthis.id = proc.pid.toString()\n\t\t}\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport { Subject } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\nimport type { UserKey } from \"atom.io/realtime\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nimport type { StderrLog } from \"./child-socket\"\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\nexport class SubjectSocket<\n\tI extends Events,\n\tO extends Events,\n> extends CustomSocket<I, O> {\n\tpublic in: Subject<EventPayload<I>>\n\tpublic out: Subject<EventPayload<O>>\n\tpublic id = `no_id_retrieved`\n\tpublic disposalFunctions: (() => void)[] = []\n\n\tpublic constructor(id: string) {\n\t\tsuper((...args) => {\n\t\t\tthis.out.next(args as any)\n\t\t\treturn this\n\t\t})\n\t\tthis.id = id\n\t\tthis.in = new Subject()\n\t\tthis.out = new Subject()\n\t\tthis.in.subscribe(`socket`, (event) => {\n\t\t\tthis.handleEvent(...event)\n\t\t})\n\t}\n\n\tpublic dispose(): void {\n\t\tfor (const dispose of this.disposalFunctions) {\n\t\t\tdispose()\n\t\t}\n\t}\n}\n\nexport type ParentProcess = {\n\tpid?: number | undefined\n\tstdin: Readable\n\tstdout: Writable\n\tstderr: Writable\n\texit: (code?: number) => void\n}\n\nexport class ParentSocket<\n\tI extends Events & {\n\t\t[id in string as `relay::${id}`]: [string, ...Json.Array[]]\n\t},\n\tO extends Events & {\n\t\t[id in string as `user::${id}`]: [string, ...Json.Array[]]\n\t} & {\n\t\t/* eslint-disable quotes */\n\t\t\"user-joins\": [key: UserKey]\n\t\t\"user-leaves\": [key: UserKey]\n\t\t/* eslint-enable quotes */\n\t},\n\tP extends ParentProcess = ParentProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected relays: Map<string, SubjectSocket<any, any>>\n\tprotected relayServices: ((\n\t\tsocket: SubjectSocket<any, any>,\n\t\tuserKey: UserKey,\n\t) => (() => void) | void)[]\n\tpublic proc: P\n\n\tpublic id = `#####`\n\n\tprotected log(...args: StderrLog): void {\n\t\tthis.proc.stderr.write(\n\t\t\tstringifyJson(\n\t\t\t\targs.map((arg) =>\n\t\t\t\t\targ instanceof UList ? `{ ${arg.toJSON().join(` | `)} }` : arg,\n\t\t\t\t),\n\t\t\t) + `\\x03`,\n\t\t)\n\t}\n\tpublic logger = {\n\t\tinfo: (...args: Json.Array): void => {\n\t\t\tthis.log(`i`, ...args)\n\t\t},\n\t\twarn: (...args: Json.Array): void => {\n\t\t\tthis.log(`w`, ...args)\n\t\t},\n\t\terror: (...args: Json.Array): void => {\n\t\t\tthis.log(`e`, ...args)\n\t\t},\n\t}\n\n\tpublic constructor(proc: P) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args])\n\t\t\tthis.proc.stdout.write(stringifiedEvent + `\\x03`)\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.proc.stdin.resume()\n\t\tthis.relays = new Map()\n\t\tthis.relayServices = []\n\n\t\tthis.proc.stdin.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece)\n\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, jsonPiece)\n\t\t\t\t\t\tthis.handleEvent(...(jsonPiece as EventPayload<I>))\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(initialMaybeWellFormed)\n\t\t\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.handleEvent(...(maybeActualJsonPiece as EventPayload<I>))\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\n\t\tthis.on(`exit`, () => {\n\t\t\tthis.logger.info(`🔥`, this.id, `received \"exit\"`)\n\t\t\tthis.proc.exit(0)\n\t\t})\n\n\t\tif (this.proc.pid) {\n\t\t\tthis.id = this.proc.pid?.toString()\n\t\t}\n\n\t\tthis.on(`user-joins`, (username: string) => {\n\t\t\tthis.logger.info(`👤`, `user`, username, `joined`)\n\t\t\tconst userKey = `user::${username}` satisfies UserKey\n\t\t\tconst relay = new SubjectSocket(userKey)\n\t\t\tthis.relays.set(username, relay)\n\t\t\tthis.logger.info(\n\t\t\t\t`🔗`,\n\t\t\t\t`attaching services:`,\n\t\t\t\t`[${[...this.relayServices.keys()].join(`, `)}]`,\n\t\t\t)\n\t\t\tfor (const attachRelay of this.relayServices) {\n\t\t\t\tconst cleanupRelay = attachRelay(relay, userKey)\n\t\t\t\tif (cleanupRelay) {\n\t\t\t\t\trelay.disposalFunctions.push(cleanupRelay)\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.on(userKey, (...data) => {\n\t\t\t\trelay.in.next(data)\n\t\t\t})\n\t\t\trelay.out.subscribe(`socket`, (data) => {\n\t\t\t\tthis.emit(...(data as [string, ...I[keyof I]]))\n\t\t\t})\n\t\t})\n\n\t\tthis.on(`user-leaves`, (username) => {\n\t\t\tconst relay = this.relays.get(username)\n\t\t\tthis.off(`relay:${username}`)\n\t\t\tif (relay) {\n\t\t\t\trelay.dispose()\n\t\t\t\tthis.relays.delete(username)\n\t\t\t}\n\t\t})\n\n\t\tthis.proc.stdout.write(`ALIVE`)\n\t}\n\n\tpublic receiveRelay(\n\t\tattachServices: (\n\t\t\tsocket: SubjectSocket<any, any>,\n\t\t\tuserKey: UserKey,\n\t\t) => (() => void) | void,\n\t): void {\n\t\tthis.logger.info(`🔗`, `running relay method`)\n\t\tthis.relayServices.push(attachServices)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, Json, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>\nexport function realtimeAtomFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function familyProvider<\n\t\tJ extends Json.Serializable,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.RegularAtomFamilyToken<J, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\ttoken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst isAvailable = (exposedSubKeys: Iterable<K>, subKey: K): boolean => {\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nconst isAvailable = <K extends Canonical>(\n\texposedSubKeys: Iterable<K>,\n\tsubKey: K,\n): boolean => {\n\tfor (const exposedSubKey of exposedSubKeys) {\n\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nexport type MutableFamilyProvider = ReturnType<\n\ttypeof realtimeMutableFamilyProvider\n>\nexport function realtimeMutableFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableFamilyProvider<\n\t\tT extends Transceiver<any, any, any>,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tconst jsonToken = getJsonToken(store, token)\n\t\t\tconst updateToken = getUpdateToken(token)\n\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tupdateToken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type MutableProvider = ReturnType<typeof realtimeMutableProvider>\nexport function realtimeMutableProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableProvider<\n\t\tCore extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\t>(token: AtomIO.MutableAtomToken<Core>): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tconst trackerToken = getUpdateToken(token)\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttrackerToken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type {\n\tHierarchy,\n\tJoinToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport { atomFamily, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport type { RoomKey, Socket, SocketKey, UserKey } from \"atom.io/realtime\"\nimport { isSocketKey, isUserKey } from \"atom.io/realtime\"\nimport { UList } from \"atom.io/transceivers/u-list\"\n\nexport type SocketSystemHierarchy = Hierarchy<\n\t[\n\t\t{\n\t\t\tabove: `root`\n\t\t\tbelow: [UserKey, SocketKey, RoomKey]\n\t\t},\n\t]\n>\n\nexport const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =\n\tatomFamily({\n\t\tkey: `sockets`,\n\t\tdefault: null,\n\t})\n\nexport const socketKeysAtom: MutableAtomToken<UList<SocketKey>> = mutableAtom({\n\tkey: `socketsIndex`,\n\tclass: UList,\n})\nexport const userKeysAtom: MutableAtomToken<UList<UserKey>> = mutableAtom({\n\tkey: `usersIndex`,\n\tclass: UList,\n})\nexport const usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n> = join({\n\tkey: `usersOfSockets`,\n\tbetween: [`user`, `socket`],\n\tcardinality: `1:1`,\n\tisAType: isUserKey,\n\tisBType: isSocketKey,\n})\n\nexport const selfListSelectors: PureSelectorFamilyToken<UserKey[], UserKey> =\n\tselectorFamily({\n\t\tkey: `selfList`,\n\t\tget: (userId) => () => [userId],\n\t})\n","import type { ChildProcessWithoutNullStreams } from \"node:child_process\"\nimport { spawn } from \"node:child_process\"\n\nimport type { Store } from \"atom.io/internal\"\nimport {\n\teditRelationsInStore,\n\tfindInStore,\n\tfindRelationsInStore,\n\tgetFromStore,\n\tgetInternalRelationsFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type {\n\tAllEventsListener,\n\tEventsMap,\n\tRoomKey,\n\tRoomSocketInterface,\n\tSocket,\n\tSocketKey,\n\tTypedSocket,\n\tUserKey,\n} from \"atom.io/realtime\"\nimport { ownersOfRooms, roomKeysAtom, usersInRooms } from \"atom.io/realtime\"\n\nimport { ChildSocket } from \"../ipc-sockets\"\nimport { realtimeMutableFamilyProvider } from \"../realtime-mutable-family-provider\"\nimport { realtimeMutableProvider } from \"../realtime-mutable-provider\"\nimport type { ServerConfig } from \"../server-config\"\nimport {\n\tselfListSelectors,\n\tsocketKeysAtom,\n\tuserKeysAtom,\n\tusersOfSockets,\n} from \"./server-user-store\"\n\nexport type RoomMap = Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>\n\ndeclare global {\n\tvar ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap\n}\n\nexport const ROOMS: RoomMap =\n\tglobalThis.ATOM_IO_REALTIME_SERVER_ROOMS ??\n\t(globalThis.ATOM_IO_REALTIME_SERVER_ROOMS = new Map())\n\nexport const roomMeta: { count: number } = { count: 0 }\n\nexport async function spawnRoom(\n\tstore: Store,\n\tuserKey: UserKey,\n\troomKey: RoomKey,\n\tcommand: string,\n\targs: string[],\n): Promise<ChildSocket<any, any>> {\n\tconst child = await new Promise<ChildProcessWithoutNullStreams>((resolve) => {\n\t\tconst room = spawn(command, args, { env: process.env })\n\t\tconst resolver = (data: Buffer) => {\n\t\t\tif (data.toString() === `ALIVE`) {\n\t\t\t\troom.stdout.off(`data`, resolver)\n\t\t\t\tresolve(room)\n\t\t\t}\n\t\t}\n\t\troom.stdout.on(`data`, resolver)\n\t})\n\tconst roomSocket = new ChildSocket(child, roomKey)\n\tROOMS.set(roomKey, roomSocket)\n\tsetIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index))\n\n\teditRelationsInStore(store, ownersOfRooms, (relations) => {\n\t\trelations.set({ room: roomKey, user: userKey })\n\t})\n\n\troomSocket.on(`close`, () => {\n\t\tdestroyRoom(store)(roomKey)\n\t})\n\n\treturn roomSocket\n}\n\nexport function provideEnterAndExit(\n\tstore: Store,\n\tuserKey: UserKey,\n\tsocket: Socket,\n): {\n\tenterRoom: (roomKey: RoomKey) => void\n} {\n\tconst enterRoom = (roomKey: RoomKey) => {\n\t\tconst exitRoom = () => {\n\t\t\tsocket.offAny(forward)\n\t\t\ttoRoom([`user-leaves`])\n\t\t\tleaveRoom(store, roomKey, userKey)\n\t\t\tsocket.off(`leaveRoom`, exitRoom)\n\t\t\tsocket.on(`joinRoom`, enterRoom)\n\t\t}\n\n\t\tsocket.on(`leaveRoom`, exitRoom)\n\t\tsocket.off(`joinRoom`, enterRoom)\n\n\t\tconst roomQueue: [string, ...Json.Array][] = []\n\t\tconst pushToRoomQueue = (payload: [string, ...Json.Array]): void => {\n\t\t\troomQueue.push(payload)\n\t\t}\n\t\tlet toRoom = pushToRoomQueue\n\t\tconst forward: AllEventsListener<EventsMap> = (...payload) => {\n\t\t\ttoRoom(payload)\n\t\t}\n\t\tsocket.onAny(forward)\n\n\t\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\t\trelations.set({ room: roomKey, user: userKey })\n\t\t})\n\t\tconst roomSocket = ROOMS.get(roomKey)\n\t\tif (!roomSocket) {\n\t\t\tstore.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`)\n\t\t\treturn null\n\t\t}\n\t\troomSocket.onAny((...payload) => {\n\t\t\tsocket.emit(...payload)\n\t\t})\n\t\troomSocket.emit(`user-joins`, userKey)\n\n\t\ttoRoom = (payload) => {\n\t\t\troomSocket.emit(`user::${userKey}`, ...payload)\n\t\t}\n\t\twhile (roomQueue.length > 0) {\n\t\t\tconst payload = roomQueue.shift()\n\t\t\tif (payload) toRoom(payload)\n\t\t}\n\t}\n\tsocket.on(`joinRoom`, enterRoom)\n\treturn { enterRoom }\n}\n\nexport function leaveRoom(\n\tstore: Store,\n\troomKey: RoomKey,\n\tuserKey: UserKey,\n): void {\n\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\trelations.delete({ room: roomKey, user: userKey })\n\t})\n}\n\nexport function destroyRoom(store: Store): (roomKey: RoomKey) => void {\n\treturn (roomKey: RoomKey) => {\n\t\t// logger.info(`[${shortId}]:${username}`, `deleting room \"${roomId}\"`)\n\t\tsetIntoStore(store, roomKeysAtom, (s) => (s.delete(roomKey), s))\n\t\teditRelationsInStore(store, usersInRooms, (relations) => {\n\t\t\trelations.delete({ room: roomKey })\n\t\t})\n\t\tconst room = ROOMS.get(roomKey)\n\t\tif (room) {\n\t\t\troom.emit(`exit`)\n\t\t\tROOMS.delete(roomKey)\n\t\t}\n\t}\n}\n\nexport type ProvideRoomsConfig = {\n\tresolveRoomScript: (path: string) => [string, string[]]\n\troomTimeLimit?: number\n}\nexport function provideRooms<RoomNames extends string>({\n\tstore = IMPLICIT.STORE,\n\tsocket,\n\tresolveRoomScript,\n}: ProvideRoomsConfig & ServerConfig): void {\n\tconst socketKey = `socket::${socket.id}` satisfies SocketKey\n\tconst userKey = getFromStore(\n\t\tstore,\n\t\tfindRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket,\n\t)!\n\tconst roomSocket = socket as TypedSocket<RoomSocketInterface<RoomNames>, {}>\n\n\tconst exposeMutable = realtimeMutableProvider({ socket, store })\n\tconst exposeMutableFamily = realtimeMutableFamilyProvider({\n\t\tsocket,\n\t\tstore,\n\t})\n\n\texposeMutable(roomKeysAtom)\n\n\tconst [, usersInRoomsAtoms] = getInternalRelationsFromStore(\n\t\tstore,\n\t\tusersInRooms,\n\t\t`split`,\n\t)\n\tconst usersWhoseRoomsCanBeSeenSelector = findInStore(\n\t\tstore,\n\t\tselfListSelectors,\n\t\tuserKey,\n\t)\n\texposeMutableFamily(usersInRoomsAtoms, usersWhoseRoomsCanBeSeenSelector)\n\tconst usersOfSocketsAtoms = getInternalRelationsFromStore(\n\t\tstore,\n\t\tusersOfSockets,\n\t)\n\texposeMutableFamily(usersOfSocketsAtoms, socketKeysAtom)\n\n\tconst createRoom = async (roomName: RoomNames) => {\n\t\t// logger.info(`[${shortId}]:${username}`, `creating room \"${roomId}\"`)\n\t\tconst roomKey = `room::${roomMeta.count++}` satisfies RoomKey\n\t\tawait spawnRoom(store, userKey, roomKey, ...resolveRoomScript(roomName))\n\t}\n\n\tconst { enterRoom } = provideEnterAndExit(store, userKey, roomSocket)\n\n\tconst userRoomSet = getFromStore(store, usersInRoomsAtoms, userKey)\n\tfor (const userRoomKey of userRoomSet) {\n\t\tenterRoom(userRoomKey)\n\t\tbreak\n\t}\n\n\troomSocket.on(`createRoom`, createRoom)\n\troomSocket.on(`deleteRoom`, destroyRoom(store))\n\tsocket.on(`disconnect`, () => {\n\t\t// logger.info(`${socket.id} disconnected`)\n\t\teditRelationsInStore(store, usersOfSockets, (rel) => rel.delete(socketKey))\n\t\tsetIntoStore(store, userKeysAtom, (keys) => (keys.delete(userKey), keys))\n\t\tsetIntoStore(store, socketKeysAtom, (keys) => (keys.delete(socketKey), keys))\n\t})\n}\n","import type * as AtomIO from \"atom.io\"\nimport { getFromStore, IMPLICIT, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateProvider = ReturnType<typeof realtimeStateProvider>\nexport function realtimeStateProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateProvider<J extends Json.Serializable>(\n\t\ttoken: AtomIO.WritableToken<J>,\n\t): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { WritableToken } from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\toperateOnStore,\n\tOWN_OP,\n\tsetIntoStore,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket, mutexAtoms } from \"atom.io/realtime\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateReceiver = ReturnType<typeof realtimeStateReceiver>\nexport function realtimeStateReceiver({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateReceiver<S extends Json.Serializable, C extends S>(\n\t\tclientToken: WritableToken<C>,\n\t\tserverToken: WritableToken<S> = clientToken,\n\t): () => void {\n\t\tconst mutexAtom = findInStore(store, mutexAtoms, serverToken.key)\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst permitPublish = () => {\n\t\t\tclearSubscriptions()\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `pub:${clientToken.key}`, (newValue) => {\n\t\t\t\t\tsetIntoStore(store, serverToken, newValue as C)\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `unclaim:${clientToken.key}`, () => {\n\t\t\t\t\tsetIntoStore(store, mutexAtom, false)\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tstart()\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `claim:${clientToken.key}`, () => {\n\t\t\t\t\tif (getFromStore(store, mutexAtom)) {\n\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\t\tsubscribeToState(store, mutexAtom, socket.id!, () => {\n\t\t\t\t\t\t\t\tconst currentValue = getFromStore(store, mutexAtom)\n\t\t\t\t\t\t\t\tif (currentValue === false) {\n\t\t\t\t\t\t\t\t\toperateOnStore(OWN_OP, store, mutexAtom, true)\n\t\t\t\t\t\t\t\t\tpermitPublish()\n\t\t\t\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, false)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, mutexAtom, true)\n\t\t\t\t\tpermitPublish()\n\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,+BACf,kBACA,SACwB;AACxB,QAAO,QACL,KAAK,WAAgC;AACrC,UAAQ,OAAO,MAAf;GACC,KAAK,uBAAuB;IAC3B,MAAM,WAAW,+BAChB,kBACA,OAAO,UACP;AACD,WAAO;KAAE,GAAG;KAAQ,WAAW;KAAU;;GAE1C,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK,iBACJ,QAAO;;GAER,CACD,QAAQ,WAAW;AACnB,UAAQ,OAAO,MAAf;GACC,KAAK;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O,KAAK,gBAAgB,YAAY,OAAO,KAAK;KACnD,CACF;;AAGF,SAAO;AAEP,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.12",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
"@types/eslint": "9.6.1",
|
|
68
68
|
"@types/estree": "1.0.8",
|
|
69
69
|
"@types/http-proxy": "1.17.17",
|
|
70
|
-
"@types/react": "19.2.
|
|
70
|
+
"@types/react": "19.2.7",
|
|
71
71
|
"@types/tmp": "0.2.6",
|
|
72
72
|
"@typescript-eslint/parser": "8.47.0",
|
|
73
73
|
"@typescript-eslint/rule-tester": "8.47.0",
|
|
74
74
|
"@typescript-eslint/utils": "8.47.0",
|
|
75
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
75
|
+
"@typescript/native-preview": "7.0.0-dev.20251124.1",
|
|
76
76
|
"@vitest/coverage-v8": "4.0.13",
|
|
77
77
|
"@vitest/ui": "4.0.13",
|
|
78
78
|
"arktype": "2.1.27",
|
|
@@ -15,12 +15,13 @@ import {
|
|
|
15
15
|
|
|
16
16
|
export type RoomSocketInterface<RoomNames extends string> = {
|
|
17
17
|
createRoom: (roomName: RoomNames) => void
|
|
18
|
-
joinRoom: (roomKey:
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
joinRoom: (roomKey: RoomKey) => void
|
|
19
|
+
deleteRoom: (roomKey: RoomKey) => void
|
|
20
|
+
leaveRoom: () => void
|
|
21
|
+
// [leaveRoom: `leaveRoom:${string}`]: () => void
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export const roomKeysAtom: MutableAtomToken<UList<
|
|
24
|
+
export const roomKeysAtom: MutableAtomToken<UList<RoomKey>> = mutableAtom({
|
|
24
25
|
key: `roomIndex`,
|
|
25
26
|
class: UList,
|
|
26
27
|
})
|
|
@@ -40,6 +41,15 @@ export const usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`> =
|
|
|
40
41
|
isBType: isUserKey,
|
|
41
42
|
})
|
|
42
43
|
|
|
44
|
+
export const ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`> =
|
|
45
|
+
join({
|
|
46
|
+
key: `ownersOfRooms`,
|
|
47
|
+
between: [`user`, `room`],
|
|
48
|
+
cardinality: `1:n`,
|
|
49
|
+
isAType: isUserKey,
|
|
50
|
+
isBType: isRoomKey,
|
|
51
|
+
})
|
|
52
|
+
|
|
43
53
|
export const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<
|
|
44
54
|
MutableAtomToken<UList<RoomKey>>[],
|
|
45
55
|
UserKey
|
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
import type { Json } from "atom.io/json"
|
|
2
2
|
|
|
3
|
+
export type EventListener = (...args: Json.Serializable[]) => void
|
|
4
|
+
|
|
5
|
+
export type EventsMap = {
|
|
6
|
+
[event: string]: EventListener
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ParticularEventListener<ListenEvents extends EventsMap = EventsMap> =
|
|
10
|
+
<E extends string & keyof ListenEvents>(
|
|
11
|
+
event: E,
|
|
12
|
+
listener: ListenEvents[E],
|
|
13
|
+
) => void
|
|
14
|
+
|
|
15
|
+
export type AllEventsListener<ListenEvents extends EventsMap = EventsMap> = <
|
|
16
|
+
E extends string & keyof ListenEvents,
|
|
17
|
+
>(
|
|
18
|
+
event: E,
|
|
19
|
+
...args: Parameters<ListenEvents[E]>
|
|
20
|
+
) => void
|
|
21
|
+
|
|
22
|
+
export type EventEmitter<EmitEvents extends EventsMap = EventsMap> = <
|
|
23
|
+
E extends keyof EmitEvents,
|
|
24
|
+
>(
|
|
25
|
+
event: E,
|
|
26
|
+
...args: Parameters<EmitEvents[E]>
|
|
27
|
+
) => void
|
|
28
|
+
|
|
29
|
+
export type TypedSocket<
|
|
30
|
+
ListenEvents extends EventsMap = EventsMap,
|
|
31
|
+
EmitEvents extends EventsMap = EventsMap,
|
|
32
|
+
> = {
|
|
33
|
+
id: string | undefined
|
|
34
|
+
on: ParticularEventListener<ListenEvents>
|
|
35
|
+
onAny: (listener: AllEventsListener<ListenEvents>) => void
|
|
36
|
+
off: ParticularEventListener<ListenEvents>
|
|
37
|
+
offAny: (listener: AllEventsListener<ListenEvents>) => void
|
|
38
|
+
emit: EventEmitter<EmitEvents>
|
|
39
|
+
}
|
|
40
|
+
|
|
3
41
|
export type Socket = {
|
|
4
42
|
id: string | undefined
|
|
5
43
|
on: (event: string, listener: (...args: Json.Serializable[]) => void) => void
|
|
@@ -12,8 +12,17 @@ import {
|
|
|
12
12
|
setIntoStore,
|
|
13
13
|
} from "atom.io/internal"
|
|
14
14
|
import type { Json } from "atom.io/json"
|
|
15
|
-
import type {
|
|
16
|
-
|
|
15
|
+
import type {
|
|
16
|
+
AllEventsListener,
|
|
17
|
+
EventsMap,
|
|
18
|
+
RoomKey,
|
|
19
|
+
RoomSocketInterface,
|
|
20
|
+
Socket,
|
|
21
|
+
SocketKey,
|
|
22
|
+
TypedSocket,
|
|
23
|
+
UserKey,
|
|
24
|
+
} from "atom.io/realtime"
|
|
25
|
+
import { ownersOfRooms, roomKeysAtom, usersInRooms } from "atom.io/realtime"
|
|
17
26
|
|
|
18
27
|
import { ChildSocket } from "../ipc-sockets"
|
|
19
28
|
import { realtimeMutableFamilyProvider } from "../realtime-mutable-family-provider"
|
|
@@ -43,6 +52,7 @@ export const roomMeta: { count: number } = { count: 0 }
|
|
|
43
52
|
|
|
44
53
|
export async function spawnRoom(
|
|
45
54
|
store: Store,
|
|
55
|
+
userKey: UserKey,
|
|
46
56
|
roomKey: RoomKey,
|
|
47
57
|
command: string,
|
|
48
58
|
args: string[],
|
|
@@ -61,60 +71,69 @@ export async function spawnRoom(
|
|
|
61
71
|
ROOMS.set(roomKey, roomSocket)
|
|
62
72
|
setIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index))
|
|
63
73
|
|
|
74
|
+
editRelationsInStore(store, ownersOfRooms, (relations) => {
|
|
75
|
+
relations.set({ room: roomKey, user: userKey })
|
|
76
|
+
})
|
|
77
|
+
|
|
64
78
|
roomSocket.on(`close`, () => {
|
|
65
|
-
destroyRoom(store
|
|
79
|
+
destroyRoom(store)(roomKey)
|
|
66
80
|
})
|
|
67
81
|
|
|
68
82
|
return roomSocket
|
|
69
83
|
}
|
|
70
84
|
|
|
71
|
-
export function
|
|
85
|
+
export function provideEnterAndExit(
|
|
72
86
|
store: Store,
|
|
73
|
-
roomKey: RoomKey,
|
|
74
87
|
userKey: UserKey,
|
|
75
88
|
socket: Socket,
|
|
76
89
|
): {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
socket.onAny(forward)
|
|
90
|
+
enterRoom: (roomKey: RoomKey) => void
|
|
91
|
+
} {
|
|
92
|
+
const enterRoom = (roomKey: RoomKey) => {
|
|
93
|
+
const exitRoom = () => {
|
|
94
|
+
socket.offAny(forward)
|
|
95
|
+
toRoom([`user-leaves`])
|
|
96
|
+
leaveRoom(store, roomKey, userKey)
|
|
97
|
+
socket.off(`leaveRoom`, exitRoom)
|
|
98
|
+
socket.on(`joinRoom`, enterRoom)
|
|
99
|
+
}
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
const roomSocket = ROOMS.get(roomKey)
|
|
94
|
-
if (!roomSocket) {
|
|
95
|
-
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`)
|
|
96
|
-
return null
|
|
97
|
-
}
|
|
98
|
-
roomSocket.onAny((...payload) => {
|
|
99
|
-
socket.emit(...payload)
|
|
100
|
-
})
|
|
101
|
-
roomSocket.emit(`user-joins`, userKey)
|
|
101
|
+
socket.on(`leaveRoom`, exitRoom)
|
|
102
|
+
socket.off(`joinRoom`, enterRoom)
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
const roomQueue: [string, ...Json.Array][] = []
|
|
105
|
+
const pushToRoomQueue = (payload: [string, ...Json.Array]): void => {
|
|
106
|
+
roomQueue.push(payload)
|
|
107
|
+
}
|
|
108
|
+
let toRoom = pushToRoomQueue
|
|
109
|
+
const forward: AllEventsListener<EventsMap> = (...payload) => {
|
|
110
|
+
toRoom(payload)
|
|
111
|
+
}
|
|
112
|
+
socket.onAny(forward)
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
115
|
+
relations.set({ room: roomKey, user: userKey })
|
|
116
|
+
})
|
|
117
|
+
const roomSocket = ROOMS.get(roomKey)
|
|
118
|
+
if (!roomSocket) {
|
|
119
|
+
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`)
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
roomSocket.onAny((...payload) => {
|
|
123
|
+
socket.emit(...payload)
|
|
124
|
+
})
|
|
125
|
+
roomSocket.emit(`user-joins`, userKey)
|
|
116
126
|
|
|
117
|
-
|
|
127
|
+
toRoom = (payload) => {
|
|
128
|
+
roomSocket.emit(`user::${userKey}`, ...payload)
|
|
129
|
+
}
|
|
130
|
+
while (roomQueue.length > 0) {
|
|
131
|
+
const payload = roomQueue.shift()
|
|
132
|
+
if (payload) toRoom(payload)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
socket.on(`joinRoom`, enterRoom)
|
|
136
|
+
return { enterRoom }
|
|
118
137
|
}
|
|
119
138
|
|
|
120
139
|
export function leaveRoom(
|
|
@@ -127,27 +146,36 @@ export function leaveRoom(
|
|
|
127
146
|
})
|
|
128
147
|
}
|
|
129
148
|
|
|
130
|
-
export function destroyRoom(store: Store
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
room.
|
|
138
|
-
|
|
149
|
+
export function destroyRoom(store: Store): (roomKey: RoomKey) => void {
|
|
150
|
+
return (roomKey: RoomKey) => {
|
|
151
|
+
// logger.info(`[${shortId}]:${username}`, `deleting room "${roomId}"`)
|
|
152
|
+
setIntoStore(store, roomKeysAtom, (s) => (s.delete(roomKey), s))
|
|
153
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
154
|
+
relations.delete({ room: roomKey })
|
|
155
|
+
})
|
|
156
|
+
const room = ROOMS.get(roomKey)
|
|
157
|
+
if (room) {
|
|
158
|
+
room.emit(`exit`)
|
|
159
|
+
ROOMS.delete(roomKey)
|
|
160
|
+
}
|
|
139
161
|
}
|
|
140
162
|
}
|
|
141
163
|
|
|
142
|
-
export
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
164
|
+
export type ProvideRoomsConfig = {
|
|
165
|
+
resolveRoomScript: (path: string) => [string, string[]]
|
|
166
|
+
roomTimeLimit?: number
|
|
167
|
+
}
|
|
168
|
+
export function provideRooms<RoomNames extends string>({
|
|
169
|
+
store = IMPLICIT.STORE,
|
|
170
|
+
socket,
|
|
171
|
+
resolveRoomScript,
|
|
172
|
+
}: ProvideRoomsConfig & ServerConfig): void {
|
|
146
173
|
const socketKey = `socket::${socket.id}` satisfies SocketKey
|
|
147
174
|
const userKey = getFromStore(
|
|
148
175
|
store,
|
|
149
176
|
findRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket,
|
|
150
177
|
)!
|
|
178
|
+
const roomSocket = socket as TypedSocket<RoomSocketInterface<RoomNames>, {}>
|
|
151
179
|
|
|
152
180
|
const exposeMutable = realtimeMutableProvider({ socket, store })
|
|
153
181
|
const exposeMutableFamily = realtimeMutableFamilyProvider({
|
|
@@ -157,7 +185,11 @@ export function provideRooms<RoomNames extends string>(
|
|
|
157
185
|
|
|
158
186
|
exposeMutable(roomKeysAtom)
|
|
159
187
|
|
|
160
|
-
const usersInRoomsAtoms = getInternalRelationsFromStore(
|
|
188
|
+
const [, usersInRoomsAtoms] = getInternalRelationsFromStore(
|
|
189
|
+
store,
|
|
190
|
+
usersInRooms,
|
|
191
|
+
`split`,
|
|
192
|
+
)
|
|
161
193
|
const usersWhoseRoomsCanBeSeenSelector = findInStore(
|
|
162
194
|
store,
|
|
163
195
|
selfListSelectors,
|
|
@@ -170,38 +202,26 @@ export function provideRooms<RoomNames extends string>(
|
|
|
170
202
|
)
|
|
171
203
|
exposeMutableFamily(usersOfSocketsAtoms, socketKeysAtom)
|
|
172
204
|
|
|
173
|
-
|
|
205
|
+
const createRoom = async (roomName: RoomNames) => {
|
|
174
206
|
// logger.info(`[${shortId}]:${username}`, `creating room "${roomId}"`)
|
|
175
|
-
const
|
|
176
|
-
await spawnRoom(store,
|
|
177
|
-
|
|
178
|
-
// logger.info(`[${shortId}]:${username}`, `deleting room "${roomId}"`)
|
|
179
|
-
destroyRoom(store, roomId)
|
|
180
|
-
})
|
|
181
|
-
})
|
|
207
|
+
const roomKey = `room::${roomMeta.count++}` satisfies RoomKey
|
|
208
|
+
await spawnRoom(store, userKey, roomKey, ...resolveRoomScript(roomName))
|
|
209
|
+
}
|
|
182
210
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
211
|
+
const { enterRoom } = provideEnterAndExit(store, userKey, roomSocket)
|
|
212
|
+
|
|
213
|
+
const userRoomSet = getFromStore(store, usersInRoomsAtoms, userKey)
|
|
214
|
+
for (const userRoomKey of userRoomSet) {
|
|
215
|
+
enterRoom(userRoomKey)
|
|
216
|
+
break
|
|
217
|
+
}
|
|
188
218
|
|
|
219
|
+
roomSocket.on(`createRoom`, createRoom)
|
|
220
|
+
roomSocket.on(`deleteRoom`, destroyRoom(store))
|
|
189
221
|
socket.on(`disconnect`, () => {
|
|
190
|
-
editRelationsInStore(store, usersOfSockets, (relations) =>
|
|
191
|
-
relations.delete(socketKey),
|
|
192
|
-
)
|
|
193
|
-
if (userKey) {
|
|
194
|
-
setIntoStore(
|
|
195
|
-
store,
|
|
196
|
-
userKeysAtom,
|
|
197
|
-
(index) => (index.delete(userKey), index),
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
setIntoStore(
|
|
201
|
-
store,
|
|
202
|
-
socketKeysAtom,
|
|
203
|
-
(index) => (index.delete(socketKey), index),
|
|
204
|
-
)
|
|
205
222
|
// logger.info(`${socket.id} disconnected`)
|
|
223
|
+
editRelationsInStore(store, usersOfSockets, (rel) => rel.delete(socketKey))
|
|
224
|
+
setIntoStore(store, userKeysAtom, (keys) => (keys.delete(userKey), keys))
|
|
225
|
+
setIntoStore(store, socketKeysAtom, (keys) => (keys.delete(socketKey), keys))
|
|
206
226
|
})
|
|
207
227
|
}
|