atom.io 0.44.3 → 0.44.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["optimisticUpdateQueue","confirmedUpdateQueue","continuityEpoch: number | undefined","k: any","v: any","myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","optimisticUpdateQueue","confirmedUpdateQueue","k: any","v: any","transaction"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector-roots.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Fn, RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tgetEpochNumberOfContinuity,\n\tingestTransactionOutcomeEvent,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Socket } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\n\nexport const useRegisterAndAttemptConfirmedUpdate =\n\t(\n\t\tstore: RootStore,\n\t\tcontinuityKey: string,\n\t\tsocket: Socket,\n\t\toptimisticUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t\tconfirmedUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t) =>\n\t(\n\t\tconfirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,\n\t): void => {\n\t\tfunction reconcileEpoch(\n\t\t\toptimisticUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t\tconfirmedUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t): void {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reconciling updates`,\n\t\t\t)\n\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\tqueue.shift()\n\t\t\t\treturn queue\n\t\t\t})\n\t\t\tif (optimisticUpdate.id === confirmedUpdate.id) {\n\t\t\t\tconst clientResult = JSON.stringify(optimisticUpdate.subEvents)\n\t\t\t\tconst serverResult = JSON.stringify(confirmedUpdate.subEvents)\n\t\t\t\tif (clientResult === serverResult) {\n\t\t\t\t\tstore.logger.info(\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`results for ${optimisticUpdate.id} match between client and server`,\n\t\t\t\t\t)\n\t\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// id mismatch\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`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`updates do not match`,\n\t\t\t\toptimisticUpdate,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tconst reversedOptimisticUpdates = optimisticUpdates.toReversed()\n\t\t\tfor (const subsequentOptimistic of reversedOptimisticUpdates) {\n\t\t\t\tingestTransactionOutcomeEvent(store, subsequentOptimistic, `oldValue`)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid optimistic updates:`,\n\t\t\t\treversedOptimisticUpdates,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, optimisticUpdate, `oldValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid zeroth optimistic update`,\n\t\t\t\toptimisticUpdate,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, confirmedUpdate, `newValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`applied confirmed update`,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\n\t\t\tfor (const subsequentOptimistic of optimisticUpdates) {\n\t\t\t\tconst token = {\n\t\t\t\t\ttype: `transaction`,\n\t\t\t\t\tkey: subsequentOptimistic.token.key,\n\t\t\t\t} as const\n\t\t\t\tconst { id, params } = subsequentOptimistic\n\t\t\t\tactUponStore(store, token, id)(...params)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reapplied subsequent optimistic updates:`,\n\t\t\t\toptimisticUpdates,\n\t\t\t)\n\t\t}\n\n\t\tstore.logger.info(\n\t\t\t`🧑‍⚖️`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`integrating confirmed update`,\n\t\t\t{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates },\n\t\t)\n\t\tconst zerothOptimisticUpdate = optimisticUpdates[0]\n\t\tif (zerothOptimisticUpdate) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has optimistic updates to reconcile`,\n\t\t\t)\n\t\t\tif (confirmed.epoch === zerothOptimisticUpdate.epoch) {\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`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`,\n\t\t\t\t)\n\t\t\t\treconcileEpoch(zerothOptimisticUpdate, confirmed)\n\t\t\t\tfor (const nextConfirmed of confirmedUpdates) {\n\t\t\t\t\tconst nextOptimistic = optimisticUpdates[0]\n\t\t\t\t\tif (nextConfirmed.epoch === nextOptimistic?.epoch) {\n\t\t\t\t\t\treconcileEpoch(nextOptimistic, nextConfirmed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// epoch mismatch\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`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (!confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\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`pushing confirmed update to queue`,\n\t\t\t\t\t\tconfirmed,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has no optimistic updates to deal with`,\n\t\t\t)\n\t\t\tlet continuityEpoch: number | undefined\n\t\t\tcontinuityEpoch = getEpochNumberOfContinuity(store, continuityKey)\n\n\t\t\tif (continuityEpoch === confirmed.epoch - 1) {\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`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,\n\t\t\t\t)\n\t\t\t\tingestTransactionOutcomeEvent(store, confirmed, `newValue`)\n\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmed.epoch)\n\t\t\t\tsetEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)\n\t\t\t} else if (continuityEpoch !== undefined) {\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`received update #${confirmed.epoch} but still waiting for update #${\n\t\t\t\t\t\tcontinuityEpoch + 1\n\t\t\t\t\t}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientEpoch: continuityEpoch,\n\t\t\t\t\t\tserverEpoch: confirmed.epoch,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\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`confirmed update #${confirmed.epoch} is already enqueued`,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\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`pushing confirmed update #${confirmed.epoch} to queue`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","import type { AtomToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { disposeAtom } from \"atom.io/internal\"\n\nexport function useConcealState(store: Store) {\n\treturn (concealed: AtomToken<unknown>[]): void => {\n\t\tfor (const token of concealed) {\n\t\t\tdisposeAtom(store, token)\n\t\t}\n\t}\n}\n","import { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function useRevealState(store: Store) {\n\treturn (revealed: Json.Array): void => {\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of revealed) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtom<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.RegularAtomToken<J, any, any>,\n): () => void {\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket.on(`serve:${token.key}`, setServedValue)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`, setServedValue)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore, setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.AtomFamilyToken<J, K, any>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket?.on(`serve:${token.key}`, setServedValue)\n\tsocket?.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`, setServedValue)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken, setIntoStore } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtom<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.MutableAtomToken<T>,\n): () => void {\n\tconst jsonToken = getJsonToken(store, token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tsetIntoStore(store, updateToken, data)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tconst trackerToken = getUpdateToken(token)\n\t\tsetIntoStore(store, trackerToken, data)\n\t})\n\tsocket.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type { AtomToken, SelectorToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { getFamilyOfToken, subscribeToState } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullAtom } from \"./pull-atom\"\nimport { pullAtomFamilyMember } from \"./pull-atom-family-member\"\nimport { pullMutableAtom } from \"./pull-mutable-atom\"\nimport { pullMutableAtomFamilyMember } from \"./pull-mutable-atom-family-member\"\n\nexport function pullSelectorRoots(\n\tstore: Store,\n\tsocket: Socket,\n\tselectorToken: SelectorToken<any>,\n): () => void {\n\tconst atomSubscriptions = new Map<string, () => void>()\n\tconst clearAtomSubscriptions = () => {\n\t\tfor (const [, unsub] of atomSubscriptions) unsub()\n\t\tatomSubscriptions.clear()\n\t}\n\n\tconst start = () => {\n\t\tconst atomKeys = store.selectorAtoms.getRelatedKeys(selectorToken.key)\n\t\tif (atomKeys) {\n\t\t\tfor (const [atomKey, unsub] of atomSubscriptions) {\n\t\t\t\tif (!atomKeys.has(atomKey)) {\n\t\t\t\t\tunsub()\n\t\t\t\t\tatomSubscriptions.delete(atomKey)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const atomKey of atomKeys) {\n\t\t\t\tif (atomSubscriptions.has(atomKey)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst atom = store.atoms.get(atomKey) as AtomToken<any, any>\n\t\t\t\tswitch (atom.type) {\n\t\t\t\t\tcase `atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(atomKey, pullAtom(store, socket, atom))\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase `mutable_atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtom(store, socket, atom),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst unsubFromSelector = subscribeToState(\n\t\tstore,\n\t\tselectorToken,\n\t\t`pull-watches-dependencies`,\n\t\t() => {\n\t\t\tstart()\n\t\t},\n\t)\n\n\tstart()\n\n\treturn () => {\n\t\tclearAtomSubscriptions()\n\t\tunsubFromSelector()\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelector<T>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.SelectorToken<T>,\n): () => void {\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelectorFamilyMember<T, K extends Canonical>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamilyToken: AtomIO.SelectorFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, familyToken, key)\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type { WritableToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { setIntoStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket, mutexAtoms } from \"atom.io/realtime\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: WritableToken<J>,\n): () => void {\n\tconst publish = (newValue: J) => {\n\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t}\n\n\tconst subscriptions = new Set<() => void>()\n\tconst clearSubscriptions = () => {\n\t\tfor (const unsub of subscriptions) unsub()\n\t\tsubscriptions.clear()\n\t}\n\n\tconst init = () => {\n\t\tsubscriptions.add(\n\t\t\temploySocket(socket, `claim-result:${token.key}`, (success: boolean) => {\n\t\t\t\tif (!success) return\n\n\t\t\t\tclearSubscriptions()\n\t\t\t\tsetIntoStore(store, mutexAtoms, token.key, true)\n\t\t\t\tsubscriptions.add(\n\t\t\t\t\tsubscribeToState(store, token, `push`, ({ newValue }) => {\n\t\t\t\t\t\tpublish(newValue)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\n\t\tsocket.emit(`claim:${token.key}`)\n\t}\n\n\tinit()\n\n\treturn () => {\n\t\tclearSubscriptions()\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { storageSync } from \"atom.io/web\"\n\nexport const myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined> =\n\tAtomIO.atom<string | undefined>({\n\t\tkey: `mySocketId__INTERNAL`,\n\t\tdefault: undefined,\n\t})\nexport const myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined> =\n\tAtomIO.selector<string | undefined>({\n\t\tkey: `mySocketId`,\n\t\tget: ({ get }) => get(myIdState__INTERNAL),\n\t})\n\nexport const myUsernameState: AtomIO.RegularAtomToken<string | null> =\n\tAtomIO.atom<string | null>({\n\t\tkey: `myName`,\n\t\tdefault: null,\n\t\teffects: [storageSync(globalThis.localStorage, JSON, `myUsername`)],\n\t})\n","import * as AtomIO from \"atom.io\"\n\nexport const optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `updateQueue`,\n\tdefault: () => [],\n})\n\nexport const confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `serverConfirmedUpdateQueue`,\n\tdefault: () => [],\n})\n","import type { RootStore } from \"atom.io/internal\"\nimport {\n\tassignTransactionToContinuity,\n\tgetFromStore,\n\tgetJsonToken,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { useRegisterAndAttemptConfirmedUpdate } from \"./continuity/register-and-attempt-confirmed-update\"\nimport { useConcealState } from \"./continuity/use-conceal-state\"\nimport { useRevealState } from \"./continuity/use-reveal-state\"\n\nexport function syncContinuity(\n\tstore: RootStore,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst optimisticUpdates = getFromStore(store, optimisticUpdateQueue)\n\tconst confirmedUpdates = getFromStore(store, confirmedUpdateQueue)\n\n\tconst initializeContinuity = (epoch: number, payload: Json.Array) => {\n\t\tsocket.off(`continuity-init:${continuityKey}`, initializeContinuity)\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of payload) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tif (`type` in k && k.type === `mutable_atom`) {\n\t\t\t\t\tk = getJsonToken(store, k)\n\t\t\t\t}\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t\tsetEpochNumberOfContinuity(store, continuityKey, epoch)\n\t}\n\tsocket.off(`continuity-init:${continuityKey}`)\n\tsocket.on(`continuity-init:${continuityKey}`, initializeContinuity)\n\n\tconst registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(\n\t\tstore,\n\t\tcontinuityKey,\n\t\tsocket,\n\t\toptimisticUpdates,\n\t\tconfirmedUpdates,\n\t)\n\tsocket.off(`tx-new:${continuityKey}`)\n\tsocket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)\n\n\tconst unsubscribeFunctions = continuity.actions.map((transaction) => {\n\t\tassignTransactionToContinuity(store, continuityKey, transaction.key)\n\t\tconst unsubscribeFromTransactionUpdates = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`tx-run:${continuityKey}`,\n\t\t\t(clientUpdate) => {\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`enqueuing optimistic update`,\n\t\t\t\t)\n\t\t\t\tconst optimisticUpdateIndex = optimisticUpdates.findIndex(\n\t\t\t\t\t(update) => update.id === clientUpdate.id,\n\t\t\t\t)\n\t\t\t\tif (optimisticUpdateIndex === -1) {\n\t\t\t\t\tstore.logger.info(\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`enqueuing new optimistic update`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(clientUpdate)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\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`replacing existing optimistic update at index ${optimisticUpdateIndex}`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue[optimisticUpdateIndex] = clientUpdate\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tsocket.emit(`tx-run:${continuityKey}`, {\n\t\t\t\t\tid: clientUpdate.id,\n\t\t\t\t\ttoken: transaction,\n\t\t\t\t\tparams: clientUpdate.params,\n\t\t\t\t})\n\t\t\t},\n\t\t)\n\t\treturn unsubscribeFromTransactionUpdates\n\t})\n\n\tconst revealState = useRevealState(store)\n\tconst concealState = useConcealState(store)\n\tsocket.on(`reveal:${continuityKey}`, revealState)\n\tsocket.on(`conceal:${continuityKey}`, concealState)\n\n\tsocket.emit(`get:${continuityKey}`)\n\treturn () => {\n\t\tsocket.off(`continuity-init:${continuityKey}`)\n\t\tsocket.off(`tx-new:${continuityKey}`)\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t// socket.emit(`unsub:${continuityKey}`)\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAa,wCAEX,OACA,eACA,QACA,mBAGA,sBAKA,cACU;CACV,SAAS,eACR,kBAGA,iBAGO;AACP,QAAM,OAAO,KACZ,SACA,cACA,eACA,sBACA;AACD,eAAa,OAAOA,0BAAwB,UAAU;AACrD,SAAM,OAAO;AACb,UAAO;IACN;AACF,MAAI,iBAAiB,OAAO,gBAAgB,IAG3C;OAFqB,KAAK,UAAU,iBAAiB,UAAU,KAC1C,KAAK,UAAU,gBAAgB,UAAU,EAC3B;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AkC;CAEvE,MAAM,uBAAuB,WAAW,QAAQ,KAAK,kBAAgB;AACpE,gCAA8B,OAAO,eAAeC,cAAY,IAAI;AA8CpE,SA7C0C,uBACzC,OACAA,eACA,UAAU,kBACT,iBAAiB;AACjB,SAAM,OAAO,KACZ,MACA,cACA,eACA,8BACA;GACD,MAAM,wBAAwB,kBAAkB,WAC9C,WAAW,OAAO,OAAO,aAAa,GACvC;AACD,OAAI,0BAA0B,IAAI;AACjC,UAAM,OAAO,KACZ,MACA,cACA,eACA,kCACA;AACD,iBAAa,OAAOJ,0BAAwB,UAAU;AACrD,WAAM,KAAK,aAAa;AACxB,WAAM,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;AACvC,YAAO;MACN;UACI;AACN,UAAM,OAAO,KACZ,MACA,cACA,eACA,iDAAiD,wBACjD;AACD,iBAAa,OAAOA,0BAAwB,UAAU;AACrD,WAAM,yBAAyB;AAC/B,YAAO;MACN;;AAEH,UAAO,KAAK,UAAU,iBAAiB;IACtC,IAAI,aAAa;IACjB,OAAOI;IACP,QAAQ,aAAa;IACrB,CAAC;IAEH;GAEA;CAEF,MAAM,cAAc,eAAe,MAAM;CACzC,MAAM,eAAe,gBAAgB,MAAM;AAC3C,QAAO,GAAG,UAAU,iBAAiB,YAAY;AACjD,QAAO,GAAG,WAAW,iBAAiB,aAAa;AAEnD,QAAO,KAAK,OAAO,gBAAgB;AACnC,cAAa;AACZ,SAAO,IAAI,mBAAmB,gBAAgB;AAC9C,SAAO,IAAI,UAAU,gBAAgB;AACrC,OAAK,MAAM,eAAe,qBAAsB,cAAa"}
1
+ {"version":3,"file":"index.js","names":["optimisticUpdateQueue","confirmedUpdateQueue","continuityEpoch: number | undefined","k: any","v: any","myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","optimisticUpdateQueue","confirmedUpdateQueue","k: any","v: any"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector-roots.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Fn, RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tgetEpochNumberOfContinuity,\n\tingestTransactionOutcomeEvent,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Socket } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\n\nexport const useRegisterAndAttemptConfirmedUpdate =\n\t(\n\t\tstore: RootStore,\n\t\tcontinuityKey: string,\n\t\tsocket: Socket,\n\t\toptimisticUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t\tconfirmedUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t) =>\n\t(\n\t\tconfirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,\n\t): void => {\n\t\tfunction reconcileEpoch(\n\t\t\toptimisticUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t\tconfirmedUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t): void {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reconciling updates`,\n\t\t\t)\n\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\tqueue.shift()\n\t\t\t\treturn queue\n\t\t\t})\n\t\t\tif (optimisticUpdate.id === confirmedUpdate.id) {\n\t\t\t\tconst clientResult = JSON.stringify(optimisticUpdate.subEvents)\n\t\t\t\tconst serverResult = JSON.stringify(confirmedUpdate.subEvents)\n\t\t\t\tif (clientResult === serverResult) {\n\t\t\t\t\tstore.logger.info(\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`results for ${optimisticUpdate.id} match between client and server`,\n\t\t\t\t\t)\n\t\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// id mismatch\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`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`updates do not match`,\n\t\t\t\toptimisticUpdate,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tconst reversedOptimisticUpdates = optimisticUpdates.toReversed()\n\t\t\tfor (const subsequentOptimistic of reversedOptimisticUpdates) {\n\t\t\t\tingestTransactionOutcomeEvent(store, subsequentOptimistic, `oldValue`)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid optimistic updates:`,\n\t\t\t\treversedOptimisticUpdates,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, optimisticUpdate, `oldValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid zeroth optimistic update`,\n\t\t\t\toptimisticUpdate,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, confirmedUpdate, `newValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`applied confirmed update`,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\n\t\t\tfor (const subsequentOptimistic of optimisticUpdates) {\n\t\t\t\tconst token = {\n\t\t\t\t\ttype: `transaction`,\n\t\t\t\t\tkey: subsequentOptimistic.token.key,\n\t\t\t\t} as const\n\t\t\t\tconst { id, params } = subsequentOptimistic\n\t\t\t\tactUponStore(store, token, id)(...params)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reapplied subsequent optimistic updates:`,\n\t\t\t\toptimisticUpdates,\n\t\t\t)\n\t\t}\n\n\t\tstore.logger.info(\n\t\t\t`🧑‍⚖️`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`integrating confirmed update`,\n\t\t\t{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates },\n\t\t)\n\t\tconst zerothOptimisticUpdate = optimisticUpdates[0]\n\t\tif (zerothOptimisticUpdate) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has optimistic updates to reconcile`,\n\t\t\t)\n\t\t\tif (confirmed.epoch === zerothOptimisticUpdate.epoch) {\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`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`,\n\t\t\t\t)\n\t\t\t\treconcileEpoch(zerothOptimisticUpdate, confirmed)\n\t\t\t\tfor (const nextConfirmed of confirmedUpdates) {\n\t\t\t\t\tconst nextOptimistic = optimisticUpdates[0]\n\t\t\t\t\tif (nextConfirmed.epoch === nextOptimistic?.epoch) {\n\t\t\t\t\t\treconcileEpoch(nextOptimistic, nextConfirmed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// epoch mismatch\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`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (!confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\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`pushing confirmed update to queue`,\n\t\t\t\t\t\tconfirmed,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has no optimistic updates to deal with`,\n\t\t\t)\n\t\t\tlet continuityEpoch: number | undefined\n\t\t\tcontinuityEpoch = getEpochNumberOfContinuity(store, continuityKey)\n\n\t\t\tif (continuityEpoch === confirmed.epoch - 1) {\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`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,\n\t\t\t\t)\n\t\t\t\tingestTransactionOutcomeEvent(store, confirmed, `newValue`)\n\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmed.epoch)\n\t\t\t\tsetEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)\n\t\t\t} else if (continuityEpoch !== undefined) {\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`received update #${confirmed.epoch} but still waiting for update #${\n\t\t\t\t\t\tcontinuityEpoch + 1\n\t\t\t\t\t}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientEpoch: continuityEpoch,\n\t\t\t\t\t\tserverEpoch: confirmed.epoch,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\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`confirmed update #${confirmed.epoch} is already enqueued`,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\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`pushing confirmed update #${confirmed.epoch} to queue`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","import type { AtomToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { disposeAtom } from \"atom.io/internal\"\n\nexport function useConcealState(store: Store) {\n\treturn (concealed: AtomToken<unknown>[]): void => {\n\t\tfor (const token of concealed) {\n\t\t\tdisposeAtom(store, token)\n\t\t}\n\t}\n}\n","import { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function useRevealState(store: Store) {\n\treturn (revealed: Json.Array): void => {\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of revealed) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtom<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.RegularAtomToken<J, any, any>,\n): () => void {\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket.on(`serve:${token.key}`, setServedValue)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`, setServedValue)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore, setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.AtomFamilyToken<J, K, any>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket?.on(`serve:${token.key}`, setServedValue)\n\tsocket?.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`, setServedValue)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken, setIntoStore } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtom<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.MutableAtomToken<T>,\n): () => void {\n\tconst jsonToken = getJsonToken(store, token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tsetIntoStore(store, updateToken, data)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tconst trackerToken = getUpdateToken(token)\n\t\tsetIntoStore(store, trackerToken, data)\n\t})\n\tsocket.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type { AtomToken, SelectorToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { getFamilyOfToken, subscribeToState } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullAtom } from \"./pull-atom\"\nimport { pullAtomFamilyMember } from \"./pull-atom-family-member\"\nimport { pullMutableAtom } from \"./pull-mutable-atom\"\nimport { pullMutableAtomFamilyMember } from \"./pull-mutable-atom-family-member\"\n\nexport function pullSelectorRoots(\n\tstore: Store,\n\tsocket: Socket,\n\tselectorToken: SelectorToken<any>,\n): () => void {\n\tconst atomSubscriptions = new Map<string, () => void>()\n\tconst clearAtomSubscriptions = () => {\n\t\tfor (const [, unsub] of atomSubscriptions) unsub()\n\t\tatomSubscriptions.clear()\n\t}\n\n\tconst start = () => {\n\t\tconst atomKeys = store.selectorAtoms.getRelatedKeys(selectorToken.key)\n\t\tif (atomKeys) {\n\t\t\tfor (const [atomKey, unsub] of atomSubscriptions) {\n\t\t\t\tif (!atomKeys.has(atomKey)) {\n\t\t\t\t\tunsub()\n\t\t\t\t\tatomSubscriptions.delete(atomKey)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const atomKey of atomKeys) {\n\t\t\t\tif (atomSubscriptions.has(atomKey)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst atom = store.atoms.get(atomKey) as AtomToken<any, any>\n\t\t\t\tswitch (atom.type) {\n\t\t\t\t\tcase `atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(atomKey, pullAtom(store, socket, atom))\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase `mutable_atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtom(store, socket, atom),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst unsubFromSelector = subscribeToState(\n\t\tstore,\n\t\tselectorToken,\n\t\t`pull-watches-dependencies`,\n\t\t() => {\n\t\t\tstart()\n\t\t},\n\t)\n\n\tstart()\n\n\treturn () => {\n\t\tclearAtomSubscriptions()\n\t\tunsubFromSelector()\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelector<T>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.SelectorToken<T>,\n): () => void {\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelectorFamilyMember<T, K extends Canonical>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamilyToken: AtomIO.SelectorFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, familyToken, key)\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type { WritableToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { setIntoStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { employSocket, mutexAtoms } from \"atom.io/realtime\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: WritableToken<J>,\n): () => void {\n\tconst publish = (newValue: J) => {\n\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t}\n\n\tconst subscriptions = new Set<() => void>()\n\tconst clearSubscriptions = () => {\n\t\tfor (const unsub of subscriptions) unsub()\n\t\tsubscriptions.clear()\n\t}\n\n\tconst init = () => {\n\t\tsubscriptions.add(\n\t\t\temploySocket(socket, `claim-result:${token.key}`, (success: boolean) => {\n\t\t\t\tif (!success) return\n\n\t\t\t\tclearSubscriptions()\n\t\t\t\tsetIntoStore(store, mutexAtoms, token.key, true)\n\t\t\t\tsubscriptions.add(\n\t\t\t\t\tsubscribeToState(store, token, `push`, ({ newValue }) => {\n\t\t\t\t\t\tpublish(newValue)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\n\t\tsocket.emit(`claim:${token.key}`)\n\t}\n\n\tinit()\n\n\treturn () => {\n\t\tclearSubscriptions()\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { storageSync } from \"atom.io/web\"\n\nexport const myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined> =\n\tAtomIO.atom<string | undefined>({\n\t\tkey: `mySocketId__INTERNAL`,\n\t\tdefault: undefined,\n\t})\nexport const myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined> =\n\tAtomIO.selector<string | undefined>({\n\t\tkey: `mySocketId`,\n\t\tget: ({ get }) => get(myIdState__INTERNAL),\n\t})\n\nexport const myUsernameState: AtomIO.RegularAtomToken<string | null> =\n\tAtomIO.atom<string | null>({\n\t\tkey: `myName`,\n\t\tdefault: null,\n\t\teffects: [storageSync(globalThis.localStorage, JSON, `myUsername`)],\n\t})\n","import * as AtomIO from \"atom.io\"\n\nexport const optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `updateQueue`,\n\tdefault: () => [],\n})\n\nexport const confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `serverConfirmedUpdateQueue`,\n\tdefault: () => [],\n})\n","import type { RootStore } from \"atom.io/internal\"\nimport {\n\tassignTransactionToContinuity,\n\tgetFromStore,\n\tgetJsonToken,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { useRegisterAndAttemptConfirmedUpdate } from \"./continuity/register-and-attempt-confirmed-update\"\nimport { useConcealState } from \"./continuity/use-conceal-state\"\nimport { useRevealState } from \"./continuity/use-reveal-state\"\n\nexport function syncContinuity(\n\tstore: RootStore,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst optimisticUpdates = getFromStore(store, optimisticUpdateQueue)\n\tconst confirmedUpdates = getFromStore(store, confirmedUpdateQueue)\n\n\tconst initializeContinuity = (epoch: number, payload: Json.Array) => {\n\t\tsocket.off(`continuity-init:${continuityKey}`, initializeContinuity)\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of payload) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tif (`type` in k && k.type === `mutable_atom`) {\n\t\t\t\t\tk = getJsonToken(store, k)\n\t\t\t\t}\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t\tsetEpochNumberOfContinuity(store, continuityKey, epoch)\n\t}\n\tsocket.off(`continuity-init:${continuityKey}`)\n\tsocket.on(`continuity-init:${continuityKey}`, initializeContinuity)\n\n\tconst registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(\n\t\tstore,\n\t\tcontinuityKey,\n\t\tsocket,\n\t\toptimisticUpdates,\n\t\tconfirmedUpdates,\n\t)\n\tsocket.off(`tx-new:${continuityKey}`)\n\tsocket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)\n\n\tconst unsubscribeFunctions = continuity.actions.map((transaction) => {\n\t\tassignTransactionToContinuity(store, continuityKey, transaction.key)\n\t\tconst unsubscribeFromTransactionUpdates = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`tx-run:${continuityKey}`,\n\t\t\t(clientUpdate) => {\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`enqueuing optimistic update`,\n\t\t\t\t)\n\t\t\t\tconst optimisticUpdateIndex = optimisticUpdates.findIndex(\n\t\t\t\t\t(update) => update.id === clientUpdate.id,\n\t\t\t\t)\n\t\t\t\tif (optimisticUpdateIndex === -1) {\n\t\t\t\t\tstore.logger.info(\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`enqueuing new optimistic update`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(clientUpdate)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\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`replacing existing optimistic update at index ${optimisticUpdateIndex}`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue[optimisticUpdateIndex] = clientUpdate\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tsocket.emit(`tx-run:${continuityKey}`, {\n\t\t\t\t\tid: clientUpdate.id,\n\t\t\t\t\ttoken: transaction,\n\t\t\t\t\tparams: clientUpdate.params,\n\t\t\t\t})\n\t\t\t},\n\t\t)\n\t\treturn unsubscribeFromTransactionUpdates\n\t})\n\n\tconst revealState = useRevealState(store)\n\tconst concealState = useConcealState(store)\n\tsocket.on(`reveal:${continuityKey}`, revealState)\n\tsocket.on(`conceal:${continuityKey}`, concealState)\n\n\tsocket.emit(`get:${continuityKey}`)\n\treturn () => {\n\t\tsocket.off(`continuity-init:${continuityKey}`)\n\t\tsocket.off(`tx-new:${continuityKey}`)\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t// socket.emit(`unsub:${continuityKey}`)\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAa,wCAEX,OACA,eACA,QACA,mBAGA,sBAKA,cACU;CACV,SAAS,eACR,kBAGA,iBAGO;AACP,QAAM,OAAO,KACZ,SACA,cACA,eACA,sBACA;AACD,eAAa,OAAOA,0BAAwB,UAAU;AACrD,SAAM,OAAO;AACb,UAAO;IACN;AACF,MAAI,iBAAiB,OAAO,gBAAgB,IAG3C;OAFqB,KAAK,UAAU,iBAAiB,UAAU,KAC1C,KAAK,UAAU,gBAAgB,UAAU,EAC3B;AAClC,UAAM,OAAO,KACZ,KACA,cACA,eACA,eAAe,iBAAiB,GAAG,kCACnC;AACD,WAAO,KAAK,OAAO,iBAAiB,gBAAgB,MAAM;AAC1D;;QAID,OAAM,OAAO,KACZ,KACA,cACA,eACA,mBAAmB,gBAAgB,MAAM,OAAO,iBAAiB,MAAM,IAAI,GAAG,iBAAiB,GAAG,wBAAwB,gBAAgB,MAAM,IAAI,GAAG,gBAAgB,KACvK;AAEF,QAAM,OAAO,KACZ,SACA,cACA,eACA,wBACA,kBACA,gBACA;EACD,MAAM,4BAA4B,kBAAkB,YA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D,WAAM,KAAK,aAAa;AACxB,WAAM,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;AACvC,YAAO;MACN;UACI;AACN,UAAM,OAAO,KACZ,MACA,cACA,eACA,iDAAiD,wBACjD;AACD,iBAAa,OAAOA,0BAAwB,UAAU;AACrD,WAAM,yBAAyB;AAC/B,YAAO;MACN;;AAEH,UAAO,KAAK,UAAU,iBAAiB;IACtC,IAAI,aAAa;IACjB,OAAO;IACP,QAAQ,aAAa;IACrB,CAAC;IAEH;GAEA;CAEF,MAAM,cAAc,eAAe,MAAM;CACzC,MAAM,eAAe,gBAAgB,MAAM;AAC3C,QAAO,GAAG,UAAU,iBAAiB,YAAY;AACjD,QAAO,GAAG,WAAW,iBAAiB,aAAa;AAEnD,QAAO,KAAK,OAAO,gBAAgB;AACnC,cAAa;AACZ,SAAO,IAAI,mBAAmB,gBAAgB;AAC9C,SAAO,IAAI,UAAU,gBAAgB;AACrC,OAAK,MAAM,eAAe,qBAAsB,cAAa"}
@@ -1,9 +1,9 @@
1
- import { RootStore, Subject, Transceiver } from "atom.io/internal";
1
+ import { RootStore, Store, Subject, Transceiver } from "atom.io/internal";
2
2
  import * as AtomIO from "atom.io";
3
- import { Hierarchy, JoinToken, MutableAtomToken, PureSelectorFamilyToken, RegularAtomFamilyToken, TransactionIO, TransactionToken, WritableToken } from "atom.io";
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, Socket, UserInRoomMeta } from "atom.io/realtime";
6
+ import { ContinuityToken, Socket } from "atom.io/realtime";
7
7
  import { ChildProcessWithoutNullStreams } from "node:child_process";
8
8
  import { Readable, Writable } from "node:stream";
9
9
 
@@ -54,6 +54,16 @@ declare class ChildSocket<I extends Events, O extends Events, P extends ChildPro
54
54
  constructor(proc: P, key: string, logger?: Pick<Console, `error` | `info` | `warn`>);
55
55
  }
56
56
  //#endregion
57
+ //#region src/realtime-server/realtime-server-stores/server-room-external-store.d.ts
58
+ declare const ROOMS: Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
59
+ declare function spawnRoom(roomId: string, command: string, args: string[], store: Store): Promise<ChildSocket<any, any>>;
60
+ declare function joinRoom(roomId: string, userId: string, socket: Socket, store: Store): {
61
+ leave: () => void;
62
+ roomSocket: ChildSocket<any, any, ChildProcessWithoutNullStreams>;
63
+ } | null;
64
+ declare function leaveRoom(roomId: string, userId: string, store: Store): void;
65
+ declare function destroyRoom(roomId: string, store: Store): void;
66
+ //#endregion
57
67
  //#region src/realtime-server/realtime-server-stores/server-user-store.d.ts
58
68
  type SocketKey = `socket::${string}`;
59
69
  type UserKey = `user::${string}`;
@@ -68,15 +78,6 @@ declare const userIndex: MutableAtomToken<UList<UserKey>>;
68
78
  declare const usersOfSockets: JoinToken<`user`, UserKey, `socket`, SocketKey, `1:1`>;
69
79
  declare const userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<UserKey[], UserKey>;
70
80
  //#endregion
71
- //#region src/realtime-server/realtime-server-stores/server-room-external-store.d.ts
72
- declare const ROOMS: Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
73
- declare function spawnRoom(roomId: string, script: string, options: string[]): Promise<ChildSocket<any, any>>;
74
- declare const joinRoomTX: TransactionToken<(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta>;
75
- type JoinRoomIO = TransactionIO<typeof joinRoomTX>;
76
- declare const leaveRoomTX: TransactionToken<(roomId: string, userId: string) => void>;
77
- type LeaveRoomIO = TransactionIO<typeof leaveRoomTX>;
78
- declare const destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>;
79
- //#endregion
80
81
  //#region src/realtime-server/ipc-sockets/parent-socket.d.ts
81
82
  declare class SubjectSocket<I extends Events, O extends Events> extends CustomSocket<I, O> {
82
83
  in: Subject<EventPayload<I>>;
@@ -154,5 +155,5 @@ type ServerConfig = {
154
155
  store?: RootStore;
155
156
  };
156
157
  //#endregion
157
- export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, JoinRoomIO, LeaveRoomIO, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ROOMS, RoomKey, ServerConfig, SocketKey, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, UserKey, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
158
+ export { ChildProcess, ChildSocket, CustomSocket, EventBuffer, EventPayload, Events, FamilyProvider, MutableFamilyProvider, MutableProvider, ParentProcess, ParentSocket, ProvideContinuity, ROOMS, RoomKey, ServerConfig, SocketKey, SocketSystemHierarchy, StateProvider, StateReceiver, StderrLog, SubjectSocket, UserKey, destroyRoom, joinRoom, leaveRoom, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
158
159
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<UList<SocketKey>>","userIndex: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<\n\tUserKey[],\n\tUserKey\n>","ROOMS: Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>","joinRoomTX: TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n>","leaveRoomTX: TransactionToken<\n\t(roomId: string, userId: string) => void\n>","destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>"],"sources":["../../src/realtime-server/continuity/provide-continuity.ts","../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts","../../src/realtime-server/server-config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAYY,iBAAA,gBACC,0BACH;iBAEM,0BAAA;;;GAGb,eAAe;;;KChBN,MAAA,GAAS,IAAA,CAAK,eAAe,IAAA,CAAK;KAElC,kCACU,iCACI,8BAA8B,4BACxC,aAAa;UAEZ,sBACN,iCACe,mBAAmB,EDA7C,SCCU,MDDE,CAAA;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,c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;;KCnBjB,YAAA;UACH;UACA"}
1
+ {"version":3,"file":"index.d.ts","names":["ROOMS: Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<UList<SocketKey>>","userIndex: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<\n\tUserKey[],\n\tUserKey\n>"],"sources":["../../src/realtime-server/continuity/provide-continuity.ts","../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts","../../src/realtime-server/server-config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAYY,iBAAA,gBACC,0BACH;iBAEM,0BAAA;;;GAGb,eAAe;;;KChBN,MAAA,GAAS,IAAA,CAAK,eAAe,IAAA,CAAK;KAElC,kCACU,iCACI,8BAA8B,4BACxC,aAAa;UAEZ,sBACN,iCACe,mBAAmB,EDA7C,SCCU,MDDE,CAAA;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,MA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,cAAc,IAAA,CAAK,sBAC9C,MAAA,CAAO,iBAAiB;;;KCdtB,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;;;KCnBjB,YAAA;UACH;UACA"}
@@ -1,5 +1,5 @@
1
1
  import { IMPLICIT, OWN_OP, Subject, actUponStore, editRelationsInStore, findInStore, getFromStore, getJsonToken, getUpdateToken, isRootStore, operateOnStore, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
2
- import { atomFamily, join, mutableAtom, selectorFamily, transaction } from "atom.io";
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
5
  import { employSocket, mutexAtoms, roomIndex, usersInRooms } from "atom.io/realtime";
@@ -49,8 +49,8 @@ const unacknowledgedUpdatesAtoms = atomFamily({
49
49
  function provideOutcomes(store, socket, continuity, userKey) {
50
50
  const continuityKey = continuity.key;
51
51
  const unsubscribeFunctions = /* @__PURE__ */ new Set();
52
- for (const transaction$1 of continuity.actions) {
53
- const unsubscribeFromTransaction = subscribeToTransaction(store, transaction$1, `sync-continuity:${continuityKey}:${userKey}`, (outcomes) => {
52
+ for (const transaction of continuity.actions) {
53
+ const unsubscribeFromTransaction = subscribeToTransaction(store, transaction, `sync-continuity:${continuityKey}:${userKey}`, (outcomes) => {
54
54
  try {
55
55
  const redactedUpdates = redactTransactionUpdateContent(continuity.globals.map((atom) => {
56
56
  if (atom.type === `atom`) return atom.key;
@@ -75,7 +75,7 @@ function provideOutcomes(store, socket, continuity, userKey) {
75
75
  });
76
76
  socket.emit(`tx-new:${continuityKey}`, redactedUpdate);
77
77
  } catch (thrown) {
78
- if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction$1.key} to ${userKey}`, thrown.message);
78
+ if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`, thrown.message);
79
79
  }
80
80
  });
81
81
  unsubscribeFunctions.add(unsubscribeFromTransaction);
@@ -679,9 +679,9 @@ function realtimeMutableProvider({ socket, store = IMPLICIT.STORE }) {
679
679
  //#endregion
680
680
  //#region src/realtime-server/realtime-server-stores/server-room-external-store.ts
681
681
  const ROOMS = /* @__PURE__ */ new Map();
682
- async function spawnRoom(roomId, script, options) {
683
- const child = await new Promise((resolve) => {
684
- const room = spawn(script, options, { env: process.env });
682
+ async function spawnRoom(roomId, command, args, store) {
683
+ const roomSocket = new ChildSocket(await new Promise((resolve) => {
684
+ const room = spawn(command, args, { env: process.env });
685
685
  const resolver = (data) => {
686
686
  if (data.toString() === `ALIVE`) {
687
687
  room.stdout.off(`data`, resolver);
@@ -689,48 +689,75 @@ async function spawnRoom(roomId, script, options) {
689
689
  }
690
690
  };
691
691
  room.stdout.on(`data`, resolver);
692
+ }), roomId);
693
+ ROOMS.set(roomId, roomSocket);
694
+ setIntoStore(store, roomIndex, (index) => (index.add(roomId), index));
695
+ roomSocket.on(`close`, () => {
696
+ destroyRoom(roomId, store);
692
697
  });
693
- ROOMS.set(roomId, new ChildSocket(child, roomId));
694
- return new ChildSocket(child, roomId);
698
+ return roomSocket;
695
699
  }
696
- const joinRoomTX = transaction({
697
- key: `joinRoom`,
698
- do: (tools, roomId, userId, enteredAtEpoch) => {
699
- const meta = { enteredAtEpoch };
700
- editRelationsInStore(usersInRooms, (relations) => {
701
- relations.set({
702
- room: roomId,
703
- user: userId
704
- });
705
- }, tools.env().store);
706
- return meta;
700
+ function joinRoom(roomId, userId, socket, store) {
701
+ const roomQueue = [];
702
+ const pushToRoomQueue = (payload) => {
703
+ roomQueue.push(payload);
704
+ };
705
+ let toRoom = pushToRoomQueue;
706
+ const forward = (...payload) => {
707
+ toRoom(payload);
708
+ };
709
+ socket.onAny(forward);
710
+ editRelationsInStore(usersInRooms, (relations) => {
711
+ relations.set({
712
+ room: roomId,
713
+ user: userId
714
+ });
715
+ }, store);
716
+ const roomSocket = ROOMS.get(roomId);
717
+ if (!roomSocket) {
718
+ store.logger.error(`❌`, `unknown`, roomId, `no room found with this id`);
719
+ return null;
707
720
  }
708
- });
709
- const leaveRoomTX = transaction({
710
- key: `leaveRoom`,
711
- do: ({ env }, roomId, userId) => {
712
- editRelationsInStore(usersInRooms, (relations) => {
713
- relations.delete({
714
- room: roomId,
715
- user: userId
716
- });
717
- }, env().store);
721
+ roomSocket.onAny((...payload) => {
722
+ socket.emit(...payload);
723
+ });
724
+ roomSocket.emit(`user-joins`, userId);
725
+ toRoom = (payload) => {
726
+ roomSocket.emit(`user::${userId}`, ...payload);
727
+ };
728
+ while (roomQueue.length > 0) {
729
+ const payload = roomQueue.shift();
730
+ if (payload) toRoom(payload);
718
731
  }
719
- });
720
- const destroyRoomTX = transaction({
721
- key: `destroyRoom`,
722
- do: ({ set, env }, roomId) => {
723
- editRelationsInStore(usersInRooms, (relations) => {
724
- relations.delete({ room: roomId });
725
- }, env().store);
726
- set(roomIndex, (s) => (s.delete(roomId), s));
727
- const room = ROOMS.get(roomId);
728
- if (room) {
729
- room.emit(`exit`);
730
- ROOMS.delete(roomId);
731
- }
732
+ const leave = () => {
733
+ socket.offAny(forward);
734
+ toRoom([`user-leaves`]);
735
+ leaveRoom(roomId, userId, store);
736
+ };
737
+ return {
738
+ leave,
739
+ roomSocket
740
+ };
741
+ }
742
+ function leaveRoom(roomId, userId, store) {
743
+ editRelationsInStore(usersInRooms, (relations) => {
744
+ relations.delete({
745
+ room: roomId,
746
+ user: userId
747
+ });
748
+ }, store);
749
+ }
750
+ function destroyRoom(roomId, store) {
751
+ editRelationsInStore(usersInRooms, (relations) => {
752
+ relations.delete({ room: roomId });
753
+ }, store);
754
+ setIntoStore(store, roomIndex, (s) => (s.delete(roomId), s));
755
+ const room = ROOMS.get(roomId);
756
+ if (room) {
757
+ room.emit(`exit`);
758
+ ROOMS.delete(roomId);
732
759
  }
733
- });
760
+ }
734
761
 
735
762
  //#endregion
736
763
  //#region src/realtime-server/realtime-server-stores/server-user-store.ts
@@ -833,5 +860,5 @@ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
833
860
  }
834
861
 
835
862
  //#endregion
836
- export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
863
+ export { ChildSocket, CustomSocket, ParentSocket, ROOMS, SubjectSocket, destroyRoom, joinRoom, leaveRoom, prepareToProvideContinuity, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, socketAtoms, socketIndex, spawnRoom, userIndex, userMutualSituationalAwarenessIndexes, usersOfSockets };
837
864
  //# sourceMappingURL=index.js.map