atom.io 0.44.12 → 0.44.13
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/internal/index.js +8 -8
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/main/index.d.ts +6 -4
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +4 -3
- package/dist/main/index.js.map +1 -1
- package/dist/realtime/index.d.ts +94 -31
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +34 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +3 -1
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +7 -4
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +43 -13
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +120 -63
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +10 -10
- package/src/internal/families/create-readonly-held-selector-family.ts +2 -2
- package/src/internal/families/create-readonly-pure-selector-family.ts +2 -2
- package/src/internal/families/create-regular-atom-family.ts +2 -2
- package/src/internal/families/create-writable-held-selector-family.ts +2 -2
- package/src/internal/families/create-writable-pure-selector-family.ts +2 -2
- package/src/internal/mutable/create-mutable-atom-family.ts +2 -2
- package/src/internal/not-found-error.ts +2 -2
- package/src/main/logger.ts +8 -4
- package/src/realtime/cast-socket.ts +73 -0
- package/src/realtime/index.ts +2 -0
- package/src/realtime/socket-interface.ts +1 -1
- package/src/realtime/standard-schema.ts +72 -0
- package/src/realtime-react/index.ts +1 -0
- package/src/realtime-react/realtime-context.tsx +0 -9
- package/src/realtime-react/use-realtime-rooms.ts +13 -0
- package/src/realtime-server/realtime-server-stores/index.ts +1 -1
- package/src/realtime-server/realtime-server-stores/provide-rooms.ts +368 -0
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +0 -227
|
@@ -1 +1 @@
|
|
|
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,SAAS,iBAAiB,QADnC,IAAI,UAAU,IAAI,CAC+B;EAC/D,MAAM,QAAQ;GAAE;GAAM;GAAK;GAAS;GAAS;GAAc;AAC3D,YAAU,SAAS,IAAI,KAAK,MAAM;AAClC,SAAO;;CAYR,AAAO,IACN,GAAG,MAII;AAEP,UADe,KAAK,GACL,MAAf;GACC,KAAK;GACL,KAAK;AAC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","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/cast-socket.ts","../../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 { Loadable } from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { EventsMap, Socket, TypedSocket } from \"./socket-interface\"\nimport type { StandardSchemaV1 } from \"./standard-schema\"\n\nexport type SocketListeners<T extends TypedSocket> = T extends TypedSocket<\n\tinfer ListenEvents\n>\n\t? ListenEvents\n\t: never\n\nexport type SocketGuard<L extends EventsMap> = {\n\t[K in keyof L]: StandardSchemaV1<Json.Array, Parameters<L[K]>>\n}\n\nexport type Loaded<L extends Loadable<any>> = L extends Loadable<infer T>\n\t? T\n\t: never\n\nfunction onLoad<L extends Loadable<any>>(\n\tloadable: L,\n\tfn: (loaded: Loaded<L>) => any,\n): void {\n\tif (loadable instanceof Promise) {\n\t\tvoid loadable.then(fn)\n\t} else {\n\t\tfn(loadable as Loaded<L>)\n\t}\n}\n\nexport function castSocket<T extends TypedSocket>(\n\tsocket: Socket,\n\tguard: SocketGuard<SocketListeners<T>> | `TRUST`,\n\tlogError?: (error: unknown) => void,\n): T {\n\tif (guard === `TRUST`) {\n\t\treturn socket as T\n\t}\n\tconst guardedSocket: Socket = {\n\t\tid: socket.id,\n\t\ton: (event, listener) => {\n\t\t\tconst schema = guard[event] as StandardSchemaV1<Json.Array, Json.Array>\n\t\t\tsocket.on(event, (...args) => {\n\t\t\t\tconst loadableResult = schema[`~standard`].validate(args)\n\t\t\t\tonLoad(loadableResult, (result) => {\n\t\t\t\t\tif (result.issues) {\n\t\t\t\t\t\tlogError?.(result.issues)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlistener(...result.value)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t\tonAny: (listener) => {\n\t\t\tsocket.onAny((event, ...args) => {\n\t\t\t\tconst schema = guard[event] as StandardSchemaV1<unknown, Json.Array>\n\t\t\t\tconst loadableResult = schema[`~standard`].validate(args)\n\t\t\t\tonLoad(loadableResult, (result) => {\n\t\t\t\t\tif (result.issues) {\n\t\t\t\t\t\tlogError?.(result.issues)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlistener(event, ...result.value)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t\toff: socket.off.bind(socket),\n\t\toffAny: socket.offAny.bind(socket),\n\t\temit: socket.emit.bind(socket),\n\t}\n\treturn guardedSocket as T\n}\n","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":";;;;;AAoBA,SAAS,OACR,UACA,IACO;AACP,KAAI,oBAAoB,QACvB,CAAK,SAAS,KAAK,GAAG;KAEtB,IAAG,SAAsB;;AAI3B,SAAgB,WACf,QACA,OACA,UACI;AACJ,KAAI,UAAU,QACb,QAAO;AAkCR,QAhC8B;EAC7B,IAAI,OAAO;EACX,KAAK,OAAO,aAAa;GACxB,MAAM,SAAS,MAAM;AACrB,UAAO,GAAG,QAAQ,GAAG,SAAS;AAE7B,WADuB,OAAO,aAAa,SAAS,KAAK,GACjC,WAAW;AAClC,SAAI,OAAO,OACV,YAAW,OAAO,OAAO;SAEzB,UAAS,GAAG,OAAO,MAAM;MAEzB;KACD;;EAEH,QAAQ,aAAa;AACpB,UAAO,OAAO,OAAO,GAAG,SAAS;AAGhC,WAFe,MAAM,OACS,aAAa,SAAS,KAAK,GACjC,WAAW;AAClC,SAAI,OAAO,OACV,YAAW,OAAO,OAAO;SAEzB,UAAS,OAAO,GAAG,OAAO,MAAM;MAEhC;KACD;;EAEH,KAAK,OAAO,IAAI,KAAK,OAAO;EAC5B,QAAQ,OAAO,OAAO,KAAK,OAAO;EAClC,MAAM,OAAO,KAAK,KAAK,OAAO;EAC9B;;;;;ACnEF,SAAgB,aACf,QACA,OACA,aACa;AACb,QA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AY;AACpB,MAAK,MAAM,UAAU,QACpB,+BAA8B,SAAS,OAAO,KAAK,OAAO,IAAI;AAE/D,4BAA2B,SAAS,OAAO,KAAK,GAAG;AACnD,QAAO;;;;;AC/HR,MAAa,eAAe,QAC3B,IAAI,WAAW,WAAW;AAG3B,MAAa,aAAa,QACzB,IAAI,WAAW,SAAS;AAGzB,MAAa,aAAa,QACzB,IAAI,WAAW,SAAS;;;;ACazB,MAAaC,eAAiD,YAAY;CACzE,KAAK;CACL,OAAO;CACP,CAAC;AAKF,MAAaC,4BAA4C,EACxD,gBAAgB,GAChB;AACD,MAAaC,eACZ,KAAK;CACJ,KAAK;CACL,SAAS,CAAC,QAAQ,OAAO;CACzB,aAAa;CACb,SAAS;CACT,SAAS;CACT,CAAC;AAEH,MAAaC,gBACZ,KAAK;CACJ,KAAK;CACL,SAAS,CAAC,QAAQ,OAAO;CACzB,aAAa;CACb,SAAS;CACT,SAAS;CACT,CAAC;AAEH,MAAaC,oBAGT,eAAe;CAClB,KAAK;CACL,MACE,gBACA,EAAE,WAAW;EACb,MAAM,GAAG,qBAAqB,qBAAqB,cAAc,QAAQ;AAEzE,SAAO,CADa,KAAK,mBAAmB,WAAW,CACnC;;CAEtB,CAAC"}
|
|
@@ -19,7 +19,6 @@ declare const RealtimeProvider: React.FC<{
|
|
|
19
19
|
children: React.ReactNode;
|
|
20
20
|
socket: Socket$1 | null;
|
|
21
21
|
}>;
|
|
22
|
-
declare function useRealtimeRooms<RoomNames extends string>(): Socket$1<{}, RoomSocketInterface<RoomNames>>;
|
|
23
22
|
//#endregion
|
|
24
23
|
//#region src/realtime-react/use-pull-atom.d.ts
|
|
25
24
|
declare function usePullAtom<J extends Json.Serializable>(token: AtomIO.RegularAtomToken<J>): J;
|
|
@@ -42,6 +41,9 @@ declare function usePullSelectorFamilyMember<T, K extends Canonical>(familyToken
|
|
|
42
41
|
//#region src/realtime-react/use-push.d.ts
|
|
43
42
|
declare function usePush<J extends Json.Serializable>(token: AtomIO.WritableToken<J>): (<New extends J>(next: New | ((old: J) => New)) => void) | null;
|
|
44
43
|
//#endregion
|
|
44
|
+
//#region src/realtime-react/use-realtime-rooms.d.ts
|
|
45
|
+
declare function useRealtimeRooms<RoomNames extends string>(): Socket$1<{}, RoomSocketInterface<RoomNames>>;
|
|
46
|
+
//#endregion
|
|
45
47
|
//#region src/realtime-react/use-realtime-service.d.ts
|
|
46
48
|
declare function useRealtimeService(key: string, create: (socket: Socket$1) => () => void): void;
|
|
47
49
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["RealtimeContext: React.Context<RealtimeReactStore>","RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}>"],"sources":["../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/use-pull-atom.ts","../../src/realtime-react/use-pull-atom-family-member.ts","../../src/realtime-react/use-pull-mutable-atom.ts","../../src/realtime-react/use-pull-mutable-family-member.ts","../../src/realtime-react/use-pull-selector.ts","../../src/realtime-react/use-pull-selector-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-realtime-service.ts","../../src/realtime-react/use-single-effect.ts","../../src/realtime-react/use-sync-continuity.ts"],"sourcesContent":[],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["RealtimeContext: React.Context<RealtimeReactStore>","RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}>"],"sources":["../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/use-pull-atom.ts","../../src/realtime-react/use-pull-atom-family-member.ts","../../src/realtime-react/use-pull-mutable-atom.ts","../../src/realtime-react/use-pull-mutable-family-member.ts","../../src/realtime-react/use-pull-selector.ts","../../src/realtime-react/use-pull-selector-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-realtime-rooms.ts","../../src/realtime-react/use-realtime-service.ts","../../src/realtime-react/use-single-effect.ts","../../src/realtime-react/use-sync-continuity.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAKY,sBAAA;;;;KAKA,kBAAA;UACH;EANT,QAAY,EAOD,GAPC,CAAA,MAAA,EAOW,sBAPX,CAAA,GAAA,IAAA;AAKZ,CAAA;AACS,cAIIA,eAJJ,EAIqB,KAAA,CAAM,OAJ3B,CAImC,kBAJnC,CAAA;AACc,cASVC,gBATU,EASQ,KAAA,CAAM,EATd,CAAA;EAAZ,QAAA,EAUA,KAAA,CAAM,SAVN;EAAA,MAAA,EAWF,QAXE,GAAA,IAAA;AAGX,CAAA,CAAA;;;iBCPgB,sBAAsB,IAAA,CAAK,qBACnC,MAAA,CAAO,iBAAiB,KAC7B;;;iBCDa,kCACL,IAAA,CAAK,wBACL,mBACD,MAAA,CAAO,uBAAuB,GAAG,YAAY,QAAQ,KAAK;;;iBCJpD,yBAAyB,mCACjC,MAAA,CAAO,iBAAiB,KAC7B;;;iBCAa,yCACL,sCACA,wBACI,MAAA,CAAO,uBAAuB,GAAG,SAAS,QAAQ,KAAK;;;iBCLtD,0BAA0B,IAAA,CAAK,qBACvC,MAAA,CAAO,cAAc,KAC1B;;;iBCDa,yCAAyC,wBAC3C,MAAA,CAAO,oBAAoB,GAAG,SACtC,QAAQ,KACX;;;iBCHa,kBAAkB,IAAA,CAAK,qBAC/B,MAAA,CAAO,cAAc,mBACZ,SAAS,aAAa,MAAM;;;iBCL7B,8CAA8C,aAE7D,oBAAoB;;;iBCFL,kBAAA,+BAEE;;;iBCHF,eAAA;;;iBCEA,iBAAA,QAAyB"}
|
|
@@ -31,10 +31,6 @@ const RealtimeProvider = ({ children, socket }) => {
|
|
|
31
31
|
children
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
function useRealtimeRooms() {
|
|
35
|
-
const { socket } = React.useContext(RealtimeContext);
|
|
36
|
-
return socket;
|
|
37
|
-
}
|
|
38
34
|
|
|
39
35
|
//#endregion
|
|
40
36
|
//#region src/realtime-react/use-single-effect.ts
|
|
@@ -142,6 +138,13 @@ function usePush(token) {
|
|
|
142
138
|
return mutex ? setter : null;
|
|
143
139
|
}
|
|
144
140
|
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/realtime-react/use-realtime-rooms.ts
|
|
143
|
+
function useRealtimeRooms() {
|
|
144
|
+
const { socket } = React.useContext(RealtimeContext);
|
|
145
|
+
return socket;
|
|
146
|
+
}
|
|
147
|
+
|
|
145
148
|
//#endregion
|
|
146
149
|
//#region src/realtime-react/use-sync-continuity.ts
|
|
147
150
|
function useSyncContinuity(token) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["RealtimeContext: React.Context<RealtimeReactStore>","RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}>"],"sources":["../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/use-single-effect.ts","../../src/realtime-react/use-realtime-service.ts","../../src/realtime-react/use-pull-atom.ts","../../src/realtime-react/use-pull-atom-family-member.ts","../../src/realtime-react/use-pull-mutable-atom.ts","../../src/realtime-react/use-pull-mutable-family-member.ts","../../src/realtime-react/use-pull-selector.ts","../../src/realtime-react/use-pull-selector-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-sync-continuity.ts"],"sourcesContent":["import { useI } from \"atom.io/react\"\nimport type { RoomSocketInterface } from \"atom.io/realtime\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nexport type RealtimeServiceCounter = {\n\tconsumerCount: number\n\tdispose: () => void\n}\n\nexport type RealtimeReactStore = {\n\tsocket: Socket | null\n\tservices: Map<string, RealtimeServiceCounter> | null\n}\n\nexport const RealtimeContext: React.Context<RealtimeReactStore> =\n\tReact.createContext({\n\t\tsocket: null,\n\t\tservices: null,\n\t})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}> = ({ children, socket }) => {\n\tconst services = React.useRef(\n\t\tnew Map<string, RealtimeServiceCounter>(),\n\t).current\n\tconst setMySocketKey = useI(RTC.mySocketKeyAtom)\n\tReact.useEffect(() => {\n\t\tsetMySocketKey(socket?.id ? `socket::${socket.id}` : undefined)\n\t\tsocket?.on(`connect`, () => {\n\t\t\tsetMySocketKey(socket?.id ? `socket::${socket.id}` : undefined)\n\t\t})\n\t\tsocket?.on(`disconnect`, () => {\n\t\t\tsetMySocketKey(undefined)\n\t\t})\n\t}, [socket, setMySocketKey])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket, services }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n\nexport function useRealtimeRooms<RoomNames extends string>(): Socket<\n\t{},\n\tRoomSocketInterface<RoomNames>\n> {\n\tconst { socket } = React.useContext(RealtimeContext)\n\treturn socket as Socket<{}, RoomSocketInterface<RoomNames>>\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: intentional */\n\nimport { isFn } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined | void,\n\tdeps: unknown[],\n): void {\n\tconst globalEnv = (globalThis as unknown as { env: any })[`env`]\n\tconst isInDev = globalEnv?.NODE_ENV === `development`\n\tif (isInDev) {\n\t\tconst cleanupRef = React.useRef<boolean | (() => void)>(false)\n\t\tReact.useEffect(() => {\n\t\t\tlet cleanupFn = cleanupRef.current\n\t\t\tif (cleanupFn === false) {\n\t\t\t\tcleanupFn = effect() ?? true\n\t\t\t\tcleanupRef.current = cleanupFn\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tif (isFn(cleanupFn)) cleanupFn()\n\t\t\t\t\tcleanupRef.current = false\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","import * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { useSingleEffect } from \"./use-single-effect\"\n\nexport function useRealtimeService(\n\tkey: string,\n\tcreate: (socket: Socket) => () => void,\n): void {\n\tconst { socket, services } = React.useContext(RealtimeContext)\n\tuseSingleEffect(() => {\n\t\tlet service = services?.get(key)\n\t\tif (service) {\n\t\t\t++service.consumerCount\n\t\t} else if (socket) {\n\t\t\tconst dispose = create(socket)\n\t\t\tservice = { consumerCount: 1, dispose }\n\t\t\tservices?.set(key, service)\n\t\t}\n\t\treturn () => {\n\t\t\tif (service) {\n\t\t\t\t--service.consumerCount\n\t\t\t\tif (service.consumerCount === 0) {\n\t\t\t\t\tservice.dispose?.()\n\t\t\t\t\tservices?.delete(key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [socket, key])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtom<J extends Json.Serializable>(\n\ttoken: AtomIO.RegularAtomToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtom(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(family: AtomIO.RegularAtomFamilyToken<J, K>, subKey: NoInfer<K>): J {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, family, subKey)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtomFamilyMember(store, socket, family, subKey),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutable<T extends Transceiver<any, any, any>>(\n\ttoken: AtomIO.MutableAtomToken<T>,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtom(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: NoInfer<K>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, familyToken, key)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtomFamilyMember(store, socket, familyToken, key),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelector<J extends Json.Serializable>(\n\ttoken: AtomIO.SelectorToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelector(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelectorFamilyMember<T, K extends Canonical>(\n\tfamilyToken: AtomIO.SelectorFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, familyToken, key)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelectorFamilyMember(store, socket, familyToken, key),\n\t)\n\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useI, useO } from \"atom.io/react\"\nimport * as RT from \"atom.io/realtime\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): (<New extends J>(next: New | ((old: J) => New)) => void) | null {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`push:${token.key}`, (socket) =>\n\t\tRTC.pushState(store, socket, token),\n\t)\n\tconst mutex = useO(RT.mutexAtoms, token.key)\n\tconst setter = useI(token)\n\n\treturn mutex ? setter : null\n}\n","import { StoreContext } from \"atom.io/react\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport { syncContinuity } from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useSyncContinuity(token: ContinuityToken): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`tx-sync:${token.key}`, (socket) => {\n\t\treturn syncContinuity(store, socket, token)\n\t})\n}\n"],"mappings":";;;;;;;;;AAgBA,MAAaA,kBACZ,MAAM,cAAc;CACnB,QAAQ;CACR,UAAU;CACV,CAAC;AAEH,MAAaC,oBAGP,EAAE,UAAU,aAAa;CAC9B,MAA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gB,QACf,OACkE;CAClE,MAAM,QAAQ,MAAM,WAAW,aAAa;AAC5C,oBAAmB,QAAQ,MAAM,QAAQ,WACxC,IAAI,UAAU,OAAO,QAAQ,MAAM,CACnC;CACD,MAAM,QAAQ,KAAK,GAAG,YAAY,MAAM,IAAI;CAC5C,MAAM,SAAS,KAAK,MAAM;AAE1B,QAAO,QAAQ,SAAS;;;;;ACZzB,SAAgB,kBAAkB,OAA8B;CAC/D,MAAM,QAAQ,MAAM,WAAW,aAAa;AAC5C,oBAAmB,WAAW,MAAM,QAAQ,WAAW;AACtD,SAAO,eAAe,OAAO,QAAQ,MAAM;GAC1C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["RealtimeContext: React.Context<RealtimeReactStore>","RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}>"],"sources":["../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/use-single-effect.ts","../../src/realtime-react/use-realtime-service.ts","../../src/realtime-react/use-pull-atom.ts","../../src/realtime-react/use-pull-atom-family-member.ts","../../src/realtime-react/use-pull-mutable-atom.ts","../../src/realtime-react/use-pull-mutable-family-member.ts","../../src/realtime-react/use-pull-selector.ts","../../src/realtime-react/use-pull-selector-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-realtime-rooms.ts","../../src/realtime-react/use-sync-continuity.ts"],"sourcesContent":["import { useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nexport type RealtimeServiceCounter = {\n\tconsumerCount: number\n\tdispose: () => void\n}\n\nexport type RealtimeReactStore = {\n\tsocket: Socket | null\n\tservices: Map<string, RealtimeServiceCounter> | null\n}\n\nexport const RealtimeContext: React.Context<RealtimeReactStore> =\n\tReact.createContext({\n\t\tsocket: null,\n\t\tservices: null,\n\t})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}> = ({ children, socket }) => {\n\tconst services = React.useRef(\n\t\tnew Map<string, RealtimeServiceCounter>(),\n\t).current\n\tconst setMySocketKey = useI(RTC.mySocketKeyAtom)\n\tReact.useEffect(() => {\n\t\tsetMySocketKey(socket?.id ? `socket::${socket.id}` : undefined)\n\t\tsocket?.on(`connect`, () => {\n\t\t\tsetMySocketKey(socket?.id ? `socket::${socket.id}` : undefined)\n\t\t})\n\t\tsocket?.on(`disconnect`, () => {\n\t\t\tsetMySocketKey(undefined)\n\t\t})\n\t}, [socket, setMySocketKey])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket, services }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: intentional */\n\nimport { isFn } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined | void,\n\tdeps: unknown[],\n): void {\n\tconst globalEnv = (globalThis as unknown as { env: any })[`env`]\n\tconst isInDev = globalEnv?.NODE_ENV === `development`\n\tif (isInDev) {\n\t\tconst cleanupRef = React.useRef<boolean | (() => void)>(false)\n\t\tReact.useEffect(() => {\n\t\t\tlet cleanupFn = cleanupRef.current\n\t\t\tif (cleanupFn === false) {\n\t\t\t\tcleanupFn = effect() ?? true\n\t\t\t\tcleanupRef.current = cleanupFn\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tif (isFn(cleanupFn)) cleanupFn()\n\t\t\t\t\tcleanupRef.current = false\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","import * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { useSingleEffect } from \"./use-single-effect\"\n\nexport function useRealtimeService(\n\tkey: string,\n\tcreate: (socket: Socket) => () => void,\n): void {\n\tconst { socket, services } = React.useContext(RealtimeContext)\n\tuseSingleEffect(() => {\n\t\tlet service = services?.get(key)\n\t\tif (service) {\n\t\t\t++service.consumerCount\n\t\t} else if (socket) {\n\t\t\tconst dispose = create(socket)\n\t\t\tservice = { consumerCount: 1, dispose }\n\t\t\tservices?.set(key, service)\n\t\t}\n\t\treturn () => {\n\t\t\tif (service) {\n\t\t\t\t--service.consumerCount\n\t\t\t\tif (service.consumerCount === 0) {\n\t\t\t\t\tservice.dispose?.()\n\t\t\t\t\tservices?.delete(key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [socket, key])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtom<J extends Json.Serializable>(\n\ttoken: AtomIO.RegularAtomToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtom(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(family: AtomIO.RegularAtomFamilyToken<J, K>, subKey: NoInfer<K>): J {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, family, subKey)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtomFamilyMember(store, socket, family, subKey),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutable<T extends Transceiver<any, any, any>>(\n\ttoken: AtomIO.MutableAtomToken<T>,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtom(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: NoInfer<K>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, familyToken, key)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtomFamilyMember(store, socket, familyToken, key),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelector<J extends Json.Serializable>(\n\ttoken: AtomIO.SelectorToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelector(store, socket, token),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelectorFamilyMember<T, K extends Canonical>(\n\tfamilyToken: AtomIO.SelectorFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(store, familyToken, key)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelectorFamilyMember(store, socket, familyToken, key),\n\t)\n\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useI, useO } from \"atom.io/react\"\nimport * as RT from \"atom.io/realtime\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): (<New extends J>(next: New | ((old: J) => New)) => void) | null {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`push:${token.key}`, (socket) =>\n\t\tRTC.pushState(store, socket, token),\n\t)\n\tconst mutex = useO(RT.mutexAtoms, token.key)\n\tconst setter = useI(token)\n\n\treturn mutex ? setter : null\n}\n","import type { RoomSocketInterface } from \"atom.io/realtime\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function useRealtimeRooms<RoomNames extends string>(): Socket<\n\t{},\n\tRoomSocketInterface<RoomNames>\n> {\n\tconst { socket } = React.useContext(RealtimeContext)\n\treturn socket as Socket<{}, RoomSocketInterface<RoomNames>>\n}\n","import { StoreContext } from \"atom.io/react\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport { syncContinuity } from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useSyncContinuity(token: ContinuityToken): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`tx-sync:${token.key}`, (socket) => {\n\t\treturn syncContinuity(store, socket, token)\n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AO,QAAQ,aAAa,IAAI,CAC7D;AAED,QAAO,KAAK,MAAM;;;;;ACVnB,SAAgB,QACf,OACkE;CAClE,MAAM,QAAQ,MAAM,WAAW,aAAa;AAC5C,oBAAmB,QAAQ,MAAM,QAAQ,WACxC,IAAI,UAAU,OAAO,QAAQ,MAAM,CACnC;CACD,MAAM,QAAQ,KAAK,GAAG,YAAY,MAAM,IAAI;CAC5C,MAAM,SAAS,KAAK,MAAM;AAE1B,QAAO,QAAQ,SAAS;;;;;ACbzB,SAAgB,mBAGd;CACD,MAAM,EAAE,WAAW,MAAM,WAAW,gBAAgB;AACpD,QAAO;;;;;ACJR,SAAgB,kBAAkB,OAA8B;CAC/D,MAAM,QAAQ,MAAM,WAAW,aAAa;AAC5C,oBAAmB,WAAW,MAAM,QAAQ,WAAW;AACtD,SAAO,eAAe,OAAO,QAAQ,MAAM;GAC1C"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RootStore,
|
|
1
|
+
import { RootStore, Subject, Transceiver } from "atom.io/internal";
|
|
2
2
|
import * as AtomIO from "atom.io";
|
|
3
3
|
import { Hierarchy, JoinToken, MutableAtomToken, PureSelectorFamilyToken, RegularAtomFamilyToken, WritableToken } from "atom.io";
|
|
4
4
|
import { Canonical, Json, stringified } from "atom.io/json";
|
|
5
5
|
import { UList } from "atom.io/transceivers/u-list";
|
|
6
|
-
import { ContinuityToken, RoomKey, Socket, SocketKey, UserKey } from "atom.io/realtime";
|
|
6
|
+
import { ContinuityToken, RoomKey, RoomSocketInterface, Socket, SocketKey, TypedSocket, UserKey } from "atom.io/realtime";
|
|
7
7
|
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
8
8
|
import { Readable, Writable } from "node:stream";
|
|
9
9
|
|
|
@@ -117,7 +117,7 @@ type ServerConfig = {
|
|
|
117
117
|
store?: RootStore;
|
|
118
118
|
};
|
|
119
119
|
//#endregion
|
|
120
|
-
//#region src/realtime-server/realtime-server-stores/
|
|
120
|
+
//#region src/realtime-server/realtime-server-stores/provide-rooms.d.ts
|
|
121
121
|
type RoomMap = Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
|
|
122
122
|
declare global {
|
|
123
123
|
var ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap;
|
|
@@ -126,21 +126,51 @@ declare const ROOMS: RoomMap;
|
|
|
126
126
|
declare const roomMeta: {
|
|
127
127
|
count: number;
|
|
128
128
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
type SpawnRoomConfig<RoomNames extends string> = {
|
|
130
|
+
store: RootStore;
|
|
131
|
+
socket: Socket;
|
|
132
|
+
userKey: UserKey;
|
|
133
|
+
resolveRoomScript: (roomName: RoomNames) => [string, string[]];
|
|
132
134
|
};
|
|
133
|
-
declare function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
declare function spawnRoom<RoomNames extends string>({
|
|
136
|
+
store,
|
|
137
|
+
socket,
|
|
138
|
+
userKey,
|
|
139
|
+
resolveRoomScript
|
|
140
|
+
}: SpawnRoomConfig<RoomNames>): (roomName: RoomNames) => Promise<ChildSocket<any, any>>;
|
|
141
|
+
type ProvideEnterAndExitConfig = {
|
|
142
|
+
store: RootStore;
|
|
143
|
+
socket: Socket;
|
|
144
|
+
roomSocket: TypedSocket<RoomSocketInterface<any>, any>;
|
|
145
|
+
userKey: UserKey;
|
|
146
|
+
};
|
|
147
|
+
declare function provideEnterAndExit({
|
|
148
|
+
store,
|
|
149
|
+
socket,
|
|
150
|
+
roomSocket,
|
|
151
|
+
userKey
|
|
152
|
+
}: ProvideEnterAndExitConfig): (roomKey: RoomKey) => void;
|
|
153
|
+
type DestroyRoomConfig = {
|
|
154
|
+
store: RootStore;
|
|
155
|
+
socket: Socket;
|
|
156
|
+
userKey: UserKey;
|
|
157
|
+
};
|
|
158
|
+
declare function destroyRoom({
|
|
159
|
+
store,
|
|
160
|
+
socket,
|
|
161
|
+
userKey
|
|
162
|
+
}: DestroyRoomConfig): (roomKey: RoomKey) => void;
|
|
163
|
+
type ProvideRoomsConfig<RoomNames extends string> = {
|
|
164
|
+
resolveRoomScript: (path: RoomNames) => [string, string[]];
|
|
165
|
+
roomNames: RoomNames[];
|
|
137
166
|
roomTimeLimit?: number;
|
|
138
167
|
};
|
|
139
168
|
declare function provideRooms<RoomNames extends string>({
|
|
140
169
|
store,
|
|
141
170
|
socket,
|
|
142
|
-
resolveRoomScript
|
|
143
|
-
|
|
171
|
+
resolveRoomScript,
|
|
172
|
+
roomNames
|
|
173
|
+
}: ProvideRoomsConfig<RoomNames> & ServerConfig): void;
|
|
144
174
|
//#endregion
|
|
145
175
|
//#region src/realtime-server/realtime-server-stores/server-user-store.d.ts
|
|
146
176
|
type SocketSystemHierarchy = Hierarchy<[{
|
|
@@ -167,5 +197,5 @@ declare function realtimeStateReceiver({
|
|
|
167
197
|
store
|
|
168
198
|
}: ServerConfig): <S extends Json.Serializable, C extends S>(clientToken: WritableToken<C>, serverToken?: WritableToken<S>) => () => void;
|
|
169
199
|
//#endregion
|
|
170
|
-
export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ProvideRoomsConfig, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, destroyRoom,
|
|
200
|
+
export { ChildProcess, ChildSocket, CustomSocket, DestroyRoomConfig, EventBuffer, EventPayload, Events, FamilyProvider, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ProvideEnterAndExitConfig, ProvideRoomsConfig, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, SpawnRoomConfig, StateProvider, StateReceiver, StderrLog, SubjectSocket, destroyRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, selfListSelectors, socketAtoms, socketKeysAtom, spawnRoom, userKeysAtom, usersOfSockets };
|
|
171
201
|
//# 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/
|
|
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/provide-rooms.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,IAA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,EAAA,IAAA;;;KQLV,qBAAA,GAAwB;;UAIzB,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, ownersOfRooms, roomKeysAtom, usersInRooms } from "atom.io/realtime";
|
|
5
|
+
import { castSocket, employSocket, isRoomKey, 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
|
|
@@ -703,44 +703,60 @@ const selfListSelectors = selectorFamily({
|
|
|
703
703
|
});
|
|
704
704
|
|
|
705
705
|
//#endregion
|
|
706
|
-
//#region src/realtime-server/realtime-server-stores/
|
|
706
|
+
//#region src/realtime-server/realtime-server-stores/provide-rooms.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
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
709
|
+
function spawnRoom({ store, socket, userKey, resolveRoomScript }) {
|
|
710
|
+
return async (roomName) => {
|
|
711
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} spawns room ${roomName}`);
|
|
712
|
+
const roomKey = `room::${roomMeta.count++}`;
|
|
713
|
+
const [command, args] = resolveRoomScript(roomName);
|
|
714
|
+
const roomSocket = new ChildSocket(await new Promise((resolve) => {
|
|
715
|
+
const room = spawn(command, args, { env: process.env });
|
|
716
|
+
const resolver = (data) => {
|
|
717
|
+
if (data.toString() === `ALIVE`) {
|
|
718
|
+
room.stdout.off(`data`, resolver);
|
|
719
|
+
resolve(room);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
room.stdout.on(`data`, resolver);
|
|
723
|
+
}), roomKey);
|
|
724
|
+
ROOMS.set(roomKey, roomSocket);
|
|
725
|
+
setIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index));
|
|
726
|
+
editRelationsInStore(store, ownersOfRooms, (relations) => {
|
|
727
|
+
relations.set({
|
|
728
|
+
room: roomKey,
|
|
729
|
+
user: userKey
|
|
730
|
+
});
|
|
726
731
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
+
roomSocket.on(`close`, () => {
|
|
733
|
+
destroyRoom({
|
|
734
|
+
store,
|
|
735
|
+
socket,
|
|
736
|
+
userKey
|
|
737
|
+
})(roomKey);
|
|
738
|
+
});
|
|
739
|
+
return roomSocket;
|
|
740
|
+
};
|
|
732
741
|
}
|
|
733
|
-
function provideEnterAndExit(store,
|
|
742
|
+
function provideEnterAndExit({ store, socket, roomSocket, userKey }) {
|
|
734
743
|
const enterRoom = (roomKey) => {
|
|
744
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} enters room ${roomKey}`);
|
|
735
745
|
const exitRoom = () => {
|
|
746
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} leaves room ${roomKey}`);
|
|
736
747
|
socket.offAny(forward);
|
|
737
748
|
toRoom([`user-leaves`]);
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
749
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
750
|
+
relations.delete({
|
|
751
|
+
room: roomKey,
|
|
752
|
+
user: userKey
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
roomSocket.off(`leaveRoom`, exitRoom);
|
|
756
|
+
roomSocket.on(`joinRoom`, enterRoom);
|
|
741
757
|
};
|
|
742
|
-
|
|
743
|
-
|
|
758
|
+
roomSocket.on(`leaveRoom`, exitRoom);
|
|
759
|
+
roomSocket.off(`joinRoom`, enterRoom);
|
|
744
760
|
const roomQueue = [];
|
|
745
761
|
const pushToRoomQueue = (payload) => {
|
|
746
762
|
roomQueue.push(payload);
|
|
@@ -756,51 +772,50 @@ function provideEnterAndExit(store, userKey, socket) {
|
|
|
756
772
|
user: userKey
|
|
757
773
|
});
|
|
758
774
|
});
|
|
759
|
-
const
|
|
760
|
-
if (!
|
|
775
|
+
const childSocket = ROOMS.get(roomKey);
|
|
776
|
+
if (!childSocket) {
|
|
761
777
|
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`);
|
|
762
778
|
return null;
|
|
763
779
|
}
|
|
764
|
-
|
|
780
|
+
childSocket.onAny((...payload) => {
|
|
765
781
|
socket.emit(...payload);
|
|
766
782
|
});
|
|
767
|
-
|
|
783
|
+
childSocket.emit(`user-joins`, userKey);
|
|
768
784
|
toRoom = (payload) => {
|
|
769
|
-
|
|
785
|
+
childSocket.emit(`user::${userKey}`, ...payload);
|
|
770
786
|
};
|
|
771
787
|
while (roomQueue.length > 0) {
|
|
772
788
|
const payload = roomQueue.shift();
|
|
773
789
|
if (payload) toRoom(payload);
|
|
774
790
|
}
|
|
775
791
|
};
|
|
776
|
-
|
|
777
|
-
return
|
|
792
|
+
roomSocket.on(`joinRoom`, enterRoom);
|
|
793
|
+
return enterRoom;
|
|
778
794
|
}
|
|
779
|
-
function
|
|
780
|
-
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
781
|
-
relations.delete({
|
|
782
|
-
room: roomKey,
|
|
783
|
-
user: userKey
|
|
784
|
-
});
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
function destroyRoom(store) {
|
|
795
|
+
function destroyRoom({ store, socket, userKey }) {
|
|
788
796
|
return (roomKey) => {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} attempts to delete room ${roomKey}`);
|
|
798
|
+
const owner = getFromStore(store, findRelationsInStore(store, ownersOfRooms, roomKey).userKeyOfRoom);
|
|
799
|
+
if (owner === userKey) {
|
|
800
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} deletes room ${roomKey}`);
|
|
801
|
+
setIntoStore(store, roomKeysAtom, (s) => (s.delete(roomKey), s));
|
|
802
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
803
|
+
relations.delete({ room: roomKey });
|
|
804
|
+
});
|
|
805
|
+
const room = ROOMS.get(roomKey);
|
|
806
|
+
if (room) {
|
|
807
|
+
room.emit(`exit`);
|
|
808
|
+
ROOMS.delete(roomKey);
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
797
811
|
}
|
|
812
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} failed to delete room ${roomKey}; room owner is ${owner}`);
|
|
798
813
|
};
|
|
799
814
|
}
|
|
800
|
-
function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript }) {
|
|
815
|
+
function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript, roomNames }) {
|
|
801
816
|
const socketKey = `socket::${socket.id}`;
|
|
802
817
|
const userKey = getFromStore(store, findRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket);
|
|
803
|
-
const roomSocket = socket;
|
|
818
|
+
const roomSocket = castSocket(socket, createRoomSocketGuard(roomNames));
|
|
804
819
|
const exposeMutable = realtimeMutableProvider({
|
|
805
820
|
socket,
|
|
806
821
|
store
|
|
@@ -813,23 +828,65 @@ function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript }) {
|
|
|
813
828
|
const [, usersInRoomsAtoms] = getInternalRelationsFromStore(store, usersInRooms, `split`);
|
|
814
829
|
exposeMutableFamily(usersInRoomsAtoms, findInStore(store, selfListSelectors, userKey));
|
|
815
830
|
exposeMutableFamily(getInternalRelationsFromStore(store, usersOfSockets), socketKeysAtom);
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
831
|
+
const enterRoom = provideEnterAndExit({
|
|
832
|
+
store,
|
|
833
|
+
socket,
|
|
834
|
+
roomSocket,
|
|
835
|
+
userKey
|
|
836
|
+
});
|
|
820
837
|
const userRoomSet = getFromStore(store, usersInRoomsAtoms, userKey);
|
|
821
838
|
for (const userRoomKey of userRoomSet) {
|
|
822
839
|
enterRoom(userRoomKey);
|
|
823
840
|
break;
|
|
824
841
|
}
|
|
825
|
-
roomSocket.on(`createRoom`,
|
|
826
|
-
|
|
842
|
+
roomSocket.on(`createRoom`, spawnRoom({
|
|
843
|
+
store,
|
|
844
|
+
socket,
|
|
845
|
+
userKey,
|
|
846
|
+
resolveRoomScript
|
|
847
|
+
}));
|
|
848
|
+
roomSocket.on(`deleteRoom`, destroyRoom({
|
|
849
|
+
store,
|
|
850
|
+
socket,
|
|
851
|
+
userKey
|
|
852
|
+
}));
|
|
827
853
|
socket.on(`disconnect`, () => {
|
|
854
|
+
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} disconnects`);
|
|
828
855
|
editRelationsInStore(store, usersOfSockets, (rel) => rel.delete(socketKey));
|
|
829
856
|
setIntoStore(store, userKeysAtom, (keys) => (keys.delete(userKey), keys));
|
|
830
857
|
setIntoStore(store, socketKeysAtom, (keys) => (keys.delete(socketKey), keys));
|
|
831
858
|
});
|
|
832
859
|
}
|
|
860
|
+
const roomKeySchema = { "~standard": {
|
|
861
|
+
version: 1,
|
|
862
|
+
vendor: `atom.io`,
|
|
863
|
+
validate: ([maybeRoomKey]) => {
|
|
864
|
+
if (typeof maybeRoomKey === `string`) {
|
|
865
|
+
if (isRoomKey(maybeRoomKey)) return { value: [maybeRoomKey] };
|
|
866
|
+
return { issues: [{ message: `Room key must start with "room::"` }] };
|
|
867
|
+
}
|
|
868
|
+
return { issues: [{ message: `Room key must be a string` }] };
|
|
869
|
+
}
|
|
870
|
+
} };
|
|
871
|
+
function createRoomSocketGuard(roomNames) {
|
|
872
|
+
return {
|
|
873
|
+
createRoom: { "~standard": {
|
|
874
|
+
version: 1,
|
|
875
|
+
vendor: `atom.io`,
|
|
876
|
+
validate: ([maybeRoomName]) => {
|
|
877
|
+
if (roomNames.includes(maybeRoomName)) return { value: [maybeRoomName] };
|
|
878
|
+
return { issues: [{ message: `Room name must be one of the following:\n - ` + roomNames.join(`\n - `) }] };
|
|
879
|
+
}
|
|
880
|
+
} },
|
|
881
|
+
joinRoom: roomKeySchema,
|
|
882
|
+
deleteRoom: roomKeySchema,
|
|
883
|
+
leaveRoom: { "~standard": {
|
|
884
|
+
version: 1,
|
|
885
|
+
vendor: `atom.io`,
|
|
886
|
+
validate: () => ({ value: [] })
|
|
887
|
+
} }
|
|
888
|
+
};
|
|
889
|
+
}
|
|
833
890
|
|
|
834
891
|
//#endregion
|
|
835
892
|
//#region src/realtime-server/realtime-state-provider.ts
|
|
@@ -904,5 +961,5 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
|
|
|
904
961
|
}
|
|
905
962
|
|
|
906
963
|
//#endregion
|
|
907
|
-
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoom,
|
|
964
|
+
export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, selfListSelectors, socketAtoms, socketKeysAtom, spawnRoom, userKeysAtom, usersOfSockets };
|
|
908
965
|
//# sourceMappingURL=index.js.map
|